kritzel-stencil 0.3.32 → 0.3.34

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.
Files changed (65) hide show
  1. package/dist/cjs/index.cjs.js +1 -1
  2. package/dist/cjs/kritzel-active-users_45.cjs.entry.js +3122 -8
  3. package/dist/cjs/loader.cjs.js +1 -1
  4. package/dist/cjs/{schema.constants-DItwOm2z.js → schema.constants-D7Z8ELAd.js} +5 -2
  5. package/dist/cjs/stencil.cjs.js +1 -1
  6. package/dist/collection/classes/managers/anchor.manager.js +3 -2
  7. package/dist/collection/components/shared/kritzel-pill-tabs/kritzel-pill-tabs.css +10 -0
  8. package/dist/collection/components/ui/kritzel-share-dialog/kritzel-share-dialog.css +17 -0
  9. package/dist/collection/components/ui/kritzel-share-dialog/kritzel-share-dialog.js +44 -3
  10. package/dist/collection/components/ui/kritzel-utility-panel/kritzel-utility-panel.js +1 -1
  11. package/dist/collection/components/ui/kritzel-zoom-panel/kritzel-zoom-panel.js +1 -1
  12. package/dist/collection/constants/version.js +1 -1
  13. package/dist/collection/themes/dark-theme.js +1 -0
  14. package/dist/collection/themes/light-theme.js +1 -0
  15. package/dist/components/index.js +1 -1
  16. package/dist/components/kritzel-awareness-cursors.js +1 -1
  17. package/dist/components/kritzel-color-palette.js +1 -1
  18. package/dist/components/kritzel-color.js +1 -1
  19. package/dist/components/kritzel-controls.js +1 -1
  20. package/dist/components/kritzel-editor.js +1 -1
  21. package/dist/components/kritzel-engine.js +1 -1
  22. package/dist/components/kritzel-export.js +1 -1
  23. package/dist/components/kritzel-pill-tabs.js +1 -1
  24. package/dist/components/kritzel-settings.js +1 -1
  25. package/dist/components/kritzel-share-dialog.js +1 -1
  26. package/dist/components/kritzel-stroke-size.js +1 -1
  27. package/dist/components/kritzel-tool-config.js +1 -1
  28. package/dist/components/kritzel-utility-panel.js +1 -1
  29. package/dist/components/kritzel-zoom-panel.js +1 -1
  30. package/dist/components/{p-DfIknZRl.js → p-2Swq9rEm.js} +1 -1
  31. package/dist/components/{p-C1jg5IQi.js → p-7ZnANv7C.js} +1 -1
  32. package/dist/components/{p-NwN6r0N0.js → p-8p1DKytO.js} +1 -1
  33. package/dist/components/p-BFTU3MAI.js +1 -0
  34. package/dist/components/{p-COhjyuRa.js → p-BUc0GFPj.js} +1 -1
  35. package/dist/components/{p-Dl3MwBL1.js → p-BVu03tNB.js} +1 -1
  36. package/dist/components/{p-C4-Som48.js → p-BcB97x3U.js} +1 -1
  37. package/dist/components/{p-14NPx-_P.js → p-BeHVCJ7n.js} +1 -1
  38. package/dist/components/p-BmyTdQGy.js +1 -0
  39. package/dist/components/{p-BmX2Vb4Z.js → p-BoA6RXEA.js} +1 -1
  40. package/dist/components/{p-vf28uSsc.js → p-CfS-5J9k.js} +1 -1
  41. package/dist/components/p-D09kgc5Q.js +1 -0
  42. package/dist/components/p-DJVRW9So.js +1 -0
  43. package/dist/components/{p-y5T0_Wvi.js → p-DYLBjStF.js} +1 -1
  44. package/dist/components/{p-FjazwgrY.js → p-DZ8yfhhf.js} +1 -1
  45. package/dist/components/p-vLVZEJXX.js +9 -0
  46. package/dist/components/{p-CO0eEzos.js → p-wl9BhN6s.js} +1 -1
  47. package/dist/esm/index.js +2 -2
  48. package/dist/esm/kritzel-active-users_45.entry.js +3122 -8
  49. package/dist/esm/loader.js +1 -1
  50. package/dist/esm/{schema.constants-CH2FWTVr.js → schema.constants-CDQonV1J.js} +5 -2
  51. package/dist/esm/stencil.js +1 -1
  52. package/dist/stencil/index.esm.js +1 -1
  53. package/dist/stencil/p-3289cc4e.entry.js +9 -0
  54. package/dist/stencil/p-CDQonV1J.js +1 -0
  55. package/dist/stencil/stencil.esm.js +1 -1
  56. package/dist/types/components/ui/kritzel-share-dialog/kritzel-share-dialog.d.ts +4 -0
  57. package/dist/types/constants/version.d.ts +1 -1
  58. package/dist/types/interfaces/theme.interface.d.ts +1 -0
  59. package/package.json +6 -4
  60. package/dist/components/p-BG6hOSrm.js +0 -1
  61. package/dist/components/p-Ckpa5tHF.js +0 -1
  62. package/dist/components/p-CpzicliK.js +0 -1
  63. package/dist/components/p-DK2ZByiU.js +0 -9
  64. package/dist/stencil/p-CH2FWTVr.js +0 -1
  65. package/dist/stencil/p-be38d770.entry.js +0 -9
