@azphalt/importer-transition 0.1.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/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 Az
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/dist/cli.d.ts ADDED
@@ -0,0 +1,2 @@
1
+ #!/usr/bin/env node
2
+ export {};
package/dist/cli.js ADDED
@@ -0,0 +1,84 @@
1
+ #!/usr/bin/env node
2
+ /** CLI for `@azphalt/importer-transition`: wrap a GL Transition into a `.azp` package. */
3
+ import { readFileSync, writeFileSync } from "node:fs";
4
+ import { basename, extname } from "node:path";
5
+ import { importGlTransition } from "./index.js";
6
+ const USAGE = "usage: azphalt-import-transition <input.glsl> --id <reverse.dns.id> " +
7
+ "[-o out.azp] [--name N] [--version V] [--license SPDX] [--license-file PATH] [--author A]";
8
+ function parse(argv) {
9
+ const a = {};
10
+ for (let i = 0; i < argv.length; i++) {
11
+ const t = argv[i];
12
+ switch (t) {
13
+ case "-o":
14
+ case "--out":
15
+ a.out = argv[++i];
16
+ break;
17
+ case "--id":
18
+ a.id = argv[++i];
19
+ break;
20
+ case "--name":
21
+ a.name = argv[++i];
22
+ break;
23
+ case "--version":
24
+ a.version = argv[++i];
25
+ break;
26
+ case "--license":
27
+ a.license = argv[++i];
28
+ break;
29
+ case "--license-file":
30
+ a.licenseFile = argv[++i];
31
+ break;
32
+ case "--author":
33
+ a.author = argv[++i];
34
+ break;
35
+ default:
36
+ if (!t.startsWith("-") && !a.input)
37
+ a.input = t;
38
+ else
39
+ fail(`unknown argument: ${t}`);
40
+ }
41
+ }
42
+ return a;
43
+ }
44
+ function fail(msg) {
45
+ console.error(`error: ${msg}`);
46
+ console.error(USAGE);
47
+ process.exit(2);
48
+ }
49
+ const args = parse(process.argv.slice(2));
50
+ if (!args.input)
51
+ fail("an input .glsl transition file is required");
52
+ if (!args.id)
53
+ fail("--id <reverse-DNS id> is required (e.g. com.hereliesaz.crosswarp)");
54
+ let source;
55
+ try {
56
+ source = readFileSync(args.input, "utf8");
57
+ }
58
+ catch (e) {
59
+ fail(`failed to read input file: ${e.message}`);
60
+ }
61
+ let licenseText;
62
+ if (args.licenseFile) {
63
+ try {
64
+ licenseText = readFileSync(args.licenseFile, "utf8");
65
+ }
66
+ catch (e) {
67
+ fail(`failed to read license file: ${e.message}`);
68
+ }
69
+ }
70
+ else {
71
+ const spdx = args.license ?? "MIT";
72
+ licenseText = `${spdx}\n\nProvide the full license text with --license-file.\n`;
73
+ console.error(`warning: no --license-file; writing a placeholder LICENSE (SPDX: ${spdx}).`);
74
+ }
75
+ const out = args.out ?? basename(args.input, extname(args.input)) + ".azp";
76
+ const { azp, manifest, panel } = importGlTransition(source, licenseText, {
77
+ id: args.id,
78
+ name: args.name,
79
+ version: args.version,
80
+ license: args.license,
81
+ author: args.author,
82
+ });
83
+ writeFileSync(out, azp);
84
+ console.error(`wrote ${out} (${manifest.id} v${manifest.version}, ${panel.controls.length} control(s), ${azp.length} bytes)`);
@@ -0,0 +1,32 @@
1
+ /**
2
+ * `@azphalt/importer-transition` — normalize a GL Transition (gl-transitions.com) into a `.azp`
3
+ * asset package. The GLSL source is stored verbatim; its tunable uniforms become an azphalt UI
4
+ * panel plus manifest params, so an adopting host — e.g. Guillotine, the video editor whose
5
+ * clip-to-clip transitions this feeds — renders the controls natively and runs the transition with
6
+ * its own engine. See `spec/package-format.md` § Assets.
7
+ */
8
+ import { type WriteResult } from "@azphalt/azp";
9
+ import type { Panel } from "@azphalt/sdk";
10
+ import { type ParsedGlTransition } from "./parse-gl-transition.js";
11
+ export interface TransitionImportOptions {
12
+ /** Reverse-DNS id, e.g. `"com.hereliesaz.crosswarp"`. Required. */
13
+ id: string;
14
+ /** Display name; defaults to the transition's `name` metadata, then the asset stem. */
15
+ name?: string;
16
+ /** Semver; default `"1.0.0"`. */
17
+ version?: string;
18
+ /** SPDX id for the manifest; default the transition's `License`, then `"MIT"`. */
19
+ license?: string;
20
+ author?: string;
21
+ /** Base name for the stored shader, e.g. `"crosswarp"` -> `assets/crosswarp.glsl`. */
22
+ assetName?: string;
23
+ }
24
+ export interface TransitionImportResult extends WriteResult {
25
+ parsed: ParsedGlTransition;
26
+ panel: Panel;
27
+ }
28
+ /** Parse a gl-transition, derive its UI panel, and package it as a `.azp` transition asset. */
29
+ export declare function importGlTransition(source: string, licenseText: string, opts: TransitionImportOptions): TransitionImportResult;
30
+ export { parseGlTransition, HOST_PROVIDED } from "./parse-gl-transition.js";
31
+ export type { ParsedGlTransition, GlUniform } from "./parse-gl-transition.js";
32
+ export { uniformsToPanel, uniformToControl, isHostBound } from "./ui.js";
package/dist/index.js ADDED
@@ -0,0 +1,58 @@
1
+ /**
2
+ * `@azphalt/importer-transition` — normalize a GL Transition (gl-transitions.com) into a `.azp`
3
+ * asset package. The GLSL source is stored verbatim; its tunable uniforms become an azphalt UI
4
+ * panel plus manifest params, so an adopting host — e.g. Guillotine, the video editor whose
5
+ * clip-to-clip transitions this feeds — renders the controls natively and runs the transition with
6
+ * its own engine. See `spec/package-format.md` § Assets.
7
+ */
8
+ import { writeAzp } from "@azphalt/azp";
9
+ import { parseGlTransition } from "./parse-gl-transition.js";
10
+ import { isHostBound, uniformsToPanel } from "./ui.js";
11
+ const FORMAT = "0.1";
12
+ /** Parse a gl-transition, derive its UI panel, and package it as a `.azp` transition asset. */
13
+ export function importGlTransition(source, licenseText, opts) {
14
+ const parsed = parseGlTransition(source);
15
+ const stem = opts.assetName ?? slug(opts.name ?? parsed.name ?? "transition");
16
+ const assetPath = `assets/${stem}.glsl`;
17
+ const uiPath = `ui/${stem}.json`;
18
+ const panel = uniformsToPanel(parsed.uniforms);
19
+ const hasUi = panel.controls.length > 0;
20
+ const manifest = {
21
+ azphalt: FORMAT,
22
+ id: opts.id,
23
+ name: opts.name ?? parsed.name ?? stem,
24
+ version: opts.version ?? "1.0.0",
25
+ kind: "asset",
26
+ license: opts.license ?? parsed.license ?? "MIT",
27
+ compat: ">=0.1",
28
+ author: opts.author ?? parsed.author,
29
+ assets: [
30
+ {
31
+ type: "transition",
32
+ path: assetPath,
33
+ ...(hasUi ? { ui: uiPath } : {}),
34
+ params: {
35
+ format: "gl-transition",
36
+ ...(parsed.name ? { title: parsed.name } : {}),
37
+ // Declared uniforms (including host-bound textures the host wires to the clips).
38
+ uniforms: parsed.uniforms.map((u) => ({
39
+ name: u.name,
40
+ type: u.glslType,
41
+ hostBound: isHostBound(u),
42
+ })),
43
+ },
44
+ },
45
+ ],
46
+ };
47
+ const payload = { [assetPath]: new TextEncoder().encode(source) };
48
+ if (hasUi)
49
+ payload[uiPath] = new TextEncoder().encode(JSON.stringify(panel, null, 2) + "\n");
50
+ const result = writeAzp({ manifest, payload, license: licenseText });
51
+ return { ...result, parsed, panel };
52
+ }
53
+ /** Filesystem-safe stem: lowercase, runs of non-alphanumerics to single hyphens. */
54
+ function slug(s) {
55
+ return s.toLowerCase().replace(/[^a-z0-9]+/g, "-").replace(/^-+|-+$/g, "") || "transition";
56
+ }
57
+ export { parseGlTransition, HOST_PROVIDED } from "./parse-gl-transition.js";
58
+ export { uniformsToPanel, uniformToControl, isHostBound } from "./ui.js";
@@ -0,0 +1,26 @@
1
+ /**
2
+ * Parser for the GL Transitions format (gl-transitions.com) — a GLSL fragment defining
3
+ * `vec4 transition(vec2 uv)`, with metadata in `//` comments and tunable `uniform` parameters
4
+ * annotated with a default (`uniform float intensity; // = 1.0`). The host supplies `from`/`to`
5
+ * (the two clips), `progress`, and `ratio`; those are not user parameters. We validate + describe
6
+ * — the original source is stored verbatim in the package.
7
+ */
8
+ export interface GlUniform {
9
+ name: string;
10
+ /** GLSL type: `float` | `int` | `bool` | `vec2..4` | `ivec2..4` | `sampler2D` | … */
11
+ glslType: string;
12
+ /** Parsed default from the `// = …` annotation, if any. */
13
+ default?: number | boolean | number[];
14
+ }
15
+ export interface ParsedGlTransition {
16
+ name?: string;
17
+ author?: string;
18
+ license?: string;
19
+ /** User-tunable uniforms (excludes the host-provided `from`/`to`/`progress`/`ratio`). */
20
+ uniforms: GlUniform[];
21
+ source: string;
22
+ }
23
+ /** Uniforms the gl-transitions runtime provides — never user controls. */
24
+ export declare const HOST_PROVIDED: ReadonlySet<string>;
25
+ /** Parse gl-transition GLSL into a {@link ParsedGlTransition}. */
26
+ export declare function parseGlTransition(source: string): ParsedGlTransition;
@@ -0,0 +1,66 @@
1
+ /**
2
+ * Parser for the GL Transitions format (gl-transitions.com) — a GLSL fragment defining
3
+ * `vec4 transition(vec2 uv)`, with metadata in `//` comments and tunable `uniform` parameters
4
+ * annotated with a default (`uniform float intensity; // = 1.0`). The host supplies `from`/`to`
5
+ * (the two clips), `progress`, and `ratio`; those are not user parameters. We validate + describe
6
+ * — the original source is stored verbatim in the package.
7
+ */
8
+ /** Uniforms the gl-transitions runtime provides — never user controls. */
9
+ export const HOST_PROVIDED = new Set(["from", "to", "progress", "ratio"]);
10
+ const VEC_SIZE = { vec2: 2, vec3: 3, vec4: 4, ivec2: 2, ivec3: 3, ivec4: 4 };
11
+ function numbersIn(expr) {
12
+ // Strip GLSL identifiers (vec3, mix, …) so their digits aren't parsed as numbers, then match
13
+ // int/float literals including trailing-dot (`1.`) and exponent forms.
14
+ const clean = expr.replace(/\b[a-zA-Z_]\w*\b/g, "");
15
+ const matches = clean.match(/-?\d+(?:\.\d*)?(?:[eE][+-]?\d+)?|-?\.\d+(?:[eE][+-]?\d+)?/g) ?? [];
16
+ return matches.map(Number);
17
+ }
18
+ function parseDefault(glslType, expr) {
19
+ if (expr === undefined)
20
+ return undefined;
21
+ const e = expr.trim();
22
+ if (glslType === "bool")
23
+ return e === "true" || e === "1";
24
+ if (glslType === "float" || glslType === "int") {
25
+ const n = numbersIn(e)[0];
26
+ return n !== undefined && Number.isFinite(n) ? n : undefined;
27
+ }
28
+ const size = VEC_SIZE[glslType];
29
+ if (size) {
30
+ let nums = numbersIn(e); // identifiers are stripped, so vecN(...)'s own digit isn't captured
31
+ if (nums.length === 1)
32
+ nums = Array(size).fill(nums[0]); // GLSL vecN(x) fills all components
33
+ return nums.slice(0, size);
34
+ }
35
+ return undefined;
36
+ }
37
+ function scanMeta(source, key) {
38
+ const m = new RegExp(`//\\s*${key}\\s*:\\s*(.+)`, "i").exec(source);
39
+ return m ? m[1].trim() : undefined;
40
+ }
41
+ /** Parse gl-transition GLSL into a {@link ParsedGlTransition}. */
42
+ export function parseGlTransition(source) {
43
+ if (!/\btransition\s*\(/.test(source)) {
44
+ throw new Error("gl-transition: source does not define a transition(...) function");
45
+ }
46
+ const uniforms = [];
47
+ const seen = new Set();
48
+ const re = /uniform\s+(?:(?:lowp|mediump|highp)\s+)?(\w+)\s+(\w+)\s*;[ \t]*(?:\/\/\s*=\s*([^\n\r]*))?/g;
49
+ let m;
50
+ while ((m = re.exec(source)) !== null) {
51
+ const [, glslType, name, defExpr] = m;
52
+ if (HOST_PROVIDED.has(name))
53
+ continue; // host binds these
54
+ if (seen.has(name))
55
+ throw new Error(`gl-transition: duplicate uniform '${name}'`);
56
+ seen.add(name);
57
+ uniforms.push({ name, glslType, default: parseDefault(glslType, defExpr) });
58
+ }
59
+ return {
60
+ name: scanMeta(source, "name"),
61
+ author: scanMeta(source, "author"),
62
+ license: scanMeta(source, "license"),
63
+ uniforms,
64
+ source,
65
+ };
66
+ }
package/dist/ui.d.ts ADDED
@@ -0,0 +1,13 @@
1
+ /**
2
+ * Map gl-transition uniforms onto azphalt's host-rendered UI schema (`spec/ui-schema.md`), so a
3
+ * transition's parameters render natively in any adopting host. `sampler2D` uniforms are textures
4
+ * the host binds, not user controls, so they are excluded from the panel.
5
+ */
6
+ import type { Control, Panel } from "@azphalt/sdk";
7
+ import type { GlUniform } from "./parse-gl-transition.js";
8
+ /** A texture uniform the host binds — not a user control. */
9
+ export declare function isHostBound(u: GlUniform): boolean;
10
+ /** Convert one uniform to an azphalt control, or `null` if it is host-bound / unmappable. */
11
+ export declare function uniformToControl(u: GlUniform): Control | null;
12
+ /** Build a {@link Panel} from a uniform list, skipping host-bound textures. */
13
+ export declare function uniformsToPanel(uniforms: GlUniform[]): Panel;
package/dist/ui.js ADDED
@@ -0,0 +1,43 @@
1
+ const VEC_SIZE = { vec2: 2, vec3: 3, vec4: 4, ivec2: 2, ivec3: 3, ivec4: 4 };
2
+ /** A texture uniform the host binds — not a user control. */
3
+ export function isHostBound(u) {
4
+ return u.glslType === "sampler2D";
5
+ }
6
+ /** Convert one uniform to an azphalt control, or `null` if it is host-bound / unmappable. */
7
+ export function uniformToControl(u) {
8
+ const key = u.name;
9
+ const label = u.name;
10
+ if (u.glslType === "bool") {
11
+ return { type: "toggle", key, label, default: u.default === true };
12
+ }
13
+ if (u.glslType === "float" || u.glslType === "int") {
14
+ return { type: "number", key, label, default: typeof u.default === "number" ? u.default : 0 };
15
+ }
16
+ const size = VEC_SIZE[u.glslType];
17
+ if (size) {
18
+ const d = Array.isArray(u.default) ? u.default : [];
19
+ const controls = [];
20
+ for (let i = 0; i < size; i++) {
21
+ controls.push({
22
+ type: "number",
23
+ key: `${key}.${i}`,
24
+ label: `${label} ${i}`,
25
+ default: typeof d[i] === "number" ? d[i] : 0,
26
+ });
27
+ }
28
+ return { type: "group", key, label, controls };
29
+ }
30
+ return null; // sampler2D and unknown types
31
+ }
32
+ /** Build a {@link Panel} from a uniform list, skipping host-bound textures. */
33
+ export function uniformsToPanel(uniforms) {
34
+ const controls = [];
35
+ for (const u of uniforms) {
36
+ if (isHostBound(u))
37
+ continue;
38
+ const c = uniformToControl(u);
39
+ if (c)
40
+ controls.push(c);
41
+ }
42
+ return { controls };
43
+ }
package/package.json ADDED
@@ -0,0 +1,41 @@
1
+ {
2
+ "name": "@azphalt/importer-transition",
3
+ "version": "0.1.0",
4
+ "publishConfig": {
5
+ "access": "public"
6
+ },
7
+ "description": "Import GL Transitions (gl-transitions.com) into .azp transition assets.",
8
+ "license": "MIT",
9
+ "author": "Az (https://hereliesaz.com)",
10
+ "type": "module",
11
+ "main": "./dist/index.js",
12
+ "types": "./dist/index.d.ts",
13
+ "bin": {
14
+ "azphalt-import-transition": "./dist/cli.js"
15
+ },
16
+ "exports": {
17
+ ".": {
18
+ "types": "./dist/index.d.ts",
19
+ "default": "./dist/index.js"
20
+ }
21
+ },
22
+ "files": [
23
+ "dist"
24
+ ],
25
+ "dependencies": {
26
+ "@azphalt/azp": "0.1.0",
27
+ "@azphalt/sdk": "0.1.0"
28
+ },
29
+ "devDependencies": {
30
+ "typescript": "^5.6.0",
31
+ "vitest": "^3.2.6",
32
+ "@types/node": "^22.0.0"
33
+ },
34
+ "sideEffects": false,
35
+ "scripts": {
36
+ "build": "tsc -p tsconfig.json",
37
+ "test": "vitest run",
38
+ "typecheck": "tsc -p tsconfig.json --noEmit",
39
+ "clean": "rm -rf dist"
40
+ }
41
+ }
package/readme.md ADDED
@@ -0,0 +1,35 @@
1
+ # @azphalt/importer-transition
2
+
3
+ Normalize a **GL Transition** ([gl-transitions.com](https://gl-transitions.com)) into a `.azp`
4
+ transition asset. A gl-transition is a GLSL fragment defining `vec4 transition(vec2 uv)` with
5
+ metadata in `//` comments and tunable `uniform` parameters (`uniform float intensity; // = 1.0`).
6
+ The source is stored verbatim; its uniforms become an azphalt UI panel plus manifest params, so an
7
+ adopting host — e.g. [Guillotine](https://github.com/HereLiesAz/Guillotine), whose clip-to-clip
8
+ transitions this feeds — renders the controls natively and runs the transition with its own engine.
9
+
10
+ This completes Guillotine's format trio alongside `@azphalt/importer-cube` (LUTs) and
11
+ `@azphalt/importer-isf` (shaders).
12
+
13
+ ## uniforms → controls
14
+
15
+ | GLSL uniform | azphalt control |
16
+ |---|---|
17
+ | `float` / `int` | `number` |
18
+ | `bool` | `toggle` |
19
+ | `vec2..4` / `ivec2..4` | `group` of `number`s |
20
+ | `sampler2D`, and `from`/`to`/`progress`/`ratio` | *host-provided* — bound by the host, not user controls |
21
+
22
+ ## CLI
23
+
24
+ ~~~sh
25
+ pnpm --filter @azphalt/importer-transition build
26
+ azphalt-import-transition crosswarp.glsl --id com.hereliesaz.crosswarp -o crosswarp.azp
27
+ ~~~
28
+
29
+ ## Library
30
+
31
+ ~~~ts
32
+ import { importGlTransition, parseGlTransition } from "@azphalt/importer-transition";
33
+
34
+ const { azp, manifest, panel } = importGlTransition(glslSource, licenseText, { id: "com.hereliesaz.crosswarp" });
35
+ ~~~