@field/cascade 0.10.0 → 0.12.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/AGENTS.md +25 -5
- package/ARCHITECTURE.md +5 -4
- package/CHANGELOG.md +382 -0
- package/README.md +1 -2
- package/dist/assets/AgentPanel-1JugFjE4.css +1 -0
- package/dist/assets/AgentPanel-BDL5MddA.js +5 -0
- package/dist/assets/{CodeEditor-DSZBpzdy.js → CodeEditor-C-xYG-Wn.js} +120 -120
- package/dist/assets/CodePanel-CtXd50m6.js +2 -0
- package/dist/assets/CookInfoPanel-B3NMhKJF.css +1 -0
- package/dist/assets/CookInfoPanel-DG4_TRsX.js +2 -0
- package/dist/assets/CustomNodeDialog-CHfZUs-r.js +1 -0
- package/dist/assets/DefinitionNode-CaRTXQ_b.js +1 -0
- package/dist/assets/DefinitionPanel-C3CxZY9r.js +1 -0
- package/dist/assets/DefinitionPanel-VNLnAiQD.css +1 -0
- package/dist/assets/OpenGraphDialog-BLdr6k_q.js +1 -0
- package/dist/assets/ProjectSettings-ZnvmIAir.js +2 -0
- package/dist/assets/{SettingsDialog-p25h3tj0.js → SettingsDialog-CBX3Wa87.js} +1 -1
- package/dist/assets/TimelinePanel-CDeR0arY.css +1 -0
- package/dist/assets/TimelinePanel-CWgnFH1e.js +1 -0
- package/dist/assets/{VersionHistoryDialog-DzFLUotB.js → VersionHistoryDialog-BOSoW1R-.js} +1 -1
- package/dist/assets/assert-BO2_erPD.js +1 -0
- package/dist/assets/assert-hvykGCnP.js +1 -0
- package/dist/assets/builder-BmBKcDix.js +1 -0
- package/dist/assets/camera-DFF7YA3F.js +1 -0
- package/dist/assets/checks-DAvyO9Gf.js +1 -0
- package/dist/assets/contactSheet-N1NcaWxw.js +2 -0
- package/dist/assets/{core-BICrEt0y.js → core-DB-MkGjj.js} +3 -4
- package/dist/assets/coreTypes-DtnDATZ7.js +1 -0
- package/dist/assets/{cssMode-D7TXw57I.js → cssMode-DPVckSOc.js} +1 -1
- package/dist/assets/definitions-B227e7f_.js +1 -0
- package/dist/assets/definitions-D0WOUJd7.js +1 -0
- package/dist/assets/{editor.api-DvkCO3ko.js → editor.api-Dkutg_Z1.js} +1 -1
- package/dist/assets/expressions-X-Z-GrgW.js +5 -0
- package/dist/assets/file-DAL6IfjV.js +1 -0
- package/dist/assets/filters-D3k1LRMa.js +1 -0
- package/dist/assets/{freemarker2-BA2lxsF1.js → freemarker2-CLiLKk3B.js} +1 -1
- package/dist/assets/generators-BhDxRAFC.js +1 -0
- package/dist/assets/geo-BsMImJIJ.js +1 -0
- package/dist/assets/geo-C4YngDob.js +2 -0
- package/dist/assets/{handlebars-BcDiyPd8.js → handlebars-CcD3aMeL.js} +1 -1
- package/dist/assets/{html-C7O4TyhX.js → html-DvZWGfqb.js} +1 -1
- package/dist/assets/{htmlMode-WaDGF3Mj.js → htmlMode-DUD3VaoN.js} +1 -1
- package/dist/assets/image-0SfH-snh.js +1 -0
- package/dist/assets/image-Ck-RdGU4.js +2 -0
- package/dist/assets/index-BWnrmIB9.js +137 -0
- package/dist/assets/index-DIaxEONI.css +1 -0
- package/dist/assets/io-BGmt2g0D.js +1 -0
- package/dist/assets/{javascript-CpIEK7tz.js → javascript-Cap2ahgh.js} +1 -1
- package/dist/assets/{jsonMode-B2FltW0f.js → jsonMode-B0uLjp9C.js} +1 -1
- package/dist/assets/{liquid-CN6FFHZE.js → liquid-CnxwhfLn.js} +1 -1
- package/dist/assets/{lspLanguageFeatures-QhV9XtLp.js → lspLanguageFeatures-Dn9hlKX6.js} +1 -1
- package/dist/assets/math-GeULS-sk.js +1 -0
- package/dist/assets/{mdx-DE89pafV.js → mdx-BV3jbrVa.js} +1 -1
- package/dist/assets/pop-KMF_qloi.js +1 -0
- package/dist/assets/preload-helper-Czpn1I53.js +1 -0
- package/dist/assets/{python-ByTllTB9.js → python-CGyFk4XK.js} +1 -1
- package/dist/assets/{razor-USYlRRCE.js → razor-CQfzX3-N.js} +1 -1
- package/dist/assets/remap-5SjXQU-q.js +1 -0
- package/dist/assets/renderMarkdown-ork0Oir7.js +67 -0
- package/dist/assets/studioImages-CAyH-0Pl.js +1 -0
- package/dist/assets/text-ZpX7qNkx.js +2 -0
- package/dist/assets/time-P_OiBhcf.js +1 -0
- package/dist/assets/{tsMode-BXpN8iUz.js → tsMode-BOeXzO9H.js} +1 -1
- package/dist/assets/{typescript-DInBjGQQ.js → typescript-J1SnE_Tu.js} +1 -1
- package/dist/assets/{workers-C7Ye5B7D.js → workers-CYwwTiVF.js} +1 -1
- package/dist/assets/{xml-U0Uocqyo.js → xml-DnPRNzK9.js} +1 -1
- package/dist/assets/{yaml-CBw_PVYf.js → yaml-BmmYBNa9.js} +1 -1
- package/dist/cli/DefinitionNode-P7AA4TAU.js +15 -0
- package/dist/cli/Graph-OB6EWSGL.js +2975 -0
- package/dist/cli/assert-GROGQNCQ.js +25 -0
- package/dist/cli/checks-3WB44XBL.js +189 -0
- package/dist/cli/chunk-2JEU3MGB.js +1125 -0
- package/dist/cli/chunk-2KXB47FP.js +115 -0
- package/dist/cli/chunk-3RXL5GHB.js +816 -0
- package/dist/cli/chunk-53LGFPWX.js +138 -0
- package/dist/cli/chunk-5ORUQ6ES.js +267 -0
- package/dist/cli/chunk-73S4JZXK.js +336 -0
- package/dist/cli/chunk-7QE2ZNSN.js +121 -0
- package/dist/cli/chunk-BP7UKF36.js +376 -0
- package/dist/cli/chunk-BPODRH52.js +201 -0
- package/dist/cli/chunk-BZ63XQ3I.js +1301 -0
- package/dist/cli/chunk-CKS2FQWR.js +89 -0
- package/dist/cli/chunk-CO22XHNG.js +593 -0
- package/dist/cli/chunk-CTPLRSWF.js +2197 -0
- package/dist/cli/chunk-DEQSEFFH.js +153 -0
- package/dist/cli/chunk-EU4ZFZ7Y.js +122 -0
- package/dist/cli/chunk-EZRWJ4G2.js +104 -0
- package/dist/cli/chunk-FWMSGKEH.js +71 -0
- package/dist/cli/chunk-G23A2BZZ.js +705 -0
- package/dist/cli/chunk-GRIN2DDP.js +1465 -0
- package/dist/cli/chunk-HFHWYL55.js +139 -0
- package/dist/cli/chunk-HSNOBIVT.js +263 -0
- package/dist/cli/chunk-ICH7N5PN.js +26 -0
- package/dist/cli/chunk-J7VK7MNF.js +418 -0
- package/dist/cli/chunk-JVOCK5W4.js +83 -0
- package/dist/cli/chunk-KBGUO27Q.js +15 -0
- package/dist/cli/chunk-KH4MUBKF.js +1551 -0
- package/dist/cli/chunk-L6B6FUQP.js +330 -0
- package/dist/cli/chunk-LTXWBXOM.js +438 -0
- package/dist/cli/chunk-MI5JLQYA.js +220 -0
- package/dist/cli/chunk-MP653A5O.js +3766 -0
- package/dist/cli/chunk-NJFMDXHR.js +320 -0
- package/dist/cli/chunk-OM6BEME6.js +267 -0
- package/dist/cli/chunk-OWWBYLHC.js +136 -0
- package/dist/cli/chunk-QQPA2ZHH.js +273 -0
- package/dist/cli/chunk-RUU3YWXU.js +99 -0
- package/dist/cli/chunk-RXDIMXN5.js +98 -0
- package/dist/cli/chunk-ST6LROUG.js +267 -0
- package/dist/cli/chunk-TJW67QSI.js +225 -0
- package/dist/cli/chunk-WD62JIP6.js +118 -0
- package/dist/cli/chunk-WGKPJZDY.js +364 -0
- package/dist/cli/chunk-X4WKAOQP.js +634 -0
- package/dist/cli/chunk-X566FWBV.js +156 -0
- package/dist/cli/chunk-YH637PDL.js +317 -0
- package/dist/cli/chunk-ZL4JTG5Y.js +37 -0
- package/dist/cli/chunk-ZSCUZE6I.js +112 -0
- package/dist/cli/cliCommands-JJN5Z3ZC.js +3470 -0
- package/dist/cli/commands-PHYFYA3F.js +1374 -0
- package/dist/cli/contactSheet-2PQVRUFW.js +11 -0
- package/dist/cli/definitions-BPOPW52L.js +32 -0
- package/dist/cli/doctorCommand-ORWQRNYP.js +106 -0
- package/dist/cli/edit-S5KEQ5RA.js +28 -0
- package/dist/cli/editorCommands-NFR32JOY.js +41 -0
- package/dist/cli/encode-ICPEPMH5.js +17 -0
- package/dist/cli/file-3HTQHPYQ.js +41 -0
- package/dist/cli/filters-6ODFWYK4.js +379 -0
- package/dist/cli/frames-LSAUBZ7P.js +16 -0
- package/dist/cli/generators-YU7GB4MD.js +210 -0
- package/dist/cli/geo-6ZPGKZRU.js +43 -0
- package/dist/cli/graphCommands-EOUOBOIJ.js +184 -0
- package/dist/cli/graphFile-YTGJB5F5.js +292 -0
- package/dist/cli/headlessCanvas-ENRHC7GS.js +16 -0
- package/dist/cli/helpCommand-PULH6ZYB.js +157 -0
- package/dist/cli/image-TXELZZK5.js +55 -0
- package/dist/cli/index.js +100 -30756
- package/dist/cli/math-RSYRQ3C6.js +16 -0
- package/dist/cli/mcp-JVZFQOEX.js +164 -0
- package/dist/cli/parity-X6DEH2DV.js +334 -0
- package/dist/cli/pop-B7SIIYKN.js +39 -0
- package/dist/cli/project-VYGIA7JX.js +12 -0
- package/dist/cli/projectDefinition-F3D7UIHJ.js +27 -0
- package/dist/cli/projectRuntime-2Q4JKEH3.js +55 -0
- package/dist/cli/registerStandardNodes-BXJCB6E4.js +744 -0
- package/dist/cli/render-PT4MWI6U.js +438 -0
- package/dist/cli/runCommand-HNPQVZMS.js +198 -0
- package/dist/cli/runner-5XPXVW7J.js +43 -0
- package/dist/cli/runtime/image.ts +302 -0
- package/dist/cli/runtime/io.ts +78 -0
- package/dist/cli/runtime/stage.ts +4 -1
- package/dist/cli/share-MHF6TNRK.js +166 -0
- package/dist/cli/stageCache-TY2BFZJR.js +15 -0
- package/dist/cli/stageRunner-KY2EJP7X.js +10 -0
- package/dist/cli/text-MB3EKR4H.js +126 -0
- package/dist/cli/verbs-PI2JH5FI.js +19 -0
- package/dist/cli/webBuild-WPPMGGW7.js +44 -0
- package/dist/contracts/capabilities.d.ts +18 -1
- package/dist/contracts/color.d.ts +8 -0
- package/dist/contracts/color.js +23 -0
- package/dist/contracts/definition.d.ts +10 -0
- package/dist/contracts/documentFormat.d.ts +18 -0
- package/dist/contracts/documentFormat.js +195 -0
- package/dist/contracts/editor.d.ts +17 -0
- package/dist/contracts/index.d.ts +1 -0
- package/dist/contracts/index.js +1 -0
- package/dist/contracts/schema.d.ts +1 -1
- package/dist/contracts/schema.js +1 -0
- package/dist/contracts/validate.js +11 -1
- package/dist/contracts/values.d.ts +24 -0
- package/dist/image.d.ts +156 -0
- package/dist/image.js +161 -0
- package/dist/index.html +8 -2
- package/dist/io.d.ts +29 -0
- package/dist/io.js +40 -0
- package/dist/player/app.js +3 -2
- package/dist/player/editor.js +35 -9
- package/dist/player/editorEngine.js +3 -2
- package/dist/runtime/builtins/assert/checks.d.ts +18 -0
- package/dist/runtime/builtins/assert/checks.js +207 -0
- package/dist/runtime/builtins/assert/definitions.d.ts +130 -0
- package/dist/runtime/builtins/assert/definitions.js +54 -0
- package/dist/runtime/builtins/assert/index.d.ts +152 -0
- package/dist/runtime/builtins/assert/index.js +36 -0
- package/dist/runtime/builtins/image/contactSheet.d.ts +64 -0
- package/dist/runtime/builtins/image/contactSheet.js +150 -0
- package/dist/runtime/builtins/image/definitions.d.ts +950 -0
- package/dist/runtime/builtins/image/definitions.js +343 -0
- package/dist/runtime/builtins/image/file.d.ts +8 -0
- package/dist/runtime/builtins/image/file.js +37 -0
- package/dist/runtime/builtins/image/filters.d.ts +8 -0
- package/dist/runtime/builtins/image/filters.js +394 -0
- package/dist/runtime/builtins/image/generators.d.ts +7 -0
- package/dist/runtime/builtins/image/generators.js +144 -0
- package/dist/runtime/builtins/image/index.d.ts +952 -0
- package/dist/runtime/builtins/image/index.js +44 -0
- package/dist/runtime/builtins/image/io.d.ts +100 -0
- package/dist/runtime/builtins/image/io.js +142 -0
- package/dist/runtime/builtins/image/planar.d.ts +55 -0
- package/dist/runtime/builtins/image/planar.js +274 -0
- package/dist/runtime/builtins/image/simplex.d.ts +22 -0
- package/dist/runtime/builtins/image/simplex.js +92 -0
- package/dist/runtime/builtins/image/text.d.ts +4 -0
- package/dist/runtime/builtins/image/text.js +141 -0
- package/dist/runtime/builtins/index.d.ts +3 -0
- package/dist/runtime/builtins/index.js +7 -0
- package/dist/runtime/gpu.d.ts +25 -0
- package/dist/runtime/gpu.js +40 -0
- package/dist/runtime/runtime.d.ts +2 -0
- package/dist/runtime/runtime.js +268 -44
- package/dist/runtime/types.d.ts +30 -0
- package/dist/stage.js +4 -1
- package/doc/CLI_REFERENCE.md +91 -2
- package/doc/EDITOR_EXPORT.md +37 -2
- package/doc/MCP.md +18 -1
- package/doc/NODE_REFERENCE.md +424 -10
- package/doc/PROJECT_AUTHORING.md +222 -7
- package/package.json +19 -4
- package/dist/assets/CodePanel-sY6sZa7B.js +0 -2
- package/dist/assets/CustomNodeDialog-BRKnqZhp.js +0 -1
- package/dist/assets/ExportDialog-C7dVGua4.js +0 -358
- package/dist/assets/ExportDialog-DOq0flMV.css +0 -1
- package/dist/assets/OpenGraphDialog-ZsgL-iwr.js +0 -1
- package/dist/assets/ProjectSettings-Cw17nNe3.js +0 -2
- package/dist/assets/definitions-DUww2Rt-.js +0 -1
- package/dist/assets/geo-C2RHOVHC.js +0 -1
- package/dist/assets/image-DR4oeyJB.js +0 -2062
- package/dist/assets/index-7vae6YFC.css +0 -1
- package/dist/assets/index-DyvDC6pS.js +0 -219
- package/dist/assets/math-DaDEgWKt.js +0 -1
- package/dist/assets/pop-pLH7L0PW.js +0 -1
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import {
|
|
2
|
+
ASSERT_NAMESPACE,
|
|
3
|
+
assertNodeRegistrations,
|
|
4
|
+
equalsDefinition,
|
|
5
|
+
equalsRegistration,
|
|
6
|
+
notBlankDefinition,
|
|
7
|
+
notBlankRegistration,
|
|
8
|
+
rangeDefinition,
|
|
9
|
+
rangeRegistration,
|
|
10
|
+
trueDefinition,
|
|
11
|
+
trueRegistration
|
|
12
|
+
} from "./chunk-JVOCK5W4.js";
|
|
13
|
+
export {
|
|
14
|
+
ASSERT_NAMESPACE,
|
|
15
|
+
assertNodeRegistrations,
|
|
16
|
+
equalsDefinition,
|
|
17
|
+
equalsRegistration,
|
|
18
|
+
notBlankDefinition,
|
|
19
|
+
notBlankRegistration,
|
|
20
|
+
rangeDefinition,
|
|
21
|
+
rangeRegistration,
|
|
22
|
+
trueDefinition,
|
|
23
|
+
trueRegistration
|
|
24
|
+
};
|
|
25
|
+
//# sourceMappingURL=assert-GROGQNCQ.js.map
|
|
@@ -0,0 +1,189 @@
|
|
|
1
|
+
// packages/runtime/src/builtins/assert/checks.ts
|
|
2
|
+
var AssertionFailed = class extends Error {
|
|
3
|
+
constructor(nodeId, moduleId, detail, message) {
|
|
4
|
+
const extra = typeof message === "string" && message.trim() ? ` ${message.trim()}` : "";
|
|
5
|
+
super(`Assertion failed in "${nodeId}" (${moduleId}): ${detail}.${extra}`);
|
|
6
|
+
this.name = "AssertionFailed";
|
|
7
|
+
}
|
|
8
|
+
};
|
|
9
|
+
function executeRange({ nodeId, inputs, props, outputs }) {
|
|
10
|
+
const value = inputs.value;
|
|
11
|
+
if (typeof value !== "number" || !Number.isFinite(value)) {
|
|
12
|
+
throw new AssertionFailed(nodeId, "cascade.assert.Range", `value ${String(value)} is not a finite number`, props.message);
|
|
13
|
+
}
|
|
14
|
+
if (value < props.min || value > props.max) {
|
|
15
|
+
throw new AssertionFailed(nodeId, "cascade.assert.Range", `value ${value} is outside [${props.min}, ${props.max}]`, props.message);
|
|
16
|
+
}
|
|
17
|
+
outputs.value.set(value);
|
|
18
|
+
}
|
|
19
|
+
function executeEquals({ nodeId, inputs, props, outputs }) {
|
|
20
|
+
if (!deepEqual(inputs.value, props.expected, props.tolerance)) {
|
|
21
|
+
throw new AssertionFailed(nodeId, "cascade.assert.Equals", `got ${preview(inputs.value)}, expected ${preview(props.expected)}`, props.message);
|
|
22
|
+
}
|
|
23
|
+
outputs.value.set(inputs.value);
|
|
24
|
+
}
|
|
25
|
+
function executeTrue({ nodeId, inputs, props, outputs }) {
|
|
26
|
+
if (inputs.value !== true) throw new AssertionFailed(nodeId, "cascade.assert.True", `value is ${preview(inputs.value)}`, props.message);
|
|
27
|
+
outputs.value.set(true);
|
|
28
|
+
}
|
|
29
|
+
async function executeNotBlank({ nodeId, inputs, props, outputs, capabilities, signal }) {
|
|
30
|
+
const image = inputs.image;
|
|
31
|
+
const ref = typeof image === "string" ? { path: image } : image;
|
|
32
|
+
if (!ref || typeof ref.path !== "string" || !ref.path) {
|
|
33
|
+
throw new AssertionFailed(nodeId, "cascade.assert.NotBlank", "no image arrived", props.message);
|
|
34
|
+
}
|
|
35
|
+
const path = ref.path;
|
|
36
|
+
const kept = capabilities.assets.imagePixels?.({ path });
|
|
37
|
+
const pixels = kept ? { width: kept.width, height: kept.height, channels: 4, data: kept.data } : await decodeImage(await capabilities.assets.read({ path }, { signal }));
|
|
38
|
+
if (!pixels) throw new AssertionFailed(nodeId, "cascade.assert.NotBlank", `${path} is not a PNG or PPM this node can read`, props.message);
|
|
39
|
+
const verdict = blankness(pixels, props.tolerance);
|
|
40
|
+
if (verdict) throw new AssertionFailed(nodeId, "cascade.assert.NotBlank", `${path} (${pixels.width}x${pixels.height}) is ${verdict}`, props.message);
|
|
41
|
+
outputs.image.set(inputs.image);
|
|
42
|
+
}
|
|
43
|
+
function preview(value) {
|
|
44
|
+
const text = JSON.stringify(value) ?? String(value);
|
|
45
|
+
return text.length > 120 ? `${text.slice(0, 117)}...` : text;
|
|
46
|
+
}
|
|
47
|
+
function deepEqual(a, b, tolerance) {
|
|
48
|
+
if (typeof a === "number" && typeof b === "number") return a === b || Math.abs(a - b) <= tolerance;
|
|
49
|
+
if (Array.isArray(a) && Array.isArray(b)) return a.length === b.length && a.every((item, index) => deepEqual(item, b[index], tolerance));
|
|
50
|
+
if (a && b && typeof a === "object" && typeof b === "object" && !Array.isArray(a) && !Array.isArray(b)) {
|
|
51
|
+
const left = a;
|
|
52
|
+
const right = b;
|
|
53
|
+
const keys = Object.keys(left);
|
|
54
|
+
if (keys.length !== Object.keys(right).length) return false;
|
|
55
|
+
return keys.every((key) => key in right && deepEqual(left[key], right[key], tolerance));
|
|
56
|
+
}
|
|
57
|
+
return a === b || a == null && b == null;
|
|
58
|
+
}
|
|
59
|
+
function blankness(pixels, tolerance = 0) {
|
|
60
|
+
const { channels, data } = pixels;
|
|
61
|
+
const alpha = channels === 2 || channels === 4 ? channels - 1 : -1;
|
|
62
|
+
const colour = alpha === -1 ? channels : channels - 1;
|
|
63
|
+
const min = new Array(channels).fill(255);
|
|
64
|
+
const max = new Array(channels).fill(0);
|
|
65
|
+
let opaque = alpha === -1;
|
|
66
|
+
for (let index = 0; index < data.length; index += channels) {
|
|
67
|
+
if (alpha !== -1 && data[index + alpha] > tolerance) opaque = true;
|
|
68
|
+
for (let channel = 0; channel < channels; channel += 1) {
|
|
69
|
+
const value = data[index + channel];
|
|
70
|
+
if (value < min[channel]) min[channel] = value;
|
|
71
|
+
if (value > max[channel]) max[channel] = value;
|
|
72
|
+
}
|
|
73
|
+
}
|
|
74
|
+
if (!opaque) return "fully transparent";
|
|
75
|
+
const spread = Math.max(...max.map((value, channel) => value - min[channel]));
|
|
76
|
+
if (spread <= tolerance) return colour === 1 ? `one flat grey (${min[0]})` : `one flat colour (rgb ${min.slice(0, 3).join(", ")})`;
|
|
77
|
+
return null;
|
|
78
|
+
}
|
|
79
|
+
async function decodeImage(bytes) {
|
|
80
|
+
if (bytes[0] === 137 && bytes[1] === 80 && bytes[2] === 78 && bytes[3] === 71) return decodePng(bytes);
|
|
81
|
+
if (bytes[0] === 80 && (bytes[1] === 54 || bytes[1] === 53)) return decodePnm(bytes);
|
|
82
|
+
return null;
|
|
83
|
+
}
|
|
84
|
+
function decodePnm(bytes) {
|
|
85
|
+
const fields = [];
|
|
86
|
+
let index = 2;
|
|
87
|
+
while (fields.length < 3 && index < bytes.length) {
|
|
88
|
+
while (index < bytes.length && /\s/.test(String.fromCharCode(bytes[index]))) index += 1;
|
|
89
|
+
if (bytes[index] === 35) {
|
|
90
|
+
while (index < bytes.length && bytes[index] !== 10) index += 1;
|
|
91
|
+
continue;
|
|
92
|
+
}
|
|
93
|
+
let field = "";
|
|
94
|
+
while (index < bytes.length && !/\s/.test(String.fromCharCode(bytes[index]))) field += String.fromCharCode(bytes[index++]);
|
|
95
|
+
fields.push(field);
|
|
96
|
+
}
|
|
97
|
+
const [width, height, maxValue] = fields.map(Number);
|
|
98
|
+
if (!width || !height || maxValue !== 255) return null;
|
|
99
|
+
const channels = bytes[1] === 54 ? 3 : 1;
|
|
100
|
+
return { width, height, channels, data: bytes.subarray(index + 1, index + 1 + width * height * channels) };
|
|
101
|
+
}
|
|
102
|
+
async function inflate(data) {
|
|
103
|
+
const globals = globalThis;
|
|
104
|
+
if (!globals.DecompressionStream || !globals.Blob || !globals.Response) {
|
|
105
|
+
throw new Error("cascade.assert.NotBlank: this host has no DecompressionStream to read a PNG with");
|
|
106
|
+
}
|
|
107
|
+
const stream = new globals.Blob([data]).stream().pipeThrough(new globals.DecompressionStream("deflate"));
|
|
108
|
+
return new Uint8Array(await new globals.Response(stream).arrayBuffer());
|
|
109
|
+
}
|
|
110
|
+
async function decodePng(bytes) {
|
|
111
|
+
const view = new DataView(bytes.buffer, bytes.byteOffset, bytes.byteLength);
|
|
112
|
+
let offset = 8;
|
|
113
|
+
let width = 0;
|
|
114
|
+
let height = 0;
|
|
115
|
+
let channels = 0;
|
|
116
|
+
const idat = [];
|
|
117
|
+
while (offset + 8 <= bytes.length) {
|
|
118
|
+
const length = view.getUint32(offset);
|
|
119
|
+
const type = String.fromCharCode(...bytes.subarray(offset + 4, offset + 8));
|
|
120
|
+
const body = bytes.subarray(offset + 8, offset + 8 + length);
|
|
121
|
+
if (type === "IHDR") {
|
|
122
|
+
width = view.getUint32(offset + 8);
|
|
123
|
+
height = view.getUint32(offset + 12);
|
|
124
|
+
const depth = body[8];
|
|
125
|
+
const colourType = body[9];
|
|
126
|
+
const interlace = body[12];
|
|
127
|
+
channels = { 0: 1, 4: 2, 2: 3, 6: 4 }[colourType] ?? 0;
|
|
128
|
+
if (depth !== 8 || !channels || interlace !== 0) return null;
|
|
129
|
+
} else if (type === "IDAT") idat.push(body);
|
|
130
|
+
else if (type === "IEND") break;
|
|
131
|
+
offset += 12 + length;
|
|
132
|
+
}
|
|
133
|
+
if (!width || !height || !idat.length) return null;
|
|
134
|
+
const joined = new Uint8Array(idat.reduce((sum, part) => sum + part.length, 0));
|
|
135
|
+
let at = 0;
|
|
136
|
+
for (const part of idat) {
|
|
137
|
+
joined.set(part, at);
|
|
138
|
+
at += part.length;
|
|
139
|
+
}
|
|
140
|
+
const raw = await inflate(joined);
|
|
141
|
+
const stride = width * channels;
|
|
142
|
+
const data = new Uint8Array(stride * height);
|
|
143
|
+
for (let row = 0; row < height; row += 1) {
|
|
144
|
+
const filter = raw[row * (stride + 1)];
|
|
145
|
+
const line = raw.subarray(row * (stride + 1) + 1, (row + 1) * (stride + 1));
|
|
146
|
+
const out = data.subarray(row * stride, (row + 1) * stride);
|
|
147
|
+
const previous = row > 0 ? data.subarray((row - 1) * stride, row * stride) : new Uint8Array(stride);
|
|
148
|
+
for (let x = 0; x < stride; x += 1) {
|
|
149
|
+
const left = x >= channels ? out[x - channels] : 0;
|
|
150
|
+
const up = previous[x];
|
|
151
|
+
const upLeft = x >= channels ? previous[x - channels] : 0;
|
|
152
|
+
const value = line[x];
|
|
153
|
+
switch (filter) {
|
|
154
|
+
case 0:
|
|
155
|
+
out[x] = value;
|
|
156
|
+
break;
|
|
157
|
+
case 1:
|
|
158
|
+
out[x] = value + left & 255;
|
|
159
|
+
break;
|
|
160
|
+
case 2:
|
|
161
|
+
out[x] = value + up & 255;
|
|
162
|
+
break;
|
|
163
|
+
case 3:
|
|
164
|
+
out[x] = value + (left + up >> 1) & 255;
|
|
165
|
+
break;
|
|
166
|
+
case 4: {
|
|
167
|
+
const estimate = left + up - upLeft;
|
|
168
|
+
const a = Math.abs(estimate - left);
|
|
169
|
+
const b = Math.abs(estimate - up);
|
|
170
|
+
const c = Math.abs(estimate - upLeft);
|
|
171
|
+
out[x] = value + (a <= b && a <= c ? left : b <= c ? up : upLeft) & 255;
|
|
172
|
+
break;
|
|
173
|
+
}
|
|
174
|
+
default:
|
|
175
|
+
return null;
|
|
176
|
+
}
|
|
177
|
+
}
|
|
178
|
+
}
|
|
179
|
+
return { width, height, channels, data };
|
|
180
|
+
}
|
|
181
|
+
export {
|
|
182
|
+
blankness,
|
|
183
|
+
decodeImage,
|
|
184
|
+
executeEquals,
|
|
185
|
+
executeNotBlank,
|
|
186
|
+
executeRange,
|
|
187
|
+
executeTrue
|
|
188
|
+
};
|
|
189
|
+
//# sourceMappingURL=checks-3WB44XBL.js.map
|