@lampdotdev/lamp 0.0.0-stage → 0.36.2-nightly.16

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 (470) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +397 -2
  3. package/Resources/Devices/roku.json +410 -0
  4. package/Resources/Devices/xbox-one.json +367 -0
  5. package/Resources/GameKit/NOTICE.md +63 -0
  6. package/Resources/GameKit/apple/LampPage.swift +1813 -0
  7. package/Resources/GameKit/apple/LampPlayer.swift +46 -0
  8. package/Resources/GameKit/apple/LampWebApp.swift +63 -0
  9. package/Resources/GameKit/apple/LampWebGame.swift +87 -0
  10. package/Resources/GameKit/apple/Native.swift +12 -0
  11. package/Resources/GameKit/build.sh +55 -0
  12. package/Resources/GameKit/lamp_game.h +116 -0
  13. package/Resources/GameKit/lamp_host.h +19 -0
  14. package/Resources/GameKit/lamp_kit.cpp +61 -0
  15. package/Resources/GameKit/lamp_sound.cpp +455 -0
  16. package/Resources/GameKit/lamp_xbox.cpp +374 -0
  17. package/Resources/GameKit/libraries/HandmadeMath.h +3940 -0
  18. package/Resources/GameKit/libraries/cgltf.h +7240 -0
  19. package/Resources/GameKit/libraries/dr_mp3.h +5430 -0
  20. package/Resources/GameKit/libraries/dr_wav.h +9209 -0
  21. package/Resources/GameKit/libraries/sokol_debugtext.h +4754 -0
  22. package/Resources/GameKit/libraries/sokol_gfx.h +29558 -0
  23. package/Resources/GameKit/libraries/sokol_gl.h +4538 -0
  24. package/Resources/GameKit/libraries/sokol_log.h +335 -0
  25. package/Resources/GameKit/libraries/sokol_shape.h +1531 -0
  26. package/Resources/GameKit/libraries/stb_image.h +7988 -0
  27. package/Resources/GameKit/libraries/stb_vorbis.c +5584 -0
  28. package/Resources/GameKit/page/lamp-live.js +672 -0
  29. package/Resources/GameKit/scaffold/Game/game.cpp +142 -0
  30. package/Resources/GameKit/scaffold/Game/scene.glsl +49 -0
  31. package/Resources/GameKit/scaffold-web/Web/game.js +31 -0
  32. package/Resources/GameKit/scaffold-web/Web/index.html +13 -0
  33. package/Resources/GameKit/scaffold-web/Web/making.js +33 -0
  34. package/Resources/GameKit/scaffold-web/Web/world.js +33 -0
  35. package/Resources/GameKit/web/lamp-game.js +3042 -0
  36. package/Resources/GameKit/web/lamp-phaser.js +128 -0
  37. package/Resources/WebHost/App.exe +0 -0
  38. package/Resources/WebHost/Microsoft.Web.WebView2.Core.dll +0 -0
  39. package/Resources/WebHost/WebView2-LICENSE.txt +27 -0
  40. package/Resources/WebHost/lamp_controllers.h +1506 -0
  41. package/Resources/WebHost/lamp_web_host.cpp +1173 -0
  42. package/Resources/WebLibraries/earlier.txt +318 -0
  43. package/Resources/WebLibraries/phaser/LICENSE.md +20 -0
  44. package/Resources/WebLibraries/phaser/NOTICE.md +2 -0
  45. package/Resources/WebLibraries/phaser/phaser.esm.min.js +1 -0
  46. package/Resources/WebLibraries/qrcode/LICENSE +21 -0
  47. package/Resources/WebLibraries/qrcode/NOTICE.md +4 -0
  48. package/Resources/WebLibraries/qrcode/qrcode.js +2297 -0
  49. package/Resources/WebLibraries/rapier/LICENSE +201 -0
  50. package/Resources/WebLibraries/rapier/NOTICE.md +3 -0
  51. package/Resources/WebLibraries/rapier/rapier.js +2 -0
  52. package/Resources/WebLibraries/three/LICENSE +21 -0
  53. package/Resources/WebLibraries/three/NOTICE.md +4 -0
  54. package/Resources/WebLibraries/three/addons/animation/AnimationClipCreator.js +168 -0
  55. package/Resources/WebLibraries/three/addons/animation/CCDIKSolver.js +607 -0
  56. package/Resources/WebLibraries/three/addons/controls/ArcballControls.js +3543 -0
  57. package/Resources/WebLibraries/three/addons/controls/DragControls.js +452 -0
  58. package/Resources/WebLibraries/three/addons/controls/FirstPersonControls.js +512 -0
  59. package/Resources/WebLibraries/three/addons/controls/FlyControls.js +384 -0
  60. package/Resources/WebLibraries/three/addons/controls/MapControls.js +116 -0
  61. package/Resources/WebLibraries/three/addons/controls/OrbitControls.js +1985 -0
  62. package/Resources/WebLibraries/three/addons/controls/PointerLockControls.js +264 -0
  63. package/Resources/WebLibraries/three/addons/controls/TrackballControls.js +1106 -0
  64. package/Resources/WebLibraries/three/addons/controls/TransformControls.js +2003 -0
  65. package/Resources/WebLibraries/three/addons/curves/CurveExtras.js +694 -0
  66. package/Resources/WebLibraries/three/addons/curves/NURBSCurve.js +169 -0
  67. package/Resources/WebLibraries/three/addons/curves/NURBSSurface.js +98 -0
  68. package/Resources/WebLibraries/three/addons/curves/NURBSUtils.js +532 -0
  69. package/Resources/WebLibraries/three/addons/curves/NURBSVolume.js +82 -0
  70. package/Resources/WebLibraries/three/addons/effects/AnaglyphEffect.js +274 -0
  71. package/Resources/WebLibraries/three/addons/effects/AsciiEffect.js +323 -0
  72. package/Resources/WebLibraries/three/addons/effects/OutlineEffect.js +489 -0
  73. package/Resources/WebLibraries/three/addons/effects/ParallaxBarrierEffect.js +155 -0
  74. package/Resources/WebLibraries/three/addons/effects/StereoEffect.js +91 -0
  75. package/Resources/WebLibraries/three/addons/environments/ColorEnvironment.js +59 -0
  76. package/Resources/WebLibraries/three/addons/environments/DebugEnvironment.js +102 -0
  77. package/Resources/WebLibraries/three/addons/environments/RoomEnvironment.js +185 -0
  78. package/Resources/WebLibraries/three/addons/geometries/BoxLineGeometry.js +92 -0
  79. package/Resources/WebLibraries/three/addons/geometries/ConvexGeometry.js +72 -0
  80. package/Resources/WebLibraries/three/addons/geometries/DecalGeometry.js +420 -0
  81. package/Resources/WebLibraries/three/addons/geometries/LoftGeometry.js +355 -0
  82. package/Resources/WebLibraries/three/addons/geometries/ParametricFunctions.js +100 -0
  83. package/Resources/WebLibraries/three/addons/geometries/ParametricGeometry.js +172 -0
  84. package/Resources/WebLibraries/three/addons/geometries/RoundedBoxGeometry.js +216 -0
  85. package/Resources/WebLibraries/three/addons/geometries/TeapotGeometry.js +689 -0
  86. package/Resources/WebLibraries/three/addons/geometries/TextGeometry.js +102 -0
  87. package/Resources/WebLibraries/three/addons/helpers/AnimationPathHelper.js +302 -0
  88. package/Resources/WebLibraries/three/addons/helpers/LightProbeGridHelper.js +166 -0
  89. package/Resources/WebLibraries/three/addons/helpers/LightProbeGridHelperWebGL.js +221 -0
  90. package/Resources/WebLibraries/three/addons/helpers/LightProbeHelper.js +166 -0
  91. package/Resources/WebLibraries/three/addons/helpers/LightProbeHelperGPU.js +102 -0
  92. package/Resources/WebLibraries/three/addons/helpers/OctreeHelper.js +109 -0
  93. package/Resources/WebLibraries/three/addons/helpers/PositionalAudioHelper.js +169 -0
  94. package/Resources/WebLibraries/three/addons/helpers/RapierHelper.js +59 -0
  95. package/Resources/WebLibraries/three/addons/helpers/RectAreaLightHelper.js +118 -0
  96. package/Resources/WebLibraries/three/addons/helpers/TextureHelper.js +265 -0
  97. package/Resources/WebLibraries/three/addons/helpers/TextureHelperGPU.js +214 -0
  98. package/Resources/WebLibraries/three/addons/helpers/VertexNormalsHelper.js +155 -0
  99. package/Resources/WebLibraries/three/addons/helpers/VertexTangentsHelper.js +133 -0
  100. package/Resources/WebLibraries/three/addons/helpers/ViewHelper.js +529 -0
  101. package/Resources/WebLibraries/three/addons/interactive/HTMLMesh.js +617 -0
  102. package/Resources/WebLibraries/three/addons/interactive/InteractiveGroup.js +224 -0
  103. package/Resources/WebLibraries/three/addons/interactive/SelectionBox.js +324 -0
  104. package/Resources/WebLibraries/three/addons/interactive/SelectionHelper.js +150 -0
  105. package/Resources/WebLibraries/three/addons/libs/fflate.module.js +2699 -0
  106. package/Resources/WebLibraries/three/addons/libs/lil-gui.module.min.js +8 -0
  107. package/Resources/WebLibraries/three/addons/libs/meshopt_decoder.module.js +196 -0
  108. package/Resources/WebLibraries/three/addons/libs/potpack.module.js +125 -0
  109. package/Resources/WebLibraries/three/addons/libs/stats.module.js +167 -0
  110. package/Resources/WebLibraries/three/addons/libs/tween.module.js +876 -0
  111. package/Resources/WebLibraries/three/addons/lighting/ClusteredLighting.js +153 -0
  112. package/Resources/WebLibraries/three/addons/lighting/DynamicLighting.js +82 -0
  113. package/Resources/WebLibraries/three/addons/lighting/LightMapper.js +295 -0
  114. package/Resources/WebLibraries/three/addons/lighting/LightProbeGrid.js +923 -0
  115. package/Resources/WebLibraries/three/addons/lighting/LightProbeGridUtils.js +107 -0
  116. package/Resources/WebLibraries/three/addons/lighting/LightProbeGridWebGL.js +846 -0
  117. package/Resources/WebLibraries/three/addons/lighting/vxgi/VXGIConeTracer.js +243 -0
  118. package/Resources/WebLibraries/three/addons/lighting/vxgi/VXGIIrradiance.js +43 -0
  119. package/Resources/WebLibraries/three/addons/lighting/vxgi/VXGINode.js +617 -0
  120. package/Resources/WebLibraries/three/addons/lighting/vxgi/VXGISceneCollector.js +793 -0
  121. package/Resources/WebLibraries/three/addons/lighting/vxgi/VXGIVolume.js +1440 -0
  122. package/Resources/WebLibraries/three/addons/lights/LightProbeGenerator.js +337 -0
  123. package/Resources/WebLibraries/three/addons/lights/RectAreaLightTexturesLib.js +127 -0
  124. package/Resources/WebLibraries/three/addons/lights/RectAreaLightUniformsLib.js +40 -0
  125. package/Resources/WebLibraries/three/addons/lights/SunLight.js +100 -0
  126. package/Resources/WebLibraries/three/addons/lights/SunLightNode.js +56 -0
  127. package/Resources/WebLibraries/three/addons/lights/SunLightShadow.js +319 -0
  128. package/Resources/WebLibraries/three/addons/lights/SunShadowNode.js +312 -0
  129. package/Resources/WebLibraries/three/addons/lines/Line2.js +56 -0
  130. package/Resources/WebLibraries/three/addons/lines/LineGeometry.js +157 -0
  131. package/Resources/WebLibraries/three/addons/lines/LineMaterial.js +742 -0
  132. package/Resources/WebLibraries/three/addons/lines/LineSegments2.js +434 -0
  133. package/Resources/WebLibraries/three/addons/lines/LineSegmentsGeometry.js +298 -0
  134. package/Resources/WebLibraries/three/addons/lines/Wireframe.js +108 -0
  135. package/Resources/WebLibraries/three/addons/lines/WireframeGeometry2.js +49 -0
  136. package/Resources/WebLibraries/three/addons/lines/webgpu/Line2.js +46 -0
  137. package/Resources/WebLibraries/three/addons/lines/webgpu/LineSegments2.js +419 -0
  138. package/Resources/WebLibraries/three/addons/lines/webgpu/Wireframe.js +86 -0
  139. package/Resources/WebLibraries/three/addons/loaders/EXRLoader.js +3411 -0
  140. package/Resources/WebLibraries/three/addons/loaders/FBXLoader.js +4660 -0
  141. package/Resources/WebLibraries/three/addons/loaders/FontLoader.js +262 -0
  142. package/Resources/WebLibraries/three/addons/loaders/GLTFLoader.js +5006 -0
  143. package/Resources/WebLibraries/three/addons/loaders/HDRLoader.js +463 -0
  144. package/Resources/WebLibraries/three/addons/loaders/MTLLoader.js +601 -0
  145. package/Resources/WebLibraries/three/addons/loaders/OBJLoader.js +961 -0
  146. package/Resources/WebLibraries/three/addons/loaders/PLYLoader.js +992 -0
  147. package/Resources/WebLibraries/three/addons/loaders/RGBELoader.js +18 -0
  148. package/Resources/WebLibraries/three/addons/loaders/STLLoader.js +423 -0
  149. package/Resources/WebLibraries/three/addons/loaders/SVGLoader.js +3297 -0
  150. package/Resources/WebLibraries/three/addons/loaders/TGALoader.js +539 -0
  151. package/Resources/WebLibraries/three/addons/loaders/UltraHDRLoader.js +757 -0
  152. package/Resources/WebLibraries/three/addons/math/Capsule.js +159 -0
  153. package/Resources/WebLibraries/three/addons/math/ColorConverter.js +62 -0
  154. package/Resources/WebLibraries/three/addons/math/ColorSpaces.js +147 -0
  155. package/Resources/WebLibraries/three/addons/math/ConvexHull.js +1695 -0
  156. package/Resources/WebLibraries/three/addons/math/ImprovedNoise.js +88 -0
  157. package/Resources/WebLibraries/three/addons/math/Lut.js +317 -0
  158. package/Resources/WebLibraries/three/addons/math/MeshSurfaceSampler.js +315 -0
  159. package/Resources/WebLibraries/three/addons/math/OBB.js +535 -0
  160. package/Resources/WebLibraries/three/addons/math/Octree.js +825 -0
  161. package/Resources/WebLibraries/three/addons/math/SimplexNoise.js +470 -0
  162. package/Resources/WebLibraries/three/addons/misc/ConvexObjectBreaker.js +539 -0
  163. package/Resources/WebLibraries/three/addons/misc/GPUComputationRenderer.js +508 -0
  164. package/Resources/WebLibraries/three/addons/misc/Gyroscope.js +78 -0
  165. package/Resources/WebLibraries/three/addons/misc/MorphAnimMesh.js +119 -0
  166. package/Resources/WebLibraries/three/addons/misc/MorphBlendMesh.js +425 -0
  167. package/Resources/WebLibraries/three/addons/misc/ProgressiveLightMap.js +370 -0
  168. package/Resources/WebLibraries/three/addons/misc/ProgressiveLightMapGPU.js +322 -0
  169. package/Resources/WebLibraries/three/addons/misc/RollerCoaster.js +661 -0
  170. package/Resources/WebLibraries/three/addons/misc/Sculptor.js +1679 -0
  171. package/Resources/WebLibraries/three/addons/misc/SculptorMesh.js +1504 -0
  172. package/Resources/WebLibraries/three/addons/misc/SculptorTools.js +1180 -0
  173. package/Resources/WebLibraries/three/addons/misc/SculptorUtils.js +345 -0
  174. package/Resources/WebLibraries/three/addons/misc/TileCreasedNormalsPlugin.js +270 -0
  175. package/Resources/WebLibraries/three/addons/misc/TubePainter.js +611 -0
  176. package/Resources/WebLibraries/three/addons/misc/Volume.js +520 -0
  177. package/Resources/WebLibraries/three/addons/misc/VolumeSlice.js +275 -0
  178. package/Resources/WebLibraries/three/addons/modifiers/CurveModifier.js +374 -0
  179. package/Resources/WebLibraries/three/addons/modifiers/CurveModifierGPU.js +256 -0
  180. package/Resources/WebLibraries/three/addons/modifiers/EdgeSplitModifier.js +299 -0
  181. package/Resources/WebLibraries/three/addons/modifiers/TessellateModifier.js +340 -0
  182. package/Resources/WebLibraries/three/addons/objects/GroundedSkybox.js +69 -0
  183. package/Resources/WebLibraries/three/addons/objects/Lensflare.js +489 -0
  184. package/Resources/WebLibraries/three/addons/objects/LensflareMesh.js +376 -0
  185. package/Resources/WebLibraries/three/addons/objects/MarchingCubes.js +1261 -0
  186. package/Resources/WebLibraries/three/addons/objects/Reflector.js +390 -0
  187. package/Resources/WebLibraries/three/addons/objects/ReflectorForSSRPass.js +393 -0
  188. package/Resources/WebLibraries/three/addons/objects/Refractor.js +389 -0
  189. package/Resources/WebLibraries/three/addons/objects/ShadowMesh.js +130 -0
  190. package/Resources/WebLibraries/three/addons/objects/Sky.js +342 -0
  191. package/Resources/WebLibraries/three/addons/objects/SkyMesh.js +403 -0
  192. package/Resources/WebLibraries/three/addons/objects/Water.js +374 -0
  193. package/Resources/WebLibraries/three/addons/objects/Water2.js +403 -0
  194. package/Resources/WebLibraries/three/addons/objects/Water2Mesh.js +199 -0
  195. package/Resources/WebLibraries/three/addons/objects/WaterMesh.js +194 -0
  196. package/Resources/WebLibraries/three/addons/postprocessing/AfterimagePass.js +187 -0
  197. package/Resources/WebLibraries/three/addons/postprocessing/BloomPass.js +274 -0
  198. package/Resources/WebLibraries/three/addons/postprocessing/BokehPass.js +218 -0
  199. package/Resources/WebLibraries/three/addons/postprocessing/ClearPass.js +97 -0
  200. package/Resources/WebLibraries/three/addons/postprocessing/CubeTexturePass.js +146 -0
  201. package/Resources/WebLibraries/three/addons/postprocessing/DotScreenPass.js +114 -0
  202. package/Resources/WebLibraries/three/addons/postprocessing/EffectComposer.js +365 -0
  203. package/Resources/WebLibraries/three/addons/postprocessing/FXAAPass.js +40 -0
  204. package/Resources/WebLibraries/three/addons/postprocessing/FilmPass.js +113 -0
  205. package/Resources/WebLibraries/three/addons/postprocessing/GTAOPass.js +735 -0
  206. package/Resources/WebLibraries/three/addons/postprocessing/GlitchPass.js +177 -0
  207. package/Resources/WebLibraries/three/addons/postprocessing/HalftonePass.js +134 -0
  208. package/Resources/WebLibraries/three/addons/postprocessing/LUTPass.js +138 -0
  209. package/Resources/WebLibraries/three/addons/postprocessing/MaskPass.js +195 -0
  210. package/Resources/WebLibraries/three/addons/postprocessing/OutlinePass.js +776 -0
  211. package/Resources/WebLibraries/three/addons/postprocessing/OutputPass.js +148 -0
  212. package/Resources/WebLibraries/three/addons/postprocessing/Pass.js +191 -0
  213. package/Resources/WebLibraries/three/addons/postprocessing/RenderPass.js +193 -0
  214. package/Resources/WebLibraries/three/addons/postprocessing/RenderPixelatedPass.js +314 -0
  215. package/Resources/WebLibraries/three/addons/postprocessing/RenderTransitionPass.js +267 -0
  216. package/Resources/WebLibraries/three/addons/postprocessing/SAOPass.js +407 -0
  217. package/Resources/WebLibraries/three/addons/postprocessing/SMAAPass.js +230 -0
  218. package/Resources/WebLibraries/three/addons/postprocessing/SSAARenderPass.js +313 -0
  219. package/Resources/WebLibraries/three/addons/postprocessing/SSAOPass.js +527 -0
  220. package/Resources/WebLibraries/three/addons/postprocessing/SSRPass.js +858 -0
  221. package/Resources/WebLibraries/three/addons/postprocessing/SavePass.js +132 -0
  222. package/Resources/WebLibraries/three/addons/postprocessing/ShaderPass.js +135 -0
  223. package/Resources/WebLibraries/three/addons/postprocessing/TAARenderPass.js +243 -0
  224. package/Resources/WebLibraries/three/addons/postprocessing/TexturePass.js +131 -0
  225. package/Resources/WebLibraries/three/addons/postprocessing/UnrealBloomPass.js +541 -0
  226. package/Resources/WebLibraries/three/addons/shaders/ACESFilmicToneMappingShader.js +96 -0
  227. package/Resources/WebLibraries/three/addons/shaders/AfterimageShader.js +63 -0
  228. package/Resources/WebLibraries/three/addons/shaders/BasicShader.js +36 -0
  229. package/Resources/WebLibraries/three/addons/shaders/BleachBypassShader.js +68 -0
  230. package/Resources/WebLibraries/three/addons/shaders/BlendShader.js +56 -0
  231. package/Resources/WebLibraries/three/addons/shaders/BokehShader.js +151 -0
  232. package/Resources/WebLibraries/three/addons/shaders/BokehShader2.js +404 -0
  233. package/Resources/WebLibraries/three/addons/shaders/BrightnessContrastShader.js +62 -0
  234. package/Resources/WebLibraries/three/addons/shaders/ColorCorrectionShader.js +59 -0
  235. package/Resources/WebLibraries/three/addons/shaders/ColorifyShader.js +57 -0
  236. package/Resources/WebLibraries/three/addons/shaders/ConvolutionShader.js +74 -0
  237. package/Resources/WebLibraries/three/addons/shaders/CopyShader.js +52 -0
  238. package/Resources/WebLibraries/three/addons/shaders/DOFMipMapShader.js +63 -0
  239. package/Resources/WebLibraries/three/addons/shaders/DepthLimitedBlurShader.js +183 -0
  240. package/Resources/WebLibraries/three/addons/shaders/DigitalGlitch.js +104 -0
  241. package/Resources/WebLibraries/three/addons/shaders/DotScreenShader.js +75 -0
  242. package/Resources/WebLibraries/three/addons/shaders/ExposureShader.js +51 -0
  243. package/Resources/WebLibraries/three/addons/shaders/FXAAShader.js +298 -0
  244. package/Resources/WebLibraries/three/addons/shaders/FilmShader.js +73 -0
  245. package/Resources/WebLibraries/three/addons/shaders/FocusShader.js +94 -0
  246. package/Resources/WebLibraries/three/addons/shaders/FreiChenShader.js +103 -0
  247. package/Resources/WebLibraries/three/addons/shaders/GTAOShader.js +437 -0
  248. package/Resources/WebLibraries/three/addons/shaders/GammaCorrectionShader.js +52 -0
  249. package/Resources/WebLibraries/three/addons/shaders/HalftoneShader.js +332 -0
  250. package/Resources/WebLibraries/three/addons/shaders/HorizontalBlurShader.js +68 -0
  251. package/Resources/WebLibraries/three/addons/shaders/HorizontalTiltShiftShader.js +70 -0
  252. package/Resources/WebLibraries/three/addons/shaders/HueSaturationShader.js +74 -0
  253. package/Resources/WebLibraries/three/addons/shaders/KaleidoShader.js +65 -0
  254. package/Resources/WebLibraries/three/addons/shaders/LuminosityHighPassShader.js +68 -0
  255. package/Resources/WebLibraries/three/addons/shaders/LuminosityShader.js +54 -0
  256. package/Resources/WebLibraries/three/addons/shaders/MirrorShader.js +62 -0
  257. package/Resources/WebLibraries/three/addons/shaders/NormalMapShader.js +60 -0
  258. package/Resources/WebLibraries/three/addons/shaders/OutputShader.js +103 -0
  259. package/Resources/WebLibraries/three/addons/shaders/PoissonDenoiseShader.js +230 -0
  260. package/Resources/WebLibraries/three/addons/shaders/RGBShiftShader.js +61 -0
  261. package/Resources/WebLibraries/three/addons/shaders/SAOShader.js +201 -0
  262. package/Resources/WebLibraries/three/addons/shaders/SMAAShader.js +489 -0
  263. package/Resources/WebLibraries/three/addons/shaders/SSAOShader.js +331 -0
  264. package/Resources/WebLibraries/three/addons/shaders/SSRShader.js +396 -0
  265. package/Resources/WebLibraries/three/addons/shaders/SepiaShader.js +57 -0
  266. package/Resources/WebLibraries/three/addons/shaders/SobelOperatorShader.js +98 -0
  267. package/Resources/WebLibraries/three/addons/shaders/SubsurfaceScatteringShader.js +95 -0
  268. package/Resources/WebLibraries/three/addons/shaders/TechnicolorShader.js +51 -0
  269. package/Resources/WebLibraries/three/addons/shaders/ToonShader.js +349 -0
  270. package/Resources/WebLibraries/three/addons/shaders/TriangleBlurShader.js +79 -0
  271. package/Resources/WebLibraries/three/addons/shaders/UnpackDepthRGBAShader.js +60 -0
  272. package/Resources/WebLibraries/three/addons/shaders/VelocityShader.js +137 -0
  273. package/Resources/WebLibraries/three/addons/shaders/VerticalBlurShader.js +66 -0
  274. package/Resources/WebLibraries/three/addons/shaders/VerticalTiltShiftShader.js +70 -0
  275. package/Resources/WebLibraries/three/addons/shaders/VignetteShader.js +56 -0
  276. package/Resources/WebLibraries/three/addons/shaders/VolumeShader.js +285 -0
  277. package/Resources/WebLibraries/three/addons/shaders/WaterRefractionShader.js +106 -0
  278. package/Resources/WebLibraries/three/addons/textures/FlakesTexture.js +54 -0
  279. package/Resources/WebLibraries/three/addons/tsl/WebGLNodesHandler.js +607 -0
  280. package/Resources/WebLibraries/three/addons/tsl/display/AfterImageNode.js +256 -0
  281. package/Resources/WebLibraries/three/addons/tsl/display/AnaglyphPassNode.js +550 -0
  282. package/Resources/WebLibraries/three/addons/tsl/display/BilateralBlurNode.js +377 -0
  283. package/Resources/WebLibraries/three/addons/tsl/display/BleachBypass.js +33 -0
  284. package/Resources/WebLibraries/three/addons/tsl/display/BloomNode.js +599 -0
  285. package/Resources/WebLibraries/three/addons/tsl/display/CRT.js +150 -0
  286. package/Resources/WebLibraries/three/addons/tsl/display/ChromaticAberrationNode.js +163 -0
  287. package/Resources/WebLibraries/three/addons/tsl/display/DenoiseNode.js +354 -0
  288. package/Resources/WebLibraries/three/addons/tsl/display/DepthOfFieldNode.js +572 -0
  289. package/Resources/WebLibraries/three/addons/tsl/display/DotScreenNode.js +104 -0
  290. package/Resources/WebLibraries/three/addons/tsl/display/FSR1Node.js +481 -0
  291. package/Resources/WebLibraries/three/addons/tsl/display/FXAANode.js +357 -0
  292. package/Resources/WebLibraries/three/addons/tsl/display/FilmNode.js +101 -0
  293. package/Resources/WebLibraries/three/addons/tsl/display/GTAONode.js +727 -0
  294. package/Resources/WebLibraries/three/addons/tsl/display/GaussianBlurNode.js +412 -0
  295. package/Resources/WebLibraries/three/addons/tsl/display/GodraysNode.js +604 -0
  296. package/Resources/WebLibraries/three/addons/tsl/display/ImportanceSampledEnvironment.js +564 -0
  297. package/Resources/WebLibraries/three/addons/tsl/display/LensflareNode.js +282 -0
  298. package/Resources/WebLibraries/three/addons/tsl/display/Lut3DNode.js +109 -0
  299. package/Resources/WebLibraries/three/addons/tsl/display/MotionBlur.js +33 -0
  300. package/Resources/WebLibraries/three/addons/tsl/display/OITPassNode.js +341 -0
  301. package/Resources/WebLibraries/three/addons/tsl/display/OutlineNode.js +916 -0
  302. package/Resources/WebLibraries/three/addons/tsl/display/ParallaxBarrierPassNode.js +90 -0
  303. package/Resources/WebLibraries/three/addons/tsl/display/PixelationPassNode.js +227 -0
  304. package/Resources/WebLibraries/three/addons/tsl/display/RGBShiftNode.js +96 -0
  305. package/Resources/WebLibraries/three/addons/tsl/display/RecurrentDenoiseNode.js +812 -0
  306. package/Resources/WebLibraries/three/addons/tsl/display/RetroPassNode.js +263 -0
  307. package/Resources/WebLibraries/three/addons/tsl/display/SMAANode.js +729 -0
  308. package/Resources/WebLibraries/three/addons/tsl/display/SSAAPassNode.js +344 -0
  309. package/Resources/WebLibraries/three/addons/tsl/display/SSAONode.js +422 -0
  310. package/Resources/WebLibraries/three/addons/tsl/display/SSGINode.js +698 -0
  311. package/Resources/WebLibraries/three/addons/tsl/display/SSRNode.js +1430 -0
  312. package/Resources/WebLibraries/three/addons/tsl/display/SSSNode.js +479 -0
  313. package/Resources/WebLibraries/three/addons/tsl/display/Sepia.js +24 -0
  314. package/Resources/WebLibraries/three/addons/tsl/display/Shape.js +29 -0
  315. package/Resources/WebLibraries/three/addons/tsl/display/SharpenNode.js +284 -0
  316. package/Resources/WebLibraries/three/addons/tsl/display/SobelOperatorNode.js +168 -0
  317. package/Resources/WebLibraries/three/addons/tsl/display/StereoCompositePassNode.js +190 -0
  318. package/Resources/WebLibraries/three/addons/tsl/display/StereoPassNode.js +117 -0
  319. package/Resources/WebLibraries/three/addons/tsl/display/TAAUNode.js +700 -0
  320. package/Resources/WebLibraries/three/addons/tsl/display/TRAANode.js +609 -0
  321. package/Resources/WebLibraries/three/addons/tsl/display/TemporalReprojectNode.js +1024 -0
  322. package/Resources/WebLibraries/three/addons/tsl/display/TransitionNode.js +141 -0
  323. package/Resources/WebLibraries/three/addons/tsl/display/boxBlur.js +65 -0
  324. package/Resources/WebLibraries/three/addons/tsl/display/depthAwareBlend.js +80 -0
  325. package/Resources/WebLibraries/three/addons/tsl/display/depthAwareBlur.js +63 -0
  326. package/Resources/WebLibraries/three/addons/tsl/display/hashBlur.js +55 -0
  327. package/Resources/WebLibraries/three/addons/tsl/display/lensDirt.js +30 -0
  328. package/Resources/WebLibraries/three/addons/tsl/display/radialBlur.js +68 -0
  329. package/Resources/WebLibraries/three/addons/tsl/lighting/ClusteredLightsNode.js +994 -0
  330. package/Resources/WebLibraries/three/addons/tsl/lighting/DynamicLightsNode.js +201 -0
  331. package/Resources/WebLibraries/three/addons/tsl/lighting/LightProbeGridNode.js +183 -0
  332. package/Resources/WebLibraries/three/addons/tsl/lighting/data/AmbientLightDataNode.js +67 -0
  333. package/Resources/WebLibraries/three/addons/tsl/lighting/data/DirectionalLightDataNode.js +117 -0
  334. package/Resources/WebLibraries/three/addons/tsl/lighting/data/HemisphereLightDataNode.js +105 -0
  335. package/Resources/WebLibraries/three/addons/tsl/lighting/data/PointLightDataNode.js +140 -0
  336. package/Resources/WebLibraries/three/addons/tsl/lighting/data/SpotLightDataNode.js +167 -0
  337. package/Resources/WebLibraries/three/addons/tsl/math/Bayer.js +84 -0
  338. package/Resources/WebLibraries/three/addons/tsl/math/curlNoise.js +107 -0
  339. package/Resources/WebLibraries/three/addons/tsl/math/voronoiNoise.js +112 -0
  340. package/Resources/WebLibraries/three/addons/tsl/shadows/TileShadowNode.js +542 -0
  341. package/Resources/WebLibraries/three/addons/tsl/shadows/TileShadowNodeHelper.js +212 -0
  342. package/Resources/WebLibraries/three/addons/tsl/utils/GroundedSkybox.js +62 -0
  343. package/Resources/WebLibraries/three/addons/tsl/utils/RNoise.js +51 -0
  344. package/Resources/WebLibraries/three/addons/tsl/utils/Raymarching.js +70 -0
  345. package/Resources/WebLibraries/three/addons/tsl/utils/SoftParticles.js +53 -0
  346. package/Resources/WebLibraries/three/addons/tsl/utils/SpecularHelpers.js +302 -0
  347. package/Resources/WebLibraries/three/addons/tsl/utils/TAAUtils.js +184 -0
  348. package/Resources/WebLibraries/three/addons/utils/BufferGeometryUtils.js +1523 -0
  349. package/Resources/WebLibraries/three/addons/utils/CameraUtils.js +82 -0
  350. package/Resources/WebLibraries/three/addons/utils/ColorUtils.js +76 -0
  351. package/Resources/WebLibraries/three/addons/utils/GaussianSplatUtils.js +229 -0
  352. package/Resources/WebLibraries/three/addons/utils/GeometryCompressionUtils.js +547 -0
  353. package/Resources/WebLibraries/three/addons/utils/GeometryUtils.js +226 -0
  354. package/Resources/WebLibraries/three/addons/utils/LDrawUtils.js +211 -0
  355. package/Resources/WebLibraries/three/addons/utils/SceneOptimizer.js +459 -0
  356. package/Resources/WebLibraries/three/addons/utils/SceneUtils.js +363 -0
  357. package/Resources/WebLibraries/three/addons/utils/ShadowMapViewer.js +244 -0
  358. package/Resources/WebLibraries/three/addons/utils/ShadowMapViewerGPU.js +233 -0
  359. package/Resources/WebLibraries/three/addons/utils/SkeletonUtils.js +496 -0
  360. package/Resources/WebLibraries/three/addons/utils/SortUtils.js +175 -0
  361. package/Resources/WebLibraries/three/addons/utils/UVsDebug.js +173 -0
  362. package/Resources/WebLibraries/three/addons/utils/WebGLTextureUtils.js +115 -0
  363. package/Resources/WebLibraries/three/addons/utils/WebGPUTextureUtils.js +81 -0
  364. package/Resources/WebLibraries/three/addons/utils/WorkerPool.js +167 -0
  365. package/Resources/WebLibraries/three/addons/utils/unwrapUVs.js +865 -0
  366. package/Resources/WebLibraries/three/three.core.js +61162 -0
  367. package/Resources/WebLibraries/three/three.module.js +19537 -0
  368. package/Resources/WebLibraries/three/three.tsl.js +41903 -0
  369. package/Resources/WebLibraries/three/three.webgpu.js +53714 -0
  370. package/Resources/share-rules.json +64 -0
  371. package/Resources/skills/2d-game/SKILL.md +305 -0
  372. package/Resources/skills/3d-game/SKILL.md +274 -0
  373. package/Resources/skills/accounts/SKILL.md +41 -0
  374. package/Resources/skills/android-design/SKILL.md +159 -0
  375. package/Resources/skills/app-ai/SKILL.md +154 -0
  376. package/Resources/skills/app-intents/SKILL.md +31 -0
  377. package/Resources/skills/app-kinds/SKILL.md +122 -0
  378. package/Resources/skills/apple-watch/SKILL.md +43 -0
  379. package/Resources/skills/assets/SKILL.md +183 -0
  380. package/Resources/skills/building-blocks/SKILL.md +97 -0
  381. package/Resources/skills/device-control/SKILL.md +56 -0
  382. package/Resources/skills/device-integrations/SKILL.md +278 -0
  383. package/Resources/skills/finder-files/SKILL.md +19 -0
  384. package/Resources/skills/game/SKILL.md +416 -0
  385. package/Resources/skills/game-3d/SKILL.md +12 -0
  386. package/Resources/skills/game-art/SKILL.md +11 -0
  387. package/Resources/skills/game-feel/SKILL.md +13 -0
  388. package/Resources/skills/game-levels/SKILL.md +12 -0
  389. package/Resources/skills/game-live/SKILL.md +12 -0
  390. package/Resources/skills/game-physics/SKILL.md +13 -0
  391. package/Resources/skills/game-playtest/SKILL.md +26 -0
  392. package/Resources/skills/game-ui/SKILL.md +278 -0
  393. package/Resources/skills/github-projects/SKILL.md +62 -0
  394. package/Resources/skills/icloud-sync/SKILL.md +30 -0
  395. package/Resources/skills/iphone-hardware/SKILL.md +57 -0
  396. package/Resources/skills/iphone-widgets/SKILL.md +53 -0
  397. package/Resources/skills/lg-developer-mode/SKILL.md +152 -0
  398. package/Resources/skills/mac-widgets/SKILL.md +60 -0
  399. package/Resources/skills/maps/SKILL.md +8 -0
  400. package/Resources/skills/menu-bar/SKILL.md +36 -0
  401. package/Resources/skills/more-apps/SKILL.md +53 -0
  402. package/Resources/skills/phone-controllers/SKILL.md +79 -0
  403. package/Resources/skills/phone-pages/SKILL.md +173 -0
  404. package/Resources/skills/roku-developer-mode/SKILL.md +106 -0
  405. package/Resources/skills/scene-3d/SKILL.md +27 -0
  406. package/Resources/skills/scripting/SKILL.md +17 -0
  407. package/Resources/skills/share-extension/SKILL.md +22 -0
  408. package/Resources/skills/tv-design/SKILL.md +72 -0
  409. package/Resources/skills/web-app/SKILL.md +170 -0
  410. package/Resources/skills/web-game/SKILL.md +95 -0
  411. package/Resources/skills/web-or-native/SKILL.md +108 -0
  412. package/Resources/skills/wish-links/SKILL.md +156 -0
  413. package/THIRD_PARTY_NOTICES.md +170 -0
  414. package/cli/ai.mjs +237 -0
  415. package/cli/android.mjs +941 -0
  416. package/cli/app-ai.mjs +473 -0
  417. package/cli/browser.mjs +284 -0
  418. package/cli/calls.mjs +594 -0
  419. package/cli/dev.mjs +820 -0
  420. package/cli/devices.mjs +984 -0
  421. package/cli/lamp.mjs +1326 -0
  422. package/cli/lampapp.mjs +332 -0
  423. package/cli/lamps/android-host/LampPageGateway.kt +345 -0
  424. package/cli/lamps/android-host/app/build.gradle.kts +40 -0
  425. package/cli/lamps/android-host/build.gradle.kts +4 -0
  426. package/cli/lamps/android-host/game/AndroidManifest.xml +33 -0
  427. package/cli/lamps/android-host/game/MainActivity.kt +173 -0
  428. package/cli/lamps/android-host/gradle/libs.versions.toml +39 -0
  429. package/cli/lamps/android-host/gradle.properties +8 -0
  430. package/cli/lamps/android-host/page/AndroidManifest.xml +35 -0
  431. package/cli/lamps/android-host/page/MainActivity.kt +193 -0
  432. package/cli/lamps/android-host/settings.gradle.kts +30 -0
  433. package/cli/lamps/android-host/tools.json +43 -0
  434. package/cli/lamps/lamp-controllers.js +2 -0
  435. package/cli/lamps/lamp-for-games.js +6922 -0
  436. package/cli/lamps/lamp.js +7082 -0
  437. package/cli/lamps/mac-starter/.lamp/meta.json +1 -0
  438. package/cli/lamps/mac-starter/APP.md +12 -0
  439. package/cli/lamps/mac-starter/Package.swift +8 -0
  440. package/cli/lamps/mac-starter/Sources/App.swift +11 -0
  441. package/cli/lamps/mac-starter/Sources/ContentView.swift +17 -0
  442. package/cli/lamps/mac-starter/Sources/LampSupport.swift +18215 -0
  443. package/cli/lamps/mac-starter/build.sh +336 -0
  444. package/cli/lamps/mac-starter/gitignore +3 -0
  445. package/cli/lamps/mac-starter/lamp-starter.json +6 -0
  446. package/cli/lamps/web-starter/APP.md +8 -0
  447. package/cli/lamps/web-starter/app.js +1 -0
  448. package/cli/lamps/web-starter/index.html +17 -0
  449. package/cli/lamps/web-starter/lamp-starter.json +5 -0
  450. package/cli/lamps/web-starter/lamp.js +7082 -0
  451. package/cli/lamps/web-starter/style.css +25 -0
  452. package/cli/link.mjs +202 -0
  453. package/cli/local-ai.mjs +193 -0
  454. package/cli/mac.mjs +621 -0
  455. package/cli/mdns.mjs +205 -0
  456. package/cli/msix.mjs +413 -0
  457. package/cli/network.mjs +209 -0
  458. package/cli/openrouter.mjs +133 -0
  459. package/cli/outside.mjs +203 -0
  460. package/cli/page.js +317 -0
  461. package/cli/place.mjs +298 -0
  462. package/cli/png.mjs +184 -0
  463. package/cli/share.mjs +270 -0
  464. package/cli/skill/SKILL.md +280 -0
  465. package/cli/skills.mjs +71 -0
  466. package/cli/state.mjs +176 -0
  467. package/cli/update.mjs +162 -0
  468. package/package.json +20 -4
  469. package/site/lib/quota.js +59 -0
  470. package/site/lib/shared-wishes.js +1727 -0
