silverlight.js
14.3 KB
//>>built
define("dojo/_base/kernel dojo/_base/lang dojo/_base/declare dojo/_base/Color dojo/on dojo/_base/array dojo/dom-geometry dojo/dom dojo/_base/sniff ./_base ./shape ./path ./registry".split(" "),function(n,h,l,D,E,t,u,r,v,e,g,w){function x(a){var b=e.normalizeColor(a);a=b.toHex();b=Math.round(255*b.a);b=(0>b?0:255<b?255:b).toString(16);return"#"+(2>b.length?"0"+b:b)+a.slice(1)}function m(a,b){var c={target:a,currentTarget:a,preventDefault:function(){},stopPropagation:function(){}};try{b.source&&(c.target=
b.source,c.gfxTarget=g.byId(c.target.tag))}catch(F){}if(b)try{c.ctrlKey=b.ctrl;c.shiftKey=b.shift;var f=b.getPosition(null);c.x=c.offsetX=c.layerX=f.x;c.y=c.offsetY=c.layerY=f.y;var k=q[a.getHost().content.root.name],d=u.position(k);c.clientX=d.x+f.x;c.clientY=d.y+f.y}catch(F){}return c}function y(a,b){a={keyCode:b.platformKeyCode,ctrlKey:b.ctrl,shiftKey:b.shift};try{b.source&&(a.target=b.source,a.gfxTarget=g.byId(a.target.tag))}catch(c){}return a}var d=e.silverlight={};n.experimental("dojox.gfx.silverlight");
var z={solid:"none",shortdash:[4,1],shortdot:[1,1],shortdashdot:[4,1,1,1],shortdashdotdot:[4,1,1,1,1,1],dot:[1,3],dash:[4,3],longdash:[8,3],dashdot:[4,3,1,3],longdashdot:[8,3,1,3],longdashdotdot:[8,3,1,3,1,3]},A={normal:400,bold:700},H={butt:"Flat",round:"Round",square:"Square"},I={bevel:"Bevel",round:"Round"},B={serif:"Times New Roman",times:"Times New Roman","sans-serif":"Arial",helvetica:"Arial",monotone:"Courier New",courier:"Courier New"};d.Shape=l("dojox.gfx.silverlight.Shape",g.Shape,{destroy:function(){v("gfxRegistry")&&
g.dispose(this);this.rawNode=null},setFill:function(a){var b=this.rawNode.getHost().content;if(!a)return this.fillStyle=null,this._setFillAttr(null),this;if("object"==typeof a&&"type"in a){switch(a.type){case "linear":this.fillStyle=a=e.makeParameters(e.defaultLinearGradient,a);var c=b.createFromXaml("\x3cLinearGradientBrush/\x3e");c.mappingMode="Absolute";c.startPoint=a.x1+","+a.y1;c.endPoint=a.x2+","+a.y2;t.forEach(a.colors,function(a){var d=b.createFromXaml("\x3cGradientStop/\x3e");d.offset=a.offset;
d.color=x(a.color);c.gradientStops.add(d)});this._setFillAttr(c);break;case "radial":this.fillStyle=a=e.makeParameters(e.defaultRadialGradient,a);var f=b.createFromXaml("\x3cRadialGradientBrush/\x3e"),d=e.matrix.multiplyPoint(e.matrix.invert(this._getAdjustedMatrix()),a.cx,a.cy),d=d.x+","+d.y;f.mappingMode="Absolute";f.gradientOrigin=d;f.center=d;f.radiusX=f.radiusY=a.r;t.forEach(a.colors,function(a){var c=b.createFromXaml("\x3cGradientStop/\x3e");c.offset=a.offset;c.color=x(a.color);f.gradientStops.add(c)});
this._setFillAttr(f);break;case "pattern":this.fillStyle=null,this._setFillAttr(null)}return this}this.fillStyle=a=e.normalizeColor(a);d=b.createFromXaml("\x3cSolidColorBrush/\x3e");d.color=a.toHex();d.opacity=a.a;this._setFillAttr(d);return this},_setFillAttr:function(a){this.rawNode.fill=a},setStroke:function(a){var b=this.rawNode.getHost().content,c=this.rawNode;if(!a)return this.strokeStyle=null,c.stroke=null,this;if("string"==typeof a||h.isArray(a)||a instanceof D)a={color:a};a=this.strokeStyle=
e.makeParameters(e.defaultStroke,a);a.color=e.normalizeColor(a.color);if(a)if(b=b.createFromXaml("\x3cSolidColorBrush/\x3e"),b.color=a.color.toHex(),b.opacity=a.color.a,c.stroke=b,c.strokeThickness=a.width,c.strokeStartLineCap=c.strokeEndLineCap=c.strokeDashCap=H[a.cap],"number"==typeof a.join?(c.strokeLineJoin="Miter",c.strokeMiterLimit=a.join):c.strokeLineJoin=I[a.join],b=a.style.toLowerCase(),b in z&&(b=z[b]),b instanceof Array){b=h.clone(b);if("butt"!=a.cap){for(a=0;a<b.length;a+=2)--b[a],1>b[a]&&
(b[a]=1);for(a=1;a<b.length;a+=2)++b[a]}c.strokeDashArray=b.join(",")}else c.strokeDashArray=null;return this},_getParentSurface:function(){for(var a=this.parent;a&&!(a instanceof e.Surface);a=a.parent);return a},_applyTransform:function(){var a=this._getAdjustedMatrix(),b=this.rawNode;if(a){var c=this.rawNode.getHost().content,d=c.createFromXaml("\x3cMatrixTransform/\x3e"),c=c.createFromXaml("\x3cMatrix/\x3e");c.m11=a.xx;c.m21=a.xy;c.m12=a.yx;c.m22=a.yy;c.offsetX=a.dx;c.offsetY=a.dy;d.matrix=c;b.renderTransform=
d}else b.renderTransform=null;return this},setRawNode:function(a){a.fill=null;a.stroke=null;this.rawNode=a;this.rawNode.tag=this.getUID()},_moveToFront:function(){var a=this.parent.rawNode.children,b=this.rawNode;a.remove(b);a.add(b);return this},_moveToBack:function(){var a=this.parent.rawNode.children,b=this.rawNode;a.remove(b);a.insert(0,b);return this},_getAdjustedMatrix:function(){return this.matrix},setClip:function(a){this.inherited(arguments);var b=this.rawNode;if(a){var c=a?"width"in a?"rect":
"cx"in a?"ellipse":"points"in a?"polyline":"d"in a?"path":null:null;if(a&&!c)return this;var d=this.getBoundingBox()||{x:0,y:0,width:0,height:0},e="1,0,0,1,"+-d.x+","+-d.y;switch(c){case "rect":b.clip=b.getHost().content.createFromXaml("\x3cRectangleGeometry/\x3e");b.clip.rect=a.x+","+a.y+","+a.width+","+a.height;b.clip.transform=e;break;case "ellipse":b.clip=b.getHost().content.createFromXaml("\x3cEllipseGeometry/\x3e");b.clip.center=a.cx+","+a.cy;b.clip.radiusX=a.rx;b.clip.radiusY=a.ry;b.clip.transform=
"1,0,0,1,"+-d.x+","+-d.y;break;case "polyline":if(2<a.points.length){var e=b.getHost().content.createFromXaml("\x3cPathGeometry/\x3e"),g=b.getHost().content.createFromXaml("\x3cPathFigure/\x3e");g.StartPoint=a.points[0]+","+a.points[1];for(var h=2;h<=a.points.length-2;h+=2)c=b.getHost().content.createFromXaml("\x3cLineSegment/\x3e"),c.Point=a.points[h]+","+a.points[h+1],g.segments.add(c);e.figures.add(g);e.transform="1,0,0,1,"+-d.x+","+-d.y;b.clip=e}}}else b.clip=null;return this}});d.Group=l("dojox.gfx.silverlight.Group",
d.Shape,{constructor:function(){g.Container._init.call(this)},setRawNode:function(a){this.rawNode=a;this.rawNode.tag=this.getUID()},destroy:function(){this.clear(!0);d.Shape.prototype.destroy.apply(this,arguments)}});d.Group.nodeType="Canvas";d.Rect=l("dojox.gfx.silverlight.Rect",[d.Shape,g.Rect],{setShape:function(a){this.shape=e.makeParameters(this.shape,a);this.bbox=null;a=this.rawNode;var b=this.shape;a.width=b.width;a.height=b.height;a.radiusX=a.radiusY=b.r;return this._applyTransform()},_getAdjustedMatrix:function(){var a=
this.matrix,b=this.shape,b={dx:b.x,dy:b.y};return new e.Matrix2D(a?[a,b]:b)}});d.Rect.nodeType="Rectangle";d.Ellipse=l("dojox.gfx.silverlight.Ellipse",[d.Shape,g.Ellipse],{setShape:function(a){this.shape=e.makeParameters(this.shape,a);this.bbox=null;a=this.rawNode;var b=this.shape;a.width=2*b.rx;a.height=2*b.ry;return this._applyTransform()},_getAdjustedMatrix:function(){var a=this.matrix,b=this.shape,b={dx:b.cx-b.rx,dy:b.cy-b.ry};return new e.Matrix2D(a?[a,b]:b)}});d.Ellipse.nodeType="Ellipse";d.Circle=
l("dojox.gfx.silverlight.Circle",[d.Shape,g.Circle],{setShape:function(a){this.shape=e.makeParameters(this.shape,a);this.bbox=null;a=this.rawNode;a.width=a.height=2*this.shape.r;return this._applyTransform()},_getAdjustedMatrix:function(){var a=this.matrix,b=this.shape,b={dx:b.cx-b.r,dy:b.cy-b.r};return new e.Matrix2D(a?[a,b]:b)}});d.Circle.nodeType="Ellipse";d.Line=l("dojox.gfx.silverlight.Line",[d.Shape,g.Line],{setShape:function(a){this.shape=e.makeParameters(this.shape,a);this.bbox=null;a=this.rawNode;
var b=this.shape;a.x1=b.x1;a.y1=b.y1;a.x2=b.x2;a.y2=b.y2;return this}});d.Line.nodeType="Line";d.Polyline=l("dojox.gfx.silverlight.Polyline",[d.Shape,g.Polyline],{setShape:function(a,b){a&&a instanceof Array?(this.shape=e.makeParameters(this.shape,{points:a}),b&&this.shape.points.length&&this.shape.points.push(this.shape.points[0])):this.shape=e.makeParameters(this.shape,a);this.bbox=null;this._normalizePoints();a=this.shape.points;b=[];for(var c=0;c<a.length;++c)b.push(a[c].x,a[c].y);this.rawNode.points=
b.join(",");return this}});d.Polyline.nodeType="Polyline";d.Image=l("dojox.gfx.silverlight.Image",[d.Shape,g.Image],{setShape:function(a){this.shape=e.makeParameters(this.shape,a);this.bbox=null;a=this.rawNode;var b=this.shape;a.width=b.width;a.height=b.height;a.source=b.src;return this._applyTransform()},_getAdjustedMatrix:function(){var a=this.matrix,b=this.shape,b={dx:b.x,dy:b.y};return new e.Matrix2D(a?[a,b]:b)},setRawNode:function(a){this.rawNode=a;this.rawNode.tag=this.getUID()}});d.Image.nodeType=
"Image";d.Text=l("dojox.gfx.silverlight.Text",[d.Shape,g.Text],{setShape:function(a){this.shape=e.makeParameters(this.shape,a);this.bbox=null;a=this.rawNode;var b=this.shape;a.text=""+b.text;a.textDecorations="underline"===b.decoration?"Underline":"None";a["Canvas.Left"]=-1E4;a["Canvas.Top"]=-1E4;this._delay||(this._delay=window.setTimeout(h.hitch(this,"_delayAlignment"),10));return this},_delayAlignment:function(){var a=this.rawNode,b=this.shape,c,d;try{c=a.actualWidth,d=a.actualHeight}catch(G){return}var e=
b.x;d=b.y-.75*d;switch(b.align){case "middle":e-=c/2;break;case "end":e-=c}this._delta={dx:e,dy:d};a["Canvas.Left"]=0;a["Canvas.Top"]=0;this._applyTransform();delete this._delay},_getAdjustedMatrix:function(){var a=this.matrix,b=this._delta;return new e.Matrix2D(a?b?[a,b]:a:b?b:{})},setStroke:function(){return this},_setFillAttr:function(a){this.rawNode.foreground=a},setRawNode:function(a){this.rawNode=a;this.rawNode.tag=this.getUID()},getTextWidth:function(){return this.rawNode.actualWidth},getBoundingBox:function(){var a=
null,b=this.getShape().text,c=this.rawNode,d=0,k=0;if(!e._base._isRendered(this))return{x:0,y:0,width:0,height:0};if(b){try{d=c.actualWidth,k=c.actualHeight}catch(G){return null}a=e._base._computeTextLocation(this.getShape(),d,k,!0);a={x:a.x,y:a.y,width:d,height:k}}return a}});d.Text.nodeType="TextBlock";d.Path=l("dojox.gfx.silverlight.Path",[d.Shape,w.Path],{_updateWithSegment:function(a){this.inherited(arguments);var b=this.shape.path;"string"==typeof b&&(this.rawNode.data=b?b:null)},setShape:function(a){this.inherited(arguments);
var b=this.shape.path;this.rawNode.data=b?b:null;return this}});d.Path.nodeType="Path";d.TextPath=l("dojox.gfx.silverlight.TextPath",[d.Shape,w.TextPath],{_updateWithSegment:function(a){},setShape:function(a){},_setText:function(){}});d.TextPath.nodeType="text";var q={},J=new Function;d.Surface=l("dojox.gfx.silverlight.Surface",g.Surface,{constructor:function(){g.Container._init.call(this)},destroy:function(){this.clear(!0);window[this._onLoadName]=J;delete q[this._nodeName];this.inherited(arguments)},
setDimensions:function(a,b){this.width=e.normalizedLength(a);this.height=e.normalizedLength(b);var c=this.rawNode&&this.rawNode.getHost();c&&(c.width=a,c.height=b);return this},getDimensions:function(){var a=this.rawNode&&this.rawNode.getHost(),a=a?{width:a.content.actualWidth,height:a.content.actualHeight}:null;0>=a.width&&(a.width=this.width);0>=a.height&&(a.height=this.height);return a}});d.createSurface=function(a,b,c){if(!b&&!c){var f=u.position(a);b=b||f.w;c=c||f.h}"number"==typeof b&&(b+="px");
"number"==typeof c&&(c+="px");var k=new d.Surface;a=r.byId(a);k._parent=a;k._nodeName=e._base._getUniqueId();f=a.ownerDocument.createElement("script");f.type="text/xaml";f.id=e._base._getUniqueId();f.text="\x3c?xml version\x3d'1.0'?\x3e\x3cCanvas xmlns\x3d'http://schemas.microsoft.com/client/2007' Name\x3d'"+k._nodeName+"'/\x3e";a.parentNode.insertBefore(f,a);k._nodes.push(f);var g=e._base._getUniqueId(),h="__"+e._base._getUniqueId()+"_onLoad";k._onLoadName=h;window[h]=function(b){k.rawNode||(k.rawNode=
r.byId(g,a.ownerDocument).content.root,q[k._nodeName]=a,k.onLoad(k))};f=v("safari")?"\x3cembed type\x3d'application/x-silverlight' id\x3d'"+g+"' width\x3d'"+b+"' height\x3d'"+c+" background\x3d'transparent' source\x3d'#"+f.id+"' windowless\x3d'true' maxFramerate\x3d'60' onLoad\x3d'"+h+"' onError\x3d'__dojoSilverlightError' /\x3e\x3ciframe style\x3d'visibility:hidden;height:0;width:0'/\x3e":"\x3cobject type\x3d'application/x-silverlight' data\x3d'data:application/x-silverlight,' id\x3d'"+g+"' width\x3d'"+
b+"' height\x3d'"+c+"'\x3e\x3cparam name\x3d'background' value\x3d'transparent' /\x3e\x3cparam name\x3d'source' value\x3d'#"+f.id+"' /\x3e\x3cparam name\x3d'windowless' value\x3d'true' /\x3e\x3cparam name\x3d'maxFramerate' value\x3d'60' /\x3e\x3cparam name\x3d'onLoad' value\x3d'"+h+"' /\x3e\x3cparam name\x3d'onError' value\x3d'__dojoSilverlightError' /\x3e\x3c/object\x3e";a.innerHTML=f;f=r.byId(g,a.ownerDocument);f.content&&f.content.root?(k.rawNode=f.content.root,q[k._nodeName]=a):(k.rawNode=null,
k.isLoaded=!1);k._nodes.push(f);k.width=e.normalizedLength(b);k.height=e.normalizedLength(c);return k};__dojoSilverlightError=function(a,b){};var p=g.Container;n={add:function(a){this!=a.getParent()&&(p.add.apply(this,arguments),this.rawNode.children.add(a.rawNode));return this},remove:function(a,b){if(this==a.getParent()){var c=a.rawNode.getParent();c&&c.children.remove(a.rawNode);p.remove.apply(this,arguments)}return this},clear:function(){this.rawNode.children.clear();return p.clear.apply(this,
arguments)},getBoundingBox:p.getBoundingBox,_moveChildToFront:p._moveChildToFront,_moveChildToBack:p._moveChildToBack};l={createObject:function(a,b){if(!this.rawNode)return null;var c=new a;a=this.rawNode.getHost().content.createFromXaml("\x3c"+a.nodeType+"/\x3e");c.setRawNode(a);c.setShape(b);this.add(c);return c}};h.extend(d.Text,{_setFont:function(){var a=this.fontStyle,b=this.rawNode,c=a.family.toLowerCase();b.fontStyle="italic"==a.style?"Italic":"Normal";b.fontWeight=a.weight in A?A[a.weight]:
a.weight;b.fontSize=e.normalizedLength(a.size);b.fontFamily=c in B?B[c]:a.family;this._delay||(this._delay=window.setTimeout(h.hitch(this,"_delayAlignment"),10))}});h.extend(d.Group,n);h.extend(d.Group,g.Creator);h.extend(d.Group,l);h.extend(d.Surface,n);h.extend(d.Surface,g.Creator);h.extend(d.Surface,l);var C={onclick:{name:"MouseLeftButtonUp",fix:m},onmouseenter:{name:"MouseEnter",fix:m},onmouseleave:{name:"MouseLeave",fix:m},onmouseover:{name:"MouseEnter",fix:m},onmouseout:{name:"MouseLeave",
fix:m},onmousedown:{name:"MouseLeftButtonDown",fix:m},onmouseup:{name:"MouseLeftButtonUp",fix:m},onmousemove:{name:"MouseMove",fix:m},onkeydown:{name:"KeyDown",fix:y},onkeyup:{name:"KeyUp",fix:y}};n={connect:function(a,b,c){return this.on(a,c?h.hitch(b,c):b)},on:function(a,b){if("string"===typeof a){0===a.indexOf("mouse")&&(a="on"+a);var c,d=a in C?C[a]:{name:a,fix:function(){return{}}};c=this.getEventSource().addEventListener(d.name,function(a,c){b(d.fix(a,c))});return{name:d.name,token:c,remove:h.hitch(this,
function(){this.getEventSource().removeEventListener(d.name,c)})}}return E(this,a,b)},disconnect:function(a){return a.remove()}};h.extend(d.Shape,n);h.extend(d.Surface,n);e.equalSources=function(a,b){return a&&b&&a.equals(b)};return d});