string-tune-3d 0.0.6 → 0.0.7

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/dist/index.d.mts CHANGED
@@ -1,5 +1,63 @@
1
1
  import { StringModule, StringContext, StringObject, StringData } from '@fiddle-digital/string-tune';
2
2
 
3
+ type UniformType = "float" | "int" | "vec2" | "vec3" | "vec4" | "color" | "texture" | "mat3" | "mat4";
4
+ type UniformDefinition = {
5
+ type: UniformType;
6
+ value: any;
7
+ css?: string;
8
+ };
9
+ type ShaderInjectionPoint = "vertex_pars" | "vertex_header" | "vertex_transform" | "vertex_output" | "fragment_pars" | "fragment_header" | "fragment_color" | "fragment_normal" | "fragment_emissive" | "fragment_output";
10
+ type ShaderInjection = {
11
+ point: ShaderInjectionPoint;
12
+ code: string;
13
+ order?: number;
14
+ };
15
+ type MaterialBlendMode = "normal" | "additive" | "subtractive" | "multiply";
16
+ type MaterialSide = "front" | "back" | "double";
17
+ type String3DCustomMaterialDefinition = {
18
+ name: string;
19
+ extends?: "basic" | "standard" | "physical" | "shader";
20
+ vertexShader?: string;
21
+ fragmentShader?: string;
22
+ injections?: ShaderInjection[];
23
+ uniforms?: Record<string, UniformDefinition>;
24
+ properties?: {
25
+ transparent?: boolean;
26
+ side?: MaterialSide;
27
+ depthWrite?: boolean;
28
+ depthTest?: boolean;
29
+ blending?: MaterialBlendMode;
30
+ wireframe?: boolean;
31
+ };
32
+ lights?: boolean;
33
+ parse?: (element: HTMLElement, style: CSSStyleDeclaration) => Record<string, any>;
34
+ };
35
+ declare class String3DCustomMaterialRegistry {
36
+ private static materials;
37
+ private static registeredCssVars;
38
+ static register(definition: String3DCustomMaterialDefinition): void;
39
+ private static registerCssVarsForMaterial;
40
+ private static resolveCssSyntax;
41
+ private static defaultCssInitialValue;
42
+ static get(name: string): String3DCustomMaterialDefinition | undefined;
43
+ static has(name: string): boolean;
44
+ static list(): String3DCustomMaterialDefinition[];
45
+ static unregister(name: string): boolean;
46
+ }
47
+
48
+ type MaterialUpdateCallback = (uniforms: Record<string, any>) => void;
49
+ interface IMaterialInstance {
50
+ material: any;
51
+ definition: String3DCustomMaterialDefinition;
52
+ update: MaterialUpdateCallback;
53
+ dispose: () => void;
54
+ }
55
+ interface IMaterialFactory {
56
+ supports(definition: String3DCustomMaterialDefinition): boolean;
57
+ create(definition: String3DCustomMaterialDefinition, initialUniforms?: Record<string, any>): IMaterialInstance;
58
+ parseUniformsFromCSS(definition: String3DCustomMaterialDefinition, element: HTMLElement, style: CSSStyleDeclaration): Record<string, any>;
59
+ }
60
+
3
61
  interface I3DVector3 {
4
62
  x: number;
5
63
  y: number;
@@ -81,6 +139,52 @@ interface I3DRenderTarget {
81
139
  setSize(width: number, height: number): void;
82
140
  dispose(): void;
83
141
  }
142
+ type ParticleMode = "emitter" | "instanced";
143
+ type ParticleSystemConfig = {
144
+ mode: ParticleMode;
145
+ count: number;
146
+ size: number;
147
+ color: string;
148
+ opacity: number;
149
+ spread: number;
150
+ seed: number;
151
+ emitRate: number;
152
+ emitBurst: number;
153
+ particleLife: number;
154
+ particleSpeed: number;
155
+ particleDirection: [number, number, number];
156
+ particleGravity: [number, number, number];
157
+ particleDrag: number;
158
+ particleSizeVariation: number;
159
+ particleColorVariation: number;
160
+ particleShape: "box" | "sphere" | "model";
161
+ particleModelUrl: string;
162
+ particleModelLoader: string;
163
+ particleModelNode: string;
164
+ instanceShape: "box" | "sphere" | "model";
165
+ instanceModelUrl: string;
166
+ instanceModelLoader: string;
167
+ instanceModelNode: string;
168
+ instanceScale: number;
169
+ instanceScaleVariation: number;
170
+ instanceRotationSpeed: number;
171
+ instanceJitter: number;
172
+ instanceFlow: number;
173
+ instanceDisperse: number;
174
+ instanceDisperseScatter: number;
175
+ instanceDisperseScatterX: number;
176
+ instanceDisperseScatterY: number;
177
+ instanceDisperseScatterZ: number;
178
+ };
179
+ interface I3DParticleSystem extends I3DObject {
180
+ update?(dt: number): void;
181
+ setConfig?(config: ParticleSystemConfig): void;
182
+ setMaterial?(material: I3DMaterial | null, options?: {
183
+ points?: boolean;
184
+ meshes?: boolean;
185
+ }): void;
186
+ dispose?(): void;
187
+ }
84
188
  interface I3DLight extends I3DObject {
85
189
  color: any;
86
190
  intensity: number;
@@ -131,6 +235,25 @@ interface I3DRenderer {
131
235
  interface I3DTextureLoader {
132
236
  load(url: string, onLoad?: (texture: any) => void): any;
133
237
  }
238
+ type TextGeometryOptions = {
239
+ size: number;
240
+ height: number;
241
+ curveSegments: number;
242
+ bevelEnabled: boolean;
243
+ bevelThickness: number;
244
+ bevelSize: number;
245
+ bevelOffset: number;
246
+ bevelSegments: number;
247
+ lineHeight: number;
248
+ letterSpacing: number;
249
+ align: "left" | "center" | "right";
250
+ layout?: Array<{
251
+ char: string;
252
+ x: number;
253
+ y: number;
254
+ scale?: number;
255
+ }>;
256
+ };
134
257
  interface I3DModelLoader {
135
258
  load(url: string, onLoad?: (model: any) => void, onProgress?: (progress: any) => void, onError?: (error: any) => void): void;
136
259
  }
@@ -166,6 +289,11 @@ interface I3DEngine {
166
289
  createTextureLoader(): I3DTextureLoader;
167
290
  createModelLoader(type: string): I3DModelLoader;
168
291
  createRenderTarget?(width: number, height: number, options?: any): I3DRenderTarget;
292
+ getMaterialFactory?(): IMaterialFactory | null;
293
+ createParticleSystem?(config: ParticleSystemConfig): I3DParticleSystem;
294
+ loadFont?(url: string): Promise<any>;
295
+ createTextGeometry?(text: string, font: any, options: TextGeometryOptions): I3DGeometry | null;
296
+ simplifyGeometry?(geometry: I3DGeometry, quality: number): I3DGeometry | null;
169
297
  degToRad(degrees: number): number;
170
298
  radToDeg(radians: number): number;
171
299
  computeBoundingBoxRecursively(object: I3DObject): I3DBox3;
@@ -184,8 +312,8 @@ interface String3DOptions {
184
312
  modelLoader?: I3DModelLoader;
185
313
  modelLoaderFactory?: (engine: I3DEngine, type?: string) => I3DModelLoader;
186
314
  useDirtySync?: boolean;
187
- useTransformWorker?: boolean;
188
- transformWorkerWasmUrl?: string;
315
+ styleReadIntervalMs?: number;
316
+ layoutReadIntervalMs?: number;
189
317
  }
190
318
  declare class String3D extends StringModule {
191
319
  private static provider;
@@ -198,21 +326,14 @@ declare class String3D extends StringModule {
198
326
  private isLoading;
199
327
  private options;
200
328
  private useDirtySync;
201
- private dirtyElements;
202
- private observedElements;
203
- private resizeObserver;
204
- private mutationObserver;
329
+ private dirtySyncManager;
205
330
  private lastSyncData;
206
- private transformWorker;
207
- private workerHasResult;
208
- private workerObjectMap;
209
- private domVersion;
210
- private lastSubmittedVersion;
211
- private scrollTicking;
212
- private onScrollBound;
213
- private filterStates;
214
- private filterWarnings;
331
+ private filterController;
215
332
  static setProvider(provider: I3DEngineProvider): void;
333
+ static registerFont(name: string, url: string, options?: {
334
+ default?: boolean;
335
+ }): void;
336
+ static setDefaultFont(name: string): void;
216
337
  constructor(context: StringContext);
217
338
  canConnect(object: StringObject): boolean;
218
339
  initializeObject(globalId: number, object: StringObject, element: HTMLElement, attributes: Record<string, any>): void;
@@ -227,43 +348,10 @@ declare class String3D extends StringModule {
227
348
  private applyContainerStyles;
228
349
  onObjectConnected(object: StringObject): void;
229
350
  onFrame(data: StringData): void;
351
+ private batchReadLayouts;
230
352
  private syncRecursive;
231
353
  private injectCSS;
232
354
  private registerTypedProperties;
233
- private setupObservers;
234
- private setupScrollListeners;
235
- private removeScrollListeners;
236
- private handleScroll;
237
- private observeElement;
238
- private observeSceneElements;
239
- private observeRecursive;
240
- private markDirty;
241
- private markAllDirty;
242
- private readNumberStyle;
243
- private readFilterRaw;
244
- private parseFilterChain;
245
- private warnFilterIssues;
246
- private readFilterChain;
247
- private collectFilterTargets;
248
- private stringifyFilterChain;
249
- private getFilterTransition;
250
- private splitTransitionList;
251
- private findTransitionIndex;
252
- private parseTime;
253
- private parseTransitionShorthand;
254
- private parseEasing;
255
- private cubicBezier;
256
- private canInterpolate;
257
- private makeZeroChain;
258
- private sampleTransition;
259
- private getCurrentChain;
260
- private interpolateChain;
261
- private interpolateEffect;
262
- private isNumeric;
263
- private isZeroChain;
264
- private buildWorkerCameraData;
265
- private collectWorkerInputs;
266
- private applyWorkerResults;
267
355
  destroy(): void;
268
356
  }
269
357
 
@@ -356,6 +444,7 @@ declare class String3DScene {
356
444
  private _objects;
357
445
  private _rootObjects;
358
446
  private _elementMap;
447
+ private _materialInstances;
359
448
  private engine;
360
449
  private _modelLoader?;
361
450
  private _modelLoaderFactory?;
@@ -376,11 +465,17 @@ declare class String3DScene {
376
465
  private createPlane;
377
466
  private createCylinder;
378
467
  private createModel;
468
+ private createParticles;
469
+ private createText;
470
+ private getGeometryQuality;
379
471
  private resolveModelLoader;
380
472
  private centerObject;
381
473
  private getBoxCenter;
382
474
  private createMaterialFromObject;
383
475
  private createMaterialFromElement;
476
+ private tryCreateCustomMaterial;
477
+ updateMaterialUniforms(objectId: string, uniforms: Record<string, any>): void;
478
+ getMaterialInstance(objectId: string): IMaterialInstance | undefined;
384
479
  private loadTexture;
385
480
  private parseFlipY;
386
481
  private shouldOverrideModelMaterial;
@@ -477,8 +572,17 @@ declare class String3DSynchronizer {
477
572
  viewportHeight: number;
478
573
  engine: I3DEngine;
479
574
  private strategies;
575
+ private styleReadIntervalMs;
576
+ private layoutReadIntervalMs;
480
577
  constructor(camera: String3DCamera, viewportWidth: number, viewportHeight: number, engine: I3DEngine);
481
- syncElement(el: HTMLElement, object: String3DObject, parentData: any): any;
578
+ syncElement(el: HTMLElement, object: String3DObject, parentData: any, hints?: {
579
+ dirtySet?: Set<HTMLElement> | null;
580
+ forceSync?: boolean;
581
+ }): any;
582
+ setSyncOptions(options: {
583
+ styleReadIntervalMs?: number;
584
+ layoutReadIntervalMs?: number;
585
+ }): void;
482
586
  updateViewportSize(width: number, height: number): void;
483
587
  }
484
588
 
@@ -496,10 +600,68 @@ declare class String3DCustomFilterRegistry {
496
600
  static list(): String3DCustomFilterDefinition[];
497
601
  }
498
602
 
603
+ type String3DFontEntry = {
604
+ name: string;
605
+ url: string;
606
+ };
607
+ declare class String3DFontRegistry {
608
+ private static fonts;
609
+ private static defaultFont;
610
+ static register(name: string, url: string): void;
611
+ static setDefault(name: string): void;
612
+ static get(name: string): String3DFontEntry | undefined;
613
+ static list(): String3DFontEntry[];
614
+ static resolveFontFamily(fontFamily: string): String3DFontEntry | null;
615
+ private static getDefault;
616
+ }
617
+
618
+ interface FontData {
619
+ glyphs: Record<string, GlyphData>;
620
+ familyName: string;
621
+ ascender: number;
622
+ descender: number;
623
+ underlinePosition: number;
624
+ underlineThickness: number;
625
+ boundingBox: {
626
+ xMin: number;
627
+ xMax: number;
628
+ yMin: number;
629
+ yMax: number;
630
+ };
631
+ resolution: number;
632
+ original_font_information: Record<string, any>;
633
+ }
634
+ interface GlyphData {
635
+ ha: number;
636
+ x_min: number;
637
+ x_max: number;
638
+ o: string;
639
+ }
640
+ type FontSource = string | ArrayBuffer | Uint8Array;
641
+ declare class FontConverter {
642
+ private static cache;
643
+ private static loadingPromises;
644
+ static load(source: FontSource): Promise<FontData>;
645
+ private static doLoad;
646
+ private static convertToTypeFace;
647
+ private static pathToOutline;
648
+ private static round;
649
+ static isTypefaceJson(url: string): boolean;
650
+ static isFontFile(url: string): boolean;
651
+ static clearCache(): void;
652
+ }
653
+
499
654
  declare class ThreeJSEngine implements I3DEngine {
500
655
  private THREE;
501
656
  private loaders;
657
+ private materialFactory;
658
+ private particleModelCache;
659
+ private particleModelPromiseCache;
660
+ private fontCache;
661
+ private fontPromiseCache;
662
+ private fontMetricsCache;
502
663
  constructor(THREE: any, loaders?: Record<string, any>);
664
+ getMaterialFactory(): IMaterialFactory | null;
503
665
  createVector3(x?: number, y?: number, z?: number): I3DVector3;
504
666
  createVector2(x?: number, y?: number): I3DVector2;
505
667
  createQuaternion(x?: number, y?: number, z?: number, w?: number): I3DQuaternion;
@@ -531,6 +693,35 @@ declare class ThreeJSEngine implements I3DEngine {
531
693
  createTextureLoader(): I3DTextureLoader;
532
694
  createModelLoader(type: string): I3DModelLoader;
533
695
  createRenderTarget(width: number, height: number, options?: any): I3DRenderTarget;
696
+ loadFont(url: string): Promise<any>;
697
+ private loadFontWithConverter;
698
+ private loadFontWithLoader;
699
+ /**
700
+ * Create a Three.js-compatible Font object from FontData
701
+ */
702
+ private createFontFromData;
703
+ /**
704
+ * Generate Three.js Shapes from FontData for given text
705
+ * This generates shapes for a SINGLE character only (used by buildLineShapes)
706
+ */
707
+ private generateShapesFromFontData;
708
+ private parseOutlineToShapes;
709
+ private reversePath;
710
+ createTextGeometry(text: string, font: any, options: any): I3DGeometry | null;
711
+ private buildLineShapes;
712
+ private getGlyphAdvance;
713
+ private translateShape;
714
+ private scaleShape;
715
+ private buildGlyphShapesFromCanvas;
716
+ private measureFontMetrics;
717
+ private traceContoursFromAlpha;
718
+ private simplifyCollinear;
719
+ private simplifyRdp;
720
+ private pointLineDistance;
721
+ private contoursToShapes;
722
+ private resolveParticleModelGeometry;
723
+ createParticleSystem(config: ParticleSystemConfig): I3DParticleSystem;
724
+ simplifyGeometry(geometry: I3DGeometry, quality: number): I3DGeometry | null;
534
725
  degToRad(degrees: number): number;
535
726
  radToDeg(radians: number): number;
536
727
  computeBoundingBoxRecursively(object: I3DObject): I3DBox3;
@@ -542,4 +733,28 @@ declare class ThreeJSProvider implements I3DEngineProvider {
542
733
  getName(): string;
543
734
  }
544
735
 
545
- export { type CameraMode, type I3DBox3, type I3DCamera, type I3DEngine, type I3DEngineProvider, type I3DEuler, type I3DGeometry, type I3DLight, type I3DMaterial, type I3DMatrix4, type I3DMesh, type I3DModelLoader, type I3DObject, type I3DOrthographicCamera, type I3DPerspectiveCamera, type I3DQuaternion, type I3DRenderTarget, type I3DRenderer, type I3DScene, type I3DTextureLoader, type I3DVector2, type I3DVector3, String3D, String3DCamera, type String3DCustomFilterDefinition, String3DCustomFilterRegistry, String3DObject, type String3DOptions, String3DRenderer, String3DScene, String3DSynchronizer, ThreeJSEngine, ThreeJSProvider };
736
+ declare class ThreeJSMaterialFactory implements IMaterialFactory {
737
+ private THREE;
738
+ private textureLoader;
739
+ private textureCache;
740
+ constructor(THREE: any);
741
+ supports(definition: String3DCustomMaterialDefinition): boolean;
742
+ create(definition: String3DCustomMaterialDefinition, initialUniforms?: Record<string, any>): IMaterialInstance;
743
+ parseUniformsFromCSS(definition: String3DCustomMaterialDefinition, element: HTMLElement, style: CSSStyleDeclaration): Record<string, any>;
744
+ private buildUniforms;
745
+ private convertUniformValue;
746
+ private loadTexture;
747
+ private createShaderMaterial;
748
+ private createExtendedMaterial;
749
+ private injectVertexShader;
750
+ private injectFragmentShader;
751
+ private generateUniformDeclarations;
752
+ private inferGLSLType;
753
+ private applyMaterialProperties;
754
+ private updateUniforms;
755
+ private getDefaultVertexShader;
756
+ private getDefaultFragmentShader;
757
+ dispose(): void;
758
+ }
759
+
760
+ export { type CameraMode, FontConverter, type FontData, type FontSource, type I3DBox3, type I3DCamera, type I3DEngine, type I3DEngineProvider, type I3DEuler, type I3DGeometry, type I3DLight, type I3DMaterial, type I3DMatrix4, type I3DMesh, type I3DModelLoader, type I3DObject, type I3DOrthographicCamera, type I3DParticleSystem, type I3DPerspectiveCamera, type I3DQuaternion, type I3DRenderTarget, type I3DRenderer, type I3DScene, type I3DTextureLoader, type I3DVector2, type I3DVector3, type IMaterialFactory, type IMaterialInstance, type MaterialBlendMode, type MaterialSide, type ParticleMode, type ParticleSystemConfig, type ShaderInjection, type ShaderInjectionPoint, String3D, String3DCamera, type String3DCustomFilterDefinition, String3DCustomFilterRegistry, type String3DCustomMaterialDefinition, String3DCustomMaterialRegistry, type String3DFontEntry, String3DFontRegistry, String3DObject, type String3DOptions, String3DRenderer, String3DScene, String3DSynchronizer, ThreeJSEngine, ThreeJSMaterialFactory, ThreeJSProvider, type UniformDefinition, type UniformType };