@m3ui-vue/m3ui-vue 1.2.2 → 1.3.1

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