@hprint/shared 0.0.7 → 0.0.8

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/index.js CHANGED
@@ -438,4 +438,4 @@ gl_FragColor.rgb *= color.a;
438
438
  `?(e++,i[e]=0):i[e]++;i[0]>0&&(this.insertCharStyleObject(t.lineIndex,t.charIndex,i[0],a),a=a&&a.slice(i[0]+1)),e&&this.insertNewlineStyleObject(t.lineIndex,t.charIndex+i[0],e);for(var s=1;s<e;s++)i[s]>0?this.insertCharStyleObject(t.lineIndex+s,0,i[s],a):a&&this.styles[t.lineIndex+s]&&a[0]&&(this.styles[t.lineIndex+s][0]=a[0]),a=a&&a.slice(i[s]+1);i[s]>0&&this.insertCharStyleObject(t.lineIndex+s,0,i[s],a)},setSelectionStartEndWithShift:function(n,l,a){a<=n?(l===n?this._selectionDirection="left":this._selectionDirection==="right"&&(this._selectionDirection="left",this.selectionEnd=n),this.selectionStart=a):a>n&&a<l?this._selectionDirection==="right"?this.selectionEnd=a:this.selectionStart=a:(l===n?this._selectionDirection="right":this._selectionDirection==="left"&&(this._selectionDirection="right",this.selectionStart=l),this.selectionEnd=a)},setSelectionInBoundaries:function(){var n=this.text.length;this.selectionStart>n?this.selectionStart=n:this.selectionStart<0&&(this.selectionStart=0),this.selectionEnd>n?this.selectionEnd=n:this.selectionEnd<0&&(this.selectionEnd=0)}})})(),o.util.object.extend(o.IText.prototype,{initDoubleClickSimulation:function(){this.__lastClickTime=+new Date,this.__lastLastClickTime=+new Date,this.__lastPointer={},this.on("mousedown",this.onMouseDown)},onMouseDown:function(u){if(this.canvas){this.__newClickTime=+new Date;var n=u.pointer;this.isTripleClick(n)&&(this.fire("tripleclick",u),this._stopEvent(u.e)),this.__lastLastClickTime=this.__lastClickTime,this.__lastClickTime=this.__newClickTime,this.__lastPointer=n,this.__lastIsEditing=this.isEditing,this.__lastSelected=this.selected}},isTripleClick:function(u){return this.__newClickTime-this.__lastClickTime<500&&this.__lastClickTime-this.__lastLastClickTime<500&&this.__lastPointer.x===u.x&&this.__lastPointer.y===u.y},_stopEvent:function(u){u.preventDefault&&u.preventDefault(),u.stopPropagation&&u.stopPropagation()},initCursorSelectionHandlers:function(){this.initMousedownHandler(),this.initMouseupHandler(),this.initClicks()},doubleClickHandler:function(u){this.isEditing&&this.selectWord(this.getSelectionStartFromPointer(u.e))},tripleClickHandler:function(u){this.isEditing&&this.selectLine(this.getSelectionStartFromPointer(u.e))},initClicks:function(){this.on("mousedblclick",this.doubleClickHandler),this.on("tripleclick",this.tripleClickHandler)},_mouseDownHandler:function(u){!this.canvas||!this.editable||u.e.button&&u.e.button!==1||(this.__isMousedown=!0,this.selected&&(this.inCompositionMode=!1,this.setCursorByClick(u.e)),this.isEditing&&(this.__selectionStartOnMouseDown=this.selectionStart,this.selectionStart===this.selectionEnd&&this.abortCursorAnimation(),this.renderCursorOrSelection()))},_mouseDownHandlerBefore:function(u){!this.canvas||!this.editable||u.e.button&&u.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(u){if(this.__isMousedown=!1,!(!this.editable||this.group||u.transform&&u.transform.actionPerformed||u.e.button&&u.e.button!==1)){if(this.canvas){var n=this.canvas._activeObject;if(n&&n!==this)return}this.__lastSelected&&!this.__corner?(this.selected=!1,this.__lastSelected=!1,this.enterEditing(u.e),this.selectionStart===this.selectionEnd?this.initDelayedCursor(!0):this.renderCursorOrSelection()):this.selected=!0}},setCursorByClick:function(u){var n=this.getSelectionStartFromPointer(u),l=this.selectionStart,a=this.selectionEnd;u.shiftKey?this.setSelectionStartEndWithShift(l,a,n):(this.selectionStart=n,this.selectionEnd=n),this.isEditing&&(this._fireSelectionChanged(),this._updateTextarea())},getSelectionStartFromPointer:function(u){for(var n=this.getLocalPointer(u),l=0,a=0,t=0,i=0,e=0,s,h,r=0,c=this._textLines.length;r<c&&t<=n.y;r++)t+=this.getHeightOfLine(r)*this.scaleY,e=r,r>0&&(i+=this._textLines[r-1].length+this.missingNewlineOffset(r-1));s=this._getLineLeftOffset(e),a=s*this.scaleX,h=this._textLines[e],this.direction==="rtl"&&(n.x=this.width*this.scaleX-n.x+a);for(var f=0,g=h.length;f<g&&(l=a,a+=this.__charBounds[e][f].kernedWidth*this.scaleX,a<=n.x);f++)i++;return this._getNewSelectionStartFromOffset(n,l,a,i,g)},_getNewSelectionStartFromOffset:function(u,n,l,a,t){var i=u.x-n,e=l-u.x,s=e>i||e<0?0:1,h=a+s;return this.flipX&&(h=t-h),h>this._text.length&&(h=this._text.length),h}}),o.util.object.extend(o.IText.prototype,{initHiddenTextarea:function(){this.hiddenTextarea=o.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 u=this._calcTextareaPosition();this.hiddenTextarea.style.cssText="position: absolute; top: "+u.top+"; left: "+u.left+"; z-index: -999; opacity: 0; width: 1px; height: 1px; font-size: 1px; padding-top: "+u.fontSize+";",this.hiddenTextareaContainer?this.hiddenTextareaContainer.appendChild(this.hiddenTextarea):o.document.body.appendChild(this.hiddenTextarea),o.util.addListener(this.hiddenTextarea,"keydown",this.onKeyDown.bind(this)),o.util.addListener(this.hiddenTextarea,"keyup",this.onKeyUp.bind(this)),o.util.addListener(this.hiddenTextarea,"input",this.onInput.bind(this)),o.util.addListener(this.hiddenTextarea,"copy",this.copy.bind(this)),o.util.addListener(this.hiddenTextarea,"cut",this.copy.bind(this)),o.util.addListener(this.hiddenTextarea,"paste",this.paste.bind(this)),o.util.addListener(this.hiddenTextarea,"compositionstart",this.onCompositionStart.bind(this)),o.util.addListener(this.hiddenTextarea,"compositionupdate",this.onCompositionUpdate.bind(this)),o.util.addListener(this.hiddenTextarea,"compositionend",this.onCompositionEnd.bind(this)),!this._clickHandlerInitialized&&this.canvas&&(o.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(u){if(this.isEditing){var n=this.direction==="rtl"?this.keysMapRtl:this.keysMap;if(u.keyCode in n)this[n[u.keyCode]](u);else if(u.keyCode in this.ctrlKeysMapDown&&(u.ctrlKey||u.metaKey))this[this.ctrlKeysMapDown[u.keyCode]](u);else return;u.stopImmediatePropagation(),u.preventDefault(),u.keyCode>=33&&u.keyCode<=40?(this.inCompositionMode=!1,this.clearContextTop(),this.renderCursorOrSelection()):this.canvas&&this.canvas.requestRenderAll()}},onKeyUp:function(u){if(!this.isEditing||this._copyDone||this.inCompositionMode){this._copyDone=!1;return}if(u.keyCode in this.ctrlKeysMapUp&&(u.ctrlKey||u.metaKey))this[this.ctrlKeysMapUp[u.keyCode]](u);else return;u.stopImmediatePropagation(),u.preventDefault(),this.canvas&&this.canvas.requestRenderAll()},onInput:function(u){var n=this.fromPaste;if(this.fromPaste=!1,u&&u.stopPropagation(),!!this.isEditing){var l=this._splitTextIntoLines(this.hiddenTextarea.value).graphemeText,a=this._text.length,t=l.length,i,e,s=t-a,h=this.selectionStart,r=this.selectionEnd,c=h!==r,f,g,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),_=h>v.selectionStart;c?(i=this._text.slice(h,r),s+=r-h):t<a&&(_?i=this._text.slice(r+s,r):i=this._text.slice(h,h-s)),e=l.slice(v.selectionEnd-s,v.selectionEnd),i&&i.length&&(e.length&&(f=this.getSelectionStyles(h,h+1,!1),f=e.map(function(){return f[0]})),c?(g=h,p=r):_?(g=r-i.length,p=r):(g=r,p=r+i.length),this.removeStyleFromTo(g,p)),e.length&&(n&&e.join("")===o.copiedText&&!o.disableStyleCopyPaste&&(f=o.copiedTextStyle),this.insertNewStyleBlock(e,h,f)),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(u){this.compositionStart=u.target.selectionStart,this.compositionEnd=u.target.selectionEnd,this.updateTextareaPosition()},copy:function(){this.selectionStart!==this.selectionEnd&&(o.copiedText=this.getSelectedText(),o.disableStyleCopyPaste?o.copiedTextStyle=null:o.copiedTextStyle=this.getSelectionStyles(this.selectionStart,this.selectionEnd,!0),this._copyDone=!0)},paste:function(){this.fromPaste=!0},_getClipboardData:function(u){return u&&u.clipboardData||o.window.clipboardData},_getWidthBeforeCursor:function(u,n){var l=this._getLineLeftOffset(u),a;return n>0&&(a=this.__charBounds[u][n-1],l+=a.left+a.width),l},getDownCursorOffset:function(u,n){var l=this._getSelectionForOffset(u,n),a=this.get2DCursorLocation(l),t=a.lineIndex;if(t===this._textLines.length-1||u.metaKey||u.keyCode===34)return this._text.length-l;var i=a.charIndex,e=this._getWidthBeforeCursor(t,i),s=this._getIndexOnLine(t+1,e),h=this._textLines[t].slice(i);return h.length+s+1+this.missingNewlineOffset(t)},_getSelectionForOffset:function(u,n){return u.shiftKey&&this.selectionStart!==this.selectionEnd&&n?this.selectionEnd:this.selectionStart},getUpCursorOffset:function(u,n){var l=this._getSelectionForOffset(u,n),a=this.get2DCursorLocation(l),t=a.lineIndex;if(t===0||u.metaKey||u.keyCode===33)return-l;var i=a.charIndex,e=this._getWidthBeforeCursor(t,i),s=this._getIndexOnLine(t-1,e),h=this._textLines[t].slice(0,i),r=this.missingNewlineOffset(t-1);return-this._textLines[t-1].length+s-h.length+(1-r)},_getIndexOnLine:function(u,n){for(var l=this._textLines[u],a=this._getLineLeftOffset(u),t=a,i=0,e,s,h=0,r=l.length;h<r;h++)if(e=this.__charBounds[u][h].width,t+=e,t>n){s=!0;var c=t-e,f=t,g=Math.abs(c-n),p=Math.abs(f-n);i=p<g?h:h-1;break}return s||(i=l.length-1),i},moveCursorDown:function(u){this.selectionStart>=this._text.length&&this.selectionEnd>=this._text.length||this._moveCursorUpOrDown("Down",u)},moveCursorUp:function(u){this.selectionStart===0&&this.selectionEnd===0||this._moveCursorUpOrDown("Up",u)},_moveCursorUpOrDown:function(u,n){var l="get"+u+"CursorOffset",a=this[l](n,this._selectionDirection==="right");n.shiftKey?this.moveCursorWithShift(a):this.moveCursorWithoutShift(a),a!==0&&(this.setSelectionInBoundaries(),this.abortCursorAnimation(),this._currentCursorOpacity=1,this.initDelayedCursor(),this._fireSelectionChanged(),this._updateTextarea())},moveCursorWithShift:function(u){var n=this._selectionDirection==="left"?this.selectionStart+u:this.selectionEnd+u;return this.setSelectionStartEndWithShift(this.selectionStart,this.selectionEnd,n),u!==0},moveCursorWithoutShift:function(u){return u<0?(this.selectionStart+=u,this.selectionEnd=this.selectionStart):(this.selectionEnd+=u,this.selectionStart=this.selectionEnd),u!==0},moveCursorLeft:function(u){this.selectionStart===0&&this.selectionEnd===0||this._moveCursorLeftOrRight("Left",u)},_move:function(u,n,l){var a;if(u.altKey)a=this["findWordBoundary"+l](this[n]);else if(u.metaKey||u.keyCode===35||u.keyCode===36)a=this["findLineBoundary"+l](this[n]);else return this[n]+=l==="Left"?-1:1,!0;if(typeof a<"u"&&this[n]!==a)return this[n]=a,!0},_moveLeft:function(u,n){return this._move(u,n,"Left")},_moveRight:function(u,n){return this._move(u,n,"Right")},moveCursorLeftWithoutShift:function(u){var n=!0;return this._selectionDirection="left",this.selectionEnd===this.selectionStart&&this.selectionStart!==0&&(n=this._moveLeft(u,"selectionStart")),this.selectionEnd=this.selectionStart,n},moveCursorLeftWithShift:function(u){if(this._selectionDirection==="right"&&this.selectionStart!==this.selectionEnd)return this._moveLeft(u,"selectionEnd");if(this.selectionStart!==0)return this._selectionDirection="left",this._moveLeft(u,"selectionStart")},moveCursorRight:function(u){this.selectionStart>=this._text.length&&this.selectionEnd>=this._text.length||this._moveCursorLeftOrRight("Right",u)},_moveCursorLeftOrRight:function(u,n){var l="moveCursor"+u+"With";this._currentCursorOpacity=1,n.shiftKey?l+="Shift":l+="outShift",this[l](n)&&(this.abortCursorAnimation(),this.initDelayedCursor(),this._fireSelectionChanged(),this._updateTextarea())},moveCursorRightWithShift:function(u){if(this._selectionDirection==="left"&&this.selectionStart!==this.selectionEnd)return this._moveRight(u,"selectionStart");if(this.selectionEnd!==this._text.length)return this._selectionDirection="right",this._moveRight(u,"selectionEnd")},moveCursorRightWithoutShift:function(u){var n=!0;return this._selectionDirection="right",this.selectionStart===this.selectionEnd?(n=this._moveRight(u,"selectionStart"),this.selectionEnd=this.selectionStart):this.selectionStart=this.selectionEnd,n},removeChars:function(u,n){typeof n>"u"&&(n=u+1),this.removeStyleFromTo(u,n),this._text.splice(u,n-u),this.text=this._text.join(""),this.set("dirty",!0),this._shouldClearDimensionCache()&&(this.initDimensions(),this.setCoords()),this._removeExtraneousStyles()},insertChars:function(u,n,l,a){typeof a>"u"&&(a=l),a>l&&this.removeStyleFromTo(l,a);var t=o.util.string.graphemeSplit(u);this.insertNewStyleBlock(t,l,n),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 u=o.util.toFixed,n=/ +/g;o.util.object.extend(o.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=[],i=[],e=l,s;this._setSVGBg(i);for(var h=0,r=this._textLines.length;h<r;h++)s=this._getLineLeftOffset(h),(this.textBackgroundColor||this.styleHas("textBackgroundColor",h))&&this._setSVGTextLineBg(i,h,a+s,e),this._setSVGTextLineText(t,h,a+s,e),e+=this.getHeightOfLine(h);return{textSpans:t,textBgRects:i}},_createTextCharSpan:function(l,a,t,i){var e=l!==l.trim()||l.match(n),s=this.getSvgSpanStyles(a,e),h=s?'style="'+s+'"':"",r=a.deltaY,c="",f=o.Object.NUM_FRACTION_DIGITS;return r&&(c=' dy="'+u(r,f)+'" '),['<tspan x="',u(t,f),'" y="',u(i,f),'" ',c,h,">",o.util.string.escapeXml(l),"</tspan>"].join("")},_setSVGTextLineText:function(l,a,t,i){var e=this.getHeightOfLine(a),s=this.textAlign.indexOf("justify")!==-1,h,r,c="",f,g,p=0,v=this._textLines[a],_;i+=e*(1-this._fontSizeFraction)/this.lineHeight;for(var x=0,D=v.length-1;x<=D;x++)_=x===D||this.charSpacing,c+=v[x],f=this.__charBounds[a][x],p===0?(t+=f.kernedWidth-f.width,p+=f.width):p+=f.kernedWidth,s&&!_&&this._reSpaceAndTab.test(v[x])&&(_=!0),_||(h=h||this.getCompleteStyleDeclaration(a,x),r=this.getCompleteStyleDeclaration(a,x+1),_=o.util.hasStyleChanged(h,r,!0)),_&&(g=this._getStyleDeclaration(a,x)||{},l.push(this._createTextCharSpan(c,g,t,i)),c="",h=r,t+=p,p=0)},_pushTextBgRect:function(l,a,t,i,e,s){var h=o.Object.NUM_FRACTION_DIGITS;l.push(" <rect ",this._getFillAttributes(a),' x="',u(t,h),'" y="',u(i,h),'" width="',u(e,h),'" height="',u(s,h),`"></rect>
