@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.
- package/README.md +1 -0
- package/dist/about.d.ts +2 -0
- package/dist/about.js +71 -0
- package/dist/board-export.d.ts +2 -0
- package/dist/board-export.js +37 -9
- package/dist/board-gpu/daemon.js +3 -10
- package/dist/board-gpu/index.js +1 -1
- package/dist/board-gpu/page.js +667 -188
- package/dist/board-gpu/protocol.d.ts +14 -0
- package/dist/board-kernel.d.ts +2 -2
- package/dist/board-kernel.js +790 -175
- package/dist/board-media-export.d.ts +1 -0
- package/dist/board-media-export.js +17 -0
- package/dist/board-profile.d.ts +3 -1
- package/dist/board-profile.js +14 -0
- package/dist/board-simulate.d.ts +8 -1
- package/dist/board-simulate.js +92 -34
- package/dist/build.json +1 -0
- package/dist/commands/boards.js +75 -7
- package/dist/commands/feedback.js +2 -0
- package/dist/commands/version.d.ts +2 -0
- package/dist/commands/version.js +21 -0
- package/dist/host/serve.js +9 -3
- package/dist/index.js +4 -11
- package/dist/runtime/connection.js +2 -0
- package/dist/runtime/presentation.d.ts +1 -0
- package/dist/runtime/presentation.js +1 -0
- package/dist/runtime/supervisor.js +2 -1
- package/dist/version.d.ts +2 -0
- package/dist/version.js +17 -0
- package/package.json +9 -3
package/dist/board-gpu/page.js
CHANGED
|
@@ -5947,6 +5947,7 @@ const itemEnvelope$1 = {
|
|
|
5947
5947
|
visible: boolean().optional().describe("false hides the item and its children; key it on a timeline to show the item only for a span."),
|
|
5948
5948
|
style: BoardStyleSchema$1.default({}),
|
|
5949
5949
|
locked: boolean().optional(),
|
|
5950
|
+
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."),
|
|
5950
5951
|
metadata: record(string(), unknown()).optional()
|
|
5951
5952
|
};
|
|
5952
5953
|
const boxed$1 = (size) => ({
|
|
@@ -7082,6 +7083,7 @@ const NOT_ANIMATABLE = /* @__PURE__ */ new Set([
|
|
|
7082
7083
|
"parent",
|
|
7083
7084
|
"z",
|
|
7084
7085
|
"locked",
|
|
7086
|
+
"autoplay",
|
|
7085
7087
|
"metadata",
|
|
7086
7088
|
"script"
|
|
7087
7089
|
]);
|
|
@@ -7881,6 +7883,159 @@ function isBoardRootScript(document, id) {
|
|
|
7881
7883
|
return Boolean(document.board?.scripts && Object.hasOwn(document.board.scripts, id));
|
|
7882
7884
|
}
|
|
7883
7885
|
//#endregion
|
|
7886
|
+
//#region ../sdk/src/board/model/json.ts
|
|
7887
|
+
function sameJson(a, b) {
|
|
7888
|
+
if (a === b) return true;
|
|
7889
|
+
if (!a || !b || typeof a !== "object" || typeof b !== "object") return false;
|
|
7890
|
+
if (Array.isArray(a) || Array.isArray(b)) {
|
|
7891
|
+
if (!Array.isArray(a) || !Array.isArray(b) || a.length !== b.length) return false;
|
|
7892
|
+
for (let index = 0; index < a.length; index += 1) if (!sameJson(a[index], b[index])) return false;
|
|
7893
|
+
return true;
|
|
7894
|
+
}
|
|
7895
|
+
const left = a;
|
|
7896
|
+
const right = b;
|
|
7897
|
+
let members = 0;
|
|
7898
|
+
for (const key of Object.keys(left)) {
|
|
7899
|
+
if (left[key] === void 0) continue;
|
|
7900
|
+
members += 1;
|
|
7901
|
+
if (!sameJson(left[key], right[key])) return false;
|
|
7902
|
+
}
|
|
7903
|
+
for (const key of Object.keys(right)) if (right[key] !== void 0) members -= 1;
|
|
7904
|
+
return members === 0;
|
|
7905
|
+
}
|
|
7906
|
+
//#endregion
|
|
7907
|
+
//#region ../sdk/src/board/model/script-scope.ts
|
|
7908
|
+
const childrenByItems = /* @__PURE__ */ new WeakMap();
|
|
7909
|
+
const everyItem = /* @__PURE__ */ new WeakMap();
|
|
7910
|
+
function childIndex(items) {
|
|
7911
|
+
let index = childrenByItems.get(items);
|
|
7912
|
+
if (!index) {
|
|
7913
|
+
index = /* @__PURE__ */ new Map();
|
|
7914
|
+
for (const [id, item] of Object.entries(items)) {
|
|
7915
|
+
if (!item.parent) continue;
|
|
7916
|
+
const siblings = index.get(item.parent);
|
|
7917
|
+
if (siblings) siblings.push(id);
|
|
7918
|
+
else index.set(item.parent, [id]);
|
|
7919
|
+
}
|
|
7920
|
+
childrenByItems.set(items, index);
|
|
7921
|
+
}
|
|
7922
|
+
return index;
|
|
7923
|
+
}
|
|
7924
|
+
function boardScriptOf(document, id) {
|
|
7925
|
+
return isBoardRootScript(document, id) ? document.board?.scripts?.[id] : document.items[id]?.script;
|
|
7926
|
+
}
|
|
7927
|
+
function boardScriptScope(document, id) {
|
|
7928
|
+
if (isBoardRootScript(document, id)) {
|
|
7929
|
+
let all = everyItem.get(document.items);
|
|
7930
|
+
if (!all) {
|
|
7931
|
+
all = new Set(Object.keys(document.items));
|
|
7932
|
+
everyItem.set(document.items, all);
|
|
7933
|
+
}
|
|
7934
|
+
return all;
|
|
7935
|
+
}
|
|
7936
|
+
const item = document.items[id];
|
|
7937
|
+
const scope = /* @__PURE__ */ new Set([id]);
|
|
7938
|
+
for (const target of Object.values(item?.script?.targets ?? {})) if (document.items[target]) scope.add(target);
|
|
7939
|
+
if (item?.type !== "frame") return scope;
|
|
7940
|
+
const children = childIndex(document.items);
|
|
7941
|
+
const visited = /* @__PURE__ */ new Set([id]);
|
|
7942
|
+
const queue = [id];
|
|
7943
|
+
for (let depth = 0; queue.length && depth < 64; depth++) for (const parent of queue.splice(0)) for (const child of children.get(parent) ?? []) {
|
|
7944
|
+
if (visited.has(child)) continue;
|
|
7945
|
+
visited.add(child);
|
|
7946
|
+
scope.add(child);
|
|
7947
|
+
queue.push(child);
|
|
7948
|
+
}
|
|
7949
|
+
return scope;
|
|
7950
|
+
}
|
|
7951
|
+
function diffBoardScriptItems(copy, document, scope, note) {
|
|
7952
|
+
const changes = {};
|
|
7953
|
+
let changed = false;
|
|
7954
|
+
for (const id of scope) {
|
|
7955
|
+
const item = document.items[id];
|
|
7956
|
+
const previous = copy.get(id);
|
|
7957
|
+
if (!item || previous === item) continue;
|
|
7958
|
+
copy.set(id, item);
|
|
7959
|
+
if (previous && sameJson(previous, item)) continue;
|
|
7960
|
+
changes[id] = item;
|
|
7961
|
+
changed = true;
|
|
7962
|
+
note?.(id, previous ? "changed" : "added");
|
|
7963
|
+
}
|
|
7964
|
+
if (copy.size > scope.size) for (const id of copy.keys()) {
|
|
7965
|
+
if (scope.has(id)) continue;
|
|
7966
|
+
copy.delete(id);
|
|
7967
|
+
changes[id] = null;
|
|
7968
|
+
changed = true;
|
|
7969
|
+
note?.(id, "removed");
|
|
7970
|
+
}
|
|
7971
|
+
return changed ? changes : null;
|
|
7972
|
+
}
|
|
7973
|
+
function supersedes(pending, event) {
|
|
7974
|
+
if (pending.type !== event.type) return false;
|
|
7975
|
+
if (event.type === "viewchange" || event.type === "selectionchange") return true;
|
|
7976
|
+
if (event.type === "pointermove") return pending.pointerId === event.pointerId;
|
|
7977
|
+
if (event.type !== "gesture") return false;
|
|
7978
|
+
const a = pending.data;
|
|
7979
|
+
const b = event.data;
|
|
7980
|
+
return a.id === b.id && a.phase === "update" && b.phase === "update";
|
|
7981
|
+
}
|
|
7982
|
+
function boardScriptListens(output, event) {
|
|
7983
|
+
return !output || event.type === "viewchange" || output.listens.includes(event.type);
|
|
7984
|
+
}
|
|
7985
|
+
function queueBoardScriptEvent(queue, event) {
|
|
7986
|
+
let queued = queue.length - 1;
|
|
7987
|
+
while (queued >= 0 && !supersedes(queue[queued], event)) queued--;
|
|
7988
|
+
if (queued >= 0 && (event.type !== "pointermove" || queued === queue.length - 1)) queue.splice(queued, 1);
|
|
7989
|
+
if (queue.length >= 128) return false;
|
|
7990
|
+
queue.push(event);
|
|
7991
|
+
return true;
|
|
7992
|
+
}
|
|
7993
|
+
function boardScriptEmit(document, sender, input) {
|
|
7994
|
+
const message = input;
|
|
7995
|
+
if (!message || typeof message.target !== "string" || typeof message.type !== "string" || !message.type) throw new Error("emit() takes a target id and an event type.");
|
|
7996
|
+
const { target, type } = message;
|
|
7997
|
+
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.`);
|
|
7998
|
+
const depth = typeof message.depth === "number" && Number.isSafeInteger(message.depth) && message.depth > 0 ? message.depth : 1;
|
|
7999
|
+
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.`);
|
|
8000
|
+
return {
|
|
8001
|
+
target,
|
|
8002
|
+
event: {
|
|
8003
|
+
type,
|
|
8004
|
+
data: message.data,
|
|
8005
|
+
depth
|
|
8006
|
+
}
|
|
8007
|
+
};
|
|
8008
|
+
}
|
|
8009
|
+
function createBoardScriptOutbox(order) {
|
|
8010
|
+
let queued = [];
|
|
8011
|
+
let seq = 0;
|
|
8012
|
+
const waiting = /* @__PURE__ */ new Map();
|
|
8013
|
+
return {
|
|
8014
|
+
get size() {
|
|
8015
|
+
return queued.length;
|
|
8016
|
+
},
|
|
8017
|
+
push(sender, target, event) {
|
|
8018
|
+
const count = waiting.get(target) ?? 0;
|
|
8019
|
+
if (count >= 128) throw new Error(`emit(${target}, "${event.type}") from ${sender}: ${target} already has 128 events waiting.`);
|
|
8020
|
+
waiting.set(target, count + 1);
|
|
8021
|
+
queued.push({
|
|
8022
|
+
rank: order().get(sender) ?? Number.MAX_SAFE_INTEGER,
|
|
8023
|
+
seq: seq++,
|
|
8024
|
+
target,
|
|
8025
|
+
event
|
|
8026
|
+
});
|
|
8027
|
+
},
|
|
8028
|
+
take() {
|
|
8029
|
+
const batch = queued.sort((a, b) => a.rank - b.rank || a.seq - b.seq);
|
|
8030
|
+
queued = [];
|
|
8031
|
+
waiting.clear();
|
|
8032
|
+
const byTarget = /* @__PURE__ */ new Map();
|
|
8033
|
+
for (const { target, event } of batch) byTarget.set(target, [...byTarget.get(target) ?? [], event]);
|
|
8034
|
+
return byTarget;
|
|
8035
|
+
}
|
|
8036
|
+
};
|
|
8037
|
+
}
|
|
8038
|
+
//#endregion
|
|
7884
8039
|
//#region ../sdk/src/board/model/geometry.ts
|
|
7885
8040
|
function worldPoint(x, y) {
|
|
7886
8041
|
return {
|
|
@@ -8021,100 +8176,13 @@ function cameraForFocus(focus, getFrame, surface, options = {}) {
|
|
|
8021
8176
|
return rect ? cameraForRect(rect, surface, options) : null;
|
|
8022
8177
|
}
|
|
8023
8178
|
//#endregion
|
|
8024
|
-
//#region ../sdk/src/board/model/json.ts
|
|
8025
|
-
function sameJson(a, b) {
|
|
8026
|
-
if (a === b) return true;
|
|
8027
|
-
if (!a || !b || typeof a !== "object" || typeof b !== "object") return false;
|
|
8028
|
-
if (Array.isArray(a) || Array.isArray(b)) {
|
|
8029
|
-
if (!Array.isArray(a) || !Array.isArray(b) || a.length !== b.length) return false;
|
|
8030
|
-
for (let index = 0; index < a.length; index += 1) if (!sameJson(a[index], b[index])) return false;
|
|
8031
|
-
return true;
|
|
8032
|
-
}
|
|
8033
|
-
const left = a;
|
|
8034
|
-
const right = b;
|
|
8035
|
-
let members = 0;
|
|
8036
|
-
for (const key of Object.keys(left)) {
|
|
8037
|
-
if (left[key] === void 0) continue;
|
|
8038
|
-
members += 1;
|
|
8039
|
-
if (!sameJson(left[key], right[key])) return false;
|
|
8040
|
-
}
|
|
8041
|
-
for (const key of Object.keys(right)) if (right[key] !== void 0) members -= 1;
|
|
8042
|
-
return members === 0;
|
|
8043
|
-
}
|
|
8044
|
-
//#endregion
|
|
8045
|
-
//#region ../sdk/src/board/model/script-scope.ts
|
|
8046
|
-
const childrenByItems = /* @__PURE__ */ new WeakMap();
|
|
8047
|
-
const everyItem = /* @__PURE__ */ new WeakMap();
|
|
8048
|
-
function childIndex(items) {
|
|
8049
|
-
let index = childrenByItems.get(items);
|
|
8050
|
-
if (!index) {
|
|
8051
|
-
index = /* @__PURE__ */ new Map();
|
|
8052
|
-
for (const [id, item] of Object.entries(items)) {
|
|
8053
|
-
if (!item.parent) continue;
|
|
8054
|
-
const siblings = index.get(item.parent);
|
|
8055
|
-
if (siblings) siblings.push(id);
|
|
8056
|
-
else index.set(item.parent, [id]);
|
|
8057
|
-
}
|
|
8058
|
-
childrenByItems.set(items, index);
|
|
8059
|
-
}
|
|
8060
|
-
return index;
|
|
8061
|
-
}
|
|
8062
|
-
function boardScriptOf(document, id) {
|
|
8063
|
-
return isBoardRootScript(document, id) ? document.board?.scripts?.[id] : document.items[id]?.script;
|
|
8064
|
-
}
|
|
8065
|
-
function boardScriptScope(document, id) {
|
|
8066
|
-
if (isBoardRootScript(document, id)) {
|
|
8067
|
-
let all = everyItem.get(document.items);
|
|
8068
|
-
if (!all) {
|
|
8069
|
-
all = new Set(Object.keys(document.items));
|
|
8070
|
-
everyItem.set(document.items, all);
|
|
8071
|
-
}
|
|
8072
|
-
return all;
|
|
8073
|
-
}
|
|
8074
|
-
const item = document.items[id];
|
|
8075
|
-
const scope = /* @__PURE__ */ new Set([id]);
|
|
8076
|
-
for (const target of Object.values(item?.script?.targets ?? {})) if (document.items[target]) scope.add(target);
|
|
8077
|
-
if (item?.type !== "frame") return scope;
|
|
8078
|
-
const children = childIndex(document.items);
|
|
8079
|
-
const visited = /* @__PURE__ */ new Set([id]);
|
|
8080
|
-
const queue = [id];
|
|
8081
|
-
for (let depth = 0; queue.length && depth < 64; depth++) for (const parent of queue.splice(0)) for (const child of children.get(parent) ?? []) {
|
|
8082
|
-
if (visited.has(child)) continue;
|
|
8083
|
-
visited.add(child);
|
|
8084
|
-
scope.add(child);
|
|
8085
|
-
queue.push(child);
|
|
8086
|
-
}
|
|
8087
|
-
return scope;
|
|
8088
|
-
}
|
|
8089
|
-
function diffBoardScriptItems(copy, document, scope, note) {
|
|
8090
|
-
const changes = {};
|
|
8091
|
-
let changed = false;
|
|
8092
|
-
for (const id of scope) {
|
|
8093
|
-
const item = document.items[id];
|
|
8094
|
-
const previous = copy.get(id);
|
|
8095
|
-
if (!item || previous === item) continue;
|
|
8096
|
-
copy.set(id, item);
|
|
8097
|
-
if (previous && sameJson(previous, item)) continue;
|
|
8098
|
-
changes[id] = item;
|
|
8099
|
-
changed = true;
|
|
8100
|
-
note?.(id, previous ? "changed" : "added");
|
|
8101
|
-
}
|
|
8102
|
-
if (copy.size > scope.size) for (const id of copy.keys()) {
|
|
8103
|
-
if (scope.has(id)) continue;
|
|
8104
|
-
copy.delete(id);
|
|
8105
|
-
changes[id] = null;
|
|
8106
|
-
changed = true;
|
|
8107
|
-
note?.(id, "removed");
|
|
8108
|
-
}
|
|
8109
|
-
return changed ? changes : null;
|
|
8110
|
-
}
|
|
8111
|
-
//#endregion
|
|
8112
8179
|
//#region ../sdk/src/board/model/shader.ts
|
|
8113
8180
|
const BOARD_SHADER_LIMITS = {
|
|
8114
|
-
passes:
|
|
8181
|
+
passes: 16,
|
|
8115
8182
|
source: 65536,
|
|
8116
8183
|
sprites: 65536,
|
|
8117
8184
|
stateEdge: 1024,
|
|
8185
|
+
texel: 1024,
|
|
8118
8186
|
uniformSlots: 128
|
|
8119
8187
|
};
|
|
8120
8188
|
const COMPONENTS = {
|
|
@@ -8189,6 +8257,10 @@ function validateBoardShader(shader) {
|
|
|
8189
8257
|
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}.`);
|
|
8190
8258
|
if (boardShaderPassLayer(value, pass) === "filter") throw new Error("Filter passes draw over the owner's box; they cannot draw sprites.");
|
|
8191
8259
|
}
|
|
8260
|
+
if (pass.texel !== void 0) {
|
|
8261
|
+
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}.`);
|
|
8262
|
+
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.");
|
|
8263
|
+
}
|
|
8192
8264
|
if (pass.name !== void 0) {
|
|
8193
8265
|
if (typeof pass.name !== "string" || !IDENTIFIER.test(pass.name)) throw new Error(`Invalid pass name: ${String(pass.name)}`);
|
|
8194
8266
|
if (names.has(pass.name)) throw new Error(`Pass names must be unique: ${pass.name}`);
|
|
@@ -8233,6 +8305,33 @@ function parseBoardItem(value) {
|
|
|
8233
8305
|
if (!parsed.ok) throw new Error(parsed.diagnostics[0]?.message ?? "Invalid script item.");
|
|
8234
8306
|
return parsed.item;
|
|
8235
8307
|
}
|
|
8308
|
+
function presentItem(base, patch) {
|
|
8309
|
+
return presentTransform(base, patch) ?? parseBoardItem(mergePatch(base, patch));
|
|
8310
|
+
}
|
|
8311
|
+
function presentTransform(base, patch) {
|
|
8312
|
+
const next = { ...base };
|
|
8313
|
+
for (const key in patch) {
|
|
8314
|
+
const value = patch[key];
|
|
8315
|
+
if (key === "position") {
|
|
8316
|
+
if (!value || typeof value !== "object") return null;
|
|
8317
|
+
const { x = base.position.x, y = base.position.y, ...rest } = value;
|
|
8318
|
+
if (!Number.isFinite(x) || !Number.isFinite(y)) return null;
|
|
8319
|
+
for (const _ in rest) return null;
|
|
8320
|
+
next.position = {
|
|
8321
|
+
x,
|
|
8322
|
+
y
|
|
8323
|
+
};
|
|
8324
|
+
continue;
|
|
8325
|
+
}
|
|
8326
|
+
if (key === "rotation" || key === "z") {
|
|
8327
|
+
if (!Number.isFinite(value)) return null;
|
|
8328
|
+
} else if (key === "opacity") {
|
|
8329
|
+
if (typeof value !== "number" || !(value >= 0 && value <= 1)) return null;
|
|
8330
|
+
} else if (key !== "visible" || typeof value !== "boolean") return null;
|
|
8331
|
+
next[key] = value;
|
|
8332
|
+
}
|
|
8333
|
+
return next;
|
|
8334
|
+
}
|
|
8236
8335
|
const DISPLAY_FIELDS = /* @__PURE__ */ new Set([
|
|
8237
8336
|
"position",
|
|
8238
8337
|
"size",
|
|
@@ -8388,7 +8487,7 @@ function prepareBoardScriptOutput(document, owner, output) {
|
|
|
8388
8487
|
const base = document.items[id];
|
|
8389
8488
|
if (base && scope.has(id)) presented.set(id, {
|
|
8390
8489
|
base,
|
|
8391
|
-
item:
|
|
8490
|
+
item: presentItem(base, patch)
|
|
8392
8491
|
});
|
|
8393
8492
|
}
|
|
8394
8493
|
const prefix = scriptTemporaryPrefix(owner);
|
|
@@ -8420,7 +8519,7 @@ function composeBoardScriptItems(document, scene, outputs, incoming = /* @__PURE
|
|
|
8420
8519
|
if (current.base !== base) {
|
|
8421
8520
|
current = {
|
|
8422
8521
|
base,
|
|
8423
|
-
item:
|
|
8522
|
+
item: presentItem(base, output.patches[id] ?? {})
|
|
8424
8523
|
};
|
|
8425
8524
|
prepared.presented.set(id, current);
|
|
8426
8525
|
}
|
|
@@ -9943,9 +10042,10 @@ function resolveRegion(scene, region) {
|
|
|
9943
10042
|
};
|
|
9944
10043
|
const rect = itemBounds(frame.frame);
|
|
9945
10044
|
return {
|
|
9946
|
-
items: scene.items.filter((item) => item.id
|
|
10045
|
+
items: scene.items.filter((item) => item.id === region.id || visible(item, rect)),
|
|
9947
10046
|
rect,
|
|
9948
|
-
padding: 0
|
|
10047
|
+
padding: 0,
|
|
10048
|
+
page: region.id
|
|
9949
10049
|
};
|
|
9950
10050
|
}
|
|
9951
10051
|
case "rect": {
|
|
@@ -9983,7 +10083,26 @@ function planBoardExport(input) {
|
|
|
9983
10083
|
width: Math.max(1, Math.floor(world.width * scale)),
|
|
9984
10084
|
height: Math.max(1, Math.floor(world.height * scale)),
|
|
9985
10085
|
items: resolved.items,
|
|
9986
|
-
clamped: scale < safeRequest - 1e-6
|
|
10086
|
+
clamped: scale < safeRequest - 1e-6,
|
|
10087
|
+
...resolved.page ? { page: resolved.page } : {}
|
|
10088
|
+
};
|
|
10089
|
+
}
|
|
10090
|
+
function boardExportView(plan) {
|
|
10091
|
+
const { world, scale, width, height } = plan;
|
|
10092
|
+
return {
|
|
10093
|
+
camera: {
|
|
10094
|
+
x: -world.x * scale,
|
|
10095
|
+
y: -world.y * scale,
|
|
10096
|
+
zoom: scale
|
|
10097
|
+
},
|
|
10098
|
+
width,
|
|
10099
|
+
height,
|
|
10100
|
+
safeRect: {
|
|
10101
|
+
x: 0,
|
|
10102
|
+
y: 0,
|
|
10103
|
+
width,
|
|
10104
|
+
height
|
|
10105
|
+
}
|
|
9987
10106
|
};
|
|
9988
10107
|
}
|
|
9989
10108
|
//#endregion
|
|
@@ -62313,6 +62432,7 @@ function shaderPasses() {
|
|
|
62313
62432
|
return passes;
|
|
62314
62433
|
}
|
|
62315
62434
|
const TEXELS_PER_DEVIATION = 4;
|
|
62435
|
+
const SAMPLED_TEXELS_PER_DEVIATION = 8;
|
|
62316
62436
|
const MAX_HALVINGS = 5;
|
|
62317
62437
|
function gaussian(filters, input, output, deviation, clear, first) {
|
|
62318
62438
|
const { horizontal, vertical, copy } = shaderPasses();
|
|
@@ -62358,6 +62478,7 @@ var BoardBlurFilter = class extends Filter {
|
|
|
62358
62478
|
this.radius = radius;
|
|
62359
62479
|
this.deviation = radius * zoom;
|
|
62360
62480
|
this.padding = Math.ceil(radius * 3 * zoom);
|
|
62481
|
+
this.resolution = this.deviation > SAMPLED_TEXELS_PER_DEVIATION ? SAMPLED_TEXELS_PER_DEVIATION / this.deviation : "inherit";
|
|
62361
62482
|
this.css = `blur(${radius * zoom}px)`;
|
|
62362
62483
|
}
|
|
62363
62484
|
apply(filters, input, output, clearMode) {
|
|
@@ -62646,6 +62767,27 @@ function syncFrameGroup(entry, item, context) {
|
|
|
62646
62767
|
function syncBoardItemEffects(container, item, context) {
|
|
62647
62768
|
syncBoardEffects(container, item.type === "frame" ? void 0 : item.style, context);
|
|
62648
62769
|
}
|
|
62770
|
+
const shaderClips = /* @__PURE__ */ new WeakMap();
|
|
62771
|
+
function clipFrameShaderLayer(layer, item) {
|
|
62772
|
+
const entry = shaderClips.get(layer);
|
|
62773
|
+
if (!isClippingFrame(item)) {
|
|
62774
|
+
if (!entry) return;
|
|
62775
|
+
layer.mask = null;
|
|
62776
|
+
entry.mask.destroy();
|
|
62777
|
+
shaderClips.delete(layer);
|
|
62778
|
+
return;
|
|
62779
|
+
}
|
|
62780
|
+
const { width, height } = item.frame;
|
|
62781
|
+
const sig = `${width},${height}`;
|
|
62782
|
+
if (entry?.sig === sig) return;
|
|
62783
|
+
const mask = entry?.mask ?? layer.addChild(new Graphics());
|
|
62784
|
+
mask.clear().rect(0, 0, width, height).fill(16777215);
|
|
62785
|
+
layer.mask = mask;
|
|
62786
|
+
shaderClips.set(layer, {
|
|
62787
|
+
mask,
|
|
62788
|
+
sig
|
|
62789
|
+
});
|
|
62790
|
+
}
|
|
62649
62791
|
//#endregion
|
|
62650
62792
|
//#region ../sdk/src/board/render/audio-waveform.ts
|
|
62651
62793
|
const DEFAULT_BARS = 44;
|
|
@@ -63378,10 +63520,12 @@ function sync$13(container, item, context) {
|
|
|
63378
63520
|
const failed = Boolean(key && !texture && context.hasError(key));
|
|
63379
63521
|
const detailed = boardCardDetailed(context.zoom);
|
|
63380
63522
|
const elevation = cardElevation(context, item.id);
|
|
63523
|
+
const covered = context.covered?.(item.id) ?? false;
|
|
63381
63524
|
const sig = [
|
|
63382
63525
|
key ?? "",
|
|
63383
63526
|
texture?.uid ?? "none",
|
|
63384
63527
|
failed,
|
|
63528
|
+
covered,
|
|
63385
63529
|
width,
|
|
63386
63530
|
height,
|
|
63387
63531
|
elevation,
|
|
@@ -63402,7 +63546,11 @@ function sync$13(container, item, context) {
|
|
|
63402
63546
|
elevation
|
|
63403
63547
|
});
|
|
63404
63548
|
if (texture && parts.sprite.texture !== texture) parts.sprite.texture = texture;
|
|
63405
|
-
parts.sprite.visible = Boolean(texture);
|
|
63549
|
+
parts.sprite.visible = Boolean(texture) && !covered;
|
|
63550
|
+
if (covered) {
|
|
63551
|
+
parts.chrome.clear();
|
|
63552
|
+
return;
|
|
63553
|
+
}
|
|
63406
63554
|
if (texture) {
|
|
63407
63555
|
const inset = Math.min(width, height) * INSET_RATIO;
|
|
63408
63556
|
const fitted = containRect(width - inset * 2, height - inset * 2, texture.width, texture.height);
|
|
@@ -63511,6 +63659,7 @@ const PLAY_HIT = {
|
|
|
63511
63659
|
cursor: "pointer"
|
|
63512
63660
|
};
|
|
63513
63661
|
function mediaPlayHit(item, point, context) {
|
|
63662
|
+
if (context.covered?.(item.id) || context.mediaTexture?.(item.id)) return null;
|
|
63514
63663
|
const key = context.assetKey(item);
|
|
63515
63664
|
return boardMediaActionAt(item, point, context.zoom, {
|
|
63516
63665
|
materialized: true,
|
|
@@ -64405,9 +64554,12 @@ function sync$8(container, item, context) {
|
|
|
64405
64554
|
const alpha = (style.stroke ? 1 : .55) * itemAlpha(context, style.stroke);
|
|
64406
64555
|
const radius = style.radius ?? 4;
|
|
64407
64556
|
const strokeWidth = style.strokeWidth ?? 1.5;
|
|
64408
|
-
const
|
|
64557
|
+
const page = context.page === item.id;
|
|
64558
|
+
const decorated = props.decoration !== "none" && (!page || style.fill !== void 0);
|
|
64559
|
+
const outlined = decorated && !page;
|
|
64409
64560
|
const visualSig = [
|
|
64410
64561
|
props.decoration,
|
|
64562
|
+
page,
|
|
64411
64563
|
frame.width,
|
|
64412
64564
|
frame.height,
|
|
64413
64565
|
fill,
|
|
@@ -64428,7 +64580,7 @@ function sync$8(container, item, context) {
|
|
|
64428
64580
|
});
|
|
64429
64581
|
const pattern = dashPattern(style.dash, strokeWidth);
|
|
64430
64582
|
const trim = style.trim ?? 1;
|
|
64431
|
-
if (
|
|
64583
|
+
if (outlined && strokeWidth > 0 && trim > 0) {
|
|
64432
64584
|
if (pattern || trim < 1) tracePolyline(parts.box, trimPolyline(roundRectPoints(frame.width, frame.height, radius), trim), pattern);
|
|
64433
64585
|
else parts.box.roundRect(0, 0, frame.width, frame.height, radius);
|
|
64434
64586
|
parts.box.stroke({
|
|
@@ -64440,7 +64592,7 @@ function sync$8(container, item, context) {
|
|
|
64440
64592
|
});
|
|
64441
64593
|
}
|
|
64442
64594
|
}
|
|
64443
|
-
parts.label.visible =
|
|
64595
|
+
parts.label.visible = outlined;
|
|
64444
64596
|
const title = locked ? `🔒 ${props.label}`.trim() : props.label;
|
|
64445
64597
|
const labelColor = style.stroke ? baseStroke : context.palette.muted;
|
|
64446
64598
|
const size = context.style.frameLabelSize;
|
|
@@ -65543,7 +65695,8 @@ function sync$3(container, item, context) {
|
|
|
65543
65695
|
parts.assetKey = key;
|
|
65544
65696
|
if (key) context.acquireTexture(key, item);
|
|
65545
65697
|
}
|
|
65546
|
-
const
|
|
65698
|
+
const live = context.mediaTexture?.(item.id) ?? null;
|
|
65699
|
+
const texture = live ?? (key ? context.getTexture(key) : null);
|
|
65547
65700
|
const previewFailed = Boolean(key && !texture && context.hasError(key));
|
|
65548
65701
|
const artifact = featuredTaskArtifact(snapshot.artifacts);
|
|
65549
65702
|
const kind = previewKindFor(artifact);
|
|
@@ -65651,7 +65804,7 @@ function sync$3(container, item, context) {
|
|
|
65651
65804
|
height: Math.max(1, frame.height - 24 - bottomInset)
|
|
65652
65805
|
}, context.colors.brand.stroke);
|
|
65653
65806
|
}
|
|
65654
|
-
if (full && (artifact?.type === "audio" || artifact?.type === "video" && texture)) drawPlayBadge(parts.previewArt, frame, context);
|
|
65807
|
+
if (full && (artifact?.type === "audio" || artifact?.type === "video" && texture && !live)) drawPlayBadge(parts.previewArt, frame, context);
|
|
65655
65808
|
if (surface) {
|
|
65656
65809
|
const markY = frame.y + frame.height / 2 - (full && label ? 18 : 0);
|
|
65657
65810
|
drawStateMark(parts.previewArt, surface, frame.x + frame.width / 2, markY, surface === "failed" ? color : context.colors.neutral.stroke);
|
|
@@ -66215,7 +66368,7 @@ function sync(container, item, context) {
|
|
|
66215
66368
|
} : context.style);
|
|
66216
66369
|
}
|
|
66217
66370
|
parts.chrome.clear();
|
|
66218
|
-
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);
|
|
66371
|
+
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);
|
|
66219
66372
|
}
|
|
66220
66373
|
function drawFilmRails(graphics, width, height, rail, hole) {
|
|
66221
66374
|
const size = Math.min(FILM_HOLE, rail * .45);
|
|
@@ -66621,6 +66774,7 @@ const itemEnvelope = {
|
|
|
66621
66774
|
visible: boolean().optional().describe("false hides the item and its children; key it on a timeline to show the item only for a span."),
|
|
66622
66775
|
style: BoardStyleSchema.default({}),
|
|
66623
66776
|
locked: boolean().optional(),
|
|
66777
|
+
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."),
|
|
66624
66778
|
metadata: record(string(), unknown()).optional()
|
|
66625
66779
|
};
|
|
66626
66780
|
const boxed = (size) => ({
|
|
@@ -67198,9 +67352,12 @@ function resolveScriptImport(from, specifier) {
|
|
|
67198
67352
|
} else parts.push(part);
|
|
67199
67353
|
}
|
|
67200
67354
|
const path = parts.join("/");
|
|
67201
|
-
if (!isSafeBoardSourcePath(path) || !/\.m?js$/.test(path)) throw new Error(`Invalid module path: ${path}`);
|
|
67355
|
+
if (!isSafeBoardSourcePath(path) || !/\.(m?js|json)$/.test(path)) throw new Error(`Invalid module path: ${path}`);
|
|
67202
67356
|
return path;
|
|
67203
67357
|
}
|
|
67358
|
+
function isBoardScriptJson(path) {
|
|
67359
|
+
return path.endsWith(".json");
|
|
67360
|
+
}
|
|
67204
67361
|
async function loadBoardScriptSources(src, read, timeoutMs = 15e3) {
|
|
67205
67362
|
if (!isSafeBoardSourcePath(src) || !/\.m?js$/.test(src)) throw new Error("Invalid script entry path.");
|
|
67206
67363
|
const { init, parse } = await Promise.resolve().then(() => (init_lexer(), lexer_exports));
|
|
@@ -67220,11 +67377,25 @@ async function loadBoardScriptSources(src, read, timeoutMs = 15e3) {
|
|
|
67220
67377
|
})]).finally(() => clearTimeout(timer));
|
|
67221
67378
|
bytes += new TextEncoder().encode(code).byteLength;
|
|
67222
67379
|
if (bytes > 2e6) throw new Error("Script modules exceed the 2 MB limit.");
|
|
67380
|
+
if (isBoardScriptJson(path)) {
|
|
67381
|
+
try {
|
|
67382
|
+
JSON.parse(code);
|
|
67383
|
+
} catch {
|
|
67384
|
+
throw new Error(`${path} is not valid JSON.`);
|
|
67385
|
+
}
|
|
67386
|
+
sources[path] = {
|
|
67387
|
+
code,
|
|
67388
|
+
imports: []
|
|
67389
|
+
};
|
|
67390
|
+
return;
|
|
67391
|
+
}
|
|
67223
67392
|
const [imports] = parse(code, path);
|
|
67224
67393
|
const resolved = [];
|
|
67225
67394
|
for (const entry of imports) {
|
|
67226
67395
|
if (entry.d === -2) throw new Error("import.meta is not available in Board scripts.");
|
|
67227
67396
|
if (entry.n === void 0) throw new Error("Dynamic imports must use a literal relative path.");
|
|
67397
|
+
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"));
|
|
67398
|
+
if (typed !== isBoardScriptJson(entry.n)) throw new Error(typed ? `Only .json files import with type "json": ${entry.n}` : `Import ${entry.n} with { type: "json" }.`);
|
|
67228
67399
|
resolved.push({
|
|
67229
67400
|
start: entry.s,
|
|
67230
67401
|
end: entry.e,
|
|
@@ -67253,21 +67424,46 @@ async function loadBoardScriptSources(src, read, timeoutMs = 15e3) {
|
|
|
67253
67424
|
await load(src);
|
|
67254
67425
|
return sources;
|
|
67255
67426
|
}
|
|
67256
|
-
function scriptModuleUrls(sources) {
|
|
67427
|
+
function scriptModuleUrls(sources, shared = /* @__PURE__ */ new Map()) {
|
|
67257
67428
|
const urls = {};
|
|
67429
|
+
const owned = [];
|
|
67430
|
+
const held = [];
|
|
67258
67431
|
for (const [path, source] of Object.entries(sources)) {
|
|
67432
|
+
if (path.endsWith(".json")) {
|
|
67433
|
+
const key = `${path}\n${source.code}`;
|
|
67434
|
+
let json = shared.get(key);
|
|
67435
|
+
if (!json) {
|
|
67436
|
+
json = {
|
|
67437
|
+
url: URL.createObjectURL(new Blob([source.code], { type: "application/json" })),
|
|
67438
|
+
users: 0
|
|
67439
|
+
};
|
|
67440
|
+
shared.set(key, json);
|
|
67441
|
+
}
|
|
67442
|
+
json.users++;
|
|
67443
|
+
held.push(key);
|
|
67444
|
+
urls[path] = json.url;
|
|
67445
|
+
continue;
|
|
67446
|
+
}
|
|
67259
67447
|
let code = source.code;
|
|
67260
67448
|
for (const entry of [...source.imports].reverse()) {
|
|
67261
67449
|
const url = urls[entry.path];
|
|
67262
67450
|
if (!url) throw new Error(`Unresolved module: ${entry.path}`);
|
|
67263
67451
|
code = code.slice(0, entry.start) + (entry.dynamic ? JSON.stringify(url) : url) + code.slice(entry.end);
|
|
67264
67452
|
}
|
|
67265
|
-
|
|
67453
|
+
const url = URL.createObjectURL(new Blob([`${code}\n//# sourceURL=cohub-script/${path.split("/").map(encodeURIComponent).join("/")}`], { type: "text/javascript" }));
|
|
67454
|
+
urls[path] = url;
|
|
67455
|
+
owned.push(url);
|
|
67266
67456
|
}
|
|
67267
67457
|
return {
|
|
67268
67458
|
urls,
|
|
67269
67459
|
dispose: () => {
|
|
67270
|
-
for (const url of
|
|
67460
|
+
for (const url of owned) URL.revokeObjectURL(url);
|
|
67461
|
+
for (const key of held) {
|
|
67462
|
+
const json = shared.get(key);
|
|
67463
|
+
if (!json || --json.users > 0) continue;
|
|
67464
|
+
URL.revokeObjectURL(json.url);
|
|
67465
|
+
shared.delete(key);
|
|
67466
|
+
}
|
|
67271
67467
|
}
|
|
67272
67468
|
};
|
|
67273
67469
|
}
|
|
@@ -67303,6 +67499,7 @@ function createScriptRuntime(module, initial, host) {
|
|
|
67303
67499
|
let input = initial;
|
|
67304
67500
|
let disposed = false;
|
|
67305
67501
|
let stepping = false;
|
|
67502
|
+
let depth = 0;
|
|
67306
67503
|
let revision = 0;
|
|
67307
67504
|
let sceneRevision = 0;
|
|
67308
67505
|
let randomState = 2166136261;
|
|
@@ -67378,7 +67575,8 @@ function createScriptRuntime(module, initial, host) {
|
|
|
67378
67575
|
await host.call("board.emit", {
|
|
67379
67576
|
target,
|
|
67380
67577
|
type,
|
|
67381
|
-
data
|
|
67578
|
+
data,
|
|
67579
|
+
depth: depth + 1
|
|
67382
67580
|
});
|
|
67383
67581
|
},
|
|
67384
67582
|
get items() {
|
|
@@ -67548,9 +67746,15 @@ function createScriptRuntime(module, initial, host) {
|
|
|
67548
67746
|
if (event.type === "viewchange") view = event.data;
|
|
67549
67747
|
const listeners = handlers.get(event.type);
|
|
67550
67748
|
if (!listeners?.size) return;
|
|
67551
|
-
|
|
67552
|
-
|
|
67553
|
-
|
|
67749
|
+
const outer = depth;
|
|
67750
|
+
depth = event.depth ?? 0;
|
|
67751
|
+
try {
|
|
67752
|
+
seeded(() => {
|
|
67753
|
+
for (const handler of listeners) handler(event);
|
|
67754
|
+
});
|
|
67755
|
+
} finally {
|
|
67756
|
+
depth = outer;
|
|
67757
|
+
}
|
|
67554
67758
|
invalidate();
|
|
67555
67759
|
},
|
|
67556
67760
|
draw(canvas) {
|
|
@@ -67613,6 +67817,7 @@ function createScriptRuntime(module, initial, host) {
|
|
|
67613
67817
|
//#region ../sdk/src/board/render/script-sandbox.ts
|
|
67614
67818
|
function scriptAgent(runtimeFactory, applyDelta, moduleUrls, load) {
|
|
67615
67819
|
const graphs = /* @__PURE__ */ new Map();
|
|
67820
|
+
const json = /* @__PURE__ */ new Map();
|
|
67616
67821
|
const instances = /* @__PURE__ */ new Map();
|
|
67617
67822
|
const calls = /* @__PURE__ */ new Map();
|
|
67618
67823
|
let callId = 0;
|
|
@@ -67626,6 +67831,16 @@ function scriptAgent(runtimeFactory, applyDelta, moduleUrls, load) {
|
|
|
67626
67831
|
announced = false;
|
|
67627
67832
|
send({ kind: "idle" });
|
|
67628
67833
|
};
|
|
67834
|
+
const freeze = (value) => {
|
|
67835
|
+
if (!value || typeof value !== "object" || Object.isFrozen(value)) return;
|
|
67836
|
+
Object.freeze(value);
|
|
67837
|
+
for (const child of Object.values(value)) freeze(child);
|
|
67838
|
+
};
|
|
67839
|
+
let jsonReader = null;
|
|
67840
|
+
const readJson = async (url) => {
|
|
67841
|
+
jsonReader ??= load(URL.createObjectURL(new Blob(["export default (url) => import(url, { with: { type: \"json\" } });"], { type: "text/javascript" }))).then((module) => module.default);
|
|
67842
|
+
return (await (await jsonReader)(url)).default;
|
|
67843
|
+
};
|
|
67629
67844
|
const describe = (error) => error instanceof Error ? error.stack ?? error.message : String(error);
|
|
67630
67845
|
function destroy(token) {
|
|
67631
67846
|
const instance = instances.get(token);
|
|
@@ -67659,10 +67874,11 @@ function scriptAgent(runtimeFactory, applyDelta, moduleUrls, load) {
|
|
|
67659
67874
|
if (!instance.runtime) {
|
|
67660
67875
|
const sources = data.graph ? graphs.get(data.graph) : void 0;
|
|
67661
67876
|
if (!sources) throw new Error("Missing script modules.");
|
|
67662
|
-
instance.urls = moduleUrls(sources);
|
|
67877
|
+
instance.urls = moduleUrls(sources, json);
|
|
67663
67878
|
const src = input.script.src;
|
|
67664
67879
|
const url = src ? instance.urls.urls[src] : void 0;
|
|
67665
67880
|
if (!url) throw new Error("Missing entry module.");
|
|
67881
|
+
for (const [path, url] of Object.entries(instance.urls.urls)) if (path.endsWith(".json")) freeze(await readJson(url));
|
|
67666
67882
|
instance.module = await load(url);
|
|
67667
67883
|
if (instances.get(token) !== instance) throw new Error("Script stopped.");
|
|
67668
67884
|
current = token;
|
|
@@ -67941,7 +68157,7 @@ function boardScriptFrameSource(options = {}) {
|
|
|
67941
68157
|
const worker = `${prelude} (${scriptAgent.toString()})(${createScriptRuntime.toString()}, ${applyScriptInputDelta.toString()}, ${scriptModuleUrls.toString()}, url => import(url));`;
|
|
67942
68158
|
const cores = typeof navigator === "undefined" ? 4 : navigator.hardwareConcurrency || 4;
|
|
67943
68159
|
const poolSize = options.poolSize ?? Math.max(1, Math.min(4, cores - 1));
|
|
67944
|
-
return `<!doctype html><meta http-equiv="Content-Security-Policy" content="default-src 'none'; script-src 'unsafe-inline' blob:; worker-src blob:; connect-src
|
|
68160
|
+
return `<!doctype html><meta http-equiv="Content-Security-Policy" content="default-src 'none'; script-src 'unsafe-inline' blob:; worker-src blob:; connect-src blob:; form-action 'none'; base-uri 'none'"><script>
|
|
67945
68161
|
${prelude}
|
|
67946
68162
|
(${scriptBroker.toString()})(URL.createObjectURL(new Blob([${JSON.stringify(worker)}], {type:'text/javascript'})), ${poolSize}, ${options.timeoutMs ?? 2e3});
|
|
67947
68163
|
<\/script>`;
|
|
@@ -67950,14 +68166,15 @@ const NO_BOX = {
|
|
|
67950
68166
|
width: 0,
|
|
67951
68167
|
height: 0
|
|
67952
68168
|
};
|
|
67953
|
-
|
|
67954
|
-
|
|
67955
|
-
|
|
67956
|
-
|
|
67957
|
-
if (
|
|
67958
|
-
const
|
|
67959
|
-
const
|
|
67960
|
-
|
|
68169
|
+
const OFFSCREEN_FRAME_RATE = 4;
|
|
68170
|
+
const CALL_QUIET_MS = 1e3;
|
|
68171
|
+
function selfContained(entry, now) {
|
|
68172
|
+
const output = entry.output;
|
|
68173
|
+
if (!entry.item || !output || now - (entry.calledAt ?? -Infinity) < CALL_QUIET_MS) return false;
|
|
68174
|
+
for (const id in output.patches) if (id !== entry.id) return false;
|
|
68175
|
+
for (const _ in output.world) return false;
|
|
68176
|
+
for (const _ in output.screen) return false;
|
|
68177
|
+
return true;
|
|
67961
68178
|
}
|
|
67962
68179
|
function createBoardScriptHost(options) {
|
|
67963
68180
|
const revisions = /* @__PURE__ */ new Map();
|
|
@@ -68176,6 +68393,7 @@ function createBoardScriptHost(options) {
|
|
|
68176
68393
|
return;
|
|
68177
68394
|
}
|
|
68178
68395
|
if (data.kind === "call") {
|
|
68396
|
+
entry.calledAt = performance.now();
|
|
68179
68397
|
const capability = typeof data.name === "string" && options.capabilities && Object.hasOwn(options.capabilities, data.name) ? options.capabilities[data.name] : void 0;
|
|
68180
68398
|
Promise.resolve().then(() => {
|
|
68181
68399
|
if (!capability) throw new Error(`Capability unavailable: ${data.name}`);
|
|
@@ -68445,7 +68663,8 @@ function createBoardScriptHost(options) {
|
|
|
68445
68663
|
}
|
|
68446
68664
|
if (!brokerReady || !entry.graph || entry.pending) continue;
|
|
68447
68665
|
const elapsed = time - entry.startedAt;
|
|
68448
|
-
const
|
|
68666
|
+
const rate = entry.visible || !selfContained(entry, now) ? entry.output?.frameRate : Math.min(entry.output?.frameRate ?? OFFSCREEN_FRAME_RATE, OFFSCREEN_FRAME_RATE);
|
|
68667
|
+
const tick = rate ? Math.floor(elapsed * rate / 1e3) : elapsed;
|
|
68449
68668
|
if (!entry.dirty && (!moving(entry) || entry.tick === tick)) continue;
|
|
68450
68669
|
entry.pending = true;
|
|
68451
68670
|
entry.dirty = false;
|
|
@@ -68484,14 +68703,11 @@ function createBoardScriptHost(options) {
|
|
|
68484
68703
|
},
|
|
68485
68704
|
event(id, event) {
|
|
68486
68705
|
const entry = entries.get(id);
|
|
68487
|
-
if (!entry || entry.error || entry.output
|
|
68488
|
-
|
|
68489
|
-
while (queued >= 0 && !supersedes(entry.events[queued], event)) queued--;
|
|
68490
|
-
if (queued >= 0 && (event.type !== "pointermove" || queued === entry.events.length - 1)) entry.events.splice(queued, 1);
|
|
68491
|
-
if (entry.events.length >= 128) return;
|
|
68492
|
-
entry.events.push(event);
|
|
68706
|
+
if (!entry || entry.error || !boardScriptListens(entry.output, event)) return true;
|
|
68707
|
+
if (!queueBoardScriptEvent(entry.events, event)) return false;
|
|
68493
68708
|
entry.dirty = true;
|
|
68494
68709
|
options.onFrame();
|
|
68710
|
+
return true;
|
|
68495
68711
|
},
|
|
68496
68712
|
invalidate(path) {
|
|
68497
68713
|
modules.invalidate(path);
|
|
@@ -69227,6 +69443,98 @@ function seedOf(value) {
|
|
|
69227
69443
|
function boardShaderSeed(seed) {
|
|
69228
69444
|
return seedOf(seed);
|
|
69229
69445
|
}
|
|
69446
|
+
const TEXEL_GROWTH = 128;
|
|
69447
|
+
function createTexels(drawn, pass) {
|
|
69448
|
+
const root = new Container();
|
|
69449
|
+
root.addChild(new Mesh({
|
|
69450
|
+
geometry: drawn.geometry,
|
|
69451
|
+
shader: drawn.shader
|
|
69452
|
+
}));
|
|
69453
|
+
const sprite = new Sprite({
|
|
69454
|
+
texture: Texture.EMPTY,
|
|
69455
|
+
label: "board-shader-texels"
|
|
69456
|
+
});
|
|
69457
|
+
sprite.blendMode = pass.blend ?? "normal";
|
|
69458
|
+
sprite.visible = false;
|
|
69459
|
+
return {
|
|
69460
|
+
size: pass.texel ?? 1,
|
|
69461
|
+
root,
|
|
69462
|
+
sprite,
|
|
69463
|
+
target: null,
|
|
69464
|
+
rect: null
|
|
69465
|
+
};
|
|
69466
|
+
}
|
|
69467
|
+
function texelRect(frame, size) {
|
|
69468
|
+
const [a, b] = frame.localToGlobal;
|
|
69469
|
+
if (Math.hypot(a, b) * frame.density * Math.min(1, frame.shading ?? 1) * size <= 1) return null;
|
|
69470
|
+
const { region, view } = frame;
|
|
69471
|
+
const left = Math.floor(Math.max(region.x, view.x) / size) * size;
|
|
69472
|
+
const top = Math.floor(Math.max(region.y, view.y) / size) * size;
|
|
69473
|
+
const right = Math.ceil(Math.min(region.x + region.width, view.x + view.width) / size) * size;
|
|
69474
|
+
const bottom = Math.ceil(Math.min(region.y + region.height, view.y + view.height) / size) * size;
|
|
69475
|
+
return right > left && bottom > top ? {
|
|
69476
|
+
x: left,
|
|
69477
|
+
y: top,
|
|
69478
|
+
width: right - left,
|
|
69479
|
+
height: bottom - top
|
|
69480
|
+
} : null;
|
|
69481
|
+
}
|
|
69482
|
+
function drawTexels(renderer, texels, rect) {
|
|
69483
|
+
const width = Math.round(rect.width / texels.size);
|
|
69484
|
+
const height = Math.round(rect.height / texels.size);
|
|
69485
|
+
let target = texels.target;
|
|
69486
|
+
if (!target || target.width < width || target.height < height) {
|
|
69487
|
+
releaseTexels(texels);
|
|
69488
|
+
const grow = (edge) => Math.ceil(edge / TEXEL_GROWTH) * TEXEL_GROWTH;
|
|
69489
|
+
target = RenderTexture.create({
|
|
69490
|
+
width: grow(width),
|
|
69491
|
+
height: grow(height),
|
|
69492
|
+
resolution: 1,
|
|
69493
|
+
scaleMode: "nearest",
|
|
69494
|
+
antialias: false,
|
|
69495
|
+
autoGenerateMipmaps: false
|
|
69496
|
+
});
|
|
69497
|
+
texels.target = target;
|
|
69498
|
+
texels.sprite.texture = new Texture({
|
|
69499
|
+
source: target.source,
|
|
69500
|
+
frame: new Rectangle(0, 0, width, height),
|
|
69501
|
+
dynamic: true
|
|
69502
|
+
});
|
|
69503
|
+
}
|
|
69504
|
+
const texture = texels.sprite.texture;
|
|
69505
|
+
if (texture.frame.width !== width || texture.frame.height !== height) {
|
|
69506
|
+
texture.frame.width = width;
|
|
69507
|
+
texture.frame.height = height;
|
|
69508
|
+
texture.update();
|
|
69509
|
+
}
|
|
69510
|
+
texels.root.scale.set(1 / texels.size);
|
|
69511
|
+
texels.root.position.set(-rect.x / texels.size, -rect.y / texels.size);
|
|
69512
|
+
renderer.render({
|
|
69513
|
+
container: texels.root,
|
|
69514
|
+
target,
|
|
69515
|
+
clear: true,
|
|
69516
|
+
clearColor: [
|
|
69517
|
+
0,
|
|
69518
|
+
0,
|
|
69519
|
+
0,
|
|
69520
|
+
0
|
|
69521
|
+
]
|
|
69522
|
+
});
|
|
69523
|
+
texels.sprite.position.set(rect.x, rect.y);
|
|
69524
|
+
texels.sprite.scale.set(texels.size);
|
|
69525
|
+
}
|
|
69526
|
+
function releaseTexels(texels) {
|
|
69527
|
+
if (!texels.target) return;
|
|
69528
|
+
texels.sprite.texture.destroy();
|
|
69529
|
+
texels.sprite.texture = Texture.EMPTY;
|
|
69530
|
+
texels.target.destroy(true);
|
|
69531
|
+
texels.target = null;
|
|
69532
|
+
}
|
|
69533
|
+
function destroyTexels(texels) {
|
|
69534
|
+
releaseTexels(texels);
|
|
69535
|
+
texels.sprite.destroy();
|
|
69536
|
+
texels.root.destroy({ children: true });
|
|
69537
|
+
}
|
|
69230
69538
|
function createBoardShaderLayer(renderer, shader, parameters, label, options = {}) {
|
|
69231
69539
|
const uniforms = boardShaderUniforms(shader.uniforms);
|
|
69232
69540
|
const surfaces = shader.surfaces === true;
|
|
@@ -69308,12 +69616,15 @@ function createBoardShaderLayer(renderer, shader, parameters, label, options = {
|
|
|
69308
69616
|
const container = containers[layer];
|
|
69309
69617
|
container.boundsArea = area;
|
|
69310
69618
|
container.addChild(drawn.mesh);
|
|
69619
|
+
const texels = pass.texel ? createTexels(drawn, pass) : null;
|
|
69620
|
+
if (texels) container.addChild(texels.sprite);
|
|
69311
69621
|
meshes.push({
|
|
69312
69622
|
...drawn,
|
|
69313
69623
|
pass,
|
|
69314
69624
|
sprites,
|
|
69315
69625
|
placement,
|
|
69316
|
-
scaler: null
|
|
69626
|
+
scaler: null,
|
|
69627
|
+
texels
|
|
69317
69628
|
});
|
|
69318
69629
|
});
|
|
69319
69630
|
let state = null;
|
|
@@ -69524,8 +69835,14 @@ function createBoardShaderLayer(renderer, shader, parameters, label, options = {
|
|
|
69524
69835
|
area.width = frame.region.width;
|
|
69525
69836
|
area.height = frame.region.height;
|
|
69526
69837
|
for (const drawn of meshes) {
|
|
69527
|
-
|
|
69528
|
-
|
|
69838
|
+
const on = boardShaderPassOn(drawn.pass, frame.passes);
|
|
69839
|
+
const texels = drawn.texels;
|
|
69840
|
+
if (texels) {
|
|
69841
|
+
texels.rect = on ? texelRect(frame, texels.size) : null;
|
|
69842
|
+
texels.sprite.visible = texels.rect !== null;
|
|
69843
|
+
}
|
|
69844
|
+
drawn.mesh.visible = on && !texels?.rect;
|
|
69845
|
+
if (drawn.mesh.visible && !drawn.sprites) shade(drawn, frame);
|
|
69529
69846
|
}
|
|
69530
69847
|
for (const { filter, pass } of filters) filter.enabled = boardShaderPassOn(pass, frame.passes);
|
|
69531
69848
|
fill(group, frame, frame.region);
|
|
@@ -69549,6 +69866,7 @@ function createBoardShaderLayer(renderer, shader, parameters, label, options = {
|
|
|
69549
69866
|
ran: 0,
|
|
69550
69867
|
behind: false
|
|
69551
69868
|
};
|
|
69869
|
+
for (const { texels } of meshes) if (texels?.rect) drawTexels(target, texels, texels.rect);
|
|
69552
69870
|
if (placementsStale || stepped.ran) {
|
|
69553
69871
|
for (const { placement, mesh } of meshes) if (placement && mesh.visible) target.render({
|
|
69554
69872
|
container: placement.mesh.mesh,
|
|
@@ -69590,6 +69908,7 @@ function createBoardShaderLayer(renderer, shader, parameters, label, options = {
|
|
|
69590
69908
|
for (const compile of compiles) compile.cancel();
|
|
69591
69909
|
for (const drawn of meshes) {
|
|
69592
69910
|
drawn.scaler?.destroy();
|
|
69911
|
+
if (drawn.texels) destroyTexels(drawn.texels);
|
|
69593
69912
|
destroyBoardShaderMesh(drawn);
|
|
69594
69913
|
if (drawn.placement) destroyPlacement(renderer, drawn.placement);
|
|
69595
69914
|
}
|
|
@@ -70088,10 +70407,17 @@ function createBrowserBoardScriptExport(readModule, options = {}) {
|
|
|
70088
70407
|
element.style.cssText = "position:fixed;left:-10000px;top:0;width:1px;height:1px;visibility:hidden;pointer-events:none";
|
|
70089
70408
|
globalThis.document.body.appendChild(element);
|
|
70090
70409
|
const outputs = /* @__PURE__ */ new Map();
|
|
70410
|
+
const ranks = /* @__PURE__ */ new Map();
|
|
70411
|
+
const last = /* @__PURE__ */ new Map();
|
|
70091
70412
|
const started = {
|
|
70092
70413
|
element,
|
|
70093
70414
|
outputs,
|
|
70094
70415
|
time: 0,
|
|
70416
|
+
document: null,
|
|
70417
|
+
ranks,
|
|
70418
|
+
outbox: createBoardScriptOutbox(() => ranks),
|
|
70419
|
+
views: /* @__PURE__ */ new Map(),
|
|
70420
|
+
last,
|
|
70095
70421
|
wake: () => {},
|
|
70096
70422
|
host: createBoardScriptHost({
|
|
70097
70423
|
host: element,
|
|
@@ -70100,7 +70426,15 @@ function createBrowserBoardScriptExport(readModule, options = {}) {
|
|
|
70100
70426
|
shaders: options.shaders ?? true,
|
|
70101
70427
|
snapshots: options.snapshots,
|
|
70102
70428
|
timeoutMs: 15e3,
|
|
70103
|
-
capabilities:
|
|
70429
|
+
capabilities: {
|
|
70430
|
+
...Object.fromEntries(Object.entries(BOARD_SCRIPT_EXPORT_CALLS).map(([name, call]) => [name, async (_id, input) => call(input)])),
|
|
70431
|
+
"board.emit": async (id, input) => {
|
|
70432
|
+
if (!started.document) return;
|
|
70433
|
+
const { target, event } = boardScriptEmit(started.document, id, input);
|
|
70434
|
+
last.set(id, `emit(${target}, "${event.type}")`);
|
|
70435
|
+
started.outbox.push(id, target, event);
|
|
70436
|
+
}
|
|
70437
|
+
},
|
|
70104
70438
|
onFrame: () => started.wake(),
|
|
70105
70439
|
onOutput(id, output) {
|
|
70106
70440
|
if (output) outputs.set(id, output);
|
|
@@ -70117,11 +70451,17 @@ function createBrowserBoardScriptExport(readModule, options = {}) {
|
|
|
70117
70451
|
run.element.remove();
|
|
70118
70452
|
run = null;
|
|
70119
70453
|
}
|
|
70120
|
-
function settle(current, document, time) {
|
|
70454
|
+
function settle(current, document, time, view) {
|
|
70121
70455
|
current.time = time;
|
|
70456
|
+
current.document = document;
|
|
70122
70457
|
const { host } = current;
|
|
70123
70458
|
const scene = buildBoardScene(document);
|
|
70124
70459
|
const ids = boardScriptAttachments(document).map(({ id }) => id);
|
|
70460
|
+
current.ranks.clear();
|
|
70461
|
+
for (const [index, id] of ids.entries()) current.ranks.set(id, index);
|
|
70462
|
+
const viewKey = view ? JSON.stringify(view) : null;
|
|
70463
|
+
let viewed = false;
|
|
70464
|
+
let rounds = 0;
|
|
70125
70465
|
return new Promise((resolve, reject) => {
|
|
70126
70466
|
const finish = (error) => {
|
|
70127
70467
|
clearTimeout(timer);
|
|
@@ -70129,7 +70469,7 @@ function createBrowserBoardScriptExport(readModule, options = {}) {
|
|
|
70129
70469
|
if (error) reject(error);
|
|
70130
70470
|
else resolve();
|
|
70131
70471
|
};
|
|
70132
|
-
const timer = setTimeout(() => finish(
|
|
70472
|
+
const timer = setTimeout(() => finish(new Error(["Scripts did not settle in 20 s.", ...status(current, ids)].join(" "))), 2e4);
|
|
70133
70473
|
let queued = false;
|
|
70134
70474
|
const sync = () => {
|
|
70135
70475
|
queued = false;
|
|
@@ -70139,11 +70479,31 @@ function createBrowserBoardScriptExport(readModule, options = {}) {
|
|
|
70139
70479
|
y: 0,
|
|
70140
70480
|
zoom: 1
|
|
70141
70481
|
}, time, false);
|
|
70482
|
+
if (viewKey && !viewed) {
|
|
70483
|
+
viewed = true;
|
|
70484
|
+
for (const id of ids) if (current.views.get(id) !== viewKey) {
|
|
70485
|
+
current.views.set(id, viewKey);
|
|
70486
|
+
host.event(id, {
|
|
70487
|
+
type: "viewchange",
|
|
70488
|
+
data: view
|
|
70489
|
+
});
|
|
70490
|
+
}
|
|
70491
|
+
}
|
|
70142
70492
|
for (const id of ids) {
|
|
70143
70493
|
const error = host.error(id);
|
|
70144
70494
|
if (error) throw new Error(error);
|
|
70145
70495
|
}
|
|
70146
|
-
if (ids.every((id) => host.settled(id)))
|
|
70496
|
+
if (!ids.every((id) => host.settled(id))) return;
|
|
70497
|
+
if (current.outbox.size && rounds++ <= 16) {
|
|
70498
|
+
for (const [target, events] of current.outbox.take()) {
|
|
70499
|
+
current.last.set(target, `event ${events.map((event) => event.type).join(", ")}`);
|
|
70500
|
+
for (const event of events) host.event(target, event);
|
|
70501
|
+
}
|
|
70502
|
+
current.wake();
|
|
70503
|
+
return;
|
|
70504
|
+
}
|
|
70505
|
+
current.outbox.take();
|
|
70506
|
+
finish();
|
|
70147
70507
|
} catch (error) {
|
|
70148
70508
|
finish(error);
|
|
70149
70509
|
}
|
|
@@ -70156,8 +70516,16 @@ function createBrowserBoardScriptExport(readModule, options = {}) {
|
|
|
70156
70516
|
current.wake();
|
|
70157
70517
|
});
|
|
70158
70518
|
}
|
|
70519
|
+
function status(current, ids) {
|
|
70520
|
+
return ids.flatMap((id) => {
|
|
70521
|
+
if (current.host.settled(id)) return [];
|
|
70522
|
+
const state = current.host.output(id) ? "is still running" : "has not started";
|
|
70523
|
+
const last = current.last.get(id);
|
|
70524
|
+
return [`${id} ${state}${last ? `; last ${last}` : ""}.`];
|
|
70525
|
+
});
|
|
70526
|
+
}
|
|
70159
70527
|
return {
|
|
70160
|
-
async at(document, time) {
|
|
70528
|
+
async at(document, time, view) {
|
|
70161
70529
|
if (!Number.isFinite(time) || time < 0 || time > 6e5) throw new Error("Script export time must be between 0 and 600000 ms.");
|
|
70162
70530
|
if (run && time < run.time) stop();
|
|
70163
70531
|
const fresh = !run;
|
|
@@ -70188,7 +70556,7 @@ function createBrowserBoardScriptExport(readModule, options = {}) {
|
|
|
70188
70556
|
}
|
|
70189
70557
|
if (boardScriptParamsKey(document) !== previous && before.at > ran) await settle(current, before.document, before.at);
|
|
70190
70558
|
}
|
|
70191
|
-
await settle(current, document, time);
|
|
70559
|
+
await settle(current, document, time, view);
|
|
70192
70560
|
return {
|
|
70193
70561
|
...host,
|
|
70194
70562
|
shaders: (input) => boardShaderOwners(input, outputs, (id) => host.clock(id)),
|
|
@@ -70356,6 +70724,7 @@ function buildContext(input) {
|
|
|
70356
70724
|
scene: input.scene,
|
|
70357
70725
|
time: input.time ?? 0,
|
|
70358
70726
|
frameAt: input.frameAt,
|
|
70727
|
+
...input.page ? { page: input.page } : {},
|
|
70359
70728
|
selectedIds: /* @__PURE__ */ new Set(),
|
|
70360
70729
|
hoveredId: null,
|
|
70361
70730
|
resizingIds: /* @__PURE__ */ new Set(),
|
|
@@ -70496,6 +70865,7 @@ function createBoardExportScene(input) {
|
|
|
70496
70865
|
const container = containers.get(owner.id);
|
|
70497
70866
|
if (!item || !container) return null;
|
|
70498
70867
|
const group = isSelfGroupedFrame(item) ? groups.get(item.id)?.group : void 0;
|
|
70868
|
+
for (const part of [layer.below, layer.above]) if (part && item.type === "frame") clipFrameShaderLayer(part, item);
|
|
70499
70869
|
if (layer.below) container.addChildAt(layer.below, 0);
|
|
70500
70870
|
if (layer.above) {
|
|
70501
70871
|
if (group) {
|
|
@@ -70647,6 +71017,7 @@ function renderBoardExport(renderer, input, options = {}) {
|
|
|
70647
71017
|
colorScheme
|
|
70648
71018
|
}),
|
|
70649
71019
|
backdropTexture: options.backgroundTexture,
|
|
71020
|
+
...plan.page ? { page: plan.page } : {},
|
|
70650
71021
|
...gpu && owners.length ? { shaders: {
|
|
70651
71022
|
renderer,
|
|
70652
71023
|
owners,
|
|
@@ -70699,6 +71070,10 @@ function renderBoardExport(renderer, input, options = {}) {
|
|
|
70699
71070
|
kind: "shader-failed",
|
|
70700
71071
|
...failure
|
|
70701
71072
|
});
|
|
71073
|
+
if (gpu) for (const miss of boardShaderMisses(scene, plan, owners, exportScene.shaderErrors)) warnings.push({
|
|
71074
|
+
kind: "shader-hidden",
|
|
71075
|
+
...miss
|
|
71076
|
+
});
|
|
70702
71077
|
return {
|
|
70703
71078
|
canvas,
|
|
70704
71079
|
plan,
|
|
@@ -70709,6 +71084,38 @@ function renderBoardExport(renderer, input, options = {}) {
|
|
|
70709
71084
|
flattened?.();
|
|
70710
71085
|
}
|
|
70711
71086
|
}
|
|
71087
|
+
function boardShaderMisses(scene, plan, owners, failed = []) {
|
|
71088
|
+
const planned = new Set(plan.items.map((item) => item.id));
|
|
71089
|
+
const misses = owners.flatMap(({ id, root, output }) => {
|
|
71090
|
+
if (failed.some((failure) => failure.id === id)) return [];
|
|
71091
|
+
const shader = output.shader;
|
|
71092
|
+
if (shader && !shader.state && shader.passes.every((pass) => !boardShaderPassOn(pass, output.passes))) return [{
|
|
71093
|
+
id,
|
|
71094
|
+
reason: "every pass is switched off (ctx.passes() or enabled: false)"
|
|
71095
|
+
}];
|
|
71096
|
+
if (root) return [];
|
|
71097
|
+
const item = scene.get(id);
|
|
71098
|
+
if (!item) return [{
|
|
71099
|
+
id,
|
|
71100
|
+
reason: "its item is not in the document"
|
|
71101
|
+
}];
|
|
71102
|
+
if (scene.opacity(id) <= 0) return [{
|
|
71103
|
+
id,
|
|
71104
|
+
reason: "its item is hidden (opacity 0 or invisible)"
|
|
71105
|
+
}];
|
|
71106
|
+
if (planned.has(id)) return [];
|
|
71107
|
+
return [{
|
|
71108
|
+
id,
|
|
71109
|
+
reason: exportItemBounds(item, scene) ? "its item is outside the exported area" : "its item is clipped away by a parent frame"
|
|
71110
|
+
}];
|
|
71111
|
+
});
|
|
71112
|
+
const grouped = /* @__PURE__ */ new Map();
|
|
71113
|
+
for (const { id, reason } of misses) grouped.set(reason, [...grouped.get(reason) ?? [], id]);
|
|
71114
|
+
return [...grouped].map(([reason, ids]) => ({
|
|
71115
|
+
ids,
|
|
71116
|
+
reason
|
|
71117
|
+
}));
|
|
71118
|
+
}
|
|
70712
71119
|
//#endregion
|
|
70713
71120
|
//#region src/board-gpu/page.ts
|
|
70714
71121
|
let renderer = null;
|
|
@@ -70816,6 +71223,7 @@ globalThis.cohubBoardGpu = {
|
|
|
70816
71223
|
},
|
|
70817
71224
|
async profile(input) {
|
|
70818
71225
|
if (!renderer || !session) throw new Error("The GPU exporter is not ready.");
|
|
71226
|
+
const started = performance.now();
|
|
70819
71227
|
const target = renderer;
|
|
70820
71228
|
const { document, animation, theme: themeId } = session.init;
|
|
70821
71229
|
const theme = boardRenderTheme(themeId);
|
|
@@ -70824,26 +71232,37 @@ globalThis.cohubBoardGpu = {
|
|
|
70824
71232
|
time: input.time
|
|
70825
71233
|
};
|
|
70826
71234
|
const time = input.time ?? 0;
|
|
70827
|
-
const
|
|
70828
|
-
const
|
|
70829
|
-
sampler
|
|
71235
|
+
const sampler = session.sampler;
|
|
71236
|
+
const options = {
|
|
71237
|
+
sampler,
|
|
70830
71238
|
region: input.region,
|
|
70831
71239
|
camera: input.camera,
|
|
70832
71240
|
scale: input.scale,
|
|
70833
|
-
|
|
71241
|
+
padding: 0,
|
|
71242
|
+
...at ? { at } : {}
|
|
71243
|
+
};
|
|
71244
|
+
const planned = prepareBoardExport(document, options);
|
|
71245
|
+
if (!planned) throw new Error("Nothing to profile: the region contains no items.");
|
|
71246
|
+
const scripts = await session.scripts.at(at ? sampler.at(time).document : document, time, boardExportView(planned.plan));
|
|
71247
|
+
const gl = target.gl;
|
|
71248
|
+
const info = gl.getExtension("WEBGL_debug_renderer_info");
|
|
71249
|
+
const rendererName = String(info ? gl.getParameter(info.UNMASKED_RENDERER_WEBGL) : gl.getParameter(gl.RENDERER));
|
|
71250
|
+
const prepared = prepareBoardExport(document, {
|
|
71251
|
+
...options,
|
|
70834
71252
|
scripts
|
|
70835
71253
|
});
|
|
70836
71254
|
if (!prepared) throw new Error("Nothing to profile: the region contains no items.");
|
|
70837
71255
|
const visible = prepared.plan.items.filter((item) => prepared.scene.opacity(item.id) > 0);
|
|
70838
71256
|
const loaded = input.withImages ? await loadTextures(visible, prepared.plan.scale, input.imageMemory, {}) : /* @__PURE__ */ new Map();
|
|
70839
|
-
const
|
|
71257
|
+
const inside = new Set(prepared.plan.items.map((item) => item.id));
|
|
71258
|
+
const owners = (scripts.shaders?.(prepared.document, time) ?? []).filter((owner) => owner.root || inside.has(owner.id));
|
|
70840
71259
|
const layers = createBoardShaderLayers({ wait: true });
|
|
70841
71260
|
const scene = createBoardExportScene({
|
|
70842
71261
|
settings: prepared.document.board,
|
|
70843
71262
|
scene: prepared.scene,
|
|
70844
71263
|
items: prepared.plan.items,
|
|
70845
71264
|
time,
|
|
70846
|
-
frameAt:
|
|
71265
|
+
frameAt: sampler.frameAt,
|
|
70847
71266
|
world: prepared.plan.world,
|
|
70848
71267
|
scale: prepared.plan.scale,
|
|
70849
71268
|
colorScheme: theme.colorScheme,
|
|
@@ -70853,76 +71272,128 @@ globalThis.cohubBoardGpu = {
|
|
|
70853
71272
|
textures: loaded,
|
|
70854
71273
|
scripts,
|
|
70855
71274
|
assetKey: boardAssetKey,
|
|
71275
|
+
...prepared.plan.page ? { page: prepared.plan.page } : {},
|
|
70856
71276
|
...owners.length ? { shaders: {
|
|
70857
71277
|
renderer: target,
|
|
70858
71278
|
owners,
|
|
70859
71279
|
layers
|
|
70860
71280
|
} } : {}
|
|
70861
71281
|
});
|
|
70862
|
-
const { width, height } = prepared.plan;
|
|
70863
|
-
const output = RenderTexture.create({
|
|
70864
|
-
width,
|
|
70865
|
-
height
|
|
70866
|
-
});
|
|
70867
|
-
const gl = target.gl;
|
|
70868
71282
|
const pixel = /* @__PURE__ */ new Uint8Array(4);
|
|
70869
|
-
|
|
70870
|
-
|
|
70871
|
-
|
|
70872
|
-
|
|
70873
|
-
|
|
70874
|
-
|
|
70875
|
-
|
|
70876
|
-
|
|
70877
|
-
|
|
70878
|
-
|
|
70879
|
-
|
|
70880
|
-
}
|
|
70881
|
-
|
|
71283
|
+
let size = {
|
|
71284
|
+
width: prepared.plan.width,
|
|
71285
|
+
height: prepared.plan.height
|
|
71286
|
+
};
|
|
71287
|
+
let output = RenderTexture.create(size);
|
|
71288
|
+
let transform;
|
|
71289
|
+
const resize = (factor) => {
|
|
71290
|
+
output.destroy(true);
|
|
71291
|
+
size = {
|
|
71292
|
+
width: Math.max(1, Math.round(prepared.plan.width * factor)),
|
|
71293
|
+
height: Math.max(1, Math.round(prepared.plan.height * factor))
|
|
71294
|
+
};
|
|
71295
|
+
output = RenderTexture.create(size);
|
|
71296
|
+
transform = new Matrix().scale(factor, factor);
|
|
71297
|
+
};
|
|
71298
|
+
const render = () => {
|
|
71299
|
+
const start = performance.now();
|
|
71300
|
+
layers.prepare(target);
|
|
71301
|
+
target.render({
|
|
71302
|
+
container: scene.root,
|
|
71303
|
+
target: output,
|
|
71304
|
+
clear: true,
|
|
71305
|
+
...transform ? { transform } : {}
|
|
71306
|
+
});
|
|
71307
|
+
gl.readPixels(0, 0, 1, 1, gl.RGBA, gl.UNSIGNED_BYTE, pixel);
|
|
71308
|
+
return performance.now() - start;
|
|
70882
71309
|
};
|
|
70883
71310
|
try {
|
|
70884
|
-
|
|
70885
|
-
const
|
|
70886
|
-
|
|
70887
|
-
|
|
70888
|
-
|
|
70889
|
-
|
|
71311
|
+
render();
|
|
71312
|
+
const renders = (frames) => frames * input.rounds * (1 + owners.length);
|
|
71313
|
+
let frames = input.frames;
|
|
71314
|
+
let frameMs = Math.max(render(), .1);
|
|
71315
|
+
let reduced = null;
|
|
71316
|
+
let factor = 1;
|
|
71317
|
+
const budget = Math.max(input.budgetMs / 4, input.budgetMs - (performance.now() - started));
|
|
71318
|
+
for (let attempt = 0; attempt < 3 && frameMs * renders(frames) > budget; attempt++) {
|
|
71319
|
+
reduced ??= {
|
|
71320
|
+
...size,
|
|
71321
|
+
frames,
|
|
71322
|
+
frameMs
|
|
71323
|
+
};
|
|
71324
|
+
frames = Math.max(3, Math.min(frames, Math.floor(budget / (frameMs * renders(1)))));
|
|
71325
|
+
const next = Math.max(factor * Math.sqrt(Math.min(1, budget / (frameMs * renders(frames)))), Math.min(1, 320 / Math.max(prepared.plan.width, prepared.plan.height)));
|
|
71326
|
+
if (next > factor * .98) break;
|
|
71327
|
+
factor = next;
|
|
71328
|
+
resize(factor);
|
|
71329
|
+
render();
|
|
71330
|
+
frameMs = Math.max(render(), .1);
|
|
71331
|
+
}
|
|
71332
|
+
const measure = () => {
|
|
71333
|
+
const samples = [];
|
|
71334
|
+
for (let frame = 0; frame < frames; frame++) samples.push(render());
|
|
71335
|
+
return samples.sort((a, b) => a - b);
|
|
71336
|
+
};
|
|
71337
|
+
const median = (samples) => [...samples].sort((a, b) => a - b)[Math.floor(samples.length / 2)] ?? 0;
|
|
71338
|
+
const all = [];
|
|
71339
|
+
const costs = new Map(owners.map((owner) => [owner.id, []]));
|
|
71340
|
+
const measuring = performance.now();
|
|
71341
|
+
let rounds = 0;
|
|
71342
|
+
for (; rounds < input.rounds; rounds++) {
|
|
71343
|
+
if (rounds && (performance.now() - measuring) * (rounds + 1) / rounds > budget * 1.25) break;
|
|
71344
|
+
const samples = measure();
|
|
71345
|
+
all.push(...samples);
|
|
71346
|
+
const base = median(samples);
|
|
71347
|
+
for (const owner of owners) {
|
|
71348
|
+
const layer = layers.layer(owner.id);
|
|
71349
|
+
const parts = [layer?.below, layer?.above].filter((part) => part !== null && part !== void 0);
|
|
71350
|
+
const filters = layer?.filters ?? [];
|
|
71351
|
+
const shown = parts.map((part) => part.visible);
|
|
71352
|
+
const enabled = filters.map((filter) => filter.enabled);
|
|
71353
|
+
for (const part of parts) part.visible = false;
|
|
71354
|
+
for (const filter of filters) filter.enabled = false;
|
|
71355
|
+
const without = median(measure());
|
|
71356
|
+
parts.forEach((part, index) => {
|
|
71357
|
+
part.visible = shown[index];
|
|
71358
|
+
});
|
|
71359
|
+
filters.forEach((filter, index) => {
|
|
71360
|
+
filter.enabled = enabled[index];
|
|
71361
|
+
});
|
|
71362
|
+
costs.get(owner.id)?.push(Math.max(0, base - without));
|
|
71363
|
+
}
|
|
71364
|
+
}
|
|
71365
|
+
all.sort((a, b) => a - b);
|
|
71366
|
+
const p50 = median(all);
|
|
71367
|
+
const results = owners.map((owner) => {
|
|
70890
71368
|
const shader = owner.output.shader;
|
|
70891
|
-
const
|
|
70892
|
-
const filters = layer?.filters ?? [];
|
|
70893
|
-
const shown = parts.map((part) => part.visible);
|
|
70894
|
-
const enabled = filters.map((filter) => filter.enabled);
|
|
70895
|
-
for (const part of parts) part.visible = false;
|
|
70896
|
-
for (const filter of filters) filter.enabled = false;
|
|
70897
|
-
const without = median(measure());
|
|
70898
|
-
parts.forEach((part, index) => {
|
|
70899
|
-
part.visible = shown[index];
|
|
70900
|
-
});
|
|
70901
|
-
filters.forEach((filter, index) => {
|
|
70902
|
-
filter.enabled = enabled[index];
|
|
70903
|
-
});
|
|
71369
|
+
const rounds = costs.get(owner.id) ?? [0];
|
|
70904
71370
|
const filterPasses = shader?.passes.filter((pass) => (pass.layer ?? shader.layer) === "filter") ?? [];
|
|
70905
71371
|
return {
|
|
70906
71372
|
id: owner.id,
|
|
70907
|
-
ms:
|
|
71373
|
+
ms: median(rounds),
|
|
71374
|
+
range: [Math.min(...rounds), Math.max(...rounds)],
|
|
70908
71375
|
filter: !filterPasses.length ? "none" : filterPasses.every((pass) => pass.name) ? "switchable" : "always",
|
|
70909
71376
|
sprites: shader?.passes.reduce((sum, pass) => sum + (pass.sprites ?? 0), 0) ?? 0,
|
|
71377
|
+
boxes: shader?.passes.filter((pass) => !pass.sprites && !pass.texel && (pass.layer ?? shader.layer) !== "filter").length ?? 0,
|
|
70910
71378
|
state: shader?.state ? {
|
|
70911
71379
|
width: shader.state.width,
|
|
70912
71380
|
height: shader.state.height
|
|
70913
71381
|
} : null
|
|
70914
71382
|
};
|
|
70915
71383
|
});
|
|
70916
|
-
const info = gl.getExtension("WEBGL_debug_renderer_info");
|
|
70917
71384
|
return {
|
|
70918
|
-
renderer:
|
|
70919
|
-
|
|
70920
|
-
|
|
71385
|
+
renderer: rendererName,
|
|
71386
|
+
gpu: /swiftshader|llvmpipe|softpipe|software|basic render/i.test(rendererName) ? "software" : "hardware",
|
|
71387
|
+
...size,
|
|
71388
|
+
frames,
|
|
71389
|
+
rounds,
|
|
71390
|
+
reduced,
|
|
71391
|
+
elapsedMs: performance.now() - started,
|
|
70921
71392
|
frame: {
|
|
70922
|
-
p50
|
|
70923
|
-
p95: all[Math.min(all.length - 1, Math.floor(all.length * .95))] ??
|
|
71393
|
+
p50,
|
|
71394
|
+
p95: all[Math.min(all.length - 1, Math.floor(all.length * .95))] ?? p50
|
|
70924
71395
|
},
|
|
70925
|
-
owners:
|
|
71396
|
+
owners: results.sort((a, b) => b.ms - a.ms),
|
|
70926
71397
|
effects: visible.filter((item) => hasBoardEffects(item.style)).length,
|
|
70927
71398
|
items: visible.length
|
|
70928
71399
|
};
|
|
@@ -70942,7 +71413,15 @@ globalThis.cohubBoardGpu = {
|
|
|
70942
71413
|
};
|
|
70943
71414
|
const time = frame.time ?? 0;
|
|
70944
71415
|
const sample = at ? session.sampler.at(time).document : document;
|
|
70945
|
-
const
|
|
71416
|
+
const planned = prepareBoardExport(document, {
|
|
71417
|
+
sampler: session.sampler,
|
|
71418
|
+
region: frame.region,
|
|
71419
|
+
camera: frame.camera,
|
|
71420
|
+
scale: frame.scale,
|
|
71421
|
+
padding: frame.padding,
|
|
71422
|
+
...at ? { at } : {}
|
|
71423
|
+
});
|
|
71424
|
+
const scripts = await session.scripts.at(sample, time, planned ? boardExportView(planned.plan) : void 0);
|
|
70946
71425
|
const options = {
|
|
70947
71426
|
sampler: session.sampler,
|
|
70948
71427
|
region: frame.region,
|