@songsid/agend 2.4.0-beta.14 → 2.4.0-beta.16
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/accounts-profiles.d.ts +1 -1
- package/dist/accounts-view.d.ts +3 -0
- package/dist/accounts-view.js.map +1 -1
- package/dist/auth-api.js +5 -0
- package/dist/auth-api.js.map +1 -1
- package/dist/backend/claude-code.d.ts +6 -1
- package/dist/backend/claude-code.js +63 -8
- package/dist/backend/claude-code.js.map +1 -1
- package/dist/backend/kiro.js +6 -1
- package/dist/backend/kiro.js.map +1 -1
- package/dist/backend/types.d.ts +2 -0
- package/dist/backend/types.js.map +1 -1
- package/dist/backend-command.d.ts +4 -2
- package/dist/backend-command.js +3 -0
- package/dist/backend-command.js.map +1 -1
- package/dist/browser-backend-signins.d.ts +1 -0
- package/dist/browser-backend-signins.js +3 -1
- package/dist/browser-backend-signins.js.map +1 -1
- package/dist/build-provenance.json +1 -1
- package/dist/classic-channel-manager.d.ts +1 -0
- package/dist/classic-channel-manager.js +4 -1
- package/dist/classic-channel-manager.js.map +1 -1
- package/dist/claude-credential-change.d.ts +22 -0
- package/dist/claude-credential-change.js +47 -0
- package/dist/claude-credential-change.js.map +1 -0
- package/dist/claude-credential-launch.d.ts +62 -0
- package/dist/claude-credential-launch.js +304 -0
- package/dist/claude-credential-launch.js.map +1 -0
- package/dist/claude-credential-runner.d.ts +1 -0
- package/dist/claude-credential-runner.js +56 -0
- package/dist/claude-credential-runner.js.map +1 -0
- package/dist/claude-credential-vault.d.ts +51 -0
- package/dist/claude-credential-vault.js +252 -0
- package/dist/claude-credential-vault.js.map +1 -0
- package/dist/claude-setup-token-transport.d.ts +9 -0
- package/dist/claude-setup-token-transport.js +82 -0
- package/dist/claude-setup-token-transport.js.map +1 -0
- package/dist/claude-setup-token.d.ts +51 -0
- package/dist/claude-setup-token.js +83 -0
- package/dist/claude-setup-token.js.map +1 -0
- package/dist/cli-audited.js +7 -6
- package/dist/cli-audited.js.map +1 -1
- package/dist/command-report.d.ts +11 -0
- package/dist/command-report.js +2 -0
- package/dist/command-report.js.map +1 -0
- package/dist/config-validator.js +9 -0
- package/dist/config-validator.js.map +1 -1
- package/dist/config.js +4 -2
- package/dist/config.js.map +1 -1
- package/dist/contact-auth-api.d.ts +2 -1
- package/dist/contact-auth-api.js +15 -5
- package/dist/contact-auth-api.js.map +1 -1
- package/dist/contact-auth-policy.d.ts +5 -0
- package/dist/contact-auth-policy.js +2 -0
- package/dist/contact-auth-policy.js.map +1 -1
- package/dist/contact-auth-store.d.ts +12 -1
- package/dist/contact-auth-store.js +67 -5
- package/dist/contact-auth-store.js.map +1 -1
- package/dist/contact-auth-types.d.ts +27 -1
- package/dist/contact-auth-types.js.map +1 -1
- package/dist/daemon.d.ts +5 -0
- package/dist/daemon.js +59 -3
- package/dist/daemon.js.map +1 -1
- package/dist/fleet-level-config.d.ts +1 -1
- package/dist/fleet-level-config.js +1 -0
- package/dist/fleet-level-config.js.map +1 -1
- package/dist/fleet-manager.d.ts +48 -3
- package/dist/fleet-manager.js +446 -27
- package/dist/fleet-manager.js.map +1 -1
- package/dist/general-knowledge/skills/cross-instance-messaging/SKILL.md +16 -6
- package/dist/general-knowledge/skills/web-appearance/SKILL.md +4 -1
- package/dist/general-knowledge/skills/web-dashboard/SKILL.md +23 -5
- package/dist/host-monitoring-config.d.ts +14 -0
- package/dist/host-monitoring-config.js +31 -0
- package/dist/host-monitoring-config.js.map +1 -0
- package/dist/hub/group-policy/resources.d.ts +1 -1
- package/dist/instance-config-impact.js +1 -1
- package/dist/instance-config-impact.js.map +1 -1
- package/dist/instructions.js +1 -0
- package/dist/instructions.js.map +1 -1
- package/dist/locale.d.ts +2 -0
- package/dist/locale.js +19 -1
- package/dist/locale.js.map +1 -1
- package/dist/needs-you-hub.js +3 -0
- package/dist/needs-you-hub.js.map +1 -1
- package/dist/needs-you.d.ts +2 -0
- package/dist/needs-you.js.map +1 -1
- package/dist/office-share-page.js +1 -1
- package/dist/office-share-page.js.map +1 -1
- package/dist/profile-signins.d.ts +1 -0
- package/dist/profile-signins.js +3 -1
- package/dist/profile-signins.js.map +1 -1
- package/dist/public-web-gateway.js +2 -0
- package/dist/public-web-gateway.js.map +1 -1
- package/dist/public-web-link.d.ts +21 -2
- package/dist/public-web-link.js +22 -2
- package/dist/public-web-link.js.map +1 -1
- package/dist/settings-api.d.ts +12 -0
- package/dist/settings-api.js +146 -7
- package/dist/settings-api.js.map +1 -1
- package/dist/settings-change.js +2 -0
- package/dist/settings-change.js.map +1 -1
- package/dist/settings-effect.js +13 -1
- package/dist/settings-effect.js.map +1 -1
- package/dist/topic-commands.d.ts +7 -1
- package/dist/topic-commands.js +98 -88
- package/dist/topic-commands.js.map +1 -1
- package/dist/types.d.ts +2 -0
- package/dist/ui/accounts-view.js +12 -6
- package/dist/ui/backend-signin.js +3 -1
- package/dist/ui/chat-commands.js +2 -0
- package/dist/ui/chat-popout-transport.js +49 -19
- package/dist/ui/chat-popout.js +15 -1
- package/dist/ui/chat-store.js +1 -1
- package/dist/ui/claude-credentials.js +112 -0
- package/dist/ui/claude-setup-token.js +36 -0
- package/dist/ui/contact-auth-client.js +9 -2
- package/dist/ui/contact-auth-strings.js +78 -16
- package/dist/ui/contact-authorizations.js +47 -26
- package/dist/ui/contact-needs.js +22 -6
- package/dist/ui/contact-permissions.js +55 -10
- package/dist/ui/contact-tool-groups.js +39 -0
- package/dist/ui/fleet-canvas.js +3 -2
- package/dist/ui/fleet-office-card.js +414 -41
- package/dist/ui/fleet-office-dialogue.js +3 -3
- package/dist/ui/fleet-office-pack.d.ts +67 -1
- package/dist/ui/fleet-office-pack.js +412 -18
- package/dist/ui/fleet-office-play.js +262 -3
- package/dist/ui/fleet-office-skin.js +67 -20
- package/dist/ui/fleet-office-zones.js +19 -1
- package/dist/ui/fleet-office.js +393 -47
- package/dist/ui/office-share-page.js +5 -1
- package/dist/ui/panel-chat.js +47 -3
- package/dist/ui/panel-fleet.js +1 -1
- package/dist/ui/panel-needs.js +7 -4
- package/dist/ui/panel-settings.js +2 -1
- package/dist/ui/preview-popout.js +134 -0
- package/dist/ui/reply-file-preview.js +1 -1
- package/dist/ui/settings-appearance.js +6 -1
- package/dist/ui/settings-host-monitoring.js +51 -0
- package/dist/ui/settings-registry.js +1 -1
- package/dist/ui/settings-shared.js +3 -2
- package/dist/ui/shared/app-i18n.js +4 -0
- package/dist/ui/shared/app-shell.js +16 -7
- package/dist/ui/shared/app.css +266 -27
- package/dist/ui/shared/app.js +7 -1
- package/dist/ui/shared/chat-strings.js +8 -2
- package/dist/ui/shared/info-tip.js +64 -0
- package/dist/ui/shared/office-dialogue.css +12 -0
- package/dist/ui/shared/preview-panel.js +44 -18
- package/dist/ui/shared/preview-popout.css +11 -0
- package/dist/ui/shared/theme-picker.js +46 -0
- package/dist/ui/shared/theme.js +47 -4
- package/dist/ui/shared/tokens.css +273 -0
- package/dist/ui/shared/ui-confirm.js +5 -2
- package/dist/ui/shared/usage-dialog.js +9 -34
- package/dist/ui/shared/view-strings.js +2 -0
- package/dist/usage/i18n-keys.d.ts +1 -1
- package/dist/usage/i18n-keys.js +1 -1
- package/dist/usage/i18n-keys.js.map +1 -1
- package/dist/usage/providers.d.ts +1 -0
- package/dist/usage/providers.js +14 -1
- package/dist/usage/providers.js.map +1 -1
- package/dist/usage/usage-api.js +5 -2
- package/dist/usage/usage-api.js.map +1 -1
- package/dist/web-api.d.ts +5 -1
- package/dist/web-api.js +29 -9
- package/dist/web-api.js.map +1 -1
- package/dist/web-claude-credentials.d.ts +31 -0
- package/dist/web-claude-credentials.js +138 -0
- package/dist/web-claude-credentials.js.map +1 -0
- package/dist/web-commands.d.ts +5 -2
- package/dist/web-commands.js +4 -2
- package/dist/web-commands.js.map +1 -1
- package/dist/web-office-skins.d.ts +7 -2
- package/dist/web-office-skins.js +42 -16
- package/dist/web-office-skins.js.map +1 -1
- package/dist/web-session.d.ts +20 -1
- package/dist/web-session.js +27 -0
- package/dist/web-session.js.map +1 -1
- package/dist/web-terminal.d.ts +4 -0
- package/dist/web-terminal.js +16 -1
- package/dist/web-terminal.js.map +1 -1
- package/package.json +1 -1
|
@@ -182,8 +182,8 @@ export const PACK_STATES = ["needs", "crashed", "stuck", "working", "idle", "pau
|
|
|
182
182
|
/** M-3293 (#4119): what a bubbles table may name — the states, and the Office's two reactions (a pat, a feed). */
|
|
183
183
|
export const BUBBLE_KEYS = [...PACK_STATES, "pat", "feed"];
|
|
184
184
|
const POSES = ["working", "idle", "paused", "needs", "walk", "walkDown", "walkUp", "walkSide"], PROPS = ["task", "send", "report", "broadcast"];
|
|
185
|
-
/** A character set's strips: its poses, and what its people send (#2562). */
|
|
186
|
-
const SET_STRIPS = [...POSES, "prop"];
|
|
185
|
+
/** A character set's strips: its poses, optional eat pose (M-3432 #4255), and what its people send (#2562). */
|
|
186
|
+
const SET_STRIPS = [...POSES, "eat", "prop"];
|
|
187
187
|
/** A furniture item's walking strips (#2596): a character set's walking poses. */
|
|
188
188
|
const WALKS = ["walk", "walkDown", "walkUp", "walkSide"];
|
|
189
189
|
const BUILT_IN = new Set(["pixel", "studio"]);
|
|
@@ -198,8 +198,23 @@ const SRC = /^[A-Za-z0-9._/-]{1,200}$/;
|
|
|
198
198
|
const HEX = /^#[0-9a-f]{6}$/i;
|
|
199
199
|
const LIMIT = { areas: 32, seats: 64, furniture: 128, waypoints: 512, edges: 2048, sets: 64, byInstance: 500, lines: 12, line: 40, seatFor: 16, titles: 32, title: 24, fixed: 500,
|
|
200
200
|
portraitInstances: 500, portraitUsers: 200, portraitNpcs: 128, slice: 128, idleVisits: 8 };
|
|
201
|
+
/** M-3394 (#4231): strip animation caps — per-sheet frames, multi-sheet count, total frames, and per-frame duration (ms). */
|
|
202
|
+
export const STRIP_LIMITS = { sheetFrames: 32, sheets: 32, frames: 600, minMs: 33, maxMs: 60000 };
|
|
203
|
+
/** M-3432 (#4255): snack manifest caps — entries per pack, attraction radius (logical units), and label length. */
|
|
204
|
+
export const SNACK_LIMITS = { max: 12, minRadius: 60, maxRadius: 1280, defaultRadius: 260, labelMax: 24 };
|
|
201
205
|
/** #2861: a portrait's expressions, by the state it is shown in (a missing one: idle, then any given). */
|
|
202
206
|
export const PORTRAIT_STATES = ["idle", "working", "needs"];
|
|
207
|
+
/** M-3433 (#4256): optional agent profile card style & layout enums and caps. */
|
|
208
|
+
export const CARD_PRESETS = ["default", "rpg", "compact", "dossier"];
|
|
209
|
+
export const CARD_RADII = ["none", "sm", "md", "lg"];
|
|
210
|
+
export const CARD_AVATAR_SIZES = ["sm", "md", "lg"];
|
|
211
|
+
export const CARD_AVATAR_SOURCES = ["sprite", "portrait"];
|
|
212
|
+
export const CARD_HEADER_ALIGNS = ["left", "center"];
|
|
213
|
+
export const CARD_SECTIONS = ["header", "level", "rows", "now", "tell", "actions"];
|
|
214
|
+
export const CARD_ROWS = ["office", "model", "backend", "today", "firstSeen"];
|
|
215
|
+
export const CARD_HIDE = ["instance", "title", "badge", "level", "xpBar", "office", "model", "backend", "today", "firstSeen", "now"];
|
|
216
|
+
export const CARD_STYLE_COLORS = ["background", "border", "text", "muted", "accent", "barTrack", "barFill", "buttonBg", "buttonText", "buttonPrimaryBg", "buttonPrimaryText"];
|
|
217
|
+
export const CARD_LIMITS = { widthMin: 280, widthMax: 400, sliceMax: 128, textContrast: 4.5, uiContrast: 3.0 };
|
|
203
218
|
/** #2861: a person's account as the chat records it (`adapter:id`, web-chat-history.ts FROM). */
|
|
204
219
|
const ACCOUNT = /^[^\s:]{1,64}:[^\s:]{1,128}$/;
|
|
205
220
|
|
|
@@ -229,15 +244,115 @@ function list(v, max, at) { if (!Array.isArray(v)) throw new Refused(at, "a list
|
|
|
229
244
|
/** Whether `v` is a pack's `matte`: a colour as #rrggbb (six hex digits, either case). */
|
|
230
245
|
export const matteOk = (v) => typeof v === "string" && HEX.test(v);
|
|
231
246
|
|
|
232
|
-
/**
|
|
247
|
+
/** M-3433 (#4256): WCAG 2.1 relative luminance (0–1) for a #rrggbb colour, or null when invalid. */
|
|
248
|
+
export function relativeLuminance(hex) {
|
|
249
|
+
if (!matteOk(hex)) return null;
|
|
250
|
+
const ch = (i) => {
|
|
251
|
+
const c = parseInt(hex.slice(i, i + 2), 16) / 255;
|
|
252
|
+
return c <= 0.03928 ? c / 12.92 : ((c + 0.055) / 1.055) ** 2.4;
|
|
253
|
+
};
|
|
254
|
+
return 0.2126 * ch(1) + 0.7152 * ch(3) + 0.0722 * ch(5);
|
|
255
|
+
}
|
|
256
|
+
|
|
257
|
+
/** M-3433 (#4256): WCAG 2.1 contrast ratio (1–21) between two #rrggbb colours, or 0 when either is invalid. */
|
|
258
|
+
export function contrastRatio(hexA, hexB) {
|
|
259
|
+
const a = relativeLuminance(hexA), b = relativeLuminance(hexB);
|
|
260
|
+
if (a === null || b === null) return 0;
|
|
261
|
+
const hi = Math.max(a, b), lo = Math.min(a, b);
|
|
262
|
+
return (hi + 0.05) / (lo + 0.05);
|
|
263
|
+
}
|
|
264
|
+
|
|
265
|
+
/** A frame strip, strictly; `scale` the pack's (its displayed size, dw × dh, is resolved here).
|
|
266
|
+
* Supports three forms:
|
|
267
|
+
* 1. Single horizontal sheet (existing): `{ src: "idle.png", frames: 4, w, h, fps?, durations?, once?, loopFrom? }`
|
|
268
|
+
* 2. Multi-sheet sequence (#4231): `{ src: ["a.png", "b.png"], frames: 32 | [32, 16], w, h, fps?, durations?, once?, loopFrom? }`
|
|
269
|
+
* 3. Frame list with per-frame durations (M-3394): `{ frames: [{ src: "f1.png", ms?: 1200 }, …], w, h, fps?, once?, loopFrom? }`
|
|
270
|
+
*/
|
|
233
271
|
export function checkStrip(v, at = "strip", scale = 2) {
|
|
234
272
|
obj(v, at);
|
|
235
|
-
keys(v, ["src", "frames", "w", "h", "fps", "ax", "ay", "dw", "dh"], at);
|
|
273
|
+
keys(v, ["src", "frames", "durations", "w", "h", "fps", "ax", "ay", "dw", "dh", "once", "loopFrom"], at);
|
|
236
274
|
const w = int(v.w, 1, 512, `${at}.w`), h = int(v.h, 1, 512, `${at}.h`);
|
|
237
275
|
const dw0 = v.dw === undefined ? null : num(v.dw, 1, LOGICAL.w, `${at}.dw`), dh0 = v.dh === undefined ? null : num(v.dh, 1, LOGICAL.h, `${at}.dh`);
|
|
238
276
|
const dw = dw0 ?? (dh0 !== null ? (dh0 * w) / h : w * scale), dh = dh0 ?? (dw0 !== null ? (dw0 * h) / w : h * scale);
|
|
239
|
-
|
|
240
|
-
|
|
277
|
+
const ax = v.ax === undefined ? w / 2 : num(v.ax, 0, w, `${at}.ax`), ay = v.ay === undefined ? h : num(v.ay, 0, h, `${at}.ay`);
|
|
278
|
+
if (v.once !== undefined && typeof v.once !== "boolean") throw new Refused(`${at}.once`, "true or false");
|
|
279
|
+
const once = v.once === true;
|
|
280
|
+
let firstSrc, totalFrames, sheets = null, durations = null, fps = 4;
|
|
281
|
+
|
|
282
|
+
if (v.src === undefined && Array.isArray(v.frames)) {
|
|
283
|
+
// Form 3: explicit frame list [{ src, ms? }, …], each image 1 frame (w × h).
|
|
284
|
+
if (v.durations !== undefined) throw new Refused(`${at}.durations`, "use ms on each entry in frames");
|
|
285
|
+
const items = list(v.frames, STRIP_LIMITS.frames, `${at}.frames`);
|
|
286
|
+
if (!items.length) throw new Refused(`${at}.frames`, "at least 1 frame");
|
|
287
|
+
fps = v.fps === undefined ? 4 : num(v.fps, 0, 30, `${at}.fps`);
|
|
288
|
+
let hasMs = false;
|
|
289
|
+
const parsed = items.map((e, i) => {
|
|
290
|
+
const here = `${at}.frames[${i}]`;
|
|
291
|
+
obj(e, here); keys(e, ["src", "ms"], here);
|
|
292
|
+
const file = src(e.src, `${here}.src`);
|
|
293
|
+
const ms = e.ms === undefined ? null : int(e.ms, STRIP_LIMITS.minMs, STRIP_LIMITS.maxMs, `${here}.ms`);
|
|
294
|
+
if (ms !== null) hasMs = true;
|
|
295
|
+
return { src: file, ms };
|
|
296
|
+
});
|
|
297
|
+
if (hasMs && v.fps === 0) throw new Refused(`${at}.fps`, "0 cannot be used with frame ms");
|
|
298
|
+
firstSrc = parsed[0].src;
|
|
299
|
+
totalFrames = parsed.length;
|
|
300
|
+
sheets = parsed.map((e) => ({ src: e.src, frames: 1 }));
|
|
301
|
+
if (hasMs) {
|
|
302
|
+
const fallbackMs = Math.max(STRIP_LIMITS.minMs, Math.min(STRIP_LIMITS.maxMs, Math.round(1000 / (fps > 0 ? fps : 4))));
|
|
303
|
+
durations = parsed.map((e) => e.ms ?? fallbackMs);
|
|
304
|
+
}
|
|
305
|
+
} else if (Array.isArray(v.src)) {
|
|
306
|
+
// Form 2: multi-sheet sequence of horizontal strips.
|
|
307
|
+
const files = list(v.src, STRIP_LIMITS.sheets, `${at}.src`).map((s, i) => src(s, `${at}.src[${i}]`));
|
|
308
|
+
if (!files.length) throw new Refused(`${at}.src`, "at least 1 file");
|
|
309
|
+
let counts;
|
|
310
|
+
if (Array.isArray(v.frames)) {
|
|
311
|
+
if (v.frames.length !== files.length) throw new Refused(`${at}.frames`, `must have ${files.length} entries (one per image in src)`);
|
|
312
|
+
counts = v.frames.map((n, i) => int(n, 1, STRIP_LIMITS.sheetFrames, `${at}.frames[${i}]`));
|
|
313
|
+
} else {
|
|
314
|
+
const n = int(v.frames, 1, STRIP_LIMITS.sheetFrames, `${at}.frames`);
|
|
315
|
+
counts = files.map(() => n);
|
|
316
|
+
}
|
|
317
|
+
totalFrames = counts.reduce((a, b) => a + b, 0);
|
|
318
|
+
if (totalFrames > STRIP_LIMITS.frames) throw new Refused(`${at}.frames`, `at most ${STRIP_LIMITS.frames} frames in all`);
|
|
319
|
+
firstSrc = files[0];
|
|
320
|
+
sheets = files.map((file, i) => ({ src: file, frames: counts[i] }));
|
|
321
|
+
if (v.durations !== undefined) {
|
|
322
|
+
if (v.fps !== undefined) throw new Refused(`${at}.durations`, "cannot be used with fps");
|
|
323
|
+
const ds = list(v.durations, STRIP_LIMITS.frames, `${at}.durations`);
|
|
324
|
+
if (ds.length !== totalFrames) throw new Refused(`${at}.durations`, `must have ${totalFrames} entries (one per frame)`);
|
|
325
|
+
durations = ds.map((d, i) => int(d, STRIP_LIMITS.minMs, STRIP_LIMITS.maxMs, `${at}.durations[${i}]`));
|
|
326
|
+
} else {
|
|
327
|
+
fps = v.fps === undefined ? 4 : num(v.fps, 0, 30, `${at}.fps`);
|
|
328
|
+
}
|
|
329
|
+
} else {
|
|
330
|
+
// Form 1: single horizontal strip (unchanged for existing packs).
|
|
331
|
+
firstSrc = src(v.src, `${at}.src`);
|
|
332
|
+
totalFrames = int(v.frames, 1, STRIP_LIMITS.sheetFrames, `${at}.frames`);
|
|
333
|
+
if (v.durations !== undefined) {
|
|
334
|
+
if (v.fps !== undefined) throw new Refused(`${at}.durations`, "cannot be used with fps");
|
|
335
|
+
const ds = list(v.durations, STRIP_LIMITS.sheetFrames, `${at}.durations`);
|
|
336
|
+
if (ds.length !== totalFrames) throw new Refused(`${at}.durations`, `must have ${totalFrames} entries (one per frame)`);
|
|
337
|
+
durations = ds.map((d, i) => int(d, STRIP_LIMITS.minMs, STRIP_LIMITS.maxMs, `${at}.durations[${i}]`));
|
|
338
|
+
} else {
|
|
339
|
+
fps = v.fps === undefined ? 4 : num(v.fps, 0, 30, `${at}.fps`);
|
|
340
|
+
}
|
|
341
|
+
}
|
|
342
|
+
|
|
343
|
+
let loopFrom = 0;
|
|
344
|
+
if (v.loopFrom !== undefined) {
|
|
345
|
+
if (once) throw new Refused(`${at}.loopFrom`, "cannot be used with once");
|
|
346
|
+
loopFrom = int(v.loopFrom, 0, totalFrames - 1, `${at}.loopFrom`);
|
|
347
|
+
}
|
|
348
|
+
|
|
349
|
+
return {
|
|
350
|
+
src: firstSrc, frames: totalFrames, w, h, fps, ax, ay, dw, dh,
|
|
351
|
+
...(sheets ? { sheets } : {}),
|
|
352
|
+
...(durations ? { durations } : {}),
|
|
353
|
+
...(once ? { once: true } : {}),
|
|
354
|
+
...(loopFrom > 0 ? { loopFrom } : {}),
|
|
355
|
+
};
|
|
241
356
|
}
|
|
242
357
|
/** A furniture item's night (#2568): { sprite, x, y } — at bedtime it is drawn as `sprite` (playing) at (x, y), its own place when left out. */
|
|
243
358
|
function nightOf(v, at, scale) {
|
|
@@ -402,6 +517,100 @@ function dialogBoxOf(v) {
|
|
|
402
517
|
return out;
|
|
403
518
|
}
|
|
404
519
|
|
|
520
|
+
/** M-3433 (#4256): a unique ordered list of allowed enum values. */
|
|
521
|
+
function uniqueEnumList(v, allowed, at) {
|
|
522
|
+
const items = list(v, allowed.length, at), seen = new Set();
|
|
523
|
+
return items.map((s, i) => {
|
|
524
|
+
if (typeof s !== "string" || !allowed.includes(s)) throw new Refused(`${at}[${i}]`, `one of ${allowed.join(", ")}`);
|
|
525
|
+
if (seen.has(s)) throw new Refused(`${at}[${i}]`, `"${s}" listed twice`);
|
|
526
|
+
seen.add(s);
|
|
527
|
+
return s;
|
|
528
|
+
});
|
|
529
|
+
}
|
|
530
|
+
|
|
531
|
+
/**
|
|
532
|
+
* M-3433 (#4256): a pack's optional `card` — agent profile card preset, visual style (strict #rrggbb colours with
|
|
533
|
+
* WCAG contrast checks on explicit pairs, optional backgroundImage and 9-slice frame, corner radius), and layout
|
|
534
|
+
* (avatar size/source, header alignment, width, section/row ordering, columns, hideable fields). Null when absent.
|
|
535
|
+
*/
|
|
536
|
+
function cardOf(v) {
|
|
537
|
+
if (v === undefined) return null;
|
|
538
|
+
obj(v, "card");
|
|
539
|
+
keys(v, ["preset", "style", "layout"], "card");
|
|
540
|
+
const out = {};
|
|
541
|
+
if (v.preset !== undefined) {
|
|
542
|
+
if (typeof v.preset !== "string" || !CARD_PRESETS.includes(v.preset)) throw new Refused("card.preset", `one of ${CARD_PRESETS.join(", ")}`);
|
|
543
|
+
out.preset = v.preset;
|
|
544
|
+
}
|
|
545
|
+
if (v.style !== undefined) {
|
|
546
|
+
const s = obj(v.style, "card.style");
|
|
547
|
+
keys(s, [...CARD_STYLE_COLORS, "backgroundImage", "frame", "slice", "radius"], "card.style");
|
|
548
|
+
if (s.slice !== undefined && s.frame === undefined) throw new Refused("card.style.slice", "only with frame");
|
|
549
|
+
const st = {};
|
|
550
|
+
for (const k of CARD_STYLE_COLORS) {
|
|
551
|
+
if (s[k] === undefined) continue;
|
|
552
|
+
if (!matteOk(s[k])) throw new Refused(`card.style.${k}`, "a colour as #rrggbb");
|
|
553
|
+
st[k] = s[k].toLowerCase();
|
|
554
|
+
}
|
|
555
|
+
if (s.backgroundImage !== undefined) st.backgroundImage = src(s.backgroundImage, "card.style.backgroundImage");
|
|
556
|
+
if (s.frame !== undefined) {
|
|
557
|
+
st.frame = src(s.frame, "card.style.frame");
|
|
558
|
+
st.slice = s.slice === undefined ? 8 : int(s.slice, 1, CARD_LIMITS.sliceMax, "card.style.slice");
|
|
559
|
+
}
|
|
560
|
+
if (s.radius !== undefined) {
|
|
561
|
+
if (typeof s.radius !== "string" || !CARD_RADII.includes(s.radius)) throw new Refused("card.style.radius", `one of ${CARD_RADII.join(", ")}`);
|
|
562
|
+
st.radius = s.radius;
|
|
563
|
+
}
|
|
564
|
+
const pairs = [
|
|
565
|
+
["text", "background", CARD_LIMITS.textContrast],
|
|
566
|
+
["muted", "background", CARD_LIMITS.textContrast],
|
|
567
|
+
["accent", "background", CARD_LIMITS.textContrast],
|
|
568
|
+
["buttonText", "buttonBg", CARD_LIMITS.textContrast],
|
|
569
|
+
["buttonPrimaryText", "buttonPrimaryBg", CARD_LIMITS.textContrast],
|
|
570
|
+
["border", "background", CARD_LIMITS.uiContrast],
|
|
571
|
+
["barFill", "barTrack", CARD_LIMITS.uiContrast],
|
|
572
|
+
];
|
|
573
|
+
for (const [fg, bg, min] of pairs) {
|
|
574
|
+
if (st[fg] && st[bg]) {
|
|
575
|
+
const ratio = contrastRatio(st[fg], st[bg]);
|
|
576
|
+
if (ratio < min) throw new Refused(`card.style.${fg}`, `contrast ratio against ${bg} must be at least ${min}:1 (got ${ratio.toFixed(2)}:1)`);
|
|
577
|
+
}
|
|
578
|
+
}
|
|
579
|
+
out.style = st;
|
|
580
|
+
}
|
|
581
|
+
if (v.layout !== undefined) {
|
|
582
|
+
const l = obj(v.layout, "card.layout");
|
|
583
|
+
keys(l, ["avatarSize", "avatarSource", "headerAlign", "width", "sections", "rows", "rowColumns", "hide"], "card.layout");
|
|
584
|
+
const ly = {};
|
|
585
|
+
if (l.avatarSize !== undefined) {
|
|
586
|
+
if (typeof l.avatarSize !== "string" || !CARD_AVATAR_SIZES.includes(l.avatarSize)) throw new Refused("card.layout.avatarSize", `one of ${CARD_AVATAR_SIZES.join(", ")}`);
|
|
587
|
+
ly.avatarSize = l.avatarSize;
|
|
588
|
+
}
|
|
589
|
+
if (l.avatarSource !== undefined) {
|
|
590
|
+
if (typeof l.avatarSource !== "string" || !CARD_AVATAR_SOURCES.includes(l.avatarSource)) throw new Refused("card.layout.avatarSource", `one of ${CARD_AVATAR_SOURCES.join(", ")}`);
|
|
591
|
+
ly.avatarSource = l.avatarSource;
|
|
592
|
+
}
|
|
593
|
+
if (l.headerAlign !== undefined) {
|
|
594
|
+
if (typeof l.headerAlign !== "string" || !CARD_HEADER_ALIGNS.includes(l.headerAlign)) throw new Refused("card.layout.headerAlign", `one of ${CARD_HEADER_ALIGNS.join(", ")}`);
|
|
595
|
+
ly.headerAlign = l.headerAlign;
|
|
596
|
+
}
|
|
597
|
+
if (l.width !== undefined) ly.width = int(l.width, CARD_LIMITS.widthMin, CARD_LIMITS.widthMax, "card.layout.width");
|
|
598
|
+
if (l.sections !== undefined) {
|
|
599
|
+
const secs = uniqueEnumList(l.sections, CARD_SECTIONS, "card.layout.sections");
|
|
600
|
+
if (!secs.includes("header") || !secs.includes("actions")) throw new Refused("card.layout.sections", 'must include "header" and "actions"');
|
|
601
|
+
ly.sections = secs;
|
|
602
|
+
}
|
|
603
|
+
if (l.rows !== undefined) ly.rows = uniqueEnumList(l.rows, CARD_ROWS, "card.layout.rows");
|
|
604
|
+
if (l.rowColumns !== undefined) {
|
|
605
|
+
if (l.rowColumns !== 1 && l.rowColumns !== 2) throw new Refused("card.layout.rowColumns", "1 or 2");
|
|
606
|
+
ly.rowColumns = l.rowColumns;
|
|
607
|
+
}
|
|
608
|
+
if (l.hide !== undefined) ly.hide = uniqueEnumList(l.hide, CARD_HIDE, "card.layout.hide");
|
|
609
|
+
out.layout = ly;
|
|
610
|
+
}
|
|
611
|
+
return out;
|
|
612
|
+
}
|
|
613
|
+
|
|
405
614
|
/**
|
|
406
615
|
* #3685: a pack's `idleVisits` — up to LIMIT.idleVisits { area, weight 1–100, minSeconds 5–600, maxSeconds minSeconds–600 },
|
|
407
616
|
* each an area the pack defines, none twice; [] when it has none.
|
|
@@ -419,6 +628,52 @@ function idleVisitsOf(v, areas) {
|
|
|
419
628
|
});
|
|
420
629
|
}
|
|
421
630
|
|
|
631
|
+
/** M-3432 (#4255): a snack's label — string (1–24 chars) or `{ en?, "zh-TW"? }`. */
|
|
632
|
+
function snackLabelOf(v, at) {
|
|
633
|
+
const ok = (s, here) => {
|
|
634
|
+
if (typeof s !== "string" || !s.trim() || [...s.trim()].length > SNACK_LIMITS.labelMax || /[\u0000-\u001f\u007f]/.test(s)) {
|
|
635
|
+
throw new Refused(here, `1–${SNACK_LIMITS.labelMax} characters`);
|
|
636
|
+
}
|
|
637
|
+
return s.trim();
|
|
638
|
+
};
|
|
639
|
+
if (typeof v === "string") return ok(v, at);
|
|
640
|
+
obj(v, at);
|
|
641
|
+
keys(v, ["en", "zh-TW"], at);
|
|
642
|
+
const out = {};
|
|
643
|
+
if (v.en !== undefined) out.en = ok(v.en, `${at}.en`);
|
|
644
|
+
if (v["zh-TW"] !== undefined) out["zh-TW"] = ok(v["zh-TW"], `${at}.zh-TW`);
|
|
645
|
+
if (!Object.keys(out).length) throw new Refused(at, 'a string, or { "en"?, "zh-TW"? }');
|
|
646
|
+
return out;
|
|
647
|
+
}
|
|
648
|
+
|
|
649
|
+
/** M-3432 (#4255): a pack's optional `snacks` list — 1–12 snack items with sprites, optional eat overlay, and attraction radius. */
|
|
650
|
+
function snacksOf(v, scale) {
|
|
651
|
+
if (v === undefined) return [];
|
|
652
|
+
const items = list(v, SNACK_LIMITS.max, "snacks");
|
|
653
|
+
if (!items.length) throw new Refused("snacks", "at least 1 snack");
|
|
654
|
+
const seen = new Set();
|
|
655
|
+
return items.map((e, i) => {
|
|
656
|
+
const at = `snacks[${i}]`;
|
|
657
|
+
obj(e, at);
|
|
658
|
+
keys(e, ["id", "label", "sprite", "eat", "radius"], at);
|
|
659
|
+
if (!nameOk(e.id) || seen.has(e.id)) throw new Refused(`${at}.id`, "a new name of letters, digits, _ or - (not an inherited one)");
|
|
660
|
+
seen.add(e.id);
|
|
661
|
+
const label = e.label === undefined ? null : snackLabelOf(e.label, `${at}.label`);
|
|
662
|
+
const sprite = checkStrip(e.sprite, `${at}.sprite`, scale);
|
|
663
|
+
const eat = e.eat === undefined ? null : checkStrip(e.eat, `${at}.eat`, scale);
|
|
664
|
+
const radius = e.radius === undefined ? SNACK_LIMITS.defaultRadius : num(e.radius, SNACK_LIMITS.minRadius, SNACK_LIMITS.maxRadius, `${at}.radius`);
|
|
665
|
+
return { id: e.id, ...(label !== null ? { label } : {}), sprite, ...(eat ? { eat } : {}), radius };
|
|
666
|
+
});
|
|
667
|
+
}
|
|
668
|
+
|
|
669
|
+
/** M-3432 (#4255): display label for a checked snack in `lang` ("en" or "zh-TW"), falling back to its id. */
|
|
670
|
+
export function snackLabel(snack, lang = "en") {
|
|
671
|
+
if (!snack) return "";
|
|
672
|
+
if (typeof snack.label === "string") return snack.label;
|
|
673
|
+
if (snack.label && typeof snack.label === "object") return own(snack.label, lang) || own(snack.label, "en") || own(snack.label, "zh-TW") || snack.id;
|
|
674
|
+
return snack.id;
|
|
675
|
+
}
|
|
676
|
+
|
|
422
677
|
/**
|
|
423
678
|
* #3679: the fleet-wide `levels` (Settings → Web dashboard → Level titles, kept in web-offices.json) checked by the very
|
|
424
679
|
* rules a pack's are (levelsOf): { ok: true, levels } or { ok: false, error: "<where>: <why>" }. `v` must be an object.
|
|
@@ -440,7 +695,7 @@ export function checkLevels(v) {
|
|
|
440
695
|
export function checkSkinPack(x, { kept = false } = {}) {
|
|
441
696
|
try {
|
|
442
697
|
obj(x, "pack");
|
|
443
|
-
keys(x, ["format", "id", "scale", "background", "foreground", "matte", "areas", "stateZones", "door", "mailDrop", "waypoints", "edges", "straight", "furniture", "characters", "byInstance", "props", "bubbles", "bubblesByInstance", "room", "desk", "levels", "portraits", "dialogBox", "idleVisits"], "pack");
|
|
698
|
+
keys(x, ["format", "id", "scale", "background", "foreground", "matte", "areas", "stateZones", "door", "mailDrop", "waypoints", "edges", "straight", "furniture", "characters", "byInstance", "props", "bubbles", "bubblesByInstance", "room", "desk", "levels", "portraits", "dialogBox", "idleVisits", "snacks", "card"], "pack");
|
|
444
699
|
if (x.format !== 1) throw new Refused("format", "1");
|
|
445
700
|
if (typeof x.id !== "string" || !ID.test(x.id)) throw new Refused("id", "1–40 letters, digits, _ or -");
|
|
446
701
|
if (BUILT_IN.has(x.id) || (!kept && RESERVED.has(x.id))) throw new Refused("id", "a built-in skin's id");
|
|
@@ -540,7 +795,8 @@ export function checkSkinPack(x, { kept = false } = {}) {
|
|
|
540
795
|
bubblesByInstance[k] = bubblesOf(v, `bubblesByInstance.${k}`);
|
|
541
796
|
}
|
|
542
797
|
const levels = levelsOf(x.levels);
|
|
543
|
-
const portraits = portraitsOf(x.portraits, fids), dialogBox = dialogBoxOf(x.dialogBox);
|
|
798
|
+
const portraits = portraitsOf(x.portraits, fids), dialogBox = dialogBoxOf(x.dialogBox), card = cardOf(x.card);
|
|
799
|
+
const snacks = snacksOf(x.snacks, scale);
|
|
544
800
|
const room = x.room === undefined ? {} : obj(x.room, "room"), desk = x.desk === undefined ? {} : obj(x.desk, "desk");
|
|
545
801
|
keys(room, ["floor", "wall"], "room"); keys(desk, ["back", "front", "lit"], "desk");
|
|
546
802
|
const opt = (v, at) => (v === undefined ? undefined : src(v, at));
|
|
@@ -554,6 +810,7 @@ export function checkSkinPack(x, { kept = false } = {}) {
|
|
|
554
810
|
room: { floor: opt(room.floor, "room.floor"), wall: opt(room.wall, "room.wall") }, desk: { back: opt(desk.back, "desk.back"), front: opt(desk.front, "desk.front"), lit: opt(desk.lit, "desk.lit") },
|
|
555
811
|
...(levels ? { levels } : {}), ...(idleVisits.length ? { idleVisits } : {}),
|
|
556
812
|
...(portraits ? { portraits } : {}), ...(dialogBox ? { dialogBox } : {}),
|
|
813
|
+
...(snacks.length ? { snacks } : {}), ...(card ? { card } : {}),
|
|
557
814
|
} };
|
|
558
815
|
} catch (err) {
|
|
559
816
|
if (err instanceof Refused) return { ok: false, error: err.message };
|
|
@@ -562,29 +819,40 @@ export function checkSkinPack(x, { kept = false } = {}) {
|
|
|
562
819
|
}
|
|
563
820
|
/** The checked pack, or null. */
|
|
564
821
|
export const skinPackOk = (x) => { const r = checkSkinPack(x); return r.ok ? r.pack : null; };
|
|
565
|
-
/** #2861:
|
|
822
|
+
/** #2861 / #4256: pictures loaded lazily (portraits, dialogue-box frame, card background/frame). */
|
|
566
823
|
export const packPortraitImages = (pack) => {
|
|
567
824
|
const p = pack.portraits, all = p ? [p.default, ...Object.values(p.byInstance), ...Object.values(p.byUser), ...Object.values(p.npc)] : [];
|
|
568
|
-
|
|
825
|
+
const cs = pack.card && pack.card.style;
|
|
826
|
+
return [...new Set([...all.flatMap((e) => (e ? Object.values(e) : [])), pack.dialogBox && pack.dialogBox.frame, cs && cs.backgroundImage, cs && cs.frame].filter(Boolean))];
|
|
569
827
|
};
|
|
828
|
+
/** The sheets a strip draws from, in order: `[{ src, frames }]` (single-sheet strips have one entry). */
|
|
829
|
+
export const stripSheets = (st) => (st && Array.isArray(st.sheets) ? st.sheets : st && st.src ? [{ src: st.src, frames: st.frames }] : []);
|
|
830
|
+
/** Every unique image file a strip references. */
|
|
831
|
+
export const stripImages = (st) => [...new Set(stripSheets(st).map((s) => s.src))];
|
|
832
|
+
|
|
570
833
|
/** The pictures the scene draws (what a loader fetches before spriteSkin draws). */
|
|
571
|
-
export const packSceneImages = (pack) => [...new Set([pack.background, pack.foreground, pack.room
|
|
572
|
-
|
|
573
|
-
...
|
|
834
|
+
export const packSceneImages = (pack) => [...new Set([pack.background, pack.foreground, pack.room && pack.room.floor, pack.room && pack.room.wall,
|
|
835
|
+
pack.desk && pack.desk.back, pack.desk && pack.desk.front, pack.desk && pack.desk.lit,
|
|
836
|
+
...packStrips(pack).flatMap(({ strip }) => stripImages(strip))].filter(Boolean))];
|
|
574
837
|
/** Every image a pack names: the scene's and (#2861) the dialogue box's — what an upload must send, and nothing else. */
|
|
575
838
|
export const packImages = (pack) => [...new Set([...packSceneImages(pack), ...packPortraitImages(pack)])];
|
|
576
839
|
|
|
577
840
|
/** Every frame strip a checked pack names, with where (the host checks each image is frames·w × h). */
|
|
578
841
|
export function packStrips(pack) {
|
|
579
842
|
const out = [];
|
|
580
|
-
|
|
581
|
-
|
|
843
|
+
if (!pack || typeof pack !== "object") return out;
|
|
844
|
+
for (const f of pack.furniture || []) {
|
|
845
|
+
if (f.sprite) out.push({ at: `furniture.${f.id}.sprite`, strip: f.sprite });
|
|
582
846
|
if (f.activeSprite) out.push({ at: `furniture.${f.id}.activeSprite`, strip: f.activeSprite });
|
|
583
|
-
if (f.night) out.push({ at: `furniture.${f.id}.night.sprite`, strip: f.night.sprite });
|
|
847
|
+
if (f.night && f.night.sprite) out.push({ at: `furniture.${f.id}.night.sprite`, strip: f.night.sprite });
|
|
584
848
|
for (const [k, st] of Object.entries(f.walk || {})) out.push({ at: `furniture.${f.id}.walk.${k}`, strip: st });
|
|
585
849
|
}
|
|
586
|
-
for (const [k, set] of Object.entries(pack.characters)) for (const [pose, st] of Object.entries(set)) out.push({ at: `characters.${k}.${pose}`, strip: st });
|
|
587
|
-
for (const [k, st] of Object.entries(pack.props)) out.push({ at: `props.${k}`, strip: st });
|
|
850
|
+
for (const [k, set] of Object.entries(pack.characters || {})) for (const [pose, st] of Object.entries(set)) out.push({ at: `characters.${k}.${pose}`, strip: st });
|
|
851
|
+
for (const [k, st] of Object.entries(pack.props || {})) out.push({ at: `props.${k}`, strip: st });
|
|
852
|
+
for (const sn of pack.snacks || []) {
|
|
853
|
+
if (sn.sprite) out.push({ at: `snacks.${sn.id}.sprite`, strip: sn.sprite });
|
|
854
|
+
if (sn.eat) out.push({ at: `snacks.${sn.id}.eat`, strip: sn.eat });
|
|
855
|
+
}
|
|
588
856
|
return out;
|
|
589
857
|
}
|
|
590
858
|
|
|
@@ -824,3 +1092,129 @@ export function stripBox(st, x, y, mirror = false) {
|
|
|
824
1092
|
const kx = st.dw / st.w, ky = st.dh / st.h;
|
|
825
1093
|
return { x: Math.round(x - (mirror ? st.w - st.ax : st.ax) * kx), y: Math.round(y - st.ay * ky), w: st.dw, h: st.dh };
|
|
826
1094
|
}
|
|
1095
|
+
|
|
1096
|
+
// ── M-3394 (#4231): multi-sheet & variable-duration strip playback ──
|
|
1097
|
+
|
|
1098
|
+
const DURATION_INDEX = new WeakMap();
|
|
1099
|
+
const SHEET_INDEX = new WeakMap();
|
|
1100
|
+
|
|
1101
|
+
/** Binary search for the smallest index `i` in strictly-increasing `ends` with `value < ends[i]`. */
|
|
1102
|
+
function upperBound(ends, value) {
|
|
1103
|
+
let lo = 0, hi = ends.length - 1;
|
|
1104
|
+
while (lo < hi) {
|
|
1105
|
+
const mid = (lo + hi) >>> 1;
|
|
1106
|
+
if (value < ends[mid]) hi = mid;
|
|
1107
|
+
else lo = mid + 1;
|
|
1108
|
+
}
|
|
1109
|
+
return lo;
|
|
1110
|
+
}
|
|
1111
|
+
|
|
1112
|
+
function durationIndex(st) {
|
|
1113
|
+
let idx = DURATION_INDEX.get(st);
|
|
1114
|
+
if (idx) return idx;
|
|
1115
|
+
const ends = new Array(st.durations.length);
|
|
1116
|
+
let sum = 0;
|
|
1117
|
+
for (let i = 0; i < st.durations.length; i++) { sum += st.durations[i]; ends[i] = sum; }
|
|
1118
|
+
const loopFrom = st.loopFrom > 0 && st.loopFrom < ends.length ? st.loopFrom : 0;
|
|
1119
|
+
const loopStart = loopFrom > 0 ? ends[loopFrom - 1] : 0;
|
|
1120
|
+
idx = { ends, total: sum, loopStart, loopSpan: sum - loopStart };
|
|
1121
|
+
DURATION_INDEX.set(st, idx);
|
|
1122
|
+
return idx;
|
|
1123
|
+
}
|
|
1124
|
+
|
|
1125
|
+
function sheetIndex(st) {
|
|
1126
|
+
let idx = SHEET_INDEX.get(st);
|
|
1127
|
+
if (idx) return idx;
|
|
1128
|
+
const sheets = st.sheets, ends = new Array(sheets.length), starts = new Array(sheets.length);
|
|
1129
|
+
let sum = 0;
|
|
1130
|
+
for (let i = 0; i < sheets.length; i++) { starts[i] = sum; sum += sheets[i].frames; ends[i] = sum; }
|
|
1131
|
+
idx = { sheets, starts, ends };
|
|
1132
|
+
SHEET_INDEX.set(st, idx);
|
|
1133
|
+
return idx;
|
|
1134
|
+
}
|
|
1135
|
+
|
|
1136
|
+
/**
|
|
1137
|
+
* The frame index (0 .. st.frames - 1) of a strip at elapsed time `ms`.
|
|
1138
|
+
* `ms <= 0` always yields frame 0 (reduced motion, still previews, or clip start).
|
|
1139
|
+
* Supports fixed `fps`, per-frame `durations`, `once: true` (play once and hold last frame),
|
|
1140
|
+
* and `loopFrom` (play intro `0 .. loopFrom - 1` once, then loop `loopFrom .. last`).
|
|
1141
|
+
*/
|
|
1142
|
+
export function stripFrameAt(st, ms) {
|
|
1143
|
+
if (!st || st.frames <= 1 || !(ms > 0)) return 0;
|
|
1144
|
+
if (Array.isArray(st.durations) && st.durations.length === st.frames) {
|
|
1145
|
+
const { ends, total, loopStart, loopSpan } = durationIndex(st);
|
|
1146
|
+
if (total <= 0) return 0;
|
|
1147
|
+
if (st.once) return ms >= total ? st.frames - 1 : upperBound(ends, ms);
|
|
1148
|
+
const t = loopStart > 0 && loopSpan > 0
|
|
1149
|
+
? (ms < loopStart ? ms : loopStart + ((ms - loopStart) % loopSpan))
|
|
1150
|
+
: ms % total;
|
|
1151
|
+
return upperBound(ends, t);
|
|
1152
|
+
}
|
|
1153
|
+
if (!(st.fps > 0)) return 0;
|
|
1154
|
+
const raw = Math.floor((ms / 1000) * st.fps);
|
|
1155
|
+
if (st.once) return Math.min(st.frames - 1, raw);
|
|
1156
|
+
const lf = st.loopFrom > 0 && st.loopFrom < st.frames ? st.loopFrom : 0;
|
|
1157
|
+
if (lf > 0) return raw < lf ? raw : lf + ((raw - lf) % (st.frames - lf));
|
|
1158
|
+
return raw % st.frames;
|
|
1159
|
+
}
|
|
1160
|
+
|
|
1161
|
+
/** Which image (`src`) and horizontal frame column (`col`) hold global frame index `frame` of `st`. */
|
|
1162
|
+
export function stripCell(st, frame) {
|
|
1163
|
+
const f = Math.max(0, Math.min((st && st.frames ? st.frames : 1) - 1, Math.floor(Number(frame) || 0)));
|
|
1164
|
+
if (!st || !Array.isArray(st.sheets)) return { src: st ? st.src : "", col: f };
|
|
1165
|
+
const { sheets, starts, ends } = sheetIndex(st);
|
|
1166
|
+
const i = upperBound(ends, f);
|
|
1167
|
+
return { src: sheets[i].src, col: f - starts[i] };
|
|
1168
|
+
}
|
|
1169
|
+
|
|
1170
|
+
/** The highest frame rate (frames/s) a strip needs for smooth playback; 0 when static. */
|
|
1171
|
+
export function stripMaxFps(st) {
|
|
1172
|
+
if (!st || st.frames <= 1) return 0;
|
|
1173
|
+
if (Array.isArray(st.durations) && st.durations.length) {
|
|
1174
|
+
let minMs = Infinity;
|
|
1175
|
+
for (let i = 0; i < st.durations.length; i++) if (st.durations[i] < minMs) minMs = st.durations[i];
|
|
1176
|
+
return minMs > 0 && Number.isFinite(minMs) ? 1000 / minMs : 0;
|
|
1177
|
+
}
|
|
1178
|
+
return st.fps > 0 ? st.fps : 0;
|
|
1179
|
+
}
|
|
1180
|
+
|
|
1181
|
+
/** M-3432 (#4255): total duration (ms) of one full pass through `st`; 0 when static or invalid. */
|
|
1182
|
+
export function stripDurationMs(st) {
|
|
1183
|
+
if (!st || !(st.frames >= 1)) return 0;
|
|
1184
|
+
if (Array.isArray(st.durations) && st.durations.length === st.frames) {
|
|
1185
|
+
return durationIndex(st).total;
|
|
1186
|
+
}
|
|
1187
|
+
if (st.frames <= 1 || !(st.fps > 0)) return 0;
|
|
1188
|
+
return Math.round((st.frames / st.fps) * 1000);
|
|
1189
|
+
}
|
|
1190
|
+
|
|
1191
|
+
/** The highest frame rate any strip in `pack` needs; 0 for built-ins without animated strips. */
|
|
1192
|
+
export function packMaxFps(pack) {
|
|
1193
|
+
let max = 0;
|
|
1194
|
+
for (const { strip } of packStrips(pack)) {
|
|
1195
|
+
const f = stripMaxFps(strip);
|
|
1196
|
+
if (f > max) max = f;
|
|
1197
|
+
}
|
|
1198
|
+
return max;
|
|
1199
|
+
}
|
|
1200
|
+
|
|
1201
|
+
/**
|
|
1202
|
+
* Per-entity clip clock: records when each key entered its current strip so `once` and `loopFrom`
|
|
1203
|
+
* start at frame 0 on pose/state changes and continue seamlessly across re-renders.
|
|
1204
|
+
*/
|
|
1205
|
+
export function createClipClocks() {
|
|
1206
|
+
const by = new Map();
|
|
1207
|
+
return {
|
|
1208
|
+
elapsed(key, strip, ms) {
|
|
1209
|
+
if (!(ms > 0) || !strip) return 0;
|
|
1210
|
+
const cur = by.get(key);
|
|
1211
|
+
if (cur && cur.strip === strip) return Math.max(0, ms - cur.since);
|
|
1212
|
+
by.set(key, { strip, since: ms });
|
|
1213
|
+
return 0;
|
|
1214
|
+
},
|
|
1215
|
+
prune(seen) {
|
|
1216
|
+
for (const k of [...by.keys()]) if (!seen.has(k)) by.delete(k);
|
|
1217
|
+
},
|
|
1218
|
+
clear() { by.clear(); },
|
|
1219
|
+
};
|
|
1220
|
+
}
|