@pairdraw/vue 0.19.2 → 0.20.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (302) hide show
  1. package/dist/canvas/CanvasRoot.vue.js +2 -0
  2. package/dist/canvas/CanvasRoot.vue.js.map +1 -1
  3. package/dist/canvas/auto-layout/value-edit.js +1 -1
  4. package/dist/canvas/auto-layout/value-edit.js.map +1 -1
  5. package/dist/canvas/eyedropper/index.d.ts +26 -0
  6. package/dist/canvas/eyedropper/index.d.ts.map +1 -0
  7. package/dist/canvas/eyedropper/index.js +62 -0
  8. package/dist/canvas/eyedropper/index.js.map +1 -0
  9. package/dist/canvas/eyedropper/sample.js +13 -0
  10. package/dist/canvas/eyedropper/sample.js.map +1 -0
  11. package/dist/canvas/eyedropper/use.d.ts +33 -0
  12. package/dist/canvas/eyedropper/use.d.ts.map +1 -0
  13. package/dist/canvas/eyedropper/use.js +52 -0
  14. package/dist/canvas/eyedropper/use.js.map +1 -0
  15. package/dist/canvas/pointer/drag-move.js +4 -0
  16. package/dist/canvas/pointer/drag-move.js.map +1 -1
  17. package/dist/canvas/surface/kit-loader.js +2 -3
  18. package/dist/canvas/surface/kit-loader.js.map +1 -1
  19. package/dist/canvas/surface/lifecycle.js +30 -1
  20. package/dist/canvas/surface/lifecycle.js.map +1 -1
  21. package/dist/canvas/surface/types.d.ts +9 -0
  22. package/dist/canvas/surface/types.d.ts.map +1 -1
  23. package/dist/canvas/text-edit/textarea.d.ts +1 -0
  24. package/dist/canvas/text-edit/textarea.d.ts.map +1 -1
  25. package/dist/canvas/tools/registry.js +5 -1
  26. package/dist/canvas/tools/registry.js.map +1 -1
  27. package/dist/canvas/useCanvasInput.d.ts +152 -10
  28. package/dist/canvas/useCanvasInput.d.ts.map +1 -1
  29. package/dist/canvas/useCanvasInput.js +3 -2
  30. package/dist/canvas/useCanvasInput.js.map +1 -1
  31. package/dist/controls/document-colors/index.d.ts +2 -0
  32. package/dist/controls/document-colors/index.js +2 -0
  33. package/dist/controls/document-colors/use.d.ts +14 -0
  34. package/dist/controls/document-colors/use.d.ts.map +1 -0
  35. package/dist/controls/document-colors/use.js +27 -0
  36. package/dist/controls/document-colors/use.js.map +1 -0
  37. package/dist/controls/effects/helpers.d.ts +13 -2
  38. package/dist/controls/effects/helpers.d.ts.map +1 -1
  39. package/dist/controls/effects/helpers.js +89 -34
  40. package/dist/controls/effects/helpers.js.map +1 -1
  41. package/dist/controls/effects/index.d.ts +2 -1
  42. package/dist/controls/effects/index.js +2 -1
  43. package/dist/controls/effects/use.d.ts +9 -7
  44. package/dist/controls/effects/use.d.ts.map +1 -1
  45. package/dist/controls/effects/use.js +6 -3
  46. package/dist/controls/effects/use.js.map +1 -1
  47. package/dist/controls/node-props/use.d.ts +3 -3
  48. package/dist/controls/position/use.d.ts +1 -1
  49. package/dist/controls/typography/features.d.ts +24 -0
  50. package/dist/controls/typography/features.d.ts.map +1 -0
  51. package/dist/controls/typography/features.js +130 -0
  52. package/dist/controls/typography/features.js.map +1 -0
  53. package/dist/controls/typography/index.d.ts +2 -1
  54. package/dist/controls/typography/index.js +2 -1
  55. package/dist/controls/typography/use.d.ts +6 -0
  56. package/dist/controls/typography/use.d.ts.map +1 -1
  57. package/dist/controls/typography/use.js +4 -1
  58. package/dist/controls/typography/use.js.map +1 -1
  59. package/dist/editor/commands/registry.d.ts +4 -0
  60. package/dist/editor/commands/registry.d.ts.map +1 -1
  61. package/dist/editor/commands/registry.js +2 -0
  62. package/dist/editor/commands/registry.js.map +1 -1
  63. package/dist/editor/commands/selection.js +22 -0
  64. package/dist/editor/commands/selection.js.map +1 -1
  65. package/dist/editor/commands/types.d.ts +1 -1
  66. package/dist/editor/commands/types.d.ts.map +1 -1
  67. package/dist/editor/menu-model/canvas.d.ts.map +1 -1
  68. package/dist/editor/menu-model/canvas.js +7 -1
  69. package/dist/editor/menu-model/canvas.js.map +1 -1
  70. package/dist/editor/selection-capabilities/use.d.ts +2 -0
  71. package/dist/editor/selection-capabilities/use.js +5 -0
  72. package/dist/editor/selection-capabilities/use.js.map +1 -1
  73. package/dist/editor/selection-state/use.d.ts +1 -0
  74. package/dist/editor/selection-state/use.js +5 -0
  75. package/dist/editor/selection-state/use.js.map +1 -1
  76. package/dist/editor/tool-cursor/index.d.ts.map +1 -1
  77. package/dist/editor/tool-cursor/index.js +5 -1
  78. package/dist/editor/tool-cursor/index.js.map +1 -1
  79. package/dist/i18n/index.d.ts +5 -2
  80. package/dist/i18n/index.js +5 -2
  81. package/dist/i18n/locales/de/ai.json.js +53 -2
  82. package/dist/i18n/locales/de/commands.json.js +2 -0
  83. package/dist/i18n/locales/de/design-check.json.js +13 -1
  84. package/dist/i18n/locales/de/design-memory.json.js +82 -0
  85. package/dist/i18n/locales/de/design-memory.json.js.map +1 -0
  86. package/dist/i18n/locales/de/fonts.json.js +10 -0
  87. package/dist/i18n/locales/de/index.js +5 -1
  88. package/dist/i18n/locales/de/index.js.map +1 -1
  89. package/dist/i18n/locales/de/menu.json.js +2 -0
  90. package/dist/i18n/locales/de/panels.json.js +94 -1
  91. package/dist/i18n/locales/de/settings.json.js +1 -0
  92. package/dist/i18n/locales/de/tools.json.js +3 -1
  93. package/dist/i18n/locales/de/variables/panel.json.js +20 -0
  94. package/dist/i18n/locales/de/variations.json.js +23 -0
  95. package/dist/i18n/locales/de/variations.json.js.map +1 -0
  96. package/dist/i18n/locales/es/ai.json.js +52 -1
  97. package/dist/i18n/locales/es/commands.json.js +2 -0
  98. package/dist/i18n/locales/es/design-check.json.js +13 -1
  99. package/dist/i18n/locales/es/design-memory.json.js +82 -0
  100. package/dist/i18n/locales/es/design-memory.json.js.map +1 -0
  101. package/dist/i18n/locales/es/fonts.json.js +10 -0
  102. package/dist/i18n/locales/es/index.js +5 -1
  103. package/dist/i18n/locales/es/index.js.map +1 -1
  104. package/dist/i18n/locales/es/menu.json.js +2 -0
  105. package/dist/i18n/locales/es/panels.json.js +94 -1
  106. package/dist/i18n/locales/es/settings.json.js +1 -0
  107. package/dist/i18n/locales/es/tools.json.js +3 -1
  108. package/dist/i18n/locales/es/variables/panel.json.js +20 -0
  109. package/dist/i18n/locales/es/variations.json.js +23 -0
  110. package/dist/i18n/locales/es/variations.json.js.map +1 -0
  111. package/dist/i18n/locales/fr/ai.json.js +53 -2
  112. package/dist/i18n/locales/fr/commands.json.js +2 -0
  113. package/dist/i18n/locales/fr/design-check.json.js +13 -1
  114. package/dist/i18n/locales/fr/design-memory.json.js +82 -0
  115. package/dist/i18n/locales/fr/design-memory.json.js.map +1 -0
  116. package/dist/i18n/locales/fr/fonts.json.js +10 -0
  117. package/dist/i18n/locales/fr/index.js +5 -1
  118. package/dist/i18n/locales/fr/index.js.map +1 -1
  119. package/dist/i18n/locales/fr/menu.json.js +2 -0
  120. package/dist/i18n/locales/fr/panels.json.js +94 -1
  121. package/dist/i18n/locales/fr/settings.json.js +1 -0
  122. package/dist/i18n/locales/fr/tools.json.js +3 -1
  123. package/dist/i18n/locales/fr/variables/panel.json.js +20 -0
  124. package/dist/i18n/locales/fr/variations.json.js +23 -0
  125. package/dist/i18n/locales/fr/variations.json.js.map +1 -0
  126. package/dist/i18n/locales/it/ai.json.js +53 -2
  127. package/dist/i18n/locales/it/commands.json.js +2 -0
  128. package/dist/i18n/locales/it/design-check.json.js +13 -1
  129. package/dist/i18n/locales/it/design-memory.json.js +82 -0
  130. package/dist/i18n/locales/it/design-memory.json.js.map +1 -0
  131. package/dist/i18n/locales/it/fonts.json.js +10 -0
  132. package/dist/i18n/locales/it/index.js +5 -1
  133. package/dist/i18n/locales/it/index.js.map +1 -1
  134. package/dist/i18n/locales/it/menu.json.js +2 -0
  135. package/dist/i18n/locales/it/panels.json.js +94 -1
  136. package/dist/i18n/locales/it/settings.json.js +1 -0
  137. package/dist/i18n/locales/it/tools.json.js +3 -1
  138. package/dist/i18n/locales/it/variables/panel.json.js +20 -0
  139. package/dist/i18n/locales/it/variations.json.js +23 -0
  140. package/dist/i18n/locales/it/variations.json.js.map +1 -0
  141. package/dist/i18n/locales/ja/ai.json.js +53 -2
  142. package/dist/i18n/locales/ja/commands.json.js +2 -0
  143. package/dist/i18n/locales/ja/design-check.json.js +13 -1
  144. package/dist/i18n/locales/ja/design-memory.json.js +61 -0
  145. package/dist/i18n/locales/ja/design-memory.json.js.map +1 -0
  146. package/dist/i18n/locales/ja/fonts.json.js +10 -0
  147. package/dist/i18n/locales/ja/index.js +5 -1
  148. package/dist/i18n/locales/ja/index.js.map +1 -1
  149. package/dist/i18n/locales/ja/menu.json.js +2 -0
  150. package/dist/i18n/locales/ja/panels.json.js +91 -1
  151. package/dist/i18n/locales/ja/settings.json.js +1 -0
  152. package/dist/i18n/locales/ja/tools.json.js +3 -1
  153. package/dist/i18n/locales/ja/variables/panel.json.js +20 -0
  154. package/dist/i18n/locales/ja/variations.json.js +23 -0
  155. package/dist/i18n/locales/ja/variations.json.js.map +1 -0
  156. package/dist/i18n/locales/pl/ai.json.js +53 -2
  157. package/dist/i18n/locales/pl/commands.json.js +2 -0
  158. package/dist/i18n/locales/pl/design-check.json.js +13 -1
  159. package/dist/i18n/locales/pl/design-memory.json.js +89 -0
  160. package/dist/i18n/locales/pl/design-memory.json.js.map +1 -0
  161. package/dist/i18n/locales/pl/fonts.json.js +10 -0
  162. package/dist/i18n/locales/pl/index.js +5 -1
  163. package/dist/i18n/locales/pl/index.js.map +1 -1
  164. package/dist/i18n/locales/pl/menu.json.js +2 -0
  165. package/dist/i18n/locales/pl/panels.json.js +95 -1
  166. package/dist/i18n/locales/pl/settings.json.js +1 -0
  167. package/dist/i18n/locales/pl/tools.json.js +3 -1
  168. package/dist/i18n/locales/pl/variables/panel.json.js +20 -0
  169. package/dist/i18n/locales/pl/variations.json.js +23 -0
  170. package/dist/i18n/locales/pl/variations.json.js.map +1 -0
  171. package/dist/i18n/locales/ru/ai.json.js +53 -2
  172. package/dist/i18n/locales/ru/commands.json.js +3 -1
  173. package/dist/i18n/locales/ru/design-check.json.js +13 -1
  174. package/dist/i18n/locales/ru/design-memory.json.js +89 -0
  175. package/dist/i18n/locales/ru/design-memory.json.js.map +1 -0
  176. package/dist/i18n/locales/ru/fonts.json.js +10 -0
  177. package/dist/i18n/locales/ru/index.js +5 -1
  178. package/dist/i18n/locales/ru/index.js.map +1 -1
  179. package/dist/i18n/locales/ru/menu.json.js +2 -0
  180. package/dist/i18n/locales/ru/panels.json.js +95 -1
  181. package/dist/i18n/locales/ru/settings.json.js +1 -0
  182. package/dist/i18n/locales/ru/tools.json.js +3 -1
  183. package/dist/i18n/locales/ru/variables/panel.json.js +20 -0
  184. package/dist/i18n/locales/ru/variations.json.js +23 -0
  185. package/dist/i18n/locales/ru/variations.json.js.map +1 -0
  186. package/dist/i18n/locales/zh-cn/ai.json.js +53 -2
  187. package/dist/i18n/locales/zh-cn/commands.json.js +2 -0
  188. package/dist/i18n/locales/zh-cn/design-check.json.js +13 -1
  189. package/dist/i18n/locales/zh-cn/design-memory.json.js +61 -0
  190. package/dist/i18n/locales/zh-cn/design-memory.json.js.map +1 -0
  191. package/dist/i18n/locales/zh-cn/fonts.json.js +10 -0
  192. package/dist/i18n/locales/zh-cn/index.js +5 -1
  193. package/dist/i18n/locales/zh-cn/index.js.map +1 -1
  194. package/dist/i18n/locales/zh-cn/menu.json.js +2 -0
  195. package/dist/i18n/locales/zh-cn/panels.json.js +91 -1
  196. package/dist/i18n/locales/zh-cn/settings.json.js +1 -0
  197. package/dist/i18n/locales/zh-cn/tools.json.js +3 -1
  198. package/dist/i18n/locales/zh-cn/variables/panel.json.js +20 -0
  199. package/dist/i18n/locales/zh-cn/variations.json.js +23 -0
  200. package/dist/i18n/locales/zh-cn/variations.json.js.map +1 -0
  201. package/dist/i18n/messages/ai.d.ts +65 -2
  202. package/dist/i18n/messages/ai.d.ts.map +1 -1
  203. package/dist/i18n/messages/ai.js +53 -2
  204. package/dist/i18n/messages/ai.js.map +1 -1
  205. package/dist/i18n/messages/chat-usage.d.ts +34 -0
  206. package/dist/i18n/messages/chat-usage.d.ts.map +1 -0
  207. package/dist/i18n/messages/chat-usage.js +25 -0
  208. package/dist/i18n/messages/chat-usage.js.map +1 -0
  209. package/dist/i18n/messages/commands.d.ts +2 -0
  210. package/dist/i18n/messages/commands.d.ts.map +1 -1
  211. package/dist/i18n/messages/commands.js +2 -0
  212. package/dist/i18n/messages/commands.js.map +1 -1
  213. package/dist/i18n/messages/design-check.d.ts +12 -0
  214. package/dist/i18n/messages/design-check.d.ts.map +1 -1
  215. package/dist/i18n/messages/design-check.js +13 -1
  216. package/dist/i18n/messages/design-check.js.map +1 -1
  217. package/dist/i18n/messages/design-memory.d.ts +68 -0
  218. package/dist/i18n/messages/design-memory.d.ts.map +1 -0
  219. package/dist/i18n/messages/design-memory.js +85 -0
  220. package/dist/i18n/messages/design-memory.js.map +1 -0
  221. package/dist/i18n/messages/fonts.d.ts +12 -0
  222. package/dist/i18n/messages/fonts.d.ts.map +1 -1
  223. package/dist/i18n/messages/fonts.js +10 -0
  224. package/dist/i18n/messages/fonts.js.map +1 -1
  225. package/dist/i18n/messages/menu.d.ts +2 -0
  226. package/dist/i18n/messages/menu.d.ts.map +1 -1
  227. package/dist/i18n/messages/menu.js +2 -0
  228. package/dist/i18n/messages/menu.js.map +1 -1
  229. package/dist/i18n/messages/panels.d.ts +114 -0
  230. package/dist/i18n/messages/panels.d.ts.map +1 -1
  231. package/dist/i18n/messages/panels.js +94 -1
  232. package/dist/i18n/messages/panels.js.map +1 -1
  233. package/dist/i18n/messages/settings.d.ts +1 -0
  234. package/dist/i18n/messages/settings.d.ts.map +1 -1
  235. package/dist/i18n/messages/settings.js +1 -0
  236. package/dist/i18n/messages/settings.js.map +1 -1
  237. package/dist/i18n/messages/tools.d.ts +2 -0
  238. package/dist/i18n/messages/tools.d.ts.map +1 -1
  239. package/dist/i18n/messages/tools.js +3 -1
  240. package/dist/i18n/messages/tools.js.map +1 -1
  241. package/dist/i18n/messages/variables/panel.d.ts +24 -0
  242. package/dist/i18n/messages/variables/panel.d.ts.map +1 -1
  243. package/dist/i18n/messages/variables/panel.js +20 -0
  244. package/dist/i18n/messages/variables/panel.js.map +1 -1
  245. package/dist/i18n/messages/variations.d.ts +28 -0
  246. package/dist/i18n/messages/variations.d.ts.map +1 -0
  247. package/dist/i18n/messages/variations.js +26 -0
  248. package/dist/i18n/messages/variations.js.map +1 -0
  249. package/dist/i18n/messages.d.ts +356 -3
  250. package/dist/i18n/messages.d.ts.map +1 -1
  251. package/dist/i18n/messages.js +8 -2
  252. package/dist/i18n/messages.js.map +1 -1
  253. package/dist/i18n/useI18n.d.ts +1193 -9
  254. package/dist/i18n/useI18n.d.ts.map +1 -1
  255. package/dist/i18n/useI18n.js +8 -1
  256. package/dist/i18n/useI18n.js.map +1 -1
  257. package/dist/primitives/ColorPicker/ColorPickerRoot.vue.d.ts +5 -2
  258. package/dist/primitives/ColorPicker/ColorPickerRoot.vue.d.ts.map +1 -1
  259. package/dist/primitives/ColorPicker/ColorPickerRoot.vue.js +12 -3
  260. package/dist/primitives/ColorPicker/ColorPickerRoot.vue.js.map +1 -1
  261. package/dist/primitives/ColorPicker/index.d.ts +2 -1
  262. package/dist/primitives/ColorPicker/index.js +2 -1
  263. package/dist/primitives/ColorPicker/outside.d.ts +16 -0
  264. package/dist/primitives/ColorPicker/outside.d.ts.map +1 -0
  265. package/dist/primitives/ColorPicker/outside.js +20 -0
  266. package/dist/primitives/ColorPicker/outside.js.map +1 -0
  267. package/dist/primitives/FontPicker/FontPickerRoot.vue.d.ts +5 -0
  268. package/dist/primitives/FontPicker/FontPickerRoot.vue.d.ts.map +1 -1
  269. package/dist/primitives/FontPicker/FontPickerRoot.vue.js +63 -56
  270. package/dist/primitives/FontPicker/FontPickerRoot.vue.js.map +1 -1
  271. package/dist/primitives/LayerTree/LayerTreeRoot.vue.d.ts +1 -1
  272. package/dist/primitives/TypographyControls/TypographyControlsRoot.vue.d.ts +3 -0
  273. package/dist/primitives/TypographyControls/TypographyControlsRoot.vue.d.ts.map +1 -1
  274. package/dist/primitives/TypographyControls/TypographyControlsRoot.vue.js +3 -1
  275. package/dist/primitives/TypographyControls/TypographyControlsRoot.vue.js.map +1 -1
  276. package/dist/shared/assets/cursors/eyedropper.svg.js +6 -0
  277. package/dist/shared/assets/cursors/eyedropper.svg.js.map +1 -0
  278. package/dist/shared/frame.d.ts +28 -0
  279. package/dist/shared/frame.d.ts.map +1 -0
  280. package/dist/shared/frame.js +92 -0
  281. package/dist/shared/frame.js.map +1 -0
  282. package/dist/shared/input/auto-layout/drag.js +71 -0
  283. package/dist/shared/input/auto-layout/drag.js.map +1 -0
  284. package/dist/shared/input/{auto-layout-hover.d.ts → auto-layout/hover.d.ts} +3 -3
  285. package/dist/shared/input/auto-layout/hover.d.ts.map +1 -0
  286. package/dist/shared/input/{auto-layout-hover.js → auto-layout/hover.js} +42 -86
  287. package/dist/shared/input/auto-layout/hover.js.map +1 -0
  288. package/dist/shared/input/{auto-layout.js → auto-layout/index.js} +2 -2
  289. package/dist/shared/input/auto-layout/index.js.map +1 -0
  290. package/dist/shared/input/index.d.ts +1 -1
  291. package/dist/shared/input/index.js +1 -1
  292. package/dist/shared/input/move/drag.js +1 -1
  293. package/dist/shared/input/resize.js +1 -1
  294. package/dist/shared/input/select.js +5 -3
  295. package/dist/shared/input/select.js.map +1 -1
  296. package/dist/shared/input/types.d.ts +10 -2
  297. package/dist/shared/input/types.d.ts.map +1 -1
  298. package/dist/shared/input/types.js.map +1 -1
  299. package/package.json +19 -4
  300. package/dist/shared/input/auto-layout-hover.d.ts.map +0 -1
  301. package/dist/shared/input/auto-layout-hover.js.map +0 -1
  302. package/dist/shared/input/auto-layout.js.map +0 -1
