@nexart/ui-renderer 0.7.0 → 0.8.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/README.md +132 -323
- package/dist/capabilities.d.ts +5 -7
- package/dist/capabilities.d.ts.map +1 -1
- package/dist/capabilities.js +6 -8
- package/dist/compiler.d.ts +3 -3
- package/dist/compiler.js +4 -4
- package/dist/index.d.ts +33 -30
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +33 -30
- package/dist/preview/canvas-scaler.d.ts +49 -0
- package/dist/preview/canvas-scaler.d.ts.map +1 -0
- package/dist/preview/canvas-scaler.js +74 -0
- package/dist/preview/code-renderer.d.ts +11 -28
- package/dist/preview/code-renderer.d.ts.map +1 -1
- package/dist/preview/code-renderer.js +115 -660
- package/dist/preview/frame-budget.d.ts +43 -0
- package/dist/preview/frame-budget.d.ts.map +1 -0
- package/dist/preview/frame-budget.js +78 -0
- package/dist/preview/preview-engine.d.ts +42 -0
- package/dist/preview/preview-engine.d.ts.map +1 -0
- package/dist/preview/preview-engine.js +201 -0
- package/dist/preview/preview-runtime.d.ts +28 -0
- package/dist/preview/preview-runtime.d.ts.map +1 -0
- package/dist/preview/preview-runtime.js +512 -0
- package/dist/preview/preview-types.d.ts +116 -0
- package/dist/preview/preview-types.d.ts.map +1 -0
- package/dist/preview/preview-types.js +36 -0
- package/dist/preview/renderer.d.ts +3 -3
- package/dist/preview/renderer.js +3 -3
- package/dist/preview/unified-renderer.d.ts.map +1 -1
- package/dist/preview/unified-renderer.js +45 -22
- package/dist/system.d.ts +2 -2
- package/dist/system.d.ts.map +1 -1
- package/dist/system.js +8 -10
- package/dist/types.d.ts +9 -5
- package/dist/types.d.ts.map +1 -1
- package/dist/types.js +9 -5
- package/package.json +2 -2
package/dist/compiler.d.ts
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* @nexart/ui-renderer v0.
|
|
2
|
+
* @nexart/ui-renderer v0.8.0 - System Compiler
|
|
3
3
|
*
|
|
4
|
-
* Compiles validated systems into
|
|
5
|
-
*
|
|
4
|
+
* Compiles validated systems into protocol-compatible JSON.
|
|
5
|
+
* Lightweight preview runtime — no protocol enforcement.
|
|
6
6
|
*/
|
|
7
7
|
import type { NexArtSystem } from './types';
|
|
8
8
|
export interface CompiledDeclarativeSystem {
|
package/dist/compiler.js
CHANGED
|
@@ -1,11 +1,11 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* @nexart/ui-renderer v0.
|
|
2
|
+
* @nexart/ui-renderer v0.8.0 - System Compiler
|
|
3
3
|
*
|
|
4
|
-
* Compiles validated systems into
|
|
5
|
-
*
|
|
4
|
+
* Compiles validated systems into protocol-compatible JSON.
|
|
5
|
+
* Lightweight preview runtime — no protocol enforcement.
|
|
6
6
|
*/
|
|
7
7
|
import { isCodeModeSystem } from './system';
|
|
8
|
-
const COMPILER_VERSION = '0.
|
|
8
|
+
const COMPILER_VERSION = '0.8.0';
|
|
9
9
|
export function compileSystem(system) {
|
|
10
10
|
if (isCodeModeSystem(system)) {
|
|
11
11
|
return compileCodeSystem(system);
|
package/dist/index.d.ts
CHANGED
|
@@ -1,35 +1,34 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* @nexart/ui-renderer
|
|
3
|
-
* Version: 0.
|
|
3
|
+
* Version: 0.8.0
|
|
4
4
|
*
|
|
5
|
-
*
|
|
6
|
-
* Mirrors @nexart/codemode-sdk v1.4.0 (Protocol v1.2.0)
|
|
5
|
+
* Lightweight Preview Runtime for NexArt Protocol
|
|
7
6
|
*
|
|
8
|
-
*
|
|
9
|
-
*
|
|
10
|
-
*
|
|
11
|
-
*
|
|
12
|
-
*
|
|
13
|
-
*
|
|
14
|
-
*
|
|
15
|
-
* -
|
|
16
|
-
* -
|
|
17
|
-
*
|
|
18
|
-
*
|
|
19
|
-
*
|
|
20
|
-
*
|
|
21
|
-
* -
|
|
22
|
-
* -
|
|
23
|
-
*
|
|
24
|
-
*
|
|
25
|
-
*
|
|
26
|
-
*
|
|
27
|
-
* -
|
|
28
|
-
*
|
|
29
|
-
*
|
|
30
|
-
*
|
|
31
|
-
*
|
|
32
|
-
*
|
|
7
|
+
* ╔══════════════════════════════════════════════════════════════════════════╗
|
|
8
|
+
* ║ PREVIEW RUNTIME — NON-AUTHORITATIVE ║
|
|
9
|
+
* ║ ║
|
|
10
|
+
* ║ This renderer is a preview-only runtime. ║
|
|
11
|
+
* ║ It does not guarantee determinism or protocol compliance. ║
|
|
12
|
+
* ║ ║
|
|
13
|
+
* ║ Performance Limits: ║
|
|
14
|
+
* ║ - Max frames: 30 ║
|
|
15
|
+
* ║ - Max total time: 500ms ║
|
|
16
|
+
* ║ - Max canvas dimension: 900px ║
|
|
17
|
+
* ║ - Frame stride: render every 3rd frame ║
|
|
18
|
+
* ║ ║
|
|
19
|
+
* ║ Use Cases: ║
|
|
20
|
+
* ║ - Editor live preview ║
|
|
21
|
+
* ║ - Builder dashboards ║
|
|
22
|
+
* ║ - Background generative art ║
|
|
23
|
+
* ║ - Static or loop previews ║
|
|
24
|
+
* ║ ║
|
|
25
|
+
* ║ NOT For: ║
|
|
26
|
+
* ║ - Minting / export ║
|
|
27
|
+
* ║ - ByX ║
|
|
28
|
+
* ║ - Protocol validation ║
|
|
29
|
+
* ║ ║
|
|
30
|
+
* ║ For canonical output: use @nexart/codemode-sdk ║
|
|
31
|
+
* ╚══════════════════════════════════════════════════════════════════════════╝
|
|
33
32
|
*/
|
|
34
33
|
export { createSystem, validateSystem, isCodeModeSystem, isDeclarativeSystem, isUnifiedModeSystem } from './system';
|
|
35
34
|
export { compileSystem, serializeSystem } from './compiler';
|
|
@@ -40,11 +39,15 @@ export { compileBackgroundPreset, getPaletteColors } from './presets/backgrounds
|
|
|
40
39
|
export { compilePrimitive } from './presets/primitives';
|
|
41
40
|
export { wrapSketch, validateSketchSafety } from './presets/sketch-wrapper';
|
|
42
41
|
export { getCapabilities, getPrimitiveTypes, getPrimitivesByCategory, getPrimitiveInfo, isPrimitiveValid, getMotionSources, getBackgroundTextures, } from './capabilities';
|
|
42
|
+
export { createPreviewEngine, renderStaticPreview, stopActivePreview, } from './preview/preview-engine';
|
|
43
|
+
export { PREVIEW_BUDGET, CANVAS_LIMITS, type RuntimeProfile, type PreviewMode, type PreviewEngineConfig, type PreviewRenderResult, type PreviewRenderer, type FrameBudgetState, } from './preview/preview-types';
|
|
44
|
+
export { createFrameBudget, canRenderFrame, recordFrame, resetBudget, shouldSkipFrame, } from './preview/frame-budget';
|
|
45
|
+
export { calculateScaledDimensions, applyScaledDimensions, type ScaledDimensions, } from './preview/canvas-scaler';
|
|
43
46
|
export type { NexArtSystemInput, NexArtSystem, DeclarativeSystemInput, DeclarativeSystem, CodeSystem, NexArtCodeSystem, UnifiedSystemInput, UnifiedSystem, UnifiedElement, BackgroundElement, PrimitiveElement, SketchElement, BackgroundPreset, PrimitiveName, ColorPalette, MotionSpeed, StrokeWeightAuto, LoopConfig, DeclarativeElement, SystemElement, DotsElement, LinesElement, WavesElement, GridElement, FlowFieldElement, OrbitsElement, BackgroundConfig, MotionConfig, PreviewOptions, ValidationResult, } from './types';
|
|
44
47
|
export { AESTHETIC_DEFAULTS, SDK_VERSION as TYPE_SDK_VERSION } from './types';
|
|
45
48
|
export type { Capabilities, PrimitiveCapability, ParameterSpec, } from './capabilities';
|
|
46
|
-
export declare const SDK_VERSION = "0.
|
|
47
|
-
export declare const PROTOCOL_VERSION = "0.
|
|
49
|
+
export declare const SDK_VERSION = "0.8.0";
|
|
50
|
+
export declare const PROTOCOL_VERSION = "0.8";
|
|
48
51
|
export declare const IS_CANONICAL = false;
|
|
49
52
|
export declare const IS_ARCHIVAL = false;
|
|
50
53
|
export declare const RENDERER = "@nexart/ui-renderer";
|
package/dist/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA+BG;AAEH,OAAO,EAAE,YAAY,EAAE,cAAc,EAAE,gBAAgB,EAAE,mBAAmB,EAAE,mBAAmB,EAAE,MAAM,UAAU,CAAC;AACpH,OAAO,EAAE,aAAa,EAAE,eAAe,EAAE,MAAM,YAAY,CAAC;AAC5D,OAAO,EAAE,aAAa,EAAE,MAAM,oBAAoB,CAAC;AACnD,OAAO,EAAE,oBAAoB,EAAE,MAAM,yBAAyB,CAAC;AAC/D,OAAO,EAAE,mBAAmB,EAAE,MAAM,4BAA4B,CAAC;AACjE,OAAO,EAAE,uBAAuB,EAAE,gBAAgB,EAAE,MAAM,uBAAuB,CAAC;AAClF,OAAO,EAAE,gBAAgB,EAAE,MAAM,sBAAsB,CAAC;AACxD,OAAO,EAAE,UAAU,EAAE,oBAAoB,EAAE,MAAM,0BAA0B,CAAC;AAC5E,OAAO,EACL,eAAe,EACf,iBAAiB,EACjB,uBAAuB,EACvB,gBAAgB,EAChB,gBAAgB,EAChB,gBAAgB,EAChB,qBAAqB,GACtB,MAAM,gBAAgB,CAAC;AAExB,OAAO,EACL,mBAAmB,EACnB,mBAAmB,EACnB,iBAAiB,GAClB,MAAM,0BAA0B,CAAC;AAElC,OAAO,EACL,cAAc,EACd,aAAa,EACb,KAAK,cAAc,EACnB,KAAK,WAAW,EAChB,KAAK,mBAAmB,EACxB,KAAK,mBAAmB,EACxB,KAAK,eAAe,EACpB,KAAK,gBAAgB,GACtB,MAAM,yBAAyB,CAAC;AAEjC,OAAO,EACL,iBAAiB,EACjB,cAAc,EACd,WAAW,EACX,WAAW,EACX,eAAe,GAChB,MAAM,wBAAwB,CAAC;AAEhC,OAAO,EACL,yBAAyB,EACzB,qBAAqB,EACrB,KAAK,gBAAgB,GACtB,MAAM,yBAAyB,CAAC;AAEjC,YAAY,EACV,iBAAiB,EACjB,YAAY,EACZ,sBAAsB,EACtB,iBAAiB,EACjB,UAAU,EACV,gBAAgB,EAChB,kBAAkB,EAClB,aAAa,EACb,cAAc,EACd,iBAAiB,EACjB,gBAAgB,EAChB,aAAa,EACb,gBAAgB,EAChB,aAAa,EACb,YAAY,EACZ,WAAW,EACX,gBAAgB,EAChB,UAAU,EACV,kBAAkB,EAClB,aAAa,EACb,WAAW,EACX,YAAY,EACZ,YAAY,EACZ,WAAW,EACX,gBAAgB,EAChB,aAAa,EACb,gBAAgB,EAChB,YAAY,EACZ,cAAc,EACd,gBAAgB,GACjB,MAAM,SAAS,CAAC;AAEjB,OAAO,EAAE,kBAAkB,EAAE,WAAW,IAAI,gBAAgB,EAAE,MAAM,SAAS,CAAC;AAE9E,YAAY,EACV,YAAY,EACZ,mBAAmB,EACnB,aAAa,GACd,MAAM,gBAAgB,CAAC;AAExB,eAAO,MAAM,WAAW,UAAU,CAAC;AACnC,eAAO,MAAM,gBAAgB,QAAQ,CAAC;AACtC,eAAO,MAAM,YAAY,QAAQ,CAAC;AAClC,eAAO,MAAM,WAAW,QAAQ,CAAC;AACjC,eAAO,MAAM,QAAQ,wBAAwB,CAAC;AAC9C,eAAO,MAAM,wBAAwB,QAAQ,CAAC"}
|
package/dist/index.js
CHANGED
|
@@ -1,35 +1,34 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* @nexart/ui-renderer
|
|
3
|
-
* Version: 0.
|
|
3
|
+
* Version: 0.8.0
|
|
4
4
|
*
|
|
5
|
-
*
|
|
6
|
-
* Mirrors @nexart/codemode-sdk v1.4.0 (Protocol v1.2.0)
|
|
5
|
+
* Lightweight Preview Runtime for NexArt Protocol
|
|
7
6
|
*
|
|
8
|
-
*
|
|
9
|
-
*
|
|
10
|
-
*
|
|
11
|
-
*
|
|
12
|
-
*
|
|
13
|
-
*
|
|
14
|
-
*
|
|
15
|
-
* -
|
|
16
|
-
* -
|
|
17
|
-
*
|
|
18
|
-
*
|
|
19
|
-
*
|
|
20
|
-
*
|
|
21
|
-
* -
|
|
22
|
-
* -
|
|
23
|
-
*
|
|
24
|
-
*
|
|
25
|
-
*
|
|
26
|
-
*
|
|
27
|
-
* -
|
|
28
|
-
*
|
|
29
|
-
*
|
|
30
|
-
*
|
|
31
|
-
*
|
|
32
|
-
*
|
|
7
|
+
* ╔══════════════════════════════════════════════════════════════════════════╗
|
|
8
|
+
* ║ PREVIEW RUNTIME — NON-AUTHORITATIVE ║
|
|
9
|
+
* ║ ║
|
|
10
|
+
* ║ This renderer is a preview-only runtime. ║
|
|
11
|
+
* ║ It does not guarantee determinism or protocol compliance. ║
|
|
12
|
+
* ║ ║
|
|
13
|
+
* ║ Performance Limits: ║
|
|
14
|
+
* ║ - Max frames: 30 ║
|
|
15
|
+
* ║ - Max total time: 500ms ║
|
|
16
|
+
* ║ - Max canvas dimension: 900px ║
|
|
17
|
+
* ║ - Frame stride: render every 3rd frame ║
|
|
18
|
+
* ║ ║
|
|
19
|
+
* ║ Use Cases: ║
|
|
20
|
+
* ║ - Editor live preview ║
|
|
21
|
+
* ║ - Builder dashboards ║
|
|
22
|
+
* ║ - Background generative art ║
|
|
23
|
+
* ║ - Static or loop previews ║
|
|
24
|
+
* ║ ║
|
|
25
|
+
* ║ NOT For: ║
|
|
26
|
+
* ║ - Minting / export ║
|
|
27
|
+
* ║ - ByX ║
|
|
28
|
+
* ║ - Protocol validation ║
|
|
29
|
+
* ║ ║
|
|
30
|
+
* ║ For canonical output: use @nexart/codemode-sdk ║
|
|
31
|
+
* ╚══════════════════════════════════════════════════════════════════════════╝
|
|
33
32
|
*/
|
|
34
33
|
export { createSystem, validateSystem, isCodeModeSystem, isDeclarativeSystem, isUnifiedModeSystem } from './system';
|
|
35
34
|
export { compileSystem, serializeSystem } from './compiler';
|
|
@@ -40,9 +39,13 @@ export { compileBackgroundPreset, getPaletteColors } from './presets/backgrounds
|
|
|
40
39
|
export { compilePrimitive } from './presets/primitives';
|
|
41
40
|
export { wrapSketch, validateSketchSafety } from './presets/sketch-wrapper';
|
|
42
41
|
export { getCapabilities, getPrimitiveTypes, getPrimitivesByCategory, getPrimitiveInfo, isPrimitiveValid, getMotionSources, getBackgroundTextures, } from './capabilities';
|
|
42
|
+
export { createPreviewEngine, renderStaticPreview, stopActivePreview, } from './preview/preview-engine';
|
|
43
|
+
export { PREVIEW_BUDGET, CANVAS_LIMITS, } from './preview/preview-types';
|
|
44
|
+
export { createFrameBudget, canRenderFrame, recordFrame, resetBudget, shouldSkipFrame, } from './preview/frame-budget';
|
|
45
|
+
export { calculateScaledDimensions, applyScaledDimensions, } from './preview/canvas-scaler';
|
|
43
46
|
export { AESTHETIC_DEFAULTS, SDK_VERSION as TYPE_SDK_VERSION } from './types';
|
|
44
|
-
export const SDK_VERSION = '0.
|
|
45
|
-
export const PROTOCOL_VERSION = '0.
|
|
47
|
+
export const SDK_VERSION = '0.8.0';
|
|
48
|
+
export const PROTOCOL_VERSION = '0.8';
|
|
46
49
|
export const IS_CANONICAL = false;
|
|
47
50
|
export const IS_ARCHIVAL = false;
|
|
48
51
|
export const RENDERER = '@nexart/ui-renderer';
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @nexart/ui-renderer - Canvas Scaler
|
|
3
|
+
*
|
|
4
|
+
* Scales canvas resolution for preview rendering.
|
|
5
|
+
* Preview renderer does NOT render at full mint resolution.
|
|
6
|
+
*
|
|
7
|
+
* ╔══════════════════════════════════════════════════════════════════════════╗
|
|
8
|
+
* ║ CANVAS SCALING — PERFORMANCE CRITICAL ║
|
|
9
|
+
* ║ ║
|
|
10
|
+
* ║ Max dimension: 900px ║
|
|
11
|
+
* ║ Preserves aspect ratio ║
|
|
12
|
+
* ║ Uses CSS scaling for display ║
|
|
13
|
+
* ╚══════════════════════════════════════════════════════════════════════════╝
|
|
14
|
+
*/
|
|
15
|
+
export interface ScaledDimensions {
|
|
16
|
+
/** Scaled width for rendering */
|
|
17
|
+
renderWidth: number;
|
|
18
|
+
/** Scaled height for rendering */
|
|
19
|
+
renderHeight: number;
|
|
20
|
+
/** Original width */
|
|
21
|
+
originalWidth: number;
|
|
22
|
+
/** Original height */
|
|
23
|
+
originalHeight: number;
|
|
24
|
+
/** Scale factor applied */
|
|
25
|
+
scaleFactor: number;
|
|
26
|
+
/** Whether scaling was applied */
|
|
27
|
+
wasScaled: boolean;
|
|
28
|
+
}
|
|
29
|
+
/**
|
|
30
|
+
* Calculate scaled dimensions for preview rendering.
|
|
31
|
+
* Maintains aspect ratio, caps at MAX_DIMENSION.
|
|
32
|
+
*/
|
|
33
|
+
export declare function calculateScaledDimensions(width: number, height: number): ScaledDimensions;
|
|
34
|
+
/**
|
|
35
|
+
* Apply scaled dimensions to a canvas element.
|
|
36
|
+
* Sets canvas internal resolution and CSS display size.
|
|
37
|
+
*/
|
|
38
|
+
export declare function applyScaledDimensions(canvas: HTMLCanvasElement, dimensions: ScaledDimensions): void;
|
|
39
|
+
/**
|
|
40
|
+
* Scale coordinates from original space to render space.
|
|
41
|
+
* Used when the sketch uses original coordinates but canvas is scaled.
|
|
42
|
+
*/
|
|
43
|
+
export declare function scaleCoordinate(value: number, scaleFactor: number): number;
|
|
44
|
+
/**
|
|
45
|
+
* Create a scaling transform for the canvas context.
|
|
46
|
+
* This allows sketches to use original coordinates while rendering at scaled resolution.
|
|
47
|
+
*/
|
|
48
|
+
export declare function applyScaleTransform(ctx: CanvasRenderingContext2D, scaleFactor: number): void;
|
|
49
|
+
//# sourceMappingURL=canvas-scaler.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"canvas-scaler.d.ts","sourceRoot":"","sources":["../../src/preview/canvas-scaler.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;GAaG;AAIH,MAAM,WAAW,gBAAgB;IAC/B,iCAAiC;IACjC,WAAW,EAAE,MAAM,CAAC;IACpB,kCAAkC;IAClC,YAAY,EAAE,MAAM,CAAC;IACrB,qBAAqB;IACrB,aAAa,EAAE,MAAM,CAAC;IACtB,sBAAsB;IACtB,cAAc,EAAE,MAAM,CAAC;IACvB,2BAA2B;IAC3B,WAAW,EAAE,MAAM,CAAC;IACpB,kCAAkC;IAClC,SAAS,EAAE,OAAO,CAAC;CACpB;AAED;;;GAGG;AACH,wBAAgB,yBAAyB,CACvC,KAAK,EAAE,MAAM,EACb,MAAM,EAAE,MAAM,GACb,gBAAgB,CA0BlB;AAED;;;GAGG;AACH,wBAAgB,qBAAqB,CACnC,MAAM,EAAE,iBAAiB,EACzB,UAAU,EAAE,gBAAgB,GAC3B,IAAI,CAWN;AAED;;;GAGG;AACH,wBAAgB,eAAe,CAC7B,KAAK,EAAE,MAAM,EACb,WAAW,EAAE,MAAM,GAClB,MAAM,CAER;AAED;;;GAGG;AACH,wBAAgB,mBAAmB,CACjC,GAAG,EAAE,wBAAwB,EAC7B,WAAW,EAAE,MAAM,GAClB,IAAI,CAIN"}
|
|
@@ -0,0 +1,74 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @nexart/ui-renderer - Canvas Scaler
|
|
3
|
+
*
|
|
4
|
+
* Scales canvas resolution for preview rendering.
|
|
5
|
+
* Preview renderer does NOT render at full mint resolution.
|
|
6
|
+
*
|
|
7
|
+
* ╔══════════════════════════════════════════════════════════════════════════╗
|
|
8
|
+
* ║ CANVAS SCALING — PERFORMANCE CRITICAL ║
|
|
9
|
+
* ║ ║
|
|
10
|
+
* ║ Max dimension: 900px ║
|
|
11
|
+
* ║ Preserves aspect ratio ║
|
|
12
|
+
* ║ Uses CSS scaling for display ║
|
|
13
|
+
* ╚══════════════════════════════════════════════════════════════════════════╝
|
|
14
|
+
*/
|
|
15
|
+
import { CANVAS_LIMITS } from './preview-types';
|
|
16
|
+
/**
|
|
17
|
+
* Calculate scaled dimensions for preview rendering.
|
|
18
|
+
* Maintains aspect ratio, caps at MAX_DIMENSION.
|
|
19
|
+
*/
|
|
20
|
+
export function calculateScaledDimensions(width, height) {
|
|
21
|
+
const maxDim = Math.max(width, height);
|
|
22
|
+
// If already within limits, no scaling needed
|
|
23
|
+
if (maxDim <= CANVAS_LIMITS.MAX_DIMENSION) {
|
|
24
|
+
return {
|
|
25
|
+
renderWidth: width,
|
|
26
|
+
renderHeight: height,
|
|
27
|
+
originalWidth: width,
|
|
28
|
+
originalHeight: height,
|
|
29
|
+
scaleFactor: 1,
|
|
30
|
+
wasScaled: false,
|
|
31
|
+
};
|
|
32
|
+
}
|
|
33
|
+
// Calculate scale factor to fit within limits
|
|
34
|
+
const scaleFactor = CANVAS_LIMITS.MAX_DIMENSION / maxDim;
|
|
35
|
+
return {
|
|
36
|
+
renderWidth: Math.round(width * scaleFactor),
|
|
37
|
+
renderHeight: Math.round(height * scaleFactor),
|
|
38
|
+
originalWidth: width,
|
|
39
|
+
originalHeight: height,
|
|
40
|
+
scaleFactor,
|
|
41
|
+
wasScaled: true,
|
|
42
|
+
};
|
|
43
|
+
}
|
|
44
|
+
/**
|
|
45
|
+
* Apply scaled dimensions to a canvas element.
|
|
46
|
+
* Sets canvas internal resolution and CSS display size.
|
|
47
|
+
*/
|
|
48
|
+
export function applyScaledDimensions(canvas, dimensions) {
|
|
49
|
+
// Set canvas internal resolution (what we actually render)
|
|
50
|
+
canvas.width = dimensions.renderWidth;
|
|
51
|
+
canvas.height = dimensions.renderHeight;
|
|
52
|
+
// Set CSS display size (visual size in the UI)
|
|
53
|
+
// This allows the canvas to display at a larger size while rendering at lower resolution
|
|
54
|
+
if (dimensions.wasScaled) {
|
|
55
|
+
canvas.style.width = `${dimensions.originalWidth}px`;
|
|
56
|
+
canvas.style.height = `${dimensions.originalHeight}px`;
|
|
57
|
+
}
|
|
58
|
+
}
|
|
59
|
+
/**
|
|
60
|
+
* Scale coordinates from original space to render space.
|
|
61
|
+
* Used when the sketch uses original coordinates but canvas is scaled.
|
|
62
|
+
*/
|
|
63
|
+
export function scaleCoordinate(value, scaleFactor) {
|
|
64
|
+
return value * scaleFactor;
|
|
65
|
+
}
|
|
66
|
+
/**
|
|
67
|
+
* Create a scaling transform for the canvas context.
|
|
68
|
+
* This allows sketches to use original coordinates while rendering at scaled resolution.
|
|
69
|
+
*/
|
|
70
|
+
export function applyScaleTransform(ctx, scaleFactor) {
|
|
71
|
+
if (scaleFactor !== 1) {
|
|
72
|
+
ctx.scale(scaleFactor, scaleFactor);
|
|
73
|
+
}
|
|
74
|
+
}
|
|
@@ -1,28 +1,20 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* @nexart/ui-renderer v0.
|
|
2
|
+
* @nexart/ui-renderer v0.8.0 - Code Mode Renderer
|
|
3
3
|
*
|
|
4
4
|
* ╔══════════════════════════════════════════════════════════════════════════╗
|
|
5
|
-
* ║ PREVIEW RENDERER —
|
|
5
|
+
* ║ PREVIEW RENDERER — LIGHTWEIGHT, NON-AUTHORITATIVE ║
|
|
6
6
|
* ║ ║
|
|
7
|
-
* ║ This
|
|
7
|
+
* ║ This renderer is a preview-only runtime. ║
|
|
8
|
+
* ║ It does not guarantee determinism or protocol compliance. ║
|
|
8
9
|
* ║ ║
|
|
9
|
-
* ║
|
|
10
|
+
* ║ Performance Limits (MANDATORY): ║
|
|
11
|
+
* ║ - Max frames: 30 ║
|
|
12
|
+
* ║ - Max total time: 500ms ║
|
|
13
|
+
* ║ - Max canvas dimension: 900px ║
|
|
14
|
+
* ║ - Frame stride: render every 3rd frame ║
|
|
15
|
+
* ║ ║
|
|
16
|
+
* ║ For minting, export, or validation: use @nexart/codemode-sdk ║
|
|
10
17
|
* ╚══════════════════════════════════════════════════════════════════════════╝
|
|
11
|
-
*
|
|
12
|
-
* ARCHITECTURAL NOTE:
|
|
13
|
-
* -------------------
|
|
14
|
-
* Live preview animation requires local p5 runtime execution because:
|
|
15
|
-
* - @nexart/codemode-sdk.executeCodeMode() returns blobs (PNG/MP4), not frames
|
|
16
|
-
* - Real-time animation in the browser requires frame-by-frame canvas updates
|
|
17
|
-
* - The SDK's loop mode produces video files, not real-time rendering
|
|
18
|
-
*
|
|
19
|
-
* To ensure faithful mirroring, this renderer:
|
|
20
|
-
* 1. Uses identical forbidden pattern validation as the SDK
|
|
21
|
-
* 2. Uses identical VAR handling (read-only, 0-10 input → 10 runtime, 0-100 strict, errors not clamps)
|
|
22
|
-
* 3. Uses identical seeded RNG (Mulberry32) and Perlin noise
|
|
23
|
-
* 4. Uses identical time variable semantics (frameCount, t, time, tGlobal)
|
|
24
|
-
*
|
|
25
|
-
* For archival/canonical output, use @nexart/codemode-sdk directly.
|
|
26
18
|
*/
|
|
27
19
|
import type { NexArtCodeSystem, PreviewOptions } from '../types';
|
|
28
20
|
export interface CodeRenderer {
|
|
@@ -33,14 +25,5 @@ export interface CodeRenderer {
|
|
|
33
25
|
isCanonical: false;
|
|
34
26
|
isArchival: false;
|
|
35
27
|
}
|
|
36
|
-
interface P5Runtime {
|
|
37
|
-
[key: string]: any;
|
|
38
|
-
width: number;
|
|
39
|
-
height: number;
|
|
40
|
-
frameCount: number;
|
|
41
|
-
VAR: readonly number[];
|
|
42
|
-
}
|
|
43
|
-
export declare function createP5Runtime(canvas: HTMLCanvasElement, width: number, height: number, seed: number, vars?: number[]): P5Runtime;
|
|
44
28
|
export declare function renderCodeModeSystem(system: NexArtCodeSystem, canvas: HTMLCanvasElement, options?: PreviewOptions): CodeRenderer;
|
|
45
|
-
export {};
|
|
46
29
|
//# sourceMappingURL=code-renderer.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"code-renderer.d.ts","sourceRoot":"","sources":["../../src/preview/code-renderer.ts"],"names":[],"mappings":"AAAA
|
|
1
|
+
{"version":3,"file":"code-renderer.d.ts","sourceRoot":"","sources":["../../src/preview/code-renderer.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;GAiBG;AAEH,OAAO,KAAK,EAAE,gBAAgB,EAAE,cAAc,EAAE,MAAM,UAAU,CAAC;AAwBjE,MAAM,WAAW,YAAY;IAC3B,MAAM,EAAE,MAAM,IAAI,CAAC;IACnB,KAAK,EAAE,MAAM,IAAI,CAAC;IAClB,IAAI,EAAE,MAAM,IAAI,CAAC;IACjB,OAAO,EAAE,MAAM,IAAI,CAAC;IACpB,WAAW,EAAE,KAAK,CAAC;IACnB,UAAU,EAAE,KAAK,CAAC;CACnB;AAwBD,wBAAgB,oBAAoB,CAClC,MAAM,EAAE,gBAAgB,EACxB,MAAM,EAAE,iBAAiB,EACzB,OAAO,GAAE,cAAmB,GAC3B,YAAY,CA0Od"}
|