@nebula-spatial/studio 0.0.0-stage → 0.1.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.
Files changed (262) hide show
  1. package/README.md +206 -3
  2. package/dist/ai/contract.d.ts +73 -0
  3. package/dist/ai/host.d.ts +28 -0
  4. package/dist/asset/dependency-scan.d.ts +78 -0
  5. package/dist/asset/intake.d.ts +84 -0
  6. package/dist/asset/layout-detect.d.ts +40 -0
  7. package/dist/asset/media-type.d.ts +10 -0
  8. package/dist/asset/model-inspection.d.ts +127 -0
  9. package/dist/asset/record.d.ts +35 -0
  10. package/dist/asset/remote-asset-resolver.d.ts +36 -0
  11. package/dist/asset/repairs.d.ts +53 -0
  12. package/dist/asset/resource-locator.d.ts +15 -0
  13. package/dist/asset/revision-diff.d.ts +33 -0
  14. package/dist/asset/source-contracts.d.ts +21 -0
  15. package/dist/asset/source-paths.d.ts +15 -0
  16. package/dist/asset/usd-inspection.d.ts +39 -0
  17. package/dist/asset/usd-source-metadata.d.ts +142 -0
  18. package/dist/asset/visual-intake.d.ts +27 -0
  19. package/dist/asset/visual-record.d.ts +22 -0
  20. package/dist/asset/web-intake.d.ts +46 -0
  21. package/dist/asset-source-BExlEcRt.js +444 -0
  22. package/dist/assets/openusd_three_loader-DLiqJWUM.js +13769 -0
  23. package/dist/assets/usd-export-worker-BRxTLqer.js +182 -0
  24. package/dist/assets/usd-worker-DekqMsQv.js +1392 -0
  25. package/dist/builders-BAXRR5o5.js +1854 -0
  26. package/dist/core/asset-task.d.ts +105 -0
  27. package/dist/core/context.d.ts +23 -0
  28. package/dist/core/host.d.ts +432 -0
  29. package/dist/core/persistence-controller.d.ts +58 -0
  30. package/dist/core/plugins.d.ts +139 -0
  31. package/dist/core/scene-tree.d.ts +62 -0
  32. package/dist/core/versions.d.ts +2 -0
  33. package/dist/core/when.d.ts +13 -0
  34. package/dist/core/write-policy.d.ts +29 -0
  35. package/dist/delivery/build-plan.d.ts +2 -0
  36. package/dist/delivery/contracts.d.ts +362 -0
  37. package/dist/delivery/digest.d.ts +3 -0
  38. package/dist/delivery/evidence.d.ts +10 -0
  39. package/dist/delivery/export-evidence.d.ts +3 -0
  40. package/dist/delivery/index.d.ts +9 -0
  41. package/dist/delivery/prim-name.d.ts +17 -0
  42. package/dist/delivery/profile.d.ts +4 -0
  43. package/dist/doc/builders.d.ts +99 -0
  44. package/dist/doc/command.d.ts +195 -0
  45. package/dist/doc/domain-extensions.d.ts +34 -0
  46. package/dist/doc/node-facts.d.ts +87 -0
  47. package/dist/doc/physics-facts.d.ts +74 -0
  48. package/dist/doc/placement-policy.d.ts +71 -0
  49. package/dist/doc/random-placement.d.ts +30 -0
  50. package/dist/doc/scene-graph.d.ts +80 -0
  51. package/dist/doc/scene-regions.d.ts +29 -0
  52. package/dist/doc/schema.d.ts +452 -0
  53. package/dist/doc/task.d.ts +71 -0
  54. package/dist/doc/validate.d.ts +68 -0
  55. package/dist/editor/asset-source.d.ts +15 -0
  56. package/dist/editor/editor.d.ts +246 -0
  57. package/dist/editor/index.d.ts +22 -0
  58. package/dist/editor/shortcuts.d.ts +2 -0
  59. package/dist/editor/types.d.ts +143 -0
  60. package/dist/editor/ui-plugins.d.ts +64 -0
  61. package/dist/editor.js +1755 -0
  62. package/dist/editorial-BkAFWfbg.js +83 -0
  63. package/dist/export-evidence-DMNRhgL9.js +2705 -0
  64. package/dist/generalization/domain.d.ts +10 -0
  65. package/dist/generalization/generalization.d.ts +371 -0
  66. package/dist/generalization/index.d.ts +11 -0
  67. package/dist/generalization.js +1659 -0
  68. package/dist/history/undo-stack.d.ts +74 -0
  69. package/dist/index.d.ts +91 -0
  70. package/dist/index.js +2840 -0
  71. package/dist/mjcf-visual-Bt4bUxd1.js +72 -0
  72. package/dist/mujoco-runtime-BYZnrvbR.js +467 -0
  73. package/dist/persist/content-addressed.d.ts +11 -0
  74. package/dist/persist/create-scene-package-from-host.d.ts +7 -0
  75. package/dist/persist/indexeddb-store.d.ts +69 -0
  76. package/dist/persist/scene-file.d.ts +52 -0
  77. package/dist/persist/scene-package.d.ts +8 -0
  78. package/dist/persist/snapshot.d.ts +5 -0
  79. package/dist/physics-facts-tfQYyNTD.js +337 -0
  80. package/dist/placement-policy-DY_FNRDu.js +405 -0
  81. package/dist/ports/asset-ingestor.d.ts +41 -0
  82. package/dist/ports/asset-source.d.ts +57 -0
  83. package/dist/ports/delivery.d.ts +13 -0
  84. package/dist/ports/persistence.d.ts +29 -0
  85. package/dist/project/asset-catalog.d.ts +21 -0
  86. package/dist/project/contracts.d.ts +272 -0
  87. package/dist/project/editorial.d.ts +16 -0
  88. package/dist/project/identity.d.ts +20 -0
  89. package/dist/project/index.d.ts +9 -0
  90. package/dist/project/scene-document.d.ts +5 -0
  91. package/dist/project/source-dependencies.d.ts +7 -0
  92. package/dist/remote-asset-resolver-Cb8cfNmw.js +136 -0
  93. package/dist/scene/index.d.ts +12 -0
  94. package/dist/scene-graph-DBLKAhxa.js +681 -0
  95. package/dist/scene-session-Cy6vDJ1l.js +21981 -0
  96. package/dist/scene.js +244 -0
  97. package/dist/session-BRBrCLdd.js +963 -0
  98. package/dist/session-DI5tPJxn.js +825 -0
  99. package/dist/session-q3uuG7OP.js +296 -0
  100. package/dist/studio/delivery-catalog.d.ts +28 -0
  101. package/dist/studio/in-memory-asset-source.d.ts +15 -0
  102. package/dist/studio/index.d.ts +31 -0
  103. package/dist/studio/indexeddb-asset-source.d.ts +32 -0
  104. package/dist/studio/indexeddb-persistence.d.ts +13 -0
  105. package/dist/studio/remote-asset-importer.d.ts +56 -0
  106. package/dist/studio/source-package.d.ts +9 -0
  107. package/dist/studio/usd-export-client.d.ts +13 -0
  108. package/dist/studio/usd-export-protocol.d.ts +98 -0
  109. package/dist/studio/usd-export-worker.d.ts +1 -0
  110. package/dist/studio/usd-zip-reader.d.ts +14 -0
  111. package/dist/studio/web-asset-ingestor.d.ts +10 -0
  112. package/dist/studio/web-host.d.ts +8 -0
  113. package/dist/studio.js +5545 -0
  114. package/dist/urdf-session-CQir2nb2.js +1230 -0
  115. package/dist/usd-session-DZJnEEOs.js +7385 -0
  116. package/dist/util/asset-facts.d.ts +3 -0
  117. package/dist/util/data.d.ts +17 -0
  118. package/dist/util/diagnostics.d.ts +38 -0
  119. package/dist/util/geometry.d.ts +11 -0
  120. package/dist/util/hash.d.ts +9 -0
  121. package/dist/util/ids.d.ts +20 -0
  122. package/dist/util/math.d.ts +47 -0
  123. package/dist/util/ply-metadata.d.ts +19 -0
  124. package/dist/util/studio-source.d.ts +23 -0
  125. package/dist/version.d.ts +5 -0
  126. package/dist/view/appearance.d.ts +13 -0
  127. package/dist/view/authoring-appearance.d.ts +25 -0
  128. package/dist/view/bounds-preview.d.ts +34 -0
  129. package/dist/view/bounds.d.ts +11 -0
  130. package/dist/view/camera-zoom.d.ts +3 -0
  131. package/dist/view/geometry-anchors.d.ts +20 -0
  132. package/dist/view/gizmo-appearance.d.ts +5 -0
  133. package/dist/view/gizmo.d.ts +81 -0
  134. package/dist/view/group-selection.d.ts +13 -0
  135. package/dist/view/node-features.d.ts +39 -0
  136. package/dist/view/picking.d.ts +49 -0
  137. package/dist/view/placement.d.ts +48 -0
  138. package/dist/view/region-editing.d.ts +25 -0
  139. package/dist/view/rotation-guide.d.ts +36 -0
  140. package/dist/view/runtime-capabilities.d.ts +22 -0
  141. package/dist/view/scene-session.d.ts +258 -0
  142. package/dist/view/screen-bounds.d.ts +17 -0
  143. package/dist/view/selection-transform.d.ts +20 -0
  144. package/dist/wasm-module-DZn2AM1W.js +13 -0
  145. package/dist/xacro-DLRXyk60.js +76 -0
  146. package/node_modules/@nebula-spatial/cad-loader/CHANGELOG.md +48 -0
  147. package/node_modules/@nebula-spatial/cad-loader/README.md +108 -0
  148. package/node_modules/@nebula-spatial/cad-loader/dist/core/cad-types.d.ts +26 -0
  149. package/node_modules/@nebula-spatial/cad-loader/dist/core/errors.d.ts +5 -0
  150. package/node_modules/@nebula-spatial/cad-loader/dist/core/index.d.ts +24 -0
  151. package/node_modules/@nebula-spatial/cad-loader/dist/core/index.js +2354 -0
  152. package/node_modules/@nebula-spatial/cad-loader/dist/core/parser/bin-group-reader.d.ts +9 -0
  153. package/node_modules/@nebula-spatial/cad-loader/dist/core/parser/bin-parser.d.ts +78 -0
  154. package/node_modules/@nebula-spatial/cad-loader/dist/core/parser/dxbs-sidecar.d.ts +24 -0
  155. package/node_modules/@nebula-spatial/cad-loader/dist/core/parser/geometry-segments.d.ts +20 -0
  156. package/node_modules/@nebula-spatial/cad-loader/dist/core/parser/text-roundtrip.d.ts +4 -0
  157. package/node_modules/@nebula-spatial/cad-loader/dist/core/parser/types.d.ts +81 -0
  158. package/node_modules/@nebula-spatial/cad-loader/dist/core/runtime-text-decoder.d.ts +8 -0
  159. package/node_modules/@nebula-spatial/cad-loader/dist/core/types.d.ts +153 -0
  160. package/node_modules/@nebula-spatial/cad-loader/dist/core/utils/insert-bbox.d.ts +10 -0
  161. package/node_modules/@nebula-spatial/cad-loader/dist/core/utils/viewport-rect.d.ts +21 -0
  162. package/node_modules/@nebula-spatial/cad-loader/dist/index.d.ts +36 -0
  163. package/node_modules/@nebula-spatial/cad-loader/dist/index.js +5829 -0
  164. package/node_modules/@nebula-spatial/cad-loader/dist/loader/geo-loader.d.ts +59 -0
  165. package/node_modules/@nebula-spatial/cad-loader/dist/loader/internal/automatic-external-resources.d.ts +26 -0
  166. package/node_modules/@nebula-spatial/cad-loader/dist/loader/internal/external-variant-sidecar-fetch.d.ts +13 -0
  167. package/node_modules/@nebula-spatial/cad-loader/dist/loader/internal/flow-control.d.ts +29 -0
  168. package/node_modules/@nebula-spatial/cad-loader/dist/loader/internal/frame-budget-scheduler.d.ts +21 -0
  169. package/node_modules/@nebula-spatial/cad-loader/dist/loader/internal/geo-compact-executor.d.ts +19 -0
  170. package/node_modules/@nebula-spatial/cad-loader/dist/loader/internal/geo-loader-local-adapter.d.ts +2 -0
  171. package/node_modules/@nebula-spatial/cad-loader/dist/loader/internal/geo-loader-pipeline.d.ts +92 -0
  172. package/node_modules/@nebula-spatial/cad-loader/dist/loader/internal/geo-loader-worker-adapter.d.ts +13 -0
  173. package/node_modules/@nebula-spatial/cad-loader/dist/loader/internal/geo-node-builder.d.ts +34 -0
  174. package/node_modules/@nebula-spatial/cad-loader/dist/loader/internal/geo-node-load-sink.d.ts +28 -0
  175. package/node_modules/@nebula-spatial/cad-loader/dist/loader/internal/geo-node.d.ts +304 -0
  176. package/node_modules/@nebula-spatial/cad-loader/dist/loader/internal/geo-prepare-worker-types.d.ts +94 -0
  177. package/node_modules/@nebula-spatial/cad-loader/dist/loader/internal/geo-prepare.d.ts +38 -0
  178. package/node_modules/@nebula-spatial/cad-loader/dist/loader/internal/geo-prepare.worker.d.ts +1 -0
  179. package/node_modules/@nebula-spatial/cad-loader/dist/loader/internal/insert-model-builder.d.ts +10 -0
  180. package/node_modules/@nebula-spatial/cad-loader/dist/loader/internal/insert-runtime-geometry.d.ts +15 -0
  181. package/node_modules/@nebula-spatial/cad-loader/dist/loader/internal/line-canonical.d.ts +37 -0
  182. package/node_modules/@nebula-spatial/cad-loader/dist/loader/internal/line-quality.d.ts +9 -0
  183. package/node_modules/@nebula-spatial/cad-loader/dist/loader/internal/prepare-credit-gate.d.ts +20 -0
  184. package/node_modules/@nebula-spatial/cad-loader/dist/loader/internal/transport.d.ts +2 -0
  185. package/node_modules/@nebula-spatial/cad-loader/dist/render-resource/cad-render-node.d.ts +80 -0
  186. package/node_modules/@nebula-spatial/cad-loader/dist/render-resource/geo-node-cad-render-node.d.ts +12 -0
  187. package/node_modules/@nebula-spatial/cad-loader/dist/scene/geo-cad-line-geometry.d.ts +28 -0
  188. package/node_modules/@nebula-spatial/cad-loader/dist/scene/geo-cad-line-material.d.ts +18 -0
  189. package/node_modules/@nebula-spatial/cad-loader/dist/scene/instancing/block-geometry-registry.d.ts +35 -0
  190. package/node_modules/@nebula-spatial/cad-loader/dist/scene/instancing/insert-instance-table.d.ts +23 -0
  191. package/node_modules/@nebula-spatial/cad-loader/dist/scene/instancing/viewport-instance-presenter.d.ts +66 -0
  192. package/node_modules/@nebula-spatial/cad-loader/dist/selection/cad-insert-selection.d.ts +35 -0
  193. package/node_modules/@nebula-spatial/cad-loader/dist/selection/cad-text-selection.d.ts +31 -0
  194. package/node_modules/@nebula-spatial/cad-loader/dist/session/annotation-idle-gate.d.ts +14 -0
  195. package/node_modules/@nebula-spatial/cad-loader/dist/session/cad-document-session.d.ts +187 -0
  196. package/node_modules/@nebula-spatial/cad-loader/dist/session/cad-font-runtime.d.ts +11 -0
  197. package/node_modules/@nebula-spatial/cad-loader/dist/session/cad-insert-id.d.ts +6 -0
  198. package/node_modules/@nebula-spatial/cad-loader/dist/session/cad-text-warmup.d.ts +38 -0
  199. package/node_modules/@nebula-spatial/cad-loader/dist/session/create-cad-document-session.d.ts +5 -0
  200. package/node_modules/@nebula-spatial/cad-loader/dist/session/load-session.d.ts +90 -0
  201. package/node_modules/@nebula-spatial/cad-loader/dist/session/viewport-coverage.d.ts +32 -0
  202. package/node_modules/@nebula-spatial/cad-loader/dist/shared/abort.d.ts +3 -0
  203. package/node_modules/@nebula-spatial/cad-loader/dist/shared/cad-display-color.d.ts +55 -0
  204. package/node_modules/@nebula-spatial/cad-loader/dist/shared/cad-load-source.d.ts +8 -0
  205. package/node_modules/@nebula-spatial/cad-loader/dist/shared/color-buffer.d.ts +6 -0
  206. package/node_modules/@nebula-spatial/cad-loader/dist/shared/constants.d.ts +11 -0
  207. package/node_modules/@nebula-spatial/cad-loader/dist/shared/display-color-buffer.d.ts +27 -0
  208. package/node_modules/@nebula-spatial/cad-loader/dist/shared/errors.d.ts +2 -0
  209. package/node_modules/@nebula-spatial/cad-loader/dist/shared/text-builder.d.ts +25 -0
  210. package/node_modules/@nebula-spatial/cad-loader/dist/shared/text-font.d.ts +12 -0
  211. package/node_modules/@nebula-spatial/cad-loader/dist/shared/types.d.ts +57 -0
  212. package/node_modules/@nebula-spatial/cad-loader/dist/shared/utils/insert-bbox.d.ts +1 -0
  213. package/node_modules/@nebula-spatial/cad-loader/dist/shared/utils/timing.d.ts +2 -0
  214. package/node_modules/@nebula-spatial/cad-loader/dist/shared/utils/viewport-rect.d.ts +1 -0
  215. package/node_modules/@nebula-spatial/cad-loader/dist/shared/viewer-theme.d.ts +2 -0
  216. package/node_modules/@nebula-spatial/cad-loader/dist/workers/geo-prepare.worker.js +2264 -0
  217. package/node_modules/@nebula-spatial/cad-loader/package.json +62 -0
  218. package/node_modules/@nebula-spatial/viewer/CHANGELOG.md +426 -0
  219. package/node_modules/@nebula-spatial/viewer/FBX-MATERIAL-CONVERSION.md +97 -0
  220. package/node_modules/@nebula-spatial/viewer/README.md +1056 -0
  221. package/node_modules/@nebula-spatial/viewer/USD-VISUAL-MATERIAL-SUPPORT.md +89 -0
  222. package/node_modules/@nebula-spatial/viewer/basis/basis_transcoder.js +19 -0
  223. package/node_modules/@nebula-spatial/viewer/basis/basis_transcoder.wasm +0 -0
  224. package/node_modules/@nebula-spatial/viewer/dist/asset-ir-DEOK9SqE.js +382 -0
  225. package/node_modules/@nebula-spatial/viewer/dist/assets/ground-grid.d.ts +6 -0
  226. package/node_modules/@nebula-spatial/viewer/dist/assets/source-types.d.ts +19 -0
  227. package/node_modules/@nebula-spatial/viewer/dist/assets/types.d.ts +393 -0
  228. package/node_modules/@nebula-spatial/viewer/dist/assets/usd-worker-Bom5cjz3.js +1392 -0
  229. package/node_modules/@nebula-spatial/viewer/dist/cad/text.d.ts +2 -0
  230. package/node_modules/@nebula-spatial/viewer/dist/cad/types.d.ts +368 -0
  231. package/node_modules/@nebula-spatial/viewer/dist/index-ByBlfVc0.js +12132 -0
  232. package/node_modules/@nebula-spatial/viewer/dist/index.d.ts +32 -0
  233. package/node_modules/@nebula-spatial/viewer/dist/index.js +26 -0
  234. package/node_modules/@nebula-spatial/viewer/dist/inspection/types.d.ts +112 -0
  235. package/node_modules/@nebula-spatial/viewer/dist/mjcf-visual-DVRa0w90.js +72 -0
  236. package/node_modules/@nebula-spatial/viewer/dist/mujoco-runtime-Dhx6Ua2u.js +463 -0
  237. package/node_modules/@nebula-spatial/viewer/dist/plugins.d.ts +179 -0
  238. package/node_modules/@nebula-spatial/viewer/dist/scene/instances.d.ts +36 -0
  239. package/node_modules/@nebula-spatial/viewer/dist/scene/types.d.ts +258 -0
  240. package/node_modules/@nebula-spatial/viewer/dist/session-B-j6KdA-.js +389 -0
  241. package/node_modules/@nebula-spatial/viewer/dist/session-B4AICTeJ.js +963 -0
  242. package/node_modules/@nebula-spatial/viewer/dist/session-BAG5cDYe.js +9153 -0
  243. package/node_modules/@nebula-spatial/viewer/dist/simulation/mujoco-runtime.d.ts +118 -0
  244. package/node_modules/@nebula-spatial/viewer/dist/simulation/mujoco-wasm-module.d.ts +11 -0
  245. package/node_modules/@nebula-spatial/viewer/dist/simulation/openusd-wasm-module.d.ts +10 -0
  246. package/node_modules/@nebula-spatial/viewer/dist/simulation/physics-runtime-state.d.ts +75 -0
  247. package/node_modules/@nebula-spatial/viewer/dist/simulation/types.d.ts +129 -0
  248. package/node_modules/@nebula-spatial/viewer/dist/simulation/usd-inspection.d.ts +66 -0
  249. package/node_modules/@nebula-spatial/viewer/dist/simulation/usd-query.d.ts +50 -0
  250. package/node_modules/@nebula-spatial/viewer/dist/simulation/usd-resource-policy.d.ts +28 -0
  251. package/node_modules/@nebula-spatial/viewer/dist/types.d.ts +278 -0
  252. package/node_modules/@nebula-spatial/viewer/dist/ui/types.d.ts +48 -0
  253. package/node_modules/@nebula-spatial/viewer/dist/urdf-session-kemAnBn8.js +3231 -0
  254. package/node_modules/@nebula-spatial/viewer/dist/usd-session-QtwGKI7v.js +6771 -0
  255. package/node_modules/@nebula-spatial/viewer/dist/version.d.ts +5 -0
  256. package/node_modules/@nebula-spatial/viewer/dist/viewer.d.ts +2 -0
  257. package/node_modules/@nebula-spatial/viewer/dist/xacro-CYTPS7mh.js +1537 -0
  258. package/node_modules/@nebula-spatial/viewer/openusd/openusd-runtime-manifest.json +15 -0
  259. package/node_modules/@nebula-spatial/viewer/openusd/openusd_probe.js +14 -0
  260. package/node_modules/@nebula-spatial/viewer/openusd/openusd_probe.wasm +0 -0
  261. package/node_modules/@nebula-spatial/viewer/package.json +66 -0
  262. package/package.json +87 -6
