@neta-art/cohub-cli 10.20.0 → 10.22.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 +668 -188
- package/dist/board-gpu/protocol.d.ts +14 -0
- package/dist/board-kernel.d.ts +2 -2
- package/dist/board-kernel.js +832 -188
- 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 +9 -2
- package/dist/board-simulate.js +93 -35
- package/dist/build.json +1 -0
- package/dist/commands/boards.js +77 -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/harnesses/claude-approval.d.ts +4 -1
- package/dist/runtime/harnesses/claude-approval.js +8 -3
- package/dist/runtime/harnesses/claude.js +20 -11
- 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() {
|
|
@@ -67461,6 +67659,7 @@ function createScriptRuntime(module, initial, host) {
|
|
|
67461
67659
|
invalidate(false);
|
|
67462
67660
|
},
|
|
67463
67661
|
async commit(patch) {
|
|
67662
|
+
if (input.capabilities && !input.capabilities.includes("board.commit")) throw new Error("This viewer cannot edit the Board.");
|
|
67464
67663
|
return await host.call("board.commit", {
|
|
67465
67664
|
patch,
|
|
67466
67665
|
frame: stepping
|
|
@@ -67548,9 +67747,15 @@ function createScriptRuntime(module, initial, host) {
|
|
|
67548
67747
|
if (event.type === "viewchange") view = event.data;
|
|
67549
67748
|
const listeners = handlers.get(event.type);
|
|
67550
67749
|
if (!listeners?.size) return;
|
|
67551
|
-
|
|
67552
|
-
|
|
67553
|
-
|
|
67750
|
+
const outer = depth;
|
|
67751
|
+
depth = event.depth ?? 0;
|
|
67752
|
+
try {
|
|
67753
|
+
seeded(() => {
|
|
67754
|
+
for (const handler of listeners) handler(event);
|
|
67755
|
+
});
|
|
67756
|
+
} finally {
|
|
67757
|
+
depth = outer;
|
|
67758
|
+
}
|
|
67554
67759
|
invalidate();
|
|
67555
67760
|
},
|
|
67556
67761
|
draw(canvas) {
|
|
@@ -67613,6 +67818,7 @@ function createScriptRuntime(module, initial, host) {
|
|
|
67613
67818
|
//#region ../sdk/src/board/render/script-sandbox.ts
|
|
67614
67819
|
function scriptAgent(runtimeFactory, applyDelta, moduleUrls, load) {
|
|
67615
67820
|
const graphs = /* @__PURE__ */ new Map();
|
|
67821
|
+
const json = /* @__PURE__ */ new Map();
|
|
67616
67822
|
const instances = /* @__PURE__ */ new Map();
|
|
67617
67823
|
const calls = /* @__PURE__ */ new Map();
|
|
67618
67824
|
let callId = 0;
|
|
@@ -67626,6 +67832,16 @@ function scriptAgent(runtimeFactory, applyDelta, moduleUrls, load) {
|
|
|
67626
67832
|
announced = false;
|
|
67627
67833
|
send({ kind: "idle" });
|
|
67628
67834
|
};
|
|
67835
|
+
const freeze = (value) => {
|
|
67836
|
+
if (!value || typeof value !== "object" || Object.isFrozen(value)) return;
|
|
67837
|
+
Object.freeze(value);
|
|
67838
|
+
for (const child of Object.values(value)) freeze(child);
|
|
67839
|
+
};
|
|
67840
|
+
let jsonReader = null;
|
|
67841
|
+
const readJson = async (url) => {
|
|
67842
|
+
jsonReader ??= load(URL.createObjectURL(new Blob(["export default (url) => import(url, { with: { type: \"json\" } });"], { type: "text/javascript" }))).then((module) => module.default);
|
|
67843
|
+
return (await (await jsonReader)(url)).default;
|
|
67844
|
+
};
|
|
67629
67845
|
const describe = (error) => error instanceof Error ? error.stack ?? error.message : String(error);
|
|
67630
67846
|
function destroy(token) {
|
|
67631
67847
|
const instance = instances.get(token);
|
|
@@ -67659,10 +67875,11 @@ function scriptAgent(runtimeFactory, applyDelta, moduleUrls, load) {
|
|
|
67659
67875
|
if (!instance.runtime) {
|
|
67660
67876
|
const sources = data.graph ? graphs.get(data.graph) : void 0;
|
|
67661
67877
|
if (!sources) throw new Error("Missing script modules.");
|
|
67662
|
-
instance.urls = moduleUrls(sources);
|
|
67878
|
+
instance.urls = moduleUrls(sources, json);
|
|
67663
67879
|
const src = input.script.src;
|
|
67664
67880
|
const url = src ? instance.urls.urls[src] : void 0;
|
|
67665
67881
|
if (!url) throw new Error("Missing entry module.");
|
|
67882
|
+
for (const [path, url] of Object.entries(instance.urls.urls)) if (path.endsWith(".json")) freeze(await readJson(url));
|
|
67666
67883
|
instance.module = await load(url);
|
|
67667
67884
|
if (instances.get(token) !== instance) throw new Error("Script stopped.");
|
|
67668
67885
|
current = token;
|
|
@@ -67941,7 +68158,7 @@ function boardScriptFrameSource(options = {}) {
|
|
|
67941
68158
|
const worker = `${prelude} (${scriptAgent.toString()})(${createScriptRuntime.toString()}, ${applyScriptInputDelta.toString()}, ${scriptModuleUrls.toString()}, url => import(url));`;
|
|
67942
68159
|
const cores = typeof navigator === "undefined" ? 4 : navigator.hardwareConcurrency || 4;
|
|
67943
68160
|
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
|
|
68161
|
+
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
68162
|
${prelude}
|
|
67946
68163
|
(${scriptBroker.toString()})(URL.createObjectURL(new Blob([${JSON.stringify(worker)}], {type:'text/javascript'})), ${poolSize}, ${options.timeoutMs ?? 2e3});
|
|
67947
68164
|
<\/script>`;
|
|
@@ -67950,14 +68167,15 @@ const NO_BOX = {
|
|
|
67950
68167
|
width: 0,
|
|
67951
68168
|
height: 0
|
|
67952
68169
|
};
|
|
67953
|
-
|
|
67954
|
-
|
|
67955
|
-
|
|
67956
|
-
|
|
67957
|
-
if (
|
|
67958
|
-
const
|
|
67959
|
-
const
|
|
67960
|
-
|
|
68170
|
+
const OFFSCREEN_FRAME_RATE = 4;
|
|
68171
|
+
const CALL_QUIET_MS = 1e3;
|
|
68172
|
+
function selfContained(entry, now) {
|
|
68173
|
+
const output = entry.output;
|
|
68174
|
+
if (!entry.item || !output || now - (entry.calledAt ?? -Infinity) < CALL_QUIET_MS) return false;
|
|
68175
|
+
for (const id in output.patches) if (id !== entry.id) return false;
|
|
68176
|
+
for (const _ in output.world) return false;
|
|
68177
|
+
for (const _ in output.screen) return false;
|
|
68178
|
+
return true;
|
|
67961
68179
|
}
|
|
67962
68180
|
function createBoardScriptHost(options) {
|
|
67963
68181
|
const revisions = /* @__PURE__ */ new Map();
|
|
@@ -68176,6 +68394,7 @@ function createBoardScriptHost(options) {
|
|
|
68176
68394
|
return;
|
|
68177
68395
|
}
|
|
68178
68396
|
if (data.kind === "call") {
|
|
68397
|
+
entry.calledAt = performance.now();
|
|
68179
68398
|
const capability = typeof data.name === "string" && options.capabilities && Object.hasOwn(options.capabilities, data.name) ? options.capabilities[data.name] : void 0;
|
|
68180
68399
|
Promise.resolve().then(() => {
|
|
68181
68400
|
if (!capability) throw new Error(`Capability unavailable: ${data.name}`);
|
|
@@ -68445,7 +68664,8 @@ function createBoardScriptHost(options) {
|
|
|
68445
68664
|
}
|
|
68446
68665
|
if (!brokerReady || !entry.graph || entry.pending) continue;
|
|
68447
68666
|
const elapsed = time - entry.startedAt;
|
|
68448
|
-
const
|
|
68667
|
+
const rate = entry.visible || !selfContained(entry, now) ? entry.output?.frameRate : Math.min(entry.output?.frameRate ?? OFFSCREEN_FRAME_RATE, OFFSCREEN_FRAME_RATE);
|
|
68668
|
+
const tick = rate ? Math.floor(elapsed * rate / 1e3) : elapsed;
|
|
68449
68669
|
if (!entry.dirty && (!moving(entry) || entry.tick === tick)) continue;
|
|
68450
68670
|
entry.pending = true;
|
|
68451
68671
|
entry.dirty = false;
|
|
@@ -68484,14 +68704,11 @@ function createBoardScriptHost(options) {
|
|
|
68484
68704
|
},
|
|
68485
68705
|
event(id, event) {
|
|
68486
68706
|
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);
|
|
68707
|
+
if (!entry || entry.error || !boardScriptListens(entry.output, event)) return true;
|
|
68708
|
+
if (!queueBoardScriptEvent(entry.events, event)) return false;
|
|
68493
68709
|
entry.dirty = true;
|
|
68494
68710
|
options.onFrame();
|
|
68711
|
+
return true;
|
|
68495
68712
|
},
|
|
68496
68713
|
invalidate(path) {
|
|
68497
68714
|
modules.invalidate(path);
|
|
@@ -69227,6 +69444,98 @@ function seedOf(value) {
|
|
|
69227
69444
|
function boardShaderSeed(seed) {
|
|
69228
69445
|
return seedOf(seed);
|
|
69229
69446
|
}
|
|
69447
|
+
const TEXEL_GROWTH = 128;
|
|
69448
|
+
function createTexels(drawn, pass) {
|
|
69449
|
+
const root = new Container();
|
|
69450
|
+
root.addChild(new Mesh({
|
|
69451
|
+
geometry: drawn.geometry,
|
|
69452
|
+
shader: drawn.shader
|
|
69453
|
+
}));
|
|
69454
|
+
const sprite = new Sprite({
|
|
69455
|
+
texture: Texture.EMPTY,
|
|
69456
|
+
label: "board-shader-texels"
|
|
69457
|
+
});
|
|
69458
|
+
sprite.blendMode = pass.blend ?? "normal";
|
|
69459
|
+
sprite.visible = false;
|
|
69460
|
+
return {
|
|
69461
|
+
size: pass.texel ?? 1,
|
|
69462
|
+
root,
|
|
69463
|
+
sprite,
|
|
69464
|
+
target: null,
|
|
69465
|
+
rect: null
|
|
69466
|
+
};
|
|
69467
|
+
}
|
|
69468
|
+
function texelRect(frame, size) {
|
|
69469
|
+
const [a, b] = frame.localToGlobal;
|
|
69470
|
+
if (Math.hypot(a, b) * frame.density * Math.min(1, frame.shading ?? 1) * size <= 1) return null;
|
|
69471
|
+
const { region, view } = frame;
|
|
69472
|
+
const left = Math.floor(Math.max(region.x, view.x) / size) * size;
|
|
69473
|
+
const top = Math.floor(Math.max(region.y, view.y) / size) * size;
|
|
69474
|
+
const right = Math.ceil(Math.min(region.x + region.width, view.x + view.width) / size) * size;
|
|
69475
|
+
const bottom = Math.ceil(Math.min(region.y + region.height, view.y + view.height) / size) * size;
|
|
69476
|
+
return right > left && bottom > top ? {
|
|
69477
|
+
x: left,
|
|
69478
|
+
y: top,
|
|
69479
|
+
width: right - left,
|
|
69480
|
+
height: bottom - top
|
|
69481
|
+
} : null;
|
|
69482
|
+
}
|
|
69483
|
+
function drawTexels(renderer, texels, rect) {
|
|
69484
|
+
const width = Math.round(rect.width / texels.size);
|
|
69485
|
+
const height = Math.round(rect.height / texels.size);
|
|
69486
|
+
let target = texels.target;
|
|
69487
|
+
if (!target || target.width < width || target.height < height) {
|
|
69488
|
+
releaseTexels(texels);
|
|
69489
|
+
const grow = (edge) => Math.ceil(edge / TEXEL_GROWTH) * TEXEL_GROWTH;
|
|
69490
|
+
target = RenderTexture.create({
|
|
69491
|
+
width: grow(width),
|
|
69492
|
+
height: grow(height),
|
|
69493
|
+
resolution: 1,
|
|
69494
|
+
scaleMode: "nearest",
|
|
69495
|
+
antialias: false,
|
|
69496
|
+
autoGenerateMipmaps: false
|
|
69497
|
+
});
|
|
69498
|
+
texels.target = target;
|
|
69499
|
+
texels.sprite.texture = new Texture({
|
|
69500
|
+
source: target.source,
|
|
69501
|
+
frame: new Rectangle(0, 0, width, height),
|
|
69502
|
+
dynamic: true
|
|
69503
|
+
});
|
|
69504
|
+
}
|
|
69505
|
+
const texture = texels.sprite.texture;
|
|
69506
|
+
if (texture.frame.width !== width || texture.frame.height !== height) {
|
|
69507
|
+
texture.frame.width = width;
|
|
69508
|
+
texture.frame.height = height;
|
|
69509
|
+
texture.update();
|
|
69510
|
+
}
|
|
69511
|
+
texels.root.scale.set(1 / texels.size);
|
|
69512
|
+
texels.root.position.set(-rect.x / texels.size, -rect.y / texels.size);
|
|
69513
|
+
renderer.render({
|
|
69514
|
+
container: texels.root,
|
|
69515
|
+
target,
|
|
69516
|
+
clear: true,
|
|
69517
|
+
clearColor: [
|
|
69518
|
+
0,
|
|
69519
|
+
0,
|
|
69520
|
+
0,
|
|
69521
|
+
0
|
|
69522
|
+
]
|
|
69523
|
+
});
|
|
69524
|
+
texels.sprite.position.set(rect.x, rect.y);
|
|
69525
|
+
texels.sprite.scale.set(texels.size);
|
|
69526
|
+
}
|
|
69527
|
+
function releaseTexels(texels) {
|
|
69528
|
+
if (!texels.target) return;
|
|
69529
|
+
texels.sprite.texture.destroy();
|
|
69530
|
+
texels.sprite.texture = Texture.EMPTY;
|
|
69531
|
+
texels.target.destroy(true);
|
|
69532
|
+
texels.target = null;
|
|
69533
|
+
}
|
|
69534
|
+
function destroyTexels(texels) {
|
|
69535
|
+
releaseTexels(texels);
|
|
69536
|
+
texels.sprite.destroy();
|
|
69537
|
+
texels.root.destroy({ children: true });
|
|
69538
|
+
}
|
|
69230
69539
|
function createBoardShaderLayer(renderer, shader, parameters, label, options = {}) {
|
|
69231
69540
|
const uniforms = boardShaderUniforms(shader.uniforms);
|
|
69232
69541
|
const surfaces = shader.surfaces === true;
|
|
@@ -69308,12 +69617,15 @@ function createBoardShaderLayer(renderer, shader, parameters, label, options = {
|
|
|
69308
69617
|
const container = containers[layer];
|
|
69309
69618
|
container.boundsArea = area;
|
|
69310
69619
|
container.addChild(drawn.mesh);
|
|
69620
|
+
const texels = pass.texel ? createTexels(drawn, pass) : null;
|
|
69621
|
+
if (texels) container.addChild(texels.sprite);
|
|
69311
69622
|
meshes.push({
|
|
69312
69623
|
...drawn,
|
|
69313
69624
|
pass,
|
|
69314
69625
|
sprites,
|
|
69315
69626
|
placement,
|
|
69316
|
-
scaler: null
|
|
69627
|
+
scaler: null,
|
|
69628
|
+
texels
|
|
69317
69629
|
});
|
|
69318
69630
|
});
|
|
69319
69631
|
let state = null;
|
|
@@ -69524,8 +69836,14 @@ function createBoardShaderLayer(renderer, shader, parameters, label, options = {
|
|
|
69524
69836
|
area.width = frame.region.width;
|
|
69525
69837
|
area.height = frame.region.height;
|
|
69526
69838
|
for (const drawn of meshes) {
|
|
69527
|
-
|
|
69528
|
-
|
|
69839
|
+
const on = boardShaderPassOn(drawn.pass, frame.passes);
|
|
69840
|
+
const texels = drawn.texels;
|
|
69841
|
+
if (texels) {
|
|
69842
|
+
texels.rect = on ? texelRect(frame, texels.size) : null;
|
|
69843
|
+
texels.sprite.visible = texels.rect !== null;
|
|
69844
|
+
}
|
|
69845
|
+
drawn.mesh.visible = on && !texels?.rect;
|
|
69846
|
+
if (drawn.mesh.visible && !drawn.sprites) shade(drawn, frame);
|
|
69529
69847
|
}
|
|
69530
69848
|
for (const { filter, pass } of filters) filter.enabled = boardShaderPassOn(pass, frame.passes);
|
|
69531
69849
|
fill(group, frame, frame.region);
|
|
@@ -69549,6 +69867,7 @@ function createBoardShaderLayer(renderer, shader, parameters, label, options = {
|
|
|
69549
69867
|
ran: 0,
|
|
69550
69868
|
behind: false
|
|
69551
69869
|
};
|
|
69870
|
+
for (const { texels } of meshes) if (texels?.rect) drawTexels(target, texels, texels.rect);
|
|
69552
69871
|
if (placementsStale || stepped.ran) {
|
|
69553
69872
|
for (const { placement, mesh } of meshes) if (placement && mesh.visible) target.render({
|
|
69554
69873
|
container: placement.mesh.mesh,
|
|
@@ -69590,6 +69909,7 @@ function createBoardShaderLayer(renderer, shader, parameters, label, options = {
|
|
|
69590
69909
|
for (const compile of compiles) compile.cancel();
|
|
69591
69910
|
for (const drawn of meshes) {
|
|
69592
69911
|
drawn.scaler?.destroy();
|
|
69912
|
+
if (drawn.texels) destroyTexels(drawn.texels);
|
|
69593
69913
|
destroyBoardShaderMesh(drawn);
|
|
69594
69914
|
if (drawn.placement) destroyPlacement(renderer, drawn.placement);
|
|
69595
69915
|
}
|
|
@@ -70088,10 +70408,17 @@ function createBrowserBoardScriptExport(readModule, options = {}) {
|
|
|
70088
70408
|
element.style.cssText = "position:fixed;left:-10000px;top:0;width:1px;height:1px;visibility:hidden;pointer-events:none";
|
|
70089
70409
|
globalThis.document.body.appendChild(element);
|
|
70090
70410
|
const outputs = /* @__PURE__ */ new Map();
|
|
70411
|
+
const ranks = /* @__PURE__ */ new Map();
|
|
70412
|
+
const last = /* @__PURE__ */ new Map();
|
|
70091
70413
|
const started = {
|
|
70092
70414
|
element,
|
|
70093
70415
|
outputs,
|
|
70094
70416
|
time: 0,
|
|
70417
|
+
document: null,
|
|
70418
|
+
ranks,
|
|
70419
|
+
outbox: createBoardScriptOutbox(() => ranks),
|
|
70420
|
+
views: /* @__PURE__ */ new Map(),
|
|
70421
|
+
last,
|
|
70095
70422
|
wake: () => {},
|
|
70096
70423
|
host: createBoardScriptHost({
|
|
70097
70424
|
host: element,
|
|
@@ -70100,7 +70427,15 @@ function createBrowserBoardScriptExport(readModule, options = {}) {
|
|
|
70100
70427
|
shaders: options.shaders ?? true,
|
|
70101
70428
|
snapshots: options.snapshots,
|
|
70102
70429
|
timeoutMs: 15e3,
|
|
70103
|
-
capabilities:
|
|
70430
|
+
capabilities: {
|
|
70431
|
+
...Object.fromEntries(Object.entries(BOARD_SCRIPT_EXPORT_CALLS).map(([name, call]) => [name, async (_id, input) => call(input)])),
|
|
70432
|
+
"board.emit": async (id, input) => {
|
|
70433
|
+
if (!started.document) return;
|
|
70434
|
+
const { target, event } = boardScriptEmit(started.document, id, input);
|
|
70435
|
+
last.set(id, `emit(${target}, "${event.type}")`);
|
|
70436
|
+
started.outbox.push(id, target, event);
|
|
70437
|
+
}
|
|
70438
|
+
},
|
|
70104
70439
|
onFrame: () => started.wake(),
|
|
70105
70440
|
onOutput(id, output) {
|
|
70106
70441
|
if (output) outputs.set(id, output);
|
|
@@ -70117,11 +70452,17 @@ function createBrowserBoardScriptExport(readModule, options = {}) {
|
|
|
70117
70452
|
run.element.remove();
|
|
70118
70453
|
run = null;
|
|
70119
70454
|
}
|
|
70120
|
-
function settle(current, document, time) {
|
|
70455
|
+
function settle(current, document, time, view) {
|
|
70121
70456
|
current.time = time;
|
|
70457
|
+
current.document = document;
|
|
70122
70458
|
const { host } = current;
|
|
70123
70459
|
const scene = buildBoardScene(document);
|
|
70124
70460
|
const ids = boardScriptAttachments(document).map(({ id }) => id);
|
|
70461
|
+
current.ranks.clear();
|
|
70462
|
+
for (const [index, id] of ids.entries()) current.ranks.set(id, index);
|
|
70463
|
+
const viewKey = view ? JSON.stringify(view) : null;
|
|
70464
|
+
let viewed = false;
|
|
70465
|
+
let rounds = 0;
|
|
70125
70466
|
return new Promise((resolve, reject) => {
|
|
70126
70467
|
const finish = (error) => {
|
|
70127
70468
|
clearTimeout(timer);
|
|
@@ -70129,7 +70470,7 @@ function createBrowserBoardScriptExport(readModule, options = {}) {
|
|
|
70129
70470
|
if (error) reject(error);
|
|
70130
70471
|
else resolve();
|
|
70131
70472
|
};
|
|
70132
|
-
const timer = setTimeout(() => finish(
|
|
70473
|
+
const timer = setTimeout(() => finish(new Error(["Scripts did not settle in 20 s.", ...status(current, ids)].join(" "))), 2e4);
|
|
70133
70474
|
let queued = false;
|
|
70134
70475
|
const sync = () => {
|
|
70135
70476
|
queued = false;
|
|
@@ -70139,11 +70480,31 @@ function createBrowserBoardScriptExport(readModule, options = {}) {
|
|
|
70139
70480
|
y: 0,
|
|
70140
70481
|
zoom: 1
|
|
70141
70482
|
}, time, false);
|
|
70483
|
+
if (viewKey && !viewed) {
|
|
70484
|
+
viewed = true;
|
|
70485
|
+
for (const id of ids) if (current.views.get(id) !== viewKey) {
|
|
70486
|
+
current.views.set(id, viewKey);
|
|
70487
|
+
host.event(id, {
|
|
70488
|
+
type: "viewchange",
|
|
70489
|
+
data: view
|
|
70490
|
+
});
|
|
70491
|
+
}
|
|
70492
|
+
}
|
|
70142
70493
|
for (const id of ids) {
|
|
70143
70494
|
const error = host.error(id);
|
|
70144
70495
|
if (error) throw new Error(error);
|
|
70145
70496
|
}
|
|
70146
|
-
if (ids.every((id) => host.settled(id)))
|
|
70497
|
+
if (!ids.every((id) => host.settled(id))) return;
|
|
70498
|
+
if (current.outbox.size && rounds++ <= 16) {
|
|
70499
|
+
for (const [target, events] of current.outbox.take()) {
|
|
70500
|
+
current.last.set(target, `event ${events.map((event) => event.type).join(", ")}`);
|
|
70501
|
+
for (const event of events) host.event(target, event);
|
|
70502
|
+
}
|
|
70503
|
+
current.wake();
|
|
70504
|
+
return;
|
|
70505
|
+
}
|
|
70506
|
+
current.outbox.take();
|
|
70507
|
+
finish();
|
|
70147
70508
|
} catch (error) {
|
|
70148
70509
|
finish(error);
|
|
70149
70510
|
}
|
|
@@ -70156,8 +70517,16 @@ function createBrowserBoardScriptExport(readModule, options = {}) {
|
|
|
70156
70517
|
current.wake();
|
|
70157
70518
|
});
|
|
70158
70519
|
}
|
|
70520
|
+
function status(current, ids) {
|
|
70521
|
+
return ids.flatMap((id) => {
|
|
70522
|
+
if (current.host.settled(id)) return [];
|
|
70523
|
+
const state = current.host.output(id) ? "is still running" : "has not started";
|
|
70524
|
+
const last = current.last.get(id);
|
|
70525
|
+
return [`${id} ${state}${last ? `; last ${last}` : ""}.`];
|
|
70526
|
+
});
|
|
70527
|
+
}
|
|
70159
70528
|
return {
|
|
70160
|
-
async at(document, time) {
|
|
70529
|
+
async at(document, time, view) {
|
|
70161
70530
|
if (!Number.isFinite(time) || time < 0 || time > 6e5) throw new Error("Script export time must be between 0 and 600000 ms.");
|
|
70162
70531
|
if (run && time < run.time) stop();
|
|
70163
70532
|
const fresh = !run;
|
|
@@ -70188,7 +70557,7 @@ function createBrowserBoardScriptExport(readModule, options = {}) {
|
|
|
70188
70557
|
}
|
|
70189
70558
|
if (boardScriptParamsKey(document) !== previous && before.at > ran) await settle(current, before.document, before.at);
|
|
70190
70559
|
}
|
|
70191
|
-
await settle(current, document, time);
|
|
70560
|
+
await settle(current, document, time, view);
|
|
70192
70561
|
return {
|
|
70193
70562
|
...host,
|
|
70194
70563
|
shaders: (input) => boardShaderOwners(input, outputs, (id) => host.clock(id)),
|
|
@@ -70356,6 +70725,7 @@ function buildContext(input) {
|
|
|
70356
70725
|
scene: input.scene,
|
|
70357
70726
|
time: input.time ?? 0,
|
|
70358
70727
|
frameAt: input.frameAt,
|
|
70728
|
+
...input.page ? { page: input.page } : {},
|
|
70359
70729
|
selectedIds: /* @__PURE__ */ new Set(),
|
|
70360
70730
|
hoveredId: null,
|
|
70361
70731
|
resizingIds: /* @__PURE__ */ new Set(),
|
|
@@ -70496,6 +70866,7 @@ function createBoardExportScene(input) {
|
|
|
70496
70866
|
const container = containers.get(owner.id);
|
|
70497
70867
|
if (!item || !container) return null;
|
|
70498
70868
|
const group = isSelfGroupedFrame(item) ? groups.get(item.id)?.group : void 0;
|
|
70869
|
+
for (const part of [layer.below, layer.above]) if (part && item.type === "frame") clipFrameShaderLayer(part, item);
|
|
70499
70870
|
if (layer.below) container.addChildAt(layer.below, 0);
|
|
70500
70871
|
if (layer.above) {
|
|
70501
70872
|
if (group) {
|
|
@@ -70647,6 +71018,7 @@ function renderBoardExport(renderer, input, options = {}) {
|
|
|
70647
71018
|
colorScheme
|
|
70648
71019
|
}),
|
|
70649
71020
|
backdropTexture: options.backgroundTexture,
|
|
71021
|
+
...plan.page ? { page: plan.page } : {},
|
|
70650
71022
|
...gpu && owners.length ? { shaders: {
|
|
70651
71023
|
renderer,
|
|
70652
71024
|
owners,
|
|
@@ -70699,6 +71071,10 @@ function renderBoardExport(renderer, input, options = {}) {
|
|
|
70699
71071
|
kind: "shader-failed",
|
|
70700
71072
|
...failure
|
|
70701
71073
|
});
|
|
71074
|
+
if (gpu) for (const miss of boardShaderMisses(scene, plan, owners, exportScene.shaderErrors)) warnings.push({
|
|
71075
|
+
kind: "shader-hidden",
|
|
71076
|
+
...miss
|
|
71077
|
+
});
|
|
70702
71078
|
return {
|
|
70703
71079
|
canvas,
|
|
70704
71080
|
plan,
|
|
@@ -70709,6 +71085,38 @@ function renderBoardExport(renderer, input, options = {}) {
|
|
|
70709
71085
|
flattened?.();
|
|
70710
71086
|
}
|
|
70711
71087
|
}
|
|
71088
|
+
function boardShaderMisses(scene, plan, owners, failed = []) {
|
|
71089
|
+
const planned = new Set(plan.items.map((item) => item.id));
|
|
71090
|
+
const misses = owners.flatMap(({ id, root, output }) => {
|
|
71091
|
+
if (failed.some((failure) => failure.id === id)) return [];
|
|
71092
|
+
const shader = output.shader;
|
|
71093
|
+
if (shader && !shader.state && shader.passes.every((pass) => !boardShaderPassOn(pass, output.passes))) return [{
|
|
71094
|
+
id,
|
|
71095
|
+
reason: "every pass is switched off (ctx.passes() or enabled: false)"
|
|
71096
|
+
}];
|
|
71097
|
+
if (root) return [];
|
|
71098
|
+
const item = scene.get(id);
|
|
71099
|
+
if (!item) return [{
|
|
71100
|
+
id,
|
|
71101
|
+
reason: "its item is not in the document"
|
|
71102
|
+
}];
|
|
71103
|
+
if (scene.opacity(id) <= 0) return [{
|
|
71104
|
+
id,
|
|
71105
|
+
reason: "its item is hidden (opacity 0 or invisible)"
|
|
71106
|
+
}];
|
|
71107
|
+
if (planned.has(id)) return [];
|
|
71108
|
+
return [{
|
|
71109
|
+
id,
|
|
71110
|
+
reason: exportItemBounds(item, scene) ? "its item is outside the exported area" : "its item is clipped away by a parent frame"
|
|
71111
|
+
}];
|
|
71112
|
+
});
|
|
71113
|
+
const grouped = /* @__PURE__ */ new Map();
|
|
71114
|
+
for (const { id, reason } of misses) grouped.set(reason, [...grouped.get(reason) ?? [], id]);
|
|
71115
|
+
return [...grouped].map(([reason, ids]) => ({
|
|
71116
|
+
ids,
|
|
71117
|
+
reason
|
|
71118
|
+
}));
|
|
71119
|
+
}
|
|
70712
71120
|
//#endregion
|
|
70713
71121
|
//#region src/board-gpu/page.ts
|
|
70714
71122
|
let renderer = null;
|
|
@@ -70816,6 +71224,7 @@ globalThis.cohubBoardGpu = {
|
|
|
70816
71224
|
},
|
|
70817
71225
|
async profile(input) {
|
|
70818
71226
|
if (!renderer || !session) throw new Error("The GPU exporter is not ready.");
|
|
71227
|
+
const started = performance.now();
|
|
70819
71228
|
const target = renderer;
|
|
70820
71229
|
const { document, animation, theme: themeId } = session.init;
|
|
70821
71230
|
const theme = boardRenderTheme(themeId);
|
|
@@ -70824,26 +71233,37 @@ globalThis.cohubBoardGpu = {
|
|
|
70824
71233
|
time: input.time
|
|
70825
71234
|
};
|
|
70826
71235
|
const time = input.time ?? 0;
|
|
70827
|
-
const
|
|
70828
|
-
const
|
|
70829
|
-
sampler
|
|
71236
|
+
const sampler = session.sampler;
|
|
71237
|
+
const options = {
|
|
71238
|
+
sampler,
|
|
70830
71239
|
region: input.region,
|
|
70831
71240
|
camera: input.camera,
|
|
70832
71241
|
scale: input.scale,
|
|
70833
|
-
|
|
71242
|
+
padding: 0,
|
|
71243
|
+
...at ? { at } : {}
|
|
71244
|
+
};
|
|
71245
|
+
const planned = prepareBoardExport(document, options);
|
|
71246
|
+
if (!planned) throw new Error("Nothing to profile: the region contains no items.");
|
|
71247
|
+
const scripts = await session.scripts.at(at ? sampler.at(time).document : document, time, boardExportView(planned.plan));
|
|
71248
|
+
const gl = target.gl;
|
|
71249
|
+
const info = gl.getExtension("WEBGL_debug_renderer_info");
|
|
71250
|
+
const rendererName = String(info ? gl.getParameter(info.UNMASKED_RENDERER_WEBGL) : gl.getParameter(gl.RENDERER));
|
|
71251
|
+
const prepared = prepareBoardExport(document, {
|
|
71252
|
+
...options,
|
|
70834
71253
|
scripts
|
|
70835
71254
|
});
|
|
70836
71255
|
if (!prepared) throw new Error("Nothing to profile: the region contains no items.");
|
|
70837
71256
|
const visible = prepared.plan.items.filter((item) => prepared.scene.opacity(item.id) > 0);
|
|
70838
71257
|
const loaded = input.withImages ? await loadTextures(visible, prepared.plan.scale, input.imageMemory, {}) : /* @__PURE__ */ new Map();
|
|
70839
|
-
const
|
|
71258
|
+
const inside = new Set(prepared.plan.items.map((item) => item.id));
|
|
71259
|
+
const owners = (scripts.shaders?.(prepared.document, time) ?? []).filter((owner) => owner.root || inside.has(owner.id));
|
|
70840
71260
|
const layers = createBoardShaderLayers({ wait: true });
|
|
70841
71261
|
const scene = createBoardExportScene({
|
|
70842
71262
|
settings: prepared.document.board,
|
|
70843
71263
|
scene: prepared.scene,
|
|
70844
71264
|
items: prepared.plan.items,
|
|
70845
71265
|
time,
|
|
70846
|
-
frameAt:
|
|
71266
|
+
frameAt: sampler.frameAt,
|
|
70847
71267
|
world: prepared.plan.world,
|
|
70848
71268
|
scale: prepared.plan.scale,
|
|
70849
71269
|
colorScheme: theme.colorScheme,
|
|
@@ -70853,76 +71273,128 @@ globalThis.cohubBoardGpu = {
|
|
|
70853
71273
|
textures: loaded,
|
|
70854
71274
|
scripts,
|
|
70855
71275
|
assetKey: boardAssetKey,
|
|
71276
|
+
...prepared.plan.page ? { page: prepared.plan.page } : {},
|
|
70856
71277
|
...owners.length ? { shaders: {
|
|
70857
71278
|
renderer: target,
|
|
70858
71279
|
owners,
|
|
70859
71280
|
layers
|
|
70860
71281
|
} } : {}
|
|
70861
71282
|
});
|
|
70862
|
-
const { width, height } = prepared.plan;
|
|
70863
|
-
const output = RenderTexture.create({
|
|
70864
|
-
width,
|
|
70865
|
-
height
|
|
70866
|
-
});
|
|
70867
|
-
const gl = target.gl;
|
|
70868
71283
|
const pixel = /* @__PURE__ */ new Uint8Array(4);
|
|
70869
|
-
|
|
70870
|
-
|
|
70871
|
-
|
|
70872
|
-
|
|
70873
|
-
|
|
70874
|
-
|
|
70875
|
-
|
|
70876
|
-
|
|
70877
|
-
|
|
70878
|
-
|
|
70879
|
-
|
|
70880
|
-
}
|
|
70881
|
-
|
|
71284
|
+
let size = {
|
|
71285
|
+
width: prepared.plan.width,
|
|
71286
|
+
height: prepared.plan.height
|
|
71287
|
+
};
|
|
71288
|
+
let output = RenderTexture.create(size);
|
|
71289
|
+
let transform;
|
|
71290
|
+
const resize = (factor) => {
|
|
71291
|
+
output.destroy(true);
|
|
71292
|
+
size = {
|
|
71293
|
+
width: Math.max(1, Math.round(prepared.plan.width * factor)),
|
|
71294
|
+
height: Math.max(1, Math.round(prepared.plan.height * factor))
|
|
71295
|
+
};
|
|
71296
|
+
output = RenderTexture.create(size);
|
|
71297
|
+
transform = new Matrix().scale(factor, factor);
|
|
71298
|
+
};
|
|
71299
|
+
const render = () => {
|
|
71300
|
+
const start = performance.now();
|
|
71301
|
+
layers.prepare(target);
|
|
71302
|
+
target.render({
|
|
71303
|
+
container: scene.root,
|
|
71304
|
+
target: output,
|
|
71305
|
+
clear: true,
|
|
71306
|
+
...transform ? { transform } : {}
|
|
71307
|
+
});
|
|
71308
|
+
gl.readPixels(0, 0, 1, 1, gl.RGBA, gl.UNSIGNED_BYTE, pixel);
|
|
71309
|
+
return performance.now() - start;
|
|
70882
71310
|
};
|
|
70883
71311
|
try {
|
|
70884
|
-
|
|
70885
|
-
const
|
|
70886
|
-
|
|
70887
|
-
|
|
70888
|
-
|
|
70889
|
-
|
|
71312
|
+
render();
|
|
71313
|
+
const renders = (frames) => frames * input.rounds * (1 + owners.length);
|
|
71314
|
+
let frames = input.frames;
|
|
71315
|
+
let frameMs = Math.max(render(), .1);
|
|
71316
|
+
let reduced = null;
|
|
71317
|
+
let factor = 1;
|
|
71318
|
+
const budget = Math.max(input.budgetMs / 4, input.budgetMs - (performance.now() - started));
|
|
71319
|
+
for (let attempt = 0; attempt < 3 && frameMs * renders(frames) > budget; attempt++) {
|
|
71320
|
+
reduced ??= {
|
|
71321
|
+
...size,
|
|
71322
|
+
frames,
|
|
71323
|
+
frameMs
|
|
71324
|
+
};
|
|
71325
|
+
frames = Math.max(3, Math.min(frames, Math.floor(budget / (frameMs * renders(1)))));
|
|
71326
|
+
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)));
|
|
71327
|
+
if (next > factor * .98) break;
|
|
71328
|
+
factor = next;
|
|
71329
|
+
resize(factor);
|
|
71330
|
+
render();
|
|
71331
|
+
frameMs = Math.max(render(), .1);
|
|
71332
|
+
}
|
|
71333
|
+
const measure = () => {
|
|
71334
|
+
const samples = [];
|
|
71335
|
+
for (let frame = 0; frame < frames; frame++) samples.push(render());
|
|
71336
|
+
return samples.sort((a, b) => a - b);
|
|
71337
|
+
};
|
|
71338
|
+
const median = (samples) => [...samples].sort((a, b) => a - b)[Math.floor(samples.length / 2)] ?? 0;
|
|
71339
|
+
const all = [];
|
|
71340
|
+
const costs = new Map(owners.map((owner) => [owner.id, []]));
|
|
71341
|
+
const measuring = performance.now();
|
|
71342
|
+
let rounds = 0;
|
|
71343
|
+
for (; rounds < input.rounds; rounds++) {
|
|
71344
|
+
if (rounds && (performance.now() - measuring) * (rounds + 1) / rounds > budget * 1.25) break;
|
|
71345
|
+
const samples = measure();
|
|
71346
|
+
all.push(...samples);
|
|
71347
|
+
const base = median(samples);
|
|
71348
|
+
for (const owner of owners) {
|
|
71349
|
+
const layer = layers.layer(owner.id);
|
|
71350
|
+
const parts = [layer?.below, layer?.above].filter((part) => part !== null && part !== void 0);
|
|
71351
|
+
const filters = layer?.filters ?? [];
|
|
71352
|
+
const shown = parts.map((part) => part.visible);
|
|
71353
|
+
const enabled = filters.map((filter) => filter.enabled);
|
|
71354
|
+
for (const part of parts) part.visible = false;
|
|
71355
|
+
for (const filter of filters) filter.enabled = false;
|
|
71356
|
+
const without = median(measure());
|
|
71357
|
+
parts.forEach((part, index) => {
|
|
71358
|
+
part.visible = shown[index];
|
|
71359
|
+
});
|
|
71360
|
+
filters.forEach((filter, index) => {
|
|
71361
|
+
filter.enabled = enabled[index];
|
|
71362
|
+
});
|
|
71363
|
+
costs.get(owner.id)?.push(Math.max(0, base - without));
|
|
71364
|
+
}
|
|
71365
|
+
}
|
|
71366
|
+
all.sort((a, b) => a - b);
|
|
71367
|
+
const p50 = median(all);
|
|
71368
|
+
const results = owners.map((owner) => {
|
|
70890
71369
|
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
|
-
});
|
|
71370
|
+
const rounds = costs.get(owner.id) ?? [0];
|
|
70904
71371
|
const filterPasses = shader?.passes.filter((pass) => (pass.layer ?? shader.layer) === "filter") ?? [];
|
|
70905
71372
|
return {
|
|
70906
71373
|
id: owner.id,
|
|
70907
|
-
ms:
|
|
71374
|
+
ms: median(rounds),
|
|
71375
|
+
range: [Math.min(...rounds), Math.max(...rounds)],
|
|
70908
71376
|
filter: !filterPasses.length ? "none" : filterPasses.every((pass) => pass.name) ? "switchable" : "always",
|
|
70909
71377
|
sprites: shader?.passes.reduce((sum, pass) => sum + (pass.sprites ?? 0), 0) ?? 0,
|
|
71378
|
+
boxes: shader?.passes.filter((pass) => !pass.sprites && !pass.texel && (pass.layer ?? shader.layer) !== "filter").length ?? 0,
|
|
70910
71379
|
state: shader?.state ? {
|
|
70911
71380
|
width: shader.state.width,
|
|
70912
71381
|
height: shader.state.height
|
|
70913
71382
|
} : null
|
|
70914
71383
|
};
|
|
70915
71384
|
});
|
|
70916
|
-
const info = gl.getExtension("WEBGL_debug_renderer_info");
|
|
70917
71385
|
return {
|
|
70918
|
-
renderer:
|
|
70919
|
-
|
|
70920
|
-
|
|
71386
|
+
renderer: rendererName,
|
|
71387
|
+
gpu: /swiftshader|llvmpipe|softpipe|software|basic render/i.test(rendererName) ? "software" : "hardware",
|
|
71388
|
+
...size,
|
|
71389
|
+
frames,
|
|
71390
|
+
rounds,
|
|
71391
|
+
reduced,
|
|
71392
|
+
elapsedMs: performance.now() - started,
|
|
70921
71393
|
frame: {
|
|
70922
|
-
p50
|
|
70923
|
-
p95: all[Math.min(all.length - 1, Math.floor(all.length * .95))] ??
|
|
71394
|
+
p50,
|
|
71395
|
+
p95: all[Math.min(all.length - 1, Math.floor(all.length * .95))] ?? p50
|
|
70924
71396
|
},
|
|
70925
|
-
owners:
|
|
71397
|
+
owners: results.sort((a, b) => b.ms - a.ms),
|
|
70926
71398
|
effects: visible.filter((item) => hasBoardEffects(item.style)).length,
|
|
70927
71399
|
items: visible.length
|
|
70928
71400
|
};
|
|
@@ -70942,7 +71414,15 @@ globalThis.cohubBoardGpu = {
|
|
|
70942
71414
|
};
|
|
70943
71415
|
const time = frame.time ?? 0;
|
|
70944
71416
|
const sample = at ? session.sampler.at(time).document : document;
|
|
70945
|
-
const
|
|
71417
|
+
const planned = prepareBoardExport(document, {
|
|
71418
|
+
sampler: session.sampler,
|
|
71419
|
+
region: frame.region,
|
|
71420
|
+
camera: frame.camera,
|
|
71421
|
+
scale: frame.scale,
|
|
71422
|
+
padding: frame.padding,
|
|
71423
|
+
...at ? { at } : {}
|
|
71424
|
+
});
|
|
71425
|
+
const scripts = await session.scripts.at(sample, time, planned ? boardExportView(planned.plan) : void 0);
|
|
70946
71426
|
const options = {
|
|
70947
71427
|
sampler: session.sampler,
|
|
70948
71428
|
region: frame.region,
|