@@ -1 +1 @@
1
- import{O as t}from"./p-Dd-pMvlr.js";import{a as i}from"./p-CpzicliK.js";class s{static doPolygonsIntersect(t,i){const s=[t.bottomLeft,t.bottomRight,t.topRight,t.topLeft],h=[i.bottomLeft,i.bottomRight,i.topRight,i.topLeft];for(const t of s)if(this.isPointInPolygon(t,h))return!0;for(const t of h)if(this.isPointInPolygon(t,s))return!0;for(let t=0;t<s.length;t++){const i=s[t],e=s[(t+1)%s.length];for(let t=0;t<h.length;t++)if(this.intersectLines(i,e,h[t],h[(t+1)%h.length]))return!0}return!1}static isPointInPolygon(t,i){let s=!1;for(let h=0,e=i.length-1;h<i.length;e=h++){const n=i[h].x,r=i[h].y,o=i[e].y;r>t.y!=o>t.y&&t.x<(i[e].x-n)*(t.y-r)/(o-r)+n&&(s=!s)}return s}static intersectLines(t,i,s,h){const e=(i.x-t.x)*(h.y-s.y)-(i.y-t.y)*(h.x-s.x);if(0===e)return!1;const n=((s.x-t.x)*(h.y-s.y)-(s.y-t.y)*(h.x-s.x))/e,r=-((t.x-s.x)*(i.y-t.y)-(t.y-s.y)*(i.x-t.x))/e;return n>=0&&n<=1&&r>=0&&r<=1}static getLineIntersectionPoint(t,i,s,h){const e=(i.x-t.x)*(h.y-s.y)-(i.y-t.y)*(h.x-s.x);if(0===e)return null;const n=((s.x-t.x)*(h.y-s.y)-(s.y-t.y)*(h.x-s.x))/e,r=-((t.x-s.x)*(i.y-t.y)-(t.y-s.y)*(i.x-t.x))/e;return n>=0&&n<=1&&r>=0&&r<=1?{x:t.x+n*(i.x-t.x),y:t.y+n*(i.y-t.y)}:null}static getLinePolygonIntersection(t,i,s){const h=[s.topLeft,s.topRight,s.bottomRight,s.bottomLeft];let e=null,n=1/0;for(let s=0;s<h.length;s++){const r=this.getLineIntersectionPoint(t,i,h[s],h[(s+1)%h.length]);if(r){const i=Math.sqrt(Math.pow(r.x-t.x,2)+Math.pow(r.y-t.y,2));i<n&&(n=i,e=r)}}return e}static getEllipsePolygonApproximation(t,i,s,h,e=32,n=0){const r=[],o=Math.cos(n),a=Math.sin(n);for(let n=0;n<e;n++){const u=2*Math.PI*n/e,l=s*Math.cos(u),c=h*Math.sin(u);r.push({x:t+l*o-c*a,y:i+l*a+c*o})}return r}static getLinePointsArrayIntersection(t,i,s){let h=null,e=1/0;for(let n=0;n<s.length;n++){const r=this.getLineIntersectionPoint(t,i,s[n],s[(n+1)%s.length]);if(r){const i=Math.sqrt(Math.pow(r.x-t.x,2)+Math.pow(r.y-t.y,2));i<e&&(e=i,h=r)}}return h}static isPointInPolygonPoints(t,i){return this.isPointInPolygon(t,i)}}class h{__class__="KritzelBaseObject";_core;_elementRef;id;workspaceId;x;y;translateX;translateY;height;width;backgroundColor;borderColor;borderWidth=0;opacity=1;padding=0;scale;resizing=!1;rotation=0;markedForRemoval=!1;zIndex=0;userId;isVisible=!0;isSelected=!1;isHovered=!1;isMounted=!1;isEditable=!1;isInteractive=!1;isResizable=!0;isRotatable=!0;get totalWidth(){return this.width+2*this.padding}get totalHeight(){return this.height+2*this.padding}set elementRef(t){this._elementRef=t}get elementRef(){return this._elementRef}get boundingBox(){return{x:this.translateX,y:this.translateY,z:this.scale,width:this.totalWidth/this.scale,height:this.totalHeight/this.scale}}get rotatedBoundingBox(){const t=this.rotatedPolygon,i=[t.topLeft.x,t.topRight.x,t.bottomRight.x,t.bottomLeft.x],s=[t.topLeft.y,t.topRight.y,t.bottomRight.y,t.bottomLeft.y],h=Math.min(...i),e=Math.max(...i),n=Math.min(...s),r=Math.max(...s);return{x:h,y:n,z:this.scale,width:e-h,height:r-n}}get rotatedPolygon(){const t=this.translateX+this.totalWidth/2/this.scale,i=this.translateY+this.totalHeight/2/this.scale,s=this.rotation,h=Math.cos(s),e=Math.sin(s),n=this.translateX,r=this.translateY,o=n+this.totalWidth/this.scale,a=r+this.totalHeight/this.scale,u=(s,n)=>({x:h*(s-t)-e*(n-i)+t,y:e*(s-t)+h*(n-i)+i});return{topLeft:u(n,r),topRight:u(o,r),bottomRight:u(o,a),bottomLeft:u(n,a)}}get minXRotated(){return Math.min(this.rotatedPolygon.topLeft.x,this.rotatedPolygon.topRight.x,this.rotatedPolygon.bottomRight.x,this.rotatedPolygon.bottomLeft.x)}get minYRotated(){return Math.min(this.rotatedPolygon.topLeft.y,this.rotatedPolygon.topRight.y,this.rotatedPolygon.bottomRight.y,this.rotatedPolygon.bottomLeft.y)}get maxXRotated(){return Math.max(this.rotatedPolygon.topLeft.x,this.rotatedPolygon.topRight.x,this.rotatedPolygon.bottomRight.x,this.rotatedPolygon.bottomLeft.x)}get maxYRotated(){return Math.max(this.rotatedPolygon.topLeft.y,this.rotatedPolygon.topRight.y,this.rotatedPolygon.bottomRight.y,this.rotatedPolygon.bottomLeft.y)}get transformationMatrix(){const t=1/this.scale;return`matrix(${t}, 0, 0, ${t}, ${this.translateX}, ${this.translateY})`}get rotationDegrees(){return this.rotation*(180/Math.PI)}get centerX(){return this.translateX+this.totalWidth/2/this.scale}get centerY(){return this.translateY+this.totalHeight/2/this.scale}constructor(){this.id=this.generateId()}static create(t){const i=new h;return i._core=t,i.zIndex=t.store.currentZIndex,i.workspaceId=t.store.state.activeWorkspace.id,i.userId=t.user?.id,i}mount(t){this.isMounted||(this.elementRef=t,this.isMounted=!0)}generateId(){return t.generateUUID()}isInViewport(){const t=this._core.store.state.scale;if(this.boundingBox.width*t*(this.boundingBox.height*t)<.5)return!1;const i=-this._core.store.state.translateX/this._core.store.state.scale,s=-this._core.store.state.translateY/this._core.store.state.scale;return this.rotatedBoundingBox.x<i+this._core.store.state.viewportWidth/this._core.store.state.scale&&this.rotatedBoundingBox.x+this.rotatedBoundingBox.width>i&&this.rotatedBoundingBox.y<s+this._core.store.state.viewportHeight/this._core.store.state.scale&&this.rotatedBoundingBox.y+this.rotatedBoundingBox.height>s}centerInViewport(){const{viewportWidth:t,viewportHeight:i,translateX:s,translateY:h,scale:e}=this._core.store.state,{x:n,y:r,width:o,height:a}=this.rotatedBoundingBox;this.updatePosition(this.translateX+((t/2-s)/e-(n+o/2)),this.translateY+((i/2-h)/e-(r+a/2)))}update(){this._core.store.objects.update(this)}move(t,i,s,h){const e=(i-h)/this._core.store.state.scale;this.translateX+=(t-s)/this._core.store.state.scale,this.translateY+=e,this._core.store.objects.update(this)}resize(t,i,s,h){s<=1||h<=1||(this.width=s,this.height=h,this.translateX=t,this.translateY=i,this._core.store.objects.update(this),this._core.anchorManager.updateAnchorsForObject(this.id))}rotate(t){this.rotation=t,this._core.store.objects.update(this)}clone(){const t=Object.create(Object.getPrototypeOf(this));return Object.assign(t,this),t.id=this.id,t}copy(){const t=Object.create(Object.getPrototypeOf(this));return Object.assign(t,this),t.id=this.generateId(),t.isMounted=!1,t.isSelected=!1,t.isHovered=!1,t.isInteractive=!1,t.resizing=!1,t.markedForRemoval=!1,t.isVisible=!0,t}serialize(){const{_core:t,_elementRef:i,element:s,totalWidth:h,totalHeight:e,isSelected:n,isHovered:r,isMounted:o,isInteractive:a,resizing:u,markedForRemoval:l,isVisible:c,...f}=this;return structuredClone(f)}deserialize(t){return Object.assign(this,t),this.isSelected=!1,this.isHovered=!1,this.isMounted=!1,this.isInteractive=!1,this.resizing=!1,this.markedForRemoval=!1,this.isVisible=!0,"_adjustedPoints"in this&&(this._adjustedPoints=null),"_clipInfo"in this&&(this._clipInfo=null),this}adoptTransientStateFrom(t){}isClass(t){return this.__class__===t}edit(t){}onAfterUpdate(t){}hitTest(t,i){return!0}hitTestPolygon(t){return s.doPolygonsIntersect(this.rotatedPolygon,t)}updatePosition(t,i){this.translateX=t,this.translateY=i,this._core.store.objects.update(this)}}class e{static average(t,i){return(t+i)/2}static degreesToRadians(t){return t*(Math.PI/180)}}var n,r={},o=(n||(n=1,function(t){Object.defineProperties(t,{__esModule:{value:!0},[Symbol.toStringTag]:{value:"Module"}});const{PI:i}=Math,s=i+1e-4,h=[1,1];function e(t,i,s,h=t=>t){return t*h(.5-i*(.5-s))}const{min:n}=Math;function r(t,i,s){let h=n(1,i/s);return n(1,t+(n(1,1-h)-t)*(.275*h))}function o(t,i){return[t[0]+i[0],t[1]+i[1]]}function a(t,i,s){return t[0]=i[0]+s[0],t[1]=i[1]+s[1],t}function u(t,i){return[t[0]-i[0],t[1]-i[1]]}function l(t,i,s){return t[0]=i[0]-s[0],t[1]=i[1]-s[1],t}function c(t,i){return[t[0]*i,t[1]*i]}function f(t,i,s){return t[0]=i[0]*s,t[1]=i[1]*s,t}function d(t){return[t[1],-t[0]]}function M(t,i){let s=i[0];return t[0]=i[1],t[1]=-s,t}function g(t,i){return t[0]*i[0]+t[1]*i[1]}function m(t,i){return t[0]===i[0]&&t[1]===i[1]}function p(t,i){let s=t[0]-i[0],h=t[1]-i[1];return s*s+h*h}function x(t){return function(t,i){return[t[0]/i,t[1]/i]}(t,function(t){return Math.hypot(t[0],t[1])}(t))}function y(t,i){return Math.hypot(t[1]-i[1],t[0]-i[0])}function v(t,i,s){let h=Math.sin(s),e=Math.cos(s),n=t[0]-i[0],r=t[1]-i[1];return[n*e-r*h+i[0],n*h+r*e+i[1]]}function P(t,i,s,h){let e=Math.sin(h),n=Math.cos(h),r=i[0]-s[0],o=i[1]-s[1],a=r*e+o*n;return t[0]=r*n-o*e+s[0],t[1]=a+s[1],t}function $(t,i,s){return o(t,c(u(i,t),s))}function b(t,i,s,h){let e=s[1]-i[1];return t[0]=i[0]+(s[0]-i[0])*h,t[1]=i[1]+e*h,t}function w(t,i,s){return o(t,c(i,s))}const z=[0,0],L=[0,0],_=[0,0];function I(t,i){let h=w(t,x(d(u(t,o(t,[1,1])))),-i),e=[],n=1/13;for(let i=n;i<=1;i+=n)e.push(v(h,t,2*s*i));return e}function X(t,i,h){let e=[],n=1/h;for(let h=n;h<=1;h+=n)e.push(v(i,t,s*h));return e}function Y(t,i,s){let h=u(i,s),e=c(h,.5),n=c(h,.51);return[u(t,e),u(t,n),o(t,n),o(t,e)]}function k(t,i,h,e){let n=[],r=w(t,i,h),o=1/e;for(let i=o;i<1;i+=o)n.push(v(r,t,3*s*i));return n}function R(t,i,s){return[o(t,c(i,s)),o(t,c(i,.99*s)),u(t,c(i,.99*s)),u(t,c(i,s))]}function j(t,i,s){return!1===t||void 0===t?0:!0===t?Math.max(i,s):t}function A(t,i={}){let{size:h=16,smoothing:n=.5,thinning:c=.5,simulatePressure:m=!0,easing:x=t=>t,start:y={},end:v={},last:$=!1}=i,{cap:w=!0,easing:A=t=>t*(2-t)}=y,{cap:B=!0,easing:S=t=>--t*t*t+1}=v;if(0===t.length||h<=0)return[];let T,C=t[t.length-1].runningLength,O=j(y.taper,h,C),D=j(v.taper,h,C),V=(h*n)**2,W=[],F=[],H=function(t,i,s){return t.slice(0,10).reduce(((t,h)=>{let e=h.pressure;return i&&(e=r(t,h.distance,s)),(t+e)/2}),t[0].pressure)}(t,m,h),K=e(h,c,t[t.length-1].pressure,x),E=t[0].vector,Q=t[0].point,U=Q,Z=Q,q=U,G=!1;for(let i=0;i<t.length;i++){let{pressure:n}=t[i],{point:d,vector:y,distance:v,runningLength:$}=t[i],w=i===t.length-1;if(!w&&C-$<3)continue;c?(m&&(n=r(H,v,h)),K=e(h,c,n,x)):K=h/2,void 0===T&&(T=K);let I=$<O?A($/O):1,X=C-$<D?S((C-$)/D):1;K=Math.max(.01,K*Math.min(I,X));let Y=(w?t[i]:t[i+1]).vector,k=w?1:g(y,Y),R=null!==k&&k<0;if(g(y,E)<0&&!G||R){M(z,E),f(z,z,K);for(let t=0;t<=1;t+=.07692307692307693)l(L,d,z),P(L,L,d,s*t),Z=[L[0],L[1]],W.push(Z),a(_,d,z),P(_,_,d,s*-t),q=[_[0],_[1]],F.push(q);Q=Z,U=q,R&&(G=!0)}else G=!1,w?(M(z,y),f(z,z,K),W.push(u(d,z)),F.push(o(d,z))):(b(z,Y,y,k),M(z,z),f(z,z,K),l(L,d,z),Z=[L[0],L[1]],(i<=1||p(Q,Z)>V)&&(W.push(Z),Q=Z),a(_,d,z),q=[_[0],_[1]],(i<=1||p(U,q)>V)&&(F.push(q),U=q),H=n,E=y)}let J=[t[0].point[0],t[0].point[1]],N=t.length>1?[t[t.length-1].point[0],t[t.length-1].point[1]]:o(t[0].point,[1,1]),tt=[],it=[];if(1===t.length){if(!O&&!D||$)return I(J,T||K)}else{O||D&&1===t.length||(w?tt.push(...X(J,F[0],13)):tt.push(...Y(J,W[0],F[0])));let i=d(function(t){return[-t[0],-t[1]]}(t[t.length-1].vector));D||O&&1===t.length?it.push(N):B?it.push(...k(N,i,K,29)):it.push(...R(N,i,K))}return W.concat(it,F.reverse(),tt)}const B=[0,0];function S(t){return null!=t&&t>=0}function T(t,i={}){let{streamline:s=.5,size:e=16,last:n=!1}=i;if(0===t.length)return[];let r=.15+.85*(1-s),a=Array.isArray(t[0])?t:t.map((({x:t,y:i,pressure:s=.5})=>[t,i,s]));if(2===a.length){let t=a[1];a=a.slice(0,-1);for(let i=1;i<5;i++)a.push($(a[0],t,i/4))}1===a.length&&(a=[...a,[...o(a[0],h),...a[0].slice(2)]]);let u=[{point:[a[0][0],a[0][1]],pressure:S(a[0][2])?a[0][2]:.25,vector:[...h],distance:0,runningLength:0}],c=!1,f=0,d=u[0],M=a.length-1;for(let t=1;t<a.length;t++){let i=n&&t===M?[a[t][0],a[t][1]]:$(d.point,a[t],r);if(m(d.point,i))continue;let s=y(i,d.point);if(f+=s,t<M&&!c){if(f<e)continue;c=!0}l(B,d.point,i),d={point:i,pressure:S(a[t][2])?a[t][2]:.5,vector:x(B),distance:s,runningLength:f},u.push(d)}return u[0].vector=u[1]?.vector||[0,0],u}function C(t,i={}){return A(T(t,i),i)}t.default=C,t.getStroke=C,t.getStrokeOutlinePoints=A,t.getStrokePoints=T}(r)),r);class a extends h{__class__="KritzelPath";points;d;stroke={light:"none",dark:"none"};strokeWidth;lineSlack=.5;fill;x=0;y=0;height=0;width=0;scale=1;options;isVisible=!0;isDebugInfoVisible=!0;isCompleted=!1;_adjustedPoints=null;get viewBox(){return`${this.x} ${this.y} ${this.width} ${this.height}`}constructor(t){super(),this.options=t,this.points=t?.points??[],this.translateX=t?.translateX??0,this.translateY=t?.translateY??0,this.rotation=e.degreesToRadians(t?.rotation??0),this.scale=t?.scale??1,this.strokeWidth=t?.strokeWidth??8,this.fill=t?.fill??{light:"#000000",dark:"#ffffff"},this.d=this.generateSvgPath(),this.updateDimensions()}static create(t,i){const s=new a;return s._core=t,s.id=s.generateId(),s.workspaceId=t.store.state.activeWorkspace.id,s.userId=t.user?.id,s.options=i,s.points=i?.points??[],s.translateX=i?.translateX??0,s.translateY=i?.translateY??0,s.rotation=e.degreesToRadians(i?.rotation??0),s.scale=i?.scale??1,s.strokeWidth=i?.strokeWidth??8,s.fill=i?.fill??{light:"#000000",dark:"#ffffff"},s.opacity=i?.opacity??1,s.zIndex=t.store.currentZIndex,s.d=s.generateSvgPath(),s.updateDimensions(),s}copy(){const t=super.copy();return this.points&&(t.points=this.points.map((t=>[...t]))),t}resize(t,i,s,h){if(s<=1||h<=1)return;const e=s/this.width,n=h/this.height;if(this.width=s,this.height=h,1===this.points.length){const t=this.points[0],i=Math.max(0,s-this.strokeWidth)/e,r=Math.max(0,h-this.strokeWidth)/n;this.points.push([t[0]+i,t[1]+r])}this.points=this.points.map((([t,i])=>[t*e,i*n])),this.d=this.generateSvgPath(),this.width=Math.max(...this.points.map((t=>t[0])))-Math.min(...this.points.map((t=>t[0])))+this.strokeWidth,this.height=Math.max(...this.points.map((t=>t[1])))-Math.min(...this.points.map((t=>t[1])))+this.strokeWidth,this.x=Math.min(...this.points.map((t=>t[0])))-this.strokeWidth/2,this.y=Math.min(...this.points.map((t=>t[1])))-this.strokeWidth/2,null!==t&&(this.translateX=t),null!==i&&(this.translateY=i),this._adjustedPoints=null,this._core.store.objects.update(this)}rotate(t){this.rotation=t,this._adjustedPoints=null,this._core.store.objects.update(this)}move(t,i,s,h){const e=(i-h)/this._core.store.state.scale;this.translateX+=(t-s)/this._core.store.state.scale,this.translateY+=e,this._adjustedPoints=null,this._core.store.objects.update(this)}hitTest(t,i){const s=this.strokeWidth/this.scale/2;if(null===this._adjustedPoints&&(this._adjustedPoints=this.computeAdjustedPoints()),1===this._adjustedPoints.length){const h=this._adjustedPoints[0];return this.pointToLineSegmentDistance(t,i,h[0],h[1],h[0],h[1])<=s}for(let h=0;h<this._adjustedPoints.length-1;h++){const e=this._adjustedPoints[h],n=this._adjustedPoints[h+1];if(this.pointToLineSegmentDistance(t,i,e[0],e[1],n[0],n[1])<=s)return!0}return!1}hitTestPolygon(t){const i=this.strokeWidth/this.scale/2;null===this._adjustedPoints&&(this._adjustedPoints=this.computeAdjustedPoints());const h=[{x:t.bottomLeft.x,y:t.bottomLeft.y},{x:t.bottomRight.x,y:t.bottomRight.y},{x:t.topRight.x,y:t.topRight.y},{x:t.topLeft.x,y:t.topLeft.y}];for(const[t,i]of this._adjustedPoints)if(s.isPointInPolygon({x:t,y:i},h))return!0;for(const t of h)if(this.hitTest(t.x,t.y))return!0;for(let t=0;t<this._adjustedPoints.length-1;t++){const i={x:this._adjustedPoints[t][0],y:this._adjustedPoints[t][1]},e={x:this._adjustedPoints[t+1][0],y:this._adjustedPoints[t+1][1]};for(let t=0;t<h.length;t++)if(s.intersectLines(i,e,h[t],h[(t+1)%h.length]))return!0}for(let t=0;t<this._adjustedPoints.length-1;t++){const s=this._adjustedPoints[t],e=this._adjustedPoints[t+1];for(let t=0;t<h.length;t++){const n=h[t],r=h[(t+1)%h.length],o=this.pointToLineSegmentDistance(n.x,n.y,s[0],s[1],e[0],e[1]),a=this.pointToLineSegmentDistance(r.x,r.y,s[0],s[1],e[0],e[1]),u=this.pointToLineSegmentDistance(s[0],s[1],n.x,n.y,r.x,r.y),l=this.pointToLineSegmentDistance(e[0],e[1],n.x,n.y,r.x,r.y);if(Math.min(o,a,u,l)<=i)return!0}}return!1}updatePosition(t,i){this.translateX=t,this.translateY=i,this._adjustedPoints=null,this._core.store.objects.update(this)}onAfterUpdate(t){t.includes("strokeWidth")&&(this.d=this.generateSvgPath(),this.updateBoundingBox(),this._adjustedPoints=null)}computeAdjustedPoints(){if(!this.points?.length)return[];const t=this.rotation,i=Math.cos(t),s=Math.sin(t),h=this.points.map((t=>t[0])),e=this.points.map((t=>t[1])),n={x:(Math.min(...h)+Math.max(...h))/2,y:(Math.min(...e)+Math.max(...e))/2},{x:r,y:o}=n;return this.points.map((([t,h])=>{const e=t-r,n=h-o;return[r+e*i-n*s,o+e*s+n*i]})).map((([t,i])=>[Math.abs(t-this.x)/this.scale+this.translateX,Math.abs(i-this.y)/this.scale+this.translateY]))}pointToLineSegmentDistance(t,i,s,h,e,n){const r=e-s,o=n-h,a=r*r+o*o;let u,l,c=-1;0!==a&&(c=((t-s)*r+(i-h)*o)/a),c<0?(u=s,l=h):c>1?(u=e,l=n):(u=s+c*r,l=h+c*o);const f=t-u,d=i-l;return Math.sqrt(f*f+d*d)}updateDimensions(){const t=Math.min(...this.points.map((t=>t[0])))-this.strokeWidth/2,i=Math.min(...this.points.map((t=>t[1])))-this.strokeWidth/2,s=Math.max(...this.points.map((t=>t[0])))+this.strokeWidth/2,h=Math.max(...this.points.map((t=>t[1])))+this.strokeWidth/2;this.width=s-t+this.lineSlack,this.height=h-i+this.lineSlack,this.x=t,this.y=i,this.translateX=(this.x+this.translateX)/this.scale,this.translateY=(this.y+this.translateY)/this.scale}updateBoundingBox(){const t=Math.min(...this.points.map((t=>t[0])))-this.strokeWidth/2,i=Math.min(...this.points.map((t=>t[1])))-this.strokeWidth/2,s=Math.max(...this.points.map((t=>t[0])))+this.strokeWidth/2,h=Math.max(...this.points.map((t=>t[1])))+this.strokeWidth/2;this.width=s-t+this.lineSlack,this.height=h-i+this.lineSlack,this.x=t,this.y=i}generateSvgPath(){const t=this.getStrokeFromPoints(this.points,this.strokeWidth);return this.getSvgPathFromStroke(t)}getStrokeFromPoints(t,i){return o.getStroke(t,{size:i,thinning:.5,smoothing:.5,streamline:.5,easing:t=>t,simulatePressure:!0,last:!0,start:{cap:!0,taper:0,easing:t=>t},end:{cap:!0,taper:0,easing:t=>t}})}getSvgPathFromStroke(t,i=!0){const s=t.length;if(s<4)return"";let h=t[0],n=t[1];const r=t[2];let o=`M${h[0].toFixed(2)},${h[1].toFixed(2)} Q${n[0].toFixed(2)},${n[1].toFixed(2)} ${e.average(n[0],r[0]).toFixed(2)},${e.average(n[1],r[1]).toFixed(2)} T`;for(let i=2,r=s-1;i<r;i++)h=t[i],n=t[i+1],o+=`${e.average(h[0],n[0]).toFixed(2)},${e.average(h[1],n[1]).toFixed(2)} `;return i&&(o+="Z"),o}isLowRes(){if(!this._core)return!1;const t=this._core.store.state.scale;return this.boundingBox.width*t*(this.boundingBox.height*t)<500}getClipPoint(t){const i=this.centerX,s=this.centerY,h=this.strokeWidth/this.scale/2;if(null===this._adjustedPoints&&(this._adjustedPoints=this.computeAdjustedPoints()),this._adjustedPoints.length<1)return null;let e=!0;for(let n=1;n<=32;n++){const r=n/32,o=t.x+(i-t.x)*r,a=t.y+(s-t.y)*r;let u=1/0;if(1===this._adjustedPoints.length){const t=this._adjustedPoints[0],i=o-t[0],s=a-t[1];u=Math.sqrt(i*i+s*s)}else for(let t=0;t<this._adjustedPoints.length-1;t++){const i=this._adjustedPoints[t],s=this._adjustedPoints[t+1],h=this.pointToLineSegmentDistance(o,a,i[0],i[1],s[0],s[1]);h<u&&(u=h)}const l=u<=h;if(e&&l){let e=(n-1)/32,o=r;for(let n=0;n<8;n++){const n=(e+o)/2,r=t.x+(i-t.x)*n,a=t.y+(s-t.y)*n;let u=1/0;if(1===this._adjustedPoints.length){const t=this._adjustedPoints[0],i=r-t[0],s=a-t[1];u=Math.sqrt(i*i+s*s)}else for(let t=0;t<this._adjustedPoints.length-1;t++){const i=this._adjustedPoints[t],s=this._adjustedPoints[t+1],h=this.pointToLineSegmentDistance(r,a,i[0],i[1],s[0],s[1]);h<u&&(u=h)}u<=h?o=n:e=n}const a=(e+o)/2;return{x:t.x+(i-t.x)*a,y:t.y+(s-t.y)*a}}e=!l}return null}}class u extends h{__class__="KritzelLine";startX;startY;endX;endY;controlX;controlY;stroke;strokeWidth;scale=1;options;startAnchor;endAnchor;arrows;isVisible=!0;isDebugInfoVisible=!0;isCompleted=!1;_adjustedPoints=null;_clipInfo=null;get d(){return void 0!==this.controlX&&void 0!==this.controlY?`M ${this.startX} ${this.startY} Q ${this.controlX} ${this.controlY} ${this.endX} ${this.endY}`:`M ${this.startX} ${this.startY} L ${this.endX} ${this.endY}`}get viewBox(){return`${this.x} ${this.y} ${this.width} ${this.height}`}constructor(t){super(),this.options=t,this.startX=t?.startX??0,this.startY=t?.startY??0,this.endX=t?.endX??0,this.endY=t?.endY??0,this.controlX=t?.controlX,this.controlY=t?.controlY,this.translateX=t?.translateX??0,this.translateY=t?.translateY??0,this.rotation=e.degreesToRadians(t?.rotation??0),this.scale=t?.scale??1,this.strokeWidth=t?.strokeWidth??4,this.stroke=t?.stroke??{light:"#000000",dark:"#ffffff"},this.startAnchor=t?.startAnchor,this.endAnchor=t?.endAnchor,this.arrows=t?.arrows,this.updateDimensions()}static create(t,i){const s=new u;return s._core=t,s.id=s.generateId(),s.workspaceId=t.store.state.activeWorkspace.id,s.userId=t.user?.id,s.options=i,s.startX=i?.startX??0,s.startY=i?.startY??0,s.endX=i?.endX??0,s.endY=i?.endY??0,s.controlX=i?.controlX,s.controlY=i?.controlY,s.translateX=i?.translateX??0,s.translateY=i?.translateY??0,s.rotation=e.degreesToRadians(i?.rotation??0),s.scale=i?.scale??1,s.strokeWidth=i?.strokeWidth??4,s.stroke=i?.stroke??{light:"#000000",dark:"#ffffff"},s.opacity=i?.opacity??1,s.startAnchor=i?.startAnchor,s.endAnchor=i?.endAnchor,s.arrows=i?.arrows,s.zIndex=t.store.currentZIndex,s.updateDimensions(),s}resize(t,i,s,h){if(s<=1||h<=1)return;const e=s/this.width,n=h/this.height;this.startX=this.startX*e,this.startY=this.startY*n,this.endX=this.endX*e,this.endY=this.endY*n,void 0!==this.controlX&&void 0!==this.controlY&&(this.controlX=this.controlX*e,this.controlY=this.controlY*n);const{minX:r,minY:o,maxX:a,maxY:u}=this.calculateBoundingBox();this.width=a-r,this.height=u-o,this.x=r,this.y=o,this.translateX=t,this.translateY=i,this._adjustedPoints=null,this._clipInfo=null,this._core.store.objects.update(this),this._core.anchorManager.updateAnchorsForObject(this.id),this.startAnchor&&this._core.anchorManager.updateAnchorsForObject(this.startAnchor.objectId),this.endAnchor&&this._core.anchorManager.updateAnchorsForObject(this.endAnchor.objectId)}rotate(t){this.rotation=t,this._adjustedPoints=null,this._clipInfo=null,this._core.store.objects.update(this)}move(t,i,s,h){const e=(i-h)/this._core.store.state.scale;this.translateX+=(t-s)/this._core.store.state.scale,this.translateY+=e,this.startAnchor&&this._core.anchorManager.updateAnchorsForObject(this.startAnchor.objectId),this.endAnchor&&this._core.anchorManager.updateAnchorsForObject(this.endAnchor.objectId),this._adjustedPoints=null,this._clipInfo=null,this._core.store.objects.update(this)}hitTest(t,i){const s=Math.max(this.strokeWidth,20)/this.scale/2;if(null===this._adjustedPoints&&(this._adjustedPoints=this.computeAdjustedPoints()),void 0!==this.controlX&&void 0!==this.controlY){const h=this.getClipInfo();return this.pointToBezierDistance(t,i,h.start?.t??0,h.end?.t??1)<=s}const h=this.getClipInfo(),e=h.start?[h.start.x,h.start.y]:this._adjustedPoints[0],n=h.end?[h.end.x,h.end.y]:this._adjustedPoints[1];return this.pointToLineSegmentDistance(t,i,e[0],e[1],n[0],n[1])<=s}hitTestPolygon(t){const i=this.strokeWidth/this.scale/2;null===this._adjustedPoints&&(this._adjustedPoints=this.computeAdjustedPoints());const h=this.getClipInfo(),e=[{x:t.bottomLeft.x,y:t.bottomLeft.y},{x:t.bottomRight.x,y:t.bottomRight.y},{x:t.topRight.x,y:t.topRight.y},{x:t.topLeft.x,y:t.topLeft.y}],n=h.start?[h.start.x,h.start.y]:this._adjustedPoints[0],r=h.end?[h.end.x,h.end.y]:this._adjustedPoints[1],o=[n,r];for(const[t,i]of o)if(s.isPointInPolygon({x:t,y:i},e))return!0;for(const t of e)if(this.hitTest(t.x,t.y))return!0;if(void 0!==this.controlX&&void 0!==this.controlY){const t=this._adjustedPoints[0],n=this._adjustedPoints[1],r=this.computeAdjustedControlPoint(),o=h.start?.t??0,a=h.end?.t??1,u=20;for(let h=0;h<=u;h++){const l=o+h/u*(a-o),c=1-l,f=c*c*t[0]+2*c*l*r[0]+l*l*n[0],d=c*c*t[1]+2*c*l*r[1]+l*l*n[1];if(s.isPointInPolygon({x:f,y:d},e))return!0;for(let t=0;t<e.length;t++){const s=e[t],h=e[(t+1)%e.length];if(this.pointToLineSegmentDistance(f,d,s.x,s.y,h.x,h.y)<=i)return!0}}return!1}const a={x:n[0],y:n[1]},u={x:r[0],y:r[1]};for(let t=0;t<e.length;t++){const h=e[t],n=e[(t+1)%e.length];if(s.intersectLines(a,u,h,n))return!0;const r=this.pointToLineSegmentDistance(h.x,h.y,a.x,a.y,u.x,u.y),o=this.pointToLineSegmentDistance(n.x,n.y,a.x,a.y,u.x,u.y),l=this.pointToLineSegmentDistance(a.x,a.y,h.x,h.y,n.x,n.y),c=this.pointToLineSegmentDistance(u.x,u.y,h.x,h.y,n.x,n.y);if(Math.min(r,o,l,c)<=i)return!0}return!1}updatePosition(t,i){this.translateX=t,this.translateY=i,this._adjustedPoints=null,this._clipInfo=null,this._core.store.objects.update(this)}updateEndpoint(t,i,s){"start"===t?(this.startX=i,this.startY=s):(this.endX=i,this.endY=s);const h=this.width,e=this.height,{minX:n,minY:r,maxX:o,maxY:a}=this.calculateBoundingBox(),u=n-this.x,l=r-this.y,c=o-n,f=a-r,d=(c-h)/2,M=(f-e)/2;this.x=n,this.y=r,this.width=c,this.height=f;const g=Math.cos(this.rotation),m=Math.sin(this.rotation),p=u+d,x=l+M,y=p*m+x*g-M;this.translateX+=(p*g-x*m-d)/this.scale,this.translateY+=y/this.scale,this._adjustedPoints=null,this._clipInfo=null,this._core.store.objects.update(this)}updateControlPoint(t,i){this.controlX=t,this.controlY=i;const s=this.width,h=this.height,{minX:e,minY:n,maxX:r,maxY:o}=this.calculateBoundingBox(),a=e-this.x,u=n-this.y,l=r-e,c=o-n,f=(l-s)/2,d=(c-h)/2;this.x=e,this.y=n,this.width=l,this.height=c;const M=Math.cos(this.rotation),g=Math.sin(this.rotation),m=a+f,p=u+d,x=m*g+p*M-d;this.translateX+=(m*M-p*g-f)/this.scale,this.translateY+=x/this.scale,this._adjustedPoints=null,this._clipInfo=null,this._core.store.objects.update(this)}computeAdjustedPoints(){const t=[[this.startX,this.startY],[this.endX,this.endY]],i=this.rotation,s=Math.cos(i),h=Math.sin(i),e=t.map((t=>t[0])),n=t.map((t=>t[1])),r={x:(Math.min(...e)+Math.max(...e))/2,y:(Math.min(...n)+Math.max(...n))/2},{x:o,y:a}=r;return t.map((([t,i])=>{const e=t-o,n=i-a;return[o+e*s-n*h,a+e*h+n*s]})).map((([t,i])=>[(t-this.x)/this.scale+this.translateX,(i-this.y)/this.scale+this.translateY]))}pointToLineSegmentDistance(t,i,s,h,e,n){const r=e-s,o=n-h,a=r*r+o*o;let u,l,c=-1;0!==a&&(c=((t-s)*r+(i-h)*o)/a),c<0?(u=s,l=h):c>1?(u=e,l=n):(u=s+c*r,l=h+c*o);const f=t-u,d=i-l;return Math.sqrt(f*f+d*d)}pointToBezierDistance(t,i,s=0,h=1){null===this._adjustedPoints&&(this._adjustedPoints=this.computeAdjustedPoints());const e=this._adjustedPoints[0],n=this._adjustedPoints[1],r=this.computeAdjustedControlPoint();let o=1/0;for(let a=0;a<=20;a++){const u=s+a/20*(h-s),l=1-u,c=t-(l*l*e[0]+2*l*u*r[0]+u*u*n[0]),f=i-(l*l*e[1]+2*l*u*r[1]+u*u*n[1]),d=Math.sqrt(c*c+f*f);d<o&&(o=d)}return o}getClipInfo(){if(this._clipInfo)return this._clipInfo;const t=this.endAnchor,i={};if(this.startAnchor){const t=this._core.anchorManager.findAnchorTarget(this,"start");if(t){const s=this._core.anchorManager.computeAnchorClipInfo(this,"start",t);s&&(i.start={x:s.worldX,y:s.worldY,t:s.t})}}if(t){const t=this._core.anchorManager.findAnchorTarget(this,"end");if(t){const s=this._core.anchorManager.computeAnchorClipInfo(this,"end",t);s&&(i.end={x:s.worldX,y:s.worldY,t:s.t})}}return this._clipInfo=i,i}computeAdjustedControlPoint(){if(void 0===this.controlX||void 0===this.controlY)return[(this.startX+this.endX)/2,(this.startY+this.endY)/2];const t=this.rotation,i=Math.cos(t),s=Math.sin(t),h=[this.startX,this.endX],e=[this.startY,this.endY],n={x:(Math.min(...h)+Math.max(...h))/2,y:(Math.min(...e)+Math.max(...e))/2},{x:r,y:o}=n,a=this.controlX-r,u=this.controlY-o;return[(r+a*i-u*s-this.x)/this.scale+this.translateX,(o+a*s+u*i-this.y)/this.scale+this.translateY]}get rotatedPolygon(){const t=this.padding,{minX:i,minY:s,maxX:h,maxY:e}=u.calculateBoundingBox(this.startX,this.startY,this.endX,this.endY,this.controlX,this.controlY,this.strokeWidth),n=i-this.x+t,r=s-this.y+t,o=h-this.x+t,a=e-this.y+t,l={x:n,y:r},c={x:o,y:r},f={x:o,y:a},d={x:n,y:a},M=this.totalWidth/2,g=this.totalHeight/2,m=this.rotation,p=Math.cos(m),x=Math.sin(m),y=t=>({x:((t.x-M)*p-(t.y-g)*x+M)/this.scale+this.translateX,y:((t.x-M)*x+(t.y-g)*p+g)/this.scale+this.translateY});return{topLeft:y(l),topRight:y(c),bottomRight:y(f),bottomLeft:y(d)}}static calculateBoundingBox(t,i,s,h,e,n,r){let o=Math.min(t,s),a=Math.min(i,h),u=Math.max(t,s),l=Math.max(i,h);if(void 0!==e&&void 0!==n){const r=t-2*e+s;if(0!==r){const i=(t-e)/r;if(i>0&&i<1){const h=(1-i)*(1-i)*t+2*(1-i)*i*e+i*i*s;o=Math.min(o,h),u=Math.max(u,h)}}const c=i-2*n+h;if(0!==c){const t=(i-n)/c;if(t>0&&t<1){const s=(1-t)*(1-t)*i+2*(1-t)*t*n+t*t*h;a=Math.min(a,s),l=Math.max(l,s)}}}const c=r/2;return{minX:o-c,minY:a-c,maxX:u+c,maxY:l+c}}calculateBoundingBox(){return u.calculateBoundingBox(this.startX,this.startY,this.endX,this.endY,this.controlX,this.controlY,this.strokeWidth)}serialize(){const t=super.serialize();return delete t._adjustedPoints,delete t._clipInfo,t}deserialize(t){const i=super.deserialize(t);return this._adjustedPoints=null,this._clipInfo=null,i}updateDimensions(){const{minX:t,minY:i,maxX:s,maxY:h}=this.calculateBoundingBox();this.width=s-t,this.height=h-i,this.x=t,this.y=i,this.translateX=(this.x+this.translateX)/this.scale,this.translateY=(this.y+this.translateY)/this.scale}get startMarkerId(){return`arrow-start-${this.id}`}get endMarkerId(){return`arrow-end-${this.id}`}getArrowSize(t){const i="start"===t?this.arrows?.start:this.arrows?.end;return i?.size??3*this.strokeWidth}getArrowFill(t){const s="start"===t?this.arrows?.start:this.arrows?.end;return i.resolveThemeColor(s?.fill??this.stroke)}getArrowPath(t="triangle"){switch(t){case"triangle":default:return"M 0 0 L 10 5 L 0 10 z";case"open":return"M 0 0 L 10 5 L 0 10";case"diamond":return"M 0 5 L 5 0 L 10 5 L 5 10 z";case"circle":return"M 5,0 A 5,5 0 1,1 5,10 A 5,5 0 1,1 5,0"}}get hasStartArrow(){return!0===this.arrows?.start?.enabled}get hasEndArrow(){return!0===this.arrows?.end?.enabled}}export{h as K,a,u as b,e as c,s as d}
1
+ import{O as t}from"./p-Dd-pMvlr.js";import{a as i}from"./p-BmyTdQGy.js";class s{static doPolygonsIntersect(t,i){const s=[t.bottomLeft,t.bottomRight,t.topRight,t.topLeft],h=[i.bottomLeft,i.bottomRight,i.topRight,i.topLeft];for(const t of s)if(this.isPointInPolygon(t,h))return!0;for(const t of h)if(this.isPointInPolygon(t,s))return!0;for(let t=0;t<s.length;t++){const i=s[t],e=s[(t+1)%s.length];for(let t=0;t<h.length;t++)if(this.intersectLines(i,e,h[t],h[(t+1)%h.length]))return!0}return!1}static isPointInPolygon(t,i){let s=!1;for(let h=0,e=i.length-1;h<i.length;e=h++){const n=i[h].x,r=i[h].y,o=i[e].y;r>t.y!=o>t.y&&t.x<(i[e].x-n)*(t.y-r)/(o-r)+n&&(s=!s)}return s}static intersectLines(t,i,s,h){const e=(i.x-t.x)*(h.y-s.y)-(i.y-t.y)*(h.x-s.x);if(0===e)return!1;const n=((s.x-t.x)*(h.y-s.y)-(s.y-t.y)*(h.x-s.x))/e,r=-((t.x-s.x)*(i.y-t.y)-(t.y-s.y)*(i.x-t.x))/e;return n>=0&&n<=1&&r>=0&&r<=1}static getLineIntersectionPoint(t,i,s,h){const e=(i.x-t.x)*(h.y-s.y)-(i.y-t.y)*(h.x-s.x);if(0===e)return null;const n=((s.x-t.x)*(h.y-s.y)-(s.y-t.y)*(h.x-s.x))/e,r=-((t.x-s.x)*(i.y-t.y)-(t.y-s.y)*(i.x-t.x))/e;return n>=0&&n<=1&&r>=0&&r<=1?{x:t.x+n*(i.x-t.x),y:t.y+n*(i.y-t.y)}:null}static getLinePolygonIntersection(t,i,s){const h=[s.topLeft,s.topRight,s.bottomRight,s.bottomLeft];let e=null,n=1/0;for(let s=0;s<h.length;s++){const r=this.getLineIntersectionPoint(t,i,h[s],h[(s+1)%h.length]);if(r){const i=Math.sqrt(Math.pow(r.x-t.x,2)+Math.pow(r.y-t.y,2));i<n&&(n=i,e=r)}}return e}static getEllipsePolygonApproximation(t,i,s,h,e=32,n=0){const r=[],o=Math.cos(n),a=Math.sin(n);for(let n=0;n<e;n++){const u=2*Math.PI*n/e,l=s*Math.cos(u),c=h*Math.sin(u);r.push({x:t+l*o-c*a,y:i+l*a+c*o})}return r}static getLinePointsArrayIntersection(t,i,s){let h=null,e=1/0;for(let n=0;n<s.length;n++){const r=this.getLineIntersectionPoint(t,i,s[n],s[(n+1)%s.length]);if(r){const i=Math.sqrt(Math.pow(r.x-t.x,2)+Math.pow(r.y-t.y,2));i<e&&(e=i,h=r)}}return h}static isPointInPolygonPoints(t,i){return this.isPointInPolygon(t,i)}}class h{__class__="KritzelBaseObject";_core;_elementRef;id;workspaceId;x;y;translateX;translateY;height;width;backgroundColor;borderColor;borderWidth=0;opacity=1;padding=0;scale;resizing=!1;rotation=0;markedForRemoval=!1;zIndex=0;userId;isVisible=!0;isSelected=!1;isHovered=!1;isMounted=!1;isEditable=!1;isInteractive=!1;isResizable=!0;isRotatable=!0;get totalWidth(){return this.width+2*this.padding}get totalHeight(){return this.height+2*this.padding}set elementRef(t){this._elementRef=t}get elementRef(){return this._elementRef}get boundingBox(){return{x:this.translateX,y:this.translateY,z:this.scale,width:this.totalWidth/this.scale,height:this.totalHeight/this.scale}}get rotatedBoundingBox(){const t=this.rotatedPolygon,i=[t.topLeft.x,t.topRight.x,t.bottomRight.x,t.bottomLeft.x],s=[t.topLeft.y,t.topRight.y,t.bottomRight.y,t.bottomLeft.y],h=Math.min(...i),e=Math.max(...i),n=Math.min(...s),r=Math.max(...s);return{x:h,y:n,z:this.scale,width:e-h,height:r-n}}get rotatedPolygon(){const t=this.translateX+this.totalWidth/2/this.scale,i=this.translateY+this.totalHeight/2/this.scale,s=this.rotation,h=Math.cos(s),e=Math.sin(s),n=this.translateX,r=this.translateY,o=n+this.totalWidth/this.scale,a=r+this.totalHeight/this.scale,u=(s,n)=>({x:h*(s-t)-e*(n-i)+t,y:e*(s-t)+h*(n-i)+i});return{topLeft:u(n,r),topRight:u(o,r),bottomRight:u(o,a),bottomLeft:u(n,a)}}get minXRotated(){return Math.min(this.rotatedPolygon.topLeft.x,this.rotatedPolygon.topRight.x,this.rotatedPolygon.bottomRight.x,this.rotatedPolygon.bottomLeft.x)}get minYRotated(){return Math.min(this.rotatedPolygon.topLeft.y,this.rotatedPolygon.topRight.y,this.rotatedPolygon.bottomRight.y,this.rotatedPolygon.bottomLeft.y)}get maxXRotated(){return Math.max(this.rotatedPolygon.topLeft.x,this.rotatedPolygon.topRight.x,this.rotatedPolygon.bottomRight.x,this.rotatedPolygon.bottomLeft.x)}get maxYRotated(){return Math.max(this.rotatedPolygon.topLeft.y,this.rotatedPolygon.topRight.y,this.rotatedPolygon.bottomRight.y,this.rotatedPolygon.bottomLeft.y)}get transformationMatrix(){const t=1/this.scale;return`matrix(${t}, 0, 0, ${t}, ${this.translateX}, ${this.translateY})`}get rotationDegrees(){return this.rotation*(180/Math.PI)}get centerX(){return this.translateX+this.totalWidth/2/this.scale}get centerY(){return this.translateY+this.totalHeight/2/this.scale}constructor(){this.id=this.generateId()}static create(t){const i=new h;return i._core=t,i.zIndex=t.store.currentZIndex,i.workspaceId=t.store.state.activeWorkspace.id,i.userId=t.user?.id,i}mount(t){this.isMounted||(this.elementRef=t,this.isMounted=!0)}generateId(){return t.generateUUID()}isInViewport(){const t=this._core.store.state.scale;if(this.boundingBox.width*t*(this.boundingBox.height*t)<.5)return!1;const i=-this._core.store.state.translateX/this._core.store.state.scale,s=-this._core.store.state.translateY/this._core.store.state.scale;return this.rotatedBoundingBox.x<i+this._core.store.state.viewportWidth/this._core.store.state.scale&&this.rotatedBoundingBox.x+this.rotatedBoundingBox.width>i&&this.rotatedBoundingBox.y<s+this._core.store.state.viewportHeight/this._core.store.state.scale&&this.rotatedBoundingBox.y+this.rotatedBoundingBox.height>s}centerInViewport(){const{viewportWidth:t,viewportHeight:i,translateX:s,translateY:h,scale:e}=this._core.store.state,{x:n,y:r,width:o,height:a}=this.rotatedBoundingBox;this.updatePosition(this.translateX+((t/2-s)/e-(n+o/2)),this.translateY+((i/2-h)/e-(r+a/2)))}update(){this._core.store.objects.update(this)}move(t,i,s,h){const e=(i-h)/this._core.store.state.scale;this.translateX+=(t-s)/this._core.store.state.scale,this.translateY+=e,this._core.store.objects.update(this)}resize(t,i,s,h){s<=1||h<=1||(this.width=s,this.height=h,this.translateX=t,this.translateY=i,this._core.store.objects.update(this),this._core.anchorManager.updateAnchorsForObject(this.id))}rotate(t){this.rotation=t,this._core.store.objects.update(this)}clone(){const t=Object.create(Object.getPrototypeOf(this));return Object.assign(t,this),t.id=this.id,t}copy(){const t=Object.create(Object.getPrototypeOf(this));return Object.assign(t,this),t.id=this.generateId(),t.isMounted=!1,t.isSelected=!1,t.isHovered=!1,t.isInteractive=!1,t.resizing=!1,t.markedForRemoval=!1,t.isVisible=!0,t}serialize(){const{_core:t,_elementRef:i,element:s,totalWidth:h,totalHeight:e,isSelected:n,isHovered:r,isMounted:o,isInteractive:a,resizing:u,markedForRemoval:l,isVisible:c,...f}=this;return structuredClone(f)}deserialize(t){return Object.assign(this,t),this.isSelected=!1,this.isHovered=!1,this.isMounted=!1,this.isInteractive=!1,this.resizing=!1,this.markedForRemoval=!1,this.isVisible=!0,"_adjustedPoints"in this&&(this._adjustedPoints=null),"_clipInfo"in this&&(this._clipInfo=null),this}adoptTransientStateFrom(t){}isClass(t){return this.__class__===t}edit(t){}onAfterUpdate(t){}hitTest(t,i){return!0}hitTestPolygon(t){return s.doPolygonsIntersect(this.rotatedPolygon,t)}updatePosition(t,i){this.translateX=t,this.translateY=i,this._core.store.objects.update(this)}}class e{static average(t,i){return(t+i)/2}static degreesToRadians(t){return t*(Math.PI/180)}}var n,r={},o=(n||(n=1,function(t){Object.defineProperties(t,{__esModule:{value:!0},[Symbol.toStringTag]:{value:"Module"}});const{PI:i}=Math,s=i+1e-4,h=[1,1];function e(t,i,s,h=t=>t){return t*h(.5-i*(.5-s))}const{min:n}=Math;function r(t,i,s){let h=n(1,i/s);return n(1,t+(n(1,1-h)-t)*(.275*h))}function o(t,i){return[t[0]+i[0],t[1]+i[1]]}function a(t,i,s){return t[0]=i[0]+s[0],t[1]=i[1]+s[1],t}function u(t,i){return[t[0]-i[0],t[1]-i[1]]}function l(t,i,s){return t[0]=i[0]-s[0],t[1]=i[1]-s[1],t}function c(t,i){return[t[0]*i,t[1]*i]}function f(t,i,s){return t[0]=i[0]*s,t[1]=i[1]*s,t}function d(t){return[t[1],-t[0]]}function M(t,i){let s=i[0];return t[0]=i[1],t[1]=-s,t}function g(t,i){return t[0]*i[0]+t[1]*i[1]}function m(t,i){return t[0]===i[0]&&t[1]===i[1]}function p(t,i){let s=t[0]-i[0],h=t[1]-i[1];return s*s+h*h}function x(t){return function(t,i){return[t[0]/i,t[1]/i]}(t,function(t){return Math.hypot(t[0],t[1])}(t))}function y(t,i){return Math.hypot(t[1]-i[1],t[0]-i[0])}function v(t,i,s){let h=Math.sin(s),e=Math.cos(s),n=t[0]-i[0],r=t[1]-i[1];return[n*e-r*h+i[0],n*h+r*e+i[1]]}function P(t,i,s,h){let e=Math.sin(h),n=Math.cos(h),r=i[0]-s[0],o=i[1]-s[1],a=r*e+o*n;return t[0]=r*n-o*e+s[0],t[1]=a+s[1],t}function $(t,i,s){return o(t,c(u(i,t),s))}function b(t,i,s,h){let e=s[1]-i[1];return t[0]=i[0]+(s[0]-i[0])*h,t[1]=i[1]+e*h,t}function w(t,i,s){return o(t,c(i,s))}const z=[0,0],L=[0,0],_=[0,0];function I(t,i){let h=w(t,x(d(u(t,o(t,[1,1])))),-i),e=[],n=1/13;for(let i=n;i<=1;i+=n)e.push(v(h,t,2*s*i));return e}function X(t,i,h){let e=[],n=1/h;for(let h=n;h<=1;h+=n)e.push(v(i,t,s*h));return e}function Y(t,i,s){let h=u(i,s),e=c(h,.5),n=c(h,.51);return[u(t,e),u(t,n),o(t,n),o(t,e)]}function k(t,i,h,e){let n=[],r=w(t,i,h),o=1/e;for(let i=o;i<1;i+=o)n.push(v(r,t,3*s*i));return n}function R(t,i,s){return[o(t,c(i,s)),o(t,c(i,.99*s)),u(t,c(i,.99*s)),u(t,c(i,s))]}function j(t,i,s){return!1===t||void 0===t?0:!0===t?Math.max(i,s):t}function A(t,i={}){let{size:h=16,smoothing:n=.5,thinning:c=.5,simulatePressure:m=!0,easing:x=t=>t,start:y={},end:v={},last:$=!1}=i,{cap:w=!0,easing:A=t=>t*(2-t)}=y,{cap:B=!0,easing:S=t=>--t*t*t+1}=v;if(0===t.length||h<=0)return[];let T,C=t[t.length-1].runningLength,O=j(y.taper,h,C),D=j(v.taper,h,C),V=(h*n)**2,W=[],F=[],H=function(t,i,s){return t.slice(0,10).reduce(((t,h)=>{let e=h.pressure;return i&&(e=r(t,h.distance,s)),(t+e)/2}),t[0].pressure)}(t,m,h),E=e(h,c,t[t.length-1].pressure,x),K=t[0].vector,Q=t[0].point,U=Q,G=Q,Z=U,q=!1;for(let i=0;i<t.length;i++){let{pressure:n}=t[i],{point:d,vector:y,distance:v,runningLength:$}=t[i],w=i===t.length-1;if(!w&&C-$<3)continue;c?(m&&(n=r(H,v,h)),E=e(h,c,n,x)):E=h/2,void 0===T&&(T=E);let I=$<O?A($/O):1,X=C-$<D?S((C-$)/D):1;E=Math.max(.01,E*Math.min(I,X));let Y=(w?t[i]:t[i+1]).vector,k=w?1:g(y,Y),R=null!==k&&k<0;if(g(y,K)<0&&!q||R){M(z,K),f(z,z,E);for(let t=0;t<=1;t+=.07692307692307693)l(L,d,z),P(L,L,d,s*t),G=[L[0],L[1]],W.push(G),a(_,d,z),P(_,_,d,s*-t),Z=[_[0],_[1]],F.push(Z);Q=G,U=Z,R&&(q=!0)}else q=!1,w?(M(z,y),f(z,z,E),W.push(u(d,z)),F.push(o(d,z))):(b(z,Y,y,k),M(z,z),f(z,z,E),l(L,d,z),G=[L[0],L[1]],(i<=1||p(Q,G)>V)&&(W.push(G),Q=G),a(_,d,z),Z=[_[0],_[1]],(i<=1||p(U,Z)>V)&&(F.push(Z),U=Z),H=n,K=y)}let J=[t[0].point[0],t[0].point[1]],N=t.length>1?[t[t.length-1].point[0],t[t.length-1].point[1]]:o(t[0].point,[1,1]),tt=[],it=[];if(1===t.length){if(!O&&!D||$)return I(J,T||E)}else{O||D&&1===t.length||(w?tt.push(...X(J,F[0],13)):tt.push(...Y(J,W[0],F[0])));let i=d(function(t){return[-t[0],-t[1]]}(t[t.length-1].vector));D||O&&1===t.length?it.push(N):B?it.push(...k(N,i,E,29)):it.push(...R(N,i,E))}return W.concat(it,F.reverse(),tt)}const B=[0,0];function S(t){return null!=t&&t>=0}function T(t,i={}){let{streamline:s=.5,size:e=16,last:n=!1}=i;if(0===t.length)return[];let r=.15+.85*(1-s),a=Array.isArray(t[0])?t:t.map((({x:t,y:i,pressure:s=.5})=>[t,i,s]));if(2===a.length){let t=a[1];a=a.slice(0,-1);for(let i=1;i<5;i++)a.push($(a[0],t,i/4))}1===a.length&&(a=[...a,[...o(a[0],h),...a[0].slice(2)]]);let u=[{point:[a[0][0],a[0][1]],pressure:S(a[0][2])?a[0][2]:.25,vector:[...h],distance:0,runningLength:0}],c=!1,f=0,d=u[0],M=a.length-1;for(let t=1;t<a.length;t++){let i=n&&t===M?[a[t][0],a[t][1]]:$(d.point,a[t],r);if(m(d.point,i))continue;let s=y(i,d.point);if(f+=s,t<M&&!c){if(f<e)continue;c=!0}l(B,d.point,i),d={point:i,pressure:S(a[t][2])?a[t][2]:.5,vector:x(B),distance:s,runningLength:f},u.push(d)}return u[0].vector=u[1]?.vector||[0,0],u}function C(t,i={}){return A(T(t,i),i)}t.default=C,t.getStroke=C,t.getStrokeOutlinePoints=A,t.getStrokePoints=T}(r)),r);class a extends h{__class__="KritzelPath";points;d;stroke={light:"none",dark:"none"};strokeWidth;lineSlack=.5;fill;x=0;y=0;height=0;width=0;scale=1;options;isVisible=!0;isDebugInfoVisible=!0;isCompleted=!1;_adjustedPoints=null;get viewBox(){return`${this.x} ${this.y} ${this.width} ${this.height}`}constructor(t){super(),this.options=t,this.points=t?.points??[],this.translateX=t?.translateX??0,this.translateY=t?.translateY??0,this.rotation=e.degreesToRadians(t?.rotation??0),this.scale=t?.scale??1,this.strokeWidth=t?.strokeWidth??8,this.fill=t?.fill??{light:"#000000",dark:"#ffffff"},this.d=this.generateSvgPath(),this.updateDimensions()}static create(t,i){const s=new a;return s._core=t,s.id=s.generateId(),s.workspaceId=t.store.state.activeWorkspace.id,s.userId=t.user?.id,s.options=i,s.points=i?.points??[],s.translateX=i?.translateX??0,s.translateY=i?.translateY??0,s.rotation=e.degreesToRadians(i?.rotation??0),s.scale=i?.scale??1,s.strokeWidth=i?.strokeWidth??8,s.fill=i?.fill??{light:"#000000",dark:"#ffffff"},s.opacity=i?.opacity??1,s.zIndex=t.store.currentZIndex,s.d=s.generateSvgPath(),s.updateDimensions(),s}copy(){const t=super.copy();return this.points&&(t.points=this.points.map((t=>[...t]))),t}resize(t,i,s,h){if(s<=1||h<=1)return;const e=s/this.width,n=h/this.height;if(this.width=s,this.height=h,1===this.points.length){const t=this.points[0],i=Math.max(0,s-this.strokeWidth)/e,r=Math.max(0,h-this.strokeWidth)/n;this.points.push([t[0]+i,t[1]+r])}this.points=this.points.map((([t,i])=>[t*e,i*n])),this.d=this.generateSvgPath(),this.width=Math.max(...this.points.map((t=>t[0])))-Math.min(...this.points.map((t=>t[0])))+this.strokeWidth,this.height=Math.max(...this.points.map((t=>t[1])))-Math.min(...this.points.map((t=>t[1])))+this.strokeWidth,this.x=Math.min(...this.points.map((t=>t[0])))-this.strokeWidth/2,this.y=Math.min(...this.points.map((t=>t[1])))-this.strokeWidth/2,null!==t&&(this.translateX=t),null!==i&&(this.translateY=i),this._adjustedPoints=null,this._core.store.objects.update(this)}rotate(t){this.rotation=t,this._adjustedPoints=null,this._core.store.objects.update(this)}move(t,i,s,h){const e=(i-h)/this._core.store.state.scale;this.translateX+=(t-s)/this._core.store.state.scale,this.translateY+=e,this._adjustedPoints=null,this._core.store.objects.update(this)}hitTest(t,i){const s=this.strokeWidth/this.scale/2;if(null===this._adjustedPoints&&(this._adjustedPoints=this.computeAdjustedPoints()),1===this._adjustedPoints.length){const h=this._adjustedPoints[0];return this.pointToLineSegmentDistance(t,i,h[0],h[1],h[0],h[1])<=s}for(let h=0;h<this._adjustedPoints.length-1;h++){const e=this._adjustedPoints[h],n=this._adjustedPoints[h+1];if(this.pointToLineSegmentDistance(t,i,e[0],e[1],n[0],n[1])<=s)return!0}return!1}hitTestPolygon(t){const i=this.strokeWidth/this.scale/2;null===this._adjustedPoints&&(this._adjustedPoints=this.computeAdjustedPoints());const h=[{x:t.bottomLeft.x,y:t.bottomLeft.y},{x:t.bottomRight.x,y:t.bottomRight.y},{x:t.topRight.x,y:t.topRight.y},{x:t.topLeft.x,y:t.topLeft.y}];for(const[t,i]of this._adjustedPoints)if(s.isPointInPolygon({x:t,y:i},h))return!0;for(const t of h)if(this.hitTest(t.x,t.y))return!0;for(let t=0;t<this._adjustedPoints.length-1;t++){const i={x:this._adjustedPoints[t][0],y:this._adjustedPoints[t][1]},e={x:this._adjustedPoints[t+1][0],y:this._adjustedPoints[t+1][1]};for(let t=0;t<h.length;t++)if(s.intersectLines(i,e,h[t],h[(t+1)%h.length]))return!0}for(let t=0;t<this._adjustedPoints.length-1;t++){const s=this._adjustedPoints[t],e=this._adjustedPoints[t+1];for(let t=0;t<h.length;t++){const n=h[t],r=h[(t+1)%h.length],o=this.pointToLineSegmentDistance(n.x,n.y,s[0],s[1],e[0],e[1]),a=this.pointToLineSegmentDistance(r.x,r.y,s[0],s[1],e[0],e[1]),u=this.pointToLineSegmentDistance(s[0],s[1],n.x,n.y,r.x,r.y),l=this.pointToLineSegmentDistance(e[0],e[1],n.x,n.y,r.x,r.y);if(Math.min(o,a,u,l)<=i)return!0}}return!1}updatePosition(t,i){this.translateX=t,this.translateY=i,this._adjustedPoints=null,this._core.store.objects.update(this)}onAfterUpdate(t){t.includes("strokeWidth")&&(this.d=this.generateSvgPath(),this.updateBoundingBox(),this._adjustedPoints=null)}computeAdjustedPoints(){if(!this.points?.length)return[];const t=this.rotation,i=Math.cos(t),s=Math.sin(t),h=this.points.map((t=>t[0])),e=this.points.map((t=>t[1])),n={x:(Math.min(...h)+Math.max(...h))/2,y:(Math.min(...e)+Math.max(...e))/2},{x:r,y:o}=n;return this.points.map((([t,h])=>{const e=t-r,n=h-o;return[r+e*i-n*s,o+e*s+n*i]})).map((([t,i])=>[Math.abs(t-this.x)/this.scale+this.translateX,Math.abs(i-this.y)/this.scale+this.translateY]))}pointToLineSegmentDistance(t,i,s,h,e,n){const r=e-s,o=n-h,a=r*r+o*o;let u,l,c=-1;0!==a&&(c=((t-s)*r+(i-h)*o)/a),c<0?(u=s,l=h):c>1?(u=e,l=n):(u=s+c*r,l=h+c*o);const f=t-u,d=i-l;return Math.sqrt(f*f+d*d)}updateDimensions(){const t=Math.min(...this.points.map((t=>t[0])))-this.strokeWidth/2,i=Math.min(...this.points.map((t=>t[1])))-this.strokeWidth/2,s=Math.max(...this.points.map((t=>t[0])))+this.strokeWidth/2,h=Math.max(...this.points.map((t=>t[1])))+this.strokeWidth/2;this.width=s-t+this.lineSlack,this.height=h-i+this.lineSlack,this.x=t,this.y=i,this.translateX=(this.x+this.translateX)/this.scale,this.translateY=(this.y+this.translateY)/this.scale}updateBoundingBox(){const t=Math.min(...this.points.map((t=>t[0])))-this.strokeWidth/2,i=Math.min(...this.points.map((t=>t[1])))-this.strokeWidth/2,s=Math.max(...this.points.map((t=>t[0])))+this.strokeWidth/2,h=Math.max(...this.points.map((t=>t[1])))+this.strokeWidth/2;this.width=s-t+this.lineSlack,this.height=h-i+this.lineSlack,this.x=t,this.y=i}generateSvgPath(){const t=this.getStrokeFromPoints(this.points,this.strokeWidth);return this.getSvgPathFromStroke(t)}getStrokeFromPoints(t,i){return o.getStroke(t,{size:i,thinning:.5,smoothing:.5,streamline:.5,easing:t=>t,simulatePressure:!0,last:!0,start:{cap:!0,taper:0,easing:t=>t},end:{cap:!0,taper:0,easing:t=>t}})}getSvgPathFromStroke(t,i=!0){const s=t.length;if(s<4)return"";let h=t[0],n=t[1];const r=t[2];let o=`M${h[0].toFixed(2)},${h[1].toFixed(2)} Q${n[0].toFixed(2)},${n[1].toFixed(2)} ${e.average(n[0],r[0]).toFixed(2)},${e.average(n[1],r[1]).toFixed(2)} T`;for(let i=2,r=s-1;i<r;i++)h=t[i],n=t[i+1],o+=`${e.average(h[0],n[0]).toFixed(2)},${e.average(h[1],n[1]).toFixed(2)} `;return i&&(o+="Z"),o}isLowRes(){if(!this._core)return!1;const t=this._core.store.state.scale;return this.boundingBox.width*t*(this.boundingBox.height*t)<500}getClipPoint(t){const i=this.centerX,s=this.centerY,h=this.strokeWidth/this.scale/2;if(null===this._adjustedPoints&&(this._adjustedPoints=this.computeAdjustedPoints()),this._adjustedPoints.length<1)return null;let e=!0;for(let n=1;n<=32;n++){const r=n/32,o=t.x+(i-t.x)*r,a=t.y+(s-t.y)*r;let u=1/0;if(1===this._adjustedPoints.length){const t=this._adjustedPoints[0],i=o-t[0],s=a-t[1];u=Math.sqrt(i*i+s*s)}else for(let t=0;t<this._adjustedPoints.length-1;t++){const i=this._adjustedPoints[t],s=this._adjustedPoints[t+1],h=this.pointToLineSegmentDistance(o,a,i[0],i[1],s[0],s[1]);h<u&&(u=h)}const l=u<=h;if(e&&l){let e=(n-1)/32,o=r;for(let n=0;n<8;n++){const n=(e+o)/2,r=t.x+(i-t.x)*n,a=t.y+(s-t.y)*n;let u=1/0;if(1===this._adjustedPoints.length){const t=this._adjustedPoints[0],i=r-t[0],s=a-t[1];u=Math.sqrt(i*i+s*s)}else for(let t=0;t<this._adjustedPoints.length-1;t++){const i=this._adjustedPoints[t],s=this._adjustedPoints[t+1],h=this.pointToLineSegmentDistance(r,a,i[0],i[1],s[0],s[1]);h<u&&(u=h)}u<=h?o=n:e=n}const a=(e+o)/2;return{x:t.x+(i-t.x)*a,y:t.y+(s-t.y)*a}}e=!l}return null}}class u extends h{__class__="KritzelLine";startX;startY;endX;endY;controlX;controlY;stroke;strokeWidth;scale=1;options;startAnchor;endAnchor;arrows;isVisible=!0;isDebugInfoVisible=!0;isCompleted=!1;_adjustedPoints=null;_clipInfo=null;get d(){return void 0!==this.controlX&&void 0!==this.controlY?`M ${this.startX} ${this.startY} Q ${this.controlX} ${this.controlY} ${this.endX} ${this.endY}`:`M ${this.startX} ${this.startY} L ${this.endX} ${this.endY}`}get viewBox(){return`${this.x} ${this.y} ${this.width} ${this.height}`}constructor(t){super(),this.options=t,this.startX=t?.startX??0,this.startY=t?.startY??0,this.endX=t?.endX??0,this.endY=t?.endY??0,this.controlX=t?.controlX,this.controlY=t?.controlY,this.translateX=t?.translateX??0,this.translateY=t?.translateY??0,this.rotation=e.degreesToRadians(t?.rotation??0),this.scale=t?.scale??1,this.strokeWidth=t?.strokeWidth??4,this.stroke=t?.stroke??{light:"#000000",dark:"#ffffff"},this.startAnchor=t?.startAnchor,this.endAnchor=t?.endAnchor,this.arrows=t?.arrows,this.updateDimensions()}static create(t,i){const s=new u;return s._core=t,s.id=s.generateId(),s.workspaceId=t.store.state.activeWorkspace.id,s.userId=t.user?.id,s.options=i,s.startX=i?.startX??0,s.startY=i?.startY??0,s.endX=i?.endX??0,s.endY=i?.endY??0,s.controlX=i?.controlX,s.controlY=i?.controlY,s.translateX=i?.translateX??0,s.translateY=i?.translateY??0,s.rotation=e.degreesToRadians(i?.rotation??0),s.scale=i?.scale??1,s.strokeWidth=i?.strokeWidth??4,s.stroke=i?.stroke??{light:"#000000",dark:"#ffffff"},s.opacity=i?.opacity??1,s.startAnchor=i?.startAnchor,s.endAnchor=i?.endAnchor,s.arrows=i?.arrows,s.zIndex=t.store.currentZIndex,s.updateDimensions(),s}resize(t,i,s,h){if(s<=1||h<=1)return;const e=s/this.width,n=h/this.height;this.startX=this.startX*e,this.startY=this.startY*n,this.endX=this.endX*e,this.endY=this.endY*n,void 0!==this.controlX&&void 0!==this.controlY&&(this.controlX=this.controlX*e,this.controlY=this.controlY*n);const{minX:r,minY:o,maxX:a,maxY:u}=this.calculateBoundingBox();this.width=a-r,this.height=u-o,this.x=r,this.y=o,this.translateX=t,this.translateY=i,this._adjustedPoints=null,this._clipInfo=null,this._core.store.objects.update(this),this._core.anchorManager.updateAnchorsForObject(this.id),this.startAnchor&&this._core.anchorManager.updateAnchorsForObject(this.startAnchor.objectId),this.endAnchor&&this._core.anchorManager.updateAnchorsForObject(this.endAnchor.objectId)}rotate(t){this.rotation=t,this._adjustedPoints=null,this._clipInfo=null,this._core.store.objects.update(this)}move(t,i,s,h){const e=(i-h)/this._core.store.state.scale;this.translateX+=(t-s)/this._core.store.state.scale,this.translateY+=e,this.startAnchor&&this._core.anchorManager.updateAnchorsForObject(this.startAnchor.objectId),this.endAnchor&&this._core.anchorManager.updateAnchorsForObject(this.endAnchor.objectId),this._adjustedPoints=null,this._clipInfo=null,this._core.store.objects.update(this)}hitTest(t,i){const s=Math.max(this.strokeWidth,20)/this.scale/2;if(null===this._adjustedPoints&&(this._adjustedPoints=this.computeAdjustedPoints()),void 0!==this.controlX&&void 0!==this.controlY){const h=this.getClipInfo();return this.pointToBezierDistance(t,i,h.start?.t??0,h.end?.t??1)<=s}const h=this.getClipInfo(),e=h.start?[h.start.x,h.start.y]:this._adjustedPoints[0],n=h.end?[h.end.x,h.end.y]:this._adjustedPoints[1];return this.pointToLineSegmentDistance(t,i,e[0],e[1],n[0],n[1])<=s}hitTestPolygon(t){const i=this.strokeWidth/this.scale/2;null===this._adjustedPoints&&(this._adjustedPoints=this.computeAdjustedPoints());const h=this.getClipInfo(),e=[{x:t.bottomLeft.x,y:t.bottomLeft.y},{x:t.bottomRight.x,y:t.bottomRight.y},{x:t.topRight.x,y:t.topRight.y},{x:t.topLeft.x,y:t.topLeft.y}],n=h.start?[h.start.x,h.start.y]:this._adjustedPoints[0],r=h.end?[h.end.x,h.end.y]:this._adjustedPoints[1],o=[n,r];for(const[t,i]of o)if(s.isPointInPolygon({x:t,y:i},e))return!0;for(const t of e)if(this.hitTest(t.x,t.y))return!0;if(void 0!==this.controlX&&void 0!==this.controlY){const t=this._adjustedPoints[0],n=this._adjustedPoints[1],r=this.computeAdjustedControlPoint(),o=h.start?.t??0,a=h.end?.t??1,u=20;for(let h=0;h<=u;h++){const l=o+h/u*(a-o),c=1-l,f=c*c*t[0]+2*c*l*r[0]+l*l*n[0],d=c*c*t[1]+2*c*l*r[1]+l*l*n[1];if(s.isPointInPolygon({x:f,y:d},e))return!0;for(let t=0;t<e.length;t++){const s=e[t],h=e[(t+1)%e.length];if(this.pointToLineSegmentDistance(f,d,s.x,s.y,h.x,h.y)<=i)return!0}}return!1}const a={x:n[0],y:n[1]},u={x:r[0],y:r[1]};for(let t=0;t<e.length;t++){const h=e[t],n=e[(t+1)%e.length];if(s.intersectLines(a,u,h,n))return!0;const r=this.pointToLineSegmentDistance(h.x,h.y,a.x,a.y,u.x,u.y),o=this.pointToLineSegmentDistance(n.x,n.y,a.x,a.y,u.x,u.y),l=this.pointToLineSegmentDistance(a.x,a.y,h.x,h.y,n.x,n.y),c=this.pointToLineSegmentDistance(u.x,u.y,h.x,h.y,n.x,n.y);if(Math.min(r,o,l,c)<=i)return!0}return!1}updatePosition(t,i){this.translateX=t,this.translateY=i,this._adjustedPoints=null,this._clipInfo=null,this._core.store.objects.update(this)}updateEndpoint(t,i,s){"start"===t?(this.startX=i,this.startY=s):(this.endX=i,this.endY=s);const h=this.width,e=this.height,{minX:n,minY:r,maxX:o,maxY:a}=this.calculateBoundingBox(),u=n-this.x,l=r-this.y,c=o-n,f=a-r,d=(c-h)/2,M=(f-e)/2;this.x=n,this.y=r,this.width=c,this.height=f;const g=Math.cos(this.rotation),m=Math.sin(this.rotation),p=u+d,x=l+M,y=p*m+x*g-M;this.translateX+=(p*g-x*m-d)/this.scale,this.translateY+=y/this.scale,this._adjustedPoints=null,this._clipInfo=null,this._core.store.objects.update(this)}updateControlPoint(t,i){this.controlX=t,this.controlY=i;const s=this.width,h=this.height,{minX:e,minY:n,maxX:r,maxY:o}=this.calculateBoundingBox(),a=e-this.x,u=n-this.y,l=r-e,c=o-n,f=(l-s)/2,d=(c-h)/2;this.x=e,this.y=n,this.width=l,this.height=c;const M=Math.cos(this.rotation),g=Math.sin(this.rotation),m=a+f,p=u+d,x=m*g+p*M-d;this.translateX+=(m*M-p*g-f)/this.scale,this.translateY+=x/this.scale,this._adjustedPoints=null,this._clipInfo=null,this._core.store.objects.update(this)}computeAdjustedPoints(){const t=[[this.startX,this.startY],[this.endX,this.endY]],i=this.rotation,s=Math.cos(i),h=Math.sin(i),e=t.map((t=>t[0])),n=t.map((t=>t[1])),r={x:(Math.min(...e)+Math.max(...e))/2,y:(Math.min(...n)+Math.max(...n))/2},{x:o,y:a}=r;return t.map((([t,i])=>{const e=t-o,n=i-a;return[o+e*s-n*h,a+e*h+n*s]})).map((([t,i])=>[(t-this.x)/this.scale+this.translateX,(i-this.y)/this.scale+this.translateY]))}pointToLineSegmentDistance(t,i,s,h,e,n){const r=e-s,o=n-h,a=r*r+o*o;let u,l,c=-1;0!==a&&(c=((t-s)*r+(i-h)*o)/a),c<0?(u=s,l=h):c>1?(u=e,l=n):(u=s+c*r,l=h+c*o);const f=t-u,d=i-l;return Math.sqrt(f*f+d*d)}pointToBezierDistance(t,i,s=0,h=1){null===this._adjustedPoints&&(this._adjustedPoints=this.computeAdjustedPoints());const e=this._adjustedPoints[0],n=this._adjustedPoints[1],r=this.computeAdjustedControlPoint();let o=1/0;for(let a=0;a<=20;a++){const u=s+a/20*(h-s),l=1-u,c=t-(l*l*e[0]+2*l*u*r[0]+u*u*n[0]),f=i-(l*l*e[1]+2*l*u*r[1]+u*u*n[1]),d=Math.sqrt(c*c+f*f);d<o&&(o=d)}return o}getClipInfo(){if(this._clipInfo)return this._clipInfo;const t=this.endAnchor,i={};if(this.startAnchor){const t=this._core.anchorManager.findAnchorTarget(this,"start");if(t){const s=this._core.anchorManager.computeAnchorClipInfo(this,"start",t);s&&(i.start={x:s.worldX,y:s.worldY,t:s.t})}}if(t){const t=this._core.anchorManager.findAnchorTarget(this,"end");if(t){const s=this._core.anchorManager.computeAnchorClipInfo(this,"end",t);s&&(i.end={x:s.worldX,y:s.worldY,t:s.t})}}return this._clipInfo=i,i}computeAdjustedControlPoint(){if(void 0===this.controlX||void 0===this.controlY)return[(this.startX+this.endX)/2,(this.startY+this.endY)/2];const t=this.rotation,i=Math.cos(t),s=Math.sin(t),h=[this.startX,this.endX],e=[this.startY,this.endY],n={x:(Math.min(...h)+Math.max(...h))/2,y:(Math.min(...e)+Math.max(...e))/2},{x:r,y:o}=n,a=this.controlX-r,u=this.controlY-o;return[(r+a*i-u*s-this.x)/this.scale+this.translateX,(o+a*s+u*i-this.y)/this.scale+this.translateY]}get rotatedPolygon(){const t=this.padding,{minX:i,minY:s,maxX:h,maxY:e}=u.calculateBoundingBox(this.startX,this.startY,this.endX,this.endY,this.controlX,this.controlY,this.strokeWidth),n=i-this.x+t,r=s-this.y+t,o=h-this.x+t,a=e-this.y+t,l={x:n,y:r},c={x:o,y:r},f={x:o,y:a},d={x:n,y:a},M=this.totalWidth/2,g=this.totalHeight/2,m=this.rotation,p=Math.cos(m),x=Math.sin(m),y=t=>({x:((t.x-M)*p-(t.y-g)*x+M)/this.scale+this.translateX,y:((t.x-M)*x+(t.y-g)*p+g)/this.scale+this.translateY});return{topLeft:y(l),topRight:y(c),bottomRight:y(f),bottomLeft:y(d)}}static calculateBoundingBox(t,i,s,h,e,n,r){let o=Math.min(t,s),a=Math.min(i,h),u=Math.max(t,s),l=Math.max(i,h);if(void 0!==e&&void 0!==n){const r=t-2*e+s;if(0!==r){const i=(t-e)/r;if(i>0&&i<1){const h=(1-i)*(1-i)*t+2*(1-i)*i*e+i*i*s;o=Math.min(o,h),u=Math.max(u,h)}}const c=i-2*n+h;if(0!==c){const t=(i-n)/c;if(t>0&&t<1){const s=(1-t)*(1-t)*i+2*(1-t)*t*n+t*t*h;a=Math.min(a,s),l=Math.max(l,s)}}}const c=r/2;return{minX:o-c,minY:a-c,maxX:u+c,maxY:l+c}}calculateBoundingBox(){return u.calculateBoundingBox(this.startX,this.startY,this.endX,this.endY,this.controlX,this.controlY,this.strokeWidth)}serialize(){const t=super.serialize();return delete t._adjustedPoints,delete t._clipInfo,t}deserialize(t){const i=super.deserialize(t);return this._adjustedPoints=null,this._clipInfo=null,i}updateDimensions(){const{minX:t,minY:i,maxX:s,maxY:h}=this.calculateBoundingBox();this.width=s-t,this.height=h-i,this.x=t,this.y=i,this.translateX=(this.x+this.translateX)/this.scale,this.translateY=(this.y+this.translateY)/this.scale}get startMarkerId(){return`arrow-start-${this.id}`}get endMarkerId(){return`arrow-end-${this.id}`}getArrowSize(t){const i="start"===t?this.arrows?.start:this.arrows?.end;return i?.size??3*this.strokeWidth}getArrowFill(t){const s="start"===t?this.arrows?.start:this.arrows?.end;return i.resolveThemeColor(s?.fill??this.stroke)}getArrowPath(t="triangle"){switch(t){case"triangle":default:return"M 0 0 L 10 5 L 0 10 z";case"open":return"M 0 0 L 10 5 L 0 10";case"diamond":return"M 0 5 L 5 0 L 10 5 L 5 10 z";case"circle":return"M 5,0 A 5,5 0 1,1 5,10 A 5,5 0 1,1 5,0"}}get hasStartArrow(){return!0===this.arrows?.start?.enabled}get hasEndArrow(){return!0===this.arrows?.end?.enabled}}export{h as K,a,u as b,e as c,s as d}
@@ -1 +1 @@
1
- import{p as e,H as s,c as t,h as r,d as i,t as o}from"./p-B43upypT.js";import{d as l}from"./p-C4-Som48.js";const c=e(class extends s{constructor(e){super(),!1!==e&&this.__registerHost(),this.__attachShadow(),this.sizeChange=t(this,"sizeChange")}sizes=[4,6,8,12,16,24];selectedSize=null;sizeChange;handleSizeClick(e){this.selectedSize=e,this.sizeChange.emit(e)}render(){return r(i,{key:"bde2cc986aebbe869a3eea026654229dee0d3e0e"},r("div",{key:"f84c4b844b865080f4e0e245bbccc6d77ac3f049",class:"size-grid"},(this.sizes??[]).map((e=>r("div",{tabIndex:0,class:{"size-container":!0,selected:this.selectedSize===e},onClick:()=>this.handleSizeClick(e)},r("kritzel-color",{value:"var(--kritzel-global-text-primary)",size:e}))))))}static get style(){return":host{display:flex;align-items:flex-start;gap:0;padding:0;width:100%;box-sizing:border-box}.size-grid{width:100%;display:grid;grid-template-columns:repeat(auto-fill, 32px);gap:8px;justify-items:center}.size-container{display:flex;justify-content:center;align-items:center;width:32px;height:32px;border-radius:50%;cursor:var(--kritzel-global-pointer-cursor, pointer);border:2px solid transparent;box-sizing:border-box}.size-container:hover{background-color:var(--kritzel-stroke-size-hover-background-color, #ebebeb)}.size-container.selected{border-color:var(--kritzel-selection-border-color, #007AFF);background-color:var(--kritzel-stroke-size-selected-background-color, #ebebeb)}"}},[513,"kritzel-stroke-size",{sizes:[16],selectedSize:[1026,"selected-size"]}]);function a(){"undefined"!=typeof customElements&&["kritzel-stroke-size","kritzel-color"].forEach((e=>{switch(e){case"kritzel-stroke-size":customElements.get(o(e))||customElements.define(o(e),c);break;case"kritzel-color":customElements.get(o(e))||l()}}))}export{c as K,a as d}
1
+ import{p as e,H as s,c as t,h as r,d as i,t as o}from"./p-B43upypT.js";import{d as l}from"./p-BcB97x3U.js";const c=e(class extends s{constructor(e){super(),!1!==e&&this.__registerHost(),this.__attachShadow(),this.sizeChange=t(this,"sizeChange")}sizes=[4,6,8,12,16,24];selectedSize=null;sizeChange;handleSizeClick(e){this.selectedSize=e,this.sizeChange.emit(e)}render(){return r(i,{key:"bde2cc986aebbe869a3eea026654229dee0d3e0e"},r("div",{key:"f84c4b844b865080f4e0e245bbccc6d77ac3f049",class:"size-grid"},(this.sizes??[]).map((e=>r("div",{tabIndex:0,class:{"size-container":!0,selected:this.selectedSize===e},onClick:()=>this.handleSizeClick(e)},r("kritzel-color",{value:"var(--kritzel-global-text-primary)",size:e}))))))}static get style(){return":host{display:flex;align-items:flex-start;gap:0;padding:0;width:100%;box-sizing:border-box}.size-grid{width:100%;display:grid;grid-template-columns:repeat(auto-fill, 32px);gap:8px;justify-items:center}.size-container{display:flex;justify-content:center;align-items:center;width:32px;height:32px;border-radius:50%;cursor:var(--kritzel-global-pointer-cursor, pointer);border:2px solid transparent;box-sizing:border-box}.size-container:hover{background-color:var(--kritzel-stroke-size-hover-background-color, #ebebeb)}.size-container.selected{border-color:var(--kritzel-selection-border-color, #007AFF);background-color:var(--kritzel-stroke-size-selected-background-color, #ebebeb)}"}},[513,"kritzel-stroke-size",{sizes:[16],selectedSize:[1026,"selected-size"]}]);function a(){"undefined"!=typeof customElements&&["kritzel-stroke-size","kritzel-color"].forEach((e=>{switch(e){case"kritzel-stroke-size":customElements.get(o(e))||customElements.define(o(e),c);break;case"kritzel-color":customElements.get(o(e))||l()}}))}export{c as K,a as d}
@@ -1 +1 @@
1
- import{p as t,H as e,c as i,h as o,d as l,t as a}from"./p-B43upypT.js";import{d as r}from"./p-CdR76C4L.js";const n=t(class extends e{constructor(t){super(),!1!==t&&this.__registerHost(),this.__attachShadow(),this.undo=i(this,"undo"),this.redo=i(this,"redo"),this.delete=i(this,"delete")}undoState=null;terms={};undo;redo;delete;handleUndo(t){t.cancelable&&(t.preventDefault(),t.stopPropagation(),this.undo.emit())}handleRedo(t){t.preventDefault(),t.stopPropagation(),this.redo.emit()}render(){return o(l,{key:"22f3826d57b4d8f0e476951a860bde3dbc6c7200"},o("button",{key:"c3259c5e924b3cf74920dc4676ec8a682c3273e8",class:"utility-button","data-testid":"utility-undo",disabled:!this.undoState?.canUndo,onClick:t=>this.handleUndo(t),"aria-label":this.terms["utility.undo"]??"Undo"},o("kritzel-icon",{key:"ab4e9da6b60d9fa470fd8f5002f2acd5a758a8ba",name:"undo"})),o("button",{key:"d17e25e78831b5ee13596cc2639cfbb5bd75a1cb",class:"utility-button","data-testid":"utility-redo",disabled:!this.undoState?.canRedo,onClick:t=>this.handleRedo(t),"aria-label":this.terms["utility.redo"]??"Redo"},o("kritzel-icon",{key:"7ae8cec39ffab1303d76315ab85ac575b886b233",name:"redo"})),o("div",{key:"f54e0262f133ad0eed0bbf853b67edd6c2f5e87f",class:"utility-separator"}),o("button",{key:"162d6e85965338b5700e661595dc6da6131ebccf",class:"utility-button","data-testid":"utility-delete",onClick:()=>this.delete.emit(),"aria-label":this.terms["utility.delete"]??"Delete selected items"},o("kritzel-icon",{key:"dc00247ed45f09b86ad9314395f56e70d1122a4b",name:"delete"})))}static get style(){return":host{display:flex;flex-direction:row;align-items:center;padding:4px;gap:8px;border-top-left-radius:12px;border-top-right-radius:12px;background-color:var(--kritzel-utility-panel-background-color, #e2e2e2);width:fit-content;user-select:none;z-index:1}.utility-button{display:flex;justify-content:center;align-items:center;width:28px;height:28px;padding:8px 4px;border:none;background:none;cursor:var(--kritzel-global-pointer-cursor, pointer);color:var(--kritzel-utility-panel-button-color, #333333);--kritzel-icon-color:var(--kritzel-utility-panel-button-color, #333333);-webkit-tap-highlight-color:transparent;border-radius:var(--kritzel-utility-panel-button-border-radius, 8px)}.utility-button:hover,.utility-button:focus-visible{background-color:var(--kritzel-utility-panel-button-hover-background-color, hsl(0, 0%, 0%, 4.3%))}.utility-button:disabled{opacity:0.4;cursor:not-allowed;pointer-events:none}.utility-separator{width:1px;height:16px;background-color:var(--kritzel-utility-panel-separator-color, hsl(0, 0%, 0%, 8%))}"}},[513,"kritzel-utility-panel",{undoState:[16],terms:[16]}]);function d(){"undefined"!=typeof customElements&&["kritzel-utility-panel","kritzel-icon"].forEach((t=>{switch(t){case"kritzel-utility-panel":customElements.get(a(t))||customElements.define(a(t),n);break;case"kritzel-icon":customElements.get(a(t))||r()}}))}export{n as K,d}
1
+ import{p as t,H as e,c as i,h as o,d as a,t as l}from"./p-B43upypT.js";import{d as r}from"./p-CdR76C4L.js";const d=t(class extends e{constructor(t){super(),!1!==t&&this.__registerHost(),this.__attachShadow(),this.undo=i(this,"undo"),this.redo=i(this,"redo"),this.delete=i(this,"delete")}undoState=null;terms={};undo;redo;delete;handleUndo(t){t.cancelable&&(t.preventDefault(),t.stopPropagation(),this.undo.emit())}handleRedo(t){t.preventDefault(),t.stopPropagation(),this.redo.emit()}render(){return o(a,{key:"40aeb81be7e767bf6565dd691d17b5dd283d997b"},o("button",{key:"80bb960bf04d5e0bea09960e3bc5e0d999a8cb84",class:"utility-button","data-testid":"utility-undo",disabled:!this.undoState?.canUndo,onClick:t=>this.handleUndo(t),"aria-label":this.terms["utility.undo"]??"Undo"},o("kritzel-icon",{key:"7ab3d89a60f247cfb040fa1ff77aed7a4e616a0a",name:"undo"})),o("button",{key:"fb5b7ee68a7488192bc053808f338fca72a22d79",class:"utility-button","data-testid":"utility-redo",disabled:!this.undoState?.canRedo,onClick:t=>this.handleRedo(t),"aria-label":this.terms["utility.redo"]??"Redo"},o("kritzel-icon",{key:"4da4fe3a445a9ae03981af51e73291c3f6b0fbbb",name:"redo"})),o("div",{key:"6144f7c81f06c6b1215230394e62df2120e5853a",class:"utility-separator"}),o("button",{key:"92839ee1dfb039a2f669326adce8d623dafe1aed",class:"utility-button","data-testid":"utility-delete",onClick:()=>this.delete.emit(),"aria-label":this.terms["utility.delete"]??"Delete selected items"},o("kritzel-icon",{key:"4071b04d37ddd033545ba92d2cedb164e6e96fdd",name:"delete"})))}static get style(){return":host{display:flex;flex-direction:row;align-items:center;padding:4px;gap:8px;border-top-left-radius:12px;border-top-right-radius:12px;background-color:var(--kritzel-utility-panel-background-color, #e2e2e2);width:fit-content;user-select:none;z-index:1}.utility-button{display:flex;justify-content:center;align-items:center;width:28px;height:28px;padding:8px 4px;border:none;background:none;cursor:var(--kritzel-global-pointer-cursor, pointer);color:var(--kritzel-utility-panel-button-color, #333333);--kritzel-icon-color:var(--kritzel-utility-panel-button-color, #333333);-webkit-tap-highlight-color:transparent;border-radius:var(--kritzel-utility-panel-button-border-radius, 8px)}.utility-button:hover,.utility-button:focus-visible{background-color:var(--kritzel-utility-panel-button-hover-background-color, hsl(0, 0%, 0%, 4.3%))}.utility-button:disabled{opacity:0.4;cursor:not-allowed;pointer-events:none}.utility-separator{width:1px;height:16px;background-color:var(--kritzel-utility-panel-separator-color, hsl(0, 0%, 0%, 8%))}"}},[513,"kritzel-utility-panel",{undoState:[16],terms:[16]}]);function n(){"undefined"!=typeof customElements&&["kritzel-utility-panel","kritzel-icon"].forEach((t=>{switch(t){case"kritzel-utility-panel":customElements.get(l(t))||customElements.define(l(t),d);break;case"kritzel-icon":customElements.get(l(t))||r()}}))}export{d as K,n as d}
@@ -0,0 +1 @@
1
+ var e="undefined"!=typeof globalThis?globalThis:"undefined"!=typeof window?window:"undefined"!=typeof global?global:"undefined"!=typeof self?self:{};function n(e){return e&&e.__esModule&&Object.prototype.hasOwnProperty.call(e,"default")?e.default:e}export{e as c,n as g}
@@ -1 +1 @@
1
- import{p as e,H as t,c as s,h as i,d as o,t as r}from"./p-B43upypT.js";import{f as n,e as l}from"./p-Dl3MwBL1.js";import{a}from"./p-CpzicliK.js";import{d as h}from"./p-C4-Som48.js";import{d as p}from"./p-CO0eEzos.js";import{d as c}from"./p-Df3BwVGy.js";import{d}from"./p-BX-nQAyH.js";import{d as m}from"./p-JhOYwUOj.js";import{d as f}from"./p-Cb5YwXbC.js";import{d as u}from"./p-CdR76C4L.js";import{d as g}from"./p-CXpv9Rxe.js";import{d as z}from"./p-CdkNxxut.js";import{d as y}from"./p-BFYtCsZu.js";import{d as k}from"./p-C1jg5IQi.js";class C{static getToolConfig(e){switch(e?.toolType){case"selection":return"getToolConfig"in e&&"function"==typeof e.getToolConfig?e.getToolConfig():null;case"brush":return{type:"brush",colorProperty:"color",sizeProperty:"size",opacityProperty:"opacity",paletteSource:"palette",sizesSource:"sizes",controls:[{type:"stroke-size",propertyName:"size"}]};case"line":return{type:"line",colorProperty:"color",sizeProperty:"size",opacityProperty:"opacity",paletteSource:"palette",sizesSource:"sizes",controls:[{type:"stroke-size",propertyName:"size"},{type:"line-endings",propertyName:"arrows",additionalProps:{}}]};case"shape":return{type:"shape",colorProperty:"strokeColor",sizeProperty:"strokeWidth",opacityProperty:"opacity",paletteSource:"palette",sizesSource:"sizes",controls:[{type:"stroke-size",propertyName:"strokeWidth"},{type:"shape-fill",propertyName:"fillColor",additionalProps:{}}]};case"text":return{type:"text",colorProperty:"fontColor",sizeProperty:"fontSize",opacityProperty:"opacity",paletteSource:"palette",sizesSource:"sizes",controls:[{type:"font-size",propertyName:"fontSize",additionalProps:{}},{type:"font-family",propertyName:"fontFamily"}]};default:return null}}}const x=e(class extends t{constructor(e){super(),!1!==e&&this.__registerHost(),this.__attachShadow(),this.toolChange=s(this,"toolChange"),this.displayValuesChange=s(this,"displayValuesChange")}tool;handleToolChange(e,t){const s=C.getToolConfig(e);if(t&&e&&"shape"===s?.type){const i=C.getToolConfig(t);"shape"===i?.type&&[s.colorProperty,s.sizeProperty,s.opacityProperty,"fillColor"].forEach((s=>{s&&void 0!==t[s]&&(e[s]=t[s])}))}this.config=s,this.config&&(this.updatePalette(),this.updateSizes(),this.currentOpacity=e[this.config.opacityProperty]??1,this.emitDisplayValues())}isExpanded=!1;theme;engine;terms={};handleSelectionChangeBound=this.handleSelectionChange.bind(this);onThemeChange(){this.emitDisplayValues()}handleEngineChange(e,t){t&&t.removeEventListener("objectsSelectionChange",this.handleSelectionChangeBound),e&&e.addEventListener("objectsSelectionChange",this.handleSelectionChangeBound)}toolChange;displayValuesChange;config;palette=[];sizes=[];currentOpacity=1;updateTrigger=0;handleSelectionChange(){this.tool instanceof n&&(this.config=C.getToolConfig(this.tool),this.config&&(this.updatePalette(),this.updateSizes(),this.currentOpacity=this.tool[this.config.opacityProperty]??1,this.emitDisplayValues()))}disconnectedCallback(){this.engine&&this.engine.removeEventListener("objectsSelectionChange",this.handleSelectionChangeBound)}componentWillLoad(){this.config=C.getToolConfig(this.tool),this.config&&(this.updatePalette(),this.updateSizes(),this.currentOpacity=this.tool[this.config.opacityProperty]??1,this.emitDisplayValues()),this.engine&&this.engine.addEventListener("objectsSelectionChange",this.handleSelectionChangeBound)}emitDisplayValues(){if(!this.config)return;const e=this.tool[this.config.sizeProperty],t={color:a.applyOpacity(this.tool[this.config.colorProperty],this.currentOpacity,this.theme),size:e};this.tool instanceof l&&(t.fontFamily=this.tool.fontFamily),this.displayValuesChange.emit(t)}updatePalette(){this.config&&(this.palette="none"===this.config.paletteSource?[]:this.tool.palette||[])}updateSizes(){this.config&&(this.sizes="none"===this.config.sizesSource?[]:this.tool.sizes||[])}handleToggleExpand=()=>{this.isExpanded=!this.isExpanded};handleColorChange=e=>{if(this.tool[this.config.colorProperty]=e.detail,"shape"===this.config.type||"selection"===this.config.type){const t=this.tool;("string"==typeof t.fillColor?"transparent"===t.fillColor:"transparent"===t.fillColor.light&&"transparent"===t.fillColor.dark)||(t.fillColor=e.detail)}this.emitDisplayValues(),this.toolChange.emit(this.tool),this.updateTrigger++};handleSizeChange=e=>{this.tool[this.config.sizeProperty]=e.detail,this.emitDisplayValues(),this.toolChange.emit(this.tool),this.updateTrigger++};handleOpacityChange=e=>{this.tool[this.config.opacityProperty]=e.detail,this.currentOpacity=e.detail,this.emitDisplayValues(),this.toolChange.emit(this.tool)};handlePropertyChange=(e,t)=>{if("shape"!==this.config.type&&"selection"!==this.config.type||"fillColor"!==e)this.tool[e]=t,"fontFamily"===e&&this.emitDisplayValues();else{const e="filled"===t?this.tool[this.config.colorProperty]:{light:"transparent",dark:"transparent"};this.tool.fillColor=e,"filled"===t&&(this.tool[this.config.colorProperty]=e)}this.toolChange.emit(this.tool),this.updateTrigger++};getShapeFillValue(){const e=this.tool.fillColor;return("string"==typeof e?"transparent"===e:"transparent"===e.light&&"transparent"===e.dark)?"transparent":"filled"}renderControl(e){const t=this.tool[e.propertyName];switch(e.type){case"stroke-size":return i("kritzel-stroke-size",{key:e.type,sizes:this.sizes,selectedSize:t,onSizeChange:this.handleSizeChange});case"font-size":return i("kritzel-font-size",{key:e.type,sizes:this.sizes,selectedSize:t,fontFamily:this.tool.fontFamily,onSizeChange:this.handleSizeChange});case"line-endings":return i("kritzel-line-endings",{key:e.type,value:t,onValueChange:t=>this.handlePropertyChange(e.propertyName,t.detail)});case"shape-fill":return i("kritzel-shape-fill",{key:e.type,value:this.getShapeFillValue(),onValueChange:t=>this.handlePropertyChange(e.propertyName,t.detail)});case"font-family":return i("kritzel-font-family",{key:e.type,selectedFontFamily:t,onFontFamilyChange:t=>this.handlePropertyChange(e.propertyName,t.detail)});default:return null}}render(){if(!this.config)return null;const e=this.palette.length>6||"text"===this.config.type,t=this.palette.length>0,s=this.config.controls.find((e=>"stroke-size"===e.type||"font-size"===e.type)),r=this.config.controls.filter((e=>"stroke-size"!==e.type&&"font-size"!==e.type));return i(o,null,i("div",{style:{display:"flex",flexDirection:"row",gap:"8px",width:"100%"}},i("div",{style:{display:"flex",flexDirection:"column",gap:"12px",flex:"1"}},t&&i("kritzel-color-palette",{colors:this.palette,selectedColor:this.tool[this.config.colorProperty],isExpanded:this.isExpanded,isOpaque:!0,opacity:this.currentOpacity,theme:this.theme,onColorChange:this.handleColorChange}),s&&this.renderControl(s),i("kritzel-opacity-slider",{value:this.tool[this.config.opacityProperty],previewColor:this.tool[this.config.colorProperty],onValueChange:this.handleOpacityChange}),r.map((e=>[i("div",{class:"divider"}),this.renderControl(e)]))),e&&i("div",{style:{display:"flex",alignItems:"flex-start"}},i("button",{class:"expand-toggle",onClick:this.handleToggleExpand,title:this.isExpanded?this.terms["toolConfig.collapse"]??"Collapse":this.terms["toolConfig.expand"]??"Expand"},i("kritzel-icon",{name:this.isExpanded?"chevron-up":"chevron-down"})))))}static get watchers(){return{tool:[{handleToolChange:0}],theme:[{onThemeChange:0}],engine:[{handleEngineChange:0}]}}static get style(){return".expand-toggle{background:none;border:none;cursor:var(--kritzel-global-pointer-cursor, pointer);padding:0;margin:0;display:flex;align-items:center;justify-content:center;width:32px;height:32px;color:var(--kritzel-icon-color, currentColor);transition:transform 0.2s ease}.expand-toggle:hover{opacity:0.7}.expand-toggle:focus{outline:none}.expand-toggle:focus-visible{outline:2px solid var(--kritzel-focus-color, #007acc);outline-offset:2px}.expand-toggle:active{transform:scale(0.95)}.divider{height:1px;background-color:var(--kritzel-divider-color, #e0e0e0);margin:4px 0;width:100%}"}},[513,"kritzel-tool-config",{tool:[1040],isExpanded:[1028,"is-expanded"],theme:[1],engine:[16],terms:[16],config:[32],palette:[32],sizes:[32],currentOpacity:[32],updateTrigger:[32]},void 0,{tool:[{handleToolChange:0}],theme:[{onThemeChange:0}],engine:[{handleEngineChange:0}]}]);function b(){"undefined"!=typeof customElements&&["kritzel-tool-config","kritzel-color","kritzel-color-palette","kritzel-dropdown","kritzel-font","kritzel-font-family","kritzel-font-size","kritzel-icon","kritzel-line-endings","kritzel-opacity-slider","kritzel-shape-fill","kritzel-stroke-size"].forEach((e=>{switch(e){case"kritzel-tool-config":customElements.get(r(e))||customElements.define(r(e),x);break;case"kritzel-color":customElements.get(r(e))||h();break;case"kritzel-color-palette":customElements.get(r(e))||p();break;case"kritzel-dropdown":customElements.get(r(e))||c();break;case"kritzel-font":customElements.get(r(e))||d();break;case"kritzel-font-family":customElements.get(r(e))||m();break;case"kritzel-font-size":customElements.get(r(e))||f();break;case"kritzel-icon":customElements.get(r(e))||u();break;case"kritzel-line-endings":customElements.get(r(e))||g();break;case"kritzel-opacity-slider":customElements.get(r(e))||z();break;case"kritzel-shape-fill":customElements.get(r(e))||y();break;case"kritzel-stroke-size":customElements.get(r(e))||k()}}))}export{C as K,x as a,b as d}
1
+ import{p as e,H as t,c as s,h as i,d as o,t as r}from"./p-B43upypT.js";import{f as n,e as l}from"./p-BVu03tNB.js";import{a}from"./p-BmyTdQGy.js";import{d as h}from"./p-BcB97x3U.js";import{d as p}from"./p-wl9BhN6s.js";import{d as c}from"./p-Df3BwVGy.js";import{d}from"./p-BX-nQAyH.js";import{d as m}from"./p-JhOYwUOj.js";import{d as f}from"./p-Cb5YwXbC.js";import{d as u}from"./p-CdR76C4L.js";import{d as g}from"./p-CXpv9Rxe.js";import{d as y}from"./p-CdkNxxut.js";import{d as z}from"./p-BFYtCsZu.js";import{d as k}from"./p-7ZnANv7C.js";class C{static getToolConfig(e){switch(e?.toolType){case"selection":return"getToolConfig"in e&&"function"==typeof e.getToolConfig?e.getToolConfig():null;case"brush":return{type:"brush",colorProperty:"color",sizeProperty:"size",opacityProperty:"opacity",paletteSource:"palette",sizesSource:"sizes",controls:[{type:"stroke-size",propertyName:"size"}]};case"line":return{type:"line",colorProperty:"color",sizeProperty:"size",opacityProperty:"opacity",paletteSource:"palette",sizesSource:"sizes",controls:[{type:"stroke-size",propertyName:"size"},{type:"line-endings",propertyName:"arrows",additionalProps:{}}]};case"shape":return{type:"shape",colorProperty:"strokeColor",sizeProperty:"strokeWidth",opacityProperty:"opacity",paletteSource:"palette",sizesSource:"sizes",controls:[{type:"stroke-size",propertyName:"strokeWidth"},{type:"shape-fill",propertyName:"fillColor",additionalProps:{}}]};case"text":return{type:"text",colorProperty:"fontColor",sizeProperty:"fontSize",opacityProperty:"opacity",paletteSource:"palette",sizesSource:"sizes",controls:[{type:"font-size",propertyName:"fontSize",additionalProps:{}},{type:"font-family",propertyName:"fontFamily"}]};default:return null}}}const x=e(class extends t{constructor(e){super(),!1!==e&&this.__registerHost(),this.__attachShadow(),this.toolChange=s(this,"toolChange"),this.displayValuesChange=s(this,"displayValuesChange")}tool;handleToolChange(e,t){const s=C.getToolConfig(e);if(t&&e&&"shape"===s?.type){const i=C.getToolConfig(t);"shape"===i?.type&&[s.colorProperty,s.sizeProperty,s.opacityProperty,"fillColor"].forEach((s=>{s&&void 0!==t[s]&&(e[s]=t[s])}))}this.config=s,this.config&&(this.updatePalette(),this.updateSizes(),this.currentOpacity=e[this.config.opacityProperty]??1,this.emitDisplayValues())}isExpanded=!1;theme;engine;terms={};handleSelectionChangeBound=this.handleSelectionChange.bind(this);onThemeChange(){this.emitDisplayValues()}handleEngineChange(e,t){t&&t.removeEventListener("objectsSelectionChange",this.handleSelectionChangeBound),e&&e.addEventListener("objectsSelectionChange",this.handleSelectionChangeBound)}toolChange;displayValuesChange;config;palette=[];sizes=[];currentOpacity=1;updateTrigger=0;handleSelectionChange(){this.tool instanceof n&&(this.config=C.getToolConfig(this.tool),this.config&&(this.updatePalette(),this.updateSizes(),this.currentOpacity=this.tool[this.config.opacityProperty]??1,this.emitDisplayValues()))}disconnectedCallback(){this.engine&&this.engine.removeEventListener("objectsSelectionChange",this.handleSelectionChangeBound)}componentWillLoad(){this.config=C.getToolConfig(this.tool),this.config&&(this.updatePalette(),this.updateSizes(),this.currentOpacity=this.tool[this.config.opacityProperty]??1,this.emitDisplayValues()),this.engine&&this.engine.addEventListener("objectsSelectionChange",this.handleSelectionChangeBound)}emitDisplayValues(){if(!this.config)return;const e=this.tool[this.config.sizeProperty],t={color:a.applyOpacity(this.tool[this.config.colorProperty],this.currentOpacity,this.theme),size:e};this.tool instanceof l&&(t.fontFamily=this.tool.fontFamily),this.displayValuesChange.emit(t)}updatePalette(){this.config&&(this.palette="none"===this.config.paletteSource?[]:this.tool.palette||[])}updateSizes(){this.config&&(this.sizes="none"===this.config.sizesSource?[]:this.tool.sizes||[])}handleToggleExpand=()=>{this.isExpanded=!this.isExpanded};handleColorChange=e=>{if(this.tool[this.config.colorProperty]=e.detail,"shape"===this.config.type||"selection"===this.config.type){const t=this.tool;("string"==typeof t.fillColor?"transparent"===t.fillColor:"transparent"===t.fillColor.light&&"transparent"===t.fillColor.dark)||(t.fillColor=e.detail)}this.emitDisplayValues(),this.toolChange.emit(this.tool),this.updateTrigger++};handleSizeChange=e=>{this.tool[this.config.sizeProperty]=e.detail,this.emitDisplayValues(),this.toolChange.emit(this.tool),this.updateTrigger++};handleOpacityChange=e=>{this.tool[this.config.opacityProperty]=e.detail,this.currentOpacity=e.detail,this.emitDisplayValues(),this.toolChange.emit(this.tool)};handlePropertyChange=(e,t)=>{if("shape"!==this.config.type&&"selection"!==this.config.type||"fillColor"!==e)this.tool[e]=t,"fontFamily"===e&&this.emitDisplayValues();else{const e="filled"===t?this.tool[this.config.colorProperty]:{light:"transparent",dark:"transparent"};this.tool.fillColor=e,"filled"===t&&(this.tool[this.config.colorProperty]=e)}this.toolChange.emit(this.tool),this.updateTrigger++};getShapeFillValue(){const e=this.tool.fillColor;return("string"==typeof e?"transparent"===e:"transparent"===e.light&&"transparent"===e.dark)?"transparent":"filled"}renderControl(e){const t=this.tool[e.propertyName];switch(e.type){case"stroke-size":return i("kritzel-stroke-size",{key:e.type,sizes:this.sizes,selectedSize:t,onSizeChange:this.handleSizeChange});case"font-size":return i("kritzel-font-size",{key:e.type,sizes:this.sizes,selectedSize:t,fontFamily:this.tool.fontFamily,onSizeChange:this.handleSizeChange});case"line-endings":return i("kritzel-line-endings",{key:e.type,value:t,onValueChange:t=>this.handlePropertyChange(e.propertyName,t.detail)});case"shape-fill":return i("kritzel-shape-fill",{key:e.type,value:this.getShapeFillValue(),onValueChange:t=>this.handlePropertyChange(e.propertyName,t.detail)});case"font-family":return i("kritzel-font-family",{key:e.type,selectedFontFamily:t,onFontFamilyChange:t=>this.handlePropertyChange(e.propertyName,t.detail)});default:return null}}render(){if(!this.config)return null;const e=this.palette.length>6||"text"===this.config.type,t=this.palette.length>0,s=this.config.controls.find((e=>"stroke-size"===e.type||"font-size"===e.type)),r=this.config.controls.filter((e=>"stroke-size"!==e.type&&"font-size"!==e.type));return i(o,null,i("div",{style:{display:"flex",flexDirection:"row",gap:"8px",width:"100%"}},i("div",{style:{display:"flex",flexDirection:"column",gap:"12px",flex:"1"}},t&&i("kritzel-color-palette",{colors:this.palette,selectedColor:this.tool[this.config.colorProperty],isExpanded:this.isExpanded,isOpaque:!0,opacity:this.currentOpacity,theme:this.theme,onColorChange:this.handleColorChange}),s&&this.renderControl(s),i("kritzel-opacity-slider",{value:this.tool[this.config.opacityProperty],previewColor:this.tool[this.config.colorProperty],onValueChange:this.handleOpacityChange}),r.map((e=>[i("div",{class:"divider"}),this.renderControl(e)]))),e&&i("div",{style:{display:"flex",alignItems:"flex-start"}},i("button",{class:"expand-toggle",onClick:this.handleToggleExpand,title:this.isExpanded?this.terms["toolConfig.collapse"]??"Collapse":this.terms["toolConfig.expand"]??"Expand"},i("kritzel-icon",{name:this.isExpanded?"chevron-up":"chevron-down"})))))}static get watchers(){return{tool:[{handleToolChange:0}],theme:[{onThemeChange:0}],engine:[{handleEngineChange:0}]}}static get style(){return".expand-toggle{background:none;border:none;cursor:var(--kritzel-global-pointer-cursor, pointer);padding:0;margin:0;display:flex;align-items:center;justify-content:center;width:32px;height:32px;color:var(--kritzel-icon-color, currentColor);transition:transform 0.2s ease}.expand-toggle:hover{opacity:0.7}.expand-toggle:focus{outline:none}.expand-toggle:focus-visible{outline:2px solid var(--kritzel-focus-color, #007acc);outline-offset:2px}.expand-toggle:active{transform:scale(0.95)}.divider{height:1px;background-color:var(--kritzel-divider-color, #e0e0e0);margin:4px 0;width:100%}"}},[513,"kritzel-tool-config",{tool:[1040],isExpanded:[1028,"is-expanded"],theme:[1],engine:[16],terms:[16],config:[32],palette:[32],sizes:[32],currentOpacity:[32],updateTrigger:[32]},void 0,{tool:[{handleToolChange:0}],theme:[{onThemeChange:0}],engine:[{handleEngineChange:0}]}]);function b(){"undefined"!=typeof customElements&&["kritzel-tool-config","kritzel-color","kritzel-color-palette","kritzel-dropdown","kritzel-font","kritzel-font-family","kritzel-font-size","kritzel-icon","kritzel-line-endings","kritzel-opacity-slider","kritzel-shape-fill","kritzel-stroke-size"].forEach((e=>{switch(e){case"kritzel-tool-config":customElements.get(r(e))||customElements.define(r(e),x);break;case"kritzel-color":customElements.get(r(e))||h();break;case"kritzel-color-palette":customElements.get(r(e))||p();break;case"kritzel-dropdown":customElements.get(r(e))||c();break;case"kritzel-font":customElements.get(r(e))||d();break;case"kritzel-font-family":customElements.get(r(e))||m();break;case"kritzel-font-size":customElements.get(r(e))||f();break;case"kritzel-icon":customElements.get(r(e))||u();break;case"kritzel-line-endings":customElements.get(r(e))||g();break;case"kritzel-opacity-slider":customElements.get(r(e))||y();break;case"kritzel-shape-fill":customElements.get(r(e))||z();break;case"kritzel-stroke-size":customElements.get(r(e))||k()}}))}export{C as K,x as a,b as d}