kritzel-stencil 0.0.140 → 0.0.141

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 (169) hide show
  1. package/dist/cjs/index-BKstgWru.js +16981 -0
  2. package/dist/cjs/index-BKstgWru.js.map +1 -0
  3. package/dist/cjs/{index-nzUNdMPh.js → index-DcTwXs_q.js} +47 -22
  4. package/dist/cjs/index-DcTwXs_q.js.map +1 -0
  5. package/dist/cjs/index.cjs.js +1 -1
  6. package/dist/cjs/kritzel-brush-style.cjs.entry.js +1 -1
  7. package/dist/cjs/kritzel-color_22.cjs.entry.js +29 -28
  8. package/dist/cjs/loader.cjs.js +2 -2
  9. package/dist/cjs/stencil.cjs.js +3 -3
  10. package/dist/cjs/stencil.cjs.js.map +1 -1
  11. package/dist/collection/classes/core/core.class.js +9 -2
  12. package/dist/collection/classes/core/core.class.js.map +1 -1
  13. package/dist/collection/classes/handlers/key.handler.js +2 -2
  14. package/dist/collection/classes/handlers/key.handler.js.map +1 -1
  15. package/dist/collection/classes/objects/text.class.js +123 -76
  16. package/dist/collection/classes/objects/text.class.js.map +1 -1
  17. package/dist/collection/classes/tools/text-tool.class.js +2 -4
  18. package/dist/collection/classes/tools/text-tool.class.js.map +1 -1
  19. package/dist/collection/collection-manifest.json +2 -2
  20. package/dist/collection/components/core/kritzel-cursor-trail/kritzel-cursor-trail.js +0 -1
  21. package/dist/collection/components/core/kritzel-cursor-trail/kritzel-cursor-trail.js.map +1 -1
  22. package/dist/collection/components/core/kritzel-editor/kritzel-editor.js +4 -8
  23. package/dist/collection/components/core/kritzel-editor/kritzel-editor.js.map +1 -1
  24. package/dist/collection/components/core/kritzel-engine/kritzel-engine.css +21 -8
  25. package/dist/collection/components/core/kritzel-engine/kritzel-engine.js +17 -27
  26. package/dist/collection/components/core/kritzel-engine/kritzel-engine.js.map +1 -1
  27. package/dist/collection/components/shared/kritzel-brush-style/kritzel-brush-style.js +1 -2
  28. package/dist/collection/components/shared/kritzel-brush-style/kritzel-brush-style.js.map +1 -1
  29. package/dist/collection/components/shared/kritzel-color/kritzel-color.js +3 -3
  30. package/dist/collection/components/shared/kritzel-color-palette/kritzel-color-palette.js +3 -4
  31. package/dist/collection/components/shared/kritzel-color-palette/kritzel-color-palette.js.map +1 -1
  32. package/dist/collection/components/shared/kritzel-dropdown/kritzel-dropdown.js +5 -6
  33. package/dist/collection/components/shared/kritzel-dropdown/kritzel-dropdown.js.map +1 -1
  34. package/dist/collection/components/shared/kritzel-font/kritzel-font.js +3 -3
  35. package/dist/collection/components/shared/kritzel-font-family/kritzel-font-family.js +2 -3
  36. package/dist/collection/components/shared/kritzel-font-family/kritzel-font-family.js.map +1 -1
  37. package/dist/collection/components/shared/kritzel-font-size/kritzel-font-size.js +2 -3
  38. package/dist/collection/components/shared/kritzel-font-size/kritzel-font-size.js.map +1 -1
  39. package/dist/collection/components/shared/kritzel-icon/kritzel-icon.js +5 -5
  40. package/dist/collection/components/shared/kritzel-menu/kritzel-menu.js +0 -2
  41. package/dist/collection/components/shared/kritzel-menu/kritzel-menu.js.map +1 -1
  42. package/dist/collection/components/shared/kritzel-menu-item/kritzel-menu-item.js +0 -2
  43. package/dist/collection/components/shared/kritzel-menu-item/kritzel-menu-item.js.map +1 -1
  44. package/dist/collection/components/shared/kritzel-portal/kritzel-portal.js +5 -6
  45. package/dist/collection/components/shared/kritzel-portal/kritzel-portal.js.map +1 -1
  46. package/dist/collection/components/shared/kritzel-split-button/kritzel-split-button.js +4 -5
  47. package/dist/collection/components/shared/kritzel-split-button/kritzel-split-button.js.map +1 -1
  48. package/dist/collection/components/shared/kritzel-stroke-size/kritzel-stroke-size.js +1 -2
  49. package/dist/collection/components/shared/kritzel-stroke-size/kritzel-stroke-size.js.map +1 -1
  50. package/dist/collection/components/shared/kritzel-tooltip/kritzel-tooltip.js +3 -4
  51. package/dist/collection/components/shared/kritzel-tooltip/kritzel-tooltip.js.map +1 -1
  52. package/dist/collection/components/ui/kritzel-context-menu/kritzel-context-menu.js +0 -2
  53. package/dist/collection/components/ui/kritzel-context-menu/kritzel-context-menu.js.map +1 -1
  54. package/dist/collection/components/ui/kritzel-control-brush-config/kritzel-control-brush-config.js +1 -2
  55. package/dist/collection/components/ui/kritzel-control-brush-config/kritzel-control-brush-config.js.map +1 -1
  56. package/dist/collection/components/ui/kritzel-control-text-config/kritzel-control-text-config.js +1 -2
  57. package/dist/collection/components/ui/kritzel-control-text-config/kritzel-control-text-config.js.map +1 -1
  58. package/dist/collection/components/ui/kritzel-controls/kritzel-controls.js +1 -3
  59. package/dist/collection/components/ui/kritzel-controls/kritzel-controls.js.map +1 -1
  60. package/dist/collection/components/ui/kritzel-workspace-manager/kritzel-workspace-manager.js +0 -2
  61. package/dist/collection/components/ui/kritzel-workspace-manager/kritzel-workspace-manager.js.map +1 -1
  62. package/dist/components/index.js +3 -3
  63. package/dist/components/kritzel-brush-style.js +4 -4
  64. package/dist/components/kritzel-color-palette.js +1 -1
  65. package/dist/components/kritzel-color.js +1 -1
  66. package/dist/components/kritzel-context-menu.js +1 -1
  67. package/dist/components/kritzel-control-brush-config.js +1 -1
  68. package/dist/components/kritzel-control-text-config.js +1 -1
  69. package/dist/components/kritzel-controls.js +1 -1
  70. package/dist/components/kritzel-cursor-trail.js +1 -1
  71. package/dist/components/kritzel-dropdown.js +1 -1
  72. package/dist/components/kritzel-editor.js +25 -25
  73. package/dist/components/kritzel-engine.js +1 -1
  74. package/dist/components/kritzel-font-family.js +1 -1
  75. package/dist/components/kritzel-font-size.js +1 -1
  76. package/dist/components/kritzel-font.js +1 -1
  77. package/dist/components/kritzel-icon.js +1 -1
  78. package/dist/components/kritzel-menu-item.js +1 -1
  79. package/dist/components/kritzel-menu.js +1 -1
  80. package/dist/components/kritzel-portal.js +1 -1
  81. package/dist/components/kritzel-split-button.js +1 -1
  82. package/dist/components/kritzel-stroke-size.js +1 -1
  83. package/dist/components/kritzel-tooltip.js +1 -1
  84. package/dist/components/kritzel-utility-panel.js +1 -1
  85. package/dist/components/kritzel-workspace-manager.js +1 -1
  86. package/dist/components/{p-BQJhnpY3.js → p-BEKicPnH.js} +3 -3
  87. package/dist/components/{p-BQJhnpY3.js.map → p-BEKicPnH.js.map} +1 -1
  88. package/dist/components/{p-D6FeQRzi.js → p-BFNwskCY.js} +4 -4
  89. package/dist/components/{p-D6FeQRzi.js.map → p-BFNwskCY.js.map} +1 -1
  90. package/dist/components/{p-sHDCqDbD.js → p-BJbN3vca.js} +6 -6
  91. package/dist/components/{p-sHDCqDbD.js.map → p-BJbN3vca.js.map} +1 -1
  92. package/dist/components/p-BuDVaqTF.js +15302 -0
  93. package/dist/components/p-BuDVaqTF.js.map +1 -0
  94. package/dist/components/{p-bC64Ng59.js → p-ByAzDzS5.js} +3 -3
  95. package/dist/components/{p-bC64Ng59.js.map → p-ByAzDzS5.js.map} +1 -1
  96. package/dist/components/{p-CE_sOMS2.js → p-BycHaC-9.js} +4 -4
  97. package/dist/components/{p-CE_sOMS2.js.map → p-BycHaC-9.js.map} +1 -1
  98. package/dist/components/{p-BV5iL9W6.js → p-C4nj29RW.js} +37 -36
  99. package/dist/components/p-C4nj29RW.js.map +1 -0
  100. package/dist/components/{p-BYanlgdq.js → p-C9hrbrUN.js} +27 -14
  101. package/dist/components/p-C9hrbrUN.js.map +1 -0
  102. package/dist/components/{p-JYqCBcMd.js → p-CEn1WeG3.js} +8 -8
  103. package/dist/components/{p-JYqCBcMd.js.map → p-CEn1WeG3.js.map} +1 -1
  104. package/dist/components/{p-C7UWRUAy.js → p-CGb-8cK4.js} +3 -3
  105. package/dist/components/{p-C7UWRUAy.js.map → p-CGb-8cK4.js.map} +1 -1
  106. package/dist/components/{p-BJZudenH.js → p-C_hSH2nN.js} +3 -3
  107. package/dist/components/{p-BJZudenH.js.map → p-C_hSH2nN.js.map} +1 -1
  108. package/dist/components/{p-SKH0G2nM.js → p-ChLi4Ufe.js} +17 -17
  109. package/dist/components/{p-SKH0G2nM.js.map → p-ChLi4Ufe.js.map} +1 -1
  110. package/dist/components/{p-D2eJXNMx.js → p-CieOx1XL.js} +4 -4
  111. package/dist/components/{p-D2eJXNMx.js.map → p-CieOx1XL.js.map} +1 -1
  112. package/dist/components/{p-BFLXutiB.js → p-Co5lU_7h.js} +10 -10
  113. package/dist/components/{p-BFLXutiB.js.map → p-Co5lU_7h.js.map} +1 -1
  114. package/dist/components/{p-sq9jgfX0.js → p-D27d2rKT.js} +3 -3
  115. package/dist/components/{p-sq9jgfX0.js.map → p-D27d2rKT.js.map} +1 -1
  116. package/dist/components/{p-DFO-6kuA.js → p-DPxzgBs0.js} +3 -3
  117. package/dist/components/{p-DFO-6kuA.js.map → p-DPxzgBs0.js.map} +1 -1
  118. package/dist/components/{p-vNnVlsJt.js → p-D_RcVGj0.js} +4 -4
  119. package/dist/components/{p-vNnVlsJt.js.map → p-D_RcVGj0.js.map} +1 -1
  120. package/dist/components/{p-C-ozL_Es.js → p-DqsgZIHC.js} +4 -4
  121. package/dist/components/{p-C-ozL_Es.js.map → p-DqsgZIHC.js.map} +1 -1
  122. package/dist/components/{p-Dh61W3GT.js → p-DzyZA2GT.js} +5 -5
  123. package/dist/components/{p-Dh61W3GT.js.map → p-DzyZA2GT.js.map} +1 -1
  124. package/dist/components/{p-DbmQ5DrU.js → p-dcR2uxM3.js} +5 -5
  125. package/dist/components/{p-DbmQ5DrU.js.map → p-dcR2uxM3.js.map} +1 -1
  126. package/dist/components/{p-BLc8TzcU.js → p-fiFoOjv0.js} +7 -7
  127. package/dist/components/{p-BLc8TzcU.js.map → p-fiFoOjv0.js.map} +1 -1
  128. package/dist/components/{p-IgPm36bH.js → p-gCHmJzc2.js} +4 -4
  129. package/dist/components/{p-IgPm36bH.js.map → p-gCHmJzc2.js.map} +1 -1
  130. package/dist/esm/{index-oCOlsFCN.js → index-Cw77zP6g.js} +47 -22
  131. package/dist/esm/index-Cw77zP6g.js.map +1 -0
  132. package/dist/esm/index-D0Q2MKPn.js +16953 -0
  133. package/dist/esm/index-D0Q2MKPn.js.map +1 -0
  134. package/dist/esm/index.js +1 -1
  135. package/dist/esm/kritzel-brush-style.entry.js +1 -1
  136. package/dist/esm/kritzel-color_22.entry.js +29 -28
  137. package/dist/esm/loader.js +3 -3
  138. package/dist/esm/stencil.js +4 -4
  139. package/dist/esm/stencil.js.map +1 -1
  140. package/dist/stencil/index.esm.js +1 -1
  141. package/dist/stencil/p-73784709.entry.js +2 -0
  142. package/dist/stencil/p-73784709.entry.js.map +1 -0
  143. package/dist/stencil/{p-25d1e040.entry.js → p-8b831c94.entry.js} +2 -2
  144. package/dist/stencil/p-Cw77zP6g.js +3 -0
  145. package/dist/stencil/p-Cw77zP6g.js.map +1 -0
  146. package/dist/stencil/p-D0Q2MKPn.js +2 -0
  147. package/dist/stencil/p-D0Q2MKPn.js.map +1 -0
  148. package/dist/stencil/stencil.esm.js +1 -1
  149. package/dist/stencil/stencil.esm.js.map +1 -1
  150. package/dist/types/classes/objects/text.class.d.ts +20 -10
  151. package/dist/types/stencil-public-runtime.d.ts +36 -12
  152. package/package.json +7 -2
  153. package/dist/cjs/index-Clh2g9JM.js +0 -2850
  154. package/dist/cjs/index-Clh2g9JM.js.map +0 -1
  155. package/dist/cjs/index-nzUNdMPh.js.map +0 -1
  156. package/dist/components/p-BV5iL9W6.js.map +0 -1
  157. package/dist/components/p-BYanlgdq.js.map +0 -1
  158. package/dist/components/p-C5sTCwe3.js +0 -1171
  159. package/dist/components/p-C5sTCwe3.js.map +0 -1
  160. package/dist/esm/index-BAbkwyRx.js +0 -2822
  161. package/dist/esm/index-BAbkwyRx.js.map +0 -1
  162. package/dist/esm/index-oCOlsFCN.js.map +0 -1
  163. package/dist/stencil/p-BAbkwyRx.js +0 -2
  164. package/dist/stencil/p-BAbkwyRx.js.map +0 -1
  165. package/dist/stencil/p-fe465059.entry.js +0 -2
  166. package/dist/stencil/p-fe465059.entry.js.map +0 -1
  167. package/dist/stencil/p-oCOlsFCN.js +0 -3
  168. package/dist/stencil/p-oCOlsFCN.js.map +0 -1
  169. /package/dist/stencil/{p-25d1e040.entry.js.map → p-8b831c94.entry.js.map} +0 -0
