@nova-lab/core 1.2.2-dev.259 → 1.2.2-dev.272

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 (30) hide show
  1. package/README.md +55 -0
  2. package/dist/2d/effects.js +165 -404
  3. package/dist/2d/lighting.d.ts +2 -0
  4. package/dist/2d/lighting.js +483 -227
  5. package/dist/2d/lottie.js +1 -1
  6. package/dist/2d/meshes.js +2 -2
  7. package/dist/2d/render-textures.js +3 -537
  8. package/dist/2d.js +3 -3
  9. package/dist/{NovaNode-CBZ-Ol-W.js → NovaNode-CshmSV9Y.js} +21 -21
  10. package/dist/{NovaRenderCommandWriter-CWQRa42y.js → NovaRenderCommandWriter-DeHyKjke.js} +272 -251
  11. package/dist/NovaRenderTexture-Desjl5-m.js +539 -0
  12. package/dist/{NovaTextSelectionService-7JqMcRrP.js → NovaTextSelectionService-CWJKn7TW.js} +3948 -3517
  13. package/dist/{NovaWebGLProgram-BO250QNF.js → NovaWebGLProgram-ytnblA5d.js} +28 -25
  14. package/dist/core.js +3 -3
  15. package/dist/model/lighting/LightingFields2D.d.ts +35 -0
  16. package/dist/model/lighting/LightingRenderer2D.d.ts +11 -18
  17. package/dist/model/lighting/LightingScene2D.d.ts +43 -0
  18. package/dist/model/lighting/NovaLighting2D.d.ts +18 -33
  19. package/dist/model/lighting/NovaLightingEffect2D.d.ts +46 -0
  20. package/dist/model/lighting/lighting-effect.d.ts +24 -0
  21. package/dist/model/lighting/lighting-shaders.d.ts +2 -2
  22. package/dist/model/lighting/lighting.types.d.ts +5 -1
  23. package/dist/model/render/backends/webgl/NovaWebGLCompositionPass.d.ts +2 -1
  24. package/dist/model/render/backends/webgl/NovaWebGLFrameRenderer.d.ts +26 -2
  25. package/dist/model/render/backends/webgl/NovaWebGLPathClipPass.d.ts +3 -2
  26. package/dist/model/render/backends/webgl/NovaWebGLProgram.d.ts +1 -1
  27. package/dist/model/render/graph/nova-render-dirty-items.d.ts +12 -0
  28. package/dist/model/runtime/cursor/NovaCursorManager.d.ts +7 -0
  29. package/dist/shader-effect-CHXZBHrO.js +247 -0
  30. package/package.json +2 -2
