svgedit/dist/svgcanvas-iife.min.js

20 lines
188 KiB
JavaScript
Raw Normal View History

2020-07-26 18:11:18 +00:00
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 c(e){var t=function(){if("undefined"==typeof Reflect||!Reflect.construct)return!1;if(Reflect.construct.sham)return!1;if("function"==typeof Proxy)return!0;try{return Date.prototype.toString.call(Reflect.construct(Date,[],(function(){}))),!0}catch(e){return!1}}();return function(){var r,n=o(e);if(t){var i=o(this).constructor;r=Reflect.construct(n,arguments,i)}else r=n.apply(this,arguments);return l(this,r)}}function h(e,t,r){return(h="undefined"!=typeof Reflect&&Reflect.get?Reflect.get:function(e,t,r){var n=function(e,t){for(;!Object.prototype.hasOwnProperty.call(e,t)&&null!==(e=o(e)););return e}(e,t);if(n){var i=Object.getOwnPropertyDescriptor(n,t);return i.get?i.get.call(r):i.value}})(e,t,r||e)}function d(e,t){return function(e){if(Array.isArray(e))return e}(e)||function(e,t){if("undefined"==typeof Symbol||!(Symbol.iterator in Object(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)||f(e,t)||function(){throw new TypeError("Invalid attempt to destructure non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}()}function m(e){return function(e){if(Array.isArray(e))return g(e)}(e)||function(e){if("undefined"!=typeof Symbol&&Symbol.iterator in Object(e))return Array.from(e)}(e)||f(e)||function(){throw new TypeError("Invalid attempt to spread non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}()}function f(e,t){if(e){if("string"==typeof e)return g(e,t);var r=Object.prototype.toString.call(e).slice(8,-1);return"Object"===r&&e.constructor&&(r=e.constructor.name),"Map"===r||"Set"===r?Array.from(e):"Arguments"===r||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(r)?g(e,t):void 0}}function g(e,t){(null==t||t>e.length)&&(t=e.length);for(var r=0,n=new Array(t);r<t;r++)n[r]=e[r];return n}function p(e,t){var r;if("undefined"==typeof Symbol||null==e[Symbol.iterator]){if(Array.isArray(e)||(r=f(e))||t&&e&&"number"==typeof e.length){r&&(e=r);var n=0,i=function(){};return{s:i,n:function(){return n>=e.length?{done:!0}:{done:!1,value:e[n++]}},e:function(e){throw e},f:i}}throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}var a,s=!0,o=!1;return{s:function(){r=e[Symbol.iterator]()},n:function(){var e=r.next();return s=e.do
/**
* A jQuery module to work with SVG attributes.
* @module jQueryAttr
* @license MIT
*/
2020-07-26 18:11:18 +00:00
function y(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 h=s.getAttribute(t);return(h||"0"===h)&&(h=isNaN(h)?h:h-0),h}for(var m=0,f=Object.entries(t);m<f.length;m++){var g=d(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){s(i,t);var r=c(i);function i(t){return n(this,i),r.call(this,e.PATHSEG_CLOSEPATH,"z",t)}return a(i,[{key:"toString",value:function(){return"[object SVGPathSegClosePath]"}},{key:"_asPathString",value:function(){return this.pathSegTypeAsLetter}},{key:"clone",value:function(){return new i(void 0)}}]),i}(e),r=function(t){s(i,t);var r=c(i);function i(t,a,s){var o;return n(this,i),(o=r.call(this,e.PATHSEG_MOVETO_ABS,"M",t))._x=a,o._y=s,o}return a(i,[{key:"toString",value:function(){return"[object SVGPathSegMovetoAbs]"}},{key:"_asPathString",value:function(){return this.pathSegTypeAsLetter+" "+this._x+" "+this._y}},{key:"clone",value:function(){return new i(void 0,this._x,this._y)}}]),i}(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){s(i,t);var r=c(i);function i(t,a,s){var o;return n(this,i),(o=r.call(this,e.PATHSEG_MOVETO_REL,"m",t))._x=a,o._y=s,o}return a(i,[{key:"toString",value:function(){return"[object SVGPathSegMovetoRel]"}},{key:"_asPathString",value:function(){return this.pathSegTypeAsLetter+" "+this._x+" "+this._y}},{key:"clone",value:function(){return new i(void 0,this._x,this._y)}}]),i}(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 o=function(t){s(i,t);var r=c(i);function i(t,a,s){var o;return n(this,i),(o=r.call(this,e.PATHSEG_LINETO_ABS,"L",t))._x=a,o._y=s,o}return a(i,[{key:"toString",value:function(){return"[object SVGPathSegLinetoAbs]"}},{key:"_asPathString",value:function(){return this.pathSegTypeAsLetter+" "+this._x+" "+this._y}},{key:"clone",value:function(){return new i(void 0,this._x,this._y)}}]),i}(e);Object.defineProperties(o.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){s(i,t);var r=c(i);function i(t,a,s){var o;return n(this,i),(o=r.call(this,e.PATHSEG_LINETO_REL,"l",t))._x=a,o._y=s,o}return a(i,[{key:"toString",value:function(){return"[object SVGPathSegLinetoRel]"}},{key:"_asPathString",value:function(){return this.pathSegTypeAsLetter+" "+this._x+" "+this._y}},{key:"clone",value:function(){return new i(void 0,this._x,this._
/**
* Namespaces or tools therefor.
* @module namespaces
* @license MIT
*/
2020-08-04 01:07:09 +00:00
var v,x={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/"},S=function(){var e={};return Object.entries(x).forEach((function(t){var r=d(t,2),n=r[0],i=r[1];e[i]=n.toLowerCase()})),e},_=jQuery,b=(Boolean(document.createElementNS&&document.createElementNS(x.SVG,"svg").createSVGRect),navigator.userAgent),w=document.createElementNS(x.SVG,"svg"),A=Boolean(window.opera),k=b.includes("AppleWebKit"),C=b.includes("Gecko/"),E=b.includes("MSIE"),G=b.includes("Chrome/"),I=(b.includes("Windows"),b.includes("Macintosh"),"ontouchstart"in window),N=Boolean(w.querySelector),P=Boolean(document.evaluate),T=function(){var e=document.createElementNS(x.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}(),L=function(){var e=document.createElementNS(x.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}(),V=function(){var e=document.createElementNS(x.SVG,"svg"),t=document.createElementNS(x.SVG,"svg");document.documentElement.append(e),t.setAttribute("x",5),e.append(t);var r=document.createElementNS(x.SVG,"text");r.textContent="a",t.append(r);try{return 0===r.getStartPositionOfChar(0).x}catch(e){return!1}finally{e.remove()}}(),O=function(){var e=document.createElementNS(x.SVG,"svg");document.documentElement.append(e);var t=document.createElementNS(x.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}(),M=function(){var e=document.createElementNS(x.SVG,"svg");document.documentElement.append(e);var t=document.createElementNS(x.SVG,"path");t.setAttribute("d","M0,0 10,0");var r=document.createElementNS(x.SVG,"path");r.setAttribute("d","M5,0 15,0");var n=document.createElementNS(x.SVG,"g");n.append(t,r),e.append(n);var i=n.getBBox();return e.remove(),15===i.width}(),R=(function(){var e=document.createElementNS(x.SVG,"rect");e.setAttribute("x",.1);var t=!e.cloneNode(!1).getAttribute("x").includes(",");t||_.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.')}(),(v=document.createElementNS(x.SVG,"rect")).setAttribute("style","vector-effect:non-scaling-stroke"),"non-scaling-stroke"===v.style.vectorEffect),B=function(){var t=document.createElementNS(x.SVG,"rect").transform.baseVal,r=w.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}(),U=function(){return k},j=function(){return C},H=function(){return E},F=function(){return G},D=function(){return R},z=document.createElementNS(x.SVG,"svg");function q(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 Q,W={},X=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+=q(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*\(/),r=t[0],i=t[1].match(/\s*(.*?)\s*\)/);i[1]=i[1
/**
* Adapted from {@link https://github.com/uupaa/dynamic-import-polyfill/blob/master/importModule.js}.
* @module importModule
* @license MIT
2020-08-04 01:07:09 +00:00
*/function Vr(e){var t=document.createElement("a");return t.setAttribute("href",e),t.cloneNode(!1).href}function Or(e,t){["id","class","type"].forEach((function(r){r in t&&(e[r]=t[r])}))}function Mr(e,t){return Rr.apply(this,arguments)}function Rr(){return(Rr=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",Ur(t,void 0,{returnDefault:i}));case 4:return e.next=6,Br(t);case 6:return e.abrupt("return",window[n]);case 7:case"end":return e.stop()}}),e)})))).apply(this,arguments)}function Br(e){var t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{};return Array.isArray(e)?Promise.all(e.map((function(e){return Br(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",Or(i,t),i.addEventListener("error",a),i.addEventListener("load",s),i.src=e,document.head.append(i)}))}function Ur(e){var t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{},r=arguments.length>2&&void 0!==arguments[2]?arguments[2]:{},n=r.returnDefault,i=void 0!==n&&n;return Array.isArray(e)?Promise.all(e.map((function(e){return Ur(e,t)}))):new Promise((function(r,n){var a="$importModule$"+Math.random().toString(32).slice(2),s=document.createElement("script");function o(){n(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=""};Or(s,t),s.defer="defer",s.type="module",s.addEventListener("error",o),s.addEventListener("load",u);var c=Vr(e),h="import * as m from '".concat(c.replace(/'/g,"\\'"),"'; window.").concat(a," = ").concat(i?"m.default || ":"","m;"),d=new Blob([h],{type:"text/javascript"});s.src=URL.createObjectURL(d),document.head.append(s)}))}var jr,Hr,Fr,Dr,zr=jQuery,qr=[0,"z","M","m","L","l","C","c","Q","q","A","a","H","h","V","v","S","s","T","t"],Qr=null,Wr=function(e,t,r){for(var n=function(e,t){return se(e,t,r)},i=function(e){return r.a*e},a=function(e){return r.d*e},s=Qr.getGridSnapping()&&"svg"===e.parentNode.parentNode.localName,o=function(){s&&Object.entries(t).forEach((function(e){var r=d(e,2),n=r[0],i=r[1];t[n]=at(i)})),nt(e,t,0,!0)},u=Be(e),l=0;l<2;l++){var c=0===l?"fill":"stroke",h=e.getAttribute(c);if(h&&h.startsWith("url(")&&(r.a<0||r.d<0)){var m=tt(h).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=Qr.getDrawing().getNextId(),Oe().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=Z(e),S=Qr.getSVGRoot().createSVGTransform();S.setMatrix(ue(he(x).matrix,r)),x.clear(),x.appendItem(S)}else{var _=he(e).matrix,b=ue(_.inverse(),r,_);t.x=Number.parseFloat(t.x)+b.e,t.y=Number.parseFloat(t.y)+b.f}switch(v){case"foreignObject":case"rect":case"image":if("image"===v&&(r.a<0||r.d<0)){var w=Z(e),A=Qr.getSVGRoot().createSVGTransform();A.setMatrix(ue(he(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 G=ce(u.x,u.y,u.width,u.height,r),I=G.tr.x-G.tl.x,N=G.bl.y-G.tl.y;t.r=Math.min(I/2,N/2),t.r&&(t.r=Math.abs(t.r)),o();break;case"line":var P=n(t.x1,t.y1),T=n(t.x2,t.y2);
//# sourceMappingURL=svgcanvas-iife.min.js.map