diff --git a/build/preprocess.sh b/build/preprocess.sh index 83fcd483..860fdd73 100755 --- a/build/preprocess.sh +++ b/build/preprocess.sh @@ -31,7 +31,7 @@ # stripped Formated but without comments # compressed Uses UglifyJS to reduce file size -VERSION=0.21 +VERSION=0.22 DATE=$(git log -1 --pretty=format:%ad) COMMAND="./prepro.js -d '{ \"version\": $VERSION, \"date\": \"$DATE\" }' -d '$4' $2" diff --git a/dist/docs/classes/CharacterStyle.html b/dist/docs/classes/CharacterStyle.html index b1692846..359b7469 100644 --- a/dist/docs/classes/CharacterStyle.html +++ b/dist/docs/classes/CharacterStyle.html @@ -151,7 +151,7 @@ text.characterStyle = { @@ -167,7 +167,7 @@ text.characterStyle = { var circle = new Path.Circle(new Point(80, 50), 35); // Set its stroke color to RGB red: -circle.strokeColor = new RGBColor(1, 0, 0); +circle.strokeColor = new RgbColor(1, 0, 0);
@@ -530,7 +530,7 @@ limit on the ratio of the miter length to the RGBColor / HSBColor / HSLColor / GrayColor + RgbColor / HsbColor / HslColor / GrayColor @@ -546,7 +546,7 @@ limit on the ratio of the miter length to the diff --git a/dist/docs/classes/Color.html b/dist/docs/classes/Color.html index 55f39f9c..c230d9b0 100644 --- a/dist/docs/classes/Color.html +++ b/dist/docs/classes/Color.html @@ -18,10 +18,10 @@

Color

All properties and functions that expect color values accept -instances of the different color classes such as RGBColor, -HSBColor and GrayColor, and also accept named colors +instances of the different color classes such as RgbColor, +HsbColor and GrayColor, and also accept named colors and hex values as strings which are then converted to instances of -RGBColor internally.

+RgbColor internally.

Example — Named color values:

@@ -34,7 +34,7 @@ and hex values as strings which are then converted to instances of var circle = new Path.Circle(new Point(80, 50), 30); // Pass a color name to the fillColor property, which is internally -// converted to an RGBColor. +// converted to an RgbColor. circle.fillColor = 'green';
@@ -53,7 +53,7 @@ circle.fillColor = 'green'; var circle = new Path.Circle(new Point(80, 50), 30); // Pass a hex string to the fillColor property, which is internally -// converted to an RGBColor. +// converted to an RgbColor. circle.fillColor = '#ff0000';
@@ -141,7 +141,7 @@ same as those of the supplied one.

-
var color = new RGBColor(1, 0, 0);
+
var color = new RgbColor(1, 0, 0);
 console.log(color.type); // 'rgb'