@@ -1,2822 +0,0 @@
1
- class KritzelBaseCommand {
2
- _core;
3
- initiator;
4
- skipHistory;
5
- constructor(core, initiator, skipHistory = false) {
6
- this._core = core;
7
- this.initiator = initiator?.constructor?.name ?? 'Unknown';
8
- this.skipHistory = skipHistory;
9
- }
10
- execute() {
11
- throw new Error('Method not implemented.');
12
- }
13
- undo() {
14
- throw new Error('Method not implemented.');
15
- }
16
- }
17
-
18
- class UpdateObjectCommand extends KritzelBaseCommand {
19
- object;
20
- updatedProperties;
21
- previousProperties;
22
- constructor(core, initiator, object, updatedProperties, skipHistory = false) {
23
- super(core, initiator, skipHistory);
24
- this.object = object;
25
- this.updatedProperties = updatedProperties;
26
- this.previousProperties = {};
27
- for (const key in updatedProperties) {
28
- if (updatedProperties.hasOwnProperty(key)) {
29
- this.previousProperties[key] = this.object[key];
30
- }
31
- }
32
- }
33
- execute() {
34
- for (const key in this.updatedProperties) {
35
- if (this.updatedProperties.hasOwnProperty(key)) {
36
- this.object[key] = this.updatedProperties[key];
37
- }
38
- }
39
- this._core.store.state.objectsMap.update(this.object);
40
- this._core.updateObjectInDatabase(this.object);
41
- }
42
- undo() {
43
- for (const key in this.previousProperties) {
44
- if (this.previousProperties.hasOwnProperty(key)) {
45
- this.object[key] = this.previousProperties[key];
46
- }
47
- }
48
- this._core.store.state.objectsMap.update(this.object);
49
- this._core.updateObjectInDatabase(this.object);
50
- }
51
- }
52
-
53
- class KritzelToolRegistry {
54
- static registry = {};
55
- static registerTool(toolName, constructor, core) {
56
- const toolInstance = new constructor(core);
57
- toolInstance.name = toolName;
58
- this.registry[toolName] = toolInstance;
59
- return toolInstance;
60
- }
61
- static getTool(toolName) {
62
- const toolInstance = this.registry[toolName];
63
- if (!toolInstance) {
64
- console.warn(`Unknown tool: ${toolName}`);
65
- return null;
66
- }
67
- return toolInstance;
68
- }
69
- }
70
-
71
- class KritzelBaseTool {
72
- __class__ = this.constructor.name;
73
- name = 'base-tool';
74
- _core;
75
- constructor(core) {
76
- this._core = core;
77
- }
78
- onActivate() {
79
- // default implementation
80
- }
81
- onDeactivate() {
82
- // default implementation
83
- }
84
- handlePointerDown(_event) {
85
- // default implementation
86
- }
87
- handlePointerMove(_event) {
88
- // default implementation
89
- }
90
- handlePointerUp(_event) {
91
- // default implementation
92
- }
93
- handleWheel(_event) {
94
- // default implementation
95
- }
96
- serialize() {
97
- return {
98
- __class__: this.__class__,
99
- name: this.name,
100
- };
101
- }
102
- deserialize(object) {
103
- Object.assign(this, object);
104
- return this;
105
- }
106
- }
107
-
108
- class AddObjectCommand extends KritzelBaseCommand {
109
- object;
110
- constructor(core, initiator, object, skipHistory = false) {
111
- super(core, initiator, skipHistory);
112
- this.object = object;
113
- }
114
- execute() {
115
- this._core.store.state.objectsMap.insert(this.object);
116
- this._core.addObjectToDatabase(this.object);
117
- }
118
- undo() {
119
- this._core.store.state.objectsMap.remove(object => object.id === this.object.id);
120
- this._core.deleteObjectFromDatabase(this.object.id);
121
- }
122
- }
123
-
124
- var KritzelMouseButton;
125
- (function (KritzelMouseButton) {
126
- KritzelMouseButton[KritzelMouseButton["Left"] = 0] = "Left";
127
- KritzelMouseButton[KritzelMouseButton["Middle"] = 1] = "Middle";
128
- KritzelMouseButton[KritzelMouseButton["Right"] = 2] = "Right";
129
- })(KritzelMouseButton || (KritzelMouseButton = {}));
130
-
131
- class KritzelEventHelper {
132
- static isRightClick(ev) {
133
- return ev.button === KritzelMouseButton.Right;
134
- }
135
- static isLeftClick(ev) {
136
- return ev.button === KritzelMouseButton.Left;
137
- }
138
- static isMainMouseWheel(event) {
139
- return Math.abs(event.deltaY) > 0 && Math.abs(event.deltaX) === 0 && Number.isInteger(event.deltaY);
140
- }
141
- static isPointerEventOnContextMenu(event) {
142
- const path = event.composedPath();
143
- const contextMenu = path.find(element => element.classList && element.classList.contains('context-menu'));
144
- return !!contextMenu;
145
- }
146
- static onLongPress(event, onSuccess, onCancel) {
147
- const longPressTimeout = 400;
148
- const moveThreshold = 10;
149
- const startX = event.clientX;
150
- const startY = event.clientY;
151
- const target = event.target;
152
- const timer = setTimeout(() => {
153
- removeListeners();
154
- onSuccess(event);
155
- }, longPressTimeout);
156
- const cancel = () => {
157
- clearTimeout(timer);
158
- removeListeners();
159
- onCancel?.();
160
- };
161
- const onPointerMove = (e) => {
162
- if (Math.abs(e.clientX - startX) > moveThreshold || Math.abs(e.clientY - startY) > moveThreshold) {
163
- cancel();
164
- }
165
- };
166
- const onPointerUp = () => {
167
- cancel();
168
- };
169
- const onPointerCancel = () => {
170
- cancel();
171
- };
172
- const removeListeners = () => {
173
- target.removeEventListener('pointermove', onPointerMove);
174
- target.removeEventListener('pointerup', onPointerUp);
175
- target.removeEventListener('pointercancel', onPointerCancel);
176
- };
177
- target.addEventListener('pointermove', onPointerMove, { passive: true });
178
- target.addEventListener('pointerup', onPointerUp, { once: true });
179
- target.addEventListener('pointercancel', onPointerCancel, { once: true });
180
- return cancel;
181
- }
182
- }
183
-
184
- class KritzelKeyboardHelper {
185
- static forceHideKeyboard() {
186
- if (document.activeElement instanceof HTMLElement) {
187
- document.activeElement.blur();
188
- }
189
- }
190
- static enableInteractiveWidget() {
191
- const meta = document.querySelector('meta[name="viewport"][content*="interactive-widget=resizes-content"]');
192
- if (meta) {
193
- let currentContent = meta.getAttribute('content');
194
- if (!currentContent.includes('interactive-widget=resizes-content')) {
195
- currentContent += ', interactive-widget=resizes-content';
196
- }
197
- meta.setAttribute('content', currentContent);
198
- }
199
- }
200
- static disableInteractiveWidget() {
201
- const meta = document.querySelector('meta[name="viewport"][content*="interactive-widget=resizes-content"]');
202
- if (meta) {
203
- let currentContent = meta.getAttribute('content');
204
- let newContent = currentContent.replace(/\s*interactive-widget=resizes-content\s*[,;]?/g, '');
205
- newContent = newContent
206
- .replace(/,(\s*,)+/g, ',')
207
- .replace(/^,/, '')
208
- .replace(/,$/, '')
209
- .trim();
210
- meta.setAttribute('content', newContent);
211
- }
212
- }
213
- static onKeyboardVisibleChanged(callback) {
214
- if ('visualViewport' in window) {
215
- const VIEWPORT_VS_CLIENT_HEIGHT_RATIO = 0.75;
216
- const onResize = (event) => {
217
- const target = event.target;
218
- const isOpen = (target.height * target.scale) / window.screen.height < VIEWPORT_VS_CLIENT_HEIGHT_RATIO;
219
- callback(isOpen);
220
- };
221
- window.visualViewport.addEventListener('resize', onResize);
222
- return () => window.visualViewport.removeEventListener('resize', onResize);
223
- }
224
- else {
225
- // Fallback for older browsers does not provide a reliable event-based mechanism.
226
- console.warn('Listening for keyboard visibility changes is not reliably supported in this browser.');
227
- // Return a no-op cleanup function.
228
- return () => { };
229
- }
230
- }
231
- }
232
-
233
- class KritzelTextTool extends KritzelBaseTool {
234
- fontFamily = 'Arial';
235
- fontSize = 16;
236
- fontColor = '#000000';
237
- palette = [
238
- '#000000',
239
- '#FFFFFF',
240
- '#FF0000',
241
- '#00FF00',
242
- '#0000FF',
243
- '#FFFF00',
244
- '#FF00FF',
245
- '#00FFFF',
246
- '#808080',
247
- '#C0C0C0',
248
- '#800000',
249
- '#008000',
250
- '#000080',
251
- '#808000',
252
- '#800080',
253
- ];
254
- constructor(core) {
255
- super(core);
256
- }
257
- handlePointerDown(event) {
258
- if (event.cancelable) {
259
- event.preventDefault();
260
- }
261
- if (event.pointerType === 'mouse') {
262
- const path = event.composedPath().slice(1);
263
- const objectElement = path.find(element => element.classList && element.classList.contains('object'));
264
- const object = this._core.findObjectById(objectElement?.id);
265
- if (object instanceof KritzelText) {
266
- this._core.store.state.activeText = object;
267
- object.focus();
268
- return;
269
- }
270
- if (this._core.store.state.activeText !== null && object instanceof KritzelText) {
271
- this._core.store.state.activeText = object;
272
- object.focus();
273
- return;
274
- }
275
- if (this._core.store.state.activeText !== null && object instanceof KritzelText === false) {
276
- this._core.resetActiveText();
277
- this._core.store.setState('activeTool', KritzelToolRegistry.getTool('selection'));
278
- return;
279
- }
280
- if (KritzelEventHelper.isLeftClick(event) === false) {
281
- return;
282
- }
283
- const clientX = event.clientX - this._core.store.offsetX;
284
- const clientY = event.clientY - this._core.store.offsetY;
285
- const text = KritzelText.create(this._core, this.fontSize, this.fontFamily);
286
- text.fontColor = this.fontColor;
287
- text.translateX = (clientX - this._core.store.state.translateX) / this._core.store.state.scale;
288
- text.translateY = (clientY - this._core.store.state.translateY) / this._core.store.state.scale;
289
- text.zIndex = this._core.store.currentZIndex;
290
- this._core.store.state.activeText = text;
291
- this._core.history.executeCommand(new AddObjectCommand(this._core, this, text));
292
- }
293
- if (event.pointerType === 'touch') {
294
- const activePointers = Array.from(this._core.store.state.pointers.values());
295
- const path = event.composedPath().slice(1);
296
- const objectElement = path.find(element => element.classList && element.classList.contains('object'));
297
- const object = this._core.findObjectById(objectElement?.id);
298
- if (object instanceof KritzelText) {
299
- this._core.store.state.activeText = object;
300
- object.focus();
301
- return;
302
- }
303
- if (this._core.store.state.activeText !== null && object instanceof KritzelText) {
304
- this._core.store.state.activeText = object;
305
- object.focus();
306
- return;
307
- }
308
- if (this._core.store.state.activeText !== null && object instanceof KritzelText === false) {
309
- this._core.resetActiveText();
310
- this._core.store.setState('activeTool', KritzelToolRegistry.getTool('selection'));
311
- return;
312
- }
313
- if (activePointers.length > 1) {
314
- return;
315
- }
316
- KritzelKeyboardHelper.disableInteractiveWidget();
317
- const clientX = Math.round(activePointers[0].clientX - this._core.store.offsetX);
318
- const clientY = Math.round(activePointers[0].clientY - this._core.store.offsetY);
319
- const text = KritzelText.create(this._core, this.fontSize, this.fontFamily);
320
- text.fontColor = this.fontColor;
321
- text.translateX = (clientX - this._core.store.state.translateX) / this._core.store.state.scale;
322
- text.translateY = (clientY - this._core.store.state.translateY) / this._core.store.state.scale;
323
- text.zIndex = this._core.store.currentZIndex;
324
- this._core.store.state.activeText = text;
325
- this._core.history.executeCommand(new AddObjectCommand(this._core, this, text));
326
- }
327
- }
328
- handlePointerUp(event) {
329
- if (event.cancelable) {
330
- event.preventDefault();
331
- }
332
- if (event.pointerType === 'mouse') {
333
- this._core.store.state.activeText?.updateTextareaDimensions();
334
- this._core.store.state.activeText?.focus();
335
- }
336
- if (event.pointerType === 'touch') {
337
- this._core.store.state.activeText?.updateTextareaDimensions();
338
- this._core.store.state.activeText?.focus();
339
- KritzelKeyboardHelper.enableInteractiveWidget();
340
- }
341
- }
342
- }
343
-
344
- class ObjectHelper {
345
- static generateUUID() {
346
- return Math.random().toString(36).substr(2, 9);
347
- }
348
- static isEmpty(obj) {
349
- if (obj === null || obj === undefined) {
350
- return true;
351
- }
352
- return Object?.keys(obj).length === 0 && obj?.constructor === Object;
353
- }
354
- }
355
-
356
- class KritzelGeometryHelper {
357
- static doPolygonsIntersect(polygon1, polygon2) {
358
- // 1. Convert polygons to array of points for easier processing
359
- const points1 = [polygon1.bottomLeft, polygon1.bottomRight, polygon1.topRight, polygon1.topLeft];
360
- const points2 = [polygon2.bottomLeft, polygon2.bottomRight, polygon2.topRight, polygon2.topLeft];
361
- // 2. Check if any point of polygon1 is inside polygon2
362
- for (const point of points1) {
363
- if (this.isPointInPolygon(point, points2)) {
364
- return true;
365
- }
366
- }
367
- // 3. Check if any point of polygon2 is inside polygon1
368
- for (const point of points2) {
369
- if (this.isPointInPolygon(point, points1)) {
370
- return true;
371
- }
372
- }
373
- // 4. Check for edge intersections (more complex)
374
- for (let i = 0; i < points1.length; i++) {
375
- const p1a = points1[i];
376
- const p1b = points1[(i + 1) % points1.length]; // Wrap around to the first point
377
- for (let j = 0; j < points2.length; j++) {
378
- const p2a = points2[j];
379
- const p2b = points2[(j + 1) % points2.length];
380
- if (this.intersectLines(p1a, p1b, p2a, p2b)) {
381
- return true;
382
- }
383
- }
384
- }
385
- return false; // No intersection found
386
- }
387
- static isPointInPolygon(point, polygon) {
388
- let inside = false;
389
- for (let i = 0, j = polygon.length - 1; i < polygon.length; j = i++) {
390
- const xi = polygon[i].x, yi = polygon[i].y;
391
- const xj = polygon[j].x, yj = polygon[j].y;
392
- const intersect = yi > point.y !== yj > point.y && point.x < ((xj - xi) * (point.y - yi)) / (yj - yi) + xi;
393
- if (intersect)
394
- inside = !inside;
395
- }
396
- return inside;
397
- }
398
- static intersectLines(p1a, p1b, p2a, p2b) {
399
- const det = (p1b.x - p1a.x) * (p2b.y - p2a.y) - (p1b.y - p1a.y) * (p2b.x - p2a.x);
400
- if (det === 0) {
401
- return false; // Lines are parallel
402
- }
403
- const t = ((p2a.x - p1a.x) * (p2b.y - p2a.y) - (p2a.y - p1a.y) * (p2b.x - p2a.x)) / det;
404
- const u = -((p1a.x - p2a.x) * (p1b.y - p1a.y) - (p1a.y - p2a.y) * (p1b.x - p1a.x)) / det;
405
- return t >= 0 && t <= 1 && u >= 0 && u <= 1;
406
- }
407
- }
408
-
409
- class KritzelBaseObject {
410
- __class__ = 'KritzelBaseObject';
411
- _core;
412
- _elementRef;
413
- id;
414
- workspaceId;
415
- x;
416
- y;
417
- translateX;
418
- translateY;
419
- height;
420
- width;
421
- backgroundColor;
422
- borderColor;
423
- borderWidth = 0;
424
- opacity = 1;
425
- padding = 0;
426
- scale;
427
- resizing = false;
428
- rotation = 0;
429
- markedForRemoval = false;
430
- zIndex = 0;
431
- isVisible = true;
432
- isSelected = false;
433
- isHovered = false;
434
- isMounted = false;
435
- isEditable = false;
436
- isInteractive = false;
437
- isDebugInfoVisible = false;
438
- get totalWidth() {
439
- return this.width + this.padding * 2;
440
- }
441
- get totalHeight() {
442
- return this.height + this.padding * 2;
443
- }
444
- set elementRef(element) {
445
- this._elementRef = element;
446
- }
447
- get elementRef() {
448
- return this._elementRef;
449
- }
450
- get boundingBox() {
451
- return {
452
- x: this.translateX,
453
- y: this.translateY,
454
- z: this.scale,
455
- width: this.totalWidth / this.scale,
456
- height: this.totalHeight / this.scale,
457
- };
458
- }
459
- get rotatedBoundingBox() {
460
- return {
461
- x: this.minXRotated,
462
- y: this.minYRotated,
463
- z: this.scale,
464
- width: this.maxXRotated - this.minXRotated,
465
- height: this.maxYRotated - this.minYRotated,
466
- };
467
- }
468
- get rotatedPolygon() {
469
- const cx = this.translateX + this.totalWidth / 2 / this.scale;
470
- const cy = this.translateY + this.totalHeight / 2 / this.scale;
471
- const angle = this.rotation;
472
- const adjustedWidth = this.totalWidth / this.scale;
473
- const adjustedHeight = this.totalHeight / this.scale;
474
- const corners = {
475
- topLeft: { x: this.translateX, y: this.translateY },
476
- topRight: { x: this.translateX + adjustedWidth, y: this.translateY },
477
- bottomRight: { x: this.translateX + adjustedWidth, y: this.translateY + adjustedHeight },
478
- bottomLeft: { x: this.translateX, y: this.translateY + adjustedHeight },
479
- };
480
- const rotatedCorners = Object.keys(corners).reduce((acc, key) => {
481
- const corner = corners[key];
482
- const rotatedX = Math.cos(angle) * (corner.x - cx) - Math.sin(angle) * (corner.y - cy) + cx;
483
- const rotatedY = Math.sin(angle) * (corner.x - cx) + Math.cos(angle) * (corner.y - cy) + cy;
484
- acc[key] = { x: rotatedX, y: rotatedY };
485
- return acc;
486
- }, {});
487
- return rotatedCorners;
488
- }
489
- get minXRotated() {
490
- const corners = [this.rotatedPolygon.topLeft.x, this.rotatedPolygon.topRight.x, this.rotatedPolygon.bottomRight.x, this.rotatedPolygon.bottomLeft.x];
491
- return Math.min(...corners);
492
- }
493
- get minYRotated() {
494
- const corners = [this.rotatedPolygon.topLeft.y, this.rotatedPolygon.topRight.y, this.rotatedPolygon.bottomRight.y, this.rotatedPolygon.bottomLeft.y];
495
- return Math.min(...corners);
496
- }
497
- get maxXRotated() {
498
- const corners = [this.rotatedPolygon.topLeft.x, this.rotatedPolygon.topRight.x, this.rotatedPolygon.bottomRight.x, this.rotatedPolygon.bottomLeft.x];
499
- return Math.max(...corners);
500
- }
501
- get maxYRotated() {
502
- const corners = [this.rotatedPolygon.topLeft.y, this.rotatedPolygon.topRight.y, this.rotatedPolygon.bottomRight.y, this.rotatedPolygon.bottomLeft.y];
503
- return Math.max(...corners);
504
- }
505
- get transformationMatrix() {
506
- const scale = 1 / this.scale;
507
- const translateX = this.translateX;
508
- const translateY = this.translateY;
509
- return `matrix(${scale}, 0, 0, ${scale}, ${translateX}, ${translateY})`;
510
- }
511
- get rotationDegrees() {
512
- return this.rotation * (180 / Math.PI);
513
- }
514
- get centerX() {
515
- return this.translateX + this.totalWidth / 2;
516
- }
517
- get centerY() {
518
- return this.translateY + this.totalHeight / 2;
519
- }
520
- constructor() {
521
- this.id = this.generateId();
522
- }
523
- static create(core) {
524
- const object = new KritzelBaseObject();
525
- object._core = core;
526
- object.zIndex = core.store.currentZIndex;
527
- object.workspaceId = core.store.state.activeWorkspace.id;
528
- return object;
529
- }
530
- mount(element) {
531
- if (this.isMounted) {
532
- return;
533
- }
534
- this.elementRef = element;
535
- this.isMounted = true;
536
- }
537
- unmount() {
538
- if (!this.isMounted) {
539
- return;
540
- }
541
- this.isMounted = false;
542
- }
543
- remount() {
544
- if (!this.isMounted) {
545
- return;
546
- }
547
- this.isMounted = false;
548
- }
549
- generateId() {
550
- return ObjectHelper.generateUUID();
551
- }
552
- isInViewport() {
553
- const viewportBounds = {
554
- x: -this._core.store.state.translateX / this._core.store.state.scale,
555
- y: -this._core.store.state.translateY / this._core.store.state.scale,
556
- width: this._core.store.state.viewportWidth / this._core.store.state.scale,
557
- height: this._core.store.state.viewportHeight / this._core.store.state.scale,
558
- };
559
- return (this.rotatedBoundingBox.x < viewportBounds.x + viewportBounds.width &&
560
- this.rotatedBoundingBox.x + this.rotatedBoundingBox.width > viewportBounds.x &&
561
- this.rotatedBoundingBox.y < viewportBounds.y + viewportBounds.height &&
562
- this.rotatedBoundingBox.y + this.rotatedBoundingBox.height > viewportBounds.y);
563
- }
564
- centerInViewport() {
565
- const { viewportWidth, viewportHeight, translateX: viewportTranslateX, translateY: viewportTranslateY, scale: viewportScale } = this._core.store.state;
566
- const { x, y, width, height } = this.rotatedBoundingBox;
567
- const objectCenterX = x + width / 2;
568
- const objectCenterY = y + height / 2;
569
- const targetCenterX = (viewportWidth / 2 - viewportTranslateX) / viewportScale;
570
- const targetCenterY = (viewportHeight / 2 - viewportTranslateY) / viewportScale;
571
- const deltaX = targetCenterX - objectCenterX;
572
- const deltaY = targetCenterY - objectCenterY;
573
- this.updatePosition(this.translateX + deltaX, this.translateY + deltaY);
574
- }
575
- move(startX, startY, endX, endY) {
576
- const deltaX = (startX - endX) / this._core.store.state.scale;
577
- const deltaY = (startY - endY) / this._core.store.state.scale;
578
- this.translateX += deltaX;
579
- this.translateY += deltaY;
580
- }
581
- resize(x, y, width, height) {
582
- if (width <= 1 || height <= 1) {
583
- return;
584
- }
585
- this.width = width;
586
- this.height = height;
587
- this.translateX = x;
588
- this.translateY = y;
589
- }
590
- rotate(value) {
591
- this.rotation = value;
592
- }
593
- clone() {
594
- const clone = new KritzelBaseObject();
595
- Object.assign(clone, this);
596
- return clone;
597
- }
598
- copy() {
599
- const copiedObject = Object.create(Object.getPrototypeOf(this));
600
- Object.assign(copiedObject, this);
601
- copiedObject.id = this.generateId();
602
- copiedObject.isMounted = false;
603
- return copiedObject;
604
- }
605
- onSelectedClick() {
606
- // This method can be overridden by subclasses to handle click events when the object is selected.
607
- }
608
- serialize() {
609
- const { _core, _elementRef, element, totalWidth, totalHeight, ...remainingProps } = this;
610
- const clonedProps = structuredClone(remainingProps);
611
- if (element && typeof element === 'object' && 'nodeType' in element && element.nodeType === 1) {
612
- clonedProps.element = element.cloneNode(true);
613
- }
614
- return clonedProps;
615
- }
616
- deserialize(object) {
617
- Object.assign(this, object);
618
- return this;
619
- }
620
- isClass(className) {
621
- return this.__class__ === className;
622
- }
623
- edit() {
624
- // This method can be overridden by subclasses to handle edit actions.
625
- }
626
- hitTest(_x, _y) {
627
- return true; // Default implementation, can be overridden by subclasses
628
- }
629
- hitTestPolygon(polygon) {
630
- const objectPolygon = this.rotatedPolygon;
631
- return KritzelGeometryHelper.doPolygonsIntersect(objectPolygon, polygon);
632
- }
633
- updatePosition(x, y) {
634
- this.translateX = x;
635
- this.translateY = y;
636
- this._core.store.state.objectsMap.update(this);
637
- }
638
- }
639
-
640
- class KritzelText extends KritzelBaseObject {
641
- __class__ = 'KritzelText';
642
- value = '';
643
- fontFamily = 'Arial';
644
- fontSize = 8;
645
- fontColor = '#000000';
646
- initialWidth = 3;
647
- isNew = true;
648
- isDebugInfoVisible = true;
649
- isEditable = true;
650
- rows = 1;
651
- get isReadonly() {
652
- return !(this._core.store.state.activeTool instanceof KritzelTextTool);
653
- }
654
- constructor(config) {
655
- super();
656
- if (config) {
657
- this.value = config.value || ' ';
658
- this.translateX = config.translateX || 0;
659
- this.translateY = config.translateY || 0;
660
- this.fontSize = config.fontSize || 8;
661
- this.fontFamily = config.fontFamily || 'Arial';
662
- this.fontColor = config.fontColor || '#000000';
663
- this.height = config.height || this.fontSize * 1.2;
664
- this.width = config.width || 0;
665
- this.scale = config.scale || 1;
666
- }
667
- }
668
- static create(core, fontSize, fontFamily) {
669
- const object = new KritzelText();
670
- object._core = core;
671
- object.id = object.generateId();
672
- object.workspaceId = core.store.state.activeWorkspace.id;
673
- object.fontSize = fontSize;
674
- object.fontFamily = fontFamily;
675
- object.translateX = 0;
676
- object.translateY = 0;
677
- object.width = object.initialWidth / (object._core.store.state.scale < 0 ? object._core.store.state.scale : 1);
678
- object.height = (object.fontSize * 1.2) / (object._core.store.state.scale < 0 ? object._core.store.state.scale : 1);
679
- object.padding = 5;
680
- object.backgroundColor = 'transparent';
681
- object.scale = object._core.store.state.scale;
682
- object.value = ' ';
683
- object.zIndex = core.store.currentZIndex;
684
- return object;
685
- }
686
- mount(element) {
687
- if ((this.isMounted && this.elementRef === element) || this.isInViewport() === false) {
688
- return;
689
- }
690
- this.elementRef = element;
691
- this.isMounted = true;
692
- }
693
- resize(x, y, width, height) {
694
- if (width <= 1 || height <= 1) {
695
- return;
696
- }
697
- const scaleFactor = height / this.height;
698
- this.fontSize = this.fontSize * scaleFactor;
699
- this.width = this.width * scaleFactor;
700
- this.height = height;
701
- this.translateX = x;
702
- this.translateY = y;
703
- }
704
- handleKeyDown(event) {
705
- if (this.isReadonly) {
706
- event.preventDefault();
707
- event.stopPropagation();
708
- }
709
- }
710
- handleInput(event) {
711
- const target = event.target;
712
- if (target.value === '') {
713
- this.value = ' ';
714
- target.value = ' ';
715
- target.selectionStart = target.selectionEnd = target.value.length;
716
- }
717
- else {
718
- this.value = target.value.trim();
719
- }
720
- this.updateTextareaDimensions();
721
- }
722
- updateTextareaDimensions() {
723
- if (this.elementRef) {
724
- const span = document.createElement('span');
725
- span.style.position = 'absolute';
726
- span.style.whiteSpace = 'pre-wrap';
727
- span.style.visibility = 'hidden';
728
- span.style.fontSize = window.getComputedStyle(this.elementRef).fontSize;
729
- span.style.fontFamily = window.getComputedStyle(this.elementRef).fontFamily;
730
- span.innerHTML = this.elementRef.value.replace(/&/g, '&amp;').replace(/</g, '&lt;').replace(/>/g, '&gt;').replace(/\n/g, '<br>') + '<br>';
731
- document.body.appendChild(span);
732
- const textWidth = span.offsetWidth;
733
- const textHeight = span.offsetHeight;
734
- document.body.removeChild(span);
735
- this.width = textWidth;
736
- this.height = textHeight;
737
- this._core.history.executeCommand(new UpdateObjectCommand(this._core, this, this, { ...this }));
738
- }
739
- }
740
- focus() {
741
- if (this.elementRef) {
742
- this.elementRef.focus();
743
- }
744
- }
745
- selectAll() {
746
- if (this.elementRef) {
747
- this.elementRef.select();
748
- }
749
- }
750
- insertFromClipboard() {
751
- if (this.elementRef) {
752
- this.elementRef.focus();
753
- try {
754
- navigator.clipboard.readText().then(text => {
755
- const start = this.elementRef.selectionStart;
756
- const end = this.elementRef.selectionEnd;
757
- const value = this.elementRef.value;
758
- this.value = (value.substring(0, start) + text + value.substring(end)).trim();
759
- this.elementRef.value = this.value;
760
- const length = this.elementRef.value.length;
761
- this.elementRef.setSelectionRange(length, length);
762
- this.updateTextareaDimensions();
763
- });
764
- }
765
- catch (err) {
766
- console.error('Failed to read clipboard contents:', err);
767
- }
768
- }
769
- }
770
- edit() {
771
- KritzelKeyboardHelper.disableInteractiveWidget();
772
- this._core.store.setState('activeTool', KritzelToolRegistry.getTool('text'));
773
- this._core.store.state.activeText = this;
774
- this._core.clearSelection();
775
- this.focus();
776
- KritzelKeyboardHelper.enableInteractiveWidget();
777
- }
778
- }
779
-
780
- var cjs = {};
781
-
782
- var hasRequiredCjs;
783
-
784
- function requireCjs () {
785
- if (hasRequiredCjs) return cjs;
786
- hasRequiredCjs = 1;
787
- (function (exports) {
788
- 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;
789
- } (cjs));
790
- return cjs;
791
- }
792
-
793
- var cjsExports = requireCjs();
794
-
795
- class KritzelMathHelper {
796
- static average(a, b) {
797
- return (a + b) / 2;
798
- }
799
- }
800
-
801
- class KritzelPath extends KritzelBaseObject {
802
- __class__ = 'KritzelPath';
803
- points;
804
- d;
805
- stroke = 'none';
806
- strokeWidth;
807
- lineSlack = 0.5;
808
- fill;
809
- x = 0;
810
- y = 0;
811
- height = 0;
812
- width = 0;
813
- scale = 1;
814
- options;
815
- isVisible = true;
816
- isDebugInfoVisible = true;
817
- _adjustedPoints = null;
818
- get viewBox() {
819
- return `${this.x} ${this.y} ${this.width} ${this.height}`;
820
- }
821
- constructor(config) {
822
- super();
823
- this.options = config;
824
- this.points = config?.points ?? [];
825
- this.translateX = config?.translateX ?? 0;
826
- this.translateY = config?.translateY ?? 0;
827
- this.scale = config?.scale ?? 1;
828
- this.strokeWidth = config?.strokeWidth ?? 8;
829
- this.fill = config?.fill ?? '#000000';
830
- this.d = this.generateSvgPath();
831
- this.updateDimensions();
832
- }
833
- static create(core, options) {
834
- const object = new KritzelPath();
835
- object._core = core;
836
- object.id = object.generateId();
837
- object.workspaceId = core.store.state.activeWorkspace.id;
838
- object.options = options;
839
- object.points = options?.points ?? [];
840
- object.translateX = options?.translateX ?? 0;
841
- object.translateY = options?.translateY ?? 0;
842
- object.scale = options?.scale ?? 1;
843
- object.strokeWidth = options?.strokeWidth ?? 8;
844
- object.fill = options?.fill ?? '#000000';
845
- object.zIndex = core.store.currentZIndex;
846
- object.d = object.generateSvgPath();
847
- object.updateDimensions();
848
- return object;
849
- }
850
- resize(x, y, width, height) {
851
- if (width <= 1 || height <= 1) {
852
- return;
853
- }
854
- const scaleX = width / this.width;
855
- const scaleY = height / this.height;
856
- this.width = width;
857
- this.height = height;
858
- this.points = this.points.map(([x, y]) => [x * scaleX, y * scaleY]);
859
- this.d = this.generateSvgPath();
860
- this.width = Math.max(...this.points.map(p => p[0])) - Math.min(...this.points.map(p => p[0])) + this.strokeWidth;
861
- this.height = Math.max(...this.points.map(p => p[1])) - Math.min(...this.points.map(p => p[1])) + this.strokeWidth;
862
- this.x = Math.min(...this.points.map(p => p[0])) - this.strokeWidth / 2;
863
- this.y = Math.min(...this.points.map(p => p[1])) - this.strokeWidth / 2;
864
- this.translateX = x;
865
- this.translateY = y;
866
- this._adjustedPoints = null;
867
- }
868
- rotate(value) {
869
- this.rotation = value;
870
- this._adjustedPoints = null;
871
- }
872
- move(startX, startY, endX, endY) {
873
- const deltaX = (startX - endX) / this._core.store.state.scale;
874
- const deltaY = (startY - endY) / this._core.store.state.scale;
875
- this.translateX += deltaX;
876
- this.translateY += deltaY;
877
- this._adjustedPoints = null;
878
- }
879
- hitTest(x, y) {
880
- const halfStroke = this.strokeWidth / this.scale / 2;
881
- if (this._adjustedPoints === null) {
882
- this._adjustedPoints = this.computeAdjustedPoints();
883
- }
884
- if (this._adjustedPoints.length === 1) {
885
- const p1 = this._adjustedPoints[0];
886
- const distance = this.pointToLineSegmentDistance(x, y, p1[0], p1[1], p1[0], p1[1]);
887
- return distance <= halfStroke;
888
- }
889
- for (let i = 0; i < this._adjustedPoints.length - 1; i++) {
890
- const p1 = this._adjustedPoints[i];
891
- const p2 = this._adjustedPoints[i + 1];
892
- const distance = this.pointToLineSegmentDistance(x, y, p1[0], p1[1], p2[0], p2[1]);
893
- if (distance <= halfStroke) {
894
- return true;
895
- }
896
- }
897
- return false;
898
- }
899
- hitTestPolygon(polygon) {
900
- const halfStroke = this.strokeWidth / this.scale / 2;
901
- if (this._adjustedPoints === null) {
902
- this._adjustedPoints = this.computeAdjustedPoints();
903
- }
904
- const polyPoints = [
905
- { x: polygon.bottomLeft.x, y: polygon.bottomLeft.y },
906
- { x: polygon.bottomRight.x, y: polygon.bottomRight.y },
907
- { x: polygon.topRight.x, y: polygon.topRight.y },
908
- { x: polygon.topLeft.x, y: polygon.topLeft.y },
909
- ];
910
- for (const [px, py] of this._adjustedPoints) {
911
- if (KritzelGeometryHelper.isPointInPolygon({ x: px, y: py }, polyPoints)) {
912
- return true;
913
- }
914
- }
915
- for (const pt of polyPoints) {
916
- if (this.hitTest(pt.x, pt.y)) {
917
- return true;
918
- }
919
- }
920
- for (let i = 0; i < this._adjustedPoints.length - 1; i++) {
921
- const p1 = { x: this._adjustedPoints[i][0], y: this._adjustedPoints[i][1] };
922
- const p2 = { x: this._adjustedPoints[i + 1][0], y: this._adjustedPoints[i + 1][1] };
923
- for (let j = 0; j < polyPoints.length; j++) {
924
- const q1 = polyPoints[j];
925
- const q2 = polyPoints[(j + 1) % polyPoints.length];
926
- if (KritzelGeometryHelper.intersectLines(p1, p2, q1, q2)) {
927
- return true;
928
- }
929
- }
930
- }
931
- for (let i = 0; i < this._adjustedPoints.length - 1; i++) {
932
- const p1 = this._adjustedPoints[i];
933
- const p2 = this._adjustedPoints[i + 1];
934
- for (let j = 0; j < polyPoints.length; j++) {
935
- const q1 = polyPoints[j];
936
- const q2 = polyPoints[(j + 1) % polyPoints.length];
937
- const d1 = this.pointToLineSegmentDistance(q1.x, q1.y, p1[0], p1[1], p2[0], p2[1]);
938
- const d2 = this.pointToLineSegmentDistance(q2.x, q2.y, p1[0], p1[1], p2[0], p2[1]);
939
- const d3 = this.pointToLineSegmentDistance(p1[0], p1[1], q1.x, q1.y, q2.x, q2.y);
940
- const d4 = this.pointToLineSegmentDistance(p2[0], p2[1], q1.x, q1.y, q2.x, q2.y);
941
- const minD = Math.min(d1, d2, d3, d4);
942
- if (minD <= halfStroke) {
943
- return true;
944
- }
945
- }
946
- }
947
- return false;
948
- }
949
- updatePosition(x, y) {
950
- this.translateX = x;
951
- this.translateY = y;
952
- this._adjustedPoints = null;
953
- this._core.store.state.objectsMap.update(this);
954
- }
955
- computeAdjustedPoints() {
956
- if (!this.points?.length) {
957
- return [];
958
- }
959
- const angle = this.rotation;
960
- const cos = Math.cos(angle);
961
- const sin = Math.sin(angle);
962
- const xs = this.points.map(p => p[0]);
963
- const ys = this.points.map(p => p[1]);
964
- const pivot = {
965
- x: (Math.min(...xs) + Math.max(...xs)) / 2,
966
- y: (Math.min(...ys) + Math.max(...ys)) / 2,
967
- };
968
- const { x: cx, y: cy } = pivot;
969
- const rotatedPoints = this.points.map(([x, y]) => {
970
- const dx = x - cx;
971
- const dy = y - cy;
972
- return [cx + dx * cos - dy * sin, cy + dx * sin + dy * cos];
973
- });
974
- return rotatedPoints.map(([px, py]) => [((Math.abs(px - this.x) / this.scale + this.translateX)), ((Math.abs(py - this.y) / this.scale + this.translateY))]);
975
- }
976
- pointToLineSegmentDistance(x, y, x1, y1, x2, y2) {
977
- const A = x - x1;
978
- const B = y - y1;
979
- const C = x2 - x1;
980
- const D = y2 - y1;
981
- const dot = A * C + B * D;
982
- const len_sq = C * C + D * D;
983
- let param = -1;
984
- if (len_sq !== 0) {
985
- // in case of 0 length line
986
- param = dot / len_sq;
987
- }
988
- let xx, yy;
989
- if (param < 0) {
990
- xx = x1;
991
- yy = y1;
992
- }
993
- else if (param > 1) {
994
- xx = x2;
995
- yy = y2;
996
- }
997
- else {
998
- xx = x1 + param * C;
999
- yy = y1 + param * D;
1000
- }
1001
- const dx = x - xx;
1002
- const dy = y - yy;
1003
- return Math.sqrt(dx * dx + dy * dy);
1004
- }
1005
- updateDimensions() {
1006
- const rotatedPoints = this.points.map(([x, y]) => {
1007
- const rotatedX = x * Math.cos(this.rotation) - y * Math.sin(this.rotation);
1008
- const rotatedY = x * Math.sin(this.rotation) + y * Math.cos(this.rotation);
1009
- return [rotatedX, rotatedY];
1010
- });
1011
- const minX = Math.min(...rotatedPoints.map(p => p[0] - this.strokeWidth / 2));
1012
- const minY = Math.min(...rotatedPoints.map(p => p[1] - this.strokeWidth / 2));
1013
- const maxX = Math.max(...rotatedPoints.map(p => p[0] + this.strokeWidth / 2));
1014
- const maxY = Math.max(...rotatedPoints.map(p => p[1] + this.strokeWidth / 2));
1015
- this.width = maxX - minX + this.lineSlack;
1016
- this.height = maxY - minY + this.lineSlack;
1017
- this.x = minX;
1018
- this.y = minY;
1019
- this.translateX = (this.x + this.translateX) / this.scale;
1020
- this.translateY = (this.y + this.translateY) / this.scale;
1021
- }
1022
- generateSvgPath() {
1023
- const stroke = this.getStrokeFromPoints(this.points, this.strokeWidth);
1024
- return this.getSvgPathFromStroke(stroke);
1025
- }
1026
- getStrokeFromPoints(points, strokeWidth) {
1027
- return cjsExports.getStroke(points, {
1028
- size: strokeWidth,
1029
- thinning: 0.5,
1030
- smoothing: 0.5,
1031
- streamline: 0.5,
1032
- easing: t => t,
1033
- simulatePressure: true,
1034
- last: true,
1035
- start: {
1036
- cap: true,
1037
- taper: 0,
1038
- easing: t => t,
1039
- },
1040
- end: {
1041
- cap: true,
1042
- taper: 0,
1043
- easing: t => t,
1044
- },
1045
- });
1046
- }
1047
- getSvgPathFromStroke(points, closed = true) {
1048
- const len = points.length;
1049
- if (len < 4) {
1050
- return ``;
1051
- }
1052
- let a = points[0];
1053
- let b = points[1];
1054
- const c = points[2];
1055
- 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`;
1056
- for (let i = 2, max = len - 1; i < max; i++) {
1057
- a = points[i];
1058
- b = points[i + 1];
1059
- result += `${KritzelMathHelper.average(a[0], b[0]).toFixed(2)},${KritzelMathHelper.average(a[1], b[1]).toFixed(2)} `;
1060
- }
1061
- if (closed) {
1062
- result += 'Z';
1063
- }
1064
- return result;
1065
- }
1066
- }
1067
-
1068
- class KritzelImage extends KritzelBaseObject {
1069
- __class__ = 'KritzelImage';
1070
- src = '';
1071
- maxWidth = 300;
1072
- maxHeight = 300;
1073
- maxCompressionSize = 300;
1074
- isDebugInfoVisible = true;
1075
- constructor(config) {
1076
- super();
1077
- this.src = config?.src || '';
1078
- this.x = config?.x || 0;
1079
- this.y = config?.y || 0;
1080
- this.translateX = config?.translateX || 0;
1081
- this.translateY = config?.translateY || 0;
1082
- this.scale = config?.scale || 1;
1083
- }
1084
- static create(core) {
1085
- const object = new KritzelImage();
1086
- object._core = core;
1087
- object.id = object.generateId();
1088
- object.workspaceId = core.store.state.activeWorkspace.id;
1089
- object.x = 0;
1090
- object.y = 0;
1091
- object.translateX = 0;
1092
- object.translateY = 0;
1093
- object.scale = object._core.store.state.scale;
1094
- object.zIndex = core.store.currentZIndex;
1095
- return object;
1096
- }
1097
- resize(x, y, width, height) {
1098
- if (width <= 1 || height <= 1) {
1099
- return;
1100
- }
1101
- const scaleFactor = height / this.height;
1102
- this.width = this.width * scaleFactor;
1103
- this.height = this.height * scaleFactor;
1104
- this.translateX = x;
1105
- this.translateY = y;
1106
- }
1107
- calculateScaledDimensions(img) {
1108
- let scaledWidth = img.width;
1109
- let scaledHeight = img.height;
1110
- if (img.width > this.maxWidth || img.height > this.maxHeight) {
1111
- const widthRatio = this.maxWidth / img.width;
1112
- const heightRatio = this.maxHeight / img.height;
1113
- const scaleRatio = Math.min(widthRatio, heightRatio);
1114
- scaledWidth = img.width * scaleRatio;
1115
- scaledHeight = img.height * scaleRatio;
1116
- }
1117
- return { scaledWidth, scaledHeight };
1118
- }
1119
- }
1120
-
1121
- class KritzelBrushTool extends KritzelBaseTool {
1122
- type = 'pen';
1123
- color = '#000000';
1124
- size = 6;
1125
- palettes = {
1126
- pen: ['#000000', '#FFFFFF', '#FF0000', '#00FF00', '#0000FF', '#FFFF00', '#FF00FF', '#00FFFF', '#808080', '#C0C0C0', '#800000', '#008000', '#000080', '#808000', '#800080'],
1127
- highlighter: ['#ffff00', '#ffb347', '#b4ffb4'],
1128
- };
1129
- constructor(core) {
1130
- super(core);
1131
- }
1132
- handlePointerDown(event) {
1133
- if (event.cancelable) {
1134
- event.preventDefault();
1135
- }
1136
- if (event.pointerType === 'mouse') {
1137
- if (KritzelEventHelper.isLeftClick(event)) {
1138
- this._core.store.state.isDrawing = true;
1139
- const x = event.clientX - this._core.store.offsetX;
1140
- const y = event.clientY - this._core.store.offsetY;
1141
- this._core.store.state.currentPath = KritzelPath.create(this._core, {
1142
- points: [[x, y]],
1143
- translateX: -this._core.store.state.translateX,
1144
- translateY: -this._core.store.state.translateY,
1145
- scale: this._core.store.state.scale,
1146
- fill: this.color,
1147
- strokeWidth: this.size,
1148
- });
1149
- }
1150
- }
1151
- if (event.pointerType === 'touch') {
1152
- const activePointers = Array.from(this._core.store.state.pointers.values());
1153
- if (activePointers.length === 1) {
1154
- const x = Math.round(activePointers[0].clientX - this._core.store.offsetX);
1155
- const y = Math.round(activePointers[0].clientY - this._core.store.offsetY);
1156
- this._core.store.state.isDrawing = true;
1157
- this._core.store.state.currentPath = KritzelPath.create(this._core, {
1158
- points: [[x, y]],
1159
- translateX: -this._core.store.state.translateX,
1160
- translateY: -this._core.store.state.translateY,
1161
- scale: this._core.store.state.scale,
1162
- fill: this.color,
1163
- strokeWidth: this.size,
1164
- });
1165
- this._core.rerender();
1166
- }
1167
- }
1168
- }
1169
- handlePointerMove(event) {
1170
- if (event.cancelable) {
1171
- event.preventDefault();
1172
- }
1173
- if (event.pointerType === 'mouse') {
1174
- if (this._core.store.state.isDrawing) {
1175
- const x = event.clientX - this._core.store.offsetX;
1176
- const y = event.clientY - this._core.store.offsetY;
1177
- this._core.store.state.currentPath = KritzelPath.create(this._core, {
1178
- points: [...this._core.store.state.currentPath.points, [x, y]],
1179
- translateX: -this._core.store.state.translateX,
1180
- translateY: -this._core.store.state.translateY,
1181
- scale: this._core.store.state.scale,
1182
- fill: this.color,
1183
- strokeWidth: this.size,
1184
- });
1185
- this._core.rerender();
1186
- }
1187
- }
1188
- if (event.pointerType === 'touch') {
1189
- const activePointers = Array.from(this._core.store.state.pointers.values());
1190
- if (activePointers.length === 1) {
1191
- const x = Math.round(activePointers[0].clientX - this._core.store.offsetX);
1192
- const y = Math.round(activePointers[0].clientY - this._core.store.offsetY);
1193
- this._core.store.state.currentPath = KritzelPath.create(this._core, {
1194
- points: [...this._core.store.state.currentPath.points, [x, y]],
1195
- translateX: -this._core.store.state.translateX,
1196
- translateY: -this._core.store.state.translateY,
1197
- scale: this._core.store.state.scale,
1198
- fill: this.color,
1199
- strokeWidth: this.size,
1200
- });
1201
- this._core.rerender();
1202
- }
1203
- }
1204
- }
1205
- handlePointerUp(event) {
1206
- if (event.cancelable) {
1207
- event.preventDefault();
1208
- }
1209
- if (event.pointerType === 'mouse') {
1210
- if (this._core.store.state.isDrawing) {
1211
- this._core.store.state.isDrawing = false;
1212
- if (this._core.store.state.currentPath) {
1213
- const currentPath = this._core.store.state.currentPath;
1214
- currentPath.zIndex = this._core.store.currentZIndex;
1215
- this._core.store.state.currentPath = currentPath;
1216
- this._core.history.executeCommand(new AddObjectCommand(this._core, this, this._core.store.state.currentPath));
1217
- }
1218
- this._core.store.state.currentPath = undefined;
1219
- }
1220
- }
1221
- if (event.pointerType === 'touch') {
1222
- if (this._core.store.state.isDrawing) {
1223
- this._core.store.state.isDrawing = false;
1224
- if (this._core.store.state.currentPath) {
1225
- const currentPath = this._core.store.state.currentPath;
1226
- currentPath.zIndex = this._core.store.currentZIndex;
1227
- this._core.store.state.currentPath = currentPath;
1228
- this._core.history.executeCommand(new AddObjectCommand(this._core, this, currentPath));
1229
- }
1230
- this._core.store.state.currentPath = undefined;
1231
- this._core.rerender();
1232
- }
1233
- }
1234
- }
1235
- }
1236
-
1237
- class BatchCommand extends KritzelBaseCommand {
1238
- commands;
1239
- constructor(core, initiator, commands, skipHistory = false) {
1240
- super(core, initiator, skipHistory);
1241
- this.commands = commands;
1242
- }
1243
- execute() {
1244
- this.commands.forEach(command => command.execute());
1245
- }
1246
- undo() {
1247
- this.commands.forEach(command => command.undo());
1248
- }
1249
- }
1250
-
1251
- class KritzelCustomElement extends KritzelBaseObject {
1252
- __class__ = 'KritzelCustomElement';
1253
- element;
1254
- isInteractive = true;
1255
- constructor(config) {
1256
- super();
1257
- if (config) {
1258
- this.translateX = config.translateX || 0;
1259
- this.translateY = config.translateY || 0;
1260
- this.scale = config.scale || 1;
1261
- this.element = config.element;
1262
- this.height = config.height || 0;
1263
- this.width = config.width || 0;
1264
- }
1265
- }
1266
- static create(core, config) {
1267
- const object = new KritzelCustomElement(config);
1268
- object._core = core;
1269
- object.id = object.generateId();
1270
- object.workspaceId = core.store.state.activeWorkspace.id;
1271
- return object;
1272
- }
1273
- mount(element) {
1274
- if (this.isMounted) {
1275
- return;
1276
- }
1277
- this.elementRef = element;
1278
- this.isMounted = true;
1279
- this.elementRef.appendChild(this.element);
1280
- }
1281
- resize(x, y, width, height) {
1282
- if (width <= 1 || height <= 1) {
1283
- return;
1284
- }
1285
- this.width = width;
1286
- this.height = height;
1287
- this.translateX = x;
1288
- this.translateY = y;
1289
- if (this.element) {
1290
- this.element.style.width = `${width}px`;
1291
- this.element.style.height = `${height}px`;
1292
- }
1293
- }
1294
- copy() {
1295
- const copiedObject = Object.create(Object.getPrototypeOf(this));
1296
- Object.assign(copiedObject, this);
1297
- copiedObject.id = this.generateId();
1298
- copiedObject.isMounted = false;
1299
- copiedObject.element = this.element.cloneNode(true);
1300
- return copiedObject;
1301
- }
1302
- }
1303
-
1304
- class RemoveObjectCommand extends KritzelBaseCommand {
1305
- object;
1306
- constructor(core, initiator, object, skipHistory = false) {
1307
- super(core, initiator, skipHistory);
1308
- this.object = object;
1309
- }
1310
- execute() {
1311
- this._core.store.state.objectsMap.remove(object => object.id === this.object.id);
1312
- this._core.store.state.objectsMap.filter(object => object instanceof KritzelCustomElement).forEach(object => object.remount());
1313
- this._core.deleteObjectFromDatabase(this.object.id);
1314
- }
1315
- undo() {
1316
- this._core.store.state.objectsMap.insert(this.object);
1317
- this._core.store.state.objectsMap.filter(object => object instanceof KritzelCustomElement).forEach(object => object.remount());
1318
- this._core.addObjectToDatabase(this.object);
1319
- }
1320
- }
1321
-
1322
- class KritzelEraserTool extends KritzelBaseTool {
1323
- touchStartTimeout = null;
1324
- constructor(core) {
1325
- super(core);
1326
- }
1327
- handlePointerDown(event) {
1328
- if (event.pointerType === 'mouse') {
1329
- if (KritzelEventHelper.isLeftClick(event)) {
1330
- this._core.store.state.isErasing = true;
1331
- }
1332
- }
1333
- if (event.pointerType === 'touch') {
1334
- this.touchStartTimeout = setTimeout(() => {
1335
- if (this._core.store.state.pointers.size === 1 && !this._core.store.state.isScaling) {
1336
- this._core.store.state.isErasing = true;
1337
- }
1338
- }, 80);
1339
- }
1340
- }
1341
- handlePointerMove(event) {
1342
- if (event.pointerType === 'mouse') {
1343
- if (this._core.store.state.isErasing) {
1344
- const selectedObjects = this._core.getObjectsFromPointerEvent(event, '.object');
1345
- if (selectedObjects.length === 0)
1346
- return;
1347
- const x = this._core.store.state.pointerX;
1348
- const y = this._core.store.state.pointerY;
1349
- selectedObjects.forEach(selectedObject => {
1350
- selectedObject.markedForRemoval = selectedObject.hitTest(x, y);
1351
- });
1352
- this._core.rerender();
1353
- }
1354
- }
1355
- if (event.pointerType === 'touch') {
1356
- if (this._core.store.state.pointers.size === 1 && this._core.store.state.isErasing) {
1357
- const shadowRoot = this._core.store.state.host?.shadowRoot;
1358
- if (!shadowRoot)
1359
- return;
1360
- const selectedObjects = this._core.getObjectsFromPointerEvent(event, '.object');
1361
- if (selectedObjects.length === 0)
1362
- return;
1363
- const x = this._core.store.state.pointerX;
1364
- const y = this._core.store.state.pointerY;
1365
- selectedObjects.forEach(selectedObject => {
1366
- selectedObject.markedForRemoval = selectedObject.hitTest(x, y);
1367
- });
1368
- this._core.rerender();
1369
- }
1370
- }
1371
- }
1372
- handlePointerUp(event) {
1373
- if (event.pointerType === 'mouse') {
1374
- if (this._core.store.state.isErasing) {
1375
- const removeCommands = this._core.store.allObjects.filter(object => object.markedForRemoval).map(object => {
1376
- object.markedForRemoval = false;
1377
- return new RemoveObjectCommand(this._core, this, object);
1378
- });
1379
- if (removeCommands.length > 0) {
1380
- this._core.history.executeCommand(new BatchCommand(this._core, this, removeCommands));
1381
- }
1382
- this._core.store.state.isErasing = false;
1383
- }
1384
- }
1385
- if (event.pointerType === 'touch') {
1386
- clearTimeout(this.touchStartTimeout);
1387
- if (this._core.store.state.isErasing) {
1388
- const removeCommands = this._core.store.allObjects
1389
- .filter(object => object.markedForRemoval)
1390
- .map(object => {
1391
- object.markedForRemoval = false;
1392
- return new RemoveObjectCommand(this._core, this, object);
1393
- });
1394
- if (removeCommands.length > 0) {
1395
- this._core.history.executeCommand(new BatchCommand(this._core, this, removeCommands));
1396
- }
1397
- this._core.store.state.isErasing = false;
1398
- }
1399
- }
1400
- }
1401
- }
1402
-
1403
- class RemoveSelectionGroupCommand extends KritzelBaseCommand {
1404
- previousSelectionGroup;
1405
- constructor(core, initiator, skipHistory = false) {
1406
- super(core, initiator, skipHistory);
1407
- this.previousSelectionGroup = this._core.store.state.selectionGroup;
1408
- }
1409
- execute() {
1410
- this._core.store.state.objectsMap.remove(object => object.id === this.previousSelectionGroup?.id);
1411
- this._core.store.state.selectionGroup = null;
1412
- }
1413
- undo() {
1414
- if (this.previousSelectionGroup) {
1415
- this._core.store.state.objectsMap.insert(this.previousSelectionGroup);
1416
- this._core.store.state.selectionGroup = this.previousSelectionGroup;
1417
- }
1418
- }
1419
- }
1420
-
1421
- class MoveSelectionGroupCommand extends KritzelBaseCommand {
1422
- selectionGroup;
1423
- startX;
1424
- startY;
1425
- endX;
1426
- endY;
1427
- skipExecution;
1428
- constructor(core, initiator, startX, startY, endX, endY, skipFirstExecution = false, skipHistory = false) {
1429
- super(core, initiator, skipHistory);
1430
- this.startX = startX;
1431
- this.startY = startY;
1432
- this.endX = endX;
1433
- this.endY = endY;
1434
- this.skipExecution = skipFirstExecution;
1435
- this.selectionGroup = this._core.store.state.selectionGroup;
1436
- }
1437
- execute() {
1438
- if (this.skipExecution) {
1439
- this.skipExecution = false;
1440
- // Skip execution, but still update objects
1441
- this._core.store.state.selectionGroup.objects.forEach(object => {
1442
- this._core.store.state.objectsMap.update(object);
1443
- this._core.updateObjectInDatabase(object);
1444
- });
1445
- return;
1446
- }
1447
- this._core.store.state.selectionGroup = this.selectionGroup;
1448
- this._core.store.state.selectionGroup.move(this.startX, this.startY, this.endX, this.endY);
1449
- this._core.store.state.selectionGroup.objects.forEach(object => {
1450
- this._core.store.state.objectsMap.update(object);
1451
- this._core.updateObjectInDatabase(object);
1452
- });
1453
- }
1454
- undo() {
1455
- this._core.store.state.selectionGroup = this.selectionGroup;
1456
- this._core.store.state.selectionGroup.move(this.endX, this.endY, this.startX, this.startY);
1457
- this._core.store.state.selectionGroup.objects.forEach(object => {
1458
- this._core.store.state.objectsMap.update(object);
1459
- this._core.updateObjectInDatabase(object);
1460
- });
1461
- }
1462
- }
1463
-
1464
- class KritzelBaseHandler {
1465
- _core;
1466
- constructor(core) {
1467
- this._core = core;
1468
- }
1469
- }
1470
-
1471
- class KritzelMoveHandler extends KritzelBaseHandler {
1472
- dragStartX;
1473
- dragStartY;
1474
- startX;
1475
- startY;
1476
- endX;
1477
- endY;
1478
- hasMoved = false;
1479
- trackedPointerId = null;
1480
- constructor(core) {
1481
- super(core);
1482
- }
1483
- reset() {
1484
- this.dragStartX = 0;
1485
- this.dragStartY = 0;
1486
- this.startX = 0;
1487
- this.startY = 0;
1488
- this.endX = 0;
1489
- this.endY = 0;
1490
- this.hasMoved = false;
1491
- this.trackedPointerId = null;
1492
- }
1493
- cancelPendingDrag() {
1494
- this._core.store.state.isDragging = false;
1495
- this.reset();
1496
- }
1497
- handlePointerDown(event) {
1498
- if (event.pointerType === 'mouse') {
1499
- if (KritzelEventHelper.isLeftClick(event)) {
1500
- if (this._core.store.state.selectionGroup?.isSelected && !this._core.store.state.isResizeHandleSelected && !this._core.store.state.isRotationHandleSelected) {
1501
- const clientX = event.clientX - this._core.store.offsetX;
1502
- const clientY = event.clientY - this._core.store.offsetY;
1503
- this._core.store.state.isDragging = true;
1504
- this.dragStartX = clientX;
1505
- this.dragStartY = clientY;
1506
- this.startX = this.dragStartX;
1507
- this.startY = this.dragStartY;
1508
- this.trackedPointerId = event.pointerId;
1509
- }
1510
- else {
1511
- this.trackedPointerId = null;
1512
- }
1513
- }
1514
- else {
1515
- this.trackedPointerId = null;
1516
- }
1517
- }
1518
- if (event.pointerType === 'touch') {
1519
- const activePointers = Array.from(this._core.store.state.pointers.values());
1520
- if (this._core.store.state.pointers.size === 1) {
1521
- if (this._core.store.state.selectionGroup?.isSelected && !this._core.store.state.isResizeHandleSelected && !this._core.store.state.isRotationHandleSelected) {
1522
- const x = Math.round(activePointers[0].clientX - this._core.store.offsetX);
1523
- const y = Math.round(activePointers[0].clientY - this._core.store.offsetY);
1524
- this.dragStartX = x;
1525
- this.dragStartY = y;
1526
- this.startX = x;
1527
- this.startY = y;
1528
- this.trackedPointerId = event.pointerId;
1529
- }
1530
- else {
1531
- this.trackedPointerId = null;
1532
- }
1533
- }
1534
- }
1535
- }
1536
- handlePointerMove(event) {
1537
- if (this.trackedPointerId === null || this.trackedPointerId !== event.pointerId) {
1538
- return;
1539
- }
1540
- if (event.pointerType === 'mouse') {
1541
- if (this._core.store.state.isDragging && this._core.store.state.selectionGroup) {
1542
- const clientX = event.clientX - this._core.store.offsetX;
1543
- const clientY = event.clientY - this._core.store.offsetY;
1544
- this.endX = clientX;
1545
- this.endY = clientY;
1546
- this._core.store.state.selectionGroup.move(clientX, clientY, this.dragStartX, this.dragStartY);
1547
- this.dragStartX = clientX;
1548
- this.dragStartY = clientY;
1549
- this.hasMoved = true;
1550
- }
1551
- }
1552
- if (event.pointerType === 'touch') {
1553
- const activePointers = Array.from(this._core.store.state.pointers.values());
1554
- if (this._core.store.state.pointers.size === 1 &&
1555
- this._core.store.state.selectionGroup &&
1556
- !this._core.store.state.isResizeHandleSelected &&
1557
- !this._core.store.state.isRotationHandleSelected) {
1558
- const x = Math.round(activePointers[0].clientX - this._core.store.offsetX);
1559
- const y = Math.round(activePointers[0].clientY - this._core.store.offsetY);
1560
- this._core.store.state.isDragging = true;
1561
- this.endX = x;
1562
- this.endY = y;
1563
- const moveDeltaX = Math.abs(x - this.startX);
1564
- const moveDeltaY = Math.abs(y - this.startY);
1565
- const moveThreshold = 5;
1566
- if (moveDeltaX > moveThreshold || moveDeltaY > moveThreshold) {
1567
- clearTimeout(this._core.store.state.longTouchTimeout);
1568
- this._core.store.state.selectionGroup.move(x, y, this.dragStartX, this.dragStartY);
1569
- this.dragStartX = x;
1570
- this.dragStartY = y;
1571
- this.hasMoved = true;
1572
- }
1573
- }
1574
- }
1575
- }
1576
- handlePointerUp(event) {
1577
- if (this.trackedPointerId === null || this.trackedPointerId !== event.pointerId) {
1578
- return;
1579
- }
1580
- if (event.pointerType === 'mouse') {
1581
- if (this._core.store.state.isDragging) {
1582
- this._core.store.state.isDragging = false;
1583
- if (this.hasMoved) {
1584
- this._core.history.executeCommand(new MoveSelectionGroupCommand(this._core, this, this.endX, this.endY, this.startX, this.startY, true));
1585
- this._core.store.state.hasObjectsChanged = true;
1586
- }
1587
- }
1588
- }
1589
- if (event.pointerType === 'touch') {
1590
- if (this._core.store.state.isDragging) {
1591
- this._core.store.state.isDragging = false;
1592
- if (this.hasMoved) {
1593
- this._core.history.executeCommand(new MoveSelectionGroupCommand(this._core, this, this.endX, this.endY, this.startX, this.startY, true));
1594
- this._core.store.state.hasObjectsChanged = true;
1595
- }
1596
- }
1597
- }
1598
- this.reset();
1599
- }
1600
- }
1601
-
1602
- var KritzelHandleType;
1603
- (function (KritzelHandleType) {
1604
- KritzelHandleType["TopLeft"] = "top-left";
1605
- KritzelHandleType["TopRight"] = "top-right";
1606
- KritzelHandleType["BottomLeft"] = "bottom-left";
1607
- KritzelHandleType["BottomRight"] = "bottom-right";
1608
- })(KritzelHandleType || (KritzelHandleType = {}));
1609
-
1610
- class ResizeSelectionGroupCommand extends KritzelBaseCommand {
1611
- newSize;
1612
- previousSize;
1613
- selectionGroup;
1614
- constructor(core, initiator, previousSize, newSize, skipHistory = false) {
1615
- super(core, initiator, skipHistory);
1616
- this.previousSize = previousSize;
1617
- this.newSize = newSize;
1618
- this.selectionGroup = this._core.store.state.selectionGroup;
1619
- }
1620
- execute() {
1621
- this._core.store.state.selectionGroup = this.selectionGroup;
1622
- this._core.store.state.selectionGroup.resize(this.newSize.x, this.newSize.y, this.newSize.width, this.newSize.height);
1623
- this._core.store.state.selectionGroup.objects.forEach(object => {
1624
- this._core.store.state.objectsMap.update(object);
1625
- this._core.updateObjectInDatabase(object);
1626
- });
1627
- }
1628
- undo() {
1629
- this._core.store.state.selectionGroup = this.selectionGroup;
1630
- this._core.store.state.selectionGroup.resize(this.previousSize.x, this.previousSize.y, this.previousSize.width, this.previousSize.height);
1631
- this._core.store.state.selectionGroup.objects.forEach(object => {
1632
- this._core.store.state.objectsMap.update(object);
1633
- this._core.updateObjectInDatabase(object);
1634
- });
1635
- }
1636
- }
1637
-
1638
- class KritzelResizeHandler extends KritzelBaseHandler {
1639
- initialMouseX = 0;
1640
- initialMouseY = 0;
1641
- initialSize = { x: 0, y: 0, width: 0, height: 0 };
1642
- newSize = { x: 0, y: 0, width: 0, height: 0 };
1643
- constructor(core) {
1644
- super(core);
1645
- }
1646
- reset() {
1647
- this.initialMouseX = 0;
1648
- this.initialMouseY = 0;
1649
- this.initialSize = { x: 0, y: 0, width: 0, height: 0 };
1650
- this.newSize = { x: 0, y: 0, width: 0, height: 0 };
1651
- }
1652
- handlePointerDown(event) {
1653
- if (event.pointerType === 'mouse') {
1654
- if (KritzelEventHelper.isLeftClick(event)) {
1655
- if (this._core.store.state.selectionGroup && this._core.store.state.isResizeHandleSelected) {
1656
- const clientX = event.clientX - this._core.store.offsetX;
1657
- const clientY = event.clientY - this._core.store.offsetY;
1658
- this._core.store.state.isResizing = true;
1659
- this.initialMouseX = clientX;
1660
- this.initialMouseY = clientY;
1661
- this.initialSize.width = this._core.store.state.selectionGroup.width;
1662
- this.initialSize.height = this._core.store.state.selectionGroup.height;
1663
- this.initialSize.x = this._core.store.state.selectionGroup.translateX;
1664
- this.initialSize.y = this._core.store.state.selectionGroup.translateY;
1665
- }
1666
- }
1667
- }
1668
- if (event.pointerType === 'touch') {
1669
- const activePointers = Array.from(this._core.store.state.pointers.values());
1670
- const firstTouch = activePointers[0];
1671
- if (!firstTouch) {
1672
- return;
1673
- }
1674
- if (activePointers.length === 1) {
1675
- if (this._core.store.state.selectionGroup && this._core.store.state.isResizeHandleSelected) {
1676
- const clientX = Math.round(firstTouch.clientX - this._core.store.offsetX);
1677
- const clientY = Math.round(firstTouch.clientY - this._core.store.offsetY);
1678
- this._core.store.state.isResizing = true;
1679
- this.initialMouseX = clientX;
1680
- this.initialMouseY = clientY;
1681
- this.initialSize.width = this._core.store.state.selectionGroup.width;
1682
- this.initialSize.height = this._core.store.state.selectionGroup.height;
1683
- this.initialSize.x = this._core.store.state.selectionGroup.translateX;
1684
- this.initialSize.y = this._core.store.state.selectionGroup.translateY;
1685
- clearTimeout(this._core.store.state.longTouchTimeout);
1686
- }
1687
- }
1688
- }
1689
- }
1690
- handlePointerMove(event) {
1691
- if (event.pointerType === 'mouse') {
1692
- if (this._core.store.state.isResizing && this._core.store.state.selectionGroup) {
1693
- const clientX = event.clientX - this._core.store.offsetX;
1694
- const clientY = event.clientY - this._core.store.offsetY;
1695
- const dx = clientX - this.initialMouseX;
1696
- const dy = clientY - this.initialMouseY;
1697
- switch (this._core.store.state.resizeHandleType) {
1698
- case KritzelHandleType.TopLeft:
1699
- this.newSize.width = this.initialSize.width - dx;
1700
- this.newSize.height = this.initialSize.height - dy;
1701
- this.newSize.x = dx / this._core.store.state.scale + this.initialSize.x;
1702
- this.newSize.y = dy / this._core.store.state.scale + this.initialSize.y;
1703
- break;
1704
- case KritzelHandleType.TopRight:
1705
- this.newSize.width = this.initialSize.width + dx;
1706
- this.newSize.height = this.initialSize.height - dy;
1707
- this.newSize.x = this.initialSize.x;
1708
- this.newSize.y = dy / this._core.store.state.scale + this.initialSize.y;
1709
- break;
1710
- case KritzelHandleType.BottomLeft:
1711
- this.newSize.width = this.initialSize.width - dx;
1712
- this.newSize.height = this.initialSize.height + dy;
1713
- this.newSize.x = dx / this._core.store.state.scale + this.initialSize.x;
1714
- this.newSize.y = this.initialSize.y;
1715
- break;
1716
- case KritzelHandleType.BottomRight:
1717
- this.newSize.width = this.initialSize.width + dx;
1718
- this.newSize.height = this.initialSize.height + dy;
1719
- this.newSize.x = this.initialSize.x;
1720
- this.newSize.y = this.initialSize.y;
1721
- break;
1722
- }
1723
- this._core.store.state.selectionGroup.resize(this.newSize.x, this.newSize.y, this.newSize.width, this.newSize.height);
1724
- }
1725
- }
1726
- if (event.pointerType === 'touch') {
1727
- const activePointers = Array.from(this._core.store.state.pointers.values());
1728
- const oneFingerTouch = activePointers[0];
1729
- if (!oneFingerTouch) {
1730
- return;
1731
- }
1732
- if (this._core.store.state.isResizing && this._core.store.state.selectionGroup) {
1733
- const clientX = Math.round(oneFingerTouch.clientX - this._core.store.offsetX);
1734
- const clientY = Math.round(oneFingerTouch.clientY - this._core.store.offsetY);
1735
- const dx = clientX - this.initialMouseX;
1736
- const dy = clientY - this.initialMouseY;
1737
- switch (this._core.store.state.resizeHandleType) {
1738
- case KritzelHandleType.TopLeft:
1739
- this.newSize.width = this.initialSize.width - dx;
1740
- this.newSize.height = this.initialSize.height - dy;
1741
- this.newSize.x = dx / this._core.store.state.scale + this.initialSize.x;
1742
- this.newSize.y = dy / this._core.store.state.scale + this.initialSize.y;
1743
- break;
1744
- case KritzelHandleType.TopRight:
1745
- this.newSize.width = this.initialSize.width + dx;
1746
- this.newSize.height = this.initialSize.height - dy;
1747
- this.newSize.x = this.initialSize.x;
1748
- this.newSize.y = dy / this._core.store.state.scale + this.initialSize.y;
1749
- break;
1750
- case KritzelHandleType.BottomLeft:
1751
- this.newSize.width = this.initialSize.width - dx;
1752
- this.newSize.height = this.initialSize.height + dy;
1753
- this.newSize.x = dx / this._core.store.state.scale + this.initialSize.x;
1754
- this.newSize.y = this.initialSize.y;
1755
- break;
1756
- case KritzelHandleType.BottomRight:
1757
- this.newSize.width = this.initialSize.width + dx;
1758
- this.newSize.height = this.initialSize.height + dy;
1759
- this.newSize.x = this.initialSize.x;
1760
- this.newSize.y = this.initialSize.y;
1761
- break;
1762
- }
1763
- this._core.store.state.selectionGroup.resize(this.newSize.x, this.newSize.y, this.newSize.width, this.newSize.height);
1764
- clearTimeout(this._core.store.state.longTouchTimeout);
1765
- }
1766
- }
1767
- }
1768
- handlePointerUp(event) {
1769
- if (event.pointerType === 'mouse') {
1770
- if (this._core.store.state.isResizing) {
1771
- this._core.history.executeCommand(new ResizeSelectionGroupCommand(this._core, this, structuredClone(this.initialSize), structuredClone(this.newSize)));
1772
- this._core.store.state.isResizing = false;
1773
- this._core.store.state.hasObjectsChanged = true;
1774
- this.reset();
1775
- }
1776
- }
1777
- if (event.pointerType === 'touch') {
1778
- if (this._core.store.state.isResizing) {
1779
- this._core.history.executeCommand(new ResizeSelectionGroupCommand(this._core, this, structuredClone(this.initialSize), structuredClone(this.newSize)));
1780
- this._core.store.state.isResizing = false;
1781
- this._core.store.state.hasObjectsChanged = true;
1782
- this.reset();
1783
- clearTimeout(this._core.store.state.longTouchTimeout);
1784
- }
1785
- }
1786
- }
1787
- }
1788
-
1789
- class RotateSelectionGroupCommand extends KritzelBaseCommand {
1790
- rotation;
1791
- initialRotation;
1792
- selectionGroup;
1793
- constructor(core, initiator, rotation, initialRotation, skipHistory = false) {
1794
- super(core, initiator, skipHistory);
1795
- this.rotation = rotation;
1796
- this.initialRotation = initialRotation;
1797
- this.selectionGroup = this._core.store.state.selectionGroup;
1798
- }
1799
- execute() {
1800
- this._core.store.state.selectionGroup = this.selectionGroup;
1801
- this._core.store.state.selectionGroup.rotate(this.rotation);
1802
- this._core.store.state.selectionGroup.objects.forEach(object => {
1803
- this._core.store.state.objectsMap.update(object);
1804
- this._core.updateObjectInDatabase(object);
1805
- });
1806
- }
1807
- undo() {
1808
- this._core.store.state.selectionGroup = this.selectionGroup;
1809
- this._core.store.state.selectionGroup.rotate(this.initialRotation);
1810
- this._core.store.state.selectionGroup.objects.forEach(object => {
1811
- this._core.store.state.objectsMap.update(object);
1812
- this._core.updateObjectInDatabase(object);
1813
- });
1814
- }
1815
- }
1816
-
1817
- class KritzelRotationHandler extends KritzelBaseHandler {
1818
- initialRotation = 0;
1819
- rotation = 0;
1820
- unchangedObjects = [];
1821
- initialSelectionGroupRotation = 0;
1822
- constructor(core) {
1823
- super(core);
1824
- }
1825
- reset() {
1826
- this.initialRotation = 0;
1827
- this.rotation = 0;
1828
- this.unchangedObjects = [];
1829
- }
1830
- handlePointerDown(event) {
1831
- if (event.pointerType === 'mouse') {
1832
- if (KritzelEventHelper.isLeftClick(event)) {
1833
- if (this._core.store.state.selectionGroup && this._core.store.state.isRotationHandleSelected) {
1834
- const clientX = event.clientX - this._core.store.offsetX;
1835
- const clientY = event.clientY - this._core.store.offsetY;
1836
- this._core.store.state.isRotating = true;
1837
- const centerX = this._core.store.state.selectionGroup.translateX + this._core.store.state.selectionGroup.width / 2 / this._core.store.state.scale;
1838
- const centerY = this._core.store.state.selectionGroup.translateY + this._core.store.state.selectionGroup.height / 2 / this._core.store.state.scale;
1839
- const cursorX = (clientX - this._core.store.state.translateX) / this._core.store.state.scale;
1840
- const cursorY = (clientY - this._core.store.state.translateY) / this._core.store.state.scale;
1841
- this.initialSelectionGroupRotation = this._core.store.state.selectionGroup.rotation;
1842
- this.initialRotation = Math.atan2(centerY - cursorY, centerX - cursorX) - this._core.store.state.selectionGroup.rotation;
1843
- this.unchangedObjects = this._core.store.state.selectionGroup.objects.map(obj => obj.clone());
1844
- }
1845
- }
1846
- }
1847
- if (event.pointerType === 'touch') {
1848
- const activePointers = Array.from(this._core.store.state.pointers.values());
1849
- const firstTouch = activePointers[0];
1850
- if (!firstTouch) {
1851
- return;
1852
- }
1853
- if (activePointers.length === 1) {
1854
- if (this._core.store.state.selectionGroup && this._core.store.state.isRotationHandleSelected) {
1855
- const clientX = Math.round(firstTouch.clientX - this._core.store.offsetX);
1856
- const clientY = Math.round(firstTouch.clientY - this._core.store.offsetY);
1857
- this._core.store.state.isRotating = true;
1858
- const centerX = this._core.store.state.selectionGroup.translateX + this._core.store.state.selectionGroup.width / 2 / this._core.store.state.scale;
1859
- const centerY = this._core.store.state.selectionGroup.translateY + this._core.store.state.selectionGroup.height / 2 / this._core.store.state.scale;
1860
- const cursorX = (clientX - this._core.store.state.translateX) / this._core.store.state.scale;
1861
- const cursorY = (clientY - this._core.store.state.translateY) / this._core.store.state.scale;
1862
- this.initialSelectionGroupRotation = this._core.store.state.selectionGroup.rotation;
1863
- this.initialRotation = Math.atan2(centerY - cursorY, centerX - cursorX) - this._core.store.state.selectionGroup.rotation;
1864
- this.unchangedObjects = this._core.store.state.selectionGroup.objects.map(obj => obj.clone());
1865
- clearTimeout(this._core.store.state.longTouchTimeout);
1866
- }
1867
- }
1868
- }
1869
- }
1870
- handlePointerMove(event) {
1871
- if (event.pointerType === 'mouse') {
1872
- if (this._core.store.state.isRotating && this._core.store.state.selectionGroup) {
1873
- const clientX = event.clientX - this._core.store.offsetX;
1874
- const clientY = event.clientY - this._core.store.offsetY;
1875
- const groupCenterX = this._core.store.state.selectionGroup.translateX + this._core.store.state.selectionGroup.width / 2 / this._core.store.state.scale;
1876
- const groupCenterY = this._core.store.state.selectionGroup.translateY + this._core.store.state.selectionGroup.height / 2 / this._core.store.state.scale;
1877
- const cursorX = (clientX - this._core.store.state.translateX) / this._core.store.state.scale;
1878
- const cursorY = (clientY - this._core.store.state.translateY) / this._core.store.state.scale;
1879
- const currentRotation = Math.atan2(groupCenterY - cursorY, groupCenterX - cursorX);
1880
- this.rotation = currentRotation - this.initialRotation;
1881
- this._core.store.state.selectionGroup.rotate(this.rotation);
1882
- }
1883
- }
1884
- if (event.pointerType === 'touch') {
1885
- const activePointers = Array.from(this._core.store.state.pointers.values());
1886
- const firstTouch = activePointers[0];
1887
- if (!firstTouch) {
1888
- return;
1889
- }
1890
- if (this._core.store.state.isRotating && this._core.store.state.selectionGroup) {
1891
- const clientX = Math.round(firstTouch.clientX - this._core.store.offsetX);
1892
- const clientY = Math.round(firstTouch.clientY - this._core.store.offsetY);
1893
- const groupCenterX = this._core.store.state.selectionGroup.translateX + this._core.store.state.selectionGroup.width / 2 / this._core.store.state.scale;
1894
- const groupCenterY = this._core.store.state.selectionGroup.translateY + this._core.store.state.selectionGroup.height / 2 / this._core.store.state.scale;
1895
- const cursorX = (clientX - this._core.store.state.translateX) / this._core.store.state.scale;
1896
- const cursorY = (clientY - this._core.store.state.translateY) / this._core.store.state.scale;
1897
- const currentRotation = Math.atan2(groupCenterY - cursorY, groupCenterX - cursorX);
1898
- this.rotation = currentRotation - this.initialRotation;
1899
- this._core.store.state.selectionGroup.rotate(this.rotation);
1900
- clearTimeout(this._core.store.state.longTouchTimeout);
1901
- }
1902
- }
1903
- }
1904
- handlePointerUp(event) {
1905
- if (event.pointerType === 'mouse') {
1906
- if (this._core.store.state.isRotating) {
1907
- this._core.history.executeCommand(new RotateSelectionGroupCommand(this._core, this, this.rotation, this.initialSelectionGroupRotation));
1908
- this._core.store.state.isRotating = false;
1909
- this._core.store.state.hasObjectsChanged = true;
1910
- this.reset();
1911
- }
1912
- }
1913
- if (event.pointerType === 'touch') {
1914
- if (this._core.store.state.isRotating) {
1915
- this._core.history.executeCommand(new RotateSelectionGroupCommand(this._core, this, this.rotation, this.initialSelectionGroupRotation));
1916
- this._core.store.state.isRotating = false;
1917
- this._core.store.state.hasObjectsChanged = true;
1918
- this.reset();
1919
- clearTimeout(this._core.store.state.longTouchTimeout);
1920
- }
1921
- }
1922
- }
1923
- }
1924
-
1925
- class KrtizelSelectionBox extends KritzelBaseObject {
1926
- __class__ = 'KrtizelSelectionBox';
1927
- objects = [];
1928
- static create(core) {
1929
- const object = new KrtizelSelectionBox();
1930
- object._core = core;
1931
- object.id = object.generateId();
1932
- object.workspaceId = core.store.state.activeWorkspace.id;
1933
- object.scale = core.store.state.scale;
1934
- object.zIndex = 99999;
1935
- object.backgroundColor = 'var(--kritzel-selection-box-background-color, rgba(0, 122, 255, 0.2))';
1936
- object.borderColor = 'var(--kritzel-selection-box-border-color, rgba(0, 122, 255, 0.5))';
1937
- object.borderWidth = 2;
1938
- object.height = 0;
1939
- object.width = 0;
1940
- return object;
1941
- }
1942
- }
1943
-
1944
- class AddSelectionGroupCommand extends KritzelBaseCommand {
1945
- selectionGroup;
1946
- previousSelectionGroup;
1947
- constructor(core, initiator, selectionGroup, previousSelectionGroup, skipHistory = false) {
1948
- super(core, initiator, skipHistory);
1949
- this.selectionGroup = selectionGroup;
1950
- this.previousSelectionGroup = previousSelectionGroup || null;
1951
- }
1952
- execute() {
1953
- this._core.store.state.objectsMap.remove(object => object instanceof KrtizelSelectionBox || object instanceof KritzelSelectionGroup);
1954
- this._core.store.state.objectsMap.insert(this.selectionGroup);
1955
- this._core.store.state.selectionGroup = this.selectionGroup;
1956
- this._core.store.state.selectionBox = null;
1957
- }
1958
- undo() {
1959
- this._core.store.state.objectsMap.remove(object => object.id === this.selectionGroup.id);
1960
- this._core.store.state.selectionGroup = this.previousSelectionGroup;
1961
- this._core.store.state.selectionBox = null;
1962
- }
1963
- }
1964
-
1965
- class KritzelSelectionHandler extends KritzelBaseHandler {
1966
- startX;
1967
- startY;
1968
- touchStartX = 0;
1969
- touchStartY = 0;
1970
- touchStartTimeout = null;
1971
- get isSelectionClick() {
1972
- return this._core.store.state.selectionBox && this._core.store.state.selectionBox.width === 0 && this._core.store.state.selectionBox.height === 0;
1973
- }
1974
- get isSelectionDrag() {
1975
- return this._core.store.state.selectionBox && (this._core.store.state.selectionBox.width > 0 || this._core.store.state.selectionBox.height > 0);
1976
- }
1977
- constructor(core) {
1978
- super(core);
1979
- }
1980
- handlePointerDown(event) {
1981
- if (event.pointerType === 'mouse') {
1982
- if (KritzelEventHelper.isLeftClick(event) && !this._core.store.state.selectionGroup) {
1983
- this.startMouseSelection(event);
1984
- }
1985
- }
1986
- if (event.pointerType === 'touch') {
1987
- this.touchStartTimeout = setTimeout(() => {
1988
- if (this._core.store.state.pointers.size === 1 && !this._core.store.state.isScaling && !this._core.store.state.selectionGroup) {
1989
- this.startTouchSelection();
1990
- this.updateTouchSelection();
1991
- }
1992
- }, 80);
1993
- }
1994
- }
1995
- handlePointerMove(event) {
1996
- if (event.pointerType === 'mouse') {
1997
- if (this._core.store.state.isSelecting) {
1998
- this.updateMouseSelection(event);
1999
- }
2000
- }
2001
- if (event.pointerType === 'touch') {
2002
- const activePointers = Array.from(this._core.store.state.pointers.values());
2003
- const x = Math.round(activePointers[0].clientX - this._core.store.offsetX);
2004
- const y = Math.round(activePointers[0].clientY - this._core.store.offsetY);
2005
- const moveDeltaX = Math.abs(x - this.touchStartX);
2006
- const moveDeltaY = Math.abs(y - this.touchStartY);
2007
- const moveThreshold = 5;
2008
- if ((moveDeltaX > moveThreshold || moveDeltaY > moveThreshold) && this._core.store.state.isSelecting) {
2009
- this.updateTouchSelection();
2010
- clearTimeout(this._core.store.state.longTouchTimeout);
2011
- }
2012
- }
2013
- }
2014
- handlePointerUp(event) {
2015
- if (event.pointerType === 'mouse') {
2016
- if (KritzelEventHelper.isLeftClick(event)) {
2017
- const hasObjectsMoved = this._core.store.state.hasObjectsChanged;
2018
- if (this._core.store.state.selectionGroup?.objects.length === 1 && hasObjectsMoved === false) {
2019
- this._core.store.state.selectionGroup.objects[0].edit();
2020
- }
2021
- this._core.store.state.hasObjectsChanged = false;
2022
- if (this._core.store.state.isSelecting) {
2023
- if (this.isSelectionClick) {
2024
- this.handleSelectionClick(event);
2025
- }
2026
- if (this.isSelectionDrag) {
2027
- this.updateMouseSelection(event);
2028
- this.addSelectedObjectsToSelectionGroup();
2029
- this.removeSelectionBox();
2030
- }
2031
- }
2032
- }
2033
- }
2034
- if (event.pointerType === 'touch') {
2035
- clearTimeout(this.touchStartTimeout);
2036
- const hasObjectsMoved = this._core.store.state.hasObjectsChanged;
2037
- if (this._core.store.state.selectionGroup?.objects.length === 1 && hasObjectsMoved === false) {
2038
- this._core.store.state.selectionGroup.objects[0].edit();
2039
- }
2040
- this._core.store.state.hasObjectsChanged = false;
2041
- if (this._core.store.state.isSelecting) {
2042
- if (this.isSelectionClick) {
2043
- this.handleSelectionClick(event);
2044
- }
2045
- if (this.isSelectionDrag) {
2046
- this.updateTouchSelection();
2047
- this.addSelectedObjectsToSelectionGroup();
2048
- this.removeSelectionBox();
2049
- }
2050
- this._core.store.state.skipContextMenu = false;
2051
- }
2052
- }
2053
- }
2054
- removeSelectionBox() {
2055
- this._core.store.state.selectionBox = null;
2056
- this._core.store.state.isSelecting = false;
2057
- this._core.store.state.objectsMap.remove(o => o instanceof KrtizelSelectionBox);
2058
- }
2059
- startMouseSelection(event) {
2060
- let clientX, clientY;
2061
- clientX = event.clientX - this._core.store.offsetX;
2062
- clientY = event.clientY - this._core.store.offsetY;
2063
- const selectionBox = KrtizelSelectionBox.create(this._core);
2064
- this.startX = (clientX - this._core.store.state.translateX) / this._core.store.state.scale;
2065
- this.startY = (clientY - this._core.store.state.translateY) / this._core.store.state.scale;
2066
- selectionBox.translateX = this.startX;
2067
- selectionBox.translateY = this.startY;
2068
- this._core.store.state.selectionGroup = null;
2069
- this._core.store.state.selectionBox = selectionBox;
2070
- this._core.store.state.isSelecting = true;
2071
- this._core.store.state.objectsMap.remove(o => o instanceof KrtizelSelectionBox || o instanceof KritzelSelectionGroup);
2072
- this._core.store.state.objectsMap.insert(selectionBox);
2073
- }
2074
- startTouchSelection() {
2075
- const activePointers = Array.from(this._core.store.state.pointers.values());
2076
- const firstTouch = activePointers[0];
2077
- if (!firstTouch) {
2078
- return;
2079
- }
2080
- let clientX, clientY;
2081
- clientX = Math.round(firstTouch.clientX - this._core.store.offsetX);
2082
- clientY = Math.round(firstTouch.clientY - this._core.store.offsetY);
2083
- this.touchStartX = clientX;
2084
- this.touchStartY = clientY;
2085
- const selectionBox = KrtizelSelectionBox.create(this._core);
2086
- this.startX = (clientX - this._core.store.state.translateX) / this._core.store.state.scale;
2087
- this.startY = (clientY - this._core.store.state.translateY) / this._core.store.state.scale;
2088
- selectionBox.translateX = this.startX;
2089
- selectionBox.translateY = this.startY;
2090
- this._core.store.state.selectionGroup = null;
2091
- this._core.store.state.selectionBox = selectionBox;
2092
- this._core.store.state.isSelecting = true;
2093
- this._core.store.state.objectsMap.remove(o => o instanceof KrtizelSelectionBox || o instanceof KritzelSelectionGroup);
2094
- this._core.store.state.objectsMap.insert(selectionBox);
2095
- }
2096
- updateMouseSelection(event) {
2097
- let clientX, clientY;
2098
- clientX = event.clientX - this._core.store.offsetX;
2099
- clientY = event.clientY - this._core.store.offsetY;
2100
- const selectionBox = this._core.store.state.selectionBox;
2101
- if (selectionBox) {
2102
- const currentX = (clientX - this._core.store.state.translateX) / selectionBox.scale;
2103
- const currentY = (clientY - this._core.store.state.translateY) / selectionBox.scale;
2104
- const width = Math.abs(currentX - this.startX) * selectionBox.scale;
2105
- const height = Math.abs(currentY - this.startY) * selectionBox.scale;
2106
- selectionBox.width = width;
2107
- selectionBox.height = height;
2108
- selectionBox.translateX = Math.min(currentX, this.startX);
2109
- selectionBox.translateY = Math.min(currentY, this.startY);
2110
- if (width > 0 || height > 0) {
2111
- this.updateSelectedObjects();
2112
- }
2113
- else {
2114
- this.clearSelectionPreview();
2115
- }
2116
- }
2117
- }
2118
- updateTouchSelection() {
2119
- const activePointers = Array.from(this._core.store.state.pointers.values());
2120
- const firstTouch = activePointers[0];
2121
- if (!firstTouch) {
2122
- return;
2123
- }
2124
- let clientX, clientY;
2125
- clientX = Math.round(firstTouch.clientX - this._core.store.offsetX);
2126
- clientY = Math.round(firstTouch.clientY - this._core.store.offsetY);
2127
- const selectionBox = this._core.store.state.selectionBox;
2128
- if (selectionBox) {
2129
- const currentX = (clientX - this._core.store.state.translateX) / selectionBox.scale;
2130
- const currentY = (clientY - this._core.store.state.translateY) / selectionBox.scale;
2131
- const width = Math.abs(currentX - this.startX) * selectionBox.scale;
2132
- const height = Math.abs(currentY - this.startY) * selectionBox.scale;
2133
- selectionBox.width = width;
2134
- selectionBox.height = height;
2135
- selectionBox.translateX = Math.min(currentX, this.startX);
2136
- selectionBox.translateY = Math.min(currentY, this.startY);
2137
- if (width > 0 || height > 0) {
2138
- this.updateSelectedObjects();
2139
- }
2140
- else {
2141
- this.clearSelectionPreview();
2142
- }
2143
- }
2144
- }
2145
- updateSelectedObjects() {
2146
- this._core.store.allObjects
2147
- .filter(o => !(o instanceof KrtizelSelectionBox))
2148
- .forEach(object => (object.isSelected = object.hitTestPolygon(this._core.store.state.selectionBox.rotatedPolygon)));
2149
- }
2150
- handleSelectionClick(event) {
2151
- const selectedObject = this.getTopmostHitObject(event);
2152
- this.clearSelectionPreview();
2153
- this.addObjectToSelectionGroup(selectedObject);
2154
- this.removeSelectionBox();
2155
- }
2156
- getTopmostHitObject(event) {
2157
- const pointerX = this._core.store.state.pointerX;
2158
- const pointerY = this._core.store.state.pointerY;
2159
- const overlappingObjects = this._core.getObjectsFromPointerEvent(event, '.object');
2160
- for (const object of overlappingObjects) {
2161
- if (object.hitTest(pointerX, pointerY)) {
2162
- return object;
2163
- }
2164
- }
2165
- return null;
2166
- }
2167
- clearSelectionPreview() {
2168
- this._core.store.allNonSelectionObjects.forEach(object => {
2169
- object.isSelected = false;
2170
- });
2171
- }
2172
- addObjectToSelectionGroup(object) {
2173
- if (!object) {
2174
- return;
2175
- }
2176
- object.isSelected = false;
2177
- const selectionGroup = KritzelSelectionGroup.create(this._core);
2178
- selectionGroup.addOrRemove(object);
2179
- selectionGroup.isSelected = true;
2180
- selectionGroup.rotation = object.rotation;
2181
- this._core.history.executeCommand(new AddSelectionGroupCommand(this._core, this, selectionGroup));
2182
- }
2183
- addSelectedObjectsToSelectionGroup() {
2184
- const selectedObjects = this._core.store.selectedObjects;
2185
- if (selectedObjects.length === 0) {
2186
- return;
2187
- }
2188
- this._core.store.state.selectionGroup = KritzelSelectionGroup.create(this._core);
2189
- selectedObjects.forEach(o => {
2190
- this._core.store.state.selectionGroup.addOrRemove(o);
2191
- o.isSelected = false;
2192
- });
2193
- const selectionGroup = this._core.store.state.selectionGroup;
2194
- selectionGroup.isSelected = true;
2195
- if (selectionGroup.length === 1) {
2196
- selectionGroup.rotation = selectionGroup.objects[0].rotation;
2197
- }
2198
- this._core.history.executeCommand(new AddSelectionGroupCommand(this._core, this, selectionGroup));
2199
- }
2200
- }
2201
-
2202
- class KritzelHoverHandler extends KritzelBaseHandler {
2203
- constructor(core) {
2204
- super(core);
2205
- }
2206
- handlePointerMove(event) {
2207
- if (event.pointerType === 'mouse') {
2208
- const hoveredObject = this._core.getObjectFromPointerEvent(event, '.object');
2209
- if (!hoveredObject)
2210
- return;
2211
- const x = this._core.store.state.pointerX;
2212
- const y = this._core.store.state.pointerY;
2213
- hoveredObject.isHovered = hoveredObject.hitTest(x, y);
2214
- }
2215
- }
2216
- }
2217
-
2218
- class KritzelSelectionTool extends KritzelBaseTool {
2219
- selectionHandler;
2220
- moveHandler;
2221
- hoverHandler;
2222
- resizeHandler;
2223
- rotationHandler;
2224
- constructor(core) {
2225
- super(core);
2226
- this.selectionHandler = new KritzelSelectionHandler(this._core);
2227
- this.moveHandler = new KritzelMoveHandler(this._core);
2228
- this.hoverHandler = new KritzelHoverHandler(this._core);
2229
- this.resizeHandler = new KritzelResizeHandler(this._core);
2230
- this.rotationHandler = new KritzelRotationHandler(this._core);
2231
- }
2232
- handlePointerDown(event) {
2233
- if (event.cancelable) {
2234
- event.preventDefault();
2235
- }
2236
- if (event.pointerType === 'mouse') {
2237
- if (KritzelEventHelper.isLeftClick(event)) {
2238
- this._core.store.state.isResizeHandleSelected = this.isHandleSelected(event);
2239
- this._core.store.state.isRotationHandleSelected = this.isRotationHandleSelected(event);
2240
- this._core.store.state.resizeHandleType = this.getHandleType(event);
2241
- const selectedObject = this.getSelectedObject(event);
2242
- const isDifferentObject = selectedObject && this._core.store.state.selectionGroup && selectedObject.id !== this._core.store.state.selectionGroup.id;
2243
- if ((selectedObject === null || isDifferentObject) &&
2244
- this._core.store.state.selectionGroup &&
2245
- !this._core.store.state.isResizeHandleSelected &&
2246
- !this._core.store.state.isRotationHandleSelected) {
2247
- this._core.history.executeCommand(new RemoveSelectionGroupCommand(this._core, this._core.store.state.selectionGroup));
2248
- }
2249
- if (selectedObject && selectedObject.isSelected === false && selectedObject?.objects.length === 1 && selectedObject.objects[0].isInteractive) {
2250
- return;
2251
- }
2252
- }
2253
- this.moveHandler.handlePointerDown(event);
2254
- this.selectionHandler.handlePointerDown(event);
2255
- this.resizeHandler.handlePointerDown(event);
2256
- this.rotationHandler.handlePointerDown(event);
2257
- this._core.rerender();
2258
- }
2259
- if (event.pointerType === 'touch') {
2260
- if (this._core.store.state.isScaling === true) {
2261
- return;
2262
- }
2263
- if (this._core.store.state.pointers.size === 1) {
2264
- this._core.store.state.isResizeHandleSelected = this.isHandleSelected(event);
2265
- this._core.store.state.isRotationHandleSelected = this.isRotationHandleSelected(event);
2266
- this._core.store.state.resizeHandleType = this.getHandleType(event);
2267
- const selectedObject = this.getSelectedObject(event);
2268
- const isDifferentObject = selectedObject && this._core.store.state.selectionGroup && selectedObject.id !== this._core.store.state.selectionGroup.id;
2269
- if (!this._core.store.state.selectionGroup && selectedObject) {
2270
- this._core.store.state.skipContextMenu = true;
2271
- }
2272
- if ((selectedObject === null || isDifferentObject) &&
2273
- this._core.store.state.selectionGroup &&
2274
- !this._core.store.state.isResizeHandleSelected &&
2275
- !this._core.store.state.isRotationHandleSelected) {
2276
- this._core.history.executeCommand(new RemoveSelectionGroupCommand(this._core, this._core.store.state.selectionGroup));
2277
- }
2278
- }
2279
- this.rotationHandler.handlePointerDown(event);
2280
- this.resizeHandler.handlePointerDown(event);
2281
- this.moveHandler.handlePointerDown(event);
2282
- this.selectionHandler.handlePointerDown(event);
2283
- this._core.rerender();
2284
- }
2285
- }
2286
- handlePointerMove(event) {
2287
- if (event.cancelable) {
2288
- event.preventDefault();
2289
- }
2290
- if (event.pointerType === 'mouse') {
2291
- this.moveHandler.handlePointerMove(event);
2292
- this.hoverHandler.handlePointerMove(event);
2293
- this.selectionHandler.handlePointerMove(event);
2294
- this.resizeHandler.handlePointerMove(event);
2295
- this.rotationHandler.handlePointerMove(event);
2296
- this._core.rerender();
2297
- }
2298
- if (event.pointerType === 'touch') {
2299
- if (this._core.store.state.isScaling === true) {
2300
- return;
2301
- }
2302
- this.rotationHandler.handlePointerMove(event);
2303
- this.resizeHandler.handlePointerMove(event);
2304
- this.moveHandler.handlePointerMove(event);
2305
- this.selectionHandler.handlePointerMove(event);
2306
- this._core.rerender();
2307
- }
2308
- }
2309
- handlePointerUp(event) {
2310
- if (event.cancelable) {
2311
- event.preventDefault();
2312
- }
2313
- if (event.pointerType === 'mouse') {
2314
- this.moveHandler.handlePointerUp(event);
2315
- this.resizeHandler.handlePointerUp(event);
2316
- this.rotationHandler.handlePointerUp(event);
2317
- this.selectionHandler.handlePointerUp(event);
2318
- this._core.rerender();
2319
- }
2320
- if (event.pointerType === 'touch') {
2321
- if (this._core.store.state.isScaling === true) {
2322
- return;
2323
- }
2324
- this.rotationHandler.handlePointerUp(event);
2325
- this.resizeHandler.handlePointerUp(event);
2326
- this.moveHandler.handlePointerUp(event);
2327
- this.selectionHandler.handlePointerUp(event);
2328
- this._core.rerender();
2329
- }
2330
- }
2331
- getSelectedObject(event) {
2332
- const path = event.composedPath().slice(1);
2333
- const objectElement = path.find(element => element.classList && element.classList.contains('object'));
2334
- const object = this._core.findObjectById(objectElement?.id);
2335
- if (!object) {
2336
- return null;
2337
- }
2338
- if (object instanceof KritzelSelectionGroup) {
2339
- return object;
2340
- }
2341
- else {
2342
- const group = KritzelSelectionGroup.create(this._core);
2343
- group.translateX = 0;
2344
- group.translateY = 0;
2345
- group.addOrRemove(object);
2346
- return group;
2347
- }
2348
- }
2349
- getHandleType(event) {
2350
- const shadowRoot = this._core.store.state.host?.shadowRoot;
2351
- if (!shadowRoot)
2352
- return;
2353
- const elementAtPoint = shadowRoot.elementFromPoint(event.clientX, event.clientY);
2354
- const handle = elementAtPoint?.closest('.resize-handle-overlay');
2355
- return handle?.classList[1];
2356
- }
2357
- isHandleSelected(event) {
2358
- const shadowRoot = this._core.store.state.host?.shadowRoot;
2359
- if (!shadowRoot)
2360
- return false;
2361
- const elementAtPoint = shadowRoot.elementFromPoint(event.clientX, event.clientY);
2362
- return !!elementAtPoint?.classList.contains('resize-handle-overlay');
2363
- }
2364
- isRotationHandleSelected(event) {
2365
- const path = event.composedPath();
2366
- return !!path.find(element => element.classList && element.classList.contains('rotation-handle-overlay'));
2367
- }
2368
- }
2369
-
2370
- const DEFAULT_BRUSH_CONFIG = {
2371
- type: 'pen',
2372
- color: '#000000',
2373
- size: 16,
2374
- palettes: {
2375
- pen: [
2376
- '#000000',
2377
- '#ff5252',
2378
- '#ffbc00',
2379
- '#00c853',
2380
- '#0000FF',
2381
- '#d500f9',
2382
- '#fafafa',
2383
- '#a52714',
2384
- '#ee8100',
2385
- '#558b2f',
2386
- '#01579b',
2387
- '#8e24aa',
2388
- '#90a4ae',
2389
- '#ff4081',
2390
- '#ff6e40',
2391
- '#aeea00',
2392
- '#304ffe',
2393
- '#7c4dff',
2394
- '#cfd8dc',
2395
- '#f8bbd0',
2396
- '#ffccbc',
2397
- '#f0f4c3',
2398
- '#9fa8da',
2399
- '#d1c4e9',
2400
- ],
2401
- highlighter: [
2402
- '#0000006e',
2403
- '#ff52526e',
2404
- '#ffbb006e',
2405
- '#00c8536e',
2406
- '#0000FF6e',
2407
- '#d500f96e',
2408
- '#fafafa6e',
2409
- '#a527146e',
2410
- '#ee81006e',
2411
- '#558b2f6e',
2412
- '#01579b6e',
2413
- '#8e24aa6e',
2414
- '#90a4ae6e',
2415
- '#ff40816e',
2416
- '#ff6e406e',
2417
- '#aeea006e',
2418
- '#304ffe6e',
2419
- '#7c4dff6e',
2420
- '#cfd8dc6e',
2421
- '#f8bbd06e',
2422
- '#ffccbc6e',
2423
- '#f0f4c36e',
2424
- '#9fa8da6e',
2425
- '#d1c4e96e',
2426
- ],
2427
- },
2428
- };
2429
-
2430
- const DEFAULT_TEXT_CONFIG = {
2431
- color: '#000000',
2432
- size: 8,
2433
- fontFamily: 'Arial',
2434
- palette: [
2435
- '#000000',
2436
- '#ff5252',
2437
- '#ffbc00',
2438
- '#00c853',
2439
- '#0000FF',
2440
- '#d500f9',
2441
- '#fafafa',
2442
- '#a52714',
2443
- '#ee8100',
2444
- '#558b2f',
2445
- '#01579b',
2446
- '#8e24aa',
2447
- '#90a4ae',
2448
- '#ff4081',
2449
- '#ff6e40',
2450
- '#aeea00',
2451
- '#304ffe',
2452
- '#7c4dff',
2453
- '#cfd8dc',
2454
- '#f8bbd0',
2455
- '#ffccbc',
2456
- '#f0f4c3',
2457
- '#9fa8da',
2458
- '#d1c4e9',
2459
- ],
2460
- };
2461
-
2462
- class KritzelWorkspace {
2463
- __class__ = 'KritzelWorkspace';
2464
- id;
2465
- name;
2466
- createdAt;
2467
- updatedAt;
2468
- viewport;
2469
- _core;
2470
- constructor(id, name, viewport = { translateX: 0, translateY: 0, scale: 1 }) {
2471
- this.id = id;
2472
- this.name = name;
2473
- this.createdAt = new Date();
2474
- this.updatedAt = new Date();
2475
- this.viewport = viewport;
2476
- }
2477
- static create(core, obj) {
2478
- const workspace = new KritzelWorkspace(obj.id, obj.name, obj.viewport);
2479
- workspace._core = core;
2480
- Object.assign(workspace, obj);
2481
- return workspace;
2482
- }
2483
- addObject(obj) {
2484
- this._core.engine.addObject(obj);
2485
- }
2486
- serialize() {
2487
- return {
2488
- __class__: this.__class__,
2489
- id: this.id,
2490
- name: this.name,
2491
- createdAt: this.createdAt,
2492
- updatedAt: this.updatedAt,
2493
- viewport: this.viewport,
2494
- };
2495
- }
2496
- deserialize(object) {
2497
- Object.assign(this, object);
2498
- this.createdAt = new Date(object.createdAt);
2499
- this.updatedAt = new Date(object.updatedAt);
2500
- return this;
2501
- }
2502
- }
2503
-
2504
- class KritzelReviver {
2505
- _core;
2506
- constructor(core) {
2507
- this._core = core;
2508
- }
2509
- revive(obj) {
2510
- if (obj && typeof obj === 'object') {
2511
- if (obj.__class__) {
2512
- let revivedObj;
2513
- switch (obj.__class__) {
2514
- case 'KritzelPath':
2515
- revivedObj = KritzelPath.create(this._core).deserialize(obj);
2516
- break;
2517
- case 'KritzelText':
2518
- revivedObj = KritzelText.create(this._core, obj.fontSize, obj.fontFamily).deserialize(obj);
2519
- break;
2520
- case 'KritzelImage':
2521
- revivedObj = KritzelImage.create(this._core).deserialize(obj);
2522
- break;
2523
- case 'KritzelCustomElement':
2524
- revivedObj = KritzelCustomElement.create(this._core).deserialize(obj);
2525
- break;
2526
- case 'KritzelSelectionGroup':
2527
- revivedObj = KritzelSelectionGroup.create(this._core).deserialize(obj);
2528
- break;
2529
- case 'KritzelWorkspace':
2530
- revivedObj = KritzelWorkspace.create(this._core, obj).deserialize(obj);
2531
- break;
2532
- case 'KritzelBrushTool':
2533
- revivedObj = new KritzelBrushTool(this._core);
2534
- break;
2535
- case 'KritzelEraserTool':
2536
- revivedObj = new KritzelEraserTool(this._core);
2537
- break;
2538
- case 'KritzelImageTool':
2539
- revivedObj = new KritzelImageTool(this._core);
2540
- break;
2541
- case 'KritzelSelectionTool':
2542
- revivedObj = new KritzelSelectionTool(this._core);
2543
- break;
2544
- case 'KritzelTextTool':
2545
- revivedObj = new KritzelTextTool(this._core);
2546
- break;
2547
- default:
2548
- revivedObj = obj;
2549
- }
2550
- return revivedObj;
2551
- }
2552
- const newObj = Array.isArray(obj) ? [] : {};
2553
- for (const key in obj) {
2554
- if (Object.prototype.hasOwnProperty.call(obj, key)) {
2555
- newObj[key] = this.revive(obj[key]);
2556
- }
2557
- }
2558
- return newObj;
2559
- }
2560
- return obj;
2561
- }
2562
- }
2563
-
2564
- class KritzelSelectionGroup extends KritzelBaseObject {
2565
- __class__ = 'KritzelSelectionGroup';
2566
- objects = [];
2567
- unchangedObjects = [];
2568
- minX;
2569
- maxX;
2570
- minY;
2571
- maxY;
2572
- get length() {
2573
- return this.objects.length;
2574
- }
2575
- static create(core) {
2576
- const object = new KritzelSelectionGroup();
2577
- object._core = core;
2578
- object.id = object.generateId();
2579
- object.workspaceId = core.store.state.activeWorkspace.id;
2580
- object.scale = core.store.state.scale;
2581
- object.zIndex = 99999;
2582
- return object;
2583
- }
2584
- addOrRemove(object) {
2585
- const index = this.objects.findIndex(obj => obj.id === object.id);
2586
- if (index === -1) {
2587
- this.objects.push(object);
2588
- }
2589
- else {
2590
- this.objects.splice(index, 1);
2591
- }
2592
- this.unchangedObjects = this.objects.map(obj => obj.clone());
2593
- this.refreshObjectDimensions();
2594
- }
2595
- deselectAllChildren() {
2596
- this.objects.forEach(obj => (obj.isSelected = false));
2597
- }
2598
- updateWorkspaceId(workspaceId) {
2599
- this.workspaceId = workspaceId;
2600
- this.objects.forEach(obj => (obj.workspaceId = workspaceId));
2601
- }
2602
- updateZIndices(startZIndex) {
2603
- this.objects.forEach((obj, i) => {
2604
- obj.zIndex = startZIndex + i;
2605
- });
2606
- }
2607
- updatePosition(x, y) {
2608
- this.objects.forEach(obj => {
2609
- const deltaX = obj.translateX - this.translateX;
2610
- const deltaY = obj.translateY - this.translateY;
2611
- obj.updatePosition(x + deltaX, y + deltaY);
2612
- });
2613
- this.unchangedObjects.forEach(obj => {
2614
- const deltaX = obj.translateX - this.translateX;
2615
- const deltaY = obj.translateY - this.translateY;
2616
- obj.translateX = x + deltaX;
2617
- obj.translateY = y + deltaY;
2618
- });
2619
- this.translateX = x;
2620
- this.translateY = y;
2621
- this._core.store.state.objectsMap.update(this);
2622
- }
2623
- move(startX, startY, endX, endY) {
2624
- const deltaX = (startX - endX) / this._core.store.state.scale;
2625
- const deltaY = (startY - endY) / this._core.store.state.scale;
2626
- this.translateX += deltaX;
2627
- this.translateY += deltaY;
2628
- this._core.store.state.objectsMap.update(this);
2629
- this.objects.forEach(obj => {
2630
- obj.move(startX, startY, endX, endY);
2631
- this._core.store.state.objectsMap.update(obj);
2632
- });
2633
- this.unchangedObjects.forEach(obj => {
2634
- obj.translateX += deltaX;
2635
- obj.translateY += deltaY;
2636
- });
2637
- }
2638
- resize(x, y, width, height) {
2639
- const widthScaleFactor = width / this.width;
2640
- const heightScaleFactor = height / this.height;
2641
- const deltaX = x - this.translateX;
2642
- const deltaY = y - this.translateY;
2643
- this.objects.forEach(child => {
2644
- const updatedWidth = child.width * widthScaleFactor;
2645
- const updatedHeight = child.height * heightScaleFactor;
2646
- const updatedX = child.translateX + deltaX + (child.translateX - this.translateX) * (widthScaleFactor - 1);
2647
- const updatedY = child.translateY + deltaY + (child.translateY - this.translateY) * (heightScaleFactor - 1);
2648
- child.resize(updatedX, updatedY, updatedWidth, updatedHeight);
2649
- this._core.store.state.objectsMap.update(child);
2650
- });
2651
- this.refreshObjectDimensions();
2652
- this.unchangedObjects = this.objects.map(obj => obj.clone());
2653
- }
2654
- rotate(value) {
2655
- this.rotation = value;
2656
- const centerX = this.translateX + this.totalWidth / 2 / this.scale;
2657
- const centerY = this.translateY + this.totalHeight / 2 / this.scale;
2658
- const angle = value;
2659
- const cos = Math.cos(angle);
2660
- const sin = Math.sin(angle);
2661
- this.objects.forEach(child => {
2662
- const unchangedChild = this.getUnchangedObject(child.id);
2663
- const offsetX = this.getOffsetXToCenter(unchangedChild);
2664
- const offsetY = this.getOffsetYToCenter(unchangedChild);
2665
- const rotatedX = cos * offsetX - sin * offsetY;
2666
- const rotatedY = sin * offsetX + cos * offsetY;
2667
- child.translateX = centerX + rotatedX - child.totalWidth / 2 / child.scale;
2668
- child.translateY = centerY + rotatedY - child.totalHeight / 2 / child.scale;
2669
- child.rotate(this.objects.length === 1 ? value : value + unchangedChild.rotation);
2670
- this._core.store.state.objectsMap.update(child);
2671
- });
2672
- }
2673
- copy() {
2674
- const selectionGroup = KritzelSelectionGroup.create(this._core);
2675
- this.objects
2676
- .sort((a, b) => a.zIndex - b.zIndex)
2677
- .forEach(obj => {
2678
- const copiedObject = obj.copy();
2679
- selectionGroup.addOrRemove(copiedObject);
2680
- });
2681
- selectionGroup.unchangedObjects = selectionGroup.objects.map(obj => obj.clone());
2682
- if (this.objects.length === 1) {
2683
- selectionGroup.rotation = this.objects[0].rotation;
2684
- }
2685
- return selectionGroup;
2686
- }
2687
- refreshObjectDimensions() {
2688
- if (this.objects.length === 1) {
2689
- const obj = this.objects[0];
2690
- this.minX = obj.boundingBox.x / this.scale;
2691
- this.maxX = obj.boundingBox.x / this.scale + obj.boundingBox.width;
2692
- this.minY = obj.boundingBox.y / this.scale;
2693
- this.maxY = obj.boundingBox.y / this.scale + obj.boundingBox.height;
2694
- this.translateX = (this.minX - this.padding) * this.scale;
2695
- this.translateY = (this.minY - this.padding) * this.scale;
2696
- this.width = (this.maxX - this.minX - this.padding) * this.scale;
2697
- this.height = (this.maxY - this.minY - this.padding) * this.scale;
2698
- }
2699
- else {
2700
- this.minX = Math.min(...this.objects.map(obj => obj.minXRotated));
2701
- this.maxX = Math.max(...this.objects.map(obj => obj.maxXRotated));
2702
- this.minY = Math.min(...this.objects.map(obj => obj.minYRotated));
2703
- this.maxY = Math.max(...this.objects.map(obj => obj.maxYRotated));
2704
- this.translateX = this.minX - this.padding;
2705
- this.translateY = this.minY - this.padding;
2706
- this.width = (this.maxX - this.minX - this.padding) * this.scale;
2707
- this.height = (this.maxY - this.minY - this.padding) * this.scale;
2708
- }
2709
- this._core.store.state.objectsMap.update(this);
2710
- }
2711
- getOffsetXToCenter(obj) {
2712
- const objCenterX = obj.translateX + obj.totalWidth / obj.scale / 2;
2713
- const groupCenterX = this.translateX + this.totalWidth / this.scale / 2;
2714
- return objCenterX - groupCenterX;
2715
- }
2716
- getOffsetYToCenter(obj) {
2717
- const objCenterY = obj.translateY + obj.totalHeight / obj.scale / 2;
2718
- const groupCenterY = this.translateY + this.totalHeight / this.scale / 2;
2719
- return objCenterY - groupCenterY;
2720
- }
2721
- getUnchangedObject(objectId) {
2722
- const obj = this.unchangedObjects.find(obj => obj.id === objectId);
2723
- const reviver = new KritzelReviver(this._core);
2724
- return reviver.revive(obj);
2725
- }
2726
- }
2727
-
2728
- /**
2729
- * Browser Image Compression
2730
- * v2.0.2
2731
- * by Donald <donaldcwl@gmail.com>
2732
- * https://github.com/Donaldcwl/browser-image-compression
2733
- */
2734
-
2735
- function _mergeNamespaces(e,t){return t.forEach((function(t){t&&"string"!=typeof t&&!Array.isArray(t)&&Object.keys(t).forEach((function(r){if("default"!==r&&!(r in e)){var i=Object.getOwnPropertyDescriptor(t,r);Object.defineProperty(e,r,i.get?i:{enumerable:true,get:function(){return t[r]}});}}));})),Object.freeze(e)}function copyExifWithoutOrientation(e,t){return new Promise((function(r,i){let o;return getApp1Segment(e).then((function(e){try{return o=e,r(new Blob([t.slice(0,2),o,t.slice(2)],{type:"image/jpeg"}))}catch(e){return i(e)}}),i)}))}const getApp1Segment=e=>new Promise(((t,r)=>{const i=new FileReader;i.addEventListener("load",(({target:{result:e}})=>{const i=new DataView(e);let o=0;if(65496!==i.getUint16(o))return r("not a valid JPEG");for(o+=2;;){const a=i.getUint16(o);if(65498===a)break;const s=i.getUint16(o+2);if(65505===a&&1165519206===i.getUint32(o+4)){const a=o+10;let f;switch(i.getUint16(a)){case 18761:f=true;break;case 19789:f=false;break;default:return r("TIFF header contains invalid endian")}if(42!==i.getUint16(a+2,f))return r("TIFF header contains invalid version");const l=i.getUint32(a+4,f),c=a+l+2+12*i.getUint16(a+l,f);for(let e=a+l+2;e<c;e+=12){if(274==i.getUint16(e,f)){if(3!==i.getUint16(e+2,f))return r("Orientation data type is invalid");if(1!==i.getUint32(e+4,f))return r("Orientation data count is invalid");i.setUint16(e+8,1,f);break}}return t(e.slice(o,o+2+s))}o+=2+s;}return t(new Blob)})),i.readAsArrayBuffer(e);}));var e={},t={get exports(){return e},set exports(t){e=t;}};!function(e){var r,i,UZIP={};t.exports=UZIP,UZIP.parse=function(e,t){for(var r=UZIP.bin.readUshort,i=UZIP.bin.readUint,o=0,a={},s=new Uint8Array(e),f=s.length-4;101010256!=i(s,f);)f--;o=f;o+=4;var l=r(s,o+=4);r(s,o+=2);var c=i(s,o+=2),u=i(s,o+=4);o+=4,o=u;for(var h=0;h<l;h++){i(s,o),o+=4,o+=4,o+=4,i(s,o+=4);c=i(s,o+=4);var d=i(s,o+=4),A=r(s,o+=4),g=r(s,o+2),p=r(s,o+4);o+=6;var m=i(s,o+=8);o+=4,o+=A+g+p,UZIP._readLocal(s,m,a,c,d,t);}return a},UZIP._readLocal=function(e,t,r,i,o,a){var s=UZIP.bin.readUshort,f=UZIP.bin.readUint;f(e,t),s(e,t+=4),s(e,t+=2);var l=s(e,t+=2);f(e,t+=2),f(e,t+=4),t+=4;var c=s(e,t+=8),u=s(e,t+=2);t+=2;var h=UZIP.bin.readUTF8(e,t,c);if(t+=c,t+=u,a)r[h]={size:o,csize:i};else {var d=new Uint8Array(e.buffer,t);if(0==l)r[h]=new Uint8Array(d.buffer.slice(t,t+i));else {if(8!=l)throw "unknown compression method: "+l;var A=new Uint8Array(o);UZIP.inflateRaw(d,A),r[h]=A;}}},UZIP.inflateRaw=function(e,t){return UZIP.F.inflate(e,t)},UZIP.inflate=function(e,t){return UZIP.inflateRaw(new Uint8Array(e.buffer,e.byteOffset+2,e.length-6),t)},UZIP.deflate=function(e,t){null==t&&(t={level:6});var r=0,i=new Uint8Array(50+Math.floor(1.1*e.length));i[r]=120,i[r+1]=156,r+=2,r=UZIP.F.deflateRaw(e,i,r,t.level);var o=UZIP.adler(e,0,e.length);return i[r+0]=o>>>24&255,i[r+1]=o>>>16&255,i[r+2]=o>>>8&255,i[r+3]=o>>>0&255,new Uint8Array(i.buffer,0,r+4)},UZIP.deflateRaw=function(e,t){null==t&&(t={level:6});var r=new Uint8Array(50+Math.floor(1.1*e.length)),i=UZIP.F.deflateRaw(e,r,i,t.level);return new Uint8Array(r.buffer,0,i)},UZIP.encode=function(e,t){null==t&&(t=false);var r=0,i=UZIP.bin.writeUint,o=UZIP.bin.writeUshort,a={};for(var s in e){var f=!UZIP._noNeed(s)&&!t,l=e[s],c=UZIP.crc.crc(l,0,l.length);a[s]={cpr:f,usize:l.length,crc:c,file:f?UZIP.deflateRaw(l):l};}for(var s in a)r+=a[s].file.length+30+46+2*UZIP.bin.sizeUTF8(s);r+=22;var u=new Uint8Array(r),h=0,d=[];for(var s in a){var A=a[s];d.push(h),h=UZIP._writeHeader(u,h,s,A,0);}var g=0,p=h;for(var s in a){A=a[s];d.push(h),h=UZIP._writeHeader(u,h,s,A,1,d[g++]);}var m=h-p;return i(u,h,101010256),h+=4,o(u,h+=4,g),o(u,h+=2,g),i(u,h+=2,m),i(u,h+=4,p),h+=4,h+=2,u.buffer},UZIP._noNeed=function(e){var t=e.split(".").pop().toLowerCase();return -1!="png,jpg,jpeg,zip".indexOf(t)},UZIP._writeHeader=function(e,t,r,i,o,a){var s=UZIP.bin.writeUint,f=UZIP.bin.writeUshort,l=i.file;return s(e,t,0==o?67324752:33639248),t+=4,1==o&&(t+=2),f(e,t,20),f(e,t+=2,0),f(e,t+=2,i.cpr?8:0),s(e,t+=2,0),s(e,t+=4,i.crc),s(e,t+=4,l.length),s(e,t+=4,i.usize),f(e,t+=4,UZIP.bin.sizeUTF8(r)),f(e,t+=2,0),t+=2,1==o&&(t+=2,t+=2,s(e,t+=6,a),t+=4),t+=UZIP.bin.writeUTF8(e,t,r),0==o&&(e.set(l,t),t+=l.length),t},UZIP.crc={table:function(){for(var e=new Uint32Array(256),t=0;t<256;t++){for(var r=t,i=0;i<8;i++)1&r?r=3988292384^r>>>1:r>>>=1;e[t]=r;}return e}(),update:function(e,t,r,i){for(var o=0;o<i;o++)e=UZIP.crc.table[255&(e^t[r+o])]^e>>>8;return e},crc:function(e,t,r){return 4294967295^UZIP.crc.update(4294967295,e,t,r)}},UZIP.adler=function(e,t,r){for(var i=1,o=0,a=t,s=t+r;a<s;){for(var f=Math.min(a+5552,s);a<f;)o+=i+=e[a++];i%=65521,o%=65521;}return o<<16|i},UZIP.bin={readUshort:function(e,t){return e[t]|e[t+1]<<8},writeUshort:function(e,t,r){e[t]=255&r,e[t+1]=r>>8&255;},readUint:function(e,t){return 16777216*e[t+3]+(e[t+2]<<16|e[t+1]<<8|e[t])},writeUint:function(e,t,r){e[t]=255&r,e[t+1]=r>>8&255,e[t+2]=r>>16&255,e[t+3]=r>>24&255;},readASCII:function(e,t,r){for(var i="",o=0;o<r;o++)i+=String.fromCharCode(e[t+o]);return i},writeASCII:function(e,t,r){for(var i=0;i<r.length;i++)e[t+i]=r.charCodeAt(i);},pad:function(e){return e.length<2?"0"+e:e},readUTF8:function(e,t,r){for(var i,o="",a=0;a<r;a++)o+="%"+UZIP.bin.pad(e[t+a].toString(16));try{i=decodeURIComponent(o);}catch(i){return UZIP.bin.readASCII(e,t,r)}return i},writeUTF8:function(e,t,r){for(var i=r.length,o=0,a=0;a<i;a++){var s=r.charCodeAt(a);if(0==(4294967168&s))e[t+o]=s,o++;else if(0==(4294965248&s))e[t+o]=192|s>>6,e[t+o+1]=128|s>>0&63,o+=2;else if(0==(4294901760&s))e[t+o]=224|s>>12,e[t+o+1]=128|s>>6&63,e[t+o+2]=128|s>>0&63,o+=3;else {if(0!=(4292870144&s))throw "e";e[t+o]=240|s>>18,e[t+o+1]=128|s>>12&63,e[t+o+2]=128|s>>6&63,e[t+o+3]=128|s>>0&63,o+=4;}}return o},sizeUTF8:function(e){for(var t=e.length,r=0,i=0;i<t;i++){var o=e.charCodeAt(i);if(0==(4294967168&o))r++;else if(0==(4294965248&o))r+=2;else if(0==(4294901760&o))r+=3;else {if(0!=(4292870144&o))throw "e";r+=4;}}return r}},UZIP.F={},UZIP.F.deflateRaw=function(e,t,r,i){var o=[[0,0,0,0,0],[4,4,8,4,0],[4,5,16,8,0],[4,6,16,16,0],[4,10,16,32,0],[8,16,32,32,0],[8,16,128,128,0],[8,32,128,256,0],[32,128,258,1024,1],[32,258,258,4096,1]][i],a=UZIP.F.U,s=UZIP.F._goodIndex;var f=UZIP.F._putsE,l=0,c=r<<3,u=0,h=e.length;if(0==i){for(;l<h;){f(t,c,l+(_=Math.min(65535,h-l))==h?1:0),c=UZIP.F._copyExact(e,l,_,t,c+8),l+=_;}return c>>>3}var d=a.lits,A=a.strt,g=a.prev,p=0,m=0,w=0,v=0,b=0,y=0;for(h>2&&(A[y=UZIP.F._hash(e,0)]=0),l=0;l<h;l++){if(b=y,l+1<h-2){y=UZIP.F._hash(e,l+1);var E=l+1&32767;g[E]=A[y],A[y]=E;}if(u<=l){(p>14e3||m>26697)&&h-l>100&&(u<l&&(d[p]=l-u,p+=2,u=l),c=UZIP.F._writeBlock(l==h-1||u==h?1:0,d,p,v,e,w,l-w,t,c),p=m=v=0,w=l);var F=0;l<h-2&&(F=UZIP.F._bestMatch(e,l,g,b,Math.min(o[2],h-l),o[3]));var _=F>>>16,B=65535&F;if(0!=F){B=65535&F;var U=s(_=F>>>16,a.of0);a.lhst[257+U]++;var C=s(B,a.df0);a.dhst[C]++,v+=a.exb[U]+a.dxb[C],d[p]=_<<23|l-u,d[p+1]=B<<16|U<<8|C,p+=2,u=l+_;}else a.lhst[e[l]]++;m++;}}for(w==l&&0!=e.length||(u<l&&(d[p]=l-u,p+=2,u=l),c=UZIP.F._writeBlock(1,d,p,v,e,w,l-w,t,c),p=0,m=0,p=m=v=0,w=l);0!=(7&c);)c++;return c>>>3},UZIP.F._bestMatch=function(e,t,r,i,o,a){var s=32767&t,f=r[s],l=s-f+32768&32767;if(f==s||i!=UZIP.F._hash(e,t-l))return 0;for(var c=0,u=0,h=Math.min(32767,t);l<=h&&0!=--a&&f!=s;){if(0==c||e[t+c]==e[t+c-l]){var d=UZIP.F._howLong(e,t,l);if(d>c){if(u=l,(c=d)>=o)break;l+2<d&&(d=l+2);for(var A=0,g=0;g<d-2;g++){var p=t-l+g+32768&32767,m=p-r[p]+32768&32767;m>A&&(A=m,f=p);}}}l+=(s=f)-(f=r[s])+32768&32767;}return c<<16|u},UZIP.F._howLong=function(e,t,r){if(e[t]!=e[t-r]||e[t+1]!=e[t+1-r]||e[t+2]!=e[t+2-r])return 0;var i=t,o=Math.min(e.length,t+258);for(t+=3;t<o&&e[t]==e[t-r];)t++;return t-i},UZIP.F._hash=function(e,t){return (e[t]<<8|e[t+1])+(e[t+2]<<4)&65535},UZIP.saved=0,UZIP.F._writeBlock=function(e,t,r,i,o,a,s,f,l){var c,u,h,d,A,g,p,m,w,v=UZIP.F.U,b=UZIP.F._putsF,y=UZIP.F._putsE;v.lhst[256]++,u=(c=UZIP.F.getTrees())[0],h=c[1],d=c[2],A=c[3],g=c[4],p=c[5],m=c[6],w=c[7];var E=32+(0==(l+3&7)?0:8-(l+3&7))+(s<<3),F=i+UZIP.F.contSize(v.fltree,v.lhst)+UZIP.F.contSize(v.fdtree,v.dhst),_=i+UZIP.F.contSize(v.ltree,v.lhst)+UZIP.F.contSize(v.dtree,v.dhst);_+=14+3*p+UZIP.F.contSize(v.itree,v.ihst)+(2*v.ihst[16]+3*v.ihst[17]+7*v.ihst[18]);for(var B=0;B<286;B++)v.lhst[B]=0;for(B=0;B<30;B++)v.dhst[B]=0;for(B=0;B<19;B++)v.ihst[B]=0;var U=E<F&&E<_?0:F<_?1:2;if(b(f,l,e),b(f,l+1,U),l+=3,0==U){for(;0!=(7&l);)l++;l=UZIP.F._copyExact(o,a,s,f,l);}else {var C,I;if(1==U&&(C=v.fltree,I=v.fdtree),2==U){UZIP.F.makeCodes(v.ltree,u),UZIP.F.revCodes(v.ltree,u),UZIP.F.makeCodes(v.dtree,h),UZIP.F.revCodes(v.dtree,h),UZIP.F.makeCodes(v.itree,d),UZIP.F.revCodes(v.itree,d),C=v.ltree,I=v.dtree,y(f,l,A-257),y(f,l+=5,g-1),y(f,l+=5,p-4),l+=4;for(var Q=0;Q<p;Q++)y(f,l+3*Q,v.itree[1+(v.ordr[Q]<<1)]);l+=3*p,l=UZIP.F._codeTiny(m,v.itree,f,l),l=UZIP.F._codeTiny(w,v.itree,f,l);}for(var M=a,x=0;x<r;x+=2){for(var S=t[x],R=S>>>23,T=M+(8388607&S);M<T;)l=UZIP.F._writeLit(o[M++],C,f,l);if(0!=R){var O=t[x+1],P=O>>16,H=O>>8&255,L=255&O;y(f,l=UZIP.F._writeLit(257+H,C,f,l),R-v.of0[H]),l+=v.exb[H],b(f,l=UZIP.F._writeLit(L,I,f,l),P-v.df0[L]),l+=v.dxb[L],M+=R;}}l=UZIP.F._writeLit(256,C,f,l);}return l},UZIP.F._copyExact=function(e,t,r,i,o){var a=o>>>3;return i[a]=r,i[a+1]=r>>>8,i[a+2]=255-i[a],i[a+3]=255-i[a+1],a+=4,i.set(new Uint8Array(e.buffer,t,r),a),o+(r+4<<3)},UZIP.F.getTrees=function(){for(var e=UZIP.F.U,t=UZIP.F._hufTree(e.lhst,e.ltree,15),r=UZIP.F._hufTree(e.dhst,e.dtree,15),i=[],o=UZIP.F._lenCodes(e.ltree,i),a=[],s=UZIP.F._lenCodes(e.dtree,a),f=0;f<i.length;f+=2)e.ihst[i[f]]++;for(f=0;f<a.length;f+=2)e.ihst[a[f]]++;for(var l=UZIP.F._hufTree(e.ihst,e.itree,7),c=19;c>4&&0==e.itree[1+(e.ordr[c-1]<<1)];)c--;return [t,r,l,o,s,c,i,a]},UZIP.F.getSecond=function(e){for(var t=[],r=0;r<e.length;r+=2)t.push(e[r+1]);return t},UZIP.F.nonZero=function(e){for(var t="",r=0;r<e.length;r+=2)0!=e[r+1]&&(t+=(r>>1)+",");return t},UZIP.F.contSize=function(e,t){for(var r=0,i=0;i<t.length;i++)r+=t[i]*e[1+(i<<1)];return r},UZIP.F._codeTiny=function(e,t,r,i){for(var o=0;o<e.length;o+=2){var a=e[o],s=e[o+1];i=UZIP.F._writeLit(a,t,r,i);var f=16==a?2:17==a?3:7;a>15&&(UZIP.F._putsE(r,i,s,f),i+=f);}return i},UZIP.F._lenCodes=function(e,t){for(var r=e.length;2!=r&&0==e[r-1];)r-=2;for(var i=0;i<r;i+=2){var o=e[i+1],a=i+3<r?e[i+3]:-1,s=i+5<r?e[i+5]:-1,f=0==i?-1:e[i-1];if(0==o&&a==o&&s==o){for(var l=i+5;l+2<r&&e[l+2]==o;)l+=2;(c=Math.min(l+1-i>>>1,138))<11?t.push(17,c-3):t.push(18,c-11),i+=2*c-2;}else if(o==f&&a==o&&s==o){for(l=i+5;l+2<r&&e[l+2]==o;)l+=2;var c=Math.min(l+1-i>>>1,6);t.push(16,c-3),i+=2*c-2;}else t.push(o,0);}return r>>>1},UZIP.F._hufTree=function(e,t,r){var i=[],o=e.length,a=t.length,s=0;for(s=0;s<a;s+=2)t[s]=0,t[s+1]=0;for(s=0;s<o;s++)0!=e[s]&&i.push({lit:s,f:e[s]});var f=i.length,l=i.slice(0);if(0==f)return 0;if(1==f){var c=i[0].lit;l=0==c?1:0;return t[1+(c<<1)]=1,t[1+(l<<1)]=1,1}i.sort((function(e,t){return e.f-t.f}));var u=i[0],h=i[1],d=0,A=1,g=2;for(i[0]={lit:-1,f:u.f+h.f,l:u,r:h,d:0};A!=f-1;)u=d!=A&&(g==f||i[d].f<i[g].f)?i[d++]:i[g++],h=d!=A&&(g==f||i[d].f<i[g].f)?i[d++]:i[g++],i[A++]={lit:-1,f:u.f+h.f,l:u,r:h};var p=UZIP.F.setDepth(i[A-1],0);for(p>r&&(UZIP.F.restrictDepth(l,r,p),p=r),s=0;s<f;s++)t[1+(l[s].lit<<1)]=l[s].d;return p},UZIP.F.setDepth=function(e,t){return -1!=e.lit?(e.d=t,t):Math.max(UZIP.F.setDepth(e.l,t+1),UZIP.F.setDepth(e.r,t+1))},UZIP.F.restrictDepth=function(e,t,r){var i=0,o=1<<r-t,a=0;for(e.sort((function(e,t){return t.d==e.d?e.f-t.f:t.d-e.d})),i=0;i<e.length&&e[i].d>t;i++){var s=e[i].d;e[i].d=t,a+=o-(1<<r-s);}for(a>>>=r-t;a>0;){(s=e[i].d)<t?(e[i].d++,a-=1<<t-s-1):i++;}for(;i>=0;i--)e[i].d==t&&a<0&&(e[i].d--,a++);0!=a&&console.log("debt left");},UZIP.F._goodIndex=function(e,t){var r=0;return t[16|r]<=e&&(r|=16),t[8|r]<=e&&(r|=8),t[4|r]<=e&&(r|=4),t[2|r]<=e&&(r|=2),t[1|r]<=e&&(r|=1),r},UZIP.F._writeLit=function(e,t,r,i){return UZIP.F._putsF(r,i,t[e<<1]),i+t[1+(e<<1)]},UZIP.F.inflate=function(e,t){var r=Uint8Array;if(3==e[0]&&0==e[1])return t||new r(0);var i=UZIP.F,o=i._bitsF,a=i._bitsE,s=i._decodeTiny,f=i.makeCodes,l=i.codes2map,c=i._get17,u=i.U,h=null==t;h&&(t=new r(e.length>>>2<<3));for(var d,A,g=0,p=0,m=0,w=0,v=0,b=0,y=0,E=0,F=0;0==g;)if(g=o(e,F,1),p=o(e,F+1,2),F+=3,0!=p){if(h&&(t=UZIP.F._check(t,E+(1<<17))),1==p&&(d=u.flmap,A=u.fdmap,b=511,y=31),2==p){m=a(e,F,5)+257,w=a(e,F+5,5)+1,v=a(e,F+10,4)+4,F+=14;for(var _=0;_<38;_+=2)u.itree[_]=0,u.itree[_+1]=0;var B=1;for(_=0;_<v;_++){var U=a(e,F+3*_,3);u.itree[1+(u.ordr[_]<<1)]=U,U>B&&(B=U);}F+=3*v,f(u.itree,B),l(u.itree,B,u.imap),d=u.lmap,A=u.dmap,F=s(u.imap,(1<<B)-1,m+w,e,F,u.ttree);var C=i._copyOut(u.ttree,0,m,u.ltree);b=(1<<C)-1;var I=i._copyOut(u.ttree,m,w,u.dtree);y=(1<<I)-1,f(u.ltree,C),l(u.ltree,C,d),f(u.dtree,I),l(u.dtree,I,A);}for(;;){var Q=d[c(e,F)&b];F+=15&Q;var M=Q>>>4;if(M>>>8==0)t[E++]=M;else {if(256==M)break;var x=E+M-254;if(M>264){var S=u.ldef[M-257];x=E+(S>>>3)+a(e,F,7&S),F+=7&S;}var R=A[c(e,F)&y];F+=15&R;var T=R>>>4,O=u.ddef[T],P=(O>>>4)+o(e,F,15&O);for(F+=15&O,h&&(t=UZIP.F._check(t,E+(1<<17)));E<x;)t[E]=t[E++-P],t[E]=t[E++-P],t[E]=t[E++-P],t[E]=t[E++-P];E=x;}}}else {0!=(7&F)&&(F+=8-(7&F));var H=4+(F>>>3),L=e[H-4]|e[H-3]<<8;h&&(t=UZIP.F._check(t,E+L)),t.set(new r(e.buffer,e.byteOffset+H,L),E),F=H+L<<3,E+=L;}return t.length==E?t:t.slice(0,E)},UZIP.F._check=function(e,t){var r=e.length;if(t<=r)return e;var i=new Uint8Array(Math.max(r<<1,t));return i.set(e,0),i},UZIP.F._decodeTiny=function(e,t,r,i,o,a){for(var s=UZIP.F._bitsE,f=UZIP.F._get17,l=0;l<r;){var c=e[f(i,o)&t];o+=15&c;var u=c>>>4;if(u<=15)a[l]=u,l++;else {var h=0,d=0;16==u?(d=3+s(i,o,2),o+=2,h=a[l-1]):17==u?(d=3+s(i,o,3),o+=3):18==u&&(d=11+s(i,o,7),o+=7);for(var A=l+d;l<A;)a[l]=h,l++;}}return o},UZIP.F._copyOut=function(e,t,r,i){for(var o=0,a=0,s=i.length>>>1;a<r;){var f=e[a+t];i[a<<1]=0,i[1+(a<<1)]=f,f>o&&(o=f),a++;}for(;a<s;)i[a<<1]=0,i[1+(a<<1)]=0,a++;return o},UZIP.F.makeCodes=function(e,t){for(var r,i,o,a,s=UZIP.F.U,f=e.length,l=s.bl_count,c=0;c<=t;c++)l[c]=0;for(c=1;c<f;c+=2)l[e[c]]++;var u=s.next_code;for(r=0,l[0]=0,i=1;i<=t;i++)r=r+l[i-1]<<1,u[i]=r;for(o=0;o<f;o+=2)0!=(a=e[o+1])&&(e[o]=u[a],u[a]++);},UZIP.F.codes2map=function(e,t,r){for(var i=e.length,o=UZIP.F.U.rev15,a=0;a<i;a+=2)if(0!=e[a+1])for(var s=a>>1,f=e[a+1],l=s<<4|f,c=t-f,u=e[a]<<c,h=u+(1<<c);u!=h;){r[o[u]>>>15-t]=l,u++;}},UZIP.F.revCodes=function(e,t){for(var r=UZIP.F.U.rev15,i=15-t,o=0;o<e.length;o+=2){var a=e[o]<<t-e[o+1];e[o]=r[a]>>>i;}},UZIP.F._putsE=function(e,t,r){r<<=7&t;var i=t>>>3;e[i]|=r,e[i+1]|=r>>>8;},UZIP.F._putsF=function(e,t,r){r<<=7&t;var i=t>>>3;e[i]|=r,e[i+1]|=r>>>8,e[i+2]|=r>>>16;},UZIP.F._bitsE=function(e,t,r){return (e[t>>>3]|e[1+(t>>>3)]<<8)>>>(7&t)&(1<<r)-1},UZIP.F._bitsF=function(e,t,r){return (e[t>>>3]|e[1+(t>>>3)]<<8|e[2+(t>>>3)]<<16)>>>(7&t)&(1<<r)-1},UZIP.F._get17=function(e,t){return (e[t>>>3]|e[1+(t>>>3)]<<8|e[2+(t>>>3)]<<16)>>>(7&t)},UZIP.F._get25=function(e,t){return (e[t>>>3]|e[1+(t>>>3)]<<8|e[2+(t>>>3)]<<16|e[3+(t>>>3)]<<24)>>>(7&t)},UZIP.F.U=(r=Uint16Array,i=Uint32Array,{next_code:new r(16),bl_count:new r(16),ordr:[16,17,18,0,8,7,9,6,10,5,11,4,12,3,13,2,14,1,15],of0:[3,4,5,6,7,8,9,10,11,13,15,17,19,23,27,31,35,43,51,59,67,83,99,115,131,163,195,227,258,999,999,999],exb:[0,0,0,0,0,0,0,0,1,1,1,1,2,2,2,2,3,3,3,3,4,4,4,4,5,5,5,5,0,0,0,0],ldef:new r(32),df0:[1,2,3,4,5,7,9,13,17,25,33,49,65,97,129,193,257,385,513,769,1025,1537,2049,3073,4097,6145,8193,12289,16385,24577,65535,65535],dxb:[0,0,0,0,1,1,2,2,3,3,4,4,5,5,6,6,7,7,8,8,9,9,10,10,11,11,12,12,13,13,0,0],ddef:new i(32),flmap:new r(512),fltree:[],fdmap:new r(32),fdtree:[],lmap:new r(32768),ltree:[],ttree:[],dmap:new r(32768),dtree:[],imap:new r(512),itree:[],rev15:new r(32768),lhst:new i(286),dhst:new i(30),ihst:new i(19),lits:new i(15e3),strt:new r(65536),prev:new r(32768)}),function(){for(var e=UZIP.F.U,t=0;t<32768;t++){var r=t;r=(4278255360&(r=(4042322160&(r=(3435973836&(r=(2863311530&r)>>>1|(1431655765&r)<<1))>>>2|(858993459&r)<<2))>>>4|(252645135&r)<<4))>>>8|(16711935&r)<<8,e.rev15[t]=(r>>>16|r<<16)>>>17;}function pushV(e,t,r){for(;0!=t--;)e.push(0,r);}for(t=0;t<32;t++)e.ldef[t]=e.of0[t]<<3|e.exb[t],e.ddef[t]=e.df0[t]<<4|e.dxb[t];pushV(e.fltree,144,8),pushV(e.fltree,112,9),pushV(e.fltree,24,7),pushV(e.fltree,8,8),UZIP.F.makeCodes(e.fltree,9),UZIP.F.codes2map(e.fltree,9,e.flmap),UZIP.F.revCodes(e.fltree,9),pushV(e.fdtree,32,5),UZIP.F.makeCodes(e.fdtree,5),UZIP.F.codes2map(e.fdtree,5,e.fdmap),UZIP.F.revCodes(e.fdtree,5),pushV(e.itree,19,0),pushV(e.ltree,286,0),pushV(e.dtree,30,0),pushV(e.ttree,320,0);}();}();var UZIP=_mergeNamespaces({__proto__:null,default:e},[e]);const UPNG=function(){var e={nextZero(e,t){for(;0!=e[t];)t++;return t},readUshort:(e,t)=>e[t]<<8|e[t+1],writeUshort(e,t,r){e[t]=r>>8&255,e[t+1]=255&r;},readUint:(e,t)=>16777216*e[t]+(e[t+1]<<16|e[t+2]<<8|e[t+3]),writeUint(e,t,r){e[t]=r>>24&255,e[t+1]=r>>16&255,e[t+2]=r>>8&255,e[t+3]=255&r;},readASCII(e,t,r){let i="";for(let o=0;o<r;o++)i+=String.fromCharCode(e[t+o]);return i},writeASCII(e,t,r){for(let i=0;i<r.length;i++)e[t+i]=r.charCodeAt(i);},readBytes(e,t,r){const i=[];for(let o=0;o<r;o++)i.push(e[t+o]);return i},pad:e=>e.length<2?`0${e}`:e,readUTF8(t,r,i){let o,a="";for(let o=0;o<i;o++)a+=`%${e.pad(t[r+o].toString(16))}`;try{o=decodeURIComponent(a);}catch(o){return e.readASCII(t,r,i)}return o}};function decodeImage(t,r,i,o){const a=r*i,s=_getBPP(o),f=Math.ceil(r*s/8),l=new Uint8Array(4*a),c=new Uint32Array(l.buffer),{ctype:u}=o,{depth:h}=o,d=e.readUshort;if(6==u){const e=a<<2;if(8==h)for(var A=0;A<e;A+=4)l[A]=t[A],l[A+1]=t[A+1],l[A+2]=t[A+2],l[A+3]=t[A+3];if(16==h)for(A=0;A<e;A++)l[A]=t[A<<1];}else if(2==u){const e=o.tabs.tRNS;if(null==e){if(8==h)for(A=0;A<a;A++){var g=3*A;c[A]=255<<24|t[g+2]<<16|t[g+1]<<8|t[g];}if(16==h)for(A=0;A<a;A++){g=6*A;c[A]=255<<24|t[g+4]<<16|t[g+2]<<8|t[g];}}else {var p=e[0];const r=e[1],i=e[2];if(8==h)for(A=0;A<a;A++){var m=A<<2;g=3*A;c[A]=255<<24|t[g+2]<<16|t[g+1]<<8|t[g],t[g]==p&&t[g+1]==r&&t[g+2]==i&&(l[m+3]=0);}if(16==h)for(A=0;A<a;A++){m=A<<2,g=6*A;c[A]=255<<24|t[g+4]<<16|t[g+2]<<8|t[g],d(t,g)==p&&d(t,g+2)==r&&d(t,g+4)==i&&(l[m+3]=0);}}}else if(3==u){const e=o.tabs.PLTE,s=o.tabs.tRNS,c=s?s.length:0;if(1==h)for(var w=0;w<i;w++){var v=w*f,b=w*r;for(A=0;A<r;A++){m=b+A<<2;var y=3*(E=t[v+(A>>3)]>>7-((7&A)<<0)&1);l[m]=e[y],l[m+1]=e[y+1],l[m+2]=e[y+2],l[m+3]=E<c?s[E]:255;}}if(2==h)for(w=0;w<i;w++)for(v=w*f,b=w*r,A=0;A<r;A++){m=b+A<<2,y=3*(E=t[v+(A>>2)]>>6-((3&A)<<1)&3);l[m]=e[y],l[m+1]=e[y+1],l[m+2]=e[y+2],l[m+3]=E<c?s[E]:255;}if(4==h)for(w=0;w<i;w++)for(v=w*f,b=w*r,A=0;A<r;A++){m=b+A<<2,y=3*(E=t[v+(A>>1)]>>4-((1&A)<<2)&15);l[m]=e[y],l[m+1]=e[y+1],l[m+2]=e[y+2],l[m+3]=E<c?s[E]:255;}if(8==h)for(A=0;A<a;A++){var E;m=A<<2,y=3*(E=t[A]);l[m]=e[y],l[m+1]=e[y+1],l[m+2]=e[y+2],l[m+3]=E<c?s[E]:255;}}else if(4==u){if(8==h)for(A=0;A<a;A++){m=A<<2;var F=t[_=A<<1];l[m]=F,l[m+1]=F,l[m+2]=F,l[m+3]=t[_+1];}if(16==h)for(A=0;A<a;A++){var _;m=A<<2,F=t[_=A<<2];l[m]=F,l[m+1]=F,l[m+2]=F,l[m+3]=t[_+2];}}else if(0==u)for(p=o.tabs.tRNS?o.tabs.tRNS:-1,w=0;w<i;w++){const e=w*f,i=w*r;if(1==h)for(var B=0;B<r;B++){var U=(F=255*(t[e+(B>>>3)]>>>7-(7&B)&1))==255*p?0:255;c[i+B]=U<<24|F<<16|F<<8|F;}else if(2==h)for(B=0;B<r;B++){U=(F=85*(t[e+(B>>>2)]>>>6-((3&B)<<1)&3))==85*p?0:255;c[i+B]=U<<24|F<<16|F<<8|F;}else if(4==h)for(B=0;B<r;B++){U=(F=17*(t[e+(B>>>1)]>>>4-((1&B)<<2)&15))==17*p?0:255;c[i+B]=U<<24|F<<16|F<<8|F;}else if(8==h)for(B=0;B<r;B++){U=(F=t[e+B])==p?0:255;c[i+B]=U<<24|F<<16|F<<8|F;}else if(16==h)for(B=0;B<r;B++){F=t[e+(B<<1)],U=d(t,e+(B<<1))==p?0:255;c[i+B]=U<<24|F<<16|F<<8|F;}}return l}function _decompress(e,r,i,o){const a=_getBPP(e),s=Math.ceil(i*a/8),f=new Uint8Array((s+1+e.interlace)*o);return r=e.tabs.CgBI?t(r,f):_inflate(r,f),0==e.interlace?r=_filterZero(r,e,0,i,o):1==e.interlace&&(r=function _readInterlace(e,t){const r=t.width,i=t.height,o=_getBPP(t),a=o>>3,s=Math.ceil(r*o/8),f=new Uint8Array(i*s);let l=0;const c=[0,0,4,0,2,0,1],u=[0,4,0,2,0,1,0],h=[8,8,8,4,4,2,2],d=[8,8,4,4,2,2,1];let A=0;for(;A<7;){const p=h[A],m=d[A];let w=0,v=0,b=c[A];for(;b<i;)b+=p,v++;let y=u[A];for(;y<r;)y+=m,w++;const E=Math.ceil(w*o/8);_filterZero(e,t,l,w,v);let F=0,_=c[A];for(;_<i;){let t=u[A],i=l+F*E<<3;for(;t<r;){var g;if(1==o)g=(g=e[i>>3])>>7-(7&i)&1,f[_*s+(t>>3)]|=g<<7-((7&t)<<0);if(2==o)g=(g=e[i>>3])>>6-(7&i)&3,f[_*s+(t>>2)]|=g<<6-((3&t)<<1);if(4==o)g=(g=e[i>>3])>>4-(7&i)&15,f[_*s+(t>>1)]|=g<<4-((1&t)<<2);if(o>=8){const r=_*s+t*a;for(let t=0;t<a;t++)f[r+t]=e[(i>>3)+t];}i+=o,t+=m;}F++,_+=p;}w*v!=0&&(l+=v*(1+E)),A+=1;}return f}(r,e)),r}function _inflate(e,r){return t(new Uint8Array(e.buffer,2,e.length-6),r)}var t=function(){const e={H:{}};return e.H.N=function(t,r){const i=Uint8Array;let o,a,s=0,f=0,l=0,c=0,u=0,h=0,d=0,A=0,g=0;if(3==t[0]&&0==t[1])return r||new i(0);const p=e.H,m=p.b,w=p.e,v=p.R,b=p.n,y=p.A,E=p.Z,F=p.m,_=null==r;for(_&&(r=new i(t.length>>>2<<5));0==s;)if(s=m(t,g,1),f=m(t,g+1,2),g+=3,0!=f){if(_&&(r=e.H.W(r,A+(1<<17))),1==f&&(o=F.J,a=F.h,h=511,d=31),2==f){l=w(t,g,5)+257,c=w(t,g+5,5)+1,u=w(t,g+10,4)+4,g+=14;let e=1;for(var B=0;B<38;B+=2)F.Q[B]=0,F.Q[B+1]=0;for(B=0;B<u;B++){const r=w(t,g+3*B,3);F.Q[1+(F.X[B]<<1)]=r,r>e&&(e=r);}g+=3*u,b(F.Q,e),y(F.Q,e,F.u),o=F.w,a=F.d,g=v(F.u,(1<<e)-1,l+c,t,g,F.v);const r=p.V(F.v,0,l,F.C);h=(1<<r)-1;const i=p.V(F.v,l,c,F.D);d=(1<<i)-1,b(F.C,r),y(F.C,r,o),b(F.D,i),y(F.D,i,a);}for(;;){const e=o[E(t,g)&h];g+=15&e;const i=e>>>4;if(i>>>8==0)r[A++]=i;else {if(256==i)break;{let e=A+i-254;if(i>264){const r=F.q[i-257];e=A+(r>>>3)+w(t,g,7&r),g+=7&r;}const o=a[E(t,g)&d];g+=15&o;const s=o>>>4,f=F.c[s],l=(f>>>4)+m(t,g,15&f);for(g+=15&f;A<e;)r[A]=r[A++-l],r[A]=r[A++-l],r[A]=r[A++-l],r[A]=r[A++-l];A=e;}}}}else {0!=(7&g)&&(g+=8-(7&g));const o=4+(g>>>3),a=t[o-4]|t[o-3]<<8;_&&(r=e.H.W(r,A+a)),r.set(new i(t.buffer,t.byteOffset+o,a),A),g=o+a<<3,A+=a;}return r.length==A?r:r.slice(0,A)},e.H.W=function(e,t){const r=e.length;if(t<=r)return e;const i=new Uint8Array(r<<1);return i.set(e,0),i},e.H.R=function(t,r,i,o,a,s){const f=e.H.e,l=e.H.Z;let c=0;for(;c<i;){const e=t[l(o,a)&r];a+=15&e;const i=e>>>4;if(i<=15)s[c]=i,c++;else {let e=0,t=0;16==i?(t=3+f(o,a,2),a+=2,e=s[c-1]):17==i?(t=3+f(o,a,3),a+=3):18==i&&(t=11+f(o,a,7),a+=7);const r=c+t;for(;c<r;)s[c]=e,c++;}}return a},e.H.V=function(e,t,r,i){let o=0,a=0;const s=i.length>>>1;for(;a<r;){const r=e[a+t];i[a<<1]=0,i[1+(a<<1)]=r,r>o&&(o=r),a++;}for(;a<s;)i[a<<1]=0,i[1+(a<<1)]=0,a++;return o},e.H.n=function(t,r){const i=e.H.m,o=t.length;let a,s,f;let l;const c=i.j;for(var u=0;u<=r;u++)c[u]=0;for(u=1;u<o;u+=2)c[t[u]]++;const h=i.K;for(a=0,c[0]=0,s=1;s<=r;s++)a=a+c[s-1]<<1,h[s]=a;for(f=0;f<o;f+=2)l=t[f+1],0!=l&&(t[f]=h[l],h[l]++);},e.H.A=function(t,r,i){const o=t.length,a=e.H.m.r;for(let e=0;e<o;e+=2)if(0!=t[e+1]){const o=e>>1,s=t[e+1],f=o<<4|s,l=r-s;let c=t[e]<<l;const u=c+(1<<l);for(;c!=u;){i[a[c]>>>15-r]=f,c++;}}},e.H.l=function(t,r){const i=e.H.m.r,o=15-r;for(let e=0;e<t.length;e+=2){const a=t[e]<<r-t[e+1];t[e]=i[a]>>>o;}},e.H.M=function(e,t,r){r<<=7&t;const i=t>>>3;e[i]|=r,e[i+1]|=r>>>8;},e.H.I=function(e,t,r){r<<=7&t;const i=t>>>3;e[i]|=r,e[i+1]|=r>>>8,e[i+2]|=r>>>16;},e.H.e=function(e,t,r){return (e[t>>>3]|e[1+(t>>>3)]<<8)>>>(7&t)&(1<<r)-1},e.H.b=function(e,t,r){return (e[t>>>3]|e[1+(t>>>3)]<<8|e[2+(t>>>3)]<<16)>>>(7&t)&(1<<r)-1},e.H.Z=function(e,t){return (e[t>>>3]|e[1+(t>>>3)]<<8|e[2+(t>>>3)]<<16)>>>(7&t)},e.H.i=function(e,t){return (e[t>>>3]|e[1+(t>>>3)]<<8|e[2+(t>>>3)]<<16|e[3+(t>>>3)]<<24)>>>(7&t)},e.H.m=function(){const e=Uint16Array,t=Uint32Array;return {K:new e(16),j:new e(16),X:[16,17,18,0,8,7,9,6,10,5,11,4,12,3,13,2,14,1,15],S:[3,4,5,6,7,8,9,10,11,13,15,17,19,23,27,31,35,43,51,59,67,83,99,115,131,163,195,227,258,999,999,999],T:[0,0,0,0,0,0,0,0,1,1,1,1,2,2,2,2,3,3,3,3,4,4,4,4,5,5,5,5,0,0,0,0],q:new e(32),p:[1,2,3,4,5,7,9,13,17,25,33,49,65,97,129,193,257,385,513,769,1025,1537,2049,3073,4097,6145,8193,12289,16385,24577,65535,65535],z:[0,0,0,0,1,1,2,2,3,3,4,4,5,5,6,6,7,7,8,8,9,9,10,10,11,11,12,12,13,13,0,0],c:new t(32),J:new e(512),_:[],h:new e(32),$:[],w:new e(32768),C:[],v:[],d:new e(32768),D:[],u:new e(512),Q:[],r:new e(32768),s:new t(286),Y:new t(30),a:new t(19),t:new t(15e3),k:new e(65536),g:new e(32768)}}(),function(){const t=e.H.m;for(var r=0;r<32768;r++){let e=r;e=(2863311530&e)>>>1|(1431655765&e)<<1,e=(3435973836&e)>>>2|(858993459&e)<<2,e=(4042322160&e)>>>4|(252645135&e)<<4,e=(4278255360&e)>>>8|(16711935&e)<<8,t.r[r]=(e>>>16|e<<16)>>>17;}function n(e,t,r){for(;0!=t--;)e.push(0,r);}for(r=0;r<32;r++)t.q[r]=t.S[r]<<3|t.T[r],t.c[r]=t.p[r]<<4|t.z[r];n(t._,144,8),n(t._,112,9),n(t._,24,7),n(t._,8,8),e.H.n(t._,9),e.H.A(t._,9,t.J),e.H.l(t._,9),n(t.$,32,5),e.H.n(t.$,5),e.H.A(t.$,5,t.h),e.H.l(t.$,5),n(t.Q,19,0),n(t.C,286,0),n(t.D,30,0),n(t.v,320,0);}(),e.H.N}();function _getBPP(e){return [1,null,3,1,2,null,4][e.ctype]*e.depth}function _filterZero(e,t,r,i,o){let a=_getBPP(t);const s=Math.ceil(i*a/8);let f,l;a=Math.ceil(a/8);let c=e[r],u=0;if(c>1&&(e[r]=[0,0,1][c-2]),3==c)for(u=a;u<s;u++)e[u+1]=e[u+1]+(e[u+1-a]>>>1)&255;for(let t=0;t<o;t++)if(f=r+t*s,l=f+t+1,c=e[l-1],u=0,0==c)for(;u<s;u++)e[f+u]=e[l+u];else if(1==c){for(;u<a;u++)e[f+u]=e[l+u];for(;u<s;u++)e[f+u]=e[l+u]+e[f+u-a];}else if(2==c)for(;u<s;u++)e[f+u]=e[l+u]+e[f+u-s];else if(3==c){for(;u<a;u++)e[f+u]=e[l+u]+(e[f+u-s]>>>1);for(;u<s;u++)e[f+u]=e[l+u]+(e[f+u-s]+e[f+u-a]>>>1);}else {for(;u<a;u++)e[f+u]=e[l+u]+_paeth(0,e[f+u-s],0);for(;u<s;u++)e[f+u]=e[l+u]+_paeth(e[f+u-a],e[f+u-s],e[f+u-a-s]);}return e}function _paeth(e,t,r){const i=e+t-r,o=i-e,a=i-t,s=i-r;return o*o<=a*a&&o*o<=s*s?e:a*a<=s*s?t:r}function _IHDR(t,r,i){i.width=e.readUint(t,r),r+=4,i.height=e.readUint(t,r),r+=4,i.depth=t[r],r++,i.ctype=t[r],r++,i.compress=t[r],r++,i.filter=t[r],r++,i.interlace=t[r],r++;}function _copyTile(e,t,r,i,o,a,s,f,l){const c=Math.min(t,o),u=Math.min(r,a);let h=0,d=0;for(let r=0;r<u;r++)for(let a=0;a<c;a++)if(s>=0&&f>=0?(h=r*t+a<<2,d=(f+r)*o+s+a<<2):(h=(-f+r)*t-s+a<<2,d=r*o+a<<2),0==l)i[d]=e[h],i[d+1]=e[h+1],i[d+2]=e[h+2],i[d+3]=e[h+3];else if(1==l){var A=e[h+3]*(1/255),g=e[h]*A,p=e[h+1]*A,m=e[h+2]*A,w=i[d+3]*(1/255),v=i[d]*w,b=i[d+1]*w,y=i[d+2]*w;const t=1-A,r=A+w*t,o=0==r?0:1/r;i[d+3]=255*r,i[d+0]=(g+v*t)*o,i[d+1]=(p+b*t)*o,i[d+2]=(m+y*t)*o;}else if(2==l){A=e[h+3],g=e[h],p=e[h+1],m=e[h+2],w=i[d+3],v=i[d],b=i[d+1],y=i[d+2];A==w&&g==v&&p==b&&m==y?(i[d]=0,i[d+1]=0,i[d+2]=0,i[d+3]=0):(i[d]=g,i[d+1]=p,i[d+2]=m,i[d+3]=A);}else if(3==l){A=e[h+3],g=e[h],p=e[h+1],m=e[h+2],w=i[d+3],v=i[d],b=i[d+1],y=i[d+2];if(A==w&&g==v&&p==b&&m==y)continue;if(A<220&&w>20)return false}return true}return {decode:function decode(r){const i=new Uint8Array(r);let o=8;const a=e,s=a.readUshort,f=a.readUint,l={tabs:{},frames:[]},c=new Uint8Array(i.length);let u,h=0,d=0;const A=[137,80,78,71,13,10,26,10];for(var g=0;g<8;g++)if(i[g]!=A[g])throw "The input is not a PNG file!";for(;o<i.length;){const e=a.readUint(i,o);o+=4;const r=a.readASCII(i,o,4);if(o+=4,"IHDR"==r)_IHDR(i,o,l);else if("iCCP"==r){for(var p=o;0!=i[p];)p++;a.readASCII(i,o,p-o);const s=i.slice(p+2,o+e);let f=null;try{f=_inflate(s);}catch(e){f=t(s);}l.tabs[r]=f;}else if("CgBI"==r)l.tabs[r]=i.slice(o,o+4);else if("IDAT"==r){for(g=0;g<e;g++)c[h+g]=i[o+g];h+=e;}else if("acTL"==r)l.tabs[r]={num_frames:f(i,o),num_plays:f(i,o+4)},u=new Uint8Array(i.length);else if("fcTL"==r){if(0!=d)(E=l.frames[l.frames.length-1]).data=_decompress(l,u.slice(0,d),E.rect.width,E.rect.height),d=0;const e={x:f(i,o+12),y:f(i,o+16),width:f(i,o+4),height:f(i,o+8)};let t=s(i,o+22);t=s(i,o+20)/(0==t?100:t);const r={rect:e,delay:Math.round(1e3*t),dispose:i[o+24],blend:i[o+25]};l.frames.push(r);}else if("fdAT"==r){for(g=0;g<e-4;g++)u[d+g]=i[o+g+4];d+=e-4;}else if("pHYs"==r)l.tabs[r]=[a.readUint(i,o),a.readUint(i,o+4),i[o+8]];else if("cHRM"==r){l.tabs[r]=[];for(g=0;g<8;g++)l.tabs[r].push(a.readUint(i,o+4*g));}else if("tEXt"==r||"zTXt"==r){null==l.tabs[r]&&(l.tabs[r]={});var m=a.nextZero(i,o),w=a.readASCII(i,o,m-o),v=o+e-m-1;if("tEXt"==r)y=a.readASCII(i,m+1,v);else {var b=_inflate(i.slice(m+2,m+2+v));y=a.readUTF8(b,0,b.length);}l.tabs[r][w]=y;}else if("iTXt"==r){null==l.tabs[r]&&(l.tabs[r]={});m=0,p=o;m=a.nextZero(i,p);w=a.readASCII(i,p,m-p);const t=i[p=m+1];var y;p+=2,m=a.nextZero(i,p),a.readASCII(i,p,m-p),p=m+1,m=a.nextZero(i,p),a.readUTF8(i,p,m-p);v=e-((p=m+1)-o);if(0==t)y=a.readUTF8(i,p,v);else {b=_inflate(i.slice(p,p+v));y=a.readUTF8(b,0,b.length);}l.tabs[r][w]=y;}else if("PLTE"==r)l.tabs[r]=a.readBytes(i,o,e);else if("hIST"==r){const e=l.tabs.PLTE.length/3;l.tabs[r]=[];for(g=0;g<e;g++)l.tabs[r].push(s(i,o+2*g));}else if("tRNS"==r)3==l.ctype?l.tabs[r]=a.readBytes(i,o,e):0==l.ctype?l.tabs[r]=s(i,o):2==l.ctype&&(l.tabs[r]=[s(i,o),s(i,o+2),s(i,o+4)]);else if("gAMA"==r)l.tabs[r]=a.readUint(i,o)/1e5;else if("sRGB"==r)l.tabs[r]=i[o];else if("bKGD"==r)0==l.ctype||4==l.ctype?l.tabs[r]=[s(i,o)]:2==l.ctype||6==l.ctype?l.tabs[r]=[s(i,o),s(i,o+2),s(i,o+4)]:3==l.ctype&&(l.tabs[r]=i[o]);else if("IEND"==r)break;o+=e,a.readUint(i,o),o+=4;}var E;return 0!=d&&((E=l.frames[l.frames.length-1]).data=_decompress(l,u.slice(0,d),E.rect.width,E.rect.height)),l.data=_decompress(l,c,l.width,l.height),delete l.compress,delete l.interlace,delete l.filter,l},toRGBA8:function toRGBA8(e){const t=e.width,r=e.height;if(null==e.tabs.acTL)return [decodeImage(e.data,t,r,e).buffer];const i=[];null==e.frames[0].data&&(e.frames[0].data=e.data);const o=t*r*4,a=new Uint8Array(o),s=new Uint8Array(o),f=new Uint8Array(o);for(let c=0;c<e.frames.length;c++){const u=e.frames[c],h=u.rect.x,d=u.rect.y,A=u.rect.width,g=u.rect.height,p=decodeImage(u.data,A,g,e);if(0!=c)for(var l=0;l<o;l++)f[l]=a[l];if(0==u.blend?_copyTile(p,A,g,a,t,r,h,d,0):1==u.blend&&_copyTile(p,A,g,a,t,r,h,d,1),i.push(a.buffer.slice(0)),0==u.dispose);else if(1==u.dispose)_copyTile(s,A,g,a,t,r,h,d,0);else if(2==u.dispose)for(l=0;l<o;l++)a[l]=f[l];}return i},_paeth:_paeth,_copyTile:_copyTile,_bin:e}}();!function(){const{_copyTile:e}=UPNG,{_bin:t}=UPNG,r=UPNG._paeth;var i={table:function(){const e=new Uint32Array(256);for(let t=0;t<256;t++){let r=t;for(let e=0;e<8;e++)1&r?r=3988292384^r>>>1:r>>>=1;e[t]=r;}return e}(),update(e,t,r,o){for(let a=0;a<o;a++)e=i.table[255&(e^t[r+a])]^e>>>8;return e},crc:(e,t,r)=>4294967295^i.update(4294967295,e,t,r)};function addErr(e,t,r,i){t[r]+=e[0]*i>>4,t[r+1]+=e[1]*i>>4,t[r+2]+=e[2]*i>>4,t[r+3]+=e[3]*i>>4;}function N(e){return Math.max(0,Math.min(255,e))}function D(e,t){const r=e[0]-t[0],i=e[1]-t[1],o=e[2]-t[2],a=e[3]-t[3];return r*r+i*i+o*o+a*a}function dither(e,t,r,i,o,a,s){null==s&&(s=1);const f=i.length,l=[];for(var c=0;c<f;c++){const e=i[c];l.push([e>>>0&255,e>>>8&255,e>>>16&255,e>>>24&255]);}for(c=0;c<f;c++){let e=4294967295;for(var u=0,h=0;h<f;h++){var d=D(l[c],l[h]);h!=c&&d<e&&(e=d,u=h);}}const A=new Uint32Array(o.buffer),g=new Int16Array(t*r*4),p=[0,8,2,10,12,4,14,6,3,11,1,9,15,7,13,5];for(c=0;c<p.length;c++)p[c]=255*((p[c]+.5)/16-.5);for(let o=0;o<r;o++)for(let w=0;w<t;w++){var m;c=4*(o*t+w);if(2!=s)m=[N(e[c]+g[c]),N(e[c+1]+g[c+1]),N(e[c+2]+g[c+2]),N(e[c+3]+g[c+3])];else {d=p[4*(3&o)+(3&w)];m=[N(e[c]+d),N(e[c+1]+d),N(e[c+2]+d),N(e[c+3]+d)];}u=0;let v=16777215;for(h=0;h<f;h++){const e=D(m,l[h]);e<v&&(v=e,u=h);}const b=l[u],y=[m[0]-b[0],m[1]-b[1],m[2]-b[2],m[3]-b[3]];1==s&&(w!=t-1&&addErr(y,g,c+4,7),o!=r-1&&(0!=w&&addErr(y,g,c+4*t-4,3),addErr(y,g,c+4*t,5),w!=t-1&&addErr(y,g,c+4*t+4,1))),a[c>>2]=u,A[c>>2]=i[u];}}function _main(e,r,o,a,s){null==s&&(s={});const{crc:f}=i,l=t.writeUint,c=t.writeUshort,u=t.writeASCII;let h=8;const d=e.frames.length>1;let A,g=false,p=33+(d?20:0);if(null!=s.sRGB&&(p+=13),null!=s.pHYs&&(p+=21),null!=s.iCCP&&(A=pako.deflate(s.iCCP),p+=21+A.length+4),3==e.ctype){for(var m=e.plte.length,w=0;w<m;w++)e.plte[w]>>>24!=255&&(g=true);p+=8+3*m+4+(g?8+1*m+4:0);}for(var v=0;v<e.frames.length;v++){d&&(p+=38),p+=(F=e.frames[v]).cimg.length+12,0!=v&&(p+=4);}p+=12;const b=new Uint8Array(p),y=[137,80,78,71,13,10,26,10];for(w=0;w<8;w++)b[w]=y[w];if(l(b,h,13),h+=4,u(b,h,"IHDR"),h+=4,l(b,h,r),h+=4,l(b,h,o),h+=4,b[h]=e.depth,h++,b[h]=e.ctype,h++,b[h]=0,h++,b[h]=0,h++,b[h]=0,h++,l(b,h,f(b,h-17,17)),h+=4,null!=s.sRGB&&(l(b,h,1),h+=4,u(b,h,"sRGB"),h+=4,b[h]=s.sRGB,h++,l(b,h,f(b,h-5,5)),h+=4),null!=s.iCCP){const e=13+A.length;l(b,h,e),h+=4,u(b,h,"iCCP"),h+=4,u(b,h,"ICC profile"),h+=11,h+=2,b.set(A,h),h+=A.length,l(b,h,f(b,h-(e+4),e+4)),h+=4;}if(null!=s.pHYs&&(l(b,h,9),h+=4,u(b,h,"pHYs"),h+=4,l(b,h,s.pHYs[0]),h+=4,l(b,h,s.pHYs[1]),h+=4,b[h]=s.pHYs[2],h++,l(b,h,f(b,h-13,13)),h+=4),d&&(l(b,h,8),h+=4,u(b,h,"acTL"),h+=4,l(b,h,e.frames.length),h+=4,l(b,h,null!=s.loop?s.loop:0),h+=4,l(b,h,f(b,h-12,12)),h+=4),3==e.ctype){l(b,h,3*(m=e.plte.length)),h+=4,u(b,h,"PLTE"),h+=4;for(w=0;w<m;w++){const t=3*w,r=e.plte[w],i=255&r,o=r>>>8&255,a=r>>>16&255;b[h+t+0]=i,b[h+t+1]=o,b[h+t+2]=a;}if(h+=3*m,l(b,h,f(b,h-3*m-4,3*m+4)),h+=4,g){l(b,h,m),h+=4,u(b,h,"tRNS"),h+=4;for(w=0;w<m;w++)b[h+w]=e.plte[w]>>>24&255;h+=m,l(b,h,f(b,h-m-4,m+4)),h+=4;}}let E=0;for(v=0;v<e.frames.length;v++){var F=e.frames[v];d&&(l(b,h,26),h+=4,u(b,h,"fcTL"),h+=4,l(b,h,E++),h+=4,l(b,h,F.rect.width),h+=4,l(b,h,F.rect.height),h+=4,l(b,h,F.rect.x),h+=4,l(b,h,F.rect.y),h+=4,c(b,h,a[v]),h+=2,c(b,h,1e3),h+=2,b[h]=F.dispose,h++,b[h]=F.blend,h++,l(b,h,f(b,h-30,30)),h+=4);const t=F.cimg;l(b,h,(m=t.length)+(0==v?0:4)),h+=4;const r=h;u(b,h,0==v?"IDAT":"fdAT"),h+=4,0!=v&&(l(b,h,E++),h+=4),b.set(t,h),h+=m,l(b,h,f(b,r,h-r)),h+=4;}return l(b,h,0),h+=4,u(b,h,"IEND"),h+=4,l(b,h,f(b,h-4,4)),h+=4,b.buffer}function compressPNG(e,t,r){for(let i=0;i<e.frames.length;i++){const o=e.frames[i];const a=o.rect.height,s=new Uint8Array(a*o.bpl+a);o.cimg=_filterZero(o.img,a,o.bpp,o.bpl,s,t,r);}}function compress(t,r,i,o,a){const s=a[0],f=a[1],l=a[2],c=a[3],u=a[4],h=a[5];let d=6,A=8,g=255;for(var p=0;p<t.length;p++){const e=new Uint8Array(t[p]);for(var m=e.length,w=0;w<m;w+=4)g&=e[w+3];}const v=255!=g,b=function framize(t,r,i,o,a,s){const f=[];for(var l=0;l<t.length;l++){const h=new Uint8Array(t[l]),A=new Uint32Array(h.buffer);var c;let g=0,p=0,m=r,w=i,v=o?1:0;if(0!=l){const b=s||o||1==l||0!=f[l-2].dispose?1:2;let y=0,E=1e9;for(let e=0;e<b;e++){var u=new Uint8Array(t[l-1-e]);const o=new Uint32Array(t[l-1-e]);let s=r,f=i,c=-1,h=-1;for(let e=0;e<i;e++)for(let t=0;t<r;t++){A[d=e*r+t]!=o[d]&&(t<s&&(s=t),t>c&&(c=t),e<f&&(f=e),e>h&&(h=e));} -1==c&&(s=f=c=h=0),a&&(1==(1&s)&&s--,1==(1&f)&&f--);const v=(c-s+1)*(h-f+1);v<E&&(E=v,y=e,g=s,p=f,m=c-s+1,w=h-f+1);}u=new Uint8Array(t[l-1-y]);1==y&&(f[l-1].dispose=2),c=new Uint8Array(m*w*4),e(u,r,i,c,m,w,-g,-p,0),v=e(h,r,i,c,m,w,-g,-p,3)?1:0,1==v?_prepareDiff(h,r,i,c,{x:g,y:p,width:m,height:w}):e(h,r,i,c,m,w,-g,-p,0);}else c=h.slice(0);f.push({rect:{x:g,y:p,width:m,height:w},img:c,blend:v,dispose:0});}if(o)for(l=0;l<f.length;l++){if(1==(A=f[l]).blend)continue;const e=A.rect,o=f[l-1].rect,s=Math.min(e.x,o.x),c=Math.min(e.y,o.y),u={x:s,y:c,width:Math.max(e.x+e.width,o.x+o.width)-s,height:Math.max(e.y+e.height,o.y+o.height)-c};f[l-1].dispose=1,l-1!=0&&_updateFrame(t,r,i,f,l-1,u,a),_updateFrame(t,r,i,f,l,u,a);}let h=0;if(1!=t.length)for(var d=0;d<f.length;d++){var A;h+=(A=f[d]).rect.width*A.rect.height;}return f}(t,r,i,s,f,l),y={},E=[],F=[];if(0!=o){const e=[];for(w=0;w<b.length;w++)e.push(b[w].img.buffer);const t=function concatRGBA(e){let t=0;for(var r=0;r<e.length;r++)t+=e[r].byteLength;const i=new Uint8Array(t);let o=0;for(r=0;r<e.length;r++){const t=new Uint8Array(e[r]),a=t.length;for(let e=0;e<a;e+=4){let r=t[e],a=t[e+1],s=t[e+2];const f=t[e+3];0==f&&(r=a=s=0),i[o+e]=r,i[o+e+1]=a,i[o+e+2]=s,i[o+e+3]=f;}o+=a;}return i.buffer}(e),r=quantize(t,o);for(w=0;w<r.plte.length;w++)E.push(r.plte[w].est.rgba);let i=0;for(w=0;w<b.length;w++){const e=(B=b[w]).img.length;var _=new Uint8Array(r.inds.buffer,i>>2,e>>2);F.push(_);const t=new Uint8Array(r.abuf,i,e);h&&dither(B.img,B.rect.width,B.rect.height,E,t,_),B.img.set(t),i+=e;}}else for(p=0;p<b.length;p++){var B=b[p];const e=new Uint32Array(B.img.buffer);var U=B.rect.width;m=e.length,_=new Uint8Array(m);F.push(_);for(w=0;w<m;w++){const t=e[w];if(0!=w&&t==e[w-1])_[w]=_[w-1];else if(w>U&&t==e[w-U])_[w]=_[w-U];else {let e=y[t];if(null==e&&(y[t]=e=E.length,E.push(t),E.length>=300))break;_[w]=e;}}}const C=E.length;C<=256&&0==u&&(A=C<=2?1:C<=4?2:C<=16?4:8,A=Math.max(A,c));for(p=0;p<b.length;p++){(B=b[p]).rect.x;U=B.rect.width;const e=B.rect.height;let t=B.img;let r=4*U,i=4;if(C<=256&&0==u){r=Math.ceil(A*U/8);var I=new Uint8Array(r*e);const o=F[p];for(let t=0;t<e;t++){w=t*r;const e=t*U;if(8==A)for(var Q=0;Q<U;Q++)I[w+Q]=o[e+Q];else if(4==A)for(Q=0;Q<U;Q++)I[w+(Q>>1)]|=o[e+Q]<<4-4*(1&Q);else if(2==A)for(Q=0;Q<U;Q++)I[w+(Q>>2)]|=o[e+Q]<<6-2*(3&Q);else if(1==A)for(Q=0;Q<U;Q++)I[w+(Q>>3)]|=o[e+Q]<<7-1*(7&Q);}t=I,d=3,i=1;}else if(0==v&&1==b.length){I=new Uint8Array(U*e*3);const o=U*e;for(w=0;w<o;w++){const e=3*w,r=4*w;I[e]=t[r],I[e+1]=t[r+1],I[e+2]=t[r+2];}t=I,d=2,i=3,r=3*U;}B.img=t,B.bpl=r,B.bpp=i;}return {ctype:d,depth:A,plte:E,frames:b}}function _updateFrame(t,r,i,o,a,s,f){const l=Uint8Array,c=Uint32Array,u=new l(t[a-1]),h=new c(t[a-1]),d=a+1<t.length?new l(t[a+1]):null,A=new l(t[a]),g=new c(A.buffer);let p=r,m=i,w=-1,v=-1;for(let e=0;e<s.height;e++)for(let t=0;t<s.width;t++){const i=s.x+t,f=s.y+e,l=f*r+i,c=g[l];0==c||0==o[a-1].dispose&&h[l]==c&&(null==d||0!=d[4*l+3])||(i<p&&(p=i),i>w&&(w=i),f<m&&(m=f),f>v&&(v=f));} -1==w&&(p=m=w=v=0),f&&(1==(1&p)&&p--,1==(1&m)&&m--),s={x:p,y:m,width:w-p+1,height:v-m+1};const b=o[a];b.rect=s,b.blend=1,b.img=new Uint8Array(s.width*s.height*4),0==o[a-1].dispose?(e(u,r,i,b.img,s.width,s.height,-s.x,-s.y,0),_prepareDiff(A,r,i,b.img,s)):e(A,r,i,b.img,s.width,s.height,-s.x,-s.y,0);}function _prepareDiff(t,r,i,o,a){e(t,r,i,o,a.width,a.height,-a.x,-a.y,2);}function _filterZero(e,t,r,i,o,a,s){const f=[];let l,c=[0,1,2,3,4];-1!=a?c=[a]:(t*i>5e5||1==r)&&(c=[0]),s&&(l={level:0});const u=UZIP;for(var h=0;h<c.length;h++){for(let a=0;a<t;a++)_filterLine(o,e,a,i,r,c[h]);f.push(u.deflate(o,l));}let d,A=1e9;for(h=0;h<f.length;h++)f[h].length<A&&(d=h,A=f[h].length);return f[d]}function _filterLine(e,t,i,o,a,s){const f=i*o;let l=f+i;if(e[l]=s,l++,0==s)if(o<500)for(var c=0;c<o;c++)e[l+c]=t[f+c];else e.set(new Uint8Array(t.buffer,f,o),l);else if(1==s){for(c=0;c<a;c++)e[l+c]=t[f+c];for(c=a;c<o;c++)e[l+c]=t[f+c]-t[f+c-a]+256&255;}else if(0==i){for(c=0;c<a;c++)e[l+c]=t[f+c];if(2==s)for(c=a;c<o;c++)e[l+c]=t[f+c];if(3==s)for(c=a;c<o;c++)e[l+c]=t[f+c]-(t[f+c-a]>>1)+256&255;if(4==s)for(c=a;c<o;c++)e[l+c]=t[f+c]-r(t[f+c-a],0,0)+256&255;}else {if(2==s)for(c=0;c<o;c++)e[l+c]=t[f+c]+256-t[f+c-o]&255;if(3==s){for(c=0;c<a;c++)e[l+c]=t[f+c]+256-(t[f+c-o]>>1)&255;for(c=a;c<o;c++)e[l+c]=t[f+c]+256-(t[f+c-o]+t[f+c-a]>>1)&255;}if(4==s){for(c=0;c<a;c++)e[l+c]=t[f+c]+256-r(0,t[f+c-o],0)&255;for(c=a;c<o;c++)e[l+c]=t[f+c]+256-r(t[f+c-a],t[f+c-o],t[f+c-a-o])&255;}}}function quantize(e,t){const r=new Uint8Array(e),i=r.slice(0),o=new Uint32Array(i.buffer),a=getKDtree(i,t),s=a[0],f=a[1],l=r.length,c=new Uint8Array(l>>2);let u;if(r.length<2e7)for(var h=0;h<l;h+=4){u=getNearest(s,d=r[h]*(1/255),A=r[h+1]*(1/255),g=r[h+2]*(1/255),p=r[h+3]*(1/255)),c[h>>2]=u.ind,o[h>>2]=u.est.rgba;}else for(h=0;h<l;h+=4){var d=r[h]*(1/255),A=r[h+1]*(1/255),g=r[h+2]*(1/255),p=r[h+3]*(1/255);for(u=s;u.left;)u=planeDst(u.est,d,A,g,p)<=0?u.left:u.right;c[h>>2]=u.ind,o[h>>2]=u.est.rgba;}return {abuf:i.buffer,inds:c,plte:f}}function getKDtree(e,t,r){null==r&&(r=1e-4);const i=new Uint32Array(e.buffer),o={i0:0,i1:e.length,bst:null,est:null,tdst:0,left:null,right:null};o.bst=stats(e,o.i0,o.i1),o.est=estats(o.bst);const a=[o];for(;a.length<t;){let t=0,o=0;for(var s=0;s<a.length;s++)a[s].est.L>t&&(t=a[s].est.L,o=s);if(t<r)break;const f=a[o],l=splitPixels(e,i,f.i0,f.i1,f.est.e,f.est.eMq255);if(f.i0>=l||f.i1<=l){f.est.L=0;continue}const c={i0:f.i0,i1:l,bst:null,est:null,tdst:0,left:null,right:null};c.bst=stats(e,c.i0,c.i1),c.est=estats(c.bst);const u={i0:l,i1:f.i1,bst:null,est:null,tdst:0,left:null,right:null};u.bst={R:[],m:[],N:f.bst.N-c.bst.N};for(s=0;s<16;s++)u.bst.R[s]=f.bst.R[s]-c.bst.R[s];for(s=0;s<4;s++)u.bst.m[s]=f.bst.m[s]-c.bst.m[s];u.est=estats(u.bst),f.left=c,f.right=u,a[o]=c,a.push(u);}a.sort(((e,t)=>t.bst.N-e.bst.N));for(s=0;s<a.length;s++)a[s].ind=s;return [o,a]}function getNearest(e,t,r,i,o){if(null==e.left)return e.tdst=function dist(e,t,r,i,o){const a=t-e[0],s=r-e[1],f=i-e[2],l=o-e[3];return a*a+s*s+f*f+l*l}(e.est.q,t,r,i,o),e;const a=planeDst(e.est,t,r,i,o);let s=e.left,f=e.right;a>0&&(s=e.right,f=e.left);const l=getNearest(s,t,r,i,o);if(l.tdst<=a*a)return l;const c=getNearest(f,t,r,i,o);return c.tdst<l.tdst?c:l}function planeDst(e,t,r,i,o){const{e:a}=e;return a[0]*t+a[1]*r+a[2]*i+a[3]*o-e.eMq}function splitPixels(e,t,r,i,o,a){for(i-=4;r<i;){for(;vecDot(e,r,o)<=a;)r+=4;for(;vecDot(e,i,o)>a;)i-=4;if(r>=i)break;const s=t[r>>2];t[r>>2]=t[i>>2],t[i>>2]=s,r+=4,i-=4;}for(;vecDot(e,r,o)>a;)r-=4;return r+4}function vecDot(e,t,r){return e[t]*r[0]+e[t+1]*r[1]+e[t+2]*r[2]+e[t+3]*r[3]}function stats(e,t,r){const i=[0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0],o=[0,0,0,0],a=r-t>>2;for(let a=t;a<r;a+=4){const t=e[a]*(1/255),r=e[a+1]*(1/255),s=e[a+2]*(1/255),f=e[a+3]*(1/255);o[0]+=t,o[1]+=r,o[2]+=s,o[3]+=f,i[0]+=t*t,i[1]+=t*r,i[2]+=t*s,i[3]+=t*f,i[5]+=r*r,i[6]+=r*s,i[7]+=r*f,i[10]+=s*s,i[11]+=s*f,i[15]+=f*f;}return i[4]=i[1],i[8]=i[2],i[9]=i[6],i[12]=i[3],i[13]=i[7],i[14]=i[11],{R:i,m:o,N:a}}function estats(e){const{R:t}=e,{m:r}=e,{N:i}=e,a=r[0],s=r[1],f=r[2],l=r[3],c=0==i?0:1/i,u=[t[0]-a*a*c,t[1]-a*s*c,t[2]-a*f*c,t[3]-a*l*c,t[4]-s*a*c,t[5]-s*s*c,t[6]-s*f*c,t[7]-s*l*c,t[8]-f*a*c,t[9]-f*s*c,t[10]-f*f*c,t[11]-f*l*c,t[12]-l*a*c,t[13]-l*s*c,t[14]-l*f*c,t[15]-l*l*c],h=u,d=o;let A=[Math.random(),Math.random(),Math.random(),Math.random()],g=0,p=0;if(0!=i)for(let e=0;e<16&&(A=d.multVec(h,A),p=Math.sqrt(d.dot(A,A)),A=d.sml(1/p,A),!(0!=e&&Math.abs(p-g)<1e-9));e++)g=p;const m=[a*c,s*c,f*c,l*c];return {Cov:u,q:m,e:A,L:g,eMq255:d.dot(d.sml(255,m),A),eMq:d.dot(A,m),rgba:(Math.round(255*m[3])<<24|Math.round(255*m[2])<<16|Math.round(255*m[1])<<8|Math.round(255*m[0])<<0)>>>0}}var o={multVec:(e,t)=>[e[0]*t[0]+e[1]*t[1]+e[2]*t[2]+e[3]*t[3],e[4]*t[0]+e[5]*t[1]+e[6]*t[2]+e[7]*t[3],e[8]*t[0]+e[9]*t[1]+e[10]*t[2]+e[11]*t[3],e[12]*t[0]+e[13]*t[1]+e[14]*t[2]+e[15]*t[3]],dot:(e,t)=>e[0]*t[0]+e[1]*t[1]+e[2]*t[2]+e[3]*t[3],sml:(e,t)=>[e*t[0],e*t[1],e*t[2],e*t[3]]};UPNG.encode=function encode(e,t,r,i,o,a,s){null==i&&(i=0),null==s&&(s=false);const f=compress(e,t,r,i,[false,false,false,0,s,false]);return compressPNG(f,-1),_main(f,t,r,o,a)},UPNG.encodeLL=function encodeLL(e,t,r,i,o,a,s,f){const l={ctype:0+(1==i?0:2)+(0==o?0:4),depth:a,frames:[]},c=(i+o)*a,u=c*t;for(let i=0;i<e.length;i++)l.frames.push({rect:{x:0,y:0,width:t,height:r},img:new Uint8Array(e[i]),blend:0,dispose:1,bpp:Math.ceil(c/8),bpl:Math.ceil(u/8)});return compressPNG(l,0,true),_main(l,t,r,s,f)},UPNG.encode.compress=compress,UPNG.encode.dither=dither,UPNG.quantize=quantize,UPNG.quantize.getKDtree=getKDtree,UPNG.quantize.getNearest=getNearest;}();const r={toArrayBuffer(e,t){const i=e.width,o=e.height,a=i<<2,s=e.getContext("2d").getImageData(0,0,i,o),f=new Uint32Array(s.data.buffer),l=(32*i+31)/32<<2,c=l*o,u=122+c,h=new ArrayBuffer(u),d=new DataView(h),A=1<<20;let g,p,m,w,v=A,b=0,y=0,E=0;function set16(e){d.setUint16(y,e,true),y+=2;}function set32(e){d.setUint32(y,e,true),y+=4;}function seek(e){y+=e;}set16(19778),set32(u),seek(4),set32(122),set32(108),set32(i),set32(-o>>>0),set16(1),set16(32),set32(3),set32(c),set32(2835),set32(2835),seek(8),set32(16711680),set32(65280),set32(255),set32(4278190080),set32(1466527264),function convert(){for(;b<o&&v>0;){for(w=122+b*l,g=0;g<a;)v--,p=f[E++],m=p>>>24,d.setUint32(w+g,p<<8|m),g+=4;b++;}E<f.length?(v=A,setTimeout(convert,r._dly)):t(h);}();},toBlob(e,t){this.toArrayBuffer(e,(e=>{t(new Blob([e],{type:"image/bmp"}));}));},_dly:9};var i={CHROME:"CHROME",FIREFOX:"FIREFOX",DESKTOP_SAFARI:"DESKTOP_SAFARI",IE:"IE",IOS:"IOS",ETC:"ETC"},o={[i.CHROME]:16384,[i.FIREFOX]:11180,[i.DESKTOP_SAFARI]:16384,[i.IE]:8192,[i.IOS]:4096,[i.ETC]:8192};const a="undefined"!=typeof window,s="undefined"!=typeof WorkerGlobalScope&&self instanceof WorkerGlobalScope,f=a&&window.cordova&&window.cordova.require&&window.cordova.require("cordova/modulemapper"),CustomFile=(a||s)&&(f&&f.getOriginalSymbol(window,"File")||"undefined"!=typeof File&&File),CustomFileReader=(a||s)&&(f&&f.getOriginalSymbol(window,"FileReader")||"undefined"!=typeof FileReader&&FileReader);function getFilefromDataUrl(e,t,r=Date.now()){return new Promise((i=>{const o=e.split(","),a=o[0].match(/:(.*?);/)[1],s=globalThis.atob(o[1]);let f=s.length;const l=new Uint8Array(f);for(;f--;)l[f]=s.charCodeAt(f);const c=new Blob([l],{type:a});c.name=t,c.lastModified=r,i(c);}))}function getDataUrlFromFile(e){return new Promise(((t,r)=>{const i=new CustomFileReader;i.onload=()=>t(i.result),i.onerror=e=>r(e),i.readAsDataURL(e);}))}function loadImage(e){return new Promise(((t,r)=>{const i=new Image;i.onload=()=>t(i),i.onerror=e=>r(e),i.src=e;}))}function getBrowserName(){if(void 0!==getBrowserName.cachedResult)return getBrowserName.cachedResult;let e=i.ETC;const{userAgent:t}=navigator;return /Chrom(e|ium)/i.test(t)?e=i.CHROME:/iP(ad|od|hone)/i.test(t)&&/WebKit/i.test(t)?e=i.IOS:/Safari/i.test(t)?e=i.DESKTOP_SAFARI:/Firefox/i.test(t)?e=i.FIREFOX:(/MSIE/i.test(t)||true==!!document.documentMode)&&(e=i.IE),getBrowserName.cachedResult=e,getBrowserName.cachedResult}function approximateBelowMaximumCanvasSizeOfBrowser(e,t){const r=getBrowserName(),i=o[r];let a=e,s=t,f=a*s;const l=a>s?s/a:a/s;for(;f>i*i;){const e=(i+a)/2,t=(i+s)/2;e<t?(s=t,a=t*l):(s=e*l,a=e),f=a*s;}return {width:a,height:s}}function getNewCanvasAndCtx(e,t){let r,i;try{if(r=new OffscreenCanvas(e,t),i=r.getContext("2d"),null===i)throw new Error("getContext of OffscreenCanvas returns null")}catch(e){r=document.createElement("canvas"),i=r.getContext("2d");}return r.width=e,r.height=t,[r,i]}function drawImageInCanvas(e,t){const{width:r,height:i}=approximateBelowMaximumCanvasSizeOfBrowser(e.width,e.height),[o,a]=getNewCanvasAndCtx(r,i);return t&&/jpe?g/.test(t)&&(a.fillStyle="white",a.fillRect(0,0,o.width,o.height)),a.drawImage(e,0,0,o.width,o.height),o}function isIOS(){return void 0!==isIOS.cachedResult||(isIOS.cachedResult=["iPad Simulator","iPhone Simulator","iPod Simulator","iPad","iPhone","iPod"].includes(navigator.platform)||navigator.userAgent.includes("Mac")&&"undefined"!=typeof document&&"ontouchend"in document),isIOS.cachedResult}function drawFileInCanvas(e,t={}){return new Promise((function(r,o){let a,s;var $Try_2_Post=function(){try{return s=drawImageInCanvas(a,t.fileType||e.type),r([a,s])}catch(e){return o(e)}},$Try_2_Catch=function(t){try{var $Try_3_Catch=function(e){try{throw e}catch(e){return o(e)}};try{let t;return getDataUrlFromFile(e).then((function(e){try{return t=e,loadImage(t).then((function(e){try{return a=e,function(){try{return $Try_2_Post()}catch(e){return o(e)}}()}catch(e){return $Try_3_Catch(e)}}),$Try_3_Catch)}catch(e){return $Try_3_Catch(e)}}),$Try_3_Catch)}catch(e){$Try_3_Catch(e);}}catch(e){return o(e)}};try{if(isIOS()||[i.DESKTOP_SAFARI,i.MOBILE_SAFARI].includes(getBrowserName()))throw new Error("Skip createImageBitmap on IOS and Safari");return createImageBitmap(e).then((function(e){try{return a=e,$Try_2_Post()}catch(e){return $Try_2_Catch()}}),$Try_2_Catch)}catch(e){$Try_2_Catch();}}))}function canvasToFile(e,t,i,o,a=1){return new Promise((function(s,f){let l;if("image/png"===t){let c,u,h;return c=e.getContext("2d"),({data:u}=c.getImageData(0,0,e.width,e.height)),h=UPNG.encode([u.buffer],e.width,e.height,4096*a),l=new Blob([h],{type:t}),l.name=i,l.lastModified=o,$If_4.call(this)}{if("image/bmp"===t)return new Promise((t=>r.toBlob(e,t))).then(function(e){try{return l=e,l.name=i,l.lastModified=o,$If_5.call(this)}catch(e){return f(e)}}.bind(this),f);{if("function"==typeof OffscreenCanvas&&e instanceof OffscreenCanvas)return e.convertToBlob({type:t,quality:a}).then(function(e){try{return l=e,l.name=i,l.lastModified=o,$If_6.call(this)}catch(e){return f(e)}}.bind(this),f);{let d;return d=e.toDataURL(t,a),getFilefromDataUrl(d,i,o).then(function(e){try{return l=e,$If_6.call(this)}catch(e){return f(e)}}.bind(this),f)}function $If_6(){return $If_5.call(this)}}function $If_5(){return $If_4.call(this)}}function $If_4(){return s(l)}}))}function cleanupCanvasMemory(e){e.width=0,e.height=0;}function isAutoOrientationInBrowser(){return new Promise((function(e,t){let i,o,a,s;return void 0!==isAutoOrientationInBrowser.cachedResult?e(isAutoOrientationInBrowser.cachedResult):(getFilefromDataUrl("data:image/jpeg;base64,/9j/4QAiRXhpZgAATU0AKgAAAAgAAQESAAMAAAABAAYAAAAAAAD/2wCEAAEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAf/AABEIAAEAAgMBEQACEQEDEQH/xABKAAEAAAAAAAAAAAAAAAAAAAALEAEAAAAAAAAAAAAAAAAAAAAAAQEAAAAAAAAAAAAAAAAAAAAAEQEAAAAAAAAAAAAAAAAAAAAA/9oADAMBAAIRAxEAPwA/8H//2Q==","test.jpg",Date.now()).then((function(r){try{return i=r,drawFileInCanvas(i).then((function(r){try{return o=r[1],canvasToFile(o,i.type,i.name,i.lastModified).then((function(r){try{return a=r,cleanupCanvasMemory(o),drawFileInCanvas(a).then((function(r){try{return s=r[0],isAutoOrientationInBrowser.cachedResult=1===s.width&&2===s.height,e(isAutoOrientationInBrowser.cachedResult)}catch(e){return t(e)}}),t)}catch(e){return t(e)}}),t)}catch(e){return t(e)}}),t)}catch(e){return t(e)}}),t))}))}function getExifOrientation(e){return new Promise(((t,r)=>{const i=new CustomFileReader;i.onload=e=>{const r=new DataView(e.target.result);if(65496!=r.getUint16(0,false))return t(-2);const i=r.byteLength;let o=2;for(;o<i;){if(r.getUint16(o+2,false)<=8)return t(-1);const e=r.getUint16(o,false);if(o+=2,65505==e){if(1165519206!=r.getUint32(o+=2,false))return t(-1);const e=18761==r.getUint16(o+=6,false);o+=r.getUint32(o+4,e);const i=r.getUint16(o,e);o+=2;for(let a=0;a<i;a++)if(274==r.getUint16(o+12*a,e))return t(r.getUint16(o+12*a+8,e))}else {if(65280!=(65280&e))break;o+=r.getUint16(o,false);}}return t(-1)},i.onerror=e=>r(e),i.readAsArrayBuffer(e);}))}function handleMaxWidthOrHeight(e,t){const{width:r}=e,{height:i}=e,{maxWidthOrHeight:o}=t;let a,s=e;return isFinite(o)&&(r>o||i>o)&&([s,a]=getNewCanvasAndCtx(r,i),r>i?(s.width=o,s.height=i/r*o):(s.width=r/i*o,s.height=o),a.drawImage(e,0,0,s.width,s.height),cleanupCanvasMemory(e)),s}function followExifOrientation(e,t){const{width:r}=e,{height:i}=e,[o,a]=getNewCanvasAndCtx(r,i);switch(t>4&&t<9?(o.width=i,o.height=r):(o.width=r,o.height=i),t){case 2:a.transform(-1,0,0,1,r,0);break;case 3:a.transform(-1,0,0,-1,r,i);break;case 4:a.transform(1,0,0,-1,0,i);break;case 5:a.transform(0,1,1,0,0,0);break;case 6:a.transform(0,1,-1,0,i,0);break;case 7:a.transform(0,-1,-1,0,i,r);break;case 8:a.transform(0,-1,1,0,0,r);}return a.drawImage(e,0,0,r,i),cleanupCanvasMemory(e),o}function compress(e,t,r=0){return new Promise((function(i,o){let a,s,f,l,c,u,h,d,A,g,p,m,w,v,b,y,E,F,_,B;function incProgress(e=5){if(t.signal&&t.signal.aborted)throw t.signal.reason;a+=e,t.onProgress(Math.min(a,100));}function setProgress(e){if(t.signal&&t.signal.aborted)throw t.signal.reason;a=Math.min(Math.max(e,a),100),t.onProgress(a);}return a=r,s=t.maxIteration||10,f=1024*t.maxSizeMB*1024,incProgress(),drawFileInCanvas(e,t).then(function(r){try{return [,l]=r,incProgress(),c=handleMaxWidthOrHeight(l,t),incProgress(),new Promise((function(r,i){var o;if(!(o=t.exifOrientation))return getExifOrientation(e).then(function(e){try{return o=e,$If_2.call(this)}catch(e){return i(e)}}.bind(this),i);function $If_2(){return r(o)}return $If_2.call(this)})).then(function(r){try{return u=r,incProgress(),isAutoOrientationInBrowser().then(function(r){try{return h=r?c:followExifOrientation(c,u),incProgress(),d=t.initialQuality||1,A=t.fileType||e.type,canvasToFile(h,A,e.name,e.lastModified,d).then(function(r){try{{if(g=r,incProgress(),p=g.size>f,m=g.size>e.size,!p&&!m)return setProgress(100),i(g);var a;function $Loop_3(){if(s--&&(b>f||b>w)){let t,r;return t=B?.95*_.width:_.width,r=B?.95*_.height:_.height,[E,F]=getNewCanvasAndCtx(t,r),F.drawImage(_,0,0,t,r),d*="image/png"===A?.85:.95,canvasToFile(E,A,e.name,e.lastModified,d).then((function(e){try{return y=e,cleanupCanvasMemory(_),_=E,b=y.size,setProgress(Math.min(99,Math.floor((v-b)/(v-f)*100))),$Loop_3}catch(e){return o(e)}}),o)}return [1]}return w=e.size,v=g.size,b=v,_=h,B=!t.alwaysKeepResolution&&p,(a=function(e){for(;e;){if(e.then)return void e.then(a,o);try{if(e.pop){if(e.length)return e.pop()?$Loop_3_exit.call(this):e;e=$Loop_3;}else e=e.call(this);}catch(e){return o(e)}}}.bind(this))($Loop_3);function $Loop_3_exit(){return cleanupCanvasMemory(_),cleanupCanvasMemory(E),cleanupCanvasMemory(c),cleanupCanvasMemory(h),cleanupCanvasMemory(l),setProgress(100),i(y)}}}catch(u){return o(u)}}.bind(this),o)}catch(e){return o(e)}}.bind(this),o)}catch(e){return o(e)}}.bind(this),o)}catch(e){return o(e)}}.bind(this),o)}))}const l="\nlet scriptImported = false\nself.addEventListener('message', async (e) => {\n const { file, id, imageCompressionLibUrl, options } = e.data\n options.onProgress = (progress) => self.postMessage({ progress, id })\n try {\n if (!scriptImported) {\n // console.log('[worker] importScripts', imageCompressionLibUrl)\n self.importScripts(imageCompressionLibUrl)\n scriptImported = true\n }\n // console.log('[worker] self', self)\n const compressedFile = await imageCompression(file, options)\n self.postMessage({ file: compressedFile, id })\n } catch (e) {\n // console.error('[worker] error', e)\n self.postMessage({ error: e.message + '\\n' + e.stack, id })\n }\n})\n";let c;function compressOnWebWorker(e,t){return new Promise(((r,i)=>{c||(c=function createWorkerScriptURL(e){const t=[];return t.push(e),URL.createObjectURL(new Blob(t))}(l));const o=new Worker(c);o.addEventListener("message",(function handler(e){if(t.signal&&t.signal.aborted)o.terminate();else if(void 0===e.data.progress){if(e.data.error)return i(new Error(e.data.error)),void o.terminate();r(e.data.file),o.terminate();}else t.onProgress(e.data.progress);})),o.addEventListener("error",i),t.signal&&t.signal.addEventListener("abort",(()=>{i(t.signal.reason),o.terminate();})),o.postMessage({file:e,imageCompressionLibUrl:t.libURL,options:{...t,onProgress:void 0,signal:void 0}});}))}function imageCompression(e,t){return new Promise((function(r,i){let o,a,s,f,l,c;if(o={...t},s=0,({onProgress:f}=o),o.maxSizeMB=o.maxSizeMB||Number.POSITIVE_INFINITY,l="boolean"!=typeof o.useWebWorker||o.useWebWorker,delete o.useWebWorker,o.onProgress=e=>{s=e,"function"==typeof f&&f(s);},!(e instanceof Blob||e instanceof CustomFile))return i(new Error("The file given is not an instance of Blob or File"));if(!/^image/.test(e.type))return i(new Error("The file given is not an image"));if(c="undefined"!=typeof WorkerGlobalScope&&self instanceof WorkerGlobalScope,!l||"function"!=typeof Worker||c)return compress(e,o).then(function(e){try{return a=e,$If_4.call(this)}catch(e){return i(e)}}.bind(this),i);var u=function(){try{return $If_4.call(this)}catch(e){return i(e)}}.bind(this),$Try_1_Catch=function(t){try{return compress(e,o).then((function(e){try{return a=e,u()}catch(e){return i(e)}}),i)}catch(e){return i(e)}};try{return o.libURL=o.libURL||"https://cdn.jsdelivr.net/npm/browser-image-compression@2.0.2/dist/browser-image-compression.js",compressOnWebWorker(e,o).then((function(e){try{return a=e,u()}catch(e){return $Try_1_Catch()}}),$Try_1_Catch)}catch(e){$Try_1_Catch();}function $If_4(){try{a.name=e.name,a.lastModified=e.lastModified;}catch(e){}try{o.preserveExif&&"image/jpeg"===e.type&&(!o.fileType||o.fileType&&o.fileType===e.type)&&(a=copyExifWithoutOrientation(e,a));}catch(e){}return r(a)}}))}imageCompression.getDataUrlFromFile=getDataUrlFromFile,imageCompression.getFilefromDataUrl=getFilefromDataUrl,imageCompression.loadImage=loadImage,imageCompression.drawImageInCanvas=drawImageInCanvas,imageCompression.drawFileInCanvas=drawFileInCanvas,imageCompression.canvasToFile=canvasToFile,imageCompression.getExifOrientation=getExifOrientation,imageCompression.handleMaxWidthOrHeight=handleMaxWidthOrHeight,imageCompression.followExifOrientation=followExifOrientation,imageCompression.cleanupCanvasMemory=cleanupCanvasMemory,imageCompression.isAutoOrientationInBrowser=isAutoOrientationInBrowser,imageCompression.approximateBelowMaximumCanvasSizeOfBrowser=approximateBelowMaximumCanvasSizeOfBrowser,imageCompression.copyExifWithoutOrientation=copyExifWithoutOrientation,imageCompression.getBrowserName=getBrowserName,imageCompression.version="2.0.2";
2736
-
2737
- class KritzelImageTool extends KritzelBaseTool {
2738
- fileInput = null;
2739
- maxCompressionSize = 300;
2740
- constructor(core) {
2741
- super(core);
2742
- this.setupFileInput();
2743
- }
2744
- onActivate() {
2745
- this.openFilePicker();
2746
- }
2747
- openFilePicker() {
2748
- if (this._core.store.isDisabled) {
2749
- return;
2750
- }
2751
- this.fileInput.click();
2752
- }
2753
- setupFileInput() {
2754
- this.fileInput = document.createElement('input');
2755
- this.fileInput.type = 'file';
2756
- this.fileInput.accept = 'image/*';
2757
- this.fileInput.style.display = 'none';
2758
- this.fileInput.addEventListener('change', this.handleFileSelect.bind(this));
2759
- this.fileInput.addEventListener('cancel', this.handleCancel.bind(this));
2760
- document.body.appendChild(this.fileInput);
2761
- }
2762
- handleFileSelect(event) {
2763
- const input = event.target;
2764
- if (input.files && input.files[0]) {
2765
- const file = input.files[0];
2766
- imageCompression(file, {
2767
- maxWidthOrHeight: this.maxCompressionSize,
2768
- })
2769
- .then(compressedFile => {
2770
- this.readFile(compressedFile);
2771
- })
2772
- .catch(error => {
2773
- console.error('Error during image compression or processing:', error);
2774
- this.handleCancel();
2775
- });
2776
- }
2777
- else {
2778
- console.info('File selection cancelled by user.');
2779
- this.handleCancel();
2780
- }
2781
- if (input) {
2782
- input.value = '';
2783
- }
2784
- }
2785
- readFile(file) {
2786
- const reader = new FileReader();
2787
- reader.onload = e => {
2788
- const img = new Image();
2789
- img.src = e.target?.result;
2790
- img.onload = () => this.createKritzelImage(img);
2791
- };
2792
- reader.readAsDataURL(file);
2793
- }
2794
- createKritzelImage(img) {
2795
- const image = KritzelImage.create(this._core);
2796
- const { scaledWidth, scaledHeight } = image.calculateScaledDimensions(img);
2797
- image.src = img.src;
2798
- image.width = scaledWidth;
2799
- image.height = scaledHeight;
2800
- image.zIndex = this._core.store.currentZIndex;
2801
- image.centerInViewport();
2802
- this.addImageToStore(image);
2803
- return image;
2804
- }
2805
- addImageToStore(image) {
2806
- const selectionGroup = KritzelSelectionGroup.create(this._core);
2807
- selectionGroup.addOrRemove(image);
2808
- selectionGroup.isSelected = true;
2809
- const addImageCommand = new AddObjectCommand(this._core, this, image);
2810
- const addSelectionGroupCommand = new AddSelectionGroupCommand(this._core, this, selectionGroup);
2811
- this._core.history.executeCommand(new BatchCommand(this._core, this, [addImageCommand, addSelectionGroupCommand]));
2812
- this._core.store.setState('activeTool', KritzelToolRegistry.getTool('selection'));
2813
- }
2814
- handleCancel() {
2815
- this._core.store.setState('activeTool', KritzelToolRegistry.getTool('selection'));
2816
- }
2817
- }
2818
-
2819
- export { AddSelectionGroupCommand as A, BatchCommand as B, DEFAULT_BRUSH_CONFIG as D, KritzelBrushTool as K, ObjectHelper as O, RemoveSelectionGroupCommand as R, UpdateObjectCommand as U, KritzelTextTool as a, KritzelMouseButton as b, KritzelSelectionTool as c, KritzelEraserTool as d, DEFAULT_TEXT_CONFIG as e, KritzelImageTool as f, KritzelWorkspace as g, KritzelKeyboardHelper as h, KritzelEventHelper as i, KritzelBaseHandler as j, KritzelToolRegistry as k, KrtizelSelectionBox as l, KritzelSelectionGroup as m, KritzelBaseCommand as n, KritzelReviver as o, RemoveObjectCommand as p, AddObjectCommand as q, KritzelBaseTool as r, KritzelText as s, KritzelPath as t, KritzelImage as u };
2820
- //# sourceMappingURL=index-BAbkwyRx.js.map
2821
-
2822
- //# sourceMappingURL=index-BAbkwyRx.js.map