@@ -0,0 +1,2699 @@
1
+ /*!
2
+ fflate - fast JavaScript compression/decompression
3
+ <https://101arrowz.github.io/fflate>
4
+ Licensed under MIT. https://github.com/101arrowz/fflate/blob/master/LICENSE
5
+ version 0.8.3
6
+ */
7
+
8
+ // DEFLATE is a complex format; to read this code, you should probably check the RFC first:
9
+ // https://tools.ietf.org/html/rfc1951
10
+ // You may also wish to take a look at the guide I made about this program:
11
+ // https://gist.github.com/101arrowz/253f31eb5abc3d9275ab943003ffecad
12
+ // Some of the following code is similar to that of UZIP.js:
13
+ // https://github.com/photopea/UZIP.js
14
+ // However, the vast majority of the codebase has diverged from UZIP.js to increase performance and reduce bundle size.
15
+ // Sometimes 0 will appear where -1 would be more appropriate. This is because using a uint
16
+ // is better for memory in most engines (I *think*).
17
+ var ch2 = {};
18
+ var wk = (function (c, id, msg, transfer, cb) {
19
+ var w = new Worker(ch2[id] || (ch2[id] = URL.createObjectURL(new Blob([
20
+ c + ';addEventListener("error",function(e){e=e.error;postMessage({$e$:[e.message,e.code,e.stack]})})'
21
+ ], { type: 'text/javascript' }))));
22
+ w.onmessage = function (e) {
23
+ var d = e.data, ed = d.$e$;
24
+ if (ed) {
25
+ var err = new Error(ed[0]);
26
+ err['code'] = ed[1];
27
+ err.stack = ed[2];
28
+ cb(err, null);
29
+ }
30
+ else
31
+ cb(null, d);
32
+ };
33
+ w.postMessage(msg, transfer);
34
+ return w;
35
+ });
36
+
37
+ // aliases for shorter compressed code (most minifers don't do this)
38
+ var u8 = Uint8Array, u16 = Uint16Array, i32 = Int32Array;
39
+ // fixed length extra bits
40
+ var fleb = new u8([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, /* unused */ 0, 0, /* impossible */ 0]);
41
+ // fixed distance extra bits
42
+ var fdeb = new u8([0, 0, 0, 0, 1, 1, 2, 2, 3, 3, 4, 4, 5, 5, 6, 6, 7, 7, 8, 8, 9, 9, 10, 10, 11, 11, 12, 12, 13, 13, /* unused */ 0, 0]);
43
+ // code length index map
44
+ var clim = new u8([16, 17, 18, 0, 8, 7, 9, 6, 10, 5, 11, 4, 12, 3, 13, 2, 14, 1, 15]);
45
+ // get base, reverse index map from extra bits
46
+ var freb = function (eb, start) {
47
+ var b = new u16(31);
48
+ for (var i = 0; i < 31; ++i) {
49
+ b[i] = start += 1 << eb[i - 1];
50
+ }
51
+ // numbers here are at max 18 bits
52
+ var r = new i32(b[30]);
53
+ for (var i = 1; i < 30; ++i) {
54
+ for (var j = b[i]; j < b[i + 1]; ++j) {
55
+ r[j] = ((j - b[i]) << 5) | i;
56
+ }
57
+ }
58
+ return { b: b, r: r };
59
+ };
60
+ var _a = freb(fleb, 2), fl = _a.b, revfl = _a.r;
61
+ // we can ignore the fact that the other numbers are wrong; they never happen anyway
62
+ fl[28] = 258, revfl[258] = 28;
63
+ var _b = freb(fdeb, 0), fd = _b.b, revfd = _b.r;
64
+ // map of value to reverse (assuming 16 bits)
65
+ var rev = new u16(32768);
66
+ for (var i = 0; i < 32768; ++i) {
67
+ // reverse table algorithm from SO
68
+ var x = ((i & 0xAAAA) >> 1) | ((i & 0x5555) << 1);
69
+ x = ((x & 0xCCCC) >> 2) | ((x & 0x3333) << 2);
70
+ x = ((x & 0xF0F0) >> 4) | ((x & 0x0F0F) << 4);
71
+ rev[i] = (((x & 0xFF00) >> 8) | ((x & 0x00FF) << 8)) >> 1;
72
+ }
73
+ // create huffman tree from u8 "map": index -> code length for code index
74
+ // mb (max bits) must be at most 15
75
+ // TODO: optimize/split up?
76
+ var hMap = (function (cd, mb, r) {
77
+ var s = cd.length;
78
+ // index
79
+ var i = 0;
80
+ // u16 "map": index -> # of codes with bit length = index
81
+ var l = new u16(mb);
82
+ // length of cd must be 288 (total # of codes)
83
+ for (; i < s; ++i) {
84
+ if (cd[i])
85
+ ++l[cd[i] - 1];
86
+ }
87
+ // u16 "map": index -> minimum code for bit length = index
88
+ var le = new u16(mb);
89
+ for (i = 1; i < mb; ++i) {
90
+ le[i] = (le[i - 1] + l[i - 1]) << 1;
91
+ }
92
+ var co;
93
+ if (r) {
94
+ // u16 "map": index -> number of actual bits, symbol for code
95
+ co = new u16(1 << mb);
96
+ // bits to remove for reverser
97
+ var rvb = 15 - mb;
98
+ for (i = 0; i < s; ++i) {
99
+ // ignore 0 lengths
100
+ if (cd[i]) {
101
+ // num encoding both symbol and bits read
102
+ var sv = (i << 4) | cd[i];
103
+ // free bits
104
+ var r_1 = mb - cd[i];
105
+ // start value
106
+ var v = le[cd[i] - 1]++ << r_1;
107
+ // m is end value
108
+ for (var m = v | ((1 << r_1) - 1); v <= m; ++v) {
109
+ // every 16 bit value starting with the code yields the same result
110
+ co[rev[v] >> rvb] = sv;
111
+ }
112
+ }
113
+ }
114
+ }
115
+ else {
116
+ co = new u16(s);
117
+ for (i = 0; i < s; ++i) {
118
+ if (cd[i]) {
119
+ co[i] = rev[le[cd[i] - 1]++] >> (15 - cd[i]);
120
+ }
121
+ }
122
+ }
123
+ return co;
124
+ });
125
+ // fixed length tree
126
+ var flt = new u8(288);
127
+ for (var i = 0; i < 144; ++i)
128
+ flt[i] = 8;
129
+ for (var i = 144; i < 256; ++i)
130
+ flt[i] = 9;
131
+ for (var i = 256; i < 280; ++i)
132
+ flt[i] = 7;
133
+ for (var i = 280; i < 288; ++i)
134
+ flt[i] = 8;
135
+ // fixed distance tree
136
+ var fdt = new u8(32);
137
+ for (var i = 0; i < 32; ++i)
138
+ fdt[i] = 5;
139
+ // fixed length map
140
+ var flm = /*#__PURE__*/ hMap(flt, 9, 0), flrm = /*#__PURE__*/ hMap(flt, 9, 1);
141
+ // fixed distance map
142
+ var fdm = /*#__PURE__*/ hMap(fdt, 5, 0), fdrm = /*#__PURE__*/ hMap(fdt, 5, 1);
143
+ // find max of array
144
+ var max = function (a) {
145
+ var m = a[0];
146
+ for (var i = 1; i < a.length; ++i) {
147
+ if (a[i] > m)
148
+ m = a[i];
149
+ }
150
+ return m;
151
+ };
152
+ // read d, starting at bit p and mask with m
153
+ var bits = function (d, p, m) {
154
+ var o = (p / 8) | 0;
155
+ return ((d[o] | (d[o + 1] << 8)) >> (p & 7)) & m;
156
+ };
157
+ // read d, starting at bit p continuing for at least 16 bits
158
+ var bits16 = function (d, p) {
159
+ var o = (p / 8) | 0;
160
+ return ((d[o] | (d[o + 1] << 8) | (d[o + 2] << 16)) >> (p & 7));
161
+ };
162
+ // get end of byte
163
+ var shft = function (p) { return ((p + 7) / 8) | 0; };
164
+ // typed array slice - allows garbage collector to free original reference,
165
+ // while being more compatible than .slice
166
+ var slc = function (v, s, e) {
167
+ if (s == null || s < 0)
168
+ s = 0;
169
+ if (e == null || e > v.length)
170
+ e = v.length;
171
+ // can't use .constructor in case user-supplied
172
+ return new u8(v.subarray(s, e));
173
+ };
174
+ /**
175
+ * Codes for errors generated within this library
176
+ */
177
+ export var FlateErrorCode = {
178
+ UnexpectedEOF: 0,
179
+ InvalidBlockType: 1,
180
+ InvalidLengthLiteral: 2,
181
+ InvalidDistance: 3,
182
+ StreamFinished: 4,
183
+ NoStreamHandler: 5,
184
+ InvalidHeader: 6,
185
+ NoCallback: 7,
186
+ InvalidUTF8: 8,
187
+ ExtraFieldTooLong: 9,
188
+ InvalidDate: 10,
189
+ FilenameTooLong: 11,
190
+ StreamFinishing: 12,
191
+ InvalidZipData: 13,
192
+ UnknownCompressionMethod: 14
193
+ };
194
+ // error codes
195
+ var ec = [
196
+ 'unexpected EOF',
197
+ 'invalid block type',
198
+ 'invalid length/literal',
199
+ 'invalid distance',
200
+ 'stream finished',
201
+ 'no stream handler',
202
+ , // determined by compression function
203
+ 'no callback',
204
+ 'invalid UTF-8 data',
205
+ 'extra field too long',
206
+ 'date not in range 1980-2099',
207
+ 'filename too long',
208
+ 'stream finishing',
209
+ 'invalid zip data'
210
+ // determined by unknown compression method
211
+ ];
212
+ ;
213
+ var err = function (ind, msg, nt) {
214
+ var e = new Error(msg || ec[ind]);
215
+ e.code = ind;
216
+ if (Error.captureStackTrace)
217
+ Error.captureStackTrace(e, err);
218
+ if (!nt)
219
+ throw e;
220
+ return e;
221
+ };
222
+ // expands raw DEFLATE data
223
+ var inflt = function (dat, st, buf, dict) {
224
+ // source length dict length
225
+ var sl = dat.length, dl = dict ? dict.length : 0;
226
+ if (!sl || st.f && !st.l)
227
+ return buf || new u8(0);
228
+ var noBuf = !buf;
229
+ // have to estimate size
230
+ var resize = noBuf || st.i != 2;
231
+ // no state
232
+ var noSt = st.i;
233
+ // Assumes roughly 33% compression ratio average
234
+ if (noBuf)
235
+ buf = new u8(sl * 3);
236
+ // ensure buffer can fit at least l elements
237
+ var cbuf = function (l) {
238
+ var bl = buf.length;
239
+ // need to increase size to fit
240
+ if (l > bl) {
241
+ // Double or set to necessary, whichever is greater
242
+ var nbuf = new u8(Math.max(bl * 2, l));
243
+ nbuf.set(buf);
244
+ buf = nbuf;
245
+ }
246
+ };
247
+ // last chunk bitpos bytes
248
+ var final = st.f || 0, pos = st.p || 0, bt = st.b || 0, lm = st.l, dm = st.d, lbt = st.m, dbt = st.n;
249
+ // total bits
250
+ var tbts = sl * 8;
251
+ do {
252
+ if (!lm) {
253
+ // BFINAL - this is only 1 when last chunk is next
254
+ final = bits(dat, pos, 1);
255
+ // type: 0 = no compression, 1 = fixed huffman, 2 = dynamic huffman
256
+ var type = bits(dat, pos + 1, 3);
257
+ pos += 3;
258
+ if (!type) {
259
+ // go to end of byte boundary
260
+ var s = shft(pos) + 4, l = dat[s - 4] | (dat[s - 3] << 8), t = s + l;
261
+ if (t > sl) {
262
+ if (noSt)
263
+ err(0);
264
+ break;
265
+ }
266
+ // ensure size
267
+ if (resize)
268
+ cbuf(bt + l);
269
+ // Copy over uncompressed data
270
+ buf.set(dat.subarray(s, t), bt);
271
+ // Get new bitpos, update byte count
272
+ st.b = bt += l, st.p = pos = t * 8, st.f = final;
273
+ continue;
274
+ }
275
+ else if (type == 1)
276
+ lm = flrm, dm = fdrm, lbt = 9, dbt = 5;
277
+ else if (type == 2) {
278
+ // literal lengths
279
+ var hLit = bits(dat, pos, 31) + 257, hcLen = bits(dat, pos + 10, 15) + 4;
280
+ var tl = hLit + bits(dat, pos + 5, 31) + 1;
281
+ pos += 14;
282
+ // length+distance tree
283
+ var ldt = new u8(tl);
284
+ // code length tree
285
+ var clt = new u8(19);
286
+ for (var i = 0; i < hcLen; ++i) {
287
+ // use index map to get real code
288
+ clt[clim[i]] = bits(dat, pos + i * 3, 7);
289
+ }
290
+ pos += hcLen * 3;
291
+ // code lengths bits
292
+ var clb = max(clt), clbmsk = (1 << clb) - 1;
293
+ // code lengths map
294
+ var clm = hMap(clt, clb, 1);
295
+ for (var i = 0; i < tl;) {
296
+ var r = clm[bits(dat, pos, clbmsk)];
297
+ // bits read
298
+ pos += r & 15;
299
+ // symbol
300
+ var s = r >> 4;
301
+ // code length to copy
302
+ if (s < 16) {
303
+ ldt[i++] = s;
304
+ }
305
+ else {
306
+ // copy count
307
+ var c = 0, n = 0;
308
+ if (s == 16)
309
+ n = 3 + bits(dat, pos, 3), pos += 2, c = ldt[i - 1];
310
+ else if (s == 17)
311
+ n = 3 + bits(dat, pos, 7), pos += 3;
312
+ else if (s == 18)
313
+ n = 11 + bits(dat, pos, 127), pos += 7;
314
+ while (n--)
315
+ ldt[i++] = c;
316
+ }
317
+ }
318
+ // length tree distance tree
319
+ var lt = ldt.subarray(0, hLit), dt = ldt.subarray(hLit);
320
+ // max length bits
321
+ lbt = max(lt);
322
+ // max dist bits
323
+ dbt = max(dt);
324
+ lm = hMap(lt, lbt, 1);
325
+ dm = hMap(dt, dbt, 1);
326
+ }
327
+ else
328
+ err(1);
329
+ if (pos > tbts) {
330
+ if (noSt)
331
+ err(0);
332
+ break;
333
+ }
334
+ }
335
+ // Make sure the buffer can hold this + the largest possible addition
336
+ // Maximum chunk size (practically, theoretically infinite) is 2^17
337
+ if (resize)
338
+ cbuf(bt + 131072);
339
+ var lms = (1 << lbt) - 1, dms = (1 << dbt) - 1;
340
+ var lpos = pos;
341
+ for (;; lpos = pos) {
342
+ // bits read, code
343
+ var c = lm[bits16(dat, pos) & lms], sym = c >> 4;
344
+ pos += c & 15;
345
+ if (pos > tbts) {
346
+ if (noSt)
347
+ err(0);
348
+ break;
349
+ }
350
+ if (!c)
351
+ err(2);
352
+ if (sym < 256)
353
+ buf[bt++] = sym;
354
+ else if (sym == 256) {
355
+ lpos = pos, lm = null;
356
+ break;
357
+ }
358
+ else {
359
+ var add = sym - 254;
360
+ // no extra bits needed if less
361
+ if (sym > 264) {
362
+ // index
363
+ var i = sym - 257, b = fleb[i];
364
+ add = bits(dat, pos, (1 << b) - 1) + fl[i];
365
+ pos += b;
366
+ }
367
+ // dist
368
+ var d = dm[bits16(dat, pos) & dms], dsym = d >> 4;
369
+ if (!d)
370
+ err(3);
371
+ pos += d & 15;
372
+ var dt = fd[dsym];
373
+ if (dsym > 3) {
374
+ var b = fdeb[dsym];
375
+ dt += bits16(dat, pos) & (1 << b) - 1, pos += b;
376
+ }
377
+ if (pos > tbts) {
378
+ if (noSt)
379
+ err(0);
380
+ break;
381
+ }
382
+ if (resize)
383
+ cbuf(bt + 131072);
384
+ var end = bt + add;
385
+ if (bt < dt) {
386
+ var shift = dl - dt, dend = Math.min(dt, end);
387
+ if (shift + bt < 0)
388
+ err(3);
389
+ for (; bt < dend; ++bt)
390
+ buf[bt] = dict[shift + bt];
391
+ }
392
+ for (; bt < end; ++bt)
393
+ buf[bt] = buf[bt - dt];
394
+ }
395
+ }
396
+ st.l = lm, st.p = lpos, st.b = bt, st.f = final;
397
+ if (lm)
398
+ final = 1, st.m = lbt, st.d = dm, st.n = dbt;
399
+ } while (!final);
400
+ // don't reallocate for streams or user buffers
401
+ return bt != buf.length && noBuf ? slc(buf, 0, bt) : buf.subarray(0, bt);
402
+ };
403
+ // starting at p, write the minimum number of bits that can hold v to d
404
+ var wbits = function (d, p, v) {
405
+ v <<= p & 7;
406
+ var o = (p / 8) | 0;
407
+ d[o] |= v;
408
+ d[o + 1] |= v >> 8;
409
+ };
410
+ // starting at p, write the minimum number of bits (>8) that can hold v to d
411
+ var wbits16 = function (d, p, v) {
412
+ v <<= p & 7;
413
+ var o = (p / 8) | 0;
414
+ d[o] |= v;
415
+ d[o + 1] |= v >> 8;
416
+ d[o + 2] |= v >> 16;
417
+ };
418
+ // creates code lengths from a frequency table
419
+ var hTree = function (d, mb) {
420
+ // Need extra info to make a tree
421
+ var t = [];
422
+ for (var i = 0; i < d.length; ++i) {
423
+ if (d[i])
424
+ t.push({ s: i, f: d[i] });
425
+ }
426
+ var s = t.length;
427
+ var t2 = t.slice();
428
+ if (!s)
429
+ return { t: et, l: 0 };
430
+ if (s == 1) {
431
+ var v = new u8(t[0].s + 1);
432
+ v[t[0].s] = 1;
433
+ return { t: v, l: 1 };
434
+ }
435
+ t.sort(function (a, b) { return a.f - b.f; });
436
+ // after i2 reaches last ind, will be stopped
437
+ // freq must be greater than largest possible number of symbols
438
+ t.push({ s: -1, f: 25001 });
439
+ var l = t[0], r = t[1], i0 = 0, i1 = 1, i2 = 2;
440
+ t[0] = { s: -1, f: l.f + r.f, l: l, r: r };
441
+ // efficient algorithm from UZIP.js
442
+ // i0 is lookbehind, i2 is lookahead - after processing two low-freq
443
+ // symbols that combined have high freq, will start processing i2 (high-freq,
444
+ // non-composite) symbols instead
445
+ // see https://reddit.com/r/photopea/comments/ikekht/uzipjs_questions/
446
+ while (i1 != s - 1) {
447
+ l = t[t[i0].f < t[i2].f ? i0++ : i2++];
448
+ r = t[i0 != i1 && t[i0].f < t[i2].f ? i0++ : i2++];
449
+ t[i1++] = { s: -1, f: l.f + r.f, l: l, r: r };
450
+ }
451
+ var maxSym = t2[0].s;
452
+ for (var i = 1; i < s; ++i) {
453
+ if (t2[i].s > maxSym)
454
+ maxSym = t2[i].s;
455
+ }
456
+ // code lengths
457
+ var tr = new u16(maxSym + 1);
458
+ // max bits in tree
459
+ var mbt = ln(t[i1 - 1], tr, 0);
460
+ if (mbt > mb) {
461
+ // more algorithms from UZIP.js
462
+ // TODO: find out how this code works (debt)
463
+ // ind debt
464
+ var i = 0, dt = 0;
465
+ // left cost
466
+ var lft = mbt - mb, cst = 1 << lft;
467
+ t2.sort(function (a, b) { return tr[b.s] - tr[a.s] || a.f - b.f; });
468
+ for (; i < s; ++i) {
469
+ var i2_1 = t2[i].s;
470
+ if (tr[i2_1] > mb) {
471
+ dt += cst - (1 << (mbt - tr[i2_1]));
472
+ tr[i2_1] = mb;
473
+ }
474
+ else
475
+ break;
476
+ }
477
+ dt >>= lft;
478
+ while (dt > 0) {
479
+ var i2_2 = t2[i].s;
480
+ if (tr[i2_2] < mb)
481
+ dt -= 1 << (mb - tr[i2_2]++ - 1);
482
+ else
483
+ ++i;
484
+ }
485
+ for (; i >= 0 && dt; --i) {
486
+ var i2_3 = t2[i].s;
487
+ if (tr[i2_3] == mb) {
488
+ --tr[i2_3];
489
+ ++dt;
490
+ }
491
+ }
492
+ mbt = mb;
493
+ }
494
+ return { t: new u8(tr), l: mbt };
495
+ };
496
+ // get the max length and assign length codes
497
+ var ln = function (n, l, d) {
498
+ return n.s == -1
499
+ ? Math.max(ln(n.l, l, d + 1), ln(n.r, l, d + 1))
500
+ : (l[n.s] = d);
501
+ };
502
+ // length codes generation
503
+ var lc = function (c) {
504
+ var s = c.length;
505
+ // Note that the semicolon was intentional
506
+ while (s && !c[--s])
507
+ ;
508
+ var cl = new u16(++s);
509
+ // ind num streak
510
+ var cli = 0, cln = c[0], cls = 1;
511
+ var w = function (v) { cl[cli++] = v; };
512
+ for (var i = 1; i <= s; ++i) {
513
+ if (c[i] == cln && i != s)
514
+ ++cls;
515
+ else {
516
+ if (!cln && cls > 2) {
517
+ for (; cls > 138; cls -= 138)
518
+ w(32754);
519
+ if (cls > 2) {
520
+ w(cls > 10 ? ((cls - 11) << 5) | 28690 : ((cls - 3) << 5) | 12305);
521
+ cls = 0;
522
+ }
523
+ }
524
+ else if (cls > 3) {
525
+ w(cln), --cls;
526
+ for (; cls > 6; cls -= 6)
527
+ w(8304);
528
+ if (cls > 2)
529
+ w(((cls - 3) << 5) | 8208), cls = 0;
530
+ }
531
+ while (cls--)
532
+ w(cln);
533
+ cls = 1;
534
+ cln = c[i];
535
+ }
536
+ }
537
+ return { c: cl.subarray(0, cli), n: s };
538
+ };
539
+ // calculate the length of output from tree, code lengths
540
+ var clen = function (cf, cl) {
541
+ var l = 0;
542
+ for (var i = 0; i < cl.length; ++i)
543
+ l += cf[i] * cl[i];
544
+ return l;
545
+ };
546
+ // writes a fixed block
547
+ // returns the new bit pos
548
+ var wfblk = function (out, pos, dat) {
549
+ // no need to write 00 as type: TypedArray defaults to 0
550
+ var s = dat.length;
551
+ var o = shft(pos + 2);
552
+ out[o] = s & 255;
553
+ out[o + 1] = s >> 8;
554
+ out[o + 2] = out[o] ^ 255;
555
+ out[o + 3] = out[o + 1] ^ 255;
556
+ for (var i = 0; i < s; ++i)
557
+ out[o + i + 4] = dat[i];
558
+ return (o + 4 + s) * 8;
559
+ };
560
+ // writes a block
561
+ var wblk = function (dat, out, final, syms, lf, df, eb, li, bs, bl, p) {
562
+ wbits(out, p++, final);
563
+ ++lf[256];
564
+ var _a = hTree(lf, 15), dlt = _a.t, mlb = _a.l;
565
+ var _b = hTree(df, 15), ddt = _b.t, mdb = _b.l;
566
+ var _c = lc(dlt), lclt = _c.c, nlc = _c.n;
567
+ var _d = lc(ddt), lcdt = _d.c, ndc = _d.n;
568
+ var lcfreq = new u16(19);
569
+ for (var i = 0; i < lclt.length; ++i)
570
+ ++lcfreq[lclt[i] & 31];
571
+ for (var i = 0; i < lcdt.length; ++i)
572
+ ++lcfreq[lcdt[i] & 31];
573
+ var _e = hTree(lcfreq, 7), lct = _e.t, mlcb = _e.l;
574
+ var nlcc = 19;
575
+ for (; nlcc > 4 && !lct[clim[nlcc - 1]]; --nlcc)
576
+ ;
577
+ var flen = (bl + 5) << 3;
578
+ var ftlen = clen(lf, flt) + clen(df, fdt) + eb;
579
+ var dtlen = clen(lf, dlt) + clen(df, ddt) + eb + 14 + 3 * nlcc + clen(lcfreq, lct) + 2 * lcfreq[16] + 3 * lcfreq[17] + 7 * lcfreq[18];
580
+ if (bs >= 0 && flen <= ftlen && flen <= dtlen)
581
+ return wfblk(out, p, dat.subarray(bs, bs + bl));
582
+ var lm, ll, dm, dl;
583
+ wbits(out, p, 1 + (dtlen < ftlen)), p += 2;
584
+ if (dtlen < ftlen) {
585
+ lm = hMap(dlt, mlb, 0), ll = dlt, dm = hMap(ddt, mdb, 0), dl = ddt;
586
+ var llm = hMap(lct, mlcb, 0);
587
+ wbits(out, p, nlc - 257);
588
+ wbits(out, p + 5, ndc - 1);
589
+ wbits(out, p + 10, nlcc - 4);
590
+ p += 14;
591
+ for (var i = 0; i < nlcc; ++i)
592
+ wbits(out, p + 3 * i, lct[clim[i]]);
593
+ p += 3 * nlcc;
594
+ var lcts = [lclt, lcdt];
595
+ for (var it = 0; it < 2; ++it) {
596
+ var clct = lcts[it];
597
+ for (var i = 0; i < clct.length; ++i) {
598
+ var len = clct[i] & 31;
599
+ wbits(out, p, llm[len]), p += lct[len];
600
+ if (len > 15)
601
+ wbits(out, p, (clct[i] >> 5) & 127), p += clct[i] >> 12;
602
+ }
603
+ }
604
+ }
605
+ else {
606
+ lm = flm, ll = flt, dm = fdm, dl = fdt;
607
+ }
608
+ for (var i = 0; i < li; ++i) {
609
+ var sym = syms[i];
610
+ if (sym > 255) {
611
+ var len = (sym >> 18) & 31;
612
+ wbits16(out, p, lm[len + 257]), p += ll[len + 257];
613
+ if (len > 7)
614
+ wbits(out, p, (sym >> 23) & 31), p += fleb[len];
615
+ var dst = sym & 31;
616
+ wbits16(out, p, dm[dst]), p += dl[dst];
617
+ if (dst > 3)
618
+ wbits16(out, p, (sym >> 5) & 8191), p += fdeb[dst];
619
+ }
620
+ else {
621
+ wbits16(out, p, lm[sym]), p += ll[sym];
622
+ }
623
+ }
624
+ wbits16(out, p, lm[256]);
625
+ return p + ll[256];
626
+ };
627
+ // deflate options (nice << 13) | chain
628
+ var deo = /*#__PURE__*/ new i32([65540, 131080, 131088, 131104, 262176, 1048704, 1048832, 2114560, 2117632]);
629
+ // empty
630
+ var et = /*#__PURE__*/ new u8(0);
631
+ // compresses data into a raw DEFLATE buffer
632
+ var dflt = function (dat, lvl, plvl, pre, post, st) {
633
+ var s = st.z || dat.length;
634
+ var o = new u8(pre + s + 5 * (1 + Math.ceil(s / 7000)) + post);
635
+ // writing to this writes to the output buffer
636
+ var w = o.subarray(pre, o.length - post);
637
+ var lst = st.l;
638
+ var pos = (st.r || 0) & 7;
639
+ if (lvl) {
640
+ if (pos)
641
+ w[0] = st.r >> 3;
642
+ var opt = deo[lvl - 1];
643
+ var n = opt >> 13, c = opt & 8191;
644
+ var msk_1 = (1 << plvl) - 1;
645
+ // prev 2-byte val map curr 2-byte val map
646
+ var prev = st.p || new u16(32768), head = st.h || new u16(msk_1 + 1);
647
+ var bs1_1 = Math.ceil(plvl / 3), bs2_1 = 2 * bs1_1;
648
+ var hsh = function (i) { return (dat[i] ^ (dat[i + 1] << bs1_1) ^ (dat[i + 2] << bs2_1)) & msk_1; };
649
+ // 24576 is an arbitrary number of maximum symbols per block
650
+ // 424 buffer for last block
651
+ var syms = new i32(25000);
652
+ // length/literal freq distance freq
653
+ var lf = new u16(288), df = new u16(32);
654
+ // l/lcnt exbits index l/lind waitdx blkpos
655
+ var lc_1 = 0, eb = 0, i = st.i || 0, li = 0, wi = st.w || 0, bs = 0;
656
+ for (; i + 2 < s; ++i) {
657
+ // hash value
658
+ var hv = hsh(i);
659
+ // index mod 32768 previous index mod
660
+ var imod = i & 32767, pimod = head[hv];
661
+ prev[imod] = pimod;
662
+ head[hv] = imod;
663
+ // We always should modify head and prev, but only add symbols if
664
+ // this data is not yet processed ("wait" for wait index)
665
+ if (wi <= i) {
666
+ // bytes remaining
667
+ var rem = s - i;
668
+ if ((lc_1 > 7000 || li > 24576) && (rem > 423 || !lst)) {
669
+ pos = wblk(dat, w, 0, syms, lf, df, eb, li, bs, i - bs, pos);
670
+ li = lc_1 = eb = 0, bs = i;
671
+ for (var j = 0; j < 286; ++j)
672
+ lf[j] = 0;
673
+ for (var j = 0; j < 30; ++j)
674
+ df[j] = 0;
675
+ }
676
+ // len dist chain
677
+ var l = 2, d = 0, ch_1 = c, dif = imod - pimod & 32767;
678
+ if (rem > 2 && hv == hsh(i - dif)) {
679
+ var maxn = Math.min(n, rem) - 1;
680
+ var maxd = Math.min(32767, i);
681
+ // max possible length
682
+ // not capped at dif because decompressors implement "rolling" index population
683
+ var ml = Math.min(258, rem);
684
+ while (dif <= maxd && --ch_1 && imod != pimod) {
685
+ if (dat[i + l] == dat[i + l - dif]) {
686
+ var nl = 0;
687
+ for (; nl < ml && dat[i + nl] == dat[i + nl - dif]; ++nl)
688
+ ;
689
+ if (nl > l) {
690
+ l = nl, d = dif;
691
+ // break out early when we reach "nice" (we are satisfied enough)
692
+ if (nl > maxn)
693
+ break;
694
+ // now, find the rarest 2-byte sequence within this
695
+ // length of literals and search for that instead.
696
+ // Much faster than just using the start
697
+ var mmd = Math.min(dif, nl - 2);
698
+ var md = 0;
699
+ for (var j = 0; j < mmd; ++j) {
700
+ var ti = i - dif + j & 32767;
701
+ var pti = prev[ti];
702
+ var cd = ti - pti & 32767;
703
+ if (cd > md)
704
+ md = cd, pimod = ti;
705
+ }
706
+ }
707
+ }
708
+ // check the previous match
709
+ imod = pimod, pimod = prev[imod];
710
+ dif += imod - pimod & 32767;
711
+ }
712
+ }
713
+ // d will be nonzero only when a match was found
714
+ if (d) {
715
+ // store both dist and len data in one int32
716
+ // Make sure this is recognized as a len/dist with 28th bit (2^28)
717
+ syms[li++] = 268435456 | (revfl[l] << 18) | revfd[d];
718
+ var lin = revfl[l] & 31, din = revfd[d] & 31;
719
+ eb += fleb[lin] + fdeb[din];
720
+ ++lf[257 + lin];
721
+ ++df[din];
722
+ wi = i + l;
723
+ ++lc_1;
724
+ }
725
+ else {
726
+ syms[li++] = dat[i];
727
+ ++lf[dat[i]];
728
+ }
729
+ }
730
+ }
731
+ for (i = Math.max(i, wi); i < s; ++i) {
732
+ syms[li++] = dat[i];
733
+ ++lf[dat[i]];
734
+ }
735
+ pos = wblk(dat, w, lst, syms, lf, df, eb, li, bs, i - bs, pos);
736
+ if (!lst) {
737
+ st.r = (pos & 7) | w[(pos / 8) | 0] << 3;
738
+ // shft(pos) now 1 less if pos & 7 != 0
739
+ pos -= 7;
740
+ st.h = head, st.p = prev, st.i = i, st.w = wi;
741
+ }
742
+ }
743
+ else {
744
+ for (var i = st.w || 0; i < s + lst; i += 65535) {
745
+ // end
746
+ var e = i + 65535;
747
+ if (e >= s) {
748
+ // write final block
749
+ w[(pos / 8) | 0] = lst;
750
+ e = s;
751
+ }
752
+ pos = wfblk(w, pos + 1, dat.subarray(i, e));
753
+ }
754
+ st.i = s;
755
+ }
756
+ return slc(o, 0, pre + shft(pos) + post);
757
+ };
758
+ // CRC32 table
759
+ var crct = /*#__PURE__*/ (function () {
760
+ var t = new Int32Array(256);
761
+ for (var i = 0; i < 256; ++i) {
762
+ var c = i, k = 9;
763
+ while (--k)
764
+ c = ((c & 1) && -306674912) ^ (c >>> 1);
765
+ t[i] = c;
766
+ }
767
+ return t;
768
+ })();
769
+ // CRC32
770
+ var crc = function () {
771
+ var c = -1;
772
+ return {
773
+ p: function (d) {
774
+ // closures have awful performance
775
+ var cr = c;
776
+ for (var i = 0; i < d.length; ++i)
777
+ cr = crct[(cr & 255) ^ d[i]] ^ (cr >>> 8);
778
+ c = cr;
779
+ },
780
+ d: function () { return ~c; }
781
+ };
782
+ };
783
+ // Adler32
784
+ var adler = function () {
785
+ var a = 1, b = 0;
786
+ return {
787
+ p: function (d) {
788
+ // closures have awful performance
789
+ var n = a, m = b;
790
+ var l = d.length | 0;
791
+ for (var i = 0; i != l;) {
792
+ var e = Math.min(i + 2655, l);
793
+ for (; i < e; ++i)
794
+ m += n += d[i];
795
+ n = (n & 65535) + 15 * (n >> 16), m = (m & 65535) + 15 * (m >> 16);
796
+ }
797
+ a = n, b = m;
798
+ },
799
+ d: function () {
800
+ a %= 65521, b %= 65521;
801
+ return (a & 255) << 24 | (a & 0xFF00) << 8 | (b & 255) << 8 | (b >> 8);
802
+ }
803
+ };
804
+ };
805
+ ;
806
+ // deflate with opts
807
+ var dopt = function (dat, opt, pre, post, st) {
808
+ if (!st) {
809
+ st = { l: 1 };
810
+ if (opt.dictionary) {
811
+ var dict = opt.dictionary.subarray(-32768);
812
+ var newDat = new u8(dict.length + dat.length);
813
+ newDat.set(dict);
814
+ newDat.set(dat, dict.length);
815
+ dat = newDat;
816
+ st.w = dict.length;
817
+ }
818
+ }
819
+ return dflt(dat, opt.level == null ? 6 : opt.level, opt.mem == null ? (st.l ? Math.ceil(Math.max(8, Math.min(13, Math.log(dat.length))) * 1.5) : 20) : (12 + opt.mem), pre, post, st);
820
+ };
821
+ // Walmart object spread
822
+ var mrg = function (a, b) {
823
+ var o = {};
824
+ for (var k in a)
825
+ o[k] = a[k];
826
+ for (var k in b)
827
+ o[k] = b[k];
828
+ return o;
829
+ };
830
+ // worker clone
831
+ // This is possibly the craziest part of the entire codebase, despite how simple it may seem.
832
+ // The only parameter to this function is a closure that returns an array of variables outside of the function scope.
833
+ // We're going to try to figure out the variable names used in the closure as strings because that is crucial for workerization.
834
+ // We will return an object mapping of true variable name to value (basically, the current scope as a JS object).
835
+ // The reason we can't just use the original variable names is minifiers mangling the toplevel scope.
836
+ // This took me three weeks to figure out how to do.
837
+ var wcln = function (fn, fnStr, td) {
838
+ var dt = fn();
839
+ var st = fn.toString();
840
+ var ks = st.slice(st.indexOf('[') + 1, st.lastIndexOf(']')).replace(/\s+/g, '').split(',');
841
+ for (var i = 0; i < dt.length; ++i) {
842
+ var v = dt[i], k = ks[i];
843
+ if (typeof v == 'function') {
844
+ fnStr += ';' + k + '=';
845
+ var st_1 = v.toString();
846
+ if (v.prototype) {
847
+ // for global objects
848
+ if (st_1.indexOf('[native code]') != -1) {
849
+ var spInd = st_1.indexOf(' ', 8) + 1;
850
+ fnStr += st_1.slice(spInd, st_1.indexOf('(', spInd));
851
+ }
852
+ else {
853
+ fnStr += st_1;
854
+ for (var t in v.prototype)
855
+ fnStr += ';' + k + '.prototype.' + t + '=' + v.prototype[t].toString();
856
+ }
857
+ }
858
+ else
859
+ fnStr += st_1;
860
+ }
861
+ else
862
+ td[k] = v;
863
+ }
864
+ return fnStr;
865
+ };
866
+ var ch = [];
867
+ // clone bufs
868
+ var cbfs = function (v) {
869
+ var tl = [];
870
+ for (var k in v) {
871
+ if (v[k].buffer) {
872
+ tl.push((v[k] = new v[k].constructor(v[k])).buffer);
873
+ }
874
+ }
875
+ return tl;
876
+ };
877
+ // use a worker to execute code
878
+ var wrkr = function (fns, init, id, cb) {
879
+ if (!ch[id]) {
880
+ var fnStr = '', td_1 = {}, m = fns.length - 1;
881
+ for (var i = 0; i < m; ++i)
882
+ fnStr = wcln(fns[i], fnStr, td_1);
883
+ ch[id] = { c: wcln(fns[m], fnStr, td_1), e: td_1 };
884
+ }
885
+ var td = mrg({}, ch[id].e);
886
+ return wk(ch[id].c + ';onmessage=function(e){for(var k in e.data)self[k]=e.data[k];onmessage=' + init.toString() + '}', id, td, cbfs(td), cb);
887
+ };
888
+ // base async inflate fn
889
+ var bInflt = function () { return [u8, u16, i32, fleb, fdeb, clim, fl, fd, flrm, fdrm, rev, ec, hMap, max, bits, bits16, shft, slc, err, inflt, inflateSync, pbf, gopt]; };
890
+ var bDflt = function () { return [u8, u16, i32, fleb, fdeb, clim, revfl, revfd, flm, flt, fdm, fdt, rev, deo, et, hMap, wbits, wbits16, hTree, ln, lc, clen, wfblk, wblk, shft, slc, dflt, dopt, deflateSync, pbf]; };
891
+ // gzip extra
892
+ var gze = function () { return [gzh, gzhl, wbytes, crc, crct]; };
893
+ // gunzip extra
894
+ var guze = function () { return [gzs, gzl]; };
895
+ // zlib extra
896
+ var zle = function () { return [zlh, wbytes, adler]; };
897
+ // unzlib extra
898
+ var zule = function () { return [zls]; };
899
+ // post buf
900
+ var pbf = function (msg) { return postMessage(msg, [msg.buffer]); };
901
+ // get opts
902
+ var gopt = function (o) { return o && {
903
+ out: o.size && new u8(o.size),
904
+ dictionary: o.dictionary
905
+ }; };
906
+ // async helper
907
+ var cbify = function (dat, opts, fns, init, id, cb) {
908
+ var w = wrkr(fns, init, id, function (err, dat) {
909
+ w.terminate();
910
+ cb(err, dat);
911
+ });
912
+ w.postMessage([dat, opts], opts.consume ? [dat.buffer] : []);
913
+ return function () { w.terminate(); };
914
+ };
915
+ // auto stream
916
+ var astrm = function (strm) {
917
+ strm.ondata = function (dat, final) { return postMessage([dat, final], [dat.buffer]); };
918
+ return function (ev) {
919
+ if (ev.data[0]) {
920
+ strm.push(ev.data[0], ev.data[1]);
921
+ postMessage([ev.data[0].length]);
922
+ }
923
+ else
924
+ strm.flush(ev.data[1]);
925
+ };
926
+ };
927
+ // async stream attach
928
+ var astrmify = function (fns, strm, opts, init, id, flush, ext) {
929
+ var t;
930
+ var w = wrkr(fns, init, id, function (err, dat) {
931
+ if (err)
932
+ w.terminate(), strm.ondata.call(strm, err);
933
+ else if (!Array.isArray(dat))
934
+ ext(dat);
935
+ else if (dat.length == 1) {
936
+ strm.queuedSize -= dat[0];
937
+ if (strm.ondrain)
938
+ strm.ondrain(dat[0]);
939
+ }
940
+ else {
941
+ if (dat[1])
942
+ w.terminate();
943
+ strm.ondata.call(strm, err, dat[0], dat[1]);
944
+ }
945
+ });
946
+ w.postMessage(opts);
947
+ strm.queuedSize = 0;
948
+ strm.push = function (d, f) {
949
+ if (!strm.ondata)
950
+ err(5);
951
+ if (t)
952
+ strm.ondata(err(4, 0, 1), null, !!f);
953
+ strm.queuedSize += d.length;
954
+ // can fail for cross-realm Uint8Array, but ok - only a small performance penalty
955
+ w.postMessage([d, t = f], d.buffer instanceof ArrayBuffer ? [d.buffer] : []);
956
+ };
957
+ strm.terminate = function () { w.terminate(); };
958
+ if (flush) {
959
+ strm.flush = function (sync) { w.postMessage([0, sync]); };
960
+ }
961
+ };
962
+ // read 2 bytes
963
+ var b2 = function (d, b) { return d[b] | (d[b + 1] << 8); };
964
+ // read 4 bytes
965
+ var b4 = function (d, b) { return (d[b] | (d[b + 1] << 8) | (d[b + 2] << 16) | (d[b + 3] << 24)) >>> 0; };
966
+ // read 8 bytes
967
+ var b8 = function (d, b) { return b4(d, b) + (b4(d, b + 4) * 4294967296); };
968
+ // write bytes
969
+ var wbytes = function (d, b, v) {
970
+ for (; v; ++b)
971
+ d[b] = v, v >>>= 8;
972
+ };
973
+ // gzip header
974
+ var gzh = function (c, o) {
975
+ var fn = o.filename;
976
+ c[0] = 31, c[1] = 139, c[2] = 8, c[8] = o.level < 2 ? 4 : o.level == 9 ? 2 : 0, c[9] = 3; // assume Unix
977
+ if (o.mtime != 0)
978
+ wbytes(c, 4, Math.floor(new Date(o.mtime || Date.now()) / 1000));
979
+ if (fn) {
980
+ c[3] = 8;
981
+ for (var i = 0; i <= fn.length; ++i)
982
+ c[i + 10] = fn.charCodeAt(i);
983
+ }
984
+ };
985
+ // gzip footer: -8 to -4 = CRC, -4 to -0 is length
986
+ // gzip start
987
+ var gzs = function (d) {
988
+ if (d[0] != 31 || d[1] != 139 || d[2] != 8)
989
+ err(6, 'invalid gzip data');
990
+ var flg = d[3];
991
+ var st = 10;
992
+ if (flg & 4)
993
+ st += (d[10] | d[11] << 8) + 2;
994
+ for (var zs = (flg >> 3 & 1) + (flg >> 4 & 1); zs > 0; zs -= !d[st++])
995
+ ;
996
+ return st + (flg & 2);
997
+ };
998
+ // gzip length
999
+ var gzl = function (d) {
1000
+ var l = d.length;
1001
+ return (d[l - 4] | d[l - 3] << 8 | d[l - 2] << 16 | d[l - 1] << 24) >>> 0;
1002
+ };
1003
+ // gzip header length
1004
+ var gzhl = function (o) { return 10 + (o.filename ? o.filename.length + 1 : 0); };
1005
+ // zlib header
1006
+ var zlh = function (c, o) {
1007
+ var lv = o.level, fl = lv == 0 ? 0 : lv < 6 ? 1 : lv == 9 ? 3 : 2;
1008
+ c[0] = 120, c[1] = (fl << 6) | (o.dictionary && 32);
1009
+ c[1] |= 31 - ((c[0] << 8) | c[1]) % 31;
1010
+ if (o.dictionary) {
1011
+ var h = adler();
1012
+ h.p(o.dictionary);
1013
+ wbytes(c, 2, h.d());
1014
+ }
1015
+ };
1016
+ // zlib start
1017
+ var zls = function (d, dict) {
1018
+ if ((d[0] & 15) != 8 || (d[0] >> 4) > 7 || ((d[0] << 8 | d[1]) % 31))
1019
+ err(6, 'invalid zlib data');
1020
+ if ((d[1] >> 5 & 1) == +!dict)
1021
+ err(6, 'invalid zlib data: ' + (d[1] & 32 ? 'need' : 'unexpected') + ' dictionary');
1022
+ return (d[1] >> 3 & 4) + 2;
1023
+ };
1024
+ function StrmOpt(opts, cb) {
1025
+ if (typeof opts == 'function')
1026
+ cb = opts, opts = {};
1027
+ this.ondata = cb;
1028
+ return opts;
1029
+ }
1030
+ /**
1031
+ * Streaming DEFLATE compression
1032
+ */
1033
+ var Deflate = /*#__PURE__*/ (function () {
1034
+ function Deflate(opts, cb) {
1035
+ if (typeof opts == 'function')
1036
+ cb = opts, opts = {};
1037
+ this.ondata = cb;
1038
+ this.o = opts || {};
1039
+ this.s = { l: 0, i: 32768, w: 32768, z: 32768 };
1040
+ // Buffer length must always be 0 mod 32768 for index calculations to be correct when modifying head and prev
1041
+ // 98304 = 32768 (lookback) + 65536 (common chunk size)
1042
+ this.b = new u8(98304);
1043
+ if (this.o.dictionary) {
1044
+ var dict = this.o.dictionary.subarray(-32768);
1045
+ this.b.set(dict, 32768 - dict.length);
1046
+ this.s.i = 32768 - dict.length;
1047
+ }
1048
+ }
1049
+ Deflate.prototype.p = function (c, f) {
1050
+ this.ondata(dopt(c, this.o, 0, 0, this.s), f);
1051
+ };
1052
+ /**
1053
+ * Pushes a chunk to be deflated
1054
+ * @param chunk The chunk to push
1055
+ * @param final Whether this is the last chunk
1056
+ */
1057
+ Deflate.prototype.push = function (chunk, final) {
1058
+ if (!this.ondata)
1059
+ err(5);
1060
+ if (this.s.l)
1061
+ err(4);
1062
+ var endLen = chunk.length + this.s.z;
1063
+ if (endLen > this.b.length) {
1064
+ if (endLen > 2 * this.b.length - 32768) {
1065
+ var newBuf = new u8(endLen & -32768);
1066
+ newBuf.set(this.b.subarray(0, this.s.z));
1067
+ this.b = newBuf;
1068
+ }
1069
+ var split = this.b.length - this.s.z;
1070
+ this.b.set(chunk.subarray(0, split), this.s.z);
1071
+ this.s.z = this.b.length;
1072
+ this.p(this.b, false);
1073
+ this.b.set(this.b.subarray(-32768));
1074
+ this.b.set(chunk.subarray(split), 32768);
1075
+ this.s.z = chunk.length - split + 32768;
1076
+ this.s.i = 32766, this.s.w = 32768;
1077
+ }
1078
+ else {
1079
+ this.b.set(chunk, this.s.z);
1080
+ this.s.z += chunk.length;
1081
+ }
1082
+ this.s.l = final & 1;
1083
+ if (this.s.z > this.s.w + 8191 || final) {
1084
+ this.p(this.b, final || false);
1085
+ this.s.w = this.s.i, this.s.i -= 2;
1086
+ }
1087
+ if (final) {
1088
+ // cleanup unneeded buffers/state to reduce memory usage
1089
+ this.s = this.o = {};
1090
+ this.b = et;
1091
+ }
1092
+ };
1093
+ /**
1094
+ * Flushes buffered uncompressed data. Useful to immediately retrieve the
1095
+ * deflated output for small inputs.
1096
+ * @param sync Whether to flush to a byte boundary. A sync flush takes 4-5
1097
+ * extra bytes, but guarantees all pushed data is immediately
1098
+ * decompressible. A separate DEFLATE stream may be concatenated
1099
+ * with the current output after a sync flush.
1100
+ */
1101
+ Deflate.prototype.flush = function (sync) {
1102
+ if (!this.ondata)
1103
+ err(5);
1104
+ if (this.s.l)
1105
+ err(4);
1106
+ this.p(this.b, false);
1107
+ this.s.w = this.s.i, this.s.i -= 2;
1108
+ // could technically skip writing the type-0 block for (this.s.r & 7) == 0,
1109
+ // but the deterministic trailer (00 00 FF FF) is useful in some situations
1110
+ if (sync) {
1111
+ var c = new u8(6);
1112
+ c[0] = this.s.r >> 3;
1113
+ // write empty, non-final type-0 block
1114
+ var ep = wfblk(c, this.s.r, et);
1115
+ this.s.r = 0;
1116
+ this.ondata(c.subarray(0, ep >> 3), false);
1117
+ }
1118
+ };
1119
+ return Deflate;
1120
+ }());
1121
+ export { Deflate };
1122
+ /**
1123
+ * Asynchronous streaming DEFLATE compression
1124
+ */
1125
+ var AsyncDeflate = /*#__PURE__*/ (function () {
1126
+ function AsyncDeflate(opts, cb) {
1127
+ astrmify([
1128
+ bDflt,
1129
+ function () { return [astrm, Deflate]; }
1130
+ ], this, StrmOpt.call(this, opts, cb), function (ev) {
1131
+ var strm = new Deflate(ev.data);
1132
+ onmessage = astrm(strm);
1133
+ }, 6, 1);
1134
+ }
1135
+ return AsyncDeflate;
1136
+ }());
1137
+ export { AsyncDeflate };
1138
+ export function deflate(data, opts, cb) {
1139
+ if (!cb)
1140
+ cb = opts, opts = {};
1141
+ if (typeof cb != 'function')
1142
+ err(7);
1143
+ return cbify(data, opts, [
1144
+ bDflt,
1145
+ ], function (ev) { return pbf(deflateSync(ev.data[0], ev.data[1])); }, 0, cb);
1146
+ }
1147
+ /**
1148
+ * Compresses data with DEFLATE without any wrapper
1149
+ * @param data The data to compress
1150
+ * @param opts The compression options
1151
+ * @returns The deflated version of the data
1152
+ */
1153
+ export function deflateSync(data, opts) {
1154
+ return dopt(data, opts || {}, 0, 0);
1155
+ }
1156
+ /**
1157
+ * Streaming DEFLATE decompression
1158
+ */
1159
+ var Inflate = /*#__PURE__*/ (function () {
1160
+ function Inflate(opts, cb) {
1161
+ // no StrmOpt here to avoid adding to workerizer
1162
+ if (typeof opts == 'function')
1163
+ cb = opts, opts = {};
1164
+ this.ondata = cb;
1165
+ var dict = opts && opts.dictionary && opts.dictionary.subarray(-32768);
1166
+ this.s = { i: 0, b: dict ? dict.length : 0 };
1167
+ this.o = new u8(32768);
1168
+ this.p = new u8(0);
1169
+ if (dict)
1170
+ this.o.set(dict);
1171
+ }
1172
+ Inflate.prototype.e = function (c) {
1173
+ if (!this.ondata)
1174
+ err(5);
1175
+ if (this.d)
1176
+ err(4);
1177
+ if (!this.p.length)
1178
+ this.p = c;
1179
+ else if (c.length) {
1180
+ var n = new u8(this.p.length + c.length);
1181
+ n.set(this.p), n.set(c, this.p.length), this.p = n;
1182
+ }
1183
+ };
1184
+ Inflate.prototype.c = function (final) {
1185
+ this.s.i = +(this.d = final || false);
1186
+ var bts = this.s.b;
1187
+ var dt = inflt(this.p, this.s, this.o);
1188
+ this.ondata(slc(dt, bts, this.s.b), this.d);
1189
+ this.o = slc(dt, this.s.b - 32768), this.s.b = this.o.length;
1190
+ this.p = slc(this.p, (this.s.p / 8) | 0), this.s.p &= 7;
1191
+ };
1192
+ /**
1193
+ * Pushes a chunk to be inflated
1194
+ * @param chunk The chunk to push
1195
+ * @param final Whether this is the final chunk
1196
+ */
1197
+ Inflate.prototype.push = function (chunk, final) {
1198
+ this.e(chunk), this.c(final);
1199
+ };
1200
+ return Inflate;
1201
+ }());
1202
+ export { Inflate };
1203
+ /**
1204
+ * Asynchronous streaming DEFLATE decompression
1205
+ */
1206
+ var AsyncInflate = /*#__PURE__*/ (function () {
1207
+ function AsyncInflate(opts, cb) {
1208
+ astrmify([
1209
+ bInflt,
1210
+ function () { return [astrm, Inflate]; }
1211
+ ], this, StrmOpt.call(this, opts, cb), function (ev) {
1212
+ var strm = new Inflate(ev.data);
1213
+ onmessage = astrm(strm);
1214
+ }, 7, 0);
1215
+ }
1216
+ return AsyncInflate;
1217
+ }());
1218
+ export { AsyncInflate };
1219
+ export function inflate(data, opts, cb) {
1220
+ if (!cb)
1221
+ cb = opts, opts = {};
1222
+ if (typeof cb != 'function')
1223
+ err(7);
1224
+ return cbify(data, opts, [
1225
+ bInflt
1226
+ ], function (ev) { return pbf(inflateSync(ev.data[0], gopt(ev.data[1]))); }, 1, cb);
1227
+ }
1228
+ export function inflateSync(data, opts) {
1229
+ return inflt(data, { i: 2 }, opts && opts.out, opts && opts.dictionary);
1230
+ }
1231
+ // before you yell at me for not just using extends, my reason is that TS inheritance is hard to workerize.
1232
+ /**
1233
+ * Streaming GZIP compression
1234
+ */
1235
+ var Gzip = /*#__PURE__*/ (function () {
1236
+ function Gzip(opts, cb) {
1237
+ this.c = crc();
1238
+ this.l = 0;
1239
+ this.v = 1;
1240
+ Deflate.call(this, opts, cb);
1241
+ }
1242
+ /**
1243
+ * Pushes a chunk to be GZIPped
1244
+ * @param chunk The chunk to push
1245
+ * @param final Whether this is the last chunk
1246
+ */
1247
+ Gzip.prototype.push = function (chunk, final) {
1248
+ this.c.p(chunk);
1249
+ this.l += chunk.length;
1250
+ Deflate.prototype.push.call(this, chunk, final);
1251
+ };
1252
+ Gzip.prototype.p = function (c, f) {
1253
+ var raw = dopt(c, this.o, this.v && gzhl(this.o), f && 8, this.s);
1254
+ if (this.v)
1255
+ gzh(raw, this.o), this.v = 0;
1256
+ if (f)
1257
+ wbytes(raw, raw.length - 8, this.c.d()), wbytes(raw, raw.length - 4, this.l);
1258
+ this.ondata(raw, f);
1259
+ };
1260
+ /**
1261
+ * Flushes buffered uncompressed data. Useful to immediately retrieve the
1262
+ * GZIPped output for small inputs.
1263
+ * @param sync Whether to flush to a byte boundary. A sync flush takes 4-5
1264
+ * extra bytes, but guarantees all pushed data is immediately
1265
+ * decompressible.
1266
+ */
1267
+ Gzip.prototype.flush = function (sync) {
1268
+ Deflate.prototype.flush.call(this, sync);
1269
+ };
1270
+ return Gzip;
1271
+ }());
1272
+ export { Gzip };
1273
+ /**
1274
+ * Asynchronous streaming GZIP compression
1275
+ */
1276
+ var AsyncGzip = /*#__PURE__*/ (function () {
1277
+ function AsyncGzip(opts, cb) {
1278
+ astrmify([
1279
+ bDflt,
1280
+ gze,
1281
+ function () { return [astrm, Deflate, Gzip]; }
1282
+ ], this, StrmOpt.call(this, opts, cb), function (ev) {
1283
+ var strm = new Gzip(ev.data);
1284
+ onmessage = astrm(strm);
1285
+ }, 8, 1);
1286
+ }
1287
+ return AsyncGzip;
1288
+ }());
1289
+ export { AsyncGzip };
1290
+ export function gzip(data, opts, cb) {
1291
+ if (!cb)
1292
+ cb = opts, opts = {};
1293
+ if (typeof cb != 'function')
1294
+ err(7);
1295
+ return cbify(data, opts, [
1296
+ bDflt,
1297
+ gze,
1298
+ function () { return [gzipSync]; }
1299
+ ], function (ev) { return pbf(gzipSync(ev.data[0], ev.data[1])); }, 2, cb);
1300
+ }
1301
+ /**
1302
+ * Compresses data with GZIP
1303
+ * @param data The data to compress
1304
+ * @param opts The compression options
1305
+ * @returns The gzipped version of the data
1306
+ */
1307
+ export function gzipSync(data, opts) {
1308
+ if (!opts)
1309
+ opts = {};
1310
+ var c = crc(), l = data.length;
1311
+ c.p(data);
1312
+ var d = dopt(data, opts, gzhl(opts), 8), s = d.length;
1313
+ return gzh(d, opts), wbytes(d, s - 8, c.d()), wbytes(d, s - 4, l), d;
1314
+ }
1315
+ /**
1316
+ * Streaming single or multi-member GZIP decompression
1317
+ */
1318
+ var Gunzip = /*#__PURE__*/ (function () {
1319
+ function Gunzip(opts, cb) {
1320
+ this.v = 1;
1321
+ this.r = 0;
1322
+ Inflate.call(this, opts, cb);
1323
+ }
1324
+ /**
1325
+ * Pushes a chunk to be GUNZIPped
1326
+ * @param chunk The chunk to push
1327
+ * @param final Whether this is the last chunk
1328
+ */
1329
+ Gunzip.prototype.push = function (chunk, final) {
1330
+ Inflate.prototype.e.call(this, chunk);
1331
+ this.r += chunk.length;
1332
+ if (this.v) {
1333
+ var p = this.p.subarray(this.v - 1);
1334
+ var s = p.length > 3 ? gzs(p) : 4;
1335
+ if (s > p.length) {
1336
+ if (!final)
1337
+ return;
1338
+ }
1339
+ else if (this.v > 1 && this.onmember) {
1340
+ this.onmember(this.r - p.length);
1341
+ }
1342
+ this.p = p.subarray(s), this.v = 0;
1343
+ }
1344
+ // necessary to prevent TS from using the closure value
1345
+ // This allows for workerization to function correctly
1346
+ Inflate.prototype.c.call(this, 0);
1347
+ // process concatenated GZIP
1348
+ if (this.s.f && !this.s.l) {
1349
+ this.v = shft(this.s.p) + 9;
1350
+ this.s = { i: 0 };
1351
+ this.o = new u8(0);
1352
+ this.push(new u8(0), final);
1353
+ }
1354
+ else if (final) {
1355
+ Inflate.prototype.c.call(this, final);
1356
+ }
1357
+ };
1358
+ return Gunzip;
1359
+ }());
1360
+ export { Gunzip };
1361
+ /**
1362
+ * Asynchronous streaming single or multi-member GZIP decompression
1363
+ */
1364
+ var AsyncGunzip = /*#__PURE__*/ (function () {
1365
+ function AsyncGunzip(opts, cb) {
1366
+ var _this = this;
1367
+ astrmify([
1368
+ bInflt,
1369
+ guze,
1370
+ function () { return [astrm, Inflate, Gunzip]; }
1371
+ ], this, StrmOpt.call(this, opts, cb), function (ev) {
1372
+ var strm = new Gunzip(ev.data);
1373
+ strm.onmember = function (offset) { return postMessage(offset); };
1374
+ onmessage = astrm(strm);
1375
+ }, 9, 0, function (offset) { return _this.onmember && _this.onmember(offset); });
1376
+ }
1377
+ return AsyncGunzip;
1378
+ }());
1379
+ export { AsyncGunzip };
1380
+ export function gunzip(data, opts, cb) {
1381
+ if (!cb)
1382
+ cb = opts, opts = {};
1383
+ if (typeof cb != 'function')
1384
+ err(7);
1385
+ return cbify(data, opts, [
1386
+ bInflt,
1387
+ guze,
1388
+ function () { return [gunzipSync]; }
1389
+ ], function (ev) { return pbf(gunzipSync(ev.data[0], ev.data[1])); }, 3, cb);
1390
+ }
1391
+ export function gunzipSync(data, opts) {
1392
+ var st = gzs(data);
1393
+ if (st + 8 > data.length)
1394
+ err(6, 'invalid gzip data');
1395
+ return inflt(data.subarray(st, -8), { i: 2 }, opts && opts.out || new u8(gzl(data)), opts && opts.dictionary);
1396
+ }
1397
+ /**
1398
+ * Streaming Zlib compression
1399
+ */
1400
+ var Zlib = /*#__PURE__*/ (function () {
1401
+ function Zlib(opts, cb) {
1402
+ this.c = adler();
1403
+ this.v = 1;
1404
+ Deflate.call(this, opts, cb);
1405
+ }
1406
+ /**
1407
+ * Pushes a chunk to be zlibbed
1408
+ * @param chunk The chunk to push
1409
+ * @param final Whether this is the last chunk
1410
+ */
1411
+ Zlib.prototype.push = function (chunk, final) {
1412
+ this.c.p(chunk);
1413
+ Deflate.prototype.push.call(this, chunk, final);
1414
+ };
1415
+ Zlib.prototype.p = function (c, f) {
1416
+ var raw = dopt(c, this.o, this.v && (this.o.dictionary ? 6 : 2), f && 4, this.s);
1417
+ if (this.v)
1418
+ zlh(raw, this.o), this.v = 0;
1419
+ if (f)
1420
+ wbytes(raw, raw.length - 4, this.c.d());
1421
+ this.ondata(raw, f);
1422
+ };
1423
+ /**
1424
+ * Flushes buffered uncompressed data. Useful to immediately retrieve the
1425
+ * zlibbed output for small inputs.
1426
+ * @param sync Whether to flush to a byte boundary. A sync flush takes 4-5
1427
+ * extra bytes, but guarantees all pushed data is immediately
1428
+ * decompressible.
1429
+ */
1430
+ Zlib.prototype.flush = function (sync) {
1431
+ Deflate.prototype.flush.call(this, sync);
1432
+ };
1433
+ return Zlib;
1434
+ }());
1435
+ export { Zlib };
1436
+ /**
1437
+ * Asynchronous streaming Zlib compression
1438
+ */
1439
+ var AsyncZlib = /*#__PURE__*/ (function () {
1440
+ function AsyncZlib(opts, cb) {
1441
+ astrmify([
1442
+ bDflt,
1443
+ zle,
1444
+ function () { return [astrm, Deflate, Zlib]; }
1445
+ ], this, StrmOpt.call(this, opts, cb), function (ev) {
1446
+ var strm = new Zlib(ev.data);
1447
+ onmessage = astrm(strm);
1448
+ }, 10, 1);
1449
+ }
1450
+ return AsyncZlib;
1451
+ }());
1452
+ export { AsyncZlib };
1453
+ export function zlib(data, opts, cb) {
1454
+ if (!cb)
1455
+ cb = opts, opts = {};
1456
+ if (typeof cb != 'function')
1457
+ err(7);
1458
+ return cbify(data, opts, [
1459
+ bDflt,
1460
+ zle,
1461
+ function () { return [zlibSync]; }
1462
+ ], function (ev) { return pbf(zlibSync(ev.data[0], ev.data[1])); }, 4, cb);
1463
+ }
1464
+ /**
1465
+ * Compress data with Zlib
1466
+ * @param data The data to compress
1467
+ * @param opts The compression options
1468
+ * @returns The zlib-compressed version of the data
1469
+ */
1470
+ export function zlibSync(data, opts) {
1471
+ if (!opts)
1472
+ opts = {};
1473
+ var a = adler();
1474
+ a.p(data);
1475
+ var d = dopt(data, opts, opts.dictionary ? 6 : 2, 4);
1476
+ return zlh(d, opts), wbytes(d, d.length - 4, a.d()), d;
1477
+ }
1478
+ /**
1479
+ * Streaming Zlib decompression
1480
+ */
1481
+ var Unzlib = /*#__PURE__*/ (function () {
1482
+ function Unzlib(opts, cb) {
1483
+ Inflate.call(this, opts, cb);
1484
+ this.v = opts && opts.dictionary ? 2 : 1;
1485
+ }
1486
+ /**
1487
+ * Pushes a chunk to be unzlibbed
1488
+ * @param chunk The chunk to push
1489
+ * @param final Whether this is the last chunk
1490
+ */
1491
+ Unzlib.prototype.push = function (chunk, final) {
1492
+ Inflate.prototype.e.call(this, chunk);
1493
+ if (this.v) {
1494
+ if (this.p.length < 6 && !final)
1495
+ return;
1496
+ this.p = this.p.subarray(zls(this.p, this.v - 1)), this.v = 0;
1497
+ }
1498
+ if (final) {
1499
+ if (this.p.length < 4)
1500
+ err(6, 'invalid zlib data');
1501
+ this.p = this.p.subarray(0, -4);
1502
+ }
1503
+ // necessary to prevent TS from using the closure value
1504
+ // This allows for workerization to function correctly
1505
+ Inflate.prototype.c.call(this, final);
1506
+ };
1507
+ return Unzlib;
1508
+ }());
1509
+ export { Unzlib };
1510
+ /**
1511
+ * Asynchronous streaming Zlib decompression
1512
+ */
1513
+ var AsyncUnzlib = /*#__PURE__*/ (function () {
1514
+ function AsyncUnzlib(opts, cb) {
1515
+ astrmify([
1516
+ bInflt,
1517
+ zule,
1518
+ function () { return [astrm, Inflate, Unzlib]; }
1519
+ ], this, StrmOpt.call(this, opts, cb), function (ev) {
1520
+ var strm = new Unzlib(ev.data);
1521
+ onmessage = astrm(strm);
1522
+ }, 11, 0);
1523
+ }
1524
+ return AsyncUnzlib;
1525
+ }());
1526
+ export { AsyncUnzlib };
1527
+ export function unzlib(data, opts, cb) {
1528
+ if (!cb)
1529
+ cb = opts, opts = {};
1530
+ if (typeof cb != 'function')
1531
+ err(7);
1532
+ return cbify(data, opts, [
1533
+ bInflt,
1534
+ zule,
1535
+ function () { return [unzlibSync]; }
1536
+ ], function (ev) { return pbf(unzlibSync(ev.data[0], gopt(ev.data[1]))); }, 5, cb);
1537
+ }
1538
+ export function unzlibSync(data, opts) {
1539
+ return inflt(data.subarray(zls(data, opts && opts.dictionary), -4), { i: 2 }, opts && opts.out, opts && opts.dictionary);
1540
+ }
1541
+ // Default algorithm for compression (used because having a known output size allows faster decompression)
1542
+ export { gzip as compress, AsyncGzip as AsyncCompress };
1543
+ export { gzipSync as compressSync, Gzip as Compress };
1544
+ /**
1545
+ * Streaming GZIP, Zlib, or raw DEFLATE decompression
1546
+ */
1547
+ var Decompress = /*#__PURE__*/ (function () {
1548
+ function Decompress(opts, cb) {
1549
+ this.o = StrmOpt.call(this, opts, cb) || {};
1550
+ this.G = Gunzip;
1551
+ this.I = Inflate;
1552
+ this.Z = Unzlib;
1553
+ }
1554
+ // init substream
1555
+ // overriden by AsyncDecompress
1556
+ Decompress.prototype.i = function () {
1557
+ var _this = this;
1558
+ this.s.ondata = function (dat, final) {
1559
+ _this.ondata(dat, final);
1560
+ };
1561
+ };
1562
+ /**
1563
+ * Pushes a chunk to be decompressed
1564
+ * @param chunk The chunk to push
1565
+ * @param final Whether this is the last chunk
1566
+ */
1567
+ Decompress.prototype.push = function (chunk, final) {
1568
+ if (!this.ondata)
1569
+ err(5);
1570
+ if (!this.s) {
1571
+ if (this.p && this.p.length) {
1572
+ var n = new u8(this.p.length + chunk.length);
1573
+ n.set(this.p), n.set(chunk, this.p.length);
1574
+ }
1575
+ else
1576
+ this.p = chunk;
1577
+ if (this.p.length > 2) {
1578
+ this.s = (this.p[0] == 31 && this.p[1] == 139 && this.p[2] == 8)
1579
+ ? new this.G(this.o)
1580
+ : ((this.p[0] & 15) != 8 || (this.p[0] >> 4) > 7 || ((this.p[0] << 8 | this.p[1]) % 31))
1581
+ ? new this.I(this.o)
1582
+ : new this.Z(this.o);
1583
+ this.i();
1584
+ this.s.push(this.p, final);
1585
+ this.p = null;
1586
+ }
1587
+ }
1588
+ else
1589
+ this.s.push(chunk, final);
1590
+ };
1591
+ return Decompress;
1592
+ }());
1593
+ export { Decompress };
1594
+ /**
1595
+ * Asynchronous streaming GZIP, Zlib, or raw DEFLATE decompression
1596
+ */
1597
+ var AsyncDecompress = /*#__PURE__*/ (function () {
1598
+ function AsyncDecompress(opts, cb) {
1599
+ Decompress.call(this, opts, cb);
1600
+ this.queuedSize = 0;
1601
+ this.G = AsyncGunzip;
1602
+ this.I = AsyncInflate;
1603
+ this.Z = AsyncUnzlib;
1604
+ }
1605
+ AsyncDecompress.prototype.i = function () {
1606
+ var _this = this;
1607
+ this.s.ondata = function (err, dat, final) {
1608
+ _this.ondata(err, dat, final);
1609
+ };
1610
+ this.s.ondrain = function (size) {
1611
+ _this.queuedSize -= size;
1612
+ if (_this.ondrain)
1613
+ _this.ondrain(size);
1614
+ };
1615
+ };
1616
+ /**
1617
+ * Pushes a chunk to be decompressed
1618
+ * @param chunk The chunk to push
1619
+ * @param final Whether this is the last chunk
1620
+ */
1621
+ AsyncDecompress.prototype.push = function (chunk, final) {
1622
+ this.queuedSize += chunk.length;
1623
+ Decompress.prototype.push.call(this, chunk, final);
1624
+ };
1625
+ return AsyncDecompress;
1626
+ }());
1627
+ export { AsyncDecompress };
1628
+ export function decompress(data, opts, cb) {
1629
+ if (!cb)
1630
+ cb = opts, opts = {};
1631
+ if (typeof cb != 'function')
1632
+ err(7);
1633
+ return (data[0] == 31 && data[1] == 139 && data[2] == 8)
1634
+ ? gunzip(data, opts, cb)
1635
+ : ((data[0] & 15) != 8 || (data[0] >> 4) > 7 || ((data[0] << 8 | data[1]) % 31))
1636
+ ? inflate(data, opts, cb)
1637
+ : unzlib(data, opts, cb);
1638
+ }
1639
+ /**
1640
+ * Expands compressed GZIP, Zlib, or raw DEFLATE data, automatically detecting the format
1641
+ * @param data The data to decompress
1642
+ * @param opts The decompression options
1643
+ * @returns The decompressed version of the data
1644
+ */
1645
+ export function decompressSync(data, opts) {
1646
+ return (data[0] == 31 && data[1] == 139 && data[2] == 8)
1647
+ ? gunzipSync(data, opts)
1648
+ : ((data[0] & 15) != 8 || (data[0] >> 4) > 7 || ((data[0] << 8 | data[1]) % 31))
1649
+ ? inflateSync(data, opts)
1650
+ : unzlibSync(data, opts);
1651
+ }
1652
+ // flatten a directory structure
1653
+ var fltn = function (d, p, t, o) {
1654
+ for (var k in d) {
1655
+ var val = d[k], n = p + k, op = o;
1656
+ if (Array.isArray(val))
1657
+ op = mrg(o, val[1]), val = val[0];
1658
+ if (ArrayBuffer.isView(val))
1659
+ t[n] = [val, op];
1660
+ else {
1661
+ t[n += '/'] = [new u8(0), op];
1662
+ fltn(val, n, t, o);
1663
+ }
1664
+ }
1665
+ };
1666
+ // text encoder
1667
+ var te = typeof TextEncoder != 'undefined' && /*#__PURE__*/ new TextEncoder();
1668
+ // text decoder
1669
+ var td = typeof TextDecoder != 'undefined' && /*#__PURE__*/ new TextDecoder();
1670
+ // text decoder stream
1671
+ var tds = 0;
1672
+ try {
1673
+ td.decode(et, { stream: true });
1674
+ tds = 1;
1675
+ }
1676
+ catch (e) { }
1677
+ // decode UTF8
1678
+ var dutf8 = function (d) {
1679
+ for (var r = '', i = 0;;) {
1680
+ var c = d[i++];
1681
+ var eb = (c > 127) + (c > 223) + (c > 239);
1682
+ if (i + eb > d.length)
1683
+ return { s: r, r: slc(d, i - 1) };
1684
+ if (!eb)
1685
+ r += String.fromCharCode(c);
1686
+ else if (eb == 3) {
1687
+ c = ((c & 15) << 18 | (d[i++] & 63) << 12 | (d[i++] & 63) << 6 | (d[i++] & 63)) - 65536,
1688
+ r += String.fromCharCode(55296 | (c >> 10), 56320 | (c & 1023));
1689
+ }
1690
+ else if (eb & 1)
1691
+ r += String.fromCharCode((c & 31) << 6 | (d[i++] & 63));
1692
+ else
1693
+ r += String.fromCharCode((c & 15) << 12 | (d[i++] & 63) << 6 | (d[i++] & 63));
1694
+ }
1695
+ };
1696
+ /**
1697
+ * Streaming UTF-8 decoding
1698
+ */
1699
+ var DecodeUTF8 = /*#__PURE__*/ (function () {
1700
+ /**
1701
+ * Creates a UTF-8 decoding stream
1702
+ * @param cb The callback to call whenever data is decoded
1703
+ */
1704
+ function DecodeUTF8(cb) {
1705
+ this.ondata = cb;
1706
+ if (tds)
1707
+ this.t = new TextDecoder();
1708
+ else
1709
+ this.p = et;
1710
+ }
1711
+ /**
1712
+ * Pushes a chunk to be decoded from UTF-8 binary
1713
+ * @param chunk The chunk to push
1714
+ * @param final Whether this is the last chunk
1715
+ */
1716
+ DecodeUTF8.prototype.push = function (chunk, final) {
1717
+ if (!this.ondata)
1718
+ err(5);
1719
+ final = !!final;
1720
+ if (this.t) {
1721
+ this.ondata(this.t.decode(chunk, { stream: true }), final);
1722
+ if (final) {
1723
+ if (this.t.decode().length)
1724
+ err(8);
1725
+ this.t = null;
1726
+ }
1727
+ return;
1728
+ }
1729
+ if (!this.p)
1730
+ err(4);
1731
+ var dat = new u8(this.p.length + chunk.length);
1732
+ dat.set(this.p);
1733
+ dat.set(chunk, this.p.length);
1734
+ var _a = dutf8(dat), s = _a.s, r = _a.r;
1735
+ if (final) {
1736
+ if (r.length)
1737
+ err(8);
1738
+ this.p = null;
1739
+ }
1740
+ else
1741
+ this.p = r;
1742
+ this.ondata(s, final);
1743
+ };
1744
+ return DecodeUTF8;
1745
+ }());
1746
+ export { DecodeUTF8 };
1747
+ /**
1748
+ * Streaming UTF-8 encoding
1749
+ */
1750
+ var EncodeUTF8 = /*#__PURE__*/ (function () {
1751
+ /**
1752
+ * Creates a UTF-8 decoding stream
1753
+ * @param cb The callback to call whenever data is encoded
1754
+ */
1755
+ function EncodeUTF8(cb) {
1756
+ this.ondata = cb;
1757
+ }
1758
+ /**
1759
+ * Pushes a chunk to be encoded to UTF-8
1760
+ * @param chunk The string data to push
1761
+ * @param final Whether this is the last chunk
1762
+ */
1763
+ EncodeUTF8.prototype.push = function (chunk, final) {
1764
+ if (!this.ondata)
1765
+ err(5);
1766
+ if (this.d)
1767
+ err(4);
1768
+ this.ondata(strToU8(chunk), this.d = final || false);
1769
+ };
1770
+ return EncodeUTF8;
1771
+ }());
1772
+ export { EncodeUTF8 };
1773
+ /**
1774
+ * Converts a string into a Uint8Array for use with compression/decompression methods
1775
+ * @param str The string to encode
1776
+ * @param latin1 Whether or not to interpret the data as Latin-1. This should
1777
+ * not need to be true unless decoding a binary string.
1778
+ * @returns The string encoded in UTF-8/Latin-1 binary
1779
+ */
1780
+ export function strToU8(str, latin1) {
1781
+ if (latin1) {
1782
+ var ar_1 = new u8(str.length);
1783
+ for (var i = 0; i < str.length; ++i)
1784
+ ar_1[i] = str.charCodeAt(i);
1785
+ return ar_1;
1786
+ }
1787
+ if (te)
1788
+ return te.encode(str);
1789
+ var l = str.length;
1790
+ var ar = new u8(str.length + (str.length >> 1));
1791
+ var ai = 0;
1792
+ var w = function (v) { ar[ai++] = v; };
1793
+ for (var i = 0; i < l; ++i) {
1794
+ if (ai + 5 > ar.length) {
1795
+ var n = new u8(ai + 8 + ((l - i) << 1));
1796
+ n.set(ar);
1797
+ ar = n;
1798
+ }
1799
+ var c = str.charCodeAt(i);
1800
+ if (c < 128 || latin1)
1801
+ w(c);
1802
+ else if (c < 2048)
1803
+ w(192 | (c >> 6)), w(128 | (c & 63));
1804
+ else if (c > 55295 && c < 57344)
1805
+ c = 65536 + (c & 1023 << 10) | (str.charCodeAt(++i) & 1023),
1806
+ w(240 | (c >> 18)), w(128 | ((c >> 12) & 63)), w(128 | ((c >> 6) & 63)), w(128 | (c & 63));
1807
+ else
1808
+ w(224 | (c >> 12)), w(128 | ((c >> 6) & 63)), w(128 | (c & 63));
1809
+ }
1810
+ return slc(ar, 0, ai);
1811
+ }
1812
+ /**
1813
+ * Converts a Uint8Array to a string
1814
+ * @param dat The data to decode to string
1815
+ * @param latin1 Whether or not to interpret the data as Latin-1. This should
1816
+ * not need to be true unless encoding to binary string.
1817
+ * @returns The original UTF-8/Latin-1 string
1818
+ */
1819
+ export function strFromU8(dat, latin1) {
1820
+ if (latin1) {
1821
+ var r = '';
1822
+ for (var i = 0; i < dat.length; i += 16384)
1823
+ r += String.fromCharCode.apply(null, dat.subarray(i, i + 16384));
1824
+ return r;
1825
+ }
1826
+ else if (td) {
1827
+ return td.decode(dat);
1828
+ }
1829
+ else {
1830
+ var _a = dutf8(dat), s = _a.s, r = _a.r;
1831
+ if (r.length)
1832
+ err(8);
1833
+ return s;
1834
+ }
1835
+ }
1836
+ ;
1837
+ // deflate bit flag
1838
+ var dbf = function (l) { return l == 1 ? 3 : l < 6 ? 2 : l == 9 ? 1 : 0; };
1839
+ // skip local zip header
1840
+ var slzh = function (d, b) { return b + 30 + b2(d, b + 26) + b2(d, b + 28); };
1841
+ // read zip header
1842
+ var zh = function (d, b, z) {
1843
+ var fnl = b2(d, b + 28), efl = b2(d, b + 30), fn = strFromU8(d.subarray(b + 46, b + 46 + fnl), !(b2(d, b + 8) & 2048)), es = b + 46 + fnl;
1844
+ var _a = z64hs(d, es, efl, z, b4(d, b + 20), b4(d, b + 24), b4(d, b + 42)), sc = _a[0], su = _a[1], off = _a[2];
1845
+ return [b2(d, b + 10), sc, su, fn, es + efl + b2(d, b + 32), off];
1846
+ };
1847
+ // read zip64 header sizes
1848
+ var z64hs = function (d, b, l, z, sc, su, off) {
1849
+ var nsc = sc == 4294967295, nsu = su == 4294967295, noff = off == 4294967295, e = b + l;
1850
+ var nf = nsc + nsu + noff;
1851
+ if (z && nf) {
1852
+ for (; b + 4 < e; b += 4 + b2(d, b + 2)) {
1853
+ if (b2(d, b) == 1) {
1854
+ return [
1855
+ nsc ? b8(d, b + 4 + 8 * nsu) : sc,
1856
+ nsu ? b8(d, b + 4) : su,
1857
+ noff ? b8(d, b + 4 + 8 * (nsu + nsc)) : off,
1858
+ 1
1859
+ ];
1860
+ }
1861
+ }
1862
+ // z == 2 for unknown whether or not zip64
1863
+ if (z < 2)
1864
+ err(13);
1865
+ }
1866
+ return [sc, su, off, 0];
1867
+ };
1868
+ // extra field length
1869
+ var exfl = function (ex) {
1870
+ var le = 0;
1871
+ if (ex) {
1872
+ for (var k in ex) {
1873
+ var l = ex[k].length;
1874
+ if (l > 65535)
1875
+ err(9);
1876
+ le += l + 4;
1877
+ }
1878
+ }
1879
+ return le;
1880
+ };
1881
+ // write zip header
1882
+ var wzh = function (d, b, f, fn, u, c, ce, co) {
1883
+ var fl = fn.length, ex = f.extra, col = co && co.length;
1884
+ var exl = exfl(ex);
1885
+ wbytes(d, b, ce != null ? 0x2014B50 : 0x4034B50), b += 4;
1886
+ if (ce != null)
1887
+ d[b++] = 20, d[b++] = f.os;
1888
+ d[b] = 20, b += 2; // spec compliance? what's that?
1889
+ d[b++] = (f.flag << 1) | (c < 0 && 8), d[b++] = u && 8;
1890
+ d[b++] = f.compression & 255, d[b++] = f.compression >> 8;
1891
+ var dt = new Date(f.mtime == null ? Date.now() : f.mtime), y = dt.getFullYear() - 1980;
1892
+ if (y < 0 || y > 119)
1893
+ err(10);
1894
+ wbytes(d, b, (y << 25) | ((dt.getMonth() + 1) << 21) | (dt.getDate() << 16) | (dt.getHours() << 11) | (dt.getMinutes() << 5) | (dt.getSeconds() >> 1)), b += 4;
1895
+ if (c != -1) {
1896
+ wbytes(d, b, f.crc);
1897
+ wbytes(d, b + 4, c < 0 ? -c - 2 : c);
1898
+ wbytes(d, b + 8, f.size);
1899
+ }
1900
+ wbytes(d, b + 12, fl);
1901
+ wbytes(d, b + 14, exl), b += 16;
1902
+ if (ce != null) {
1903
+ wbytes(d, b, col);
1904
+ wbytes(d, b + 6, f.attrs);
1905
+ wbytes(d, b + 10, ce), b += 14;
1906
+ }
1907
+ d.set(fn, b);
1908
+ b += fl;
1909
+ if (exl) {
1910
+ for (var k in ex) {
1911
+ var exf = ex[k], l = exf.length;
1912
+ wbytes(d, b, +k);
1913
+ wbytes(d, b + 2, l);
1914
+ d.set(exf, b + 4), b += 4 + l;
1915
+ }
1916
+ }
1917
+ if (col)
1918
+ d.set(co, b), b += col;
1919
+ return b;
1920
+ };
1921
+ // write zip footer (end of central directory)
1922
+ var wzf = function (o, b, c, d, e) {
1923
+ wbytes(o, b, 0x6054B50); // skip disk
1924
+ wbytes(o, b + 8, c);
1925
+ wbytes(o, b + 10, c);
1926
+ wbytes(o, b + 12, d);
1927
+ wbytes(o, b + 16, e);
1928
+ };
1929
+ /**
1930
+ * A pass-through stream to keep data uncompressed in a ZIP archive.
1931
+ */
1932
+ var ZipPassThrough = /*#__PURE__*/ (function () {
1933
+ /**
1934
+ * Creates a pass-through stream that can be added to ZIP archives
1935
+ * @param filename The filename to associate with this data stream
1936
+ */
1937
+ function ZipPassThrough(filename) {
1938
+ this.filename = filename;
1939
+ this.c = crc();
1940
+ this.size = 0;
1941
+ this.compression = 0;
1942
+ }
1943
+ /**
1944
+ * Processes a chunk and pushes to the output stream. You can override this
1945
+ * method in a subclass for custom behavior, but by default this passes
1946
+ * the data through. You must call this.ondata(err, chunk, final) at some
1947
+ * point in this method.
1948
+ * @param chunk The chunk to process
1949
+ * @param final Whether this is the last chunk
1950
+ */
1951
+ ZipPassThrough.prototype.process = function (chunk, final) {
1952
+ this.ondata(null, chunk, final);
1953
+ };
1954
+ /**
1955
+ * Pushes a chunk to be added. If you are subclassing this with a custom
1956
+ * compression algorithm, note that you must push data from the source
1957
+ * file only, pre-compression.
1958
+ * @param chunk The chunk to push
1959
+ * @param final Whether this is the last chunk
1960
+ */
1961
+ ZipPassThrough.prototype.push = function (chunk, final) {
1962
+ if (!this.ondata)
1963
+ err(5);
1964
+ this.c.p(chunk);
1965
+ this.size += chunk.length;
1966
+ if (final)
1967
+ this.crc = this.c.d();
1968
+ // we shouldn't really do this cast, but properly handling ArrayBufferLike
1969
+ // makes the API unergonomic with Buffer
1970
+ this.process(chunk, final || false);
1971
+ };
1972
+ return ZipPassThrough;
1973
+ }());
1974
+ export { ZipPassThrough };
1975
+ // I don't extend because TypeScript extension adds 1kB of runtime bloat
1976
+ /**
1977
+ * Streaming DEFLATE compression for ZIP archives. Prefer using AsyncZipDeflate
1978
+ * for better performance
1979
+ */
1980
+ var ZipDeflate = /*#__PURE__*/ (function () {
1981
+ /**
1982
+ * Creates a DEFLATE stream that can be added to ZIP archives
1983
+ * @param filename The filename to associate with this data stream
1984
+ * @param opts The compression options
1985
+ */
1986
+ function ZipDeflate(filename, opts) {
1987
+ var _this = this;
1988
+ if (!opts)
1989
+ opts = {};
1990
+ ZipPassThrough.call(this, filename);
1991
+ this.d = new Deflate(opts, function (dat, final) {
1992
+ _this.ondata(null, dat, final);
1993
+ });
1994
+ this.compression = 8;
1995
+ this.flag = dbf(opts.level);
1996
+ }
1997
+ ZipDeflate.prototype.process = function (chunk, final) {
1998
+ try {
1999
+ this.d.push(chunk, final);
2000
+ }
2001
+ catch (e) {
2002
+ this.ondata(e, null, final);
2003
+ }
2004
+ };
2005
+ /**
2006
+ * Pushes a chunk to be deflated
2007
+ * @param chunk The chunk to push
2008
+ * @param final Whether this is the last chunk
2009
+ */
2010
+ ZipDeflate.prototype.push = function (chunk, final) {
2011
+ ZipPassThrough.prototype.push.call(this, chunk, final);
2012
+ };
2013
+ return ZipDeflate;
2014
+ }());
2015
+ export { ZipDeflate };
2016
+ /**
2017
+ * Asynchronous streaming DEFLATE compression for ZIP archives
2018
+ */
2019
+ var AsyncZipDeflate = /*#__PURE__*/ (function () {
2020
+ /**
2021
+ * Creates an asynchronous DEFLATE stream that can be added to ZIP archives
2022
+ * @param filename The filename to associate with this data stream
2023
+ * @param opts The compression options
2024
+ */
2025
+ function AsyncZipDeflate(filename, opts) {
2026
+ var _this = this;
2027
+ if (!opts)
2028
+ opts = {};
2029
+ ZipPassThrough.call(this, filename);
2030
+ this.d = new AsyncDeflate(opts, function (err, dat, final) {
2031
+ _this.ondata(err, dat, final);
2032
+ });
2033
+ this.compression = 8;
2034
+ this.flag = dbf(opts.level);
2035
+ this.terminate = this.d.terminate;
2036
+ }
2037
+ AsyncZipDeflate.prototype.process = function (chunk, final) {
2038
+ this.d.push(chunk, final);
2039
+ };
2040
+ /**
2041
+ * Pushes a chunk to be deflated
2042
+ * @param chunk The chunk to push
2043
+ * @param final Whether this is the last chunk
2044
+ */
2045
+ AsyncZipDeflate.prototype.push = function (chunk, final) {
2046
+ ZipPassThrough.prototype.push.call(this, chunk, final);
2047
+ };
2048
+ return AsyncZipDeflate;
2049
+ }());
2050
+ export { AsyncZipDeflate };
2051
+ // TODO: Better tree shaking
2052
+ /**
2053
+ * A zippable archive to which files can incrementally be added
2054
+ */
2055
+ var Zip = /*#__PURE__*/ (function () {
2056
+ /**
2057
+ * Creates an empty ZIP archive to which files can be added
2058
+ * @param cb The callback to call whenever data for the generated ZIP archive
2059
+ * is available
2060
+ */
2061
+ function Zip(cb) {
2062
+ this.ondata = cb;
2063
+ this.u = [];
2064
+ this.d = 1;
2065
+ }
2066
+ /**
2067
+ * Adds a file to the ZIP archive
2068
+ * @param file The file stream to add
2069
+ */
2070
+ Zip.prototype.add = function (file) {
2071
+ var _this = this;
2072
+ if (!this.ondata)
2073
+ err(5);
2074
+ // finishing or finished
2075
+ if (this.d & 2)
2076
+ this.ondata(err(4 + (this.d & 1) * 8, 0, 1), null, false);
2077
+ else {
2078
+ var f = strToU8(file.filename), fl_1 = f.length;
2079
+ var com = file.comment, o = com && strToU8(com);
2080
+ var u = fl_1 != file.filename.length || (o && (com.length != o.length));
2081
+ var hl_1 = fl_1 + exfl(file.extra) + 30;
2082
+ if (fl_1 > 65535)
2083
+ this.ondata(err(11, 0, 1), null, false);
2084
+ var header = new u8(hl_1);
2085
+ wzh(header, 0, file, f, u, -1);
2086
+ var chks_1 = [header];
2087
+ var pAll_1 = function () {
2088
+ for (var _i = 0, chks_2 = chks_1; _i < chks_2.length; _i++) {
2089
+ var chk = chks_2[_i];
2090
+ _this.ondata(null, chk, false);
2091
+ }
2092
+ chks_1 = [];
2093
+ };
2094
+ var tr_1 = this.d;
2095
+ this.d = 0;
2096
+ var ind_1 = this.u.length;
2097
+ var uf_1 = mrg(file, {
2098
+ f: f,
2099
+ u: u,
2100
+ o: o,
2101
+ t: function () {
2102
+ if (file.terminate)
2103
+ file.terminate();
2104
+ },
2105
+ r: function () {
2106
+ pAll_1();
2107
+ if (tr_1) {
2108
+ var nxt = _this.u[ind_1 + 1];
2109
+ if (nxt)
2110
+ nxt.r();
2111
+ else
2112
+ _this.d = 1;
2113
+ }
2114
+ tr_1 = 1;
2115
+ }
2116
+ });
2117
+ var cl_1 = 0;
2118
+ file.ondata = function (err, dat, final) {
2119
+ if (err) {
2120
+ _this.ondata(err, dat, final);
2121
+ _this.terminate();
2122
+ }
2123
+ else {
2124
+ cl_1 += dat.length;
2125
+ chks_1.push(dat);
2126
+ if (final) {
2127
+ var dd = new u8(16);
2128
+ wbytes(dd, 0, 0x8074B50);
2129
+ wbytes(dd, 4, file.crc);
2130
+ wbytes(dd, 8, cl_1);
2131
+ wbytes(dd, 12, file.size);
2132
+ chks_1.push(dd);
2133
+ uf_1.c = cl_1, uf_1.b = hl_1 + cl_1 + 16, uf_1.crc = file.crc, uf_1.size = file.size;
2134
+ if (tr_1)
2135
+ uf_1.r();
2136
+ tr_1 = 1;
2137
+ }
2138
+ else if (tr_1)
2139
+ pAll_1();
2140
+ }
2141
+ };
2142
+ this.u.push(uf_1);
2143
+ }
2144
+ };
2145
+ /**
2146
+ * Ends the process of adding files and prepares to emit the final chunks.
2147
+ * This *must* be called after adding all desired files for the resulting
2148
+ * ZIP file to work properly.
2149
+ */
2150
+ Zip.prototype.end = function () {
2151
+ var _this = this;
2152
+ if (this.d & 2) {
2153
+ this.ondata(err(4 + (this.d & 1) * 8, 0, 1), null, true);
2154
+ return;
2155
+ }
2156
+ if (this.d)
2157
+ this.e();
2158
+ else
2159
+ this.u.push({
2160
+ r: function () {
2161
+ if (!(_this.d & 1))
2162
+ return;
2163
+ _this.u.splice(-1, 1);
2164
+ _this.e();
2165
+ },
2166
+ t: function () { }
2167
+ });
2168
+ this.d = 3;
2169
+ };
2170
+ Zip.prototype.e = function () {
2171
+ var bt = 0, l = 0, tl = 0;
2172
+ for (var _i = 0, _a = this.u; _i < _a.length; _i++) {
2173
+ var f = _a[_i];
2174
+ tl += 46 + f.f.length + exfl(f.extra) + (f.o ? f.o.length : 0);
2175
+ }
2176
+ var out = new u8(tl + 22);
2177
+ for (var _b = 0, _c = this.u; _b < _c.length; _b++) {
2178
+ var f = _c[_b];
2179
+ wzh(out, bt, f, f.f, f.u, -f.c - 2, l, f.o);
2180
+ bt += 46 + f.f.length + exfl(f.extra) + (f.o ? f.o.length : 0), l += f.b;
2181
+ }
2182
+ wzf(out, bt, this.u.length, tl, l);
2183
+ this.ondata(null, out, true);
2184
+ this.d = 2;
2185
+ };
2186
+ /**
2187
+ * A method to terminate any internal workers used by the stream. Subsequent
2188
+ * calls to add() will fail.
2189
+ */
2190
+ Zip.prototype.terminate = function () {
2191
+ for (var _i = 0, _a = this.u; _i < _a.length; _i++) {
2192
+ var f = _a[_i];
2193
+ f.t();
2194
+ }
2195
+ this.d = 2;
2196
+ };
2197
+ return Zip;
2198
+ }());
2199
+ export { Zip };
2200
+ export function zip(data, opts, cb) {
2201
+ if (!cb)
2202
+ cb = opts, opts = {};
2203
+ if (typeof cb != 'function')
2204
+ err(7);
2205
+ var r = {};
2206
+ fltn(data, '', r, opts);
2207
+ var k = Object.keys(r);
2208
+ var lft = k.length, o = 0, tot = 0;
2209
+ var slft = lft, files = new Array(lft);
2210
+ var term = [];
2211
+ var tAll = function () {
2212
+ for (var i = 0; i < term.length; ++i)
2213
+ term[i]();
2214
+ };
2215
+ var cbd = function (a, b) {
2216
+ mt(function () { cb(a, b); });
2217
+ };
2218
+ mt(function () { cbd = cb; });
2219
+ var cbf = function () {
2220
+ var out = new u8(tot + 22), oe = o, cdl = tot - o;
2221
+ tot = 0;
2222
+ for (var i = 0; i < slft; ++i) {
2223
+ var f = files[i];
2224
+ try {
2225
+ var l = f.c.length;
2226
+ wzh(out, tot, f, f.f, f.u, l);
2227
+ var badd = 30 + f.f.length + exfl(f.extra);
2228
+ var loc = tot + badd;
2229
+ out.set(f.c, loc);
2230
+ wzh(out, o, f, f.f, f.u, l, tot, f.m), o += 16 + badd + (f.m ? f.m.length : 0), tot = loc + l;
2231
+ }
2232
+ catch (e) {
2233
+ return cbd(e, null);
2234
+ }
2235
+ }
2236
+ wzf(out, o, files.length, cdl, oe);
2237
+ cbd(null, out);
2238
+ };
2239
+ if (!lft)
2240
+ cbf();
2241
+ var _loop_1 = function (i) {
2242
+ var fn = k[i];
2243
+ var _a = r[fn], file = _a[0], p = _a[1];
2244
+ var c = crc(), size = file.length;
2245
+ c.p(file);
2246
+ var f = strToU8(fn), s = f.length;
2247
+ var com = p.comment, m = com && strToU8(com), ms = m && m.length;
2248
+ var exl = exfl(p.extra);
2249
+ var compression = p.level == 0 ? 0 : 8;
2250
+ var cbl = function (e, d) {
2251
+ if (e) {
2252
+ tAll();
2253
+ cbd(e, null);
2254
+ }
2255
+ else {
2256
+ var l = d.length;
2257
+ files[i] = mrg(p, {
2258
+ size: size,
2259
+ crc: c.d(),
2260
+ c: d,
2261
+ f: f,
2262
+ m: m,
2263
+ u: s != fn.length || (m && (com.length != ms)),
2264
+ compression: compression
2265
+ });
2266
+ o += 30 + s + exl + l;
2267
+ tot += 76 + 2 * (s + exl) + (ms || 0) + l;
2268
+ if (!--lft)
2269
+ cbf();
2270
+ }
2271
+ };
2272
+ if (s > 65535)
2273
+ cbl(err(11, 0, 1), null);
2274
+ if (!compression)
2275
+ cbl(null, file);
2276
+ else if (size < 160000) {
2277
+ try {
2278
+ cbl(null, deflateSync(file, p));
2279
+ }
2280
+ catch (e) {
2281
+ cbl(e, null);
2282
+ }
2283
+ }
2284
+ else
2285
+ term.push(deflate(file, p, cbl));
2286
+ };
2287
+ // Cannot use lft because it can decrease
2288
+ for (var i = 0; i < slft; ++i) {
2289
+ _loop_1(i);
2290
+ }
2291
+ return tAll;
2292
+ }
2293
+ /**
2294
+ * Synchronously creates a ZIP file. Prefer using `zip` for better performance
2295
+ * with more than one file.
2296
+ * @param data The directory structure for the ZIP archive
2297
+ * @param opts The main options, merged with per-file options
2298
+ * @returns The generated ZIP archive
2299
+ */
2300
+ export function zipSync(data, opts) {
2301
+ if (!opts)
2302
+ opts = {};
2303
+ var r = {};
2304
+ var files = [];
2305
+ fltn(data, '', r, opts);
2306
+ var o = 0;
2307
+ var tot = 0;
2308
+ for (var fn in r) {
2309
+ var _a = r[fn], file = _a[0], p = _a[1];
2310
+ var compression = p.level == 0 ? 0 : 8;
2311
+ var f = strToU8(fn), s = f.length;
2312
+ var com = p.comment, m = com && strToU8(com), ms = m && m.length;
2313
+ var exl = exfl(p.extra);
2314
+ if (s > 65535)
2315
+ err(11);
2316
+ var d = compression ? deflateSync(file, p) : file, l = d.length;
2317
+ var c = crc();
2318
+ c.p(file);
2319
+ files.push(mrg(p, {
2320
+ size: file.length,
2321
+ crc: c.d(),
2322
+ c: d,
2323
+ f: f,
2324
+ m: m,
2325
+ u: s != fn.length || (m && (com.length != ms)),
2326
+ o: o,
2327
+ compression: compression
2328
+ }));
2329
+ o += 30 + s + exl + l;
2330
+ tot += 76 + 2 * (s + exl) + (ms || 0) + l;
2331
+ }
2332
+ var out = new u8(tot + 22), oe = o, cdl = tot - o;
2333
+ for (var i = 0; i < files.length; ++i) {
2334
+ var f = files[i];
2335
+ wzh(out, f.o, f, f.f, f.u, f.c.length);
2336
+ var badd = 30 + f.f.length + exfl(f.extra);
2337
+ out.set(f.c, f.o + badd);
2338
+ wzh(out, o, f, f.f, f.u, f.c.length, f.o, f.m), o += 16 + badd + (f.m ? f.m.length : 0);
2339
+ }
2340
+ wzf(out, o, files.length, cdl, oe);
2341
+ return out;
2342
+ }
2343
+ /**
2344
+ * Streaming pass-through decompression for ZIP archives
2345
+ */
2346
+ var UnzipPassThrough = /*#__PURE__*/ (function () {
2347
+ function UnzipPassThrough() {
2348
+ }
2349
+ UnzipPassThrough.prototype.push = function (chunk, final) {
2350
+ // same as ZipPassThrough: cast to retain Buffer ergonomics
2351
+ this.ondata(null, chunk, final);
2352
+ };
2353
+ UnzipPassThrough.compression = 0;
2354
+ return UnzipPassThrough;
2355
+ }());
2356
+ export { UnzipPassThrough };
2357
+ /**
2358
+ * Streaming DEFLATE decompression for ZIP archives. Prefer AsyncZipInflate for
2359
+ * better performance.
2360
+ */
2361
+ var UnzipInflate = /*#__PURE__*/ (function () {
2362
+ /**
2363
+ * Creates a DEFLATE decompression that can be used in ZIP archives
2364
+ */
2365
+ function UnzipInflate() {
2366
+ var _this = this;
2367
+ this.i = new Inflate(function (dat, final) {
2368
+ _this.ondata(null, dat, final);
2369
+ });
2370
+ }
2371
+ UnzipInflate.prototype.push = function (chunk, final) {
2372
+ try {
2373
+ this.i.push(chunk, final);
2374
+ }
2375
+ catch (e) {
2376
+ this.ondata(e, null, final);
2377
+ }
2378
+ };
2379
+ UnzipInflate.compression = 8;
2380
+ return UnzipInflate;
2381
+ }());
2382
+ export { UnzipInflate };
2383
+ /**
2384
+ * Asynchronous streaming DEFLATE decompression for ZIP archives
2385
+ */
2386
+ var AsyncUnzipInflate = /*#__PURE__*/ (function () {
2387
+ /**
2388
+ * Creates a DEFLATE decompression that can be used in ZIP archives
2389
+ */
2390
+ function AsyncUnzipInflate(_, sz) {
2391
+ var _this = this;
2392
+ if (sz < 320000) {
2393
+ this.i = new Inflate(function (dat, final) {
2394
+ _this.ondata(null, dat, final);
2395
+ });
2396
+ }
2397
+ else {
2398
+ this.i = new AsyncInflate(function (err, dat, final) {
2399
+ _this.ondata(err, dat, final);
2400
+ });
2401
+ this.terminate = this.i.terminate;
2402
+ }
2403
+ }
2404
+ AsyncUnzipInflate.prototype.push = function (chunk, final) {
2405
+ if (this.i.terminate)
2406
+ chunk = slc(chunk, 0);
2407
+ this.i.push(chunk, final);
2408
+ };
2409
+ AsyncUnzipInflate.compression = 8;
2410
+ return AsyncUnzipInflate;
2411
+ }());
2412
+ export { AsyncUnzipInflate };
2413
+ /**
2414
+ * A ZIP archive decompression stream that emits files as they are discovered
2415
+ */
2416
+ var Unzip = /*#__PURE__*/ (function () {
2417
+ /**
2418
+ * Creates a ZIP decompression stream
2419
+ * @param cb The callback to call whenever a file in the ZIP archive is found
2420
+ */
2421
+ function Unzip(cb) {
2422
+ this.onfile = cb;
2423
+ this.k = [];
2424
+ this.o = {
2425
+ 0: UnzipPassThrough
2426
+ };
2427
+ this.p = et;
2428
+ }
2429
+ /**
2430
+ * Pushes a chunk to be unzipped
2431
+ * @param chunk The chunk to push
2432
+ * @param final Whether this is the last chunk
2433
+ */
2434
+ Unzip.prototype.push = function (chunk, final) {
2435
+ var _this = this;
2436
+ if (!this.onfile)
2437
+ err(5);
2438
+ if (!this.p)
2439
+ err(4);
2440
+ if (this.c > 0) {
2441
+ var len = Math.min(this.c, chunk.length);
2442
+ var toAdd = chunk.subarray(0, len);
2443
+ this.c -= len;
2444
+ if (this.d)
2445
+ this.d.push(toAdd, !this.c);
2446
+ else
2447
+ this.k[0].push(toAdd);
2448
+ chunk = chunk.subarray(len);
2449
+ if (chunk.length)
2450
+ return this.push(chunk, final);
2451
+ }
2452
+ else {
2453
+ var f = 0, i = 0, is = void 0, buf = void 0;
2454
+ if (!this.p.length)
2455
+ buf = chunk;
2456
+ else if (!chunk.length)
2457
+ buf = this.p;
2458
+ else {
2459
+ buf = new u8(this.p.length + chunk.length);
2460
+ buf.set(this.p), buf.set(chunk, this.p.length);
2461
+ }
2462
+ var l = buf.length, oc = this.c, add = oc && this.d;
2463
+ var _loop_2 = function () {
2464
+ var sig = b4(buf, i);
2465
+ if (sig == 0x4034B50) {
2466
+ f = 1, is = i;
2467
+ this_1.d = null;
2468
+ this_1.c = 0;
2469
+ var bf = b2(buf, i + 6), cmp_1 = b2(buf, i + 8), u = bf & 2048, dd = bf & 8, fnl = b2(buf, i + 26), es = b2(buf, i + 28);
2470
+ if (l > i + 30 + fnl + es) {
2471
+ var chks_3 = [];
2472
+ this_1.k.unshift(chks_3);
2473
+ f = 2;
2474
+ var lsc = b4(buf, i + 18), lsu = b4(buf, i + 22);
2475
+ var fn_1 = strFromU8(buf.subarray(i + 30, i += 30 + fnl), !u);
2476
+ var _a = z64hs(buf, i, es, 2, lsc, lsu, 0), sc_1 = _a[0], su_1 = _a[1], z64 = _a[3];
2477
+ if (dd)
2478
+ sc_1 = -1 - z64;
2479
+ i += es;
2480
+ this_1.c = sc_1;
2481
+ var d_1;
2482
+ var file_1 = {
2483
+ name: fn_1,
2484
+ compression: cmp_1,
2485
+ start: function () {
2486
+ if (!file_1.ondata)
2487
+ err(5);
2488
+ if (!sc_1)
2489
+ file_1.ondata(null, et, true);
2490
+ else {
2491
+ var ctr = _this.o[cmp_1];
2492
+ if (!ctr)
2493
+ file_1.ondata(err(14, 'unknown compression type ' + cmp_1, 1), null, false);
2494
+ d_1 = sc_1 < 0 ? new ctr(fn_1) : new ctr(fn_1, sc_1, su_1);
2495
+ d_1.ondata = function (err, dat, final) { file_1.ondata(err, dat, final); };
2496
+ for (var _i = 0, chks_4 = chks_3; _i < chks_4.length; _i++) {
2497
+ var dat = chks_4[_i];
2498
+ d_1.push(dat, false);
2499
+ }
2500
+ if (_this.k[0] == chks_3 && _this.c)
2501
+ _this.d = d_1;
2502
+ else
2503
+ d_1.push(et, true);
2504
+ }
2505
+ },
2506
+ terminate: function () {
2507
+ if (d_1 && d_1.terminate)
2508
+ d_1.terminate();
2509
+ }
2510
+ };
2511
+ if (sc_1 >= 0)
2512
+ file_1.size = sc_1, file_1.originalSize = su_1;
2513
+ this_1.onfile(file_1);
2514
+ }
2515
+ return "break";
2516
+ }
2517
+ else if (oc) {
2518
+ if (sig == 0x8074B50) {
2519
+ is = i += 12 + (oc == -2 && 8), f = 3, this_1.c = 0;
2520
+ return "break";
2521
+ }
2522
+ else if (sig == 0x2014B50) {
2523
+ is = i -= 4, f = 3, this_1.c = 0;
2524
+ return "break";
2525
+ }
2526
+ }
2527
+ };
2528
+ var this_1 = this;
2529
+ for (; i < l - 4; ++i) {
2530
+ var state_1 = _loop_2();
2531
+ if (state_1 === "break")
2532
+ break;
2533
+ }
2534
+ this.p = et;
2535
+ if (oc < 0) {
2536
+ var dat = f ? buf.subarray(0, is - 12 - (oc == -2 && 8) - (b4(buf, is - 16) == 0x8074B50 && 4)) : buf.subarray(0, i);
2537
+ if (add)
2538
+ add.push(dat, !!f);
2539
+ else
2540
+ this.k[+(f == 2)].push(dat);
2541
+ }
2542
+ if (f & 2)
2543
+ return this.push(buf.subarray(i), final);
2544
+ this.p = buf.subarray(i);
2545
+ }
2546
+ if (final) {
2547
+ if (this.c)
2548
+ err(13);
2549
+ this.p = null;
2550
+ }
2551
+ };
2552
+ /**
2553
+ * Registers a decoder with the stream, allowing for files compressed with
2554
+ * the compression type provided to be expanded correctly
2555
+ * @param decoder The decoder constructor
2556
+ */
2557
+ Unzip.prototype.register = function (decoder) {
2558
+ this.o[decoder.compression] = decoder;
2559
+ };
2560
+ return Unzip;
2561
+ }());
2562
+ export { Unzip };
2563
+ var mt = typeof queueMicrotask == 'function' ? queueMicrotask : typeof setTimeout == 'function' ? setTimeout : function (fn) { fn(); };
2564
+ export function unzip(data, opts, cb) {
2565
+ if (!cb)
2566
+ cb = opts, opts = {};
2567
+ if (typeof cb != 'function')
2568
+ err(7);
2569
+ var term = [];
2570
+ var tAll = function () {
2571
+ for (var i = 0; i < term.length; ++i)
2572
+ term[i]();
2573
+ };
2574
+ var files = {};
2575
+ var cbd = function (a, b) {
2576
+ mt(function () { cb(a, b); });
2577
+ };
2578
+ mt(function () { cbd = cb; });
2579
+ var e = data.length - 22;
2580
+ for (; b4(data, e) != 0x6054B50; --e) {
2581
+ if (!e || data.length - e > 65558) {
2582
+ cbd(err(13, 0, 1), null);
2583
+ return tAll;
2584
+ }
2585
+ }
2586
+ ;
2587
+ var lft = b2(data, e + 8);
2588
+ if (lft) {
2589
+ var c = lft;
2590
+ var o = b4(data, e + 16);
2591
+ var z = b4(data, e - 20) == 0x7064B50;
2592
+ if (z) {
2593
+ var ze = b4(data, e - 12);
2594
+ z = b4(data, ze) == 0x6064B50;
2595
+ if (z) {
2596
+ c = lft = b4(data, ze + 32);
2597
+ o = b4(data, ze + 48);
2598
+ }
2599
+ }
2600
+ var fltr = opts && opts.filter;
2601
+ var _loop_3 = function (i) {
2602
+ var _a = zh(data, o, z), c_1 = _a[0], sc = _a[1], su = _a[2], fn = _a[3], no = _a[4], off = _a[5], b = slzh(data, off);
2603
+ o = no;
2604
+ var cbl = function (e, d) {
2605
+ if (e) {
2606
+ tAll();
2607
+ cbd(e, null);
2608
+ }
2609
+ else {
2610
+ if (d)
2611
+ files[fn] = d;
2612
+ if (!--lft)
2613
+ cbd(null, files);
2614
+ }
2615
+ };
2616
+ if (!fltr || fltr({
2617
+ name: fn,
2618
+ size: sc,
2619
+ originalSize: su,
2620
+ compression: c_1
2621
+ })) {
2622
+ if (!c_1)
2623
+ cbl(null, slc(data, b, b + sc));
2624
+ else if (c_1 == 8) {
2625
+ var infl = data.subarray(b, b + sc);
2626
+ // Synchronously decompress under 512KB, or barely-compressed data
2627
+ if (su < 524288 || sc > 0.8 * su) {
2628
+ try {
2629
+ cbl(null, inflateSync(infl, { out: new u8(su) }));
2630
+ }
2631
+ catch (e) {
2632
+ cbl(e, null);
2633
+ }
2634
+ }
2635
+ else
2636
+ term.push(inflate(infl, { size: su }, cbl));
2637
+ }
2638
+ else
2639
+ cbl(err(14, 'unknown compression type ' + c_1, 1), null);
2640
+ }
2641
+ else
2642
+ cbl(null, null);
2643
+ };
2644
+ for (var i = 0; i < c; ++i) {
2645
+ _loop_3(i);
2646
+ }
2647
+ }
2648
+ else
2649
+ cbd(null, {});
2650
+ return tAll;
2651
+ }
2652
+ /**
2653
+ * Synchronously decompresses a ZIP archive. Prefer using `unzip` for better
2654
+ * performance with more than one file.
2655
+ * @param data The raw compressed ZIP file
2656
+ * @param opts The ZIP extraction options
2657
+ * @returns The decompressed files
2658
+ */
2659
+ export function unzipSync(data, opts) {
2660
+ var files = {};
2661
+ var e = data.length - 22;
2662
+ for (; b4(data, e) != 0x6054B50; --e) {
2663
+ if (!e || data.length - e > 65558)
2664
+ err(13);
2665
+ }
2666
+ ;
2667
+ var c = b2(data, e + 8);
2668
+ if (!c)
2669
+ return {};
2670
+ var o = b4(data, e + 16);
2671
+ var z = b4(data, e - 20) == 0x7064B50;
2672
+ if (z) {
2673
+ var ze = b4(data, e - 12);
2674
+ z = b4(data, ze) == 0x6064B50;
2675
+ if (z) {
2676
+ c = b4(data, ze + 32);
2677
+ o = b4(data, ze + 48);
2678
+ }
2679
+ }
2680
+ var fltr = opts && opts.filter;
2681
+ for (var i = 0; i < c; ++i) {
2682
+ var _a = zh(data, o, z), c_2 = _a[0], sc = _a[1], su = _a[2], fn = _a[3], no = _a[4], off = _a[5], b = slzh(data, off);
2683
+ o = no;
2684
+ if (!fltr || fltr({
2685
+ name: fn,
2686
+ size: sc,
2687
+ originalSize: su,
2688
+ compression: c_2
2689
+ })) {
2690
+ if (!c_2)
2691
+ files[fn] = slc(data, b, b + sc);
2692
+ else if (c_2 == 8)
2693
+ files[fn] = inflateSync(data.subarray(b, b + sc), { out: new u8(su) });
2694
+ else
2695
+ err(14, 'unknown compression type ' + c_2);
2696
+ }
2697
+ }
2698
+ return files;
2699
+ }