@@ -520,6 +520,40 @@ function onFrame(event) { + + + + + + +

HSL Components

+ +
+ + @@ -554,7 +588,7 @@ function onFrame(event) { diff --git a/dist/docs/classes/CompoundPath.html b/dist/docs/classes/CompoundPath.html index 8332fcf7..302ea309 100644 --- a/dist/docs/classes/CompoundPath.html +++ b/dist/docs/classes/CompoundPath.html @@ -1554,6 +1554,38 @@ already contained within a clipping group.

+
+ + +
+ +
@@ -2356,7 +2388,7 @@ miterLimit imposes a limit on the ratio of the miter length to the @@ -2372,7 +2404,7 @@ miterLimit imposes a limit on the ratio of the miter length to the var circle = new Path.Circle(new Point(80, 50), 35); // Set the fill color of the circle to RGB red: -circle.fillColor = new RGBColor(1, 0, 0); +circle.fillColor = new RgbColor(1, 0, 0);
diff --git a/dist/docs/classes/GradientStop.html b/dist/docs/classes/GradientStop.html index 97b43e0f..0e879e34 100644 --- a/dist/docs/classes/GradientStop.html +++ b/dist/docs/classes/GradientStop.html @@ -48,7 +48,7 @@ color: Color — the color of the stop -— optional, default: new RGBColor(0, 0, 0) +— optional, default: new RgbColor(0, 0, 0)
  • diff --git a/dist/docs/classes/GrayColor.html b/dist/docs/classes/GrayColor.html index 0f3239e4..c3987ba6 100644 --- a/dist/docs/classes/GrayColor.html +++ b/dist/docs/classes/GrayColor.html @@ -94,6 +94,43 @@ circle.fillColor = new GrayColor(0.5); +

    Properties

    + + +
    + + +
    + +
    + @@ -133,7 +170,7 @@ circle.fillColor = new GrayColor(0.5);

    -
    var color = new RGBColor(1, 0, 0);
    +
    var color = new RgbColor(1, 0, 0);
     console.log(color.type); // 'rgb'
    @@ -344,41 +381,6 @@ circle.fillColor.blue = 1; - - - - - - -

    Gray Components

    - -
    - - @@ -512,6 +514,40 @@ function onFrame(event) { +
    + + + + + +

    HSL Components

    + +
    + + @@ -545,7 +581,7 @@ function onFrame(event) { diff --git a/dist/docs/classes/Group.html b/dist/docs/classes/Group.html index 9b4b70bf..426e459f 100644 --- a/dist/docs/classes/Group.html +++ b/dist/docs/classes/Group.html @@ -759,6 +759,38 @@ already contained within a clipping group.

    +
    + + +
    + +
    @@ -1561,7 +1593,7 @@ miterLimit imposes a limit on the ratio of the miter length to the @@ -1577,7 +1609,7 @@ miterLimit imposes a limit on the ratio of the miter length to the var circle = new Path.Circle(new Point(80, 50), 35); // Set the fill color of the circle to RGB red: -circle.fillColor = new RGBColor(1, 0, 0); +circle.fillColor = new RgbColor(1, 0, 0);
    diff --git a/dist/docs/classes/HsbColor.html b/dist/docs/classes/HsbColor.html index 906ad8f2..b02271d5 100644 --- a/dist/docs/classes/HsbColor.html +++ b/dist/docs/classes/HsbColor.html @@ -2,7 +2,7 @@ -HSBColor +HsbColor @@ -15,11 +15,11 @@
    -

    HSBColor

    +

    HsbColor

    Extends Color

    -

    An HSBColor object is used to represent any HSB color value.

    +

    An HsbColor object is used to represent any HSB color value.

    @@ -29,20 +29,20 @@
    -

    HSB Components

    +

    HSL Components

    -
    - + +
    +
    + + +
    + + @@ -1008,24 +1042,22 @@ anchor point.

    -
    -
  • @@ -472,7 +472,7 @@ limit on the ratio of the miter length to the diff --git a/dist/docs/classes/PlacedItem.html b/dist/docs/classes/PlacedItem.html index efbc37cf..959080f6 100644 --- a/dist/docs/classes/PlacedItem.html +++ b/dist/docs/classes/PlacedItem.html @@ -665,6 +665,38 @@ already contained within a clipping group.

    +
    + + +
    + +
    @@ -1467,7 +1499,7 @@ miterLimit imposes a limit on the ratio of the miter length to the @@ -1483,7 +1515,7 @@ miterLimit imposes a limit on the ratio of the miter length to the var circle = new Path.Circle(new Point(80, 50), 35); // Set the fill color of the circle to RGB red: -circle.fillColor = new RGBColor(1, 0, 0); +circle.fillColor = new RgbColor(1, 0, 0);
    diff --git a/dist/docs/classes/PlacedSymbol.html b/dist/docs/classes/PlacedSymbol.html index 0b7c7db8..8780cc5c 100644 --- a/dist/docs/classes/PlacedSymbol.html +++ b/dist/docs/classes/PlacedSymbol.html @@ -751,6 +751,38 @@ already contained within a clipping group.

    +
    + + +
    + +
    @@ -1553,7 +1585,7 @@ miterLimit imposes a limit on the ratio of the miter length to the @@ -1569,7 +1601,7 @@ miterLimit imposes a limit on the ratio of the miter length to the var circle = new Path.Circle(new Point(80, 50), 35); // Set the fill color of the circle to RGB red: -circle.fillColor = new RGBColor(1, 0, 0); +circle.fillColor = new RgbColor(1, 0, 0);
    diff --git a/dist/docs/classes/PointText.html b/dist/docs/classes/PointText.html index 2ebd14af..a25c35a9 100644 --- a/dist/docs/classes/PointText.html +++ b/dist/docs/classes/PointText.html @@ -714,6 +714,38 @@ already contained within a clipping group.

    +
    + + +
    + +
    @@ -1516,7 +1548,7 @@ miterLimit imposes a limit on the ratio of the miter length to the @@ -1532,7 +1564,7 @@ miterLimit imposes a limit on the ratio of the miter length to the var circle = new Path.Circle(new Point(80, 50), 35); // Set the fill color of the circle to RGB red: -circle.fillColor = new RGBColor(1, 0, 0); +circle.fillColor = new RgbColor(1, 0, 0);
    diff --git a/dist/docs/classes/Project.html b/dist/docs/classes/Project.html index 5b995459..d1948071 100644 --- a/dist/docs/classes/Project.html +++ b/dist/docs/classes/Project.html @@ -504,7 +504,7 @@ type: PathItem, segment.point of Path items.

    options.handles: Boolean - Hit test for the handles (segment.handleIn / segment.handleOut) of path segments.

    diff --git a/dist/docs/classes/Raster.html b/dist/docs/classes/Raster.html index 21c0e17a..f54df035 100644 --- a/dist/docs/classes/Raster.html +++ b/dist/docs/classes/Raster.html @@ -393,7 +393,7 @@ effects.

    + + + + + + +

    HSL Components

    + +
    + + @@ -561,7 +597,7 @@ function onFrame(event) { diff --git a/dist/docs/classes/TextItem.html b/dist/docs/classes/TextItem.html index 1a9860a6..9654093b 100644 --- a/dist/docs/classes/TextItem.html +++ b/dist/docs/classes/TextItem.html @@ -772,6 +772,38 @@ already contained within a clipping group.

    +
    + + +
    + +
    @@ -1574,7 +1606,7 @@ miterLimit imposes a limit on the ratio of the miter length to the @@ -1590,7 +1622,7 @@ miterLimit imposes a limit on the ratio of the miter length to the var circle = new Path.Circle(new Point(80, 50), 35); // Set the fill color of the circle to RGB red: -circle.fillColor = new RGBColor(1, 0, 0); +circle.fillColor = new RgbColor(1, 0, 0);
    diff --git a/dist/docs/classes/index.html b/dist/docs/classes/index.html index 7e200530..871e0c3c 100644 --- a/dist/docs/classes/index.html +++ b/dist/docs/classes/index.html @@ -55,10 +55,10 @@

    Colors

  • Gradients

    diff --git a/dist/docs/resources/css/codemirror.css b/dist/docs/resources/css/codemirror.css index 0bf4a03b..98bbf7d3 100644 --- a/dist/docs/resources/css/codemirror.css +++ b/dist/docs/resources/css/codemirror.css @@ -92,24 +92,50 @@ span.CodeMirror-selected { span.cm-keyword { color: #ff7800; } -span.cm-number, -span.cm-atom { +span.cm-atom, +span.cm-number { color: #3b5bb5; } -span.cm-string { - color: #409b1c; -} -span.cm-comment { - color: #8c868f; -} -span.cm-property { - color: #000; -} -span.cm-variable { - color: #000; -} span.cm-def, span.cm-variable-2, span.cm-variable-3 { color: #3a4a64; } +span.cm-variable { + color: #000; +} +span.cm-property { + color: #000; +} +span.cm-operator { + color: #000; +} +span.cm-comment { + color: #8c868f; +} +span.cm-string { + color: #409b1c; +} +span.cm-meta { + color: #555; +} +span.cm-error { + color: #f30; +} +span.cm-qualifier { + color: #555; +} +span.cm-builtin { + color: #30a; +} +span.cm-bracket { + color: #cc7; +} +span.cm-tag { + font-weight: bold; + color: #3b5bb5; +} +span.cm-attribute { + font-style: italic; + color: #3b5bb5; +} diff --git a/dist/docs/resources/css/paperscript.css b/dist/docs/resources/css/paperscript.css index 7fe81134..c296c3c1 100644 --- a/dist/docs/resources/css/paperscript.css +++ b/dist/docs/resources/css/paperscript.css @@ -1,4 +1,5 @@ -.paperscript .button { +.paperscript .button, +.paperscript .explain { display: none; position: relative; /* position (top / right) relative to paperscriptcontainer */ float: right; /* align right as block */ @@ -6,18 +7,23 @@ line-height: 16px; padding: 2px 6px; margin-bottom: -20px; /* move canvas up by 16px (height) + 2 * 2px (padding) */ - top: 8px; /* margin to top */ - right: 8px; /* margin to right */ - background: #eee; border-radius: 4px; -moz-border-radius: 4px; -webkit-border-radius: 4px; z-index: 1; + top: 8px; /* margin to top */ } -.paperscript .source { - overflow: auto; - border: 1px solid #999; +.paperscript .button { + right: 8px; /* margin to right */ + background: #eee; +} + +.paperscript .explain { + display: block; + right: 64px; /* margin to right */ + background: #e3f4fc; + margin-bottom: -36px; /* (height) + 2 * 2px (padding) */ } .paperscript:hover .button { @@ -29,6 +35,11 @@ cursor: pointer; } +.paperscript .source { + overflow: auto; + border: 1px solid #999; +} + .paperscript .CodeMirror { margin: 0 !important; /* Override any potential margins again */ } diff --git a/dist/docs/resources/css/reference.css b/dist/docs/resources/css/reference.css index 4ba326fb..d9e152c3 100644 --- a/dist/docs/resources/css/reference.css +++ b/dist/docs/resources/css/reference.css @@ -17,12 +17,6 @@ .reference a tt { line-height: 18px; } -/* -.reference a tt, -.reference a tt b { - padding-bottom: 1px; -} -*/ .reference p { margin: 0 0 16px 0; @@ -58,6 +52,7 @@ * html .reference-packages img { margin-top: 5px; } + .reference-packages li { list-style: none; list-style-image: none; /* needed for ie 6 */ diff --git a/dist/docs/resources/js/codemirror.js b/dist/docs/resources/js/codemirror.js index a5c4ba10..0c1c6427 100644 --- a/dist/docs/resources/js/codemirror.js +++ b/dist/docs/resources/js/codemirror.js @@ -1 +1 @@ -var CodeMirror=function(){function H(a,b){if(a.indexOf)return a.indexOf(b);for(var c=0,d=a.length;c=0&&d>=0;--c,--d)if(a.charAt(c)!=b.charAt(d))break;return d+1}function F(a){return a.replace(/[<>&]/g,function(a){return a=="&"?"&":a=="<"?"<":">"})}function E(a){return{line:a.line,ch:a.ch}}function D(a,b){return a.linea&&d.push(h.slice(a-f,Math.min(h.length,b-f)),c[e+1]),i>=a&&(g=1)):g==1&&(i>b?d.push(h.slice(0,b-f),c[e+1]):d.push(h,c[e+1])),f=i}}function h(a,b){this.styles=b||[a,null],this.stateAfter=null,this.text=a,this.marked=this.gutterMarker=this.className=null}function g(a){this.pos=this.start=0,this.string=a}function f(a,b,c){return a.startState?a.startState(b,c):!0}function e(a,b){if(b===!0)return b;if(a.copyState)return a.copyState(b);var c={};for(var d in b){var e=b[d];e instanceof Array&&(e=e.concat([])),c[d]=e}return c}function a(b,c){function cO(a,b,c){this.atOccurrence=!1,c==null&&(c=typeof a=="string"&&a==a.toLowerCase()),b&&typeof b=="object"?b=cc(b):b={line:0,ch:0},this.pos={from:b,to:b};if(typeof a!="string")this.matches=function(b,c){if(b){var d=W[c.line].text.slice(0,c.ch),e=d.match(a),f=0;while(e){var g=d.indexOf(e[0]);f+=g,d=d.slice(g+1);var h=d.match(a);if(h)e=h;else break;f++}}else var d=W[c.line].text.slice(c.ch),e=d.match(a),f=e&&c.ch+d.indexOf(e[0]);if(e)return{from:{line:c.line,ch:f},to:{line:c.line,ch:f+e[0].length},match:e}};else{c&&(a=a.toLowerCase());var d=c?function(a){return a.toLowerCase()}:function(a){return a},e=a.split("\n");e.length==1?this.matches=function(b,c){var e=d(W[c.line].text),f=a.length,g;if(b?c.ch>=f&&(g=e.lastIndexOf(a,c.ch-f))!=-1:(g=e.indexOf(a,c.ch))!=-1)return{from:{line:c.line,ch:g},to:{line:c.line,ch:g+f}}}:this.matches=function(a,b){var c=b.line,f=a?e.length-1:0,g=e[f],h=d(W[c].text),i=a?h.indexOf(g)+g.length:h.lastIndexOf(g);if(!(a?i>=b.ch||i!=g.length:i<=b.ch||i!=h.length-g.length))for(;;){if(a?!c:c==W.length-1)return;h=d(W[c+=a?-1:1].text),g=e[a?--f:++f];if(f>0&&f=W.length)continue;var d=cF(c),h=d&&W[d-1].stateAfter;h?h=e(V,h):h=f(V);var i=0,j=V.compareStates;for(var k=d,l=W.length;ka){X.push(k),cJ(g.workDelay),bd.push({from:c,to:k});return}var o=m.highlight(V,h);m.stateAfter=e(V,h);if(j){if(n&&j(n,h))break}else if(o||!n)i=0;else if(++i>3)break}bd.push({from:c,to:k})}b&&g.onHighlightComplete&&g.onHighlightComplete(br)}function cH(a,b){var c=cG(a);for(var d=a;de;--d){if(d==0)return 0;var f=W[d-1];if(f.stateAfter)return d;var g=f.indentation();if(c==null||b>g)c=d,b=g}return c}function cE(a){function p(a,b,c){if(!!a.text){var d=a.styles,e=g?0:a.text.length-1,f;for(var i=g?0:d.length-2,j=g?d.length:-2;i!=j;i+=2*h){var k=d[i];if(d[i+1]!=null&&d[i+1]!=m){e+=h*k.length;continue}for(var l=g?0:k.length-1,p=g?k.length:-1;l!=p;l+=h,e+=h)if(e>=b&&e"==g)n.push(f);else{if(n.pop()!=q.charAt(0))return{pos:e,match:!1};if(!n.length)return{pos:e,match:!0}}}}}}var b=$.inverted?$.from:$.to,c=W[b.line],d=b.ch-1,e=d>=0&&cD[c.text.charAt(d)]||cD[c.text.charAt(++d)];if(!!e){var f=e.charAt(0),g=e.charAt(1)==">",h=g?1:-1,i=c.styles;for(var j=d+1,k=0,l=i.length;kz.clientWidth||e-c.top>z.clientHeight))return null;var f=A(P,!0),g=bh+Math.floor((e-f.top)/cx());return cc({line:g,ch:cu(cb(g),d-f.left)})}function cz(){return P.offsetLeft}function cy(){return P.offsetTop}function cx(){var a=R.childNodes.length;if(a)return R.offsetHeight/a||1;L.innerHTML="
    x
    ";return L.firstChild.offsetHeight||1}function cw(a){var b=cv(a,!0),c=A(P);return{x:c.left+b.x,y:c.top+b.y,yBot:c.top+b.yBot}}function cv(a,b){var c=cx(),d=a.line-(b?bh:0);return{x:ct(a.line,a.ch),y:d*c,yBot:(d+1)*c}}function cu(a,b){function e(a){L.innerHTML="
    "+c.getHTML(null,null,!1,a)+"
    ";return L.firstChild.firstChild.offsetWidth}if(b<=0)return 0;var c=W[a],d=c.text,f=0,g=0,h=d.length,i,j=Math.min(h,Math.ceil(b/cs("x")));for(;;){var k=e(j);if(k<=b&&ji)return h;j=Math.floor(h*.8),k=e(j),kb-g?f:h;var l=Math.ceil((f+h)/2),m=e(l);m>b?(h=l,i=m):(f=l,g=m)}}function ct(a,b){if(b==0)return 0;L.innerHTML="
    "+W[a].getHTML(null,null,!1,b)+"
    ";return L.firstChild.firstChild.offsetWidth}function cs(a){L.innerHTML="
    x
    ",L.firstChild.firstChild.firstChild.nodeValue=a;return L.firstChild.firstChild.offsetWidth||10}function cr(a){if(typeof a=="number"){var b=a;a=W[a];if(!a)return null}else{var b=H(W,a);if(b==-1)return null}var c=a.gutterMarker;return{line:b,text:a.text,markerText:c&&c.text,markerClass:c&&c.style}}function cq(a,b){if(typeof a=="number"){var c=a;a=W[cb(a)]}else{var c=H(W,a);if(c==-1)return null}a.className!=b&&(a.className=b,bd.push({from:c,to:c+1}));return a}function cp(a){typeof a=="number"&&(a=W[cb(a)]),a.gutterMarker=null,bY()}function co(a,b,c){typeof a=="number"&&(a=W[cb(a)]),a.gutterMarker={text:b,style:c},bY();return a}function cn(a,b,c){function e(a,b,c,e){var a=W[a],f=a.addMark(b,c,e);f.line=a,d.push(f)}a=cc(a),b=cc(b);var d=[];if(a.line==b.line)e(a.line,a.ch,b.ch,c);else{e(a.line,a.ch,null,c);for(var f=a.line+1,g=b.line;f-1&&(a==null&&(a=f),b=f)}a!=null&&bd.push({from:a,to:b+1})}}function cm(){var a=g.gutter||g.lineNumbers;N.style.display=a?"":"none",a?bY():R.parentNode.style.marginLeft=0}function cl(){V=a.getMode(g,g.mode);for(var b=0,c=W.length;b0&&/\w/.test(b.charAt(c-1)))--c;while(d=W.length)return{line:W.length-1,ch:W[W.length-1].text.length};var b=a.ch,c=W[a.line].text.length;return b==null||b>c?{line:a.line,ch:c}:b<0?{line:a.line,ch:0}:a}function cb(a){return Math.max(0,Math.min(a,W.length-1))}function ca(a,b,c){var d=cc({line:a,ch:b||0});(c?b$:b_)(d,d)}function b_(a,b,c,d){if(!C($.from,a)||!C($.to,b)){if(D(b,a)){var e=b;b=a,a=e}C(a,b)?$.inverted=!1:C(a,$.to)?$.inverted=!1:C(b,$.from)&&($.inverted=!0),c==null&&(c=$.from.line,d=$.to.line),C(a,b)?C($.from,$.to)||bd.push({from:c,to:d+1}):C($.from,$.to)?bd.push({from:a.line,to:b.line+1}):(C(a,$.from)||(a.line':"
    ",f,"
    ")}N.style.display="none",O.innerHTML=c.join("");var h=String(W.length).length,i=O.firstChild,j=B(i),k="";while(j.length+k.length0;--k)R.removeChild(j?j.previousSibling:R.lastChild);else if(i){for(var k=Math.max(0,i);k>0;--k)R.insertBefore(m.createElement("pre"),j);for(var k=Math.max(0,-i);k>0;--k)R.removeChild(j?j.previousSibling:R.lastChild)}var l=R.childNodes[h.domStart+d],n=b=h.from;for(var k=h.from;kj.from&&f.push({from:j.from,to:e.from,domStart:j.domStart}),e.to=m)break;if(j.domStart>o||j.from>q)n.push({from:q,to:j.from,domSize:j.domStart-o,domStart:o}),r+=j.from-q;q=j.to,o=j.domStart+(j.to-j.from)}if(o!=p||q!=m)r+=Math.abs(m-q),n.push({from:q,to:m,domSize:p-o,domStart:o});if(!n.length)return;R.style.display="none",r>(k.to-k.from)*.3?bW(l=Math.max(k.from-10,0),m=Math.min(k.to+7,W.length)):bX(n),R.style.display="";var s=l!=bh||m!=bi||bj!=z.clientHeight;bh=l,bi=m,M.style.top=l*cx()+"px",s&&(bj=z.clientHeight,F.style.height=W.length*cx()+2*cy()+"px",bY());var t=cs(bn);P.style.width=t>z.clientWidth?t+"px":"";if(R.childNodes.length!=bi-bh)throw new Error("BAD PATCH! "+JSON.stringify(n)+" size="+(bi-bh)+" nodes="+R.childNodes.length);bZ()}}function bU(){var a=cx(),b=z.scrollTop-cy();return{from:Math.min(W.length,Math.max(0,Math.floor(b/a))),to:Math.min(W.length,Math.ceil((b+z.clientHeight)/a))}}function bT(a,b,c,d){var e=cz(),f=cy(),h=cx();b+=f,d+=f,a+=e,c+=e;var i=z.clientHeight,j=z.scrollTop,k=!1,l=!0;bj+i&&(z.scrollTop=d+h-i,k=!0);var m=z.clientWidth,n=z.scrollLeft;am+n&&(z.scrollLeft=c+10-m,k=!0,c>F.clientWidth&&(l=!1)),k&&g.onScroll&&g.onScroll(br);return l}function bS(){var a=cv($.inverted?$.from:$.to);return bT(a.x,a.y,a.x,a.yBot)}function bR(){g.readOnly!="nocursor"&&y.focus()}function bQ(){var a=[],b=Math.max(0,$.from.line-1),c=Math.min(W.length,$.to.line+2);for(var d=b;d=a)return{line:c,ch:a-d};++c,d=e+1}}if(!bg){var a=!1,b=y.value,c=J(y);if(!c)return!1;var a=bl.text!=b,d=ba,e=a||c.start!=bl.start||c.end!=(d?bl.start:bl.end);if(!e&&!d)return!1;if(a){_=ba=null;if(g.readOnly){bc=!0;return"changed"}}var h=f(c.start,bl.from),i=f(c.end,bl.from);if(d){var j=c.start==d.anchor?i:h,k=_?$.to:c.start==d.anchor?h:i;($.inverted=D(j,k))?(h=j,i=k):(ba=null,h=k,i=j)}h.line==i.line&&h.line==$.from.line&&h.line==$.to.line&&!_&&(bc=!1);if(a){var l=0,m=b.length,n=Math.min(m,bl.text.length),o,p=bl.from,q=-1;while(l-1?l-q:l,s=bl.to-1,t=bl.text.length;for(;;){o=bl.text.charAt(t);if(b.charAt(m)!=o){++m,++t;break}o=="\n"&&s--;if(t<=l||m<=l)break;--m,--t}var q=bl.text.lastIndexOf("\n",t-1),u=q==-1?t:t-q-1;bC({line:p,ch:r},{line:s,ch:u},I(b.slice(l,m)),h,i);if(p!=s||h.line!=p)bc=!0}else b_(h,i);bl.text=b,bl.start=c.start,bl.end=c.end;return a?"changed":e?"moved":!1}}function bO(a){function c(){cK();var d=bP();d=="moved"&&a&&(w[a]=!0),!d&&!b?(b=!0,S.set(80,c)):(bM=!1,bN()),cL()}var b=!1;bM=!0,S.set(20,c)}function bN(){bM||S.set(2e3,function(){cK(),bP(),Z&&bN(),cL()})}function bL(){return bK($.from,$.to)}function bK(a,b){var c=a.line,d=b.line;if(c==d)return W[c].text.slice(a.ch,b.ch);var e=[W[c].text.slice(a.ch)];for(var f=c+1;fg&&(bn=o,g=o.length,f=!1)}if(f){g=0,bn="";for(var i=0,n=W.length;ig&&(g=o.length,bn=o)}}var p=[],q=c.length-j-1;for(var i=0,o=X.length;ib.line&&p.push(r+q)}c.length<5?(cH(a.line,a.line+c.length),p.push(a.line+c.length)):p.push(a.line),X=p,cJ(100),bd.push({from:a.line,to:b.line+1,diff:q}),be={from:a,to:b,text:c},b_(d,e,s($.from.line),s($.to.line)),F.style.height=W.length*cx()+2*cy()+"px"}function bF(){bD(Y.undone,Y.done)}function bE(){bD(Y.done,Y.undone)}function bD(a,b){var c=a.pop();if(c){var d=[],e=c.start+c.added;for(var f=c.start;fg.undoDepth)Y.done.shift()}bG(a,b,c,d,e)}function bB(){Z&&(g.onBlur&&g.onBlur(br),Z=!1,s.className=s.className.replace(" CodeMirror-focused","")),clearInterval(U),setTimeout(function(){Z||(_=null)},150)}function bA(){g.readOnly!="nocursor"&&(Z||(g.onFocus&&g.onFocus(br),Z=!0,s.className.search(/\bCodeMirror-focused\b/)==-1&&(s.className+=" CodeMirror-focused"),bg||bQ()),bN(),cC())}function bz(a){if(!g.onKeyEvent||!g.onKeyEvent(br,l(a.e))){if(g.electricChars&&V.electricChars){var b=String.fromCharCode(a.e.charCode==null?a.e.keyCode:a.e.charCode);V.electricChars.indexOf(b)>-1&&setTimeout(cN(function(){ck($.to.line,"smart")}),50)}var c=a.e.keyCode;c==13?(g.readOnly||ci(),a.stop()):!a.e.ctrlKey&&!a.e.altKey&&!a.e.metaKey&&c==9&&g.tabMode!="default"?a.stop():bO(bk)}}function by(a){if(!g.onKeyEvent||!g.onKeyEvent(br,l(a.e)))ba&&(ba=null,bc=!0),a.e.keyCode==16&&(_=null)}function bx(a){Z||bA();var b=a.e.keyCode;r&&b==27&&(a.e.returnValue=!1);var c=(v?a.e.metaKey:a.e.ctrlKey)&&!a.e.altKey,d=a.e.ctrlKey||a.e.altKey||a.e.metaKey;b==16||a.e.shiftKey?_=_||($.inverted?$.to:$.from):_=null;if(!g.onKeyEvent||!g.onKeyEvent(br,l(a.e))){if(b==33||b==34){cd(b==34);return a.stop()}if(c&&(b==36||b==35||v&&(b==38||b==40))){ce(b==36||b==38);return a.stop()}if(c&&b==65){cf();return a.stop()}if(!g.readOnly){if(!d&&b==13)return;if(!d&&b==9&&cj(a.e.shiftKey))return a.stop();if(c&&b==90){bE();return a.stop()}if(c&&(a.e.shiftKey&&b==90||b==89)){bF();return a.stop()}}bk=(c?"c":"")+b;if($.inverted&&w.hasOwnProperty(bk)){var e=J(y);e&&(ba={anchor:e.start},K(y,e.start,e.start))}bO(bk)}}function bw(a){a.e.preventDefault();var b=cA(a,!0),c=a.e.dataTransfer.files;if(!!b&&!g.readOnly)if(c&&c.length&&window.FileReader&&window.File){function d(a,c){var d=new FileReader;d.onload=function(){f[c]=d.result,++h==e&&bH(f.join(""),cc(b),cc(b))},d.readAsText(a)}var e=c.length,f=Array(e),h=0;for(var i=0;i=c.to||b.line=0&&a
    '+'
    '+'
    '+'
    '+'
    '+'
    '+'
     
    '+"
    "+"
    ",b.appendChild?b.appendChild(s):b(s);var x=s.firstChild,y=x.firstChild,z=s.lastChild,F=z.firstChild,L=F.firstChild,M=L.nextSibling,N=M.firstChild,O=N.firstChild,P=N.nextSibling.firstChild,Q=P.firstChild,R=Q.nextSibling;g.tabindex!=null&&(y.tabindex=g.tabindex),!g.gutter&&!g.lineNumbers&&(N.style.display="none");var S=new o,T=new o,U,V,W=[new h("")],X,Y=new j,Z;cl();var $={from:{line:0,ch:0},to:{line:0,ch:0},inverted:!1},_,ba,bb,bc,bd,be,bf,bg,bh=0,bi=0,bj=0,bk=null,bl,bm,bn="";cN(function(){bs(g.value||""),bc=!1})(),n(z,"mousedown",cN(bu)),q||n(z,"contextmenu",cB),n(F,"dblclick",cN(bv)),n(z,"scroll",function(){bV([]),g.onScroll&&g.onScroll(br)}),n(window,"resize",function(){bV(!0)}),n(y,"keyup",cN(by)),n(y,"keydown",cN(bx)),n(y,"keypress",cN(bz)),n(y,"focus",bA),n(y,"blur",bB),n(z,"dragenter",function(a){a.stop()}),n(z,"dragover",function(a){a.stop()}),n(z,"drop",cN(bw)),n(z,"paste",function(){bR(),bO()}),n(y,"paste",function(){bO()}),n(y,"cut",function(){bO()});var bo;try{bo=m.activeElement==y}catch(bp){}bo?setTimeout(bA,20):bB();var br={getValue:bt,setValue:cN(bs),getSelection:bL,replaceSelection:cN(bI),focus:function(){bR(),bA(),bO()},setOption:function(a,b){g[a]=b,a=="lineNumbers"||a=="gutter"?cm():a=="mode"||a=="indentUnit"?cl():a=="readOnly"&&b=="nocursor"?y.blur():a=="theme"&&(z.className=z.className.replace(/cm-s-\w+/,"cm-s-"+b))},getOption:function(a){return g[a]},undo:cN(bE),redo:cN(bF),indentLine:cN(function(a){bq(a)&&ck(a,"smart")}),historySize:function(){return{undo:Y.done.length,redo:Y.undone.length}},matchBrackets:cN(function(){cE(!0)}),getTokenAt:function(a){a=cc(a);return W[a.line].getTokenAt(V,cG(a.line),a.ch)},getStateAfter:function(a){a=cb(a==null?W.length-1:a);return cG(a+1)},cursorCoords:function(a){a==null&&(a=$.inverted);return cw(a?$.from:$.to)},charCoords:function(a){return cw(cc(a))},coordsChar:function(a){var b=A(P),c=cb(Math.min(W.length-1,bh+Math.floor((a.y-b.top)/cx())));return cc({line:c,ch:cu(cb(c),a.x-b.left)})},getSearchCursor:function(a,b,c){return new cO(a,b,c)},markText:cN(function(a,b,c){return cN(cn(a,b,c))}),setMarker:co,clearMarker:cp,setLineClass:cN(cq),lineInfo:cr,addWidget:function(a,b,c){a=cc(a);var d=cv(a,!0);b.style.top=bh*cx()+d.yBot+cy()+"px",b.style.left=d.x+cz()+"px",F.appendChild(b);if(c){var e=cv(a);bT(e.x,e.yBot,e.x+b.offsetWidth,e.yBot+b.offsetHeight)}},lineCount:function(){return W.length},getCursor:function(a){a==null&&(a=$.inverted);return E(a?$.from:$.to)},somethingSelected:function(){return!C($.from,$.to)},setCursor:cN(function(a,b){b==null&&typeof a.line=="number"?ca(a.line,a.ch):ca(a,b)}),setSelection:cN(function(a,b){b_(cc(a),cc(b||a))}),getLine:function(a){if(bq(a))return W[a].text},setLine:cN(function(a,b){bq(a)&&bH(b,{line:a,ch:0},{line:a,ch:W[a].text.length})}),removeLine:cN(function(a){bq(a)&&bH("",{line:a,ch:0},cc({line:a+1,ch:0}))}),replaceRange:cN(bH),getRange:function(a,b){return bK(cc(a),cc(b))},operation:function(a){return cN(a)()},refresh:function(){bV(!0)},getInputField:function(){return y},getWrapperElement:function(){return s},getScrollerElement:function(){return z}},bM=!1,cD={"(":")>",")":"(<","[":"]>","]":"[<","{":"}>","}":"{<"},cM=0;cO.prototype={findNext:function(){return this.find(!1)},findPrevious:function(){return this.find(!0)},find:function(a){function d(a){var c={line:a,ch:0};b.pos={from:c,to:c},b.atOccurrence=!1;return!1}var b=this,c=cc(a?this.pos.from:this.pos.to);for(;;){if(this.pos=this.matches(a,c)){this.atOccurrence=!0;return this.pos.match||!0}if(a){if(!c.line)return d(0);c={line:c.line-1,ch:W[c.line-1].text.length}}else{if(c.line==W.length-1)return d(W.length);c={line:c.line+1,ch:0}}}},from:function(){if(this.atOccurrence)return E(this.pos.from)},to:function(){if(this.atOccurrence)return E(this.pos.to)},replace:function(a){var b=this;this.atOccurrence&&cN(function(){b.pos.to=bH(a,b.pos.from,b.pos.to)})()}};for(var cP in d)d.propertyIsEnumerable(cP)&&!br.propertyIsEnumerable(cP)&&(br[cP]=d[cP]);return br}a.defaults={value:"",mode:null,theme:"default",indentUnit:2,indentWithTabs:!1,tabMode:"classic",enterMode:"indent",electricChars:!0,onKeyEvent:null,lineNumbers:!1,gutter:!1,firstLineNumber:1,readOnly:!1,onChange:null,onCursorActivity:null,onGutterClick:null,onHighlightComplete:null,onFocus:null,onBlur:null,onScroll:null,matchBrackets:!1,workTime:100,workDelay:200,undoDepth:40,tabindex:null,document:window.document};var b={},c={};a.defineMode=function(c,d){!a.defaults.mode&&c!="null"&&(a.defaults.mode=c),b[c]=d},a.defineMIME=function(a,b){c[a]=b},a.getMode=function(d,e){typeof e=="string"&&c.hasOwnProperty(e)&&(e=c[e]);if(typeof e=="string")var f=e,g={};else if(e!=null)var f=e.name,g=e;var h=b[f];if(!h){window.console&&console.warn("No mode "+f+" found, falling back to plain text.");return a.getMode(d,"text/plain")}return h(d,g||{})},a.listModes=function(){var a=[];for(var c in b)b.propertyIsEnumerable(c)&&a.push(c);return a},a.listMIMEs=function(){var a=[];for(var b in c)c.propertyIsEnumerable(b)&&a.push(b);return a};var d={};a.defineExtension=function(a,b){d[a]=b},a.fromTextArea=function(b,c){function d(){b.value=h.getValue()}c||(c={}),c.value=b.value,!c.tabindex&&b.tabindex&&(c.tabindex=b.tabindex);if(b.form){var e=n(b.form,"submit",d,!0);if(typeof b.form.submit=="function"){var f=b.form.submit;function g(){d(),b.form.submit=f,b.form.submit(),b.form.submit=g}b.form.submit=g}}b.style.display="none";var h=a(function(a){b.parentNode.insertBefore(a,b.nextSibling)},c);h.save=d,h.toTextArea=function(){d(),b.parentNode.removeChild(h.getWrapperElement()),b.style.display="",b.form&&(e(),typeof b.form.submit=="function"&&(b.form.submit=f))};return h},a.startState=f,a.copyState=e,g.prototype={eol:function(){return this.pos>=this.string.length},sol:function(){return this.pos==0},peek:function(){return this.string.charAt(this.pos)},next:function(){if(this.posb},eatSpace:function(){var a=this.pos;while(/[\s\u00a0]/.test(this.string.charAt(this.pos)))++this.pos;return this.pos>a},skipToEnd:function(){this.pos=this.string.length},skipTo:function(a){var b=this.string.indexOf(a,this.pos);if(b>-1){this.pos=b;return!0}},backUp:function(a){this.pos-=a},column:function(){return y(this.string,this.start)},indentation:function(){return y(this.string)},match:function(a,b,c){if(typeof a!="string"){var e=this.string.slice(this.pos).match(a);e&&b!==!1&&(this.pos+=e[0].length);return e}function d(a){return c?a.toLowerCase():a}if(d(this.string).indexOf(d(a),this.pos)==this.pos){b!==!1&&(this.pos+=a.length);return!0}},current:function(){return this.string.slice(this.start,this.pos)}},a.StringStream=g,h.prototype={replace:function(a,b,c){var d=[],e=this.marked;i(0,a,this.styles,d),c&&d.push(c,null),i(b,this.text.length,this.styles,d),this.styles=d,this.text=this.text.slice(0,a)+c+this.text.slice(b),this.stateAfter=null;if(e){var f=c.length-(b-a),g=this.text.length;function h(a){return a<=Math.min(b,b+f)?a:a+f}for(var j=0;j=g?l=!0:(k.from=h(k.from),k.to!=null&&(k.to=h(k.to)));if(l||k.from>=k.to)e.splice(j,1),j--}}},split:function(a,b){var c=[b,null];i(a,this.text.length,this.styles,c);return new h(b+this.text.slice(a),c)},addMark:function(a,b,c){var d=this.marked,e={from:a,to:b,style:c};this.marked==null&&(this.marked=[]),this.marked.push(e),this.marked.sort(function(a,b){return a.from-b.from});return e},removeMark:function(a){var b=this.marked;if(!!b)for(var c=0;c5e3){d[e++]=this.text.slice(c.pos),d[e++]=null;break}}d.length!=e&&(d.length=e,f=!0),e&&d[e-2]!=i&&(f=!0);return f||d.length<5&&this.text.length<10},getTokenAt:function(a,b,c){var d=this.text,e=new g(d);while(e.pos',F(a),""):e.push(F(a)))}var e=[];c&&e.push(this.className?'
    ':"
    ");var g=this.styles,h=this.text,i=this.marked;a==b&&(a=null);var j=h.length;d!=null&&(j=Math.min(d,j));if(!h&&d==null)f(" ",a!=null&&b==null?"CodeMirror-selected":null);else if(!i&&a==null)for(var k=0,l=0;lj&&(m=m.slice(0,j-l)),l+=n,f(m,g[k+1])}else{var o=0,k=0,p="",q,r=0,s=-1,t=null;function u(){i&&(s+=1,t=so)v=a;else if(b==null||b>o)w=" CodeMirror-selected",b!=null&&(v=Math.min(v,b));while(t&&t.to!=null&&t.to<=o)u();t&&(t.from>o?v=Math.min(v,t.from):(w+=" "+t.style,t.to!=null&&(v=Math.min(v,t.to))));for(;;){var x=o+p.length,y=q;w&&(y=q?q+w:w),f(x>v?p.slice(0,v-o):p,y);if(x>=v){p=p.slice(v-o),o=v;break}o=x,p=g[k++],q=g[k++]}}a!=null&&b==null&&f(" ","CodeMirror-selected")}c&&e.push("
    ");return e.join("")}},j.prototype={addChange:function(a,b,c){this.undone.length=0;var d=+(new Date),e=this.done[this.done.length-1];if(d-this.time>400||!e||e.start>a+b||e.start+e.added=0;--g)e.old.unshift(c[g]);e.added+=e.start-a,e.start=a}else e.start-1&&(t="\r\n")})();var u=8,v=/Mac/.test(navigator.platform),w={};for(var x=35;x<=40;++x)w[x]=w["c"+x]=!0;a.htmlEscape=F;if("\n\nb".split(/\n/).length!=3)var I=function(a){var b=0,c,d=[];while((c=a.indexOf("\n",b))>-1)d.push(a.slice(b,a.charAt(c-1)=="\r"?c-1:c)),b=c+1;d.push(a.slice(b));return d};else var I=function(a){return a.split(/\r?\n/)};a.splitLines=I;if(window.getSelection){var J=function(a){try{return{start:a.selectionStart,end:a.selectionEnd}}catch(b){return null}};if(s)var K=function(a,b,c){b==c?a.setSelectionRange(b,c):(a.setSelectionRange(b,c-1),window.getSelection().modify("extend","forward","character"))};else var K=function(a,b,c){try{a.setSelectionRange(b,c)}catch(d){}}}else var J=function(a){try{var b=a.ownerDocument.selection.createRange()}catch(c){return null}if(!b||b.parentElement()!=a)return null;var d=a.value,e=d.length,f=a.createTextRange();f.moveToBookmark(b.getBookmark());var g=a.createTextRange();g.collapse(!1);if(f.compareEndPoints("StartToEnd",g)>-1)return{start:e,end:e};var h=-f.moveStart("character",-e);for(var i=d.indexOf("\r");i>-1&&i-1)return{start:h,end:e};var j=-f.moveEnd("character",-e);for(var i=d.indexOf("\r");i>-1&&i-1&&h-1&&h=0;a--)s.cc.push(arguments[a])}function r(a,b,c,e,f){var g=a.cc;s.state=a,s.stream=f,s.marked=null,s.cc=g,a.lexical.hasOwnProperty("align")||(a.lexical.align=!0);for(;;){var h=g.length?g.pop():d?D:C;if(h(c,e)){while(g.length&&g[g.length-1].lex)g.pop()();if(s.marked)return s.marked;if(c=="variable"&&q(a,e))return"variable-2";return b}}}function q(a,b){for(var c=a.localVars;c;c=c.next)if(c.name==b)return!0}function p(a,b,c,d,e,f){this.indented=a,this.column=b,this.type=c,this.prev=e,this.info=f,d!=null&&(this.align=d)}function n(a,b){var c=!1,d;while(d=a.next()){if(d=="/"&&c){b.tokenize=l;break}c=d=="*"}return k("comment","comment")}function m(a){return function(b,c){h(b,a)||(c.tokenize=l);return k("string","string")}}function l(a,b){var c=a.next();if(c=='"'||c=="'")return g(a,b,m(c));if(/[\[\]{}\(\),;\:\.]/.test(c))return k(c);if(c=="0"&&a.eat(/x/i)){a.eatWhile(/[\da-f]/i);return k("number","atom")}if(/\d/.test(c)){a.match(/^\d*(?:\.\d*)?(?:e[+\-]?\d+)?/);return k("number","atom")}if(c=="/"){if(a.eat("*"))return g(a,b,n);if(a.eat("/")){a.skipToEnd();return k("comment","comment")}if(b.reAllowed){h(a,"/"),a.eatWhile(/[gimy]/);return k("regexp","string")}a.eatWhile(f);return k("operator",null,a.current())}if(f.test(c)){a.eatWhile(f);return k("operator",null,a.current())}a.eatWhile(/[\w\$_]/);var d=a.current(),i=e.propertyIsEnumerable(d)&&e[d];return i?k(i.type,i.style,d):k("variable","variable",d)}function k(a,b,c){i=a,j=c;return b}function h(a,b){var c=!1,d;while((d=a.next())!=null){if(d==b&&!c)return!1;c=!c&&d=="\\"}return c}function g(a,b,c){b.tokenize=c;return c(a,b)}var c=a.indentUnit,d=b.json,e=function(){function a(a){return{type:a,style:"keyword"}}var b=a("keyword a"),c=a("keyword b"),d=a("keyword c"),e=a("operator"),f={type:"atom",style:"atom"};return{"if":b,"while":b,"with":b,"else":c,"do":c,"try":c,"finally":c,"return":d,"break":d,"continue":d,"new":d,"delete":d,"throw":d,"var":a("var"),"function":a("function"),"catch":a("catch"),"for":a("for"),"switch":a("switch"),"case":a("case"),"default":a("default"),"in":e,"typeof":e,"instanceof":e,"true":f,"false":f,"null":f,"undefined":f,NaN:f,Infinity:f}}(),f=/[+\-*&%=<>!?|]/,i,j,o={atom:!0,number:!0,variable:!0,string:!0,regexp:!0},s={state:null,column:null,marked:null,cc:null},w={name:"this",next:{name:"arguments"}};A.lex=!0;return{startState:function(a){return{tokenize:l,reAllowed:!0,cc:[],lexical:new p((a||0)-c,0,"block",!1),localVars:null,context:null,indented:0}},token:function(a,b){a.sol()&&(b.lexical.hasOwnProperty("align")||(b.lexical.align=!1),b.indented=a.indentation());if(a.eatSpace())return null;var c=b.tokenize(a,b);if(i=="comment")return c;b.reAllowed=i=="operator"||i=="keyword c"||i.match(/^[\[{}\(,;:]$/);return r(b,c,i,j,a)},indent:function(a,b){if(a.tokenize!=l)return 0;var d=b&&b.charAt(0),e=a.lexical,f=e.type,g=d==f;return f=="vardef"?e.indented+4:f=="form"&&d=="{"?e.indented:f=="stat"||f=="form"?e.indented+c:e.info=="switch"&&!g?e.indented+(/^(?:case|default)\b/.test(b)?c:2*c):e.align?e.column+(g?0:1):e.indented+(g?0:c)},electricChars:":{}"}}),CodeMirror.defineMIME("text/javascript","javascript"),CodeMirror.defineMIME("application/json",{name:"javascript",json:!0}) \ No newline at end of file +var CodeMirror=function(){function O(a,b){if(a.indexOf)return a.indexOf(b);for(var c=0,d=a.length;c=0&&d>=0;--c,--d)if(a.charAt(c)!=b.charAt(d))break;return d+1}function M(a){L.innerText=L.textContent=a;return L.innerHTML}function K(a){return{line:a.line,ch:a.ch}}function J(a,b){return a.linea&&d.push(h.slice(a-f,Math.min(h.length,b-f)),c[e+1]),i>=a&&(g=1)):g==1&&(i>b?d.push(h.slice(0,b-f),c[e+1]):d.push(h,c[e+1])),f=i}}function h(a,b){this.styles=b||[a,null],this.stateAfter=null,this.text=a,this.marked=this.gutterMarker=this.className=null}function g(a){this.pos=this.start=0,this.string=a}function f(a,b,c){return a.startState?a.startState(b,c):!0}function e(a,b){if(b===!0)return b;if(a.copyState)return a.copyState(b);var c={};for(var d in b){var e=b[d];e instanceof Array&&(e=e.concat([])),c[d]=e}return c}function a(b,c){function cV(a,b,c){this.atOccurrence=!1,c==null&&(c=typeof a=="string"&&a==a.toLowerCase()),b&&typeof b=="object"?b=cj(b):b={line:0,ch:0},this.pos={from:b,to:b};if(typeof a!="string")this.matches=function(b,c){if(b){var d=ba[c.line].text.slice(0,c.ch),e=d.match(a),f=0;while(e){var g=d.indexOf(e[0]);f+=g,d=d.slice(g+1);var h=d.match(a);if(h)e=h;else break;f++}}else var d=ba[c.line].text.slice(c.ch),e=d.match(a),f=e&&c.ch+d.indexOf(e[0]);if(e)return{from:{line:c.line,ch:f},to:{line:c.line,ch:f+e[0].length},match:e}};else{c&&(a=a.toLowerCase());var d=c?function(a){return a.toLowerCase()}:function(a){return a},e=a.split("\n");e.length==1?this.matches=function(b,c){var e=d(ba[c.line].text),f=a.length,g;if(b?c.ch>=f&&(g=e.lastIndexOf(a,c.ch-f))!=-1:(g=e.indexOf(a,c.ch))!=-1)return{from:{line:c.line,ch:g},to:{line:c.line,ch:g+f}}}:this.matches=function(a,b){var c=b.line,f=a?e.length-1:0,g=e[f],h=d(ba[c].text),i=a?h.indexOf(g)+g.length:h.lastIndexOf(g);if(!(a?i>=b.ch||i!=g.length:i<=b.ch||i!=h.length-g.length))for(;;){if(a?!c:c==ba.length-1)return;h=d(ba[c+=a?-1:1].text),g=e[a?--f:++f];if(f>0&&f=ba.length)continue;var d=cM(c),h=d&&ba[d-1].stateAfter;h?h=e(_,h):h=f(_);var i=0,j=_.compareStates;for(var k=d,l=ba.length;ka){bb.push(k),cQ(g.workDelay),bj.push({from:c,to:k+1});return}var o=m.highlight(_,h);m.stateAfter=e(_,h);if(j){if(n&&j(n,h))break}else if(o||!n)i=0;else if(++i>3)break}bj.push({from:c,to:k+1})}b&&g.onHighlightComplete&&g.onHighlightComplete(by)}function cO(a,b){var c=cN(a);for(var d=a;de;--d){if(d==0)return 0;var f=ba[d-1];if(f.stateAfter)return d;var g=f.indentation();if(c==null||b>g)c=d,b=g}return c}function cL(a){function p(a,b,c){if(!!a.text){var d=a.styles,e=g?0:a.text.length-1,f;for(var i=g?0:d.length-2,j=g?d.length:-2;i!=j;i+=2*h){var k=d[i];if(d[i+1]!=null&&d[i+1]!=m){e+=h*k.length;continue}for(var l=g?0:k.length-1,p=g?k.length:-1;l!=p;l+=h,e+=h)if(e>=b&&e"==g)n.push(f);else{if(n.pop()!=q.charAt(0))return{pos:e,match:!1};if(!n.length)return{pos:e,match:!0}}}}}}var b=be.inverted?be.from:be.to,c=ba[b.line],d=b.ch-1,e=d>=0&&cK[c.text.charAt(d)]||cK[c.text.charAt(++d)];if(!!e){var f=e.charAt(0),g=e.charAt(1)==">",h=g?1:-1,i=c.styles;for(var j=d+1,k=0,l=i.length;kF.clientWidth||e-c.top>F.clientHeight))return null;var f=G(V,!0),g=bn+Math.floor((e-f.top)/cE());return cj({line:g,ch:cB(ci(g),d-f.left)})}function cG(){return V.offsetLeft}function cF(){return V.offsetTop}function cE(){var a=X.childNodes.length;if(a)return X.offsetHeight/a||1;M.innerHTML="
    x
    ";return M.firstChild.offsetHeight||1}function cD(a){var b=cC(a,!0),c=G(V);return{x:c.left+b.x,y:c.top+b.y,yBot:c.top+b.yBot}}function cC(a,b){var c=cE(),d=a.line-(b?bn:0);return{x:cA(a.line,a.ch),y:d*c,yBot:(d+1)*c}}function cB(a,b){function e(a){M.innerHTML="
    "+c.getHTML(null,null,!1,a)+"
    ";return M.firstChild.firstChild.offsetWidth}if(b<=0)return 0;var c=ba[a],d=c.text,f=0,g=0,h=d.length,i,j=Math.min(h,Math.ceil(b/cz("x")));for(;;){var k=e(j);if(k<=b&&ji)return h;j=Math.floor(h*.8),k=e(j),kb-g?f:h;var l=Math.ceil((f+h)/2),m=e(l);m>b?(h=l,i=m):(f=l,g=m)}}function cA(a,b){if(b==0)return 0;M.innerHTML="
    "+ba[a].getHTML(null,null,!1,b)+"
    ";return M.firstChild.firstChild.offsetWidth}function cz(a){M.innerHTML="
    x
    ",M.firstChild.firstChild.firstChild.nodeValue=a;return M.firstChild.firstChild.offsetWidth||10}function cy(a){if(typeof a=="number"){var b=a;a=ba[a];if(!a)return null}else{var b=O(ba,a);if(b==-1)return null}var c=a.gutterMarker;return{line:b,text:a.text,markerText:c&&c.text,markerClass:c&&c.style}}function cx(a,b){if(typeof a=="number"){var c=a;a=ba[ci(a)]}else{var c=O(ba,a);if(c==-1)return null}a.className!=b&&(a.className=b,bj.push({from:c,to:c+1}));return a}function cw(a){typeof a=="number"&&(a=ba[ci(a)]),a.gutterMarker=null,cd()}function cv(a,b,c){typeof a=="number"&&(a=ba[ci(a)]),a.gutterMarker={text:b,style:c},cd();return a}function cu(a,b,c){function e(a,b,c,e){var a=ba[a],f=a.addMark(b,c,e);f.line=a,d.push(f)}a=cj(a),b=cj(b);var d=[];if(a.line==b.line)e(a.line,a.ch,b.ch,c);else{e(a.line,a.ch,null,c);for(var f=a.line+1,g=b.line;f-1&&(a==null&&(a=f),b=f)}a!=null&&bj.push({from:a,to:b+1})}}function ct(){var a=g.gutter||g.lineNumbers;T.style.display=a?"":"none",a?cd():X.parentNode.style.marginLeft=0}function cs(){_=a.getMode(g,g.mode);for(var b=0,c=ba.length;b0&&/\w/.test(b.charAt(c-1)))--c;while(d=ba.length)return{line:ba.length-1,ch:ba[ba.length-1].text.length};var b=a.ch,c=ba[a.line].text.length;return b==null||b>c?{line:a.line,ch:c}:b<0?{line:a.line,ch:0}:a}function ci(a){return Math.max(0,Math.min(a,ba.length-1))}function ch(a,b,c){var d=cj({line:a,ch:b||0});(c?cf:cg)(d,d)}function cg(a,b,c,d){if(!I(be.from,a)||!I(be.to,b)){if(J(b,a)){var e=b;b=a,a=e}I(a,b)?be.inverted=!1:I(a,be.to)?be.inverted=!1:I(b,be.from)&&(be.inverted=!0),c==null&&(c=be.from.line,d=be.to.line),I(a,b)?I(be.from,be.to)||bj.push({from:c,to:d+1}):I(be.from,be.to)?bj.push({from:a.line,to:b.line+1}):(I(a,be.from)||(a.line':"
    ",f,"
    ")}T.style.display="none",U.innerHTML=c.join("");var h=String(ba.length).length,i=U.firstChild,j=H(i),k="";while(j.length+k.length0;--k)X.removeChild(j?j.previousSibling:X.lastChild);else if(i){for(var k=Math.max(0,i);k>0;--k)X.insertBefore(n.createElement("pre"),j);for(var k=Math.max(0,-i);k>0;--k)X.removeChild(j?j.previousSibling:X.lastChild)}var l=X.childNodes[h.domStart+d],m=b=h.from;for(var k=h.from;kj.from&&f.push({from:j.from,to:e.from,domStart:j.domStart}),e.to=m)break;if(j.domStart>o||j.from>q)n.push({from:q,to:j.from,domSize:j.domStart-o,domStart:o}),r+=j.from-q;q=j.to,o=j.domStart+(j.to-j.from)}if(o!=p||q!=m)r+=Math.abs(m-q),n.push({from:q,to:m,domSize:p-o,domStart:o});if(!n.length)return;X.style.display="none",r>(k.to-k.from)*.3?cb(l=Math.max(k.from-10,0),m=Math.min(k.to+7,ba.length)):cc(n),X.style.display="";var s=l!=bn||m!=bo||bp!=F.clientHeight;bn=l,bo=m,S.style.top=l*cE()+"px",s&&(bp=F.clientHeight,L.style.height=ba.length*cE()+2*cF()+"px",cd()),bu==null&&(bu=cz(bt)),bu>F.clientWidth?(V.style.width=bu+"px",L.style.width="",L.style.width=F.scrollWidth+"px"):V.style.width=L.style.width="";if(X.childNodes.length!=bo-bn)throw new Error("BAD PATCH! "+JSON.stringify(n)+" size="+(bo-bn)+" nodes="+X.childNodes.length);ce()}}function b_(){var a=cE(),b=F.scrollTop-cF();return{from:Math.min(ba.length,Math.max(0,Math.floor(b/a))),to:Math.min(ba.length,Math.ceil((b+F.clientHeight)/a))}}function b$(a,b,c,d){var e=cG(),f=cF(),h=cE();b+=f,d+=f,a+=e,c+=e;var i=F.clientHeight,j=F.scrollTop,k=!1,l=!0;bj+i&&(F.scrollTop=d+h-i,k=!0);var m=F.clientWidth,n=F.scrollLeft;am+n&&(F.scrollLeft=c+10-m,k=!0,c>L.clientWidth&&(l=!1)),k&&g.onScroll&&g.onScroll(by);return l}function bZ(){var a=cC(be.inverted?be.from:be.to);return b$(a.x,a.y,a.x,a.yBot)}function bY(){g.readOnly!="nocursor"&&E.focus()}function bX(){var a=[],b=Math.max(0,be.from.line-1),c=Math.min(ba.length,be.to.line+2);for(var d=b;d=a)return{line:c,ch:a-d};++c,d=e+1}}if(!bm&&!!bd){var a=!1,b=E.value,c=Q(E);if(!c)return!1;var a=br.text!=b,d=bg,e=a||c.start!=br.start||c.end!=(d?br.start:br.end);if(!e&&!d)return!1;if(a){bf=bg=null;if(g.readOnly){bi=!0;return"changed"}}var h=f(c.start,br.from),i=f(c.end,br.from);if(d){var j=c.start==d.anchor?i:h,k=bf?be.to:c.start==d.anchor?h:i;(be.inverted=J(j,k))?(h=j,i=k):(bg=null,h=k,i=j)}h.line==i.line&&h.line==be.from.line&&h.line==be.to.line&&!bf&&(bi=!1);if(a){var l=0,m=b.length,n=Math.min(m,br.text.length),o,p=br.from,q=-1;while(l-1?l-q:l,s=br.to-1,t=br.text.length;for(;;){o=br.text.charAt(t);if(b.charAt(m)!=o){++m,++t;break}o=="\n"&&s--;if(t<=l||m<=l)break;--m,--t}var q=br.text.lastIndexOf("\n",t-1),u=q==-1?t:t-q-1;bJ({line:p,ch:r},{line:s,ch:u},P(b.slice(l,m)),h,i);if(p!=s||h.line!=p)bi=!0}else cg(h,i);br.text=b,br.start=c.start,br.end=c.end;return a?"changed":e?"moved":!1}}function bV(a){function c(){cR();var d=bW();d=="moved"&&a&&(C[a]=!0),!d&&!b?(b=!0,Y.set(80,c)):(bT=!1,bU()),cS()}var b=!1;bT=!0,Y.set(20,c)}function bU(){bT||Y.set(2e3,function(){cR(),bW(),bd&&bU(),cS()})}function bS(){return bR(be.from,be.to)}function bR(a,b){var c=a.line,d=b.line;if(c==d)return ba[c].text.slice(a.ch,b.ch);var e=[ba[c].text.slice(a.ch)];for(var f=c+1;fg&&(bt=o,g=o.length,bu=null,f=!1)}if(f){g=0,bt="",bu=null;for(var i=0,n=ba.length;ig&&(g=o.length,bt=o)}}var p=[],q=c.length-j-1;for(var i=0,o=bb.length;ib.line&&p.push(r+q)}c.length<5?(cO(a.line,a.line+c.length),p.push(a.line+c.length)):p.push(a.line),bb=p,cQ(100),bj.push({from:a.line,to:b.line+1,diff:q}),bk={from:a,to:b,text:c},cg(d,e,s(be.from.line),s(be.to.line)),L.style.height=ba.length*cE()+2*cF()+"px"}function bM(){bK(bc.undone,bc.done)}function bL(){bK(bc.done,bc.undone)}function bK(a,b){var c=a.pop();if(c){var d=[],e=c.start+c.added;for(var f=c.start;fg.undoDepth)bc.done.shift()}bN(a,b,c,d,e)}function bI(){bd&&(g.onBlur&&g.onBlur(by),bd=!1,y.className=y.className.replace(" CodeMirror-focused","")),clearInterval($),setTimeout(function(){bd||(bf=null)},150)}function bH(){g.readOnly!="nocursor"&&(bd||(g.onFocus&&g.onFocus(by),bd=!0,y.className.search(/\bCodeMirror-focused\b/)==-1&&(y.className+=" CodeMirror-focused"),bm||bX()),bU(),cJ())}function bG(a){if(!g.onKeyEvent||!g.onKeyEvent(by,l(a))){if(g.electricChars&&_.electricChars){var b=String.fromCharCode(a.charCode==null?a.keyCode:a.charCode);_.electricChars.indexOf(b)>-1&&setTimeout(cU(function(){cr(be.to.line,"smart")}),50)}var c=a.keyCode;c==13?(g.readOnly||cp(),m(a)):!a.ctrlKey&&!a.altKey&&!a.metaKey&&c==9&&g.tabMode!="default"?m(a):bV(bq)}}function bF(a){if(!g.onKeyEvent||!g.onKeyEvent(by,l(a)))bg&&(bg=null,bi=!0),a.keyCode==16&&(bf=null)}function bE(a){bd||bH();var b=a.keyCode;x&&b==27&&(a.returnValue=!1);var c=(B?a.metaKey:a.ctrlKey)&&!a.altKey,d=a.ctrlKey||a.altKey||a.metaKey;b==16||a.shiftKey?bf=bf||(be.inverted?be.to:be.from):bf=null;if(!g.onKeyEvent||!g.onKeyEvent(by,l(a))){if(b==33||b==34){ck(b==34);return m(a)}if(c&&(b==36||b==35||B&&(b==38||b==40))){cl(b==36||b==38);return m(a)}if(c&&b==65){cm();return m(a)}if(!g.readOnly){if(!d&&b==13)return;if(!d&&b==9&&cq(a.shiftKey))return m(a);if(c&&b==90){bL();return m(a)}if(c&&(a.shiftKey&&b==90||b==89)){bM();return m(a)}}bq=(c?"c":"")+b;if(be.inverted&&C.hasOwnProperty(bq)){var e=Q(E);e&&(bg={anchor:e.start},R(E,e.start,e.start))}bV(bq)}}function bD(a){a.preventDefault();var b=cH(a,!0),c=a.dataTransfer.files;if(!!b&&!g.readOnly)if(c&&c.length&&window.FileReader&&window.File){function d(a,c){var d=new FileReader;d.onload=function(){f[c]=d.result,++h==e&&bO(f.join(""),cj(b),cj(b))},d.readAsText(a)}var e=c.length,f=Array(e),h=0;for(var i=0;i=c.to||b.line=0&&a
    '+'
    '+'
    '+'
    '+'
    '+'
    '+'
     
    '+"
    "+"
    ",b.appendChild?b.appendChild(y):b(y);var D=y.firstChild,E=D.firstChild,F=y.lastChild,L=F.firstChild,M=L.firstChild,S=M.nextSibling,T=S.firstChild,U=T.firstChild,V=T.nextSibling.firstChild,W=V.firstChild,X=W.nextSibling;g.tabindex!=null&&(E.tabindex=g.tabindex),!g.gutter&&!g.lineNumbers&&(T.style.display="none");var Y=new u,Z=new u,$,_,ba=[new h("")],bb,bc=new j,bd;cs();var be={from:{line:0,ch:0},to:{line:0,ch:0},inverted:!1},bf,bg,bh,bi,bj,bk,bl,bm,bn=0,bo=0,bp=0,bq=null,br,bs,bt="",bu;cU(function(){bz(g.value||""),bi=!1})(),t(F,"mousedown",cU(bB)),w||t(F,"contextmenu",cI),t(L,"dblclick",cU(bC)),t(F,"scroll",function(){ca([]),g.onScroll&&g.onScroll(by)}),t(window,"resize",function(){ca(!0)}),t(E,"keyup",cU(bF)),t(E,"keydown",cU(bE)),t(E,"keypress",cU(bG)),t(E,"focus",bH),t(E,"blur",bI),t(F,"dragenter",o),t(F,"dragover",o),t(F,"drop",cU(bD)),t(F,"paste",function(){bY(),bV()}),t(E,"paste",function(){bV()}),t(E,"cut",function(){bV()});var bv;try{bv=n.activeElement==E}catch(bw){}bv?setTimeout(bH,20):bI();var by={getValue:bA,setValue:cU(bz),getSelection:bS,replaceSelection:cU(bP),focus:function(){bY(),bH(),bV()},setOption:function(a,b){g[a]=b,a=="lineNumbers"||a=="gutter"?ct():a=="mode"||a=="indentUnit"?cs():a=="readOnly"&&b=="nocursor"?E.blur():a=="theme"&&(F.className=F.className.replace(/cm-s-\w+/,"cm-s-"+b))},getOption:function(a){return g[a]},undo:cU(bL),redo:cU(bM),indentLine:cU(function(a,b){bx(a)&&cr(a,b==null?"smart":b?"add":"subtract")}),historySize:function(){return{undo:bc.done.length,redo:bc.undone.length}},matchBrackets:cU(function(){cL(!0)}),getTokenAt:function(a){a=cj(a);return ba[a.line].getTokenAt(_,cN(a.line),a.ch)},getStateAfter:function(a){a=ci(a==null?ba.length-1:a);return cN(a+1)},cursorCoords:function(a){a==null&&(a=be.inverted);return cD(a?be.from:be.to)},charCoords:function(a){return cD(cj(a))},coordsChar:function(a){var b=G(V),c=ci(Math.min(ba.length-1,bn+Math.floor((a.y-b.top)/cE())));return cj({line:c,ch:cB(ci(c),a.x-b.left)})},getSearchCursor:function(a,b,c){return new cV(a,b,c)},markText:cU(function(a,b,c){return cU(cu(a,b,c))}),setMarker:cv,clearMarker:cw,setLineClass:cU(cx),lineInfo:cy,addWidget:function(a,b,c,d){a=cC(cj(a));var e=a.yBot,f=a.x;b.style.position="absolute",L.appendChild(b),b.style.left=f+"px";if(d=="over")e=a.y;else if(d=="near"){var g=Math.max(F.offsetHeight,ba.length*cE()),h=Math.max(L.clientWidth,V.clientWidth)-cG();a.yBot+b.offsetHeight>g&&a.y>b.offsetHeight&&(e=a.y-b.offsetHeight),f+b.offsetWidth>h&&(f=h-b.offsetWidth)}b.style.top=e+cF()+"px",b.style.left=f+cG()+"px",c&&b$(f,e,f+b.offsetWidth,e+b.offsetHeight)},lineCount:function(){return ba.length},getCursor:function(a){a==null&&(a=be.inverted);return K(a?be.from:be.to)},somethingSelected:function(){return!I(be.from,be.to)},setCursor:cU(function(a,b){b==null&&typeof a.line=="number"?ch(a.line,a.ch):ch(a,b)}),setSelection:cU(function(a,b){cg(cj(a),cj(b||a))}),getLine:function(a){if(bx(a))return ba[a].text},setLine:cU(function(a,b){bx(a)&&bO(b,{line:a,ch:0},{line:a,ch:ba[a].text.length})}),removeLine:cU(function(a){bx(a)&&bO("",{line:a,ch:0},cj({line:a+1,ch:0}))}),replaceRange:cU(bO),getRange:function(a,b){return bR(cj(a),cj(b))},operation:function(a){return cU(a)()},refresh:function(){ca(!0)},getInputField:function(){return E},getWrapperElement:function(){return y},getScrollerElement:function(){return F},getGutterElement:function(){return T}},bT=!1,cK={"(":")>",")":"(<","[":"]>","]":"[<","{":"}>","}":"{<"},cT=0;cV.prototype={findNext:function(){return this.find(!1)},findPrevious:function(){return this.find(!0)},find:function(a){function d(a){var c={line:a,ch:0};b.pos={from:c,to:c},b.atOccurrence=!1;return!1}var b=this,c=cj(a?this.pos.from:this.pos.to);for(;;){if(this.pos=this.matches(a,c)){this.atOccurrence=!0;return this.pos.match||!0}if(a){if(!c.line)return d(0);c={line:c.line-1,ch:ba[c.line-1].text.length}}else{if(c.line==ba.length-1)return d(ba.length);c={line:c.line+1,ch:0}}}},from:function(){if(this.atOccurrence)return K(this.pos.from)},to:function(){if(this.atOccurrence)return K(this.pos.to)},replace:function(a){var b=this;this.atOccurrence&&cU(function(){b.pos.to=bO(a,b.pos.from,b.pos.to)})()}};for(var cW in d)d.propertyIsEnumerable(cW)&&!by.propertyIsEnumerable(cW)&&(by[cW]=d[cW]);return by}a.defaults={value:"",mode:null,theme:"default",indentUnit:2,indentWithTabs:!1,tabMode:"classic",enterMode:"indent",electricChars:!0,onKeyEvent:null,lineNumbers:!1,gutter:!1,firstLineNumber:1,readOnly:!1,onChange:null,onCursorActivity:null,onGutterClick:null,onHighlightComplete:null,onFocus:null,onBlur:null,onScroll:null,matchBrackets:!1,workTime:100,workDelay:200,undoDepth:40,tabindex:null,document:window.document};var b={},c={};a.defineMode=function(c,d){!a.defaults.mode&&c!="null"&&(a.defaults.mode=c),b[c]=d},a.defineMIME=function(a,b){c[a]=b},a.getMode=function(d,e){typeof e=="string"&&c.hasOwnProperty(e)&&(e=c[e]);if(typeof e=="string")var f=e,g={};else if(e!=null)var f=e.name,g=e;var h=b[f];if(!h){window.console&&console.warn("No mode "+f+" found, falling back to plain text.");return a.getMode(d,"text/plain")}return h(d,g||{})},a.listModes=function(){var a=[];for(var c in b)b.propertyIsEnumerable(c)&&a.push(c);return a},a.listMIMEs=function(){var a=[];for(var b in c)c.propertyIsEnumerable(b)&&a.push(b);return a};var d={};a.defineExtension=function(a,b){d[a]=b},a.fromTextArea=function(b,c){function d(){b.value=h.getValue()}c||(c={}),c.value=b.value,!c.tabindex&&b.tabindex&&(c.tabindex=b.tabindex);if(b.form){var e=t(b.form,"submit",d,!0);if(typeof b.form.submit=="function"){var f=b.form.submit;function g(){d(),b.form.submit=f,b.form.submit(),b.form.submit=g}b.form.submit=g}}b.style.display="none";var h=a(function(a){b.parentNode.insertBefore(a,b.nextSibling)},c);h.save=d,h.toTextArea=function(){d(),b.parentNode.removeChild(h.getWrapperElement()),b.style.display="",b.form&&(e(),typeof b.form.submit=="function"&&(b.form.submit=f))};return h},a.startState=f,a.copyState=e,g.prototype={eol:function(){return this.pos>=this.string.length},sol:function(){return this.pos==0},peek:function(){return this.string.charAt(this.pos)},next:function(){if(this.posb},eatSpace:function(){var a=this.pos;while(/[\s\u00a0]/.test(this.string.charAt(this.pos)))++this.pos;return this.pos>a},skipToEnd:function(){this.pos=this.string.length},skipTo:function(a){var b=this.string.indexOf(a,this.pos);if(b>-1){this.pos=b;return!0}},backUp:function(a){this.pos-=a},column:function(){return E(this.string,this.start)},indentation:function(){return E(this.string)},match:function(a,b,c){if(typeof a!="string"){var e=this.string.slice(this.pos).match(a);e&&b!==!1&&(this.pos+=e[0].length);return e}function d(a){return c?a.toLowerCase():a}if(d(this.string).indexOf(d(a),this.pos)==this.pos){b!==!1&&(this.pos+=a.length);return!0}},current:function(){return this.string.slice(this.start,this.pos)}},a.StringStream=g,h.prototype={replace:function(a,b,c){var d=[],e=this.marked;i(0,a,this.styles,d),c&&d.push(c,null),i(b,this.text.length,this.styles,d),this.styles=d,this.text=this.text.slice(0,a)+c+this.text.slice(b),this.stateAfter=null;if(e){var f=c.length-(b-a),g=this.text.length;function h(a){return a<=Math.min(b,b+f)?a:a+f}for(var j=0;j=g?l=!0:(k.from=h(k.from),k.to!=null&&(k.to=h(k.to)));if(l||k.from>=k.to)e.splice(j,1),j--}}},split:function(a,b){var c=[b,null];i(a,this.text.length,this.styles,c);return new h(b+this.text.slice(a),c)},addMark:function(a,b,c){var d=this.marked,e={from:a,to:b,style:c};this.marked==null&&(this.marked=[]),this.marked.push(e),this.marked.sort(function(a,b){return a.from-b.from});return e},removeMark:function(a){var b=this.marked;if(!!b)for(var c=0;c5e3){d[e++]=this.text.slice(c.pos),d[e++]=null;break}}d.length!=e&&(d.length=e,f=!0),e&&d[e-2]!=i&&(f=!0);return f||d.length<5&&this.text.length<10},getTokenAt:function(a,b,c){var d=this.text,e=new g(d);while(e.pos',M(a),""):e.push(M(a)))}var e=[];c&&e.push(this.className?'
    ':"
    ");var g=this.styles,h=this.text,i=this.marked;a==b&&(a=null);var j=h.length;d!=null&&(j=Math.min(d,j));if(!h&&d==null)f(" ",a!=null&&b==null?"CodeMirror-selected":null);else if(!i&&a==null)for(var k=0,l=0;lj&&(m=m.slice(0,j-l)),l+=n,f(m,"cm-"+g[k+1])}else{var o=0,k=0,p="",q,r=0,s=-1,t=null;function u(){i&&(s+=1,t=so)v=a;else if(b==null||b>o)w=" CodeMirror-selected",b!=null&&(v=Math.min(v,b));while(t&&t.to!=null&&t.to<=o)u();t&&(t.from>o?v=Math.min(v,t.from):(w+=" "+t.style,t.to!=null&&(v=Math.min(v,t.to))));for(;;){var x=o+p.length,y=q;w&&(y=q?q+w:w),f(x>v?p.slice(0,v-o):p,y);if(x>=v){p=p.slice(v-o),o=v;break}o=x,p=g[k++],q="cm-"+g[k++]}}a!=null&&b==null&&f(" ","CodeMirror-selected")}c&&e.push("
    ");return e.join("")}},j.prototype={addChange:function(a,b,c){this.undone.length=0;var d=+(new Date),e=this.done[this.done.length-1];if(d-this.time>400||!e||e.start>a+b||e.start+e.added=0;--g)e.old.unshift(c[g]);e.added+=e.start-a,e.start=a}else e.start-1&&(z="\r\n")})();var A=8,B=/Mac/.test(navigator.platform),C={};for(var D=35;D<=40;++D)C[D]=C["c"+D]=!0;var L=document.createElement("div");a.htmlEscape=M;var P,Q,R;"\n\nb".split(/\n/).length!=3?P=function(a){var b=0,c,d=[];while((c=a.indexOf("\n",b))>-1)d.push(a.slice(b,a.charAt(c-1)=="\r"?c-1:c)),b=c+1;d.push(a.slice(b));return d}:P=function(a){return a.split(/\r?\n/)},a.splitLines=P,window.getSelection?(Q=function(a){try{return{start:a.selectionStart,end:a.selectionEnd}}catch(b){return null}},y?R=function(a,b,c){b==c?a.setSelectionRange(b,c):(a.setSelectionRange(b,c-1),window.getSelection().modify("extend","forward","character"))}:R=function(a,b,c){try{a.setSelectionRange(b,c)}catch(d){}}):(Q=function(a){try{var b=a.ownerDocument.selection.createRange()}catch(c){return null}if(!b||b.parentElement()!=a)return null;var d=a.value,e=d.length,f=a.createTextRange();f.moveToBookmark(b.getBookmark());var g=a.createTextRange();g.collapse(!1);if(f.compareEndPoints("StartToEnd",g)>-1)return{start:e,end:e};var h=-f.moveStart("character",-e);for(var i=d.indexOf("\r");i>-1&&i-1)return{start:h,end:e};var j=-f.moveEnd("character",-e);for(var i=d.indexOf("\r");i>-1&&i-1&&h-1&&h=0;a--)s.cc.push(arguments[a])}function r(a,b,c,e,f){var g=a.cc;s.state=a,s.stream=f,s.marked=null,s.cc=g,a.lexical.hasOwnProperty("align")||(a.lexical.align=!0);for(;;){var h=g.length?g.pop():d?D:C;if(h(c,e)){while(g.length&&g[g.length-1].lex)g.pop()();if(s.marked)return s.marked;if(c=="variable"&&q(a,e))return"variable-2";return b}}}function q(a,b){for(var c=a.localVars;c;c=c.next)if(c.name==b)return!0}function p(a,b,c,d,e,f){this.indented=a,this.column=b,this.type=c,this.prev=e,this.info=f,d!=null&&(this.align=d)}function n(a,b){var c=!1,d;while(d=a.next()){if(d=="/"&&c){b.tokenize=l;break}c=d=="*"}return k("comment","comment")}function m(a){return function(b,c){h(b,a)||(c.tokenize=l);return k("string","string")}}function l(a,b){var c=a.next();if(c=='"'||c=="'")return g(a,b,m(c));if(/[\[\]{}\(\),;\:\.]/.test(c))return k(c);if(c=="0"&&a.eat(/x/i)){a.eatWhile(/[\da-f]/i);return k("number","number")}if(/\d/.test(c)){a.match(/^\d*(?:\.\d*)?(?:e[+\-]?\d+)?/);return k("number","number")}if(c=="/"){if(a.eat("*"))return g(a,b,n);if(a.eat("/")){a.skipToEnd();return k("comment","comment")}if(b.reAllowed){h(a,"/"),a.eatWhile(/[gimy]/);return k("regexp","string")}a.eatWhile(f);return k("operator",null,a.current())}if(f.test(c)){a.eatWhile(f);return k("operator",null,a.current())}a.eatWhile(/[\w\$_]/);var d=a.current(),i=e.propertyIsEnumerable(d)&&e[d];return i?k(i.type,i.style,d):k("variable","variable",d)}function k(a,b,c){i=a,j=c;return b}function h(a,b){var c=!1,d;while((d=a.next())!=null){if(d==b&&!c)return!1;c=!c&&d=="\\"}return c}function g(a,b,c){b.tokenize=c;return c(a,b)}var c=a.indentUnit,d=b.json,e=function(){function a(a){return{type:a,style:"keyword"}}var b=a("keyword a"),c=a("keyword b"),d=a("keyword c"),e=a("operator"),f={type:"atom",style:"atom"};return{"if":b,"while":b,"with":b,"else":c,"do":c,"try":c,"finally":c,"return":d,"break":d,"continue":d,"new":d,"delete":d,"throw":d,"var":a("var"),"function":a("function"),"catch":a("catch"),"for":a("for"),"switch":a("switch"),"case":a("case"),"default":a("default"),"in":e,"typeof":e,"instanceof":e,"true":f,"false":f,"null":f,"undefined":f,NaN:f,Infinity:f}}(),f=/[+\-*&%=<>!?|]/,i,j,o={atom:!0,number:!0,variable:!0,string:!0,regexp:!0},s={state:null,column:null,marked:null,cc:null},w={name:"this",next:{name:"arguments"}};A.lex=!0;return{startState:function(a){return{tokenize:l,reAllowed:!0,cc:[],lexical:new p((a||0)-c,0,"block",!1),localVars:null,context:null,indented:0}},token:function(a,b){a.sol()&&(b.lexical.hasOwnProperty("align")||(b.lexical.align=!1),b.indented=a.indentation());if(a.eatSpace())return null;var c=b.tokenize(a,b);if(i=="comment")return c;b.reAllowed=i=="operator"||i=="keyword c"||i.match(/^[\[{}\(,;:]$/);return r(b,c,i,j,a)},indent:function(a,b){if(a.tokenize!=l)return 0;var d=b&&b.charAt(0),e=a.lexical,f=e.type,g=d==f;return f=="vardef"?e.indented+4:f=="form"&&d=="{"?e.indented:f=="stat"||f=="form"?e.indented+c:e.info=="switch"&&!g?e.indented+(/^(?:case|default)\b/.test(b)?c:2*c):e.align?e.column+(g?0:1):e.indented+(g?0:c)},electricChars:":{}"}}),CodeMirror.defineMIME("text/javascript","javascript"),CodeMirror.defineMIME("application/json",{name:"javascript",json:!0}),CodeMirror.defineMode("xml",function(a,b){function w(a){return a=="string"?o(w):n()}function v(a){if(a=="word"&&d.allowUnquoted){m="string";return o()}if(a=="string")return o(w);return n()}function u(a){if(a=="word"){m="attribute";return o(u)}if(a=="equals")return o(v,u);return n()}function t(a){return function(b){a&&(m="error");if(b=="endTag")return o();return n()}}function s(a){return function(b){if(b=="selfcloseTag"||b=="endTag"&&d.autoSelfClosers.hasOwnProperty(l.tagName.toLowerCase()))return o();if(b=="endTag"){p(l.tagName,a);return o()}return o()}}function r(a){if(a=="openTag"){l.tagName=f;return o(u,s(l.startOfLine))}if(a=="closeTag"){var b=!1;l.context?(b=l.context.tagName!=f,q()):b=!0,b&&(m="error");return o(t(b))}if(a=="string"){(!l.context||l.context.name!="!cdata")&&p("!cdata"),l.tokenize==h&&q();return o()}return o()}function q(){l.context&&(l.context=l.context.prev)}function p(a,b){var c=d.doNotIndent.hasOwnProperty(a)||l.context&&l.context.noIndent;l.context={prev:l.context,tagName:a,indent:l.indented,startOfLine:b,noIndent:c}}function o(){n.apply(null,arguments);return!0}function n(){for(var a=arguments.length-1;a>=0;a--)l.cc.push(arguments[a])}function k(a,b){return function(c,d){while(!c.eol()){if(c.match(b)){d.tokenize=h;break}c.next()}return a}}function j(a){return function(b,c){while(!b.eol())if(b.next()==a){c.tokenize=i;break}return"string"}}function i(a,b){var c=a.next();if(c==">"||c=="/"&&a.eat(">")){b.tokenize=h,g=c==">"?"endTag":"selfcloseTag";return"tag"}if(c=="="){g="equals";return null}if(/[\'\"]/.test(c)){b.tokenize=j(c);return b.tokenize(a,b)}a.eatWhile(/[^\s\u00a0=<>\"\'\/?]/);return"word"}function h(a,b){function c(c){b.tokenize=c;return c(a,b)}var d=a.next();if(d=="<"){if(a.eat("!")){if(a.eat("["))return a.match("CDATA[")?c(k("atom","]]>")):null;if(a.match("--"))return c(k("comment","-->"));if(a.match("DOCTYPE",!0,!0)){a.eatWhile(/[\w\._\-]/);return c(k("meta",">"))}return null}if(a.eat("?")){a.eatWhile(/[\w\._\-]/),b.tokenize=k("meta","?>");return"meta"}g=a.eat("/")?"closeTag":"openTag",a.eatSpace(),f="";var e;while(e=a.eat(/[^\s\u00a0=<>\"\'\/?]/))f+=e;b.tokenize=i;return"tag"}if(d=="&"){a.eatWhile(/[^;]/),a.eat(";");return"atom"}a.eatWhile(/[^&<]/);return null}var c=a.indentUnit,d=b.htmlMode?{autoSelfClosers:{br:!0,img:!0,hr:!0,link:!0,input:!0,meta:!0,col:!0,frame:!0,base:!0,area:!0},doNotIndent:{pre:!0,"!cdata":!0},allowUnquoted:!0}:{autoSelfClosers:{},doNotIndent:{"!cdata":!0},allowUnquoted:!1},e=b.alignCDATA,f,g,l,m;return{startState:function(){return{tokenize:h,cc:[],indented:0,startOfLine:!0,tagName:null,context:null}},token:function(a,b){a.sol()&&(b.startOfLine=!0,b.indented=a.indentation());if(a.eatSpace())return null;m=g=f=null;var c=b.tokenize(a,b);if((c||g)&&c!="comment"){l=b;for(;;){var d=b.cc.pop()||r;if(d(g||c))break}}b.startOfLine=!1;return m||c},indent:function(a,b){var d=a.context;if(d&&d.noIndent)return 0;if(e&&/=2&&f==">"){b.tokenize=e;break}c=f=="-"?c+1:0}return d("comment","comment")}function f(a,b){var c=!1,f;while((f=a.next())!=null){if(c&&f=="/"){b.tokenize=e;break}c=f=="*"}return d("comment","comment")}function e(a,b){var c=a.next();if(c=="@"){a.eatWhile(/\w/);return d("meta",a.current())}if(c=="/"&&a.eat("*")){b.tokenize=f;return f(a,b)}if(c=="<"&&a.eat("!")){b.tokenize=g;return g(a,b)}if(c=="=")d(null,"compare");else{if(c!="~"&&c!="|"||!a.eat("=")){if(c=='"'||c=="'"){b.tokenize=h(c);return b.tokenize(a,b)}if(c=="#"){a.eatWhile(/\w/);return d("atom","hash")}if(c=="!"){a.match(/^\s*\w*/);return d("keyword","important")}if(/\d/.test(c)){a.eatWhile(/[\w.%]/);return d("number","unit")}if(/[,.+>*\/]/.test(c))return d(null,"select-op");if(/[;{}:\[\]]/.test(c))return d(null,c);a.eatWhile(/[\w\\\-_]/);return d("variable","variable")}return d(null,"compare")}}function d(a,b){c=b;return a}var b=a.indentUnit,c;return{startState:function(a){return{tokenize:e,baseIndent:a||0,stack:[]}},token:function(a,b){if(a.eatSpace())return null;var d=b.tokenize(a,b),e=b.stack[b.stack.length-1];if(c=="hash"&&e=="rule")d="atom";else if(d=="variable")if(e=="rule")d="number";else if(!e||e=="@media{")d="tag";e=="rule"&&/^[\{\};]$/.test(c)&&b.stack.pop(),c=="{"?e=="@media"?b.stack[b.stack.length-1]="@media{":b.stack.push("{"):c=="}"?b.stack.pop():c=="@media"?b.stack.push("@media"):e=="{"&&c!="comment"&&b.stack.push("rule");return d},indent:function(a,c){var d=a.stack.length;/^\}/.test(c)&&(d-=a.stack[a.stack.length-1]=="rule"?2:1);return a.baseIndent+d*b},electricChars:"}"}}),CodeMirror.defineMIME("text/css","css"),CodeMirror.defineMode("htmlmixed",function(a,b){function i(a,b){if(a.match(/^<\/\s*style\s*>/i,!1)){b.token=f,b.localState=null,b.mode="html";return f(a,b)}return g(a,/<\/\s*style\s*>/,e.token(a,b.localState))}function h(a,b){if(a.match(/^<\/\s*script\s*>/i,!1)){b.token=f,b.curState=null,b.mode="html";return f(a,b)}return g(a,/<\/\s*script\s*>/,d.token(a,b.localState))}function g(a,b,c){var d=a.current(),e=d.search(b);e>-1&&a.backUp(d.length-e);return c}function f(a,b){var f=c.token(a,b.htmlState);f=="tag"&&a.current()==">"&&b.htmlState.context&&(/^script$/i.test(b.htmlState.context.tagName)?(b.token=h,b.localState=d.startState(c.indent(b.htmlState,"")),b.mode="javascript"):/^style$/i.test(b.htmlState.context.tagName)&&(b.token=i,b.localState=e.startState(c.indent(b.htmlState,"")),b.mode="css"));return f}var c=CodeMirror.getMode(a,{name:"xml",htmlMode:!0}),d=CodeMirror.getMode(a,"javascript"),e=CodeMirror.getMode(a,"css");return{startState:function(){var a=c.startState();return{token:f,localState:null,mode:"html",htmlState:a}},copyState:function(a){if(a.localState)var b=CodeMirror.copyState(a.token==i?e:d,a.localState);return{token:a.token,localState:b,mode:a.mode,htmlState:CodeMirror.copyState(c,a.htmlState)}},token:function(a,b){return b.token(a,b)},indent:function(a,b){return a.token==f||/^\s*<\//.test(b)?c.indent(a.htmlState,b):a.token==h?d.indent(a.localState,b):e.indent(a.localState,b)},electricChars:"/{}:"}}),CodeMirror.defineMIME("text/html","htmlmixed") \ No newline at end of file diff --git a/dist/docs/resources/js/paper.js b/dist/docs/resources/js/paper.js index ea11ce94..e963d27f 100644 --- a/dist/docs/resources/js/paper.js +++ b/dist/docs/resources/js/paper.js @@ -1,27 +1,27 @@ /*! - * Paper.js v0.21 + * Paper.js v0.22 * * This file is part of Paper.js, a JavaScript Vector Graphics Library, * based on Scriptographer.org and designed to be largely API compatible. - * http: - * http: + * http://paperjs.org/ + * http://scriptographer.org/ * * Copyright (c) 2011, Juerg Lehni & Jonathan Puckey - * http: + * http://lehni.org/ & http://jonathanpuckey.com/ * * Distributed under the MIT license. See LICENSE file for details. * * All rights reserved. * - * Date: Tue Aug 2 10:08:08 2011 +0100 + * Date: Thu Nov 10 18:30:18 2011 +0100 * *** * * Bootstrap.js JavaScript Framework. - * http: + * http://bootstrapjs.org/ * * Copyright (c) 2006 - 2011 Juerg Lehni - * http: + * http://lehni.org/ * * Distributed under the MIT license. * @@ -31,14 +31,14 @@ * * A JavaScript tokenizer / parser / generator, originally written in Lisp. * Copyright (c) Marijn Haverbeke - * http: + * http://marijn.haverbeke.nl/parse-js/ * * Ported by to JavaScript by Mihai Bazon * Copyright (c) 2010, Mihai Bazon - * http: + * http://mihai.bazon.net/blog/ * * Modifications and adaptions to browser (c) 2011, Juerg Lehni - * http: + * http://lehni.org/ * * Distributed under the BSD license. */ @@ -409,7 +409,7 @@ var PaperScope = this.PaperScope = Base.extend({ PaperScope._scopes[this._id] = this; }, - version: 0.21, + version: 0.22, evaluate: function(code) { var res = PaperScript.evaluate(code, this); @@ -804,7 +804,9 @@ var LinkedPoint = Point.extend({ }, statics: { - create: function(owner, setter, x, y) { + create: function(owner, setter, x, y, dontLink) { + if (dontLink) + return Point.create(x, y); var point = new LinkedPoint(LinkedPoint.dont); point._x = x; point._y = y; @@ -893,7 +895,7 @@ var Size = this.Size = Base.extend({ }, isZero: function() { - return this.width == 0 && this.width == 0; + return this.width == 0 && this.height == 0; }, isNaN: function() { @@ -959,13 +961,15 @@ var LinkedSize = Size.extend({ }, statics: { - create: function(owner, setter, width, height) { - var point = new LinkedSize(LinkedSize.dont); - point._width = width; - point._height = height; - point._owner = owner; - point._setter = setter; - return point; + create: function(owner, setter, width, height, dontLink) { + if (dontLink) + return Size.create(width, height); + var size = new LinkedSize(LinkedSize.dont); + size._width = width; + size._height = height; + size._owner = owner; + size._setter = setter; + return size; } } }); @@ -1020,7 +1024,8 @@ var Rectangle = this.Rectangle = Base.extend({ }, getPoint: function() { - return LinkedPoint.create(this, 'setPoint', this.x, this.y); + return LinkedPoint.create(this, 'setPoint', this.x, this.y, + arguments[0]); }, setPoint: function(point) { @@ -1031,7 +1036,8 @@ var Rectangle = this.Rectangle = Base.extend({ }, getSize: function() { - return LinkedSize.create(this, 'setSize', this.width, this.height); + return LinkedSize.create(this, 'setSize', this.width, this.height, + arguments[0]); }, setSize: function(size) { @@ -1099,7 +1105,7 @@ var Rectangle = this.Rectangle = Base.extend({ getCenter: function() { return LinkedPoint.create(this, 'setCenter', - this.getCenterX(), this.getCenterY()); + this.getCenterX(), this.getCenterY(), arguments[0]); }, setCenter: function(point) { @@ -1223,7 +1229,7 @@ var Rectangle = this.Rectangle = Base.extend({ set = 'set' + part; this[get] = function() { return LinkedPoint.create(this, set, - this[getX](), this[getY]()); + this[getX](), this[getY](), arguments[0]); }; this[set] = function(point) { point = Point.read(arguments); @@ -1323,7 +1329,7 @@ var Matrix = this.Matrix = Base.extend({ return this; }, - scale: function(hor, ver , center) { + scale: function( hor, ver, center) { if (arguments.length < 2 || typeof ver === 'object') { center = Point.read(arguments, 1); ver = hor; @@ -1354,7 +1360,7 @@ var Matrix = this.Matrix = Base.extend({ Matrix.getRotateInstance.apply(Matrix, arguments)); }, - shear: function(hor, ver, center) { + shear: function( hor, ver, center) { if (arguments.length < 2 || typeof ver === 'object') { center = Point.read(arguments, 1); ver = hor; @@ -1471,8 +1477,30 @@ var Matrix = this.Matrix = Base.extend({ max[0] - min[0], max[1] - min[1]); }, - getDeterminant: function() { - return this._a * this._d - this._b * this._c; + inverseTransform: function(point) { + return this._inverseTransform(Point.read(arguments)); + }, + + _getDeterminant: function() { + var det = this._a * this._d - this._b * this._c; + return isFinite(det) && Math.abs(det) > Numerical.EPSILON + && isFinite(this._tx) && isFinite(this._ty) + ? det : null; + }, + + _inverseTransform: function(point, dest, dontNotify) { + var det = this._getDeterminant(); + if (!det) + return null; + var x = point.x - this._tx, + y = point.y - this._ty; + if (!dest) + dest = new Point(Point.dont); + return dest.set( + (x * this._d - y * this._b) / det, + (y * this._a - x * this._c) / det, + dontNotify + ); }, getTranslation: function() { @@ -1498,28 +1526,22 @@ var Matrix = this.Matrix = Base.extend({ }, isInvertible: function() { - var det = this.getDeterminant(); - return isFinite(det) && det != 0 && isFinite(this._tx) - && isFinite(this._ty); + return !!this._getDeterminant(); }, isSingular: function() { - return !this.isInvertible(); + return !this._getDeterminant(); }, createInverse: function() { - var det = this.getDeterminant(); - if (isFinite(det) && det != 0 && isFinite(this._tx) - && isFinite(this._ty)) { - return Matrix.create( + var det = this._getDeterminant(); + return det && Matrix.create( this._d / det, -this._c / det, -this._b / det, this._a / det, (this._b * this._ty - this._d * this._tx) / det, (this._c * this._tx - this._a * this._ty) / det); - } - return null; }, createShiftless: function() { @@ -1818,11 +1840,20 @@ var Item = this.Item = Base.extend({ delete this._position; } if (flags & ChangeFlag.APPEARANCE) { - if (this._project) - this._project._needsRedraw(); + this._project._needsRedraw(); } if (this._parentSymbol) this._parentSymbol._changed(flags); + if (this._project._changes) { + var entry = this._project._changesById[this._id]; + if (entry) { + entry.flags |= flags; + } else { + entry = { item: this, flags: flags }; + this._project._changesById[this._id] = entry; + this._project._changes.push(entry); + } + } }, getId: function() { @@ -1972,6 +2003,15 @@ var Item = this.Item = Base.extend({ } }, + getLayer: function() { + var parent = this; + while (parent = parent._parent) { + if (parent instanceof Layer) + return parent; + } + return null; + }, + getParent: function() { return this._parent; }, @@ -2048,8 +2088,7 @@ var Item = this.Item = Base.extend({ matrix.applyToContext(ctx); this.draw(ctx, {}); var raster = new Raster(canvas); - raster.setPosition(this.getPosition()); - raster.scale(1 / scale); + raster.setBounds(bounds); return raster; }, @@ -2855,7 +2894,7 @@ var Raster = this.Raster = PlacedItem.extend({ channels = new Array(4); for (var i = 0; i < 4; i++) channels[i] = pixels[i] / 255; - return RGBColor.read(channels); + return RgbColor.read(channels); }, setPixel: function(point, color) { @@ -3102,6 +3141,7 @@ var Segment = this.Segment = Base.extend({ if (selected) selection[0] = false; selection[index] = selected; + path._changed(Change.ATTRIBUTE); } } this._selectionState = (selection[0] ? SelectionState.POINT : 0) @@ -3241,6 +3281,10 @@ var SegmentPoint = Point.extend({ this._owner._changed(this); }, + isZero: function() { + return this._x == 0 && this._y == 0; + }, + setSelected: function(selected) { this._owner._setSelected(this, selected); }, @@ -3742,7 +3786,7 @@ var Curve = this.Curve = Base.extend({ return [0.5 * (w[0].x + w[5].x)]; if (isFlatEnough(w)) { var line = new Line(w[0], w[5], true); - return [ line.vector.getLength(true) < Numerical.EPSILON + return [ line.vector.getLength(true) <= Numerical.EPSILON ? line.point.x : xAxis.intersect(line).x ]; } @@ -4427,8 +4471,8 @@ var Path = this.Path = PathItem.extend({ ctx.rect(point._x - 1, point._y - 1, 2, 2); ctx.fillStyle = '#ffffff'; ctx.fill(); - ctx.restore(); } + ctx.restore(); } } @@ -5051,13 +5095,17 @@ Path.inject({ statics: new function() { Rectangle: function(rect) { rect = Rectangle.read(arguments); - var path = new Path(), - corners = ['getBottomLeft', 'getTopLeft', 'getTopRight', - 'getBottomRight'], - segments = new Array(4); - for (var i = 0; i < 4; i++) - segments[i] = new Segment(rect[corners[i]]()); - path._add(segments); + var left = rect.x, + top = rect.y + right = left + rect.width, + bottom = top + rect.height, + path = new Path(); + path._add([ + new Segment(Point.create(left, bottom)), + new Segment(Point.create(left, top)), + new Segment(Point.create(right, top)), + new Segment(Point.create(right, bottom)) + ]); path._closed = true; return path; }, @@ -5070,13 +5118,13 @@ Path.inject({ statics: new function() { rect = Rectangle.read(arguments, 0, 4); size = Size.read(arguments, 4, 2); } - size = Size.min(size, rect.getSize().divide(2)); + size = Size.min(size, rect.getSize(true).divide(2)); var path = new Path(), uSize = size.multiply(kappa * 2), - bl = rect.getBottomLeft(), - tl = rect.getTopLeft(), - tr = rect.getTopRight(), - br = rect.getBottomRight(); + bl = rect.getBottomLeft(true), + tl = rect.getTopLeft(true), + tr = rect.getTopRight(true), + br = rect.getBottomRight(true); path._add([ new Segment(bl.add(size.width, 0), null, [-uSize.width, 0]), new Segment(bl.subtract(0, size.height), [0, uSize.height], null), @@ -5097,13 +5145,13 @@ Path.inject({ statics: new function() { Oval: function(rect) { rect = Rectangle.read(arguments); var path = new Path(), - topLeft = rect.getTopLeft(), - size = new Size(rect.width, rect.height), + point = rect.getPoint(true), + size = rect.getSize(true), segments = new Array(4); for (var i = 0; i < 4; i++) { var segment = ovalSegments[i]; segments[i] = new Segment( - segment._point.multiply(size).add(topLeft), + segment._point.multiply(size).add(point), segment._handleIn.multiply(size), segment._handleOut.multiply(size) ); @@ -5121,7 +5169,7 @@ Path.inject({ statics: new function() { center = Point.read(arguments, 0, 1); } return Path.Oval(new Rectangle(center.subtract(radius), - new Size(radius * 2, radius * 2))); + Size.create(radius * 2, radius * 2))); }, Arc: function(from, through, to) { @@ -5583,9 +5631,8 @@ var TextItem = this.TextItem = Item.extend({ var PointText = this.PointText = TextItem.extend({ initialize: function(point) { this.base(); - var point = Point.read(arguments); - this._point = LinkedPoint.create(this, 'setPoint', point.x, point.y); - this._matrix = new Matrix().translate(point); + this._point = Point.read(arguments).clone(); + this._matrix = new Matrix().translate(this._point); }, clone: function() { @@ -5595,16 +5642,16 @@ var PointText = this.PointText = TextItem.extend({ }, getPoint: function() { - return this._point; + return LinkedPoint.create(this, 'setPoint', + this._point.x, this._point.y); }, setPoint: function(point) { - this._transform(new Matrix().translate( - Point.read(arguments).subtract(this._point))); + this.translate(Point.read(arguments).subtract(this._point)); }, getPosition: function() { - return this._point; + return this.getPoint(); }, setPosition: function(point) { @@ -5613,7 +5660,7 @@ var PointText = this.PointText = TextItem.extend({ _transform: function(matrix, flags) { this._matrix.preConcatenate(matrix); - matrix._transformPoint(this._point, this._point, true); + matrix._transformPoint(this._point, this._point); }, draw: function(ctx) { @@ -5771,7 +5818,7 @@ var Color = this.Color = Base.extend(new function() { var colorCache = {}, colorContext; - function nameToRGBColor(name) { + function nameToRgbColor(name) { var color = colorCache[name]; if (color) return color.clone(); @@ -5785,10 +5832,10 @@ var Color = this.Color = Base.extend(new function() { colorContext.fillRect(0, 0, 1, 1); var data = colorContext.getImageData(0, 0, 1, 1).data, rgb = [data[0] / 255, data[1] / 255, data[2] / 255]; - return (colorCache[name] = RGBColor.read(rgb)).clone(); + return (colorCache[name] = RgbColor.read(rgb)).clone(); } - function hexToRGBColor(string) { + function hexToRgbColor(string) { var hex = string.match(/^#?(\w{1,2})(\w{1,2})(\w{1,2})$/); if (hex.length >= 4) { var rgb = new Array(3); @@ -5797,7 +5844,7 @@ var Color = this.Color = Base.extend(new function() { rgb[i] = parseInt(channel.length == 1 ? channel + channel : channel, 16) / 255; } - return RGBColor.read(rgb); + return RgbColor.read(rgb); } } @@ -5824,7 +5871,7 @@ var Color = this.Color = Base.extend(new function() { : (r - g) / delta + 4) * 60, s = max == 0 ? 0 : delta / max, v = max; - return new HSBColor(h, s, v, color._alpha); + return new HsbColor(h, s, v, color._alpha); }, 'hsb-rgb': function(color) { @@ -5840,7 +5887,7 @@ var Color = this.Color = Base.extend(new function() { b * (1 - s * f), b * (1 - s * (1 - f)) ]; - return new RGBColor(v[i[0]], v[i[1]], v[i[2]], color._alpha); + return new RgbColor(v[i[0]], v[i[1]], v[i[2]], color._alpha); }, 'rgb-hsl': function(color) { @@ -5850,15 +5897,16 @@ var Color = this.Color = Base.extend(new function() { max = Math.max(r, g, b), min = Math.min(r, g, b), delta = max - min, - h = delta == 0 ? 0 + achromatic = delta == 0, + h = achromatic ? 0 : ( max == r ? (g - b) / delta + (g < b ? 6 : 0) : max == g ? (b - r) / delta + 2 : (r - g) / delta + 4) * 60, l = (max + min) / 2, - s = l < 0.5 - ? delta / (max + min) - : delta / (2 - max - min); - return new HSLColor(h, s, l, color._alpha); + s = achromatic ? 0 : l < 0.5 + ? delta / (max + min) + : delta / (2 - max - min); + return new HslColor(h, s, l, color._alpha); }, 'hsl-rgb': function(color) { @@ -5867,7 +5915,7 @@ var Color = this.Color = Base.extend(new function() { l = color._lightness, t1, t2, c; if (s == 0) - return new RGBColor(l, l, l, color._alpha); + return new RgbColor(l, l, l, color._alpha); var t3s = [ h + 1 / 3, h, h - 1 / 3 ], t2 = l < 0.5 ? l * (1 + s) : l + s - l * s, t1 = 2 * l - t2, @@ -5884,7 +5932,7 @@ var Color = this.Color = Base.extend(new function() { ? t1 + (t2 - t1) * ((2 / 3) - t3) * 6 : t1; } - return new RGBColor(c[0], c[1], c[2], color._alpha); + return new RgbColor(c[0], c[1], c[2], color._alpha); }, 'rgb-gray': function(color) { @@ -5894,15 +5942,15 @@ var Color = this.Color = Base.extend(new function() { 'gray-rgb': function(color) { var comp = 1 - color._gray; - return new RGBColor(comp, comp, comp, color._alpha); + return new RgbColor(comp, comp, comp, color._alpha); }, 'gray-hsb': function(color) { - return new HSBColor(0, 0, 1 - color._gray, color._alpha); + return new HsbColor(0, 0, 1 - color._gray, color._alpha); }, 'gray-hsl': function(color) { - return new HSLColor(0, 0, 1 - color._gray, color._alpha); + return new HslColor(0, 0, 1 - color._gray, color._alpha); } }; @@ -5915,23 +5963,23 @@ var Color = this.Color = Base.extend(new function() { if (typeof arg === 'object' && !isArray) { if (!type) { return arg.red !== undefined - ? new RGBColor(arg.red, arg.green, arg.blue, arg.alpha) + ? new RgbColor(arg.red, arg.green, arg.blue, arg.alpha) : arg.gray !== undefined ? new GrayColor(arg.gray, arg.alpha) : arg.lightness !== undefined - ? new HSLColor(arg.hue, arg.saturation, arg.lightness, + ? new HslColor(arg.hue, arg.saturation, arg.lightness, arg.alpha) : arg.hue !== undefined - ? new HSBColor(arg.hue, arg.saturation, arg.brightness, + ? new HsbColor(arg.hue, arg.saturation, arg.brightness, arg.alpha) - : new RGBColor(); + : new RgbColor(); } else { return Color.read(arguments).convert(type); } } else if (typeof arg === 'string') { var rgbColor = arg.match(/^#[0-9a-f]{3,6}$/i) - ? hexToRGBColor(arg) - : nameToRGBColor(arg); + ? hexToRgbColor(arg) + : nameToRgbColor(arg); return type ? rgbColor.convert(type) : rgbColor; @@ -5940,7 +5988,7 @@ var Color = this.Color = Base.extend(new function() { : Array.prototype.slice.call(arguments); if (!type) { if (components.length >= 3) - return new RGBColor(components); + return new RgbColor(components); return new GrayColor(components); } else { Base.each(this._components, @@ -6121,17 +6169,17 @@ var GrayColor = this.GrayColor = Color.extend({ _colorType: 'gray' }); -var RGBColor = this.RGBColor = Color.extend({ +var RgbColor = this.RgbColor = this.RGBColor = Color.extend({ _colorType: 'rgb' }); -var HSBColor = this.HSBColor = Color.extend({ +var HsbColor = this.HsbColor = this.HSBColor = Color.extend({ _colorType: 'hsb' }); -var HSLColor = this.HSLColor = Color.extend({ +var HslColor = this.HslColor = this.HSLColor = Color.extend({ _colorType: 'hsl' }); @@ -6489,6 +6537,7 @@ var View = this.View = PaperScopeItem.extend({ initialize: function(canvas) { this.base(); var size; + if (typeof canvas === 'string') canvas = document.getElementById(canvas); if (canvas instanceof HTMLCanvasElement) { @@ -6533,16 +6582,19 @@ var View = this.View = PaperScopeItem.extend({ this._id = this._canvas.getAttribute('id'); if (this._id == null) this._canvas.setAttribute('id', this._id = 'canvas-' + View._id++); + View._views[this._id] = this; this._viewSize = LinkedSize.create(this, 'setViewSize', size.width, size.height); this._context = this._canvas.getContext('2d'); this._matrix = new Matrix(); this._zoom = 1; + this._events = this._createEvents(); DomEvent.add(this._canvas, this._events); if (!View._focused) View._focused = this; + this._scope._redrawNotified = false; }, @@ -6557,6 +6609,22 @@ var View = this.View = PaperScopeItem.extend({ return true; }, + _redraw: function() { + this._redrawNeeded = true; + if (this._onFrameCallback) { + this._onFrameCallback(0, true); + } else { + this.draw(); + } + }, + + _transform: function(matrix, flags) { + this._matrix.preConcatenate(matrix); + this._bounds = null; + this._inverse = null; + this._redraw(); + }, + getCanvas: function() { return this._canvas; }, @@ -6581,16 +6649,12 @@ var View = this.View = PaperScopeItem.extend({ delta: delta }); } - if (this._onFrameCallback) { - this._onFrameCallback(0, true); - } else { - this.draw(true); - } + this._redraw(); }, getBounds: function() { if (!this._bounds) - this._bounds = this._matrix._transformBounds( + this._bounds = this._getInverse()._transformBounds( new Rectangle(new Point(), this._viewSize)); return this._bounds; }, @@ -6624,12 +6688,6 @@ var View = this.View = PaperScopeItem.extend({ this._transform(new Matrix().translate(Point.read(arguments).negate())); }, - _transform: function(matrix, flags) { - this._matrix.preConcatenate(matrix); - this._bounds = null; - this._inverse = null; - }, - draw: function(checkRedraw) { if (checkRedraw && !this._redrawNeeded) return false; @@ -6704,7 +6762,12 @@ var View = this.View = PaperScopeItem.extend({ }, onResize: null -}, new function() { +}, { + statics: { + _views: {}, + _id: 0 + } +}, new function() { var tool, timer, curPoint, @@ -6815,8 +6878,6 @@ var View = this.View = PaperScopeItem.extend({ }, statics: { - _views: {}, - _id: 0, updateFocus: updateFocus } @@ -6883,7 +6944,9 @@ var Key = this.Key = new function() { 39: 'right', 40: 'down', 46: 'delete', - 91: 'command' + 91: 'command', + 93: 'command', + 224: 'command' }, modifiers = Base.merge({ @@ -6920,12 +6983,10 @@ var Key = this.Key = new function() { var code = event.which || event.keyCode; var key = keys[code], name; if (key) { - if (modifiers[name = Base.camelize(key)] !== undefined) { + if ((name = Base.camelize(key)) in modifiers) modifiers[name] = true; - } else { - charCodeMap[code] = 0; - handleKey(true, code, null, event); - } + charCodeMap[code] = 0; + handleKey(true, code, null, event); } else { downCode = code; } @@ -6943,9 +7004,9 @@ var Key = this.Key = new function() { keyup: function(event) { var code = event.which || event.keyCode, key = keys[code], name; - if (key && modifiers[name = Base.camelize(key)] !== undefined) { + if (key && (name = Base.camelize(key)) in modifiers) modifiers[name] = false; - } else if (charCodeMap[code] != null) { + if (charCodeMap[code] != null) { handleKey(false, code, charCodeMap[code], event); delete charCodeMap[code]; } @@ -7778,4 +7839,4 @@ Base.each(this, function(val, key) { this.enumerable = true; return new (PaperScope.inject(this)); -}; +}; \ No newline at end of file diff --git a/dist/paper.js b/dist/paper.js index ea11ce94..e963d27f 100644 --- a/dist/paper.js +++ b/dist/paper.js @@ -1,27 +1,27 @@ /*! - * Paper.js v0.21 + * Paper.js v0.22 * * This file is part of Paper.js, a JavaScript Vector Graphics Library, * based on Scriptographer.org and designed to be largely API compatible. - * http: - * http: + * http://paperjs.org/ + * http://scriptographer.org/ * * Copyright (c) 2011, Juerg Lehni & Jonathan Puckey - * http: + * http://lehni.org/ & http://jonathanpuckey.com/ * * Distributed under the MIT license. See LICENSE file for details. * * All rights reserved. * - * Date: Tue Aug 2 10:08:08 2011 +0100 + * Date: Thu Nov 10 18:30:18 2011 +0100 * *** * * Bootstrap.js JavaScript Framework. - * http: + * http://bootstrapjs.org/ * * Copyright (c) 2006 - 2011 Juerg Lehni - * http: + * http://lehni.org/ * * Distributed under the MIT license. * @@ -31,14 +31,14 @@ * * A JavaScript tokenizer / parser / generator, originally written in Lisp. * Copyright (c) Marijn Haverbeke - * http: + * http://marijn.haverbeke.nl/parse-js/ * * Ported by to JavaScript by Mihai Bazon * Copyright (c) 2010, Mihai Bazon - * http: + * http://mihai.bazon.net/blog/ * * Modifications and adaptions to browser (c) 2011, Juerg Lehni - * http: + * http://lehni.org/ * * Distributed under the BSD license. */ @@ -409,7 +409,7 @@ var PaperScope = this.PaperScope = Base.extend({ PaperScope._scopes[this._id] = this; }, - version: 0.21, + version: 0.22, evaluate: function(code) { var res = PaperScript.evaluate(code, this); @@ -804,7 +804,9 @@ var LinkedPoint = Point.extend({ }, statics: { - create: function(owner, setter, x, y) { + create: function(owner, setter, x, y, dontLink) { + if (dontLink) + return Point.create(x, y); var point = new LinkedPoint(LinkedPoint.dont); point._x = x; point._y = y; @@ -893,7 +895,7 @@ var Size = this.Size = Base.extend({ }, isZero: function() { - return this.width == 0 && this.width == 0; + return this.width == 0 && this.height == 0; }, isNaN: function() { @@ -959,13 +961,15 @@ var LinkedSize = Size.extend({ }, statics: { - create: function(owner, setter, width, height) { - var point = new LinkedSize(LinkedSize.dont); - point._width = width; - point._height = height; - point._owner = owner; - point._setter = setter; - return point; + create: function(owner, setter, width, height, dontLink) { + if (dontLink) + return Size.create(width, height); + var size = new LinkedSize(LinkedSize.dont); + size._width = width; + size._height = height; + size._owner = owner; + size._setter = setter; + return size; } } }); @@ -1020,7 +1024,8 @@ var Rectangle = this.Rectangle = Base.extend({ }, getPoint: function() { - return LinkedPoint.create(this, 'setPoint', this.x, this.y); + return LinkedPoint.create(this, 'setPoint', this.x, this.y, + arguments[0]); }, setPoint: function(point) { @@ -1031,7 +1036,8 @@ var Rectangle = this.Rectangle = Base.extend({ }, getSize: function() { - return LinkedSize.create(this, 'setSize', this.width, this.height); + return LinkedSize.create(this, 'setSize', this.width, this.height, + arguments[0]); }, setSize: function(size) { @@ -1099,7 +1105,7 @@ var Rectangle = this.Rectangle = Base.extend({ getCenter: function() { return LinkedPoint.create(this, 'setCenter', - this.getCenterX(), this.getCenterY()); + this.getCenterX(), this.getCenterY(), arguments[0]); }, setCenter: function(point) { @@ -1223,7 +1229,7 @@ var Rectangle = this.Rectangle = Base.extend({ set = 'set' + part; this[get] = function() { return LinkedPoint.create(this, set, - this[getX](), this[getY]()); + this[getX](), this[getY](), arguments[0]); }; this[set] = function(point) { point = Point.read(arguments); @@ -1323,7 +1329,7 @@ var Matrix = this.Matrix = Base.extend({ return this; }, - scale: function(hor, ver , center) { + scale: function( hor, ver, center) { if (arguments.length < 2 || typeof ver === 'object') { center = Point.read(arguments, 1); ver = hor; @@ -1354,7 +1360,7 @@ var Matrix = this.Matrix = Base.extend({ Matrix.getRotateInstance.apply(Matrix, arguments)); }, - shear: function(hor, ver, center) { + shear: function( hor, ver, center) { if (arguments.length < 2 || typeof ver === 'object') { center = Point.read(arguments, 1); ver = hor; @@ -1471,8 +1477,30 @@ var Matrix = this.Matrix = Base.extend({ max[0] - min[0], max[1] - min[1]); }, - getDeterminant: function() { - return this._a * this._d - this._b * this._c; + inverseTransform: function(point) { + return this._inverseTransform(Point.read(arguments)); + }, + + _getDeterminant: function() { + var det = this._a * this._d - this._b * this._c; + return isFinite(det) && Math.abs(det) > Numerical.EPSILON + && isFinite(this._tx) && isFinite(this._ty) + ? det : null; + }, + + _inverseTransform: function(point, dest, dontNotify) { + var det = this._getDeterminant(); + if (!det) + return null; + var x = point.x - this._tx, + y = point.y - this._ty; + if (!dest) + dest = new Point(Point.dont); + return dest.set( + (x * this._d - y * this._b) / det, + (y * this._a - x * this._c) / det, + dontNotify + ); }, getTranslation: function() { @@ -1498,28 +1526,22 @@ var Matrix = this.Matrix = Base.extend({ }, isInvertible: function() { - var det = this.getDeterminant(); - return isFinite(det) && det != 0 && isFinite(this._tx) - && isFinite(this._ty); + return !!this._getDeterminant(); }, isSingular: function() { - return !this.isInvertible(); + return !this._getDeterminant(); }, createInverse: function() { - var det = this.getDeterminant(); - if (isFinite(det) && det != 0 && isFinite(this._tx) - && isFinite(this._ty)) { - return Matrix.create( + var det = this._getDeterminant(); + return det && Matrix.create( this._d / det, -this._c / det, -this._b / det, this._a / det, (this._b * this._ty - this._d * this._tx) / det, (this._c * this._tx - this._a * this._ty) / det); - } - return null; }, createShiftless: function() { @@ -1818,11 +1840,20 @@ var Item = this.Item = Base.extend({ delete this._position; } if (flags & ChangeFlag.APPEARANCE) { - if (this._project) - this._project._needsRedraw(); + this._project._needsRedraw(); } if (this._parentSymbol) this._parentSymbol._changed(flags); + if (this._project._changes) { + var entry = this._project._changesById[this._id]; + if (entry) { + entry.flags |= flags; + } else { + entry = { item: this, flags: flags }; + this._project._changesById[this._id] = entry; + this._project._changes.push(entry); + } + } }, getId: function() { @@ -1972,6 +2003,15 @@ var Item = this.Item = Base.extend({ } }, + getLayer: function() { + var parent = this; + while (parent = parent._parent) { + if (parent instanceof Layer) + return parent; + } + return null; + }, + getParent: function() { return this._parent; }, @@ -2048,8 +2088,7 @@ var Item = this.Item = Base.extend({ matrix.applyToContext(ctx); this.draw(ctx, {}); var raster = new Raster(canvas); - raster.setPosition(this.getPosition()); - raster.scale(1 / scale); + raster.setBounds(bounds); return raster; }, @@ -2855,7 +2894,7 @@ var Raster = this.Raster = PlacedItem.extend({ channels = new Array(4); for (var i = 0; i < 4; i++) channels[i] = pixels[i] / 255; - return RGBColor.read(channels); + return RgbColor.read(channels); }, setPixel: function(point, color) { @@ -3102,6 +3141,7 @@ var Segment = this.Segment = Base.extend({ if (selected) selection[0] = false; selection[index] = selected; + path._changed(Change.ATTRIBUTE); } } this._selectionState = (selection[0] ? SelectionState.POINT : 0) @@ -3241,6 +3281,10 @@ var SegmentPoint = Point.extend({ this._owner._changed(this); }, + isZero: function() { + return this._x == 0 && this._y == 0; + }, + setSelected: function(selected) { this._owner._setSelected(this, selected); }, @@ -3742,7 +3786,7 @@ var Curve = this.Curve = Base.extend({ return [0.5 * (w[0].x + w[5].x)]; if (isFlatEnough(w)) { var line = new Line(w[0], w[5], true); - return [ line.vector.getLength(true) < Numerical.EPSILON + return [ line.vector.getLength(true) <= Numerical.EPSILON ? line.point.x : xAxis.intersect(line).x ]; } @@ -4427,8 +4471,8 @@ var Path = this.Path = PathItem.extend({ ctx.rect(point._x - 1, point._y - 1, 2, 2); ctx.fillStyle = '#ffffff'; ctx.fill(); - ctx.restore(); } + ctx.restore(); } } @@ -5051,13 +5095,17 @@ Path.inject({ statics: new function() { Rectangle: function(rect) { rect = Rectangle.read(arguments); - var path = new Path(), - corners = ['getBottomLeft', 'getTopLeft', 'getTopRight', - 'getBottomRight'], - segments = new Array(4); - for (var i = 0; i < 4; i++) - segments[i] = new Segment(rect[corners[i]]()); - path._add(segments); + var left = rect.x, + top = rect.y + right = left + rect.width, + bottom = top + rect.height, + path = new Path(); + path._add([ + new Segment(Point.create(left, bottom)), + new Segment(Point.create(left, top)), + new Segment(Point.create(right, top)), + new Segment(Point.create(right, bottom)) + ]); path._closed = true; return path; }, @@ -5070,13 +5118,13 @@ Path.inject({ statics: new function() { rect = Rectangle.read(arguments, 0, 4); size = Size.read(arguments, 4, 2); } - size = Size.min(size, rect.getSize().divide(2)); + size = Size.min(size, rect.getSize(true).divide(2)); var path = new Path(), uSize = size.multiply(kappa * 2), - bl = rect.getBottomLeft(), - tl = rect.getTopLeft(), - tr = rect.getTopRight(), - br = rect.getBottomRight(); + bl = rect.getBottomLeft(true), + tl = rect.getTopLeft(true), + tr = rect.getTopRight(true), + br = rect.getBottomRight(true); path._add([ new Segment(bl.add(size.width, 0), null, [-uSize.width, 0]), new Segment(bl.subtract(0, size.height), [0, uSize.height], null), @@ -5097,13 +5145,13 @@ Path.inject({ statics: new function() { Oval: function(rect) { rect = Rectangle.read(arguments); var path = new Path(), - topLeft = rect.getTopLeft(), - size = new Size(rect.width, rect.height), + point = rect.getPoint(true), + size = rect.getSize(true), segments = new Array(4); for (var i = 0; i < 4; i++) { var segment = ovalSegments[i]; segments[i] = new Segment( - segment._point.multiply(size).add(topLeft), + segment._point.multiply(size).add(point), segment._handleIn.multiply(size), segment._handleOut.multiply(size) ); @@ -5121,7 +5169,7 @@ Path.inject({ statics: new function() { center = Point.read(arguments, 0, 1); } return Path.Oval(new Rectangle(center.subtract(radius), - new Size(radius * 2, radius * 2))); + Size.create(radius * 2, radius * 2))); }, Arc: function(from, through, to) { @@ -5583,9 +5631,8 @@ var TextItem = this.TextItem = Item.extend({ var PointText = this.PointText = TextItem.extend({ initialize: function(point) { this.base(); - var point = Point.read(arguments); - this._point = LinkedPoint.create(this, 'setPoint', point.x, point.y); - this._matrix = new Matrix().translate(point); + this._point = Point.read(arguments).clone(); + this._matrix = new Matrix().translate(this._point); }, clone: function() { @@ -5595,16 +5642,16 @@ var PointText = this.PointText = TextItem.extend({ }, getPoint: function() { - return this._point; + return LinkedPoint.create(this, 'setPoint', + this._point.x, this._point.y); }, setPoint: function(point) { - this._transform(new Matrix().translate( - Point.read(arguments).subtract(this._point))); + this.translate(Point.read(arguments).subtract(this._point)); }, getPosition: function() { - return this._point; + return this.getPoint(); }, setPosition: function(point) { @@ -5613,7 +5660,7 @@ var PointText = this.PointText = TextItem.extend({ _transform: function(matrix, flags) { this._matrix.preConcatenate(matrix); - matrix._transformPoint(this._point, this._point, true); + matrix._transformPoint(this._point, this._point); }, draw: function(ctx) { @@ -5771,7 +5818,7 @@ var Color = this.Color = Base.extend(new function() { var colorCache = {}, colorContext; - function nameToRGBColor(name) { + function nameToRgbColor(name) { var color = colorCache[name]; if (color) return color.clone(); @@ -5785,10 +5832,10 @@ var Color = this.Color = Base.extend(new function() { colorContext.fillRect(0, 0, 1, 1); var data = colorContext.getImageData(0, 0, 1, 1).data, rgb = [data[0] / 255, data[1] / 255, data[2] / 255]; - return (colorCache[name] = RGBColor.read(rgb)).clone(); + return (colorCache[name] = RgbColor.read(rgb)).clone(); } - function hexToRGBColor(string) { + function hexToRgbColor(string) { var hex = string.match(/^#?(\w{1,2})(\w{1,2})(\w{1,2})$/); if (hex.length >= 4) { var rgb = new Array(3); @@ -5797,7 +5844,7 @@ var Color = this.Color = Base.extend(new function() { rgb[i] = parseInt(channel.length == 1 ? channel + channel : channel, 16) / 255; } - return RGBColor.read(rgb); + return RgbColor.read(rgb); } } @@ -5824,7 +5871,7 @@ var Color = this.Color = Base.extend(new function() { : (r - g) / delta + 4) * 60, s = max == 0 ? 0 : delta / max, v = max; - return new HSBColor(h, s, v, color._alpha); + return new HsbColor(h, s, v, color._alpha); }, 'hsb-rgb': function(color) { @@ -5840,7 +5887,7 @@ var Color = this.Color = Base.extend(new function() { b * (1 - s * f), b * (1 - s * (1 - f)) ]; - return new RGBColor(v[i[0]], v[i[1]], v[i[2]], color._alpha); + return new RgbColor(v[i[0]], v[i[1]], v[i[2]], color._alpha); }, 'rgb-hsl': function(color) { @@ -5850,15 +5897,16 @@ var Color = this.Color = Base.extend(new function() { max = Math.max(r, g, b), min = Math.min(r, g, b), delta = max - min, - h = delta == 0 ? 0 + achromatic = delta == 0, + h = achromatic ? 0 : ( max == r ? (g - b) / delta + (g < b ? 6 : 0) : max == g ? (b - r) / delta + 2 : (r - g) / delta + 4) * 60, l = (max + min) / 2, - s = l < 0.5 - ? delta / (max + min) - : delta / (2 - max - min); - return new HSLColor(h, s, l, color._alpha); + s = achromatic ? 0 : l < 0.5 + ? delta / (max + min) + : delta / (2 - max - min); + return new HslColor(h, s, l, color._alpha); }, 'hsl-rgb': function(color) { @@ -5867,7 +5915,7 @@ var Color = this.Color = Base.extend(new function() { l = color._lightness, t1, t2, c; if (s == 0) - return new RGBColor(l, l, l, color._alpha); + return new RgbColor(l, l, l, color._alpha); var t3s = [ h + 1 / 3, h, h - 1 / 3 ], t2 = l < 0.5 ? l * (1 + s) : l + s - l * s, t1 = 2 * l - t2, @@ -5884,7 +5932,7 @@ var Color = this.Color = Base.extend(new function() { ? t1 + (t2 - t1) * ((2 / 3) - t3) * 6 : t1; } - return new RGBColor(c[0], c[1], c[2], color._alpha); + return new RgbColor(c[0], c[1], c[2], color._alpha); }, 'rgb-gray': function(color) { @@ -5894,15 +5942,15 @@ var Color = this.Color = Base.extend(new function() { 'gray-rgb': function(color) { var comp = 1 - color._gray; - return new RGBColor(comp, comp, comp, color._alpha); + return new RgbColor(comp, comp, comp, color._alpha); }, 'gray-hsb': function(color) { - return new HSBColor(0, 0, 1 - color._gray, color._alpha); + return new HsbColor(0, 0, 1 - color._gray, color._alpha); }, 'gray-hsl': function(color) { - return new HSLColor(0, 0, 1 - color._gray, color._alpha); + return new HslColor(0, 0, 1 - color._gray, color._alpha); } }; @@ -5915,23 +5963,23 @@ var Color = this.Color = Base.extend(new function() { if (typeof arg === 'object' && !isArray) { if (!type) { return arg.red !== undefined - ? new RGBColor(arg.red, arg.green, arg.blue, arg.alpha) + ? new RgbColor(arg.red, arg.green, arg.blue, arg.alpha) : arg.gray !== undefined ? new GrayColor(arg.gray, arg.alpha) : arg.lightness !== undefined - ? new HSLColor(arg.hue, arg.saturation, arg.lightness, + ? new HslColor(arg.hue, arg.saturation, arg.lightness, arg.alpha) : arg.hue !== undefined - ? new HSBColor(arg.hue, arg.saturation, arg.brightness, + ? new HsbColor(arg.hue, arg.saturation, arg.brightness, arg.alpha) - : new RGBColor(); + : new RgbColor(); } else { return Color.read(arguments).convert(type); } } else if (typeof arg === 'string') { var rgbColor = arg.match(/^#[0-9a-f]{3,6}$/i) - ? hexToRGBColor(arg) - : nameToRGBColor(arg); + ? hexToRgbColor(arg) + : nameToRgbColor(arg); return type ? rgbColor.convert(type) : rgbColor; @@ -5940,7 +5988,7 @@ var Color = this.Color = Base.extend(new function() { : Array.prototype.slice.call(arguments); if (!type) { if (components.length >= 3) - return new RGBColor(components); + return new RgbColor(components); return new GrayColor(components); } else { Base.each(this._components, @@ -6121,17 +6169,17 @@ var GrayColor = this.GrayColor = Color.extend({ _colorType: 'gray' }); -var RGBColor = this.RGBColor = Color.extend({ +var RgbColor = this.RgbColor = this.RGBColor = Color.extend({ _colorType: 'rgb' }); -var HSBColor = this.HSBColor = Color.extend({ +var HsbColor = this.HsbColor = this.HSBColor = Color.extend({ _colorType: 'hsb' }); -var HSLColor = this.HSLColor = Color.extend({ +var HslColor = this.HslColor = this.HSLColor = Color.extend({ _colorType: 'hsl' }); @@ -6489,6 +6537,7 @@ var View = this.View = PaperScopeItem.extend({ initialize: function(canvas) { this.base(); var size; + if (typeof canvas === 'string') canvas = document.getElementById(canvas); if (canvas instanceof HTMLCanvasElement) { @@ -6533,16 +6582,19 @@ var View = this.View = PaperScopeItem.extend({ this._id = this._canvas.getAttribute('id'); if (this._id == null) this._canvas.setAttribute('id', this._id = 'canvas-' + View._id++); + View._views[this._id] = this; this._viewSize = LinkedSize.create(this, 'setViewSize', size.width, size.height); this._context = this._canvas.getContext('2d'); this._matrix = new Matrix(); this._zoom = 1; + this._events = this._createEvents(); DomEvent.add(this._canvas, this._events); if (!View._focused) View._focused = this; + this._scope._redrawNotified = false; }, @@ -6557,6 +6609,22 @@ var View = this.View = PaperScopeItem.extend({ return true; }, + _redraw: function() { + this._redrawNeeded = true; + if (this._onFrameCallback) { + this._onFrameCallback(0, true); + } else { + this.draw(); + } + }, + + _transform: function(matrix, flags) { + this._matrix.preConcatenate(matrix); + this._bounds = null; + this._inverse = null; + this._redraw(); + }, + getCanvas: function() { return this._canvas; }, @@ -6581,16 +6649,12 @@ var View = this.View = PaperScopeItem.extend({ delta: delta }); } - if (this._onFrameCallback) { - this._onFrameCallback(0, true); - } else { - this.draw(true); - } + this._redraw(); }, getBounds: function() { if (!this._bounds) - this._bounds = this._matrix._transformBounds( + this._bounds = this._getInverse()._transformBounds( new Rectangle(new Point(), this._viewSize)); return this._bounds; }, @@ -6624,12 +6688,6 @@ var View = this.View = PaperScopeItem.extend({ this._transform(new Matrix().translate(Point.read(arguments).negate())); }, - _transform: function(matrix, flags) { - this._matrix.preConcatenate(matrix); - this._bounds = null; - this._inverse = null; - }, - draw: function(checkRedraw) { if (checkRedraw && !this._redrawNeeded) return false; @@ -6704,7 +6762,12 @@ var View = this.View = PaperScopeItem.extend({ }, onResize: null -}, new function() { +}, { + statics: { + _views: {}, + _id: 0 + } +}, new function() { var tool, timer, curPoint, @@ -6815,8 +6878,6 @@ var View = this.View = PaperScopeItem.extend({ }, statics: { - _views: {}, - _id: 0, updateFocus: updateFocus } @@ -6883,7 +6944,9 @@ var Key = this.Key = new function() { 39: 'right', 40: 'down', 46: 'delete', - 91: 'command' + 91: 'command', + 93: 'command', + 224: 'command' }, modifiers = Base.merge({ @@ -6920,12 +6983,10 @@ var Key = this.Key = new function() { var code = event.which || event.keyCode; var key = keys[code], name; if (key) { - if (modifiers[name = Base.camelize(key)] !== undefined) { + if ((name = Base.camelize(key)) in modifiers) modifiers[name] = true; - } else { - charCodeMap[code] = 0; - handleKey(true, code, null, event); - } + charCodeMap[code] = 0; + handleKey(true, code, null, event); } else { downCode = code; } @@ -6943,9 +7004,9 @@ var Key = this.Key = new function() { keyup: function(event) { var code = event.which || event.keyCode, key = keys[code], name; - if (key && modifiers[name = Base.camelize(key)] !== undefined) { + if (key && (name = Base.camelize(key)) in modifiers) modifiers[name] = false; - } else if (charCodeMap[code] != null) { + if (charCodeMap[code] != null) { handleKey(false, code, charCodeMap[code], event); delete charCodeMap[code]; } @@ -7778,4 +7839,4 @@ Base.each(this, function(val, key) { this.enumerable = true; return new (PaperScope.inject(this)); -}; +}; \ No newline at end of file