@kriya-ai/harness 0.2.4 → 2.0.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/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 +49 -0
- package/contract/SOURCE.md +3 -3
- package/contract/contract.json +504 -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 +376 -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 +426 -0
- package/plugins/runstrip/index.js +301 -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 +82 -5
- package/src/edit/core/layout.js +46 -1
- package/src/edit/core/ops.js +175 -3
- package/src/edit/core/plan.js +95 -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/transitions.js +17 -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 +137 -0
- package/src/edit/director/custom-motion.js +88 -0
- package/src/edit/director/graphics.js +186 -0
- package/src/edit/director/intent.js +125 -0
- package/src/edit/director/mentions.js +52 -0
- package/src/edit/director/plan.js +89 -12
- package/src/edit/director/revise.js +172 -7
- 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 +439 -0
- package/src/edit/engine/index.js +14 -5
- package/src/edit/engine/motion.js +153 -14
- 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 +76 -8
- package/src/edit/gates/picture.js +6 -3
- package/src/edit/gates/reference.js +115 -0
- package/src/edit/gates/tile.js +96 -0
- package/src/edit/host/client.js +4 -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 +17 -7
- package/src/edit/host/paths.js +34 -3
- package/src/edit/host/preview.js +108 -0
- package/src/edit/host/projects.js +494 -29
- package/src/edit/host/server.js +263 -19
- package/src/edit/host/tavi.js +77 -0
- package/src/edit/loop/make.js +44 -3
- package/src/edit/recipes/assembly.js +352 -0
- package/src/edit/recipes/graphic-clips.js +59 -0
- package/src/edit/recipes/openings.js +36 -0
- package/src/edit/recipes/reel.js +138 -17
- 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 -3
- 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 +407 -0
- package/src/gates/ui.js +111 -0
- package/src/launch.js +15 -3
- package/src/loop.js +199 -7
- package/src/mcp.js +126 -0
- package/src/milestones.js +188 -0
- package/src/modes.js +32 -0
- package/src/orchestra.js +43 -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 +452 -3
- package/studio/dist/studio.js +3 -3
|
@@ -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
|
+
}
|