@pairdraw/vue 0.18.0 → 0.19.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 (228) hide show
  1. package/dist/canvas/CanvasRoot.vue.js +1 -0
  2. package/dist/canvas/CanvasRoot.vue.js.map +1 -1
  3. package/dist/canvas/drop/use.d.ts.map +1 -1
  4. package/dist/canvas/drop/use.js +5 -3
  5. package/dist/canvas/drop/use.js.map +1 -1
  6. package/dist/canvas/guides/input.js +2 -1
  7. package/dist/canvas/guides/input.js.map +1 -1
  8. package/dist/canvas/pen/input.js +20 -6
  9. package/dist/canvas/pen/input.js.map +1 -1
  10. package/dist/canvas/surface/gl-surface.js +82 -4
  11. package/dist/canvas/surface/gl-surface.js.map +1 -1
  12. package/dist/canvas/surface/lifecycle.js +5 -0
  13. package/dist/canvas/surface/lifecycle.js.map +1 -1
  14. package/dist/canvas/surface/resize-observer.js +11 -4
  15. package/dist/canvas/surface/resize-observer.js.map +1 -1
  16. package/dist/canvas/surface/types.d.ts +5 -0
  17. package/dist/canvas/surface/types.d.ts.map +1 -1
  18. package/dist/canvas/surface/use.d.ts +1 -0
  19. package/dist/canvas/surface/use.js +1 -0
  20. package/dist/canvas/surface/use.js.map +1 -1
  21. package/dist/canvas/text-edit/editing.js +11 -8
  22. package/dist/canvas/text-edit/editing.js.map +1 -1
  23. package/dist/canvas/text-edit/keyboard.js +12 -0
  24. package/dist/canvas/text-edit/keyboard.js.map +1 -1
  25. package/dist/canvas/useCanvasInput.d.ts +240 -0
  26. package/dist/controls/appearance/use.d.ts +1 -1
  27. package/dist/controls/layout/helpers.d.ts.map +1 -1
  28. package/dist/controls/layout/helpers.js +36 -7
  29. package/dist/controls/layout/helpers.js.map +1 -1
  30. package/dist/controls/layout/use.d.ts +1 -0
  31. package/dist/controls/layout/use.d.ts.map +1 -1
  32. package/dist/controls/layout/use.js +3 -0
  33. package/dist/controls/layout/use.js.map +1 -1
  34. package/dist/controls/node-preview/use.js +21 -1
  35. package/dist/controls/node-preview/use.js.map +1 -1
  36. package/dist/controls/position/use.d.ts +2 -1
  37. package/dist/controls/position/use.d.ts.map +1 -1
  38. package/dist/controls/position/use.js +13 -5
  39. package/dist/controls/position/use.js.map +1 -1
  40. package/dist/controls/property-list/use.d.ts.map +1 -1
  41. package/dist/controls/property-list/use.js +27 -5
  42. package/dist/controls/property-list/use.js.map +1 -1
  43. package/dist/controls/selection-layout/use.d.ts.map +1 -1
  44. package/dist/controls/selection-layout/use.js +2 -1
  45. package/dist/controls/selection-layout/use.js.map +1 -1
  46. package/dist/controls/slots/authoring.d.ts.map +1 -1
  47. package/dist/controls/slots/authoring.js +2 -1
  48. package/dist/controls/slots/authoring.js.map +1 -1
  49. package/dist/controls/typography/actions.js +18 -10
  50. package/dist/controls/typography/actions.js.map +1 -1
  51. package/dist/controls/typography/axes.d.ts.map +1 -1
  52. package/dist/controls/typography/axes.js +62 -19
  53. package/dist/controls/typography/axes.js.map +1 -1
  54. package/dist/editor/commands/registry.d.ts +1 -0
  55. package/dist/editor/commands/registry.d.ts.map +1 -1
  56. package/dist/editor/commands/registry.js +1 -0
  57. package/dist/editor/commands/registry.js.map +1 -1
  58. package/dist/editor/commands/selection.js +12 -3
  59. package/dist/editor/commands/selection.js.map +1 -1
  60. package/dist/editor/commands/types.d.ts +1 -1
  61. package/dist/editor/commands/types.d.ts.map +1 -1
  62. package/dist/editor/menu-model/canvas.js +5 -1
  63. package/dist/editor/menu-model/canvas.js.map +1 -1
  64. package/dist/editor/selection-capabilities/use.d.ts +1 -0
  65. package/dist/editor/selection-capabilities/use.js +4 -0
  66. package/dist/editor/selection-capabilities/use.js.map +1 -1
  67. package/dist/editor/selection-state/nodes.js +2 -2
  68. package/dist/editor/selection-state/nodes.js.map +1 -1
  69. package/dist/i18n/locale.d.ts.map +1 -1
  70. package/dist/i18n/locale.js +16 -6
  71. package/dist/i18n/locale.js.map +1 -1
  72. package/dist/i18n/locales/de/ai.json.js +3 -0
  73. package/dist/i18n/locales/de/cloud/portal.json.js +1 -1
  74. package/dist/i18n/locales/de/commands.json.js +1 -0
  75. package/dist/i18n/locales/de/comments.json.js +1 -0
  76. package/dist/i18n/locales/de/editor.json.js +2 -2
  77. package/dist/i18n/locales/de/menu.json.js +1 -1
  78. package/dist/i18n/locales/de/variables/panel.json.js +2 -0
  79. package/dist/i18n/locales/es/ai.json.js +3 -0
  80. package/dist/i18n/locales/es/cloud/portal.json.js +1 -1
  81. package/dist/i18n/locales/es/commands.json.js +1 -0
  82. package/dist/i18n/locales/es/comments.json.js +1 -0
  83. package/dist/i18n/locales/es/editor.json.js +2 -2
  84. package/dist/i18n/locales/es/menu.json.js +1 -1
  85. package/dist/i18n/locales/es/variables/panel.json.js +2 -0
  86. package/dist/i18n/locales/fr/ai.json.js +3 -0
  87. package/dist/i18n/locales/fr/cloud/portal.json.js +1 -1
  88. package/dist/i18n/locales/fr/commands.json.js +1 -0
  89. package/dist/i18n/locales/fr/comments.json.js +1 -0
  90. package/dist/i18n/locales/fr/editor.json.js +2 -2
  91. package/dist/i18n/locales/fr/menu.json.js +1 -1
  92. package/dist/i18n/locales/fr/variables/panel.json.js +2 -0
  93. package/dist/i18n/locales/it/ai.json.js +3 -0
  94. package/dist/i18n/locales/it/cloud/portal.json.js +1 -1
  95. package/dist/i18n/locales/it/commands.json.js +1 -0
  96. package/dist/i18n/locales/it/comments.json.js +1 -0
  97. package/dist/i18n/locales/it/editor.json.js +2 -2
  98. package/dist/i18n/locales/it/menu.json.js +1 -1
  99. package/dist/i18n/locales/it/variables/panel.json.js +2 -0
  100. package/dist/i18n/locales/ja/ai.json.js +3 -0
  101. package/dist/i18n/locales/ja/cloud/portal.json.js +1 -1
  102. package/dist/i18n/locales/ja/commands.json.js +1 -0
  103. package/dist/i18n/locales/ja/comments.json.js +1 -0
  104. package/dist/i18n/locales/ja/editor.json.js +2 -2
  105. package/dist/i18n/locales/ja/menu.json.js +1 -1
  106. package/dist/i18n/locales/ja/variables/panel.json.js +2 -0
  107. package/dist/i18n/locales/pl/ai.json.js +3 -0
  108. package/dist/i18n/locales/pl/cloud/portal.json.js +1 -1
  109. package/dist/i18n/locales/pl/commands.json.js +1 -0
  110. package/dist/i18n/locales/pl/comments.json.js +1 -0
  111. package/dist/i18n/locales/pl/editor.json.js +2 -2
  112. package/dist/i18n/locales/pl/menu.json.js +1 -1
  113. package/dist/i18n/locales/pl/variables/panel.json.js +2 -0
  114. package/dist/i18n/locales/ru/ai.json.js +3 -0
  115. package/dist/i18n/locales/ru/cloud/portal.json.js +1 -1
  116. package/dist/i18n/locales/ru/commands.json.js +1 -0
  117. package/dist/i18n/locales/ru/comments.json.js +1 -0
  118. package/dist/i18n/locales/ru/editor.json.js +2 -2
  119. package/dist/i18n/locales/ru/menu.json.js +1 -1
  120. package/dist/i18n/locales/ru/variables/panel.json.js +2 -0
  121. package/dist/i18n/locales/zh-cn/ai.json.js +3 -0
  122. package/dist/i18n/locales/zh-cn/cloud/portal.json.js +1 -1
  123. package/dist/i18n/locales/zh-cn/commands.json.js +1 -0
  124. package/dist/i18n/locales/zh-cn/comments.json.js +1 -0
  125. package/dist/i18n/locales/zh-cn/editor.json.js +2 -2
  126. package/dist/i18n/locales/zh-cn/menu.json.js +1 -1
  127. package/dist/i18n/locales/zh-cn/variables/panel.json.js +2 -0
  128. package/dist/i18n/messages/ai.d.ts +6 -0
  129. package/dist/i18n/messages/ai.d.ts.map +1 -1
  130. package/dist/i18n/messages/ai.js +4 -0
  131. package/dist/i18n/messages/ai.js.map +1 -1
  132. package/dist/i18n/messages/cloud/portal.d.ts +1 -1
  133. package/dist/i18n/messages/cloud/portal.js +1 -1
  134. package/dist/i18n/messages/cloud/portal.js.map +1 -1
  135. package/dist/i18n/messages/commands.d.ts +1 -0
  136. package/dist/i18n/messages/commands.d.ts.map +1 -1
  137. package/dist/i18n/messages/commands.js +1 -0
  138. package/dist/i18n/messages/commands.js.map +1 -1
  139. package/dist/i18n/messages/comments.d.ts +1 -0
  140. package/dist/i18n/messages/comments.d.ts.map +1 -1
  141. package/dist/i18n/messages/comments.js +1 -0
  142. package/dist/i18n/messages/comments.js.map +1 -1
  143. package/dist/i18n/messages/editor.d.ts +1 -1
  144. package/dist/i18n/messages/editor.js +1 -1
  145. package/dist/i18n/messages/editor.js.map +1 -1
  146. package/dist/i18n/messages/menu.d.ts +1 -1
  147. package/dist/i18n/messages/menu.js +1 -1
  148. package/dist/i18n/messages/menu.js.map +1 -1
  149. package/dist/i18n/messages/panels.d.ts +1 -1
  150. package/dist/i18n/messages/panels.js +1 -1
  151. package/dist/i18n/messages/panels.js.map +1 -1
  152. package/dist/i18n/messages/variables/panel.d.ts +2 -0
  153. package/dist/i18n/messages/variables/panel.d.ts.map +1 -1
  154. package/dist/i18n/messages/variables/panel.js +2 -0
  155. package/dist/i18n/messages/variables/panel.js.map +1 -1
  156. package/dist/i18n/messages.d.ts +13 -4
  157. package/dist/i18n/useI18n.d.ts +48 -14
  158. package/dist/i18n/useI18n.d.ts.map +1 -1
  159. package/dist/primitives/ColorPicker/ColorPickerRoot.vue.d.ts +12 -2
  160. package/dist/primitives/ColorPicker/ColorPickerRoot.vue.d.ts.map +1 -1
  161. package/dist/primitives/ColorPicker/ColorPickerRoot.vue.js +39 -10
  162. package/dist/primitives/ColorPicker/ColorPickerRoot.vue.js.map +1 -1
  163. package/dist/primitives/ColorPicker/gesture.d.ts +40 -0
  164. package/dist/primitives/ColorPicker/gesture.d.ts.map +1 -0
  165. package/dist/primitives/ColorPicker/gesture.js +120 -0
  166. package/dist/primitives/ColorPicker/gesture.js.map +1 -0
  167. package/dist/primitives/ColorPicker/index.d.ts +2 -1
  168. package/dist/primitives/ColorPicker/index.js +2 -1
  169. package/dist/primitives/Fill/FillSwatch.vue.d.ts.map +1 -1
  170. package/dist/primitives/Fill/FillSwatch.vue.js +6 -1
  171. package/dist/primitives/Fill/FillSwatch.vue.js.map +1 -1
  172. package/dist/primitives/Fill/types.d.ts +5 -0
  173. package/dist/primitives/Fill/types.d.ts.map +1 -1
  174. package/dist/primitives/Fill/useFill.d.ts.map +1 -1
  175. package/dist/primitives/Fill/useFill.js +15 -7
  176. package/dist/primitives/Fill/useFill.js.map +1 -1
  177. package/dist/primitives/FontPicker/FontPickerRoot.vue.d.ts +1 -0
  178. package/dist/primitives/FontPicker/FontPickerRoot.vue.d.ts.map +1 -1
  179. package/dist/primitives/FontPicker/FontPickerRoot.vue.js +7 -2
  180. package/dist/primitives/FontPicker/FontPickerRoot.vue.js.map +1 -1
  181. package/dist/primitives/LayerTree/LayerTreeRoot.vue.d.ts +2 -0
  182. package/dist/primitives/LayerTree/LayerTreeRoot.vue.d.ts.map +1 -1
  183. package/dist/primitives/LayerTree/LayerTreeRoot.vue.js +14 -3
  184. package/dist/primitives/LayerTree/LayerTreeRoot.vue.js.map +1 -1
  185. package/dist/primitives/LayerTree/model.js +1 -1
  186. package/dist/primitives/LayoutControls/LayoutControlsRoot.vue.d.ts.map +1 -1
  187. package/dist/primitives/LayoutControls/LayoutControlsRoot.vue.js +1 -0
  188. package/dist/primitives/LayoutControls/LayoutControlsRoot.vue.js.map +1 -1
  189. package/dist/primitives/NumberField/NumberFieldRoot.vue.d.ts +2 -2
  190. package/dist/primitives/NumberField/NumberFieldRoot.vue.d.ts.map +1 -1
  191. package/dist/primitives/NumberField/NumberFieldRoot.vue.js +3 -2
  192. package/dist/primitives/NumberField/NumberFieldRoot.vue.js.map +1 -1
  193. package/dist/primitives/NumberField/types.d.ts +5 -0
  194. package/dist/primitives/NumberField/types.d.ts.map +1 -1
  195. package/dist/primitives/PageList/PageListRoot.vue.d.ts +3 -3
  196. package/dist/primitives/PageList/PageListRoot.vue.d.ts.map +1 -1
  197. package/dist/primitives/PageList/PageListRoot.vue.js +3 -2
  198. package/dist/primitives/PageList/PageListRoot.vue.js.map +1 -1
  199. package/dist/primitives/PageList/usePageList.d.ts +1 -1
  200. package/dist/primitives/PageList/usePageList.d.ts.map +1 -1
  201. package/dist/primitives/PositionControls/PositionControlsRoot.vue.d.ts +1 -0
  202. package/dist/primitives/PositionControls/PositionControlsRoot.vue.d.ts.map +1 -1
  203. package/dist/primitives/PositionControls/PositionControlsRoot.vue.js +11 -13
  204. package/dist/primitives/PositionControls/PositionControlsRoot.vue.js.map +1 -1
  205. package/dist/primitives/PropertyList/PropertyListRoot.vue.d.ts.map +1 -1
  206. package/dist/primitives/PropertyList/PropertyListRoot.vue.js +10 -1
  207. package/dist/primitives/PropertyList/PropertyListRoot.vue.js.map +1 -1
  208. package/dist/primitives/PropertyList/index.d.ts +2 -2
  209. package/dist/primitives/PropertyList/types.d.ts +14 -2
  210. package/dist/primitives/PropertyList/types.d.ts.map +1 -1
  211. package/dist/shared/input/drop-target.js +2 -1
  212. package/dist/shared/input/drop-target.js.map +1 -1
  213. package/dist/shared/input/duplicate-drag.js.map +1 -1
  214. package/dist/shared/input/move/drag.js +25 -4
  215. package/dist/shared/input/move/drag.js.map +1 -1
  216. package/dist/shared/input/resize/start.js +2 -1
  217. package/dist/shared/input/resize/start.js.map +1 -1
  218. package/dist/shared/input/select/move.js +8 -3
  219. package/dist/shared/input/select/move.js.map +1 -1
  220. package/dist/shared/input/select.js +22 -12
  221. package/dist/shared/input/select.js.map +1 -1
  222. package/dist/shared/input/types.d.ts +2 -0
  223. package/dist/shared/input/types.d.ts.map +1 -1
  224. package/dist/shared/input/types.js.map +1 -1
  225. package/dist/variables/use.d.ts.map +1 -1
  226. package/dist/variables/use.js +2 -1
  227. package/dist/variables/use.js.map +1 -1
  228. package/package.json +4 -4
