@bitbybit-dev/base 1.5.0 → 1.6.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 (314) hide show
  1. package/lib/api/GlobalCDNProvider.js +1 -1
  2. package/lib/api/bearings/ansi-bearings.constants.d.ts +2 -0
  3. package/lib/api/bearings/ansi-bearings.constants.js +26 -0
  4. package/lib/api/bearings/ansi-bearings.d.ts +4 -0
  5. package/lib/api/bearings/ansi-bearings.js +14 -0
  6. package/lib/api/bearings/bearing-types.d.ts +25 -0
  7. package/lib/api/bearings/bearing-types.js +1 -0
  8. package/lib/api/bearings/bearings.constants.d.ts +1 -0
  9. package/lib/api/bearings/bearings.constants.js +1 -0
  10. package/lib/api/bearings/iso-bearings.constants.d.ts +2 -0
  11. package/lib/api/bearings/iso-bearings.constants.js +30 -0
  12. package/lib/api/bearings/iso-bearings.d.ts +4 -0
  13. package/lib/api/bearings/iso-bearings.js +14 -0
  14. package/lib/api/color-space.d.ts +2 -0
  15. package/lib/api/color-space.js +5 -8
  16. package/lib/api/fasteners/ansi-fasteners.constants.d.ts +16 -0
  17. package/lib/api/fasteners/ansi-fasteners.constants.js +118 -0
  18. package/lib/api/fasteners/ansi-fasteners.d.ts +8 -0
  19. package/lib/api/fasteners/ansi-fasteners.js +64 -0
  20. package/lib/api/fasteners/fastener-types.d.ts +161 -0
  21. package/lib/api/fasteners/fastener-types.js +1 -0
  22. package/lib/api/fasteners/fasteners.constants.d.ts +5 -0
  23. package/lib/api/fasteners/fasteners.constants.js +5 -0
  24. package/lib/api/fasteners/fasteners.d.ts +2 -0
  25. package/lib/api/fasteners/fasteners.js +9 -0
  26. package/lib/api/fasteners/iso-fasteners.constants.d.ts +23 -0
  27. package/lib/api/fasteners/iso-fasteners.constants.js +110 -0
  28. package/lib/api/fasteners/iso-fasteners.d.ts +9 -0
  29. package/lib/api/fasteners/iso-fasteners.js +61 -0
  30. package/lib/api/gears/bevel-gears.d.ts +6 -0
  31. package/lib/api/gears/bevel-gears.js +69 -0
  32. package/lib/api/gears/gear-checks.d.ts +8 -0
  33. package/lib/api/gears/gear-checks.js +69 -0
  34. package/lib/api/gears/gear-pairs.d.ts +4 -0
  35. package/lib/api/gears/gear-pairs.js +140 -0
  36. package/lib/api/gears/gear-types.d.ts +425 -0
  37. package/lib/api/gears/gear-types.js +1 -0
  38. package/lib/api/gears/gears.constants.d.ts +19 -0
  39. package/lib/api/gears/gears.constants.js +19 -0
  40. package/lib/api/gears/gears.d.ts +10 -0
  41. package/lib/api/gears/gears.js +156 -0
  42. package/lib/api/gears/helical-gears.d.ts +5 -0
  43. package/lib/api/gears/helical-gears.js +33 -0
  44. package/lib/api/gears/involute-flank.d.ts +26 -0
  45. package/lib/api/gears/involute-flank.js +158 -0
  46. package/lib/api/gears/racks.d.ts +3 -0
  47. package/lib/api/gears/racks.js +64 -0
  48. package/lib/api/index.d.ts +10 -1
  49. package/lib/api/index.js +0 -1
  50. package/lib/api/inputs/base-inputs.d.ts +450 -3
  51. package/lib/api/inputs/base-inputs.js +12 -0
  52. package/lib/api/inputs/color-inputs.d.ts +14 -0
  53. package/lib/api/inputs/color-inputs.js +19 -0
  54. package/lib/api/inputs/engineering-inputs.d.ts +1539 -0
  55. package/lib/api/inputs/engineering-inputs.js +2181 -0
  56. package/lib/api/inputs/index.d.ts +2 -0
  57. package/lib/api/inputs/index.js +2 -0
  58. package/lib/api/inputs/io-inputs.d.ts +8 -1
  59. package/lib/api/inputs/io-inputs.js +4 -1
  60. package/lib/api/inputs/math-inputs.d.ts +61 -0
  61. package/lib/api/inputs/math-inputs.js +85 -0
  62. package/lib/api/inputs/mesh-inputs.d.ts +170 -0
  63. package/lib/api/inputs/mesh-inputs.js +206 -0
  64. package/lib/api/inputs/point-inputs.d.ts +4 -4
  65. package/lib/api/inputs/polyline-inputs.d.ts +144 -0
  66. package/lib/api/inputs/polyline-inputs.js +151 -0
  67. package/lib/api/inputs/recipes-inputs.d.ts +76 -0
  68. package/lib/api/inputs/recipes-inputs.js +74 -0
  69. package/lib/api/inputs/transforms-inputs.d.ts +34 -0
  70. package/lib/api/inputs/transforms-inputs.js +35 -0
  71. package/lib/api/keys/ansi-keys.constants.d.ts +3 -0
  72. package/lib/api/keys/ansi-keys.constants.js +16 -0
  73. package/lib/api/keys/ansi-keys.d.ts +3 -0
  74. package/lib/api/keys/ansi-keys.js +14 -0
  75. package/lib/api/keys/din-keys.constants.d.ts +3 -0
  76. package/lib/api/keys/din-keys.constants.js +14 -0
  77. package/lib/api/keys/din-keys.d.ts +3 -0
  78. package/lib/api/keys/din-keys.js +13 -0
  79. package/lib/api/keys/key-types.d.ts +17 -0
  80. package/lib/api/keys/key-types.js +1 -0
  81. package/lib/api/keys/keys.constants.d.ts +1 -0
  82. package/lib/api/keys/keys.constants.js +1 -0
  83. package/lib/api/knurls/ansi-knurls.constants.d.ts +4 -0
  84. package/lib/api/knurls/ansi-knurls.constants.js +8 -0
  85. package/lib/api/knurls/ansi-knurls.d.ts +3 -0
  86. package/lib/api/knurls/ansi-knurls.js +20 -0
  87. package/lib/api/knurls/din-knurls.constants.d.ts +2 -0
  88. package/lib/api/knurls/din-knurls.constants.js +2 -0
  89. package/lib/api/knurls/din-knurls.d.ts +3 -0
  90. package/lib/api/knurls/din-knurls.js +19 -0
  91. package/lib/api/knurls/knurl-types.d.ts +24 -0
  92. package/lib/api/knurls/knurl-types.js +1 -0
  93. package/lib/api/knurls/knurls.constants.d.ts +1 -0
  94. package/lib/api/knurls/knurls.constants.js +1 -0
  95. package/lib/api/knurls/knurls.d.ts +2 -0
  96. package/lib/api/knurls/knurls.js +9 -0
  97. package/lib/api/recipes/checks.d.ts +15 -0
  98. package/lib/api/recipes/checks.js +85 -0
  99. package/lib/api/recipes/limits.constants.d.ts +4 -0
  100. package/lib/api/recipes/limits.constants.js +4 -0
  101. package/lib/api/recipes/sources.d.ts +0 -13
  102. package/lib/api/recipes/sources.js +3 -15
  103. package/lib/api/recipes/surface-mesh.d.ts +0 -14
  104. package/lib/api/recipes/surface-mesh.js +8 -21
  105. package/lib/api/recipes/validate-brep.d.ts +2 -0
  106. package/lib/api/recipes/validate-brep.js +330 -0
  107. package/lib/api/recipes/validate.d.ts +0 -31
  108. package/lib/api/recipes/validate.js +7 -115
  109. package/lib/api/resolved-inputs/index.d.ts +80 -0
  110. package/lib/api/retaining-rings/ansi-retaining-rings.constants.d.ts +4 -0
  111. package/lib/api/retaining-rings/ansi-retaining-rings.constants.js +93 -0
  112. package/lib/api/retaining-rings/ansi-retaining-rings.d.ts +4 -0
  113. package/lib/api/retaining-rings/ansi-retaining-rings.js +20 -0
  114. package/lib/api/retaining-rings/din-retaining-rings.constants.d.ts +3 -0
  115. package/lib/api/retaining-rings/din-retaining-rings.constants.js +115 -0
  116. package/lib/api/retaining-rings/din-retaining-rings.d.ts +4 -0
  117. package/lib/api/retaining-rings/din-retaining-rings.js +20 -0
  118. package/lib/api/retaining-rings/retaining-ring-types.d.ts +30 -0
  119. package/lib/api/retaining-rings/retaining-ring-types.js +1 -0
  120. package/lib/api/retaining-rings/retaining-rings.constants.d.ts +1 -0
  121. package/lib/api/retaining-rings/retaining-rings.constants.js +1 -0
  122. package/lib/api/retaining-rings/retaining-rings.d.ts +2 -0
  123. package/lib/api/retaining-rings/retaining-rings.js +9 -0
  124. package/lib/api/services/base-bitbybit.d.ts +42 -0
  125. package/lib/api/services/base-bitbybit.js +43 -0
  126. package/lib/api/services/color.d.ts +35 -2
  127. package/lib/api/services/color.js +48 -12
  128. package/lib/api/services/engineering/engineering.d.ts +12 -0
  129. package/lib/api/services/engineering/engineering.js +13 -0
  130. package/lib/api/services/engineering/index.d.ts +2 -0
  131. package/lib/api/services/engineering/index.js +2 -0
  132. package/lib/api/services/engineering/mechanical/bearings-ansi.d.ts +40 -0
  133. package/lib/api/services/engineering/mechanical/bearings-ansi.js +47 -0
  134. package/lib/api/services/engineering/mechanical/bearings-iso.d.ts +39 -0
  135. package/lib/api/services/engineering/mechanical/bearings-iso.js +46 -0
  136. package/lib/api/services/engineering/mechanical/bearings.d.ts +14 -0
  137. package/lib/api/services/engineering/mechanical/bearings.js +15 -0
  138. package/lib/api/services/engineering/mechanical/fasteners-ansi.d.ts +109 -0
  139. package/lib/api/services/engineering/mechanical/fasteners-ansi.js +133 -0
  140. package/lib/api/services/engineering/mechanical/fasteners-iso.d.ts +123 -0
  141. package/lib/api/services/engineering/mechanical/fasteners-iso.js +151 -0
  142. package/lib/api/services/engineering/mechanical/fasteners.d.ts +13 -0
  143. package/lib/api/services/engineering/mechanical/fasteners.js +14 -0
  144. package/lib/api/services/engineering/mechanical/gears.d.ts +267 -0
  145. package/lib/api/services/engineering/mechanical/gears.js +318 -0
  146. package/lib/api/services/engineering/mechanical/index.d.ts +24 -0
  147. package/lib/api/services/engineering/mechanical/index.js +24 -0
  148. package/lib/api/services/engineering/mechanical/keys-ansi.d.ts +27 -0
  149. package/lib/api/services/engineering/mechanical/keys-ansi.js +32 -0
  150. package/lib/api/services/engineering/mechanical/keys-din.d.ts +26 -0
  151. package/lib/api/services/engineering/mechanical/keys-din.js +31 -0
  152. package/lib/api/services/engineering/mechanical/keys.d.ts +14 -0
  153. package/lib/api/services/engineering/mechanical/keys.js +15 -0
  154. package/lib/api/services/engineering/mechanical/knurls-ansi.d.ts +26 -0
  155. package/lib/api/services/engineering/mechanical/knurls-ansi.js +31 -0
  156. package/lib/api/services/engineering/mechanical/knurls-din.d.ts +26 -0
  157. package/lib/api/services/engineering/mechanical/knurls-din.js +31 -0
  158. package/lib/api/services/engineering/mechanical/knurls.d.ts +14 -0
  159. package/lib/api/services/engineering/mechanical/knurls.js +15 -0
  160. package/lib/api/services/engineering/mechanical/mechanical.d.ts +29 -0
  161. package/lib/api/services/engineering/mechanical/mechanical.js +30 -0
  162. package/lib/api/services/engineering/mechanical/retaining-rings-ansi.d.ts +43 -0
  163. package/lib/api/services/engineering/mechanical/retaining-rings-ansi.js +51 -0
  164. package/lib/api/services/engineering/mechanical/retaining-rings-din.d.ts +43 -0
  165. package/lib/api/services/engineering/mechanical/retaining-rings-din.js +51 -0
  166. package/lib/api/services/engineering/mechanical/retaining-rings.d.ts +13 -0
  167. package/lib/api/services/engineering/mechanical/retaining-rings.js +14 -0
  168. package/lib/api/services/engineering/mechanical/splines-ansi.d.ts +27 -0
  169. package/lib/api/services/engineering/mechanical/splines-ansi.js +32 -0
  170. package/lib/api/services/engineering/mechanical/splines-din.d.ts +26 -0
  171. package/lib/api/services/engineering/mechanical/splines-din.js +31 -0
  172. package/lib/api/services/engineering/mechanical/splines.d.ts +13 -0
  173. package/lib/api/services/engineering/mechanical/splines.js +14 -0
  174. package/lib/api/services/engineering/mechanical/springs.d.ts +27 -0
  175. package/lib/api/services/engineering/mechanical/springs.js +31 -0
  176. package/lib/api/services/engineering/mechanical/threads-ansi.d.ts +40 -0
  177. package/lib/api/services/engineering/mechanical/threads-ansi.js +48 -0
  178. package/lib/api/services/engineering/mechanical/threads-iso.d.ts +40 -0
  179. package/lib/api/services/engineering/mechanical/threads-iso.js +48 -0
  180. package/lib/api/services/engineering/mechanical/threads.d.ts +13 -0
  181. package/lib/api/services/engineering/mechanical/threads.js +14 -0
  182. package/lib/api/services/frame.js +3 -3
  183. package/lib/api/services/geometry-helper.js +8 -111
  184. package/lib/api/services/helpers/color/color-space.d.ts +2 -0
  185. package/lib/api/services/helpers/color/color-space.js +12 -0
  186. package/lib/api/services/helpers/{nurbs.d.ts → curves/nurbs.d.ts} +1 -1
  187. package/lib/api/services/helpers/{surface-triangulation.d.ts → curves/surface-triangulation.d.ts} +2 -2
  188. package/lib/api/services/helpers/{surface-triangulation.js → curves/surface-triangulation.js} +14 -8
  189. package/lib/api/services/helpers/{dxf → files/dxf}/dxf-generator.d.ts +2 -1
  190. package/lib/api/services/helpers/{dxf → files/dxf}/dxf-generator.js +19 -5
  191. package/lib/api/services/helpers/files/dxf/dxf.constants.d.ts +4 -0
  192. package/lib/api/services/helpers/files/dxf/dxf.constants.js +4 -0
  193. package/lib/api/services/helpers/{dxf → files/dxf}/dxf.d.ts +1 -1
  194. package/lib/api/services/helpers/{dxf → files/dxf}/dxf.js +2 -2
  195. package/lib/api/services/helpers/files/glb.constants.d.ts +11 -0
  196. package/lib/api/services/helpers/files/glb.constants.js +11 -0
  197. package/lib/api/services/helpers/files/glb.d.ts +1 -0
  198. package/lib/api/services/helpers/files/glb.js +69 -0
  199. package/lib/api/services/helpers/files/gzip.constants.d.ts +11 -0
  200. package/lib/api/services/helpers/files/gzip.constants.js +11 -0
  201. package/lib/api/services/helpers/files/gzip.d.ts +2 -0
  202. package/lib/api/services/helpers/files/gzip.js +50 -0
  203. package/lib/api/services/helpers/{inflate.constants.d.ts → files/inflate.constants.d.ts} +2 -0
  204. package/lib/api/services/helpers/{inflate.constants.js → files/inflate.constants.js} +2 -0
  205. package/lib/api/services/helpers/{inflate.d.ts → files/inflate.d.ts} +2 -2
  206. package/lib/api/services/helpers/{inflate.js → files/inflate.js} +16 -7
  207. package/lib/api/services/helpers/{zip.constants.d.ts → files/zip.constants.d.ts} +8 -0
  208. package/lib/api/services/helpers/{zip.constants.js → files/zip.constants.js} +8 -0
  209. package/lib/api/services/helpers/files/zip.d.ts +8 -0
  210. package/lib/api/services/helpers/files/zip.js +226 -0
  211. package/lib/api/services/helpers/geometry/arcs.d.ts +9 -0
  212. package/lib/api/services/helpers/{arcs.js → geometry/arcs.js} +7 -0
  213. package/lib/api/services/helpers/{frame-axes.d.ts → geometry/frame-axes.d.ts} +8 -5
  214. package/lib/api/services/helpers/{frame-axes.js → geometry/frame-axes.js} +21 -9
  215. package/lib/api/services/helpers/geometry/lengths.constants.d.ts +4 -0
  216. package/lib/api/services/helpers/geometry/lengths.constants.js +3 -0
  217. package/lib/api/services/helpers/geometry/lengths.d.ts +7 -0
  218. package/lib/api/services/helpers/geometry/lengths.js +20 -0
  219. package/lib/api/services/helpers/geometry/matrices.constants.d.ts +8 -0
  220. package/lib/api/services/helpers/geometry/matrices.constants.js +7 -0
  221. package/lib/api/services/helpers/geometry/matrices.d.ts +17 -0
  222. package/lib/api/services/helpers/{matrices.js → geometry/matrices.js} +28 -17
  223. package/lib/api/services/helpers/{paths.d.ts → geometry/paths.d.ts} +2 -1
  224. package/lib/api/services/helpers/{paths.js → geometry/paths.js} +36 -30
  225. package/lib/api/services/helpers/{polygons.d.ts → geometry/polygons.d.ts} +1 -1
  226. package/lib/api/services/helpers/geometry/polygons.js +111 -0
  227. package/lib/api/services/helpers/geometry/scalars.d.ts +9 -0
  228. package/lib/api/services/helpers/geometry/scalars.js +34 -0
  229. package/lib/api/services/helpers/{triangulation.js → geometry/triangulation.js} +11 -6
  230. package/lib/api/services/helpers/geometry/vector-grid.d.ts +12 -0
  231. package/lib/api/services/helpers/geometry/vector-grid.js +149 -0
  232. package/lib/api/services/helpers/{vectors.d.ts → geometry/vectors.d.ts} +8 -1
  233. package/lib/api/services/helpers/geometry/vectors.js +43 -0
  234. package/lib/api/services/helpers/helper-types.d.ts +77 -0
  235. package/lib/api/services/helpers/mesh/mesh-normals.d.ts +21 -0
  236. package/lib/api/services/helpers/{mesh-normals.js → mesh/mesh-normals.js} +54 -65
  237. package/lib/api/services/helpers/mesh/mesh-orientation.d.ts +24 -0
  238. package/lib/api/services/helpers/mesh/mesh-orientation.js +104 -0
  239. package/lib/api/services/helpers/{mesh-primitives.d.ts → mesh/mesh-primitives.d.ts} +1 -1
  240. package/lib/api/services/helpers/{mesh-primitives.js → mesh/mesh-primitives.js} +6 -5
  241. package/lib/api/services/helpers/mesh/mesh-proximity.constants.d.ts +7 -0
  242. package/lib/api/services/helpers/mesh/mesh-proximity.constants.js +11 -0
  243. package/lib/api/services/helpers/mesh/mesh-proximity.d.ts +11 -0
  244. package/lib/api/services/helpers/mesh/mesh-proximity.js +382 -0
  245. package/lib/api/services/index.d.ts +3 -0
  246. package/lib/api/services/index.js +3 -0
  247. package/lib/api/services/io.d.ts +1 -1
  248. package/lib/api/services/io.js +1 -1
  249. package/lib/api/services/line.js +2 -3
  250. package/lib/api/services/math.d.ts +47 -0
  251. package/lib/api/services/math.js +77 -10
  252. package/lib/api/services/mesh.d.ts +174 -2
  253. package/lib/api/services/mesh.js +305 -7
  254. package/lib/api/services/point.js +4 -10
  255. package/lib/api/services/polyline-types.d.ts +6 -0
  256. package/lib/api/services/polyline-types.js +1 -0
  257. package/lib/api/services/polyline.d.ts +163 -1
  258. package/lib/api/services/polyline.js +270 -13
  259. package/lib/api/services/recipes.d.ts +80 -0
  260. package/lib/api/services/recipes.js +107 -0
  261. package/lib/api/services/transforms.d.ts +74 -2
  262. package/lib/api/services/transforms.js +100 -3
  263. package/lib/api/services/vector.d.ts +4 -3
  264. package/lib/api/services/vector.js +14 -14
  265. package/lib/api/splines/ansi-splines.constants.d.ts +9 -0
  266. package/lib/api/splines/ansi-splines.constants.js +9 -0
  267. package/lib/api/splines/ansi-splines.d.ts +3 -0
  268. package/lib/api/splines/ansi-splines.js +28 -0
  269. package/lib/api/splines/din-splines.constants.d.ts +12 -0
  270. package/lib/api/splines/din-splines.constants.js +12 -0
  271. package/lib/api/splines/din-splines.d.ts +3 -0
  272. package/lib/api/splines/din-splines.js +38 -0
  273. package/lib/api/splines/spline-types.d.ts +32 -0
  274. package/lib/api/splines/spline-types.js +1 -0
  275. package/lib/api/splines/splines.constants.d.ts +1 -0
  276. package/lib/api/splines/splines.constants.js +1 -0
  277. package/lib/api/springs/spring-types.d.ts +26 -0
  278. package/lib/api/springs/spring-types.js +1 -0
  279. package/lib/api/springs/springs.constants.d.ts +9 -0
  280. package/lib/api/springs/springs.constants.js +9 -0
  281. package/lib/api/springs/springs.d.ts +2 -0
  282. package/lib/api/springs/springs.js +50 -0
  283. package/lib/api/threads/ansi-threads.constants.d.ts +6 -0
  284. package/lib/api/threads/ansi-threads.constants.js +27 -0
  285. package/lib/api/threads/ansi-threads.d.ts +4 -0
  286. package/lib/api/threads/ansi-threads.js +50 -0
  287. package/lib/api/threads/iso-threads.constants.d.ts +5 -0
  288. package/lib/api/threads/iso-threads.constants.js +20 -0
  289. package/lib/api/threads/iso-threads.d.ts +4 -0
  290. package/lib/api/threads/iso-threads.js +32 -0
  291. package/lib/api/threads/thread-profile.constants.d.ts +3 -0
  292. package/lib/api/threads/thread-profile.constants.js +3 -0
  293. package/lib/api/threads/thread-types.d.ts +66 -0
  294. package/lib/api/threads/thread-types.js +1 -0
  295. package/package.json +1 -1
  296. package/lib/api/recipes/index.d.ts +0 -4
  297. package/lib/api/recipes/index.js +0 -3
  298. package/lib/api/services/helpers/arcs.d.ts +0 -6
  299. package/lib/api/services/helpers/matrices.constants.d.ts +0 -2
  300. package/lib/api/services/helpers/matrices.constants.js +0 -2
  301. package/lib/api/services/helpers/matrices.d.ts +0 -25
  302. package/lib/api/services/helpers/mesh-normals.d.ts +0 -11
  303. package/lib/api/services/helpers/polygons.js +0 -59
  304. package/lib/api/services/helpers/vectors.js +0 -17
  305. package/lib/api/services/helpers/zip.d.ts +0 -4
  306. package/lib/api/services/helpers/zip.js +0 -89
  307. /package/lib/api/services/helpers/{nurbs.js → curves/nurbs.js} +0 -0
  308. /package/lib/api/services/helpers/{crc32.d.ts → files/crc32.d.ts} +0 -0
  309. /package/lib/api/services/helpers/{crc32.js → files/crc32.js} +0 -0
  310. /package/lib/api/services/helpers/{triangulation.d.ts → geometry/triangulation.d.ts} +0 -0
  311. /package/lib/api/services/helpers/{mesh-measures.d.ts → mesh/mesh-measures.d.ts} +0 -0
  312. /package/lib/api/services/helpers/{mesh-measures.js → mesh/mesh-measures.js} +0 -0
  313. /package/lib/api/services/helpers/{mesh-primitives.constants.d.ts → mesh/mesh-primitives.constants.d.ts} +0 -0
  314. /package/lib/api/services/helpers/{mesh-primitives.constants.js → mesh/mesh-primitives.constants.js} +0 -0
