@kriya-ai/harness 0.2.5 → 2.0.1
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/RELEASE_NOTES.md +121 -0
- package/SAFETY.md +181 -0
- package/THIRD_PARTY_NOTICES.md +113 -0
- package/bin/kriya.js +188 -2
- package/bundle/cordis.patch.yml +60 -5
- package/contract/SOURCE.md +3 -3
- package/contract/contract.json +498 -3
- package/contract/schemas/api.json +64 -0
- package/contract/schemas/auth_matrix.json +44 -0
- package/contract/schemas/component_states.json +33 -0
- package/contract/schemas/design_tokens.json +34 -0
- package/contract/schemas/scene_direction.json +82 -0
- package/contract/schemas/threat_model.json +44 -0
- package/package.json +2 -1
- package/plugins/changes/client.js +5 -3
- package/plugins/deploy/index.js +215 -0
- package/plugins/deploy/package.json +13 -0
- package/plugins/grounding/index.js +81 -0
- package/plugins/grounding/lookup.js +373 -0
- package/plugins/grounding/package.json +13 -0
- package/plugins/kriya-tools/index.js +2 -1
- package/plugins/loop/index.js +381 -10
- package/plugins/mcp/index.js +79 -0
- package/plugins/mcp/package.json +13 -0
- package/plugins/mirror/index.js +17 -0
- package/plugins/overview/client.js +5 -2
- package/plugins/preview/client.js +12 -6
- package/plugins/progress/client.js +7 -4
- package/plugins/repo/index.js +230 -0
- package/plugins/repo/package.json +13 -0
- package/plugins/repo/repo.js +348 -0
- package/plugins/runstrip/client.js +436 -0
- package/plugins/runstrip/index.js +312 -0
- package/plugins/runstrip/package.json +23 -0
- package/src/cartridges.js +133 -0
- package/src/contracts.js +130 -0
- package/src/critic.js +78 -0
- package/src/daemon.js +7 -1
- package/src/doctor.js +67 -0
- package/src/edit/core/effects.js +185 -0
- package/src/edit/core/ffmpeg.js +65 -6
- package/src/edit/core/layout.js +46 -1
- package/src/edit/core/ops.js +169 -2
- package/src/edit/core/plan.js +65 -9
- package/src/edit/core/project.d.ts +24 -0
- package/src/edit/core/project.js +64 -0
- package/src/edit/core/solver.js +34 -6
- package/src/edit/core/style-brief.js +211 -0
- package/src/edit/core/style-packs.js +57 -0
- package/src/edit/core/type-kit.js +173 -0
- package/src/edit/director/ask.js +37 -3
- package/src/edit/director/assembly.js +829 -0
- package/src/edit/director/continuity.js +9 -1
- package/src/edit/director/custom-motion.js +88 -0
- package/src/edit/director/graphics.js +44 -10
- package/src/edit/director/intent.js +125 -0
- package/src/edit/director/mentions.js +52 -0
- package/src/edit/director/plan.js +43 -11
- package/src/edit/director/revise.js +132 -9
- package/src/edit/director/viewer.js +136 -0
- package/src/edit/director/watch-fix.js +119 -0
- package/src/edit/engine/captions.js +110 -5
- package/src/edit/engine/confine.js +81 -4
- package/src/edit/engine/custom.js +243 -0
- package/src/edit/engine/dna2.js +893 -0
- package/src/edit/engine/fonts.js +218 -0
- package/src/edit/engine/graphics.js +271 -10
- package/src/edit/engine/index.js +14 -5
- package/src/edit/engine/motion.js +148 -13
- package/src/edit/engine/music-bed.js +59 -1
- package/src/edit/engine/packs.js +11 -0
- package/src/edit/engine/reference2.js +26 -0
- package/src/edit/engine/sfx.js +56 -1
- package/src/edit/engine/tool.js +21 -5
- package/src/edit/gates/assembly.js +194 -0
- package/src/edit/gates/copy.js +7 -4
- package/src/edit/gates/index.js +72 -7
- package/src/edit/gates/reference.js +115 -0
- package/src/edit/gates/tile.js +96 -0
- package/src/edit/host/client.js +8 -3
- package/src/edit/host/clips.js +33 -0
- package/src/edit/host/jobs.js +9 -3
- package/src/edit/host/layers.js +134 -0
- package/src/edit/host/main.js +10 -3
- package/src/edit/host/paths.js +21 -3
- package/src/edit/host/preview.js +108 -0
- package/src/edit/host/projects.js +443 -34
- package/src/edit/host/server.js +235 -20
- package/src/edit/host/tavi.js +77 -0
- package/src/edit/index/index.js +3 -2
- package/src/edit/loop/make.js +28 -3
- package/src/edit/recipes/assembly.js +352 -0
- package/src/edit/recipes/graphic-clips.js +4 -2
- package/src/edit/recipes/openings.js +36 -0
- package/src/edit/recipes/reel.js +104 -14
- package/src/edit/recipes/reference-look.js +29 -0
- package/src/edit/recipes/short-from-long.js +3 -3
- package/src/edit/recipes/sound.js +71 -0
- package/src/edit/runtime/cli.js +26 -5
- package/src/edit/runtime/fetch.js +4 -4
- package/src/edit/runtime/licences.js +7 -1
- package/src/explore.js +103 -0
- package/src/failure.js +1 -1
- package/src/gate-commands.js +114 -0
- package/src/gates/api.js +127 -0
- package/src/gates/commands.js +111 -0
- package/src/gates/detectors.js +370 -0
- package/src/gates/http.js +62 -0
- package/src/gates/index.js +196 -0
- package/src/gates/page.js +264 -0
- package/src/gates/sast.js +64 -0
- package/src/gates/stack.js +110 -0
- package/src/gates/tenant.js +162 -0
- package/src/gates/three.js +431 -0
- package/src/gates/ui.js +111 -0
- package/src/gateway-proxy.js +20 -2
- package/src/launch.js +39 -5
- package/src/loop.js +199 -7
- package/src/mcp.js +126 -0
- package/src/milestones.js +188 -0
- package/src/modes.js +67 -0
- package/src/orchestra.js +50 -0
- package/src/outcomes.js +88 -0
- package/src/profiles.js +5 -0
- package/src/receipts.js +238 -0
- package/src/release.js +356 -0
- package/src/runstrip.js +122 -0
- package/src/stack.js +120 -0
- package/src/verify.js +67 -20
- package/studio/dist/fonts/fraunces.woff2 +0 -0
- package/studio/dist/fonts/geist.woff2 +0 -0
- package/studio/dist/fonts/jetbrains-mono.woff2 +0 -0
- package/studio/dist/studio.css +449 -1
- package/studio/dist/studio.js +3 -3
|
@@ -2,6 +2,8 @@
|
|
|
2
2
|
// looks written as Kriya's own CSS and WAAPI (no GSAP, no Remotion: EDD-08, EDD-09),
|
|
3
3
|
// and each caption a HyperFrames tile, so preview and final match (EDIT_ENGINE §6).
|
|
4
4
|
|
|
5
|
+
import { boxFor, readableColors } from "../core/type-kit.js"
|
|
6
|
+
import { fontFaces, fontsFor, fontStackFor, lineFor } from "./fonts.js"
|
|
5
7
|
import { springKeyframes, tileDocument } from "./motion.js"
|
|
6
8
|
|
|
7
9
|
const FLICKS = 705_600_000
|
|
@@ -27,11 +29,40 @@ export const LOOKS = {
|
|
|
27
29
|
minimal: { font: "sans", weight: 700, size: 0.034, color: "#ffffff", accent: "#ffffff", box: { color: "#000000", alpha: 0.72 }, stroke: null, highlight: false },
|
|
28
30
|
}
|
|
29
31
|
|
|
32
|
+
/**
|
|
33
|
+
* TP7 (CRAFT_UPGRADE §5.3, EDD-67): eight more looks, offered only with editing.typeKit on.
|
|
34
|
+
* Data like the six: words per page (1 to 5), lines, how a word arrives (pop, rise, fade, type
|
|
35
|
+
* on), how the spoken word is marked (colour, box, underline, size), how an emphasised word
|
|
36
|
+
* differs, where the page sits. Web Animations only; QG-08 and QG-09 judge each as before.
|
|
37
|
+
*/
|
|
38
|
+
export const MORE_CAPTION_LOOKS = {
|
|
39
|
+
single: { font: "sans", weight: 900, size: 0.07, color: "#ffffff", accent: "#ffd23f", box: null, stroke: "#000000", highlight: false, words: 1, lines: 1, arrive: "pop", mark: "none", emphasis: "color", place: "middle" },
|
|
40
|
+
duo: { font: "sans", weight: 900, size: 0.06, color: "#ffffff", accent: "#4fd1c5", box: null, stroke: "#000000", highlight: false, words: 2, lines: 1, arrive: "pop", mark: "color", emphasis: "size", place: "middle" },
|
|
41
|
+
marker: { font: "sans", weight: 800, size: 0.05, color: "#ffffff", accent: "#ffd23f", box: null, stroke: "#000000", highlight: false, words: 3, lines: 2, arrive: "rise", mark: "box", emphasis: "box", place: "bottom" },
|
|
42
|
+
underline: { font: "sans", weight: 800, size: 0.046, color: "#ffffff", accent: "#ff7ab6", box: { color: "#0a0a0a", alpha: 0.72 }, stroke: null, highlight: false, words: 4, lines: 2, arrive: "fade", mark: "underline", emphasis: "underline", place: "bottom" },
|
|
43
|
+
grow: { font: "sans", weight: 800, size: 0.05, color: "#ffffff", accent: "#ffb347", box: null, stroke: "#000000", highlight: false, words: 3, lines: 2, arrive: "pop", mark: "size", emphasis: "color", place: "bottom" },
|
|
44
|
+
typewriter: { font: "sans", weight: 700, size: 0.04, color: "#f2eadf", accent: "#ffb347", box: { color: "#13292b", alpha: 0.92 }, stroke: null, highlight: false, words: 5, lines: 2, arrive: "type", mark: "none", emphasis: "color", place: "bottom" },
|
|
45
|
+
headline: { font: "sans", weight: 900, size: 0.052, color: "#ffffff", accent: "#ffd23f", box: { color: "#0a0a0a", alpha: 0.8 }, stroke: null, highlight: false, words: 3, lines: 2, arrive: "rise", mark: "color", emphasis: "box", place: "top", case: "upper" },
|
|
46
|
+
subtle: { font: "sans", weight: 600, size: 0.034, color: "#ffffff", accent: "#cfe8ff", box: { color: "#000000", alpha: 0.6 }, stroke: null, highlight: false, words: 5, lines: 2, arrive: "fade", mark: "color", emphasis: "underline", place: "bottom" },
|
|
47
|
+
}
|
|
48
|
+
export const ALL_LOOKS = { ...LOOKS, ...MORE_CAPTION_LOOKS }
|
|
49
|
+
export const ARRIVALS = ["pop", "rise", "fade", "type"]
|
|
50
|
+
export const MARKS = ["none", "color", "box", "underline", "size"]
|
|
51
|
+
|
|
52
|
+
/** Words per page a look asks for: the six keep 2 to 5, as before. */
|
|
53
|
+
export function pageLimits(id) {
|
|
54
|
+
const words = MORE_CAPTION_LOOKS[id]?.words
|
|
55
|
+
return words ? { min: Math.min(2, words), max: words } : { min: 2, max: 5 }
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
/** Where a look's page sits when it isn't the recipe's row (TP7): "middle" or "top", else nothing. */
|
|
59
|
+
export const placeOf = (id) => (["middle", "top"].includes(MORE_CAPTION_LOOKS[id]?.place) ? MORE_CAPTION_LOOKS[id].place : undefined)
|
|
60
|
+
|
|
30
61
|
const HEX = /^#[0-9a-f]{6}$/i
|
|
31
62
|
|
|
32
63
|
/** A look with the project's typed overrides; anything else in the style is ignored, never passed on. */
|
|
33
64
|
export function lookOf(id, style = {}) {
|
|
34
|
-
const base =
|
|
65
|
+
const base = ALL_LOOKS[id] ?? ALL_LOOKS[style.style] ?? LOOKS.clean
|
|
35
66
|
const look = { ...base }
|
|
36
67
|
if (HEX.test(style.color ?? "")) look.color = style.color
|
|
37
68
|
if (HEX.test(style.accent ?? "")) look.accent = style.accent
|
|
@@ -143,6 +174,15 @@ const ENTRANCE = { damping: 0.7, frequency: 14, ms: 320 }
|
|
|
143
174
|
*/
|
|
144
175
|
export function captionComposition(node, { output, canvas }) {
|
|
145
176
|
const look = lookOf(node.look, node.style)
|
|
177
|
+
// TP7: a project with a type kit draws in its faces and colours; one without draws as it did
|
|
178
|
+
const kit = node.type
|
|
179
|
+
if (kit?.colors) {
|
|
180
|
+
const colors = readableColors({ text: kit.colors.text ?? look.color, accent: kit.colors.accent ?? look.accent, plate: kit.colors.plate }, { plate: !!look.box })
|
|
181
|
+
look.color = colors.text
|
|
182
|
+
look.accent = colors.accent
|
|
183
|
+
look.stroke = colors.stroke
|
|
184
|
+
look.box = colors.plate ? { color: colors.plate, alpha: look.box ? Math.max(look.box.alpha, 0.92) : 0.92 } : null
|
|
185
|
+
}
|
|
146
186
|
const sx = output.width / canvas.width
|
|
147
187
|
const sy = output.height / canvas.height
|
|
148
188
|
const box = node.placement ?? { x: Math.round(canvas.width * 0.1), y: Math.round(canvas.height * 0.7), w: Math.round(canvas.width * 0.8), h: Math.round(canvas.height * 0.12) }
|
|
@@ -150,13 +190,21 @@ export function captionComposition(node, { output, canvas }) {
|
|
|
150
190
|
const area = { x: Math.round(box.x * sx), y: Math.round(box.y * sy), w: Math.round(box.w * sx), h: Math.round(box.h * sy) }
|
|
151
191
|
const plate = look.box ? `background:${look.box.color}${Math.round(look.box.alpha * 255).toString(16).padStart(2, "0")};border-radius:${Math.round(size * 0.35)}px;padding:${Math.round(size * 0.22)}px ${Math.round(size * 0.45)}px;` : ""
|
|
152
192
|
const stroke = look.stroke ? `-webkit-text-stroke:${Math.max(2, Math.round(size * 0.08))}px ${look.stroke};paint-order:stroke fill;` : ""
|
|
193
|
+
const duration = node.duration
|
|
194
|
+
const pageText = node.text ?? node.words.map((w) => w.text).join(" ")
|
|
195
|
+
const face = kit ? (look.weight >= 900 || look.case === "upper" ? kit.heading : kit.body) : null
|
|
196
|
+
// Not shipped here: the kit's own system stacks, no font asked for, so the tile is the same with or without the pack
|
|
197
|
+
const family = face ? fontStackFor(pageText, face.font, kit.shipped ? null : new Set()) : FONTS[look.font]
|
|
198
|
+
const typeCss = face ? `${face.case === "upper" || look.case === "upper" ? "text-transform:uppercase;" : ""}${face.tracking ? `letter-spacing:${face.tracking}em;` : ""}` : look.case === "upper" ? "text-transform:uppercase;" : ""
|
|
153
199
|
const css = [
|
|
200
|
+
face && kit.shipped ? fontFaces(fontsFor(pageText, face.font)) : "",
|
|
154
201
|
`#area{position:absolute;left:${area.x}px;top:${area.y}px;width:${area.w}px;height:${area.h}px;display:flex;align-items:center;justify-content:center}`,
|
|
155
|
-
|
|
202
|
+
// A look that marks the spoken word by size wraps narrower, so the word can grow inside the box
|
|
203
|
+
`#t{max-width:${look.mark === "size" ? Math.floor(area.w / 1.2) : area.w}px;box-sizing:border-box;text-align:center;font-family:${family};font-weight:${look.weight};font-size:${size}px;line-height:${face ? lineFor(pageText, face.font, 1.18) : 1.18};color:${look.color};${plate}${stroke}${typeCss}${look.lines === 1 ? "white-space:nowrap;" : ""}}`,
|
|
156
204
|
`#t span{display:inline-block;white-space:pre}`,
|
|
157
205
|
`#t .e{color:${look.accent}}`,
|
|
206
|
+
look.arrive ? emphasisCss(look, size) : "",
|
|
158
207
|
].join("")
|
|
159
|
-
const duration = node.duration
|
|
160
208
|
// The person's corrected text is what shows (caption_edit): word by word when it has as many
|
|
161
209
|
// words as were said, else as one block (found in ED10: the edit wasn't drawn at all)
|
|
162
210
|
const said = node.words.map((w) => w.text).join(" ")
|
|
@@ -164,7 +212,7 @@ export function captionComposition(node, { output, canvas }) {
|
|
|
164
212
|
const shown = !edited ? node.words : edited.length === node.words.length ? node.words.map((w, i) => ({ ...w, text: edited[i] })) : [{ text: node.text, at: 0, end: duration, emphasis: false }]
|
|
165
213
|
const words = shown.map((word, i) => ({ ...word, id: `w${i}` }))
|
|
166
214
|
const body = `<div id="area"><div id="t" data-text>${words.map((w, i) => `<span id="${w.id}"${w.emphasis ? ' class="e"' : ""} data-at="${ms(w.at)}" data-end="${ms(w.end)}">${i ? " " : ""}${escapeText(w.text)}</span>`).join("")}</div></div>`
|
|
167
|
-
const animations = [{ id: "t", keyframes: springKeyframes({ ...ENTRANCE, from: { y: Math.round(size * 0.6), opacity: 0 }, to: { y: 0, opacity: 1 } }), options: { duration: ENTRANCE.ms, fill: "both" } }]
|
|
215
|
+
const animations = look.arrive ? arrivals(look, words, size, duration) : [{ id: "t", keyframes: springKeyframes({ ...ENTRANCE, from: { y: Math.round(size * 0.6), opacity: 0 }, to: { y: 0, opacity: 1 } }), options: { duration: ENTRANCE.ms, fill: "both" } }]
|
|
168
216
|
if (look.highlight) {
|
|
169
217
|
const total = Math.max(1, ms(duration))
|
|
170
218
|
for (const word of words) {
|
|
@@ -177,7 +225,64 @@ export function captionComposition(node, { output, canvas }) {
|
|
|
177
225
|
}
|
|
178
226
|
}
|
|
179
227
|
// A page fits its placement: the font steps down, never under QG-09's smallest size
|
|
180
|
-
|
|
228
|
+
// A kit page with a script font may step down to QG-09's own floor, not the Latin one (TP7)
|
|
229
|
+
const floor = face && fontsFor(pageText, face.font).length > 1 ? 0.0205 : 0.025
|
|
230
|
+
return tileDocument({ width: output.width, height: output.height, duration, css, body, animations, fit: { id: "t", within: "area", min: Math.ceil(output.height * floor) } })
|
|
231
|
+
}
|
|
232
|
+
|
|
233
|
+
/* ─────────────────────────────── TP7's looks ─────────────────────────────── */
|
|
234
|
+
|
|
235
|
+
// An emphasised word: in the accent, boxed, underlined or larger. A box keeps the page's ink and outline, on the accent moved until that ink holds 4.5:1
|
|
236
|
+
function emphasisCss(look, size) {
|
|
237
|
+
const pad = Math.round(size * 0.12)
|
|
238
|
+
const rules = {
|
|
239
|
+
color: `#t .e{color:${look.accent}}`,
|
|
240
|
+
box: `#t .e{color:${look.color};background:${boxFor(look.accent, look.color)};border-radius:${pad}px;padding:0 ${pad}px}`,
|
|
241
|
+
underline: `#t .e{box-shadow:inset 0 -${Math.max(3, Math.round(size * 0.12))}px 0 ${look.accent}}`,
|
|
242
|
+
size: `#t .e{color:${look.accent};font-size:1.15em}`,
|
|
243
|
+
}
|
|
244
|
+
return rules[look.emphasis] ?? ""
|
|
245
|
+
}
|
|
246
|
+
|
|
247
|
+
/**
|
|
248
|
+
* Each word arrives as it is said, and the spoken word is marked while it is said. Timed on
|
|
249
|
+
* the tile's whole length, so a seek to any frame draws the same.
|
|
250
|
+
*/
|
|
251
|
+
function arrivals(look, words, size, duration) {
|
|
252
|
+
const total = Math.max(1, ms(duration))
|
|
253
|
+
const at = (t) => Math.min(1, Math.max(0, t / total))
|
|
254
|
+
const out = []
|
|
255
|
+
for (const word of words) {
|
|
256
|
+
// A word is fully in by the moment it is said, so a gate reading at a word's start sees it whole
|
|
257
|
+
const on = ms(word.at)
|
|
258
|
+
const arrive = look.arrive === "type" ? 260 : 220
|
|
259
|
+
const a = at(Math.max(0, on - arrive))
|
|
260
|
+
const b = Math.max(a, at(on))
|
|
261
|
+
const from = {
|
|
262
|
+
pop: { transform: "scale(0.6)", opacity: 0 },
|
|
263
|
+
rise: { transform: "scaleY(0.2)", transformOrigin: "50% 100%", opacity: 0 },
|
|
264
|
+
fade: { opacity: 0 },
|
|
265
|
+
type: { clipPath: "inset(0 100% 0 0)" },
|
|
266
|
+
}[look.arrive]
|
|
267
|
+
const to = { pop: { transform: "scale(1)", opacity: 1 }, rise: { transform: "scaleY(1)", transformOrigin: "50% 100%", opacity: 1 }, fade: { opacity: 1 }, type: { clipPath: "inset(0 0% 0 0)" } }[look.arrive]
|
|
268
|
+
out.push({ id: word.id, keyframes: [{ ...from, offset: 0 }, { ...from, offset: a }, { ...to, offset: b }, { ...to, offset: 1 }], options: { duration: total, fill: "both", easing: "linear" } })
|
|
269
|
+
if (look.mark === "none" || word.emphasis) continue
|
|
270
|
+
const lit = Math.max(b, at(ms(word.end)))
|
|
271
|
+
// A mark that doesn't touch what the arrival moves: colour, background, a shadow line, or the size (a second animation on font-size)
|
|
272
|
+
// The size mark is in em, so it follows the page the fit shrank
|
|
273
|
+
const mark = { color: ["color", look.color, look.accent], box: ["backgroundColor", `${boxFor(look.accent, look.color)}00`, boxFor(look.accent, look.color)], underline: ["boxShadow", `inset 0 0 0 ${look.accent}00`, `inset 0 -${Math.max(3, Math.round(size * 0.12))}px 0 ${look.accent}`], size: ["fontSize", "1em", "1.18em"] }[look.mark]
|
|
274
|
+
const [prop, base, on2] = mark
|
|
275
|
+
const frames = [{ [prop]: base, offset: 0 }, { [prop]: base, offset: b }, { [prop]: on2, offset: b }, { [prop]: on2, offset: lit }, { [prop]: base, offset: lit }, { [prop]: base, offset: 1 }]
|
|
276
|
+
out.push({ id: word.id, keyframes: frames, options: { duration: total, fill: "both", easing: "linear" } })
|
|
277
|
+
}
|
|
278
|
+
return out
|
|
279
|
+
}
|
|
280
|
+
|
|
281
|
+
/** When a page with arriving words is all in: QG-10 reads it then (ms into the tile). */
|
|
282
|
+
export function captionAtRest(node) {
|
|
283
|
+
const look = lookOf(node.look, node.style)
|
|
284
|
+
if (!look.arrive) return null
|
|
285
|
+
return Math.max(0, ...node.words.map((w) => ms(w.at))) + 320
|
|
181
286
|
}
|
|
182
287
|
|
|
183
288
|
/** Text for an element's content: markup can't get in (ES-05, ET-SEC-02). */
|
|
@@ -4,11 +4,18 @@
|
|
|
4
4
|
// loopback, no reading people's files, writing only to its own work folder.
|
|
5
5
|
|
|
6
6
|
import { existsSync, realpathSync } from "node:fs"
|
|
7
|
-
import { dirname } from "node:path"
|
|
7
|
+
import { dirname, join } from "node:path"
|
|
8
8
|
|
|
9
|
+
import { activeRuntime } from "../runtime/setup.js"
|
|
9
10
|
import { EngineFailure } from "./tool.js"
|
|
10
11
|
|
|
11
12
|
const SANDBOX_EXEC = "/usr/bin/sandbox-exec"
|
|
13
|
+
// TP11 (EQ-11): Linux's bubblewrap where the distribution puts it; never a PATH lookup a folder could shadow
|
|
14
|
+
export const BWRAP_PATHS = ["/usr/bin/bwrap", "/bin/bwrap", "/usr/local/bin/bwrap"]
|
|
15
|
+
// The system's own read-only parts a confined Chrome needs on Linux (libraries, fonts, certificates); never /home
|
|
16
|
+
const LINUX_SYSTEM = ["/usr", "/lib", "/lib64", "/lib32", "/bin", "/sbin", "/etc/fonts", "/etc/ssl", "/etc/ld.so.cache", "/etc/alternatives"]
|
|
17
|
+
// Windows: an AppContainer runner the Media Runtime ships and verifies by hash (manifest artifact), or nothing
|
|
18
|
+
export const WINDOWS_RUNNER = "appcontainer-runner"
|
|
12
19
|
// Where people's files and other programs' temporary files live
|
|
13
20
|
const PRIVATE = ["/Users", "/Volumes", "/private/tmp", "/private/var/folders", "/private/var/tmp"]
|
|
14
21
|
|
|
@@ -19,13 +26,80 @@ function quoted(path) {
|
|
|
19
26
|
return `"${path}"`
|
|
20
27
|
}
|
|
21
28
|
|
|
22
|
-
/**
|
|
23
|
-
|
|
29
|
+
/**
|
|
30
|
+
* The Windows runner the active Media Runtime installed, verified by hash at install: the manifest's
|
|
31
|
+
* `appcontainer-runner` artifact for win32-x64, present on disk. No signed manifest carries one yet (EQ-11).
|
|
32
|
+
* @returns {string | null}
|
|
33
|
+
*/
|
|
34
|
+
export function windowsRunner(runtime = activeRuntime(), exists = existsSync) {
|
|
35
|
+
const artifact = runtime?.manifest?.platforms?.["win32-x64"]?.artifacts?.find((a) => a.id === WINDOWS_RUNNER)
|
|
36
|
+
if (!artifact || typeof artifact.entry !== "string") return null
|
|
37
|
+
const path = join(runtime.dir, artifact.id, artifact.entry)
|
|
38
|
+
return exists(path) ? path : null
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
/**
|
|
42
|
+
* What this computer can confine with, or why it can't. Never an open process called confined (ES-05):
|
|
43
|
+
* macOS's sandbox-exec, Linux's bubblewrap, or the Windows runner the Media Runtime ships; else none.
|
|
44
|
+
* @returns {{ kind: "sandbox-exec" } | { kind: "bwrap", path: string } | { kind: "appcontainer", path: string } | { kind: null, missing: string }}
|
|
45
|
+
*/
|
|
46
|
+
export function confinement(platform = process.platform, exists = existsSync, { runner = () => windowsRunner(undefined, exists) } = {}) {
|
|
24
47
|
if (platform === "darwin" && exists(SANDBOX_EXEC)) return { kind: "sandbox-exec" }
|
|
25
|
-
|
|
48
|
+
if (platform === "linux") {
|
|
49
|
+
const path = BWRAP_PATHS.find((candidate) => exists(candidate))
|
|
50
|
+
if (path) return { kind: "bwrap", path }
|
|
51
|
+
return { kind: null, missing: "The motion layer runs Chrome inside bubblewrap on Linux, and it isn't installed. Install the bubblewrap package (bwrap), then try again." }
|
|
52
|
+
}
|
|
53
|
+
if (platform === "win32") {
|
|
54
|
+
const path = runner()
|
|
55
|
+
if (path) return { kind: "appcontainer", path }
|
|
56
|
+
return { kind: null, missing: "The motion layer runs Chrome inside an AppContainer on Windows, and this Media Runtime has no runner for it yet." }
|
|
57
|
+
}
|
|
26
58
|
return { kind: null, missing: "The motion layer runs Chrome inside the operating system's sandbox, and this system's sandbox isn't supported yet." }
|
|
27
59
|
}
|
|
28
60
|
|
|
61
|
+
// A path handed to a sandbox: absolute, and nothing that could end an argument or a line
|
|
62
|
+
function plain(path) {
|
|
63
|
+
if (!(path.startsWith("/") || /^[A-Za-z]:\\/.test(path)) || /["\n\r\0]/.test(path)) throw new RangeError(`a confinement path must be a plain absolute path, got "${path}"`)
|
|
64
|
+
return path
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
/**
|
|
68
|
+
* Linux (TP11): bubblewrap's arguments. Every namespace unshared, the network too, so only a loopback of its
|
|
69
|
+
* own exists (Chrome and HyperFrames talk over it; nothing reaches another computer or this one's services);
|
|
70
|
+
* the system's libraries read-only; the runtime read-only; the tile's folder read-write; a private /tmp; it
|
|
71
|
+
* dies with its parent. No /home and no /Users unless a folder asked for sits there, and then only that folder.
|
|
72
|
+
* @param {{ read: string[], write: string[] }} paths absolute; made real here
|
|
73
|
+
*/
|
|
74
|
+
export function bwrapArgs({ read, write }, exists = existsSync) {
|
|
75
|
+
const r = [...new Set(read.map(real).map(plain))]
|
|
76
|
+
const w = [...new Set(write.map(real).map(plain))]
|
|
77
|
+
return [
|
|
78
|
+
"--die-with-parent",
|
|
79
|
+
"--new-session",
|
|
80
|
+
"--unshare-all",
|
|
81
|
+
"--cap-drop",
|
|
82
|
+
"ALL",
|
|
83
|
+
...LINUX_SYSTEM.filter((p) => exists(p)).flatMap((p) => ["--ro-bind", p, p]),
|
|
84
|
+
"--proc",
|
|
85
|
+
"/proc",
|
|
86
|
+
"--dev",
|
|
87
|
+
"/dev",
|
|
88
|
+
"--tmpfs",
|
|
89
|
+
"/tmp",
|
|
90
|
+
...r.flatMap((p) => ["--ro-bind", p, p]),
|
|
91
|
+
...w.flatMap((p) => ["--bind", p, p]),
|
|
92
|
+
]
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
/**
|
|
96
|
+
* Windows (TP11): the runner's arguments, a seam for the runner the Media Runtime will ship. The folders it
|
|
97
|
+
* may read and write, loopback only, then the command. Nothing here runs until a verified runner exists.
|
|
98
|
+
*/
|
|
99
|
+
export function appContainerArgs({ read, write }) {
|
|
100
|
+
return [...read.map(plain).flatMap((p) => ["--read", p]), ...write.map(plain).flatMap((p) => ["--write", p]), "--network", "loopback", "--"]
|
|
101
|
+
}
|
|
102
|
+
|
|
29
103
|
/**
|
|
30
104
|
* The macOS profile. Later rules win in SBPL, so the denials come first and the few
|
|
31
105
|
* folders a render needs are let back in.
|
|
@@ -60,6 +134,9 @@ export function sandboxProfile({ read, write }) {
|
|
|
60
134
|
*/
|
|
61
135
|
export function confine(command, args, paths, which = confinement()) {
|
|
62
136
|
if (!which.kind) throw new EngineFailure("environment", "no_confinement", which.missing)
|
|
137
|
+
if (which.kind === "bwrap") return { command: which.path, args: [...bwrapArgs(paths), "--", command, ...args] }
|
|
138
|
+
if (which.kind === "appcontainer") return { command: which.path, args: [...appContainerArgs(paths), command, ...args] }
|
|
139
|
+
if (which.kind !== "sandbox-exec") throw new EngineFailure("environment", "no_confinement", "This sandbox isn't one Kriya knows.")
|
|
63
140
|
return { command: SANDBOX_EXEC, args: ["-p", sandboxProfile(paths), command, ...args] }
|
|
64
141
|
}
|
|
65
142
|
|
|
@@ -0,0 +1,243 @@
|
|
|
1
|
+
// Custom motion (MG2, TP9; DIRECTOR_AND_AGENT §11, EDD-44): the one place a model's design becomes a
|
|
2
|
+
// tile. The model never writes script: it sends CSS, a small body of allow-listed elements and its Web
|
|
3
|
+
// Animations as data. This file checks those parts structurally (an allow-list, not a deny-list); the
|
|
4
|
+
// document around them is Kriya's (motion.js customDocument), and customComposition then lints the
|
|
5
|
+
// whole document and puts Kriya's CSP first. Every visible word arrives through a slot, as data, so it
|
|
6
|
+
// is grounded by code and escaped by code (ET-SEC-02); the markup itself may hold no text at all.
|
|
7
|
+
|
|
8
|
+
export const CUSTOM_BLOCK = "custom"
|
|
9
|
+
export const CUSTOM_VERSION = 1
|
|
10
|
+
export const LIMITS = { css: 20_000, body: 20_000, elements: 400, depth: 24, animations: 24, keyframes: 32, texts: 6, text: 80, name: 40, ms: 60_000 }
|
|
11
|
+
// Ids Kriya's document uses itself: the model can't style or animate them
|
|
12
|
+
const RESERVED = new Set(["stage", "clip", "mg"])
|
|
13
|
+
const TAGS = new Set(["div", "span", "svg", "g", "path", "circle", "ellipse", "rect", "line", "polyline", "polygon"])
|
|
14
|
+
const ATTRS = new Set(["id", "class", "data-slot", "viewBox", "d", "cx", "cy", "r", "rx", "ry", "x", "y", "x1", "y1", "x2", "y2", "width", "height", "points", "fill", "stroke", "stroke-width", "stroke-linecap", "stroke-linejoin", "stroke-dasharray", "stroke-dashoffset", "opacity", "fill-opacity", "stroke-opacity", "transform", "preserveAspectRatio"])
|
|
15
|
+
const IDENT = /^[A-Za-z][A-Za-z0-9_-]{0,31}$/
|
|
16
|
+
// An attribute's or a keyframe's value: no colon (no scheme), no slash (no //host), no quote, no backslash, no angle bracket
|
|
17
|
+
const VALUE = /^[A-Za-z0-9 #.,%()_+-]*$/
|
|
18
|
+
const EASING = /^(?:linear|ease|ease-in|ease-out|ease-in-out|step-start|step-end|cubic-bezier\(\s*-?\d*\.?\d+(?:\s*,\s*-?\d*\.?\d+){3}\s*\)|steps\(\s*\d{1,3}\s*(?:,\s*(?:start|end|jump-start|jump-end|jump-none|jump-both))?\s*\))$/
|
|
19
|
+
const KEYFRAME_PROPS = new Set(["offset", "easing", "opacity", "transform", "color", "backgroundColor", "fill", "stroke", "strokeDashoffset", "strokeDasharray", "strokeWidth", "clipPath", "width", "height", "left", "top", "right", "bottom", "borderRadius", "filter"])
|
|
20
|
+
const OPTIONS = { duration: "ms", delay: "ms", endDelay: "ms", iterations: "count", easing: "easing", fill: ["none", "forwards", "backwards", "both", "auto"], direction: ["normal", "reverse", "alternate", "alternate-reverse"] }
|
|
21
|
+
const PSEUDO = new Set(["first-child", "last-child", "nth-child", "nth-of-type", "before", "after", "not"])
|
|
22
|
+
|
|
23
|
+
/** The parts' schema for the model: only data, no script. */
|
|
24
|
+
export const PARTS_SCHEMA = {
|
|
25
|
+
type: "object",
|
|
26
|
+
properties: {
|
|
27
|
+
name: { type: "string", maxLength: LIMITS.name },
|
|
28
|
+
css: { type: "string", maxLength: LIMITS.css },
|
|
29
|
+
body: { type: "string", maxLength: LIMITS.body },
|
|
30
|
+
animations: { type: "array", maxItems: LIMITS.animations, items: { type: "object" } },
|
|
31
|
+
texts: { type: "array", maxItems: LIMITS.texts, items: { type: "string", maxLength: LIMITS.text } },
|
|
32
|
+
},
|
|
33
|
+
required: ["css", "body", "animations", "texts"],
|
|
34
|
+
additionalProperties: false,
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
// Words on screen: one line of text, markup characters gone, control characters (but a newline) gone
|
|
38
|
+
export const cleanSlotText = (text) => String(text).replace(/[\u0000-\u0009\u000b-\u001f\u007f]/g, " ").trim()
|
|
39
|
+
|
|
40
|
+
/**
|
|
41
|
+
* The body, parsed against the allow-list and written out again in a canonical form, so what renders
|
|
42
|
+
* is exactly what passed. Slots come out as `<span data-slot="0" data-text>⟦0⟧</span>`, filled later.
|
|
43
|
+
* @returns {{ html: string, stored: string, ids: Set<string>, slots: number[] } | { problem: string }}
|
|
44
|
+
*/
|
|
45
|
+
export function parseBody(body) {
|
|
46
|
+
if (typeof body !== "string" || body.length > LIMITS.body) return { problem: `the body is text of up to ${LIMITS.body} characters` }
|
|
47
|
+
const TOKEN = /<\/([A-Za-z][A-Za-z0-9]*)\s*>|<([A-Za-z][A-Za-z0-9]*)((?:\s+[A-Za-z][A-Za-z0-9:-]*\s*=\s*"[^"<>]*")*)\s*(\/?)>|([^<]+)|(<)/gy
|
|
48
|
+
const ATTR = /\s+([A-Za-z][A-Za-z0-9:-]*)\s*=\s*"([^"<>]*)"/g
|
|
49
|
+
const out = []
|
|
50
|
+
const stored = [] // the same, slots empty: what a project keeps, parsed again before every render
|
|
51
|
+
const stack = []
|
|
52
|
+
const ids = new Set()
|
|
53
|
+
const slots = []
|
|
54
|
+
let elements = 0
|
|
55
|
+
for (let m = TOKEN.exec(body); m; m = TOKEN.exec(body)) {
|
|
56
|
+
const [, close, open, attrs, selfClose, text, stray] = m
|
|
57
|
+
if (stray) return { problem: "the body has a stray <" }
|
|
58
|
+
if (text !== undefined) {
|
|
59
|
+
// Every visible word comes through a slot, as data; markup holds none
|
|
60
|
+
if (/\S/.test(text)) return { problem: "the body has text in it; put words in `texts` and a <span data-slot> where each goes" }
|
|
61
|
+
continue
|
|
62
|
+
}
|
|
63
|
+
if (close) {
|
|
64
|
+
const tag = close.toLowerCase()
|
|
65
|
+
if (stack.pop() !== tag) return { problem: `</${tag}> closes nothing open` }
|
|
66
|
+
out.push(`</${tag}>`)
|
|
67
|
+
stored.push(`</${tag}>`)
|
|
68
|
+
continue
|
|
69
|
+
}
|
|
70
|
+
const tag = open.toLowerCase()
|
|
71
|
+
if (!TAGS.has(tag)) return { problem: `<${tag}> isn't allowed: ${[...TAGS].join(", ")}` }
|
|
72
|
+
if (++elements > LIMITS.elements) return { problem: `the body has more than ${LIMITS.elements} elements` }
|
|
73
|
+
if (stack.length >= LIMITS.depth) return { problem: `the body nests deeper than ${LIMITS.depth}` }
|
|
74
|
+
const parts = []
|
|
75
|
+
const seen = new Set()
|
|
76
|
+
let slot = null
|
|
77
|
+
for (const [, rawName, value] of attrs.matchAll(ATTR)) {
|
|
78
|
+
const name = rawName === "viewBox" || rawName === "preserveAspectRatio" ? rawName : rawName.toLowerCase()
|
|
79
|
+
if (!ATTRS.has(name)) return { problem: `the attribute ${rawName} isn't allowed` }
|
|
80
|
+
if (seen.has(name)) return { problem: `${name} is given twice` }
|
|
81
|
+
seen.add(name)
|
|
82
|
+
if (!VALUE.test(value) || /url\s*\(|expression|javascript/i.test(value)) return { problem: `${name}="${value.slice(0, 40)}" has characters that aren't allowed` }
|
|
83
|
+
if (name === "id") {
|
|
84
|
+
if (!IDENT.test(value) || RESERVED.has(value)) return { problem: `the id "${value}" isn't allowed` }
|
|
85
|
+
if (ids.has(value)) return { problem: `the id "${value}" is used twice` }
|
|
86
|
+
ids.add(value)
|
|
87
|
+
}
|
|
88
|
+
if (name === "class" && !value.split(/\s+/).filter(Boolean).every((c) => IDENT.test(c))) return { problem: `the class "${value}" isn't allowed` }
|
|
89
|
+
if (name === "data-slot") {
|
|
90
|
+
if (!/^[0-9]$/.test(value) || !["span", "div"].includes(tag)) return { problem: "a data-slot is a digit, on a span or a div" }
|
|
91
|
+
slot = Number(value)
|
|
92
|
+
if (slots.includes(slot)) return { problem: `slot ${slot} is used twice` }
|
|
93
|
+
slots.push(slot)
|
|
94
|
+
}
|
|
95
|
+
parts.push(`${name}="${value}"`)
|
|
96
|
+
}
|
|
97
|
+
if (slot !== null) {
|
|
98
|
+
// A slot holds its words and nothing else
|
|
99
|
+
if (selfClose) return { problem: "a slot needs a closing tag" }
|
|
100
|
+
const end = new RegExp(`\\s*</${tag}\\s*>`, "y")
|
|
101
|
+
end.lastIndex = TOKEN.lastIndex
|
|
102
|
+
if (!end.test(body)) return { problem: `slot ${slot} must be empty: its words come from \`texts\`` }
|
|
103
|
+
TOKEN.lastIndex = end.lastIndex
|
|
104
|
+
out.push(`<${tag} ${parts.join(" ")} data-text>⟦${slot}⟧</${tag}>`)
|
|
105
|
+
stored.push(`<${tag} ${parts.join(" ")}></${tag}>`)
|
|
106
|
+
continue
|
|
107
|
+
}
|
|
108
|
+
if (selfClose) {
|
|
109
|
+
if (["div", "span"].includes(tag)) return { problem: `<${tag}/> can't close itself` }
|
|
110
|
+
out.push(`<${tag}${parts.length ? ` ${parts.join(" ")}` : ""}/>`)
|
|
111
|
+
} else {
|
|
112
|
+
stack.push(tag)
|
|
113
|
+
out.push(`<${tag}${parts.length ? ` ${parts.join(" ")}` : ""}>`)
|
|
114
|
+
}
|
|
115
|
+
stored.push(out.at(-1))
|
|
116
|
+
}
|
|
117
|
+
if (stack.length) return { problem: `<${stack.at(-1)}> is never closed` }
|
|
118
|
+
return { html: out.join(""), stored: stored.join(""), ids, slots }
|
|
119
|
+
}
|
|
120
|
+
|
|
121
|
+
/**
|
|
122
|
+
* The CSS: printable ASCII, no comments, escapes, imports, fonts, addresses or generated text; each
|
|
123
|
+
* rule's prelude a selector of allowed tags, ids and classes, or one @keyframes.
|
|
124
|
+
* @returns {string | null} why it is refused
|
|
125
|
+
*/
|
|
126
|
+
export function cssProblem(css) {
|
|
127
|
+
if (typeof css !== "string" || css.length > LIMITS.css) return `the CSS is text of up to ${LIMITS.css} characters`
|
|
128
|
+
if (/[^\x20-\x7e\n\t]/.test(css)) return "the CSS has characters outside plain ASCII"
|
|
129
|
+
// No < (it could close the style element), no backslash (escapes hide words), no comments (they hide preludes)
|
|
130
|
+
if (/[<\\]|\/\*|\*\//.test(css)) return "the CSS has <, a backslash or a comment"
|
|
131
|
+
if (/@(?!keyframes\b)/i.test(css)) return "the only at-rule allowed is @keyframes"
|
|
132
|
+
if (/\b(?:url|image|image-set|element|expression|attr|counter|counters|paint|env)\s*\(|-moz-binding|behavior\s*:/i.test(css)) return "the CSS loads, builds or reads something from outside"
|
|
133
|
+
if (/\bcontent\s*:\s*(?!(?:""|''|none)\s*(?:;|}|!))/i.test(css)) return 'only an empty `content: ""` is allowed: words come from `texts`'
|
|
134
|
+
if (/position\s*:\s*fixed/i.test(css)) return "position: fixed isn't allowed"
|
|
135
|
+
let depth = 0
|
|
136
|
+
let since = 0
|
|
137
|
+
let inKeyframes = -1
|
|
138
|
+
for (let i = 0; i < css.length; i++) {
|
|
139
|
+
const c = css[i]
|
|
140
|
+
if (c === "{") {
|
|
141
|
+
const prelude = css.slice(since, i).trim()
|
|
142
|
+
const why = inKeyframes >= 0 && depth > inKeyframes ? (/^(?:from|to|\d{1,3}(?:\.\d+)?%)(?:\s*,\s*(?:from|to|\d{1,3}(?:\.\d+)?%))*$/.test(prelude) ? null : `"${prelude.slice(0, 40)}" isn't a keyframe`) : preludeProblem(prelude)
|
|
143
|
+
if (why) return why
|
|
144
|
+
if (/^@keyframes/i.test(prelude)) {
|
|
145
|
+
if (depth !== 0) return "@keyframes must be at the top level"
|
|
146
|
+
inKeyframes = depth
|
|
147
|
+
}
|
|
148
|
+
depth++
|
|
149
|
+
since = i + 1
|
|
150
|
+
} else if (c === "}") {
|
|
151
|
+
depth--
|
|
152
|
+
if (depth < 0) return "the CSS closes a } it never opened"
|
|
153
|
+
if (depth === inKeyframes) inKeyframes = -1
|
|
154
|
+
since = i + 1
|
|
155
|
+
} else if (c === ";") since = i + 1
|
|
156
|
+
}
|
|
157
|
+
if (depth !== 0) return "the CSS leaves a { open"
|
|
158
|
+
return null
|
|
159
|
+
}
|
|
160
|
+
|
|
161
|
+
function preludeProblem(prelude) {
|
|
162
|
+
if (/^@keyframes\s+[A-Za-z][A-Za-z0-9_-]{0,31}$/i.test(prelude)) return null
|
|
163
|
+
if (!prelude || !/^[A-Za-z0-9#.\s>+~,:()_-]+$/.test(prelude)) return `the selector "${prelude.slice(0, 40)}" isn't allowed`
|
|
164
|
+
for (const selector of prelude.split(",")) {
|
|
165
|
+
const words = selector.replace(/::?([a-z-]+)(\([^)]*\))?/g, (_, name) => (PSEUDO.has(name) ? " " : " \u0000 "))
|
|
166
|
+
if (words.includes("\u0000")) return `the selector "${selector.trim().slice(0, 40)}" uses a pseudo-class that isn't allowed`
|
|
167
|
+
for (const id of words.matchAll(/#([A-Za-z0-9_-]+)/g)) if (RESERVED.has(id[1])) return `#${id[1]} is Kriya's own and can't be styled`
|
|
168
|
+
const tags = words.replace(/[#.][A-Za-z0-9_-]+/g, " ").split(/[\s>+~]+/).filter(Boolean)
|
|
169
|
+
for (const tag of tags) if (!TAGS.has(tag.toLowerCase())) return `the selector names "${tag}", which isn't an allowed element`
|
|
170
|
+
}
|
|
171
|
+
return null
|
|
172
|
+
}
|
|
173
|
+
|
|
174
|
+
/** The animations as data: each on an element of the body, keyframes of allowed properties and values, finite. @returns {string | null} */
|
|
175
|
+
export function animationsProblem(animations, ids) {
|
|
176
|
+
if (!Array.isArray(animations) || animations.length > LIMITS.animations) return `animations is a list of up to ${LIMITS.animations}`
|
|
177
|
+
for (const [i, a] of animations.entries()) {
|
|
178
|
+
const at = `animation ${i + 1}`
|
|
179
|
+
if (!a || typeof a !== "object" || Array.isArray(a) || Object.keys(a).some((k) => !["id", "keyframes", "options"].includes(k))) return `${at} is { id, keyframes, options }`
|
|
180
|
+
if (typeof a.id !== "string" || !ids.has(a.id)) return `${at} animates an id the body doesn't have`
|
|
181
|
+
if (!Array.isArray(a.keyframes) || a.keyframes.length < 1 || a.keyframes.length > LIMITS.keyframes) return `${at} has 1 to ${LIMITS.keyframes} keyframes`
|
|
182
|
+
for (const frame of a.keyframes) {
|
|
183
|
+
if (!frame || typeof frame !== "object" || Array.isArray(frame)) return `${at}: a keyframe is an object`
|
|
184
|
+
for (const [key, value] of Object.entries(frame)) {
|
|
185
|
+
if (!KEYFRAME_PROPS.has(key)) return `${at}: the property ${key} isn't allowed`
|
|
186
|
+
if (key === "offset") {
|
|
187
|
+
if (typeof value !== "number" || !(value >= 0 && value <= 1)) return `${at}: an offset is a number from 0 to 1`
|
|
188
|
+
} else if (key === "easing") {
|
|
189
|
+
if (typeof value !== "string" || !EASING.test(value)) return `${at}: that easing isn't allowed`
|
|
190
|
+
} else if (typeof value === "number") {
|
|
191
|
+
if (!Number.isFinite(value)) return `${at}: ${key} isn't a finite number`
|
|
192
|
+
} else if (typeof value !== "string" || value.length > 200 || !VALUE.test(value) || /url\s*\(|expression|attr\s*\(/i.test(value)) return `${at}: ${key} has characters that aren't allowed`
|
|
193
|
+
}
|
|
194
|
+
}
|
|
195
|
+
const options = a.options ?? {}
|
|
196
|
+
if (typeof options !== "object" || Array.isArray(options)) return `${at}: options is an object`
|
|
197
|
+
for (const [key, value] of Object.entries(options)) {
|
|
198
|
+
const rule = OPTIONS[key]
|
|
199
|
+
if (!rule) return `${at}: the option ${key} isn't allowed`
|
|
200
|
+
if (rule === "ms" && !(Number.isInteger(value) && value >= 0 && value <= LIMITS.ms)) return `${at}: ${key} is whole milliseconds up to ${LIMITS.ms}`
|
|
201
|
+
// Finite only, so every frame of the tile is decided by its time (no "Infinity" that never ends)
|
|
202
|
+
if (rule === "count" && !(Number.isInteger(value) && value >= 1 && value <= 50)) return `${at}: iterations is a whole number from 1 to 50`
|
|
203
|
+
if (rule === "easing" && !(typeof value === "string" && EASING.test(value))) return `${at}: that easing isn't allowed`
|
|
204
|
+
if (Array.isArray(rule) && !rule.includes(value)) return `${at}: ${key} is one of ${rule.join(", ")}`
|
|
205
|
+
}
|
|
206
|
+
if (!Number.isInteger(options.duration) || options.duration < 1) return `${at} needs a duration in whole milliseconds`
|
|
207
|
+
}
|
|
208
|
+
return null
|
|
209
|
+
}
|
|
210
|
+
|
|
211
|
+
/**
|
|
212
|
+
* Every structural problem of a model's parts, or none. Words are checked by the caller (they need the
|
|
213
|
+
* transcript); here only that each text has its slot and each slot its text.
|
|
214
|
+
* @returns {{ problems: string[], parsed?: { html: string, ids: Set<string>, slots: number[] }, texts?: string[] }}
|
|
215
|
+
*/
|
|
216
|
+
export function partsProblems(parts) {
|
|
217
|
+
if (!parts || typeof parts !== "object" || Array.isArray(parts)) return { problems: ["the answer is { css, body, animations, texts }"] }
|
|
218
|
+
const problems = []
|
|
219
|
+
const parsed = parseBody(parts.body)
|
|
220
|
+
if (parsed.problem) problems.push(parsed.problem)
|
|
221
|
+
const css = cssProblem(parts.css)
|
|
222
|
+
if (css) problems.push(css)
|
|
223
|
+
if (!parsed.problem) {
|
|
224
|
+
const why = animationsProblem(parts.animations, parsed.ids)
|
|
225
|
+
if (why) problems.push(why)
|
|
226
|
+
}
|
|
227
|
+
const texts = Array.isArray(parts.texts) ? parts.texts.map(cleanSlotText) : null
|
|
228
|
+
if (!texts || texts.length > LIMITS.texts || texts.some((t) => !t || t.length > LIMITS.text)) problems.push(`texts is a list of up to ${LIMITS.texts} non-empty lines of up to ${LIMITS.text} characters`)
|
|
229
|
+
else if (!parsed.problem) {
|
|
230
|
+
for (let i = 0; i < texts.length; i++) if (!parsed.slots.includes(i)) problems.push(`text ${i} has no <span data-slot="${i}">`)
|
|
231
|
+
for (const slot of parsed.slots) if (slot >= texts.length) problems.push(`slot ${slot} has no text`)
|
|
232
|
+
}
|
|
233
|
+
if (parts.name !== undefined && (typeof parts.name !== "string" || parts.name.length > LIMITS.name)) problems.push(`a name is up to ${LIMITS.name} characters`)
|
|
234
|
+
return problems.length ? { problems } : { problems, parsed, texts }
|
|
235
|
+
}
|
|
236
|
+
|
|
237
|
+
/** The stored block's variables, from parts that passed: canonical body, cleaned texts. */
|
|
238
|
+
export function customVariables(parts) {
|
|
239
|
+
const { problems, parsed, texts } = partsProblems(parts)
|
|
240
|
+
if (problems.length) return null
|
|
241
|
+
const name = typeof parts.name === "string" ? parts.name.replace(/[\u0000-\u001f<>]/g, " ").trim().slice(0, LIMITS.name) : ""
|
|
242
|
+
return { ...(name ? { name } : {}), css: parts.css, body: parsed.stored, animations: parts.animations, texts }
|
|
243
|
+
}
|