@neta-art/cohub-cli 10.18.0 → 10.19.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 +8 -2
- package/dist/board-export.js +75 -42
- package/dist/board-gpu/page.js +339 -133
- package/dist/board-gpu/protocol.d.ts +1 -0
- package/dist/board-kernel.d.ts +1 -1
- package/dist/board-kernel.js +1113 -188
- 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/commands/boards/authoring.js +45 -3
- 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-kernel.js
CHANGED
|
@@ -5909,6 +5909,7 @@ const itemEnvelope$1 = {
|
|
|
5909
5909
|
y: .5
|
|
5910
5910
|
}).describe("Rotation and scale origin as fractions of the size."),
|
|
5911
5911
|
opacity: ratio$1.default(1),
|
|
5912
|
+
visible: boolean().optional().describe("false hides the item and its children; key it on a timeline to show the item only for a span."),
|
|
5912
5913
|
style: BoardStyleSchema$1.default({}),
|
|
5913
5914
|
locked: boolean().optional(),
|
|
5914
5915
|
metadata: record(string(), unknown()).optional()
|
|
@@ -6058,7 +6059,8 @@ const mediaProps$1 = {
|
|
|
6058
6059
|
};
|
|
6059
6060
|
const timedFileProps$1 = {
|
|
6060
6061
|
...mediaProps$1,
|
|
6061
|
-
time: nonNegative$1.optional().describe("Playback position in milliseconds; animate props.time to play it on a timeline.")
|
|
6062
|
+
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."),
|
|
6063
|
+
volume: ratio$1.optional().describe("Loudness from 0 to 1; defaults to 1. Animate it to fade.")
|
|
6062
6064
|
};
|
|
6063
6065
|
const BoardCropSchema$1 = object({
|
|
6064
6066
|
x: ratio$1,
|
|
@@ -9056,10 +9058,10 @@ const glsl = \`
|
|
|
9056
9058
|
const float SPEED = 1400.0; // screen pixels per second, at any zoom
|
|
9057
9059
|
const float SPLASH = 0.38; // seconds a splash lasts
|
|
9058
9060
|
|
|
9059
|
-
struct Drop { vec2 start; vec2 heading; float reach; float
|
|
9061
|
+
struct Drop { vec2 start; vec2 heading; float reach; float travelled; float landing; bool lands; };
|
|
9060
9062
|
|
|
9061
9063
|
// Drops respawn every cycle at new seeded places, anywhere in view.
|
|
9062
|
-
Drop drop(int index, float pixel) {
|
|
9064
|
+
Drop drop(int index, float pixel, bool streak) {
|
|
9063
9065
|
float speed = SPEED * pixel;
|
|
9064
9066
|
float cycle = board.view.w * 0.6 / speed + SPLASH;
|
|
9065
9067
|
float clock = board.time + hash(index, 7) * cycle;
|
|
@@ -9068,17 +9070,18 @@ Drop drop(int index, float pixel) {
|
|
|
9068
9070
|
d.heading = normalize(vec2(params.wind, 1.0));
|
|
9069
9071
|
d.start = board.view.xy + vec2(hash(key, 1) * 1.2 - 0.1, hash(key, 2) * 0.9 - 0.15) * board.view.zw;
|
|
9070
9072
|
d.reach = (0.25 + hash(key, 3) * 0.55) * board.view.w;
|
|
9071
|
-
d.
|
|
9073
|
+
d.travelled = mod(clock, cycle) * speed;
|
|
9072
9074
|
d.lands = false;
|
|
9073
9075
|
d.landing = d.reach;
|
|
9074
9076
|
if (surface(d.start).inside) { d.reach = 0.0; return d; }
|
|
9077
|
+
float limit = min(d.reach, streak ? d.travelled + 0.15 * d.reach : d.travelled);
|
|
9075
9078
|
// Sphere-trace the item edges along the drop's path.
|
|
9076
|
-
float
|
|
9079
|
+
float ahead = 0.0;
|
|
9077
9080
|
for (int i = 0; i < 40 && params.splash > 0.5; i++) {
|
|
9078
|
-
float gap = surface(d.start + d.heading *
|
|
9079
|
-
if (gap < pixel) { d.lands = true; d.landing =
|
|
9080
|
-
|
|
9081
|
-
if (
|
|
9081
|
+
float gap = surface(d.start + d.heading * ahead).distance;
|
|
9082
|
+
if (gap < pixel) { d.lands = true; d.landing = ahead; break; }
|
|
9083
|
+
ahead += max(gap, 2.0 * pixel);
|
|
9084
|
+
if (ahead > limit) break;
|
|
9082
9085
|
}
|
|
9083
9086
|
return d;
|
|
9084
9087
|
}
|
|
@@ -9087,15 +9090,14 @@ Sprite sprite(int id) {
|
|
|
9087
9090
|
int index = id / PARTS;
|
|
9088
9091
|
int part = id - index * PARTS;
|
|
9089
9092
|
Sprite s = makeSprite(vec2(0.0), vec2(0.0));
|
|
9090
|
-
if (hash(index, 11) > params.density) { s.visible = false; return s; }
|
|
9093
|
+
if (hash(index, 11) > params.density || (part > 0 && params.splash < 0.5)) { s.visible = false; return s; }
|
|
9091
9094
|
float pixel = 1.0 / board.zoom;
|
|
9092
9095
|
vec4 tint = board.dark > 0.5 ? vec4(0.75, 0.84, 1.0, 0.5) : vec4(0.3, 0.4, 0.55, 0.45);
|
|
9093
|
-
Drop d = drop(index, pixel);
|
|
9094
|
-
float travelled = d.age * SPEED * pixel;
|
|
9096
|
+
Drop d = drop(index, pixel, part == 0);
|
|
9095
9097
|
if (part == 0) {
|
|
9096
9098
|
float end = d.lands ? d.landing : d.reach;
|
|
9097
|
-
float head = min(travelled, end);
|
|
9098
|
-
float tail = max(0.0,
|
|
9099
|
+
float head = min(d.travelled, end);
|
|
9100
|
+
float tail = max(0.0, d.travelled - 34.0 * pixel);
|
|
9099
9101
|
s.visible = head > tail;
|
|
9100
9102
|
vec2 a = d.start + d.heading * tail;
|
|
9101
9103
|
vec2 b = d.start + d.heading * head;
|
|
@@ -9106,7 +9108,7 @@ Sprite sprite(int id) {
|
|
|
9106
9108
|
s.color = vec4(tint.rgb, tint.a * smoothstep(0.0, 0.08 * d.reach, head) * fade);
|
|
9107
9109
|
return s;
|
|
9108
9110
|
}
|
|
9109
|
-
float age = (travelled - d.landing) / (SPEED * pixel);
|
|
9111
|
+
float age = (d.travelled - d.landing) / (SPEED * pixel);
|
|
9110
9112
|
if (!d.lands || age < 0.0 || age > SPLASH) { s.visible = false; return s; }
|
|
9111
9113
|
vec2 hit = d.start + d.heading * d.landing;
|
|
9112
9114
|
vec2 normal = surface(hit - d.heading * 2.0 * pixel).normal;
|
|
@@ -9219,7 +9221,7 @@ function parameterKind(track) {
|
|
|
9219
9221
|
if (values.every((value) => BoardColorSchema$1.safeParse(value).success)) return "color";
|
|
9220
9222
|
return "discrete";
|
|
9221
9223
|
}
|
|
9222
|
-
function
|
|
9224
|
+
function compileBoardTrack(animationId, id, track, targetType) {
|
|
9223
9225
|
const resolved = resolveBoardProperty(targetType, track.property);
|
|
9224
9226
|
if (!resolved.ok) return null;
|
|
9225
9227
|
const kind = targetType === "script" ? parameterKind(track) : resolved.spec.kind;
|
|
@@ -9277,7 +9279,7 @@ function compileAnimation(animationId, animation, document) {
|
|
|
9277
9279
|
for (const [id, track] of Object.entries(tracks).sort(([a], [b]) => a < b ? -1 : a > b ? 1 : 0)) {
|
|
9278
9280
|
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;
|
|
9279
9281
|
if (!targetType) continue;
|
|
9280
|
-
const entry =
|
|
9282
|
+
const entry = compileBoardTrack(animationId, id, track, targetType);
|
|
9281
9283
|
if (!entry) continue;
|
|
9282
9284
|
(targetType === "animation" ? children : compiled).push(entry);
|
|
9283
9285
|
}
|
|
@@ -9579,20 +9581,6 @@ function applyBoardEvaluation(document, evaluation) {
|
|
|
9579
9581
|
items
|
|
9580
9582
|
};
|
|
9581
9583
|
}
|
|
9582
|
-
function boardDocumentAt(document, animationId, time, options = {}) {
|
|
9583
|
-
const compiled = compileBoardAnimations(document);
|
|
9584
|
-
const times = /* @__PURE__ */ new Map();
|
|
9585
|
-
for (const [id, animation] of compiled.animations) if (animation.header.play === "always") times.set(id, boardAnimationTime(animation.header, time) ?? 0);
|
|
9586
|
-
if (animationId) {
|
|
9587
|
-
const animation = compiled.animations.get(animationId);
|
|
9588
|
-
if (animation) times.set(animationId, Math.min(Math.max(0, time), animation.header.duration));
|
|
9589
|
-
}
|
|
9590
|
-
const evaluation = evaluateBoardAnimations(compiled, times, options);
|
|
9591
|
-
return {
|
|
9592
|
-
document: applyBoardEvaluation(document, evaluation),
|
|
9593
|
-
evaluation
|
|
9594
|
-
};
|
|
9595
|
-
}
|
|
9596
9584
|
//#endregion
|
|
9597
9585
|
//#region ../sdk/src/board/model/scene.ts
|
|
9598
9586
|
const EPSILON = 1e-6;
|
|
@@ -9680,16 +9668,18 @@ function buildBoardScene(document, previous) {
|
|
|
9680
9668
|
return result;
|
|
9681
9669
|
},
|
|
9682
9670
|
binders: (id) => binders.get(id) ?? [],
|
|
9683
|
-
opacity: (id) => cumulativeOpacity((key) => items[key], id)
|
|
9671
|
+
opacity: (id) => cumulativeOpacity((key) => items[key], id),
|
|
9672
|
+
shown: (id) => cumulativeOpacity((key) => items[key], id, true) > 0
|
|
9684
9673
|
};
|
|
9685
9674
|
}
|
|
9686
|
-
function cumulativeOpacity(lookup, id) {
|
|
9675
|
+
function cumulativeOpacity(lookup, id, presence = false) {
|
|
9687
9676
|
let value = 1;
|
|
9688
9677
|
let cursor = id;
|
|
9689
9678
|
for (let depth = 0; cursor && depth < 64; depth += 1) {
|
|
9690
9679
|
const item = lookup(cursor);
|
|
9691
9680
|
if (!item) break;
|
|
9692
|
-
|
|
9681
|
+
if (item.visible === false) return 0;
|
|
9682
|
+
if (!presence) value *= item.opacity;
|
|
9693
9683
|
cursor = item.parent;
|
|
9694
9684
|
}
|
|
9695
9685
|
return value;
|
|
@@ -9725,7 +9715,8 @@ function refreshBoardScene(previous, lookup, ids) {
|
|
|
9725
9715
|
items: sceneItems,
|
|
9726
9716
|
get: (id) => overrides.get(id) ?? base.get(id),
|
|
9727
9717
|
layout,
|
|
9728
|
-
opacity: (id) => cumulativeOpacity(lookup, id)
|
|
9718
|
+
opacity: (id) => cumulativeOpacity(lookup, id),
|
|
9719
|
+
shown: (id) => cumulativeOpacity(lookup, id, true) > 0
|
|
9729
9720
|
};
|
|
9730
9721
|
refreshed.set(scene, {
|
|
9731
9722
|
base,
|
|
@@ -9981,6 +9972,494 @@ function resolveBoardAnimationCamera(override, bounds, surface, time, base = {
|
|
|
9981
9972
|
return camera;
|
|
9982
9973
|
}
|
|
9983
9974
|
//#endregion
|
|
9975
|
+
//#region ../sdk/src/board/model/items/id.ts
|
|
9976
|
+
function createBoardEntityId() {
|
|
9977
|
+
const cryptoRef = globalThis.crypto;
|
|
9978
|
+
if (cryptoRef && typeof cryptoRef.randomUUID === "function") return cryptoRef.randomUUID();
|
|
9979
|
+
return `c-${Date.now().toString(36)}-${Math.random().toString(36).slice(2, 10)}`;
|
|
9980
|
+
}
|
|
9981
|
+
function createBoardItemId() {
|
|
9982
|
+
return `item_${createBoardEntityId()}`;
|
|
9983
|
+
}
|
|
9984
|
+
const VISIBLE = "visible";
|
|
9985
|
+
function newBoardTrackId(tracks, target, property) {
|
|
9986
|
+
const id = `${target}-${property.replaceAll(".", "-")}`;
|
|
9987
|
+
return id.length <= 160 && !Object.hasOwn(tracks, id) ? id : createBoardEntityId();
|
|
9988
|
+
}
|
|
9989
|
+
function findBoardKeyTrack(tracks, target, property) {
|
|
9990
|
+
return Object.entries(tracks).find(([, track]) => track.target === target && track.property === property && track.composite === "replace");
|
|
9991
|
+
}
|
|
9992
|
+
function targetType(document, target) {
|
|
9993
|
+
if (target === "camera") return BOARD_CAMERA_TARGET$1;
|
|
9994
|
+
if (document.animations[target]) return "animation";
|
|
9995
|
+
if (document.board.scripts?.[target]) return "script";
|
|
9996
|
+
return document.items[target]?.type ?? null;
|
|
9997
|
+
}
|
|
9998
|
+
function boardPlayProperty(document, target) {
|
|
9999
|
+
const type = targetType(document, target);
|
|
10000
|
+
return type === "video" || type === "audio" ? "props.time" : type === "animation" ? "time" : null;
|
|
10001
|
+
}
|
|
10002
|
+
function boardPlayLength(document, target) {
|
|
10003
|
+
const item = document.items[target];
|
|
10004
|
+
if (item?.type === "video" || item?.type === "audio") return item.props.snapshot?.durationMs || null;
|
|
10005
|
+
return document.animations[target]?.duration ?? null;
|
|
10006
|
+
}
|
|
10007
|
+
function visibleSpan(track, duration) {
|
|
10008
|
+
let start = null;
|
|
10009
|
+
let lastShown = -1;
|
|
10010
|
+
let end = null;
|
|
10011
|
+
for (const keyframe of track.keyframes) if (keyframe.value !== false) {
|
|
10012
|
+
start ??= keyframe.at;
|
|
10013
|
+
lastShown = keyframe.at;
|
|
10014
|
+
end = null;
|
|
10015
|
+
} else if (start !== null && end === null) end = keyframe.at;
|
|
10016
|
+
return start === null ? null : {
|
|
10017
|
+
start,
|
|
10018
|
+
end: end ?? Math.max(duration, lastShown)
|
|
10019
|
+
};
|
|
10020
|
+
}
|
|
10021
|
+
function boardClipSpan(tracks, duration) {
|
|
10022
|
+
if (tracks.visible) return visibleSpan(tracks.visible, duration);
|
|
10023
|
+
const first = tracks.play?.keyframes[0];
|
|
10024
|
+
const last = tracks.play?.keyframes.at(-1);
|
|
10025
|
+
return first && last && last.at > first.at ? {
|
|
10026
|
+
start: first.at,
|
|
10027
|
+
end: last.at
|
|
10028
|
+
} : null;
|
|
10029
|
+
}
|
|
10030
|
+
function boardTargetSpan(document, animation, target) {
|
|
10031
|
+
const property = boardPlayProperty(document, target);
|
|
10032
|
+
return boardClipSpan({
|
|
10033
|
+
visible: findBoardKeyTrack(animation.tracks, target, VISIBLE)?.[1],
|
|
10034
|
+
play: property ? findBoardKeyTrack(animation.tracks, target, property)?.[1] : void 0
|
|
10035
|
+
}, animation.duration);
|
|
10036
|
+
}
|
|
10037
|
+
function visibleKeyframes(start, end) {
|
|
10038
|
+
if (end <= start) return [{
|
|
10039
|
+
at: 0,
|
|
10040
|
+
value: false
|
|
10041
|
+
}];
|
|
10042
|
+
return [
|
|
10043
|
+
...start > 0 ? [{
|
|
10044
|
+
at: 0,
|
|
10045
|
+
value: false
|
|
10046
|
+
}] : [],
|
|
10047
|
+
{
|
|
10048
|
+
at: start,
|
|
10049
|
+
value: true
|
|
10050
|
+
},
|
|
10051
|
+
{
|
|
10052
|
+
at: end,
|
|
10053
|
+
value: false
|
|
10054
|
+
}
|
|
10055
|
+
];
|
|
10056
|
+
}
|
|
10057
|
+
function normalizeVisible(keyframes) {
|
|
10058
|
+
const sorted = keyframes.map((keyframe, index) => ({
|
|
10059
|
+
keyframe,
|
|
10060
|
+
index
|
|
10061
|
+
})).sort((a, b) => a.keyframe.at - b.keyframe.at || a.index - b.index);
|
|
10062
|
+
const result = [];
|
|
10063
|
+
for (const { keyframe } of sorted) {
|
|
10064
|
+
if (result.at(-1)?.at === keyframe.at) result.pop();
|
|
10065
|
+
if (result.at(-1)?.value === keyframe.value) continue;
|
|
10066
|
+
result.push(keyframe);
|
|
10067
|
+
}
|
|
10068
|
+
if (result[0]?.value !== false && (result[0]?.at ?? 0) > 0) result.unshift({
|
|
10069
|
+
at: 0,
|
|
10070
|
+
value: false
|
|
10071
|
+
});
|
|
10072
|
+
return result;
|
|
10073
|
+
}
|
|
10074
|
+
function withDuration(animation, end) {
|
|
10075
|
+
return end > animation.duration ? {
|
|
10076
|
+
...animation,
|
|
10077
|
+
duration: Math.ceil(end)
|
|
10078
|
+
} : animation;
|
|
10079
|
+
}
|
|
10080
|
+
function setTrack(tracks, target, property, keyframes, interpolation = "auto") {
|
|
10081
|
+
const existing = findBoardKeyTrack(tracks, target, property);
|
|
10082
|
+
const id = existing?.[0] ?? newBoardTrackId(tracks, target, property);
|
|
10083
|
+
tracks[id] = existing ? {
|
|
10084
|
+
...existing[1],
|
|
10085
|
+
keyframes
|
|
10086
|
+
} : {
|
|
10087
|
+
target,
|
|
10088
|
+
property,
|
|
10089
|
+
keyframes,
|
|
10090
|
+
composite: "replace",
|
|
10091
|
+
interpolation
|
|
10092
|
+
};
|
|
10093
|
+
}
|
|
10094
|
+
function sampleTrack(document, track, time) {
|
|
10095
|
+
const type = targetType(document, track.target);
|
|
10096
|
+
const compiled = type ? compileBoardTrack("", "", track, type) : null;
|
|
10097
|
+
if (compiled) return sampleBoardTrack(compiled, time);
|
|
10098
|
+
return [...track.keyframes].reverse().find((keyframe) => keyframe.at <= time)?.value ?? track.keyframes[0]?.value;
|
|
10099
|
+
}
|
|
10100
|
+
function slope(a, b) {
|
|
10101
|
+
if (!a || !b || b.at <= a.at || typeof a.value !== "number" || typeof b.value !== "number") return 0;
|
|
10102
|
+
return (b.value - a.value) / (b.at - a.at);
|
|
10103
|
+
}
|
|
10104
|
+
function playValue(document, track, time) {
|
|
10105
|
+
const { keyframes } = track;
|
|
10106
|
+
const first = keyframes[0];
|
|
10107
|
+
const last = keyframes.at(-1);
|
|
10108
|
+
if (time < first.at) return Math.max(0, first.value - slope(first, keyframes[1]) * (first.at - time));
|
|
10109
|
+
if (time > last.at) return Math.max(0, last.value + slope(keyframes.at(-2), last) * (time - last.at));
|
|
10110
|
+
const value = sampleTrack(document, track, time);
|
|
10111
|
+
return typeof value === "number" ? value : 0;
|
|
10112
|
+
}
|
|
10113
|
+
function shiftKeyframes(keyframes, shift) {
|
|
10114
|
+
return keyframes.map((keyframe) => ({
|
|
10115
|
+
...keyframe,
|
|
10116
|
+
at: keyframe.at + shift
|
|
10117
|
+
}));
|
|
10118
|
+
}
|
|
10119
|
+
function withoutAnchor(track) {
|
|
10120
|
+
const [first, second] = track.keyframes;
|
|
10121
|
+
return track.property === VISIBLE && first?.at === 0 && first.value === false && second ? track.keyframes.slice(1) : track.keyframes;
|
|
10122
|
+
}
|
|
10123
|
+
function boardPlaceTarget(document, animation, target, placement) {
|
|
10124
|
+
const at = Math.max(0, Math.round(placement.at));
|
|
10125
|
+
const existing = boardTargetSpan(document, animation, target);
|
|
10126
|
+
if (existing) return boardShiftTargets(document, animation, [target], at - existing.start);
|
|
10127
|
+
const rate = placement.rate && placement.rate > 0 ? placement.rate : 1;
|
|
10128
|
+
const from = Math.max(0, placement.from ?? 0);
|
|
10129
|
+
const length = boardPlayLength(document, target);
|
|
10130
|
+
const remaining = length !== null && length > from ? (length - from) / rate : null;
|
|
10131
|
+
const duration = Math.max(40, Math.round(placement.duration ?? remaining ?? 3e3));
|
|
10132
|
+
const tracks = { ...animation.tracks };
|
|
10133
|
+
if (document.items[target]) setTrack(tracks, target, VISIBLE, visibleKeyframes(at, at + duration), "step");
|
|
10134
|
+
const property = boardPlayProperty(document, target);
|
|
10135
|
+
if (property) setTrack(tracks, target, property, [{
|
|
10136
|
+
at,
|
|
10137
|
+
value: from
|
|
10138
|
+
}, {
|
|
10139
|
+
at: at + duration,
|
|
10140
|
+
value: from + duration * rate
|
|
10141
|
+
}]);
|
|
10142
|
+
return withDuration({
|
|
10143
|
+
...animation,
|
|
10144
|
+
tracks
|
|
10145
|
+
}, at + duration);
|
|
10146
|
+
}
|
|
10147
|
+
function boardShiftTargets(document, animation, targets, delta) {
|
|
10148
|
+
const owned = Object.entries(animation.tracks).filter(([, track]) => targets.includes(track.target));
|
|
10149
|
+
const spans = targets.map((target) => boardTargetSpan(document, animation, target));
|
|
10150
|
+
const keyed = Math.min(...owned.map(([, track]) => withoutAnchor(track)[0]?.at ?? Number.POSITIVE_INFINITY));
|
|
10151
|
+
const earliest = Math.min(...spans.map((span) => span?.start ?? keyed));
|
|
10152
|
+
if (!Number.isFinite(earliest)) return animation;
|
|
10153
|
+
const shift = Math.round(Math.max(delta, -earliest));
|
|
10154
|
+
if (shift === 0) return animation;
|
|
10155
|
+
const tracks = { ...animation.tracks };
|
|
10156
|
+
let end = Math.max(0, ...spans.map((span) => span ? span.end + shift : 0));
|
|
10157
|
+
for (const [id, track] of owned) {
|
|
10158
|
+
let body = withoutAnchor(track);
|
|
10159
|
+
if ((body[0]?.at ?? 0) < -shift) {
|
|
10160
|
+
const after = cutTrack(document, {
|
|
10161
|
+
...track,
|
|
10162
|
+
keyframes: [...body]
|
|
10163
|
+
}, -shift).after;
|
|
10164
|
+
body = after.length ? after : [{
|
|
10165
|
+
...body.at(-1),
|
|
10166
|
+
at: -shift
|
|
10167
|
+
}];
|
|
10168
|
+
}
|
|
10169
|
+
const moved = shiftKeyframes(body, shift);
|
|
10170
|
+
const keyframes = track.property === VISIBLE ? normalizeVisible(moved) : moved;
|
|
10171
|
+
tracks[id] = {
|
|
10172
|
+
...track,
|
|
10173
|
+
keyframes
|
|
10174
|
+
};
|
|
10175
|
+
if (!spans.some(Boolean)) end = Math.max(end, keyframes.at(-1)?.at ?? 0);
|
|
10176
|
+
}
|
|
10177
|
+
return withDuration({
|
|
10178
|
+
...animation,
|
|
10179
|
+
tracks
|
|
10180
|
+
}, end);
|
|
10181
|
+
}
|
|
10182
|
+
function boardTrimLimits(document, animation, target) {
|
|
10183
|
+
const property = boardPlayProperty(document, target);
|
|
10184
|
+
const play = property ? findBoardKeyTrack(animation.tracks, target, property)?.[1] : void 0;
|
|
10185
|
+
const first = play?.keyframes[0];
|
|
10186
|
+
const last = play?.keyframes.at(-1);
|
|
10187
|
+
if (!play || !first || !last) return {
|
|
10188
|
+
start: 0,
|
|
10189
|
+
end: Number.POSITIVE_INFINITY
|
|
10190
|
+
};
|
|
10191
|
+
const head = slope(first, play.keyframes[1]);
|
|
10192
|
+
const tail = slope(play.keyframes.at(-2), last);
|
|
10193
|
+
const length = boardPlayLength(document, target);
|
|
10194
|
+
const start = head > 0 && typeof first.value === "number" ? first.at - first.value / head : 0;
|
|
10195
|
+
const end = tail > 0 && length !== null && typeof last.value === "number" ? last.at + (length - last.value) / tail : Number.POSITIVE_INFINITY;
|
|
10196
|
+
return {
|
|
10197
|
+
start: Math.max(0, Math.ceil(start)),
|
|
10198
|
+
end: Math.max(last.at, Math.floor(end))
|
|
10199
|
+
};
|
|
10200
|
+
}
|
|
10201
|
+
function boardTrimTarget(document, animation, target, edge, at) {
|
|
10202
|
+
const span = boardTargetSpan(document, animation, target);
|
|
10203
|
+
if (!span) return animation;
|
|
10204
|
+
const limits = boardTrimLimits(document, animation, target);
|
|
10205
|
+
const time = edge === "start" ? Math.round(Math.min(Math.max(at, limits.start), span.end - 40)) : Math.round(Math.max(Math.min(at, limits.end), span.start + 40));
|
|
10206
|
+
if (time === span[edge]) return animation;
|
|
10207
|
+
const next = edge === "start" ? {
|
|
10208
|
+
start: time,
|
|
10209
|
+
end: span.end
|
|
10210
|
+
} : {
|
|
10211
|
+
start: span.start,
|
|
10212
|
+
end: time
|
|
10213
|
+
};
|
|
10214
|
+
const tracks = { ...animation.tracks };
|
|
10215
|
+
if (findBoardKeyTrack(tracks, target, VISIBLE)) setTrack(tracks, target, VISIBLE, visibleKeyframes(next.start, next.end), "step");
|
|
10216
|
+
const property = boardPlayProperty(document, target);
|
|
10217
|
+
const play = property ? findBoardKeyTrack(tracks, target, property) : void 0;
|
|
10218
|
+
if (play) {
|
|
10219
|
+
const [id, track] = play;
|
|
10220
|
+
const first = track.keyframes[0];
|
|
10221
|
+
const last = track.keyframes.at(-1);
|
|
10222
|
+
let keyframes;
|
|
10223
|
+
if (time > first.at && time < last.at) keyframes = cutTrack(document, track, time)[edge === "start" ? "after" : "before"];
|
|
10224
|
+
else {
|
|
10225
|
+
const cut = {
|
|
10226
|
+
at: time,
|
|
10227
|
+
value: playValue(document, track, time)
|
|
10228
|
+
};
|
|
10229
|
+
keyframes = edge === "start" ? [cut, ...track.keyframes.filter((keyframe) => keyframe.at > time)] : [...track.keyframes.filter((keyframe) => keyframe.at < time), cut];
|
|
10230
|
+
}
|
|
10231
|
+
tracks[id] = {
|
|
10232
|
+
...track,
|
|
10233
|
+
keyframes
|
|
10234
|
+
};
|
|
10235
|
+
}
|
|
10236
|
+
return withDuration({
|
|
10237
|
+
...animation,
|
|
10238
|
+
tracks
|
|
10239
|
+
}, next.end);
|
|
10240
|
+
}
|
|
10241
|
+
function cutValue(document, track, at) {
|
|
10242
|
+
return {
|
|
10243
|
+
at,
|
|
10244
|
+
value: sampleTrack(document, track, at)
|
|
10245
|
+
};
|
|
10246
|
+
}
|
|
10247
|
+
const CURVES = {
|
|
10248
|
+
ease: [
|
|
10249
|
+
.25,
|
|
10250
|
+
.1,
|
|
10251
|
+
.25,
|
|
10252
|
+
1
|
|
10253
|
+
],
|
|
10254
|
+
"ease-in": [
|
|
10255
|
+
.42,
|
|
10256
|
+
0,
|
|
10257
|
+
1,
|
|
10258
|
+
1
|
|
10259
|
+
],
|
|
10260
|
+
"ease-out": [
|
|
10261
|
+
0,
|
|
10262
|
+
0,
|
|
10263
|
+
.58,
|
|
10264
|
+
1
|
|
10265
|
+
],
|
|
10266
|
+
"ease-in-out": [
|
|
10267
|
+
.42,
|
|
10268
|
+
0,
|
|
10269
|
+
.58,
|
|
10270
|
+
1
|
|
10271
|
+
]
|
|
10272
|
+
};
|
|
10273
|
+
function curveOf(ease) {
|
|
10274
|
+
const key = ease.trim();
|
|
10275
|
+
const known = CURVES[key];
|
|
10276
|
+
if (known) return known;
|
|
10277
|
+
const numbers = /^cubic-bezier\(([^)]+)\)$/.exec(key)?.[1]?.split(",").map(Number);
|
|
10278
|
+
return numbers?.length === 4 && numbers.every(Number.isFinite) ? numbers : null;
|
|
10279
|
+
}
|
|
10280
|
+
const format = (curve) => `cubic-bezier(${curve.map((value) => Number(value.toFixed(4))).join(", ")})`;
|
|
10281
|
+
function splitEase(ease, progress) {
|
|
10282
|
+
const curve = ease && ease.trim() !== "linear" ? curveOf(ease) : null;
|
|
10283
|
+
if (!ease || !curve) return [ease, ease];
|
|
10284
|
+
const [x1, y1, x2, y2] = curve;
|
|
10285
|
+
const bezier = (a, b, t) => 3 * a * t * (1 - t) ** 2 + 3 * b * t ** 2 * (1 - t) + t ** 3;
|
|
10286
|
+
let low = 0;
|
|
10287
|
+
let high = 1;
|
|
10288
|
+
for (let index = 0; index < 40; index += 1) {
|
|
10289
|
+
const mid = (low + high) / 2;
|
|
10290
|
+
if (bezier(x1, x2, mid) < progress) low = mid;
|
|
10291
|
+
else high = mid;
|
|
10292
|
+
}
|
|
10293
|
+
const t = (low + high) / 2;
|
|
10294
|
+
const lerp = (a, b) => a + (b - a) * t;
|
|
10295
|
+
const p01 = [lerp(0, x1), lerp(0, y1)];
|
|
10296
|
+
const p12 = [lerp(x1, x2), lerp(y1, y2)];
|
|
10297
|
+
const p23 = [lerp(x2, 1), lerp(y2, 1)];
|
|
10298
|
+
const p012 = [lerp(p01[0], p12[0]), lerp(p01[1], p12[1])];
|
|
10299
|
+
const p123 = [lerp(p12[0], p23[0]), lerp(p12[1], p23[1])];
|
|
10300
|
+
const [x, y] = [lerp(p012[0], p123[0]), lerp(p012[1], p123[1])];
|
|
10301
|
+
if (x <= 0 || x >= 1 || Math.abs(y) < 1e-9 || Math.abs(1 - y) < 1e-9) return [ease, ease];
|
|
10302
|
+
return [format([
|
|
10303
|
+
p01[0] / x,
|
|
10304
|
+
p01[1] / y,
|
|
10305
|
+
p012[0] / x,
|
|
10306
|
+
p012[1] / y
|
|
10307
|
+
]), format([
|
|
10308
|
+
(p123[0] - x) / (1 - x),
|
|
10309
|
+
(p123[1] - y) / (1 - y),
|
|
10310
|
+
(p23[0] - x) / (1 - x),
|
|
10311
|
+
(p23[1] - y) / (1 - y)
|
|
10312
|
+
])];
|
|
10313
|
+
}
|
|
10314
|
+
function withEase(keyframe, ease) {
|
|
10315
|
+
const { ease: _ease, ...rest } = keyframe;
|
|
10316
|
+
return ease && ease !== "linear" ? {
|
|
10317
|
+
...rest,
|
|
10318
|
+
ease
|
|
10319
|
+
} : rest;
|
|
10320
|
+
}
|
|
10321
|
+
function cutTrack(document, track, time) {
|
|
10322
|
+
const { keyframes } = track;
|
|
10323
|
+
const index = keyframes.findIndex((keyframe) => keyframe.at >= time);
|
|
10324
|
+
const before = keyframes.filter((keyframe) => keyframe.at <= time);
|
|
10325
|
+
const after = keyframes.filter((keyframe) => keyframe.at >= time);
|
|
10326
|
+
const a = keyframes[index - 1];
|
|
10327
|
+
const b = keyframes[index];
|
|
10328
|
+
if (!a || !b || b.at === time) return {
|
|
10329
|
+
before,
|
|
10330
|
+
after
|
|
10331
|
+
};
|
|
10332
|
+
const value = cutValue(document, track, time).value;
|
|
10333
|
+
const [left, right] = track.interpolation === "step" ? [b.ease, b.ease] : splitEase(b.ease, (time - a.at) / (b.at - a.at));
|
|
10334
|
+
return {
|
|
10335
|
+
before: [...before, withEase({
|
|
10336
|
+
at: time,
|
|
10337
|
+
value
|
|
10338
|
+
}, left)],
|
|
10339
|
+
after: [
|
|
10340
|
+
{
|
|
10341
|
+
at: time,
|
|
10342
|
+
value
|
|
10343
|
+
},
|
|
10344
|
+
withEase(b, right),
|
|
10345
|
+
...after.slice(1)
|
|
10346
|
+
]
|
|
10347
|
+
};
|
|
10348
|
+
}
|
|
10349
|
+
function boardSplitTarget(document, animation, target, copies, at) {
|
|
10350
|
+
const span = boardTargetSpan(document, animation, target);
|
|
10351
|
+
const time = Math.round(at);
|
|
10352
|
+
if (!span || time < span.start + 40 || time > span.end - 40) return null;
|
|
10353
|
+
const tracks = { ...animation.tracks };
|
|
10354
|
+
for (const [id, track] of Object.entries(animation.tracks)) {
|
|
10355
|
+
const copy = copies.get(track.target);
|
|
10356
|
+
if (!copy) continue;
|
|
10357
|
+
const own = track.property === VISIBLE ? boardTargetSpan(document, animation, track.target) : null;
|
|
10358
|
+
let before;
|
|
10359
|
+
let after;
|
|
10360
|
+
if (own) {
|
|
10361
|
+
before = visibleKeyframes(own.start, Math.min(own.end, time));
|
|
10362
|
+
after = visibleKeyframes(Math.max(own.start, time), own.end);
|
|
10363
|
+
} else {
|
|
10364
|
+
const index = track.keyframes.findIndex((keyframe) => keyframe.at >= time);
|
|
10365
|
+
const next = index < 0 ? track.keyframes.length : index;
|
|
10366
|
+
before = track.keyframes.slice(0, next + 2);
|
|
10367
|
+
after = track.keyframes.slice(Math.max(0, next - 2));
|
|
10368
|
+
}
|
|
10369
|
+
tracks[id] = {
|
|
10370
|
+
...track,
|
|
10371
|
+
keyframes: before
|
|
10372
|
+
};
|
|
10373
|
+
tracks[newBoardTrackId(tracks, copy, track.property)] = {
|
|
10374
|
+
...structuredClone(track),
|
|
10375
|
+
target: copy,
|
|
10376
|
+
keyframes: after
|
|
10377
|
+
};
|
|
10378
|
+
}
|
|
10379
|
+
const copy = copies.get(target);
|
|
10380
|
+
if (document.items[target] && !findBoardKeyTrack(animation.tracks, target, VISIBLE)) {
|
|
10381
|
+
setTrack(tracks, target, VISIBLE, visibleKeyframes(span.start, time), "step");
|
|
10382
|
+
setTrack(tracks, copy, VISIBLE, visibleKeyframes(time, span.end), "step");
|
|
10383
|
+
}
|
|
10384
|
+
return {
|
|
10385
|
+
...animation,
|
|
10386
|
+
tracks
|
|
10387
|
+
};
|
|
10388
|
+
}
|
|
10389
|
+
function boardRemoveTarget(animation, target) {
|
|
10390
|
+
const tracks = Object.fromEntries(Object.entries(animation.tracks).filter(([, track]) => track.target !== target));
|
|
10391
|
+
return Object.keys(tracks).length === Object.keys(animation.tracks).length ? animation : {
|
|
10392
|
+
...animation,
|
|
10393
|
+
tracks
|
|
10394
|
+
};
|
|
10395
|
+
}
|
|
10396
|
+
function retime(animation, keyframes, markers, duration) {
|
|
10397
|
+
const tracks = {};
|
|
10398
|
+
for (const [id, track] of Object.entries(animation.tracks)) {
|
|
10399
|
+
const next = track.property === VISIBLE ? normalizeVisible(keyframes(track)) : keyframes(track);
|
|
10400
|
+
if (track.property === VISIBLE) tracks[id] = {
|
|
10401
|
+
...track,
|
|
10402
|
+
keyframes: next.length ? next : [{
|
|
10403
|
+
at: 0,
|
|
10404
|
+
value: false
|
|
10405
|
+
}]
|
|
10406
|
+
};
|
|
10407
|
+
else if (next.length) tracks[id] = {
|
|
10408
|
+
...track,
|
|
10409
|
+
keyframes: next
|
|
10410
|
+
};
|
|
10411
|
+
}
|
|
10412
|
+
return {
|
|
10413
|
+
...animation,
|
|
10414
|
+
tracks,
|
|
10415
|
+
markers,
|
|
10416
|
+
duration: Math.max(1, Math.round(duration))
|
|
10417
|
+
};
|
|
10418
|
+
}
|
|
10419
|
+
function join(before, after) {
|
|
10420
|
+
const last = before.at(-1);
|
|
10421
|
+
const [first, second] = after;
|
|
10422
|
+
if (!last || !first || first.at !== last.at) return [...before, ...after];
|
|
10423
|
+
if (sameJson(first.value, last.value) || second && second.at <= first.at + 1) return [...before, ...after.slice(1)];
|
|
10424
|
+
return [
|
|
10425
|
+
...before,
|
|
10426
|
+
{
|
|
10427
|
+
...first,
|
|
10428
|
+
at: first.at + 1
|
|
10429
|
+
},
|
|
10430
|
+
...after.slice(1)
|
|
10431
|
+
];
|
|
10432
|
+
}
|
|
10433
|
+
function boardRemoveTime(document, animation, from, to) {
|
|
10434
|
+
const start = Math.max(0, Math.round(Math.min(from, to)));
|
|
10435
|
+
const end = Math.round(Math.max(from, to));
|
|
10436
|
+
const length = end - start;
|
|
10437
|
+
if (length <= 0) return animation;
|
|
10438
|
+
return retime(animation, (track) => {
|
|
10439
|
+
const { before } = cutTrack(document, track, start);
|
|
10440
|
+
const after = shiftKeyframes(cutTrack(document, track, end).after, -length);
|
|
10441
|
+
return track.property === VISIBLE ? [...before, ...after] : join(before, after);
|
|
10442
|
+
}, animation.markers.filter((marker) => marker.at <= start || marker.at >= end).map((marker) => marker.at >= end ? {
|
|
10443
|
+
...marker,
|
|
10444
|
+
at: marker.at - length
|
|
10445
|
+
} : marker), animation.duration - (Math.min(end, animation.duration) - Math.min(start, animation.duration)));
|
|
10446
|
+
}
|
|
10447
|
+
function boardInsertTime(document, animation, at, length) {
|
|
10448
|
+
const time = Math.max(0, Math.round(at));
|
|
10449
|
+
const gap = Math.round(length);
|
|
10450
|
+
if (gap <= 0) return animation;
|
|
10451
|
+
return retime(animation, (track) => {
|
|
10452
|
+
const body = withoutAnchor(track);
|
|
10453
|
+
const anchor = track.keyframes.slice(0, track.keyframes.length - body.length);
|
|
10454
|
+
if ((body[0]?.at ?? 0) >= time) return [...anchor, ...shiftKeyframes(body, gap)];
|
|
10455
|
+
const { before, after } = cutTrack(document, track, time);
|
|
10456
|
+
return after.some((keyframe) => keyframe.at > time) ? [...before, ...shiftKeyframes(after, gap)] : before;
|
|
10457
|
+
}, animation.markers.map((marker) => marker.at > time ? {
|
|
10458
|
+
...marker,
|
|
10459
|
+
at: marker.at + gap
|
|
10460
|
+
} : marker), time < animation.duration ? animation.duration + gap : animation.duration);
|
|
10461
|
+
}
|
|
10462
|
+
//#endregion
|
|
9984
10463
|
//#region ../sdk/src/board/model/authoring.ts
|
|
9985
10464
|
function validateChapterComposition(document, chapters) {
|
|
9986
10465
|
const uses = /* @__PURE__ */ new Map();
|
|
@@ -10116,6 +10595,39 @@ function boardSequencePatch(document, id, chapters) {
|
|
|
10116
10595
|
if (!result.ok) throw new Error(result.diagnostics.map((entry) => `${entry.path}: ${entry.message}`).join("; "));
|
|
10117
10596
|
return patch;
|
|
10118
10597
|
}
|
|
10598
|
+
function boardPlacePatch(document, id, targets, placement) {
|
|
10599
|
+
BoardIdSchema$1.parse(id);
|
|
10600
|
+
const existing = document.animations[id];
|
|
10601
|
+
let animation = existing ?? {
|
|
10602
|
+
duration: 1,
|
|
10603
|
+
play: "manual",
|
|
10604
|
+
delay: 0,
|
|
10605
|
+
loop: false,
|
|
10606
|
+
end: "hold",
|
|
10607
|
+
markers: [],
|
|
10608
|
+
tracks: {}
|
|
10609
|
+
};
|
|
10610
|
+
let at = placement.at;
|
|
10611
|
+
for (const target of targets) {
|
|
10612
|
+
if (target === id || !document.items[target] && !document.animations[target]) throw new Error(`${target} is not an item or animation on this Board.`);
|
|
10613
|
+
animation = boardPlaceTarget(document, animation, target, {
|
|
10614
|
+
...placement,
|
|
10615
|
+
at
|
|
10616
|
+
});
|
|
10617
|
+
if (!placement.together) at = boardTargetSpan(document, animation, target)?.end ?? at;
|
|
10618
|
+
}
|
|
10619
|
+
const tracks = Object.fromEntries(Object.entries(animation.tracks).filter(([key, track]) => existing?.tracks[key] !== track));
|
|
10620
|
+
const patch = { animations: { [id]: existing ? {
|
|
10621
|
+
duration: animation.duration,
|
|
10622
|
+
tracks
|
|
10623
|
+
} : {
|
|
10624
|
+
...animation,
|
|
10625
|
+
tracks
|
|
10626
|
+
} } };
|
|
10627
|
+
const result = applyBoardPatchToDocument(document, patch);
|
|
10628
|
+
if (!result.ok) throw new Error(result.diagnostics.map((entry) => `${entry.path}: ${entry.message}`).join("; "));
|
|
10629
|
+
return patch;
|
|
10630
|
+
}
|
|
10119
10631
|
function boardPathTrack(target, points, options) {
|
|
10120
10632
|
const { duration, at = 0, samples = 64, orient = false } = options;
|
|
10121
10633
|
if (points.length < 2 || points.length > 1e4 || points.some((p) => !Number.isFinite(p.x) || !Number.isFinite(p.y))) throw new Error("A path needs 2 to 10000 finite points.");
|
|
@@ -10161,6 +10673,105 @@ function boardPathTrack(target, points, options) {
|
|
|
10161
10673
|
})
|
|
10162
10674
|
};
|
|
10163
10675
|
}
|
|
10676
|
+
//#endregion
|
|
10677
|
+
//#region ../sdk/src/board/model/media-spans.ts
|
|
10678
|
+
const BOARD_MEDIA_RATES = {
|
|
10679
|
+
min: .25,
|
|
10680
|
+
max: 4
|
|
10681
|
+
};
|
|
10682
|
+
function boardTimedMedia(scene, ids) {
|
|
10683
|
+
const result = [];
|
|
10684
|
+
const items = ids ? Array.from(ids, (id) => scene.get(id)) : scene.items;
|
|
10685
|
+
for (const item of items) {
|
|
10686
|
+
if (item?.type !== "video" && item?.type !== "audio") continue;
|
|
10687
|
+
const { time, volume, src } = item.props;
|
|
10688
|
+
if (time === void 0 || !parseBoardMediaSource$1(src)) continue;
|
|
10689
|
+
result.push({
|
|
10690
|
+
id: item.id,
|
|
10691
|
+
kind: item.type,
|
|
10692
|
+
src,
|
|
10693
|
+
time,
|
|
10694
|
+
volume: volume ?? 1,
|
|
10695
|
+
shown: scene.shown(item.id)
|
|
10696
|
+
});
|
|
10697
|
+
}
|
|
10698
|
+
return result;
|
|
10699
|
+
}
|
|
10700
|
+
function boardMediaRate(from, to) {
|
|
10701
|
+
const elapsed = to.at - from.at;
|
|
10702
|
+
if (elapsed <= 0) return 0;
|
|
10703
|
+
const rate = (to.time - from.time) / elapsed;
|
|
10704
|
+
return rate >= BOARD_MEDIA_RATES.min && rate <= BOARD_MEDIA_RATES.max ? rate : 0;
|
|
10705
|
+
}
|
|
10706
|
+
function sameRate(a, b) {
|
|
10707
|
+
return Math.abs(a - b) <= .01 * Math.max(a, b);
|
|
10708
|
+
}
|
|
10709
|
+
function simplify(points) {
|
|
10710
|
+
const result = [];
|
|
10711
|
+
for (const point of points) {
|
|
10712
|
+
const a = result.at(-2);
|
|
10713
|
+
const b = result.at(-1);
|
|
10714
|
+
if (a && b && point.at > a.at && Math.abs(a.value + (b.at - a.at) / (point.at - a.at) * (point.value - a.value) - b.value) < .001) result.pop();
|
|
10715
|
+
result.push(point);
|
|
10716
|
+
}
|
|
10717
|
+
return result;
|
|
10718
|
+
}
|
|
10719
|
+
function boardMediaSpans(samples) {
|
|
10720
|
+
const spans = [];
|
|
10721
|
+
const open = /* @__PURE__ */ new Map();
|
|
10722
|
+
const previous = /* @__PURE__ */ new Map();
|
|
10723
|
+
for (const { at, media } of samples) {
|
|
10724
|
+
const seen = /* @__PURE__ */ new Set();
|
|
10725
|
+
for (const state of media) {
|
|
10726
|
+
seen.add(state.id);
|
|
10727
|
+
const before = previous.get(state.id);
|
|
10728
|
+
previous.set(state.id, {
|
|
10729
|
+
at,
|
|
10730
|
+
state
|
|
10731
|
+
});
|
|
10732
|
+
const span = open.get(state.id);
|
|
10733
|
+
const rate = before?.state.shown && state.shown && before.state.src === state.src ? boardMediaRate({
|
|
10734
|
+
at: before.at,
|
|
10735
|
+
time: before.state.time
|
|
10736
|
+
}, {
|
|
10737
|
+
at,
|
|
10738
|
+
time: state.time
|
|
10739
|
+
}) : 0;
|
|
10740
|
+
if (span && rate && sameRate(rate, span.rate)) {
|
|
10741
|
+
span.end = at;
|
|
10742
|
+
span.volume.push({
|
|
10743
|
+
at,
|
|
10744
|
+
value: state.volume
|
|
10745
|
+
});
|
|
10746
|
+
continue;
|
|
10747
|
+
}
|
|
10748
|
+
if (span) open.delete(state.id);
|
|
10749
|
+
if (!before || !rate) continue;
|
|
10750
|
+
const next = {
|
|
10751
|
+
id: state.id,
|
|
10752
|
+
kind: state.kind,
|
|
10753
|
+
src: state.src,
|
|
10754
|
+
start: before.at,
|
|
10755
|
+
end: at,
|
|
10756
|
+
from: before.state.time,
|
|
10757
|
+
rate,
|
|
10758
|
+
volume: [{
|
|
10759
|
+
at: before.at,
|
|
10760
|
+
value: before.state.volume
|
|
10761
|
+
}, {
|
|
10762
|
+
at,
|
|
10763
|
+
value: state.volume
|
|
10764
|
+
}]
|
|
10765
|
+
};
|
|
10766
|
+
open.set(state.id, next);
|
|
10767
|
+
spans.push(next);
|
|
10768
|
+
}
|
|
10769
|
+
for (const id of open.keys()) if (!seen.has(id)) open.delete(id);
|
|
10770
|
+
for (const id of previous.keys()) if (!seen.has(id)) previous.delete(id);
|
|
10771
|
+
}
|
|
10772
|
+
for (const span of spans) span.volume = simplify(span.volume);
|
|
10773
|
+
return spans;
|
|
10774
|
+
}
|
|
10164
10775
|
const CURVE_SEGMENTS = 20;
|
|
10165
10776
|
const ORTHOGONAL_SNAP = .5;
|
|
10166
10777
|
const SIDE_NORMALS = {
|
|
@@ -12150,16 +12761,6 @@ const builtinBoardItems = [
|
|
|
12150
12761
|
customItem
|
|
12151
12762
|
];
|
|
12152
12763
|
//#endregion
|
|
12153
|
-
//#region ../sdk/src/board/model/items/id.ts
|
|
12154
|
-
function createBoardEntityId() {
|
|
12155
|
-
const cryptoRef = globalThis.crypto;
|
|
12156
|
-
if (cryptoRef && typeof cryptoRef.randomUUID === "function") return cryptoRef.randomUUID();
|
|
12157
|
-
return `c-${Date.now().toString(36)}-${Math.random().toString(36).slice(2, 10)}`;
|
|
12158
|
-
}
|
|
12159
|
-
function createBoardItemId() {
|
|
12160
|
-
return `item_${createBoardEntityId()}`;
|
|
12161
|
-
}
|
|
12162
|
-
//#endregion
|
|
12163
12764
|
//#region ../sdk/src/board/model/items/create.ts
|
|
12164
12765
|
const DEFAULT_MODEL_SIZE = {
|
|
12165
12766
|
width: 264,
|
|
@@ -38266,6 +38867,9 @@ function colorSteps(filter) {
|
|
|
38266
38867
|
}
|
|
38267
38868
|
var BoardColorFilter = class extends ColorMatrixFilter {
|
|
38268
38869
|
css = "";
|
|
38870
|
+
constructor() {
|
|
38871
|
+
super({ resolution: "inherit" });
|
|
38872
|
+
}
|
|
38269
38873
|
set(filter) {
|
|
38270
38874
|
const steps = colorSteps(filter);
|
|
38271
38875
|
this.css = steps.map(({ step, value }) => step.css(value)).join(" ");
|
|
@@ -38343,21 +38947,47 @@ function shaderPasses() {
|
|
|
38343
38947
|
};
|
|
38344
38948
|
return passes;
|
|
38345
38949
|
}
|
|
38346
|
-
|
|
38347
|
-
|
|
38950
|
+
const TEXELS_PER_DEVIATION = 4;
|
|
38951
|
+
const MAX_HALVINGS = 5;
|
|
38952
|
+
function gaussian(filters, input, output, deviation, clear, first) {
|
|
38953
|
+
const { horizontal, vertical, copy } = shaderPasses();
|
|
38954
|
+
const resolution = input.source.resolution;
|
|
38955
|
+
const halvings = Math.max(0, Math.min(MAX_HALVINGS, Math.floor(Math.log2(deviation * resolution / TEXELS_PER_DEVIATION))));
|
|
38956
|
+
const borrowed = [];
|
|
38957
|
+
const borrow = (scale) => {
|
|
38958
|
+
const texture = TexturePool.getOptimalTexture(input.frame.width, input.frame.height, resolution * scale, false);
|
|
38959
|
+
borrowed.push(texture);
|
|
38960
|
+
return texture;
|
|
38961
|
+
};
|
|
38962
|
+
let source = input;
|
|
38963
|
+
let scale = 1;
|
|
38964
|
+
for (let step = 0; step < Math.max(halvings, first ? 1 : 0); step++) {
|
|
38965
|
+
if (step < halvings) scale /= 2;
|
|
38966
|
+
const next = borrow(scale);
|
|
38967
|
+
filters.applyFilter(step === 0 && first ? first : copy, source, next, true);
|
|
38968
|
+
source = next;
|
|
38969
|
+
}
|
|
38348
38970
|
horizontal.resources.blurUniforms.uniforms.uStep = [deviation / 4, 0];
|
|
38349
38971
|
vertical.resources.blurUniforms.uniforms.uStep = [0, deviation / 4];
|
|
38350
|
-
const between =
|
|
38351
|
-
filters.applyFilter(horizontal,
|
|
38352
|
-
filters.applyFilter(vertical, between, output, clear);
|
|
38353
|
-
|
|
38972
|
+
const between = borrow(scale);
|
|
38973
|
+
filters.applyFilter(horizontal, source, between, true);
|
|
38974
|
+
if (scale === 1) filters.applyFilter(vertical, between, output, clear);
|
|
38975
|
+
else {
|
|
38976
|
+
const blurred = borrow(scale);
|
|
38977
|
+
filters.applyFilter(vertical, between, blurred, true);
|
|
38978
|
+
filters.applyFilter(copy, blurred, output, clear);
|
|
38979
|
+
}
|
|
38980
|
+
for (const texture of borrowed) TexturePool.returnTexture(texture);
|
|
38354
38981
|
}
|
|
38355
38982
|
var BoardBlurFilter = class extends Filter {
|
|
38356
38983
|
css = "";
|
|
38357
38984
|
radius = 0;
|
|
38358
38985
|
deviation = 0;
|
|
38359
38986
|
constructor() {
|
|
38360
|
-
super({
|
|
38987
|
+
super({
|
|
38988
|
+
glProgram: program("board-copy", COPY_FRAGMENT),
|
|
38989
|
+
resolution: "inherit"
|
|
38990
|
+
});
|
|
38361
38991
|
}
|
|
38362
38992
|
set(radius, zoom) {
|
|
38363
38993
|
this.radius = radius;
|
|
@@ -38384,6 +39014,7 @@ var BoardShadowFilter = class extends Filter {
|
|
|
38384
39014
|
deviation = 0;
|
|
38385
39015
|
constructor() {
|
|
38386
39016
|
super({
|
|
39017
|
+
resolution: "inherit",
|
|
38387
39018
|
glProgram: program("board-shadow", SHADOW_FRAGMENT),
|
|
38388
39019
|
resources: { shadowUniforms: {
|
|
38389
39020
|
uOffset: {
|
|
@@ -38416,12 +39047,9 @@ var BoardShadowFilter = class extends Filter {
|
|
|
38416
39047
|
}
|
|
38417
39048
|
apply(filters, input, output, clearMode) {
|
|
38418
39049
|
const { copy } = shaderPasses();
|
|
38419
|
-
|
|
38420
|
-
filters.applyFilter(this, input,
|
|
38421
|
-
if (this.deviation > 0) gaussian(filters, shadow, output, this.deviation, clearMode);
|
|
38422
|
-
else filters.applyFilter(copy, shadow, output, clearMode);
|
|
39050
|
+
if (this.deviation > 0) gaussian(filters, input, output, this.deviation, clearMode, this);
|
|
39051
|
+
else filters.applyFilter(this, input, output, clearMode);
|
|
38423
39052
|
filters.applyFilter(copy, input, output, false);
|
|
38424
|
-
TexturePool.returnTexture(shadow);
|
|
38425
39053
|
}
|
|
38426
39054
|
getCanvasFilterString() {
|
|
38427
39055
|
return this.css;
|
|
@@ -38908,6 +39536,32 @@ function roundRectPoints(width, height, radius) {
|
|
|
38908
39536
|
worldPoint(width - r, 0)
|
|
38909
39537
|
];
|
|
38910
39538
|
}
|
|
39539
|
+
function shapeOutlinePoints(geometry, width, height, radius) {
|
|
39540
|
+
const p = (x, y) => worldPoint(x, y);
|
|
39541
|
+
switch (geometry) {
|
|
39542
|
+
case "ellipse": {
|
|
39543
|
+
const segments = 64;
|
|
39544
|
+
return Array.from({ length: 65 }, (_, index) => {
|
|
39545
|
+
const angle = -Math.PI / 2 + index / segments * Math.PI * 2;
|
|
39546
|
+
return p(width / 2 + Math.cos(angle) * width / 2, height / 2 + Math.sin(angle) * height / 2);
|
|
39547
|
+
});
|
|
39548
|
+
}
|
|
39549
|
+
case "diamond": return [
|
|
39550
|
+
p(width / 2, 0),
|
|
39551
|
+
p(width, height / 2),
|
|
39552
|
+
p(width / 2, height),
|
|
39553
|
+
p(0, height / 2),
|
|
39554
|
+
p(width / 2, 0)
|
|
39555
|
+
];
|
|
39556
|
+
case "triangle": return [
|
|
39557
|
+
p(width / 2, 0),
|
|
39558
|
+
p(width, height),
|
|
39559
|
+
p(0, height),
|
|
39560
|
+
p(width / 2, 0)
|
|
39561
|
+
];
|
|
39562
|
+
default: return roundRectPoints(width, height, radius);
|
|
39563
|
+
}
|
|
39564
|
+
}
|
|
38911
39565
|
const SHADOW_LAYERS = 5;
|
|
38912
39566
|
function traceCardOutline(graphics, rect, style, grow = 0) {
|
|
38913
39567
|
const x = rect.x - grow;
|
|
@@ -39452,7 +40106,8 @@ const modelCardRenderer = {
|
|
|
39452
40106
|
const BOARD_PLAY_MEDIA = "play-media";
|
|
39453
40107
|
function mediaPlayBadgeVisible(item, zoom, options) {
|
|
39454
40108
|
if (!options.materialized) return false;
|
|
39455
|
-
if (item.type === "video"
|
|
40109
|
+
if (item.type === "video") return item.props.time === void 0;
|
|
40110
|
+
if (item.type === "audio") return true;
|
|
39456
40111
|
if (isBoardModelItem(item)) return boardCardDetailed(zoom);
|
|
39457
40112
|
if (item.type !== "task" || !boardCardDetailed(zoom)) return false;
|
|
39458
40113
|
const artifact = featuredTaskArtifact(item.props.snapshot.artifacts);
|
|
@@ -40482,7 +41137,6 @@ const frameCardRenderer = {
|
|
|
40482
41137
|
};
|
|
40483
41138
|
//#endregion
|
|
40484
41139
|
//#region ../sdk/src/board/render/renderers/shape-card-renderer.ts
|
|
40485
|
-
const DEFAULT_ROUNDED_RADIUS = 8;
|
|
40486
41140
|
const partsByContainer$7 = /* @__PURE__ */ new WeakMap();
|
|
40487
41141
|
const pathCache = /* @__PURE__ */ new Map();
|
|
40488
41142
|
function parsedPath(d) {
|
|
@@ -40521,7 +41175,7 @@ function traceShapeOutline(graphics, props, width, height, radius) {
|
|
|
40521
41175
|
graphics.moveTo(width / 2, 0).lineTo(width, height).lineTo(0, height).closePath();
|
|
40522
41176
|
return;
|
|
40523
41177
|
case "rounded":
|
|
40524
|
-
graphics.roundRect(0, 0, width, height, radius ??
|
|
41178
|
+
graphics.roundRect(0, 0, width, height, radius ?? 8);
|
|
40525
41179
|
return;
|
|
40526
41180
|
case "path": {
|
|
40527
41181
|
const parsed = props.path ? parsedPath(props.path) : null;
|
|
@@ -40538,32 +41192,6 @@ function traceShapeOutline(graphics, props, width, height, radius) {
|
|
|
40538
41192
|
else graphics.rect(0, 0, width, height);
|
|
40539
41193
|
}
|
|
40540
41194
|
}
|
|
40541
|
-
function outlinePoints(geometry, width, height, radius) {
|
|
40542
|
-
const p = (x, y) => worldPoint(x, y);
|
|
40543
|
-
switch (geometry) {
|
|
40544
|
-
case "ellipse": {
|
|
40545
|
-
const segments = 64;
|
|
40546
|
-
return Array.from({ length: 65 }, (_, index) => {
|
|
40547
|
-
const angle = -Math.PI / 2 + index / segments * Math.PI * 2;
|
|
40548
|
-
return p(width / 2 + Math.cos(angle) * width / 2, height / 2 + Math.sin(angle) * height / 2);
|
|
40549
|
-
});
|
|
40550
|
-
}
|
|
40551
|
-
case "diamond": return [
|
|
40552
|
-
p(width / 2, 0),
|
|
40553
|
-
p(width, height / 2),
|
|
40554
|
-
p(width / 2, height),
|
|
40555
|
-
p(0, height / 2),
|
|
40556
|
-
p(width / 2, 0)
|
|
40557
|
-
];
|
|
40558
|
-
case "triangle": return [
|
|
40559
|
-
p(width / 2, 0),
|
|
40560
|
-
p(width, height),
|
|
40561
|
-
p(0, height),
|
|
40562
|
-
p(width / 2, 0)
|
|
40563
|
-
];
|
|
40564
|
-
default: return roundRectPoints(width, height, radius);
|
|
40565
|
-
}
|
|
40566
|
-
}
|
|
40567
41195
|
function sync$7(container, item, context) {
|
|
40568
41196
|
const parts = partsByContainer$7.get(container);
|
|
40569
41197
|
if (!parts) return;
|
|
@@ -40603,8 +41231,8 @@ function sync$7(container, item, context) {
|
|
|
40603
41231
|
const partial = style.trim !== void 0 && style.trim < 1;
|
|
40604
41232
|
if (strokeWidth > 0 && (!partial || style.trim)) {
|
|
40605
41233
|
if ((pattern || partial) && props.geometry !== "path") {
|
|
40606
|
-
const radius = style.radius ?? (props.geometry === "rounded" ?
|
|
40607
|
-
tracePolyline(parts.shape, trimPolyline(
|
|
41234
|
+
const radius = style.radius ?? (props.geometry === "rounded" ? 8 : 0);
|
|
41235
|
+
tracePolyline(parts.shape, trimPolyline(shapeOutlinePoints(props.geometry, width, height, radius), style.trim), pattern);
|
|
40608
41236
|
} else traceShapeOutline(parts.shape, props, width, height, style.radius);
|
|
40609
41237
|
parts.shape.stroke({
|
|
40610
41238
|
color: stroke,
|
|
@@ -42168,8 +42796,9 @@ function sync(container, item, context) {
|
|
|
42168
42796
|
text: duration ? `${title} · ${duration}` : title,
|
|
42169
42797
|
width
|
|
42170
42798
|
}, context);
|
|
42799
|
+
const live = context.mediaTexture?.(item.id) ?? null;
|
|
42171
42800
|
const key = context.assetKey(item);
|
|
42172
|
-
const texture = key ? context.getTexture(key) : null;
|
|
42801
|
+
const texture = live ?? (key ? context.getTexture(key) : null);
|
|
42173
42802
|
const elevation = cardElevation(context, item.id);
|
|
42174
42803
|
const sig = [
|
|
42175
42804
|
key ?? "",
|
|
@@ -42178,6 +42807,7 @@ function sync(container, item, context) {
|
|
|
42178
42807
|
height,
|
|
42179
42808
|
elevation,
|
|
42180
42809
|
boardCardDetailed(context.zoom),
|
|
42810
|
+
item.props.time === void 0,
|
|
42181
42811
|
context.themeKey
|
|
42182
42812
|
].join("|");
|
|
42183
42813
|
if (sig === parts.sig) return;
|
|
@@ -42217,7 +42847,7 @@ function sync(container, item, context) {
|
|
|
42217
42847
|
} : context.style);
|
|
42218
42848
|
}
|
|
42219
42849
|
parts.chrome.clear();
|
|
42220
|
-
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);
|
|
42850
|
+
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);
|
|
42221
42851
|
}
|
|
42222
42852
|
function drawFilmRails(graphics, width, height, rail, hole) {
|
|
42223
42853
|
const size = Math.min(FILM_HOLE, rail * .45);
|
|
@@ -42567,6 +43197,7 @@ const itemEnvelope = {
|
|
|
42567
43197
|
y: .5
|
|
42568
43198
|
}).describe("Rotation and scale origin as fractions of the size."),
|
|
42569
43199
|
opacity: ratio.default(1),
|
|
43200
|
+
visible: boolean().optional().describe("false hides the item and its children; key it on a timeline to show the item only for a span."),
|
|
42570
43201
|
style: BoardStyleSchema.default({}),
|
|
42571
43202
|
locked: boolean().optional(),
|
|
42572
43203
|
metadata: record(string(), unknown()).optional()
|
|
@@ -42716,7 +43347,8 @@ const mediaProps = {
|
|
|
42716
43347
|
};
|
|
42717
43348
|
const timedFileProps = {
|
|
42718
43349
|
...mediaProps,
|
|
42719
|
-
time: nonNegative.optional().describe("Playback position in milliseconds; animate props.time to play it on a timeline.")
|
|
43350
|
+
time: nonNegative.optional().describe("Playback position in milliseconds; animate props.time to play it on a timeline. It sounds while its time moves forward."),
|
|
43351
|
+
volume: ratio.optional().describe("Loudness from 0 to 1; defaults to 1. Animate it to fade.")
|
|
42720
43352
|
};
|
|
42721
43353
|
const BoardCropSchema = object({
|
|
42722
43354
|
x: ratio,
|
|
@@ -43453,6 +44085,12 @@ float luminance(vec3 c) { return dot(c, vec3(0.2126, 0.7152, 0.0722)); }
|
|
|
43453
44085
|
//#endregion
|
|
43454
44086
|
//#region ../sdk/src/board/render/shader/program.ts
|
|
43455
44087
|
const BOARD_SHADER_ITERATIONS = 65536;
|
|
44088
|
+
const BOARD_SPRITE_PLACEMENTS = [
|
|
44089
|
+
"uCohubSpriteGeometry",
|
|
44090
|
+
"uCohubSpriteColor",
|
|
44091
|
+
"uCohubSpriteData",
|
|
44092
|
+
"uCohubSpriteRotation"
|
|
44093
|
+
];
|
|
43456
44094
|
const FORBIDDEN = [
|
|
43457
44095
|
[/#\s*(version|extension|pragma|line)\b/, "#version, #extension, #pragma and #line are set by Cohub"],
|
|
43458
44096
|
[/\b(uniform|attribute|varying|layout)\b/, "declare uniforms in shader.uniforms; inputs and outputs belong to Cohub"],
|
|
@@ -43543,7 +44181,8 @@ function declarations(input, stage) {
|
|
|
43543
44181
|
"precision highp float;",
|
|
43544
44182
|
"precision highp int;",
|
|
43545
44183
|
"precision highp sampler2D;",
|
|
43546
|
-
stage === "vertex" ? "#define COHUB_VERTEX 1" : "#define COHUB_FRAGMENT 1"
|
|
44184
|
+
stage === "vertex" ? "#define COHUB_VERTEX 1" : "#define COHUB_FRAGMENT 1",
|
|
44185
|
+
`#define COHUB_SPRITE_COLUMNS 256`
|
|
43547
44186
|
];
|
|
43548
44187
|
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)");
|
|
43549
44188
|
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;");
|
|
@@ -43566,6 +44205,22 @@ vec4 cohubClip(vec2 local) {
|
|
|
43566
44205
|
return vec4((m * vec3(local, 1.0)).xy, 0.0, 1.0);
|
|
43567
44206
|
}`;
|
|
43568
44207
|
const VARYINGS = "vec2 vCohubUv; vec2 vCohubLocal; vec4 vCohubColor; vec4 vCohubData;";
|
|
44208
|
+
function spriteVertex(out) {
|
|
44209
|
+
return `in vec2 aPosition;
|
|
44210
|
+
${CLIP}
|
|
44211
|
+
${out}
|
|
44212
|
+
void cohubEmit(vec2 position, vec2 size, float rotation, vec4 color, vec4 data) {
|
|
44213
|
+
vec2 corner = (aPosition - 0.5) * size;
|
|
44214
|
+
float c = cos(rotation);
|
|
44215
|
+
float r = sin(rotation);
|
|
44216
|
+
vec2 local = position + vec2(corner.x * c - corner.y * r, corner.x * r + corner.y * c);
|
|
44217
|
+
gl_Position = cohubClip(local);
|
|
44218
|
+
vCohubUv = aPosition;
|
|
44219
|
+
vCohubLocal = local;
|
|
44220
|
+
vCohubColor = color;
|
|
44221
|
+
vCohubData = data;
|
|
44222
|
+
}`;
|
|
44223
|
+
}
|
|
43569
44224
|
function vertexMain(kind) {
|
|
43570
44225
|
const out = VARYINGS.split(" ").reduce((text, part, index) => text + (index % 2 ? `${part} ` : `out ${part} `), "");
|
|
43571
44226
|
if (kind === "filter") return `in vec2 aPosition;
|
|
@@ -43582,22 +44237,20 @@ void main() {
|
|
|
43582
44237
|
vCohubColor = vec4(1.0);
|
|
43583
44238
|
vCohubData = vec4(0.0);
|
|
43584
44239
|
}`;
|
|
43585
|
-
if (kind === "
|
|
43586
|
-
${
|
|
43587
|
-
|
|
44240
|
+
if (kind === "placed") return `${spriteVertex(out)}
|
|
44241
|
+
${BOARD_SPRITE_PLACEMENTS.map((name) => `uniform sampler2D ${name};`).join("\n")}
|
|
44242
|
+
void main() {
|
|
44243
|
+
ivec2 at = ivec2(gl_InstanceID % COHUB_SPRITE_COLUMNS, gl_InstanceID / COHUB_SPRITE_COLUMNS);
|
|
44244
|
+
vec4 placed = texelFetch(uCohubSpriteGeometry, at, 0);
|
|
44245
|
+
if (placed.z <= 0.0 || placed.w <= 0.0) { gl_Position = vec4(2.0, 2.0, 2.0, 1.0); return; }
|
|
44246
|
+
cohubEmit(placed.xy, placed.zw, texelFetch(uCohubSpriteRotation, at, 0).x, texelFetch(uCohubSpriteColor, at, 0), texelFetch(uCohubSpriteData, at, 0));
|
|
44247
|
+
}`;
|
|
44248
|
+
if (kind === "sprites") return `${spriteVertex(out)}
|
|
43588
44249
|
void main() {
|
|
43589
44250
|
cohubIterations = 0;
|
|
43590
44251
|
Sprite s = sprite(gl_InstanceID);
|
|
43591
44252
|
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; }
|
|
43592
|
-
|
|
43593
|
-
float c = cos(s.rotation);
|
|
43594
|
-
float r = sin(s.rotation);
|
|
43595
|
-
vec2 local = s.position + vec2(corner.x * c - corner.y * r, corner.x * r + corner.y * c);
|
|
43596
|
-
gl_Position = cohubClip(local);
|
|
43597
|
-
vCohubUv = aPosition;
|
|
43598
|
-
vCohubLocal = local;
|
|
43599
|
-
vCohubColor = s.color;
|
|
43600
|
-
vCohubData = s.data;
|
|
44253
|
+
cohubEmit(s.position, s.size, s.rotation, s.color, s.data);
|
|
43601
44254
|
}`;
|
|
43602
44255
|
return `in vec2 aPosition;
|
|
43603
44256
|
uniform vec4 uCohubGeometry;
|
|
@@ -43613,7 +44266,25 @@ void main() {
|
|
|
43613
44266
|
}`;
|
|
43614
44267
|
}
|
|
43615
44268
|
function fragmentMain(kind) {
|
|
43616
|
-
|
|
44269
|
+
const inputs = VARYINGS.split(" ").reduce((text, part, index) => text + (index % 2 ? `${part} ` : `in ${part} `), "");
|
|
44270
|
+
if (kind === "place") return `uniform int uCohubSpriteCount;
|
|
44271
|
+
layout(location = 0) out vec4 cohubGeometry;
|
|
44272
|
+
layout(location = 1) out vec4 cohubColor;
|
|
44273
|
+
layout(location = 2) out vec4 cohubData;
|
|
44274
|
+
layout(location = 3) out vec4 cohubRotation;
|
|
44275
|
+
void main() {
|
|
44276
|
+
cohubIterations = 0;
|
|
44277
|
+
ivec2 at = ivec2(gl_FragCoord.xy);
|
|
44278
|
+
int id = at.y * COHUB_SPRITE_COLUMNS + at.x;
|
|
44279
|
+
if (id >= uCohubSpriteCount) { cohubGeometry = vec4(0.0); return; }
|
|
44280
|
+
Sprite s = sprite(id);
|
|
44281
|
+
bool shown = s.visible && s.size.x > 0.0 && s.size.y > 0.0;
|
|
44282
|
+
cohubGeometry = shown ? vec4(s.position, s.size) : vec4(0.0);
|
|
44283
|
+
cohubColor = s.color;
|
|
44284
|
+
cohubData = s.data;
|
|
44285
|
+
cohubRotation = vec4(s.rotation, 0.0, 0.0, 0.0);
|
|
44286
|
+
}`;
|
|
44287
|
+
return `${inputs}
|
|
43617
44288
|
${kind === "filter" ? "in vec2 vTextureCoord;" : "uniform vec4 uColor;"}
|
|
43618
44289
|
out vec4 finalColor;
|
|
43619
44290
|
void main() {
|
|
@@ -43629,16 +44300,18 @@ function lineCount(text) {
|
|
|
43629
44300
|
function buildBoardShaderProgram(input) {
|
|
43630
44301
|
const { code, includes } = prepareBoardShaderSource(input.glsl);
|
|
43631
44302
|
const library = includes.map((name) => BOARD_SHADER_LIBRARY[name]).join("\n");
|
|
43632
|
-
const
|
|
43633
|
-
const head = `${declarations(input,
|
|
43634
|
-
const main = name === "vertex" ? vertexMain(input.kind) : fragmentMain(input.kind);
|
|
44303
|
+
const author = (role, main) => {
|
|
44304
|
+
const head = `${declarations(input, role)}\n${library}`;
|
|
43635
44305
|
return {
|
|
43636
44306
|
source: `${head}\n${code}\n${main}\n`,
|
|
43637
44307
|
firstLine: lineCount(head) + 1
|
|
43638
44308
|
};
|
|
43639
44309
|
};
|
|
43640
|
-
const vertex =
|
|
43641
|
-
|
|
44310
|
+
const vertex = input.kind === "sprites" ? author("vertex", vertexMain(input.kind)) : {
|
|
44311
|
+
source: `${declarations(input, "vertex")}\n${vertexMain(input.kind)}\n`,
|
|
44312
|
+
firstLine: 1
|
|
44313
|
+
};
|
|
44314
|
+
const fragment = author(input.kind === "place" ? "vertex" : "fragment", fragmentMain(input.kind));
|
|
43642
44315
|
return {
|
|
43643
44316
|
vertex: vertex.source,
|
|
43644
44317
|
fragment: fragment.source,
|
|
@@ -43655,11 +44328,28 @@ function describeBoardShaderError(log, firstLine, label) {
|
|
|
43655
44328
|
})).slice(0, 4).join("; ") || "the shader failed to compile"}`;
|
|
43656
44329
|
}
|
|
43657
44330
|
function boardShaderStages(shader, label) {
|
|
43658
|
-
const stages = shader.passes.
|
|
43659
|
-
name
|
|
43660
|
-
|
|
43661
|
-
|
|
43662
|
-
|
|
44331
|
+
const stages = shader.passes.flatMap((pass, index) => {
|
|
44332
|
+
const name = `${label} pass ${index + 1}`;
|
|
44333
|
+
if (shader.layer === "filter") return [{
|
|
44334
|
+
name,
|
|
44335
|
+
kind: "filter",
|
|
44336
|
+
glsl: pass.glsl
|
|
44337
|
+
}];
|
|
44338
|
+
if (!pass.sprites) return [{
|
|
44339
|
+
name,
|
|
44340
|
+
kind: "box",
|
|
44341
|
+
glsl: pass.glsl
|
|
44342
|
+
}];
|
|
44343
|
+
return [{
|
|
44344
|
+
name,
|
|
44345
|
+
kind: "place",
|
|
44346
|
+
glsl: pass.glsl
|
|
44347
|
+
}, {
|
|
44348
|
+
name,
|
|
44349
|
+
kind: "placed",
|
|
44350
|
+
glsl: pass.glsl
|
|
44351
|
+
}];
|
|
44352
|
+
});
|
|
43663
44353
|
if (shader.state) stages.push({
|
|
43664
44354
|
name: `${label} state`,
|
|
43665
44355
|
kind: "simulate",
|
|
@@ -43817,6 +44507,51 @@ function check(renderer, program, label) {
|
|
|
43817
44507
|
}
|
|
43818
44508
|
if (error) throw new Error(error);
|
|
43819
44509
|
}
|
|
44510
|
+
const placing = /* @__PURE__ */ new WeakMap();
|
|
44511
|
+
function canPlaceSprites(renderer) {
|
|
44512
|
+
let supported = placing.get(renderer);
|
|
44513
|
+
if (supported === void 0) {
|
|
44514
|
+
const gl = renderer.type === RendererType.WEBGL ? renderer.gl : null;
|
|
44515
|
+
supported = Boolean(gl?.getExtension("EXT_color_buffer_float") && gl.getParameter(gl.MAX_DRAW_BUFFERS) >= BOARD_SPRITE_PLACEMENTS.length);
|
|
44516
|
+
placing.set(renderer, supported);
|
|
44517
|
+
}
|
|
44518
|
+
return supported;
|
|
44519
|
+
}
|
|
44520
|
+
function createPlacement(mesh, uniforms, sprites) {
|
|
44521
|
+
mesh.mesh.blendMode = "none";
|
|
44522
|
+
const height = Math.ceil(sprites / 256);
|
|
44523
|
+
const textures = BOARD_SPRITE_PLACEMENTS.map(() => new TextureSource({
|
|
44524
|
+
width: 256,
|
|
44525
|
+
height,
|
|
44526
|
+
resolution: 1,
|
|
44527
|
+
format: "rgba32float",
|
|
44528
|
+
scaleMode: "nearest",
|
|
44529
|
+
autoGenerateMipmaps: false
|
|
44530
|
+
}));
|
|
44531
|
+
return {
|
|
44532
|
+
mesh,
|
|
44533
|
+
uniforms,
|
|
44534
|
+
target: new RenderTarget({
|
|
44535
|
+
colorTextures: textures,
|
|
44536
|
+
width: 256,
|
|
44537
|
+
height,
|
|
44538
|
+
resolution: 1
|
|
44539
|
+
}),
|
|
44540
|
+
textures
|
|
44541
|
+
};
|
|
44542
|
+
}
|
|
44543
|
+
function destroyPlacement(renderer, placement) {
|
|
44544
|
+
const system = renderer.renderTarget;
|
|
44545
|
+
const gpu = system._gpuRenderTargetHash?.[placement.target.uid];
|
|
44546
|
+
if (gpu && system._gpuRenderTargetHash) {
|
|
44547
|
+
system._gpuRenderTargetHash[placement.target.uid] = null;
|
|
44548
|
+
system.adaptor?.destroyGpuRenderTarget(gpu);
|
|
44549
|
+
}
|
|
44550
|
+
system._renderSurfaceToRenderTargetHash?.delete(placement.target);
|
|
44551
|
+
placement.target.destroy();
|
|
44552
|
+
for (const texture of placement.textures) texture.destroy();
|
|
44553
|
+
destroyBoardShaderMesh(placement.mesh);
|
|
44554
|
+
}
|
|
43820
44555
|
function boardUniforms(parameters, uniforms) {
|
|
43821
44556
|
const vec = (size) => new Float32Array(size);
|
|
43822
44557
|
const fields = {
|
|
@@ -43864,6 +44599,10 @@ function boardUniforms(parameters, uniforms) {
|
|
|
43864
44599
|
value: vec(4),
|
|
43865
44600
|
type: "vec4<f32>"
|
|
43866
44601
|
},
|
|
44602
|
+
uCohubSpriteCount: {
|
|
44603
|
+
value: 0,
|
|
44604
|
+
type: "i32"
|
|
44605
|
+
},
|
|
43867
44606
|
uCohubRegion: {
|
|
43868
44607
|
value: vec(4),
|
|
43869
44608
|
type: "vec4<f32>"
|
|
@@ -43975,6 +44714,8 @@ function createBoardShaderLayer(renderer, shader, parameters, label) {
|
|
|
43975
44714
|
const meshes = [];
|
|
43976
44715
|
const filters = [];
|
|
43977
44716
|
const container = layer === "filter" ? null : new Container({ label: `board-shader-${label}` });
|
|
44717
|
+
const place = canPlaceSprites(renderer);
|
|
44718
|
+
let placementsStale = true;
|
|
43978
44719
|
shader.passes.forEach((pass, index) => {
|
|
43979
44720
|
const name = `${label} pass ${index + 1}`;
|
|
43980
44721
|
if (layer === "filter") {
|
|
@@ -43990,21 +44731,36 @@ function createBoardShaderLayer(renderer, shader, parameters, label) {
|
|
|
43990
44731
|
cohubUniforms: group,
|
|
43991
44732
|
...textures
|
|
43992
44733
|
},
|
|
43993
|
-
padding: 0
|
|
44734
|
+
padding: 0,
|
|
44735
|
+
resolution: "inherit"
|
|
43994
44736
|
});
|
|
43995
44737
|
filters.push(filter);
|
|
43996
44738
|
return;
|
|
43997
44739
|
}
|
|
43998
44740
|
const sprites = pass.sprites ?? 0;
|
|
43999
|
-
|
|
44741
|
+
let placement = null;
|
|
44742
|
+
if (sprites && place) {
|
|
44743
|
+
const own = boardUniforms(parameters, uniforms);
|
|
44744
|
+
placement = createPlacement(boardShaderMesh("board-shader-place", program("place", pass.glsl, name), {
|
|
44745
|
+
cohubUniforms: own,
|
|
44746
|
+
...textures
|
|
44747
|
+
}), own, sprites);
|
|
44748
|
+
}
|
|
44749
|
+
const kind = !sprites ? "box" : placement ? "placed" : "sprites";
|
|
44750
|
+
const resources = {
|
|
44000
44751
|
cohubUniforms: group,
|
|
44001
44752
|
...textures
|
|
44002
|
-
}
|
|
44753
|
+
};
|
|
44754
|
+
placement?.textures.forEach((texture, slot) => {
|
|
44755
|
+
resources[BOARD_SPRITE_PLACEMENTS[slot]] = texture;
|
|
44756
|
+
});
|
|
44757
|
+
const drawn = boardShaderMesh("board-shader", program(kind, pass.glsl, name), resources, boardQuadGeometry(Math.max(1, sprites)));
|
|
44003
44758
|
drawn.mesh.blendMode = pass.blend ?? "normal";
|
|
44004
44759
|
container?.addChild(drawn.mesh);
|
|
44005
44760
|
meshes.push({
|
|
44006
44761
|
...drawn,
|
|
44007
|
-
sprites
|
|
44762
|
+
sprites,
|
|
44763
|
+
placement
|
|
44008
44764
|
});
|
|
44009
44765
|
});
|
|
44010
44766
|
let state = null;
|
|
@@ -44086,6 +44842,53 @@ function createBoardShaderLayer(renderer, shader, parameters, label) {
|
|
|
44086
44842
|
}
|
|
44087
44843
|
target.update();
|
|
44088
44844
|
}
|
|
44845
|
+
function advance(target, state, frame, catchUp) {
|
|
44846
|
+
const wanted = Math.floor(frame.time / STEP_MS);
|
|
44847
|
+
if (wanted < state.steps || state.steps < 0) {
|
|
44848
|
+
for (const texture of [state.read, state.write]) target.render({
|
|
44849
|
+
container: blank,
|
|
44850
|
+
target: texture,
|
|
44851
|
+
clear: true,
|
|
44852
|
+
clearColor: [
|
|
44853
|
+
0,
|
|
44854
|
+
0,
|
|
44855
|
+
0,
|
|
44856
|
+
0
|
|
44857
|
+
]
|
|
44858
|
+
});
|
|
44859
|
+
state.steps = Math.max(0, wanted - MAX_REPLAY);
|
|
44860
|
+
}
|
|
44861
|
+
if (!catchUp && wanted - state.steps > MAX_LAG) state.steps = wanted - STEPS_PER_FRAME;
|
|
44862
|
+
const limit = catchUp ? Number.POSITIVE_INFINITY : STEPS_PER_FRAME;
|
|
44863
|
+
let ran = 0;
|
|
44864
|
+
while (state.steps < wanted && ran < limit) {
|
|
44865
|
+
fill(state.uniforms, frame, {
|
|
44866
|
+
x: 0,
|
|
44867
|
+
y: 0,
|
|
44868
|
+
width: state.write.width,
|
|
44869
|
+
height: state.write.height
|
|
44870
|
+
}, state.steps);
|
|
44871
|
+
state.simulate.shader.resources.uCohubState = state.read.source;
|
|
44872
|
+
target.render({
|
|
44873
|
+
container: state.simulate.mesh,
|
|
44874
|
+
target: state.write,
|
|
44875
|
+
clear: true
|
|
44876
|
+
});
|
|
44877
|
+
[state.read, state.write] = [state.write, state.read];
|
|
44878
|
+
state.steps++;
|
|
44879
|
+
ran++;
|
|
44880
|
+
}
|
|
44881
|
+
const source = state.read.source;
|
|
44882
|
+
for (const { shader, placement } of meshes) {
|
|
44883
|
+
shader.resources.uCohubState = source;
|
|
44884
|
+
if (placement) placement.mesh.shader.resources.uCohubState = source;
|
|
44885
|
+
}
|
|
44886
|
+
for (const filter of filters) filter.resources.uCohubState = source;
|
|
44887
|
+
return {
|
|
44888
|
+
ran,
|
|
44889
|
+
behind: state.steps < wanted
|
|
44890
|
+
};
|
|
44891
|
+
}
|
|
44089
44892
|
return {
|
|
44090
44893
|
layer,
|
|
44091
44894
|
container,
|
|
@@ -44093,21 +44896,35 @@ function createBoardShaderLayer(renderer, shader, parameters, label) {
|
|
|
44093
44896
|
surfaces,
|
|
44094
44897
|
animated: hasState,
|
|
44095
44898
|
update(frame) {
|
|
44096
|
-
fill(group, frame, frame.region);
|
|
44097
|
-
time = frame.time;
|
|
44098
|
-
last = frame;
|
|
44099
44899
|
if (frame.quality !== quality) {
|
|
44100
44900
|
quality = frame.quality;
|
|
44101
44901
|
for (const { geometry, sprites } of meshes) if (sprites) geometry.instanceCount = Math.max(1, Math.round(sprites * quality));
|
|
44102
44902
|
}
|
|
44903
|
+
fill(group, frame, frame.region);
|
|
44904
|
+
for (const { geometry, placement } of meshes) {
|
|
44905
|
+
if (!placement) continue;
|
|
44906
|
+
placement.uniforms.uniforms.uCohubSpriteCount = geometry.instanceCount;
|
|
44907
|
+
fill(placement.uniforms, frame, {
|
|
44908
|
+
x: 0,
|
|
44909
|
+
y: 0,
|
|
44910
|
+
width: 256,
|
|
44911
|
+
height: Math.ceil(geometry.instanceCount / 256)
|
|
44912
|
+
});
|
|
44913
|
+
}
|
|
44914
|
+
time = frame.time;
|
|
44915
|
+
last = frame;
|
|
44916
|
+
placementsStale = true;
|
|
44103
44917
|
},
|
|
44104
44918
|
prepare(target, options) {
|
|
44105
|
-
if (!
|
|
44106
|
-
const
|
|
44107
|
-
|
|
44108
|
-
|
|
44109
|
-
|
|
44110
|
-
|
|
44919
|
+
if (!last) return false;
|
|
44920
|
+
const stepped = state ? advance(target, state, last, options?.catchUp === true) : {
|
|
44921
|
+
ran: 0,
|
|
44922
|
+
behind: false
|
|
44923
|
+
};
|
|
44924
|
+
if (placementsStale || stepped.ran) {
|
|
44925
|
+
for (const { placement } of meshes) if (placement) target.render({
|
|
44926
|
+
container: placement.mesh.mesh,
|
|
44927
|
+
target: placement.target,
|
|
44111
44928
|
clear: true,
|
|
44112
44929
|
clearColor: [
|
|
44113
44930
|
0,
|
|
@@ -44116,38 +44933,17 @@ function createBoardShaderLayer(renderer, shader, parameters, label) {
|
|
|
44116
44933
|
0
|
|
44117
44934
|
]
|
|
44118
44935
|
});
|
|
44119
|
-
|
|
44120
|
-
}
|
|
44121
|
-
if (!options?.catchUp && wanted - state.steps > MAX_LAG) state.steps = wanted - STEPS_PER_FRAME;
|
|
44122
|
-
const limit = options?.catchUp ? Number.POSITIVE_INFINITY : STEPS_PER_FRAME;
|
|
44123
|
-
let ran = 0;
|
|
44124
|
-
while (state.steps < wanted && ran < limit) {
|
|
44125
|
-
fill(state.uniforms, last, {
|
|
44126
|
-
x: 0,
|
|
44127
|
-
y: 0,
|
|
44128
|
-
width: state.write.width,
|
|
44129
|
-
height: state.write.height
|
|
44130
|
-
}, state.steps);
|
|
44131
|
-
state.simulate.shader.resources.uCohubState = state.read.source;
|
|
44132
|
-
target.render({
|
|
44133
|
-
container: state.simulate.mesh,
|
|
44134
|
-
target: state.write,
|
|
44135
|
-
clear: true
|
|
44136
|
-
});
|
|
44137
|
-
[state.read, state.write] = [state.write, state.read];
|
|
44138
|
-
state.steps++;
|
|
44139
|
-
ran++;
|
|
44936
|
+
placementsStale = false;
|
|
44140
44937
|
}
|
|
44141
|
-
|
|
44142
|
-
for (const { shader } of meshes) shader.resources.uCohubState = source;
|
|
44143
|
-
for (const filter of filters) filter.resources.uCohubState = source;
|
|
44144
|
-
return state.steps < wanted;
|
|
44938
|
+
return stepped.behind;
|
|
44145
44939
|
},
|
|
44146
44940
|
setSurfaces(texture, region) {
|
|
44147
|
-
|
|
44148
|
-
|
|
44149
|
-
|
|
44150
|
-
|
|
44941
|
+
const shaders = [...meshes.flatMap(({ shader, placement }) => placement ? [shader, placement.mesh.shader] : [shader]), ...filters];
|
|
44942
|
+
if (state) shaders.push(state.simulate.shader);
|
|
44943
|
+
for (const target of shaders) target.resources.uCohubSurfaces = texture.source;
|
|
44944
|
+
const groups = [group, ...meshes.flatMap(({ placement }) => placement ? [placement.uniforms] : [])];
|
|
44945
|
+
if (state) groups.push(state.uniforms);
|
|
44946
|
+
for (const target of groups) {
|
|
44151
44947
|
setUniform(target, "uCohubSurfaceRegion", [
|
|
44152
44948
|
region.x,
|
|
44153
44949
|
region.y,
|
|
@@ -44156,9 +44952,13 @@ function createBoardShaderLayer(renderer, shader, parameters, label) {
|
|
|
44156
44952
|
]);
|
|
44157
44953
|
target.update();
|
|
44158
44954
|
}
|
|
44955
|
+
placementsStale = true;
|
|
44159
44956
|
},
|
|
44160
44957
|
destroy() {
|
|
44161
|
-
for (const drawn of meshes)
|
|
44958
|
+
for (const drawn of meshes) {
|
|
44959
|
+
destroyBoardShaderMesh(drawn);
|
|
44960
|
+
if (drawn.placement) destroyPlacement(renderer, drawn.placement);
|
|
44961
|
+
}
|
|
44162
44962
|
container?.destroy();
|
|
44163
44963
|
for (const filter of filters) filter.destroy();
|
|
44164
44964
|
blank.destroy();
|
|
@@ -44392,35 +45192,49 @@ const SKIPPED = /* @__PURE__ */ new Set([
|
|
|
44392
45192
|
"frame",
|
|
44393
45193
|
"arrow",
|
|
44394
45194
|
"draw",
|
|
44395
|
-
"effect"
|
|
45195
|
+
"effect",
|
|
45196
|
+
"text"
|
|
44396
45197
|
]);
|
|
45198
|
+
const LIGHT_BLENDS = /* @__PURE__ */ new Set(["screen", "add"]);
|
|
44397
45199
|
const SURFACE_EDGE = 512;
|
|
45200
|
+
const SURFACE_MARGIN = .25;
|
|
45201
|
+
const SURFACE_COARSEN = 1.5;
|
|
45202
|
+
function surfaceOutline(item) {
|
|
45203
|
+
const { width, height } = item.frame;
|
|
45204
|
+
const radius = item.style?.radius;
|
|
45205
|
+
if (item.type === "shape") {
|
|
45206
|
+
const { geometry } = item.props;
|
|
45207
|
+
return shapeOutlinePoints(geometry, width, height, radius ?? (geometry === "rounded" ? 8 : 0));
|
|
45208
|
+
}
|
|
45209
|
+
return roundRectPoints(width, height, radius ?? 0);
|
|
45210
|
+
}
|
|
44398
45211
|
function boardSurfaceOutlines(scene, owner, world, worldToLocal, candidates) {
|
|
44399
45212
|
const prefix = scriptTemporaryPrefix(owner);
|
|
44400
45213
|
const outlines = [];
|
|
44401
45214
|
const items = candidates ? [...candidates].map((id) => scene.get(id)).filter((item) => Boolean(item)) : scene.items;
|
|
44402
45215
|
for (const item of items) {
|
|
44403
|
-
if (item.id === owner || SKIPPED.has(item.type) || item.id.startsWith(prefix) || scene.opacity(item.id) <= 0) continue;
|
|
45216
|
+
if (item.id === owner || SKIPPED.has(item.type) || LIGHT_BLENDS.has(item.style?.blend ?? "") || item.id.startsWith(prefix) || scene.opacity(item.id) <= 0) continue;
|
|
44404
45217
|
if (!rectsIntersect(itemBounds(item.frame), world)) continue;
|
|
44405
|
-
const
|
|
45218
|
+
const { width, height } = item.frame;
|
|
44406
45219
|
const points = [];
|
|
44407
|
-
|
|
44408
|
-
const
|
|
44409
|
-
return [.5 + Math.cos(angle) / 2, .5 + Math.sin(angle) / 2];
|
|
44410
|
-
}) : [
|
|
44411
|
-
[0, 0],
|
|
44412
|
-
[1, 0],
|
|
44413
|
-
[1, 1],
|
|
44414
|
-
[0, 1]
|
|
44415
|
-
];
|
|
44416
|
-
for (const [u, v] of corners) {
|
|
44417
|
-
const local = applyMatrix$1(worldToLocal, framePoint(item.frame, u, v));
|
|
45220
|
+
for (const point of surfaceOutline(item)) {
|
|
45221
|
+
const local = applyMatrix$1(worldToLocal, framePoint(item.frame, width ? point.x / width : 0, height ? point.y / height : 0));
|
|
44418
45222
|
points.push(local.x, local.y);
|
|
44419
45223
|
}
|
|
44420
45224
|
outlines.push(points);
|
|
44421
45225
|
}
|
|
44422
45226
|
return outlines;
|
|
44423
45227
|
}
|
|
45228
|
+
function boardSurfaceRegion(previous, region, margin) {
|
|
45229
|
+
if (!margin) return region;
|
|
45230
|
+
if (previous && previous.x <= region.x && previous.y <= region.y && previous.x + previous.width >= region.x + region.width && previous.y + previous.height >= region.y + region.height && previous.width <= region.width * (1 + 2 * margin) * SURFACE_COARSEN) return previous;
|
|
45231
|
+
return {
|
|
45232
|
+
x: region.x - region.width * margin,
|
|
45233
|
+
y: region.y - region.height * margin,
|
|
45234
|
+
width: region.width * (1 + 2 * margin),
|
|
45235
|
+
height: region.height * (1 + 2 * margin)
|
|
45236
|
+
};
|
|
45237
|
+
}
|
|
44424
45238
|
function parameterValues(parameters, params, color) {
|
|
44425
45239
|
const values = {};
|
|
44426
45240
|
for (const [name, spec] of Object.entries(parameters ?? {})) {
|
|
@@ -44510,7 +45324,9 @@ function createBoardShaderLayers() {
|
|
|
44510
45324
|
uniforms: output.uniforms
|
|
44511
45325
|
});
|
|
44512
45326
|
if (entry.layer.surfaces) {
|
|
44513
|
-
const {
|
|
45327
|
+
const { localToWorld } = placement;
|
|
45328
|
+
const margin = owner.root ? SURFACE_MARGIN : 0;
|
|
45329
|
+
const region = boardSurfaceRegion(entry.surfaces?.region ?? null, placement.region, margin);
|
|
44514
45330
|
const corners = [
|
|
44515
45331
|
applyMatrix$1(localToWorld, region),
|
|
44516
45332
|
applyMatrix$1(localToWorld, {
|
|
@@ -44534,7 +45350,7 @@ function createBoardShaderLayers() {
|
|
|
44534
45350
|
width: Math.max(...xs) - Math.min(...xs),
|
|
44535
45351
|
height: Math.max(...ys) - Math.min(...ys)
|
|
44536
45352
|
};
|
|
44537
|
-
const edge = Math.max(64, Math.round(SURFACE_EDGE * host.quality));
|
|
45353
|
+
const edge = Math.max(64, Math.round(SURFACE_EDGE * (1 + 2 * margin) * host.quality));
|
|
44538
45354
|
const key = `${[
|
|
44539
45355
|
region.x,
|
|
44540
45356
|
region.y,
|
|
@@ -46174,13 +46990,6 @@ const STRUCTURAL_KEYS = [
|
|
|
46174
46990
|
"locked",
|
|
46175
46991
|
"metadata"
|
|
46176
46992
|
];
|
|
46177
|
-
function newBoardTrackId(tracks, target, property) {
|
|
46178
|
-
const id = `${target}-${property.replaceAll(".", "-")}`;
|
|
46179
|
-
return id.length <= 160 && !Object.hasOwn(tracks, id) ? id : createBoardEntityId();
|
|
46180
|
-
}
|
|
46181
|
-
function findBoardKeyTrack(tracks, target, property) {
|
|
46182
|
-
return Object.entries(tracks).find(([, track]) => track.target === target && track.property === property && track.composite === "replace");
|
|
46183
|
-
}
|
|
46184
46993
|
function keyframe(animations, playhead, recording, id, property, value, storedValue) {
|
|
46185
46994
|
const animation = animations[playhead.animationId];
|
|
46186
46995
|
if (!animation) return false;
|
|
@@ -46687,14 +47496,20 @@ function createAnimationModule(ctx) {
|
|
|
46687
47496
|
animation
|
|
46688
47497
|
} : null;
|
|
46689
47498
|
}
|
|
46690
|
-
function commitAnimation(id, animation) {
|
|
46691
|
-
|
|
47499
|
+
function commitAnimation(id, animation, items = {}) {
|
|
47500
|
+
if (animation === state.base.animations[id] && Object.keys(items).length === 0) return true;
|
|
47501
|
+
const next = {
|
|
46692
47502
|
...state.base,
|
|
47503
|
+
items: {
|
|
47504
|
+
...state.base.items,
|
|
47505
|
+
...items
|
|
47506
|
+
},
|
|
46693
47507
|
animations: {
|
|
46694
47508
|
...state.base.animations,
|
|
46695
47509
|
[id]: animation
|
|
46696
47510
|
}
|
|
46697
|
-
}
|
|
47511
|
+
};
|
|
47512
|
+
const patch = diffBoardEdits(state.base, next, Object.keys(items));
|
|
46698
47513
|
try {
|
|
46699
47514
|
ctx.document.commitPatch(patch)?.catch(() => {});
|
|
46700
47515
|
return true;
|
|
@@ -47010,7 +47825,78 @@ function createAnimationModule(ctx) {
|
|
|
47010
47825
|
});
|
|
47011
47826
|
return id;
|
|
47012
47827
|
}
|
|
47828
|
+
function placeOnTimeline(targets, at, options = {}) {
|
|
47829
|
+
const found = editing();
|
|
47830
|
+
if (!found) return false;
|
|
47831
|
+
let animation = found.animation;
|
|
47832
|
+
let cursor = Math.max(0, at);
|
|
47833
|
+
for (const target of targets) {
|
|
47834
|
+
if (target === found.id || (state.base.animations[target] ? plays(target, found.id) : !state.base.items[target])) continue;
|
|
47835
|
+
animation = boardPlaceTarget(state.base, animation, target, {
|
|
47836
|
+
...options,
|
|
47837
|
+
at: cursor
|
|
47838
|
+
});
|
|
47839
|
+
const span = boardTargetSpan(state.base, animation, target);
|
|
47840
|
+
if (!options.together && span) cursor = span.end;
|
|
47841
|
+
}
|
|
47842
|
+
return commitAnimation(found.id, animation);
|
|
47843
|
+
}
|
|
47844
|
+
function shiftOnTimeline(targets, delta) {
|
|
47845
|
+
const found = editing();
|
|
47846
|
+
if (found) commitAnimation(found.id, boardShiftTargets(state.base, found.animation, targets, delta));
|
|
47847
|
+
}
|
|
47848
|
+
function trimOnTimeline(target, edge, at) {
|
|
47849
|
+
const found = editing();
|
|
47850
|
+
if (found) commitAnimation(found.id, boardTrimTarget(state.base, found.animation, target, edge, at));
|
|
47851
|
+
}
|
|
47852
|
+
function removeFromTimeline(targets) {
|
|
47853
|
+
const found = editing();
|
|
47854
|
+
if (!found) return;
|
|
47855
|
+
let animation = found.animation;
|
|
47856
|
+
for (const target of targets) animation = boardRemoveTarget(animation, target);
|
|
47857
|
+
commitAnimation(found.id, animation);
|
|
47858
|
+
}
|
|
47859
|
+
function splitAtPlayhead(targets) {
|
|
47860
|
+
const found = editing();
|
|
47861
|
+
if (!found) return [];
|
|
47862
|
+
let animation = found.animation;
|
|
47863
|
+
const items = {};
|
|
47864
|
+
const roots = [];
|
|
47865
|
+
for (const target of ctx.query.rootsOf(targets)) {
|
|
47866
|
+
if (!state.base.items[target]) continue;
|
|
47867
|
+
const subtree = [...ctx.query.withSubtrees([target])];
|
|
47868
|
+
const source = Object.fromEntries(subtree.flatMap((id) => state.base.items[id] ? [[id, state.base.items[id]]] : []));
|
|
47869
|
+
const idMap = new Map(subtree.map((id) => [id, createBoardItemId()]));
|
|
47870
|
+
const split = boardSplitTarget(state.base, animation, target, idMap, found.time);
|
|
47871
|
+
if (!split) continue;
|
|
47872
|
+
animation = split;
|
|
47873
|
+
Object.assign(items, remapItems(source, idMap));
|
|
47874
|
+
const copy = idMap.get(target);
|
|
47875
|
+
const { parent } = state.base.items[target];
|
|
47876
|
+
if (parent) items[copy] = {
|
|
47877
|
+
...items[copy],
|
|
47878
|
+
parent
|
|
47879
|
+
};
|
|
47880
|
+
roots.push(copy);
|
|
47881
|
+
}
|
|
47882
|
+
return roots.length && commitAnimation(found.id, animation, items) ? roots : [];
|
|
47883
|
+
}
|
|
47884
|
+
function insertTime(at, length) {
|
|
47885
|
+
const found = editing();
|
|
47886
|
+
if (found) commitAnimation(found.id, boardInsertTime(state.base, found.animation, at, length));
|
|
47887
|
+
}
|
|
47888
|
+
function removeTime(from, to) {
|
|
47889
|
+
const found = editing();
|
|
47890
|
+
if (found) commitAnimation(found.id, boardRemoveTime(state.base, found.animation, from, to));
|
|
47891
|
+
}
|
|
47013
47892
|
return {
|
|
47893
|
+
placeOnTimeline,
|
|
47894
|
+
shiftOnTimeline,
|
|
47895
|
+
trimOnTimeline,
|
|
47896
|
+
removeFromTimeline,
|
|
47897
|
+
splitAtPlayhead,
|
|
47898
|
+
insertTime,
|
|
47899
|
+
removeTime,
|
|
47014
47900
|
setPlayhead,
|
|
47015
47901
|
setRecording,
|
|
47016
47902
|
keyProperty,
|
|
@@ -49498,7 +50384,7 @@ function createQueryModule(ctx) {
|
|
|
49498
50384
|
ensureSpatial();
|
|
49499
50385
|
for (const id of spatial.idsAtPoint(point)) {
|
|
49500
50386
|
const item = state.scene.get(id);
|
|
49501
|
-
if (!state.base.items[id] || item?.type !== "frame" || exclude?.has(id)) continue;
|
|
50387
|
+
if (!state.base.items[id] || item?.type !== "frame" || exclude?.has(id) || !state.scene.shown(id)) continue;
|
|
49502
50388
|
if (registry.hitTest(item, point)) return item;
|
|
49503
50389
|
}
|
|
49504
50390
|
return null;
|
|
@@ -49525,6 +50411,7 @@ function createQueryModule(ctx) {
|
|
|
49525
50411
|
return enclosed.sort((a, b) => scene.indexOf(a.id) - scene.indexOf(b.id));
|
|
49526
50412
|
}
|
|
49527
50413
|
function hitsItem(item, point) {
|
|
50414
|
+
if (!state.scene.shown(item.id) && !state.selection.includes(item.id)) return false;
|
|
49528
50415
|
if (item.type === "arrow") return distanceToArrow(resolveSceneArrow(item, state.scene), point) <= arrowHitRadius(item.style.strokeWidth) / Math.min(1, state.camera.zoom);
|
|
49529
50416
|
return registry.hitTest(item, point);
|
|
49530
50417
|
}
|
|
@@ -49558,7 +50445,7 @@ function createQueryModule(ctx) {
|
|
|
49558
50445
|
height: reach * 2
|
|
49559
50446
|
})) {
|
|
49560
50447
|
const item = state.scene.get(id);
|
|
49561
|
-
if (!pickable(item, id)) continue;
|
|
50448
|
+
if (!pickable(item, id) || !(state.scene.shown(id) || state.selection.includes(id))) continue;
|
|
49562
50449
|
const distance = item.type === "arrow" ? distanceToArrow(resolveSceneArrow(item, state.scene), point) - arrowHitRadius(item.style.strokeWidth) / Math.min(1, state.camera.zoom) : distanceToFrame(item.frame, point);
|
|
49563
50450
|
if (distance > 0 && distance < best) {
|
|
49564
50451
|
nearest = item;
|
|
@@ -49580,7 +50467,7 @@ function createQueryModule(ctx) {
|
|
|
49580
50467
|
const candidates = selection.length === 1 ? [...selection, ...nearby] : nearby;
|
|
49581
50468
|
for (const id of new Set(candidates)) {
|
|
49582
50469
|
const item = scene.get(id);
|
|
49583
|
-
if (!item || !state.base.items[id] || isLocked(item)) continue;
|
|
50470
|
+
if (!item || !state.base.items[id] || isLocked(item) || !scene.shown(id)) continue;
|
|
49584
50471
|
if (item.type === "frame" && rectContainsPoint(frameLabelHitRect(item.frame, frameLabelSize), point)) return item;
|
|
49585
50472
|
if (item.type === "arrow") {
|
|
49586
50473
|
const resolved = resolveSceneArrow(item, scene);
|
|
@@ -49774,6 +50661,31 @@ function createSelectionModule(ctx) {
|
|
|
49774
50661
|
if (ids.length < 3) return;
|
|
49775
50662
|
ctx.document.commitItems(placed(distributeFrames(framesFor(ids), axis)));
|
|
49776
50663
|
}
|
|
50664
|
+
function framed() {
|
|
50665
|
+
return movable().flatMap((id) => {
|
|
50666
|
+
const item = state.scene.get(id);
|
|
50667
|
+
const parent = item?.parent ? state.scene.get(item.parent) : void 0;
|
|
50668
|
+
return item && parent?.type === "frame" && hasAuthoredSize(item.type) ? [[id, parent.frame]] : [];
|
|
50669
|
+
});
|
|
50670
|
+
}
|
|
50671
|
+
function fillFrame() {
|
|
50672
|
+
const frames = /* @__PURE__ */ new Map();
|
|
50673
|
+
for (const [id, outer] of framed()) {
|
|
50674
|
+
const own = state.scene.get(id)?.frame;
|
|
50675
|
+
if (!own?.width || !own.height) continue;
|
|
50676
|
+
const scale = Math.max(outer.width / own.width, outer.height / own.height);
|
|
50677
|
+
const width = own.width * scale;
|
|
50678
|
+
const height = own.height * scale;
|
|
50679
|
+
frames.set(id, {
|
|
50680
|
+
x: outer.x + (outer.width - width) / 2,
|
|
50681
|
+
y: outer.y + (outer.height - height) / 2,
|
|
50682
|
+
width,
|
|
50683
|
+
height,
|
|
50684
|
+
rotation: outer.rotation
|
|
50685
|
+
});
|
|
50686
|
+
}
|
|
50687
|
+
ctx.document.commitItems(placed(frames));
|
|
50688
|
+
}
|
|
49777
50689
|
function edit(update, ids = ctx.query.unlockedIds(state.selection)) {
|
|
49778
50690
|
const changes = /* @__PURE__ */ new Map();
|
|
49779
50691
|
for (const id of ids) {
|
|
@@ -49890,6 +50802,8 @@ function createSelectionModule(ctx) {
|
|
|
49890
50802
|
nudge,
|
|
49891
50803
|
align,
|
|
49892
50804
|
distribute,
|
|
50805
|
+
canFillFrame: () => framed().length > 0,
|
|
50806
|
+
fillFrame,
|
|
49893
50807
|
toggleLock,
|
|
49894
50808
|
setColor,
|
|
49895
50809
|
setStyle,
|
|
@@ -50373,6 +51287,10 @@ function createBoardEditor(options) {
|
|
|
50373
51287
|
nudgeSelection: selection.nudge,
|
|
50374
51288
|
alignSelection: selection.align,
|
|
50375
51289
|
distributeSelection: selection.distribute,
|
|
51290
|
+
get canFillFrame() {
|
|
51291
|
+
return read(["selection", "scene"], () => selection.canFillFrame());
|
|
51292
|
+
},
|
|
51293
|
+
fillFrame: selection.fillFrame,
|
|
50376
51294
|
toggleSelectionLock: selection.toggleLock,
|
|
50377
51295
|
setSelectionColor: selection.setColor,
|
|
50378
51296
|
setSelectionStyle: selection.setStyle,
|
|
@@ -50422,6 +51340,13 @@ function createBoardEditor(options) {
|
|
|
50422
51340
|
deleteAnimation: animation.deleteAnimation,
|
|
50423
51341
|
createAnimation: animation.createAnimation,
|
|
50424
51342
|
createSequence: animation.createSequence,
|
|
51343
|
+
placeOnTimeline: animation.placeOnTimeline,
|
|
51344
|
+
shiftOnTimeline: animation.shiftOnTimeline,
|
|
51345
|
+
trimOnTimeline: animation.trimOnTimeline,
|
|
51346
|
+
removeFromTimeline: animation.removeFromTimeline,
|
|
51347
|
+
splitAtPlayhead: animation.splitAtPlayhead,
|
|
51348
|
+
insertTime: animation.insertTime,
|
|
51349
|
+
removeTime: animation.removeTime,
|
|
50425
51350
|
pointerDown: interaction.pointerDown,
|
|
50426
51351
|
pointerMove: interaction.pointerMove,
|
|
50427
51352
|
pointerUp: interaction.pointerUp,
|
|
@@ -51428,4 +52353,4 @@ async function createBoardScriptHarness(options) {
|
|
|
51428
52353
|
};
|
|
51429
52354
|
}
|
|
51430
52355
|
//#endregion
|
|
51431
|
-
export { BOARD_SCRIPT_DRAWING_EXAMPLE, BOARD_SCRIPT_RAIN_EXAMPLE, boardAssetKey, boardAssetKeySource,
|
|
52356
|
+
export { BOARD_SCRIPT_DRAWING_EXAMPLE, BOARD_SCRIPT_RAIN_EXAMPLE, boardAssetKey, boardAssetKeySource, boardFrameRegions, boardMediaRate, boardMediaSpans, boardPathTrack, boardPlacePatch, boardRegionStep, boardRenderTheme, boardScriptAttachments, boardSequence, boardSequencePatch, boardShaderParameters, boardTextureEdge, boardTexturePixels, boardTimedMedia, buildBoardScene, checkBoardShader, createBoardAnimationSampler, createBoardRenderSampler, createBoardScriptHarness, createNodeBoardRenderer, createNodeBoardScriptHost, describeBoardExportWarning, exportBoardImageBytes, hasBoardScripts, inspectBoardItems, inspectBoardScene, measureBoardText, parseBoardDocument, planBoardExport, prepareBoardExport, selectBoardExportAssets };
|