@m3ui-vue/m3ui-vue 1.2.2 → 1.3.0

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 (235) hide show
  1. package/dist/API.md +2776 -351
  2. package/dist/MButton-CuNzpoxm.js +172 -0
  3. package/dist/MButton-CuNzpoxm.js.map +1 -0
  4. package/dist/MDialog-HxEL-m58.js +173 -0
  5. package/dist/MDialog-HxEL-m58.js.map +1 -0
  6. package/dist/MIconButton-DoNotQ9v.js +282 -0
  7. package/dist/MIconButton-DoNotQ9v.js.map +1 -0
  8. package/dist/MListItem-DnPtv-hY.js +824 -0
  9. package/dist/MListItem-DnPtv-hY.js.map +1 -0
  10. package/dist/MLoadingIndicator-BQMNX6Dx.js +115 -0
  11. package/dist/MLoadingIndicator-BQMNX6Dx.js.map +1 -0
  12. package/dist/MMenuItem-Bih0h4-n.js +604 -0
  13. package/dist/MMenuItem-Bih0h4-n.js.map +1 -0
  14. package/dist/MProgressBar-BCoruxA-.js +184 -0
  15. package/dist/MProgressBar-BCoruxA-.js.map +1 -0
  16. package/dist/MSeekBar-LURE1Ah7.js +435 -0
  17. package/dist/MSeekBar-LURE1Ah7.js.map +1 -0
  18. package/dist/MSegmentedButton-DL9JtJFX.js +65 -0
  19. package/dist/MSegmentedButton-DL9JtJFX.js.map +1 -0
  20. package/dist/MSlider-_J4IS2_z.js +691 -0
  21. package/dist/MSlider-_J4IS2_z.js.map +1 -0
  22. package/dist/MSpinner-BhkMYKOM.js +65 -0
  23. package/dist/MSpinner-BhkMYKOM.js.map +1 -0
  24. package/dist/MTextField-CkzwNBWS.js +296 -0
  25. package/dist/MTextField-CkzwNBWS.js.map +1 -0
  26. package/dist/MTooltip-B67ZDSGp.js +756 -0
  27. package/dist/MTooltip-B67ZDSGp.js.map +1 -0
  28. package/dist/_storageKeys-CYXsUBwK.js +18 -0
  29. package/dist/_storageKeys-CYXsUBwK.js.map +1 -0
  30. package/dist/_useEscapeStack-CjndQhqg.js +19 -0
  31. package/dist/_useEscapeStack-CjndQhqg.js.map +1 -0
  32. package/dist/api.json +1 -1
  33. package/dist/chart.js +1 -1
  34. package/dist/code-editor.js +1 -1
  35. package/dist/components/MAudioPlayer.vue.d.ts +115 -0
  36. package/dist/components/MBadge.vue.d.ts +1 -1
  37. package/dist/components/MBottomSheetScaffold.vue.d.ts +1 -1
  38. package/dist/components/MBox.vue.d.ts +1 -1
  39. package/dist/components/MButton.vue.d.ts +1 -1
  40. package/dist/components/MConfirmDialog.vue.d.ts +1 -1
  41. package/dist/components/MCopyButton.vue.d.ts +2 -2
  42. package/dist/components/MDataTable.vue.d.ts +2 -2
  43. package/dist/components/MDialog.vue.d.ts +2 -2
  44. package/dist/components/MDivider.vue.d.ts +1 -1
  45. package/dist/components/MDragHandle.vue.d.ts +1 -1
  46. package/dist/components/MDrawCanvas.vue.d.ts +148 -0
  47. package/dist/components/MDrawLayers.vue.d.ts +3 -0
  48. package/dist/components/MDrawToolbar.vue.d.ts +34 -0
  49. package/dist/components/MExportButton.vue.d.ts +1 -1
  50. package/dist/components/MFab.vue.d.ts +2 -2
  51. package/dist/components/MFabMenu.vue.d.ts +2 -2
  52. package/dist/components/MFixed.vue.d.ts +1 -1
  53. package/dist/components/MFlex.vue.d.ts +2 -2
  54. package/dist/components/MFloorPlan.vue.d.ts +160 -0
  55. package/dist/components/MFlow.vue.d.ts +305 -0
  56. package/dist/components/MFlowControls.vue.d.ts +33 -0
  57. package/dist/components/MFlowHandle.vue.d.ts +16 -0
  58. package/dist/components/MFlowMinimap.vue.d.ts +22 -0
  59. package/dist/components/MFlowNode.vue.d.ts +35 -0
  60. package/dist/components/MGantt.vue.d.ts +141 -0
  61. package/dist/components/MGanttControls.vue.d.ts +32 -0
  62. package/dist/components/MIconButton.vue.d.ts +3 -1
  63. package/dist/components/MImageCropper.vue.d.ts +110 -0
  64. package/dist/components/MInfiniteScroll.vue.d.ts +1 -1
  65. package/dist/components/MLightbox.vue.d.ts +2 -2
  66. package/dist/components/MList.vue.d.ts +1 -1
  67. package/dist/components/MLoadingOverlay.vue.d.ts +1 -1
  68. package/dist/components/MMapControl.vue.d.ts +1 -1
  69. package/dist/components/MMapSearch.vue.d.ts +1 -1
  70. package/dist/components/MMaskField.vue.d.ts +12 -1
  71. package/dist/components/MMenu.vue.d.ts +1 -1
  72. package/dist/components/MNavigationDrawer.vue.d.ts +1 -1
  73. package/dist/components/MNumberField.vue.d.ts +11 -2
  74. package/dist/components/MPdfViewer.vue.d.ts +174 -0
  75. package/dist/components/MPullToRefresh.vue.d.ts +1 -1
  76. package/dist/components/MResourceTimeline.vue.d.ts +149 -0
  77. package/dist/components/MScheduler.vue.d.ts +3 -3
  78. package/dist/components/MScheme.vue.d.ts +1 -1
  79. package/dist/components/MSearchField.vue.d.ts +1 -1
  80. package/dist/components/MSeekBar.vue.d.ts +1 -1
  81. package/dist/components/MSimpleCarousel.vue.d.ts +1 -1
  82. package/dist/components/MSkeleton.vue.d.ts +1 -1
  83. package/dist/components/MSlider.vue.d.ts +2 -2
  84. package/dist/components/MSparkline.vue.d.ts +1 -1
  85. package/dist/components/MSplitter.vue.d.ts +1 -1
  86. package/dist/components/MStack.vue.d.ts +2 -2
  87. package/dist/components/MSwipeToDismiss.vue.d.ts +1 -1
  88. package/dist/components/MSwitch.vue.d.ts +1 -1
  89. package/dist/components/MTable.vue.d.ts +1 -1
  90. package/dist/components/MTagInput.vue.d.ts +12 -1
  91. package/dist/components/MTextField.vue.d.ts +13 -2
  92. package/dist/components/MToolbar.vue.d.ts +1 -1
  93. package/dist/components/MTree.vue.d.ts +2 -2
  94. package/dist/components/MVideoPlayer.vue.d.ts +253 -0
  95. package/dist/components/MVirtualTable.vue.d.ts +1 -1
  96. package/dist/components/MWindow.vue.d.ts +3 -3
  97. package/dist/components/_MFlowEdge.vue.d.ts +9 -0
  98. package/dist/components/_MFlowEdgeLabel.vue.d.ts +9 -0
  99. package/dist/components/_MFlowNodeShell.vue.d.ts +9 -0
  100. package/dist/components/_MPdfPage.vue.d.ts +76 -0
  101. package/dist/components/_MTimeBackground.vue.d.ts +14 -0
  102. package/dist/components/_MTimeHeader.vue.d.ts +20 -0
  103. package/dist/composables/_flowPanel.d.ts +2 -0
  104. package/dist/composables/_flowSlot.d.ts +5 -0
  105. package/dist/composables/_ganttTime.d.ts +41 -0
  106. package/dist/composables/_useTimeAxis.d.ts +90 -0
  107. package/dist/composables/drawGeometry.d.ts +119 -0
  108. package/dist/composables/flowFormats.d.ts +79 -0
  109. package/dist/composables/flowLayout.d.ts +45 -0
  110. package/dist/composables/flowPaths.d.ts +53 -0
  111. package/dist/composables/ganttFormats.d.ts +52 -0
  112. package/dist/composables/ganttSchedule.d.ts +99 -0
  113. package/dist/composables/useDrawing.d.ts +44 -0
  114. package/dist/composables/useFlow.d.ts +266 -0
  115. package/dist/composables/useGantt.d.ts +87 -0
  116. package/dist/composables/useLocale.d.ts +163 -0
  117. package/dist/composables/useMediaPlayer.d.ts +101 -0
  118. package/dist/composables/usePdf.d.ts +119 -0
  119. package/dist/composables/useResourceTimeline.d.ts +70 -0
  120. package/dist/draw.d.ts +7 -0
  121. package/dist/draw.js +1700 -0
  122. package/dist/draw.js.map +1 -0
  123. package/dist/flow.d.ts +14 -0
  124. package/dist/flow.js +3542 -0
  125. package/dist/flow.js.map +1 -0
  126. package/dist/flowPaths-CUc6X373.js +161 -0
  127. package/dist/flowPaths-CUc6X373.js.map +1 -0
  128. package/dist/gantt.d.ts +12 -0
  129. package/dist/gantt.js +3575 -0
  130. package/dist/gantt.js.map +1 -0
  131. package/dist/index.d.ts +4 -0
  132. package/dist/locales/index.js +1148 -7
  133. package/dist/locales/index.js.map +1 -1
  134. package/dist/m3ui-vue.css +1 -1
  135. package/dist/m3ui.js +7286 -7654
  136. package/dist/m3ui.js.map +1 -1
  137. package/dist/map.js +113 -108
  138. package/dist/map.js.map +1 -1
  139. package/dist/media.d.ts +5 -0
  140. package/dist/media.js +1311 -0
  141. package/dist/media.js.map +1 -0
  142. package/dist/pdf.d.ts +4 -0
  143. package/dist/pdf.js +1871 -0
  144. package/dist/pdf.js.map +1 -0
  145. package/dist/rich-text-editor.js +28 -26
  146. package/dist/rich-text-editor.js.map +1 -1
  147. package/dist/styles.css +1 -1
  148. package/dist/{useLocale-JYxDDeXC.js → useLocale-BpGxplLV.js} +165 -2
  149. package/dist/useLocale-BpGxplLV.js.map +1 -0
  150. package/dist/{useThemeTokens-y0HZpyhL.js → useThemeTokens-DQQcaWbE.js} +40 -54
  151. package/dist/useThemeTokens-DQQcaWbE.js.map +1 -0
  152. package/package.json +29 -5
  153. package/src/__tests__/MAudioPlayer.test.ts +75 -0
  154. package/src/__tests__/MDrawCanvas.test.ts +110 -0
  155. package/src/__tests__/MFloorPlan.test.ts +97 -0
  156. package/src/__tests__/MFlow.test.ts +575 -0
  157. package/src/__tests__/MGantt.test.ts +130 -0
  158. package/src/__tests__/MImageCropper.test.ts +89 -0
  159. package/src/__tests__/MPdfViewer.test.ts +235 -0
  160. package/src/__tests__/MResourceTimeline.test.ts +102 -0
  161. package/src/__tests__/MVideoPlayer.test.ts +201 -0
  162. package/src/__tests__/drawGeometry.test.ts +58 -0
  163. package/src/__tests__/fieldExpose.test.ts +30 -0
  164. package/src/__tests__/flowFormats.test.ts +185 -0
  165. package/src/__tests__/flowLayout.test.ts +113 -0
  166. package/src/__tests__/ganttFormats.test.ts +76 -0
  167. package/src/__tests__/ganttSchedule.test.ts +136 -0
  168. package/src/__tests__/pdfMock.ts +83 -0
  169. package/src/__tests__/useMediaPlayer.test.ts +182 -0
  170. package/src/__tests__/usePdf.test.ts +102 -0
  171. package/src/components/MAudioPlayer.vue +319 -0
  172. package/src/components/MDrawCanvas.vue +813 -0
  173. package/src/components/MDrawLayers.vue +114 -0
  174. package/src/components/MDrawToolbar.vue +171 -0
  175. package/src/components/MFloorPlan.vue +581 -0
  176. package/src/components/MFlow.vue +2049 -0
  177. package/src/components/MFlowControls.vue +110 -0
  178. package/src/components/MFlowHandle.vue +60 -0
  179. package/src/components/MFlowMinimap.vue +134 -0
  180. package/src/components/MFlowNode.vue +98 -0
  181. package/src/components/MGantt.vue +1609 -0
  182. package/src/components/MGanttControls.vue +77 -0
  183. package/src/components/MIconButton.vue +3 -1
  184. package/src/components/MImageCropper.vue +507 -0
  185. package/src/components/MMaskField.vue +13 -0
  186. package/src/components/MNumberField.vue +13 -0
  187. package/src/components/MPdfViewer.vue +1269 -0
  188. package/src/components/MResourceTimeline.vue +1020 -0
  189. package/src/components/MTagInput.vue +13 -0
  190. package/src/components/MTextField.vue +16 -0
  191. package/src/components/MVideoPlayer.vue +839 -0
  192. package/src/components/_MFlowEdge.vue +100 -0
  193. package/src/components/_MFlowEdgeLabel.vue +56 -0
  194. package/src/components/_MFlowNodeShell.vue +111 -0
  195. package/src/components/_MPdfPage.vue +456 -0
  196. package/src/components/_MTimeBackground.vue +16 -0
  197. package/src/components/_MTimeHeader.vue +31 -0
  198. package/src/composables/_flowPanel.ts +13 -0
  199. package/src/composables/_flowSlot.ts +6 -0
  200. package/src/composables/_ganttTime.ts +200 -0
  201. package/src/composables/_useTimeAxis.ts +224 -0
  202. package/src/composables/drawGeometry.ts +405 -0
  203. package/src/composables/flowFormats.ts +916 -0
  204. package/src/composables/flowLayout.ts +297 -0
  205. package/src/composables/flowPaths.ts +239 -0
  206. package/src/composables/ganttFormats.ts +366 -0
  207. package/src/composables/ganttSchedule.ts +403 -0
  208. package/src/composables/useDrawing.ts +53 -0
  209. package/src/composables/useFlow.ts +250 -0
  210. package/src/composables/useGantt.ts +92 -0
  211. package/src/composables/useLocale.ts +328 -0
  212. package/src/composables/useMediaPlayer.ts +406 -0
  213. package/src/composables/usePdf.ts +456 -0
  214. package/src/composables/useResourceTimeline.ts +76 -0
  215. package/src/draw.ts +25 -0
  216. package/src/flow.ts +26 -0
  217. package/src/gantt.ts +12 -0
  218. package/src/index.ts +4 -0
  219. package/src/locales/de.ts +163 -0
  220. package/src/locales/es.ts +163 -0
  221. package/src/locales/fr.ts +163 -0
  222. package/src/locales/ja.ts +163 -0
  223. package/src/locales/ko.ts +163 -0
  224. package/src/locales/pt.ts +163 -0
  225. package/src/locales/zh.ts +163 -0
  226. package/src/media.ts +5 -0
  227. package/src/pdf.ts +15 -0
  228. package/dist/MMenuItem-D4Gx_l3F.js +0 -929
  229. package/dist/MMenuItem-D4Gx_l3F.js.map +0 -1
  230. package/dist/MSlider-Dx_S3vJ9.js +0 -1506
  231. package/dist/MSlider-Dx_S3vJ9.js.map +0 -1
  232. package/dist/MTextField-Bz8JIsnl.js +0 -633
  233. package/dist/MTextField-Bz8JIsnl.js.map +0 -1
  234. package/dist/useLocale-JYxDDeXC.js.map +0 -1
  235. package/dist/useThemeTokens-y0HZpyhL.js.map +0 -1
