@omrips/viewstl 2.0.0-rc.8 → 2.0.0-rc.9

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.
@@ -426,59 +426,109 @@ export class StlViewer {
426
426
  }
427
427
  export default StlViewer;
428
428
 
429
- export interface ViewstlAppOptions {
430
- /** Composed with the app's own playback controls and reduced-motion policy. */
431
- animation_state_callback?: ViewerOptions["animation_state_callback"];
432
- animation_complete_callback?: ViewerOptions["animation_complete_callback"];
433
- url_import_endpoint?: string;
434
- worker_url?: string | URL;
435
- worker_factory?: () => Worker;
436
- worker_timeout?: number;
437
- /** Optional sample URL; omit to hide the sample button. */
438
- sample_url?: string;
439
- sample_name?: string;
440
- /** Prefix used by this root's control IDs and associated label/ARIA references. */
441
- id_prefix?: string;
442
- }
443
- export interface ViewstlAppState {
444
- selectedId: number | null;
445
- busy: boolean;
446
- arrangement: string;
447
- memoryBudget: number;
448
- models: Array<{
449
- id: number;
450
- name: string;
451
- size?: number;
452
- units: string | null;
453
- position: Vector3;
454
- /** Euler XYZ angles in degrees, about the model's own center. */
455
- rotation: Vector3;
456
- color: string | null;
457
- animation: AnimationPlaybackState;
458
- }>;
429
+ export type SessionArrangement = "original" | "side-by-side" | "custom";
430
+ export interface SessionModel {
431
+ id: number;
432
+ name: string;
433
+ size: number | null;
434
+ units: string | null;
435
+ bounds: { min: number[]; max: number[] };
436
+ position: Vector3;
437
+ /** Euler XYZ in degrees, rotated around the model center. */
438
+ rotation: Vector3;
439
+ originalPosition: Vector3;
440
+ originalRotation: Vector3;
441
+ embedded: boolean;
442
+ color: string | null;
443
+ originalColor: string | null;
444
+ animationPivot?: boolean;
445
+ animation: AnimationPlaybackState | null;
446
+ animationDefinition: Animation | null;
447
+ }
448
+ export type SessionEvent =
449
+ | { type: "ready" }
450
+ | { type: "busy"; busy: boolean }
451
+ | { type: "opening" | "load-failed"; name: string }
452
+ | { type: "loaded"; name: string; id: number }
453
+ | { type: "scene-loaded"; name: string; ids: number[] }
454
+ | { type: "error"; code: string; message: string; source?: string }
455
+ | {
456
+ type: "animation";
457
+ id: number;
458
+ state: AnimationPlaybackState;
459
+ reason: AnimationStateReason;
460
+ }
461
+ | {
462
+ type: "progress";
463
+ scene: boolean;
464
+ progress: { phase?: string; loaded?: number; total?: number };
465
+ };
466
+ export interface ViewerSessionOptions {
467
+ /** Initial models are added through openFiles/openURL, not viewer_options. */
468
+ viewer_options?: Omit<ViewerOptions, "models" | "allow_drag_and_drop">;
469
+ device_memory?: number;
470
+ /** Optional fallback colors for models with no embedded colors. */
471
+ colors?: string[];
472
+ on_event?: (event: SessionEvent) => void;
473
+ }
474
+ export interface ManipulationOptions {
475
+ /** Event is absent for wheel input. Return null to ignore an empty hit. */
476
+ getModelId(event?: PointerEvent): number | null;
477
+ getTool(): "move" | "rotate" | "depth";
478
+ onChange?(id: number): void;
479
+ onStart?(id: number): void;
480
+ onEnd?(id: number, cancelled: boolean): void;
481
+ }
482
+ export interface ManipulationBinding {
483
+ setEnabled(enabled: boolean): void;
484
+ dispose(): void;
459
485
  }
460
- export interface ViewstlApp {
461
- openURL(url: string, format?: ModelOptions["remote_format"]): Promise<void>;
462
- /** Adds files to the scene; settles when the queue drains or is cancelled.
463
- * Per-file errors appear in the app notice and preserve existing models. */
486
+ /** UI-independent queue/scene/editor session. Mounting creates no WebGL context.
487
+ * Use viewer for existing rendering, saving, analysis, resize and camera APIs.
488
+ * Methods taking angles use degrees; StlViewer's original methods retain radians.
489
+ */
490
+ export class ViewerSession {
491
+ constructor(container: HTMLElement, options?: ViewerSessionOptions);
492
+ readonly viewer: StlViewer | null;
493
+ readonly busy: boolean;
494
+ readonly arrangement: SessionArrangement;
495
+ readonly grid: { enabled: boolean; spacing: number; height: number };
496
+ readonly memoryPolicy: {
497
+ budget: number;
498
+ estimated: number;
499
+ reported: boolean;
500
+ limits: {
501
+ max_memory_bytes: number;
502
+ max_file_bytes: number;
503
+ max_triangles: number;
504
+ max_uncompressed_bytes: number;
505
+ };
506
+ };
507
+ ready(): Promise<StlViewer>;
464
508
  openFiles(
465
509
  files: Iterable<File | { name: string; url: string; size?: number }>,
466
510
  ): Promise<void>;
511
+ openURL(
512
+ url: string,
513
+ format?: ModelOptions["remote_format"] | "vsb" | "vsj",
514
+ ): Promise<void>;
467
515
  cancelLoading(): void;
468
- clear(): void;
469
- select(id: number): void;
516
+ /** Detached constant-size metadata; no geometry copies or mesh scans. */
517
+ getModel(id: number): SessionModel | null;
518
+ getModels(): SessionModel[];
519
+ setPosition(id: number, position: Vector3): boolean;
520
+ setRotation(id: number, degrees: Vector3): boolean;
521
+ prepareManual(id: number): void;
522
+ centerPivot(id: number): void;
523
+ moveDepth(id: number, amount: number): boolean;
524
+ bindManipulation(options: ManipulationOptions): ManipulationBinding;
525
+ setArrangement(mode: SessionArrangement): void;
526
+ setGrid(enabled: boolean, spacing?: number, height?: number): void;
527
+ duplicate(id: number): number;
470
528
  remove(id: number): void;
471
- /** Detached state snapshot; changing it never mutates the scene. */
472
- getState(): ViewstlAppState;
473
- /** Cancels pending work and releases listeners, workers, and WebGL resources. */
529
+ clear(): void;
474
530
  dispose(): void;
475
531
  }
476
- /** Optional complete app controller for the documented HTML control template.
477
- * No WebGL context, workers or CAD assets are created until a file is opened. */
478
- export function mountViewstlApp(
479
- root: Document | HTMLElement,
480
- options?: ViewstlAppOptions,
481
- ): ViewstlApp;
482
532
 
483
533
  export interface PrintProfile {
484
534
  technology: "fdm";
@@ -426,59 +426,109 @@ export class StlViewer {
426
426
  }
427
427
  export default StlViewer;
428
428
 
429
- export interface ViewstlAppOptions {
430
- /** Composed with the app's own playback controls and reduced-motion policy. */
431
- animation_state_callback?: ViewerOptions["animation_state_callback"];
432
- animation_complete_callback?: ViewerOptions["animation_complete_callback"];
433
- url_import_endpoint?: string;
434
- worker_url?: string | URL;
435
- worker_factory?: () => Worker;
436
- worker_timeout?: number;
437
- /** Optional sample URL; omit to hide the sample button. */
438
- sample_url?: string;
439
- sample_name?: string;
440
- /** Prefix used by this root's control IDs and associated label/ARIA references. */
441
- id_prefix?: string;
442
- }
443
- export interface ViewstlAppState {
444
- selectedId: number | null;
445
- busy: boolean;
446
- arrangement: string;
447
- memoryBudget: number;
448
- models: Array<{
449
- id: number;
450
- name: string;
451
- size?: number;
452
- units: string | null;
453
- position: Vector3;
454
- /** Euler XYZ angles in degrees, about the model's own center. */
455
- rotation: Vector3;
456
- color: string | null;
457
- animation: AnimationPlaybackState;
458
- }>;
429
+ export type SessionArrangement = "original" | "side-by-side" | "custom";
430
+ export interface SessionModel {
431
+ id: number;
432
+ name: string;
433
+ size: number | null;
434
+ units: string | null;
435
+ bounds: { min: number[]; max: number[] };
436
+ position: Vector3;
437
+ /** Euler XYZ in degrees, rotated around the model center. */
438
+ rotation: Vector3;
439
+ originalPosition: Vector3;
440
+ originalRotation: Vector3;
441
+ embedded: boolean;
442
+ color: string | null;
443
+ originalColor: string | null;
444
+ animationPivot?: boolean;
445
+ animation: AnimationPlaybackState | null;
446
+ animationDefinition: Animation | null;
447
+ }
448
+ export type SessionEvent =
449
+ | { type: "ready" }
450
+ | { type: "busy"; busy: boolean }
451
+ | { type: "opening" | "load-failed"; name: string }
452
+ | { type: "loaded"; name: string; id: number }
453
+ | { type: "scene-loaded"; name: string; ids: number[] }
454
+ | { type: "error"; code: string; message: string; source?: string }
455
+ | {
456
+ type: "animation";
457
+ id: number;
458
+ state: AnimationPlaybackState;
459
+ reason: AnimationStateReason;
460
+ }
461
+ | {
462
+ type: "progress";
463
+ scene: boolean;
464
+ progress: { phase?: string; loaded?: number; total?: number };
465
+ };
466
+ export interface ViewerSessionOptions {
467
+ /** Initial models are added through openFiles/openURL, not viewer_options. */
468
+ viewer_options?: Omit<ViewerOptions, "models" | "allow_drag_and_drop">;
469
+ device_memory?: number;
470
+ /** Optional fallback colors for models with no embedded colors. */
471
+ colors?: string[];
472
+ on_event?: (event: SessionEvent) => void;
473
+ }
474
+ export interface ManipulationOptions {
475
+ /** Event is absent for wheel input. Return null to ignore an empty hit. */
476
+ getModelId(event?: PointerEvent): number | null;
477
+ getTool(): "move" | "rotate" | "depth";
478
+ onChange?(id: number): void;
479
+ onStart?(id: number): void;
480
+ onEnd?(id: number, cancelled: boolean): void;
481
+ }
482
+ export interface ManipulationBinding {
483
+ setEnabled(enabled: boolean): void;
484
+ dispose(): void;
459
485
  }
460
- export interface ViewstlApp {
461
- openURL(url: string, format?: ModelOptions["remote_format"]): Promise<void>;
462
- /** Adds files to the scene; settles when the queue drains or is cancelled.
463
- * Per-file errors appear in the app notice and preserve existing models. */
486
+ /** UI-independent queue/scene/editor session. Mounting creates no WebGL context.
487
+ * Use viewer for existing rendering, saving, analysis, resize and camera APIs.
488
+ * Methods taking angles use degrees; StlViewer's original methods retain radians.
489
+ */
490
+ export class ViewerSession {
491
+ constructor(container: HTMLElement, options?: ViewerSessionOptions);
492
+ readonly viewer: StlViewer | null;
493
+ readonly busy: boolean;
494
+ readonly arrangement: SessionArrangement;
495
+ readonly grid: { enabled: boolean; spacing: number; height: number };
496
+ readonly memoryPolicy: {
497
+ budget: number;
498
+ estimated: number;
499
+ reported: boolean;
500
+ limits: {
501
+ max_memory_bytes: number;
502
+ max_file_bytes: number;
503
+ max_triangles: number;
504
+ max_uncompressed_bytes: number;
505
+ };
506
+ };
507
+ ready(): Promise<StlViewer>;
464
508
  openFiles(
465
509
  files: Iterable<File | { name: string; url: string; size?: number }>,
466
510
  ): Promise<void>;
511
+ openURL(
512
+ url: string,
513
+ format?: ModelOptions["remote_format"] | "vsb" | "vsj",
514
+ ): Promise<void>;
467
515
  cancelLoading(): void;
468
- clear(): void;
469
- select(id: number): void;
516
+ /** Detached constant-size metadata; no geometry copies or mesh scans. */
517
+ getModel(id: number): SessionModel | null;
518
+ getModels(): SessionModel[];
519
+ setPosition(id: number, position: Vector3): boolean;
520
+ setRotation(id: number, degrees: Vector3): boolean;
521
+ prepareManual(id: number): void;
522
+ centerPivot(id: number): void;
523
+ moveDepth(id: number, amount: number): boolean;
524
+ bindManipulation(options: ManipulationOptions): ManipulationBinding;
525
+ setArrangement(mode: SessionArrangement): void;
526
+ setGrid(enabled: boolean, spacing?: number, height?: number): void;
527
+ duplicate(id: number): number;
470
528
  remove(id: number): void;
471
- /** Detached state snapshot; changing it never mutates the scene. */
472
- getState(): ViewstlAppState;
473
- /** Cancels pending work and releases listeners, workers, and WebGL resources. */
529
+ clear(): void;
474
530
  dispose(): void;
475
531
  }
476
- /** Optional complete app controller for the documented HTML control template.
477
- * No WebGL context, workers or CAD assets are created until a file is opened. */
478
- export function mountViewstlApp(
479
- root: Document | HTMLElement,
480
- options?: ViewstlAppOptions,
481
- ): ViewstlApp;
482
532
 
483
533
  export interface PrintProfile {
484
534
  technology: "fdm";