svgedit/dist/svgcanvas-iife.min.js

20 lines
186 KiB
JavaScript
Raw Normal View History

var SvgCanvas=function(){"use strict";function e(t){return(e="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(e){return typeof e}:function(e){return e&&"function"==typeof Symbol&&e.constructor===Symbol&&e!==Symbol.prototype?"symbol":typeof e})(t)}function t(e,t,r,n,i,a,s){try{var o=e[a](s),u=o.value}catch(e){return void r(e)}o.done?t(u):Promise.resolve(u).then(n,i)}function r(e){return function(){var r=this,n=arguments;return new Promise((function(i,a){var s=e.apply(r,n);function o(e){t(s,i,a,o,u,"next",e)}function u(e){t(s,i,a,o,u,"throw",e)}o(void 0)}))}}function n(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}function i(e,t){for(var r=0;r<t.length;r++){var n=t[r];n.enumerable=n.enumerable||!1,n.configurable=!0,"value"in n&&(n.writable=!0),Object.defineProperty(e,n.key,n)}}function a(e,t,r){return t&&i(e.prototype,t),r&&i(e,r),e}function s(e,t){if("function"!=typeof t&&null!==t)throw new TypeError("Super expression must either be null or a function");e.prototype=Object.create(t&&t.prototype,{constructor:{value:e,writable:!0,configurable:!0}}),t&&u(e,t)}function o(e){return(o=Object.setPrototypeOf?Object.getPrototypeOf:function(e){return e.__proto__||Object.getPrototypeOf(e)})(e)}function u(e,t){return(u=Object.setPrototypeOf||function(e,t){return e.__proto__=t,e})(e,t)}function l(e,t){return!t||"object"!=typeof t&&"function"!=typeof t?function(e){if(void 0===e)throw new ReferenceError("this hasn't been initialised - super() hasn't been called");return e}(e):t}function h(e,t){return function(e){if(Array.isArray(e))return e}(e)||function(e,t){if(!(Symbol.iterator in Object(e)||"[object Arguments]"===Object.prototype.toString.call(e)))return;var r=[],n=!0,i=!1,a=void 0;try{for(var s,o=e[Symbol.iterator]();!(n=(s=o.next()).done)&&(r.push(s.value),!t||r.length!==t);n=!0);}catch(e){i=!0,a=e}finally{try{n||null==o.return||o.return()}finally{if(i)throw a}}return r}(e,t)||function(){throw new TypeError("Invalid attempt to destructure non-iterable instance")}()}function c(e){return function(e){if(Array.isArray(e)){for(var t=0,r=new Array(e.length);t<e.length;t++)r[t]=e[t];return r}}(e)||function(e){if(Symbol.iterator in Object(e)||"[object Arguments]"===Object.prototype.toString.call(e))return Array.from(e)}(e)||function(){throw new TypeError("Invalid attempt to spread non-iterable instance")}()}
/**
* A jQuery module to work with SVG attributes.
* @module jQueryAttr
* @license MIT
*/
function d(t){var r=t.fn.attr;return t.fn.attr=function(t,n){var i=this.length;if(!i)return r.call(this,t,n);for(var a=0;a<i;++a){var s=this[a];if("http://www.w3.org/2000/svg"!==s.namespaceURI)return r.call(this,t,n);if(void 0!==n)s.setAttribute(t,n);else if(Array.isArray(t)){for(var o={},u=t.length;u--;){var l=t[u],c=s.getAttribute(l);(c||"0"===c)&&(c=isNaN(c)?c:c-0),o[l]=c}return o}if("object"!==e(t)){var d=s.getAttribute(t);return(d||"0"===d)&&(d=isNaN(d)?d:d-0),d}for(var m=0,f=Object.entries(t);m<f.length;m++){var g=h(f[m],2),p=g[0],y=g[1];s.setAttribute(p,y)}}return this},t}!function(){if(!("SVGPathSeg"in window)){var e=function(){function e(t,r,i){n(this,e),this.pathSegType=t,this.pathSegTypeAsLetter=r,this._owningPathSegList=i}return a(e,[{key:"_segmentChanged",value:function(){this._owningPathSegList&&this._owningPathSegList.segmentChanged(this)}}]),e}();e.prototype.classname="SVGPathSeg",e.PATHSEG_UNKNOWN=0,e.PATHSEG_CLOSEPATH=1,e.PATHSEG_MOVETO_ABS=2,e.PATHSEG_MOVETO_REL=3,e.PATHSEG_LINETO_ABS=4,e.PATHSEG_LINETO_REL=5,e.PATHSEG_CURVETO_CUBIC_ABS=6,e.PATHSEG_CURVETO_CUBIC_REL=7,e.PATHSEG_CURVETO_QUADRATIC_ABS=8,e.PATHSEG_CURVETO_QUADRATIC_REL=9,e.PATHSEG_ARC_ABS=10,e.PATHSEG_ARC_REL=11,e.PATHSEG_LINETO_HORIZONTAL_ABS=12,e.PATHSEG_LINETO_HORIZONTAL_REL=13,e.PATHSEG_LINETO_VERTICAL_ABS=14,e.PATHSEG_LINETO_VERTICAL_REL=15,e.PATHSEG_CURVETO_CUBIC_SMOOTH_ABS=16,e.PATHSEG_CURVETO_CUBIC_SMOOTH_REL=17,e.PATHSEG_CURVETO_QUADRATIC_SMOOTH_ABS=18,e.PATHSEG_CURVETO_QUADRATIC_SMOOTH_REL=19;var t=function(t){function r(t){return n(this,r),l(this,o(r).call(this,e.PATHSEG_CLOSEPATH,"z",t))}return s(r,t),a(r,[{key:"toString",value:function(){return"[object SVGPathSegClosePath]"}},{key:"_asPathString",value:function(){return this.pathSegTypeAsLetter}},{key:"clone",value:function(){return new r(void 0)}}]),r}(e),r=function(t){function r(t,i,a){var s;return n(this,r),(s=l(this,o(r).call(this,e.PATHSEG_MOVETO_ABS,"M",t)))._x=i,s._y=a,s}return s(r,t),a(r,[{key:"toString",value:function(){return"[object SVGPathSegMovetoAbs]"}},{key:"_asPathString",value:function(){return this.pathSegTypeAsLetter+" "+this._x+" "+this._y}},{key:"clone",value:function(){return new r(void 0,this._x,this._y)}}]),r}(e);Object.defineProperties(r.prototype,{x:{get:function(){return this._x},set:function(e){this._x=e,this._segmentChanged()},enumerable:!0},y:{get:function(){return this._y},set:function(e){this._y=e,this._segmentChanged()},enumerable:!0}});var i=function(t){function r(t,i,a){var s;return n(this,r),(s=l(this,o(r).call(this,e.PATHSEG_MOVETO_REL,"m",t)))._x=i,s._y=a,s}return s(r,t),a(r,[{key:"toString",value:function(){return"[object SVGPathSegMovetoRel]"}},{key:"_asPathString",value:function(){return this.pathSegTypeAsLetter+" "+this._x+" "+this._y}},{key:"clone",value:function(){return new r(void 0,this._x,this._y)}}]),r}(e);Object.defineProperties(i.prototype,{x:{get:function(){return this._x},set:function(e){this._x=e,this._segmentChanged()},enumerable:!0},y:{get:function(){return this._y},set:function(e){this._y=e,this._segmentChanged()},enumerable:!0}});var u=function(t){function r(t,i,a){var s;return n(this,r),(s=l(this,o(r).call(this,e.PATHSEG_LINETO_ABS,"L",t)))._x=i,s._y=a,s}return s(r,t),a(r,[{key:"toString",value:function(){return"[object SVGPathSegLinetoAbs]"}},{key:"_asPathString",value:function(){return this.pathSegTypeAsLetter+" "+this._x+" "+this._y}},{key:"clone",value:function(){return new r(void 0,this._x,this._y)}}]),r}(e);Object.defineProperties(u.prototype,{x:{get:function(){return this._x},set:function(e){this._x=e,this._segmentChanged()},enumerable:!0},y:{get:function(){return this._y},set:function(e){this._y=e,this._segmentChanged()},enumerable:!0}});var h=function(t){function r(t,i,a){var s;return n(this,r),(s=l(this,o(r).call(this,e.PATHSEG_LINETO_REL,"l",t)))._x=i,s._y=a,s}return s(r,t),a(r,[{key:"toString",value:function(){return"[object SVGPathSegLinetoRel]"}},{key:"_asPathString",value:function(){return this.pathSegTypeAsLetter+" "+this._x+" "+this._y}},{key:"clone",value:function(){return new r(void 0,this._x,this._
/**
* Namespaces or tools therefor.
* @module namespaces
* @license MIT
*/
var m,f={HTML:"http://www.w3.org/1999/xhtml",MATH:"http://www.w3.org/1998/Math/MathML",SE:"http://svg-edit.googlecode.com",SVG:"http://www.w3.org/2000/svg",XLINK:"http://www.w3.org/1999/xlink",XML:"http://www.w3.org/XML/1998/namespace",XMLNS:"http://www.w3.org/2000/xmlns/"},g=function(){var e={};return Object.entries(f).forEach((function(t){var r=h(t,2),n=r[0],i=r[1];e[i]=n.toLowerCase()})),e},p=jQuery,y=(Boolean(document.createElementNS&&document.createElementNS(f.SVG,"svg").createSVGRect),navigator.userAgent),v=document.createElementNS(f.SVG,"svg"),x=Boolean(window.opera),_=y.includes("AppleWebKit"),S=y.includes("Gecko/"),b=y.includes("MSIE"),w=y.includes("Chrome/"),A=(y.includes("Windows"),y.includes("Macintosh"),"ontouchstart"in window),k=Boolean(v.querySelector),C=Boolean(document.evaluate),E=function(){var e=document.createElementNS(f.SVG,"path");e.setAttribute("d","M0,0 10,10");var t=e.pathSegList,r=e.createSVGPathSegLinetoAbs(5,5);try{return t.replaceItem(r,1),!0}catch(e){}return!1}(),P=function(){var e=document.createElementNS(f.SVG,"path");e.setAttribute("d","M0,0 10,10");var t=e.pathSegList,r=e.createSVGPathSegLinetoAbs(5,5);try{return t.insertItemBefore(r,1),!0}catch(e){}return!1}(),G=function(){var e=document.createElementNS(f.SVG,"svg"),t=document.createElementNS(f.SVG,"svg");document.documentElement.append(e),t.setAttribute("x",5),e.append(t);var r=document.createElementNS(f.SVG,"text");r.textContent="a",t.append(r);try{return 0===r.getStartPositionOfChar(0).x}catch(e){return!1}finally{e.remove()}}(),N=function(){var e=document.createElementNS(f.SVG,"svg");document.documentElement.append(e);var t=document.createElementNS(f.SVG,"path");t.setAttribute("d","M0,0 C0,0 10,10 10,0"),e.append(t);var r=t.getBBox();return e.remove(),r.height>4&&r.height<5}(),I=function(){var e=document.createElementNS(f.SVG,"svg");document.documentElement.append(e);var t=document.createElementNS(f.SVG,"path");t.setAttribute("d","M0,0 10,0");var r=document.createElementNS(f.SVG,"path");r.setAttribute("d","M5,0 15,0");var n=document.createElementNS(f.SVG,"g");n.append(t,r),e.append(n);var i=n.getBBox();return e.remove(),15===i.width}(),T=(function(){var e=document.createElementNS(f.SVG,"rect");e.setAttribute("x",.1);var t=!e.cloneNode(!1).getAttribute("x").includes(",");t||p.alert('NOTE: This version of Opera is known to contain bugs in SVG-edit.\nPlease upgrade to the <a href="http://opera.com">latest version</a> in which the problems have been fixed.')}(),(m=document.createElementNS(f.SVG,"rect")).setAttribute("style","vector-effect:non-scaling-stroke"),"non-scaling-stroke"===m.style.vectorEffect),L=function(){var t=document.createElementNS(f.SVG,"rect").transform.baseVal,r=v.createSVGTransform();t.appendItem(r);var n=t.getItem(0),i=function(t){return t&&"object"===e(t)&&"function"==typeof t.setMatrix&&"angle"in t};return i(n)&&i(r)&&n.type===r.type&&n.angle===r.angle&&n.matrix.a===r.matrix.a&&n.matrix.b===r.matrix.b&&n.matrix.c===r.matrix.c&&n.matrix.d===r.matrix.d&&n.matrix.e===r.matrix.e&&n.matrix.f===r.matrix.f}(),V=function(){return x},O=function(){return _},M=function(){return S},R=function(){return b},B=function(){return w},U=function(){return I},H=function(){return T},j=document.createElementNS(f.SVG,"svg");function F(e){var t=e.matrix,r="";switch(e.type){case 1:r="matrix("+[t.a,t.b,t.c,t.d,t.e,t.f].join(",")+")";break;case 2:r="translate("+t.e+","+t.f+")";break;case 3:r=t.a===t.d?"scale("+t.a+")":"scale("+t.a+","+t.d+")";break;case 4:var n=0,i=0;if(0!==e.angle){var a=1-t.a;i=(a*t.f+t.b*t.e)/(a*a+t.b*t.b),n=(t.e-t.b*i)/a}r="rotate("+e.angle+" "+n+","+i+")"}return r}var D,z={},q=function(){function e(t){n(this,e),this._elem=t||null,this._xforms=[],this._update=function(){for(var e="",t=0;t<this.numberOfItems;++t){e+=F(this._list.getItem(t))+" "}this._elem.setAttribute("transform",e)},this._list=this,this._init=function(){var e=this,t=this._elem.getAttribute("transform");if(t)for(var r=/\s*((scale|matrix|rotate|translate)\s*\(.*?\))\s*,?\s*/,n=!0;n;)n=t.match(r),t=t.replace(r,""),n&&n[1]&&function(){var t=n[1].split(/\s*\(/)
/**
* Adapted from {@link https://github.com/uupaa/dynamic-import-polyfill/blob/master/importModule.js}.
* @module importModule
* @license MIT
*/function Pr(e,t){["id","class","type"].forEach((function(r){r in t&&(e[r]=t[r])}))}function Gr(e,t){return Nr.apply(this,arguments)}function Nr(){return(Nr=r(regeneratorRuntime.mark((function e(t,r){var n,i;return regeneratorRuntime.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:if(n=r.global,i=r.returnDefault,!!("svgEditor"in window&&window.svgEditor&&!1===window.svgEditor.modules)){e.next=4;break}return e.abrupt("return",Tr(t,void 0,{returnDefault:i}));case 4:return e.next=6,Ir(t);case 6:return e.abrupt("return",window[n]);case 7:case"end":return e.stop()}}),e)})))).apply(this,arguments)}function Ir(e){var t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{};return Array.isArray(e)?Promise.all(e.map((function(e){return Ir(e,t)}))):new Promise((function(r,n){var i=document.createElement("script");function a(){n(new Error("Failed to import: ".concat(e))),o()}function s(){r(),o()}var o=function(){i.removeEventListener("error",a),i.removeEventListener("load",s),i.remove(),i.src=""};i.defer="defer",Pr(i,t),i.addEventListener("error",a),i.addEventListener("load",s),i.src=e,document.head.append(i)}))}function Tr(e){var t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{},r=(arguments.length>2&&void 0!==arguments[2]?arguments[2]:{}).returnDefault,n=void 0!==r&&r;return Array.isArray(e)?Promise.all(e.map((function(e){return Tr(e,t)}))):new Promise((function(r,i){var a="$importModule$"+Math.random().toString(32).slice(2),s=document.createElement("script");function o(){i(new Error("Failed to import: ".concat(e))),l()}function u(){r(window[a]),l()}var l=function(){delete window[a],s.removeEventListener("error",o),s.removeEventListener("load",u),s.remove(),URL.revokeObjectURL(s.src),s.src=""};Pr(s,t),s.defer="defer",s.type="module",s.addEventListener("error",o),s.addEventListener("load",u);var h=function(e){var t=document.createElement("a");return t.setAttribute("href",e),t.cloneNode(!1).href}(e),c="import * as m from '".concat(h.replace(/'/g,"\\'"),"'; window.").concat(a," = ").concat(n?"m.default || ":"","m;"),d=new Blob([c],{type:"text/javascript"});s.src=URL.createObjectURL(d),document.head.append(s)}))}var Lr,Vr,Or,Mr,Rr=jQuery,Br=[0,"z","M","m","L","l","C","c","Q","q","A","a","H","h","V","v","S","s","T","t"],Ur=null,Hr=function(e,t,r){for(var n=function(e,t){return ye(e,t,r)},i=function(e){return r.a*e},a=function(e){return r.d*e},s=Ur.getGridSnapping()&&"svg"===e.parentNode.parentNode.localName,o=function(){s&&Object.entries(t).forEach((function(e){var r=h(e,2),n=r[0],i=r[1];t[n]=Yt(i)})),Wt(e,t,1e3,!0)},u=Tt(e),l=0;l<2;l++){var c=0===l?"fill":"stroke",d=e.getAttribute(c);if(d&&d.startsWith("url(")&&(r.a<0||r.d<0)){var m=zt(d).cloneNode(!0);if(r.a<0){var f=m.getAttribute("x1"),g=m.getAttribute("x2");m.setAttribute("x1",-(f-1)),m.setAttribute("x2",-(g-1))}if(r.d<0){var p=m.getAttribute("y1"),y=m.getAttribute("y2");m.setAttribute("y1",-(p-1)),m.setAttribute("y2",-(y-1))}m.id=Ur.getDrawing().getNextId(),Gt().append(m),e.setAttribute(c,"url(#"+m.id+")")}}var v=e.tagName;if("g"===v||"text"===v||"tspan"===v||"use"===v)if(1!==r.a||0!==r.b||0!==r.c||1!==r.d||0===r.e&&0===r.f){var x=Q(e),_=Ur.getSVGRoot().createSVGTransform();_.setMatrix(xe(be(x).matrix,r)),x.clear(),x.appendItem(_)}else{var S=be(e).matrix,b=xe(S.inverse(),r,S);t.x=parseFloat(t.x)+b.e,t.y=parseFloat(t.y)+b.f}switch(v){case"foreignObject":case"rect":case"image":if("image"===v&&(r.a<0||r.d<0)){var w=Q(e),A=Ur.getSVGRoot().createSVGTransform();A.setMatrix(xe(be(w).matrix,r)),w.clear(),w.appendItem(A)}else{var k=n(t.x,t.y);t.width=i(t.width),t.height=a(t.height),t.x=k.x+Math.min(0,t.width),t.y=k.y+Math.min(0,t.height),t.width=Math.abs(t.width),t.height=Math.abs(t.height)}o();break;case"ellipse":var C=n(t.cx,t.cy);t.cx=C.x,t.cy=C.y,t.rx=i(t.rx),t.ry=a(t.ry),t.rx=Math.abs(t.rx),t.ry=Math.abs(t.ry),o();break;case"circle":var E=n(t.cx,t.cy);t.cx=E.x,t.cy=E.y;var P=Se(u.x,u.y,u.width,u.height,r),G=P.tr.x-P.tl.x,N=P.bl.y-P.tl.y;t.r=Math.min(G/2,N/2),t.r&&(t.r=Math.abs(t.r)),o();break;case"line":var I=n(t.x1,t.y1),T=n(t.x2,t.y2);t.x1=I.x,t.y1=I.y,t.x2
//# sourceMappingURL=svgcanvas-iife.min.js.map