440
440
  `)},_setSVGTextLineBg:function(l,a,t,i){for(var e=this._textLines[a],s=this.getHeightOfLine(a)/this.lineHeight,h=0,r=0,c,f,g=this.getValueOfPropertyAt(a,0,"textBackgroundColor"),p=0,v=e.length;p<v;p++)c=this.__charBounds[a][p],f=this.getValueOfPropertyAt(a,p,"textBackgroundColor"),f!==g?(g&&this._pushTextBgRect(l,g,t+r,i,h,s),r=c.left,h=c.width,g=f):h+=c.kernedWidth;f&&this._pushTextBgRect(l,f,t+r,i,h,s)},_getFillAttributes:function(l){var a=l&&typeof l=="string"?new o.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,i=0;i<l;i++)a+=this.getHeightOfLine(i);return t=this.getHeightOfLine(i),{lineTop:a,offset:(this._fontSizeMult-this._fontSizeFraction)*t/(this.lineHeight*this._fontSizeMult)}},getSvgStyles:function(l){var a=o.Object.prototype.getSvgStyles.call(this,l);return a+" white-space: pre;"}})})(),(function(u){var n=u.fabric||(u.fabric={});n.Textbox=n.util.createClass(n.IText,n.Observable,{type:"textbox",minWidth:20,dynamicMinWidth:2,__cachedLines:null,lockScalingFlip:!0,noScaleCache:!1,_dimensionAffectingProps:n.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,i=0,e={},s=0;s<l.graphemeLines.length;s++)l.graphemeText[i]===`
