@nexart/ui-renderer 0.1.0 → 0.2.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.
- package/README.md +204 -95
- package/dist/capabilities.d.ts +54 -0
- package/dist/capabilities.d.ts.map +1 -0
- package/dist/capabilities.js +338 -0
- package/dist/compiler.d.ts +34 -0
- package/dist/compiler.d.ts.map +1 -0
- package/dist/compiler.js +80 -0
- package/dist/index.d.ts +21 -6
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +19 -5
- package/dist/preview/primitives/dots.d.ts +6 -0
- package/dist/preview/primitives/dots.d.ts.map +1 -0
- package/dist/preview/primitives/dots.js +53 -0
- package/dist/preview/primitives/flow.d.ts +6 -0
- package/dist/preview/primitives/flow.d.ts.map +1 -0
- package/dist/preview/primitives/flow.js +32 -0
- package/dist/preview/primitives/grid.d.ts +6 -0
- package/dist/preview/primitives/grid.d.ts.map +1 -0
- package/dist/preview/primitives/grid.js +38 -0
- package/dist/preview/primitives/lines.d.ts +6 -0
- package/dist/preview/primitives/lines.d.ts.map +1 -0
- package/dist/preview/primitives/lines.js +47 -0
- package/dist/preview/primitives/orbits.d.ts +6 -0
- package/dist/preview/primitives/orbits.d.ts.map +1 -0
- package/dist/preview/primitives/orbits.js +27 -0
- package/dist/preview/primitives/waves.d.ts +6 -0
- package/dist/preview/primitives/waves.d.ts.map +1 -0
- package/dist/preview/primitives/waves.js +44 -0
- package/dist/preview/renderer.d.ts +17 -0
- package/dist/preview/renderer.d.ts.map +1 -0
- package/dist/preview/renderer.js +167 -0
- package/dist/system.d.ts +9 -0
- package/dist/system.d.ts.map +1 -0
- package/dist/system.js +165 -0
- package/dist/types.d.ts +99 -0
- package/dist/types.d.ts.map +1 -0
- package/dist/types.js +7 -0
- package/package.json +16 -7
- package/dist/renderer.d.ts +0 -31
- package/dist/renderer.d.ts.map +0 -1
- package/dist/renderer.js +0 -210
package/package.json
CHANGED
|
@@ -1,11 +1,18 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@nexart/ui-renderer",
|
|
3
|
-
"version": "0.1
|
|
4
|
-
"description": "
|
|
3
|
+
"version": "0.2.1",
|
|
4
|
+
"description": "Declarative system authoring SDK for NexArt Protocol (non-canonical, preview only)",
|
|
5
5
|
"license": "MIT",
|
|
6
|
-
"main": "dist/index.js",
|
|
7
|
-
"types": "dist/index.d.ts",
|
|
8
6
|
"type": "module",
|
|
7
|
+
"main": "./dist/index.js",
|
|
8
|
+
"module": "./dist/index.js",
|
|
9
|
+
"types": "./dist/index.d.ts",
|
|
10
|
+
"exports": {
|
|
11
|
+
".": {
|
|
12
|
+
"import": "./dist/index.js",
|
|
13
|
+
"types": "./dist/index.d.ts"
|
|
14
|
+
}
|
|
15
|
+
},
|
|
9
16
|
"files": [
|
|
10
17
|
"dist"
|
|
11
18
|
],
|
|
@@ -17,12 +24,14 @@
|
|
|
17
24
|
"typescript": "^5.0.0"
|
|
18
25
|
},
|
|
19
26
|
"keywords": [
|
|
27
|
+
"nexart",
|
|
20
28
|
"generative-art",
|
|
21
29
|
"canvas",
|
|
22
30
|
"browser",
|
|
23
|
-
"
|
|
24
|
-
"
|
|
25
|
-
"
|
|
31
|
+
"declarative",
|
|
32
|
+
"protocol",
|
|
33
|
+
"authoring",
|
|
34
|
+
"preview"
|
|
26
35
|
],
|
|
27
36
|
"repository": {
|
|
28
37
|
"type": "git",
|
package/dist/renderer.d.ts
DELETED
|
@@ -1,31 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* @nexart/ui-renderer - Core Renderer
|
|
3
|
-
* Version: 0.1.0
|
|
4
|
-
*
|
|
5
|
-
* Browser-first generative art renderer.
|
|
6
|
-
* Uses deterministic PRNG for reproducible (but non-canonical) output.
|
|
7
|
-
*/
|
|
8
|
-
export interface UIRendererOptions {
|
|
9
|
-
canvas: HTMLCanvasElement;
|
|
10
|
-
seed: number;
|
|
11
|
-
mode: 'static' | 'loop';
|
|
12
|
-
width?: number;
|
|
13
|
-
height?: number;
|
|
14
|
-
}
|
|
15
|
-
export interface UIRenderer {
|
|
16
|
-
render: () => void;
|
|
17
|
-
start: () => void;
|
|
18
|
-
stop: () => void;
|
|
19
|
-
setSeed: (newSeed: number) => void;
|
|
20
|
-
destroy: () => void;
|
|
21
|
-
isCanonical: false;
|
|
22
|
-
isArchival: false;
|
|
23
|
-
}
|
|
24
|
-
/**
|
|
25
|
-
* Create a UI renderer instance.
|
|
26
|
-
*
|
|
27
|
-
* ⚠️ This renderer is NOT canonical and NOT archival.
|
|
28
|
-
* For production NFT minting, use @nexart/codemode-sdk.
|
|
29
|
-
*/
|
|
30
|
-
export declare function createUIRenderer(options: UIRendererOptions): UIRenderer;
|
|
31
|
-
//# sourceMappingURL=renderer.d.ts.map
|
package/dist/renderer.d.ts.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"renderer.d.ts","sourceRoot":"","sources":["../src/renderer.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAEH,MAAM,WAAW,iBAAiB;IAChC,MAAM,EAAE,iBAAiB,CAAC;IAC1B,IAAI,EAAE,MAAM,CAAC;IACb,IAAI,EAAE,QAAQ,GAAG,MAAM,CAAC;IACxB,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,MAAM,CAAC,EAAE,MAAM,CAAC;CACjB;AAED,MAAM,WAAW,UAAU;IACzB,MAAM,EAAE,MAAM,IAAI,CAAC;IACnB,KAAK,EAAE,MAAM,IAAI,CAAC;IAClB,IAAI,EAAE,MAAM,IAAI,CAAC;IACjB,OAAO,EAAE,CAAC,OAAO,EAAE,MAAM,KAAK,IAAI,CAAC;IACnC,OAAO,EAAE,MAAM,IAAI,CAAC;IACpB,WAAW,EAAE,KAAK,CAAC;IACnB,UAAU,EAAE,KAAK,CAAC;CACnB;AAiBD;;;;;GAKG;AACH,wBAAgB,gBAAgB,CAAC,OAAO,EAAE,iBAAiB,GAAG,UAAU,CAgOvE"}
|
package/dist/renderer.js
DELETED
|
@@ -1,210 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* @nexart/ui-renderer - Core Renderer
|
|
3
|
-
* Version: 0.1.0
|
|
4
|
-
*
|
|
5
|
-
* Browser-first generative art renderer.
|
|
6
|
-
* Uses deterministic PRNG for reproducible (but non-canonical) output.
|
|
7
|
-
*/
|
|
8
|
-
/**
|
|
9
|
-
* Deterministic PRNG (Mulberry32)
|
|
10
|
-
* Fast, simple, good distribution
|
|
11
|
-
*/
|
|
12
|
-
function createPRNG(seed) {
|
|
13
|
-
let state = seed;
|
|
14
|
-
return () => {
|
|
15
|
-
state |= 0;
|
|
16
|
-
state = (state + 0x6d2b79f5) | 0;
|
|
17
|
-
let t = Math.imul(state ^ (state >>> 15), 1 | state);
|
|
18
|
-
t = (t + Math.imul(t ^ (t >>> 7), 61 | t)) ^ t;
|
|
19
|
-
return ((t ^ (t >>> 14)) >>> 0) / 4294967296;
|
|
20
|
-
};
|
|
21
|
-
}
|
|
22
|
-
/**
|
|
23
|
-
* Create a UI renderer instance.
|
|
24
|
-
*
|
|
25
|
-
* ⚠️ This renderer is NOT canonical and NOT archival.
|
|
26
|
-
* For production NFT minting, use @nexart/codemode-sdk.
|
|
27
|
-
*/
|
|
28
|
-
export function createUIRenderer(options) {
|
|
29
|
-
const { canvas, mode } = options;
|
|
30
|
-
let { seed } = options;
|
|
31
|
-
const width = options.width ?? canvas.width ?? 800;
|
|
32
|
-
const height = options.height ?? canvas.height ?? 800;
|
|
33
|
-
canvas.width = width;
|
|
34
|
-
canvas.height = height;
|
|
35
|
-
const ctx = canvas.getContext('2d');
|
|
36
|
-
let animationId = null;
|
|
37
|
-
let frameCount = 0;
|
|
38
|
-
let random;
|
|
39
|
-
// Initialize PRNG
|
|
40
|
-
const initRandom = () => {
|
|
41
|
-
random = createPRNG(seed);
|
|
42
|
-
frameCount = 0;
|
|
43
|
-
};
|
|
44
|
-
initRandom();
|
|
45
|
-
// Utility functions
|
|
46
|
-
const map = (value, start1, stop1, start2, stop2) => {
|
|
47
|
-
return start2 + (stop2 - start2) * ((value - start1) / (stop1 - start1));
|
|
48
|
-
};
|
|
49
|
-
const lerp = (a, b, t) => a + (b - a) * t;
|
|
50
|
-
const noise2D = (x, y) => {
|
|
51
|
-
// Simple value noise using PRNG
|
|
52
|
-
const xi = Math.floor(x);
|
|
53
|
-
const yi = Math.floor(y);
|
|
54
|
-
const xf = x - xi;
|
|
55
|
-
const yf = y - yi;
|
|
56
|
-
const hash = (px, py) => {
|
|
57
|
-
const n = Math.sin(px * 12.9898 + py * 78.233 + seed * 0.001) * 43758.5453;
|
|
58
|
-
return n - Math.floor(n);
|
|
59
|
-
};
|
|
60
|
-
const v00 = hash(xi, yi);
|
|
61
|
-
const v10 = hash(xi + 1, yi);
|
|
62
|
-
const v01 = hash(xi, yi + 1);
|
|
63
|
-
const v11 = hash(xi + 1, yi + 1);
|
|
64
|
-
const sx = xf * xf * (3 - 2 * xf);
|
|
65
|
-
const sy = yf * yf * (3 - 2 * yf);
|
|
66
|
-
return lerp(lerp(v00, v10, sx), lerp(v01, v11, sx), sy);
|
|
67
|
-
};
|
|
68
|
-
/**
|
|
69
|
-
* Render a single frame
|
|
70
|
-
* Style: Abstract flow field / vortex art
|
|
71
|
-
*/
|
|
72
|
-
const renderFrame = (t = 0) => {
|
|
73
|
-
// Clear with dark background
|
|
74
|
-
ctx.fillStyle = `hsl(${(seed % 360)}, 15%, 8%)`;
|
|
75
|
-
ctx.fillRect(0, 0, width, height);
|
|
76
|
-
// Re-seed for deterministic frame
|
|
77
|
-
random = createPRNG(seed + frameCount);
|
|
78
|
-
// Draw flow field particles
|
|
79
|
-
const particleCount = 2000;
|
|
80
|
-
const scale = 0.003;
|
|
81
|
-
for (let i = 0; i < particleCount; i++) {
|
|
82
|
-
// Particle position based on PRNG
|
|
83
|
-
let x = random() * width;
|
|
84
|
-
let y = random() * height;
|
|
85
|
-
// Particle color from seed
|
|
86
|
-
const hue = (seed + i * 0.1 + t * 50) % 360;
|
|
87
|
-
const sat = 60 + random() * 30;
|
|
88
|
-
const light = 50 + random() * 30;
|
|
89
|
-
const alpha = 0.3 + random() * 0.4;
|
|
90
|
-
ctx.strokeStyle = `hsla(${hue}, ${sat}%, ${light}%, ${alpha})`;
|
|
91
|
-
ctx.lineWidth = 0.5 + random() * 1.5;
|
|
92
|
-
ctx.beginPath();
|
|
93
|
-
ctx.moveTo(x, y);
|
|
94
|
-
// Trace flow line
|
|
95
|
-
const steps = 20 + Math.floor(random() * 30);
|
|
96
|
-
for (let s = 0; s < steps; s++) {
|
|
97
|
-
// Flow field angle using noise
|
|
98
|
-
const noiseVal = noise2D(x * scale, y * scale + t * 0.5);
|
|
99
|
-
const angle = noiseVal * Math.PI * 4;
|
|
100
|
-
// Add vortex influence
|
|
101
|
-
const cx = width / 2;
|
|
102
|
-
const cy = height / 2;
|
|
103
|
-
const dx = x - cx;
|
|
104
|
-
const dy = y - cy;
|
|
105
|
-
const dist = Math.sqrt(dx * dx + dy * dy);
|
|
106
|
-
const vortexStrength = map(dist, 0, width / 2, 0.8, 0.2);
|
|
107
|
-
const vortexAngle = Math.atan2(dy, dx) + Math.PI / 2;
|
|
108
|
-
const finalAngle = lerp(angle, vortexAngle, vortexStrength);
|
|
109
|
-
x += Math.cos(finalAngle) * 3;
|
|
110
|
-
y += Math.sin(finalAngle) * 3;
|
|
111
|
-
ctx.lineTo(x, y);
|
|
112
|
-
// Stop if out of bounds
|
|
113
|
-
if (x < 0 || x > width || y < 0 || y > height)
|
|
114
|
-
break;
|
|
115
|
-
}
|
|
116
|
-
ctx.stroke();
|
|
117
|
-
}
|
|
118
|
-
// Draw orbital elements
|
|
119
|
-
const orbits = 3 + Math.floor(random() * 4);
|
|
120
|
-
for (let o = 0; o < orbits; o++) {
|
|
121
|
-
const orbitRadius = 100 + random() * (Math.min(width, height) / 3);
|
|
122
|
-
const orbitSpeed = 0.5 + random() * 1.5;
|
|
123
|
-
const dotCount = 20 + Math.floor(random() * 40);
|
|
124
|
-
const orbitHue = (seed + o * 60 + t * 30) % 360;
|
|
125
|
-
for (let d = 0; d < dotCount; d++) {
|
|
126
|
-
const angle = (d / dotCount) * Math.PI * 2 + t * orbitSpeed + o;
|
|
127
|
-
const wobble = Math.sin(angle * 3 + t * 2) * 20;
|
|
128
|
-
const x = width / 2 + Math.cos(angle) * (orbitRadius + wobble);
|
|
129
|
-
const y = height / 2 + Math.sin(angle) * (orbitRadius + wobble);
|
|
130
|
-
const size = 2 + random() * 4;
|
|
131
|
-
const alpha = 0.4 + random() * 0.4;
|
|
132
|
-
ctx.beginPath();
|
|
133
|
-
ctx.arc(x, y, size, 0, Math.PI * 2);
|
|
134
|
-
ctx.fillStyle = `hsla(${orbitHue}, 70%, 60%, ${alpha})`;
|
|
135
|
-
ctx.fill();
|
|
136
|
-
}
|
|
137
|
-
}
|
|
138
|
-
// Central glow
|
|
139
|
-
const gradient = ctx.createRadialGradient(width / 2, height / 2, 0, width / 2, height / 2, width / 3);
|
|
140
|
-
const glowHue = (seed + t * 20) % 360;
|
|
141
|
-
gradient.addColorStop(0, `hsla(${glowHue}, 80%, 60%, 0.15)`);
|
|
142
|
-
gradient.addColorStop(0.5, `hsla(${glowHue}, 60%, 40%, 0.05)`);
|
|
143
|
-
gradient.addColorStop(1, 'transparent');
|
|
144
|
-
ctx.fillStyle = gradient;
|
|
145
|
-
ctx.fillRect(0, 0, width, height);
|
|
146
|
-
frameCount++;
|
|
147
|
-
};
|
|
148
|
-
/**
|
|
149
|
-
* Render static image
|
|
150
|
-
*/
|
|
151
|
-
const render = () => {
|
|
152
|
-
initRandom();
|
|
153
|
-
renderFrame(0);
|
|
154
|
-
};
|
|
155
|
-
/**
|
|
156
|
-
* Start animation loop
|
|
157
|
-
*/
|
|
158
|
-
const start = () => {
|
|
159
|
-
if (mode !== 'loop') {
|
|
160
|
-
console.warn('start() called but mode is "static". Use render() instead.');
|
|
161
|
-
render();
|
|
162
|
-
return;
|
|
163
|
-
}
|
|
164
|
-
stop();
|
|
165
|
-
initRandom();
|
|
166
|
-
let startTime = performance.now();
|
|
167
|
-
const loop = () => {
|
|
168
|
-
const elapsed = (performance.now() - startTime) / 1000;
|
|
169
|
-
const t = (elapsed % 10) / 10; // 10 second loop
|
|
170
|
-
renderFrame(t);
|
|
171
|
-
animationId = requestAnimationFrame(loop);
|
|
172
|
-
};
|
|
173
|
-
animationId = requestAnimationFrame(loop);
|
|
174
|
-
};
|
|
175
|
-
/**
|
|
176
|
-
* Stop animation loop
|
|
177
|
-
*/
|
|
178
|
-
const stop = () => {
|
|
179
|
-
if (animationId !== null) {
|
|
180
|
-
cancelAnimationFrame(animationId);
|
|
181
|
-
animationId = null;
|
|
182
|
-
}
|
|
183
|
-
};
|
|
184
|
-
/**
|
|
185
|
-
* Set new seed and re-render
|
|
186
|
-
*/
|
|
187
|
-
const setSeed = (newSeed) => {
|
|
188
|
-
seed = newSeed;
|
|
189
|
-
initRandom();
|
|
190
|
-
if (mode === 'static' || animationId === null) {
|
|
191
|
-
render();
|
|
192
|
-
}
|
|
193
|
-
};
|
|
194
|
-
/**
|
|
195
|
-
* Clean up resources
|
|
196
|
-
*/
|
|
197
|
-
const destroy = () => {
|
|
198
|
-
stop();
|
|
199
|
-
ctx.clearRect(0, 0, width, height);
|
|
200
|
-
};
|
|
201
|
-
return {
|
|
202
|
-
render,
|
|
203
|
-
start,
|
|
204
|
-
stop,
|
|
205
|
-
setSeed,
|
|
206
|
-
destroy,
|
|
207
|
-
isCanonical: false,
|
|
208
|
-
isArchival: false,
|
|
209
|
-
};
|
|
210
|
-
}
|