@vib3code/sdk 2.0.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/CHANGELOG.md +118 -0
- package/DOCS/BLUEPRINT_EXECUTION_PLAN_2026-01-07.md +34 -0
- package/DOCS/CI_TESTING.md +38 -0
- package/DOCS/CLI_ONBOARDING.md +75 -0
- package/DOCS/CONTROL_REFERENCE.md +64 -0
- package/DOCS/DEV_TRACK_ANALYSIS.md +77 -0
- package/DOCS/DEV_TRACK_PLAN_2026-01-07.md +42 -0
- package/DOCS/DEV_TRACK_SESSION_2026-01-31.md +220 -0
- package/DOCS/ENV_SETUP.md +189 -0
- package/DOCS/EXPORT_FORMATS.md +417 -0
- package/DOCS/GPU_DISPOSAL_GUIDE.md +21 -0
- package/DOCS/LICENSING_TIERS.md +275 -0
- package/DOCS/MASTER_PLAN_2026-01-31.md +570 -0
- package/DOCS/OBS_SETUP_GUIDE.md +98 -0
- package/DOCS/PROJECT_SETUP.md +66 -0
- package/DOCS/RENDERER_LIFECYCLE.md +40 -0
- package/DOCS/REPO_MANIFEST.md +121 -0
- package/DOCS/SESSION_014_PLAN.md +195 -0
- package/DOCS/SESSION_LOG_2026-01-07.md +56 -0
- package/DOCS/STRATEGIC_BLUEPRINT_2026-01-07.md +72 -0
- package/DOCS/SYSTEM_AUDIT_2026-01-30.md +738 -0
- package/DOCS/SYSTEM_INVENTORY.md +520 -0
- package/DOCS/TELEMETRY_EXPORTS.md +34 -0
- package/DOCS/WEBGPU_STATUS.md +38 -0
- package/DOCS/XR_BENCHMARKS.md +608 -0
- package/LICENSE +21 -0
- package/README.md +426 -0
- package/docs/.nojekyll +0 -0
- package/docs/01-dissolution_of_euclidean_hegemony.html +346 -0
- package/docs/02-hyperspatial_ego_death.html +346 -0
- package/docs/03-post_cartesian_sublime.html +346 -0
- package/docs/04-crystalline_void_meditation.html +346 -0
- package/docs/05-quantum_decoherence_ballet.html +346 -0
- package/docs/06-dissolution_of_euclidean_hegemony.html +346 -0
- package/docs/07-hyperspatial_ego_death.html +346 -0
- package/docs/08-post_cartesian_sublime.html +346 -0
- package/docs/09-crystalline_void_meditation.html +346 -0
- package/docs/10-quantum_decoherence_ballet.html +346 -0
- package/docs/11-dissolution_of_euclidean_hegemony.html +346 -0
- package/docs/12-hyperspatial_ego_death.html +346 -0
- package/docs/13-post_cartesian_sublime.html +346 -0
- package/docs/index.html +794 -0
- package/docs/test-hub.html +441 -0
- package/docs/url-state.js +102 -0
- package/docs/vib3-exports/01-quantum-quantum-tetrahedron-lattice.html +489 -0
- package/docs/vib3-exports/02-quantum-quantum-hypersphere-matrix.html +489 -0
- package/docs/vib3-exports/03-quantum-quantum-hypertetra-fractal.html +489 -0
- package/docs/vib3-exports/04-faceted-faceted-crystal-structure.html +407 -0
- package/docs/vib3-exports/05-faceted-faceted-klein-bottle.html +407 -0
- package/docs/vib3-exports/06-faceted-faceted-hypertetra-torus.html +407 -0
- package/docs/vib3-exports/07-holographic-holographic-wave-field.html +457 -0
- package/docs/vib3-exports/08-holographic-holographic-hypersphere-sphere.html +457 -0
- package/docs/vib3-exports/09-holographic-holographic-hypertetra-crystal.html +457 -0
- package/docs/vib3-exports/index.html +238 -0
- package/docs/webgpu-live.html +702 -0
- package/package.json +367 -0
- package/src/advanced/AIPresetGenerator.js +777 -0
- package/src/advanced/MIDIController.js +703 -0
- package/src/advanced/OffscreenWorker.js +1051 -0
- package/src/advanced/WebGPUCompute.js +1051 -0
- package/src/advanced/WebXRRenderer.js +680 -0
- package/src/agent/cli/AgentCLI.js +615 -0
- package/src/agent/cli/index.js +14 -0
- package/src/agent/index.js +73 -0
- package/src/agent/mcp/MCPServer.js +950 -0
- package/src/agent/mcp/index.js +9 -0
- package/src/agent/mcp/tools.js +548 -0
- package/src/agent/telemetry/EventStream.js +669 -0
- package/src/agent/telemetry/Instrumentation.js +618 -0
- package/src/agent/telemetry/TelemetryExporters.js +427 -0
- package/src/agent/telemetry/TelemetryService.js +464 -0
- package/src/agent/telemetry/index.js +52 -0
- package/src/benchmarks/BenchmarkRunner.js +381 -0
- package/src/benchmarks/MetricsCollector.js +299 -0
- package/src/benchmarks/index.js +9 -0
- package/src/benchmarks/scenes.js +259 -0
- package/src/cli/index.js +675 -0
- package/src/config/ApiConfig.js +88 -0
- package/src/core/CanvasManager.js +217 -0
- package/src/core/ErrorReporter.js +117 -0
- package/src/core/ParameterMapper.js +333 -0
- package/src/core/Parameters.js +396 -0
- package/src/core/RendererContracts.js +200 -0
- package/src/core/UnifiedResourceManager.js +370 -0
- package/src/core/VIB3Engine.js +636 -0
- package/src/core/renderers/FacetedRendererAdapter.js +32 -0
- package/src/core/renderers/HolographicRendererAdapter.js +29 -0
- package/src/core/renderers/QuantumRendererAdapter.js +29 -0
- package/src/core/renderers/RendererLifecycleManager.js +63 -0
- package/src/creative/ColorPresetsSystem.js +980 -0
- package/src/creative/ParameterTimeline.js +1061 -0
- package/src/creative/PostProcessingPipeline.js +1113 -0
- package/src/creative/TransitionAnimator.js +683 -0
- package/src/export/CSSExporter.js +226 -0
- package/src/export/CardGeneratorBase.js +279 -0
- package/src/export/ExportManager.js +580 -0
- package/src/export/FacetedCardGenerator.js +279 -0
- package/src/export/HolographicCardGenerator.js +543 -0
- package/src/export/LottieExporter.js +552 -0
- package/src/export/QuantumCardGenerator.js +315 -0
- package/src/export/SVGExporter.js +519 -0
- package/src/export/ShaderExporter.js +903 -0
- package/src/export/TradingCardGenerator.js +3055 -0
- package/src/export/TradingCardManager.js +181 -0
- package/src/export/VIB3PackageExporter.js +559 -0
- package/src/export/index.js +14 -0
- package/src/export/systems/TradingCardSystemFaceted.js +494 -0
- package/src/export/systems/TradingCardSystemHolographic.js +452 -0
- package/src/export/systems/TradingCardSystemQuantum.js +411 -0
- package/src/faceted/FacetedSystem.js +963 -0
- package/src/features/CollectionManager.js +433 -0
- package/src/gallery/CollectionManager.js +240 -0
- package/src/gallery/GallerySystem.js +485 -0
- package/src/geometry/GeometryFactory.js +314 -0
- package/src/geometry/GeometryLibrary.js +72 -0
- package/src/geometry/buffers/BufferBuilder.js +338 -0
- package/src/geometry/buffers/index.js +18 -0
- package/src/geometry/generators/Crystal.js +420 -0
- package/src/geometry/generators/Fractal.js +298 -0
- package/src/geometry/generators/KleinBottle.js +197 -0
- package/src/geometry/generators/Sphere.js +192 -0
- package/src/geometry/generators/Tesseract.js +160 -0
- package/src/geometry/generators/Tetrahedron.js +225 -0
- package/src/geometry/generators/Torus.js +304 -0
- package/src/geometry/generators/Wave.js +341 -0
- package/src/geometry/index.js +142 -0
- package/src/geometry/warp/HypersphereCore.js +211 -0
- package/src/geometry/warp/HypertetraCore.js +386 -0
- package/src/geometry/warp/index.js +57 -0
- package/src/holograms/HolographicVisualizer.js +1073 -0
- package/src/holograms/RealHolographicSystem.js +966 -0
- package/src/holograms/variantRegistry.js +69 -0
- package/src/integrations/FigmaPlugin.js +854 -0
- package/src/integrations/OBSMode.js +754 -0
- package/src/integrations/ThreeJsPackage.js +660 -0
- package/src/integrations/TouchDesignerExport.js +552 -0
- package/src/integrations/frameworks/Vib3React.js +591 -0
- package/src/integrations/frameworks/Vib3Svelte.js +654 -0
- package/src/integrations/frameworks/Vib3Vue.js +628 -0
- package/src/llm/LLMParameterInterface.js +240 -0
- package/src/llm/LLMParameterUI.js +577 -0
- package/src/math/Mat4x4.js +708 -0
- package/src/math/Projection.js +341 -0
- package/src/math/Rotor4D.js +637 -0
- package/src/math/Vec4.js +476 -0
- package/src/math/constants.js +164 -0
- package/src/math/index.js +68 -0
- package/src/math/projections.js +54 -0
- package/src/math/rotations.js +196 -0
- package/src/quantum/QuantumEngine.js +906 -0
- package/src/quantum/QuantumVisualizer.js +1103 -0
- package/src/reactivity/ReactivityConfig.js +499 -0
- package/src/reactivity/ReactivityManager.js +586 -0
- package/src/reactivity/SpatialInputSystem.js +1783 -0
- package/src/reactivity/index.js +93 -0
- package/src/render/CommandBuffer.js +465 -0
- package/src/render/MultiCanvasBridge.js +340 -0
- package/src/render/RenderCommand.js +514 -0
- package/src/render/RenderResourceRegistry.js +523 -0
- package/src/render/RenderState.js +552 -0
- package/src/render/RenderTarget.js +512 -0
- package/src/render/ShaderLoader.js +253 -0
- package/src/render/ShaderProgram.js +599 -0
- package/src/render/UnifiedRenderBridge.js +496 -0
- package/src/render/backends/WebGLBackend.js +1108 -0
- package/src/render/backends/WebGPUBackend.js +1409 -0
- package/src/render/commands/CommandBufferExecutor.js +607 -0
- package/src/render/commands/RenderCommandBuffer.js +661 -0
- package/src/render/commands/index.js +17 -0
- package/src/render/index.js +367 -0
- package/src/scene/Disposable.js +498 -0
- package/src/scene/MemoryPool.js +618 -0
- package/src/scene/Node4D.js +697 -0
- package/src/scene/ResourceManager.js +599 -0
- package/src/scene/Scene4D.js +540 -0
- package/src/scene/index.js +98 -0
- package/src/schemas/error.schema.json +84 -0
- package/src/schemas/extension.schema.json +88 -0
- package/src/schemas/index.js +214 -0
- package/src/schemas/parameters.schema.json +142 -0
- package/src/schemas/tool-pack.schema.json +44 -0
- package/src/schemas/tool-response.schema.json +127 -0
- package/src/shaders/common/fullscreen.vert.glsl +5 -0
- package/src/shaders/common/fullscreen.vert.wgsl +17 -0
- package/src/shaders/common/geometry24.glsl +65 -0
- package/src/shaders/common/geometry24.wgsl +54 -0
- package/src/shaders/common/rotation4d.glsl +85 -0
- package/src/shaders/common/rotation4d.wgsl +86 -0
- package/src/shaders/common/uniforms.glsl +44 -0
- package/src/shaders/common/uniforms.wgsl +48 -0
- package/src/shaders/faceted/faceted.frag.glsl +129 -0
- package/src/shaders/faceted/faceted.frag.wgsl +164 -0
- package/src/shaders/holographic/holographic.frag.glsl +406 -0
- package/src/shaders/holographic/holographic.frag.wgsl +185 -0
- package/src/shaders/quantum/quantum.frag.glsl +513 -0
- package/src/shaders/quantum/quantum.frag.wgsl +361 -0
- package/src/testing/ParallelTestFramework.js +519 -0
- package/src/testing/__snapshots__/exportFormats.test.js.snap +24 -0
- package/src/testing/exportFormats.test.js +8 -0
- package/src/testing/projections.test.js +14 -0
- package/src/testing/rotations.test.js +37 -0
- package/src/ui/InteractivityMenu.js +516 -0
- package/src/ui/StatusManager.js +96 -0
- package/src/ui/adaptive/renderers/webgpu/BufferLayout.ts +252 -0
- package/src/ui/adaptive/renderers/webgpu/PolytopeInstanceBuffer.ts +144 -0
- package/src/ui/adaptive/renderers/webgpu/TripleBufferedUniform.ts +170 -0
- package/src/ui/adaptive/renderers/webgpu/WebGPURenderer.ts +735 -0
- package/src/ui/adaptive/renderers/webgpu/index.ts +112 -0
- package/src/variations/VariationManager.js +431 -0
- package/src/viewer/AudioReactivity.js +505 -0
- package/src/viewer/CardBending.js +481 -0
- package/src/viewer/GalleryUI.js +832 -0
- package/src/viewer/ReactivityManager.js +590 -0
- package/src/viewer/TradingCardExporter.js +600 -0
- package/src/viewer/ViewerPortal.js +374 -0
- package/src/viewer/index.js +12 -0
- package/src/wasm/WasmLoader.js +296 -0
- package/src/wasm/index.js +132 -0
- package/tools/agentic/mcpTools.js +88 -0
- package/tools/cli/agent-cli.js +92 -0
- package/tools/export/formats.js +24 -0
- package/tools/math/rotation-baseline.mjs +64 -0
- package/tools/shader-sync-verify.js +937 -0
- package/tools/telemetry/manifestPipeline.js +141 -0
- package/tools/telemetry/telemetryEvents.js +35 -0
- package/types/adaptive-sdk.d.ts +185 -0
- package/types/advanced/AIPresetGenerator.d.ts +81 -0
- package/types/advanced/MIDIController.d.ts +100 -0
- package/types/advanced/OffscreenWorker.d.ts +82 -0
- package/types/advanced/WebGPUCompute.d.ts +52 -0
- package/types/advanced/WebXRRenderer.d.ts +77 -0
- package/types/advanced/index.d.ts +46 -0
- package/types/core/ErrorReporter.d.ts +50 -0
- package/types/core/VIB3Engine.d.ts +204 -0
- package/types/creative/ColorPresetsSystem.d.ts +91 -0
- package/types/creative/ParameterTimeline.d.ts +74 -0
- package/types/creative/PostProcessingPipeline.d.ts +109 -0
- package/types/creative/TransitionAnimator.d.ts +71 -0
- package/types/creative/index.d.ts +35 -0
- package/types/integrations/FigmaPlugin.d.ts +46 -0
- package/types/integrations/OBSMode.d.ts +74 -0
- package/types/integrations/ThreeJsPackage.d.ts +62 -0
- package/types/integrations/TouchDesignerExport.d.ts +36 -0
- package/types/integrations/Vib3React.d.ts +74 -0
- package/types/integrations/Vib3Svelte.d.ts +63 -0
- package/types/integrations/Vib3Vue.d.ts +55 -0
- package/types/integrations/index.d.ts +52 -0
- package/types/reactivity/SpatialInputSystem.d.ts +173 -0
- package/types/reactivity/index.d.ts +394 -0
- package/types/render/CommandBuffer.d.ts +169 -0
- package/types/render/RenderCommand.d.ts +312 -0
- package/types/render/RenderState.d.ts +279 -0
- package/types/render/RenderTarget.d.ts +254 -0
- package/types/render/ShaderProgram.d.ts +277 -0
- package/types/render/UnifiedRenderBridge.d.ts +143 -0
- package/types/render/WebGLBackend.d.ts +168 -0
- package/types/render/WebGPUBackend.d.ts +186 -0
- package/types/render/index.d.ts +141 -0
|
@@ -0,0 +1,600 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* TradingCardExporter.js - Export Visualization Frames as Trading Cards
|
|
3
|
+
*
|
|
4
|
+
* Creates high-quality trading card exports with:
|
|
5
|
+
* - Standard card dimensions (2.5" x 3.5" at various DPI)
|
|
6
|
+
* - Custom borders and frames
|
|
7
|
+
* - Metadata overlays (name, stats, rarity)
|
|
8
|
+
* - Multiple export formats (PNG, JPEG, WebP, PDF)
|
|
9
|
+
* - Batch export capabilities
|
|
10
|
+
*/
|
|
11
|
+
|
|
12
|
+
import { EventEmitter } from 'events';
|
|
13
|
+
|
|
14
|
+
/**
|
|
15
|
+
* Card size presets (in pixels at 300 DPI)
|
|
16
|
+
*/
|
|
17
|
+
export const CardSize = {
|
|
18
|
+
STANDARD: { width: 750, height: 1050, name: 'Standard (2.5" x 3.5")' },
|
|
19
|
+
MINI: { width: 525, height: 735, name: 'Mini (1.75" x 2.45")' },
|
|
20
|
+
JUMBO: { width: 1050, height: 1470, name: 'Jumbo (3.5" x 4.9")' },
|
|
21
|
+
SQUARE: { width: 900, height: 900, name: 'Square (3" x 3")' },
|
|
22
|
+
POSTER: { width: 1800, height: 2400, name: 'Poster (6" x 8")' }
|
|
23
|
+
};
|
|
24
|
+
|
|
25
|
+
/**
|
|
26
|
+
* Card frame styles
|
|
27
|
+
*/
|
|
28
|
+
export const FrameStyle = {
|
|
29
|
+
NONE: 'none',
|
|
30
|
+
SIMPLE: 'simple',
|
|
31
|
+
HOLOGRAPHIC: 'holographic',
|
|
32
|
+
QUANTUM: 'quantum',
|
|
33
|
+
FACETED: 'faceted',
|
|
34
|
+
VINTAGE: 'vintage',
|
|
35
|
+
FUTURISTIC: 'futuristic'
|
|
36
|
+
};
|
|
37
|
+
|
|
38
|
+
/**
|
|
39
|
+
* Rarity levels with colors
|
|
40
|
+
*/
|
|
41
|
+
export const Rarity = {
|
|
42
|
+
COMMON: { name: 'Common', color: '#888888', glow: false },
|
|
43
|
+
UNCOMMON: { name: 'Uncommon', color: '#4CAF50', glow: false },
|
|
44
|
+
RARE: { name: 'Rare', color: '#2196F3', glow: true },
|
|
45
|
+
EPIC: { name: 'Epic', color: '#9C27B0', glow: true },
|
|
46
|
+
LEGENDARY: { name: 'Legendary', color: '#FF9800', glow: true },
|
|
47
|
+
MYTHIC: { name: 'Mythic', color: '#FF5722', glow: true, animated: true }
|
|
48
|
+
};
|
|
49
|
+
|
|
50
|
+
/**
|
|
51
|
+
* TradingCardExporter - Export visualization frames as trading cards
|
|
52
|
+
*/
|
|
53
|
+
export class TradingCardExporter extends EventEmitter {
|
|
54
|
+
constructor(options = {}) {
|
|
55
|
+
super();
|
|
56
|
+
|
|
57
|
+
this.sourceCanvas = null;
|
|
58
|
+
this.exportCanvas = null;
|
|
59
|
+
this.ctx = null;
|
|
60
|
+
|
|
61
|
+
// Default configuration
|
|
62
|
+
this.config = {
|
|
63
|
+
size: options.size || CardSize.STANDARD,
|
|
64
|
+
frameStyle: options.frameStyle || FrameStyle.HOLOGRAPHIC,
|
|
65
|
+
borderWidth: options.borderWidth || 20,
|
|
66
|
+
cornerRadius: options.cornerRadius || 20,
|
|
67
|
+
quality: options.quality || 0.95,
|
|
68
|
+
showMetadata: options.showMetadata !== false,
|
|
69
|
+
showRarity: options.showRarity !== false,
|
|
70
|
+
showStats: options.showStats || false
|
|
71
|
+
};
|
|
72
|
+
|
|
73
|
+
// Card metadata
|
|
74
|
+
this.metadata = {
|
|
75
|
+
title: options.title || 'VIB3+ Visualization',
|
|
76
|
+
subtitle: options.subtitle || '',
|
|
77
|
+
rarity: options.rarity || Rarity.RARE,
|
|
78
|
+
system: options.system || 'quantum',
|
|
79
|
+
geometry: options.geometry || 0,
|
|
80
|
+
variation: options.variation || 0,
|
|
81
|
+
stats: options.stats || {}
|
|
82
|
+
};
|
|
83
|
+
|
|
84
|
+
// Create offscreen canvas
|
|
85
|
+
this._createExportCanvas();
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
/**
|
|
89
|
+
* Initialize with source canvas
|
|
90
|
+
*/
|
|
91
|
+
initialize(sourceCanvas) {
|
|
92
|
+
this.sourceCanvas = sourceCanvas;
|
|
93
|
+
this.emit('initialized');
|
|
94
|
+
return this;
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
/**
|
|
98
|
+
* Create offscreen export canvas
|
|
99
|
+
*/
|
|
100
|
+
_createExportCanvas() {
|
|
101
|
+
if (typeof OffscreenCanvas !== 'undefined') {
|
|
102
|
+
this.exportCanvas = new OffscreenCanvas(
|
|
103
|
+
this.config.size.width,
|
|
104
|
+
this.config.size.height
|
|
105
|
+
);
|
|
106
|
+
} else {
|
|
107
|
+
this.exportCanvas = document.createElement('canvas');
|
|
108
|
+
this.exportCanvas.width = this.config.size.width;
|
|
109
|
+
this.exportCanvas.height = this.config.size.height;
|
|
110
|
+
}
|
|
111
|
+
this.ctx = this.exportCanvas.getContext('2d');
|
|
112
|
+
}
|
|
113
|
+
|
|
114
|
+
/**
|
|
115
|
+
* Set card size
|
|
116
|
+
*/
|
|
117
|
+
setSize(size) {
|
|
118
|
+
this.config.size = size;
|
|
119
|
+
this.exportCanvas.width = size.width;
|
|
120
|
+
this.exportCanvas.height = size.height;
|
|
121
|
+
}
|
|
122
|
+
|
|
123
|
+
/**
|
|
124
|
+
* Set card metadata
|
|
125
|
+
*/
|
|
126
|
+
setMetadata(metadata) {
|
|
127
|
+
Object.assign(this.metadata, metadata);
|
|
128
|
+
}
|
|
129
|
+
|
|
130
|
+
/**
|
|
131
|
+
* Export current frame as trading card
|
|
132
|
+
*/
|
|
133
|
+
async exportCard(format = 'png') {
|
|
134
|
+
if (!this.sourceCanvas) {
|
|
135
|
+
throw new Error('Source canvas not initialized');
|
|
136
|
+
}
|
|
137
|
+
|
|
138
|
+
const { width, height } = this.config.size;
|
|
139
|
+
|
|
140
|
+
// Clear canvas
|
|
141
|
+
this.ctx.clearRect(0, 0, width, height);
|
|
142
|
+
|
|
143
|
+
// Draw background
|
|
144
|
+
this._drawBackground();
|
|
145
|
+
|
|
146
|
+
// Draw frame
|
|
147
|
+
this._drawFrame();
|
|
148
|
+
|
|
149
|
+
// Draw visualization (with padding for frame)
|
|
150
|
+
this._drawVisualization();
|
|
151
|
+
|
|
152
|
+
// Draw metadata
|
|
153
|
+
if (this.config.showMetadata) {
|
|
154
|
+
this._drawMetadata();
|
|
155
|
+
}
|
|
156
|
+
|
|
157
|
+
// Draw rarity indicator
|
|
158
|
+
if (this.config.showRarity) {
|
|
159
|
+
this._drawRarity();
|
|
160
|
+
}
|
|
161
|
+
|
|
162
|
+
// Draw stats
|
|
163
|
+
if (this.config.showStats) {
|
|
164
|
+
this._drawStats();
|
|
165
|
+
}
|
|
166
|
+
|
|
167
|
+
// Export to blob
|
|
168
|
+
const blob = await this._canvasToBlob(format);
|
|
169
|
+
|
|
170
|
+
this.emit('exported', { format, size: blob.size });
|
|
171
|
+
|
|
172
|
+
return blob;
|
|
173
|
+
}
|
|
174
|
+
|
|
175
|
+
/**
|
|
176
|
+
* Download card
|
|
177
|
+
*/
|
|
178
|
+
async downloadCard(filename, format = 'png') {
|
|
179
|
+
const blob = await this.exportCard(format);
|
|
180
|
+
const url = URL.createObjectURL(blob);
|
|
181
|
+
|
|
182
|
+
const link = document.createElement('a');
|
|
183
|
+
link.download = `${filename}.${format}`;
|
|
184
|
+
link.href = url;
|
|
185
|
+
link.click();
|
|
186
|
+
|
|
187
|
+
URL.revokeObjectURL(url);
|
|
188
|
+
|
|
189
|
+
this.emit('downloaded', { filename, format });
|
|
190
|
+
}
|
|
191
|
+
|
|
192
|
+
/**
|
|
193
|
+
* Export batch of cards at different rotations
|
|
194
|
+
*/
|
|
195
|
+
async exportBatch(rotations, format = 'png') {
|
|
196
|
+
const results = [];
|
|
197
|
+
|
|
198
|
+
for (let i = 0; i < rotations.length; i++) {
|
|
199
|
+
const rotation = rotations[i];
|
|
200
|
+
|
|
201
|
+
// Apply rotation to engine (if available)
|
|
202
|
+
if (this.engine?.setRotation) {
|
|
203
|
+
this.engine.setRotation(rotation);
|
|
204
|
+
// Wait for render
|
|
205
|
+
await new Promise(resolve => requestAnimationFrame(resolve));
|
|
206
|
+
}
|
|
207
|
+
|
|
208
|
+
const blob = await this.exportCard(format);
|
|
209
|
+
results.push({
|
|
210
|
+
index: i,
|
|
211
|
+
rotation,
|
|
212
|
+
blob,
|
|
213
|
+
size: blob.size
|
|
214
|
+
});
|
|
215
|
+
|
|
216
|
+
this.emit('batchProgress', { current: i + 1, total: rotations.length });
|
|
217
|
+
}
|
|
218
|
+
|
|
219
|
+
this.emit('batchComplete', { count: results.length });
|
|
220
|
+
|
|
221
|
+
return results;
|
|
222
|
+
}
|
|
223
|
+
|
|
224
|
+
/**
|
|
225
|
+
* Draw card background
|
|
226
|
+
*/
|
|
227
|
+
_drawBackground() {
|
|
228
|
+
const { width, height } = this.config.size;
|
|
229
|
+
const { cornerRadius } = this.config;
|
|
230
|
+
|
|
231
|
+
// Draw rounded rectangle background
|
|
232
|
+
this.ctx.fillStyle = '#0a0a0f';
|
|
233
|
+
this._roundedRect(0, 0, width, height, cornerRadius);
|
|
234
|
+
this.ctx.fill();
|
|
235
|
+
|
|
236
|
+
// Add subtle gradient
|
|
237
|
+
const gradient = this.ctx.createLinearGradient(0, 0, width, height);
|
|
238
|
+
gradient.addColorStop(0, 'rgba(30, 30, 50, 0.5)');
|
|
239
|
+
gradient.addColorStop(1, 'rgba(10, 10, 20, 0.5)');
|
|
240
|
+
this.ctx.fillStyle = gradient;
|
|
241
|
+
this._roundedRect(0, 0, width, height, cornerRadius);
|
|
242
|
+
this.ctx.fill();
|
|
243
|
+
}
|
|
244
|
+
|
|
245
|
+
/**
|
|
246
|
+
* Draw card frame
|
|
247
|
+
*/
|
|
248
|
+
_drawFrame() {
|
|
249
|
+
const { width, height } = this.config.size;
|
|
250
|
+
const { borderWidth, cornerRadius, frameStyle } = this.config;
|
|
251
|
+
|
|
252
|
+
this.ctx.lineWidth = borderWidth;
|
|
253
|
+
|
|
254
|
+
switch (frameStyle) {
|
|
255
|
+
case FrameStyle.HOLOGRAPHIC:
|
|
256
|
+
this._drawHolographicFrame(width, height, cornerRadius);
|
|
257
|
+
break;
|
|
258
|
+
case FrameStyle.QUANTUM:
|
|
259
|
+
this._drawQuantumFrame(width, height, cornerRadius);
|
|
260
|
+
break;
|
|
261
|
+
case FrameStyle.FACETED:
|
|
262
|
+
this._drawFacetedFrame(width, height, cornerRadius);
|
|
263
|
+
break;
|
|
264
|
+
case FrameStyle.SIMPLE:
|
|
265
|
+
this._drawSimpleFrame(width, height, cornerRadius);
|
|
266
|
+
break;
|
|
267
|
+
case FrameStyle.VINTAGE:
|
|
268
|
+
this._drawVintageFrame(width, height, cornerRadius);
|
|
269
|
+
break;
|
|
270
|
+
case FrameStyle.FUTURISTIC:
|
|
271
|
+
this._drawFuturisticFrame(width, height, cornerRadius);
|
|
272
|
+
break;
|
|
273
|
+
}
|
|
274
|
+
}
|
|
275
|
+
|
|
276
|
+
_drawHolographicFrame(width, height, radius) {
|
|
277
|
+
const gradient = this.ctx.createLinearGradient(0, 0, width, height);
|
|
278
|
+
gradient.addColorStop(0, '#ff00ff');
|
|
279
|
+
gradient.addColorStop(0.25, '#00ffff');
|
|
280
|
+
gradient.addColorStop(0.5, '#ffff00');
|
|
281
|
+
gradient.addColorStop(0.75, '#ff00ff');
|
|
282
|
+
gradient.addColorStop(1, '#00ffff');
|
|
283
|
+
|
|
284
|
+
this.ctx.strokeStyle = gradient;
|
|
285
|
+
this._roundedRect(10, 10, width - 20, height - 20, radius);
|
|
286
|
+
this.ctx.stroke();
|
|
287
|
+
|
|
288
|
+
// Inner glow
|
|
289
|
+
this.ctx.shadowColor = '#ff00ff';
|
|
290
|
+
this.ctx.shadowBlur = 15;
|
|
291
|
+
this.ctx.stroke();
|
|
292
|
+
this.ctx.shadowBlur = 0;
|
|
293
|
+
}
|
|
294
|
+
|
|
295
|
+
_drawQuantumFrame(width, height, radius) {
|
|
296
|
+
const gradient = this.ctx.createLinearGradient(0, 0, width, height);
|
|
297
|
+
gradient.addColorStop(0, '#00ff88');
|
|
298
|
+
gradient.addColorStop(0.5, '#0088ff');
|
|
299
|
+
gradient.addColorStop(1, '#8800ff');
|
|
300
|
+
|
|
301
|
+
this.ctx.strokeStyle = gradient;
|
|
302
|
+
this._roundedRect(10, 10, width - 20, height - 20, radius);
|
|
303
|
+
this.ctx.stroke();
|
|
304
|
+
|
|
305
|
+
// Quantum particles effect
|
|
306
|
+
this.ctx.fillStyle = '#00ffff';
|
|
307
|
+
for (let i = 0; i < 20; i++) {
|
|
308
|
+
const x = Math.random() * width;
|
|
309
|
+
const y = Math.random() * height;
|
|
310
|
+
this.ctx.beginPath();
|
|
311
|
+
this.ctx.arc(x, y, 2, 0, Math.PI * 2);
|
|
312
|
+
this.ctx.fill();
|
|
313
|
+
}
|
|
314
|
+
}
|
|
315
|
+
|
|
316
|
+
_drawFacetedFrame(width, height, radius) {
|
|
317
|
+
const gradient = this.ctx.createLinearGradient(0, 0, width, height);
|
|
318
|
+
gradient.addColorStop(0, '#ff4444');
|
|
319
|
+
gradient.addColorStop(0.33, '#44ff44');
|
|
320
|
+
gradient.addColorStop(0.66, '#4444ff');
|
|
321
|
+
gradient.addColorStop(1, '#ff4444');
|
|
322
|
+
|
|
323
|
+
this.ctx.strokeStyle = gradient;
|
|
324
|
+
|
|
325
|
+
// Draw angular frame
|
|
326
|
+
this.ctx.beginPath();
|
|
327
|
+
const inset = 15;
|
|
328
|
+
const cut = 30;
|
|
329
|
+
this.ctx.moveTo(inset + cut, inset);
|
|
330
|
+
this.ctx.lineTo(width - inset - cut, inset);
|
|
331
|
+
this.ctx.lineTo(width - inset, inset + cut);
|
|
332
|
+
this.ctx.lineTo(width - inset, height - inset - cut);
|
|
333
|
+
this.ctx.lineTo(width - inset - cut, height - inset);
|
|
334
|
+
this.ctx.lineTo(inset + cut, height - inset);
|
|
335
|
+
this.ctx.lineTo(inset, height - inset - cut);
|
|
336
|
+
this.ctx.lineTo(inset, inset + cut);
|
|
337
|
+
this.ctx.closePath();
|
|
338
|
+
this.ctx.stroke();
|
|
339
|
+
}
|
|
340
|
+
|
|
341
|
+
_drawSimpleFrame(width, height, radius) {
|
|
342
|
+
this.ctx.strokeStyle = '#ffffff';
|
|
343
|
+
this._roundedRect(10, 10, width - 20, height - 20, radius);
|
|
344
|
+
this.ctx.stroke();
|
|
345
|
+
}
|
|
346
|
+
|
|
347
|
+
_drawVintageFrame(width, height, radius) {
|
|
348
|
+
this.ctx.strokeStyle = '#d4af37';
|
|
349
|
+
this.ctx.lineWidth = 25;
|
|
350
|
+
this._roundedRect(12, 12, width - 24, height - 24, radius);
|
|
351
|
+
this.ctx.stroke();
|
|
352
|
+
|
|
353
|
+
this.ctx.strokeStyle = '#8b7355';
|
|
354
|
+
this.ctx.lineWidth = 15;
|
|
355
|
+
this._roundedRect(12, 12, width - 24, height - 24, radius);
|
|
356
|
+
this.ctx.stroke();
|
|
357
|
+
}
|
|
358
|
+
|
|
359
|
+
_drawFuturisticFrame(width, height, radius) {
|
|
360
|
+
const gradient = this.ctx.createLinearGradient(0, 0, width, height);
|
|
361
|
+
gradient.addColorStop(0, '#00ffff');
|
|
362
|
+
gradient.addColorStop(1, '#ff00ff');
|
|
363
|
+
|
|
364
|
+
this.ctx.strokeStyle = gradient;
|
|
365
|
+
this.ctx.lineWidth = 3;
|
|
366
|
+
|
|
367
|
+
// Outer frame
|
|
368
|
+
this._roundedRect(5, 5, width - 10, height - 10, radius);
|
|
369
|
+
this.ctx.stroke();
|
|
370
|
+
|
|
371
|
+
// Inner frame
|
|
372
|
+
this._roundedRect(15, 15, width - 30, height - 30, radius - 5);
|
|
373
|
+
this.ctx.stroke();
|
|
374
|
+
|
|
375
|
+
// Corner accents
|
|
376
|
+
this.ctx.lineWidth = 5;
|
|
377
|
+
const cornerSize = 40;
|
|
378
|
+
[[0, 0], [width, 0], [0, height], [width, height]].forEach(([cx, cy]) => {
|
|
379
|
+
this.ctx.beginPath();
|
|
380
|
+
this.ctx.moveTo(cx === 0 ? 5 : width - 5, cy === 0 ? 5 : height - 5);
|
|
381
|
+
this.ctx.lineTo(cx === 0 ? 5 + cornerSize : width - 5 - cornerSize, cy === 0 ? 5 : height - 5);
|
|
382
|
+
this.ctx.moveTo(cx === 0 ? 5 : width - 5, cy === 0 ? 5 : height - 5);
|
|
383
|
+
this.ctx.lineTo(cx === 0 ? 5 : width - 5, cy === 0 ? 5 + cornerSize : height - 5 - cornerSize);
|
|
384
|
+
this.ctx.stroke();
|
|
385
|
+
});
|
|
386
|
+
}
|
|
387
|
+
|
|
388
|
+
/**
|
|
389
|
+
* Draw visualization from source canvas
|
|
390
|
+
*/
|
|
391
|
+
_drawVisualization() {
|
|
392
|
+
if (!this.sourceCanvas) return;
|
|
393
|
+
|
|
394
|
+
const { width, height } = this.config.size;
|
|
395
|
+
const padding = this.config.borderWidth + 20;
|
|
396
|
+
|
|
397
|
+
// Calculate visualization area (top 60% of card)
|
|
398
|
+
const vizWidth = width - padding * 2;
|
|
399
|
+
const vizHeight = (height - padding * 2) * 0.6;
|
|
400
|
+
|
|
401
|
+
// Draw with aspect ratio preservation
|
|
402
|
+
const sourceAspect = this.sourceCanvas.width / this.sourceCanvas.height;
|
|
403
|
+
const targetAspect = vizWidth / vizHeight;
|
|
404
|
+
|
|
405
|
+
let drawWidth, drawHeight, drawX, drawY;
|
|
406
|
+
|
|
407
|
+
if (sourceAspect > targetAspect) {
|
|
408
|
+
drawWidth = vizWidth;
|
|
409
|
+
drawHeight = vizWidth / sourceAspect;
|
|
410
|
+
drawX = padding;
|
|
411
|
+
drawY = padding + (vizHeight - drawHeight) / 2;
|
|
412
|
+
} else {
|
|
413
|
+
drawHeight = vizHeight;
|
|
414
|
+
drawWidth = vizHeight * sourceAspect;
|
|
415
|
+
drawX = padding + (vizWidth - drawWidth) / 2;
|
|
416
|
+
drawY = padding;
|
|
417
|
+
}
|
|
418
|
+
|
|
419
|
+
// Draw border for visualization area
|
|
420
|
+
this.ctx.fillStyle = '#000000';
|
|
421
|
+
this._roundedRect(padding, padding, vizWidth, vizHeight, 10);
|
|
422
|
+
this.ctx.fill();
|
|
423
|
+
|
|
424
|
+
// Draw the visualization
|
|
425
|
+
this.ctx.drawImage(this.sourceCanvas, drawX, drawY, drawWidth, drawHeight);
|
|
426
|
+
}
|
|
427
|
+
|
|
428
|
+
/**
|
|
429
|
+
* Draw card metadata (title, subtitle)
|
|
430
|
+
*/
|
|
431
|
+
_drawMetadata() {
|
|
432
|
+
const { width, height } = this.config.size;
|
|
433
|
+
const padding = this.config.borderWidth + 20;
|
|
434
|
+
|
|
435
|
+
// Title area (below visualization)
|
|
436
|
+
const titleY = height * 0.65;
|
|
437
|
+
|
|
438
|
+
// Title
|
|
439
|
+
this.ctx.fillStyle = '#ffffff';
|
|
440
|
+
this.ctx.font = 'bold 36px "Segoe UI", Arial, sans-serif';
|
|
441
|
+
this.ctx.textAlign = 'center';
|
|
442
|
+
this.ctx.fillText(this.metadata.title, width / 2, titleY);
|
|
443
|
+
|
|
444
|
+
// Subtitle
|
|
445
|
+
if (this.metadata.subtitle) {
|
|
446
|
+
this.ctx.fillStyle = '#aaaaaa';
|
|
447
|
+
this.ctx.font = '24px "Segoe UI", Arial, sans-serif';
|
|
448
|
+
this.ctx.fillText(this.metadata.subtitle, width / 2, titleY + 35);
|
|
449
|
+
}
|
|
450
|
+
|
|
451
|
+
// System badge
|
|
452
|
+
const systemColors = {
|
|
453
|
+
quantum: '#00ff88',
|
|
454
|
+
faceted: '#ff4488',
|
|
455
|
+
holographic: '#44aaff'
|
|
456
|
+
};
|
|
457
|
+
const systemColor = systemColors[this.metadata.system] || '#ffffff';
|
|
458
|
+
|
|
459
|
+
this.ctx.fillStyle = systemColor;
|
|
460
|
+
this.ctx.font = 'bold 18px "Segoe UI", Arial, sans-serif';
|
|
461
|
+
this.ctx.textAlign = 'left';
|
|
462
|
+
this.ctx.fillText(this.metadata.system.toUpperCase(), padding, height - padding - 60);
|
|
463
|
+
|
|
464
|
+
// Geometry & Variation info
|
|
465
|
+
this.ctx.fillStyle = '#888888';
|
|
466
|
+
this.ctx.font = '16px "Segoe UI", Arial, sans-serif';
|
|
467
|
+
this.ctx.fillText(`Geometry: ${this.metadata.geometry} | Variation: ${this.metadata.variation}`, padding, height - padding - 35);
|
|
468
|
+
}
|
|
469
|
+
|
|
470
|
+
/**
|
|
471
|
+
* Draw rarity indicator
|
|
472
|
+
*/
|
|
473
|
+
_drawRarity() {
|
|
474
|
+
const { width, height } = this.config.size;
|
|
475
|
+
const padding = this.config.borderWidth + 20;
|
|
476
|
+
const rarity = this.metadata.rarity;
|
|
477
|
+
|
|
478
|
+
// Rarity badge
|
|
479
|
+
const badgeX = width - padding - 100;
|
|
480
|
+
const badgeY = height - padding - 50;
|
|
481
|
+
const badgeWidth = 90;
|
|
482
|
+
const badgeHeight = 30;
|
|
483
|
+
|
|
484
|
+
// Badge background
|
|
485
|
+
this.ctx.fillStyle = rarity.color;
|
|
486
|
+
this._roundedRect(badgeX, badgeY, badgeWidth, badgeHeight, 5);
|
|
487
|
+
this.ctx.fill();
|
|
488
|
+
|
|
489
|
+
// Glow effect for rare+ cards
|
|
490
|
+
if (rarity.glow) {
|
|
491
|
+
this.ctx.shadowColor = rarity.color;
|
|
492
|
+
this.ctx.shadowBlur = 10;
|
|
493
|
+
this._roundedRect(badgeX, badgeY, badgeWidth, badgeHeight, 5);
|
|
494
|
+
this.ctx.fill();
|
|
495
|
+
this.ctx.shadowBlur = 0;
|
|
496
|
+
}
|
|
497
|
+
|
|
498
|
+
// Rarity text
|
|
499
|
+
this.ctx.fillStyle = '#ffffff';
|
|
500
|
+
this.ctx.font = 'bold 14px "Segoe UI", Arial, sans-serif';
|
|
501
|
+
this.ctx.textAlign = 'center';
|
|
502
|
+
this.ctx.fillText(rarity.name.toUpperCase(), badgeX + badgeWidth / 2, badgeY + 20);
|
|
503
|
+
}
|
|
504
|
+
|
|
505
|
+
/**
|
|
506
|
+
* Draw stats (if enabled)
|
|
507
|
+
*/
|
|
508
|
+
_drawStats() {
|
|
509
|
+
const { width, height } = this.config.size;
|
|
510
|
+
const padding = this.config.borderWidth + 20;
|
|
511
|
+
const stats = this.metadata.stats;
|
|
512
|
+
|
|
513
|
+
if (!stats || Object.keys(stats).length === 0) return;
|
|
514
|
+
|
|
515
|
+
// Stats area
|
|
516
|
+
const statsY = height * 0.72;
|
|
517
|
+
const statWidth = (width - padding * 2) / Object.keys(stats).length;
|
|
518
|
+
|
|
519
|
+
this.ctx.textAlign = 'center';
|
|
520
|
+
let x = padding + statWidth / 2;
|
|
521
|
+
|
|
522
|
+
for (const [key, value] of Object.entries(stats)) {
|
|
523
|
+
// Stat value
|
|
524
|
+
this.ctx.fillStyle = '#00ffff';
|
|
525
|
+
this.ctx.font = 'bold 28px "Segoe UI", Arial, sans-serif';
|
|
526
|
+
this.ctx.fillText(String(value), x, statsY);
|
|
527
|
+
|
|
528
|
+
// Stat name
|
|
529
|
+
this.ctx.fillStyle = '#888888';
|
|
530
|
+
this.ctx.font = '14px "Segoe UI", Arial, sans-serif';
|
|
531
|
+
this.ctx.fillText(key.toUpperCase(), x, statsY + 20);
|
|
532
|
+
|
|
533
|
+
x += statWidth;
|
|
534
|
+
}
|
|
535
|
+
}
|
|
536
|
+
|
|
537
|
+
/**
|
|
538
|
+
* Draw rounded rectangle path
|
|
539
|
+
*/
|
|
540
|
+
_roundedRect(x, y, width, height, radius) {
|
|
541
|
+
this.ctx.beginPath();
|
|
542
|
+
this.ctx.moveTo(x + radius, y);
|
|
543
|
+
this.ctx.lineTo(x + width - radius, y);
|
|
544
|
+
this.ctx.quadraticCurveTo(x + width, y, x + width, y + radius);
|
|
545
|
+
this.ctx.lineTo(x + width, y + height - radius);
|
|
546
|
+
this.ctx.quadraticCurveTo(x + width, y + height, x + width - radius, y + height);
|
|
547
|
+
this.ctx.lineTo(x + radius, y + height);
|
|
548
|
+
this.ctx.quadraticCurveTo(x, y + height, x, y + height - radius);
|
|
549
|
+
this.ctx.lineTo(x, y + radius);
|
|
550
|
+
this.ctx.quadraticCurveTo(x, y, x + radius, y);
|
|
551
|
+
this.ctx.closePath();
|
|
552
|
+
}
|
|
553
|
+
|
|
554
|
+
/**
|
|
555
|
+
* Convert canvas to blob
|
|
556
|
+
*/
|
|
557
|
+
async _canvasToBlob(format) {
|
|
558
|
+
const mimeType = `image/${format}`;
|
|
559
|
+
|
|
560
|
+
if (this.exportCanvas instanceof OffscreenCanvas) {
|
|
561
|
+
return await this.exportCanvas.convertToBlob({
|
|
562
|
+
type: mimeType,
|
|
563
|
+
quality: this.config.quality
|
|
564
|
+
});
|
|
565
|
+
}
|
|
566
|
+
|
|
567
|
+
return new Promise(resolve => {
|
|
568
|
+
this.exportCanvas.toBlob(resolve, mimeType, this.config.quality);
|
|
569
|
+
});
|
|
570
|
+
}
|
|
571
|
+
|
|
572
|
+
/**
|
|
573
|
+
* Get card as data URL
|
|
574
|
+
*/
|
|
575
|
+
async getDataURL(format = 'png') {
|
|
576
|
+
await this.exportCard(format);
|
|
577
|
+
return this.exportCanvas.toDataURL(`image/${format}`, this.config.quality);
|
|
578
|
+
}
|
|
579
|
+
|
|
580
|
+
/**
|
|
581
|
+
* Serialize configuration
|
|
582
|
+
*/
|
|
583
|
+
toJSON() {
|
|
584
|
+
return {
|
|
585
|
+
config: this.config,
|
|
586
|
+
metadata: this.metadata
|
|
587
|
+
};
|
|
588
|
+
}
|
|
589
|
+
|
|
590
|
+
/**
|
|
591
|
+
* Restore from serialized state
|
|
592
|
+
*/
|
|
593
|
+
fromJSON(data) {
|
|
594
|
+
if (data.config) Object.assign(this.config, data.config);
|
|
595
|
+
if (data.metadata) Object.assign(this.metadata, data.metadata);
|
|
596
|
+
this.setSize(this.config.size);
|
|
597
|
+
}
|
|
598
|
+
}
|
|
599
|
+
|
|
600
|
+
export default TradingCardExporter;
|