441
- `&&s>0?(t=0,i++,a++):!this.splitByGrapheme&&this._reSpaceAndTab.test(l.graphemeText[i])&&s>0&&(t++,i++),e[s]={line:a,offset:t},i+=l.graphemeLines[s].length,t+=l.graphemeLines[s].length;return e},styleHas:function(l,a){if(this._styleMap&&!this.isWrapping){var t=this._styleMap[a];t&&(a=t.line)}return n.Text.prototype.styleHas.call(this,l,a)},isEmptyStyles:function(l){if(!this.styles)return!0;var a=0,t=l+1,i,e,s=!1,h=this._styleMap[l],r=this._styleMap[l+1];h&&(l=h.line,a=h.offset),r&&(t=r.line,s=t===l,i=r.offset),e=typeof l>"u"?this.styles:{line:this.styles[l]};for(var c in e)for(var f in e[c])if(f>=a&&(!s||f<i))for(var g in e[c][f])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 i=this._styleMap[l];l=i.line,a=i.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=[],i;for(this.isWrapping=!0,i=0;i<l.length;i++)t=t.concat(this._wrapLine(l[i],i,a));return this.isWrapping=!1,t},_measureWord:function(l,a,t){var i=0,e,s=!0;t=t||0;for(var h=0,r=l.length;h<r;h++){var c=this._getGraphemeBox(l[h],a,h+t,e,s);i+=c.kernedWidth,e=l[h]}return i},_wrapLine:function(l,a,t,z){var e=0,s=this.splitByGrapheme,h=[],r=[],c=s?n.util.string.graphemeSplit(l):l.split(this._wordJoiners),f="",g=0,p=s?"":" ",v=0,_=0,x=0,D=!0,B=this._getWidthOfCharSpacing(),z=z||0;c.length===0&&c.push([]),t-=z;for(var G=0;G<c.length;G++)f=s?c[G]:n.util.string.graphemeSplit(c[G]),v=this._measureWord(f,a,g),g+=f.length,e+=_+v-B,e>t&&!D?(h.push(r),r=[],e=v,D=!0):e+=B,!D&&!s&&r.push(p),r=r.concat(f),_=s?0:this._measureWord([p],a,g),g++,D=!1,v>x&&(x=v);return G&&h.push(r),x+z>this.dynamicMinWidth&&(this.dynamicMinWidth=x-B+z),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=n.Text.prototype._splitTextIntoLines.call(this,l),t=this._wrapText(a.lines,this.width),i=new Array(t.length),e=0;e<t.length;e++)i[e]=t[e].join("");return a.lines=i,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))}}),n.Textbox.fromObject=function(l,a){var t=n.util.stylesFromArray(l.styles,l.text),i=Object.assign({},l,{styles:t});return n.Object._fromObject("Textbox",i,a,"text")}})(d),(function(){var u=o.controlsUtils,n=u.scaleSkewCursorStyleHandler,l=u.scaleCursorStyleHandler,a=u.scalingEqually,t=u.scalingYOrSkewingX,i=u.scalingXOrSkewingY,e=u.scaleOrSkewActionName,s=o.Object.prototype.controls;if(s.ml=new o.Control({x:-.5,y:0,cursorStyleHandler:n,actionHandler:i,getActionName:e}),s.mr=new o.Control({x:.5,y:0,cursorStyleHandler:n,actionHandler:i,getActionName:e}),s.mb=new o.Control({x:0,y:.5,cursorStyleHandler:n,actionHandler:t,getActionName:e}),s.mt=new o.Control({x:0,y:-.5,cursorStyleHandler:n,actionHandler:t,getActionName:e}),s.tl=new o.Control({x:-.5,y:-.5,cursorStyleHandler:l,actionHandler:a}),s.tr=new o.Control({x:.5,y:-.5,cursorStyleHandler:l,actionHandler:a}),s.bl=new o.Control({x:-.5,y:.5,cursorStyleHandler:l,actionHandler:a}),s.br=new o.Control({x:.5,y:.5,cursorStyleHandler:l,actionHandler:a}),s.mtr=new o.Control({x:0,y:-.5,actionHandler:u.rotationWithSnapping,cursorStyleHandler:u.rotationStyleHandler,offsetY:-40,withConnection:!0,actionName:"rotate"}),o.Textbox){var h=o.Textbox.prototype.controls={};h.mtr=s.mtr,h.tr=s.tr,h.br=s.br,h.tl=s.tl,h.bl=s.bl,h.mt=s.mt,h.mb=s.mb,h.mr=new o.Control({x:.5,y:0,actionHandler:u.changeWidth,cursorStyleHandler:n,actionName:"resizing"}),h.ml=new o.Control({x:-.5,y:0,actionHandler:u.changeWidth,cursorStyleHandler:n,actionName:"resizing"})}})()})(Be)),Be}var ge=ss();function os(d){return $n(d).promise.value}function as(d){return new Promise(o=>{const{onChange:m,open:S}=es(d);m(b=>{o(b)}),S()})}function ls(d){return new Promise(o=>{const m=document.createElement("img");m.src=d,document.body.appendChild(m),m.onload=()=>{o(m)}})}const hs=(d,o)=>Zn({source:d,...o}).copy();function cs(d,o){const m=document.createElement("a");m.href=d,m.download=`${hr()}.${o}`,document.body.appendChild(m),m.click(),m.remove()}function us(d,o,m,S,b,T,F){F!==void 0&&(d.save(),d.translate(o,m),d.rotate(F),d.drawImage(S,-b/2,-T/2,b,T),d.restore())}const fs=d=>d instanceof ge.fabric.Image,ds=d=>d instanceof ge.fabric.Group,gs=d=>d instanceof ge.fabric.IText,ps=d=>d instanceof ge.fabric.ActiveSelection;function ms(d){return new Promise(o=>{const m=new FileReader;m.addEventListener("load",()=>{o(m.result)}),m.readAsDataURL(d)})}function vs(d){if(!d)return null;const o=d.split(","),m=o[0].match(/:(.*?);/)[1],S=window.atob(o[1]),b=new ArrayBuffer(S.length),T=new Uint8Array(b);for(let F=0;F<S.length;F++)T[F]=S.charCodeAt(F);return[new Blob([b],{type:m}),m.slice(6)]}const _s={getImgStr:os,downFile:cs,selectFiles:as,insertImgFile:ls,clipboardText:hs,drawImg:us,isImage:fs,isGroup:ds,isIText:gs,isActiveSelection:ps,blobToBase64:ms,base64ToBlob:vs},ys="0.0.7";window&&(window._hprintPrintVersion=ys);exports.LengthConvert=Xe;exports.fabric=ge.fabric;exports.mathHelper=rr;exports.utils=_s;
441
+ `&&s>0?(t=0,i++,a++):!this.splitByGrapheme&&this._reSpaceAndTab.test(l.graphemeText[i])&&s>0&&(t++,i++),e[s]={line:a,offset:t},i+=l.graphemeLines[s].length,t+=l.graphemeLines[s].length;return e},styleHas:function(l,a){if(this._styleMap&&!this.isWrapping){var t=this._styleMap[a];t&&(a=t.line)}return n.Text.prototype.styleHas.call(this,l,a)},isEmptyStyles:function(l){if(!this.styles)return!0;var a=0,t=l+1,i,e,s=!1,h=this._styleMap[l],r=this._styleMap[l+1];h&&(l=h.line,a=h.offset),r&&(t=r.line,s=t===l,i=r.offset),e=typeof l>"u"?this.styles:{line:this.styles[l]};for(var c in e)for(var f in e[c])if(f>=a&&(!s||f<i))for(var g in e[c][f])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 i=this._styleMap[l];l=i.line,a=i.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=[],i;for(this.isWrapping=!0,i=0;i<l.length;i++)t=t.concat(this._wrapLine(l[i],i,a));return this.isWrapping=!1,t},_measureWord:function(l,a,t){var i=0,e,s=!0;t=t||0;for(var h=0,r=l.length;h<r;h++){var c=this._getGraphemeBox(l[h],a,h+t,e,s);i+=c.kernedWidth,e=l[h]}return i},_wrapLine:function(l,a,t,z){var e=0,s=this.splitByGrapheme,h=[],r=[],c=s?n.util.string.graphemeSplit(l):l.split(this._wordJoiners),f="",g=0,p=s?"":" ",v=0,_=0,x=0,D=!0,B=this._getWidthOfCharSpacing(),z=z||0;c.length===0&&c.push([]),t-=z;for(var G=0;G<c.length;G++)f=s?c[G]:n.util.string.graphemeSplit(c[G]),v=this._measureWord(f,a,g),g+=f.length,e+=_+v-B,e>t&&!D?(h.push(r),r=[],e=v,D=!0):e+=B,!D&&!s&&r.push(p),r=r.concat(f),_=s?0:this._measureWord([p],a,g),g++,D=!1,v>x&&(x=v);return G&&h.push(r),x+z>this.dynamicMinWidth&&(this.dynamicMinWidth=x-B+z),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=n.Text.prototype._splitTextIntoLines.call(this,l),t=this._wrapText(a.lines,this.width),i=new Array(t.length),e=0;e<t.length;e++)i[e]=t[e].join("");return a.lines=i,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))}}),n.Textbox.fromObject=function(l,a){var t=n.util.stylesFromArray(l.styles,l.text),i=Object.assign({},l,{styles:t});return n.Object._fromObject("Textbox",i,a,"text")}})(d),(function(){var u=o.controlsUtils,n=u.scaleSkewCursorStyleHandler,l=u.scaleCursorStyleHandler,a=u.scalingEqually,t=u.scalingYOrSkewingX,i=u.scalingXOrSkewingY,e=u.scaleOrSkewActionName,s=o.Object.prototype.controls;if(s.ml=new o.Control({x:-.5,y:0,cursorStyleHandler:n,actionHandler:i,getActionName:e}),s.mr=new o.Control({x:.5,y:0,cursorStyleHandler:n,actionHandler:i,getActionName:e}),s.mb=new o.Control({x:0,y:.5,cursorStyleHandler:n,actionHandler:t,getActionName:e}),s.mt=new o.Control({x:0,y:-.5,cursorStyleHandler:n,actionHandler:t,getActionName:e}),s.tl=new o.Control({x:-.5,y:-.5,cursorStyleHandler:l,actionHandler:a}),s.tr=new o.Control({x:.5,y:-.5,cursorStyleHandler:l,actionHandler:a}),s.bl=new o.Control({x:-.5,y:.5,cursorStyleHandler:l,actionHandler:a}),s.br=new o.Control({x:.5,y:.5,cursorStyleHandler:l,actionHandler:a}),s.mtr=new o.Control({x:0,y:-.5,actionHandler:u.rotationWithSnapping,cursorStyleHandler:u.rotationStyleHandler,offsetY:-40,withConnection:!0,actionName:"rotate"}),o.Textbox){var h=o.Textbox.prototype.controls={};h.mtr=s.mtr,h.tr=s.tr,h.br=s.br,h.tl=s.tl,h.bl=s.bl,h.mt=s.mt,h.mb=s.mb,h.mr=new o.Control({x:.5,y:0,actionHandler:u.changeWidth,cursorStyleHandler:n,actionName:"resizing"}),h.ml=new o.Control({x:-.5,y:0,actionHandler:u.changeWidth,cursorStyleHandler:n,actionName:"resizing"})}})()})(Be)),Be}var ge=ss();function os(d){return $n(d).promise.value}function as(d){return new Promise(o=>{const{onChange:m,open:S}=es(d);m(b=>{o(b)}),S()})}function ls(d){return new Promise(o=>{const m=document.createElement("img");m.src=d,document.body.appendChild(m),m.onload=()=>{o(m)}})}const hs=(d,o)=>Zn({source:d,...o}).copy();function cs(d,o){const m=document.createElement("a");m.href=d,m.download=`${hr()}.${o}`,document.body.appendChild(m),m.click(),m.remove()}function us(d,o,m,S,b,T,F){F!==void 0&&(d.save(),d.translate(o,m),d.rotate(F),d.drawImage(S,-b/2,-T/2,b,T),d.restore())}const fs=d=>d instanceof ge.fabric.Image,ds=d=>d instanceof ge.fabric.Group,gs=d=>d instanceof ge.fabric.IText,ps=d=>d instanceof ge.fabric.ActiveSelection;function ms(d){return new Promise(o=>{const m=new FileReader;m.addEventListener("load",()=>{o(m.result)}),m.readAsDataURL(d)})}function vs(d){if(!d)return null;const o=d.split(","),m=o[0].match(/:(.*?);/)[1],S=window.atob(o[1]),b=new ArrayBuffer(S.length),T=new Uint8Array(b);for(let F=0;F<S.length;F++)T[F]=S.charCodeAt(F);return[new Blob([b],{type:m}),m.slice(6)]}const _s={getImgStr:os,downFile:cs,selectFiles:as,insertImgFile:ls,clipboardText:hs,drawImg:us,isImage:fs,isGroup:ds,isIText:gs,isActiveSelection:ps,blobToBase64:ms,base64ToBlob:vs},ys="0.0.8";window&&(window._hprintPrintVersion=ys);exports.LengthConvert=Xe;exports.fabric=ge.fabric;exports.mathHelper=rr;exports.utils=_s;
package/dist/index.mjs CHANGED
@@ -20396,7 +20396,7 @@ const ys = {
20396
20396
  isActiveSelection: gs,
20397
20397
  blobToBase64: ps,
20398
20398
  base64ToBlob: ms
20399
- }, vs = "0.0.7";
20399
+ }, vs = "0.0.8";
20400
20400
  window && (window._hprintPrintVersion = vs);