@@ -0,0 +1,48 @@
1
+ import * as Inputs from "../../../inputs";
2
+ import { resolveDto } from "../../../kernel-calls";
3
+ import { isoThread, isoThreadSizes } from "../../../threads/iso-threads";
4
+ import { THREAD_LENGTHS } from "../../../threads/thread-profile.constants";
5
+ import { checkedUnitOfLength, lengthsConverted } from "../../helpers/geometry/lengths";
6
+ /**
7
+ * The sizes of ISO metric screw threads from M1.6 to M24, with no CAD kernel needed: diameters,
8
+ * pitches and tap drills, coarse or fine, in the unit asked for. The fasteners of
9
+ * `occt.parts.mechanical.fasteners.iso` carry them.
10
+ * @beta
11
+ */
12
+ export class EngineeringThreadsIso {
13
+ /**
14
+ * Gives an ISO metric thread by its size: the nominal, pitch and minor diameters, the pitch,
15
+ * the internal thread's minor diameter and the drill for tapping it.
16
+ *
17
+ * The coarse pitch unless `pitch` gives a fine one, in millimetres as ISO names it; the sizes come
18
+ * back in `unit`. Example: M8 -> pitch 1.25, tap drill 6.8
19
+ * @param inputs - The size, an optional fine pitch and the unit
20
+ * @returns The thread's diameters and pitch in `unit`
21
+ * @group threads
22
+ * @shortname iso thread
23
+ * @drawable false
24
+ * @example
25
+ * ```typescript
26
+ * const thread = bitbybit.engineering.mechanical.threads.iso.thread({ size: Bit.Inputs.Engineering.isoThreadSizeEnum.m8 });
27
+ * const drill = thread.tapDrill;
28
+ * ```
29
+ */
30
+ thread(inputs) {
31
+ const resolved = resolveDto(Inputs.Engineering.IsoThreadDto, inputs);
32
+ return lengthsConverted(isoThread(resolved.size, resolved.pitch), THREAD_LENGTHS, "mm", checkedUnitOfLength(resolved.unit, "unit"));
33
+ }
34
+ /**
35
+ * Lists the ISO metric thread sizes the tables hold, from M1.6 to M24.
36
+ * @returns The sizes, smallest first
37
+ * @group threads
38
+ * @shortname iso thread sizes
39
+ * @drawable false
40
+ * @example
41
+ * ```typescript
42
+ * const sizes = bitbybit.engineering.mechanical.threads.iso.sizes();
43
+ * ```
44
+ */
45
+ sizes() {
46
+ return isoThreadSizes();
47
+ }
48
+ }
@@ -0,0 +1,13 @@
1
+ import { EngineeringThreadsAnsi } from "./threads-ansi";
2
+ import { EngineeringThreadsIso } from "./threads-iso";
3
+ /**
4
+ * The sizes of screw threads by the standard that sets them, with no CAD kernel needed: `iso` holds
5
+ * the ISO metric threads, `ansi` the Unified inch threads. Each gives diameters, pitches and tap
6
+ * drills in the unit asked for; `occt.parts.mechanical.machining` cuts the threads into a body.
7
+ * @beta
8
+ */
9
+ export declare class EngineeringThreads {
10
+ readonly iso: EngineeringThreadsIso;
11
+ readonly ansi: EngineeringThreadsAnsi;
12
+ constructor();
13
+ }
@@ -0,0 +1,14 @@
1
+ import { EngineeringThreadsAnsi } from "./threads-ansi";
2
+ import { EngineeringThreadsIso } from "./threads-iso";
3
+ /**
4
+ * The sizes of screw threads by the standard that sets them, with no CAD kernel needed: `iso` holds
5
+ * the ISO metric threads, `ansi` the Unified inch threads. Each gives diameters, pitches and tap
6
+ * drills in the unit asked for; `occt.parts.mechanical.machining` cuts the threads into a body.
7
+ * @beta
8
+ */
9
+ export class EngineeringThreads {
10
+ constructor() {
11
+ this.iso = new EngineeringThreadsIso();
12
+ this.ansi = new EngineeringThreadsAnsi();
13
+ }
14
+ }
@@ -1,7 +1,7 @@
1
1
  import * as Inputs from "../inputs";
