@onlyworlds/sdk 4.112.0 → 4.113.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.
@@ -0,0 +1,468 @@
1
+ import {
2
+ TOOLS,
3
+ doorWhere,
4
+ doorsOf,
5
+ elementAddress,
6
+ openersFor,
7
+ refuseUnknownOptions,
8
+ typeWord
9
+ } from "./chunk-PVVXKLWE.js";
10
+
11
+ // src/waymark/glyphs.ts
12
+ var MARK_PATH = "M48.8 0.0 43.8 0.4 39.0 1.2 36.0 2.0 33.2 2.9 29.3 4.5 24.8 6.8 20.6 9.5 17.0 12.4 13.6 15.7 10.4 19.4 7.8 23.1 5.8 26.6 4.5 29.3 3.3 32.1 1.8 36.8 0.8 41.2 0.1 46.3 0.0 51.1 0.4 56.2 1.2 61.0 2.0 63.9 2.9 66.8 4.5 70.7 6.8 75.2 9.5 79.4 12.4 82.9 15.7 86.3 19.4 89.5 23.1 92.1 26.6 94.2 29.3 95.5 32.1 96.7 36.8 98.2 41.2 99.2 46.3 99.8 51.1 100.0 56.2 99.6 61.0 98.8 63.9 98.0 66.8 97.1 70.7 95.5 75.2 93.2 79.4 90.4 82.9 87.6 86.3 84.3 89.5 80.5 92.1 76.9 94.2 73.4 95.5 70.7 96.7 67.9 98.2 63.2 99.2 58.7 99.8 53.7 100.0 48.8 99.6 43.8 98.6 38.4 97.1 33.2 95.5 29.3 93.2 24.8 90.4 20.6 87.6 17.0 84.3 13.6 80.5 10.4 76.9 7.8 73.4 5.8 70.7 4.5 67.9 3.3 63.2 1.8 58.7 0.8 53.7 0.1ZM77.5 80.7 74.1 83.4 70.7 85.7 67.0 87.5 64.5 88.6 64.1 88.7 65.7 86.3 67.1 83.9 68.7 80.7 69.9 77.6 72.7 78.5 73.0 78.4ZM22.5 80.7 25.6 79.0 27.3 78.3 30.0 77.6 31.3 80.7 32.8 83.9 34.2 86.3 35.9 88.7 32.9 87.5 29.3 85.7 25.8 83.4ZM51.2 74.5 55.1 74.7 59.9 75.2 64.2 76.0 67.5 76.9 66.0 80.5 64.2 84.0 62.0 87.4 59.6 90.1 55.1 90.9 52.2 91.2 51.2 91.1ZM48.7 74.5 48.8 91.1 47.7 91.2 44.9 90.9 40.3 90.1 38.2 87.8 36.3 85.0 34.2 81.2 32.5 77.0 35.8 76.0 40.5 75.2 44.5 74.7ZM91.1 51.2 91.1 52.9 90.8 56.3 90.1 59.7 89.3 62.5 88.5 64.8 87.2 67.7 85.7 70.7 83.9 73.4 82.0 75.9 79.4 78.9 76.3 77.2 73.8 76.1 76.2 68.8 77.8 62.7 78.7 56.8 79.0 51.2ZM55.8 51.2 67.7 51.2 67.6 55.1 67.2 59.0 66.7 61.5 65.7 65.0 61.0 64.2 55.7 63.6ZM32.5 51.2 44.5 51.2 44.4 63.6 39.7 64.1 34.5 65.0 33.5 61.3 32.9 58.1 32.5 54.2ZM8.8 51.2 21.0 51.2 21.0 53.3 21.4 56.6 22.7 64.0 23.8 68.4 25.0 72.1 26.6 75.9 23.7 77.2 20.6 78.9 18.5 76.7 16.5 74.1 14.8 71.5 13.4 69.1 12.1 66.3 11.0 63.6 10.1 60.5 9.4 57.3 8.9 53.5 8.8 51.3ZM36.2 27.0 39.5 27.5 44.5 28.2 44.4 48.8 32.4 48.7 32.8 44.5 33.6 39.1 35.0 32.0ZM63.9 26.9 65.2 32.1 66.6 39.2 67.4 44.8 67.7 48.7 55.8 48.8 55.7 28.1 60.5 27.5ZM74.8 23.4 76.9 22.5 79.4 21.1 82.0 24.0 84.8 27.8 86.2 30.3 87.5 32.9 88.6 35.4 89.5 38.1 90.3 41.2 90.8 44.0 91.1 47.0 91.1 48.8 79.0 48.7 78.7 44.6 78.0 39.3 76.5 31.2 74.7 23.5ZM25.5 23.5 25.5 23.7 24.5 26.8 23.7 30.2 22.4 36.6 21.5 42.5 21.1 48.7 8.8 48.8 8.8 47.0 9.2 43.7 9.8 40.8 10.5 38.1 11.5 35.2 12.4 32.9 13.8 30.2 15.2 27.8 17.9 24.0 20.6 21.1 23.1 22.5ZM64.1 11.3 67.0 12.4 70.7 14.3 74.1 16.5 77.5 19.3 75.6 20.3 73.2 21.5 70.0 22.6 68.7 19.2 67.1 16.1 65.7 13.6ZM35.9 11.3 34.2 13.6 32.8 16.1 31.3 19.2 30.0 22.5 27.9 21.9 26.4 21.3 22.5 19.3 25.8 16.5 29.3 14.3 32.9 12.4 35.4 11.4ZM51.2 8.8 52.2 8.8 55.1 9.0 59.6 9.9 61.7 12.2 64.2 16.0 66.0 19.5 67.6 23.3 64.3 24.3 59.4 25.2 56.2 25.6 51.2 25.5ZM48.8 8.8 48.7 25.5 44.2 25.6 40.6 25.2 36.4 24.5 32.4 23.2 33.9 19.5 35.7 16.0 38.2 12.2 40.3 9.9 44.9 9.0 47.7 8.8Z";
13
+ var TOOL_GLYPH = [
14
+ ["rect", { x: "3.5", y: "4.5", width: "17", height: "15", rx: "3" }],
15
+ ["path", { d: "M3.5 9.5h17" }]
16
+ ];
17
+ var COPY_GLYPH = [
18
+ ["rect", { x: "9", y: "9", width: "11", height: "11", rx: "2" }],
19
+ ["path", { d: "M5 15V6a2 2 0 0 1 2-2h8" }]
20
+ ];
21
+ var LENS_GLYPH = [
22
+ ["circle", { cx: "12", cy: "12", r: "8" }],
23
+ ["circle", { cx: "12", cy: "12", r: "3.5" }]
24
+ ];
25
+ var CHEVRON_GLYPH = [["path", { d: "m7 10 5 5 5-5" }]];
26
+
27
+ // src/waymark/index.ts
28
+ var OPTION_KEYS = [
29
+ "world",
30
+ "element",
31
+ "reader",
32
+ "tool",
33
+ "signedIn",
34
+ "browser",
35
+ "phone",
36
+ "tools",
37
+ "lenses",
38
+ "ground",
39
+ "entry",
40
+ "returnFocus"
41
+ ];
42
+ var READERS = ["member", "guest", "public"];
43
+ var GROUNDS = ["dark", "paper"];
44
+ var ENTRIES = ["mark", "menu", "both"];
45
+ var SVG = "http://www.w3.org/2000/svg";
46
+ var MONTHS = ["Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec"];
47
+ var TOAST_MS = 2e3;
48
+ var COPIED = "Link copied";
49
+ var NOT_COPIED = "Could not copy the link.";
50
+ var mounted = 0;
51
+ var fail = (what) => {
52
+ throw new TypeError(`mountWaymark: ${what}`);
53
+ };
54
+ function cannotOpen(state) {
55
+ return state !== null && (state.startsWith("Sign in to ") || state === "Needs the world on this phone");
56
+ }
57
+ function shapedOn(at, now) {
58
+ const d = new Date(at);
59
+ const day = `${d.getDate()} ${MONTHS[d.getMonth()]}`;
60
+ return d.getFullYear() === now.getFullYear() ? day : `${day} ${d.getFullYear()}`;
61
+ }
62
+ function mountWaymark(target, options) {
63
+ if (target === null || typeof target !== "object" || typeof target.appendChild !== "function" || !target.ownerDocument) {
64
+ fail("target is the DOM element that holds the name");
65
+ }
66
+ if (options === null || typeof options !== "object" || Array.isArray(options)) fail("options is an object ({ world, reader, ... })");
67
+ refuseUnknownOptions("mountWaymark", options, OPTION_KEYS);
68
+ const {
69
+ world,
70
+ element = null,
71
+ reader,
72
+ tool = null,
73
+ signedIn = null,
74
+ browser = true,
75
+ phone = false,
76
+ tools = TOOLS,
77
+ lenses = null,
78
+ ground = "dark",
79
+ entry = "mark",
80
+ returnFocus = null
81
+ } = options;
82
+ if (world === null || typeof world !== "object" || typeof world.id !== "string" || typeof world.name !== "string") {
83
+ fail("world is an object with a string id and name");
84
+ }
85
+ if (element !== null && (typeof element !== "object" || typeof element.id !== "string" || typeof element.type !== "string" || typeof element.name !== "string")) {
86
+ fail("element is null or an element body with a string id, type and name");
87
+ }
88
+ if (!READERS.includes(reader)) fail(`reader is 'member', 'guest' or 'public'; got ${JSON.stringify(reader)}`);
89
+ if (!GROUNDS.includes(ground)) fail(`ground is 'dark' or 'paper'; got ${JSON.stringify(ground)}`);
90
+ if (!ENTRIES.includes(entry)) fail(`entry is 'mark', 'menu' or 'both'; got ${JSON.stringify(entry)}`);
91
+ if (returnFocus !== null) {
92
+ if (entry === "mark") fail("returnFocus is for entry 'menu' or 'both': with the mark alone, focus returns to the mark");
93
+ const View = target.ownerDocument.defaultView?.HTMLElement;
94
+ const isElement = View ? returnFocus instanceof View : typeof returnFocus === "object" && returnFocus.nodeType === 1;
95
+ if (!isElement) fail("returnFocus is an HTMLElement: the surface's own button that takes focus back");
96
+ }
97
+ if (lenses !== null && !Array.isArray(lenses)) fail("lenses is an array of { id, name } or null");
98
+ for (const l of lenses ?? []) {
99
+ if (l === null || typeof l !== "object" || typeof l.id !== "string" || typeof l.name !== "string") fail("each lens is { id, name }, both strings");
100
+ }
101
+ const isPublic = reader === "public";
102
+ const kind = element === null ? "world" : "element";
103
+ const address = element === null ? { form: "human", world: world.id } : { form: "human", world: world.id, type: element.type, id: element.id };
104
+ const rows = openersFor(tools, kind, address, { tool, audience: isPublic ? "public" : "member", signedIn, browser, phone });
105
+ const throughLenses = isPublic ? [] : [...lenses ?? []];
106
+ const linkFor = (lens) => elementAddress({ ...address, lens });
107
+ for (const l of throughLenses) linkFor(l.id);
108
+ const doc = target.ownerDocument;
109
+ const win = doc.defaultView;
110
+ const timers = win ?? globalThis;
111
+ const last = !isPublic && element !== null ? doorsOf(element, tools)[0] : void 0;
112
+ const doorLine = last === void 0 ? null : `Last shaped ${doorWhere(last)}, ${shapedOn(last.at, /* @__PURE__ */ new Date())}`;
113
+ const typeLine = element === null ? null : typeWord(world, element.type) ?? element.type.charAt(0).toUpperCase() + element.type.slice(1);
114
+ const n = ++mounted;
115
+ const listeners = [];
116
+ const openListeners = [];
117
+ const on = (list, t, type, fn, capture = false) => {
118
+ t.addEventListener(type, fn, capture);
119
+ list.push([t, type, fn, capture]);
120
+ };
121
+ const offAll = (list) => {
122
+ for (const [t, type, fn, capture] of list.splice(0)) t.removeEventListener(type, fn, capture);
123
+ };
124
+ const el = (tag, cls, text) => {
125
+ const node = doc.createElement(tag);
126
+ node.className = cls;
127
+ if (text !== void 0) node.textContent = text;
128
+ return node;
129
+ };
130
+ const markSvg = (cls) => {
131
+ const svg = doc.createElementNS(SVG, "svg");
132
+ svg.setAttribute("class", cls);
133
+ svg.setAttribute("viewBox", "0 0 100 100");
134
+ svg.setAttribute("aria-hidden", "true");
135
+ svg.setAttribute("focusable", "false");
136
+ const path = doc.createElementNS(SVG, "path");
137
+ path.setAttribute("fill", "currentColor");
138
+ path.setAttribute("fill-rule", "evenodd");
139
+ path.setAttribute("d", MARK_PATH);
140
+ svg.appendChild(path);
141
+ return svg;
142
+ };
143
+ const glyph = (shapes, cls) => {
144
+ const svg = doc.createElementNS(SVG, "svg");
145
+ svg.setAttribute("class", cls);
146
+ svg.setAttribute("viewBox", "0 0 24 24");
147
+ svg.setAttribute("fill", "none");
148
+ svg.setAttribute("stroke", "currentColor");
149
+ svg.setAttribute("stroke-width", "1.6");
150
+ svg.setAttribute("stroke-linecap", "round");
151
+ svg.setAttribute("stroke-linejoin", "round");
152
+ svg.setAttribute("aria-hidden", "true");
153
+ svg.setAttribute("focusable", "false");
154
+ for (const [tag, attrs] of shapes) {
155
+ const shape = doc.createElementNS(SVG, tag);
156
+ for (const [k, v] of Object.entries(attrs)) shape.setAttribute(k, v);
157
+ svg.appendChild(shape);
158
+ }
159
+ return svg;
160
+ };
161
+ const root = el("span", `ow-waymark ow-waymark--${ground}`);
162
+ const menuId = `ow-waymark-${n}-menu`;
163
+ const nameId = `ow-waymark-${n}-name`;
164
+ let mark = null;
165
+ if (entry !== "menu") {
166
+ mark = el("button", "ow-waymark__mark");
167
+ mark.type = "button";
168
+ mark.setAttribute("aria-label", "Open with");
169
+ mark.setAttribute("aria-haspopup", "menu");
170
+ mark.setAttribute("aria-expanded", "false");
171
+ mark.setAttribute("aria-controls", menuId);
172
+ mark.appendChild(markSvg("ow-waymark__glyph"));
173
+ root.appendChild(mark);
174
+ }
175
+ const menuEntry = entry !== "mark" ? el("button", "ow-waymark-entry", "Open with") : null;
176
+ if (menuEntry !== null) {
177
+ menuEntry.type = "button";
178
+ menuEntry.setAttribute("aria-haspopup", "menu");
179
+ menuEntry.setAttribute("aria-expanded", "false");
180
+ menuEntry.setAttribute("aria-controls", menuId);
181
+ }
182
+ const openers = [mark, menuEntry].filter((b) => b !== null);
183
+ let openedBy = openers[0];
184
+ const focusBack = () => openedBy === menuEntry ? returnFocus ?? menuEntry : openedBy;
185
+ const scrim = el("div", "ow-waymark__scrim");
186
+ scrim.hidden = true;
187
+ root.appendChild(scrim);
188
+ const pop = el("div", "ow-waymark__pop");
189
+ pop.hidden = true;
190
+ root.appendChild(pop);
191
+ pop.appendChild(el("div", "ow-waymark__grab"));
192
+ const head = el("div", "ow-waymark__head");
193
+ const tile = el("span", "ow-waymark__tile");
194
+ tile.appendChild(markSvg("ow-waymark__glyph"));
195
+ head.appendChild(tile);
196
+ const names = el("div", "ow-waymark__names");
197
+ const name = el("div", "ow-waymark__name", element === null ? world.name : element.name);
198
+ name.id = nameId;
199
+ names.appendChild(name);
200
+ if (typeLine !== null) {
201
+ const sub = el("div", "ow-waymark__sub");
202
+ sub.appendChild(el("span", "ow-waymark__type", typeLine));
203
+ sub.appendChild(el("span", "ow-waymark__world", `in ${world.name}`));
204
+ names.appendChild(sub);
205
+ }
206
+ head.appendChild(names);
207
+ pop.appendChild(head);
208
+ if (doorLine !== null) pop.appendChild(el("div", "ow-waymark__door", doorLine));
209
+ const menu = el("div", "ow-waymark__menu");
210
+ menu.id = menuId;
211
+ menu.setAttribute("role", "menu");
212
+ menu.setAttribute("aria-labelledby", nameId);
213
+ pop.appendChild(menu);
214
+ const section = (label) => {
215
+ const group = el("div", "ow-waymark__group");
216
+ group.setAttribute("role", "group");
217
+ group.setAttribute("aria-label", label);
218
+ const heading = el("div", "ow-waymark__sec", label);
219
+ heading.setAttribute("aria-hidden", "true");
220
+ group.appendChild(heading);
221
+ menu.appendChild(group);
222
+ return group;
223
+ };
224
+ const openWith = section("Open with");
225
+ for (const r of rows) {
226
+ const a = el("a", `ow-waymark__row${cannotOpen(r.state) ? " ow-waymark__row--cannot" : ""}`);
227
+ a.href = r.href;
228
+ a.setAttribute("role", "menuitem");
229
+ a.dataset.opener = r.id;
230
+ a.appendChild(r.id === "onlyworlds" ? markSvg("ow-waymark__icon") : glyph(TOOL_GLYPH, "ow-waymark__icon"));
231
+ a.appendChild(el("span", "ow-waymark__label", r.name));
232
+ if (r.state !== null) a.appendChild(el("span", "ow-waymark__state", r.state));
233
+ openWith.appendChild(a);
234
+ }
235
+ let chosenLens = null;
236
+ let lensToggle = null;
237
+ let lensList = null;
238
+ let lensValue = null;
239
+ if (throughLenses.length > 0) {
240
+ const through = section("Through");
241
+ lensToggle = el("button", "ow-waymark__row");
242
+ lensToggle.type = "button";
243
+ lensToggle.setAttribute("role", "menuitem");
244
+ lensToggle.setAttribute("aria-haspopup", "true");
245
+ lensToggle.setAttribute("aria-expanded", "false");
246
+ lensToggle.appendChild(glyph(LENS_GLYPH, "ow-waymark__icon ow-waymark__icon--small"));
247
+ lensToggle.appendChild(el("span", "ow-waymark__label", "In a lens"));
248
+ lensValue = el("span", "ow-waymark__state");
249
+ lensToggle.appendChild(lensValue);
250
+ lensToggle.appendChild(glyph(CHEVRON_GLYPH, "ow-waymark__chevron"));
251
+ through.appendChild(lensToggle);
252
+ lensList = el("div", "ow-waymark__lenses");
253
+ lensList.setAttribute("role", "group");
254
+ lensList.setAttribute("aria-label", "In a lens");
255
+ lensList.hidden = true;
256
+ for (const l of throughLenses) {
257
+ const b = el("button", "ow-waymark__row ow-waymark__row--lens", l.name);
258
+ b.type = "button";
259
+ b.setAttribute("role", "menuitemradio");
260
+ b.setAttribute("aria-checked", "false");
261
+ b.dataset.lens = l.id;
262
+ lensList.appendChild(b);
263
+ }
264
+ through.appendChild(lensList);
265
+ }
266
+ const sep = el("div", "ow-waymark__sep");
267
+ sep.setAttribute("role", "separator");
268
+ menu.appendChild(sep);
269
+ const copy = el("button", "ow-waymark__row");
270
+ copy.type = "button";
271
+ copy.setAttribute("role", "menuitem");
272
+ copy.appendChild(glyph(COPY_GLYPH, "ow-waymark__icon ow-waymark__icon--small"));
273
+ copy.appendChild(el("span", "ow-waymark__label", "Copy link"));
274
+ menu.appendChild(copy);
275
+ const toast = el("div", "ow-waymark__toast");
276
+ toast.setAttribute("role", "status");
277
+ toast.hidden = true;
278
+ const toastLine = el("span", "ow-waymark__toast-line");
279
+ toastLine.appendChild(glyph(COPY_GLYPH, "ow-waymark__icon ow-waymark__icon--small"));
280
+ const toastWords = el("span", "ow-waymark__label", COPIED);
281
+ toastWords.id = `ow-waymark-${n}-toast`;
282
+ toastLine.appendChild(toastWords);
283
+ toast.appendChild(toastLine);
284
+ const addressLine = el("input", "ow-waymark__address");
285
+ addressLine.type = "text";
286
+ addressLine.readOnly = true;
287
+ addressLine.setAttribute("aria-labelledby", toastWords.id);
288
+ addressLine.hidden = true;
289
+ toast.appendChild(addressLine);
290
+ root.appendChild(toast);
291
+ let toastTimer = null;
292
+ let disposed = false;
293
+ const items = () => Array.from(menu.querySelectorAll('[role="menuitem"], [role="menuitemradio"]')).filter((i) => !i.closest("[hidden]"));
294
+ const isOpen = () => !pop.hidden;
295
+ const open = (from, focus) => {
296
+ if (isOpen()) return;
297
+ openedBy = from;
298
+ pressedInside = false;
299
+ pop.hidden = false;
300
+ scrim.hidden = false;
301
+ from.setAttribute("aria-expanded", "true");
302
+ on(openListeners, doc, "pointerdown", onOutside, true);
303
+ const list = items();
304
+ (focus === "first" ? list[0] : list[list.length - 1])?.focus();
305
+ };
306
+ const failed = () => !addressLine.hidden;
307
+ const close = (refocus) => {
308
+ if (!isOpen()) return;
309
+ pop.hidden = true;
310
+ scrim.hidden = true;
311
+ openedBy.setAttribute("aria-expanded", "false");
312
+ offAll(openListeners);
313
+ if (failed()) {
314
+ toast.hidden = true;
315
+ addressLine.hidden = true;
316
+ toast.classList.remove("ow-waymark__toast--failed");
317
+ }
318
+ if (refocus) focusBack().focus();
319
+ };
320
+ const copied = () => {
321
+ toastWords.textContent = COPIED;
322
+ toast.hidden = false;
323
+ if (toastTimer !== null) timers.clearTimeout(toastTimer);
324
+ toastTimer = timers.setTimeout(() => {
325
+ toastTimer = null;
326
+ toast.hidden = true;
327
+ }, TOAST_MS);
328
+ };
329
+ const notCopied = (text) => {
330
+ if (toastTimer !== null) timers.clearTimeout(toastTimer);
331
+ toastTimer = null;
332
+ toastWords.textContent = NOT_COPIED;
333
+ addressLine.value = text;
334
+ addressLine.hidden = false;
335
+ toast.classList.add("ow-waymark__toast--failed");
336
+ toast.hidden = false;
337
+ addressLine.focus();
338
+ addressLine.select();
339
+ };
340
+ let pressedInside = false;
341
+ function onOutside(e) {
342
+ const t = e.target;
343
+ pressedInside = t !== null && (root.contains(t) || menuEntry?.contains(t) === true);
344
+ if (pressedInside) return;
345
+ close(false);
346
+ }
347
+ let openAtPress = false;
348
+ const onOpenerPress = () => {
349
+ openAtPress = isOpen();
350
+ };
351
+ const onOpenerClick = (e) => {
352
+ const wasOpen = openAtPress || isOpen();
353
+ openAtPress = false;
354
+ if (wasOpen) close(false);
355
+ else open(e.currentTarget, "first");
356
+ };
357
+ const onOpenerKey = (e) => {
358
+ if (e.key === "ArrowDown" || e.key === "ArrowUp") {
359
+ e.preventDefault();
360
+ open(e.currentTarget, e.key === "ArrowDown" ? "first" : "last");
361
+ } else if (e.key === "Escape" && isOpen()) {
362
+ e.preventDefault();
363
+ close(true);
364
+ }
365
+ };
366
+ const onMenuKey = (e) => {
367
+ pressedInside = false;
368
+ const list = items();
369
+ const at = list.indexOf(doc.activeElement);
370
+ let next;
371
+ if (e.key === "ArrowDown") next = list[(at + 1) % list.length];
372
+ else if (e.key === "ArrowUp") next = list[(at - 1 + list.length) % list.length];
373
+ else if (e.key === "Home") next = list[0];
374
+ else if (e.key === "End") next = list[list.length - 1];
375
+ else if (e.key === "Escape") {
376
+ e.preventDefault();
377
+ close(true);
378
+ return;
379
+ } else if (e.key === " " && e.target.tagName === "A") {
380
+ e.preventDefault();
381
+ e.target.click();
382
+ return;
383
+ } else return;
384
+ e.preventDefault();
385
+ next?.focus();
386
+ };
387
+ const onMenuClick = (e) => {
388
+ const t = e.target;
389
+ const row = t.closest(".ow-waymark__row");
390
+ if (row === null) return;
391
+ if (row === lensToggle) {
392
+ const show = lensList.hidden;
393
+ lensList.hidden = !show;
394
+ lensToggle.setAttribute("aria-expanded", String(show));
395
+ } else if (row.dataset.lens !== void 0) {
396
+ chosenLens = chosenLens === row.dataset.lens ? null : row.dataset.lens;
397
+ for (const b of Array.from(lensList.children)) b.setAttribute("aria-checked", String(b.dataset.lens === chosenLens));
398
+ lensValue.textContent = throughLenses.find((l) => l.id === chosenLens)?.name ?? "";
399
+ } else if (row === copy) {
400
+ const text = linkFor(chosenLens);
401
+ const clipboard = timers.navigator?.clipboard;
402
+ if (!clipboard) notCopied(text);
403
+ else {
404
+ clipboard.writeText(text).then(
405
+ () => {
406
+ if (disposed) return;
407
+ close(true);
408
+ copied();
409
+ },
410
+ () => {
411
+ if (!disposed && isOpen()) notCopied(text);
412
+ }
413
+ );
414
+ }
415
+ } else {
416
+ close(false);
417
+ }
418
+ };
419
+ let settleTimer = null;
420
+ const inside = (n2) => n2 !== null && (pop.contains(n2) || toast.contains(n2));
421
+ const onFocusOut = (e) => {
422
+ const to = e.relatedTarget;
423
+ if (to !== null) {
424
+ if (!inside(to)) close(false);
425
+ return;
426
+ }
427
+ if (settleTimer !== null) timers.clearTimeout(settleTimer);
428
+ settleTimer = timers.setTimeout(() => {
429
+ settleTimer = null;
430
+ const pressed = pressedInside;
431
+ pressedInside = false;
432
+ if (!isOpen() || pressed || !doc.hasFocus()) return;
433
+ if (!inside(doc.activeElement)) close(false);
434
+ }, 0);
435
+ };
436
+ for (const b of openers) {
437
+ on(listeners, b, "pointerdown", onOpenerPress);
438
+ on(listeners, b, "click", onOpenerClick);
439
+ on(listeners, b, "keydown", onOpenerKey);
440
+ }
441
+ on(listeners, pop, "keydown", onMenuKey);
442
+ on(listeners, toast, "keydown", ((e) => {
443
+ if (e.key === "Escape") {
444
+ e.preventDefault();
445
+ close(true);
446
+ }
447
+ }));
448
+ on(listeners, menu, "click", onMenuClick);
449
+ on(listeners, scrim, "click", (() => close(true)));
450
+ on(listeners, root, "focusout", onFocusOut);
451
+ target.appendChild(root);
452
+ const dispose = () => {
453
+ if (disposed) return;
454
+ disposed = true;
455
+ offAll(openListeners);
456
+ offAll(listeners);
457
+ if (toastTimer !== null) timers.clearTimeout(toastTimer);
458
+ toastTimer = null;
459
+ if (settleTimer !== null) timers.clearTimeout(settleTimer);
460
+ settleTimer = null;
461
+ root.remove();
462
+ menuEntry?.remove();
463
+ };
464
+ return Object.defineProperty(dispose, "entry", { value: menuEntry, enumerable: true });
465
+ }
466
+ export {
467
+ mountWaymark
468
+ };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@onlyworlds/sdk",
3
- "version": "4.112.0",
3
+ "version": "4.113.0",
4
4
  "description": "TypeScript SDK for the OnlyWorlds API - build world-building applications with type safety",