20401
20401
  const Cs = ge.fabric;
20402
20402
  export {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@hprint/shared",
3
- "version": "0.0.7",
3
+ "version": "0.0.8",
4
4
  "description": "",
5
5
  "main": "./dist/index.js",
6
6
  "module": "./dist/index.mjs",
package/src/index.ts CHANGED
@@ -1,9 +1,9 @@
1
- import LengthConvert from './lengthConvert';
2
- import mathHelper from './mathHelper';
3
- import utils from './utils';
4
- import { fabric } from 'fabric';
5
- import { version } from '../package.json';
6
-
7
- if (window) (window as (typeof window & { _hprintPrintVersion: string }))._hprintPrintVersion = version
8
-
9
- export { LengthConvert, mathHelper, utils, fabric };
1
+ import LengthConvert from './lengthConvert';
2
+ import mathHelper from './mathHelper';
3
+ import utils from './utils';
4
+ import { fabric } from 'fabric';
5
+ import { version } from '../package.json';
6
+
7
+ if (window) (window as (typeof window & { _hprintPrintVersion: string }))._hprintPrintVersion = version
8
+
9
+ export { LengthConvert, mathHelper, utils, fabric };
package/src/mathHelper.ts CHANGED
@@ -1,25 +1,25 @@
1
- /**
2
- * 获取多边形顶点坐标
3
- * @param edges 变数
4
- * @param radius 半径
5
- * @returns 坐标数组
6
- */
7
- const getPolygonVertices = (edges: number, radius: number) => {
8
- const vertices = [];
9
- const interiorAngle = (Math.PI * 2) / edges;
10
- let rotationAdjustment = -Math.PI / 2;
11
- if (edges % 2 === 0) {
12
- rotationAdjustment += interiorAngle / 2;
13
- }
14
- for (let i = 0; i < edges; i++) {
15
- // 画圆取顶点坐标
16
- const rad = i * interiorAngle + rotationAdjustment;
17
- vertices.push({
18
- x: Math.cos(rad) * radius,
19
- y: Math.sin(rad) * radius,
20
- });
21
- }
22
- return vertices;
23
- };
24
-
25
- export default { getPolygonVertices };
1
+ /**
2
+ * 获取多边形顶点坐标
3
+ * @param edges 变数
4
+ * @param radius 半径
5
+ * @returns 坐标数组
6
+ */
7
+ const getPolygonVertices = (edges: number, radius: number) => {
8
+ const vertices = [];
9
+ const interiorAngle = (Math.PI * 2) / edges;
10
+ let rotationAdjustment = -Math.PI / 2;
11
+ if (edges % 2 === 0) {
12
+ rotationAdjustment += interiorAngle / 2;
13
+ }
14
+ for (let i = 0; i < edges; i++) {
15
+ // 画圆取顶点坐标
16
+ const rad = i * interiorAngle + rotationAdjustment;
17
+ vertices.push({
18
+ x: Math.cos(rad) * radius,
19
+ y: Math.sin(rad) * radius,
20
+ });
21
+ }
22
+ return vertices;
23
+ };
24
+
25
+ export default { getPolygonVertices };
package/tsconfig.json CHANGED
@@ -1,10 +1,10 @@
1
- {
2
- "extends": "../../tsconfig.json",
3
- "compilerOptions": {
4
- "outDir": "./dist",
5
- "rootDir": "./",
6
- "composite": true
7
- },
8
- "include": ["**/*.ts", "**/*.json"],
9
- "exclude": ["node_modules", "dist"]
10
- }
1
+ {
2
+ "extends": "../../tsconfig.json",
3
+ "compilerOptions": {
4
+ "outDir": "./dist",
5
+ "rootDir": "./",
6
+ "composite": true
7
+ },
8
+ "include": ["**/*.ts", "**/*.json"],
9
+ "exclude": ["node_modules", "dist"]
10
+ }
package/vite.config.ts CHANGED
@@ -1,29 +1,29 @@
1
- import { defineConfig } from 'vite';
2
- import { resolve } from 'path';
3
- import { fileURLToPath } from 'url';
4
- import dts from 'vite-plugin-dts';
5
-
6
- const __dirname = fileURLToPath(new URL('.', import.meta.url));
7
-
8
- export default defineConfig({
9
- plugins: [
10
- dts({
11
- outDir: 'dist',
12
- include: ['src/**/*'],
13
- }),
14
- ],
15
- build: {
16
- lib: {
17
- entry: resolve(__dirname, 'src/index.ts'),
18
- name: '@hprint/shared',
19
- fileName: 'index',
20
- formats: ['es', 'cjs'],
21
- },
22
- rollupOptions: {
23
- external: [],
24
- output: {
25
- globals: {},
26
- },
27
- },
28
- },
29
- });
1
+ import { defineConfig } from 'vite';
2
+ import { resolve } from 'path';
3
+ import { fileURLToPath } from 'url';
4
+ import dts from 'vite-plugin-dts';
5
+
6
+ const __dirname = fileURLToPath(new URL('.', import.meta.url));
7
+
8
+ export default defineConfig({
9
+ plugins: [
10
+ dts({
11
+ outDir: 'dist',
12
+ include: ['src/**/*'],
13
+ }),
14
+ ],
15
+ build: {
16
+ lib: {
17
+ entry: resolve(__dirname, 'src/index.ts'),
18
+ name: '@hprint/shared',
19
+ fileName: 'index',
20
+ formats: ['es', 'cjs'],
21
+ },
22
+ rollupOptions: {
23
+ external: [],
24
+ output: {
25
+ globals: {},
26
+ },
27
+ },
28
+ },
29
+ });