@hprint/core 0.0.11-alpha.5 → 0.0.11-alpha.7
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/ServersPlugin.d.ts +2 -0
- package/dist/ServersPlugin.d.ts.map +1 -1
- package/dist/index.js +1 -1
- package/dist/index.mjs +99 -68
- package/package.json +2 -2
- package/src/ServersPlugin.ts +126 -83
package/dist/ServersPlugin.d.ts
CHANGED
|
@@ -54,8 +54,10 @@ declare class ServersPlugin implements IPluginTempl {
|
|
|
54
54
|
saveJson(): Promise<void>;
|
|
55
55
|
saveSvg(): void;
|
|
56
56
|
saveImg(): void;
|
|
57
|
+
private exportBase64;
|
|
57
58
|
getBase64(options?: PrintExportOptions): Promise<string>;
|
|
58
59
|
getBase64Result(options?: PrintExportOptions): Promise<PrintExportResult>;
|
|
60
|
+
private exportSVG;
|
|
59
61
|
getSVG(options?: PrintSVGExportOptions): Promise<string>;
|
|
60
62
|
getSVGResult(options?: PrintSVGExportOptions): Promise<PrintExportResult>;
|
|
61
63
|
preview(): Promise<string>;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ServersPlugin.d.ts","sourceRoot":"","sources":["../src/ServersPlugin.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,MAAM,EAAE,MAAM,QAAQ,CAAC;AAChC,OAAO,KAAK,EAAE,OAAO,EAAE,YAAY,EAAE,MAAM,cAAc,CAAC;AAC1D,OAAO,EAAE,WAAW,EAAE,UAAU,EAAE,MAAM,mCAAmC,CAAC;AAE5E,MAAM,MAAM,aAAa,GAAG,CAAC,GAAG,EAAE,GAAG,GAAG,GAAG,GAAG,CAAC;AAE/C,MAAM,WAAW,kBAAkB;IAC/B,QAAQ,CAAC,EAAE,aAAa,GAAG,MAAM,CAAC;CACrC;AAED,MAAM,WAAW,qBAAsB,SAAQ,kBAAkB;IAC7D,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,MAAM,CAAC,EAAE,MAAM,CAAC;CACnB;AAED,MAAM,WAAW,iBAAiB;IAC9B,OAAO,EAAE,MAAM,CAAC;IAChB,KAAK,EAAE,MAAM,CAAC;IACd,MAAM,EAAE,MAAM,CAAC;IACf,QAAQ,EAAE,aAAa,CAAC;CAC3B;AAED,KAAK,OAAO,GAAG,IAAI,CACf,aAAa,EACX,QAAQ,GACR,UAAU,GACV,SAAS,GACT,aAAa,GACb,WAAW,GACX,iBAAiB,GACjB,UAAU,GACV,SAAS,GACT,WAAW,GACX,iBAAiB,GACjB,QAAQ,GACR,cAAc,GACd,SAAS,GACT,OAAO,GACP,SAAS,GACT,eAAe,GACf,eAAe,GACf,iBAAiB,CACtB,CAAC;AAEF,OAAO,QAAQ,cAAc,CAAC;IAE1B,UAAU,OAAQ,SAAQ,OAAO;KAAG;CACvC;AAaD,cAAM,aAAc,YAAW,YAAY;IA0B5B,MAAM,EAAE,MAAM,CAAC,MAAM;IACrB,MAAM,EAAE,OAAO;IA1BnB,YAAY,EAAE,UAAU,CAAC;IAChC,MAAM,CAAC,UAAU,SAAmB;IACpC,MAAM,CAAC,IAAI,WAmBT;IACF,MAAM,CAAC,MAAM,+BAA0D;gBAG5D,MAAM,EAAE,MAAM,CAAC,MAAM,EACrB,MAAM,EAAE,OAAO;IAM1B,OAAO,CAAC,gBAAgB;IAMxB,OAAO,CAAC,gBAAgB;IAmBxB,aAAa;IAIb,MAAM,CAAC,QAAQ,CAAC,EAAE,MAAM,IAAI;IAc5B,eAAe,CAAC,SAAS,EAAE,MAAM,CAAC,IAAI,GAAG,MAAM,EAAE,GAAG,CAAC,EAAE;IAajD,QAAQ,CAAC,QAAQ,EAAE,MAAM,GAAG,MAAM,EAAE,QAAQ,CAAC,EAAE,MAAM,IAAI;IAuDzD,UAAU,CAAC,IAAI,EAAE,GAAG;IAW1B,gBAAgB,CAAC,IAAI,EAAE,GAAG;IAQ1B,OAAO,CAAC,OAAO,CAAC,EAAE;QAAE,QAAQ,CAAC,EAAE,OAAO,CAAA;KAAE;;;;IAiBxC,eAAe;IAmBf;;;;OAIG;IACH,WAAW,CAAC,IAAI,EAAE,MAAM,CAAC,MAAM,EAAE,KAAK,CAAC,EAAE,SAAS;IAyBlD,SAAS;IAKH,eAAe;IAKf,QAAQ;IAUd,OAAO;IAcP,OAAO;IAWP,SAAS,CAAC,OAAO,CAAC,EAAE,kBAAkB;
|
|
1
|
+
{"version":3,"file":"ServersPlugin.d.ts","sourceRoot":"","sources":["../src/ServersPlugin.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,MAAM,EAAE,MAAM,QAAQ,CAAC;AAChC,OAAO,KAAK,EAAE,OAAO,EAAE,YAAY,EAAE,MAAM,cAAc,CAAC;AAC1D,OAAO,EAAE,WAAW,EAAE,UAAU,EAAE,MAAM,mCAAmC,CAAC;AAE5E,MAAM,MAAM,aAAa,GAAG,CAAC,GAAG,EAAE,GAAG,GAAG,GAAG,GAAG,CAAC;AAE/C,MAAM,WAAW,kBAAkB;IAC/B,QAAQ,CAAC,EAAE,aAAa,GAAG,MAAM,CAAC;CACrC;AAED,MAAM,WAAW,qBAAsB,SAAQ,kBAAkB;IAC7D,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,MAAM,CAAC,EAAE,MAAM,CAAC;CACnB;AAED,MAAM,WAAW,iBAAiB;IAC9B,OAAO,EAAE,MAAM,CAAC;IAChB,KAAK,EAAE,MAAM,CAAC;IACd,MAAM,EAAE,MAAM,CAAC;IACf,QAAQ,EAAE,aAAa,CAAC;CAC3B;AAED,KAAK,OAAO,GAAG,IAAI,CACf,aAAa,EACX,QAAQ,GACR,UAAU,GACV,SAAS,GACT,aAAa,GACb,WAAW,GACX,iBAAiB,GACjB,UAAU,GACV,SAAS,GACT,WAAW,GACX,iBAAiB,GACjB,QAAQ,GACR,cAAc,GACd,SAAS,GACT,OAAO,GACP,SAAS,GACT,eAAe,GACf,eAAe,GACf,iBAAiB,CACtB,CAAC;AAEF,OAAO,QAAQ,cAAc,CAAC;IAE1B,UAAU,OAAQ,SAAQ,OAAO;KAAG;CACvC;AAaD,cAAM,aAAc,YAAW,YAAY;IA0B5B,MAAM,EAAE,MAAM,CAAC,MAAM;IACrB,MAAM,EAAE,OAAO;IA1BnB,YAAY,EAAE,UAAU,CAAC;IAChC,MAAM,CAAC,UAAU,SAAmB;IACpC,MAAM,CAAC,IAAI,WAmBT;IACF,MAAM,CAAC,MAAM,+BAA0D;gBAG5D,MAAM,EAAE,MAAM,CAAC,MAAM,EACrB,MAAM,EAAE,OAAO;IAM1B,OAAO,CAAC,gBAAgB;IAMxB,OAAO,CAAC,gBAAgB;IAmBxB,aAAa;IAIb,MAAM,CAAC,QAAQ,CAAC,EAAE,MAAM,IAAI;IAc5B,eAAe,CAAC,SAAS,EAAE,MAAM,CAAC,IAAI,GAAG,MAAM,EAAE,GAAG,CAAC,EAAE;IAajD,QAAQ,CAAC,QAAQ,EAAE,MAAM,GAAG,MAAM,EAAE,QAAQ,CAAC,EAAE,MAAM,IAAI;IAuDzD,UAAU,CAAC,IAAI,EAAE,GAAG;IAW1B,gBAAgB,CAAC,IAAI,EAAE,GAAG;IAQ1B,OAAO,CAAC,OAAO,CAAC,EAAE;QAAE,QAAQ,CAAC,EAAE,OAAO,CAAA;KAAE;;;;IAiBxC,eAAe;IAmBf;;;;OAIG;IACH,WAAW,CAAC,IAAI,EAAE,MAAM,CAAC,MAAM,EAAE,KAAK,CAAC,EAAE,SAAS;IAyBlD,SAAS;IAKH,eAAe;IAKf,QAAQ;IAUd,OAAO;IAcP,OAAO;IAWP,OAAO,CAAC,YAAY;IAsCpB,SAAS,CAAC,OAAO,CAAC,EAAE,kBAAkB;IAIhC,eAAe,CACjB,OAAO,CAAC,EAAE,kBAAkB,GAC7B,OAAO,CAAC,iBAAiB,CAAC;IAI7B,OAAO,CAAC,SAAS;IA+CjB,MAAM,CAAC,OAAO,CAAC,EAAE,qBAAqB;IAIhC,YAAY,CACd,OAAO,CAAC,EAAE,qBAAqB,GAChC,OAAO,CAAC,iBAAiB,CAAC;IAI7B,OAAO;IAcP,aAAa;IAIb,iBAAiB,CAAC,OAAO,CAAC,EAAE;QACxB,UAAU,CAAC,EAAE,OAAO,CAAC;QACrB,KAAK,CAAC,EAAE,MAAM,CAAC;QACf,MAAM,CAAC,EAAE,MAAM,CAAC;KACnB;;;;;;;;;;;;;IAqCD,cAAc;;;;;;;;;;IAkBd,OAAO,CAAC,sBAAsB;IAM9B,OAAO,CAAC,kBAAkB;IAsB1B,OAAO,CAAC,YAAY;IAyCpB,OAAO,CAAC,SAAS;IAyDjB,KAAK;IAWL,OAAO;CAGV;AAED,eAAe,aAAa,CAAC"}
|
package/dist/index.js
CHANGED
|
@@ -438,7 +438,7 @@ gl_FragColor.rgb *= color.a;
|
|
|
438
438
|
`?(i++,n[i]=0):n[i]++;n[0]>0&&(this.insertCharStyleObject(t.lineIndex,t.charIndex,n[0],a),a=a&&a.slice(n[0]+1)),i&&this.insertNewlineStyleObject(t.lineIndex,t.charIndex+n[0],i);for(var o=1;o<i;o++)n[o]>0?this.insertCharStyleObject(t.lineIndex+o,0,n[o],a):a&&this.styles[t.lineIndex+o]&&a[0]&&(this.styles[t.lineIndex+o][0]=a[0]),a=a&&a.slice(n[o]+1);n[o]>0&&this.insertCharStyleObject(t.lineIndex+o,0,n[o],a)},setSelectionStartEndWithShift:function(e,l,a){a<=e?(l===e?this._selectionDirection="left":this._selectionDirection==="right"&&(this._selectionDirection="left",this.selectionEnd=e),this.selectionStart=a):a>e&&a<l?this._selectionDirection==="right"?this.selectionEnd=a:this.selectionStart=a:(l===e?this._selectionDirection="right":this._selectionDirection==="left"&&(this._selectionDirection="right",this.selectionStart=l),this.selectionEnd=a)},setSelectionInBoundaries:function(){var e=this.text.length;this.selectionStart>e?this.selectionStart=e:this.selectionStart<0&&(this.selectionStart=0),this.selectionEnd>e?this.selectionEnd=e:this.selectionEnd<0&&(this.selectionEnd=0)}})})(),r.util.object.extend(r.IText.prototype,{initDoubleClickSimulation:function(){this.__lastClickTime=+new Date,this.__lastLastClickTime=+new Date,this.__lastPointer={},this.on("mousedown",this.onMouseDown)},onMouseDown:function(h){if(this.canvas){this.__newClickTime=+new Date;var e=h.pointer;this.isTripleClick(e)&&(this.fire("tripleclick",h),this._stopEvent(h.e)),this.__lastLastClickTime=this.__lastClickTime,this.__lastClickTime=this.__newClickTime,this.__lastPointer=e,this.__lastIsEditing=this.isEditing,this.__lastSelected=this.selected}},isTripleClick:function(h){return this.__newClickTime-this.__lastClickTime<500&&this.__lastClickTime-this.__lastLastClickTime<500&&this.__lastPointer.x===h.x&&this.__lastPointer.y===h.y},_stopEvent:function(h){h.preventDefault&&h.preventDefault(),h.stopPropagation&&h.stopPropagation()},initCursorSelectionHandlers:function(){this.initMousedownHandler(),this.initMouseupHandler(),this.initClicks()},doubleClickHandler:function(h){this.isEditing&&this.selectWord(this.getSelectionStartFromPointer(h.e))},tripleClickHandler:function(h){this.isEditing&&this.selectLine(this.getSelectionStartFromPointer(h.e))},initClicks:function(){this.on("mousedblclick",this.doubleClickHandler),this.on("tripleclick",this.tripleClickHandler)},_mouseDownHandler:function(h){!this.canvas||!this.editable||h.e.button&&h.e.button!==1||(this.__isMousedown=!0,this.selected&&(this.inCompositionMode=!1,this.setCursorByClick(h.e)),this.isEditing&&(this.__selectionStartOnMouseDown=this.selectionStart,this.selectionStart===this.selectionEnd&&this.abortCursorAnimation(),this.renderCursorOrSelection()))},_mouseDownHandlerBefore:function(h){!this.canvas||!this.editable||h.e.button&&h.e.button!==1||(this.selected=this===this.canvas._activeObject)},initMousedownHandler:function(){this.on("mousedown",this._mouseDownHandler),this.on("mousedown:before",this._mouseDownHandlerBefore)},initMouseupHandler:function(){this.on("mouseup",this.mouseUpHandler)},mouseUpHandler:function(h){if(this.__isMousedown=!1,!(!this.editable||this.group||h.transform&&h.transform.actionPerformed||h.e.button&&h.e.button!==1)){if(this.canvas){var e=this.canvas._activeObject;if(e&&e!==this)return}this.__lastSelected&&!this.__corner?(this.selected=!1,this.__lastSelected=!1,this.enterEditing(h.e),this.selectionStart===this.selectionEnd?this.initDelayedCursor(!0):this.renderCursorOrSelection()):this.selected=!0}},setCursorByClick:function(h){var e=this.getSelectionStartFromPointer(h),l=this.selectionStart,a=this.selectionEnd;h.shiftKey?this.setSelectionStartEndWithShift(l,a,e):(this.selectionStart=e,this.selectionEnd=e),this.isEditing&&(this._fireSelectionChanged(),this._updateTextarea())},getSelectionStartFromPointer:function(h){for(var e=this.getLocalPointer(h),l=0,a=0,t=0,n=0,i=0,o,c,s=0,u=this._textLines.length;s<u&&t<=e.y;s++)t+=this.getHeightOfLine(s)*this.scaleY,i=s,s>0&&(n+=this._textLines[s-1].length+this.missingNewlineOffset(s-1));o=this._getLineLeftOffset(i),a=o*this.scaleX,c=this._textLines[i],this.direction==="rtl"&&(e.x=this.width*this.scaleX-e.x+a);for(var d=0,m=c.length;d<m&&(l=a,a+=this.__charBounds[i][d].kernedWidth*this.scaleX,a<=e.x);d++)n++;return this._getNewSelectionStartFromOffset(e,l,a,n,m)},_getNewSelectionStartFromOffset:function(h,e,l,a,t){var n=h.x-e,i=l-h.x,o=i>n||i<0?0:1,c=a+o;return this.flipX&&(c=t-c),c>this._text.length&&(c=this._text.length),c}}),r.util.object.extend(r.IText.prototype,{initHiddenTextarea:function(){this.hiddenTextarea=r.document.createElement("textarea"),this.hiddenTextarea.setAttribute("autocapitalize","off"),this.hiddenTextarea.setAttribute("autocorrect","off"),this.hiddenTextarea.setAttribute("autocomplete","off"),this.hiddenTextarea.setAttribute("spellcheck","false"),this.hiddenTextarea.setAttribute("data-fabric-hiddentextarea",""),this.hiddenTextarea.setAttribute("wrap","off");var h=this._calcTextareaPosition();this.hiddenTextarea.style.cssText="position: absolute; top: "+h.top+"; left: "+h.left+"; z-index: -999; opacity: 0; width: 1px; height: 1px; font-size: 1px; padding-top: "+h.fontSize+";",this.hiddenTextareaContainer?this.hiddenTextareaContainer.appendChild(this.hiddenTextarea):r.document.body.appendChild(this.hiddenTextarea),r.util.addListener(this.hiddenTextarea,"keydown",this.onKeyDown.bind(this)),r.util.addListener(this.hiddenTextarea,"keyup",this.onKeyUp.bind(this)),r.util.addListener(this.hiddenTextarea,"input",this.onInput.bind(this)),r.util.addListener(this.hiddenTextarea,"copy",this.copy.bind(this)),r.util.addListener(this.hiddenTextarea,"cut",this.copy.bind(this)),r.util.addListener(this.hiddenTextarea,"paste",this.paste.bind(this)),r.util.addListener(this.hiddenTextarea,"compositionstart",this.onCompositionStart.bind(this)),r.util.addListener(this.hiddenTextarea,"compositionupdate",this.onCompositionUpdate.bind(this)),r.util.addListener(this.hiddenTextarea,"compositionend",this.onCompositionEnd.bind(this)),!this._clickHandlerInitialized&&this.canvas&&(r.util.addListener(this.canvas.upperCanvasEl,"click",this.onClick.bind(this)),this._clickHandlerInitialized=!0)},keysMap:{9:"exitEditing",27:"exitEditing",33:"moveCursorUp",34:"moveCursorDown",35:"moveCursorRight",36:"moveCursorLeft",37:"moveCursorLeft",38:"moveCursorUp",39:"moveCursorRight",40:"moveCursorDown"},keysMapRtl:{9:"exitEditing",27:"exitEditing",33:"moveCursorUp",34:"moveCursorDown",35:"moveCursorLeft",36:"moveCursorRight",37:"moveCursorRight",38:"moveCursorUp",39:"moveCursorLeft",40:"moveCursorDown"},ctrlKeysMapUp:{67:"copy",88:"cut"},ctrlKeysMapDown:{65:"selectAll"},onClick:function(){this.hiddenTextarea&&this.hiddenTextarea.focus()},onKeyDown:function(h){if(this.isEditing){var e=this.direction==="rtl"?this.keysMapRtl:this.keysMap;if(h.keyCode in e)this[e[h.keyCode]](h);else if(h.keyCode in this.ctrlKeysMapDown&&(h.ctrlKey||h.metaKey))this[this.ctrlKeysMapDown[h.keyCode]](h);else return;h.stopImmediatePropagation(),h.preventDefault(),h.keyCode>=33&&h.keyCode<=40?(this.inCompositionMode=!1,this.clearContextTop(),this.renderCursorOrSelection()):this.canvas&&this.canvas.requestRenderAll()}},onKeyUp:function(h){if(!this.isEditing||this._copyDone||this.inCompositionMode){this._copyDone=!1;return}if(h.keyCode in this.ctrlKeysMapUp&&(h.ctrlKey||h.metaKey))this[this.ctrlKeysMapUp[h.keyCode]](h);else return;h.stopImmediatePropagation(),h.preventDefault(),this.canvas&&this.canvas.requestRenderAll()},onInput:function(h){var e=this.fromPaste;if(this.fromPaste=!1,h&&h.stopPropagation(),!!this.isEditing){var l=this._splitTextIntoLines(this.hiddenTextarea.value).graphemeText,a=this._text.length,t=l.length,n,i,o=t-a,c=this.selectionStart,s=this.selectionEnd,u=c!==s,d,m,p;if(this.hiddenTextarea.value===""){this.styles={},this.updateFromTextArea(),this.fire("changed"),this.canvas&&(this.canvas.fire("text:changed",{target:this}),this.canvas.requestRenderAll());return}var v=this.fromStringToGraphemeSelection(this.hiddenTextarea.selectionStart,this.hiddenTextarea.selectionEnd,this.hiddenTextarea.value),S=c>v.selectionStart;u?(n=this._text.slice(c,s),o+=s-c):t<a&&(S?n=this._text.slice(s+o,s):n=this._text.slice(c,c-o)),i=l.slice(v.selectionEnd-o,v.selectionEnd),n&&n.length&&(i.length&&(d=this.getSelectionStyles(c,c+1,!1),d=i.map(function(){return d[0]})),u?(m=c,p=s):S?(m=s-n.length,p=s):(m=s,p=s+n.length),this.removeStyleFromTo(m,p)),i.length&&(e&&i.join("")===r.copiedText&&!r.disableStyleCopyPaste&&(d=r.copiedTextStyle),this.insertNewStyleBlock(i,c,d)),this.updateFromTextArea(),this.fire("changed"),this.canvas&&(this.canvas.fire("text:changed",{target:this}),this.canvas.requestRenderAll())}},onCompositionStart:function(){this.inCompositionMode=!0},onCompositionEnd:function(){this.inCompositionMode=!1},onCompositionUpdate:function(h){this.compositionStart=h.target.selectionStart,this.compositionEnd=h.target.selectionEnd,this.updateTextareaPosition()},copy:function(){this.selectionStart!==this.selectionEnd&&(r.copiedText=this.getSelectedText(),r.disableStyleCopyPaste?r.copiedTextStyle=null:r.copiedTextStyle=this.getSelectionStyles(this.selectionStart,this.selectionEnd,!0),this._copyDone=!0)},paste:function(){this.fromPaste=!0},_getClipboardData:function(h){return h&&h.clipboardData||r.window.clipboardData},_getWidthBeforeCursor:function(h,e){var l=this._getLineLeftOffset(h),a;return e>0&&(a=this.__charBounds[h][e-1],l+=a.left+a.width),l},getDownCursorOffset:function(h,e){var l=this._getSelectionForOffset(h,e),a=this.get2DCursorLocation(l),t=a.lineIndex;if(t===this._textLines.length-1||h.metaKey||h.keyCode===34)return this._text.length-l;var n=a.charIndex,i=this._getWidthBeforeCursor(t,n),o=this._getIndexOnLine(t+1,i),c=this._textLines[t].slice(n);return c.length+o+1+this.missingNewlineOffset(t)},_getSelectionForOffset:function(h,e){return h.shiftKey&&this.selectionStart!==this.selectionEnd&&e?this.selectionEnd:this.selectionStart},getUpCursorOffset:function(h,e){var l=this._getSelectionForOffset(h,e),a=this.get2DCursorLocation(l),t=a.lineIndex;if(t===0||h.metaKey||h.keyCode===33)return-l;var n=a.charIndex,i=this._getWidthBeforeCursor(t,n),o=this._getIndexOnLine(t-1,i),c=this._textLines[t].slice(0,n),s=this.missingNewlineOffset(t-1);return-this._textLines[t-1].length+o-c.length+(1-s)},_getIndexOnLine:function(h,e){for(var l=this._textLines[h],a=this._getLineLeftOffset(h),t=a,n=0,i,o,c=0,s=l.length;c<s;c++)if(i=this.__charBounds[h][c].width,t+=i,t>e){o=!0;var u=t-i,d=t,m=Math.abs(u-e),p=Math.abs(d-e);n=p<m?c:c-1;break}return o||(n=l.length-1),n},moveCursorDown:function(h){this.selectionStart>=this._text.length&&this.selectionEnd>=this._text.length||this._moveCursorUpOrDown("Down",h)},moveCursorUp:function(h){this.selectionStart===0&&this.selectionEnd===0||this._moveCursorUpOrDown("Up",h)},_moveCursorUpOrDown:function(h,e){var l="get"+h+"CursorOffset",a=this[l](e,this._selectionDirection==="right");e.shiftKey?this.moveCursorWithShift(a):this.moveCursorWithoutShift(a),a!==0&&(this.setSelectionInBoundaries(),this.abortCursorAnimation(),this._currentCursorOpacity=1,this.initDelayedCursor(),this._fireSelectionChanged(),this._updateTextarea())},moveCursorWithShift:function(h){var e=this._selectionDirection==="left"?this.selectionStart+h:this.selectionEnd+h;return this.setSelectionStartEndWithShift(this.selectionStart,this.selectionEnd,e),h!==0},moveCursorWithoutShift:function(h){return h<0?(this.selectionStart+=h,this.selectionEnd=this.selectionStart):(this.selectionEnd+=h,this.selectionStart=this.selectionEnd),h!==0},moveCursorLeft:function(h){this.selectionStart===0&&this.selectionEnd===0||this._moveCursorLeftOrRight("Left",h)},_move:function(h,e,l){var a;if(h.altKey)a=this["findWordBoundary"+l](this[e]);else if(h.metaKey||h.keyCode===35||h.keyCode===36)a=this["findLineBoundary"+l](this[e]);else return this[e]+=l==="Left"?-1:1,!0;if(typeof a<"u"&&this[e]!==a)return this[e]=a,!0},_moveLeft:function(h,e){return this._move(h,e,"Left")},_moveRight:function(h,e){return this._move(h,e,"Right")},moveCursorLeftWithoutShift:function(h){var e=!0;return this._selectionDirection="left",this.selectionEnd===this.selectionStart&&this.selectionStart!==0&&(e=this._moveLeft(h,"selectionStart")),this.selectionEnd=this.selectionStart,e},moveCursorLeftWithShift:function(h){if(this._selectionDirection==="right"&&this.selectionStart!==this.selectionEnd)return this._moveLeft(h,"selectionEnd");if(this.selectionStart!==0)return this._selectionDirection="left",this._moveLeft(h,"selectionStart")},moveCursorRight:function(h){this.selectionStart>=this._text.length&&this.selectionEnd>=this._text.length||this._moveCursorLeftOrRight("Right",h)},_moveCursorLeftOrRight:function(h,e){var l="moveCursor"+h+"With";this._currentCursorOpacity=1,e.shiftKey?l+="Shift":l+="outShift",this[l](e)&&(this.abortCursorAnimation(),this.initDelayedCursor(),this._fireSelectionChanged(),this._updateTextarea())},moveCursorRightWithShift:function(h){if(this._selectionDirection==="left"&&this.selectionStart!==this.selectionEnd)return this._moveRight(h,"selectionStart");if(this.selectionEnd!==this._text.length)return this._selectionDirection="right",this._moveRight(h,"selectionEnd")},moveCursorRightWithoutShift:function(h){var e=!0;return this._selectionDirection="right",this.selectionStart===this.selectionEnd?(e=this._moveRight(h,"selectionStart"),this.selectionEnd=this.selectionStart):this.selectionStart=this.selectionEnd,e},removeChars:function(h,e){typeof e>"u"&&(e=h+1),this.removeStyleFromTo(h,e),this._text.splice(h,e-h),this.text=this._text.join(""),this.set("dirty",!0),this._shouldClearDimensionCache()&&(this.initDimensions(),this.setCoords()),this._removeExtraneousStyles()},insertChars:function(h,e,l,a){typeof a>"u"&&(a=l),a>l&&this.removeStyleFromTo(l,a);var t=r.util.string.graphemeSplit(h);this.insertNewStyleBlock(t,l,e),this._text=[].concat(this._text.slice(0,l),t,this._text.slice(a)),this.text=this._text.join(""),this.set("dirty",!0),this._shouldClearDimensionCache()&&(this.initDimensions(),this.setCoords()),this._removeExtraneousStyles()}}),(function(){var h=r.util.toFixed,e=/ +/g;r.util.object.extend(r.Text.prototype,{_toSVG:function(){var l=this._getSVGLeftTopOffsets(),a=this._getSVGTextAndBg(l.textTop,l.textLeft);return this._wrapSVGTextAndBg(a)},toSVG:function(l){return this._createBaseSVGMarkup(this._toSVG(),{reviver:l,noStyle:!0,withShadow:!0})},_getSVGLeftTopOffsets:function(){return{textLeft:-this.width/2,textTop:-this.height/2,lineTop:this.getHeightOfLine(0)}},_wrapSVGTextAndBg:function(l){var a=!0,t=this.getSvgTextDecoration(this);return[l.textBgRects.join(""),' <text xml:space="preserve" ',this.fontFamily?'font-family="'+this.fontFamily.replace(/"/g,"'")+'" ':"",this.fontSize?'font-size="'+this.fontSize+'" ':"",this.fontStyle?'font-style="'+this.fontStyle+'" ':"",this.fontWeight?'font-weight="'+this.fontWeight+'" ':"",t?'text-decoration="'+t+'" ':"",'style="',this.getSvgStyles(a),'"',this.addPaintOrder()," >",l.textSpans.join(""),`</text>
|
|
439
439
|
`]},_getSVGTextAndBg:function(l,a){var t=[],n=[],i=l,o;this._setSVGBg(n);for(var c=0,s=this._textLines.length;c<s;c++)o=this._getLineLeftOffset(c),(this.textBackgroundColor||this.styleHas("textBackgroundColor",c))&&this._setSVGTextLineBg(n,c,a+o,i),this._setSVGTextLineText(t,c,a+o,i),i+=this.getHeightOfLine(c);return{textSpans:t,textBgRects:n}},_createTextCharSpan:function(l,a,t,n){var i=l!==l.trim()||l.match(e),o=this.getSvgSpanStyles(a,i),c=o?'style="'+o+'"':"",s=a.deltaY,u="",d=r.Object.NUM_FRACTION_DIGITS;return s&&(u=' dy="'+h(s,d)+'" '),['<tspan x="',h(t,d),'" y="',h(n,d),'" ',u,c,">",r.util.string.escapeXml(l),"</tspan>"].join("")},_setSVGTextLineText:function(l,a,t,n){var i=this.getHeightOfLine(a),o=this.textAlign.indexOf("justify")!==-1,c,s,u="",d,m,p=0,v=this._textLines[a],S;n+=i*(1-this._fontSizeFraction)/this.lineHeight;for(var w=0,E=v.length-1;w<=E;w++)S=w===E||this.charSpacing,u+=v[w],d=this.__charBounds[a][w],p===0?(t+=d.kernedWidth-d.width,p+=d.width):p+=d.kernedWidth,o&&!S&&this._reSpaceAndTab.test(v[w])&&(S=!0),S||(c=c||this.getCompleteStyleDeclaration(a,w),s=this.getCompleteStyleDeclaration(a,w+1),S=r.util.hasStyleChanged(c,s,!0)),S&&(m=this._getStyleDeclaration(a,w)||{},l.push(this._createTextCharSpan(u,m,t,n)),u="",c=s,t+=p,p=0)},_pushTextBgRect:function(l,a,t,n,i,o){var c=r.Object.NUM_FRACTION_DIGITS;l.push(" <rect ",this._getFillAttributes(a),' x="',h(t,c),'" y="',h(n,c),'" width="',h(i,c),'" height="',h(o,c),`"></rect>
|
|
440
440
|
`)},_setSVGTextLineBg:function(l,a,t,n){for(var i=this._textLines[a],o=this.getHeightOfLine(a)/this.lineHeight,c=0,s=0,u,d,m=this.getValueOfPropertyAt(a,0,"textBackgroundColor"),p=0,v=i.length;p<v;p++)u=this.__charBounds[a][p],d=this.getValueOfPropertyAt(a,p,"textBackgroundColor"),d!==m?(m&&this._pushTextBgRect(l,m,t+s,n,c,o),s=u.left,c=u.width,m=d):c+=u.kernedWidth;d&&this._pushTextBgRect(l,d,t+s,n,c,o)},_getFillAttributes:function(l){var a=l&&typeof l=="string"?new r.Color(l):"";return!a||!a.getSource()||a.getAlpha()===1?'fill="'+l+'"':'opacity="'+a.getAlpha()+'" fill="'+a.setAlpha(1).toRgb()+'"'},_getSVGLineTopOffset:function(l){for(var a=0,t=0,n=0;n<l;n++)a+=this.getHeightOfLine(n);return t=this.getHeightOfLine(n),{lineTop:a,offset:(this._fontSizeMult-this._fontSizeFraction)*t/(this.lineHeight*this._fontSizeMult)}},getSvgStyles:function(l){var a=r.Object.prototype.getSvgStyles.call(this,l);return a+" white-space: pre;"}})})(),(function(h){var e=h.fabric||(h.fabric={});e.Textbox=e.util.createClass(e.IText,e.Observable,{type:"textbox",minWidth:20,dynamicMinWidth:2,__cachedLines:null,lockScalingFlip:!0,noScaleCache:!1,_dimensionAffectingProps:e.Text.prototype._dimensionAffectingProps.concat("width"),_wordJoiners:/[ \t\r]/,splitByGrapheme:!1,initDimensions:function(){this.__skipDimension||(this.isEditing&&this.initDelayedCursor(),this.clearContextTop(),this._clearCache(),this.dynamicMinWidth=0,this._styleMap=this._generateStyleMap(this._splitText()),this.dynamicMinWidth>this.width&&this._set("width",this.dynamicMinWidth),this.textAlign.indexOf("justify")!==-1&&this.enlargeSpaces(),this.height=this.calcTextHeight(),this.saveState({propertySet:"_dimensionAffectingProps"}))},_generateStyleMap:function(l){for(var a=0,t=0,n=0,i={},o=0;o<l.graphemeLines.length;o++)l.graphemeText[n]===`
|
|
441
|
-
`&&o>0?(t=0,n++,a++):!this.splitByGrapheme&&this._reSpaceAndTab.test(l.graphemeText[n])&&o>0&&(t++,n++),i[o]={line:a,offset:t},n+=l.graphemeLines[o].length,t+=l.graphemeLines[o].length;return i},styleHas:function(l,a){if(this._styleMap&&!this.isWrapping){var t=this._styleMap[a];t&&(a=t.line)}return e.Text.prototype.styleHas.call(this,l,a)},isEmptyStyles:function(l){if(!this.styles)return!0;var a=0,t=l+1,n,i,o=!1,c=this._styleMap[l],s=this._styleMap[l+1];c&&(l=c.line,a=c.offset),s&&(t=s.line,o=t===l,n=s.offset),i=typeof l>"u"?this.styles:{line:this.styles[l]};for(var u in i)for(var d in i[u])if(d>=a&&(!o||d<n))for(var m in i[u][d])return!1;return!0},_getStyleDeclaration:function(l,a){if(this._styleMap&&!this.isWrapping){var t=this._styleMap[l];if(!t)return null;l=t.line,a=t.offset+a}return this.callSuper("_getStyleDeclaration",l,a)},_setStyleDeclaration:function(l,a,t){var n=this._styleMap[l];l=n.line,a=n.offset+a,this.styles[l][a]=t},_deleteStyleDeclaration:function(l,a){var t=this._styleMap[l];l=t.line,a=t.offset+a,delete this.styles[l][a]},_getLineStyle:function(l){var a=this._styleMap[l];return!!this.styles[a.line]},_setLineStyle:function(l){var a=this._styleMap[l];this.styles[a.line]={}},_wrapText:function(l,a){var t=[],n;for(this.isWrapping=!0,n=0;n<l.length;n++)t=t.concat(this._wrapLine(l[n],n,a));return this.isWrapping=!1,t},_measureWord:function(l,a,t){var n=0,i,o=!0;t=t||0;for(var c=0,s=l.length;c<s;c++){var u=this._getGraphemeBox(l[c],a,c+t,i,o);n+=u.kernedWidth,i=l[c]}return n},_wrapLine:function(l,a,t,R){var i=0,o=this.splitByGrapheme,c=[],s=[],u=o?e.util.string.graphemeSplit(l):l.split(this._wordJoiners),d="",m=0,p=o?"":" ",v=0,S=0,w=0,E=!0,F=this._getWidthOfCharSpacing(),R=R||0;u.length===0&&u.push([]),t-=R;for(var z=0;z<u.length;z++)d=o?u[z]:e.util.string.graphemeSplit(u[z]),v=this._measureWord(d,a,m),m+=d.length,i+=S+v-F,i>t&&!E?(c.push(s),s=[],i=v,E=!0):i+=F,!E&&!o&&s.push(p),s=s.concat(d),S=o?0:this._measureWord([p],a,m),m++,E=!1,v>w&&(w=v);return z&&c.push(s),w+R>this.dynamicMinWidth&&(this.dynamicMinWidth=w-F+R),c},isEndOfWrapping:function(l){return!this._styleMap[l+1]||this._styleMap[l+1].line!==this._styleMap[l].line},missingNewlineOffset:function(l){return this.splitByGrapheme?this.isEndOfWrapping(l)?1:0:1},_splitTextIntoLines:function(l){for(var a=e.Text.prototype._splitTextIntoLines.call(this,l),t=this._wrapText(a.lines,this.width),n=new Array(t.length),i=0;i<t.length;i++)n[i]=t[i].join("");return a.lines=n,a.graphemeLines=t,a},getMinWidth:function(){return Math.max(this.minWidth,this.dynamicMinWidth)},_removeExtraneousStyles:function(){var l={};for(var a in this._styleMap)this._textLines[a]&&(l[this._styleMap[a].line]=1);for(var a in this.styles)l[a]||delete this.styles[a]},toObject:function(l){return this.callSuper("toObject",["minWidth","splitByGrapheme"].concat(l))}}),e.Textbox.fromObject=function(l,a){var t=e.util.stylesFromArray(l.styles,l.text),n=Object.assign({},l,{styles:t});return e.Object._fromObject("Textbox",n,a,"text")}})(f),(function(){var h=r.controlsUtils,e=h.scaleSkewCursorStyleHandler,l=h.scaleCursorStyleHandler,a=h.scalingEqually,t=h.scalingYOrSkewingX,n=h.scalingXOrSkewingY,i=h.scaleOrSkewActionName,o=r.Object.prototype.controls;if(o.ml=new r.Control({x:-.5,y:0,cursorStyleHandler:e,actionHandler:n,getActionName:i}),o.mr=new r.Control({x:.5,y:0,cursorStyleHandler:e,actionHandler:n,getActionName:i}),o.mb=new r.Control({x:0,y:.5,cursorStyleHandler:e,actionHandler:t,getActionName:i}),o.mt=new r.Control({x:0,y:-.5,cursorStyleHandler:e,actionHandler:t,getActionName:i}),o.tl=new r.Control({x:-.5,y:-.5,cursorStyleHandler:l,actionHandler:a}),o.tr=new r.Control({x:.5,y:-.5,cursorStyleHandler:l,actionHandler:a}),o.bl=new r.Control({x:-.5,y:.5,cursorStyleHandler:l,actionHandler:a}),o.br=new r.Control({x:.5,y:.5,cursorStyleHandler:l,actionHandler:a}),o.mtr=new r.Control({x:0,y:-.5,actionHandler:h.rotationWithSnapping,cursorStyleHandler:h.rotationStyleHandler,offsetY:-40,withConnection:!0,actionName:"rotate"}),r.Textbox){var c=r.Textbox.prototype.controls={};c.mtr=o.mtr,c.tr=o.tr,c.br=o.br,c.tl=o.tl,c.bl=o.bl,c.mt=o.mt,c.mb=o.mb,c.mr=new r.Control({x:.5,y:0,actionHandler:h.changeWidth,cursorStyleHandler:e,actionName:"resizing"}),c.ml=new r.Control({x:-.5,y:0,actionHandler:h.changeWidth,cursorStyleHandler:e,actionName:"resizing"})}})()})(si)),si}var mt=No(),ue=(f=>(f.ONE="selectOne",f.MULTI="selectMultiple",f.CANCEL="selectCancel",f))(ue||{}),te=(f=>(f.EMPTY="",f.ONE="one",f.MULTI="multiple",f))(te||{});function dr(f){f&&f.forEach(r=>{r.objects?dr(r.objects):r.type==="text"&&(r.type="textbox")})}const ge=class ge{constructor(r,g){this.canvas=r,this.editor=g,this.selectedMode=te.EMPTY,this._initSelectEvent()}_initSelectEvent(){this.canvas.on("selection:created",()=>this._emitSelectEvent()),this.canvas.on("selection:updated",()=>this._emitSelectEvent()),this.canvas.on("selection:cleared",()=>this._emitSelectEvent())}_emitSelectEvent(){if(!this.canvas)throw TypeError("还未初始化");const r=this.canvas.getActiveObjects().filter(g=>!(g instanceof mt.fabric.GuideLine));r&&r.length===1?(this.selectedMode=te.ONE,this.editor.emit(ue.ONE,r)):r&&r.length>1?(this.selectedMode=te.MULTI,this.editor.emit(ue.MULTI,r)):this.editor.emit(ue.CANCEL)}getSelectMode(){return String(this.selectedMode)}insert(r){ur({accept:".json"}).then(g=>{if(g&&g.length>0){const _=g[0],y=new FileReader;y.readAsText(_,"UTF-8"),y.onload=()=>{this.loadJSON(y.result,r)}}})}renderITextPath(r){r.forEach(g=>{const _=this.canvas.getObjects().find(y=>y.id===g.id);_&&mt.fabric.Path.fromObject(g.path,y=>{_.set("path",y)})})}async loadJSON(r,g){const _=typeof r=="string"?JSON.parse(r):r,y=[];_.objects.forEach(b=>{!b.id&&(b.id=On()),b.type==="i-text"&&b.path&&(y.push({id:b.id,path:b.path}),b.path=null)});const C=await this._transform(_);r=JSON.stringify(C),this.editor.hooksEntity.hookImportBefore.callAsync(r,()=>{this.canvas.loadFromJSON(r,()=>{this.renderITextPath(y),this.canvas.renderAll(),this.editor.hooksEntity.hookImportAfter.callAsync(r,()=>{this.editor?.updateDrawStatus&&typeof this.editor.updateDrawStatus=="function"&&this.editor.updateDrawStatus(!!_.overlayImage),this.canvas.renderAll(),g&&g(),this.editor.emit("loadJson")})},(b,h)=>{this.editor.hooksEntity.hookTransformObjectEnd.callAsync({originObject:b,fabricObject:h},()=>{this.canvas.renderAll()})})})}async _transform(r){if(await this.promiseCallAsync(r),r.objects){const g=r.objects.map(_=>this._transform(_));await Promise.all(g)}return r}promiseCallAsync(r){return new Promise(g=>{this.editor.hooksEntity.hookTransform.callAsync(r,()=>{g(r)})})}getJson(r){const g=this.getExtensionKey(),_=this.canvas.toJSON(g);return r?.clearSrc&&_.objects.forEach(y=>{["qrcode","barcode","imageTextList"].includes(y.extensionType)&&(y.src="")}),_}getExtensionKey(){return["id","gradientAngle","selectable","hasControls","linkData","editable","extensionType","extension","verticalAlign","roundValue","getBase64","lockScalingX","lockScalingY","_originSize"]}dragAddItem(r,g){if(g){const{left:y,top:C}=this.canvas.getSelectionElement().getBoundingClientRect();if(g.x<y||g.y<C||r.width===void 0)return;const b={x:g.x-y,y:g.y-C},h=this.canvas.restorePointerVpt(b);r.left=h.x-r.width/2,r.top=h.y}const{width:_}=this._getSaveOption();_&&r.scaleToWidth(_/2),this.canvas.add(r),this.canvas.setActiveObject(r),!g&&this.editor.position("center"),this.canvas.requestRenderAll()}clipboard(){const r=this.getJson();return ki(JSON.stringify(r,null," "))}async clipboardBase64(){const r=await this.preview();return ki(r)}async saveJson(){const r=this.getJson();await dr(r.objects);const g=`data:text/json;charset=utf-8,${encodeURIComponent(JSON.stringify(r,null," "))}`;Re(g,"json")}saveSvg(){this.editor.hooksEntity.hookSaveBefore.callAsync("",()=>{const{fontOption:r,svgOption:g}=this._getSaveSvgOption();mt.fabric.fontPaths={...r};const _=this.canvas.toSVG(g),y=`data:image/svg+xml;charset=utf-8,${encodeURIComponent(_)}`;this.editor.hooksEntity.hookSaveAfter.callAsync(y,()=>{Re(y,"svg")})})}saveImg(){this.editor.hooksEntity.hookSaveBefore.callAsync("",()=>{const r=this._getSaveOption();this.canvas.setViewportTransform([1,0,0,1,0,0]);const g=this.canvas.toDataURL(r);this.editor.hooksEntity.hookSaveAfter.callAsync(g,()=>{Re(g,"png")})})}getBase64(r){return new Promise(g=>{this.editor.hooksEntity.hookSaveBefore.callAsync("",()=>{const _=this._getSaveOption();this.canvas.setViewportTransform([1,0,0,1,0,0]);const y=this.canvas.toDataURL(_);this.rotateBase64(y,r?.rotation).then(C=>{this.editor.hooksEntity.hookSaveAfter.callAsync(C,()=>g(C))},()=>{this.editor.hooksEntity.hookSaveAfter.callAsync(y,()=>g(y))})})})}async getBase64Result(r){const g=this.normalizePrintRotation(r?.rotation);return{content:await this.getBase64({rotation:g}),...this.getPrintExportSize(g),rotation:g}}getSVG(r){return new Promise(g=>{this.editor.hooksEntity.hookSaveBefore.callAsync("",()=>{this.canvas.setViewportTransform([1,0,0,1,0,0]);const{fontOption:_,svgOption:y}=this._getSaveSvgOption({ignoreFont:!0,width:r?.width,height:r?.height});mt.fabric.fontPaths={..._};const C=this.rotateSVG(this.canvas.toSVG(y),r?.rotation);this.editor.hooksEntity.hookSaveAfter.callAsync(C,()=>g(C))})})}async getSVGResult(r){const g=this.normalizePrintRotation(r?.rotation);return{content:await this.getSVG({...r,rotation:g}),...this.getPrintExportSize(g),rotation:g}}preview(){return new Promise(r=>{this.editor.hooksEntity.hookSaveBefore.callAsync("",()=>{const g=this._getSaveOption();this.canvas.setViewportTransform([1,0,0,1,0,0]),this.canvas.renderAll();const _=this.canvas.toDataURL(g);this.editor.hooksEntity.hookSaveAfter.callAsync(_,()=>{r(_)})})})}staticPreview(){return new Promise(r=>{})}_getSaveSvgOption(r){const g=this.canvas.getObjects().find(a=>a.id==="workspace");let _=this.canvas.getObjects().filter(a=>a.type=="textbox").map(a=>a.fontFamily);_=Array.from(new Set(_));const y=this.editor.getPlugin("FontPlugin").cacheList,C={};if(!r?.ignoreFont)for(const a of _){const t=y.find(n=>n.name===a);C[a]=t.file}console.log("_getSaveSvgOption",C);const{left:b,top:h,width:e,height:l}=g;return{fontOption:C,svgOption:{width:r?.width??e,height:r?.height??l,viewBox:{x:b,y:h,width:e,height:l}}}}_getSaveOption(){const r=this.canvas.getObjects().find(h=>h.id==="workspace"),{left:g,top:_,width:y,height:C}=r;return{name:"New Image",format:"jpeg",quality:1,multiplier:5,width:y,height:C,left:g,top:_}}normalizePrintRotation(r){return[0,90,180,270].includes(Number(r))?Number(r):0}getPrintExportSize(r){const g=this.canvas.getObjects().find(b=>b.id==="workspace"),_=this.editor.getSizeByUnit,y=g?_?_.call(this.editor,g.width||0):g.width||0:0,C=g?_?_.call(this.editor,g.height||0):g.height||0:0;return r===90||r===270?{width:C,height:y}:{width:y,height:C}}rotateBase64(r,g){const _=this.normalizePrintRotation(g);return!_||typeof Image>"u"?Promise.resolve(r):new Promise((y,C)=>{const b=new Image;b.onload=()=>{const h=document.createElement("canvas"),e=_===90||_===270;h.width=e?b.height:b.width,h.height=e?b.width:b.height;const l=h.getContext("2d");if(!l){C(new Error("无法创建旋转画布"));return}_===90?l.translate(h.width,0):_===180?l.translate(h.width,h.height):_===270&&l.translate(0,h.height),l.rotate(_*Math.PI/180),l.drawImage(b,0,0);const a=/^data:([^;,]+)/i.exec(r)?.[1];y(h.toDataURL(a||"image/jpeg",1))},b.onerror=()=>C(new Error("无法读取导出图片")),b.src=r})}rotateSVG(r,g){const _=this.normalizePrintRotation(g);if(!_||typeof DOMParser>"u")return r;const y=new DOMParser().parseFromString(r,"image/svg+xml"),C=y.documentElement;if(!C||C.nodeName==="parsererror")return r;const b=String(C.getAttribute("viewBox")||"").trim().split(/[\s,]+/).map(Number);if(b.length!==4||b.some(s=>!Number.isFinite(s)))return r;const[h,e,l,a]=b,t=C.getAttribute("width"),n=C.getAttribute("height"),o={90:`translate(${a} 0) rotate(90) translate(${-h} ${-e})`,180:`translate(${l} ${a}) rotate(180) translate(${-h} ${-e})`,270:`translate(0 ${l}) rotate(270) translate(${-h} ${-e})`}[_],c=y.createElementNS("http://www.w3.org/2000/svg","g");return c.setAttribute("transform",o),Array.from(C.childNodes).forEach(s=>{s.nodeType===1&&["defs","style","desc","title","metadata"].includes(s.localName)||c.appendChild(s)}),C.appendChild(c),_===90||_===270?(C.setAttribute("viewBox",`0 0 ${a} ${l}`),n&&C.setAttribute("width",n),t&&C.setAttribute("height",t)):C.setAttribute("viewBox",`0 0 ${l} ${a}`),new XMLSerializer().serializeToString(C)}clear(){this.canvas.getObjects().forEach(r=>{r.id!=="workspace"&&this.canvas.remove(r)}),this.editor?.setWorkspaseBg("#fff"),this.canvas.discardActiveObject(),this.canvas.renderAll()}destroy(){console.log("pluginDestroy")}};ge.pluginName="ServersPlugin",ge.apis=["insert","loadJSON","getJson","dragAddItem","clipboard","clipboardBase64","saveJson","saveSvg","saveImg","getBase64","getBase64Result","getSVG","getSVGResult","clear","preview","staticPreview","getSelectMode","getExtensionKey"],ge.events=[te.ONE,te.MULTI,ue.CANCEL];let Ai=ge;var bt={},ai={},rn;function gr(){return rn||(rn=1,ai.deprecate=(f,r)=>{let g=!0;return function(){return g&&(console.warn(`DeprecationWarning: ${r}`),g=!1),f.apply(this,arguments)}}),ai}var li,sn;function Mt(){if(sn)return li;sn=1;const r=gr().deprecate(()=>{},"Hook.context is deprecated and will be removed");function g(...b){return this.call=this._createCall("sync"),this.call(...b)}function _(...b){return this.callAsync=this._createCall("async"),this.callAsync(...b)}function y(...b){return this.promise=this._createCall("promise"),this.promise(...b)}class C{constructor(h=[],e=void 0){this._args=h,this.name=e,this.taps=[],this.interceptors=[],this._call=g,this.call=g,this._callAsync=_,this.callAsync=_,this._promise=y,this.promise=y,this._x=void 0,this.compile=this.compile,this.tap=this.tap,this.tapAsync=this.tapAsync,this.tapPromise=this.tapPromise}compile(h){throw new Error("Abstract: should be overridden")}_createCall(h){return this.compile({taps:this.taps,interceptors:this.interceptors,args:this._args,type:h})}_tap(h,e,l){if(typeof e=="string")e={name:e.trim()};else if(typeof e!="object"||e===null)throw new Error("Invalid tap options");if(typeof e.name!="string"||e.name==="")throw new Error("Missing name for tap");typeof e.context<"u"&&r(),e=Object.assign({type:h,fn:l},e),e=this._runRegisterInterceptors(e),this._insert(e)}tap(h,e){this._tap("sync",h,e)}tapAsync(h,e){this._tap("async",h,e)}tapPromise(h,e){this._tap("promise",h,e)}_runRegisterInterceptors(h){for(const e of this.interceptors)if(e.register){const l=e.register(h);l!==void 0&&(h=l)}return h}withOptions(h){const e=l=>Object.assign({},h,typeof l=="string"?{name:l}:l);return{name:this.name,tap:(l,a)=>this.tap(e(l),a),tapAsync:(l,a)=>this.tapAsync(e(l),a),tapPromise:(l,a)=>this.tapPromise(e(l),a),intercept:l=>this.intercept(l),isUsed:()=>this.isUsed(),withOptions:l=>this.withOptions(e(l))}}isUsed(){return this.taps.length>0||this.interceptors.length>0}intercept(h){if(this._resetCompilation(),this.interceptors.push(Object.assign({},h)),h.register)for(let e=0;e<this.taps.length;e++)this.taps[e]=h.register(this.taps[e])}_resetCompilation(){this.call=this._call,this.callAsync=this._callAsync,this.promise=this._promise}_insert(h){this._resetCompilation();let e;typeof h.before=="string"?e=new Set([h.before]):Array.isArray(h.before)&&(e=new Set(h.before));let l=0;typeof h.stage=="number"&&(l=h.stage);let a=this.taps.length;for(;a>0;){a--;const t=this.taps[a];this.taps[a+1]=t;const n=t.stage||0;if(e){if(e.has(t.name)){e.delete(t.name);continue}if(e.size>0)continue}if(!(n>l)){a++;break}}this.taps[a]=h}}return Object.setPrototypeOf(C.prototype,null),li=C,li}var hi,on;function Lt(){if(on)return hi;on=1;class f{constructor(g){this.config=g,this.options=void 0,this._args=void 0}create(g){this.init(g);let _;switch(this.options.type){case"sync":_=new Function(this.args(),`"use strict";
|
|
441
|
+
`&&o>0?(t=0,n++,a++):!this.splitByGrapheme&&this._reSpaceAndTab.test(l.graphemeText[n])&&o>0&&(t++,n++),i[o]={line:a,offset:t},n+=l.graphemeLines[o].length,t+=l.graphemeLines[o].length;return i},styleHas:function(l,a){if(this._styleMap&&!this.isWrapping){var t=this._styleMap[a];t&&(a=t.line)}return e.Text.prototype.styleHas.call(this,l,a)},isEmptyStyles:function(l){if(!this.styles)return!0;var a=0,t=l+1,n,i,o=!1,c=this._styleMap[l],s=this._styleMap[l+1];c&&(l=c.line,a=c.offset),s&&(t=s.line,o=t===l,n=s.offset),i=typeof l>"u"?this.styles:{line:this.styles[l]};for(var u in i)for(var d in i[u])if(d>=a&&(!o||d<n))for(var m in i[u][d])return!1;return!0},_getStyleDeclaration:function(l,a){if(this._styleMap&&!this.isWrapping){var t=this._styleMap[l];if(!t)return null;l=t.line,a=t.offset+a}return this.callSuper("_getStyleDeclaration",l,a)},_setStyleDeclaration:function(l,a,t){var n=this._styleMap[l];l=n.line,a=n.offset+a,this.styles[l][a]=t},_deleteStyleDeclaration:function(l,a){var t=this._styleMap[l];l=t.line,a=t.offset+a,delete this.styles[l][a]},_getLineStyle:function(l){var a=this._styleMap[l];return!!this.styles[a.line]},_setLineStyle:function(l){var a=this._styleMap[l];this.styles[a.line]={}},_wrapText:function(l,a){var t=[],n;for(this.isWrapping=!0,n=0;n<l.length;n++)t=t.concat(this._wrapLine(l[n],n,a));return this.isWrapping=!1,t},_measureWord:function(l,a,t){var n=0,i,o=!0;t=t||0;for(var c=0,s=l.length;c<s;c++){var u=this._getGraphemeBox(l[c],a,c+t,i,o);n+=u.kernedWidth,i=l[c]}return n},_wrapLine:function(l,a,t,R){var i=0,o=this.splitByGrapheme,c=[],s=[],u=o?e.util.string.graphemeSplit(l):l.split(this._wordJoiners),d="",m=0,p=o?"":" ",v=0,S=0,w=0,E=!0,F=this._getWidthOfCharSpacing(),R=R||0;u.length===0&&u.push([]),t-=R;for(var z=0;z<u.length;z++)d=o?u[z]:e.util.string.graphemeSplit(u[z]),v=this._measureWord(d,a,m),m+=d.length,i+=S+v-F,i>t&&!E?(c.push(s),s=[],i=v,E=!0):i+=F,!E&&!o&&s.push(p),s=s.concat(d),S=o?0:this._measureWord([p],a,m),m++,E=!1,v>w&&(w=v);return z&&c.push(s),w+R>this.dynamicMinWidth&&(this.dynamicMinWidth=w-F+R),c},isEndOfWrapping:function(l){return!this._styleMap[l+1]||this._styleMap[l+1].line!==this._styleMap[l].line},missingNewlineOffset:function(l){return this.splitByGrapheme?this.isEndOfWrapping(l)?1:0:1},_splitTextIntoLines:function(l){for(var a=e.Text.prototype._splitTextIntoLines.call(this,l),t=this._wrapText(a.lines,this.width),n=new Array(t.length),i=0;i<t.length;i++)n[i]=t[i].join("");return a.lines=n,a.graphemeLines=t,a},getMinWidth:function(){return Math.max(this.minWidth,this.dynamicMinWidth)},_removeExtraneousStyles:function(){var l={};for(var a in this._styleMap)this._textLines[a]&&(l[this._styleMap[a].line]=1);for(var a in this.styles)l[a]||delete this.styles[a]},toObject:function(l){return this.callSuper("toObject",["minWidth","splitByGrapheme"].concat(l))}}),e.Textbox.fromObject=function(l,a){var t=e.util.stylesFromArray(l.styles,l.text),n=Object.assign({},l,{styles:t});return e.Object._fromObject("Textbox",n,a,"text")}})(f),(function(){var h=r.controlsUtils,e=h.scaleSkewCursorStyleHandler,l=h.scaleCursorStyleHandler,a=h.scalingEqually,t=h.scalingYOrSkewingX,n=h.scalingXOrSkewingY,i=h.scaleOrSkewActionName,o=r.Object.prototype.controls;if(o.ml=new r.Control({x:-.5,y:0,cursorStyleHandler:e,actionHandler:n,getActionName:i}),o.mr=new r.Control({x:.5,y:0,cursorStyleHandler:e,actionHandler:n,getActionName:i}),o.mb=new r.Control({x:0,y:.5,cursorStyleHandler:e,actionHandler:t,getActionName:i}),o.mt=new r.Control({x:0,y:-.5,cursorStyleHandler:e,actionHandler:t,getActionName:i}),o.tl=new r.Control({x:-.5,y:-.5,cursorStyleHandler:l,actionHandler:a}),o.tr=new r.Control({x:.5,y:-.5,cursorStyleHandler:l,actionHandler:a}),o.bl=new r.Control({x:-.5,y:.5,cursorStyleHandler:l,actionHandler:a}),o.br=new r.Control({x:.5,y:.5,cursorStyleHandler:l,actionHandler:a}),o.mtr=new r.Control({x:0,y:-.5,actionHandler:h.rotationWithSnapping,cursorStyleHandler:h.rotationStyleHandler,offsetY:-40,withConnection:!0,actionName:"rotate"}),r.Textbox){var c=r.Textbox.prototype.controls={};c.mtr=o.mtr,c.tr=o.tr,c.br=o.br,c.tl=o.tl,c.bl=o.bl,c.mt=o.mt,c.mb=o.mb,c.mr=new r.Control({x:.5,y:0,actionHandler:h.changeWidth,cursorStyleHandler:e,actionName:"resizing"}),c.ml=new r.Control({x:-.5,y:0,actionHandler:h.changeWidth,cursorStyleHandler:e,actionName:"resizing"})}})()})(si)),si}var mt=No(),ue=(f=>(f.ONE="selectOne",f.MULTI="selectMultiple",f.CANCEL="selectCancel",f))(ue||{}),te=(f=>(f.EMPTY="",f.ONE="one",f.MULTI="multiple",f))(te||{});function dr(f){f&&f.forEach(r=>{r.objects?dr(r.objects):r.type==="text"&&(r.type="textbox")})}const ge=class ge{constructor(r,g){this.canvas=r,this.editor=g,this.selectedMode=te.EMPTY,this._initSelectEvent()}_initSelectEvent(){this.canvas.on("selection:created",()=>this._emitSelectEvent()),this.canvas.on("selection:updated",()=>this._emitSelectEvent()),this.canvas.on("selection:cleared",()=>this._emitSelectEvent())}_emitSelectEvent(){if(!this.canvas)throw TypeError("还未初始化");const r=this.canvas.getActiveObjects().filter(g=>!(g instanceof mt.fabric.GuideLine));r&&r.length===1?(this.selectedMode=te.ONE,this.editor.emit(ue.ONE,r)):r&&r.length>1?(this.selectedMode=te.MULTI,this.editor.emit(ue.MULTI,r)):this.editor.emit(ue.CANCEL)}getSelectMode(){return String(this.selectedMode)}insert(r){ur({accept:".json"}).then(g=>{if(g&&g.length>0){const _=g[0],y=new FileReader;y.readAsText(_,"UTF-8"),y.onload=()=>{this.loadJSON(y.result,r)}}})}renderITextPath(r){r.forEach(g=>{const _=this.canvas.getObjects().find(y=>y.id===g.id);_&&mt.fabric.Path.fromObject(g.path,y=>{_.set("path",y)})})}async loadJSON(r,g){const _=typeof r=="string"?JSON.parse(r):r,y=[];_.objects.forEach(b=>{!b.id&&(b.id=On()),b.type==="i-text"&&b.path&&(y.push({id:b.id,path:b.path}),b.path=null)});const C=await this._transform(_);r=JSON.stringify(C),this.editor.hooksEntity.hookImportBefore.callAsync(r,()=>{this.canvas.loadFromJSON(r,()=>{this.renderITextPath(y),this.canvas.renderAll(),this.editor.hooksEntity.hookImportAfter.callAsync(r,()=>{this.editor?.updateDrawStatus&&typeof this.editor.updateDrawStatus=="function"&&this.editor.updateDrawStatus(!!_.overlayImage),this.canvas.renderAll(),g&&g(),this.editor.emit("loadJson")})},(b,h)=>{this.editor.hooksEntity.hookTransformObjectEnd.callAsync({originObject:b,fabricObject:h},()=>{this.canvas.renderAll()})})})}async _transform(r){if(await this.promiseCallAsync(r),r.objects){const g=r.objects.map(_=>this._transform(_));await Promise.all(g)}return r}promiseCallAsync(r){return new Promise(g=>{this.editor.hooksEntity.hookTransform.callAsync(r,()=>{g(r)})})}getJson(r){const g=this.getExtensionKey(),_=this.canvas.toJSON(g);return r?.clearSrc&&_.objects.forEach(y=>{["qrcode","barcode","imageTextList"].includes(y.extensionType)&&(y.src="")}),_}getExtensionKey(){return["id","gradientAngle","selectable","hasControls","linkData","editable","extensionType","extension","verticalAlign","roundValue","getBase64","lockScalingX","lockScalingY","_originSize"]}dragAddItem(r,g){if(g){const{left:y,top:C}=this.canvas.getSelectionElement().getBoundingClientRect();if(g.x<y||g.y<C||r.width===void 0)return;const b={x:g.x-y,y:g.y-C},h=this.canvas.restorePointerVpt(b);r.left=h.x-r.width/2,r.top=h.y}const{width:_}=this._getSaveOption();_&&r.scaleToWidth(_/2),this.canvas.add(r),this.canvas.setActiveObject(r),!g&&this.editor.position("center"),this.canvas.requestRenderAll()}clipboard(){const r=this.getJson();return ki(JSON.stringify(r,null," "))}async clipboardBase64(){const r=await this.preview();return ki(r)}async saveJson(){const r=this.getJson();await dr(r.objects);const g=`data:text/json;charset=utf-8,${encodeURIComponent(JSON.stringify(r,null," "))}`;Re(g,"json")}saveSvg(){this.editor.hooksEntity.hookSaveBefore.callAsync("",()=>{const{fontOption:r,svgOption:g}=this._getSaveSvgOption();mt.fabric.fontPaths={...r};const _=this.canvas.toSVG(g),y=`data:image/svg+xml;charset=utf-8,${encodeURIComponent(_)}`;this.editor.hooksEntity.hookSaveAfter.callAsync(y,()=>{Re(y,"svg")})})}saveImg(){this.editor.hooksEntity.hookSaveBefore.callAsync("",()=>{const r=this._getSaveOption();this.canvas.setViewportTransform([1,0,0,1,0,0]);const g=this.canvas.toDataURL(r);this.editor.hooksEntity.hookSaveAfter.callAsync(g,()=>{Re(g,"png")})})}exportBase64(r){const g=this.normalizePrintRotation(r?.rotation);return new Promise((_,y)=>{let C={width:0,height:0};const b=(h,e)=>{this.editor.hooksEntity.hookSaveAfter.callAsync(h,l=>{const a=e||l;a?y(a):_({content:h,...C,rotation:g})})};this.editor.hooksEntity.hookSaveBefore.callAsync("",h=>{if(h){y(h);return}try{const e=this._getSaveOption();C=this.getPrintExportSize(g),this.canvas.setViewportTransform([1,0,0,1,0,0]);const l=this.canvas.toDataURL(e);this.rotateBase64(l,g).then(a=>b(a),a=>b(l,a))}catch(e){b("",e)}})})}getBase64(r){return this.exportBase64(r).then(g=>g.content)}async getBase64Result(r){return this.exportBase64(r)}exportSVG(r){const g=this.normalizePrintRotation(r?.rotation);return new Promise((_,y)=>{let C={width:0,height:0};const b=(h,e)=>{this.editor.hooksEntity.hookSaveAfter.callAsync(h,l=>{const a=e||l;a?y(a):_({content:h,...C,rotation:g})})};this.editor.hooksEntity.hookSaveBefore.callAsync("",h=>{if(h){y(h);return}try{C=this.getPrintExportSize(g),this.canvas.setViewportTransform([1,0,0,1,0,0]);const{fontOption:e,svgOption:l}=this._getSaveSvgOption({ignoreFont:!0,width:r?.width,height:r?.height});mt.fabric.fontPaths={...e};const a=this.rotateSVG(this.canvas.toSVG(l),g);b(a)}catch(e){b("",e)}})})}getSVG(r){return this.exportSVG(r).then(g=>g.content)}async getSVGResult(r){return this.exportSVG(r)}preview(){return new Promise(r=>{this.editor.hooksEntity.hookSaveBefore.callAsync("",()=>{const g=this._getSaveOption();this.canvas.setViewportTransform([1,0,0,1,0,0]),this.canvas.renderAll();const _=this.canvas.toDataURL(g);this.editor.hooksEntity.hookSaveAfter.callAsync(_,()=>{r(_)})})})}staticPreview(){return new Promise(r=>{})}_getSaveSvgOption(r){const g=this.canvas.getObjects().find(a=>a.id==="workspace");let _=this.canvas.getObjects().filter(a=>a.type=="textbox").map(a=>a.fontFamily);_=Array.from(new Set(_));const y=this.editor.getPlugin("FontPlugin").cacheList,C={};if(!r?.ignoreFont)for(const a of _){const t=y.find(n=>n.name===a);C[a]=t.file}console.log("_getSaveSvgOption",C);const{left:b,top:h,width:e,height:l}=g;return{fontOption:C,svgOption:{width:r?.width??e,height:r?.height??l,viewBox:{x:b,y:h,width:e,height:l}}}}_getSaveOption(){const r=this.canvas.getObjects().find(h=>h.id==="workspace"),{left:g,top:_,width:y,height:C}=r;return{name:"New Image",format:"jpeg",quality:1,multiplier:5,width:y,height:C,left:g,top:_}}normalizePrintRotation(r){return[0,90,180,270].includes(Number(r))?Number(r):0}getPrintExportSize(r){const g=this.canvas.getObjects().find(b=>b.id==="workspace"),_=this.editor.getSizeByUnit,y=g?_?_.call(this.editor,g.width||0):g.width||0:0,C=g?_?_.call(this.editor,g.height||0):g.height||0:0;return r===90||r===270?{width:C,height:y}:{width:y,height:C}}rotateBase64(r,g){const _=this.normalizePrintRotation(g);return _?typeof Image>"u"?Promise.reject(new Error("无法读取导出图片")):new Promise((y,C)=>{const b=new Image;b.onload=()=>{try{const h=document.createElement("canvas"),e=_===90||_===270;h.width=e?b.height:b.width,h.height=e?b.width:b.height;const l=h.getContext("2d");if(!l){C(new Error("无法创建旋转画布"));return}_===90?l.translate(h.width,0):_===180?l.translate(h.width,h.height):_===270&&l.translate(0,h.height),l.rotate(_*Math.PI/180),l.drawImage(b,0,0);const a=/^data:([^;,]+)/i.exec(r)?.[1];y(h.toDataURL(a||"image/jpeg",1))}catch(h){C(h)}},b.onerror=()=>C(new Error("无法读取导出图片")),b.src=r}):Promise.resolve(r)}rotateSVG(r,g){const _=this.normalizePrintRotation(g);if(!_)return r;if(typeof DOMParser>"u")throw new Error("无法解析旋转 SVG");const y=new DOMParser().parseFromString(r,"image/svg+xml"),C=y.documentElement;if(!C||C.nodeName==="parsererror")throw new Error("旋转 SVG 内容无效");const b=String(C.getAttribute("viewBox")||"").trim().split(/[\s,]+/).map(Number);if(b.length!==4||b.some(s=>!Number.isFinite(s)))throw new Error("旋转 SVG 的 viewBox 无效");const[h,e,l,a]=b,t=C.getAttribute("width"),n=C.getAttribute("height"),o={90:`translate(${a} 0) rotate(90) translate(${-h} ${-e})`,180:`translate(${l} ${a}) rotate(180) translate(${-h} ${-e})`,270:`translate(0 ${l}) rotate(270) translate(${-h} ${-e})`}[_],c=y.createElementNS("http://www.w3.org/2000/svg","g");return c.setAttribute("transform",o),Array.from(C.childNodes).forEach(s=>{s.nodeType===1&&["defs","style","desc","title","metadata"].includes(s.localName)||c.appendChild(s)}),C.appendChild(c),_===90||_===270?(C.setAttribute("viewBox",`0 0 ${a} ${l}`),n&&C.setAttribute("width",n),t&&C.setAttribute("height",t)):C.setAttribute("viewBox",`0 0 ${l} ${a}`),new XMLSerializer().serializeToString(C)}clear(){this.canvas.getObjects().forEach(r=>{r.id!=="workspace"&&this.canvas.remove(r)}),this.editor?.setWorkspaseBg("#fff"),this.canvas.discardActiveObject(),this.canvas.renderAll()}destroy(){console.log("pluginDestroy")}};ge.pluginName="ServersPlugin",ge.apis=["insert","loadJSON","getJson","dragAddItem","clipboard","clipboardBase64","saveJson","saveSvg","saveImg","getBase64","getBase64Result","getSVG","getSVGResult","clear","preview","staticPreview","getSelectMode","getExtensionKey"],ge.events=[te.ONE,te.MULTI,ue.CANCEL];let Ai=ge;var bt={},ai={},rn;function gr(){return rn||(rn=1,ai.deprecate=(f,r)=>{let g=!0;return function(){return g&&(console.warn(`DeprecationWarning: ${r}`),g=!1),f.apply(this,arguments)}}),ai}var li,sn;function Mt(){if(sn)return li;sn=1;const r=gr().deprecate(()=>{},"Hook.context is deprecated and will be removed");function g(...b){return this.call=this._createCall("sync"),this.call(...b)}function _(...b){return this.callAsync=this._createCall("async"),this.callAsync(...b)}function y(...b){return this.promise=this._createCall("promise"),this.promise(...b)}class C{constructor(h=[],e=void 0){this._args=h,this.name=e,this.taps=[],this.interceptors=[],this._call=g,this.call=g,this._callAsync=_,this.callAsync=_,this._promise=y,this.promise=y,this._x=void 0,this.compile=this.compile,this.tap=this.tap,this.tapAsync=this.tapAsync,this.tapPromise=this.tapPromise}compile(h){throw new Error("Abstract: should be overridden")}_createCall(h){return this.compile({taps:this.taps,interceptors:this.interceptors,args:this._args,type:h})}_tap(h,e,l){if(typeof e=="string")e={name:e.trim()};else if(typeof e!="object"||e===null)throw new Error("Invalid tap options");if(typeof e.name!="string"||e.name==="")throw new Error("Missing name for tap");typeof e.context<"u"&&r(),e=Object.assign({type:h,fn:l},e),e=this._runRegisterInterceptors(e),this._insert(e)}tap(h,e){this._tap("sync",h,e)}tapAsync(h,e){this._tap("async",h,e)}tapPromise(h,e){this._tap("promise",h,e)}_runRegisterInterceptors(h){for(const e of this.interceptors)if(e.register){const l=e.register(h);l!==void 0&&(h=l)}return h}withOptions(h){const e=l=>Object.assign({},h,typeof l=="string"?{name:l}:l);return{name:this.name,tap:(l,a)=>this.tap(e(l),a),tapAsync:(l,a)=>this.tapAsync(e(l),a),tapPromise:(l,a)=>this.tapPromise(e(l),a),intercept:l=>this.intercept(l),isUsed:()=>this.isUsed(),withOptions:l=>this.withOptions(e(l))}}isUsed(){return this.taps.length>0||this.interceptors.length>0}intercept(h){if(this._resetCompilation(),this.interceptors.push(Object.assign({},h)),h.register)for(let e=0;e<this.taps.length;e++)this.taps[e]=h.register(this.taps[e])}_resetCompilation(){this.call=this._call,this.callAsync=this._callAsync,this.promise=this._promise}_insert(h){this._resetCompilation();let e;typeof h.before=="string"?e=new Set([h.before]):Array.isArray(h.before)&&(e=new Set(h.before));let l=0;typeof h.stage=="number"&&(l=h.stage);let a=this.taps.length;for(;a>0;){a--;const t=this.taps[a];this.taps[a+1]=t;const n=t.stage||0;if(e){if(e.has(t.name)){e.delete(t.name);continue}if(e.size>0)continue}if(!(n>l)){a++;break}}this.taps[a]=h}}return Object.setPrototypeOf(C.prototype,null),li=C,li}var hi,on;function Lt(){if(on)return hi;on=1;class f{constructor(g){this.config=g,this.options=void 0,this._args=void 0}create(g){this.init(g);let _;switch(this.options.type){case"sync":_=new Function(this.args(),`"use strict";
|
|
442
442
|
${this.header()}${this.contentWithInterceptors({onError:y=>`throw ${y};
|
|
443
443
|
`,onResult:y=>`return ${y};
|
|
444
444
|
`,resultReturns:!0,onDone:()=>"",rethrowIfPossible:!0})}`);break;case"async":_=new Function(this.args({after:"_callback"}),`"use strict";
|
package/dist/index.mjs
CHANGED
|
@@ -20995,67 +20995,94 @@ const ge = class ge {
|
|
|
20995
20995
|
});
|
|
20996
20996
|
});
|
|
20997
20997
|
}
|
|
20998
|
-
|
|
20999
|
-
|
|
21000
|
-
|
|
21001
|
-
|
|
21002
|
-
|
|
21003
|
-
|
|
21004
|
-
|
|
21005
|
-
(
|
|
21006
|
-
|
|
21007
|
-
|
|
21008
|
-
() => g(C)
|
|
21009
|
-
);
|
|
21010
|
-
},
|
|
21011
|
-
() => {
|
|
21012
|
-
this.editor.hooksEntity.hookSaveAfter.callAsync(
|
|
21013
|
-
y,
|
|
21014
|
-
() => g(y)
|
|
21015
|
-
);
|
|
20998
|
+
exportBase64(r) {
|
|
20999
|
+
const g = this.normalizePrintRotation(r?.rotation);
|
|
21000
|
+
return new Promise((_, y) => {
|
|
21001
|
+
let C = { width: 0, height: 0 };
|
|
21002
|
+
const b = (h, e) => {
|
|
21003
|
+
this.editor.hooksEntity.hookSaveAfter.callAsync(
|
|
21004
|
+
h,
|
|
21005
|
+
(l) => {
|
|
21006
|
+
const a = e || l;
|
|
21007
|
+
a ? y(a) : _({ content: h, ...C, rotation: g });
|
|
21016
21008
|
}
|
|
21017
21009
|
);
|
|
21018
|
-
}
|
|
21010
|
+
};
|
|
21011
|
+
this.editor.hooksEntity.hookSaveBefore.callAsync(
|
|
21012
|
+
"",
|
|
21013
|
+
(h) => {
|
|
21014
|
+
if (h) {
|
|
21015
|
+
y(h);
|
|
21016
|
+
return;
|
|
21017
|
+
}
|
|
21018
|
+
try {
|
|
21019
|
+
const e = this._getSaveOption();
|
|
21020
|
+
C = this.getPrintExportSize(g), this.canvas.setViewportTransform([1, 0, 0, 1, 0, 0]);
|
|
21021
|
+
const l = this.canvas.toDataURL(e);
|
|
21022
|
+
this.rotateBase64(l, g).then(
|
|
21023
|
+
(a) => b(a),
|
|
21024
|
+
(a) => b(l, a)
|
|
21025
|
+
);
|
|
21026
|
+
} catch (e) {
|
|
21027
|
+
b("", e);
|
|
21028
|
+
}
|
|
21029
|
+
}
|
|
21030
|
+
);
|
|
21019
21031
|
});
|
|
21020
21032
|
}
|
|
21033
|
+
getBase64(r) {
|
|
21034
|
+
return this.exportBase64(r).then((g) => g.content);
|
|
21035
|
+
}
|
|
21021
21036
|
async getBase64Result(r) {
|
|
21022
|
-
|
|
21023
|
-
return {
|
|
21024
|
-
content: await this.getBase64({ rotation: g }),
|
|
21025
|
-
...this.getPrintExportSize(g),
|
|
21026
|
-
rotation: g
|
|
21027
|
-
};
|
|
21037
|
+
return this.exportBase64(r);
|
|
21028
21038
|
}
|
|
21029
|
-
|
|
21030
|
-
|
|
21031
|
-
|
|
21032
|
-
|
|
21033
|
-
|
|
21034
|
-
ignoreFont: !0,
|
|
21035
|
-
width: r?.width,
|
|
21036
|
-
height: r?.height
|
|
21037
|
-
});
|
|
21038
|
-
mt.fabric.fontPaths = {
|
|
21039
|
-
..._
|
|
21040
|
-
};
|
|
21041
|
-
const C = this.rotateSVG(
|
|
21042
|
-
this.canvas.toSVG(y),
|
|
21043
|
-
r?.rotation
|
|
21044
|
-
);
|
|
21039
|
+
exportSVG(r) {
|
|
21040
|
+
const g = this.normalizePrintRotation(r?.rotation);
|
|
21041
|
+
return new Promise((_, y) => {
|
|
21042
|
+
let C = { width: 0, height: 0 };
|
|
21043
|
+
const b = (h, e) => {
|
|
21045
21044
|
this.editor.hooksEntity.hookSaveAfter.callAsync(
|
|
21046
|
-
|
|
21047
|
-
() =>
|
|
21045
|
+
h,
|
|
21046
|
+
(l) => {
|
|
21047
|
+
const a = e || l;
|
|
21048
|
+
a ? y(a) : _({ content: h, ...C, rotation: g });
|
|
21049
|
+
}
|
|
21048
21050
|
);
|
|
21049
|
-
}
|
|
21051
|
+
};
|
|
21052
|
+
this.editor.hooksEntity.hookSaveBefore.callAsync(
|
|
21053
|
+
"",
|
|
21054
|
+
(h) => {
|
|
21055
|
+
if (h) {
|
|
21056
|
+
y(h);
|
|
21057
|
+
return;
|
|
21058
|
+
}
|
|
21059
|
+
try {
|
|
21060
|
+
C = this.getPrintExportSize(g), this.canvas.setViewportTransform([1, 0, 0, 1, 0, 0]);
|
|
21061
|
+
const { fontOption: e, svgOption: l } = this._getSaveSvgOption({
|
|
21062
|
+
ignoreFont: !0,
|
|
21063
|
+
width: r?.width,
|
|
21064
|
+
height: r?.height
|
|
21065
|
+
});
|
|
21066
|
+
mt.fabric.fontPaths = {
|
|
21067
|
+
...e
|
|
21068
|
+
};
|
|
21069
|
+
const a = this.rotateSVG(
|
|
21070
|
+
this.canvas.toSVG(l),
|
|
21071
|
+
g
|
|
21072
|
+
);
|
|
21073
|
+
b(a);
|
|
21074
|
+
} catch (e) {
|
|
21075
|
+
b("", e);
|
|
21076
|
+
}
|
|
21077
|
+
}
|
|
21078
|
+
);
|
|
21050
21079
|
});
|
|
21051
21080
|
}
|
|
21081
|
+
getSVG(r) {
|
|
21082
|
+
return this.exportSVG(r).then((g) => g.content);
|
|
21083
|
+
}
|
|
21052
21084
|
async getSVGResult(r) {
|
|
21053
|
-
|
|
21054
|
-
return {
|
|
21055
|
-
content: await this.getSVG({ ...r, rotation: g }),
|
|
21056
|
-
...this.getPrintExportSize(g),
|
|
21057
|
-
rotation: g
|
|
21058
|
-
};
|
|
21085
|
+
return this.exportSVG(r);
|
|
21059
21086
|
}
|
|
21060
21087
|
preview() {
|
|
21061
21088
|
return new Promise((r) => {
|
|
@@ -21121,30 +21148,37 @@ const ge = class ge {
|
|
|
21121
21148
|
}
|
|
21122
21149
|
rotateBase64(r, g) {
|
|
21123
21150
|
const _ = this.normalizePrintRotation(g);
|
|
21124
|
-
return
|
|
21151
|
+
return _ ? typeof Image > "u" ? Promise.reject(new Error("无法读取导出图片")) : new Promise((y, C) => {
|
|
21125
21152
|
const b = new Image();
|
|
21126
21153
|
b.onload = () => {
|
|
21127
|
-
|
|
21128
|
-
|
|
21129
|
-
|
|
21130
|
-
|
|
21131
|
-
|
|
21132
|
-
|
|
21154
|
+
try {
|
|
21155
|
+
const h = document.createElement("canvas"), e = _ === 90 || _ === 270;
|
|
21156
|
+
h.width = e ? b.height : b.width, h.height = e ? b.width : b.height;
|
|
21157
|
+
const l = h.getContext("2d");
|
|
21158
|
+
if (!l) {
|
|
21159
|
+
C(new Error("无法创建旋转画布"));
|
|
21160
|
+
return;
|
|
21161
|
+
}
|
|
21162
|
+
_ === 90 ? l.translate(h.width, 0) : _ === 180 ? l.translate(h.width, h.height) : _ === 270 && l.translate(0, h.height), l.rotate(_ * Math.PI / 180), l.drawImage(b, 0, 0);
|
|
21163
|
+
const a = /^data:([^;,]+)/i.exec(r)?.[1];
|
|
21164
|
+
y(h.toDataURL(a || "image/jpeg", 1));
|
|
21165
|
+
} catch (h) {
|
|
21166
|
+
C(h);
|
|
21133
21167
|
}
|
|
21134
|
-
_ === 90 ? l.translate(h.width, 0) : _ === 180 ? l.translate(h.width, h.height) : _ === 270 && l.translate(0, h.height), l.rotate(_ * Math.PI / 180), l.drawImage(b, 0, 0);
|
|
21135
|
-
const a = /^data:([^;,]+)/i.exec(r)?.[1];
|
|
21136
|
-
y(h.toDataURL(a || "image/jpeg", 1));
|
|
21137
21168
|
}, b.onerror = () => C(new Error("无法读取导出图片")), b.src = r;
|
|
21138
|
-
});
|
|
21169
|
+
}) : Promise.resolve(r);
|
|
21139
21170
|
}
|
|
21140
21171
|
rotateSVG(r, g) {
|
|
21141
21172
|
const _ = this.normalizePrintRotation(g);
|
|
21142
|
-
if (!_
|
|
21173
|
+
if (!_) return r;
|
|
21174
|
+
if (typeof DOMParser > "u")
|
|
21175
|
+
throw new Error("无法解析旋转 SVG");
|
|
21143
21176
|
const y = new DOMParser().parseFromString(r, "image/svg+xml"), C = y.documentElement;
|
|
21144
|
-
if (!C || C.nodeName === "parsererror")
|
|
21177
|
+
if (!C || C.nodeName === "parsererror")
|
|
21178
|
+
throw new Error("旋转 SVG 内容无效");
|
|
21145
21179
|
const b = String(C.getAttribute("viewBox") || "").trim().split(/[\s,]+/).map(Number);
|
|
21146
21180
|
if (b.length !== 4 || b.some((s) => !Number.isFinite(s)))
|
|
21147
|
-
|
|
21181
|
+
throw new Error("旋转 SVG 的 viewBox 无效");
|
|
21148
21182
|
const [h, e, l, a] = b, t = C.getAttribute("width"), n = C.getAttribute("height"), o = {
|
|
21149
21183
|
90: `translate(${a} 0) rotate(90) translate(${-h} ${-e})`,
|
|
21150
21184
|
180: `translate(${l} ${a}) rotate(180) translate(${-h} ${-e})`,
|
|
@@ -21153,10 +21187,7 @@ const ge = class ge {
|
|
|
21153
21187
|
"http://www.w3.org/2000/svg",
|
|
21154
21188
|
"g"
|
|
21155
21189
|
);
|
|
21156
|
-
return c.setAttribute(
|
|
21157
|
-
"transform",
|
|
21158
|
-
o
|
|
21159
|
-
), Array.from(C.childNodes).forEach((s) => {
|
|
21190
|
+
return c.setAttribute("transform", o), Array.from(C.childNodes).forEach((s) => {
|
|
21160
21191
|
s.nodeType === 1 && ["defs", "style", "desc", "title", "metadata"].includes(
|
|
21161
21192
|
s.localName
|
|
21162
21193
|
) || c.appendChild(s);
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@hprint/core",
|
|
3
|
-
"version": "0.0.11-alpha.
|
|
3
|
+
"version": "0.0.11-alpha.7",
|
|
4
4
|
"description": "",
|
|
5
5
|
"main": "./dist/index.js",
|
|
6
6
|
"module": "./dist/index.mjs",
|
|
@@ -33,7 +33,7 @@
|
|
|
33
33
|
"hotkeys-js": "~3.8.9",
|
|
34
34
|
"tapable": "~2.3.0",
|
|
35
35
|
"uuid": "~8.3.2",
|
|
36
|
-
"@hprint/shared": "0.0.11-alpha.
|
|
36
|
+
"@hprint/shared": "0.0.11-alpha.7"
|
|
37
37
|
},
|
|
38
38
|
"scripts": {
|
|
39
39
|
"build": "vite build",
|
package/src/ServersPlugin.ts
CHANGED
|
@@ -334,74 +334,109 @@ class ServersPlugin implements IPluginTempl {
|
|
|
334
334
|
});
|
|
335
335
|
}
|
|
336
336
|
|
|
337
|
-
|
|
338
|
-
|
|
339
|
-
|
|
340
|
-
|
|
341
|
-
|
|
342
|
-
|
|
343
|
-
|
|
344
|
-
(
|
|
345
|
-
|
|
346
|
-
|
|
347
|
-
|
|
348
|
-
);
|
|
349
|
-
},
|
|
350
|
-
() => {
|
|
351
|
-
this.editor.hooksEntity.hookSaveAfter.callAsync(
|
|
352
|
-
dataUrl,
|
|
353
|
-
() => resolve(dataUrl)
|
|
354
|
-
);
|
|
337
|
+
private exportBase64(options?: PrintExportOptions) {
|
|
338
|
+
const rotation = this.normalizePrintRotation(options?.rotation);
|
|
339
|
+
return new Promise<PrintExportResult>((resolve, reject) => {
|
|
340
|
+
let size = { width: 0, height: 0 };
|
|
341
|
+
const finish = (content: string, error?: unknown) => {
|
|
342
|
+
this.editor.hooksEntity.hookSaveAfter.callAsync(
|
|
343
|
+
content,
|
|
344
|
+
(hookError?: unknown) => {
|
|
345
|
+
const failure = error || hookError;
|
|
346
|
+
if (failure) reject(failure);
|
|
347
|
+
else resolve({ content, ...size, rotation });
|
|
355
348
|
}
|
|
356
349
|
);
|
|
357
|
-
}
|
|
350
|
+
};
|
|
351
|
+
this.editor.hooksEntity.hookSaveBefore.callAsync(
|
|
352
|
+
'',
|
|
353
|
+
(error?: unknown) => {
|
|
354
|
+
if (error) {
|
|
355
|
+
reject(error);
|
|
356
|
+
return;
|
|
357
|
+
}
|
|
358
|
+
try {
|
|
359
|
+
const option = this._getSaveOption();
|
|
360
|
+
size = this.getPrintExportSize(rotation);
|
|
361
|
+
this.canvas.setViewportTransform([1, 0, 0, 1, 0, 0]);
|
|
362
|
+
const dataUrl = this.canvas.toDataURL(option);
|
|
363
|
+
void this.rotateBase64(dataUrl, rotation).then(
|
|
364
|
+
(content) => finish(content),
|
|
365
|
+
(error) => finish(dataUrl, error)
|
|
366
|
+
);
|
|
367
|
+
} catch (error) {
|
|
368
|
+
finish('', error);
|
|
369
|
+
}
|
|
370
|
+
}
|
|
371
|
+
);
|
|
358
372
|
});
|
|
359
373
|
}
|
|
360
374
|
|
|
375
|
+
getBase64(options?: PrintExportOptions) {
|
|
376
|
+
return this.exportBase64(options).then((result) => result.content);
|
|
377
|
+
}
|
|
378
|
+
|
|
361
379
|
async getBase64Result(
|
|
362
380
|
options?: PrintExportOptions
|
|
363
381
|
): Promise<PrintExportResult> {
|
|
364
|
-
|
|
365
|
-
return {
|
|
366
|
-
content: await this.getBase64({ rotation }),
|
|
367
|
-
...this.getPrintExportSize(rotation),
|
|
368
|
-
rotation,
|
|
369
|
-
};
|
|
382
|
+
return this.exportBase64(options);
|
|
370
383
|
}
|
|
371
384
|
|
|
372
|
-
|
|
373
|
-
|
|
374
|
-
|
|
375
|
-
|
|
376
|
-
|
|
377
|
-
|
|
378
|
-
|
|
379
|
-
|
|
380
|
-
|
|
381
|
-
|
|
382
|
-
|
|
383
|
-
|
|
384
|
-
const svg = this.rotateSVG(
|
|
385
|
-
this.canvas.toSVG(svgOption),
|
|
386
|
-
options?.rotation
|
|
387
|
-
);
|
|
388
|
-
// this._printSvgString(svg);
|
|
389
|
-
this.editor.hooksEntity.hookSaveAfter.callAsync(svg, () =>
|
|
390
|
-
resolve(svg)
|
|
385
|
+
private exportSVG(options?: PrintSVGExportOptions) {
|
|
386
|
+
const rotation = this.normalizePrintRotation(options?.rotation);
|
|
387
|
+
return new Promise<PrintExportResult>((resolve, reject) => {
|
|
388
|
+
let size = { width: 0, height: 0 };
|
|
389
|
+
const finish = (content: string, error?: unknown) => {
|
|
390
|
+
this.editor.hooksEntity.hookSaveAfter.callAsync(
|
|
391
|
+
content,
|
|
392
|
+
(hookError?: unknown) => {
|
|
393
|
+
const failure = error || hookError;
|
|
394
|
+
if (failure) reject(failure);
|
|
395
|
+
else resolve({ content, ...size, rotation });
|
|
396
|
+
}
|
|
391
397
|
);
|
|
392
|
-
}
|
|
398
|
+
};
|
|
399
|
+
this.editor.hooksEntity.hookSaveBefore.callAsync(
|
|
400
|
+
'',
|
|
401
|
+
(error?: unknown) => {
|
|
402
|
+
if (error) {
|
|
403
|
+
reject(error);
|
|
404
|
+
return;
|
|
405
|
+
}
|
|
406
|
+
try {
|
|
407
|
+
size = this.getPrintExportSize(rotation);
|
|
408
|
+
this.canvas.setViewportTransform([1, 0, 0, 1, 0, 0]);
|
|
409
|
+
const { fontOption, svgOption } =
|
|
410
|
+
this._getSaveSvgOption({
|
|
411
|
+
ignoreFont: true,
|
|
412
|
+
width: options?.width,
|
|
413
|
+
height: options?.height,
|
|
414
|
+
});
|
|
415
|
+
fabric.fontPaths = {
|
|
416
|
+
...fontOption,
|
|
417
|
+
};
|
|
418
|
+
const svg = this.rotateSVG(
|
|
419
|
+
this.canvas.toSVG(svgOption),
|
|
420
|
+
rotation
|
|
421
|
+
);
|
|
422
|
+
// this._printSvgString(svg);
|
|
423
|
+
finish(svg);
|
|
424
|
+
} catch (error) {
|
|
425
|
+
finish('', error);
|
|
426
|
+
}
|
|
427
|
+
}
|
|
428
|
+
);
|
|
393
429
|
});
|
|
394
430
|
}
|
|
395
431
|
|
|
432
|
+
getSVG(options?: PrintSVGExportOptions) {
|
|
433
|
+
return this.exportSVG(options).then((result) => result.content);
|
|
434
|
+
}
|
|
435
|
+
|
|
396
436
|
async getSVGResult(
|
|
397
437
|
options?: PrintSVGExportOptions
|
|
398
438
|
): Promise<PrintExportResult> {
|
|
399
|
-
|
|
400
|
-
return {
|
|
401
|
-
content: await this.getSVG({ ...options, rotation }),
|
|
402
|
-
...this.getPrintExportSize(rotation),
|
|
403
|
-
rotation,
|
|
404
|
-
};
|
|
439
|
+
return this.exportSVG(options);
|
|
405
440
|
}
|
|
406
441
|
|
|
407
442
|
preview() {
|
|
@@ -511,33 +546,39 @@ class ServersPlugin implements IPluginTempl {
|
|
|
511
546
|
|
|
512
547
|
private rotateBase64(dataUrl: string, rotation?: number) {
|
|
513
548
|
const normalizedRotation = this.normalizePrintRotation(rotation);
|
|
514
|
-
if (!normalizedRotation
|
|
549
|
+
if (!normalizedRotation) {
|
|
515
550
|
return Promise.resolve(dataUrl);
|
|
516
551
|
}
|
|
552
|
+
if (typeof Image === 'undefined')
|
|
553
|
+
return Promise.reject(new Error('无法读取导出图片'));
|
|
517
554
|
return new Promise<string>((resolve, reject) => {
|
|
518
555
|
const image = new Image();
|
|
519
556
|
image.onload = () => {
|
|
520
|
-
|
|
521
|
-
|
|
522
|
-
|
|
523
|
-
|
|
524
|
-
|
|
525
|
-
|
|
526
|
-
|
|
527
|
-
|
|
528
|
-
|
|
529
|
-
|
|
530
|
-
|
|
531
|
-
|
|
532
|
-
|
|
533
|
-
|
|
534
|
-
|
|
535
|
-
|
|
557
|
+
try {
|
|
558
|
+
const canvas = document.createElement('canvas');
|
|
559
|
+
const swapSize =
|
|
560
|
+
normalizedRotation === 90 || normalizedRotation === 270;
|
|
561
|
+
canvas.width = swapSize ? image.height : image.width;
|
|
562
|
+
canvas.height = swapSize ? image.width : image.height;
|
|
563
|
+
const context = canvas.getContext('2d');
|
|
564
|
+
if (!context) {
|
|
565
|
+
reject(new Error('无法创建旋转画布'));
|
|
566
|
+
return;
|
|
567
|
+
}
|
|
568
|
+
if (normalizedRotation === 90) {
|
|
569
|
+
context.translate(canvas.width, 0);
|
|
570
|
+
} else if (normalizedRotation === 180) {
|
|
571
|
+
context.translate(canvas.width, canvas.height);
|
|
572
|
+
} else if (normalizedRotation === 270) {
|
|
573
|
+
context.translate(0, canvas.height);
|
|
574
|
+
}
|
|
575
|
+
context.rotate((normalizedRotation * Math.PI) / 180);
|
|
576
|
+
context.drawImage(image, 0, 0);
|
|
577
|
+
const mimeType = /^data:([^;,]+)/i.exec(dataUrl)?.[1];
|
|
578
|
+
resolve(canvas.toDataURL(mimeType || 'image/jpeg', 1));
|
|
579
|
+
} catch (error) {
|
|
580
|
+
reject(error);
|
|
536
581
|
}
|
|
537
|
-
context.rotate((normalizedRotation * Math.PI) / 180);
|
|
538
|
-
context.drawImage(image, 0, 0);
|
|
539
|
-
const mimeType = /^data:([^;,]+)/i.exec(dataUrl)?.[1];
|
|
540
|
-
resolve(canvas.toDataURL(mimeType || 'image/jpeg', 1));
|
|
541
582
|
};
|
|
542
583
|
image.onerror = () => reject(new Error('无法读取导出图片'));
|
|
543
584
|
image.src = dataUrl;
|
|
@@ -546,16 +587,22 @@ class ServersPlugin implements IPluginTempl {
|
|
|
546
587
|
|
|
547
588
|
private rotateSVG(svg: string, rotation?: number) {
|
|
548
589
|
const normalizedRotation = this.normalizePrintRotation(rotation);
|
|
549
|
-
if (!normalizedRotation
|
|
590
|
+
if (!normalizedRotation) return svg;
|
|
591
|
+
if (typeof DOMParser === 'undefined')
|
|
592
|
+
throw new Error('无法解析旋转 SVG');
|
|
550
593
|
const document = new DOMParser().parseFromString(svg, 'image/svg+xml');
|
|
551
594
|
const root = document.documentElement;
|
|
552
|
-
if (!root || root.nodeName === 'parsererror')
|
|
595
|
+
if (!root || root.nodeName === 'parsererror')
|
|
596
|
+
throw new Error('旋转 SVG 内容无效');
|
|
553
597
|
const values = String(root.getAttribute('viewBox') || '')
|
|
554
598
|
.trim()
|
|
555
599
|
.split(/[\s,]+/)
|
|
556
600
|
.map(Number);
|
|
557
|
-
if (
|
|
558
|
-
|
|
601
|
+
if (
|
|
602
|
+
values.length !== 4 ||
|
|
603
|
+
values.some((value) => !Number.isFinite(value))
|
|
604
|
+
) {
|
|
605
|
+
throw new Error('旋转 SVG 的 viewBox 无效');
|
|
559
606
|
}
|
|
560
607
|
const [x, y, width, height] = values;
|
|
561
608
|
const originalWidth = root.getAttribute('width');
|
|
@@ -565,17 +612,13 @@ class ServersPlugin implements IPluginTempl {
|
|
|
565
612
|
180: `translate(${width} ${height}) rotate(180) translate(${-x} ${-y})`,
|
|
566
613
|
270: `translate(0 ${width}) rotate(270) translate(${-x} ${-y})`,
|
|
567
614
|
};
|
|
568
|
-
const transform =
|
|
569
|
-
normalizedRotation as Exclude<PrintRotation, 0>
|
|
570
|
-
];
|
|
615
|
+
const transform =
|
|
616
|
+
transforms[normalizedRotation as Exclude<PrintRotation, 0>];
|
|
571
617
|
const content = document.createElementNS(
|
|
572
618
|
'http://www.w3.org/2000/svg',
|
|
573
619
|
'g'
|
|
574
620
|
);
|
|
575
|
-
content.setAttribute(
|
|
576
|
-
'transform',
|
|
577
|
-
transform
|
|
578
|
-
);
|
|
621
|
+
content.setAttribute('transform', transform);
|
|
579
622
|
|
|
580
623
|
Array.from(root.childNodes).forEach((node) => {
|
|
581
624
|
if (
|