kritzel-stencil 0.0.104 → 0.0.106

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 (172) hide show
  1. package/dist/cjs/index-D62tBCuq.js.map +1 -1
  2. package/dist/cjs/kritzel-brush-style_18.cjs.entry.js +281 -2167
  3. package/dist/cjs/kritzel-brush-style_18.cjs.entry.js.map +1 -1
  4. package/dist/cjs/loader.cjs.js +1 -1
  5. package/dist/cjs/stencil.cjs.js +1 -1
  6. package/dist/cjs/stencil.cjs.js.map +1 -1
  7. package/dist/collection/classes/handlers/context-menu.handler.js +1 -1
  8. package/dist/collection/classes/handlers/context-menu.handler.js.map +1 -1
  9. package/dist/collection/classes/handlers/rotation.handler.js +1 -0
  10. package/dist/collection/classes/handlers/rotation.handler.js.map +1 -1
  11. package/dist/collection/classes/handlers/selection.handler.js +4 -4
  12. package/dist/collection/classes/handlers/selection.handler.js.map +1 -1
  13. package/dist/collection/classes/objects/base-object.class.js +7 -2
  14. package/dist/collection/classes/objects/base-object.class.js.map +1 -1
  15. package/dist/collection/classes/objects/image.class.js +15 -10
  16. package/dist/collection/classes/objects/image.class.js.map +1 -1
  17. package/dist/collection/classes/objects/path.class.js +22 -16
  18. package/dist/collection/classes/objects/path.class.js.map +1 -1
  19. package/dist/collection/classes/objects/selection-box.class.js +15 -9
  20. package/dist/collection/classes/objects/selection-box.class.js.map +1 -1
  21. package/dist/collection/classes/objects/selection-group.class.js +19 -12
  22. package/dist/collection/classes/objects/selection-group.class.js.map +1 -1
  23. package/dist/collection/classes/objects/text.class.js +29 -12
  24. package/dist/collection/classes/objects/text.class.js.map +1 -1
  25. package/dist/collection/classes/reviver.class.js +4 -4
  26. package/dist/collection/classes/reviver.class.js.map +1 -1
  27. package/dist/collection/classes/store.class.js +30 -14
  28. package/dist/collection/classes/store.class.js.map +1 -1
  29. package/dist/collection/classes/structures/octree.structure.js +2 -2
  30. package/dist/collection/classes/structures/octree.structure.js.map +1 -1
  31. package/dist/collection/classes/tools/brush-tool.class.js +4 -4
  32. package/dist/collection/classes/tools/brush-tool.class.js.map +1 -1
  33. package/dist/collection/classes/tools/image-tool.class.js +3 -2
  34. package/dist/collection/classes/tools/image-tool.class.js.map +1 -1
  35. package/dist/collection/classes/tools/selection-tool.class.js +1 -1
  36. package/dist/collection/classes/tools/selection-tool.class.js.map +1 -1
  37. package/dist/collection/classes/tools/text-tool.class.js +2 -2
  38. package/dist/collection/classes/tools/text-tool.class.js.map +1 -1
  39. package/dist/collection/components/core/kritzel-cursor-trail/kritzel-cursor-trail.css +10 -10
  40. package/dist/collection/components/core/kritzel-cursor-trail/kritzel-cursor-trail.js +1 -1
  41. package/dist/collection/components/core/kritzel-cursor-trail/kritzel-cursor-trail.js.map +1 -1
  42. package/dist/collection/components/core/kritzel-editor/kritzel-editor.js +42 -1
  43. package/dist/collection/components/core/kritzel-editor/kritzel-editor.js.map +1 -1
  44. package/dist/collection/components/core/kritzel-engine/kritzel-engine.js +236 -23
  45. package/dist/collection/components/core/kritzel-engine/kritzel-engine.js.map +1 -1
  46. package/dist/collection/components/shared/kritzel-brush-style/kritzel-brush-style.css +43 -43
  47. package/dist/collection/components/shared/kritzel-brush-style/kritzel-brush-style.js +3 -3
  48. package/dist/collection/components/shared/kritzel-brush-style/kritzel-brush-style.js.map +1 -1
  49. package/dist/collection/components/shared/kritzel-color/kritzel-color.css +20 -20
  50. package/dist/collection/components/shared/kritzel-color/kritzel-color.js +2 -2
  51. package/dist/collection/components/shared/kritzel-color/kritzel-color.js.map +1 -1
  52. package/dist/collection/components/shared/kritzel-color-palette/kritzel-color-palette.js +1 -1
  53. package/dist/collection/components/shared/kritzel-dropdown/kritzel-dropdown.css +53 -53
  54. package/dist/collection/components/shared/kritzel-dropdown/kritzel-dropdown.js +2 -2
  55. package/dist/collection/components/shared/kritzel-dropdown/kritzel-dropdown.js.map +1 -1
  56. package/dist/collection/components/shared/kritzel-font/kritzel-font.css +10 -10
  57. package/dist/collection/components/shared/kritzel-font/kritzel-font.js +1 -1
  58. package/dist/collection/components/shared/kritzel-font/kritzel-font.js.map +1 -1
  59. package/dist/collection/components/shared/kritzel-font-family/kritzel-font-family.css +48 -48
  60. package/dist/collection/components/shared/kritzel-font-family/kritzel-font-family.js +3 -3
  61. package/dist/collection/components/shared/kritzel-font-family/kritzel-font-family.js.map +1 -1
  62. package/dist/collection/components/shared/kritzel-font-size/kritzel-font-size.css +30 -30
  63. package/dist/collection/components/shared/kritzel-font-size/kritzel-font-size.js +1 -1
  64. package/dist/collection/components/shared/kritzel-font-size/kritzel-font-size.js.map +1 -1
  65. package/dist/collection/components/shared/kritzel-icon/kritzel-icon.css +17 -17
  66. package/dist/collection/components/shared/kritzel-stroke-size/kritzel-stroke-size.js +1 -1
  67. package/dist/collection/components/shared/kritzel-tooltip/kritzel-tooltip.css +17 -17
  68. package/dist/collection/components/shared/kritzel-tooltip/kritzel-tooltip.js +4 -4
  69. package/dist/collection/components/shared/kritzel-tooltip/kritzel-tooltip.js.map +1 -1
  70. package/dist/collection/components/ui/kritzel-context-menu/kritzel-context-menu.js +1 -1
  71. package/dist/collection/components/ui/kritzel-context-menu/kritzel-context-menu.js.map +1 -1
  72. package/dist/collection/components/ui/kritzel-control-brush-config/kritzel-control-brush-config.css +18 -18
  73. package/dist/collection/components/ui/kritzel-control-brush-config/kritzel-control-brush-config.js +2 -2
  74. package/dist/collection/components/ui/kritzel-control-brush-config/kritzel-control-brush-config.js.map +1 -1
  75. package/dist/collection/components/ui/kritzel-control-text-config/kritzel-control-text-config.js +2 -2
  76. package/dist/collection/components/ui/kritzel-controls/kritzel-controls.js +2 -2
  77. package/dist/collection/components/ui/kritzel-utility-panel/kritzel-utility-panel.js +1 -1
  78. package/dist/collection/helpers/object.helper.js +2 -15
  79. package/dist/collection/helpers/object.helper.js.map +1 -1
  80. package/dist/collection/interfaces/object.interface.js.map +1 -1
  81. package/dist/components/kritzel-brush-style.js +1 -1
  82. package/dist/components/kritzel-color-palette.js +1 -1
  83. package/dist/components/kritzel-color.js +1 -1
  84. package/dist/components/kritzel-context-menu.js +1 -1
  85. package/dist/components/kritzel-control-brush-config.js +1 -1
  86. package/dist/components/kritzel-control-text-config.js +1 -1
  87. package/dist/components/kritzel-controls.js +1 -1
  88. package/dist/components/kritzel-cursor-trail.js +1 -1
  89. package/dist/components/kritzel-dropdown.js +1 -1
  90. package/dist/components/kritzel-editor.js +58 -18
  91. package/dist/components/kritzel-editor.js.map +1 -1
  92. package/dist/components/kritzel-engine.js +1 -1
  93. package/dist/components/kritzel-font-family.js +1 -1
  94. package/dist/components/kritzel-font-size.js +1 -1
  95. package/dist/components/kritzel-font.js +1 -1
  96. package/dist/components/kritzel-stroke-size.js +1 -1
  97. package/dist/components/kritzel-tooltip.js +1 -1
  98. package/dist/components/kritzel-utility-panel.js +1 -1
  99. package/dist/components/{p-X3xYsp4r.js → p-9IX8ss5J.js} +6 -6
  100. package/dist/components/p-9IX8ss5J.js.map +1 -0
  101. package/dist/components/{p-Ddfewfv9.js → p-B1tJ3Woq.js} +3 -3
  102. package/dist/components/{p-Ddfewfv9.js.map → p-B1tJ3Woq.js.map} +1 -1
  103. package/dist/components/{p-D06w3u84.js → p-B7P9QBiE.js} +4 -4
  104. package/dist/components/p-B7P9QBiE.js.map +1 -0
  105. package/dist/components/{p-BjqfG-5H.js → p-BFlJumTk.js} +10 -10
  106. package/dist/components/{p-BjqfG-5H.js.map → p-BFlJumTk.js.map} +1 -1
  107. package/dist/components/p-BcQCX1Z6.js +813 -0
  108. package/dist/components/p-BcQCX1Z6.js.map +1 -0
  109. package/dist/components/{p-_wFpvzNp.js → p-Bhfk_puI.js} +4 -4
  110. package/dist/components/p-Bhfk_puI.js.map +1 -0
  111. package/dist/components/{p-BYH2jNAX.js → p-CF5pcRGS.js} +4 -4
  112. package/dist/components/{p-BYH2jNAX.js.map → p-CF5pcRGS.js.map} +1 -1
  113. package/dist/components/p-CZkSABuJ.js.map +1 -1
  114. package/dist/components/{p-BYt7-mGK.js → p-Cbu5RSmC.js} +3 -3
  115. package/dist/components/{p-BYt7-mGK.js.map → p-Cbu5RSmC.js.map} +1 -1
  116. package/dist/components/{p-DaeIjoQm.js → p-Ck2d5Wd1.js} +4 -4
  117. package/dist/components/p-Ck2d5Wd1.js.map +1 -0
  118. package/dist/components/{p-DMSOfO6k.js → p-CkPd1oL1.js} +165 -84
  119. package/dist/components/p-CkPd1oL1.js.map +1 -0
  120. package/dist/components/{p-C8KDwUb7.js → p-D9nf_Yw4.js} +3 -3
  121. package/dist/components/p-D9nf_Yw4.js.map +1 -0
  122. package/dist/components/p-DC8SDK2U.js.map +1 -1
  123. package/dist/components/{p-DJUnTtGg.js → p-DIxwvThL.js} +17 -17
  124. package/dist/components/{p-DJUnTtGg.js.map → p-DIxwvThL.js.map} +1 -1
  125. package/dist/components/{p-CDhTT8u8.js → p-Ds3FhuuO.js} +3 -3
  126. package/dist/components/p-Ds3FhuuO.js.map +1 -0
  127. package/dist/components/{p-BgUIonZF.js → p-I1jXruHK.js} +4 -4
  128. package/dist/components/p-I1jXruHK.js.map +1 -0
  129. package/dist/components/{p-BqUM5gV3.js → p-JvUh5Cky.js} +9 -9
  130. package/dist/components/p-JvUh5Cky.js.map +1 -0
  131. package/dist/components/{p-DQHNxDS7.js → p-c6tIpE_t.js} +3 -3
  132. package/dist/components/p-c6tIpE_t.js.map +1 -0
  133. package/dist/components/{p-BJ5xxphF.js → p-wUZba7Vi.js} +4 -4
  134. package/dist/components/{p-BJ5xxphF.js.map → p-wUZba7Vi.js.map} +1 -1
  135. package/dist/esm/index-BOJOOWaP.js.map +1 -1
  136. package/dist/esm/kritzel-brush-style_18.entry.js +281 -2167
  137. package/dist/esm/kritzel-brush-style_18.entry.js.map +1 -1
  138. package/dist/esm/loader.js +1 -1
  139. package/dist/esm/stencil.js +1 -1
  140. package/dist/esm/stencil.js.map +1 -1
  141. package/dist/stencil/p-7aaf3e49.entry.js +2 -0
  142. package/dist/stencil/p-7aaf3e49.entry.js.map +1 -0
  143. package/dist/stencil/p-BOJOOWaP.js.map +1 -1
  144. package/dist/stencil/stencil.esm.js +1 -1
  145. package/dist/stencil/stencil.esm.js.map +1 -1
  146. package/dist/types/classes/objects/base-object.class.d.ts +4 -3
  147. package/dist/types/classes/objects/image.class.d.ts +2 -2
  148. package/dist/types/classes/objects/path.class.d.ts +1 -1
  149. package/dist/types/classes/objects/selection-box.class.d.ts +1 -1
  150. package/dist/types/classes/objects/selection-group.class.d.ts +1 -1
  151. package/dist/types/classes/objects/text.class.d.ts +12 -1
  152. package/dist/types/classes/store.class.d.ts +3 -3
  153. package/dist/types/components/core/kritzel-editor/kritzel-editor.d.ts +7 -0
  154. package/dist/types/components/core/kritzel-engine/kritzel-engine.d.ts +8 -1
  155. package/dist/types/components.d.ts +11 -3
  156. package/dist/types/helpers/object.helper.d.ts +0 -1
  157. package/dist/types/interfaces/object.interface.d.ts +1 -1
  158. package/package.json +3 -5
  159. package/dist/components/p-BgUIonZF.js.map +0 -1
  160. package/dist/components/p-BqUM5gV3.js.map +0 -1
  161. package/dist/components/p-C8KDwUb7.js.map +0 -1
  162. package/dist/components/p-CDhTT8u8.js.map +0 -1
  163. package/dist/components/p-CFkDfXW4.js +0 -2814
  164. package/dist/components/p-CFkDfXW4.js.map +0 -1
  165. package/dist/components/p-D06w3u84.js.map +0 -1
  166. package/dist/components/p-DMSOfO6k.js.map +0 -1
  167. package/dist/components/p-DQHNxDS7.js.map +0 -1
  168. package/dist/components/p-DaeIjoQm.js.map +0 -1
  169. package/dist/components/p-X3xYsp4r.js.map +0 -1
  170. package/dist/components/p-_wFpvzNp.js.map +0 -1
  171. package/dist/stencil/p-f059fbff.entry.js +0 -2
  172. package/dist/stencil/p-f059fbff.entry.js.map +0 -1
