@thi.ng/shader-ast-js 1.1.34 → 1.1.36
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/CHANGELOG.md +7 -1
- package/README.md +2 -2
- package/package.json +15 -15
- package/pool.js +1 -2
- package/runtime.js +3 -3
- package/target.js +14 -12
package/CHANGELOG.md
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
# Change Log
|
|
2
2
|
|
|
3
|
-
- **Last updated**: 2024-
|
|
3
|
+
- **Last updated**: 2024-06-21T19:34:38Z
|
|
4
4
|
- **Generator**: [thi.ng/monopub](https://thi.ng/monopub)
|
|
5
5
|
|
|
6
6
|
All notable changes to this project will be documented in this file.
|
|
@@ -9,6 +9,12 @@ See [Conventional Commits](https://conventionalcommits.org/) for commit guidelin
|
|
|
9
9
|
**Note:** Unlisted _patch_ versions only involve non-code or otherwise excluded changes
|
|
10
10
|
and/or version bumps of transitive dependencies.
|
|
11
11
|
|
|
12
|
+
### [1.1.36](https://github.com/thi-ng/umbrella/tree/@thi.ng/shader-ast-js@1.1.36) (2024-06-21)
|
|
13
|
+
|
|
14
|
+
#### ♻️ Refactoring
|
|
15
|
+
|
|
16
|
+
- enforce uniform naming convention of internal functions ([56992b2](https://github.com/thi-ng/umbrella/commit/56992b2))
|
|
17
|
+
|
|
12
18
|
## [1.1.0](https://github.com/thi-ng/umbrella/tree/@thi.ng/shader-ast-js@1.1.0) (2023-12-31)
|
|
13
19
|
|
|
14
20
|
#### 🚀 Features
|
package/README.md
CHANGED
|
@@ -7,7 +7,7 @@
|
|
|
7
7
|
[](https://mastodon.thi.ng/@toxi)
|
|
8
8
|
|
|
9
9
|
> [!NOTE]
|
|
10
|
-
> This is one of
|
|
10
|
+
> This is one of 193 standalone projects, maintained as part
|
|
11
11
|
> of the [@thi.ng/umbrella](https://github.com/thi-ng/umbrella/) monorepo
|
|
12
12
|
> and anti-framework.
|
|
13
13
|
>
|
|
@@ -87,7 +87,7 @@ For Node.js REPL:
|
|
|
87
87
|
const js = await import("@thi.ng/shader-ast-js");
|
|
88
88
|
```
|
|
89
89
|
|
|
90
|
-
Package sizes (brotli'd, pre-treeshake): ESM: 6.
|
|
90
|
+
Package sizes (brotli'd, pre-treeshake): ESM: 6.56 KB
|
|
91
91
|
|
|
92
92
|
## Dependencies
|
|
93
93
|
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@thi.ng/shader-ast-js",
|
|
3
|
-
"version": "1.1.
|
|
3
|
+
"version": "1.1.36",
|
|
4
4
|
"description": "Customizable JS codegen, compiler & runtime for @thi.ng/shader-ast",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"module": "./index.js",
|
|
@@ -10,7 +10,7 @@
|
|
|
10
10
|
"type": "git",
|
|
11
11
|
"url": "https://github.com/thi-ng/umbrella.git"
|
|
12
12
|
},
|
|
13
|
-
"homepage": "https://
|
|
13
|
+
"homepage": "https://thi.ng/shader-ast-js",
|
|
14
14
|
"funding": [
|
|
15
15
|
{
|
|
16
16
|
"type": "github",
|
|
@@ -36,20 +36,20 @@
|
|
|
36
36
|
"tool:tangle": "../../node_modules/.bin/tangle src/**/*.ts"
|
|
37
37
|
},
|
|
38
38
|
"dependencies": {
|
|
39
|
-
"@thi.ng/api": "^8.11.
|
|
40
|
-
"@thi.ng/checks": "^3.6.
|
|
41
|
-
"@thi.ng/errors": "^2.5.
|
|
42
|
-
"@thi.ng/math": "^5.
|
|
43
|
-
"@thi.ng/matrices": "^2.
|
|
44
|
-
"@thi.ng/pixel": "^6.1.
|
|
45
|
-
"@thi.ng/shader-ast": "^0.15.
|
|
46
|
-
"@thi.ng/vectors": "^7.
|
|
39
|
+
"@thi.ng/api": "^8.11.3",
|
|
40
|
+
"@thi.ng/checks": "^3.6.5",
|
|
41
|
+
"@thi.ng/errors": "^2.5.8",
|
|
42
|
+
"@thi.ng/math": "^5.11.0",
|
|
43
|
+
"@thi.ng/matrices": "^2.4.0",
|
|
44
|
+
"@thi.ng/pixel": "^6.1.33",
|
|
45
|
+
"@thi.ng/shader-ast": "^0.15.16",
|
|
46
|
+
"@thi.ng/vectors": "^7.11.0"
|
|
47
47
|
},
|
|
48
48
|
"devDependencies": {
|
|
49
|
-
"@microsoft/api-extractor": "^7.
|
|
50
|
-
"esbuild": "^0.
|
|
51
|
-
"typedoc": "^0.25.
|
|
52
|
-
"typescript": "^5.
|
|
49
|
+
"@microsoft/api-extractor": "^7.47.0",
|
|
50
|
+
"esbuild": "^0.21.5",
|
|
51
|
+
"typedoc": "^0.25.13",
|
|
52
|
+
"typescript": "^5.5.2"
|
|
53
53
|
},
|
|
54
54
|
"keywords": [
|
|
55
55
|
"2d",
|
|
@@ -163,5 +163,5 @@
|
|
|
163
163
|
],
|
|
164
164
|
"year": 2019
|
|
165
165
|
},
|
|
166
|
-
"gitHead": "
|
|
166
|
+
"gitHead": "154c95cf9d6bab32174498ec3b5b5d87e42be7f9\n"
|
|
167
167
|
}
|
package/pool.js
CHANGED
|
@@ -15,8 +15,7 @@ class Pool {
|
|
|
15
15
|
this.items[i] = this.mem.subarray(i * size, i * size + size);
|
|
16
16
|
}
|
|
17
17
|
const next = () => {
|
|
18
|
-
if (this.index > this.items.length)
|
|
19
|
-
outOfBounds(this.index);
|
|
18
|
+
if (this.index > this.items.length) outOfBounds(this.index);
|
|
20
19
|
return this.items[this.index++];
|
|
21
20
|
};
|
|
22
21
|
let from;
|
package/runtime.js
CHANGED
|
@@ -2,15 +2,15 @@ import { clamp, clamp01 } from "@thi.ng/math/interval";
|
|
|
2
2
|
import { intBufferFromCanvas } from "@thi.ng/pixel/int";
|
|
3
3
|
const rgbaBgra8888 = (rgba) => clamp01(rgba[0]) * 255.5 << 0 | clamp01(rgba[1]) * 255.5 << 8 | clamp01(rgba[2]) * 255.5 << 16 | clamp01(rgba[3]) * 255.5 << 24;
|
|
4
4
|
const rgbaRgb565 = (rgba) => (clamp01(rgba[0]) * 255.5 & 248) << 8 | (clamp01(rgba[1]) * 255.5 & 252) << 3 | (clamp01(rgba[2]) * 255.5 & 248) >> 3;
|
|
5
|
-
const
|
|
5
|
+
const __clampCoord = (x, maxW, w) => w !== void 0 ? Math.min(x + w, maxW) : maxW;
|
|
6
6
|
const renderPixels = (fn, pixels, { x, y, w, h, bufW, bufH, offsetX, offsetY, imgH, fmt }) => {
|
|
7
7
|
offsetX = offsetX || 0;
|
|
8
8
|
offsetY = offsetY || 0;
|
|
9
9
|
imgH = (imgH || bufH) - 1 - offsetY;
|
|
10
10
|
x = clamp(x || 0, 0, bufW);
|
|
11
11
|
y = clamp(y || 0, 0, bufH);
|
|
12
|
-
const x2 =
|
|
13
|
-
const y2 =
|
|
12
|
+
const x2 = __clampCoord(x, bufW, w);
|
|
13
|
+
const y2 = __clampCoord(y, bufH, h);
|
|
14
14
|
const fragCoord = [];
|
|
15
15
|
for (let yy = y; yy < y2; yy++) {
|
|
16
16
|
fragCoord[1] = imgH - yy;
|
package/target.js
CHANGED
|
@@ -71,13 +71,13 @@ const POOL_PRELUDE = VEC_TYPES.map(
|
|
|
71
71
|
const COMPS = { x: 0, y: 1, z: 2, w: 3 };
|
|
72
72
|
const RE_SEMI = /[};]$/;
|
|
73
73
|
const RESET = `for(let t in env.pools) env.pools[t].reset();`;
|
|
74
|
-
const
|
|
75
|
-
const
|
|
76
|
-
const
|
|
77
|
-
const
|
|
74
|
+
const __isIntOrBool = (l) => isInt(l) || isUint(l) || isBool(l);
|
|
75
|
+
const __isVecOrMat = (l) => isVec(l) || isMat(l);
|
|
76
|
+
const __swizzle = (id) => [...id].map((x) => COMPS[x]).join(", ");
|
|
77
|
+
const __buildComments = (t) => `/**
|
|
78
78
|
${t.args.map((p) => ` * @param ${p.id} ${p.type}`).join("\n")}
|
|
79
79
|
*/`;
|
|
80
|
-
const
|
|
80
|
+
const __buildExports = (tree) => tree.tag === "scope" ? tree.body.filter((x) => x.tag === "fn").map((f) => `${f.id}: ${f.id}`).join(",\n") : tree.tag === "fn" ? `${tree.id}: ${tree.id}` : "";
|
|
81
81
|
const targetJS = (opts) => {
|
|
82
82
|
opts = { ...opts };
|
|
83
83
|
const ff = opts.prec !== void 0 ? (x) => x === (x | 0) ? x : x.toFixed(opts.prec) : String;
|
|
@@ -94,7 +94,7 @@ const targetJS = (opts) => {
|
|
|
94
94
|
const rhs = emit(t.r);
|
|
95
95
|
if (t.l.tag === "swizzle") {
|
|
96
96
|
const s = t.l;
|
|
97
|
-
const id =
|
|
97
|
+
const id = __swizzle(s.id);
|
|
98
98
|
const val = emit(s.val);
|
|
99
99
|
return s.id.length > 1 ? `env.set_swizzle${s.id.length}(${val}, ${rhs}, ${id})` : `(${val}[${id}] = ${rhs})`;
|
|
100
100
|
}
|
|
@@ -121,7 +121,7 @@ ${emit({
|
|
|
121
121
|
} else {
|
|
122
122
|
body = emit(t.scope);
|
|
123
123
|
}
|
|
124
|
-
return `${
|
|
124
|
+
return `${__buildComments(t)}
|
|
125
125
|
function ${t.id}(${$list(
|
|
126
126
|
t.args
|
|
127
127
|
)}) ${body}`;
|
|
@@ -169,15 +169,15 @@ function ${t.id}(${$list(
|
|
|
169
169
|
}
|
|
170
170
|
},
|
|
171
171
|
op1: (t) => {
|
|
172
|
-
const complex =
|
|
172
|
+
const complex = __isVecOrMat(t) || isInt(t);
|
|
173
173
|
const op = t.op;
|
|
174
174
|
const val = emit(t.val);
|
|
175
175
|
return complex && t.post ? `${t.val.id} = ${t.type}.${OP_IDS[op]}(${val})` : complex ? `${t.type}.${OP_IDS[op]}1(${val})` : t.post ? `(${val}${op})` : `${op}${val}`;
|
|
176
176
|
},
|
|
177
177
|
op2: (t) => {
|
|
178
178
|
const { l, r } = t;
|
|
179
|
-
const vec =
|
|
180
|
-
const int = !vec ?
|
|
179
|
+
const vec = __isVecOrMat(l) ? l.type : __isVecOrMat(r) ? r.type : void 0;
|
|
180
|
+
const int = !vec ? __isIntOrBool(l) ? l.type : __isIntOrBool(r) ? r.type : void 0 : void 0;
|
|
181
181
|
const el = emit(l);
|
|
182
182
|
const er = emit(r);
|
|
183
183
|
return vec || int && !CMP_OPS[t.op] ? `${vec || int}.${OP_IDS[t.op]}${t.info || ""}(${el}, ${er})` : `(${el} ${t.op} ${er})`;
|
|
@@ -190,14 +190,16 @@ function ${t.id}(${$list(
|
|
|
190
190
|
${res}
|
|
191
191
|
}`;
|
|
192
192
|
},
|
|
193
|
-
swizzle: (t) => t.id.length > 1 ? `env.swizzle${t.id.length}(${emit(t.val)}, ${
|
|
193
|
+
swizzle: (t) => t.id.length > 1 ? `env.swizzle${t.id.length}(${emit(t.val)}, ${__swizzle(
|
|
194
|
+
t.id
|
|
195
|
+
)})` : `${emit(t.val)}[${__swizzle(t.id)}]`,
|
|
194
196
|
sym: (t) => t.id,
|
|
195
197
|
ternary: (t) => `(${emit(t.test)} ? ${emit(t.t)} : ${emit(t.f)})`,
|
|
196
198
|
while: (t) => `while (${emit(t.test)}) ${emit(t.scope)}`
|
|
197
199
|
});
|
|
198
200
|
Object.assign(emit, {
|
|
199
201
|
compile: (tree, env = JS_DEFAULT_ENV) => {
|
|
200
|
-
const exports =
|
|
202
|
+
const exports = __buildExports(tree);
|
|
201
203
|
return new Function(
|
|
202
204
|
"env",
|
|
203
205
|
[
|