@@ -2,6 +2,7 @@ import { useSelectedNodeState } from "../../editor/selection-state/nodes.js";
2
2
  import { useNodePreview } from "../node-preview/use.js";
3
3
  import { computed, ref } from "vue";
4
4
  import { aspectRatioLockEditable, enforcedAspectRatio, layoutSizing, layoutSizingOptions, layoutSizingUpdates, lockedAspectRatioTarget, sizeKeepingAspectRatio } from "@pairdraw/scene-graph/layout";
5
+ import { collectResizeDescendants, computeConstrainedResizeChanges } from "@pairdraw/scene-graph/resize";
5
6
  //#region src/controls/layout/helpers.ts
6
7
  const ALIGN_HORIZONTAL = [
7
8
  {
@@ -232,24 +233,52 @@ function createLayoutActions({ editor, node }) {
232
233
  function fixedAxisPatch(n, axis) {
233
234
  return axisSizingForNode(editor.graph, n, axis) === "FIXED" ? {} : axisSizingPatchForNode(editor.graph, n, axis, "FIXED");
234
235
  }
236
+ /**
237
+ * What the size edit running in the preview started from. A size typed in the panel places the
238
+ * layers inside by their constraints, as a corner drag does in Figma, instead of leaving them
239
+ * pinned to their old offsets; every keystroke and scrub step of one edit previews the same
240
+ * frame, so a later value measures from where the edit began instead of from the size the
241
+ * previous keystroke already gave.
242
+ */
243
+ let sizeEditStart;
244
+ function startOfSizeEdit(n) {
245
+ if (!preview.isActive() || sizeEditStart?.nodeId !== n.id) sizeEditStart = {
246
+ nodeId: n.id,
247
+ size: {
248
+ width: n.width,
249
+ height: n.height
250
+ },
251
+ originals: collectResizeDescendants(editor.graph, n.id) ?? /* @__PURE__ */ new Map()
252
+ };
253
+ return sizeEditStart;
254
+ }
255
+ function previewSize(n, size, label, sizing) {
256
+ const start = startOfSizeEdit(n);
257
+ const placed = computeConstrainedResizeChanges(editor.graph, n.id, start.size, size, start.originals);
258
+ preview.update([n.id], {
259
+ ...sizing,
260
+ ...size
261
+ }, label);
262
+ preview.updateNodes(placed, label);
263
+ }
235
264
  function updateAxisSize(axis, value) {
236
265
  const n = node.value;
237
266
  if (!n) return;
238
267
  const ratio = enforcedAspectRatio(n);
239
268
  if (ratio === null) {
240
- preview.update([n.id], {
241
- ...fixedAxisPatch(n, axis),
269
+ previewSize(n, {
270
+ width: n.width,
271
+ height: n.height,
242
272
  [axis]: value
243
- }, `Change ${axis}`);
273
+ }, `Change ${axis}`, fixedAxisPatch(n, axis));
244
274
  return;
245
275
  }
246
276
  const size = sizeKeepingAspectRatio(ratio, axis, value);
247
- const patch = {
277
+ const sizing = {
248
278
  ...fixedAxisPatch(n, "width"),
249
- ...fixedAxisPatch(n, "height"),
250
- ...size
279
+ ...fixedAxisPatch(n, "height")
251
280
  };
252
- preview.update([n.id], patch, `Change ${axis}`);
281
+ previewSize(n, size, `Change ${axis}`, sizing);
253
282
  }
254
283
  function toggleAspectRatioLock() {
255
284
  const n = node.value;
@@ -1 +1 @@
1
- {"version":3,"file":"helpers.js","names":[],"sources":["../../../src/controls/layout/helpers.ts"],"sourcesContent":["import { computed, ref } from 'vue'\nimport type { ComputedRef } from 'vue'\n\nimport type { Editor } from '@pairdraw/core'\nimport type {\n GridTrack,\n LayoutAlign,\n LayoutCounterAlign,\n LayoutSizing,\n NumericNodeProperty,\n SceneGraph,\n SceneNode\n} from '@pairdraw/scene-graph'\nimport {\n aspectRatioLockEditable,\n enforcedAspectRatio,\n layoutSizing,\n layoutSizingOptions,\n layoutSizingUpdates,\n lockedAspectRatioTarget,\n sizeKeepingAspectRatio,\n type LayoutSizingAxis\n} from '@pairdraw/scene-graph/layout'\n\nimport { useNodePreview } from '#vue/controls/node-preview/use'\nimport { useSelectedNodeState } from '#vue/editor/selection-state/nodes'\nimport type { useI18n } from '#vue/i18n'\n\ntype AlignCell = { primary: LayoutAlign; counter: LayoutCounterAlign }\n\ntype GridTrackProp = 'gridTemplateColumns' | 'gridTemplateRows'\n\ntype LayoutPanelStrings = {\n sizingFixed: string\n sizingHug: string\n sizingFill: string\n}\n\nexport type LayoutAxis = 'width' | 'height'\nexport type SizeLimitProp = 'minWidth' | 'maxWidth' | 'minHeight' | 'maxHeight'\n\ntype ValueRef<T> = { readonly value: T }\n\nconst ALIGN_HORIZONTAL: AlignCell[] = [\n { primary: 'MIN', counter: 'MIN' },\n { primary: 'CENTER', counter: 'MIN' },\n { primary: 'MAX', counter: 'MIN' },\n { primary: 'MIN', counter: 'CENTER' },\n { primary: 'CENTER', counter: 'CENTER' },\n { primary: 'MAX', counter: 'CENTER' },\n { primary: 'MIN', counter: 'MAX' },\n { primary: 'CENTER', counter: 'MAX' },\n { primary: 'MAX', counter: 'MAX' }\n]\n\nconst ALIGN_VERTICAL: AlignCell[] = [\n { primary: 'MIN', counter: 'MIN' },\n { primary: 'MIN', counter: 'CENTER' },\n { primary: 'MIN', counter: 'MAX' },\n { primary: 'CENTER', counter: 'MIN' },\n { primary: 'CENTER', counter: 'CENTER' },\n { primary: 'CENTER', counter: 'MAX' },\n { primary: 'MAX', counter: 'MIN' },\n { primary: 'MAX', counter: 'CENTER' },\n { primary: 'MAX', counter: 'MAX' }\n]\n\nexport function createLayoutSelectionState(\n editor: Editor,\n panels: ReturnType<typeof useI18n>['panels']\n) {\n const { node } = useSelectedNodeState(editor)\n const layoutDirection = computed<SceneNode['layoutDirection']>(\n () => node.value?.layoutDirection ?? 'AUTO'\n )\n const sizingState = createLayoutSizingState(editor, node, panels)\n const gapAuto = computed(() => node.value?.primaryAxisAlign === 'SPACE_BETWEEN')\n const alignGrid = computed(() =>\n node.value?.layoutMode === 'VERTICAL' ? ALIGN_VERTICAL : ALIGN_HORIZONTAL\n )\n\n return { node, layoutDirection, gapAuto, alignGrid, ...sizingState }\n}\n\nexport function createTrackSizingOptions(panels: ReturnType<typeof useI18n>['panels']['value']) {\n return [\n { value: 'FR' as const, label: panels.sizingFillFr },\n { value: 'FIXED' as const, label: panels.sizingFixedPx },\n { value: 'AUTO' as const, label: panels.auto }\n ]\n}\n\nexport function trackLabel(track: GridTrack): string {\n if (track.sizing === 'FR') return `${track.value}fr`\n if (track.sizing === 'FIXED') return `${track.value}px`\n return 'Auto'\n}\n\nexport function createGridTrackActions(editor: Editor, node: ComputedRef<SceneNode | null>) {\n function updateGridTrack(prop: GridTrackProp, index: number, updates: Partial<GridTrack>) {\n if (!node.value) return\n const tracks = [...node.value[prop]]\n tracks[index] = { ...tracks[index], ...updates }\n editor.updateNodeWithUndo(node.value.id, { [prop]: tracks }, 'Change grid track')\n }\n\n function addTrack(prop: GridTrackProp) {\n if (!node.value) return\n editor.updateNodeWithUndo(\n node.value.id,\n { [prop]: [...node.value[prop], { sizing: 'FR' as const, value: 1 }] },\n 'Add grid track'\n )\n }\n\n function removeTrack(prop: GridTrackProp, index: number) {\n if (!node.value) return\n editor.updateNodeWithUndo(\n node.value.id,\n { [prop]: node.value[prop].filter((_: GridTrack, i: number) => i !== index) },\n 'Remove grid track'\n )\n }\n\n return { updateGridTrack, addTrack, removeTrack }\n}\n\nexport function createPaddingActions(editor: Editor, node: ComputedRef<SceneNode | null>) {\n const showIndividualPadding = ref(false)\n const preview = useNodePreview(editor)\n\n const hasUniformPadding = computed(() => {\n const n = node.value\n if (!n) return true\n return (\n n.paddingTop === n.paddingRight &&\n n.paddingRight === n.paddingBottom &&\n n.paddingBottom === n.paddingLeft\n )\n })\n\n const hasSymmetricPadding = computed(() => {\n const n = node.value\n if (!n) return true\n return n.paddingLeft === n.paddingRight && n.paddingTop === n.paddingBottom\n })\n\n function setHorizontalPadding(v: number) {\n if (!node.value) return\n preview.update(\n [node.value.id],\n { paddingLeft: v, paddingRight: v },\n 'Change horizontal padding'\n )\n }\n\n function commitHorizontalPadding(_value: number, _previous: number) {\n preview.commit()\n }\n\n function setVerticalPadding(v: number) {\n if (!node.value) return\n preview.update([node.value.id], { paddingTop: v, paddingBottom: v }, 'Change vertical padding')\n }\n\n function commitVerticalPadding(_value: number, _previous: number) {\n preview.commit()\n }\n\n function toggleIndividualPadding() {\n showIndividualPadding.value = !showIndividualPadding.value\n }\n\n return {\n cancelPaddingPreview: preview.cancel,\n showIndividualPadding,\n hasUniformPadding,\n hasSymmetricPadding,\n setHorizontalPadding,\n commitHorizontalPadding,\n setVerticalPadding,\n commitVerticalPadding,\n toggleIndividualPadding\n }\n}\n\nfunction sizingAxis(axis: LayoutAxis): LayoutSizingAxis {\n return axis === 'width' ? 'HORIZONTAL' : 'VERTICAL'\n}\n\nexport function axisSizingPatchForNode(\n graph: SceneGraph,\n node: SceneNode,\n axis: LayoutAxis,\n sizing: LayoutSizing\n): Partial<SceneNode> {\n return layoutSizingUpdates(graph, node, sizingAxis(axis), sizing)\n}\n\nexport function createLayoutActions({\n editor,\n node\n}: {\n editor: Editor\n node: ComputedRef<SceneNode | null>\n}) {\n const preview = useNodePreview(editor)\n\n function updateProp(key: NumericNodeProperty, value: number) {\n if (node.value) preview.update([node.value.id], { [key]: value }, `Change ${key}`)\n }\n\n function updateSizeLimit(prop: SizeLimitProp, value: number) {\n if (!node.value) return\n preview.update([node.value.id], { [prop]: value }, `Change ${prop}`)\n }\n\n function setSizeLimitToCurrent(prop: SizeLimitProp) {\n const n = node.value\n if (!n) return\n const value = prop === 'minWidth' || prop === 'maxWidth' ? n.width : n.height\n editor.updateNodeWithUndo(n.id, { [prop]: Math.round(value) }, `Set ${prop}`)\n }\n\n function commitSizeLimit(_prop: SizeLimitProp, _value: number, _previous: number) {\n preview.commit()\n }\n\n function addSizeLimit(prop: SizeLimitProp) {\n const n = node.value\n if (!n) return\n const fallback = prop === 'minWidth' || prop === 'maxWidth' ? n.width : n.height\n editor.updateNodeWithUndo(n.id, { [prop]: Math.round(fallback) }, `Add ${prop}`)\n }\n\n function removeSizeLimit(prop: SizeLimitProp) {\n if (!node.value) return\n editor.updateNodeWithUndo(node.value.id, { [prop]: null }, `Remove ${prop}`)\n }\n\n function commitProp(_key: NumericNodeProperty, _value: number, _previous: number) {\n preview.commit()\n }\n\n function setAxisSizing(axis: LayoutAxis, sizing: LayoutSizing) {\n const n = node.value\n if (!n) return\n editor.updateNodeWithUndo(\n n.id,\n axisSizingPatchForNode(editor.graph, n, axis, sizing),\n `Set ${axis} sizing`\n )\n }\n\n function fixedAxisPatch(n: SceneNode, axis: LayoutAxis): Partial<SceneNode> {\n return axisSizingForNode(editor.graph, n, axis) === 'FIXED'\n ? {}\n : axisSizingPatchForNode(editor.graph, n, axis, 'FIXED')\n }\n\n // A locked layer keeps its ratio as either side is typed, as in Figma.\n function updateAxisSize(axis: LayoutAxis, value: number) {\n const n = node.value\n if (!n) return\n const ratio = enforcedAspectRatio(n)\n if (ratio === null) {\n preview.update([n.id], { ...fixedAxisPatch(n, axis), [axis]: value }, `Change ${axis}`)\n return\n }\n const size = sizeKeepingAspectRatio(ratio, axis, value)\n const patch = { ...fixedAxisPatch(n, 'width'), ...fixedAxisPatch(n, 'height'), ...size }\n preview.update([n.id], patch, `Change ${axis}`)\n }\n\n function toggleAspectRatioLock() {\n const n = node.value\n if (!n || !aspectRatioLockEditable(editor.graph, n)) return\n const locked = n.targetAspectRatio !== null\n editor.updateNodeWithUndo(\n n.id,\n { targetAspectRatio: locked ? null : lockedAspectRatioTarget(n.width, n.height) },\n 'Toggle aspect ratio lock'\n )\n }\n\n function commitAxisSize(_axis: LayoutAxis, _value: number, _previous: number) {\n preview.commit()\n }\n\n function setAlignment(primary: LayoutAlign, counter: LayoutCounterAlign) {\n if (!node.value) return\n editor.updateNodeWithUndo(\n node.value.id,\n { primaryAxisAlign: primary, counterAxisAlign: counter },\n 'Change alignment'\n )\n }\n\n function setGapAuto(enabled: boolean) {\n const n = node.value\n if (!n) return\n editor.updateNodeWithUndo(\n n.id,\n { primaryAxisAlign: enabled ? 'SPACE_BETWEEN' : 'MIN' },\n enabled ? 'Set gap to auto' : 'Set gap to fixed'\n )\n }\n\n function setLayoutDirection(direction: SceneNode['layoutDirection']) {\n if (!node.value) return\n editor.updateNodeWithUndo(\n node.value.id,\n { layoutDirection: direction },\n 'Change layout direction'\n )\n }\n\n return {\n cancelPreview: preview.cancel,\n updateProp,\n updateSizeLimit,\n setSizeLimitToCurrent,\n commitSizeLimit,\n addSizeLimit,\n removeSizeLimit,\n commitProp,\n setAxisSizing,\n updateAxisSize,\n commitAxisSize,\n toggleAspectRatioLock,\n setAlignment,\n setGapAuto,\n setLayoutDirection\n }\n}\n\nexport function axisSizingForNode(\n graph: SceneGraph,\n node: SceneNode | null,\n axis: LayoutAxis\n): LayoutSizing {\n return node ? layoutSizing(graph, node, sizingAxis(axis)) : 'FIXED'\n}\n\nexport function sizingOptionsForNode(\n graph: SceneGraph,\n node: SceneNode | null,\n labels: Partial<Record<LayoutSizing, string>> = {}\n): { value: LayoutSizing; label: string }[] {\n const allowed = node ? layoutSizingOptions(graph, node) : []\n // A node outside auto-layout still shows its fixed size.\n const values: LayoutSizing[] = allowed.length > 0 ? allowed : ['FIXED']\n const fallback: Record<LayoutSizing, string> = { FIXED: 'Fixed', HUG: 'Hug', FILL: 'Fill' }\n return values.map((value) => ({ value, label: labels[value] ?? fallback[value] }))\n}\n\nfunction createLayoutSizingState(\n editor: Editor,\n node: ComputedRef<SceneNode | null>,\n panels: ValueRef<LayoutPanelStrings>\n) {\n const isInAutoLayout = computed(() => {\n const n = node.value\n if (!n?.parentId) return false\n const parent = editor.getNode(n.parentId)\n return parent ? parent.layoutMode !== 'NONE' : false\n })\n\n const isGrid = computed(() => node.value?.layoutMode === 'GRID')\n const isFlex = computed(\n () => node.value?.layoutMode === 'HORIZONTAL' || node.value?.layoutMode === 'VERTICAL'\n )\n const widthSizing = computed(() => axisSizingForNode(editor.graph, node.value, 'width'))\n const heightSizing = computed(() => axisSizingForNode(editor.graph, node.value, 'height'))\n\n function sizingOptions() {\n return sizingOptionsForNode(editor.graph, node.value, {\n FIXED: panels.value.sizingFixed,\n HUG: panels.value.sizingHug,\n FILL: panels.value.sizingFill\n })\n }\n\n const widthSizingOptions = computed(sizingOptions)\n const heightSizingOptions = computed(sizingOptions)\n const aspectRatioLocked = computed(() => node.value?.targetAspectRatio != null)\n const aspectRatioLockable = computed(() => {\n const n = node.value\n return !!n && aspectRatioLockEditable(editor.graph, n)\n })\n\n return {\n isInAutoLayout,\n aspectRatioLocked,\n aspectRatioLockable,\n isGrid,\n isFlex,\n widthSizing,\n heightSizing,\n widthSizingOptions,\n heightSizingOptions\n }\n}\n"],"mappings":";;;;;AA2CA,MAAM,mBAAgC;CACpC;EAAE,SAAS;EAAO,SAAS;CAAM;CACjC;EAAE,SAAS;EAAU,SAAS;CAAM;CACpC;EAAE,SAAS;EAAO,SAAS;CAAM;CACjC;EAAE,SAAS;EAAO,SAAS;CAAS;CACpC;EAAE,S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EAAE;EAAO,OAAO,OAAO,UAAU,SAAS;CAAO,EAAE;AACnF;AAEA,SAAS,wBACP,QACA,MACA,QACA;CACA,MAAM,iBAAiB,eAAe;EACpC,MAAM,IAAI,KAAK;EACf,IAAI,CAAC,GAAG,UAAU,OAAO;EACzB,MAAM,SAAS,OAAO,QAAQ,EAAE,QAAQ;EACxC,OAAO,SAAS,OAAO,eAAe,SAAS;CACjD,CAAC;CAED,MAAM,SAAS,eAAe,KAAK,OAAO,eAAe,MAAM;CAC/D,MAAM,SAAS,eACP,KAAK,OAAO,eAAe,gBAAgB,KAAK,OAAO,eAAe,UAC9E;CACA,MAAM,cAAc,eAAe,kBAAkB,OAAO,OAAO,KAAK,OAAO,OAAO,CAAC;CACvF,MAAM,eAAe,eAAe,kBAAkB,OAAO,OAAO,KAAK,OAAO,QAAQ,CAAC;CAEzF,SAAS,gBAAgB;EACvB,OAAO,qBAAqB,OAAO,OAAO,KAAK,OAAO;GACpD,OAAO,OAAO,MAAM;GACpB,KAAK,OAAO,MAAM;GAClB,MAAM,OAAO,MAAM;EACrB,CAAC;CACH;CAEA,MAAM,qBAAqB,SAAS,aAAa;CACjD,MAAM,sBAAsB,SAAS,aAAa;CAOlD,OAAO;EACL;EACA,mBARwB,eAAe,KAAK,OAAO,qBAAqB,IAQxD;EAChB,qBAR0B,eAAe;GACzC,MAAM,IAAI,KAAK;GACf,OAAO,CAAC,CAAC,KAAK,wBAAwB,OAAO,OAAO,CAAC;EACvD,CAKoB;EAClB;EACA;EACA;EACA;EACA;EACA;CACF;AACF"}
1
+ {"version":3,"file":"helpers.js","names":[],"sources":["../../../src/controls/layout/helpers.ts"],"sourcesContent":["import { computed, ref } from 'vue'\nimport type { ComputedRef } from 'vue'\n\nimport type { Editor } from '@pairdraw/core'\nimport type {\n GridTrack,\n LayoutAlign,\n LayoutCounterAlign,\n LayoutSizing,\n NumericNodeProperty,\n SceneGraph,\n SceneNode\n} from '@pairdraw/scene-graph'\nimport {\n aspectRatioLockEditable,\n enforcedAspectRatio,\n layoutSizing,\n layoutSizingOptions,\n layoutSizingUpdates,\n lockedAspectRatioTarget,\n sizeKeepingAspectRatio,\n type LayoutSizingAxis\n} from '@pairdraw/scene-graph/layout'\nimport {\n collectResizeDescendants,\n computeConstrainedResizeChanges,\n type ResizeSnapshot\n} from '@pairdraw/scene-graph/resize'\n\nimport { useNodePreview } from '#vue/controls/node-preview/use'\nimport { useSelectedNodeState } from '#vue/editor/selection-state/nodes'\nimport type { useI18n } from '#vue/i18n'\n\ntype AlignCell = { primary: LayoutAlign; counter: LayoutCounterAlign }\n\ntype GridTrackProp = 'gridTemplateColumns' | 'gridTemplateRows'\n\ntype LayoutPanelStrings = {\n sizingFixed: string\n sizingHug: string\n sizingFill: string\n}\n\nexport type LayoutAxis = 'width' | 'height'\nexport type SizeLimitProp = 'minWidth' | 'maxWidth' | 'minHeight' | 'maxHeight'\n\ntype ValueRef<T> = { readonly value: T }\n\nconst ALIGN_HORIZONTAL: AlignCell[] = [\n { primary: 'MIN', counter: 'MIN' },\n { primary: 'CENTER', counter: 'MIN' },\n { primary: 'MAX', counter: 'MIN' },\n { primary: 'MIN', counter: 'CENTER' },\n { primary: 'CENTER', counter: 'CENTER' },\n { primary: 'MAX', counter: 'CENTER' },\n { primary: 'MIN', counter: 'MAX' },\n { primary: 'CENTER', counter: 'MAX' },\n { primary: 'MAX', counter: 'MAX' }\n]\n\nconst ALIGN_VERTICAL: AlignCell[] = [\n { primary: 'MIN', counter: 'MIN' },\n { primary: 'MIN', counter: 'CENTER' },\n { primary: 'MIN', counter: 'MAX' },\n { primary: 'CENTER', counter: 'MIN' },\n { primary: 'CENTER', counter: 'CENTER' },\n { primary: 'CENTER', counter: 'MAX' },\n { primary: 'MAX', counter: 'MIN' },\n { primary: 'MAX', counter: 'CENTER' },\n { primary: 'MAX', counter: 'MAX' }\n]\n\nexport function createLayoutSelectionState(\n editor: Editor,\n panels: ReturnType<typeof useI18n>['panels']\n) {\n const { node } = useSelectedNodeState(editor)\n const layoutDirection = computed<SceneNode['layoutDirection']>(\n () => node.value?.layoutDirection ?? 'AUTO'\n )\n const sizingState = createLayoutSizingState(editor, node, panels)\n const gapAuto = computed(() => node.value?.primaryAxisAlign === 'SPACE_BETWEEN')\n const alignGrid = computed(() =>\n node.value?.layoutMode === 'VERTICAL' ? ALIGN_VERTICAL : ALIGN_HORIZONTAL\n )\n\n return { node, layoutDirection, gapAuto, alignGrid, ...sizingState }\n}\n\nexport function createTrackSizingOptions(panels: ReturnType<typeof useI18n>['panels']['value']) {\n return [\n { value: 'FR' as const, label: panels.sizingFillFr },\n { value: 'FIXED' as const, label: panels.sizingFixedPx },\n { value: 'AUTO' as const, label: panels.auto }\n ]\n}\n\nexport function trackLabel(track: GridTrack): string {\n if (track.sizing === 'FR') return `${track.value}fr`\n if (track.sizing === 'FIXED') return `${track.value}px`\n return 'Auto'\n}\n\nexport function createGridTrackActions(editor: Editor, node: ComputedRef<SceneNode | null>) {\n function updateGridTrack(prop: GridTrackProp, index: number, updates: Partial<GridTrack>) {\n if (!node.value) return\n const tracks = [...node.value[prop]]\n tracks[index] = { ...tracks[index], ...updates }\n editor.updateNodeWithUndo(node.value.id, { [prop]: tracks }, 'Change grid track')\n }\n\n function addTrack(prop: GridTrackProp) {\n if (!node.value) return\n editor.updateNodeWithUndo(\n node.value.id,\n { [prop]: [...node.value[prop], { sizing: 'FR' as const, value: 1 }] },\n 'Add grid track'\n )\n }\n\n function removeTrack(prop: GridTrackProp, index: number) {\n if (!node.value) return\n editor.updateNodeWithUndo(\n node.value.id,\n { [prop]: node.value[prop].filter((_: GridTrack, i: number) => i !== index) },\n 'Remove grid track'\n )\n }\n\n return { updateGridTrack, addTrack, removeTrack }\n}\n\nexport function createPaddingActions(editor: Editor, node: ComputedRef<SceneNode | null>) {\n const showIndividualPadding = ref(false)\n const preview = useNodePreview(editor)\n\n const hasUniformPadding = computed(() => {\n const n = node.value\n if (!n) return true\n return (\n n.paddingTop === n.paddingRight &&\n n.paddingRight === n.paddingBottom &&\n n.paddingBottom === n.paddingLeft\n )\n })\n\n const hasSymmetricPadding = computed(() => {\n const n = node.value\n if (!n) return true\n return n.paddingLeft === n.paddingRight && n.paddingTop === n.paddingBottom\n })\n\n function setHorizontalPadding(v: number) {\n if (!node.value) return\n preview.update(\n [node.value.id],\n { paddingLeft: v, paddingRight: v },\n 'Change horizontal padding'\n )\n }\n\n function commitHorizontalPadding(_value: number, _previous: number) {\n preview.commit()\n }\n\n function setVerticalPadding(v: number) {\n if (!node.value) return\n preview.update([node.value.id], { paddingTop: v, paddingBottom: v }, 'Change vertical padding')\n }\n\n function commitVerticalPadding(_value: number, _previous: number) {\n preview.commit()\n }\n\n function toggleIndividualPadding() {\n showIndividualPadding.value = !showIndividualPadding.value\n }\n\n return {\n cancelPaddingPreview: preview.cancel,\n showIndividualPadding,\n hasUniformPadding,\n hasSymmetricPadding,\n setHorizontalPadding,\n commitHorizontalPadding,\n setVerticalPadding,\n commitVerticalPadding,\n toggleIndividualPadding\n }\n}\n\nfunction sizingAxis(axis: LayoutAxis): LayoutSizingAxis {\n return axis === 'width' ? 'HORIZONTAL' : 'VERTICAL'\n}\n\nexport function axisSizingPatchForNode(\n graph: SceneGraph,\n node: SceneNode,\n axis: LayoutAxis,\n sizing: LayoutSizing\n): Partial<SceneNode> {\n return layoutSizingUpdates(graph, node, sizingAxis(axis), sizing)\n}\n\nexport function createLayoutActions({\n editor,\n node\n}: {\n editor: Editor\n node: ComputedRef<SceneNode | null>\n}) {\n const preview = useNodePreview(editor)\n\n function updateProp(key: NumericNodeProperty, value: number) {\n if (node.value) preview.update([node.value.id], { [key]: value }, `Change ${key}`)\n }\n\n function updateSizeLimit(prop: SizeLimitProp, value: number) {\n if (!node.value) return\n preview.update([node.value.id], { [prop]: value }, `Change ${prop}`)\n }\n\n function setSizeLimitToCurrent(prop: SizeLimitProp) {\n const n = node.value\n if (!n) return\n const value = prop === 'minWidth' || prop === 'maxWidth' ? n.width : n.height\n editor.updateNodeWithUndo(n.id, { [prop]: Math.round(value) }, `Set ${prop}`)\n }\n\n function commitSizeLimit(_prop: SizeLimitProp, _value: number, _previous: number) {\n preview.commit()\n }\n\n function addSizeLimit(prop: SizeLimitProp) {\n const n = node.value\n if (!n) return\n const fallback = prop === 'minWidth' || prop === 'maxWidth' ? n.width : n.height\n editor.updateNodeWithUndo(n.id, { [prop]: Math.round(fallback) }, `Add ${prop}`)\n }\n\n function removeSizeLimit(prop: SizeLimitProp) {\n if (!node.value) return\n editor.updateNodeWithUndo(node.value.id, { [prop]: null }, `Remove ${prop}`)\n }\n\n function commitProp(_key: NumericNodeProperty, _value: number, _previous: number) {\n preview.commit()\n }\n\n function setAxisSizing(axis: LayoutAxis, sizing: LayoutSizing) {\n const n = node.value\n if (!n) return\n editor.updateNodeWithUndo(\n n.id,\n axisSizingPatchForNode(editor.graph, n, axis, sizing),\n `Set ${axis} sizing`\n )\n }\n\n function fixedAxisPatch(n: SceneNode, axis: LayoutAxis): Partial<SceneNode> {\n return axisSizingForNode(editor.graph, n, axis) === 'FIXED'\n ? {}\n : axisSizingPatchForNode(editor.graph, n, axis, 'FIXED')\n }\n\n /**\n * What the size edit running in the preview started from. A size typed in the panel places the\n * layers inside by their constraints, as a corner drag does in Figma, instead of leaving them\n * pinned to their old offsets; every keystroke and scrub step of one edit previews the same\n * frame, so a later value measures from where the edit began instead of from the size the\n * previous keystroke already gave.\n */\n let sizeEditStart:\n | {\n nodeId: string\n size: { width: number; height: number }\n originals: ReadonlyMap<string, ResizeSnapshot>\n }\n | undefined\n\n function startOfSizeEdit(n: SceneNode) {\n if (!preview.isActive() || sizeEditStart?.nodeId !== n.id) {\n sizeEditStart = {\n nodeId: n.id,\n size: { width: n.width, height: n.height },\n originals: collectResizeDescendants(editor.graph, n.id) ?? new Map()\n }\n }\n return sizeEditStart\n }\n\n function previewSize(\n n: SceneNode,\n size: { width: number; height: number },\n label: string,\n sizing: Partial<SceneNode>\n ) {\n const start = startOfSizeEdit(n)\n const placed = computeConstrainedResizeChanges(\n editor.graph,\n n.id,\n start.size,\n size,\n start.originals\n )\n preview.update([n.id], { ...sizing, ...size }, label)\n preview.updateNodes(placed, label)\n }\n\n // A locked layer keeps its ratio as either side is typed, as in Figma.\n function updateAxisSize(axis: LayoutAxis, value: number) {\n const n = node.value\n if (!n) return\n const ratio = enforcedAspectRatio(n)\n if (ratio === null) {\n previewSize(\n n,\n { width: n.width, height: n.height, [axis]: value },\n `Change ${axis}`,\n fixedAxisPatch(n, axis)\n )\n return\n }\n const size = sizeKeepingAspectRatio(ratio, axis, value)\n const sizing = { ...fixedAxisPatch(n, 'width'), ...fixedAxisPatch(n, 'height') }\n previewSize(n, size, `Change ${axis}`, sizing)\n }\n\n function toggleAspectRatioLock() {\n const n = node.value\n if (!n || !aspectRatioLockEditable(editor.graph, n)) return\n const locked = n.targetAspectRatio !== null\n editor.updateNodeWithUndo(\n n.id,\n { targetAspectRatio: locked ? null : lockedAspectRatioTarget(n.width, n.height) },\n 'Toggle aspect ratio lock'\n )\n }\n\n function commitAxisSize(_axis: LayoutAxis, _value: number, _previous: number) {\n preview.commit()\n }\n\n function setAlignment(primary: LayoutAlign, counter: LayoutCounterAlign) {\n if (!node.value) return\n editor.updateNodeWithUndo(\n node.value.id,\n { primaryAxisAlign: primary, counterAxisAlign: counter },\n 'Change alignment'\n )\n }\n\n function setGapAuto(enabled: boolean) {\n const n = node.value\n if (!n) return\n editor.updateNodeWithUndo(\n n.id,\n { primaryAxisAlign: enabled ? 'SPACE_BETWEEN' : 'MIN' },\n enabled ? 'Set gap to auto' : 'Set gap to fixed'\n )\n }\n\n function setLayoutDirection(direction: SceneNode['layoutDirection']) {\n if (!node.value) return\n editor.updateNodeWithUndo(\n node.value.id,\n { layoutDirection: direction },\n 'Change layout direction'\n )\n }\n\n return {\n cancelPreview: preview.cancel,\n updateProp,\n updateSizeLimit,\n setSizeLimitToCurrent,\n commitSizeLimit,\n addSizeLimit,\n removeSizeLimit,\n commitProp,\n setAxisSizing,\n updateAxisSize,\n commitAxisSize,\n toggleAspectRatioLock,\n setAlignment,\n setGapAuto,\n setLayoutDirection\n }\n}\n\nexport function axisSizingForNode(\n graph: SceneGraph,\n node: SceneNode | null,\n axis: LayoutAxis\n): LayoutSizing {\n return node ? layoutSizing(graph, node, sizingAxis(axis)) : 'FIXED'\n}\n\nexport function sizingOptionsForNode(\n graph: SceneGraph,\n node: SceneNode | null,\n labels: Partial<Record<LayoutSizing, string>> = {}\n): { value: LayoutSizing; label: string }[] {\n const allowed = node ? layoutSizingOptions(graph, node) : []\n // A node outside auto-layout still shows its fixed size.\n const values: LayoutSizing[] = allowed.length > 0 ? allowed : ['FIXED']\n const fallback: Record<LayoutSizing, string> = { FIXED: 'Fixed', HUG: 'Hug', FILL: 'Fill' }\n return values.map((value) => ({ value, label: labels[value] ?? fallback[value] }))\n}\n\nfunction createLayoutSizingState(\n editor: Editor,\n node: ComputedRef<SceneNode | null>,\n panels: ValueRef<LayoutPanelStrings>\n) {\n const isInAutoLayout = computed(() => {\n const n = node.value\n if (!n?.parentId) return false\n const parent = editor.getNode(n.parentId)\n return parent ? parent.layoutMode !== 'NONE' : false\n })\n\n const isGrid = computed(() => node.value?.layoutMode === 'GRID')\n const isFlex = computed(\n () => node.value?.layoutMode === 'HORIZONTAL' || node.value?.layoutMode === 'VERTICAL'\n )\n const widthSizing = computed(() => axisSizingForNode(editor.graph, node.value, 'width'))\n const heightSizing = computed(() => axisSizingForNode(editor.graph, node.value, 'height'))\n\n function sizingOptions() {\n return sizingOptionsForNode(editor.graph, node.value, {\n FIXED: panels.value.sizingFixed,\n HUG: panels.value.sizingHug,\n FILL: panels.value.sizingFill\n })\n }\n\n const widthSizingOptions = computed(sizingOptions)\n const heightSizingOptions = computed(sizingOptions)\n const aspectRatioLocked = computed(() => node.value?.targetAspectRatio != null)\n const aspectRatioLockable = computed(() => {\n const n = node.value\n return !!n && aspectRatioLockEditable(editor.graph, n)\n })\n\n return {\n isInAutoLayout,\n aspectRatioL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,OAAO,OAAO,CAAC;CACvF,MAAM,eAAe,eAAe,kBAAkB,OAAO,OAAO,KAAK,OAAO,QAAQ,CAAC;CAEzF,SAAS,gBAAgB;EACvB,OAAO,qBAAqB,OAAO,OAAO,KAAK,OAAO;GACpD,OAAO,OAAO,MAAM;GACpB,KAAK,OAAO,MAAM;GAClB,MAAM,OAAO,MAAM;EACrB,CAAC;CACH;CAEA,MAAM,qBAAqB,SAAS,aAAa;CACjD,MAAM,sBAAsB,SAAS,aAAa;CAOlD,OAAO;EACL;EACA,mBARwB,eAAe,KAAK,OAAO,qBAAqB,IAQxD;EAChB,qBAR0B,eAAe;GACzC,MAAM,IAAI,KAAK;GACf,OAAO,CAAC,CAAC,KAAK,wBAAwB,OAAO,OAAO,CAAC;EACvD,CAKoB;EAClB;EACA;EACA;EACA;EACA;EACA;CACF;AACF"}
@@ -9,6 +9,7 @@ import { LayoutAxis, SizeLimitProp, trackLabel } from "./helpers.js";
9
9
  declare function useLayout(): {
10
10
  editor: import("@pairdraw/core").Editor;
11
11
  node: import("vue").ComputedRef<import("@pairdraw/scene-graph").SceneNode | null>;
12
+ resizes: import("vue").ComputedRef<boolean>;
12
13
  layoutDirection: import("vue").ComputedRef<import("@pairdraw/scene-graph").LayoutDirection>;
13
14
  gapAuto: import("vue").ComputedRef<boolean>;
14
15
  isInAutoLayout: import("vue").ComputedRef<boolean>;
@@ -1 +1 @@
1
- {"version":3,"file":"use.d.ts","names":[],"sources":["../../../src/controls/layout/use.ts"],"mappings":";;;;;;;;iBAiBgB;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;0BAAA"}
1
+ {"version":3,"file":"use.d.ts","names":[],"sources":["../../../src/controls/layout/use.ts"],"mappings":";;;;;;;;iBAqBgB;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;0BAAA"}
@@ -1,6 +1,8 @@
1
1
  import { useEditor } from "../../editor/context/index.js";
2
2
  import { useI18n } from "../../i18n/useI18n.js";
3
3
  import { createGridTrackActions, createLayoutActions, createLayoutSelectionState, createPaddingActions, createTrackSizingOptions, trackLabel } from "./helpers.js";
4
+ import { computed } from "vue";
5
+ import { takesOwnSize } from "@pairdraw/scene-graph/instances";
4
6
  //#region src/controls/layout/use.ts
5
7
  /**
6
8
  * Returns layout-related state and actions for the current selection.
@@ -21,6 +23,7 @@ function useLayout() {
21
23
  return {
22
24
  editor,
23
25
  node,
26
+ resizes: computed(() => node.value ? takesOwnSize(editor.graph, node.value) : false),
24
27
  layoutDirection,
25
28
  gapAuto,
26
29
  isInAutoLayout,
@@ -1 +1 @@
1
- {"version":3,"file":"use.js","names":[],"sources":["../../../src/controls/layout/use.ts"],"sourcesContent":["import {\n createGridTrackActions,\n createLayoutActions,\n createLayoutSelectionState,\n createPaddingActions,\n createTrackSizingOptions,\n trackLabel\n} from '#vue/controls/layout/helpers'\nimport { useEditor } from '#vue/editor/context'\nimport { useI18n } from '#vue/i18n'\n\n/**\n * Returns layout-related state and actions for the current selection.\n *\n * Use this composable to build auto-layout and grid panels that need sizing,\n * padding, alignment, and track editing behavior.\n */\nexport function useLayout() {\n const editor = useEditor()\n const { panels } = useI18n()\n\n const {\n node,\n layoutDirection,\n gapAuto,\n alignGrid,\n isInAutoLayout,\n isGrid,\n isFlex,\n widthSizing,\n heightSizing,\n widthSizingOptions,\n heightSizingOptions,\n aspectRatioLocked,\n aspectRatioLockable\n } = createLayoutSelectionState(editor, panels)\n\n const {\n showIndividualPadding,\n hasUniformPadding,\n hasSymmetricPadding,\n setHorizontalPadding,\n commitHorizontalPadding,\n setVerticalPadding,\n commitVerticalPadding,\n toggleIndividualPadding,\n cancelPaddingPreview\n } = createPaddingActions(editor, node)\n\n const layoutActions = createLayoutActions({ editor, node })\n\n const { updateGridTrack, addTrack, removeTrack } = createGridTrackActions(editor, node)\n\n return {\n editor,\n node,\n layoutDirection,\n gapAuto,\n isInAutoLayout,\n isGrid,\n isFlex,\n widthSizing,\n heightSizing,\n widthSizingOptions,\n heightSizingOptions,\n aspectRatioLocked,\n aspectRatioLockable,\n alignGrid,\n showIndividualPadding,\n hasUniformPadding,\n hasSymmetricPadding,\n trackSizingOptions: createTrackSizingOptions(panels.value),\n cancelPreview: () => {\n cancelPaddingPreview()\n layoutActions.cancelPreview()\n },\n updateProp: layoutActions.updateProp,\n updateSizeLimit: layoutActions.updateSizeLimit,\n setSizeLimitToCurrent: layoutActions.setSizeLimitToCurrent,\n commitSizeLimit: layoutActions.commitSizeLimit,\n addSizeLimit: layoutActions.addSizeLimit,\n removeSizeLimit: layoutActions.removeSizeLimit,\n commitProp: layoutActions.commitProp,\n setAxisSizing: layoutActions.setAxisSizing,\n updateAxisSize: layoutActions.updateAxisSize,\n commitAxisSize: layoutActions.commitAxisSize,\n toggleAspectRatioLock: layoutActions.toggleAspectRatioLock,\n setHorizontalPadding,\n commitHorizontalPadding,\n setVerticalPadding,\n commitVerticalPadding,\n setAlignment: layoutActions.setAlignment,\n setGapAuto: layoutActions.setGapAuto,\n setLayoutDirection: layoutActions.setLayoutDirection,\n updateGridTrack,\n addTrack,\n removeTrack,\n trackLabel,\n toggleIndividualPadding\n }\n}\n"],"mappings":";;;;;;;;;;AAiBA,SAAgB,YAAY;CAC1B,MAAM,SAAS,UAAU;CACzB,MAAM,EAAE,WAAW,QAAQ;CAE3B,MAAM,EACJ,MACA,iBACA,SACA,WACA,gBACA,QACA,QACA,aACA,cACA,oBACA,qBACA,mBACA,wBACE,2BAA2B,QAAQ,MAAM;CAE7C,MAAM,EACJ,uBACA,mBACA,qBACA,sBACA,yBACA,oBACA,uBACA,yBACA,yBACE,qBAAqB,QAAQ,IAAI;CAErC,MAAM,gBAAgB,oBAAoB;EAAE;EAAQ;CAAK,CAAC;CAE1D,MAAM,EAAE,iBAAiB,UAAU,gBAAgB,uBAAuB,QAAQ,IAAI;CAEtF,OAAO;EACL;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA,oBAAoB,yBAAyB,OAAO,KAAK;EACzD,qBAAqB;GACnB,qBAAqB;GACrB,cAAc,cAAc;EAC9B;EACA,YAAY,cAAc;EAC1B,iBAAiB,cAAc;EAC/B,uBAAuB,cAAc;EACrC,iBAAiB,cAAc;EAC/B,cAAc,cAAc;EAC5B,iBAAiB,cAAc;EAC/B,YAAY,cAAc;EAC1B,eAAe,cAAc;EAC7B,gBAAgB,cAAc;EAC9B,gBAAgB,cAAc;EAC9B,uBAAuB,cAAc;EACrC;EACA;EACA;EACA;EACA,cAAc,cAAc;EAC5B,YAAY,cAAc;EAC1B,oBAAoB,cAAc;EAClC;EACA;EACA;EACA;EACA;CACF;AACF"}
1
+ {"version":3,"file":"use.js","names":[],"sources":["../../../src/controls/layout/use.ts"],"sourcesContent":["import { computed } from 'vue'\n\nimport { takesOwnSize } from '@pairdraw/scene-graph/instances'\n\nimport {\n createGridTrackActions,\n createLayoutActions,\n createLayoutSelectionState,\n createPaddingActions,\n createTrackSizingOptions,\n trackLabel\n} from '#vue/controls/layout/helpers'\nimport { useEditor } from '#vue/editor/context'\nimport { useI18n } from '#vue/i18n'\n\n/**\n * Returns layout-related state and actions for the current selection.\n *\n * Use this composable to build auto-layout and grid panels that need sizing,\n * padding, alignment, and track editing behavior.\n */\nexport function useLayout() {\n const editor = useEditor()\n const { panels } = useI18n()\n\n const {\n node,\n layoutDirection,\n gapAuto,\n alignGrid,\n isInAutoLayout,\n isGrid,\n isFlex,\n widthSizing,\n heightSizing,\n widthSizingOptions,\n heightSizingOptions,\n aspectRatioLocked,\n aspectRatioLockable\n } = createLayoutSelectionState(editor, panels)\n\n const {\n showIndividualPadding,\n hasUniformPadding,\n hasSymmetricPadding,\n setHorizontalPadding,\n commitHorizontalPadding,\n setVerticalPadding,\n commitVerticalPadding,\n toggleIndividualPadding,\n cancelPaddingPreview\n } = createPaddingActions(editor, node)\n\n const layoutActions = createLayoutActions({ editor, node })\n\n const { updateGridTrack, addTrack, removeTrack } = createGridTrackActions(editor, node)\n\n /** Whether Figma lets the selected layer take a size of its own; see `takesOwnSize`. */\n const resizes = computed(() => (node.value ? takesOwnSize(editor.graph, node.value) : false))\n\n return {\n editor,\n node,\n resizes,\n layoutDirection,\n gapAuto,\n isInAutoLayout,\n isGrid,\n isFlex,\n widthSizing,\n heightSizing,\n widthSizingOptions,\n heightSizingOptions,\n aspectRatioLocked,\n aspectRatioLockable,\n alignGrid,\n showIndividualPadding,\n hasUniformPadding,\n hasSymmetricPadding,\n trackSizingOptions: createTrackSizingOptions(panels.value),\n cancelPreview: () => {\n cancelPaddingPreview()\n layoutActions.cancelPreview()\n },\n updateProp: layoutActions.updateProp,\n updateSizeLimit: layoutActions.updateSizeLimit,\n setSizeLimitToCurrent: layoutActions.setSizeLimitToCurrent,\n commitSizeLimit: layoutActions.commitSizeLimit,\n addSizeLimit: layoutActions.addSizeLimit,\n removeSizeLimit: layoutActions.removeSizeLimit,\n commitProp: layoutActions.commitProp,\n setAxisSizing: layoutActions.setAxisSizing,\n updateAxisSize: layoutActions.updateAxisSize,\n commitAxisSize: layoutActions.commitAxisSize,\n toggleAspectRatioLock: layoutActions.toggleAspectRatioLock,\n setHorizontalPadding,\n commitHorizontalPadding,\n setVerticalPadding,\n commitVerticalPadding,\n setAlignment: layoutActions.setAlignment,\n setGapAuto: layoutActions.setGapAuto,\n setLayoutDirection: layoutActions.setLayoutDirection,\n updateGridTrack,\n addTrack,\n removeTrack,\n trackLabel,\n toggleIndividualPadding\n }\n}\n"],"mappings":";;;;;;;;;;;;AAqBA,SAAgB,YAAY;CAC1B,MAAM,SAAS,UAAU;CACzB,MAAM,EAAE,WAAW,QAAQ;CAE3B,MAAM,EACJ,MACA,iBACA,SACA,WACA,gBACA,QACA,QACA,aACA,cACA,oBACA,qBACA,mBACA,wBACE,2BAA2B,QAAQ,MAAM;CAE7C,MAAM,EACJ,uBACA,mBACA,qBACA,sBACA,yBACA,oBACA,uBACA,yBACA,yBACE,qBAAqB,QAAQ,IAAI;CAErC,MAAM,gBAAgB,oBAAoB;EAAE;EAAQ;CAAK,CAAC;CAE1D,MAAM,EAAE,iBAAiB,UAAU,gBAAgB,uBAAuB,QAAQ,IAAI;CAKtF,OAAO;EACL;EACA;EACA,SALc,eAAgB,KAAK,QAAQ,aAAa,OAAO,OAAO,KAAK,KAAK,IAAI,KAK9E;EACN;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA,oBAAoB,yBAAyB,OAAO,KAAK;EACzD,qBAAqB;GACnB,qBAAqB;GACrB,cAAc,cAAc;EAC9B;EACA,YAAY,cAAc;EAC1B,iBAAiB,cAAc;EAC/B,uBAAuB,cAAc;EACrC,iBAAiB,cAAc;EAC/B,cAAc,cAAc;EAC5B,iBAAiB,cAAc;EAC/B,YAAY,cAAc;EAC1B,eAAe,cAAc;EAC7B,gBAAgB,cAAc;EAC9B,gBAAgB,cAAc;EAC9B,uBAAuB,cAAc;EACrC;EACA;EACA;EACA;EACA,cAAc,cAAc;EAC5B,YAAY,cAAc;EAC1B,oBAAoB,cAAc;EAClC;EACA;EACA;EACA;EACA;CACF;AACF"}
@@ -19,12 +19,30 @@ function useNodePreview(editor) {
19
19
  throw error;
20
20
  }
21
21
  }
22
+ /** Previews a change for each named node, such as the layers a resize places. */
23
+ function updateNodes(changes, label) {
24
+ if (!changes.size) return;
25
+ if (!preview) {
26
+ targets = [...changes.keys()];
27
+ preview = editor.beginNodePreview(label);
28
+ }
29
+ try {
30
+ for (const [id, patch] of changes) preview.update(id, patch);
31
+ } catch (error) {
32
+ cancel();
33
+ throw error;
34
+ }
35
+ }
22
36
  function takePreview() {
23
37
  const current = preview;
24
38
  preview = void 0;
25
39
  targets = [];
26
40
  return current;
27
41
  }
42
+ /** Whether a preview is running, so a caller can tell an edit's first preview from its later ones. */
43
+ function isActive() {
44
+ return preview !== void 0;
45
+ }
28
46
  function commit() {
29
47
  takePreview()?.commit();
30
48
  }
@@ -35,8 +53,10 @@ function useNodePreview(editor) {
35
53
  if (getCurrentInstance()) onDeactivated(cancel);
36
54
  return {
37
55
  update,
56
+ updateNodes,
38
57
  commit,
39
- cancel
58
+ cancel,
59
+ isActive
40
60
  };
41
61
  }
42
62
  //#endregion
@@ -1 +1 @@
1
- {"version":3,"file":"use.js","names":[],"sources":["../../../src/controls/node-preview/use.ts"],"sourcesContent":["import { tryOnScopeDispose } from '@vueuse/core'\nimport { getCurrentInstance, onDeactivated } from 'vue'\n\nimport type { Editor, NodePreview } from '@pairdraw/core'\nimport type { SceneNode } from '@pairdraw/scene-graph'\n\n/** Keeps an edit's original targets until its terminal event, even after selection changes. */\nexport function useNodePreview(editor: Editor) {\n let preview: NodePreview | undefined\n let targets: readonly string[] = []\n\n /** Previews `changes` on every target, or the changes a function gives for each one. */\n function update(\n ids: readonly string[],\n changes: Partial<SceneNode> | ((id: string) => Partial<SceneNode>),\n label: string\n ) {\n if (!preview) {\n if (!ids.length) return\n targets = [...ids]\n preview = editor.beginNodePreview(label)\n }\n try {\n for (const id of targets) {\n preview.update(id, typeof changes === 'function' ? changes(id) : changes)\n }\n } catch (error) {\n cancel()\n throw error\n }\n }\n\n function takePreview() {\n const current = preview\n preview = undefined\n targets = []\n return current\n }\n\n function commit() {\n takePreview()?.commit()\n }\n\n function cancel() {\n takePreview()?.cancel()\n }\n\n tryOnScopeDispose(cancel)\n if (getCurrentInstance()) onDeactivated(cancel)\n return { update, commit, cancel }\n}\n"],"mappings":";;;;AAOA,SAAgB,eAAe,QAAgB;CAC7C,IAAI;CACJ,IAAI,UAA6B,CAAC;;CAGlC,SAAS,OACP,KACA,SACA,OACA;EACA,IAAI,CAAC,SAAS;GACZ,IAAI,CAAC,IAAI,QAAQ;GACjB,UAAU,CAAC,GAAG,GAAG;GACjB,UAAU,OAAO,iBAAiB,KAAK;EACzC;EACA,IAAI;GACF,KAAK,MAAM,MAAM,SACf,QAAQ,OAAO,IAAI,OAAO,YAAY,aAAa,QAAQ,EAAE,IAAI,OAAO;EAE5E,SAAS,OAAO;GACd,OAAO;GACP,MAAM;EACR;CACF;CAEA,SAAS,cAAc;EACrB,MAAM,UAAU;EAChB,UAAU,KAAA;EACV,UAAU,CAAC;EACX,OAAO;CACT;CAEA,SAAS,SAAS;EAChB,YAAY,CAAC,EAAE,OAAO;CACxB;CAEA,SAAS,SAAS;EAChB,YAAY,CAAC,EAAE,OAAO;CACxB;CAEA,kBAAkB,MAAM;CACxB,IAAI,mBAAmB,GAAG,cAAc,MAAM;CAC9C,OAAO;EAAE;EAAQ;EAAQ;CAAO;AAClC"}
1
+ {"version":3,"file":"use.js","names":[],"sources":["../../../src/controls/node-preview/use.ts"],"sourcesContent":["import { tryOnScopeDispose } from '@vueuse/core'\nimport { getCurrentInstance, onDeactivated } from 'vue'\n\nimport type { Editor, NodePreview } from '@pairdraw/core'\nimport type { SceneNode } from '@pairdraw/scene-graph'\n\n/** Keeps an edit's original targets until its terminal event, even after selection changes. */\nexport function useNodePreview(editor: Editor) {\n let preview: NodePreview | undefined\n let targets: readonly string[] = []\n\n /** Previews `changes` on every target, or the changes a function gives for each one. */\n function update(\n ids: readonly string[],\n changes: Partial<SceneNode> | ((id: string) => Partial<SceneNode>),\n label: string\n ) {\n if (!preview) {\n if (!ids.length) return\n targets = [...ids]\n preview = editor.beginNodePreview(label)\n }\n try {\n for (const id of targets) {\n preview.update(id, typeof changes === 'function' ? changes(id) : changes)\n }\n } catch (error) {\n cancel()\n throw error\n }\n }\n\n /** Previews a change for each named node, such as the layers a resize places. */\n function updateNodes(changes: ReadonlyMap<string, Partial<SceneNode>>, label: string) {\n if (!changes.size) return\n if (!preview) {\n targets = [...changes.keys()]\n preview = editor.beginNodePreview(label)\n }\n try {\n for (const [id, patch] of changes) preview.update(id, patch)\n } catch (error) {\n cancel()\n throw error\n }\n }\n\n function takePreview() {\n const current = preview\n preview = undefined\n targets = []\n return current\n }\n\n /** Whether a preview is running, so a caller can tell an edit's first preview from its later ones. */\n function isActive() {\n return preview !== undefined\n }\n\n function commit() {\n takePreview()?.commit()\n }\n\n function cancel() {\n takePreview()?.cancel()\n }\n\n tryOnScopeDispose(cancel)\n if (getCurrentInstance()) onDeactivated(cancel)\n return { update, updateNodes, commit, cancel, isActive }\n}\n"],"mappings":";;;;AAOA,SAAgB,eAAe,QAAgB;CAC7C,IAAI;CACJ,IAAI,UAA6B,CAAC;;CAGlC,SAAS,OACP,KACA,SACA,OACA;EACA,IAAI,CAAC,SAAS;GACZ,IAAI,CAAC,IAAI,QAAQ;GACjB,UAAU,CAAC,GAAG,GAAG;GACjB,UAAU,OAAO,iBAAiB,KAAK;EACzC;EACA,IAAI;GACF,KAAK,MAAM,MAAM,SACf,QAAQ,OAAO,IAAI,OAAO,YAAY,aAAa,QAAQ,EAAE,IAAI,OAAO;EAE5E,SAAS,OAAO;GACd,OAAO;GACP,MAAM;EACR;CACF;;CAGA,SAAS,YAAY,SAAkD,OAAe;EACpF,IAAI,CAAC,QAAQ,MAAM;EACnB,IAAI,CAAC,SAAS;GACZ,UAAU,CAAC,GAAG,QAAQ,KAAK,CAAC;GAC5B,UAAU,OAAO,iBAAiB,KAAK;EACzC;EACA,IAAI;GACF,KAAK,MAAM,CAAC,IAAI,UAAU,SAAS,QAAQ,OAAO,IAAI,KAAK;EAC7D,SAAS,OAAO;GACd,OAAO;GACP,MAAM;EACR;CACF;CAEA,SAAS,cAAc;EACrB,MAAM,UAAU;EAChB,UAAU,KAAA;EACV,UAAU,CAAC;EACX,OAAO;CACT;;CAGA,SAAS,WAAW;EAClB,OAAO,YAAY,KAAA;CACrB;CAEA,SAAS,SAAS;EAChB,YAAY,CAAC,EAAE,OAAO;CACxB;CAEA,SAAS,SAAS;EAChB,YAAY,CAAC,EAAE,OAAO;CACxB;CAEA,kBAAkB,MAAM;CACxB,IAAI,mBAAmB,GAAG,cAAc,MAAM;CAC9C,OAAO;EAAE;EAAQ;EAAa;EAAQ;EAAQ;CAAS;AACzD"}
@@ -14,7 +14,7 @@ declare function usePosition(): {
14
14
  active: import("vue").ComputedRef<boolean>;
15
15
  isMulti: import("vue").ComputedRef<boolean>;
16
16
  prop: <K extends keyof SceneNode>(key: K) => import("vue").ComputedRef<MixedValue<SceneNode[K]>>;
17
- panelProp: (key: "x" | "y" | "rotation") => import("vue").ComputedRef<MixedValue<number>>;
17
+ panelProp: (key: "x" | "y" | "width" | "height" | "rotation") => import("vue").ComputedRef<MixedValue<number>>;
18
18
  ids: import("vue").ComputedRef<string[]>;
19
19
  x: import("vue").ComputedRef<number>;
20
20
  y: import("vue").ComputedRef<number>;
@@ -22,6 +22,7 @@ declare function usePosition(): {
22
22
  height: import("vue").ComputedRef<number>;
23
23
  rotation: import("vue").ComputedRef<number>;
24
24
  rotates: import("vue").ComputedRef<boolean>;
25
+ resizes: import("vue").ComputedRef<boolean>;
25
26
  inAutoLayout: import("vue").ComputedRef<boolean>;
26
27
  ignoresAutoLayout: import("vue").ComputedRef<boolean>;
27
28
  toggleIgnoreAutoLayout: () => void;
@@ -1 +1 @@
1
- {"version":3,"file":"use.d.ts","names":[],"sources":["../../../src/controls/position/use.ts"],"mappings":";;;;;;;;;iBAqBgB;;;;;;;EAgBU,YAAA,8CAAsB,YAAA;;;;;;;;;;;EAuBrB,aAAA,KAAA,qBAAmB;EAYnB,aAAA,KAAA,qBAAmB,eAAe;EAIlC,aAAA,KAAA;EAwBJ,QAAA,iCAAyB;EAI1B,OAAA;EAIK,SAAA"}
1
+ {"version":3,"file":"use.d.ts","names":[],"sources":["../../../src/controls/position/use.ts"],"mappings":";;;;;;;;;iBAuBgB;;;;;;;;;;;;;;;;;;;EAmDW,aAAA,KAAA,qBAAmB;EAYnB,aAAA,KAAA,qBAAmB,eAAe;EAIlC,aAAA,KAAA;EAwBJ,QAAA,iCAAyB;EAI1B,OAAA;EAIK,SAAA"}
@@ -4,7 +4,8 @@ import { useNodeProps } from "../node-props/use.js";
4
4
  import { usePropScrub } from "../prop-scrub/use.js";
5
5
  import { computed } from "vue";
6
6
  import { layerRotates } from "@pairdraw/scene-graph/generated";
7
- import { panelPosition, panelPositionChange, panelRotation, panelRotationChange } from "@pairdraw/core/geometry";
7
+ import { takesOwnSize } from "@pairdraw/scene-graph/instances";
8
+ import { panelNumber, panelPosition, panelPositionChange, panelRotation, panelRotationChange } from "@pairdraw/core/geometry";
8
9
  //#region src/controls/position/use.ts
9
10
  /**
10
11
  * Returns position-related state and actions for the current selection.
@@ -18,9 +19,15 @@ function usePosition() {
18
19
  const ids = computed(() => nodes.value.map((n) => n.id));
19
20
  /** Whether the selection turns and flips; a sticky note or connector stays upright. */
20
21
  const rotates = computed(() => nodes.value.every(layerRotates));
22
+ /**
23
+ * Whether every selected layer takes a size of its own: a layer inside an instance shows its
24
+ * component's size, as in Figma, while an instance nested in another may be resized.
25
+ */
26
+ const resizes = computed(() => nodes.value.length > 0 && nodes.value.every((target) => takesOwnSize(editor.graph, target)));
21
27
  function shown(target, key) {
22
- if (key === "rotation") return Math.round(panelRotation(target, editor.graph));
23
- return Math.round(panelPosition(target, editor.graph)[key]);
28
+ if (key === "rotation") return panelNumber(panelRotation(target, editor.graph));
29
+ if (key === "x" || key === "y") return panelNumber(panelPosition(target, editor.graph)[key]);
30
+ return panelNumber(target[key]);
24
31
  }
25
32
  /** The shown value of every selected node, or MIXED when they differ. */
26
33
  function panelProp(key) {
@@ -33,8 +40,8 @@ function usePosition() {
33
40
  }
34
41
  const x = computed(() => node.value ? shown(node.value, "x") : 0);
35
42
  const y = computed(() => node.value ? shown(node.value, "y") : 0);
36
- const width = computed(() => node.value?.width ?? 0);
37
- const height = computed(() => node.value?.height ?? 0);
43
+ const width = computed(() => node.value ? shown(node.value, "width") : 0);
44
+ const height = computed(() => node.value ? shown(node.value, "height") : 0);
38
45
  const rotation = computed(() => node.value ? shown(node.value, "rotation") : 0);
39
46
  const { updateProp: _updateProp, updateEach, commitProp: _commitProp, cancelProp: _cancelProp } = usePropScrub(editor);
40
47
  function updateProp(key, value) {
@@ -83,6 +90,7 @@ function usePosition() {
83
90
  height,
84
91
  rotation,
85
92
  rotates,
93
+ resizes,
86
94
  inAutoLayout,
87
95
  ignoresAutoLayout,
88
96
  toggleIgnoreAutoLayout,
@@ -1 +1 @@
1
- {"version":3,"file":"use.js","names":[],"sources":["../../../src/controls/position/use.ts"],"sourcesContent":["import { computed } from 'vue'\n\nimport {\n panelPosition,\n panelPositionChange,\n panelRotation,\n panelRotationChange\n} from '@pairdraw/core/geometry'\nimport type { NumericNodeProperty, SceneNode } from '@pairdraw/scene-graph'\nimport { layerRotates } from '@pairdraw/scene-graph/generated'\n\nimport { MIXED, useNodeProps, type MixedValue } from '#vue/controls/node-props/use'\nimport { usePropScrub } from '#vue/controls/prop-scrub/use'\nimport { useEditor } from '#vue/editor/context'\n\n/**\n * Returns position-related state and actions for the current selection.\n *\n * This composable is designed for property panels that edit x/y, size,\n * rotation, alignment, flipping, and multi-node transforms.\n */\nexport function usePosition() {\n const editor = useEditor()\n\n const { nodes, node, active, isMulti, prop } = useNodeProps()\n const ids = computed(() => nodes.value.map((n) => n.id))\n /** Whether the selection turns and flips; a sticky note or connector stays upright. */\n const rotates = computed(() => nodes.value.every(layerRotates))\n\n // X, Y, and rotation read as Figma's panel shows them: the turned layer's box on the canvas and\n // its counterclockwise angle; see `panelPosition` and `panelRotation`.\n function shown(target: SceneNode, key: 'x' | 'y' | 'rotation'): number {\n if (key === 'rotation') return Math.round(panelRotation(target, editor.graph))\n return Math.round(panelPosition(target, editor.graph)[key])\n }\n\n /** The shown value of every selected node, or MIXED when they differ. */\n function panelProp(key: 'x' | 'y' | 'rotation') {\n return computed<MixedValue<number>>(() => {\n const values = nodes.value.map((target) => shown(target, key))\n if (values.length === 0) return 0\n const first = values[0]\n return values.every((value) => value === first) ? first : MIXED\n })\n }\n\n const x = computed(() => (node.value ? shown(node.value, 'x') : 0))\n const y = computed(() => (node.value ? shown(node.value, 'y') : 0))\n const width = computed(() => node.value?.width ?? 0)\n const height = computed(() => node.value?.height ?? 0)\n const rotation = computed(() => (node.value ? shown(node.value, 'rotation') : 0))\n\n const {\n updateProp: _updateProp,\n updateEach,\n commitProp: _commitProp,\n cancelProp: _cancelProp\n } = usePropScrub(editor)\n\n // Typed X, Y, and rotation become each node's own move or turn, as typing them in Figma does.\n function updateProp(key: NumericNodeProperty, value: number) {\n if (key === 'x' || key === 'y') {\n updateEach(nodes.value, key, (target) =>\n panelPositionChange(target, editor.graph, key, value)\n )\n } else if (key === 'rotation') {\n updateEach(nodes.value, key, (target) => panelRotationChange(target, editor.graph, value))\n } else {\n _updateProp(nodes.value, key, value)\n }\n }\n\n function commitProp(key: NumericNodeProperty, value: number, previous: number) {\n _commitProp(nodes.value, key, value, previous)\n }\n\n function cancelProp(key: NumericNodeProperty) {\n _cancelProp(nodes.value, key)\n }\n\n /** Whether every selected layer sits in an auto layout, where it can ignore that layout. */\n const inAutoLayout = computed(\n () =>\n nodes.value.length > 0 &&\n nodes.value.every((target) => {\n const parent = target.parentId ? editor.graph.getNode(target.parentId) : undefined\n return !!parent && parent.layoutMode !== 'NONE'\n })\n )\n /** On only when every selected layer ignores its auto layout. */\n const ignoresAutoLayout = computed(\n () =>\n inAutoLayout.value && nodes.value.every((target) => target.layoutPositioning === 'ABSOLUTE')\n )\n\n /** Figma's Ignore auto layout toggle: a mixed selection is taken out of its layouts. */\n function toggleIgnoreAutoLayout() {\n editor.setLayoutPositioning(ids.value, ignoresAutoLayout.value ? 'AUTO' : 'ABSOLUTE')\n }\n\n function align(axis: 'horizontal' | 'vertical', pos: 'min' | 'center' | 'max') {\n editor.alignNodes(ids.value, axis, pos)\n }\n\n function flip(axis: 'horizontal' | 'vertical') {\n editor.flipNodes(ids.value, axis)\n }\n\n function rotate(degrees: number) {\n editor.rotateNodes(ids.value, degrees)\n }\n\n return {\n editor,\n nodes,\n node,\n active,\n isMulti,\n prop,\n panelProp,\n ids,\n x,\n y,\n width,\n height,\n rotation,\n rotates,\n inAutoLayout,\n ignoresAutoLayout,\n toggleIgnoreAutoLayout,\n updateProp,\n commitProp,\n cancel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O,OAAO,KAAK,KAAK,CACtD;OACK,IAAI,QAAQ,YACjB,WAAW,MAAM,OAAO,MAAM,WAAW,oBAAoB,QAAQ,OAAO,OAAO,KAAK,CAAC;OAEzF,YAAY,MAAM,OAAO,KAAK,KAAK;CAEvC;CAEA,SAAS,WAAW,KAA0B,OAAe,UAAkB;EAC7E,YAAY,MAAM,OAAO,KAAK,OAAO,QAAQ;CAC/C;CAEA,SAAS,WAAW,KAA0B;EAC5C,YAAY,MAAM,OAAO,GAAG;CAC9B;;CAGA,MAAM,eAAe,eAEjB,MAAM,MAAM,SAAS,KACrB,MAAM,MAAM,OAAO,WAAW;EAC5B,MAAM,SAAS,OAAO,WAAW,OAAO,MAAM,QAAQ,OAAO,QAAQ,IAAI,KAAA;EACzE,OAAO,CAAC,CAAC,UAAU,OAAO,eAAe;CAC3C,CAAC,CACL;;CAEA,MAAM,oBAAoB,eAEtB,aAAa,SAAS,MAAM,MAAM,OAAO,WAAW,OAAO,sBAAsB,UAAU,CAC/F;;CAGA,SAAS,yBAAyB;EAChC,OAAO,qBAAqB,IAAI,OAAO,kBAAkB,QAAQ,SAAS,UAAU;CACtF;CAEA,SAAS,MAAM,MAAiC,KAA+B;EAC7E,OAAO,WAAW,IAAI,OAAO,MAAM,GAAG;CACxC;CAEA,SAAS,KAAK,MAAiC;EAC7C,OAAO,UAAU,IAAI,OAAO,IAAI;CAClC;CAEA,SAAS,OAAO,SAAiB;EAC/B,OAAO,YAAY,IAAI,OAAO,OAAO;CACvC;CAEA,OAAO;EACL;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;CACF;AACF"}
1
+ {"version":3,"file":"use.js","names":[],"sources":["../../../src/controls/position/use.ts"],"sourcesContent":["import { computed } from 'vue'\n\nimport {\n panelNumber,\n panelPosition,\n panelPositionChange,\n panelRotation,\n panelRotationChange\n} from '@pairdraw/core/geometry'\nimport type { NumericNodeProperty, SceneNode } from '@pairdraw/scene-graph'\nimport { layerRotates } from '@pairdraw/scene-graph/generated'\nimport { takesOwnSize } from '@pairdraw/scene-graph/instances'\n\nimport { MIXED, useNodeProps, type MixedValue } from '#vue/controls/node-props/use'\nimport { usePropScrub } from '#vue/controls/prop-scrub/use'\nimport { useEditor } from '#vue/editor/context'\n\n/**\n * Returns position-related state and actions for the current selection.\n *\n * This composable is designed for property panels that edit x/y, size,\n * rotation, alignment, flipping, and multi-node transforms.\n */\nexport function usePosition() {\n const editor = useEditor()\n\n const { nodes, node, active, isMulti, prop } = useNodeProps()\n const ids = computed(() => nodes.value.map((n) => n.id))\n /** Whether the selection turns and flips; a sticky note or connector stays upright. */\n const rotates = computed(() => nodes.value.every(layerRotates))\n /**\n * Whether every selected layer takes a size of its own: a layer inside an instance shows its\n * component's size, as in Figma, while an instance nested in another may be resized.\n */\n const resizes = computed(\n () =>\n nodes.value.length > 0 && nodes.value.every((target) => takesOwnSize(editor.graph, target))\n )\n\n type PanelProp = 'x' | 'y' | 'rotation' | 'width' | 'height'\n\n // X, Y, rotation, width and height read as Figma's panel shows them: two decimals, the turned\n // layer's box on the canvas and its counterclockwise angle; see `panelPosition` and\n // `panelRotation`.\n function shown(target: SceneNode, key: PanelProp): number {\n if (key === 'rotation') return panelNumber(panelRotation(target, editor.graph))\n if (key === 'x' || key === 'y') return panelNumber(panelPosition(target, editor.graph)[key])\n return panelNumber(target[key])\n }\n\n /** The shown value of every selected node, or MIXED when they differ. */\n function panelProp(key: PanelProp) {\n return computed<MixedValue<number>>(() => {\n const values = nodes.value.map((target) => shown(target, key))\n if (values.length === 0) return 0\n const first = values[0]\n return values.every((value) => value === first) ? first : MIXED\n })\n }\n\n const x = computed(() => (node.value ? shown(node.value, 'x') : 0))\n const y = computed(() => (node.value ? shown(node.value, 'y') : 0))\n const width = computed(() => (node.value ? shown(node.value, 'width') : 0))\n const height = computed(() => (node.value ? shown(node.value, 'height') : 0))\n const rotation = computed(() => (node.value ? shown(node.value, 'rotation') : 0))\n\n const {\n updateProp: _updateProp,\n updateEach,\n commitProp: _commitProp,\n cancelProp: _cancelProp\n } = usePropScrub(editor)\n\n // Typed X, Y, and rotation become each node's own move or turn, as typing them in Figma does.\n function updateProp(key: NumericNodeProperty, value: number) {\n if (key === 'x' || key === 'y') {\n updateEach(nodes.value, key, (target) =>\n panelPositionChange(target, editor.graph, key, value)\n )\n } else if (key === 'rotation') {\n updateEach(nodes.value, key, (target) => panelRotationChange(target, editor.graph, value))\n } else {\n _updateProp(nodes.value, key, value)\n }\n }\n\n function commitProp(key: NumericNodeProperty, value: number, previous: number) {\n _commitProp(nodes.value, key, value, previous)\n }\n\n function cancelProp(key: NumericNodeProperty) {\n _cancelProp(nodes.value, key)\n }\n\n /** Whether every selected layer sits in an auto layout, where it can ignore that layout. */\n const inAutoLayout = computed(\n () =>\n nodes.value.length > 0 &&\n nodes.value.every((target) => {\n const parent = target.parentId ? editor.graph.getNode(target.parentId) : undefined\n return !!parent && parent.layoutMode !== 'NONE'\n })\n )\n /** On only when every selected layer ignores its auto layout. */\n const ignoresAutoLayout = computed(\n () =>\n inAutoLayout.value && nodes.value.every((target) => target.layoutPositioning === 'ABSOLUTE')\n )\n\n /** Figma's Ignore auto layout toggle: a mixed selection is taken out of its layouts. */\n function toggleIgnoreAutoLayout() {\n editor.setLayoutPositioning(ids.value, ignoresAutoLayout.value ? 'AUTO' : 'ABSOLUTE')\n }\n\n function align(axis: 'horizontal' | 'vertical', pos: 'min' | 'center' | 'max') {\n editor.alignNodes(ids.value, axis, pos)\n }\n\n function flip(axis: 'horizontal' | 'vertical') {\n editor.flipNodes(ids.value, axis)\n }\n\n function rotate(degrees: number) {\n editor.rotateNodes(ids.value, degrees)\n }\n\n return {\n editor,\n nodes,\n node,\n active,\n isMulti,\n prop,\n panelProp,\n ids,\n x,\n y,\n width,\n height,\n rotation,\n rotates,\n resizes,\n inAutoLayout,\n ignoresAutoLayout,\n toggleIgnoreAutoLayout,\n updatePro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;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;CACF;AACF"}
@@ -1 +1 @@
1
- {"version":3,"file":"use.d.ts","names":[],"sources":["../../../src/controls/property-list/use.ts"],"mappings":";;;iBAwBgB,sBAAsB,UAAU,iBAAiB,SAAS"}
1
+ {"version":3,"file":"use.d.ts","names":[],"sources":["../../../src/controls/property-list/use.ts"],"mappings":";;;iBAyBgB,sBAAsB,UAAU,iBAAiB,SAAS"}
@@ -3,6 +3,7 @@ import { isNodeArrayMixed } from "../node-props/helpers.js";
3
3
  import { useNodeProps } from "../node-props/use.js";
4
4
  import { useUndoBatch } from "../undo-batch/use.js";
5
5
  import { computed } from "vue";
6
+ import { listBindingsAfterEdit } from "@pairdraw/scene-graph/variables";
6
7
  //#region src/controls/property-list/use.ts
7
8
  function moveItem(items, fromIndex, toIndex) {
8
9
  if (fromIndex === toIndex || fromIndex < 0 || fromIndex >= items.length) return items;
@@ -38,8 +39,19 @@ function useEditorPropertyList(propKey) {
38
39
  const own = node[propKey];
39
40
  return own.length === 0 && !isMixed.value ? items.value : own;
40
41
  }
41
- function updateArray(node, value, label) {
42
- editor.updateNodeWithUndo(node.id, { [propKey]: value }, label);
42
+ /**
43
+ * A text's fills colour every character, as a layer's own fills do in Figma. `sources` gives
44
+ * the position each item had, or null for a new one, when the edit adds, removes, or moves
45
+ * items, so their bindings follow them in the same undo step.
46
+ */
47
+ function updateArray(node, value, label, sources) {
48
+ const changes = { [propKey]: value };
49
+ if (sources) changes.boundVariables = listBindingsAfterEdit(node.boundVariables, propKey, sources);
50
+ editor.updateNodeWithUndo(node.id, editor.layerChanges(node.id, changes), label);
51
+ }
52
+ /** The positions of a list of `length` items, as `sources` for an edit that keeps them. */
53
+ function positions(length) {
54
+ return Array.from({ length }, (_, index) => index);
43
55
  }
44
56
  function add(item) {
45
57
  batch.flush();
@@ -48,7 +60,9 @@ function useEditorPropertyList(propKey) {
48
60
  const apply = () => {
49
61
  for (const node of nodes) {
50
62
  const nextItem = structuredClone(item);
51
- updateArray(node, isMulti.value ? [nextItem] : [...propArray(node), nextItem], label);
63
+ const replace = isMulti.value;
64
+ const current = propArray(node);
65
+ updateArray(node, replace ? [nextItem] : [...current, nextItem], label, replace ? [null] : [...positions(current.length), null]);
52
66
  }
53
67
  };
54
68
  if (nodes.length > 1) editor.undo.runBatch(label, apply);
@@ -59,7 +73,11 @@ function useEditorPropertyList(propKey) {
59
73
  const nodes = targetNodes();
60
74
  const label = `Remove ${propKey}`;
61
75
  const apply = () => {
62
- for (const node of nodes) updateArray(node, propArray(node).filter((_, itemIndex) => itemIndex !== index), label);
76
+ for (const node of nodes) {
77
+ const current = propArray(node);
78
+ const kept = positions(current.length).filter((itemIndex) => itemIndex !== index);
79
+ updateArray(node, kept.map((itemIndex) => current[itemIndex]), label, kept);
80
+ }
63
81
  };
64
82
  if (nodes.length > 1) editor.undo.runBatch(label, apply);
65
83
  else apply();
@@ -115,7 +133,11 @@ function useEditorPropertyList(propKey) {
115
133
  const nodes = targetNodes();
116
134
  if (nodes.length === 0 || fromIndex === toIndex) return;
117
135
  const apply = () => {
118
- for (const node of nodes) updateArray(node, moveItem(propArray(node), fromIndex, toIndex), `Reorder ${propKey}`);
136
+ for (const node of nodes) {
137
+ const current = propArray(node);
138
+ const order = moveItem(positions(current.length), fromIndex, toIndex);
139
+ updateArray(node, order.map((itemIndex) => current[itemIndex]), `Reorder ${propKey}`, order);
140
+ }
119
141
  };
120
142
  if (nodes.length > 1) editor.undo.runBatch(`Reorder ${propKey}`, apply);
121
143
  else apply();
@@ -1 +1 @@
1
- {"version":3,"file":"use.js","names":[],"sources":["../../../src/controls/property-list/use.ts"],"sourcesContent":["import { computed } from 'vue'\n\nimport type { SceneNode } from '@pairdraw/scene-graph'\n\nimport { isNodeArrayMixed } from '#vue/controls/node-props/helpers'\nimport { useNodeProps } from '#vue/controls/node-props/use'\nimport { useUndoBatch } from '#vue/controls/undo-batch/use'\nimport { useEditor } from '#vue/editor/context'\nimport type {\n PropertyListActions,\n PropertyListItemFor,\n PropertyListKey,\n PropertyListPatchFor\n} from '#vue/primitives/PropertyList/types.ts'\n\nfunction moveItem<T>(items: T[], fromIndex: number, toIndex: number): T[] {\n if (fromIndex === toIndex || fromIndex < 0 || fromIndex >= items.length) return items\n const next = [...items]\n const moved = next.splice(fromIndex, 1)[0]\n if (moved === undefined) return items\n next.splice(Math.max(0, Math.min(toIndex, next.length)), 0, moved)\n return next\n}\n\nexport function useEditorPropertyList<K extends PropertyListKey>(propKey: K) {\n const editor = useEditor()\n const { nodes: selectedNodes, activeNode } = useNodeProps()\n const batch = useUndoBatch(editor.undo, editor.beginInteractiveEdit)\n const selectedNodeIds = computed(() => selectedNodes.value.map((node) => node.id))\n const isMulti = computed(() => selectedNodes.value.length > 1)\n const active = computed(() => selectedNodes.value.length > 0)\n // Figma leaves layers without strokes out when it compares strokes, so a stroke on some of the\n // selection shows as theirs; fills and effects still differ when a layer has none.\n const shownNodes = computed(() => {\n if (propKey !== 'strokes') return selectedNodes.value\n const stroked = selectedNodes.value.filter((node) => node.strokes.length > 0)\n return stroked.length > 0 ? stroked : selectedNodes.value\n })\n const isMixed = computed(() => isNodeArrayMixed(shownNodes.value, propKey))\n const items = computed<PropertyListItemFor<K>[]>(() => {\n if (isMixed.value) return []\n const shown = shownNodes.value.at(0)\n return (shown?.[propKey] ?? []) as PropertyListItemFor<K>[]\n })\n\n function targetNodes(): SceneNode[] {\n if (isMulti.value) return selectedNodes.value\n return activeNode.value ? [activeNode.value] : []\n }\n\n /** A layer without strokes takes the shown ones when they are edited, as in Figma. */\n function propArray(node: SceneNode): PropertyListItemFor<K>[] {\n const own = node[propKey] as PropertyListItemFor<K>[]\n return own.length === 0 && !isMixed.value ? items.value : own\n }\n\n function updateArray(node: SceneNode, value: PropertyListItemFor<K>[], label: string) {\n editor.updateNodeWithUndo(node.id, { [propKey]: value }, label)\n }\n\n function add(item: PropertyListItemFor<K>) {\n batch.flush()\n const nodes = targetNodes()\n const label = isMulti.value ? `Set ${propKey}` : `Add ${propKey}`\n const apply = () => {\n for (const node of nodes) {\n const nextItem = structuredClone(item)\n const next = isMulti.value ? [nextItem] : [...propArray(node), nextItem]\n updateArray(node, next, label)\n }\n }\n if (nodes.length > 1) editor.undo.runBatch(label, apply)\n else apply()\n }\n\n function remove(index: number) {\n batch.flush()\n const nodes = targetNodes()\n const label = `Remove ${propKey}`\n const apply = () => {\n for (const node of nodes) {\n updateArray(\n node,\n propArray(node).filter((_, itemIndex) => itemIndex !== index),\n label\n )\n }\n }\n if (nodes.length > 1) editor.undo.runBatch(label, apply)\n else apply()\n }\n\n function update(index: number, item: PropertyListItemFor<K>) {\n const nodes = targetNodes()\n if (nodes.length === 0) return\n batch.ensure(\n `update:${propKey}:${index}:${nodes.map((node) => node.id).join(',')}`,\n `Change ${propKey}`\n )\n for (const node of nodes) {\n const next = [...propArray(node)]\n next[index] = structuredClone(item)\n updateArray(node, next, `Change ${propKey}`)\n }\n }\n\n function patch(index: number, changes: PropertyListPatchFor<K>) {\n const nodes = targetNodes()\n if (nodes.length === 0) return\n batch.ensure(\n `patch:${propKey}:${index}:${nodes.map((node) => node.id).join(',')}`,\n `Change ${propKey}`\n )\n for (const node of nodes) {\n const current = propArray(node)[index]\n if (!current) continue\n const next = [...propArray(node)]\n next[index] = { ...current, ...structuredClone(changes) }\n updateArray(node, next, `Change ${propKey}`)\n }\n }\n\n function toggleVisibility(index: number) {\n batch.flush()\n const nodes = targetNodes()\n if (nodes.length === 0) return\n const apply = () => {\n for (const node of nodes) {\n const liveNode = editor.getNode(node.id)\n if (!liveNode) continue\n const current = propArray(liveNode)[index]\n if (!current) continue\n const next = [...propArray(liveNode)]\n next[index] = { ...current, visible: !current.visible }\n updateArray(liveNode, next, `Toggle ${propKey} visibility`)\n }\n }\n if (nodes.length > 1) editor.undo.runBatch(`Toggle ${propKey} visibility`, apply)\n else apply()\n }\n\n function reorder(fromIndex: number, toIndex: number) {\n batch.flush()\n const nodes = targetNodes()\n if (nodes.length === 0 || fromIndex === toIndex) return\n const apply = () => {\n for (const node of nodes) {\n updateArray(node, moveItem(propArray(node), fromIndex, toIndex), `Reorder ${propKey}`)\n }\n }\n if (nodes.length > 1) editor.undo.runBatch(`Reorder ${propKey}`, apply)\n else apply()\n }\n\n const actions: PropertyListActions<K> = {\n add,\n remove,\n update,\n patch,\n toggleVisibility,\n reorder\n }\n\n return {\n items,\n isMixed,\n isMulti,\n active,\n activeNode,\n selectedNodeIds,\n flush: batch.flush,\n actions\n }\n}\n"],"mappings":";;;;;;AAeA,SAAS,SAAY,OAAY,WAAmB,SAAsB;CACxE,IAAI,cAAc,WAAW,YAAY,KAAK,aAAa,MAAM,QAAQ,OAAO;CAChF,MAAM,OAAO,CAAC,GAAG,KAAK;CACtB,MAAM,QAAQ,KAAK,OAAO,WAAW,CAAC,CAAC,CAAC;CACxC,IAAI,UAAU,KAAA,GAAW,OAAO;CAChC,KAAK,OAAO,KAAK,IAAI,GAAG,KAAK,IAAI,SAAS,KAAK,MAAM,CAAC,GAAG,GAAG,KAAK;CACjE,OAAO;AACT;AAEA,SAAgB,sBAAiD,SAAY;CAC3E,MAAM,SAAS,UAAU;CACzB,MAAM,EAAE,OAAO,eAAe,eAAe,aAAa;CAC1D,MAAM,QAAQ,aAAa,OAAO,MAAM,OAAO,oBAAoB;CACnE,MAAM,kBAAkB,eAAe,cAAc,MAAM,KAAK,SAAS,KAAK,EAAE,CAAC;CACjF,MAAM,UAAU,eAAe,cAAc,MAAM,SAAS,CAAC;CAC7D,MAAM,SAAS,eAAe,cAAc,MAAM,SAAS,CAAC;CAG5D,MAAM,aAAa,eAAe;EAChC,IAAI,YAAY,WAAW,OAAO,cAAc;EAChD,MAAM,UAAU,cAAc,MAAM,QAAQ,SAAS,KAAK,QAAQ,SAAS,CAAC;EAC5E,OAAO,QAAQ,SAAS,IAAI,UAAU,cAAc;CACtD,CAAC;CACD,MAAM,UAAU,eAAe,iBAAiB,WAAW,OAAO,O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GAC5D;EACF;EACA,IAAI,MAAM,SAAS,GAAG,OAAO,KAAK,SAAS,UAAU,QAAQ,cAAc,KAAK;OAC3E,MAAM;CACb;CAEA,SAAS,QAAQ,WAAmB,SAAiB;EACnD,MAAM,MAAM;EACZ,MAAM,QAAQ,YAAY;EAC1B,IAAI,MAAM,WAAW,KAAK,cAAc,SAAS;EACjD,MAAM,cAAc;GAClB,KAAK,MAAM,QAAQ,OACjB,YAAY,MAAM,SAAS,UAAU,IAAI,GAAG,WAAW,OAAO,GAAG,WAAW,SAAS;EAEzF;EACA,IAAI,MAAM,SAAS,GAAG,OAAO,KAAK,SAAS,WAAW,WAAW,KAAK;OACjE,MAAM;CACb;CAEA,MAAM,UAAkC;EACtC;EACA;EACA;EACA;EACA;EACA;CACF;CAEA,OAAO;EACL;EACA;EACA;EACA;EACA;EACA;EACA,OAAO,MAAM;EACb;CACF;AACF"}
1
+ {"version":3,"file":"use.js","names":[],"sources":["../../../src/controls/property-list/use.ts"],"sourcesContent":["import { computed } from 'vue'\n\nimport type { SceneNode } from '@pairdraw/scene-graph'\nimport { listBindingsAfterEdit } from '@pairdraw/scene-graph/variables'\n\nimport { isNodeArrayMixed } from '#vue/controls/node-props/helpers'\nimport { useNodeProps } from '#vue/controls/node-props/use'\nimport { useUndoBatch } from '#vue/controls/undo-batch/use'\nimport { useEditor } from '#vue/editor/context'\nimport type {\n PropertyListActions,\n PropertyListItemFor,\n PropertyListKey,\n PropertyListPatchFor\n} from '#vue/primitives/PropertyList/types.ts'\n\nfunction moveItem<T>(items: readonly T[], fromIndex: number, toIndex: number): readonly T[] {\n if (fromIndex === toIndex || fromIndex < 0 || fromIndex >= items.length) return items\n const next = [...items]\n const moved = next.splice(fromIndex, 1)[0]\n if (moved === undefined) return items\n next.splice(Math.max(0, Math.min(toIndex, next.length)), 0, moved)\n return next\n}\n\nexport function useEditorPropertyList<K extends PropertyListKey>(propKey: K) {\n const editor = useEditor()\n const { nodes: selectedNodes, activeNode } = useNodeProps()\n const batch = useUndoBatch(editor.undo, editor.beginInteractiveEdit)\n const selectedNodeIds = computed(() => selectedNodes.value.map((node) => node.id))\n const isMulti = computed(() => selectedNodes.value.length > 1)\n const active = computed(() => selectedNodes.value.length > 0)\n // Figma leaves layers without strokes out when it compares strokes, so a stroke on some of the\n // selection shows as theirs; fills and effects still differ when a layer has none.\n const shownNodes = computed(() => {\n if (propKey !== 'strokes') return selectedNodes.value\n const stroked = selectedNodes.value.filter((node) => node.strokes.length > 0)\n return stroked.length > 0 ? stroked : selectedNodes.value\n })\n const isMixed = computed(() => isNodeArrayMixed(shownNodes.value, propKey))\n const items = computed<PropertyListItemFor<K>[]>(() => {\n if (isMixed.value) return []\n const shown = shownNodes.value.at(0)\n return (shown?.[propKey] ?? []) as PropertyListItemFor<K>[]\n })\n\n function targetNodes(): SceneNode[] {\n if (isMulti.value) return selectedNodes.value\n return activeNode.value ? [activeNode.value] : []\n }\n\n /** A layer without strokes takes the shown ones when they are edited, as in Figma. */\n function propArray(node: SceneNode): PropertyListItemFor<K>[] {\n const own = node[propKey] as PropertyListItemFor<K>[]\n return own.length === 0 && !isMixed.value ? items.value : own\n }\n\n /**\n * A text's fills colour every character, as a layer's own fills do in Figma. `sources` gives\n * the position each item had, or null for a new one, when the edit adds, removes, or moves\n * items, so their bindings follow them in the same undo step.\n */\n function updateArray(\n node: SceneNode,\n value: PropertyListItemFor<K>[],\n label: string,\n sources?: readonly (number | null)[]\n ) {\n const changes: Partial<SceneNode> = { [propKey]: value }\n if (sources) {\n changes.boundVariables = listBindingsAfterEdit(node.boundVariables, propKey, sources)\n }\n editor.updateNodeWithUndo(node.id, editor.layerChanges(node.id, changes), label)\n }\n\n /** The positions of a list of `length` items, as `sources` for an edit that keeps them. */\n function positions(length: number): number[] {\n return Array.from({ length }, (_, index) => index)\n }\n\n function add(item: PropertyListItemFor<K>) {\n batch.flush()\n const nodes = targetNodes()\n const label = isMulti.value ? `Set ${propKey}` : `Add ${propKey}`\n const apply = () => {\n for (const node of nodes) {\n const nextItem = structuredClone(item)\n const replace = isMulti.value\n const current = propArray(node)\n updateArray(\n node,\n replace ? [nextItem] : [...current, nextItem],\n label,\n replace ? [null] : [...positions(current.length), null]\n )\n }\n }\n if (nodes.length > 1) editor.undo.runBatch(label, apply)\n else apply()\n }\n\n function remove(index: number) {\n batch.flush()\n const nodes = targetNodes()\n const label = `Remove ${propKey}`\n const apply = () => {\n for (const node of nodes) {\n const current = propArray(node)\n const kept = positions(current.length).filter((itemIndex) => itemIndex !== index)\n updateArray(\n node,\n kept.map((itemIndex) => current[itemIndex]),\n label,\n kept\n )\n }\n }\n if (nodes.length > 1) editor.undo.runBatch(label, apply)\n else apply()\n }\n\n function update(index: number, item: PropertyListItemFor<K>) {\n const nodes = targetNodes()\n if (nodes.length === 0) return\n batch.ensure(\n `update:${propKey}:${index}:${nodes.map((node) => node.id).join(',')}`,\n `Change ${propKey}`\n )\n for (const node of nodes) {\n const next = [...propArray(node)]\n next[index] = structuredClone(item)\n updateArray(node, next, `Change ${propKey}`)\n }\n }\n\n function patch(index: number, changes: PropertyListPatchFor<K>) {\n const nodes = targetNodes()\n if (nodes.length === 0) return\n batch.ensure(\n `patch:${propKey}:${index}:${nodes.map((node) => node.id).join(',')}`,\n `Change ${propKey}`\n )\n for (const node of nodes) {\n const current = propArray(node)[index]\n if (!current) continue\n const next = [...propArray(node)]\n next[index] = { ...current, ...structuredClone(changes) }\n updateArray(node, next, `Change ${propKey}`)\n }\n }\n\n function toggleVisibility(index: number) {\n batch.flush()\n const nodes = targetNodes()\n if (nodes.length === 0) return\n const apply = () => {\n for (const node of nodes) {\n const liveNode = editor.getNode(node.id)\n if (!liveNode) continue\n const current = propArray(liveNode)[index]\n if (!current) continue\n const next = [...propArray(liveNode)]\n next[index] = { ...current, visible: !current.visible }\n updateArray(liveNode, next, `Toggle ${propKey} visibility`)\n }\n }\n if (nodes.length > 1) editor.undo.runBatch(`Toggle ${propKey} visibility`, apply)\n else apply()\n }\n\n function reorder(fromIndex: number, toIndex: number) {\n batch.flush()\n const nodes = targetNodes()\n if (nodes.length === 0 || fromIndex === toIndex) return\n const apply = () => {\n for (const node of nodes) {\n const current = propArray(node)\n const order = moveItem(positions(current.length), fromIndex, toIndex)\n updateArray(\n node,\n order.map((itemIndex) => current[itemIndex]),\n `Reorder ${propKey}`,\n order\n )\n }\n }\n if (nodes.length > 1) editor.undo.runBatch(`Reorder ${propKey}`, apply)\n else apply()\n }\n\n const actions: PropertyListActions<K> = {\n add,\n remove,\n update,\n patch,\n toggleVisibility,\n reorder\n }\n\n return {\n items,\n isMixed,\n isMulti,\n active,\n activeNode,\n selectedNodeIds,\n flush: batch.flush,\n actions\n }\n}\n"],"mappings":";;;;;;;AAgBA,SAAS,SAAY,OAAqB,WAAmB,SAA+B;CAC1F,IAAI,cAAc,WAAW,YAAY,KAAK,aAAa,MAAM,QAAQ,OAAO;CAChF,MAAM,OAAO,CAAC,GAAG,KAAK;CACtB,MAAM,QAAQ,KAAK,OAAO,WAAW,CAAC,CAAC,CAAC;CACxC,IAAI,UAAU,KAAA,GAAW,OAAO;CAChC,KAAK,OAAO,KAAK,IAAI,GAAG,KAAK,IAAI,SAAS,KAAK,MAAM,CAAC,GAAG,GAAG,KAAK;CACjE,OAAO;AACT;AAEA,SAAgB,sBAAiD,SAAY;CAC3E,MAAM,SAAS,UAAU;CACzB,MAAM,EAAE,OAAO,eAAe,eAAe,aAAa;CAC1D,MAAM,QAAQ,aAAa,OAAO,MAAM,OAAO,oBAAoB;CACnE,MAAM,kBAAkB,eAAe,cAAc,MAAM,KAAK,SAAS,KAAK,EAAE,CAAC;CACjF,MAAM,UAAU,eAAe,cAAc,MAAM,SAAS,CAAC;CAC7D,MAAM,SAAS,eAAe,cAAc,MAAM,SAAS,CAAC;CAG5D,MAAM,aAAa,eAAe;EAChC,IAAI,YAAY,WAAW,OAAO,cAAc;EAChD,MAAM,UAAU,cAAc,MAAM,QAAQ,SAAS,KAAK,QAAQ,SAAS,CAAC;EAC5E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.ts"],"mappings":";;;;cAUa,wBAAwB,YAAY;KAOrC;iBAQI,eAAe,MAAM,YAAY;;;;;;iBAkBjC;;;;;;;;;;;EA+BW,aAAA;;EAgBI,gBAAA,MAAA;EAOA,gBAAA,MAAA"}
1
+ {"version":3,"file":"use.d.ts","names":[],"sources":["../../../src/controls/selection-layout/use.ts"],"mappings":";;;;cAWa,wBAAwB,YAAY;KAOrC;iBAQI,eAAe,MAAM,YAAY;;;;;;iBAkBjC;;;;;;;;;;;EA+BW,aAAA;;EAgBI,gBAAA,MAAA;EAOA,gBAAA,MAAA"}
@@ -4,6 +4,7 @@ import { useNodeProps } from "../node-props/use.js";
4
4
  import { useSceneComputed } from "../../internal/scene-computed/use.js";
5
5
  import { useUndoBatch } from "../undo-batch/use.js";
6
6
  import { computed } from "vue";
7
+ import { panelNumber } from "@pairdraw/core/geometry";
7
8
  //#region src/controls/selection-layout/use.ts
8
9
  /** Layers that can hold an auto layout and clip their content. */
9
10
  const LAYOUT_CONTAINER_TYPES = /* @__PURE__ */ new Set([
@@ -48,7 +49,7 @@ function useSelectionLayout() {
48
49
  const spacingAxis = computed(() => rowSpacing.value?.axis);
49
50
  /** The gap between neighbours, MIXED when they differ. */
50
51
  const spacing = computed(() => {
51
- return shared(rowSpacing.value?.gaps.map((gap) => Math.round(gap * 100) / 100) ?? []) ?? MIXED;
52
+ return shared(rowSpacing.value?.gaps.map(panelNumber) ?? []) ?? MIXED;
52
53
  });
53
54
  /** Spaces the row evenly from its first layer; a scrub is one undo step. */
54
55
  function setSpacing(gap) {
@@ -1 +1 @@
1
- {"version":3,"file":"use.js","names":[],"sources":["../../../src/controls/selection-layout/use.ts"],"sourcesContent":["import { computed } from 'vue'\n\nimport type { LayoutMode, NodeType, SceneNode } from '@pairdraw/scene-graph'\n\nimport { MIXED, useNodeProps, type MixedValue } from '#vue/controls/node-props/use'\nimport { useUndoBatch } from '#vue/controls/undo-batch/use'\nimport { useEditor } from '#vue/editor/context'\nimport { useSceneComputed } from '#vue/internal/scene-computed/use'\n\n/** Layers that can hold an auto layout and clip their content. */\nexport const LAYOUT_CONTAINER_TYPES: ReadonlySet<NodeType> = new Set<NodeType>([\n 'FRAME',\n 'COMPONENT',\n 'COMPONENT_SET',\n 'INSTANCE'\n])\n\nexport type TextResizeMode = 'AUTO_WIDTH' | 'AUTO_HEIGHT' | 'FIXED'\n\nconst TEXT_AUTO_RESIZE: Record<TextResizeMode, SceneNode['textAutoResize']> = {\n AUTO_WIDTH: 'WIDTH_AND_HEIGHT',\n AUTO_HEIGHT: 'HEIGHT',\n FIXED: 'NONE'\n}\n\nexport function textResizeMode(node: SceneNode): TextResizeMode {\n if (node.textAutoResize === 'WIDTH_AND_HEIGHT') return 'AUTO_WIDTH'\n // A truncating text keeps the size it has and ends its lines, so it is a fixed box here.\n if (node.textAutoResize === 'HEIGHT') return 'AUTO_HEIGHT'\n return 'FIXED'\n}\n\nfunction shared<T>(values: readonly T[]): MixedValue<T> | undefined {\n if (values.length === 0) return undefined\n const [first] = values\n return values.every((value) => value === first) ? first : MIXED\n}\n\n/**\n * Layout of a multi-selection, as Figma's panel shows it: text resizing for its text layers,\n * flow when every layer can hold an auto layout, clip content for those that can clip, and the\n * spacing of a row or column. Each edit changes the layers it applies to in one undo step.\n */\nexport function useSelectionLayout() {\n const editor = useEditor()\n const { nodes } = useNodeProps()\n const batch = useUndoBatch(editor.undo, editor.beginInteractiveEdit)\n\n const texts = computed(() => nodes.value.filter((node) => node.type === 'TEXT'))\n const containers = computed(() =>\n nodes.value.filter((node) => LAYOUT_CONTAINER_TYPES.has(node.type))\n )\n const allContainers = computed(\n () => nodes.value.length > 0 && containers.value.length === nodes.value.length\n )\n\n /** Undefined when no text is selected. */\n const textResize = computed(() => shared(texts.value.map(textResizeMode)))\n /** Undefined unless every selected layer can hold an auto layout. */\n const layoutMode = computed(() =>\n allContainers.value ? shared(containers.value.map((node) => node.layoutMode)) : undefined\n )\n const rowSpacing = useSceneComputed(() =>\n editor.selectionSpacing(nodes.value.map((node) => node.id))\n )\n /** The axis of a row or column, or undefined when the layers are not one. */\n const spacingAxis = computed(() => rowSpacing.value?.axis)\n /** The gap between neighbours, MIXED when they differ. */\n const spacing = computed<MixedValue<number>>(() => {\n const gaps = rowSpacing.value?.gaps.map((gap) => Math.round(gap * 100) / 100) ?? []\n return shared(gaps) ?? MIXED\n })\n\n /** Spaces the row evenly from its first layer; a scrub is one undo step. */\n function setSpacing(gap: number) {\n batch.ensure('selection-spacing', 'Change spacing')\n editor.setSelectionSpacing(\n nodes.value.map((node) => node.id),\n gap\n )\n }\n\n /** Undefined when nothing selected can clip. */\n const clipsContent = computed(() => shared(containers.value.map((node) => node.clipsContent)))\n const autoLayouts = computed(() => containers.value.filter((node) => node.layoutMode !== 'NONE'))\n /** Undefined when nothing selected has an auto layout. */\n const strokesIncludedInLayout = computed(() =>\n shared(autoLayouts.value.map((node) => node.strokesIncludedInLayout))\n )\n\n function setTextResize(mode: TextResizeMode) {\n editor.undo.runBatch('Set text resizing', () => {\n for (const node of texts.value)\n editor.updateNodeWithUndo(node.id, { textAutoResize: TEXT_AUTO_RESIZE[mode] })\n })\n }\n\n function setLayoutMode(mode: LayoutMode) {\n editor.undo.runBatch('Set layout', () => {\n for (const node of containers.value) editor.setLayoutMode(node.id, mode)\n })\n }\n\n /** A mixed checkbox turns clipping on, as Figma's does. */\n function toggleClipsContent() {\n const clips = clipsContent.value !== true\n editor.undo.runBatch('Toggle clip content', () => {\n for (const node of containers.value)\n editor.updateNodeWithUndo(node.id, { clipsContent: clips })\n })\n }\n\n /** A mixed checkbox includes strokes, as a mixed clip content checkbox clips. */\n function toggleStrokesIncludedInLayout() {\n const included = strokesIncludedInLayout.value !== true\n editor.undo.runBatch('Toggle strokes in layout', () => {\n for (const node of autoLayouts.value)\n editor.updateNodeWithUndo(node.id, { strokesIncludedInLayout: included })\n })\n }\n\n return {\n editor,\n nodes,\n texts,\n containers,\n textResize,\n layoutMode,\n clipsContent,\n strokesIncludedInLayout,\n sp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;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA,cAAc,MAAM;EACpB;EACA;EACA;EACA;CACF;AACF"}
1
+ {"version":3,"file":"use.js","names":[],"sources":["../../../src/controls/selection-layout/use.ts"],"sourcesContent":["import { computed } from 'vue'\n\nimport { panelNumber } from '@pairdraw/core/geometry'\nimport type { LayoutMode, NodeType, SceneNode } from '@pairdraw/scene-graph'\n\nimport { MIXED, useNodeProps, type MixedValue } from '#vue/controls/node-props/use'\nimport { useUndoBatch } from '#vue/controls/undo-batch/use'\nimport { useEditor } from '#vue/editor/context'\nimport { useSceneComputed } from '#vue/internal/scene-computed/use'\n\n/** Layers that can hold an auto layout and clip their content. */\nexport const LAYOUT_CONTAINER_TYPES: ReadonlySet<NodeType> = new Set<NodeType>([\n 'FRAME',\n 'COMPONENT',\n 'COMPONENT_SET',\n 'INSTANCE'\n])\n\nexport type TextResizeMode = 'AUTO_WIDTH' | 'AUTO_HEIGHT' | 'FIXED'\n\nconst TEXT_AUTO_RESIZE: Record<TextResizeMode, SceneNode['textAutoResize']> = {\n AUTO_WIDTH: 'WIDTH_AND_HEIGHT',\n AUTO_HEIGHT: 'HEIGHT',\n FIXED: 'NONE'\n}\n\nexport function textResizeMode(node: SceneNode): TextResizeMode {\n if (node.textAutoResize === 'WIDTH_AND_HEIGHT') return 'AUTO_WIDTH'\n // A truncating text keeps the size it has and ends its lines, so it is a fixed box here.\n if (node.textAutoResize === 'HEIGHT') return 'AUTO_HEIGHT'\n return 'FIXED'\n}\n\nfunction shared<T>(values: readonly T[]): MixedValue<T> | undefined {\n if (values.length === 0) return undefined\n const [first] = values\n return values.every((value) => value === first) ? first : MIXED\n}\n\n/**\n * Layout of a multi-selection, as Figma's panel shows it: text resizing for its text layers,\n * flow when every layer can hold an auto layout, clip content for those that can clip, and the\n * spacing of a row or column. Each edit changes the layers it applies to in one undo step.\n */\nexport function useSelectionLayout() {\n const editor = useEditor()\n const { nodes } = useNodeProps()\n const batch = useUndoBatch(editor.undo, editor.beginInteractiveEdit)\n\n const texts = computed(() => nodes.value.filter((node) => node.type === 'TEXT'))\n const containers = computed(() =>\n nodes.value.filter((node) => LAYOUT_CONTAINER_TYPES.has(node.type))\n )\n const allContainers = computed(\n () => nodes.value.length > 0 && containers.value.length === nodes.value.length\n )\n\n /** Undefined when no text is selected. */\n const textResize = computed(() => shared(texts.value.map(textResizeMode)))\n /** Undefined unless every selected layer can hold an auto layout. */\n const layoutMode = computed(() =>\n allContainers.value ? shared(containers.value.map((node) => node.layoutMode)) : undefined\n )\n const rowSpacing = useSceneComputed(() =>\n editor.selectionSpacing(nodes.value.map((node) => node.id))\n )\n /** The axis of a row or column, or undefined when the layers are not one. */\n const spacingAxis = computed(() => rowSpacing.value?.axis)\n /** The gap between neighbours, MIXED when they differ. */\n const spacing = computed<MixedValue<number>>(() => {\n const gaps = rowSpacing.value?.gaps.map(panelNumber) ?? []\n return shared(gaps) ?? MIXED\n })\n\n /** Spaces the row evenly from its first layer; a scrub is one undo step. */\n function setSpacing(gap: number) {\n batch.ensure('selection-spacing', 'Change spacing')\n editor.setSelectionSpacing(\n nodes.value.map((node) => node.id),\n gap\n )\n }\n\n /** Undefined when nothing selected can clip. */\n const clipsContent = computed(() => shared(containers.value.map((node) => node.clipsContent)))\n const autoLayouts = computed(() => containers.value.filter((node) => node.layoutMode !== 'NONE'))\n /** Undefined when nothing selected has an auto layout. */\n const strokesIncludedInLayout = computed(() =>\n shared(autoLayouts.value.map((node) => node.strokesIncludedInLayout))\n )\n\n function setTextResize(mode: TextResizeMode) {\n editor.undo.runBatch('Set text resizing', () => {\n for (const node of texts.value)\n editor.updateNodeWithUndo(node.id, { textAutoResize: TEXT_AUTO_RESIZE[mode] })\n })\n }\n\n function setLayoutMode(mode: LayoutMode) {\n editor.undo.runBatch('Set layout', () => {\n for (const node of containers.value) editor.setLayoutMode(node.id, mode)\n })\n }\n\n /** A mixed checkbox turns clipping on, as Figma's does. */\n function toggleClipsContent() {\n const clips = clipsContent.value !== true\n editor.undo.runBatch('Toggle clip content', () => {\n for (const node of containers.value)\n editor.updateNodeWithUndo(node.id, { clipsContent: clips })\n })\n }\n\n /** A mixed checkbox includes strokes, as a mixed clip content checkbox clips. */\n function toggleStrokesIncludedInLayout() {\n const included = strokesIncludedInLayout.value !== true\n editor.undo.runBatch('Toggle strokes in layout', () => {\n for (const node of autoLayouts.value)\n editor.updateNodeWithUndo(node.id, { strokesIncludedInLayout: included })\n })\n }\n\n return {\n editor,\n nodes,\n texts,\n containers,\n textResize,\n layoutMode,\n clipsContent,\n strokesIncludedInLayout,\n spacingAxis,\n spacing,\n setSpacing,\n flushSpacing: batch.flush,\n setTextResize,\n setLayoutMode,\n toggleClipsContent,\n toggleStrokesIncludedInLayout\n }\n}\n"],"mappings":";;;;;;;;;AAWA,MAAa,yCAAgD,IAAI,IAAc;CAC7E;CACA;CACA;CACA;AACF,CAAC;AAID,MAAM,mBAAwE;CAC5E,YAAY;CACZ,aAAa;CACb,OAAO;AACT;AAEA,SAAgB,eAAe,MAAiC;CAC9D,IAAI,KAAK,mBAAmB,oBAAoB,OAAO;CAEvD,IAAI,KAAK,mBAAmB,UAAU,OAAO;CAC7C,OAAO;AACT;AAEA,SAAS,OAAU,QAAiD;CAClE,IAAI,OAAO,WAAW,GAAG,OAAO,KAAA;CAChC,MAAM,CAAC,SAAS;CAChB,OAAO,OAAO,OAAO,UAAU,UAAU,KAAK,IAAI,QAAQ;AAC5D;;;;;;AAOA,SAAgB,qBAAqB;CACnC,MAAM,SAAS,UAAU;CACzB,MAAM,EAAE,UAAU,aAAa;CAC/B,MAAM,QAAQ,aAAa,OAAO,MAAM,OAAO,oBAAoB;CAEnE,MAAM,QAAQ,eAAe,MAAM,MAAM,QAAQ,SAAS,KAAK,SAAS,MAAM,CAAC;CAC/E,MAAM,aAAa,eACjB,MAAM,MAAM,QAAQ,SAAS,uBAAuB,IAAI,KAAK,IAAI,CAAC,CACpE;CACA,MAAM,gBAAgB,eACd,MAA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AK,SAAS,6BAA6B;GAChD,KAAK,MAAM,QAAQ,WAAW,OAC5B,OAAO,mBAAmB,KAAK,IAAI,EAAE,cAAc,MAAM,CAAC;EAC9D,CAAC;CACH;;CAGA,SAAS,gCAAgC;EACvC,MAAM,WAAW,wBAAwB,UAAU;EACnD,OAAO,KAAK,SAAS,kCAAkC;GACrD,KAAK,MAAM,QAAQ,YAAY,OAC7B,OAAO,mBAAmB,KAAK,IAAI,EAAE,yBAAyB,SAAS,CAAC;EAC5E,CAAC;CACH;CAEA,OAAO;EACL;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA,cAAc,MAAM;EACpB;EACA;EACA;EACA;CACF;AACF"}
@@ -1 +1 @@
1
- {"version":3,"file":"authoring.d.ts","names":[],"sources":["../../../src/controls/slots/authoring.ts"],"mappings":";;;UAciB;EACf;EACA;EACA;EACA;EACA;EACA;;EAEA,WAAW;;;;;;iBAYG;;;mCAAA;EAgDe,UAAA,uBAAS;;EAsBf,SAAA,oBAAM;EACJ,WAAA,oBAAM;EACL,YAAA,oBAAM;IAAY;IAAsB;;EAEjC,mBAAA,oBAAM;EArBL,eAAA,oBAAM,qBAAqB;EAwBtC,SAAA"}
1
+ {"version":3,"file":"authoring.d.ts","names":[],"sources":["../../../src/controls/slots/authoring.ts"],"mappings":";;;UAeiB;EACf;EACA;EACA;EACA;EACA;EACA;;EAEA,WAAW;;;;;;iBAYG;;;mCAAA;EAiDe,UAAA,uBAAS;;EAsBf,SAAA,oBAAM;EACJ,WAAA,oBAAM;EACL,YAAA,oBAAM;IAAY;IAAsB;;EAEjC,mBAAA,oBAAM;EArBL,eAAA,oBAAM,qBAAqB;EAwBtC,SAAA"}
@@ -2,6 +2,7 @@ import { useEditor } from "../../editor/context/index.js";
2
2
  import { useSceneComputed } from "../../internal/scene-computed/use.js";
3
3
  import { slotInstanceOptions } from "./instance.js";
4
4
  import { canCreateSlot, slotOwner, slotPropertyId } from "@pairdraw/scene-graph/slots";
5
+ import { propertyOwner } from "@pairdraw/scene-graph/components";
5
6
  //#region src/controls/slots/authoring.ts
6
7
  /** The value a preferred-components list stores for a component: its key, else its id. */
7
8
  function preferredValue(component) {
@@ -18,7 +19,7 @@ function useSlotAuthoring() {
18
19
  if (nodes.length !== 1) return void 0;
19
20
  const [node] = nodes;
20
21
  if (node.type === "COMPONENT") return {
21
- owner: node,
22
+ owner: propertyOwner(editor.graph, node),
22
23
  frame: void 0,
23
24
  propertyId: void 0
24
25
  };