@weasel-js/modes 1.10.0 → 1.11.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/README.md +1 -1
- package/dist/{chunk-DPP5MVDO.js → chunk-TLMWTM4B.js} +4 -4
- package/dist/chunk-TLMWTM4B.js.map +1 -0
- package/dist/{default-6A7txdga.d.ts → default-CF62V4DX.d.ts} +18 -9
- package/dist/index.d.ts +2 -2
- package/dist/index.js +1 -1
- package/dist/index.js.map +1 -1
- package/dist/presets/default.d.ts +1 -1
- package/dist/presets/default.js +1 -1
- package/package.json +2 -2
- package/dist/chunk-DPP5MVDO.js.map +0 -1
package/README.md
CHANGED
|
@@ -4,7 +4,7 @@ App-level modality primitives: capability tags, mode definitions, mode registry,
|
|
|
4
4
|
|
|
5
5
|
Part of [weasel](https://github.com/orochi235/weasel), a domain-agnostic 2D
|
|
6
6
|
scene-graph canvas kit for React. See the
|
|
7
|
-
[API reference](https://orochi235.github.io/weasel/
|
|
7
|
+
[API reference](https://orochi235.github.io/weasel/#pkg/modes).
|
|
8
8
|
|
|
9
9
|
## Install
|
|
10
10
|
|
|
@@ -24,7 +24,7 @@ var PATH_EDIT = {
|
|
|
24
24
|
allows: ["edits-anchors"],
|
|
25
25
|
scoping: true,
|
|
26
26
|
workspace: { tint: "#3b82f6", gradient: "bottom-up", intensity: 0.12 },
|
|
27
|
-
entry: { trigger: "double-click-target", shortcut: "Enter" },
|
|
27
|
+
entry: { trigger: "double-click-target", targets: ["path"], shortcut: "Enter" },
|
|
28
28
|
exit: { shortcut: "Escape" },
|
|
29
29
|
discard: { shortcut: "Meta+Escape" }
|
|
30
30
|
};
|
|
@@ -44,7 +44,7 @@ var ISOLATION = {
|
|
|
44
44
|
],
|
|
45
45
|
scoping: true,
|
|
46
46
|
workspace: { tint: "#8b5cf6", gradient: "bottom-up", intensity: 0.12 },
|
|
47
|
-
entry: { trigger: "double-click-target" },
|
|
47
|
+
entry: { trigger: "double-click-target", targets: ["group"] },
|
|
48
48
|
exit: { shortcut: "Escape" },
|
|
49
49
|
discard: { shortcut: "Meta+Escape" }
|
|
50
50
|
};
|
|
@@ -99,5 +99,5 @@ function byId(id) {
|
|
|
99
99
|
}
|
|
100
100
|
|
|
101
101
|
export { CROP, DEFAULT_MODES, FREE_TRANSFORM, ISOLATION, NORMAL, PATH_EDIT, TEXT_EDIT, byId };
|
|
102
|
-
//# sourceMappingURL=chunk-
|
|
103
|
-
//# sourceMappingURL=chunk-
|
|
102
|
+
//# sourceMappingURL=chunk-TLMWTM4B.js.map
|
|
103
|
+
//# sourceMappingURL=chunk-TLMWTM4B.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/presets/default.ts"],"names":["m"],"mappings":";AAIO,IAAM,MAAA,GAAyB;AAAA,EACpC,EAAA,EAAI,QAAA;AAAA,EACJ,KAAA,EAAO,QAAA;AAAA,EACP,WAAA,EAAa,gDAAA;AAAA,EACb,IAAA,EAAM,MAAA;AAAA,EACN,MAAA,EAAQ;AAAA,IACN,mBAAA;AAAA,IACA,sBAAA;AAAA,IACA,eAAA;AAAA,IACA,gBAAA;AAAA,IACA,cAAA;AAAA,IACA,eAAA;AAAA,IACA,cAAA;AAAA,IACA;AAAA,GACF;AAAA,EACA,OAAA,EAAS;AACX;AAIO,IAAM,SAAA,GAA4B;AAAA,EACvC,EAAA,EAAI,WAAA;AAAA,EACJ,KAAA,EAAO,WAAA;AAAA,EACP,WAAA,EAAa,oCAAA;AAAA,EACb,IAAA,EAAM,MAAA;AAAA,EACN,MAAA,EAAQ,CAAC,eAAe,CAAA;AAAA,EACxB,OAAA,EAAS,IAAA;AAAA,EACT,WAAW,EAAE,IAAA,EAAM,WAAW,QAAA,EAAU,WAAA,EAAa,WAAW,IAAA,EAAK;AAAA,EACrE,KAAA,EAAO,EAAE,OAAA,EAAS,qBAAA,EAAuB,SAAS,CAAC,MAAM,CAAA,EAAG,QAAA,EAAU,OAAA,EAAQ;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AAA,CAAE,CAAA;AAChD,EAAA,OAAO,CAAA;AACT","file":"chunk-TLMWTM4B.js","sourcesContent":["import type { ModeDefinition } from '../modeDefinition';\n\n/** The default mode: everything except anchor and text editing, no scoping,\n * no workspace tint. */\nexport const NORMAL: ModeDefinition = {\n id: 'normal',\n label: 'Normal',\n description: 'Select, draw and arrange anything on the page.',\n kind: 'soft',\n allows: [\n 'creates-selection',\n 'transforms-selection',\n 'creates-paths',\n 'creates-shapes',\n 'creates-text',\n 'samples-color',\n 'applies-fill',\n 'edits-page',\n ],\n scoping: false,\n};\n\n/** Editing the anchors of a path. Scoped to the target, entered by\n * double-clicking a `path` or with Enter, left with Escape. */\nexport const PATH_EDIT: ModeDefinition = {\n id: 'path-edit',\n label: 'Path Edit',\n description: \"Move a path's anchors and handles.\",\n kind: 'soft',\n allows: ['edits-anchors'],\n scoping: true,\n workspace: { tint: '#3b82f6', gradient: 'bottom-up', intensity: 0.12 },\n entry: { trigger: 'double-click-target', targets: ['path'], shortcut: 'Enter' },\n exit: { shortcut: 'Escape' },\n discard: { shortcut: 'Meta+Escape' },\n};\n\n/** Working inside one subtree with everything outside it dimmed and inert,\n * entered by double-clicking a `group`. Allows the same authoring tools as `NORMAL`, minus page edits. */\nexport const ISOLATION: ModeDefinition = {\n id: 'isolation',\n label: 'Isolation',\n description: 'Work inside one group with everything outside it dimmed and locked.',\n kind: 'soft',\n allows: [\n 'creates-selection',\n 'transforms-selection',\n 'creates-paths',\n 'creates-shapes',\n 'creates-text',\n 'samples-color',\n 'applies-fill',\n ],\n scoping: true,\n workspace: { tint: '#8b5cf6', gradient: 'bottom-up', intensity: 0.12 },\n entry: { trigger: 'double-click-target', targets: ['group'] },\n exit: { shortcut: 'Escape' },\n discard: { shortcut: 'Meta+Escape' },\n};\n\n/** A transaction that transforms the selection: the whole session is one undo\n * step, committed with Enter or discarded with Escape. */\nexport const FREE_TRANSFORM: ModeDefinition = {\n id: 'free-transform',\n label: 'Free Transform',\n description: 'Move, scale and rotate the selection as one undoable step.',\n kind: 'strict',\n allows: ['transforms-selection'],\n scoping: false,\n workspace: { tint: '#f59e0b', gradient: 'bottom-up', intensity: 0.12 },\n entry: { shortcut: 'Meta+T' },\n commit: { shortcut: 'Enter' },\n cancel: { shortcut: 'Escape' },\n};\n\n/** Editing the text of one node. Entered by double-clicking it, left with\n * Escape. It names no targets: the text edit opening is what enters it. */\nexport const TEXT_EDIT: ModeDefinition = {\n id: 'text-edit',\n label: 'Text Edit',\n description: \"Edit a text node's content.\",\n kind: 'soft',\n allows: ['edits-text'],\n scoping: false,\n workspace: { tint: '#10b981', gradient: 'bottom-up', intensity: 0.12 },\n entry: { trigger: 'double-click-target' },\n exit: { shortcut: 'Escape' },\n discard: { shortcut: 'Meta+Escape' },\n};\n\n/** A transaction that changes the page extents, committed with Enter or\n * discarded with Escape. */\nexport const CROP: ModeDefinition = {\n id: 'crop',\n label: 'Crop',\n description: 'Change the page extents as one undoable step.',\n kind: 'strict',\n allows: ['edits-page'],\n scoping: false,\n workspace: { tint: '#ef4444', gradient: 'bottom-up', intensity: 0.12 },\n entry: { shortcut: 'C' },\n commit: { shortcut: 'Enter' },\n cancel: { shortcut: 'Escape' },\n};\n\n/** The six modes this package ships, ready to hand to `createModeRegistry`. */\nexport const DEFAULT_MODES: readonly ModeDefinition[] = [\n NORMAL,\n PATH_EDIT,\n ISOLATION,\n FREE_TRANSFORM,\n TEXT_EDIT,\n CROP,\n];\n\n/** Look up one of the `DEFAULT_MODES` by id. Throws on an unknown id. For an\n * app's own mode set, use the registry's `byId` instead. */\nexport function byId(id: string): ModeDefinition {\n const m = DEFAULT_MODES.find((m) => m.id === id);\n if (!m) throw new Error(`Unknown mode id: ${id}`);\n return m;\n}\n"]}
|
|
@@ -27,6 +27,18 @@ interface WorkspaceVisual {
|
|
|
27
27
|
gradient?: 'top-down' | 'bottom-up';
|
|
28
28
|
intensity?: number;
|
|
29
29
|
}
|
|
30
|
+
/** How a mode is entered. */
|
|
31
|
+
interface ModeEntry {
|
|
32
|
+
shortcut?: string;
|
|
33
|
+
/** `'double-click-target'`: double-clicking a node enters the mode on that node. Which nodes is
|
|
34
|
+
* `targets`; `modeTriggers` in `@weasel-js/core` turns the pair into a canvas binding. */
|
|
35
|
+
trigger?: 'double-click-target';
|
|
36
|
+
/** The routing kinds a double-click enters this mode on — the `Hit.kind` vocabulary a
|
|
37
|
+
* binding's `kind:<k>` target reads, so `'path'` or an app's own `'group'`. A trigger with no
|
|
38
|
+
* targets binds nothing, for a mode whose entry follows something else (text-edit, which the
|
|
39
|
+
* edit opening enters). */
|
|
40
|
+
targets?: readonly string[];
|
|
41
|
+
}
|
|
30
42
|
/**
|
|
31
43
|
* A mode: an app-level editing context that narrows which tools are usable and
|
|
32
44
|
* how the workspace looks. Tools live inside modes; a tool is never "in" one.
|
|
@@ -54,10 +66,7 @@ interface ModeDefinition {
|
|
|
54
66
|
/** When true, out-of-target objects dim at the renderer layer. */
|
|
55
67
|
scoping: boolean;
|
|
56
68
|
workspace?: WorkspaceVisual;
|
|
57
|
-
entry?:
|
|
58
|
-
shortcut?: string;
|
|
59
|
-
trigger?: 'double-click-target';
|
|
60
|
-
};
|
|
69
|
+
entry?: ModeEntry;
|
|
61
70
|
exit?: {
|
|
62
71
|
shortcut?: string;
|
|
63
72
|
};
|
|
@@ -82,16 +91,16 @@ declare function eligibleForMode(mode: ModeDefinition, toolTags: readonly Capabi
|
|
|
82
91
|
* no workspace tint. */
|
|
83
92
|
declare const NORMAL: ModeDefinition;
|
|
84
93
|
/** Editing the anchors of a path. Scoped to the target, entered by
|
|
85
|
-
* double-clicking
|
|
94
|
+
* double-clicking a `path` or with Enter, left with Escape. */
|
|
86
95
|
declare const PATH_EDIT: ModeDefinition;
|
|
87
|
-
/** Working inside one subtree with everything outside it dimmed and inert
|
|
88
|
-
* Allows the same authoring tools as `NORMAL`, minus page edits. */
|
|
96
|
+
/** Working inside one subtree with everything outside it dimmed and inert,
|
|
97
|
+
* entered by double-clicking a `group`. Allows the same authoring tools as `NORMAL`, minus page edits. */
|
|
89
98
|
declare const ISOLATION: ModeDefinition;
|
|
90
99
|
/** A transaction that transforms the selection: the whole session is one undo
|
|
91
100
|
* step, committed with Enter or discarded with Escape. */
|
|
92
101
|
declare const FREE_TRANSFORM: ModeDefinition;
|
|
93
102
|
/** Editing the text of one node. Entered by double-clicking it, left with
|
|
94
|
-
* Escape. */
|
|
103
|
+
* Escape. It names no targets: the text edit opening is what enters it. */
|
|
95
104
|
declare const TEXT_EDIT: ModeDefinition;
|
|
96
105
|
/** A transaction that changes the page extents, committed with Enter or
|
|
97
106
|
* discarded with Escape. */
|
|
@@ -102,4 +111,4 @@ declare const DEFAULT_MODES: readonly ModeDefinition[];
|
|
|
102
111
|
* app's own mode set, use the registry's `byId` instead. */
|
|
103
112
|
declare function byId(id: string): ModeDefinition;
|
|
104
113
|
|
|
105
|
-
export { ALL_TAGS as A, type CapabilityTag as C, DEFAULT_MODES as D, FREE_TRANSFORM as F, IMPLICIT_TAGS as I, type ModeDefinition as M, NORMAL as N, PATH_EDIT as P, TEXT_EDIT as T, type WorkspaceVisual as W, CROP as a, ISOLATION as b,
|
|
114
|
+
export { ALL_TAGS as A, type CapabilityTag as C, DEFAULT_MODES as D, FREE_TRANSFORM as F, IMPLICIT_TAGS as I, type ModeDefinition as M, NORMAL as N, PATH_EDIT as P, TEXT_EDIT as T, type WorkspaceVisual as W, CROP as a, ISOLATION as b, type ModeEntry as c, byId as d, capabilitiesAllowed as e, eligibleForMode as f, isCapabilityTag as i, modeLabel as m };
|
package/dist/index.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { M as ModeDefinition, C as CapabilityTag } from './default-
|
|
2
|
-
export { A as ALL_TAGS, a as CROP, D as DEFAULT_MODES, F as FREE_TRANSFORM, I as IMPLICIT_TAGS, b as ISOLATION, N as NORMAL, P as PATH_EDIT, T as TEXT_EDIT, W as WorkspaceVisual,
|
|
1
|
+
import { M as ModeDefinition, C as CapabilityTag } from './default-CF62V4DX.js';
|
|
2
|
+
export { A as ALL_TAGS, a as CROP, D as DEFAULT_MODES, F as FREE_TRANSFORM, I as IMPLICIT_TAGS, b as ISOLATION, c as ModeEntry, N as NORMAL, P as PATH_EDIT, T as TEXT_EDIT, W as WorkspaceVisual, d as byId, e as capabilitiesAllowed, f as eligibleForMode, i as isCapabilityTag, m as modeLabel } from './default-CF62V4DX.js';
|
|
3
3
|
import { Reflection } from '@weasel-js/registry';
|
|
4
4
|
|
|
5
5
|
/** Options for `createModeRegistry`: the modes to register and which one is
|
package/dist/index.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
export { CROP, DEFAULT_MODES, FREE_TRANSFORM, ISOLATION, NORMAL, PATH_EDIT, TEXT_EDIT, byId } from './chunk-
|
|
1
|
+
export { CROP, DEFAULT_MODES, FREE_TRANSFORM, ISOLATION, NORMAL, PATH_EDIT, TEXT_EDIT, byId } from './chunk-TLMWTM4B.js';
|
|
2
2
|
import { createReflectable, createEmitter } from '@weasel-js/registry';
|
|
3
3
|
|
|
4
4
|
// src/capabilities.ts
|
package/dist/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/capabilities.ts","../src/modeDefinition.ts","../src/registry.ts","../src/decorations.ts","../src/eligibility.ts","../src/scopingLayer.ts"],"names":["createEmitter"],"mappings":";;;;AAGO,IAAM,QAAA,GAAW;AAAA,EACtB,YAAA;AAAA,EACA,mBAAA;AAAA,EACA,eAAA;AAAA,EACA,gBAAA;AAAA,EACA,cAAA;AAAA,EACA,eAAA;AAAA,EACA,YAAA;AAAA,EACA,sBAAA;AAAA,EACA,eAAA;AAAA,EACA,cAAA;AAAA,EACA;AACF;AASO,IAAM,aAAA,GAA0C,CAAC,YAAY;AAQ7D,SAAS,mBAAA,CAAoB,SAA8B,IAAA,EAAqD;AACrH,EAAA,OAAO,IAAA,KAAS,UAAa,IAAA,CAAK,KAAA,CAAM,CAAC,GAAA,KAAQ,OA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QAAA,OAAA,EAAQ;AAAA,MACV,CAAA;AAAA,IACF;AAAA,GACF;AACF","file":"index.js","sourcesContent":["/** The full vocabulary of capability tags shipped in the default preset.\n * Apps and other consumers can add their own tags; this list is what\n * `weasel-modes` itself uses. */\nexport const ALL_TAGS = [\n 'navigation',\n 'creates-selection',\n 'creates-paths',\n 'creates-shapes',\n 'creates-text',\n 'edits-anchors',\n 'edits-text',\n 'transforms-selection',\n 'samples-color',\n 'applies-fill',\n 'edits-page',\n] as const;\n\n/** One capability a tool or contribution declares, and a mode allows. Any\n * string is accepted so apps can add tags of their own; `ALL_TAGS` is the\n * set this package ships. */\nexport type CapabilityTag = (typeof ALL_TAGS)[number] | (string & {});\n\n/** Tags that are implicitly allowed in every mode — never listed per-mode.\n * A tool carrying only these is eligible everywhere. */\nexport const IMPLICIT_TAGS: readonly CapabilityTag[] = ['navigation'];\n\n/**\n * Whether a tool or contribution carrying `tags` may be used while `allowed`\n * is the set of tags the active mode permits. Every tag has to be allowed: a\n * tag names something the entry does, and one refused thing refuses the entry.\n * An entry with no tags asks for nothing and is allowed everywhere.\n */\nexport function capabilitiesAllowed(allowed: ReadonlySet<string>, tags: readonly CapabilityTag[] | undefined): boolean {\n return tags === undefined || tags.every((tag) => allowed.has(tag));\n}\n\n/** Whether a string is one of the shipped `ALL_TAGS`. An app-defined tag is\n * still a valid `CapabilityTag` and will answer `false` here. */\nexport function isCapabilityTag(value: string): value is CapabilityTag {\n return (ALL_TAGS as readonly string[]).includes(value);\n}\n","import { capabilitiesAllowed, IMPLICIT_TAGS, type CapabilityTag } from './capabilities';\n\n/** How a mode tints the workspace — the area around the page — so the user\n * can see at a glance which mode is active. */\nexport interface WorkspaceVisual {\n tint?: string;\n gradient?: 'top-down' | 'bottom-up';\n intensity?: number;\n}\n\n/**\n * A mode: an app-level editing context that narrows which tools are usable and\n * how the workspace looks. Tools live inside modes; a tool is never \"in\" one.\n *\n * `kind` picks the lifecycle. A `soft` mode (path-edit, isolation, text-edit)\n * is a scoped context with no commit ceremony — every edit inside it is\n * independently undoable and `exit` is non-destructive. A `strict` mode\n * (free-transform, crop) is a transaction: the whole session collapses to one\n * undoable step and leaving requires an explicit `commit` or `cancel`.\n *\n * The four shortcut fields are key chords (`'Escape'`, `'Meta+T'`) that\n * `modeShortcuts` in `@weasel-js/routing` turns into dispatcher bindings,\n * each live only while the mode it acts on is (or, for `entry`, is not).\n */\nexport interface ModeDefinition {\n id: string;\n /** Human-readable name for chrome — a breadcrumb, a status bar. Falls back\n * to `id`; read it through {@link modeLabel}. */\n label?: string;\n /** One sentence on what the mode is for, for a tooltip or a hint line. */\n description?: string;\n kind: 'soft' | 'strict';\n /** Capability tags this mode allows beyond IMPLICIT_TAGS. */\n allows: CapabilityTag[];\n /** When true, out-of-target objects dim at the renderer layer. */\n scoping: boolean;\n workspace?: WorkspaceVisual;\n entry?: { shortcut?: string; trigger?: 'double-click-target' };\n exit?: { shortcut?: string };\n commit?: { shortcut?: string };\n cancel?: { shortcut?: string };\n /** Leave a soft mode and throw its session away, where `exit` keeps it to\n * resume. */\n discard?: { shortcut?: string };\n}\n\n/** A mode's display name: its `label`, else its `id`. */\nexport function modeLabel(mode: ModeDefinition): string {\n return mode.label ?? mode.id;\n}\n\n/** True iff a tool carrying `toolTags` is eligible for `mode`. */\nexport function eligibleForMode(mode: ModeDefinition, toolTags: readonly CapabilityTag[]): boolean {\n return capabilitiesAllowed(allowedCapabilitiesOf(mode), toolTags);\n}\n\n/** Every tag `mode` permits: its `allows` plus `IMPLICIT_TAGS`. */\nexport function allowedCapabilitiesOf(mode: ModeDefinition): Set<string> {\n return new Set<string>([...mode.allows, ...IMPLICIT_TAGS]);\n}\n","import { createReflectable, type Reflection } from '@weasel-js/registry';\nimport { allowedCapabilitiesOf, type ModeDefinition } from './modeDefinition';\n\n/** Options for `createModeRegistry`: the modes to register and which one is\n * active at startup. */\nexport interface CreateModeRegistryOptions {\n modes: readonly ModeDefinition[];\n initial: string;\n}\n\n/** Holds the set of available modes and which one is active, and notifies\n * subscribers when that changes. `getVersion` is a monotonic counter for\n * render-cache invalidation. Unknown mode ids throw rather than being\n * ignored. */\nexport interface ModeRegistry {\n current(): ModeDefinition;\n /** Every registered mode, in registration order. */\n list(): readonly ModeDefinition[];\n setMode(id: string): void;\n byId(id: string): ModeDefinition;\n getVersion(): number;\n subscribe(listener: () => void): () => void;\n /** The registered modes keyed by id. Shares this registry's version, so it\n * also advances on `setMode`. */\n readonly reflection: Reflection<ModeDefinition>;\n}\n\n/** Build a mode registry. Throws if two of `modes` share an id, or if\n * `initial` does not name one of them. */\nexport function createModeRegistry(opts: CreateModeRegistryOptions): ModeRegistry {\n const modes = createReflectable<ModeDefinition>();\n for (const m of opts.modes) {\n if (modes.get(m.id)) throw new Error(`createModeRegistry: duplicate mode id \"${m.id}\"`);\n modes.set(m.id, m);\n }\n const initial = modes.get(opts.initial);\n if (!initial) throw new Error(`Initial mode \"${opts.initial}\" not in modes list`);\n\n let active: ModeDefinition = initial;\n\n return {\n current: () => active,\n list: () => opts.modes,\n setMode(id: string): void {\n const next = modes.get(id);\n if (!next) throw new Error(`Unknown mode id: ${id}`);\n if (next === active) return;\n active = next;\n modes.bump();\n },\n byId(id: string): ModeDefinition {\n const m = modes.get(id);\n if (!m) throw new Error(`Unknown mode id: ${id}`);\n return m;\n },\n getVersion: modes.getVersion,\n subscribe: modes.subscribe,\n reflection: modes.reflection,\n };\n}\n\n/** The active mode as a canvas gates on it: its id, and every capability tag\n * a tool may carry to be usable in it — the mode's `allows` plus\n * `IMPLICIT_TAGS`. The shape `<SceneCanvas modes>` gates on. */\nexport interface ActiveMode {\n id: string;\n allowedCapabilities: ReadonlySet<string>;\n}\n\n/** A mode definition as a canvas gates on it. */\nexport function activeModeOf(mode: ModeDefinition): ActiveMode {\n return { id: mode.id, allowedCapabilities: allowedCapabilitiesOf(mode) };\n}\n\n/** A reader for the registry's active mode, as `<SceneCanvas modes>` builds\n * one. It returns the same object until the mode changes. */\nexport function getActiveModeFor(registry: ModeRegistry): () => ActiveMode {\n let cached: { version: number; value: ActiveMode } | null = null;\n return () => {\n const version = registry.getVersion();\n if (cached?.version !== version) cached = { version, value: activeModeOf(registry.current()) };\n return cached.value;\n };\n}\n","import { createEmitter } from '@weasel-js/registry';\nimport type { ModeRegistry } from './registry';\n\n/** Loose draw-command type — the kit's `DrawCommand` union shape is over in\n * `src/renderer`. We keep this opaque to avoid a cross-package import in\n * the type surface; consumers cast to the real DrawCommand at use site. */\nexport type ModeDrawCommand = unknown;\n\n/** Produces the draw commands for one mode's persistent decorations. Called\n * once per paint while that mode is active. */\nexport type ModeDecorationPainter = () => ModeDrawCommand[];\n\n/** Options for `createModeDecorations`. */\nexport interface CreateModeDecorationsOptions {\n registry: ModeRegistry;\n}\n\n/** Per-mode decoration painters, keyed by mode id. Mode decorations are drawn\n * for as long as the mode is active and belong to the mode rather than to any\n * tool — path-edit's anchor dots and handle lines are the motivating case. */\nexport interface ModeDecorations {\n /** Register (or replace) the painter for a mode id. Returns a release that\n * removes it, and does nothing once another painter has replaced it. */\n register(modeId: string, painter: ModeDecorationPainter): () => void;\n /** Paint the active mode's decorations. Returns an empty array if no\n * painter is registered for the active mode. */\n paint(): ModeDrawCommand[];\n /** Monotonic version. Bumps on mode change, painter registration, or release. */\n getVersion(): number;\n /** Notified whenever `getVersion` bumps — what a canvas repaints on. */\n subscribe(listener: () => void): () => void;\n}\n\n/** Build a decoration registry bound to a mode registry, so switching modes\n * switches which painter runs. */\nexport function createModeDecorations(opts: CreateModeDecorationsOptions): ModeDecorations {\n const { registry } = opts;\n const painters = new Map<string, ModeDecorationPainter>();\n const listeners = createEmitter();\n let registrations = 0;\n const changed = (): void => {\n registrations++;\n listeners.emit();\n };\n\n return {\n register(modeId: string, painter: ModeDecorationPainter): () => void {\n painters.set(modeId, painter);\n changed();\n return () => {\n if (painters.get(modeId) !== painter) return;\n painters.delete(modeId);\n changed();\n };\n },\n paint(): ModeDrawCommand[] {\n const painter = painters.get(registry.current().id);\n if (!painter) return [];\n return painter();\n },\n getVersion: () => registry.getVersion() + registrations,\n subscribe(listener: () => void): () => void {\n const off = listeners.subscribe(listener);\n const offMode = registry.subscribe(listener);\n return () => {\n off();\n offMode();\n };\n },\n };\n}\n","import type { ModeRegistry } from './registry';\nimport type { CapabilityTag } from './capabilities';\nimport { eligibleForMode } from './modeDefinition';\n\n/** The part of a tool this package needs in order to judge eligibility: its\n * id and the capabilities it claims. Structural, so a real `ToolDef`\n * satisfies it without this package depending on the kit. */\nexport interface ToolLike {\n id: string;\n capabilities?: readonly CapabilityTag[];\n}\n\n/** True iff `tool` is usable in the registry's currently active mode. */\nexport function eligibleTool(reg: ModeRegistry, tool: ToolLike): boolean {\n return eligibleForMode(reg.current(), tool.capabilities ?? []);\n}\n\n/** True iff a contribution is usable in the registry's active mode. */\nexport function eligibleContribution(\n reg: ModeRegistry,\n entry: { id: string; eligibility?: { capabilities?: readonly CapabilityTag[] } },\n): boolean {\n return eligibleForMode(reg.current(), entry.eligibility?.capabilities ?? []);\n}\n","import { createEmitter } from '@weasel-js/registry';\nimport type { ModeRegistry } from './registry';\n\n/** Options for `createScopingDim`. */\nexport interface CreateScopingDimOptions {\n registry: ModeRegistry;\n /** Returns the set of node ids that are *in* scope for the current mode.\n * The app computes this — typically: selection-only for path-edit,\n * isolated subtree for isolation, empty for non-scoping modes. */\n getTargetIds: () => ReadonlySet<string>;\n /** Alpha for out-of-scope nodes. Default 0.3 (spec). */\n dimAlpha?: number;\n}\n\n/** Answers, per node, how a scoping mode should treat it: dimmed or not,\n * hit-testable or not. Consult it from the renderer and the hit-tester —\n * it computes nothing itself. Its answers change when the mode does, or when\n * the app says the target set moved (`invalidate`); both notify\n * subscribers, so a canvas can repaint on `subscribe` (`<SceneCanvas\n * redrawOn>`). */\nexport interface ScopingDim {\n /** Multiplier in [0, 1] to apply to a node's render alpha. */\n alphaFor(id: string): number;\n /** Whether the node should respond to pointer hits. */\n isPointerInteractive(id: string): boolean;\n /** Tell subscribers the target set changed without a mode switch. */\n invalidate(): void;\n /** Monotonic; bumps on a mode switch and on `invalidate`. */\n getVersion(): number;\n subscribe(listener: () => void): () => void;\n}\n\n/** Build the scoping lookup for a mode registry. In a mode with\n * `scoping: false` every node is full-alpha and interactive, so this is safe\n * to consult unconditionally. */\nexport function createScopingDim(opts: CreateScopingDimOptions): ScopingDim {\n const { registry } = opts;\n const dim = opts.dimAlpha ?? 0.3;\n const listeners = createEmitter();\n let invalidations = 0;\n return {\n alphaFor(id) {\n const mode = registry.current();\n if (!mode.scoping) return 1;\n return opts.getTargetIds().has(id) ? 1 : dim;\n },\n isPointerInteractive(id) {\n const mode = registry.current();\n if (!mode.scoping) return true;\n return opts.getTargetIds().has(id);\n },\n invalidate() {\n invalidations++;\n listeners.emit();\n },\n getVersion: () => registry.getVersion() + invalidations,\n subscribe(listener) {\n const off = listeners.subscribe(listener);\n const offMode = registry.subscribe(listener);\n return () => {\n off();\n offMode();\n };\n },\n };\n}\n"]}
|
|
1
|
+
{"version":3,"sources":["../src/capabilities.ts","../src/modeDefinition.ts","../src/registry.ts","../src/decorations.ts","../src/eligibility.ts","../src/scopingLayer.ts"],"names":["createEmitter"],"mappings":";;;;AAGO,IAAM,QAAA,GAAW;AAAA,EACtB,YAAA;AAAA,EACA,mBAAA;AAAA,EACA,eAAA;AAAA,EACA,gBAAA;AAAA,EACA,cAAA;AAAA,EACA,eAAA;AAAA,EACA,YAAA;AAAA,EACA,sBAAA;AAAA,EACA,eAAA;AAAA,EACA,cAAA;AAAA,EACA;AACF;AASO,IAAM,aAAA,GAA0C,CAAC,YAAY;AAQ7D,SAAS,mBAAA,CAAoB,SAA8B,IAAA,EAAqD;AACrH,EAAA,OAAO,IAAA,KAAS,UAAa,IAAA,CAAK,KAAA,CAAM,CAAC,GAAA,KAAQ,OAAA,CAAQ,GAAA,CAAI,GAAG,CAAC,CAAA;AACnE;AAIO,SAAS,gBAAgB,KAAA,EAAuC;AACrE,EAAA,OAAQ,QAAA,CAA+B,SA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ps and other consumers can add their own tags; this list is what\n * `weasel-modes` itself uses. */\nexport const ALL_TAGS = [\n 'navigation',\n 'creates-selection',\n 'creates-paths',\n 'creates-shapes',\n 'creates-text',\n 'edits-anchors',\n 'edits-text',\n 'transforms-selection',\n 'samples-color',\n 'applies-fill',\n 'edits-page',\n] as const;\n\n/** One capability a tool or contribution declares, and a mode allows. Any\n * string is accepted so apps can add tags of their own; `ALL_TAGS` is the\n * set this package ships. */\nexport type CapabilityTag = (typeof ALL_TAGS)[number] | (string & {});\n\n/** Tags that are implicitly allowed in every mode — never listed per-mode.\n * A tool carrying only these is eligible everywhere. */\nexport const IMPLICIT_TAGS: readonly CapabilityTag[] = ['navigation'];\n\n/**\n * Whether a tool or contribution carrying `tags` may be used while `allowed`\n * is the set of tags the active mode permits. Every tag has to be allowed: a\n * tag names something the entry does, and one refused thing refuses the entry.\n * An entry with no tags asks for nothing and is allowed everywhere.\n */\nexport function capabilitiesAllowed(allowed: ReadonlySet<string>, tags: readonly CapabilityTag[] | undefined): boolean {\n return tags === undefined || tags.every((tag) => allowed.has(tag));\n}\n\n/** Whether a string is one of the shipped `ALL_TAGS`. An app-defined tag is\n * still a valid `CapabilityTag` and will answer `false` here. */\nexport function isCapabilityTag(value: string): value is CapabilityTag {\n return (ALL_TAGS as readonly string[]).includes(value);\n}\n","import { capabilitiesAllowed, IMPLICIT_TAGS, type CapabilityTag } from './capabilities';\n\n/** How a mode tints the workspace — the area around the page — so the user\n * can see at a glance which mode is active. */\nexport interface WorkspaceVisual {\n tint?: string;\n gradient?: 'top-down' | 'bottom-up';\n intensity?: number;\n}\n\n/** How a mode is entered. */\nexport interface ModeEntry {\n shortcut?: string;\n /** `'double-click-target'`: double-clicking a node enters the mode on that node. Which nodes is\n * `targets`; `modeTriggers` in `@weasel-js/core` turns the pair into a canvas binding. */\n trigger?: 'double-click-target';\n /** The routing kinds a double-click enters this mode on — the `Hit.kind` vocabulary a\n * binding's `kind:<k>` target reads, so `'path'` or an app's own `'group'`. A trigger with no\n * targets binds nothing, for a mode whose entry follows something else (text-edit, which the\n * edit opening enters). */\n targets?: readonly string[];\n}\n\n/**\n * A mode: an app-level editing context that narrows which tools are usable and\n * how the workspace looks. Tools live inside modes; a tool is never \"in\" one.\n *\n * `kind` picks the lifecycle. A `soft` mode (path-edit, isolation, text-edit)\n * is a scoped context with no commit ceremony — every edit inside it is\n * independently undoable and `exit` is non-destructive. A `strict` mode\n * (free-transform, crop) is a transaction: the whole session collapses to one\n * undoable step and leaving requires an explicit `commit` or `cancel`.\n *\n * The four shortcut fields are key chords (`'Escape'`, `'Meta+T'`) that\n * `modeShortcuts` in `@weasel-js/routing` turns into dispatcher bindings,\n * each live only while the mode it acts on is (or, for `entry`, is not).\n */\nexport interface ModeDefinition {\n id: string;\n /** Human-readable name for chrome — a breadcrumb, a status bar. Falls back\n * to `id`; read it through {@link modeLabel}. */\n label?: string;\n /** One sentence on what the mode is for, for a tooltip or a hint line. */\n description?: string;\n kind: 'soft' | 'strict';\n /** Capability tags this mode allows beyond IMPLICIT_TAGS. */\n allows: CapabilityTag[];\n /** When true, out-of-target objects dim at the renderer layer. */\n scoping: boolean;\n workspace?: WorkspaceVisual;\n entry?: ModeEntry;\n exit?: { shortcut?: string };\n commit?: { shortcut?: string };\n cancel?: { shortcut?: string };\n /** Leave a soft mode and throw its session away, where `exit` keeps it to\n * resume. */\n discard?: { shortcut?: string };\n}\n\n/** A mode's display name: its `label`, else its `id`. */\nexport function modeLabel(mode: ModeDefinition): string {\n return mode.label ?? mode.id;\n}\n\n/** True iff a tool carrying `toolTags` is eligible for `mode`. */\nexport function eligibleForMode(mode: ModeDefinition, toolTags: readonly CapabilityTag[]): boolean {\n return capabilitiesAllowed(allowedCapabilitiesOf(mode), toolTags);\n}\n\n/** Every tag `mode` permits: its `allows` plus `IMPLICIT_TAGS`. */\nexport function allowedCapabilitiesOf(mode: ModeDefinition): Set<string> {\n return new Set<string>([...mode.allows, ...IMPLICIT_TAGS]);\n}\n","import { createReflectable, type Reflection } from '@weasel-js/registry';\nimport { allowedCapabilitiesOf, type ModeDefinition } from './modeDefinition';\n\n/** Options for `createModeRegistry`: the modes to register and which one is\n * active at startup. */\nexport interface CreateModeRegistryOptions {\n modes: readonly ModeDefinition[];\n initial: string;\n}\n\n/** Holds the set of available modes and which one is active, and notifies\n * subscribers when that changes. `getVersion` is a monotonic counter for\n * render-cache invalidation. Unknown mode ids throw rather than being\n * ignored. */\nexport interface ModeRegistry {\n current(): ModeDefinition;\n /** Every registered mode, in registration order. */\n list(): readonly ModeDefinition[];\n setMode(id: string): void;\n byId(id: string): ModeDefinition;\n getVersion(): number;\n subscribe(listener: () => void): () => void;\n /** The registered modes keyed by id. Shares this registry's version, so it\n * also advances on `setMode`. */\n readonly reflection: Reflection<ModeDefinition>;\n}\n\n/** Build a mode registry. Throws if two of `modes` share an id, or if\n * `initial` does not name one of them. */\nexport function createModeRegistry(opts: CreateModeRegistryOptions): ModeRegistry {\n const modes = createReflectable<ModeDefinition>();\n for (const m of opts.modes) {\n if (modes.get(m.id)) throw new Error(`createModeRegistry: duplicate mode id \"${m.id}\"`);\n modes.set(m.id, m);\n }\n const initial = modes.get(opts.initial);\n if (!initial) throw new Error(`Initial mode \"${opts.initial}\" not in modes list`);\n\n let active: ModeDefinition = initial;\n\n return {\n current: () => active,\n list: () => opts.modes,\n setMode(id: string): void {\n const next = modes.get(id);\n if (!next) throw new Error(`Unknown mode id: ${id}`);\n if (next === active) return;\n active = next;\n modes.bump();\n },\n byId(id: string): ModeDefinition {\n const m = modes.get(id);\n if (!m) throw new Error(`Unknown mode id: ${id}`);\n return m;\n },\n getVersion: modes.getVersion,\n subscribe: modes.subscribe,\n reflection: modes.reflection,\n };\n}\n\n/** The active mode as a canvas gates on it: its id, and every capability tag\n * a tool may carry to be usable in it — the mode's `allows` plus\n * `IMPLICIT_TAGS`. The shape `<SceneCanvas modes>` gates on. */\nexport interface ActiveMode {\n id: string;\n allowedCapabilities: ReadonlySet<string>;\n}\n\n/** A mode definition as a canvas gates on it. */\nexport function activeModeOf(mode: ModeDefinition): ActiveMode {\n return { id: mode.id, allowedCapabilities: allowedCapabilitiesOf(mode) };\n}\n\n/** A reader for the registry's active mode, as `<SceneCanvas modes>` builds\n * one. It returns the same object until the mode changes. */\nexport function getActiveModeFor(registry: ModeRegistry): () => ActiveMode {\n let cached: { version: number; value: ActiveMode } | null = null;\n return () => {\n const version = registry.getVersion();\n if (cached?.version !== version) cached = { version, value: activeModeOf(registry.current()) };\n return cached.value;\n };\n}\n","import { createEmitter } from '@weasel-js/registry';\nimport type { ModeRegistry } from './registry';\n\n/** Loose draw-command type — the kit's `DrawCommand` union shape is over in\n * `src/renderer`. We keep this opaque to avoid a cross-package import in\n * the type surface; consumers cast to the real DrawCommand at use site. */\nexport type ModeDrawCommand = unknown;\n\n/** Produces the draw commands for one mode's persistent decorations. Called\n * once per paint while that mode is active. */\nexport type ModeDecorationPainter = () => ModeDrawCommand[];\n\n/** Options for `createModeDecorations`. */\nexport interface CreateModeDecorationsOptions {\n registry: ModeRegistry;\n}\n\n/** Per-mode decoration painters, keyed by mode id. Mode decorations are drawn\n * for as long as the mode is active and belong to the mode rather than to any\n * tool — path-edit's anchor dots and handle lines are the motivating case. */\nexport interface ModeDecorations {\n /** Register (or replace) the painter for a mode id. Returns a release that\n * removes it, and does nothing once another painter has replaced it. */\n register(modeId: string, painter: ModeDecorationPainter): () => void;\n /** Paint the active mode's decorations. Returns an empty array if no\n * painter is registered for the active mode. */\n paint(): ModeDrawCommand[];\n /** Monotonic version. Bumps on mode change, painter registration, or release. */\n getVersion(): number;\n /** Notified whenever `getVersion` bumps — what a canvas repaints on. */\n subscribe(listener: () => void): () => void;\n}\n\n/** Build a decoration registry bound to a mode registry, so switching modes\n * switches which painter runs. */\nexport function createModeDecorations(opts: CreateModeDecorationsOptions): ModeDecorations {\n const { registry } = opts;\n const painters = new Map<string, ModeDecorationPainter>();\n const listeners = createEmitter();\n let registrations = 0;\n const changed = (): void => {\n registrations++;\n listeners.emit();\n };\n\n return {\n register(modeId: string, painter: ModeDecorationPainter): () => void {\n painters.set(modeId, painter);\n changed();\n return () => {\n if (painters.get(modeId) !== painter) return;\n painters.delete(modeId);\n changed();\n };\n },\n paint(): ModeDrawCommand[] {\n const painter = painters.get(registry.current().id);\n if (!painter) return [];\n return painter();\n },\n getVersion: () => registry.getVersion() + registrations,\n subscribe(listener: () => void): () => void {\n const off = listeners.subscribe(listener);\n const offMode = registry.subscribe(listener);\n return () => {\n off();\n offMode();\n };\n },\n };\n}\n","import type { ModeRegistry } from './registry';\nimport type { CapabilityTag } from './capabilities';\nimport { eligibleForMode } from './modeDefinition';\n\n/** The part of a tool this package needs in order to judge eligibility: its\n * id and the capabilities it claims. Structural, so a real `ToolDef`\n * satisfies it without this package depending on the kit. */\nexport interface ToolLike {\n id: string;\n capabilities?: readonly CapabilityTag[];\n}\n\n/** True iff `tool` is usable in the registry's currently active mode. */\nexport function eligibleTool(reg: ModeRegistry, tool: ToolLike): boolean {\n return eligibleForMode(reg.current(), tool.capabilities ?? []);\n}\n\n/** True iff a contribution is usable in the registry's active mode. */\nexport function eligibleContribution(\n reg: ModeRegistry,\n entry: { id: string; eligibility?: { capabilities?: readonly CapabilityTag[] } },\n): boolean {\n return eligibleForMode(reg.current(), entry.eligibility?.capabilities ?? []);\n}\n","import { createEmitter } from '@weasel-js/registry';\nimport type { ModeRegistry } from './registry';\n\n/** Options for `createScopingDim`. */\nexport interface CreateScopingDimOptions {\n registry: ModeRegistry;\n /** Returns the set of node ids that are *in* scope for the current mode.\n * The app computes this — typically: selection-only for path-edit,\n * isolated subtree for isolation, empty for non-scoping modes. */\n getTargetIds: () => ReadonlySet<string>;\n /** Alpha for out-of-scope nodes. Default 0.3 (spec). */\n dimAlpha?: number;\n}\n\n/** Answers, per node, how a scoping mode should treat it: dimmed or not,\n * hit-testable or not. Consult it from the renderer and the hit-tester —\n * it computes nothing itself. Its answers change when the mode does, or when\n * the app says the target set moved (`invalidate`); both notify\n * subscribers, so a canvas can repaint on `subscribe` (`<SceneCanvas\n * redrawOn>`). */\nexport interface ScopingDim {\n /** Multiplier in [0, 1] to apply to a node's render alpha. */\n alphaFor(id: string): number;\n /** Whether the node should respond to pointer hits. */\n isPointerInteractive(id: string): boolean;\n /** Tell subscribers the target set changed without a mode switch. */\n invalidate(): void;\n /** Monotonic; bumps on a mode switch and on `invalidate`. */\n getVersion(): number;\n subscribe(listener: () => void): () => void;\n}\n\n/** Build the scoping lookup for a mode registry. In a mode with\n * `scoping: false` every node is full-alpha and interactive, so this is safe\n * to consult unconditionally. */\nexport function createScopingDim(opts: CreateScopingDimOptions): ScopingDim {\n const { registry } = opts;\n const dim = opts.dimAlpha ?? 0.3;\n const listeners = createEmitter();\n let invalidations = 0;\n return {\n alphaFor(id) {\n const mode = registry.current();\n if (!mode.scoping) return 1;\n return opts.getTargetIds().has(id) ? 1 : dim;\n },\n isPointerInteractive(id) {\n const mode = registry.current();\n if (!mode.scoping) return true;\n return opts.getTargetIds().has(id);\n },\n invalidate() {\n invalidations++;\n listeners.emit();\n },\n getVersion: () => registry.getVersion() + invalidations,\n subscribe(listener) {\n const off = listeners.subscribe(listener);\n const offMode = registry.subscribe(listener);\n return () => {\n off();\n offMode();\n };\n },\n };\n}\n"]}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
export { a as CROP, D as DEFAULT_MODES, F as FREE_TRANSFORM, b as ISOLATION, N as NORMAL, P as PATH_EDIT, T as TEXT_EDIT,
|
|
1
|
+
export { a as CROP, D as DEFAULT_MODES, F as FREE_TRANSFORM, b as ISOLATION, N as NORMAL, P as PATH_EDIT, T as TEXT_EDIT, d as byId } from '../default-CF62V4DX.js';
|
package/dist/presets/default.js
CHANGED
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
export { CROP, DEFAULT_MODES, FREE_TRANSFORM, ISOLATION, NORMAL, PATH_EDIT, TEXT_EDIT, byId } from '../chunk-
|
|
1
|
+
export { CROP, DEFAULT_MODES, FREE_TRANSFORM, ISOLATION, NORMAL, PATH_EDIT, TEXT_EDIT, byId } from '../chunk-TLMWTM4B.js';
|
|
2
2
|
//# sourceMappingURL=default.js.map
|
|
3
3
|
//# sourceMappingURL=default.js.map
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@weasel-js/modes",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.11.0",
|
|
4
4
|
"description": "App-level modality primitives: capability tags, mode definitions, mode registry, and decoration layer.",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"type": "module",
|
|
@@ -33,7 +33,7 @@
|
|
|
33
33
|
"node": ">=22"
|
|
34
34
|
},
|
|
35
35
|
"dependencies": {
|
|
36
|
-
"@weasel-js/registry": "1.
|
|
36
|
+
"@weasel-js/registry": "1.11.0"
|
|
37
37
|
},
|
|
38
38
|
"files": [
|
|
39
39
|
"dist",
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/presets/default.ts"],"names":["m"],"mappings":";AAIO,IAAM,MAAA,GAAyB;AAAA,EACpC,EAAA,EAAI,QAAA;AAAA,EACJ,KAAA,EAAO,QAAA;AAAA,EACP,WAAA,EAAa,gDAAA;AAAA,EACb,IAAA,EAAM,MAAA;AAAA,EACN,MAAA,EAAQ;AAAA,IACN,mBAAA;AAAA,IACA,sBAAA;AAAA,IACA,eAAA;AAAA,IACA,gBAAA;AAAA,IACA,cAAA;AAAA,IACA,eAAA;AAAA,IACA,cAAA;AAAA,IACA;AAAA,GACF;AAAA,EACA,OAAA,EAAS;AACX;AAIO,IAAM,SAAA,GAA4B;AAAA,EACvC,EAAA,EAAI,WAAA;AAAA,EACJ,KAAA,EAAO,WAAA;AAAA,EACP,WAAA,EAAa,oCAAA;AAAA,EACb,IAAA,EAAM,MAAA;AAAA,EACN,MAAA,EAAQ,CAAC,eAAe,CAAA;AAAA,EACxB,OAAA,EAAS,IAAA;AAAA,EACT,WAAW,EAAE,IAAA,E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O,EAAE,CAAA;AAC/C,EAAA,IAAI,CAAC,CAAA,EAAG,MAAM,IAAI,KAAA,CAAM,CAAA,iBAAA,EAAoB,EAAE,CAAA,CAAE,CAAA;AAChD,EAAA,OAAO,CAAA;AACT","file":"chunk-DPP5MVDO.js","sourcesContent":["import type { ModeDefinition } from '../modeDefinition';\n\n/** The default mode: everything except anchor and text editing, no scoping,\n * no workspace tint. */\nexport const NORMAL: ModeDefinition = {\n id: 'normal',\n label: 'Normal',\n description: 'Select, draw and arrange anything on the page.',\n kind: 'soft',\n allows: [\n 'creates-selection',\n 'transforms-selection',\n 'creates-paths',\n 'creates-shapes',\n 'creates-text',\n 'samples-color',\n 'applies-fill',\n 'edits-page',\n ],\n scoping: false,\n};\n\n/** Editing the anchors of a path. Scoped to the target, entered by\n * double-clicking it, left with Escape. */\nexport const PATH_EDIT: ModeDefinition = {\n id: 'path-edit',\n label: 'Path Edit',\n description: \"Move a path's anchors and handles.\",\n kind: 'soft',\n allows: ['edits-anchors'],\n scoping: true,\n workspace: { tint: '#3b82f6', gradient: 'bottom-up', intensity: 0.12 },\n entry: { trigger: 'double-click-target', shortcut: 'Enter' },\n exit: { shortcut: 'Escape' },\n discard: { shortcut: 'Meta+Escape' },\n};\n\n/** Working inside one subtree with everything outside it dimmed and inert.\n * Allows the same authoring tools as `NORMAL`, minus page edits. */\nexport const ISOLATION: ModeDefinition = {\n id: 'isolation',\n label: 'Isolation',\n description: 'Work inside one group with everything outside it dimmed and locked.',\n kind: 'soft',\n allows: [\n 'creates-selection',\n 'transforms-selection',\n 'creates-paths',\n 'creates-shapes',\n 'creates-text',\n 'samples-color',\n 'applies-fill',\n ],\n scoping: true,\n workspace: { tint: '#8b5cf6', gradient: 'bottom-up', intensity: 0.12 },\n entry: { trigger: 'double-click-target' },\n exit: { shortcut: 'Escape' },\n discard: { shortcut: 'Meta+Escape' },\n};\n\n/** A transaction that transforms the selection: the whole session is one undo\n * step, committed with Enter or discarded with Escape. */\nexport const FREE_TRANSFORM: ModeDefinition = {\n id: 'free-transform',\n label: 'Free Transform',\n description: 'Move, scale and rotate the selection as one undoable step.',\n kind: 'strict',\n allows: ['transforms-selection'],\n scoping: false,\n workspace: { tint: '#f59e0b', gradient: 'bottom-up', intensity: 0.12 },\n entry: { shortcut: 'Meta+T' },\n commit: { shortcut: 'Enter' },\n cancel: { shortcut: 'Escape' },\n};\n\n/** Editing the text of one node. Entered by double-clicking it, left with\n * Escape. */\nexport const TEXT_EDIT: ModeDefinition = {\n id: 'text-edit',\n label: 'Text Edit',\n description: \"Edit a text node's content.\",\n kind: 'soft',\n allows: ['edits-text'],\n scoping: false,\n workspace: { tint: '#10b981', gradient: 'bottom-up', intensity: 0.12 },\n entry: { trigger: 'double-click-target' },\n exit: { shortcut: 'Escape' },\n discard: { shortcut: 'Meta+Escape' },\n};\n\n/** A transaction that changes the page extents, committed with Enter or\n * discarded with Escape. */\nexport const CROP: ModeDefinition = {\n id: 'crop',\n label: 'Crop',\n description: 'Change the page extents as one undoable step.',\n kind: 'strict',\n allows: ['edits-page'],\n scoping: false,\n workspace: { tint: '#ef4444', gradient: 'bottom-up', intensity: 0.12 },\n entry: { shortcut: 'C' },\n commit: { shortcut: 'Enter' },\n cancel: { shortcut: 'Escape' },\n};\n\n/** The six modes this package ships, ready to hand to `createModeRegistry`. */\nexport const DEFAULT_MODES: readonly ModeDefinition[] = [\n NORMAL,\n PATH_EDIT,\n ISOLATION,\n FREE_TRANSFORM,\n TEXT_EDIT,\n CROP,\n];\n\n/** Look up one of the `DEFAULT_MODES` by id. Throws on an unknown id. For an\n * app's own mode set, use the registry's `byId` instead. */\nexport function byId(id: string): ModeDefinition {\n const m = DEFAULT_MODES.find((m) => m.id === id);\n if (!m) throw new Error(`Unknown mode id: ${id}`);\n return m;\n}\n"]}
|