@aelionsdk/material-sdk 0.1.0-beta.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.
Files changed (60) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +7 -0
  3. package/dist/bundled-schemas.d.ts +5 -0
  4. package/dist/bundled-schemas.d.ts.map +1 -0
  5. package/dist/bundled-schemas.js +3 -0
  6. package/dist/canonical.d.ts +6 -0
  7. package/dist/canonical.d.ts.map +1 -0
  8. package/dist/canonical.js +33 -0
  9. package/dist/catalog.d.ts +24 -0
  10. package/dist/catalog.d.ts.map +1 -0
  11. package/dist/catalog.js +47 -0
  12. package/dist/composition.d.ts +42 -0
  13. package/dist/composition.d.ts.map +1 -0
  14. package/dist/composition.js +169 -0
  15. package/dist/definition-builder.d.ts +48 -0
  16. package/dist/definition-builder.d.ts.map +1 -0
  17. package/dist/definition-builder.js +159 -0
  18. package/dist/graph-builder.d.ts +45 -0
  19. package/dist/graph-builder.d.ts.map +1 -0
  20. package/dist/graph-builder.js +125 -0
  21. package/dist/index.d.ts +15 -0
  22. package/dist/index.d.ts.map +1 -0
  23. package/dist/index.js +14 -0
  24. package/dist/lab.d.ts +48 -0
  25. package/dist/lab.d.ts.map +1 -0
  26. package/dist/lab.js +169 -0
  27. package/dist/migration.d.ts +22 -0
  28. package/dist/migration.d.ts.map +1 -0
  29. package/dist/migration.js +59 -0
  30. package/dist/package-limits.d.ts +30 -0
  31. package/dist/package-limits.d.ts.map +1 -0
  32. package/dist/package-limits.js +202 -0
  33. package/dist/package-shape.d.ts +6 -0
  34. package/dist/package-shape.d.ts.map +1 -0
  35. package/dist/package-shape.js +547 -0
  36. package/dist/package-snapshot.d.ts +5 -0
  37. package/dist/package-snapshot.d.ts.map +1 -0
  38. package/dist/package-snapshot.js +31 -0
  39. package/dist/package.d.ts +12 -0
  40. package/dist/package.d.ts.map +1 -0
  41. package/dist/package.js +244 -0
  42. package/dist/registry.d.ts +32 -0
  43. package/dist/registry.d.ts.map +1 -0
  44. package/dist/registry.js +150 -0
  45. package/dist/schema-validation.d.ts +4 -0
  46. package/dist/schema-validation.d.ts.map +1 -0
  47. package/dist/schema-validation.js +36 -0
  48. package/dist/security.d.ts +70 -0
  49. package/dist/security.d.ts.map +1 -0
  50. package/dist/security.js +161 -0
  51. package/dist/types.d.ts +245 -0
  52. package/dist/types.d.ts.map +1 -0
  53. package/dist/types.js +5 -0
  54. package/dist/validation.d.ts +6 -0
  55. package/dist/validation.d.ts.map +1 -0
  56. package/dist/validation.js +124 -0
  57. package/dist/zip.d.ts +4 -0
  58. package/dist/zip.d.ts.map +1 -0
  59. package/dist/zip.js +172 -0
  60. package/package.json +46 -0