2
2
  import { InputError, resolveDto } from "../kernel-calls";
3
- import { composeAxes, isFrameShaped, isTriple, PARALLEL_SINE, pointToLocal, pointToWorld, relativeAxes, squareFrame, unitOf, vectorToLocal, vectorToWorld, WORLD_AXES } from "./helpers/frame-axes";
4
- import { composed, symmetricEigen } from "./helpers/matrices";
3
+ import { axesToMatrix, composeAxes, isFrameShaped, isTriple, PARALLEL_SINE, pointToLocal, pointToWorld, relativeAxes, squareFrame, unitOf, vectorToLocal, vectorToWorld, WORLD_AXES } from "./helpers/geometry/frame-axes";
4
+ import { composed, symmetricEigen } from "./helpers/geometry/matrices";
5
5
  const EQUAL_COMPONENT_TOLERANCE = 1e-12;
6
6
  const reachOf = (vectors) => {
7
7
  let reach = 0;
@@ -623,7 +623,7 @@ export class Frame {
623
623
  * ```
624
624
  */
625
625
  toMatrix(inputs) {
626
- return [this.matrixBetween(WORLD_AXES, this.axesOf(inputs.frame, "frame"))];
626
+ return [axesToMatrix(this.axesOf(inputs.frame, "frame"))];
627
627
  }
628
628
  /**
629
629
  * Reads the frame a transformation puts the world frame on: where it moves the world origin
@@ -1,85 +1,6 @@
1
- const CELL_KEY_DIMENSIONS = 6;
2
- const CELL_SIZE_IN_TOLERANCES = 8;
3
- const CELL_PROBE_MARGIN_IN_TOLERANCES = 1.5;
4
- const CELL_ARITHMETIC_SAFE_MULTIPLE_OF_TOLERANCE = Math.pow(2, 50);
5
- const CELL_HASH_WORD = 4294967296;
6
- const hashCells = (vectorLength, cells) => {
7
- let hash = Math.imul(vectorLength + 1, 0x9E3779B1);
8
- for (let i = 0; i < cells.length; i++) {
9
- const cell = cells[i];
10
- const lowWord = cell % CELL_HASH_WORD;
11
- const highWord = (cell - lowWord) / CELL_HASH_WORD;
12
- hash = Math.imul(hash ^ lowWord, 0x85EBCA6B);
13
- hash = Math.imul(hash ^ highWord, 0xC2B2AE35);
14
- hash ^= hash >>> 15;
15
- }
16
- return hash;
17
- };
18
- const neverMatchesAnyVector = (vector, tolerance) => {
19
- for (let i = 0; i < vector.length; i++) {
20
- if (!Number.isFinite(vector[i])) {
21
- return true;
22
- }
23
- }
24
- return vector.length > 0 && !(tolerance > 0);
25
- };
26
- const vectorCellRange = (vector, tolerance) => {
27
- const keyDimensions = Math.min(vector.length, CELL_KEY_DIMENSIONS);
28
- if (keyDimensions > 0 && !Number.isFinite(tolerance)) {
29
- return undefined;
30
- }
31
- const cellSize = tolerance * CELL_SIZE_IN_TOLERANCES;
32
- const probeMargin = tolerance * CELL_PROBE_MARGIN_IN_TOLERANCES;
33
- const centre = [];
34
- const lowest = [];
35
- const highest = [];
36
- for (let i = 0; i < keyDimensions; i++) {
37
- const component = vector[i];
38
- if (Math.abs(component) / tolerance >= CELL_ARITHMETIC_SAFE_MULTIPLE_OF_TOLERANCE) {
39
- return undefined;
40
- }
41
- const lowestCell = Math.floor((component - probeMargin) / cellSize);
42
- const highestCell = Math.floor((component + probeMargin) / cellSize);
43
- const cellsToProbe = highestCell - lowestCell + 1;
44
- if (!Number.isInteger(lowestCell) || !Number.isInteger(highestCell) || cellsToProbe < 1 || cellsToProbe > 2) {
45
- return undefined;
46
- }
47
- centre.push(Math.floor(component / cellSize));
48
- lowest.push(lowestCell);
49
- highest.push(highestCell);
50
- }
51
- return { centre, lowest, highest };
52
- };
53
- const cellRangeHoldsSameVector = (keptVectorsByCell, vector, cellRange, isTheSameAsVector) => {
54
- const lowest = cellRange.lowest;
55
- const highest = cellRange.highest;
56
- const probe = lowest.slice();
57
- for (;;) {
58
- const cellVectors = keptVectorsByCell.get(hashCells(vector.length, probe));
59
- if (cellVectors !== undefined && cellVectors.some(isTheSameAsVector)) {
60
- return true;
61
- }
62
- let dimension = probe.length - 1;
63
- while (dimension >= 0 && probe[dimension] === highest[dimension]) {
64
- probe[dimension] = lowest[dimension];
65
- dimension--;
66
- }
67
- if (dimension < 0) {
68
- return false;
69
- }
70
- probe[dimension] = probe[dimension] + 1;
71
- }
72
- };
73
- const addVectorToCell = (keptVectorsByCell, vector, cellRange) => {
74
- const cellKey = hashCells(vector.length, cellRange.centre);
75
- const cellVectors = keptVectorsByCell.get(cellKey);
76
- if (cellVectors === undefined) {
77
- keptVectorsByCell.set(cellKey, [vector]);
78
- }
79
- else {
80
- cellVectors.push(vector);
81
- }
82
- };
1
+ import { movedCoordinate } from "./helpers/geometry/matrices";
2
+ import { W_AXIS } from "./helpers/geometry/matrices.constants";
3
+ import { uniqueVectors } from "./helpers/geometry/vector-grid";
83
4
  export class GeometryHelper {
84
5
  constructor() {
85
6
  /**
@@ -146,31 +67,7 @@ export class GeometryHelper {
146
67
  * Example: [[1,2], [3,4], [1,2], [5,6]] with tolerance=1e-7 → [[1,2], [3,4], [5,6]]
147
68
  */
148
69
  removeAllDuplicateVectors(vectors, tolerance = 1e-7) {
149
- const cleanVectors = [];
150
- const keptVectorsByCell = new Map();
151
- const keptVectorsOutsideCellIndex = [];
152
- vectors.forEach(vector => {
153
- if (neverMatchesAnyVector(vector, tolerance)) {
154
- cleanVectors.push(vector);
155
- return;
156
- }
157
- const isTheSameAsVector = (kept) => this.vectorsTheSame(vector, kept, tolerance);
158
- const cellRange = vectorCellRange(vector, tolerance);
159
- if (cellRange === undefined) {
160
- if (!cleanVectors.some(isTheSameAsVector)) {
161
- cleanVectors.push(vector);
162
- keptVectorsOutsideCellIndex.push(vector);
163
- }
164
- return;
165
- }
166
- const alreadyKept = cellRangeHoldsSameVector(keptVectorsByCell, vector, cellRange, isTheSameAsVector)
167
- || keptVectorsOutsideCellIndex.some(isTheSameAsVector);
168
- if (!alreadyKept) {
169
- cleanVectors.push(vector);
170
- addVectorToCell(keptVectorsByCell, vector, cellRange);
171
- }
172
- });
173
- return cleanVectors;
70
+ return uniqueVectors(vectors, tolerance).kept;
174
71
  }
175
72
  /**
176
73
  * Removes consecutive duplicate vectors from a list (keeps only first occurrence in each sequence).
@@ -286,10 +183,10 @@ export class GeometryHelper {
286
183
  }
287
184
  transformCoordinates(x, y, z, transformation) {
288
185
  const m = transformation;
289
- const rx = x * m[0] + y * m[4] + z * m[8] + m[12];
290
- const ry = x * m[1] + y * m[5] + z * m[9] + m[13];
291
- const rz = x * m[2] + y * m[6] + z * m[10] + m[14];
292
- const rw = 1 / (x * m[3] + y * m[7] + z * m[11] + m[15]);
186
+ const rx = movedCoordinate(m, x, y, z, 0);
187
+ const ry = movedCoordinate(m, x, y, z, 1);
188
+ const rz = movedCoordinate(m, x, y, z, 2);
189
+ const rw = 1 / movedCoordinate(m, x, y, z, W_AXIS);
293
190
  const newx = rx * rw;
294
191
  const newy = ry * rw;
295
192
  const newz = rz * rw;
@@ -0,0 +1,2 @@
1
+ export declare function srgbToLinear(channel: number): number;
2
+ export declare function linearToSrgb(channel: number): number;
@@ -0,0 +1,12 @@
1
+ const ENCODED_KNEE = 0.04045;
2
+ const LINEAR_KNEE = 0.0031308;
3
+ const LINEAR_SLOPE = 12.92;
4
+ const CURVE_OFFSET = 0.055;
5
+ const CURVE_SCALE = 1.055;
6
+ const CURVE_EXPONENT = 2.4;
7
+ export function srgbToLinear(channel) {
8
+ return channel <= ENCODED_KNEE ? channel / LINEAR_SLOPE : Math.pow(((channel + CURVE_OFFSET) / CURVE_SCALE), CURVE_EXPONENT);
9
+ }
10
+ export function linearToSrgb(channel) {
11
+ return channel <= LINEAR_KNEE ? channel * LINEAR_SLOPE : CURVE_SCALE * Math.pow(channel, (1 / CURVE_EXPONENT)) - CURVE_OFFSET;
12
+ }
@@ -1,4 +1,4 @@
1
- import type * as Inputs from "../../inputs";
1
+ import type * as Inputs from "../../../inputs";
2
2
  type Point3 = Inputs.Base.Point3;
3
3
  export declare const expandedKnots: (knots: readonly number[], multiplicities: readonly number[]) => number[];
4
4
  export declare const knotDomain: (degree: number, knots: readonly number[]) => [number, number];
@@ -1,5 +1,5 @@
1
- import type * as Inputs from "../../inputs";
2
- import type { RefinedSurfaceMesh } from "./helper-types";
1
+ import type * as Inputs from "../../../inputs";
2
+ import type { RefinedSurfaceMesh } from "../helper-types";
3
3
  type Point2 = Inputs.Base.Point2;
4
4
  type Point3 = Inputs.Base.Point3;
5
5
  export declare const refinedSurfaceMesh: (uv: readonly Point2[], positions: readonly Point3[], loops: readonly (readonly number[])[], pointAt: (u: number, v: number) => Point3) => RefinedSurfaceMesh;
@@ -1,5 +1,6 @@
1
- import { triangulateFace } from "./triangulation";
2
- import { add3, cross3, dot3, length3, scale3, subtract3 } from "./vectors";
1
+ import { triangulateFace } from "../geometry/triangulation";
2
+ import { add3, cross3, dot3, length3, scale3, subtract3 } from "../geometry/vectors";
3
+ import { angleOfCosine } from "../geometry/scalars";
3
4
  const SEGMENTS_PER_TURN = 32;
4
5
  const TURN_SLACK = 1e-6;
5
6
  const MAX_TURN = ((2 * Math.PI) / SEGMENTS_PER_TURN) * (1 + TURN_SLACK);
@@ -20,11 +21,16 @@ const unitOrUndefined = (vector) => {
20
21
  const length = length3(vector);
21
22
  return length > 0 ? scale3(vector, 1 / length) : undefined;
22
23
  };
23
- const angleAt = (corner, a, b) => {
24
+ const opposite = (corner, a, b) => {
24
25
  const toA = [a[0] - corner[0], a[1] - corner[1]];
25
26
  const toB = [b[0] - corner[0], b[1] - corner[1]];
26
- const lengths = Math.hypot(toA[0], toA[1]) * Math.hypot(toB[0], toB[1]);
27
- return lengths > 0 ? Math.acos(Math.max(-1, Math.min(1, (toA[0] * toB[0] + toA[1] * toB[1]) / lengths))) : 0;
27
+ return [toA[0] * toB[0] + toA[1] * toB[1], Math.abs(toA[0] * toB[1] - toA[1] * toB[0]), Math.hypot(toA[0], toA[1]) * Math.hypot(toB[0], toB[1])];
28
+ };
29
+ const anglesPassHalfTurn = (c, d, p, q) => {
30
+ const [cosC, sinC, lengthsC] = opposite(c, p, q);
31
+ const [cosD, sinD, lengthsD] = opposite(d, p, q);
32
+ const lengths = lengthsC * lengthsD;
33
+ return lengths > 0 && (sinC * cosD + cosC * sinD) / lengths < -FLIP_SLACK;
28
34
  };
29
35
  const orient2 = (a, b, c) => (b[0] - a[0]) * (c[1] - a[1]) - (b[1] - a[1]) * (c[0] - a[0]);
30
36
  class SurfaceMesh {
@@ -93,7 +99,7 @@ class SurfaceMesh {
93
99
  normalTurn(from, to) {
94
100
  const first = this.normalAt(from[0], from[1]);
95
101
  const second = this.normalAt(to[0], to[1]);
96
- return first && second ? Math.acos(Math.max(-1, Math.min(1, dot3(first, second)))) : 0;
102
+ return first && second ? angleOfCosine(dot3(first, second)) : 0;
97
103
  }
98
104
  scaled(vertex) {
99
105
  const [u, v] = this.uv[vertex];
@@ -112,7 +118,7 @@ class SurfaceMesh {
112
118
  turn(a, b) {
113
119
  const first = this.normal(a);
114
120
  const second = this.normal(b);
115
- return first && second ? Math.acos(Math.max(-1, Math.min(1, dot3(first, second)))) : 0;
121
+ return first && second ? angleOfCosine(dot3(first, second)) : 0;
116
122
  }
117
123
  bendingChord(a, b) {
118
124
  const first = this.normal(a);
@@ -285,7 +291,7 @@ class SurfaceMesh {
285
291
  const [p, q, c] = this.alongEdge(sharing[0], a, b);
286
292
  const [, , d] = this.alongEdge(sharing[1], a, b);
287
293
  const [sp, sq, sc, sd] = [p, q, c, d].map((vertex) => this.scaled(vertex));
288
- if (angleAt(sc, sp, sq) + angleAt(sd, sp, sq) > Math.PI + FLIP_SLACK) {
294
+ if (anglesPassHalfTurn(sc, sd, sp, sq)) {
289
295
  flipped = this.flip(a, b) || flipped;
290
296
  }
291
297
  }
@@ -1,4 +1,4 @@
1
- import * as Inputs from "../../../inputs";
1
+ import * as Inputs from "../../../../inputs";
2
2
  export declare class DxfGenerator {
3
3
  private entityHandle;
4
4
  private colorFormat;
@@ -8,6 +8,7 @@ export declare class DxfGenerator {
8
8
  */
9
9
  generateDxf(dxfInputs: Inputs.IO.DxfModelDto): string;
10
10
  private generateHeader;
11
+ private unitHeader;
11
12
  private generateTables;
12
13
  private generateLineTypeTable;
13
14
  private generateStyleTable;
@@ -1,9 +1,11 @@
1
- import * as Inputs from "../../../inputs";
2
- import { resolveDto } from "../../../kernel-calls";
1
+ import * as Inputs from "../../../../inputs";
2
+ import { InputError, resolveDto } from "../../../../kernel-calls";
3
+ import { checkedUnitOfLength } from "../../geometry/lengths";
4
+ import { DXF_FIRST_ENTITY_HANDLE, DXF_IMPERIAL_MEASUREMENT, DXF_INSUNITS, DXF_METRIC_MEASUREMENT } from "./dxf.constants";
3
5
  const CLOSED_POLYLINE_TOLERANCE = 1e-10;
4
6
  export class DxfGenerator {
5
7
  constructor() {
6
- this.entityHandle = 256;
8
+ this.entityHandle = DXF_FIRST_ENTITY_HANDLE;
7
9
  this.colorFormat = "aci";
8
10
  this.acadVersion = "AC1009";
9
11
  }
@@ -14,15 +16,16 @@ export class DxfGenerator {
14
16
  const resolved = resolveDto(Inputs.IO.DxfModelDto, dxfInputs);
15
17
  this.colorFormat = resolved.colorFormat || "aci";
16
18
  this.acadVersion = resolved.acadVersion || "AC1009";
19
+ this.entityHandle = DXF_FIRST_ENTITY_HANDLE;
17
20
  const dxfContent = [];
18
- dxfContent.push(...this.generateHeader());
21
+ dxfContent.push(...this.generateHeader(resolved.unit));
19
22
  dxfContent.push(...this.generateTables(resolved));
20
23
  dxfContent.push(...this.generateBlocks());
21
24
  dxfContent.push(...this.generateEntities(resolved));
22
25
  dxfContent.push("0", "EOF");
23
26
  return dxfContent.join("\n");
24
27
  }
25
- generateHeader() {
28
+ generateHeader(unit) {
26
29
  const header = [
27
30
  "0",
28
31
  "SECTION",
@@ -39,9 +42,20 @@ export class DxfGenerator {
39
42
  else {
40
43
  header.push("9", "$DWGCODEPAGE", "3", "ANSI_1252", "9", "$LASTSAVEDBY", "1", "bitbybit.dev", "9", "$HANDSEED", "5", "20000");
41
44
  }
45
+ header.push(...this.unitHeader(unit));
42
46
  header.push("0", "ENDSEC");
43
47
  return header;
44
48
  }
49
+ unitHeader(unit) {
50
+ if (unit === undefined) {
51
+ return [];
52
+ }
53
+ const checked = checkedUnitOfLength(unit, "unit");
54
+ if (this.acadVersion === "AC1009") {
55
+ throw new InputError("`unit` is given, but an AC1009 (R12) file has no place for a drawing's unit: write AC1015 to state it.", "unit");
56
+ }
57
+ return ["9", "$INSUNITS", "70", DXF_INSUNITS[checked], "9", "$MEASUREMENT", "70", checked === "in" ? DXF_IMPERIAL_MEASUREMENT : DXF_METRIC_MEASUREMENT];
58
+ }
45
59
  generateTables(dxfInputs) {
46
60
  const tables = [
47
61
  "0",
@@ -0,0 +1,4 @@
1
+ export declare const DXF_FIRST_ENTITY_HANDLE = 256;
2
+ export declare const DXF_INSUNITS: Readonly<Record<string, string>>;
3
+ export declare const DXF_IMPERIAL_MEASUREMENT = "0";
4
+ export declare const DXF_METRIC_MEASUREMENT = "1";
@@ -0,0 +1,4 @@
1
+ export const DXF_FIRST_ENTITY_HANDLE = 256;
2
+ export const DXF_INSUNITS = { in: "1", mm: "4", cm: "5", m: "6" };
3
+ export const DXF_IMPERIAL_MEASUREMENT = "0";
4
+ export const DXF_METRIC_MEASUREMENT = "1";
@@ -1,4 +1,4 @@
1
- import * as Inputs from "../../../inputs";
1
+ import * as Inputs from "../../../../inputs";
2
2
  export declare class Dxf {
3
3
  private dxfGenerator;
4
4
  /**
@@ -1,6 +1,6 @@
1
- import * as Inputs from "../../../inputs";
1
+ import * as Inputs from "../../../../inputs";
2
2
  import { DxfGenerator } from "./dxf-generator";
3
- import { resolveDto } from "../../../kernel-calls";
3
+ import { resolveDto } from "../../../../kernel-calls";
4
4
  export class Dxf {
5
5
  constructor() {
6
6
  this.dxfGenerator = new DxfGenerator();
@@ -0,0 +1,11 @@
1
+ export declare const GLB_MAGIC = 1179937895;
2
+ export declare const GLB_VERSION = 2;
3
+ export declare const GLB_HEADER_SIZE = 12;
4
+ export declare const GLB_VERSION_AT = 4;
5
+ export declare const GLB_LENGTH_AT = 8;
6
+ export declare const GLB_CHUNK_TYPE_AT = 4;
7
+ export declare const GLB_CHUNK_HEADER_SIZE = 8;
8
+ export declare const GLB_JSON_CHUNK = 1313821514;
9
+ export declare const GLB_ALIGNMENT = 4;
10
+ export declare const GLB_JSON_PADDING = 32;
11
+ export declare const GLB_SCALE_NODE_NAME = "unit scale";
@@ -0,0 +1,11 @@
1
+ export const GLB_MAGIC = 0x46546c67;
2
+ export const GLB_VERSION = 2;
3
+ export const GLB_HEADER_SIZE = 12;
4
+ export const GLB_VERSION_AT = 4;
5
+ export const GLB_LENGTH_AT = 8;
6
+ export const GLB_CHUNK_TYPE_AT = 4;
7
+ export const GLB_CHUNK_HEADER_SIZE = 8;
8
+ export const GLB_JSON_CHUNK = 0x4e4f534a;
9
+ export const GLB_ALIGNMENT = 4;
10
+ export const GLB_JSON_PADDING = 0x20;
11
+ export const GLB_SCALE_NODE_NAME = "unit scale";
@@ -0,0 +1 @@
1
+ export declare function glbWithRootScale(glb: Uint8Array, scale: number): Uint8Array;
@@ -0,0 +1,69 @@
1
+ import { GLB_ALIGNMENT, GLB_CHUNK_HEADER_SIZE, GLB_CHUNK_TYPE_AT, GLB_HEADER_SIZE, GLB_JSON_CHUNK, GLB_JSON_PADDING, GLB_LENGTH_AT, GLB_MAGIC, GLB_SCALE_NODE_NAME, GLB_VERSION, GLB_VERSION_AT, } from "./glb.constants";
2
+ function rootsOf(nodes) {
3
+ const children = new Set(nodes.flatMap(node => { var _a; return (_a = node.children) !== null && _a !== void 0 ? _a : []; }));
4
+ return nodes.map((_, index) => index).filter(index => !children.has(index));
5
+ }
6
+ const isIndexList = (value) => value === undefined || (Array.isArray(value) && value.every(index => Number.isInteger(index) && index >= 0));
7
+ function checkedJson(parsed) {
8
+ var _a, _b;
9
+ const json = parsed;
10
+ const objects = (value) => value === undefined || (Array.isArray(value) && value.every(item => typeof item === "object" && item !== null));
11
+ if (typeof json !== "object" || json === null || !objects(json.nodes) || !objects(json.scenes)
12
+ || !((_a = json.nodes) !== null && _a !== void 0 ? _a : []).every(node => isIndexList(node.children)) || !((_b = json.scenes) !== null && _b !== void 0 ? _b : []).every(scene => isIndexList(scene.nodes))) {
13
+ throw new Error("The glb's JSON is not glTF: its nodes or scenes are not lists of objects with index lists");
14
+ }
15
+ return json;
16
+ }
17
+ function scaledJson(json, scale) {
18
+ var _a, _b;
19
+ const nodes = [...((_a = json.nodes) !== null && _a !== void 0 ? _a : [])];
20
+ if (nodes.length === 0) {
21
+ return json;
22
+ }
23
+ const scenes = json.scenes !== undefined && json.scenes.length > 0 ? json.scenes : [{ nodes: rootsOf(nodes) }];
24
+ const placed = scenes.flatMap(scene => { var _a; return (_a = scene.nodes) !== null && _a !== void 0 ? _a : []; });
25
+ if (new Set(placed).size !== placed.length) {
26
+ throw new Error("The glb's scenes share root nodes, so no one node can scale each scene alone");
27
+ }
28
+ const wrapped = scenes.map(scene => {
29
+ var _a, _b;
30
+ if (((_a = scene.nodes) !== null && _a !== void 0 ? _a : []).length === 0) {
31
+ return scene;
32
+ }
33
+ nodes.push({ name: GLB_SCALE_NODE_NAME, scale: [scale, scale, scale], children: [...((_b = scene.nodes) !== null && _b !== void 0 ? _b : [])] });
34
+ return Object.assign(Object.assign({}, scene), { nodes: [nodes.length - 1] });
35
+ });
36
+ return Object.assign(Object.assign({}, json), { scene: (_b = json.scene) !== null && _b !== void 0 ? _b : 0, scenes: wrapped, nodes });
37
+ }
38
+ export function glbWithRootScale(glb, scale) {
39
+ if (!(scale > 0) || !Number.isFinite(scale)) {
40
+ throw new Error(`The glb's scale is ${String(scale)}; it has to be a finite number above zero`);
41
+ }
42
+ const view = new DataView(glb.buffer, glb.byteOffset, glb.byteLength);
43
+ if (glb.byteLength < GLB_HEADER_SIZE + GLB_CHUNK_HEADER_SIZE || view.getUint32(0, true) !== GLB_MAGIC || view.getUint32(GLB_VERSION_AT, true) !== GLB_VERSION) {
44
+ throw new Error("The data is not a version 2 glb: its header is missing");
45
+ }
46
+ const jsonLength = view.getUint32(GLB_HEADER_SIZE, true);
47
+ const jsonEnd = GLB_HEADER_SIZE + GLB_CHUNK_HEADER_SIZE + jsonLength;
48
+ if (view.getUint32(GLB_HEADER_SIZE + GLB_CHUNK_TYPE_AT, true) !== GLB_JSON_CHUNK || jsonEnd > glb.byteLength) {
49
+ throw new Error("The glb's first chunk is not its JSON, or runs past the end of the file");
50
+ }
51
+ if (scale === 1) {
52
+ return glb;
53
+ }
54
+ const json = checkedJson(JSON.parse(new TextDecoder().decode(glb.subarray(GLB_HEADER_SIZE + GLB_CHUNK_HEADER_SIZE, jsonEnd))));
55
+ const text = new TextEncoder().encode(JSON.stringify(scaledJson(json, scale)));
56
+ const padded = Math.ceil(text.length / GLB_ALIGNMENT) * GLB_ALIGNMENT;
57
+ const rest = glb.subarray(jsonEnd);
58
+ const result = new Uint8Array(GLB_HEADER_SIZE + GLB_CHUNK_HEADER_SIZE + padded + rest.length);
59
+ const out = new DataView(result.buffer);
60
+ out.setUint32(0, GLB_MAGIC, true);
61
+ out.setUint32(GLB_VERSION_AT, GLB_VERSION, true);
62
+ out.setUint32(GLB_LENGTH_AT, result.length, true);
63
+ out.setUint32(GLB_HEADER_SIZE, padded, true);
64
+ out.setUint32(GLB_HEADER_SIZE + GLB_CHUNK_TYPE_AT, GLB_JSON_CHUNK, true);
65
+ result.set(text, GLB_HEADER_SIZE + GLB_CHUNK_HEADER_SIZE);
66
+ result.fill(GLB_JSON_PADDING, GLB_HEADER_SIZE + GLB_CHUNK_HEADER_SIZE + text.length, GLB_HEADER_SIZE + GLB_CHUNK_HEADER_SIZE + padded);
67
+ result.set(rest, GLB_HEADER_SIZE + GLB_CHUNK_HEADER_SIZE + padded);
68
+ return result;
69
+ }
@@ -0,0 +1,11 @@
1
+ export declare const GZIP_MAGIC_FIRST = 31;
2
+ export declare const GZIP_MAGIC_SECOND = 139;
3
+ export declare const GZIP_DEFLATE_METHOD = 8;
4
+ export declare const GZIP_HEADER_SIZE = 10;
5
+ export declare const GZIP_TRAILER_SIZE = 8;
6
+ export declare const GZIP_FLAGS_AT = 3;
7
+ export declare const GZIP_METHOD_AT = 2;
8
+ export declare const GZIP_HEADER_CRC_FLAG = 2;
9
+ export declare const GZIP_EXTRA_FLAG = 4;
10
+ export declare const GZIP_NAME_FLAG = 8;
11
+ export declare const GZIP_COMMENT_FLAG = 16;
@@ -0,0 +1,11 @@
1
+ export const GZIP_MAGIC_FIRST = 0x1f;
2
+ export const GZIP_MAGIC_SECOND = 0x8b;
3
+ export const GZIP_DEFLATE_METHOD = 8;
4
+ export const GZIP_HEADER_SIZE = 10;
5
+ export const GZIP_TRAILER_SIZE = 8;
6
+ export const GZIP_FLAGS_AT = 3;
7
+ export const GZIP_METHOD_AT = 2;
8
+ export const GZIP_HEADER_CRC_FLAG = 2;
9
+ export const GZIP_EXTRA_FLAG = 4;
10
+ export const GZIP_NAME_FLAG = 8;
11
+ export const GZIP_COMMENT_FLAG = 16;
@@ -0,0 +1,2 @@
1
+ export declare function isGzip(bytes: Uint8Array): boolean;
2
+ export declare function gunzipped(bytes: Uint8Array, limit?: number): Uint8Array;
@@ -0,0 +1,50 @@
1
+ import { crc32 } from "./crc32";
2
+ import { inflateRaw } from "./inflate";
3
+ import { MOST_INFLATED_BYTES } from "./inflate.constants";
4
+ import { BYTE_BITS, UINT16_BYTES, UINT32_BYTES } from "./zip.constants";
5
+ import { GZIP_COMMENT_FLAG, GZIP_DEFLATE_METHOD, GZIP_EXTRA_FLAG, GZIP_FLAGS_AT, GZIP_HEADER_CRC_FLAG, GZIP_HEADER_SIZE, GZIP_MAGIC_FIRST, GZIP_MAGIC_SECOND, GZIP_METHOD_AT, GZIP_NAME_FLAG, GZIP_TRAILER_SIZE, } from "./gzip.constants";
6
+ function uint32(bytes, at) {
7
+ return new DataView(bytes.buffer, bytes.byteOffset, bytes.byteLength).getUint32(at, true);
8
+ }
9
+ function afterText(bytes, from) {
10
+ const end = bytes.indexOf(0, from);
11
+ if (end < 0) {
12
+ throw new Error("The gzip header's name or comment never ends");
13
+ }
14
+ return end + 1;
15
+ }
16
+ export function isGzip(bytes) {
17
+ return bytes.length >= 2 && bytes[0] === GZIP_MAGIC_FIRST && bytes[1] === GZIP_MAGIC_SECOND;
18
+ }
19
+ export function gunzipped(bytes, limit = MOST_INFLATED_BYTES) {
20
+ if (!isGzip(bytes) || bytes.length < GZIP_HEADER_SIZE + GZIP_TRAILER_SIZE) {
21
+ throw new Error("The data is not gzip: it does not start with the gzip signature or is too short to hold its header");
22
+ }
23
+ if (bytes[GZIP_METHOD_AT] !== GZIP_DEFLATE_METHOD) {
24
+ throw new Error(`The gzip data is compressed with method ${String(bytes[GZIP_METHOD_AT])}; only deflate is read`);
25
+ }
26
+ const flags = bytes[GZIP_FLAGS_AT];
27
+ let start = GZIP_HEADER_SIZE;
28
+ if (flags & GZIP_EXTRA_FLAG) {
29
+ start += UINT16_BYTES + (bytes[start] | (bytes[start + 1] << BYTE_BITS));
30
+ }
31
+ if (flags & GZIP_NAME_FLAG) {
32
+ start = afterText(bytes, start);
33
+ }
34
+ if (flags & GZIP_COMMENT_FLAG) {
35
+ start = afterText(bytes, start);
36
+ }
37
+ if (flags & GZIP_HEADER_CRC_FLAG) {
38
+ start += UINT16_BYTES;
39
+ }
40
+ const end = bytes.length - GZIP_TRAILER_SIZE;
41
+ if (start > end) {
42
+ throw new Error("The gzip header runs past the end of the data");
43
+ }
44
+ const size = uint32(bytes, end + UINT32_BYTES);
45
+ const data = inflateRaw(bytes.subarray(start, end), size, limit);
46
+ if (crc32(data) !== uint32(bytes, end)) {
47
+ throw new Error("The gzip data fails its CRC-32 check");
48
+ }
49
+ return data;
50
+ }
@@ -33,6 +33,8 @@ export declare const REPEAT_ZERO_SHORT_BASE = 3;
33
33
  export declare const REPEAT_ZERO_LONG_BITS = 7;