@@ -0,0 +1,2264 @@
1
+ var rn = Object.defineProperty;
2
+ var te = (t) => {
3
+ throw TypeError(t);
4
+ };
5
+ var on = (t, e, n) => e in t ? rn(t, e, { enumerable: !0, configurable: !0, writable: !0, value: n }) : t[e] = n;
6
+ var Q = (t, e, n) => on(t, typeof e != "symbol" ? e + "" : e, n), sn = (t, e, n) => e.has(t) || te("Cannot " + n);
7
+ var rt = (t, e, n) => (sn(t, e, "read from private field"), n ? n.call(t) : e.get(t)), ee = (t, e, n) => e.has(t) ? te("Cannot add the same private member more than once") : e instanceof WeakSet ? e.add(t) : e.set(t, n);
8
+ class f extends Error {
9
+ constructor(n, r) {
10
+ super(r);
11
+ Q(this, "code");
12
+ this.name = "GeoLoaderError", this.code = n;
13
+ }
14
+ }
15
+ const Bt = 4096;
16
+ function Ie(t) {
17
+ return t >= 6 ? "u16_lw" : t >= 5 ? "u8_lw" : t >= 4 ? "u16" : "u8";
18
+ }
19
+ function Re(t) {
20
+ return t === "u16_lw" ? 13 : t === "u8_lw" ? 12 : t === "u16" ? 9 : 8;
21
+ }
22
+ function Ve(t, e, n) {
23
+ return n === "u16" || n === "u16_lw" ? t.getUint16(e + 7, !0) : t.getUint8(e + 7);
24
+ }
25
+ function an(t) {
26
+ return t === "u16" || t === "u16_lw" ? 2 : 1;
27
+ }
28
+ function Ge(t, e, n) {
29
+ if (!(n !== "u8_lw" && n !== "u16_lw"))
30
+ return t.getFloat32(e + 7 + an(n), !0);
31
+ }
32
+ function Ne(t, e, n, r, s = t.byteLength, o = "u8") {
33
+ if (n > s || s > t.byteLength)
34
+ throw new f("E_GROUP_RANGE", "Group byte range exceeds payload length");
35
+ let i = n;
36
+ const a = r * 2, u = a * 4;
37
+ if (i + u > s)
38
+ throw new f("E_GROUP_RANGE", "Group position bytes exceed payload length");
39
+ let c;
40
+ if (a > 0) {
41
+ const p = new Uint8Array(t, i, u), h = new Uint8Array(u), y = a;
42
+ for (let w = 0; w < a; w++)
43
+ h[w * 4] = p[w], h[w * 4 + 1] = p[y + w], h[w * 4 + 2] = p[y * 2 + w], h[w * 4 + 3] = p[y * 3 + w];
44
+ c = new Float32Array(h.buffer);
45
+ } else
46
+ c = new Float32Array(0);
47
+ if (i += u, i + 4 > s)
48
+ throw new f("E_GROUP_RANGE", "Missing seg_count field for group");
49
+ const m = e.getUint32(i, !0);
50
+ i += 4;
51
+ const g = [];
52
+ let l = 0;
53
+ const d = Re(o);
54
+ for (let p = 0; p < m; p++) {
55
+ if (i + d > s)
56
+ throw new f("E_GROUP_RANGE", "Segment record exceeds payload length");
57
+ const h = e.getUint32(i, !0), y = e.getUint8(i + 4), w = e.getUint8(i + 5), _ = e.getUint8(i + 6), E = Ve(e, i, o), A = Ge(e, i, o);
58
+ if (l + h > r)
59
+ throw new f("E_SEGMENT_SUM", "Segment vertex_count sum exceeds group count");
60
+ g.push({
61
+ startVertex: l,
62
+ vertexCount: h,
63
+ color: [y, w, _],
64
+ layerIndex: E,
65
+ ...A === void 0 ? {} : { lineweightPx: A }
66
+ }), i += d;
67
+ const U = l * 2;
68
+ if (h > 1) {
69
+ let N = c[U], C = c[U + 1];
70
+ for (let V = 1; V < h; V++) {
71
+ const G = U + V * 2;
72
+ N += c[G], C += c[G + 1], c[G] = N, c[G + 1] = C;
73
+ }
74
+ }
75
+ l += h;
76
+ }
77
+ if (l !== r)
78
+ throw new f("E_SEGMENT_SUM", `Segment vertex_count sum ${l} does not match group count ${r}`);
79
+ return {
80
+ chunk: { pos: c, count: r, segments: g },
81
+ offset: i
82
+ };
83
+ }
84
+ function un(t, e, n, r, s = "u8") {
85
+ const o = r * 2, i = o * 4;
86
+ if (n + i > t.byteLength)
87
+ throw new f("E_GROUP_RANGE", "Group position bytes exceed payload length");
88
+ const a = new Uint8Array(t, n, i);
89
+ let u = n + i;
90
+ if (u + 4 > t.byteLength)
91
+ throw new f("E_GROUP_RANGE", "Missing seg_count field for group");
92
+ const c = e.getUint32(u, !0);
93
+ u += 4;
94
+ const m = [];
95
+ let g = 0;
96
+ const l = Re(s);
97
+ for (let d = 0; d < c; d++) {
98
+ if (u + l > t.byteLength)
99
+ throw new f("E_GROUP_RANGE", "Segment record exceeds payload length");
100
+ const p = e.getUint32(u, !0), h = e.getUint8(u + 4), y = e.getUint8(u + 5), w = e.getUint8(u + 6), _ = Ve(e, u, s), E = Ge(e, u, s);
101
+ if (u += l, g + p > r)
102
+ throw new f("E_SEGMENT_SUM", "Segment vertex_count sum exceeds group count");
103
+ m.push({
104
+ startVertex: g,
105
+ vertexCount: p,
106
+ color: [h, y, w],
107
+ layerIndex: _,
108
+ ...E === void 0 ? {} : { lineweightPx: E }
109
+ }), g += p;
110
+ }
111
+ if (g !== r)
112
+ throw new f("E_SEGMENT_SUM", `Segment vertex_count sum ${g} does not match group count ${r}`);
113
+ return {
114
+ shuffled: a,
115
+ plane: o,
116
+ segments: m,
117
+ offset: u
118
+ };
119
+ }
120
+ function ln(t, e, n, r) {
121
+ if (r === 0)
122
+ return new Float32Array(0);
123
+ const s = new Uint8Array(r * 4);
124
+ for (let o = 0; o < r; o++)
125
+ s[o * 4] = t[n + o], s[o * 4 + 1] = t[e + n + o], s[o * 4 + 2] = t[e * 2 + n + o], s[o * 4 + 3] = t[e * 3 + n + o];
126
+ return new Float32Array(s.buffer);
127
+ }
128
+ function cn(t, e, n, r, s) {
129
+ const o = ln(
130
+ t.shuffled,
131
+ t.plane,
132
+ (e.startVertex + n) * 2,
133
+ r * 2
134
+ );
135
+ let i = (s == null ? void 0 : s[0]) ?? 0, a = (s == null ? void 0 : s[1]) ?? 0;
136
+ if (r > 0) {
137
+ n === 0 ? (i = o[0], a = o[1]) : (i += o[0], a += o[1], o[0] = i, o[1] = a);
138
+ for (let c = 1; c < r; c++) {
139
+ const m = c * 2;
140
+ i += o[m], a += o[m + 1], o[m] = i, o[m + 1] = a;
141
+ }
142
+ }
143
+ const u = r > 0 ? [{
144
+ startVertex: 0,
145
+ vertexCount: r,
146
+ color: [e.color[0], e.color[1], e.color[2]],
147
+ layerIndex: e.layerIndex,
148
+ ...e.lineweightPx === void 0 ? {} : { lineweightPx: e.lineweightPx }
149
+ }] : [];
150
+ return {
151
+ chunk: { pos: o, count: r, segments: u },
152
+ lastPoint: r > 0 ? [i, a] : s
153
+ };
154
+ }
155
+ function* fn(t, e, n, r, s = "u8") {
156
+ const o = un(t, e, n, r, s);
157
+ if (r === 0)
158
+ return yield { pos: new Float32Array(0), count: 0, segments: [] }, o.offset;
159
+ for (const i of o.segments) {
160
+ let a = null;
161
+ for (let u = 0; u < i.vertexCount; u += Bt) {
162
+ const c = Math.min(Bt, i.vertexCount - u), m = cn(o, i, u, c, a);
163
+ a = m.lastPoint, yield m.chunk;
164
+ }
165
+ }
166
+ return o.offset;
167
+ }
168
+ function Ue() {
169
+ const t = globalThis.TextDecoder;
170
+ if (!t)
171
+ throw new f("E_HEADER_JSON", "TextDecoder is required to parse CAD pack metadata");
172
+ return new t();
173
+ }
174
+ function it(t) {
175
+ return t ? {
176
+ minX: t.minX,
177
+ minY: t.minY,
178
+ maxX: t.maxX,
179
+ maxY: t.maxY
180
+ } : null;
181
+ }
182
+ function $t(t) {
183
+ return !!t && Number.isFinite(t.minX) && Number.isFinite(t.minY) && Number.isFinite(t.maxX) && Number.isFinite(t.maxY);
184
+ }
185
+ function ht(t) {
186
+ return $t(t) ? it(t) : null;
187
+ }
188
+ function Ce(t, e) {
189
+ const n = $t(t) ? t : null, r = $t(e) ? e : null;
190
+ return n ? r ? {
191
+ minX: Math.min(n.minX, r.minX),
192
+ minY: Math.min(n.minY, r.minY),
193
+ maxX: Math.max(n.maxX, r.maxX),
194
+ maxY: Math.max(n.maxY, r.maxY)
195
+ } : it(n) : it(r);
196
+ }
197
+ function dn(t, e, n, r = 0, s = 1) {
198
+ if (e <= 0 || n <= 0) return null;
199
+ let o = Number.POSITIVE_INFINITY, i = Number.POSITIVE_INFINITY, a = Number.NEGATIVE_INFINITY, u = Number.NEGATIVE_INFINITY, c = !1;
200
+ for (let m = 0; m < e; m += 1) {
201
+ const g = m * n, l = t[g + r], d = t[g + s];
202
+ !Number.isFinite(l) || !Number.isFinite(d) || (l < o && (o = l), d < i && (i = d), l > a && (a = l), d > u && (u = d), c = !0);
203
+ }
204
+ return c ? { minX: o, minY: i, maxX: a, maxY: u } : null;
205
+ }
206
+ function Se(t, e) {
207
+ const n = t.minX, r = t.minY, s = t.maxX, o = t.maxY, { matA: i, matB: a, matC: u, matD: c, tx: m, ty: g } = e;
208
+ let l = i * n + u * r + m, d = a * n + c * r + g, p = l, h = d, y = l, w = d;
209
+ return l = i * n + u * o + m, d = a * n + c * o + g, l < p && (p = l), d < h && (h = d), l > y && (y = l), d > w && (w = d), l = i * s + u * r + m, d = a * s + c * r + g, l < p && (p = l), d < h && (h = d), l > y && (y = l), d > w && (w = d), l = i * s + u * o + m, d = a * s + c * o + g, l < p && (p = l), d < h && (h = d), l > y && (y = l), d > w && (w = d), { minX: p, minY: h, maxX: y, maxY: w };
210
+ }
211
+ function mn(t) {
212
+ return Math.hypot(t.maxX - t.minX, t.maxY - t.minY);
213
+ }
214
+ function gn(t, e) {
215
+ const n = (t.minX + t.maxX) / 2, r = (t.minY + t.maxY) / 2, s = (e.minX + e.maxX) / 2, o = (e.minY + e.maxY) / 2;
216
+ return Math.hypot(n - s, r - o);
217
+ }
218
+ const yn = {};
219
+ function ne(t) {
220
+ return typeof t == "object" && t !== null;
221
+ }
222
+ function dt(t, e) {
223
+ return Object.prototype.hasOwnProperty.call(t, e);
224
+ }
225
+ function K(t) {
226
+ if (t.length === 0) return "$";
227
+ let e = "";
228
+ for (const n of t) {
229
+ if (typeof n == "number") {
230
+ e += `[${n}]`;
231
+ continue;
232
+ }
233
+ e += e.length === 0 ? n : `.${n}`;
234
+ }
235
+ return e;
236
+ }
237
+ function re(t, e, n, r) {
238
+ return new f("E_TEXT_ROUNDTRIP", `Text roundtrip mismatch at stage=${t} index=${e} path=${n}: ${r}`);
239
+ }
240
+ function vt(t, e, n) {
241
+ if (Object.is(t, e)) return null;
242
+ if (Array.isArray(t)) {
243
+ if (!Array.isArray(e))
244
+ return { path: K(n), reason: `expected array but found ${typeof e}` };
245
+ if (t.length !== e.length)
246
+ return { path: K([...n, "length"]), reason: `array length ${t.length} !== ${e.length}` };
247
+ for (let r = 0; r < t.length; r += 1) {
248
+ const s = vt(t[r], e[r], [...n, r]);
249
+ if (s) return s;
250
+ }
251
+ return null;
252
+ }
253
+ if (ne(t)) {
254
+ if (!ne(e) || Array.isArray(e))
255
+ return { path: K(n), reason: `expected object but found ${Array.isArray(e) ? "array" : typeof e}` };
256
+ const r = Object.keys(t), s = Object.keys(e);
257
+ if (r.length !== s.length) {
258
+ const o = r.find((a) => !dt(e, a));
259
+ if (o !== void 0)
260
+ return {
261
+ path: K([...n, o]),
262
+ reason: "missing key on actual"
263
+ };
264
+ const i = s.find((a) => !dt(t, a));
265
+ if (i !== void 0)
266
+ return {
267
+ path: K([...n, i]),
268
+ reason: "extra key on actual"
269
+ };
270
+ }
271
+ for (const o of r) {
272
+ if (!dt(e, o))
273
+ return { path: K([...n, o]), reason: "missing key on actual" };
274
+ const i = vt(t[o], e[o], [...n, o]);
275
+ if (i) return i;
276
+ }
277
+ for (const o of s)
278
+ if (!dt(t, o))
279
+ return { path: K([...n, o]), reason: "extra key on actual" };
280
+ return null;
281
+ }
282
+ return { path: K(n), reason: `expected ${String(t)} but found ${String(e)}` };
283
+ }
284
+ function hn(t, e) {
285
+ return vt(t, e, []);
286
+ }
287
+ function oe(t) {
288
+ if (t === !0 || t === "1" || t === "true") return !0;
289
+ if (t === !1 || t === "0" || t === "false") return !1;
290
+ }
291
+ function _n() {
292
+ var s, o;
293
+ const t = globalThis.process, e = oe(
294
+ ((s = t == null ? void 0 : t.env) == null ? void 0 : s.DXF_STRICT_TEXT_ROUNDTRIP) ?? ((o = t == null ? void 0 : t.env) == null ? void 0 : o.VITE_DXF_STRICT_TEXT_ROUNDTRIP)
295
+ );
296
+ if (e !== void 0) return e;
297
+ const n = yn, r = oe(n == null ? void 0 : n.VITE_DXF_STRICT_TEXT_ROUNDTRIP);
298
+ return r !== void 0 ? r : !1;
299
+ }
300
+ function xn(t, e, n) {
301
+ if (e.length !== n.length)
302
+ throw re(t, Math.min(e.length, n.length), "$length", `text count ${e.length} !== ${n.length}`);
303
+ for (let r = 0; r < e.length; r += 1) {
304
+ const s = hn(e[r], n[r]);
305
+ if (s)
306
+ throw re(t, r, s.path, s.reason);
307
+ }
308
+ }
309
+ Ue();
310
+ function se(t, e) {
311
+ if (t > BigInt(Number.MAX_SAFE_INTEGER))
312
+ throw new f("E_GROUP_RANGE", `${e} exceeds safe integer range`);
313
+ return Number(t);
314
+ }
315
+ function ie(t, e, n, r) {
316
+ if (!Number.isInteger(t) || !Number.isInteger(e) || t < 0 || e < 0 || t + e > n)
317
+ throw new f("E_GROUP_RANGE", `${r} exceeds payload length`);
318
+ }
319
+ function En(t) {
320
+ if (t.byteLength < 4) return !1;
321
+ const e = new Uint8Array(t, 0, 4);
322
+ return e[0] === 68 && e[1] === 88 && e[2] === 66 && e[3] === 83;
323
+ }
324
+ function wn(t) {
325
+ if (t.byteLength < 20)
326
+ throw new f("E_HEADER", "DXBS payload too small: missing container header");
327
+ if (!En(t))
328
+ throw new f("E_HEADER", "DXBS payload missing magic");
329
+ const e = new DataView(t), n = e.getUint16(4, !0), r = e.getUint16(6, !0), s = e.getUint16(8, !0), o = e.getUint16(10, !0), i = e.getUint16(12, !0), a = e.getUint16(14, !0), u = e.getUint32(16, !0);
330
+ if (n !== 3 || r < 3 || r > 6)
331
+ throw new f("E_GROUP_RANGE", `Unsupported DXBS version: ${n}.${r}`);
332
+ if (s !== 0)
333
+ throw new f("E_GROUP_RANGE", `Unsupported DXBS sidecar kind: ${s}`);
334
+ if (a !== 0)
335
+ throw new f("E_GROUP_RANGE", `Invalid DXBS reserved field: ${a}`);
336
+ if (o < 24)
337
+ throw new f("E_GROUP_RANGE", `Invalid DXBS directory entry size: ${o}`);
338
+ if (u !== o * i)
339
+ throw new f("E_GROUP_RANGE", "DXBS directory byte size mismatch");
340
+ const c = 20;
341
+ ie(c, u, t.byteLength, "DXBS section directory");
342
+ const m = /* @__PURE__ */ new Map();
343
+ for (let g = 0; g < i; g += 1) {
344
+ const l = c + g * o, d = e.getUint16(l, !0), p = e.getUint16(l + 2, !0), h = e.getUint32(l + 4, !0), y = se(e.getBigUint64(l + 8, !0), "DXBS section offset"), w = se(e.getBigUint64(l + 16, !0), "DXBS section length");
345
+ if (p !== 0)
346
+ throw new f("E_GROUP_RANGE", `Unsupported DXBS section flags for type ${d}: ${p}`);
347
+ if (h !== 0)
348
+ throw new f("E_GROUP_RANGE", `Invalid DXBS section reserved field for type ${d}: ${h}`);
349
+ ie(y, w, t.byteLength, `DXBS section ${d}`), m.set(d, { type: d, flags: p, offset: y, length: w });
350
+ }
351
+ return { versionMajor: n, versionMinor: r, sections: m };
352
+ }
353
+ function pn(t, e, n) {
354
+ const r = t.sections.get(e);
355
+ if (!r)
356
+ throw new f("E_GROUP_RANGE", `Missing DXBS section ${n}`);
357
+ return r;
358
+ }
359
+ function bn() {
360
+ return {
361
+ pos: new Float32Array(0),
362
+ count: 0,
363
+ segments: []
364
+ };
365
+ }
366
+ function Ot(t) {
367
+ if (t.segments && t.segments.length > 0)
368
+ return In(t.segments, t.count), t.segments;
369
+ if (t.count <= 0) return [];
370
+ if (!t.col || !t.lay)
371
+ throw new f("E_GROUP_RANGE", "Geometry chunk is missing segment or expanded color/layer metadata");
372
+ return An(t.col, t.lay, t.count);
373
+ }
374
+ function ae(t) {
375
+ const e = [];
376
+ for (const n of t) {
377
+ const r = e[e.length - 1];
378
+ if (r && r.startVertex + r.vertexCount === n.startVertex && r.layerIndex === n.layerIndex && r.color[0] === n.color[0] && r.color[1] === n.color[1] && r.color[2] === n.color[2] && r.lineweightPx === n.lineweightPx) {
379
+ e[e.length - 1] = {
380
+ ...r,
381
+ vertexCount: r.vertexCount + n.vertexCount
382
+ };
383
+ continue;
384
+ }
385
+ e.push({
386
+ startVertex: n.startVertex,
387
+ vertexCount: n.vertexCount,
388
+ color: Rn(n),
389
+ layerIndex: n.layerIndex,
390
+ ...n.lineweightPx === void 0 ? {} : { lineweightPx: n.lineweightPx }
391
+ });
392
+ }
393
+ return e;
394
+ }
395
+ function An(t, e, n) {
396
+ if (t.length < n * 3 || e.length < n)
397
+ throw new f("E_GROUP_RANGE", "Expanded color/layer metadata is shorter than geometry count");
398
+ const r = [];
399
+ let s = 0;
400
+ for (; s < n; ) {
401
+ const o = s * 3, i = t[o] ?? 0, a = t[o + 1] ?? 0, u = t[o + 2] ?? 0, c = e[s] ?? 0;
402
+ let m = s + 1;
403
+ for (; m < n; ) {
404
+ const g = m * 3;
405
+ if (e[m] !== c || t[g] !== i || t[g + 1] !== a || t[g + 2] !== u)
406
+ break;
407
+ m += 1;
408
+ }
409
+ r.push({
410
+ startVertex: s,
411
+ vertexCount: m - s,
412
+ color: [i, a, u],
413
+ layerIndex: c
414
+ }), s = m;
415
+ }
416
+ return r;
417
+ }
418
+ function In(t, e) {
419
+ let n = 0;
420
+ for (const r of t) {
421
+ if (r.vertexCount < 0 || r.startVertex !== n)
422
+ throw new f("E_SEGMENT_SUM", "Geometry segments must be contiguous and non-negative");
423
+ n += r.vertexCount;
424
+ }
425
+ if (n !== e)
426
+ throw new f("E_SEGMENT_SUM", `Geometry segment vertex sum ${n} does not match count ${e}`);
427
+ }
428
+ function Rn(t) {
429
+ return [t.color[0], t.color[1], t.color[2]];
430
+ }
431
+ const Vn = 8e6, Lt = Ue(), Gn = ["left", "center", "right"], Nn = ["top", "middle", "bottom", "alphabetic"];
432
+ function ue(t, e, n) {
433
+ for (const r of t)
434
+ n(r);
435
+ for (const r of e)
436
+ n(r);
437
+ }
438
+ const Te = /* @__PURE__ */ new WeakSet();
439
+ function st(t) {
440
+ return typeof t == "object" && t !== null;
441
+ }
442
+ function Un(t) {
443
+ return Array.isArray(t) ? "array" : t === null ? "null" : typeof t;
444
+ }
445
+ function Cn(t) {
446
+ return !(!st(t) || Array.isArray(t) || typeof t.t != "string" || typeof t.x != "number" || typeof t.y != "number" || typeof t.h != "number" || typeof t.r != "number" || !Array.isArray(t.c) || t.c.length !== 3 || !t.c.every((e) => typeof e == "number") || typeof t.li != "number" || t.ha !== "left" && t.ha !== "center" && t.ha !== "right" || t.va !== "top" && t.va !== "middle" && t.va !== "bottom" && t.va !== "alphabetic" || typeof t.lh != "number" || t.w !== void 0 && typeof t.w != "number" || t.wf !== void 0 && typeof t.wf != "number" || t.iv !== void 0 && typeof t.iv != "number" || t.io !== void 0 && typeof t.io != "number" || t.mx !== void 0 && t.mx !== !0 || t.my !== void 0 && t.my !== !0);
447
+ }
448
+ function Sn(t) {
449
+ return t.map((e, n) => ({
450
+ index: n,
451
+ name: e.name,
452
+ color: [...e.color],
453
+ lw_px: e.lw_px,
454
+ visible: e.visible ?? !0
455
+ }));
456
+ }
457
+ function Pe(t) {
458
+ const e = t.texts, n = Array.isArray(e) ? e : [], r = n.filter(Cn), s = _n();
459
+ if (s && e !== void 0 && !Array.isArray(e))
460
+ throw new f(
461
+ "E_TEXT_ROUNDTRIP",
462
+ `Text roundtrip mismatch at stage=Boundary-2:header->stream index=0 path=$: expected array but found ${Un(e)}`
463
+ );
464
+ return s && xn("Boundary-2:header->stream", n, r), {
465
+ bounds: [...t.bounds],
466
+ entityCount: Number(t.entity_count || 0),
467
+ lineCount: Number(t.line_count || 0),
468
+ fillCount: Number(t.fill_count || 0),
469
+ dotCount: Number(t.dot_count || 0),
470
+ textCount: r.length,
471
+ layers: Sn(t.layers ?? []),
472
+ texts: r,
473
+ units: t.units
474
+ };
475
+ }
476
+ function Tn(t) {
477
+ const e = t == null ? void 0 : t.maxExpandedInstanceVertices, n = typeof e == "number" && Number.isFinite(e) && e >= 0 ? Math.floor(e) : Vn;
478
+ return {
479
+ hiddenInstanceIds: t != null && t.hiddenInstanceIds ? new Set(t.hiddenInstanceIds) : /* @__PURE__ */ new Set(),
480
+ keepTextsForHiddenInstances: (t == null ? void 0 : t.keepTextsForHiddenInstances) === !0,
481
+ loadBlocks: (t == null ? void 0 : t.loadBlocks) !== !1,
482
+ suppressExpandedInsertGeometry: (t == null ? void 0 : t.suppressExpandedInsertGeometry) === !0,
483
+ maxExpandedInstanceVertices: n,
484
+ expandedInstanceVertices: 0,
485
+ externalVariantBuffers: t == null ? void 0 : t.externalVariantBuffers,
486
+ requiredExternalVariantIds: t == null ? void 0 : t.requiredExternalVariantIds,
487
+ externalVariantDeltaOnly: (t == null ? void 0 : t.externalVariantDeltaOnly) === !0,
488
+ deferExternalVariantGeometry: (t == null ? void 0 : t.deferExternalVariantGeometry) === !0,
489
+ cacheDocument: (t == null ? void 0 : t.cacheDocument) === !0
490
+ };
491
+ }
492
+ function Pn(t) {
493
+ return t.loadBlocks && !t.suppressExpandedInsertGeometry;
494
+ }
495
+ function Be(t, e) {
496
+ return Pn(e) && !e.hiddenInstanceIds.has(t);
497
+ }
498
+ function Bn(t, e, n) {
499
+ if (n <= 0)
500
+ return;
501
+ const r = t.expandedInstanceVertices + n;
502
+ if (r > t.maxExpandedInstanceVertices)
503
+ throw new f(
504
+ "E_EXPANSION_BUDGET",
505
+ `CPU-expanded ${e} instance vertices exceed budget: ${r}/${t.maxExpandedInstanceVertices}. Disable block loading or raise maxExpandedInstanceVertices.`
506
+ );
507
+ t.expandedInstanceVertices = r;
508
+ }
509
+ function $n(t, e, n) {
510
+ return n.loadBlocks ? n.hiddenInstanceIds.size === 0 || n.keepTextsForHiddenInstances ? t : t.filter((r) => {
511
+ if (!Number.isInteger(r.iv) || !Number.isInteger(r.io))
512
+ return !0;
513
+ const s = e.get(`${r.iv}:${r.io}`);
514
+ return s === void 0 || !n.hiddenInstanceIds.has(s);
515
+ }) : t.filter((r) => !Number.isInteger(r.iv) || !Number.isInteger(r.io));
516
+ }
517
+ function vn(t, e) {
518
+ const n = /* @__PURE__ */ new Map();
519
+ return t.forEach((r, s) => {
520
+ if (!Number.isInteger(r.iv) || !Number.isInteger(r.io))
521
+ return;
522
+ const o = e.get(`${r.iv}:${r.io}`);
523
+ if (o === void 0)
524
+ return;
525
+ const i = n.get(o);
526
+ i ? i.push(s) : n.set(o, [s]);
527
+ }), n;
528
+ }
529
+ function On(t, e, n, r, s, o, i) {
530
+ const a = e.map((u, c) => ({
531
+ id: u.id,
532
+ blockName: $e(u, c),
533
+ line: n[c].line,
534
+ fill: n[c].fill,
535
+ dot: n[c].dot,
536
+ texts: r.get(u.id) ?? []
537
+ }));
538
+ return {
539
+ layer0Index: t,
540
+ variants: a,
541
+ instances: s,
542
+ textIndexesByInstanceId: vn(o, i),
543
+ ownerInstanceIdByVariantOrdinal: i
544
+ };
545
+ }
546
+ function Mn(t) {
547
+ if (t.byteLength < 4)
548
+ throw new f("E_HEADER", "Payload too small: missing header length");
549
+ const e = new DataView(t), n = e.getUint32(0, !0), r = 4, s = r + n;
550
+ if (s > t.byteLength)
551
+ throw new f("E_HEADER", "Header length exceeds payload length");
552
+ let o;
553
+ try {
554
+ o = JSON.parse(Lt.decode(new Uint8Array(t, r, n)));
555
+ } catch (i) {
556
+ throw new f("E_HEADER_JSON", `Invalid JSON header: ${i.message}`);
557
+ }
558
+ return {
559
+ meta: o,
560
+ header: Pe(o),
561
+ dataOffset: s,
562
+ view: e
563
+ };
564
+ }
565
+ function $e(t, e) {
566
+ var o, i, a;
567
+ const n = (o = t.name) == null ? void 0 : o.trim();
568
+ if (n)
569
+ return n;
570
+ const r = (i = t.block_name) == null ? void 0 : i.trim();
571
+ if (r)
572
+ return r;
573
+ const s = (a = t.blockName) == null ? void 0 : a.trim();
574
+ return s || `block_${e}`;
575
+ }
576
+ function kn(t) {
577
+ const e = Number(t.version ?? 1), n = String(t.encoding ?? "").toLowerCase();
578
+ if (e === 2) {
579
+ const r = n ? ` ${n}` : "";
580
+ throw new f(
581
+ "E_UNSUPPORTED_PACK_VERSION",
582
+ `当前文件是 V2${r} pack,前端不再兼容解析;请升级到最新版本后再打开。`
583
+ );
584
+ }
585
+ }
586
+ function Dn(t) {
587
+ const e = Mn(t);
588
+ return kn(e.meta), e;
589
+ }
590
+ function ve(t) {
591
+ if (t.byteLength < 4)
592
+ return !1;
593
+ const e = new Uint8Array(t, 0, 4);
594
+ return e[0] === 68 && e[1] === 88 && e[2] === 66 && e[3] === 51;
595
+ }
596
+ function le(t, e) {
597
+ if (t > BigInt(Number.MAX_SAFE_INTEGER))
598
+ throw new f("E_GROUP_RANGE", `${e} exceeds safe integer range`);
599
+ return Number(t);
600
+ }
601
+ function at(t, e, n, r) {
602
+ if (!Number.isInteger(t) || !Number.isInteger(e) || t < 0 || e < 0 || t + e > n)
603
+ throw new f("E_GROUP_RANGE", `${r} exceeds payload length`);
604
+ }
605
+ function Ln(t) {
606
+ if (t.byteLength < 20)
607
+ throw new f("E_HEADER", "V3 payload too small: missing container header");
608
+ const e = new DataView(t), n = e.getUint16(4, !0), r = e.getUint16(6, !0), s = e.getUint32(8, !0), o = e.getUint16(12, !0), i = e.getUint16(14, !0), a = e.getUint32(16, !0);
609
+ if (n !== 3 || r > 6)
610
+ throw new f("E_GROUP_RANGE", `Unsupported V3 version: ${n}.${r}`);
611
+ if (s !== 0)
612
+ throw new f("E_GROUP_RANGE", `Unsupported V3 file flags: ${s}`);
613
+ if (o < 24)
614
+ throw new f("E_GROUP_RANGE", `Invalid V3 directory entry size: ${o}`);
615
+ if (a !== o * i)
616
+ throw new f("E_GROUP_RANGE", "V3 directory byte size mismatch");
617
+ const u = 20;
618
+ at(u, a, t.byteLength, "V3 section directory");
619
+ const c = /* @__PURE__ */ new Map();
620
+ for (let m = 0; m < i; m += 1) {
621
+ const g = u + m * o, l = e.getUint16(g, !0), d = e.getUint16(g + 2, !0), p = e.getUint32(g + 4, !0), h = le(e.getBigUint64(g + 8, !0), "V3 section offset"), y = le(e.getBigUint64(g + 16, !0), "V3 section length");
622
+ if (d !== 0)
623
+ throw new f("E_GROUP_RANGE", `Unsupported V3 section flags for type ${l}: ${d}`);
624
+ if (p !== 0)
625
+ throw new f("E_GROUP_RANGE", `Invalid V3 section reserved field for type ${l}: ${p}`);
626
+ at(h, y, t.byteLength, `V3 section ${l}`), c.set(l, { type: l, flags: d, offset: h, length: y });
627
+ }
628
+ return { versionMinor: r, sections: c };
629
+ }
630
+ function tt(t, e, n) {
631
+ const r = t.get(e);
632
+ if (!r)
633
+ throw new f("E_GROUP_RANGE", `Missing V3 section ${n}`);
634
+ return r;
635
+ }
636
+ function pt(t, e) {
637
+ return t.get(e) ?? { type: e, flags: 0, offset: 0, length: 0 };
638
+ }
639
+ function Fn(t, e, n) {
640
+ try {
641
+ return JSON.parse(Lt.decode(new Uint8Array(t, e.offset, e.length)));
642
+ } catch (r) {
643
+ throw new f("E_HEADER_JSON", `Invalid V3 ${n} JSON: ${r.message}`);
644
+ }
645
+ }
646
+ function Xn(t) {
647
+ const e = String(t.encoding ?? "").toLowerCase();
648
+ return e === "nested_instanced_external" || e === "nested_instanced_external_annotations";
649
+ }
650
+ function Yn(t) {
651
+ return String(t.encoding ?? "").toLowerCase() === "nested_instanced_external_annotations";
652
+ }
653
+ function zn(t, e, n) {
654
+ const r = t.features, s = r && typeof r == "object" && !Array.isArray(r) ? { ...r } : {};
655
+ return e && (s.has_external_variant_geometry = !0), n && (s.has_external_annotations = !0), Object.keys(s).length ? s : void 0;
656
+ }
657
+ function Y(t, e) {
658
+ if (!Number.isInteger(t) || Number(t) < 0)
659
+ throw new f("E_HEADER", `${e} must be a non-negative integer`);
660
+ return Number(t);
661
+ }
662
+ function Oe(t, e) {
663
+ if (typeof t != "string" || !t.trim())
664
+ throw new f("E_HEADER", `${e} must be a non-empty string`);
665
+ return t;
666
+ }
667
+ function ce(t, e) {
668
+ if (t == null)
669
+ return null;
670
+ if (!Array.isArray(t) || t.length !== 4 || t.some((n) => typeof n != "number" || !Number.isFinite(n)))
671
+ throw new f("E_HEADER", `${e} must be null or [minX, minY, maxX, maxY]`);
672
+ return [t[0], t[1], t[2], t[3]];
673
+ }
674
+ function Mt(t, e) {
675
+ if (!st(t) || Array.isArray(t))
676
+ throw new f("E_HEADER", `${e} must be an object`);
677
+ return {
678
+ line_count: Y(t.line_count, `${e}.line_count`),
679
+ fill_count: Y(t.fill_count, `${e}.fill_count`),
680
+ dot_count: Y(t.dot_count, `${e}.dot_count`),
681
+ bbox: ce(t.bbox, `${e}.bbox`),
682
+ own_bbox: ce(t.own_bbox, `${e}.own_bbox`)
683
+ };
684
+ }
685
+ function Hn(t) {
686
+ return t ? { minX: t[0], minY: t[1], maxX: t[2], maxY: t[3] } : null;
687
+ }
688
+ function Kn(t, e) {
689
+ const n = t.external_variants;
690
+ if (!Array.isArray(n))
691
+ throw new f("E_HEADER", "V3 external SCENE_META.external_variants must be an array");
692
+ if (n.length !== e)
693
+ throw new f(
694
+ "E_GROUP_RANGE",
695
+ `V3 external variant manifest count mismatch: manifest=${n.length}, table=${e}`
696
+ );
697
+ return n.map((r, s) => {
698
+ if (!st(r) || Array.isArray(r))
699
+ throw new f("E_HEADER", `V3 external_variants[${s}] must be an object`);
700
+ const o = Y(r.id, `V3 external_variants[${s}].id`);
701
+ if (o !== s)
702
+ throw new f("E_GROUP_RANGE", `V3 external_variants[${s}].id must equal ${s}, found ${o}`);
703
+ const i = Oe(r.href, `V3 external_variants[${s}].href`), a = Y(r.raw_size, `V3 external_variants[${s}].raw_size`);
704
+ if ("normal" in r || "annotation" in r) {
705
+ const u = Mt(r.annotation, `V3 external_variants[${s}].annotation`);
706
+ return {
707
+ id: o,
708
+ href: i,
709
+ raw_size: a,
710
+ normal: Mt(r.normal, `V3 external_variants[${s}].normal`),
711
+ annotation: {
712
+ ...u,
713
+ text_count: Y(
714
+ st(r.annotation) && !Array.isArray(r.annotation) ? r.annotation.text_count : void 0,
715
+ `V3 external_variants[${s}].annotation.text_count`
716
+ )
717
+ }
718
+ };
719
+ }
720
+ return {
721
+ id: o,
722
+ href: i,
723
+ raw_size: a,
724
+ line_count: Y(r.line_count, `V3 external_variants[${s}].line_count`),
725
+ fill_count: Y(r.fill_count, `V3 external_variants[${s}].fill_count`),
726
+ dot_count: Y(r.dot_count, `V3 external_variants[${s}].dot_count`)
727
+ };
728
+ });
729
+ }
730
+ function jn(t) {
731
+ const e = t.external_annotations;
732
+ if (e == null) return null;
733
+ if (!st(e) || Array.isArray(e))
734
+ throw new f("E_HEADER", "V3 external_annotations must be an object");
735
+ const n = e.scene;
736
+ if (n == null) return {};
737
+ if (!st(n) || Array.isArray(n))
738
+ throw new f("E_HEADER", "V3 external_annotations.scene must be an object");
739
+ const r = Mt(n, "V3 external_annotations.scene");
740
+ return {
741
+ scene: {
742
+ href: Oe(n.href, "V3 external_annotations.scene.href"),
743
+ raw_size: Y(n.raw_size, "V3 external_annotations.scene.raw_size"),
744
+ ...r,
745
+ text_count: Y(n.text_count, "V3 external_annotations.scene.text_count")
746
+ }
747
+ };
748
+ }
749
+ function _t(t, e, n, r) {
750
+ return at(e, n, t.byteLength, r), Lt.decode(t.subarray(e, e + n));
751
+ }
752
+ function Wn(t, e, n) {
753
+ if (e.length % 20 !== 0)
754
+ throw new f("E_GROUP_RANGE", "V3 LAYER_TABLE length must be a multiple of 20");
755
+ const r = new DataView(t), s = [];
756
+ for (let o = e.offset; o < e.offset + e.length; o += 20) {
757
+ const i = r.getUint32(o, !0), a = r.getUint32(o + 4, !0);
758
+ s.push({
759
+ name: _t(n, i, a, "V3 layer name"),
760
+ color: [r.getUint8(o + 8), r.getUint8(o + 9), r.getUint8(o + 10)],
761
+ visible: r.getUint8(o + 11) !== 0,
762
+ lw_px: r.getFloat32(o + 12, !0)
763
+ });
764
+ }
765
+ return s;
766
+ }
767
+ function gt(t, e, n, r, s, o) {
768
+ if (n + 4 > r)
769
+ throw new f("E_GROUP_RANGE", `Missing ${s} vertex_count`);
770
+ const i = e.getUint32(n, !0), a = n + 4, u = Ne(t, e, a, i, r, o);
771
+ if (u.offset > r)
772
+ throw new f("E_GROUP_RANGE", `${s} exceeds section bounds`);
773
+ return {
774
+ chunk: u.chunk,
775
+ offset: u.offset
776
+ };
777
+ }
778
+ function Me(t, e, n, r, s, o) {
779
+ const i = gt(t, e, n, r, s, o), a = n + 4;
780
+ return {
781
+ chunk: i.chunk,
782
+ snapshot: {
783
+ count: i.chunk.count,
784
+ raw: new Uint8Array(t, a, i.offset - a).slice(),
785
+ groupLayerEncoding: o
786
+ },
787
+ offset: i.offset
788
+ };
789
+ }
790
+ function yt(t = "u8") {
791
+ return {
792
+ chunk: { pos: new Float32Array(0), col: new Uint8Array(0), lay: new Uint8Array(0), count: 0 },
793
+ snapshot: { count: 0, raw: new Uint8Array(0), groupLayerEncoding: t }
794
+ };
795
+ }
796
+ function ke(t = "u8") {
797
+ return {
798
+ line: yt(t),
799
+ fill: yt(t),
800
+ dot: yt(t)
801
+ };
802
+ }
803
+ function De(t, e, n) {
804
+ var r;
805
+ return !!(e && n && t.deferExternalVariantGeometry && !((r = t.externalVariantBuffers) != null && r.has(e.id)));
806
+ }
807
+ function bt(t, e, n, r, s, o, i) {
808
+ if (s === 0)
809
+ return yt(i);
810
+ at(r, s, n.length, o);
811
+ const a = n.offset + r, u = a + s, c = Me(t, e, a, u, o, i);
812
+ if (c.offset !== u)
813
+ throw new f("E_GROUP_RANGE", `${o} has trailing bytes`);
814
+ return { chunk: c.chunk, snapshot: c.snapshot };
815
+ }
816
+ function Ft(t, e, n) {
817
+ if ([
818
+ t.getUint32(e + 8, !0),
819
+ t.getUint32(e + 12, !0),
820
+ t.getUint32(e + 16, !0),
821
+ t.getUint32(e + 20, !0),
822
+ t.getUint32(e + 24, !0),
823
+ t.getUint32(e + 28, !0)
824
+ ].some((s) => s !== 0))
825
+ throw new f("E_GROUP_RANGE", `V3 external variant ${n} must use zero inline geometry offsets`);
826
+ }
827
+ function ot(t, e, n, r, s, o) {
828
+ const i = Me(t, e, n, t.byteLength, s, o);
829
+ if (i.chunk.count !== r)
830
+ throw new f(
831
+ "E_GROUP_RANGE",
832
+ `${s} vertex_count mismatch: manifest=${r}, sidecar=${i.chunk.count}`
833
+ );
834
+ return i;
835
+ }
836
+ function xt(t) {
837
+ return "normal" in t ? t.normal : t;
838
+ }
839
+ function qn(t, e, n) {
840
+ const r = xt(t), s = new DataView(e);
841
+ let o = 0;
842
+ const i = ot(e, s, o, r.line_count, `V3 external variant ${t.id} line blob`, n);
843
+ o = i.offset;
844
+ const a = ot(e, s, o, r.fill_count, `V3 external variant ${t.id} fill blob`, n);
845
+ o = a.offset;
846
+ const u = ot(e, s, o, r.dot_count, `V3 external variant ${t.id} dot blob`, n);
847
+ if (o = u.offset, o !== e.byteLength)
848
+ throw new f("E_GROUP_RANGE", `V3 external variant ${t.id} sidecar has trailing bytes`);
849
+ return {
850
+ line: { chunk: i.chunk, snapshot: i.snapshot },
851
+ fill: { chunk: a.chunk, snapshot: a.snapshot },
852
+ dot: { chunk: u.chunk, snapshot: u.snapshot }
853
+ };
854
+ }
855
+ function Jn(t, e) {
856
+ const n = wn(e), r = pn(n, 257, "BLOCK_NORMAL_GEOMETRY"), s = new DataView(e);
857
+ let o = r.offset;
858
+ const i = r.offset + r.length, a = Ie(n.versionMinor), u = ot(e, s, o, t.normal.line_count, `V3.3 external variant ${t.id} normal line blob`, a);
859
+ o = u.offset;
860
+ const c = ot(e, s, o, t.normal.fill_count, `V3.3 external variant ${t.id} normal fill blob`, a);
861
+ o = c.offset;
862
+ const m = ot(e, s, o, t.normal.dot_count, `V3.3 external variant ${t.id} normal dot blob`, a);
863
+ if (o = m.offset, o !== i)
864
+ throw new f("E_GROUP_RANGE", `V3.3 external variant ${t.id} normal geometry section has trailing bytes`);
865
+ return {
866
+ line: { chunk: u.chunk, snapshot: u.snapshot },
867
+ fill: { chunk: c.chunk, snapshot: c.snapshot },
868
+ dot: { chunk: m.chunk, snapshot: m.snapshot }
869
+ };
870
+ }
871
+ function Zn(t, e, n = "u8") {
872
+ if (e.byteLength !== t.raw_size)
873
+ throw new f(
874
+ "E_GROUP_RANGE",
875
+ `V3 external variant ${t.id} raw_size mismatch: manifest=${t.raw_size}, sidecar=${e.byteLength}`
876
+ );
877
+ return "normal" in t ? Jn(t, e) : qn(t, e, n);
878
+ }
879
+ function Le(t, e, n) {
880
+ const r = e == null ? void 0 : e.get(t.id);
881
+ if (!r)
882
+ throw new f("E_GROUP_RANGE", `Missing V3 external sidecar buffer for variant ${t.id}`);
883
+ return Zn(t, r, n);
884
+ }
885
+ function At(t, e, n, r, s) {
886
+ if (r === 0)
887
+ return 0;
888
+ if (at(n, r, e.length, s), r < 4)
889
+ throw new f("E_GROUP_RANGE", `Missing ${s} vertex_count`);
890
+ return t.getUint32(e.offset + n, !0);
891
+ }
892
+ function Qn(t, e, n, r) {
893
+ const s = n.offset + n.length;
894
+ let o = n.offset;
895
+ const i = gt(t, e, o, s, "V3 BASE_GEOMETRY line", r);
896
+ o = i.offset;
897
+ const a = gt(t, e, o, s, "V3 BASE_GEOMETRY fill", r);
898
+ o = a.offset;
899
+ const u = gt(t, e, o, s, "V3 BASE_GEOMETRY dot", r);
900
+ if (o = u.offset, o !== s)
901
+ throw new f("E_GROUP_RANGE", "V3 BASE_GEOMETRY has trailing bytes");
902
+ return {
903
+ line: i.chunk,
904
+ fill: a.chunk,
905
+ dot: u.chunk
906
+ };
907
+ }
908
+ function It(t) {
909
+ return dn(t.pos, t.count, 2);
910
+ }
911
+ function Fe(t, e, n) {
912
+ return kt(kt(It(t), It(e)), It(n));
913
+ }
914
+ function Xt(t) {
915
+ return "normal" in t ? Hn(t.normal.bbox ?? t.normal.own_bbox ?? null) : null;
916
+ }
917
+ function tr(t, e, n, r, s, o, i, a) {
918
+ if (n.length % 60 !== 0)
919
+ throw new f("E_GROUP_RANGE", "V3 VARIANT_TABLE length must be a multiple of 60");
920
+ const u = [], c = /* @__PURE__ */ new Map(), m = [], g = n.length / 60;
921
+ for (let l = 0; l < g; l += 1) {
922
+ const d = n.offset + l * 60, p = e.getUint32(d, !0), h = e.getUint32(d + 4, !0), y = (o == null ? void 0 : o[l]) ?? null, w = !y || !a.requiredExternalVariantIds || a.requiredExternalVariantIds.has(l), _ = De(a, y, w), E = y ? (Ft(e, d, l), !w || _ ? ke(i) : Le(y, a.externalVariantBuffers, i)) : {
923
+ line: bt(
924
+ t,
925
+ e,
926
+ r,
927
+ e.getUint32(d + 8, !0),
928
+ e.getUint32(d + 12, !0),
929
+ `V3 variant ${l} line blob`,
930
+ i
931
+ ),
932
+ fill: bt(
933
+ t,
934
+ e,
935
+ r,
936
+ e.getUint32(d + 16, !0),
937
+ e.getUint32(d + 20, !0),
938
+ `V3 variant ${l} fill blob`,
939
+ i
940
+ ),
941
+ dot: bt(
942
+ t,
943
+ e,
944
+ r,
945
+ e.getUint32(d + 24, !0),
946
+ e.getUint32(d + 28, !0),
947
+ `V3 variant ${l} dot blob`,
948
+ i
949
+ )
950
+ }, A = y ? xt(y) : null, U = (A == null ? void 0 : A.line_count) ?? E.line.chunk.count, N = (A == null ? void 0 : A.fill_count) ?? E.fill.chunk.count, C = (A == null ? void 0 : A.dot_count) ?? E.dot.chunk.count, V = y && (!w || _) ? Xt(y) : Fe(E.line.chunk, E.fill.chunk, E.dot.chunk), G = {
951
+ id: l,
952
+ name: _t(s, p, h, `V3 variant ${l} name`),
953
+ line_count: _ ? U : E.line.chunk.count,
954
+ fill_count: _ ? N : E.fill.chunk.count,
955
+ dot_count: _ ? C : E.dot.chunk.count,
956
+ sourceLineCount: U,
957
+ sourceFillCount: N,
958
+ sourceDotCount: C,
959
+ nestedStart: e.getUint32(d + 32, !0),
960
+ nestedCount: e.getUint32(d + 36, !0),
961
+ textStart: e.getUint32(d + 40, !0),
962
+ textCount: e.getUint32(d + 44, !0),
963
+ precisionOriginX: e.getFloat32(d + 48, !0),
964
+ precisionOriginY: e.getFloat32(d + 52, !0),
965
+ lineSnapshot: E.line.snapshot,
966
+ fillSnapshot: E.fill.snapshot,
967
+ dotSnapshot: E.dot.snapshot,
968
+ bbox: V
969
+ };
970
+ u.push(G), c.set(l, { line: E.line.chunk, fill: E.fill.chunk, dot: E.dot.chunk }), m.push({ line: E.line.snapshot, fill: E.fill.snapshot, dot: E.dot.snapshot });
971
+ }
972
+ return { variantsById: u, variants: c, snapshots: m };
973
+ }
974
+ function fe(t, e, n, r, s) {
975
+ if (e.length % 60 !== 0)
976
+ throw new f("E_GROUP_RANGE", "V3 VARIANT_TABLE length must be a multiple of 60");
977
+ const o = [], i = e.length / 60;
978
+ for (let a = 0; a < i; a += 1) {
979
+ const u = e.offset + a * 60, c = t.getUint32(u, !0), m = t.getUint32(u + 4, !0), g = (s == null ? void 0 : s[a]) ?? null;
980
+ g && Ft(t, u, a);
981
+ const l = g ? xt(g) : null, d = t.getFloat32(u + 48, !0), p = t.getFloat32(u + 52, !0);
982
+ o.push({
983
+ id: a,
984
+ name: _t(r, c, m, `V3 variant ${a} name`),
985
+ line_count: g ? l.line_count : At(
986
+ t,
987
+ n,
988
+ t.getUint32(u + 8, !0),
989
+ t.getUint32(u + 12, !0),
990
+ `V3 variant ${a} line blob`
991
+ ),
992
+ fill_count: g ? l.fill_count : At(
993
+ t,
994
+ n,
995
+ t.getUint32(u + 16, !0),
996
+ t.getUint32(u + 20, !0),
997
+ `V3 variant ${a} fill blob`
998
+ ),
999
+ dot_count: g ? l.dot_count : At(
1000
+ t,
1001
+ n,
1002
+ t.getUint32(u + 24, !0),
1003
+ t.getUint32(u + 28, !0),
1004
+ `V3 variant ${a} dot blob`
1005
+ ),
1006
+ nestedStart: t.getUint32(u + 32, !0),
1007
+ nestedCount: t.getUint32(u + 36, !0),
1008
+ textStart: t.getUint32(u + 40, !0),
1009
+ textCount: t.getUint32(u + 44, !0),
1010
+ precisionOriginX: d,
1011
+ precisionOriginY: p,
1012
+ bbox: g ? Xt(g) : null
1013
+ });
1014
+ }
1015
+ return o;
1016
+ }
1017
+ function er(t, e, n) {
1018
+ var a;
1019
+ const r = new DataView(t), s = [], o = /* @__PURE__ */ new Map(), i = [];
1020
+ for (const u of e.variantHeaders) {
1021
+ const c = ((a = e.externalVariants) == null ? void 0 : a[u.id]) ?? null, m = !c || !n.requiredExternalVariantIds || n.requiredExternalVariantIds.has(u.id), g = De(n, c, m), l = c ? (() => {
1022
+ const E = e.sections.get(5).offset + u.id * 60;
1023
+ return Ft(r, E, u.id), !m || g ? ke(e.groupLayerEncoding) : Le(c, n.externalVariantBuffers, e.groupLayerEncoding);
1024
+ })() : e.internalVariants.get(u.id);
1025
+ if (!l)
1026
+ throw new f("E_GROUP_RANGE", `Missing cached V3 variant geometry for variant ${u.id}`);
1027
+ const d = c ? xt(c) : null, p = (d == null ? void 0 : d.line_count) ?? l.line.chunk.count, h = (d == null ? void 0 : d.fill_count) ?? l.fill.chunk.count, y = (d == null ? void 0 : d.dot_count) ?? l.dot.chunk.count, w = c && (!m || g) ? Xt(c) : Fe(l.line.chunk, l.fill.chunk, l.dot.chunk), _ = {
1028
+ ...u,
1029
+ line_count: g ? p : l.line.chunk.count,
1030
+ fill_count: g ? h : l.fill.chunk.count,
1031
+ dot_count: g ? y : l.dot.chunk.count,
1032
+ sourceLineCount: p,
1033
+ sourceFillCount: h,
1034
+ sourceDotCount: y,
1035
+ lineSnapshot: l.line.snapshot,
1036
+ fillSnapshot: l.fill.snapshot,
1037
+ dotSnapshot: l.dot.snapshot,
1038
+ bbox: w
1039
+ };
1040
+ s.push(_), o.set(u.id, { line: l.line.chunk, fill: l.fill.chunk, dot: l.dot.chunk }), i.push({ line: l.line.snapshot, fill: l.fill.snapshot, dot: l.dot.snapshot });
1041
+ }
1042
+ return { variantsById: s, variants: o, snapshots: i };
1043
+ }
1044
+ function mt(t, e, n) {
1045
+ if (e.length % 32 !== 0)
1046
+ throw new f("E_GROUP_RANGE", `${n} length must be a multiple of 32`);
1047
+ const r = new DataView(t), s = [];
1048
+ for (let o = e.offset; o < e.offset + e.length; o += 32) {
1049
+ const i = r.getUint16(o + 30, !0);
1050
+ dr(i), s.push({
1051
+ variantId: r.getUint32(o, !0),
1052
+ matA: r.getFloat32(o + 4, !0),
1053
+ matB: r.getFloat32(o + 8, !0),
1054
+ matC: r.getFloat32(o + 12, !0),
1055
+ matD: r.getFloat32(o + 16, !0),
1056
+ tx: r.getFloat32(o + 20, !0),
1057
+ ty: r.getFloat32(o + 24, !0),
1058
+ insLayerIdx: r.getUint16(o + 28, !0),
1059
+ flags: i
1060
+ });
1061
+ }
1062
+ return s;
1063
+ }
1064
+ function nr(t, e, n) {
1065
+ const r = t.getUint32(e, !0), s = t.getUint32(e + 4, !0), o = t.getUint8(e + 42), i = t.getUint8(e + 43), a = t.getFloat32(e + 24, !0), u = t.getFloat32(e + 28, !0);
1066
+ return {
1067
+ t: _t(n, r, s, "V3 text value"),
1068
+ x: t.getFloat32(e + 8, !0),
1069
+ y: t.getFloat32(e + 12, !0),
1070
+ h: t.getFloat32(e + 16, !0),
1071
+ r: t.getFloat32(e + 20, !0),
1072
+ c: [t.getUint8(e + 36), t.getUint8(e + 37), t.getUint8(e + 38)],
1073
+ li: t.getUint16(e + 40, !0),
1074
+ ha: Gn[o & 3] ?? "left",
1075
+ va: Nn[o >> 2 & 3] ?? "alphabetic",
1076
+ lh: t.getFloat32(e + 32, !0),
1077
+ ...a ? { w: a } : {},
1078
+ ...u !== 1 ? { wf: u } : {},
1079
+ ...i & 1 ? { mx: !0 } : {},
1080
+ ...i & 2 ? { my: !0 } : {}
1081
+ };
1082
+ }
1083
+ function Rt(t, e, n, r) {
1084
+ if (e.length % 44 !== 0)
1085
+ throw new f("E_GROUP_RANGE", `${r} length must be a multiple of 44`);
1086
+ const s = [], o = new DataView(t);
1087
+ for (let i = e.offset; i < e.offset + e.length; i += 44)
1088
+ s.push(nr(o, i, n));
1089
+ return s;
1090
+ }
1091
+ function rr(t, e) {
1092
+ if (t.length % 44 !== 0)
1093
+ throw new f("E_GROUP_RANGE", `${e} length must be a multiple of 44`);
1094
+ return t.length / 44;
1095
+ }
1096
+ function or(t, e, n, r) {
1097
+ return {
1098
+ instanceId: n,
1099
+ variantId: e.variantId,
1100
+ matA: t.matA * e.matA + t.matC * e.matB,
1101
+ matB: t.matB * e.matA + t.matD * e.matB,
1102
+ matC: t.matA * e.matC + t.matC * e.matD,
1103
+ matD: t.matB * e.matC + t.matD * e.matD,
1104
+ tx: t.matA * e.tx + t.matC * e.ty + t.tx,
1105
+ ty: t.matB * e.tx + t.matD * e.ty + t.ty,
1106
+ insLayerIdx: r
1107
+ };
1108
+ }
1109
+ function sr(t, e, n, r) {
1110
+ var h;
1111
+ const s = ((h = r[e.insLayerIdx]) == null ? void 0 : h.visible) === !1, o = e.matA * t.x + e.matC * t.y + e.tx, i = e.matB * t.x + e.matD * t.y + e.ty, a = Math.hypot(e.matA, e.matB), u = Math.hypot(e.matC, e.matD), c = u > 1e-12 ? u : a > 1e-12 ? a : 1, m = a > 1e-12 && c > 1e-12 ? a / c : 1, g = ir(t, e), { mx: l, my: d, ...p } = t;
1112
+ return {
1113
+ ...p,
1114
+ x: o,
1115
+ y: i,
1116
+ h: t.h * c,
1117
+ w: t.w === void 0 ? void 0 : t.w * c,
1118
+ wf: (t.wf ?? 1) * m,
1119
+ r: g.r,
1120
+ ...g.mx ? { mx: !0 } : {},
1121
+ ...g.my ? { my: !0 } : {},
1122
+ li: s || t.li === n ? e.insLayerIdx : t.li
1123
+ };
1124
+ }
1125
+ function ir(t, e) {
1126
+ const n = t.r * Math.PI / 180, r = Math.cos(n), s = Math.sin(n), o = t.mx ? -1 : 1, i = t.my ? -1 : 1, a = o * (e.matA * r + e.matC * s), u = o * (e.matB * r + e.matD * s), c = i * (e.matC * r - e.matA * s), m = i * (e.matD * r - e.matB * s), g = a * m - u * c, l = Math.atan2(u, a) * 180 / Math.PI;
1127
+ return g < 0 ? { r: Math.atan2(-u, -a) * 180 / Math.PI, mx: !0 } : { r: l };
1128
+ }
1129
+ function ar(t, e) {
1130
+ return t === e ? e : t;
1131
+ }
1132
+ function ur(t, e, n) {
1133
+ return t === n ? e : t;
1134
+ }
1135
+ function lr(t, e, n) {
1136
+ const r = new DataView(t), s = n ? void 0 : Ln(t), o = (n == null ? void 0 : n.versionMinor) ?? s.versionMinor, i = (n == null ? void 0 : n.sections) ?? s.sections, a = (n == null ? void 0 : n.groupLayerEncoding) ?? Ie(o), u = n ? n.sections.get(1) : tt(i, 1, "SCENE_META"), c = n ? n.sections.get(2) : tt(i, 2, "LAYER_TABLE"), m = n ? n.sections.get(3) : tt(i, 3, "STRING_TABLE"), g = n ? n.sections.get(4) : tt(i, 4, "BASE_GEOMETRY"), l = n ? n.sections.get(5) : tt(i, 5, "VARIANT_TABLE"), d = n ? n.sections.get(6) : tt(i, 6, "VARIANT_GEOMETRY"), p = n ? n.sections.get(7) : tt(i, 7, "SCENE_INSTANCE_TABLE"), h = (n == null ? void 0 : n.sections.get(8)) ?? pt(i, 8), y = (n == null ? void 0 : n.sections.get(9)) ?? pt(i, 9), w = (n == null ? void 0 : n.sections.get(10)) ?? pt(i, 10), _ = (n == null ? void 0 : n.sceneMeta) ?? Fn(t, u, "SCENE_META"), E = (n == null ? void 0 : n.externalVariants) ?? (Xn(_) ? Kn(_, l.length / 60) : null), A = Yn(_), U = (n == null ? void 0 : n.externalAnnotations) ?? (A ? jn(_) : null), N = (n == null ? void 0 : n.geoMetaFeatures) ?? zn(_, E, A), C = (n == null ? void 0 : n.geoMetaEncoding) ?? (A ? "nested_instanced_external_annotations" : E ? "nested_instanced_external" : "nested_instanced"), V = (n == null ? void 0 : n.stringTable) ?? new Uint8Array(t, m.offset, m.length), G = n != null && n.layers ? [...n.layers] : Wn(t, c, V), $ = (n == null ? void 0 : n.layer0Index) ?? Number(_.layer0_index ?? 0), M = (n == null ? void 0 : n.headerForValidation) ?? Pe({
1137
+ bounds: _.bounds ?? [0, 0, 0, 0],
1138
+ entity_count: Number(_.entity_count ?? 0),
1139
+ line_count: Number(_.base_line_count ?? 0),
1140
+ fill_count: Number(_.base_fill_count ?? 0),
1141
+ dot_count: Number(_.base_dot_count ?? 0),
1142
+ layers: G,
1143
+ texts: []
1144
+ });
1145
+ fr($, M.layers);
1146
+ const I = (n == null ? void 0 : n.baseGeometry) ?? Qn(t, r, g, a);
1147
+ if (!e.loadBlocks) {
1148
+ const x = (n == null ? void 0 : n.variantHeaders) ?? fe(r, l, d, V, E), b = (n == null ? void 0 : n.sceneInstances) ?? mt(t, p, "V3 SCENE_INSTANCE_TABLE"), B = (n == null ? void 0 : n.nestedInstances) ?? mt(t, h, "V3 NESTED_INSTANCE_TABLE"), S = (n == null ? void 0 : n.sceneTexts) ?? Rt(t, y, V, "V3 SCENE_TEXT_TABLE"), O = (n == null ? void 0 : n.variantTextCount) ?? rr(w, "V3 VARIANT_TEXT_TABLE");
1149
+ if (Number(_.variant_count ?? x.length) !== x.length)
1150
+ throw new f("E_GROUP_RANGE", "V3 variant count mismatch");
1151
+ if (Number(_.scene_instance_count ?? b.length) !== b.length)
1152
+ throw new f("E_GROUP_RANGE", "V3 scene instance count mismatch");
1153
+ if (Number(_.nested_instance_count ?? B.length) !== B.length)
1154
+ throw new f("E_GROUP_RANGE", "V3 nested instance count mismatch");
1155
+ if (Number(_.scene_text_count ?? S.length) !== S.length)
1156
+ throw new f("E_GROUP_RANGE", "V3 scene text count mismatch");
1157
+ if (Number(_.variant_text_count ?? O) !== O)
1158
+ throw new f("E_GROUP_RANGE", "V3 variant text count mismatch");
1159
+ for (const R of x) {
1160
+ if (R.nestedStart + R.nestedCount > B.length)
1161
+ throw new f("E_GROUP_RANGE", `V3 variant ${R.id} nested range exceeds table`);
1162
+ if (R.textStart + R.textCount > O)
1163
+ throw new f("E_GROUP_RANGE", `V3 variant ${R.id} text range exceeds table`);
1164
+ }
1165
+ return ue(b, B, (R) => {
1166
+ if (!x[R.variantId])
1167
+ throw new f("E_GROUP_RANGE", `Unknown V3 variantId ${R.variantId}`);
1168
+ ye(R.insLayerIdx, G.length);
1169
+ }), {
1170
+ meta: {
1171
+ bounds: _.bounds ?? [0, 0, 0, 0],
1172
+ entity_count: Number(_.entity_count ?? 0),
1173
+ line_count: I.line.count,
1174
+ fill_count: I.fill.count,
1175
+ dot_count: I.dot.count,
1176
+ version: 3,
1177
+ version_minor: o,
1178
+ encoding: C,
1179
+ ...N ? { features: N } : {},
1180
+ ...E ? { external_variants: [...E] } : {},
1181
+ ...U ? { external_annotations: U } : {},
1182
+ layer0_index: $,
1183
+ block_variants: x.map((R) => ({
1184
+ id: R.id,
1185
+ name: R.name,
1186
+ line_count: R.line_count,
1187
+ fill_count: R.fill_count,
1188
+ dot_count: R.dot_count
1189
+ })),
1190
+ instance_count: b.length,
1191
+ layers: G,
1192
+ texts: S
1193
+ },
1194
+ header: {
1195
+ ...M,
1196
+ lineCount: I.line.count,
1197
+ fillCount: I.fill.count,
1198
+ dotCount: I.dot.count,
1199
+ textCount: S.length,
1200
+ texts: S
1201
+ },
1202
+ decoded: {
1203
+ baseLine: I.line,
1204
+ baseFill: I.fill,
1205
+ baseDot: I.dot,
1206
+ variants: /* @__PURE__ */ new Map(),
1207
+ instances: [],
1208
+ instanceIdByVariantOrdinal: /* @__PURE__ */ new Map()
1209
+ }
1210
+ };
1211
+ }
1212
+ const T = n ? er(t, n, e) : tr(
1213
+ t,
1214
+ r,
1215
+ l,
1216
+ d,
1217
+ V,
1218
+ E,
1219
+ a,
1220
+ e
1221
+ ), { variantsById: P, variants: k, snapshots: D } = T, v = (n == null ? void 0 : n.sceneInstances) ?? mt(t, p, "V3 SCENE_INSTANCE_TABLE"), et = (n == null ? void 0 : n.nestedInstances) ?? mt(t, h, "V3 NESTED_INSTANCE_TABLE"), ut = (n == null ? void 0 : n.sceneTexts) ?? Rt(t, y, V, "V3 SCENE_TEXT_TABLE"), W = (n == null ? void 0 : n.variantTexts) ?? Rt(t, w, V, "V3 VARIANT_TEXT_TABLE");
1222
+ if (Number(_.variant_count ?? P.length) !== P.length)
1223
+ throw new f("E_GROUP_RANGE", "V3 variant count mismatch");
1224
+ if (Number(_.scene_instance_count ?? v.length) !== v.length)
1225
+ throw new f("E_GROUP_RANGE", "V3 scene instance count mismatch");
1226
+ if (Number(_.nested_instance_count ?? et.length) !== et.length)
1227
+ throw new f("E_GROUP_RANGE", "V3 nested instance count mismatch");
1228
+ if (Number(_.scene_text_count ?? ut.length) !== ut.length)
1229
+ throw new f("E_GROUP_RANGE", "V3 scene text count mismatch");
1230
+ if (Number(_.variant_text_count ?? W.length) !== W.length)
1231
+ throw new f("E_GROUP_RANGE", "V3 variant text count mismatch");
1232
+ for (const x of P) {
1233
+ if (x.nestedStart + x.nestedCount > et.length)
1234
+ throw new f("E_GROUP_RANGE", `V3 variant ${x.id} nested range exceeds table`);
1235
+ if (x.textStart + x.textCount > W.length)
1236
+ throw new f("E_GROUP_RANGE", `V3 variant ${x.id} text range exceeds table`);
1237
+ }
1238
+ ue(v, et, (x) => {
1239
+ if (!P[x.variantId])
1240
+ throw new f("E_GROUP_RANGE", `Unknown V3 variantId ${x.variantId}`);
1241
+ ye(x.insLayerIdx, G.length);
1242
+ });
1243
+ const Yt = (n == null ? void 0 : n.variantTextsByVariantId) ?? (() => {
1244
+ const x = /* @__PURE__ */ new Map();
1245
+ for (const b of P)
1246
+ x.set(
1247
+ b.id,
1248
+ W.slice(b.textStart, b.textStart + b.textCount)
1249
+ );
1250
+ return x;
1251
+ })(), lt = [], L = e.externalVariantDeltaOnly, zt = L ? [] : [...ut], Et = /* @__PURE__ */ new Map(), ct = /* @__PURE__ */ new Map(), Ht = /* @__PURE__ */ new Map(), We = (x, b) => {
1252
+ Et.set(x, kt(Et.get(x) ?? null, b));
1253
+ }, Kt = (x, b, B, S, O, q) => {
1254
+ var Qt;
1255
+ if (O > 64)
1256
+ throw new f("E_GROUP_RANGE", "V3 nested instance depth exceeds limit");
1257
+ if (q.has(x))
1258
+ throw new f("E_GROUP_RANGE", `V3 nested variant cycle detected at ${x}`);
1259
+ const R = P[x];
1260
+ if (!R)
1261
+ throw new f("E_GROUP_RANGE", `Unknown V3 variantId ${x}`);
1262
+ q.add(x);
1263
+ const J = !e.requiredExternalVariantIds || e.requiredExternalVariantIds.has(x), z = L ? ((Qt = e.requiredExternalVariantIds) == null ? void 0 : Qt.has(x)) === !0 : J;
1264
+ let F = !1;
1265
+ const Zt = !!(R.line_count || R.fill_count || R.dot_count), Qe = R.textCount > 0;
1266
+ if (z && (Zt || Qe) && (lt.push({
1267
+ instanceId: b.instanceId,
1268
+ variantId: x,
1269
+ matA: b.matA,
1270
+ matB: b.matB,
1271
+ matC: b.matC,
1272
+ matD: b.matD,
1273
+ tx: b.tx,
1274
+ ty: b.ty,
1275
+ insLayerIdx: b.insLayerIdx
1276
+ }), Zt && We(b.instanceId, R.bbox ? Xe(R.bbox, b) : null), F = !0), z) {
1277
+ R.textCount > 0 && (F = !0);
1278
+ for (let Z = 0; Z < R.textCount; Z += 1) {
1279
+ const nt = sr(W[R.textStart + Z], b, $, M.layers);
1280
+ zt.push({
1281
+ ...nt,
1282
+ iv: B,
1283
+ io: S
1284
+ });
1285
+ }
1286
+ }
1287
+ for (let Z = 0; Z < R.nestedCount; Z += 1) {
1288
+ const nt = et[R.nestedStart + Z], tn = ur(nt.insLayerIdx, b.insLayerIdx, $), en = cr(nt, R, P[nt.variantId]), nn = or(b, en, b.instanceId, tn);
1289
+ F = Kt(nt.variantId, nn, B, S, O + 1, q) || F;
1290
+ }
1291
+ return q.delete(x), F;
1292
+ }, wt = /* @__PURE__ */ new Map();
1293
+ v.forEach((x, b) => {
1294
+ if (!P[x.variantId])
1295
+ throw new f("E_GROUP_RANGE", `Unknown V3 scene variantId ${x.variantId}`);
1296
+ const S = Ht.get(x.variantId) ?? 0;
1297
+ Ht.set(x.variantId, S + 1), ct.set(`${x.variantId}:${S}`, b);
1298
+ const O = ar(x.insLayerIdx, $), q = {
1299
+ instanceId: b,
1300
+ variantId: x.variantId,
1301
+ matA: x.matA,
1302
+ matB: x.matB,
1303
+ matC: x.matC,
1304
+ matD: x.matD,
1305
+ tx: x.tx,
1306
+ ty: x.ty,
1307
+ insLayerIdx: O
1308
+ }, R = Kt(x.variantId, q, x.variantId, S, 0, /* @__PURE__ */ new Set());
1309
+ if (L && !R)
1310
+ return;
1311
+ let J = wt.get(O);
1312
+ J || (J = /* @__PURE__ */ new Map(), wt.set(O, J));
1313
+ let z = J.get(x.variantId);
1314
+ z || (z = { count: 0, bboxes: [], inserts: [] }, J.set(x.variantId, z)), z.count += 1;
1315
+ const F = Et.get(b) ?? null;
1316
+ F && z.bboxes.push(F), z.inserts.push({
1317
+ instanceId: b,
1318
+ variantId: x.variantId,
1319
+ label: `#${b + 1} (${x.tx.toFixed(1)}, ${x.ty.toFixed(1)})`,
1320
+ tx: x.tx,
1321
+ ty: x.ty,
1322
+ canHighlight: F !== null,
1323
+ ...F ? { bbox: F } : {}
1324
+ });
1325
+ });
1326
+ const jt = /* @__PURE__ */ new Map();
1327
+ for (const [x, b] of wt) {
1328
+ const B = [];
1329
+ for (const [S, O] of b)
1330
+ B.push({
1331
+ variantId: S,
1332
+ blockName: $e(P[S], S),
1333
+ instanceCount: O.count,
1334
+ bboxes: O.bboxes,
1335
+ inserts: O.inserts
1336
+ });
1337
+ B.sort((S, O) => O.instanceCount - S.instanceCount), jt.set(x, B);
1338
+ }
1339
+ let Wt = L ? 0 : I.line.count, qt = L ? 0 : I.fill.count, Jt = L ? 0 : I.dot.count;
1340
+ for (const x of lt) {
1341
+ const b = P[x.variantId];
1342
+ e.deferExternalVariantGeometry && b.lineSnapshot.count === 0 && b.fillSnapshot.count === 0 && b.dotSnapshot.count === 0 || !Be(x.instanceId, e) || (Wt += b.line_count, qt += b.fill_count, Jt += b.dot_count);
1343
+ }
1344
+ const ft = $n(zt, ct, e), qe = {
1345
+ bounds: _.bounds ?? [0, 0, 0, 0],
1346
+ entity_count: L ? 0 : Number(_.entity_count ?? 0),
1347
+ line_count: I.line.count,
1348
+ fill_count: I.fill.count,
1349
+ dot_count: I.dot.count,
1350
+ version: 3,
1351
+ version_minor: o,
1352
+ encoding: C,
1353
+ ...N ? { features: N } : {},
1354
+ ...E ? { external_variants: [...E] } : {},
1355
+ ...U ? { external_annotations: U } : {},
1356
+ layer0_index: $,
1357
+ block_variants: P.map((x) => ({
1358
+ id: x.id,
1359
+ name: x.name,
1360
+ line_count: x.sourceLineCount,
1361
+ fill_count: x.sourceFillCount,
1362
+ dot_count: x.sourceDotCount
1363
+ })),
1364
+ instance_count: v.length,
1365
+ layers: G,
1366
+ texts: ft
1367
+ }, Je = {
1368
+ ...M,
1369
+ entityCount: L ? 0 : M.entityCount,
1370
+ lineCount: Wt,
1371
+ fillCount: qt,
1372
+ dotCount: Jt,
1373
+ textCount: ft.length,
1374
+ texts: ft,
1375
+ ...e.loadBlocks ? {
1376
+ layerBlockUsages: jt,
1377
+ insertRuntime: On(
1378
+ $,
1379
+ P,
1380
+ D,
1381
+ Yt,
1382
+ lt,
1383
+ ft,
1384
+ ct
1385
+ )
1386
+ } : {}
1387
+ }, Ze = n ?? (e.cacheDocument ? (() => {
1388
+ const x = /* @__PURE__ */ new Map();
1389
+ for (const [b, B] of k)
1390
+ E != null && E[b] || x.set(b, {
1391
+ line: { chunk: B.line, snapshot: D[b].line },
1392
+ fill: { chunk: B.fill, snapshot: D[b].fill },
1393
+ dot: { chunk: B.dot, snapshot: D[b].dot }
1394
+ });
1395
+ return {
1396
+ kind: "dxb3-v3",
1397
+ buffer: t,
1398
+ versionMinor: o,
1399
+ sections: i,
1400
+ groupLayerEncoding: a,
1401
+ sceneMeta: _,
1402
+ externalVariants: E,
1403
+ externalAnnotations: U,
1404
+ geoMetaFeatures: N,
1405
+ geoMetaEncoding: C,
1406
+ stringTable: V,
1407
+ layers: G,
1408
+ layer0Index: $,
1409
+ headerForValidation: M,
1410
+ baseGeometry: I,
1411
+ variantHeaders: fe(
1412
+ r,
1413
+ l,
1414
+ d,
1415
+ V,
1416
+ E
1417
+ ),
1418
+ internalVariants: x,
1419
+ sceneInstances: v,
1420
+ nestedInstances: et,
1421
+ sceneTexts: ut,
1422
+ variantTexts: W,
1423
+ variantTextCount: W.length,
1424
+ variantTextsByVariantId: Yt
1425
+ };
1426
+ })() : void 0);
1427
+ return {
1428
+ meta: qe,
1429
+ header: Je,
1430
+ documentCache: Ze,
1431
+ decoded: {
1432
+ baseLine: L ? Gt() : I.line,
1433
+ baseFill: L ? Gt() : I.fill,
1434
+ baseDot: L ? Gt() : I.dot,
1435
+ variants: k,
1436
+ instances: lt,
1437
+ instanceIdByVariantOrdinal: ct
1438
+ }
1439
+ };
1440
+ }
1441
+ function kt(t, e) {
1442
+ return Ce(t, e);
1443
+ }
1444
+ function Xe(t, e) {
1445
+ return Se(t, e);
1446
+ }
1447
+ function de(t) {
1448
+ return mn(t);
1449
+ }
1450
+ function me(t, e) {
1451
+ return gn(t, e);
1452
+ }
1453
+ function ge(t, e) {
1454
+ return Xe(t, {
1455
+ variantId: e.variantId,
1456
+ matA: e.matA,
1457
+ matB: e.matB,
1458
+ matC: e.matC,
1459
+ matD: e.matD,
1460
+ tx: e.tx,
1461
+ ty: e.ty,
1462
+ insLayerIdx: e.insLayerIdx
1463
+ });
1464
+ }
1465
+ function cr(t, e, n) {
1466
+ if (!(n != null && n.bbox) || !e.bbox)
1467
+ return t;
1468
+ const r = e.precisionOriginX, s = e.precisionOriginY;
1469
+ if (!Number.isFinite(r) || !Number.isFinite(s) || r === 0 && s === 0)
1470
+ return t;
1471
+ const o = {
1472
+ ...t,
1473
+ tx: t.tx - r,
1474
+ ty: t.ty - s
1475
+ }, i = ge(n.bbox, t), a = ge(n.bbox, o), u = Math.max(de(e.bbox), de(n.bbox), 1), c = Math.hypot(r, s), m = Math.hypot(t.tx, t.ty), g = Math.hypot(o.tx, o.ty);
1476
+ if (c <= u * 16 || m <= u * 16)
1477
+ return t;
1478
+ const l = me(e.bbox, i), d = me(e.bbox, a);
1479
+ return l > u * 16 && d * 4 < l && g * 4 < m ? o : t;
1480
+ }
1481
+ function ye(t, e) {
1482
+ if (t >= e)
1483
+ throw new f("E_GROUP_RANGE", `Instance layer index ${t} exceeds layer count ${e}`);
1484
+ }
1485
+ function fr(t, e) {
1486
+ if (!Number.isInteger(t) || t < 0 || t >= e.length)
1487
+ throw new f("E_GROUP_RANGE", `layer0_index out of range: ${t}`);
1488
+ if (e[t].name !== "0")
1489
+ throw new f("E_GROUP_RANGE", `layer0_index must reference layer "0": ${t}`);
1490
+ }
1491
+ function dr(t) {
1492
+ if (t !== 0)
1493
+ throw new f("E_GROUP_RANGE", `Instance flags must be zero for Stage 1, found ${t}`);
1494
+ }
1495
+ function* mr(t, e, n, r, s) {
1496
+ let o = n;
1497
+ const i = [
1498
+ { kind: "line", count: r.lineCount },
1499
+ { kind: "fill", count: r.fillCount },
1500
+ { kind: "dot", count: r.dotCount }
1501
+ ];
1502
+ for (const a of i) {
1503
+ const u = fn(t, e, o, a.count);
1504
+ for (; ; ) {
1505
+ const c = u.next();
1506
+ if (c.done) {
1507
+ o = c.value;
1508
+ break;
1509
+ }
1510
+ yield { kind: a.kind, payload: c.value };
1511
+ }
1512
+ }
1513
+ if (o !== t.byteLength)
1514
+ throw new f("E_GROUP_RANGE", `Trailing bytes detected: offset=${o}, size=${t.byteLength}`);
1515
+ for (const a of r.texts)
1516
+ yield { kind: "text", payload: a };
1517
+ }
1518
+ function* gr(t, e, n, r) {
1519
+ yield* mr(t, e, n, r);
1520
+ }
1521
+ function* Vt(t, e, n, r, s, o, i, a) {
1522
+ if (Bn(a, t, Math.max(0, e - n.count)), e === 0) {
1523
+ yield { kind: t, payload: bn() };
1524
+ return;
1525
+ }
1526
+ const u = Bt;
1527
+ let c = new Float32Array(u * 2), m = [], g = 0, l = 0;
1528
+ const d = function* () {
1529
+ if (g <= 0)
1530
+ return;
1531
+ const y = g === u ? { pos: c, count: g, segments: ae(m) } : { pos: c.slice(0, g * 2), count: g, segments: ae(m) };
1532
+ yield { kind: t, payload: y }, l += g, g = 0, c = new Float32Array(u * 2), m = [];
1533
+ }, p = (y, w, _, E) => {
1534
+ if (y <= 0)
1535
+ return;
1536
+ const A = m[m.length - 1];
1537
+ if (A && A.startVertex + A.vertexCount === g && A.layerIndex === _ && A.color[0] === w[0] && A.color[1] === w[1] && A.color[2] === w[2] && A.lineweightPx === E) {
1538
+ m[m.length - 1] = {
1539
+ ...A,
1540
+ vertexCount: A.vertexCount + y
1541
+ };
1542
+ return;
1543
+ }
1544
+ m.push({
1545
+ startVertex: g,
1546
+ vertexCount: y,
1547
+ color: [w[0], w[1], w[2]],
1548
+ layerIndex: _,
1549
+ ...E === void 0 ? {} : { lineweightPx: E }
1550
+ });
1551
+ };
1552
+ yield* function* () {
1553
+ for (const y of Ot(n)) {
1554
+ let w = y.startVertex;
1555
+ const _ = y.startVertex + y.vertexCount;
1556
+ for (; w < _; ) {
1557
+ const E = Math.min(u - g, _ - w), A = w * 2, U = g * 2;
1558
+ c.set(n.pos.subarray(A, A + E * 2), U), p(E, y.color, y.layerIndex, y.lineweightPx), w += E, g += E, g === u && (yield* d());
1559
+ }
1560
+ }
1561
+ }();
1562
+ for (const y of s) {
1563
+ if (!Be(y.instanceId, a))
1564
+ continue;
1565
+ const w = r.get(y.variantId);
1566
+ if (!w)
1567
+ throw new f("E_GROUP_RANGE", `Unknown variantId ${y.variantId}`);
1568
+ const _ = w[t], E = i[y.insLayerIdx].visible === !1;
1569
+ for (const A of Ot(_)) {
1570
+ const U = E || A.layerIndex === o ? y.insLayerIdx : A.layerIndex;
1571
+ let N = A.startVertex;
1572
+ const C = A.startVertex + A.vertexCount;
1573
+ for (; N < C; ) {
1574
+ const V = Math.min(u - g, C - N);
1575
+ for (let G = 0; G < V; G += 1) {
1576
+ const $ = (N + G) * 2, M = (g + G) * 2, I = _.pos[$], T = _.pos[$ + 1];
1577
+ c[M] = y.matA * I + y.matC * T + y.tx, c[M + 1] = y.matB * I + y.matD * T + y.ty;
1578
+ }
1579
+ p(V, A.color, U, A.lineweightPx), N += V, g += V, g === u && (yield* d());
1580
+ }
1581
+ }
1582
+ }
1583
+ if (yield* d(), l !== e)
1584
+ throw new f("E_GROUP_RANGE", `Expanded ${t} count mismatch: header=${e}, emitted=${l}`);
1585
+ }
1586
+ function* yr(t, e, n, r) {
1587
+ yield* Vt(
1588
+ "line",
1589
+ e.lineCount,
1590
+ t.baseLine,
1591
+ t.variants,
1592
+ t.instances,
1593
+ n.layer0_index,
1594
+ e.layers,
1595
+ r
1596
+ ), yield* Vt(
1597
+ "fill",
1598
+ e.fillCount,
1599
+ t.baseFill,
1600
+ t.variants,
1601
+ t.instances,
1602
+ n.layer0_index,
1603
+ e.layers,
1604
+ r
1605
+ ), yield* Vt(
1606
+ "dot",
1607
+ e.dotCount,
1608
+ t.baseDot,
1609
+ t.variants,
1610
+ t.instances,
1611
+ n.layer0_index,
1612
+ e.layers,
1613
+ r
1614
+ );
1615
+ for (const s of e.texts)
1616
+ yield { kind: "text", payload: s };
1617
+ }
1618
+ function Ye(t, e, n) {
1619
+ const r = Tn(e), s = lr(t, r, n);
1620
+ return s.documentCache && Te.add(s.documentCache), {
1621
+ header: s.header,
1622
+ ...s.documentCache ? { documentCache: s.documentCache } : {},
1623
+ chunks: yr(
1624
+ s.decoded,
1625
+ s.header,
1626
+ { layer0_index: s.meta.layer0_index ?? 0 },
1627
+ r
1628
+ )
1629
+ };
1630
+ }
1631
+ function ze(t, e) {
1632
+ if (ve(t))
1633
+ return Ye(t, e);
1634
+ const n = Dn(t);
1635
+ return {
1636
+ header: n.header,
1637
+ chunks: gr(t, n.view, n.dataOffset, n.header)
1638
+ };
1639
+ }
1640
+ function hr(t, e, n) {
1641
+ return e.kind !== "dxb3-v3" || e.buffer !== t || !Te.has(e) || !ve(t) ? ze(t, n) : Ye(t, n, e);
1642
+ }
1643
+ function Gt() {
1644
+ return {
1645
+ pos: new Float32Array(0),
1646
+ col: new Uint8Array(0),
1647
+ lay: new Uint8Array(0),
1648
+ count: 0
1649
+ };
1650
+ }
1651
+ function _r(t, e) {
1652
+ return t ? ht(Se(t, e)) : null;
1653
+ }
1654
+ async function xr(t) {
1655
+ const e = he(), n = t.fetchImpl ?? fetch, r = new Map(
1656
+ t.entries.map((a) => [a.id, a])
1657
+ ), s = Array.from(new Set(t.requiredVariantIds)).sort((a, u) => a - u), o = /* @__PURE__ */ new Map();
1658
+ async function i(a) {
1659
+ var l;
1660
+ const u = r.get(a);
1661
+ if (!u)
1662
+ throw new Error(`External block ${a} is missing from manifest`);
1663
+ const c = new URL(u.href, t.baseUrl).href, m = await n(c, { signal: t.signal });
1664
+ if (!m.ok) {
1665
+ const d = "status" in m ? m.status : void 0, p = "statusText" in m ? m.statusText : void 0, h = [d, p].filter((y) => y !== void 0 && y !== "").join(" ");
1666
+ throw new Error(`External block ${a} fetch failed${h ? `: ${h}` : ""}`);
1667
+ }
1668
+ const g = await m.arrayBuffer();
1669
+ if (g.byteLength !== u.raw_size)
1670
+ throw new Error(
1671
+ `External block ${a} raw_size mismatch: manifest=${u.raw_size}, response=${g.byteLength}`
1672
+ );
1673
+ o.set(a, g), await ((l = t.onBuffer) == null ? void 0 : l.call(t, a, g));
1674
+ }
1675
+ return await Promise.all(s.map(i)), { buffers: o, fetchMs: he() - e };
1676
+ }
1677
+ function he() {
1678
+ var t, e;
1679
+ return ((e = (t = globalThis.performance) == null ? void 0 : t.now) == null ? void 0 : e.call(t)) ?? Date.now();
1680
+ }
1681
+ var j;
1682
+ class Er {
1683
+ constructor() {
1684
+ ee(this, j, /* @__PURE__ */ new Map());
1685
+ }
1686
+ get size() {
1687
+ return rt(this, j).size;
1688
+ }
1689
+ append(e) {
1690
+ let n = 0;
1691
+ for (const r of e) {
1692
+ if (r.count <= 0) continue;
1693
+ const s = Dt(r.layerIndex, r.lineweightPx);
1694
+ let o = rt(this, j).get(s), i = r.pos, a = r.positionItemSize;
1695
+ const u = r.linePositionKind ?? null;
1696
+ o ? o.positionItemSize !== a && (_e(o), a !== 3 && (i = Ke(i, r.count, a)), o.positionItemSize = 3, a = 3, o.linePositionKind = null) : (o = {
1697
+ layerIndex: r.layerIndex,
1698
+ ...r.lineweightPx === void 0 ? {} : { lineweightPx: r.lineweightPx },
1699
+ posParts: [],
1700
+ positionItemSize: a,
1701
+ colParts: [],
1702
+ colorRunParts: [],
1703
+ linePositionKind: u,
1704
+ count: 0,
1705
+ bbox: null
1706
+ }, rt(this, j).set(s, o));
1707
+ const c = o.count > 0;
1708
+ o.posParts.push(i), o.colParts.push(r.col);
1709
+ const m = Gr(
1710
+ r.colorRuns ?? Nr(r.col),
1711
+ o.count
1712
+ );
1713
+ o.colorRunParts.push(m), o.linePositionKind !== u && (o.linePositionKind = null), o.positionItemSize === 2 && o.linePositionKind === null && _e(o), o.count += r.count, o.bbox = c && o.bbox === null ? null : pr(o.bbox, r.bbox), n += r.count;
1714
+ }
1715
+ return n;
1716
+ }
1717
+ drain() {
1718
+ const e = [];
1719
+ for (const n of rt(this, j).values()) {
1720
+ if (n.count <= 0) continue;
1721
+ const r = n.posParts.length === 1 ? n.posParts[0] : Rr(n.posParts, n.count * n.positionItemSize), s = n.colParts.length === 1 ? n.colParts[0] : Vr(n.colParts, n.count * 3), o = je(n.colorRunParts.flat()), i = {
1722
+ layerIndex: n.layerIndex,
1723
+ pos: r,
1724
+ positionItemSize: n.positionItemSize,
1725
+ col: s,
1726
+ count: n.count,
1727
+ bbox: ht(n.bbox),
1728
+ colorRuns: o
1729
+ };
1730
+ n.lineweightPx !== void 0 && (i.lineweightPx = n.lineweightPx), n.linePositionKind && (i.linePositionKind = n.linePositionKind), e.push(i);
1731
+ }
1732
+ return rt(this, j).clear(), e;
1733
+ }
1734
+ }
1735
+ j = new WeakMap();
1736
+ function Nt() {
1737
+ return new Er();
1738
+ }
1739
+ function wr() {
1740
+ return {
1741
+ line: Nt(),
1742
+ fill: Nt(),
1743
+ dot: Nt()
1744
+ };
1745
+ }
1746
+ function pr(t, e) {
1747
+ const n = ht(e);
1748
+ return t ? n ? {
1749
+ minX: Math.min(t.minX, n.minX),
1750
+ minY: Math.min(t.minY, n.minY),
1751
+ maxX: Math.max(t.maxX, n.maxX),
1752
+ maxY: Math.max(t.maxY, n.maxY)
1753
+ } : null : n;
1754
+ }
1755
+ function He(t, e = {}) {
1756
+ if (t.count <= 0) return [];
1757
+ const n = Ot(t), r = [], s = /* @__PURE__ */ new Map(), o = /* @__PURE__ */ new Map(), i = /* @__PURE__ */ new Map(), a = e.markLinePositionXy === !0 || e.splitLineweight === !0;
1758
+ for (const h of n) {
1759
+ if (h.vertexCount <= 0) continue;
1760
+ const y = h.layerIndex, w = a ? h.lineweightPx : void 0, _ = Dt(y, w), E = s.get(_);
1761
+ E === void 0 ? (s.set(_, h.vertexCount), o.set(_, y), i.set(_, w), r.push(_)) : s.set(_, E + h.vertexCount);
1762
+ }
1763
+ const u = /* @__PURE__ */ new Map(), c = /* @__PURE__ */ new Map(), m = /* @__PURE__ */ new Map(), g = /* @__PURE__ */ new Set(), l = e.markLinePositionXy === !0 ? "xy-zero-z" : void 0, d = l ? 2 : 3;
1764
+ for (const h of r) {
1765
+ const y = o.get(h), w = i.get(h), _ = s.get(h) ?? 0, E = {
1766
+ layerIndex: y,
1767
+ ...w === void 0 ? {} : { lineweightPx: w },
1768
+ pos: new Float32Array(_ * d),
1769
+ positionItemSize: d,
1770
+ col: new Uint8Array(_ * 3),
1771
+ count: _,
1772
+ bbox: null,
1773
+ colorRuns: []
1774
+ };
1775
+ l && (E.linePositionKind = l), u.set(h, E), c.set(h, 0), m.set(h, null);
1776
+ }
1777
+ for (const h of n) {
1778
+ if (h.vertexCount <= 0) continue;
1779
+ const y = h.layerIndex, w = a ? h.lineweightPx : void 0, _ = Dt(y, w), E = u.get(_), A = c.get(_), U = A, N = h.color[0], C = h.color[1], V = h.color[2];
1780
+ for (let G = 0; G < h.vertexCount; G += 1) {
1781
+ const $ = h.startVertex + G, M = A + G, I = M * d, T = M * 3, P = $ * 2, k = t.pos[P], D = t.pos[P + 1];
1782
+ E.pos[I] = k, E.pos[I + 1] = D, d === 3 && (E.pos[I + 2] = 0), E.col[T] = N, E.col[T + 1] = C, E.col[T + 2] = V;
1783
+ const v = m.get(_);
1784
+ !Number.isFinite(k) || !Number.isFinite(D) ? g.add(_) : v ? (k < v.minX && (v.minX = k), D < v.minY && (v.minY = D), k > v.maxX && (v.maxX = k), D > v.maxY && (v.maxY = D)) : m.set(_, { minX: k, minY: D, maxX: k, maxY: D });
1785
+ }
1786
+ E.colorRuns.push({
1787
+ startVertex: U,
1788
+ vertexCount: h.vertexCount,
1789
+ color: [N, C, V]
1790
+ }), c.set(_, A + h.vertexCount);
1791
+ }
1792
+ const p = [];
1793
+ for (const h of r) {
1794
+ const y = u.get(h);
1795
+ y && (y.bbox = g.has(h) ? null : ht(m.get(h) ?? null), y.colorRuns = je(y.colorRuns ?? []), p.push(y));
1796
+ }
1797
+ return p;
1798
+ }
1799
+ function Dt(t, e) {
1800
+ return e === void 0 ? `${t}:` : `${t}:${e}`;
1801
+ }
1802
+ function br(t, e) {
1803
+ return t.append(e);
1804
+ }
1805
+ function Ar(t) {
1806
+ return t.drain();
1807
+ }
1808
+ function Ir(t) {
1809
+ const e = [], n = /* @__PURE__ */ new Set();
1810
+ for (const r of t)
1811
+ xe(e, n, r.pos.buffer), xe(e, n, r.col.buffer);
1812
+ return e;
1813
+ }
1814
+ function Rr(t, e) {
1815
+ const n = new Float32Array(e);
1816
+ let r = 0;
1817
+ for (const s of t)
1818
+ n.set(s, r), r += s.length;
1819
+ return n;
1820
+ }
1821
+ function Ke(t, e, n) {
1822
+ if (n === 3) return t;
1823
+ const r = new Float32Array(e * 3);
1824
+ for (let s = 0; s < e; s += 1) {
1825
+ const o = s * 2, i = s * 3;
1826
+ r[i] = t[o] ?? 0, r[i + 1] = t[o + 1] ?? 0, r[i + 2] = 0;
1827
+ }
1828
+ return r;
1829
+ }
1830
+ function _e(t) {
1831
+ if (t.positionItemSize === 3) return;
1832
+ const e = t.positionItemSize;
1833
+ t.posParts = t.posParts.map((n) => Ke(n, n.length / e, e)), t.positionItemSize = 3, t.linePositionKind = null;
1834
+ }
1835
+ function Vr(t, e) {
1836
+ const n = new Uint8Array(e);
1837
+ let r = 0;
1838
+ for (const s of t)
1839
+ n.set(s, r), r += s.length;
1840
+ return n;
1841
+ }
1842
+ function Gr(t, e) {
1843
+ return t.map((n) => ({
1844
+ startVertex: n.startVertex + e,
1845
+ vertexCount: n.vertexCount,
1846
+ color: [n.color[0], n.color[1], n.color[2]]
1847
+ }));
1848
+ }
1849
+ function je(t) {
1850
+ const e = [];
1851
+ for (const n of t) {
1852
+ const r = e[e.length - 1];
1853
+ if (r && r.startVertex + r.vertexCount === n.startVertex && r.color[0] === n.color[0] && r.color[1] === n.color[1] && r.color[2] === n.color[2]) {
1854
+ e[e.length - 1] = {
1855
+ ...r,
1856
+ vertexCount: r.vertexCount + n.vertexCount
1857
+ };
1858
+ continue;
1859
+ }
1860
+ e.push({
1861
+ startVertex: n.startVertex,
1862
+ vertexCount: n.vertexCount,
1863
+ color: [n.color[0], n.color[1], n.color[2]]
1864
+ });
1865
+ }
1866
+ return e;
1867
+ }
1868
+ function Nr(t) {
1869
+ const e = Math.floor(t.length / 3), n = [];
1870
+ let r = 0;
1871
+ for (; r < e; ) {
1872
+ const s = r * 3, o = t[s] ?? 0, i = t[s + 1] ?? 0, a = t[s + 2] ?? 0;
1873
+ let u = r + 1;
1874
+ for (; u < e; ) {
1875
+ const c = u * 3;
1876
+ if (t[c] !== o || t[c + 1] !== i || t[c + 2] !== a) break;
1877
+ u += 1;
1878
+ }
1879
+ n.push({ startVertex: r, vertexCount: u - r, color: [o, i, a] }), r = u;
1880
+ }
1881
+ return n;
1882
+ }
1883
+ function xe(t, e, n) {
1884
+ n instanceof ArrayBuffer && (e.has(n) || (e.add(n), t.push(n)));
1885
+ }
1886
+ function Ur(t, e, n = "u8") {
1887
+ if (e <= 0 && t.byteLength === 0)
1888
+ return { pos: new Float32Array(0), count: 0, segments: [] };
1889
+ const { buffer: r, startOffset: s, endOffset: o } = Pr(t), i = new DataView(r), a = Ne(r, i, s, e, o, n);
1890
+ if (a.offset !== o)
1891
+ throw new f(
1892
+ "E_GROUP_RANGE",
1893
+ `Insert runtime geometry chunk has trailing bytes: offset=${a.offset - s}, length=${t.byteLength}`
1894
+ );
1895
+ return a.chunk;
1896
+ }
1897
+ function Cr(t) {
1898
+ const e = (n) => {
1899
+ const r = t[n], s = Ur(
1900
+ r.raw,
1901
+ r.count,
1902
+ r.groupLayerEncoding
1903
+ ), o = He(s, { splitLineweight: n === "line" }), i = /* @__PURE__ */ new Map();
1904
+ for (const a of o)
1905
+ i.set(Sr(a.layerIndex, a.lineweightPx), {
1906
+ layerIndex: a.layerIndex,
1907
+ ...a.lineweightPx === void 0 ? {} : { lineweightPx: a.lineweightPx },
1908
+ pos: a.pos,
1909
+ col: a.col,
1910
+ count: a.count,
1911
+ bbox: it(a.bbox)
1912
+ });
1913
+ return i;
1914
+ };
1915
+ return {
1916
+ line: e("line"),
1917
+ fill: e("fill"),
1918
+ dot: e("dot")
1919
+ };
1920
+ }
1921
+ function Sr(t, e) {
1922
+ return e === void 0 ? `${t}:` : `${t}:${e}`;
1923
+ }
1924
+ function Tr(t, e) {
1925
+ let n = e ? it(e) : null;
1926
+ for (const r of ["line", "fill", "dot"])
1927
+ for (const s of t[r].values())
1928
+ n = Ce(n, s.bbox);
1929
+ return n;
1930
+ }
1931
+ function Pr(t) {
1932
+ if (t.buffer instanceof ArrayBuffer)
1933
+ return {
1934
+ buffer: t.buffer,
1935
+ startOffset: t.byteOffset,
1936
+ endOffset: t.byteOffset + t.byteLength
1937
+ };
1938
+ const e = Uint8Array.from(t);
1939
+ return {
1940
+ buffer: e.buffer,
1941
+ startOffset: e.byteOffset,
1942
+ endOffset: e.byteOffset + e.byteLength
1943
+ };
1944
+ }
1945
+ function Br(t) {
1946
+ const e = t.insertRuntime;
1947
+ if (!e || e.instances.length === 0) return null;
1948
+ const n = [], r = /* @__PURE__ */ new Map(), s = /* @__PURE__ */ new Set();
1949
+ for (const u of e.variants) {
1950
+ const c = Cr(u), m = Ut(c.line), g = Ut(c.fill), l = Ut(c.dot), d = m.length > 0 || g.length > 0 || l.length > 0;
1951
+ r.set(u.id, d ? Tr(c, null) : null), d && (s.add(u.id), n.push({
1952
+ variantId: u.id,
1953
+ line: m,
1954
+ fill: g,
1955
+ dot: l
1956
+ }));
1957
+ }
1958
+ const o = e.instances.filter((u) => s.has(u.variantId));
1959
+ if (o.length === 0) return null;
1960
+ const i = Or(o, r), a = kr(n, i);
1961
+ return {
1962
+ variants: n,
1963
+ instances: i,
1964
+ bytes: a,
1965
+ cost: i.count
1966
+ };
1967
+ }
1968
+ function $r(t) {
1969
+ const e = [], n = /* @__PURE__ */ new Set(), r = (s) => {
1970
+ n.has(s) || (n.add(s), e.push(s));
1971
+ };
1972
+ r(t.instances.meta.buffer), r(t.instances.mats.buffer), r(t.instances.bboxes.buffer);
1973
+ for (const s of t.variants)
1974
+ St(s.line, r), St(s.fill, r), St(s.dot, r);
1975
+ return e;
1976
+ }
1977
+ function Ut(t) {
1978
+ const e = [];
1979
+ for (const n of t.values())
1980
+ n.count <= 0 || e.push(vr(n));
1981
+ return e;
1982
+ }
1983
+ function vr(t) {
1984
+ return {
1985
+ pos: t.pos,
1986
+ col: t.col,
1987
+ count: t.count,
1988
+ layerIndex: t.layerIndex,
1989
+ ...t.lineweightPx === void 0 ? {} : { lineweightPx: t.lineweightPx },
1990
+ bbox: t.bbox
1991
+ };
1992
+ }
1993
+ function Or(t, e) {
1994
+ const n = t.length, r = new Uint32Array(n * 3), s = new Float32Array(n * 6), o = new Float32Array(n * 4);
1995
+ for (let i = 0; i < n; i += 1) {
1996
+ const a = t[i], u = i * 3;
1997
+ r[u] = a.instanceId, r[u + 1] = a.variantId, r[u + 2] = a.insLayerIdx;
1998
+ const c = i * 6;
1999
+ s[c] = a.matA, s[c + 1] = a.matB, s[c + 2] = a.matC, s[c + 3] = a.matD, s[c + 4] = a.tx, s[c + 5] = a.ty;
2000
+ const m = _r(e.get(a.variantId) ?? null, a);
2001
+ Mr(o, i * 4, m);
2002
+ }
2003
+ return { meta: r, mats: s, bboxes: o, count: n };
2004
+ }
2005
+ function Mr(t, e, n) {
2006
+ if (!n) {
2007
+ t[e] = Number.POSITIVE_INFINITY, t[e + 1] = Number.POSITIVE_INFINITY, t[e + 2] = Number.NEGATIVE_INFINITY, t[e + 3] = Number.NEGATIVE_INFINITY;
2008
+ return;
2009
+ }
2010
+ t[e] = n.minX, t[e + 1] = n.minY, t[e + 2] = n.maxX, t[e + 3] = n.maxY;
2011
+ }
2012
+ function kr(t, e) {
2013
+ let n = e.meta.byteLength + e.mats.byteLength + e.bboxes.byteLength;
2014
+ for (const r of t)
2015
+ n += Ct(r.line), n += Ct(r.fill), n += Ct(r.dot);
2016
+ return n;
2017
+ }
2018
+ function Ct(t) {
2019
+ return t.reduce((e, n) => e + n.pos.byteLength + n.col.byteLength, 0);
2020
+ }
2021
+ function St(t, e) {
2022
+ for (const n of t)
2023
+ e(n.pos.buffer), e(n.col.buffer);
2024
+ }
2025
+ function Ee() {
2026
+ return typeof performance < "u" && typeof performance.now == "function" ? performance.now() : Date.now();
2027
+ }
2028
+ class Dr {
2029
+ constructor() {
2030
+ Q(this, "geometryCredits", 0);
2031
+ Q(this, "textCredits", 0);
2032
+ Q(this, "cancelled", !1);
2033
+ Q(this, "geometryWaiters", []);
2034
+ Q(this, "textWaiters", []);
2035
+ }
2036
+ grant(e) {
2037
+ this.cancelled || (this.geometryCredits += Math.max(0, e.geometryCredits), this.textCredits += Math.max(0, e.textCredits), this.flushWaiters());
2038
+ }
2039
+ cancel() {
2040
+ if (!this.cancelled) {
2041
+ this.cancelled = !0, this.geometryCredits = 0, this.textCredits = 0;
2042
+ for (const e of this.geometryWaiters.splice(0, this.geometryWaiters.length))
2043
+ e(!1);
2044
+ for (const e of this.textWaiters.splice(0, this.textWaiters.length))
2045
+ e(!1);
2046
+ }
2047
+ }
2048
+ take(e) {
2049
+ return this.cancelled ? Promise.resolve(!1) : e === "geometry" && this.geometryCredits > 0 ? (this.geometryCredits -= 1, Promise.resolve(!0)) : e === "text" && this.textCredits > 0 ? (this.textCredits -= 1, Promise.resolve(!0)) : new Promise((n) => {
2050
+ this.getWaiters(e).push(n);
2051
+ });
2052
+ }
2053
+ flushWaiters() {
2054
+ this.flushKind("geometry"), this.flushKind("text");
2055
+ }
2056
+ flushKind(e) {
2057
+ const n = this.getWaiters(e);
2058
+ for (; n.length > 0 && this.getCredits(e) > 0; ) {
2059
+ this.setCredits(e, this.getCredits(e) - 1);
2060
+ const r = n.shift();
2061
+ r == null || r(!0);
2062
+ }
2063
+ }
2064
+ getCredits(e) {
2065
+ return e === "geometry" ? this.geometryCredits : this.textCredits;
2066
+ }
2067
+ setCredits(e, n) {
2068
+ if (e === "geometry") {
2069
+ this.geometryCredits = n;
2070
+ return;
2071
+ }
2072
+ this.textCredits = n;
2073
+ }
2074
+ getWaiters(e) {
2075
+ return e === "geometry" ? this.geometryWaiters : this.textWaiters;
2076
+ }
2077
+ }
2078
+ const we = 262144, Lr = Number.MAX_SAFE_INTEGER, pe = 524288, Fr = Number.MAX_SAFE_INTEGER, Xr = 5e6, Yr = 64, H = self;
2079
+ let X = null, be = null, Tt = null;
2080
+ async function Pt(t, e, n) {
2081
+ const r = Ar(e);
2082
+ if (!r.length || !await n.take("geometry")) return 0;
2083
+ const o = r.reduce((a, u) => a + u.count, 0), i = {
2084
+ type: "geometry",
2085
+ kind: t,
2086
+ layers: r,
2087
+ cost: o
2088
+ };
2089
+ return H.postMessage(i, Ir(r)), o;
2090
+ }
2091
+ async function zr(t, e) {
2092
+ return await Pt("line", t.line, e) + await Pt("fill", t.fill, e) + await Pt("dot", t.dot, e);
2093
+ }
2094
+ async function Ae(t, e) {
2095
+ if (!t.length || !await e.take("text")) return 0;
2096
+ const r = t.slice();
2097
+ t.length = 0;
2098
+ const s = {
2099
+ type: "text",
2100
+ texts: r,
2101
+ cost: r.length
2102
+ };
2103
+ return H.postMessage(s), r.length;
2104
+ }
2105
+ function Hr(t) {
2106
+ return t.lineCount + t.fillCount + t.dotCount;
2107
+ }
2108
+ function Kr(t, e) {
2109
+ return Hr(t) >= Xr ? {
2110
+ initial: pe,
2111
+ steady: e ? pe : Fr
2112
+ } : {
2113
+ initial: we,
2114
+ steady: e ? we : Lr
2115
+ };
2116
+ }
2117
+ function jr(t) {
2118
+ return t instanceof Error ? t : new Error(String(t));
2119
+ }
2120
+ function Wr(t) {
2121
+ if (!(!t || t.length === 0))
2122
+ return new Map(t.map((e) => [e.variantId, e.buffer]));
2123
+ }
2124
+ function qr(t) {
2125
+ if (t !== void 0)
2126
+ return new Set(t);
2127
+ }
2128
+ async function Jr(t, e, n) {
2129
+ const r = Wr(e);
2130
+ if (!t || !n || n.length === 0)
2131
+ return r;
2132
+ const s = Array.from(new Set(n)).filter((a) => !(r != null && r.has(a))).sort((a, u) => a - u);
2133
+ if (s.length === 0)
2134
+ return r;
2135
+ const o = await xr({
2136
+ baseUrl: t.baseUrl,
2137
+ entries: t.entries,
2138
+ requiredVariantIds: s
2139
+ }), i = new Map(r ?? []);
2140
+ for (const [a, u] of o.buffers)
2141
+ i.set(a, u);
2142
+ return i;
2143
+ }
2144
+ async function Zr(t, e, n, r, s = !0, o, i, a, u, c, m, g, l, d, p = !1) {
2145
+ const h = wr(), y = [];
2146
+ let w = 0, _ = !1;
2147
+ const E = u === !0, A = typeof i == "number" && Number.isFinite(i) && i >= 0, U = await Jr(
2148
+ a,
2149
+ c,
2150
+ g
2151
+ ), N = qr(m), C = n && n.length > 0 || r === !0 || s === !1 || o === !0 || A || E || U || N !== void 0 || l === !0 || d === !0 ? {
2152
+ ...n && n.length > 0 ? { hiddenInstanceIds: new Set(n) } : {},
2153
+ ...r === !0 ? { keepTextsForHiddenInstances: !0 } : {},
2154
+ ...s === !1 ? { loadBlocks: !1 } : {},
2155
+ ...o === !0 ? { suppressExpandedInsertGeometry: !0 } : {},
2156
+ ...A ? { maxExpandedInstanceVertices: i } : {},
2157
+ ...E ? { deferExternalVariantGeometry: !0 } : {},
2158
+ ...U ? { externalVariantBuffers: U } : {},
2159
+ ...N !== void 0 ? { requiredExternalVariantIds: N } : {},
2160
+ ...l === !0 ? { externalVariantDeltaOnly: !0 } : {},
2161
+ ...d === !0 ? { cacheDocument: !0 } : {}
2162
+ } : void 0, V = p && Tt ? hr(t, Tt, C) : ze(t, C);
2163
+ p || (Tt = V.documentCache ?? null);
2164
+ const G = Kr(V.header, l === !0);
2165
+ H.postMessage({
2166
+ type: "header",
2167
+ header: V.header
2168
+ });
2169
+ const $ = async () => {
2170
+ const T = await zr(h, e);
2171
+ return w = 0, T > 0 && (_ = !0), T;
2172
+ };
2173
+ for (const T of V.chunks) {
2174
+ if (T.kind === "text") {
2175
+ y.push(T.payload), y.length >= Yr && await Ae(y, e);
2176
+ continue;
2177
+ }
2178
+ const P = He(T.payload, {
2179
+ markLinePositionXy: T.kind === "line"
2180
+ });
2181
+ w += br(h[T.kind], P);
2182
+ const k = _ ? G.steady : G.initial;
2183
+ w >= k && await $();
2184
+ }
2185
+ await $(), await Ae(y, e), H.postMessage({ type: "done" });
2186
+ const M = Ee(), I = Br(V.header);
2187
+ I && H.postMessage(
2188
+ {
2189
+ type: "insertModel",
2190
+ variants: I.variants,
2191
+ instances: I.instances,
2192
+ cost: I.cost,
2193
+ bytes: I.bytes,
2194
+ planMs: Ee() - M
2195
+ },
2196
+ $r(I)
2197
+ ), H.postMessage({ type: "complete" });
2198
+ }
2199
+ self.addEventListener("message", (t) => {
2200
+ const e = t.data;
2201
+ if (!e) return;
2202
+ if (e.type === "grant") {
2203
+ X == null || X.grant({
2204
+ geometryCredits: e.geometryCredits,
2205
+ textCredits: e.textCredits
2206
+ });
2207
+ return;
2208
+ }
2209
+ if (e.type === "cancel") {
2210
+ X == null || X.cancel();
2211
+ return;
2212
+ }
2213
+ if (e.type !== "parse") return;
2214
+ const n = new Dr();
2215
+ X = n;
2216
+ const r = e.useRetainedMainBuffer === !0;
2217
+ if (r && e.buffer !== void 0) {
2218
+ const o = new Error("Geo prepare worker parse request cannot include both a retained and transferred main buffer");
2219
+ o.code = "E_MAIN_BUFFER_PROTOCOL", H.postMessage({
2220
+ type: "error",
2221
+ message: o.message,
2222
+ code: "E_MAIN_BUFFER_PROTOCOL"
2223
+ }), X = null;
2224
+ return;
2225
+ }
2226
+ const s = r ? be : e.buffer;
2227
+ if (!s) {
2228
+ const o = new Error(
2229
+ r ? "Geo prepare worker has no retained main buffer for this delta parse" : "Geo prepare worker parse request is missing its main buffer"
2230
+ );
2231
+ o.code = "E_MAIN_BUFFER_MISSING", H.postMessage({
2232
+ type: "error",
2233
+ message: o.message,
2234
+ code: "E_MAIN_BUFFER_MISSING"
2235
+ }), X = null;
2236
+ return;
2237
+ }
2238
+ r || (be = s), Zr(
2239
+ s,
2240
+ n,
2241
+ e.hiddenInstanceIds,
2242
+ e.keepTextsForHiddenInstances,
2243
+ e.loadBlocks,
2244
+ e.suppressExpandedInsertGeometry,
2245
+ e.maxExpandedInstanceVertices,
2246
+ e.externalVariantFetchSource,
2247
+ e.deferExternalVariantGeometry,
2248
+ e.externalVariantBuffers,
2249
+ e.requiredExternalVariantIds,
2250
+ e.externalVariantGeometryFetchIds,
2251
+ e.externalVariantDeltaOnly,
2252
+ e.cacheDocument,
2253
+ r
2254
+ ).catch((o) => {
2255
+ const i = jr(o), a = i.code;
2256
+ H.postMessage({
2257
+ type: "error",
2258
+ message: i.message,
2259
+ code: typeof a == "string" ? a : void 0
2260
+ });
2261
+ }).finally(() => {
2262
+ X === n && (X = null);
2263
+ });
2264
+ });