@pairdraw/vue 0.21.0 → 0.22.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.
- package/dist/canvas/index.d.ts +2 -1
- package/dist/canvas/index.js +2 -1
- package/dist/canvas/pointer/drag-move.js +2 -2
- package/dist/canvas/pointer/drag-move.js.map +1 -1
- package/dist/canvas/surface/color-space.d.ts.map +1 -1
- package/dist/canvas/surface/color-space.js +3 -19
- package/dist/canvas/surface/color-space.js.map +1 -1
- package/dist/canvas/surface/gl-surface.js +11 -1
- package/dist/canvas/surface/gl-surface.js.map +1 -1
- package/dist/canvas/surface/kit-loader.d.ts +10 -0
- package/dist/canvas/surface/kit-loader.d.ts.map +1 -0
- package/dist/canvas/surface/kit-loader.js +11 -2
- package/dist/canvas/surface/kit-loader.js.map +1 -1
- package/dist/canvas/tools/registry.js +1 -0
- package/dist/canvas/tools/registry.js.map +1 -1
- package/dist/canvas/useCanvasInput.d.ts +420 -0
- package/dist/controls/appearance/use.d.ts +1 -1
- package/dist/controls/layout/helpers.js +28 -9
- package/dist/controls/layout/helpers.js.map +1 -1
- package/dist/controls/layout/use.d.ts +2 -0
- package/dist/controls/layout/use.d.ts.map +1 -1
- package/dist/controls/layout/use.js +3 -1
- package/dist/controls/layout/use.js.map +1 -1
- package/dist/controls/node-props/helpers.d.ts.map +1 -1
- package/dist/controls/node-props/helpers.js +1 -1
- package/dist/controls/node-props/helpers.js.map +1 -1
- package/dist/controls/number-variable-binding/index.d.ts +2 -2
- package/dist/controls/number-variable-binding/index.js +2 -2
- package/dist/controls/number-variable-binding/use.d.ts +7 -2
- package/dist/controls/number-variable-binding/use.d.ts.map +1 -1
- package/dist/controls/number-variable-binding/use.js +9 -1
- package/dist/controls/number-variable-binding/use.js.map +1 -1
- package/dist/controls/typography/arrivals.js +35 -0
- package/dist/controls/typography/arrivals.js.map +1 -0
- package/dist/controls/typography/axes.d.ts.map +1 -1
- package/dist/controls/typography/axes.js +3 -0
- package/dist/controls/typography/axes.js.map +1 -1
- package/dist/controls/typography/faces.js +4 -15
- package/dist/controls/typography/faces.js.map +1 -1
- package/dist/controls/typography/features.d.ts.map +1 -1
- package/dist/controls/typography/features.js +3 -17
- package/dist/controls/typography/features.js.map +1 -1
- package/dist/editor/commands/actions.d.ts +10 -0
- package/dist/editor/commands/actions.d.ts.map +1 -0
- package/dist/editor/commands/actions.js +9 -1
- package/dist/editor/commands/actions.js.map +1 -1
- package/dist/editor/commands/index.d.ts +3 -1
- package/dist/editor/commands/index.js +3 -1
- package/dist/editor/commands/refusals.d.ts +18 -0
- package/dist/editor/commands/refusals.d.ts.map +1 -0
- package/dist/editor/commands/refusals.js +16 -0
- package/dist/editor/commands/refusals.js.map +1 -0
- package/dist/editor/commands/registry.d.ts +4 -1
- package/dist/editor/commands/registry.d.ts.map +1 -1
- package/dist/editor/commands/registry.js +2 -1
- package/dist/editor/commands/registry.js.map +1 -1
- package/dist/editor/commands/selection.js +11 -0
- package/dist/editor/commands/selection.js.map +1 -1
- package/dist/editor/commands/shortcut.d.ts.map +1 -1
- package/dist/editor/commands/shortcut.js +9 -1
- package/dist/editor/commands/shortcut.js.map +1 -1
- package/dist/editor/commands/types.d.ts +1 -1
- package/dist/editor/commands/types.d.ts.map +1 -1
- package/dist/editor/selection-capabilities/use.d.ts +2 -0
- package/dist/editor/selection-capabilities/use.d.ts.map +1 -1
- package/dist/editor/selection-capabilities/use.js +38 -11
- package/dist/editor/selection-capabilities/use.js.map +1 -1
- package/dist/editor/selection-state/use.js +1 -5
- package/dist/editor/selection-state/use.js.map +1 -1
- package/dist/editor/tool-cursor/index.d.ts.map +1 -1
- package/dist/editor/tool-cursor/index.js +1 -0
- package/dist/editor/tool-cursor/index.js.map +1 -1
- package/dist/i18n/locales/de/ai.json.js +4 -11
- package/dist/i18n/locales/de/code.json.js +2 -0
- package/dist/i18n/locales/de/commands.json.js +4 -2
- package/dist/i18n/locales/de/files.json.js +21 -1
- package/dist/i18n/locales/de/menu.json.js +2 -0
- package/dist/i18n/locales/de/panels.json.js +77 -2
- package/dist/i18n/locales/de/tools.json.js +1 -0
- package/dist/i18n/locales/es/ai.json.js +4 -11
- package/dist/i18n/locales/es/code.json.js +2 -0
- package/dist/i18n/locales/es/commands.json.js +4 -2
- package/dist/i18n/locales/es/files.json.js +21 -1
- package/dist/i18n/locales/es/menu.json.js +2 -0
- package/dist/i18n/locales/es/panels.json.js +77 -2
- package/dist/i18n/locales/es/tools.json.js +1 -0
- package/dist/i18n/locales/fr/ai.json.js +4 -11
- package/dist/i18n/locales/fr/code.json.js +2 -0
- package/dist/i18n/locales/fr/commands.json.js +4 -2
- package/dist/i18n/locales/fr/files.json.js +21 -1
- package/dist/i18n/locales/fr/menu.json.js +2 -0
- package/dist/i18n/locales/fr/panels.json.js +77 -2
- package/dist/i18n/locales/fr/tools.json.js +1 -0
- package/dist/i18n/locales/id/ai.json.js +4 -11
- package/dist/i18n/locales/id/automation.json.js +7 -7
- package/dist/i18n/locales/id/code.json.js +3 -1
- package/dist/i18n/locales/id/commands.json.js +4 -2
- package/dist/i18n/locales/id/editor.json.js +1 -1
- package/dist/i18n/locales/id/files.json.js +21 -1
- package/dist/i18n/locales/id/menu.json.js +3 -1
- package/dist/i18n/locales/id/panels.json.js +80 -5
- package/dist/i18n/locales/id/tools.json.js +1 -0
- package/dist/i18n/locales/it/ai.json.js +4 -11
- package/dist/i18n/locales/it/code.json.js +2 -0
- package/dist/i18n/locales/it/commands.json.js +4 -2
- package/dist/i18n/locales/it/files.json.js +21 -1
- package/dist/i18n/locales/it/menu.json.js +2 -0
- package/dist/i18n/locales/it/panels.json.js +77 -2
- package/dist/i18n/locales/it/tools.json.js +1 -0
- package/dist/i18n/locales/ja/ai.json.js +4 -11
- package/dist/i18n/locales/ja/code.json.js +2 -0
- package/dist/i18n/locales/ja/commands.json.js +4 -2
- package/dist/i18n/locales/ja/files.json.js +21 -1
- package/dist/i18n/locales/ja/menu.json.js +2 -0
- package/dist/i18n/locales/ja/panels.json.js +77 -2
- package/dist/i18n/locales/ja/tools.json.js +1 -0
- package/dist/i18n/locales/pl/ai.json.js +4 -11
- package/dist/i18n/locales/pl/code.json.js +2 -0
- package/dist/i18n/locales/pl/commands.json.js +4 -2
- package/dist/i18n/locales/pl/files.json.js +21 -1
- package/dist/i18n/locales/pl/menu.json.js +2 -0
- package/dist/i18n/locales/pl/panels.json.js +77 -2
- package/dist/i18n/locales/pl/tools.json.js +1 -0
- package/dist/i18n/locales/ru/ai.json.js +4 -11
- package/dist/i18n/locales/ru/code.json.js +2 -0
- package/dist/i18n/locales/ru/commands.json.js +4 -2
- package/dist/i18n/locales/ru/files.json.js +21 -1
- package/dist/i18n/locales/ru/menu.json.js +2 -0
- package/dist/i18n/locales/ru/panels.json.js +77 -2
- package/dist/i18n/locales/ru/tools.json.js +1 -0
- package/dist/i18n/locales/zh-cn/ai.json.js +4 -11
- package/dist/i18n/locales/zh-cn/code.json.js +2 -0
- package/dist/i18n/locales/zh-cn/commands.json.js +4 -2
- package/dist/i18n/locales/zh-cn/files.json.js +21 -1
- package/dist/i18n/locales/zh-cn/menu.json.js +2 -0
- package/dist/i18n/locales/zh-cn/panels.json.js +77 -2
- package/dist/i18n/locales/zh-cn/tools.json.js +1 -0
- package/dist/i18n/messages/ai.d.ts +10 -11
- package/dist/i18n/messages/ai.js +4 -11
- package/dist/i18n/messages/ai.js.map +1 -1
- package/dist/i18n/messages/code.d.ts +4 -0
- package/dist/i18n/messages/code.d.ts.map +1 -1
- package/dist/i18n/messages/code.js +3 -1
- package/dist/i18n/messages/code.js.map +1 -1
- package/dist/i18n/messages/commands.d.ts +3 -1
- package/dist/i18n/messages/commands.d.ts.map +1 -1
- package/dist/i18n/messages/commands.js +3 -1
- package/dist/i18n/messages/commands.js.map +1 -1
- package/dist/i18n/messages/files.d.ts +34 -0
- package/dist/i18n/messages/files.d.ts.map +1 -1
- package/dist/i18n/messages/files.js +20 -0
- package/dist/i18n/messages/files.js.map +1 -1
- package/dist/i18n/messages/menu.d.ts +2 -0
- package/dist/i18n/messages/menu.d.ts.map +1 -1
- package/dist/i18n/messages/menu.js +2 -0
- package/dist/i18n/messages/menu.js.map +1 -1
- package/dist/i18n/messages/panels.d.ts +77 -0
- package/dist/i18n/messages/panels.d.ts.map +1 -1
- package/dist/i18n/messages/panels.js +75 -0
- package/dist/i18n/messages/panels.js.map +1 -1
- package/dist/i18n/messages/tools.d.ts +1 -0
- package/dist/i18n/messages/tools.d.ts.map +1 -1
- package/dist/i18n/messages/tools.js +1 -0
- package/dist/i18n/messages/tools.js.map +1 -1
- package/dist/i18n/messages.d.ts +131 -12
- package/dist/i18n/useI18n.d.ts +524 -48
- package/dist/i18n/useI18n.d.ts.map +1 -1
- package/dist/primitives/LayoutControls/LayoutControlsRoot.vue.d.ts.map +1 -1
- package/dist/primitives/LayoutControls/LayoutControlsRoot.vue.js +2 -0
- package/dist/primitives/LayoutControls/LayoutControlsRoot.vue.js.map +1 -1
- package/dist/shared/input/resize.js +28 -12
- package/dist/shared/input/resize.js.map +1 -1
- package/dist/shared/input/types.js +1 -0
- package/dist/shared/input/types.js.map +1 -1
- package/package.json +4 -4
|
@@ -13,7 +13,7 @@ import { takesOwnSize } from "@pairdraw/scene-graph/instances";
|
|
|
13
13
|
function useLayout() {
|
|
14
14
|
const editor = useEditor();
|
|
15
15
|
const { panels } = useI18n();
|
|
16
|
-
const { node, layoutDirection, gapAuto, alignGrid, isInAutoLayout, isGrid, isFlex, widthSizing, heightSizing, widthSizingOptions, heightSizingOptions, aspectRatioLocked, aspectRatioLockable } = createLayoutSelectionState(editor, panels);
|
|
16
|
+
const { node, layoutDirection, gapAuto, alignGrid, isInAutoLayout, isGrid, isGridChild, isFlex, widthSizing, heightSizing, widthSizingOptions, heightSizingOptions, aspectRatioLocked, aspectRatioLockable } = createLayoutSelectionState(editor, panels);
|
|
17
17
|
const { showIndividualPadding, hasUniformPadding, hasSymmetricPadding, setHorizontalPadding, commitHorizontalPadding, setVerticalPadding, commitVerticalPadding, toggleIndividualPadding, cancelPaddingPreview } = createPaddingActions(editor, node);
|
|
18
18
|
const layoutActions = createLayoutActions({
|
|
19
19
|
editor,
|
|
@@ -23,11 +23,13 @@ function useLayout() {
|
|
|
23
23
|
return {
|
|
24
24
|
editor,
|
|
25
25
|
node,
|
|
26
|
+
isMulti: computed(() => editor.state.selectedIds.size > 1),
|
|
26
27
|
resizes: computed(() => node.value ? takesOwnSize(editor.graph, node.value) : false),
|
|
27
28
|
layoutDirection,
|
|
28
29
|
gapAuto,
|
|
29
30
|
isInAutoLayout,
|
|
30
31
|
isGrid,
|
|
32
|
+
isGridChild,
|
|
31
33
|
isFlex,
|
|
32
34
|
widthSizing,
|
|
33
35
|
heightSizing,
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"use.js","names":[],"sources":["../../../src/controls/layout/use.ts"],"sourcesContent":["import { computed } from 'vue'\n\nimport { takesOwnSize } from '@pairdraw/scene-graph/instances'\n\nimport {\n createGridTrackActions,\n createLayoutActions,\n createLayoutSelectionState,\n createPaddingActions,\n createTrackSizingOptions,\n trackLabel\n} from '#vue/controls/layout/helpers'\nimport { useEditor } from '#vue/editor/context'\nimport { useI18n } from '#vue/i18n'\n\n/**\n * Returns layout-related state and actions for the current selection.\n *\n * Use this composable to build auto-layout and grid panels that need sizing,\n * padding, alignment, and track editing behavior.\n */\nexport function useLayout() {\n const editor = useEditor()\n const { panels } = useI18n()\n\n const {\n node,\n layoutDirection,\n gapAuto,\n alignGrid,\n isInAutoLayout,\n isGrid,\n isFlex,\n widthSizing,\n heightSizing,\n widthSizingOptions,\n heightSizingOptions,\n aspectRatioLocked,\n aspectRatioLockable\n } = createLayoutSelectionState(editor, panels)\n\n const {\n showIndividualPadding,\n hasUniformPadding,\n hasSymmetricPadding,\n setHorizontalPadding,\n commitHorizontalPadding,\n setVerticalPadding,\n commitVerticalPadding,\n toggleIndividualPadding,\n cancelPaddingPreview\n } = createPaddingActions(editor, node)\n\n const layoutActions = createLayoutActions({ editor, node })\n\n const { updateGridTrack, addTrack, removeTrack } = createGridTrackActions(editor, node)\n\n /** Whether Figma lets the selected layer take a size of its own; see `takesOwnSize`. */\n const resizes = computed(() => (node.value ? takesOwnSize(editor.graph, node.value) : false))\n\n return {\n editor,\n node,\n resizes,\n layoutDirection,\n gapAuto,\n isInAutoLayout,\n isGrid,\n isFlex,\n widthSizing,\n heightSizing,\n widthSizingOptions,\n heightSizingOptions,\n aspectRatioLocked,\n aspectRatioLockable,\n alignGrid,\n showIndividualPadding,\n hasUniformPadding,\n hasSymmetricPadding,\n trackSizingOptions: createTrackSizingOptions(panels.value),\n cancelPreview: () => {\n cancelPaddingPreview()\n layoutActions.cancelPreview()\n },\n updateProp: layoutActions.updateProp,\n updateSizeLimit: layoutActions.updateSizeLimit,\n setSizeLimitToCurrent: layoutActions.setSizeLimitToCurrent,\n commitSizeLimit: layoutActions.commitSizeLimit,\n addSizeLimit: layoutActions.addSizeLimit,\n removeSizeLimit: layoutActions.removeSizeLimit,\n commitProp: layoutActions.commitProp,\n setAxisSizing: layoutActions.setAxisSizing,\n updateAxisSize: layoutActions.updateAxisSize,\n commitAxisSize: layoutActions.commitAxisSize,\n toggleAspectRatioLock: layoutActions.toggleAspectRatioLock,\n setHorizontalPadding,\n commitHorizontalPadding,\n setVerticalPadding,\n commitVerticalPadding,\n setAlignment: layoutActions.setAlignment,\n setGapAuto: layoutActions.setGapAuto,\n setLayoutDirection: layoutActions.setLayoutDirection,\n updateGridTrack,\n addTrack,\n removeTrack,\n trackLabel,\n toggleIndividualPadding\n }\n}\n"],"mappings":";;;;;;;;;;;;AAqBA,SAAgB,YAAY;CAC1B,MAAM,SAAS,UAAU;CACzB,MAAM,EAAE,WAAW,QAAQ;CAE3B,MAAM,EACJ,MACA,iBACA,SACA,WACA,gBACA,QACA,QACA,aACA,cACA,oBACA,qBACA,mBACA,wBACE,2BAA2B,QAAQ,MAAM;CAE7C,MAAM,EACJ,uBACA,mBACA,qBACA,sBACA,yBACA,oBACA,uBACA,yBACA,yBACE,qBAAqB,QAAQ,IAAI;CAErC,MAAM,gBAAgB,oBAAoB;EAAE;EAAQ;CAAK,CAAC;CAE1D,MAAM,EAAE,iBAAiB,UAAU,gBAAgB,uBAAuB,QAAQ,IAAI;
|
|
1
|
+
{"version":3,"file":"use.js","names":[],"sources":["../../../src/controls/layout/use.ts"],"sourcesContent":["import { computed } from 'vue'\n\nimport { takesOwnSize } from '@pairdraw/scene-graph/instances'\n\nimport {\n createGridTrackActions,\n createLayoutActions,\n createLayoutSelectionState,\n createPaddingActions,\n createTrackSizingOptions,\n trackLabel\n} from '#vue/controls/layout/helpers'\nimport { useEditor } from '#vue/editor/context'\nimport { useI18n } from '#vue/i18n'\n\n/**\n * Returns layout-related state and actions for the current selection.\n *\n * Use this composable to build auto-layout and grid panels that need sizing,\n * padding, alignment, and track editing behavior.\n */\nexport function useLayout() {\n const editor = useEditor()\n const { panels } = useI18n()\n\n const {\n node,\n layoutDirection,\n gapAuto,\n alignGrid,\n isInAutoLayout,\n isGrid,\n isGridChild,\n isFlex,\n widthSizing,\n heightSizing,\n widthSizingOptions,\n heightSizingOptions,\n aspectRatioLocked,\n aspectRatioLockable\n } = createLayoutSelectionState(editor, panels)\n\n const {\n showIndividualPadding,\n hasUniformPadding,\n hasSymmetricPadding,\n setHorizontalPadding,\n commitHorizontalPadding,\n setVerticalPadding,\n commitVerticalPadding,\n toggleIndividualPadding,\n cancelPaddingPreview\n } = createPaddingActions(editor, node)\n\n const layoutActions = createLayoutActions({ editor, node })\n\n const { updateGridTrack, addTrack, removeTrack } = createGridTrackActions(editor, node)\n\n /** Whether more than one layer is selected, so the panel edits all of them. */\n const isMulti = computed(() => editor.state.selectedIds.size > 1)\n\n /** Whether Figma lets the selected layer take a size of its own; see `takesOwnSize`. */\n const resizes = computed(() => (node.value ? takesOwnSize(editor.graph, node.value) : false))\n\n return {\n editor,\n node,\n isMulti,\n resizes,\n layoutDirection,\n gapAuto,\n isInAutoLayout,\n isGrid,\n isGridChild,\n isFlex,\n widthSizing,\n heightSizing,\n widthSizingOptions,\n heightSizingOptions,\n aspectRatioLocked,\n aspectRatioLockable,\n alignGrid,\n showIndividualPadding,\n hasUniformPadding,\n hasSymmetricPadding,\n trackSizingOptions: createTrackSizingOptions(panels.value),\n cancelPreview: () => {\n cancelPaddingPreview()\n layoutActions.cancelPreview()\n },\n updateProp: layoutActions.updateProp,\n updateSizeLimit: layoutActions.updateSizeLimit,\n setSizeLimitToCurrent: layoutActions.setSizeLimitToCurrent,\n commitSizeLimit: layoutActions.commitSizeLimit,\n addSizeLimit: layoutActions.addSizeLimit,\n removeSizeLimit: layoutActions.removeSizeLimit,\n commitProp: layoutActions.commitProp,\n setAxisSizing: layoutActions.setAxisSizing,\n updateAxisSize: layoutActions.updateAxisSize,\n commitAxisSize: layoutActions.commitAxisSize,\n toggleAspectRatioLock: layoutActions.toggleAspectRatioLock,\n setHorizontalPadding,\n commitHorizontalPadding,\n setVerticalPadding,\n commitVerticalPadding,\n setAlignment: layoutActions.setAlignment,\n setGapAuto: layoutActions.setGapAuto,\n setLayoutDirection: layoutActions.setLayoutDirection,\n updateGridTrack,\n addTrack,\n removeTrack,\n trackLabel,\n toggleIndividualPadding\n }\n}\n"],"mappings":";;;;;;;;;;;;AAqBA,SAAgB,YAAY;CAC1B,MAAM,SAAS,UAAU;CACzB,MAAM,EAAE,WAAW,QAAQ;CAE3B,MAAM,EACJ,MACA,iBACA,SACA,WACA,gBACA,QACA,aACA,QACA,aACA,cACA,oBACA,qBACA,mBACA,wBACE,2BAA2B,QAAQ,MAAM;CAE7C,MAAM,EACJ,uBACA,mBACA,qBACA,sBACA,yBACA,oBACA,uBACA,yBACA,yBACE,qBAAqB,QAAQ,IAAI;CAErC,MAAM,gBAAgB,oBAAoB;EAAE;EAAQ;CAAK,CAAC;CAE1D,MAAM,EAAE,iBAAiB,UAAU,gBAAgB,uBAAuB,QAAQ,IAAI;CAQtF,OAAO;EACL;EACA;EACA,SARc,eAAe,OAAO,MAAM,YAAY,OAAO,CAQvD;EACN,SANc,eAAgB,KAAK,QAAQ,aAAa,OAAO,OAAO,KAAK,KAAK,IAAI,KAM9E;EACN;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA,oBAAoB,yBAAyB,OAAO,KAAK;EACzD,qBAAqB;GACnB,qBAAqB;GACrB,cAAc,cAAc;EAC9B;EACA,YAAY,cAAc;EAC1B,iBAAiB,cAAc;EAC/B,uBAAuB,cAAc;EACrC,iBAAiB,cAAc;EAC/B,cAAc,cAAc;EAC5B,iBAAiB,cAAc;EAC/B,YAAY,cAAc;EAC1B,eAAe,cAAc;EAC7B,gBAAgB,cAAc;EAC9B,gBAAgB,cAAc;EAC9B,uBAAuB,cAAc;EACrC;EACA;EACA;EACA;EACA,cAAc,cAAc;EAC5B,YAAY,cAAc;EAC1B,oBAAoB,cAAc;EAClC;EACA;EACA;EACA;EACA;CACF;AACF"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"helpers.d.ts","names":[],"sources":["../../../src/controls/node-props/helpers.ts"],"mappings":";;;;cAQa;KACD,WAAW,KAAK,WAAW;
|
|
1
|
+
{"version":3,"file":"helpers.d.ts","names":[],"sources":["../../../src/controls/node-props/helpers.ts"],"mappings":";;;;cAQa;KACD,WAAW,KAAK,WAAW;iBAgFvB,iBAAiB,OAAO,aAAa,WAAW"}
|
|
@@ -39,7 +39,7 @@ function createNodePropSelectionState(store) {
|
|
|
39
39
|
if (all.length === 0) return MIXED;
|
|
40
40
|
const first = all[0][key];
|
|
41
41
|
for (let i = 1; i < all.length; i++) if (all[i][key] !== first) return MIXED;
|
|
42
|
-
return first;
|
|
42
|
+
return all.some((selected) => selected.type === "TEXT" && store.isTextStyleMixed(selected.id, key)) ? MIXED : first;
|
|
43
43
|
}
|
|
44
44
|
function prop(key) {
|
|
45
45
|
return computed(() => merged(key));
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"helpers.js","names":[],"sources":["../../../src/controls/node-props/helpers.ts"],"sourcesContent":["import { computed } from 'vue'\nimport type { ComputedRef } from 'vue'\n\nimport type { Editor } from '@pairdraw/core'\nimport type { Effect, Fill, SceneNode, Stroke } from '@pairdraw/scene-graph'\n\nimport { useSelectedNodeState } from '#vue/editor/selection-state/nodes'\n\nexport const MIXED = Symbol('mixed')\nexport type MixedValue<T> = T | typeof MIXED\n\ntype ArrayItem = Fill | Stroke | Effect | Record<string, unknown>\n\nfunction areArrayItemsEqual(a: ArrayItem, b: ArrayItem): boolean {\n if (a === b) return true\n const aKeys = Object.keys(a)\n const bKeys = Object.keys(b)\n if (aKeys.length !== bKeys.length) return false\n for (const key of aKeys) {\n const aValue = a[key as keyof typeof a]\n const bValue = b[key as keyof typeof b]\n if (Array.isArray(aValue) && Array.isArray(bValue)) {\n if (aValue.length !== bValue.length) return false\n for (let i = 0; i < aValue.length; i++) {\n const left = aValue[i]\n const right = bValue[i]\n if (\n typeof left === 'object' &&\n left != null &&\n typeof right === 'object' &&\n right != null\n ) {\n if (!areArrayItemsEqual(left as ArrayItem, right as ArrayItem)) return false\n } else if (left !== right) {\n return false\n }\n }\n continue\n }\n if (\n typeof aValue === 'object' &&\n aValue != null &&\n typeof bValue === 'object' &&\n bValue != null\n ) {\n if (!areArrayItemsEqual(aValue as ArrayItem, bValue as ArrayItem)) return false\n continue\n }\n if (aValue !== bValue) return false\n }\n return true\n}\n\ntype ArrayPropKey = 'fills' | 'strokes' | 'effects'\n\nexport function createNodePropSelectionState(store: Editor) {\n const { node, nodes } = useSelectedNodeState(store)\n const isMulti = computed(() => nodes.value.length > 1)\n const active = computed(() => node.value !== null || isMulti.value)\n const activeNode = computed(() => node.value ?? (nodes.value[0] as SceneNode | undefined) ?? null)\n\n function merged<K extends keyof SceneNode>(key: K): MixedValue<SceneNode[K]> {\n const all = nodes.value\n if (all.length === 0) return MIXED\n const first = all[0][key]\n for (let i = 1; i < all.length; i++) {\n if (all[i][key] !== first) return MIXED\n }\n return first\n }\n\n function prop<K extends keyof SceneNode>(key: K) {\n return computed(() => merged(key))\n }\n\n function updateAllWithUndo(patch: Partial<SceneNode>, label: string) {\n for (const n of nodes.value) {\n store.updateNodeWithUndo(n.id, patch, label)\n }\n }\n\n return { node, nodes, isMulti, active, activeNode, merged, prop, updateAllWithUndo }\n}\n\nexport function isNodeArrayMixed(nodes: SceneNode[], key: keyof SceneNode): boolean {\n if (nodes.length <= 1) return false\n const first = nodes[0][key]\n if (!Array.isArray(first)) return nodes.some((n) => n[key] !== first)\n for (let i = 1; i < nodes.length; i++) {\n const current = nodes[i][key]\n if (!Array.isArray(current) || current.length !== first.length) return true\n for (let j = 0; j < first.length; j++) {\n const left = first[j]\n const right = current[j]\n if (typeof left === 'object' && typeof right === 'object') {\n if (!areArrayItemsEqual(left as ArrayItem, right as ArrayItem)) return true\n } else if (left !== right) {\n return true\n }\n }\n }\n return false\n}\n\nexport function createNodePropArrayActions({\n store,\n nodes,\n activeNode,\n isMulti\n}: {\n store: Editor\n nodes: ComputedRef<SceneNode[]>\n activeNode: ComputedRef<SceneNode | null>\n isMulti: ComputedRef<boolean>\n}) {\n function targetNodes(): SceneNode[] {\n if (isMulti.value) return nodes.value\n return activeNode.value ? [activeNode.value] : []\n }\n\n function updateArrayItem(\n key: ArrayPropKey,\n index: number,\n patch: Record<string, unknown> | Fill | Stroke,\n label: string\n ) {\n for (const n of targetNodes()) {\n const arr = [...n[key]]\n arr[index] = { ...arr[index], ...patch }\n store.updateNodeWithUndo(n.id, { [key]: arr }, label)\n }\n }\n\n function removeArrayItem(key: ArrayPropKey, index: number, label: string) {\n for (const n of targetNodes()) {\n store.updateNodeWithUndo(\n n.id,\n { [key]: (n[key] as unknown[]).filter((_, i) => i !== index) },\n label\n )\n }\n }\n\n function toggleArrayVisibility(key: ArrayPropKey, index: number) {\n for (const n of targetNodes()) {\n const items = n[key] as Array<{ visible: boolean }>\n if (!items[index]) continue\n const arr = [...n[key]]\n arr[index] = { ...arr[index], visible: !items[index].visible }\n store.updateNodeWithUndo(n.id, { [key]: arr }, `Toggle ${key} visibility`)\n }\n }\n\n return { targetNodes, updateArrayItem, removeArrayItem, toggleArrayVisibility }\n}\n\nexport function createNodePropScrubActions(store: Editor) {\n const previousValues = new Map<string, Record<string, number | string>>()\n\n function storePreviousValues(key: string) {\n for (const n of store.getSelectedNodes()) {\n let rec = previousValues.get(n.id)\n if (!rec) {\n rec = {}\n previousValues.set(n.id, rec)\n }\n if (!(key in rec)) {\n rec[key] = n[key as keyof SceneNode] as number | string\n }\n }\n }\n\n function updateProp(key: string, value: number | string) {\n if (store.getSelectedNodes().length > 1) {\n storePreviousValues(key)\n for (const n of store.getSelectedNodes()) {\n store.updateNode(n.id, { [key]: value })\n }\n } else {\n const node = store.getSelectedNode()\n if (node) store.updateNode(node.id, { [key]: value })\n }\n }\n\n function commitProp(key: string, _value: number | string, previous: number | string) {\n if (store.getSelectedNodes().length > 1) {\n for (const n of store.getSelectedNodes()) {\n const prev = previousValues.get(n.id)?.[key] ?? previous\n store.commitNodeUpdate(n.id, { [key]: prev }, `Change ${key}`)\n }\n previousValues.clear()\n } else {\n const node = store.getSelectedNode()\n if (node) {\n store.commitNodeUpdate(node.id, { [key]: previous }, `Change ${key}`)\n }\n }\n }\n\n return { updateProp, commitProp }\n}\n"],"mappings":";;;AAQA,MAAa,QAAQ,OAAO,OAAO;AAKnC,SAAS,mBAAmB,GAAc,GAAuB;CAC/D,IAAI,MAAM,GAAG,OAAO;CACpB,MAAM,QAAQ,OAAO,KAAK,CAAC;CAC3B,MAAM,QAAQ,OAAO,KAAK,CAAC;CAC3B,IAAI,MAAM,WAAW,MAAM,QAAQ,OAAO;CAC1C,KAAK,MAAM,OAAO,OAAO;EACvB,MAAM,SAAS,EAAE;EACjB,MAAM,SAAS,EAAE;EACjB,IAAI,MAAM,QAAQ,MAAM,KAAK,MAAM,QAAQ,MAAM,GAAG;GAClD,IAAI,OAAO,WA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AAI,GAAG,MAAM,KAAK,GAAG,UAAU,KAAK;GAC/D;GACA,eAAe,MAAM;EACvB,OAAO;GACL,MAAM,OAAO,MAAM,gBAAgB;GACnC,IAAI,MACF,MAAM,iBAAiB,KAAK,IAAI,GAAG,MAAM,SAAS,GAAG,UAAU,KAAK;EAExE;CACF;CAEA,OAAO;EAAE;EAAY;CAAW;AAClC"}
|
|
1
|
+
{"version":3,"file":"helpers.js","names":[],"sources":["../../../src/controls/node-props/helpers.ts"],"sourcesContent":["import { computed } from 'vue'\nimport type { ComputedRef } from 'vue'\n\nimport type { Editor } from '@pairdraw/core'\nimport type { Effect, Fill, SceneNode, Stroke } from '@pairdraw/scene-graph'\n\nimport { useSelectedNodeState } from '#vue/editor/selection-state/nodes'\n\nexport const MIXED = Symbol('mixed')\nexport type MixedValue<T> = T | typeof MIXED\n\ntype ArrayItem = Fill | Stroke | Effect | Record<string, unknown>\n\nfunction areArrayItemsEqual(a: ArrayItem, b: ArrayItem): boolean {\n if (a === b) return true\n const aKeys = Object.keys(a)\n const bKeys = Object.keys(b)\n if (aKeys.length !== bKeys.length) return false\n for (const key of aKeys) {\n const aValue = a[key as keyof typeof a]\n const bValue = b[key as keyof typeof b]\n if (Array.isArray(aValue) && Array.isArray(bValue)) {\n if (aValue.length !== bValue.length) return false\n for (let i = 0; i < aValue.length; i++) {\n const left = aValue[i]\n const right = bValue[i]\n if (\n typeof left === 'object' &&\n left != null &&\n typeof right === 'object' &&\n right != null\n ) {\n if (!areArrayItemsEqual(left as ArrayItem, right as ArrayItem)) return false\n } else if (left !== right) {\n return false\n }\n }\n continue\n }\n if (\n typeof aValue === 'object' &&\n aValue != null &&\n typeof bValue === 'object' &&\n bValue != null\n ) {\n if (!areArrayItemsEqual(aValue as ArrayItem, bValue as ArrayItem)) return false\n continue\n }\n if (aValue !== bValue) return false\n }\n return true\n}\n\ntype ArrayPropKey = 'fills' | 'strokes' | 'effects'\n\nexport function createNodePropSelectionState(store: Editor) {\n const { node, nodes } = useSelectedNodeState(store)\n const isMulti = computed(() => nodes.value.length > 1)\n const active = computed(() => node.value !== null || isMulti.value)\n const activeNode = computed(() => node.value ?? (nodes.value[0] as SceneNode | undefined) ?? null)\n\n function merged<K extends keyof SceneNode>(key: K): MixedValue<SceneNode[K]> {\n const all = nodes.value\n if (all.length === 0) return MIXED\n const first = all[0][key]\n for (let i = 1; i < all.length; i++) {\n if (all[i][key] !== first) return MIXED\n }\n // A text layer's own style is its first character's; characters a range styles differently\n // make the row Mixed even though the layer's value is one.\n const mixedInside = all.some(\n (selected) => selected.type === 'TEXT' && store.isTextStyleMixed(selected.id, key)\n )\n return mixedInside ? MIXED : first\n }\n\n function prop<K extends keyof SceneNode>(key: K) {\n return computed(() => merged(key))\n }\n\n function updateAllWithUndo(patch: Partial<SceneNode>, label: string) {\n for (const n of nodes.value) {\n store.updateNodeWithUndo(n.id, patch, label)\n }\n }\n\n return { node, nodes, isMulti, active, activeNode, merged, prop, updateAllWithUndo }\n}\n\nexport function isNodeArrayMixed(nodes: SceneNode[], key: keyof SceneNode): boolean {\n if (nodes.length <= 1) return false\n const first = nodes[0][key]\n if (!Array.isArray(first)) return nodes.some((n) => n[key] !== first)\n for (let i = 1; i < nodes.length; i++) {\n const current = nodes[i][key]\n if (!Array.isArray(current) || current.length !== first.length) return true\n for (let j = 0; j < first.length; j++) {\n const left = first[j]\n const right = current[j]\n if (typeof left === 'object' && typeof right === 'object') {\n if (!areArrayItemsEqual(left as ArrayItem, right as ArrayItem)) return true\n } else if (left !== right) {\n return true\n }\n }\n }\n return false\n}\n\nexport function createNodePropArrayActions({\n store,\n nodes,\n activeNode,\n isMulti\n}: {\n store: Editor\n nodes: ComputedRef<SceneNode[]>\n activeNode: ComputedRef<SceneNode | null>\n isMulti: ComputedRef<boolean>\n}) {\n function targetNodes(): SceneNode[] {\n if (isMulti.value) return nodes.value\n return activeNode.value ? [activeNode.value] : []\n }\n\n function updateArrayItem(\n key: ArrayPropKey,\n index: number,\n patch: Record<string, unknown> | Fill | Stroke,\n label: string\n ) {\n for (const n of targetNodes()) {\n const arr = [...n[key]]\n arr[index] = { ...arr[index], ...patch }\n store.updateNodeWithUndo(n.id, { [key]: arr }, label)\n }\n }\n\n function removeArrayItem(key: ArrayPropKey, index: number, label: string) {\n for (const n of targetNodes()) {\n store.updateNodeWithUndo(\n n.id,\n { [key]: (n[key] as unknown[]).filter((_, i) => i !== index) },\n label\n )\n }\n }\n\n function toggleArrayVisibility(key: ArrayPropKey, index: number) {\n for (const n of targetNodes()) {\n const items = n[key] as Array<{ visible: boolean }>\n if (!items[index]) continue\n const arr = [...n[key]]\n arr[index] = { ...arr[index], visible: !items[index].visible }\n store.updateNodeWithUndo(n.id, { [key]: arr }, `Toggle ${key} visibility`)\n }\n }\n\n return { targetNodes, updateArrayItem, removeArrayItem, toggleArrayVisibility }\n}\n\nexport function createNodePropScrubActions(store: Editor) {\n const previousValues = new Map<string, Record<string, number | string>>()\n\n function storePreviousValues(key: string) {\n for (const n of store.getSelectedNodes()) {\n let rec = previousValues.get(n.id)\n if (!rec) {\n rec = {}\n previousValues.set(n.id, rec)\n }\n if (!(key in rec)) {\n rec[key] = n[key as keyof SceneNode] as number | string\n }\n }\n }\n\n function updateProp(key: string, value: number | string) {\n if (store.getSelectedNodes().length > 1) {\n storePreviousValues(key)\n for (const n of store.getSelectedNodes()) {\n store.updateNode(n.id, { [key]: value })\n }\n } else {\n const node = store.getSelectedNode()\n if (node) store.updateNode(node.id, { [key]: value })\n }\n }\n\n function commitProp(key: string, _value: number | string, previous: number | string) {\n if (store.getSelectedNodes().length > 1) {\n for (const n of store.getSelectedNodes()) {\n const prev = previousValues.get(n.id)?.[key] ?? previous\n store.commitNodeUpdate(n.id, { [key]: prev }, `Change ${key}`)\n }\n previousValues.clear()\n } else {\n const node = store.getSelectedNode()\n if (node) {\n store.commitNodeUpdate(node.id, { [key]: previous }, `Change ${key}`)\n }\n }\n }\n\n return { updateProp, commitProp }\n}\n"],"mappings":";;;AAQA,MA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GAAG;GACvC,oBAAoB,GAAG;GACvB,KAAK,MAAM,KAAK,MAAM,iBAAiB,GACrC,MAAM,WAAW,EAAE,IAAI,GAAG,MAAM,MAAM,CAAC;EAE3C,OAAO;GACL,MAAM,OAAO,MAAM,gBAAgB;GACnC,IAAI,MAAM,MAAM,WAAW,KAAK,IAAI,GAAG,MAAM,MAAM,CAAC;EACtD;CACF;CAEA,SAAS,WAAW,KAAa,QAAyB,UAA2B;EACnF,IAAI,MAAM,iBAAiB,CAAC,CAAC,SAAS,GAAG;GACvC,KAAK,MAAM,KAAK,MAAM,iBAAiB,GAAG;IACxC,MAAM,OAAO,eAAe,IAAI,EAAE,EAAE,CAAC,GAAG,QAAQ;IAChD,MAAM,iBAAiB,EAAE,IAAI,GAAG,MAAM,KAAK,GAAG,UAAU,KAAK;GAC/D;GACA,eAAe,MAAM;EACvB,OAAO;GACL,MAAM,OAAO,MAAM,gBAAgB;GACnC,IAAI,MACF,MAAM,iBAAiB,KAAK,IAAI,GAAG,MAAM,SAAS,GAAG,UAAU,KAAK;EAExE;CACF;CAEA,OAAO;EAAE;EAAY;CAAW;AAClC"}
|
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
import { NumberBindingPath, useNumberVariableBinding } from "./use.js";
|
|
1
|
+
import { NumberBindingPath, effectBindingPath, layoutGridBindingPath, useNumberVariableBinding } from "./use.js";
|
|
2
2
|
import { displayNumberFromStored, storedNumberFromDisplay, textLengthVariableValue } from "./scale.js";
|
|
3
|
-
export { type NumberBindingPath, displayNumberFromStored, storedNumberFromDisplay, textLengthVariableValue, useNumberVariableBinding };
|
|
3
|
+
export { type NumberBindingPath, displayNumberFromStored, effectBindingPath, layoutGridBindingPath, storedNumberFromDisplay, textLengthVariableValue, useNumberVariableBinding };
|
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
import { useNumberVariableBinding } from "./use.js";
|
|
1
|
+
import { effectBindingPath, layoutGridBindingPath, useNumberVariableBinding } from "./use.js";
|
|
2
2
|
import { displayNumberFromStored, storedNumberFromDisplay, textLengthVariableValue } from "./scale.js";
|
|
3
|
-
export { displayNumberFromStored, storedNumberFromDisplay, textLengthVariableValue, useNumberVariableBinding };
|
|
3
|
+
export { displayNumberFromStored, effectBindingPath, layoutGridBindingPath, storedNumberFromDisplay, textLengthVariableValue, useNumberVariableBinding };
|
|
@@ -1,6 +1,11 @@
|
|
|
1
1
|
import { VariableBindingState } from "../variable-binding/use.js";
|
|
2
|
+
import { EffectBindingField, LayoutGridBindingField } from "@pairdraw/scene-graph/variables";
|
|
2
3
|
//#region src/controls/number-variable-binding/use.d.ts
|
|
3
|
-
|
|
4
|
+
/** The binding path of a shadow field on the n-th effect. */
|
|
5
|
+
declare function effectBindingPath(index: number, field: EffectBindingField): NumberBindingPath;
|
|
6
|
+
/** The binding path of a layout grid's field on the n-th grid. */
|
|
7
|
+
declare function layoutGridBindingPath(index: number, field: LayoutGridBindingField): NumberBindingPath;
|
|
8
|
+
type NumberBindingPath = 'width' | 'height' | 'minWidth' | 'maxWidth' | 'minHeight' | 'maxHeight' | 'cornerRadius' | 'topLeftRadius' | 'topRightRadius' | 'bottomLeftRadius' | 'bottomRightRadius' | 'itemSpacing' | 'counterAxisSpacing' | 'paddingTop' | 'paddingRight' | 'paddingBottom' | 'paddingLeft' | 'opacity' | 'fontSize' | 'fontWeight' | 'lineHeight' | 'letterSpacing' | 'paragraphSpacing' | 'paragraphIndent' | 'gridColumnGap' | 'gridRowGap' | `effects/${number}/${EffectBindingField}` | `layoutGrids/${number}/${LayoutGridBindingField}`;
|
|
4
9
|
declare function useNumberVariableBinding(path: NumberBindingPath): {
|
|
5
10
|
numberVariables: import("vue").ComputedRef<import("@pairdraw/scene-graph").Variable[]>;
|
|
6
11
|
createAndBindVariable: (nodeId: string, value: number, name?: string) => void;
|
|
@@ -15,5 +20,5 @@ declare function useNumberVariableBinding(path: NumberBindingPath): {
|
|
|
15
20
|
unbindVariable: (nodeId: string, index?: number) => void;
|
|
16
21
|
};
|
|
17
22
|
//#endregion
|
|
18
|
-
export { NumberBindingPath, useNumberVariableBinding };
|
|
23
|
+
export { NumberBindingPath, effectBindingPath, layoutGridBindingPath, useNumberVariableBinding };
|
|
19
24
|
//# sourceMappingURL=use.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"use.d.ts","names":[],"sources":["../../../src/controls/number-variable-binding/use.ts"],"mappings":";;
|
|
1
|
+
{"version":3,"file":"use.d.ts","names":[],"sources":["../../../src/controls/number-variable-binding/use.ts"],"mappings":";;;;iBAMgB,kBAAkB,eAAe,OAAO,qBAAqB;;iBAK7D,sBACd,eACA,OAAO,yBACN;KAIS,idA2Ba,gDACI;iBAEb,yBAAyB,MAAM;;EAMN,wBAAA,gBAAM,eAAe;;;;;;;0DANf"}
|
|
@@ -1,6 +1,14 @@
|
|
|
1
1
|
import { createAndBindNumberVariable } from "../binding-provider/number.js";
|
|
2
2
|
import { useVariableBinding } from "../variable-binding/use.js";
|
|
3
3
|
//#region src/controls/number-variable-binding/use.ts
|
|
4
|
+
/** The binding path of a shadow field on the n-th effect. */
|
|
5
|
+
function effectBindingPath(index, field) {
|
|
6
|
+
return `effects/${index}/${field}`;
|
|
7
|
+
}
|
|
8
|
+
/** The binding path of a layout grid's field on the n-th grid. */
|
|
9
|
+
function layoutGridBindingPath(index, field) {
|
|
10
|
+
return `layoutGrids/${index}/${field}`;
|
|
11
|
+
}
|
|
4
12
|
function useNumberVariableBinding(path) {
|
|
5
13
|
const binding = useVariableBinding({
|
|
6
14
|
type: "FLOAT",
|
|
@@ -19,6 +27,6 @@ function useNumberVariableBinding(path) {
|
|
|
19
27
|
};
|
|
20
28
|
}
|
|
21
29
|
//#endregion
|
|
22
|
-
export { useNumberVariableBinding };
|
|
30
|
+
export { effectBindingPath, layoutGridBindingPath, useNumberVariableBinding };
|
|
23
31
|
|
|
24
32
|
//# sourceMappingURL=use.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"use.js","names":[],"sources":["../../../src/controls/number-variable-binding/use.ts"],"sourcesContent":["import { createAndBindNumberVariable } from '#vue/controls/binding-provider/number'\nimport { useVariableBinding } from '#vue/controls/variable-binding/use'\n\nexport type NumberBindingPath =\n | 'width'\n | 'height'\n | 'minWidth'\n | 'maxWidth'\n | 'minHeight'\n | 'maxHeight'\n | 'cornerRadius'\n | 'topLeftRadius'\n | 'topRightRadius'\n | 'bottomLeftRadius'\n | 'bottomRightRadius'\n | 'itemSpacing'\n | 'counterAxisSpacing'\n | 'paddingTop'\n | 'paddingRight'\n | 'paddingBottom'\n | 'paddingLeft'\n | 'opacity'\n | 'fontSize'\n | 'fontWeight'\n | 'lineHeight'\n | 'letterSpacing'\n | 'paragraphSpacing'\n | 'paragraphIndent'\n\nexport function useNumberVariableBinding(path: NumberBindingPath) {\n const binding = useVariableBinding({\n type: 'FLOAT',\n path\n })\n\n function createAndBindVariable(nodeId: string, value: number, name?: string) {\n createAndBindNumberVariable(binding.store, { nodeId, path: binding.bindingPath() }, value, name)\n }\n\n return {\n ...binding,\n numberVariables: binding.variables,\n createAndBindVariable\n }\n}\n"],"mappings":"
|
|
1
|
+
{"version":3,"file":"use.js","names":[],"sources":["../../../src/controls/number-variable-binding/use.ts"],"sourcesContent":["import type { EffectBindingField, LayoutGridBindingField } from '@pairdraw/scene-graph/variables'\n\nimport { createAndBindNumberVariable } from '#vue/controls/binding-provider/number'\nimport { useVariableBinding } from '#vue/controls/variable-binding/use'\n\n/** The binding path of a shadow field on the n-th effect. */\nexport function effectBindingPath(index: number, field: EffectBindingField): NumberBindingPath {\n return `effects/${index}/${field}`\n}\n\n/** The binding path of a layout grid's field on the n-th grid. */\nexport function layoutGridBindingPath(\n index: number,\n field: LayoutGridBindingField\n): NumberBindingPath {\n return `layoutGrids/${index}/${field}`\n}\n\nexport type NumberBindingPath =\n | 'width'\n | 'height'\n | 'minWidth'\n | 'maxWidth'\n | 'minHeight'\n | 'maxHeight'\n | 'cornerRadius'\n | 'topLeftRadius'\n | 'topRightRadius'\n | 'bottomLeftRadius'\n | 'bottomRightRadius'\n | 'itemSpacing'\n | 'counterAxisSpacing'\n | 'paddingTop'\n | 'paddingRight'\n | 'paddingBottom'\n | 'paddingLeft'\n | 'opacity'\n | 'fontSize'\n | 'fontWeight'\n | 'lineHeight'\n | 'letterSpacing'\n | 'paragraphSpacing'\n | 'paragraphIndent'\n | 'gridColumnGap'\n | 'gridRowGap'\n | `effects/${number}/${EffectBindingField}`\n | `layoutGrids/${number}/${LayoutGridBindingField}`\n\nexport function useNumberVariableBinding(path: NumberBindingPath) {\n const binding = useVariableBinding({\n type: 'FLOAT',\n path\n })\n\n function createAndBindVariable(nodeId: string, value: number, name?: string) {\n createAndBindNumberVariable(binding.store, { nodeId, path: binding.bindingPath() }, value, name)\n }\n\n return {\n ...binding,\n numberVariables: binding.variables,\n createAndBindVariable\n }\n}\n"],"mappings":";;;;AAMA,SAAgB,kBAAkB,OAAe,OAA8C;CAC7F,OAAO,WAAW,MAAM,GAAG;AAC7B;;AAGA,SAAgB,sBACd,OACA,OACmB;CACnB,OAAO,eAAe,MAAM,GAAG;AACjC;AAgCA,SAAgB,yBAAyB,MAAyB;CAChE,MAAM,UAAU,mBAAmB;EACjC,MAAM;EACN;CACF,CAAC;CAED,SAAS,sBAAsB,QAAgB,OAAe,MAAe;EAC3E,4BAA4B,QAAQ,OAAO;GAAE;GAAQ,MAAM,QAAQ,YAAY;EAAE,GAAG,OAAO,IAAI;CACjG;CAEA,OAAO;EACL,GAAG;EACH,iBAAiB,QAAQ;EACzB;CACF;AACF"}
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
import { computed, onScopeDispose, ref, watch } from "vue";
|
|
2
|
+
import { fontManager } from "@pairdraw/core/text";
|
|
3
|
+
import { uniq } from "es-toolkit/array";
|
|
4
|
+
//#region src/controls/typography/arrivals.ts
|
|
5
|
+
/**
|
|
6
|
+
* The families the selected text draws in, and a signal that changes when a face of any of them
|
|
7
|
+
* arrives. Axes and features both read it, so a font that finishes loading after selection still
|
|
8
|
+
* reaches the panel without another selection.
|
|
9
|
+
*/
|
|
10
|
+
function useFontArrivals(nodes) {
|
|
11
|
+
const arrived = ref(0);
|
|
12
|
+
const families = computed(() => uniq(nodes.value.map((node) => node.fontFamily)));
|
|
13
|
+
function request(current) {
|
|
14
|
+
for (const family of current) {
|
|
15
|
+
if (fontManager.loadedFamilyFaces(family) !== void 0) continue;
|
|
16
|
+
fontManager.familyFaces(family).then(() => arrived.value++);
|
|
17
|
+
}
|
|
18
|
+
}
|
|
19
|
+
watch(families, request, { immediate: true });
|
|
20
|
+
onScopeDispose(fontManager.onFamilyFacesReset(() => {
|
|
21
|
+
arrived.value++;
|
|
22
|
+
request(families.value);
|
|
23
|
+
}));
|
|
24
|
+
onScopeDispose(fontManager.onFaceLoaded((family) => {
|
|
25
|
+
if (families.value.includes(family)) arrived.value++;
|
|
26
|
+
}));
|
|
27
|
+
return {
|
|
28
|
+
arrived,
|
|
29
|
+
families
|
|
30
|
+
};
|
|
31
|
+
}
|
|
32
|
+
//#endregion
|
|
33
|
+
export { useFontArrivals };
|
|
34
|
+
|
|
35
|
+
//# sourceMappingURL=arrivals.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"arrivals.js","names":[],"sources":["../../../src/controls/typography/arrivals.ts"],"sourcesContent":["import { uniq } from 'es-toolkit/array'\nimport { computed, onScopeDispose, ref, watch, type ComputedRef } from 'vue'\n\nimport { fontManager } from '@pairdraw/core/text'\nimport type { SceneNode } from '@pairdraw/scene-graph'\n\n/**\n * The families the selected text draws in, and a signal that changes when a face of any of them\n * arrives. Axes and features both read it, so a font that finishes loading after selection still\n * reaches the panel without another selection.\n */\nexport function useFontArrivals(nodes: ComputedRef<SceneNode[]>) {\n const arrived = ref(0)\n const families = computed(() => uniq(nodes.value.map((node) => node.fontFamily)))\n\n function request(current: readonly string[]) {\n for (const family of current) {\n if (fontManager.loadedFamilyFaces(family) !== undefined) continue\n void fontManager.familyFaces(family).then(() => arrived.value++)\n }\n }\n watch(families, request, { immediate: true })\n onScopeDispose(\n fontManager.onFamilyFacesReset(() => {\n arrived.value++\n request(families.value)\n })\n )\n // Faces may also arrive by the renderer, a paste or a script: the panel follows any of them.\n onScopeDispose(\n fontManager.onFaceLoaded((family) => {\n if (families.value.includes(family)) arrived.value++\n })\n )\n\n return { arrived, families }\n}\n"],"mappings":";;;;;;;;;AAWA,SAAgB,gBAAgB,OAAiC;CAC/D,MAAM,UAAU,IAAI,CAAC;CACrB,MAAM,WAAW,eAAe,KAAK,MAAM,MAAM,KAAK,SAAS,KAAK,UAAU,CAAC,CAAC;CAEhF,SAAS,QAAQ,SAA4B;EAC3C,KAAK,MAAM,UAAU,SAAS;GAC5B,IAAI,YAAY,kBAAkB,MAAM,MAAM,KAAA,GAAW;GACzD,YAAiB,YAAY,MAAM,CAAC,CAAC,WAAW,QAAQ,OAAO;EACjE;CACF;CACA,MAAM,UAAU,SAAS,EAAE,WAAW,KAAK,CAAC;CAC5C,eACE,YAAY,yBAAyB;EACnC,QAAQ;EACR,QAAQ,SAAS,KAAK;CACxB,CAAC,CACH;CAEA,eACE,YAAY,cAAc,WAAW;EACnC,IAAI,SAAS,MAAM,SAAS,MAAM,GAAG,QAAQ;CAC/C,CAAC,CACH;CAEA,OAAO;EAAE;EAAS;CAAS;AAC7B"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"axes.d.ts","names":[],"sources":["../../../src/controls/typography/axes.ts"],"mappings":";;;;;;;
|
|
1
|
+
{"version":3,"file":"axes.d.ts","names":[],"sources":["../../../src/controls/typography/axes.ts"],"mappings":";;;;;;;UAaiB,uBAAuB,KAAK;EAC3C,OAAO"}
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { MIXED } from "../node-props/helpers.js";
|
|
2
2
|
import { useUndoBatch } from "../undo-batch/use.js";
|
|
3
|
+
import { useFontArrivals } from "./arrivals.js";
|
|
3
4
|
import { computed } from "vue";
|
|
4
5
|
import { drawnFontAxes } from "@pairdraw/core/canvas";
|
|
5
6
|
import { layerTextStyleChanges } from "@pairdraw/core/text";
|
|
@@ -60,7 +61,9 @@ function wholeTextAxisChanges(node, edit) {
|
|
|
60
61
|
* them, and actions that set them. Layers in different families or slants have no shared axes.
|
|
61
62
|
*/
|
|
62
63
|
function createTypographyAxes(editor, nodes) {
|
|
64
|
+
const { arrived } = useFontArrivals(nodes);
|
|
63
65
|
const axes = computed(() => {
|
|
66
|
+
arrived.value;
|
|
64
67
|
const first = nodes.value.at(0);
|
|
65
68
|
if (!first) return [];
|
|
66
69
|
if (!nodes.value.every((node) => node.fontFamily === first.fontFamily && node.italic === first.italic)) return [];
|
|
@@ -1 +1 @@
|
|
|
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 }\n}\n"],"mappings":";;;;;;;AAgBA,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;;AASA,SAAS,YAAY,MAAc,OAAyB;CAC1D,OAAO;EACL,aAAa,eAAe,CAC1B,GAAG,WAAW,QAAQ,cAAc,UAAU,SAAS,IAAI,GAC3D;GAAE;GAAM;EAAM,CAChB;EACA,GAAI,SAAS,eAAe,EAAE,SAAS,EAAE,yBAAyB,MA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U,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"}
|
|
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 { useFontArrivals } from '#vue/controls/typography/arrivals'\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 // A font that finishes loading after selection re-reads its axes, as the feature list does.\n const { arrived } = useFontArrivals(nodes)\n const axes = computed<TypographyAxis[]>(() => {\n void arrived.value\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 }\n}\n"],"mappings":";;;;;;;;AAiBA,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;;AASA,SAAS,YAAY,MAAc,OAAyB;CAC1D,OAAO;EACL,aAAa,eAAe,CAC1B,GAAG,W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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"}
|
|
@@ -1,6 +1,7 @@
|
|
|
1
|
+
import { useFontArrivals } from "./arrivals.js";
|
|
1
2
|
import { TYPOGRAPHY_WEIGHTS } from "./weights.js";
|
|
2
|
-
import { computed
|
|
3
|
-
import {
|
|
3
|
+
import { computed } from "vue";
|
|
4
|
+
import { uniqBy } from "es-toolkit";
|
|
4
5
|
import { fontManager, standardFace, textStyleName } from "@pairdraw/core/text";
|
|
5
6
|
import { styleSpelling } from "@pairdraw/scene-graph/font-style";
|
|
6
7
|
//#region src/controls/typography/faces.ts
|
|
@@ -10,19 +11,7 @@ import { styleSpelling } from "@pairdraw/scene-graph/font-style";
|
|
|
10
11
|
* family it cannot read.
|
|
11
12
|
*/
|
|
12
13
|
function useFamilyFaces(nodes) {
|
|
13
|
-
const arrived =
|
|
14
|
-
const families = computed(() => uniq(nodes.value.map((node) => node.fontFamily)));
|
|
15
|
-
function request(current) {
|
|
16
|
-
for (const family of current) {
|
|
17
|
-
if (fontManager.loadedFamilyFaces(family) !== void 0) continue;
|
|
18
|
-
fontManager.familyFaces(family).then(() => arrived.value++);
|
|
19
|
-
}
|
|
20
|
-
}
|
|
21
|
-
watch(families, request, { immediate: true });
|
|
22
|
-
onScopeDispose(fontManager.onFamilyFacesReset(() => {
|
|
23
|
-
arrived.value++;
|
|
24
|
-
request(families.value);
|
|
25
|
-
}));
|
|
14
|
+
const { arrived } = useFontArrivals(nodes);
|
|
26
15
|
/** Whether a layer's family has this face, or nothing says it has not. */
|
|
27
16
|
function supports(node, weight, italic) {
|
|
28
17
|
arrived.value;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"faces.js","names":[],"sources":["../../../src/controls/typography/faces.ts"],"sourcesContent":["import {
|
|
1
|
+
{"version":3,"file":"faces.js","names":[],"sources":["../../../src/controls/typography/faces.ts"],"sourcesContent":["import { uniqBy } from 'es-toolkit'\nimport { computed, type ComputedRef } from 'vue'\n\nimport { fontManager, standardFace, textStyleName } from '@pairdraw/core/text'\nimport type { SceneNode } from '@pairdraw/scene-graph'\nimport { styleSpelling } from '@pairdraw/scene-graph/font-style'\n\nimport { useFontArrivals } from '#vue/controls/typography/arrivals'\nimport { TYPOGRAPHY_WEIGHTS } from '#vue/controls/typography/weights'\n\n/**\n * The faces of the selected text layers' families, read as they arrive. A family whose faces are\n * not known yet, or cannot be, offers every weight, as Figma shows a generic style list for a\n * family it cannot read.\n */\nexport function useFamilyFaces(nodes: ComputedRef<SceneNode[]>) {\n // Bumped when a family's faces arrive, so the lists that read them follow.\n const { arrived } = useFontArrivals(nodes)\n\n /** Whether a layer's family has this face, or nothing says it has not. */\n function supports(node: SceneNode, weight: number, italic: boolean): boolean {\n void arrived.value\n return fontManager.offersFace(node.fontFamily, weight, italic)\n }\n\n /**\n * Whether a layer's family has a face of this name in the layer's slant, which choosing it\n * keeps, or nothing says it has not.\n */\n function offersStyle(node: SceneNode, style: string): boolean {\n const faces = fontManager.loadedFamilyFaces(node.fontFamily)\n return (\n !faces ||\n faces.some(\n (face) => face.italic === node.italic && styleSpelling(face.style) === styleSpelling(style)\n )\n )\n }\n\n /**\n * The faces of the first layer's family in its slant, lightest first, by the names its fonts\n * give them, as Figma's style menu lists a family's faces (\"Book\" and \"Roman\" apart), and only\n * those every selected layer's family has. A family whose faces are unknown offers every\n * standard weight. The faces the layers are set in stay listed, by the layers' own names, so\n * the field still names one their family lacks or a file spells its own way.\n */\n // Each option's value is the face's name, which is also what choosing it sets.\n const faces = computed(() => {\n void arrived.value\n const first = nodes.value.at(0)\n if (!first) return []\n const known =\n fontManager.loadedFamilyFaces(first.fontFamily) ??\n TYPOGRAPHY_WEIGHTS.map(({ value }) => standardFace(value, first.italic))\n const listed = known\n .filter((face) => face.italic === first.italic)\n .toSorted((a, b) => a.weight - b.weight)\n .map((face) => face.style)\n .filter((style) => nodes.value.every((node) => offersStyle(node, style)))\n const own = nodes.value.map((node) => textStyleName(node))\n const names = uniqBy(\n [...listed, ...own].map(\n (style) => own.find((name) => styleSpelling(name) === styleSpelling(style)) ?? style\n ),\n styleSpelling\n )\n return names.map((style) => ({ value: style, label: style }))\n })\n\n /** The name of the face a layer is set in, as its font names it once its faces arrive. */\n function styleName(node: SceneNode): string {\n void arrived.value\n return textStyleName(node)\n }\n\n return { faces, supports, styleName }\n}\n"],"mappings":";;;;;;;;;;;;AAeA,SAAgB,eAAe,OAAiC;CAE9D,MAAM,EAAE,YAAY,gBAAgB,KAAK;;CAGzC,SAAS,SAAS,MAAiB,QAAgB,QAA0B;EAC3E,QAAa;EACb,OAAO,YAAY,WAAW,KAAK,YAAY,QAAQ,MAAM;CAC/D;;;;;CAMA,SAAS,YAAY,MAAiB,OAAwB;EAC5D,MAAM,QAAQ,YAAY,kBAAkB,KAAK,UAAU;EAC3D,OACE,CAAC,SACD,MAAM,MACH,SAAS,KAAK,WAAW,KAAK,UAAU,cAAc,KAAK,KAAK,MAAM,cAAc,KAAK,CAC5F;CAEJ;;;;;;;;CAUA,MAAM,QAAQ,eAAe;EAC3B,QAAa;EACb,MAAM,QAAQ,MAAM,MAAM,GAAG,CAAC;EAC9B,IAAI,CAAC,OAAO,OAAO,CAAC;EAIpB,MAAM,UAFJ,YAAY,kBAAkB,MAAM,UAAU,KAC9C,mBAAmB,KAAK,EAAE,YAAY,aAAa,OAAO,MAAM,MAAM,CAAC,EAAA,CAEtE,QAAQ,SAAS,KAAK,WAAW,MAAM,MAAM,CAAC,CAC9C,UAAU,GAAG,MAAM,EAAE,SAAS,EAAE,MAAM,CAAC,CACvC,KAAK,SAAS,KAAK,KAAK,CAAC,CACzB,QAAQ,UAAU,MAAM,MAAM,OAAO,SAAS,YAAY,MAAM,KAAK,CAAC,CAAC;EAC1E,MAAM,MAAM,MAAM,MAAM,KAAK,SAAS,cAAc,IAAI,CAAC;EAOzD,OANc,OACZ,CAAC,GAAG,QAAQ,GAAG,GAAG,CAAC,CAAC,KACjB,UAAU,IAAI,MAAM,SAAS,cAAc,IAAI,MAAM,cAAc,KAAK,CAAC,KAAK,KACjF,GACA,aAES,CAAC,CAAC,KAAK,WAAW;GAAE,OAAO;GAAO,OAAO;EAAM,EAAE;CAC9D,CAAC;;CAGD,SAAS,UAAU,MAAyB;EAC1C,QAAa;EACb,OAAO,cAAc,IAAI;CAC3B;CAEA,OAAO;EAAE;EAAO;EAAU;CAAU;AACtC"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"features.d.ts","names":[],"sources":["../../../src/controls/typography/features.ts"],"mappings":";;;;;;
|
|
1
|
+
{"version":3,"file":"features.d.ts","names":[],"sources":["../../../src/controls/typography/features.ts"],"mappings":";;;;;;UAWiB;EACf;;EAEA;;;;;;;iBAiDc,yBAAyB,QAAQ,QAAQ,OAAO,YAAY;;EAkCtD,QAAA,gBAAS;EASX,MAAA,aAAM"}
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { MIXED } from "../node-props/helpers.js";
|
|
2
|
-
import {
|
|
2
|
+
import { useFontArrivals } from "./arrivals.js";
|
|
3
|
+
import { computed } from "vue";
|
|
3
4
|
import { fontManager } from "@pairdraw/core/text";
|
|
4
5
|
import { uniq } from "es-toolkit/array";
|
|
5
6
|
//#region src/controls/typography/features.ts
|
|
@@ -50,22 +51,7 @@ function featureOrder(tag) {
|
|
|
50
51
|
* families share the features every one of their fonts has.
|
|
51
52
|
*/
|
|
52
53
|
function createTypographyFeatures(editor, nodes) {
|
|
53
|
-
const arrived =
|
|
54
|
-
const families = computed(() => uniq(nodes.value.map((node) => node.fontFamily)));
|
|
55
|
-
function request(current) {
|
|
56
|
-
for (const family of current) {
|
|
57
|
-
if (fontManager.loadedFamilyFaces(family) !== void 0) continue;
|
|
58
|
-
fontManager.familyFaces(family).then(() => arrived.value++);
|
|
59
|
-
}
|
|
60
|
-
}
|
|
61
|
-
request(families.value);
|
|
62
|
-
onScopeDispose(fontManager.onFamilyFacesReset(() => {
|
|
63
|
-
arrived.value++;
|
|
64
|
-
request(families.value);
|
|
65
|
-
}));
|
|
66
|
-
onScopeDispose(fontManager.onFaceLoaded((family) => {
|
|
67
|
-
if (families.value.includes(family)) arrived.value++;
|
|
68
|
-
}));
|
|
54
|
+
const { arrived, families } = useFontArrivals(nodes);
|
|
69
55
|
const available = computed(() => {
|
|
70
56
|
arrived.value;
|
|
71
57
|
if (families.value.at(0) === void 0 || nodes.value.length === 0) return [];
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"features.js","names":[],"sources":["../../../src/controls/typography/features.ts"],"sourcesContent":["import { uniq } from 'es-toolkit/array'\nimport { computed,
|
|
1
|
+
{"version":3,"file":"features.js","names":[],"sources":["../../../src/controls/typography/features.ts"],"sourcesContent":["import { uniq } from 'es-toolkit/array'\nimport { computed, type ComputedRef } from 'vue'\n\nimport type { Editor } from '@pairdraw/core'\nimport { fontManager } from '@pairdraw/core/text'\nimport type { FontFeature, SceneNode } from '@pairdraw/scene-graph'\n\nimport { MIXED, type MixedValue } from '#vue/controls/node-props/use'\nimport { useFontArrivals } from '#vue/controls/typography/arrivals'\n\n/** One OpenType feature the selected text's font has, as the panel's switch list offers it. */\nexport interface TypographyFeature {\n tag: string\n /** One of the switches Figma always offers, whether or not the font lists the tag. */\n standard: boolean\n}\n\n/** The common switches Figma always shows for text; the font's own features follow them. */\nexport const STANDARD_FEATURES = ['LIGA', 'CALT', 'KERN'] as const\n\n/** The features a font has, in a stable order: the common controls first, then the font's own. */\nconst COMMON_ORDER = [\n 'LIGA',\n 'CALT',\n 'DLIG',\n 'HLIG',\n 'KERN',\n 'LNUM',\n 'ONUM',\n 'PNUM',\n 'TNUM',\n 'FRAC',\n 'AFRC',\n 'ORDN',\n 'ZERO',\n 'SMCP',\n 'PCAP',\n 'C2SC',\n 'C2PC',\n 'UNIC',\n 'TITL',\n 'CASE',\n 'SINF',\n 'SUBS',\n 'SUPS'\n]\n\nfunction featureOrder(tag: string): number {\n const common = COMMON_ORDER.indexOf(tag)\n if (common !== -1) return common\n // Stylistic sets and character variants follow, numbered; anything else sorts after them.\n const set = /^SS(\\d{2})$/.exec(tag)\n if (set) return COMMON_ORDER.length + Number(set[1])\n const variant = /^CV(\\d{2})$/.exec(tag)\n if (variant) return COMMON_ORDER.length + 100 + Number(variant[1])\n return COMMON_ORDER.length + 200\n}\n\n/**\n * The OpenType features of the selected text layers' font, as Figma's type settings offer them:\n * only the features the font actually has, and actions that toggle them. Layers in different\n * families share the features every one of their fonts has.\n */\nexport function createTypographyFeatures(editor: Editor, nodes: ComputedRef<SceneNode[]>) {\n // Bumped when a family's faces arrive, so the list follows a font that loads after selection.\n const { arrived, families } = useFontArrivals(nodes)\n\n const available = computed<TypographyFeature[]>(() => {\n void arrived.value\n const first = families.value.at(0)\n if (first === undefined || nodes.value.length === 0) return []\n let shared: string[] | null = null\n for (const family of families.value) {\n const tags = fontManager.familyFeatures(family)\n // Until a family's font is loaded its features are unknown: the common switches stay, and\n // the font's own join them once it arrives.\n if (tags === undefined || tags === null) {\n return STANDARD_FEATURES.map((tag) => ({ tag, standard: true }))\n }\n shared = shared === null ? tags : shared.filter((tag) => tags.includes(tag))\n }\n // The common switches stay offered beside the font's own, as Figma keeps them for any font.\n const tags = uniq([...STANDARD_FEATURES, ...(shared ?? [])])\n return tags\n .map((tag) => ({\n tag,\n standard: (STANDARD_FEATURES as readonly string[]).includes(tag)\n }))\n .sort(\n (a, b) =>\n Number(b.standard) - Number(a.standard) ||\n featureOrder(a.tag) - featureOrder(b.tag) ||\n a.tag.localeCompare(b.tag)\n )\n })\n\n /** Whether a feature is on for every selected text, MIXED when they differ; unset reads on. */\n function state(tag: string): MixedValue<boolean> {\n const values = nodes.value.map(\n (node) => node.fontFeatures.find((feature) => feature.tag === tag)?.enabled ?? true\n )\n const first = values.at(0)\n return values.every((value) => value === first) ? (first ?? true) : MIXED\n }\n\n /** Toggles one feature on every selected text, keeping its other features and its ranges'. */\n function set(tag: string, enabled: boolean) {\n const targets = nodes.value\n if (targets.length === 0) return\n editor.undo.runBatch(`Change ${tag} feature`, () => {\n for (const target of targets) {\n const node = editor.graph.getNode(target.id) ?? target\n // The toggled tag keeps its place in the list, so a range whose features now equal the\n // text's own keeps its run instead of being stripped as redundant.\n const merge = (features: FontFeature[]): FontFeature[] =>\n features.some((feature) => feature.tag === tag)\n ? features.map((feature) => (feature.tag === tag ? { tag, enabled } : feature))\n : [...features, { tag, enabled }]\n // A range with its own features keeps them, with the toggled tag replaced, as an axis\n // edit keeps the other axes a range sets. layerChanges strips the changed style from\n // the runs it recomputes, so the merged runs go on after it, not through it.\n const styleRuns = node.styleRuns.map((run) =>\n run.style.fontFeatures\n ? { ...run, style: { ...run.style, fontFeatures: merge(run.style.fontFeatures) } }\n : run\n )\n const changes = editor.layerChanges(target.id, { fontFeatures: merge(node.fontFeatures) })\n editor.updateNodeWithUndo(target.id, { ...changes, styleRuns }, `Change ${tag} feature`)\n }\n })\n }\n\n return { available, state, set }\n}\n"],"mappings":";;;;;;;AAkBA,MAAa,oBAAoB;CAAC;CAAQ;CAAQ;AAAM;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G,CAC7B;CACJ,CAAC;;CAGD,SAAS,MAAM,KAAkC;EAC/C,MAAM,SAAS,MAAM,MAAM,KACxB,SAAS,KAAK,aAAa,MAAM,YAAY,QAAQ,QAAQ,GAAG,CAAC,EAAE,WAAW,IACjF;EACA,MAAM,QAAQ,OAAO,GAAG,CAAC;EACzB,OAAO,OAAO,OAAO,UAAU,UAAU,KAAK,IAAK,SAAS,OAAQ;CACtE;;CAGA,SAAS,IAAI,KAAa,SAAkB;EAC1C,MAAM,UAAU,MAAM;EACtB,IAAI,QAAQ,WAAW,GAAG;EAC1B,OAAO,KAAK,SAAS,UAAU,IAAI,iBAAiB;GAClD,KAAK,MAAM,UAAU,SAAS;IAC5B,MAAM,OAAO,OAAO,MAAM,QAAQ,OAAO,EAAE,KAAK;IAGhD,MAAM,SAAS,aACb,SAAS,MAAM,YAAY,QAAQ,QAAQ,GAAG,IAC1C,SAAS,KAAK,YAAa,QAAQ,QAAQ,MAAM;KAAE;KAAK;IAAQ,IAAI,OAAQ,IAC5E,CAAC,GAAG,UAAU;KAAE;KAAK;IAAQ,CAAC;IAIpC,MAAM,YAAY,KAAK,UAAU,KAAK,QACpC,IAAI,MAAM,eACN;KAAE,GAAG;KAAK,OAAO;MAAE,GAAG,IAAI;MAAO,cAAc,MAAM,IAAI,MAAM,YAAY;KAAE;IAAE,IAC/E,GACN;IACA,MAAM,UAAU,OAAO,aAAa,OAAO,IAAI,EAAE,cAAc,MAAM,KAAK,YAAY,EAAE,CAAC;IACzF,OAAO,mBAAmB,OAAO,IAAI;KAAE,GAAG;KAAS;IAAU,GAAG,UAAU,IAAI,SAAS;GACzF;EACF,CAAC;CACH;CAEA,OAAO;EAAE;EAAW;EAAO;CAAI;AACjC"}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import { EditorCommand, EditorCommandId, EditorCommandMenuItem } from "./types.js";
|
|
2
|
+
//#region src/editor/commands/actions.d.ts
|
|
3
|
+
declare function createEditorCommandActions(commands: Record<EditorCommandId, EditorCommand>): {
|
|
4
|
+
getCommand: (id: EditorCommandId) => EditorCommand;
|
|
5
|
+
runCommand: (id: EditorCommandId) => void;
|
|
6
|
+
menuItem: (id: EditorCommandId, shortcut?: string | undefined) => EditorCommandMenuItem;
|
|
7
|
+
};
|
|
8
|
+
//#endregion
|
|
9
|
+
export { createEditorCommandActions };
|
|
10
|
+
//# sourceMappingURL=actions.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"actions.d.ts","names":[],"sources":["../../../src/editor/commands/actions.ts"],"mappings":";;iBAOgB,2BAA2B,UAAU,OAAO,iBAAiB;EACnD,aAAA,IAAA,oBAAe;EAIf,aAAA,IAAA;EAclB,WAAA,IAAA,iBAAe,kCAElB"}
|
|
@@ -1,5 +1,7 @@
|
|
|
1
|
+
import { reportCommandRefusal } from "./refusals.js";
|
|
1
2
|
import { editorCommandMetadata } from "./registry.js";
|
|
2
3
|
import { formatShortcut } from "./shortcut.js";
|
|
4
|
+
import { InstanceGuardError } from "@pairdraw/scene-graph/slots";
|
|
3
5
|
//#region src/editor/commands/actions.ts
|
|
4
6
|
function createEditorCommandActions(commands) {
|
|
5
7
|
function getCommand(id) {
|
|
@@ -7,7 +9,13 @@ function createEditorCommandActions(commands) {
|
|
|
7
9
|
}
|
|
8
10
|
function runCommand(id) {
|
|
9
11
|
const command = commands[id];
|
|
10
|
-
if (command.enabled.value)
|
|
12
|
+
if (!command.enabled.value) return;
|
|
13
|
+
try {
|
|
14
|
+
command.run();
|
|
15
|
+
} catch (error) {
|
|
16
|
+
if (!(error instanceof InstanceGuardError)) throw error;
|
|
17
|
+
reportCommandRefusal(error);
|
|
18
|
+
}
|
|
11
19
|
}
|
|
12
20
|
function menuItem(id, shortcut = editorCommandMetadata(id).shortcut) {
|
|
13
21
|
const command = getCommand(id);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"actions.js","names":[],"sources":["../../../src/editor/commands/actions.ts"],"sourcesContent":["import { editorCommandMetadata } from './registry'\nimport { formatShortcut } from './shortcut'\nimport type { EditorCommand, EditorCommandId, EditorCommandMenuItem } from './types'\n\nexport function createEditorCommandActions(commands: Record<EditorCommandId, EditorCommand>) {\n function getCommand(id: EditorCommandId) {\n return commands[id]\n }\n\n function runCommand(id: EditorCommandId) {\n const command = commands[id]\n if (command.enabled.value) command.run()\n }\n\n function menuItem(\n id: EditorCommandId,\n shortcut = editorCommandMetadata(id).shortcut\n ): EditorCommandMenuItem {\n const command = getCommand(id)\n return {\n id,\n label: command.label,\n shortcut: formatShortcut(shortcut),\n get disabled() {\n return !command.enabled.value\n },\n action: () => runCommand(id)\n }\n }\n\n return { getCommand, runCommand, menuItem }\n}\n"],"mappings":"
|
|
1
|
+
{"version":3,"file":"actions.js","names":[],"sources":["../../../src/editor/commands/actions.ts"],"sourcesContent":["import { InstanceGuardError } from '@pairdraw/scene-graph/slots'\n\nimport { reportCommandRefusal } from './refusals'\nimport { editorCommandMetadata } from './registry'\nimport { formatShortcut } from './shortcut'\nimport type { EditorCommand, EditorCommandId, EditorCommandMenuItem } from './types'\n\nexport function createEditorCommandActions(commands: Record<EditorCommandId, EditorCommand>) {\n function getCommand(id: EditorCommandId) {\n return commands[id]\n }\n\n function runCommand(id: EditorCommandId) {\n const command = commands[id]\n if (!command.enabled.value) return\n try {\n command.run()\n } catch (error) {\n // A guard can still refuse at run time (a race, a drag, paste): show that as a toast. Any\n // other error is a real failure and keeps propagating unchanged.\n if (!(error instanceof InstanceGuardError)) throw error\n reportCommandRefusal(error)\n }\n }\n\n function menuItem(\n id: EditorCommandId,\n shortcut = editorCommandMetadata(id).shortcut\n ): EditorCommandMenuItem {\n const command = getCommand(id)\n return {\n id,\n label: command.label,\n shortcut: formatShortcut(shortcut),\n get disabled() {\n return !command.enabled.value\n },\n action: () => runCommand(id)\n }\n }\n\n return { getCommand, runCommand, menuItem }\n}\n"],"mappings":";;;;;AAOA,SAAgB,2BAA2B,UAAkD;CAC3F,SAAS,WAAW,IAAqB;EACvC,OAAO,SAAS;CAClB;CAEA,SAAS,WAAW,IAAqB;EACvC,MAAM,UAAU,SAAS;EACzB,IAAI,CAAC,QAAQ,QAAQ,OAAO;EAC5B,IAAI;GACF,QAAQ,IAAI;EACd,SAAS,OAAO;GAGd,IAAI,EAAE,iBAAiB,qBAAqB,MAAM;GAClD,qBAAqB,KAAK;EAC5B;CACF;CAEA,SAAS,SACP,IACA,WAAW,sBAAsB,EAAE,CAAC,CAAC,UACd;EACvB,MAAM,UAAU,WAAW,EAAE;EAC7B,OAAO;GACL;GACA,OAAO,QAAQ;GACf,UAAU,eAAe,QAAQ;GACjC,IAAI,WAAW;IACb,OAAO,CAAC,QAAQ,QAAQ;GAC1B;GACA,cAAc,WAAW,EAAE;EAC7B;CACF;CAEA,OAAO;EAAE;EAAY;EAAY;CAAS;AAC5C"}
|
|
@@ -1,5 +1,7 @@
|
|
|
1
|
+
import { CommandRefusal, clearCommandRefusal, commandRefusal, reportCommandRefusal } from "./refusals.js";
|
|
1
2
|
import { EditorCommand, EditorCommandId } from "./types.js";
|
|
3
|
+
import { createEditorCommandActions } from "./actions.js";
|
|
2
4
|
import { useEditorCommands } from "./use.js";
|
|
3
5
|
import { EDITOR_COMMAND_METADATA, EditorCommandMetadata, editorCommandMetadata } from "./registry.js";
|
|
4
6
|
import { ShortcutPlatform, formatShortcut, shortcutPlatform } from "./shortcut.js";
|
|
5
|
-
export { EDITOR_COMMAND_METADATA, type EditorCommand, type EditorCommandId, type EditorCommandMetadata, type ShortcutPlatform, editorCommandMetadata, formatShortcut, shortcutPlatform, useEditorCommands };
|
|
7
|
+
export { type CommandRefusal, EDITOR_COMMAND_METADATA, type EditorCommand, type EditorCommandId, type EditorCommandMetadata, type ShortcutPlatform, clearCommandRefusal, commandRefusal, createEditorCommandActions, editorCommandMetadata, formatShortcut, reportCommandRefusal, shortcutPlatform, useEditorCommands };
|
|
@@ -1,4 +1,6 @@
|
|
|
1
|
+
import { clearCommandRefusal, commandRefusal, reportCommandRefusal } from "./refusals.js";
|
|
1
2
|
import { EDITOR_COMMAND_METADATA, editorCommandMetadata } from "./registry.js";
|
|
2
3
|
import { formatShortcut, shortcutPlatform } from "./shortcut.js";
|
|
4
|
+
import { createEditorCommandActions } from "./actions.js";
|
|
3
5
|
import { useEditorCommands } from "./use.js";
|
|
4
|
-
export { EDITOR_COMMAND_METADATA, editorCommandMetadata, formatShortcut, shortcutPlatform, useEditorCommands };
|
|
6
|
+
export { EDITOR_COMMAND_METADATA, clearCommandRefusal, commandRefusal, createEditorCommandActions, editorCommandMetadata, formatShortcut, reportCommandRefusal, shortcutPlatform, useEditorCommands };
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
//#region src/editor/commands/refusals.d.ts
|
|
2
|
+
/**
|
|
3
|
+
* The last command the editor refused to run, as the guard explained it. The command runner
|
|
4
|
+
* catches instead of throwing so a menu click never ends in a console error; the app turns this
|
|
5
|
+
* into a short localized toast.
|
|
6
|
+
*/
|
|
7
|
+
interface CommandRefusal {
|
|
8
|
+
/** The guard's message, useful for logs and tests; the UI shows a localized sentence instead. */
|
|
9
|
+
reason: string;
|
|
10
|
+
}
|
|
11
|
+
declare const commandRefusal: import("nanostores").PreinitializedWritableAtom<CommandRefusal | null> & object;
|
|
12
|
+
/** Records a command that the guard refused; the runner never rethrows it. */
|
|
13
|
+
declare function reportCommandRefusal(error: unknown): void;
|
|
14
|
+
/** Clears the record once the app has shown it, so the same refusal cannot toast twice. */
|
|
15
|
+
declare function clearCommandRefusal(): void;
|
|
16
|
+
//#endregion
|
|
17
|
+
export { CommandRefusal, clearCommandRefusal, commandRefusal, reportCommandRefusal };
|
|
18
|
+
//# sourceMappingURL=refusals.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"refusals.d.ts","names":[],"sources":["../../../src/editor/commands/refusals.ts"],"mappings":";;;;;;UAOiB;;EAEf;;cAGW,qCAAc,2BAAA;;iBAGX,qBAAqB;;iBAMrB"}
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import { atom } from "nanostores";
|
|
2
|
+
//#region src/editor/commands/refusals.ts
|
|
3
|
+
const commandRefusal = atom(null);
|
|
4
|
+
/** Records a command that the guard refused; the runner never rethrows it. */
|
|
5
|
+
function reportCommandRefusal(error) {
|
|
6
|
+
const reason = error instanceof Error ? error.message : String(error);
|
|
7
|
+
commandRefusal.set({ reason });
|
|
8
|
+
}
|
|
9
|
+
/** Clears the record once the app has shown it, so the same refusal cannot toast twice. */
|
|
10
|
+
function clearCommandRefusal() {
|
|
11
|
+
commandRefusal.set(null);
|
|
12
|
+
}
|
|
13
|
+
//#endregion
|
|
14
|
+
export { clearCommandRefusal, commandRefusal, reportCommandRefusal };
|
|
15
|
+
|
|
16
|
+
//# sourceMappingURL=refusals.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"refusals.js","names":[],"sources":["../../../src/editor/commands/refusals.ts"],"sourcesContent":["import { atom } from 'nanostores'\n\n/**\n * The last command the editor refused to run, as the guard explained it. The command runner\n * catches instead of throwing so a menu click never ends in a console error; the app turns this\n * into a short localized toast.\n */\nexport interface CommandRefusal {\n /** The guard's message, useful for logs and tests; the UI shows a localized sentence instead. */\n reason: string\n}\n\nexport const commandRefusal = atom<CommandRefusal | null>(null)\n\n/** Records a command that the guard refused; the runner never rethrows it. */\nexport function reportCommandRefusal(error: unknown): void {\n const reason = error instanceof Error ? error.message : String(error)\n commandRefusal.set({ reason })\n}\n\n/** Clears the record once the app has shown it, so the same refusal cannot toast twice. */\nexport function clearCommandRefusal(): void {\n commandRefusal.set(null)\n}\n"],"mappings":";;AAYA,MAAa,iBAAiB,KAA4B,IAAI;;AAG9D,SAAgB,qBAAqB,OAAsB;CACzD,MAAM,SAAS,iBAAiB,QAAQ,MAAM,UAAU,OAAO,KAAK;CACpE,eAAe,IAAI,EAAE,OAAO,CAAC;AAC/B;;AAGA,SAAgB,sBAA4B;CAC1C,eAAe,IAAI,IAAI;AACzB"}
|
|
@@ -71,7 +71,9 @@ declare const EDITOR_COMMAND_METADATA: {
|
|
|
71
71
|
'selection.convertToFrame': {
|
|
72
72
|
contextTestId: string;
|
|
73
73
|
};
|
|
74
|
-
'selection.createComponentSet': {
|
|
74
|
+
'selection.createComponentSet': {
|
|
75
|
+
contextTestId: string;
|
|
76
|
+
};
|
|
75
77
|
'selection.detachInstance': {
|
|
76
78
|
shortcut: string;
|
|
77
79
|
keybinding: string;
|
|
@@ -79,6 +81,7 @@ declare const EDITOR_COMMAND_METADATA: {
|
|
|
79
81
|
'selection.detachIcon': {};
|
|
80
82
|
'selection.goToMainComponent': {};
|
|
81
83
|
'selection.resetInstanceOverrides': {};
|
|
84
|
+
'selection.resetLayerOverrides': {};
|
|
82
85
|
'selection.pushInstanceOverrides': {};
|
|
83
86
|
'selection.createInstance': {};
|
|
84
87
|
'selection.createSlot': {
|