@@ -0,0 +1,247 @@
1
+ import { N as M } from "./NovaWebGLProgram-ytnblA5d.js";
2
+ import { i as I } from "./nova-render-texture-image-identity-DQ09XFKs.js";
3
+ import { o as $ } from "./NovaAssetRegistry-p2QlCwvT.js";
4
+ import { r as P } from "./nova-color-parser-BCN_rFRN.js";
5
+ const U = { float: 1, int: 1, vec2: 2, vec3: 3, vec4: 4, mat3: 9, mat4: 16 }, V = Object.freeze([]), G = `#version 300 es
6
+ precision highp float;
7
+ out vec2 novaUv;
8
+ void main() {
9
+ const vec2 p[3] = vec2[3](vec2(-1.0, -1.0), vec2(3.0, -1.0), vec2(-1.0, 3.0));
10
+ vec2 corner = p[gl_VertexID];
11
+ novaUv = (corner + 1.0) * 0.5;
12
+ gl_Position = vec4(corner, 0.0, 1.0);
13
+ }`;
14
+ function L(r, t, i) {
15
+ if (t === "sampler2D") {
16
+ if (!r || typeof r != "object" || r.__novaAssetRef !== !0)
17
+ throw new TypeError(`[Nova] Sampler "${i}" requires an image asset ref`);
18
+ const o = r, f = o.id, T = o.kind;
19
+ if (typeof f != "string" || f.length === 0 || !["image", "icon", "fill"].includes(T))
20
+ throw new TypeError(`[Nova] Sampler "${i}" requires an image asset ref`);
21
+ return I(o) ? o : Object.freeze({ __novaAssetRef: !0, namespace: o.namespace, kind: T, name: o.name, id: f });
22
+ }
23
+ const c = (o) => {
24
+ if (typeof o != "number" || !Number.isFinite(o) || (t === "int" ? !Number.isInteger(o) || o < -2147483648 || o > 2147483647 : !Number.isFinite(Math.fround(o))))
25
+ throw new RangeError(`[Nova] Invalid ${t} uniform "${i}"`);
26
+ return t === "int" ? o : Math.fround(o);
27
+ };
28
+ if (t === "float" || t === "int")
29
+ return c(r);
30
+ if (!r || typeof r != "object" || !("length" in r) || r.length !== U[t])
31
+ throw new RangeError(`[Nova] Uniform "${i}" requires ${U[t]} coefficients`);
32
+ return Object.freeze(Array.from({ length: U[t] }, (o, f) => c(r[f])));
33
+ }
34
+ function q(r, t) {
35
+ return $(r) || $(t) ? $(r) && $(t) && (I(r) || I(t) ? r === t : r.id === t.id && r.kind === t.kind) : typeof r == "number" ? Object.is(r, t) : typeof t != "number" && r.every((i, c) => Object.is(i, t[c]));
36
+ }
37
+ function A(r) {
38
+ if (!r || typeof r != "object" || Array.isArray(r) || ArrayBuffer.isView(r))
39
+ throw new TypeError("[Nova] Shader uniforms must be an object");
40
+ }
41
+ function z(r, t) {
42
+ return t.map(([i, c]) => {
43
+ const o = r[i];
44
+ return { name: i, type: c, value: typeof o == "number" ? o : new Float32Array(o) };
45
+ });
46
+ }
47
+ function W(r, t, i) {
48
+ switch (i.type) {
49
+ case "float":
50
+ r.uniform1f(t, i.value);
51
+ break;
52
+ case "int":
53
+ r.uniform1i(t, i.value);
54
+ break;
55
+ case "vec2":
56
+ r.uniform2fv(t, i.value);
57
+ break;
58
+ case "vec3":
59
+ r.uniform3fv(t, i.value);
60
+ break;
61
+ case "vec4":
62
+ r.uniform4fv(t, i.value);
63
+ break;
64
+ case "mat3":
65
+ r.uniformMatrix3fv(t, !1, i.value);
66
+ break;
67
+ case "mat4":
68
+ r.uniformMatrix4fv(t, !1, i.value);
69
+ break;
70
+ }
71
+ }
72
+ function K(r) {
73
+ if (typeof r.name != "string" || r.name.length === 0 || r.name.length > 128 || typeof r.fragment != "string" || r.fragment.trim().length === 0 || r.fragment.length > 65536)
74
+ throw new TypeError("[Nova] Shader effect requires a name and a GLSL fragment body (at most 65536 characters)");
75
+ const t = r.name, i = r.fragment, c = r.outset ?? 0, o = r.canvas;
76
+ if (!Number.isFinite(c) || c < 0 || c > 256)
77
+ throw new RangeError("[Nova] Shader effect outset must be from 0 to 256 CSS pixels");
78
+ if (o !== void 0 && typeof o != "function")
79
+ throw new TypeError("[Nova] Shader effect Canvas2D fallback must be a function");
80
+ A(r.uniforms);
81
+ const f = Object.entries(r.uniforms);
82
+ if (f.length > 64 || f.some(([e, a]) => !/^[A-Z_]\w*$/i.test(e) || e.startsWith("nova") || e.startsWith("gl_") || e.includes("__") || a !== "sampler2D" && !Object.hasOwn(U, a)))
83
+ throw new TypeError("[Nova] Shader effect supports at most 64 typed uniforms; nova/gl_ and double-underscore names are reserved");
84
+ const T = Object.freeze(Object.fromEntries(f)), j = f.filter((e) => e[1] !== "sampler2D"), u = f.filter(([, e]) => e === "sampler2D").map(([e]) => e);
85
+ if (u.some((e) => e.startsWith("_")))
86
+ throw new TypeError("[Nova] Sampler names must start with a letter to keep generated GLSL helper names unambiguous");
87
+ const x = (e) => u.length ? Object.freeze(u.map((a) => e[a])) : V, S = /* @__PURE__ */ new WeakMap(), D = `#version 300 es
88
+ precision highp float;
89
+ precision highp int;
90
+ in vec2 novaUv;
91
+ uniform sampler2D novaSource;
92
+ uniform vec2 novaResolution;
93
+ uniform float novaDpr;
94
+ ${f.map(([e, a]) => `uniform ${a} ${e};`).join(`
95
+ `)}
96
+ ${u.map((e) => `uniform vec4 novaImageUv_${e};
97
+ uniform vec4 novaImageClamp_${e};
98
+ uniform float novaImagePremultiplied_${e};
99
+ vec4 novaSample_${e}(vec2 uv) {
100
+ vec2 nativeUv = clamp(clamp(uv, 0.0, 1.0) * novaImageUv_${e}.xy + novaImageUv_${e}.zw, novaImageClamp_${e}.xy, novaImageClamp_${e}.zw);
101
+ vec4 color = texture(${e}, nativeUv);
102
+ return vec4(color.rgb * mix(color.a, 1.0, novaImagePremultiplied_${e}), color.a);
103
+ }`).join(`
104
+ `)}
105
+ out vec4 novaColor;
106
+ // Public UV has its origin at the top left; the FBO attachment has its origin below.
107
+ vec4 novaSample(vec2 uv) { return texture(novaSource, vec2(uv.x, 1.0 - uv.y)); }
108
+ ${i}
109
+ void main() { novaColor = novaEffect(vec2(novaUv.x, 1.0 - novaUv.y)); }`, C = {
110
+ images: u.length ? (e) => S.get(e).images : void 0,
111
+ outset: c > 0 ? () => c : void 0,
112
+ stageOutset: c > 0 ? () => ({ x: c, y: c }) : void 0,
113
+ subscribe(e, a) {
114
+ const n = S.get(e).listeners;
115
+ return n.add(a), () => {
116
+ n.delete(a);
117
+ };
118
+ },
119
+ canvas(e, a, n, s) {
120
+ if (!o)
121
+ throw new Error(`[Nova] Shader effect "${t}" requires an explicit Canvas2D fallback`);
122
+ const m = S.get(n).values;
123
+ let l;
124
+ if (u.length) {
125
+ const h = /* @__PURE__ */ Object.create(null);
126
+ for (const b of u) {
127
+ const p = s.resolveImage?.(m[b]);
128
+ if (p?.kind !== "canvas")
129
+ throw new Error(`[Nova] Shader sampler "${b}" changed or is unavailable; retry`);
130
+ h[b] = Object.freeze({ source: p.source, width: p.width, height: p.height });
131
+ }
132
+ l = Object.freeze({ width: s.width, height: s.height, dpr: s.dpr, samplers: Object.freeze(h) });
133
+ } else
134
+ l = Object.freeze({ width: s.width, height: s.height, dpr: s.dpr });
135
+ a.save();
136
+ try {
137
+ a.setTransform(1, 0, 0, 1, 0, 0), a.globalAlpha = 1, a.globalCompositeOperation = "source-over", a.clearRect(0, 0, e.width, e.height);
138
+ const h = o(e, a, m, l);
139
+ if (h && typeof h == "object" && "then" in h)
140
+ throw new TypeError("[Nova] Shader effect Canvas2D fallback must be synchronous");
141
+ } finally {
142
+ a.restore();
143
+ }
144
+ },
145
+ webgl(e) {
146
+ let a, n = null;
147
+ try {
148
+ if (u.length) {
149
+ const g = Number(e.getParameter(e.MAX_TEXTURE_IMAGE_UNITS));
150
+ if (!Number.isSafeInteger(g) || g < u.length + 1)
151
+ throw new RangeError(`[Nova] Shader effect "${t}" needs ${u.length + 1} fragment texture units`);
152
+ }
153
+ if (a = M.create(e, G, D), n = e.createVertexArray(), !n)
154
+ throw new Error("Failed to create vertex array");
155
+ const s = j.map(([g]) => e.getUniformLocation(a.program, g)), m = u.map((g) => ({
156
+ source: e.getUniformLocation(a.program, g),
157
+ uv: e.getUniformLocation(a.program, `novaImageUv_${g}`),
158
+ clamp: e.getUniformLocation(a.program, `novaImageClamp_${g}`),
159
+ premultiplied: e.getUniformLocation(a.program, `novaImagePremultiplied_${g}`)
160
+ })), l = e.getUniformLocation(a.program, "novaSource"), h = e.getUniformLocation(a.program, "novaResolution"), b = e.getUniformLocation(a.program, "novaDpr"), p = a, d = n;
161
+ let E;
162
+ return {
163
+ draw(g, k, _) {
164
+ const { values: R, prepared: X, images: F } = S.get(k), O = u.length ? F.map((v, N) => {
165
+ const w = _.resolveImage?.(v);
166
+ if (w?.kind !== "webgl")
167
+ throw new Error(`[Nova] Shader sampler "${u[N]}" changed or is unavailable; retry`);
168
+ return w;
169
+ }) : void 0;
170
+ if (p.use(), e.bindVertexArray(d), e.activeTexture(e.TEXTURE0), e.bindTexture(e.TEXTURE_2D, g), l !== null && e.uniform1i(l, 0), h !== null && e.uniform2f(h, _.width, _.height), b !== null && e.uniform1f(b, _.dpr), E !== R && (X.forEach((v, N) => {
171
+ const w = s[N];
172
+ w !== null && W(e, w, v);
173
+ }), E = R), !O) {
174
+ e.drawArrays(e.TRIANGLES, 0, 3);
175
+ return;
176
+ }
177
+ try {
178
+ O.forEach((v, N) => {
179
+ const w = N + 1, y = m[N];
180
+ e.activeTexture(e.TEXTURE0 + w), e.bindTexture(e.TEXTURE_2D, v.texture), e.bindSampler(w, v.sampler), y.source !== null && e.uniform1i(y.source, w), y.uv !== null && e.uniform4f(y.uv, ...v.uv), y.clamp !== null && e.uniform4f(y.clamp, ...v.clamp), y.premultiplied !== null && e.uniform1f(y.premultiplied, v.premultiplied ? 1 : 0);
181
+ }), e.drawArrays(e.TRIANGLES, 0, 3);
182
+ } finally {
183
+ for (let v = 1; v <= O.length; v++)
184
+ e.activeTexture(e.TEXTURE0 + v), e.bindSampler(v, null), e.bindTexture(e.TEXTURE_2D, null);
185
+ e.activeTexture(e.TEXTURE0);
186
+ }
187
+ },
188
+ destroy() {
189
+ e.deleteVertexArray(d), p.destroy(), E = void 0;
190
+ }
191
+ };
192
+ } catch (s) {
193
+ throw n && e.deleteVertexArray(n), a?.destroy(), new Error(`[Nova] Shader effect "${t}" failed: ${s instanceof Error ? s.message : String(s)}`, { cause: s });
194
+ }
195
+ }
196
+ };
197
+ return Object.freeze({
198
+ name: t,
199
+ uniforms: T,
200
+ fragment: i,
201
+ outset: c,
202
+ create(e) {
203
+ if (A(e), Object.keys(e).length !== f.length || f.some(([m]) => !Object.hasOwn(e, m)))
204
+ throw new TypeError("[Nova] Shader effect initial uniforms must match its layout");
205
+ const a = /* @__PURE__ */ Object.create(null);
206
+ for (const [m, l] of f)
207
+ a[m] = L(e[m], l, m);
208
+ const n = { values: Object.freeze(a), prepared: z(a, j), images: x(a), version: 0, listeners: /* @__PURE__ */ new Set() }, s = P({
209
+ kind: "shader",
210
+ get uniforms() {
211
+ return n.values;
212
+ },
213
+ get version() {
214
+ return n.version;
215
+ },
216
+ setUniforms(m) {
217
+ A(m);
218
+ const l = { ...n.values };
219
+ let h = !1;
220
+ for (const d of Object.keys(m)) {
221
+ if (!Object.hasOwn(T, d))
222
+ throw new TypeError(`[Nova] Unknown shader uniform "${d}"`);
223
+ const E = L(m[d], T[d], d);
224
+ q(n.values[d], E) || (l[d] = E, h = !0);
225
+ }
226
+ if (!h)
227
+ return;
228
+ const b = z(l, j);
229
+ n.values = Object.freeze(l), n.prepared = b, n.images = x(l), n.version = n.version === Number.MAX_SAFE_INTEGER ? 0 : n.version + 1;
230
+ const p = [];
231
+ for (const d of [...n.listeners])
232
+ try {
233
+ d();
234
+ } catch (E) {
235
+ p.push(E);
236
+ }
237
+ if (p.length)
238
+ throw new AggregateError(p, "[Nova] Shader effect replay notification failed");
239
+ }
240
+ }, C);
241
+ return S.set(s, n), s;
242
+ }
243
+ });
244
+ }
245
+ export {
246
+ K as d
247
+ };
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@nova-lab/core",
3
3
  "type": "module",
4
- "version": "1.2.2-dev.259",
4
+ "version": "1.2.2-dev.272",
5
5
  "private": false,
6
6
  "license": "Apache-2.0",
7
7
  "repository": {
@@ -215,7 +215,7 @@
215
215
  "example:courier": "vite --config examples/courier/vite.config.ts",
216
216
  "example:fps": "vite --config examples/fps/vite.config.ts",
217
217
  "example:rpg": "vite --config examples/rpg/vite.config.ts",
218
- "lint:release": "eslint src/model/render/backends/webgl/NovaWebGLFrameRenderer.ts",
218
+ "lint:release": "eslint src build-tools vite.config.ts package.json eslint.config.mjs eslint.endge.config.mjs",
219
219
  "test:release": "node node_modules/vitest/vitest.mjs run --maxWorkers=1 --exclude \"**/benchmarks/**\" --exclude \"**/*.bench.*\" --exclude \"**/*.performance.*\" --exclude \"**/performance/**\" --config vite.config.ts"
220
220
  },
221
221
  "peerDependencies": {