pptx-svelte-viewer 3.22.0 → 4.1.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.
@@ -472,6 +472,8 @@ var n = {
472
472
  "pptx.collaboration.userCount": "{{count}} user(s)",
473
473
  "pptx.collaboration.youLabel": "{{name}} (you)",
474
474
  "pptx.collaboration.usersConnected": "{{count}} user(s) connected",
475
+ "pptx.collaboration.editable": "Editable",
476
+ "pptx.collaboration.shellStatusLabel": "Collaboration status",
475
477
  "pptx.collaboration.moreUsers": "{{count}} more user(s)",
476
478
  "pptx.collaboration.onePersonHere": "1 person here",
477
479
  "pptx.collaboration.peopleHere": "{{count}} people here",
@@ -12577,6 +12577,12 @@ interface ShapeAdjustmentHandleDescriptor {
12577
12577
  */
12578
12578
  solvers?: AdjustmentAxisSolver[];
12579
12579
  }
12580
+ interface CollaborationShellState {
12581
+ canEdit: boolean;
12582
+ status: ConnectionStatus;
12583
+ remoteUsers: readonly SanitizedPresence[];
12584
+ connectedCount: number;
12585
+ }
12580
12586
  //#endregion
12581
12587
  //#region src/render/collaboration-text-codec.d.ts
12582
12588
  /**
@@ -12601,6 +12607,62 @@ interface YTextLike {
12601
12607
  toString: () => string;
12602
12608
  }
12603
12609
  //#endregion
12610
+ //#region src/render/collaboration-text-merge.d.ts
12611
+ /** Y.Text surface needed for in-place edits (delete/format on top of insert). */
12612
+ interface YTextEditableLike extends YTextLike {
12613
+ delete: (index: number, length: number) => void;
12614
+ format: (index: number, length: number, attributes: Record<string, string | null>) => void;
12615
+ }
12616
+ //#endregion
12617
+ //#region src/render/collaboration-text-positions.d.ts
12618
+ interface TextPositionCell {
12619
+ index: number;
12620
+ left?: TextPositionCell;
12621
+ right?: TextPositionCell;
12622
+ }
12623
+ interface TrackedTextPosition {
12624
+ /** Internal identity, shared by snapshots that observed the same character. */
12625
+ readonly cell: TextPositionCell;
12626
+ readonly association: number;
12627
+ }
12628
+ //#endregion
12629
+ //#region src/render/collaboration-text-session-delta.d.ts
12630
+ /** Browser edit range mapped to the editor's pre-input encoded coordinates. */
12631
+ interface LocalTextReplacement {
12632
+ from: number;
12633
+ to: number;
12634
+ }
12635
+ /** Desired UTF-16 units mapped to the editor's previously observed identities. */
12636
+ interface TextSessionCorrespondence {
12637
+ readonly retainedIndices: readonly (number | null)[];
12638
+ /** Old carriers for known paragraph attributes, independently of character identity. */
12639
+ readonly paragraphSources?: readonly (number | null)[];
12640
+ }
12641
+ type LocalTextEdit = LocalTextReplacement | TextSessionCorrespondence;
12642
+ //#endregion
12643
+ //#region src/render/collaboration-text-session.d.ts
12644
+ /** Supplied by the binding's existing Yjs runtime, bound to this exact Y.Text. */
12645
+ interface TextSessionPositions<Position> {
12646
+ capture: (index: number, association: number) => Position;
12647
+ resolve: (position: Position) => number | null;
12648
+ /** Synchronize tracked positions once per batch, including in-transaction writes. */
12649
+ refresh?: () => boolean | void;
12650
+ /** Release only resources created for this session. */
12651
+ dispose?: () => void;
12652
+ }
12653
+ /** Opaque acknowledgement identity for an exact remote snapshot painted by an adapter. */
12654
+ interface CollaborationTextSnapshot {
12655
+ readonly delta: readonly DeltaOp[];
12656
+ }
12657
+ interface CollaborationTextSession {
12658
+ applyLocalDelta: (delta: readonly DeltaOp[], edit?: LocalTextEdit) => boolean;
12659
+ readMerged: () => CollaborationTextSnapshot | undefined;
12660
+ adoptMerged: (snapshot: CollaborationTextSnapshot) => boolean;
12661
+ /** Capture an offset in the last painted/local draft, not the newer remote string. */
12662
+ bookmark: (index: number, association: number) => () => number | null;
12663
+ dispose: () => void;
12664
+ }
12665
+ //#endregion
12604
12666
  //#region src/render/collaboration-sync.d.ts
12605
12667
  interface YMapLike {
12606
12668
  get: (key: string) => unknown;
@@ -12634,6 +12696,8 @@ interface YjsFactories {
12634
12696
  createMap: () => YMapLike;
12635
12697
  createArray: () => YArrayLike;
12636
12698
  createText: () => YTextLike;
12699
+ /** Track character identities using the binding's existing Yjs runtime. */
12700
+ createTextPositions?: (text: YTextEditableLike) => TextSessionPositions<TrackedTextPosition>;
12637
12701
  }
12638
12702
  //#endregion
12639
12703
  //#region src/render/collaboration-live-patch-target.d.ts
@@ -12650,7 +12714,20 @@ interface LiveTextSource {
12650
12714
  textSegments?: TextSegment[];
12651
12715
  textStyle?: TextStyle;
12652
12716
  }
12717
+ //#endregion
12718
+ //#region src/render/collaboration-text-target.d.ts
12719
+ interface CollaborationInlineSnapshot extends CollaborationTextSnapshot {
12720
+ readonly inline: InlineTextEditSnapshot;
12721
+ }
12722
+ /** A mounted editor owns this handle, never the document or its provider. */
12723
+ interface CollaborationTextTarget extends CollaborationTextSession {
12724
+ readMerged: () => CollaborationInlineSnapshot | undefined;
12725
+ /** A bookmark follows character identity rather than a mutable numeric offset. */
12726
+ bookmark: (index: number, association: number) => () => number | null;
12727
+ }
12653
12728
  interface CollaborationLivePatcher {
12729
+ /** Bind a mounted native editor; its handle must be disposed on unmount. */
12730
+ beginTextEdit?: (slideId: string | undefined, elementId: string, onChange?: () => void, ownsModel?: (element: PptxElement) => boolean) => CollaborationTextTarget | undefined;
12654
12731
  /** Attach a live doc (or `null` to go dormant). Pending patches are dropped. */
12655
12732
  configure: (doc: YDocLike | null, factories: YjsFactories | null,
12656
12733
  /** Publish synchronously when the host may revoke write readiness at any time. */
@@ -12700,6 +12777,37 @@ interface CollaborationLivePatcher {
12700
12777
  */
12701
12778
  type CollabLoadOrigin = 'bootstrap' | 'user';
12702
12779
  //#endregion
12780
+ //#region src/render/inline-list-selection.d.ts
12781
+ type InlineListSelectionResult = {
12782
+ kind: 'supported';
12783
+ snapshot: InlineTextEditSnapshot;
12784
+ selection: InlineTextSelection | null;
12785
+ bodyRange?: {
12786
+ start: number;
12787
+ end: number;
12788
+ };
12789
+ } | {
12790
+ kind: 'unsupported';
12791
+ reason: string;
12792
+ };
12793
+ interface InlineListController {
12794
+ read(): InlineListReadResult;
12795
+ format(snapshot: InlineTextEditSnapshot): InlineListReadResult;
12796
+ readSelection(selection?: Selection | null): InlineListSelectionResult;
12797
+ refresh(): InlineListReadResult;
12798
+ dispose(): void;
12799
+ }
12800
+ //#endregion
12801
+ //#region src/render/collaboration-inline-editor.d.ts
12802
+ interface CollaborationInlineEditor extends InlineListController {
12803
+ /** Current authoritative text for retirement only; pending Save must use read(). */
12804
+ readAccepted(): InlineTextEditSnapshot | undefined;
12805
+ /** An explicit model replacement retires ownership before full-deck sync. */
12806
+ checkModel(model: PptxElement | undefined): boolean;
12807
+ /** Capture a known programmatic DOM mutation, such as trimming before Enter. */
12808
+ mutate(range: AbstractRange, apply: () => void): boolean;
12809
+ }
12810
+ //#endregion
12703
12811
  //#region src/render/slide-compare.d.ts
12704
12812
  type SlideDiffStatus = 'added' | 'removed' | 'changed' | 'unchanged';
12705
12813
  type ElementChangeKind = 'added' | 'removed' | 'moved' | 'resized' | 'textChanged';
@@ -13527,27 +13635,6 @@ interface ViewportFitOptions {
13527
13635
  maxFitScale?: number | null;
13528
13636
  }
13529
13637
  //#endregion
13530
- //#region src/render/inline-list-selection.d.ts
13531
- type InlineListSelectionResult = {
13532
- kind: 'supported';
13533
- snapshot: InlineTextEditSnapshot;
13534
- selection: InlineTextSelection | null;
13535
- bodyRange?: {
13536
- start: number;
13537
- end: number;
13538
- };
13539
- } | {
13540
- kind: 'unsupported';
13541
- reason: string;
13542
- };
13543
- interface InlineListController {
13544
- read(): InlineListReadResult;
13545
- format(snapshot: InlineTextEditSnapshot): InlineListReadResult;
13546
- readSelection(selection?: Selection | null): InlineListSelectionResult;
13547
- refresh(): InlineListReadResult;
13548
- dispose(): void;
13549
- }
13550
- //#endregion
13551
13638
  //#region src/export/rasterize-element-strategy.d.ts
13552
13639
  /** Which path actually produced the tile, for telemetry/tests. */
13553
13640
  type RasterStrategy = 'foreignObject' | 'vectorSvg' | 'html2canvas';
@@ -14461,6 +14548,25 @@ interface PowerPointViewerApi extends PowerPointViewerAPI {
14461
14548
  */
14462
14549
  declare const PowerPointViewer: Component<PowerPointViewerProps, PowerPointViewerApi>;
14463
14550
 
14551
+ /** Props for the remote-cursor overlay. */
14552
+ interface CollaborationCursorsProps {
14553
+ /** Remote collaborators to render, in unscaled slide coordinates. */
14554
+ cursors: RemoteCursor[];
14555
+ /** Current canvas zoom factor; cursor positions scale by this. */
14556
+ zoom: number;
14557
+ }
14558
+ /** Props for the remote-selection overlay. */
14559
+ interface RemoteSelectionOverlayProps {
14560
+ /** Remote collaborators' presence (selection + active slide), excludes self. */
14561
+ presences: SanitizedPresence[];
14562
+ /** Elements on the active slide; selected ids resolve against these. */
14563
+ elements: PptxElement[];
14564
+ /** The current slide index; only peers on this slide are drawn. */
14565
+ activeSlideIndex: number;
14566
+ /** Current canvas zoom factor; element geometry scales by this. */
14567
+ zoom: number;
14568
+ }
14569
+
14464
14570
  interface SlideCanvasProps {
14465
14571
  slide: PptxSlide | undefined;
14466
14572
  canvasSize: CanvasSize;
@@ -15657,6 +15763,8 @@ interface EditorControllerDeps {
15657
15763
  getScale(): number;
15658
15764
  getCurrent(): number;
15659
15765
  getPresenting(): boolean;
15766
+ /** Synchronous host permission, before reactive teardown clears the native editor. */
15767
+ getEditable?(): boolean;
15660
15768
  getStageRoot(): Element | null;
15661
15769
  getHolderEl(): HTMLElement | null;
15662
15770
  /**
@@ -15790,16 +15898,31 @@ declare class EditorController {
15790
15898
  * state or history: the commit path stays the single source of truth.
15791
15899
  */
15792
15900
  previewInline(id: string, text: string): void;
15901
+ /** Native editor capability stays scoped to this controller's active slide. */
15902
+ get inlineCollaboration(): {
15903
+ patcher: CollaborationLivePatcher;
15904
+ slideId: string;
15905
+ } | undefined;
15793
15906
  /** Commit the inline editor's text onto the element and close it. */
15794
15907
  commitInline(id: string, text: string, snapshot?: InlineTextEditSnapshot): void;
15795
15908
  /** Register a live reader with this viewer's document and editing session. */
15796
- registerInlineReader(id: string, controller?: InlineListController, cancel?: () => void): void;
15909
+ registerInlineReader(id: string, controller?: InlineListController | CollaborationInlineEditor, cancel?: () => void): void;
15910
+ /** Retain authoritative accepted text before a host-only permission veto. */
15911
+ retainAcceptedInlineText(permissionLossOnly?: boolean): boolean;
15797
15912
  /** Close the inline editor without further mutation. */
15798
15913
  closeInline(): void;
15799
15914
  /** Tear down window listeners (component destroy). */
15800
15915
  destroy(): void;
15801
15916
  }
15802
15917
 
15918
+ /** Props for the editing layer (selection overlay + inline editor over the stage). */
15919
+ interface EditorLayerProps {
15920
+ /** The reactive editing orchestrator (owns overlay/snap/inline state). */
15921
+ controller: EditorController;
15922
+ /** Stage scale (screen px per element px). */
15923
+ scale: number;
15924
+ spellCheck?: boolean;
15925
+ }
15803
15926
  /**
15804
15927
  * Where the canvas context menu opened, and on which table cell.
15805
15928
  *
@@ -16009,6 +16132,9 @@ interface RibbonProps {
16009
16132
  declare const Ribbon: Component<RibbonProps>;
16010
16133
  declare const ViewerToolbar: Component<ViewerToolbarProps>;
16011
16134
  declare const SlideCanvas: Component<SlideCanvasProps>;
16135
+ declare const CollaborationCursors: Component<CollaborationCursorsProps>;
16136
+ declare const RemoteSelectionOverlay: Component<RemoteSelectionOverlayProps>;
16137
+ declare const EditorLayer: Component<EditorLayerProps>;
16012
16138
 
16013
16139
  /** Live editor accessors the bridge closes over (all read from viewer runes). */
16014
16140
  interface SvelteAiBridgeDeps {
@@ -17326,6 +17452,8 @@ interface ViewerStateBag {
17326
17452
  readonly chromeUi: ChromeUiState;
17327
17453
  readonly findReplace: FindReplaceState;
17328
17454
  readonly collab: CollaborationController;
17455
+ /** Shared authorization, canonical session readiness, status and presence for host chrome. */
17456
+ readonly shellState: CollaborationShellState;
17329
17457
  readonly dialogs: CollaborationDialogsState;
17330
17458
  readonly autosaveCtl: AutosaveController;
17331
17459
  /** The "recover unsaved changes?" probe + prompt for the loaded deck. */
@@ -17450,5 +17578,5 @@ interface ViewerStateBag {
17450
17578
  */
17451
17579
  declare function createViewerState(options: CreateViewerStateOptions): ViewerStateBag;
17452
17580
 
17453
- export { PowerPointViewer, PresentationLoader, Ribbon, SlideCanvas, ViewerState, ViewerToolbar, clampSlideIndex, createSvelteAiBridge, createViewerState, exportAllSlidesToSvg, exportAllSlidesToSvgBlobs, exportSlideAsSvg, exportSlideToSvg, exportSlideToSvgBlob, fitScale, resolveNavigationKey, zoomInPercent, zoomOutPercent };
17454
- export type { CanvasSize, CreateViewerStateOptions, ExportGifOptions, ExportPdfOptions, ExportVideoOptions, ExternalCollaborationAwareness, ExternalCollaborationSession, ExternalCollaborationSnapshot, NavigationAction, PowerPointViewerApi, PowerPointViewerProps, PptxAiBridge, PptxAiConfig, PptxAiConnection, PptxAiContextStrategy, PptxAiToolName, PptxAiUIMessage, PptxAiWritePolicy, PrintOptions, RibbonProps, SlideCanvasProps, SvelteAiBridgeDeps, SvgExportAllOptions, SvgExportSingleSlideOptions, ViewerLoadDetail, ViewerStateBag, ViewerTheme, ViewerToolbarProps };
17581
+ export { CollaborationCursors, EditorController, EditorLayer, PowerPointViewer, PresentationLoader, RemoteSelectionOverlay, Ribbon, SlideCanvas, ViewerState, ViewerToolbar, clampSlideIndex, createSvelteAiBridge, createViewerState, exportAllSlidesToSvg, exportAllSlidesToSvgBlobs, exportSlideAsSvg, exportSlideToSvg, exportSlideToSvgBlob, fitScale, resolveNavigationKey, zoomInPercent, zoomOutPercent };
17582
+ export type { CanvasSize, CollaborationCursorsProps, CollaborationShellState, ConnectionStatus, CreateViewerStateOptions, EditorLayerProps, ExportGifOptions, ExportPdfOptions, ExportVideoOptions, ExternalCollaborationAwareness, ExternalCollaborationSession, ExternalCollaborationSnapshot, InlineListController, InlineListReadResult, InlineTextEditSnapshot, NavigationAction, PowerPointViewerApi, PowerPointViewerProps, PptxAiBridge, PptxAiConfig, PptxAiConnection, PptxAiContextStrategy, PptxAiToolName, PptxAiUIMessage, PptxAiWritePolicy, PrintOptions, RemoteCursor, RemoteSelectionOverlayProps, RibbonProps, SanitizedPresence, SlideCanvasProps, SvelteAiBridgeDeps, SvgExportAllOptions, SvgExportSingleSlideOptions, ViewerLoadDetail, ViewerStateBag, ViewerTheme, ViewerToolbarProps };
@@ -1,23 +1,26 @@
1
- import { Ih as s, Lh as i } from "../transition-overlay-Cs0NYacO.js";
2
- import { A as e, M as a, c as l, d as S, f as n, i as v, j as o, l as d, m as p, n as b, o as m, p as c, r as g, s as x, t as w, u as T } from "../export-CXDSKwGo.js";
3
- var A = a, P = o, V = e;
1
+ import { Hh as l, Vh as S } from "../transition-overlay-Dvef1UAZ.js";
2
+ import { A as e, F as a, M as o, N as r, P as s, c as n, d, f as b, i as m, j as t, l as p, m as c, n as g, o as x, p as w, r as C, s as P, t as T, u as V } from "../export-gq-uU4it.js";
3
+ var $ = a, y = s, A = o, f = t, u = e, R = r;
4
4
  export {
5
- w as PowerPointViewer,
6
- v as PresentationLoader,
7
- A as Ribbon,
8
- V as SlideCanvas,
9
- g as ViewerState,
10
- P as ViewerToolbar,
11
- S as clampSlideIndex,
12
- p as createSvelteAiBridge,
13
- b as createViewerState,
14
- m as exportAllSlidesToSvg,
15
- x as exportAllSlidesToSvgBlobs,
16
- l as exportSlideAsSvg,
17
- d as exportSlideToSvg,
18
- T as exportSlideToSvgBlob,
19
- n as fitScale,
20
- c as resolveNavigationKey,
21
- s as zoomInPercent,
22
- i as zoomOutPercent
5
+ f as CollaborationCursors,
6
+ R as EditorLayer,
7
+ T as PowerPointViewer,
8
+ m as PresentationLoader,
9
+ u as RemoteSelectionOverlay,
10
+ $ as Ribbon,
11
+ A as SlideCanvas,
12
+ C as ViewerState,
13
+ y as ViewerToolbar,
14
+ d as clampSlideIndex,
15
+ c as createSvelteAiBridge,
16
+ g as createViewerState,
17
+ x as exportAllSlidesToSvg,
18
+ P as exportAllSlidesToSvgBlobs,
19
+ n as exportSlideAsSvg,
20
+ p as exportSlideToSvg,
21
+ V as exportSlideToSvgBlob,
22
+ b as fitScale,
23
+ w as resolveNavigationKey,
24
+ S as zoomInPercent,
25
+ l as zoomOutPercent
23
26
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "pptx-svelte-viewer",
3
- "version": "3.22.0",
3
+ "version": "4.1.0",
4
4
  "description": "Svelte 5 PowerPoint viewer and editor component: render, edit, present, and export PPTX slides in the browser.",
5
5
  "keywords": [
6
6
  "office",
@@ -116,7 +116,7 @@
116
116
  "jspdf": "^4.2.1",
117
117
  "jszip": "^3.10.2",
118
118
  "opentype.js": "^2.0.0",
119
- "pptx-viewer-mcp": "^2.5.2"
119
+ "pptx-viewer-mcp": "^2.5.4"
120
120
  },
121
121
  "devDependencies": {
122
122
  "@ai-sdk/svelte": "^5.0.97",
@@ -1,213 +0,0 @@
1
- import { AmbientLight as W, BufferGeometry as D, CanvasTexture as H, Color as z, DirectionalLight as L, EdgesGeometry as $, Euler as Y, ExtrudeGeometry as U, Group as q, Line as N, LineBasicMaterial as G, LineSegments as O, LinearFilter as P, Mesh as I, MeshBasicMaterial as V, MeshStandardMaterial as X, PerspectiveCamera as Z, PlaneGeometry as j, RepeatWrapping as J, SRGBColorSpace as K, Scene as Q, Shape as _, Vector3 as A, WebGLRenderer as ee } from "./three.module-BP1MPwgf.js";
2
- import { OrbitControls as te } from "./OrbitControls-Dj3MmTu8.js";
3
- var T = 4, R = 0.86;
4
- function ne(t, n, e) {
5
- const i = n.split(/\s+/u).filter(Boolean);
6
- if (i.length === 0) return [];
7
- const s = [];
8
- let o = i[0];
9
- for (let a = 1; a < i.length; a++) {
10
- const r = `${o} ${i[a]}`;
11
- t.measureText(r).width <= e ? o = r : (s.push(o), o = i[a]);
12
- }
13
- return s.push(o), s;
14
- }
15
- function oe(t, n) {
16
- const e = n?.bold === void 0 ? "600" : n.bold ? "700" : "400", i = n?.italic ? "italic " : "", s = typeof n?.fontScale == "number" && Number.isFinite(n.fontScale) && n.fontScale > 0 ? n.fontScale : 1;
17
- return {
18
- weight: e,
19
- italic: i,
20
- color: n?.color ?? t,
21
- scale: s
22
- };
23
- }
24
- function ie(t, n, e, i, s, o) {
25
- if (typeof document > "u" || !t.trim() || i <= 0 || s <= 0) return null;
26
- const { weight: a, italic: r, color: l, scale: p } = oe(n, o), h = i * R, w = s * R, f = document.createElement("canvas");
27
- f.width = Math.max(8, Math.round(h * T)), f.height = Math.max(8, Math.round(w * T));
28
- const d = f.getContext("2d");
29
- if (!d) return null;
30
- const M = "system-ui, -apple-system, Segoe UI, Roboto, sans-serif", S = f.width * 0.94, g = (x) => `${r}${a} ${x}px ${M}`;
31
- let c = Math.max(6, e) * p * T, b = [];
32
- for (let x = 0; x < 12; x++) {
33
- d.font = g(c), b = ne(d, t, S);
34
- const m = c * 1.2;
35
- if (b.length * m <= f.height * 0.96 || c <= 6 * T) break;
36
- c *= 0.88;
37
- }
38
- d.clearRect(0, 0, f.width, f.height), d.fillStyle = l, d.textAlign = "center", d.textBaseline = "middle", d.font = g(c);
39
- const y = c * 1.2, v = b.length * y, k = f.height / 2 - v / 2 + y / 2;
40
- for (let x = 0; x < b.length; x++) {
41
- const m = k + x * y;
42
- if (d.fillText(b[x], f.width / 2, m), o?.underline) {
43
- const F = d.measureText(b[x]).width;
44
- d.strokeStyle = l, d.lineWidth = Math.max(1, c * 0.06), d.beginPath(), d.moveTo(f.width / 2 - F / 2, m + c * 0.32), d.lineTo(f.width / 2 + F / 2, m + c * 0.32), d.stroke();
45
- }
46
- }
47
- const u = new H(f);
48
- return u.colorSpace = K, u.minFilter = P, u.magFilter = P, u.flipY = !1, u.premultiplyAlpha = !1, u.wrapT = J, u.repeat.set(1, -1), u.offset.set(0, 1), u.needsUpdate = !0, {
49
- texture: u,
50
- worldWidth: h,
51
- worldHeight: w
52
- };
53
- }
54
- function ae(t) {
55
- const n = new _();
56
- t.outline.forEach((i, s) => {
57
- s === 0 ? n.moveTo(i.x, i.y) : n.lineTo(i.x, i.y);
58
- }), n.closePath();
59
- const e = t.bevel > 0;
60
- return new U(n, {
61
- depth: t.depth,
62
- bevelEnabled: e,
63
- bevelThickness: t.bevel,
64
- bevelSize: t.bevel,
65
- bevelSegments: 2,
66
- curveSegments: t.rounded ? 24 : 1,
67
- steps: 1
68
- });
69
- }
70
- function se(t, n, e) {
71
- const i = ae(e), s = new X({
72
- color: new z(e.fill),
73
- metalness: 0.12,
74
- roughness: 0.52,
75
- transparent: e.opacity < 1,
76
- opacity: e.opacity
77
- }), o = new I(i, s);
78
- if (o.position.set(e.position.x, e.position.y, e.position.z), o.rotation.set(e.rotation.x, e.rotation.y, e.rotation.z), t.add(o), n.push(i, s), e.strokeWidth > 0) {
79
- const a = new $(i, 30), r = new G({ color: new z(e.stroke) }), l = new O(a, r);
80
- l.position.copy(o.position), l.rotation.copy(o.rotation), t.add(l), n.push(a, r);
81
- }
82
- return i;
83
- }
84
- function E(t, n) {
85
- if (!t.text) return null;
86
- const e = ie(t.text, t.textColor, t.fontSize, t.halfWidth * 2, t.halfHeight * 2, n);
87
- if (!e) return null;
88
- const i = new j(e.worldWidth, e.worldHeight), s = new V({
89
- map: e.texture,
90
- transparent: !0,
91
- depthWrite: !1
92
- }), o = new I(i, s), a = new Y(t.rotation.x, t.rotation.y, t.rotation.z), r = new A(0, 0, t.depth + t.bevel + 0.4).applyEuler(a);
93
- return o.position.set(t.position.x + r.x, t.position.y + r.y, t.position.z + r.z), o.rotation.copy(a), {
94
- plane: o,
95
- disposables: [
96
- i,
97
- s,
98
- e.texture
99
- ]
100
- };
101
- }
102
- function re(t, n, e) {
103
- for (const i of e.connectors) {
104
- if (i.points.length < 2) continue;
105
- const s = new D().setFromPoints(i.points.map((a) => new A(a.x, a.y, a.z))), o = new G({
106
- color: new z(i.color),
107
- transparent: !0,
108
- opacity: 0.7
109
- });
110
- t.add(new N(s, o)), n.push(s, o);
111
- }
112
- }
113
- function C(t, n) {
114
- n.plane && t.remove(n.plane);
115
- for (const e of n.disposables) e.dispose();
116
- n.plane = null, n.disposables = [];
117
- }
118
- function le(t, n) {
119
- const e = new q(), i = [], s = t.meshes.map((o) => {
120
- se(e, i, o);
121
- const a = E(o, n);
122
- return a && e.add(a.plane), {
123
- node: o,
124
- plane: a?.plane ?? null,
125
- disposables: a?.disposables ?? []
126
- };
127
- });
128
- return re(e, i, t), {
129
- group: e,
130
- setTextStyle(o) {
131
- for (const a of s) {
132
- C(e, a);
133
- const r = E(a.node, o);
134
- r && (e.add(r.plane), a.plane = r.plane, a.disposables = r.disposables);
135
- }
136
- },
137
- dispose() {
138
- for (const o of i) o.dispose();
139
- for (const o of s) C(e, o);
140
- }
141
- };
142
- }
143
- var B = 42;
144
- function ce(t) {
145
- let n = 1 / 0, e = 1 / 0, i = 1 / 0, s = -1 / 0, o = -1 / 0, a = -1 / 0;
146
- const r = (l, p, h, w) => {
147
- n = Math.min(n, l - w), e = Math.min(e, p - w), i = Math.min(i, h - w), s = Math.max(s, l + w), o = Math.max(o, p + w), a = Math.max(a, h + w);
148
- };
149
- for (const l of t.meshes) {
150
- const p = Math.max(l.halfWidth, l.halfHeight) + l.depth + l.bevel;
151
- r(l.position.x, l.position.y, l.position.z, p);
152
- }
153
- for (const l of t.connectors) for (const p of l.points) r(p.x, p.y, p.z, 1);
154
- return Number.isFinite(n) ? {
155
- cx: (n + s) / 2,
156
- cy: (e + o) / 2,
157
- cz: (i + a) / 2,
158
- radius: 0.5 * Math.hypot(s - n, o - e, a - i) || 1
159
- } : {
160
- cx: 0,
161
- cy: 0,
162
- cz: 0,
163
- radius: Math.max(t.bounds.width, t.bounds.height) / 2 || 1
164
- };
165
- }
166
- function de(t, n) {
167
- const e = B * Math.PI / 180, i = 2 * Math.atan(Math.tan(e / 2) * n);
168
- return t / Math.sin(Math.min(e, i) / 2) * 1.1;
169
- }
170
- function pe(t, n, e, i, s = {}) {
171
- const o = new ee({
172
- canvas: t,
173
- antialias: !0,
174
- alpha: !s.background
175
- });
176
- o.setPixelRatio(Math.min(typeof window > "u" ? 1 : window.devicePixelRatio || 1, s.maxPixelRatio ?? 2)), o.setSize(e, i, !1);
177
- const a = new Q();
178
- s.background && (a.background = new z(s.background));
179
- const { cx: r, cy: l, cz: p, radius: h } = ce(n), w = e / Math.max(1, i), f = de(h, w), d = new Z(B, w, 0.1, f * 8 + h * 4);
180
- d.position.set(r + h * 0.25, l + h * 0.3, p + f), d.lookAt(r, l, p), a.add(new W(16777215, 0.62));
181
- const M = new L(16777215, 0.95);
182
- M.position.set(r + h, l + h * 1.4, p + f), a.add(M);
183
- const S = new L(16777215, 0.3);
184
- S.position.set(r - h, l - h * 0.6, p + f * 0.6), a.add(S);
185
- const g = le(n, s.textStyle);
186
- a.add(g.group);
187
- let c = null;
188
- const b = (u) => {
189
- u && !c ? (c = new te(d, t), c.enablePan = !1, c.target.set(r, l, p), c.minDistance = f * 0.4, c.maxDistance = f * 3, c.update()) : !u && c && (c.dispose(), c = null), c && (c.autoRotate = !!s.autoRotate, c.autoRotateSpeed = 1.2);
190
- };
191
- b(!!s.interactive);
192
- let y = 0, v = !1;
193
- const k = () => {
194
- v || (y = requestAnimationFrame(k), c?.update(), o.render(a, d));
195
- };
196
- return y = requestAnimationFrame(k), {
197
- resize(u, x) {
198
- d.aspect = u / Math.max(1, x), d.updateProjectionMatrix(), o.setSize(u, x, !1);
199
- },
200
- setInteractive(u) {
201
- b(u);
202
- },
203
- setTextStyle(u) {
204
- g.setTextStyle(u);
205
- },
206
- dispose() {
207
- v = !0, cancelAnimationFrame(y), c?.dispose(), g.dispose(), o.dispose();
208
- }
209
- };
210
- }
211
- export {
212
- pe as mountSmartArt3D
213
- };