@neta-art/cohub-cli 10.20.0 → 10.21.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.
@@ -5912,6 +5912,7 @@ const itemEnvelope$1 = {
5912
5912
  visible: boolean().optional().describe("false hides the item and its children; key it on a timeline to show the item only for a span."),
5913
5913
  style: BoardStyleSchema$1.default({}),
5914
5914
  locked: boolean().optional(),
5915
+ autoplay: boolean().optional().describe("true shows live content as the Board opens: an app runs, a video loops muted, a 3D model renders. Ignored for other items and for a video whose props.time follows a timeline."),
5915
5916
  metadata: record(string(), unknown()).optional()
5916
5917
  };
5917
5918
  const boxed$1 = (size) => ({
@@ -7127,6 +7128,7 @@ const NOT_ANIMATABLE = /* @__PURE__ */ new Set([
7127
7128
  "parent",
7128
7129
  "z",
7129
7130
  "locked",
7131
+ "autoplay",
7130
7132
  "metadata",
7131
7133
  "script"
7132
7134
  ]);
@@ -7965,6 +7967,159 @@ function isBoardRootScript(document, id) {
7965
7967
  return Boolean(document.board?.scripts && Object.hasOwn(document.board.scripts, id));
7966
7968
  }
7967
7969
  //#endregion
7970
+ //#region ../sdk/src/board/model/json.ts
7971
+ function sameJson(a, b) {
7972
+ if (a === b) return true;
7973
+ if (!a || !b || typeof a !== "object" || typeof b !== "object") return false;
7974
+ if (Array.isArray(a) || Array.isArray(b)) {
7975
+ if (!Array.isArray(a) || !Array.isArray(b) || a.length !== b.length) return false;
7976
+ for (let index = 0; index < a.length; index += 1) if (!sameJson(a[index], b[index])) return false;
7977
+ return true;
7978
+ }
7979
+ const left = a;
7980
+ const right = b;
7981
+ let members = 0;
7982
+ for (const key of Object.keys(left)) {
7983
+ if (left[key] === void 0) continue;
7984
+ members += 1;
7985
+ if (!sameJson(left[key], right[key])) return false;
7986
+ }
7987
+ for (const key of Object.keys(right)) if (right[key] !== void 0) members -= 1;
7988
+ return members === 0;
7989
+ }
7990
+ //#endregion
7991
+ //#region ../sdk/src/board/model/script-scope.ts
7992
+ const childrenByItems = /* @__PURE__ */ new WeakMap();
7993
+ const everyItem = /* @__PURE__ */ new WeakMap();
7994
+ function childIndex(items) {
7995
+ let index = childrenByItems.get(items);
7996
+ if (!index) {
7997
+ index = /* @__PURE__ */ new Map();
7998
+ for (const [id, item] of Object.entries(items)) {
7999
+ if (!item.parent) continue;
8000
+ const siblings = index.get(item.parent);
8001
+ if (siblings) siblings.push(id);
8002
+ else index.set(item.parent, [id]);
8003
+ }
8004
+ childrenByItems.set(items, index);
8005
+ }
8006
+ return index;
8007
+ }
8008
+ function boardScriptOf(document, id) {
8009
+ return isBoardRootScript(document, id) ? document.board?.scripts?.[id] : document.items[id]?.script;
8010
+ }
8011
+ function boardScriptScope(document, id) {
8012
+ if (isBoardRootScript(document, id)) {
8013
+ let all = everyItem.get(document.items);
8014
+ if (!all) {
8015
+ all = new Set(Object.keys(document.items));
8016
+ everyItem.set(document.items, all);
8017
+ }
8018
+ return all;
8019
+ }
8020
+ const item = document.items[id];
8021
+ const scope = /* @__PURE__ */ new Set([id]);
8022
+ for (const target of Object.values(item?.script?.targets ?? {})) if (document.items[target]) scope.add(target);
8023
+ if (item?.type !== "frame") return scope;
8024
+ const children = childIndex(document.items);
8025
+ const visited = /* @__PURE__ */ new Set([id]);
8026
+ const queue = [id];
8027
+ for (let depth = 0; queue.length && depth < 64; depth++) for (const parent of queue.splice(0)) for (const child of children.get(parent) ?? []) {
8028
+ if (visited.has(child)) continue;
8029
+ visited.add(child);
8030
+ scope.add(child);
8031
+ queue.push(child);
8032
+ }
8033
+ return scope;
8034
+ }
8035
+ function diffBoardScriptItems(copy, document, scope, note) {
8036
+ const changes = {};
8037
+ let changed = false;
8038
+ for (const id of scope) {
8039
+ const item = document.items[id];
8040
+ const previous = copy.get(id);
8041
+ if (!item || previous === item) continue;
8042
+ copy.set(id, item);
8043
+ if (previous && sameJson(previous, item)) continue;
8044
+ changes[id] = item;
8045
+ changed = true;
8046
+ note?.(id, previous ? "changed" : "added");
8047
+ }
8048
+ if (copy.size > scope.size) for (const id of copy.keys()) {
8049
+ if (scope.has(id)) continue;
8050
+ copy.delete(id);
8051
+ changes[id] = null;
8052
+ changed = true;
8053
+ note?.(id, "removed");
8054
+ }
8055
+ return changed ? changes : null;
8056
+ }
8057
+ function supersedes(pending, event) {
8058
+ if (pending.type !== event.type) return false;
8059
+ if (event.type === "viewchange" || event.type === "selectionchange") return true;
8060
+ if (event.type === "pointermove") return pending.pointerId === event.pointerId;
8061
+ if (event.type !== "gesture") return false;
8062
+ const a = pending.data;
8063
+ const b = event.data;
8064
+ return a.id === b.id && a.phase === "update" && b.phase === "update";
8065
+ }
8066
+ function boardScriptListens(output, event) {
8067
+ return !output || event.type === "viewchange" || output.listens.includes(event.type);
8068
+ }
8069
+ function queueBoardScriptEvent(queue, event) {
8070
+ let queued = queue.length - 1;
8071
+ while (queued >= 0 && !supersedes(queue[queued], event)) queued--;
8072
+ if (queued >= 0 && (event.type !== "pointermove" || queued === queue.length - 1)) queue.splice(queued, 1);
8073
+ if (queue.length >= 128) return false;
8074
+ queue.push(event);
8075
+ return true;
8076
+ }
8077
+ function boardScriptEmit(document, sender, input) {
8078
+ const message = input;
8079
+ if (!message || typeof message.target !== "string" || typeof message.type !== "string" || !message.type) throw new Error("emit() takes a target id and an event type.");
8080
+ const { target, type } = message;
8081
+ if (!isBoardRootScript(document, target) && !boardScriptScope(document, sender).has(target)) throw new Error(`emit() from ${sender} cannot reach ${target}: it is neither in scope nor a Board script.`);
8082
+ const depth = typeof message.depth === "number" && Number.isSafeInteger(message.depth) && message.depth > 0 ? message.depth : 1;
8083
+ if (depth > 16) throw new Error(`emit(${target}, "${type}") from ${sender} is ${depth} handlers deep, past the limit of 16: handlers keep answering each other. Emit from onFrame() to send it on the next step.`);
8084
+ return {
8085
+ target,
8086
+ event: {
8087
+ type,
8088
+ data: message.data,
8089
+ depth
8090
+ }
8091
+ };
8092
+ }
8093
+ function createBoardScriptOutbox(order) {
8094
+ let queued = [];
8095
+ let seq = 0;
8096
+ const waiting = /* @__PURE__ */ new Map();
8097
+ return {
8098
+ get size() {
8099
+ return queued.length;
8100
+ },
8101
+ push(sender, target, event) {
8102
+ const count = waiting.get(target) ?? 0;
8103
+ if (count >= 128) throw new Error(`emit(${target}, "${event.type}") from ${sender}: ${target} already has 128 events waiting.`);
8104
+ waiting.set(target, count + 1);
8105
+ queued.push({
8106
+ rank: order().get(sender) ?? Number.MAX_SAFE_INTEGER,
8107
+ seq: seq++,
8108
+ target,
8109
+ event
8110
+ });
8111
+ },
8112
+ take() {
8113
+ const batch = queued.sort((a, b) => a.rank - b.rank || a.seq - b.seq);
8114
+ queued = [];
8115
+ waiting.clear();
8116
+ const byTarget = /* @__PURE__ */ new Map();
8117
+ for (const { target, event } of batch) byTarget.set(target, [...byTarget.get(target) ?? [], event]);
8118
+ return byTarget;
8119
+ }
8120
+ };
8121
+ }
8122
+ //#endregion
7968
8123
  //#region ../sdk/src/board/model/geometry.ts
7969
8124
  function screenPoint(x, y) {
7970
8125
  return {
@@ -8407,100 +8562,13 @@ function visibleWorldRect(viewport, surfaceWidth, surfaceHeight) {
8407
8562
  };
8408
8563
  }
8409
8564
  //#endregion
8410
- //#region ../sdk/src/board/model/json.ts
8411
- function sameJson(a, b) {
8412
- if (a === b) return true;
8413
- if (!a || !b || typeof a !== "object" || typeof b !== "object") return false;
8414
- if (Array.isArray(a) || Array.isArray(b)) {
8415
- if (!Array.isArray(a) || !Array.isArray(b) || a.length !== b.length) return false;
8416
- for (let index = 0; index < a.length; index += 1) if (!sameJson(a[index], b[index])) return false;
8417
- return true;
8418
- }
8419
- const left = a;
8420
- const right = b;
8421
- let members = 0;
8422
- for (const key of Object.keys(left)) {
8423
- if (left[key] === void 0) continue;
8424
- members += 1;
8425
- if (!sameJson(left[key], right[key])) return false;
8426
- }
8427
- for (const key of Object.keys(right)) if (right[key] !== void 0) members -= 1;
8428
- return members === 0;
8429
- }
8430
- //#endregion
8431
- //#region ../sdk/src/board/model/script-scope.ts
8432
- const childrenByItems = /* @__PURE__ */ new WeakMap();
8433
- const everyItem = /* @__PURE__ */ new WeakMap();
8434
- function childIndex(items) {
8435
- let index = childrenByItems.get(items);
8436
- if (!index) {
8437
- index = /* @__PURE__ */ new Map();
8438
- for (const [id, item] of Object.entries(items)) {
8439
- if (!item.parent) continue;
8440
- const siblings = index.get(item.parent);
8441
- if (siblings) siblings.push(id);
8442
- else index.set(item.parent, [id]);
8443
- }
8444
- childrenByItems.set(items, index);
8445
- }
8446
- return index;
8447
- }
8448
- function boardScriptOf(document, id) {
8449
- return isBoardRootScript(document, id) ? document.board?.scripts?.[id] : document.items[id]?.script;
8450
- }
8451
- function boardScriptScope(document, id) {
8452
- if (isBoardRootScript(document, id)) {
8453
- let all = everyItem.get(document.items);
8454
- if (!all) {
8455
- all = new Set(Object.keys(document.items));
8456
- everyItem.set(document.items, all);
8457
- }
8458
- return all;
8459
- }
8460
- const item = document.items[id];
8461
- const scope = /* @__PURE__ */ new Set([id]);
8462
- for (const target of Object.values(item?.script?.targets ?? {})) if (document.items[target]) scope.add(target);
8463
- if (item?.type !== "frame") return scope;
8464
- const children = childIndex(document.items);
8465
- const visited = /* @__PURE__ */ new Set([id]);
8466
- const queue = [id];
8467
- for (let depth = 0; queue.length && depth < 64; depth++) for (const parent of queue.splice(0)) for (const child of children.get(parent) ?? []) {
8468
- if (visited.has(child)) continue;
8469
- visited.add(child);
8470
- scope.add(child);
8471
- queue.push(child);
8472
- }
8473
- return scope;
8474
- }
8475
- function diffBoardScriptItems(copy, document, scope, note) {
8476
- const changes = {};
8477
- let changed = false;
8478
- for (const id of scope) {
8479
- const item = document.items[id];
8480
- const previous = copy.get(id);
8481
- if (!item || previous === item) continue;
8482
- copy.set(id, item);
8483
- if (previous && sameJson(previous, item)) continue;
8484
- changes[id] = item;
8485
- changed = true;
8486
- note?.(id, previous ? "changed" : "added");
8487
- }
8488
- if (copy.size > scope.size) for (const id of copy.keys()) {
8489
- if (scope.has(id)) continue;
8490
- copy.delete(id);
8491
- changes[id] = null;
8492
- changed = true;
8493
- note?.(id, "removed");
8494
- }
8495
- return changed ? changes : null;
8496
- }
8497
- //#endregion
8498
8565
  //#region ../sdk/src/board/model/shader.ts
8499
8566
  const BOARD_SHADER_LIMITS = {
8500
- passes: 8,
8567
+ passes: 16,
8501
8568
  source: 65536,
8502
8569
  sprites: 65536,
8503
8570
  stateEdge: 1024,
8571
+ texel: 1024,
8504
8572
  uniformSlots: 128
8505
8573
  };
8506
8574
  const COMPONENTS = {
@@ -8575,6 +8643,10 @@ function validateBoardShader(shader) {
8575
8643
  if (!Number.isSafeInteger(pass.sprites) || pass.sprites < 1 || pass.sprites > BOARD_SHADER_LIMITS.sprites) throw new Error(`sprites must be an integer from 1 to ${BOARD_SHADER_LIMITS.sprites}.`);
8576
8644
  if (boardShaderPassLayer(value, pass) === "filter") throw new Error("Filter passes draw over the owner's box; they cannot draw sprites.");
8577
8645
  }
8646
+ if (pass.texel !== void 0) {
8647
+ if (typeof pass.texel !== "number" || !(pass.texel > 0 && pass.texel <= BOARD_SHADER_LIMITS.texel)) throw new Error(`texel must be a number above 0 and up to ${BOARD_SHADER_LIMITS.texel}.`);
8648
+ if (pass.sprites !== void 0 || boardShaderPassLayer(value, pass) === "filter") throw new Error("texel shades a pass over its box; sprite and filter passes cannot take it.");
8649
+ }
8578
8650
  if (pass.name !== void 0) {
8579
8651
  if (typeof pass.name !== "string" || !IDENTIFIER.test(pass.name)) throw new Error(`Invalid pass name: ${String(pass.name)}`);
8580
8652
  if (names.has(pass.name)) throw new Error(`Pass names must be unique: ${pass.name}`);
@@ -8619,6 +8691,33 @@ function parseBoardItem(value) {
8619
8691
  if (!parsed.ok) throw new Error(parsed.diagnostics[0]?.message ?? "Invalid script item.");
8620
8692
  return parsed.item;
8621
8693
  }
8694
+ function presentItem(base, patch) {
8695
+ return presentTransform(base, patch) ?? parseBoardItem(mergePatch(base, patch));
8696
+ }
8697
+ function presentTransform(base, patch) {
8698
+ const next = { ...base };
8699
+ for (const key in patch) {
8700
+ const value = patch[key];
8701
+ if (key === "position") {
8702
+ if (!value || typeof value !== "object") return null;
8703
+ const { x = base.position.x, y = base.position.y, ...rest } = value;
8704
+ if (!Number.isFinite(x) || !Number.isFinite(y)) return null;
8705
+ for (const _ in rest) return null;
8706
+ next.position = {
8707
+ x,
8708
+ y
8709
+ };
8710
+ continue;
8711
+ }
8712
+ if (key === "rotation" || key === "z") {
8713
+ if (!Number.isFinite(value)) return null;
8714
+ } else if (key === "opacity") {
8715
+ if (typeof value !== "number" || !(value >= 0 && value <= 1)) return null;
8716
+ } else if (key !== "visible" || typeof value !== "boolean") return null;
8717
+ next[key] = value;
8718
+ }
8719
+ return next;
8720
+ }
8622
8721
  const DISPLAY_FIELDS = /* @__PURE__ */ new Set([
8623
8722
  "position",
8624
8723
  "size",
@@ -8816,7 +8915,7 @@ function prepareBoardScriptOutput(document, owner, output) {
8816
8915
  const base = document.items[id];
8817
8916
  if (base && scope.has(id)) presented.set(id, {
8818
8917
  base,
8819
- item: parseBoardItem(mergePatch(base, patch))
8918
+ item: presentItem(base, patch)
8820
8919
  });
8821
8920
  }
8822
8921
  const prefix = scriptTemporaryPrefix(owner);
@@ -8848,7 +8947,7 @@ function composeBoardScriptItems(document, scene, outputs, incoming = /* @__PURE
8848
8947
  if (current.base !== base) {
8849
8948
  current = {
8850
8949
  base,
8851
- item: parseBoardItem(mergePatch(base, output.patches[id]))
8950
+ item: presentItem(base, output.patches[id] ?? {})
8852
8951
  };
8853
8952
  prepared.presented.set(id, current);
8854
8953
  }
@@ -11649,9 +11748,10 @@ function resolveRegion(scene, region) {
11649
11748
  };
11650
11749
  const rect = itemBounds(frame.frame);
11651
11750
  return {
11652
- items: scene.items.filter((item) => item.id !== region.id && visible(item, rect)),
11751
+ items: scene.items.filter((item) => item.id === region.id || visible(item, rect)),
11653
11752
  rect,
11654
- padding: 0
11753
+ padding: 0,
11754
+ page: region.id
11655
11755
  };
11656
11756
  }
11657
11757
  case "rect": {
@@ -11689,7 +11789,8 @@ function planBoardExport(input) {
11689
11789
  width: Math.max(1, Math.floor(world.width * scale)),
11690
11790
  height: Math.max(1, Math.floor(world.height * scale)),
11691
11791
  items: resolved.items,
11692
- clamped: scale < safeRequest - 1e-6
11792
+ clamped: scale < safeRequest - 1e-6,
11793
+ ...resolved.page ? { page: resolved.page } : {}
11693
11794
  };
11694
11795
  }
11695
11796
  //#endregion
@@ -13153,6 +13254,61 @@ function createBoardRegistry(definitions = []) {
13153
13254
  }
13154
13255
  const defaultBoardRegistry = createBoardRegistry();
13155
13256
  //#endregion
13257
+ //#region ../sdk/src/board/model/autoplay.ts
13258
+ const text = (value) => typeof value === "string" && value.length > 0 ? value : void 0;
13259
+ function boardAppMetadata(item) {
13260
+ if (item?.type !== "frame" || !item.metadata) return null;
13261
+ const value = item.metadata.cohubApp;
13262
+ if (!value || typeof value !== "object") return null;
13263
+ const app = value;
13264
+ const appId = text(app.appId);
13265
+ const ref = text(app.ref);
13266
+ const url = text(app.url);
13267
+ const name = text(app.name);
13268
+ if (!appId || !ref || !url || !name) return null;
13269
+ const icon = text(app.icon);
13270
+ const cover = text(app.cover);
13271
+ const themeColor = text(app.themeColor);
13272
+ return {
13273
+ appId,
13274
+ ref,
13275
+ url,
13276
+ name,
13277
+ ...icon ? { icon } : {},
13278
+ ...cover ? { cover } : {},
13279
+ ...themeColor ? { themeColor } : {}
13280
+ };
13281
+ }
13282
+ function boardAutoplayKind(item) {
13283
+ if (!item) return null;
13284
+ if (item.type === "video") return item.props.time === void 0 ? "video" : null;
13285
+ if (item.type === "task") return boardAutoplayVideo(item) ? "video" : null;
13286
+ if (isBoardModelItem(item)) return "model";
13287
+ return boardAppMetadata(item) ? "app" : null;
13288
+ }
13289
+ function boardAutoplayVideo(item) {
13290
+ if (item.type === "video") return item.props.time === void 0 ? item.props.src : null;
13291
+ if (item.type !== "task" || item.props.snapshot.status !== "completed") return null;
13292
+ const artifact = featuredTaskArtifact(item.props.snapshot.artifacts);
13293
+ return artifact?.type === "video" ? artifact.url : null;
13294
+ }
13295
+ function boardAutoplayLoops(scene, at) {
13296
+ const loops = [];
13297
+ for (const item of scene.items) {
13298
+ const src = item.autoplay ? boardAutoplayVideo(item) : null;
13299
+ if (src) loops.push({
13300
+ id: item.id,
13301
+ kind: "video",
13302
+ src,
13303
+ time: at,
13304
+ volume: 0,
13305
+ shown: scene.shown(item.id),
13306
+ loop: true
13307
+ });
13308
+ }
13309
+ return loops;
13310
+ }
13311
+ //#endregion
13156
13312
  //#region ../../node_modules/.pnpm/pixi.js@8.20.1/node_modules/pixi.js/lib/environment-browser/browserExt.mjs
13157
13313
  const browserExt = {
13158
13314
  extension: {
@@ -38312,6 +38468,11 @@ function inspectBoardScene(scene, limit = 100, ids) {
38312
38468
  code: "effect-follow-unused",
38313
38469
  item: item.id
38314
38470
  });
38471
+ const unfinished = item.type === "task" && (item.props.snapshot.status === "pending" || item.props.snapshot.status === "running");
38472
+ if (item.autoplay && !unfinished && !boardAutoplayKind(item)) push({
38473
+ code: "autoplay-unused",
38474
+ item: item.id
38475
+ });
38315
38476
  }
38316
38477
  let glyphBudget = 256;
38317
38478
  for (const item of texts) {
@@ -39311,6 +39472,7 @@ function shaderPasses() {
39311
39472
  return passes;
39312
39473
  }
39313
39474
  const TEXELS_PER_DEVIATION = 4;
39475
+ const SAMPLED_TEXELS_PER_DEVIATION = 8;
39314
39476
  const MAX_HALVINGS = 5;
39315
39477
  function gaussian(filters, input, output, deviation, clear, first) {
39316
39478
  const { horizontal, vertical, copy } = shaderPasses();
@@ -39356,6 +39518,7 @@ var BoardBlurFilter = class extends Filter {
39356
39518
  this.radius = radius;
39357
39519
  this.deviation = radius * zoom;
39358
39520
  this.padding = Math.ceil(radius * 3 * zoom);
39521
+ this.resolution = this.deviation > SAMPLED_TEXELS_PER_DEVIATION ? SAMPLED_TEXELS_PER_DEVIATION / this.deviation : "inherit";
39359
39522
  this.css = `blur(${radius * zoom}px)`;
39360
39523
  }
39361
39524
  apply(filters, input, output, clearMode) {
@@ -39644,6 +39807,27 @@ function syncFrameGroup(entry, item, context) {
39644
39807
  function syncBoardItemEffects(container, item, context) {
39645
39808
  syncBoardEffects(container, item.type === "frame" ? void 0 : item.style, context);
39646
39809
  }
39810
+ const shaderClips = /* @__PURE__ */ new WeakMap();
39811
+ function clipFrameShaderLayer(layer, item) {
39812
+ const entry = shaderClips.get(layer);
39813
+ if (!isClippingFrame(item)) {
39814
+ if (!entry) return;
39815
+ layer.mask = null;
39816
+ entry.mask.destroy();
39817
+ shaderClips.delete(layer);
39818
+ return;
39819
+ }
39820
+ const { width, height } = item.frame;
39821
+ const sig = `${width},${height}`;
39822
+ if (entry?.sig === sig) return;
39823
+ const mask = entry?.mask ?? layer.addChild(new Graphics());
39824
+ mask.clear().rect(0, 0, width, height).fill(16777215);
39825
+ layer.mask = mask;
39826
+ shaderClips.set(layer, {
39827
+ mask,
39828
+ sig
39829
+ });
39830
+ }
39647
39831
  //#endregion
39648
39832
  //#region ../sdk/src/board/render/audio-waveform.ts
39649
39833
  const DEFAULT_BARS = 44;
@@ -40376,10 +40560,12 @@ function sync$13(container, item, context) {
40376
40560
  const failed = Boolean(key && !texture && context.hasError(key));
40377
40561
  const detailed = boardCardDetailed(context.zoom);
40378
40562
  const elevation = cardElevation(context, item.id);
40563
+ const covered = context.covered?.(item.id) ?? false;
40379
40564
  const sig = [
40380
40565
  key ?? "",
40381
40566
  texture?.uid ?? "none",
40382
40567
  failed,
40568
+ covered,
40383
40569
  width,
40384
40570
  height,
40385
40571
  elevation,
@@ -40400,7 +40586,11 @@ function sync$13(container, item, context) {
40400
40586
  elevation
40401
40587
  });
40402
40588
  if (texture && parts.sprite.texture !== texture) parts.sprite.texture = texture;
40403
- parts.sprite.visible = Boolean(texture);
40589
+ parts.sprite.visible = Boolean(texture) && !covered;
40590
+ if (covered) {
40591
+ parts.chrome.clear();
40592
+ return;
40593
+ }
40404
40594
  if (texture) {
40405
40595
  const inset = Math.min(width, height) * INSET_RATIO;
40406
40596
  const fitted = containRect(width - inset * 2, height - inset * 2, texture.width, texture.height);
@@ -40509,6 +40699,7 @@ const PLAY_HIT = {
40509
40699
  cursor: "pointer"
40510
40700
  };
40511
40701
  function mediaPlayHit(item, point, context) {
40702
+ if (context.covered?.(item.id) || context.mediaTexture?.(item.id)) return null;
40512
40703
  const key = context.assetKey(item);
40513
40704
  return boardMediaActionAt(item, point, context.zoom, {
40514
40705
  materialized: true,
@@ -41403,9 +41594,12 @@ function sync$8(container, item, context) {
41403
41594
  const alpha = (style.stroke ? 1 : .55) * itemAlpha(context, style.stroke);
41404
41595
  const radius = style.radius ?? 4;
41405
41596
  const strokeWidth = style.strokeWidth ?? 1.5;
41406
- const decorated = props.decoration !== "none";
41597
+ const page = context.page === item.id;
41598
+ const decorated = props.decoration !== "none" && (!page || style.fill !== void 0);
41599
+ const outlined = decorated && !page;
41407
41600
  const visualSig = [
41408
41601
  props.decoration,
41602
+ page,
41409
41603
  frame.width,
41410
41604
  frame.height,
41411
41605
  fill,
@@ -41426,7 +41620,7 @@ function sync$8(container, item, context) {
41426
41620
  });
41427
41621
  const pattern = dashPattern(style.dash, strokeWidth);
41428
41622
  const trim = style.trim ?? 1;
41429
- if (decorated && strokeWidth > 0 && trim > 0) {
41623
+ if (outlined && strokeWidth > 0 && trim > 0) {
41430
41624
  if (pattern || trim < 1) tracePolyline(parts.box, trimPolyline(roundRectPoints(frame.width, frame.height, radius), trim), pattern);
41431
41625
  else parts.box.roundRect(0, 0, frame.width, frame.height, radius);
41432
41626
  parts.box.stroke({
@@ -41438,7 +41632,7 @@ function sync$8(container, item, context) {
41438
41632
  });
41439
41633
  }
41440
41634
  }
41441
- parts.label.visible = decorated;
41635
+ parts.label.visible = outlined;
41442
41636
  const title = locked ? `🔒 ${props.label}`.trim() : props.label;
41443
41637
  const labelColor = style.stroke ? baseStroke : context.palette.muted;
41444
41638
  const size = context.style.frameLabelSize;
@@ -42541,7 +42735,8 @@ function sync$3(container, item, context) {
42541
42735
  parts.assetKey = key;
42542
42736
  if (key) context.acquireTexture(key, item);
42543
42737
  }
42544
- const texture = key ? context.getTexture(key) : null;
42738
+ const live = context.mediaTexture?.(item.id) ?? null;
42739
+ const texture = live ?? (key ? context.getTexture(key) : null);
42545
42740
  const previewFailed = Boolean(key && !texture && context.hasError(key));
42546
42741
  const artifact = featuredTaskArtifact(snapshot.artifacts);
42547
42742
  const kind = previewKindFor(artifact);
@@ -42649,7 +42844,7 @@ function sync$3(container, item, context) {
42649
42844
  height: Math.max(1, frame.height - 24 - bottomInset)
42650
42845
  }, context.colors.brand.stroke);
42651
42846
  }
42652
- if (full && (artifact?.type === "audio" || artifact?.type === "video" && texture)) drawPlayBadge(parts.previewArt, frame, context);
42847
+ if (full && (artifact?.type === "audio" || artifact?.type === "video" && texture && !live)) drawPlayBadge(parts.previewArt, frame, context);
42653
42848
  if (surface) {
42654
42849
  const markY = frame.y + frame.height / 2 - (full && label ? 18 : 0);
42655
42850
  drawStateMark(parts.previewArt, surface, frame.x + frame.width / 2, markY, surface === "failed" ? color : context.colors.neutral.stroke);
@@ -43213,7 +43408,7 @@ function sync(container, item, context) {
43213
43408
  } : context.style);
43214
43409
  }
43215
43410
  parts.chrome.clear();
43216
- if (boardCardDetailed(context.zoom) && item.props.time === void 0) drawMediaPlayKey(parts.chrome, screen.x + screen.width / 2, screen.y + screen.height / 2, Math.min(18, Math.min(screen.width, screen.height) * .16), context);
43411
+ if (boardCardDetailed(context.zoom) && !live && item.props.time === void 0) drawMediaPlayKey(parts.chrome, screen.x + screen.width / 2, screen.y + screen.height / 2, Math.min(18, Math.min(screen.width, screen.height) * .16), context);
43217
43412
  }
43218
43413
  function drawFilmRails(graphics, width, height, rail, hole) {
43219
43414
  const size = Math.min(FILM_HOLE, rail * .45);
@@ -43566,6 +43761,7 @@ const itemEnvelope = {
43566
43761
  visible: boolean().optional().describe("false hides the item and its children; key it on a timeline to show the item only for a span."),
43567
43762
  style: BoardStyleSchema.default({}),
43568
43763
  locked: boolean().optional(),
43764
+ autoplay: boolean().optional().describe("true shows live content as the Board opens: an app runs, a video loops muted, a 3D model renders. Ignored for other items and for a video whose props.time follows a timeline."),
43569
43765
  metadata: record(string(), unknown()).optional()
43570
43766
  };
43571
43767
  const boxed = (size) => ({
@@ -44046,9 +44242,12 @@ function resolveScriptImport(from, specifier) {
44046
44242
  } else parts.push(part);
44047
44243
  }
44048
44244
  const path = parts.join("/");
44049
- if (!isSafeBoardSourcePath(path) || !/\.m?js$/.test(path)) throw new Error(`Invalid module path: ${path}`);
44245
+ if (!isSafeBoardSourcePath(path) || !/\.(m?js|json)$/.test(path)) throw new Error(`Invalid module path: ${path}`);
44050
44246
  return path;
44051
44247
  }
44248
+ function isBoardScriptJson(path) {
44249
+ return path.endsWith(".json");
44250
+ }
44052
44251
  async function loadBoardScriptSources(src, read, timeoutMs = 15e3) {
44053
44252
  if (!isSafeBoardSourcePath(src) || !/\.m?js$/.test(src)) throw new Error("Invalid script entry path.");
44054
44253
  const { init, parse } = await import("./board-kernel/lexer.js");
@@ -44068,11 +44267,25 @@ async function loadBoardScriptSources(src, read, timeoutMs = 15e3) {
44068
44267
  })]).finally(() => clearTimeout(timer));
44069
44268
  bytes += new TextEncoder().encode(code).byteLength;
44070
44269
  if (bytes > 2e6) throw new Error("Script modules exceed the 2 MB limit.");
44270
+ if (isBoardScriptJson(path)) {
44271
+ try {
44272
+ JSON.parse(code);
44273
+ } catch {
44274
+ throw new Error(`${path} is not valid JSON.`);
44275
+ }
44276
+ sources[path] = {
44277
+ code,
44278
+ imports: []
44279
+ };
44280
+ return;
44281
+ }
44071
44282
  const [imports] = parse(code, path);
44072
44283
  const resolved = [];
44073
44284
  for (const entry of imports) {
44074
44285
  if (entry.d === -2) throw new Error("import.meta is not available in Board scripts.");
44075
44286
  if (entry.n === void 0) throw new Error("Dynamic imports must use a literal relative path.");
44287
+ const typed = entry.d >= 0 ? entry.a >= 0 && /\btype\s*:\s*["']json["']/.test(code.slice(entry.a, entry.se)) : Boolean(entry.at?.some(([key, value]) => key === "type" && value === "json"));
44288
+ if (typed !== isBoardScriptJson(entry.n)) throw new Error(typed ? `Only .json files import with type "json": ${entry.n}` : `Import ${entry.n} with { type: "json" }.`);
44076
44289
  resolved.push({
44077
44290
  start: entry.s,
44078
44291
  end: entry.e,
@@ -44122,6 +44335,7 @@ function createScriptRuntime(module, initial, host) {
44122
44335
  let input = initial;
44123
44336
  let disposed = false;
44124
44337
  let stepping = false;
44338
+ let depth = 0;
44125
44339
  let revision = 0;
44126
44340
  let sceneRevision = 0;
44127
44341
  let randomState = 2166136261;
@@ -44197,7 +44411,8 @@ function createScriptRuntime(module, initial, host) {
44197
44411
  await host.call("board.emit", {
44198
44412
  target,
44199
44413
  type,
44200
- data
44414
+ data,
44415
+ depth: depth + 1
44201
44416
  });
44202
44417
  },
44203
44418
  get items() {
@@ -44367,9 +44582,15 @@ function createScriptRuntime(module, initial, host) {
44367
44582
  if (event.type === "viewchange") view = event.data;
44368
44583
  const listeners = handlers.get(event.type);
44369
44584
  if (!listeners?.size) return;
44370
- seeded(() => {
44371
- for (const handler of listeners) handler(event);
44372
- });
44585
+ const outer = depth;
44586
+ depth = event.depth ?? 0;
44587
+ try {
44588
+ seeded(() => {
44589
+ for (const handler of listeners) handler(event);
44590
+ });
44591
+ } finally {
44592
+ depth = outer;
44593
+ }
44373
44594
  invalidate();
44374
44595
  },
44375
44596
  draw(canvas) {
@@ -45177,6 +45398,98 @@ function seedOf(value) {
45177
45398
  function boardShaderSeed(seed) {
45178
45399
  return seedOf(seed);
45179
45400
  }
45401
+ const TEXEL_GROWTH = 128;
45402
+ function createTexels(drawn, pass) {
45403
+ const root = new Container();
45404
+ root.addChild(new Mesh({
45405
+ geometry: drawn.geometry,
45406
+ shader: drawn.shader
45407
+ }));
45408
+ const sprite = new Sprite({
45409
+ texture: Texture.EMPTY,
45410
+ label: "board-shader-texels"
45411
+ });
45412
+ sprite.blendMode = pass.blend ?? "normal";
45413
+ sprite.visible = false;
45414
+ return {
45415
+ size: pass.texel ?? 1,
45416
+ root,
45417
+ sprite,
45418
+ target: null,
45419
+ rect: null
45420
+ };
45421
+ }
45422
+ function texelRect(frame, size) {
45423
+ const [a, b] = frame.localToGlobal;
45424
+ if (Math.hypot(a, b) * frame.density * Math.min(1, frame.shading ?? 1) * size <= 1) return null;
45425
+ const { region, view } = frame;
45426
+ const left = Math.floor(Math.max(region.x, view.x) / size) * size;
45427
+ const top = Math.floor(Math.max(region.y, view.y) / size) * size;
45428
+ const right = Math.ceil(Math.min(region.x + region.width, view.x + view.width) / size) * size;
45429
+ const bottom = Math.ceil(Math.min(region.y + region.height, view.y + view.height) / size) * size;
45430
+ return right > left && bottom > top ? {
45431
+ x: left,
45432
+ y: top,
45433
+ width: right - left,
45434
+ height: bottom - top
45435
+ } : null;
45436
+ }
45437
+ function drawTexels(renderer, texels, rect) {
45438
+ const width = Math.round(rect.width / texels.size);
45439
+ const height = Math.round(rect.height / texels.size);
45440
+ let target = texels.target;
45441
+ if (!target || target.width < width || target.height < height) {
45442
+ releaseTexels(texels);
45443
+ const grow = (edge) => Math.ceil(edge / TEXEL_GROWTH) * TEXEL_GROWTH;
45444
+ target = RenderTexture.create({
45445
+ width: grow(width),
45446
+ height: grow(height),
45447
+ resolution: 1,
45448
+ scaleMode: "nearest",
45449
+ antialias: false,
45450
+ autoGenerateMipmaps: false
45451
+ });
45452
+ texels.target = target;
45453
+ texels.sprite.texture = new Texture({
45454
+ source: target.source,
45455
+ frame: new Rectangle(0, 0, width, height),
45456
+ dynamic: true
45457
+ });
45458
+ }
45459
+ const texture = texels.sprite.texture;
45460
+ if (texture.frame.width !== width || texture.frame.height !== height) {
45461
+ texture.frame.width = width;
45462
+ texture.frame.height = height;
45463
+ texture.update();
45464
+ }
45465
+ texels.root.scale.set(1 / texels.size);
45466
+ texels.root.position.set(-rect.x / texels.size, -rect.y / texels.size);
45467
+ renderer.render({
45468
+ container: texels.root,
45469
+ target,
45470
+ clear: true,
45471
+ clearColor: [
45472
+ 0,
45473
+ 0,
45474
+ 0,
45475
+ 0
45476
+ ]
45477
+ });
45478
+ texels.sprite.position.set(rect.x, rect.y);
45479
+ texels.sprite.scale.set(texels.size);
45480
+ }
45481
+ function releaseTexels(texels) {
45482
+ if (!texels.target) return;
45483
+ texels.sprite.texture.destroy();
45484
+ texels.sprite.texture = Texture.EMPTY;
45485
+ texels.target.destroy(true);
45486
+ texels.target = null;
45487
+ }
45488
+ function destroyTexels(texels) {
45489
+ releaseTexels(texels);
45490
+ texels.sprite.destroy();
45491
+ texels.root.destroy({ children: true });
45492
+ }
45180
45493
  function createBoardShaderLayer(renderer, shader, parameters, label, options = {}) {
45181
45494
  const uniforms = boardShaderUniforms(shader.uniforms);
45182
45495
  const surfaces = shader.surfaces === true;
@@ -45258,12 +45571,15 @@ function createBoardShaderLayer(renderer, shader, parameters, label, options = {
45258
45571
  const container = containers[layer];
45259
45572
  container.boundsArea = area;
45260
45573
  container.addChild(drawn.mesh);
45574
+ const texels = pass.texel ? createTexels(drawn, pass) : null;
45575
+ if (texels) container.addChild(texels.sprite);
45261
45576
  meshes.push({
45262
45577
  ...drawn,
45263
45578
  pass,
45264
45579
  sprites,
45265
45580
  placement,
45266
- scaler: null
45581
+ scaler: null,
45582
+ texels
45267
45583
  });
45268
45584
  });
45269
45585
  let state = null;
@@ -45474,8 +45790,14 @@ function createBoardShaderLayer(renderer, shader, parameters, label, options = {
45474
45790
  area.width = frame.region.width;
45475
45791
  area.height = frame.region.height;
45476
45792
  for (const drawn of meshes) {
45477
- drawn.mesh.visible = boardShaderPassOn(drawn.pass, frame.passes);
45478
- if (!drawn.sprites) shade(drawn, frame);
45793
+ const on = boardShaderPassOn(drawn.pass, frame.passes);
45794
+ const texels = drawn.texels;
45795
+ if (texels) {
45796
+ texels.rect = on ? texelRect(frame, texels.size) : null;
45797
+ texels.sprite.visible = texels.rect !== null;
45798
+ }
45799
+ drawn.mesh.visible = on && !texels?.rect;
45800
+ if (drawn.mesh.visible && !drawn.sprites) shade(drawn, frame);
45479
45801
  }
45480
45802
  for (const { filter, pass } of filters) filter.enabled = boardShaderPassOn(pass, frame.passes);
45481
45803
  fill(group, frame, frame.region);
@@ -45499,6 +45821,7 @@ function createBoardShaderLayer(renderer, shader, parameters, label, options = {
45499
45821
  ran: 0,
45500
45822
  behind: false
45501
45823
  };
45824
+ for (const { texels } of meshes) if (texels?.rect) drawTexels(target, texels, texels.rect);
45502
45825
  if (placementsStale || stepped.ran) {
45503
45826
  for (const { placement, mesh } of meshes) if (placement && mesh.visible) target.render({
45504
45827
  container: placement.mesh.mesh,
@@ -45540,6 +45863,7 @@ function createBoardShaderLayer(renderer, shader, parameters, label, options = {
45540
45863
  for (const compile of compiles) compile.cancel();
45541
45864
  for (const drawn of meshes) {
45542
45865
  drawn.scaler?.destroy();
45866
+ if (drawn.texels) destroyTexels(drawn.texels);
45543
45867
  destroyBoardShaderMesh(drawn);
45544
45868
  if (drawn.placement) destroyPlacement(renderer, drawn.placement);
45545
45869
  }
@@ -46180,6 +46504,7 @@ function buildContext(input) {
46180
46504
  scene: input.scene,
46181
46505
  time: input.time ?? 0,
46182
46506
  frameAt: input.frameAt,
46507
+ ...input.page ? { page: input.page } : {},
46183
46508
  selectedIds: /* @__PURE__ */ new Set(),
46184
46509
  hoveredId: null,
46185
46510
  resizingIds: /* @__PURE__ */ new Set(),
@@ -46320,6 +46645,7 @@ function createBoardExportScene(input) {
46320
46645
  const container = containers.get(owner.id);
46321
46646
  if (!item || !container) return null;
46322
46647
  const group = isSelfGroupedFrame(item) ? groups.get(item.id)?.group : void 0;
46648
+ for (const part of [layer.below, layer.above]) if (part && item.type === "frame") clipFrameShaderLayer(part, item);
46323
46649
  if (layer.below) container.addChildAt(layer.below, 0);
46324
46650
  if (layer.above) {
46325
46651
  if (group) {
@@ -46471,6 +46797,7 @@ function renderBoardExport(renderer, input, options = {}) {
46471
46797
  colorScheme
46472
46798
  }),
46473
46799
  backdropTexture: options.backgroundTexture,
46800
+ ...plan.page ? { page: plan.page } : {},
46474
46801
  ...gpu && owners.length ? { shaders: {
46475
46802
  renderer,
46476
46803
  owners,
@@ -46523,6 +46850,10 @@ function renderBoardExport(renderer, input, options = {}) {
46523
46850
  kind: "shader-failed",
46524
46851
  ...failure
46525
46852
  });
46853
+ if (gpu) for (const miss of boardShaderMisses(scene, plan, owners, exportScene.shaderErrors)) warnings.push({
46854
+ kind: "shader-hidden",
46855
+ ...miss
46856
+ });
46526
46857
  return {
46527
46858
  canvas,
46528
46859
  plan,
@@ -46533,6 +46864,38 @@ function renderBoardExport(renderer, input, options = {}) {
46533
46864
  flattened?.();
46534
46865
  }
46535
46866
  }
46867
+ function boardShaderMisses(scene, plan, owners, failed = []) {
46868
+ const planned = new Set(plan.items.map((item) => item.id));
46869
+ const misses = owners.flatMap(({ id, root, output }) => {
46870
+ if (failed.some((failure) => failure.id === id)) return [];
46871
+ const shader = output.shader;
46872
+ if (shader && !shader.state && shader.passes.every((pass) => !boardShaderPassOn(pass, output.passes))) return [{
46873
+ id,
46874
+ reason: "every pass is switched off (ctx.passes() or enabled: false)"
46875
+ }];
46876
+ if (root) return [];
46877
+ const item = scene.get(id);
46878
+ if (!item) return [{
46879
+ id,
46880
+ reason: "its item is not in the document"
46881
+ }];
46882
+ if (scene.opacity(id) <= 0) return [{
46883
+ id,
46884
+ reason: "its item is hidden (opacity 0 or invisible)"
46885
+ }];
46886
+ if (planned.has(id)) return [];
46887
+ return [{
46888
+ id,
46889
+ reason: exportItemBounds(item, scene) ? "its item is outside the exported area" : "its item is clipped away by a parent frame"
46890
+ }];
46891
+ });
46892
+ const grouped = /* @__PURE__ */ new Map();
46893
+ for (const { id, reason } of misses) grouped.set(reason, [...grouped.get(reason) ?? [], id]);
46894
+ return [...grouped].map(([reason, ids]) => ({
46895
+ ids,
46896
+ reason
46897
+ }));
46898
+ }
46536
46899
  function listIds(ids) {
46537
46900
  return ids.length > 3 ? `${ids.slice(0, 3).join(", ")} and ${ids.length - 3} more` : ids.join(", ");
46538
46901
  }
@@ -46543,6 +46906,7 @@ function describeBoardExportWarning(warning) {
46543
46906
  case "many-items": return `${warning.count} items exported; this may take a moment.`;
46544
46907
  case "shaders-unsupported": return `Shaders need a WebGL renderer; this export ${[warning.omitted.length ? `left out ${listIds(warning.omitted)}` : "", warning.drawn.length ? `drew ${listIds(warning.drawn)} with draw()` : ""].filter(Boolean).join(" and ")}.`;
46545
46908
  case "shader-failed": return `Shader ${warning.id} was left out: ${warning.message}`;
46909
+ case "shader-hidden": return `${warning.ids.length === 1 ? "Shader" : "Shaders"} of ${listIds(warning.ids)} drew nothing: ${warning.reason.replace(/^its item is/, warning.ids.length === 1 ? "its item is" : "their items are")}.`;
46546
46910
  }
46547
46911
  }
46548
46912
  //#endregion
@@ -46596,7 +46960,7 @@ function initializeBoardFonts(registry, fonts) {
46596
46960
  //#region ../sdk/src/board/export/node/scripts.ts
46597
46961
  const WORKER = `
46598
46962
  const {parentPort, workerData} = require('node:worker_threads');
46599
- const {createContext, Script, SourceTextModule} = require('node:vm');
46963
+ const {createContext, Script, SourceTextModule, SyntheticModule} = require('node:vm');
46600
46964
  const {createCanvas, GlobalFonts} = require(workerData.canvasModule);
46601
46965
  (${initializeBoardFonts.toString()})(GlobalFonts, workerData.fonts);
46602
46966
  const instances = new Map();
@@ -46627,10 +46991,15 @@ async function create(data) {
46627
46991
  return parts.join('/');
46628
46992
  };
46629
46993
  const link = (name,ref) => load(resolve(ref.identifier,name));
46994
+ const json = new Script('(text)=>{const freeze=v=>{if(v&&typeof v==="object"&&!Object.isFrozen(v)){Object.freeze(v);for(const k in v)freeze(v[k]);}return v};return freeze(JSON.parse(text))}').runInContext(context);
46630
46995
  function load(path) {
46631
46996
  if(modules.has(path)) return modules.get(path);
46632
46997
  const source=sources[path];
46633
46998
  if(!source) throw new Error('Module is unavailable: '+path);
46999
+ if(path.endsWith('.json')) {
47000
+ const module=new SyntheticModule(['default'],function(){this.setExport('default',json(source.code));},{context,identifier:path});
47001
+ modules.set(path,module);return module;
47002
+ }
46634
47003
  const module=new SourceTextModule(source.code,{context,identifier:path,importModuleDynamically:async name=>{
46635
47004
  const child=load(resolve(path,name));
46636
47005
  if(child.status==='unlinked') await child.link(link);
@@ -46696,6 +47065,16 @@ parentPort.on('message',async data=>{
46696
47065
  } catch(error) { release(data.input?.id);parentPort.postMessage({kind:'sample',error:String(error.stack||error)}); }
46697
47066
  });
46698
47067
  `;
47068
+ function describeBoardScriptLanes(lanes) {
47069
+ return lanes.flatMap(({ lane, thread, running, waiting, scripts }) => {
47070
+ if (!running && !waiting) return [];
47071
+ return [`${`lane ${lane}${thread === null ? "" : ` (worker thread ${thread})`}`}: ${running ? `${running.id} busy for ${(running.ms / 1e3).toFixed(1)} s${running.event ? `, last event ${running.event}` : ""}${running.call ? `, last call ${running.call}` : ""}` : "idle"}${waiting ? `; ${waiting} more request${waiting === 1 ? "" : "s"} queued` : ""} (runs ${scripts.join(", ")})`];
47072
+ });
47073
+ }
47074
+ function describeCall(name, input) {
47075
+ const message = input;
47076
+ return name === "board.emit" && message && typeof message.target === "string" ? `emit(${message.target}, "${String(message.type)}")` : name;
47077
+ }
46699
47078
  function createNodeScriptLanes(renderer, options) {
46700
47079
  const calls = /* @__PURE__ */ new Map();
46701
47080
  const settled = /* @__PURE__ */ new Set();
@@ -46704,8 +47083,11 @@ function createNodeScriptLanes(renderer, options) {
46704
47083
  const lanes = Array.from({ length: concurrency }, () => ({
46705
47084
  worker: null,
46706
47085
  tail: Promise.resolve(),
46707
- graphs: /* @__PURE__ */ new Set()
47086
+ graphs: /* @__PURE__ */ new Set(),
47087
+ running: null,
47088
+ waiting: 0
46708
47089
  }));
47090
+ const activity = /* @__PURE__ */ new Map();
46709
47091
  const assignments = /* @__PURE__ */ new Map();
46710
47092
  const sources = /* @__PURE__ */ new Map();
46711
47093
  const modules = createBoardScriptModuleReader(options.readModule, options.readTimeoutMs);
@@ -46761,6 +47143,10 @@ function createNodeScriptLanes(renderer, options) {
46761
47143
  calls.delete(key);
46762
47144
  }
46763
47145
  if (message.kind !== "call") return;
47146
+ activity.set(message.id ?? "", {
47147
+ ...activity.get(message.id ?? ""),
47148
+ call: describeCall(message.name ?? "", message.input)
47149
+ });
46764
47150
  const answer = (value, error) => {
46765
47151
  if (lane.worker !== worker) return;
46766
47152
  const done = new Promise((resolve) => {
@@ -46794,14 +47180,21 @@ function createNodeScriptLanes(renderer, options) {
46794
47180
  });
46795
47181
  return worker;
46796
47182
  }
46797
- function request(lane, message, register) {
47183
+ function request(lane, message, register, id) {
47184
+ lane.waiting++;
46798
47185
  const task = lane.tail.then(() => new Promise((resolve, reject) => {
47186
+ lane.waiting--;
46799
47187
  if (disposed) return reject(/* @__PURE__ */ new Error("Script host is disposed."));
46800
47188
  const worker = start(lane);
47189
+ if (id) lane.running = {
47190
+ id,
47191
+ since: performance.now()
47192
+ };
46801
47193
  const cleanup = () => {
46802
47194
  clearTimeout(timer);
46803
47195
  worker.off("message", reply);
46804
47196
  lane.reject = void 0;
47197
+ lane.running = null;
46805
47198
  };
46806
47199
  const reply = (value) => {
46807
47200
  if (value.kind !== "sample") return;
@@ -46839,6 +47232,10 @@ function createNodeScriptLanes(renderer, options) {
46839
47232
  if (!Number.isFinite(time) || time < 0 || time > 6e5) return Promise.reject(/* @__PURE__ */ new Error("Script time must be between 0 and 600000 ms."));
46840
47233
  const lane = laneOf(input.id);
46841
47234
  const src = input.script.src;
47235
+ if (events?.length) activity.set(input.id, {
47236
+ ...activity.get(input.id),
47237
+ event: events.map((event) => event.type).join(", ")
47238
+ });
46842
47239
  return request(lane, {
46843
47240
  input,
46844
47241
  src,
@@ -46852,7 +47249,21 @@ function createNodeScriptLanes(renderer, options) {
46852
47249
  draw,
46853
47250
  shaders,
46854
47251
  sources: lane.graphs.has(src) ? void 0 : graph
46855
- }, () => lane.graphs.add(src));
47252
+ }, () => lane.graphs.add(src), input.id);
47253
+ },
47254
+ status() {
47255
+ const now = performance.now();
47256
+ return lanes.map((lane, index) => ({
47257
+ lane: index + 1,
47258
+ thread: lane.worker?.threadId ?? null,
47259
+ running: lane.running && {
47260
+ id: lane.running.id,
47261
+ ms: now - lane.running.since,
47262
+ ...activity.get(lane.running.id)
47263
+ },
47264
+ waiting: lane.waiting,
47265
+ scripts: [...assignments].flatMap(([id, assigned]) => assigned === lane ? [id] : [])
47266
+ }));
46856
47267
  },
46857
47268
  async snapshot(id) {
46858
47269
  const lane = assignments.get(id);
@@ -46862,6 +47273,7 @@ function createNodeScriptLanes(renderer, options) {
46862
47273
  release(id) {
46863
47274
  const lane = assignments.get(id);
46864
47275
  assignments.delete(id);
47276
+ activity.delete(id);
46865
47277
  if (lane) lane.tail = lane.tail.then(() => lane.worker?.postMessage({ release: [id] }));
46866
47278
  },
46867
47279
  assigned: () => assignments.keys(),
@@ -46901,11 +47313,33 @@ function scopedInput(document, { id, script, item }, size) {
46901
47313
  };
46902
47314
  }
46903
47315
  function createNodeBoardScriptHost(renderer, options) {
46904
- const lanes = createNodeScriptLanes(renderer, options);
47316
+ let current = null;
47317
+ let ranks = /* @__PURE__ */ new Map();
47318
+ const outbox = createBoardScriptOutbox(() => ranks);
47319
+ const emitFailures = /* @__PURE__ */ new Map();
47320
+ const lanes = createNodeScriptLanes(renderer, {
47321
+ ...options,
47322
+ async call(id, name, input) {
47323
+ if (name === "board.emit" && current) {
47324
+ try {
47325
+ const { target, event } = boardScriptEmit(current, id, input);
47326
+ outbox.push(id, target, event);
47327
+ } catch (error) {
47328
+ emitFailures.set(id, error instanceof Error ? error.message : String(error));
47329
+ throw error;
47330
+ }
47331
+ return;
47332
+ }
47333
+ const call = BOARD_SCRIPT_EXPORT_CALLS[name];
47334
+ if (!call) throw new Error("Capabilities are unavailable during export.");
47335
+ return call(input);
47336
+ }
47337
+ });
46905
47338
  const textures = /* @__PURE__ */ new Map();
46906
47339
  const outputs = /* @__PURE__ */ new Map();
46907
47340
  const errors = /* @__PURE__ */ new Map();
46908
47341
  const sampled = /* @__PURE__ */ new Map();
47342
+ const views = /* @__PURE__ */ new Map();
46909
47343
  const key = (id, time) => `${id}|${time}`;
46910
47344
  let disposed = false;
46911
47345
  return {
@@ -46913,6 +47347,8 @@ function createNodeBoardScriptHost(renderer, options) {
46913
47347
  frame: (item, time) => textures.get(key(item.id, time)) ?? null,
46914
47348
  error: (id) => errors.get(id) ?? null,
46915
47349
  release() {},
47350
+ emitFailures,
47351
+ status: () => lanes.status(),
46916
47352
  shaders: (document, time) => boardShaderOwners(document, outputs.get(time) ?? [], () => time),
46917
47353
  document(document, time) {
46918
47354
  const at = outputs.get(time);
@@ -46936,11 +47372,20 @@ function createNodeBoardScriptHost(renderer, options) {
46936
47372
  items: Object.fromEntries(list.map(({ id, frame: _frame, ...item }) => [id, item]))
46937
47373
  });
46938
47374
  const document = documentOf(items);
47375
+ current = document;
47376
+ emitFailures.clear();
46939
47377
  const scripted = boardScriptAttachments(document);
47378
+ ranks = new Map(scripted.map(({ id }, index) => [id, index]));
46940
47379
  const alive = new Set(scripted.map(({ id }) => id));
46941
- for (const id of [...lanes.assigned()]) if (!alive.has(id)) lanes.release(id);
47380
+ for (const id of [...lanes.assigned()]) if (!alive.has(id)) {
47381
+ lanes.release(id);
47382
+ views.delete(id);
47383
+ sampled.delete(id);
47384
+ }
46942
47385
  if (!scripted.length) return;
46943
47386
  const frames = new Map(items.map((item) => [item.id, item.frame]));
47387
+ const viewKey = options?.view ? JSON.stringify(options.view) : null;
47388
+ const prepared = /* @__PURE__ */ new Map();
46944
47389
  await Promise.all(scripted.map(async (attachment) => {
46945
47390
  const { id, item } = attachment;
46946
47391
  try {
@@ -46949,12 +47394,58 @@ function createNodeBoardScriptHost(renderer, options) {
46949
47394
  const width = item ? "size" in item ? item.size.width : frame?.width ?? 0 : 0;
46950
47395
  const height = item ? "size" in item ? item.size.height : frame?.height ?? 0 : 0;
46951
47396
  const scale = Math.min(4, Math.max(.25, zoom), 2048 / Math.max(1, width, height));
46952
- const input = scopedInput(document, attachment, {
47397
+ prepared.set(id, {
47398
+ attachment,
47399
+ graph,
47400
+ input: scopedInput(document, attachment, {
47401
+ width,
47402
+ height
47403
+ }),
46953
47404
  width,
46954
- height
47405
+ height,
47406
+ scale
47407
+ });
47408
+ } catch (error) {
47409
+ errors.set(id, error instanceof Error ? error.message : String(error));
47410
+ }
47411
+ }));
47412
+ const keep = async (id, time, events) => {
47413
+ const entry = prepared.get(id);
47414
+ if (!entry || errors.has(id)) return;
47415
+ const { attachment, graph, input, scale } = entry;
47416
+ try {
47417
+ const result = await lanes.sample({
47418
+ input,
47419
+ graph,
47420
+ time,
47421
+ scale,
47422
+ events,
47423
+ draw: Boolean(attachment.item),
47424
+ shaders: options?.shaders
46955
47425
  });
46956
- for (const time of times) {
47426
+ if (disposed) return;
47427
+ if (result.png) {
47428
+ const frameKey = key(id, time);
47429
+ textures.get(frameKey)?.destroy(true);
47430
+ const texture = await renderer.decodeImage(result.png);
47431
+ if (result.output.pixelated) texture.source.scaleMode = "nearest";
47432
+ textures.set(frameKey, texture);
47433
+ }
47434
+ let at = outputs.get(time);
47435
+ if (!at) {
47436
+ at = /* @__PURE__ */ new Map();
47437
+ outputs.set(time, at);
47438
+ }
47439
+ at.set(id, result.output);
47440
+ } catch (error) {
47441
+ errors.set(id, error instanceof Error ? error.message : String(error));
47442
+ }
47443
+ };
47444
+ for (const time of times) {
47445
+ await Promise.all([...prepared].map(async ([id, { attachment, graph, input, width, height, scale }]) => {
47446
+ try {
46957
47447
  const last = sampled.get(id) ?? 0;
47448
+ if (time < last) views.delete(id);
46958
47449
  if (options?.history) {
46959
47450
  const from = last <= time ? last : 0;
46960
47451
  const run = async (at, document) => {
@@ -46998,34 +47489,36 @@ function createNodeBoardScriptHost(renderer, options) {
46998
47489
  }
46999
47490
  if (JSON.stringify(input.script.params) !== previous && before.at > ran) await run(before.at, before.document);
47000
47491
  }
47001
- sampled.set(id, time);
47002
- const result = await lanes.sample({
47003
- input,
47004
- graph,
47005
- time,
47006
- scale,
47007
- draw: Boolean(item),
47008
- shaders: options?.shaders
47492
+ } catch (error) {
47493
+ errors.set(id, error instanceof Error ? error.message : String(error));
47494
+ return;
47495
+ }
47496
+ sampled.set(id, time);
47497
+ const events = [];
47498
+ const shown = viewKey && `${JSON.stringify({
47499
+ ...attachment.script,
47500
+ params: void 0
47501
+ })}|${viewKey}`;
47502
+ if (shown && views.get(id) !== shown) {
47503
+ views.set(id, shown);
47504
+ events.push({
47505
+ type: "viewchange",
47506
+ data: options?.view
47009
47507
  });
47010
- if (disposed) return;
47011
- if (result.png) {
47012
- const frameKey = key(id, time);
47013
- textures.get(frameKey)?.destroy(true);
47014
- const texture = await renderer.decodeImage(result.png);
47015
- if (result.output.pixelated) texture.source.scaleMode = "nearest";
47016
- textures.set(frameKey, texture);
47017
- }
47018
- let at = outputs.get(time);
47019
- if (!at) {
47020
- at = /* @__PURE__ */ new Map();
47021
- outputs.set(time, at);
47022
- }
47023
- at.set(id, result.output);
47024
47508
  }
47025
- } catch (error) {
47026
- errors.set(id, error instanceof Error ? error.message : String(error));
47509
+ await keep(id, time, events);
47510
+ }));
47511
+ for (let round = 0; outbox.size && round <= 16 && !disposed; round++) {
47512
+ const delivered = [...outbox.take()].flatMap(([id, events]) => {
47513
+ const output = outputs.get(time)?.get(id);
47514
+ const wanted = events.filter((event) => boardScriptListens(output, event));
47515
+ return wanted.length ? [keep(id, time, wanted)] : [];
47516
+ });
47517
+ await Promise.all(delivered);
47027
47518
  }
47028
- }));
47519
+ outbox.take();
47520
+ }
47521
+ await lanes.idle();
47029
47522
  },
47030
47523
  destroy() {
47031
47524
  disposed = true;
@@ -47183,10 +47676,12 @@ function createNodeBoardScriptRuntime(renderer, options) {
47183
47676
  },
47184
47677
  event(id, event) {
47185
47678
  const entry = entries.get(id);
47186
- if (!entry || entry.error || entry.output && !entry.output.listens.includes(event.type)) return;
47187
- entry.events.push(event);
47679
+ if (!entry || entry.error || !boardScriptListens(entry.output, event)) return true;
47680
+ if (!queueBoardScriptEvent(entry.events, event)) return false;
47188
47681
  callbacks.onFrame();
47682
+ return true;
47189
47683
  },
47684
+ status: () => lanes.status(),
47190
47685
  output: (id) => entries.get(id)?.output ?? null,
47191
47686
  snapshot: (id) => lanes.snapshot(id),
47192
47687
  restore() {
@@ -47684,6 +48179,7 @@ const STRUCTURAL_KEYS = [
47684
48179
  "parent",
47685
48180
  "z",
47686
48181
  "locked",
48182
+ "autoplay",
47687
48183
  "metadata"
47688
48184
  ];
47689
48185
  function keyframe(animations, playhead, recording, id, property, value, storedValue) {
@@ -49199,7 +49695,7 @@ function createDocumentModule(ctx) {
49199
49695
  const previous = scripted;
49200
49696
  scripted = items;
49201
49697
  const changed = [.../* @__PURE__ */ new Set([...previous.keys(), ...items.keys()])].filter((id) => !sameJson(previous.get(id), items.get(id)));
49202
- if (!changed.length) return;
49698
+ if (!changed.length) return changed;
49203
49699
  const restacked = /* @__PURE__ */ new Set();
49204
49700
  rescene(changed.some((id) => {
49205
49701
  const before = previous.get(id) ?? state.base.items[id];
@@ -49208,6 +49704,7 @@ function createDocumentModule(ctx) {
49208
49704
  if (before.z !== after.z) restacked.add(after.parent ?? "");
49209
49705
  return false;
49210
49706
  }) || [...restacked].some(reordered) ? void 0 : changed);
49707
+ return changed;
49211
49708
  }
49212
49709
  function reordered(parent) {
49213
49710
  const { scene } = state;
@@ -49245,10 +49742,10 @@ function createDocumentModule(ctx) {
49245
49742
  state.structureVersion += 1;
49246
49743
  state.geometryVersion += 1;
49247
49744
  }
49248
- function setDraftItem(id, item) {
49745
+ function setDraftItem(id, item, shown) {
49249
49746
  if (!draft.has(id)) {
49250
- const shown = displayItem(id);
49251
- if (shown) draftOrigins.set(id, shown);
49747
+ const origin = shown ?? displayItem(id);
49748
+ if (origin) draftOrigins.set(id, origin);
49252
49749
  }
49253
49750
  draft.set(id, item);
49254
49751
  }
@@ -49258,9 +49755,9 @@ function createDocumentModule(ctx) {
49258
49755
  function dropDraftItem(id) {
49259
49756
  draft.delete(id);
49260
49757
  }
49261
- function writeDraft(changes, structural = false) {
49758
+ function writeDraft(changes, structural = false, shown) {
49262
49759
  if (changes.size === 0) return;
49263
- for (const [id, item] of changes) setDraftItem(id, item);
49760
+ for (const [id, item] of changes) setDraftItem(id, item, shown?.get(id)?.item);
49264
49761
  if (!structural) for (const [id, item] of changes) {
49265
49762
  const before = state.scene.get(id);
49266
49763
  if (!item || !before || before.parent !== item.parent || before.z !== item.z || !sameJson(arrowBindings(before), arrowBindings(item))) {
@@ -50066,7 +50563,7 @@ function createInteractionModule(ctx) {
50066
50563
  const translating = {
50067
50564
  type: "translating",
50068
50565
  start: gesture.world,
50069
- origin: ctx.selection.framesFor([gesture.itemId]),
50566
+ ...ctx.selection.grab([gesture.itemId]),
50070
50567
  moved: false,
50071
50568
  duplicate: false
50072
50569
  };
@@ -50094,7 +50591,7 @@ function createInteractionModule(ctx) {
50094
50591
  state.interaction = {
50095
50592
  type: "translating",
50096
50593
  start: last?.world ?? (gesture.type === "pressing" ? gesture.world : rectCenter(item.frame)),
50097
- origin: ctx.selection.framesFor([item.id]),
50594
+ ...ctx.selection.grab([item.id]),
50098
50595
  moved: false,
50099
50596
  duplicate: false,
50100
50597
  held: true
@@ -50131,7 +50628,7 @@ function createInteractionModule(ctx) {
50131
50628
  state.interaction = {
50132
50629
  type: "translating",
50133
50630
  start: event.world,
50134
- origin: ctx.selection.framesFor(ctx.selection.movable()),
50631
+ ...ctx.selection.grab(ctx.selection.movable()),
50135
50632
  moved: false,
50136
50633
  duplicate: event.altKey,
50137
50634
  ...tap ? { tap } : {}
@@ -50278,13 +50775,13 @@ function createInteractionModule(ctx) {
50278
50775
  pivot,
50279
50776
  startAngle: angleFrom(pivot, event.world),
50280
50777
  current: event.world,
50281
- origin: ctx.selection.framesFor(ctx.selection.movable()),
50778
+ ...ctx.selection.grab(ctx.selection.movable()),
50282
50779
  moved: false
50283
50780
  };
50284
50781
  return;
50285
50782
  }
50286
50783
  if (control?.kind === "resize" && bounds && transform) {
50287
- const origin = ctx.selection.framesFor(ctx.selection.movable());
50784
+ const { origin, grabbed } = ctx.selection.grab(ctx.selection.movable());
50288
50785
  const single = origin.size === 1 ? { ...[...origin.values()][0] } : null;
50289
50786
  const edge = frameHandlePosition(transform.frame, control.handle);
50290
50787
  const grab = {
@@ -50297,6 +50794,7 @@ function createInteractionModule(ctx) {
50297
50794
  single,
50298
50795
  bounds,
50299
50796
  origin,
50797
+ grabbed,
50300
50798
  grab,
50301
50799
  moved: false
50302
50800
  };
@@ -50388,7 +50886,7 @@ function createInteractionModule(ctx) {
50388
50886
  state.selection = roots;
50389
50887
  current = {
50390
50888
  ...current,
50391
- origin: ctx.selection.framesFor(roots),
50889
+ ...ctx.selection.grab(roots),
50392
50890
  duplicate: false
50393
50891
  };
50394
50892
  }
@@ -50416,7 +50914,7 @@ function createInteractionModule(ctx) {
50416
50914
  ty += snap.dy;
50417
50915
  state.snapGuides = snap.guides;
50418
50916
  } else state.snapGuides = [];
50419
- ctx.document.writeDraft(ctx.selection.placed(shift(tx, ty)));
50917
+ ctx.document.writeDraft(ctx.selection.placed(shift(tx, ty), current.grabbed), false, current.grabbed);
50420
50918
  let dropTargetId = null;
50421
50919
  for (const parent of dropParents(current.origin, true).values()) if (parent) dropTargetId = parent;
50422
50920
  if ((current.dropTargetId ?? null) !== dropTargetId) state.interaction = {
@@ -50446,7 +50944,7 @@ function createInteractionModule(ctx) {
50446
50944
  if (frame) frames.set(id, frame);
50447
50945
  });
50448
50946
  }
50449
- ctx.document.writeDraft(ctx.selection.placed(frames));
50947
+ ctx.document.writeDraft(ctx.selection.placed(frames, gesture.grabbed), false, gesture.grabbed);
50450
50948
  }
50451
50949
  function rotate(gesture, event) {
50452
50950
  if (!gesture.moved && !dragged(event)) return;
@@ -50466,7 +50964,7 @@ function createInteractionModule(ctx) {
50466
50964
  rotation: normalizeRotation(frame.rotation)
50467
50965
  });
50468
50966
  });
50469
- ctx.document.writeDraft(ctx.selection.placed(frames));
50967
+ ctx.document.writeDraft(ctx.selection.placed(frames, gesture.grabbed), false, gesture.grabbed);
50470
50968
  }
50471
50969
  function dragArrowHandle(gesture, event) {
50472
50970
  if (!gesture.moved) {
@@ -51313,11 +51811,30 @@ function createSelectionModule(ctx) {
51313
51811
  }
51314
51812
  return frames;
51315
51813
  }
51316
- function placed(frames) {
51814
+ function grab(ids) {
51815
+ const { layout } = state.scene;
51816
+ const origin = framesFor(ids);
51817
+ const grabbed = /* @__PURE__ */ new Map();
51818
+ for (const id of origin.keys()) {
51819
+ const item = ctx.document.displayItem(id);
51820
+ if (item) grabbed.set(id, {
51821
+ item,
51822
+ parent: item.parent && layout.has(item.parent) ? layout.matrix(item.parent) : IDENTITY_MATRIX,
51823
+ box: layout.box(id)
51824
+ });
51825
+ }
51826
+ return {
51827
+ origin,
51828
+ grabbed
51829
+ };
51830
+ }
51831
+ function placed(frames, from) {
51317
51832
  const changes = /* @__PURE__ */ new Map();
51318
51833
  for (const [id, frame] of frames) {
51834
+ const grabbed = from?.get(id);
51319
51835
  const item = state.scene.get(id);
51320
- if (item) changes.set(id, sceneItemToItem({
51836
+ if (grabbed) changes.set(id, placeItem(grabbed.item, frame, grabbed.parent, grabbed.box));
51837
+ else if (item) changes.set(id, sceneItemToItem({
51321
51838
  ...item,
51322
51839
  frame
51323
51840
  }, state.scene.layout));
@@ -51403,6 +51920,22 @@ function createSelectionModule(ctx) {
51403
51920
  return unlocked;
51404
51921
  }, state.selection);
51405
51922
  }
51923
+ const autoplayable = () => items().filter((item) => !item.locked && boardAutoplayKind(item));
51924
+ function autoplay() {
51925
+ const eligible = autoplayable();
51926
+ return eligible.length > 0 ? eligible.every((item) => item.autoplay) : null;
51927
+ }
51928
+ function setAutoplay(on) {
51929
+ edit((item) => {
51930
+ if (!boardAutoplayKind(item) || Boolean(item.autoplay) === on) return null;
51931
+ if (on) return {
51932
+ ...item,
51933
+ autoplay: true
51934
+ };
51935
+ const { autoplay: _autoplay, ...rest } = item;
51936
+ return rest;
51937
+ }, autoplayable().map((item) => item.id));
51938
+ }
51406
51939
  function setColor(color) {
51407
51940
  edit((item) => {
51408
51941
  switch (item.type) {
@@ -51492,6 +52025,7 @@ function createSelectionModule(ctx) {
51492
52025
  clear: () => set([]),
51493
52026
  selectAll: () => set(state.scene.children(void 0).slice()),
51494
52027
  framesFor,
52028
+ grab,
51495
52029
  placed,
51496
52030
  movable,
51497
52031
  carries,
@@ -51501,6 +52035,8 @@ function createSelectionModule(ctx) {
51501
52035
  canFillFrame: () => framed().length > 0,
51502
52036
  fillFrame,
51503
52037
  toggleLock,
52038
+ autoplay,
52039
+ setAutoplay,
51504
52040
  setColor,
51505
52041
  setStyle,
51506
52042
  setProps,
@@ -51745,6 +52281,9 @@ function createBoardEditor(options) {
51745
52281
  return items.length > 0 && items.every((item) => item.locked);
51746
52282
  });
51747
52283
  },
52284
+ get selectionAutoplay() {
52285
+ return read(["scene", "selection"], selection.autoplay);
52286
+ },
51748
52287
  get bounds() {
51749
52288
  return read(["scene", "selection"], selection.bounds);
51750
52289
  },
@@ -51988,6 +52527,7 @@ function createBoardEditor(options) {
51988
52527
  },
51989
52528
  fillFrame: selection.fillFrame,
51990
52529
  toggleSelectionLock: selection.toggleLock,
52530
+ setSelectionAutoplay: selection.setAutoplay,
51991
52531
  setSelectionColor: selection.setColor,
51992
52532
  setSelectionStyle: selection.setStyle,
51993
52533
  setSelectionProps: selection.setProps,
@@ -52406,6 +52946,7 @@ const DEFAULT_TOOLS = ["select", "hand"];
52406
52946
  //#endregion
52407
52947
  //#region ../sdk/src/board/stage/script-controller.ts
52408
52948
  const ACTIVATION_MS = 5e3;
52949
+ const MOTION_MS = 1e3;
52409
52950
  const USER_EVENTS = /* @__PURE__ */ new Set([
52410
52951
  "pointerdown",
52411
52952
  "pointerup",
@@ -52435,6 +52976,8 @@ function createBoardScriptController(options) {
52435
52976
  const interactive = /* @__PURE__ */ new Set();
52436
52977
  const screens = /* @__PURE__ */ new Set();
52437
52978
  const activations = /* @__PURE__ */ new Map();
52979
+ const emitFailures = /* @__PURE__ */ new Map();
52980
+ const moved = /* @__PURE__ */ new Map();
52438
52981
  const listeners = /* @__PURE__ */ new Set();
52439
52982
  let version = 0;
52440
52983
  let composed = {
@@ -52526,13 +53069,14 @@ function createBoardScriptController(options) {
52526
53069
  capabilities: {
52527
53070
  ...options.capabilities,
52528
53071
  "board.emit": async (id, value) => {
52529
- const message = value;
52530
- if (!message || typeof message.target !== "string" || typeof message.type !== "string" || !(isBoardRootScript(editor.document, message.target) || boardScriptScope(editor.document, id).has(message.target))) throw new Error("Invalid script event target.");
52531
- if (activated(id)) activations.set(message.target, activations.get(id) ?? now());
52532
- host?.event(message.target, {
52533
- type: message.type,
52534
- data: message.data
52535
- });
53072
+ try {
53073
+ const { target, event } = boardScriptEmit(editor.document, id, value);
53074
+ if (activated(id)) activations.set(target, activations.get(id) ?? now());
53075
+ if (host && !host.event(target, event)) throw new Error(`emit(${target}, "${event.type}") from ${id}: ${target} already has 128 events waiting.`);
53076
+ } catch (error) {
53077
+ emitFailures.set(id, error instanceof Error ? error.message : String(error));
53078
+ throw error;
53079
+ }
52536
53080
  },
52537
53081
  "board.commit": (id, value) => {
52538
53082
  const { patch, frame } = value;
@@ -52583,10 +53127,12 @@ function createBoardScriptController(options) {
52583
53127
  screens.clear();
52584
53128
  outputs.clear();
52585
53129
  activations.clear();
53130
+ emitFailures.clear();
52586
53131
  presses.clear();
52587
53132
  gesture = null;
52588
53133
  router.clear();
52589
53134
  editor.setScriptItems(/* @__PURE__ */ new Map());
53135
+ moved.clear();
52590
53136
  hover = null;
52591
53137
  composed = {
52592
53138
  ...composed,
@@ -52612,7 +53158,8 @@ function createBoardScriptController(options) {
52612
53158
  const items = composeBoardScriptItems(editor.document, editor.scene, outputs, animation, camera, (owner, error) => host?.fault(owner, error instanceof Error ? error.message : String(error)), editor.gestureActive ? editor.scene.layout : void 0);
52613
53159
  const presented = new Set([...outputs.values()].flatMap((output) => Object.keys(output.patches)));
52614
53160
  for (const id of animation.keys()) if (!presented.has(id)) items.delete(id);
52615
- editor.setScriptItems(items);
53161
+ const at = now();
53162
+ for (const id of editor.setScriptItems(items)) if (items.has(id)) moved.set(id, at);
52616
53163
  composed = {
52617
53164
  version,
52618
53165
  document: editor.document,
@@ -52789,6 +53336,9 @@ function createBoardScriptController(options) {
52789
53336
  get hovering() {
52790
53337
  return hover !== null;
52791
53338
  },
53339
+ get hovered() {
53340
+ return hover;
53341
+ },
52792
53342
  get paused() {
52793
53343
  return paused;
52794
53344
  },
@@ -52804,6 +53354,11 @@ function createBoardScriptController(options) {
52804
53354
  animated = next;
52805
53355
  },
52806
53356
  compose,
53357
+ moving() {
53358
+ const at = now();
53359
+ for (const [id, changed] of moved) if (at - changed > MOTION_MS) moved.delete(id);
53360
+ return moved.keys();
53361
+ },
52807
53362
  sync,
52808
53363
  pointer,
52809
53364
  key(event) {
@@ -52835,6 +53390,7 @@ function createBoardScriptController(options) {
52835
53390
  return current && !paused ? boardShaderOwners(scriptDocument(), outputs, (id) => current.clock(id)) : [];
52836
53391
  },
52837
53392
  error: (id) => host?.error(id) ?? null,
53393
+ emitFailures,
52838
53394
  async snapshot() {
52839
53395
  const result = {};
52840
53396
  await Promise.all([...outputs.keys()].map(async (id) => {
@@ -52863,6 +53419,24 @@ function createBoardScriptController(options) {
52863
53419
  //#endregion
52864
53420
  //#region ../sdk/src/board/testing/index.ts
52865
53421
  const FRAME_MS = 1e3 / 60;
53422
+ function describeInteraction(editor) {
53423
+ const interaction = editor.interaction;
53424
+ const ids = () => editor.selection.join(", ");
53425
+ switch (interaction.type) {
53426
+ case "idle":
53427
+ case "pressing": return null;
53428
+ case "translating": return interaction.moved ? `move ${[...interaction.origin.keys()].join(", ")}` : null;
53429
+ case "resizing": return `resize ${ids()}`;
53430
+ case "rotating": return `rotate ${ids()}`;
53431
+ case "brushing": return "select box";
53432
+ case "panning": return interaction.moved ? "pan" : null;
53433
+ case "drawing": return "draw";
53434
+ case "creatingBox": return `create ${interaction.kind}`;
53435
+ case "creatingArrow": return "create arrow";
53436
+ case "creatingText": return "create text";
53437
+ case "draggingArrowHandle": return `arrow ${interaction.which} handle`;
53438
+ }
53439
+ }
52866
53440
  async function createBoardScriptHarness(options) {
52867
53441
  const renderer = options.renderer ?? await createNodeBoardRenderer();
52868
53442
  const commits = [];
@@ -52943,15 +53517,52 @@ async function createBoardScriptHarness(options) {
52943
53517
  pressure: .5
52944
53518
  };
52945
53519
  }
53520
+ let press = null;
53521
+ function editorHit(event) {
53522
+ const control = editor.tool === "select" && selectionTransformControlAt(editor.selectionTransform, event.world, editor.camera.zoom, event.pointerType, editor.controlOutset);
53523
+ if (control) return {
53524
+ on: "handle",
53525
+ handle: control.kind === "rotate" ? "rotate" : control.handle
53526
+ };
53527
+ const item = editor.pickAt(event.world, event.pointerType);
53528
+ if (item) return {
53529
+ on: "item",
53530
+ id: item.id,
53531
+ type: item.type
53532
+ };
53533
+ const under = editor.itemAt(event.world);
53534
+ return {
53535
+ on: "empty",
53536
+ ...under ? { under: under.id } : {}
53537
+ };
53538
+ }
52946
53539
  async function pointer(phase, point, input, pressed) {
52947
53540
  const event = pointerEvent(point, phase, input, pressed);
52948
- if (!controller.pointer(phase, event)) {
53541
+ const hit = phase === "down" ? editorHit(event) : null;
53542
+ const routed = controller.pointer(phase, event);
53543
+ const target = routed ? controller.hovered : null;
53544
+ if (phase === "down") press = {
53545
+ down: target ? {
53546
+ on: "script",
53547
+ ...target
53548
+ } : hit,
53549
+ taken: target ? `script ${target.owner}/${target.target}` : null
53550
+ };
53551
+ if (!routed) {
52949
53552
  if (phase === "down") editor.pointerDown(event);
52950
53553
  else if (phase === "move") editor.pointerMove(event);
52951
53554
  else editor.pointerUp(event);
52952
53555
  }
53556
+ if (press && !routed) press.taken = describeInteraction(editor) ?? press.taken;
52953
53557
  clock += FRAME_MS;
52954
53558
  await frame();
53559
+ if (phase !== "up" || !press) return null;
53560
+ const done = {
53561
+ down: press.down,
53562
+ taken: press.taken ?? (press.down.on === "empty" ? "nothing" : "tap")
53563
+ };
53564
+ press = null;
53565
+ return done;
52955
53566
  }
52956
53567
  await frame();
52957
53568
  return {
@@ -52967,6 +53578,10 @@ async function createBoardScriptHarness(options) {
52967
53578
  },
52968
53579
  output: (id) => controller.output(id),
52969
53580
  error: (id) => controller.error(id),
53581
+ get emitFailures() {
53582
+ return controller.emitFailures;
53583
+ },
53584
+ status: () => runtime?.status() ?? [],
52970
53585
  async advance(ms = FRAME_MS) {
52971
53586
  const end = clock + ms;
52972
53587
  while (clock < end) {
@@ -52977,14 +53592,14 @@ async function createBoardScriptHarness(options) {
52977
53592
  pointer,
52978
53593
  async tap(point, input) {
52979
53594
  await pointer("down", point, input);
52980
- await pointer("up", point, input);
53595
+ return await pointer("up", point, input);
52981
53596
  },
52982
53597
  async drag(points, input) {
52983
53598
  const [first, ...rest] = points;
52984
- if (!first) return;
53599
+ if (!first) return null;
52985
53600
  await pointer("down", first, input);
52986
53601
  for (const point of rest) await pointer("move", point, input);
52987
- await pointer("up", points.at(-1) ?? first, input);
53602
+ return pointer("up", points.at(-1) ?? first, input);
52988
53603
  },
52989
53604
  async move(points, input) {
52990
53605
  for (const point of points) await pointer("move", point, input, false);
@@ -53042,4 +53657,4 @@ async function createBoardScriptHarness(options) {
53042
53657
  };
53043
53658
  }
53044
53659
  //#endregion
53045
- export { BOARD_SCRIPT_DRAWING_EXAMPLE, BOARD_SCRIPT_RAIN_EXAMPLE, boardAnimatesScriptParams, boardAssetKey, boardAssetKeySource, boardFrameRegions, boardMediaRate, boardMediaSpans, boardPathTrack, boardPlacePatch, boardRegionStep, boardRenderTheme, boardScriptAttachments, boardSequence, boardSequencePatch, boardShaderParameters, boardTextureEdge, boardTexturePixels, boardTimedMedia, buildBoardScene, checkBoardShader, createBoardAnimationSampler, createBoardRenderSampler, createBoardScriptHarness, createNodeBoardRenderer, createNodeBoardScriptHost, describeBoardExportWarning, exportBoardImageBytes, hasBoardScripts, inspectBoardItems, inspectBoardScene, itemBounds, measureBoardText, parseBoardDocument, planBoardExport, prepareBoardExport, rectsIntersect, selectBoardExportAssets };
53660
+ export { BOARD_SCRIPT_DRAWING_EXAMPLE, BOARD_SCRIPT_RAIN_EXAMPLE, boardAnimatesScriptParams, boardAssetKey, boardAssetKeySource, boardAutoplayLoops, boardFrameRegions, boardMediaRate, boardMediaSpans, boardPathTrack, boardPlacePatch, boardRegionStep, boardRenderTheme, boardScriptAttachments, boardSequence, boardSequencePatch, boardShaderParameters, boardTextureEdge, boardTexturePixels, boardTimedMedia, buildBoardScene, checkBoardShader, createBoardAnimationSampler, createBoardRenderSampler, createBoardScriptHarness, createNodeBoardRenderer, createNodeBoardScriptHost, describeBoardExportWarning, describeBoardScriptLanes, exportBoardImageBytes, hasBoardScripts, inspectBoardItems, inspectBoardScene, itemBounds, measureBoardText, parseBoardDocument, planBoardExport, prepareBoardExport, rectsIntersect, selectBoardExportAssets };