@edv4h/usketch-plugin-start-position 0.1.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/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 EdV4H
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
@@ -0,0 +1,5 @@
1
+ export { createStartPositionPlugin } from "./plugin.js";
2
+ export { applyStartPosition, captureViewport, } from "./resolve.js";
3
+ export { createStartPositionShapeDefinition, findStartPosition, isStartPosition, makeStartPosition, START_POSITION_TYPE, type StartPosition, type StartPositionShapeData, } from "./start-position-shape.js";
4
+ export { claimViewport, DEEP_LINK_PRIORITY, START_POSITION_PRIORITY, VIEWPORT_CLAIMED, type ViewportClaim, watchViewportClaims, } from "./viewport-claim.js";
5
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,yBAAyB,EAAE,MAAM,aAAa,CAAC;AACxD,OAAO,EACN,kBAAkB,EAClB,eAAe,GACf,MAAM,cAAc,CAAC;AACtB,OAAO,EACN,kCAAkC,EAClC,iBAAiB,EACjB,eAAe,EACf,iBAAiB,EACjB,mBAAmB,EACnB,KAAK,aAAa,EAClB,KAAK,sBAAsB,GAC3B,MAAM,2BAA2B,CAAC;AACnC,OAAO,EACN,aAAa,EACb,kBAAkB,EAClB,uBAAuB,EACvB,gBAAgB,EAChB,KAAK,aAAa,EAClB,mBAAmB,GACnB,MAAM,qBAAqB,CAAC"}
package/dist/index.js ADDED
@@ -0,0 +1,5 @@
1
+ export { createStartPositionPlugin } from "./plugin.js";
2
+ export { applyStartPosition, captureViewport, } from "./resolve.js";
3
+ export { createStartPositionShapeDefinition, findStartPosition, isStartPosition, makeStartPosition, START_POSITION_TYPE, } from "./start-position-shape.js";
4
+ export { claimViewport, DEEP_LINK_PRIORITY, START_POSITION_PRIORITY, VIEWPORT_CLAIMED, watchViewportClaims, } from "./viewport-claim.js";
5
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,yBAAyB,EAAE,MAAM,aAAa,CAAC;AACxD,OAAO,EACN,kBAAkB,EAClB,eAAe,GACf,MAAM,cAAc,CAAC;AACtB,OAAO,EACN,kCAAkC,EAClC,iBAAiB,EACjB,eAAe,EACf,iBAAiB,EACjB,mBAAmB,GAGnB,MAAM,2BAA2B,CAAC;AACnC,OAAO,EACN,aAAa,EACb,kBAAkB,EAClB,uBAAuB,EACvB,gBAAgB,EAEhB,mBAAmB,GACnB,MAAM,qBAAqB,CAAC"}
@@ -0,0 +1,3 @@
1
+ import type { UsketchPlugin } from "@edv4h/usketch-shared";
2
+ export declare function createStartPositionPlugin(): UsketchPlugin;
3
+ //# sourceMappingURL=plugin.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"plugin.d.ts","sourceRoot":"","sources":["../src/plugin.ts"],"names":[],"mappings":"AAKA,OAAO,KAAK,EAKX,aAAa,EACb,MAAM,uBAAuB,CAAC;AAwC/B,wBAAgB,yBAAyB,IAAI,aAAa,CAgNzD"}
package/dist/plugin.js ADDED
@@ -0,0 +1,232 @@
1
+ import { fitContent } from "@edv4h/usketch-shared";
2
+ import { applyStartPosition, captureViewport } from "./resolve.js";
3
+ import { createStartPositionShapeDefinition, findStartPosition, makeStartPosition, START_POSITION_TYPE, } from "./start-position-shape.js";
4
+ import { claimViewport, START_POSITION_PRIORITY, watchViewportClaims } from "./viewport-claim.js";
5
+ /** How long to wait for the start-position shape to arrive via CRDT sync on load. */
6
+ const SYNC_TIMEOUT_MS = 5000;
7
+ const SOURCE = "start-position";
8
+ /** The x/y/pinZoom/zoom the HUD shows for a shape's current start (defaults when none). */
9
+ function formOf(shape) {
10
+ const st = shape?.start;
11
+ if (st?.kind === "viewport")
12
+ return { x: st.x, y: st.y, pinZoom: true, zoom: st.zoom };
13
+ if (st?.kind === "coordinate")
14
+ return { x: st.x, y: st.y, pinZoom: false, zoom: 1 };
15
+ return { x: 0, y: 0, pinZoom: false, zoom: 1 };
16
+ }
17
+ /** Build a coordinate/viewport start from an (edited) form. */
18
+ function startOfForm(f) {
19
+ return f.pinZoom
20
+ ? { kind: "viewport", x: f.x, y: f.y, zoom: f.zoom }
21
+ : { kind: "coordinate", x: f.x, y: f.y };
22
+ }
23
+ export function createStartPositionPlugin() {
24
+ return {
25
+ id: "usketch-plugin-start-position",
26
+ name: "スタート位置",
27
+ setup(ctx) {
28
+ ctx.shapes.register(START_POSITION_TYPE, createStartPositionShapeDefinition());
29
+ const currentShape = () => findStartPosition(ctx.store.getShapes().values());
30
+ // The singleton shape, creating it (synced) the first time a start is set.
31
+ const ensureShape = () => {
32
+ const s = currentShape();
33
+ if (s)
34
+ return s.id;
35
+ const shape = makeStartPosition();
36
+ ctx.store.addShape(shape);
37
+ return shape.id;
38
+ };
39
+ const setStart = (start) => {
40
+ ctx.store.updateShape(ensureShape(), { start });
41
+ };
42
+ const setFormField = (field, value) => {
43
+ const next = { ...formOf(currentShape()), [field]: value };
44
+ setStart(startOfForm(next));
45
+ };
46
+ // ── HUD settings: coordinate inputs + zoom pin + auto-apply ──
47
+ const fields = [
48
+ { name: "x", label: "X 座標", type: "number", step: 1 },
49
+ { name: "y", label: "Y 座標", type: "number", step: 1 },
50
+ { name: "pinZoom", label: "ズームを固定", type: "boolean" },
51
+ { name: "zoom", label: "ズーム", type: "number", min: 0.1, max: 10, step: 0.1 },
52
+ { name: "autoApply", label: "起動時に移動", type: "boolean" },
53
+ ];
54
+ const unregisterSettings = ctx.hud.registerSettings({
55
+ id: "usketch-start-position:settings",
56
+ label: "スタート位置",
57
+ fields,
58
+ get: (name) => {
59
+ const shape = currentShape();
60
+ if (name === "autoApply")
61
+ return shape?.autoApply !== false;
62
+ return formOf(shape)[name];
63
+ },
64
+ set: (name, value) => {
65
+ if (name === "autoApply") {
66
+ ctx.store.updateShape(ensureShape(), {
67
+ autoApply: value === true || value === "true",
68
+ });
69
+ }
70
+ else if (name === "pinZoom") {
71
+ setFormField("pinZoom", value === true || value === "true");
72
+ }
73
+ else if (name === "x" || name === "y" || name === "zoom") {
74
+ const n = Number(value);
75
+ if (Number.isFinite(n))
76
+ setFormField(name, n);
77
+ }
78
+ },
79
+ // Re-read when the shape changes (incl. edits from another client), not on
80
+ // every pan/zoom — filter to shape mutations only.
81
+ subscribe: (listener) => ctx.store.onMutation((e) => {
82
+ if (e.type === "shape:added" ||
83
+ e.type === "shape:removed" ||
84
+ e.type === "shape:updated")
85
+ listener();
86
+ }),
87
+ });
88
+ // ── Actions ──
89
+ const goToStart = (animate) => {
90
+ const s = currentShape();
91
+ if (!s?.start)
92
+ return;
93
+ const ok = applyStartPosition(ctx.store, s.start, { animate });
94
+ // A "shape" start whose shape was deleted → frame all content instead.
95
+ if (!ok)
96
+ fitContent(ctx.store, { animate });
97
+ };
98
+ const offs = [
99
+ ctx.actions.register({
100
+ id: "start-position:go",
101
+ group: "スタート位置",
102
+ label: "スタート位置へ移動",
103
+ isEnabled: () => currentShape()?.start != null,
104
+ run: () => goToStart(true),
105
+ }),
106
+ ctx.actions.register({
107
+ id: "start-position:capture-view",
108
+ group: "スタート位置",
109
+ label: "現在の画角をスタートに設定",
110
+ run: () => setStart({ kind: "viewport", ...captureViewport(ctx.store) }),
111
+ }),
112
+ ctx.actions.register({
113
+ id: "start-position:from-selection",
114
+ group: "スタート位置",
115
+ label: "選択Shapeをスタートに設定",
116
+ // Exactly one shape selected, and not the (locked) start shape itself.
117
+ isEnabled: () => {
118
+ const sel = [...ctx.store.getSelection()];
119
+ return sel.length === 1 && ctx.store.getShape(sel[0])?.type !== START_POSITION_TYPE;
120
+ },
121
+ run: () => {
122
+ const sel = [...ctx.store.getSelection()];
123
+ if (sel.length === 1)
124
+ setStart({ kind: "shape", shapeId: sel[0] });
125
+ },
126
+ }),
127
+ ctx.actions.register({
128
+ id: "start-position:clear",
129
+ group: "スタート位置",
130
+ label: "スタート位置をクリア",
131
+ isEnabled: () => currentShape() != null,
132
+ run: () => {
133
+ const s = currentShape();
134
+ if (s)
135
+ ctx.store.deleteShape(s.id);
136
+ },
137
+ }),
138
+ ];
139
+ // ── Auto-apply on load (per-user, once, cooperating with deep-link) ──
140
+ const guard = watchViewportClaims(ctx.events, SOURCE, START_POSITION_PRIORITY);
141
+ let disposed = false;
142
+ let settled = false;
143
+ let waitTimer = null;
144
+ let applyTimer = null;
145
+ let offWait = null;
146
+ const finishWait = () => {
147
+ settled = true;
148
+ if (waitTimer) {
149
+ clearTimeout(waitTimer);
150
+ waitTimer = null;
151
+ }
152
+ if (offWait) {
153
+ offWait();
154
+ offWait = null;
155
+ }
156
+ };
157
+ // Move the camera to `start`, deferred a task so competing claims (deep-link
158
+ // emits on a microtask, which runs before this timeout) are recorded before
159
+ // we decide to yield. Tracked so teardown (StrictMode remount, board switch)
160
+ // can cancel it — otherwise it could move the camera after disposal. When the
161
+ // move can't resolve — `applyStartPosition` returns false only for a shape
162
+ // target that's gone — frame all content instead (documented fallback).
163
+ const applyOnLoad = (start) => {
164
+ applyTimer = setTimeout(() => {
165
+ applyTimer = null;
166
+ if (disposed || guard.shouldYield())
167
+ return;
168
+ if (applyStartPosition(ctx.store, start, { animate: false })) {
169
+ claimViewport(ctx.events, SOURCE, START_POSITION_PRIORITY);
170
+ }
171
+ else {
172
+ fitContent(ctx.store, { animate: false });
173
+ }
174
+ }, 0);
175
+ };
176
+ const attemptAutoApply = () => {
177
+ if (settled)
178
+ return;
179
+ const s = currentShape();
180
+ if (!s)
181
+ return; // start-position shape not synced in yet — keep waiting
182
+ if (s.autoApply === false) {
183
+ finishWait(); // auto-move explicitly disabled
184
+ return;
185
+ }
186
+ // Shape present but `start` not set yet — it may still arrive via sync/edit,
187
+ // so keep waiting (up to the timeout) rather than settling.
188
+ if (!s.start)
189
+ return;
190
+ const start = s.start;
191
+ // A shape target may still be streaming in via CRDT; keep waiting for it.
192
+ if (start.kind === "shape" && !ctx.store.getShape(start.shapeId))
193
+ return;
194
+ finishWait();
195
+ applyOnLoad(start);
196
+ };
197
+ attemptAutoApply();
198
+ if (!settled) {
199
+ offWait = ctx.store.onMutation((e) => {
200
+ // Retry on add AND update: the shape (or its `start`/`autoApply` fields,
201
+ // or the referenced target) can arrive/change during the sync window.
202
+ if (e.type === "shape:added" || e.type === "shape:updated")
203
+ attemptAutoApply();
204
+ });
205
+ // Timed out waiting for the (start-position or referenced) shape to sync.
206
+ // Apply whatever is defined now, falling back to fit-all if a shape target
207
+ // is still missing — matching the documented "frame all if gone" behavior.
208
+ waitTimer = setTimeout(() => {
209
+ if (settled)
210
+ return;
211
+ const s = currentShape();
212
+ finishWait();
213
+ if (s && s.autoApply !== false && s.start)
214
+ applyOnLoad(s.start);
215
+ }, SYNC_TIMEOUT_MS);
216
+ }
217
+ return () => {
218
+ disposed = true;
219
+ if (applyTimer) {
220
+ clearTimeout(applyTimer);
221
+ applyTimer = null;
222
+ }
223
+ finishWait();
224
+ guard.dispose();
225
+ unregisterSettings();
226
+ for (const off of offs)
227
+ off();
228
+ };
229
+ },
230
+ };
231
+ }
232
+ //# sourceMappingURL=plugin.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"plugin.js","sourceRoot":"","sources":["../src/plugin.ts"],"names":[],"mappings":"AAYA,OAAO,EAAE,UAAU,EAAE,MAAM,uBAAuB,CAAC;AACnD,OAAO,EAAE,kBAAkB,EAAE,eAAe,EAAE,MAAM,cAAc,CAAC;AACnE,OAAO,EACN,kCAAkC,EAClC,iBAAiB,EACjB,iBAAiB,EACjB,mBAAmB,GAGnB,MAAM,2BAA2B,CAAC;AACnC,OAAO,EAAE,aAAa,EAAE,uBAAuB,EAAE,mBAAmB,EAAE,MAAM,qBAAqB,CAAC;AAElG,qFAAqF;AACrF,MAAM,eAAe,GAAG,IAAI,CAAC;AAE7B,MAAM,MAAM,GAAG,gBAAgB,CAAC;AAShC,2FAA2F;AAC3F,SAAS,MAAM,CAAC,KAAoC;IACnD,MAAM,EAAE,GAAG,KAAK,EAAE,KAAK,CAAC;IACxB,IAAI,EAAE,EAAE,IAAI,KAAK,UAAU;QAAE,OAAO,EAAE,CAAC,EAAE,EAAE,CAAC,CAAC,EAAE,CAAC,EAAE,EAAE,CAAC,CAAC,EAAE,OAAO,EAAE,IAAI,EAAE,IAAI,EAAE,EAAE,CAAC,IAAI,EAAE,CAAC;IACvF,IAAI,EAAE,EAAE,IAAI,KAAK,YAAY;QAAE,OAAO,EAAE,CAAC,EAAE,EAAE,CAAC,CAAC,EAAE,CAAC,EAAE,EAAE,CAAC,CAAC,EAAE,OAAO,EAAE,KAAK,EAAE,IAAI,EAAE,CAAC,EAAE,CAAC;IACpF,OAAO,EAAE,CAAC,EAAE,CAAC,EAAE,CAAC,EAAE,CAAC,EAAE,OAAO,EAAE,KAA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,KAAK,CAAC,CAAC;YACpB,CAAC,CAAC;YAEF,gBAAgB,EAAE,CAAC;YACnB,IAAI,CAAC,OAAO,EAAE,CAAC;gBACd,OAAO,GAAG,GAAG,CAAC,KAAK,CAAC,UAAU,CAAC,CAAC,CAAa,EAAE,EAAE;oBAChD,yEAAyE;oBACzE,sEAAsE;oBACtE,IAAI,CAAC,CAAC,IAAI,KAAK,aAAa,IAAI,CAAC,CAAC,IAAI,KAAK,eAAe;wBAAE,gBAAgB,EAAE,CAAC;gBAChF,CAAC,CAAC,CAAC;gBACH,0EAA0E;gBAC1E,2EAA2E;gBAC3E,2EAA2E;gBAC3E,SAAS,GAAG,UAAU,CAAC,GAAG,EAAE;oBAC3B,IAAI,OAAO;wBAAE,OAAO;oBACpB,MAAM,CAAC,GAAG,YAAY,EAAE,CAAC;oBACzB,UAAU,EAAE,CAAC;oBACb,IAAI,CAAC,IAAI,CAAC,CAAC,SAAS,KAAK,KAAK,IAAI,CAAC,CAAC,KAAK;wBAAE,WAAW,CAAC,CAAC,CAAC,KAAK,CAAC,CAAC;gBACjE,CAAC,EAAE,eAAe,CAAC,CAAC;YACrB,CAAC;YAED,OAAO,GAAG,EAAE;gBACX,QAAQ,GAAG,IAAI,CAAC;gBAChB,IAAI,UAAU,EAAE,CAAC;oBAChB,YAAY,CAAC,UAAU,CAAC,CAAC;oBACzB,UAAU,GAAG,IAAI,CAAC;gBACnB,CAAC;gBACD,UAAU,EAAE,CAAC;gBACb,KAAK,CAAC,OAAO,EAAE,CAAC;gBAChB,kBAAkB,EAAE,CAAC;gBACrB,KAAK,MAAM,GAAG,IAAI,IAAI;oBAAE,GAAG,EAAE,CAAC;YAC/B,CAAC,CAAC;QACH,CAAC;KACD,CAAC;AACH,CAAC"}
@@ -0,0 +1,24 @@
1
+ import type { BoardStore } from "@edv4h/usketch-shared";
2
+ import type { StartPosition } from "./start-position-shape.js";
3
+ export interface ApplyOptions {
4
+ animate?: boolean;
5
+ durationMs?: number;
6
+ }
7
+ /**
8
+ * Move the camera to a start position. Returns `false` when it can't be resolved
9
+ * — an unframeable `shape` target (deleted / zero-size) OR malformed coordinates
10
+ * from corrupt synced data — so callers can fall back (e.g. frame all content).
11
+ *
12
+ * `start` comes from synced/persisted shape data, so it is **validated**: a
13
+ * non-finite x/y/zoom (or non-positive zoom) is rejected rather than fed into
14
+ * `animateViewportTo` (which does not clamp) and left to corrupt the viewport.
15
+ */
16
+ export declare function applyStartPosition(store: BoardStore, start: StartPosition, opts?: ApplyOptions): boolean;
17
+ /** The current camera as an exact framing (world center point + zoom) — screen-size
18
+ * independent, so it reproduces on any viewer. Backs "set current view as start". */
19
+ export declare function captureViewport(store: BoardStore): {
20
+ x: number;
21
+ y: number;
22
+ zoom: number;
23
+ };
24
+ //# sourceMappingURL=resolve.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"resolve.d.ts","sourceRoot":"","sources":["../src/resolve.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,uBAAuB,CAAC;AAQxD,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,2BAA2B,CAAC;AAE/D,MAAM,WAAW,YAAY;IAC5B,OAAO,CAAC,EAAE,OAAO,CAAC;IAClB,UAAU,CAAC,EAAE,MAAM,CAAC;CACpB;AAOD;;;;;;;;GAQG;AACH,wBAAgB,kBAAkB,CACjC,KAAK,EAAE,UAAU,EACjB,KAAK,EAAE,aAAa,EACpB,IAAI,GAAE,YAAiB,GACrB,OAAO,CA+BT;AAED;sFACsF;AACtF,wBAAgB,eAAe,CAAC,KAAK,EAAE,UAAU,GAAG;IAAE,CAAC,EAAE,MAAM,CAAC;IAAC,CAAC,EAAE,MAAM,CAAC;IAAC,IAAI,EAAE,MAAM,CAAA;CAAE,CAKzF"}
@@ -0,0 +1,52 @@
1
+ import { centerOnWorld, getRotatedAABB, getScreenSize, safeRotation, screenToWorld, } from "@edv4h/usketch-shared";
2
+ const ZOOM_MIN = 0.1;
3
+ const ZOOM_MAX = 10;
4
+ const isNum = (n) => typeof n === "number" && Number.isFinite(n);
5
+ const clampZoom = (z) => Math.min(Math.max(z, ZOOM_MIN), ZOOM_MAX);
6
+ /**
7
+ * Move the camera to a start position. Returns `false` when it can't be resolved
8
+ * — an unframeable `shape` target (deleted / zero-size) OR malformed coordinates
9
+ * from corrupt synced data — so callers can fall back (e.g. frame all content).
10
+ *
11
+ * `start` comes from synced/persisted shape data, so it is **validated**: a
12
+ * non-finite x/y/zoom (or non-positive zoom) is rejected rather than fed into
13
+ * `animateViewportTo` (which does not clamp) and left to corrupt the viewport.
14
+ */
15
+ export function applyStartPosition(store, start, opts = {}) {
16
+ const { animate = false, durationMs } = opts;
17
+ switch (start.kind) {
18
+ case "coordinate":
19
+ if (!isNum(start.x) || !isNum(start.y))
20
+ return false;
21
+ // Keep the viewer's current zoom; only recenter.
22
+ centerOnWorld(store, { x: start.x, y: start.y }, { animate, durationMs });
23
+ return true;
24
+ case "viewport":
25
+ if (!isNum(start.x) || !isNum(start.y) || !isNum(start.zoom) || start.zoom <= 0)
26
+ return false;
27
+ centerOnWorld(store, { x: start.x, y: start.y }, { zoom: clampZoom(start.zoom), animate, durationMs });
28
+ return true;
29
+ case "shape": {
30
+ const s = store.getShape(start.shapeId);
31
+ if (!s)
32
+ return false;
33
+ const aabb = getRotatedAABB({ x: s.x, y: s.y, width: s.width, height: s.height }, safeRotation(s.rotation));
34
+ // `fitToBounds` is a no-op for a non-positive/NaN box, which would leave the
35
+ // camera unmoved while we wrongly report success — reject so callers fall back.
36
+ if (!isNum(aabb.x) || !isNum(aabb.y) || !(aabb.width > 0) || !(aabb.height > 0))
37
+ return false;
38
+ const padding = isNum(start.padding) && start.padding >= 0 ? start.padding : 80;
39
+ store.fitToBounds(aabb, getScreenSize(), padding, { animate, durationMs });
40
+ return true;
41
+ }
42
+ }
43
+ }
44
+ /** The current camera as an exact framing (world center point + zoom) — screen-size
45
+ * independent, so it reproduces on any viewer. Backs "set current view as start". */
46
+ export function captureViewport(store) {
47
+ const vp = store.getViewport();
48
+ const { width, height } = getScreenSize();
49
+ const c = screenToWorld(width / 2, height / 2, vp);
50
+ return { x: c.x, y: c.y, zoom: vp.zoom };
51
+ }
52
+ //# sourceMappingURL=resolve.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"resolve.js","sourceRoot":"","sources":["../src/resolve.ts"],"names":[],"mappings":"AAGA,OAAO,EACN,aAAa,EACb,cAAc,EACd,aAAa,EACb,YAAY,EACZ,aAAa,GACb,MAAM,uBAAuB,CAAC;AAQ/B,MAAM,QAAQ,GAAG,GAAG,CAAC;AACrB,MAAM,QAAQ,GAAG,EAAE,CAAC;AACpB,MAAM,KAAK,GAAG,CAAC,CAAU,EAAe,EAAE,CAAC,OAAO,CAAC,KAAK,QAAQ,IAAI,MAAM,CAAC,QAAQ,CAAC,CAAC,CAAC,CAAC;AACvF,MAAM,SAAS,GAAG,CAAC,CAAS,EAAU,EAAE,CAAC,IAAI,CAAC,GAAG,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC,EAAE,QAAQ,CAAC,EAAE,QAAQ,CAAC,CAAC;AAEnF;;;;;;;;GAQG;AACH,MAAM,UAAU,kBAAkB,CACjC,KAAiB,EACjB,KAAoB,EACpB,IAAI,GAAiB,EAAE;IAEvB,MAAM,EAAE,OAAO,GAAG,KAAK,EAAE,UAAU,EAAE,GAAG,IAAI,CAAC;IAC7C,QAAQ,KAAK,CAAC,IAAI,EAAE,CAAC;QACpB,KAAK,YAAY;YAChB,IAAI,CAAC,KAAK,CAAC,KAAK,CAAC,CAAC,CAAC,IAAI,CAAC,KAAK,CAAC,KAAK,CAAC,CAAC,CAAC;gBAAE,OAAO,KAAK,CAAC;YACrD,iDAAiD;YACjD,aAAa,CAAC,KAAK,EAAE,EAAE,CAAC,EAAE,KAAK,CAAC,CAAC,EAAE,CAAC,EAAE,KAAK,CAAC,CAAC,EAAE,EAAE,EAAE,OAAO,EAAE,UAAU,EAAE,CAAC,CAAC;YAC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,IAAI,CAAC,CAAC,CAAC,CAAC,KAAK,CAAC,OAAO,CAAC,CAAC,CAAC,EAAE,CAAC;YAChF,KAAK,CAAC,WAAW,CAAC,IAAI,EAAE,aAAa,EAAE,EAAE,OAAO,EAAE,EAAE,OAAO,EAAE,UAAU,EAAE,CAAC,CAAC;YAC3E,OAAO,IAAI,CAAC;QACb,CAAC;IACF,CAAC;AACF,CAAC;AAED;sFACsF;AACtF,MAAM,UAAU,eAAe,CAAC,KAAiB;IAChD,MAAM,EAAE,GAAG,KAAK,CAAC,WAAW,EAAE,CAAC;IAC/B,MAAM,EAAE,KAAK,EAAE,MAAM,EAAE,GAAG,aAAa,EAAE,CAAC;IAC1C,MAAM,CAAC,GAAG,aAAa,CAAC,KAAK,GAAG,CAAC,EAAE,MAAM,GAAG,CAAC,EAAE,EAAE,CAAC,CAAC;IACnD,OAAO,EAAE,CAAC,EAAE,CAAC,CAAC,CAAC,EAAE,CAAC,EAAE,CAAC,CAAC,CAAC,EAAE,IAAI,EAAE,EAAE,CAAC,IAAI,EAAE,CAAC;AAC1C,CAAC"}
@@ -0,0 +1,44 @@
1
+ import type { ShapeData, ShapeDefinition } from "@edv4h/usketch-shared";
2
+ export declare const START_POSITION_TYPE = "start-position";
3
+ /**
4
+ * How the board's start view is defined. A tagged union so a fourth mode (e.g.
5
+ * "named bookmark") is just another variant + a resolver branch.
6
+ * - `coordinate` — center on a world point, keeping the viewer's current zoom.
7
+ * - `viewport` — an exact framing: world center point **and** zoom (画角).
8
+ * - `shape` — frame a specific shape's bounds; re-derived each time so it
9
+ * follows the shape if it moves.
10
+ */
11
+ export type StartPosition = {
12
+ kind: "coordinate";
13
+ x: number;
14
+ y: number;
15
+ } | {
16
+ kind: "viewport";
17
+ x: number;
18
+ y: number;
19
+ zoom: number;
20
+ } | {
21
+ kind: "shape";
22
+ shapeId: string;
23
+ padding?: number;
24
+ };
25
+ export interface StartPositionShapeData extends ShapeData {
26
+ type: typeof START_POSITION_TYPE;
27
+ /** The start definition; `undefined` = not configured yet. */
28
+ start?: StartPosition;
29
+ /**
30
+ * Move each viewer's camera to the start on board load. Per-user/ephemeral —
31
+ * only the *definition* above is synced, not the live camera. Default `true`.
32
+ */
33
+ autoApply?: boolean;
34
+ }
35
+ export declare function isStartPosition(shape: ShapeData): shape is StartPositionShapeData;
36
+ /**
37
+ * The board's start-position shape, chosen **deterministically** (lowest `id`) so
38
+ * every synced client agrees even if several somehow coexist. `null` if none.
39
+ */
40
+ export declare function findStartPosition(shapes: Iterable<ShapeData>): StartPositionShapeData | null;
41
+ /** Create the data-only singleton (locked, invisible, non-hit-testable). */
42
+ export declare function makeStartPosition(): StartPositionShapeData;
43
+ export declare function createStartPositionShapeDefinition(): ShapeDefinition;
44
+ //# sourceMappingURL=start-position-shape.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"start-position-shape.d.ts","sourceRoot":"","sources":["../src/start-position-shape.ts"],"names":[],"mappings":"AAKA,OAAO,KAAK,EAAe,SAAS,EAAE,eAAe,EAAE,MAAM,uBAAuB,CAAC;AAIrF,eAAO,MAAM,mBAAmB,mBAAmB,CAAC;AAEpD;;;;;;;GAOG;AACH,MAAM,MAAM,aAAa,GACtB;IAAE,IAAI,EAAE,YAAY,CAAC;IAAC,CAAC,EAAE,MAAM,CAAC;IAAC,CAAC,EAAE,MAAM,CAAA;CAAE,GAC5C;IAAE,IAAI,EAAE,UAAU,CAAC;IAAC,CAAC,EAAE,MAAM,CAAC;IAAC,CAAC,EAAE,MAAM,CAAC;IAAC,IAAI,EAAE,MAAM,CAAA;CAAE,GACxD;IAAE,IAAI,EAAE,OAAO,CAAC;IAAC,OAAO,EAAE,MAAM,CAAC;IAAC,OAAO,CAAC,EAAE,MAAM,CAAA;CAAE,CAAC;AAExD,MAAM,WAAW,sBAAuB,SAAQ,SAAS;IACxD,IAAI,EAAE,OAAO,mBAAmB,CAAC;IACjC,8DAA8D;IAC9D,KAAK,CAAC,EAAE,aAAa,CAAC;IACtB;;;OAGG;IACH,SAAS,CAAC,EAAE,OAAO,CAAC;CACpB;AAED,wBAAgB,eAAe,CAAC,KAAK,EAAE,SAAS,GAAG,KAAK,IAAI,sBAAsB,CAEjF;AAED;;;GAGG;AACH,wBAAgB,iBAAiB,CAAC,MAAM,EAAE,QAAQ,CAAC,SAAS,CAAC,GAAG,sBAAsB,GAAG,IAAI,CAI5F;AAED,4EAA4E;AAC5E,wBAAgB,iBAAiB,IAAI,sBAAsB,CAY1D;AAED,wBAAgB,kCAAkC,IAAI,eAAe,CAqBpE"}
@@ -0,0 +1,54 @@
1
+ import { generateId } from "@edv4h/usketch-shared";
2
+ import { createElement } from "react";
3
+ export const START_POSITION_TYPE = "start-position";
4
+ export function isStartPosition(shape) {
5
+ return shape.type === START_POSITION_TYPE;
6
+ }
7
+ /**
8
+ * The board's start-position shape, chosen **deterministically** (lowest `id`) so
9
+ * every synced client agrees even if several somehow coexist. `null` if none.
10
+ */
11
+ export function findStartPosition(shapes) {
12
+ let best = null;
13
+ for (const s of shapes)
14
+ if (isStartPosition(s) && (best === null || s.id < best.id))
15
+ best = s;
16
+ return best;
17
+ }
18
+ /** Create the data-only singleton (locked, invisible, non-hit-testable). */
19
+ export function makeStartPosition() {
20
+ return {
21
+ id: generateId(),
22
+ type: START_POSITION_TYPE,
23
+ x: 0,
24
+ y: 0,
25
+ width: 0,
26
+ height: 0,
27
+ style: { fill: "transparent", stroke: "transparent", strokeWidth: 0, opacity: 1 },
28
+ autoApply: true,
29
+ locked: true,
30
+ };
31
+ }
32
+ export function createStartPositionShapeDefinition() {
33
+ const zeroBounds = () => ({ x: 0, y: 0, width: 0, height: 0 });
34
+ return {
35
+ // Renders nothing — it is pure data. (Empty SVG group, like the tilemap.)
36
+ render: () => createElement("g"),
37
+ renderTarget: "svg",
38
+ getBounds: zeroBounds,
39
+ // Never selectable via pointer — it is config, not an object.
40
+ hitTest: () => false,
41
+ resizable: false,
42
+ resize: (data) => data,
43
+ createDefault: (params) => ({ ...makeStartPosition(), id: params.id }),
44
+ serializeForAi: (data) => {
45
+ const d = data;
46
+ return { kind: "start-position", start: d.start ?? null, autoApply: d.autoApply !== false };
47
+ },
48
+ debugFields: (data) => {
49
+ const d = data;
50
+ return { start: d.start?.kind ?? "none", autoApply: d.autoApply !== false };
51
+ },
52
+ };
53
+ }
54
+ //# sourceMappingURL=start-position-shape.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"start-position-shape.js","sourceRoot":"","sources":["../src/start-position-shape.ts"],"names":[],"mappings":"AAMA,OAAO,EAAE,UAAU,EAAE,MAAM,uBAAuB,CAAC;AACnD,OAAO,EAAE,aAAa,EAAqB,MAAM,OAAO,CAAC;AAEzD,MAAM,CAAC,MAAM,mBAAmB,GAAG,gBAAgB,CAAC;AA0BpD,MAAM,UAAU,eAAe,CAAC,KAAgB;IAC/C,OAAO,KAAK,CAAC,IAAI,KAAK,mBAAmB,CAAC;AAC3C,CAAC;AAED;;;GAGG;AACH,MAAM,UAAU,iBAAiB,CAAC,MAA2B;IAC5D,IAAI,IAAI,GAAkC,IAAI,CAAC;IAC/C,KAAK,MAAM,CAAC,IAAI,MAAM;QAAE,IAAI,eAAe,CAAC,CAAC,CAAC,IAAI,CAAC,IAAI,KAAK,IAAI,IAAI,CAAC,CAAC,EAAE,GAAG,IAAI,CAAC,EAAE,CAAC;YAAE,IAAI,GAAG,CAAC,CAAC;IAC9F,OAAO,IAAI,CAAC;AACb,CAAC;AAED,4EAA4E;AAC5E,MAAM,UAAU,iBAAiB;IAChC,OAAO;QACN,EAAE,EAAE,UAAU,EAAE;QAChB,IAAI,EAAE,mBAAmB;QACzB,CAAC,EAAE,CAAC;QACJ,CAAC,EAAE,CAAC;QACJ,KAAK,EAAE,CAAC;QACR,MAAM,EAAE,CAAC;QACT,KAAK,EAAE,EAAE,IAAI,EAAE,aAAa,EAAE,MAAM,EAAE,aAAa,EAAE,WAAW,EAAE,CAAC,EAAE,OAAO,EAAE,CAAC,EAAE;QACjF,SAAS,EAAE,IAAI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ViewportClaim {
4
+ /** Who is taking the camera (e.g. "deep-link", "start-position"). */
5
+ source: string;
6
+ /** Higher wins. */
7
+ priority: number;
8
+ }
9
+ export declare const DEEP_LINK_PRIORITY = 100;
10
+ export declare const START_POSITION_PRIORITY = 10;
11
+ /** Announce that `source` is taking the load-time camera at `priority`. */
12
+ export declare function claimViewport(events: EventBus, source: string, priority: number): void;
13
+ export interface ClaimGuard {
14
+ /** True if another source claimed a priority >= yours ⇒ you should defer. */
15
+ shouldYield(): boolean;
16
+ dispose(): void;
17
+ }
18
+ /**
19
+ * Watch for competing viewport claims. Track the highest priority claimed by any
20
+ * OTHER source; call {@link ClaimGuard.shouldYield} right before your own camera
21
+ * move. Your own claims (matching `mySource`) are ignored so emitting one doesn't
22
+ * make you yield to yourself.
23
+ */
24
+ export declare function watchViewportClaims(events: EventBus, mySource: string, myPriority: number): ClaimGuard;
25
+ //# sourceMappingURL=viewport-claim.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"viewport-claim.d.ts","sourceRoot":"","sources":["../src/viewport-claim.ts"],"names":[],"mappings":"AASA,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,uBAAuB,CAAC;AAEtD,eAAO,MAAM,gBAAgB,qBAAqB,CAAC;AAEnD,MAAM,WAAW,aAAa;IAC7B,qEAAqE;IACrE,MAAM,EAAE,MAAM,CAAC;IACf,mBAAmB;IACnB,QAAQ,EAAE,MAAM,CAAC;CACjB;AAED,eAAO,MAAM,kBAAkB,MAAM,CAAC;AACtC,eAAO,MAAM,uBAAuB,KAAK,CAAC;AAE1C,2EAA2E;AAC3E,wBAAgB,aAAa,CAAC,MAAM,EAAE,QAAQ,EAAE,MAAM,EAAE,MAAM,EAAE,QAAQ,EAAE,MAAM,GAAG,IAAI,CAEtF;AAED,MAAM,WAAW,UAAU;IAC1B,6EAA6E;IAC7E,WAAW,IAAI,OAAO,CAAC;IACvB,OAAO,IAAI,IAAI,CAAC;CAChB;AAED;;;;;GAKG;AACH,wBAAgB,mBAAmB,CAClC,MAAM,EAAE,QAAQ,EAChB,QAAQ,EAAE,MAAM,EAChB,UAAU,EAAE,MAAM,GAChB,UAAU,CAaZ"}
@@ -0,0 +1,28 @@
1
+ export const VIEWPORT_CLAIMED = "viewport:claimed";
2
+ export const DEEP_LINK_PRIORITY = 100;
3
+ export const START_POSITION_PRIORITY = 10;
4
+ /** Announce that `source` is taking the load-time camera at `priority`. */
5
+ export function claimViewport(events, source, priority) {
6
+ events.emit(VIEWPORT_CLAIMED, { source, priority });
7
+ }
8
+ /**
9
+ * Watch for competing viewport claims. Track the highest priority claimed by any
10
+ * OTHER source; call {@link ClaimGuard.shouldYield} right before your own camera
11
+ * move. Your own claims (matching `mySource`) are ignored so emitting one doesn't
12
+ * make you yield to yourself.
13
+ */
14
+ export function watchViewportClaims(events, mySource, myPriority) {
15
+ let maxOther = Number.NEGATIVE_INFINITY;
16
+ const off = events.on(VIEWPORT_CLAIMED, (c) => {
17
+ // Require a FINITE priority: a NaN would poison `maxOther` via Math.max and,
18
+ // since every NaN comparison is false, make `shouldYield()` never yield again.
19
+ if (c && c.source !== mySource && Number.isFinite(c.priority)) {
20
+ maxOther = Math.max(maxOther, c.priority);
21
+ }
22
+ });
23
+ return {
24
+ shouldYield: () => maxOther >= myPriority,
25
+ dispose: off,
26
+ };
27
+ }
28
+ //# sourceMappingURL=viewport-claim.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"viewport-claim.js","sourceRoot":"","sources":["../src/viewport-claim.ts"],"names":[],"mappings":"AAWA,MAAM,CAAC,MAAM,gBAAgB,GAAG,kBAAkB,CAAC;AASnD,MAAM,CAAC,MAAM,kBAAkB,GAAG,GAAG,CAAC;AACtC,MAAM,CAAC,MAAM,uBAAuB,GAAG,EAAE,CAAC;AAE1C,2EAA2E;AAC3E,MAAM,UAAU,aAAa,CAAC,MAAgB,EAAE,MAAc,EAAE,QAAgB;IAC/E,MAAM,CAAC,IAAI,CAAC,gBAAgB,EAAE,EAAE,MAAM,EAAE,QAAQ,EAA0B,CAAC,CAAC;AAC7E,CAAC;AAQD;;;;;GAKG;AACH,MAAM,UAAU,mBAAmB,CAClC,MAAgB,EAChB,QAAgB,EAChB,UAAkB;IAElB,IAAI,QAAQ,GAAG,MAAM,CAAC,iBAAiB,CAAC;IACxC,MAAM,GAAG,GAAG,MAAM,CAAC,EAAE,CAAgB,gBAAgB,EAAE,CAAC,CAAC,EAAE,EAAE;QAC5D,6EAA6E;QAC7E,+EAA+E;QAC/E,IAAI,CAAC,IAAI,CAAC,CAAC,MAAM,KAAK,QAAQ,IAAI,MAAM,CAAC,QAAQ,CAAC,CAAC,CAAC,QAAQ,CAAC,EAAE,CAAC;YAC/D,QAAQ,GAAG,IAAI,CAAC,GAAG,CAAC,QAAQ,EAAE,CAAC,CAAC,QAAQ,CAAC,CAAC;QAC3C,CAAC;IACF,CAAC,CAAC,CAAC;IACH,OAAO;QACN,WAAW,EAAE,GAAG,EAAE,CAAC,QAAQ,IAAI,UAAU;QACzC,OAAO,EAAE,GAAG;KACZ,CAAC;AACH,CAAC"}
package/package.json ADDED
@@ -0,0 +1,48 @@
1
+ {
2
+ "name": "@edv4h/usketch-plugin-start-position",
3
+ "version": "0.1.0",
4
+ "type": "module",
5
+ "main": "./dist/index.js",
6
+ "types": "./dist/index.d.ts",
7
+ "exports": {
8
+ ".": {
9
+ "source": "./src/index.ts",
10
+ "types": "./dist/index.d.ts",
11
+ "import": "./dist/index.js"
12
+ }
13
+ },
14
+ "dependencies": {
15
+ "@edv4h/usketch-shared": "4.10.0"
16
+ },
17
+ "peerDependencies": {
18
+ "react": ">=19"
19
+ },
20
+ "devDependencies": {
21
+ "@types/react": "19.2.18",
22
+ "typescript": "7.0.2",
23
+ "vitest": "4.1.10"
24
+ },
25
+ "publishConfig": {
26
+ "access": "public"
27
+ },
28
+ "files": [
29
+ "dist",
30
+ "README.md"
31
+ ],
32
+ "license": "MIT",
33
+ "repository": {
34
+ "type": "git",
35
+ "url": "git+https://github.com/EdV4H/usketch.git",
36
+ "directory": "plugins/usketch-plugin-start-position"
37
+ },
38
+ "homepage": "https://github.com/EdV4H/usketch#readme",
39
+ "bugs": {
40
+ "url": "https://github.com/EdV4H/usketch/issues"
41
+ },
42
+ "scripts": {
43
+ "build": "tsc -p tsconfig.json",
44
+ "typecheck": "tsc --noEmit",
45
+ "test": "vitest run --passWithNoTests",
46
+ "clean": "rm -rf dist"
47
+ }
48
+ }