@neta-art/cohub-cli 10.18.0 → 10.20.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/dist/board-export.d.ts +9 -2
- package/dist/board-export.js +83 -45
- package/dist/board-gpu/daemon.d.ts +11 -0
- package/dist/board-gpu/daemon.js +302 -0
- package/dist/board-gpu/index.d.ts +3 -2
- package/dist/board-gpu/index.js +1 -0
- package/dist/board-gpu/page.js +1202 -396
- package/dist/board-gpu/protocol.d.ts +27 -1
- package/dist/board-kernel.d.ts +1 -1
- package/dist/board-kernel.js +2075 -461
- package/dist/board-media-export.d.ts +16 -0
- package/dist/board-media-export.js +147 -0
- package/dist/board-media.d.ts +2 -1
- package/dist/board-media.js +23 -0
- package/dist/board-profile.d.ts +19 -0
- package/dist/board-profile.js +53 -0
- package/dist/board-simulate.d.ts +3 -0
- package/dist/board-simulate.js +27 -7
- package/dist/commands/boards/authoring.js +45 -3
- package/dist/commands/boards.js +83 -5
- package/dist/commands/space-displays.d.ts +1 -1
- package/dist/commands/space-displays.js +70 -18
- package/dist/output.d.ts +1 -0
- package/dist/output.js +3 -0
- package/dist/safe-remote-image.d.ts +4 -0
- package/dist/safe-remote-image.js +8 -0
- package/package.json +2 -2
package/dist/board-gpu/page.js
CHANGED
|
@@ -5944,6 +5944,7 @@ const itemEnvelope$1 = {
|
|
|
5944
5944
|
y: .5
|
|
5945
5945
|
}).describe("Rotation and scale origin as fractions of the size."),
|
|
5946
5946
|
opacity: ratio$1.default(1),
|
|
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."),
|
|
5947
5948
|
style: BoardStyleSchema$1.default({}),
|
|
5948
5949
|
locked: boolean().optional(),
|
|
5949
5950
|
metadata: record(string(), unknown()).optional()
|
|
@@ -6093,7 +6094,8 @@ const mediaProps$1 = {
|
|
|
6093
6094
|
};
|
|
6094
6095
|
const timedFileProps$1 = {
|
|
6095
6096
|
...mediaProps$1,
|
|
6096
|
-
time: nonNegative$1.optional().describe("Playback position in milliseconds; animate props.time to play it on a timeline.")
|
|
6097
|
+
time: nonNegative$1.optional().describe("Playback position in milliseconds; animate props.time to play it on a timeline. It sounds while its time moves forward."),
|
|
6098
|
+
volume: ratio$1.optional().describe("Loudness from 0 to 1; defaults to 1. Animate it to fade.")
|
|
6097
6099
|
};
|
|
6098
6100
|
const BoardCropSchema$1 = object({
|
|
6099
6101
|
x: ratio$1,
|
|
@@ -7152,6 +7154,10 @@ function resolveBoardProperty(targetType, property) {
|
|
|
7152
7154
|
ok: false,
|
|
7153
7155
|
message: `Board scripts animate params.<name>, not ${property}`
|
|
7154
7156
|
};
|
|
7157
|
+
if (/^script\.params\.[^.]+$/.test(property)) return {
|
|
7158
|
+
ok: true,
|
|
7159
|
+
spec: SCRIPT_PARAMETER
|
|
7160
|
+
};
|
|
7155
7161
|
const path = property.split(".");
|
|
7156
7162
|
if (path.some((segment) => !segment) || NOT_ANIMATABLE.has(path[0])) return {
|
|
7157
7163
|
ok: false,
|
|
@@ -7507,6 +7513,7 @@ function validateTrack(path, animationId, value, item, animation, track, script,
|
|
|
7507
7513
|
if (value.target === animationId || nestsInto(value.target, animationId, animation, track, state)) return [error(`${path}.target`, "ANIMATION_CYCLE", `${animationId} cannot contain itself through ${value.target}`)];
|
|
7508
7514
|
} else if (script(value.target)) targetType = "script";
|
|
7509
7515
|
else return [error(`${path}.target`, "TARGET_NOT_FOUND", `target ${value.target} is not an item, animation, Board script or camera`)];
|
|
7516
|
+
if (!keepUnknownProperty && value.property.startsWith("script.") && !item(value.target)?.script) return [error(`${path}.property`, "INVALID_PROPERTY", `${value.target} has no script to animate`)];
|
|
7510
7517
|
const resolved = resolveBoardProperty(targetType, value.property);
|
|
7511
7518
|
if (!resolved.ok) return keepUnknownProperty ? [] : [error(`${path}.property`, "INVALID_PROPERTY", resolved.message)];
|
|
7512
7519
|
for (const [index, keyframe] of value.keyframes.entries()) {
|
|
@@ -8146,6 +8153,12 @@ function boardShaderUniformValue(uniform, value) {
|
|
|
8146
8153
|
while (list.length < size) list.push(0);
|
|
8147
8154
|
return list;
|
|
8148
8155
|
}
|
|
8156
|
+
function boardShaderPassLayer(shader, pass) {
|
|
8157
|
+
return pass.layer ?? shader.layer ?? "above";
|
|
8158
|
+
}
|
|
8159
|
+
function boardShaderPassOn(pass, states) {
|
|
8160
|
+
return (pass.name !== void 0 ? states?.[pass.name] : void 0) ?? pass.enabled ?? true;
|
|
8161
|
+
}
|
|
8149
8162
|
function boardShaderParameters(parameters) {
|
|
8150
8163
|
const result = [];
|
|
8151
8164
|
for (const [name, spec] of Object.entries(parameters ?? {})) {
|
|
@@ -8167,13 +8180,22 @@ function validateBoardShader(shader) {
|
|
|
8167
8180
|
if (value.layer !== void 0 && !BOARD_SHADER_LAYERS.includes(value.layer)) throw new Error(`shader.layer must be ${BOARD_SHADER_LAYERS.join(", ")}.`);
|
|
8168
8181
|
if (value.surfaces !== void 0 && typeof value.surfaces !== "boolean") throw new Error("shader.surfaces must be a boolean.");
|
|
8169
8182
|
if (!Array.isArray(value.passes) || value.passes.length < 1 || value.passes.length > BOARD_SHADER_LIMITS.passes) throw new Error(`shader.passes takes 1 to ${BOARD_SHADER_LIMITS.passes} passes.`);
|
|
8183
|
+
const names = /* @__PURE__ */ new Set();
|
|
8170
8184
|
for (const pass of value.passes) {
|
|
8171
8185
|
if (!pass || typeof pass.glsl !== "string" || !pass.glsl.trim()) throw new Error("Each shader pass needs glsl source.");
|
|
8172
8186
|
if (pass.glsl.length > BOARD_SHADER_LIMITS.source) throw new Error("A shader pass exceeds 64 KB of source.");
|
|
8187
|
+
if (pass.layer !== void 0 && !BOARD_SHADER_LAYERS.includes(pass.layer)) throw new Error(`A pass layer must be ${BOARD_SHADER_LAYERS.join(", ")}.`);
|
|
8173
8188
|
if (pass.sprites !== void 0) {
|
|
8174
8189
|
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}.`);
|
|
8175
|
-
if (value
|
|
8190
|
+
if (boardShaderPassLayer(value, pass) === "filter") throw new Error("Filter passes draw over the owner's box; they cannot draw sprites.");
|
|
8191
|
+
}
|
|
8192
|
+
if (pass.name !== void 0) {
|
|
8193
|
+
if (typeof pass.name !== "string" || !IDENTIFIER.test(pass.name)) throw new Error(`Invalid pass name: ${String(pass.name)}`);
|
|
8194
|
+
if (names.has(pass.name)) throw new Error(`Pass names must be unique: ${pass.name}`);
|
|
8195
|
+
names.add(pass.name);
|
|
8176
8196
|
}
|
|
8197
|
+
if (pass.enabled !== void 0 && typeof pass.enabled !== "boolean") throw new Error("A pass's enabled must be a boolean.");
|
|
8198
|
+
if (pass.enabled === false && pass.name === void 0) throw new Error("A pass that starts off needs a name to turn it on.");
|
|
8177
8199
|
if (pass.blend !== void 0 && !BOARD_SHADER_BLENDS.includes(pass.blend)) throw new Error(`blend must be ${BOARD_SHADER_BLENDS.join(", ")}.`);
|
|
8178
8200
|
}
|
|
8179
8201
|
boardShaderUniforms(value.uniforms);
|
|
@@ -8636,10 +8658,10 @@ function parameterKind(track) {
|
|
|
8636
8658
|
if (values.every((value) => BoardColorSchema$1.safeParse(value).success)) return "color";
|
|
8637
8659
|
return "discrete";
|
|
8638
8660
|
}
|
|
8639
|
-
function
|
|
8661
|
+
function compileBoardTrack(animationId, id, track, targetType) {
|
|
8640
8662
|
const resolved = resolveBoardProperty(targetType, track.property);
|
|
8641
8663
|
if (!resolved.ok) return null;
|
|
8642
|
-
const kind = targetType === "script" ? parameterKind(track) : resolved.spec.kind;
|
|
8664
|
+
const kind = targetType === "script" || track.property.startsWith("script.params.") ? parameterKind(track) : resolved.spec.kind;
|
|
8643
8665
|
const times = new Float64Array(track.keyframes.length);
|
|
8644
8666
|
const values = [];
|
|
8645
8667
|
const eases = [];
|
|
@@ -8694,7 +8716,7 @@ function compileAnimation(animationId, animation, document) {
|
|
|
8694
8716
|
for (const [id, track] of Object.entries(tracks).sort(([a], [b]) => a < b ? -1 : a > b ? 1 : 0)) {
|
|
8695
8717
|
const targetType = track.target === "camera" ? BOARD_CAMERA_TARGET$1 : document.animations[track.target] ? "animation" : document.board.scripts?.[track.target] ? "script" : document.items[track.target]?.type;
|
|
8696
8718
|
if (!targetType) continue;
|
|
8697
|
-
const entry =
|
|
8719
|
+
const entry = compileBoardTrack(animationId, id, track, targetType);
|
|
8698
8720
|
if (!entry) continue;
|
|
8699
8721
|
(targetType === "animation" ? children : compiled).push(entry);
|
|
8700
8722
|
}
|
|
@@ -8929,10 +8951,14 @@ function evaluateBoardAnimations(compiled, times, options = {}) {
|
|
|
8929
8951
|
const ordered = [...groups.values()].sort((a, b) => a.path.length - b.path.length);
|
|
8930
8952
|
for (const group of ordered) {
|
|
8931
8953
|
const isCamera = group.target === BOARD_CAMERA_TARGET$1;
|
|
8932
|
-
const
|
|
8954
|
+
const rootScript = isCamera ? void 0 : compiled.document.board.scripts?.[group.target];
|
|
8955
|
+
const itemScript = isCamera || rootScript || group.path[0] !== "script" ? void 0 : compiled.document.items[group.target]?.script;
|
|
8956
|
+
const script = rootScript || itemScript ? scripts.get(group.target) ?? rootScript ?? itemScript : void 0;
|
|
8957
|
+
if (group.path[0] === "script" && !itemScript) continue;
|
|
8958
|
+
const path = itemScript ? group.path.slice(1) : group.path;
|
|
8933
8959
|
const base = isCamera || script ? void 0 : items.get(group.target) ?? compiled.document.items[group.target];
|
|
8934
8960
|
if (!isCamera && !script && !base) continue;
|
|
8935
|
-
let value = isCamera ? camera[
|
|
8961
|
+
let value = isCamera ? camera[path[0]] : readPath(script ?? base, path);
|
|
8936
8962
|
let orientTrack = null;
|
|
8937
8963
|
if (group.winner) {
|
|
8938
8964
|
value = sampleBoardTrack(group.winner, group.winnerTime, resolveColor);
|
|
@@ -8947,7 +8973,7 @@ function evaluateBoardAnimations(compiled, times, options = {}) {
|
|
|
8947
8973
|
continue;
|
|
8948
8974
|
}
|
|
8949
8975
|
if (script) {
|
|
8950
|
-
scripts.set(group.target, writePath(script,
|
|
8976
|
+
scripts.set(group.target, writePath(script, path, value));
|
|
8951
8977
|
continue;
|
|
8952
8978
|
}
|
|
8953
8979
|
let next = writePath(base, group.path, value);
|
|
@@ -8967,30 +8993,62 @@ function evaluateBoardAnimations(compiled, times, options = {}) {
|
|
|
8967
8993
|
times: local
|
|
8968
8994
|
};
|
|
8969
8995
|
}
|
|
8996
|
+
const BOARD_SCRIPT_HISTORY_MS = 1e3 / 30;
|
|
8997
|
+
function boardScriptParamsKey(document) {
|
|
8998
|
+
const params = [];
|
|
8999
|
+
for (const script of Object.values(document.board.scripts ?? {})) params.push(script.params);
|
|
9000
|
+
for (const item of Object.values(document.items)) if (item.script) params.push(item.script.params);
|
|
9001
|
+
return JSON.stringify(params);
|
|
9002
|
+
}
|
|
9003
|
+
function boardAnimatesScriptParams(document) {
|
|
9004
|
+
return Object.values(document.animations).some((animation) => Object.values(animation.tracks).some((track) => /^(script\.)?params\./.test(track.property)));
|
|
9005
|
+
}
|
|
8970
9006
|
function withBoardScripts(document, scripts) {
|
|
9007
|
+
if (scripts.size === 0) return document;
|
|
8971
9008
|
const stored = document.board.scripts;
|
|
8972
|
-
|
|
8973
|
-
|
|
9009
|
+
let board = document.board;
|
|
9010
|
+
let items = document.items;
|
|
8974
9011
|
for (const [id, script] of scripts) {
|
|
8975
|
-
const
|
|
8976
|
-
if (
|
|
8977
|
-
|
|
8978
|
-
|
|
9012
|
+
const root = stored?.[id];
|
|
9013
|
+
if (root) {
|
|
9014
|
+
if (board === document.board) board = {
|
|
9015
|
+
...board,
|
|
9016
|
+
scripts: { ...stored }
|
|
9017
|
+
};
|
|
9018
|
+
board.scripts[id] = {
|
|
9019
|
+
...root,
|
|
9020
|
+
params: script.params
|
|
9021
|
+
};
|
|
9022
|
+
continue;
|
|
9023
|
+
}
|
|
9024
|
+
const item = items[id];
|
|
9025
|
+
if (!item?.script) continue;
|
|
9026
|
+
if (items === document.items) items = { ...items };
|
|
9027
|
+
items[id] = {
|
|
9028
|
+
...item,
|
|
9029
|
+
script: {
|
|
9030
|
+
...item.script,
|
|
9031
|
+
params: script.params
|
|
9032
|
+
}
|
|
8979
9033
|
};
|
|
8980
9034
|
}
|
|
8981
|
-
return {
|
|
9035
|
+
return board === document.board && items === document.items ? document : {
|
|
8982
9036
|
...document,
|
|
8983
|
-
board
|
|
8984
|
-
|
|
8985
|
-
scripts: next
|
|
8986
|
-
}
|
|
9037
|
+
board,
|
|
9038
|
+
items
|
|
8987
9039
|
};
|
|
8988
9040
|
}
|
|
8989
9041
|
function applyBoardEvaluation(document, evaluation) {
|
|
8990
9042
|
const scripted = withBoardScripts(document, evaluation.scripts);
|
|
8991
9043
|
if (evaluation.items.size === 0) return scripted;
|
|
8992
|
-
const items = { ...
|
|
8993
|
-
for (const [id, item] of evaluation.items)
|
|
9044
|
+
const items = { ...scripted.items };
|
|
9045
|
+
for (const [id, item] of evaluation.items) {
|
|
9046
|
+
const script = scripted.items[id]?.script;
|
|
9047
|
+
items[id] = script && script !== document.items[id]?.script ? {
|
|
9048
|
+
...item,
|
|
9049
|
+
script
|
|
9050
|
+
} : item;
|
|
9051
|
+
}
|
|
8994
9052
|
return {
|
|
8995
9053
|
...scripted,
|
|
8996
9054
|
items
|
|
@@ -9077,16 +9135,18 @@ function buildBoardScene(document, previous) {
|
|
|
9077
9135
|
return result;
|
|
9078
9136
|
},
|
|
9079
9137
|
binders: (id) => binders.get(id) ?? [],
|
|
9080
|
-
opacity: (id) => cumulativeOpacity((key) => items[key], id)
|
|
9138
|
+
opacity: (id) => cumulativeOpacity((key) => items[key], id),
|
|
9139
|
+
shown: (id) => cumulativeOpacity((key) => items[key], id, true) > 0
|
|
9081
9140
|
};
|
|
9082
9141
|
}
|
|
9083
|
-
function cumulativeOpacity(lookup, id) {
|
|
9142
|
+
function cumulativeOpacity(lookup, id, presence = false) {
|
|
9084
9143
|
let value = 1;
|
|
9085
9144
|
let cursor = id;
|
|
9086
9145
|
for (let depth = 0; cursor && depth < 64; depth += 1) {
|
|
9087
9146
|
const item = lookup(cursor);
|
|
9088
9147
|
if (!item) break;
|
|
9089
|
-
|
|
9148
|
+
if (item.visible === false) return 0;
|
|
9149
|
+
if (!presence) value *= item.opacity;
|
|
9090
9150
|
cursor = item.parent;
|
|
9091
9151
|
}
|
|
9092
9152
|
return value;
|
|
@@ -28149,15 +28209,15 @@ var init_defaultFilter_vert = __esmMin((() => {
|
|
|
28149
28209
|
}));
|
|
28150
28210
|
//#endregion
|
|
28151
28211
|
//#region ../../node_modules/.pnpm/pixi.js@8.20.1/node_modules/pixi.js/lib/filters/defaults/passthrough/passthrough.frag.mjs
|
|
28152
|
-
var fragment$
|
|
28212
|
+
var fragment$4;
|
|
28153
28213
|
var init_passthrough_frag = __esmMin((() => {
|
|
28154
|
-
fragment$
|
|
28214
|
+
fragment$4 = "in vec2 vTextureCoord;\nout vec4 finalColor;\nuniform sampler2D uTexture;\nvoid main() {\n finalColor = texture(uTexture, vTextureCoord);\n}\n";
|
|
28155
28215
|
}));
|
|
28156
28216
|
//#endregion
|
|
28157
28217
|
//#region ../../node_modules/.pnpm/pixi.js@8.20.1/node_modules/pixi.js/lib/filters/defaults/passthrough/passthrough.wgsl.mjs
|
|
28158
|
-
var source$
|
|
28218
|
+
var source$3;
|
|
28159
28219
|
var init_passthrough_wgsl = __esmMin((() => {
|
|
28160
|
-
source$
|
|
28220
|
+
source$3 = "struct GlobalFilterUniforms {\n uInputSize: vec4<f32>,\n uInputPixel: vec4<f32>,\n uInputClamp: vec4<f32>,\n uOutputFrame: vec4<f32>,\n uGlobalFrame: vec4<f32>,\n uOutputTexture: vec4<f32>,\n};\n\n@group(0) @binding(0) var <uniform> gfu: GlobalFilterUniforms;\n@group(0) @binding(1) var uTexture: texture_2d<f32>;\n@group(0) @binding(2) var uSampler: sampler;\n\nstruct VSOutput {\n @builtin(position) position: vec4<f32>,\n @location(0) uv: vec2<f32>\n};\n\nfn filterVertexPosition(aPosition: vec2<f32>) -> vec4<f32>\n{\n var position = aPosition * gfu.uOutputFrame.zw + gfu.uOutputFrame.xy;\n\n position.x = position.x * (2.0 / gfu.uOutputTexture.x) - 1.0;\n position.y = position.y * (2.0 * gfu.uOutputTexture.z / gfu.uOutputTexture.y) - gfu.uOutputTexture.z;\n\n return vec4(position, 0.0, 1.0);\n}\n\nfn filterTextureCoord(aPosition: vec2<f32>) -> vec2<f32>\n{\n return aPosition * (gfu.uOutputFrame.zw * gfu.uInputSize.zw);\n}\n\n@vertex\nfn mainVertex(\n @location(0) aPosition: vec2<f32>,\n) -> VSOutput {\n return VSOutput(\n filterVertexPosition(aPosition),\n filterTextureCoord(aPosition)\n );\n}\n\n@fragment\nfn mainFragment(\n @location(0) uv: vec2<f32>,\n) -> @location(0) vec4<f32> {\n return textureSample(uTexture, uSampler, uv);\n}\n";
|
|
28161
28221
|
}));
|
|
28162
28222
|
//#endregion
|
|
28163
28223
|
//#region ../../node_modules/.pnpm/pixi.js@8.20.1/node_modules/pixi.js/lib/filters/defaults/passthrough/PassthroughFilter.mjs
|
|
@@ -28173,18 +28233,18 @@ var init_PassthroughFilter = __esmMin((() => {
|
|
|
28173
28233
|
constructor() {
|
|
28174
28234
|
const gpuProgram = GpuProgram.from({
|
|
28175
28235
|
vertex: {
|
|
28176
|
-
source: source$
|
|
28236
|
+
source: source$3,
|
|
28177
28237
|
entryPoint: "mainVertex"
|
|
28178
28238
|
},
|
|
28179
28239
|
fragment: {
|
|
28180
|
-
source: source$
|
|
28240
|
+
source: source$3,
|
|
28181
28241
|
entryPoint: "mainFragment"
|
|
28182
28242
|
},
|
|
28183
28243
|
name: "passthrough-filter"
|
|
28184
28244
|
});
|
|
28185
28245
|
const glProgram = GlProgram.from({
|
|
28186
28246
|
vertex: vertex$2,
|
|
28187
|
-
fragment: fragment$
|
|
28247
|
+
fragment: fragment$4,
|
|
28188
28248
|
name: "passthrough-filter"
|
|
28189
28249
|
});
|
|
28190
28250
|
super({
|
|
@@ -32492,9 +32552,9 @@ var init_BatcherPipe = __esmMin((() => {
|
|
|
32492
32552
|
}));
|
|
32493
32553
|
//#endregion
|
|
32494
32554
|
//#region ../../node_modules/.pnpm/pixi.js@8.20.1/node_modules/pixi.js/lib/filters/mask/mask.frag.mjs
|
|
32495
|
-
var fragment$
|
|
32555
|
+
var fragment$3;
|
|
32496
32556
|
var init_mask_frag = __esmMin((() => {
|
|
32497
|
-
fragment$
|
|
32557
|
+
fragment$3 = "in vec2 vMaskCoord;\nin vec2 vTextureCoord;\n\nuniform sampler2D uTexture;\nuniform sampler2D uMaskTexture;\n\nuniform float uAlpha;\nuniform vec4 uMaskClamp;\nuniform float uInverse;\nuniform float uChannel;\n\nout vec4 finalColor;\n\nvoid main(void)\n{\n float clip = step(3.5,\n step(uMaskClamp.x, vMaskCoord.x) +\n step(uMaskClamp.y, vMaskCoord.y) +\n step(vMaskCoord.x, uMaskClamp.z) +\n step(vMaskCoord.y, uMaskClamp.w));\n\n // TODO look into why this is needed\n float npmAlpha = uAlpha;\n vec4 original = texture(uTexture, vTextureCoord);\n vec4 masky = texture(uMaskTexture, vMaskCoord);\n\n float a;\n if (uChannel == 1.0) {\n a = masky.a * npmAlpha * clip;\n } else {\n float alphaMul = 1.0 - npmAlpha * (1.0 - masky.a);\n a = alphaMul * masky.r * npmAlpha * clip;\n }\n\n if (uInverse == 1.0) {\n a = 1.0 - a;\n }\n\n finalColor = original * a;\n}\n";
|
|
32498
32558
|
}));
|
|
32499
32559
|
//#endregion
|
|
32500
32560
|
//#region ../../node_modules/.pnpm/pixi.js@8.20.1/node_modules/pixi.js/lib/filters/mask/mask.vert.mjs
|
|
@@ -32504,9 +32564,9 @@ var init_mask_vert = __esmMin((() => {
|
|
|
32504
32564
|
}));
|
|
32505
32565
|
//#endregion
|
|
32506
32566
|
//#region ../../node_modules/.pnpm/pixi.js@8.20.1/node_modules/pixi.js/lib/filters/mask/mask.wgsl.mjs
|
|
32507
|
-
var source$
|
|
32567
|
+
var source$2;
|
|
32508
32568
|
var init_mask_wgsl = __esmMin((() => {
|
|
32509
|
-
source$
|
|
32569
|
+
source$2 = "struct GlobalFilterUniforms {\n uInputSize:vec4<f32>,\n uInputPixel:vec4<f32>,\n uInputClamp:vec4<f32>,\n uOutputFrame:vec4<f32>,\n uGlobalFrame:vec4<f32>,\n uOutputTexture:vec4<f32>,\n};\n\nstruct MaskUniforms {\n uFilterMatrix:mat3x3<f32>,\n uMaskClamp:vec4<f32>,\n uAlpha:f32,\n uInverse:f32,\n uChannel:f32,\n};\n\n@group(0) @binding(0) var<uniform> gfu: GlobalFilterUniforms;\n@group(0) @binding(1) var uTexture: texture_2d<f32>;\n@group(0) @binding(2) var uSampler : sampler;\n\n@group(1) @binding(0) var<uniform> filterUniforms : MaskUniforms;\n@group(1) @binding(1) var uMaskTexture: texture_2d<f32>;\n\nstruct VSOutput {\n @builtin(position) position: vec4<f32>,\n @location(0) uv : vec2<f32>,\n @location(1) filterUv : vec2<f32>,\n};\n\nfn filterVertexPosition(aPosition:vec2<f32>) -> vec4<f32>\n{\n var position = aPosition * gfu.uOutputFrame.zw + gfu.uOutputFrame.xy;\n\n position.x = position.x * (2.0 / gfu.uOutputTexture.x) - 1.0;\n position.y = position.y * (2.0*gfu.uOutputTexture.z / gfu.uOutputTexture.y) - gfu.uOutputTexture.z;\n\n return vec4(position, 0.0, 1.0);\n}\n\nfn filterTextureCoord( aPosition:vec2<f32> ) -> vec2<f32>\n{\n return aPosition * (gfu.uOutputFrame.zw * gfu.uInputSize.zw);\n}\n\nfn globalTextureCoord( aPosition:vec2<f32> ) -> vec2<f32>\n{\n return (aPosition.xy / gfu.uGlobalFrame.zw) + (gfu.uGlobalFrame.xy / gfu.uGlobalFrame.zw);\n}\n\nfn getFilterCoord(aPosition:vec2<f32> ) -> vec2<f32>\n{\n return ( filterUniforms.uFilterMatrix * vec3( filterTextureCoord(aPosition), 1.0) ).xy;\n}\n\nfn getSize() -> vec2<f32>\n{\n return gfu.uGlobalFrame.zw;\n}\n\n@vertex\nfn mainVertex(\n @location(0) aPosition : vec2<f32>,\n) -> VSOutput {\n return VSOutput(\n filterVertexPosition(aPosition),\n filterTextureCoord(aPosition),\n getFilterCoord(aPosition)\n );\n}\n\n@fragment\nfn mainFragment(\n @location(0) uv: vec2<f32>,\n @location(1) filterUv: vec2<f32>,\n @builtin(position) position: vec4<f32>\n) -> @location(0) vec4<f32> {\n\n var maskClamp = filterUniforms.uMaskClamp;\n var uAlpha = filterUniforms.uAlpha;\n\n var clip = step(3.5,\n step(maskClamp.x, filterUv.x) +\n step(maskClamp.y, filterUv.y) +\n step(filterUv.x, maskClamp.z) +\n step(filterUv.y, maskClamp.w));\n\n var mask = textureSample(uMaskTexture, uSampler, filterUv);\n var source = textureSample(uTexture, uSampler, uv);\n\n var a: f32;\n if (filterUniforms.uChannel == 1.0) {\n a = mask.a * uAlpha * clip;\n } else {\n var alphaMul = 1.0 - uAlpha * (1.0 - mask.a);\n a = alphaMul * mask.r * uAlpha * clip;\n }\n\n if (filterUniforms.uInverse == 1.0) {\n a = 1.0 - a;\n }\n\n return source * a;\n}\n";
|
|
32510
32570
|
}));
|
|
32511
32571
|
//#endregion
|
|
32512
32572
|
//#region ../../node_modules/.pnpm/pixi.js@8.20.1/node_modules/pixi.js/lib/filters/mask/MaskFilter.mjs
|
|
@@ -32551,17 +32611,17 @@ var init_MaskFilter = __esmMin((() => {
|
|
|
32551
32611
|
});
|
|
32552
32612
|
const gpuProgram = GpuProgram.from({
|
|
32553
32613
|
vertex: {
|
|
32554
|
-
source: source$
|
|
32614
|
+
source: source$2,
|
|
32555
32615
|
entryPoint: "mainVertex"
|
|
32556
32616
|
},
|
|
32557
32617
|
fragment: {
|
|
32558
|
-
source: source$
|
|
32618
|
+
source: source$2,
|
|
32559
32619
|
entryPoint: "mainFragment"
|
|
32560
32620
|
}
|
|
32561
32621
|
});
|
|
32562
32622
|
const glProgram = GlProgram.from({
|
|
32563
32623
|
vertex: vertex$1,
|
|
32564
|
-
fragment: fragment$
|
|
32624
|
+
fragment: fragment$3,
|
|
32565
32625
|
name: "mask-filter"
|
|
32566
32626
|
});
|
|
32567
32627
|
super({
|
|
@@ -51009,6 +51069,96 @@ var init_getCanvasFillStyle = __esmMin((() => {
|
|
|
51009
51069
|
PRECISION = 1e5;
|
|
51010
51070
|
}));
|
|
51011
51071
|
//#endregion
|
|
51072
|
+
//#region ../../node_modules/.pnpm/pixi.js@8.20.1/node_modules/pixi.js/lib/filters/defaults/alpha/alpha.frag.mjs
|
|
51073
|
+
var fragment$2 = "\nin vec2 vTextureCoord;\n\nout vec4 finalColor;\n\nuniform float uAlpha;\nuniform sampler2D uTexture;\n\nvoid main()\n{\n finalColor = texture(uTexture, vTextureCoord) * uAlpha;\n}\n";
|
|
51074
|
+
//#endregion
|
|
51075
|
+
//#region ../../node_modules/.pnpm/pixi.js@8.20.1/node_modules/pixi.js/lib/filters/defaults/alpha/alpha.wgsl.mjs
|
|
51076
|
+
var source$1 = "struct GlobalFilterUniforms {\n uInputSize:vec4<f32>,\n uInputPixel:vec4<f32>,\n uInputClamp:vec4<f32>,\n uOutputFrame:vec4<f32>,\n uGlobalFrame:vec4<f32>,\n uOutputTexture:vec4<f32>,\n};\n\nstruct AlphaUniforms {\n uAlpha:f32,\n};\n\n@group(0) @binding(0) var<uniform> gfu: GlobalFilterUniforms;\n@group(0) @binding(1) var uTexture: texture_2d<f32>;\n@group(0) @binding(2) var uSampler : sampler;\n\n@group(1) @binding(0) var<uniform> alphaUniforms : AlphaUniforms;\n\nstruct VSOutput {\n @builtin(position) position: vec4<f32>,\n @location(0) uv : vec2<f32>\n };\n\nfn filterVertexPosition(aPosition:vec2<f32>) -> vec4<f32>\n{\n var position = aPosition * gfu.uOutputFrame.zw + gfu.uOutputFrame.xy;\n\n position.x = position.x * (2.0 / gfu.uOutputTexture.x) - 1.0;\n position.y = position.y * (2.0*gfu.uOutputTexture.z / gfu.uOutputTexture.y) - gfu.uOutputTexture.z;\n\n return vec4(position, 0.0, 1.0);\n}\n\nfn filterTextureCoord( aPosition:vec2<f32> ) -> vec2<f32>\n{\n return aPosition * (gfu.uOutputFrame.zw * gfu.uInputSize.zw);\n}\n\nfn globalTextureCoord( aPosition:vec2<f32> ) -> vec2<f32>\n{\n return (aPosition.xy / gfu.uGlobalFrame.zw) + (gfu.uGlobalFrame.xy / gfu.uGlobalFrame.zw); \n}\n\nfn getSize() -> vec2<f32>\n{\n return gfu.uGlobalFrame.zw;\n}\n \n@vertex\nfn mainVertex(\n @location(0) aPosition : vec2<f32>, \n) -> VSOutput {\n return VSOutput(\n filterVertexPosition(aPosition),\n filterTextureCoord(aPosition)\n );\n}\n\n@fragment\nfn mainFragment(\n @location(0) uv: vec2<f32>,\n @builtin(position) position: vec4<f32>\n) -> @location(0) vec4<f32> {\n \n var sample = textureSample(uTexture, uSampler, uv);\n \n return sample * alphaUniforms.uAlpha;\n}";
|
|
51077
|
+
//#endregion
|
|
51078
|
+
//#region ../../node_modules/.pnpm/pixi.js@8.20.1/node_modules/pixi.js/lib/filters/defaults/alpha/AlphaFilter.mjs
|
|
51079
|
+
init_GlProgram();
|
|
51080
|
+
init_GpuProgram();
|
|
51081
|
+
init_UniformGroup();
|
|
51082
|
+
init_Filter();
|
|
51083
|
+
init_defaultFilter_vert();
|
|
51084
|
+
const _AlphaFilter = class _AlphaFilter extends Filter {
|
|
51085
|
+
constructor(options) {
|
|
51086
|
+
options = {
|
|
51087
|
+
..._AlphaFilter.defaultOptions,
|
|
51088
|
+
...options
|
|
51089
|
+
};
|
|
51090
|
+
const gpuProgram = GpuProgram.from({
|
|
51091
|
+
vertex: {
|
|
51092
|
+
source: source$1,
|
|
51093
|
+
entryPoint: "mainVertex"
|
|
51094
|
+
},
|
|
51095
|
+
fragment: {
|
|
51096
|
+
source: source$1,
|
|
51097
|
+
entryPoint: "mainFragment"
|
|
51098
|
+
}
|
|
51099
|
+
});
|
|
51100
|
+
const glProgram = GlProgram.from({
|
|
51101
|
+
vertex: vertex$2,
|
|
51102
|
+
fragment: fragment$2,
|
|
51103
|
+
name: "alpha-filter"
|
|
51104
|
+
});
|
|
51105
|
+
const { alpha, ...rest } = options;
|
|
51106
|
+
const alphaUniforms = new UniformGroup({ uAlpha: {
|
|
51107
|
+
value: alpha,
|
|
51108
|
+
type: "f32"
|
|
51109
|
+
} });
|
|
51110
|
+
super({
|
|
51111
|
+
...rest,
|
|
51112
|
+
gpuProgram,
|
|
51113
|
+
glProgram,
|
|
51114
|
+
resources: { alphaUniforms }
|
|
51115
|
+
});
|
|
51116
|
+
}
|
|
51117
|
+
/**
|
|
51118
|
+
* The alpha value of the filter.
|
|
51119
|
+
* Controls the transparency of the filtered display object.
|
|
51120
|
+
* @example
|
|
51121
|
+
* ```ts
|
|
51122
|
+
* // Create filter with initial alpha
|
|
51123
|
+
* const filter = new AlphaFilter({ alpha: 0.5 });
|
|
51124
|
+
*
|
|
51125
|
+
* // Update alpha value dynamically
|
|
51126
|
+
* filter.alpha = 0.8;
|
|
51127
|
+
* ```
|
|
51128
|
+
* @default 1
|
|
51129
|
+
* @remarks
|
|
51130
|
+
* - 0 = fully transparent
|
|
51131
|
+
* - 1 = fully opaque
|
|
51132
|
+
* - Values are clamped between 0 and 1
|
|
51133
|
+
*/
|
|
51134
|
+
get alpha() {
|
|
51135
|
+
return this.resources.alphaUniforms.uniforms.uAlpha;
|
|
51136
|
+
}
|
|
51137
|
+
set alpha(value) {
|
|
51138
|
+
this.resources.alphaUniforms.uniforms.uAlpha = value;
|
|
51139
|
+
}
|
|
51140
|
+
};
|
|
51141
|
+
/**
|
|
51142
|
+
* Default options for the AlphaFilter.
|
|
51143
|
+
* @example
|
|
51144
|
+
* ```ts
|
|
51145
|
+
* AlphaFilter.defaultOptions = {
|
|
51146
|
+
* alpha: 0.5, // Default alpha value
|
|
51147
|
+
* };
|
|
51148
|
+
* // Use default options
|
|
51149
|
+
* const filter = new AlphaFilter(); // Uses default alpha of 0.5
|
|
51150
|
+
* ```
|
|
51151
|
+
*/
|
|
51152
|
+
_AlphaFilter.defaultOptions = {
|
|
51153
|
+
/**
|
|
51154
|
+
* Amount of alpha transparency to apply.
|
|
51155
|
+
* - 0 = fully transparent
|
|
51156
|
+
* - 1 = fully opaque (default)
|
|
51157
|
+
* @default 1
|
|
51158
|
+
*/
|
|
51159
|
+
alpha: 1 };
|
|
51160
|
+
let AlphaFilter = _AlphaFilter;
|
|
51161
|
+
//#endregion
|
|
51012
51162
|
//#region ../../node_modules/.pnpm/pixi.js@8.20.1/node_modules/pixi.js/lib/filters/defaults/color-matrix/colorMatrixFilter.frag.mjs
|
|
51013
51163
|
var fragment$1 = "\nin vec2 vTextureCoord;\nin vec4 vColor;\n\nout vec4 finalColor;\n\nuniform float uColorMatrix[20];\nuniform float uAlpha;\n\nuniform sampler2D uTexture;\n\nfloat rand(vec2 co)\n{\n return fract(sin(dot(co.xy, vec2(12.9898, 78.233))) * 43758.5453);\n}\n\nvoid main()\n{\n vec4 color = texture(uTexture, vTextureCoord);\n float randomValue = rand(gl_FragCoord.xy * 0.2);\n float diff = (randomValue - 0.5) * 0.5;\n\n if (uAlpha == 0.0) {\n finalColor = color;\n return;\n }\n\n if (color.a > 0.0) {\n color.rgb /= color.a;\n }\n\n vec4 result;\n\n result.r = (uColorMatrix[0] * color.r);\n result.r += (uColorMatrix[1] * color.g);\n result.r += (uColorMatrix[2] * color.b);\n result.r += (uColorMatrix[3] * color.a);\n result.r += uColorMatrix[4];\n\n result.g = (uColorMatrix[5] * color.r);\n result.g += (uColorMatrix[6] * color.g);\n result.g += (uColorMatrix[7] * color.b);\n result.g += (uColorMatrix[8] * color.a);\n result.g += uColorMatrix[9];\n\n result.b = (uColorMatrix[10] * color.r);\n result.b += (uColorMatrix[11] * color.g);\n result.b += (uColorMatrix[12] * color.b);\n result.b += (uColorMatrix[13] * color.a);\n result.b += uColorMatrix[14];\n\n result.a = (uColorMatrix[15] * color.r);\n result.a += (uColorMatrix[16] * color.g);\n result.a += (uColorMatrix[17] * color.b);\n result.a += (uColorMatrix[18] * color.a);\n result.a += uColorMatrix[19];\n\n vec3 rgb = mix(color.rgb, result.rgb, uAlpha);\n\n // Premultiply alpha again.\n rgb *= result.a;\n\n finalColor = vec4(rgb, result.a);\n}\n";
|
|
51014
51164
|
//#endregion
|
|
@@ -56047,11 +56197,18 @@ init_Filter();
|
|
|
56047
56197
|
init_Matrix();
|
|
56048
56198
|
init_Rectangle();
|
|
56049
56199
|
init_GlProgram();
|
|
56200
|
+
init_GlProgramData();
|
|
56201
|
+
init_defaultValue();
|
|
56202
|
+
init_extractAttributesFromGlProgram();
|
|
56203
|
+
init_getUboData();
|
|
56204
|
+
init_getUniformData();
|
|
56050
56205
|
init_Geometry();
|
|
56206
|
+
init_RenderTarget();
|
|
56051
56207
|
init_Shader();
|
|
56052
56208
|
init_UniformGroup();
|
|
56053
56209
|
init_RenderTexture();
|
|
56054
56210
|
init_ImageSource();
|
|
56211
|
+
init_TextureSource();
|
|
56055
56212
|
init_Texture();
|
|
56056
56213
|
init_TexturePool();
|
|
56057
56214
|
init_textureFrom();
|
|
@@ -62075,6 +62232,9 @@ function colorSteps(filter) {
|
|
|
62075
62232
|
}
|
|
62076
62233
|
var BoardColorFilter = class extends ColorMatrixFilter {
|
|
62077
62234
|
css = "";
|
|
62235
|
+
constructor() {
|
|
62236
|
+
super({ resolution: "inherit" });
|
|
62237
|
+
}
|
|
62078
62238
|
set(filter) {
|
|
62079
62239
|
const steps = colorSteps(filter);
|
|
62080
62240
|
this.css = steps.map(({ step, value }) => step.css(value)).join(" ");
|
|
@@ -62152,21 +62312,47 @@ function shaderPasses() {
|
|
|
62152
62312
|
};
|
|
62153
62313
|
return passes;
|
|
62154
62314
|
}
|
|
62155
|
-
|
|
62156
|
-
|
|
62315
|
+
const TEXELS_PER_DEVIATION = 4;
|
|
62316
|
+
const MAX_HALVINGS = 5;
|
|
62317
|
+
function gaussian(filters, input, output, deviation, clear, first) {
|
|
62318
|
+
const { horizontal, vertical, copy } = shaderPasses();
|
|
62319
|
+
const resolution = input.source.resolution;
|
|
62320
|
+
const halvings = Math.max(0, Math.min(MAX_HALVINGS, Math.floor(Math.log2(deviation * resolution / TEXELS_PER_DEVIATION))));
|
|
62321
|
+
const borrowed = [];
|
|
62322
|
+
const borrow = (scale) => {
|
|
62323
|
+
const texture = TexturePool.getOptimalTexture(input.frame.width, input.frame.height, resolution * scale, false);
|
|
62324
|
+
borrowed.push(texture);
|
|
62325
|
+
return texture;
|
|
62326
|
+
};
|
|
62327
|
+
let source = input;
|
|
62328
|
+
let scale = 1;
|
|
62329
|
+
for (let step = 0; step < Math.max(halvings, first ? 1 : 0); step++) {
|
|
62330
|
+
if (step < halvings) scale /= 2;
|
|
62331
|
+
const next = borrow(scale);
|
|
62332
|
+
filters.applyFilter(step === 0 && first ? first : copy, source, next, true);
|
|
62333
|
+
source = next;
|
|
62334
|
+
}
|
|
62157
62335
|
horizontal.resources.blurUniforms.uniforms.uStep = [deviation / 4, 0];
|
|
62158
62336
|
vertical.resources.blurUniforms.uniforms.uStep = [0, deviation / 4];
|
|
62159
|
-
const between =
|
|
62160
|
-
filters.applyFilter(horizontal,
|
|
62161
|
-
filters.applyFilter(vertical, between, output, clear);
|
|
62162
|
-
|
|
62337
|
+
const between = borrow(scale);
|
|
62338
|
+
filters.applyFilter(horizontal, source, between, true);
|
|
62339
|
+
if (scale === 1) filters.applyFilter(vertical, between, output, clear);
|
|
62340
|
+
else {
|
|
62341
|
+
const blurred = borrow(scale);
|
|
62342
|
+
filters.applyFilter(vertical, between, blurred, true);
|
|
62343
|
+
filters.applyFilter(copy, blurred, output, clear);
|
|
62344
|
+
}
|
|
62345
|
+
for (const texture of borrowed) TexturePool.returnTexture(texture);
|
|
62163
62346
|
}
|
|
62164
62347
|
var BoardBlurFilter = class extends Filter {
|
|
62165
62348
|
css = "";
|
|
62166
62349
|
radius = 0;
|
|
62167
62350
|
deviation = 0;
|
|
62168
62351
|
constructor() {
|
|
62169
|
-
super({
|
|
62352
|
+
super({
|
|
62353
|
+
glProgram: program("board-copy", COPY_FRAGMENT),
|
|
62354
|
+
resolution: "inherit"
|
|
62355
|
+
});
|
|
62170
62356
|
}
|
|
62171
62357
|
set(radius, zoom) {
|
|
62172
62358
|
this.radius = radius;
|
|
@@ -62193,6 +62379,7 @@ var BoardShadowFilter = class extends Filter {
|
|
|
62193
62379
|
deviation = 0;
|
|
62194
62380
|
constructor() {
|
|
62195
62381
|
super({
|
|
62382
|
+
resolution: "inherit",
|
|
62196
62383
|
glProgram: program("board-shadow", SHADOW_FRAGMENT),
|
|
62197
62384
|
resources: { shadowUniforms: {
|
|
62198
62385
|
uOffset: {
|
|
@@ -62225,12 +62412,9 @@ var BoardShadowFilter = class extends Filter {
|
|
|
62225
62412
|
}
|
|
62226
62413
|
apply(filters, input, output, clearMode) {
|
|
62227
62414
|
const { copy } = shaderPasses();
|
|
62228
|
-
|
|
62229
|
-
filters.applyFilter(this, input,
|
|
62230
|
-
if (this.deviation > 0) gaussian(filters, shadow, output, this.deviation, clearMode);
|
|
62231
|
-
else filters.applyFilter(copy, shadow, output, clearMode);
|
|
62415
|
+
if (this.deviation > 0) gaussian(filters, input, output, this.deviation, clearMode, this);
|
|
62416
|
+
else filters.applyFilter(this, input, output, clearMode);
|
|
62232
62417
|
filters.applyFilter(copy, input, output, false);
|
|
62233
|
-
TexturePool.returnTexture(shadow);
|
|
62234
62418
|
}
|
|
62235
62419
|
getCanvasFilterString() {
|
|
62236
62420
|
return this.css;
|
|
@@ -62238,7 +62422,9 @@ var BoardShadowFilter = class extends Filter {
|
|
|
62238
62422
|
};
|
|
62239
62423
|
const filtersByContainer = /* @__PURE__ */ new WeakMap();
|
|
62240
62424
|
function hasBoardEffects(style) {
|
|
62241
|
-
|
|
62425
|
+
if (!style) return false;
|
|
62426
|
+
const shadow = style.shadow && (style.shadow.opacity ?? BOARD_SHADOW_DEFAULTS.opacity) > 0;
|
|
62427
|
+
return Boolean(shadow || style.filter && (style.filter.blur || colorSteps(style.filter).length) || style.blend && style.blend !== "normal");
|
|
62242
62428
|
}
|
|
62243
62429
|
function resolveShadow(shadow, context) {
|
|
62244
62430
|
return {
|
|
@@ -62271,7 +62457,8 @@ function syncBoardEffects(container, style, context) {
|
|
|
62271
62457
|
const filter = style?.filter;
|
|
62272
62458
|
const blurs = context.blurs !== false;
|
|
62273
62459
|
const blur = blurs ? filter?.blur ?? 0 : 0;
|
|
62274
|
-
const
|
|
62460
|
+
const resolved = blurs && style?.shadow ? resolveShadow(style.shadow, context) : null;
|
|
62461
|
+
const shadow = resolved && resolved.alpha > 0 ? resolved : null;
|
|
62275
62462
|
const colored = colorSteps(filter).length > 0;
|
|
62276
62463
|
let parts = filtersByContainer.get(container);
|
|
62277
62464
|
if (!colored && blur <= 0 && !shadow) {
|
|
@@ -62717,6 +62904,32 @@ function roundRectPoints(width, height, radius) {
|
|
|
62717
62904
|
worldPoint(width - r, 0)
|
|
62718
62905
|
];
|
|
62719
62906
|
}
|
|
62907
|
+
function shapeOutlinePoints(geometry, width, height, radius) {
|
|
62908
|
+
const p = (x, y) => worldPoint(x, y);
|
|
62909
|
+
switch (geometry) {
|
|
62910
|
+
case "ellipse": {
|
|
62911
|
+
const segments = 64;
|
|
62912
|
+
return Array.from({ length: 65 }, (_, index) => {
|
|
62913
|
+
const angle = -Math.PI / 2 + index / segments * Math.PI * 2;
|
|
62914
|
+
return p(width / 2 + Math.cos(angle) * width / 2, height / 2 + Math.sin(angle) * height / 2);
|
|
62915
|
+
});
|
|
62916
|
+
}
|
|
62917
|
+
case "diamond": return [
|
|
62918
|
+
p(width / 2, 0),
|
|
62919
|
+
p(width, height / 2),
|
|
62920
|
+
p(width / 2, height),
|
|
62921
|
+
p(0, height / 2),
|
|
62922
|
+
p(width / 2, 0)
|
|
62923
|
+
];
|
|
62924
|
+
case "triangle": return [
|
|
62925
|
+
p(width / 2, 0),
|
|
62926
|
+
p(width, height),
|
|
62927
|
+
p(0, height),
|
|
62928
|
+
p(width / 2, 0)
|
|
62929
|
+
];
|
|
62930
|
+
default: return roundRectPoints(width, height, radius);
|
|
62931
|
+
}
|
|
62932
|
+
}
|
|
62720
62933
|
const SHADOW_LAYERS = 5;
|
|
62721
62934
|
function traceCardOutline(graphics, rect, style, grow = 0) {
|
|
62722
62935
|
const x = rect.x - grow;
|
|
@@ -63261,7 +63474,8 @@ const modelCardRenderer = {
|
|
|
63261
63474
|
const BOARD_PLAY_MEDIA = "play-media";
|
|
63262
63475
|
function mediaPlayBadgeVisible(item, zoom, options) {
|
|
63263
63476
|
if (!options.materialized) return false;
|
|
63264
|
-
if (item.type === "video"
|
|
63477
|
+
if (item.type === "video") return item.props.time === void 0;
|
|
63478
|
+
if (item.type === "audio") return true;
|
|
63265
63479
|
if (isBoardModelItem(item)) return boardCardDetailed(zoom);
|
|
63266
63480
|
if (item.type !== "task" || !boardCardDetailed(zoom)) return false;
|
|
63267
63481
|
const artifact = featuredTaskArtifact(item.props.snapshot.artifacts);
|
|
@@ -64291,7 +64505,6 @@ const frameCardRenderer = {
|
|
|
64291
64505
|
};
|
|
64292
64506
|
//#endregion
|
|
64293
64507
|
//#region ../sdk/src/board/render/renderers/shape-card-renderer.ts
|
|
64294
|
-
const DEFAULT_ROUNDED_RADIUS = 8;
|
|
64295
64508
|
const partsByContainer$7 = /* @__PURE__ */ new WeakMap();
|
|
64296
64509
|
const pathCache = /* @__PURE__ */ new Map();
|
|
64297
64510
|
function parsedPath(d) {
|
|
@@ -64330,7 +64543,7 @@ function traceShapeOutline(graphics, props, width, height, radius) {
|
|
|
64330
64543
|
graphics.moveTo(width / 2, 0).lineTo(width, height).lineTo(0, height).closePath();
|
|
64331
64544
|
return;
|
|
64332
64545
|
case "rounded":
|
|
64333
|
-
graphics.roundRect(0, 0, width, height, radius ??
|
|
64546
|
+
graphics.roundRect(0, 0, width, height, radius ?? 8);
|
|
64334
64547
|
return;
|
|
64335
64548
|
case "path": {
|
|
64336
64549
|
const parsed = props.path ? parsedPath(props.path) : null;
|
|
@@ -64347,32 +64560,6 @@ function traceShapeOutline(graphics, props, width, height, radius) {
|
|
|
64347
64560
|
else graphics.rect(0, 0, width, height);
|
|
64348
64561
|
}
|
|
64349
64562
|
}
|
|
64350
|
-
function outlinePoints(geometry, width, height, radius) {
|
|
64351
|
-
const p = (x, y) => worldPoint(x, y);
|
|
64352
|
-
switch (geometry) {
|
|
64353
|
-
case "ellipse": {
|
|
64354
|
-
const segments = 64;
|
|
64355
|
-
return Array.from({ length: 65 }, (_, index) => {
|
|
64356
|
-
const angle = -Math.PI / 2 + index / segments * Math.PI * 2;
|
|
64357
|
-
return p(width / 2 + Math.cos(angle) * width / 2, height / 2 + Math.sin(angle) * height / 2);
|
|
64358
|
-
});
|
|
64359
|
-
}
|
|
64360
|
-
case "diamond": return [
|
|
64361
|
-
p(width / 2, 0),
|
|
64362
|
-
p(width, height / 2),
|
|
64363
|
-
p(width / 2, height),
|
|
64364
|
-
p(0, height / 2),
|
|
64365
|
-
p(width / 2, 0)
|
|
64366
|
-
];
|
|
64367
|
-
case "triangle": return [
|
|
64368
|
-
p(width / 2, 0),
|
|
64369
|
-
p(width, height),
|
|
64370
|
-
p(0, height),
|
|
64371
|
-
p(width / 2, 0)
|
|
64372
|
-
];
|
|
64373
|
-
default: return roundRectPoints(width, height, radius);
|
|
64374
|
-
}
|
|
64375
|
-
}
|
|
64376
64563
|
function sync$7(container, item, context) {
|
|
64377
64564
|
const parts = partsByContainer$7.get(container);
|
|
64378
64565
|
if (!parts) return;
|
|
@@ -64412,8 +64599,8 @@ function sync$7(container, item, context) {
|
|
|
64412
64599
|
const partial = style.trim !== void 0 && style.trim < 1;
|
|
64413
64600
|
if (strokeWidth > 0 && (!partial || style.trim)) {
|
|
64414
64601
|
if ((pattern || partial) && props.geometry !== "path") {
|
|
64415
|
-
const radius = style.radius ?? (props.geometry === "rounded" ?
|
|
64416
|
-
tracePolyline(parts.shape, trimPolyline(
|
|
64602
|
+
const radius = style.radius ?? (props.geometry === "rounded" ? 8 : 0);
|
|
64603
|
+
tracePolyline(parts.shape, trimPolyline(shapeOutlinePoints(props.geometry, width, height, radius), style.trim), pattern);
|
|
64417
64604
|
} else traceShapeOutline(parts.shape, props, width, height, style.radius);
|
|
64418
64605
|
parts.shape.stroke({
|
|
64419
64606
|
color: stroke,
|
|
@@ -65977,8 +66164,9 @@ function sync(container, item, context) {
|
|
|
65977
66164
|
text: duration ? `${title} · ${duration}` : title,
|
|
65978
66165
|
width
|
|
65979
66166
|
}, context);
|
|
66167
|
+
const live = context.mediaTexture?.(item.id) ?? null;
|
|
65980
66168
|
const key = context.assetKey(item);
|
|
65981
|
-
const texture = key ? context.getTexture(key) : null;
|
|
66169
|
+
const texture = live ?? (key ? context.getTexture(key) : null);
|
|
65982
66170
|
const elevation = cardElevation(context, item.id);
|
|
65983
66171
|
const sig = [
|
|
65984
66172
|
key ?? "",
|
|
@@ -65987,6 +66175,7 @@ function sync(container, item, context) {
|
|
|
65987
66175
|
height,
|
|
65988
66176
|
elevation,
|
|
65989
66177
|
boardCardDetailed(context.zoom),
|
|
66178
|
+
item.props.time === void 0,
|
|
65990
66179
|
context.themeKey
|
|
65991
66180
|
].join("|");
|
|
65992
66181
|
if (sig === parts.sig) return;
|
|
@@ -66026,7 +66215,7 @@ function sync(container, item, context) {
|
|
|
66026
66215
|
} : context.style);
|
|
66027
66216
|
}
|
|
66028
66217
|
parts.chrome.clear();
|
|
66029
|
-
if (boardCardDetailed(context.zoom)) drawMediaPlayKey(parts.chrome, screen.x + screen.width / 2, screen.y + screen.height / 2, Math.min(18, Math.min(screen.width, screen.height) * .16), context);
|
|
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);
|
|
66030
66219
|
}
|
|
66031
66220
|
function drawFilmRails(graphics, width, height, rail, hole) {
|
|
66032
66221
|
const size = Math.min(FILM_HOLE, rail * .45);
|
|
@@ -66429,6 +66618,7 @@ const itemEnvelope = {
|
|
|
66429
66618
|
y: .5
|
|
66430
66619
|
}).describe("Rotation and scale origin as fractions of the size."),
|
|
66431
66620
|
opacity: ratio.default(1),
|
|
66621
|
+
visible: boolean().optional().describe("false hides the item and its children; key it on a timeline to show the item only for a span."),
|
|
66432
66622
|
style: BoardStyleSchema.default({}),
|
|
66433
66623
|
locked: boolean().optional(),
|
|
66434
66624
|
metadata: record(string(), unknown()).optional()
|
|
@@ -66578,7 +66768,8 @@ const mediaProps = {
|
|
|
66578
66768
|
};
|
|
66579
66769
|
const timedFileProps = {
|
|
66580
66770
|
...mediaProps,
|
|
66581
|
-
time: nonNegative.optional().describe("Playback position in milliseconds; animate props.time to play it on a timeline.")
|
|
66771
|
+
time: nonNegative.optional().describe("Playback position in milliseconds; animate props.time to play it on a timeline. It sounds while its time moves forward."),
|
|
66772
|
+
volume: ratio.optional().describe("Loudness from 0 to 1; defaults to 1. Animate it to fade.")
|
|
66582
66773
|
};
|
|
66583
66774
|
const BoardCropSchema = object({
|
|
66584
66775
|
x: ratio,
|
|
@@ -67015,40 +67206,51 @@ async function loadBoardScriptSources(src, read, timeoutMs = 15e3) {
|
|
|
67015
67206
|
const { init, parse } = await Promise.resolve().then(() => (init_lexer(), lexer_exports));
|
|
67016
67207
|
await init;
|
|
67017
67208
|
const sources = {};
|
|
67018
|
-
const
|
|
67209
|
+
const loading = /* @__PURE__ */ new Map();
|
|
67210
|
+
const edges = /* @__PURE__ */ new Map();
|
|
67019
67211
|
let bytes = 0;
|
|
67020
|
-
|
|
67021
|
-
|
|
67022
|
-
if (
|
|
67023
|
-
if (
|
|
67024
|
-
|
|
67025
|
-
|
|
67026
|
-
|
|
67027
|
-
|
|
67028
|
-
|
|
67029
|
-
|
|
67030
|
-
|
|
67031
|
-
|
|
67032
|
-
|
|
67033
|
-
|
|
67034
|
-
|
|
67035
|
-
|
|
67036
|
-
|
|
67037
|
-
|
|
67038
|
-
|
|
67039
|
-
|
|
67040
|
-
|
|
67041
|
-
|
|
67042
|
-
|
|
67043
|
-
|
|
67044
|
-
|
|
67045
|
-
|
|
67046
|
-
|
|
67047
|
-
|
|
67048
|
-
|
|
67049
|
-
|
|
67212
|
+
function load(path) {
|
|
67213
|
+
let promise = loading.get(path);
|
|
67214
|
+
if (promise) return promise;
|
|
67215
|
+
if (loading.size >= 64) throw new Error("A script may load at most 64 modules.");
|
|
67216
|
+
promise = (async () => {
|
|
67217
|
+
let timer;
|
|
67218
|
+
const code = await Promise.race([Promise.resolve().then(() => read(path)), new Promise((_resolve, reject) => {
|
|
67219
|
+
timer = setTimeout(() => reject(/* @__PURE__ */ new Error(`Module read timed out: ${path}`)), timeoutMs);
|
|
67220
|
+
})]).finally(() => clearTimeout(timer));
|
|
67221
|
+
bytes += new TextEncoder().encode(code).byteLength;
|
|
67222
|
+
if (bytes > 2e6) throw new Error("Script modules exceed the 2 MB limit.");
|
|
67223
|
+
const [imports] = parse(code, path);
|
|
67224
|
+
const resolved = [];
|
|
67225
|
+
for (const entry of imports) {
|
|
67226
|
+
if (entry.d === -2) throw new Error("import.meta is not available in Board scripts.");
|
|
67227
|
+
if (entry.n === void 0) throw new Error("Dynamic imports must use a literal relative path.");
|
|
67228
|
+
resolved.push({
|
|
67229
|
+
start: entry.s,
|
|
67230
|
+
end: entry.e,
|
|
67231
|
+
path: resolveScriptImport(path, entry.n),
|
|
67232
|
+
dynamic: entry.d >= 0
|
|
67233
|
+
});
|
|
67234
|
+
}
|
|
67235
|
+
const dependencies = resolved.map((entry) => entry.path);
|
|
67236
|
+
edges.set(path, dependencies);
|
|
67237
|
+
if (dependencies.some((dependency) => importsReach(dependency, path))) throw new Error(`Circular module dependency: ${path}`);
|
|
67238
|
+
await Promise.all(dependencies.map(load));
|
|
67239
|
+
sources[path] = {
|
|
67240
|
+
code,
|
|
67241
|
+
imports: resolved
|
|
67242
|
+
};
|
|
67243
|
+
})();
|
|
67244
|
+
loading.set(path, promise);
|
|
67245
|
+
return promise;
|
|
67246
|
+
}
|
|
67247
|
+
function importsReach(from, target, seen = /* @__PURE__ */ new Set()) {
|
|
67248
|
+
if (from === target) return true;
|
|
67249
|
+
if (seen.has(from)) return false;
|
|
67250
|
+
seen.add(from);
|
|
67251
|
+
return (edges.get(from) ?? []).some((next) => importsReach(next, target, seen));
|
|
67050
67252
|
}
|
|
67051
|
-
await
|
|
67253
|
+
await load(src);
|
|
67052
67254
|
return sources;
|
|
67053
67255
|
}
|
|
67054
67256
|
function scriptModuleUrls(sources) {
|
|
@@ -67102,6 +67304,7 @@ function createScriptRuntime(module, initial, host) {
|
|
|
67102
67304
|
let disposed = false;
|
|
67103
67305
|
let stepping = false;
|
|
67104
67306
|
let revision = 0;
|
|
67307
|
+
let sceneRevision = 0;
|
|
67105
67308
|
let randomState = 2166136261;
|
|
67106
67309
|
for (const char of initial.script.seed ?? initial.id) randomState = Math.imul(randomState ^ char.charCodeAt(0), 16777619) >>> 0;
|
|
67107
67310
|
const parameterDefaults = Object.fromEntries(Object.entries(module.parameters ?? {}).filter(([, spec]) => spec.default !== void 0).map(([key, spec]) => [key, spec.default]));
|
|
@@ -67136,9 +67339,11 @@ function createScriptRuntime(module, initial, host) {
|
|
|
67136
67339
|
let view = null;
|
|
67137
67340
|
let hits = effects?.hits ?? {};
|
|
67138
67341
|
let uniforms = effects?.uniforms;
|
|
67139
|
-
|
|
67342
|
+
let passes = effects?.passes;
|
|
67343
|
+
const invalidate = (scene = true) => {
|
|
67140
67344
|
if (disposed) return;
|
|
67141
67345
|
revision++;
|
|
67346
|
+
if (scene) sceneRevision++;
|
|
67142
67347
|
host.invalidate();
|
|
67143
67348
|
};
|
|
67144
67349
|
const present = (id, patch) => {
|
|
@@ -67213,7 +67418,7 @@ function createScriptRuntime(module, initial, host) {
|
|
|
67213
67418
|
};
|
|
67214
67419
|
},
|
|
67215
67420
|
onDispose: (handler) => cleanups.push(handler),
|
|
67216
|
-
invalidate,
|
|
67421
|
+
invalidate: () => invalidate(),
|
|
67217
67422
|
get: (id) => input.items[id],
|
|
67218
67423
|
present,
|
|
67219
67424
|
scene(next, options) {
|
|
@@ -67244,7 +67449,16 @@ function createScriptRuntime(module, initial, host) {
|
|
|
67244
67449
|
...uniforms,
|
|
67245
67450
|
...values
|
|
67246
67451
|
};
|
|
67247
|
-
invalidate();
|
|
67452
|
+
invalidate(false);
|
|
67453
|
+
},
|
|
67454
|
+
passes(next) {
|
|
67455
|
+
if (!next || typeof next !== "object" || Object.values(next).some((on) => typeof on !== "boolean")) throw new Error("passes() takes a record of pass names and booleans.");
|
|
67456
|
+
if (Object.entries(next).every(([name, on]) => passes?.[name] === on)) return;
|
|
67457
|
+
passes = {
|
|
67458
|
+
...passes,
|
|
67459
|
+
...next
|
|
67460
|
+
};
|
|
67461
|
+
invalidate(false);
|
|
67248
67462
|
},
|
|
67249
67463
|
async commit(patch) {
|
|
67250
67464
|
return await host.call("board.commit", {
|
|
@@ -67260,7 +67474,16 @@ function createScriptRuntime(module, initial, host) {
|
|
|
67260
67474
|
call: (name, value) => host.call(name, value)
|
|
67261
67475
|
}
|
|
67262
67476
|
};
|
|
67263
|
-
const
|
|
67477
|
+
const seeded = (run) => {
|
|
67478
|
+
const random = Math.random;
|
|
67479
|
+
Math.random = context.random;
|
|
67480
|
+
try {
|
|
67481
|
+
return run();
|
|
67482
|
+
} finally {
|
|
67483
|
+
Math.random = random;
|
|
67484
|
+
}
|
|
67485
|
+
};
|
|
67486
|
+
const setup = seeded(() => module.default?.(context));
|
|
67264
67487
|
if (typeof setup === "function") cleanups.push(setup);
|
|
67265
67488
|
return {
|
|
67266
67489
|
get animated() {
|
|
@@ -67271,6 +67494,7 @@ function createScriptRuntime(module, initial, host) {
|
|
|
67271
67494
|
for (const id of Object.keys(patches)) if (!next.items[id]) {
|
|
67272
67495
|
delete patches[id];
|
|
67273
67496
|
revision++;
|
|
67497
|
+
sceneRevision++;
|
|
67274
67498
|
}
|
|
67275
67499
|
params = {
|
|
67276
67500
|
...parameterDefaults,
|
|
@@ -67291,10 +67515,12 @@ function createScriptRuntime(module, initial, host) {
|
|
|
67291
67515
|
};
|
|
67292
67516
|
stepping = true;
|
|
67293
67517
|
try {
|
|
67294
|
-
|
|
67295
|
-
const
|
|
67296
|
-
|
|
67297
|
-
|
|
67518
|
+
seeded(() => {
|
|
67519
|
+
for (const handler of frames) {
|
|
67520
|
+
const result = handler(frame);
|
|
67521
|
+
if (result && typeof result.then === "function") throw new Error("onFrame() handlers must be synchronous.");
|
|
67522
|
+
}
|
|
67523
|
+
});
|
|
67298
67524
|
} finally {
|
|
67299
67525
|
stepping = false;
|
|
67300
67526
|
}
|
|
@@ -67322,11 +67548,13 @@ function createScriptRuntime(module, initial, host) {
|
|
|
67322
67548
|
if (event.type === "viewchange") view = event.data;
|
|
67323
67549
|
const listeners = handlers.get(event.type);
|
|
67324
67550
|
if (!listeners?.size) return;
|
|
67325
|
-
|
|
67551
|
+
seeded(() => {
|
|
67552
|
+
for (const handler of listeners) handler(event);
|
|
67553
|
+
});
|
|
67326
67554
|
invalidate();
|
|
67327
67555
|
},
|
|
67328
67556
|
draw(canvas) {
|
|
67329
|
-
const result = module.draw?.(canvas, frame);
|
|
67557
|
+
const result = seeded(() => module.draw?.(canvas, frame));
|
|
67330
67558
|
if (result && typeof result.then === "function") throw new Error("draw() must be synchronous.");
|
|
67331
67559
|
},
|
|
67332
67560
|
output() {
|
|
@@ -67339,13 +67567,15 @@ function createScriptRuntime(module, initial, host) {
|
|
|
67339
67567
|
hits,
|
|
67340
67568
|
shader: module.shader,
|
|
67341
67569
|
uniforms,
|
|
67570
|
+
passes,
|
|
67342
67571
|
listens: [...handlers].filter(([, callbacks]) => callbacks.size).map(([type]) => type),
|
|
67343
67572
|
animated: this.animated,
|
|
67344
67573
|
draws: typeof module.draw === "function",
|
|
67345
67574
|
updating: frames.size > 0,
|
|
67346
67575
|
frameRate: module.frameRate,
|
|
67347
67576
|
pixelated: module.pixelated,
|
|
67348
|
-
version: revision
|
|
67577
|
+
version: revision,
|
|
67578
|
+
sceneVersion: sceneRevision
|
|
67349
67579
|
};
|
|
67350
67580
|
},
|
|
67351
67581
|
snapshot(includeEffects = true, clone = true) {
|
|
@@ -67359,7 +67589,8 @@ function createScriptRuntime(module, initial, host) {
|
|
|
67359
67589
|
screen: layers.screen,
|
|
67360
67590
|
anchor,
|
|
67361
67591
|
hits,
|
|
67362
|
-
uniforms
|
|
67592
|
+
uniforms,
|
|
67593
|
+
passes
|
|
67363
67594
|
} : void 0
|
|
67364
67595
|
};
|
|
67365
67596
|
return clone ? structuredClone(snapshot) : snapshot;
|
|
@@ -67374,6 +67605,7 @@ function createScriptRuntime(module, initial, host) {
|
|
|
67374
67605
|
layers.screen = {};
|
|
67375
67606
|
hits = {};
|
|
67376
67607
|
uniforms = void 0;
|
|
67608
|
+
passes = void 0;
|
|
67377
67609
|
}
|
|
67378
67610
|
};
|
|
67379
67611
|
}
|
|
@@ -67480,12 +67712,14 @@ function scriptAgent(runtimeFactory, applyDelta, moduleUrls, load) {
|
|
|
67480
67712
|
}
|
|
67481
67713
|
const output = runtime.output();
|
|
67482
67714
|
const changed = output.version !== instance.outputVersion;
|
|
67715
|
+
const { shader: _shader, parameters: _parameters, ...repeat } = output;
|
|
67716
|
+
const sent = changed ? instance.outputVersion < 0 ? output : repeat : void 0;
|
|
67483
67717
|
instance.outputVersion = output.version;
|
|
67484
67718
|
send({
|
|
67485
67719
|
token,
|
|
67486
67720
|
kind: "frame",
|
|
67487
67721
|
request: data.request,
|
|
67488
|
-
output:
|
|
67722
|
+
output: sent,
|
|
67489
67723
|
bitmap
|
|
67490
67724
|
}, bitmap ? [bitmap] : []);
|
|
67491
67725
|
} catch (error) {
|
|
@@ -67982,11 +68216,15 @@ function createBoardScriptHost(options) {
|
|
|
67982
68216
|
const acceptsBitmap = Boolean(data.bitmap) && (options.export || !options.isMaterialized || options.isMaterialized(entry.id)) && entry.draw;
|
|
67983
68217
|
if (acceptsBitmap) entry.texture.update(data.bitmap, (output ?? entry.output)?.pixelated === true);
|
|
67984
68218
|
else data.bitmap?.close?.();
|
|
67985
|
-
|
|
67986
|
-
|
|
68219
|
+
if (output && entry.output) {
|
|
68220
|
+
output.shader ??= entry.output.shader;
|
|
68221
|
+
output.parameters ??= entry.output.parameters;
|
|
68222
|
+
}
|
|
68223
|
+
let changed = acceptsBitmap;
|
|
68224
|
+
if (acceptsBitmap || output) revisions.set(entry.id, (revisions.get(entry.id) ?? 0) + 1);
|
|
67987
68225
|
try {
|
|
67988
68226
|
if (output) {
|
|
67989
|
-
options.onOutput(entry.id, output);
|
|
68227
|
+
changed = options.onOutput(entry.id, output) !== false || changed;
|
|
67990
68228
|
entry.output = output;
|
|
67991
68229
|
}
|
|
67992
68230
|
} catch (error) {
|
|
@@ -67994,7 +68232,7 @@ function createBoardScriptHost(options) {
|
|
|
67994
68232
|
return;
|
|
67995
68233
|
}
|
|
67996
68234
|
if (changed || options.export) options.onFrame();
|
|
67997
|
-
else if (needsTick(entry)) schedule();
|
|
68235
|
+
else if (output || needsTick(entry)) schedule();
|
|
67998
68236
|
};
|
|
67999
68237
|
window.addEventListener("message", onMessage);
|
|
68000
68238
|
function focusTarget(id, target) {
|
|
@@ -68289,6 +68527,34 @@ function createBoardScriptHost(options) {
|
|
|
68289
68527
|
};
|
|
68290
68528
|
}
|
|
68291
68529
|
//#endregion
|
|
68530
|
+
//#region ../sdk/src/board/model/script-calls.ts
|
|
68531
|
+
function layoutBoardScriptText(value) {
|
|
68532
|
+
const input = value;
|
|
68533
|
+
if (!input || typeof input.text !== "string" || input.text.length > 1e4) throw new Error("layoutText() needs text of at most 10000 characters.");
|
|
68534
|
+
for (const key of [
|
|
68535
|
+
"fontSize",
|
|
68536
|
+
"fontWeight",
|
|
68537
|
+
"lineHeight",
|
|
68538
|
+
"width"
|
|
68539
|
+
]) if (input[key] !== void 0 && !(Number.isFinite(input[key]) && input[key] > 0)) throw new Error(`layoutText() ${key} must be a positive number.`);
|
|
68540
|
+
const { width, height } = layoutBoardText({
|
|
68541
|
+
fontSize: 24,
|
|
68542
|
+
fontWeight: 500,
|
|
68543
|
+
font: "sans",
|
|
68544
|
+
lineHeight: 4 / 3,
|
|
68545
|
+
...input
|
|
68546
|
+
});
|
|
68547
|
+
return {
|
|
68548
|
+
width,
|
|
68549
|
+
height
|
|
68550
|
+
};
|
|
68551
|
+
}
|
|
68552
|
+
const BOARD_SCRIPT_EXPORT_CALLS = {
|
|
68553
|
+
"board.emit": () => void 0,
|
|
68554
|
+
"board.commit": () => false,
|
|
68555
|
+
"board.layoutText": layoutBoardScriptText
|
|
68556
|
+
};
|
|
68557
|
+
//#endregion
|
|
68292
68558
|
//#region ../sdk/src/board/render/shader/library.ts
|
|
68293
68559
|
const BOARD_SHADER_LIBRARY = {
|
|
68294
68560
|
hash: `
|
|
@@ -68352,6 +68618,12 @@ float luminance(vec3 c) { return dot(c, vec3(0.2126, 0.7152, 0.0722)); }
|
|
|
68352
68618
|
//#endregion
|
|
68353
68619
|
//#region ../sdk/src/board/render/shader/program.ts
|
|
68354
68620
|
const BOARD_SHADER_ITERATIONS = 65536;
|
|
68621
|
+
const BOARD_SPRITE_PLACEMENTS = [
|
|
68622
|
+
"uCohubSpriteGeometry",
|
|
68623
|
+
"uCohubSpriteColor",
|
|
68624
|
+
"uCohubSpriteData",
|
|
68625
|
+
"uCohubSpriteRotation"
|
|
68626
|
+
];
|
|
68355
68627
|
const FORBIDDEN = [
|
|
68356
68628
|
[/#\s*(version|extension|pragma|line)\b/, "#version, #extension, #pragma and #line are set by Cohub"],
|
|
68357
68629
|
[/\b(uniform|attribute|varying|layout)\b/, "declare uniforms in shader.uniforms; inputs and outputs belong to Cohub"],
|
|
@@ -68442,7 +68714,8 @@ function declarations(input, stage) {
|
|
|
68442
68714
|
"precision highp float;",
|
|
68443
68715
|
"precision highp int;",
|
|
68444
68716
|
"precision highp sampler2D;",
|
|
68445
|
-
stage === "vertex" ? "#define COHUB_VERTEX 1" : "#define COHUB_FRAGMENT 1"
|
|
68717
|
+
stage === "vertex" ? "#define COHUB_VERTEX 1" : "#define COHUB_FRAGMENT 1",
|
|
68718
|
+
`#define COHUB_SPRITE_COLUMNS 256`
|
|
68446
68719
|
];
|
|
68447
68720
|
if (stage === "vertex") lines.push("#define dFdx(x) ((x) * 0.0)", "#define dFdy(x) ((x) * 0.0)", "#define fwidth(x) ((x) * 0.0)", "#define discard return vec4(0.0)");
|
|
68448
68721
|
lines.push("struct Board { float time; float delta; int frame; vec2 size; vec4 view; vec2 resolution; float zoom; float seed; float quality; float dark; };", "uniform Board board;");
|
|
@@ -68465,6 +68738,22 @@ vec4 cohubClip(vec2 local) {
|
|
|
68465
68738
|
return vec4((m * vec3(local, 1.0)).xy, 0.0, 1.0);
|
|
68466
68739
|
}`;
|
|
68467
68740
|
const VARYINGS = "vec2 vCohubUv; vec2 vCohubLocal; vec4 vCohubColor; vec4 vCohubData;";
|
|
68741
|
+
function spriteVertex(out) {
|
|
68742
|
+
return `in vec2 aPosition;
|
|
68743
|
+
${CLIP}
|
|
68744
|
+
${out}
|
|
68745
|
+
void cohubEmit(vec2 position, vec2 size, float rotation, vec4 color, vec4 data) {
|
|
68746
|
+
vec2 corner = (aPosition - 0.5) * size;
|
|
68747
|
+
float c = cos(rotation);
|
|
68748
|
+
float r = sin(rotation);
|
|
68749
|
+
vec2 local = position + vec2(corner.x * c - corner.y * r, corner.x * r + corner.y * c);
|
|
68750
|
+
gl_Position = cohubClip(local);
|
|
68751
|
+
vCohubUv = aPosition;
|
|
68752
|
+
vCohubLocal = local;
|
|
68753
|
+
vCohubColor = color;
|
|
68754
|
+
vCohubData = data;
|
|
68755
|
+
}`;
|
|
68756
|
+
}
|
|
68468
68757
|
function vertexMain(kind) {
|
|
68469
68758
|
const out = VARYINGS.split(" ").reduce((text, part, index) => text + (index % 2 ? `${part} ` : `out ${part} `), "");
|
|
68470
68759
|
if (kind === "filter") return `in vec2 aPosition;
|
|
@@ -68481,22 +68770,20 @@ void main() {
|
|
|
68481
68770
|
vCohubColor = vec4(1.0);
|
|
68482
68771
|
vCohubData = vec4(0.0);
|
|
68483
68772
|
}`;
|
|
68484
|
-
if (kind === "
|
|
68485
|
-
${
|
|
68486
|
-
|
|
68773
|
+
if (kind === "placed") return `${spriteVertex(out)}
|
|
68774
|
+
${BOARD_SPRITE_PLACEMENTS.map((name) => `uniform sampler2D ${name};`).join("\n")}
|
|
68775
|
+
void main() {
|
|
68776
|
+
ivec2 at = ivec2(gl_InstanceID % COHUB_SPRITE_COLUMNS, gl_InstanceID / COHUB_SPRITE_COLUMNS);
|
|
68777
|
+
vec4 placed = texelFetch(uCohubSpriteGeometry, at, 0);
|
|
68778
|
+
if (placed.z <= 0.0 || placed.w <= 0.0) { gl_Position = vec4(2.0, 2.0, 2.0, 1.0); return; }
|
|
68779
|
+
cohubEmit(placed.xy, placed.zw, texelFetch(uCohubSpriteRotation, at, 0).x, texelFetch(uCohubSpriteColor, at, 0), texelFetch(uCohubSpriteData, at, 0));
|
|
68780
|
+
}`;
|
|
68781
|
+
if (kind === "sprites") return `${spriteVertex(out)}
|
|
68487
68782
|
void main() {
|
|
68488
68783
|
cohubIterations = 0;
|
|
68489
68784
|
Sprite s = sprite(gl_InstanceID);
|
|
68490
68785
|
if (!s.visible || s.size.x <= 0.0 || s.size.y <= 0.0) { gl_Position = vec4(2.0, 2.0, 2.0, 1.0); return; }
|
|
68491
|
-
|
|
68492
|
-
float c = cos(s.rotation);
|
|
68493
|
-
float r = sin(s.rotation);
|
|
68494
|
-
vec2 local = s.position + vec2(corner.x * c - corner.y * r, corner.x * r + corner.y * c);
|
|
68495
|
-
gl_Position = cohubClip(local);
|
|
68496
|
-
vCohubUv = aPosition;
|
|
68497
|
-
vCohubLocal = local;
|
|
68498
|
-
vCohubColor = s.color;
|
|
68499
|
-
vCohubData = s.data;
|
|
68786
|
+
cohubEmit(s.position, s.size, s.rotation, s.color, s.data);
|
|
68500
68787
|
}`;
|
|
68501
68788
|
return `in vec2 aPosition;
|
|
68502
68789
|
uniform vec4 uCohubGeometry;
|
|
@@ -68512,7 +68799,25 @@ void main() {
|
|
|
68512
68799
|
}`;
|
|
68513
68800
|
}
|
|
68514
68801
|
function fragmentMain(kind) {
|
|
68515
|
-
|
|
68802
|
+
const inputs = VARYINGS.split(" ").reduce((text, part, index) => text + (index % 2 ? `${part} ` : `in ${part} `), "");
|
|
68803
|
+
if (kind === "place") return `uniform int uCohubSpriteCount;
|
|
68804
|
+
layout(location = 0) out vec4 cohubGeometry;
|
|
68805
|
+
layout(location = 1) out vec4 cohubColor;
|
|
68806
|
+
layout(location = 2) out vec4 cohubData;
|
|
68807
|
+
layout(location = 3) out vec4 cohubRotation;
|
|
68808
|
+
void main() {
|
|
68809
|
+
cohubIterations = 0;
|
|
68810
|
+
ivec2 at = ivec2(gl_FragCoord.xy);
|
|
68811
|
+
int id = at.y * COHUB_SPRITE_COLUMNS + at.x;
|
|
68812
|
+
if (id >= uCohubSpriteCount) { cohubGeometry = vec4(0.0); return; }
|
|
68813
|
+
Sprite s = sprite(id);
|
|
68814
|
+
bool shown = s.visible && s.size.x > 0.0 && s.size.y > 0.0;
|
|
68815
|
+
cohubGeometry = shown ? vec4(s.position, s.size) : vec4(0.0);
|
|
68816
|
+
cohubColor = s.color;
|
|
68817
|
+
cohubData = s.data;
|
|
68818
|
+
cohubRotation = vec4(s.rotation, 0.0, 0.0, 0.0);
|
|
68819
|
+
}`;
|
|
68820
|
+
return `${inputs}
|
|
68516
68821
|
${kind === "filter" ? "in vec2 vTextureCoord;" : "uniform vec4 uColor;"}
|
|
68517
68822
|
out vec4 finalColor;
|
|
68518
68823
|
void main() {
|
|
@@ -68528,16 +68833,18 @@ function lineCount(text) {
|
|
|
68528
68833
|
function buildBoardShaderProgram(input) {
|
|
68529
68834
|
const { code, includes } = prepareBoardShaderSource(input.glsl);
|
|
68530
68835
|
const library = includes.map((name) => BOARD_SHADER_LIBRARY[name]).join("\n");
|
|
68531
|
-
const
|
|
68532
|
-
const head = `${declarations(input,
|
|
68533
|
-
const main = name === "vertex" ? vertexMain(input.kind) : fragmentMain(input.kind);
|
|
68836
|
+
const author = (role, main) => {
|
|
68837
|
+
const head = `${declarations(input, role)}\n${library}`;
|
|
68534
68838
|
return {
|
|
68535
68839
|
source: `${head}\n${code}\n${main}\n`,
|
|
68536
68840
|
firstLine: lineCount(head) + 1
|
|
68537
68841
|
};
|
|
68538
68842
|
};
|
|
68539
|
-
const vertex =
|
|
68540
|
-
|
|
68843
|
+
const vertex = input.kind === "sprites" ? author("vertex", vertexMain(input.kind)) : {
|
|
68844
|
+
source: `${declarations(input, "vertex")}\n${vertexMain(input.kind)}\n`,
|
|
68845
|
+
firstLine: 1
|
|
68846
|
+
};
|
|
68847
|
+
const fragment = author(input.kind === "place" ? "vertex" : "fragment", fragmentMain(input.kind));
|
|
68541
68848
|
return {
|
|
68542
68849
|
vertex: vertex.source,
|
|
68543
68850
|
fragment: fragment.source,
|
|
@@ -68554,6 +68861,100 @@ function describeBoardShaderError(log, firstLine, label) {
|
|
|
68554
68861
|
})).slice(0, 4).join("; ") || "the shader failed to compile"}`;
|
|
68555
68862
|
}
|
|
68556
68863
|
//#endregion
|
|
68864
|
+
//#region ../sdk/src/board/render/shader/compile.ts
|
|
68865
|
+
const READY = {
|
|
68866
|
+
poll: () => true,
|
|
68867
|
+
cancel() {}
|
|
68868
|
+
};
|
|
68869
|
+
const COMPLETION_STATUS = 37297;
|
|
68870
|
+
const failures = /* @__PURE__ */ new Map();
|
|
68871
|
+
const parallel = /* @__PURE__ */ new WeakMap();
|
|
68872
|
+
function programs(renderer) {
|
|
68873
|
+
return renderer.shader._programDataHash ?? null;
|
|
68874
|
+
}
|
|
68875
|
+
function adopt(gl, glProgram, program, cache) {
|
|
68876
|
+
glProgram._attributeData = extractAttributesFromGlProgram(program, gl, false);
|
|
68877
|
+
glProgram._uniformData = getUniformData(program, gl);
|
|
68878
|
+
glProgram._uniformBlockData = getUboData(program, gl);
|
|
68879
|
+
const uniforms = {};
|
|
68880
|
+
for (const [name, data] of Object.entries(glProgram._uniformData)) uniforms[name] = {
|
|
68881
|
+
location: gl.getUniformLocation(program, name),
|
|
68882
|
+
value: defaultValue(data.type, data.size)
|
|
68883
|
+
};
|
|
68884
|
+
cache[glProgram._key] = new GlProgramData(program, uniforms);
|
|
68885
|
+
}
|
|
68886
|
+
function lineShift(raw, final) {
|
|
68887
|
+
return final.split("\n").length - raw.split("\n").length;
|
|
68888
|
+
}
|
|
68889
|
+
function compileBoardProgram(renderer, glProgram, source, label, wait) {
|
|
68890
|
+
if (renderer.type !== RendererType.WEBGL) return READY;
|
|
68891
|
+
const failure = failures.get(glProgram._key);
|
|
68892
|
+
if (failure) throw new Error(failure);
|
|
68893
|
+
const cache = programs(renderer);
|
|
68894
|
+
if (cache?.[glProgram._key]) return READY;
|
|
68895
|
+
const gl = renderer.gl;
|
|
68896
|
+
if (!parallel.has(gl)) parallel.set(gl, Boolean(gl.getExtension("KHR_parallel_shader_compile")));
|
|
68897
|
+
const job = {
|
|
68898
|
+
gl,
|
|
68899
|
+
program: gl.createProgram(),
|
|
68900
|
+
shaders: [gl.createShader(gl.VERTEX_SHADER), gl.createShader(gl.FRAGMENT_SHADER)]
|
|
68901
|
+
};
|
|
68902
|
+
const vertex = glProgram.vertex;
|
|
68903
|
+
const fragment = glProgram.fragment;
|
|
68904
|
+
const stages = [{
|
|
68905
|
+
shader: job.shaders[0],
|
|
68906
|
+
code: vertex,
|
|
68907
|
+
first: source.firstLine.vertex + lineShift(source.vertex, vertex),
|
|
68908
|
+
name: "vertex"
|
|
68909
|
+
}, {
|
|
68910
|
+
shader: job.shaders[1],
|
|
68911
|
+
code: fragment,
|
|
68912
|
+
first: source.firstLine.fragment + lineShift(source.fragment, fragment),
|
|
68913
|
+
name: "fragment"
|
|
68914
|
+
}];
|
|
68915
|
+
for (const { shader, code } of stages) {
|
|
68916
|
+
gl.shaderSource(shader, code);
|
|
68917
|
+
gl.compileShader(shader);
|
|
68918
|
+
gl.attachShader(job.program, shader);
|
|
68919
|
+
}
|
|
68920
|
+
gl.linkProgram(job.program);
|
|
68921
|
+
let done = false;
|
|
68922
|
+
const finish = () => {
|
|
68923
|
+
done = true;
|
|
68924
|
+
let error = null;
|
|
68925
|
+
if (!gl.getProgramParameter(job.program, gl.LINK_STATUS) && !gl.isContextLost()) {
|
|
68926
|
+
for (const { shader, first, name } of stages) if (!error && !gl.getShaderParameter(shader, gl.COMPILE_STATUS)) error = describeBoardShaderError(gl.getShaderInfoLog(shader) ?? "", first, `${label} (${name})`);
|
|
68927
|
+
error ??= `${label}: ${gl.getProgramInfoLog(job.program) ?? "the shader failed to link"}`;
|
|
68928
|
+
}
|
|
68929
|
+
for (const shader of job.shaders) gl.deleteShader(shader);
|
|
68930
|
+
if (error || !cache || gl.isContextLost()) {
|
|
68931
|
+
gl.deleteProgram(job.program);
|
|
68932
|
+
if (error) {
|
|
68933
|
+
if (failures.size > 256) failures.clear();
|
|
68934
|
+
failures.set(glProgram._key, error);
|
|
68935
|
+
throw new Error(error);
|
|
68936
|
+
}
|
|
68937
|
+
return true;
|
|
68938
|
+
}
|
|
68939
|
+
if (cache[glProgram._key]) gl.deleteProgram(job.program);
|
|
68940
|
+
else adopt(gl, glProgram, job.program, cache);
|
|
68941
|
+
return true;
|
|
68942
|
+
};
|
|
68943
|
+
if (wait || !parallel.get(gl)) {
|
|
68944
|
+
finish();
|
|
68945
|
+
return READY;
|
|
68946
|
+
}
|
|
68947
|
+
return {
|
|
68948
|
+
poll: () => done || (gl.getProgramParameter(job.program, COMPLETION_STATUS) === true ? finish() : false),
|
|
68949
|
+
cancel() {
|
|
68950
|
+
if (done) return;
|
|
68951
|
+
done = true;
|
|
68952
|
+
for (const shader of job.shaders) gl.deleteShader(shader);
|
|
68953
|
+
gl.deleteProgram(job.program);
|
|
68954
|
+
}
|
|
68955
|
+
};
|
|
68956
|
+
}
|
|
68957
|
+
//#endregion
|
|
68557
68958
|
//#region ../sdk/src/board/render/shader/quad.ts
|
|
68558
68959
|
function boardQuadGeometry(instanceCount = 1) {
|
|
68559
68960
|
return new Geometry({
|
|
@@ -68581,14 +68982,18 @@ function boardQuadGeometry(instanceCount = 1) {
|
|
|
68581
68982
|
instanceCount
|
|
68582
68983
|
});
|
|
68583
68984
|
}
|
|
68985
|
+
function boardGlProgram(name, source) {
|
|
68986
|
+
return GlProgram.from({
|
|
68987
|
+
name,
|
|
68988
|
+
vertex: source.vertex,
|
|
68989
|
+
fragment: source.fragment,
|
|
68990
|
+
preferredFragmentPrecision: "highp"
|
|
68991
|
+
});
|
|
68992
|
+
}
|
|
68584
68993
|
function boardShaderMesh(name, source, resources, geometry = boardQuadGeometry()) {
|
|
68994
|
+
const glProgram = source instanceof GlProgram ? source : boardGlProgram(name, source);
|
|
68585
68995
|
const shader = new Shader({
|
|
68586
|
-
glProgram
|
|
68587
|
-
name,
|
|
68588
|
-
vertex: source.vertex,
|
|
68589
|
-
fragment: source.fragment,
|
|
68590
|
-
preferredFragmentPrecision: "highp"
|
|
68591
|
-
}),
|
|
68996
|
+
glProgram,
|
|
68592
68997
|
resources
|
|
68593
68998
|
});
|
|
68594
68999
|
return {
|
|
@@ -68631,6 +69036,8 @@ const STEP_MS = 1e3 / 60;
|
|
|
68631
69036
|
const STEPS_PER_FRAME = 8;
|
|
68632
69037
|
const MAX_LAG = 60;
|
|
68633
69038
|
const MAX_REPLAY = 36e3;
|
|
69039
|
+
const CHECKPOINT_STEPS = 600;
|
|
69040
|
+
const CHECKPOINTS = 6;
|
|
68634
69041
|
const PIXI_TYPES = {
|
|
68635
69042
|
float: "f32",
|
|
68636
69043
|
int: "i32",
|
|
@@ -68645,45 +69052,50 @@ const SIZES = {
|
|
|
68645
69052
|
vec3: 3,
|
|
68646
69053
|
vec4: 4
|
|
68647
69054
|
};
|
|
68648
|
-
const
|
|
68649
|
-
function
|
|
68650
|
-
|
|
68651
|
-
|
|
68652
|
-
|
|
68653
|
-
|
|
68654
|
-
|
|
68655
|
-
|
|
68656
|
-
|
|
68657
|
-
|
|
68658
|
-
|
|
68659
|
-
|
|
68660
|
-
|
|
68661
|
-
|
|
68662
|
-
|
|
68663
|
-
|
|
68664
|
-
|
|
68665
|
-
|
|
68666
|
-
|
|
68667
|
-
|
|
68668
|
-
|
|
68669
|
-
|
|
68670
|
-
|
|
68671
|
-
|
|
68672
|
-
|
|
68673
|
-
|
|
68674
|
-
|
|
68675
|
-
|
|
68676
|
-
|
|
68677
|
-
|
|
68678
|
-
|
|
68679
|
-
|
|
68680
|
-
|
|
68681
|
-
|
|
68682
|
-
|
|
68683
|
-
|
|
68684
|
-
|
|
69055
|
+
const placing = /* @__PURE__ */ new WeakMap();
|
|
69056
|
+
function canPlaceSprites(renderer) {
|
|
69057
|
+
let supported = placing.get(renderer);
|
|
69058
|
+
if (supported === void 0) {
|
|
69059
|
+
const gl = renderer.type === RendererType.WEBGL ? renderer.gl : null;
|
|
69060
|
+
supported = Boolean(gl?.getExtension("EXT_color_buffer_float") && gl.getParameter(gl.MAX_DRAW_BUFFERS) >= BOARD_SPRITE_PLACEMENTS.length);
|
|
69061
|
+
placing.set(renderer, supported);
|
|
69062
|
+
}
|
|
69063
|
+
return supported;
|
|
69064
|
+
}
|
|
69065
|
+
function createPlacement(mesh, uniforms, sprites) {
|
|
69066
|
+
mesh.mesh.blendMode = "none";
|
|
69067
|
+
const height = Math.ceil(sprites / 256);
|
|
69068
|
+
const textures = BOARD_SPRITE_PLACEMENTS.map(() => new TextureSource({
|
|
69069
|
+
width: 256,
|
|
69070
|
+
height,
|
|
69071
|
+
resolution: 1,
|
|
69072
|
+
format: "rgba32float",
|
|
69073
|
+
scaleMode: "nearest",
|
|
69074
|
+
autoGenerateMipmaps: false
|
|
69075
|
+
}));
|
|
69076
|
+
return {
|
|
69077
|
+
mesh,
|
|
69078
|
+
uniforms,
|
|
69079
|
+
target: new RenderTarget({
|
|
69080
|
+
colorTextures: textures,
|
|
69081
|
+
width: 256,
|
|
69082
|
+
height,
|
|
69083
|
+
resolution: 1
|
|
69084
|
+
}),
|
|
69085
|
+
textures
|
|
69086
|
+
};
|
|
69087
|
+
}
|
|
69088
|
+
function destroyPlacement(renderer, placement) {
|
|
69089
|
+
const system = renderer.renderTarget;
|
|
69090
|
+
const gpu = system._gpuRenderTargetHash?.[placement.target.uid];
|
|
69091
|
+
if (gpu && system._gpuRenderTargetHash) {
|
|
69092
|
+
system._gpuRenderTargetHash[placement.target.uid] = null;
|
|
69093
|
+
system.adaptor?.destroyGpuRenderTarget(gpu);
|
|
68685
69094
|
}
|
|
68686
|
-
|
|
69095
|
+
system._renderSurfaceToRenderTargetHash?.delete(placement.target);
|
|
69096
|
+
placement.target.destroy();
|
|
69097
|
+
for (const texture of placement.textures) texture.destroy();
|
|
69098
|
+
destroyBoardShaderMesh(placement.mesh);
|
|
68687
69099
|
}
|
|
68688
69100
|
function boardUniforms(parameters, uniforms) {
|
|
68689
69101
|
const vec = (size) => new Float32Array(size);
|
|
@@ -68732,6 +69144,10 @@ function boardUniforms(parameters, uniforms) {
|
|
|
68732
69144
|
value: vec(4),
|
|
68733
69145
|
type: "vec4<f32>"
|
|
68734
69146
|
},
|
|
69147
|
+
uCohubSpriteCount: {
|
|
69148
|
+
value: 0,
|
|
69149
|
+
type: "i32"
|
|
69150
|
+
},
|
|
68735
69151
|
uCohubRegion: {
|
|
68736
69152
|
value: vec(4),
|
|
68737
69153
|
type: "vec4<f32>"
|
|
@@ -68811,8 +69227,7 @@ function seedOf(value) {
|
|
|
68811
69227
|
function boardShaderSeed(seed) {
|
|
68812
69228
|
return seedOf(seed);
|
|
68813
69229
|
}
|
|
68814
|
-
function createBoardShaderLayer(renderer, shader, parameters, label) {
|
|
68815
|
-
const layer = shader.layer ?? "above";
|
|
69230
|
+
function createBoardShaderLayer(renderer, shader, parameters, label, options = {}) {
|
|
68816
69231
|
const uniforms = boardShaderUniforms(shader.uniforms);
|
|
68817
69232
|
const surfaces = shader.surfaces === true;
|
|
68818
69233
|
const hasState = shader.state !== void 0;
|
|
@@ -68822,19 +69237,21 @@ function createBoardShaderLayer(renderer, shader, parameters, label) {
|
|
|
68822
69237
|
surfaces,
|
|
68823
69238
|
state: hasState
|
|
68824
69239
|
};
|
|
69240
|
+
const compiles = [];
|
|
68825
69241
|
const program = (kind, glsl, name) => {
|
|
68826
|
-
let built;
|
|
68827
69242
|
try {
|
|
68828
|
-
built = buildBoardShaderProgram({
|
|
69243
|
+
const built = buildBoardShaderProgram({
|
|
68829
69244
|
...base,
|
|
68830
69245
|
kind,
|
|
68831
69246
|
glsl
|
|
68832
69247
|
});
|
|
69248
|
+
const glProgram = boardGlProgram(`board-shader-${kind}`, built);
|
|
69249
|
+
compiles.push(compileBoardProgram(renderer, glProgram, built, name, options.wait === true));
|
|
69250
|
+
return glProgram;
|
|
68833
69251
|
} catch (error) {
|
|
68834
|
-
|
|
69252
|
+
const message = error instanceof Error ? error.message : String(error);
|
|
69253
|
+
throw new Error(message.startsWith(name) ? message : `${name}: ${message}`);
|
|
68835
69254
|
}
|
|
68836
|
-
check(renderer, built, name);
|
|
68837
|
-
return built;
|
|
68838
69255
|
};
|
|
68839
69256
|
const group = boardUniforms(parameters, uniforms);
|
|
68840
69257
|
const textures = {};
|
|
@@ -68842,37 +69259,61 @@ function createBoardShaderLayer(renderer, shader, parameters, label) {
|
|
|
68842
69259
|
if (hasState) textures.uCohubState = Texture.EMPTY.source;
|
|
68843
69260
|
const meshes = [];
|
|
68844
69261
|
const filters = [];
|
|
68845
|
-
const
|
|
69262
|
+
const containers = {
|
|
69263
|
+
below: null,
|
|
69264
|
+
above: null
|
|
69265
|
+
};
|
|
69266
|
+
const area = new Rectangle();
|
|
69267
|
+
const place = canPlaceSprites(renderer);
|
|
69268
|
+
let placementsStale = true;
|
|
68846
69269
|
shader.passes.forEach((pass, index) => {
|
|
68847
69270
|
const name = `${label} pass ${index + 1}`;
|
|
69271
|
+
const layer = boardShaderPassLayer(shader, pass);
|
|
68848
69272
|
if (layer === "filter") {
|
|
68849
|
-
const built = program("filter", pass.glsl, name);
|
|
68850
69273
|
const filter = new Filter({
|
|
68851
|
-
glProgram:
|
|
68852
|
-
name: `board-shader-filter`,
|
|
68853
|
-
vertex: built.vertex,
|
|
68854
|
-
fragment: built.fragment,
|
|
68855
|
-
preferredFragmentPrecision: "highp"
|
|
68856
|
-
}),
|
|
69274
|
+
glProgram: program("filter", pass.glsl, name),
|
|
68857
69275
|
resources: {
|
|
68858
69276
|
cohubUniforms: group,
|
|
68859
69277
|
...textures
|
|
68860
69278
|
},
|
|
68861
|
-
padding: 0
|
|
69279
|
+
padding: 0,
|
|
69280
|
+
resolution: "inherit"
|
|
69281
|
+
});
|
|
69282
|
+
filters.push({
|
|
69283
|
+
filter,
|
|
69284
|
+
pass
|
|
68862
69285
|
});
|
|
68863
|
-
filters.push(filter);
|
|
68864
69286
|
return;
|
|
68865
69287
|
}
|
|
68866
69288
|
const sprites = pass.sprites ?? 0;
|
|
68867
|
-
|
|
69289
|
+
let placement = null;
|
|
69290
|
+
if (sprites && place) {
|
|
69291
|
+
const own = boardUniforms(parameters, uniforms);
|
|
69292
|
+
placement = createPlacement(boardShaderMesh("board-shader-place", program("place", pass.glsl, name), {
|
|
69293
|
+
cohubUniforms: own,
|
|
69294
|
+
...textures
|
|
69295
|
+
}), own, sprites);
|
|
69296
|
+
}
|
|
69297
|
+
const kind = !sprites ? "box" : placement ? "placed" : "sprites";
|
|
69298
|
+
const resources = {
|
|
68868
69299
|
cohubUniforms: group,
|
|
68869
69300
|
...textures
|
|
68870
|
-
}
|
|
69301
|
+
};
|
|
69302
|
+
placement?.textures.forEach((texture, slot) => {
|
|
69303
|
+
resources[BOARD_SPRITE_PLACEMENTS[slot]] = texture;
|
|
69304
|
+
});
|
|
69305
|
+
const drawn = boardShaderMesh("board-shader", program(kind, pass.glsl, name), resources, boardQuadGeometry(Math.max(1, sprites)));
|
|
68871
69306
|
drawn.mesh.blendMode = pass.blend ?? "normal";
|
|
68872
|
-
|
|
69307
|
+
containers[layer] ??= new Container({ label: `board-shader-${label}-${layer}` });
|
|
69308
|
+
const container = containers[layer];
|
|
69309
|
+
container.boundsArea = area;
|
|
69310
|
+
container.addChild(drawn.mesh);
|
|
68873
69311
|
meshes.push({
|
|
68874
69312
|
...drawn,
|
|
68875
|
-
|
|
69313
|
+
pass,
|
|
69314
|
+
sprites,
|
|
69315
|
+
placement,
|
|
69316
|
+
scaler: null
|
|
68876
69317
|
});
|
|
68877
69318
|
});
|
|
68878
69319
|
let state = null;
|
|
@@ -68895,6 +69336,7 @@ function createBoardShaderLayer(renderer, shader, parameters, label) {
|
|
|
68895
69336
|
const blank = new Container();
|
|
68896
69337
|
let time = 0;
|
|
68897
69338
|
let quality = 1;
|
|
69339
|
+
let compiled = compiles.length === 0;
|
|
68898
69340
|
let last = null;
|
|
68899
69341
|
const stateRegion = (frame) => shader.state?.bounds ?? frame.region;
|
|
68900
69342
|
function fill(target, frame, geometry, step) {
|
|
@@ -68954,28 +69396,163 @@ function createBoardShaderLayer(renderer, shader, parameters, label) {
|
|
|
68954
69396
|
}
|
|
68955
69397
|
target.update();
|
|
68956
69398
|
}
|
|
69399
|
+
const checkpoints = [];
|
|
69400
|
+
let surfaceKey = "";
|
|
69401
|
+
const copier = new Sprite();
|
|
69402
|
+
copier.blendMode = "none";
|
|
69403
|
+
const copy = (target, from, to) => {
|
|
69404
|
+
copier.texture = from;
|
|
69405
|
+
target.render({
|
|
69406
|
+
container: copier,
|
|
69407
|
+
target: to,
|
|
69408
|
+
clear: true,
|
|
69409
|
+
clearColor: [
|
|
69410
|
+
0,
|
|
69411
|
+
0,
|
|
69412
|
+
0,
|
|
69413
|
+
0
|
|
69414
|
+
]
|
|
69415
|
+
});
|
|
69416
|
+
};
|
|
69417
|
+
const inputs = ({ time: _time, ...frame }) => JSON.stringify([frame, surfaceKey]);
|
|
69418
|
+
function checkpoint(target, state, key) {
|
|
69419
|
+
if (checkpoints.some((entry) => entry.steps === state.steps && entry.key === key)) return;
|
|
69420
|
+
const texture = (checkpoints.length >= CHECKPOINTS ? checkpoints.shift() : void 0)?.texture ?? boardRenderTarget(state.read.width, state.read.height, state.read.source.format);
|
|
69421
|
+
copy(target, state.read, texture);
|
|
69422
|
+
checkpoints.push({
|
|
69423
|
+
steps: state.steps,
|
|
69424
|
+
key,
|
|
69425
|
+
texture
|
|
69426
|
+
});
|
|
69427
|
+
}
|
|
69428
|
+
function advance(target, state, frame, catchUp) {
|
|
69429
|
+
const wanted = Math.floor(frame.time / STEP_MS);
|
|
69430
|
+
const key = catchUp ? inputs(frame) : "";
|
|
69431
|
+
let replaying = false;
|
|
69432
|
+
if (wanted < state.steps || state.steps < 0) {
|
|
69433
|
+
replaying = catchUp;
|
|
69434
|
+
for (const texture of [state.read, state.write]) target.render({
|
|
69435
|
+
container: blank,
|
|
69436
|
+
target: texture,
|
|
69437
|
+
clear: true,
|
|
69438
|
+
clearColor: [
|
|
69439
|
+
0,
|
|
69440
|
+
0,
|
|
69441
|
+
0,
|
|
69442
|
+
0
|
|
69443
|
+
]
|
|
69444
|
+
});
|
|
69445
|
+
state.steps = Math.max(0, wanted - MAX_REPLAY);
|
|
69446
|
+
const resume = catchUp ? checkpoints.reduce((best, entry) => entry.key === key && entry.steps <= wanted && entry.steps > (best?.steps ?? state.steps - 1) ? entry : best, null) : null;
|
|
69447
|
+
if (resume) {
|
|
69448
|
+
copy(target, resume.texture, state.read);
|
|
69449
|
+
state.steps = resume.steps;
|
|
69450
|
+
}
|
|
69451
|
+
}
|
|
69452
|
+
if (!catchUp && wanted - state.steps > MAX_LAG) state.steps = wanted - STEPS_PER_FRAME;
|
|
69453
|
+
const limit = catchUp ? Number.POSITIVE_INFINITY : STEPS_PER_FRAME;
|
|
69454
|
+
let ran = 0;
|
|
69455
|
+
while (state.steps < wanted && ran < limit) {
|
|
69456
|
+
fill(state.uniforms, frame, {
|
|
69457
|
+
x: 0,
|
|
69458
|
+
y: 0,
|
|
69459
|
+
width: state.write.width,
|
|
69460
|
+
height: state.write.height
|
|
69461
|
+
}, state.steps);
|
|
69462
|
+
state.simulate.shader.resources.uCohubState = state.read.source;
|
|
69463
|
+
target.render({
|
|
69464
|
+
container: state.simulate.mesh,
|
|
69465
|
+
target: state.write,
|
|
69466
|
+
clear: true
|
|
69467
|
+
});
|
|
69468
|
+
[state.read, state.write] = [state.write, state.read];
|
|
69469
|
+
state.steps++;
|
|
69470
|
+
ran++;
|
|
69471
|
+
if (replaying && state.steps % CHECKPOINT_STEPS === 0) checkpoint(target, state, key);
|
|
69472
|
+
}
|
|
69473
|
+
const source = state.read.source;
|
|
69474
|
+
for (const { shader, placement } of meshes) {
|
|
69475
|
+
shader.resources.uCohubState = source;
|
|
69476
|
+
if (placement) placement.mesh.shader.resources.uCohubState = source;
|
|
69477
|
+
}
|
|
69478
|
+
for (const { filter } of filters) filter.resources.uCohubState = source;
|
|
69479
|
+
return {
|
|
69480
|
+
ran,
|
|
69481
|
+
behind: state.steps < wanted
|
|
69482
|
+
};
|
|
69483
|
+
}
|
|
69484
|
+
function shade(drawn, frame) {
|
|
69485
|
+
const resolution = frame.density * Math.min(1, frame.shading ?? 1);
|
|
69486
|
+
const blend = drawn.pass.blend ?? "normal";
|
|
69487
|
+
if (resolution >= frame.density * .99) {
|
|
69488
|
+
if (!drawn.scaler) return;
|
|
69489
|
+
drawn.mesh.filters = null;
|
|
69490
|
+
drawn.mesh.filterArea = null;
|
|
69491
|
+
drawn.mesh.blendMode = blend;
|
|
69492
|
+
drawn.scaler.destroy();
|
|
69493
|
+
drawn.scaler = null;
|
|
69494
|
+
return;
|
|
69495
|
+
}
|
|
69496
|
+
if (!drawn.scaler) {
|
|
69497
|
+
drawn.scaler = new AlphaFilter({
|
|
69498
|
+
alpha: 1,
|
|
69499
|
+
blendMode: blend
|
|
69500
|
+
});
|
|
69501
|
+
drawn.mesh.blendMode = "normal";
|
|
69502
|
+
drawn.mesh.filters = [drawn.scaler];
|
|
69503
|
+
drawn.mesh.filterArea = area;
|
|
69504
|
+
}
|
|
69505
|
+
drawn.scaler.resolution = resolution;
|
|
69506
|
+
}
|
|
68957
69507
|
return {
|
|
68958
|
-
|
|
68959
|
-
|
|
68960
|
-
filters:
|
|
69508
|
+
below: containers.below,
|
|
69509
|
+
above: containers.above,
|
|
69510
|
+
filters: filters.length ? filters.map(({ filter }) => filter) : null,
|
|
68961
69511
|
surfaces,
|
|
68962
69512
|
animated: hasState,
|
|
69513
|
+
ready() {
|
|
69514
|
+
if (!compiled) compiled = compiles.every((compile) => compile.poll());
|
|
69515
|
+
return compiled;
|
|
69516
|
+
},
|
|
68963
69517
|
update(frame) {
|
|
68964
|
-
fill(group, frame, frame.region);
|
|
68965
|
-
time = frame.time;
|
|
68966
|
-
last = frame;
|
|
68967
69518
|
if (frame.quality !== quality) {
|
|
68968
69519
|
quality = frame.quality;
|
|
68969
69520
|
for (const { geometry, sprites } of meshes) if (sprites) geometry.instanceCount = Math.max(1, Math.round(sprites * quality));
|
|
68970
69521
|
}
|
|
69522
|
+
area.x = frame.region.x;
|
|
69523
|
+
area.y = frame.region.y;
|
|
69524
|
+
area.width = frame.region.width;
|
|
69525
|
+
area.height = frame.region.height;
|
|
69526
|
+
for (const drawn of meshes) {
|
|
69527
|
+
drawn.mesh.visible = boardShaderPassOn(drawn.pass, frame.passes);
|
|
69528
|
+
if (!drawn.sprites) shade(drawn, frame);
|
|
69529
|
+
}
|
|
69530
|
+
for (const { filter, pass } of filters) filter.enabled = boardShaderPassOn(pass, frame.passes);
|
|
69531
|
+
fill(group, frame, frame.region);
|
|
69532
|
+
for (const { geometry, placement } of meshes) {
|
|
69533
|
+
if (!placement) continue;
|
|
69534
|
+
placement.uniforms.uniforms.uCohubSpriteCount = geometry.instanceCount;
|
|
69535
|
+
fill(placement.uniforms, frame, {
|
|
69536
|
+
x: 0,
|
|
69537
|
+
y: 0,
|
|
69538
|
+
width: 256,
|
|
69539
|
+
height: Math.ceil(geometry.instanceCount / 256)
|
|
69540
|
+
});
|
|
69541
|
+
}
|
|
69542
|
+
time = frame.time;
|
|
69543
|
+
last = frame;
|
|
69544
|
+
placementsStale = true;
|
|
68971
69545
|
},
|
|
68972
69546
|
prepare(target, options) {
|
|
68973
|
-
if (!
|
|
68974
|
-
const
|
|
68975
|
-
|
|
68976
|
-
|
|
68977
|
-
|
|
68978
|
-
|
|
69547
|
+
if (!last) return false;
|
|
69548
|
+
const stepped = state ? advance(target, state, last, options?.catchUp === true) : {
|
|
69549
|
+
ran: 0,
|
|
69550
|
+
behind: false
|
|
69551
|
+
};
|
|
69552
|
+
if (placementsStale || stepped.ran) {
|
|
69553
|
+
for (const { placement, mesh } of meshes) if (placement && mesh.visible) target.render({
|
|
69554
|
+
container: placement.mesh.mesh,
|
|
69555
|
+
target: placement.target,
|
|
68979
69556
|
clear: true,
|
|
68980
69557
|
clearColor: [
|
|
68981
69558
|
0,
|
|
@@ -68984,38 +69561,21 @@ function createBoardShaderLayer(renderer, shader, parameters, label) {
|
|
|
68984
69561
|
0
|
|
68985
69562
|
]
|
|
68986
69563
|
});
|
|
68987
|
-
|
|
69564
|
+
placementsStale = false;
|
|
68988
69565
|
}
|
|
68989
|
-
|
|
68990
|
-
|
|
68991
|
-
|
|
68992
|
-
|
|
68993
|
-
fill(state.uniforms, last, {
|
|
68994
|
-
x: 0,
|
|
68995
|
-
y: 0,
|
|
68996
|
-
width: state.write.width,
|
|
68997
|
-
height: state.write.height
|
|
68998
|
-
}, state.steps);
|
|
68999
|
-
state.simulate.shader.resources.uCohubState = state.read.source;
|
|
69000
|
-
target.render({
|
|
69001
|
-
container: state.simulate.mesh,
|
|
69002
|
-
target: state.write,
|
|
69003
|
-
clear: true
|
|
69004
|
-
});
|
|
69005
|
-
[state.read, state.write] = [state.write, state.read];
|
|
69006
|
-
state.steps++;
|
|
69007
|
-
ran++;
|
|
69008
|
-
}
|
|
69009
|
-
const source = state.read.source;
|
|
69010
|
-
for (const { shader } of meshes) shader.resources.uCohubState = source;
|
|
69011
|
-
for (const filter of filters) filter.resources.uCohubState = source;
|
|
69012
|
-
return state.steps < wanted;
|
|
69566
|
+
return stepped.behind;
|
|
69567
|
+
},
|
|
69568
|
+
rewind() {
|
|
69569
|
+
if (state) state.steps = -1;
|
|
69013
69570
|
},
|
|
69014
|
-
setSurfaces(texture, region) {
|
|
69015
|
-
|
|
69016
|
-
|
|
69017
|
-
if (state) state.simulate.shader
|
|
69018
|
-
for (const target of
|
|
69571
|
+
setSurfaces(texture, region, key = "") {
|
|
69572
|
+
surfaceKey = key;
|
|
69573
|
+
const shaders = [...meshes.flatMap(({ shader, placement }) => placement ? [shader, placement.mesh.shader] : [shader]), ...filters.map(({ filter }) => filter)];
|
|
69574
|
+
if (state) shaders.push(state.simulate.shader);
|
|
69575
|
+
for (const target of shaders) target.resources.uCohubSurfaces = texture.source;
|
|
69576
|
+
const groups = [group, ...meshes.flatMap(({ placement }) => placement ? [placement.uniforms] : [])];
|
|
69577
|
+
if (state) groups.push(state.uniforms);
|
|
69578
|
+
for (const target of groups) {
|
|
69019
69579
|
setUniform(target, "uCohubSurfaceRegion", [
|
|
69020
69580
|
region.x,
|
|
69021
69581
|
region.y,
|
|
@@ -69024,17 +69584,26 @@ function createBoardShaderLayer(renderer, shader, parameters, label) {
|
|
|
69024
69584
|
]);
|
|
69025
69585
|
target.update();
|
|
69026
69586
|
}
|
|
69587
|
+
placementsStale = true;
|
|
69027
69588
|
},
|
|
69028
69589
|
destroy() {
|
|
69029
|
-
for (const
|
|
69030
|
-
|
|
69031
|
-
|
|
69590
|
+
for (const compile of compiles) compile.cancel();
|
|
69591
|
+
for (const drawn of meshes) {
|
|
69592
|
+
drawn.scaler?.destroy();
|
|
69593
|
+
destroyBoardShaderMesh(drawn);
|
|
69594
|
+
if (drawn.placement) destroyPlacement(renderer, drawn.placement);
|
|
69595
|
+
}
|
|
69596
|
+
containers.below?.destroy();
|
|
69597
|
+
containers.above?.destroy();
|
|
69598
|
+
for (const { filter } of filters) filter.destroy();
|
|
69032
69599
|
blank.destroy();
|
|
69033
69600
|
if (state) {
|
|
69034
69601
|
destroyBoardShaderMesh(state.simulate);
|
|
69035
69602
|
state.read.destroy(true);
|
|
69036
69603
|
state.write.destroy(true);
|
|
69037
69604
|
}
|
|
69605
|
+
for (const { texture } of checkpoints) texture.destroy(true);
|
|
69606
|
+
copier.destroy();
|
|
69038
69607
|
}
|
|
69039
69608
|
};
|
|
69040
69609
|
}
|
|
@@ -69260,35 +69829,53 @@ const SKIPPED = /* @__PURE__ */ new Set([
|
|
|
69260
69829
|
"frame",
|
|
69261
69830
|
"arrow",
|
|
69262
69831
|
"draw",
|
|
69263
|
-
"effect"
|
|
69832
|
+
"effect",
|
|
69833
|
+
"text"
|
|
69264
69834
|
]);
|
|
69835
|
+
const LIGHT_BLENDS = /* @__PURE__ */ new Set(["screen", "add"]);
|
|
69265
69836
|
const SURFACE_EDGE = 512;
|
|
69837
|
+
const SURFACE_MARGIN = .25;
|
|
69838
|
+
const SURFACE_COARSEN = 1.5;
|
|
69839
|
+
const SURFACE_INTERVAL_MS = 1e3 / 30;
|
|
69840
|
+
function grow(rect, margin) {
|
|
69841
|
+
return {
|
|
69842
|
+
x: rect.x - rect.width * margin,
|
|
69843
|
+
y: rect.y - rect.height * margin,
|
|
69844
|
+
width: rect.width * (1 + 2 * margin),
|
|
69845
|
+
height: rect.height * (1 + 2 * margin)
|
|
69846
|
+
};
|
|
69847
|
+
}
|
|
69848
|
+
function surfaceOutline(item) {
|
|
69849
|
+
const { width, height } = item.frame;
|
|
69850
|
+
const radius = item.style?.radius;
|
|
69851
|
+
if (item.type === "shape") {
|
|
69852
|
+
const { geometry } = item.props;
|
|
69853
|
+
return shapeOutlinePoints(geometry, width, height, radius ?? (geometry === "rounded" ? 8 : 0));
|
|
69854
|
+
}
|
|
69855
|
+
return roundRectPoints(width, height, radius ?? 0);
|
|
69856
|
+
}
|
|
69266
69857
|
function boardSurfaceOutlines(scene, owner, world, worldToLocal, candidates) {
|
|
69267
69858
|
const prefix = scriptTemporaryPrefix(owner);
|
|
69268
69859
|
const outlines = [];
|
|
69269
69860
|
const items = candidates ? [...candidates].map((id) => scene.get(id)).filter((item) => Boolean(item)) : scene.items;
|
|
69270
69861
|
for (const item of items) {
|
|
69271
|
-
if (item.id === owner || SKIPPED.has(item.type) || item.id.startsWith(prefix) || scene.opacity(item.id) <= 0) continue;
|
|
69862
|
+
if (item.id === owner || SKIPPED.has(item.type) || LIGHT_BLENDS.has(item.style?.blend ?? "") || item.id.startsWith(prefix) || scene.opacity(item.id) <= 0) continue;
|
|
69272
69863
|
if (!rectsIntersect(itemBounds(item.frame), world)) continue;
|
|
69273
|
-
const
|
|
69864
|
+
const { width, height } = item.frame;
|
|
69274
69865
|
const points = [];
|
|
69275
|
-
|
|
69276
|
-
const
|
|
69277
|
-
return [.5 + Math.cos(angle) / 2, .5 + Math.sin(angle) / 2];
|
|
69278
|
-
}) : [
|
|
69279
|
-
[0, 0],
|
|
69280
|
-
[1, 0],
|
|
69281
|
-
[1, 1],
|
|
69282
|
-
[0, 1]
|
|
69283
|
-
];
|
|
69284
|
-
for (const [u, v] of corners) {
|
|
69285
|
-
const local = applyMatrix$1(worldToLocal, framePoint(item.frame, u, v));
|
|
69866
|
+
for (const point of surfaceOutline(item)) {
|
|
69867
|
+
const local = applyMatrix$1(worldToLocal, framePoint(item.frame, width ? point.x / width : 0, height ? point.y / height : 0));
|
|
69286
69868
|
points.push(local.x, local.y);
|
|
69287
69869
|
}
|
|
69288
69870
|
outlines.push(points);
|
|
69289
69871
|
}
|
|
69290
69872
|
return outlines;
|
|
69291
69873
|
}
|
|
69874
|
+
function boardSurfaceRegion(previous, needed, margin) {
|
|
69875
|
+
const grown = grow(needed, margin);
|
|
69876
|
+
if (previous && previous.x <= needed.x && previous.y <= needed.y && previous.x + previous.width >= needed.x + needed.width && previous.y + previous.height >= needed.y + needed.height && previous.width <= grown.width * SURFACE_COARSEN && previous.height <= grown.height * SURFACE_COARSEN) return previous;
|
|
69877
|
+
return grown;
|
|
69878
|
+
}
|
|
69292
69879
|
function parameterValues(parameters, params, color) {
|
|
69293
69880
|
const values = {};
|
|
69294
69881
|
for (const [name, spec] of Object.entries(parameters ?? {})) {
|
|
@@ -69299,18 +69886,26 @@ function parameterValues(parameters, params, color) {
|
|
|
69299
69886
|
}
|
|
69300
69887
|
return values;
|
|
69301
69888
|
}
|
|
69302
|
-
function sameOutlines(a, b) {
|
|
69889
|
+
function sameOutlines(a, b, tolerance) {
|
|
69303
69890
|
if (a.length !== b.length) return false;
|
|
69304
69891
|
for (let index = 0; index < a.length; index++) {
|
|
69305
69892
|
const left = a[index];
|
|
69306
69893
|
const right = b[index];
|
|
69307
69894
|
if (left.length !== right.length) return false;
|
|
69308
|
-
for (let point = 0; point < left.length; point++) if (Math.abs(left[point] - right[point]) >
|
|
69895
|
+
for (let point = 0; point < left.length; point++) if (Math.abs(left[point] - right[point]) > tolerance) return false;
|
|
69309
69896
|
}
|
|
69310
69897
|
return true;
|
|
69311
69898
|
}
|
|
69312
|
-
function
|
|
69899
|
+
function outlineHash(outlines) {
|
|
69900
|
+
let hash = 2166136261;
|
|
69901
|
+
for (const outline of outlines) for (const value of outline) hash = Math.imul(hash ^ Math.round(value * 8), 16777619) >>> 0;
|
|
69902
|
+
return `${outlines.length}.${hash.toString(36)}`;
|
|
69903
|
+
}
|
|
69904
|
+
function createBoardShaderLayers(options = {}) {
|
|
69905
|
+
const now = options.now ?? (() => performance.now());
|
|
69906
|
+
const interval = options.wait ? 0 : SURFACE_INTERVAL_MS;
|
|
69313
69907
|
const entries = /* @__PURE__ */ new Map();
|
|
69908
|
+
const compiling = /* @__PURE__ */ new Map();
|
|
69314
69909
|
const failed = /* @__PURE__ */ new Map();
|
|
69315
69910
|
let animated = false;
|
|
69316
69911
|
let pending = false;
|
|
@@ -69322,13 +69917,71 @@ function createBoardShaderLayers() {
|
|
|
69322
69917
|
entry.layer.destroy();
|
|
69323
69918
|
entry.surfaces?.destroy();
|
|
69324
69919
|
}
|
|
69920
|
+
function dropCompiling(id) {
|
|
69921
|
+
compiling.get(id)?.layer.destroy();
|
|
69922
|
+
compiling.delete(id);
|
|
69923
|
+
}
|
|
69924
|
+
function surfaceField(entry, renderer, owner, placement, host, scene, candidates) {
|
|
69925
|
+
const { localToWorld } = placement;
|
|
69926
|
+
const region = owner.root ? boardSurfaceRegion(entry.surfaces?.region ?? null, placement.region, SURFACE_MARGIN) : placement.region;
|
|
69927
|
+
const corners = [
|
|
69928
|
+
applyMatrix$1(localToWorld, region),
|
|
69929
|
+
applyMatrix$1(localToWorld, {
|
|
69930
|
+
x: region.x + region.width,
|
|
69931
|
+
y: region.y + region.height
|
|
69932
|
+
}),
|
|
69933
|
+
applyMatrix$1(localToWorld, {
|
|
69934
|
+
x: region.x + region.width,
|
|
69935
|
+
y: region.y
|
|
69936
|
+
}),
|
|
69937
|
+
applyMatrix$1(localToWorld, {
|
|
69938
|
+
x: region.x,
|
|
69939
|
+
y: region.y + region.height
|
|
69940
|
+
})
|
|
69941
|
+
];
|
|
69942
|
+
const xs = corners.map((point) => point.x);
|
|
69943
|
+
const ys = corners.map((point) => point.y);
|
|
69944
|
+
const world = {
|
|
69945
|
+
x: Math.min(...xs),
|
|
69946
|
+
y: Math.min(...ys),
|
|
69947
|
+
width: Math.max(...xs) - Math.min(...xs),
|
|
69948
|
+
height: Math.max(...ys) - Math.min(...ys)
|
|
69949
|
+
};
|
|
69950
|
+
const edge = Math.max(64, Math.round(SURFACE_EDGE * (owner.root ? 1.5 : 1) * host.quality));
|
|
69951
|
+
const key = `${[
|
|
69952
|
+
region.x,
|
|
69953
|
+
region.y,
|
|
69954
|
+
region.width,
|
|
69955
|
+
region.height,
|
|
69956
|
+
...localToWorld
|
|
69957
|
+
].map((n) => n.toFixed(3)).join(",")}|${edge}`;
|
|
69958
|
+
entry.surfaces ??= createBoardSurfaceField();
|
|
69959
|
+
const moved = key !== entry.surfaceKey;
|
|
69960
|
+
const at = now();
|
|
69961
|
+
if (moved || entry.surfaceScene !== scene && at - entry.surfaceAt >= interval) {
|
|
69962
|
+
entry.surfaceScene = scene;
|
|
69963
|
+
const outlines = boardSurfaceOutlines(scene, owner.id, world, invertMatrix(localToWorld), candidates?.(world));
|
|
69964
|
+
if (moved || !sameOutlines(outlines, entry.outlines, region.width / edge / 2)) {
|
|
69965
|
+
entry.surfaces.build(renderer, region, outlines, edge);
|
|
69966
|
+
entry.outlines = outlines;
|
|
69967
|
+
entry.surfaceAt = at;
|
|
69968
|
+
entry.surfaceSignature = `${key}|${outlineHash(outlines)}`;
|
|
69969
|
+
}
|
|
69970
|
+
entry.surfaceKey = key;
|
|
69971
|
+
} else if (entry.surfaceScene !== scene) pending = true;
|
|
69972
|
+
entry.layer.setSurfaces(entry.surfaces.texture, entry.surfaces.region, entry.surfaceSignature);
|
|
69973
|
+
}
|
|
69325
69974
|
return {
|
|
69326
69975
|
get animated() {
|
|
69327
69976
|
return animated || pending;
|
|
69328
69977
|
},
|
|
69329
69978
|
get size() {
|
|
69330
|
-
return entries.size;
|
|
69979
|
+
return entries.size + compiling.size;
|
|
69331
69980
|
},
|
|
69981
|
+
get compiling() {
|
|
69982
|
+
return compiling.size > 0;
|
|
69983
|
+
},
|
|
69984
|
+
layer: (id) => entries.get(id)?.layer ?? null,
|
|
69332
69985
|
sync(renderer, owners, host, scene, candidates) {
|
|
69333
69986
|
const alive = /* @__PURE__ */ new Set();
|
|
69334
69987
|
animated = false;
|
|
@@ -69339,31 +69992,44 @@ function createBoardShaderLayers() {
|
|
|
69339
69992
|
if (!shader || !signature || failed.get(owner.id) === signature) continue;
|
|
69340
69993
|
alive.add(owner.id);
|
|
69341
69994
|
let entry = entries.get(owner.id);
|
|
69342
|
-
if (entry && entry.signature !== signature) {
|
|
69343
|
-
drop(owner.id, host);
|
|
69344
|
-
entry = void 0;
|
|
69345
|
-
}
|
|
69346
69995
|
try {
|
|
69347
|
-
if (
|
|
69348
|
-
|
|
69349
|
-
|
|
69350
|
-
|
|
69351
|
-
|
|
69352
|
-
|
|
69353
|
-
|
|
69354
|
-
|
|
69355
|
-
|
|
69356
|
-
|
|
69357
|
-
|
|
69358
|
-
|
|
69359
|
-
|
|
69996
|
+
if (entry?.signature !== signature) {
|
|
69997
|
+
let next = compiling.get(owner.id);
|
|
69998
|
+
if (next?.signature !== signature) {
|
|
69999
|
+
dropCompiling(owner.id);
|
|
70000
|
+
next = {
|
|
70001
|
+
signature,
|
|
70002
|
+
layer: createBoardShaderLayer(renderer, shader, boardShaderParameters(output.parameters), owner.id, { wait: options.wait })
|
|
70003
|
+
};
|
|
70004
|
+
compiling.set(owner.id, next);
|
|
70005
|
+
}
|
|
70006
|
+
if (next.layer.ready()) {
|
|
70007
|
+
compiling.delete(owner.id);
|
|
70008
|
+
drop(owner.id, host);
|
|
70009
|
+
entry = {
|
|
70010
|
+
owner,
|
|
70011
|
+
output,
|
|
70012
|
+
signature,
|
|
70013
|
+
layer: next.layer,
|
|
70014
|
+
surfaces: null,
|
|
70015
|
+
surfaceKey: "",
|
|
70016
|
+
surfaceScene: null,
|
|
70017
|
+
surfaceAt: -Infinity,
|
|
70018
|
+
surfaceSignature: "",
|
|
70019
|
+
outlines: [],
|
|
70020
|
+
placed: false
|
|
70021
|
+
};
|
|
70022
|
+
entries.set(owner.id, entry);
|
|
70023
|
+
}
|
|
69360
70024
|
}
|
|
70025
|
+
if (!entry) continue;
|
|
69361
70026
|
entry.owner = owner;
|
|
69362
|
-
entry.output = output;
|
|
70027
|
+
if (entry.signature === signature) entry.output = output;
|
|
70028
|
+
const drawn = entry.output;
|
|
69363
70029
|
const placement = host.attach(owner, entry.layer);
|
|
69364
70030
|
entry.placed = placement !== null;
|
|
69365
70031
|
if (!placement) continue;
|
|
69366
|
-
animated ||=
|
|
70032
|
+
animated ||= drawn.animated || entry.layer.animated;
|
|
69367
70033
|
entry.layer.update({
|
|
69368
70034
|
time: owner.time,
|
|
69369
70035
|
region: placement.region,
|
|
@@ -69373,75 +70039,42 @@ function createBoardShaderLayers() {
|
|
|
69373
70039
|
density: host.density,
|
|
69374
70040
|
seed: boardShaderSeed(owner.seed),
|
|
69375
70041
|
quality: host.quality,
|
|
70042
|
+
shading: host.shading,
|
|
69376
70043
|
dark: host.dark,
|
|
69377
|
-
params: parameterValues(
|
|
69378
|
-
uniforms:
|
|
70044
|
+
params: parameterValues(drawn.parameters, owner.params, host.color),
|
|
70045
|
+
uniforms: drawn.uniforms,
|
|
70046
|
+
passes: drawn.passes
|
|
69379
70047
|
});
|
|
69380
|
-
if (entry.layer.surfaces)
|
|
69381
|
-
const { region, localToWorld } = placement;
|
|
69382
|
-
const corners = [
|
|
69383
|
-
applyMatrix$1(localToWorld, region),
|
|
69384
|
-
applyMatrix$1(localToWorld, {
|
|
69385
|
-
x: region.x + region.width,
|
|
69386
|
-
y: region.y + region.height
|
|
69387
|
-
}),
|
|
69388
|
-
applyMatrix$1(localToWorld, {
|
|
69389
|
-
x: region.x + region.width,
|
|
69390
|
-
y: region.y
|
|
69391
|
-
}),
|
|
69392
|
-
applyMatrix$1(localToWorld, {
|
|
69393
|
-
x: region.x,
|
|
69394
|
-
y: region.y + region.height
|
|
69395
|
-
})
|
|
69396
|
-
];
|
|
69397
|
-
const xs = corners.map((point) => point.x);
|
|
69398
|
-
const ys = corners.map((point) => point.y);
|
|
69399
|
-
const world = {
|
|
69400
|
-
x: Math.min(...xs),
|
|
69401
|
-
y: Math.min(...ys),
|
|
69402
|
-
width: Math.max(...xs) - Math.min(...xs),
|
|
69403
|
-
height: Math.max(...ys) - Math.min(...ys)
|
|
69404
|
-
};
|
|
69405
|
-
const edge = Math.max(64, Math.round(SURFACE_EDGE * host.quality));
|
|
69406
|
-
const key = `${[
|
|
69407
|
-
region.x,
|
|
69408
|
-
region.y,
|
|
69409
|
-
region.width,
|
|
69410
|
-
region.height,
|
|
69411
|
-
...localToWorld
|
|
69412
|
-
].map((n) => n.toFixed(3)).join(",")}|${edge}`;
|
|
69413
|
-
entry.surfaces ??= createBoardSurfaceField();
|
|
69414
|
-
if (key !== entry.surfaceKey || entry.surfaceScene !== scene) {
|
|
69415
|
-
entry.surfaceScene = scene;
|
|
69416
|
-
const outlines = boardSurfaceOutlines(scene, owner.id, world, invertMatrix(localToWorld), candidates?.(world));
|
|
69417
|
-
if (key !== entry.surfaceKey || !sameOutlines(outlines, entry.outlines)) entry.surfaces.build(renderer, region, outlines, edge);
|
|
69418
|
-
entry.surfaceKey = key;
|
|
69419
|
-
entry.outlines = outlines;
|
|
69420
|
-
}
|
|
69421
|
-
entry.layer.setSurfaces(entry.surfaces.texture, entry.surfaces.region);
|
|
69422
|
-
}
|
|
70048
|
+
if (entry.layer.surfaces) surfaceField(entry, renderer, owner, placement, host, scene, candidates);
|
|
69423
70049
|
} catch (error) {
|
|
69424
70050
|
host.attach(owner, null);
|
|
69425
70051
|
drop(owner.id, host);
|
|
70052
|
+
dropCompiling(owner.id);
|
|
69426
70053
|
failed.set(owner.id, signature);
|
|
69427
70054
|
host.fault(owner.id, error instanceof Error ? error.message : String(error));
|
|
69428
70055
|
}
|
|
69429
70056
|
}
|
|
69430
70057
|
for (const id of [...entries.keys()]) if (!alive.has(id)) drop(id, host);
|
|
70058
|
+
for (const id of [...compiling.keys()]) if (!alive.has(id)) dropCompiling(id);
|
|
69431
70059
|
for (const id of [...failed.keys()]) if (!owners.some((owner) => owner.id === id)) failed.delete(id);
|
|
69432
70060
|
},
|
|
69433
70061
|
prepare(renderer, catchUp = false) {
|
|
69434
70062
|
pending = false;
|
|
69435
70063
|
for (const entry of entries.values()) if (entry.placed && entry.layer.prepare(renderer, { catchUp })) pending = true;
|
|
69436
70064
|
},
|
|
70065
|
+
rewind() {
|
|
70066
|
+
for (const entry of entries.values()) entry.layer.rewind();
|
|
70067
|
+
},
|
|
69437
70068
|
detach() {
|
|
69438
70069
|
for (const entry of entries.values()) {
|
|
69439
|
-
entry.layer.
|
|
70070
|
+
entry.layer.below?.removeFromParent();
|
|
70071
|
+
entry.layer.above?.removeFromParent();
|
|
69440
70072
|
entry.placed = false;
|
|
69441
70073
|
}
|
|
69442
70074
|
},
|
|
69443
70075
|
destroy() {
|
|
69444
70076
|
for (const id of [...entries.keys()]) drop(id);
|
|
70077
|
+
for (const id of [...compiling.keys()]) dropCompiling(id);
|
|
69445
70078
|
failed.clear();
|
|
69446
70079
|
}
|
|
69447
70080
|
};
|
|
@@ -69467,6 +70100,7 @@ function createBrowserBoardScriptExport(readModule, options = {}) {
|
|
|
69467
70100
|
shaders: options.shaders ?? true,
|
|
69468
70101
|
snapshots: options.snapshots,
|
|
69469
70102
|
timeoutMs: 15e3,
|
|
70103
|
+
capabilities: Object.fromEntries(Object.entries(BOARD_SCRIPT_EXPORT_CALLS).map(([name, call]) => [name, async (_id, input) => call(input)])),
|
|
69470
70104
|
onFrame: () => started.wake(),
|
|
69471
70105
|
onOutput(id, output) {
|
|
69472
70106
|
if (output) outputs.set(id, output);
|
|
@@ -69483,49 +70117,78 @@ function createBrowserBoardScriptExport(readModule, options = {}) {
|
|
|
69483
70117
|
run.element.remove();
|
|
69484
70118
|
run = null;
|
|
69485
70119
|
}
|
|
70120
|
+
function settle(current, document, time) {
|
|
70121
|
+
current.time = time;
|
|
70122
|
+
const { host } = current;
|
|
70123
|
+
const scene = buildBoardScene(document);
|
|
70124
|
+
const ids = boardScriptAttachments(document).map(({ id }) => id);
|
|
70125
|
+
return new Promise((resolve, reject) => {
|
|
70126
|
+
const finish = (error) => {
|
|
70127
|
+
clearTimeout(timer);
|
|
70128
|
+
current.wake = () => {};
|
|
70129
|
+
if (error) reject(error);
|
|
70130
|
+
else resolve();
|
|
70131
|
+
};
|
|
70132
|
+
const timer = setTimeout(() => finish(/* @__PURE__ */ new Error("Script export preparation timed out.")), 2e4);
|
|
70133
|
+
let queued = false;
|
|
70134
|
+
const sync = () => {
|
|
70135
|
+
queued = false;
|
|
70136
|
+
try {
|
|
70137
|
+
host.sync(document, scene, {
|
|
70138
|
+
x: 0,
|
|
70139
|
+
y: 0,
|
|
70140
|
+
zoom: 1
|
|
70141
|
+
}, time, false);
|
|
70142
|
+
for (const id of ids) {
|
|
70143
|
+
const error = host.error(id);
|
|
70144
|
+
if (error) throw new Error(error);
|
|
70145
|
+
}
|
|
70146
|
+
if (ids.every((id) => host.settled(id))) finish();
|
|
70147
|
+
} catch (error) {
|
|
70148
|
+
finish(error);
|
|
70149
|
+
}
|
|
70150
|
+
};
|
|
70151
|
+
current.wake = () => {
|
|
70152
|
+
if (queued) return;
|
|
70153
|
+
queued = true;
|
|
70154
|
+
queueMicrotask(sync);
|
|
70155
|
+
};
|
|
70156
|
+
current.wake();
|
|
70157
|
+
});
|
|
70158
|
+
}
|
|
69486
70159
|
return {
|
|
69487
70160
|
async at(document, time) {
|
|
69488
70161
|
if (!Number.isFinite(time) || time < 0 || time > 6e5) throw new Error("Script export time must be between 0 and 600000 ms.");
|
|
69489
70162
|
if (run && time < run.time) stop();
|
|
70163
|
+
const fresh = !run;
|
|
69490
70164
|
const current = run ?? start();
|
|
69491
70165
|
run = current;
|
|
69492
|
-
current.time = time;
|
|
69493
70166
|
const { host, outputs } = current;
|
|
69494
|
-
|
|
69495
|
-
|
|
69496
|
-
|
|
69497
|
-
|
|
69498
|
-
clearTimeout(timer);
|
|
69499
|
-
current.wake = () => {};
|
|
69500
|
-
if (error) reject(error);
|
|
69501
|
-
else resolve();
|
|
70167
|
+
if (options.documentAt) {
|
|
70168
|
+
let before = {
|
|
70169
|
+
at: current.time,
|
|
70170
|
+
document: options.documentAt(current.time)
|
|
69502
70171
|
};
|
|
69503
|
-
|
|
69504
|
-
let
|
|
69505
|
-
|
|
69506
|
-
|
|
69507
|
-
|
|
69508
|
-
|
|
69509
|
-
|
|
69510
|
-
|
|
69511
|
-
|
|
69512
|
-
|
|
69513
|
-
|
|
69514
|
-
const error = host.error(id);
|
|
69515
|
-
if (error) throw new Error(error);
|
|
69516
|
-
}
|
|
69517
|
-
if (ids.every((id) => host.settled(id))) finish();
|
|
69518
|
-
} catch (error) {
|
|
69519
|
-
finish(error);
|
|
70172
|
+
let previous = boardScriptParamsKey(before.document);
|
|
70173
|
+
let ran = current.time;
|
|
70174
|
+
if (fresh) await settle(current, before.document, before.at);
|
|
70175
|
+
for (let at = current.time + BOARD_SCRIPT_HISTORY_MS; at < time; at += BOARD_SCRIPT_HISTORY_MS) {
|
|
70176
|
+
const sample = options.documentAt(at);
|
|
70177
|
+
const key = boardScriptParamsKey(sample);
|
|
70178
|
+
if (key !== previous) {
|
|
70179
|
+
if (before.at > ran) await settle(current, before.document, before.at);
|
|
70180
|
+
await settle(current, sample, at);
|
|
70181
|
+
previous = key;
|
|
70182
|
+
ran = at;
|
|
69520
70183
|
}
|
|
69521
|
-
|
|
69522
|
-
|
|
69523
|
-
|
|
69524
|
-
|
|
69525
|
-
|
|
69526
|
-
|
|
69527
|
-
|
|
69528
|
-
|
|
70184
|
+
before = {
|
|
70185
|
+
at,
|
|
70186
|
+
document: sample
|
|
70187
|
+
};
|
|
70188
|
+
}
|
|
70189
|
+
if (boardScriptParamsKey(document) !== previous && before.at > ran) await settle(current, before.document, before.at);
|
|
70190
|
+
}
|
|
70191
|
+
await settle(current, document, time);
|
|
69529
70192
|
return {
|
|
69530
70193
|
...host,
|
|
69531
70194
|
shaders: (input) => boardShaderOwners(input, outputs, (id) => host.clock(id)),
|
|
@@ -69786,7 +70449,7 @@ function createBoardExportScene(input) {
|
|
|
69786
70449
|
}
|
|
69787
70450
|
root.addChild(world);
|
|
69788
70451
|
const shaderErrors = [];
|
|
69789
|
-
const layers = input.shaders?.owners.length ? input.shaders.layers ?? createBoardShaderLayers() : null;
|
|
70452
|
+
const layers = input.shaders?.owners.length ? input.shaders.layers ?? createBoardShaderLayers({ wait: true }) : null;
|
|
69790
70453
|
if (layers && input.shaders) {
|
|
69791
70454
|
const toOutput = [
|
|
69792
70455
|
input.scale,
|
|
@@ -69808,10 +70471,12 @@ function createBoardExportScene(input) {
|
|
|
69808
70471
|
const attach = (owner, layer) => {
|
|
69809
70472
|
if (!layer) return null;
|
|
69810
70473
|
if (owner.root) {
|
|
69811
|
-
if (layer.
|
|
70474
|
+
if (layer.below) below.addChild(layer.below);
|
|
70475
|
+
if (layer.above) above.addChild(layer.above);
|
|
69812
70476
|
if (layer.filters) {
|
|
69813
70477
|
filters.set(owner.id, layer.filters);
|
|
69814
70478
|
setBoardShaderFilters(world, [...filters.values()].flat());
|
|
70479
|
+
world.filterArea = new Rectangle(input.world.x, input.world.y, input.world.width, input.world.height);
|
|
69815
70480
|
}
|
|
69816
70481
|
return {
|
|
69817
70482
|
region: input.world,
|
|
@@ -69831,15 +70496,25 @@ function createBoardExportScene(input) {
|
|
|
69831
70496
|
const container = containers.get(owner.id);
|
|
69832
70497
|
if (!item || !container) return null;
|
|
69833
70498
|
const group = isSelfGroupedFrame(item) ? groups.get(item.id)?.group : void 0;
|
|
69834
|
-
if (layer.
|
|
69835
|
-
if (layer.
|
|
70499
|
+
if (layer.below) container.addChildAt(layer.below, 0);
|
|
70500
|
+
if (layer.above) {
|
|
69836
70501
|
if (group) {
|
|
69837
|
-
positionShell(layer.
|
|
69838
|
-
layer.
|
|
70502
|
+
positionShell(layer.above, item);
|
|
70503
|
+
layer.above.zIndex = Number.MAX_SAFE_INTEGER;
|
|
69839
70504
|
}
|
|
69840
|
-
(group ?? container).addChild(layer.
|
|
70505
|
+
(group ?? container).addChild(layer.above);
|
|
70506
|
+
}
|
|
70507
|
+
if (layer.filters) {
|
|
70508
|
+
const host = group ?? container;
|
|
70509
|
+
setBoardShaderFilters(host, layer.filters);
|
|
70510
|
+
const box = group ? itemBounds(item.frame) : {
|
|
70511
|
+
x: 0,
|
|
70512
|
+
y: 0,
|
|
70513
|
+
width: item.frame.width,
|
|
70514
|
+
height: item.frame.height
|
|
70515
|
+
};
|
|
70516
|
+
host.filterArea = new Rectangle(box.x, box.y, box.width, box.height);
|
|
69841
70517
|
}
|
|
69842
|
-
if (layer.filters) setBoardShaderFilters(group ?? container, layer.filters);
|
|
69843
70518
|
const localToWorld = boardItemLocalToWorld(item.frame);
|
|
69844
70519
|
return {
|
|
69845
70520
|
region: {
|
|
@@ -70046,9 +70721,9 @@ async function fetchTexture(query) {
|
|
|
70046
70721
|
const bitmap = await createImageBitmap(await response.blob(), { premultiplyAlpha: "premultiply" });
|
|
70047
70722
|
return new Texture({ source: new ImageSource({ resource: bitmap }) });
|
|
70048
70723
|
}
|
|
70049
|
-
async function loadTextures(items, scale, maxBytes) {
|
|
70724
|
+
async function loadTextures(items, scale, maxBytes, overrides) {
|
|
70050
70725
|
const exportKey = (item) => {
|
|
70051
|
-
const key = boardAssetKey(item);
|
|
70726
|
+
const key = overrides[item.id] ?? boardAssetKey(item);
|
|
70052
70727
|
return key && boardAssetKeySource(key)?.media !== "model" ? key : null;
|
|
70053
70728
|
};
|
|
70054
70729
|
const selection = selectBoardExportAssets([...items], exportKey, {
|
|
@@ -70101,7 +70776,7 @@ globalThis.cohubBoardGpu = {
|
|
|
70101
70776
|
const target = await ensureRenderer();
|
|
70102
70777
|
const errors = {};
|
|
70103
70778
|
for (const { id, shader, parameters } of shaders) try {
|
|
70104
|
-
createBoardShaderLayer(target, shader, boardShaderParameters(parameters), id).destroy();
|
|
70779
|
+
createBoardShaderLayer(target, shader, boardShaderParameters(parameters), id, { wait: true }).destroy();
|
|
70105
70780
|
} catch (error) {
|
|
70106
70781
|
errors[id] = error instanceof Error ? error.message : String(error);
|
|
70107
70782
|
}
|
|
@@ -70112,22 +70787,151 @@ globalThis.cohubBoardGpu = {
|
|
|
70112
70787
|
await document.fonts.ready;
|
|
70113
70788
|
const board = normalizeBoardDocument(init.document);
|
|
70114
70789
|
session?.scripts.dispose();
|
|
70115
|
-
session?.layers
|
|
70790
|
+
const layers = session?.layers ?? createBoardShaderLayers({ wait: true });
|
|
70791
|
+
layers.rewind();
|
|
70792
|
+
for (const [key, entry] of textures) if (!/^([a-z]+-)?url:/.test(key)) {
|
|
70793
|
+
entry?.texture.destroy(true);
|
|
70794
|
+
textures.delete(key);
|
|
70795
|
+
}
|
|
70796
|
+
background?.destroy(true);
|
|
70797
|
+
background = void 0;
|
|
70798
|
+
const sampler = createBoardRenderSampler(board, init.animation, boardRenderTheme(init.theme));
|
|
70116
70799
|
session = {
|
|
70117
70800
|
init: {
|
|
70118
70801
|
...init,
|
|
70119
70802
|
document: board
|
|
70120
70803
|
},
|
|
70121
|
-
sampler
|
|
70804
|
+
sampler,
|
|
70122
70805
|
scripts: createBrowserBoardScriptExport(async (path) => {
|
|
70123
70806
|
const response = await fetch(`module?path=${encodeURIComponent(path)}`);
|
|
70124
70807
|
if (!response.ok) throw new Error(`${path} is not available.`);
|
|
70125
70808
|
return response.text();
|
|
70809
|
+
}, {
|
|
70810
|
+
...init.snapshots ? { snapshots: init.snapshots } : {},
|
|
70811
|
+
...init.animation && boardAnimatesScriptParams(board) ? { documentAt: (time) => sampler.at(time).document } : {}
|
|
70126
70812
|
}),
|
|
70127
|
-
layers
|
|
70813
|
+
layers
|
|
70128
70814
|
};
|
|
70129
70815
|
return { renderer: renderer.name };
|
|
70130
70816
|
},
|
|
70817
|
+
async profile(input) {
|
|
70818
|
+
if (!renderer || !session) throw new Error("The GPU exporter is not ready.");
|
|
70819
|
+
const target = renderer;
|
|
70820
|
+
const { document, animation, theme: themeId } = session.init;
|
|
70821
|
+
const theme = boardRenderTheme(themeId);
|
|
70822
|
+
const at = input.time === null ? void 0 : {
|
|
70823
|
+
animation: animation ?? void 0,
|
|
70824
|
+
time: input.time
|
|
70825
|
+
};
|
|
70826
|
+
const time = input.time ?? 0;
|
|
70827
|
+
const scripts = await session.scripts.at(at ? session.sampler.at(time).document : document, time);
|
|
70828
|
+
const prepared = prepareBoardExport(document, {
|
|
70829
|
+
sampler: session.sampler,
|
|
70830
|
+
region: input.region,
|
|
70831
|
+
camera: input.camera,
|
|
70832
|
+
scale: input.scale,
|
|
70833
|
+
...at ? { at } : {},
|
|
70834
|
+
scripts
|
|
70835
|
+
});
|
|
70836
|
+
if (!prepared) throw new Error("Nothing to profile: the region contains no items.");
|
|
70837
|
+
const visible = prepared.plan.items.filter((item) => prepared.scene.opacity(item.id) > 0);
|
|
70838
|
+
const loaded = input.withImages ? await loadTextures(visible, prepared.plan.scale, input.imageMemory, {}) : /* @__PURE__ */ new Map();
|
|
70839
|
+
const owners = scripts.shaders?.(prepared.document, time) ?? [];
|
|
70840
|
+
const layers = createBoardShaderLayers({ wait: true });
|
|
70841
|
+
const scene = createBoardExportScene({
|
|
70842
|
+
settings: prepared.document.board,
|
|
70843
|
+
scene: prepared.scene,
|
|
70844
|
+
items: prepared.plan.items,
|
|
70845
|
+
time,
|
|
70846
|
+
frameAt: session.sampler.frameAt,
|
|
70847
|
+
world: prepared.plan.world,
|
|
70848
|
+
scale: prepared.plan.scale,
|
|
70849
|
+
colorScheme: theme.colorScheme,
|
|
70850
|
+
palette: theme.palette,
|
|
70851
|
+
colors: theme.colors,
|
|
70852
|
+
style: theme.style,
|
|
70853
|
+
textures: loaded,
|
|
70854
|
+
scripts,
|
|
70855
|
+
assetKey: boardAssetKey,
|
|
70856
|
+
...owners.length ? { shaders: {
|
|
70857
|
+
renderer: target,
|
|
70858
|
+
owners,
|
|
70859
|
+
layers
|
|
70860
|
+
} } : {}
|
|
70861
|
+
});
|
|
70862
|
+
const { width, height } = prepared.plan;
|
|
70863
|
+
const output = RenderTexture.create({
|
|
70864
|
+
width,
|
|
70865
|
+
height
|
|
70866
|
+
});
|
|
70867
|
+
const gl = target.gl;
|
|
70868
|
+
const pixel = /* @__PURE__ */ new Uint8Array(4);
|
|
70869
|
+
const measure = () => {
|
|
70870
|
+
const samples = [];
|
|
70871
|
+
for (let frame = 0; frame < Math.max(3, input.frames); frame++) {
|
|
70872
|
+
const start = performance.now();
|
|
70873
|
+
target.render({
|
|
70874
|
+
container: scene.root,
|
|
70875
|
+
target: output,
|
|
70876
|
+
clear: true
|
|
70877
|
+
});
|
|
70878
|
+
gl.readPixels(0, 0, 1, 1, gl.RGBA, gl.UNSIGNED_BYTE, pixel);
|
|
70879
|
+
samples.push(performance.now() - start);
|
|
70880
|
+
}
|
|
70881
|
+
return samples.sort((a, b) => a - b);
|
|
70882
|
+
};
|
|
70883
|
+
try {
|
|
70884
|
+
measure();
|
|
70885
|
+
const all = measure();
|
|
70886
|
+
const median = (samples) => samples[Math.floor(samples.length / 2)] ?? 0;
|
|
70887
|
+
const base = median(all);
|
|
70888
|
+
const costs = owners.map((owner) => {
|
|
70889
|
+
const layer = layers.layer(owner.id);
|
|
70890
|
+
const shader = owner.output.shader;
|
|
70891
|
+
const parts = [layer?.below, layer?.above].filter((part) => part !== null && part !== void 0);
|
|
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
|
+
});
|
|
70904
|
+
const filterPasses = shader?.passes.filter((pass) => (pass.layer ?? shader.layer) === "filter") ?? [];
|
|
70905
|
+
return {
|
|
70906
|
+
id: owner.id,
|
|
70907
|
+
ms: Math.max(0, base - without),
|
|
70908
|
+
filter: !filterPasses.length ? "none" : filterPasses.every((pass) => pass.name) ? "switchable" : "always",
|
|
70909
|
+
sprites: shader?.passes.reduce((sum, pass) => sum + (pass.sprites ?? 0), 0) ?? 0,
|
|
70910
|
+
state: shader?.state ? {
|
|
70911
|
+
width: shader.state.width,
|
|
70912
|
+
height: shader.state.height
|
|
70913
|
+
} : null
|
|
70914
|
+
};
|
|
70915
|
+
});
|
|
70916
|
+
const info = gl.getExtension("WEBGL_debug_renderer_info");
|
|
70917
|
+
return {
|
|
70918
|
+
renderer: String(info ? gl.getParameter(info.UNMASKED_RENDERER_WEBGL) : gl.getParameter(gl.RENDERER)),
|
|
70919
|
+
width,
|
|
70920
|
+
height,
|
|
70921
|
+
frame: {
|
|
70922
|
+
p50: base,
|
|
70923
|
+
p95: all[Math.min(all.length - 1, Math.floor(all.length * .95))] ?? base
|
|
70924
|
+
},
|
|
70925
|
+
owners: costs.sort((a, b) => b.ms - a.ms),
|
|
70926
|
+
effects: visible.filter((item) => hasBoardEffects(item.style)).length,
|
|
70927
|
+
items: visible.length
|
|
70928
|
+
};
|
|
70929
|
+
} finally {
|
|
70930
|
+
output.destroy(true);
|
|
70931
|
+
scene.destroy();
|
|
70932
|
+
layers.destroy();
|
|
70933
|
+
}
|
|
70934
|
+
},
|
|
70131
70935
|
async render(frame) {
|
|
70132
70936
|
if (!renderer || !session) throw new Error("The GPU exporter is not ready.");
|
|
70133
70937
|
const { document, animation, theme: themeId } = session.init;
|
|
@@ -70151,13 +70955,15 @@ globalThis.cohubBoardGpu = {
|
|
|
70151
70955
|
const prepared = prepareBoardExport(document, options);
|
|
70152
70956
|
if (!prepared) throw new Error("Nothing to export: the region contains no items.");
|
|
70153
70957
|
const visible = prepared.plan.items.filter((item) => prepared.scene.opacity(item.id) > 0);
|
|
70154
|
-
const
|
|
70958
|
+
const overrides = frame.assetKeys ?? {};
|
|
70959
|
+
const loaded = frame.withImages ? await loadTextures(visible, prepared.plan.scale, frame.imageMemory, overrides) : /* @__PURE__ */ new Map();
|
|
70155
70960
|
if (frame.withImages && frame.background === "paper" && document.board.background.image && background === void 0) background = await fetchTexture("background=1").catch(() => null);
|
|
70156
70961
|
const result = renderBoardExport(renderer, document, {
|
|
70157
70962
|
...options,
|
|
70158
70963
|
...theme,
|
|
70159
70964
|
background: frame.background,
|
|
70160
70965
|
textures: loaded,
|
|
70966
|
+
assetKey: (item) => overrides[item.id] ?? boardAssetKey(item),
|
|
70161
70967
|
backgroundTexture: frame.background === "paper" ? background ?? void 0 : void 0,
|
|
70162
70968
|
shaderLayers: session.layers
|
|
70163
70969
|
});
|