@nebula-spatial/studio 0.0.0-stage → 0.1.0

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