5
5
  "type": "module",
6
6
  "exports": {
@@ -8,10 +8,17 @@
8
8
  "types": "./dist/index.d.ts",
9
9
  "import": "./dist/index.js"
10
10
  },
11
+ "./waymark": {
12
+ "types": "./dist/waymark.d.ts",
13
+ "import": "./dist/waymark.js"
14
+ },
15
+ "./waymark.css": "./dist/waymark.css",
11
16
  "./package.json": "./package.json"
12
17
  },
13
18
  "types": "dist/index.d.ts",
14
- "sideEffects": false,
19
+ "sideEffects": [
20
+ "*.css"
21
+ ],
15
22
  "files": [
16
23
  "dist",
17
24
  "README.md",
@@ -20,8 +27,8 @@
20
27
  "SCHEMA.md"
21
28
  ],
22
29
  "scripts": {
23
- "build": "tsup src/index.ts --format esm --dts --clean",
24
- "dev": "tsup src/index.ts --format esm --dts --watch",
30
+ "build": "tsup --entry.index src/index.ts --entry.waymark src/waymark/index.ts --format esm --clean && tsup --entry.index src/index.ts --format esm --dts-only && tsup --entry.waymark src/waymark/index.ts --format esm --dts-only && node -e \"require('fs').copyFileSync('src/waymark/waymark.css', 'dist/waymark.css')\"",
31
+ "dev": "tsup --entry.index src/index.ts --entry.waymark src/waymark/index.ts --format esm --dts --watch",
25
32
  "pretest": "npm run build",
26
33
  "test": "node --test",
27
34
  "codegen": "python codegen/generate_types.py && node codegen/tools.mjs",
@@ -29,7 +36,8 @@
29
36
  "schema:verify": "python codegen/verify_dist.py",
30
37
  "schema:check": "npm run schema:verify && npm run codegen:check",
31
38
  "prepublishOnly": "npm run build",
32
- "release:verify": "node codegen/verify_release.mjs"
39
+ "release:verify": "node codegen/verify_release.mjs",
40
+ "demo": "npm run build && node scripts/serve-demo.mjs"
33
41
  },
34
42
  "keywords": [
35
43
  "onlyworlds",
@@ -52,6 +60,7 @@
52
60
  "url": "https://github.com/OnlyWorlds/sdk/issues"
53
61
  },
54
62
  "devDependencies": {
63
+ "happy-dom": "^20.14.6",
55
64
  "tsup": "^8.0.1",
56
65
  "typescript": "^5.3.3"
57
66
  },