package/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 FoyonaCZY and AelionSDK contributors
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md ADDED
@@ -0,0 +1,7 @@
1
+ # @aelionsdk/material-sdk
2
+
3
+ Type-safe authoring, validation and packaging tools for Aelion materials
4
+
5
+ Install with `npm install @aelionsdk/material-sdk@next`.
6
+
7
+ Version 0.1.0-beta.1 is a prerelease and its API may change before the first stable release. This package is part of [AelionSDK](https://github.com/FoyonaCZY/AelionSDK); see the repository README for supported browsers, examples and deployment requirements.
@@ -0,0 +1,5 @@
1
+ import type { JsonObject } from '@aelionsdk/core';
2
+ export declare const materialPackageSchema: JsonObject;
3
+ export declare const materialDefinitionSchema: JsonObject;
4
+ export declare const materialGraphSchema: JsonObject;
5
+ //# sourceMappingURL=bundled-schemas.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"bundled-schemas.d.ts","sourceRoot":"","sources":["../src/bundled-schemas.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,iBAAiB,CAAC;AAElD,eAAO,MAAM,qBAAqB,EAE7B,UAAU,CAAC;AAEhB,eAAO,MAAM,wBAAwB,EAEhC,UAAU,CAAC;AAEhB,eAAO,MAAM,mBAAmB,EAE3B,UAAU,CAAC"}
@@ -0,0 +1,3 @@
1
+ export const materialPackageSchema = JSON.parse(String.raw `{"$schema":"https://json-schema.org/draft/2020-12/schema","$id":"https://schemas.aelion.dev/material/package/v1.json","title":"Aelion Material Package Manifest v1","type":"object","additionalProperties":false,"required":["$schema","protocolVersion","package","materials","files"],"properties":{"$schema":{"const":"https://schemas.aelion.dev/material/package/v1.json"},"protocolVersion":{"const":"1.0.0"},"package":{"$ref":"#/$defs/packageMetadata"},"materials":{"type":"array","minItems":1,"maxItems":256,"items":{"$ref":"#/$defs/materialEntry"}},"files":{"type":"array","maxItems":255,"items":{"$ref":"#/$defs/fileEntry"}}},"$defs":{"identifier":{"type":"string","minLength":1,"maxLength":128,"pattern":"^[a-z0-9]+(?:[._-][a-z0-9]+)*$"},"relativePath":{"type":"string","minLength":1,"maxLength":512,"pattern":"^(?!/)(?!.*(?:^|/)\\.\\.(?:/|$))(?!.*\\\\)[^\\u0000]+$"},"packageMetadata":{"type":"object","additionalProperties":false,"required":["id","version","displayName","publisher","license","engines","trust"],"properties":{"id":{"$ref":"#/$defs/identifier"},"version":{"type":"string","pattern":"^(0|[1-9][0-9]*)\\.(0|[1-9][0-9]*)\\.(0|[1-9][0-9]*)(?:-[0-9A-Za-z.-]+)?(?:\\+[0-9A-Za-z.-]+)?$"},"displayName":{"type":"string","minLength":1,"maxLength":128},"publisher":{"type":"object","additionalProperties":false,"required":["id","name"],"properties":{"id":{"$ref":"#/$defs/identifier"},"name":{"type":"string","minLength":1,"maxLength":128}}},"license":{"type":"string","minLength":1,"maxLength":128},"engines":{"type":"object","additionalProperties":false,"required":["aelion","nodeSet"],"properties":{"aelion":{"type":"string","minLength":1,"maxLength":128},"nodeSet":{"type":"string","minLength":1,"maxLength":128}}},"trust":{"enum":["declarative","trusted-code"]}}},"materialEntry":{"type":"object","additionalProperties":false,"required":["id","kind","definition"],"properties":{"id":{"$ref":"#/$defs/identifier"},"kind":{"enum":["visual-filter","visual-effect","visual-transition","visual-generator"]},"definition":{"$ref":"#/$defs/relativePath"}}},"fileEntry":{"type":"object","additionalProperties":false,"required":["path","mediaType","bytes","sha256"],"properties":{"path":{"$ref":"#/$defs/relativePath"},"mediaType":{"type":"string","minLength":1,"maxLength":128},"bytes":{"type":"integer","minimum":0,"maximum":67108864},"sha256":{"type":"string","pattern":"^[0-9a-f]{64}$"}}}}}`);
2
+ export const materialDefinitionSchema = JSON.parse(String.raw `{"$schema":"https://json-schema.org/draft/2020-12/schema","$id":"https://schemas.aelion.dev/material/definition/v1.json","title":"Aelion Material Definition v1","type":"object","additionalProperties":false,"required":["$schema","protocolVersion","id","kind","display","scopes","ports","parameters","bundledResources","resourceSlots","execution","implementations","splitPolicy"],"properties":{"$schema":{"const":"https://schemas.aelion.dev/material/definition/v1.json"},"protocolVersion":{"const":"1.0.0"},"id":{"$ref":"#/$defs/identifier"},"kind":{"enum":["visual-filter","visual-effect","visual-transition","visual-generator"]},"display":{"$ref":"#/$defs/display"},"scopes":{"type":"array","minItems":1,"uniqueItems":true,"items":{"enum":["source","item","track","sequence","transition"]}},"ports":{"type":"array","minItems":1,"maxItems":16,"items":{"$ref":"#/$defs/port"}},"parameters":{"type":"array","maxItems":64,"items":{"$ref":"#/$defs/parameter"}},"bundledResources":{"type":"array","maxItems":32,"items":{"$ref":"#/$defs/bundledResource"}},"resourceSlots":{"type":"array","maxItems":16,"items":{"$ref":"#/$defs/resourceSlot"}},"execution":{"$ref":"#/$defs/execution"},"implementations":{"type":"array","minItems":1,"maxItems":8,"items":{"$ref":"#/$defs/implementation"}},"splitPolicy":{"enum":["copy","reset","reject"]}},"$defs":{"identifier":{"type":"string","minLength":1,"maxLength":96,"pattern":"^[A-Za-z][A-Za-z0-9_-]*$"},"relativePath":{"type":"string","minLength":1,"maxLength":512,"pattern":"^(?!/)(?!.*(?:^|/)\\.\\.(?:/|$))(?!.*\\\\)[^\\u0000]+$"},"jsonValue":{"oneOf":[{"type":"null"},{"type":"boolean"},{"type":"number"},{"type":"string","maxLength":4096},{"type":"array","maxItems":1024,"items":{"$ref":"#/$defs/jsonValue"}},{"type":"object","maxProperties":128,"additionalProperties":{"$ref":"#/$defs/jsonValue"}}]},"display":{"type":"object","additionalProperties":false,"required":["name"],"properties":{"name":{"type":"string","minLength":1,"maxLength":128},"description":{"type":"string","maxLength":2048},"category":{"type":"string","maxLength":64},"tags":{"type":"array","maxItems":32,"uniqueItems":true,"items":{"type":"string","minLength":1,"maxLength":64}},"icon":{"$ref":"#/$defs/relativePath"},"thumbnail":{"$ref":"#/$defs/relativePath"},"preview":{"$ref":"#/$defs/relativePath"},"localizationPrefix":{"type":"string","maxLength":128}}},"port":{"type":"object","additionalProperties":false,"required":["id","direction","type","role","binding","required"],"properties":{"id":{"$ref":"#/$defs/identifier"},"direction":{"enum":["input","output"]},"type":{"enum":["visual-frame","mask","depth","motion-vectors"]},"role":{"enum":["source","from","to","auxiliary","result"]},"binding":{"enum":["host","instance"]},"required":{"type":"boolean"},"description":{"type":"string","maxLength":512}}},"parameter":{"type":"object","additionalProperties":false,"required":["id","type","default","animatable","affects","ui"],"properties":{"id":{"$ref":"#/$defs/identifier"},"type":{"enum":["boolean","integer","float","enum","vec2","vec3","vec4","color","angle","duration","gradient","curve","string"]},"default":{"$ref":"#/$defs/jsonValue"},"range":{"type":"object","additionalProperties":false,"properties":{"min":{"type":"number"},"max":{"type":"number"},"softMin":{"type":"number"},"softMax":{"type":"number"},"step":{"type":"number","exclusiveMinimum":0}}},"values":{"type":"array","minItems":1,"uniqueItems":true,"items":{"type":"string","minLength":1,"maxLength":96}},"unit":{"enum":["none","ratio","percent","px","degree","us","db","hz"]},"animatable":{"type":"boolean"},"interpolation":{"enum":["hold","linear","cubic-bezier","shortest-angle","linear-color"]},"affects":{"enum":["uniform","specialization","graph"]},"ui":{"type":"object","additionalProperties":false,"required":["control","group","order","label"],"properties":{"control":{"enum":["toggle","slider","number","select","segmented","color","point","curve","gradient","text"]},"group":{"type":"string","maxLength":96},"order":{"type":"integer"},"label":{"type":"string","minLength":1,"maxLength":128}}}}},"bundledResource":{"type":"object","additionalProperties":true,"required":["id","kind","path"],"properties":{"id":{"$ref":"#/$defs/identifier"},"kind":{"enum":["texture2d","texture3d","lut1d","lut3d","cube-texture","mask","binary-table"]},"path":{"$ref":"#/$defs/relativePath"}}},"resourceSlot":{"type":"object","additionalProperties":true,"required":["id","kind","required"],"properties":{"id":{"$ref":"#/$defs/identifier"},"kind":{"enum":["texture2d","texture3d","lut1d","lut3d","cube-texture","mask","binary-table"]},"required":{"type":"boolean"},"fallbackResourceId":{"$ref":"#/$defs/identifier"}}},"execution":{"type":"object","additionalProperties":false,"required":["color","alpha","resolution","spatialPadding","temporal","determinism","supports"],"properties":{"color":{"type":"object","additionalProperties":false,"required":["input","output"],"properties":{"input":{"const":"working-linear"},"output":{"const":"working-linear"}}},"alpha":{"type":"object","additionalProperties":false,"required":["input","output","preservesTransparency"],"properties":{"input":{"const":"premultiplied"},"output":{"const":"premultiplied"},"preservesTransparency":{"type":"boolean"}}},"resolution":{"type":"object","additionalProperties":false,"required":["policy"],"properties":{"policy":{"enum":["same-as-host","scale"]},"scale":{"type":"number","exclusiveMinimum":0,"maximum":4},"minimum":{"type":"object","additionalProperties":false,"required":["width","height"],"properties":{"width":{"type":"integer","minimum":1,"maximum":16384},"height":{"type":"integer","minimum":1,"maximum":16384}}}}},"spatialPadding":{"type":"object","additionalProperties":false,"required":["mode"],"properties":{"mode":{"enum":["none","fixed","parameter-bound"]},"pixels":{"type":"number","minimum":0,"maximum":4096},"parameter":{"$ref":"#/$defs/identifier"},"maximumPixels":{"type":"number","minimum":0,"maximum":4096}}},"temporal":{"type":"object","additionalProperties":false,"required":["pastUs","futureUs","stateful","seekPolicy"],"properties":{"pastUs":{"type":"integer","minimum":0},"futureUs":{"type":"integer","minimum":0},"stateful":{"type":"boolean"},"seekPolicy":{"enum":["stateless","reconstruct","reset-with-warning"]}}},"determinism":{"enum":["strict","backend-tolerant","non-deterministic"]},"supports":{"type":"object","additionalProperties":false,"required":["realtime","offline","alpha","hdr","tiled"],"properties":{"realtime":{"type":"boolean"},"offline":{"type":"boolean"},"alpha":{"type":"boolean"},"hdr":{"type":"boolean"},"tiled":{"type":"boolean"}}}}},"implementation":{"oneOf":[{"type":"object","additionalProperties":false,"required":["type","graph","nodeSet"],"properties":{"type":{"const":"graph"},"graph":{"$ref":"#/$defs/relativePath"},"nodeSet":{"type":"string","minLength":1,"maxLength":128}}},{"type":"object","additionalProperties":true,"required":["type","backend","abi","entryPoint"],"properties":{"type":{"const":"shader"},"backend":{"enum":["webgpu","webgl2"]},"abi":{"enum":["aelion-material-shader/1","aelion-material-webgl/1"]},"entryPoint":{"type":"string","minLength":1,"maxLength":128}}},{"type":"object","additionalProperties":true,"required":["type","module","abi"],"properties":{"type":{"const":"wasm"},"module":{"$ref":"#/$defs/relativePath"},"abi":{"const":"aelion-material-wasm/1"}}}]}}}`);
3
+ export const materialGraphSchema = JSON.parse(String.raw `{"$schema":"https://json-schema.org/draft/2020-12/schema","$id":"https://schemas.aelion.dev/material/graph/v1.json","title":"Aelion Material Graph v1","type":"object","additionalProperties":false,"required":["$schema","graphVersion","nodeSet","nodes","outputs"],"properties":{"$schema":{"const":"https://schemas.aelion.dev/material/graph/v1.json"},"graphVersion":{"const":"1.0.0"},"nodeSet":{"type":"string","minLength":1,"maxLength":128},"nodes":{"type":"array","maxItems":128,"items":{"$ref":"#/$defs/node"}},"outputs":{"type":"object","minProperties":1,"maxProperties":8,"additionalProperties":{"$ref":"#/$defs/nodeReference"},"propertyNames":{"$ref":"#/$defs/localIdentifier"}}},"$defs":{"jsonValue":{"oneOf":[{"type":"null"},{"type":"boolean"},{"type":"number"},{"type":"string","maxLength":4096},{"type":"array","maxItems":1024,"items":{"$ref":"#/$defs/jsonValue"}},{"type":"object","maxProperties":128,"additionalProperties":{"$ref":"#/$defs/jsonValue"}}]},"localIdentifier":{"type":"string","minLength":1,"maxLength":96,"pattern":"^[A-Za-z][A-Za-z0-9_-]*$"},"node":{"type":"object","additionalProperties":false,"required":["id","type","typeVersion","inputs"],"properties":{"id":{"$ref":"#/$defs/localIdentifier"},"type":{"type":"string","minLength":1,"maxLength":128,"pattern":"^[a-z0-9]+(?:[._-][a-z0-9]+)*$"},"typeVersion":{"type":"string","pattern":"^[0-9]+\\.[0-9]+\\.[0-9]+$"},"inputs":{"type":"object","maxProperties":32,"additionalProperties":{"$ref":"#/$defs/graphValue"},"propertyNames":{"$ref":"#/$defs/localIdentifier"}},"config":{"type":"object","maxProperties":32,"additionalProperties":{"$ref":"#/$defs/jsonValue"}}}},"graphValue":{"oneOf":[{"type":"object","additionalProperties":false,"required":["value"],"properties":{"value":{"$ref":"#/$defs/jsonValue"}}},{"type":"object","additionalProperties":false,"required":["parameter"],"properties":{"parameter":{"$ref":"#/$defs/localIdentifier"}}},{"type":"object","additionalProperties":false,"required":["resource"],"properties":{"resource":{"$ref":"#/$defs/localIdentifier"}}},{"type":"object","additionalProperties":false,"required":["inputPort"],"properties":{"inputPort":{"$ref":"#/$defs/localIdentifier"}}},{"$ref":"#/$defs/nodeReference"},{"type":"object","additionalProperties":false,"required":["system"],"properties":{"system":{"enum":["sequenceTimeUs","itemTimeUs","itemDurationUs","normalizedItemTime","transitionProgress","frameIndex","frameDurationUs","outputSizePx","pixelSizeUv","workingColorSpace","qualityScale","randomSeed"]}}}]},"nodeReference":{"type":"object","additionalProperties":false,"required":["node","output"],"properties":{"node":{"$ref":"#/$defs/localIdentifier"},"output":{"$ref":"#/$defs/localIdentifier"}}}}}`);
@@ -0,0 +1,6 @@
1
+ import type { JsonValue } from '@aelionsdk/core';
2
+ /** Deterministic JSON serialization used for AMP file and manifest integrity. */
3
+ export declare function canonicalizeMaterialJson(value: JsonValue): string;
4
+ export declare function canonicalMaterialBytes(value: JsonValue): Uint8Array;
5
+ export declare function sha256Hex(data: Uint8Array): Promise<string>;
6
+ //# sourceMappingURL=canonical.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"canonical.d.ts","sourceRoot":"","sources":["../src/canonical.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,iBAAiB,CAAC;AAsBjD,iFAAiF;AACjF,wBAAgB,wBAAwB,CAAC,KAAK,EAAE,SAAS,GAAG,MAAM,CAEjE;AAED,wBAAgB,sBAAsB,CAAC,KAAK,EAAE,SAAS,GAAG,UAAU,CAEnE;AAED,wBAAsB,SAAS,CAAC,IAAI,EAAE,UAAU,GAAG,OAAO,CAAC,MAAM,CAAC,CAIjE"}
@@ -0,0 +1,33 @@
1
+ function serialize(value) {
2
+ if (value === null || typeof value === 'boolean' || typeof value === 'string') {
3
+ return JSON.stringify(value);
4
+ }
5
+ if (typeof value === 'number') {
6
+ if (!Number.isFinite(value))
7
+ throw new TypeError('Canonical JSON cannot contain non-finite numbers');
8
+ return JSON.stringify(value);
9
+ }
10
+ if (Array.isArray(value))
11
+ return `[${value.map(item => serialize(item)).join(',')}]`;
12
+ return `{${Object.keys(value)
13
+ .sort()
14
+ .map(key => {
15
+ const item = value[key];
16
+ if (item === undefined)
17
+ throw new TypeError('Canonical JSON cannot contain undefined');
18
+ return `${JSON.stringify(key)}:${serialize(item)}`;
19
+ })
20
+ .join(',')}}`;
21
+ }
22
+ /** Deterministic JSON serialization used for AMP file and manifest integrity. */
23
+ export function canonicalizeMaterialJson(value) {
24
+ return serialize(value);
25
+ }
26
+ export function canonicalMaterialBytes(value) {
27
+ return new TextEncoder().encode(canonicalizeMaterialJson(value));
28
+ }
29
+ export async function sha256Hex(data) {
30
+ const source = new Uint8Array(data);
31
+ const digest = await globalThis.crypto.subtle.digest('SHA-256', source);
32
+ return [...new Uint8Array(digest)].map(value => value.toString(16).padStart(2, '0')).join('');
33
+ }
@@ -0,0 +1,24 @@
1
+ import type { MaterialPackageReference } from './types.js';
2
+ export type MaterialCatalogStatus = 'active' | 'deprecated' | 'revoked';
3
+ export interface MaterialCatalogEntry {
4
+ readonly packageId: string;
5
+ readonly packageVersion: string;
6
+ readonly packageIntegrity: string;
7
+ readonly publisherId: string;
8
+ readonly materialIds: readonly string[];
9
+ readonly status: MaterialCatalogStatus;
10
+ readonly reason?: string;
11
+ readonly publishedAtMs: number;
12
+ }
13
+ /** Immutable-version local catalog model suitable for backing a remote marketplace adapter. */
14
+ export declare class MaterialCatalog {
15
+ #private;
16
+ publish(entry: Omit<MaterialCatalogEntry, 'status' | 'reason'>): void;
17
+ setStatus(packageId: string, packageVersion: string, status: Exclude<MaterialCatalogStatus, 'active'>, reason: string): void;
18
+ resolve(reference: MaterialPackageReference): MaterialCatalogEntry;
19
+ list(options?: {
20
+ readonly publisherId?: string;
21
+ readonly includeRevoked?: boolean;
22
+ }): readonly MaterialCatalogEntry[];
23
+ }
24
+ //# sourceMappingURL=catalog.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"catalog.d.ts","sourceRoot":"","sources":["../src/catalog.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,wBAAwB,EAAE,MAAM,YAAY,CAAC;AAE3D,MAAM,MAAM,qBAAqB,GAAG,QAAQ,GAAG,YAAY,GAAG,SAAS,CAAC;AAExE,MAAM,WAAW,oBAAoB;IACnC,QAAQ,CAAC,SAAS,EAAE,MAAM,CAAC;IAC3B,QAAQ,CAAC,cAAc,EAAE,MAAM,CAAC;IAChC,QAAQ,CAAC,gBAAgB,EAAE,MAAM,CAAC;IAClC,QAAQ,CAAC,WAAW,EAAE,MAAM,CAAC;IAC7B,QAAQ,CAAC,WAAW,EAAE,SAAS,MAAM,EAAE,CAAC;IACxC,QAAQ,CAAC,MAAM,EAAE,qBAAqB,CAAC;IACvC,QAAQ,CAAC,MAAM,CAAC,EAAE,MAAM,CAAC;IACzB,QAAQ,CAAC,aAAa,EAAE,MAAM,CAAC;CAChC;AAMD,+FAA+F;AAC/F,qBAAa,eAAe;;IAGnB,OAAO,CAAC,KAAK,EAAE,IAAI,CAAC,oBAAoB,EAAE,QAAQ,GAAG,QAAQ,CAAC,GAAG,IAAI;IAarE,SAAS,CACd,SAAS,EAAE,MAAM,EACjB,cAAc,EAAE,MAAM,EACtB,MAAM,EAAE,OAAO,CAAC,qBAAqB,EAAE,QAAQ,CAAC,EAChD,MAAM,EAAE,MAAM,GACb,IAAI;IAOA,OAAO,CAAC,SAAS,EAAE,wBAAwB,GAAG,oBAAoB;IAalE,IAAI,CACT,OAAO,GAAE;QAAE,QAAQ,CAAC,WAAW,CAAC,EAAE,MAAM,CAAC;QAAC,QAAQ,CAAC,cAAc,CAAC,EAAE,OAAO,CAAA;KAAO,GACjF,SAAS,oBAAoB,EAAE;CAanC"}
@@ -0,0 +1,47 @@
1
+ function keyOf(entry) {
2
+ return `${entry.packageId}\0${entry.packageVersion}`;
3
+ }
4
+ /** Immutable-version local catalog model suitable for backing a remote marketplace adapter. */
5
+ export class MaterialCatalog {
6
+ #entries = new Map();
7
+ publish(entry) {
8
+ const key = keyOf(entry);
9
+ const existing = this.#entries.get(key);
10
+ if (existing !== undefined) {
11
+ if (existing.packageIntegrity === entry.packageIntegrity)
12
+ return;
13
+ throw new TypeError('MATERIAL_CATALOG_VERSION_IMMUTABLE');
14
+ }
15
+ if (new Set(entry.materialIds).size !== entry.materialIds.length) {
16
+ throw new TypeError('MATERIAL_CATALOG_DUPLICATE_MATERIAL');
17
+ }
18
+ this.#entries.set(key, { ...entry, materialIds: [...entry.materialIds], status: 'active' });
19
+ }
20
+ setStatus(packageId, packageVersion, status, reason) {
21
+ const key = keyOf({ packageId, packageVersion });
22
+ const entry = this.#entries.get(key);
23
+ if (entry === undefined)
24
+ throw new ReferenceError('MATERIAL_CATALOG_MISSING');
25
+ this.#entries.set(key, { ...entry, status, reason });
26
+ }
27
+ resolve(reference) {
28
+ const entry = this.#entries.get(keyOf(reference));
29
+ if (!entry?.materialIds.includes(reference.materialId)) {
30
+ throw new ReferenceError('MATERIAL_CATALOG_MISSING');
31
+ }
32
+ if (entry.packageIntegrity !== reference.packageIntegrity) {
33
+ throw new TypeError('MATERIAL_CATALOG_INTEGRITY_MISMATCH');
34
+ }
35
+ if (entry.status === 'revoked')
36
+ throw new TypeError(`MATERIAL_CATALOG_REVOKED: ${entry.reason}`);
37
+ return { ...entry, materialIds: [...entry.materialIds] };
38
+ }
39
+ list(options = {}) {
40
+ return [...this.#entries.values()]
41
+ .filter(entry => options.publisherId === undefined || entry.publisherId === options.publisherId)
42
+ .filter(entry => options.includeRevoked === true || entry.status !== 'revoked')
43
+ .sort((left, right) => left.packageId.localeCompare(right.packageId) ||
44
+ left.packageVersion.localeCompare(right.packageVersion))
45
+ .map(entry => ({ ...entry, materialIds: [...entry.materialIds] }));
46
+ }
47
+ }
@@ -0,0 +1,42 @@
1
+ import type { JsonValue } from '@aelionsdk/core';
2
+ import type { MaterialDefinition, MaterialPackageReference } from './types.js';
3
+ export interface MaterialCompositionSlot {
4
+ readonly id: string;
5
+ readonly order: number;
6
+ readonly enabled: boolean;
7
+ readonly reference: MaterialPackageReference;
8
+ readonly definition: MaterialDefinition;
9
+ readonly parameters: Readonly<Record<string, JsonValue>>;
10
+ }
11
+ export interface MaterialFusionGroup {
12
+ readonly slotIds: readonly string[];
13
+ readonly fused: boolean;
14
+ readonly barrierReason?: string;
15
+ }
16
+ export interface MaterialCompositionPlan {
17
+ readonly slots: readonly MaterialCompositionSlot[];
18
+ readonly fusionGroups: readonly MaterialFusionGroup[];
19
+ readonly cacheKey: string;
20
+ readonly qualityScale: number;
21
+ }
22
+ export declare function createMaterialCompositionPlan(slots: readonly MaterialCompositionSlot[], options: {
23
+ readonly qualityScale?: number;
24
+ readonly outputWidth: number;
25
+ readonly outputHeight: number;
26
+ readonly workingColorSpace: string;
27
+ readonly maxFusedPasses?: number;
28
+ }): Promise<MaterialCompositionPlan>;
29
+ export interface AdaptiveMaterialQualityOptions {
30
+ readonly targetFrameMs: number;
31
+ readonly levels?: readonly number[];
32
+ readonly recoveryFrames?: number;
33
+ }
34
+ /** Hysteresis controller for preview quality; offline rendering should always use scale 1. */
35
+ export declare class AdaptiveMaterialQualityController {
36
+ #private;
37
+ constructor(options: AdaptiveMaterialQualityOptions);
38
+ get qualityScale(): number;
39
+ reportFrame(frameMs: number): number;
40
+ reset(): void;
41
+ }
42
+ //# sourceMappingURL=composition.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"composition.d.ts","sourceRoot":"","sources":["../src/composition.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,iBAAiB,CAAC;AAGjD,OAAO,KAAK,EAAE,kBAAkB,EAAE,wBAAwB,EAAE,MAAM,YAAY,CAAC;AAE/E,MAAM,WAAW,uBAAuB;IACtC,QAAQ,CAAC,EAAE,EAAE,MAAM,CAAC;IACpB,QAAQ,CAAC,KAAK,EAAE,MAAM,CAAC;IACvB,QAAQ,CAAC,OAAO,EAAE,OAAO,CAAC;IAC1B,QAAQ,CAAC,SAAS,EAAE,wBAAwB,CAAC;IAC7C,QAAQ,CAAC,UAAU,EAAE,kBAAkB,CAAC;IACxC,QAAQ,CAAC,UAAU,EAAE,QAAQ,CAAC,MAAM,CAAC,MAAM,EAAE,SAAS,CAAC,CAAC,CAAC;CAC1D;AAED,MAAM,WAAW,mBAAmB;IAClC,QAAQ,CAAC,OAAO,EAAE,SAAS,MAAM,EAAE,CAAC;IACpC,QAAQ,CAAC,KAAK,EAAE,OAAO,CAAC;IACxB,QAAQ,CAAC,aAAa,CAAC,EAAE,MAAM,CAAC;CACjC;AAED,MAAM,WAAW,uBAAuB;IACtC,QAAQ,CAAC,KAAK,EAAE,SAAS,uBAAuB,EAAE,CAAC;IACnD,QAAQ,CAAC,YAAY,EAAE,SAAS,mBAAmB,EAAE,CAAC;IACtD,QAAQ,CAAC,QAAQ,EAAE,MAAM,CAAC;IAC1B,QAAQ,CAAC,YAAY,EAAE,MAAM,CAAC;CAC/B;AA8DD,wBAAsB,6BAA6B,CACjD,KAAK,EAAE,SAAS,uBAAuB,EAAE,EACzC,OAAO,EAAE;IACP,QAAQ,CAAC,YAAY,CAAC,EAAE,MAAM,CAAC;IAC/B,QAAQ,CAAC,WAAW,EAAE,MAAM,CAAC;IAC7B,QAAQ,CAAC,YAAY,EAAE,MAAM,CAAC;IAC9B,QAAQ,CAAC,iBAAiB,EAAE,MAAM,CAAC;IACnC,QAAQ,CAAC,cAAc,CAAC,EAAE,MAAM,CAAC;CAClC,GACA,OAAO,CAAC,uBAAuB,CAAC,CA6ClC;AAED,MAAM,WAAW,8BAA8B;IAC7C,QAAQ,CAAC,aAAa,EAAE,MAAM,CAAC;IAC/B,QAAQ,CAAC,MAAM,CAAC,EAAE,SAAS,MAAM,EAAE,CAAC;IACpC,QAAQ,CAAC,cAAc,CAAC,EAAE,MAAM,CAAC;CAClC;AAED,8FAA8F;AAC9F,qBAAa,iCAAiC;;gBASzB,OAAO,EAAE,8BAA8B;IAqB1D,IAAW,YAAY,IAAI,MAAM,CAIhC;IAEM,WAAW,CAAC,OAAO,EAAE,MAAM,GAAG,MAAM;IAoBpC,KAAK,IAAI,IAAI;CAMrB"}
@@ -0,0 +1,169 @@
1
+ import { canonicalMaterialBytes, sha256Hex } from './canonical.js';
2
+ function fusionBarrier(slot) {
3
+ const { definition } = slot;
4
+ if (definition.implementations.every(value => value.type !== 'graph'))
5
+ return 'native-code';
6
+ if (definition.execution.temporal.stateful)
7
+ return 'stateful';
8
+ if (definition.execution.temporal.pastUs > 0 || definition.execution.temporal.futureUs > 0) {
9
+ return 'temporal-neighborhood';
10
+ }
11
+ if (definition.execution.resolution.policy !== 'same-as-host')
12
+ return 'resolution-change';
13
+ if (definition.execution.spatialPadding.mode !== 'none')
14
+ return 'spatial-padding';
15
+ if (definition.execution.determinism === 'non-deterministic')
16
+ return 'non-deterministic';
17
+ return undefined;
18
+ }
19
+ function validateSlots(slots) {
20
+ if (slots.length > 64)
21
+ throw new RangeError('Material composition supports at most 64 slots');
22
+ const ids = new Set();
23
+ for (const slot of slots) {
24
+ if (slot.id.length === 0 || ids.has(slot.id))
25
+ throw new TypeError('MATERIAL_SLOT_ID_INVALID');
26
+ if (!Number.isSafeInteger(slot.order))
27
+ throw new RangeError('MATERIAL_SLOT_ORDER_INVALID');
28
+ ids.add(slot.id);
29
+ }
30
+ return slots
31
+ .filter(value => value.enabled)
32
+ .slice()
33
+ .sort((left, right) => left.order - right.order || left.id.localeCompare(right.id));
34
+ }
35
+ function buildFusionGroups(slots, maxFusedPasses) {
36
+ const groups = [];
37
+ let current = [];
38
+ const flush = () => {
39
+ if (current.length === 0)
40
+ return;
41
+ groups.push({ slotIds: current, fused: current.length > 1 });
42
+ current = [];
43
+ };
44
+ for (const slot of slots) {
45
+ const barrier = fusionBarrier(slot);
46
+ if (barrier !== undefined) {
47
+ flush();
48
+ groups.push({ slotIds: [slot.id], fused: false, barrierReason: barrier });
49
+ continue;
50
+ }
51
+ if (current.length >= maxFusedPasses)
52
+ flush();
53
+ current.push(slot.id);
54
+ }
55
+ flush();
56
+ return groups;
57
+ }
58
+ function canonicalParameters(parameters) {
59
+ return Object.fromEntries(Object.entries(parameters).sort(([left], [right]) => left.localeCompare(right)));
60
+ }
61
+ export async function createMaterialCompositionPlan(slots, options) {
62
+ const ordered = validateSlots(slots);
63
+ const qualityScale = options.qualityScale ?? 1;
64
+ const maxFusedPasses = options.maxFusedPasses ?? 8;
65
+ if (!(qualityScale > 0 && qualityScale <= 1))
66
+ throw new RangeError('QUALITY_SCALE_INVALID');
67
+ if (!Number.isSafeInteger(maxFusedPasses) || maxFusedPasses <= 0 || maxFusedPasses > 16) {
68
+ throw new RangeError('MAX_FUSED_PASSES_INVALID');
69
+ }
70
+ if (!Number.isSafeInteger(options.outputWidth) ||
71
+ !Number.isSafeInteger(options.outputHeight) ||
72
+ options.outputWidth <= 0 ||
73
+ options.outputHeight <= 0) {
74
+ throw new RangeError('MATERIAL_OUTPUT_SIZE_INVALID');
75
+ }
76
+ const fusionGroups = buildFusionGroups(ordered, maxFusedPasses);
77
+ const keyValue = {
78
+ protocol: 'aelion-material-composition/1',
79
+ output: {
80
+ width: options.outputWidth,
81
+ height: options.outputHeight,
82
+ workingColorSpace: options.workingColorSpace,
83
+ qualityScale,
84
+ },
85
+ slots: ordered.map(slot => ({
86
+ id: slot.id,
87
+ packageId: slot.reference.packageId,
88
+ packageVersion: slot.reference.packageVersion,
89
+ packageIntegrity: slot.reference.packageIntegrity,
90
+ materialId: slot.reference.materialId,
91
+ parameters: canonicalParameters(slot.parameters),
92
+ })),
93
+ fusionGroups: fusionGroups.map(group => ({
94
+ slotIds: [...group.slotIds],
95
+ fused: group.fused,
96
+ ...(group.barrierReason === undefined ? {} : { barrierReason: group.barrierReason }),
97
+ })),
98
+ };
99
+ return {
100
+ slots: ordered,
101
+ fusionGroups,
102
+ cacheKey: `sha256:${await sha256Hex(canonicalMaterialBytes(keyValue))}`,
103
+ qualityScale,
104
+ };
105
+ }
106
+ /** Hysteresis controller for preview quality; offline rendering should always use scale 1. */
107
+ export class AdaptiveMaterialQualityController {
108
+ #targetFrameMs;
109
+ #levels;
110
+ #recoveryFrames;
111
+ #levelIndex = 0;
112
+ #averageFrameMs = 0;
113
+ #samples = 0;
114
+ #underBudgetFrames = 0;
115
+ constructor(options) {
116
+ if (!Number.isFinite(options.targetFrameMs) || options.targetFrameMs <= 0) {
117
+ throw new RangeError('TARGET_FRAME_TIME_INVALID');
118
+ }
119
+ const levels = [...(options.levels ?? [1, 0.75, 0.5, 0.25])];
120
+ const invalidLevel = levels.some((value, index) => {
121
+ const previous = levels[index - 1];
122
+ return !(value > 0 && value <= 1) || (previous !== undefined && value >= previous);
123
+ });
124
+ if (levels.length === 0 || invalidLevel) {
125
+ throw new RangeError('QUALITY_LEVELS_INVALID');
126
+ }
127
+ const recoveryFrames = options.recoveryFrames ?? 30;
128
+ if (!Number.isSafeInteger(recoveryFrames) || recoveryFrames <= 0) {
129
+ throw new RangeError('RECOVERY_FRAMES_INVALID');
130
+ }
131
+ this.#targetFrameMs = options.targetFrameMs;
132
+ this.#levels = levels;
133
+ this.#recoveryFrames = recoveryFrames;
134
+ }
135
+ get qualityScale() {
136
+ const value = this.#levels[this.#levelIndex];
137
+ if (value === undefined)
138
+ throw new RangeError('QUALITY_LEVELS_INVALID');
139
+ return value;
140
+ }
141
+ reportFrame(frameMs) {
142
+ if (!Number.isFinite(frameMs) || frameMs < 0)
143
+ throw new RangeError('FRAME_TIME_INVALID');
144
+ this.#averageFrameMs =
145
+ this.#samples === 0 ? frameMs : this.#averageFrameMs * 0.8 + frameMs * 0.2;
146
+ this.#samples++;
147
+ if (this.#averageFrameMs > this.#targetFrameMs * 1.1) {
148
+ this.#levelIndex = Math.min(this.#levelIndex + 1, this.#levels.length - 1);
149
+ this.#underBudgetFrames = 0;
150
+ }
151
+ else if (this.#averageFrameMs < this.#targetFrameMs * 0.75) {
152
+ this.#underBudgetFrames++;
153
+ if (this.#underBudgetFrames >= this.#recoveryFrames) {
154
+ this.#levelIndex = Math.max(0, this.#levelIndex - 1);
155
+ this.#underBudgetFrames = 0;
156
+ }
157
+ }
158
+ else {
159
+ this.#underBudgetFrames = 0;
160
+ }
161
+ return this.qualityScale;
162
+ }
163
+ reset() {
164
+ this.#levelIndex = 0;
165
+ this.#averageFrameMs = 0;
166
+ this.#samples = 0;
167
+ this.#underBudgetFrames = 0;
168
+ }
169
+ }
@@ -0,0 +1,48 @@
1
+ import type { JsonValue } from '@aelionsdk/core';
2
+ import { type AuthoredMaterial, type BundledMaterialResource, type MaterialDefinition, type MaterialDisplay, type MaterialExecutionContract, type MaterialImplementation, type MaterialKind, type MaterialParameter, type MaterialPort, type MaterialResourceSlot, type MaterialScope } from './types.js';
3
+ import type { MaterialGraph } from '@aelionsdk/material-compiler';
4
+ export interface MaterialDefinitionBuilderOptions {
5
+ readonly id: string;
6
+ readonly kind: MaterialKind;
7
+ readonly display: MaterialDisplay;
8
+ readonly scopes?: readonly MaterialScope[];
9
+ }
10
+ export declare class MaterialDefinitionBuilder {
11
+ #private;
12
+ constructor(options: MaterialDefinitionBuilderOptions);
13
+ port(port: MaterialPort): this;
14
+ parameter(parameter: MaterialParameter): this;
15
+ floatParameter(id: string, options: {
16
+ readonly default: number;
17
+ readonly min?: number;
18
+ readonly max?: number;
19
+ readonly step?: number;
20
+ readonly label?: string;
21
+ readonly group?: string;
22
+ readonly order?: number;
23
+ readonly unit?: MaterialParameter['unit'];
24
+ readonly animatable?: boolean;
25
+ readonly affects?: MaterialParameter['affects'];
26
+ }): this;
27
+ enumParameter(id: string, options: {
28
+ readonly default: string;
29
+ readonly values: readonly string[];
30
+ readonly label?: string;
31
+ readonly group?: string;
32
+ readonly order?: number;
33
+ readonly affects?: MaterialParameter['affects'];
34
+ }): this;
35
+ bundledResource(resource: BundledMaterialResource): this;
36
+ resourceSlot(resource: MaterialResourceSlot): this;
37
+ graph(path: string, graph: MaterialGraph): this;
38
+ /** Adds trusted executable code. The package still requires explicit host authorization. */
39
+ trustedImplementation(implementation: Exclude<MaterialImplementation, {
40
+ type: 'graph';
41
+ }>): this;
42
+ execution(contract: MaterialExecutionContract): this;
43
+ splitPolicy(policy: MaterialDefinition['splitPolicy']): this;
44
+ build(): AuthoredMaterial;
45
+ }
46
+ export declare function materialDefinition(options: MaterialDefinitionBuilderOptions): MaterialDefinitionBuilder;
47
+ export type MaterialParameterDefault = JsonValue;
48
+ //# sourceMappingURL=definition-builder.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"definition-builder.d.ts","sourceRoot":"","sources":["../src/definition-builder.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,iBAAiB,CAAC;AAEjD,OAAO,EAIL,KAAK,gBAAgB,EACrB,KAAK,uBAAuB,EAC5B,KAAK,kBAAkB,EACvB,KAAK,eAAe,EACpB,KAAK,yBAAyB,EAC9B,KAAK,sBAAsB,EAC3B,KAAK,YAAY,EACjB,KAAK,iBAAiB,EACtB,KAAK,YAAY,EACjB,KAAK,oBAAoB,EACzB,KAAK,aAAa,EACnB,MAAM,YAAY,CAAC;AACpB,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,8BAA8B,CAAC;AAElE,MAAM,WAAW,gCAAgC;IAC/C,QAAQ,CAAC,EAAE,EAAE,MAAM,CAAC;IACpB,QAAQ,CAAC,IAAI,EAAE,YAAY,CAAC;IAC5B,QAAQ,CAAC,OAAO,EAAE,eAAe,CAAC;IAClC,QAAQ,CAAC,MAAM,CAAC,EAAE,SAAS,aAAa,EAAE,CAAC;CAC5C;AAiDD,qBAAa,yBAAyB;;gBAYxB,OAAO,EAAE,gCAAgC;IAKrD,IAAI,CAAC,IAAI,EAAE,YAAY,GAAG,IAAI;IAK9B,SAAS,CAAC,SAAS,EAAE,iBAAiB,GAAG,IAAI;IAK7C,cAAc,CACZ,EAAE,EAAE,MAAM,EACV,OAAO,EAAE;QACP,QAAQ,CAAC,OAAO,EAAE,MAAM,CAAC;QACzB,QAAQ,CAAC,GAAG,CAAC,EAAE,MAAM,CAAC;QACtB,QAAQ,CAAC,GAAG,CAAC,EAAE,MAAM,CAAC;QACtB,QAAQ,CAAC,IAAI,CAAC,EAAE,MAAM,CAAC;QACvB,QAAQ,CAAC,KAAK,CAAC,EAAE,MAAM,CAAC;QACxB,QAAQ,CAAC,KAAK,CAAC,EAAE,MAAM,CAAC;QACxB,QAAQ,CAAC,KAAK,CAAC,EAAE,MAAM,CAAC;QACxB,QAAQ,CAAC,IAAI,CAAC,EAAE,iBAAiB,CAAC,MAAM,CAAC,CAAC;QAC1C,QAAQ,CAAC,UAAU,CAAC,EAAE,OAAO,CAAC;QAC9B,QAAQ,CAAC,OAAO,CAAC,EAAE,iBAAiB,CAAC,SAAS,CAAC,CAAC;KACjD,GACA,IAAI;IA2BP,aAAa,CACX,EAAE,EAAE,MAAM,EACV,OAAO,EAAE;QACP,QAAQ,CAAC,OAAO,EAAE,MAAM,CAAC;QACzB,QAAQ,CAAC,MAAM,EAAE,SAAS,MAAM,EAAE,CAAC;QACnC,QAAQ,CAAC,KAAK,CAAC,EAAE,MAAM,CAAC;QACxB,QAAQ,CAAC,KAAK,CAAC,EAAE,MAAM,CAAC;QACxB,QAAQ,CAAC,KAAK,CAAC,EAAE,MAAM,CAAC;QACxB,QAAQ,CAAC,OAAO,CAAC,EAAE,iBAAiB,CAAC,SAAS,CAAC,CAAC;KACjD,GACA,IAAI;IAkBP,eAAe,CAAC,QAAQ,EAAE,uBAAuB,GAAG,IAAI;IAKxD,YAAY,CAAC,QAAQ,EAAE,oBAAoB,GAAG,IAAI;IAKlD,KAAK,CAAC,IAAI,EAAE,MAAM,EAAE,KAAK,EAAE,aAAa,GAAG,IAAI;IAO/C,4FAA4F;IAC5F,qBAAqB,CAAC,cAAc,EAAE,OAAO,CAAC,sBAAsB,EAAE;QAAE,IAAI,EAAE,OAAO,CAAA;KAAE,CAAC,GAAG,IAAI;IAK/F,SAAS,CAAC,QAAQ,EAAE,yBAAyB,GAAG,IAAI;IAKpD,WAAW,CAAC,MAAM,EAAE,kBAAkB,CAAC,aAAa,CAAC,GAAG,IAAI;IAK5D,KAAK,IAAI,gBAAgB;CAuB1B;AAED,wBAAgB,kBAAkB,CAChC,OAAO,EAAE,gCAAgC,GACxC,yBAAyB,CAE3B;AAGD,MAAM,MAAM,wBAAwB,GAAG,SAAS,CAAC"}
@@ -0,0 +1,159 @@
1
+ import { MATERIAL_DEFINITION_SCHEMA, MATERIAL_NODE_SET, MATERIAL_PROTOCOL_VERSION, } from './types.js';
2
+ const DEFAULT_EXECUTION = {
3
+ color: { input: 'working-linear', output: 'working-linear' },
4
+ alpha: {
5
+ input: 'premultiplied',
6
+ output: 'premultiplied',
7
+ preservesTransparency: true,
8
+ },
9
+ resolution: { policy: 'same-as-host' },
10
+ spatialPadding: { mode: 'none' },
11
+ temporal: { pastUs: 0, futureUs: 0, stateful: false, seekPolicy: 'stateless' },
12
+ determinism: 'strict',
13
+ supports: { realtime: true, offline: true, alpha: true, hdr: false, tiled: true },
14
+ };
15
+ function hostPort(id, direction, role) {
16
+ return { id, direction, type: 'visual-frame', role, binding: 'host', required: true };
17
+ }
18
+ function defaultPorts(kind) {
19
+ switch (kind) {
20
+ case 'visual-filter':
21
+ return [hostPort('source', 'input', 'source'), hostPort('result', 'output', 'result')];
22
+ case 'visual-transition':
23
+ return [
24
+ hostPort('from', 'input', 'from'),
25
+ hostPort('to', 'input', 'to'),
26
+ hostPort('result', 'output', 'result'),
27
+ ];
28
+ case 'visual-generator':
29
+ return [hostPort('result', 'output', 'result')];
30
+ case 'visual-effect':
31
+ return [hostPort('source', 'input', 'source'), hostPort('result', 'output', 'result')];
32
+ }
33
+ }
34
+ function defaultScopes(kind) {
35
+ return kind === 'visual-transition'
36
+ ? ['transition']
37
+ : kind === 'visual-generator'
38
+ ? ['item']
39
+ : ['source', 'item', 'track', 'sequence'];
40
+ }
41
+ export class MaterialDefinitionBuilder {
42
+ #options;
43
+ #ports;
44
+ #parameters = [];
45
+ #bundledResources = [];
46
+ #resourceSlots = [];
47
+ #implementations = [];
48
+ #execution = DEFAULT_EXECUTION;
49
+ #splitPolicy = 'copy';
50
+ #graph;
51
+ #graphPath;
52
+ constructor(options) {
53
+ this.#options = options;
54
+ this.#ports = defaultPorts(options.kind);
55
+ }
56
+ port(port) {
57
+ this.#ports.push(port);
58
+ return this;
59
+ }
60
+ parameter(parameter) {
61
+ this.#parameters.push(parameter);
62
+ return this;
63
+ }
64
+ floatParameter(id, options) {
65
+ const range = options.min === undefined && options.max === undefined && options.step === undefined
66
+ ? undefined
67
+ : {
68
+ ...(options.min === undefined ? {} : { min: options.min, softMin: options.min }),
69
+ ...(options.max === undefined ? {} : { max: options.max, softMax: options.max }),
70
+ ...(options.step === undefined ? {} : { step: options.step }),
71
+ };
72
+ return this.parameter({
73
+ id,
74
+ type: 'float',
75
+ default: options.default,
76
+ ...(range === undefined ? {} : { range }),
77
+ ...(options.unit === undefined ? {} : { unit: options.unit }),
78
+ animatable: options.animatable ?? true,
79
+ interpolation: 'linear',
80
+ affects: options.affects ?? 'uniform',
81
+ ui: {
82
+ control: 'slider',
83
+ group: options.group ?? 'main',
84
+ order: options.order ?? this.#parameters.length,
85
+ label: options.label ?? id,
86
+ },
87
+ });
88
+ }
89
+ enumParameter(id, options) {
90
+ return this.parameter({
91
+ id,
92
+ type: 'enum',
93
+ default: options.default,
94
+ values: options.values,
95
+ animatable: false,
96
+ interpolation: 'hold',
97
+ affects: options.affects ?? 'specialization',
98
+ ui: {
99
+ control: 'select',
100
+ group: options.group ?? 'main',
101
+ order: options.order ?? this.#parameters.length,
102
+ label: options.label ?? id,
103
+ },
104
+ });
105
+ }
106
+ bundledResource(resource) {
107
+ this.#bundledResources.push(resource);
108
+ return this;
109
+ }
110
+ resourceSlot(resource) {
111
+ this.#resourceSlots.push(resource);
112
+ return this;
113
+ }
114
+ graph(path, graph) {
115
+ this.#graphPath = path;
116
+ this.#graph = graph;
117
+ this.#implementations.push({ type: 'graph', graph: path, nodeSet: MATERIAL_NODE_SET });
118
+ return this;
119
+ }
120
+ /** Adds trusted executable code. The package still requires explicit host authorization. */
121
+ trustedImplementation(implementation) {
122
+ this.#implementations.push(implementation);
123
+ return this;
124
+ }
125
+ execution(contract) {
126
+ this.#execution = contract;
127
+ return this;
128
+ }
129
+ splitPolicy(policy) {
130
+ this.#splitPolicy = policy;
131
+ return this;
132
+ }
133
+ build() {
134
+ const definition = {
135
+ $schema: MATERIAL_DEFINITION_SCHEMA,
136
+ protocolVersion: MATERIAL_PROTOCOL_VERSION,
137
+ id: this.#options.id,
138
+ kind: this.#options.kind,
139
+ display: this.#options.display,
140
+ scopes: this.#options.scopes ?? defaultScopes(this.#options.kind),
141
+ ports: [...this.#ports],
142
+ parameters: [...this.#parameters],
143
+ bundledResources: [...this.#bundledResources],
144
+ resourceSlots: [...this.#resourceSlots],
145
+ execution: this.#execution,
146
+ implementations: [...this.#implementations],
147
+ splitPolicy: this.#splitPolicy,
148
+ };
149
+ return {
150
+ definition,
151
+ ...(this.#graph === undefined ? {} : { graph: this.#graph }),
152
+ definitionPath: `materials/${this.#options.id}.material.json`,
153
+ ...(this.#graphPath === undefined ? {} : { graphPath: this.#graphPath }),
154
+ };
155
+ }
156
+ }
157
+ export function materialDefinition(options) {
158
+ return new MaterialDefinitionBuilder(options);
159
+ }