@hprint/core 0.0.1-alpha.3 → 0.0.1-alpha.4
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.map +1 -1
- package/dist/index.js +1 -1
- package/dist/index.mjs +2 -0
- package/package.json +2 -2
- package/src/ContextMenu.js +277 -277
- package/src/Instance.ts +79 -79
- package/src/ServersPlugin.ts +411 -409
- package/src/index.ts +11 -11
- package/src/interface/Editor.ts +58 -58
- package/src/objects/CustomRect.js +21 -21
- package/src/objects/CustomTextbox.js +165 -165
- package/src/plugin.ts +88 -88
- package/src/styles/contextMenu.css +60 -60
- package/src/utils/fabric-history.js +232 -232
- package/src/utils/utils.ts +165 -165
- package/tsconfig.json +10 -10
- package/vite.config.ts +29 -29
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ServersPlugin.d.ts","sourceRoot":"","sources":["../src/ServersPlugin.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,MAAM,EAAgB,MAAM,QAAQ,CAAC;AAC9C,OAAO,KAAK,EAAE,OAAO,EAAE,YAAY,EAAE,MAAM,cAAc,CAAC;AAC1D,OAAO,EAAE,WAAW,EAAE,UAAU,EAAE,MAAM,mCAAmC,CAAC;AAE5E,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,SAAS,GACT,OAAO,GACP,SAAS,GACT,eAAe,GACf,eAAe,GACf,iBAAiB,CACtB,CAAC;AAEF,OAAO,QAAQ,cAAc,CAAC;IAE1B,UAAU,OAAQ,SAAQ,OAAO;KAAI;CACxC;AAaD,cAAM,aAAc,YAAW,YAAY;IAuB5B,MAAM,EAAE,MAAM,CAAC,MAAM;IACrB,MAAM,EAAE,OAAO;IAvBnB,YAAY,EAAE,UAAU,CAAC;IAChC,MAAM,CAAC,UAAU,SAAmB;IACpC,MAAM,CAAC,IAAI,WAgBT;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;QACd,QAAQ,CAAC,EAAE,OAAO,CAAA;KACrB;;;;IAaD,eAAe;
|
|
1
|
+
{"version":3,"file":"ServersPlugin.d.ts","sourceRoot":"","sources":["../src/ServersPlugin.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,MAAM,EAAgB,MAAM,QAAQ,CAAC;AAC9C,OAAO,KAAK,EAAE,OAAO,EAAE,YAAY,EAAE,MAAM,cAAc,CAAC;AAC1D,OAAO,EAAE,WAAW,EAAE,UAAU,EAAE,MAAM,mCAAmC,CAAC;AAE5E,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,SAAS,GACT,OAAO,GACP,SAAS,GACT,eAAe,GACf,eAAe,GACf,iBAAiB,CACtB,CAAC;AAEF,OAAO,QAAQ,cAAc,CAAC;IAE1B,UAAU,OAAQ,SAAQ,OAAO;KAAI;CACxC;AAaD,cAAM,aAAc,YAAW,YAAY;IAuB5B,MAAM,EAAE,MAAM,CAAC,MAAM;IACrB,MAAM,EAAE,OAAO;IAvBnB,YAAY,EAAE,UAAU,CAAC;IAChC,MAAM,CAAC,UAAU,SAAmB;IACpC,MAAM,CAAC,IAAI,WAgBT;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;QACd,QAAQ,CAAC,EAAE,OAAO,CAAA;KACrB;;;;IAaD,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;IAaT,OAAO;IAcP,aAAa;IAIb,iBAAiB;;;;;;;;;;;;;IAmCjB,cAAc;;;;;;;;;;IAkBd,KAAK;IAWL,OAAO;CAGV;AAED,eAAe,aAAa,CAAC"}
|
package/dist/index.js
CHANGED
|
@@ -438,7 +438,7 @@ gl_FragColor.rgb *= color.a;
|
|
|
438
438
|
`?(e++,n[e]=0):n[e]++;n[0]>0&&(this.insertCharStyleObject(t.lineIndex,t.charIndex,n[0],a),a=a&&a.slice(n[0]+1)),e&&this.insertNewlineStyleObject(t.lineIndex,t.charIndex+n[0],e);for(var o=1;o<e;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(i,l,a){a<=i?(l===i?this._selectionDirection="left":this._selectionDirection==="right"&&(this._selectionDirection="left",this.selectionEnd=i),this.selectionStart=a):a>i&&a<l?this._selectionDirection==="right"?this.selectionEnd=a:this.selectionStart=a:(l===i?this._selectionDirection="right":this._selectionDirection==="left"&&(this._selectionDirection="right",this.selectionStart=l),this.selectionEnd=a)},setSelectionInBoundaries:function(){var i=this.text.length;this.selectionStart>i?this.selectionStart=i:this.selectionStart<0&&(this.selectionStart=0),this.selectionEnd>i?this.selectionEnd=i: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(c){if(this.canvas){this.__newClickTime=+new Date;var i=c.pointer;this.isTripleClick(i)&&(this.fire("tripleclick",c),this._stopEvent(c.e)),this.__lastLastClickTime=this.__lastClickTime,this.__lastClickTime=this.__newClickTime,this.__lastPointer=i,this.__lastIsEditing=this.isEditing,this.__lastSelected=this.selected}},isTripleClick:function(c){return this.__newClickTime-this.__lastClickTime<500&&this.__lastClickTime-this.__lastLastClickTime<500&&this.__lastPointer.x===c.x&&this.__lastPointer.y===c.y},_stopEvent:function(c){c.preventDefault&&c.preventDefault(),c.stopPropagation&&c.stopPropagation()},initCursorSelectionHandlers:function(){this.initMousedownHandler(),this.initMouseupHandler(),this.initClicks()},doubleClickHandler:function(c){this.isEditing&&this.selectWord(this.getSelectionStartFromPointer(c.e))},tripleClickHandler:function(c){this.isEditing&&this.selectLine(this.getSelectionStartFromPointer(c.e))},initClicks:function(){this.on("mousedblclick",this.doubleClickHandler),this.on("tripleclick",this.tripleClickHandler)},_mouseDownHandler:function(c){!this.canvas||!this.editable||c.e.button&&c.e.button!==1||(this.__isMousedown=!0,this.selected&&(this.inCompositionMode=!1,this.setCursorByClick(c.e)),this.isEditing&&(this.__selectionStartOnMouseDown=this.selectionStart,this.selectionStart===this.selectionEnd&&this.abortCursorAnimation(),this.renderCursorOrSelection()))},_mouseDownHandlerBefore:function(c){!this.canvas||!this.editable||c.e.button&&c.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(c){if(this.__isMousedown=!1,!(!this.editable||this.group||c.transform&&c.transform.actionPerformed||c.e.button&&c.e.button!==1)){if(this.canvas){var i=this.canvas._activeObject;if(i&&i!==this)return}this.__lastSelected&&!this.__corner?(this.selected=!1,this.__lastSelected=!1,this.enterEditing(c.e),this.selectionStart===this.selectionEnd?this.initDelayedCursor(!0):this.renderCursorOrSelection()):this.selected=!0}},setCursorByClick:function(c){var i=this.getSelectionStartFromPointer(c),l=this.selectionStart,a=this.selectionEnd;c.shiftKey?this.setSelectionStartEndWithShift(l,a,i):(this.selectionStart=i,this.selectionEnd=i),this.isEditing&&(this._fireSelectionChanged(),this._updateTextarea())},getSelectionStartFromPointer:function(c){for(var i=this.getLocalPointer(c),l=0,a=0,t=0,n=0,e=0,o,h,s=0,u=this._textLines.length;s<u&&t<=i.y;s++)t+=this.getHeightOfLine(s)*this.scaleY,e=s,s>0&&(n+=this._textLines[s-1].length+this.missingNewlineOffset(s-1));o=this._getLineLeftOffset(e),a=o*this.scaleX,h=this._textLines[e],this.direction==="rtl"&&(i.x=this.width*this.scaleX-i.x+a);for(var d=0,m=h.length;d<m&&(l=a,a+=this.__charBounds[e][d].kernedWidth*this.scaleX,a<=i.x);d++)n++;return this._getNewSelectionStartFromOffset(i,l,a,n,m)},_getNewSelectionStartFromOffset:function(c,i,l,a,t){var n=c.x-i,e=l-c.x,o=e>n||e<0?0:1,h=a+o;return this.flipX&&(h=t-h),h>this._text.length&&(h=this._text.length),h}}),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 c=this._calcTextareaPosition();this.hiddenTextarea.style.cssText="position: absolute; top: "+c.top+"; left: "+c.left+"; z-index: -999; opacity: 0; width: 1px; height: 1px; font-size: 1px; padding-top: "+c.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(c){if(this.isEditing){var i=this.direction==="rtl"?this.keysMapRtl:this.keysMap;if(c.keyCode in i)this[i[c.keyCode]](c);else if(c.keyCode in this.ctrlKeysMapDown&&(c.ctrlKey||c.metaKey))this[this.ctrlKeysMapDown[c.keyCode]](c);else return;c.stopImmediatePropagation(),c.preventDefault(),c.keyCode>=33&&c.keyCode<=40?(this.inCompositionMode=!1,this.clearContextTop(),this.renderCursorOrSelection()):this.canvas&&this.canvas.requestRenderAll()}},onKeyUp:function(c){if(!this.isEditing||this._copyDone||this.inCompositionMode){this._copyDone=!1;return}if(c.keyCode in this.ctrlKeysMapUp&&(c.ctrlKey||c.metaKey))this[this.ctrlKeysMapUp[c.keyCode]](c);else return;c.stopImmediatePropagation(),c.preventDefault(),this.canvas&&this.canvas.requestRenderAll()},onInput:function(c){var i=this.fromPaste;if(this.fromPaste=!1,c&&c.stopPropagation(),!!this.isEditing){var l=this._splitTextIntoLines(this.hiddenTextarea.value).graphemeText,a=this._text.length,t=l.length,n,e,o=t-a,h=this.selectionStart,s=this.selectionEnd,u=h!==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),b=h>v.selectionStart;u?(n=this._text.slice(h,s),o+=s-h):t<a&&(b?n=this._text.slice(s+o,s):n=this._text.slice(h,h-o)),e=l.slice(v.selectionEnd-o,v.selectionEnd),n&&n.length&&(e.length&&(d=this.getSelectionStyles(h,h+1,!1),d=e.map(function(){return d[0]})),u?(m=h,p=s):b?(m=s-n.length,p=s):(m=s,p=s+n.length),this.removeStyleFromTo(m,p)),e.length&&(i&&e.join("")===r.copiedText&&!r.disableStyleCopyPaste&&(d=r.copiedTextStyle),this.insertNewStyleBlock(e,h,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(c){this.compositionStart=c.target.selectionStart,this.compositionEnd=c.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(c){return c&&c.clipboardData||r.window.clipboardData},_getWidthBeforeCursor:function(c,i){var l=this._getLineLeftOffset(c),a;return i>0&&(a=this.__charBounds[c][i-1],l+=a.left+a.width),l},getDownCursorOffset:function(c,i){var l=this._getSelectionForOffset(c,i),a=this.get2DCursorLocation(l),t=a.lineIndex;if(t===this._textLines.length-1||c.metaKey||c.keyCode===34)return this._text.length-l;var n=a.charIndex,e=this._getWidthBeforeCursor(t,n),o=this._getIndexOnLine(t+1,e),h=this._textLines[t].slice(n);return h.length+o+1+this.missingNewlineOffset(t)},_getSelectionForOffset:function(c,i){return c.shiftKey&&this.selectionStart!==this.selectionEnd&&i?this.selectionEnd:this.selectionStart},getUpCursorOffset:function(c,i){var l=this._getSelectionForOffset(c,i),a=this.get2DCursorLocation(l),t=a.lineIndex;if(t===0||c.metaKey||c.keyCode===33)return-l;var n=a.charIndex,e=this._getWidthBeforeCursor(t,n),o=this._getIndexOnLine(t-1,e),h=this._textLines[t].slice(0,n),s=this.missingNewlineOffset(t-1);return-this._textLines[t-1].length+o-h.length+(1-s)},_getIndexOnLine:function(c,i){for(var l=this._textLines[c],a=this._getLineLeftOffset(c),t=a,n=0,e,o,h=0,s=l.length;h<s;h++)if(e=this.__charBounds[c][h].width,t+=e,t>i){o=!0;var u=t-e,d=t,m=Math.abs(u-i),p=Math.abs(d-i);n=p<m?h:h-1;break}return o||(n=l.length-1),n},moveCursorDown:function(c){this.selectionStart>=this._text.length&&this.selectionEnd>=this._text.length||this._moveCursorUpOrDown("Down",c)},moveCursorUp:function(c){this.selectionStart===0&&this.selectionEnd===0||this._moveCursorUpOrDown("Up",c)},_moveCursorUpOrDown:function(c,i){var l="get"+c+"CursorOffset",a=this[l](i,this._selectionDirection==="right");i.shiftKey?this.moveCursorWithShift(a):this.moveCursorWithoutShift(a),a!==0&&(this.setSelectionInBoundaries(),this.abortCursorAnimation(),this._currentCursorOpacity=1,this.initDelayedCursor(),this._fireSelectionChanged(),this._updateTextarea())},moveCursorWithShift:function(c){var i=this._selectionDirection==="left"?this.selectionStart+c:this.selectionEnd+c;return this.setSelectionStartEndWithShift(this.selectionStart,this.selectionEnd,i),c!==0},moveCursorWithoutShift:function(c){return c<0?(this.selectionStart+=c,this.selectionEnd=this.selectionStart):(this.selectionEnd+=c,this.selectionStart=this.selectionEnd),c!==0},moveCursorLeft:function(c){this.selectionStart===0&&this.selectionEnd===0||this._moveCursorLeftOrRight("Left",c)},_move:function(c,i,l){var a;if(c.altKey)a=this["findWordBoundary"+l](this[i]);else if(c.metaKey||c.keyCode===35||c.keyCode===36)a=this["findLineBoundary"+l](this[i]);else return this[i]+=l==="Left"?-1:1,!0;if(typeof a<"u"&&this[i]!==a)return this[i]=a,!0},_moveLeft:function(c,i){return this._move(c,i,"Left")},_moveRight:function(c,i){return this._move(c,i,"Right")},moveCursorLeftWithoutShift:function(c){var i=!0;return this._selectionDirection="left",this.selectionEnd===this.selectionStart&&this.selectionStart!==0&&(i=this._moveLeft(c,"selectionStart")),this.selectionEnd=this.selectionStart,i},moveCursorLeftWithShift:function(c){if(this._selectionDirection==="right"&&this.selectionStart!==this.selectionEnd)return this._moveLeft(c,"selectionEnd");if(this.selectionStart!==0)return this._selectionDirection="left",this._moveLeft(c,"selectionStart")},moveCursorRight:function(c){this.selectionStart>=this._text.length&&this.selectionEnd>=this._text.length||this._moveCursorLeftOrRight("Right",c)},_moveCursorLeftOrRight:function(c,i){var l="moveCursor"+c+"With";this._currentCursorOpacity=1,i.shiftKey?l+="Shift":l+="outShift",this[l](i)&&(this.abortCursorAnimation(),this.initDelayedCursor(),this._fireSelectionChanged(),this._updateTextarea())},moveCursorRightWithShift:function(c){if(this._selectionDirection==="left"&&this.selectionStart!==this.selectionEnd)return this._moveRight(c,"selectionStart");if(this.selectionEnd!==this._text.length)return this._selectionDirection="right",this._moveRight(c,"selectionEnd")},moveCursorRightWithoutShift:function(c){var i=!0;return this._selectionDirection="right",this.selectionStart===this.selectionEnd?(i=this._moveRight(c,"selectionStart"),this.selectionEnd=this.selectionStart):this.selectionStart=this.selectionEnd,i},removeChars:function(c,i){typeof i>"u"&&(i=c+1),this.removeStyleFromTo(c,i),this._text.splice(c,i-c),this.text=this._text.join(""),this.set("dirty",!0),this._shouldClearDimensionCache()&&(this.initDimensions(),this.setCoords()),this._removeExtraneousStyles()},insertChars:function(c,i,l,a){typeof a>"u"&&(a=l),a>l&&this.removeStyleFromTo(l,a);var t=r.util.string.graphemeSplit(c);this.insertNewStyleBlock(t,l,i),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 c=r.util.toFixed,i=/ +/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=[],e=l,o;this._setSVGBg(n);for(var h=0,s=this._textLines.length;h<s;h++)o=this._getLineLeftOffset(h),(this.textBackgroundColor||this.styleHas("textBackgroundColor",h))&&this._setSVGTextLineBg(n,h,a+o,e),this._setSVGTextLineText(t,h,a+o,e),e+=this.getHeightOfLine(h);return{textSpans:t,textBgRects:n}},_createTextCharSpan:function(l,a,t,n){var e=l!==l.trim()||l.match(i),o=this.getSvgSpanStyles(a,e),h=o?'style="'+o+'"':"",s=a.deltaY,u="",d=r.Object.NUM_FRACTION_DIGITS;return s&&(u=' dy="'+c(s,d)+'" '),['<tspan x="',c(t,d),'" y="',c(n,d),'" ',u,h,">",r.util.string.escapeXml(l),"</tspan>"].join("")},_setSVGTextLineText:function(l,a,t,n){var e=this.getHeightOfLine(a),o=this.textAlign.indexOf("justify")!==-1,h,s,u="",d,m,p=0,v=this._textLines[a],b;n+=e*(1-this._fontSizeFraction)/this.lineHeight;for(var S=0,E=v.length-1;S<=E;S++)b=S===E||this.charSpacing,u+=v[S],d=this.__charBounds[a][S],p===0?(t+=d.kernedWidth-d.width,p+=d.width):p+=d.kernedWidth,o&&!b&&this._reSpaceAndTab.test(v[S])&&(b=!0),b||(h=h||this.getCompleteStyleDeclaration(a,S),s=this.getCompleteStyleDeclaration(a,S+1),b=r.util.hasStyleChanged(h,s,!0)),b&&(m=this._getStyleDeclaration(a,S)||{},l.push(this._createTextCharSpan(u,m,t,n)),u="",h=s,t+=p,p=0)},_pushTextBgRect:function(l,a,t,n,e,o){var h=r.Object.NUM_FRACTION_DIGITS;l.push(" <rect ",this._getFillAttributes(a),' x="',c(t,h),'" y="',c(n,h),'" width="',c(e,h),'" height="',c(o,h),`"></rect>
|
|
440
440
|
`)},_setSVGTextLineBg:function(l,a,t,n){for(var e=this._textLines[a],o=this.getHeightOfLine(a)/this.lineHeight,h=0,s=0,u,d,m=this.getValueOfPropertyAt(a,0,"textBackgroundColor"),p=0,v=e.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,h,o),s=u.left,h=u.width,m=d):h+=u.kernedWidth;d&&this._pushTextBgRect(l,d,t+s,n,h,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(c){var i=c.fabric||(c.fabric={});i.Textbox=i.util.createClass(i.IText,i.Observable,{type:"textbox",minWidth:20,dynamicMinWidth:2,__cachedLines:null,lockScalingFlip:!0,noScaleCache:!1,_dimensionAffectingProps:i.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,e={},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++),e[o]={line:a,offset:t},n+=l.graphemeLines[o].length,t+=l.graphemeLines[o].length;return e},styleHas:function(l,a){if(this._styleMap&&!this.isWrapping){var t=this._styleMap[a];t&&(a=t.line)}return i.Text.prototype.styleHas.call(this,l,a)},isEmptyStyles:function(l){if(!this.styles)return!0;var a=0,t=l+1,n,e,o=!1,h=this._styleMap[l],s=this._styleMap[l+1];h&&(l=h.line,a=h.offset),s&&(t=s.line,o=t===l,n=s.offset),e=typeof l>"u"?this.styles:{line:this.styles[l]};for(var u in e)for(var d in e[u])if(d>=a&&(!o||d<n))for(var m in e[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,e,o=!0;t=t||0;for(var h=0,s=l.length;h<s;h++){var u=this._getGraphemeBox(l[h],a,h+t,e,o);n+=u.kernedWidth,e=l[h]}return n},_wrapLine:function(l,a,t,R){var e=0,o=this.splitByGrapheme,h=[],s=[],u=o?i.util.string.graphemeSplit(l):l.split(this._wordJoiners),d="",m=0,p=o?"":" ",v=0,b=0,S=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]:i.util.string.graphemeSplit(u[z]),v=this._measureWord(d,a,m),m+=d.length,e+=b+v-F,e>t&&!E?(h.push(s),s=[],e=v,E=!0):e+=F,!E&&!o&&s.push(p),s=s.concat(d),b=o?0:this._measureWord([p],a,m),m++,E=!1,v>S&&(S=v);return z&&h.push(s),S+R>this.dynamicMinWidth&&(this.dynamicMinWidth=S-F+R),h},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=i.Text.prototype._splitTextIntoLines.call(this,l),t=this._wrapText(a.lines,this.width),n=new Array(t.length),e=0;e<t.length;e++)n[e]=t[e].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))}}),i.Textbox.fromObject=function(l,a){var t=i.util.stylesFromArray(l.styles,l.text),n=Object.assign({},l,{styles:t});return i.Object._fromObject("Textbox",n,a,"text")}})(f),(function(){var c=r.controlsUtils,i=c.scaleSkewCursorStyleHandler,l=c.scaleCursorStyleHandler,a=c.scalingEqually,t=c.scalingYOrSkewingX,n=c.scalingXOrSkewingY,e=c.scaleOrSkewActionName,o=r.Object.prototype.controls;if(o.ml=new r.Control({x:-.5,y:0,cursorStyleHandler:i,actionHandler:n,getActionName:e}),o.mr=new r.Control({x:.5,y:0,cursorStyleHandler:i,actionHandler:n,getActionName:e}),o.mb=new r.Control({x:0,y:.5,cursorStyleHandler:i,actionHandler:t,getActionName:e}),o.mt=new r.Control({x:0,y:-.5,cursorStyleHandler:i,actionHandler:t,getActionName:e}),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:c.rotationWithSnapping,cursorStyleHandler:c.rotationStyleHandler,offsetY:-40,withConnection:!0,actionName:"rotate"}),r.Textbox){var h=r.Textbox.prototype.controls={};h.mtr=o.mtr,h.tr=o.tr,h.br=o.br,h.tl=o.tl,h.bl=o.bl,h.mt=o.mt,h.mb=o.mb,h.mr=new r.Control({x:.5,y:0,actionHandler:c.changeWidth,cursorStyleHandler:i,actionName:"resizing"}),h.ml=new r.Control({x:-.5,y:0,actionHandler:c.changeWidth,cursorStyleHandler:i,actionName:"resizing"})}})()})(si)),si}var _t=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 _t.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);_&&_t.fabric.Path.fromObject(g.path,y=>{_.set("path",y)})})}async loadJSON(r,g){const _=typeof r=="string"?JSON.parse(r):r,y=[];_.objects.forEach(T=>{!T.id&&(T.id=On()),T.type==="i-text"&&T.path&&(y.push({id:T.id,path:T.path}),T.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")})},(T,c)=>{this.editor.hooksEntity.hookTransformObjectEnd.callAsync({originObject:T,fabricObject:c},()=>{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"].includes(y.extensionType)&&(y.src="")}),_}getExtensionKey(){return["id","gradientAngle","selectable","hasControls","linkData","editable","extensionType","extension","verticalAlign","roundValue","getBase64","_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 T={x:g.x-y,y:g.y-C},c=this.canvas.restorePointerVpt(T);r.left=c.x-r.width/2,r.top=c.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();_t.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(){return new Promise(r=>{this.editor.hooksEntity.hookSaveBefore.callAsync("",()=>{const g=this._getSaveOption();this.canvas.setViewportTransform([1,0,0,1,0,0]);const _=this.canvas.toDataURL(g);this.editor.hooksEntity.hookSaveAfter.callAsync(_,()=>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(){const r=this.canvas.getObjects().find(l=>l.id==="workspace");let g=this.canvas.getObjects().filter(l=>l.type=="textbox").map(l=>l.fontFamily);g=Array.from(new Set(g));const _=this.editor.getPlugin("FontPlugin").cacheList,y={};for(const l of g){const a=_.find(t=>t.name===l);y[l]=a.file}console.log("_getSaveSvgOption",y);const{left:C,top:T,width:c,height:i}=r;return{fontOption:y,svgOption:{width:c,height:i,viewBox:{x:C,y:T,width:c,height:i}}}}_getSaveOption(){const r=this.canvas.getObjects().find(c=>c.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:_}}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","clear","preview","staticPreview","getSelectMode","getExtensionKey"],ge.events=[te.ONE,te.MULTI,ue.CANCEL];let Ai=ge;var St={},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(...T){return this.call=this._createCall("sync"),this.call(...T)}function _(...T){return this.callAsync=this._createCall("async"),this.callAsync(...T)}function y(...T){return this.promise=this._createCall("promise"),this.promise(...T)}class C{constructor(c=[],i=void 0){this._args=c,this.name=i,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(c){throw new Error("Abstract: should be overridden")}_createCall(c){return this.compile({taps:this.taps,interceptors:this.interceptors,args:this._args,type:c})}_tap(c,i,l){if(typeof i=="string")i={name:i.trim()};else if(typeof i!="object"||i===null)throw new Error("Invalid tap options");if(typeof i.name!="string"||i.name==="")throw new Error("Missing name for tap");typeof i.context<"u"&&r(),i=Object.assign({type:c,fn:l},i),i=this._runRegisterInterceptors(i),this._insert(i)}tap(c,i){this._tap("sync",c,i)}tapAsync(c,i){this._tap("async",c,i)}tapPromise(c,i){this._tap("promise",c,i)}_runRegisterInterceptors(c){for(const i of this.interceptors)if(i.register){const l=i.register(c);l!==void 0&&(c=l)}return c}withOptions(c){const i=l=>Object.assign({},c,typeof l=="string"?{name:l}:l);return{name:this.name,tap:(l,a)=>this.tap(i(l),a),tapAsync:(l,a)=>this.tapAsync(i(l),a),tapPromise:(l,a)=>this.tapPromise(i(l),a),intercept:l=>this.intercept(l),isUsed:()=>this.isUsed(),withOptions:l=>this.withOptions(i(l))}}isUsed(){return this.taps.length>0||this.interceptors.length>0}intercept(c){if(this._resetCompilation(),this.interceptors.push(Object.assign({},c)),c.register)for(let i=0;i<this.taps.length;i++)this.taps[i]=c.register(this.taps[i])}_resetCompilation(){this.call=this._call,this.callAsync=this._callAsync,this.promise=this._promise}_insert(c){this._resetCompilation();let i;typeof c.before=="string"?i=new Set([c.before]):Array.isArray(c.before)&&(i=new Set(c.before));let l=0;typeof c.stage=="number"&&(l=c.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(i){if(i.has(t.name)){i.delete(t.name);continue}if(i.size>0)continue}if(!(n>l)){a++;break}}this.taps[a]=c}}return Object.setPrototypeOf(C.prototype,null),li=C,li}var ci,on;function Lt(){if(on)return ci;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++),e[o]={line:a,offset:t},n+=l.graphemeLines[o].length,t+=l.graphemeLines[o].length;return e},styleHas:function(l,a){if(this._styleMap&&!this.isWrapping){var t=this._styleMap[a];t&&(a=t.line)}return i.Text.prototype.styleHas.call(this,l,a)},isEmptyStyles:function(l){if(!this.styles)return!0;var a=0,t=l+1,n,e,o=!1,h=this._styleMap[l],s=this._styleMap[l+1];h&&(l=h.line,a=h.offset),s&&(t=s.line,o=t===l,n=s.offset),e=typeof l>"u"?this.styles:{line:this.styles[l]};for(var u in e)for(var d in e[u])if(d>=a&&(!o||d<n))for(var m in e[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,e,o=!0;t=t||0;for(var h=0,s=l.length;h<s;h++){var u=this._getGraphemeBox(l[h],a,h+t,e,o);n+=u.kernedWidth,e=l[h]}return n},_wrapLine:function(l,a,t,R){var e=0,o=this.splitByGrapheme,h=[],s=[],u=o?i.util.string.graphemeSplit(l):l.split(this._wordJoiners),d="",m=0,p=o?"":" ",v=0,b=0,S=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]:i.util.string.graphemeSplit(u[z]),v=this._measureWord(d,a,m),m+=d.length,e+=b+v-F,e>t&&!E?(h.push(s),s=[],e=v,E=!0):e+=F,!E&&!o&&s.push(p),s=s.concat(d),b=o?0:this._measureWord([p],a,m),m++,E=!1,v>S&&(S=v);return z&&h.push(s),S+R>this.dynamicMinWidth&&(this.dynamicMinWidth=S-F+R),h},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=i.Text.prototype._splitTextIntoLines.call(this,l),t=this._wrapText(a.lines,this.width),n=new Array(t.length),e=0;e<t.length;e++)n[e]=t[e].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))}}),i.Textbox.fromObject=function(l,a){var t=i.util.stylesFromArray(l.styles,l.text),n=Object.assign({},l,{styles:t});return i.Object._fromObject("Textbox",n,a,"text")}})(f),(function(){var c=r.controlsUtils,i=c.scaleSkewCursorStyleHandler,l=c.scaleCursorStyleHandler,a=c.scalingEqually,t=c.scalingYOrSkewingX,n=c.scalingXOrSkewingY,e=c.scaleOrSkewActionName,o=r.Object.prototype.controls;if(o.ml=new r.Control({x:-.5,y:0,cursorStyleHandler:i,actionHandler:n,getActionName:e}),o.mr=new r.Control({x:.5,y:0,cursorStyleHandler:i,actionHandler:n,getActionName:e}),o.mb=new r.Control({x:0,y:.5,cursorStyleHandler:i,actionHandler:t,getActionName:e}),o.mt=new r.Control({x:0,y:-.5,cursorStyleHandler:i,actionHandler:t,getActionName:e}),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:c.rotationWithSnapping,cursorStyleHandler:c.rotationStyleHandler,offsetY:-40,withConnection:!0,actionName:"rotate"}),r.Textbox){var h=r.Textbox.prototype.controls={};h.mtr=o.mtr,h.tr=o.tr,h.br=o.br,h.tl=o.tl,h.bl=o.bl,h.mt=o.mt,h.mb=o.mb,h.mr=new r.Control({x:.5,y:0,actionHandler:c.changeWidth,cursorStyleHandler:i,actionName:"resizing"}),h.ml=new r.Control({x:-.5,y:0,actionHandler:c.changeWidth,cursorStyleHandler:i,actionName:"resizing"})}})()})(si)),si}var _t=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 _t.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);_&&_t.fabric.Path.fromObject(g.path,y=>{_.set("path",y)})})}async loadJSON(r,g){const _=typeof r=="string"?JSON.parse(r):r,y=[];_.objects.forEach(T=>{!T.id&&(T.id=On()),T.type==="i-text"&&T.path&&(y.push({id:T.id,path:T.path}),T.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")})},(T,c)=>{this.editor.hooksEntity.hookTransformObjectEnd.callAsync({originObject:T,fabricObject:c},()=>{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"].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 T={x:g.x-y,y:g.y-C},c=this.canvas.restorePointerVpt(T);r.left=c.x-r.width/2,r.top=c.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();_t.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(){return new Promise(r=>{this.editor.hooksEntity.hookSaveBefore.callAsync("",()=>{const g=this._getSaveOption();this.canvas.setViewportTransform([1,0,0,1,0,0]);const _=this.canvas.toDataURL(g);this.editor.hooksEntity.hookSaveAfter.callAsync(_,()=>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(){const r=this.canvas.getObjects().find(l=>l.id==="workspace");let g=this.canvas.getObjects().filter(l=>l.type=="textbox").map(l=>l.fontFamily);g=Array.from(new Set(g));const _=this.editor.getPlugin("FontPlugin").cacheList,y={};for(const l of g){const a=_.find(t=>t.name===l);y[l]=a.file}console.log("_getSaveSvgOption",y);const{left:C,top:T,width:c,height:i}=r;return{fontOption:y,svgOption:{width:c,height:i,viewBox:{x:C,y:T,width:c,height:i}}}}_getSaveOption(){const r=this.canvas.getObjects().find(c=>c.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:_}}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","clear","preview","staticPreview","getSelectMode","getExtensionKey"],ge.events=[te.ONE,te.MULTI,ue.CANCEL];let Ai=ge;var St={},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(...T){return this.call=this._createCall("sync"),this.call(...T)}function _(...T){return this.callAsync=this._createCall("async"),this.callAsync(...T)}function y(...T){return this.promise=this._createCall("promise"),this.promise(...T)}class C{constructor(c=[],i=void 0){this._args=c,this.name=i,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(c){throw new Error("Abstract: should be overridden")}_createCall(c){return this.compile({taps:this.taps,interceptors:this.interceptors,args:this._args,type:c})}_tap(c,i,l){if(typeof i=="string")i={name:i.trim()};else if(typeof i!="object"||i===null)throw new Error("Invalid tap options");if(typeof i.name!="string"||i.name==="")throw new Error("Missing name for tap");typeof i.context<"u"&&r(),i=Object.assign({type:c,fn:l},i),i=this._runRegisterInterceptors(i),this._insert(i)}tap(c,i){this._tap("sync",c,i)}tapAsync(c,i){this._tap("async",c,i)}tapPromise(c,i){this._tap("promise",c,i)}_runRegisterInterceptors(c){for(const i of this.interceptors)if(i.register){const l=i.register(c);l!==void 0&&(c=l)}return c}withOptions(c){const i=l=>Object.assign({},c,typeof l=="string"?{name:l}:l);return{name:this.name,tap:(l,a)=>this.tap(i(l),a),tapAsync:(l,a)=>this.tapAsync(i(l),a),tapPromise:(l,a)=>this.tapPromise(i(l),a),intercept:l=>this.intercept(l),isUsed:()=>this.isUsed(),withOptions:l=>this.withOptions(i(l))}}isUsed(){return this.taps.length>0||this.interceptors.length>0}intercept(c){if(this._resetCompilation(),this.interceptors.push(Object.assign({},c)),c.register)for(let i=0;i<this.taps.length;i++)this.taps[i]=c.register(this.taps[i])}_resetCompilation(){this.call=this._call,this.callAsync=this._callAsync,this.promise=this._promise}_insert(c){this._resetCompilation();let i;typeof c.before=="string"?i=new Set([c.before]):Array.isArray(c.before)&&(i=new Set(c.before));let l=0;typeof c.stage=="number"&&(l=c.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(i){if(i.has(t.name)){i.delete(t.name);continue}if(i.size>0)continue}if(!(n>l)){a++;break}}this.taps[a]=c}}return Object.setPrototypeOf(C.prototype,null),li=C,li}var ci,on;function Lt(){if(on)return ci;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
|
@@ -20931,6 +20931,8 @@ const ge = class ge {
|
|
|
20931
20931
|
"verticalAlign",
|
|
20932
20932
|
"roundValue",
|
|
20933
20933
|
"getBase64",
|
|
20934
|
+
"lockScalingX",
|
|
20935
|
+
"lockScalingY",
|
|
20934
20936
|
"_originSize"
|
|
20935
20937
|
];
|
|
20936
20938
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@hprint/core",
|
|
3
|
-
"version": "0.0.1-alpha.
|
|
3
|
+
"version": "0.0.1-alpha.4",
|
|
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.1-alpha.
|
|
36
|
+
"@hprint/shared": "0.0.1-alpha.4"
|
|
37
37
|
},
|
|
38
38
|
"scripts": {
|
|
39
39
|
"build": "vite build",
|