@@ -0,0 +1,813 @@
1
+ var KritzelMouseButton;
2
+ (function (KritzelMouseButton) {
3
+ KritzelMouseButton[KritzelMouseButton["Left"] = 0] = "Left";
4
+ KritzelMouseButton[KritzelMouseButton["Middle"] = 1] = "Middle";
5
+ KritzelMouseButton[KritzelMouseButton["Right"] = 2] = "Right";
6
+ })(KritzelMouseButton || (KritzelMouseButton = {}));
7
+
8
+ class KritzelEventHelper {
9
+ static isRightClick(ev) {
10
+ return ev.button === KritzelMouseButton.Right;
11
+ }
12
+ static isLeftClick(ev) {
13
+ return ev.button === KritzelMouseButton.Left;
14
+ }
15
+ static isMainMouseWheel(event) {
16
+ return Math.abs(event.deltaY) > 0 && Math.abs(event.deltaX) === 0 && Number.isInteger(event.deltaY);
17
+ }
18
+ static detectDoubleTap() {
19
+ const currentTime = Date.now();
20
+ const tapLength = currentTime - KritzelEventHelper.lastTapTimestamp;
21
+ if (KritzelEventHelper.tapTimeoutId) {
22
+ clearTimeout(KritzelEventHelper.tapTimeoutId);
23
+ KritzelEventHelper.tapTimeoutId = null;
24
+ }
25
+ if (tapLength < KritzelEventHelper.doubleTapTimeout && tapLength > 0) {
26
+ KritzelEventHelper.lastTapTimestamp = 0;
27
+ return true;
28
+ }
29
+ else {
30
+ KritzelEventHelper.lastTapTimestamp = currentTime;
31
+ KritzelEventHelper.tapTimeoutId = setTimeout(() => {
32
+ KritzelEventHelper.tapTimeoutId = null;
33
+ }, KritzelEventHelper.doubleTapTimeout);
34
+ return false;
35
+ }
36
+ }
37
+ }
38
+ KritzelEventHelper.lastTapTimestamp = 0;
39
+ KritzelEventHelper.tapTimeoutId = null;
40
+ KritzelEventHelper.doubleTapTimeout = 300;
41
+
42
+ class KritzelBaseCommand {
43
+ constructor(store, initiator) {
44
+ var _a, _b;
45
+ this._store = store;
46
+ this.initiator = (_b = (_a = initiator === null || initiator === void 0 ? void 0 : initiator.constructor) === null || _a === void 0 ? void 0 : _a.name) !== null && _b !== void 0 ? _b : 'Unknown';
47
+ this.isUndoable = true;
48
+ }
49
+ execute() {
50
+ throw new Error('Method not implemented.');
51
+ }
52
+ undo() {
53
+ throw new Error('Method not implemented.');
54
+ }
55
+ }
56
+
57
+ class AddObjectCommand extends KritzelBaseCommand {
58
+ constructor(store, initiator, object) {
59
+ super(store, initiator);
60
+ this.object = object;
61
+ }
62
+ execute() {
63
+ this._store.state.objectsOctree.insert(this.object);
64
+ }
65
+ undo() {
66
+ this._store.state.objectsOctree.remove(object => object.id === this.object.id);
67
+ }
68
+ }
69
+
70
+ var cjs = {};
71
+
72
+ var hasRequiredCjs;
73
+
74
+ function requireCjs () {
75
+ if (hasRequiredCjs) return cjs;
76
+ hasRequiredCjs = 1;
77
+ (function (exports) {
78
+ var pe=Object.defineProperty;var ge=e=>pe(e,"__esModule",{value:true});var de=(e,t)=>{ge(e);for(var s in t)pe(e,s,{get:t[s],enumerable:true});};de(exports,{default:()=>ve,getStroke:()=>ne,getStrokeOutlinePoints:()=>te,getStrokePoints:()=>re});function $(e,t,s,x=h=>h){return e*x(.5-t*(.5-s))}function ce(e){return [-e[0],-e[1]]}function l(e,t){return [e[0]+t[0],e[1]+t[1]]}function a(e,t){return [e[0]-t[0],e[1]-t[1]]}function b(e,t){return [e[0]*t,e[1]*t]}function xe(e,t){return [e[0]/t,e[1]/t]}function R(e){return [e[1],-e[0]]}function B(e,t){return e[0]*t[0]+e[1]*t[1]}function me(e,t){return e[0]===t[0]&&e[1]===t[1]}function Se(e){return Math.hypot(e[0],e[1])}function Pe(e){return e[0]*e[0]+e[1]*e[1]}function A(e,t){return Pe(a(e,t))}function G(e){return xe(e,Se(e))}function ae(e,t){return Math.hypot(e[1]-t[1],e[0]-t[0])}function L(e,t,s){let x=Math.sin(s),h=Math.cos(s),y=e[0]-t[0],n=e[1]-t[1],f=y*h-n*x,d=y*x+n*h;return [f+t[0],d+t[1]]}function K(e,t,s){return l(e,b(a(t,e),s))}function ee(e,t,s){return l(e,b(t,s))}var{min:C,PI:ke}=Math,le=.275,V=ke+1e-4;function te(e,t={}){let{size:s=16,smoothing:x=.5,thinning:h=.5,simulatePressure:y=true,easing:n=r=>r,start:f={},end:d={},last:D=false}=t,{cap:S=true,easing:j=r=>r*(2-r)}=f,{cap:q=true,easing:c=r=>--r*r*r+1}=d;if(e.length===0||s<=0)return [];let p=e[e.length-1].runningLength,g=f.taper===false?0:f.taper===true?Math.max(s,p):f.taper,T=d.taper===false?0:d.taper===true?Math.max(s,p):d.taper,oe=Math.pow(s*x,2),_=[],M=[],H=e.slice(0,10).reduce((r,i)=>{let o=i.pressure;if(y){let u=C(1,i.distance/s),W=C(1,1-u);o=C(1,r+(W-r)*(u*le));}return (r+o)/2},e[0].pressure),m=$(s,h,e[e.length-1].pressure,n),U,X=e[0].vector,z=e[0].point,F=z,O=z,E=F,J=false;for(let r=0;r<e.length;r++){let{pressure:i}=e[r],{point:o,vector:u,distance:W,runningLength:I}=e[r];if(r<e.length-1&&p-I<3)continue;if(h){if(y){let v=C(1,W/s),Z=C(1,1-v);i=C(1,H+(Z-H)*(v*le));}m=$(s,h,i,n);}else m=s/2;U===void 0&&(U=m);let fe=I<g?j(I/g):1,be=p-I<T?c((p-I)/T):1;m=Math.max(.01,m*Math.min(fe,be));let se=(r<e.length-1?e[r+1]:e[r]).vector,Y=r<e.length-1?B(u,se):1,he=B(u,X)<0&&!J,ue=Y!==null&&Y<0;if(he||ue){let v=b(R(X),m);for(let Z=1/13,w=0;w<=1;w+=Z)O=L(a(o,v),o,V*w),_.push(O),E=L(l(o,v),o,V*-w),M.push(E);z=O,F=E,ue&&(J=true);continue}if(J=false,r===e.length-1){let v=b(R(u),m);_.push(a(o,v)),M.push(l(o,v));continue}let ie=b(R(K(se,u,Y)),m);O=a(o,ie),(r<=1||A(z,O)>oe)&&(_.push(O),z=O),E=l(o,ie),(r<=1||A(F,E)>oe)&&(M.push(E),F=E),H=i,X=u;}let P=e[0].point.slice(0,2),k=e.length>1?e[e.length-1].point.slice(0,2):l(e[0].point,[1,1]),Q=[],N=[];if(e.length===1){if(!(g||T)||D){let r=ee(P,G(R(a(P,k))),-(U||m)),i=[];for(let o=1/13,u=o;u<=1;u+=o)i.push(L(r,P,V*2*u));return i}}else {if(!(g||T&&e.length===1))if(S)for(let i=1/13,o=i;o<=1;o+=i){let u=L(M[0],P,V*o);Q.push(u);}else {let i=a(_[0],M[0]),o=b(i,.5),u=b(i,.51);Q.push(a(P,o),a(P,u),l(P,u),l(P,o));}let r=R(ce(e[e.length-1].vector));if(T||g&&e.length===1)N.push(k);else if(q){let i=ee(k,r,m);for(let o=1/29,u=o;u<1;u+=o)N.push(L(i,k,V*3*u));}else N.push(l(k,b(r,m)),l(k,b(r,m*.99)),a(k,b(r,m*.99)),a(k,b(r,m)));}return _.concat(N,M.reverse(),Q)}function re(e,t={}){var q;let{streamline:s=.5,size:x=16,last:h=false}=t;if(e.length===0)return [];let y=.15+(1-s)*.85,n=Array.isArray(e[0])?e:e.map(({x:c,y:p,pressure:g=.5})=>[c,p,g]);if(n.length===2){let c=n[1];n=n.slice(0,-1);for(let p=1;p<5;p++)n.push(K(n[0],c,p/4));}n.length===1&&(n=[...n,[...l(n[0],[1,1]),...n[0].slice(2)]]);let f=[{point:[n[0][0],n[0][1]],pressure:n[0][2]>=0?n[0][2]:.25,vector:[1,1],distance:0,runningLength:0}],d=false,D=0,S=f[0],j=n.length-1;for(let c=1;c<n.length;c++){let p=h&&c===j?n[c].slice(0,2):K(S.point,n[c],y);if(me(S.point,p))continue;let g=ae(p,S.point);if(D+=g,c<j&&!d){if(D<x)continue;d=true;}S={point:p,pressure:n[c][2]>=0?n[c][2]:.5,vector:G(a(S.point,p)),distance:g,runningLength:D},f.push(S);}return f[0].vector=((q=f[1])==null?void 0:q.vector)||[0,0],f}function ne(e,t={}){return te(re(e,t),t)}var ve=ne;
79
+ } (cjs));
80
+ return cjs;
81
+ }
82
+
83
+ var cjsExports = requireCjs();
84
+
85
+ class KritzelMathHelper {
86
+ static average(a, b) {
87
+ return (a + b) / 2;
88
+ }
89
+ }
90
+
91
+ var __rest = (undefined && undefined.__rest) || function (s, e) {
92
+ var t = {};
93
+ for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)
94
+ t[p] = s[p];
95
+ if (s != null && typeof Object.getOwnPropertySymbols === "function")
96
+ for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {
97
+ if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i]))
98
+ t[p[i]] = s[p[i]];
99
+ }
100
+ return t;
101
+ };
102
+ class ObjectHelper {
103
+ static generateUUID() {
104
+ return Math.random().toString(36).substr(2, 9);
105
+ }
106
+ static clone(objOrObjs) {
107
+ const cloneObject = (obj) => {
108
+ const remainingProps = __rest(obj, ["_store", "_elementRef", "totalWidth", "totalHeight"]);
109
+ return structuredClone(remainingProps);
110
+ };
111
+ if (Array.isArray(objOrObjs)) {
112
+ return objOrObjs.map(cloneObject);
113
+ }
114
+ return cloneObject(objOrObjs);
115
+ }
116
+ static isEmpty(obj) {
117
+ if (obj === null || obj === undefined) {
118
+ return true;
119
+ }
120
+ return (Object === null || Object === void 0 ? void 0 : Object.keys(obj).length) === 0 && (obj === null || obj === void 0 ? void 0 : obj.constructor) === Object;
121
+ }
122
+ }
123
+
124
+ class KritzelBaseObject {
125
+ get totalWidth() {
126
+ return this.width + this.padding * 2;
127
+ }
128
+ get totalHeight() {
129
+ return this.height + this.padding * 2;
130
+ }
131
+ set elementRef(element) {
132
+ this._elementRef = element;
133
+ }
134
+ get elementRef() {
135
+ return this._elementRef;
136
+ }
137
+ get boundingBox() {
138
+ return {
139
+ x: this.translateX,
140
+ y: this.translateY,
141
+ z: this.scale,
142
+ width: this.totalWidth / this.scale,
143
+ height: this.totalHeight / this.scale,
144
+ depth: 0,
145
+ };
146
+ }
147
+ get rotatedBoundingBox() {
148
+ return {
149
+ x: this.minXRotated,
150
+ y: this.minYRotated,
151
+ z: this.scale,
152
+ width: this.maxXRotated - this.minXRotated,
153
+ height: this.maxYRotated - this.minYRotated,
154
+ depth: 0,
155
+ };
156
+ }
157
+ get rotatedPolygon() {
158
+ const cx = (this.translateX + this.totalWidth / 2 / this.scale);
159
+ const cy = (this.translateY + this.totalHeight / 2 / this.scale);
160
+ const angle = this.rotation;
161
+ const adjustedWidth = this.totalWidth / this.scale;
162
+ const adjustedHeight = this.totalHeight / this.scale;
163
+ const corners = {
164
+ topLeft: { x: this.translateX, y: this.translateY },
165
+ topRight: { x: this.translateX + adjustedWidth, y: this.translateY },
166
+ bottomRight: { x: this.translateX + adjustedWidth, y: this.translateY + adjustedHeight },
167
+ bottomLeft: { x: this.translateX, y: this.translateY + adjustedHeight },
168
+ };
169
+ const rotatedCorners = Object.keys(corners).reduce((acc, key) => {
170
+ const corner = corners[key];
171
+ const rotatedX = Math.cos(angle) * (corner.x - cx) - Math.sin(angle) * (corner.y - cy) + cx;
172
+ const rotatedY = Math.sin(angle) * (corner.x - cx) + Math.cos(angle) * (corner.y - cy) + cy;
173
+ acc[key] = { x: rotatedX, y: rotatedY };
174
+ return acc;
175
+ }, {});
176
+ return rotatedCorners;
177
+ }
178
+ get minXRotated() {
179
+ const corners = [
180
+ this.rotatedPolygon.topLeft.x,
181
+ this.rotatedPolygon.topRight.x,
182
+ this.rotatedPolygon.bottomRight.x,
183
+ this.rotatedPolygon.bottomLeft.x,
184
+ ];
185
+ return Math.min(...corners);
186
+ }
187
+ get minYRotated() {
188
+ const corners = [
189
+ this.rotatedPolygon.topLeft.y,
190
+ this.rotatedPolygon.topRight.y,
191
+ this.rotatedPolygon.bottomRight.y,
192
+ this.rotatedPolygon.bottomLeft.y,
193
+ ];
194
+ return Math.min(...corners);
195
+ }
196
+ get maxXRotated() {
197
+ const corners = [
198
+ this.rotatedPolygon.topLeft.x,
199
+ this.rotatedPolygon.topRight.x,
200
+ this.rotatedPolygon.bottomRight.x,
201
+ this.rotatedPolygon.bottomLeft.x,
202
+ ];
203
+ return Math.max(...corners);
204
+ }
205
+ get maxYRotated() {
206
+ const corners = [
207
+ this.rotatedPolygon.topLeft.y,
208
+ this.rotatedPolygon.topRight.y,
209
+ this.rotatedPolygon.bottomRight.y,
210
+ this.rotatedPolygon.bottomLeft.y,
211
+ ];
212
+ return Math.max(...corners);
213
+ }
214
+ get transformationMatrix() {
215
+ const scale = 1 / this.scale;
216
+ const translateX = this.translateX;
217
+ const translateY = this.translateY;
218
+ return `matrix(${scale}, 0, 0, ${scale}, ${translateX}, ${translateY})`;
219
+ }
220
+ get rotationDegrees() {
221
+ return this.rotation * (180 / Math.PI);
222
+ }
223
+ get centerX() {
224
+ return this.translateX + this.totalWidth / 2;
225
+ }
226
+ get centerY() {
227
+ return this.translateY + this.totalHeight / 2;
228
+ }
229
+ constructor() {
230
+ this.__class__ = 'KritzelBaseObject';
231
+ this.visible = true;
232
+ this.borderWidth = 0;
233
+ this.opacity = 1;
234
+ this.padding = 0;
235
+ this.selected = false;
236
+ this.resizing = false;
237
+ this.rotation = 0;
238
+ this.markedForRemoval = false;
239
+ this.isMounted = false;
240
+ this.zIndex = 0;
241
+ this.debugInfoVisible = false;
242
+ this.id = this.generateId();
243
+ }
244
+ static create(store) {
245
+ const object = new KritzelBaseObject();
246
+ object._store = store;
247
+ object.zIndex = store.currentZIndex;
248
+ return object;
249
+ }
250
+ mount(element) {
251
+ if (this.isMounted) {
252
+ return;
253
+ }
254
+ this.elementRef = element;
255
+ this.isMounted = true;
256
+ }
257
+ generateId() {
258
+ return ObjectHelper.generateUUID();
259
+ }
260
+ isInViewport() {
261
+ const viewportBounds = {
262
+ x: -this._store.state.translateX / this._store.state.scale,
263
+ y: -this._store.state.translateY / this._store.state.scale,
264
+ width: this._store.state.viewportWidth / this._store.state.scale,
265
+ height: this._store.state.viewportHeight / this._store.state.scale};
266
+ return this.boundingBox.x < viewportBounds.x + viewportBounds.width &&
267
+ this.boundingBox.x + this.boundingBox.width > viewportBounds.x &&
268
+ this.boundingBox.y < viewportBounds.y + viewportBounds.height &&
269
+ this.boundingBox.y + this.boundingBox.height > viewportBounds.y;
270
+ }
271
+ centerInViewport() {
272
+ const scale = this._store.state.scale;
273
+ this.translateX = (this._store.state.viewportWidth / 2 - this.totalWidth / 2 - this._store.state.translateX) / scale;
274
+ this.translateY = (this._store.state.viewportHeight / 2 - this.totalHeight / 2 - this._store.state.translateY) / scale;
275
+ }
276
+ move(startX, startY, endX, endY) {
277
+ const deltaX = (startX - endX) / this._store.state.scale;
278
+ const deltaY = (startY - endY) / this._store.state.scale;
279
+ this.translateX += deltaX;
280
+ this.translateY += deltaY;
281
+ }
282
+ resize(x, y, width, height) {
283
+ if (width <= 1 || height <= 1) {
284
+ return;
285
+ }
286
+ this.width = width;
287
+ this.height = height;
288
+ this.translateX = x;
289
+ this.translateY = y;
290
+ }
291
+ rotate(value) {
292
+ this.rotation = value;
293
+ }
294
+ copy() {
295
+ const copiedObject = Object.create(Object.getPrototypeOf(this));
296
+ Object.assign(copiedObject, this);
297
+ copiedObject.id = this.generateId();
298
+ copiedObject.isMounted = false;
299
+ return copiedObject;
300
+ }
301
+ revive(object) {
302
+ Object.assign(this, object);
303
+ return this;
304
+ }
305
+ }
306
+
307
+ class KritzelPath extends KritzelBaseObject {
308
+ constructor() {
309
+ super(...arguments);
310
+ this.__class__ = 'KritzelPath';
311
+ this.stroke = 'none';
312
+ this.lineSlack = 0.5;
313
+ this.x = 0;
314
+ this.y = 0;
315
+ this.height = 0;
316
+ this.width = 0;
317
+ this.scale = 1;
318
+ this.visible = true;
319
+ this.debugInfoVisible = true;
320
+ }
321
+ get viewBox() {
322
+ return `${this.x} ${this.y} ${this.width} ${this.height}`;
323
+ }
324
+ static create(store, options) {
325
+ var _a, _b, _c, _d, _e, _f;
326
+ const object = new KritzelPath();
327
+ object._store = store;
328
+ object.id = object.generateId();
329
+ object.options = options;
330
+ object.points = (_a = options === null || options === void 0 ? void 0 : options.points) !== null && _a !== void 0 ? _a : [];
331
+ object.translateX = (_b = options === null || options === void 0 ? void 0 : options.translateX) !== null && _b !== void 0 ? _b : 0;
332
+ object.translateY = (_c = options === null || options === void 0 ? void 0 : options.translateY) !== null && _c !== void 0 ? _c : 0;
333
+ object.scale = (_d = options === null || options === void 0 ? void 0 : options.scale) !== null && _d !== void 0 ? _d : 1;
334
+ object.strokeWidth = (_e = options === null || options === void 0 ? void 0 : options.strokeWidth) !== null && _e !== void 0 ? _e : 8;
335
+ object.fill = (_f = options === null || options === void 0 ? void 0 : options.fill) !== null && _f !== void 0 ? _f : '#000000';
336
+ object.zIndex = store.currentZIndex;
337
+ object.d = object.generateSvgPath();
338
+ object.updateDimensions();
339
+ return object;
340
+ }
341
+ resize(x, y, width, height) {
342
+ if (width <= 1 || height <= 1) {
343
+ return;
344
+ }
345
+ const scaleX = width / this.width;
346
+ const scaleY = height / this.height;
347
+ this.width = width;
348
+ this.height = height;
349
+ this.points = this.points.map(([x, y]) => [x * scaleX, y * scaleY]);
350
+ this.d = this.generateSvgPath();
351
+ this.width = Math.max(...this.points.map(p => p[0])) - Math.min(...this.points.map(p => p[0])) + this.strokeWidth;
352
+ this.height = Math.max(...this.points.map(p => p[1])) - Math.min(...this.points.map(p => p[1])) + this.strokeWidth;
353
+ this.x = Math.min(...this.points.map(p => p[0])) - this.strokeWidth / 2;
354
+ this.y = Math.min(...this.points.map(p => p[1])) - this.strokeWidth / 2;
355
+ this.translateX = x;
356
+ this.translateY = y;
357
+ }
358
+ rotate(value) {
359
+ super.rotate(value);
360
+ this.updateDimensions();
361
+ }
362
+ updateDimensions() {
363
+ const rotatedPoints = this.points.map(([x, y]) => {
364
+ const rotatedX = x * Math.cos(this.rotation) - y * Math.sin(this.rotation);
365
+ const rotatedY = x * Math.sin(this.rotation) + y * Math.cos(this.rotation);
366
+ return [rotatedX, rotatedY];
367
+ });
368
+ const minX = Math.min(...rotatedPoints.map(p => p[0] - this.strokeWidth / 2));
369
+ const minY = Math.min(...rotatedPoints.map(p => p[1] - this.strokeWidth / 2));
370
+ const maxX = Math.max(...rotatedPoints.map(p => p[0] + this.strokeWidth / 2));
371
+ const maxY = Math.max(...rotatedPoints.map(p => p[1] + this.strokeWidth / 2));
372
+ this.width = maxX - minX + this.lineSlack; // Add 0.5 to avoid rounding issues
373
+ this.height = maxY - minY + this.lineSlack; // Add 0.5 to avoid rounding issues
374
+ this.x = minX;
375
+ this.y = minY;
376
+ this.translateX = (this.x + this.translateX) / this.scale;
377
+ this.translateY = (this.y + this.translateY) / this.scale;
378
+ }
379
+ generateSvgPath() {
380
+ const stroke = this.getStrokeFromPoints(this.points, this.strokeWidth);
381
+ return this.getSvgPathFromStroke(stroke);
382
+ }
383
+ getStrokeFromPoints(points, strokeWidth) {
384
+ return cjsExports.getStroke(points, {
385
+ size: strokeWidth,
386
+ thinning: 0.5,
387
+ smoothing: 0.5,
388
+ streamline: 0.5,
389
+ easing: t => t,
390
+ simulatePressure: true,
391
+ last: true,
392
+ start: {
393
+ cap: true,
394
+ taper: 0,
395
+ easing: t => t,
396
+ },
397
+ end: {
398
+ cap: true,
399
+ taper: 0,
400
+ easing: t => t,
401
+ },
402
+ });
403
+ }
404
+ getSvgPathFromStroke(points, closed = true) {
405
+ const len = points.length;
406
+ if (len < 4) {
407
+ return ``;
408
+ }
409
+ let a = points[0];
410
+ let b = points[1];
411
+ const c = points[2];
412
+ let result = `M${a[0].toFixed(2)},${a[1].toFixed(2)} Q${b[0].toFixed(2)},${b[1].toFixed(2)} ${KritzelMathHelper.average(b[0], c[0]).toFixed(2)},${KritzelMathHelper.average(b[1], c[1]).toFixed(2)} T`;
413
+ for (let i = 2, max = len - 1; i < max; i++) {
414
+ a = points[i];
415
+ b = points[i + 1];
416
+ result += `${KritzelMathHelper.average(a[0], b[0]).toFixed(2)},${KritzelMathHelper.average(a[1], b[1]).toFixed(2)} `;
417
+ }
418
+ if (closed) {
419
+ result += 'Z';
420
+ }
421
+ return result;
422
+ }
423
+ }
424
+
425
+ class KritzelBaseTool {
426
+ constructor(store) {
427
+ this.__class__ = this.constructor.name;
428
+ this.name = 'base-tool';
429
+ this._store = store;
430
+ }
431
+ onActivate() {
432
+ // default implementation
433
+ }
434
+ onDeactivate() {
435
+ // default implementation
436
+ }
437
+ handleMouseDown(_event) {
438
+ // default implementation
439
+ }
440
+ handleMouseMove(_event) {
441
+ // default implementation
442
+ }
443
+ handleMouseUp(_event) {
444
+ // default implementation
445
+ }
446
+ handleDoubleClick(_event) {
447
+ // default implementation
448
+ }
449
+ handleDoubleTap(_event) {
450
+ // default implementation
451
+ }
452
+ handleTouchStart(_event) {
453
+ // default implementation
454
+ }
455
+ handleTouchMove(_event) {
456
+ // default implementation
457
+ }
458
+ handleTouchEnd(_event) {
459
+ // default implementation
460
+ }
461
+ handleWheel(_event) {
462
+ // default implementation
463
+ }
464
+ revive(object) {
465
+ Object.assign(this, object);
466
+ return this;
467
+ }
468
+ }
469
+
470
+ class KritzelBrushTool extends KritzelBaseTool {
471
+ constructor(store) {
472
+ super(store);
473
+ this.type = 'pen';
474
+ this.color = '#000000';
475
+ this.size = 6;
476
+ this.palettes = {
477
+ pen: ['#000000', '#FFFFFF', '#FF0000', '#00FF00', '#0000FF', '#FFFF00', '#FF00FF', '#00FFFF', '#808080', '#C0C0C0', '#800000', '#008000', '#000080', '#808000', '#800080'],
478
+ highlighter: ['#ffff00', '#ffb347', '#b4ffb4'],
479
+ };
480
+ }
481
+ handleMouseDown(event) {
482
+ if (KritzelEventHelper.isLeftClick(event)) {
483
+ this._store.state.isDrawing = true;
484
+ const x = event.clientX - this._store.offsetX;
485
+ const y = event.clientY - this._store.offsetY;
486
+ this._store.state.currentPath = KritzelPath.create(this._store, {
487
+ points: [[x, y]],
488
+ translateX: -this._store.state.translateX,
489
+ translateY: -this._store.state.translateY,
490
+ scale: this._store.state.scale,
491
+ fill: this.color,
492
+ strokeWidth: this.size,
493
+ });
494
+ }
495
+ }
496
+ handleMouseMove(event) {
497
+ if (this._store.state.isDrawing) {
498
+ const x = event.clientX - this._store.offsetX;
499
+ const y = event.clientY - this._store.offsetY;
500
+ this._store.state.currentPath = KritzelPath.create(this._store, {
501
+ points: [...this._store.state.currentPath.points, [x, y]],
502
+ translateX: -this._store.state.translateX,
503
+ translateY: -this._store.state.translateY,
504
+ scale: this._store.state.scale,
505
+ fill: this.color,
506
+ strokeWidth: this.size,
507
+ });
508
+ this._store.rerender();
509
+ }
510
+ }
511
+ handleMouseUp(_event) {
512
+ if (this._store.state.isDrawing) {
513
+ this._store.state.isDrawing = false;
514
+ if (this._store.state.currentPath) {
515
+ this._store.state.currentPath.zIndex = this._store.currentZIndex;
516
+ this._store.history.executeCommand(new AddObjectCommand(this._store, this, this._store.state.currentPath));
517
+ }
518
+ this._store.state.currentPath = undefined;
519
+ }
520
+ }
521
+ handleTouchStart(event) {
522
+ if (this._store.state.touchCount === 1) {
523
+ const x = Math.round(event.touches[0].clientX - this._store.offsetX);
524
+ const y = Math.round(event.touches[0].clientY - this._store.offsetY);
525
+ this._store.state.isDrawing = true;
526
+ this._store.state.currentPath = KritzelPath.create(this._store, {
527
+ points: [[x, y]],
528
+ translateX: -this._store.state.translateX,
529
+ translateY: -this._store.state.translateY,
530
+ scale: this._store.state.scale,
531
+ fill: this.color,
532
+ strokeWidth: this.size,
533
+ });
534
+ this._store.rerender();
535
+ }
536
+ }
537
+ handleTouchMove(event) {
538
+ if (this._store.state.touchCount === 1) {
539
+ const x = Math.round(event.touches[0].clientX - this._store.offsetX);
540
+ const y = Math.round(event.touches[0].clientY - this._store.offsetY);
541
+ this._store.state.currentPath = KritzelPath.create(this._store, {
542
+ points: [...this._store.state.currentPath.points, [x, y]],
543
+ translateX: -this._store.state.translateX,
544
+ translateY: -this._store.state.translateY,
545
+ scale: this._store.state.scale,
546
+ fill: this.color,
547
+ strokeWidth: this.size,
548
+ });
549
+ this._store.rerender();
550
+ }
551
+ }
552
+ handleTouchEnd(_event) {
553
+ if (this._store.state.isDrawing) {
554
+ this._store.state.isDrawing = false;
555
+ if (this._store.state.currentPath) {
556
+ this._store.state.currentPath.zIndex = this._store.currentZIndex;
557
+ this._store.history.executeCommand(new AddObjectCommand(this._store, this, this._store.state.currentPath));
558
+ }
559
+ this._store.state.currentPath = undefined;
560
+ this._store.rerender();
561
+ }
562
+ }
563
+ }
564
+
565
+ class KritzelText extends KritzelBaseObject {
566
+ get isReadonly() {
567
+ return !(this._store.state.activeTool instanceof KritzelTextTool);
568
+ }
569
+ constructor(config) {
570
+ super();
571
+ this.__class__ = 'KritzelText';
572
+ this.value = '';
573
+ this.fontFamily = 'Arial';
574
+ this.fontSize = 8;
575
+ this.fontColor = '#000000';
576
+ this.initialWidth = 3;
577
+ this.isNew = true;
578
+ this.debugInfoVisible = true;
579
+ this.rows = 1;
580
+ if (config) {
581
+ this.value = config.value || ' ';
582
+ this.translateX = config.translateX || 0;
583
+ this.translateY = config.translateY || 0;
584
+ this.fontSize = config.fontSize || 8;
585
+ this.fontFamily = config.fontFamily || 'Arial';
586
+ this.fontColor = config.fontColor || '#000000';
587
+ this.height = config.height || (this.fontSize * 1.2);
588
+ this.width = config.width || 0;
589
+ this.scale = config.scale || 1;
590
+ }
591
+ }
592
+ static create(store, fontSize, fontFamily) {
593
+ const object = new KritzelText();
594
+ object._store = store;
595
+ object.fontSize = fontSize;
596
+ object.fontFamily = fontFamily;
597
+ object.translateX = 0;
598
+ object.translateY = 0;
599
+ object.width = object.initialWidth / (object._store.state.scale < 0 ? object._store.state.scale : 1);
600
+ object.height = (object.fontSize * 1.2) / (object._store.state.scale < 0 ? object._store.state.scale : 1);
601
+ object.padding = 5;
602
+ object.backgroundColor = 'transparent';
603
+ object.scale = object._store.state.scale;
604
+ object.value = ' ';
605
+ object.zIndex = store.currentZIndex;
606
+ return object;
607
+ }
608
+ mount(element) {
609
+ if ((this.isMounted && this.elementRef === element) || this.isInViewport() === false) {
610
+ return;
611
+ }
612
+ this.elementRef = element;
613
+ this.isMounted = true;
614
+ }
615
+ resize(x, y, width, height) {
616
+ if (width <= 1 || height <= 1) {
617
+ return;
618
+ }
619
+ const scaleFactor = height / this.height;
620
+ this.fontSize = this.fontSize * scaleFactor;
621
+ this.width = this.width * scaleFactor;
622
+ this.height = height;
623
+ this.translateX = x;
624
+ this.translateY = y;
625
+ }
626
+ handleKeyDown(event) {
627
+ if (this.isReadonly) {
628
+ event.preventDefault();
629
+ event.stopPropagation();
630
+ }
631
+ }
632
+ handleInput(event) {
633
+ const target = event.target;
634
+ if (target.value === '') {
635
+ this.value = ' ';
636
+ target.value = ' ';
637
+ target.selectionStart = target.selectionEnd = target.value.length;
638
+ }
639
+ else {
640
+ this.value = target.value.trim();
641
+ }
642
+ this.adjustTextareaSize();
643
+ }
644
+ adjustTextareaSize() {
645
+ if (this.elementRef) {
646
+ const span = document.createElement('span');
647
+ span.style.position = 'absolute';
648
+ span.style.whiteSpace = 'pre-wrap';
649
+ span.style.visibility = 'hidden';
650
+ span.style.fontSize = window.getComputedStyle(this.elementRef).fontSize;
651
+ span.style.fontFamily = window.getComputedStyle(this.elementRef).fontFamily;
652
+ span.innerHTML = this.elementRef.value.replace(/&/g, '&amp;').replace(/</g, '&lt;').replace(/>/g, '&gt;').replace(/\n/g, '<br>') + '<br>';
653
+ document.body.appendChild(span);
654
+ const textWidth = span.offsetWidth;
655
+ const textHeight = span.offsetHeight;
656
+ document.body.removeChild(span);
657
+ this.width = textWidth;
658
+ this.height = textHeight;
659
+ this._store.rerender();
660
+ }
661
+ }
662
+ focus() {
663
+ if (this.elementRef) {
664
+ this.elementRef.focus();
665
+ }
666
+ }
667
+ selectAll() {
668
+ if (this.elementRef) {
669
+ this.elementRef.select();
670
+ }
671
+ }
672
+ insertFromClipboard() {
673
+ if (this.elementRef) {
674
+ this.elementRef.focus();
675
+ try {
676
+ navigator.clipboard.readText().then(text => {
677
+ const start = this.elementRef.selectionStart;
678
+ const end = this.elementRef.selectionEnd;
679
+ const value = this.elementRef.value;
680
+ this.elementRef.value = value.substring(0, start) + text + value.substring(end);
681
+ this.elementRef.selectionStart = this.elementRef.selectionEnd = start + text.length;
682
+ this.value = this.elementRef.value;
683
+ this.adjustTextareaSize();
684
+ });
685
+ }
686
+ catch (err) {
687
+ console.error('Failed to read clipboard contents:', err);
688
+ }
689
+ }
690
+ }
691
+ }
692
+
693
+ class KritzelToolRegistry {
694
+ static registerTool(toolName, constructor, store) {
695
+ const toolInstance = new constructor(store);
696
+ toolInstance.name = toolName;
697
+ this.registry[toolName] = toolInstance;
698
+ return toolInstance;
699
+ }
700
+ static getTool(toolName) {
701
+ const toolInstance = this.registry[toolName];
702
+ if (!toolInstance) {
703
+ console.warn(`Unknown tool: ${toolName}`);
704
+ return null;
705
+ }
706
+ return toolInstance;
707
+ }
708
+ }
709
+ KritzelToolRegistry.registry = {};
710
+
711
+ class KritzelTextTool extends KritzelBaseTool {
712
+ constructor(store) {
713
+ super(store);
714
+ this.fontFamily = 'Arial';
715
+ this.fontSize = 16;
716
+ this.fontColor = '#000000';
717
+ this.palette = [
718
+ '#000000',
719
+ '#FFFFFF',
720
+ '#FF0000',
721
+ '#00FF00',
722
+ '#0000FF',
723
+ '#FFFF00',
724
+ '#FF00FF',
725
+ '#00FFFF',
726
+ '#808080',
727
+ '#C0C0C0',
728
+ '#800000',
729
+ '#008000',
730
+ '#000080',
731
+ '#808000',
732
+ '#800080',
733
+ ];
734
+ }
735
+ handleMouseDown(event) {
736
+ const path = event.composedPath().slice(1);
737
+ const objectElement = path.find(element => element.classList && element.classList.contains('object'));
738
+ const object = this._store.findObjectById(objectElement === null || objectElement === void 0 ? void 0 : objectElement.id);
739
+ if (this._store.state.activeText === null && object && object instanceof KritzelText) {
740
+ this._store.state.activeText = object;
741
+ object.focus();
742
+ return;
743
+ }
744
+ if (this._store.state.activeText !== null && object instanceof KritzelText) {
745
+ object.focus();
746
+ return;
747
+ }
748
+ if (this._store.state.activeText !== null) {
749
+ this._store.resetActiveText();
750
+ this._store.setState('activeTool', KritzelToolRegistry.getTool('selection'));
751
+ return;
752
+ }
753
+ if (KritzelEventHelper.isLeftClick(event) === false) {
754
+ return;
755
+ }
756
+ const clientX = event.clientX - this._store.offsetX;
757
+ const clientY = event.clientY - this._store.offsetY;
758
+ const text = KritzelText.create(this._store, this.fontSize, this.fontFamily);
759
+ text.fontColor = this.fontColor;
760
+ text.translateX = (clientX - this._store.state.translateX) / this._store.state.scale;
761
+ text.translateY = (clientY - this._store.state.translateY) / this._store.state.scale;
762
+ text.zIndex = this._store.currentZIndex;
763
+ text.adjustTextareaSize();
764
+ this._store.state.activeText = text;
765
+ this._store.history.executeCommand(new AddObjectCommand(this._store, this, text));
766
+ }
767
+ handleMouseUp(_event) {
768
+ var _a, _b;
769
+ (_a = this._store.state.activeText) === null || _a === void 0 ? void 0 : _a.focus();
770
+ (_b = this._store.state.activeText) === null || _b === void 0 ? void 0 : _b.adjustTextareaSize();
771
+ }
772
+ handleTouchStart(event) {
773
+ const path = event.composedPath().slice(1);
774
+ const objectElement = path.find(element => element.classList && element.classList.contains('object'));
775
+ const object = this._store.findObjectById(objectElement === null || objectElement === void 0 ? void 0 : objectElement.id);
776
+ if (this._store.state.activeText === null && object && object instanceof KritzelText) {
777
+ this._store.state.activeText = object;
778
+ object.focus();
779
+ return;
780
+ }
781
+ if (this._store.state.activeText !== null && object instanceof KritzelText) {
782
+ object.focus();
783
+ return;
784
+ }
785
+ if (this._store.state.activeText !== null) {
786
+ this._store.resetActiveText();
787
+ this._store.setState('activeTool', KritzelToolRegistry.getTool('selection'));
788
+ return;
789
+ }
790
+ if (this._store.state.touchCount > 1) {
791
+ return;
792
+ }
793
+ const clientX = Math.round(event.touches[0].clientX - this._store.offsetX);
794
+ const clientY = Math.round(event.touches[0].clientY - this._store.offsetY);
795
+ const text = KritzelText.create(this._store, this.fontSize, this.fontFamily);
796
+ text.fontColor = this.fontColor;
797
+ text.translateX = (clientX - this._store.state.translateX) / this._store.state.scale;
798
+ text.translateY = (clientY - this._store.state.translateY) / this._store.state.scale;
799
+ text.zIndex = this._store.currentZIndex;
800
+ this._store.state.activeText = text;
801
+ this._store.history.executeCommand(new AddObjectCommand(this._store, this, text));
802
+ }
803
+ handleTouchEnd(_event) {
804
+ var _a, _b;
805
+ (_a = this._store.state.activeText) === null || _a === void 0 ? void 0 : _a.focus();
806
+ (_b = this._store.state.activeText) === null || _b === void 0 ? void 0 : _b.adjustTextareaSize();
807
+ }
808
+ }
809
+
810
+ export { AddObjectCommand as A, KritzelBrushTool as K, ObjectHelper as O, KritzelTextTool as a, KritzelText as b, KritzelBaseCommand as c, KritzelBaseTool as d, KritzelEventHelper as e, KritzelBaseObject as f, KritzelToolRegistry as g, KritzelPath as h };
811
+ //# sourceMappingURL=p-BcQCX1Z6.js.map
812
+
813
+ //# sourceMappingURL=p-BcQCX1Z6.js.map