package/dist/draw.js ADDED
@@ -0,0 +1,1700 @@
1
+ import { i as e } from "./useLocale-BpGxplLV.js";
2
+ import { t } from "./MIconButton-DoNotQ9v.js";
3
+ import { n, t as r } from "./MTooltip-B67ZDSGp.js";
4
+ import { n as i, t as a } from "./MMenuItem-Bih0h4-n.js";
5
+ import { Fragment as o, computed as s, createBlock as c, createCommentVNode as l, createElementBlock as u, createElementVNode as d, createTextVNode as f, createVNode as p, defineComponent as m, inject as h, mergeModels as g, mergeProps as _, nextTick as v, normalizeClass as y, normalizeStyle as b, onBeforeUnmount as x, onMounted as S, openBlock as C, provide as ee, ref as w, renderList as T, renderSlot as E, shallowRef as D, toDisplayString as te, unref as O, useId as ne, useModel as k, vModelText as re, watch as ie, withCtx as A, withDirectives as j, withKeys as ae, withModifiers as M } from "vue";
6
+ //#region src/composables/drawGeometry.ts
7
+ var N = 0, oe = () => `d${Date.now().toString(36)}${(N++).toString(36)}`, se = {
8
+ pen: {
9
+ thinning: .6,
10
+ taper: .4,
11
+ opacity: 1
12
+ },
13
+ brush: {
14
+ thinning: .85,
15
+ taper: 1,
16
+ opacity: 1
17
+ },
18
+ marker: {
19
+ thinning: 0,
20
+ taper: 0,
21
+ opacity: 1
22
+ },
23
+ highlighter: {
24
+ thinning: 0,
25
+ taper: 0,
26
+ opacity: .35
27
+ }
28
+ }, P = (e) => Math.round(e * 100) / 100;
29
+ function ce(e, t = .5, n = 4) {
30
+ if (e.length < 2) return e.slice();
31
+ let r = 1 - Math.min(.9, Math.max(0, t) * .85), i = Math.max(.5, n * .1), a = [e[0]], [o, s] = e[0];
32
+ for (let t = 1; t < e.length; t++) {
33
+ let n = e[t];
34
+ o += (n[0] - o) * r, s += (n[1] - s) * r;
35
+ let c = a[a.length - 1];
36
+ (Math.hypot(o - c[0], s - c[1]) >= i || t === e.length - 1) && a.push([
37
+ o,
38
+ s,
39
+ n[2]
40
+ ]);
41
+ }
42
+ let c = e[e.length - 1];
43
+ return a[a.length - 1] = [
44
+ c[0],
45
+ c[1],
46
+ c[2]
47
+ ], a;
48
+ }
49
+ function le(e, t) {
50
+ let n = .5;
51
+ return e.map((r, i) => {
52
+ if (!i) return [
53
+ r[0],
54
+ r[1],
55
+ .5
56
+ ];
57
+ let a = e[i - 1], o = Math.min(1, Math.hypot(r[0] - a[0], r[1] - a[1]) / (t * 2));
58
+ return n += (1 - o - n) * .3, [
59
+ r[0],
60
+ r[1],
61
+ Math.max(.2, Math.min(1, n))
62
+ ];
63
+ });
64
+ }
65
+ function ue(e, t, n) {
66
+ let { thinning: r, taper: i } = se[n], a = [0];
67
+ for (let t = 1; t < e.length; t++) a.push(a[t - 1] + Math.hypot(e[t][0] - e[t - 1][0], e[t][1] - e[t - 1][1]));
68
+ let o = a[a.length - 1], s = Math.min(o / 3, t * 3 * i);
69
+ return e.map((e, n) => {
70
+ let i = t / 2 * (1 - r * (1 - e[2]));
71
+ if (s > 0) {
72
+ let e = (e) => 1 - (1 - e) * (1 - e);
73
+ i *= Math.max(.15, Math.min(1, e(Math.min(1, a[n] / s)), e(Math.min(1, (o - a[n]) / s))));
74
+ }
75
+ return Math.max(.25, i);
76
+ });
77
+ }
78
+ function de(e) {
79
+ let t = e.points;
80
+ if (!t.length) return "";
81
+ let n = ue(t, e.size, e.pen);
82
+ if (t.length === 1 || t.every((e) => Math.hypot(e[0] - t[0][0], e[1] - t[0][1]) < .5)) {
83
+ let [e, r] = t[0], i = P(Math.max(...n));
84
+ return `M${P(e - i)} ${P(r)}a${i} ${i} 0 1 0 ${i * 2} 0a${i} ${i} 0 1 0 ${-i * 2} 0Z`;
85
+ }
86
+ let r = [], i = [];
87
+ for (let e = 0; e < t.length; e++) {
88
+ let a = t[Math.max(0, e - 1)], o = t[Math.min(t.length - 1, e + 1)], s = o[0] - a[0], c = o[1] - a[1], l = Math.hypot(s, c) || 1;
89
+ s /= l, c /= l;
90
+ let u = n[e];
91
+ r.push([t[e][0] - c * u, t[e][1] + s * u]), i.push([t[e][0] + c * u, t[e][1] - s * u]);
92
+ }
93
+ let a = (e) => {
94
+ let t = "";
95
+ for (let n = 1; n < e.length - 1; n++) {
96
+ let [r, i] = e[n], [a, o] = e[n + 1];
97
+ t += `Q${P(r)} ${P(i)} ${P((r + a) / 2)} ${P((i + o) / 2)}`;
98
+ }
99
+ let n = e[e.length - 1];
100
+ return `${t}L${P(n[0])} ${P(n[1])}`;
101
+ }, o = P(n[n.length - 1]), s = P(n[0]), c = i.slice().reverse();
102
+ return `M${P(r[0][0])} ${P(r[0][1])}${a(r)}A${o} ${o} 0 0 1 ${P(c[0][0])} ${P(c[0][1])}${a(c)}A${s} ${s} 0 0 1 ${P(r[0][0])} ${P(r[0][1])}Z`;
103
+ }
104
+ function fe(e) {
105
+ let [t, n] = e.from, [r, i] = e.to;
106
+ switch (e.shape) {
107
+ case "rect": {
108
+ let e = Math.min(t, r), a = Math.min(n, i);
109
+ return { d: `M${P(e)} ${P(a)}h${P(Math.abs(r - t))}v${P(Math.abs(i - n))}h${P(-Math.abs(r - t))}Z` };
110
+ }
111
+ case "ellipse": {
112
+ let e = Math.abs(r - t) / 2, a = Math.abs(i - n) / 2, o = (t + r) / 2, s = (n + i) / 2;
113
+ return { d: `M${P(o - e)} ${P(s)}a${P(e)} ${P(a)} 0 1 0 ${P(e * 2)} 0a${P(e)} ${P(a)} 0 1 0 ${P(-e * 2)} 0Z` };
114
+ }
115
+ case "arrow": {
116
+ let a = Math.hypot(r - t, i - n) || 1, o = (r - t) / a, s = (i - n) / a, c = Math.min(a * .6, Math.max(10, e.size * 4)), l = c * .55, u = r - o * c, d = i - s * c;
117
+ return {
118
+ d: `M${P(t)} ${P(n)}L${P(u + o * .5)} ${P(d + s * .5)}`,
119
+ head: `M${P(r)} ${P(i)}L${P(u - s * l)} ${P(d + o * l)}L${P(u + s * l)} ${P(d - o * l)}Z`
120
+ };
121
+ }
122
+ default: return { d: `M${P(t)} ${P(n)}L${P(r)} ${P(i)}` };
123
+ }
124
+ }
125
+ function pe(e, t, n) {
126
+ let r = n[0] - t[0], i = n[1] - t[1];
127
+ if (e === "rect" || e === "ellipse") {
128
+ let e = Math.max(Math.abs(r), Math.abs(i));
129
+ return [t[0] + Math.sign(r || 1) * e, t[1] + Math.sign(i || 1) * e];
130
+ }
131
+ let a = Math.round(Math.atan2(i, r) / (Math.PI / 4)) * (Math.PI / 4), o = Math.hypot(r, i);
132
+ return [t[0] + Math.cos(a) * o, t[1] + Math.sin(a) * o];
133
+ }
134
+ var me = 1.25;
135
+ function F(e) {
136
+ let t = e.text.split("\n");
137
+ return {
138
+ x: e.at[0],
139
+ y: e.at[1],
140
+ width: Math.max(e.size, ...t.map((t) => t.length * e.size * .56)),
141
+ height: t.length * e.size * me
142
+ };
143
+ }
144
+ function he(e) {
145
+ if (e.type === "text") return F(e);
146
+ let t = e.type === "stroke" ? e.points.map((e) => [e[0], e[1]]) : [e.from, e.to], n = e.size / 2, r = Infinity, i = Infinity, a = -Infinity, o = -Infinity;
147
+ for (let [e, n] of t) r = Math.min(r, e), i = Math.min(i, n), a = Math.max(a, e), o = Math.max(o, n);
148
+ return {
149
+ x: r - n,
150
+ y: i - n,
151
+ width: a - r + n * 2,
152
+ height: o - i + n * 2
153
+ };
154
+ }
155
+ function ge(e) {
156
+ if (!e.length) return null;
157
+ let t = Math.min(...e.map((e) => e.x)), n = Math.min(...e.map((e) => e.y)), r = Math.max(...e.map((e) => e.x + e.width)), i = Math.max(...e.map((e) => e.y + e.height));
158
+ return {
159
+ x: t,
160
+ y: n,
161
+ width: r - t,
162
+ height: i - n
163
+ };
164
+ }
165
+ function _e(e, t, n, r, i, a) {
166
+ let o = i - n, s = a - r, c = o * o + s * s, l = c ? Math.max(0, Math.min(1, ((e - n) * o + (t - r) * s) / c)) : 0;
167
+ return Math.hypot(n + l * o - e, r + l * s - t);
168
+ }
169
+ function I(e) {
170
+ let [t, n] = e.from, [r, i] = e.to;
171
+ if (e.shape === "rect") return [
172
+ [t, n],
173
+ [r, n],
174
+ [r, i],
175
+ [t, i],
176
+ [t, n]
177
+ ];
178
+ if (e.shape === "ellipse") {
179
+ let e = (t + r) / 2, a = (n + i) / 2;
180
+ return Array.from({ length: 33 }, (o, s) => [e + Math.abs(r - t) / 2 * Math.cos(s / 32 * Math.PI * 2), a + Math.abs(i - n) / 2 * Math.sin(s / 32 * Math.PI * 2)]);
181
+ }
182
+ return [e.from, e.to];
183
+ }
184
+ function ve(e, t, n, r = 4) {
185
+ if (e.type === "text") {
186
+ let i = F(e);
187
+ return t >= i.x - r && t <= i.x + i.width + r && n >= i.y - r && n <= i.y + i.height + r;
188
+ }
189
+ if (e.type === "shape" && e.fill && (e.shape === "rect" || e.shape === "ellipse")) {
190
+ let r = he(e);
191
+ if (t >= r.x && t <= r.x + r.width && n >= r.y && n <= r.y + r.height) {
192
+ if (e.shape === "rect") return !0;
193
+ let i = r.width / 2, a = r.height / 2;
194
+ if (((t - r.x - i) / i) ** 2 + ((n - r.y - a) / a) ** 2 <= 1) return !0;
195
+ }
196
+ }
197
+ let i = e.type === "stroke" ? e.points.map((e) => [e[0], e[1]]) : I(e), a = e.size / 2 + r;
198
+ if (i.length === 1) return Math.hypot(i[0][0] - t, i[0][1] - n) <= a;
199
+ for (let e = 1; e < i.length; e++) if (_e(t, n, i[e - 1][0], i[e - 1][1], i[e][0], i[e][1]) <= a) return !0;
200
+ return !1;
201
+ }
202
+ function ye(e, t, n, r) {
203
+ if (e.type !== "stroke") return ve(e, t, n, r) ? [] : [e];
204
+ let i = r + e.size / 2, a = e.points;
205
+ if (a.length === 1) return Math.hypot(a[0][0] - t, a[0][1] - n) <= i ? [] : [e];
206
+ let o = !1, s = [], c = [];
207
+ return a.forEach((e, r) => {
208
+ let l = a[r - 1], u = Math.hypot(e[0] - t, e[1] - n) <= i, d = !!l && c.length > 0 && _e(t, n, l[0], l[1], e[0], e[1]) <= i;
209
+ u || d ? (o = !0, c.length > 1 && s.push(c), c = u ? [] : [e]) : c.push(e);
210
+ }), c.length > 1 && s.push(c), o ? s.map((t, n) => ({
211
+ ...e,
212
+ id: n ? oe() : e.id,
213
+ points: t
214
+ })) : [e];
215
+ }
216
+ function L(e, t, n) {
217
+ let r = !1;
218
+ for (let i = 0, a = n.length - 1; i < n.length; a = i++) {
219
+ let [o, s] = n[i], [c, l] = n[a];
220
+ s > t != l > t && e < (c - o) * (t - s) / (l - s) + o && (r = !r);
221
+ }
222
+ return r;
223
+ }
224
+ function be(e, t) {
225
+ if (t.length < 3) return !1;
226
+ let n;
227
+ if (e.type === "stroke") n = e.points.map((e) => [e[0], e[1]]);
228
+ else if (e.type === "shape") n = I(e);
229
+ else {
230
+ let t = F(e);
231
+ n = [
232
+ [t.x, t.y],
233
+ [t.x + t.width, t.y],
234
+ [t.x, t.y + t.height],
235
+ [t.x + t.width, t.y + t.height]
236
+ ];
237
+ }
238
+ return n.filter(([e, n]) => L(e, n, t)).length >= Math.max(1, n.length * .5);
239
+ }
240
+ function xe(e, t) {
241
+ let { dx: n = 0, dy: r = 0, sx: i = 1, sy: a = 1, ox: o = 0, oy: s = 0 } = t, c = (e) => o + (e - o) * i + n, l = (e) => s + (e - s) * a + r, u = Math.sqrt(Math.abs(i * a));
242
+ return e.type === "stroke" ? {
243
+ ...e,
244
+ size: e.size * u,
245
+ points: e.points.map(([e, t, n]) => [
246
+ c(e),
247
+ l(t),
248
+ n
249
+ ])
250
+ } : e.type === "shape" ? {
251
+ ...e,
252
+ size: e.size * u,
253
+ from: [c(e.from[0]), l(e.from[1])],
254
+ to: [c(e.to[0]), l(e.to[1])]
255
+ } : {
256
+ ...e,
257
+ size: e.size * u,
258
+ at: [c(e.at[0]), l(e.at[1])]
259
+ };
260
+ }
261
+ var R = (e) => e.replace(/&/g, "&amp;").replace(/</g, "&lt;").replace(/>/g, "&gt;").replace(/"/g, "&quot;");
262
+ function z(e, t = "sans-serif") {
263
+ if (e.type === "stroke") {
264
+ let t = se[e.pen].opacity;
265
+ return `<path d="${de(e)}" fill="${R(e.color)}"${t < 1 ? ` fill-opacity="${t}"` : ""}/>`;
266
+ }
267
+ if (e.type === "shape") {
268
+ let { d: t, head: n } = fe(e);
269
+ return `<path d="${t}" fill="${e.fill && (e.shape === "rect" || e.shape === "ellipse") ? R(e.fill) : "none"}" stroke="${R(e.color)}" stroke-width="${e.size}" stroke-linecap="round" stroke-linejoin="round"/>${n ? `<path d="${n}" fill="${R(e.color)}"/>` : ""}`;
270
+ }
271
+ let n = e.text.split("\n");
272
+ return `<text x="${e.at[0]}" y="${e.at[1]}" font-size="${e.size}" font-family="${R(t)}" fill="${R(e.color)}">${n.map((t, n) => `<tspan x="${e.at[0]}" dy="${n ? e.size * me : e.size * .95}">${R(t) || " "}</tspan>`).join("")}</text>`;
273
+ }
274
+ function Se(e, t) {
275
+ if (!t?.length) return e;
276
+ let n = (e) => e.layer === void 0 ? 0 : Math.max(0, t.indexOf(e.layer));
277
+ return e.map((e, t) => [e, t]).sort((e, t) => n(e[0]) - n(t[0]) || e[1] - t[1]).map(([e]) => e);
278
+ }
279
+ function Ce(e, t = {}) {
280
+ let n = Se(e, t.layers).filter((e) => (t.page === void 0 || (e.page ?? 0) === t.page) && !t.hiddenLayers?.includes(e.layer ?? "")), r = t.padding ?? 16, i = t.box ?? ge(n.map(he)) ?? {
281
+ x: 0,
282
+ y: 0,
283
+ width: 1,
284
+ height: 1
285
+ }, a = t.box ? i : {
286
+ x: i.x - r,
287
+ y: i.y - r,
288
+ width: i.width + r * 2,
289
+ height: i.height + r * 2
290
+ }, o = t.background ? `<rect x="${a.x}" y="${a.y}" width="${a.width}" height="${a.height}" fill="${R(t.background)}"/>` : "";
291
+ return `<svg xmlns="http://www.w3.org/2000/svg" viewBox="${P(a.x)} ${P(a.y)} ${P(a.width)} ${P(a.height)}" width="${Math.ceil(a.width)}" height="${Math.ceil(a.height)}">${o}${n.map((e) => z(e, t.fontFamily)).join("")}</svg>`;
292
+ }
293
+ async function we(e, t = 2) {
294
+ let n = URL.createObjectURL(new Blob([e], { type: "image/svg+xml" }));
295
+ try {
296
+ let e = new Image();
297
+ e.src = n, await e.decode();
298
+ let r = document.createElement("canvas");
299
+ return r.width = Math.ceil(e.width * t), r.height = Math.ceil(e.height * t), r.getContext("2d").drawImage(e, 0, 0, r.width, r.height), await new Promise((e, t) => r.toBlob((n) => n ? e(n) : t(/* @__PURE__ */ Error("PNG export failed")), "image/png"));
300
+ } finally {
301
+ URL.revokeObjectURL(n);
302
+ }
303
+ }
304
+ //#endregion
305
+ //#region src/composables/useDrawing.ts
306
+ var Te = Symbol("m3-draw");
307
+ function Ee() {
308
+ let e = h(Te, null);
309
+ if (!e) throw Error("useDrawing() must be called inside <MDrawCanvas>");
310
+ return e;
311
+ }
312
+ //#endregion
313
+ //#region src/components/MDrawCanvas.vue?vue&type=script&setup=true&lang.ts
314
+ var De = ["aria-label"], Oe = [
315
+ "id",
316
+ "width",
317
+ "height"
318
+ ], ke = ["d", "stroke-width"], Ae = [
319
+ "id",
320
+ "width",
321
+ "height"
322
+ ], je = [
323
+ "cx",
324
+ "cy",
325
+ "r"
326
+ ], Me = [
327
+ "id",
328
+ "width",
329
+ "height"
330
+ ], Ne = ["d", "stroke-width"], Pe = ["id"], Fe = ["width", "height"], Ie = ["transform"], Le = ["fill"], Re = ["href"], ze = ["fill"], Be = ["transform"], Ve = [
331
+ "width",
332
+ "height",
333
+ "fill"
334
+ ], He = [
335
+ "href",
336
+ "width",
337
+ "height"
338
+ ], Ue = [
339
+ "width",
340
+ "height",
341
+ "fill"
342
+ ], We = ["clip-path"], Ge = [
343
+ "d",
344
+ "fill",
345
+ "fill-opacity"
346
+ ], Ke = [
347
+ "d",
348
+ "fill",
349
+ "stroke",
350
+ "stroke-width"
351
+ ], qe = ["d", "fill"], Je = [
352
+ "x",
353
+ "y",
354
+ "font-size",
355
+ "fill"
356
+ ], Ye = ["x", "dy"], Xe = [
357
+ "d",
358
+ "fill",
359
+ "fill-opacity"
360
+ ], Ze = [
361
+ "d",
362
+ "fill",
363
+ "stroke",
364
+ "stroke-width"
365
+ ], Qe = ["d", "fill"], $e = [
366
+ "points",
367
+ "stroke-width",
368
+ "stroke-dasharray"
369
+ ], et = [
370
+ "x",
371
+ "y",
372
+ "width",
373
+ "height",
374
+ "stroke-width",
375
+ "stroke-dasharray"
376
+ ], tt = [
377
+ "x",
378
+ "y",
379
+ "width",
380
+ "height",
381
+ "rx",
382
+ "stroke-width"
383
+ ], nt = ["aria-label", "onKeydown"], rt = 24, it = 10, at = /* @__PURE__ */ m({
384
+ __name: "MDrawCanvas",
385
+ props: /*@__PURE__*/ g({
386
+ mode: { default: "infinite" },
387
+ pageSize: { default: () => ({
388
+ width: 794,
389
+ height: 1123
390
+ }) },
391
+ paper: { default: "#ffffff" },
392
+ background: { default: "none" },
393
+ backgroundSize: { default: 24 },
394
+ backgroundImage: {},
395
+ penOnly: {
396
+ type: [Boolean, String],
397
+ default: "auto"
398
+ },
399
+ pressure: {
400
+ type: Boolean,
401
+ default: !0
402
+ },
403
+ smoothing: { default: .5 },
404
+ eraserSize: { default: 12 },
405
+ history: {
406
+ type: Boolean,
407
+ default: !0
408
+ },
409
+ historySize: { default: 100 },
410
+ readonly: {
411
+ type: Boolean,
412
+ default: !1
413
+ },
414
+ minZoom: { default: .1 },
415
+ maxZoom: { default: 8 },
416
+ label: {}
417
+ }, {
418
+ modelValue: { default: () => [] },
419
+ modelModifiers: {},
420
+ tool: { default: "pen" },
421
+ toolModifiers: {},
422
+ color: { default: "#1d1b20" },
423
+ colorModifiers: {},
424
+ size: { default: 4 },
425
+ sizeModifiers: {},
426
+ fill: {
427
+ type: Boolean,
428
+ default: !1
429
+ },
430
+ fillModifiers: {},
431
+ layers: { default: () => [] },
432
+ layersModifiers: {},
433
+ layer: { default: void 0 },
434
+ layerModifiers: {},
435
+ pages: { default: 1 },
436
+ pagesModifiers: {},
437
+ selection: { default: () => [] },
438
+ selectionModifiers: {},
439
+ viewport: { default: () => ({
440
+ x: 0,
441
+ y: 0,
442
+ zoom: 1
443
+ }) },
444
+ viewportModifiers: {}
445
+ }),
446
+ emits: /*@__PURE__*/ g(["change"], [
447
+ "update:modelValue",
448
+ "update:tool",
449
+ "update:color",
450
+ "update:size",
451
+ "update:fill",
452
+ "update:layers",
453
+ "update:layer",
454
+ "update:pages",
455
+ "update:selection",
456
+ "update:viewport"
457
+ ]),
458
+ setup(t, { expose: n, emit: r }) {
459
+ let i = t, a = k(t, "modelValue"), c = k(t, "tool"), f = k(t, "color"), p = k(t, "size"), m = k(t, "fill"), h = k(t, "layers"), g = k(t, "layer"), y = k(t, "pages"), A = k(t, "selection"), N = k(t, "viewport"), P = r, ue = e(), F = w(), _e = w(), I = w({
460
+ width: 0,
461
+ height: 0
462
+ }), L = (e) => e * (i.pageSize.height + rt), R = s(() => i.mode === "pages"), z = D(null), Ee = s(() => z.value ?? a.value), at = s(() => h.value.map((e) => e.id)), ot = s(() => g.value ?? h.value[h.value.length - 1]?.id), st = (e) => h.value.find((t) => t.id === (e.layer ?? h.value[0]?.id)), ct = (e) => st(e)?.visible !== !1, B = (e) => ct(e) && !st(e)?.locked, lt = s(() => Se(Ee.value, at.value).filter(ct)), V = D([]), H = D([]);
463
+ function U(e) {
464
+ i.history && (V.value = [...V.value, a.value].slice(-i.historySize), H.value = []), a.value = e, P("change", e);
465
+ }
466
+ function ut() {
467
+ V.value.length && (H.value = [a.value, ...H.value], a.value = V.value[V.value.length - 1], V.value = V.value.slice(0, -1), A.value = A.value.filter((e) => a.value.some((t) => t.id === e)), P("change", a.value));
468
+ }
469
+ function dt() {
470
+ H.value.length && (V.value = [...V.value, a.value], a.value = H.value[0], H.value = H.value.slice(1), P("change", a.value));
471
+ }
472
+ function ft() {
473
+ a.value.length && U(a.value.filter((e) => !B(e))), A.value = [];
474
+ }
475
+ function pt() {
476
+ if (!A.value.length) return;
477
+ let e = new Set(A.value);
478
+ U(a.value.filter((t) => !e.has(t.id))), A.value = [];
479
+ }
480
+ let W = s(() => N.value);
481
+ function G(e) {
482
+ let t = F.value.getBoundingClientRect();
483
+ return {
484
+ x: (e.clientX - t.left - W.value.x) / W.value.zoom,
485
+ y: (e.clientY - t.top - W.value.y) / W.value.zoom
486
+ };
487
+ }
488
+ function mt(e) {
489
+ if (!R.value) return;
490
+ let t = Math.floor(e / (i.pageSize.height + rt));
491
+ return Math.max(0, Math.min(y.value - 1, t));
492
+ }
493
+ let ht = (e, t) => ({
494
+ x: e.x,
495
+ y: t === void 0 ? e.y : e.y - L(t)
496
+ }), gt = (e) => R.value ? L(e.page ?? 0) : 0, _t = (e) => Math.min(i.maxZoom, Math.max(i.minZoom, e));
497
+ function vt(e, t, n) {
498
+ let r = W.value, i = _t(e);
499
+ N.value = {
500
+ zoom: i,
501
+ x: t - (t - r.x) / r.zoom * i,
502
+ y: n - (n - r.y) / r.zoom * i
503
+ };
504
+ }
505
+ let yt = (e) => vt(W.value.zoom * e, I.value.width / 2, I.value.height / 2);
506
+ function bt() {
507
+ let { width: e, height: t } = I.value;
508
+ if (!e || !t) return;
509
+ let n = R.value ? {
510
+ x: 0,
511
+ y: 0,
512
+ width: i.pageSize.width,
513
+ height: L(y.value - 1) + i.pageSize.height
514
+ } : ge(lt.value.map((e) => he(e)));
515
+ if (!n) {
516
+ N.value = {
517
+ x: e / 2,
518
+ y: t / 2,
519
+ zoom: 1
520
+ };
521
+ return;
522
+ }
523
+ let r = _t(R.value ? Math.min((e - 48) / n.width, 1.5) : Math.min((e - 48) / n.width, (t - 48) / n.height, 2));
524
+ N.value = {
525
+ zoom: r,
526
+ x: (e - n.width * r) / 2 - n.x * r,
527
+ y: R.value ? 24 : (t - n.height * r) / 2 - n.y * r
528
+ };
529
+ }
530
+ let K = D(null), q = /* @__PURE__ */ new Map(), J = null, xt = w(!1), St = w(!1), Ct = s(() => i.penOnly === !0 || i.penOnly === "auto" && xt.value), Y = D(null), wt = D(null), Tt = (e) => e === "pen" || e === "brush" || e === "marker" || e === "highlighter", Et = (e) => e === "line" || e === "arrow" || e === "rect" || e === "ellipse", Dt = (e) => i.pressure && e.pointerType === "pen" && e.pressure > 0 ? e.pressure : .5;
531
+ function Ot(e) {
532
+ let t = c.value, n = e.points;
533
+ return !(e.pen && i.pressure) && se[t].thinning > 0 && (n = le(n, p.value)), n = ce(n, i.smoothing, p.value).map(([e, t, n]) => [
534
+ Math.round(e * 100) / 100,
535
+ Math.round(t * 100) / 100,
536
+ Math.round(n * 100) / 100
537
+ ]), {
538
+ id: "live",
539
+ type: "stroke",
540
+ pen: t,
541
+ color: f.value,
542
+ size: p.value,
543
+ points: n,
544
+ layer: ot.value,
545
+ page: e.page
546
+ };
547
+ }
548
+ function kt() {
549
+ let [e, t] = [...q.values()];
550
+ if (!e || !t) return;
551
+ let n = F.value.getBoundingClientRect();
552
+ J = {
553
+ d: Math.hypot(e.x - t.x, e.y - t.y) || 1,
554
+ mx: (e.x + t.x) / 2 - n.left,
555
+ my: (e.y + t.y) / 2 - n.top,
556
+ vp: { ...W.value }
557
+ }, K.value = {
558
+ kind: "pinch",
559
+ ids: [...q.keys()].slice(0, 2)
560
+ };
561
+ }
562
+ let At = (e) => e.target === F.value || !!_e.value?.contains(e.target);
563
+ function jt(e) {
564
+ if (!At(e)) return;
565
+ F.value.focus({ preventScroll: !0 }), e.pointerType === "touch" && q.set(e.pointerId, {
566
+ x: e.clientX,
567
+ y: e.clientY
568
+ }), e.pointerType === "pen" && (xt.value = !0);
569
+ let t = K.value;
570
+ if (e.pointerType === "touch" && q.size === 2 && (!t || t.kind === "pan" || t.kind === "draw" && t.touch || t.kind === "lasso" || t.kind === "shape" || t.kind === "erase")) {
571
+ t?.kind === "erase" && (z.value = null), Y.value = null, wt.value = null, kt();
572
+ return;
573
+ }
574
+ if (t) return;
575
+ try {
576
+ F.value.setPointerCapture(e.pointerId);
577
+ } catch {}
578
+ let n = G(e);
579
+ if (e.button === 1 || St.value || c.value === "pan" || i.readonly || e.pointerType === "touch" && Ct.value) {
580
+ K.value = {
581
+ kind: "pan",
582
+ id: e.pointerId,
583
+ sx: e.clientX,
584
+ sy: e.clientY,
585
+ vx: W.value.x,
586
+ vy: W.value.y
587
+ };
588
+ return;
589
+ }
590
+ if (e.button !== 0 && (e.pointerType !== "pen" || e.button !== 5)) return;
591
+ let r = e.pointerType === "pen" && (e.button === 5 || e.buttons & 32) ? "eraser" : c.value;
592
+ if (r === "eraser" || r === "stroke-eraser") {
593
+ K.value = {
594
+ kind: "erase",
595
+ id: e.pointerId,
596
+ whole: r === "stroke-eraser",
597
+ last: n
598
+ }, z.value = a.value, Pt(n);
599
+ return;
600
+ }
601
+ let o = mt(n.y), s = ht(n, o);
602
+ if (Tt(r)) {
603
+ K.value = {
604
+ kind: "draw",
605
+ id: e.pointerId,
606
+ page: o,
607
+ points: [[
608
+ s.x,
609
+ s.y,
610
+ Dt(e)
611
+ ]],
612
+ pen: e.pointerType === "pen",
613
+ touch: e.pointerType === "touch",
614
+ started: performance.now()
615
+ }, Y.value = Ot(K.value);
616
+ return;
617
+ }
618
+ if (Et(r)) {
619
+ K.value = {
620
+ kind: "shape",
621
+ id: e.pointerId,
622
+ page: o,
623
+ shape: r,
624
+ from: [s.x, s.y],
625
+ to: [s.x, s.y]
626
+ };
627
+ return;
628
+ }
629
+ if (r === "text") {
630
+ let t = Ft(n, (e) => e.type === "text");
631
+ t ? Ut(t) : Ht(s, o), e.preventDefault();
632
+ return;
633
+ }
634
+ if (r === "select") {
635
+ let t = Bt(n);
636
+ if (t) {
637
+ let r = X.value, i = t.includes("l") ? r.x + r.width : r.x, o = t.includes("t") ? r.y + r.height : r.y;
638
+ K.value = {
639
+ kind: "scale",
640
+ id: e.pointerId,
641
+ origin: {
642
+ x: i,
643
+ y: o
644
+ },
645
+ from: n
646
+ }, z.value = a.value;
647
+ return;
648
+ }
649
+ let r = Ft(n), i = X.value && n.x >= X.value.x && n.x <= X.value.x + X.value.width && n.y >= X.value.y && n.y <= X.value.y + X.value.height;
650
+ if (r && !A.value.includes(r.id) && !i && (A.value = e.shiftKey ? [...A.value, r.id] : [r.id]), r || i) {
651
+ K.value = {
652
+ kind: "move",
653
+ id: e.pointerId,
654
+ from: n,
655
+ moved: !1
656
+ }, z.value = a.value;
657
+ return;
658
+ }
659
+ K.value = {
660
+ kind: "lasso",
661
+ id: e.pointerId,
662
+ points: [[n.x, n.y]],
663
+ add: e.shiftKey
664
+ }, wt.value = [[n.x, n.y]];
665
+ }
666
+ }
667
+ function Mt(e) {
668
+ e.pointerType === "touch" && q.has(e.pointerId) && q.set(e.pointerId, {
669
+ x: e.clientX,
670
+ y: e.clientY
671
+ });
672
+ let t = K.value;
673
+ if (!t) return;
674
+ if (t.kind === "pinch") {
675
+ let [e, n] = t.ids.map((e) => q.get(e));
676
+ if (!e || !n || !J) return;
677
+ let r = F.value.getBoundingClientRect(), i = Math.hypot(e.x - n.x, e.y - n.y), a = (e.x + n.x) / 2 - r.left, o = (e.y + n.y) / 2 - r.top, s = _t(J.vp.zoom * (i / J.d)), c = (J.mx - J.vp.x) / J.vp.zoom, l = (J.my - J.vp.y) / J.vp.zoom;
678
+ N.value = {
679
+ zoom: s,
680
+ x: a - c * s,
681
+ y: o - l * s
682
+ };
683
+ return;
684
+ }
685
+ if ("id" in t && t.id !== e.pointerId) return;
686
+ if (t.kind === "pan") {
687
+ N.value = {
688
+ ...W.value,
689
+ x: t.vx + e.clientX - t.sx,
690
+ y: t.vy + e.clientY - t.sy
691
+ };
692
+ return;
693
+ }
694
+ let n = (e.getCoalescedEvents?.() ?? []).length ? e.getCoalescedEvents() : [e];
695
+ if (t.kind === "draw") {
696
+ for (let e of n) {
697
+ let n = ht(G(e), t.page);
698
+ t.points.push([
699
+ n.x,
700
+ n.y,
701
+ Dt(e)
702
+ ]);
703
+ }
704
+ Y.value = Ot(t);
705
+ return;
706
+ }
707
+ let r = G(e);
708
+ if (t.kind === "erase") {
709
+ let e = i.eraserSize / W.value.zoom / 2;
710
+ for (let r of n) {
711
+ let n = G(r), i = Math.max(1, Math.ceil(Math.hypot(n.x - t.last.x, n.y - t.last.y) / e));
712
+ for (let e = 1; e <= i; e++) Pt({
713
+ x: t.last.x + (n.x - t.last.x) * e / i,
714
+ y: t.last.y + (n.y - t.last.y) * e / i
715
+ });
716
+ t.last = n;
717
+ }
718
+ return;
719
+ }
720
+ if (t.kind === "shape") {
721
+ let n = ht(r, t.page);
722
+ t.to = e.shiftKey ? pe(t.shape, t.from, [n.x, n.y]) : [n.x, n.y], Y.value = {
723
+ id: "live",
724
+ type: "shape",
725
+ shape: t.shape,
726
+ from: t.from,
727
+ to: t.to,
728
+ color: f.value,
729
+ size: p.value,
730
+ fill: m.value ? f.value : null,
731
+ layer: ot.value,
732
+ page: t.page
733
+ };
734
+ return;
735
+ }
736
+ if (t.kind === "lasso") {
737
+ t.points.push([r.x, r.y]), wt.value = t.points.slice();
738
+ return;
739
+ }
740
+ if (t.kind === "move") {
741
+ let e = r.x - t.from.x, n = r.y - t.from.y;
742
+ if (!t.moved && Math.hypot(e, n) * W.value.zoom < 3) return;
743
+ t.moved = !0;
744
+ let i = new Set(A.value);
745
+ z.value = a.value.map((t) => i.has(t.id) ? xe(t, {
746
+ dx: e,
747
+ dy: n
748
+ }) : t);
749
+ return;
750
+ }
751
+ if (t.kind === "scale") {
752
+ let e = Math.hypot(t.from.x - t.origin.x, t.from.y - t.origin.y) || 1, n = Math.max(.05, Math.hypot(r.x - t.origin.x, r.y - t.origin.y) / e), i = new Set(A.value);
753
+ z.value = a.value.map((e) => i.has(e.id) ? xe(e, {
754
+ sx: n,
755
+ sy: n,
756
+ ox: t.origin.x,
757
+ oy: t.origin.y - gt(e)
758
+ }) : e);
759
+ }
760
+ }
761
+ function Nt(e) {
762
+ q.delete(e.pointerId);
763
+ let t = K.value;
764
+ if (!t) return;
765
+ if (t.kind === "pinch") {
766
+ if (!t.ids.includes(e.pointerId)) return;
767
+ K.value = null, J = null;
768
+ let [n, r] = [...q.entries()][0] ?? [];
769
+ n !== void 0 && r && (K.value = {
770
+ kind: "pan",
771
+ id: n,
772
+ sx: r.x,
773
+ sy: r.y,
774
+ vx: W.value.x,
775
+ vy: W.value.y
776
+ });
777
+ return;
778
+ }
779
+ if (t.id !== e.pointerId) return;
780
+ K.value = null;
781
+ let n = e.type === "pointercancel";
782
+ if (t.kind === "draw") {
783
+ let e = Ot(t);
784
+ Y.value = null, n || U([...a.value, {
785
+ ...e,
786
+ id: oe()
787
+ }]);
788
+ } else if (t.kind === "shape") {
789
+ let e = Y.value;
790
+ Y.value = null, e && !n && Math.hypot(t.to[0] - t.from[0], t.to[1] - t.from[1]) > 2 && U([...a.value, {
791
+ ...e,
792
+ id: oe()
793
+ }]);
794
+ } else if (t.kind === "erase" || t.kind === "move" || t.kind === "scale") {
795
+ let r = z.value;
796
+ if (z.value = null, r && r !== a.value && !n && (t.kind !== "move" || t.moved) && U(r), t.kind === "move" && !t.moved && !e.shiftKey) {
797
+ let t = Ft(G(e));
798
+ A.value = t ? [t.id] : [];
799
+ }
800
+ } else if (t.kind === "lasso") {
801
+ let e = t.points;
802
+ if (wt.value = null, e.length < 3) {
803
+ t.add || (A.value = []);
804
+ return;
805
+ }
806
+ let n = Ee.value.filter((t) => B(t) && be(t, e.map(([e, n]) => [e, n - gt(t)]))).map((e) => e.id);
807
+ A.value = t.add ? [.../* @__PURE__ */ new Set([...A.value, ...n])] : n;
808
+ }
809
+ }
810
+ function Pt(e) {
811
+ let t = i.eraserSize / W.value.zoom, n = K.value, r = n?.kind === "erase" && n.whole, o = !1, s = [];
812
+ for (let n of z.value ?? a.value) {
813
+ if (!B(n)) {
814
+ s.push(n);
815
+ continue;
816
+ }
817
+ let i = e.x, a = e.y - gt(n);
818
+ if (r) {
819
+ ve(n, i, a, t) ? o = !0 : s.push(n);
820
+ continue;
821
+ }
822
+ let c = ye(n, i, a, t);
823
+ (c.length !== 1 || c[0] !== n) && (o = !0), s.push(...c);
824
+ }
825
+ o && (z.value = s);
826
+ }
827
+ function Ft(e, t = () => !0) {
828
+ let n = 6 / W.value.zoom, r = lt.value;
829
+ for (let i = r.length - 1; i >= 0; i--) {
830
+ let a = r[i];
831
+ if (B(a) && t(a) && ve(a, e.x, e.y - gt(a), n)) return a;
832
+ }
833
+ return null;
834
+ }
835
+ function It(e) {
836
+ if (!At(e)) return;
837
+ e.preventDefault();
838
+ let t = F.value.getBoundingClientRect();
839
+ if (e.ctrlKey || e.metaKey) vt(W.value.zoom * Math.exp(-e.deltaY * (e.deltaMode ? .05 : .01)), e.clientX - t.left, e.clientY - t.top);
840
+ else {
841
+ let t = e.deltaMode ? 16 : 1, n = e.shiftKey && !e.deltaX ? e.deltaY : e.deltaX, r = e.shiftKey && !e.deltaX ? 0 : e.deltaY;
842
+ N.value = {
843
+ ...W.value,
844
+ x: W.value.x - n * t,
845
+ y: W.value.y - r * t
846
+ };
847
+ }
848
+ }
849
+ function Lt(e) {
850
+ if (!At(e)) return;
851
+ let t = e.ctrlKey || e.metaKey;
852
+ t && e.key.toLowerCase() === "z" ? (e.preventDefault(), e.shiftKey ? dt() : ut()) : t && e.key.toLowerCase() === "y" ? (e.preventDefault(), dt()) : t && e.key.toLowerCase() === "a" && !i.readonly ? (e.preventDefault(), c.value = "select", A.value = Ee.value.filter(B).map((e) => e.id)) : (e.key === "Delete" || e.key === "Backspace") && A.value.length ? (e.preventDefault(), pt()) : e.key === "Escape" ? A.value = [] : e.key === " " && !e.repeat && (e.preventDefault(), St.value = !0);
853
+ }
854
+ let Rt = (e) => e.key === " " && (St.value = !1), X = s(() => {
855
+ let e = new Set(A.value);
856
+ return ge(Ee.value.filter((t) => e.has(t.id)).map((e) => {
857
+ let t = he(e);
858
+ return {
859
+ ...t,
860
+ y: t.y + gt(e)
861
+ };
862
+ }));
863
+ }), zt = s(() => {
864
+ let e = X.value;
865
+ return !e || c.value !== "select" ? [] : [
866
+ {
867
+ id: "tl",
868
+ x: e.x,
869
+ y: e.y,
870
+ cursor: "nwse-resize"
871
+ },
872
+ {
873
+ id: "tr",
874
+ x: e.x + e.width,
875
+ y: e.y,
876
+ cursor: "nesw-resize"
877
+ },
878
+ {
879
+ id: "bl",
880
+ x: e.x,
881
+ y: e.y + e.height,
882
+ cursor: "nesw-resize"
883
+ },
884
+ {
885
+ id: "br",
886
+ x: e.x + e.width,
887
+ y: e.y + e.height,
888
+ cursor: "nwse-resize"
889
+ }
890
+ ];
891
+ });
892
+ function Bt(e) {
893
+ let t = it * 1.2 / W.value.zoom;
894
+ return zt.value.find((n) => Math.abs(n.x - e.x) <= t && Math.abs(n.y - e.y) <= t)?.id;
895
+ }
896
+ ie(c, (e) => e !== "select" && (A.value = []));
897
+ let Z = w(null), Vt = w();
898
+ function Ht(e, t) {
899
+ if (Z.value) return Wt();
900
+ let n = Math.max(12, p.value * 4);
901
+ Z.value = {
902
+ id: null,
903
+ at: [e.x, e.y - n * .6],
904
+ page: t,
905
+ text: "",
906
+ size: n,
907
+ color: f.value
908
+ }, v(() => Vt.value?.focus());
909
+ }
910
+ function Ut(e) {
911
+ Z.value = {
912
+ id: e.id,
913
+ at: e.at,
914
+ page: e.page,
915
+ text: e.text,
916
+ size: e.size,
917
+ color: e.color
918
+ }, v(() => {
919
+ Vt.value?.focus(), Vt.value?.select();
920
+ });
921
+ }
922
+ function Wt() {
923
+ let e = Z.value;
924
+ if (!e) return;
925
+ Z.value = null;
926
+ let t = e.text.replace(/\s+$/, "");
927
+ if (e.id) {
928
+ let n = a.value.find((t) => t.id === e.id);
929
+ if (!n) return;
930
+ t ? n.type === "text" && n.text !== t && U(a.value.map((n) => n.id === e.id ? {
931
+ ...n,
932
+ text: t
933
+ } : n)) : U(a.value.filter((t) => t.id !== e.id));
934
+ } else t && U([...a.value, {
935
+ id: oe(),
936
+ type: "text",
937
+ at: e.at,
938
+ text: t,
939
+ size: e.size,
940
+ color: e.color,
941
+ layer: ot.value,
942
+ page: e.page
943
+ }]);
944
+ }
945
+ let Gt = s(() => {
946
+ let e = Z.value;
947
+ if (!e) return {};
948
+ let t = W.value.zoom, n = e.page === void 0 ? 0 : L(e.page), r = e.text.split("\n");
949
+ return {
950
+ left: `${e.at[0] * t + W.value.x}px`,
951
+ top: `${(e.at[1] + n) * t + W.value.y}px`,
952
+ fontSize: `${e.size * t}px`,
953
+ lineHeight: String(me),
954
+ color: e.color,
955
+ width: `${Math.max(4, ...r.map((e) => e.length + 1)) * .6}em`,
956
+ height: `${r.length * me}em`
957
+ };
958
+ });
959
+ function Kt(e) {
960
+ if (c.value !== "select" || i.readonly) return;
961
+ let t = Ft(G(e), (e) => e.type === "text");
962
+ t && Ut(t);
963
+ }
964
+ let qt = /* @__PURE__ */ new WeakMap();
965
+ function Jt(e) {
966
+ let t = qt.get(e);
967
+ return t || (t = e.type === "stroke" ? { d: de(e) } : e.type === "shape" ? fe(e) : { d: "" }, qt.set(e, t)), t;
968
+ }
969
+ let Yt = s(() => Z.value?.id), Xt = s(() => R.value ? Array.from({ length: Math.max(1, y.value) }, (e, t) => t) : [void 0]), Zt = (e) => lt.value.filter((t) => (e === void 0 || (t.page ?? 0) === e) && t.id !== Yt.value), Qt = s(() => {
970
+ let e = W.value.zoom;
971
+ return {
972
+ x: -W.value.x / e,
973
+ y: -W.value.y / e,
974
+ width: I.value.width / e,
975
+ height: I.value.height / e
976
+ };
977
+ }), Q = `m3d${ne().replace(/[^a-zA-Z0-9-]/g, "")}`, $ = s(() => i.backgroundSize), $t = s(() => K.value?.kind === "pan" || K.value?.kind === "pinch" ? "grabbing" : St.value || c.value === "pan" || i.readonly ? "grab" : c.value === "text" ? "text" : c.value === "select" ? "default" : "crosshair"), en = s(() => h.value.filter((e) => e.visible === !1).map((e) => e.id));
978
+ function tn(e = {}) {
979
+ let t = F.value ? getComputedStyle(F.value).fontFamily : "sans-serif", n = R.value ? e.page ?? 0 : void 0;
980
+ return Ce(a.value, {
981
+ page: n,
982
+ box: R.value ? {
983
+ x: 0,
984
+ y: 0,
985
+ ...i.pageSize
986
+ } : void 0,
987
+ background: e.background === !1 ? void 0 : i.paper,
988
+ hiddenLayers: en.value,
989
+ layers: at.value,
990
+ fontFamily: t
991
+ });
992
+ }
993
+ let nn = (e = {}) => we(tn(e), e.scale ?? 2), rn = null;
994
+ return S(() => {
995
+ let e = F.value;
996
+ e.addEventListener("wheel", It, { passive: !1 });
997
+ let t = () => I.value = {
998
+ width: e.clientWidth,
999
+ height: e.clientHeight
1000
+ };
1001
+ t(), rn = new ResizeObserver(t), rn.observe(e);
1002
+ let n = N.value;
1003
+ n.x === 0 && n.y === 0 && n.zoom === 1 && bt();
1004
+ }), x(() => {
1005
+ rn?.disconnect(), F.value?.removeEventListener("wheel", It);
1006
+ }), ee(Te, {
1007
+ tool: c,
1008
+ color: f,
1009
+ size: p,
1010
+ fill: m,
1011
+ items: s(() => a.value),
1012
+ selection: A,
1013
+ layers: s(() => h.value),
1014
+ setLayers: (e) => h.value = e,
1015
+ layer: s({
1016
+ get: () => ot.value,
1017
+ set: (e) => g.value = e
1018
+ }),
1019
+ mode: s(() => i.mode),
1020
+ pages: y,
1021
+ addPage: () => y.value += 1,
1022
+ zoom: s(() => W.value.zoom),
1023
+ zoomIn: () => yt(1.25),
1024
+ zoomOut: () => yt(.8),
1025
+ fitView: bt,
1026
+ canUndo: s(() => V.value.length > 0),
1027
+ canRedo: s(() => H.value.length > 0),
1028
+ undo: ut,
1029
+ redo: dt,
1030
+ clear: ft,
1031
+ deleteSelection: pt,
1032
+ exportSvg: tn,
1033
+ exportPng: nn
1034
+ }), n({
1035
+ undo: ut,
1036
+ redo: dt,
1037
+ clear: ft,
1038
+ deleteSelection: pt,
1039
+ fitView: bt,
1040
+ zoomIn: () => yt(1.25),
1041
+ zoomOut: () => yt(.8),
1042
+ exportSvg: tn,
1043
+ exportPng: nn,
1044
+ toContent: G
1045
+ }), (e, n) => (C(), u("div", {
1046
+ ref_key: "root",
1047
+ ref: F,
1048
+ class: "m3-draw-canvas relative overflow-hidden bg-surface-container outline-none select-none [touch-action:none]",
1049
+ style: b({ cursor: $t.value }),
1050
+ tabindex: "0",
1051
+ role: "application",
1052
+ "aria-label": t.label ?? O(ue).drawCanvas,
1053
+ onPointerdown: jt,
1054
+ onPointermove: Mt,
1055
+ onPointerup: Nt,
1056
+ onPointercancel: Nt,
1057
+ onLostpointercapture: Nt,
1058
+ onDblclick: Kt,
1059
+ onKeydown: Lt,
1060
+ onKeyup: Rt,
1061
+ onContextmenu: n[2] ||= M(() => {}, ["prevent"])
1062
+ }, [
1063
+ (C(), u("svg", {
1064
+ ref_key: "svgEl",
1065
+ ref: _e,
1066
+ class: "absolute inset-0 size-full",
1067
+ "aria-hidden": "true"
1068
+ }, [d("defs", null, [
1069
+ d("pattern", {
1070
+ id: `${Q}-grid`,
1071
+ width: $.value,
1072
+ height: $.value,
1073
+ patternUnits: "userSpaceOnUse"
1074
+ }, [d("path", {
1075
+ d: `M${$.value} 0H0V${$.value}`,
1076
+ fill: "none",
1077
+ stroke: "rgba(0,0,0,.12)",
1078
+ "stroke-width": 1 / W.value.zoom
1079
+ }, null, 8, ke)], 8, Oe),
1080
+ d("pattern", {
1081
+ id: `${Q}-dots`,
1082
+ width: $.value,
1083
+ height: $.value,
1084
+ patternUnits: "userSpaceOnUse"
1085
+ }, [d("circle", {
1086
+ cx: $.value / 2,
1087
+ cy: $.value / 2,
1088
+ r: Math.max(.8, 1.2 / W.value.zoom),
1089
+ fill: "rgba(0,0,0,.22)"
1090
+ }, null, 8, je)], 8, Ae),
1091
+ d("pattern", {
1092
+ id: `${Q}-lines`,
1093
+ width: $.value * 4,
1094
+ height: $.value * 1.25,
1095
+ patternUnits: "userSpaceOnUse"
1096
+ }, [d("path", {
1097
+ d: `M0 ${$.value * 1.25 - .5}H${$.value * 4}`,
1098
+ fill: "none",
1099
+ stroke: "rgba(30,90,200,.22)",
1100
+ "stroke-width": 1 / W.value.zoom
1101
+ }, null, 8, Ne)], 8, Me),
1102
+ (C(!0), u(o, null, T(R.value ? Xt.value : [], (e) => (C(), u("clipPath", {
1103
+ id: `${Q}-page${e}`,
1104
+ key: e ?? "x"
1105
+ }, [d("rect", {
1106
+ x: "0",
1107
+ y: "0",
1108
+ width: t.pageSize.width,
1109
+ height: t.pageSize.height
1110
+ }, null, 8, Fe)], 8, Pe))), 128))
1111
+ ]), d("g", { transform: `translate(${W.value.x} ${W.value.y}) scale(${W.value.zoom})` }, [
1112
+ R.value ? l("", !0) : (C(), u(o, { key: 0 }, [
1113
+ d("rect", _(Qt.value, { fill: t.paper }), null, 16, Le),
1114
+ t.backgroundImage ? (C(), u("image", {
1115
+ key: 0,
1116
+ href: t.backgroundImage,
1117
+ x: "0",
1118
+ y: "0"
1119
+ }, null, 8, Re)) : l("", !0),
1120
+ t.background === "none" ? l("", !0) : (C(), u("rect", _({ key: 1 }, Qt.value, { fill: `url(#${Q}-${t.background})` }), null, 16, ze))
1121
+ ], 64)),
1122
+ (C(!0), u(o, null, T(Xt.value, (e) => (C(), u("g", {
1123
+ key: e ?? "all",
1124
+ transform: e === void 0 ? void 0 : `translate(0 ${L(e)})`
1125
+ }, [e === void 0 ? l("", !0) : (C(), u(o, { key: 0 }, [
1126
+ d("rect", {
1127
+ x: "0",
1128
+ y: "0",
1129
+ width: t.pageSize.width,
1130
+ height: t.pageSize.height,
1131
+ fill: t.paper,
1132
+ class: "m3-draw-page"
1133
+ }, null, 8, Ve),
1134
+ t.backgroundImage ? (C(), u("image", {
1135
+ key: 0,
1136
+ href: t.backgroundImage,
1137
+ x: "0",
1138
+ y: "0",
1139
+ width: t.pageSize.width,
1140
+ height: t.pageSize.height,
1141
+ preserveAspectRatio: "xMidYMid meet"
1142
+ }, null, 8, He)) : l("", !0),
1143
+ t.background === "none" ? l("", !0) : (C(), u("rect", {
1144
+ key: 1,
1145
+ x: "0",
1146
+ y: "0",
1147
+ width: t.pageSize.width,
1148
+ height: t.pageSize.height,
1149
+ fill: `url(#${Q}-${t.background})`
1150
+ }, null, 8, Ue))
1151
+ ], 64)), d("g", { "clip-path": e === void 0 ? void 0 : `url(#${Q}-page${e})` }, [(C(!0), u(o, null, T(Zt(e), (e) => (C(), u(o, { key: e.id }, [e.type === "stroke" ? (C(), u("path", {
1152
+ key: 0,
1153
+ d: Jt(e).d,
1154
+ fill: e.color,
1155
+ "fill-opacity": O(se)[e.pen].opacity
1156
+ }, null, 8, Ge)) : e.type === "shape" ? (C(), u(o, { key: 1 }, [d("path", {
1157
+ d: Jt(e).d,
1158
+ fill: e.fill && (e.shape === "rect" || e.shape === "ellipse") ? e.fill : "none",
1159
+ stroke: e.color,
1160
+ "stroke-width": e.size,
1161
+ "stroke-linecap": "round",
1162
+ "stroke-linejoin": "round"
1163
+ }, null, 8, Ke), Jt(e).head ? (C(), u("path", {
1164
+ key: 0,
1165
+ d: Jt(e).head,
1166
+ fill: e.color
1167
+ }, null, 8, qe)) : l("", !0)], 64)) : (C(), u("text", {
1168
+ key: 2,
1169
+ x: e.at[0],
1170
+ y: e.at[1],
1171
+ "font-size": e.size,
1172
+ fill: e.color,
1173
+ class: "m3-draw-text"
1174
+ }, [(C(!0), u(o, null, T(e.text.split("\n"), (t, n) => (C(), u("tspan", {
1175
+ key: n,
1176
+ x: e.at[0],
1177
+ dy: n ? e.size * O(me) : e.size * .95
1178
+ }, te(t || " "), 9, Ye))), 128))], 8, Je))], 64))), 128)), Y.value && (e === void 0 || Y.value.page === e) ? (C(), u(o, { key: 0 }, [Y.value.type === "stroke" ? (C(), u("path", {
1179
+ key: 0,
1180
+ d: O(de)(Y.value),
1181
+ fill: Y.value.color,
1182
+ "fill-opacity": O(se)[Y.value.pen].opacity
1183
+ }, null, 8, Xe)) : Y.value.type === "shape" ? (C(), u(o, { key: 1 }, [d("path", {
1184
+ d: O(fe)(Y.value).d,
1185
+ fill: Y.value.fill && (Y.value.shape === "rect" || Y.value.shape === "ellipse") ? Y.value.fill : "none",
1186
+ stroke: Y.value.color,
1187
+ "stroke-width": Y.value.size,
1188
+ "stroke-linecap": "round",
1189
+ "stroke-linejoin": "round"
1190
+ }, null, 8, Ze), O(fe)(Y.value).head ? (C(), u("path", {
1191
+ key: 0,
1192
+ d: O(fe)(Y.value).head,
1193
+ fill: Y.value.color
1194
+ }, null, 8, Qe)) : l("", !0)], 64)) : l("", !0)], 64)) : l("", !0)], 8, We)], 8, Be))), 128)),
1195
+ wt.value ? (C(), u("polygon", {
1196
+ key: 1,
1197
+ points: wt.value.map((e) => e.join(",")).join(" "),
1198
+ class: "fill-primary/8 stroke-primary",
1199
+ "stroke-width": 1.5 / W.value.zoom,
1200
+ "stroke-dasharray": `${4 / W.value.zoom} ${3 / W.value.zoom}`
1201
+ }, null, 8, $e)) : l("", !0),
1202
+ X.value && c.value === "select" ? (C(), u(o, { key: 2 }, [d("rect", {
1203
+ x: X.value.x - 4 / W.value.zoom,
1204
+ y: X.value.y - 4 / W.value.zoom,
1205
+ width: X.value.width + 8 / W.value.zoom,
1206
+ height: X.value.height + 8 / W.value.zoom,
1207
+ fill: "none",
1208
+ class: "stroke-primary",
1209
+ "stroke-width": 1.5 / W.value.zoom,
1210
+ "stroke-dasharray": `${5 / W.value.zoom} ${4 / W.value.zoom}`
1211
+ }, null, 8, et), (C(!0), u(o, null, T(zt.value, (e) => (C(), u("rect", {
1212
+ key: e.id,
1213
+ x: e.x - it / 2 / W.value.zoom,
1214
+ y: e.y - it / 2 / W.value.zoom,
1215
+ width: it / W.value.zoom,
1216
+ height: it / W.value.zoom,
1217
+ rx: 2 / W.value.zoom,
1218
+ class: "fill-surface stroke-primary",
1219
+ "stroke-width": 1.5 / W.value.zoom,
1220
+ style: b({ cursor: e.cursor })
1221
+ }, null, 12, tt))), 128))], 64)) : l("", !0)
1222
+ ], 8, Ie)], 512)),
1223
+ Z.value ? j((C(), u("textarea", {
1224
+ key: 0,
1225
+ ref_key: "textarea",
1226
+ ref: Vt,
1227
+ "onUpdate:modelValue": n[0] ||= (e) => Z.value.text = e,
1228
+ "data-draw-overlay": "",
1229
+ class: "m3-draw-text absolute resize-none overflow-hidden border-0 bg-transparent p-0 whitespace-pre outline-1 outline-primary outline-dashed",
1230
+ style: b(Gt.value),
1231
+ "aria-label": O(ue).drawText,
1232
+ spellcheck: "false",
1233
+ onBlur: Wt,
1234
+ onKeydown: [ae(M(Wt, ["prevent"]), ["esc"]), n[1] ||= M(() => {}, ["stop"])]
1235
+ }, null, 44, nt)), [[re, Z.value.text]]) : l("", !0),
1236
+ E(e.$slots, "default")
1237
+ ], 44, De));
1238
+ }
1239
+ }), ot = ["aria-label"], st = {
1240
+ key: 1,
1241
+ class: "flex items-center"
1242
+ }, ct = ["aria-label"], B = [
1243
+ "aria-label",
1244
+ "aria-pressed",
1245
+ "onClick"
1246
+ ], lt = ["aria-label", "aria-pressed"], V = {
1247
+ key: 0,
1248
+ class: "material-symbols-outlined text-[16px] text-white drop-shadow",
1249
+ "aria-hidden": "true"
1250
+ }, H = [
1251
+ "aria-label",
1252
+ "aria-pressed",
1253
+ "onClick"
1254
+ ], U = /* @__PURE__ */ m({
1255
+ __name: "MDrawToolbar",
1256
+ props: {
1257
+ tools: { default: () => [
1258
+ "select",
1259
+ "pan",
1260
+ "pen",
1261
+ "brush",
1262
+ "marker",
1263
+ "highlighter",
1264
+ "eraser",
1265
+ "stroke-eraser",
1266
+ "line",
1267
+ "arrow",
1268
+ "rect",
1269
+ "ellipse",
1270
+ "text"
1271
+ ] },
1272
+ colors: { default: () => [
1273
+ "#1d1b20",
1274
+ "#e53935",
1275
+ "#fb8c00",
1276
+ "#fdd835",
1277
+ "#43a047",
1278
+ "#1e88e5",
1279
+ "#8e24aa",
1280
+ "#ffffff"
1281
+ ] },
1282
+ sizes: { default: () => [
1283
+ 2,
1284
+ 4,
1285
+ 8,
1286
+ 16
1287
+ ] },
1288
+ history: {
1289
+ type: Boolean,
1290
+ default: !0
1291
+ },
1292
+ customColor: {
1293
+ type: Boolean,
1294
+ default: !0
1295
+ }
1296
+ },
1297
+ setup(m) {
1298
+ let g = m, _ = h(Te, null);
1299
+ if (!_) throw Error("MDrawToolbar must be inside <MDrawCanvas>");
1300
+ let v = _, x = e(), S = {
1301
+ select: {
1302
+ icon: "arrow_selector_tool",
1303
+ key: "drawSelect"
1304
+ },
1305
+ pan: {
1306
+ icon: "pan_tool",
1307
+ key: "drawPan"
1308
+ },
1309
+ pen: {
1310
+ icon: "ink_pen",
1311
+ key: "drawPen"
1312
+ },
1313
+ brush: {
1314
+ icon: "brush",
1315
+ key: "drawBrush"
1316
+ },
1317
+ marker: {
1318
+ icon: "stylus_note",
1319
+ key: "drawMarker"
1320
+ },
1321
+ highlighter: {
1322
+ icon: "ink_highlighter",
1323
+ key: "drawHighlighter"
1324
+ },
1325
+ eraser: {
1326
+ icon: "ink_eraser",
1327
+ key: "drawEraser"
1328
+ },
1329
+ "stroke-eraser": {
1330
+ icon: "backspace",
1331
+ key: "drawStrokeEraser"
1332
+ },
1333
+ line: {
1334
+ icon: "pen_size_2",
1335
+ key: "drawLine"
1336
+ },
1337
+ arrow: {
1338
+ icon: "arrow_right_alt",
1339
+ key: "drawArrow"
1340
+ },
1341
+ rect: {
1342
+ icon: "rectangle",
1343
+ key: "drawRect"
1344
+ },
1345
+ ellipse: {
1346
+ icon: "circle",
1347
+ key: "drawEllipse"
1348
+ },
1349
+ text: {
1350
+ icon: "text_fields",
1351
+ key: "drawText"
1352
+ }
1353
+ }, ee = [
1354
+ ["select"],
1355
+ ["pan"],
1356
+ [
1357
+ "pen",
1358
+ "brush",
1359
+ "marker",
1360
+ "highlighter"
1361
+ ],
1362
+ ["eraser", "stroke-eraser"],
1363
+ [
1364
+ "line",
1365
+ "arrow",
1366
+ "rect",
1367
+ "ellipse"
1368
+ ],
1369
+ ["text"]
1370
+ ], D = s(() => ee.map((e) => e.filter((e) => g.tools.includes(e))).filter((e) => e.length)), ne = w({}), k = (e, t) => e.includes(v.tool.value) ? v.tool.value : ne.value[t] ?? e[0];
1371
+ ie(v.tool, (e) => {
1372
+ let t = D.value.findIndex((t) => t.includes(e));
1373
+ t >= 0 && (ne.value = {
1374
+ ...ne.value,
1375
+ [t]: e
1376
+ });
1377
+ }, { immediate: !0 });
1378
+ let re = s(() => ["rect", "ellipse"].includes(v.tool.value)), j = (e) => x[S[e].key], ae = w(!1), M = s(() => !g.colors.some((e) => e.toLowerCase() === v.color.value.toLowerCase()));
1379
+ return (e, s) => (C(), u("div", {
1380
+ class: "m3-draw-toolbar flex max-w-[calc(100%-16px)] items-center gap-0.5 overflow-x-auto rounded-full bg-surface-container px-2 py-1 text-on-surface shadow-elevation-3 [scrollbar-width:none]",
1381
+ role: "toolbar",
1382
+ "aria-label": O(x).drawTools
1383
+ }, [
1384
+ E(e.$slots, "default"),
1385
+ (C(!0), u(o, null, T(D.value, (e, n) => (C(), u(o, { key: n }, [e.length === 1 ? (C(), c(r, {
1386
+ key: 0,
1387
+ text: j(e[0]),
1388
+ placement: "top"
1389
+ }, {
1390
+ default: A(() => [p(t, {
1391
+ icon: S[e[0]].icon,
1392
+ label: j(e[0]),
1393
+ variant: O(v).tool.value === e[0] ? "filled" : "standard",
1394
+ "aria-pressed": O(v).tool.value === e[0],
1395
+ onClick: (t) => O(v).tool.value = e[0]
1396
+ }, null, 8, [
1397
+ "icon",
1398
+ "label",
1399
+ "variant",
1400
+ "aria-pressed",
1401
+ "onClick"
1402
+ ])]),
1403
+ _: 2
1404
+ }, 1032, ["text"])) : (C(), u("div", st, [p(r, {
1405
+ text: j(k(e, n)),
1406
+ placement: "top"
1407
+ }, {
1408
+ default: A(() => [p(t, {
1409
+ icon: S[k(e, n)].icon,
1410
+ label: j(k(e, n)),
1411
+ variant: e.includes(O(v).tool.value) ? "filled" : "standard",
1412
+ "aria-pressed": e.includes(O(v).tool.value),
1413
+ onClick: (t) => O(v).tool.value = k(e, n)
1414
+ }, null, 8, [
1415
+ "icon",
1416
+ "label",
1417
+ "variant",
1418
+ "aria-pressed",
1419
+ "onClick"
1420
+ ])]),
1421
+ _: 2
1422
+ }, 1032, ["text"]), p(i, null, {
1423
+ trigger: A(() => [d("button", {
1424
+ type: "button",
1425
+ class: "flex h-10 w-4 items-center justify-center rounded-full text-on-surface-variant hover:bg-on-surface/8",
1426
+ "aria-label": O(x).drawMore
1427
+ }, [...s[7] ||= [d("span", {
1428
+ class: "material-symbols-outlined text-[18px]",
1429
+ "aria-hidden": "true"
1430
+ }, "arrow_drop_down", -1)]], 8, ct)]),
1431
+ default: A(() => [(C(!0), u(o, null, T(e, (e) => (C(), c(a, {
1432
+ key: e,
1433
+ icon: S[e].icon,
1434
+ selected: O(v).tool.value === e,
1435
+ onClick: (t) => O(v).tool.value = e
1436
+ }, {
1437
+ default: A(() => [f(te(j(e)), 1)]),
1438
+ _: 2
1439
+ }, 1032, [
1440
+ "icon",
1441
+ "selected",
1442
+ "onClick"
1443
+ ]))), 128))]),
1444
+ _: 2
1445
+ }, 1024)]))], 64))), 128)),
1446
+ re.value ? (C(), c(r, {
1447
+ key: 0,
1448
+ text: O(x).drawFill,
1449
+ placement: "top"
1450
+ }, {
1451
+ default: A(() => [p(t, {
1452
+ icon: "format_color_fill",
1453
+ label: O(x).drawFill,
1454
+ variant: O(v).fill.value ? "tonal" : "standard",
1455
+ "aria-pressed": O(v).fill.value,
1456
+ onClick: s[0] ||= (e) => O(v).fill.value = !O(v).fill.value
1457
+ }, null, 8, [
1458
+ "label",
1459
+ "variant",
1460
+ "aria-pressed"
1461
+ ])]),
1462
+ _: 1
1463
+ }, 8, ["text"])) : l("", !0),
1464
+ s[9] ||= d("span", { class: "mx-1 h-6 w-px shrink-0 bg-outline-variant" }, null, -1),
1465
+ (C(!0), u(o, null, T(m.colors, (e) => (C(), u("button", {
1466
+ key: e,
1467
+ type: "button",
1468
+ class: y(["m-0.5 size-7 shrink-0 rounded-full border border-outline-variant outline-offset-2 transition-[outline-color] duration-150", O(v).color.value.toLowerCase() === e.toLowerCase() ? "outline-2 outline-primary" : "outline-2 outline-transparent"]),
1469
+ style: b({ background: e }),
1470
+ "aria-label": `${O(x).drawColor} ${e}`,
1471
+ "aria-pressed": O(v).color.value.toLowerCase() === e.toLowerCase(),
1472
+ onClick: (t) => O(v).color.value = e
1473
+ }, null, 14, B))), 128)),
1474
+ m.customColor ? (C(), c(r, {
1475
+ key: 1,
1476
+ text: O(x).drawCustomColor,
1477
+ placement: "top"
1478
+ }, {
1479
+ default: A(() => [d("button", {
1480
+ type: "button",
1481
+ class: y(["m-0.5 flex size-7 shrink-0 items-center justify-center rounded-full outline-offset-2 transition-[outline-color] duration-150", M.value ? "outline-2 outline-primary" : "outline-2 outline-transparent"]),
1482
+ style: b({ background: M.value ? O(v).color.value : "conic-gradient(#f44336, #ffeb3b, #4caf50, #00bcd4, #3f51b5, #e91e63, #f44336)" }),
1483
+ "aria-label": O(x).drawCustomColor,
1484
+ "aria-pressed": M.value,
1485
+ onClick: s[1] ||= (e) => ae.value = !0
1486
+ }, [M.value ? l("", !0) : (C(), u("span", V, "add"))], 14, lt)]),
1487
+ _: 1
1488
+ }, 8, ["text"])) : l("", !0),
1489
+ m.customColor ? (C(), c(n, {
1490
+ key: 2,
1491
+ modelValue: O(v).color.value,
1492
+ "onUpdate:modelValue": s[2] ||= (e) => O(v).color.value = e,
1493
+ show: ae.value,
1494
+ "onUpdate:show": s[3] ||= (e) => ae.value = e
1495
+ }, null, 8, ["modelValue", "show"])) : l("", !0),
1496
+ s[10] ||= d("span", { class: "mx-1 h-6 w-px shrink-0 bg-outline-variant" }, null, -1),
1497
+ (C(!0), u(o, null, T(m.sizes, (e) => (C(), u("button", {
1498
+ key: e,
1499
+ type: "button",
1500
+ class: y(["flex size-9 shrink-0 items-center justify-center rounded-full transition-colors", O(v).size.value === e ? "bg-secondary-container" : "hover:bg-on-surface/8"]),
1501
+ "aria-label": `${O(x).drawSize} ${e}`,
1502
+ "aria-pressed": O(v).size.value === e,
1503
+ onClick: (t) => O(v).size.value = e
1504
+ }, [d("span", {
1505
+ class: "rounded-full bg-on-surface",
1506
+ style: b({
1507
+ width: `${Math.min(20, Math.max(3, e * 1.2))}px`,
1508
+ height: `${Math.min(20, Math.max(3, e * 1.2))}px`
1509
+ })
1510
+ }, null, 4)], 10, H))), 128)),
1511
+ m.history ? (C(), u(o, { key: 3 }, [
1512
+ s[8] ||= d("span", { class: "mx-1 h-6 w-px shrink-0 bg-outline-variant" }, null, -1),
1513
+ p(r, {
1514
+ text: O(x).drawUndo,
1515
+ placement: "top"
1516
+ }, {
1517
+ default: A(() => [p(t, {
1518
+ icon: "undo",
1519
+ label: O(x).drawUndo,
1520
+ disabled: !O(v).canUndo.value,
1521
+ onClick: s[4] ||= (e) => O(v).undo()
1522
+ }, null, 8, ["label", "disabled"])]),
1523
+ _: 1
1524
+ }, 8, ["text"]),
1525
+ p(r, {
1526
+ text: O(x).drawRedo,
1527
+ placement: "top"
1528
+ }, {
1529
+ default: A(() => [p(t, {
1530
+ icon: "redo",
1531
+ label: O(x).drawRedo,
1532
+ disabled: !O(v).canRedo.value,
1533
+ onClick: s[5] ||= (e) => O(v).redo()
1534
+ }, null, 8, ["label", "disabled"])]),
1535
+ _: 1
1536
+ }, 8, ["text"])
1537
+ ], 64)) : l("", !0),
1538
+ O(v).selection.value.length ? (C(), c(r, {
1539
+ key: 4,
1540
+ text: O(x).drawDelete,
1541
+ placement: "top"
1542
+ }, {
1543
+ default: A(() => [p(t, {
1544
+ icon: "delete",
1545
+ label: O(x).drawDelete,
1546
+ onClick: s[6] ||= (e) => O(v).deleteSelection()
1547
+ }, null, 8, ["label"])]),
1548
+ _: 1
1549
+ }, 8, ["text"])) : l("", !0),
1550
+ E(e.$slots, "end")
1551
+ ], 8, ot));
1552
+ }
1553
+ }), ut = ["aria-label"], dt = { class: "flex items-center pb-1 pl-2" }, ft = { class: "flex-1 text-title-small" }, pt = [
1554
+ "value",
1555
+ "aria-label",
1556
+ "onKeydown",
1557
+ "onBlur"
1558
+ ], W = [
1559
+ "aria-pressed",
1560
+ "onClick",
1561
+ "onDblclick"
1562
+ ], G = { class: "hidden flex-col group-hover:flex group-focus-within:flex" }, mt = ["aria-label", "onClick"], ht = ["aria-label", "onClick"], gt = /* @__PURE__ */ m({
1563
+ __name: "MDrawLayers",
1564
+ setup(n) {
1565
+ let i = h(Te, null);
1566
+ if (!i) throw Error("MDrawLayers must be inside <MDrawCanvas>");
1567
+ let a = i, f = e(), m = s(() => a.layers.value.length ? a.layers.value : [{
1568
+ id: "layer-1",
1569
+ name: f.drawLayer.replace("{n}", "1")
1570
+ }]), g = s(() => m.value.slice().reverse()), _ = (e) => a.setLayers(e), b = (e, t) => _(m.value.map((n) => n.id === e ? {
1571
+ ...n,
1572
+ ...t
1573
+ } : n));
1574
+ function x() {
1575
+ let e = {
1576
+ id: oe(),
1577
+ name: f.drawLayer.replace("{n}", String(m.value.length + 1))
1578
+ };
1579
+ _([...m.value, e]), a.layer.value = e.id;
1580
+ }
1581
+ function S(e) {
1582
+ if (m.value.length < 2) return;
1583
+ let t = m.value[0].id, n = a.items.value.filter((n) => (n.layer ?? t) === e).map((e) => e.id);
1584
+ n.length && (a.selection.value = n, a.deleteSelection());
1585
+ let r = m.value.filter((t) => t.id !== e);
1586
+ _(r), a.layer.value === e && (a.layer.value = r[r.length - 1].id);
1587
+ }
1588
+ function ee(e, t) {
1589
+ let n = m.value.findIndex((t) => t.id === e), r = n + t;
1590
+ if (r < 0 || r >= m.value.length) return;
1591
+ let i = m.value.slice();
1592
+ [i[n], i[r]] = [i[r], i[n]], _(i);
1593
+ }
1594
+ let E = w(""), D = w();
1595
+ function ne(e) {
1596
+ E.value = e, v(() => D.value?.[0]?.select());
1597
+ }
1598
+ function k(e, t) {
1599
+ E.value === e && (E.value = "", t.trim() && b(e, { name: t.trim() }));
1600
+ }
1601
+ return (e, n) => (C(), u("div", {
1602
+ class: "m3-draw-layers flex w-64 flex-col rounded-xl bg-surface-container p-2 text-on-surface shadow-elevation-2",
1603
+ role: "group",
1604
+ "aria-label": O(f).drawLayers
1605
+ }, [d("div", dt, [d("span", ft, te(O(f).drawLayers), 1), p(r, {
1606
+ text: O(f).drawAddLayer,
1607
+ placement: "left"
1608
+ }, {
1609
+ default: A(() => [p(t, {
1610
+ icon: "add",
1611
+ size: "xs",
1612
+ label: O(f).drawAddLayer,
1613
+ onClick: x
1614
+ }, null, 8, ["label"])]),
1615
+ _: 1
1616
+ }, 8, ["text"])]), (C(!0), u(o, null, T(g.value, (e) => (C(), u("div", {
1617
+ key: e.id,
1618
+ class: y(["group flex h-10 items-center gap-1 rounded-full pr-1 pl-3 text-body-medium", O(a).layer.value === e.id ? "bg-secondary-container text-on-secondary-container" : "hover:bg-on-surface/8"])
1619
+ }, [
1620
+ E.value === e.id ? (C(), u("input", {
1621
+ key: 0,
1622
+ ref_for: !0,
1623
+ ref_key: "input",
1624
+ ref: D,
1625
+ value: e.name,
1626
+ "aria-label": O(f).drawLayerName,
1627
+ class: "h-7 min-w-0 flex-1 rounded-xs bg-surface px-1 ring-1 ring-primary outline-none",
1628
+ onKeydown: [ae((t) => k(e.id, t.target.value), ["enter"]), n[0] ||= ae((e) => E.value = "", ["esc"])],
1629
+ onBlur: (t) => k(e.id, t.target.value)
1630
+ }, null, 40, pt)) : (C(), u("button", {
1631
+ key: 1,
1632
+ type: "button",
1633
+ class: y(["min-w-0 flex-1 truncate text-left outline-none", e.visible === !1 && "opacity-50"]),
1634
+ "aria-pressed": O(a).layer.value === e.id,
1635
+ onClick: (t) => O(a).layer.value = e.id,
1636
+ onDblclick: (t) => ne(e.id)
1637
+ }, te(e.name), 43, W)),
1638
+ p(r, {
1639
+ text: e.visible === !1 ? O(f).drawShowLayer : O(f).drawHideLayer,
1640
+ placement: "left"
1641
+ }, {
1642
+ default: A(() => [p(t, {
1643
+ icon: e.visible === !1 ? "visibility_off" : "visibility",
1644
+ size: "xs",
1645
+ label: e.visible === !1 ? O(f).drawShowLayer : O(f).drawHideLayer,
1646
+ onClick: (t) => b(e.id, { visible: e.visible === !1 })
1647
+ }, null, 8, [
1648
+ "icon",
1649
+ "label",
1650
+ "onClick"
1651
+ ])]),
1652
+ _: 2
1653
+ }, 1032, ["text"]),
1654
+ p(r, {
1655
+ text: e.locked ? O(f).drawUnlockLayer : O(f).drawLockLayer,
1656
+ placement: "left"
1657
+ }, {
1658
+ default: A(() => [p(t, {
1659
+ icon: e.locked ? "lock" : "lock_open",
1660
+ size: "xs",
1661
+ label: e.locked ? O(f).drawUnlockLayer : O(f).drawLockLayer,
1662
+ onClick: (t) => b(e.id, { locked: !e.locked })
1663
+ }, null, 8, [
1664
+ "icon",
1665
+ "label",
1666
+ "onClick"
1667
+ ])]),
1668
+ _: 2
1669
+ }, 1032, ["text"]),
1670
+ d("div", G, [d("button", {
1671
+ type: "button",
1672
+ class: "h-4 leading-none text-on-surface-variant",
1673
+ "aria-label": O(f).drawLayerUp,
1674
+ onClick: (t) => ee(e.id, 1)
1675
+ }, [...n[1] ||= [d("span", {
1676
+ class: "material-symbols-outlined text-[16px]",
1677
+ "aria-hidden": "true"
1678
+ }, "arrow_drop_up", -1)]], 8, mt), d("button", {
1679
+ type: "button",
1680
+ class: "h-4 leading-none text-on-surface-variant",
1681
+ "aria-label": O(f).drawLayerDown,
1682
+ onClick: (t) => ee(e.id, -1)
1683
+ }, [...n[2] ||= [d("span", {
1684
+ class: "material-symbols-outlined text-[16px]",
1685
+ "aria-hidden": "true"
1686
+ }, "arrow_drop_down", -1)]], 8, ht)]),
1687
+ m.value.length > 1 ? (C(), c(t, {
1688
+ key: 2,
1689
+ icon: "delete",
1690
+ size: "xs",
1691
+ label: O(f).drawDeleteLayer,
1692
+ onClick: (t) => S(e.id)
1693
+ }, null, 8, ["label", "onClick"])) : l("", !0)
1694
+ ], 2))), 128))], 8, ut));
1695
+ }
1696
+ });
1697
+ //#endregion
1698
+ export { at as MDrawCanvas, gt as MDrawLayers, U as MDrawToolbar, pe as constrain, oe as drawId, ye as eraseAt, ve as hitItem, be as inLasso, he as itemBox, z as itemSvg, fe as shapePath, le as simulatePressure, ce as smoothPoints, Se as sortByLayer, de as strokePath, we as svgToPng, F as textBox, Ce as toDrawSvg, xe as transformItem, ge as unionBox, Ee as useDrawing };
1699
+
1700
+ //# sourceMappingURL=draw.js.map