@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
@@ -1 +1 @@
1
- {"version":3,"file":"authoring.js","names":[],"sources":["../../../src/controls/slots/authoring.ts"],"sourcesContent":["import type { ComponentPropertyDefinition, SceneNode } from '@pairdraw/scene-graph'\nimport {\n canCreateSlot,\n slotOwner,\n slotPropertyId,\n type SlotPropertyPatch\n} from '@pairdraw/scene-graph/slots'\n\nimport { useEditor } from '#vue/editor/context'\nimport { useSceneComputed } from '#vue/internal/scene-computed/use'\n\nimport { slotInstanceOptions, type SlotInstanceOption } from './instance'\n\n/** A slot property as its main component defines it. */\nexport interface SlotDefinitionControl {\n id: string\n name: string\n description: string\n minChildren?: number\n maxChildren?: number\n preferredOnly: boolean\n /** Components the slot prefers, resolved from the definition's preferred values. */\n preferred: SlotInstanceOption[]\n}\n\n/** The value a preferred-components list stores for a component: its key, else its id. */\nfunction preferredValue(component: SceneNode): string {\n return component.componentKey ?? component.id\n}\n\n/**\n * Slot properties of the selected main component or slot frame, with the actions that\n * create, configure, and remove them.\n */\nexport function useSlotAuthoring() {\n const editor = useEditor()\n const target = useSceneComputed(() => {\n const nodes = editor.getSelectedNodes()\n if (nodes.length !== 1) return undefined\n const [node] = nodes\n if (node.type === 'COMPONENT') return { owner: node, frame: undefined, propertyId: undefined }\n const owner = slotOwner(editor.graph, node)\n if (!owner) return undefined\n const propertyId = slotPropertyId(node)\n if (!propertyId && !canCreateSlot(editor.graph, node)) return undefined\n return { owner, frame: node, propertyId }\n })\n const slots = useSceneComputed<SlotDefinitionControl[]>(() => {\n const current = target.value\n if (!current) return []\n return current.owner.componentPropertyDefinitions\n .filter((definition) => definition.type === 'SLOT')\n .filter((definition) => !current.frame || definition.id === current.propertyId)\n .map((definition) => {\n const values = new Set(definition.preferredValues)\n return {\n id: definition.id,\n name: definition.name,\n description: definition.description ?? '',\n minChildren: definition.slotSettings?.minChildren,\n maxChildren: definition.slotSettings?.maxChildren,\n preferredOnly: definition.slotSettings?.allowPreferredValuesOnly ?? false,\n preferred: slotInstanceOptions(editor.graph, definition).filter(\n (option) => option.preferred && values.size > 0\n )\n }\n })\n })\n /** Whether the selection is a frame that can become a slot. */\n const canCreate = useSceneComputed(() => !!target.value?.frame && !target.value.propertyId)\n const active = useSceneComputed(() => slots.value.length > 0 || canCreate.value)\n\n function update(propertyId: string, patch: SlotPropertyPatch) {\n const owner = target.value?.owner\n if (owner) editor.updateSlot(owner.id, propertyId, patch)\n }\n\n function definition(propertyId: string): ComponentPropertyDefinition | undefined {\n return target.value?.owner.componentPropertyDefinitions.find((item) => item.id === propertyId)\n }\n\n /** Components that can be marked preferred, the slot's current choices first. */\n function options(propertyId: string): SlotInstanceOption[] {\n const found = definition(propertyId)\n return found ? slotInstanceOptions(editor.graph, found) : []\n }\n\n function setPreferred(propertyId: string, componentId: string, preferred: boolean) {\n const found = definition(propertyId)\n const component = editor.graph.getNode(componentId)\n if (!found || !component) return\n const keys = new Set([component.id, component.componentKey, component.sourceLibraryKey])\n const rest = (found.preferredValues ?? []).filter((value) => !keys.has(value))\n update(propertyId, {\n preferredValues: preferred ? [...rest, preferredValue(component)] : rest\n })\n }\n\n return {\n active,\n canCreate,\n slots,\n options,\n create: () => editor.createSlot(),\n rename: (propertyId: string, name: string) => update(propertyId, { name }),\n describe: (propertyId: string, description: string) => update(propertyId, { description }),\n setLimits: (propertyId: string, limits: { minChildren?: number; maxChildren?: number }) =>\n update(propertyId, { slotSettings: limits }),\n setPreferredOnly: (propertyId: string, value: boolean) =>\n update(propertyId, { slotSettings: { allowPreferredValuesOnly: value } }),\n setPreferred,\n remove: (propertyId: string) => {\n const owner = target.value?.owner\n if (owner) editor.removeSlot(owner.id, propertyId)\n }\n }\n}\n"],"mappings":";;;;;;AA0BA,SAAS,eAAe,WAA8B;CACpD,OAAO,UAAU,gBAAgB,UAAU;AAC7C;;;;;AAMA,SAAgB,mBAAmB;CACjC,MAAM,SAAS,UAAU;CACzB,MAAM,SAAS,uBAAuB;EACpC,MAAM,QAAQ,OAAO,iBAAiB;EACtC,IAAI,MAAM,WAAW,GAAG,OAAO,KAAA;EAC/B,MAAM,CAAC,QAAQ;EACf,IAAI,KAAK,SAAS,aAAa,OAAO;GAAE,OAAO;GAAM,OAAO,KAAA;GAAW,YAAY,KAAA;EAAU;EAC7F,MAAM,QAAQ,UAAU,OAAO,OAAO,IAAI;EAC1C,IAAI,CAAC,OAAO,OAAO,KAAA;EACnB,MAAM,aAAa,eAAe,IAAI;EACtC,IAAI,CAAC,cAAc,CAAC,cAAc,O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YAAY,OAAO,MAAM,QAAQ,WAAW;EAClD,IAAI,CAAC,SAAS,CAAC,WAAW;EAC1B,MAAM,uBAAO,IAAI,IAAI;GAAC,UAAU;GAAI,UAAU;GAAc,UAAU;EAAgB,CAAC;EACvF,MAAM,QAAQ,MAAM,mBAAmB,CAAC,EAAA,CAAG,QAAQ,UAAU,CAAC,KAAK,IAAI,KAAK,CAAC;EAC7E,OAAO,YAAY,EACjB,iBAAiB,YAAY,CAAC,GAAG,MAAM,eAAe,SAAS,CAAC,IAAI,KACtE,CAAC;CACH;CAEA,OAAO;EACL;EACA;EACA;EACA;EACA,cAAc,OAAO,WAAW;EAChC,SAAS,YAAoB,SAAiB,OAAO,YAAY,EAAE,KAAK,CAAC;EACzE,WAAW,YAAoB,gBAAwB,OAAO,YAAY,EAAE,YAAY,CAAC;EACzF,YAAY,YAAoB,WAC9B,OAAO,YAAY,EAAE,cAAc,OAAO,CAAC;EAC7C,mBAAmB,YAAoB,UACrC,OAAO,YAAY,EAAE,cAAc,EAAE,0BAA0B,MAAM,EAAE,CAAC;EAC1E;EACA,SAAS,eAAuB;GAC9B,MAAM,QAAQ,OAAO,OAAO;GAC5B,IAAI,OAAO,OAAO,WAAW,MAAM,IAAI,UAAU;EACnD;CACF;AACF"}
1
+ {"version":3,"file":"authoring.js","names":[],"sources":["../../../src/controls/slots/authoring.ts"],"sourcesContent":["import type { ComponentPropertyDefinition, SceneNode } from '@pairdraw/scene-graph'\nimport { propertyOwner } from '@pairdraw/scene-graph/components'\nimport {\n canCreateSlot,\n slotOwner,\n slotPropertyId,\n type SlotPropertyPatch\n} from '@pairdraw/scene-graph/slots'\n\nimport { useEditor } from '#vue/editor/context'\nimport { useSceneComputed } from '#vue/internal/scene-computed/use'\n\nimport { slotInstanceOptions, type SlotInstanceOption } from './instance'\n\n/** A slot property as its main component defines it. */\nexport interface SlotDefinitionControl {\n id: string\n name: string\n description: string\n minChildren?: number\n maxChildren?: number\n preferredOnly: boolean\n /** Components the slot prefers, resolved from the definition's preferred values. */\n preferred: SlotInstanceOption[]\n}\n\n/** The value a preferred-components list stores for a component: its key, else its id. */\nfunction preferredValue(component: SceneNode): string {\n return component.componentKey ?? component.id\n}\n\n/**\n * Slot properties of the selected main component or slot frame, with the actions that\n * create, configure, and remove them.\n */\nexport function useSlotAuthoring() {\n const editor = useEditor()\n const target = useSceneComputed(() => {\n const nodes = editor.getSelectedNodes()\n if (nodes.length !== 1) return undefined\n const [node] = nodes\n if (node.type === 'COMPONENT')\n return { owner: propertyOwner(editor.graph, node), frame: undefined, propertyId: undefined }\n const owner = slotOwner(editor.graph, node)\n if (!owner) return undefined\n const propertyId = slotPropertyId(node)\n if (!propertyId && !canCreateSlot(editor.graph, node)) return undefined\n return { owner, frame: node, propertyId }\n })\n const slots = useSceneComputed<SlotDefinitionControl[]>(() => {\n const current = target.value\n if (!current) return []\n return current.owner.componentPropertyDefinitions\n .filter((definition) => definition.type === 'SLOT')\n .filter((definition) => !current.frame || definition.id === current.propertyId)\n .map((definition) => {\n const values = new Set(definition.preferredValues)\n return {\n id: definition.id,\n name: definition.name,\n description: definition.description ?? '',\n minChildren: definition.slotSettings?.minChildren,\n maxChildren: definition.slotSettings?.maxChildren,\n preferredOnly: definition.slotSettings?.allowPreferredValuesOnly ?? false,\n preferred: slotInstanceOptions(editor.graph, definition).filter(\n (option) => option.preferred && values.size > 0\n )\n }\n })\n })\n /** Whether the selection is a frame that can become a slot. */\n const canCreate = useSceneComputed(() => !!target.value?.frame && !target.value.propertyId)\n const active = useSceneComputed(() => slots.value.length > 0 || canCreate.value)\n\n function update(propertyId: string, patch: SlotPropertyPatch) {\n const owner = target.value?.owner\n if (owner) editor.updateSlot(owner.id, propertyId, patch)\n }\n\n function definition(propertyId: string): ComponentPropertyDefinition | undefined {\n return target.value?.owner.componentPropertyDefinitions.find((item) => item.id === propertyId)\n }\n\n /** Components that can be marked preferred, the slot's current choices first. */\n function options(propertyId: string): SlotInstanceOption[] {\n const found = definition(propertyId)\n return found ? slotInstanceOptions(editor.graph, found) : []\n }\n\n function setPreferred(propertyId: string, componentId: string, preferred: boolean) {\n const found = definition(propertyId)\n const component = editor.graph.getNode(componentId)\n if (!found || !component) return\n const keys = new Set([component.id, component.componentKey, component.sourceLibraryKey])\n const rest = (found.preferredValues ?? []).filter((value) => !keys.has(value))\n update(propertyId, {\n preferredValues: preferred ? [...rest, preferredValue(component)] : rest\n })\n }\n\n return {\n active,\n canCreate,\n slots,\n options,\n create: () => editor.createSlot(),\n rename: (propertyId: string, name: string) => update(propertyId, { name }),\n describe: (propertyId: string, description: string) => update(propertyId, { description }),\n setLimits: (propertyId: string, limits: { minChildren?: number; maxChildren?: number }) =>\n update(propertyId, { slotSettings: limits }),\n setPreferredOnly: (propertyId: string, value: boolean) =>\n update(propertyId, { slotSettings: { allowPreferredValuesOnly: value } }),\n setPreferred,\n remove: (propertyId: string) => {\n const owner = target.value?.owner\n if (owner) editor.removeSlot(owner.id, propertyId)\n }\n }\n}\n"],"mappings":";;;;;;;AA2BA,SAAS,eAAe,WAA8B;CACpD,OAAO,UAAU,gBAAgB,UAAU;AAC7C;;;;;AAMA,SAAgB,mBAAmB;CACjC,MAAM,SAAS,UAAU;CACzB,MAAM,SAAS,uBAAuB;EACpC,MAAM,QAAQ,OAAO,iBAAiB;EACtC,IAAI,MAAM,WAAW,GAAG,OAAO,KAAA;EAC/B,MAAM,CAAC,QAAQ;EACf,IAAI,KAAK,SAAS,aAChB,OAAO;GAAE,OAAO,cAAc,OAAO,OAAO,IAAI;GAAG,OAAO,KAAA;GAAW,YAAY,KAAA;EAAU;EAC7F,MAAM,QAAQ,UAAU,OAAO,OAAO,IAAI;EAC1C,IAAI,CAAC,OAAO,OAAO,KAAA;EACnB,MAAM,aAAa,eAAe,IAAI;EACtC,IAAI,CAAC,cAAc,CAAC,cAAc,OAAO,OAAO,IAAI,GAAG,OAAO,KAAA;EAC9D,OAAO;GAAE;GAAO,OAAO;GAAM;EAAW;CAC1C,CAAC;CACD,MAAM,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AC,UAAU;GAAI,UAAU;GAAc,UAAU;EAAgB,CAAC;EACvF,MAAM,QAAQ,MAAM,mBAAmB,CAAC,EAAA,CAAG,QAAQ,UAAU,CAAC,KAAK,IAAI,KAAK,CAAC;EAC7E,OAAO,YAAY,EACjB,iBAAiB,YAAY,CAAC,GAAG,MAAM,eAAe,SAAS,CAAC,IAAI,KACtE,CAAC;CACH;CAEA,OAAO;EACL;EACA;EACA;EACA;EACA,cAAc,OAAO,WAAW;EAChC,SAAS,YAAoB,SAAiB,OAAO,YAAY,EAAE,KAAK,CAAC;EACzE,WAAW,YAAoB,gBAAwB,OAAO,YAAY,EAAE,YAAY,CAAC;EACzF,YAAY,YAAoB,WAC9B,OAAO,YAAY,EAAE,cAAc,OAAO,CAAC;EAC7C,mBAAmB,YAAoB,UACrC,OAAO,YAAY,EAAE,cAAc,EAAE,0BAA0B,MAAM,EAAE,CAAC;EAC1E;EACA,SAAS,eAAuB;GAC9B,MAAM,QAAQ,OAAO,OAAO;GAC5B,IAAI,OAAO,OAAO,WAAW,MAAM,IAAI,UAAU;EACnD;CACF;AACF"}
@@ -105,7 +105,7 @@ function createTypographyActions({ editor, nodes, activeFormatting, supports, op
105
105
  editor.undo.runBatch(label, () => {
106
106
  for (const target of targets) {
107
107
  if (detach && editor.graph.getNode(target.id)?.boundVariables[detach]) editor.unbindVariable(target.id, detach);
108
- editor.updateNodeWithUndo(target.id, changes(target), label);
108
+ editor.updateNodeWithUndo(target.id, editor.layerChanges(target.id, changes(target)), label);
109
109
  }
110
110
  });
111
111
  }
@@ -304,11 +304,16 @@ function createTypographyActions({ editor, nodes, activeFormatting, supports, op
304
304
  beforePreview.clear();
305
305
  }
306
306
  for (const target of nodes.value) {
307
- if (!beforePreview.has(target.id)) beforePreview.set(target.id, {
308
- value: target[key],
309
- textStyleId: target.textStyleId
310
- });
311
- editor.updateNode(target.id, { [key]: value });
307
+ const own = editor.graph.getNode(target.id) ?? target;
308
+ if (!beforePreview.has(target.id)) {
309
+ const { textStyleId, styleRuns } = own;
310
+ beforePreview.set(target.id, {
311
+ value: own[key],
312
+ textStyleId,
313
+ styleRuns
314
+ });
315
+ }
316
+ editor.updateNode(target.id, editor.layerChanges(target.id, { [key]: value }));
312
317
  }
313
318
  }
314
319
  function commitProp(key, _value, previous) {
@@ -318,9 +323,11 @@ function createTypographyActions({ editor, nodes, activeFormatting, supports, op
318
323
  editor.undo.runBatch(`Change ${String(key)}`, () => {
319
324
  for (const target of targets) {
320
325
  const snapshot = snapshots.get(target.id);
326
+ const ranges = snapshot && editor.state.editingTextId !== target.id ? { styleRuns: snapshot.styleRuns } : {};
321
327
  editor.commitNodeUpdate(target.id, {
322
328
  [key]: snapshot ? snapshot.value : previous,
323
- ...snapshot ? { textStyleId: snapshot.textStyleId } : {}
329
+ ...snapshot ? { textStyleId: snapshot.textStyleId } : {},
330
+ ...ranges
324
331
  }, `Change ${String(key)}`);
325
332
  }
326
333
  });
@@ -330,9 +337,10 @@ function createTypographyActions({ editor, nodes, activeFormatting, supports, op
330
337
  }
331
338
  /** Puts back what a cancelled field previewed, as `cancelAxis` does for a font axis. */
332
339
  function cancelProp(key) {
333
- if (previewKey === key) for (const [id, before] of beforePreview) editor.updateNode(id, {
334
- [key]: before.value,
335
- textStyleId: before.textStyleId
340
+ if (previewKey === key) for (const [id, { value, textStyleId, styleRuns }] of beforePreview) editor.updateNode(id, {
341
+ [key]: value,
342
+ textStyleId,
343
+ styleRuns
336
344
  });
337
345
  previewKey = void 0;
338
346
  beforePreview.clear();
@@ -1 +1 @@
1
- {"version":3,"file":"actions.js","names":[],"sources":["../../../src/controls/typography/actions.ts"],"sourcesContent":["import { computed } from 'vue'\nimport type { ComputedRef } from 'vue'\n\nimport type { Editor } from '@pairdraw/core'\nimport { faceForStyle, fontManager, nearestFamilyFace } from '@pairdraw/core/text'\nimport type {\n SceneNode,\n TextLength,\n TextListType,\n TextParagraphSpacingField\n} from '@pairdraw/scene-graph'\nimport { faceLoadKey, faceStyleKey } from '@pairdraw/scene-graph/font-style'\nimport { shapeWithTextLabel } from '@pairdraw/scene-graph/generated'\n\nimport {\n createTextListActions,\n listTypeOf,\n paragraphSpacingChanges,\n paragraphSpacingOf\n} from '#vue/canvas/text-edit/paragraphs'\nimport { MIXED, type MixedValue } from '#vue/controls/node-props/use'\nimport { styleFontVariations } from '#vue/controls/typography/axes'\nimport { useFamilyFaces } from '#vue/controls/typography/faces'\nimport type { UseTypographyOptions } from '#vue/controls/typography/use'\nimport { useUndoBatch } from '#vue/controls/undo-batch/use'\nimport { selectedNodesAsShown } from '#vue/editor/selection-state/nodes'\nimport { useSceneComputed } from '#vue/internal/scene-computed/use'\nimport { useNodeFontStatus } from '#vue/shared/font-status/use'\n\ntype TextAlign = SceneNode['textAlignHorizontal']\ntype TextDirection = SceneNode['textDirection']\ntype TextVerticalAlign = SceneNode['textAlignVertical']\ntype TextCase = SceneNode['textCase']\ntype TextTruncation = SceneNode['textTruncation']\n/** A value the panel previews and commits on every selected text. */\ntype PropValue = number | string | TextLength | null\n\nfunction sharedValue<T>(values: readonly T[]): MixedValue<T> {\n const [first] = values\n return values.every((value) => value === first) ? first : MIXED\n}\n\n/** The formatting every node has, so a mixed toggle reads as off. */\nfunction sharedFormatting(nodes: readonly SceneNode[]) {\n if (nodes.length === 0) return []\n const result: string[] = []\n if (nodes.every((n) => n.fontWeight >= 700)) result.push('bold')\n if (nodes.every((n) => n.italic)) result.push('italic')\n if (nodes.every((n) => n.textDecoration === 'UNDERLINE')) result.push('underline')\n if (nodes.every((n) => n.textDecoration === 'STRIKETHROUGH')) result.push('strikethrough')\n return result\n}\n\n/** The text a selected layer's typography edits: its own, or a shape with text's label. */\nfunction typographyTargets(editor: Editor): SceneNode[] {\n return selectedNodesAsShown(editor).flatMap((n) => {\n if (n.type === 'TEXT') return [n]\n const label = shapeWithTextLabel(editor.graph, n)\n return label ? [label] : []\n })\n}\n\n/**\n * Typography of the selected text layers and shapes' labels. With other layers selected too,\n * Figma shows the text's typography and edits only the text, so `nodes` holds just the text.\n */\nexport function createTypographyState(editor: Editor) {\n const nodes = useSceneComputed<SceneNode[]>(() => typographyTargets(editor))\n const node = computed<SceneNode | null>(() => nodes.value.at(0) ?? null)\n const { missingFonts, hasMissingFonts } = useNodeFontStatus(() => node.value)\n const fontFamily = computed(() => node.value?.fontFamily ?? '')\n const fontWeight = computed(() => node.value?.fontWeight ?? 400)\n const fontSize = computed(() => node.value?.fontSize ?? 16)\n const { faces, supports, styleName } = useFamilyFaces(nodes)\n const currentWeightLabel = computed(() => (node.value ? styleName(node.value) : 'Regular'))\n /** The face every selected text layer is set in, by its name, or MIXED when they differ. */\n const faceName = computed(() => sharedValue(nodes.value.map((text) => styleName(text))))\n const activeFormatting = computed(() => sharedFormatting(nodes.value))\n /**\n * The list style every selected text shares, or that of the paragraphs being edited; `null`\n * when they differ.\n */\n const listType = computed(() => {\n void editor.state.textSelectionVersion\n const shared = sharedValue(nodes.value.map((n) => listTypeOf(editor, n)))\n return shared === MIXED ? null : shared\n })\n\n /** The value every selected text layer shares, or MIXED when they differ. */\n function merged<K extends keyof SceneNode>(key: K): MixedValue<SceneNode[K]> {\n return sharedValue(nodes.value.map((n) => n[key]))\n }\n\n /** A spacing every paragraph changes apply to shares, or MIXED when they differ. */\n function paragraphSpacing(field: TextParagraphSpacingField): MixedValue<number> {\n void editor.state.textSelectionVersion\n const values = nodes.value.map((n) => paragraphSpacingOf(editor, n, field))\n const shared = sharedValue(values)\n return shared === null ? MIXED : shared\n }\n\n /** Whether one OpenType feature is on for every text layer, MIXED when they differ. */\n function fontFeature(tag: string): MixedValue<boolean> {\n return sharedValue(\n nodes.value.map((n) => n.fontFeatures.find((feature) => feature.tag === tag)?.enabled ?? true)\n )\n }\n\n return {\n node,\n nodes,\n merged,\n paragraphSpacing,\n fontFeature,\n fontFamily,\n fontWeight,\n fontSize,\n currentWeightLabel,\n faceName,\n activeFormatting,\n listType,\n faces,\n supports,\n missingFonts,\n hasMissingFonts\n }\n}\n\ntype TypographyActionOptions = {\n editor: Editor\n nodes: ComputedRef<SceneNode[]>\n activeFormatting: ComputedRef<string[]>\n /** Whether a layer's family has a face; true when nothing says it has not. */\n supports: (node: SceneNode, weight: number, italic: boolean) => boolean\n options: UseTypographyOptions\n}\n\nexport function createTypographyActions({\n editor,\n nodes,\n activeFormatting,\n supports,\n options\n}: TypographyActionOptions) {\n const lists = createTextListActions(editor)\n // A dragged field's previews belong to the step its commit records, so they are not edits of\n // their own that keep the document unsaved after that step is undone.\n const batch = useUndoBatch(editor.undo, () => editor.beginInteractiveEdit())\n type Preview = { value: SceneNode[keyof SceneNode]; textStyleId: string | null }\n let previewKey: keyof SceneNode | undefined\n const beforePreview = new Map<string, Preview>()\n\n /**\n * Applies one change per text layer in one undo step. A field named in `detach` is unbound\n * first in that step, since a value chosen here replaces the variable's, as in Figma.\n */\n function updateEach(\n label: string,\n changes: (node: SceneNode) => Partial<SceneNode>,\n targets = nodes.value,\n detach?: keyof SceneNode\n ) {\n if (targets.length === 0) return\n editor.undo.runBatch(label, () => {\n for (const target of targets) {\n if (detach && editor.graph.getNode(target.id)?.boundVariables[detach])\n editor.unbindVariable(target.id, detach)\n editor.updateNodeWithUndo(target.id, changes(target), label)\n }\n })\n }\n\n function update(label: string, changes: Partial<SceneNode>) {\n updateEach(label, () => changes)\n }\n\n /** The newest pending change for each layer and field, by `id:field`. */\n const latestLoadingRequest = new Map<string, symbol>()\n\n /**\n * Applies each layer's change once its face has loaded, to the layers selected when it was\n * asked for: the selection may change while the load is pending, and a layer may be deleted.\n * `prepare` loads a layer's face and returns its change, or null to leave the layer alone.\n */\n async function updateAfterLoading(\n label: string,\n fields: readonly (keyof SceneNode)[],\n prepare: (target: SceneNode) => Promise<Partial<SceneNode> | null>,\n targets = nodes.value,\n detach?: keyof SceneNode\n ) {\n if (targets.length === 0) return\n const request = Symbol(label)\n const keys = (target: SceneNode) => fields.map((field) => `${target.id}:${field}`)\n for (const target of targets)\n for (const key of keys(target)) latestLoadingRequest.set(key, request)\n const changes = await Promise.all(targets.map(prepare))\n // A later choice for the same field wins, even when its face loaded first.\n const current = targets.filter((target) =>\n keys(target).every((key) => latestLoadingRequest.get(key) === request)\n )\n for (const target of current) for (const key of keys(target)) latestLoadingRequest.delete(key)\n const changed = new Map(targets.map((target, index) => [target.id, changes[index]]))\n const live = current.filter(\n (target) => editor.graph.getNode(target.id) && changed.get(target.id)\n )\n updateEach(label, (target) => changed.get(target.id) ?? {}, live, detach)\n }\n\n /**\n * Keeps each layer's weight and slant where the family has them, otherwise takes the nearest\n * face, as Figma does: Black goes to Bold in a family that ends at Bold. A layer whose family\n * follows a variable is detached from it in the same step, so the next mode switch or variable\n * edit cannot take the chosen family back.\n */\n async function setFamily(family: string) {\n const faces = fontManager.familyFaces(family)\n await updateAfterLoading(\n 'Change font',\n ['fontFamily', 'fontWeight', 'italic'],\n async (target) => {\n await faces\n // Asked again, so faces forgotten while loading (a catalog arriving) are read anew.\n const known = await fontManager.familyFaces(family)\n const face = known ? nearestFamilyFace(known, target.fontWeight, target.italic) : null\n const fontWeight = face?.weight ?? target.fontWeight\n const italic = face?.italic ?? target.italic\n await options.fontLoader?.load(family, faceLoadKey(fontWeight, italic))\n return {\n fontFamily: family,\n fontWeight,\n italic,\n fontVariations: styleFontVariations(target)\n }\n },\n nodes.value,\n 'fontFamily'\n )\n }\n\n /** Loads the face first, as for a family, so the text is laid out once with it. */\n async function setWeight(weight: number, targets = nodes.value) {\n await updateAfterLoading(\n 'Change font weight',\n ['fontWeight'],\n async (target) => {\n await options.fontLoader?.load(target.fontFamily, faceLoadKey(weight, target.italic))\n return { fontWeight: weight, fontVariations: styleFontVariations(target) }\n },\n targets\n )\n }\n\n /**\n * Sets the face `style` names in each layer's family, as the style menu sets one: its weight,\n * slant, and name, loaded first so the text is laid out once with it.\n */\n async function setFace(style: string, targets = nodes.value) {\n await updateAfterLoading(\n 'Change font style',\n ['fontWeight', 'italic', 'fontStyle'],\n async (target) => {\n // The menu lists the faces of the layer's slant, so a name in both slants is that one.\n const face = faceForStyle(target.fontFamily, style, target.italic)\n const fields = { fontWeight: face.weight, italic: face.italic, fontStyle: face.style }\n await options.fontLoader?.load(target.fontFamily, faceStyleKey(fields))\n return { ...fields, fontVariations: styleFontVariations(target) }\n },\n targets\n )\n }\n\n function setAlign(align: TextAlign) {\n update('Change text alignment', { textAlignHorizontal: align })\n }\n\n function setDirection(direction: TextDirection) {\n update('Change text direction', { textDirection: direction })\n }\n\n function setVerticalAlign(align: TextVerticalAlign) {\n update('Change vertical text alignment', { textAlignVertical: align })\n }\n\n function setTextCase(textCase: TextCase) {\n update('Change text case', { textCase })\n }\n\n function setTruncation(textTruncation: TextTruncation) {\n update('Change text truncation', { textTruncation })\n }\n\n function setFontFeature(tag: string, enabled: boolean) {\n updateEach(`Change ${tag} feature`, (target) => ({\n fontFeatures: [\n ...target.fontFeatures.filter((feature) => feature.tag !== tag),\n { tag, enabled }\n ]\n }))\n }\n\n function setListType(listType: TextListType) {\n const targets = nodes.value\n if (targets.length === 0) return\n editor.undo.runBatch('Change list style', () => {\n for (const target of targets) lists.setListType(target, listType)\n })\n }\n\n type SpacingPreview = Pick<SceneNode, TextParagraphSpacingField | 'textParagraphs'>\n let spacingPreviewField: TextParagraphSpacingField | undefined\n const beforeSpacing = new Map<string, SpacingPreview>()\n\n function previewParagraphSpacing(field: TextParagraphSpacingField, value: number) {\n if (spacingPreviewField !== field) {\n restoreSpacingPreview()\n spacingPreviewField = field\n }\n for (const target of nodes.value) {\n if (!beforeSpacing.has(target.id)) {\n const { listSpacing, paragraphSpacing, paragraphIndent, textParagraphs } = target\n beforeSpacing.set(target.id, {\n listSpacing,\n paragraphSpacing,\n paragraphIndent,\n textParagraphs\n })\n }\n editor.updateNode(target.id, paragraphSpacingChanges(editor, target, field, value))\n }\n editor.requestRender()\n }\n\n function restoreSpacingPreview() {\n for (const [id, before] of beforeSpacing) editor.updateNode(id, before)\n beforeSpacing.clear()\n spacingPreviewField = undefined\n }\n\n /**\n * Sets a spacing for the paragraphs being edited, or for whole text layers, in one undo step;\n * while text is edited the change is a step of its own after what was typed.\n */\n function setParagraphSpacing(field: TextParagraphSpacingField, value: number) {\n restoreSpacingPreview()\n const targets = nodes.value\n if (targets.length === 0) return\n const label = `Change ${field}`\n editor.runTextEditStep(() => {\n editor.undo.runBatch(label, () => {\n for (const target of targets) {\n const current = editor.graph.getNode(target.id) ?? target\n editor.updateNodeWithUndo(\n target.id,\n paragraphSpacingChanges(editor, current, field, value),\n label\n )\n }\n })\n })\n editor.requestRender()\n }\n\n function setHangingList(hangingList: boolean) {\n update('Change hanging lists', { hangingList })\n }\n\n /**\n * Bold unless every text layer already is, as Figma's toggle does for a mixed selection. A layer\n * whose family has no such face is left alone, as Figma leaves it.\n */\n function toggleBold() {\n const weight = activeFormatting.value.includes('bold') ? 400 : 700\n void setWeight(\n weight,\n nodes.value.filter((target) => supports(target, weight, target.italic))\n )\n }\n\n function toggleItalic() {\n const italic = !activeFormatting.value.includes('italic')\n void updateAfterLoading(\n 'Toggle italic',\n ['italic'],\n async (target) => {\n await options.fontLoader?.load(target.fontFamily, faceLoadKey(target.fontWeight, italic))\n return { italic, fontVariations: styleFontVariations(target) }\n },\n nodes.value.filter((target) => supports(target, target.fontWeight, italic))\n )\n }\n\n function toggleDecoration(deco: 'UNDERLINE' | 'STRIKETHROUGH') {\n const on = activeFormatting.value.includes(deco.toLowerCase())\n update(`Toggle ${deco.toLowerCase()}`, {\n textDecoration: on ? 'NONE' : deco\n })\n }\n\n function onFormattingChange(values: string[]) {\n const prev = activeFormatting.value\n const added = values.filter((v) => !prev.includes(v))\n const removed = prev.filter((v) => !values.includes(v))\n for (const item of [...added, ...removed]) {\n if (item === 'bold') toggleBold()\n else if (item === 'italic') toggleItalic()\n else if (item === 'underline') toggleDecoration('UNDERLINE')\n else if (item === 'strikethrough') toggleDecoration('STRIKETHROUGH')\n }\n }\n\n function updateProp(key: keyof SceneNode, value: PropValue) {\n batch.ensure(`typography:${String(key)}`, `Change ${String(key)}`)\n if (previewKey !== key) {\n previewKey = key\n beforePreview.clear()\n }\n for (const target of nodes.value) {\n if (!beforePreview.has(target.id))\n beforePreview.set(target.id, { value: target[key], textStyleId: target.textStyleId })\n editor.updateNode(target.id, { [key]: value })\n }\n }\n\n function commitProp(key: keyof SceneNode, _value: PropValue, previous: PropValue) {\n const targets = nodes.value\n if (targets.length === 0) return\n const snapshots = previewKey === key ? beforePreview : new Map<string, Preview>()\n editor.undo.runBatch(`Change ${String(key)}`, () => {\n for (const target of targets) {\n const snapshot = snapshots.get(target.id)\n editor.commitNodeUpdate(\n target.id,\n {\n [key]: snapshot ? snapshot.value : previous,\n ...(snapshot ? { textStyleId: snapshot.textStyleId } : {})\n },\n `Change ${String(key)}`\n )\n }\n })\n previewKey = undefined\n beforePreview.clear()\n batch.flush()\n }\n\n /** Puts back what a cancelled field previewed, as `cancelAxis` does for a font axis. */\n function cancelProp(key: keyof SceneNode) {\n if (previewKey === key) {\n for (const [id, before] of beforePreview)\n editor.updateNode(id, { [key]: before.value, textStyleId: before.textStyleId })\n }\n previewKey = undefined\n beforePreview.clear()\n batch.flush()\n editor.requestRender()\n }\n\n return {\n setFamily,\n setWeight,\n setFace,\n setAlign,\n setDirection,\n setVerticalAlign,\n setTextCase,\n setTruncation,\n setFontFeature,\n setListType,\n previewParagraphSpacing,\n setParagraphSpacing,\n setHangingList,\n toggleBold,\n toggleItalic,\n toggleDecoration,\n onFormattingChange,\n updateProp,\n commitProp,\n cancelProp\n }\n}\n"],"mappings":";;;;;;;;;;;;;AAqCA,SAAS,YAAe,QAAqC;CAC3D,MAAM,CAAC,SAAS;CAChB,OAAO,OAAO,OAAO,UAAU,UAAU,KAAK,IAAI,QAAQ;AAC5D;;AAGA,SAAS,iBAAiB,OAA6B;CACrD,IAAI,MAAM,WAAW,GAAG,OAAO,CAAC;CAChC,MAAM,SAAmB,CAAC;CAC1B,IAAI,MAAM,OAAO,MAAM,EAAE,cAAc,GAAG,GAAG,OAAO,KAAK,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AAM;EACtB;EACA,KAAK,MAAM,UAAU,MAAM,OAAO;GAChC,IAAI,CAAC,cAAc,IAAI,OAAO,EAAE,GAC9B,cAAc,IAAI,OAAO,IAAI;IAAE,OAAO,OAAO;IAAM,aAAa,OAAO;GAAY,CAAC;GACtF,OAAO,WAAW,OAAO,IAAI,GAAG,MAAM,MAAM,CAAC;EAC/C;CACF;CAEA,SAAS,WAAW,KAAsB,QAAmB,UAAqB;EAChF,MAAM,UAAU,MAAM;EACtB,IAAI,QAAQ,WAAW,GAAG;EAC1B,MAAM,YAAY,eAAe,MAAM,gCAAgB,IAAI,IAAqB;EAChF,OAAO,KAAK,SAAS,UAAU,OAAO,GAAG,WAAW;GAClD,KAAK,MAAM,UAAU,SAAS;IAC5B,MAAM,WAAW,UAAU,IAAI,OAAO,EAAE;IACxC,OAAO,iBACL,OAAO,IACP;MACG,MAAM,WAAW,SAAS,QAAQ;KACnC,GAAI,WAAW,EAAE,aAAa,SAAS,YAAY,IAAI,CAAC;IAC1D,GACA,UAAU,OAAO,GAAG,GACtB;GACF;EACF,CAAC;EACD,aAAa,KAAA;EACb,cAAc,MAAM;EACpB,MAAM,MAAM;CACd;;CAGA,SAAS,WAAW,KAAsB;EACxC,IAAI,eAAe,KACjB,KAAK,MAAM,CAAC,IAAI,WAAW,eACzB,OAAO,WAAW,IAAI;IAAG,MAAM,OAAO;GAAO,aAAa,OAAO;EAAY,CAAC;EAElF,aAAa,KAAA;EACb,cAAc,MAAM;EACpB,MAAM,MAAM;EACZ,OAAO,cAAc;CACvB;CAEA,OAAO;EACL;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":"actions.js","names":[],"sources":["../../../src/controls/typography/actions.ts"],"sourcesContent":["import { computed } from 'vue'\nimport type { ComputedRef } from 'vue'\n\nimport type { Editor } from '@pairdraw/core'\nimport { faceForStyle, fontManager, nearestFamilyFace } from '@pairdraw/core/text'\nimport type {\n SceneNode,\n TextLength,\n TextListType,\n TextParagraphSpacingField\n} from '@pairdraw/scene-graph'\nimport { faceLoadKey, faceStyleKey } from '@pairdraw/scene-graph/font-style'\nimport { shapeWithTextLabel } from '@pairdraw/scene-graph/generated'\n\nimport {\n createTextListActions,\n listTypeOf,\n paragraphSpacingChanges,\n paragraphSpacingOf\n} from '#vue/canvas/text-edit/paragraphs'\nimport { MIXED, type MixedValue } from '#vue/controls/node-props/use'\nimport { styleFontVariations } from '#vue/controls/typography/axes'\nimport { useFamilyFaces } from '#vue/controls/typography/faces'\nimport type { UseTypographyOptions } from '#vue/controls/typography/use'\nimport { useUndoBatch } from '#vue/controls/undo-batch/use'\nimport { selectedNodesAsShown } from '#vue/editor/selection-state/nodes'\nimport { useSceneComputed } from '#vue/internal/scene-computed/use'\nimport { useNodeFontStatus } from '#vue/shared/font-status/use'\n\ntype TextAlign = SceneNode['textAlignHorizontal']\ntype TextDirection = SceneNode['textDirection']\ntype TextVerticalAlign = SceneNode['textAlignVertical']\ntype TextCase = SceneNode['textCase']\ntype TextTruncation = SceneNode['textTruncation']\n/** A value the panel previews and commits on every selected text. */\ntype PropValue = number | string | TextLength | null\n\nfunction sharedValue<T>(values: readonly T[]): MixedValue<T> {\n const [first] = values\n return values.every((value) => value === first) ? first : MIXED\n}\n\n/** The formatting every node has, so a mixed toggle reads as off. */\nfunction sharedFormatting(nodes: readonly SceneNode[]) {\n if (nodes.length === 0) return []\n const result: string[] = []\n if (nodes.every((n) => n.fontWeight >= 700)) result.push('bold')\n if (nodes.every((n) => n.italic)) result.push('italic')\n if (nodes.every((n) => n.textDecoration === 'UNDERLINE')) result.push('underline')\n if (nodes.every((n) => n.textDecoration === 'STRIKETHROUGH')) result.push('strikethrough')\n return result\n}\n\n/** The text a selected layer's typography edits: its own, or a shape with text's label. */\nfunction typographyTargets(editor: Editor): SceneNode[] {\n return selectedNodesAsShown(editor).flatMap((n) => {\n if (n.type === 'TEXT') return [n]\n const label = shapeWithTextLabel(editor.graph, n)\n return label ? [label] : []\n })\n}\n\n/**\n * Typography of the selected text layers and shapes' labels. With other layers selected too,\n * Figma shows the text's typography and edits only the text, so `nodes` holds just the text.\n */\nexport function createTypographyState(editor: Editor) {\n const nodes = useSceneComputed<SceneNode[]>(() => typographyTargets(editor))\n const node = computed<SceneNode | null>(() => nodes.value.at(0) ?? null)\n const { missingFonts, hasMissingFonts } = useNodeFontStatus(() => node.value)\n const fontFamily = computed(() => node.value?.fontFamily ?? '')\n const fontWeight = computed(() => node.value?.fontWeight ?? 400)\n const fontSize = computed(() => node.value?.fontSize ?? 16)\n const { faces, supports, styleName } = useFamilyFaces(nodes)\n const currentWeightLabel = computed(() => (node.value ? styleName(node.value) : 'Regular'))\n /** The face every selected text layer is set in, by its name, or MIXED when they differ. */\n const faceName = computed(() => sharedValue(nodes.value.map((text) => styleName(text))))\n const activeFormatting = computed(() => sharedFormatting(nodes.value))\n /**\n * The list style every selected text shares, or that of the paragraphs being edited; `null`\n * when they differ.\n */\n const listType = computed(() => {\n void editor.state.textSelectionVersion\n const shared = sharedValue(nodes.value.map((n) => listTypeOf(editor, n)))\n return shared === MIXED ? null : shared\n })\n\n /** The value every selected text layer shares, or MIXED when they differ. */\n function merged<K extends keyof SceneNode>(key: K): MixedValue<SceneNode[K]> {\n return sharedValue(nodes.value.map((n) => n[key]))\n }\n\n /** A spacing every paragraph changes apply to shares, or MIXED when they differ. */\n function paragraphSpacing(field: TextParagraphSpacingField): MixedValue<number> {\n void editor.state.textSelectionVersion\n const values = nodes.value.map((n) => paragraphSpacingOf(editor, n, field))\n const shared = sharedValue(values)\n return shared === null ? MIXED : shared\n }\n\n /** Whether one OpenType feature is on for every text layer, MIXED when they differ. */\n function fontFeature(tag: string): MixedValue<boolean> {\n return sharedValue(\n nodes.value.map((n) => n.fontFeatures.find((feature) => feature.tag === tag)?.enabled ?? true)\n )\n }\n\n return {\n node,\n nodes,\n merged,\n paragraphSpacing,\n fontFeature,\n fontFamily,\n fontWeight,\n fontSize,\n currentWeightLabel,\n faceName,\n activeFormatting,\n listType,\n faces,\n supports,\n missingFonts,\n hasMissingFonts\n }\n}\n\ntype TypographyActionOptions = {\n editor: Editor\n nodes: ComputedRef<SceneNode[]>\n activeFormatting: ComputedRef<string[]>\n /** Whether a layer's family has a face; true when nothing says it has not. */\n supports: (node: SceneNode, weight: number, italic: boolean) => boolean\n options: UseTypographyOptions\n}\n\nexport function createTypographyActions({\n editor,\n nodes,\n activeFormatting,\n supports,\n options\n}: TypographyActionOptions) {\n const lists = createTextListActions(editor)\n // A dragged field's previews belong to the step its commit records, so they are not edits of\n // their own that keep the document unsaved after that step is undone.\n const batch = useUndoBatch(editor.undo, () => editor.beginInteractiveEdit())\n /** A layer's own values before a preview, with the ranges a preview over the whole text clears. */\n type Preview = Pick<SceneNode, 'textStyleId' | 'styleRuns'> & {\n value: SceneNode[keyof SceneNode]\n }\n let previewKey: keyof SceneNode | undefined\n const beforePreview = new Map<string, Preview>()\n\n /**\n * Applies one change per text layer in one undo step. A field named in `detach` is unbound\n * first in that step, since a value chosen here replaces the variable's, as in Figma.\n */\n function updateEach(\n label: string,\n changes: (node: SceneNode) => Partial<SceneNode>,\n targets = nodes.value,\n detach?: keyof SceneNode\n ) {\n if (targets.length === 0) return\n editor.undo.runBatch(label, () => {\n for (const target of targets) {\n if (detach && editor.graph.getNode(target.id)?.boundVariables[detach])\n editor.unbindVariable(target.id, detach)\n editor.updateNodeWithUndo(target.id, editor.layerChanges(target.id, changes(target)), label)\n }\n })\n }\n\n function update(label: string, changes: Partial<SceneNode>) {\n updateEach(label, () => changes)\n }\n\n /** The newest pending change for each layer and field, by `id:field`. */\n const latestLoadingRequest = new Map<string, symbol>()\n\n /**\n * Applies each layer's change once its face has loaded, to the layers selected when it was\n * asked for: the selection may change while the load is pending, and a layer may be deleted.\n * `prepare` loads a layer's face and returns its change, or null to leave the layer alone.\n */\n async function updateAfterLoading(\n label: string,\n fields: readonly (keyof SceneNode)[],\n prepare: (target: SceneNode) => Promise<Partial<SceneNode> | null>,\n targets = nodes.value,\n detach?: keyof SceneNode\n ) {\n if (targets.length === 0) return\n const request = Symbol(label)\n const keys = (target: SceneNode) => fields.map((field) => `${target.id}:${field}`)\n for (const target of targets)\n for (const key of keys(target)) latestLoadingRequest.set(key, request)\n const changes = await Promise.all(targets.map(prepare))\n // A later choice for the same field wins, even when its face loaded first.\n const current = targets.filter((target) =>\n keys(target).every((key) => latestLoadingRequest.get(key) === request)\n )\n for (const target of current) for (const key of keys(target)) latestLoadingRequest.delete(key)\n const changed = new Map(targets.map((target, index) => [target.id, changes[index]]))\n const live = current.filter(\n (target) => editor.graph.getNode(target.id) && changed.get(target.id)\n )\n updateEach(label, (target) => changed.get(target.id) ?? {}, live, detach)\n }\n\n /**\n * Keeps each layer's weight and slant where the family has them, otherwise takes the nearest\n * face, as Figma does: Black goes to Bold in a family that ends at Bold. A layer whose family\n * follows a variable is detached from it in the same step, so the next mode switch or variable\n * edit cannot take the chosen family back.\n */\n async function setFamily(family: string) {\n const faces = fontManager.familyFaces(family)\n await updateAfterLoading(\n 'Change font',\n ['fontFamily', 'fontWeight', 'italic'],\n async (target) => {\n await faces\n // Asked again, so faces forgotten while loading (a catalog arriving) are read anew.\n const known = await fontManager.familyFaces(family)\n const face = known ? nearestFamilyFace(known, target.fontWeight, target.italic) : null\n const fontWeight = face?.weight ?? target.fontWeight\n const italic = face?.italic ?? target.italic\n await options.fontLoader?.load(family, faceLoadKey(fontWeight, italic))\n return {\n fontFamily: family,\n fontWeight,\n italic,\n fontVariations: styleFontVariations(target)\n }\n },\n nodes.value,\n 'fontFamily'\n )\n }\n\n /** Loads the face first, as for a family, so the text is laid out once with it. */\n async function setWeight(weight: number, targets = nodes.value) {\n await updateAfterLoading(\n 'Change font weight',\n ['fontWeight'],\n async (target) => {\n await options.fontLoader?.load(target.fontFamily, faceLoadKey(weight, target.italic))\n return { fontWeight: weight, fontVariations: styleFontVariations(target) }\n },\n targets\n )\n }\n\n /**\n * Sets the face `style` names in each layer's family, as the style menu sets one: its weight,\n * slant, and name, loaded first so the text is laid out once with it.\n */\n async function setFace(style: string, targets = nodes.value) {\n await updateAfterLoading(\n 'Change font style',\n ['fontWeight', 'italic', 'fontStyle'],\n async (target) => {\n // The menu lists the faces of the layer's slant, so a name in both slants is that one.\n const face = faceForStyle(target.fontFamily, style, target.italic)\n const fields = { fontWeight: face.weight, italic: face.italic, fontStyle: face.style }\n await options.fontLoader?.load(target.fontFamily, faceStyleKey(fields))\n return { ...fields, fontVariations: styleFontVariations(target) }\n },\n targets\n )\n }\n\n function setAlign(align: TextAlign) {\n update('Change text alignment', { textAlignHorizontal: align })\n }\n\n function setDirection(direction: TextDirection) {\n update('Change text direction', { textDirection: direction })\n }\n\n function setVerticalAlign(align: TextVerticalAlign) {\n update('Change vertical text alignment', { textAlignVertical: align })\n }\n\n function setTextCase(textCase: TextCase) {\n update('Change text case', { textCase })\n }\n\n function setTruncation(textTruncation: TextTruncation) {\n update('Change text truncation', { textTruncation })\n }\n\n function setFontFeature(tag: string, enabled: boolean) {\n updateEach(`Change ${tag} feature`, (target) => ({\n fontFeatures: [\n ...target.fontFeatures.filter((feature) => feature.tag !== tag),\n { tag, enabled }\n ]\n }))\n }\n\n function setListType(listType: TextListType) {\n const targets = nodes.value\n if (targets.length === 0) return\n editor.undo.runBatch('Change list style', () => {\n for (const target of targets) lists.setListType(target, listType)\n })\n }\n\n type SpacingPreview = Pick<SceneNode, TextParagraphSpacingField | 'textParagraphs'>\n let spacingPreviewField: TextParagraphSpacingField | undefined\n const beforeSpacing = new Map<string, SpacingPreview>()\n\n function previewParagraphSpacing(field: TextParagraphSpacingField, value: number) {\n if (spacingPreviewField !== field) {\n restoreSpacingPreview()\n spacingPreviewField = field\n }\n for (const target of nodes.value) {\n if (!beforeSpacing.has(target.id)) {\n const { listSpacing, paragraphSpacing, paragraphIndent, textParagraphs } = target\n beforeSpacing.set(target.id, {\n listSpacing,\n paragraphSpacing,\n paragraphIndent,\n textParagraphs\n })\n }\n editor.updateNode(target.id, paragraphSpacingChanges(editor, target, field, value))\n }\n editor.requestRender()\n }\n\n function restoreSpacingPreview() {\n for (const [id, before] of beforeSpacing) editor.updateNode(id, before)\n beforeSpacing.clear()\n spacingPreviewField = undefined\n }\n\n /**\n * Sets a spacing for the paragraphs being edited, or for whole text layers, in one undo step;\n * while text is edited the change is a step of its own after what was typed.\n */\n function setParagraphSpacing(field: TextParagraphSpacingField, value: number) {\n restoreSpacingPreview()\n const targets = nodes.value\n if (targets.length === 0) return\n const label = `Change ${field}`\n editor.runTextEditStep(() => {\n editor.undo.runBatch(label, () => {\n for (const target of targets) {\n const current = editor.graph.getNode(target.id) ?? target\n editor.updateNodeWithUndo(\n target.id,\n paragraphSpacingChanges(editor, current, field, value),\n label\n )\n }\n })\n })\n editor.requestRender()\n }\n\n function setHangingList(hangingList: boolean) {\n update('Change hanging lists', { hangingList })\n }\n\n /**\n * Bold unless every text layer already is, as Figma's toggle does for a mixed selection. A layer\n * whose family has no such face is left alone, as Figma leaves it.\n */\n function toggleBold() {\n const weight = activeFormatting.value.includes('bold') ? 400 : 700\n void setWeight(\n weight,\n nodes.value.filter((target) => supports(target, weight, target.italic))\n )\n }\n\n function toggleItalic() {\n const italic = !activeFormatting.value.includes('italic')\n void updateAfterLoading(\n 'Toggle italic',\n ['italic'],\n async (target) => {\n await options.fontLoader?.load(target.fontFamily, faceLoadKey(target.fontWeight, italic))\n return { italic, fontVariations: styleFontVariations(target) }\n },\n nodes.value.filter((target) => supports(target, target.fontWeight, italic))\n )\n }\n\n function toggleDecoration(deco: 'UNDERLINE' | 'STRIKETHROUGH') {\n const on = activeFormatting.value.includes(deco.toLowerCase())\n update(`Toggle ${deco.toLowerCase()}`, {\n textDecoration: on ? 'NONE' : deco\n })\n }\n\n function onFormattingChange(values: string[]) {\n const prev = activeFormatting.value\n const added = values.filter((v) => !prev.includes(v))\n const removed = prev.filter((v) => !values.includes(v))\n for (const item of [...added, ...removed]) {\n if (item === 'bold') toggleBold()\n else if (item === 'italic') toggleItalic()\n else if (item === 'underline') toggleDecoration('UNDERLINE')\n else if (item === 'strikethrough') toggleDecoration('STRIKETHROUGH')\n }\n }\n\n function updateProp(key: keyof SceneNode, value: PropValue) {\n batch.ensure(`typography:${String(key)}`, `Change ${String(key)}`)\n if (previewKey !== key) {\n previewKey = key\n beforePreview.clear()\n }\n for (const target of nodes.value) {\n // The panel shows a text's characters' style, so what it replaces is read from the layer.\n const own = editor.graph.getNode(target.id) ?? target\n if (!beforePreview.has(target.id)) {\n const { textStyleId, styleRuns } = own\n beforePreview.set(target.id, { value: own[key], textStyleId, styleRuns })\n }\n editor.updateNode(target.id, editor.layerChanges(target.id, { [key]: value }))\n }\n }\n\n function commitProp(key: keyof SceneNode, _value: PropValue, previous: PropValue) {\n const targets = nodes.value\n if (targets.length === 0) return\n const snapshots = previewKey === key ? beforePreview : new Map<string, Preview>()\n editor.undo.runBatch(`Change ${String(key)}`, () => {\n for (const target of targets) {\n const snapshot = snapshots.get(target.id)\n // While text is edited, the editor records the selected characters' ranges itself.\n const ranges =\n snapshot && editor.state.editingTextId !== target.id\n ? { styleRuns: snapshot.styleRuns }\n : {}\n editor.commitNodeUpdate(\n target.id,\n {\n [key]: snapshot ? snapshot.value : previous,\n ...(snapshot ? { textStyleId: snapshot.textStyleId } : {}),\n ...ranges\n },\n `Change ${String(key)}`\n )\n }\n })\n previewKey = undefined\n beforePreview.clear()\n batch.flush()\n }\n\n /** Puts back what a cancelled field previewed, as `cancelAxis` does for a font axis. */\n function cancelProp(key: keyof SceneNode) {\n if (previewKey === key) {\n for (const [id, { value, textStyleId, styleRuns }] of beforePreview)\n editor.updateNode(id, { [key]: value, textStyleId, styleRuns })\n }\n previewKey = undefined\n beforePreview.clear()\n batch.flush()\n editor.requestRender()\n }\n\n return {\n setFamily,\n setWeight,\n setFace,\n setAlign,\n setDirection,\n setVerticalAlign,\n setTextCase,\n setTruncation,\n setFontFeature,\n setListType,\n previewParagraphSpacing,\n setParagraphSpacing,\n setHangingList,\n toggleBold,\n toggleItalic,\n toggleDecoration,\n onFormattingChange,\n updateProp,\n commitProp,\n cancelProp\n }\n}\n"],"mappings":";;;;;;;;;;;;;AAqCA,SAAS,YAAe,QAAqC;CAC3D,MAAM,CAAC,SAAS;CAChB,OAAO,OAAO,OAAO,UAAU,UAAU,KAAK,IAAI,QAAQ;AAC5D;;AAGA,SAAS,iBAAiB,OAA6B;CACrD,IAAI,MAAM,WAAW,GAAG,OAAO,CAAC;CAChC,MAAM,SAAmB,CAAC;CAC1B,IAAI,MAAM,OAAO,MAAM,EAAE,cAAc,GAAG,GAAG,OAAO,KAAK,MAAM;CAC/D,IAAI,MAAM,OAAO,MAAM,EAAE,MAAM,GAAG,OAAO,KAAK,QAAQ;CACtD,IAAI,MAAM,OAAO,MAAM,EAAE,mBAAmB,WAAW,GAAG,OAAO,KAAK,WAAW;CACjF,IAAI,MAAM,OAAO,MAAM,EAAE,mBAAmB,eAAe,GAAG,OAAO,KAAK,eAAe;CACzF,OAAO;AACT;;AAGA,SAAS,kBAAkB,QAA6B;CACtD,OAAO,qBAAqB,MAAM,CAAC,CAAC,SAAS,MAAM;EACjD,IAAI,EAAE,SAAS,QAAQ,OAAO,CAAC,CAAC;EAChC,MAAM,QAAQ,mBAAmB,OAAO,OAAO,CAAC;EAChD,OAAO,QAAQ,CAAC,KAAK,IAAI,CAAC;CAC5B,CAAC;AACH;;;;;AAMA,SAAgB,sBAAsB,QAAgB;CACpD,MAAM,QAAQ,uBAAoC,kBAAkB,MAAM,CAAC;CAC3E,MAAM,OAAO,eAAiC,MAAM,MAAM,GAAG,CAAC,KAAK,IAAI;CACvE,MAAM,EAAE,cAAc,oBAAoB,wBAAwB,KAAK,KAAK;CAC5E,MAAM,aAAa,eAAe,KAAK,OAAO,cAAc,EAAE;CAC9D,MAAM,aAAa,eAAe,KAAK,OAAO,cAAc,GAAG;CAC/D,MAAM,WAAW,eAAe,KAAK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AQ;KACnC,GAAI,WAAW,EAAE,aAAa,SAAS,YAAY,IAAI,CAAC;KACxD,GAAG;IACL,GACA,UAAU,OAAO,GAAG,GACtB;GACF;EACF,CAAC;EACD,aAAa,KAAA;EACb,cAAc,MAAM;EACpB,MAAM,MAAM;CACd;;CAGA,SAAS,WAAW,KAAsB;EACxC,IAAI,eAAe,KACjB,KAAK,MAAM,CAAC,IAAI,EAAE,OAAO,aAAa,gBAAgB,eACpD,OAAO,WAAW,IAAI;IAAG,MAAM;GAAO;GAAa;EAAU,CAAC;EAElE,aAAa,KAAA;EACb,cAAc,MAAM;EACpB,MAAM,MAAM;EACZ,OAAO,cAAc;CACvB;CAEA,OAAO;EACL;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;CACF;AACF"}
@@ -1 +1 @@
1
- {"version":3,"file":"axes.d.ts","names":[],"sources":["../../../src/controls/typography/axes.ts"],"mappings":";;;;;;;UAUiB,uBAAuB,KAAK;EAC3C,OAAO"}
1
+ {"version":3,"file":"axes.d.ts","names":[],"sources":["../../../src/controls/typography/axes.ts"],"mappings":";;;;;;;UAYiB,uBAAuB,KAAK;EAC3C,OAAO"}
@@ -2,6 +2,8 @@ import { MIXED } from "../node-props/helpers.js";
2
2
  import { useUndoBatch } from "../undo-batch/use.js";
3
3
  import { computed } from "vue";
4
4
  import { drawnFontAxes } from "@pairdraw/core/canvas";
5
+ import { layerTextStyleChanges } from "@pairdraw/core/text";
6
+ import { omit } from "es-toolkit/object";
5
7
  //#region src/controls/typography/axes.ts
6
8
  const OPTICAL_SIZE = "opsz";
7
9
  function drawnAxes(node) {
@@ -22,14 +24,35 @@ function styleFontVariations(node) {
22
24
  if (node.opticalSizeFromFontSize) return [];
23
25
  return node.fontVariations.filter(({ axis }) => axis === OPTICAL_SIZE);
24
26
  }
25
- /** The text's axes with `axis` set to `value`; an optical size set by hand no longer follows the size. */
26
- function axisChanges(node, axis, value) {
27
+ /** `axis` set to `value`; an optical size set by hand no longer follows the size. */
28
+ function setAxisEdit(axis, value) {
27
29
  return {
28
- fontVariations: [...node.fontVariations.filter((variation) => variation.axis !== axis), {
30
+ variations: (variations) => [...variations.filter((variation) => variation.axis !== axis), {
29
31
  axis,
30
32
  value
31
33
  }],
32
- ...axis === OPTICAL_SIZE ? { opticalSizeFromFontSize: false } : {}
34
+ ...axis === OPTICAL_SIZE ? { changes: { opticalSizeFromFontSize: false } } : {}
35
+ };
36
+ }
37
+ /**
38
+ * An axis edit on a whole text: on its own axes and on each range's, so a range keeps the other
39
+ * axes it sets, as it keeps its other styles.
40
+ */
41
+ function wholeTextAxisChanges(node, edit) {
42
+ const styleRuns = node.styleRuns.map((run) => run.style.fontVariations ? {
43
+ ...run,
44
+ style: {
45
+ ...run.style,
46
+ fontVariations: edit.variations(run.style.fontVariations)
47
+ }
48
+ } : run);
49
+ return {
50
+ styleRuns,
51
+ ...layerTextStyleChanges({
52
+ ...node,
53
+ styleRuns
54
+ }, edit.changes ?? {}),
55
+ fontVariations: edit.variations(node.fontVariations)
33
56
  };
34
57
  }
35
58
  /**
@@ -60,32 +83,50 @@ function createTypographyAxes(editor, nodes) {
60
83
  });
61
84
  const beforePreview = /* @__PURE__ */ new Map();
62
85
  const batch = useUndoBatch(editor.undo, () => editor.beginInteractiveEdit());
63
- function previewEach(changes) {
86
+ /**
87
+ * Previews `edit` on every selected text: while text is edited the editor applies it to the
88
+ * selected characters, whose style the panel shows; otherwise to the whole text.
89
+ */
90
+ function previewEach(edit) {
64
91
  batch.ensure("typography:axes", "Change font axes");
65
92
  for (const target of nodes.value) {
93
+ const own = editor.graph.getNode(target.id) ?? target;
66
94
  if (!beforePreview.has(target.id)) {
67
- const { fontVariations, opticalSizeFromFontSize } = target;
95
+ const { fontVariations, opticalSizeFromFontSize, styleRuns, textStyleId } = own;
68
96
  beforePreview.set(target.id, {
69
97
  fontVariations,
70
- opticalSizeFromFontSize
98
+ opticalSizeFromFontSize,
99
+ styleRuns,
100
+ textStyleId
71
101
  });
72
102
  }
73
- editor.updateNode(target.id, changes(target));
103
+ const axisEdit = edit(target);
104
+ editor.updateNode(target.id, editor.state.editingTextId === target.id ? {
105
+ fontVariations: axisEdit.variations(target.fontVariations),
106
+ ...axisEdit.changes
107
+ } : wholeTextAxisChanges(own, axisEdit));
74
108
  }
75
109
  editor.requestRender();
76
110
  }
77
111
  function commitPreview(label) {
78
112
  editor.undo.runBatch(label, () => {
79
- for (const [id, before] of beforePreview) editor.commitNodeUpdate(id, before, label);
113
+ for (const [id, before] of beforePreview) {
114
+ const values = omit(before, ["textStyleId"]);
115
+ const edited = editor.state.editingTextId === id;
116
+ editor.commitNodeUpdate(id, edited ? omit(values, ["styleRuns"]) : values, label);
117
+ }
80
118
  });
81
119
  beforePreview.clear();
82
120
  batch.flush();
83
121
  }
84
122
  /** Draws the text at `value` on `axis` while it is dragged or typed. */
85
123
  function previewAxis(axis, value) {
86
- previewEach((node) => axisChanges(node, axis, value));
124
+ previewEach(() => setAxisEdit(axis, value));
87
125
  }
88
- /** Puts back the axes a cancelled edit previewed. */
126
+ /**
127
+ * Puts back the axes and ranges a cancelled edit previewed. The text style it names goes back
128
+ * too, so the editor restores the layer rather than styling selected characters with it.
129
+ */
89
130
  function cancelAxis() {
90
131
  for (const [id, before] of beforePreview) editor.updateNode(id, before);
91
132
  beforePreview.clear();
@@ -102,15 +143,17 @@ function createTypographyAxes(editor, nodes) {
102
143
  * Figma's "Set optical size automatically" does.
103
144
  */
104
145
  function setOpticalSizeAuto(auto) {
105
- previewEach((node) => {
106
- const drawn = drawnAxes(node)?.find((axis) => axis.tag === OPTICAL_SIZE);
107
- const rest = node.fontVariations.filter(({ axis }) => axis !== OPTICAL_SIZE);
146
+ previewEach((shown) => {
147
+ const drawn = drawnAxes(shown)?.find((axis) => axis.tag === OPTICAL_SIZE);
108
148
  return {
109
- opticalSizeFromFontSize: auto,
110
- fontVariations: auto || !drawn ? rest : [...rest, {
111
- axis: OPTICAL_SIZE,
112
- value: drawn.value
113
- }]
149
+ variations: (variations) => {
150
+ const rest = variations.filter(({ axis }) => axis !== OPTICAL_SIZE);
151
+ return auto || !drawn ? rest : [...rest, {
152
+ axis: OPTICAL_SIZE,
153
+ value: drawn.value
154
+ }];
155
+ },
156
+ changes: { opticalSizeFromFontSize: auto }
114
157
  };
115
158
  });
116
159
  commitPreview("Change optical size");
@@ -1 +1 @@
1
- {"version":3,"file":"axes.js","names":[],"sources":["../../../src/controls/typography/axes.ts"],"sourcesContent":["import { computed, type ComputedRef } from 'vue'\n\nimport type { Editor } from '@pairdraw/core'\nimport { drawnFontAxes, type DrawnFontAxis } from '@pairdraw/core/canvas'\nimport type { FontVariation, SceneNode } from '@pairdraw/scene-graph'\n\nimport { MIXED, type MixedValue } from '#vue/controls/node-props/use'\nimport { useUndoBatch } from '#vue/controls/undo-batch/use'\n\n/** An axis of the selected text's variable font, with the value every layer draws it at. */\nexport interface TypographyAxis extends Omit<DrawnFontAxis, 'value'> {\n value: MixedValue<number>\n}\n\nconst OPTICAL_SIZE = 'opsz'\n\nfunction drawnAxes(node: SceneNode): DrawnFontAxis[] | null {\n return drawnFontAxes({\n family: node.fontFamily,\n weight: node.fontWeight,\n italic: node.italic,\n fontSize: node.fontSize,\n variations: node.fontVariations,\n opticalSizeFromFontSize: node.opticalSizeFromFontSize\n })\n}\n\n/**\n * The axes a text keeps when it changes style, as a named style draws at its own: none, except an\n * optical size set by hand, which stays set by hand.\n */\nexport function styleFontVariations(node: SceneNode): FontVariation[] {\n if (node.opticalSizeFromFontSize) return []\n return node.fontVariations.filter(({ axis }) => axis === OPTICAL_SIZE)\n}\n\n/** The text's axes with `axis` set to `value`; an optical size set by hand no longer follows the size. */\nfunction axisChanges(node: SceneNode, axis: string, value: number): Partial<SceneNode> {\n return {\n fontVariations: [\n ...node.fontVariations.filter((variation) => variation.axis !== axis),\n { axis, value }\n ],\n ...(axis === OPTICAL_SIZE ? { opticalSizeFromFontSize: false } : {})\n }\n}\n\n/**\n * The variation axes of the selected text layers' font, as Figma's Variable type settings list\n * them, and actions that set them. Layers in different families or slants have no shared axes.\n */\nexport function createTypographyAxes(editor: Editor, nodes: ComputedRef<SceneNode[]>) {\n const axes = computed<TypographyAxis[]>(() => {\n const first = nodes.value.at(0)\n if (!first) return []\n const same = nodes.value.every(\n (node) => node.fontFamily === first.fontFamily && node.italic === first.italic\n )\n if (!same) return []\n const perNode = nodes.value.map(drawnAxes)\n const axesOfFirst = perNode.at(0)\n if (!axesOfFirst || perNode.some((drawn) => !drawn)) return []\n return axesOfFirst.map((axis, index) => {\n const values = perNode.map((drawn) => drawn?.[index]?.value)\n return { ...axis, value: values.every((value) => value === axis.value) ? axis.value : MIXED }\n })\n })\n\n /** Whether the optical size follows the font size on every layer, MIXED when they differ. */\n const opticalSizeAuto = computed<MixedValue<boolean>>(() => {\n const first = nodes.value.at(0)\n if (!first) return MIXED\n return nodes.value.every(\n (node) => node.opticalSizeFromFontSize === first.opticalSizeFromFontSize\n )\n ? first.opticalSizeFromFontSize\n : MIXED\n })\n\n // A drag or a typed value is previewed, then committed as one undo step from the values it\n // started at, as the other typography fields are. While text is edited, the editor applies\n // both to the selected characters, and records the step with what was typed.\n type AxisValues = Pick<SceneNode, 'fontVariations' | 'opticalSizeFromFontSize'>\n const beforePreview = new Map<string, AxisValues>()\n // The previews belong to the step the commit records, so undoing it leaves nothing unsaved.\n const batch = useUndoBatch(editor.undo, () => editor.beginInteractiveEdit())\n\n function previewEach(changes: (node: SceneNode) => Partial<SceneNode>) {\n batch.ensure('typography:axes', 'Change font axes')\n for (const target of nodes.value) {\n if (!beforePreview.has(target.id)) {\n const { fontVariations, opticalSizeFromFontSize } = target\n beforePreview.set(target.id, { fontVariations, opticalSizeFromFontSize })\n }\n editor.updateNode(target.id, changes(target))\n }\n editor.requestRender()\n }\n\n function commitPreview(label: string) {\n editor.undo.runBatch(label, () => {\n for (const [id, before] of beforePreview) editor.commitNodeUpdate(id, before, label)\n })\n beforePreview.clear()\n batch.flush()\n }\n\n /** Draws the text at `value` on `axis` while it is dragged or typed. */\n function previewAxis(axis: string, value: number) {\n previewEach((node) => axisChanges(node, axis, value))\n }\n\n /** Puts back the axes a cancelled edit previewed. */\n function cancelAxis() {\n for (const [id, before] of beforePreview) editor.updateNode(id, before)\n beforePreview.clear()\n batch.flush()\n editor.requestRender()\n }\n\n /** Sets `axis` to `value` on every selected text layer in one undo step. */\n function setAxis(axis: string, value: number) {\n previewAxis(axis, value)\n commitPreview(`Change ${axis} axis`)\n }\n\n /**\n * Lets the optical size follow the font size, or holds it at the size it is drawn at now, as\n * Figma's \"Set optical size automatically\" does.\n */\n function setOpticalSizeAuto(auto: boolean) {\n previewEach((node) => {\n const drawn = drawnAxes(node)?.find((axis) => axis.tag === OPTICAL_SIZE)\n const rest = node.fontVariations.filter(({ axis }) => axis !== OPTICAL_SIZE)\n const fontVariations =\n auto || !drawn ? rest : [...rest, { axis: OPTICAL_SIZE, value: drawn.value }]\n return { opticalSizeFromFontSize: auto, fontVariations }\n })\n commitPreview('Change optical size')\n }\n\n return {\n axes,\n opticalSizeAuto,\n previewAxis,\n cancelAxis,\n setAxis,\n setOpticalSizeAuto\n }\n}\n"],"mappings":";;;;;AAcA,MAAM,eAAe;AAErB,SAAS,UAAU,MAAyC;CAC1D,OAAO,cAAc;EACnB,QAAQ,KAAK;EACb,QAAQ,KAAK;EACb,QAAQ,KAAK;EACb,UAAU,KAAK;EACf,YAAY,KAAK;EACjB,yBAAyB,KAAK;CAChC,CAAC;AACH;;;;;AAMA,SAAgB,oBAAoB,MAAkC;CACpE,IAAI,KAAK,yBAAyB,OAAO,CAAC;CAC1C,OAAO,KAAK,eAAe,QAAQ,EAAE,WAAW,SAAS,YAAY;AACvE;;AAGA,SAAS,YAAY,MAAiB,MAAc,OAAmC;CACrF,OAAO;EACL,gBAAgB,CACd,GAAG,KAAK,eAAe,QAAQ,cAAc,UAAU,SAAS,IAAI,GACpE;GAAE;GAAM;EAA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GAC1E;GACA,OAAO,WAAW,OAAO,IAAI,QAAQ,MAAM,CAAC;EAC9C;EACA,OAAO,cAAc;CACvB;CAEA,SAAS,cAAc,OAAe;EACpC,OAAO,KAAK,SAAS,aAAa;GAChC,KAAK,MAAM,CAAC,IAAI,WAAW,eAAe,OAAO,iBAAiB,IAAI,QAAQ,KAAK;EACrF,CAAC;EACD,cAAc,MAAM;EACpB,MAAM,MAAM;CACd;;CAGA,SAAS,YAAY,MAAc,OAAe;EAChD,aAAa,SAAS,YAAY,MAAM,MAAM,KAAK,CAAC;CACtD;;CAGA,SAAS,aAAa;EACpB,KAAK,MAAM,CAAC,IAAI,WAAW,eAAe,OAAO,WAAW,IAAI,MAAM;EACtE,cAAc,MAAM;EACpB,MAAM,MAAM;EACZ,OAAO,cAAc;CACvB;;CAGA,SAAS,QAAQ,MAAc,OAAe;EAC5C,YAAY,MAAM,KAAK;EACvB,cAAc,UAAU,KAAK,MAAM;CACrC;;;;;CAMA,SAAS,mBAAmB,MAAe;EACzC,aAAa,SAAS;GACpB,MAAM,QAAQ,UAAU,IAAI,CAAC,EAAE,MAAM,SAAS,KAAK,QAAQ,YAAY;GACvE,MAAM,OAAO,KAAK,eAAe,QAAQ,EAAE,WAAW,SAAS,YAAY;GAG3E,OAAO;IAAE,yBAAyB;IAAM,gBADtC,QAAQ,CAAC,QAAQ,OAAO,CAAC,GAAG,MAAM;KAAE,MAAM;KAAc,OAAO,MAAM;IAAM,CAAC;GACvB;EACzD,CAAC;EACD,cAAc,qBAAqB;CACrC;CAEA,OAAO;EACL;EACA;EACA;EACA;EACA;EACA;CACF;AACF"}
1
+ {"version":3,"file":"axes.js","names":[],"sources":["../../../src/controls/typography/axes.ts"],"sourcesContent":["import { omit } from 'es-toolkit/object'\nimport { computed, type ComputedRef } from 'vue'\n\nimport type { Editor } from '@pairdraw/core'\nimport { drawnFontAxes, type DrawnFontAxis } from '@pairdraw/core/canvas'\nimport { layerTextStyleChanges } from '@pairdraw/core/text'\nimport type { FontVariation, SceneNode } from '@pairdraw/scene-graph'\n\nimport { MIXED, type MixedValue } from '#vue/controls/node-props/use'\nimport { useUndoBatch } from '#vue/controls/undo-batch/use'\n\n/** An axis of the selected text's variable font, with the value every layer draws it at. */\nexport interface TypographyAxis extends Omit<DrawnFontAxis, 'value'> {\n value: MixedValue<number>\n}\n\nconst OPTICAL_SIZE = 'opsz'\n\nfunction drawnAxes(node: SceneNode): DrawnFontAxis[] | null {\n return drawnFontAxes({\n family: node.fontFamily,\n weight: node.fontWeight,\n italic: node.italic,\n fontSize: node.fontSize,\n variations: node.fontVariations,\n opticalSizeFromFontSize: node.opticalSizeFromFontSize\n })\n}\n\n/**\n * The axes a text keeps when it changes style, as a named style draws at its own: none, except an\n * optical size set by hand, which stays set by hand.\n */\nexport function styleFontVariations(node: SceneNode): FontVariation[] {\n if (node.opticalSizeFromFontSize) return []\n return node.fontVariations.filter(({ axis }) => axis === OPTICAL_SIZE)\n}\n\n/** A change to one axis: how it rewrites a list of axes, and what else it sets on the text. */\ninterface AxisEdit {\n variations: (variations: FontVariation[]) => FontVariation[]\n changes?: Pick<Partial<SceneNode>, 'opticalSizeFromFontSize'>\n}\n\n/** `axis` set to `value`; an optical size set by hand no longer follows the size. */\nfunction setAxisEdit(axis: string, value: number): AxisEdit {\n return {\n variations: (variations) => [\n ...variations.filter((variation) => variation.axis !== axis),\n { axis, value }\n ],\n ...(axis === OPTICAL_SIZE ? { changes: { opticalSizeFromFontSize: false } } : {})\n }\n}\n\n/**\n * An axis edit on a whole text: on its own axes and on each range's, so a range keeps the other\n * axes it sets, as it keeps its other styles.\n */\nfunction wholeTextAxisChanges(node: SceneNode, edit: AxisEdit): Partial<SceneNode> {\n const styleRuns = node.styleRuns.map((run) =>\n run.style.fontVariations\n ? {\n ...run,\n style: { ...run.style, fontVariations: edit.variations(run.style.fontVariations) }\n }\n : run\n )\n return {\n styleRuns,\n ...layerTextStyleChanges({ ...node, styleRuns }, edit.changes ?? {}),\n fontVariations: edit.variations(node.fontVariations)\n }\n}\n\n/**\n * The variation axes of the selected text layers' font, as Figma's Variable type settings list\n * them, and actions that set them. Layers in different families or slants have no shared axes.\n */\nexport function createTypographyAxes(editor: Editor, nodes: ComputedRef<SceneNode[]>) {\n const axes = computed<TypographyAxis[]>(() => {\n const first = nodes.value.at(0)\n if (!first) return []\n const same = nodes.value.every(\n (node) => node.fontFamily === first.fontFamily && node.italic === first.italic\n )\n if (!same) return []\n const perNode = nodes.value.map(drawnAxes)\n const axesOfFirst = perNode.at(0)\n if (!axesOfFirst || perNode.some((drawn) => !drawn)) return []\n return axesOfFirst.map((axis, index) => {\n const values = perNode.map((drawn) => drawn?.[index]?.value)\n return { ...axis, value: values.every((value) => value === axis.value) ? axis.value : MIXED }\n })\n })\n\n /** Whether the optical size follows the font size on every layer, MIXED when they differ. */\n const opticalSizeAuto = computed<MixedValue<boolean>>(() => {\n const first = nodes.value.at(0)\n if (!first) return MIXED\n return nodes.value.every(\n (node) => node.opticalSizeFromFontSize === first.opticalSizeFromFontSize\n )\n ? first.opticalSizeFromFontSize\n : MIXED\n })\n\n // A drag or a typed value is previewed, then committed as one undo step from the values it\n // started at, as the other typography fields are. While text is edited, the editor applies\n // both to the selected characters, and records the step with what was typed.\n type AxisValues = Pick<\n SceneNode,\n 'fontVariations' | 'opticalSizeFromFontSize' | 'styleRuns' | 'textStyleId'\n >\n const beforePreview = new Map<string, AxisValues>()\n // The previews belong to the step the commit records, so undoing it leaves nothing unsaved.\n const batch = useUndoBatch(editor.undo, () => editor.beginInteractiveEdit())\n\n /**\n * Previews `edit` on every selected text: while text is edited the editor applies it to the\n * selected characters, whose style the panel shows; otherwise to the whole text.\n */\n function previewEach(edit: (shown: SceneNode) => AxisEdit) {\n batch.ensure('typography:axes', 'Change font axes')\n for (const target of nodes.value) {\n // The panel shows a text's characters' style, so what it replaces is read from the layer.\n const own = editor.graph.getNode(target.id) ?? target\n if (!beforePreview.has(target.id)) {\n const { fontVariations, opticalSizeFromFontSize, styleRuns, textStyleId } = own\n beforePreview.set(target.id, {\n fontVariations,\n opticalSizeFromFontSize,\n styleRuns,\n textStyleId\n })\n }\n const axisEdit = edit(target)\n editor.updateNode(\n target.id,\n editor.state.editingTextId === target.id\n ? { fontVariations: axisEdit.variations(target.fontVariations), ...axisEdit.changes }\n : wholeTextAxisChanges(own, axisEdit)\n )\n }\n editor.requestRender()\n }\n\n function commitPreview(label: string) {\n editor.undo.runBatch(label, () => {\n // While text is edited, the editor records the selected characters' ranges itself.\n for (const [id, before] of beforePreview) {\n const values = omit(before, ['textStyleId'])\n const edited = editor.state.editingTextId === id\n editor.commitNodeUpdate(id, edited ? omit(values, ['styleRuns']) : values, label)\n }\n })\n beforePreview.clear()\n batch.flush()\n }\n\n /** Draws the text at `value` on `axis` while it is dragged or typed. */\n function previewAxis(axis: string, value: number) {\n previewEach(() => setAxisEdit(axis, value))\n }\n\n /**\n * Puts back the axes and ranges a cancelled edit previewed. The text style it names goes back\n * too, so the editor restores the layer rather than styling selected characters with it.\n */\n function cancelAxis() {\n for (const [id, before] of beforePreview) editor.updateNode(id, before)\n beforePreview.clear()\n batch.flush()\n editor.requestRender()\n }\n\n /** Sets `axis` to `value` on every selected text layer in one undo step. */\n function setAxis(axis: string, value: number) {\n previewAxis(axis, value)\n commitPreview(`Change ${axis} axis`)\n }\n\n /**\n * Lets the optical size follow the font size, or holds it at the size it is drawn at now, as\n * Figma's \"Set optical size automatically\" does.\n */\n function setOpticalSizeAuto(auto: boolean) {\n previewEach((shown) => {\n const drawn = drawnAxes(shown)?.find((axis) => axis.tag === OPTICAL_SIZE)\n return {\n variations: (variations) => {\n const rest = variations.filter(({ axis }) => axis !== OPTICAL_SIZE)\n return auto || !drawn ? rest : [...rest, { axis: OPTICAL_SIZE, value: drawn.value }]\n },\n changes: { opticalSizeFromFontSize: auto }\n }\n })\n commitPreview('Change optical size')\n }\n\n return {\n axes,\n opticalSizeAuto,\n previewAxis,\n cancelAxis,\n setAxis,\n setOpticalSizeAuto\n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I,WAAW,eAAe;IACxC,MAAM,SAAS,KAAK,QAAQ,CAAC,aAAa,CAAC;IAC3C,MAAM,SAAS,OAAO,MAAM,kBAAkB;IAC9C,OAAO,iBAAiB,IAAI,SAAS,KAAK,QAAQ,CAAC,WAAW,CAAC,IAAI,QAAQ,KAAK;GAClF;EACF,CAAC;EACD,cAAc,MAAM;EACpB,MAAM,MAAM;CACd;;CAGA,SAAS,YAAY,MAAc,OAAe;EAChD,kBAAkB,YAAY,MAAM,KAAK,CAAC;CAC5C;;;;;CAMA,SAAS,aAAa;EACpB,KAAK,MAAM,CAAC,IAAI,WAAW,eAAe,OAAO,WAAW,IAAI,MAAM;EACtE,cAAc,MAAM;EACpB,MAAM,MAAM;EACZ,OAAO,cAAc;CACvB;;CAGA,SAAS,QAAQ,MAAc,OAAe;EAC5C,YAAY,MAAM,KAAK;EACvB,cAAc,UAAU,KAAK,MAAM;CACrC;;;;;CAMA,SAAS,mBAAmB,MAAe;EACzC,aAAa,UAAU;GACrB,MAAM,QAAQ,UAAU,KAAK,CAAC,EAAE,MAAM,SAAS,KAAK,QAAQ,YAAY;GACxE,OAAO;IACL,aAAa,eAAe;KAC1B,MAAM,OAAO,WAAW,QAAQ,EAAE,WAAW,SAAS,YAAY;KAClE,OAAO,QAAQ,CAAC,QAAQ,OAAO,CAAC,GAAG,MAAM;MAAE,MAAM;MAAc,OAAO,MAAM;KAAM,CAAC;IACrF;IACA,SAAS,EAAE,yBAAyB,KAAK;GAC3C;EACF,CAAC;EACD,cAAc,qBAAqB;CACrC;CAEA,OAAO;EACL;EACA;EACA;EACA;EACA;EACA;CACF;AACF"}
@@ -75,6 +75,7 @@ declare const EDITOR_COMMAND_METADATA: {
75
75
  };
76
76
  'selection.detachIcon': {};
77
77
  'selection.goToMainComponent': {};
78
+ 'selection.resetInstanceOverrides': {};
78
79
  'selection.createInstance': {};
79
80
  'selection.createSlot': {
80
81
  contextTestId: string;
@@ -1 +1 @@
1
- {"version":3,"file":"registry.d.ts","names":[],"sources":["../../../src/editor/commands/registry.ts"],"mappings":";;UAEiB;EACf;EACA;EACA;;cAGW;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;iBA2IG,sBAAsB,IAAI,kBAAkB"}
1
+ {"version":3,"file":"registry.d.ts","names":[],"sources":["../../../src/editor/commands/registry.ts"],"mappings":";;UAEiB;EACf;EACA;EACA;;cAGW;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;iBA4IG,sBAAsB,IAAI,kBAAkB"}
@@ -65,6 +65,7 @@ const EDITOR_COMMAND_METADATA = {
65
65
  },
66
66
  "selection.detachIcon": {},
67
67
  "selection.goToMainComponent": {},
68
+ "selection.resetInstanceOverrides": {},
68
69
  "selection.createInstance": {},
69
70
  "selection.createSlot": { contextTestId: "context-create-slot" },
70
71
  "selection.wrapInAutoLayout": {
@@ -1 +1 @@
1
- {"version":3,"file":"registry.js","names":[],"sources":["../../../src/editor/commands/registry.ts"],"sourcesContent":["import type { EditorCommandId } from './types'\n\nexport interface EditorCommandMetadata {\n shortcut?: string\n keybinding?: string | string[]\n contextTestId?: string\n}\n\nexport const EDITOR_COMMAND_METADATA = {\n 'edit.undo': { shortcut: 'MOD+Z', keybinding: '$mod+KeyZ' },\n 'edit.redo': { shortcut: 'MOD+SHIFT+Z', keybinding: ['$mod+Shift+KeyZ', '$mod+KeyY'] },\n 'selection.selectAll': { shortcut: 'MOD+A', keybinding: '$mod+KeyA' },\n 'selection.selectInverse': { shortcut: 'MOD+SHIFT+A', keybinding: '$mod+Shift+KeyA' },\n // Enter also opens a vector's path or a text layer, so the app binds it with that.\n 'selection.selectChildren': { shortcut: '↵' },\n 'selection.selectParent': {\n shortcut: 'SHIFT+↵',\n keybinding: ['Shift+Enter', 'Backslash']\n },\n 'selection.selectNextSibling': { shortcut: '⇥', keybinding: 'Tab' },\n 'selection.selectPreviousSibling': { shortcut: 'SHIFT+⇥', keybinding: 'Shift+Tab' },\n 'selection.duplicate': {\n shortcut: 'MOD+D',\n keybinding: '$mod+KeyD',\n contextTestId: 'context-duplicate'\n },\n 'selection.delete': { shortcut: '⌫', contextTestId: 'context-delete' },\n 'selection.group': { shortcut: 'MOD+G', keybinding: '$mod+KeyG', contextTestId: 'context-group' },\n 'selection.frameSelection': {\n shortcut: 'MOD+ALT+G',\n keybinding: '$mod+Alt+KeyG',\n contextTestId: 'context-frame-selection'\n },\n 'selection.ungroup': { shortcut: 'MOD+SHIFT+G', keybinding: '$mod+Shift+KeyG' },\n 'selection.createComponent': {\n shortcut: 'MOD+ALT+K',\n keybinding: '$mod+Alt+KeyK',\n contextTestId: 'context-create-component'\n },\n 'selection.convertToFrame': { contextTestId: 'context-convert-to-frame' },\n // ⇧⌘K is File › Place Image…, as in Figma, which gives Combine as variants no key.\n 'selection.createComponentSet': {},\n 'selection.detachInstance': { shortcut: 'MOD+ALT+B', keybinding: '$mod+Alt+KeyB' },\n 'selection.detachIcon': {},\n 'selection.goToMainComponent': {},\n 'selection.createInstance': {},\n 'selection.createSlot': { contextTestId: 'context-create-slot' },\n 'selection.wrapInAutoLayout': { shortcut: 'SHIFT+A', keybinding: 'Shift+KeyA' },\n 'selection.toggleMask': {\n shortcut: 'MOD+ALT+M',\n keybinding: ['Control+Meta+KeyM', '$mod+Alt+KeyM'],\n contextTestId: 'context-toggle-mask'\n },\n 'selection.bringForward': {\n shortcut: 'MOD+]',\n keybinding: '$mod+BracketRight',\n contextTestId: 'context-bring-forward'\n },\n 'selection.bringToFront': {\n shortcut: ']',\n keybinding: 'BracketRight',\n contextTestId: 'context-bring-to-front'\n },\n 'selection.sendBackward': {\n shortcut: 'MOD+[',\n keybinding: '$mod+BracketLeft',\n contextTestId: 'context-send-backward'\n },\n 'selection.sendToBack': {\n shortcut: '[',\n keybinding: 'BracketLeft',\n contextTestId: 'context-send-to-back'\n },\n 'selection.toggleVisibility': {\n shortcut: 'MOD+SHIFT+H',\n keybinding: '$mod+Shift+KeyH',\n contextTestId: 'context-toggle-visibility'\n },\n 'selection.toggleLock': {\n shortcut: 'MOD+SHIFT+L',\n keybinding: '$mod+Shift+KeyL',\n contextTestId: 'context-toggle-lock'\n },\n 'selection.flipHorizontal': {\n shortcut: 'SHIFT+H',\n keybinding: 'Shift+KeyH',\n contextTestId: 'context-flip-horizontal'\n },\n 'selection.flipVertical': {\n shortcut: 'SHIFT+V',\n keybinding: 'Shift+KeyV',\n contextTestId: 'context-flip-vertical'\n },\n 'selection.distributeHorizontal': { shortcut: 'CTRL+ALT+H', keybinding: 'Control+Alt+KeyH' },\n 'selection.distributeVertical': { shortcut: 'CTRL+ALT+V', keybinding: 'Control+Alt+KeyV' },\n 'selection.tidyUp': { shortcut: 'CTRL+ALT+T', keybinding: 'Control+Alt+KeyT' },\n 'selection.packHorizontal': {},\n 'selection.packVertical': {},\n 'selection.arrangeSpread': {},\n 'selection.arrangeCompact': {},\n 'selection.arrangePack': {},\n 'selection.arrangeFlowDown': {},\n 'selection.arrangeFlowRight': {},\n 'selection.arrangeTreeDown': {},\n 'selection.arrangeTreeRight': {},\n 'selection.arrangeRadial': {},\n 'selection.arrangeNetwork': {},\n 'selection.booleanUnion': {\n shortcut: 'ALT+SHIFT+U',\n keybinding: 'Alt+Shift+KeyU',\n contextTestId: 'context-boolean-union'\n },\n 'selection.booleanSubtract': {\n shortcut: 'ALT+SHIFT+S',\n keybinding: 'Alt+Shift+KeyS',\n contextTestId: 'context-boolean-subtract'\n },\n 'selection.booleanIntersect': {\n shortcut: 'ALT+SHIFT+I',\n keybinding: 'Alt+Shift+KeyI',\n contextTestId: 'context-boolean-intersect'\n },\n 'selection.booleanExclude': {\n shortcut: 'ALT+SHIFT+E',\n keybinding: 'Alt+Shift+KeyE',\n contextTestId: 'context-boolean-exclude'\n },\n 'selection.flatten': {\n shortcut: 'ALT+SHIFT+F',\n keybinding: 'Alt+Shift+KeyF',\n contextTestId: 'context-flatten'\n },\n 'selection.outlineText': { contextTestId: 'context-outline-text' },\n 'selection.outlineStroke': { contextTestId: 'context-outline-stroke' },\n // Enter or a double-click opens a selected image too, so the app binds it with them.\n 'selection.cropImage': { shortcut: '↵', contextTestId: 'context-crop-image' },\n 'selection.moveToPage': {},\n 'selection.setOpacity': { shortcut: '1-9, 0' },\n 'view.zoom100': { shortcut: 'MOD+0', keybinding: ['$mod+Digit0', 'Shift+Digit0'] },\n 'view.zoomFit': { shortcut: 'SHIFT+1', keybinding: ['$mod+Digit1', 'Shift+Digit1'] },\n 'view.zoomSelection': { shortcut: 'SHIFT+2', keybinding: ['$mod+Digit2', 'Shift+Digit2'] },\n 'view.zoomNextFrame': { shortcut: 'N', keybinding: 'KeyN' },\n 'view.zoomPreviousFrame': { shortcut: 'SHIFT+N', keybinding: 'Shift+KeyN' },\n 'view.nextPage': { shortcut: '⇟', keybinding: 'PageDown' },\n 'view.previousPage': { shortcut: '⇞', keybinding: 'PageUp' }\n} satisfies Record<EditorCommandId, EditorCommandMetadata>\n\nexport function editorCommandMetadata(id: EditorCommandId): EditorCommandMetadata {\n return EDITOR_COMMAND_METADATA[id]\n}\n"],"mappings":";AAQA,MAAa,0BAA0B;CACrC,aAAa;EAAE,UAAU;EAAS,YAAY;CAAY;CAC1D,aAAa;EAAE,UAAU;EAAe,YAAY,CAAC,mBAAmB,WAAW;CAAE;CACrF,uBAAuB;EAAE,UAAU;E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CACzD,qBAAqB;EAAE,UAAU;EAAK,YAAY;CAAS;AAC7D;AAEA,SAAgB,sBAAsB,IAA4C;CAChF,OAAO,wBAAwB;AACjC"}
1
+ {"version":3,"file":"registry.js","names":[],"sources":["../../../src/editor/commands/registry.ts"],"sourcesContent":["import type { EditorCommandId } from './types'\n\nexport interface EditorCommandMetadata {\n shortcut?: string\n keybinding?: string | string[]\n contextTestId?: string\n}\n\nexport const EDITOR_COMMAND_METADATA = {\n 'edit.undo': { shortcut: 'MOD+Z', keybinding: '$mod+KeyZ' },\n 'edit.redo': { shortcut: 'MOD+SHIFT+Z', keybinding: ['$mod+Shift+KeyZ', '$mod+KeyY'] },\n 'selection.selectAll': { shortcut: 'MOD+A', keybinding: '$mod+KeyA' },\n 'selection.selectInverse': { shortcut: 'MOD+SHIFT+A', keybinding: '$mod+Shift+KeyA' },\n // Enter also opens a vector's path or a text layer, so the app binds it with that.\n 'selection.selectChildren': { shortcut: '↵' },\n 'selection.selectParent': {\n shortcut: 'SHIFT+↵',\n keybinding: ['Shift+Enter', 'Backslash']\n },\n 'selection.selectNextSibling': { shortcut: '⇥', keybinding: 'Tab' },\n 'selection.selectPreviousSibling': { shortcut: 'SHIFT+⇥', keybinding: 'Shift+Tab' },\n 'selection.duplicate': {\n shortcut: 'MOD+D',\n keybinding: '$mod+KeyD',\n contextTestId: 'context-duplicate'\n },\n 'selection.delete': { shortcut: '⌫', contextTestId: 'context-delete' },\n 'selection.group': { shortcut: 'MOD+G', keybinding: '$mod+KeyG', contextTestId: 'context-group' },\n 'selection.frameSelection': {\n shortcut: 'MOD+ALT+G',\n keybinding: '$mod+Alt+KeyG',\n contextTestId: 'context-frame-selection'\n },\n 'selection.ungroup': { shortcut: 'MOD+SHIFT+G', keybinding: '$mod+Shift+KeyG' },\n 'selection.createComponent': {\n shortcut: 'MOD+ALT+K',\n keybinding: '$mod+Alt+KeyK',\n contextTestId: 'context-create-component'\n },\n 'selection.convertToFrame': { contextTestId: 'context-convert-to-frame' },\n // ⇧⌘K is File › Place Image…, as in Figma, which gives Combine as variants no key.\n 'selection.createComponentSet': {},\n 'selection.detachInstance': { shortcut: 'MOD+ALT+B', keybinding: '$mod+Alt+KeyB' },\n 'selection.detachIcon': {},\n 'selection.goToMainComponent': {},\n 'selection.resetInstanceOverrides': {},\n 'selection.createInstance': {},\n 'selection.createSlot': { contextTestId: 'context-create-slot' },\n 'selection.wrapInAutoLayout': { shortcut: 'SHIFT+A', keybinding: 'Shift+KeyA' },\n 'selection.toggleMask': {\n shortcut: 'MOD+ALT+M',\n keybinding: ['Control+Meta+KeyM', '$mod+Alt+KeyM'],\n contextTestId: 'context-toggle-mask'\n },\n 'selection.bringForward': {\n shortcut: 'MOD+]',\n keybinding: '$mod+BracketRight',\n contextTestId: 'context-bring-forward'\n },\n 'selection.bringToFront': {\n shortcut: ']',\n keybinding: 'BracketRight',\n contextTestId: 'context-bring-to-front'\n },\n 'selection.sendBackward': {\n shortcut: 'MOD+[',\n keybinding: '$mod+BracketLeft',\n contextTestId: 'context-send-backward'\n },\n 'selection.sendToBack': {\n shortcut: '[',\n keybinding: 'BracketLeft',\n contextTestId: 'context-send-to-back'\n },\n 'selection.toggleVisibility': {\n shortcut: 'MOD+SHIFT+H',\n keybinding: '$mod+Shift+KeyH',\n contextTestId: 'context-toggle-visibility'\n },\n 'selection.toggleLock': {\n shortcut: 'MOD+SHIFT+L',\n keybinding: '$mod+Shift+KeyL',\n contextTestId: 'context-toggle-lock'\n },\n 'selection.flipHorizontal': {\n shortcut: 'SHIFT+H',\n keybinding: 'Shift+KeyH',\n contextTestId: 'context-flip-horizontal'\n },\n 'selection.flipVertical': {\n shortcut: 'SHIFT+V',\n keybinding: 'Shift+KeyV',\n contextTestId: 'context-flip-vertical'\n },\n 'selection.distributeHorizontal': { shortcut: 'CTRL+ALT+H', keybinding: 'Control+Alt+KeyH' },\n 'selection.distributeVertical': { shortcut: 'CTRL+ALT+V', keybinding: 'Control+Alt+KeyV' },\n 'selection.tidyUp': { shortcut: 'CTRL+ALT+T', keybinding: 'Control+Alt+KeyT' },\n 'selection.packHorizontal': {},\n 'selection.packVertical': {},\n 'selection.arrangeSpread': {},\n 'selection.arrangeCompact': {},\n 'selection.arrangePack': {},\n 'selection.arrangeFlowDown': {},\n 'selection.arrangeFlowRight': {},\n 'selection.arrangeTreeDown': {},\n 'selection.arrangeTreeRight': {},\n 'selection.arrangeRadial': {},\n 'selection.arrangeNetwork': {},\n 'selection.booleanUnion': {\n shortcut: 'ALT+SHIFT+U',\n keybinding: 'Alt+Shift+KeyU',\n contextTestId: 'context-boolean-union'\n },\n 'selection.booleanSubtract': {\n shortcut: 'ALT+SHIFT+S',\n keybinding: 'Alt+Shift+KeyS',\n contextTestId: 'context-boolean-subtract'\n },\n 'selection.booleanIntersect': {\n shortcut: 'ALT+SHIFT+I',\n keybinding: 'Alt+Shift+KeyI',\n contextTestId: 'context-boolean-intersect'\n },\n 'selection.booleanExclude': {\n shortcut: 'ALT+SHIFT+E',\n keybinding: 'Alt+Shift+KeyE',\n contextTestId: 'context-boolean-exclude'\n },\n 'selection.flatten': {\n shortcut: 'ALT+SHIFT+F',\n keybinding: 'Alt+Shift+KeyF',\n contextTestId: 'context-flatten'\n },\n 'selection.outlineText': { contextTestId: 'context-outline-text' },\n 'selection.outlineStroke': { contextTestId: 'context-outline-stroke' },\n // Enter or a double-click opens a selected image too, so the app binds it with them.\n 'selection.cropImage': { shortcut: '↵', contextTestId: 'context-crop-image' },\n 'selection.moveToPage': {},\n 'selection.setOpacity': { shortcut: '1-9, 0' },\n 'view.zoom100': { shortcut: 'MOD+0', keybinding: ['$mod+Digit0', 'Shift+Digit0'] },\n 'view.zoomFit': { shortcut: 'SHIFT+1', keybinding: ['$mod+Digit1', 'Shift+Digit1'] },\n 'view.zoomSelection': { shortcut: 'SHIFT+2', keybinding: ['$mod+Digit2', 'Shift+Digit2'] },\n 'view.zoomNextFrame': { shortcut: 'N', keybinding: 'KeyN' },\n 'view.zoomPreviousFrame': { shortcut: 'SHIFT+N', keybinding: 'Shift+KeyN' },\n 'view.nextPage': { shortcut: '⇟', keybinding: 'PageDown' },\n 'view.previousPage': { shortcut: '⇞', keybinding: 'PageUp' }\n} satisfies Record<EditorCommandId, EditorCommandMetadata>\n\nexport function editorCommandMetadata(id: EditorCommandId): EditorCommandMetadata {\n return EDITOR_COMMAND_METADATA[id]\n}\n"],"mappings":";AAQA,MAAa,0BAA0B;CACrC,aAAa;EAAE,UAAU;EAAS,YAAY;CAAY;CAC1D,aAAa;EAAE,UAAU;EAAe,YAAY,CAAC,mBAAmB,WAAW;CAAE;CACrF,uBAAuB;EAAE,UAAU;EAAS,YAAY;CAAY;CACpE,2BAA2B;EAAE,UAAU;EAAe,YAAY;CAAkB;CAEpF,4BAA4B,EAAE,UAAU,IAAI;CAC5C,0BAA0B;EACxB,UAAU;EACV,YAAY,CAAC,eAAe,WAAW;CACzC;CACA,+BAA+B;EAAE,UAAU;EAAK,YAAY;CAAM;CAClE,mCAAmC;EAAE,UAAU;EAAW,YAAY;CAAY;CAClF,uBAAuB;EACrB,UAAU;EACV,YAAY;EACZ,eAAe;CACjB;CACA,oBAAoB;EAAE,UAAU;EAAK,eAAe;CAAiB;CACrE,mBAAmB;EAAE,UAAU;EAAS,YAAY;EAAa,eAAe;CAAgB;CAChG,4BAA4B;EAC1B,UAAU;EACV,YAAY;EACZ,eAAe;CACjB;CACA,qBAAqB;EAAE,UAAU;EAAe,YAAY;CAAkB;CAC9E,6BAA6B;EAC3B,UAAU;EACV,YAAY;EACZ,eAAe;CACjB;CACA,4BAA4B,EAAE,eAAe,2BAA2B;CAExE,gCAAgC,CAAC;CACjC,4BAA4B;EAAE,UAAU;EAAa,YAAY;CAAgB;CACjF,wBAAwB,CAAC;CACzB,+BAA+B,CAAC;CAChC,oCAAoC,CAAC;CACrC,4BAA4B,CAAC;CAC7B,wBAAwB,EAAE,eAAe,sBAAsB;CAC/D,8BAA8B;EAAE,UAAU;EAAW,YAAY;CAAa;CAC9E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,uBAAuB;EAAE,UAAU;EAAK,eAAe;CAAqB;CAC5E,wBAAwB,CAAC;CACzB,wBAAwB,EAAE,UAAU,SAAS;CAC7C,gBAAgB;EAAE,UAAU;EAAS,YAAY,CAAC,eAAe,cAAc;CAAE;CACjF,gBAAgB;EAAE,UAAU;EAAW,YAAY,CAAC,eAAe,cAAc;CAAE;CACnF,sBAAsB;EAAE,UAAU;EAAW,YAAY,CAAC,eAAe,cAAc;CAAE;CACzF,sBAAsB;EAAE,UAAU;EAAK,YAAY;CAAO;CAC1D,0BAA0B;EAAE,UAAU;EAAW,YAAY;CAAa;CAC1E,iBAAiB;EAAE,UAAU;EAAK,YAAY;CAAW;CACzD,qBAAqB;EAAE,UAAU;EAAK,YAAY;CAAS;AAC7D;AAEA,SAAgB,sBAAsB,IAA4C;CAChF,OAAO,wBAAwB;AACjC"}
@@ -172,6 +172,17 @@ function createSelectionCommands({ editor, selection, capabilities, messages: t,
172
172
  });
173
173
  }
174
174
  },
175
+ "selection.resetInstanceOverrides": {
176
+ id: "selection.resetInstanceOverrides",
177
+ get label() {
178
+ return t.value.resetAllChanges;
179
+ },
180
+ enabled: capabilities.canResetInstanceOverrides,
181
+ run: () => {
182
+ const node = selection.selectedNode.value;
183
+ if (node) editor.resetInstanceOverrides(node.id);
184
+ }
185
+ },
175
186
  "selection.goToMainComponent": {
176
187
  id: "selection.goToMainComponent",
177
188
  get label() {
@@ -203,9 +214,7 @@ function createSelectionCommands({ editor, selection, capabilities, messages: t,
203
214
  },
204
215
  enabled: capabilities.canToggleMask,
205
216
  run: () => {
206
- const target = selectedMaskTarget(editor.getSelectedNodes(), editor);
207
- if (!target) return;
208
- editor.updateNodeWithUndo(target.id, { isMask: !target.isMask }, target.isMask ? "Remove mask" : "Use as mask");
217
+ editor.maskSelected();
209
218
  }
210
219
  },
211
220
  "selection.bringForward": {