@pairdraw/vue 0.17.0 → 0.19.0-beta.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 (254) hide show
  1. package/dist/canvas/CanvasRoot.vue.js +4 -1
  2. package/dist/canvas/CanvasRoot.vue.js.map +1 -1
  3. package/dist/canvas/drop/use.d.ts.map +1 -1
  4. package/dist/canvas/drop/use.js +5 -3
  5. package/dist/canvas/drop/use.js.map +1 -1
  6. package/dist/canvas/guides/input.js +2 -1
  7. package/dist/canvas/guides/input.js.map +1 -1
  8. package/dist/canvas/pen/input.js +20 -6
  9. package/dist/canvas/pen/input.js.map +1 -1
  10. package/dist/canvas/surface/gl-surface.js +82 -4
  11. package/dist/canvas/surface/gl-surface.js.map +1 -1
  12. package/dist/canvas/surface/kit-loader.js +22 -14
  13. package/dist/canvas/surface/kit-loader.js.map +1 -1
  14. package/dist/canvas/surface/lifecycle.js +41 -3
  15. package/dist/canvas/surface/lifecycle.js.map +1 -1
  16. package/dist/canvas/surface/resize-observer.js +11 -4
  17. package/dist/canvas/surface/resize-observer.js.map +1 -1
  18. package/dist/canvas/surface/types.d.ts +16 -0
  19. package/dist/canvas/surface/types.d.ts.map +1 -1
  20. package/dist/canvas/surface/use.d.ts +1 -0
  21. package/dist/canvas/surface/use.js +3 -1
  22. package/dist/canvas/surface/use.js.map +1 -1
  23. package/dist/canvas/text-edit/editing.js +11 -8
  24. package/dist/canvas/text-edit/editing.js.map +1 -1
  25. package/dist/canvas/text-edit/keyboard.js +12 -0
  26. package/dist/canvas/text-edit/keyboard.js.map +1 -1
  27. package/dist/canvas/useCanvasInput.d.ts +240 -0
  28. package/dist/controls/appearance/use.d.ts +1 -1
  29. package/dist/controls/layout/helpers.d.ts.map +1 -1
  30. package/dist/controls/layout/helpers.js +36 -7
  31. package/dist/controls/layout/helpers.js.map +1 -1
  32. package/dist/controls/layout/use.d.ts +1 -0
  33. package/dist/controls/layout/use.d.ts.map +1 -1
  34. package/dist/controls/layout/use.js +3 -0
  35. package/dist/controls/layout/use.js.map +1 -1
  36. package/dist/controls/node-preview/use.js +21 -1
  37. package/dist/controls/node-preview/use.js.map +1 -1
  38. package/dist/controls/position/use.d.ts +2 -1
  39. package/dist/controls/position/use.d.ts.map +1 -1
  40. package/dist/controls/position/use.js +13 -5
  41. package/dist/controls/position/use.js.map +1 -1
  42. package/dist/controls/property-list/use.d.ts.map +1 -1
  43. package/dist/controls/property-list/use.js +27 -5
  44. package/dist/controls/property-list/use.js.map +1 -1
  45. package/dist/controls/selection-layout/use.d.ts.map +1 -1
  46. package/dist/controls/selection-layout/use.js +3 -2
  47. package/dist/controls/selection-layout/use.js.map +1 -1
  48. package/dist/controls/slots/authoring.d.ts.map +1 -1
  49. package/dist/controls/slots/authoring.js +2 -1
  50. package/dist/controls/slots/authoring.js.map +1 -1
  51. package/dist/controls/typography/actions.js +18 -10
  52. package/dist/controls/typography/actions.js.map +1 -1
  53. package/dist/controls/typography/axes.d.ts.map +1 -1
  54. package/dist/controls/typography/axes.js +62 -19
  55. package/dist/controls/typography/axes.js.map +1 -1
  56. package/dist/editor/commands/registry.d.ts +1 -0
  57. package/dist/editor/commands/registry.d.ts.map +1 -1
  58. package/dist/editor/commands/registry.js +1 -0
  59. package/dist/editor/commands/registry.js.map +1 -1
  60. package/dist/editor/commands/selection.js +12 -3
  61. package/dist/editor/commands/selection.js.map +1 -1
  62. package/dist/editor/commands/types.d.ts +1 -1
  63. package/dist/editor/commands/types.d.ts.map +1 -1
  64. package/dist/editor/menu-model/canvas.js +5 -1
  65. package/dist/editor/menu-model/canvas.js.map +1 -1
  66. package/dist/editor/selection-capabilities/use.d.ts +1 -0
  67. package/dist/editor/selection-capabilities/use.js +4 -0
  68. package/dist/editor/selection-capabilities/use.js.map +1 -1
  69. package/dist/editor/selection-state/nodes.js +2 -2
  70. package/dist/editor/selection-state/nodes.js.map +1 -1
  71. package/dist/i18n/locale.d.ts.map +1 -1
  72. package/dist/i18n/locale.js +16 -6
  73. package/dist/i18n/locale.js.map +1 -1
  74. package/dist/i18n/locales/de/ai.json.js +9 -0
  75. package/dist/i18n/locales/de/automation.json.js +2 -0
  76. package/dist/i18n/locales/de/cloud/portal.json.js +1 -1
  77. package/dist/i18n/locales/de/commands.json.js +1 -0
  78. package/dist/i18n/locales/de/comments.json.js +1 -0
  79. package/dist/i18n/locales/de/diagnostics.json.js +1 -0
  80. package/dist/i18n/locales/de/editor.json.js +2 -2
  81. package/dist/i18n/locales/de/menu.json.js +1 -1
  82. package/dist/i18n/locales/de/variables/panel.json.js +2 -0
  83. package/dist/i18n/locales/es/ai.json.js +9 -0
  84. package/dist/i18n/locales/es/automation.json.js +2 -0
  85. package/dist/i18n/locales/es/cloud/portal.json.js +1 -1
  86. package/dist/i18n/locales/es/commands.json.js +1 -0
  87. package/dist/i18n/locales/es/comments.json.js +1 -0
  88. package/dist/i18n/locales/es/diagnostics.json.js +1 -0
  89. package/dist/i18n/locales/es/editor.json.js +2 -2
  90. package/dist/i18n/locales/es/menu.json.js +1 -1
  91. package/dist/i18n/locales/es/variables/panel.json.js +2 -0
  92. package/dist/i18n/locales/fr/ai.json.js +9 -0
  93. package/dist/i18n/locales/fr/automation.json.js +2 -0
  94. package/dist/i18n/locales/fr/cloud/portal.json.js +1 -1
  95. package/dist/i18n/locales/fr/commands.json.js +1 -0
  96. package/dist/i18n/locales/fr/comments.json.js +1 -0
  97. package/dist/i18n/locales/fr/diagnostics.json.js +1 -0
  98. package/dist/i18n/locales/fr/editor.json.js +2 -2
  99. package/dist/i18n/locales/fr/menu.json.js +1 -1
  100. package/dist/i18n/locales/fr/variables/panel.json.js +2 -0
  101. package/dist/i18n/locales/it/ai.json.js +9 -0
  102. package/dist/i18n/locales/it/automation.json.js +2 -0
  103. package/dist/i18n/locales/it/cloud/portal.json.js +1 -1
  104. package/dist/i18n/locales/it/commands.json.js +1 -0
  105. package/dist/i18n/locales/it/comments.json.js +1 -0
  106. package/dist/i18n/locales/it/diagnostics.json.js +1 -0
  107. package/dist/i18n/locales/it/editor.json.js +2 -2
  108. package/dist/i18n/locales/it/menu.json.js +1 -1
  109. package/dist/i18n/locales/it/variables/panel.json.js +2 -0
  110. package/dist/i18n/locales/ja/ai.json.js +9 -0
  111. package/dist/i18n/locales/ja/automation.json.js +2 -0
  112. package/dist/i18n/locales/ja/cloud/portal.json.js +1 -1
  113. package/dist/i18n/locales/ja/commands.json.js +1 -0
  114. package/dist/i18n/locales/ja/comments.json.js +1 -0
  115. package/dist/i18n/locales/ja/diagnostics.json.js +1 -0
  116. package/dist/i18n/locales/ja/editor.json.js +2 -2
  117. package/dist/i18n/locales/ja/menu.json.js +1 -1
  118. package/dist/i18n/locales/ja/variables/panel.json.js +2 -0
  119. package/dist/i18n/locales/pl/ai.json.js +9 -0
  120. package/dist/i18n/locales/pl/automation.json.js +2 -0
  121. package/dist/i18n/locales/pl/cloud/portal.json.js +1 -1
  122. package/dist/i18n/locales/pl/commands.json.js +1 -0
  123. package/dist/i18n/locales/pl/comments.json.js +1 -0
  124. package/dist/i18n/locales/pl/diagnostics.json.js +1 -0
  125. package/dist/i18n/locales/pl/editor.json.js +2 -2
  126. package/dist/i18n/locales/pl/menu.json.js +1 -1
  127. package/dist/i18n/locales/pl/variables/panel.json.js +2 -0
  128. package/dist/i18n/locales/ru/ai.json.js +9 -0
  129. package/dist/i18n/locales/ru/automation.json.js +2 -0
  130. package/dist/i18n/locales/ru/cloud/portal.json.js +1 -1
  131. package/dist/i18n/locales/ru/commands.json.js +1 -0
  132. package/dist/i18n/locales/ru/comments.json.js +1 -0
  133. package/dist/i18n/locales/ru/diagnostics.json.js +1 -0
  134. package/dist/i18n/locales/ru/editor.json.js +2 -2
  135. package/dist/i18n/locales/ru/menu.json.js +1 -1
  136. package/dist/i18n/locales/ru/variables/panel.json.js +2 -0
  137. package/dist/i18n/locales/zh-cn/ai.json.js +9 -0
  138. package/dist/i18n/locales/zh-cn/automation.json.js +2 -0
  139. package/dist/i18n/locales/zh-cn/cloud/portal.json.js +1 -1
  140. package/dist/i18n/locales/zh-cn/commands.json.js +1 -0
  141. package/dist/i18n/locales/zh-cn/comments.json.js +1 -0
  142. package/dist/i18n/locales/zh-cn/diagnostics.json.js +1 -0
  143. package/dist/i18n/locales/zh-cn/editor.json.js +2 -2
  144. package/dist/i18n/locales/zh-cn/menu.json.js +1 -1
  145. package/dist/i18n/locales/zh-cn/variables/panel.json.js +2 -0
  146. package/dist/i18n/messages/ai.d.ts +20 -0
  147. package/dist/i18n/messages/ai.d.ts.map +1 -1
  148. package/dist/i18n/messages/ai.js +10 -0
  149. package/dist/i18n/messages/ai.js.map +1 -1
  150. package/dist/i18n/messages/automation.d.ts +2 -0
  151. package/dist/i18n/messages/automation.d.ts.map +1 -1
  152. package/dist/i18n/messages/automation.js +2 -0
  153. package/dist/i18n/messages/automation.js.map +1 -1
  154. package/dist/i18n/messages/cloud/portal.d.ts +1 -1
  155. package/dist/i18n/messages/cloud/portal.js +1 -1
  156. package/dist/i18n/messages/cloud/portal.js.map +1 -1
  157. package/dist/i18n/messages/commands.d.ts +1 -0
  158. package/dist/i18n/messages/commands.d.ts.map +1 -1
  159. package/dist/i18n/messages/commands.js +1 -0
  160. package/dist/i18n/messages/commands.js.map +1 -1
  161. package/dist/i18n/messages/comments.d.ts +1 -0
  162. package/dist/i18n/messages/comments.d.ts.map +1 -1
  163. package/dist/i18n/messages/comments.js +1 -0
  164. package/dist/i18n/messages/comments.js.map +1 -1
  165. package/dist/i18n/messages/diagnostics.d.ts +1 -0
  166. package/dist/i18n/messages/diagnostics.d.ts.map +1 -1
  167. package/dist/i18n/messages/diagnostics.js +1 -0
  168. package/dist/i18n/messages/diagnostics.js.map +1 -1
  169. package/dist/i18n/messages/editor.d.ts +1 -1
  170. package/dist/i18n/messages/editor.js +1 -1
  171. package/dist/i18n/messages/editor.js.map +1 -1
  172. package/dist/i18n/messages/menu.d.ts +1 -1
  173. package/dist/i18n/messages/menu.js +1 -1
  174. package/dist/i18n/messages/menu.js.map +1 -1
  175. package/dist/i18n/messages/panels.d.ts +1 -1
  176. package/dist/i18n/messages/panels.js +1 -1
  177. package/dist/i18n/messages/panels.js.map +1 -1
  178. package/dist/i18n/messages/variables/panel.d.ts +2 -0
  179. package/dist/i18n/messages/variables/panel.d.ts.map +1 -1
  180. package/dist/i18n/messages/variables/panel.js +2 -0
  181. package/dist/i18n/messages/variables/panel.js.map +1 -1
  182. package/dist/i18n/messages.d.ts +30 -4
  183. package/dist/i18n/useI18n.d.ts +116 -14
  184. package/dist/i18n/useI18n.d.ts.map +1 -1
  185. package/dist/primitives/ColorPicker/ColorPickerRoot.vue.d.ts +12 -2
  186. package/dist/primitives/ColorPicker/ColorPickerRoot.vue.d.ts.map +1 -1
  187. package/dist/primitives/ColorPicker/ColorPickerRoot.vue.js +39 -10
  188. package/dist/primitives/ColorPicker/ColorPickerRoot.vue.js.map +1 -1
  189. package/dist/primitives/ColorPicker/gesture.d.ts +40 -0
  190. package/dist/primitives/ColorPicker/gesture.d.ts.map +1 -0
  191. package/dist/primitives/ColorPicker/gesture.js +120 -0
  192. package/dist/primitives/ColorPicker/gesture.js.map +1 -0
  193. package/dist/primitives/ColorPicker/index.d.ts +2 -1
  194. package/dist/primitives/ColorPicker/index.js +2 -1
  195. package/dist/primitives/Fill/FillSwatch.vue.d.ts.map +1 -1
  196. package/dist/primitives/Fill/FillSwatch.vue.js +6 -1
  197. package/dist/primitives/Fill/FillSwatch.vue.js.map +1 -1
  198. package/dist/primitives/Fill/types.d.ts +5 -0
  199. package/dist/primitives/Fill/types.d.ts.map +1 -1
  200. package/dist/primitives/Fill/useFill.d.ts.map +1 -1
  201. package/dist/primitives/Fill/useFill.js +15 -7
  202. package/dist/primitives/Fill/useFill.js.map +1 -1
  203. package/dist/primitives/FontPicker/FontPickerRoot.vue.d.ts +1 -0
  204. package/dist/primitives/FontPicker/FontPickerRoot.vue.d.ts.map +1 -1
  205. package/dist/primitives/FontPicker/FontPickerRoot.vue.js +7 -2
  206. package/dist/primitives/FontPicker/FontPickerRoot.vue.js.map +1 -1
  207. package/dist/primitives/LayerTree/LayerTreeRoot.vue.d.ts +2 -0
  208. package/dist/primitives/LayerTree/LayerTreeRoot.vue.d.ts.map +1 -1
  209. package/dist/primitives/LayerTree/LayerTreeRoot.vue.js +14 -3
  210. package/dist/primitives/LayerTree/LayerTreeRoot.vue.js.map +1 -1
  211. package/dist/primitives/LayerTree/model.js +1 -1
  212. package/dist/primitives/LayoutControls/LayoutControlsRoot.vue.d.ts.map +1 -1
  213. package/dist/primitives/LayoutControls/LayoutControlsRoot.vue.js +1 -0
  214. package/dist/primitives/LayoutControls/LayoutControlsRoot.vue.js.map +1 -1
  215. package/dist/primitives/NumberField/NumberFieldRoot.vue.d.ts +2 -2
  216. package/dist/primitives/NumberField/NumberFieldRoot.vue.d.ts.map +1 -1
  217. package/dist/primitives/NumberField/NumberFieldRoot.vue.js +3 -2
  218. package/dist/primitives/NumberField/NumberFieldRoot.vue.js.map +1 -1
  219. package/dist/primitives/NumberField/types.d.ts +5 -0
  220. package/dist/primitives/NumberField/types.d.ts.map +1 -1
  221. package/dist/primitives/PageList/PageListRoot.vue.d.ts +3 -3
  222. package/dist/primitives/PageList/PageListRoot.vue.d.ts.map +1 -1
  223. package/dist/primitives/PageList/PageListRoot.vue.js +3 -2
  224. package/dist/primitives/PageList/PageListRoot.vue.js.map +1 -1
  225. package/dist/primitives/PageList/usePageList.d.ts +1 -1
  226. package/dist/primitives/PageList/usePageList.d.ts.map +1 -1
  227. package/dist/primitives/PositionControls/PositionControlsRoot.vue.d.ts +1 -0
  228. package/dist/primitives/PositionControls/PositionControlsRoot.vue.d.ts.map +1 -1
  229. package/dist/primitives/PositionControls/PositionControlsRoot.vue.js +11 -13
  230. package/dist/primitives/PositionControls/PositionControlsRoot.vue.js.map +1 -1
  231. package/dist/primitives/PropertyList/PropertyListRoot.vue.d.ts.map +1 -1
  232. package/dist/primitives/PropertyList/PropertyListRoot.vue.js +10 -1
  233. package/dist/primitives/PropertyList/PropertyListRoot.vue.js.map +1 -1
  234. package/dist/primitives/PropertyList/index.d.ts +2 -2
  235. package/dist/primitives/PropertyList/types.d.ts +14 -2
  236. package/dist/primitives/PropertyList/types.d.ts.map +1 -1
  237. package/dist/shared/input/drop-target.js +2 -1
  238. package/dist/shared/input/drop-target.js.map +1 -1
  239. package/dist/shared/input/duplicate-drag.js.map +1 -1
  240. package/dist/shared/input/move/drag.js +25 -4
  241. package/dist/shared/input/move/drag.js.map +1 -1
  242. package/dist/shared/input/resize/start.js +2 -1
  243. package/dist/shared/input/resize/start.js.map +1 -1
  244. package/dist/shared/input/select/move.js +8 -3
  245. package/dist/shared/input/select/move.js.map +1 -1
  246. package/dist/shared/input/select.js +22 -12
  247. package/dist/shared/input/select.js.map +1 -1
  248. package/dist/shared/input/types.d.ts +2 -0
  249. package/dist/shared/input/types.d.ts.map +1 -1
  250. package/dist/shared/input/types.js.map +1 -1
  251. package/dist/variables/use.d.ts.map +1 -1
  252. package/dist/variables/use.js +2 -1
  253. package/dist/variables/use.js.map +1 -1
  254. package/package.json +4 -4