@@ -19,6 +19,8 @@ const _sfc_main = /*@__PURE__*/ defineComponent({
19
19
  onPresentation: { type: Function },
20
20
  getRenderState: { type: Function },
21
21
  getSceneScope: { type: Function },
22
+ getPlayScenes: { type: Function },
23
+ getPlayScroll: { type: Function },
22
24
  onFrame: { type: Function },
23
25
  onViewportResize: { type: Function },
24
26
  onContextLost: { type: Function },
@@ -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,4 +1,4 @@
1
- import { autoLayoutValueField, resolveAutoLayoutHover } from "../../shared/input/auto-layout-hover.js";
1
+ import { autoLayoutValueField, resolveAutoLayoutHover } from "../../shared/input/auto-layout/hover.js";
2
2
  import { ref } from "vue";
3
3
  //#region src/canvas/auto-layout/value-edit.ts
4
4
  /**
@@ -1 +1 @@
1
- {"version":3,"file":"value-edit.js","names":[],"sources":["../../../src/canvas/auto-layout/value-edit.ts"],"sourcesContent":["import { ref } from 'vue'\n\nimport type { Editor, NodePreview } from '@pairdraw/core'\n\nimport {\n autoLayoutValueField,\n resolveAutoLayoutHover,\n type AutoLayoutValueField\n} from '#vue/shared/input/auto-layout-hover'\n\n/**\n * A padding or gap value edited on the canvas, as Figma opens one on a double-click: the editor\n * shows while the edit is open, and the value previews on the frame until it is committed.\n */\nexport function createAutoLayoutValueEdit(editor: Editor) {\n const autoLayoutValueEdit = ref<{\n nodeId: string\n field: AutoLayoutValueField\n /** The gap a double-click opened the gap's editor on, which it sits over. */\n gap: number\n value: number\n } | null>(null)\n // The edit's owned preview: undo takes it back in one step, and a selection, page, or\n // document change cancels it, which closes the editor.\n let valuePreview: NodePreview | null = null\n let stopValuePreview: Array<() => void> = []\n\n function end() {\n for (const stop of stopValuePreview) stop()\n stopValuePreview = []\n valuePreview = null\n autoLayoutValueEdit.value = null\n }\n\n function start(cx: number, cy: number): boolean {\n const hover = resolveAutoLayoutHover(cx, cy, editor)\n const field = hover ? autoLayoutValueField(hover) : null\n const node = hover ? editor.graph.getNode(hover.nodeId) : undefined\n if (!hover || !field || !node) return false\n valuePreview = editor.beginNodePreview(\n field === 'itemSpacing' ? 'Update gap' : 'Update padding'\n )\n const close = () => {\n if (valuePreview?.closed) end()\n }\n stopValuePreview = (['selection:changed', 'page:changed', 'graph:replaced'] as const).map(\n (event) => editor.onEditorEvent(event, close)\n )\n // The preview tracks the frame only once a value changes, so its deletion closes the editor here.\n stopValuePreview.push(\n editor.onEditorEvent('node:deleted', (id) => {\n if (id === node.id) valuePreview?.cancel()\n close()\n })\n )\n autoLayoutValueEdit.value = {\n nodeId: node.id,\n field,\n gap: hover.index ?? 0,\n value: node[field]\n }\n return true\n }\n\n function update(value: number) {\n const edit = autoLayoutValueEdit.value\n if (!edit || !valuePreview || !Number.isFinite(value)) return\n const next = Math.max(0, value)\n autoLayoutValueEdit.value = { ...edit, value: next }\n valuePreview.update(edit.nodeId, { [edit.field]: next })\n }\n\n function commit(value: number) {\n const edit = autoLayoutValueEdit.value\n if (edit && valuePreview && Number.isFinite(value)) {\n valuePreview.update(edit.nodeId, { [edit.field]: Math.max(0, value) })\n valuePreview.commit()\n } else {\n valuePreview?.cancel()\n }\n end()\n }\n\n function cancel() {\n valuePreview?.cancel()\n end()\n }\n\n return { edit: autoLayoutValueEdit, start, update, commit, cancel }\n}\n"],"mappings":";;;;;;;AAcA,SAAgB,0BAA0B,QAAgB;CACxD,MAAM,sBAAsB,IAMlB,IAAI;CAGd,IAAI,eAAmC;CACvC,IAAI,mBAAsC,CAAC;CAE3C,SAAS,MAAM;EACb,KAAK,MAAM,QAAQ,kBAAkB,KAAK;EAC1C,mBAAmB,CAAC;EACpB,eAAe;EACf,oBAAoB,QAAQ;CAC9B;CAEA,SAAS,MAAM,IAAY,IAAqB;EAC9C,MAAM,QAAQ,uBAAuB,IAAI,IAAI,MAAM;EACnD,MAAM,QAAQ,QAAQ,qBAAqB,KAAK,IAAI;EACpD,MAAM,OAAO,QAAQ,OAAO,MAAM,QAAQ,MAAM,MAAM,IAAI,KAAA;EAC1D,IAAI,CAAC,SAAS,CAAC,SAAS,CAAC,MAAM,OAAO;EACtC,eAAe,OAAO,iBACpB,UAAU,gBAAgB,eAAe,gBAC3C;EACA,MAAM,cAAc;GAClB,IAAI,cAAc,QAAQ,IAAI;EAChC;EACA,mBAAoB;GAAC;GAAqB;GAAgB;EAAgB,CAAC,CAAW,KACnF,UAAU,OAAO,cAAc,OAAO,KAAK,CAC9C;EAEA,iBAAiB,KACf,OAAO,cAAc,iBAAiB,OAAO;GAC3C,IAAI,OAAO,KAAK,IAAI,cAAc,OAAO;GACzC,MAAM;EACR,CAAC,CACH;EACA,oBAAoB,QAAQ;GAC1B,QAAQ,KAAK;GACb;GACA,KAAK,MAAM,SAAS;GACpB,OAAO,KAAK;EACd;EACA,OAAO;CACT;CAEA,SAAS,OAAO,OAAe;EAC7B,MAAM,OAAO,oBAAoB;EACjC,IAAI,CAAC,QAAQ,CAAC,gBAAgB,CAAC,OAAO,SAAS,KAAK,GAAG;EACvD,MAAM,OAAO,KAAK,IAAI,GAAG,KAAK;EAC9B,oBAAoB,QAAQ;GAAE,GAAG;GAAM,OAAO;EAAK;EACnD,aAAa,OAAO,KAAK,QAAQ,GAAG,KAAK,QAAQ,KAAK,CAAC;CACzD;CAEA,SAAS,OAAO,OAAe;EAC7B,MAAM,OAAO,oBAAoB;EACjC,IAAI,QAAQ,gBAAgB,OAAO,SAAS,KAAK,GAAG;GAClD,aAAa,OAAO,KAAK,QAAQ,GAAG,KAAK,QAAQ,KAAK,IAAI,GAAG,KAAK,EAAE,CAAC;GACrE,aAAa,OAAO;EACtB,OACE,cAAc,OAAO;EAEvB,IAAI;CACN;CAEA,SAAS,SAAS;EAChB,cAAc,OAAO;EACrB,IAAI;CACN;CAEA,OAAO;EAAE,MAAM;EAAqB;EAAO;EAAQ;EAAQ;CAAO;AACpE"}
1
+ {"version":3,"file":"value-edit.js","names":[],"sources":["../../../src/canvas/auto-layout/value-edit.ts"],"sourcesContent":["import { ref } from 'vue'\n\nimport type { Editor, NodePreview } from '@pairdraw/core'\n\nimport {\n autoLayoutValueField,\n resolveAutoLayoutHover,\n type AutoLayoutValueField\n} from '#vue/shared/input/auto-layout/hover'\n\n/**\n * A padding or gap value edited on the canvas, as Figma opens one on a double-click: the editor\n * shows while the edit is open, and the value previews on the frame until it is committed.\n */\nexport function createAutoLayoutValueEdit(editor: Editor) {\n const autoLayoutValueEdit = ref<{\n nodeId: string\n field: AutoLayoutValueField\n /** The gap a double-click opened the gap's editor on, which it sits over. */\n gap: number\n value: number\n } | null>(null)\n // The edit's owned preview: undo takes it back in one step, and a selection, page, or\n // document change cancels it, which closes the editor.\n let valuePreview: NodePreview | null = null\n let stopValuePreview: Array<() => void> = []\n\n function end() {\n for (const stop of stopValuePreview) stop()\n stopValuePreview = []\n valuePreview = null\n autoLayoutValueEdit.value = null\n }\n\n function start(cx: number, cy: number): boolean {\n const hover = resolveAutoLayoutHover(cx, cy, editor)\n const field = hover ? autoLayoutValueField(hover) : null\n const node = hover ? editor.graph.getNode(hover.nodeId) : undefined\n if (!hover || !field || !node) return false\n valuePreview = editor.beginNodePreview(\n field === 'itemSpacing' ? 'Update gap' : 'Update padding'\n )\n const close = () => {\n if (valuePreview?.closed) end()\n }\n stopValuePreview = (['selection:changed', 'page:changed', 'graph:replaced'] as const).map(\n (event) => editor.onEditorEvent(event, close)\n )\n // The preview tracks the frame only once a value changes, so its deletion closes the editor here.\n stopValuePreview.push(\n editor.onEditorEvent('node:deleted', (id) => {\n if (id === node.id) valuePreview?.cancel()\n close()\n })\n )\n autoLayoutValueEdit.value = {\n nodeId: node.id,\n field,\n gap: hover.index ?? 0,\n value: node[field]\n }\n return true\n }\n\n function update(value: number) {\n const edit = autoLayoutValueEdit.value\n if (!edit || !valuePreview || !Number.isFinite(value)) return\n const next = Math.max(0, value)\n autoLayoutValueEdit.value = { ...edit, value: next }\n valuePreview.update(edit.nodeId, { [edit.field]: next })\n }\n\n function commit(value: number) {\n const edit = autoLayoutValueEdit.value\n if (edit && valuePreview && Number.isFinite(value)) {\n valuePreview.update(edit.nodeId, { [edit.field]: Math.max(0, value) })\n valuePreview.commit()\n } else {\n valuePreview?.cancel()\n }\n end()\n }\n\n function cancel() {\n valuePreview?.cancel()\n end()\n }\n\n return { edit: autoLayoutValueEdit, start, update, commit, cancel }\n}\n"],"mappings":";;;;;;;AAcA,SAAgB,0BAA0B,QAAgB;CACxD,MAAM,sBAAsB,IAMlB,IAAI;CAGd,IAAI,eAAmC;CACvC,IAAI,mBAAsC,CAAC;CAE3C,SAAS,MAAM;EACb,KAAK,MAAM,QAAQ,kBAAkB,KAAK;EAC1C,mBAAmB,CAAC;EACpB,eAAe;EACf,oBAAoB,QAAQ;CAC9B;CAEA,SAAS,MAAM,IAAY,IAAqB;EAC9C,MAAM,QAAQ,uBAAuB,IAAI,IAAI,MAAM;EACnD,MAAM,QAAQ,QAAQ,qBAAqB,KAAK,IAAI;EACpD,MAAM,OAAO,QAAQ,OA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edropperLoupe, useEyedropperLoupe } from "./use.js";
2
+ import { Editor } from "@pairdraw/core";
3
+ import { Color } from "@pairdraw/scene-graph/primitives";
4
+ //#region src/canvas/eyedropper/index.d.ts
5
+ /** Whether the editor's profile offers the eyedropper; boards and read-only documents do not. */
6
+ declare function offersEyedropper(editor: Editor): boolean;
7
+ /**
8
+ * Switches to the eyedropper and resolves with the next color picked on the canvas instead of
9
+ * applying it to the selection; `null` when the user leaves the tool or the request is cancelled.
10
+ */
11
+ declare function requestEyedropperSample(editor: Editor): Promise<Color | null>;
12
+ /** Gives up a waiting request, as when its picker closes, and leaves the eyedropper. */
13
+ declare function cancelEyedropperSample(editor: Editor): void;
14
+ /**
15
+ * Whether a press answers a picker's request: one on the canvas while a request waits. A picker
16
+ * passes it as `keepOpen`, so the press that samples does not dismiss it.
17
+ */
18
+ declare function pressAnswersEyedropper(editor: Editor, event: PointerEvent): boolean;
19
+ /**
20
+ * A click with the eyedropper: answers a waiting picker request, otherwise paints the selection's
21
+ * fill (Alt: stroke) in one undo step. Either way the Move tool comes back.
22
+ */
23
+ declare function handleEyedropperDown(editor: Editor, cx: number, cy: number, altKey: boolean): void;
24
+ //#endregion
25
+ export { EYEDROPPER_LOUPE_PIXELS, type EyedropperLoupe, cancelEyedropperSample, handleEyedropperDown, offersEyedropper, pressAnswersEyedropper, requestEyedropperSample, useEyedropperLoupe };
26
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","names":[],"sources":["../../../src/canvas/eyedropper/index.ts"],"mappings":";;;;;iBAuBgB,iBAAiB,QAAQ;;;;;iBASzB,wBAAwB,QAAQ,SAAS,QAAQ;;iBAajD,uBAAuB,QAAQ;;;;;iBAU/B,uBAAuB,QAAQ,QAAQ,OAAO;;;;;iBAQ9C,qBAAqB,QAAQ,QAAQ,YAAY,YAAY"}
@@ -0,0 +1,62 @@
1
+ import { sampleEyedropperPixels } from "./sample.js";
2
+ import { EYEDROPPER_LOUPE_PIXELS, useEyedropperLoupe } from "./use.js";
3
+ import { applySampledColor, resolveEditorProfile, scenePixelColor } from "@pairdraw/core";
4
+ //#region src/canvas/eyedropper/index.ts
5
+ /** The request a color picker waits on, per editor; a new request replaces the old one. */
6
+ const requests = /* @__PURE__ */ new WeakMap();
7
+ function settle(editor, color) {
8
+ const request = requests.get(editor);
9
+ if (!request) return;
10
+ requests.delete(editor);
11
+ request.stop();
12
+ request.resolve(color);
13
+ }
14
+ /** Whether the editor's profile offers the eyedropper; boards and read-only documents do not. */
15
+ function offersEyedropper(editor) {
16
+ const { tools } = resolveEditorProfile(editor.state);
17
+ return !tools || tools.has("EYEDROPPER");
18
+ }
19
+ /**
20
+ * Switches to the eyedropper and resolves with the next color picked on the canvas instead of
21
+ * applying it to the selection; `null` when the user leaves the tool or the request is cancelled.
22
+ */
23
+ function requestEyedropperSample(editor) {
24
+ settle(editor, null);
25
+ editor.setTool("EYEDROPPER");
26
+ if (editor.state.activeTool !== "EYEDROPPER") return Promise.resolve(null);
27
+ return new Promise((resolve) => {
28
+ const stop = editor.onEditorEvent("tool:changed", () => settle(editor, null));
29
+ requests.set(editor, {
30
+ resolve,
31
+ stop
32
+ });
33
+ });
34
+ }
35
+ /** Gives up a waiting request, as when its picker closes, and leaves the eyedropper. */
36
+ function cancelEyedropperSample(editor) {
37
+ if (!requests.has(editor)) return;
38
+ settle(editor, null);
39
+ if (editor.state.activeTool === "EYEDROPPER") editor.setTool("SELECT");
40
+ }
41
+ /**
42
+ * Whether a press answers a picker's request: one on the canvas while a request waits. A picker
43
+ * passes it as `keepOpen`, so the press that samples does not dismiss it.
44
+ */
45
+ function pressAnswersEyedropper(editor, event) {
46
+ return requests.has(editor) && event.target instanceof HTMLCanvasElement;
47
+ }
48
+ /**
49
+ * A click with the eyedropper: answers a waiting picker request, otherwise paints the selection's
50
+ * fill (Alt: stroke) in one undo step. Either way the Move tool comes back.
51
+ */
52
+ function handleEyedropperDown(editor, cx, cy, altKey) {
53
+ const pixels = sampleEyedropperPixels(editor, cx, cy, 1);
54
+ const color = pixels ? scenePixelColor(pixels, 0, 0) : null;
55
+ if (requests.has(editor)) settle(editor, color);
56
+ else if (color) applySampledColor(editor, color, altKey ? "stroke" : "fill");
57
+ editor.setTool("SELECT");
58
+ }
59
+ //#endregion
60
+ export { EYEDROPPER_LOUPE_PIXELS, cancelEyedropperSample, handleEyedropperDown, offersEyedropper, pressAnswersEyedropper, requestEyedropperSample, useEyedropperLoupe };
61
+
62
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","names":[],"sources":["../../../src/canvas/eyedropper/index.ts"],"sourcesContent":["import { applySampledColor, resolveEditorProfile, scenePixelColor } from '@pairdraw/core'\nimport type { Editor, EyedropperTarget } from '@pairdraw/core'\nimport type { Color } from '@pairdraw/scene-graph/primitives'\n\nimport { sampleEyedropperPixels } from './sample'\n\ninterface SampleRequest {\n resolve: (color: Color | null) => void\n stop: () => void\n}\n\n/** The request a color picker waits on, per editor; a new request replaces the old one. */\nconst requests = new WeakMap<Editor, SampleRequest>()\n\nfunction settle(editor: Editor, color: Color | null) {\n const request = requests.get(editor)\n if (!request) return\n requests.delete(editor)\n request.stop()\n request.resolve(color)\n}\n\n/** Whether the editor's profile offers the eyedropper; boards and read-only documents do not. */\nexport function offersEyedropper(editor: Editor): boolean {\n const { tools } = resolveEditorProfile(editor.state)\n return !tools || tools.has('EYEDROPPER')\n}\n\n/**\n * Switches to the eyedropper and resolves with the next color picked on the canvas instead of\n * applying it to the selection; `null` when the user leaves the tool or the request is cancelled.\n */\nexport function requestEyedropperSample(editor: Editor): Promise<Color | null> {\n settle(editor, null)\n editor.setTool('EYEDROPPER')\n if (editor.state.activeTool !== 'EYEDROPPER') return Promise.resolve(null)\n // Subscribed after switching, so the switch to the eyedropper itself does not cancel. The\n // executor runs at once, so the request is stored before anything can settle it.\n return new Promise<Color | null>((resolve) => {\n const stop = editor.onEditorEvent('tool:changed', () => settle(editor, null))\n requests.set(editor, { resolve, stop })\n })\n}\n\n/** Gives up a waiting request, as when its picker closes, and leaves the eyedropper. */\nexport function cancelEyedropperSample(editor: Editor) {\n if (!requests.has(editor)) return\n settle(editor, null)\n if (editor.state.activeTool === 'EYEDROPPER') editor.setTool('SELECT')\n}\n\n/**\n * Whether a press answers a picker's request: one on the canvas while a request waits. A picker\n * passes it as `keepOpen`, so the press that samples does not dismiss it.\n */\nexport function pressAnswersEyedropper(editor: Editor, event: PointerEvent): boolean {\n return requests.has(editor) && event.target instanceof HTMLCanvasElement\n}\n\n/**\n * A click with the eyedropper: answers a waiting picker request, otherwise paints the selection's\n * fill (Alt: stroke) in one undo step. Either way the Move tool comes back.\n */\nexport function handleEyedropperDown(editor: Editor, cx: number, cy: number, altKey: boolean) {\n const pixels = sampleEyedropperPixels(editor, cx, cy, 1)\n const color = pixels ? scenePixelColor(pixels, 0, 0) : null\n if (requests.has(editor)) {\n // Resolve before the tool switch, which would otherwise cancel the request.\n settle(editor, color)\n } else if (color) {\n const target: EyedropperTarget = altKey ? 'stroke' : 'fill'\n applySampledColor(editor, color, target)\n }\n editor.setTool('SELECT')\n}\n\nexport { EYEDROPPER_LOUPE_PIXELS, useEyedropperLoupe } from './use'\nexport type { EyedropperLoupe } from './use'\n"],"mappings":";;;;;AAYA,MAAM,2BAAW,IAAI,QAA+B;AAEpD,SAAS,OAAO,QAAgB,OAAqB;CACnD,MAAM,UAAU,SAAS,IAAI,MAAM;CACnC,IAAI,CAAC,SAAS;CACd,SAAS,OAAO,MAAM;CACtB,QAAQ,KAAK;CACb,QAAQ,QAAQ,KAAK;AACvB;;AAGA,SAAgB,iBAAiB,QAAyB;CACxD,MAAM,EAAE,UAAU,qBAAqB,OAAO,KAAK;CACnD,OAAO,CAAC,SAAS,MAAM,IAAI,YAAY;AACzC;;;;;AAMA,SAAgB,wBAAwB,QAAuC;CAC7E,OAAO,QAAQ,IAAI;CACnB,OAAO,QAAQ,YAAY;CAC3B,IAAI,OAAO,MAAM,eAAe,cAAc,OAAO,QAAQ,QAAQ,IAAI;CAGzE,OAAO,IAAI,SAAuB,YAAY;EAC5C,MAAM,OAAO,OAAO,cAAc,sBAAsB,OAAO,QAAQ,IAAI,CAAC;EAC5E,SAAS,IAAI,QAAQ;GAAE;GAAS;EAAK,CAAC;CACxC,CAAC;AACH;;AAGA,SAAgB,uBAAuB,QAAgB;CACrD,IAAI,CAAC,SAAS,IAAI,MAAM,GAAG;CAC3B,OAAO,QAAQ,IAAI;CACnB,IAAI,OAAO,MAAM,eAAe,cAAc,OAAO,QAAQ,QAAQ;AACvE;;;;;AAMA,SAAgB,uBAAuB,QAAgB,OAA8B;CACnF,OAAO,SAAS,IAAI,MAAM,KAAK,MAAM,kBAAkB;AACzD;;;;;AAMA,SAAgB,qBAAqB,QAAgB,IAAY,IAAY,QAAiB;CAC5F,MAAM,SAAS,uBAAuB,QAAQ,IAAI,IAAI,CAAC;CACvD,MAAM,QAAQ,SAAS,gBAAgB,QAAQ,GAAG,CAAC,IAAI;CACvD,IAAI,SAAS,IAAI,MAAM,GAErB,OAAO,QAAQ,KAAK;MACf,IAAI,OAET,kBAAkB,QAAQ,OADO,SAAS,WAAW,MACd;CAEzC,OAAO,QAAQ,QAAQ;AACzB"}
@@ -0,0 +1,13 @@
1
+ import { sampleScenePixels } from "@pairdraw/core";
2
+ //#region src/canvas/eyedropper/sample.ts
3
+ /** The screen pixels around a world point at the view's zoom, the centre one sampled. */
4
+ function sampleEyedropperPixels(editor, cx, cy, size) {
5
+ const renderer = editor.renderer;
6
+ if (!renderer) return null;
7
+ const { currentPageId, zoom } = editor.state;
8
+ return sampleScenePixels(renderer.ck, renderer, editor.graph, currentPageId, cx, cy, size, zoom);
9
+ }
10
+ //#endregion
11
+ export { sampleEyedropperPixels };
12
+
13
+ //# sourceMappingURL=sample.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"sample.js","names":[],"sources":["../../../src/canvas/eyedropper/sample.ts"],"sourcesContent":["import { sampleScenePixels } from '@pairdraw/core'\nimport type { Editor, ScenePixels } from '@pairdraw/core'\n\n/** The screen pixels around a world point at the view's zoom, the centre one sampled. */\nexport function sampleEyedropperPixels(\n editor: Editor,\n cx: number,\n cy: number,\n size: number\n): ScenePixels | null {\n const renderer = editor.renderer\n if (!renderer) return null\n const { currentPageId, zoom } = editor.state\n return sampleScenePixels(renderer.ck, renderer, editor.graph, currentPageId, cx, cy, size, zoom)\n}\n"],"mappings":";;;AAIA,SAAgB,uBACd,QACA,IACA,IACA,MACoB;CACpB,MAAM,WAAW,OAAO;CACxB,IAAI,CAAC,UAAU,OAAO;CACtB,MAAM,EAAE,eAAe,SAAS,OAAO;CACvC,OAAO,kBAAkB,SAAS,IAAI,UAAU,OAAO,OAAO,eAAe,IAAI,IAAI,MAAM,IAAI;AACjG"}
@@ -0,0 +1,33 @@
1
+ import { ComputedRef, MaybeRefOrGetter, Ref, ShallowRef } from "vue";
2
+ import { Editor, ScenePixels } from "@pairdraw/core";
3
+ import { Color } from "@pairdraw/scene-graph/primitives";
4
+ //#region src/canvas/eyedropper/use.d.ts
5
+ /** How many screen pixels a side the loupe shows; odd, so one pixel is the centre. */
6
+ declare const EYEDROPPER_LOUPE_PIXELS = 9;
7
+ /**
8
+ * A loupe that stands in for the cursor while the eyedropper is active over the canvas: centred
9
+ * on the pointer, so the outlined centre pixel is the one a click picks. The pointer cursor
10
+ * itself should be hidden while it shows, or the cursor, drawn by the system ahead of the page,
11
+ * appears to run ahead of the loupe.
12
+ */
13
+ interface EyedropperLoupe {
14
+ /** Whether the loupe has pixels to show: the eyedropper is active with the pointer on the canvas. */
15
+ visible: ComputedRef<boolean>;
16
+ /** The pointer in viewport (client) coordinates, updated with each move. */
17
+ clientX: ShallowRef<number>;
18
+ clientY: ShallowRef<number>;
19
+ /** The screen pixels around the pointer, sampled once a frame from the document alone. */
20
+ pixels: ShallowRef<ScenePixels | null>;
21
+ /** The centre pixel's colour: what a click picks. */
22
+ color: ComputedRef<Color | null>;
23
+ }
24
+ /**
25
+ * Tracks the pointer over a canvas while the eyedropper is active. The position follows each
26
+ * move at once; the pixels are sampled on the next frame, and again only when the pointer, the
27
+ * view, or the page changed, so a still pointer costs nothing. `enabled` is false for a canvas
28
+ * that takes no input, such as a split view's inactive pane.
29
+ */
30
+ declare function useEyedropperLoupe(editor: Editor, canvas: Readonly<Ref<HTMLElement | null | undefined>>, enabled?: MaybeRefOrGetter<boolean>): EyedropperLoupe;
31
+ //#endregion
32
+ export { EYEDROPPER_LOUPE_PIXELS, EyedropperLoupe, useEyedropperLoupe };
33
+ //# sourceMappingURL=use.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"use.d.ts","names":[],"sources":["../../../src/canvas/eyedropper/use.ts"],"mappings":";;;;;cAmBa;;;;;;;UAQI;;EAEf,SAAS;;EAET,SAAS;EACT,SAAS;;EAET,QAAQ,WAAW;;EAEnB,OAAO,YAAY;;;;;;;;iBASL,mBACd,QAAQ,QACR,QAAQ,SAAS,IAAI,kCACrB,UAAS,4BACR"}
@@ -0,0 +1,52 @@
1
+ import { sampleEyedropperPixels } from "./sample.js";
2
+ import { computed, shallowRef, toValue, watch } from "vue";
3
+ import { useElementHover, useMouseInElement, useRafFn } from "@vueuse/core";
4
+ import { scenePixelColor } from "@pairdraw/core";
5
+ //#region src/canvas/eyedropper/use.ts
6
+ /** How many screen pixels a side the loupe shows; odd, so one pixel is the centre. */
7
+ const EYEDROPPER_LOUPE_PIXELS = 9;
8
+ /**
9
+ * Tracks the pointer over a canvas while the eyedropper is active. The position follows each
10
+ * move at once; the pixels are sampled on the next frame, and again only when the pointer, the
11
+ * view, or the page changed, so a still pointer costs nothing. `enabled` is false for a canvas
12
+ * that takes no input, such as a split view's inactive pane.
13
+ */
14
+ function useEyedropperLoupe(editor, canvas, enabled = true) {
15
+ const pointer = useMouseInElement(canvas, {
16
+ handleOutside: false,
17
+ type: "client"
18
+ });
19
+ const hovered = useElementHover(canvas);
20
+ const active = computed(() => toValue(enabled) && hovered.value && editor.state.activeTool === "EYEDROPPER");
21
+ const pixels = shallowRef(null);
22
+ let sampledAt = "";
23
+ const { pause, resume } = useRafFn(() => {
24
+ const sx = pointer.elementX.value;
25
+ const sy = pointer.elementY.value;
26
+ const { zoom, panX, panY, currentPageId } = editor.state;
27
+ const at = `${sx} ${sy} ${zoom} ${panX} ${panY} ${currentPageId}`;
28
+ if (at === sampledAt) return;
29
+ sampledAt = at;
30
+ const { x, y } = editor.screenToCanvas(sx, sy);
31
+ pixels.value = sampleEyedropperPixels(editor, x, y, 9);
32
+ }, { immediate: false });
33
+ watch(active, (shown) => {
34
+ if (shown) return resume();
35
+ pause();
36
+ pixels.value = null;
37
+ sampledAt = "";
38
+ }, { immediate: true });
39
+ const centre = 4;
40
+ const color = computed(() => pixels.value ? scenePixelColor(pixels.value, centre, centre) : null);
41
+ return {
42
+ visible: computed(() => active.value && color.value !== null),
43
+ clientX: pointer.x,
44
+ clientY: pointer.y,
45
+ pixels,
46
+ color
47
+ };
48
+ }
49
+ //#endregion
50
+ export { EYEDROPPER_LOUPE_PIXELS, useEyedropperLoupe };
51
+
52
+ //# sourceMappingURL=use.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"use.js","names":[],"sources":["../../../src/canvas/eyedropper/use.ts"],"sourcesContent":["import { useElementHover, useMouseInElement, useRafFn } from '@vueuse/core'\nimport {\n computed,\n shallowRef,\n toValue,\n watch,\n type ComputedRef,\n type MaybeRefOrGetter,\n type Ref,\n type ShallowRef\n} from 'vue'\n\nimport { scenePixelColor } from '@pairdraw/core'\nimport type { Editor, ScenePixels } from '@pairdraw/core'\nimport type { Color } from '@pairdraw/scene-graph/primitives'\n\nimport { sampleEyedropperPixels } from './sample'\n\n/** How many screen pixels a side the loupe shows; odd, so one pixel is the centre. */\nexport const EYEDROPPER_LOUPE_PIXELS = 9\n\n/**\n * A loupe that stands in for the cursor while the eyedropper is active over the canvas: centred\n * on the pointer, so the outlined centre pixel is the one a click picks. The pointer cursor\n * itself should be hidden while it shows, or the cursor, drawn by the system ahead of the page,\n * appears to run ahead of the loupe.\n */\nexport interface EyedropperLoupe {\n /** Whether the loupe has pixels to show: the eyedropper is active with the pointer on the canvas. */\n visible: ComputedRef<boolean>\n /** The pointer in viewport (client) coordinates, updated with each move. */\n clientX: ShallowRef<number>\n clientY: ShallowRef<number>\n /** The screen pixels around the pointer, sampled once a frame from the document alone. */\n pixels: ShallowRef<ScenePixels | null>\n /** The centre pixel's colour: what a click picks. */\n color: ComputedRef<Color | null>\n}\n\n/**\n * Tracks the pointer over a canvas while the eyedropper is active. The position follows each\n * move at once; the pixels are sampled on the next frame, and again only when the pointer, the\n * view, or the page changed, so a still pointer costs nothing. `enabled` is false for a canvas\n * that takes no input, such as a split view's inactive pane.\n */\nexport function useEyedropperLoupe(\n editor: Editor,\n canvas: Readonly<Ref<HTMLElement | null | undefined>>,\n enabled: MaybeRefOrGetter<boolean> = true\n): EyedropperLoupe {\n const pointer = useMouseInElement(canvas, { handleOutside: false, type: 'client' })\n const hovered = useElementHover(canvas)\n const active = computed(\n () => toValue(enabled) && hovered.value && editor.state.activeTool === 'EYEDROPPER'\n )\n const pixels = shallowRef<ScenePixels | null>(null)\n let sampledAt = ''\n\n const { pause, resume } = useRafFn(\n () => {\n const sx = pointer.elementX.value\n const sy = pointer.elementY.value\n const { zoom, panX, panY, currentPageId } = editor.state\n const at = `${sx} ${sy} ${zoom} ${panX} ${panY} ${currentPageId}`\n if (at === sampledAt) return\n sampledAt = at\n const { x, y } = editor.screenToCanvas(sx, sy)\n pixels.value = sampleEyedropperPixels(editor, x, y, EYEDROPPER_LOUPE_PIXELS)\n },\n { immediate: false }\n )\n\n watch(\n active,\n (shown) => {\n if (shown) return resume()\n pause()\n pixels.value = null\n sampledAt = ''\n },\n { immediate: true }\n )\n\n const centre = (EYEDROPPER_LOUPE_PIXELS - 1) / 2\n const color = computed(() =>\n pixels.value ? scenePixelColor(pixels.value, centre, centre) : null\n )\n\n return {\n visible: computed(() => active.value && color.value !== null),\n clientX: pointer.x,\n clientY: pointer.y,\n pixels,\n color\n }\n}\n"],"mappings":";;;;;;AAmBA,MAAa,0BAA0B;;;;;;;AA0BvC,SAAgB,mBACd,QACA,QACA,UAAqC,MACpB;CACjB,MAAM,UAAU,kBAAkB,QAAQ;EAAE,eAAe;EAAO,MAAM;CAAS,CAAC;CAClF,MAAM,UAAU,gBAAgB,MAAM;CACtC,MAAM,SAAS,eACP,QAAQ,OAAO,KAAK,QAAQ,SAAS,OAAO,MAAM,eAAe,YACzE;CACA,MAAM,SAAS,WAA+B,IAAI;CAClD,IAAI,YAAY;CAEhB,MAAM,EAAE,OAAO,WAAW,eAClB;EACJ,MAAM,KAAK,QAAQ,SAAS;EAC5B,MAAM,KAAK,QAAQ,SAAS;EAC5B,MAAM,EAAE,MAAM,MAAM,MAAM,kBAAkB,OAAO;EACnD,MAAM,KAAK,GAAG,GAAG,GAAG,GAAG,GAAG,KAAK,GAAG,KAAK,GAAG,KAAK,GAAG;EAClD,IAAI,OAAO,WAAW;EACtB,YAAY;EACZ,MAAM,EAAE,GAAG,MAAM,OAAO,eAAe,IAAI,EAAE;EAC7C,OAAO,QAAQ,uBAAuB,QAAQ,GAAG,GAAA,CAA0B;CAC7E,GACA,EAAE,WAAW,MAAM,CACrB;CAEA,MACE,SACC,UAAU;EACT,IAAI,OAAO,OAAO,OAAO;EACzB,MAAM;EACN,OAAO,QAAQ;EACf,YAAY;CACd,GACA,EAAE,WAAW,KAAK,CACpB;CAEA,MAAM,SAAS;CACf,MAAM,QAAQ,eACZ,OAAO,QAAQ,gBAAgB,OAAO,OAAO,QAAQ,MAAM,IAAI,IACjE;CAEA,OAAO;EACL,SAAS,eAAe,OAAO,SAAS,MAAM,UAAU,IAAI;EAC5D,SAAS,QAAQ;EACjB,SAAS,QAAQ;EACjB;EACA;CACF;AACF"}
@@ -16,6 +16,10 @@ function moveDrag(d, e, { sx, sy, cx, cy }, { editor, guideInput, transform, spa
16
16
  transform.handlePanMove(d, e);
17
17
  return;
18
18
  }
19
+ if (d.type === "auto-layout") {
20
+ d.update(sx, sy, e.altKey, e.shiftKey);
21
+ return;
22
+ }
19
23
  if (d.type === "gradient" || d.type === "shape-handle") {
20
24
  d.update(sx, sy, e.shiftKey);
21
25
  return;
@@ -1 +1 @@
1
- {"version":3,"file":"drag-move.js","names":[],"sources":["../../../src/canvas/pointer/drag-move.ts"],"sourcesContent":["import type { Editor } from '@pairdraw/core'\n\nimport { selectedTopLevelGuideFrameId, type createGuideInput } from '#vue/canvas/guides/input'\nimport { handlePenDragMove } from '#vue/canvas/pen/input'\nimport { handlePencilDragMove } from '#vue/canvas/pencil/input'\nimport type { createCanvasTransformInput } from '#vue/canvas/transform/input'\nimport { handleBendHandleMove } from '#vue/canvas/vector-input/input'\nimport { attachModifiers, handleConnectorDrawMove } from '#vue/shared/input/connector/draw'\nimport { handleDrawMove } from '#vue/shared/input/draw'\nimport { handleMoveMove } from '#vue/shared/input/move/drag'\nimport { applyResize } from '#vue/shared/input/resize'\nimport { applyStickyScale } from '#vue/shared/input/sticky/scale'\nimport type { DragState } from '#vue/shared/input/types'\nimport { handleNodeEditMarqueeMove, handleNodeEditMove } from '#vue/shared/input/vector'\nimport { handleNodeEditTransformMove } from '#vue/shared/input/vector/transform'\n\ntype TransformInput = ReturnType<typeof createCanvasTransformInput>\n\n/** What a drag in progress reaches while the pointer moves. */\nexport interface DragMoveContext {\n editor: Editor\n guideInput: Pick<ReturnType<typeof createGuideInput>, 'handleMove'>\n transform: Pick<\n TransformInput,\n 'handlePanMove' | 'handleRotateMove' | 'handleTextSelectMove' | 'handleMarqueeMove'\n >\n /** Whether Space is held, which moves a pen handle's anchor instead of the handle. */\n spaceHeld: () => boolean\n}\n\n/** Pointer position on screen (`sx`, `sy`) and on the canvas (`cx`, `cy`). */\ninterface DragMovePointer {\n sx: number\n sy: number\n cx: number\n cy: number\n}\n\n/** Moves the drag in progress to the pointer, for each kind of drag the canvas starts. */\n// Dispatching the full drag union is intentionally centralized here.\n// eslint-disable-next-line complexity\nexport function moveDrag(\n d: DragState,\n e: MouseEvent,\n { sx, sy, cx, cy }: DragMovePointer,\n { editor, guideInput, transform, spaceHeld }: DragMoveContext\n): void {\n if (d.type === 'pan') {\n transform.handlePanMove(d, e)\n return\n }\n\n if (d.type === 'gradient' || d.type === 'shape-handle') {\n d.update(sx, sy, e.shiftKey)\n return\n }\n\n if (d.type === 'image-crop') {\n d.update(sx, sy, { shift: e.shiftKey, alt: e.altKey })\n return\n }\n\n if (d.type === 'guide') {\n const frameId = e.altKey && !d.guideId ? selectedTopLevelGuideFrameId(editor) : null\n guideInput.handleMove(\n d,\n sx,\n sy,\n cx,\n cy,\n frameId ? { frameId, deep: e.metaKey || e.ctrlKey } : undefined\n )\n return\n }\n\n if (d.type === 'rotate') {\n transform.handleRotateMove(d, cx, cy, e.shiftKey)\n return\n }\n if (d.type === 'move') {\n handleMoveMove(d, cx, cy, sx, sy, editor, { ctrlKey: e.ctrlKey, shiftKey: e.shiftKey })\n return\n }\n if (d.type === 'text-select') {\n transform.handleTextSelectMove(cx, cy)\n return\n }\n if (d.type === 'resize') {\n applyResize(d, cx, cy, e.shiftKey, editor, e.ctrlKey)\n return\n }\n\n if (d.type === 'pen-drag') {\n handlePenDragMove(d, cx, cy, spaceHeld(), e, editor)\n return\n }\n\n if (d.type === 'pencil-drag') {\n handlePencilDragMove(cx, cy, e.shiftKey, editor)\n return\n }\n\n if (d.type === 'edit-node' || d.type === 'edit-handle') {\n handleNodeEditMove(d, cx, cy, editor, e.altKey, e.metaKey || e.ctrlKey, e.shiftKey, e.ctrlKey)\n return\n }\n\n if (d.type === 'bend-handle') {\n handleBendHandleMove(d, cx, cy, e, editor)\n return\n }\n\n if (d.type === 'bend-segment' || d.type === 'edit-transform') {\n handleNodeEditTransformMove(d, cx, cy, e, editor)\n return\n }\n\n if (d.type === 'edit-marquee') {\n handleNodeEditMarqueeMove(d, cx, cy, editor)\n return\n }\n\n if (d.type === 'draw') {\n handleDrawMove(d, cx, cy, e.shiftKey)\n return\n }\n\n if (d.type === 'sticky-draw') {\n d.move(cx, cy)\n return\n }\n\n if (d.type === 'connector-draw') {\n handleConnectorDrawMove(d, cx, cy, sx, sy, editor, attachModifiers(e))\n return\n }\n\n if (d.type === 'connector-end') {\n editor.connectorEndpointDrag(cx, cy, attachModifiers(e))\n return\n }\n\n if (d.type === 'connector-line') {\n editor.connectorLineDrag(cx, cy)\n return\n }\n\n if (d.type === 'line-end') {\n editor.lineEndDrag(cx, cy, { shift: e.shiftKey, alt: e.altKey })\n return\n }\n\n if (d.type === 'sticky-scale') {\n applyStickyScale(d, cx, cy, editor)\n return\n }\n\n if (d.type === 'zoom' || d.type === 'scale') {\n d.update(cx, cy, sx, sy, e.altKey)\n return\n }\n\n // While ⌘ or Ctrl is held the marquee reaches nested layers, as in Figma.\n transform.handleMarqueeMove(d, cx, cy, e.metaKey || e.ctrlKey)\n}\n"],"mappings":";;;;;;;;;;;;;AAyCA,SAAgB,SACd,GACA,GACA,EAAE,IAAI,IAAI,IAAI,MACd,EAAE,QAAQ,YAAY,WAAW,aAC3B;CACN,IAAI,EAAE,SAAS,OAAO;EACpB,UAAU,cAAc,GAAG,CAAC;EAC5B;CACF;CAEA,IAAI,EAAE,SAAS,cAAc,EAAE,SAAS,gBAAgB;EACtD,EAAE,OAAO,IAAI,IAAI,EAAE,QAAQ;EAC3B;CACF;CAEA,IAAI,EAAE,SAAS,cAAc;EAC3B,EAAE,OAAO,IAAI,IAAI;GAAE,OAAO,EAAE;GAAU,KAAK,EAAE;EAAO,CAAC;EACrD;CACF;CAEA,IAAI,EAAE,SAAS,SAAS;EACtB,MAAM,UAAU,EAAE,UAAU,CAAC,EAAE,UAAU,6BAA6B,MAAM,IAAI;EAChF,WAAW,WACT,GACA,IACA,IACA,IACA,IACA,UAAU;GAAE;GAAS,MAAM,EAAE,WAAW,EAAE;EAAQ,IAAI,KAAA,CACxD;EACA;CACF;CAEA,IAAI,EAAE,SAAS,UAAU;EACvB,UA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Q,gBAAgB,CAAC,CAAC;EACrE;CACF;CAEA,IAAI,EAAE,SAAS,iBAAiB;EAC9B,OAAO,sBAAsB,IAAI,IAAI,gBAAgB,CAAC,CAAC;EACvD;CACF;CAEA,IAAI,EAAE,SAAS,kBAAkB;EAC/B,OAAO,kBAAkB,IAAI,EAAE;EAC/B;CACF;CAEA,IAAI,EAAE,SAAS,YAAY;EACzB,OAAO,YAAY,IAAI,IAAI;GAAE,OAAO,EAAE;GAAU,KAAK,EAAE;EAAO,CAAC;EAC/D;CACF;CAEA,IAAI,EAAE,SAAS,gBAAgB;EAC7B,iBAAiB,GAAG,IAAI,IAAI,MAAM;EAClC;CACF;CAEA,IAAI,EAAE,SAAS,UAAU,EAAE,SAAS,SAAS;EAC3C,EAAE,OAAO,IAAI,IAAI,IAAI,IAAI,EAAE,MAAM;EACjC;CACF;CAGA,UAAU,kBAAkB,GAAG,IAAI,IAAI,EAAE,WAAW,EAAE,OAAO;AAC/D"}
1
+ {"version":3,"file":"drag-move.js","names":[],"sources":["../../../src/canvas/pointer/drag-move.ts"],"sourcesContent":["import type { Editor } from '@pairdraw/core'\n\nimport { selectedTopLevelGuideFrameId, type createGuideInput } from '#vue/canvas/guides/input'\nimport { handlePenDragMove } from '#vue/canvas/pen/input'\nimport { handlePencilDragMove } from '#vue/canvas/pencil/input'\nimport type { createCanvasTransformInput } from '#vue/canvas/transform/input'\nimport { handleBendHandleMove } from '#vue/canvas/vector-input/input'\nimport { attachModifiers, handleConnectorDrawMove } from '#vue/shared/input/connector/draw'\nimport { handleDrawMove } from '#vue/shared/input/draw'\nimport { handleMoveMove } from '#vue/shared/input/move/drag'\nimport { applyResize } from '#vue/shared/input/resize'\nimport { applyStickyScale } from '#vue/shared/input/sticky/scale'\nimport type { DragState } from '#vue/shared/input/types'\nimport { handleNodeEditMarqueeMove, handleNodeEditMove } from '#vue/shared/input/vector'\nimport { handleNodeEditTransformMove } from '#vue/shared/input/vector/transform'\n\ntype TransformInput = ReturnType<typeof createCanvasTransformInput>\n\n/** What a drag in progress reaches while the pointer moves. */\nexport interface DragMoveContext {\n editor: Editor\n guideInput: Pick<ReturnType<typeof createGuideInput>, 'handleMove'>\n transform: Pick<\n TransformInput,\n 'handlePanMove' | 'handleRotateMove' | 'handleTextSelectMove' | 'handleMarqueeMove'\n >\n /** Whether Space is held, which moves a pen handle's anchor instead of the handle. */\n spaceHeld: () => boolean\n}\n\n/** Pointer position on screen (`sx`, `sy`) and on the canvas (`cx`, `cy`). */\ninterface DragMovePointer {\n sx: number\n sy: number\n cx: number\n cy: number\n}\n\n/** Moves the drag in progress to the pointer, for each kind of drag the canvas starts. */\n// Dispatching the full drag union is intentionally centralized here.\n// eslint-disable-next-line complexity\nexport function moveDrag(\n d: DragState,\n e: MouseEvent,\n { sx, sy, cx, cy }: DragMovePointer,\n { editor, guideInput, transform, spaceHeld }: DragMoveContext\n): void {\n if (d.type === 'pan') {\n transform.handlePanMove(d, e)\n return\n }\n\n if (d.type === 'auto-layout') {\n d.update(sx, sy, e.altKey, e.shiftKey)\n return\n }\n\n if (d.type === 'gradient' || d.type === 'shape-handle') {\n d.update(sx, sy, e.shiftKey)\n return\n }\n\n if (d.type === 'image-crop') {\n d.update(sx, sy, { shift: e.shiftKey, alt: e.altKey })\n return\n }\n\n if (d.type === 'guide') {\n const frameId = e.altKey && !d.guideId ? selectedTopLevelGuideFrameId(editor) : null\n guideInput.handleMove(\n d,\n sx,\n sy,\n cx,\n cy,\n frameId ? { frameId, deep: e.metaKey || e.ctrlKey } : undefined\n )\n return\n }\n\n if (d.type === 'rotate') {\n transform.handleRotateMove(d, cx, cy, e.shiftKey)\n return\n }\n if (d.type === 'move') {\n handleMoveMove(d, cx, cy, sx, sy, editor, { ctrlKey: e.ctrlKey, shiftKey: e.shiftKey })\n return\n }\n if (d.type === 'text-select') {\n transform.handleTextSelectMove(cx, cy)\n return\n }\n if (d.type === 'resize') {\n applyResize(d, cx, cy, e.shiftKey, editor, e.ctrlKey)\n return\n }\n\n if (d.type === 'pen-drag') {\n handlePenDragMove(d, cx, cy, spaceHeld(), e, editor)\n return\n }\n\n if (d.type === 'pencil-drag') {\n handlePencilDragMove(cx, cy, e.shiftKey, editor)\n return\n }\n\n if (d.type === 'edit-node' || d.type === 'edit-handle') {\n handleNodeEditMove(d, cx, cy, editor, e.altKey, e.metaKey || e.ctrlKey, e.shiftKey, e.ctrlKey)\n return\n }\n\n if (d.type === 'bend-handle') {\n handleBendHandleMove(d, cx, cy, e, editor)\n return\n }\n\n if (d.type === 'bend-segment' || d.type === 'edit-transform') {\n handleNodeEditTransformMove(d, cx, cy, e, editor)\n return\n }\n\n if (d.type === 'edit-marquee') {\n handleNodeEditMarqueeMove(d, cx, cy, editor)\n return\n }\n\n if (d.type === 'draw') {\n handleDrawMove(d, cx, cy, e.shiftKey)\n return\n }\n\n if (d.type === 'sticky-draw') {\n d.move(cx, cy)\n return\n }\n\n if (d.type === 'connector-draw') {\n handleConnectorDrawMove(d, cx, cy, sx, sy, editor, attachModifiers(e))\n return\n }\n\n if (d.type === 'connector-end') {\n editor.connectorEndpointDrag(cx, cy, attachModifiers(e))\n return\n }\n\n if (d.type === 'connector-line') {\n editor.connectorLineDrag(cx, cy)\n return\n }\n\n if (d.type === 'line-end') {\n editor.lineEndDrag(cx, cy, { shift: e.shiftKey, alt: e.altKey })\n return\n }\n\n if (d.type === 'sticky-scale') {\n applyStickyScale(d, cx, cy, editor)\n return\n }\n\n if (d.type === 'zoom' || d.type === 'scale') {\n d.update(cx, cy, sx, sy, e.altKey)\n return\n }\n\n // While ⌘ or Ctrl is held the marquee reaches nested layers, as in Figma.\n transform.handleMarqueeMove(d, cx, cy, e.metaKey || e.ctrlKey)\n}\n"],"mappings":";;;;;;;;;;;;;AAyCA,SAAgB,SACd,GACA,GACA,EAAE,IAAI,IAAI,IAAI,MACd,EAAE,QAAQ,YAAY,WAAW,aAC3B;CACN,IAAI,EAAE,SAAS,OAAO;EACpB,UAAU,cAAc,GAAG,CAAC;EAC5B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js";
1
2
  import { onScopeDispose, watch } from "vue";
2
3
  import { getCanvasKit } from "@pairdraw/core/canvaskit";
3
4
  //#region src/canvas/surface/kit-loader.ts
@@ -9,9 +10,7 @@ function useCanvasKitLoader({ canvasRef, lifecycle, setCanvasKit, createSurface,
9
10
  if (!stillCurrent()) return;
10
11
  setCanvasKit(await loadCanvasKit());
11
12
  if (!stillCurrent()) return;
12
- await new Promise((resolve) => {
13
- requestAnimationFrame(resolve);
14
- });
13
+ await nextFrame();
15
14
  if (!stillCurrent()) return;
16
15
  if (!createSurface(canvas)) throw new Error("WebGL is unavailable, so the canvas cannot draw");
17
16
  await loadFonts();
@@ -1 +1 @@
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"}
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\nimport { nextFrame } from '#vue/shared/frame'\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 nextFrame()\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":";;;;AAyBA,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,UAAU;EAChB,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"}
@@ -7,8 +7,18 @@ import { useCanvasResizeObserver } from "./resize-observer.js";
7
7
  import { createShaderRasterizer } from "./shader/rasterizer.js";
8
8
  import { editorMessages } from "../../i18n/messages/editor.js";
9
9
  import { onScopeDispose, watch } from "vue";
10
+ import { useDocumentVisibility } from "@vueuse/core";
10
11
  import { SkiaRenderer } from "@pairdraw/core/canvas";
11
12
  //#region src/canvas/surface/lifecycle.ts
13
+ /**
14
+ * The device's memory in bytes where the browser reports it. Browsers round it and stop at 8 GB,
15
+ * which means at least that much, so a device at the cap is treated as unknown.
16
+ */
17
+ function reportedDeviceMemory() {
18
+ const gigabytes = Reflect.get(navigator, "deviceMemory");
19
+ if (typeof gigabytes !== "number" || gigabytes >= 8) return void 0;
20
+ return gigabytes * 1024 ** 3;
21
+ }
12
22
  /** What a canvas asks of its renderer: its layer, renderer mode, pixel density, and effects. */
13
23
  function applyRenderOptions(renderer, options) {
14
24
  renderer.tracksSceneSettlement = options?.layer !== "overlays";
@@ -17,9 +27,15 @@ function applyRenderOptions(renderer, options) {
17
27
  renderer.reducedEffects = options?.reducedEffects ?? false;
18
28
  renderer.onNodeDrawFailure = options?.onNodeDrawFailure ?? null;
19
29
  }
20
- /** Shows only the scope layer the canvas asks for, or the whole page when it asks for none. */
30
+ /**
31
+ * Shows only the scope layer the canvas asks for, or the whole page when it asks for none, with
32
+ * the frames a playing prototype changed drawn from their play scenes, scrolled as play scrolled
33
+ * them.
34
+ */
21
35
  function applySceneScope(renderer, options) {
22
36
  renderer.sceneScopeId = options?.getSceneScope?.() ?? null;
37
+ renderer.playScenes = options?.getPlayScenes?.() ?? null;
38
+ renderer.playScroll = options?.getPlayScroll?.() ?? null;
23
39
  }
24
40
  function createCanvasSurfaceManager({ editor, canvasRef, options, getCanvasKit, isDestroyed, shouldShowRulers }) {
25
41
  const state = {
@@ -44,6 +60,16 @@ function createCanvasSurfaceManager({ editor, canvasRef, options, getCanvasKit,
44
60
  renderer.connectorLabelPlaceholder = connectorLabelPlaceholder;
45
61
  if (showsStickyPlaceholder) renderer.stickyPlaceholder = stickyPlaceholder;
46
62
  }
63
+ /**
64
+ * Tells the renderer's tiles what memory they share: a share of the device's where the browser
65
+ * reports it, and only what the canvas showed last while the page is hidden.
66
+ */
67
+ function applyTileMemory() {
68
+ state.renderer?.tiledScene.setMemory({
69
+ deviceBytes: reportedDeviceMemory(),
70
+ hidden: document.visibilityState === "hidden"
71
+ });
72
+ }
47
73
  function clearSceneBackingRenderTimer() {
48
74
  if (sceneBackingRenderTimer === null) return;
49
75
  clearTimeout(sceneBackingRenderTimer);
@@ -84,6 +110,7 @@ function createCanvasSurfaceManager({ editor, canvasRef, options, getCanvasKit,
84
110
  state.renderer.presentationColorSpace = result.presentation ?? "srgb";
85
111
  applyRenderOptions(state.renderer, options);
86
112
  showPlaceholders(state.renderer);
113
+ applyTileMemory();
87
114
  editor.setCanvasKit(ck, state.renderer);
88
115
  if (options?.layer !== "overlays" && !editor.hasShaderRasterizer()) editor.setShaderRasterizer(createShaderRasterizer());
89
116
  canvas.dataset.ready = "1";
@@ -171,6 +198,7 @@ function createCanvasSurfaceManager({ editor, canvasRef, options, getCanvasKit,
171
198
  renderNow,
172
199
  destroy,
173
200
  markDirty: () => renderLoop.markDirty(),
201
+ applyTileMemory,
174
202
  getRenderer: () => state.renderer,
175
203
  getPresentation: () => state.presentation
176
204
  };
@@ -223,6 +251,7 @@ function useCanvasSurfaceLifecycle({ canvasRef, surface, setCanvasKit, getCanvas
223
251
  getCanvasKitValue,
224
252
  resizeCanvas: surface.resizeCanvas
225
253
  });
254
+ watch(useDocumentVisibility(), () => surface.applyTileMemory());
226
255
  onScopeDispose(() => {
227
256
  lifecycle.destroyed = true;
228
257
  cancelResize();
@@ -1 +1 @@
1
- {"version":3,"file":"lifecycle.js","names":[],"sources":["../../../src/canvas/surface/lifecycle.ts"],"sourcesContent":["import type { CanvasKit } from 'canvaskit-wasm'\nimport { onScopeDispose, watch } from 'vue'\nimport type { Ref } from 'vue'\n\nimport type { Editor } from '@pairdraw/core'\nimport { SkiaRenderer } from '@pairdraw/core/canvas'\n\nimport {\n supportsWideGamutPresentation,\n type PresentationColorSpace\n} from '#vue/canvas/surface/color-space'\nimport {\n makeGLSurface,\n releaseWebGLContext,\n sizeCanvas,\n type CanvasGLContext,\n type CanvasGLHandle\n} from '#vue/canvas/surface/gl-surface'\nimport { createImagePreviewDecoder } from '#vue/canvas/surface/image-preview'\nimport { useCanvasKitLoader } from '#vue/canvas/surface/kit-loader'\nimport { createCanvasRenderLoop } from '#vue/canvas/surface/render-loop'\nimport { useCanvasResizeObserver } from '#vue/canvas/surface/resize-observer'\nimport { createShaderRasterizer } from '#vue/canvas/surface/shader/rasterizer'\nimport type { UseCanvasOptions } from '#vue/canvas/surface/types'\nimport { editorMessages } from '#vue/i18n/messages/editor'\n\ntype SurfaceManagerState = {\n renderer: SkiaRenderer | null\n glContext: CanvasGLContext | null\n glHandle: CanvasGLHandle | null\n /** The canvas the WebGL context belongs to, kept until the context is released. */\n glCanvas: HTMLCanvasElement | null\n presentation: PresentationColorSpace | null\n}\n\n/** What a canvas asks of its renderer: its layer, renderer mode, pixel density, and effects. */\nfunction applyRenderOptions(renderer: SkiaRenderer, options: UseCanvasOptions | undefined) {\n renderer.tracksSceneSettlement = options?.layer !== 'overlays'\n renderer.tiledSceneEnabled = options?.sceneRenderer === 'tiled'\n // The canvas buffer is sized for this ratio, so the renderer must draw at the same one.\n renderer.maxPixelRatio = options?.maxPixelRatio ?? Number.POSITIVE_INFINITY\n renderer.reducedEffects = options?.reducedEffects ?? false\n renderer.onNodeDrawFailure = options?.onNodeDrawFailure ?? null\n}\n\n/** Shows only the scope layer the canvas asks for, or the whole page when it asks for none. */\nfunction applySceneScope(renderer: SkiaRenderer, options: UseCanvasOptions | undefined) {\n renderer.sceneScopeId = options?.getSceneScope?.() ?? null\n}\n\nexport function createCanvasSurfaceManager({\n editor,\n canvasRef,\n options,\n getCanvasKit,\n isDestroyed,\n shouldShowRulers\n}: {\n editor: Editor\n canvasRef: { value: HTMLCanvasElement | null }\n options: UseCanvasOptions | undefined\n getCanvasKit: () => CanvasKit | null\n isDestroyed: () => boolean\n shouldShowRulers: () => boolean\n}) {\n const state: SurfaceManagerState = {\n renderer: null,\n glContext: null,\n glHandle: null,\n glCanvas: null,\n presentation: null\n }\n let sceneBackingRenderTimer: ReturnType<typeof setTimeout> | null = null\n\n // The scene of an editing canvas shows an empty sticky note's placeholder, and every layer an\n // empty connector label's while it is typed into, as the overlays draw the text being edited,\n // in the interface language, and draws them again when the language changes.\n const showsStickyPlaceholder = options?.layer !== 'overlays'\n let stickyPlaceholder: string = editorMessages.get().stickyPlaceholder\n let connectorLabelPlaceholder: string = editorMessages.get().connectorLabelPlaceholder\n const stopPlaceholders = editorMessages.subscribe((messages) => {\n if (\n messages.stickyPlaceholder === stickyPlaceholder &&\n messages.connectorLabelPlaceholder === connectorLabelPlaceholder\n ) {\n return\n }\n ;({ stickyPlaceholder, connectorLabelPlaceholder } = messages)\n if (!state.renderer) return\n showPlaceholders(state.renderer)\n editor.requestRender()\n })\n\n function showPlaceholders(renderer: SkiaRenderer) {\n renderer.connectorLabelPlaceholder = connectorLabelPlaceholder\n if (showsStickyPlaceholder) renderer.stickyPlaceholder = stickyPlaceholder\n }\n\n function clearSceneBackingRenderTimer() {\n if (sceneBackingRenderTimer === null) return\n clearTimeout(sceneBackingRenderTimer)\n sceneBackingRenderTimer = null\n }\n\n /** Releases the Skia context and the WebGL context CanvasKit registered for this canvas. */\n function releaseGLContext() {\n state.glContext?.delete()\n state.glContext = null\n const ck = getCanvasKit()\n if (ck && state.glHandle !== null) releaseWebGLContext(ck, state.glHandle, state.glCanvas)\n state.glHandle = null\n state.glCanvas = null\n }\n\n function createSurface(\n canvas: HTMLCanvasElement,\n { reloadFonts = false }: { reloadFonts?: boolean } = {}\n ): boolean {\n const ck = getCanvasKit()\n if (!ck) return false\n\n if (state.renderer) editor.removeCanvasRenderer(state.renderer)\n state.renderer?.destroy()\n state.renderer = null\n releaseGLContext()\n\n sizeCanvas(canvas, editor, options?.onViewportResize, options?.maxPixelRatio)\n\n const result = makeGLSurface(\n ck,\n canvas,\n options,\n state.glContext,\n editor.graph.documentColorSpace\n )\n state.glContext = result.glContext\n state.glHandle = result.glHandle\n state.glCanvas = result.glHandle === null ? null : canvas\n state.presentation = result.presentation\n options?.onPresentation?.(result.presentation)\n const surface = result.surface\n if (!surface) {\n canvas.dataset.surfaceError = 'webgl'\n return false\n }\n\n const glCtx = canvas.getContext('webgl2') ?? null\n state.renderer = new SkiaRenderer(ck, surface, glCtx)\n state.renderer.onImagePreviewReady = () => renderLoop.markDirty()\n state.renderer.imagePreviews.setDecoder(createImagePreviewDecoder())\n state.renderer.presentationColorSpace = result.presentation ?? 'srgb'\n applyRenderOptions(state.renderer, options)\n showPlaceholders(state.renderer)\n editor.setCanvasKit(ck, state.renderer)\n // The scene surface draws shader frames; an overlay surface has none to draw.\n if (options?.layer !== 'overlays' && !editor.hasShaderRasterizer())\n editor.setShaderRasterizer(createShaderRasterizer())\n canvas.dataset.ready = '1'\n\n // When the surface is recreated after a resize fallback, destroyRenderer\n // has cleared the module-level fontProvider — the new renderer must reload.\n // On initial mount, kit-loader.init() handles loadFonts, so skip here.\n if (reloadFonts && !isDestroyed()) {\n void state.renderer.loadFonts(renderNow).then(() => {\n if (!isDestroyed()) renderNow()\n return undefined\n })\n }\n return true\n }\n\n function acknowledgePresentation() {\n const renderedState = options?.getRenderState?.() ?? editor.state\n options?.onPresented?.({\n renderVersion: renderedState.renderVersion,\n sceneVersion: renderedState.sceneVersion\n })\n }\n\n function renderNow() {\n if (!state.renderer || isDestroyed()) return\n const view = options?.getRenderState?.() ?? editor.state\n applySceneScope(state.renderer, options)\n state.renderer.renderFromEditorState(\n view,\n editor.graph,\n editor.textEditor,\n canvasRef.value?.clientWidth ?? 0,\n canvasRef.value?.clientHeight ?? 0,\n shouldShowRulers(),\n options?.layer ?? 'full',\n editor.isInteractiveEditing()\n )\n renderLoop.markRendered()\n options?.onFrame?.({ panX: view.panX, panY: view.panY, zoom: view.zoom })\n acknowledgePresentation()\n clearSceneBackingRenderTimer()\n if (options?.layer === 'scene' && state.renderer.tiledScenePending) {\n renderLoop.markDirty()\n }\n if (options?.layer === 'scene' && state.renderer.sceneBackingNeedsCrispRender) {\n const delay = Math.max(0, state.renderer.sceneBackingPreviewUntil - performance.now())\n sceneBackingRenderTimer = setTimeout(() => renderLoop.markDirty(), delay)\n }\n }\n\n const renderLoop = createCanvasRenderLoop(editor, renderNow, {\n layer: options?.layer,\n getRenderState: options?.getRenderState,\n shouldSuspendRender: options?.shouldSuspendRender\n })\n\n function resizeCanvas(canvas: HTMLCanvasElement) {\n const ck = getCanvasKit()\n if (!ck || !state.renderer) {\n createSurface(canvas)\n return\n }\n\n sizeCanvas(canvas, editor, options?.onViewportResize, options?.maxPixelRatio)\n\n const result = makeGLSurface(\n ck,\n canvas,\n options,\n state.glContext,\n editor.graph.documentColorSpace\n )\n state.glContext = result.glContext\n state.presentation = result.presentation\n options?.onPresentation?.(result.presentation)\n const surface = result.surface\n if (!surface) {\n console.warn('Falling back to full surface recreation after resize')\n createSurface(canvas, { reloadFonts: true })\n return\n }\n state.renderer.presentationColorSpace = result.presentation ?? 'srgb'\n state.renderer.replaceSurface(surface)\n renderNow()\n }\n\n const wantsWideGamut = () =>\n editor.graph.documentColorSpace === 'display-p3' && supportsWideGamutPresentation()\n\n /** A P3 document needs the P3 surface, and vice versa; documents arrive after mount. */\n function refreshPresentation() {\n if (isDestroyed()) return\n const canvas = canvasRef.value\n if (!canvas) return\n if (wantsWideGamut() === (state.presentation === 'display-p3')) return\n createSurface(canvas, { reloadFonts: true })\n }\n\n const stopPresentationRefresh = editor.onEditorEvent('graph:replaced', refreshPresentation)\n const stopColorSpaceRefresh = editor.onEditorEvent(\n 'document:color-space-changed',\n refreshPresentation\n )\n\n function destroy() {\n stopPlaceholders()\n stopPresentationRefresh()\n stopColorSpaceRefresh()\n clearSceneBackingRenderTimer()\n renderLoop.pause()\n if (state.renderer) editor.removeCanvasRenderer(state.renderer)\n state.renderer?.destroy()\n releaseGLContext()\n }\n\n return {\n createSurface,\n resizeCanvas,\n renderNow,\n destroy,\n markDirty: () => renderLoop.markDirty(),\n getRenderer: () => state.renderer,\n getPresentation: () => state.presentation\n }\n}\n\n/**\n * A browser takes a canvas's WebGL context away on a GPU reset, a driver update, or a tab that\n * comes back from sleep. Ignoring the events leaves the canvas blank for good: the loss is\n * prevented so the context can be given back. The app replaces the element, which starts again.\n * An SDK canvas keeps its element, so the surface is made again on that same element once the\n * browser gives the context back.\n */\nfunction connectContextRecovery(\n canvasRef: Ref<HTMLCanvasElement | null>,\n lifecycle: { destroyed: boolean },\n onContextLost: (() => void) | undefined,\n recreateSurface: (canvas: HTMLCanvasElement) => void\n): void {\n watch(\n canvasRef,\n (canvas, _previous, onCleanup) => {\n if (!canvas) return\n const onLost = (event: Event) => {\n // The host may replace the canvas, because a context the browser keeps lost can never be\n // drawn into again; a fresh element gets a fresh context.\n event.preventDefault()\n if (lifecycle.destroyed) return\n onContextLost?.()\n }\n const onRestored = () => {\n if (lifecycle.destroyed) return\n // A host that already swapped in a new element must not have the old one's restore\n // rebuild a surface for a canvas that is no longer shown.\n if (canvasRef.value !== canvas) return\n recreateSurface(canvas)\n }\n canvas.addEventListener('webglcontextlost', onLost)\n canvas.addEventListener('webglcontextrestored', onRestored)\n onCleanup(() => {\n canvas.removeEventListener('webglcontextlost', onLost)\n canvas.removeEventListener('webglcontextrestored', onRestored)\n })\n },\n { flush: 'post' }\n )\n}\n\nexport function useCanvasSurfaceLifecycle({\n canvasRef,\n surface,\n setCanvasKit,\n getCanvasKitValue,\n lifecycle,\n onReady,\n onFailed,\n onContextLost,\n loadCanvasKit\n}: {\n canvasRef: Ref<HTMLCanvasElement | null>\n surface: ReturnType<typeof createCanvasSurfaceManager>\n setCanvasKit: (ck: CanvasKit | null) => void\n getCanvasKitValue: () => CanvasKit | null\n lifecycle: { destroyed: boolean }\n onReady?: () => void\n onFailed?: (error: unknown) => void\n onContextLost?: () => void\n /** Loads CanvasKit. The canvas uses the shared loader; a test can pass a stand-in. */\n loadCanvasKit?: () => Promise<CanvasKit>\n}) {\n useCanvasKitLoader({\n canvasRef,\n lifecycle,\n setCanvasKit,\n createSurface: surface.createSurface,\n loadFonts: () => surface.getRenderer()?.loadFonts(surface.renderNow),\n renderNow: surface.renderNow,\n onReady,\n onFailed,\n loadCanvasKit\n })\n\n connectContextRecovery(canvasRef, lifecycle, onContextLost, (canvas) => {\n surface.createSurface(canvas, { reloadFonts: true })\n })\n\n const { cancelResize } = useCanvasResizeObserver({\n canvasRef,\n getCanvasKitValue,\n resizeCanvas: surface.resizeCanvas\n })\n\n onScopeDispose(() => {\n lifecycle.destroyed = true\n cancelResize()\n surface.destroy()\n })\n}\n"],"mappings":";;;;;;;;;;;;AAoCA,SAAS,mBAAmB,UAAwB,SAAuC;CACzF,SAAS,wBAAwB,SAAS,UAAU;CACpD,SAAS,oBAAoB,SAAS,kBAAkB;CAExD,SAAS,gBAAgB,SAAS,iBAAiB,OAAO;CAC1D,SAAS,iBAAiB,SAAS,kBAAkB;CACrD,SAAS,oBAAoB,SAAS,qBAAqB;AAC7D;;AAGA,SAAS,gBAAgB,UAAwB,SAAuC;CACtF,SAAS,eAAe,SAAS,gBAAgB,KAAK;AACxD;AAEA,SAAgB,2BAA2B,EACzC,QACA,WACA,SACA,cACA,aACA,oBAQC;CACD,MAAM,QAA6B;EAC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iBAAiB,wBAAwB;EAC/C;EACA;EACA,cAAc,QAAQ;CACxB,CAAC;CAED,qBAAqB;EACnB,UAAU,YAAY;EACtB,aAAa;EACb,QAAQ,QAAQ;CAClB,CAAC;AACH"}
1
+ {"version":3,"file":"lifecycle.js","names":[],"sources":["../../../src/canvas/surface/lifecycle.ts"],"sourcesContent":["import { useDocumentVisibility } from '@vueuse/core'\nimport type { CanvasKit } from 'canvaskit-wasm'\nimport { onScopeDispose, watch } from 'vue'\nimport type { Ref } from 'vue'\n\nimport type { Editor } from '@pairdraw/core'\nimport { SkiaRenderer } from '@pairdraw/core/canvas'\n\nimport {\n supportsWideGamutPresentation,\n type PresentationColorSpace\n} from '#vue/canvas/surface/color-space'\nimport {\n makeGLSurface,\n releaseWebGLContext,\n sizeCanvas,\n type CanvasGLContext,\n type CanvasGLHandle\n} from '#vue/canvas/surface/gl-surface'\nimport { createImagePreviewDecoder } from '#vue/canvas/surface/image-preview'\nimport { useCanvasKitLoader } from '#vue/canvas/surface/kit-loader'\nimport { createCanvasRenderLoop } from '#vue/canvas/surface/render-loop'\nimport { useCanvasResizeObserver } from '#vue/canvas/surface/resize-observer'\nimport { createShaderRasterizer } from '#vue/canvas/surface/shader/rasterizer'\nimport type { UseCanvasOptions } from '#vue/canvas/surface/types'\nimport { editorMessages } from '#vue/i18n/messages/editor'\n\n/**\n * The device's memory in bytes where the browser reports it. Browsers round it and stop at 8 GB,\n * which means at least that much, so a device at the cap is treated as unknown.\n */\nfunction reportedDeviceMemory(): number | undefined {\n // Chromium's Device Memory API; WebKit and Firefox leave it out.\n const gigabytes: unknown = Reflect.get(navigator, 'deviceMemory')\n if (typeof gigabytes !== 'number' || gigabytes >= 8) return undefined\n return gigabytes * 1024 ** 3\n}\n\ntype SurfaceManagerState = {\n renderer: SkiaRenderer | null\n glContext: CanvasGLContext | null\n glHandle: CanvasGLHandle | null\n /** The canvas the WebGL context belongs to, kept until the context is released. */\n glCanvas: HTMLCanvasElement | null\n presentation: PresentationColorSpace | null\n}\n\n/** What a canvas asks of its renderer: its layer, renderer mode, pixel density, and effects. */\nfunction applyRenderOptions(renderer: SkiaRenderer, options: UseCanvasOptions | undefined) {\n renderer.tracksSceneSettlement = options?.layer !== 'overlays'\n renderer.tiledSceneEnabled = options?.sceneRenderer === 'tiled'\n // The canvas buffer is sized for this ratio, so the renderer must draw at the same one.\n renderer.maxPixelRatio = options?.maxPixelRatio ?? Number.POSITIVE_INFINITY\n renderer.reducedEffects = options?.reducedEffects ?? false\n renderer.onNodeDrawFailure = options?.onNodeDrawFailure ?? null\n}\n\n/**\n * Shows only the scope layer the canvas asks for, or the whole page when it asks for none, with\n * the frames a playing prototype changed drawn from their play scenes, scrolled as play scrolled\n * them.\n */\nfunction applySceneScope(renderer: SkiaRenderer, options: UseCanvasOptions | undefined) {\n renderer.sceneScopeId = options?.getSceneScope?.() ?? null\n renderer.playScenes = options?.getPlayScenes?.() ?? null\n renderer.playScroll = options?.getPlayScroll?.() ?? null\n}\n\nexport function createCanvasSurfaceManager({\n editor,\n canvasRef,\n options,\n getCanvasKit,\n isDestroyed,\n shouldShowRulers\n}: {\n editor: Editor\n canvasRef: { value: HTMLCanvasElement | null }\n options: UseCanvasOptions | undefined\n getCanvasKit: () => CanvasKit | null\n isDestroyed: () => boolean\n shouldShowRulers: () => boolean\n}) {\n const state: SurfaceManagerState = {\n renderer: null,\n glContext: null,\n glHandle: null,\n glCanvas: null,\n presentation: null\n }\n let sceneBackingRenderTimer: ReturnType<typeof setTimeout> | null = null\n\n // The scene of an editing canvas shows an empty sticky note's placeholder, and every layer an\n // empty connector label's while it is typed into, as the overlays draw the text being edited,\n // in the interface language, and draws them again when the language changes.\n const showsStickyPlaceholder = options?.layer !== 'overlays'\n let stickyPlaceholder: string = editorMessages.get().stickyPlaceholder\n let connectorLabelPlaceholder: string = editorMessages.get().connectorLabelPlaceholder\n const stopPlaceholders = editorMessages.subscribe((messages) => {\n if (\n messages.stickyPlaceholder === stickyPlaceholder &&\n messages.connectorLabelPlaceholder === connectorLabelPlaceholder\n ) {\n return\n }\n ;({ stickyPlaceholder, connectorLabelPlaceholder } = messages)\n if (!state.renderer) return\n showPlaceholders(state.renderer)\n editor.requestRender()\n })\n\n function showPlaceholders(renderer: SkiaRenderer) {\n renderer.connectorLabelPlaceholder = connectorLabelPlaceholder\n if (showsStickyPlaceholder) renderer.stickyPlaceholder = stickyPlaceholder\n }\n\n /**\n * Tells the renderer's tiles what memory they share: a share of the device's where the browser\n * reports it, and only what the canvas showed last while the page is hidden.\n */\n function applyTileMemory() {\n state.renderer?.tiledScene.setMemory({\n deviceBytes: reportedDeviceMemory(),\n hidden: document.visibilityState === 'hidden'\n })\n }\n\n function clearSceneBackingRenderTimer() {\n if (sceneBackingRenderTimer === null) return\n clearTimeout(sceneBackingRenderTimer)\n sceneBackingRenderTimer = null\n }\n\n /** Releases the Skia context and the WebGL context CanvasKit registered for this canvas. */\n function releaseGLContext() {\n state.glContext?.delete()\n state.glContext = null\n const ck = getCanvasKit()\n if (ck && state.glHandle !== null) releaseWebGLContext(ck, state.glHandle, state.glCanvas)\n state.glHandle = null\n state.glCanvas = null\n }\n\n function createSurface(\n canvas: HTMLCanvasElement,\n { reloadFonts = false }: { reloadFonts?: boolean } = {}\n ): boolean {\n const ck = getCanvasKit()\n if (!ck) return false\n\n if (state.renderer) editor.removeCanvasRenderer(state.renderer)\n state.renderer?.destroy()\n state.renderer = null\n releaseGLContext()\n\n sizeCanvas(canvas, editor, options?.onViewportResize, options?.maxPixelRatio)\n\n const result = makeGLSurface(\n ck,\n canvas,\n options,\n state.glContext,\n editor.graph.documentColorSpace\n )\n state.glContext = result.glContext\n state.glHandle = result.glHandle\n state.glCanvas = result.glHandle === null ? null : canvas\n state.presentation = result.presentation\n options?.onPresentation?.(result.presentation)\n const surface = result.surface\n if (!surface) {\n canvas.dataset.surfaceError = 'webgl'\n return false\n }\n\n const glCtx = canvas.getContext('webgl2') ?? null\n state.renderer = new SkiaRenderer(ck, surface, glCtx)\n state.renderer.onImagePreviewReady = () => renderLoop.markDirty()\n state.renderer.imagePreviews.setDecoder(createImagePreviewDecoder())\n state.renderer.presentationColorSpace = result.presentation ?? 'srgb'\n applyRenderOptions(state.renderer, options)\n showPlaceholders(state.renderer)\n applyTileMemory()\n editor.setCanvasKit(ck, state.renderer)\n // The scene surface draws shader frames; an overlay surface has none to draw.\n if (options?.layer !== 'overlays' && !editor.hasShaderRasterizer())\n editor.setShaderRasterizer(createShaderRasterizer())\n canvas.dataset.ready = '1'\n\n // When the surface is recreated after a resize fallback, destroyRenderer\n // has cleared the module-level fontProvider — the new renderer must reload.\n // On initial mount, kit-loader.init() handles loadFonts, so skip here.\n if (reloadFonts && !isDestroyed()) {\n void state.renderer.loadFonts(renderNow).then(() => {\n if (!isDestroyed()) renderNow()\n return undefined\n })\n }\n return true\n }\n\n function acknowledgePresentation() {\n const renderedState = options?.getRenderState?.() ?? editor.state\n options?.onPresented?.({\n renderVersion: renderedState.renderVersion,\n sceneVersion: renderedState.sceneVersion\n })\n }\n\n function renderNow() {\n if (!state.renderer || isDestroyed()) return\n const view = options?.getRenderState?.() ?? editor.state\n applySceneScope(state.renderer, options)\n state.renderer.renderFromEditorState(\n view,\n editor.graph,\n editor.textEditor,\n canvasRef.value?.clientWidth ?? 0,\n canvasRef.value?.clientHeight ?? 0,\n shouldShowRulers(),\n options?.layer ?? 'full',\n editor.isInteractiveEditing()\n )\n renderLoop.markRendered()\n options?.onFrame?.({ panX: view.panX, panY: view.panY, zoom: view.zoom })\n acknowledgePresentation()\n clearSceneBackingRenderTimer()\n if (options?.layer === 'scene' && state.renderer.tiledScenePending) {\n renderLoop.markDirty()\n }\n if (options?.layer === 'scene' && state.renderer.sceneBackingNeedsCrispRender) {\n const delay = Math.max(0, state.renderer.sceneBackingPreviewUntil - performance.now())\n sceneBackingRenderTimer = setTimeout(() => renderLoop.markDirty(), delay)\n }\n }\n\n const renderLoop = createCanvasRenderLoop(editor, renderNow, {\n layer: options?.layer,\n getRenderState: options?.getRenderState,\n shouldSuspendRender: options?.shouldSuspendRender\n })\n\n function resizeCanvas(canvas: HTMLCanvasElement) {\n const ck = getCanvasKit()\n if (!ck || !state.renderer) {\n createSurface(canvas)\n return\n }\n\n sizeCanvas(canvas, editor, options?.onViewportResize, options?.maxPixelRatio)\n\n const result = makeGLSurface(\n ck,\n canvas,\n options,\n state.glContext,\n editor.graph.documentColorSpace\n )\n state.glContext = result.glContext\n state.presentation = result.presentation\n options?.onPresentation?.(result.presentation)\n const surface = result.surface\n if (!surface) {\n console.warn('Falling back to full surface recreation after resize')\n createSurface(canvas, { reloadFonts: true })\n return\n }\n state.renderer.presentationColorSpace = result.presentation ?? 'srgb'\n state.renderer.replaceSurface(surface)\n renderNow()\n }\n\n const wantsWideGamut = () =>\n editor.graph.documentColorSpace === 'display-p3' && supportsWideGamutPresentation()\n\n /** A P3 document needs the P3 surface, and vice versa; documents arrive after mount. */\n function refreshPresentation() {\n if (isDestroyed()) return\n const canvas = canvasRef.value\n if (!canvas) return\n if (wantsWideGamut() === (state.presentation === 'display-p3')) return\n createSurface(canvas, { reloadFonts: true })\n }\n\n const stopPresentationRefresh = editor.onEditorEvent('graph:replaced', refreshPresentation)\n const stopColorSpaceRefresh = editor.onEditorEvent(\n 'document:color-space-changed',\n refreshPresentation\n )\n\n function destroy() {\n stopPlaceholders()\n stopPresentationRefresh()\n stopColorSpaceRefresh()\n clearSceneBackingRenderTimer()\n renderLoop.pause()\n if (state.renderer) editor.removeCanvasRenderer(state.renderer)\n state.renderer?.destroy()\n releaseGLContext()\n }\n\n return {\n createSurface,\n resizeCanvas,\n renderNow,\n destroy,\n markDirty: () => renderLoop.markDirty(),\n applyTileMemory,\n getRenderer: () => state.renderer,\n getPresentation: () => state.presentation\n }\n}\n\n/**\n * A browser takes a canvas's WebGL context away on a GPU reset, a driver update, or a tab that\n * comes back from sleep. Ignoring the events leaves the canvas blank for good: the loss is\n * prevented so the context can be given back. The app replaces the element, which starts again.\n * An SDK canvas keeps its element, so the surface is made again on that same element once the\n * browser gives the context back.\n */\nfunction connectContextRecovery(\n canvasRef: Ref<HTMLCanvasElement | null>,\n lifecycle: { destroyed: boolean },\n onContextLost: (() => void) | undefined,\n recreateSurface: (canvas: HTMLCanvasElement) => void\n): void {\n watch(\n canvasRef,\n (canvas, _previous, onCleanup) => {\n if (!canvas) return\n const onLost = (event: Event) => {\n // The host may replace the canvas, because a context the browser keeps lost can never be\n // drawn into again; a fresh element gets a fresh context.\n event.preventDefault()\n if (lifecycle.destroyed) return\n onContextLost?.()\n }\n const onRestored = () => {\n if (lifecycle.destroyed) return\n // A host that already swapped in a new element must not have the old one's restore\n // rebuild a surface for a canvas that is no longer shown.\n if (canvasRef.value !== canvas) return\n recreateSurface(canvas)\n }\n canvas.addEventListener('webglcontextlost', onLost)\n canvas.addEventListener('webglcontextrestored', onRestored)\n onCleanup(() => {\n canvas.removeEventListener('webglcontextlost', onLost)\n canvas.removeEventListener('webglcontextrestored', onRestored)\n })\n },\n { flush: 'post' }\n )\n}\n\nexport function useCanvasSurfaceLifecycle({\n canvasRef,\n surface,\n setCanvasKit,\n getCanvasKitValue,\n lifecycle,\n onReady,\n onFailed,\n onContextLost,\n loadCanvasKit\n}: {\n canvasRef: Ref<HTMLCanvasElement | null>\n surface: ReturnType<typeof createCanvasSurfaceManager>\n setCanvasKit: (ck: CanvasKit | null) => void\n getCanvasKitValue: () => CanvasKit | null\n lifecycle: { destroyed: boolean }\n onReady?: () => void\n onFailed?: (error: unknown) => void\n onContextLost?: () => void\n /** Loads CanvasKit. The canvas uses the shared loader; a test can pass a stand-in. */\n loadCanvasKit?: () => Promise<CanvasKit>\n}) {\n useCanvasKitLoader({\n canvasRef,\n lifecycle,\n setCanvasKit,\n createSurface: surface.createSurface,\n loadFonts: () => surface.getRenderer()?.loadFonts(surface.renderNow),\n renderNow: surface.renderNow,\n onReady,\n onFailed,\n loadCanvasKit\n })\n\n connectContextRecovery(canvasRef, lifecycle, onContextLost, (canvas) => {\n surface.createSurface(canvas, { reloadFonts: true })\n })\n\n const { cancelResize } = useCanvasResizeObserver({\n canvasRef,\n getCanvasKitValue,\n resizeCanvas: surface.resizeCanvas\n })\n\n // A hidden page draws nothing, so its tiles shrink to what it showed last until it is back.\n watch(useDocumentVisibility(), () => surface.applyTileMemory())\n\n onScopeDispose(() => {\n lifecycle.destroyed = true\n cancelResize()\n surface.destroy()\n })\n}\n"],"mappings":";;;;;;;;;;;;;;;;AA+BA,SAAS,uBAA2C;CAElD,MAAM,YAAqB,QAAQ,IAAI,WAAW,cAAc;CAChE,IAAI,OAAO,cAAc,YAAY,aAAa,GAAG,OAAO,KAAA;CAC5D,OAAO,YAAY,QAAQ;AAC7B;;AAYA,SAAS,mBAAmB,UAAwB,SAAuC;CACzF,SAAS,wBAAwB,SAAS,UAAU;CACpD,SAAS,oBAAoB,SAAS,kBAAkB;CAExD,SAAS,gBAAgB,SAAS,iBAAiB,OAAO;CAC1D,SAAS,iBAAiB,SAAS,kBAAkB;CACrD,SAAS,oBAAoB,SAAS,qBAAqB;AAC7D;;;;;;AAOA,SAAS,gBAAgB,UAAwB,SAAuC;CACtF,SAAS,eAAe,SAAS,gBAAgB,KAAK;CACtD,SAAS,aAAa,SAAS,gBAAgB,KAAK;CACpD,SAAS,aAAa,SAAS,gBAAgB,KAAK;AACtD;AAEA,SAAgB,2BAA2B,EACzC,QACA,WACA,SACA,cACA,aACA,oBAQC;CACD,MAAM,QAA6B;EACjC,UAAU;EACV,WAAW;EACX,UAAU;EACV,UAAU;EACV,cAAc;CAChB;CACA,IAAI,0BAAgE;CAKpE,MAAM,yBAAyB,SAAS,UAAU;CAClD,IAAI,oBAA4B,eAAe,IAAI,CAAC,CAAC;CACrD,IAAI,4BAAoC,eAAe,IAAI,CAAC,CAAC;CAC7D,MAAM,mBAAmB,eAAe,WAAW,aAAa;EAC9D,IACE,SAAS,sBAAsB,qBAC/B,SAAS,8BAA8B,2BAEvC;EAED,CAAC,CAAE,mBAAmB,6BAA8B;E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 -1,6 +1,8 @@
1
1
  import { PresentationColorSpace } from "./color-space.js";
2
+ import { RenderedPlayScene } from "@pairdraw/core/canvas";
2
3
  import { EditorState } from "@pairdraw/core";
3
4
  import { ViewportTransform } from "@pairdraw/core/geometry";
5
+ import { Vector } from "@pairdraw/scene-graph/primitives";
4
6
  //#region src/canvas/surface/types.d.ts
5
7
  /**
6
8
  * Options for {@link useCanvas}.
@@ -69,6 +71,13 @@ interface UseCanvasOptions {
69
71
  * presentation shows only its slide. Null draws every layer of the page.
70
72
  */
71
73
  getSceneScope?: () => string | null;
74
+ /**
75
+ * The top-level frames a playing prototype changed, which this canvas draws from their play
76
+ * scenes instead of the document, by frame id. Null or absent draws the document.
77
+ */
78
+ getPlayScenes?: () => ReadonlyMap<string, RenderedPlayScene> | null;
79
+ /** How far a playing prototype scrolled each frame's content, by frame id. */
80
+ getPlayScroll?: () => ReadonlyMap<string, Vector> | null;
72
81
  /**
73
82
  * Called after each frame this canvas draws, with the pan and zoom it was drawn at. DOM laid
74
83
  * over the canvas, such as preview islands, follows these to stay in step with the drawing
@@ -1 +1 @@
1
- {"version":3,"file":"types.d.ts","names":[],"sources":["../../../src/canvas/surface/types.ts"],"mappings":";;;;;;;KAQY;UAEK;EACf;EACA,eAAe;IAAY;IAAuB;;;;;EAIlD,QAAQ;;;;EAIR;;;;;EAKA;;;;;EAKA;;;;;;EAMA;;;;;;;EAOA;;;;EAIA;;;;;EAKA,YAAY;;;;;EAKZ,kBAAkB,YAAY;;;;;;;EAO9B,uBAAuB;;;;;EAKvB;;;;;;EAMA,WAAW,MAAM;;;;EAIjB,oBAAoB,eAAe;;;;;;EAMnC;;;;;EAKA,qBAAqB,gBAAgB"}
1
+ {"version":3,"file":"types.d.ts","names":[],"sources":["../../../src/canvas/surface/types.ts"],"mappings":";;;;;;;;;KAUY;UAEK;EACf;EACA,eAAe;IAAY;IAAuB;;;;;EAIlD,QAAQ;;;;EAIR;;;;;EAKA;;;;;EAKA;;;;;;EAMA;;;;;;;EAOA;;;;EAIA;;;;;EAKA,YAAY;;;;;EAKZ,kBAAkB,YAAY;;;;;;;EAO9B,uBAAuB;;;;;EAKvB;;;;;EAKA,sBAAsB,oBAAoB;;EAE1C,sBAAsB,oBAAoB;;;;;;EAM1C,WAAW,MAAM;;;;EAIjB,oBAAoB,eAAe;;;;;;EAMnC;;;;;EAKA,qBAAqB,gBAAgB"}
@@ -1,3 +1,4 @@
1
+ import { ShallowRef } from "vue";
1
2
  import { Editor } from "@pairdraw/core";
2
3
  //#region src/canvas/text-edit/textarea.d.ts
3
4
  /**
@@ -1 +1 @@
1
- {"version":3,"file":"textarea.d.ts","names":[],"sources":["../../../src/canvas/text-edit/textarea.ts"],"mappings":";;;;;;;iBAYgB,kBAAkB,SAAS"}
1
+ {"version":3,"file":"textarea.d.ts","names":[],"sources":["../../../src/canvas/text-edit/textarea.ts"],"mappings":";;;;;;;;iBAYgB,kBAAkB,SAAS"}
@@ -3,6 +3,7 @@ import { HAND_GRAB_CURSOR } from "../../editor/tool-cursor/index.js";
3
3
  import { startPenInput, updatePenHover } from "../pen/input.js";
4
4
  import { attachModifiers, startConnectorDraw } from "../../shared/input/connector/draw.js";
5
5
  import { startShapeDraw, startTextDraw } from "../../shared/input/draw.js";
6
+ import { handleEyedropperDown } from "../eyedropper/index.js";
6
7
  import { onSelectionHandle, scaleHoverCursor, tryStartScaleDrag } from "../scale/input.js";
7
8
  import { startZoomDrag, zoomToolCursor } from "../zoom/input.js";
8
9
  import { startPanDrag } from "../../shared/input/pan/drag.js";
@@ -17,7 +18,7 @@ const pan = { press: ({ event }, { editor, setDrag, cursorOverride }) => {
17
18
  const shape = { press: ({ cx, cy }, { editor, setDrag }) => startShapeDraw(cx, cy, editor, setDrag) };
18
19
  /** Selects, moves, resizes, and turns layers: the Move tool. */
19
20
  const select = {
20
- press: ({ event, cx, cy, sx, sy }, context) => handleSelectDown(event, cx, cy, sx, sy, context.editor, context.hitFns, context.tryStartRotation, context.handleTextEditClick, context.setDrag),
21
+ press: ({ event, cx, cy, sx, sy }, context) => handleSelectDown(event, cx, cy, sx, sy, context.editor, context.hitFns, context.tryStartRotation, context.handleTextEditClick, context.setDrag, context.bigNudge()),
21
22
  hover: (pointer, { hoverLayers }) => hoverLayers(pointer)
22
23
  };
23
24
  /**
@@ -53,6 +54,9 @@ const CANVAS_TOOLS = {
53
54
  },
54
55
  HAND: pan,
55
56
  COMMENT: { press: () => void 0 },
57
+ EYEDROPPER: { press: ({ event, cx, cy }, { editor }) => {
58
+ if (event.button === 0) handleEyedropperDown(editor, cx, cy, event.altKey);
59
+ } },
56
60
  PEN: {
57
61
  press: ({ event, cx, cy }, { editor, setDrag, cursorOverride }) => startPenInput(event, cx, cy, editor, setDrag, cursorOverride),
58
62
  hover: ({ cx, cy }, { editor }) => {