svgedit/dist/index-es.min.js

187 lines
333 KiB
JavaScript
Raw Normal View History

function e(e){const{changedTouches:t}=e,n=t[0];let i="";switch(e.type){case"touchstart":i="mousedown";break;case"touchmove":i="mousemove";break;case"touchend":i="mouseup";break;default:return}const{screenX:s,screenY:o,clientX:r,clientY:a}=n,l=new MouseEvent(i,{bubbles:!0,cancelable:!0,view:window,detail:1,screenX:s,screenY:o,clientX:r,clientY:a,ctrlKey:!1,altKey:!1,shiftKey:!1,metaKey:!1,button:0,relatedTarget:null});t.length<2&&(n.target.dispatchEvent(l),e.preventDefault())}document.addEventListener("touchstart",e,!0),document.addEventListener("touchmove",e,!0),document.addEventListener("touchend",e,!0),document.addEventListener("touchcancel",e,!0);
/**
* Namespaces or tools therefor.
* @module namespaces
* @license MIT
*/
const t={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/"},n=function(){const e={};return Object.entries(t).forEach(([t,n])=>{e[n]=t.toLowerCase()}),e};(()=>{if(!("SVGPathSeg"in window)){class e{constructor(e,t,n){this.pathSegType=e,this.pathSegTypeAsLetter=t,this._owningPathSegList=n}_segmentChanged(){this._owningPathSegList&&this._owningPathSegList.segmentChanged(this)}}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;class t extends e{constructor(t){super(e.PATHSEG_CLOSEPATH,"z",t)}toString(){return"[object SVGPathSegClosePath]"}_asPathString(){return this.pathSegTypeAsLetter}clone(){return new t(void 0)}}class n extends e{constructor(t,n,i){super(e.PATHSEG_MOVETO_ABS,"M",t),this._x=n,this._y=i}toString(){return"[object SVGPathSegMovetoAbs]"}_asPathString(){return this.pathSegTypeAsLetter+" "+this._x+" "+this._y}clone(){return new n(void 0,this._x,this._y)}}Object.defineProperties(n.prototype,{x:{get(){return this._x},set(e){this._x=e,this._segmentChanged()},enumerable:!0},y:{get(){return this._y},set(e){this._y=e,this._segmentChanged()},enumerable:!0}});class i extends e{constructor(t,n,i){super(e.PATHSEG_MOVETO_REL,"m",t),this._x=n,this._y=i}toString(){return"[object SVGPathSegMovetoRel]"}_asPathString(){return this.pathSegTypeAsLetter+" "+this._x+" "+this._y}clone(){return new i(void 0,this._x,this._y)}}Object.defineProperties(i.prototype,{x:{get(){return this._x},set(e){this._x=e,this._segmentChanged()},enumerable:!0},y:{get(){return this._y},set(e){this._y=e,this._segmentChanged()},enumerable:!0}});class s extends e{constructor(t,n,i){super(e.PATHSEG_LINETO_ABS,"L",t),this._x=n,this._y=i}toString(){return"[object SVGPathSegLinetoAbs]"}_asPathString(){return this.pathSegTypeAsLetter+" "+this._x+" "+this._y}clone(){return new s(void 0,this._x,this._y)}}Object.defineProperties(s.prototype,{x:{get(){return this._x},set(e){this._x=e,this._segmentChanged()},enumerable:!0},y:{get(){return this._y},set(e){this._y=e,this._segmentChanged()},enumerable:!0}});class o extends e{constructor(t,n,i){super(e.PATHSEG_LINETO_REL,"l",t),this._x=n,this._y=i}toString(){return"[object SVGPathSegLinetoRel]"}_asPathString(){return this.pathSegTypeAsLetter+" "+this._x+" "+this._y}clone(){return new o(void 0,this._x,this._y)}}Object.defineProperties(o.prototype,{x:{get(){return this._x},set(e){this._x=e,this._segmentChanged()},enumerable:!0},y:{get(){return this._y},set(e){this._y=e,this._segmentChanged()},enumerable:!0}});class r extends e{constructor(t,n,i,s,o,r,a){super(e.PATHSEG_CURVETO_CUBIC_ABS,"C",t),this._x=n,this._y=i,this._x1=s,this._y1=o,this._x2=r,this._y2=a}toString(){return"[object SVGPathSegCurvetoCubicAbs]"}_asPathString(){return this.pathSegTypeAsLetter+" "+this._x1+" "+this._y1+" "+this._x2+" "+this._y2+" "+this._x+" "+this._y}clone(){return new r(void 0,this._x,this._y,this._x1,this._y1,this._x2,this._y2)}}Object.defineProperties(r.prototype,{x:{get(){return this._x},set(e){this._x=e,this._segmentChanged()},enumerable:!0},y:{get(){return this._y},set(e){this._y=e,this._segmentChanged()},enumerable:!0},x1:{get(){return this._x1},set(e){this._x1=e,this._segmentChanged()},enumerable:!0},y1:{get(){return this._y1},set(e){this._y1=e,this._segmentChanged()},enumerable:!0},x2:{get(){return this._x2},set(e){this._x2=e,this._segmentChanged()}
/**
* A jQuery module to work with SVG attributes.
* @module jQueryAttr
* @license MIT
*/
function P(e){const t=e.fn.attr;return e.fn.attr=function(e,n){const i=this.length;if(!i)return t.call(this,e,n);for(let s=0;s<i;++s){const i=this[s];if("http://www.w3.org/2000/svg"!==i.namespaceURI)return t.call(this,e,n);if(void 0!==n)i.setAttribute(e,n);else if(Array.isArray(e)){const t={};let n=e.length;for(;n--;){const s=e[n];let o=i.getAttribute(s);(o||"0"===o)&&(o=isNaN(o)?o:o-0),t[s]=o}return t}if("object"!=typeof e){let t=i.getAttribute(e);return(t||"0"===t)&&(t=isNaN(t)?t:t-0),t}for(const[t,n]of Object.entries(e))i.setAttribute(t,n)}return this},e}
/**
* Partial polyfill of `SVGTransformList`
* @module SVGTransformList
*
* @license MIT
*
* @copyright 2010 Alexis Deveria, 2010 Jeff Schiller
*/const N=document.createElementNS(t.SVG,"svg");function I(e){const t=e.matrix;let n="";switch(e.type){case 1:n="matrix("+[t.a,t.b,t.c,t.d,t.e,t.f].join(",")+")";break;case 2:n="translate("+t.e+","+t.f+")";break;case 3:n=t.a===t.d?"scale("+t.a+")":"scale("+t.a+","+t.d+")";break;case 4:{let i=0,s=0;if(0!==e.angle){const e=1-t.a;s=(e*t.f+t.b*t.e)/(e*e+t.b*t.b),i=(t.e-t.b*s)/e}n="rotate("+e.angle+" "+i+","+s+")";break}}return n}let T={};class L{constructor(e){this._elem=e||null,this._xforms=[],this._update=function(){let e="";for(let t=0;t<this.numberOfItems;++t){e+=I(this._list.getItem(t))+" "}this._elem.setAttribute("transform",e)},this._list=this,this._init=function(){let e=this._elem.getAttribute("transform");if(!e)return;const t=/\s*((scale|matrix|rotate|translate)\s*\(.*?\))\s*,?\s*/;let n=!0;for(;n;)if(n=e.match(t),e=e.replace(t,""),n&&n[1]){const e=n[1].split(/\s*\(/),t=e[0],i=e[1].match(/\s*(.*?)\s*\)/);i[1]=i[1].replace(/(\d)-/g,"$1 -");const s=i[1].split(/[, ]+/),o="abcdef".split(""),r=N.createSVGMatrix();Object.values(s).forEach((function(e,n){s[n]=Number.parseFloat(e),"matrix"===t&&(r[o[n]]=s[n])}));const a=N.createSVGTransform(),l="set"+t.charAt(0).toUpperCase()+t.slice(1),c="matrix"===t?[r]:s;"scale"===t&&1===c.length?c.push(c[0]):"translate"===t&&1===c.length?c.push(0):"rotate"===t&&1===c.length&&c.push(0,0),a[l](...c),this._list.appendItem(a)}},this._removeFromOtherLists=function(e){e&&Object.values(T).some(t=>{for(let n=0,i=t._xforms.length;n<i;++n)if(t._xforms[n]===e)return t.removeItem(n),!0;return!1})},this.numberOfItems=0}clear(){this.numberOfItems=0,this._xforms=[]}initialize(e){this.numberOfItems=1,this._removeFromOtherLists(e),this._xforms=[e]}getItem(e){if(e<this.numberOfItems&&e>=0)return this._xforms[e];const t=new Error("DOMException with code=INDEX_SIZE_ERR");throw t.code=1,t}insertItemBefore(e,t){let n=null;if(t>=0)if(t<this.numberOfItems){this._removeFromOtherLists(e);const i=new Array(this.numberOfItems+1);let s;for(s=0;s<t;++s)i[s]=this._xforms[s];i[s]=e;for(let e=s+1;s<this.numberOfItems;++e,++s)i[e]=this._xforms[s];this.numberOfItems++,this._xforms=i,n=e,this._list._update()}else n=this._list.appendItem(e);return n}replaceItem(e,t){let n=null;return t<this.numberOfItems&&t>=0&&(this._removeFromOtherLists(e),this._xforms[t]=e,n=e,this._list._update()),n}removeItem(e){if(e<this.numberOfItems&&e>=0){const t=this._xforms[e],n=new Array(this.numberOfItems-1);let i;for(i=0;i<e;++i)n[i]=this._xforms[i];for(let e=i;e<this.numberOfItems-1;++e,++i)n[e]=this._xforms[i+1];return this.numberOfItems--,this._xforms=n,this._list._update(),t}const t=new Error("DOMException with code=INDEX_SIZE_ERR");throw t.code=1,t}appendItem(e){return this._removeFromOtherLists(e),this._xforms.push(e),this.numberOfItems++,this._list._update(),e}}let M=function(e){e.id&&T[e.id]&&delete T[e.id]};const O=function(e){if(!x){const t=e.id||"temp";let n=T[t];return n&&"temp"!==t||(T[t]=new L(e),T[t]._init(),n=T[t]),n}return e.transform?e.transform.baseVal:e.gradientTransform?e.gradientTransform.baseVal:e.patternTransform?e.patternTransform.baseVal:null},j=["x","x1","cx","rx","width"],V=["y","y1","cy","ry","height"],R=["r","radius",...j,...V];
/**
* Tools for working with units.
* @module units
* @license MIT
*
* @copyright 2010 Alexis Deveria, 2010 Jeff Schiller
*/let B,U={};const D=function(){return U},F=function(e){const t=B.getRoundDigits();return isNaN(e)?Array.isArray(e)?F(e[0])+","+F(e[1]):Number.parseFloat(e).toFixed(t)-0:Number(Number(e).toFixed(t))},z=function(e,t){return t=t||B.getBaseUnit(),F(e/U[t])},H=function(e,t,n){e.setAttribute(t,n)},q=function(e,t){if(!isNaN(t))return t-0;if("%"===t.substr(-1)){const n=t.substr(0,t.length-1)/100,i=B.getWidth(),s=B.getHeight();return j.includes(e)?n*i:V.includes(e)?n*s:n*Math.sqrt(i*i+s*s)/Math.sqrt(2)}const n=t.substr(-2);return t.substr(0,t.length-2)*U[n]},X=function(e,t,n){if(R.includes(e))return!isNaN(t)||(t=t.toLowerCase(),Object.keys(U).some(e=>new RegExp("^-?[\\d\\.]+"+e+"$").test(t)));if("id"===e){let e=!1;try{const i=B.getElement(t);e=Qe(i)||i===n}catch(e){}return e}return!0},W=document.createElementNS(t.SVG,"svg"),$=function(e,t,n){return{x:n.a*e+n.c*t+n.e,y:n.b*e+n.d*t+n.f}},Y=function(e){return 1===e.a&&0===e.b&&0===e.c&&1===e.d&&0===e.e&&0===e.f},Q=function(...e){const t=e.reduceRight((e,t)=>t.multiply(e));return Math.abs(t.a)<1e-14&&(t.a=0),Math.abs(t.b)<1e-14&&(t.b=0),Math.abs(t.c)<1e-14&&(t.c=0),Math.abs(t.d)<1e-14&&(t.d=0),Math.abs(t.e)<1e-14&&(t.e=0),Math.abs(t.f)<1e-14&&(t.f=0),t},K=function(e){if(!e)return!1;let t=e.numberOfItems;for(;t--;){const n=e.getItem(t);if(1===n.type&&!Y(n.matrix))return!0}return!1},Z=function(e,t,n,i,s){const o=$(e,t,s),r=$(e+n,t,s),a=$(e,t+i,s),l=$(e+n,t+i,s),c=Math.min(o.x,r.x,a.x,l.x),u=Math.max(o.x,r.x,a.x,l.x),d=Math.min(o.y,r.y,a.y,l.y);return{tl:o,tr:r,bl:a,br:l,aabox:{x:c,y:d,width:u-c,height:Math.max(o.y,r.y,a.y,l.y)-d}}},J=function(e,t,n){if(Qe(e))return W.createSVGTransformFromMatrix(W.createSVGMatrix());if(t=t||0,n=n||e.numberOfItems-1,(t=Number.parseInt(t))>(n=Number.parseInt(n))){const e=n;n=t,t=e}let i=W.createSVGMatrix();for(let s=t;s<=n;++s){const t=s>=0&&s<e.numberOfItems?e.getItem(s).matrix:W.createSVGMatrix();i=Q(i,t)}return W.createSVGTransformFromMatrix(i)},ee=function(e){const t=O(e);return J(t).matrix},te=function(e,t,n,i){const s=Math.PI/4,o=n-e,r=i-t,a=Math.atan2(r,o),l=Math.sqrt(o*o+r*r),c=Math.round(a/s)*s;return{x:e+l*Math.cos(c),y:t+l*Math.sin(c),a:c}},ne=function(e,t){return t.x<e.x+e.width&&t.x+t.width>e.x&&t.y<e.y+e.height&&t.y+t.height>e.y},ie=P(jQuery),se="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=",oe="a,circle,ellipse,foreignObject,g,image,line,path,polygon,polyline,rect,svg,text,tspan,use,clipPath".split(",");let re=null,ae=null,le=null,ce=null;const ue=function(e){re=e,ae=e.getDOMDocument(),le=e.getDOMContainer(),ce=e.getSVGRoot()},de=e=>e.replace(/(<!DOCTYPE\s+\w*\s*\[).*(\?]>)/,"$1$2"),he=function(e){return e.replace(/&/g,"&amp;").replace(/</g,"&lt;").replace(/>/g,"&gt;").replace(/"/g,"&quot;").replace(/'/g,"&#x27;")};function pe(e){if(e=me(e),window.btoa)return window.btoa(e);const t=new Array(4*Math.floor((e.length+2)/3));let n=0,i=0;do{const s=e.charCodeAt(n++),o=e.charCodeAt(n++),r=e.charCodeAt(n++),a=s>>2,l=(3&s)<<4|o>>4;let c=(15&o)<<2|r>>6,u=63&r;Number.isNaN(o)?(c=64,u=64):Number.isNaN(r)&&(u=64),t[i++]=se.charAt(a),t[i++]=se.charAt(l),t[i++]=se.charAt(c),t[i++]=se.charAt(u)}while(n<e.length);return t.join("")}function ge(e){if(window.atob)return fe(window.atob(e));e=e.replace(/[^A-Za-z\d+/=]/g,"");let t="",n=0;do{const i=se.indexOf(e.charAt(n++)),s=se.indexOf(e.charAt(n++)),o=se.indexOf(e.charAt(n++)),r=se.indexOf(e.charAt(n++)),a=i<<2|s>>4,l=(15&s)<<4|o>>2,c=(3&o)<<6|r;t+=String.fromCharCode(a),64!==o&&(t+=String.fromCharCode(l)),64!==r&&(t+=String.fromCharCode(c))}while(n<e.length);return fe(t)}function fe(e){return decodeURIComponent(escape(e))}const me=function(e){return unescape(encodeURIComponent(e))},_e=function(e){if("undefined"==typeof Uint8Array||"undefined"==typeof Blob||"undefined"==typeof URL||!URL.createObjectURL)return"";const t=e.split(","),n=t[0].match(/:(.*?);/)[1],i=atob(t[1]);let s=i.length;const o=new Uint8Array(s);for(;s--;)o[s]=i.charCodeAt(s);const r=new Blob([o],{type:n});return URL.createObjectURL(r)},ye=function(e){return e&&"undefined"!=typeof URL&&URL.createObjectURL?URL.createObje
/**
* Adds context menu functionality.
* @module contextmenu
* @license Apache-2.0
* @author Adam Bender
*/const Ze=jQuery;let Je={};const et=function(){Object.values(Je).forEach(e=>{!function(e){Object.keys(Je).length||Ze("#cmenu_canvas").append("<li class='separator'>");const t=e.shortcut||"";Ze("#cmenu_canvas").append("<li class='disabled'><a href='#"+e.id+"'>"+e.label+"<span class='shortcut'>"+t+"</span></a></li>")}(e)})};function tt(){return(tt=Object.assign||function(e){for(var t=1;t<arguments.length;t++){var n=arguments[t];for(var i in n)Object.prototype.hasOwnProperty.call(n,i)&&(e[i]=n[i])}return e}).apply(this,arguments)}
/**
* Adapted from {@link https://github.com/uupaa/dynamic-import-polyfill/blob/master/importModule.js}.
* @module importModule
* @license MIT
*/function nt(e,t){["id","class","type"].forEach(n=>{n in t&&(e[n]=t[n])})}function it(e,t){return st(e,tt({},t,{returnDefault:!0}))}async function st(e,{global:t,returnDefault:n}){return"svgEditor"in window&&window.svgEditor&&!1===window.svgEditor.modules?(await ot(e),window[t]):function e(t,n={},{returnDefault:i=!1}={}){if(Array.isArray(t))return Promise.all(t.map(t=>e(t,n)));return new Promise((e,s)=>{const o="$importModule$"+Math.random().toString(32).slice(2),r=document.createElement("script");function a(){s(new Error("Failed to import: "+t)),c()}function l(){e(window[o]),c()}const c=()=>{delete window[o],r.removeEventListener("error",a),r.removeEventListener("load",l),r.remove(),URL.revokeObjectURL(r.src),r.src=""};nt(r,n),r.defer="defer",r.type="module",r.addEventListener("error",a),r.addEventListener("load",l);const u=`import * as m from '${function(e){const t=document.createElement("a");return t.setAttribute("href",e),t.cloneNode(!1).href}(t).replace(/'/g,"\\'")}'; window.${o} = ${i?"m.default || ":""}m;`,d=new Blob([u],{type:"text/javascript"});r.src=URL.createObjectURL(d),document.head.append(r)})}(e,void 0,{returnDefault:n})}function ot(e,t={}){return Array.isArray(e)?Promise.all(e.map(e=>ot(e,t))):new Promise((n,i)=>{const s=document.createElement("script");function o(){i(new Error("Failed to import: "+e)),a()}function r(){n(),a()}const a=()=>{s.removeEventListener("error",o),s.removeEventListener("load",r),s.remove(),s.src=""};s.defer="defer",nt(s,t),s.addEventListener("error",o),s.addEventListener("load",r),s.src=e,document.head.append(s)})}const rt={true:!0,false:!1,null:null};function at(e,t={ok:"Ok",cancel:"Cancel"}){e("#dialog_container").draggable({cancel:"#dialog_content, #dialog_buttons *",containment:"window"}).css("position","absolute");const n=e("#dialog_box"),i=e("#dialog_buttons"),s=e("#dialog_content");function o(o,r,a,l,c,u){s.html("<p>"+r.replace(/\n/g,"</p><p>")+"</p>").toggleClass("prompt","prompt"===o),i.empty();const d=e('<input type="button" data-ok="" value="'+t.ok+'">').appendTo(i);return new Promise((h,p)=>{let g,f;if("alert"!==o&&e('<input type="button" value="'+t.cancel+'">').appendTo(i).click((function(){n.hide(),h(!1)})),"prompt"===o)g=e('<input type="text">').prependTo(i),g.val(a||""),g.bind("keydown","return",(function(){d.click()}));else if("select"===o){const t=e('<div style="text-align:center;">');if(g=e(`<select aria-label="${r}">`).appendTo(t),u){const n=e("<label>").text(u.label);f=e('<input type="checkbox">').appendTo(n),f.val(u.value),u.tooltip&&n.attr("title",u.tooltip),f.prop("checked",Boolean(u.checked)),t.append(e("<div>").append(n))}e.each(l||[],(function(t,n){"object"==typeof n?g.append(e("<option>").val(n.value).html(n.text)):g.append(e("<option>").html(n))})),s.append(t),a&&g.val(a),c&&g.bind("change","return",c),g.bind("keydown","return",(function(){d.click()}))}else"process"===o&&d.hide();n.show(),d.click((function(){n.hide();const e="prompt"!==o&&"select"!==o||g.val();h(f?{response:e,checked:f.prop("checked")}:e)})).focus(),"prompt"!==o&&"select"!==o||g.focus()})}return e.alert=function(e){return o("alert",e)},e.confirm=function(e){return o("confirm",e)},e.process_cancel=function(e){return o("process",e)},e.prompt=function(e,t=""){return o("prompt",e,t)},e.select=function(e,t,n,i,s){return o("select",e,i,t,n,s)},e}const lt={BEFORE_APPLY:"before_apply",AFTER_APPLY:"after_apply",BEFORE_UNAPPLY:"before_unapply",AFTER_UNAPPLY:"after_unapply"};class ct{getText(){return this.text}apply(e,t){e&&e.handleHistoryEvent(lt.BEFORE_APPLY,this),t(e),e&&e.handleHistoryEvent(lt.AFTER_APPLY,this)}unapply(e,t){e&&e.handleHistoryEvent(lt.BEFORE_UNAPPLY,this),t(),e&&e.handleHistoryEvent(lt.AFTER_UNAPPLY,this)}elements(){return[this.elem]}type(){return this.constructor.name}}class ut extends ct{constructor(e,t,n,i){super(),this.elem=e,this.text=i?"Move "+e.tagName+" to "+i:"Move "+e.tagName,this.oldNextSibling=t,this.oldParent=n,this.newNextSibling=e.nextSibling,this.newParent=e.parentNode}apply(e){super.apply(e,()=>{this.elem=this.newParent.insertBefore(this.elem,this.newNextSi
/**
* HistoryRecordingService component of history.
* @module history
* @license MIT
* @copyright 2016 Flint O'Brien
*/(this.group_),we(this.group_,(function(e){e.setAttribute("style","pointer-events:inherit")})),this.group_.setAttribute("style",i?"pointer-events:all":"pointer-events:none")}getName(){return this.name_}getGroup(){return this.group_}activate(){this.group_.setAttribute("style","pointer-events:all")}deactivate(){this.group_.setAttribute("style","pointer-events:none")}setVisible(e){const t=void 0===e||e?"inline":"none";this.group_.getAttribute("display")!==t&&this.group_.setAttribute("display",t)}isVisible(){return"none"!==this.group_.getAttribute("display")}getOpacity(){const e=this.group_.getAttribute("opacity");return Qe(e)?1:Number.parseFloat(e)}setOpacity(e){"number"==typeof e&&e>=0&&e<=1&&this.group_.setAttribute("opacity",e)}appendChildren(e){for(const t of e)this.group_.append(t)}getTitleElement(){const e=this.group_.childNodes.length;for(let t=0;t<e;++t){const e=this.group_.childNodes.item(t);if(e&&"title"===e.tagName)return e}return null}setName(e,t){const n=this.name_;e=he(e);const i=this.getTitleElement();return i?(on(i).empty(),i.textContent=e,this.name_=e,t&&t.changeElement(i,{"#text":n}),this.name_):null}removeGroup(){const e=this.group_;return this.group_.remove(),this.group_=void 0,e}}rn.CLASS_NAME="layer",rn.CLASS_REGEX=new RegExp("(\\s|^)"+rn.CLASS_NAME+"(\\s|$)");class an{constructor(e){this.undoManager_=e,this.currentBatchCommand_=null,this.batchCommandStack_=[]}startBatchCommand(e){return this.undoManager_?(this.currentBatchCommand_=new gt(e),this.batchCommandStack_.push(this.currentBatchCommand_),this):this}endBatchCommand(){if(!this.undoManager_)return this;if(this.currentBatchCommand_){const e=this.currentBatchCommand_;this.batchCommandStack_.pop();const{length:t}=this.batchCommandStack_;this.currentBatchCommand_=t?this.batchCommandStack_[t-1]:null,this.addCommand_(e)}return this}moveElement(e,t,n,i){return this.undoManager_?(this.addCommand_(new ut(e,t,n,i)),this):this}insertElement(e,t){return this.undoManager_?(this.addCommand_(new dt(e,t)),this):this}removeElement(e,t,n,i){return this.undoManager_?(this.addCommand_(new ht(e,t,n,i)),this):this}changeElement(e,t,n){return this.undoManager_?(this.addCommand_(new pt(e,t,n)),this):this}addCommand_(e){if(!this.undoManager_)return this;this.currentBatchCommand_?this.currentBatchCommand_.addSubCommand(e):this.undoManager_.addCommandToHistory(e)}}an.NO_HISTORY=new an;const ln=P(jQuery),cn=function(e,t){const n=document.createElementNS(e.namespaceURI,e.nodeName);if(ln.each(e.attributes,(function(e,t){"-moz-math-font-style"!==t.localName&&n.setAttributeNS(t.namespaceURI,t.nodeName,t.value)})),n.removeAttribute("id"),n.id=t(),w()&&"path"===e.nodeName){const t=en(e);n.setAttribute("d",t)}if(ln.each(e.childNodes,(function(e,i){switch(i.nodeType){case 1:n.append(cn(i,t));break;case 3:n.textContent=i.nodeValue}})),ln(e).data("gsvg"))ln(n).data("gsvg",n.firstChild);else if(ln(e).data("symbol")){const t=ln(e).data("symbol");ln(n).data("ref",t).data("symbol",t)}else"image"===n.tagName&&Ye(n);return n},un=jQuery,dn="a,circle,ellipse,foreignObject,g,image,line,path,polygon,polyline,rect,svg,text,tspan,use".split(","),hn=1,pn=2;let gn=0,fn=[];function mn(e){return e||new an(xn.undoMgr)}function _n(e){return un("title",e).text()||(r&&e.querySelectorAll?un(e.querySelectorAll("title")).text():"")}function yn(e){let t=1;for(;e.includes("Layer "+t);)t++;return"Layer "+t}class bn{constructor(e,n){if(!e||!e.tagName||!e.namespaceURI||"svg"!==e.tagName||e.namespaceURI!==t.SVG)throw new Error("Error: svgedit.draw.Drawing instance initialized without a <svg> element");this.svgElem_=e,this.obj_num=0,this.idPrefix=n||"svg_",this.releasedNums=[],this.all_layers=[],this.layer_map={},this.current_layer=null,this.nonce_="";const i=this.svgElem_.getAttributeNS(t.SE,"nonce");i&&gn!==pn?this.nonce_=i:gn===hn&&this.setNonce(Math.floor(100001*Math.random()))}getElem_(e){return this.svgElem_.querySelector?this.svgElem_.querySelector("#"+e):un(this.svgElem_).find("[id="+e+"]")[0]}getSvgElem(){return this.svgElem_}getNonce(){return this.nonce_}setNonce(e){this.svgElem_.setAttributeNS(t.XML
/**
* @file SVG Icon Loader 2.0
*
* jQuery Plugin for loading SVG icons from a single file
*
* Adds {@link external:jQuery.svgIcons}, {@link external:jQuery.getSvgIcon}, {@link external:jQuery.resizeSvgIcons}
*
* How to use:
1. Create the SVG master file that includes all icons:
The master SVG icon-containing file is an SVG file that contains
`<g>` elements. Each `<g>` element should contain the markup of an SVG
icon. The `<g>` element has an ID that should
correspond with the ID of the HTML element used on the page that should contain
or optionally be replaced by the icon. Additionally, one empty element should be
added at the end with id "svg_eof".
2. Optionally create fallback raster images for each SVG icon.
3. Include the jQuery and the SVG Icon Loader scripts on your page.
4. Run `$.svgIcons()` when the document is ready. See its signature
5. To access an icon at a later point without using the callback, use this:
`$.getSvgIcon(id (string), uniqueClone (boolean))`;
This will return the icon (as jQuery object) with a given ID.
6. To resize icons at a later point without using the callback, use this:
`$.resizeSvgIcons(resizeOptions)` (use the same way as the "resize" parameter)
*
* @module jQuerySVGIcons
* @license MIT
* @copyright (c) 2009 Alexis Deveria
* {@link http://a.deveria.com}
* @example
$(function () {
$.svgIcons('my_icon_set.svg'); // The SVG file that contains all icons
// No options have been set, so all icons will automatically be inserted
// into HTML elements that match the same IDs.
});
* @example
$(function () {
// The SVG file that contains all icons
$.svgIcons('my_icon_set.svg', {
callback (icons) { // Custom callback function that sets click
// events for each icon
$.each(icons, function (id, icon) {
icon.click(function () {
alert('You clicked on the icon with id ' + id);
});
});
}
});
});
* @example
$(function () {
// The SVGZ file that contains all icons
$.svgIcons('my_icon_set.svgz', {
w: 32, // All icons will be 32px wide
h: 32, // All icons will be 32px high
fallback_path: 'icons/', // All fallback files can be found here
fallback: {
'#open_icon': 'open.png', // The "open.png" will be appended to the
// HTML element with ID "open_icon"
'#close_icon': 'close.png',
'#save_icon': 'save.png'
},
placement: {'.open_icon': 'open'}, // The "open" icon will be added
// to all elements with class "open_icon"
resize: {
'#save_icon .svg_icon': 64 // The "save" icon will be resized to 64 x 64px
},
callback (icons) { // Sets background color for "close" icon
icons.close.css('background', 'red');
},
svgz: true // Indicates that an SVGZ file is being used
});
});
*/
const ci=Boolean(window.opera),ui=function(e,t,n){const i=e.find("defs");if(!i.length)return e;let s;s=ci?i.find("*").filter((function(){return Boolean(this.id)})):i.find("[id]");const o=e[0].getElementsByTagName("*"),r=o.length;return s.each((function(e){const{id:n}=this,i="x"+n+t+e;this.id=i;const s="url(#"+n+")",a="url(#"+i+")";for(e=0;e<r;e++){const t=o[e];t.getAttribute("fill")===s&&t.setAttribute("fill",a),t.getAttribute("stroke")===s&&t.setAttribute("stroke",a),t.getAttribute("filter")===s&&t.setAttribute("filter",a)}})),e};
/**
* @file jGraduate 0.4
*
* jQuery Plugin for a gradient picker
*
* @module jGraduate
* @copyright 2010 Jeff Schiller {@link http://blog.codedread.com/}, 2010 Alexis Deveria {@link http://a.deveria.com/}
*
* @license Apache-2.0
* @example
* // The Paint object is described below.
* $.jGraduate.Paint(); // constructs a 'none' color
* @example $.jGraduate.Paint({copy: o}); // creates a copy of the paint o
* @example $.jGraduate.Paint({hex: '#rrggbb'}); // creates a solid color paint with hex = "#rrggbb"
* @example $.jGraduate.Paint({linearGradient: o, a: 50}); // creates a linear gradient paint with opacity=0.5
* @example $.jGraduate.Paint({radialGradient: o, a: 7}); // creates a radial gradient paint with opacity=0.07
* @example $.jGraduate.Paint({hex: '#rrggbb', linearGradient: o}); // throws an exception?
*/
const di="http://www.w3.org/2000/svg",hi="http://www.w3.org/1999/xlink";
/**
* @file jPicker (Adapted from version 1.1.6)
*
* jQuery Plugin for Photoshop style color picker
*
* @module jPicker
* @copyright (c) 2010 Christopher T. Tillman
* Digital Magic Productions, Inc. ({@link http://www.digitalmagicpro.com/})
* FREE to use, alter, copy, sell, and especially ENHANCE
* @license MIT
*
* Painstakingly ported from John Dyers' excellent work on his own color picker based on the Prototype framework.
*
* John Dyers' website: {@link http://johndyer.name}
* Color Picker page: {@link http://johndyer.name/photoshop-like-javascript-color-picker/}
*/
function pi(e,t){return void 0===t&&(t=0),Math.round(e*10**t)/10**t}window.console||(window.console={log(e){},dir(e){}});const gi=e=>null==e,fi=jQuery;let mi;const _i=function(e,t,n){const i=fi("#svg_editor").parent();Object.entries(t).forEach(([t,s])=>{if(!s)return void console.log(t);n&&(t="#"+t);const o=i.find(t);if(o.length){const t=o[0];switch(e){case"aria-label":t.setAttribute("aria-label",s);break;case"content":[...t.childNodes].some(e=>!(3!==e.nodeType||!e.textContent.trim())&&(e.textContent=s,!0));break;case"title":t.title=s}}else console.log("Missing element for localization: "+t)})};let yi;const bi=async function(e){const t=await yi.addLangData(mi);if(fi.each(t,(function(t,n){n.data&&(e=fi.merge(e,n.data))})),!e.tools)return;const{tools:n,properties:i,config:s,layers:o,common:r,ui:a}=e;_i("content",{curve_segments:i.curve_segments,fitToContent:n.fitToContent,fit_to_all:n.fit_to_all,fit_to_canvas:n.fit_to_canvas,fit_to_layer_content:n.fit_to_layer_content,fit_to_sel:n.fit_to_sel,icon_large:s.icon_large,icon_medium:s.icon_medium,icon_small:s.icon_small,icon_xlarge:s.icon_xlarge,image_opt_embed:s.image_opt_embed,image_opt_ref:s.image_opt_ref,includedImages:s.included_images,largest_object:n.largest_object,layersLabel:o.layers,page:n.page,relativeToLabel:n.relativeTo,selLayerLabel:o.move_elems_to,selectedPredefined:s.select_predefined,selected_objects:n.selected_objects,smallest_object:n.smallest_object,straight_segments:i.straight_segments,svginfo_bg_url:s.editor_img_url+":",svginfo_bg_note:s.editor_bg_note,svginfo_change_background:s.background,svginfo_dim:s.doc_dims,svginfo_editor_prefs:s.editor_prefs,svginfo_height:r.height,svginfo_icons:s.icon_size,svginfo_image_props:s.image_props,svginfo_lang:s.language,svginfo_title:s.doc_title,svginfo_width:r.width,tool_docprops_cancel:r.cancel,tool_docprops_save:r.ok,tool_source_cancel:r.cancel,tool_source_save:r.ok,tool_prefs_cancel:r.cancel,tool_prefs_save:r.ok,sidepanel_handle:o.layers.split("").join(" "),tool_clear:n.new_doc,tool_docprops:n.docprops,tool_export:n.export_img,tool_import:n.import_doc,tool_open:n.open_doc,tool_save:n.save_doc,tool_editor_prefs:s.editor_prefs,tool_editor_homepage:n.editor_homepage,svginfo_units_rulers:s.units_and_rulers,svginfo_rulers_onoff:s.show_rulers,svginfo_unit:s.base_unit,svginfo_grid_settings:s.grid,svginfo_snap_onoff:s.snapping_onoff,svginfo_snap_step:s.snapping_stepsize,svginfo_grid_color:s.grid_color},!0);const l={};["cut","copy","paste","paste_in_place","delete","group","ungroup","move_front","move_up","move_down","move_back"].forEach(e=>{l['#cmenu_canvas a[href="#'+e+'"]']=n[e]}),["dupe","merge_down","merge_all"].forEach(e=>{l['#cmenu_layers a[href="#'+e+'"]']=o[e]}),l['#cmenu_layers a[href="#delete"]']=o.del,_i("content",l);const c={};return Object.entries({tool_blur:i.blur,tool_position:n.align_to_page,tool_font_family:i.font_family,zoom_panel:a.zoom_level,stroke_linejoin:i.linejoin_miter,stroke_linecap:i.linecap_butt,tool_opacity:i.opacity}).forEach(([e,t])=>{c["#"+e+" button"]=t}),Object.entries({group_opacity:i.opacity,zoom:a.zoom_level}).forEach(([e,t])=>{c["#"+e]=t}),_i("aria-label",c),_i("title",{align_relative_to:n.align_relative_to,circle_cx:i.circle_cx,circle_cy:i.circle_cy,circle_r:i.circle_r,cornerRadiusLabel:i.corner_radius,ellipse_cx:i.ellipse_cx,ellipse_cy:i.ellipse_cy,ellipse_rx:i.ellipse_rx,ellipse_ry:i.ellipse_ry,fill_color:i.fill_color,font_family:i.font_family,idLabel:i.id,image_height:i.image_height,image_url:i.image_url,image_width:i.image_width,layer_delete:o.del,layer_down:o.move_down,layer_new:o.new,layer_rename:o.rename,layer_moreopts:r.more_opts,layer_up:o.move_up,line_x1:i.line_x1,line_x2:i.line_x2,line_y1:i.line_y1,line_y2:i.line_y2,linecap_butt:i.linecap_butt,linecap_round:i.linecap_round,linecap_square:i.linecap_square,linejoin_bevel:i.linejoin_bevel,linejoin_miter:i.linejoin_miter,linejoin_round:i.linejoin_round,main_icon:n.main_menu,palette:a.palette_info,zoom_panel:a.zoom_level,path_node_x:i.node_x,path_node_y:i.node_y,rect_height_tool:i.rect_height,rect_width_tool:i.rect_width,seg_type:i.
/**
* @file jQuery Context Menu Plugin
* Cory S.N. LaViska
* A Beautiful Site ({@link https://abeautifulsite.net/})
* Modified by Alexis Deveria
*
* More info: {@link https://abeautifulsite.net/2008/09/jquery-context-menu-plugin/}
*
* @module jQueryContextMenu
* @todo Update to latest version and adapt (and needs jQuery update as well): {@link https://github.com/swisnl/jQuery-contextMenu}
* @version 1.0.1
*
* @license (MIT OR GPL-2.0-or-later)
*
* This plugin is dual-licensed under the GNU General Public License
* and the MIT License and is copyright A Beautiful Site, LLC.
*
*/,P,function(e){const t=e(window),n=e(document);return e.extend(e.fn,{contextMenu(i,s){return void 0!==i.menu&&(void 0===i.inSpeed&&(i.inSpeed=150),void 0===i.outSpeed&&(i.outSpeed=75),0===i.inSpeed&&(i.inSpeed=-1),0===i.outSpeed&&(i.outSpeed=-1),e(this).each((function(){const o=e(this),r=e(o).offset(),a=e("#"+i.menu);a.addClass("contextMenu"),e(this).bind("mousedown",(function(l){e(this).mouseup((function(c){const u=e(this);if(u.unbind("mouseup"),!(2===l.button||i.allowLeft||l.ctrlKey&&A()))return;if(c.stopPropagation(),e(".contextMenu").hide(),o.hasClass("disabled"))return!1;let d=c.pageX,h=c.pageY;const p=t.width()-a.width(),g=t.height()-a.height();d>p-15&&(d=p-15),h>g-30&&(h=g-30),n.unbind("click"),a.css({top:h,left:d}).fadeIn(i.inSpeed),a.find("A").mouseover((function(){a.find("LI.hover").removeClass("hover"),e(this).parent().addClass("hover")})).mouseout((function(){a.find("LI.hover").removeClass("hover")})),n.keypress((function(e){switch(e.keyCode){case 38:a.find("LI.hover").length?(a.find("LI.hover").removeClass("hover").prevAll("LI:not(.disabled)").eq(0).addClass("hover"),a.find("LI.hover").length||a.find("LI:last").addClass("hover")):a.find("LI:last").addClass("hover");break;case 40:a.find("LI.hover").length?(a.find("LI.hover").removeClass("hover").nextAll("LI:not(.disabled)").eq(0).addClass("hover"),a.find("LI.hover").length||a.find("LI:first").addClass("hover")):a.find("LI:first").addClass("hover");break;case 13:a.find("LI.hover A").trigger("click");break;case 27:n.trigger("click")}})),a.find("A").unbind("mouseup"),a.find("LI:not(.disabled) A").mouseup((function(){return n.unbind("click").unbind("keypress"),e(".contextMenu").hide(),s&&s(e(this).attr("href").substr(1),e(u),{x:d-r.left,y:h-r.top,docX:d,docY:h}),!1})),setTimeout((function(){n.click((function(){return n.unbind("click").unbind("keypress"),a.fadeOut(i.outSpeed),!1}))}),0)}))})),e.browser.mozilla?e("#"+i.menu).each((function(){e(this).css({MozUserSelect:"none"})})):e.browser.msie?e("#"+i.menu).each((function(){e(this).bind("selectstart.disableTextSelect",(function(){return!1}))})):e("#"+i.menu).each((function(){e(this).bind("mousedown.disableTextSelect",(function(){return!1}))})),e(o).add(e("UL.contextMenu")).bind("contextmenu",(function(){return!1}))})),e(this))},disableContextMenuItems(t){return void 0===t?(e(this).find("LI").addClass("disabled"),e(this)):(e(this).each((function(){if(void 0!==t){const n=t.split(",");for(const t of n)e(this).find('A[href="'+t+'"]').parent().addClass("disabled")}})),e(this))},enableContextMenuItems(t){return void 0===t?(e(this).find("LI.disabled").removeClass("disabled"),e(this)):(e(this).each((function(){if(void 0!==t){const n=t.split(",");for(const t of n)e(this).find('A[href="'+t+'"]').parent().removeClass("disabled")}})),e(this))},disableContextMenu(){return e(this).each((function(){e(this).addClass("disabled")})),e(this)},enableContextMenu(){return e(this).each((function(){e(this).removeClass("disabled")})),e(this)},destroyContextMenu(){return e(this).each((function(){e(this).unbind("mousedown").unbind("mouseup")})),e(this)}}),e},function(e){e.loadingStylesheets||(e.loadingStylesheets=[]);e.loadingStylesheets.includes("jgraduate/css/jPicker.css")||e.loadingStylesheets.push("jgraduate/css/jPicker.css");class t{constructor(t,n){const i=this;function s(e){w.forEach(t=>{t.call(i,i,e)})}function o(n){const s=t.offset();d={l:0|s.left,t:0|s.top},clearTimeout(h),h=setTimeout((function(){l.call(i,n)}),0),e(document).bind("mousemove",r).bind("mouseup",a),n.preventDefault()}function r(e){return clearTimeout(h),h=setTimeout((function(){l.call(i,e)}),0),e.stopPropagation(),e.preventDefault(),!1}function a(t){return e(document).unbind("mouseup",a).unbind("mousemove",r),t.stopPropagation(),t.preventDefault(),!1}function l(e){const n=t.w,s=t.h;let o=e.pageX-d.l,r=e.pageY-d.t;o<0?o=0:o>n&&(o=n),r<0?r=0:r>s&&(r=s),c.call(i,"xy",{x:o/n*_+f,y:r/s*v+y})}function c(e,t,n){if(!(void 0!==t))switch(gi(e)&&(e="xy"),e.toLowerCase()){case"x":return p;case"y":return g;case"xy":default:return{x:p,y:g}}if(!gi(n)&&n===i)return;let o,r,a=!1;
- Breaking change: Rename config file to `svgedit-config-iife.js` (or for the module version, `svgedit-config-es.js`); also expect one directory higher; incorporates #207 (@iuyiuy) - Breaking change: Separate `extIconsPath` from `extPath` (not copying over icons) - Breaking change: Don't reference `custom.css` in HTML; can instead be referenced in JavaScript through the config file (provided in `svgedit-config-sample-iife.js`/`svgedit-config-sample-es.js` as `svgedit-custom.css` for better namespacing); incorporates #207 (@iuyiuy) - Breaking change: Remove minified jgraduate/spinbtn files (minified within Rollup routine) - Fix: Zoom when scrolled; incorporates #169 (@AndrolGenhald), adapting for conventions; also allow avoidance when shift key pressed - Fix: Update Atom feed reference in HTML - Fixes related to recent commits: Some path and method name fixes needed, function order, missing methods, variable scope declaration, no need for DOMContentLoaded listeners in modules, switch back to non-default export, avoid trimming nullish, deal with mock tests, fix `math.matrixMultiply`, use jquery-svg where needed for array/SVG attributes; add babel-polyfill and defer script to imagelib; other misc. fixes - Enhancement: Move config-sample.js out of `editor` directory - Enhancement: For `callback`-style extensions, also provide config object; add following to that object: buildCanvgCallback, canvg, decode64, encode64, executeAfterLoads, getTypeMap, isChrome, ieIE, NS, text2xml - Enhancement: Complete ES6 modules work (extensions, locales, tests), along with Babel; make Node build routine for converting modular source to non-modular, use `loadStylesheets` for modular stylehsheet defining (but parallel loading); - Enhancement: Add `stylesheets` config for modular but parallel stylesheet loading with `@default` option for simple inclusion/exclusion of defaults (if not going with default). - Refactoring: Clean up `svg-editor.html`: consistent indents; avoid extra lbs, avoid long lines - Refactoring: Avoid embedded API adding inline JavaScript listener - Refactoring: Move layers and context code to `draw.js` - Refactoring: Move `pathActions` from `svgcanvas.js` (though preserve aliases to these methods on `canvas`) and `convertPath` from `svgutils.js` to `path.js` - Refactoring: Move `getStrokedBBox` from `svgcanvas.js` (while keeping an alias) to `svgutils.js` (as `getStrokedBBoxDefaultVisible` to avoid conflict with existing) - Docs: Remove "dependencies" comments in code except where summarizing role of jQuery or a non-obvious dependency - Refactoring/Linting: Enfore `no-extra-semi` and `quote-props` rules - Refactoring: Further avoidance of quotes on properties (as possible) - Refactoring: Use `class` in place of functions where intended as classes - Refactoring: Consistency and granularity in extensions imports - Testing: Update QUnit to 2.6.1 (node_modules) and Sinon to 5.0.8 (and add sinon-test at 2.1.3) and enforce eslint-plugin-qunit linting rules; update custom extensions - Testing: Add node-static for automating (and accessing out-of-directory contents) - Testing: Avoid HTML attributes for styling - Testing: Add npm `test` script - Testing: Comment out unused jQuery SVG test - Testing: Add test1 and svgutils_performance_test to all tests page - Testing: Due apparently to Path having not been a formal class, the test was calling it without `new`; refactored now with sufficient mock data to take into account it is a class - npm: Update devDeps - npm: Add html modules and config build to test script
2018-05-22 10:03:16 +00:00
//# sourceMappingURL=index-es.min.js.map