@@ -18,8 +18,11 @@ const _sfc_main = /*@__PURE__*/ defineComponent({
18
18
  onFailed: { type: Function },
19
19
  onPresentation: { type: Function },
20
20
  getRenderState: { type: Function },
21
+ getSceneScope: { type: Function },
21
22
  onFrame: { type: Function },
22
- onViewportResize: { type: Function }
23
+ onViewportResize: { type: Function },
24
+ onContextLost: { type: Function },
25
+ onNodeDrawFailure: { type: Function }
23
26
  },
24
27
  setup(__props) {
25
28
  const editor = useEditor();
@@ -1 +1 @@
1
- {"version":3,"file":"CanvasRoot.vue.js","names":[],"sources":["../../src/canvas/CanvasRoot.vue"],"sourcesContent":["<script setup lang=\"ts\">\nimport { ref } from 'vue'\n\nimport { provideCanvas } from '#vue/canvas/context'\nimport { useCanvas, type UseCanvasOptions } from '#vue/canvas/surface/use'\nimport { useEditor } from '#vue/editor/context'\n\nconst { showRulers, preserveDrawingBuffer } = defineProps<UseCanvasOptions>()\n\nconst editor = useEditor()\nconst canvasRef = ref<HTMLCanvasElement | null>(null)\nconst ready = ref(false)\n\nconst { renderNow, hitTestSectionTitle, hitTestComponentLabel, hitTestFrameTitle } = useCanvas(\n canvasRef,\n editor,\n {\n showRulers,\n preserveDrawingBuffer,\n onReady: () => {\n ready.value = true\n }\n }\n)\n\nprovideCanvas({\n canvasRef,\n ready,\n renderNow,\n hitTestSectionTitle,\n hitTestComponentLabel,\n hitTestFrameTitle\n})\n</script>\n\n<template>\n <slot :canvas-ref=\"canvasRef\" :ready=\"ready\" :render-now=\"renderNow\" />\n</template>\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;EASA,MAAM,SAAS,UAAU;EACzB,MAAM,YAAY,IAA8B,IAAI;EACpD,MAAM,QAAQ,IAAI,KAAK;EAEvB,MAAM,EAAE,WAAW,qBAAqB,uBAAuB,sBAAsB,UACnF,WACA,QACA;GACE,YAAS,QAAA;GACT,uBAAoB,QAAA;GACpB,eAAe;IACb,MAAM,QAAQ;GAChB;EACF,CACF;EAEA,cAAc;GACZ;GACA;GACA;GACA;GACA;GACA;EACF,CAAC;;GAIC,OAAA,WAAuE,KAAA,QAAA,WAAA;IAAhE,WAAY,UAAA;IAAY,OAAO,MAAA;IAAQ,WAAY,MAAA,SAAA"}
1
+ {"version":3,"file":"CanvasRoot.vue.js","names":[],"sources":["../../src/canvas/CanvasRoot.vue"],"sourcesContent":["<script setup lang=\"ts\">\nimport { ref } from 'vue'\n\nimport { provideCanvas } from '#vue/canvas/context'\nimport { useCanvas, type UseCanvasOptions } from '#vue/canvas/surface/use'\nimport { useEditor } from '#vue/editor/context'\n\nconst { showRulers, preserveDrawingBuffer } = defineProps<UseCanvasOptions>()\n\nconst editor = useEditor()\nconst canvasRef = ref<HTMLCanvasElement | null>(null)\nconst ready = ref(false)\n\nconst { renderNow, hitTestSectionTitle, hitTestComponentLabel, hitTestFrameTitle } = useCanvas(\n canvasRef,\n editor,\n {\n showRulers,\n preserveDrawingBuffer,\n onReady: () => {\n ready.value = true\n }\n }\n)\n\nprovideCanvas({\n canvasRef,\n ready,\n renderNow,\n hitTestSectionTitle,\n hitTestComponentLabel,\n hitTestFrameTitle\n})\n</script>\n\n<template>\n <slot :canvas-ref=\"canvasRef\" :ready=\"ready\" :render-now=\"renderNow\" />\n</template>\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;EASA,MAAM,SAAS,UAAU;EACzB,MAAM,YAAY,IAA8B,IAAI;EACpD,MAAM,QAAQ,IAAI,KAAK;EAEvB,MAAM,EAAE,WAAW,qBAAqB,uBAAuB,sBAAsB,UACnF,WACA,QACA;GACE,YAAS,QAAA;GACT,uBAAoB,QAAA;GACpB,eAAe;IACb,MAAM,QAAQ;GAChB;EACF,CACF;EAEA,cAAc;GACZ;GACA;GACA;GACA;GACA;GACA;EACF,CAAC;;GAIC,OAAA,WAAuE,KAAA,QAAA,WAAA;IAAhE,WAAY,UAAA;IAAY,OAAO,MAAA;IAAQ,WAAY,MAAA,SAAA"}
@@ -1 +1 @@
1
- {"version":3,"file":"use.d.ts","names":[],"sources":["../../../src/canvas/drop/use.ts"],"mappings":";;;iBAsCgB,cACd,WAAW,IAAI,2BACf,QAAQ,QACR;;;iBAsDc,kBAAkB,OAAO,UAAU,QAAQ,SAAS,eAAe;iBAOnE,+BAA+B,GAAG,iBAAiB"}
1
+ {"version":3,"file":"use.d.ts","names":[],"sources":["../../../src/canvas/drop/use.ts"],"mappings":";;;iBA6CgB,cACd,WAAW,IAAI,2BACf,QAAQ,QACR;;;iBAsDc,kBAAkB,OAAO,UAAU,QAAQ,SAAS,eAAe;iBAOnE,+BAA+B,GAAG,iBAAiB"}
@@ -1,4 +1,5 @@
1
1
  import { cycleSafeTarget, findMoveDropTarget } from "../../shared/input/drop-target.js";
2
+ import { gridRounding } from "../../shared/input/snap.js";
2
3
  import { ref } from "vue";
3
4
  import { useEventListener } from "@vueuse/core";
4
5
  import { IMPORTABLE_RASTER_TYPES, isSVGFile } from "@pairdraw/scene-graph/images";
@@ -19,10 +20,11 @@ function componentDropPlacement(componentId, cx, cy, editor) {
19
20
  x: 0,
20
21
  y: 0
21
22
  } : editor.graph.getAbsolutePosition(parentId);
23
+ const round = gridRounding(editor);
22
24
  return {
23
25
  parentId,
24
- x: cx - parentOffset.x - component.width / 2,
25
- y: cy - parentOffset.y - component.height / 2
26
+ x: round(cx - parentOffset.x - component.width / 2),
27
+ y: round(cy - parentOffset.y - component.height / 2)
26
28
  };
27
29
  }
28
30
  function useCanvasDrop(canvasRef, editor, onActivate) {
@@ -77,6 +79,6 @@ function extractImageFilesFromClipboard(e) {
77
79
  return files ? Array.from(files).filter((file) => IMPORTABLE_RASTER_TYPES.has(file.type)) : [];
78
80
  }
79
81
  //#endregion
80
- export { extractImageFilesFromClipboard, filterCanvasFiles, useCanvasDrop };
82
+ export { componentDropPlacement, extractImageFilesFromClipboard, filterCanvasFiles, useCanvasDrop };
81
83
 
82
84
  //# sourceMappingURL=use.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"use.js","names":[],"sources":["../../../src/canvas/drop/use.ts"],"sourcesContent":["import { useEventListener } from '@vueuse/core'\nimport { ref, type Ref } from 'vue'\n\nimport type { Editor } from '@pairdraw/core'\nimport { IMPORTABLE_RASTER_TYPES, isSVGFile } from '@pairdraw/scene-graph/images'\n\nimport { cycleSafeTarget, findMoveDropTarget } from '#vue/shared/input/drop-target'\n\nconst COMPONENT_MIME = 'application/x-pairdraw-component'\n\nfunction hasComponentData(e: DragEvent): boolean {\n return e.dataTransfer?.types.includes(COMPONENT_MIME) ?? false\n}\n\nfunction dropPoint(e: DragEvent, canvas: HTMLCanvasElement, editor: Editor) {\n const rect = canvas.getBoundingClientRect()\n return editor.screenToCanvas(e.clientX - rect.left, e.clientY - rect.top)\n}\n\nfunction componentDropPlacement(componentId: string, cx: number, cy: number, editor: Editor) {\n const component = editor.graph.getNode(componentId)\n if (component?.type !== 'COMPONENT') return null\n\n // An instance never lands inside its own component; Figma puts it in the nearest frame that can hold it.\n const dragged = new Set([componentId])\n const target = cycleSafeTarget(findMoveDropTarget(cx, cy, editor, dragged), [componentId], editor)\n const parentId = target?.id ?? editor.state.currentPageId\n const parentOffset =\n parentId === editor.state.currentPageId\n ? { x: 0, y: 0 }\n : editor.graph.getAbsolutePosition(parentId)\n return {\n parentId,\n x: cx - parentOffset.x - component.width / 2,\n y: cy - parentOffset.y - component.height / 2\n }\n}\n\nexport function useCanvasDrop(\n canvasRef: Ref<HTMLCanvasElement | null>,\n editor: Editor,\n onActivate?: () => void\n) {\n const isDraggingOver = ref(false)\n\n useEventListener(canvasRef, 'dragover', (e: DragEvent) => {\n if (!hasComponentData(e) && !hasFileData(e)) return\n e.preventDefault()\n if (e.dataTransfer) e.dataTransfer.dropEffect = 'copy'\n isDraggingOver.value = true\n })\n\n useEventListener(canvasRef, 'dragenter', (e: DragEvent) => {\n if (!hasComponentData(e) && !hasFileData(e)) return\n onActivate?.()\n e.preventDefault()\n isDraggingOver.value = true\n })\n\n useEventListener(canvasRef, 'dragleave', () => {\n isDraggingOver.value = false\n })\n\n useEventListener(canvasRef, 'drop', (e: DragEvent) => {\n onActivate?.()\n e.preventDefault()\n isDraggingOver.value = false\n\n const canvas = canvasRef.value\n if (!canvas) return\n const point = dropPoint(e, canvas, editor)\n\n const componentId = e.dataTransfer?.getData(COMPONENT_MIME)\n if (componentId) {\n const placement = componentDropPlacement(componentId, point.x, point.y, editor)\n if (!placement) return\n editor.createInstanceFromComponent(componentId, placement.x, placement.y, placement.parentId)\n editor.requestRender()\n return\n }\n\n const files = filterCanvasFiles(e.dataTransfer?.files ?? null)\n if (!files.length) return\n void editor.placeFiles(files, point.x, point.y).catch((error: unknown) => {\n console.error('Failed to place dropped files', error)\n })\n })\n\n return { isDraggingOver }\n}\n\nfunction hasFileData(e: DragEvent): boolean {\n return e.dataTransfer?.types.includes('Files') ?? false\n}\n\nexport function filterCanvasFiles(files: ArrayLike<File> | Iterable<File> | null): File[] {\n if (!files) return []\n return Array.from(files).filter(\n (file) => IMPORTABLE_RASTER_TYPES.has(file.type) || isSVGFile(file)\n )\n}\n\nexport function extractImageFilesFromClipboard(e: ClipboardEvent): File[] {\n const files = e.clipboardData?.files\n return files ? Array.from(files).filter((file) => IMPORTABLE_RASTER_TYPES.has(file.type)) : []\n}\n"],"mappings":";;;;;AAQA,MAAM,iBAAiB;AAEvB,SAAS,iBAAiB,GAAuB;CAC/C,OAAO,EAAE,cAAc,MAAM,SAAS,cAAc,KAAK;AAC3D;AAEA,SAAS,UAAU,GAAc,QAA2B,QAAgB;CAC1E,MAAM,OAAO,OAAO,sBAAsB;CAC1C,OAAO,OAAO,eAAe,EAAE,UAAU,KAAK,MAAM,EAAE,UAAU,KAAK,GAAG;AAC1E;AAEA,SAAS,uBAAuB,aAAqB,IAAY,IAAY,QAAgB;CAC3F,MAAM,YAAY,OAAO,MAAM,QAAQ,WAAW;CAClD,IAAI,WAAW,SAAS,aAAa,OAAO;CAK5C,MAAM,WADS,gBAAgB,mBAAmB,IAAI,IAAI,wBAAQ,IAD9C,IAAI,CAAC,WAAW,CACoC,CAAC,GAAG,CAAC,WAAW,GAAG,MACrE,CAAC,EAAE,MAAM,OAAO,MAAM;CAC5C,MAAM,eACJ,aAAa,OAAO,MAAM,gBACtB;EAAE,GAAG;EAAG,GAAG;CAAE,IACb,OAAO,MAAM,oBAAoB,QAAQ;CAC/C,OAAO;EACL;EACA,GAAG,KAAK,aAAa,IAAI,UAAU,QAAQ;EAC3C,GAAG,KAAK,aAAa,IAAI,UAAU,SAAS;CAC9C;AACF;AAEA,SAAgB,cACd,WACA,QACA,YACA;CACA,MAAM,iBAAiB,IAAI,KAAK;CAEhC,iBAAiB,WAAW,aAAa,MAAiB;EACxD,IAAI,CAAC,iBAAiB,CAAC,KAAK,CAAC,YAAY,CAAC,GAAG;EAC7C,EAAE,eAAe;EACjB,IAAI,EAAE,cAAc,EAAE,aAAa,aAAa;EAChD,eAAe,QAAQ;CACzB,CAAC;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,CAAC,CAAC,QAAQ,SAAS,wBAAwB,IAAI,KAAK,IAAI,CAAC,IAAI,CAAC;AAC/F"}
1
+ {"version":3,"file":"use.js","names":[],"sources":["../../../src/canvas/drop/use.ts"],"sourcesContent":["import { useEventListener } from '@vueuse/core'\nimport { ref, type Ref } from 'vue'\n\nimport type { Editor } from '@pairdraw/core'\nimport { IMPORTABLE_RASTER_TYPES, isSVGFile } from '@pairdraw/scene-graph/images'\n\nimport { cycleSafeTarget, findMoveDropTarget } from '#vue/shared/input/drop-target'\nimport { gridRounding } from '#vue/shared/input/snap'\n\nconst COMPONENT_MIME = 'application/x-pairdraw-component'\n\nfunction hasComponentData(e: DragEvent): boolean {\n return e.dataTransfer?.types.includes(COMPONENT_MIME) ?? false\n}\n\nfunction dropPoint(e: DragEvent, canvas: HTMLCanvasElement, editor: Editor) {\n const rect = canvas.getBoundingClientRect()\n return editor.screenToCanvas(e.clientX - rect.left, e.clientY - rect.top)\n}\n\nexport function componentDropPlacement(\n componentId: string,\n cx: number,\n cy: number,\n editor: Editor\n) {\n const component = editor.graph.getNode(componentId)\n if (component?.type !== 'COMPONENT') return null\n\n // An instance never lands inside its own component; Figma puts it in the nearest frame that can hold it.\n const dragged = new Set([componentId])\n const target = cycleSafeTarget(findMoveDropTarget(cx, cy, editor, dragged), [componentId], editor)\n const parentId = target?.id ?? editor.state.currentPageId\n const parentOffset =\n parentId === editor.state.currentPageId\n ? { x: 0, y: 0 }\n : editor.graph.getAbsolutePosition(parentId)\n const round = gridRounding(editor)\n return {\n parentId,\n x: round(cx - parentOffset.x - component.width / 2),\n y: round(cy - parentOffset.y - component.height / 2)\n }\n}\n\nexport function useCanvasDrop(\n canvasRef: Ref<HTMLCanvasElement | null>,\n editor: Editor,\n onActivate?: () => void\n) {\n const isDraggingOver = ref(false)\n\n useEventListener(canvasRef, 'dragover', (e: DragEvent) => {\n if (!hasComponentData(e) && !hasFileData(e)) return\n e.preventDefault()\n if (e.dataTransfer) e.dataTransfer.dropEffect = 'copy'\n isDraggingOver.value = true\n })\n\n useEventListener(canvasRef, 'dragenter', (e: DragEvent) => {\n if (!hasComponentData(e) && !hasFileData(e)) return\n onActivate?.()\n e.preventDefault()\n isDraggingOver.value = true\n })\n\n useEventListener(canvasRef, 'dragleave', () => {\n isDraggingOver.value = false\n })\n\n useEventListener(canvasRef, 'drop', (e: DragEvent) => {\n onActivate?.()\n e.preventDefault()\n isDraggingOver.value = false\n\n const canvas = canvasRef.value\n if (!canvas) return\n const point = dropPoint(e, canvas, editor)\n\n const componentId = e.dataTransfer?.getData(COMPONENT_MIME)\n if (componentId) {\n const placement = componentDropPlacement(componentId, point.x, point.y, editor)\n if (!placement) return\n editor.createInstanceFromComponent(componentId, placement.x, placement.y, placement.parentId)\n editor.requestRender()\n return\n }\n\n const files = filterCanvasFiles(e.dataTransfer?.files ?? null)\n if (!files.length) return\n void editor.placeFiles(files, point.x, point.y).catch((error: unknown) => {\n console.error('Failed to place dropped files', error)\n })\n })\n\n return { isDraggingOver }\n}\n\nfunction hasFileData(e: DragEvent): boolean {\n return e.dataTransfer?.types.includes('Files') ?? false\n}\n\nexport function filterCanvasFiles(files: ArrayLike<File> | Iterable<File> | null): File[] {\n if (!files) return []\n return Array.from(files).filter(\n (file) => IMPORTABLE_RASTER_TYPES.has(file.type) || isSVGFile(file)\n )\n}\n\nexport function extractImageFilesFromClipboard(e: ClipboardEvent): File[] {\n const files = e.clipboardData?.files\n return files ? Array.from(files).filter((file) => IMPORTABLE_RASTER_TYPES.has(file.type)) : []\n}\n"],"mappings":";;;;;;AASA,MAAM,iBAAiB;AAEvB,SAAS,iBAAiB,GAAuB;CAC/C,OAAO,EAAE,cAAc,MAAM,SAAS,cAAc,KAAK;AAC3D;AAEA,SAAS,UAAU,GAAc,QAA2B,QAAgB;CAC1E,MAAM,OAAO,OAAO,sBAAsB;CAC1C,OAAO,OAAO,eAAe,EAAE,UAAU,KAAK,MAAM,EAAE,UAAU,KAAK,GAAG;AAC1E;AAEA,SAAg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AAI,aAAa;GACf,MAAM,YAAY,uBAAuB,aAAa,MAAM,GAAG,MAAM,GAAG,MAAM;GAC9E,IAAI,CAAC,WAAW;GAChB,OAAO,4BAA4B,aAAa,UAAU,GAAG,UAAU,GAAG,UAAU,QAAQ;GAC5F,OAAO,cAAc;GACrB;EACF;EAEA,MAAM,QAAQ,kBAAkB,EAAE,cAAc,SAAS,IAAI;EAC7D,IAAI,CAAC,MAAM,QAAQ;EACnB,OAAY,WAAW,OAAO,MAAM,GAAG,MAAM,CAAC,CAAC,CAAC,OAAO,UAAmB;GACxE,QAAQ,MAAM,iCAAiC,KAAK;EACtD,CAAC;CACH,CAAC;CAED,OAAO,EAAE,eAAe;AAC1B;AAEA,SAAS,YAAY,GAAuB;CAC1C,OAAO,EAAE,cAAc,MAAM,SAAS,OAAO,KAAK;AACpD;AAEA,SAAgB,kBAAkB,OAAwD;CACxF,IAAI,CAAC,OAAO,OAAO,CAAC;CACpB,OAAO,MAAM,KAAK,KAAK,CAAC,CAAC,QACtB,SAAS,wBAAwB,IAAI,KAAK,IAAI,KAAK,UAAU,IAAI,CACpE;AACF;AAEA,SAAgB,+BAA+B,GAA2B;CACxE,MAAM,QAAQ,EAAE,eAAe;CAC/B,OAAO,QAAQ,MAAM,KAAK,KAAK,CAAC,CAAC,QAAQ,SAAS,wBAAwB,IAAI,KAAK,IAAI,CAAC,IAAI,CAAC;AAC/F"}
@@ -30,10 +30,11 @@ function createGuideInput({ canvasRef, editor, canvasToLocal, setDrag, setCursor
30
30
  }
31
31
  return editor.state.currentPageId;
32
32
  }
33
+ /** Where the guide lands: a whole canvas pixel, as Figma's guides do. */
33
34
  function positionFor(ownerId, axis, cx, cy) {
34
35
  const owner = editor.graph.getNode(ownerId);
35
36
  const local = owner && owner.type !== "CANVAS" ? canvasToLocal(cx, cy, owner.id) : null;
36
- return axis === "x" ? local?.lx ?? cx : local?.ly ?? cy;
37
+ return Math.round(axis === "x" ? local?.lx ?? cx : local?.ly ?? cy);
37
38
  }
38
39
  function cursor(axis) {
39
40
  return axis === "x" ? "ew-resize" : "ns-resize";
@@ -1 +1 @@
1
- {"version":3,"file":"input.js","names":[],"sources":["../../../src/canvas/guides/input.ts"],"sourcesContent":["import type { Ref } from 'vue'\n\nimport type { Editor } from '@pairdraw/core'\nimport { computeGuideRedline, hitTestGuides } from '@pairdraw/core/canvas'\nimport { RULER_SIZE } from '@pairdraw/core/constants'\n\nimport { isPastPointerDragThreshold } from '#vue/shared/input/drag-threshold'\nimport type { DragGuide, DragState } from '#vue/shared/input/types'\n\ninterface GuideInputOptions {\n canvasRef: Ref<HTMLCanvasElement | null>\n editor: Editor\n canvasToLocal: (cx: number, cy: number, scopeId: string) => { lx: number; ly: number }\n setDrag: (drag: DragState) => void\n setCursor: (cursor: string | null) => void\n}\n\nexport function selectedTopLevelGuideFrameId(editor: Editor): string | null {\n if (editor.state.selectedIds.size !== 1) return null\n const id = [...editor.state.selectedIds][0]\n const node = editor.graph.getNode(id)\n return node?.type === 'FRAME' && node.parentId === editor.state.currentPageId ? node.id : null\n}\n\nexport function createGuideInput({\n canvasRef,\n editor,\n canvasToLocal,\n setDrag,\n setCursor\n}: GuideInputOptions) {\n function viewport() {\n const canvas = canvasRef.value\n return {\n panX: editor.state.panX,\n panY: editor.state.panY,\n zoom: editor.state.zoom,\n width: canvas?.clientWidth ?? 0,\n height: canvas?.clientHeight ?? 0\n }\n }\n\n function hitTest(sx: number, sy: number) {\n return hitTestGuides(editor.graph, editor.state.currentPageId, viewport(), sx, sy)\n }\n\n function ownerAt(cx: number, cy: number): string {\n let node = editor.graph.hitTestDeep(cx, cy, editor.state.currentPageId)\n while (node) {\n if (node.type === 'FRAME' || node.type === 'COMPONENT') return node.id\n node = node.parentId ? (editor.graph.getNode(node.parentId) ?? null) : null\n }\n return editor.state.currentPageId\n }\n\n function positionFor(ownerId: string, axis: DragGuide['axis'], cx: number, cy: number) {\n const owner = editor.graph.getNode(ownerId)\n const local = owner && owner.type !== 'CANVAS' ? canvasToLocal(cx, cy, owner.id) : null\n return axis === 'x' ? (local?.lx ?? cx) : (local?.ly ?? cy)\n }\n\n function cursor(axis: DragGuide['axis']) {\n return axis === 'x' ? 'ew-resize' : 'ns-resize'\n }\n\n function rulerAxis(sx: number, sy: number): DragGuide['axis'] | null {\n if (sx < RULER_SIZE && sy < RULER_SIZE) return null\n if (sy < RULER_SIZE) return 'y'\n if (sx < RULER_SIZE) return 'x'\n return null\n }\n\n function updateHover(sx: number, sy: number): string | null {\n const axis = rulerAxis(sx, sy)\n if (axis) {\n editor.setHoveredGuide(null)\n return cursor(axis)\n }\n const hit = hitTest(sx, sy)\n editor.setHoveredGuide(hit ? { ownerId: hit.ownerId, guideId: hit.guideId } : null)\n return hit ? cursor(hit.axis) : null\n }\n\n function tryStartExisting(sx: number, sy: number, duplicate = false): boolean {\n if (rulerAxis(sx, sy)) return false\n const hit = hitTest(sx, sy)\n if (!hit) return false\n editor.setSelectedGuide({ ownerId: hit.ownerId, guideId: hit.guideId })\n editor.setHoveredGuide(null)\n setCursor(cursor(hit.axis))\n setDrag({\n type: 'guide',\n axis: hit.axis,\n ownerId: hit.ownerId,\n position: hit.position,\n startScreenX: sx,\n startScreenY: sy,\n currentScreenX: sx,\n currentScreenY: sy,\n dragStarted: false,\n guideId: hit.guideId,\n originalOwnerId: hit.ownerId,\n originalPosition: hit.position,\n duplicate\n })\n return true\n }\n\n function tryStartFromRuler(sx: number, sy: number, cx: number, cy: number): boolean {\n if (!('showRulers' in editor.state) || editor.state.showRulers !== true) return false\n const axis = rulerAxis(sx, sy)\n if (!axis) return false\n const ownerId = ownerAt(cx, cy)\n setDrag({\n type: 'guide',\n axis,\n ownerId,\n position: positionFor(ownerId, axis, cx, cy),\n startScreenX: sx,\n startScreenY: sy,\n currentScreenX: sx,\n currentScreenY: sy,\n dragStarted: false\n })\n return true\n }\n\n function handleMove(\n drag: DragGuide,\n sx: number,\n sy: number,\n cx: number,\n cy: number,\n redlines?: { frameId: string; deep: boolean }\n ): void {\n drag.currentScreenX = sx\n drag.currentScreenY = sy\n if (\n !drag.dragStarted &&\n !isPastPointerDragThreshold(drag.startScreenX, drag.startScreenY, sx, sy)\n )\n return\n drag.dragStarted = true\n setCursor(cursor(drag.axis))\n drag.ownerId = redlines?.frameId ?? ownerAt(cx, cy)\n drag.position = positionFor(drag.ownerId, drag.axis, cx, cy)\n editor.setGuidePreview({\n ownerId: drag.ownerId,\n axis: drag.axis,\n position: drag.position,\n source:\n !drag.duplicate && drag.guideId && drag.originalOwnerId\n ? { ownerId: drag.originalOwnerId, guideId: drag.guideId }\n : undefined\n })\n editor.setGuideRedline(\n redlines\n ? computeGuideRedline(\n editor.graph,\n editor.state.currentPageId,\n redlines.frameId,\n drag.axis,\n drag.position,\n redlines.deep\n )\n : null\n )\n }\n\n function finish(drag: DragGuide): void {\n if (drag.dragStarted) {\n if (drag.currentScreenX < RULER_SIZE || drag.currentScreenY < RULER_SIZE) {\n if (!drag.duplicate && drag.guideId && drag.originalOwnerId) {\n editor.removeGuide(drag.originalOwnerId, drag.guideId)\n editor.setSelectedGuide(null)\n }\n } else if (drag.duplicate && drag.guideId && drag.originalOwnerId) {\n const source = editor.graph\n .getNode(drag.originalOwnerId)\n ?.guides.find((guide) => guide.id === drag.guideId)\n if (source) {\n const guideId = editor.addGuide(drag.ownerId, drag.axis, drag.position)\n if (guideId) editor.setSelectedGuide({ ownerId: drag.ownerId, guideId })\n }\n } else if (drag.guideId && drag.originalOwnerId) {\n if (drag.ownerId === drag.originalOwnerId)\n editor.moveGuide(drag.ownerId, drag.guideId, drag.position)\n else editor.transferGuide(drag.originalOwnerId, drag.ownerId, drag.guideId, drag.position)\n editor.setSelectedGuide({ ownerId: drag.ownerId, guideId: drag.guideId })\n } else {\n const guideId = editor.addGuide(drag.ownerId, drag.axis, drag.position)\n if (guideId) editor.setSelectedGuide({ ownerId: drag.ownerId, guideId })\n }\n }\n clearHoverAndPreview()\n }\n\n function deleteSelected(event: KeyboardEvent): boolean {\n if (event.code !== 'Delete' && event.code !== 'Backspace') return false\n const selected = editor.state.guides.selected\n if (!selected || editor.state.editingTextId) return false\n if (!editor.removeGuide(selected.ownerId, selected.guideId)) return false\n editor.setSelectedGuide(null)\n event.preventDefault()\n return true\n }\n\n function clearHoverAndPreview(): void {\n editor.setGuidePreview(null)\n editor.setGuideRedline(null)\n editor.setHoveredGuide(null)\n }\n\n return {\n tryStartExisting,\n tryStartFromRuler,\n updateHover,\n handleMove,\n finish,\n deleteSelected,\n clearHoverAndPreview\n }\n}\n"],"mappings":";;;;AAiBA,SAAgB,6BAA6B,QAA+B;CAC1E,IAAI,OAAO,MAAM,YAAY,SAAS,GAAG,OAAO;CAChD,MAAM,KAAK,CAAC,GAAG,OAAO,MAAM,WAAW,CAAC,CAAC;CACzC,MAAM,OAAO,OAAO,MAAM,QAAQ,EAAE;CACpC,OAAO,MAAM,SAAS,WAAW,KAAK,aAAa,OAAO,MAAM,gBAAgB,KAAK,KAAK;AAC5F;AAEA,SAAgB,iBAAiB,EAC/B,WACA,QACA,eACA,SACA,aACoB;CACpB,SAAS,WAAW;EAClB,MAAM,SAAS,UAAU;EACzB,OAAO;GACL,MAAM,OAAO,MAAM;GACnB,MAAM,OAAO,MAAM;GACnB,MAAM,OAAO,MAAM;GACnB,OAAO,QAAQ,eAAe;GAC9B,QAAQ,QAAQ,gBAAgB;EAClC;CACF;CAEA,SAAS,QAAQ,IAAY,IAAY;EACvC,OAAO,cAAc,OAAO,OAAO,OAAO,MAAM,eAAe,SAAS,GAAG,IAAI,EAAE;CACnF;CAEA,SAAS,QAAQ,IAAY,IAAoB;EAC/C,IAAI,OAAO,OAAO,MAAM,YAAY,IAAI,IAAI,OAAO,MAAM,aAAa;EACtE,OAAO,MAAM;GACX,IAAI,KAAK,SAAS,WAAW,KAAK,SAAS,aAAa,OAAO,KAAK;GACpE,OAAO,KAAK,WAAY,OAAO,MAAM,QAAQ,KAAK,QAAQ,KAAK,OAAQ;EACzE;EACA,OAAO,OAAO,MAAM;C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ACA;EACA;EACA;EACA;EACA;CACF;AACF"}
1
+ {"version":3,"file":"input.js","names":[],"sources":["../../../src/canvas/guides/input.ts"],"sourcesContent":["import type { Ref } from 'vue'\n\nimport type { Editor } from '@pairdraw/core'\nimport { computeGuideRedline, hitTestGuides } from '@pairdraw/core/canvas'\nimport { RULER_SIZE } from '@pairdraw/core/constants'\n\nimport { isPastPointerDragThreshold } from '#vue/shared/input/drag-threshold'\nimport type { DragGuide, DragState } from '#vue/shared/input/types'\n\ninterface GuideInputOptions {\n canvasRef: Ref<HTMLCanvasElement | null>\n editor: Editor\n canvasToLocal: (cx: number, cy: number, scopeId: string) => { lx: number; ly: number }\n setDrag: (drag: DragState) => void\n setCursor: (cursor: string | null) => void\n}\n\nexport function selectedTopLevelGuideFrameId(editor: Editor): string | null {\n if (editor.state.selectedIds.size !== 1) return null\n const id = [...editor.state.selectedIds][0]\n const node = editor.graph.getNode(id)\n return node?.type === 'FRAME' && node.parentId === editor.state.currentPageId ? node.id : null\n}\n\nexport function createGuideInput({\n canvasRef,\n editor,\n canvasToLocal,\n setDrag,\n setCursor\n}: GuideInputOptions) {\n function viewport() {\n const canvas = canvasRef.value\n return {\n panX: editor.state.panX,\n panY: editor.state.panY,\n zoom: editor.state.zoom,\n width: canvas?.clientWidth ?? 0,\n height: canvas?.clientHeight ?? 0\n }\n }\n\n function hitTest(sx: number, sy: number) {\n return hitTestGuides(editor.graph, editor.state.currentPageId, viewport(), sx, sy)\n }\n\n function ownerAt(cx: number, cy: number): string {\n let node = editor.graph.hitTestDeep(cx, cy, editor.state.currentPageId)\n while (node) {\n if (node.type === 'FRAME' || node.type === 'COMPONENT') return node.id\n node = node.parentId ? (editor.graph.getNode(node.parentId) ?? null) : null\n }\n return editor.state.currentPageId\n }\n\n /** Where the guide lands: a whole canvas pixel, as Figma's guides do. */\n function positionFor(ownerId: string, axis: DragGuide['axis'], cx: number, cy: number) {\n const owner = editor.graph.getNode(ownerId)\n const local = owner && owner.type !== 'CANVAS' ? canvasToLocal(cx, cy, owner.id) : null\n return Math.round(axis === 'x' ? (local?.lx ?? cx) : (local?.ly ?? cy))\n }\n\n function cursor(axis: DragGuide['axis']) {\n return axis === 'x' ? 'ew-resize' : 'ns-resize'\n }\n\n function rulerAxis(sx: number, sy: number): DragGuide['axis'] | null {\n if (sx < RULER_SIZE && sy < RULER_SIZE) return null\n if (sy < RULER_SIZE) return 'y'\n if (sx < RULER_SIZE) return 'x'\n return null\n }\n\n function updateHover(sx: number, sy: number): string | null {\n const axis = rulerAxis(sx, sy)\n if (axis) {\n editor.setHoveredGuide(null)\n return cursor(axis)\n }\n const hit = hitTest(sx, sy)\n editor.setHoveredGuide(hit ? { ownerId: hit.ownerId, guideId: hit.guideId } : null)\n return hit ? cursor(hit.axis) : null\n }\n\n function tryStartExisting(sx: number, sy: number, duplicate = false): boolean {\n if (rulerAxis(sx, sy)) return false\n const hit = hitTest(sx, sy)\n if (!hit) return false\n editor.setSelectedGuide({ ownerId: hit.ownerId, guideId: hit.guideId })\n editor.setHoveredGuide(null)\n setCursor(cursor(hit.axis))\n setDrag({\n type: 'guide',\n axis: hit.axis,\n ownerId: hit.ownerId,\n position: hit.position,\n startScreenX: sx,\n startScreenY: sy,\n currentScreenX: sx,\n currentScreenY: sy,\n dragStarted: false,\n guideId: hit.guideId,\n originalOwnerId: hit.ownerId,\n originalPosition: hit.position,\n duplicate\n })\n return true\n }\n\n function tryStartFromRuler(sx: number, sy: number, cx: number, cy: number): boolean {\n if (!('showRulers' in editor.state) || editor.state.showRulers !== true) return false\n const axis = rulerAxis(sx, sy)\n if (!axis) return false\n const ownerId = ownerAt(cx, cy)\n setDrag({\n type: 'guide',\n axis,\n ownerId,\n position: positionFor(ownerId, axis, cx, cy),\n startScreenX: sx,\n startScreenY: sy,\n currentScreenX: sx,\n currentScreenY: sy,\n dragStarted: false\n })\n return true\n }\n\n function handleMove(\n drag: DragGuide,\n sx: number,\n sy: number,\n cx: number,\n cy: number,\n redlines?: { frameId: string; deep: boolean }\n ): void {\n drag.currentScreenX = sx\n drag.currentScreenY = sy\n if (\n !drag.dragStarted &&\n !isPastPointerDragThreshold(drag.startScreenX, drag.startScreenY, sx, sy)\n )\n return\n drag.dragStarted = true\n setCursor(cursor(drag.axis))\n drag.ownerId = redlines?.frameId ?? ownerAt(cx, cy)\n drag.position = positionFor(drag.ownerId, drag.axis, cx, cy)\n editor.setGuidePreview({\n ownerId: drag.ownerId,\n axis: drag.axis,\n position: drag.position,\n source:\n !drag.duplicate && drag.guideId && drag.originalOwnerId\n ? { ownerId: drag.originalOwnerId, guideId: drag.guideId }\n : undefined\n })\n editor.setGuideRedline(\n redlines\n ? computeGuideRedline(\n editor.graph,\n editor.state.currentPageId,\n redlines.frameId,\n drag.axis,\n drag.position,\n redlines.deep\n )\n : null\n )\n }\n\n function finish(drag: DragGuide): void {\n if (drag.dragStarted) {\n if (drag.currentScreenX < RULER_SIZE || drag.currentScreenY < RULER_SIZE) {\n if (!drag.duplicate && drag.guideId && drag.originalOwnerId) {\n editor.removeGuide(drag.originalOwnerId, drag.guideId)\n editor.setSelectedGuide(null)\n }\n } else if (drag.duplicate && drag.guideId && drag.originalOwnerId) {\n const source = editor.graph\n .getNode(drag.originalOwnerId)\n ?.guides.find((guide) => guide.id === drag.guideId)\n if (source) {\n const guideId = editor.addGuide(drag.ownerId, drag.axis, drag.position)\n if (guideId) editor.setSelectedGuide({ ownerId: drag.ownerId, guideId })\n }\n } else if (drag.guideId && drag.originalOwnerId) {\n if (drag.ownerId === drag.originalOwnerId)\n editor.moveGuide(drag.ownerId, drag.guideId, drag.position)\n else editor.transferGuide(drag.originalOwnerId, drag.ownerId, drag.guideId, drag.position)\n editor.setSelectedGuide({ ownerId: drag.ownerId, guideId: drag.guideId })\n } else {\n const guideId = editor.addGuide(drag.ownerId, drag.axis, drag.position)\n if (guideId) editor.setSelectedGuide({ ownerId: drag.ownerId, guideId })\n }\n }\n clearHoverAndPreview()\n }\n\n function deleteSelected(event: KeyboardEvent): boolean {\n if (event.code !== 'Delete' && event.code !== 'Backspace') return false\n const selected = editor.state.guides.selected\n if (!selected || editor.state.editingTextId) return false\n if (!editor.removeGuide(selected.ownerId, selected.guideId)) return false\n editor.setSelectedGuide(null)\n event.preventDefault()\n return true\n }\n\n function clearHoverAndPreview(): void {\n editor.setGuidePreview(null)\n editor.setGuideRedline(null)\n editor.setHoveredGuide(null)\n }\n\n return {\n tryStartExisting,\n tryStartFromRuler,\n updateHover,\n handleMove,\n finish,\n deleteSelected,\n clearHoverAndPreview\n }\n}\n"],"mappings":";;;;AAiBA,SAAgB,6BAA6B,QAA+B;CAC1E,IAAI,OAAO,MAAM,YAAY,SAAS,GAAG,OAAO;CAChD,MAAM,KAAK,CAAC,GAAG,OAAO,MAAM,WAAW,CAAC,CAAC;CACzC,MAAM,OAAO,OAAO,MAAM,QAAQ,EAAE;CACpC,OAAO,MAAM,SAAS,WAAW,KAAK,aAAa,OAAO,MAAM,gBAAgB,KAAK,KAAK;AAC5F;AAEA,SAAgB,iBAAiB,EAC/B,WACA,QACA,eACA,SACA,aACoB;CACpB,SAAS,WAAW;EAClB,MAAM,SAAS,UAAU;EACzB,OAAO;GACL,MAAM,OAAO,MAAM;GACnB,MAAM,OAAO,MAAM;GACnB,MAAM,OAAO,MAAM;GACnB,OAAO,QAAQ,eAAe;GAC9B,QAAQ,QAAQ,gBAAgB;EAClC;CACF;CAEA,SAAS,QAAQ,IAAY,IAAY;EACvC,OAAO,cAAc,OAAO,OAAO,OAAO,MAAM,eAAe,SAAS,GAAG,IAAI,EAAE;CACnF;CAEA,SAAS,QAAQ,IAAY,IAAoB;EAC/C,IAAI,OAAO,OAAO,MAAM,YAAY,IAAI,IAAI,OAAO,MAAM,aAAa;EACtE,OAAO,MAAM;GACX,IAAI,KAAK,SAAS,WAAW,KAAK,SAAS,aAAa,OAAO,KAAK;GACpE,OAAO,KAAK,WAAY,OAAO,MAAM,QAAQ,KAAK,QAAQ,KAAK,OAAQ;EACzE;EACA,OAAO,OA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AC7B;CAEA,OAAO;EACL;EACA;EACA;EACA;EACA;EACA;EACA;CACF;AACF"}
@@ -1,9 +1,21 @@
1
1
  import { createPenDrag, handlePenDragMove } from "./drag.js";
2
2
  import { PEN_CURSOR } from "../../editor/tool-cursor/index.js";
3
- import { resolveVertexSnap } from "../../shared/input/snap.js";
3
+ import { gridRounding, resolveVertexSnap } from "../../shared/input/snap.js";
4
4
  import { handlePenNodeEditDown } from "../../shared/input/vector/index.js";
5
5
  import { PEN_CLOSE_THRESHOLD } from "@pairdraw/core/constants";
6
6
  //#region src/canvas/pen/input.ts
7
+ /**
8
+ * The point the pen records: on the pixel grid the shape tools land on, except on an axis a vertex
9
+ * already holds, which Figma leaves exactly where that vertex is.
10
+ */
11
+ function penAnchor(point, guides, editor) {
12
+ const round = gridRounding(editor);
13
+ const snapped = new Set(guides.map((guide) => guide.axis));
14
+ return {
15
+ x: snapped.has("x") ? point.x : round(point.x),
16
+ y: snapped.has("y") ? point.y : round(point.y)
17
+ };
18
+ }
7
19
  /** Whether a canvas point lies within the close threshold, in screen pixels, of the path's start. */
8
20
  function nearFirstVertex(cx, cy, first, editor) {
9
21
  const zoom = editor.renderer?.zoom ?? 1;
@@ -21,10 +33,11 @@ function penSnapVertices(editor) {
21
33
  function startPenInput(e, cx, cy, editor, setDrag, cursorOverride) {
22
34
  editor.state.penCursorX = null;
23
35
  editor.state.penCursorY = null;
24
- const { point } = resolveVertexSnap({
36
+ const { point, guides } = resolveVertexSnap({
25
37
  x: cx,
26
38
  y: cy
27
39
  }, penSnapVertices(editor), editor);
40
+ const anchor = penAnchor(point, guides, editor);
28
41
  editor.setSnapGuides([]);
29
42
  if (editor.state.nodeEditState) {
30
43
  handlePenNodeEditDown(e, cx, cy, editor, point);
@@ -42,8 +55,8 @@ function startPenInput(e, cx, cy, editor, setDrag, cursorOverride) {
42
55
  }
43
56
  }
44
57
  editor.penSetPendingClose(false);
45
- editor.penAddVertex(point.x, point.y);
46
- setDrag(createPenDrag(point.x, point.y));
58
+ editor.penAddVertex(anchor.x, anchor.y);
59
+ setDrag(createPenDrag(anchor.x, anchor.y));
47
60
  cursorOverride.value = PEN_CURSOR;
48
61
  return true;
49
62
  }
@@ -56,8 +69,9 @@ function updatePenHover(cx, cy, editor) {
56
69
  }, penSnapVertices(editor), editor);
57
70
  editor.setSnapGuides(snap.guides);
58
71
  if (!editor.state.penState) return true;
59
- editor.state.penCursorX = snap.point.x;
60
- editor.state.penCursorY = snap.point.y;
72
+ const anchor = penAnchor(snap.point, snap.guides, editor);
73
+ editor.state.penCursorX = anchor.x;
74
+ editor.state.penCursorY = anchor.y;
61
75
  const first = editor.state.penState.vertices[0];
62
76
  if (editor.state.penState.vertices.length > 2) editor.penSetClosingToFirst(nearFirstVertex(cx, cy, first, editor));
63
77
  editor.requestRepaint();
@@ -1 +1 @@
1
- {"version":3,"file":"input.js","names":[],"sources":["../../../src/canvas/pen/input.ts"],"sourcesContent":["import type { Ref } from 'vue'\n\nimport type { Editor } from '@pairdraw/core'\nimport { PEN_CLOSE_THRESHOLD } from '@pairdraw/core/constants'\nimport type { Vector } from '@pairdraw/scene-graph/primitives'\n\nimport { createPenDrag, handlePenDragMove } from '#vue/canvas/pen/drag'\nimport { PEN_CURSOR } from '#vue/editor/tool-cursor'\nimport { resolveVertexSnap } from '#vue/shared/input/snap'\nimport type { DragState } from '#vue/shared/input/types'\nimport { handlePenNodeEditDown } from '#vue/shared/input/vector'\n\ntype SetDrag = (drag: DragState) => void\n\n/** Whether a canvas point lies within the close threshold, in screen pixels, of the path's start. */\nfunction nearFirstVertex(cx: number, cy: number, first: Vector, editor: Editor) {\n const zoom = editor.renderer?.zoom ?? 1\n return Math.hypot(cx - first.x, cy - first.y) < PEN_CLOSE_THRESHOLD / zoom\n}\n\n/**\n * The vertices the pen's next point lines up with, which in Figma are only the path's own: the\n * path being drawn with the one it continues, or the path being edited before the pen picks it up.\n */\nfunction penSnapVertices(editor: Editor): readonly Vector[] {\n const penState = editor.state.penState\n if (!penState) return editor.state.nodeEditState?.vertices ?? []\n const resumed = penState.resumedPath?.network.vertices ?? []\n return [...resumed, ...penState.vertices]\n}\n\nexport function startPenInput(\n e: Pick<MouseEvent, 'altKey'>,\n cx: number,\n cy: number,\n editor: Editor,\n setDrag: SetDrag,\n cursorOverride: Ref<string | null>\n): boolean {\n editor.state.penCursorX = null\n editor.state.penCursorY = null\n\n const { point } = resolveVertexSnap({ x: cx, y: cy }, penSnapVertices(editor), editor)\n editor.setSnapGuides([])\n if (editor.state.nodeEditState) {\n handlePenNodeEditDown(e, cx, cy, editor, point)\n return true\n }\n\n const penState = editor.state.penState\n if (penState && penState.vertices.length > 2) {\n const first = penState.vertices[0]\n if (nearFirstVertex(cx, cy, first, editor)) {\n editor.penSetPendingClose(true)\n editor.penSetClosingToFirst(true)\n setDrag(createPenDrag(first.x, first.y))\n cursorOverride.value = PEN_CURSOR\n return true\n }\n }\n\n editor.penSetPendingClose(false)\n editor.penAddVertex(point.x, point.y)\n setDrag(createPenDrag(point.x, point.y))\n cursorOverride.value = PEN_CURSOR\n return true\n}\n\nexport function updatePenHover(cx: number, cy: number, editor: Editor): boolean {\n if (editor.state.activeTool !== 'PEN') return false\n if (!editor.state.penState && !editor.state.nodeEditState) return false\n const snap = resolveVertexSnap({ x: cx, y: cy }, penSnapVertices(editor), editor)\n editor.setSnapGuides(snap.guides)\n if (!editor.state.penState) return true\n editor.state.penCursorX = snap.point.x\n editor.state.penCursorY = snap.point.y\n\n const first = editor.state.penState.vertices[0]\n if (editor.state.penState.vertices.length > 2) {\n editor.penSetClosingToFirst(nearFirstVertex(cx, cy, first, editor))\n }\n editor.requestRepaint()\n return true\n}\n\nexport { handlePenDragMove }\n"],"mappings":";;;;;;;AAeA,SAAS,gBAAgB,IAAY,IAAY,OAAe,QAAgB;CAC9E,MAAM,OAAO,OAAO,UAAU,QAAQ;CACtC,OAAO,KAAK,MAAM,KAAK,MAAM,GAAG,KAAK,MAAM,CAAC,IAAI,sBAAsB;AACxE;;;;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AO,cAAc,KAAK,MAAM;CAChC,IAAI,CAAC,OAAO,MAAM,UAAU,OAAO;CACnC,OAAO,MAAM,aAAa,KAAK,MAAM;CACrC,OAAO,MAAM,aAAa,KAAK,MAAM;CAErC,MAAM,QAAQ,OAAO,MAAM,SAAS,SAAS;CAC7C,IAAI,OAAO,MAAM,SAAS,SAAS,SAAS,GAC1C,OAAO,qBAAqB,gBAAgB,IAAI,IAAI,OAAO,MAAM,CAAC;CAEpE,OAAO,eAAe;CACtB,OAAO;AACT"}
1
+ {"version":3,"file":"input.js","names":[],"sources":["../../../src/canvas/pen/input.ts"],"sourcesContent":["import type { Ref } from 'vue'\n\nimport type { Editor } from '@pairdraw/core'\nimport { PEN_CLOSE_THRESHOLD } from '@pairdraw/core/constants'\nimport type { Vector } from '@pairdraw/scene-graph/primitives'\nimport type { SnapGuide } from '@pairdraw/scene-graph/snap'\n\nimport { createPenDrag, handlePenDragMove } from '#vue/canvas/pen/drag'\nimport { PEN_CURSOR } from '#vue/editor/tool-cursor'\nimport { gridRounding, resolveVertexSnap } from '#vue/shared/input/snap'\nimport type { DragState } from '#vue/shared/input/types'\nimport { handlePenNodeEditDown } from '#vue/shared/input/vector'\n\ntype SetDrag = (drag: DragState) => void\n\n/**\n * The point the pen records: on the pixel grid the shape tools land on, except on an axis a vertex\n * already holds, which Figma leaves exactly where that vertex is.\n */\nfunction penAnchor(point: Vector, guides: readonly SnapGuide[], editor: Editor): Vector {\n const round = gridRounding(editor)\n const snapped = new Set(guides.map((guide) => guide.axis))\n return {\n x: snapped.has('x') ? point.x : round(point.x),\n y: snapped.has('y') ? point.y : round(point.y)\n }\n}\n\n/** Whether a canvas point lies within the close threshold, in screen pixels, of the path's start. */\nfunction nearFirstVertex(cx: number, cy: number, first: Vector, editor: Editor) {\n const zoom = editor.renderer?.zoom ?? 1\n return Math.hypot(cx - first.x, cy - first.y) < PEN_CLOSE_THRESHOLD / zoom\n}\n\n/**\n * The vertices the pen's next point lines up with, which in Figma are only the path's own: the\n * path being drawn with the one it continues, or the path being edited before the pen picks it up.\n */\nfunction penSnapVertices(editor: Editor): readonly Vector[] {\n const penState = editor.state.penState\n if (!penState) return editor.state.nodeEditState?.vertices ?? []\n const resumed = penState.resumedPath?.network.vertices ?? []\n return [...resumed, ...penState.vertices]\n}\n\nexport function startPenInput(\n e: Pick<MouseEvent, 'altKey'>,\n cx: number,\n cy: number,\n editor: Editor,\n setDrag: SetDrag,\n cursorOverride: Ref<string | null>\n): boolean {\n editor.state.penCursorX = null\n editor.state.penCursorY = null\n\n const { point, guides } = resolveVertexSnap({ x: cx, y: cy }, penSnapVertices(editor), editor)\n const anchor = penAnchor(point, guides, editor)\n editor.setSnapGuides([])\n if (editor.state.nodeEditState) {\n handlePenNodeEditDown(e, cx, cy, editor, point)\n return true\n }\n\n const penState = editor.state.penState\n if (penState && penState.vertices.length > 2) {\n const first = penState.vertices[0]\n if (nearFirstVertex(cx, cy, first, editor)) {\n editor.penSetPendingClose(true)\n editor.penSetClosingToFirst(true)\n setDrag(createPenDrag(first.x, first.y))\n cursorOverride.value = PEN_CURSOR\n return true\n }\n }\n\n editor.penSetPendingClose(false)\n editor.penAddVertex(anchor.x, anchor.y)\n setDrag(createPenDrag(anchor.x, anchor.y))\n cursorOverride.value = PEN_CURSOR\n return true\n}\n\nexport function updatePenHover(cx: number, cy: number, editor: Editor): boolean {\n if (editor.state.activeTool !== 'PEN') return false\n if (!editor.state.penState && !editor.state.nodeEditState) return false\n const snap = resolveVertexSnap({ x: cx, y: cy }, penSnapVertices(editor), editor)\n editor.setSnapGuides(snap.guides)\n if (!editor.state.penState) return true\n const anchor = penAnchor(snap.point, snap.guides, editor)\n editor.state.penCursorX = anchor.x\n editor.state.penCursorY = anchor.y\n\n const first = editor.state.penState.vertices[0]\n if (editor.state.penState.vertices.length > 2) {\n editor.penSetClosingToFirst(nearFirstVertex(cx, cy, first, editor))\n }\n editor.requestRepaint()\n return true\n}\n\nexport { handlePenDragMove }\n"],"mappings":";;;;;;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I;GAC9B,OAAO,qBAAqB,IAAI;GAChC,QAAQ,cAAc,MAAM,GAAG,MAAM,CAAC,CAAC;GACvC,eAAe,QAAQ;GACvB,OAAO;EACT;CACF;CAEA,OAAO,mBAAmB,KAAK;CAC/B,OAAO,aAAa,OAAO,GAAG,OAAO,CAAC;CACtC,QAAQ,cAAc,OAAO,GAAG,OAAO,CAAC,CAAC;CACzC,eAAe,QAAQ;CACvB,OAAO;AACT;AAEA,SAAgB,eAAe,IAAY,IAAY,QAAyB;CAC9E,IAAI,OAAO,MAAM,eAAe,OAAO,OAAO;CAC9C,IAAI,CAAC,OAAO,MAAM,YAAY,CAAC,OAAO,MAAM,eAAe,OAAO;CAClE,MAAM,OAAO,kBAAkB;EAAE,GAAG;EAAI,GAAG;CAAG,GAAG,gBAAgB,MAAM,GAAG,MAAM;CAChF,OAAO,cAAc,KAAK,MAAM;CAChC,IAAI,CAAC,OAAO,MAAM,UAAU,OAAO;CACnC,MAAM,SAAS,UAAU,KAAK,OAAO,KAAK,QAAQ,MAAM;CACxD,OAAO,MAAM,aAAa,OAAO;CACjC,OAAO,MAAM,aAAa,OAAO;CAEjC,MAAM,QAAQ,OAAO,MAAM,SAAS,SAAS;CAC7C,IAAI,OAAO,MAAM,SAAS,SAAS,SAAS,GAC1C,OAAO,qBAAqB,gBAAgB,IAAI,IAAI,OAAO,MAAM,CAAC;CAEpE,OAAO,eAAe;CACtB,OAAO;AACT"}
@@ -43,12 +43,90 @@ function releaseWebGLContext(ck, handle, canvas) {
43
43
  function canvasPixelRatio(maxPixelRatio = Number.POSITIVE_INFINITY) {
44
44
  return Math.min(IS_BROWSER ? window.devicePixelRatio || 1 : 1, maxPixelRatio);
45
45
  }
46
+ const PINNED_PROPERTIES = [
47
+ "width",
48
+ "height",
49
+ "marginLeft",
50
+ "marginTop"
51
+ ];
52
+ /** Per canvas: the inline style its owner set, and the style sizeCanvas last wrote over it. */
53
+ const pinnedStyles = /* @__PURE__ */ new WeakMap();
54
+ function inlineStyle(canvas) {
55
+ const { width, height, marginLeft, marginTop } = canvas.style;
56
+ return {
57
+ width,
58
+ height,
59
+ marginLeft,
60
+ marginTop
61
+ };
62
+ }
63
+ /**
64
+ * Puts back the inline style the canvas's owner set, so the page's own sizing is measured. A
65
+ * property that differs from what sizeCanvas last wrote was set by the owner since, and becomes
66
+ * theirs; the others keep the owner's earlier value.
67
+ */
68
+ function restoreOwnStyle(canvas) {
69
+ const current = inlineStyle(canvas);
70
+ const pinned = pinnedStyles.get(canvas);
71
+ const own = { ...current };
72
+ if (pinned) {
73
+ for (const property of PINNED_PROPERTIES) if (current[property] === pinned.written[property]) own[property] = pinned.own[property];
74
+ }
75
+ pinnedStyles.set(canvas, {
76
+ own,
77
+ written: current
78
+ });
79
+ Object.assign(canvas.style, own);
80
+ }
81
+ /** Records the style sizeCanvas wrote, so a later change by the owner can be told apart. */
82
+ function rememberWrittenStyle(canvas) {
83
+ const pinned = pinnedStyles.get(canvas);
84
+ if (pinned) pinnedStyles.set(canvas, {
85
+ own: pinned.own,
86
+ written: inlineStyle(canvas)
87
+ });
88
+ }
89
+ /**
90
+ * Sizes the canvas bitmap to the content box the page's CSS gives it, pinned to whole CSS pixels
91
+ * as Figma pins its canvas. A panel sized in percent leaves the box at a fraction of a pixel, and
92
+ * the browser shows a canvas at whole pixels, so its bitmap was stretched by one device pixel
93
+ * across the width, softening every line. The canvas moves under a pixel to the nearest whole
94
+ * one through its margins; pointers map from its box, so they follow. Under a transform, where no
95
+ * snap holds, the canvas takes its layout size rounded and stays where it is. A flex container
96
+ * that centres the canvas moves it by half a margin change, so there the snap can stay a quarter
97
+ * pixel off.
98
+ */
46
99
  function sizeCanvas(canvas, editor, onViewportResize, maxPixelRatio = Number.POSITIVE_INFINITY) {
47
100
  const dpr = canvasPixelRatio(maxPixelRatio);
48
- const width = canvas.clientWidth;
49
- const height = canvas.clientHeight;
50
- canvas.width = width * dpr;
51
- canvas.height = height * dpr;
101
+ restoreOwnStyle(canvas);
102
+ const box = canvas.getBoundingClientRect();
103
+ const layout = getComputedStyle(canvas);
104
+ const px = (value) => Number.parseFloat(value) || 0;
105
+ const inset = {
106
+ left: px(layout.borderLeftWidth) + px(layout.paddingLeft),
107
+ right: px(layout.borderRightWidth) + px(layout.paddingRight),
108
+ top: px(layout.borderTopWidth) + px(layout.paddingTop),
109
+ bottom: px(layout.borderBottomWidth) + px(layout.paddingBottom)
110
+ };
111
+ const borderBox = layout.boxSizing === "border-box";
112
+ const outerWidth = (px(layout.width) || box.width) + (borderBox ? 0 : inset.left + inset.right);
113
+ const outerHeight = (px(layout.height) || box.height) + (borderBox ? 0 : inset.top + inset.bottom);
114
+ const transformed = Math.abs(outerWidth - box.width) > .01 || Math.abs(outerHeight - box.height) > .01;
115
+ const contentLeft = box.left + inset.left;
116
+ const contentTop = box.top + inset.top;
117
+ const left = transformed ? contentLeft : Math.round(contentLeft);
118
+ const top = transformed ? contentTop : Math.round(contentTop);
119
+ const width = Math.max(1, transformed ? Math.round(outerWidth - inset.left - inset.right) : Math.round(box.right - inset.right) - left);
120
+ const height = Math.max(1, transformed ? Math.round(outerHeight - inset.top - inset.bottom) : Math.round(box.bottom - inset.bottom) - top);
121
+ canvas.width = Math.round(width * dpr);
122
+ canvas.height = Math.round(height * dpr);
123
+ canvas.style.width = `${borderBox ? width + inset.left + inset.right : width}px`;
124
+ canvas.style.height = `${borderBox ? height + inset.top + inset.bottom : height}px`;
125
+ if (!transformed) {
126
+ canvas.style.marginLeft = `${px(layout.marginLeft) + left - contentLeft}px`;
127
+ canvas.style.marginTop = `${px(layout.marginTop) + top - contentTop}px`;
128
+ }
129
+ rememberWrittenStyle(canvas);
52
130
  if (onViewportResize) onViewportResize(width, height);
53
131
  else if ("setViewportSize" in editor && typeof editor.setViewportSize === "function") editor.setViewportSize(width, height);
54
132
  }
@@ -1 +1 @@
1
- {"version":3,"file":"gl-surface.js","names":[],"sources":["../../../src/canvas/surface/gl-surface.ts"],"sourcesContent":["import type { CanvasKit, Surface } from 'canvaskit-wasm'\n\nimport type { Editor } from '@pairdraw/core'\nimport { IS_BROWSER } from '@pairdraw/core/constants'\nimport type { DocumentColorSpace } from '@pairdraw/scene-graph'\n\nimport type { UseCanvasOptions } from '#vue/canvas/surface/types'\n\nimport {\n configurePresentation,\n supportsWideGamutPresentation,\n type PresentationColorSpace\n} from './color-space'\n\ntype GLContext = ReturnType<CanvasKit['MakeGrContext']>\ntype GLHandle = ReturnType<CanvasKit['GetWebGLContext']>\n\nexport type CanvasGLContext = GLContext\nexport type CanvasGLHandle = GLHandle\n\nconst parkingHandles = new WeakMap<CanvasKit, GLHandle>()\n\n/** A 1×1 offscreen WebGL context that stays registered, so another context can become current. */\nfunction parkingHandle(ck: CanvasKit): GLHandle | null {\n const existing = parkingHandles.get(ck)\n if (existing !== undefined) return existing\n if (typeof document === 'undefined') return null\n const canvas = document.createElement('canvas')\n canvas.width = 1\n canvas.height = 1\n const handle = ck.GetWebGLContext(canvas)\n if (!handle) return null\n parkingHandles.set(ck, handle)\n return handle\n}\n\n/** Makes the parking context current, so CanvasKit lets go of the one it held. */\nfunction park(ck: CanvasKit): void {\n const parking = parkingHandle(ck)\n if (!parking) return\n try {\n ck.MakeGrContext(parking)?.delete()\n } catch {\n // A browser drops a page's oldest WebGL contexts once it holds too many, as WebKit does after\n // a few tabs, and reports it only later; the parking context is the oldest, so it is the one\n // gone, and CanvasKit fails on it. A new parking context takes its place.\n ck.deleteContext(parking)\n parkingHandles.delete(ck)\n const replacement = parkingHandle(ck)\n if (replacement) ck.MakeGrContext(replacement)?.delete()\n }\n}\n\n/**\n * Unregisters a canvas's WebGL context from CanvasKit. `deleteContext` leaves CanvasKit holding\n * the last current context, which keeps the canvas, and every component its element reaches,\n * alive; when this context was current, a parking context takes its place.\n */\nexport function releaseWebGLContext(\n ck: CanvasKit,\n handle: GLHandle,\n canvas: HTMLCanvasElement | null\n): void {\n const context = canvas ? (canvas.getContext('webgl2') ?? canvas.getContext('webgl')) : null\n const wasCurrent = context !== null && Reflect.get(ck, 'ctx') === context\n ck.deleteContext(handle)\n if (wasCurrent) park(ck)\n}\n\n/** The device pixels a canvas draws per CSS pixel: the display's, at most `maxPixelRatio`. */\nexport function canvasPixelRatio(maxPixelRatio = Number.POSITIVE_INFINITY): number {\n return Math.min(IS_BROWSER ? window.devicePixelRatio || 1 : 1, maxPixelRatio)\n}\n\nexport function sizeCanvas(\n canvas: HTMLCanvasElement,\n editor: Editor,\n onViewportResize?: (width: number, height: number) => void,\n maxPixelRatio = Number.POSITIVE_INFINITY\n) {\n const dpr = canvasPixelRatio(maxPixelRatio)\n const width = canvas.clientWidth\n const height = canvas.clientHeight\n canvas.width = width * dpr\n canvas.height = height * dpr\n if (onViewportResize) {\n onViewportResize(width, height)\n } else if ('setViewportSize' in editor && typeof editor.setViewportSize === 'function') {\n editor.setViewportSize(width, height)\n }\n}\n\nexport function makeGLSurface(\n ck: CanvasKit,\n canvas: HTMLCanvasElement,\n options: UseCanvasOptions | undefined,\n glContext: GLContext | null,\n documentColorSpace: DocumentColorSpace\n): {\n surface: Surface | null\n glContext: GLContext | null\n /**\n * The WebGL context this call registered with CanvasKit, which the caller must release with\n * `deleteContext`: CanvasKit's context table otherwise keeps the canvas, and everything its\n * element reaches, alive. Null when the existing context was reused.\n */\n glHandle: GLHandle | null\n presentation: PresentationColorSpace | null\n} {\n let context = glContext\n const glAttrs = options?.preserveDrawingBuffer ? { preserveDrawingBuffer: 1 } : undefined\n const handle = context ? null : ck.GetWebGLContext(canvas, glAttrs)\n if (!context && !handle) {\n return { surface: null, glContext: context, glHandle: null, presentation: null }\n }\n\n const buffer = canvas.getContext('webgl2') ?? canvas.getContext('webgl')\n const presentation = configurePresentation(buffer, {\n documentColorSpace,\n wideGamutDisplay: IS_BROWSER && supportsWideGamutPresentation(),\n width: canvas.width,\n height: canvas.height\n })\n if (!presentation) {\n if (handle) ck.deleteContext(handle)\n return { surface: null, glContext: context, glHandle: null, presentation: null }\n }\n if (!context && handle) context = ck.MakeGrContext(handle)\n if (!context) {\n if (handle) ck.deleteContext(handle)\n return { surface: null, glContext: context, glHandle: null, presentation: null }\n }\n\n return {\n surface: ck.MakeOnScreenGLSurface(\n context,\n canvas.width,\n canvas.height,\n presentation === 'display-p3' ? ck.ColorSpace.DISPLAY_P3 : ck.ColorSpace.SRGB\n ),\n glContext: context,\n glHandle: handle,\n presentation\n }\n}\n"],"mappings":";;;AAoBA,MAAM,iCAAiB,IAAI,QAA6B;;AAGxD,SAAS,cAAc,IAAgC;CACrD,MAAM,WAAW,eAAe,IAAI,EAAE;CACtC,IAAI,aAAa,KAAA,GAAW,OAAO;CACnC,IAAI,OAAO,aAAa,aAAa,OAAO;CAC5C,MAAM,SAAS,SAAS,cAAc,QAAQ;CAC9C,OAAO,QAAQ;CACf,OAAO,SAAS;CAChB,MAAM,SAAS,GAAG,gBAAgB,MAAM;CACxC,IAAI,CAAC,QAAQ,OAAO;CACpB,eAAe,IAAI,IAAI,MAAM;CAC7B,OAAO;AACT;;AAGA,SAAS,KAAK,IAAqB;CACjC,MAAM,UAAU,cAAc,EAAE;CAChC,IAAI,CAAC,SAAS;CACd,IAAI;EACF,GAAG,cAAc,OAAO,CAAC,EAAE,OAAO;CACpC,QAAQ;EAIN,GAAG,cAAc,OAAO;EACxB,eAAe,OAAO,EAAE;EACxB,MAAM,cAAc,cAAc,EAAE;EACpC,IAAI,aAAa,GAAG,cAAc,WAAW,CAAC,EAAE,OAAO;CACzD;AACF;;;;;;AAOA,SAAgB,oBACd,IACA,QACA,QACM;CACN,MAAM,UAAU,SAAU,OAAO,WAAW,QAAQ,KAAK,OAAO,WAAW,OAAO,IAAK;CACvF,MAAM,aAAa,YAAY,QAAQ,QAAQ,IAAI,IAAI,KAAK,MAAM;CAClE,GAAG,cAAc,MAAM;CACvB,IAAI,YAAY,KAAK,EAAE;AACzB;;AAGA,SAAgB,iBAAiB,gBAAgB,OAAO,mBAA2B;CACjF,OAAO,KAAK,IAAI,aAAa,OAAO,oBAAoB,IAAI,GA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ACX,UAAU;EACV;CACF;AACF"}
1
+ {"version":3,"file":"gl-surface.js","names":[],"sources":["../../../src/canvas/surface/gl-surface.ts"],"sourcesContent":["import type { CanvasKit, Surface } from 'canvaskit-wasm'\n\nimport type { Editor } from '@pairdraw/core'\nimport { IS_BROWSER } from '@pairdraw/core/constants'\nimport type { DocumentColorSpace } from '@pairdraw/scene-graph'\n\nimport type { UseCanvasOptions } from '#vue/canvas/surface/types'\n\nimport {\n configurePresentation,\n supportsWideGamutPresentation,\n type PresentationColorSpace\n} from './color-space'\n\ntype GLContext = ReturnType<CanvasKit['MakeGrContext']>\ntype GLHandle = ReturnType<CanvasKit['GetWebGLContext']>\n\nexport type CanvasGLContext = GLContext\nexport type CanvasGLHandle = GLHandle\n\nconst parkingHandles = new WeakMap<CanvasKit, GLHandle>()\n\n/** A 1×1 offscreen WebGL context that stays registered, so another context can become current. */\nfunction parkingHandle(ck: CanvasKit): GLHandle | null {\n const existing = parkingHandles.get(ck)\n if (existing !== undefined) return existing\n if (typeof document === 'undefined') return null\n const canvas = document.createElement('canvas')\n canvas.width = 1\n canvas.height = 1\n const handle = ck.GetWebGLContext(canvas)\n if (!handle) return null\n parkingHandles.set(ck, handle)\n return handle\n}\n\n/** Makes the parking context current, so CanvasKit lets go of the one it held. */\nfunction park(ck: CanvasKit): void {\n const parking = parkingHandle(ck)\n if (!parking) return\n try {\n ck.MakeGrContext(parking)?.delete()\n } catch {\n // A browser drops a page's oldest WebGL contexts once it holds too many, as WebKit does after\n // a few tabs, and reports it only later; the parking context is the oldest, so it is the one\n // gone, and CanvasKit fails on it. A new parking context takes its place.\n ck.deleteContext(parking)\n parkingHandles.delete(ck)\n const replacement = parkingHandle(ck)\n if (replacement) ck.MakeGrContext(replacement)?.delete()\n }\n}\n\n/**\n * Unregisters a canvas's WebGL context from CanvasKit. `deleteContext` leaves CanvasKit holding\n * the last current context, which keeps the canvas, and every component its element reaches,\n * alive; when this context was current, a parking context takes its place.\n */\nexport function releaseWebGLContext(\n ck: CanvasKit,\n handle: GLHandle,\n canvas: HTMLCanvasElement | null\n): void {\n const context = canvas ? (canvas.getContext('webgl2') ?? canvas.getContext('webgl')) : null\n const wasCurrent = context !== null && Reflect.get(ck, 'ctx') === context\n ck.deleteContext(handle)\n if (wasCurrent) park(ck)\n}\n\n/** The device pixels a canvas draws per CSS pixel: the display's, at most `maxPixelRatio`. */\nexport function canvasPixelRatio(maxPixelRatio = Number.POSITIVE_INFINITY): number {\n return Math.min(IS_BROWSER ? window.devicePixelRatio || 1 : 1, maxPixelRatio)\n}\n\n/** A canvas's inline size and margins. */\ntype PinnedStyle = Pick<CSSStyleDeclaration, 'width' | 'height' | 'marginLeft' | 'marginTop'>\nconst PINNED_PROPERTIES = ['width', 'height', 'marginLeft', 'marginTop'] as const\n/** Per canvas: the inline style its owner set, and the style sizeCanvas last wrote over it. */\nconst pinnedStyles = new WeakMap<HTMLCanvasElement, { own: PinnedStyle; written: PinnedStyle }>()\n\nfunction inlineStyle(canvas: HTMLCanvasElement): PinnedStyle {\n const { width, height, marginLeft, marginTop } = canvas.style\n return { width, height, marginLeft, marginTop }\n}\n\n/**\n * Puts back the inline style the canvas's owner set, so the page's own sizing is measured. A\n * property that differs from what sizeCanvas last wrote was set by the owner since, and becomes\n * theirs; the others keep the owner's earlier value.\n */\nfunction restoreOwnStyle(canvas: HTMLCanvasElement): void {\n const current = inlineStyle(canvas)\n const pinned = pinnedStyles.get(canvas)\n const own = { ...current }\n if (pinned) {\n for (const property of PINNED_PROPERTIES) {\n if (current[property] === pinned.written[property]) own[property] = pinned.own[property]\n }\n }\n pinnedStyles.set(canvas, { own, written: current })\n Object.assign(canvas.style, own)\n}\n\n/** Records the style sizeCanvas wrote, so a later change by the owner can be told apart. */\nfunction rememberWrittenStyle(canvas: HTMLCanvasElement): void {\n const pinned = pinnedStyles.get(canvas)\n if (pinned) pinnedStyles.set(canvas, { own: pinned.own, written: inlineStyle(canvas) })\n}\n\n/**\n * Sizes the canvas bitmap to the content box the page's CSS gives it, pinned to whole CSS pixels\n * as Figma pins its canvas. A panel sized in percent leaves the box at a fraction of a pixel, and\n * the browser shows a canvas at whole pixels, so its bitmap was stretched by one device pixel\n * across the width, softening every line. The canvas moves under a pixel to the nearest whole\n * one through its margins; pointers map from its box, so they follow. Under a transform, where no\n * snap holds, the canvas takes its layout size rounded and stays where it is. A flex container\n * that centres the canvas moves it by half a margin change, so there the snap can stay a quarter\n * pixel off.\n */\nexport function sizeCanvas(\n canvas: HTMLCanvasElement,\n editor: Editor,\n onViewportResize?: (width: number, height: number) => void,\n maxPixelRatio = Number.POSITIVE_INFINITY\n) {\n const dpr = canvasPixelRatio(maxPixelRatio)\n restoreOwnStyle(canvas)\n const box = canvas.getBoundingClientRect()\n const layout = getComputedStyle(canvas)\n const px = (value: string) => Number.parseFloat(value) || 0\n // Border and padding sit outside the bitmap, which fills the content box.\n const inset = {\n left: px(layout.borderLeftWidth) + px(layout.paddingLeft),\n right: px(layout.borderRightWidth) + px(layout.paddingRight),\n top: px(layout.borderTopWidth) + px(layout.paddingTop),\n bottom: px(layout.borderBottomWidth) + px(layout.paddingBottom)\n }\n const borderBox = layout.boxSizing === 'border-box'\n const outerWidth = (px(layout.width) || box.width) + (borderBox ? 0 : inset.left + inset.right)\n const outerHeight = (px(layout.height) || box.height) + (borderBox ? 0 : inset.top + inset.bottom)\n const transformed =\n Math.abs(outerWidth - box.width) > 0.01 || Math.abs(outerHeight - box.height) > 0.01\n const contentLeft = box.left + inset.left\n const contentTop = box.top + inset.top\n const left = transformed ? contentLeft : Math.round(contentLeft)\n const top = transformed ? contentTop : Math.round(contentTop)\n const width = Math.max(\n 1,\n transformed\n ? Math.round(outerWidth - inset.left - inset.right)\n : Math.round(box.right - inset.right) - left\n )\n const height = Math.max(\n 1,\n transformed\n ? Math.round(outerHeight - inset.top - inset.bottom)\n : Math.round(box.bottom - inset.bottom) - top\n )\n canvas.width = Math.round(width * dpr)\n canvas.height = Math.round(height * dpr)\n canvas.style.width = `${borderBox ? width + inset.left + inset.right : width}px`\n canvas.style.height = `${borderBox ? height + inset.top + inset.bottom : height}px`\n // The margins the page resolves, such as auto for a centred canvas, plus the snap. A translate\n // would leave the bitmap a fraction of a pixel off, which the browser smooths over.\n if (!transformed) {\n canvas.style.marginLeft = `${px(layout.marginLeft) + left - contentLeft}px`\n canvas.style.marginTop = `${px(layout.marginTop) + top - contentTop}px`\n }\n rememberWrittenStyle(canvas)\n if (onViewportResize) {\n onViewportResize(width, height)\n } else if ('setViewportSize' in editor && typeof editor.setViewportSize === 'function') {\n editor.setViewportSize(width, height)\n }\n}\n\nexport function makeGLSurface(\n ck: CanvasKit,\n canvas: HTMLCanvasElement,\n options: UseCanvasOptions | undefined,\n glContext: GLContext | null,\n documentColorSpace: DocumentColorSpace\n): {\n surface: Surface | null\n glContext: GLContext | null\n /**\n * The WebGL context this call registered with CanvasKit, which the caller must release with\n * `deleteContext`: CanvasKit's context table otherwise keeps the canvas, and everything its\n * element reaches, alive. Null when the existing context was reused.\n */\n glHandle: GLHandle | null\n presentation: PresentationColorSpace | null\n} {\n let context = glContext\n const glAttrs = options?.preserveDrawingBuffer ? { preserveDrawingBuffer: 1 } : undefined\n const handle = context ? null : ck.GetWebGLContext(canvas, glAttrs)\n if (!context && !handle) {\n return { surface: null, glContext: context, glHandle: null, presentation: null }\n }\n\n const buffer = canvas.getContext('webgl2') ?? canvas.getContext('webgl')\n const presentation = configurePresentation(buffer, {\n documentColorSpace,\n wideGamutDisplay: IS_BROWSER && supportsWideGamutPresentation(),\n width: canvas.width,\n height: canvas.height\n })\n if (!presentation) {\n if (handle) ck.deleteContext(handle)\n return { surface: null, glContext: context, glHandle: null, presentation: null }\n }\n if (!context && handle) context = ck.MakeGrContext(handle)\n if (!context) {\n if (handle) ck.deleteContext(handle)\n return { surface: null, glContext: context, glHandle: null, presentation: null }\n }\n\n return {\n surface: ck.MakeOnScreenGLSurface(\n context,\n canvas.width,\n canvas.height,\n presentation === 'display-p3' ? ck.ColorSpace.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IAAI,KAAA;CAChF,MAAM,SAAS,UAAU,OAAO,GAAG,gBAAgB,QAAQ,OAAO;CAClE,IAAI,CAAC,WAAW,CAAC,QACf,OAAO;EAAE,SAAS;EAAM,WAAW;EAAS,UAAU;EAAM,cAAc;CAAK;CAGjF,MAAM,SAAS,OAAO,WAAW,QAAQ,KAAK,OAAO,WAAW,OAAO;CACvE,MAAM,eAAe,sBAAsB,QAAQ;EACjD;EACA,kBAAkB,cAAc,8BAA8B;EAC9D,OAAO,OAAO;EACd,QAAQ,OAAO;CACjB,CAAC;CACD,IAAI,CAAC,cAAc;EACjB,IAAI,QAAQ,GAAG,cAAc,MAAM;EACnC,OAAO;GAAE,SAAS;GAAM,WAAW;GAAS,UAAU;GAAM,cAAc;EAAK;CACjF;CACA,IAAI,CAAC,WAAW,QAAQ,UAAU,GAAG,cAAc,MAAM;CACzD,IAAI,CAAC,SAAS;EACZ,IAAI,QAAQ,GAAG,cAAc,MAAM;EACnC,OAAO;GAAE,SAAS;GAAM,WAAW;GAAS,UAAU;GAAM,cAAc;EAAK;CACjF;CAEA,OAAO;EACL,SAAS,GAAG,sBACV,SACA,OAAO,OACP,OAAO,QACP,iBAAiB,eAAe,GAAG,WAAW,aAAa,GAAG,WAAW,IAC3E;EACA,WAAW;EACX,UAAU;EACV;CACF;AACF"}
@@ -1,33 +1,41 @@
1
- import { onScopeDispose } from "vue";
2
- import { whenever } from "@vueuse/core";
1
+ import { onScopeDispose, watch } from "vue";
3
2
  import { getCanvasKit } from "@pairdraw/core/canvaskit";
4
3
  //#region src/canvas/surface/kit-loader.ts
5
- function useCanvasKitLoader({ canvasRef, lifecycle, setCanvasKit, createSurface, loadFonts, renderNow, onReady, onFailed }) {
4
+ function useCanvasKitLoader({ canvasRef, lifecycle, setCanvasKit, createSurface, loadFonts, renderNow, onReady, onFailed, loadCanvasKit = getCanvasKit }) {
6
5
  const isDestroyed = () => lifecycle.destroyed;
7
- async function init() {
8
- const canvas = canvasRef.value;
9
- if (!canvas || isDestroyed()) return;
10
- setCanvasKit(await getCanvasKit());
11
- if (isDestroyed()) return;
6
+ let generation = 0;
7
+ async function init(canvas, generationAtStart) {
8
+ const stillCurrent = () => !isDestroyed() && canvasRef.value === canvas && generation === generationAtStart;
9
+ if (!stillCurrent()) return;
10
+ setCanvasKit(await loadCanvasKit());
11
+ if (!stillCurrent()) return;
12
12
  await new Promise((resolve) => {
13
13
  requestAnimationFrame(resolve);
14
14
  });
15
+ if (!stillCurrent()) return;
15
16
  if (!createSurface(canvas)) throw new Error("WebGL is unavailable, so the canvas cannot draw");
16
17
  await loadFonts();
17
- if (isDestroyed()) return;
18
+ if (!stillCurrent()) return;
18
19
  renderNow();
19
20
  onReady?.();
20
21
  }
21
- whenever(canvasRef, () => void init().catch((error) => {
22
- if (!onFailed) throw error;
23
- if (!isDestroyed()) onFailed(error);
24
- }), {
25
- once: true,
22
+ function start(canvas) {
23
+ const generationAtStart = ++generation;
24
+ init(canvas, generationAtStart).catch((error) => {
25
+ if (!onFailed) throw error;
26
+ if (!isDestroyed() && generation === generationAtStart) onFailed(error);
27
+ });
28
+ }
29
+ watch(canvasRef, (canvas, previous) => {
30
+ if (!canvas || canvas === previous) return;
31
+ start(canvas);
32
+ }, {
26
33
  flush: "post",
27
34
  immediate: true
28
35
  });
29
36
  onScopeDispose(() => {
30
37
  lifecycle.destroyed = true;
38
+ generation += 1;
31
39
  });
32
40
  }
33
41
  //#endregion
@@ -1 +1 @@
1
- {"version":3,"file":"kit-loader.js","names":[],"sources":["../../../src/canvas/surface/kit-loader.ts"],"sourcesContent":["import { whenever } from '@vueuse/core'\nimport type { CanvasKit } from 'canvaskit-wasm'\nimport { onScopeDispose } from 'vue'\nimport type { Ref } from 'vue'\n\nimport { getCanvasKit } from '@pairdraw/core/canvaskit'\n\ntype CanvasKitLoaderOptions = {\n canvasRef: Ref<HTMLCanvasElement | null>\n lifecycle: { destroyed: boolean }\n setCanvasKit: (ck: CanvasKit | null) => void\n /** Whether a surface the canvas can draw on was made. */\n createSurface: (canvas: HTMLCanvasElement) => boolean\n loadFonts: () => Promise<unknown> | undefined\n renderNow: () => void\n onReady?: () => void\n onFailed?: (error: unknown) => void\n}\n\nexport function useCanvasKitLoader({\n canvasRef,\n lifecycle,\n setCanvasKit,\n createSurface,\n loadFonts,\n renderNow,\n onReady,\n onFailed\n}: CanvasKitLoaderOptions) {\n const isDestroyed = () => lifecycle.destroyed\n\n async function init() {\n const canvas = canvasRef.value\n if (!canvas || isDestroyed()) return\n\n setCanvasKit(await getCanvasKit())\n if (isDestroyed()) return\n\n await new Promise((resolve) => {\n requestAnimationFrame(resolve)\n })\n if (!createSurface(canvas)) throw new Error('WebGL is unavailable, so the canvas cannot draw')\n await loadFonts()\n if (isDestroyed()) return\n renderNow()\n onReady?.()\n }\n\n // Start once there is a canvas: a CanvasSurface child hands its element over after the\n // root has mounted, so waiting for mount alone would find none.\n whenever(\n canvasRef,\n () =>\n void init().catch((error: unknown) => {\n if (!onFailed) throw error\n if (!isDestroyed()) onFailed(error)\n }),\n { once: true, flush: 'post', immediate: true }\n )\n\n onScopeDispose(() => {\n lifecycle.destroyed = true\n })\n}\n"],"mappings":";;;;AAmBA,SAAgB,mBAAmB,EACjC,WACA,WACA,cACA,eACA,WACA,WACA,SACA,YACyB;CACzB,MAAM,oBAAoB,UAAU;CAEpC,eAAe,OAAO;EACpB,MAAM,SAAS,UAAU;EACzB,IAAI,CAAC,UAAU,YAAY,GAAG;EAE9B,aAAa,MAAM,aAAa,CAAC;EACjC,IAAI,YAAY,GAAG;EAEnB,MAAM,IAAI,SAAS,YAAY;GAC7B,sBAAsB,OAAO;EAC/B,CAAC;EACD,IAAI,CAAC,cAAc,MAAM,GAAG,MAAM,IAAI,MAAM,iDAAiD;EAC7F,MAAM,UAAU;EAChB,IAAI,YAAY,GAAG;EACnB,UAAU;EACV,UAAU;CACZ;CAIA,SACE,iBAEE,KAAK,KAAK,CAAC,CAAC,OAAO,UAAmB;EACpC,IAAI,CAAC,UAAU,MAAM;EACrB,IAAI,CAAC,YAAY,GAAG,SAAS,KAAK;CACpC,CAAC,GACH;EAAE,MAAM;EAAM,OAAO;EAAQ,WAAW;CAAK,CAC/C;CAEA,qBAAqB;EACnB,UAAU,YAAY;CACxB,CAAC;AACH"}
1
+ {"version":3,"file":"kit-loader.js","names":[],"sources":["../../../src/canvas/surface/kit-loader.ts"],"sourcesContent":["import type { CanvasKit } from 'canvaskit-wasm'\nimport { onScopeDispose, watch } from 'vue'\nimport type { Ref } from 'vue'\n\nimport { getCanvasKit } from '@pairdraw/core/canvaskit'\n\ntype CanvasKitLoaderOptions = {\n canvasRef: Ref<HTMLCanvasElement | null>\n lifecycle: { destroyed: boolean }\n setCanvasKit: (ck: CanvasKit | null) => void\n /** Whether a surface the canvas can draw on was made. */\n createSurface: (canvas: HTMLCanvasElement) => boolean\n loadFonts: () => Promise<unknown> | undefined\n renderNow: () => void\n onReady?: () => void\n onFailed?: (error: unknown) => void\n /**\n * Loads CanvasKit. Tests pass a stand-in; the canvas uses the shared loader.\n * A default keeps the unit test from downloading the WASM module.\n */\n loadCanvasKit?: () => Promise<CanvasKit>\n}\n\nexport function useCanvasKitLoader({\n canvasRef,\n lifecycle,\n setCanvasKit,\n createSurface,\n loadFonts,\n renderNow,\n onReady,\n onFailed,\n loadCanvasKit = getCanvasKit\n}: CanvasKitLoaderOptions) {\n const isDestroyed = () => lifecycle.destroyed\n // Bumped when a new element arrives, so a start still in flight cannot make a surface\n // on a canvas that has already been replaced.\n let generation = 0\n\n async function init(canvas: HTMLCanvasElement, generationAtStart: number) {\n const stillCurrent = () =>\n !isDestroyed() && canvasRef.value === canvas && generation === generationAtStart\n\n if (!stillCurrent()) return\n\n setCanvasKit(await loadCanvasKit())\n if (!stillCurrent()) return\n\n await new Promise((resolve) => {\n requestAnimationFrame(resolve)\n })\n if (!stillCurrent()) return\n if (!createSurface(canvas)) throw new Error('WebGL is unavailable, so the canvas cannot draw')\n await loadFonts()\n if (!stillCurrent()) return\n renderNow()\n onReady?.()\n }\n\n function start(canvas: HTMLCanvasElement) {\n const generationAtStart = ++generation\n void init(canvas, generationAtStart).catch((error: unknown) => {\n if (!onFailed) throw error\n if (!isDestroyed() && generation === generationAtStart) onFailed(error)\n })\n }\n\n // A CanvasSurface child hands its element over after the root has mounted, so waiting for\n // mount alone would find none. The app replaces the element when the browser keeps a context\n // lost, and that new element has to start too: watching once would leave it blank. The same\n // element does not start again.\n watch(\n canvasRef,\n (canvas, previous) => {\n if (!canvas || canvas === previous) return\n start(canvas)\n },\n { flush: 'post', immediate: true }\n )\n\n onScopeDispose(() => {\n lifecycle.destroyed = true\n generation += 1\n })\n}\n"],"mappings":";;;AAuBA,SAAgB,mBAAmB,EACjC,WACA,WACA,cACA,eACA,WACA,WACA,SACA,UACA,gBAAgB,gBACS;CACzB,MAAM,oBAAoB,UAAU;CAGpC,IAAI,aAAa;CAEjB,eAAe,KAAK,QAA2B,mBAA2B;EACxE,MAAM,qBACJ,CAAC,YAAY,KAAK,UAAU,UAAU,UAAU,eAAe;EAEjE,IAAI,CAAC,aAAa,GAAG;EAErB,aAAa,MAAM,cAAc,CAAC;EAClC,IAAI,CAAC,aAAa,GAAG;EAErB,MAAM,IAAI,SAAS,YAAY;GAC7B,sBAAsB,OAAO;EAC/B,CAAC;EACD,IAAI,CAAC,aAAa,GAAG;EACrB,IAAI,CAAC,cAAc,MAAM,GAAG,MAAM,IAAI,MAAM,iDAAiD;EAC7F,MAAM,UAAU;EAChB,IAAI,CAAC,aAAa,GAAG;EACrB,UAAU;EACV,UAAU;CACZ;CAEA,SAAS,MAAM,QAA2B;EACxC,MAAM,oBAAoB,EAAE;EAC5B,KAAU,QAAQ,iBAAiB,CAAC,CAAC,OAAO,UAAmB;GAC7D,IAAI,CAAC,UAAU,MAAM;GACrB,IAAI,CAAC,YAAY,KAAK,eAAe,mBAAmB,SAAS,KAAK;EACxE,CAAC;CACH;CAMA,MACE,YACC,QAAQ,aAAa;EACpB,IAAI,CAAC,UAAU,WAAW,UAAU;EACpC,MAAM,MAAM;CACd,GACA;EAAE,OAAO;EAAQ,WAAW;CAAK,CACnC;CAEA,qBAAqB;EACnB,UAAU,YAAY;EACtB,cAAc;CAChB,CAAC;AACH"}
@@ -6,7 +6,7 @@ import { createCanvasRenderLoop } from "./render-loop.js";
6
6
  import { useCanvasResizeObserver } from "./resize-observer.js";
7
7
  import { createShaderRasterizer } from "./shader/rasterizer.js";
8
8
  import { editorMessages } from "../../i18n/messages/editor.js";
9
- import { onScopeDispose } from "vue";
9
+ import { onScopeDispose, watch } from "vue";
10
10
  import { SkiaRenderer } from "@pairdraw/core/canvas";
11
11
  //#region src/canvas/surface/lifecycle.ts
12
12
  /** What a canvas asks of its renderer: its layer, renderer mode, pixel density, and effects. */
@@ -15,6 +15,11 @@ function applyRenderOptions(renderer, options) {
15
15
  renderer.tiledSceneEnabled = options?.sceneRenderer === "tiled";
16
16
  renderer.maxPixelRatio = options?.maxPixelRatio ?? Number.POSITIVE_INFINITY;
17
17
  renderer.reducedEffects = options?.reducedEffects ?? false;
18
+ renderer.onNodeDrawFailure = options?.onNodeDrawFailure ?? null;
19
+ }
20
+ /** Shows only the scope layer the canvas asks for, or the whole page when it asks for none. */
21
+ function applySceneScope(renderer, options) {
22
+ renderer.sceneScopeId = options?.getSceneScope?.() ?? null;
18
23
  }
19
24
  function createCanvasSurfaceManager({ editor, canvasRef, options, getCanvasKit, isDestroyed, shouldShowRulers }) {
20
25
  const state = {
@@ -97,6 +102,7 @@ function createCanvasSurfaceManager({ editor, canvasRef, options, getCanvasKit,
97
102
  function renderNow() {
98
103
  if (!state.renderer || isDestroyed()) return;
99
104
  const view = options?.getRenderState?.() ?? editor.state;
105
+ applySceneScope(state.renderer, options);
100
106
  state.renderer.renderFromEditorState(view, editor.graph, editor.textEditor, canvasRef.value?.clientWidth ?? 0, canvasRef.value?.clientHeight ?? 0, shouldShowRulers(), options?.layer ?? "full", editor.isInteractiveEditing());
101
107
  renderLoop.markRendered();
102
108
  options?.onFrame?.({
@@ -169,7 +175,35 @@ function createCanvasSurfaceManager({ editor, canvasRef, options, getCanvasKit,
169
175
  getPresentation: () => state.presentation
170
176
  };
171
177
  }
172
- function useCanvasSurfaceLifecycle({ canvasRef, surface, setCanvasKit, getCanvasKitValue, lifecycle, onReady, onFailed }) {
178
+ /**
179
+ * A browser takes a canvas's WebGL context away on a GPU reset, a driver update, or a tab that
180
+ * comes back from sleep. Ignoring the events leaves the canvas blank for good: the loss is
181
+ * prevented so the context can be given back. The app replaces the element, which starts again.
182
+ * An SDK canvas keeps its element, so the surface is made again on that same element once the
183
+ * browser gives the context back.
184
+ */
185
+ function connectContextRecovery(canvasRef, lifecycle, onContextLost, recreateSurface) {
186
+ watch(canvasRef, (canvas, _previous, onCleanup) => {
187
+ if (!canvas) return;
188
+ const onLost = (event) => {
189
+ event.preventDefault();
190
+ if (lifecycle.destroyed) return;
191
+ onContextLost?.();
192
+ };
193
+ const onRestored = () => {
194
+ if (lifecycle.destroyed) return;
195
+ if (canvasRef.value !== canvas) return;
196
+ recreateSurface(canvas);
197
+ };
198
+ canvas.addEventListener("webglcontextlost", onLost);
199
+ canvas.addEventListener("webglcontextrestored", onRestored);
200
+ onCleanup(() => {
201
+ canvas.removeEventListener("webglcontextlost", onLost);
202
+ canvas.removeEventListener("webglcontextrestored", onRestored);
203
+ });
204
+ }, { flush: "post" });
205
+ }
206
+ function useCanvasSurfaceLifecycle({ canvasRef, surface, setCanvasKit, getCanvasKitValue, lifecycle, onReady, onFailed, onContextLost, loadCanvasKit }) {
173
207
  useCanvasKitLoader({
174
208
  canvasRef,
175
209
  lifecycle,
@@ -178,7 +212,11 @@ function useCanvasSurfaceLifecycle({ canvasRef, surface, setCanvasKit, getCanvas
178
212
  loadFonts: () => surface.getRenderer()?.loadFonts(surface.renderNow),
179
213
  renderNow: surface.renderNow,
180
214
  onReady,
181
- onFailed
215
+ onFailed,
216
+ loadCanvasKit
217
+ });
218
+ connectContextRecovery(canvasRef, lifecycle, onContextLost, (canvas) => {
219
+ surface.createSurface(canvas, { reloadFonts: true });
182
220
  });
183
221
  const { cancelResize } = useCanvasResizeObserver({
184
222
  canvasRef,