34
34
  export declare const REPEAT_ZERO_LONG_BASE = 11;
35
35
  export declare const INITIAL_OUTPUT: number;
36
+ export declare const MOST_DEFLATE_RATIO = 1032;
37
+ export declare const MOST_INFLATED_BYTES = 1073741824;
36
38
  export declare const CODE_LENGTH_ORDER: Uint8Array<ArrayBuffer>;
37
39
  export declare const LENGTH_BASE: Uint16Array<ArrayBuffer>;
38
40
  export declare const LENGTH_EXTRA: Uint8Array<ArrayBuffer>;
@@ -33,6 +33,8 @@ export const REPEAT_ZERO_SHORT_BASE = 3;
33
33
  export const REPEAT_ZERO_LONG_BITS = 7;
34
34
  export const REPEAT_ZERO_LONG_BASE = 11;
35
35
  export const INITIAL_OUTPUT = 1 << 16;
36
+ export const MOST_DEFLATE_RATIO = 1032;
37
+ export const MOST_INFLATED_BYTES = 0x40000000;
36
38
  export const CODE_LENGTH_ORDER = Uint8Array.of(16, 17, 18, 0, 8, 7, 9, 6, 10, 5, 11, 4, 12, 3, 13, 2, 14, 1, 15);
37
39
  export const LENGTH_BASE = Uint16Array.of(3, 4, 5, 6, 7, 8, 9, 10, 11, 13, 15, 17, 19, 23, 27, 31, 35, 43, 51, 59, 67, 83, 99, 115, 131, 163, 195, 227, 258);
38
40
  export const LENGTH_EXTRA = Uint8Array.of(0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 2, 2, 2, 2, 3, 3, 3, 3, 4, 4, 4, 4, 5, 5, 5, 5, 0);
@@ -1,3 +1,3 @@
1
- import type { HuffmanTable } from "./helper-types";
1
+ import type { HuffmanTable } from "../helper-types";
2
2
  export declare function huffmanTable(lengths: ArrayLike<number>): HuffmanTable;
3
- export declare function inflateRaw(data: Uint8Array, expectedSize?: number): Uint8Array;
3
+ export declare function inflateRaw(data: Uint8Array, expectedSize?: number, limit?: number): Uint8Array;