anyfile-cli 0.2.0 → 0.2.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (111) hide show
  1. package/README.md +1 -2
  2. package/chunks/{chunk-5OI4NQH7.mjs → chunk-HI7TURZM.mjs} +27 -3
  3. package/chunks/{chunk-UUN2DVDC.mjs → chunk-IGEGIF35.mjs} +178 -37
  4. package/cli-main.mjs +24 -5
  5. package/index.mjs +2 -2
  6. package/package.json +2 -2
  7. package/renderer-host/assets/{amf-CLBaywBr.js → amf-BkE--DNX.js} +1 -1
  8. package/renderer-host/assets/{animation-DnPo99To.js → animation-Dt0WW2cB.js} +1 -1
  9. package/renderer-host/assets/{archive-client-CyhEmSF7.js → archive-client-CL5yOgwH.js} +1 -1
  10. package/renderer-host/assets/{book-worker-DrtzCzPo.js → book-worker-DUt14LJO.js} +1 -1
  11. package/renderer-host/assets/{client-Dp-p4unY.js → client-CU2ERPtk.js} +1 -1
  12. package/renderer-host/assets/container-inspection-ekEPWWcy.js +1 -0
  13. package/renderer-host/assets/decode-hBroL8C1.js +1 -0
  14. package/renderer-host/assets/{decode-tiff-BuYdKp6p.js → decode-tiff-CP1xdrF_.js} +3 -3
  15. package/renderer-host/assets/{dual-track-playback-lNQyU1GR.js → dual-track-playback-CxjGms-W.js} +1 -1
  16. package/renderer-host/assets/{ffmpeg-playback-QcT_NwlK.js → ffmpeg-playback-DzCJz9Ny.js} +1 -1
  17. package/renderer-host/assets/{gltf-Cqq-xStc.js → gltf-PozNLKNg.js} +1 -1
  18. package/renderer-host/assets/{image-load-B1fNI3iO.js → image-load-SK3ULGWm.js} +1 -1
  19. package/renderer-host/assets/index-DtiyOy_J.js +2 -0
  20. package/renderer-host/assets/{lerc-CRhfhhOS.js → lerc-Cuor-Zm2.js} +1 -1
  21. package/renderer-host/assets/{mediabunny-viewer-BnJM6Yo0.js → mediabunny-viewer-BniHVEWJ.js} +1 -1
  22. package/renderer-host/assets/{model-D2YSoRt5.js → model-Drd3vqcF.js} +1 -1
  23. package/renderer-host/assets/{obj-DbUZkDna.js → obj-B3p81LL2.js} +1 -1
  24. package/renderer-host/assets/{off-CzR_R_Tf.js → off-QQbiKPTX.js} +1 -1
  25. package/renderer-host/assets/{ogg-viewer-CT31JEhG.js → ogg-viewer-Dc8K-tas.js} +1 -1
  26. package/renderer-host/assets/{paged-CX-N_Pzy.js → paged-C8AQD7sX.js} +1 -1
  27. package/renderer-host/assets/{ply-C-xrhUaO.js → ply-C3_RRA7n.js} +1 -1
  28. package/renderer-host/assets/{probe-asf-CvcaYQaR.js → probe-asf-C_UpCBly.js} +1 -1
  29. package/renderer-host/assets/{range-reader-9PeAh1Hv.js → range-reader-BMfLhWcp.js} +1 -1
  30. package/renderer-host/assets/{resources-WcZvn3-C.js → resources-6AmS6O5e.js} +1 -1
  31. package/renderer-host/assets/{safe-content-B61Ktgzp.js → safe-content-CWHf8jex.js} +1 -1
  32. package/renderer-host/assets/{scene-adapter-CmaaVwsM.js → scene-adapter-CaCLr1am.js} +1 -1
  33. package/renderer-host/assets/{skp-adapter-ByI1iX8S.js → skp-adapter-jl6q24fW.js} +1 -1
  34. package/renderer-host/assets/{src-DZE9IoBl.js → src-1Won7FxU.js} +1 -1
  35. package/renderer-host/assets/{src-CXRrmfb0.js → src-3RoHqOkA.js} +1 -1
  36. package/renderer-host/assets/{src-vPHMg1Fp.js → src-4zBOL6Jt.js} +1 -1
  37. package/renderer-host/assets/{src-CGx0nUS5.js → src-6v8-hoR3.js} +1 -1
  38. package/renderer-host/assets/{src-D3OyeoQs.js → src-8Jx9gbII.js} +1 -1
  39. package/renderer-host/assets/{src-Bu1cTJNz.js → src-B1WA0dRu.js} +1 -1
  40. package/renderer-host/assets/{src-j_mEQ9Os.js → src-B5ijbemo.js} +2 -2
  41. package/renderer-host/assets/{src-efHN2oAJ.js → src-B8DH2GJe.js} +3 -3
  42. package/renderer-host/assets/{src-B_o7QilB.js → src-B9t_iEO3.js} +1 -1
  43. package/renderer-host/assets/{src-CIDWSV97.js → src-BCC58C0X.js} +1 -1
  44. package/renderer-host/assets/{src-lYIAi6Hw.js → src-BCwENs26.js} +1 -1
  45. package/renderer-host/assets/{src-ClIHDiJ4.js → src-BEirBh4c.js} +1 -1
  46. package/renderer-host/assets/{src-CeGmxOTi.js → src-BHR6n7Fj.js} +1 -1
  47. package/renderer-host/assets/{src-BMrLVJyB.js → src-BIlLq0QT.js} +3 -3
  48. package/renderer-host/assets/{src-C5k8Ydia.js → src-BKlK1jcN.js} +1 -1
  49. package/renderer-host/assets/{src-C_1M1IDo.js → src-BN0FUJhs.js} +1 -1
  50. package/renderer-host/assets/{src-BEn15PBT.js → src-BWElAdlq.js} +1 -1
  51. package/renderer-host/assets/{src-QXdjrTaw.js → src-BXg11IjY.js} +1 -1
  52. package/renderer-host/assets/{src-BwZAUudm.js → src-BbBdnTjJ.js} +2 -2
  53. package/renderer-host/assets/{src-Bw-O8ujJ.js → src-BbFZbZsL.js} +2 -2
  54. package/renderer-host/assets/{src-DPm7_lsi.js → src-BdPbFRd-.js} +1 -1
  55. package/renderer-host/assets/{src-C2LKqLBA.js → src-BpbGaBrT.js} +1 -1
  56. package/renderer-host/assets/{src-DmzigsPg.js → src-BwIl76_H.js} +1 -1
  57. package/renderer-host/assets/{src-CHNgoDf9.js → src-C2e6QJIj.js} +1 -1
  58. package/renderer-host/assets/{src-Cyw_3X-L.js → src-C2gNidHF.js} +1 -1
  59. package/renderer-host/assets/{src-CBE5sqjl.js → src-CBUhG6W5.js} +1 -1
  60. package/renderer-host/assets/{src-Cvb3aCDG.js → src-CQDGi3Qa.js} +1 -1
  61. package/renderer-host/assets/{src-CBo2yHRk.js → src-CRLCRg0N.js} +1 -1
  62. package/renderer-host/assets/{src-Q-oKL3Dw.js → src-CS5rqxBy.js} +1 -1
  63. package/renderer-host/assets/{src-DrYYfoQO.js → src-CWZdSJQw.js} +1 -1
  64. package/renderer-host/assets/{src-B0zJlB0C.js → src-CXnpsVpU.js} +1 -1
  65. package/renderer-host/assets/{src-C4t_UvT8.js → src-CnhXvqQY.js} +1 -1
  66. package/renderer-host/assets/{src-CPUYqpHZ.js → src-CpExg0ZA.js} +1 -1
  67. package/renderer-host/assets/{src-C_HAB_bn.js → src-CrLmL3wU.js} +1 -1
  68. package/renderer-host/assets/{src-2X3Gt6Lk.js → src-CrYEJ5uz.js} +2 -2
  69. package/renderer-host/assets/{src-CifsQr3m.js → src-D-iIkSqZ.js} +1 -1
  70. package/renderer-host/assets/{src-p14e1hma.js → src-D6sH9uTT.js} +1 -1
  71. package/renderer-host/assets/{src-BPG8SYXq.js → src-D8zHDJh_.js} +1 -1
  72. package/renderer-host/assets/{src-D4cv_-u0.js → src-D9OFaPNV.js} +1 -1
  73. package/renderer-host/assets/{src-9k3CCYnZ.js → src-DCI_ff7c.js} +1 -1
  74. package/renderer-host/assets/{src-BB6xj1UK.js → src-DCrbiTpH.js} +1 -1
  75. package/renderer-host/assets/{src-TbSq3WSr.js → src-DK8DvtMd.js} +1 -1
  76. package/renderer-host/assets/{src-eVKtGm4Q.js → src-DWGlOVjt.js} +1 -1
  77. package/renderer-host/assets/{src-DpEmkhrn.js → src-DbvEX_Ct.js} +1 -1
  78. package/renderer-host/assets/{src-Ck1ekdEN.js → src-Dezc2dj1.js} +1 -1
  79. package/renderer-host/assets/{src-TuTvYAR6.js → src-Dh5VD1lL.js} +1 -1
  80. package/renderer-host/assets/{src-BydeR01n.js → src-DlwABqw5.js} +1 -1
  81. package/renderer-host/assets/{src-0QHjkpy0.js → src-DlxETlTh.js} +1 -1
  82. package/renderer-host/assets/{src-R4bKlaNn.js → src-Dmd6BvBh.js} +1 -1
  83. package/renderer-host/assets/{src-BuN3y1yE.js → src-DpgvaJNJ.js} +1 -1
  84. package/renderer-host/assets/{src-C6w9FGSB.js → src-DpjRB2sv.js} +1 -1
  85. package/renderer-host/assets/{src-Blx9jp9x.js → src-Dvn41FR7.js} +1 -1
  86. package/renderer-host/assets/{src-CVc67mQv.js → src-DwcPYp7X.js} +1 -1
  87. package/renderer-host/assets/{src-BZrNtUNO.js → src-HUxhcDlO.js} +1 -1
  88. package/renderer-host/assets/{src-ORHZWeVF.js → src-Jhqg3J8L.js} +2 -2
  89. package/renderer-host/assets/{src-DsVDi0pr.js → src-MO5bLsLj.js} +1 -1
  90. package/renderer-host/assets/{src-n2gsf381.js → src-N8XBQaK4.js} +1 -1
  91. package/renderer-host/assets/{src-BgUXah8O.js → src-XZ_0U972.js} +1 -1
  92. package/renderer-host/assets/{src-5ZJshveh.js → src-Y6mXl4vh.js} +3 -3
  93. package/renderer-host/assets/{src-B4jorJ2U.js → src-b9aXVJde.js} +1 -1
  94. package/renderer-host/assets/{src-CAdKRH5C.js → src-d2U6neq8.js} +1 -1
  95. package/renderer-host/assets/{src-Bl5Lv4-d.js → src-jUGjKzOV.js} +1 -1
  96. package/renderer-host/assets/{src-BgM1jpe4.js → src-vOBd-1zk.js} +1 -1
  97. package/renderer-host/assets/{src-0DTp6SF8.js → src-yCrAObB-.js} +1 -1
  98. package/renderer-host/assets/{src-BLndk63N.js → src-zrBiCtay.js} +1 -1
  99. package/renderer-host/assets/{stl-adapter-D1eozFH9.js → stl-adapter-CLkWHoOn.js} +1 -1
  100. package/renderer-host/assets/{three-mf-CbcWWdM8.js → three-mf-BSrcsdQD.js} +1 -1
  101. package/renderer-host/assets/{webm-_wYh_V7u.js → webm-14HHwfWy.js} +1 -1
  102. package/renderer-host/assets/{zip-core-base-CDv8KjIR.js → zip-core-base-DD8akpjq.js} +1 -1
  103. package/renderer-host/assets/zip-core-custom-CfPFs1lw.js +1 -0
  104. package/renderer-host/assets/{zip-source-C5dFTDt7.js → zip-source-CLF3Hfcg.js} +1 -1
  105. package/renderer-host/index.html +1 -1
  106. package/worker.mjs +3 -2
  107. package/renderer-host/assets/container-inspection-DZoaDYQR.js +0 -1
  108. package/renderer-host/assets/decode-D5vB6JN8.js +0 -1
  109. package/renderer-host/assets/index-BCxD9rBl.js +0 -2
  110. package/renderer-host/assets/src-2tfD0huT.js +0 -16
  111. package/renderer-host/assets/zip-core-custom-D3VVVj-J.js +0 -1
@@ -1,5 +1,5 @@
1
- const __vite__mapDeps=(i,m=__vite__mapDeps,d=(m.f||(m.f=["assets/raw-A-vJRPpa.js","assets/basedecoder-BuG7fe0q.js","assets/lzw-D2FslT4L.js","assets/jpeg-AGQ46WDa.js","assets/deflate-DPjr4M2G.js","assets/pako.esm-CtVA0R7W.js","assets/packbits-DCimUQ1T.js","assets/lerc-CRhfhhOS.js","assets/rolldown-runtime-Dd_uD5pT.js","assets/zstd-i4Jwubnx.js","assets/webimage-zQMH-_zR.js"])))=>i.map(i=>d[i]);
2
- import"./rolldown-runtime-Dd_uD5pT.js";import{a as e,r as t}from"./index-BCxD9rBl.js";var n={BYTE:1,ASCII:2,SHORT:3,LONG:4,RATIONAL:5,SBYTE:6,UNDEFINED:7,SSHORT:8,SLONG:9,SRATIONAL:10,FLOAT:11,DOUBLE:12,IFD:13,LONG8:16,SLONG8:17,IFD8:18},r={[n.BYTE]:1,[n.ASCII]:1,[n.SBYTE]:1,[n.UNDEFINED]:1,[n.SHORT]:2,[n.SSHORT]:2,[n.LONG]:4,[n.SLONG]:4,[n.FLOAT]:4,[n.IFD]:4,[n.RATIONAL]:8,[n.SRATIONAL]:8,[n.DOUBLE]:8,[n.LONG8]:8,[n.SLONG8]:8,[n.IFD8]:8};function i(e){let t=r[e];if(t===void 0)throw RangeError(`Invalid field type: ${e}`);return t}var a={NewSubfileType:{tag:254,type:n.LONG,eager:!0},SubfileType:{tag:255,type:n.SHORT,eager:!0},ImageWidth:{tag:256,type:n.SHORT,eager:!0},ImageLength:{tag:257,type:n.SHORT,eager:!0},BitsPerSample:{tag:258,type:n.SHORT,isArray:!0,eager:!0},Compression:{tag:259,type:n.SHORT,eager:!0},PhotometricInterpretation:{tag:262,type:n.SHORT,eager:!0},Threshholding:{tag:263,type:n.SHORT},CellWidth:{tag:264,type:n.SHORT},CellLength:{tag:265,type:n.SHORT},FillOrder:{tag:266,type:n.SHORT},DocumentName:{tag:269,type:n.ASCII},ImageDescription:{tag:270,type:n.ASCII},Make:{tag:271,type:n.ASCII},Model:{tag:272,type:n.ASCII},StripOffsets:{tag:273,type:n.SHORT,isArray:!0},Orientation:{tag:274,type:n.SHORT},SamplesPerPixel:{tag:277,type:n.SHORT,eager:!0},RowsPerStrip:{tag:278,type:n.SHORT,eager:!0},StripByteCounts:{tag:279,type:n.LONG,isArray:!0},MinSampleValue:{tag:280,type:n.SHORT,isArray:!0},MaxSampleValue:{tag:281,type:n.SHORT,isArray:!0},XResolution:{tag:282,type:n.RATIONAL},YResolution:{tag:283,type:n.RATIONAL},PlanarConfiguration:{tag:284,type:n.SHORT,eager:!0},PageName:{tag:285,type:n.ASCII},XPosition:{tag:286,type:n.RATIONAL},YPosition:{tag:287,type:n.RATIONAL},FreeOffsets:{tag:288,type:n.LONG},FreeByteCounts:{tag:289,type:n.LONG},GrayResponseUnit:{tag:290,type:n.SHORT},GrayResponseCurve:{tag:291,type:n.SHORT,isArray:!0},T4Options:{tag:292,type:n.LONG},T6Options:{tag:293,type:n.LONG},ResolutionUnit:{tag:296,type:n.SHORT},PageNumber:{tag:297,type:n.SHORT,isArray:!0},TransferFunction:{tag:301,type:n.SHORT,isArray:!0},Software:{tag:305,type:n.ASCII},DateTime:{tag:306,type:n.ASCII},Artist:{tag:315,type:n.ASCII},HostComputer:{tag:316,type:n.ASCII},Predictor:{tag:317,type:n.SHORT},WhitePoint:{tag:318,type:n.RATIONAL,isArray:!0},PrimaryChromaticities:{tag:319,type:n.RATIONAL,isArray:!0},ColorMap:{tag:320,type:n.SHORT,isArray:!0},HalftoneHints:{tag:321,type:n.SHORT,isArray:!0},TileWidth:{tag:322,type:n.SHORT,eager:!0},TileLength:{tag:323,type:n.SHORT,eager:!0},TileOffsets:{tag:324,type:n.LONG,isArray:!0},TileByteCounts:{tag:325,type:n.SHORT,isArray:!0},InkSet:{tag:332,type:n.SHORT},InkNames:{tag:333,type:n.ASCII},NumberOfInks:{tag:334,type:n.SHORT},DotRange:{tag:336,type:n.BYTE,isArray:!0},TargetPrinter:{tag:337,type:n.ASCII},ExtraSamples:{tag:338,type:n.BYTE,isArray:!0,eager:!0},SampleFormat:{tag:339,type:n.SHORT,isArray:!0,eager:!0},SMinSampleValue:{tag:340,isArray:!0},SMaxSampleValue:{tag:341,isArray:!0},TransferRange:{tag:342,type:n.SHORT,isArray:!0},JPEGProc:{tag:512,type:n.SHORT},JPEGInterchangeFormat:{tag:513,type:n.LONG},JPEGInterchangeFormatLngth:{tag:514,type:n.LONG},JPEGRestartInterval:{tag:515,type:n.SHORT},JPEGLosslessPredictors:{tag:517,type:n.SHORT,isArray:!0},JPEGPointTransforms:{tag:518,type:n.SHORT,isArray:!0},JPEGQTables:{tag:519,type:n.LONG,isArray:!0},JPEGDCTables:{tag:520,type:n.LONG,isArray:!0},JPEGACTables:{tag:521,type:n.LONG,isArray:!0},YCbCrCoefficients:{tag:529,type:n.RATIONAL,isArray:!0},YCbCrSubSampling:{tag:530,type:n.SHORT,isArray:!0},YCbCrPositioning:{tag:531,type:n.SHORT},ReferenceBlackWhite:{tag:532,type:n.LONG,isArray:!0},Copyright:{tag:33432,type:n.ASCII},BadFaxLines:{tag:326},CleanFaxData:{tag:327},ClipPath:{tag:343},ConsecutiveBadFaxLines:{tag:328},Decode:{tag:433},DefaultImageColor:{tag:434},Indexed:{tag:346},JPEGTables:{tag:347,isArray:!0,eager:!0},StripRowCounts:{tag:559,isArray:!0},SubIFDs:{tag:330,isArray:!0},XClipPathUnits:{tag:344},YClipPathUnits:{tag:345},ApertureValue:{tag:37378},ColorSpace:{tag:40961},DateTimeDigitized:{tag:36868},DateTimeOriginal:{tag:36867},ExifIFD:{tag:34665,name:`Exif IFD`,type:n.LONG},ExifVersion:{tag:36864},ExposureTime:{tag:33434},FileSource:{tag:41728},Flash:{tag:37385},FlashpixVersion:{tag:40960},FNumber:{tag:33437},ImageUniqueID:{tag:42016},LightSource:{tag:37384},MakerNote:{tag:37500},ShutterSpeedValue:{tag:37377},UserComment:{tag:37510},IPTC:{tag:33723},CZ_LSMINFO:{tag:34412},ICCProfile:{tag:34675,name:`ICC Profile`},XMP:{tag:700},GDAL_METADATA:{tag:42112},GDAL_NODATA:{tag:42113,type:n.ASCII,eager:!0},Photoshop:{tag:34377},ModelPixelScale:{tag:33550,type:n.DOUBLE,isArray:!0,eager:!0},ModelTiepoint:{tag:33922,type:n.DOUBLE,isArray:!0,eager:!0},ModelTransformation:{tag:34264,type:n.DOUBLE,isArray:!0,eager:!0},GeoKeyDirectory:{tag:34735,type:n.SHORT,isArray:!0,eager:!0},GeoDoubleParams:{tag:34736,type:n.DOUBLE,isArray:!0,eager:!0},GeoAsciiParams:{tag:34737,type:n.ASCII,eager:!0},LercParameters:{tag:50674,eager:!0}},o={},s={};function c(e,t,r,i=!1,a=!1){o[t]=e,s[e]={tag:e,name:t,type:typeof r==`string`?n[r]:r,isArray:i,eager:a}}for(let[e,t]of Object.entries(a)){let n=t;c(n.tag,n.name||e,n.type,n.isArray,n.eager)}function l(e){return typeof e==`number`?e:o[e]}var u={WhiteIsZero:0,BlackIsZero:1,RGB:2,Palette:3,TransparencyMask:4,CMYK:5,YCbCr:6,CIELab:8,ICCLab:9},d={Unspecified:0,Assocalpha:1,Unassalpha:2},f={Version:0,AddCompression:1},p={None:0,Deflate:1,Zstandard:2},m={1024:`GTModelTypeGeoKey`,1025:`GTRasterTypeGeoKey`,1026:`GTCitationGeoKey`,2048:`GeographicTypeGeoKey`,2049:`GeogCitationGeoKey`,2050:`GeogGeodeticDatumGeoKey`,2051:`GeogPrimeMeridianGeoKey`,2052:`GeogLinearUnitsGeoKey`,2053:`GeogLinearUnitSizeGeoKey`,2054:`GeogAngularUnitsGeoKey`,2055:`GeogAngularUnitSizeGeoKey`,2056:`GeogEllipsoidGeoKey`,2057:`GeogSemiMajorAxisGeoKey`,2058:`GeogSemiMinorAxisGeoKey`,2059:`GeogInvFlatteningGeoKey`,2060:`GeogAzimuthUnitsGeoKey`,2061:`GeogPrimeMeridianLongGeoKey`,2062:`GeogTOWGS84GeoKey`,3072:`ProjectedCSTypeGeoKey`,3073:`PCSCitationGeoKey`,3074:`ProjectionGeoKey`,3075:`ProjCoordTransGeoKey`,3076:`ProjLinearUnitsGeoKey`,3077:`ProjLinearUnitSizeGeoKey`,3078:`ProjStdParallel1GeoKey`,3079:`ProjStdParallel2GeoKey`,3080:`ProjNatOriginLongGeoKey`,3081:`ProjNatOriginLatGeoKey`,3082:`ProjFalseEastingGeoKey`,3083:`ProjFalseNorthingGeoKey`,3084:`ProjFalseOriginLongGeoKey`,3085:`ProjFalseOriginLatGeoKey`,3086:`ProjFalseOriginEastingGeoKey`,3087:`ProjFalseOriginNorthingGeoKey`,3088:`ProjCenterLongGeoKey`,3089:`ProjCenterLatGeoKey`,3090:`ProjCenterEastingGeoKey`,3091:`ProjCenterNorthingGeoKey`,3092:`ProjScaleAtNatOriginGeoKey`,3093:`ProjScaleAtCenterGeoKey`,3094:`ProjAzimuthAngleGeoKey`,3095:`ProjStraightVertPoleLongGeoKey`,3096:`ProjRectifiedGridAngleGeoKey`,4096:`VerticalCSTypeGeoKey`,4097:`VerticalCitationGeoKey`,4098:`VerticalDatumGeoKey`,4099:`VerticalUnitsGeoKey`},h={};for(let[e,t]of Object.entries(m))h[t]=parseInt(e,10);function g(e){return(t,...n)=>v(e,t,n)}function _(e,t){return g(S(e,t).get)}var{apply:v,construct:y,defineProperty:b,get:x,getOwnPropertyDescriptor:S,getPrototypeOf:C,has:w,ownKeys:T,set:ee,setPrototypeOf:te}=Reflect,{EPSILON:ne,MAX_SAFE_INTEGER:re,isFinite:ie,isNaN:ae}=Number,{iterator:E,species:oe,toStringTag:se,for:ce}=Symbol,D=Object,{create:O,defineProperty:le,freeze:ue,is:de}=D,k=D.prototype;k.__lookupGetter__&&k.__lookupGetter__,D.hasOwn||k.hasOwnProperty;var fe=Array;fe.isArray;var A=fe.prototype;A.join,A.push,A.toLocaleString;var pe=A[E],me=g(pe),{abs:he,trunc:ge}=Math,j=ArrayBuffer;j.isView;var _e=j.prototype;_e.slice,_(_e,`byteLength`);var ve=typeof SharedArrayBuffer<`u`?SharedArrayBuffer:null;ve&&_(ve.prototype,`byteLength`);var ye=C(Uint8Array);ye.from;var M=ye.prototype;M[E],M.keys,M.values,M.entries,M.set,M.reverse,M.fill,M.copyWithin,M.sort,M.slice,M.subarray,_(M,`buffer`),_(M,`byteOffset`),_(M,`length`),_(M,se);var be=Uint8Array,xe=Uint16Array,N=Uint32Array,Se=Float32Array,P=C([][E]()),Ce=g(P.next),we=g((function*(){})().next),Te=C(P),Ee=DataView.prototype,De=g(Ee.getUint16);Ee.setUint16;var Oe=WeakSet.prototype;Oe.add,Oe.has;var F=WeakMap,I=F.prototype,ke=g(I.get);I.has;var Ae=g(I.set),je=new F,Me=O(null,{next:{value:function(){return Ce(ke(je,this))}},[E]:{value:function(){return this}}});function Ne(e){if(e[E]===pe&&P.next===Ce)return e;let t=O(Me);return Ae(je,t,me(e)),t}var Pe=new F,Fe=O(Te,{next:{value:function(){return we(ke(Pe,this))},writable:!0,configurable:!0}});for(let e of T(P))e!==`next`&&le(Fe,e,S(P,e));var Ie=1/ne,Le=6103515625e-14,Re=.0009765625;Re*Le,Re*Ie;var ze=new j(4),Be=new Se(ze),Ve=new N(ze),L=new xe(512),R=new be(512);for(let e=0;e<256;++e){let t=e-127;t<-24?(L[e]=0,L[e|256]=32768,R[e]=24,R[e|256]=24):t<-14?(L[e]=1024>>-t-14,L[e|256]=1024>>-t-14|32768,R[e]=-t-1,R[e|256]=-t-1):t<=15?(L[e]=t+15<<10,L[e|256]=t+15<<10|32768,R[e]=13,R[e|256]=13):t<128?(L[e]=31744,L[e|256]=64512,R[e]=24,R[e|256]=24):(L[e]=31744,L[e|256]=64512,R[e]=13,R[e|256]=13)}var z=new N(2048);for(let e=1;e<1024;++e){let t=e<<13,n=0;for(;!(t&8388608);)t<<=1,n-=8388608;t&=-8388609,n+=947912704,z[e]=t|n}for(let e=1024;e<2048;++e)z[e]=939524096+(e-1024<<13);var B=new N(64);for(let e=1;e<31;++e)B[e]=e<<23;B[31]=1199570944,B[32]=2147483648;for(let e=33;e<63;++e)B[e]=2147483648+(e-32<<23);B[63]=3347054592;var He=new xe(64);for(let e=1;e<64;++e)e!==32&&(He[e]=1024);function Ue(e){let t=e>>10;return Ve[0]=z[He[t]+(e&1023)]+B[t],Be[0]}function We(e,t,...n){return Ue(De(e,t,...Ne(n)))}function Ge(e,t,n){let r=n&&n.debug||!1;r&&console.log(`[xml-utils] getting `+t+` in `+e);let i=typeof e==`object`?e.outer:e,a=i.slice(0,i.indexOf(`>`)+1),o=[`"`,`'`];for(let e=0;e<o.length;e++){let n=o[e],i=t+`\\=`+n+`([^`+n+`]*)`+n;r&&console.log(`[xml-utils] pattern:`,i);let s=new RegExp(i).exec(a);if(r&&console.log(`[xml-utils] match:`,s),s)return s[1]}}function Ke(e,t,n){let r=new RegExp(t).exec(e.slice(n));return r?n+r.index:-1}function V(e,t,n){let r=new RegExp(t).exec(e.slice(n));return r?n+r.index+r[0].length-1:-1}function qe(e,t){let n=new RegExp(t,`g`),r=e.match(n);return r?r.length:0}function Je(e,t,n){let r=n&&n.debug||!1,i=!(n&&typeof n.nested===!1),a=n&&n.startIndex||0;r&&console.log(`[xml-utils] starting findTagByName with`,t,` and `,n);let o=Ke(e,`\<${t}[ \n\>\/]`,a);if(r&&console.log(`[xml-utils] start:`,o),o===-1)return;let s=e.slice(o+t.length),c=V(s,`^[^<]*[ /]>`,0),l=c!==-1&&s[c-1]===`/`;if(r&&console.log(`[xml-utils] selfClosing:`,l),l===!1){if(i){let e=0,n=1,r=0;for(;(c=V(s,`[ /]`+t+`>`,e))!==-1;){let i=s.substring(e,c+1);if(n+=qe(i,`<`+t+`[
3
- >]`),r+=qe(i,`</`+t+`>`),r>=n)break;e=c}}else c=V(s,`[ /]`+t+`>`,0)}let u=o+t.length+c+1;if(r&&console.log(`[xml-utils] end:`,u),u===-1)return;let d=e.slice(o,u),f;return f=l?null:d.slice(d.indexOf(`>`)+1,d.lastIndexOf(`<`)),{inner:f,outer:d,start:o,end:u}}function Ye(e,t,n){let r=[],i=n&&n.debug||!1,a=n&&typeof n.nested==`boolean`?n.nested:!0,o=n&&n.startIndex||0,s;for(;s=Je(e,t,{debug:i,startIndex:o});)o=a?s.start+1+t.length:s.end,r.push(s);return i&&console.log(`findTagsByName found`,r.length,`tags`),r}function Xe(e,t){let{width:n,height:r}=e,i=new Uint8Array(n*r*3),a;for(let n=0,r=0;n<e.length;++n,r+=3)a=256-e[n]/t*256,i[r]=a,i[r+1]=a,i[r+2]=a;return i}function Ze(e,t){let{width:n,height:r}=e,i=new Uint8Array(n*r*3),a;for(let n=0,r=0;n<e.length;++n,r+=3)a=e[n]/t*256,i[r]=a,i[r+1]=a,i[r+2]=a;return i}function Qe(e,t){let{width:n,height:r}=e,i=new Uint8Array(n*r*3),a=t.length/3,o=t.length/3*2;for(let n=0,r=0;n<e.length;++n,r+=3){let s=e[n];i[r]=t[s]/65536*256,i[r+1]=t[s+a]/65536*256,i[r+2]=t[s+o]/65536*256}return i}function $e(e){let{width:t,height:n}=e,r=new Uint8Array(t*n*3);for(let t=0,n=0;t<e.length;t+=4,n+=3){let i=e[t],a=e[t+1],o=e[t+2],s=e[t+3];r[n]=255*((255-i)/256)*((255-s)/256),r[n+1]=255*((255-a)/256)*((255-s)/256),r[n+2]=255*((255-o)/256)*((255-s)/256)}return r}function et(e){let{width:t,height:n}=e,r=new Uint8ClampedArray(t*n*3);for(let t=0,n=0;t<e.length;t+=3,n+=3){let i=e[t],a=e[t+1],o=e[t+2];r[n]=i+1.402*(o-128),r[n+1]=i-.34414*(a-128)-.71414*(o-128),r[n+2]=i+1.772*(a-128)}return r}var tt=.95047,nt=1,rt=1.08883;function it(e){let{width:t,height:n}=e,r=new Uint8Array(t*n*3);for(let t=0,n=0;t<e.length;t+=3,n+=3){let i=e[t+0],a=e[t+1]<<24>>24,o=e[t+2]<<24>>24,s=(i+16)/116,c=a/500+s,l=s-o/200,u,d,f;c=tt*(c*c*c>.008856?c*c*c:(c-16/116)/7.787),s=nt*(s*s*s>.008856?s*s*s:(s-16/116)/7.787),l=rt*(l*l*l>.008856?l*l*l:(l-16/116)/7.787),u=c*3.2406+s*-1.5372+l*-.4986,d=c*-.9689+s*1.8758+l*.0415,f=c*.0557+s*-.204+l*1.057,u=u>.0031308?1.055*u**(1/2.4)-.055:12.92*u,d=d>.0031308?1.055*d**(1/2.4)-.055:12.92*d,f=f>.0031308?1.055*f**(1/2.4)-.055:12.92*f,r[n]=Math.max(0,Math.min(1,u))*255,r[n+1]=Math.max(0,Math.min(1,d))*255,r[n+2]=Math.max(0,Math.min(1,f))*255}return r}var H=new Map;async function U(e){let t=!e.hasTag(`StripOffsets`);return{tileWidth:t?await e.loadValue(`TileWidth`):await e.loadValue(`ImageWidth`),tileHeight:t?await e.loadValue(`TileLength`):await e.loadValue(`RowsPerStrip`)||await e.loadValue(`ImageLength`),planarConfiguration:await e.loadValue(`PlanarConfiguration`),bitsPerSample:await e.loadValue(`BitsPerSample`),predictor:await e.loadValue(`Predictor`)||1}}function at(e,t,n=U,r=!0){Array.isArray(e)||(e=[e]),e.forEach(e=>{H.set(e,{importFn:t,decoderParameterFn:n,preferWorker:r})})}async function ot(e,t){if(!H.has(e))throw Error(`Unknown compression method identifier: ${e}`);let{decoderParameterFn:n}=H.get(e);return n(t)}async function st(e,t){if(!H.has(e))throw Error(`Unknown compression method identifier: ${e}`);let{importFn:n}=H.get(e);return new(await(n()))(t)}var ct=[{cases:[void 0,1],importFn:()=>t(()=>import(`./raw-A-vJRPpa.js`).then(e=>e.default),__vite__mapDeps([0,1])),preferWorker:!1},{cases:5,importFn:()=>t(()=>import(`./lzw-D2FslT4L.js`).then(e=>e.default),__vite__mapDeps([2,1]))},{cases:6,importFn:()=>{throw Error(`old style JPEG compression is not supported.`)}},{cases:7,importFn:()=>t(()=>import(`./jpeg-AGQ46WDa.js`).then(e=>e.default),__vite__mapDeps([3,1])),decoderParameterFn:async e=>({...await U(e),JPEGTables:await e.loadValue(`JPEGTables`)})},{cases:[8,32946],importFn:()=>t(()=>import(`./deflate-DPjr4M2G.js`).then(e=>e.default),__vite__mapDeps([4,5,1]))},{cases:32773,importFn:()=>t(()=>import(`./packbits-DCimUQ1T.js`).then(e=>e.default),__vite__mapDeps([6,1]))},{cases:34887,importFn:()=>t(()=>import(`./lerc-CRhfhhOS.js`).then(async e=>(await e.zstd.init(),e)),__vite__mapDeps([7,8,5,1])).then(e=>e.default),decoderParameterFn:async e=>({...await U(e),LercParameters:await e.loadValue(`LercParameters`)})},{cases:5e4,importFn:()=>t(()=>import(`./zstd-i4Jwubnx.js`).then(async e=>(await e.zstd.init(),e)),__vite__mapDeps([9,1])).then(e=>e.default)},{cases:50001,importFn:()=>t(()=>import(`./webimage-zQMH-_zR.js`).then(e=>e.default),__vite__mapDeps([10,1])),decoderParameterFn:async e=>({...await U(e),samplesPerPixel:Number(await e.loadValue(`SamplesPerPixel`))||4}),preferWorker:!1}];for(let e of ct){let{cases:t,importFn:n,decoderParameterFn:r,preferWorker:i}=e;at(t,n,r,i)}function W(e,t,n,r=1){return new(Object.getPrototypeOf(e)).constructor(t*n*r)}function lt(e,t,n,r,i){let a=t/r,o=n/i;return e.map(e=>{let s=W(e,r,i);for(let c=0;c<i;++c){let i=Math.min(Math.round(o*c),n-1);for(let n=0;n<r;++n){let o=Math.min(Math.round(a*n),t-1),l=e[i*t+o];s[c*r+n]=l}}return s})}function G(e,t,n){return(1-n)*e+n*t}function ut(e,t,n,r,i){let a=t/r,o=n/i;return e.map(e=>{let s=W(e,r,i);for(let c=0;c<i;++c){let i=o*c,l=Math.floor(i),u=Math.min(Math.ceil(i),n-1);for(let n=0;n<r;++n){let o=a*n,d=o%1,f=Math.floor(o),p=Math.min(Math.ceil(o),t-1),m=e[l*t+f],h=e[l*t+p],g=e[u*t+f],_=e[u*t+p],v=G(G(m,h,d),G(g,_,d),i%1);s[c*r+n]=v}}return s})}function dt(e,t,n,r,i,a=`nearest`){switch(a.toLowerCase()){case`nearest`:return lt(e,t,n,r,i);case`bilinear`:case`linear`:return ut(e,t,n,r,i);default:throw Error(`Unsupported resampling method: '${a}'`)}}function ft(e,t,n,r,i,a){let o=t/r,s=n/i,c=W(e,r,i,a);for(let l=0;l<i;++l){let i=Math.min(Math.round(s*l),n-1);for(let n=0;n<r;++n){let s=Math.min(Math.round(o*n),t-1);for(let o=0;o<a;++o){let u=e[i*t*a+s*a+o];c[l*r*a+n*a+o]=u}}}return c}function pt(e,t,n,r,i,a){let o=t/r,s=n/i,c=W(e,r,i,a);for(let l=0;l<i;++l){let i=s*l,u=Math.floor(i),d=Math.min(Math.ceil(i),n-1);for(let n=0;n<r;++n){let s=o*n,f=s%1,p=Math.floor(s),m=Math.min(Math.ceil(s),t-1);for(let o=0;o<a;++o){let s=e[u*t*a+p*a+o],h=e[u*t*a+m*a+o],g=e[d*t*a+p*a+o],_=e[d*t*a+m*a+o],v=G(G(s,h,f),G(g,_,f),i%1);c[l*r*a+n*a+o]=v}}}return c}function mt(e,t,n,r,i,a,o=`nearest`){switch(o.toLowerCase()){case`nearest`:return ft(e,t,n,r,i,a);case`bilinear`:case`linear`:return pt(e,t,n,r,i,a);default:throw Error(`Unsupported resampling method: '${o}'`)}}function ht(e,t,n){let r=0;for(let i=t;i<n;++i)r+=e[i];return r}function K(e,t,n){let r;switch(e){case 1:t<=8?r=Uint8Array:t<=16?r=Uint16Array:t<=32&&(r=Uint32Array);break;case 2:t===8?r=Int8Array:t===16?r=Int16Array:t===32&&(r=Int32Array);break;case 3:switch(t){case 16:case 32:r=Float32Array;break;case 64:r=Float64Array}}if(r&&(typeof n==`number`||n instanceof ArrayBuffer))return new r(n);throw Error(`Unsupported data format/bitsPerSample`)}function gt(e,t){return(e===1||e===2)&&t<=32&&t%8==0?!1:e!==3||t!==16&&t!==32&&t!==64}function _t(e,t,n,r,i,a,o){let s=new DataView(e),c=n===2?o*a:o*a*r,l=n===2?1:r,u=K(t,i,c),d=parseInt(`1`.repeat(i),2);if(t===1){let e;e=n===1?r*i:i;let t=a*e;t&7&&(t=t+7&-8);for(let e=0;e<o;++e){let n=e*t;for(let t=0;t<a;++t){let r=n+t*l*i;for(let n=0;n<l;++n){let o=r+n*i,c=(e*a+t)*l+n,f=Math.floor(o/8),p=o%8;u[c]=p+i<=8?s.getUint8(f)>>8-i-p&d:p+i<=16?s.getUint16(f)>>16-i-p&d:p+i<=24?(s.getUint16(f)<<8|s.getUint8(f+2))>>24-i-p&d:s.getUint32(f)>>32-i-p&d}}}}return u.buffer}var vt=class{constructor(e,t,n,r){this.fileDirectory=e,this.littleEndian=t,this.tiles=n?[]:null,this.isTiled=!e.hasTag(`StripOffsets`);let i=e.getValue(`PlanarConfiguration`)??1;if(i!==1&&i!==2)throw Error(`Invalid planar configuration.`);this.planarConfiguration=i,this.source=r}getFileDirectory(){return this.fileDirectory}getGeoKeys(){return this.fileDirectory.parseGeoKeyDirectory()}getWidth(){return this.fileDirectory.getValue(`ImageWidth`)||0}getHeight(){return this.fileDirectory.getValue(`ImageLength`)||0}getSamplesPerPixel(){return this.fileDirectory.getValue(`SamplesPerPixel`)??1}getTileWidth(){return this.isTiled?this.fileDirectory.getValue(`TileWidth`)||0:this.getWidth()}getTileHeight(){if(this.isTiled)return this.fileDirectory.getValue(`TileLength`)||0;let e=this.fileDirectory.hasTag(`RowsPerStrip`)&&this.fileDirectory.getValue(`RowsPerStrip`);return e?Math.min(e,this.getHeight()):this.getHeight()}getBlockWidth(){return this.getTileWidth()}getBlockHeight(e){return this.isTiled||(e+1)*this.getTileHeight()<=this.getHeight()?this.getTileHeight():this.getHeight()-e*this.getTileHeight()}getBytesPerPixel(){let e=0,t=this.fileDirectory.getValue(`BitsPerSample`)||[];for(let n=0;n<t.length;++n)e+=this.getSampleByteSize(n);return e}getSampleByteSize(e){let t=this.fileDirectory.getValue(`BitsPerSample`)||[];if(e>=t.length)throw RangeError(`Sample index ${e} is out of range.`);return Math.ceil(t[e]/8)}getReaderForSample(e){let t=this.fileDirectory.getValue(`SampleFormat`),n=t?t[e]:1,r=(this.fileDirectory.getValue(`BitsPerSample`)||[])[e];switch(n){case 1:if(r<=8)return DataView.prototype.getUint8;if(r<=16)return DataView.prototype.getUint16;if(r<=32)return DataView.prototype.getUint32;break;case 2:if(r<=8)return DataView.prototype.getInt8;if(r<=16)return DataView.prototype.getInt16;if(r<=32)return DataView.prototype.getInt32;break;case 3:switch(r){case 16:return function(e,t){return We(this,e,t)};case 32:return DataView.prototype.getFloat32;case 64:return DataView.prototype.getFloat64}}throw Error(`Unsupported data format/bitsPerSample`)}getSampleFormat(e=0){let t=this.fileDirectory.getValue(`SampleFormat`);return t?t[e]:1}getBitsPerSample(e=0){let t=this.fileDirectory.getValue(`BitsPerSample`);return t?t[e]:0}getArrayForSample(e,t){return K(this.getSampleFormat(e),this.getBitsPerSample(e),t)}async getTileOrStrip(e,t,n,r,i){let a=Math.ceil(this.getWidth()/this.getTileWidth()),o=Math.ceil(this.getHeight()/this.getTileHeight()),s,{tiles:c}=this;if(this.planarConfiguration===1?s=t*a+e:this.planarConfiguration===2&&(s=n*a*o+t*a+e),s===void 0)throw Error(`Could not determine tile or strip index.`);let l,u;if(this.isTiled?(l=Number(await this.fileDirectory.loadValueIndexed(`TileOffsets`,s)),u=Number(await this.fileDirectory.loadValueIndexed(`TileByteCounts`,s))):(l=Number(await this.fileDirectory.loadValueIndexed(`StripOffsets`,s)),u=Number(await this.fileDirectory.loadValueIndexed(`StripByteCounts`,s))),u===0){let r=this.getBlockHeight(t)*this.getTileWidth(),i=this.planarConfiguration===2?this.getSampleByteSize(n):this.getBytesPerPixel(),a=new ArrayBuffer(r*i);return this.getArrayForSample(n,a).fill(this.getGDALNoData()||0),{x:e,y:t,sample:n,data:a}}let d=(await this.source.fetch([{offset:l,length:u}],i))[0],f;return c===null||!c[s]?(f=(async()=>{let e=await r.decode(d),n=this.getSampleFormat(),i=this.getBitsPerSample();return gt(n,i)&&(e=_t(e,n,this.planarConfiguration,this.getSamplesPerPixel(),i,this.getTileWidth(),this.getBlockHeight(t))),e})(),c!==null&&(c[s]=f)):f=c[s],{x:e,y:t,sample:n,data:await f}}async _readRaster(e,t,n,r,i,a,o,s,c){let l=this.getTileWidth(),u=this.getTileHeight(),d=this.getWidth(),f=this.getHeight(),p=Math.max(Math.floor(e[0]/l),0),m=Math.min(Math.ceil(e[2]/l),Math.ceil(d/l)),h=Math.max(Math.floor(e[1]/u),0),g=Math.min(Math.ceil(e[3]/u),Math.ceil(f/u)),_=e[2]-e[0],v=this.getBytesPerPixel(),y=[],b=[];for(let e=0;e<t.length;++e){if(this.planarConfiguration===1){let n=await this.fileDirectory.loadValue(`BitsPerSample`);if(typeof n!=`object`)throw Error(`Expected BitsPerSample to be an array or typed array.`);y.push(ht(n,0,t[e])/8)}else y.push(0);b.push(this.getReaderForSample(t[e]))}let x=[],{littleEndian:S}=this;for(let a=h;a<g;++a)for(let o=p;o<m;++o){let s;this.planarConfiguration===1&&(s=this.getTileOrStrip(o,a,0,i,c));for(let p=0;p<t.length;++p){let m=p,h=t[p];if(this.planarConfiguration===2&&(v=this.getSampleByteSize(h),s=this.getTileOrStrip(o,a,h,i,c)),!s)throw Error(`Could not get tile or strip data.`);let g=s.then(i=>{let a=i.data,o=new DataView(a),s=this.getBlockHeight(i.y),c=i.y*u,p=i.x*l,h=c+s,g=(i.x+1)*l,x=b[m],C=Math.min(s,s-(h-e[3]),f-c),w=Math.min(l,l-(g-e[2]),d-p);for(let i=Math.max(0,e[1]-c);i<C;++i)for(let a=Math.max(0,e[0]-p);a<w;++a){let s=(i*l+a)*v,u=x.call(o,s+y[m],S),d;r?(d=(i+c-e[1])*_*t.length+(a+p-e[0])*t.length+m,n[d]=u):(d=(i+c-e[1])*_+a+p-e[0],n[m][d]=u)}});x.push(g)}}if(await Promise.all(x),a&&e[2]-e[0]!==a||o&&e[3]-e[1]!==o){let i;i=r?mt(n,e[2]-e[0],e[3]-e[1],a,o,t.length,s):dt(n,e[2]-e[0],e[3]-e[1],a,o,s);let c=i;return c.width=a??e[2]-e[0],c.height=o??e[3]-e[1],c}let C=n;return C.width=a||e[2]-e[0],C.height=o||e[3]-e[1],C}async readRasters(e={}){let{window:t,samples:n=[],pool:r=null,width:i,height:a,resampleMethod:o,fillValue:s,signal:c}=e,l=`interleave`in e&&e.interleave,u=t||[0,0,this.getWidth(),this.getHeight()];if(u[0]>u[2]||u[1]>u[3])throw Error(`Invalid subsets`);let d=(u[2]-u[0])*(u[3]-u[1]),f=this.getSamplesPerPixel();if(!n||!n.length)for(let e=0;e<f;++e)n.push(e);else for(let e=0;e<n.length;++e)if(n[e]>=f)return Promise.reject(RangeError(`Invalid sample index '${n[e]}'.`));let p;if(l){let{fileDirectory:e}=this,t=e.getValue(`SampleFormat`),r=t?Math.max.apply(null,Array.from(t)):1;if(r!==1&&r!==2&&r!==3)throw Error(`Unsupported sample format for interleaved data. Must be 1, 2, or 3.`);let i=e.getValue(`BitsPerSample`);if(p=K(r,i?Math.max.apply(null,Array.from(i)):8,d*n.length),s){if(Array.isArray(s))throw Error(`When reading interleaved data, fillValue must be a single number.`);p.fill(s)}}else{p=[];for(let e=0;e<n.length;++e){let t=this.getArrayForSample(n[e],d);Array.isArray(s)&&e<s.length?t.fill(s[e]):s&&!Array.isArray(s)&&t.fill(s),p.push(t)}}let m=this.fileDirectory.getValue(`Compression`)||1,h=await ot(m,this.fileDirectory),g=r?r.bindParameters(m,h):await st(m,h);return await this._readRaster(u,n,p,l,g,i,a,o,c)}async readRGB(e={}){let{window:t,pool:n=null,width:r,height:i,resampleMethod:a,enableAlpha:o=!1,signal:s}=e,c=(`interleave`in e&&e.interleave)??!1,l=t||[0,0,this.getWidth(),this.getHeight()];if(l[0]>l[2]||l[1]>l[3])throw Error(`Invalid subsets`);let f=this.fileDirectory.getValue(`PhotometricInterpretation`);if(f===u.RGB){let e=[0,1,2],l=this.fileDirectory.getValue(`ExtraSamples`);if(l&&l[0]!==d.Unspecified&&o){e=[];let t=this.fileDirectory.getValue(`BitsPerSample`)||[];for(let n=0;n<t.length;n+=1)e.push(n)}return this.readRasters({window:t,interleave:c,samples:e,pool:n,width:r,height:i,resampleMethod:a,signal:s})}let p;switch(f){case u.WhiteIsZero:case u.BlackIsZero:case u.Palette:p=[0];break;case u.CMYK:p=[0,1,2,3];break;case u.YCbCr:case u.CIELab:p=[0,1,2];break;default:throw Error(`Invalid or unsupported photometric interpretation.`)}let m={window:l,interleave:!0,samples:p,pool:n,width:r,height:i,resampleMethod:a,signal:s},{fileDirectory:h}=this,g=await this.readRasters(m),_=2**this.getBitsPerSample(0),v;switch(f){case u.WhiteIsZero:v=Xe(g,_);break;case u.BlackIsZero:v=Ze(g,_);break;case u.Palette:v=Qe(g,await h.loadValue(`ColorMap`));break;case u.CMYK:v=$e(g);break;case u.YCbCr:v=et(g);break;case u.CIELab:v=it(g);break;default:throw Error(`Unsupported photometric interpretation.`)}if(!c){let e=new Uint8Array(v.length/3),t=new Uint8Array(v.length/3),n=new Uint8Array(v.length/3);for(let r=0,i=0;r<v.length;r+=3,++i)e[i]=v[r],t[i]=v[r+1],n[i]=v[r+2];v=[e,t,n]}let y=v;return y.width=g.width,y.height=g.height,y}async getTiePoints(){if(!this.fileDirectory.hasTag(`ModelTiepoint`))return[];let e=await this.fileDirectory.loadValue(`ModelTiepoint`);if(typeof e!=`object`)throw Error(`Expected ModelTiepoint to be an array or typed array.`);let t=[];for(let n=0;n<e.length;n+=6)t.push({i:e[n],j:e[n+1],k:e[n+2],x:e[n+3],y:e[n+4],z:e[n+5]});return t}async getGDALMetadata(e=null){let t={};if(!this.fileDirectory.hasTag(`GDAL_METADATA`))return null;let n=Ye(await this.fileDirectory.loadValue(`GDAL_METADATA`),`Item`);n=e===null?n.filter(e=>Ge(e,`sample`)===void 0):n.filter(t=>Number(Ge(t,`sample`))===e);for(let e=0;e<n.length;++e){let r=n[e];t[Ge(r,`name`)]=r.inner}return t}getGDALNoData(){let e=this.fileDirectory.hasTag(`GDAL_NODATA`)&&this.fileDirectory.getValue(`GDAL_NODATA`);return e?Number(e.substring(0,e.length-1)):null}getOrigin(){let e=this.fileDirectory.getValue(`ModelTiepoint`),t=this.fileDirectory.getValue(`ModelTransformation`);if(e&&e.length===6)return[e[3],e[4],e[5]];if(t)return[t[3],t[7],t[11]];throw Error(`The image does not have an affine transformation.`)}getResolution(e=null){let t=this.fileDirectory.getValue(`ModelPixelScale`),n=this.fileDirectory.getValue(`ModelTransformation`);if(t)return[t[0],-t[1],t[2]];if(n)return n[1]===0&&n[4]===0?[n[0],-n[5],n[10]]:[Math.sqrt(n[0]*n[0]+n[4]*n[4]),-Math.sqrt(n[1]*n[1]+n[5]*n[5]),n[10]];if(e){let[t,n,r]=e.getResolution();return[t*e.getWidth()/this.getWidth(),n*e.getHeight()/this.getHeight(),r*e.getWidth()/this.getWidth()]}throw Error(`The image does not have an affine transformation.`)}pixelIsArea(){return this.getGeoKeys()?.GTRasterTypeGeoKey===1}getBoundingBox(e=!1){let t=this.getHeight(),n=this.getWidth(),r=this.fileDirectory.getValue(`ModelTransformation`);if(r&&!e){let[e,i,,a,o,s,,c]=r,l=[[0,0],[0,t],[n,0],[n,t]].map(([t,n])=>[a+e*t+i*n,c+o*t+s*n]),u=l.map(e=>e[0]),d=l.map(e=>e[1]);return[Math.min(...u),Math.min(...d),Math.max(...u),Math.max(...d)]}{let e=this.getOrigin(),r=this.getResolution(),i=e[0],a=e[1],o=i+r[0]*n,s=a+r[1]*t;return[Math.min(i,o),Math.min(a,s),Math.max(i,o),Math.max(a,s)]}}},yt=class{constructor(e){this._dataView=new DataView(e)}get buffer(){return this._dataView.buffer}getUint64(e,t){let n=this.getUint32(e,t),r=this.getUint32(e+4,t),i;if(t){if(i=n+2**32*r,!Number.isSafeInteger(i))throw Error(`${i} exceeds MAX_SAFE_INTEGER. Precision may be lost. Please report if you get this message to https://github.com/geotiffjs/geotiff.js/issues`);return i}if(i=2**32*n+r,!Number.isSafeInteger(i))throw Error(`${i} exceeds MAX_SAFE_INTEGER. Precision may be lost. Please report if you get this message to https://github.com/geotiffjs/geotiff.js/issues`);return i}getInt64(e,t){let n=0,r=(this._dataView.getUint8(e+(t?7:0))&128)>0,i=!0;for(let a=0;a<8;a++){let o=this._dataView.getUint8(e+(t?a:7-a));r&&(i?o!==0&&(o=~(o-1)&255,i=!1):o=~o&255),n+=o*256**a}return r&&(n=-n),n}getUint8(e){return this._dataView.getUint8(e)}getInt8(e){return this._dataView.getInt8(e)}getUint16(e,t){return this._dataView.getUint16(e,t)}getInt16(e,t){return this._dataView.getInt16(e,t)}getUint32(e,t){return this._dataView.getUint32(e,t)}getInt32(e,t){return this._dataView.getInt32(e,t)}getFloat16(e,t){return We(this._dataView,e,t)}getFloat32(e,t){return this._dataView.getFloat32(e,t)}getFloat64(e,t){return this._dataView.getFloat64(e,t)}},q=class{constructor(e,t,n,r){this._dataView=new DataView(e),this._sliceOffset=t,this._littleEndian=n,this._bigTiff=r}get sliceOffset(){return this._sliceOffset}get sliceTop(){return this._sliceOffset+this.buffer.byteLength}get littleEndian(){return this._littleEndian}get bigTiff(){return this._bigTiff}get buffer(){return this._dataView.buffer}covers(e,t){return this.sliceOffset<=e&&this.sliceTop>=e+t}readUint8(e){return this._dataView.getUint8(e-this._sliceOffset)}readInt8(e){return this._dataView.getInt8(e-this._sliceOffset)}readUint16(e){return this._dataView.getUint16(e-this._sliceOffset,this._littleEndian)}readInt16(e){return this._dataView.getInt16(e-this._sliceOffset,this._littleEndian)}readUint32(e){return this._dataView.getUint32(e-this._sliceOffset,this._littleEndian)}readInt32(e){return this._dataView.getInt32(e-this._sliceOffset,this._littleEndian)}readFloat32(e){return this._dataView.getFloat32(e-this._sliceOffset,this._littleEndian)}readFloat64(e){return this._dataView.getFloat64(e-this._sliceOffset,this._littleEndian)}readUint64(e){let t=this.readUint32(e),n=this.readUint32(e+4),r;if(this._littleEndian){if(r=t+2**32*n,!Number.isSafeInteger(r))throw Error(`${r} exceeds MAX_SAFE_INTEGER. Precision may be lost. Please report if you get this message to https://github.com/geotiffjs/geotiff.js/issues`);return r}if(r=2**32*t+n,!Number.isSafeInteger(r))throw Error(`${r} exceeds MAX_SAFE_INTEGER. Precision may be lost. Please report if you get this message to https://github.com/geotiffjs/geotiff.js/issues`);return r}readInt64(e){let t=0,n=(this._dataView.getUint8(e+(this._littleEndian?7:0))&128)>0,r=!0;for(let i=0;i<8;i++){let a=this._dataView.getUint8(e+(this._littleEndian?i:7-i));n&&(r?a!==0&&(a=~(a-1)&255,r=!1):a=~a&255),t+=a*256**i}return n&&(t=-t),t}readOffset(e){return this._bigTiff?this.readUint64(e):this.readUint32(e)}},bt=class{async fetch(e,t){return Promise.all(e.map(async e=>(await this.fetchSlice(e,t)).data))}async fetchSlice(e,t){throw Error(`fetching of slice ${e} not possible, not implemented`)}get fileSize(){return null}async close(){}},xt=class extends bt{constructor(e){super(),this.file=e}async fetchSlice(e,t){return new Promise((n,r)=>{let i=this.file.slice(e.offset,e.offset+e.length),a=new FileReader;a.onload=()=>n({data:a.result,offset:e.offset,length:e.length}),a.onerror=r,a.onabort=r,a.readAsArrayBuffer(i),t&&t.addEventListener(`abort`,()=>a.abort())})}};function St(e){return new xt(e)}function J(e,t){switch(e){case n.BYTE:case n.ASCII:case n.UNDEFINED:return new Uint8Array(t);case n.SBYTE:return new Int8Array(t);case n.SHORT:return new Uint16Array(t);case n.SSHORT:return new Int16Array(t);case n.LONG:case n.IFD:return new Uint32Array(t);case n.SLONG:return new Int32Array(t);case n.LONG8:case n.IFD8:return Array(t);case n.SLONG8:return Array(t);case n.RATIONAL:return new Uint32Array(t*2);case n.SRATIONAL:return new Int32Array(t*2);case n.FLOAT:return new Float32Array(t);case n.DOUBLE:return new Float64Array(t);default:throw RangeError(`Invalid field type: ${e}`)}}function Y(e,t){switch(t){case n.BYTE:case n.ASCII:case n.UNDEFINED:return e.readUint8;case n.SBYTE:return e.readInt8;case n.SHORT:return e.readUint16;case n.SSHORT:return e.readInt16;case n.LONG:case n.IFD:return e.readUint32;case n.SLONG:return e.readInt32;case n.LONG8:case n.IFD8:return e.readUint64;case n.SLONG8:return e.readInt64;case n.RATIONAL:return e.readUint32;case n.SRATIONAL:return e.readInt32;case n.FLOAT:return e.readFloat32;case n.DOUBLE:return e.readFloat64;default:throw RangeError(`Invalid field type: ${t}`)}}function X(e=null,t,r,a,o,s,c=!1){let l=i(a),u=e||J(a,o),d=a===n.RATIONAL||a===n.SRATIONAL;if(d)for(let e=0;e<o;e+=2)u[e]=t.call(r,s+e*l),u[e+1]=t.call(r,s+(e*l+4));else for(let e=0;e<o;++e)u[e]=t.call(r,s+e*l);return a===n.ASCII?new TextDecoder(`utf-8`).decode(u):o===1&&!c&&!d?u[0]:u}var Ct=class{constructor(e,t,n,r,a){this.source=e,this.arrayOffset=t,this.littleEndian=n,this.fieldType=r,this.length=a,this.data=J(r,a),this.itemSize=i(r),this.maskBitmap=new Uint8Array(Math.ceil(a/8)),this.fetchIndexPromises=new Map,this.fullFetchPromise=null}async loadAll(){return this.fullFetchPromise||=this.source.fetch([{offset:this.arrayOffset,length:this.itemSize*this.length}]).then(e=>{let t=new q(e[0],this.arrayOffset,!0,!1),n=X(this.data,Y(t,this.fieldType),t,this.fieldType,this.length,this.arrayOffset,!0);return this.maskBitmap.fill(255),this.fetchIndexPromises.clear(),n}),this.fullFetchPromise}async get(e){if(e<0||e>=this.data.length)throw RangeError(`Index ${e} out of bounds for length ${this.data.length}`);let t=Math.floor(e/8),n=1<<e%8,r=this.arrayOffset+e*this.itemSize;if((this.maskBitmap[t]&n)===0){if(!this.fetchIndexPromises.has(e)){let i=this.source.fetch([{offset:r,length:this.itemSize}]).then(i=>{let a=new q(i[0],this.arrayOffset+e*this.itemSize,!0,!1),o=Y(a,this.fieldType).call(a,r);return this.data[e]=o,this.maskBitmap[t]|=n,this.fetchIndexPromises.delete(e),o});this.fetchIndexPromises.set(e,i)}return this.fetchIndexPromises.get(e)}return this.data[e]}},wt=class{constructor(e,t,n,r){this.actualizedFields=e,this.deferredFields=t,this.deferredFieldsBeingResolved=new Map,this.deferredArrays=n,this.nextIFDByteOffset=r}hasTag(e){let t=l(e);return this.actualizedFields.has(t)||this.deferredFields.has(t)||this.deferredArrays.has(t)}getValue(e){let t=l(e);if(this.deferredFields.has(t)||this.deferredArrays.has(t)){let e=s[t]?.name||`Tag${t}`;throw Error(`Field '${e}' (${t}) is deferred. Use loadValue() to load it asynchronously.`)}if(this.actualizedFields.has(t))return this.actualizedFields.get(t)}async loadValue(e){let t=l(e);if(this.actualizedFields.has(t))return this.actualizedFields.get(t);if(this.deferredFieldsBeingResolved.has(t))return this.deferredFieldsBeingResolved.get(t);let n=this.deferredFields.get(t);if(n){this.deferredFields.delete(t);let e=(async()=>{try{let e=await n();return this.actualizedFields.set(t,e),e}finally{this.deferredFieldsBeingResolved.delete(t)}})();return this.deferredFieldsBeingResolved.set(t,e),e}let r=this.deferredArrays.get(t);if(r)return r.loadAll()}async loadValueIndexed(e,t){let n=l(e);if(this.actualizedFields.has(n))return this.actualizedFields.get(n)[t];if(this.deferredArrays.has(n))return this.deferredArrays.get(n).get(t);if(this.hasTag(n)){let e=await this.loadValue(n);if(e&&typeof e!=`number`)return e[t]}}parseGeoKeyDirectory(){let e=this.getValue(`GeoKeyDirectory`);if(!e)return null;let t={};for(let n=4;n<=e[3]*4;n+=4){let r=m[e[n]],i=e[n+1]||null,a=e[n+2],o=e[n+3],s=null;if(!i)s=o;else{if(s=this.getValue(i),s==null)throw Error(`Could not get value of geoKey '${r}'.`);typeof s==`string`?s=s.substring(o,o+a-1):s.subarray&&(s=s.subarray(o,o+a),a===1&&(s=s[0]))}t[r]=s}return t}toObject(){let e={};for(let[t,n]of this.actualizedFields.entries()){let r=typeof t==`number`?s[t]:void 0,i=r?r.name:`Tag${t}`;e[i]=n}return e}},Tt=class{constructor(e,t,n,r=!1){this.source=e,this.littleEndian=t,this.bigTiff=n,this.eager=r}async getSlice(e,t){let n=this.bigTiff?4048:1024;return new q((await this.source.fetch([{offset:e,length:t===void 0?n:t}]))[0],e,this.littleEndian,this.bigTiff)}async parseFileDirectoryAt(e){let t=this.bigTiff?20:12,n=this.bigTiff?8:2,r=await this.getSlice(e),a=this.bigTiff?r.readUint64(e):r.readUint16(e),o=a*(t+(this.bigTiff?16:6));r.covers(e,o)||(r=await this.getSlice(e,o));let c=new Map,l=new Map,u=new Map,d=e+(this.bigTiff?8:2);for(let e=0;e<a;d+=t,++e){let e=r.readUint16(d),t=r.readUint16(d+2),n=this.bigTiff?r.readUint64(d+4):r.readUint32(d+4),a=null,o=null,f=null,p=i(t),m=d+(this.bigTiff?12:8),h=s[e]?.isArray,g=s[e]?.eager||this.eager;if(p*n<=(this.bigTiff?8:4))a=X(J(t,n),Y(r,t),r,t,n,m,h);else{let e=r.readOffset(m),s=i(t)*n;if(r.covers(e,s))a=X(J(t,n),Y(r,t),r,t,n,e,h);else if(g){let r=await this.getSlice(e,s);a=X(J(t,n),Y(r,t),r,t,n,e,h)}else h?f=new Ct(this.source,e,this.littleEndian,t,n):o=async()=>{let r=await this.getSlice(e,s);return X(J(t,n),Y(r,t),r,t,n,e,h)}}a===null?o===null?f!==null&&u.set(e,f):l.set(e,o):c.set(e,a)}return new wt(c,l,u,r.readOffset(e+n+t*a))}};function Z(e,t,r,a){let o=null,s=null,c=i(t);switch(t){case n.BYTE:case n.ASCII:case n.UNDEFINED:o=new Uint8Array(r),s=e.readUint8;break;case n.SBYTE:o=new Int8Array(r),s=e.readInt8;break;case n.SHORT:o=new Uint16Array(r),s=e.readUint16;break;case n.SSHORT:o=new Int16Array(r),s=e.readInt16;break;case n.LONG:case n.IFD:o=new Uint32Array(r),s=e.readUint32;break;case n.SLONG:o=new Int32Array(r),s=e.readInt32;break;case n.LONG8:case n.IFD8:o=Array(r),s=e.readUint64;break;case n.SLONG8:o=Array(r),s=e.readInt64;break;case n.RATIONAL:o=new Uint32Array(r*2),s=e.readUint32;break;case n.SRATIONAL:o=new Int32Array(r*2),s=e.readInt32;break;case n.FLOAT:o=new Float32Array(r),s=e.readFloat32;break;case n.DOUBLE:o=new Float64Array(r),s=e.readFloat64}if(o===null||s===null)throw RangeError(`Invalid field type: ${t}`);if(t!==n.RATIONAL&&t!==n.SRATIONAL)for(let t=0;t<r;++t)o[t]=s.call(e,a+t*c);else for(let t=0;t<r;t+=2)o[t]=s.call(e,a+t*c),o[t+1]=s.call(e,a+(t*c+4));return t===n.ASCII?new TextDecoder(`utf-8`).decode(o):o}var Q=class extends Error{constructor(e){super(`No image at index ${e}`),this.index=e}},Et=class{async getImage(e=0){throw Error(`Not implemented`)}async getImageCount(){throw Error(`Not implemented`)}async readRasters(e={}){let{window:t,width:n,height:r}=e,{resX:i,resY:a,bbox:o}=e,s=await this.getImage(),c=s,l=await this.getImageCount(),u=s.getBoundingBox();if(t&&o)throw Error(`Both "bbox" and "window" passed.`);if(n||r){if(t){let[e,n]=s.getOrigin(),[r,i]=s.getResolution();o=[e+t[0]*r,n+t[1]*i,e+t[2]*r,n+t[3]*i]}let e=o||u;if(n){if(i)throw Error(`Both width and resX passed`);i=(e[2]-e[0])/n}if(r){if(a)throw Error(`Both width and resY passed`);a=(e[3]-e[1])/r}}if(i||a){let e=[];for(let t=0;t<l;++t){let n=await this.getImage(t),r=n.fileDirectory.getValue(`SubfileType`),i=n.fileDirectory.getValue(`NewSubfileType`);(t===0||r===2||(i||0)&1)&&e.push(n)}e.sort((e,t)=>e.getWidth()-t.getWidth());for(let t=0;t<e.length;++t){let n=e[t],r=(u[2]-u[0])/n.getWidth(),o=(u[3]-u[1])/n.getHeight();if(c=n,i&&i>r||a&&a>o)break}}let d=t;if(o){let[e,t]=s.getOrigin(),[n,r]=c.getResolution(s);d=[Math.round((o[0]-e)/n),Math.round((o[1]-t)/r),Math.round((o[2]-e)/n),Math.round((o[3]-t)/r)],d=[Math.min(d[0],d[2]),Math.min(d[1],d[3]),Math.max(d[0],d[2]),Math.max(d[1],d[3])]}return c.readRasters({...e,window:d})}},Dt=class e extends Et{constructor(e,t,n,r,i={}){super(),this.source=e,this.parser=new Tt(e,t,n,!1),this.littleEndian=t,this.bigTiff=n,this.firstIFDOffset=r,this.cache=i.cache||!1,this.ifdRequests=[],this.ghostValues=null}async getSlice(e,t){let n=this.bigTiff?4048:1024;return new q((await this.source.fetch([{offset:e,length:t===void 0?n:t}]))[0],e,this.littleEndian,this.bigTiff)}async requestIFD(e){if(this.ifdRequests[e])return this.ifdRequests[e];if(e===0)return this.ifdRequests[e]=this.parser.parseFileDirectoryAt(this.firstIFDOffset),this.ifdRequests[e];if(!this.ifdRequests[e-1])try{this.ifdRequests[e-1]=this.requestIFD(e-1)}catch(t){throw t instanceof Q?new Q(e):t}return this.ifdRequests[e]=(async()=>{let t=this.ifdRequests[e-1];if(!t)throw Error(`Previous IFD request missing`);let n=await t;if(n.nextIFDByteOffset===0)throw new Q(e);return this.parser.parseFileDirectoryAt(n.nextIFDByteOffset)})(),this.ifdRequests[e]}async getImage(e=0){return new vt(await this.requestIFD(e),this.littleEndian,this.cache,this.source)}async getImageCount(){let e=0,t=!0;for(;t;)try{await this.requestIFD(e),++e}catch(e){if(e instanceof Q)t=!1;else throw e}return e}async getGhostValues(){let e=this.bigTiff?16:8;if(this.ghostValues!==null)return this.ghostValues;let t=await this.getSlice(e,130);if(Z(t,n.ASCII,30,e)===`GDAL_STRUCTURAL_METADATA_SIZE=`){let r=Z(t,n.ASCII,130,e).split(`
1
+ const __vite__mapDeps=(i,m=__vite__mapDeps,d=(m.f||(m.f=["assets/raw-A-vJRPpa.js","assets/basedecoder-BuG7fe0q.js","assets/lzw-D2FslT4L.js","assets/jpeg-AGQ46WDa.js","assets/deflate-DPjr4M2G.js","assets/pako.esm-CtVA0R7W.js","assets/packbits-DCimUQ1T.js","assets/lerc-Cuor-Zm2.js","assets/rolldown-runtime-Dd_uD5pT.js","assets/zstd-i4Jwubnx.js","assets/webimage-zQMH-_zR.js"])))=>i.map(i=>d[i]);
2
+ import"./rolldown-runtime-Dd_uD5pT.js";import{a as e,r as t}from"./index-DtiyOy_J.js";var n={BYTE:1,ASCII:2,SHORT:3,LONG:4,RATIONAL:5,SBYTE:6,UNDEFINED:7,SSHORT:8,SLONG:9,SRATIONAL:10,FLOAT:11,DOUBLE:12,IFD:13,LONG8:16,SLONG8:17,IFD8:18},r={[n.BYTE]:1,[n.ASCII]:1,[n.SBYTE]:1,[n.UNDEFINED]:1,[n.SHORT]:2,[n.SSHORT]:2,[n.LONG]:4,[n.SLONG]:4,[n.FLOAT]:4,[n.IFD]:4,[n.RATIONAL]:8,[n.SRATIONAL]:8,[n.DOUBLE]:8,[n.LONG8]:8,[n.SLONG8]:8,[n.IFD8]:8};function i(e){let t=r[e];if(t===void 0)throw RangeError(`Invalid field type: ${e}`);return t}var a={NewSubfileType:{tag:254,type:n.LONG,eager:!0},SubfileType:{tag:255,type:n.SHORT,eager:!0},ImageWidth:{tag:256,type:n.SHORT,eager:!0},ImageLength:{tag:257,type:n.SHORT,eager:!0},BitsPerSample:{tag:258,type:n.SHORT,isArray:!0,eager:!0},Compression:{tag:259,type:n.SHORT,eager:!0},PhotometricInterpretation:{tag:262,type:n.SHORT,eager:!0},Threshholding:{tag:263,type:n.SHORT},CellWidth:{tag:264,type:n.SHORT},CellLength:{tag:265,type:n.SHORT},FillOrder:{tag:266,type:n.SHORT},DocumentName:{tag:269,type:n.ASCII},ImageDescription:{tag:270,type:n.ASCII},Make:{tag:271,type:n.ASCII},Model:{tag:272,type:n.ASCII},StripOffsets:{tag:273,type:n.SHORT,isArray:!0},Orientation:{tag:274,type:n.SHORT},SamplesPerPixel:{tag:277,type:n.SHORT,eager:!0},RowsPerStrip:{tag:278,type:n.SHORT,eager:!0},StripByteCounts:{tag:279,type:n.LONG,isArray:!0},MinSampleValue:{tag:280,type:n.SHORT,isArray:!0},MaxSampleValue:{tag:281,type:n.SHORT,isArray:!0},XResolution:{tag:282,type:n.RATIONAL},YResolution:{tag:283,type:n.RATIONAL},PlanarConfiguration:{tag:284,type:n.SHORT,eager:!0},PageName:{tag:285,type:n.ASCII},XPosition:{tag:286,type:n.RATIONAL},YPosition:{tag:287,type:n.RATIONAL},FreeOffsets:{tag:288,type:n.LONG},FreeByteCounts:{tag:289,type:n.LONG},GrayResponseUnit:{tag:290,type:n.SHORT},GrayResponseCurve:{tag:291,type:n.SHORT,isArray:!0},T4Options:{tag:292,type:n.LONG},T6Options:{tag:293,type:n.LONG},ResolutionUnit:{tag:296,type:n.SHORT},PageNumber:{tag:297,type:n.SHORT,isArray:!0},TransferFunction:{tag:301,type:n.SHORT,isArray:!0},Software:{tag:305,type:n.ASCII},DateTime:{tag:306,type:n.ASCII},Artist:{tag:315,type:n.ASCII},HostComputer:{tag:316,type:n.ASCII},Predictor:{tag:317,type:n.SHORT},WhitePoint:{tag:318,type:n.RATIONAL,isArray:!0},PrimaryChromaticities:{tag:319,type:n.RATIONAL,isArray:!0},ColorMap:{tag:320,type:n.SHORT,isArray:!0},HalftoneHints:{tag:321,type:n.SHORT,isArray:!0},TileWidth:{tag:322,type:n.SHORT,eager:!0},TileLength:{tag:323,type:n.SHORT,eager:!0},TileOffsets:{tag:324,type:n.LONG,isArray:!0},TileByteCounts:{tag:325,type:n.SHORT,isArray:!0},InkSet:{tag:332,type:n.SHORT},InkNames:{tag:333,type:n.ASCII},NumberOfInks:{tag:334,type:n.SHORT},DotRange:{tag:336,type:n.BYTE,isArray:!0},TargetPrinter:{tag:337,type:n.ASCII},ExtraSamples:{tag:338,type:n.BYTE,isArray:!0,eager:!0},SampleFormat:{tag:339,type:n.SHORT,isArray:!0,eager:!0},SMinSampleValue:{tag:340,isArray:!0},SMaxSampleValue:{tag:341,isArray:!0},TransferRange:{tag:342,type:n.SHORT,isArray:!0},JPEGProc:{tag:512,type:n.SHORT},JPEGInterchangeFormat:{tag:513,type:n.LONG},JPEGInterchangeFormatLngth:{tag:514,type:n.LONG},JPEGRestartInterval:{tag:515,type:n.SHORT},JPEGLosslessPredictors:{tag:517,type:n.SHORT,isArray:!0},JPEGPointTransforms:{tag:518,type:n.SHORT,isArray:!0},JPEGQTables:{tag:519,type:n.LONG,isArray:!0},JPEGDCTables:{tag:520,type:n.LONG,isArray:!0},JPEGACTables:{tag:521,type:n.LONG,isArray:!0},YCbCrCoefficients:{tag:529,type:n.RATIONAL,isArray:!0},YCbCrSubSampling:{tag:530,type:n.SHORT,isArray:!0},YCbCrPositioning:{tag:531,type:n.SHORT},ReferenceBlackWhite:{tag:532,type:n.LONG,isArray:!0},Copyright:{tag:33432,type:n.ASCII},BadFaxLines:{tag:326},CleanFaxData:{tag:327},ClipPath:{tag:343},ConsecutiveBadFaxLines:{tag:328},Decode:{tag:433},DefaultImageColor:{tag:434},Indexed:{tag:346},JPEGTables:{tag:347,isArray:!0,eager:!0},StripRowCounts:{tag:559,isArray:!0},SubIFDs:{tag:330,isArray:!0},XClipPathUnits:{tag:344},YClipPathUnits:{tag:345},ApertureValue:{tag:37378},ColorSpace:{tag:40961},DateTimeDigitized:{tag:36868},DateTimeOriginal:{tag:36867},ExifIFD:{tag:34665,name:`Exif IFD`,type:n.LONG},ExifVersion:{tag:36864},ExposureTime:{tag:33434},FileSource:{tag:41728},Flash:{tag:37385},FlashpixVersion:{tag:40960},FNumber:{tag:33437},ImageUniqueID:{tag:42016},LightSource:{tag:37384},MakerNote:{tag:37500},ShutterSpeedValue:{tag:37377},UserComment:{tag:37510},IPTC:{tag:33723},CZ_LSMINFO:{tag:34412},ICCProfile:{tag:34675,name:`ICC Profile`},XMP:{tag:700},GDAL_METADATA:{tag:42112},GDAL_NODATA:{tag:42113,type:n.ASCII,eager:!0},Photoshop:{tag:34377},ModelPixelScale:{tag:33550,type:n.DOUBLE,isArray:!0,eager:!0},ModelTiepoint:{tag:33922,type:n.DOUBLE,isArray:!0,eager:!0},ModelTransformation:{tag:34264,type:n.DOUBLE,isArray:!0,eager:!0},GeoKeyDirectory:{tag:34735,type:n.SHORT,isArray:!0,eager:!0},GeoDoubleParams:{tag:34736,type:n.DOUBLE,isArray:!0,eager:!0},GeoAsciiParams:{tag:34737,type:n.ASCII,eager:!0},LercParameters:{tag:50674,eager:!0}},o={},s={};function c(e,t,r,i=!1,a=!1){o[t]=e,s[e]={tag:e,name:t,type:typeof r==`string`?n[r]:r,isArray:i,eager:a}}for(let[e,t]of Object.entries(a)){let n=t;c(n.tag,n.name||e,n.type,n.isArray,n.eager)}function l(e){return typeof e==`number`?e:o[e]}var u={WhiteIsZero:0,BlackIsZero:1,RGB:2,Palette:3,TransparencyMask:4,CMYK:5,YCbCr:6,CIELab:8,ICCLab:9},d={Unspecified:0,Assocalpha:1,Unassalpha:2},f={Version:0,AddCompression:1},p={None:0,Deflate:1,Zstandard:2},m={1024:`GTModelTypeGeoKey`,1025:`GTRasterTypeGeoKey`,1026:`GTCitationGeoKey`,2048:`GeographicTypeGeoKey`,2049:`GeogCitationGeoKey`,2050:`GeogGeodeticDatumGeoKey`,2051:`GeogPrimeMeridianGeoKey`,2052:`GeogLinearUnitsGeoKey`,2053:`GeogLinearUnitSizeGeoKey`,2054:`GeogAngularUnitsGeoKey`,2055:`GeogAngularUnitSizeGeoKey`,2056:`GeogEllipsoidGeoKey`,2057:`GeogSemiMajorAxisGeoKey`,2058:`GeogSemiMinorAxisGeoKey`,2059:`GeogInvFlatteningGeoKey`,2060:`GeogAzimuthUnitsGeoKey`,2061:`GeogPrimeMeridianLongGeoKey`,2062:`GeogTOWGS84GeoKey`,3072:`ProjectedCSTypeGeoKey`,3073:`PCSCitationGeoKey`,3074:`ProjectionGeoKey`,3075:`ProjCoordTransGeoKey`,3076:`ProjLinearUnitsGeoKey`,3077:`ProjLinearUnitSizeGeoKey`,3078:`ProjStdParallel1GeoKey`,3079:`ProjStdParallel2GeoKey`,3080:`ProjNatOriginLongGeoKey`,3081:`ProjNatOriginLatGeoKey`,3082:`ProjFalseEastingGeoKey`,3083:`ProjFalseNorthingGeoKey`,3084:`ProjFalseOriginLongGeoKey`,3085:`ProjFalseOriginLatGeoKey`,3086:`ProjFalseOriginEastingGeoKey`,3087:`ProjFalseOriginNorthingGeoKey`,3088:`ProjCenterLongGeoKey`,3089:`ProjCenterLatGeoKey`,3090:`ProjCenterEastingGeoKey`,3091:`ProjCenterNorthingGeoKey`,3092:`ProjScaleAtNatOriginGeoKey`,3093:`ProjScaleAtCenterGeoKey`,3094:`ProjAzimuthAngleGeoKey`,3095:`ProjStraightVertPoleLongGeoKey`,3096:`ProjRectifiedGridAngleGeoKey`,4096:`VerticalCSTypeGeoKey`,4097:`VerticalCitationGeoKey`,4098:`VerticalDatumGeoKey`,4099:`VerticalUnitsGeoKey`},h={};for(let[e,t]of Object.entries(m))h[t]=parseInt(e,10);function g(e){return(t,...n)=>v(e,t,n)}function _(e,t){return g(S(e,t).get)}var{apply:v,construct:y,defineProperty:b,get:x,getOwnPropertyDescriptor:S,getPrototypeOf:C,has:w,ownKeys:T,set:ee,setPrototypeOf:te}=Reflect,{EPSILON:ne,MAX_SAFE_INTEGER:re,isFinite:ie,isNaN:ae}=Number,{iterator:E,species:oe,toStringTag:se,for:ce}=Symbol,D=Object,{create:O,defineProperty:le,freeze:ue,is:de}=D,k=D.prototype;k.__lookupGetter__&&k.__lookupGetter__,D.hasOwn||k.hasOwnProperty;var fe=Array;fe.isArray;var A=fe.prototype;A.join,A.push,A.toLocaleString;var pe=A[E],me=g(pe),{abs:he,trunc:ge}=Math,j=ArrayBuffer;j.isView;var _e=j.prototype;_e.slice,_(_e,`byteLength`);var ve=typeof SharedArrayBuffer<`u`?SharedArrayBuffer:null;ve&&_(ve.prototype,`byteLength`);var ye=C(Uint8Array);ye.from;var M=ye.prototype;M[E],M.keys,M.values,M.entries,M.set,M.reverse,M.fill,M.copyWithin,M.sort,M.slice,M.subarray,_(M,`buffer`),_(M,`byteOffset`),_(M,`length`),_(M,se);var be=Uint8Array,xe=Uint16Array,N=Uint32Array,Se=Float32Array,P=C([][E]()),Ce=g(P.next),we=g((function*(){})().next),Te=C(P),Ee=DataView.prototype,De=g(Ee.getUint16);Ee.setUint16;var Oe=WeakSet.prototype;Oe.add,Oe.has;var F=WeakMap,I=F.prototype,ke=g(I.get);I.has;var Ae=g(I.set),je=new F,Me=O(null,{next:{value:function(){return Ce(ke(je,this))}},[E]:{value:function(){return this}}});function Ne(e){if(e[E]===pe&&P.next===Ce)return e;let t=O(Me);return Ae(je,t,me(e)),t}var Pe=new F,Fe=O(Te,{next:{value:function(){return we(ke(Pe,this))},writable:!0,configurable:!0}});for(let e of T(P))e!==`next`&&le(Fe,e,S(P,e));var Ie=1/ne,Le=6103515625e-14,Re=.0009765625;Re*Le,Re*Ie;var ze=new j(4),Be=new Se(ze),Ve=new N(ze),L=new xe(512),R=new be(512);for(let e=0;e<256;++e){let t=e-127;t<-24?(L[e]=0,L[e|256]=32768,R[e]=24,R[e|256]=24):t<-14?(L[e]=1024>>-t-14,L[e|256]=1024>>-t-14|32768,R[e]=-t-1,R[e|256]=-t-1):t<=15?(L[e]=t+15<<10,L[e|256]=t+15<<10|32768,R[e]=13,R[e|256]=13):t<128?(L[e]=31744,L[e|256]=64512,R[e]=24,R[e|256]=24):(L[e]=31744,L[e|256]=64512,R[e]=13,R[e|256]=13)}var z=new N(2048);for(let e=1;e<1024;++e){let t=e<<13,n=0;for(;!(t&8388608);)t<<=1,n-=8388608;t&=-8388609,n+=947912704,z[e]=t|n}for(let e=1024;e<2048;++e)z[e]=939524096+(e-1024<<13);var B=new N(64);for(let e=1;e<31;++e)B[e]=e<<23;B[31]=1199570944,B[32]=2147483648;for(let e=33;e<63;++e)B[e]=2147483648+(e-32<<23);B[63]=3347054592;var He=new xe(64);for(let e=1;e<64;++e)e!==32&&(He[e]=1024);function Ue(e){let t=e>>10;return Ve[0]=z[He[t]+(e&1023)]+B[t],Be[0]}function We(e,t,...n){return Ue(De(e,t,...Ne(n)))}function Ge(e,t,n){let r=n&&n.debug||!1;r&&console.log(`[xml-utils] getting `+t+` in `+e);let i=typeof e==`object`?e.outer:e,a=i.slice(0,i.indexOf(`>`)+1),o=[`"`,`'`];for(let e=0;e<o.length;e++){let n=o[e],i=t+`\\=`+n+`([^`+n+`]*)`+n;r&&console.log(`[xml-utils] pattern:`,i);let s=new RegExp(i).exec(a);if(r&&console.log(`[xml-utils] match:`,s),s)return s[1]}}function Ke(e,t,n){let r=new RegExp(t).exec(e.slice(n));return r?n+r.index:-1}function V(e,t,n){let r=new RegExp(t).exec(e.slice(n));return r?n+r.index+r[0].length-1:-1}function qe(e,t){let n=new RegExp(t,`g`),r=e.match(n);return r?r.length:0}function Je(e,t,n){let r=n&&n.debug||!1,i=!(n&&typeof n.nested===!1),a=n&&n.startIndex||0;r&&console.log(`[xml-utils] starting findTagByName with`,t,` and `,n);let o=Ke(e,`\<${t}[ \n\>\/]`,a);if(r&&console.log(`[xml-utils] start:`,o),o===-1)return;let s=e.slice(o+t.length),c=V(s,`^[^<]*[ /]>`,0),l=c!==-1&&s[c-1]===`/`;if(r&&console.log(`[xml-utils] selfClosing:`,l),l===!1){if(i){let e=0,n=1,r=0;for(;(c=V(s,`[ /]`+t+`>`,e))!==-1;){let i=s.substring(e,c+1);if(n+=qe(i,`<`+t+`[
3
+ >]`),r+=qe(i,`</`+t+`>`),r>=n)break;e=c}}else c=V(s,`[ /]`+t+`>`,0)}let u=o+t.length+c+1;if(r&&console.log(`[xml-utils] end:`,u),u===-1)return;let d=e.slice(o,u),f;return f=l?null:d.slice(d.indexOf(`>`)+1,d.lastIndexOf(`<`)),{inner:f,outer:d,start:o,end:u}}function Ye(e,t,n){let r=[],i=n&&n.debug||!1,a=n&&typeof n.nested==`boolean`?n.nested:!0,o=n&&n.startIndex||0,s;for(;s=Je(e,t,{debug:i,startIndex:o});)o=a?s.start+1+t.length:s.end,r.push(s);return i&&console.log(`findTagsByName found`,r.length,`tags`),r}function Xe(e,t){let{width:n,height:r}=e,i=new Uint8Array(n*r*3),a;for(let n=0,r=0;n<e.length;++n,r+=3)a=256-e[n]/t*256,i[r]=a,i[r+1]=a,i[r+2]=a;return i}function Ze(e,t){let{width:n,height:r}=e,i=new Uint8Array(n*r*3),a;for(let n=0,r=0;n<e.length;++n,r+=3)a=e[n]/t*256,i[r]=a,i[r+1]=a,i[r+2]=a;return i}function Qe(e,t){let{width:n,height:r}=e,i=new Uint8Array(n*r*3),a=t.length/3,o=t.length/3*2;for(let n=0,r=0;n<e.length;++n,r+=3){let s=e[n];i[r]=t[s]/65536*256,i[r+1]=t[s+a]/65536*256,i[r+2]=t[s+o]/65536*256}return i}function $e(e){let{width:t,height:n}=e,r=new Uint8Array(t*n*3);for(let t=0,n=0;t<e.length;t+=4,n+=3){let i=e[t],a=e[t+1],o=e[t+2],s=e[t+3];r[n]=255*((255-i)/256)*((255-s)/256),r[n+1]=255*((255-a)/256)*((255-s)/256),r[n+2]=255*((255-o)/256)*((255-s)/256)}return r}function et(e){let{width:t,height:n}=e,r=new Uint8ClampedArray(t*n*3);for(let t=0,n=0;t<e.length;t+=3,n+=3){let i=e[t],a=e[t+1],o=e[t+2];r[n]=i+1.402*(o-128),r[n+1]=i-.34414*(a-128)-.71414*(o-128),r[n+2]=i+1.772*(a-128)}return r}var tt=.95047,nt=1,rt=1.08883;function it(e){let{width:t,height:n}=e,r=new Uint8Array(t*n*3);for(let t=0,n=0;t<e.length;t+=3,n+=3){let i=e[t+0],a=e[t+1]<<24>>24,o=e[t+2]<<24>>24,s=(i+16)/116,c=a/500+s,l=s-o/200,u,d,f;c=tt*(c*c*c>.008856?c*c*c:(c-16/116)/7.787),s=nt*(s*s*s>.008856?s*s*s:(s-16/116)/7.787),l=rt*(l*l*l>.008856?l*l*l:(l-16/116)/7.787),u=c*3.2406+s*-1.5372+l*-.4986,d=c*-.9689+s*1.8758+l*.0415,f=c*.0557+s*-.204+l*1.057,u=u>.0031308?1.055*u**(1/2.4)-.055:12.92*u,d=d>.0031308?1.055*d**(1/2.4)-.055:12.92*d,f=f>.0031308?1.055*f**(1/2.4)-.055:12.92*f,r[n]=Math.max(0,Math.min(1,u))*255,r[n+1]=Math.max(0,Math.min(1,d))*255,r[n+2]=Math.max(0,Math.min(1,f))*255}return r}var H=new Map;async function U(e){let t=!e.hasTag(`StripOffsets`);return{tileWidth:t?await e.loadValue(`TileWidth`):await e.loadValue(`ImageWidth`),tileHeight:t?await e.loadValue(`TileLength`):await e.loadValue(`RowsPerStrip`)||await e.loadValue(`ImageLength`),planarConfiguration:await e.loadValue(`PlanarConfiguration`),bitsPerSample:await e.loadValue(`BitsPerSample`),predictor:await e.loadValue(`Predictor`)||1}}function at(e,t,n=U,r=!0){Array.isArray(e)||(e=[e]),e.forEach(e=>{H.set(e,{importFn:t,decoderParameterFn:n,preferWorker:r})})}async function ot(e,t){if(!H.has(e))throw Error(`Unknown compression method identifier: ${e}`);let{decoderParameterFn:n}=H.get(e);return n(t)}async function st(e,t){if(!H.has(e))throw Error(`Unknown compression method identifier: ${e}`);let{importFn:n}=H.get(e);return new(await(n()))(t)}var ct=[{cases:[void 0,1],importFn:()=>t(()=>import(`./raw-A-vJRPpa.js`).then(e=>e.default),__vite__mapDeps([0,1])),preferWorker:!1},{cases:5,importFn:()=>t(()=>import(`./lzw-D2FslT4L.js`).then(e=>e.default),__vite__mapDeps([2,1]))},{cases:6,importFn:()=>{throw Error(`old style JPEG compression is not supported.`)}},{cases:7,importFn:()=>t(()=>import(`./jpeg-AGQ46WDa.js`).then(e=>e.default),__vite__mapDeps([3,1])),decoderParameterFn:async e=>({...await U(e),JPEGTables:await e.loadValue(`JPEGTables`)})},{cases:[8,32946],importFn:()=>t(()=>import(`./deflate-DPjr4M2G.js`).then(e=>e.default),__vite__mapDeps([4,5,1]))},{cases:32773,importFn:()=>t(()=>import(`./packbits-DCimUQ1T.js`).then(e=>e.default),__vite__mapDeps([6,1]))},{cases:34887,importFn:()=>t(()=>import(`./lerc-Cuor-Zm2.js`).then(async e=>(await e.zstd.init(),e)),__vite__mapDeps([7,8,5,1])).then(e=>e.default),decoderParameterFn:async e=>({...await U(e),LercParameters:await e.loadValue(`LercParameters`)})},{cases:5e4,importFn:()=>t(()=>import(`./zstd-i4Jwubnx.js`).then(async e=>(await e.zstd.init(),e)),__vite__mapDeps([9,1])).then(e=>e.default)},{cases:50001,importFn:()=>t(()=>import(`./webimage-zQMH-_zR.js`).then(e=>e.default),__vite__mapDeps([10,1])),decoderParameterFn:async e=>({...await U(e),samplesPerPixel:Number(await e.loadValue(`SamplesPerPixel`))||4}),preferWorker:!1}];for(let e of ct){let{cases:t,importFn:n,decoderParameterFn:r,preferWorker:i}=e;at(t,n,r,i)}function W(e,t,n,r=1){return new(Object.getPrototypeOf(e)).constructor(t*n*r)}function lt(e,t,n,r,i){let a=t/r,o=n/i;return e.map(e=>{let s=W(e,r,i);for(let c=0;c<i;++c){let i=Math.min(Math.round(o*c),n-1);for(let n=0;n<r;++n){let o=Math.min(Math.round(a*n),t-1),l=e[i*t+o];s[c*r+n]=l}}return s})}function G(e,t,n){return(1-n)*e+n*t}function ut(e,t,n,r,i){let a=t/r,o=n/i;return e.map(e=>{let s=W(e,r,i);for(let c=0;c<i;++c){let i=o*c,l=Math.floor(i),u=Math.min(Math.ceil(i),n-1);for(let n=0;n<r;++n){let o=a*n,d=o%1,f=Math.floor(o),p=Math.min(Math.ceil(o),t-1),m=e[l*t+f],h=e[l*t+p],g=e[u*t+f],_=e[u*t+p],v=G(G(m,h,d),G(g,_,d),i%1);s[c*r+n]=v}}return s})}function dt(e,t,n,r,i,a=`nearest`){switch(a.toLowerCase()){case`nearest`:return lt(e,t,n,r,i);case`bilinear`:case`linear`:return ut(e,t,n,r,i);default:throw Error(`Unsupported resampling method: '${a}'`)}}function ft(e,t,n,r,i,a){let o=t/r,s=n/i,c=W(e,r,i,a);for(let l=0;l<i;++l){let i=Math.min(Math.round(s*l),n-1);for(let n=0;n<r;++n){let s=Math.min(Math.round(o*n),t-1);for(let o=0;o<a;++o){let u=e[i*t*a+s*a+o];c[l*r*a+n*a+o]=u}}}return c}function pt(e,t,n,r,i,a){let o=t/r,s=n/i,c=W(e,r,i,a);for(let l=0;l<i;++l){let i=s*l,u=Math.floor(i),d=Math.min(Math.ceil(i),n-1);for(let n=0;n<r;++n){let s=o*n,f=s%1,p=Math.floor(s),m=Math.min(Math.ceil(s),t-1);for(let o=0;o<a;++o){let s=e[u*t*a+p*a+o],h=e[u*t*a+m*a+o],g=e[d*t*a+p*a+o],_=e[d*t*a+m*a+o],v=G(G(s,h,f),G(g,_,f),i%1);c[l*r*a+n*a+o]=v}}}return c}function mt(e,t,n,r,i,a,o=`nearest`){switch(o.toLowerCase()){case`nearest`:return ft(e,t,n,r,i,a);case`bilinear`:case`linear`:return pt(e,t,n,r,i,a);default:throw Error(`Unsupported resampling method: '${o}'`)}}function ht(e,t,n){let r=0;for(let i=t;i<n;++i)r+=e[i];return r}function K(e,t,n){let r;switch(e){case 1:t<=8?r=Uint8Array:t<=16?r=Uint16Array:t<=32&&(r=Uint32Array);break;case 2:t===8?r=Int8Array:t===16?r=Int16Array:t===32&&(r=Int32Array);break;case 3:switch(t){case 16:case 32:r=Float32Array;break;case 64:r=Float64Array}}if(r&&(typeof n==`number`||n instanceof ArrayBuffer))return new r(n);throw Error(`Unsupported data format/bitsPerSample`)}function gt(e,t){return(e===1||e===2)&&t<=32&&t%8==0?!1:e!==3||t!==16&&t!==32&&t!==64}function _t(e,t,n,r,i,a,o){let s=new DataView(e),c=n===2?o*a:o*a*r,l=n===2?1:r,u=K(t,i,c),d=parseInt(`1`.repeat(i),2);if(t===1){let e;e=n===1?r*i:i;let t=a*e;t&7&&(t=t+7&-8);for(let e=0;e<o;++e){let n=e*t;for(let t=0;t<a;++t){let r=n+t*l*i;for(let n=0;n<l;++n){let o=r+n*i,c=(e*a+t)*l+n,f=Math.floor(o/8),p=o%8;u[c]=p+i<=8?s.getUint8(f)>>8-i-p&d:p+i<=16?s.getUint16(f)>>16-i-p&d:p+i<=24?(s.getUint16(f)<<8|s.getUint8(f+2))>>24-i-p&d:s.getUint32(f)>>32-i-p&d}}}}return u.buffer}var vt=class{constructor(e,t,n,r){this.fileDirectory=e,this.littleEndian=t,this.tiles=n?[]:null,this.isTiled=!e.hasTag(`StripOffsets`);let i=e.getValue(`PlanarConfiguration`)??1;if(i!==1&&i!==2)throw Error(`Invalid planar configuration.`);this.planarConfiguration=i,this.source=r}getFileDirectory(){return this.fileDirectory}getGeoKeys(){return this.fileDirectory.parseGeoKeyDirectory()}getWidth(){return this.fileDirectory.getValue(`ImageWidth`)||0}getHeight(){return this.fileDirectory.getValue(`ImageLength`)||0}getSamplesPerPixel(){return this.fileDirectory.getValue(`SamplesPerPixel`)??1}getTileWidth(){return this.isTiled?this.fileDirectory.getValue(`TileWidth`)||0:this.getWidth()}getTileHeight(){if(this.isTiled)return this.fileDirectory.getValue(`TileLength`)||0;let e=this.fileDirectory.hasTag(`RowsPerStrip`)&&this.fileDirectory.getValue(`RowsPerStrip`);return e?Math.min(e,this.getHeight()):this.getHeight()}getBlockWidth(){return this.getTileWidth()}getBlockHeight(e){return this.isTiled||(e+1)*this.getTileHeight()<=this.getHeight()?this.getTileHeight():this.getHeight()-e*this.getTileHeight()}getBytesPerPixel(){let e=0,t=this.fileDirectory.getValue(`BitsPerSample`)||[];for(let n=0;n<t.length;++n)e+=this.getSampleByteSize(n);return e}getSampleByteSize(e){let t=this.fileDirectory.getValue(`BitsPerSample`)||[];if(e>=t.length)throw RangeError(`Sample index ${e} is out of range.`);return Math.ceil(t[e]/8)}getReaderForSample(e){let t=this.fileDirectory.getValue(`SampleFormat`),n=t?t[e]:1,r=(this.fileDirectory.getValue(`BitsPerSample`)||[])[e];switch(n){case 1:if(r<=8)return DataView.prototype.getUint8;if(r<=16)return DataView.prototype.getUint16;if(r<=32)return DataView.prototype.getUint32;break;case 2:if(r<=8)return DataView.prototype.getInt8;if(r<=16)return DataView.prototype.getInt16;if(r<=32)return DataView.prototype.getInt32;break;case 3:switch(r){case 16:return function(e,t){return We(this,e,t)};case 32:return DataView.prototype.getFloat32;case 64:return DataView.prototype.getFloat64}}throw Error(`Unsupported data format/bitsPerSample`)}getSampleFormat(e=0){let t=this.fileDirectory.getValue(`SampleFormat`);return t?t[e]:1}getBitsPerSample(e=0){let t=this.fileDirectory.getValue(`BitsPerSample`);return t?t[e]:0}getArrayForSample(e,t){return K(this.getSampleFormat(e),this.getBitsPerSample(e),t)}async getTileOrStrip(e,t,n,r,i){let a=Math.ceil(this.getWidth()/this.getTileWidth()),o=Math.ceil(this.getHeight()/this.getTileHeight()),s,{tiles:c}=this;if(this.planarConfiguration===1?s=t*a+e:this.planarConfiguration===2&&(s=n*a*o+t*a+e),s===void 0)throw Error(`Could not determine tile or strip index.`);let l,u;if(this.isTiled?(l=Number(await this.fileDirectory.loadValueIndexed(`TileOffsets`,s)),u=Number(await this.fileDirectory.loadValueIndexed(`TileByteCounts`,s))):(l=Number(await this.fileDirectory.loadValueIndexed(`StripOffsets`,s)),u=Number(await this.fileDirectory.loadValueIndexed(`StripByteCounts`,s))),u===0){let r=this.getBlockHeight(t)*this.getTileWidth(),i=this.planarConfiguration===2?this.getSampleByteSize(n):this.getBytesPerPixel(),a=new ArrayBuffer(r*i);return this.getArrayForSample(n,a).fill(this.getGDALNoData()||0),{x:e,y:t,sample:n,data:a}}let d=(await this.source.fetch([{offset:l,length:u}],i))[0],f;return c===null||!c[s]?(f=(async()=>{let e=await r.decode(d),n=this.getSampleFormat(),i=this.getBitsPerSample();return gt(n,i)&&(e=_t(e,n,this.planarConfiguration,this.getSamplesPerPixel(),i,this.getTileWidth(),this.getBlockHeight(t))),e})(),c!==null&&(c[s]=f)):f=c[s],{x:e,y:t,sample:n,data:await f}}async _readRaster(e,t,n,r,i,a,o,s,c){let l=this.getTileWidth(),u=this.getTileHeight(),d=this.getWidth(),f=this.getHeight(),p=Math.max(Math.floor(e[0]/l),0),m=Math.min(Math.ceil(e[2]/l),Math.ceil(d/l)),h=Math.max(Math.floor(e[1]/u),0),g=Math.min(Math.ceil(e[3]/u),Math.ceil(f/u)),_=e[2]-e[0],v=this.getBytesPerPixel(),y=[],b=[];for(let e=0;e<t.length;++e){if(this.planarConfiguration===1){let n=await this.fileDirectory.loadValue(`BitsPerSample`);if(typeof n!=`object`)throw Error(`Expected BitsPerSample to be an array or typed array.`);y.push(ht(n,0,t[e])/8)}else y.push(0);b.push(this.getReaderForSample(t[e]))}let x=[],{littleEndian:S}=this;for(let a=h;a<g;++a)for(let o=p;o<m;++o){let s;this.planarConfiguration===1&&(s=this.getTileOrStrip(o,a,0,i,c));for(let p=0;p<t.length;++p){let m=p,h=t[p];if(this.planarConfiguration===2&&(v=this.getSampleByteSize(h),s=this.getTileOrStrip(o,a,h,i,c)),!s)throw Error(`Could not get tile or strip data.`);let g=s.then(i=>{let a=i.data,o=new DataView(a),s=this.getBlockHeight(i.y),c=i.y*u,p=i.x*l,h=c+s,g=(i.x+1)*l,x=b[m],C=Math.min(s,s-(h-e[3]),f-c),w=Math.min(l,l-(g-e[2]),d-p);for(let i=Math.max(0,e[1]-c);i<C;++i)for(let a=Math.max(0,e[0]-p);a<w;++a){let s=(i*l+a)*v,u=x.call(o,s+y[m],S),d;r?(d=(i+c-e[1])*_*t.length+(a+p-e[0])*t.length+m,n[d]=u):(d=(i+c-e[1])*_+a+p-e[0],n[m][d]=u)}});x.push(g)}}if(await Promise.all(x),a&&e[2]-e[0]!==a||o&&e[3]-e[1]!==o){let i;i=r?mt(n,e[2]-e[0],e[3]-e[1],a,o,t.length,s):dt(n,e[2]-e[0],e[3]-e[1],a,o,s);let c=i;return c.width=a??e[2]-e[0],c.height=o??e[3]-e[1],c}let C=n;return C.width=a||e[2]-e[0],C.height=o||e[3]-e[1],C}async readRasters(e={}){let{window:t,samples:n=[],pool:r=null,width:i,height:a,resampleMethod:o,fillValue:s,signal:c}=e,l=`interleave`in e&&e.interleave,u=t||[0,0,this.getWidth(),this.getHeight()];if(u[0]>u[2]||u[1]>u[3])throw Error(`Invalid subsets`);let d=(u[2]-u[0])*(u[3]-u[1]),f=this.getSamplesPerPixel();if(!n||!n.length)for(let e=0;e<f;++e)n.push(e);else for(let e=0;e<n.length;++e)if(n[e]>=f)return Promise.reject(RangeError(`Invalid sample index '${n[e]}'.`));let p;if(l){let{fileDirectory:e}=this,t=e.getValue(`SampleFormat`),r=t?Math.max.apply(null,Array.from(t)):1;if(r!==1&&r!==2&&r!==3)throw Error(`Unsupported sample format for interleaved data. Must be 1, 2, or 3.`);let i=e.getValue(`BitsPerSample`);if(p=K(r,i?Math.max.apply(null,Array.from(i)):8,d*n.length),s){if(Array.isArray(s))throw Error(`When reading interleaved data, fillValue must be a single number.`);p.fill(s)}}else{p=[];for(let e=0;e<n.length;++e){let t=this.getArrayForSample(n[e],d);Array.isArray(s)&&e<s.length?t.fill(s[e]):s&&!Array.isArray(s)&&t.fill(s),p.push(t)}}let m=this.fileDirectory.getValue(`Compression`)||1,h=await ot(m,this.fileDirectory),g=r?r.bindParameters(m,h):await st(m,h);return await this._readRaster(u,n,p,l,g,i,a,o,c)}async readRGB(e={}){let{window:t,pool:n=null,width:r,height:i,resampleMethod:a,enableAlpha:o=!1,signal:s}=e,c=(`interleave`in e&&e.interleave)??!1,l=t||[0,0,this.getWidth(),this.getHeight()];if(l[0]>l[2]||l[1]>l[3])throw Error(`Invalid subsets`);let f=this.fileDirectory.getValue(`PhotometricInterpretation`);if(f===u.RGB){let e=[0,1,2],l=this.fileDirectory.getValue(`ExtraSamples`);if(l&&l[0]!==d.Unspecified&&o){e=[];let t=this.fileDirectory.getValue(`BitsPerSample`)||[];for(let n=0;n<t.length;n+=1)e.push(n)}return this.readRasters({window:t,interleave:c,samples:e,pool:n,width:r,height:i,resampleMethod:a,signal:s})}let p;switch(f){case u.WhiteIsZero:case u.BlackIsZero:case u.Palette:p=[0];break;case u.CMYK:p=[0,1,2,3];break;case u.YCbCr:case u.CIELab:p=[0,1,2];break;default:throw Error(`Invalid or unsupported photometric interpretation.`)}let m={window:l,interleave:!0,samples:p,pool:n,width:r,height:i,resampleMethod:a,signal:s},{fileDirectory:h}=this,g=await this.readRasters(m),_=2**this.getBitsPerSample(0),v;switch(f){case u.WhiteIsZero:v=Xe(g,_);break;case u.BlackIsZero:v=Ze(g,_);break;case u.Palette:v=Qe(g,await h.loadValue(`ColorMap`));break;case u.CMYK:v=$e(g);break;case u.YCbCr:v=et(g);break;case u.CIELab:v=it(g);break;default:throw Error(`Unsupported photometric interpretation.`)}if(!c){let e=new Uint8Array(v.length/3),t=new Uint8Array(v.length/3),n=new Uint8Array(v.length/3);for(let r=0,i=0;r<v.length;r+=3,++i)e[i]=v[r],t[i]=v[r+1],n[i]=v[r+2];v=[e,t,n]}let y=v;return y.width=g.width,y.height=g.height,y}async getTiePoints(){if(!this.fileDirectory.hasTag(`ModelTiepoint`))return[];let e=await this.fileDirectory.loadValue(`ModelTiepoint`);if(typeof e!=`object`)throw Error(`Expected ModelTiepoint to be an array or typed array.`);let t=[];for(let n=0;n<e.length;n+=6)t.push({i:e[n],j:e[n+1],k:e[n+2],x:e[n+3],y:e[n+4],z:e[n+5]});return t}async getGDALMetadata(e=null){let t={};if(!this.fileDirectory.hasTag(`GDAL_METADATA`))return null;let n=Ye(await this.fileDirectory.loadValue(`GDAL_METADATA`),`Item`);n=e===null?n.filter(e=>Ge(e,`sample`)===void 0):n.filter(t=>Number(Ge(t,`sample`))===e);for(let e=0;e<n.length;++e){let r=n[e];t[Ge(r,`name`)]=r.inner}return t}getGDALNoData(){let e=this.fileDirectory.hasTag(`GDAL_NODATA`)&&this.fileDirectory.getValue(`GDAL_NODATA`);return e?Number(e.substring(0,e.length-1)):null}getOrigin(){let e=this.fileDirectory.getValue(`ModelTiepoint`),t=this.fileDirectory.getValue(`ModelTransformation`);if(e&&e.length===6)return[e[3],e[4],e[5]];if(t)return[t[3],t[7],t[11]];throw Error(`The image does not have an affine transformation.`)}getResolution(e=null){let t=this.fileDirectory.getValue(`ModelPixelScale`),n=this.fileDirectory.getValue(`ModelTransformation`);if(t)return[t[0],-t[1],t[2]];if(n)return n[1]===0&&n[4]===0?[n[0],-n[5],n[10]]:[Math.sqrt(n[0]*n[0]+n[4]*n[4]),-Math.sqrt(n[1]*n[1]+n[5]*n[5]),n[10]];if(e){let[t,n,r]=e.getResolution();return[t*e.getWidth()/this.getWidth(),n*e.getHeight()/this.getHeight(),r*e.getWidth()/this.getWidth()]}throw Error(`The image does not have an affine transformation.`)}pixelIsArea(){return this.getGeoKeys()?.GTRasterTypeGeoKey===1}getBoundingBox(e=!1){let t=this.getHeight(),n=this.getWidth(),r=this.fileDirectory.getValue(`ModelTransformation`);if(r&&!e){let[e,i,,a,o,s,,c]=r,l=[[0,0],[0,t],[n,0],[n,t]].map(([t,n])=>[a+e*t+i*n,c+o*t+s*n]),u=l.map(e=>e[0]),d=l.map(e=>e[1]);return[Math.min(...u),Math.min(...d),Math.max(...u),Math.max(...d)]}{let e=this.getOrigin(),r=this.getResolution(),i=e[0],a=e[1],o=i+r[0]*n,s=a+r[1]*t;return[Math.min(i,o),Math.min(a,s),Math.max(i,o),Math.max(a,s)]}}},yt=class{constructor(e){this._dataView=new DataView(e)}get buffer(){return this._dataView.buffer}getUint64(e,t){let n=this.getUint32(e,t),r=this.getUint32(e+4,t),i;if(t){if(i=n+2**32*r,!Number.isSafeInteger(i))throw Error(`${i} exceeds MAX_SAFE_INTEGER. Precision may be lost. Please report if you get this message to https://github.com/geotiffjs/geotiff.js/issues`);return i}if(i=2**32*n+r,!Number.isSafeInteger(i))throw Error(`${i} exceeds MAX_SAFE_INTEGER. Precision may be lost. Please report if you get this message to https://github.com/geotiffjs/geotiff.js/issues`);return i}getInt64(e,t){let n=0,r=(this._dataView.getUint8(e+(t?7:0))&128)>0,i=!0;for(let a=0;a<8;a++){let o=this._dataView.getUint8(e+(t?a:7-a));r&&(i?o!==0&&(o=~(o-1)&255,i=!1):o=~o&255),n+=o*256**a}return r&&(n=-n),n}getUint8(e){return this._dataView.getUint8(e)}getInt8(e){return this._dataView.getInt8(e)}getUint16(e,t){return this._dataView.getUint16(e,t)}getInt16(e,t){return this._dataView.getInt16(e,t)}getUint32(e,t){return this._dataView.getUint32(e,t)}getInt32(e,t){return this._dataView.getInt32(e,t)}getFloat16(e,t){return We(this._dataView,e,t)}getFloat32(e,t){return this._dataView.getFloat32(e,t)}getFloat64(e,t){return this._dataView.getFloat64(e,t)}},q=class{constructor(e,t,n,r){this._dataView=new DataView(e),this._sliceOffset=t,this._littleEndian=n,this._bigTiff=r}get sliceOffset(){return this._sliceOffset}get sliceTop(){return this._sliceOffset+this.buffer.byteLength}get littleEndian(){return this._littleEndian}get bigTiff(){return this._bigTiff}get buffer(){return this._dataView.buffer}covers(e,t){return this.sliceOffset<=e&&this.sliceTop>=e+t}readUint8(e){return this._dataView.getUint8(e-this._sliceOffset)}readInt8(e){return this._dataView.getInt8(e-this._sliceOffset)}readUint16(e){return this._dataView.getUint16(e-this._sliceOffset,this._littleEndian)}readInt16(e){return this._dataView.getInt16(e-this._sliceOffset,this._littleEndian)}readUint32(e){return this._dataView.getUint32(e-this._sliceOffset,this._littleEndian)}readInt32(e){return this._dataView.getInt32(e-this._sliceOffset,this._littleEndian)}readFloat32(e){return this._dataView.getFloat32(e-this._sliceOffset,this._littleEndian)}readFloat64(e){return this._dataView.getFloat64(e-this._sliceOffset,this._littleEndian)}readUint64(e){let t=this.readUint32(e),n=this.readUint32(e+4),r;if(this._littleEndian){if(r=t+2**32*n,!Number.isSafeInteger(r))throw Error(`${r} exceeds MAX_SAFE_INTEGER. Precision may be lost. Please report if you get this message to https://github.com/geotiffjs/geotiff.js/issues`);return r}if(r=2**32*t+n,!Number.isSafeInteger(r))throw Error(`${r} exceeds MAX_SAFE_INTEGER. Precision may be lost. Please report if you get this message to https://github.com/geotiffjs/geotiff.js/issues`);return r}readInt64(e){let t=0,n=(this._dataView.getUint8(e+(this._littleEndian?7:0))&128)>0,r=!0;for(let i=0;i<8;i++){let a=this._dataView.getUint8(e+(this._littleEndian?i:7-i));n&&(r?a!==0&&(a=~(a-1)&255,r=!1):a=~a&255),t+=a*256**i}return n&&(t=-t),t}readOffset(e){return this._bigTiff?this.readUint64(e):this.readUint32(e)}},bt=class{async fetch(e,t){return Promise.all(e.map(async e=>(await this.fetchSlice(e,t)).data))}async fetchSlice(e,t){throw Error(`fetching of slice ${e} not possible, not implemented`)}get fileSize(){return null}async close(){}},xt=class extends bt{constructor(e){super(),this.file=e}async fetchSlice(e,t){return new Promise((n,r)=>{let i=this.file.slice(e.offset,e.offset+e.length),a=new FileReader;a.onload=()=>n({data:a.result,offset:e.offset,length:e.length}),a.onerror=r,a.onabort=r,a.readAsArrayBuffer(i),t&&t.addEventListener(`abort`,()=>a.abort())})}};function St(e){return new xt(e)}function J(e,t){switch(e){case n.BYTE:case n.ASCII:case n.UNDEFINED:return new Uint8Array(t);case n.SBYTE:return new Int8Array(t);case n.SHORT:return new Uint16Array(t);case n.SSHORT:return new Int16Array(t);case n.LONG:case n.IFD:return new Uint32Array(t);case n.SLONG:return new Int32Array(t);case n.LONG8:case n.IFD8:return Array(t);case n.SLONG8:return Array(t);case n.RATIONAL:return new Uint32Array(t*2);case n.SRATIONAL:return new Int32Array(t*2);case n.FLOAT:return new Float32Array(t);case n.DOUBLE:return new Float64Array(t);default:throw RangeError(`Invalid field type: ${e}`)}}function Y(e,t){switch(t){case n.BYTE:case n.ASCII:case n.UNDEFINED:return e.readUint8;case n.SBYTE:return e.readInt8;case n.SHORT:return e.readUint16;case n.SSHORT:return e.readInt16;case n.LONG:case n.IFD:return e.readUint32;case n.SLONG:return e.readInt32;case n.LONG8:case n.IFD8:return e.readUint64;case n.SLONG8:return e.readInt64;case n.RATIONAL:return e.readUint32;case n.SRATIONAL:return e.readInt32;case n.FLOAT:return e.readFloat32;case n.DOUBLE:return e.readFloat64;default:throw RangeError(`Invalid field type: ${t}`)}}function X(e=null,t,r,a,o,s,c=!1){let l=i(a),u=e||J(a,o),d=a===n.RATIONAL||a===n.SRATIONAL;if(d)for(let e=0;e<o;e+=2)u[e]=t.call(r,s+e*l),u[e+1]=t.call(r,s+(e*l+4));else for(let e=0;e<o;++e)u[e]=t.call(r,s+e*l);return a===n.ASCII?new TextDecoder(`utf-8`).decode(u):o===1&&!c&&!d?u[0]:u}var Ct=class{constructor(e,t,n,r,a){this.source=e,this.arrayOffset=t,this.littleEndian=n,this.fieldType=r,this.length=a,this.data=J(r,a),this.itemSize=i(r),this.maskBitmap=new Uint8Array(Math.ceil(a/8)),this.fetchIndexPromises=new Map,this.fullFetchPromise=null}async loadAll(){return this.fullFetchPromise||=this.source.fetch([{offset:this.arrayOffset,length:this.itemSize*this.length}]).then(e=>{let t=new q(e[0],this.arrayOffset,!0,!1),n=X(this.data,Y(t,this.fieldType),t,this.fieldType,this.length,this.arrayOffset,!0);return this.maskBitmap.fill(255),this.fetchIndexPromises.clear(),n}),this.fullFetchPromise}async get(e){if(e<0||e>=this.data.length)throw RangeError(`Index ${e} out of bounds for length ${this.data.length}`);let t=Math.floor(e/8),n=1<<e%8,r=this.arrayOffset+e*this.itemSize;if((this.maskBitmap[t]&n)===0){if(!this.fetchIndexPromises.has(e)){let i=this.source.fetch([{offset:r,length:this.itemSize}]).then(i=>{let a=new q(i[0],this.arrayOffset+e*this.itemSize,!0,!1),o=Y(a,this.fieldType).call(a,r);return this.data[e]=o,this.maskBitmap[t]|=n,this.fetchIndexPromises.delete(e),o});this.fetchIndexPromises.set(e,i)}return this.fetchIndexPromises.get(e)}return this.data[e]}},wt=class{constructor(e,t,n,r){this.actualizedFields=e,this.deferredFields=t,this.deferredFieldsBeingResolved=new Map,this.deferredArrays=n,this.nextIFDByteOffset=r}hasTag(e){let t=l(e);return this.actualizedFields.has(t)||this.deferredFields.has(t)||this.deferredArrays.has(t)}getValue(e){let t=l(e);if(this.deferredFields.has(t)||this.deferredArrays.has(t)){let e=s[t]?.name||`Tag${t}`;throw Error(`Field '${e}' (${t}) is deferred. Use loadValue() to load it asynchronously.`)}if(this.actualizedFields.has(t))return this.actualizedFields.get(t)}async loadValue(e){let t=l(e);if(this.actualizedFields.has(t))return this.actualizedFields.get(t);if(this.deferredFieldsBeingResolved.has(t))return this.deferredFieldsBeingResolved.get(t);let n=this.deferredFields.get(t);if(n){this.deferredFields.delete(t);let e=(async()=>{try{let e=await n();return this.actualizedFields.set(t,e),e}finally{this.deferredFieldsBeingResolved.delete(t)}})();return this.deferredFieldsBeingResolved.set(t,e),e}let r=this.deferredArrays.get(t);if(r)return r.loadAll()}async loadValueIndexed(e,t){let n=l(e);if(this.actualizedFields.has(n))return this.actualizedFields.get(n)[t];if(this.deferredArrays.has(n))return this.deferredArrays.get(n).get(t);if(this.hasTag(n)){let e=await this.loadValue(n);if(e&&typeof e!=`number`)return e[t]}}parseGeoKeyDirectory(){let e=this.getValue(`GeoKeyDirectory`);if(!e)return null;let t={};for(let n=4;n<=e[3]*4;n+=4){let r=m[e[n]],i=e[n+1]||null,a=e[n+2],o=e[n+3],s=null;if(!i)s=o;else{if(s=this.getValue(i),s==null)throw Error(`Could not get value of geoKey '${r}'.`);typeof s==`string`?s=s.substring(o,o+a-1):s.subarray&&(s=s.subarray(o,o+a),a===1&&(s=s[0]))}t[r]=s}return t}toObject(){let e={};for(let[t,n]of this.actualizedFields.entries()){let r=typeof t==`number`?s[t]:void 0,i=r?r.name:`Tag${t}`;e[i]=n}return e}},Tt=class{constructor(e,t,n,r=!1){this.source=e,this.littleEndian=t,this.bigTiff=n,this.eager=r}async getSlice(e,t){let n=this.bigTiff?4048:1024;return new q((await this.source.fetch([{offset:e,length:t===void 0?n:t}]))[0],e,this.littleEndian,this.bigTiff)}async parseFileDirectoryAt(e){let t=this.bigTiff?20:12,n=this.bigTiff?8:2,r=await this.getSlice(e),a=this.bigTiff?r.readUint64(e):r.readUint16(e),o=a*(t+(this.bigTiff?16:6));r.covers(e,o)||(r=await this.getSlice(e,o));let c=new Map,l=new Map,u=new Map,d=e+(this.bigTiff?8:2);for(let e=0;e<a;d+=t,++e){let e=r.readUint16(d),t=r.readUint16(d+2),n=this.bigTiff?r.readUint64(d+4):r.readUint32(d+4),a=null,o=null,f=null,p=i(t),m=d+(this.bigTiff?12:8),h=s[e]?.isArray,g=s[e]?.eager||this.eager;if(p*n<=(this.bigTiff?8:4))a=X(J(t,n),Y(r,t),r,t,n,m,h);else{let e=r.readOffset(m),s=i(t)*n;if(r.covers(e,s))a=X(J(t,n),Y(r,t),r,t,n,e,h);else if(g){let r=await this.getSlice(e,s);a=X(J(t,n),Y(r,t),r,t,n,e,h)}else h?f=new Ct(this.source,e,this.littleEndian,t,n):o=async()=>{let r=await this.getSlice(e,s);return X(J(t,n),Y(r,t),r,t,n,e,h)}}a===null?o===null?f!==null&&u.set(e,f):l.set(e,o):c.set(e,a)}return new wt(c,l,u,r.readOffset(e+n+t*a))}};function Z(e,t,r,a){let o=null,s=null,c=i(t);switch(t){case n.BYTE:case n.ASCII:case n.UNDEFINED:o=new Uint8Array(r),s=e.readUint8;break;case n.SBYTE:o=new Int8Array(r),s=e.readInt8;break;case n.SHORT:o=new Uint16Array(r),s=e.readUint16;break;case n.SSHORT:o=new Int16Array(r),s=e.readInt16;break;case n.LONG:case n.IFD:o=new Uint32Array(r),s=e.readUint32;break;case n.SLONG:o=new Int32Array(r),s=e.readInt32;break;case n.LONG8:case n.IFD8:o=Array(r),s=e.readUint64;break;case n.SLONG8:o=Array(r),s=e.readInt64;break;case n.RATIONAL:o=new Uint32Array(r*2),s=e.readUint32;break;case n.SRATIONAL:o=new Int32Array(r*2),s=e.readInt32;break;case n.FLOAT:o=new Float32Array(r),s=e.readFloat32;break;case n.DOUBLE:o=new Float64Array(r),s=e.readFloat64}if(o===null||s===null)throw RangeError(`Invalid field type: ${t}`);if(t!==n.RATIONAL&&t!==n.SRATIONAL)for(let t=0;t<r;++t)o[t]=s.call(e,a+t*c);else for(let t=0;t<r;t+=2)o[t]=s.call(e,a+t*c),o[t+1]=s.call(e,a+(t*c+4));return t===n.ASCII?new TextDecoder(`utf-8`).decode(o):o}var Q=class extends Error{constructor(e){super(`No image at index ${e}`),this.index=e}},Et=class{async getImage(e=0){throw Error(`Not implemented`)}async getImageCount(){throw Error(`Not implemented`)}async readRasters(e={}){let{window:t,width:n,height:r}=e,{resX:i,resY:a,bbox:o}=e,s=await this.getImage(),c=s,l=await this.getImageCount(),u=s.getBoundingBox();if(t&&o)throw Error(`Both "bbox" and "window" passed.`);if(n||r){if(t){let[e,n]=s.getOrigin(),[r,i]=s.getResolution();o=[e+t[0]*r,n+t[1]*i,e+t[2]*r,n+t[3]*i]}let e=o||u;if(n){if(i)throw Error(`Both width and resX passed`);i=(e[2]-e[0])/n}if(r){if(a)throw Error(`Both width and resY passed`);a=(e[3]-e[1])/r}}if(i||a){let e=[];for(let t=0;t<l;++t){let n=await this.getImage(t),r=n.fileDirectory.getValue(`SubfileType`),i=n.fileDirectory.getValue(`NewSubfileType`);(t===0||r===2||(i||0)&1)&&e.push(n)}e.sort((e,t)=>e.getWidth()-t.getWidth());for(let t=0;t<e.length;++t){let n=e[t],r=(u[2]-u[0])/n.getWidth(),o=(u[3]-u[1])/n.getHeight();if(c=n,i&&i>r||a&&a>o)break}}let d=t;if(o){let[e,t]=s.getOrigin(),[n,r]=c.getResolution(s);d=[Math.round((o[0]-e)/n),Math.round((o[1]-t)/r),Math.round((o[2]-e)/n),Math.round((o[3]-t)/r)],d=[Math.min(d[0],d[2]),Math.min(d[1],d[3]),Math.max(d[0],d[2]),Math.max(d[1],d[3])]}return c.readRasters({...e,window:d})}},Dt=class e extends Et{constructor(e,t,n,r,i={}){super(),this.source=e,this.parser=new Tt(e,t,n,!1),this.littleEndian=t,this.bigTiff=n,this.firstIFDOffset=r,this.cache=i.cache||!1,this.ifdRequests=[],this.ghostValues=null}async getSlice(e,t){let n=this.bigTiff?4048:1024;return new q((await this.source.fetch([{offset:e,length:t===void 0?n:t}]))[0],e,this.littleEndian,this.bigTiff)}async requestIFD(e){if(this.ifdRequests[e])return this.ifdRequests[e];if(e===0)return this.ifdRequests[e]=this.parser.parseFileDirectoryAt(this.firstIFDOffset),this.ifdRequests[e];if(!this.ifdRequests[e-1])try{this.ifdRequests[e-1]=this.requestIFD(e-1)}catch(t){throw t instanceof Q?new Q(e):t}return this.ifdRequests[e]=(async()=>{let t=this.ifdRequests[e-1];if(!t)throw Error(`Previous IFD request missing`);let n=await t;if(n.nextIFDByteOffset===0)throw new Q(e);return this.parser.parseFileDirectoryAt(n.nextIFDByteOffset)})(),this.ifdRequests[e]}async getImage(e=0){return new vt(await this.requestIFD(e),this.littleEndian,this.cache,this.source)}async getImageCount(){let e=0,t=!0;for(;t;)try{await this.requestIFD(e),++e}catch(e){if(e instanceof Q)t=!1;else throw e}return e}async getGhostValues(){let e=this.bigTiff?16:8;if(this.ghostValues!==null)return this.ghostValues;let t=await this.getSlice(e,130);if(Z(t,n.ASCII,30,e)===`GDAL_STRUCTURAL_METADATA_SIZE=`){let r=Z(t,n.ASCII,130,e).split(`
4
4
  `)[0],i=Number(r.split(`=`)[1].split(` `)[0])+r.length;i>130&&(t=await this.getSlice(e,i));let a=Z(t,n.ASCII,i,e),o={};a.split(`
5
5
  `).filter(e=>e.length>0).map(e=>e.split(`=`)).forEach(([e,t])=>{o[e]=t}),this.ghostValues=o}return this.ghostValues}static async fromSource(t,n,r){let i=(await t.fetch([{offset:0,length:1024}],r))[0],a=new yt(i),o=a.getUint16(0,!1),s;if(o===18761)s=!0;else if(o===19789)s=!1;else throw TypeError(`Invalid byte order value.`);let c=a.getUint16(2,s),l;if(c===42)l=!1;else if(c===43){if(l=!0,a.getUint16(4,s)!==8)throw Error(`Unsupported offset byte-size.`)}else throw TypeError(`Invalid magic number.`);let u=l?a.getUint64(8,s):a.getUint32(4,s);return new e(t,s,l,u,n)}close(){return typeof this.source.close==`function`&&this.source.close()}};async function Ot(e,t){return Dt.fromSource(St(e),void 0,t)}var kt=1024;function At(t,n){if(!Number.isSafeInteger(t)||!Number.isSafeInteger(n)||t<=0||n<=0)throw new e(`invalid-file`,`图片尺寸无效。`);let r=t*n;if(!Number.isSafeInteger(r))throw new e(`resource-limit`,`图片尺寸超出安全范围。`);if(r>67108864)throw new e(`resource-limit`,`图片解码后超过 64 Mi 像素上限。`);return r}var jt={1:`none`,5:`LZW`,7:`JPEG`,8:`Deflate`,32946:`Deflate`,32773:`PackBits`,34887:`LERC`,5e4:`Zstandard`,50001:`WebP`};function $(t=`TIFF 文件损坏或使用了不支持的变体。`){throw new e(`invalid-file`,t)}function Mt(e,t,n,r){if(r===1)return{rgba:e,width:t,height:n};let i=r>=5&&r<=8,a=i?n:t,o=i?t:n,s=new Uint8ClampedArray(e.length);for(let i=0;i<n;i+=1)for(let o=0;o<t;o+=1){let c,l;switch(r){case 2:c=t-1-o,l=i;break;case 3:c=t-1-o,l=n-1-i;break;case 4:c=o,l=n-1-i;break;case 5:c=i,l=o;break;case 6:c=n-1-i,l=o;break;case 7:c=n-1-i,l=t-1-o;break;case 8:c=i,l=t-1-o;break;default:c=o,l=i}let u=(i*t+o)*4,d=(l*a+c)*4;s[d]=e[u],s[d+1]=e[u+1],s[d+2]=e[u+2],s[d+3]=e[u+3]}return{rgba:s,width:a,height:o}}async function Nt(e,t,n){let r=await Ot(e,n),i=new Uint8Array(await e.slice(0,4).arrayBuffer());return Pt(r,t,n,i[0]===73?i[2]===43:i[3]===43)}async function Pt(t,n,r,i){let a=await t.getImageCount();if(a<1||a>1024)throw new e(`resource-limit`,`TIFF 页数超过 ${kt} 页上限。`);(!Number.isInteger(n)||n<0||n>=a)&&$(`TIFF 页码无效。`);let o=await t.getImage(n),s=o.getWidth(),c=o.getHeight(),l=At(s,c),u=o.getFileDirectory(),d=await u.loadValue(`SampleFormat`);(d==null?[1]:Array.from(d)).some(e=>e!==1)&&$(`通用 TIFF 查看器不把有符号或浮点样本误作普通颜色图片。`);let f=await u.loadValue(`BitsPerSample`),p=f==null?[8]:Array.from(f);p.some(e=>e<1||e>16)&&$(`当前 TIFF 查看器只支持每通道 1–16 bit 的整数样本。`);let m=Math.max(...p),h=await o.readRGB({interleave:!0,enableAlpha:!0,signal:r}),g=h.length/l;g!==3&&g!==4&&$();let _=Number(await u.loadValue(`PhotometricInterpretation`)??1)===2?2**m-1:255,v=new Uint8ClampedArray(l*4),y=await u.loadValue(`ExtraSamples`),b=y==null?[]:Array.from(y),x=g===4&&b[0]===1;for(let e=0;e<l;e+=1){let t=e*g,n=e*4,r=Math.round(Number(h[t])*255/_),i=Math.round(Number(h[t+1])*255/_),a=Math.round(Number(h[t+2])*255/_),o=g===4?Math.round(Number(h[t+3])*255/_):255;x&&o>0&&o<255&&(r=Math.min(255,Math.round(r*255/o)),i=Math.min(255,Math.round(i*255/o)),a=Math.min(255,Math.round(a*255/o))),v[n]=r,v[n+1]=i,v[n+2]=a,v[n+3]=o}let S=Number(await u.loadValue(`Orientation`)??1),C=S>=1&&S<=8?S:1,w=Mt(v,s,c,C),T=u.hasTag(`ICCProfile`),ee=Number(await u.loadValue(`Compression`)??1);return{width:w.width,height:w.height,rgba:w.rgba,format:i?`BigTIFF`:`TIFF`,bitDepth:m,hasAlpha:g===4,colorSpace:T?`unknown`:`sRGB`,orientation:C,orientationApplied:!0,icc:T?`preserved-not-applied`:`none`,pageIndex:n,pageCount:a,tiled:o.isTiled,compression:jt[ee]??`TIFF ${ee}`}}export{Nt as decodeTiff,f as n,p as t};
@@ -1 +1 @@
1
- import{a as e,o as t}from"./index-BCxD9rBl.js";import{a as n,l as r,n as i,r as a,t as o}from"./id3-uzaDmDwy.js";import{n as s}from"./src-BMrLVJyB.js";var c=8388608,l=1;async function u(i,a,s){let l=new o({source:new r(i,{maxCacheSize:c}),formats:[n]}),u=()=>l.dispose();s.addEventListener(`abort`,u,{once:!0});try{if(s.aborted)throw t();if(!await l.canRead()||await l.getFormat()!==n)throw new e(`invalid-file`,`Invalid Insta360 MP4 container.`);let r=await l.getVideoTracks(),i=await l.getAudioTracks();if(r.length!==2||i.length!==1)throw new e(`invalid-file`,`Expected two video tracks and one audio track.`);let o=await Promise.all(r.flatMap(e=>[e.getCodedWidth(),e.getCodedHeight()])),c=await Promise.all([...r.map(e=>e.getCodec()),i[0].getCodec()]);if(o.some(e=>e!==a.width)||c[0]!==`hevc`||c[1]!==`hevc`||c[2]!==`aac`)throw new e(`invalid-file`,`Unexpected Insta360 media tracks.`);if(typeof VideoDecoder>`u`||typeof AudioDecoder>`u`)throw new e(`unsupported-environment`,`WebCodecs is unavailable.`);let d=await Promise.all([r[0].getFirstTimestamp(),r[1].getFirstTimestamp()]),f=await i[0].getFirstTimestamp(),p=Math.max(0,...d),m=await Promise.all([...r,i[0]].map(e=>l.getDurationFromMetadata([e],{skipLiveWait:!0}))),h=m.every(e=>e!==null&&Number.isFinite(e))?Math.min(...m):NaN;if(!Number.isFinite(p)||!Number.isFinite(f)||!Number.isFinite(h)||h<=p||f>=h)throw new e(`invalid-file`,`Invalid Insta360 track timeline.`);return s.removeEventListener(`abort`,u),{input:l,videos:[r[0],r[1]],audio:i[0],start:p,audioStart:f,duration:h}}catch(e){throw s.removeEventListener(`abort`,u),l.dispose(),s.aborted?t():e}}var d=class n{#e;#t;#n;#r;#i;#a;#o;#s;#c;#l;#u;#d;#f;#p;#m;#h;#g;#_;#v;#y;#b;#x;#S;#C;constructor(e,t,n,r,o){this.#l=new Set,this.#u=new Set,this.#d=[],this.#f=new Map,this.#m=0,this.#h=0,this.#g=0,this.#v=0,this.#y=Promise.resolve(),this.#b=!1,this.#x=!1,this.#S=!1,this.#C=!1,this.updateTimeline=()=>{if(!(!this.#x||this.#S)){if(this.#p=this.currentPosition(),this.updateControls(),this.#p>=this.#e.duration){this.#x=!1,this.cancelPipelines(),this.updateControls();return}this.#_=requestAnimationFrame(this.updateTimeline)}},this.#e=e,this.#n=t,this.#t=n,this.#r=r,this.#i=o,this.#p=e.start,this.#a=[new a(e.videos[0],{poolSize:2}),new a(e.videos[1],{poolSize:2})],this.#o=new i(e.audio),this.#s=new AudioContext({latencyHint:`playback`}),this.#c=this.#s.createGain(),this.#c.connect(this.#s.destination)}static async open(t,r,i,a,o,s,c){if(typeof AudioContext>`u`)throw new e(`unsupported-environment`,`Web Audio is unavailable.`);let l=await u(t,r,c),d=new n(l,i,a,o,s);d.listen(c,`abort`,()=>{d.dispose()});try{return await d.initialize(r,c),d}catch(t){throw await d.dispose(),t instanceof DOMException&&t.name===`AbortError`||t instanceof e?t:new e(`unsupported-environment`,`The browser could not decode the first HEVC frames.`,{cause:t})}}async initialize(n,r){if(r.aborted)throw t();let i=await Promise.all(this.#a.map(e=>e.getCanvas(this.#p)));if(r.aborted||this.#S)throw t();if(!i[0]||!i[1])throw new e(`invalid-file`,`The fisheye tracks have no first frame.`);let a=await this.#o.getBuffer(Math.max(this.#p,this.#e.audioStart));if(r.aborted||this.#S)throw t();if(!a)throw new e(`invalid-file`,`The audio track has no first buffer.`);this.#t.setDualFrames(i[0].canvas,i[1].canvas,n.width,n.height,this.#n);let{play:o,seek:s,volume:c,viewport:l}=this.#r;if(!o||!s||!c)throw new e(`open-failed`,`Missing playback controls.`);this.listen(o,`click`,()=>void this.toggle()),this.listen(s,`input`,()=>{this.previewSeek(Number(s.value))}),this.listen(s,`change`,()=>void this.seek(Number(s.value)).catch(()=>this.fail())),this.listen(c,`input`,()=>{this.#c.gain.value=Number(c.value)}),this.listen(l,`keydown`,e=>{let t=e;t.key===` `&&(t.preventDefault(),this.toggle())}),this.updateControls()}listen(e,t,n){e.addEventListener(t,n),this.#d.push(()=>e.removeEventListener(t,n))}async toggle(){try{this.#x?this.pause():await this.play()}catch{this.fail()}}async play(){if(this.#S||this.#C||this.#x||(this.#p>=this.#e.duration-.001&&await this.seek(this.#e.start),await this.#s.resume(),this.#S))return;this.cancelPipelines();let e=this.#g;this.#x=!0,this.#m=this.#p,this.#h=this.#s.currentTime,this.updateControls(),this.runVideo(e).catch(()=>this.fail()),this.runAudio(e).catch(()=>this.fail()),this.updateTimeline()}pause(){this.#x&&(this.#p=this.currentPosition(),this.#x=!1,this.cancelPipelines(),this.updateControls())}previewSeek(e){if(this.#S||!Number.isFinite(e))return;this.#v+=1;let t=this.#x||this.#b;return this.#b=t,this.#x&&this.pause(),this.#p=Math.min(this.#e.duration,Math.max(this.#e.start,e)),this.updateControls(),this.#p}seek(e){let t=this.previewSeek(e);if(t===void 0)return Promise.resolve();let n=this.#v,r=this.#y.catch(()=>void 0).then(async()=>{if(this.#S||n!==this.#v)return;if(t>=this.#e.duration){this.#b=!1;return}let e=await Promise.all(this.#a.map(e=>e.getCanvas(t)));if(!(this.#S||n!==this.#v)){if(!e[0]||!e[1])throw Error(`No frames at requested time.`);this.#t.setDualFrames(e[0].canvas,e[1].canvas,3840,3840,this.#n),this.#b&&(this.#b=!1,await this.play())}});return this.#y=r,r}currentPosition(){return this.#x?Math.min(this.#e.duration,this.#m+this.#s.currentTime-this.#h):this.#p}async runVideo(e){let t=this.#a.map(e=>e.canvases(this.#p));t.forEach(e=>this.#l.add(e));try{for(;this.active(e);){let[n,r]=await Promise.all(t.map(e=>e.next()));if(n.done||r.done||!this.active(e))break;let i=n.value,a=r.value;if(await this.waitUntil(Math.max(i.timestamp,a.timestamp),e),!this.active(e))break;this.#t.setDualFrames(i.canvas,a.canvas,3840,3840,this.#n),this.onPlayback?.()}}finally{t.forEach(e=>this.#l.delete(e))}}async runAudio(e){let t=this.#o.buffers(Math.max(this.#p,this.#e.audioStart));this.#l.add(t);try{for(;this.active(e);){let n=await t.next();if(n.done||!this.active(e))break;let r=n.value;for(;this.active(e)&&r.timestamp-this.currentPosition()>l;)await this.delay(50);this.active(e)&&this.scheduleAudio(r)}}finally{this.#l.delete(t)}}scheduleAudio({buffer:e,timestamp:t,duration:n}){let r=this.#s.createBufferSource();r.buffer=e,r.connect(this.#c);let i=Math.max(0,this.#m-t);if(i>=n)return;let a=Math.max(this.#s.currentTime,this.#h+t-this.#m+i);r.addEventListener(`ended`,()=>this.#u.delete(r),{once:!0}),this.#u.add(r),r.start(a,i)}async waitUntil(e,t){for(;this.active(t);){let t=e-this.currentPosition();if(t<=0)return;await this.delay(Math.min(50,t*1e3))}}delay(e){return new Promise(t=>{let n=window.setTimeout(()=>{this.#f.delete(n),t()},e);this.#f.set(n,t)})}updateControls(){let{play:e,seek:t,time:n}=this.#r;if(!e||!t||!n)return;t.min=String(this.#e.start),t.max=String(this.#e.duration),t.value=String(this.#p),n.textContent=`${s(this.#p)} / ${s(this.#e.duration)}`;let r=this.#p>=this.#e.duration?this.#i.replay:this.#x?this.#i.pause:this.#i.play;e.textContent=r,e.setAttribute(`aria-label`,r)}active(e){return!this.#S&&!this.#C&&this.#x&&e===this.#g}cancelPipelines(){this.#g+=1;for(let e of this.#l)e.return(void 0);this.#l.clear();for(let e of this.#u){try{e.stop()}catch{}e.disconnect()}this.#u.clear(),this.#_!==void 0&&cancelAnimationFrame(this.#_),this.#_=void 0;for(let[e,t]of this.#f)clearTimeout(e),t();this.#f.clear()}fail(){this.#S||this.#C||(this.#p=this.currentPosition(),this.#x=!1,this.#C=!0,this.onFailure?.(),this.cancelPipelines(),this.#r.play&&(this.#r.play.disabled=!0),this.#r.seek&&(this.#r.seek.disabled=!0),this.#r.status.textContent=this.#i.playbackFailed)}async dispose(){if(!this.#S&&(this.#S=!0,this.#v+=1,this.#x=!1,this.cancelPipelines(),this.#d.splice(0).forEach(e=>e()),this.#c.disconnect(),this.#e.input.dispose(),this.#s.state!==`closed`))try{await this.#s.close()}catch{}}};export{d as DualTrackPlayback};
1
+ import{a as e,o as t}from"./index-DtiyOy_J.js";import{a as n,l as r,n as i,r as a,t as o}from"./id3-uzaDmDwy.js";import{n as s}from"./src-BIlLq0QT.js";var c=8388608,l=1;async function u(i,a,s){let l=new o({source:new r(i,{maxCacheSize:c}),formats:[n]}),u=()=>l.dispose();s.addEventListener(`abort`,u,{once:!0});try{if(s.aborted)throw t();if(!await l.canRead()||await l.getFormat()!==n)throw new e(`invalid-file`,`Invalid Insta360 MP4 container.`);let r=await l.getVideoTracks(),i=await l.getAudioTracks();if(r.length!==2||i.length!==1)throw new e(`invalid-file`,`Expected two video tracks and one audio track.`);let o=await Promise.all(r.flatMap(e=>[e.getCodedWidth(),e.getCodedHeight()])),c=await Promise.all([...r.map(e=>e.getCodec()),i[0].getCodec()]);if(o.some(e=>e!==a.width)||c[0]!==`hevc`||c[1]!==`hevc`||c[2]!==`aac`)throw new e(`invalid-file`,`Unexpected Insta360 media tracks.`);if(typeof VideoDecoder>`u`||typeof AudioDecoder>`u`)throw new e(`unsupported-environment`,`WebCodecs is unavailable.`);let d=await Promise.all([r[0].getFirstTimestamp(),r[1].getFirstTimestamp()]),f=await i[0].getFirstTimestamp(),p=Math.max(0,...d),m=await Promise.all([...r,i[0]].map(e=>l.getDurationFromMetadata([e],{skipLiveWait:!0}))),h=m.every(e=>e!==null&&Number.isFinite(e))?Math.min(...m):NaN;if(!Number.isFinite(p)||!Number.isFinite(f)||!Number.isFinite(h)||h<=p||f>=h)throw new e(`invalid-file`,`Invalid Insta360 track timeline.`);return s.removeEventListener(`abort`,u),{input:l,videos:[r[0],r[1]],audio:i[0],start:p,audioStart:f,duration:h}}catch(e){throw s.removeEventListener(`abort`,u),l.dispose(),s.aborted?t():e}}var d=class n{#e;#t;#n;#r;#i;#a;#o;#s;#c;#l;#u;#d;#f;#p;#m;#h;#g;#_;#v;#y;#b;#x;#S;#C;constructor(e,t,n,r,o){this.#l=new Set,this.#u=new Set,this.#d=[],this.#f=new Map,this.#m=0,this.#h=0,this.#g=0,this.#v=0,this.#y=Promise.resolve(),this.#b=!1,this.#x=!1,this.#S=!1,this.#C=!1,this.updateTimeline=()=>{if(!(!this.#x||this.#S)){if(this.#p=this.currentPosition(),this.updateControls(),this.#p>=this.#e.duration){this.#x=!1,this.cancelPipelines(),this.updateControls();return}this.#_=requestAnimationFrame(this.updateTimeline)}},this.#e=e,this.#n=t,this.#t=n,this.#r=r,this.#i=o,this.#p=e.start,this.#a=[new a(e.videos[0],{poolSize:2}),new a(e.videos[1],{poolSize:2})],this.#o=new i(e.audio),this.#s=new AudioContext({latencyHint:`playback`}),this.#c=this.#s.createGain(),this.#c.connect(this.#s.destination)}static async open(t,r,i,a,o,s,c){if(typeof AudioContext>`u`)throw new e(`unsupported-environment`,`Web Audio is unavailable.`);let l=await u(t,r,c),d=new n(l,i,a,o,s);d.listen(c,`abort`,()=>{d.dispose()});try{return await d.initialize(r,c),d}catch(t){throw await d.dispose(),t instanceof DOMException&&t.name===`AbortError`||t instanceof e?t:new e(`unsupported-environment`,`The browser could not decode the first HEVC frames.`,{cause:t})}}async initialize(n,r){if(r.aborted)throw t();let i=await Promise.all(this.#a.map(e=>e.getCanvas(this.#p)));if(r.aborted||this.#S)throw t();if(!i[0]||!i[1])throw new e(`invalid-file`,`The fisheye tracks have no first frame.`);let a=await this.#o.getBuffer(Math.max(this.#p,this.#e.audioStart));if(r.aborted||this.#S)throw t();if(!a)throw new e(`invalid-file`,`The audio track has no first buffer.`);this.#t.setDualFrames(i[0].canvas,i[1].canvas,n.width,n.height,this.#n);let{play:o,seek:s,volume:c,viewport:l}=this.#r;if(!o||!s||!c)throw new e(`open-failed`,`Missing playback controls.`);this.listen(o,`click`,()=>void this.toggle()),this.listen(s,`input`,()=>{this.previewSeek(Number(s.value))}),this.listen(s,`change`,()=>void this.seek(Number(s.value)).catch(()=>this.fail())),this.listen(c,`input`,()=>{this.#c.gain.value=Number(c.value)}),this.listen(l,`keydown`,e=>{let t=e;t.key===` `&&(t.preventDefault(),this.toggle())}),this.updateControls()}listen(e,t,n){e.addEventListener(t,n),this.#d.push(()=>e.removeEventListener(t,n))}async toggle(){try{this.#x?this.pause():await this.play()}catch{this.fail()}}async play(){if(this.#S||this.#C||this.#x||(this.#p>=this.#e.duration-.001&&await this.seek(this.#e.start),await this.#s.resume(),this.#S))return;this.cancelPipelines();let e=this.#g;this.#x=!0,this.#m=this.#p,this.#h=this.#s.currentTime,this.updateControls(),this.runVideo(e).catch(()=>this.fail()),this.runAudio(e).catch(()=>this.fail()),this.updateTimeline()}pause(){this.#x&&(this.#p=this.currentPosition(),this.#x=!1,this.cancelPipelines(),this.updateControls())}previewSeek(e){if(this.#S||!Number.isFinite(e))return;this.#v+=1;let t=this.#x||this.#b;return this.#b=t,this.#x&&this.pause(),this.#p=Math.min(this.#e.duration,Math.max(this.#e.start,e)),this.updateControls(),this.#p}seek(e){let t=this.previewSeek(e);if(t===void 0)return Promise.resolve();let n=this.#v,r=this.#y.catch(()=>void 0).then(async()=>{if(this.#S||n!==this.#v)return;if(t>=this.#e.duration){this.#b=!1;return}let e=await Promise.all(this.#a.map(e=>e.getCanvas(t)));if(!(this.#S||n!==this.#v)){if(!e[0]||!e[1])throw Error(`No frames at requested time.`);this.#t.setDualFrames(e[0].canvas,e[1].canvas,3840,3840,this.#n),this.#b&&(this.#b=!1,await this.play())}});return this.#y=r,r}currentPosition(){return this.#x?Math.min(this.#e.duration,this.#m+this.#s.currentTime-this.#h):this.#p}async runVideo(e){let t=this.#a.map(e=>e.canvases(this.#p));t.forEach(e=>this.#l.add(e));try{for(;this.active(e);){let[n,r]=await Promise.all(t.map(e=>e.next()));if(n.done||r.done||!this.active(e))break;let i=n.value,a=r.value;if(await this.waitUntil(Math.max(i.timestamp,a.timestamp),e),!this.active(e))break;this.#t.setDualFrames(i.canvas,a.canvas,3840,3840,this.#n),this.onPlayback?.()}}finally{t.forEach(e=>this.#l.delete(e))}}async runAudio(e){let t=this.#o.buffers(Math.max(this.#p,this.#e.audioStart));this.#l.add(t);try{for(;this.active(e);){let n=await t.next();if(n.done||!this.active(e))break;let r=n.value;for(;this.active(e)&&r.timestamp-this.currentPosition()>l;)await this.delay(50);this.active(e)&&this.scheduleAudio(r)}}finally{this.#l.delete(t)}}scheduleAudio({buffer:e,timestamp:t,duration:n}){let r=this.#s.createBufferSource();r.buffer=e,r.connect(this.#c);let i=Math.max(0,this.#m-t);if(i>=n)return;let a=Math.max(this.#s.currentTime,this.#h+t-this.#m+i);r.addEventListener(`ended`,()=>this.#u.delete(r),{once:!0}),this.#u.add(r),r.start(a,i)}async waitUntil(e,t){for(;this.active(t);){let t=e-this.currentPosition();if(t<=0)return;await this.delay(Math.min(50,t*1e3))}}delay(e){return new Promise(t=>{let n=window.setTimeout(()=>{this.#f.delete(n),t()},e);this.#f.set(n,t)})}updateControls(){let{play:e,seek:t,time:n}=this.#r;if(!e||!t||!n)return;t.min=String(this.#e.start),t.max=String(this.#e.duration),t.value=String(this.#p),n.textContent=`${s(this.#p)} / ${s(this.#e.duration)}`;let r=this.#p>=this.#e.duration?this.#i.replay:this.#x?this.#i.pause:this.#i.play;e.textContent=r,e.setAttribute(`aria-label`,r)}active(e){return!this.#S&&!this.#C&&this.#x&&e===this.#g}cancelPipelines(){this.#g+=1;for(let e of this.#l)e.return(void 0);this.#l.clear();for(let e of this.#u){try{e.stop()}catch{}e.disconnect()}this.#u.clear(),this.#_!==void 0&&cancelAnimationFrame(this.#_),this.#_=void 0;for(let[e,t]of this.#f)clearTimeout(e),t();this.#f.clear()}fail(){this.#S||this.#C||(this.#p=this.currentPosition(),this.#x=!1,this.#C=!0,this.onFailure?.(),this.cancelPipelines(),this.#r.play&&(this.#r.play.disabled=!0),this.#r.seek&&(this.#r.seek.disabled=!0),this.#r.status.textContent=this.#i.playbackFailed)}async dispose(){if(!this.#S&&(this.#S=!0,this.#v+=1,this.#x=!1,this.cancelPipelines(),this.#d.splice(0).forEach(e=>e()),this.#c.disconnect(),this.#e.input.dispose(),this.#s.state!==`closed`))try{await this.#s.close()}catch{}}};export{d as DualTrackPlayback};
@@ -1 +1 @@
1
- import{t as e}from"./src-rJN_jaC5.js";import{a as t}from"./index-BCxD9rBl.js";import{n}from"./client-Dp-p4unY.js";import{n as r}from"./src-BMrLVJyB.js";var i=268435456,a=class{#e;#t;constructor(e,t,n){this.duration=e,this.rate=t,this.channels=n,this.tracks=[[],[],[]],this.ends=[0,0,0],this.#e=0,this.#t=[-1/0,-1/0,-1/0]}get end(){return Math.min(...this.ends)}get full(){return this.#e>262905856}get firstFrames(){return[this.tracks[0][0],this.tracks[1][0]]}push(e){let n=e.kind===`audio`?2:e.lens;if(n!==0&&n!==1&&n!==2)throw new t(`invalid-file`,`Missing lens identity.`);if(!Number.isFinite(e.timestamp)||!Number.isFinite(e.duration)||e.duration<=0||e.duration>1||e.timestamp<this.#t[n]-.001||e.timestamp>this.duration+.1)throw new t(`invalid-file`,`Invalid panorama timeline.`);if(e.kind===`video`?e.width!==1920||e.height!==1920||e.data.byteLength!==5529600:e.sampleRate!==this.rate||e.channels!==this.channels||e.samples*e.channels*4!==e.data.byteLength)throw new t(`invalid-file`,`Invalid panorama frame.`);if(this.#e+e.data.byteLength>i||this.tracks[n].length>=128)throw new t(`resource-limit`,`Panorama queue exceeded its budget.`);this.#t[n]=e.timestamp,this.ends[n]=e.timestamp+e.duration,this.tracks[n].push(e),this.#e+=e.data.byteLength}shift(e){let t=this.tracks[e].shift();return t&&(this.#e-=t.data.byteLength),t}},o=.5,s=.7,c=.1,l=t=>e(t,{"zh-CN":{play:`播放`,pause:`暂停`,replay:`重播`,buffering:`正在缓冲全景视频…`,failed:`全景视频播放失败。`,limit:`当前设备无法在资源限制内解码此全景视频。`,software:`FFmpeg 软件解码 · 每路 1920×1920 预览;播放速度取决于设备性能。`},en:{play:`Play`,pause:`Pause`,replay:`Replay`,buffering:`Buffering panorama…`,failed:`Panorama playback failed.`,limit:`This device cannot decode the panorama within the resource limits.`,software:`FFmpeg software decoding · 1920×1920 per lens; playback speed depends on your device.`}}),u=class e{#e;#t;#n;#r;#i;#a;#o;#s;#c;#l;#u;#d;#f;#p;#m;#h;#g;#_;#v;#y;#b;#x;#S;constructor(e,t,n,r,i,o){this.client=e,this.info=t,this.renderer=n,this.projection=r,this.elements=i,this.#r=new Set,this.#i=new WeakSet,this.#a=0,this.#s=0,this.#c=0,this.#l=!1,this.#u=!1,this.#d=!1,this.#f=!1,this.#p=!1,this.#m=0,this.#h=Promise.resolve(),this.#b=[],this.tick=()=>{if(this.#f||this.#p||!this.#l)return;let e=this.position();if(this.#u){for(let t=0;t<2;t++)for(;this.#e.tracks[t][1]?.timestamp<=e;)this.#e.shift(t);for(this.drawFirst();this.#e.tracks[2][0]&&this.#e.tracks[2][0].timestamp+this.#e.tracks[2][0].duration<=e;)this.#e.shift(2);if(this.#d&&e>=this.#o-.001){this.stopClock(),this.#a=this.#o,this.#l=!1,this.update();return}!this.#d&&e>=this.#e.end-.005&&(this.stopClock(),this.elements.status.textContent=this.#S.buffering)}this.update(),this.#_=requestAnimationFrame(this.tick)},this.#o=t.duration,this.#e=new a(t.duration,t.sampleRate,t.channels),this.#S=l(o)}static async open(r,i,a,o,s,l){if(typeof VideoFrame>`u`||typeof AudioContext>`u`||typeof Worker>`u`)throw new t(`unsupported-environment`,`VideoFrame, Web Audio and Worker are required.`);let u=await n(l),d;try{let n=await u.openPanorama(r);if(l.throwIfAborted(),n.videoCodec!==`hevc`||n.audioCodec!==`aac`||n.width!==1920||n.height!==1920||!Number.isFinite(n.duration)||n.duration<=0||!n.audio)throw new t(`invalid-file`,`Unexpected panorama tracks.`);return d=new e(u,n,i,a,o,s),d.listen(l,`abort`,()=>{d?.dispose()}),await d.prime(0,0,c),l.throwIfAborted(),d.drawFirst(),d.bind(),d.update(),o.status.dataset.kind=`notice`,o.status.title=d.#S.software,o.status.textContent=d.#S.software,d}catch(e){throw u.dispose(),await d?.dispose(),l.throwIfAborted(),e}}listen(e,t,n){e.addEventListener(t,n),this.#b.push(()=>e.removeEventListener(t,n))}bind(){let{play:e,seek:n,volume:r,viewport:i}=this.elements;if(!e||!n||!r)throw new t(`open-failed`,`Missing video controls.`);this.listen(e,`click`,()=>this.toggle()),this.listen(n,`input`,()=>this.seek(Number(n.value))),this.listen(r,`input`,()=>{this.#n&&(this.#n.gain.value=Number(r.value))}),this.listen(i,`keydown`,e=>{e.key===` `&&(e.preventDefault(),this.toggle())})}toggle(){this.#l?this.pause():this.play().catch(e=>this.fail(e))}async play(){if(!(this.#f||this.#p||this.#l)&&(this.#l=!0,this.#t||(this.#t=new AudioContext({latencyHint:`playback`,sampleRate:this.info.sampleRate}),this.#n=this.#t.createGain(),this.#n.gain.value=Number(this.elements.volume.value),this.#n.connect(this.#t.destination)),await this.#t.resume(),!(this.#f||!this.#l))){if(this.#t.state!==`running`)throw new t(`unsupported-environment`,`Audio context did not resume.`);this.#a>=this.#o-.001&&(this.#a=0),this.restart()}}pause(){this.stopClock(),this.#l=!1,this.#m++,this.elements.status.textContent=this.#S.software,this.update()}seek(e){this.#f||this.#p||!Number.isFinite(e)||(this.stopClock(),this.#a=Math.max(0,Math.min(this.#o,e)),this.restart())}restart(){this.stopClock(),this.#m++,this.update(),this.elements.status.textContent=this.#S.buffering,!this.#g&&(this.#g=this.reconcile().catch(e=>this.fail(e)).finally(()=>{this.#g=void 0}))}async reconcile(){for(;!this.#f&&!this.#p;){let e=this.#m,t=this.#a;if(await this.#h,this.#f)return;if(e===this.#m){if(t>=this.#o-.001){this.#l=!1,this.update(),this.elements.status.textContent=this.#S.software;return}if(await this.client.seek(t),this.#f)return;if(e===this.#m){if(this.#e=new a(this.info.duration,this.info.sampleRate,this.info.channels),this.#d=!1,await this.prime(t,e,this.#l?o:c),this.#f)return;if(e===this.#m){if(this.drawFirst(),!this.#l){this.elements.status.textContent=this.#S.software,this.update();return}this.startClock(),this.#h=this.decode(e).catch(t=>{e===this.#m&&this.fail(t)}),this.tick();return}}}}}async pull(e,t){let n=await this.client.next();if(!(this.#f||t!==this.#m)){if(n.kind===`eof`){this.#d=!0,this.#o=Math.min(this.info.duration,this.#e.end);return}n.timestamp+n.duration>e&&this.#e.push(n)}}async prime(e,n,r){for(let i=0;i<8192&&!this.#f&&n===this.#m;i++){if(await this.pull(e,n),this.#f||n!==this.#m)return;if(this.#e.end>=e+r||this.#d){if(!this.#e.firstFrames.every(Boolean)||!this.#e.tracks[2].length)throw new t(`invalid-file`,`Missing panorama samples.`);return}}if(!this.#f&&n===this.#m)throw new t(`resource-limit`,`Panorama preroll exceeded its budget.`)}active(e){return!this.#f&&!this.#p&&this.#l&&e===this.#m}async decode(e){for(;this.active(e)&&!this.#d;){if(this.#e.end-this.position()>=s||this.#e.full){if(!this.#u&&this.#e.end<this.#a+o)throw new t(`resource-limit`,`Unbalanced panorama tracks.`);await this.waitForDrain();continue}if(await this.pull(this.position(),e),!this.active(e))return;this.#u?this.scheduleAudio():(this.#e.end>=this.#a+o||this.#d)&&this.startClock()}}waitForDrain(){return new Promise(e=>{let t=setTimeout(()=>{this.#v=void 0,e()},20);this.#v={timer:t,resolve:e}})}position(){return this.#u?Math.min(this.#o,this.#e.end,this.#s+Math.max(0,this.#t.currentTime-this.#c)):this.#a}startClock(){this.onPlayback?.(),this.#u=!0,this.#s=this.#a,this.#c=this.#t.currentTime+.02,this.elements.status.textContent=this.#S.software,this.scheduleAudio(),this.update()}stopClock(){this.#a=this.position(),this.#u=!1,this.#v&&=(clearTimeout(this.#v.timer),this.#v.resolve(),void 0),this.#_!==void 0&&cancelAnimationFrame(this.#_),this.#_=void 0;for(let e of this.#r)e.onended=null,e.stop(),e.disconnect(),e.buffer=null;this.#r.clear(),this.#i=new WeakSet}scheduleAudio(){let e=this.#t;for(let t of this.#e.tracks[2]){if(this.#i.has(t))continue;this.#i.add(t);let n=Math.max(0,Math.ceil((Math.max(this.#s,this.position())-t.timestamp)*t.sampleRate));if(n>=t.samples)continue;let r=e.createBuffer(t.channels,t.samples-n,t.sampleRate),i=new Float32Array(t.data);for(let e=0;e<t.channels;e++){let a=r.getChannelData(e);for(let r=0;r<a.length;r++)a[r]=i[(r+n)*t.channels+e]}let a=e.createBufferSource();a.buffer=r,a.connect(this.#n),this.#r.add(a),a.onended=()=>{this.#r.delete(a),a.disconnect(),a.buffer=null},a.start(Math.max(e.currentTime,this.#c+t.timestamp+n/t.sampleRate-this.#s))}}draw(e,t){if(this.#y?.[0]===e&&this.#y[1]===t)return;let n=[];try{for(let r of[e,t])n.push(new VideoFrame(r.data,{colorSpace:{primaries:`bt709`,transfer:`bt709`,matrix:`bt709`,fullRange:!1},format:`I420`,codedWidth:r.width,codedHeight:r.height,timestamp:Math.round(r.timestamp*1e6)}));this.renderer.setDualFrames(n[0],n[1],e.width,e.height,this.projection),this.#y=[e,t]}finally{n.forEach(e=>e.close())}}drawFirst(){let[e,t]=this.#e.firstFrames;e&&t&&!this.#f&&this.draw(e,t)}update(){let{play:e,seek:t,time:n}=this.elements;if(!e||!t||!n)return;let i=this.position();t.min=`0`,t.max=String(this.#o),t.value=String(i);let a=this.#l?this.#S.pause:i>=this.#o-.001?this.#S.replay:this.#S.play;e.textContent=a,e.setAttribute(`aria-label`,a),n.textContent=`${r(i)} / ${r(this.#o)}`}fail(e){!this.#f&&!this.#p&&this.onFailure?.(),!(this.#f||this.#p)&&(this.stopClock(),this.#p=!0,this.#l=!1,this.client.dispose(),this.elements.status.textContent=e instanceof t&&e.code===`resource-limit`?this.#S.limit:this.#S.failed,this.elements.status.setAttribute(`role`,`alert`),this.elements.play&&(this.elements.play.disabled=!0),this.elements.seek&&(this.elements.seek.disabled=!0),this.#y=void 0,this.#e=new a(this.info.duration,this.info.sampleRate,this.info.channels),this.#n?.disconnect(),this.#t?.close().catch(()=>{}))}dispose(){return this.#x?this.#x:(this.stopClock(),this.#f=!0,this.#m++,this.#l=!1,this.client.dispose(),this.#b.splice(0).forEach(e=>e()),this.#n?.disconnect(),this.#y=void 0,this.#e=new a(this.info.duration,this.info.sampleRate,this.info.channels),this.#x=this.#t&&this.#t.state!==`closed`?this.#t.close().catch(()=>{}):Promise.resolve(),this.#x)}};export{u as FfmpegPanoramaPlayback};
1
+ import{t as e}from"./src-rJN_jaC5.js";import{a as t}from"./index-DtiyOy_J.js";import{n}from"./client-CU2ERPtk.js";import{n as r}from"./src-BIlLq0QT.js";var i=268435456,a=class{#e;#t;constructor(e,t,n){this.duration=e,this.rate=t,this.channels=n,this.tracks=[[],[],[]],this.ends=[0,0,0],this.#e=0,this.#t=[-1/0,-1/0,-1/0]}get end(){return Math.min(...this.ends)}get full(){return this.#e>262905856}get firstFrames(){return[this.tracks[0][0],this.tracks[1][0]]}push(e){let n=e.kind===`audio`?2:e.lens;if(n!==0&&n!==1&&n!==2)throw new t(`invalid-file`,`Missing lens identity.`);if(!Number.isFinite(e.timestamp)||!Number.isFinite(e.duration)||e.duration<=0||e.duration>1||e.timestamp<this.#t[n]-.001||e.timestamp>this.duration+.1)throw new t(`invalid-file`,`Invalid panorama timeline.`);if(e.kind===`video`?e.width!==1920||e.height!==1920||e.data.byteLength!==5529600:e.sampleRate!==this.rate||e.channels!==this.channels||e.samples*e.channels*4!==e.data.byteLength)throw new t(`invalid-file`,`Invalid panorama frame.`);if(this.#e+e.data.byteLength>i||this.tracks[n].length>=128)throw new t(`resource-limit`,`Panorama queue exceeded its budget.`);this.#t[n]=e.timestamp,this.ends[n]=e.timestamp+e.duration,this.tracks[n].push(e),this.#e+=e.data.byteLength}shift(e){let t=this.tracks[e].shift();return t&&(this.#e-=t.data.byteLength),t}},o=.5,s=.7,c=.1,l=t=>e(t,{"zh-CN":{play:`播放`,pause:`暂停`,replay:`重播`,buffering:`正在缓冲全景视频…`,failed:`全景视频播放失败。`,limit:`当前设备无法在资源限制内解码此全景视频。`,software:`FFmpeg 软件解码 · 每路 1920×1920 预览;播放速度取决于设备性能。`},en:{play:`Play`,pause:`Pause`,replay:`Replay`,buffering:`Buffering panorama…`,failed:`Panorama playback failed.`,limit:`This device cannot decode the panorama within the resource limits.`,software:`FFmpeg software decoding · 1920×1920 per lens; playback speed depends on your device.`}}),u=class e{#e;#t;#n;#r;#i;#a;#o;#s;#c;#l;#u;#d;#f;#p;#m;#h;#g;#_;#v;#y;#b;#x;#S;constructor(e,t,n,r,i,o){this.client=e,this.info=t,this.renderer=n,this.projection=r,this.elements=i,this.#r=new Set,this.#i=new WeakSet,this.#a=0,this.#s=0,this.#c=0,this.#l=!1,this.#u=!1,this.#d=!1,this.#f=!1,this.#p=!1,this.#m=0,this.#h=Promise.resolve(),this.#b=[],this.tick=()=>{if(this.#f||this.#p||!this.#l)return;let e=this.position();if(this.#u){for(let t=0;t<2;t++)for(;this.#e.tracks[t][1]?.timestamp<=e;)this.#e.shift(t);for(this.drawFirst();this.#e.tracks[2][0]&&this.#e.tracks[2][0].timestamp+this.#e.tracks[2][0].duration<=e;)this.#e.shift(2);if(this.#d&&e>=this.#o-.001){this.stopClock(),this.#a=this.#o,this.#l=!1,this.update();return}!this.#d&&e>=this.#e.end-.005&&(this.stopClock(),this.elements.status.textContent=this.#S.buffering)}this.update(),this.#_=requestAnimationFrame(this.tick)},this.#o=t.duration,this.#e=new a(t.duration,t.sampleRate,t.channels),this.#S=l(o)}static async open(r,i,a,o,s,l){if(typeof VideoFrame>`u`||typeof AudioContext>`u`||typeof Worker>`u`)throw new t(`unsupported-environment`,`VideoFrame, Web Audio and Worker are required.`);let u=await n(l),d;try{let n=await u.openPanorama(r);if(l.throwIfAborted(),n.videoCodec!==`hevc`||n.audioCodec!==`aac`||n.width!==1920||n.height!==1920||!Number.isFinite(n.duration)||n.duration<=0||!n.audio)throw new t(`invalid-file`,`Unexpected panorama tracks.`);return d=new e(u,n,i,a,o,s),d.listen(l,`abort`,()=>{d?.dispose()}),await d.prime(0,0,c),l.throwIfAborted(),d.drawFirst(),d.bind(),d.update(),o.status.dataset.kind=`notice`,o.status.title=d.#S.software,o.status.textContent=d.#S.software,d}catch(e){throw u.dispose(),await d?.dispose(),l.throwIfAborted(),e}}listen(e,t,n){e.addEventListener(t,n),this.#b.push(()=>e.removeEventListener(t,n))}bind(){let{play:e,seek:n,volume:r,viewport:i}=this.elements;if(!e||!n||!r)throw new t(`open-failed`,`Missing video controls.`);this.listen(e,`click`,()=>this.toggle()),this.listen(n,`input`,()=>this.seek(Number(n.value))),this.listen(r,`input`,()=>{this.#n&&(this.#n.gain.value=Number(r.value))}),this.listen(i,`keydown`,e=>{e.key===` `&&(e.preventDefault(),this.toggle())})}toggle(){this.#l?this.pause():this.play().catch(e=>this.fail(e))}async play(){if(!(this.#f||this.#p||this.#l)&&(this.#l=!0,this.#t||(this.#t=new AudioContext({latencyHint:`playback`,sampleRate:this.info.sampleRate}),this.#n=this.#t.createGain(),this.#n.gain.value=Number(this.elements.volume.value),this.#n.connect(this.#t.destination)),await this.#t.resume(),!(this.#f||!this.#l))){if(this.#t.state!==`running`)throw new t(`unsupported-environment`,`Audio context did not resume.`);this.#a>=this.#o-.001&&(this.#a=0),this.restart()}}pause(){this.stopClock(),this.#l=!1,this.#m++,this.elements.status.textContent=this.#S.software,this.update()}seek(e){this.#f||this.#p||!Number.isFinite(e)||(this.stopClock(),this.#a=Math.max(0,Math.min(this.#o,e)),this.restart())}restart(){this.stopClock(),this.#m++,this.update(),this.elements.status.textContent=this.#S.buffering,!this.#g&&(this.#g=this.reconcile().catch(e=>this.fail(e)).finally(()=>{this.#g=void 0}))}async reconcile(){for(;!this.#f&&!this.#p;){let e=this.#m,t=this.#a;if(await this.#h,this.#f)return;if(e===this.#m){if(t>=this.#o-.001){this.#l=!1,this.update(),this.elements.status.textContent=this.#S.software;return}if(await this.client.seek(t),this.#f)return;if(e===this.#m){if(this.#e=new a(this.info.duration,this.info.sampleRate,this.info.channels),this.#d=!1,await this.prime(t,e,this.#l?o:c),this.#f)return;if(e===this.#m){if(this.drawFirst(),!this.#l){this.elements.status.textContent=this.#S.software,this.update();return}this.startClock(),this.#h=this.decode(e).catch(t=>{e===this.#m&&this.fail(t)}),this.tick();return}}}}}async pull(e,t){let n=await this.client.next();if(!(this.#f||t!==this.#m)){if(n.kind===`eof`){this.#d=!0,this.#o=Math.min(this.info.duration,this.#e.end);return}n.timestamp+n.duration>e&&this.#e.push(n)}}async prime(e,n,r){for(let i=0;i<8192&&!this.#f&&n===this.#m;i++){if(await this.pull(e,n),this.#f||n!==this.#m)return;if(this.#e.end>=e+r||this.#d){if(!this.#e.firstFrames.every(Boolean)||!this.#e.tracks[2].length)throw new t(`invalid-file`,`Missing panorama samples.`);return}}if(!this.#f&&n===this.#m)throw new t(`resource-limit`,`Panorama preroll exceeded its budget.`)}active(e){return!this.#f&&!this.#p&&this.#l&&e===this.#m}async decode(e){for(;this.active(e)&&!this.#d;){if(this.#e.end-this.position()>=s||this.#e.full){if(!this.#u&&this.#e.end<this.#a+o)throw new t(`resource-limit`,`Unbalanced panorama tracks.`);await this.waitForDrain();continue}if(await this.pull(this.position(),e),!this.active(e))return;this.#u?this.scheduleAudio():(this.#e.end>=this.#a+o||this.#d)&&this.startClock()}}waitForDrain(){return new Promise(e=>{let t=setTimeout(()=>{this.#v=void 0,e()},20);this.#v={timer:t,resolve:e}})}position(){return this.#u?Math.min(this.#o,this.#e.end,this.#s+Math.max(0,this.#t.currentTime-this.#c)):this.#a}startClock(){this.onPlayback?.(),this.#u=!0,this.#s=this.#a,this.#c=this.#t.currentTime+.02,this.elements.status.textContent=this.#S.software,this.scheduleAudio(),this.update()}stopClock(){this.#a=this.position(),this.#u=!1,this.#v&&=(clearTimeout(this.#v.timer),this.#v.resolve(),void 0),this.#_!==void 0&&cancelAnimationFrame(this.#_),this.#_=void 0;for(let e of this.#r)e.onended=null,e.stop(),e.disconnect(),e.buffer=null;this.#r.clear(),this.#i=new WeakSet}scheduleAudio(){let e=this.#t;for(let t of this.#e.tracks[2]){if(this.#i.has(t))continue;this.#i.add(t);let n=Math.max(0,Math.ceil((Math.max(this.#s,this.position())-t.timestamp)*t.sampleRate));if(n>=t.samples)continue;let r=e.createBuffer(t.channels,t.samples-n,t.sampleRate),i=new Float32Array(t.data);for(let e=0;e<t.channels;e++){let a=r.getChannelData(e);for(let r=0;r<a.length;r++)a[r]=i[(r+n)*t.channels+e]}let a=e.createBufferSource();a.buffer=r,a.connect(this.#n),this.#r.add(a),a.onended=()=>{this.#r.delete(a),a.disconnect(),a.buffer=null},a.start(Math.max(e.currentTime,this.#c+t.timestamp+n/t.sampleRate-this.#s))}}draw(e,t){if(this.#y?.[0]===e&&this.#y[1]===t)return;let n=[];try{for(let r of[e,t])n.push(new VideoFrame(r.data,{colorSpace:{primaries:`bt709`,transfer:`bt709`,matrix:`bt709`,fullRange:!1},format:`I420`,codedWidth:r.width,codedHeight:r.height,timestamp:Math.round(r.timestamp*1e6)}));this.renderer.setDualFrames(n[0],n[1],e.width,e.height,this.projection),this.#y=[e,t]}finally{n.forEach(e=>e.close())}}drawFirst(){let[e,t]=this.#e.firstFrames;e&&t&&!this.#f&&this.draw(e,t)}update(){let{play:e,seek:t,time:n}=this.elements;if(!e||!t||!n)return;let i=this.position();t.min=`0`,t.max=String(this.#o),t.value=String(i);let a=this.#l?this.#S.pause:i>=this.#o-.001?this.#S.replay:this.#S.play;e.textContent=a,e.setAttribute(`aria-label`,a),n.textContent=`${r(i)} / ${r(this.#o)}`}fail(e){!this.#f&&!this.#p&&this.onFailure?.(),!(this.#f||this.#p)&&(this.stopClock(),this.#p=!0,this.#l=!1,this.client.dispose(),this.elements.status.textContent=e instanceof t&&e.code===`resource-limit`?this.#S.limit:this.#S.failed,this.elements.status.setAttribute(`role`,`alert`),this.elements.play&&(this.elements.play.disabled=!0),this.elements.seek&&(this.elements.seek.disabled=!0),this.#y=void 0,this.#e=new a(this.info.duration,this.info.sampleRate,this.info.channels),this.#n?.disconnect(),this.#t?.close().catch(()=>{}))}dispose(){return this.#x?this.#x:(this.stopClock(),this.#f=!0,this.#m++,this.#l=!1,this.client.dispose(),this.#b.splice(0).forEach(e=>e()),this.#n?.disconnect(),this.#y=void 0,this.#e=new a(this.info.duration,this.info.sampleRate,this.info.channels),this.#x=this.#t&&this.#t.state!==`closed`?this.#t.close().catch(()=>{}):Promise.resolve(),this.#x)}};export{u as FfmpegPanoramaPlayback};
@@ -1 +1 @@
1
- import{t as e}from"./src-rJN_jaC5.js";import{a as t}from"./index-BCxD9rBl.js";import{A as n,B as r,C as i,Ct as a,D as o,E as s,F as c,G as l,H as u,I as d,J as f,K as p,L as m,M as h,N as g,O as ee,P as _,Q as v,St as y,T as te,U as b,V as x,X as ne,Y as re,Z as S,_ as ie,_t as ae,a as oe,at as se,ct as ce,d as le,dt as ue,et as de,ft as fe,g as C,gt as pe,i as me,it as he,j as ge,k as _e,l as ve,lt as w,m as T,n as ye,nt as be,o as E,ot as D,p as xe,pt as Se,q as Ce,r as we,rt as Te,s as Ee,st as O,tt as De,u as k,ut as Oe,v as ke,w as Ae,xt as A,y as je,z as j}from"./src-DsVDi0pr.js";import{i as Me,r as Ne,t as Pe}from"./resources-WcZvn3-C.js";function Fe(e,t){let n=new Map,r=new Set,i=(t,a)=>{if(!Number.isInteger(t)||t<0||t>=e.length)throw Error(`Invalid glTF node index`);if(r.has(t))throw Error(`Cyclic glTF nodes`);if(a>128)throw RangeError(`glTF hierarchy depth`);if(n.has(t)){let e=n.get(t);if(a+e>128)throw RangeError(`glTF hierarchy depth`);return e}r.add(t);let o=e[t].children??[];if(!Array.isArray(o)||o.length>4096)throw Error(`Invalid glTF children`);let s=0;for(let e of o)s=Math.max(s,1+i(e,a+1));return r.delete(t),n.set(t,s),s};for(let e of t)i(e,0);for(let t=0;t<e.length;t++)i(t,0)}function M(e,t){if(t===0)return console.warn(`THREE.BufferGeometryUtils.toTrianglesDrawMode(): Geometry already defined as triangles.`),e;if(t===2||t===1){let n=e.getIndex();if(n===null){let t=[],r=e.getAttribute(`position`);if(r!==void 0){for(let e=0;e<r.count;e++)t.push(e);e.setIndex(t),n=e.getIndex()}else return console.error(`THREE.BufferGeometryUtils.toTrianglesDrawMode(): Undefined position attribute. Processing not possible.`),e}let r=n.count-2,i=[];if(t===2)for(let e=1;e<=r;e++)i.push(n.getX(0)),i.push(n.getX(e)),i.push(n.getX(e+1));else for(let e=0;e<r;e++)e%2==0?(i.push(n.getX(e)),i.push(n.getX(e+1)),i.push(n.getX(e+2))):(i.push(n.getX(e+2)),i.push(n.getX(e+1)),i.push(n.getX(e)));i.length/3!==r&&console.error(`THREE.BufferGeometryUtils.toTrianglesDrawMode(): Unable to generate correct amount of triangles.`);let a=e.clone();return a.setIndex(i),a.clearGroups(),a}return console.error(`THREE.BufferGeometryUtils.toTrianglesDrawMode(): Unknown draw mode:`,t),e}function Ie(e){let t=new Map,n=new Map,r=e.clone();return N(e,r,function(e,r){t.set(r,e),n.set(e,r)}),r.traverse(function(e){if(!e.isSkinnedMesh)return;let r=e,i=t.get(e),a=i.skeleton.bones;r.skeleton=i.skeleton.clone(),r.bindMatrix.copy(i.bindMatrix),r.skeleton.bones=a.map(function(e){return n.get(e)}),r.bind(r.skeleton,r.bindMatrix)}),r}function N(e,t,n){n(e,t);for(let r=0;r<e.children.length;r++)N(e.children[r],t.children[r],n)}var Le=class extends d{constructor(e){super(e),this.dracoLoader=null,this.ktx2Loader=null,this.meshoptDecoder=null,this.pluginCallbacks=[],this.register(function(e){return new He(e)}),this.register(function(e){return new Ue(e)}),this.register(function(e){return new Qe(e)}),this.register(function(e){return new $e(e)}),this.register(function(e){return new et(e)}),this.register(function(e){return new Ge(e)}),this.register(function(e){return new Ke(e)}),this.register(function(e){return new qe(e)}),this.register(function(e){return new Je(e)}),this.register(function(e){return new Ve(e)}),this.register(function(e){return new Ye(e)}),this.register(function(e){return new We(e)}),this.register(function(e){return new Ze(e)}),this.register(function(e){return new Xe(e)}),this.register(function(e){return new ze(e)}),this.register(function(e){return new I(e,F.EXT_MESHOPT_COMPRESSION)}),this.register(function(e){return new I(e,F.KHR_MESHOPT_COMPRESSION)}),this.register(function(e){return new tt(e)})}load(e,t,n,r){let i=this,a;if(this.resourcePath!==``)a=this.resourcePath;else if(this.path!==``){let t=m.extractUrlBase(e);a=m.resolveURL(t,this.path)}else a=m.extractUrlBase(e);this.manager.itemStart(e);let o=function(t){r?r(t):console.error(t),i.manager.itemError(e),i.manager.itemEnd(e)},s=new T(this.manager);s.setPath(this.path),s.setResponseType(`arraybuffer`),s.setRequestHeader(this.requestHeader),s.setWithCredentials(this.withCredentials),s.load(e,function(n){try{i.parse(n,a,function(n){t(n),i.manager.itemEnd(e)},o)}catch(e){o(e)}},n,o)}setDRACOLoader(e){return this.dracoLoader=e,this}setKTX2Loader(e){return this.ktx2Loader=e,this}setMeshoptDecoder(e){return this.meshoptDecoder=e,this}register(e){return this.pluginCallbacks.indexOf(e)===-1&&this.pluginCallbacks.push(e),this}unregister(e){return this.pluginCallbacks.indexOf(e)!==-1&&this.pluginCallbacks.splice(this.pluginCallbacks.indexOf(e),1),this}parse(e,t,n,r){let i,a={},o={},s=new TextDecoder;if(typeof e==`string`)i=JSON.parse(e);else if(e instanceof ArrayBuffer){if(s.decode(new Uint8Array(e,0,4))===L){try{a[F.KHR_BINARY_GLTF]=new nt(e)}catch(e){r&&r(e);return}i=JSON.parse(a[F.KHR_BINARY_GLTF].content)}else i=JSON.parse(s.decode(e))}else i=e;if(i.asset===void 0||i.asset.version[0]<2){r&&r(Error(`THREE.GLTFLoader: Unsupported asset. glTF versions >=2.0 are supported.`));return}let c=new ht(i,{path:t||this.resourcePath||``,crossOrigin:this.crossOrigin,requestHeader:this.requestHeader,manager:this.manager,ktx2Loader:this.ktx2Loader,meshoptDecoder:this.meshoptDecoder});c.fileLoader.setRequestHeader(this.requestHeader);for(let e=0;e<this.pluginCallbacks.length;e++){let t=this.pluginCallbacks[e](c);t.name||console.error(`THREE.GLTFLoader: Invalid plugin found: missing name`),o[t.name]=t,a[t.name]=!0}if(i.extensionsUsed)for(let e=0;e<i.extensionsUsed.length;++e){let t=i.extensionsUsed[e],n=i.extensionsRequired||[];switch(t){case F.KHR_MATERIALS_UNLIT:a[t]=new Be;break;case F.KHR_DRACO_MESH_COMPRESSION:a[t]=new rt(i,this.dracoLoader);break;case F.KHR_TEXTURE_TRANSFORM:a[t]=new it;break;case F.KHR_MESH_QUANTIZATION:a[t]=new at;break;default:n.indexOf(t)>=0&&o[t]===void 0&&console.warn(`THREE.GLTFLoader: Unknown extension "`+t+`".`)}}c.setExtensions(a),c.setPlugins(o),c.parse(n,r)}parseAsync(e,t){let n=this;return new Promise(function(r,i){n.parse(e,t,r,i)})}};function Re(){let e={};return{get:function(t){return e[t]},add:function(t,n){e[t]=n},remove:function(t){delete e[t]},removeAll:function(){e={}}}}function P(e,t,n){let r=e.json.materials[t];return r.extensions&&r.extensions[n]?r.extensions[n]:null}var F={KHR_BINARY_GLTF:`KHR_binary_glTF`,KHR_DRACO_MESH_COMPRESSION:`KHR_draco_mesh_compression`,KHR_LIGHTS_PUNCTUAL:`KHR_lights_punctual`,KHR_MATERIALS_CLEARCOAT:`KHR_materials_clearcoat`,KHR_MATERIALS_DISPERSION:`KHR_materials_dispersion`,KHR_MATERIALS_IOR:`KHR_materials_ior`,KHR_MATERIALS_SHEEN:`KHR_materials_sheen`,KHR_MATERIALS_SPECULAR:`KHR_materials_specular`,KHR_MATERIALS_TRANSMISSION:`KHR_materials_transmission`,KHR_MATERIALS_IRIDESCENCE:`KHR_materials_iridescence`,KHR_MATERIALS_ANISOTROPY:`KHR_materials_anisotropy`,KHR_MATERIALS_UNLIT:`KHR_materials_unlit`,KHR_MATERIALS_VOLUME:`KHR_materials_volume`,KHR_TEXTURE_BASISU:`KHR_texture_basisu`,KHR_TEXTURE_TRANSFORM:`KHR_texture_transform`,KHR_MESH_QUANTIZATION:`KHR_mesh_quantization`,KHR_MATERIALS_EMISSIVE_STRENGTH:`KHR_materials_emissive_strength`,EXT_MATERIALS_BUMP:`EXT_materials_bump`,EXT_TEXTURE_WEBP:`EXT_texture_webp`,EXT_TEXTURE_AVIF:`EXT_texture_avif`,EXT_MESHOPT_COMPRESSION:`EXT_meshopt_compression`,KHR_MESHOPT_COMPRESSION:`KHR_meshopt_compression`,EXT_MESH_GPU_INSTANCING:`EXT_mesh_gpu_instancing`},ze=class{constructor(e){this.parser=e,this.name=F.KHR_LIGHTS_PUNCTUAL,this.cache={refs:{},uses:{}}}_markDefs(){let e=this.parser,t=this.parser.json.nodes||[];for(let n=0,r=t.length;n<r;n++){let r=t[n];r.extensions&&r.extensions[this.name]&&r.extensions[this.name].light!==void 0&&e._addNodeRef(this.cache,r.extensions[this.name].light)}}_loadLight(e){let t=this.parser,n=`light:`+e,r=t.cache.get(n);if(r)return r;let i=t.json,a=((i.extensions&&i.extensions[this.name]||{}).lights||[])[e],o,s=new k(16777215);a.color!==void 0&&s.setRGB(a.color[0],a.color[1],a.color[2],c);let l=a.range===void 0?0:a.range;switch(a.type){case`directional`:o=new xe(s),o.target.position.set(0,0,-1),o.add(o.target);break;case`point`:o=new be(s),o.distance=l;break;case`spot`:o=new Se(s),o.distance=l,a.spot=a.spot||{},a.spot.innerConeAngle=a.spot.innerConeAngle===void 0?0:a.spot.innerConeAngle,a.spot.outerConeAngle=a.spot.outerConeAngle===void 0?Math.PI/4:a.spot.outerConeAngle,o.angle=a.spot.outerConeAngle,o.penumbra=1-a.spot.innerConeAngle/a.spot.outerConeAngle,o.target.position.set(0,0,-1),o.add(o.target);break;default:throw Error(`THREE.GLTFLoader: Unexpected light type: `+a.type)}return o.position.set(0,0,0),X(o,a),a.intensity!==void 0&&(o.intensity=a.intensity),o.name=t.createUniqueName(a.name||`light_`+e),r=Promise.resolve(o),t.cache.add(n,r),r}getDependency(e,t){if(e===`light`)return this._loadLight(t)}createNodeAttachment(e){let t=this,n=this.parser,r=n.json.nodes[e],i=(r.extensions&&r.extensions[this.name]||{}).light;return i===void 0?null:this._loadLight(i).then(function(e){return n._getNodeRef(t.cache,i,e)})}},Be=class{constructor(){this.name=F.KHR_MATERIALS_UNLIT}getMaterialType(){return b}extendParams(e,t,n){let r=[];e.color=new k(1,1,1),e.opacity=1;let i=t.pbrMetallicRoughness;if(i){if(Array.isArray(i.baseColorFactor)){let t=i.baseColorFactor;e.color.setRGB(t[0],t[1],t[2],c),e.opacity=t[3]}i.baseColorTexture!==void 0&&r.push(n.assignTexture(e,`map`,i.baseColorTexture,w))}return Promise.all(r)}},Ve=class{constructor(e){this.parser=e,this.name=F.KHR_MATERIALS_EMISSIVE_STRENGTH}extendMaterialParams(e,t){let n=P(this.parser,e,this.name);return n===null||n.emissiveStrength!==void 0&&(t.emissiveIntensity=n.emissiveStrength),Promise.resolve()}},He=class{constructor(e){this.parser=e,this.name=F.KHR_MATERIALS_CLEARCOAT}getMaterialType(e){return P(this.parser,e,this.name)===null?null:l}extendMaterialParams(e,t){let n=P(this.parser,e,this.name);if(n===null)return Promise.resolve();let r=[];if(n.clearcoatFactor!==void 0&&(t.clearcoat=n.clearcoatFactor),n.clearcoatTexture!==void 0&&r.push(this.parser.assignTexture(t,`clearcoatMap`,n.clearcoatTexture)),n.clearcoatRoughnessFactor!==void 0&&(t.clearcoatRoughness=n.clearcoatRoughnessFactor),n.clearcoatRoughnessTexture!==void 0&&r.push(this.parser.assignTexture(t,`clearcoatRoughnessMap`,n.clearcoatRoughnessTexture)),n.clearcoatNormalTexture!==void 0&&(r.push(this.parser.assignTexture(t,`clearcoatNormalMap`,n.clearcoatNormalTexture)),n.clearcoatNormalTexture.scale!==void 0)){let e=n.clearcoatNormalTexture.scale;t.clearcoatNormalScale=new A(e,e)}return Promise.all(r)}},Ue=class{constructor(e){this.parser=e,this.name=F.KHR_MATERIALS_DISPERSION}getMaterialType(e){return P(this.parser,e,this.name)===null?null:l}extendMaterialParams(e,t){let n=P(this.parser,e,this.name);return n===null||(t.dispersion=n.dispersion===void 0?0:n.dispersion),Promise.resolve()}},We=class{constructor(e){this.parser=e,this.name=F.KHR_MATERIALS_IRIDESCENCE}getMaterialType(e){return P(this.parser,e,this.name)===null?null:l}extendMaterialParams(e,t){let n=P(this.parser,e,this.name);if(n===null)return Promise.resolve();let r=[];return n.iridescenceFactor!==void 0&&(t.iridescence=n.iridescenceFactor),n.iridescenceTexture!==void 0&&r.push(this.parser.assignTexture(t,`iridescenceMap`,n.iridescenceTexture)),n.iridescenceIor!==void 0&&(t.iridescenceIOR=n.iridescenceIor),t.iridescenceThicknessRange===void 0&&(t.iridescenceThicknessRange=[100,400]),n.iridescenceThicknessMinimum!==void 0&&(t.iridescenceThicknessRange[0]=n.iridescenceThicknessMinimum),n.iridescenceThicknessMaximum!==void 0&&(t.iridescenceThicknessRange[1]=n.iridescenceThicknessMaximum),n.iridescenceThicknessTexture!==void 0&&r.push(this.parser.assignTexture(t,`iridescenceThicknessMap`,n.iridescenceThicknessTexture)),Promise.all(r)}},Ge=class{constructor(e){this.parser=e,this.name=F.KHR_MATERIALS_SHEEN}getMaterialType(e){return P(this.parser,e,this.name)===null?null:l}extendMaterialParams(e,t){let n=P(this.parser,e,this.name);if(n===null)return Promise.resolve();let r=[];if(t.sheenColor=new k(0,0,0),t.sheenRoughness=0,t.sheen=1,n.sheenColorFactor!==void 0){let e=n.sheenColorFactor;t.sheenColor.setRGB(e[0],e[1],e[2],c)}return n.sheenRoughnessFactor!==void 0&&(t.sheenRoughness=n.sheenRoughnessFactor),n.sheenColorTexture!==void 0&&r.push(this.parser.assignTexture(t,`sheenColorMap`,n.sheenColorTexture,w)),n.sheenRoughnessTexture!==void 0&&r.push(this.parser.assignTexture(t,`sheenRoughnessMap`,n.sheenRoughnessTexture)),Promise.all(r)}},Ke=class{constructor(e){this.parser=e,this.name=F.KHR_MATERIALS_TRANSMISSION}getMaterialType(e){return P(this.parser,e,this.name)===null?null:l}extendMaterialParams(e,t){let n=P(this.parser,e,this.name);if(n===null)return Promise.resolve();let r=[];return n.transmissionFactor!==void 0&&(t.transmission=n.transmissionFactor),n.transmissionTexture!==void 0&&r.push(this.parser.assignTexture(t,`transmissionMap`,n.transmissionTexture)),Promise.all(r)}},qe=class{constructor(e){this.parser=e,this.name=F.KHR_MATERIALS_VOLUME}getMaterialType(e){return P(this.parser,e,this.name)===null?null:l}extendMaterialParams(e,t){let n=P(this.parser,e,this.name);if(n===null)return Promise.resolve();let r=[];t.thickness=n.thicknessFactor===void 0?0:n.thicknessFactor,n.thicknessTexture!==void 0&&r.push(this.parser.assignTexture(t,`thicknessMap`,n.thicknessTexture)),t.attenuationDistance=n.attenuationDistance||1/0;let i=n.attenuationColor||[1,1,1];return t.attenuationColor=new k().setRGB(i[0],i[1],i[2],c),Promise.all(r)}},Je=class{constructor(e){this.parser=e,this.name=F.KHR_MATERIALS_IOR}getMaterialType(e){return P(this.parser,e,this.name)===null?null:l}extendMaterialParams(e,t){let n=P(this.parser,e,this.name);return n===null?Promise.resolve():(t.ior=n.ior===void 0?1.5:n.ior,t.ior===0&&(t.ior=1e3),Promise.resolve())}},Ye=class{constructor(e){this.parser=e,this.name=F.KHR_MATERIALS_SPECULAR}getMaterialType(e){return P(this.parser,e,this.name)===null?null:l}extendMaterialParams(e,t){let n=P(this.parser,e,this.name);if(n===null)return Promise.resolve();let r=[];t.specularIntensity=n.specularFactor===void 0?1:n.specularFactor,n.specularTexture!==void 0&&r.push(this.parser.assignTexture(t,`specularIntensityMap`,n.specularTexture));let i=n.specularColorFactor||[1,1,1];return t.specularColor=new k().setRGB(i[0],i[1],i[2],c),n.specularColorTexture!==void 0&&r.push(this.parser.assignTexture(t,`specularColorMap`,n.specularColorTexture,w)),Promise.all(r)}},Xe=class{constructor(e){this.parser=e,this.name=F.EXT_MATERIALS_BUMP}getMaterialType(e){return P(this.parser,e,this.name)===null?null:l}extendMaterialParams(e,t){let n=P(this.parser,e,this.name);if(n===null)return Promise.resolve();let r=[];return t.bumpScale=n.bumpFactor===void 0?1:n.bumpFactor,n.bumpTexture!==void 0&&r.push(this.parser.assignTexture(t,`bumpMap`,n.bumpTexture)),Promise.all(r)}},Ze=class{constructor(e){this.parser=e,this.name=F.KHR_MATERIALS_ANISOTROPY}getMaterialType(e){return P(this.parser,e,this.name)===null?null:l}extendMaterialParams(e,t){let n=P(this.parser,e,this.name);if(n===null)return Promise.resolve();let r=[];return n.anisotropyStrength!==void 0&&(t.anisotropy=n.anisotropyStrength),n.anisotropyRotation!==void 0&&(t.anisotropyRotation=n.anisotropyRotation),n.anisotropyTexture!==void 0&&r.push(this.parser.assignTexture(t,`anisotropyMap`,n.anisotropyTexture)),Promise.all(r)}},Qe=class{constructor(e){this.parser=e,this.name=F.KHR_TEXTURE_BASISU}loadTexture(e){let t=this.parser,n=t.json,r=n.textures[e];if(!r.extensions||!r.extensions[this.name])return null;let i=r.extensions[this.name],a=t.options.ktx2Loader;if(!a){if(n.extensionsRequired&&n.extensionsRequired.indexOf(this.name)>=0)throw Error(`THREE.GLTFLoader: setKTX2Loader must be called before loading KTX2 textures`);return null}return t.loadTextureImage(e,i.source,a)}},$e=class{constructor(e){this.parser=e,this.name=F.EXT_TEXTURE_WEBP}loadTexture(e){let t=this.name,n=this.parser,r=n.json,i=r.textures[e];if(!i.extensions||!i.extensions[t])return null;let a=i.extensions[t],o=r.images[a.source],s=n.textureLoader;if(o.uri){let e=n.options.manager.getHandler(o.uri);e!==null&&(s=e)}return n.loadTextureImage(e,a.source,s)}},et=class{constructor(e){this.parser=e,this.name=F.EXT_TEXTURE_AVIF}loadTexture(e){let t=this.name,n=this.parser,r=n.json,i=r.textures[e];if(!i.extensions||!i.extensions[t])return null;let a=i.extensions[t],o=r.images[a.source],s=n.textureLoader;if(o.uri){let e=n.options.manager.getHandler(o.uri);e!==null&&(s=e)}return n.loadTextureImage(e,a.source,s)}},I=class{constructor(e,t){this.name=t,this.parser=e}loadBufferView(e){let t=this.parser.json,n=t.bufferViews[e];if(n.extensions&&n.extensions[this.name]){let e=n.extensions[this.name],r=this.parser.getDependency(`buffer`,e.buffer),i=this.parser.options.meshoptDecoder;if(!i||!i.supported){if(t.extensionsRequired&&t.extensionsRequired.indexOf(this.name)>=0)throw Error(`THREE.GLTFLoader: setMeshoptDecoder must be called before loading compressed files`);return null}return r.then(function(t){let n=e.byteOffset||0,r=e.byteLength||0,a=e.count,o=e.byteStride,s=new Uint8Array(t,n,r);return i.decodeGltfBufferAsync?i.decodeGltfBufferAsync(a,o,s,e.mode,e.filter).then(function(e){return e.buffer}):i.ready.then(function(){let t=new ArrayBuffer(a*o);return i.decodeGltfBuffer(new Uint8Array(t),a,o,s,e.mode,e.filter),t})})}return null}},tt=class{constructor(e){this.name=F.EXT_MESH_GPU_INSTANCING,this.parser=e}createNodeMesh(e){let t=this.parser.json,n=t.nodes[e];if(!n.extensions||!n.extensions[this.name]||n.mesh===void 0)return null;let r=t.meshes[n.mesh];for(let e of r.primitives)if(e.mode!==V.TRIANGLES&&e.mode!==V.TRIANGLE_STRIP&&e.mode!==V.TRIANGLE_FAN&&e.mode!==void 0)return null;let i=n.extensions[this.name].attributes,a=[],o={};for(let e in i)a.push(this.parser.getDependency(`accessor`,i[e]).then(t=>(o[e]=t,o[e])));return a.length<1?null:(a.push(this.parser.createNodeMesh(e)),Promise.all(a).then(e=>{let t=e.pop(),n=t.isGroup?t.children:[t],r=e[0].count,i=[];for(let e of n){let t=new x,n=new y,a=new D,s=new y(1,1,1),c=new je(e.geometry,e.material,r);for(let e=0;e<r;e++)o.TRANSLATION&&n.fromBufferAttribute(o.TRANSLATION,e),o.ROTATION&&a.fromBufferAttribute(o.ROTATION,e),o.SCALE&&s.fromBufferAttribute(o.SCALE,e),c.setMatrixAt(e,t.compose(n,a,s));for(let t in o)if(t===`_COLOR_0`){let e=o[t];c.instanceColor=new ke(e.array,e.itemSize,e.normalized)}else t!==`TRANSLATION`&&t!==`ROTATION`&&t!==`SCALE`&&e.geometry.setAttribute(t,o[t]);v.prototype.copy.call(c,e),this.parser.assignFinalMaterial(c),i.push(c)}return t.isGroup?(t.clear(),t.add(...i),t):i[0]}))}},L=`glTF`,R=12,z={JSON:1313821514,BIN:5130562},nt=class{constructor(e){this.name=F.KHR_BINARY_GLTF,this.content=null,this.body=null;let t=new DataView(e,0,R),n=new TextDecoder;if(this.header={magic:n.decode(new Uint8Array(e.slice(0,4))),version:t.getUint32(4,!0),length:t.getUint32(8,!0)},this.header.magic!==L)throw Error(`THREE.GLTFLoader: Unsupported glTF-Binary header.`);if(this.header.version<2)throw Error(`THREE.GLTFLoader: Legacy binary file detected.`);let r=this.header.length-R,i=new DataView(e,R),a=0;for(;a<r;){let t=i.getUint32(a,!0);a+=4;let r=i.getUint32(a,!0);if(a+=4,r===z.JSON){let r=new Uint8Array(e,R+a,t);this.content=n.decode(r)}else if(r===z.BIN){let n=R+a;this.body=e.slice(n,n+t)}a+=t}if(this.content===null)throw Error(`THREE.GLTFLoader: JSON content not found.`)}},rt=class{constructor(e,t){if(!t)throw Error(`THREE.GLTFLoader: No DRACOLoader instance provided.`);this.name=F.KHR_DRACO_MESH_COMPRESSION,this.json=e,this.dracoLoader=t,this.dracoLoader.preload()}decodePrimitive(e,t){let n=this.json,r=this.dracoLoader,i=e.extensions[this.name].bufferView,a=e.extensions[this.name].attributes,o={},s={},l={};for(let e in a){let t=K[e]||e.toLowerCase();o[t]=a[e]}for(let t in e.attributes){let r=K[t]||t.toLowerCase();if(a[t]!==void 0){let i=n.accessors[e.attributes[t]];l[r]=H[i.componentType].name,s[r]=i.normalized===!0}}return t.getDependency(`bufferView`,i).then(function(e){return new Promise(function(t,n){r.decodeDracoFile(e,function(e){for(let t in e.attributes){let n=e.attributes[t],r=s[t];r!==void 0&&(n.normalized=r)}t(e)},o,l,c,n)})})}},it=class{constructor(){this.name=F.KHR_TEXTURE_TRANSFORM}extendTexture(e,t){return(t.texCoord===void 0||t.texCoord===e.channel)&&t.offset===void 0&&t.rotation===void 0&&t.scale===void 0?e:(e=e.clone(),t.texCoord!==void 0&&(e.channel=t.texCoord),t.offset!==void 0&&e.offset.fromArray(t.offset),t.rotation!==void 0&&(e.rotation=t.rotation),t.scale!==void 0&&e.repeat.fromArray(t.scale),e.needsUpdate=!0,e)}},at=class{constructor(){this.name=F.KHR_MESH_QUANTIZATION}},B=class extends te{constructor(e,t,n,r){super(e,t,n,r)}copySampleValue_(e){let t=this.resultBuffer,n=this.sampleValues,r=this.valueSize,i=e*r*3+r;for(let e=0;e!==r;e++)t[e]=n[i+e];return t}interpolate_(e,t,n,r){let i=this.resultBuffer,a=this.sampleValues,o=this.valueSize,s=o*2,c=o*3,l=r-t,u=(n-t)/l,d=u*u,f=d*u,p=e*c,m=p-c,h=-2*f+3*d,g=f-d,ee=1-h,_=g-d+u;for(let e=0;e!==o;e++){let t=a[m+e+o],n=a[m+e+s]*l,r=a[p+e+o],c=a[p+e]*l;i[e]=ee*t+_*n+h*r+g*c}return i}},ot=new D,st=class extends B{interpolate_(e,t,n,r){let i=super.interpolate_(e,t,n,r);return ot.fromArray(i).normalize().toArray(i),i}},V={FLOAT:5126,FLOAT_MAT3:35675,FLOAT_MAT4:35676,FLOAT_VEC2:35664,FLOAT_VEC3:35665,FLOAT_VEC4:35666,LINEAR:9729,REPEAT:10497,SAMPLER_2D:35678,POINTS:0,LINES:1,LINE_LOOP:2,LINE_STRIP:3,TRIANGLES:4,TRIANGLE_STRIP:5,TRIANGLE_FAN:6,UNSIGNED_BYTE:5121,UNSIGNED_SHORT:5123},H={5120:Int8Array,5121:Uint8Array,5122:Int16Array,5123:Uint16Array,5125:Uint32Array,5126:Float32Array},U={9728:f,9729:h,9984:ne,9985:_,9986:re,9987:g},W={33071:ve,33648:Ce,10497:ce},G={SCALAR:1,VEC2:2,VEC3:3,VEC4:4,MAT2:4,MAT3:9,MAT4:16},K={POSITION:`position`,NORMAL:`normal`,TANGENT:`tangent`,TEXCOORD_0:`uv`,TEXCOORD_1:`uv1`,TEXCOORD_2:`uv2`,TEXCOORD_3:`uv3`,COLOR_0:`color`,WEIGHTS_0:`skinWeight`,JOINTS_0:`skinIndex`},q={scale:`scale`,translation:`position`,rotation:`quaternion`,weights:`morphTargetInfluences`},ct={CUBICSPLINE:void 0,LINEAR:o,STEP:s},J={OPAQUE:`OPAQUE`,MASK:`MASK`,BLEND:`BLEND`};function lt(e){return e.DefaultMaterial===void 0&&(e.DefaultMaterial=new p({color:16777215,emissive:0,metalness:1,roughness:1,transparent:!1,depthTest:!0,side:0})),e.DefaultMaterial}function Y(e,t,n){for(let r in n.extensions)e[r]===void 0&&(t.userData.gltfExtensions=t.userData.gltfExtensions||{},t.userData.gltfExtensions[r]=n.extensions[r])}function X(e,t){t.extras!==void 0&&(typeof t.extras==`object`?Object.assign(e.userData,t.extras):console.warn(`THREE.GLTFLoader: Ignoring primitive type .extras, `+t.extras))}function ut(e,t,n){let r=!1,i=!1,a=!1;for(let e=0,n=t.length;e<n;e++){let n=t[e];if(n.POSITION!==void 0&&(r=!0),n.NORMAL!==void 0&&(i=!0),n.COLOR_0!==void 0&&(a=!0),r&&i&&a)break}if(!r&&!i&&!a)return Promise.resolve(e);let o=[],s=[],c=[];for(let l=0,u=t.length;l<u;l++){let u=t[l];if(r){let t=u.POSITION===void 0?e.attributes.position:n.getDependency(`accessor`,u.POSITION);o.push(t)}if(i){let t=u.NORMAL===void 0?e.attributes.normal:n.getDependency(`accessor`,u.NORMAL);s.push(t)}if(a){let t=u.COLOR_0===void 0?e.attributes.color:n.getDependency(`accessor`,u.COLOR_0);c.push(t)}}return Promise.all([Promise.all(o),Promise.all(s),Promise.all(c)]).then(function(t){let n=t[0],o=t[1],s=t[2];return r&&(e.morphAttributes.position=n),i&&(e.morphAttributes.normal=o),a&&(e.morphAttributes.color=s),e.morphTargetsRelative=!0,e})}function dt(e,t){if(e.updateMorphTargets(),t.weights!==void 0)for(let n=0,r=t.weights.length;n<r;n++)e.morphTargetInfluences[n]=t.weights[n];if(t.extras&&Array.isArray(t.extras.targetNames)){let n=t.extras.targetNames;if(e.morphTargetInfluences.length===n.length){e.morphTargetDictionary={};for(let t=0,r=n.length;t<r;t++)e.morphTargetDictionary[n[t]]=t}else console.warn(`THREE.GLTFLoader: Invalid extras.targetNames length. Ignoring names.`)}}function ft(e){let t,n=e.extensions&&e.extensions[F.KHR_DRACO_MESH_COMPRESSION];if(t=n?`draco:`+n.bufferView+`:`+n.indices+`:`+Z(n.attributes):e.indices+`:`+Z(e.attributes)+`:`+e.mode,e.targets!==void 0)for(let n=0,r=e.targets.length;n<r;n++)t+=`:`+Z(e.targets[n]);return t}function Z(e){let t=``,n=Object.keys(e).sort();for(let r=0,i=n.length;r<i;r++)t+=n[r]+`:`+e[n[r]]+`;`;return t}function Q(e){switch(e){case Int8Array:return 1/127;case Uint8Array:return 1/255;case Int16Array:return 1/32767;case Uint16Array:return 1/65535;default:throw Error(`THREE.GLTFLoader: Unsupported normalized accessor component type.`)}}function pt(e){return e.search(/\.jpe?g($|\?)/i)>0||e.search(/^data\:image\/jpeg/)===0?`image/jpeg`:e.search(/\.webp($|\?)/i)>0||e.search(/^data\:image\/webp/)===0?`image/webp`:e.search(/\.ktx2($|\?)/i)>0||e.search(/^data\:image\/ktx2/)===0?`image/ktx2`:`image/png`}var mt=new x,ht=class{constructor(e={},t={}){this.json=e,this.extensions={},this.plugins={},this.options=t,this.cache=new Re,this.associations=new Map,this.primitiveCache={},this.nodeCache={},this.meshCache={refs:{},uses:{}},this.cameraCache={refs:{},uses:{}},this.lightCache={refs:{},uses:{}},this.sourceCache={},this.textureCache={},this.nodeNamesUsed={};let n=!1,r=-1,i=!1,a=-1;if(typeof navigator<`u`&&navigator.userAgent!==void 0){let e=navigator.userAgent;n=/^((?!chrome|android).)*safari/i.test(e)===!0;let t=e.match(/Version\/(\d+)/);r=n&&t?parseInt(t[1],10):-1,i=e.indexOf(`Firefox`)>-1,a=i?e.match(/Firefox\/([0-9]+)\./)[1]:-1}this.textureLoader=typeof createImageBitmap>`u`||n&&r<17||i&&a<98?new ae(this.options.manager):new ie(this.options.manager),this.textureLoader.setCrossOrigin(this.options.crossOrigin),this.textureLoader.setRequestHeader(this.options.requestHeader),this.fileLoader=new T(this.options.manager),this.fileLoader.setResponseType(`arraybuffer`),this.options.crossOrigin===`use-credentials`&&this.fileLoader.setWithCredentials(!0)}setExtensions(e){this.extensions=e}setPlugins(e){this.plugins=e}parse(e,t){let n=this,r=this.json,i=this.extensions;this.cache.removeAll(),this.nodeCache={},this._invokeAll(function(e){return e._markDefs&&e._markDefs()}),Promise.all(this._invokeAll(function(e){return e.beforeRoot&&e.beforeRoot()})).then(function(){return Promise.all([n.getDependencies(`scene`),n.getDependencies(`animation`),n.getDependencies(`camera`)])}).then(function(t){let a={scene:t[0][r.scene||0],scenes:t[0],animations:t[1],cameras:t[2],asset:r.asset,parser:n,userData:{}};return Y(i,a,r),X(a,r),Promise.all(n._invokeAll(function(e){return e.afterRoot&&e.afterRoot(a)})).then(function(){for(let e of a.scenes)e.updateMatrixWorld();e(a)})}).catch(t)}_markDefs(){let e=this.json.nodes||[],t=this.json.skins||[],n=this.json.meshes||[];for(let n=0,r=t.length;n<r;n++){let r=t[n].joints;for(let t=0,n=r.length;t<n;t++)e[r[t]].isBone=!0}for(let t=0,r=e.length;t<r;t++){let r=e[t];r.mesh!==void 0&&(this._addNodeRef(this.meshCache,r.mesh),r.skin!==void 0&&(n[r.mesh].isSkinnedMesh=!0)),r.camera!==void 0&&this._addNodeRef(this.cameraCache,r.camera)}}_addNodeRef(e,t){t!==void 0&&(e.refs[t]===void 0&&(e.refs[t]=e.uses[t]=0),e.refs[t]++)}_getNodeRef(e,t,n){if(e.refs[t]<=1)return n;let r=n.clone(),i=(e,t)=>{let n=this.associations.get(e);n!=null&&this.associations.set(t,n);for(let[n,r]of e.children.entries())i(r,t.children[n])};return i(n,r),r.name+=`_instance_`+e.uses[t]++,r}_invokeOne(e){let t=Object.values(this.plugins);t.push(this);for(let n=0;n<t.length;n++){let r=e(t[n]);if(r)return r}return null}_invokeAll(e){let t=Object.values(this.plugins);t.unshift(this);let n=[];for(let r=0;r<t.length;r++){let i=e(t[r]);i&&n.push(i)}return n}getDependency(e,t){let n=e+`:`+t,r=this.cache.get(n);if(!r){switch(e){case`scene`:r=this.loadScene(t);break;case`node`:r=this._invokeOne(function(e){return e.loadNode&&e.loadNode(t)});break;case`mesh`:r=this._invokeOne(function(e){return e.loadMesh&&e.loadMesh(t)});break;case`accessor`:r=this.loadAccessor(t);break;case`bufferView`:r=this._invokeOne(function(e){return e.loadBufferView&&e.loadBufferView(t)});break;case`buffer`:r=this.loadBuffer(t);break;case`material`:r=this._invokeOne(function(e){return e.loadMaterial&&e.loadMaterial(t)});break;case`texture`:r=this._invokeOne(function(e){return e.loadTexture&&e.loadTexture(t)});break;case`skin`:r=this.loadSkin(t);break;case`animation`:r=this._invokeOne(function(e){return e.loadAnimation&&e.loadAnimation(t)});break;case`camera`:r=this.loadCamera(t);break;default:if(r=this._invokeOne(function(n){return n!=this&&n.getDependency&&n.getDependency(e,t)}),!r)throw Error(`Unknown type: `+e)}this.cache.add(n,r)}return r}getDependencies(e){let t=this.cache.get(e);if(!t){let n=this,r=this.json[e+(e===`mesh`?`es`:`s`)]||[];t=Promise.all(r.map(function(t,r){return n.getDependency(e,r)})),this.cache.add(e,t)}return t}loadBuffer(e){let t=this.json.buffers[e],n=this.fileLoader;if(t.type&&t.type!==`arraybuffer`)throw Error(`THREE.GLTFLoader: `+t.type+` buffer type is not supported.`);if(t.uri===void 0&&e===0)return Promise.resolve(this.extensions[F.KHR_BINARY_GLTF].body);let r=this.options;return new Promise(function(e,i){n.load(m.resolveURL(t.uri,r.path),e,void 0,function(){i(Error(`THREE.GLTFLoader: Failed to load buffer "`+t.uri+`".`))})})}loadBufferView(e){let t=this.json.bufferViews[e];return this.getDependency(`buffer`,t.buffer).then(function(e){let n=t.byteLength||0,r=t.byteOffset||0;return e.slice(r,r+n)})}loadAccessor(e){let t=this,n=this.json,r=this.json.accessors[e];if(r.bufferView===void 0&&r.sparse===void 0){let e=G[r.type],t=H[r.componentType],n=r.normalized===!0,i=new t(r.count*e);return Promise.resolve(new E(i,e,n))}let a=[];return r.bufferView===void 0?a.push(null):a.push(this.getDependency(`bufferView`,r.bufferView)),r.sparse!==void 0&&(a.push(this.getDependency(`bufferView`,r.sparse.indices.bufferView)),a.push(this.getDependency(`bufferView`,r.sparse.values.bufferView))),Promise.all(a).then(function(e){let a=e[0],o=G[r.type],s=H[r.componentType],c=s.BYTES_PER_ELEMENT,l=c*o,u=r.byteOffset||0,d=r.bufferView===void 0?void 0:n.bufferViews[r.bufferView].byteStride,f=r.normalized===!0,p,m;if(d&&d!==l){let e=Math.floor(u/d),n=`InterleavedBuffer:`+r.bufferView+`:`+r.componentType+`:`+e+`:`+r.count,l=t.cache.get(n);l||(p=new s(a,e*d,r.count*d/c),l=new i(p,d/c),t.cache.add(n,l)),m=new Ae(l,o,u%d/c,f)}else p=a===null?new s(r.count*o):new s(a,u,r.count*o),m=new E(p,o,f);if(r.sparse!==void 0){let t=G.SCALAR,n=H[r.sparse.indices.componentType],i=r.sparse.indices.byteOffset||0,c=r.sparse.values.byteOffset||0,l=new n(e[1],i,r.sparse.count*t),u=new s(e[2],c,r.sparse.count*o);a!==null&&(m=new E(m.array.slice(),m.itemSize,m.normalized)),m.normalized=!1;for(let e=0,t=l.length;e<t;e++){let t=l[e];if(m.setX(t,u[e*o]),o>=2&&m.setY(t,u[e*o+1]),o>=3&&m.setZ(t,u[e*o+2]),o>=4&&m.setW(t,u[e*o+3]),o>=5)throw Error(`THREE.GLTFLoader: Unsupported itemSize in sparse BufferAttribute.`)}m.normalized=f}return m})}loadTexture(e){let t=this.json,n=this.options,r=t.textures[e].source,i=t.images[r],a=this.textureLoader;if(i.uri){let e=n.manager.getHandler(i.uri);e!==null&&(a=e)}return this.loadTextureImage(e,r,a)}loadTextureImage(e,t,n){let r=this,i=this.json,a=i.textures[e],o=i.images[t],s=(o.uri||o.bufferView)+`:`+a.sampler;if(this.textureCache[s])return this.textureCache[s];let c=this.loadImageSource(t,n).then(function(t){t.flipY=!1,t.name=a.name||o.name||``,t.name===``&&typeof o.uri==`string`&&o.uri.startsWith(`data:image/`)===!1&&(t.name=o.uri);let n=(i.samplers||{})[a.sampler]||{};return t.magFilter=U[n.magFilter]||1006,t.minFilter=U[n.minFilter]||1008,t.wrapS=W[n.wrapS]||1e3,t.wrapT=W[n.wrapT]||1e3,t.generateMipmaps=!t.isCompressedTexture&&t.minFilter!==1003&&t.minFilter!==1006,r.associations.set(t,{textures:e}),t}).catch(function(){return null});return this.textureCache[s]=c,c}loadImageSource(e,t){let n=this,r=this.json,i=this.options;if(this.sourceCache[e]!==void 0)return this.sourceCache[e].then(e=>e.clone());let a=r.images[e],o=self.URL||self.webkitURL,s=a.uri||``,c=!1;if(a.bufferView!==void 0)s=n.getDependency(`bufferView`,a.bufferView).then(function(e){c=!0;let t=new Blob([e],{type:a.mimeType});return s=o.createObjectURL(t),s});else if(a.uri===void 0)throw Error(`THREE.GLTFLoader: Image `+e+` is missing URI and bufferView`);let l=Promise.resolve(s).then(function(e){return new Promise(function(n,r){let a=n;t.isImageBitmapLoader===!0&&(a=function(e){let t=new pe(e);t.needsUpdate=!0,n(t)}),t.load(m.resolveURL(e,i.path),a,void 0,r)})}).then(function(e){return c===!0&&o.revokeObjectURL(s),X(e,a),e.userData.mimeType=a.mimeType||pt(a.uri),e}).catch(function(e){throw console.error(`THREE.GLTFLoader: Couldn't load texture`,s),e});return this.sourceCache[e]=l,l}assignTexture(e,t,n,r){let i=this;return this.getDependency(`texture`,n.index).then(function(a){if(!a)return null;if(n.texCoord!==void 0&&n.texCoord>0&&(a=a.clone(),a.channel=n.texCoord),i.extensions[F.KHR_TEXTURE_TRANSFORM]){let e=n.extensions===void 0?void 0:n.extensions[F.KHR_TEXTURE_TRANSFORM];if(e){let t=i.associations.get(a);a=i.extensions[F.KHR_TEXTURE_TRANSFORM].extendTexture(a,e),i.associations.set(a,t)}}return r!==void 0&&(a.colorSpace=r),e[t]=a,a})}assignFinalMaterial(e){let t=e.geometry,n=e.material,r=t.attributes.tangent===void 0,i=t.attributes.color!==void 0,a=t.attributes.normal===void 0;if(e.isPoints){let e=`PointsMaterial:`+n.uuid,t=this.cache.get(e);t||(t=new he,j.prototype.copy.call(t,n),t.color.copy(n.color),t.map=n.map,t.sizeAttenuation=!1,this.cache.add(e,t)),n=t}else if(e.isLine){let e=`LineBasicMaterial:`+n.uuid,t=this.cache.get(e);t||(t=new _e,j.prototype.copy.call(t,n),t.color.copy(n.color),t.map=n.map,this.cache.add(e,t)),n=t}if(r||i||a){let e=`ClonedMaterial:`+n.uuid+`:`;r&&(e+=`derivative-tangents:`),i&&(e+=`vertex-colors:`),a&&(e+=`flat-shading:`);let t=this.cache.get(e);t||(t=n.clone(),i&&(t.vertexColors=!0),a&&(t.flatShading=!0),r&&(t.normalScale&&(t.normalScale.y*=-1),t.clearcoatNormalScale&&(t.clearcoatNormalScale.y*=-1)),this.cache.add(e,t),this.associations.set(t,this.associations.get(n))),n=t}e.material=n}getMaterialType(){return p}loadMaterial(e){let t=this,n=this.json,r=this.extensions,i=n.materials[e],a,o={},s=i.extensions||{},l=[];if(s[F.KHR_MATERIALS_UNLIT]){let e=r[F.KHR_MATERIALS_UNLIT];a=e.getMaterialType(),l.push(e.extendParams(o,i,t))}else{let n=i.pbrMetallicRoughness||{};if(o.color=new k(1,1,1),o.opacity=1,Array.isArray(n.baseColorFactor)){let e=n.baseColorFactor;o.color.setRGB(e[0],e[1],e[2],c),o.opacity=e[3]}n.baseColorTexture!==void 0&&l.push(t.assignTexture(o,`map`,n.baseColorTexture,w)),o.metalness=n.metallicFactor===void 0?1:n.metallicFactor,o.roughness=n.roughnessFactor===void 0?1:n.roughnessFactor,n.metallicRoughnessTexture!==void 0&&(l.push(t.assignTexture(o,`metalnessMap`,n.metallicRoughnessTexture)),l.push(t.assignTexture(o,`roughnessMap`,n.metallicRoughnessTexture))),a=this._invokeOne(function(t){return t.getMaterialType&&t.getMaterialType(e)}),l.push(Promise.all(this._invokeAll(function(t){return t.extendMaterialParams&&t.extendMaterialParams(e,o)})))}i.doubleSided===!0&&(o.side=2);let u=i.alphaMode||J.OPAQUE;if(u===J.BLEND?(o.transparent=!0,o.depthWrite=!1):(o.transparent=!1,u===J.MASK&&(o.alphaTest=i.alphaCutoff===void 0?.5:i.alphaCutoff)),i.normalTexture!==void 0&&a!==b&&(l.push(t.assignTexture(o,`normalMap`,i.normalTexture)),o.normalScale=new A(1,1),i.normalTexture.scale!==void 0)){let e=i.normalTexture.scale;o.normalScale.set(e,e)}if(i.occlusionTexture!==void 0&&a!==b&&(l.push(t.assignTexture(o,`aoMap`,i.occlusionTexture)),i.occlusionTexture.strength!==void 0&&(o.aoMapIntensity=i.occlusionTexture.strength)),i.emissiveFactor!==void 0&&a!==b){let e=i.emissiveFactor;o.emissive=new k().setRGB(e[0],e[1],e[2],c)}return i.emissiveTexture!==void 0&&a!==b&&l.push(t.assignTexture(o,`emissiveMap`,i.emissiveTexture,w)),Promise.all(l).then(function(){let n=new a(o);return i.name&&(n.name=i.name),X(n,i),t.associations.set(n,{materials:e}),i.extensions&&Y(r,n,i),n})}createUniqueName(e){let t=se.sanitizeNodeName(e||``);return t in this.nodeNamesUsed?t+`_`+ ++this.nodeNamesUsed[t]:(this.nodeNamesUsed[t]=0,t)}loadGeometries(e){let t=this,n=this.extensions,r=this.primitiveCache;function i(e){return n[F.KHR_DRACO_MESH_COMPRESSION].decodePrimitive(e,t).then(function(n){return $(n,e,t)})}let a=[];for(let n=0,o=e.length;n<o;n++){let o=e[n],s=ft(o),c=r[s];if(c)a.push(c.promise);else{let e;e=o.extensions&&o.extensions[F.KHR_DRACO_MESH_COMPRESSION]?i(o):$(new Ee,o,t),r[s]={primitive:o,promise:e},a.push(e)}}return Promise.all(a)}loadMesh(e){let t=this,r=this.json,i=this.extensions,a=r.meshes[e],o=a.primitives,s=[];for(let e=0,t=o.length;e<t;e++){let t=o[e].material===void 0?lt(this.cache):this.getDependency(`material`,o[e].material);s.push(t)}return s.push(t.loadGeometries(o)),Promise.all(s).then(function(r){let s=r.slice(0,r.length-1),c=r[r.length-1],l=[];for(let r=0,d=c.length;r<d;r++){let d=c[r],f=o[r],p,m=s[r];if(f.mode===V.TRIANGLES||f.mode===V.TRIANGLE_STRIP||f.mode===V.TRIANGLE_FAN||f.mode===void 0)p=a.isSkinnedMesh===!0?new ue(d,m):new u(d,m),p.isSkinnedMesh===!0&&p.normalizeSkinWeights(),f.mode===V.TRIANGLE_STRIP?p.geometry=M(p.geometry,1):f.mode===V.TRIANGLE_FAN&&(p.geometry=M(p.geometry,2));else if(f.mode===V.LINES)p=new ge(d,m);else if(f.mode===V.LINE_STRIP)p=new ee(d,m);else if(f.mode===V.LINE_LOOP)p=new n(d,m);else if(f.mode===V.POINTS)p=new Te(d,m);else throw Error(`THREE.GLTFLoader: Primitive mode unsupported: `+f.mode);Object.keys(p.geometry.morphAttributes).length>0&&dt(p,a),p.name=t.createUniqueName(a.name||`mesh_`+e),X(p,a),f.extensions&&Y(i,p,f),t.assignFinalMaterial(p),l.push(p)}for(let n=0,r=l.length;n<r;n++)t.associations.set(l[n],{meshes:e,primitives:n});if(l.length===1)return a.extensions&&Y(i,l[0],a),l[0];let d=new C;a.extensions&&Y(i,d,a),t.associations.set(d,{meshes:e});for(let e=0,t=l.length;e<t;e++)d.add(l[e]);return d})}loadCamera(e){let t,n=this.json.cameras[e],i=n[n.type];if(!i){console.warn(`THREE.GLTFLoader: Missing camera parameters.`);return}return n.type===`perspective`?t=new De(r.radToDeg(i.yfov),i.aspectRatio||1,i.znear||1,i.zfar||2e6):n.type===`orthographic`&&(t=new de(-i.xmag,i.xmag,i.ymag,-i.ymag,i.znear,i.zfar)),n.name&&(t.name=this.createUniqueName(n.name)),X(t,n),Promise.resolve(t)}loadSkin(e){let t=this.json.skins[e],n=[];for(let e=0,r=t.joints.length;e<r;e++)n.push(this._loadNodeShallow(t.joints[e]));return t.inverseBindMatrices===void 0?n.push(null):n.push(this.getDependency(`accessor`,t.inverseBindMatrices)),Promise.all(n).then(function(e){let n=e.pop(),r=e,i=[],a=[];for(let e=0,o=r.length;e<o;e++){let o=r[e];if(o){i.push(o);let t=new x;n!==null&&t.fromArray(n.array,e*16),a.push(t)}else console.warn(`THREE.GLTFLoader: Joint "%s" could not be found.`,t.joints[e])}return new Oe(i,a)})}loadAnimation(e){let t=this.json,n=this,r=t.animations[e],i=r.name?r.name:`animation_`+e,a=[],o=[],s=[],c=[],l=[];for(let e=0,t=r.channels.length;e<t;e++){let t=r.channels[e],n=r.samplers[t.sampler],i=t.target,u=i.node,d=r.parameters===void 0?n.input:r.parameters[n.input],f=r.parameters===void 0?n.output:r.parameters[n.output];i.node!==void 0&&(a.push(this.getDependency(`node`,u)),o.push(this.getDependency(`accessor`,d)),s.push(this.getDependency(`accessor`,f)),c.push(n),l.push(i))}return Promise.all([Promise.all(a),Promise.all(o),Promise.all(s),Promise.all(c),Promise.all(l)]).then(function(e){let t=e[0],a=e[1],o=e[2],s=e[3],c=e[4],l=[];for(let e=0,r=t.length;e<r;e++){let r=t[e],i=a[e],u=o[e],d=s[e],f=c[e];if(r===void 0)continue;r.updateMatrix&&r.updateMatrix();let p=n._createAnimationTracks(r,i,u,d,f);if(p)for(let e=0;e<p.length;e++)l.push(p[e])}let u=new we(i,void 0,l);return X(u,r),u})}createNodeMesh(e){let t=this.json,n=this,r=t.nodes[e];return r.mesh===void 0?null:n.getDependency(`mesh`,r.mesh).then(function(e){let t=n._getNodeRef(n.meshCache,r.mesh,e);return r.weights!==void 0&&t.traverse(function(e){if(e.isMesh)for(let t=0,n=r.weights.length;t<n;t++)e.morphTargetInfluences[t]=r.weights[t]}),t})}loadNode(e){let t=this.json,n=this,r=t.nodes[e],i=n._loadNodeShallow(e),a=[],o=r.children||[];for(let e=0,t=o.length;e<t;e++)a.push(n.getDependency(`node`,o[e]));let s=r.skin===void 0?Promise.resolve(null):n.getDependency(`skin`,r.skin);return Promise.all([i,Promise.all(a),s]).then(function(e){let t=e[0],n=e[1],r=e[2];r!==null&&t.traverse(function(e){e.isSkinnedMesh&&e.bind(r,mt)});for(let e=0,r=n.length;e<r;e++)t.add(n[e]);if(t.userData.pivot!==void 0&&n.length>0){let e=t.userData.pivot,r=n[0];t.pivot=new y().fromArray(e),t.position.x-=e[0],t.position.y-=e[1],t.position.z-=e[2],r.position.set(0,0,0),delete t.userData.pivot}return t})}_loadNodeShallow(e){let t=this.json,n=this.extensions,r=this;if(this.nodeCache[e]!==void 0)return this.nodeCache[e];let i=t.nodes[e],a=i.name?r.createUniqueName(i.name):``,o=[],s=r._invokeOne(function(t){return t.createNodeMesh&&t.createNodeMesh(e)});return s&&o.push(s),i.camera!==void 0&&o.push(r.getDependency(`camera`,i.camera).then(function(e){return r._getNodeRef(r.cameraCache,i.camera,e)})),r._invokeAll(function(t){return t.createNodeAttachment&&t.createNodeAttachment(e)}).forEach(function(e){o.push(e)}),this.nodeCache[e]=Promise.all(o).then(function(t){let o;if(o=i.isBone===!0?new me:t.length>1?new C:t.length===1?t[0]:new v,o!==t[0])for(let e=0,n=t.length;e<n;e++)o.add(t[e]);if(i.name&&(o.userData.name=i.name,o.name=a),X(o,i),i.extensions&&Y(n,o,i),i.matrix!==void 0){let e=new x;e.fromArray(i.matrix),o.applyMatrix4(e)}else i.translation!==void 0&&o.position.fromArray(i.translation),i.rotation!==void 0&&o.quaternion.fromArray(i.rotation),i.scale!==void 0&&o.scale.fromArray(i.scale);if(!r.associations.has(o))r.associations.set(o,{});else if(i.mesh!==void 0&&r.meshCache.refs[i.mesh]>1){let e=r.associations.get(o);r.associations.set(o,{...e})}return r.associations.get(o).nodes=e,o}),this.nodeCache[e]}loadScene(e){let t=this.extensions,n=this.json.scenes[e],r=this,i=new C;n.name&&(i.name=r.createUniqueName(n.name)),X(i,n),n.extensions&&Y(t,i,n);let a=n.nodes||[],o=[];for(let e=0,t=a.length;e<t;e++)o.push(r.getDependency(`node`,a[e]));return Promise.all(o).then(function(e){for(let t=0,n=e.length;t<n;t++){let n=e[t];n.parent===null?i.add(n):i.add(Ie(n))}return r.associations=(e=>{let t=new Map;for(let[e,n]of r.associations)(e instanceof j||e instanceof pe)&&t.set(e,n);return e.traverse(e=>{let n=r.associations.get(e);n!=null&&t.set(e,n)}),t})(i),i})}_createAnimationTracks(e,t,n,r,i){let s=[],c=e.name?e.name:e.uuid,l=[];function u(e){e.morphTargetInfluences&&l.push(e.name?e.name:e.uuid)}q[i.path]===q.weights?(u(e),e.isGroup&&e.children.forEach(u)):l.push(c);let d;switch(q[i.path]){case q.weights:d=S;break;case q.rotation:d=O;break;case q.translation:case q.scale:d=a;break;default:switch(n.itemSize){case 1:d=S;break;default:d=a}}let f=r.interpolation===void 0?o:ct[r.interpolation],p=this._getArrayFromAccessor(n);for(let e=0,n=l.length;e<n;e++){let n=new d(l[e]+`.`+q[i.path],t.array,p,f);r.interpolation===`CUBICSPLINE`&&this._createCubicSplineTrackInterpolant(n),s.push(n)}return s}_getArrayFromAccessor(e){let t=e.array;if(e.normalized){let e=Q(t.constructor),n=new Float32Array(t.length);for(let r=0,i=t.length;r<i;r++)n[r]=t[r]*e;t=n}return t}_createCubicSplineTrackInterpolant(e){e.createInterpolant=function(e){return new(this instanceof O?st:B)(this.times,this.values,this.getValueSize()/3,e)},e.createInterpolant.isInterpolantFactoryMethodGLTFCubicSpline=!0}};function gt(e,t,n){let r=t.attributes,i=new oe;if(r.POSITION!==void 0){let e=n.json.accessors[r.POSITION],t=e.min,a=e.max;if(t!==void 0&&a!==void 0){if(i.set(new y(t[0],t[1],t[2]),new y(a[0],a[1],a[2])),e.normalized){let t=Q(H[e.componentType]);i.min.multiplyScalar(t),i.max.multiplyScalar(t)}}else{console.warn(`THREE.GLTFLoader: Missing min/max properties for accessor POSITION.`);return}}else return;let a=t.targets;if(a!==void 0){let e=new y,t=new y;for(let r=0,i=a.length;r<i;r++){let i=a[r];if(i.POSITION!==void 0){let r=n.json.accessors[i.POSITION],a=r.min,o=r.max;if(a!==void 0&&o!==void 0){if(t.setX(Math.max(Math.abs(a[0]),Math.abs(o[0]))),t.setY(Math.max(Math.abs(a[1]),Math.abs(o[1]))),t.setZ(Math.max(Math.abs(a[2]),Math.abs(o[2]))),r.normalized){let e=Q(H[r.componentType]);t.multiplyScalar(e)}e.max(t)}else console.warn(`THREE.GLTFLoader: Missing min/max properties for accessor POSITION.`)}}i.expandByVector(e)}e.boundingBox=i;let o=new fe;i.getCenter(o.center),o.radius=i.min.distanceTo(i.max)/2,e.boundingSphere=o}function $(e,t,n){let r=t.attributes,i=[];function a(t,r){return n.getDependency(`accessor`,t).then(function(t){e.setAttribute(r,t)})}for(let t in r){let n=K[t]||t.toLowerCase();n in e.attributes||i.push(a(r[t],n))}if(t.indices!==void 0&&!e.index){let r=n.getDependency(`accessor`,t.indices).then(function(t){e.setIndex(t)});i.push(r)}return le.workingColorSpace!==`srgb-linear`&&`COLOR_0`in r&&console.warn(`THREE.GLTFLoader: Converting vertex colors from "srgb-linear" to "${le.workingColorSpace}" not supported.`),X(e,t),gt(e,t,n),Promise.all(i).then(function(){return t.targets===void 0?e:ut(e,t.targets,n)})}async function _t(n,r){let i=new DataView(n),a,o=n.byteLength>=12&&i.getUint32(0,!0)===1179937895;if(o){if(i.getUint32(4,!0)!==2||i.getUint32(8,!0)!==n.byteLength||n.byteLength<20||i.getUint32(16,!0)!==1313821514)throw Error(`Invalid GLB`);let e=i.getUint32(12,!0);if(20+e>n.byteLength||e>16777216)throw RangeError();a=new TextDecoder().decode(n.slice(20,20+e))}else a=new TextDecoder().decode(n);let s=JSON.parse(a);if(s.asset?.version!==`2.0`)throw Error(`Unsupported glTF version`);if((s.nodes?.length??0)>4096||(s.accessors?.length??0)>16384)throw RangeError();Fe(s.nodes??[],(s.scenes??[]).flatMap(e=>e.nodes??[]));let c=0;for(let e of s.accessors??[]){if(!Number.isSafeInteger(e.count)||e.count<0)throw Error(`Invalid accessor`);c+=e.count}if(c>2e7)throw RangeError();if(s.extensionsRequired?.some(e=>[`KHR_draco_mesh_compression`,`EXT_meshopt_compression`,`KHR_texture_basisu`].includes(e)))throw Error(`Compressed glTF requires an unavailable decoder`);let l=Pe(r);try{let a=0,c=0;for(let[e,u]of(s.images??[]).entries())try{if(u.uri)await l.prepare(u.uri,!0);else{let e=s.bufferViews?.[u.bufferView];if(!o||!e||e.buffer!==0)throw Error(`Unsupported embedded image storage`);let t=20+i.getUint32(12,!0);if(t+8>n.byteLength||i.getUint32(t+4,!0)!==5130562)throw Error(`Missing GLB binary chunk`);let r=e.byteOffset??0,c=e.byteLength;if(!Number.isSafeInteger(r)||!Number.isSafeInteger(c)||r<0||c<0||r+c>i.getUint32(t,!0))throw Error(`Invalid image range`);a+=await Me(new Blob([n.slice(t+8+r,t+8+r+c)]))}Ne(a+l.imagePixels,r.locale)}catch(n){if(r.signal.aborted||n instanceof RangeError||n instanceof t&&n.code===`resource-limit`)throw n;c++;let i=new Set((s.textures??[]).flatMap((t,n)=>t.source===e?[n]:[])),a=e=>{for(let[t,n]of Object.entries(e))n&&typeof n==`object`&&(t.endsWith(`Texture`)&&i.has(n.index)?delete e[t]:a(n))};for(let e of s.materials??[])a(e);s.images[e]={}}for(let e of s.buffers??[])e.uri&&await l.prepare(e.uri);let u=new Le(l.manager);for(let e of[...s.buffers??[],...s.images??[]])e.uri&&=await l.prepare(e.uri);let d=JSON.stringify(s);if(o){let e=new TextEncoder().encode(d),t=Math.ceil(e.length/4)*4,r=20+i.getUint32(12,!0),a=new Uint8Array(20+t+n.byteLength-r);a.set(new Uint8Array(n,0,12));let o=new DataView(a.buffer);o.setUint32(8,a.length,!0),o.setUint32(12,t,!0),o.setUint32(16,1313821514,!0),a.fill(32,20,20+t),a.set(e,20),a.set(new Uint8Array(n,r),20+t),d=a.buffer}l.manager.setURLModifier(e=>{if(!e.startsWith(`blob:`))throw Error(`Network blocked`);return e});let f=await u.parseAsync(d,``);if(r.signal.aborted)throw ye(f.scene),new DOMException(`Aborted`,`AbortError`);return{root:f.scene,units:`m`,animations:f.animations,description:c?e(r.locale,{en:`Some textures are missing or unsupported; geometry remains visible.`,"zh-CN":`部分纹理缺失或不受支持;几何仍可查看。`}):void 0}}finally{l.dispose()}}export{_t as loadGltf};
1
+ import{t as e}from"./src-rJN_jaC5.js";import{a as t}from"./index-DtiyOy_J.js";import{A as n,B as r,C as i,Ct as a,D as o,E as s,F as c,G as l,H as u,I as d,J as f,K as p,L as m,M as h,N as g,O as ee,P as _,Q as v,St as y,T as te,U as b,V as x,X as ne,Y as re,Z as S,_ as ie,_t as ae,a as oe,at as se,ct as ce,d as le,dt as ue,et as de,ft as fe,g as C,gt as pe,i as me,it as he,j as ge,k as _e,l as ve,lt as w,m as T,n as ye,nt as be,o as E,ot as D,p as xe,pt as Se,q as Ce,r as we,rt as Te,s as Ee,st as O,tt as De,u as k,ut as Oe,v as ke,w as Ae,xt as A,y as je,z as j}from"./src-MO5bLsLj.js";import{i as Me,r as Ne,t as Pe}from"./resources-6AmS6O5e.js";function Fe(e,t){let n=new Map,r=new Set,i=(t,a)=>{if(!Number.isInteger(t)||t<0||t>=e.length)throw Error(`Invalid glTF node index`);if(r.has(t))throw Error(`Cyclic glTF nodes`);if(a>128)throw RangeError(`glTF hierarchy depth`);if(n.has(t)){let e=n.get(t);if(a+e>128)throw RangeError(`glTF hierarchy depth`);return e}r.add(t);let o=e[t].children??[];if(!Array.isArray(o)||o.length>4096)throw Error(`Invalid glTF children`);let s=0;for(let e of o)s=Math.max(s,1+i(e,a+1));return r.delete(t),n.set(t,s),s};for(let e of t)i(e,0);for(let t=0;t<e.length;t++)i(t,0)}function M(e,t){if(t===0)return console.warn(`THREE.BufferGeometryUtils.toTrianglesDrawMode(): Geometry already defined as triangles.`),e;if(t===2||t===1){let n=e.getIndex();if(n===null){let t=[],r=e.getAttribute(`position`);if(r!==void 0){for(let e=0;e<r.count;e++)t.push(e);e.setIndex(t),n=e.getIndex()}else return console.error(`THREE.BufferGeometryUtils.toTrianglesDrawMode(): Undefined position attribute. Processing not possible.`),e}let r=n.count-2,i=[];if(t===2)for(let e=1;e<=r;e++)i.push(n.getX(0)),i.push(n.getX(e)),i.push(n.getX(e+1));else for(let e=0;e<r;e++)e%2==0?(i.push(n.getX(e)),i.push(n.getX(e+1)),i.push(n.getX(e+2))):(i.push(n.getX(e+2)),i.push(n.getX(e+1)),i.push(n.getX(e)));i.length/3!==r&&console.error(`THREE.BufferGeometryUtils.toTrianglesDrawMode(): Unable to generate correct amount of triangles.`);let a=e.clone();return a.setIndex(i),a.clearGroups(),a}return console.error(`THREE.BufferGeometryUtils.toTrianglesDrawMode(): Unknown draw mode:`,t),e}function Ie(e){let t=new Map,n=new Map,r=e.clone();return N(e,r,function(e,r){t.set(r,e),n.set(e,r)}),r.traverse(function(e){if(!e.isSkinnedMesh)return;let r=e,i=t.get(e),a=i.skeleton.bones;r.skeleton=i.skeleton.clone(),r.bindMatrix.copy(i.bindMatrix),r.skeleton.bones=a.map(function(e){return n.get(e)}),r.bind(r.skeleton,r.bindMatrix)}),r}function N(e,t,n){n(e,t);for(let r=0;r<e.children.length;r++)N(e.children[r],t.children[r],n)}var Le=class extends d{constructor(e){super(e),this.dracoLoader=null,this.ktx2Loader=null,this.meshoptDecoder=null,this.pluginCallbacks=[],this.register(function(e){return new He(e)}),this.register(function(e){return new Ue(e)}),this.register(function(e){return new Qe(e)}),this.register(function(e){return new $e(e)}),this.register(function(e){return new et(e)}),this.register(function(e){return new Ge(e)}),this.register(function(e){return new Ke(e)}),this.register(function(e){return new qe(e)}),this.register(function(e){return new Je(e)}),this.register(function(e){return new Ve(e)}),this.register(function(e){return new Ye(e)}),this.register(function(e){return new We(e)}),this.register(function(e){return new Ze(e)}),this.register(function(e){return new Xe(e)}),this.register(function(e){return new ze(e)}),this.register(function(e){return new I(e,F.EXT_MESHOPT_COMPRESSION)}),this.register(function(e){return new I(e,F.KHR_MESHOPT_COMPRESSION)}),this.register(function(e){return new tt(e)})}load(e,t,n,r){let i=this,a;if(this.resourcePath!==``)a=this.resourcePath;else if(this.path!==``){let t=m.extractUrlBase(e);a=m.resolveURL(t,this.path)}else a=m.extractUrlBase(e);this.manager.itemStart(e);let o=function(t){r?r(t):console.error(t),i.manager.itemError(e),i.manager.itemEnd(e)},s=new T(this.manager);s.setPath(this.path),s.setResponseType(`arraybuffer`),s.setRequestHeader(this.requestHeader),s.setWithCredentials(this.withCredentials),s.load(e,function(n){try{i.parse(n,a,function(n){t(n),i.manager.itemEnd(e)},o)}catch(e){o(e)}},n,o)}setDRACOLoader(e){return this.dracoLoader=e,this}setKTX2Loader(e){return this.ktx2Loader=e,this}setMeshoptDecoder(e){return this.meshoptDecoder=e,this}register(e){return this.pluginCallbacks.indexOf(e)===-1&&this.pluginCallbacks.push(e),this}unregister(e){return this.pluginCallbacks.indexOf(e)!==-1&&this.pluginCallbacks.splice(this.pluginCallbacks.indexOf(e),1),this}parse(e,t,n,r){let i,a={},o={},s=new TextDecoder;if(typeof e==`string`)i=JSON.parse(e);else if(e instanceof ArrayBuffer){if(s.decode(new Uint8Array(e,0,4))===L){try{a[F.KHR_BINARY_GLTF]=new nt(e)}catch(e){r&&r(e);return}i=JSON.parse(a[F.KHR_BINARY_GLTF].content)}else i=JSON.parse(s.decode(e))}else i=e;if(i.asset===void 0||i.asset.version[0]<2){r&&r(Error(`THREE.GLTFLoader: Unsupported asset. glTF versions >=2.0 are supported.`));return}let c=new ht(i,{path:t||this.resourcePath||``,crossOrigin:this.crossOrigin,requestHeader:this.requestHeader,manager:this.manager,ktx2Loader:this.ktx2Loader,meshoptDecoder:this.meshoptDecoder});c.fileLoader.setRequestHeader(this.requestHeader);for(let e=0;e<this.pluginCallbacks.length;e++){let t=this.pluginCallbacks[e](c);t.name||console.error(`THREE.GLTFLoader: Invalid plugin found: missing name`),o[t.name]=t,a[t.name]=!0}if(i.extensionsUsed)for(let e=0;e<i.extensionsUsed.length;++e){let t=i.extensionsUsed[e],n=i.extensionsRequired||[];switch(t){case F.KHR_MATERIALS_UNLIT:a[t]=new Be;break;case F.KHR_DRACO_MESH_COMPRESSION:a[t]=new rt(i,this.dracoLoader);break;case F.KHR_TEXTURE_TRANSFORM:a[t]=new it;break;case F.KHR_MESH_QUANTIZATION:a[t]=new at;break;default:n.indexOf(t)>=0&&o[t]===void 0&&console.warn(`THREE.GLTFLoader: Unknown extension "`+t+`".`)}}c.setExtensions(a),c.setPlugins(o),c.parse(n,r)}parseAsync(e,t){let n=this;return new Promise(function(r,i){n.parse(e,t,r,i)})}};function Re(){let e={};return{get:function(t){return e[t]},add:function(t,n){e[t]=n},remove:function(t){delete e[t]},removeAll:function(){e={}}}}function P(e,t,n){let r=e.json.materials[t];return r.extensions&&r.extensions[n]?r.extensions[n]:null}var F={KHR_BINARY_GLTF:`KHR_binary_glTF`,KHR_DRACO_MESH_COMPRESSION:`KHR_draco_mesh_compression`,KHR_LIGHTS_PUNCTUAL:`KHR_lights_punctual`,KHR_MATERIALS_CLEARCOAT:`KHR_materials_clearcoat`,KHR_MATERIALS_DISPERSION:`KHR_materials_dispersion`,KHR_MATERIALS_IOR:`KHR_materials_ior`,KHR_MATERIALS_SHEEN:`KHR_materials_sheen`,KHR_MATERIALS_SPECULAR:`KHR_materials_specular`,KHR_MATERIALS_TRANSMISSION:`KHR_materials_transmission`,KHR_MATERIALS_IRIDESCENCE:`KHR_materials_iridescence`,KHR_MATERIALS_ANISOTROPY:`KHR_materials_anisotropy`,KHR_MATERIALS_UNLIT:`KHR_materials_unlit`,KHR_MATERIALS_VOLUME:`KHR_materials_volume`,KHR_TEXTURE_BASISU:`KHR_texture_basisu`,KHR_TEXTURE_TRANSFORM:`KHR_texture_transform`,KHR_MESH_QUANTIZATION:`KHR_mesh_quantization`,KHR_MATERIALS_EMISSIVE_STRENGTH:`KHR_materials_emissive_strength`,EXT_MATERIALS_BUMP:`EXT_materials_bump`,EXT_TEXTURE_WEBP:`EXT_texture_webp`,EXT_TEXTURE_AVIF:`EXT_texture_avif`,EXT_MESHOPT_COMPRESSION:`EXT_meshopt_compression`,KHR_MESHOPT_COMPRESSION:`KHR_meshopt_compression`,EXT_MESH_GPU_INSTANCING:`EXT_mesh_gpu_instancing`},ze=class{constructor(e){this.parser=e,this.name=F.KHR_LIGHTS_PUNCTUAL,this.cache={refs:{},uses:{}}}_markDefs(){let e=this.parser,t=this.parser.json.nodes||[];for(let n=0,r=t.length;n<r;n++){let r=t[n];r.extensions&&r.extensions[this.name]&&r.extensions[this.name].light!==void 0&&e._addNodeRef(this.cache,r.extensions[this.name].light)}}_loadLight(e){let t=this.parser,n=`light:`+e,r=t.cache.get(n);if(r)return r;let i=t.json,a=((i.extensions&&i.extensions[this.name]||{}).lights||[])[e],o,s=new k(16777215);a.color!==void 0&&s.setRGB(a.color[0],a.color[1],a.color[2],c);let l=a.range===void 0?0:a.range;switch(a.type){case`directional`:o=new xe(s),o.target.position.set(0,0,-1),o.add(o.target);break;case`point`:o=new be(s),o.distance=l;break;case`spot`:o=new Se(s),o.distance=l,a.spot=a.spot||{},a.spot.innerConeAngle=a.spot.innerConeAngle===void 0?0:a.spot.innerConeAngle,a.spot.outerConeAngle=a.spot.outerConeAngle===void 0?Math.PI/4:a.spot.outerConeAngle,o.angle=a.spot.outerConeAngle,o.penumbra=1-a.spot.innerConeAngle/a.spot.outerConeAngle,o.target.position.set(0,0,-1),o.add(o.target);break;default:throw Error(`THREE.GLTFLoader: Unexpected light type: `+a.type)}return o.position.set(0,0,0),X(o,a),a.intensity!==void 0&&(o.intensity=a.intensity),o.name=t.createUniqueName(a.name||`light_`+e),r=Promise.resolve(o),t.cache.add(n,r),r}getDependency(e,t){if(e===`light`)return this._loadLight(t)}createNodeAttachment(e){let t=this,n=this.parser,r=n.json.nodes[e],i=(r.extensions&&r.extensions[this.name]||{}).light;return i===void 0?null:this._loadLight(i).then(function(e){return n._getNodeRef(t.cache,i,e)})}},Be=class{constructor(){this.name=F.KHR_MATERIALS_UNLIT}getMaterialType(){return b}extendParams(e,t,n){let r=[];e.color=new k(1,1,1),e.opacity=1;let i=t.pbrMetallicRoughness;if(i){if(Array.isArray(i.baseColorFactor)){let t=i.baseColorFactor;e.color.setRGB(t[0],t[1],t[2],c),e.opacity=t[3]}i.baseColorTexture!==void 0&&r.push(n.assignTexture(e,`map`,i.baseColorTexture,w))}return Promise.all(r)}},Ve=class{constructor(e){this.parser=e,this.name=F.KHR_MATERIALS_EMISSIVE_STRENGTH}extendMaterialParams(e,t){let n=P(this.parser,e,this.name);return n===null||n.emissiveStrength!==void 0&&(t.emissiveIntensity=n.emissiveStrength),Promise.resolve()}},He=class{constructor(e){this.parser=e,this.name=F.KHR_MATERIALS_CLEARCOAT}getMaterialType(e){return P(this.parser,e,this.name)===null?null:l}extendMaterialParams(e,t){let n=P(this.parser,e,this.name);if(n===null)return Promise.resolve();let r=[];if(n.clearcoatFactor!==void 0&&(t.clearcoat=n.clearcoatFactor),n.clearcoatTexture!==void 0&&r.push(this.parser.assignTexture(t,`clearcoatMap`,n.clearcoatTexture)),n.clearcoatRoughnessFactor!==void 0&&(t.clearcoatRoughness=n.clearcoatRoughnessFactor),n.clearcoatRoughnessTexture!==void 0&&r.push(this.parser.assignTexture(t,`clearcoatRoughnessMap`,n.clearcoatRoughnessTexture)),n.clearcoatNormalTexture!==void 0&&(r.push(this.parser.assignTexture(t,`clearcoatNormalMap`,n.clearcoatNormalTexture)),n.clearcoatNormalTexture.scale!==void 0)){let e=n.clearcoatNormalTexture.scale;t.clearcoatNormalScale=new A(e,e)}return Promise.all(r)}},Ue=class{constructor(e){this.parser=e,this.name=F.KHR_MATERIALS_DISPERSION}getMaterialType(e){return P(this.parser,e,this.name)===null?null:l}extendMaterialParams(e,t){let n=P(this.parser,e,this.name);return n===null||(t.dispersion=n.dispersion===void 0?0:n.dispersion),Promise.resolve()}},We=class{constructor(e){this.parser=e,this.name=F.KHR_MATERIALS_IRIDESCENCE}getMaterialType(e){return P(this.parser,e,this.name)===null?null:l}extendMaterialParams(e,t){let n=P(this.parser,e,this.name);if(n===null)return Promise.resolve();let r=[];return n.iridescenceFactor!==void 0&&(t.iridescence=n.iridescenceFactor),n.iridescenceTexture!==void 0&&r.push(this.parser.assignTexture(t,`iridescenceMap`,n.iridescenceTexture)),n.iridescenceIor!==void 0&&(t.iridescenceIOR=n.iridescenceIor),t.iridescenceThicknessRange===void 0&&(t.iridescenceThicknessRange=[100,400]),n.iridescenceThicknessMinimum!==void 0&&(t.iridescenceThicknessRange[0]=n.iridescenceThicknessMinimum),n.iridescenceThicknessMaximum!==void 0&&(t.iridescenceThicknessRange[1]=n.iridescenceThicknessMaximum),n.iridescenceThicknessTexture!==void 0&&r.push(this.parser.assignTexture(t,`iridescenceThicknessMap`,n.iridescenceThicknessTexture)),Promise.all(r)}},Ge=class{constructor(e){this.parser=e,this.name=F.KHR_MATERIALS_SHEEN}getMaterialType(e){return P(this.parser,e,this.name)===null?null:l}extendMaterialParams(e,t){let n=P(this.parser,e,this.name);if(n===null)return Promise.resolve();let r=[];if(t.sheenColor=new k(0,0,0),t.sheenRoughness=0,t.sheen=1,n.sheenColorFactor!==void 0){let e=n.sheenColorFactor;t.sheenColor.setRGB(e[0],e[1],e[2],c)}return n.sheenRoughnessFactor!==void 0&&(t.sheenRoughness=n.sheenRoughnessFactor),n.sheenColorTexture!==void 0&&r.push(this.parser.assignTexture(t,`sheenColorMap`,n.sheenColorTexture,w)),n.sheenRoughnessTexture!==void 0&&r.push(this.parser.assignTexture(t,`sheenRoughnessMap`,n.sheenRoughnessTexture)),Promise.all(r)}},Ke=class{constructor(e){this.parser=e,this.name=F.KHR_MATERIALS_TRANSMISSION}getMaterialType(e){return P(this.parser,e,this.name)===null?null:l}extendMaterialParams(e,t){let n=P(this.parser,e,this.name);if(n===null)return Promise.resolve();let r=[];return n.transmissionFactor!==void 0&&(t.transmission=n.transmissionFactor),n.transmissionTexture!==void 0&&r.push(this.parser.assignTexture(t,`transmissionMap`,n.transmissionTexture)),Promise.all(r)}},qe=class{constructor(e){this.parser=e,this.name=F.KHR_MATERIALS_VOLUME}getMaterialType(e){return P(this.parser,e,this.name)===null?null:l}extendMaterialParams(e,t){let n=P(this.parser,e,this.name);if(n===null)return Promise.resolve();let r=[];t.thickness=n.thicknessFactor===void 0?0:n.thicknessFactor,n.thicknessTexture!==void 0&&r.push(this.parser.assignTexture(t,`thicknessMap`,n.thicknessTexture)),t.attenuationDistance=n.attenuationDistance||1/0;let i=n.attenuationColor||[1,1,1];return t.attenuationColor=new k().setRGB(i[0],i[1],i[2],c),Promise.all(r)}},Je=class{constructor(e){this.parser=e,this.name=F.KHR_MATERIALS_IOR}getMaterialType(e){return P(this.parser,e,this.name)===null?null:l}extendMaterialParams(e,t){let n=P(this.parser,e,this.name);return n===null?Promise.resolve():(t.ior=n.ior===void 0?1.5:n.ior,t.ior===0&&(t.ior=1e3),Promise.resolve())}},Ye=class{constructor(e){this.parser=e,this.name=F.KHR_MATERIALS_SPECULAR}getMaterialType(e){return P(this.parser,e,this.name)===null?null:l}extendMaterialParams(e,t){let n=P(this.parser,e,this.name);if(n===null)return Promise.resolve();let r=[];t.specularIntensity=n.specularFactor===void 0?1:n.specularFactor,n.specularTexture!==void 0&&r.push(this.parser.assignTexture(t,`specularIntensityMap`,n.specularTexture));let i=n.specularColorFactor||[1,1,1];return t.specularColor=new k().setRGB(i[0],i[1],i[2],c),n.specularColorTexture!==void 0&&r.push(this.parser.assignTexture(t,`specularColorMap`,n.specularColorTexture,w)),Promise.all(r)}},Xe=class{constructor(e){this.parser=e,this.name=F.EXT_MATERIALS_BUMP}getMaterialType(e){return P(this.parser,e,this.name)===null?null:l}extendMaterialParams(e,t){let n=P(this.parser,e,this.name);if(n===null)return Promise.resolve();let r=[];return t.bumpScale=n.bumpFactor===void 0?1:n.bumpFactor,n.bumpTexture!==void 0&&r.push(this.parser.assignTexture(t,`bumpMap`,n.bumpTexture)),Promise.all(r)}},Ze=class{constructor(e){this.parser=e,this.name=F.KHR_MATERIALS_ANISOTROPY}getMaterialType(e){return P(this.parser,e,this.name)===null?null:l}extendMaterialParams(e,t){let n=P(this.parser,e,this.name);if(n===null)return Promise.resolve();let r=[];return n.anisotropyStrength!==void 0&&(t.anisotropy=n.anisotropyStrength),n.anisotropyRotation!==void 0&&(t.anisotropyRotation=n.anisotropyRotation),n.anisotropyTexture!==void 0&&r.push(this.parser.assignTexture(t,`anisotropyMap`,n.anisotropyTexture)),Promise.all(r)}},Qe=class{constructor(e){this.parser=e,this.name=F.KHR_TEXTURE_BASISU}loadTexture(e){let t=this.parser,n=t.json,r=n.textures[e];if(!r.extensions||!r.extensions[this.name])return null;let i=r.extensions[this.name],a=t.options.ktx2Loader;if(!a){if(n.extensionsRequired&&n.extensionsRequired.indexOf(this.name)>=0)throw Error(`THREE.GLTFLoader: setKTX2Loader must be called before loading KTX2 textures`);return null}return t.loadTextureImage(e,i.source,a)}},$e=class{constructor(e){this.parser=e,this.name=F.EXT_TEXTURE_WEBP}loadTexture(e){let t=this.name,n=this.parser,r=n.json,i=r.textures[e];if(!i.extensions||!i.extensions[t])return null;let a=i.extensions[t],o=r.images[a.source],s=n.textureLoader;if(o.uri){let e=n.options.manager.getHandler(o.uri);e!==null&&(s=e)}return n.loadTextureImage(e,a.source,s)}},et=class{constructor(e){this.parser=e,this.name=F.EXT_TEXTURE_AVIF}loadTexture(e){let t=this.name,n=this.parser,r=n.json,i=r.textures[e];if(!i.extensions||!i.extensions[t])return null;let a=i.extensions[t],o=r.images[a.source],s=n.textureLoader;if(o.uri){let e=n.options.manager.getHandler(o.uri);e!==null&&(s=e)}return n.loadTextureImage(e,a.source,s)}},I=class{constructor(e,t){this.name=t,this.parser=e}loadBufferView(e){let t=this.parser.json,n=t.bufferViews[e];if(n.extensions&&n.extensions[this.name]){let e=n.extensions[this.name],r=this.parser.getDependency(`buffer`,e.buffer),i=this.parser.options.meshoptDecoder;if(!i||!i.supported){if(t.extensionsRequired&&t.extensionsRequired.indexOf(this.name)>=0)throw Error(`THREE.GLTFLoader: setMeshoptDecoder must be called before loading compressed files`);return null}return r.then(function(t){let n=e.byteOffset||0,r=e.byteLength||0,a=e.count,o=e.byteStride,s=new Uint8Array(t,n,r);return i.decodeGltfBufferAsync?i.decodeGltfBufferAsync(a,o,s,e.mode,e.filter).then(function(e){return e.buffer}):i.ready.then(function(){let t=new ArrayBuffer(a*o);return i.decodeGltfBuffer(new Uint8Array(t),a,o,s,e.mode,e.filter),t})})}return null}},tt=class{constructor(e){this.name=F.EXT_MESH_GPU_INSTANCING,this.parser=e}createNodeMesh(e){let t=this.parser.json,n=t.nodes[e];if(!n.extensions||!n.extensions[this.name]||n.mesh===void 0)return null;let r=t.meshes[n.mesh];for(let e of r.primitives)if(e.mode!==V.TRIANGLES&&e.mode!==V.TRIANGLE_STRIP&&e.mode!==V.TRIANGLE_FAN&&e.mode!==void 0)return null;let i=n.extensions[this.name].attributes,a=[],o={};for(let e in i)a.push(this.parser.getDependency(`accessor`,i[e]).then(t=>(o[e]=t,o[e])));return a.length<1?null:(a.push(this.parser.createNodeMesh(e)),Promise.all(a).then(e=>{let t=e.pop(),n=t.isGroup?t.children:[t],r=e[0].count,i=[];for(let e of n){let t=new x,n=new y,a=new D,s=new y(1,1,1),c=new je(e.geometry,e.material,r);for(let e=0;e<r;e++)o.TRANSLATION&&n.fromBufferAttribute(o.TRANSLATION,e),o.ROTATION&&a.fromBufferAttribute(o.ROTATION,e),o.SCALE&&s.fromBufferAttribute(o.SCALE,e),c.setMatrixAt(e,t.compose(n,a,s));for(let t in o)if(t===`_COLOR_0`){let e=o[t];c.instanceColor=new ke(e.array,e.itemSize,e.normalized)}else t!==`TRANSLATION`&&t!==`ROTATION`&&t!==`SCALE`&&e.geometry.setAttribute(t,o[t]);v.prototype.copy.call(c,e),this.parser.assignFinalMaterial(c),i.push(c)}return t.isGroup?(t.clear(),t.add(...i),t):i[0]}))}},L=`glTF`,R=12,z={JSON:1313821514,BIN:5130562},nt=class{constructor(e){this.name=F.KHR_BINARY_GLTF,this.content=null,this.body=null;let t=new DataView(e,0,R),n=new TextDecoder;if(this.header={magic:n.decode(new Uint8Array(e.slice(0,4))),version:t.getUint32(4,!0),length:t.getUint32(8,!0)},this.header.magic!==L)throw Error(`THREE.GLTFLoader: Unsupported glTF-Binary header.`);if(this.header.version<2)throw Error(`THREE.GLTFLoader: Legacy binary file detected.`);let r=this.header.length-R,i=new DataView(e,R),a=0;for(;a<r;){let t=i.getUint32(a,!0);a+=4;let r=i.getUint32(a,!0);if(a+=4,r===z.JSON){let r=new Uint8Array(e,R+a,t);this.content=n.decode(r)}else if(r===z.BIN){let n=R+a;this.body=e.slice(n,n+t)}a+=t}if(this.content===null)throw Error(`THREE.GLTFLoader: JSON content not found.`)}},rt=class{constructor(e,t){if(!t)throw Error(`THREE.GLTFLoader: No DRACOLoader instance provided.`);this.name=F.KHR_DRACO_MESH_COMPRESSION,this.json=e,this.dracoLoader=t,this.dracoLoader.preload()}decodePrimitive(e,t){let n=this.json,r=this.dracoLoader,i=e.extensions[this.name].bufferView,a=e.extensions[this.name].attributes,o={},s={},l={};for(let e in a){let t=K[e]||e.toLowerCase();o[t]=a[e]}for(let t in e.attributes){let r=K[t]||t.toLowerCase();if(a[t]!==void 0){let i=n.accessors[e.attributes[t]];l[r]=H[i.componentType].name,s[r]=i.normalized===!0}}return t.getDependency(`bufferView`,i).then(function(e){return new Promise(function(t,n){r.decodeDracoFile(e,function(e){for(let t in e.attributes){let n=e.attributes[t],r=s[t];r!==void 0&&(n.normalized=r)}t(e)},o,l,c,n)})})}},it=class{constructor(){this.name=F.KHR_TEXTURE_TRANSFORM}extendTexture(e,t){return(t.texCoord===void 0||t.texCoord===e.channel)&&t.offset===void 0&&t.rotation===void 0&&t.scale===void 0?e:(e=e.clone(),t.texCoord!==void 0&&(e.channel=t.texCoord),t.offset!==void 0&&e.offset.fromArray(t.offset),t.rotation!==void 0&&(e.rotation=t.rotation),t.scale!==void 0&&e.repeat.fromArray(t.scale),e.needsUpdate=!0,e)}},at=class{constructor(){this.name=F.KHR_MESH_QUANTIZATION}},B=class extends te{constructor(e,t,n,r){super(e,t,n,r)}copySampleValue_(e){let t=this.resultBuffer,n=this.sampleValues,r=this.valueSize,i=e*r*3+r;for(let e=0;e!==r;e++)t[e]=n[i+e];return t}interpolate_(e,t,n,r){let i=this.resultBuffer,a=this.sampleValues,o=this.valueSize,s=o*2,c=o*3,l=r-t,u=(n-t)/l,d=u*u,f=d*u,p=e*c,m=p-c,h=-2*f+3*d,g=f-d,ee=1-h,_=g-d+u;for(let e=0;e!==o;e++){let t=a[m+e+o],n=a[m+e+s]*l,r=a[p+e+o],c=a[p+e]*l;i[e]=ee*t+_*n+h*r+g*c}return i}},ot=new D,st=class extends B{interpolate_(e,t,n,r){let i=super.interpolate_(e,t,n,r);return ot.fromArray(i).normalize().toArray(i),i}},V={FLOAT:5126,FLOAT_MAT3:35675,FLOAT_MAT4:35676,FLOAT_VEC2:35664,FLOAT_VEC3:35665,FLOAT_VEC4:35666,LINEAR:9729,REPEAT:10497,SAMPLER_2D:35678,POINTS:0,LINES:1,LINE_LOOP:2,LINE_STRIP:3,TRIANGLES:4,TRIANGLE_STRIP:5,TRIANGLE_FAN:6,UNSIGNED_BYTE:5121,UNSIGNED_SHORT:5123},H={5120:Int8Array,5121:Uint8Array,5122:Int16Array,5123:Uint16Array,5125:Uint32Array,5126:Float32Array},U={9728:f,9729:h,9984:ne,9985:_,9986:re,9987:g},W={33071:ve,33648:Ce,10497:ce},G={SCALAR:1,VEC2:2,VEC3:3,VEC4:4,MAT2:4,MAT3:9,MAT4:16},K={POSITION:`position`,NORMAL:`normal`,TANGENT:`tangent`,TEXCOORD_0:`uv`,TEXCOORD_1:`uv1`,TEXCOORD_2:`uv2`,TEXCOORD_3:`uv3`,COLOR_0:`color`,WEIGHTS_0:`skinWeight`,JOINTS_0:`skinIndex`},q={scale:`scale`,translation:`position`,rotation:`quaternion`,weights:`morphTargetInfluences`},ct={CUBICSPLINE:void 0,LINEAR:o,STEP:s},J={OPAQUE:`OPAQUE`,MASK:`MASK`,BLEND:`BLEND`};function lt(e){return e.DefaultMaterial===void 0&&(e.DefaultMaterial=new p({color:16777215,emissive:0,metalness:1,roughness:1,transparent:!1,depthTest:!0,side:0})),e.DefaultMaterial}function Y(e,t,n){for(let r in n.extensions)e[r]===void 0&&(t.userData.gltfExtensions=t.userData.gltfExtensions||{},t.userData.gltfExtensions[r]=n.extensions[r])}function X(e,t){t.extras!==void 0&&(typeof t.extras==`object`?Object.assign(e.userData,t.extras):console.warn(`THREE.GLTFLoader: Ignoring primitive type .extras, `+t.extras))}function ut(e,t,n){let r=!1,i=!1,a=!1;for(let e=0,n=t.length;e<n;e++){let n=t[e];if(n.POSITION!==void 0&&(r=!0),n.NORMAL!==void 0&&(i=!0),n.COLOR_0!==void 0&&(a=!0),r&&i&&a)break}if(!r&&!i&&!a)return Promise.resolve(e);let o=[],s=[],c=[];for(let l=0,u=t.length;l<u;l++){let u=t[l];if(r){let t=u.POSITION===void 0?e.attributes.position:n.getDependency(`accessor`,u.POSITION);o.push(t)}if(i){let t=u.NORMAL===void 0?e.attributes.normal:n.getDependency(`accessor`,u.NORMAL);s.push(t)}if(a){let t=u.COLOR_0===void 0?e.attributes.color:n.getDependency(`accessor`,u.COLOR_0);c.push(t)}}return Promise.all([Promise.all(o),Promise.all(s),Promise.all(c)]).then(function(t){let n=t[0],o=t[1],s=t[2];return r&&(e.morphAttributes.position=n),i&&(e.morphAttributes.normal=o),a&&(e.morphAttributes.color=s),e.morphTargetsRelative=!0,e})}function dt(e,t){if(e.updateMorphTargets(),t.weights!==void 0)for(let n=0,r=t.weights.length;n<r;n++)e.morphTargetInfluences[n]=t.weights[n];if(t.extras&&Array.isArray(t.extras.targetNames)){let n=t.extras.targetNames;if(e.morphTargetInfluences.length===n.length){e.morphTargetDictionary={};for(let t=0,r=n.length;t<r;t++)e.morphTargetDictionary[n[t]]=t}else console.warn(`THREE.GLTFLoader: Invalid extras.targetNames length. Ignoring names.`)}}function ft(e){let t,n=e.extensions&&e.extensions[F.KHR_DRACO_MESH_COMPRESSION];if(t=n?`draco:`+n.bufferView+`:`+n.indices+`:`+Z(n.attributes):e.indices+`:`+Z(e.attributes)+`:`+e.mode,e.targets!==void 0)for(let n=0,r=e.targets.length;n<r;n++)t+=`:`+Z(e.targets[n]);return t}function Z(e){let t=``,n=Object.keys(e).sort();for(let r=0,i=n.length;r<i;r++)t+=n[r]+`:`+e[n[r]]+`;`;return t}function Q(e){switch(e){case Int8Array:return 1/127;case Uint8Array:return 1/255;case Int16Array:return 1/32767;case Uint16Array:return 1/65535;default:throw Error(`THREE.GLTFLoader: Unsupported normalized accessor component type.`)}}function pt(e){return e.search(/\.jpe?g($|\?)/i)>0||e.search(/^data\:image\/jpeg/)===0?`image/jpeg`:e.search(/\.webp($|\?)/i)>0||e.search(/^data\:image\/webp/)===0?`image/webp`:e.search(/\.ktx2($|\?)/i)>0||e.search(/^data\:image\/ktx2/)===0?`image/ktx2`:`image/png`}var mt=new x,ht=class{constructor(e={},t={}){this.json=e,this.extensions={},this.plugins={},this.options=t,this.cache=new Re,this.associations=new Map,this.primitiveCache={},this.nodeCache={},this.meshCache={refs:{},uses:{}},this.cameraCache={refs:{},uses:{}},this.lightCache={refs:{},uses:{}},this.sourceCache={},this.textureCache={},this.nodeNamesUsed={};let n=!1,r=-1,i=!1,a=-1;if(typeof navigator<`u`&&navigator.userAgent!==void 0){let e=navigator.userAgent;n=/^((?!chrome|android).)*safari/i.test(e)===!0;let t=e.match(/Version\/(\d+)/);r=n&&t?parseInt(t[1],10):-1,i=e.indexOf(`Firefox`)>-1,a=i?e.match(/Firefox\/([0-9]+)\./)[1]:-1}this.textureLoader=typeof createImageBitmap>`u`||n&&r<17||i&&a<98?new ae(this.options.manager):new ie(this.options.manager),this.textureLoader.setCrossOrigin(this.options.crossOrigin),this.textureLoader.setRequestHeader(this.options.requestHeader),this.fileLoader=new T(this.options.manager),this.fileLoader.setResponseType(`arraybuffer`),this.options.crossOrigin===`use-credentials`&&this.fileLoader.setWithCredentials(!0)}setExtensions(e){this.extensions=e}setPlugins(e){this.plugins=e}parse(e,t){let n=this,r=this.json,i=this.extensions;this.cache.removeAll(),this.nodeCache={},this._invokeAll(function(e){return e._markDefs&&e._markDefs()}),Promise.all(this._invokeAll(function(e){return e.beforeRoot&&e.beforeRoot()})).then(function(){return Promise.all([n.getDependencies(`scene`),n.getDependencies(`animation`),n.getDependencies(`camera`)])}).then(function(t){let a={scene:t[0][r.scene||0],scenes:t[0],animations:t[1],cameras:t[2],asset:r.asset,parser:n,userData:{}};return Y(i,a,r),X(a,r),Promise.all(n._invokeAll(function(e){return e.afterRoot&&e.afterRoot(a)})).then(function(){for(let e of a.scenes)e.updateMatrixWorld();e(a)})}).catch(t)}_markDefs(){let e=this.json.nodes||[],t=this.json.skins||[],n=this.json.meshes||[];for(let n=0,r=t.length;n<r;n++){let r=t[n].joints;for(let t=0,n=r.length;t<n;t++)e[r[t]].isBone=!0}for(let t=0,r=e.length;t<r;t++){let r=e[t];r.mesh!==void 0&&(this._addNodeRef(this.meshCache,r.mesh),r.skin!==void 0&&(n[r.mesh].isSkinnedMesh=!0)),r.camera!==void 0&&this._addNodeRef(this.cameraCache,r.camera)}}_addNodeRef(e,t){t!==void 0&&(e.refs[t]===void 0&&(e.refs[t]=e.uses[t]=0),e.refs[t]++)}_getNodeRef(e,t,n){if(e.refs[t]<=1)return n;let r=n.clone(),i=(e,t)=>{let n=this.associations.get(e);n!=null&&this.associations.set(t,n);for(let[n,r]of e.children.entries())i(r,t.children[n])};return i(n,r),r.name+=`_instance_`+e.uses[t]++,r}_invokeOne(e){let t=Object.values(this.plugins);t.push(this);for(let n=0;n<t.length;n++){let r=e(t[n]);if(r)return r}return null}_invokeAll(e){let t=Object.values(this.plugins);t.unshift(this);let n=[];for(let r=0;r<t.length;r++){let i=e(t[r]);i&&n.push(i)}return n}getDependency(e,t){let n=e+`:`+t,r=this.cache.get(n);if(!r){switch(e){case`scene`:r=this.loadScene(t);break;case`node`:r=this._invokeOne(function(e){return e.loadNode&&e.loadNode(t)});break;case`mesh`:r=this._invokeOne(function(e){return e.loadMesh&&e.loadMesh(t)});break;case`accessor`:r=this.loadAccessor(t);break;case`bufferView`:r=this._invokeOne(function(e){return e.loadBufferView&&e.loadBufferView(t)});break;case`buffer`:r=this.loadBuffer(t);break;case`material`:r=this._invokeOne(function(e){return e.loadMaterial&&e.loadMaterial(t)});break;case`texture`:r=this._invokeOne(function(e){return e.loadTexture&&e.loadTexture(t)});break;case`skin`:r=this.loadSkin(t);break;case`animation`:r=this._invokeOne(function(e){return e.loadAnimation&&e.loadAnimation(t)});break;case`camera`:r=this.loadCamera(t);break;default:if(r=this._invokeOne(function(n){return n!=this&&n.getDependency&&n.getDependency(e,t)}),!r)throw Error(`Unknown type: `+e)}this.cache.add(n,r)}return r}getDependencies(e){let t=this.cache.get(e);if(!t){let n=this,r=this.json[e+(e===`mesh`?`es`:`s`)]||[];t=Promise.all(r.map(function(t,r){return n.getDependency(e,r)})),this.cache.add(e,t)}return t}loadBuffer(e){let t=this.json.buffers[e],n=this.fileLoader;if(t.type&&t.type!==`arraybuffer`)throw Error(`THREE.GLTFLoader: `+t.type+` buffer type is not supported.`);if(t.uri===void 0&&e===0)return Promise.resolve(this.extensions[F.KHR_BINARY_GLTF].body);let r=this.options;return new Promise(function(e,i){n.load(m.resolveURL(t.uri,r.path),e,void 0,function(){i(Error(`THREE.GLTFLoader: Failed to load buffer "`+t.uri+`".`))})})}loadBufferView(e){let t=this.json.bufferViews[e];return this.getDependency(`buffer`,t.buffer).then(function(e){let n=t.byteLength||0,r=t.byteOffset||0;return e.slice(r,r+n)})}loadAccessor(e){let t=this,n=this.json,r=this.json.accessors[e];if(r.bufferView===void 0&&r.sparse===void 0){let e=G[r.type],t=H[r.componentType],n=r.normalized===!0,i=new t(r.count*e);return Promise.resolve(new E(i,e,n))}let a=[];return r.bufferView===void 0?a.push(null):a.push(this.getDependency(`bufferView`,r.bufferView)),r.sparse!==void 0&&(a.push(this.getDependency(`bufferView`,r.sparse.indices.bufferView)),a.push(this.getDependency(`bufferView`,r.sparse.values.bufferView))),Promise.all(a).then(function(e){let a=e[0],o=G[r.type],s=H[r.componentType],c=s.BYTES_PER_ELEMENT,l=c*o,u=r.byteOffset||0,d=r.bufferView===void 0?void 0:n.bufferViews[r.bufferView].byteStride,f=r.normalized===!0,p,m;if(d&&d!==l){let e=Math.floor(u/d),n=`InterleavedBuffer:`+r.bufferView+`:`+r.componentType+`:`+e+`:`+r.count,l=t.cache.get(n);l||(p=new s(a,e*d,r.count*d/c),l=new i(p,d/c),t.cache.add(n,l)),m=new Ae(l,o,u%d/c,f)}else p=a===null?new s(r.count*o):new s(a,u,r.count*o),m=new E(p,o,f);if(r.sparse!==void 0){let t=G.SCALAR,n=H[r.sparse.indices.componentType],i=r.sparse.indices.byteOffset||0,c=r.sparse.values.byteOffset||0,l=new n(e[1],i,r.sparse.count*t),u=new s(e[2],c,r.sparse.count*o);a!==null&&(m=new E(m.array.slice(),m.itemSize,m.normalized)),m.normalized=!1;for(let e=0,t=l.length;e<t;e++){let t=l[e];if(m.setX(t,u[e*o]),o>=2&&m.setY(t,u[e*o+1]),o>=3&&m.setZ(t,u[e*o+2]),o>=4&&m.setW(t,u[e*o+3]),o>=5)throw Error(`THREE.GLTFLoader: Unsupported itemSize in sparse BufferAttribute.`)}m.normalized=f}return m})}loadTexture(e){let t=this.json,n=this.options,r=t.textures[e].source,i=t.images[r],a=this.textureLoader;if(i.uri){let e=n.manager.getHandler(i.uri);e!==null&&(a=e)}return this.loadTextureImage(e,r,a)}loadTextureImage(e,t,n){let r=this,i=this.json,a=i.textures[e],o=i.images[t],s=(o.uri||o.bufferView)+`:`+a.sampler;if(this.textureCache[s])return this.textureCache[s];let c=this.loadImageSource(t,n).then(function(t){t.flipY=!1,t.name=a.name||o.name||``,t.name===``&&typeof o.uri==`string`&&o.uri.startsWith(`data:image/`)===!1&&(t.name=o.uri);let n=(i.samplers||{})[a.sampler]||{};return t.magFilter=U[n.magFilter]||1006,t.minFilter=U[n.minFilter]||1008,t.wrapS=W[n.wrapS]||1e3,t.wrapT=W[n.wrapT]||1e3,t.generateMipmaps=!t.isCompressedTexture&&t.minFilter!==1003&&t.minFilter!==1006,r.associations.set(t,{textures:e}),t}).catch(function(){return null});return this.textureCache[s]=c,c}loadImageSource(e,t){let n=this,r=this.json,i=this.options;if(this.sourceCache[e]!==void 0)return this.sourceCache[e].then(e=>e.clone());let a=r.images[e],o=self.URL||self.webkitURL,s=a.uri||``,c=!1;if(a.bufferView!==void 0)s=n.getDependency(`bufferView`,a.bufferView).then(function(e){c=!0;let t=new Blob([e],{type:a.mimeType});return s=o.createObjectURL(t),s});else if(a.uri===void 0)throw Error(`THREE.GLTFLoader: Image `+e+` is missing URI and bufferView`);let l=Promise.resolve(s).then(function(e){return new Promise(function(n,r){let a=n;t.isImageBitmapLoader===!0&&(a=function(e){let t=new pe(e);t.needsUpdate=!0,n(t)}),t.load(m.resolveURL(e,i.path),a,void 0,r)})}).then(function(e){return c===!0&&o.revokeObjectURL(s),X(e,a),e.userData.mimeType=a.mimeType||pt(a.uri),e}).catch(function(e){throw console.error(`THREE.GLTFLoader: Couldn't load texture`,s),e});return this.sourceCache[e]=l,l}assignTexture(e,t,n,r){let i=this;return this.getDependency(`texture`,n.index).then(function(a){if(!a)return null;if(n.texCoord!==void 0&&n.texCoord>0&&(a=a.clone(),a.channel=n.texCoord),i.extensions[F.KHR_TEXTURE_TRANSFORM]){let e=n.extensions===void 0?void 0:n.extensions[F.KHR_TEXTURE_TRANSFORM];if(e){let t=i.associations.get(a);a=i.extensions[F.KHR_TEXTURE_TRANSFORM].extendTexture(a,e),i.associations.set(a,t)}}return r!==void 0&&(a.colorSpace=r),e[t]=a,a})}assignFinalMaterial(e){let t=e.geometry,n=e.material,r=t.attributes.tangent===void 0,i=t.attributes.color!==void 0,a=t.attributes.normal===void 0;if(e.isPoints){let e=`PointsMaterial:`+n.uuid,t=this.cache.get(e);t||(t=new he,j.prototype.copy.call(t,n),t.color.copy(n.color),t.map=n.map,t.sizeAttenuation=!1,this.cache.add(e,t)),n=t}else if(e.isLine){let e=`LineBasicMaterial:`+n.uuid,t=this.cache.get(e);t||(t=new _e,j.prototype.copy.call(t,n),t.color.copy(n.color),t.map=n.map,this.cache.add(e,t)),n=t}if(r||i||a){let e=`ClonedMaterial:`+n.uuid+`:`;r&&(e+=`derivative-tangents:`),i&&(e+=`vertex-colors:`),a&&(e+=`flat-shading:`);let t=this.cache.get(e);t||(t=n.clone(),i&&(t.vertexColors=!0),a&&(t.flatShading=!0),r&&(t.normalScale&&(t.normalScale.y*=-1),t.clearcoatNormalScale&&(t.clearcoatNormalScale.y*=-1)),this.cache.add(e,t),this.associations.set(t,this.associations.get(n))),n=t}e.material=n}getMaterialType(){return p}loadMaterial(e){let t=this,n=this.json,r=this.extensions,i=n.materials[e],a,o={},s=i.extensions||{},l=[];if(s[F.KHR_MATERIALS_UNLIT]){let e=r[F.KHR_MATERIALS_UNLIT];a=e.getMaterialType(),l.push(e.extendParams(o,i,t))}else{let n=i.pbrMetallicRoughness||{};if(o.color=new k(1,1,1),o.opacity=1,Array.isArray(n.baseColorFactor)){let e=n.baseColorFactor;o.color.setRGB(e[0],e[1],e[2],c),o.opacity=e[3]}n.baseColorTexture!==void 0&&l.push(t.assignTexture(o,`map`,n.baseColorTexture,w)),o.metalness=n.metallicFactor===void 0?1:n.metallicFactor,o.roughness=n.roughnessFactor===void 0?1:n.roughnessFactor,n.metallicRoughnessTexture!==void 0&&(l.push(t.assignTexture(o,`metalnessMap`,n.metallicRoughnessTexture)),l.push(t.assignTexture(o,`roughnessMap`,n.metallicRoughnessTexture))),a=this._invokeOne(function(t){return t.getMaterialType&&t.getMaterialType(e)}),l.push(Promise.all(this._invokeAll(function(t){return t.extendMaterialParams&&t.extendMaterialParams(e,o)})))}i.doubleSided===!0&&(o.side=2);let u=i.alphaMode||J.OPAQUE;if(u===J.BLEND?(o.transparent=!0,o.depthWrite=!1):(o.transparent=!1,u===J.MASK&&(o.alphaTest=i.alphaCutoff===void 0?.5:i.alphaCutoff)),i.normalTexture!==void 0&&a!==b&&(l.push(t.assignTexture(o,`normalMap`,i.normalTexture)),o.normalScale=new A(1,1),i.normalTexture.scale!==void 0)){let e=i.normalTexture.scale;o.normalScale.set(e,e)}if(i.occlusionTexture!==void 0&&a!==b&&(l.push(t.assignTexture(o,`aoMap`,i.occlusionTexture)),i.occlusionTexture.strength!==void 0&&(o.aoMapIntensity=i.occlusionTexture.strength)),i.emissiveFactor!==void 0&&a!==b){let e=i.emissiveFactor;o.emissive=new k().setRGB(e[0],e[1],e[2],c)}return i.emissiveTexture!==void 0&&a!==b&&l.push(t.assignTexture(o,`emissiveMap`,i.emissiveTexture,w)),Promise.all(l).then(function(){let n=new a(o);return i.name&&(n.name=i.name),X(n,i),t.associations.set(n,{materials:e}),i.extensions&&Y(r,n,i),n})}createUniqueName(e){let t=se.sanitizeNodeName(e||``);return t in this.nodeNamesUsed?t+`_`+ ++this.nodeNamesUsed[t]:(this.nodeNamesUsed[t]=0,t)}loadGeometries(e){let t=this,n=this.extensions,r=this.primitiveCache;function i(e){return n[F.KHR_DRACO_MESH_COMPRESSION].decodePrimitive(e,t).then(function(n){return $(n,e,t)})}let a=[];for(let n=0,o=e.length;n<o;n++){let o=e[n],s=ft(o),c=r[s];if(c)a.push(c.promise);else{let e;e=o.extensions&&o.extensions[F.KHR_DRACO_MESH_COMPRESSION]?i(o):$(new Ee,o,t),r[s]={primitive:o,promise:e},a.push(e)}}return Promise.all(a)}loadMesh(e){let t=this,r=this.json,i=this.extensions,a=r.meshes[e],o=a.primitives,s=[];for(let e=0,t=o.length;e<t;e++){let t=o[e].material===void 0?lt(this.cache):this.getDependency(`material`,o[e].material);s.push(t)}return s.push(t.loadGeometries(o)),Promise.all(s).then(function(r){let s=r.slice(0,r.length-1),c=r[r.length-1],l=[];for(let r=0,d=c.length;r<d;r++){let d=c[r],f=o[r],p,m=s[r];if(f.mode===V.TRIANGLES||f.mode===V.TRIANGLE_STRIP||f.mode===V.TRIANGLE_FAN||f.mode===void 0)p=a.isSkinnedMesh===!0?new ue(d,m):new u(d,m),p.isSkinnedMesh===!0&&p.normalizeSkinWeights(),f.mode===V.TRIANGLE_STRIP?p.geometry=M(p.geometry,1):f.mode===V.TRIANGLE_FAN&&(p.geometry=M(p.geometry,2));else if(f.mode===V.LINES)p=new ge(d,m);else if(f.mode===V.LINE_STRIP)p=new ee(d,m);else if(f.mode===V.LINE_LOOP)p=new n(d,m);else if(f.mode===V.POINTS)p=new Te(d,m);else throw Error(`THREE.GLTFLoader: Primitive mode unsupported: `+f.mode);Object.keys(p.geometry.morphAttributes).length>0&&dt(p,a),p.name=t.createUniqueName(a.name||`mesh_`+e),X(p,a),f.extensions&&Y(i,p,f),t.assignFinalMaterial(p),l.push(p)}for(let n=0,r=l.length;n<r;n++)t.associations.set(l[n],{meshes:e,primitives:n});if(l.length===1)return a.extensions&&Y(i,l[0],a),l[0];let d=new C;a.extensions&&Y(i,d,a),t.associations.set(d,{meshes:e});for(let e=0,t=l.length;e<t;e++)d.add(l[e]);return d})}loadCamera(e){let t,n=this.json.cameras[e],i=n[n.type];if(!i){console.warn(`THREE.GLTFLoader: Missing camera parameters.`);return}return n.type===`perspective`?t=new De(r.radToDeg(i.yfov),i.aspectRatio||1,i.znear||1,i.zfar||2e6):n.type===`orthographic`&&(t=new de(-i.xmag,i.xmag,i.ymag,-i.ymag,i.znear,i.zfar)),n.name&&(t.name=this.createUniqueName(n.name)),X(t,n),Promise.resolve(t)}loadSkin(e){let t=this.json.skins[e],n=[];for(let e=0,r=t.joints.length;e<r;e++)n.push(this._loadNodeShallow(t.joints[e]));return t.inverseBindMatrices===void 0?n.push(null):n.push(this.getDependency(`accessor`,t.inverseBindMatrices)),Promise.all(n).then(function(e){let n=e.pop(),r=e,i=[],a=[];for(let e=0,o=r.length;e<o;e++){let o=r[e];if(o){i.push(o);let t=new x;n!==null&&t.fromArray(n.array,e*16),a.push(t)}else console.warn(`THREE.GLTFLoader: Joint "%s" could not be found.`,t.joints[e])}return new Oe(i,a)})}loadAnimation(e){let t=this.json,n=this,r=t.animations[e],i=r.name?r.name:`animation_`+e,a=[],o=[],s=[],c=[],l=[];for(let e=0,t=r.channels.length;e<t;e++){let t=r.channels[e],n=r.samplers[t.sampler],i=t.target,u=i.node,d=r.parameters===void 0?n.input:r.parameters[n.input],f=r.parameters===void 0?n.output:r.parameters[n.output];i.node!==void 0&&(a.push(this.getDependency(`node`,u)),o.push(this.getDependency(`accessor`,d)),s.push(this.getDependency(`accessor`,f)),c.push(n),l.push(i))}return Promise.all([Promise.all(a),Promise.all(o),Promise.all(s),Promise.all(c),Promise.all(l)]).then(function(e){let t=e[0],a=e[1],o=e[2],s=e[3],c=e[4],l=[];for(let e=0,r=t.length;e<r;e++){let r=t[e],i=a[e],u=o[e],d=s[e],f=c[e];if(r===void 0)continue;r.updateMatrix&&r.updateMatrix();let p=n._createAnimationTracks(r,i,u,d,f);if(p)for(let e=0;e<p.length;e++)l.push(p[e])}let u=new we(i,void 0,l);return X(u,r),u})}createNodeMesh(e){let t=this.json,n=this,r=t.nodes[e];return r.mesh===void 0?null:n.getDependency(`mesh`,r.mesh).then(function(e){let t=n._getNodeRef(n.meshCache,r.mesh,e);return r.weights!==void 0&&t.traverse(function(e){if(e.isMesh)for(let t=0,n=r.weights.length;t<n;t++)e.morphTargetInfluences[t]=r.weights[t]}),t})}loadNode(e){let t=this.json,n=this,r=t.nodes[e],i=n._loadNodeShallow(e),a=[],o=r.children||[];for(let e=0,t=o.length;e<t;e++)a.push(n.getDependency(`node`,o[e]));let s=r.skin===void 0?Promise.resolve(null):n.getDependency(`skin`,r.skin);return Promise.all([i,Promise.all(a),s]).then(function(e){let t=e[0],n=e[1],r=e[2];r!==null&&t.traverse(function(e){e.isSkinnedMesh&&e.bind(r,mt)});for(let e=0,r=n.length;e<r;e++)t.add(n[e]);if(t.userData.pivot!==void 0&&n.length>0){let e=t.userData.pivot,r=n[0];t.pivot=new y().fromArray(e),t.position.x-=e[0],t.position.y-=e[1],t.position.z-=e[2],r.position.set(0,0,0),delete t.userData.pivot}return t})}_loadNodeShallow(e){let t=this.json,n=this.extensions,r=this;if(this.nodeCache[e]!==void 0)return this.nodeCache[e];let i=t.nodes[e],a=i.name?r.createUniqueName(i.name):``,o=[],s=r._invokeOne(function(t){return t.createNodeMesh&&t.createNodeMesh(e)});return s&&o.push(s),i.camera!==void 0&&o.push(r.getDependency(`camera`,i.camera).then(function(e){return r._getNodeRef(r.cameraCache,i.camera,e)})),r._invokeAll(function(t){return t.createNodeAttachment&&t.createNodeAttachment(e)}).forEach(function(e){o.push(e)}),this.nodeCache[e]=Promise.all(o).then(function(t){let o;if(o=i.isBone===!0?new me:t.length>1?new C:t.length===1?t[0]:new v,o!==t[0])for(let e=0,n=t.length;e<n;e++)o.add(t[e]);if(i.name&&(o.userData.name=i.name,o.name=a),X(o,i),i.extensions&&Y(n,o,i),i.matrix!==void 0){let e=new x;e.fromArray(i.matrix),o.applyMatrix4(e)}else i.translation!==void 0&&o.position.fromArray(i.translation),i.rotation!==void 0&&o.quaternion.fromArray(i.rotation),i.scale!==void 0&&o.scale.fromArray(i.scale);if(!r.associations.has(o))r.associations.set(o,{});else if(i.mesh!==void 0&&r.meshCache.refs[i.mesh]>1){let e=r.associations.get(o);r.associations.set(o,{...e})}return r.associations.get(o).nodes=e,o}),this.nodeCache[e]}loadScene(e){let t=this.extensions,n=this.json.scenes[e],r=this,i=new C;n.name&&(i.name=r.createUniqueName(n.name)),X(i,n),n.extensions&&Y(t,i,n);let a=n.nodes||[],o=[];for(let e=0,t=a.length;e<t;e++)o.push(r.getDependency(`node`,a[e]));return Promise.all(o).then(function(e){for(let t=0,n=e.length;t<n;t++){let n=e[t];n.parent===null?i.add(n):i.add(Ie(n))}return r.associations=(e=>{let t=new Map;for(let[e,n]of r.associations)(e instanceof j||e instanceof pe)&&t.set(e,n);return e.traverse(e=>{let n=r.associations.get(e);n!=null&&t.set(e,n)}),t})(i),i})}_createAnimationTracks(e,t,n,r,i){let s=[],c=e.name?e.name:e.uuid,l=[];function u(e){e.morphTargetInfluences&&l.push(e.name?e.name:e.uuid)}q[i.path]===q.weights?(u(e),e.isGroup&&e.children.forEach(u)):l.push(c);let d;switch(q[i.path]){case q.weights:d=S;break;case q.rotation:d=O;break;case q.translation:case q.scale:d=a;break;default:switch(n.itemSize){case 1:d=S;break;default:d=a}}let f=r.interpolation===void 0?o:ct[r.interpolation],p=this._getArrayFromAccessor(n);for(let e=0,n=l.length;e<n;e++){let n=new d(l[e]+`.`+q[i.path],t.array,p,f);r.interpolation===`CUBICSPLINE`&&this._createCubicSplineTrackInterpolant(n),s.push(n)}return s}_getArrayFromAccessor(e){let t=e.array;if(e.normalized){let e=Q(t.constructor),n=new Float32Array(t.length);for(let r=0,i=t.length;r<i;r++)n[r]=t[r]*e;t=n}return t}_createCubicSplineTrackInterpolant(e){e.createInterpolant=function(e){return new(this instanceof O?st:B)(this.times,this.values,this.getValueSize()/3,e)},e.createInterpolant.isInterpolantFactoryMethodGLTFCubicSpline=!0}};function gt(e,t,n){let r=t.attributes,i=new oe;if(r.POSITION!==void 0){let e=n.json.accessors[r.POSITION],t=e.min,a=e.max;if(t!==void 0&&a!==void 0){if(i.set(new y(t[0],t[1],t[2]),new y(a[0],a[1],a[2])),e.normalized){let t=Q(H[e.componentType]);i.min.multiplyScalar(t),i.max.multiplyScalar(t)}}else{console.warn(`THREE.GLTFLoader: Missing min/max properties for accessor POSITION.`);return}}else return;let a=t.targets;if(a!==void 0){let e=new y,t=new y;for(let r=0,i=a.length;r<i;r++){let i=a[r];if(i.POSITION!==void 0){let r=n.json.accessors[i.POSITION],a=r.min,o=r.max;if(a!==void 0&&o!==void 0){if(t.setX(Math.max(Math.abs(a[0]),Math.abs(o[0]))),t.setY(Math.max(Math.abs(a[1]),Math.abs(o[1]))),t.setZ(Math.max(Math.abs(a[2]),Math.abs(o[2]))),r.normalized){let e=Q(H[r.componentType]);t.multiplyScalar(e)}e.max(t)}else console.warn(`THREE.GLTFLoader: Missing min/max properties for accessor POSITION.`)}}i.expandByVector(e)}e.boundingBox=i;let o=new fe;i.getCenter(o.center),o.radius=i.min.distanceTo(i.max)/2,e.boundingSphere=o}function $(e,t,n){let r=t.attributes,i=[];function a(t,r){return n.getDependency(`accessor`,t).then(function(t){e.setAttribute(r,t)})}for(let t in r){let n=K[t]||t.toLowerCase();n in e.attributes||i.push(a(r[t],n))}if(t.indices!==void 0&&!e.index){let r=n.getDependency(`accessor`,t.indices).then(function(t){e.setIndex(t)});i.push(r)}return le.workingColorSpace!==`srgb-linear`&&`COLOR_0`in r&&console.warn(`THREE.GLTFLoader: Converting vertex colors from "srgb-linear" to "${le.workingColorSpace}" not supported.`),X(e,t),gt(e,t,n),Promise.all(i).then(function(){return t.targets===void 0?e:ut(e,t.targets,n)})}async function _t(n,r){let i=new DataView(n),a,o=n.byteLength>=12&&i.getUint32(0,!0)===1179937895;if(o){if(i.getUint32(4,!0)!==2||i.getUint32(8,!0)!==n.byteLength||n.byteLength<20||i.getUint32(16,!0)!==1313821514)throw Error(`Invalid GLB`);let e=i.getUint32(12,!0);if(20+e>n.byteLength||e>16777216)throw RangeError();a=new TextDecoder().decode(n.slice(20,20+e))}else a=new TextDecoder().decode(n);let s=JSON.parse(a);if(s.asset?.version!==`2.0`)throw Error(`Unsupported glTF version`);if((s.nodes?.length??0)>4096||(s.accessors?.length??0)>16384)throw RangeError();Fe(s.nodes??[],(s.scenes??[]).flatMap(e=>e.nodes??[]));let c=0;for(let e of s.accessors??[]){if(!Number.isSafeInteger(e.count)||e.count<0)throw Error(`Invalid accessor`);c+=e.count}if(c>2e7)throw RangeError();if(s.extensionsRequired?.some(e=>[`KHR_draco_mesh_compression`,`EXT_meshopt_compression`,`KHR_texture_basisu`].includes(e)))throw Error(`Compressed glTF requires an unavailable decoder`);let l=Pe(r);try{let a=0,c=0;for(let[e,u]of(s.images??[]).entries())try{if(u.uri)await l.prepare(u.uri,!0);else{let e=s.bufferViews?.[u.bufferView];if(!o||!e||e.buffer!==0)throw Error(`Unsupported embedded image storage`);let t=20+i.getUint32(12,!0);if(t+8>n.byteLength||i.getUint32(t+4,!0)!==5130562)throw Error(`Missing GLB binary chunk`);let r=e.byteOffset??0,c=e.byteLength;if(!Number.isSafeInteger(r)||!Number.isSafeInteger(c)||r<0||c<0||r+c>i.getUint32(t,!0))throw Error(`Invalid image range`);a+=await Me(new Blob([n.slice(t+8+r,t+8+r+c)]))}Ne(a+l.imagePixels,r.locale)}catch(n){if(r.signal.aborted||n instanceof RangeError||n instanceof t&&n.code===`resource-limit`)throw n;c++;let i=new Set((s.textures??[]).flatMap((t,n)=>t.source===e?[n]:[])),a=e=>{for(let[t,n]of Object.entries(e))n&&typeof n==`object`&&(t.endsWith(`Texture`)&&i.has(n.index)?delete e[t]:a(n))};for(let e of s.materials??[])a(e);s.images[e]={}}for(let e of s.buffers??[])e.uri&&await l.prepare(e.uri);let u=new Le(l.manager);for(let e of[...s.buffers??[],...s.images??[]])e.uri&&=await l.prepare(e.uri);let d=JSON.stringify(s);if(o){let e=new TextEncoder().encode(d),t=Math.ceil(e.length/4)*4,r=20+i.getUint32(12,!0),a=new Uint8Array(20+t+n.byteLength-r);a.set(new Uint8Array(n,0,12));let o=new DataView(a.buffer);o.setUint32(8,a.length,!0),o.setUint32(12,t,!0),o.setUint32(16,1313821514,!0),a.fill(32,20,20+t),a.set(e,20),a.set(new Uint8Array(n,r),20+t),d=a.buffer}l.manager.setURLModifier(e=>{if(!e.startsWith(`blob:`))throw Error(`Network blocked`);return e});let f=await u.parseAsync(d,``);if(r.signal.aborted)throw ye(f.scene),new DOMException(`Aborted`,`AbortError`);return{root:f.scene,units:`m`,animations:f.animations,description:c?e(r.locale,{en:`Some textures are missing or unsupported; geometry remains visible.`,"zh-CN":`部分纹理缺失或不受支持;几何仍可查看。`}):void 0}}finally{l.dispose()}}export{_t as loadGltf};
@@ -1 +1 @@
1
- import{o as e}from"./index-BCxD9rBl.js";function t(e){let t=new DataView(e.buffer,e.byteOffset,e.byteLength),n=0,r=0,i=0,a=[{start:0,end:e.length,kind:`root`}];for(;a.length;){let o=a.pop(),s=o.start;for(;s+8<=o.end;){if(++i>4096)return;let c=t.getUint32(s),l=8,u=String.fromCharCode(...e.subarray(s+4,s+8));if(c===1){if(s+16>o.end)return;let e=t.getBigUint64(s+8);if(e>BigInt(2**53-1))return;c=Number(e),l=16}if(c===0&&(c=o.end-s),c<l||s+c>o.end)return;let d=s+l,f=s+c;if(o.kind===`root`&&u===`meta`){if(d+4>f)return;a.push({start:d+4,end:f,kind:`meta`})}else if(o.kind===`meta`&&u===`iprp`)a.push({start:d,end:f,kind:`iprp`});else if(o.kind===`iprp`&&u===`ipco`)a.push({start:d,end:f,kind:`ipco`});else if(o.kind===`ipco`&&u===`ispe`){if(f-d!==12||t.getUint32(d)!==0)return;let e=t.getUint32(d+4),i=t.getUint32(d+8);if(!e||!i)return;n=Math.max(n,e),r=Math.max(r,i)}s=f}if(s!==o.end)return}return n&&r?{width:n,height:r}:void 0}function n(e,t,n){return String.fromCharCode(...e.subarray(t,t+n))}function r(e,t){return e[t]<<8|e[t+1]}function i(e,t){return(e[t]<<24>>>0)+(e[t+1]<<16)+(e[t+2]<<8)+e[t+3]>>>0}function a(e,t){return e[t]|e[t+1]<<8|e[t+2]<<16}function o(e,t){return e[t]|e[t+1]<<8}function s(e,t){return e[t]+(e[t+1]<<8)+(e[t+2]<<16)+(e[t+3]<<24>>>0)>>>0}function c(e,t){let n=i(e,t),r=i(e,t+4),a=n*2**32+r;return Number.isSafeInteger(a)?a:void 0}function l(e,t,r){if(r<14||n(e,t,6)!==`Exif\0\0`)return;let i=t+6,a=n(e,i,2)===`II`;if(!a&&n(e,i,2)!==`MM`)return;let o=new DataView(e.buffer,e.byteOffset,e.byteLength),s=e=>o.getUint16(e,a),c=e=>o.getUint32(e,a);if(s(i+2)!==42)return;let l=i+c(i+4);if(l+2>t+r)return;let u=s(l);for(let e=0;e<u;e+=1){let n=l+2+e*12;if(n+12>t+r)return;if(s(n)===274&&s(n+2)===3&&c(n+4)===1){let e=s(n+8);return e>=1&&e<=8?e:void 0}}}function u(e,t){if(e.length<4||e[0]!==255||e[1]!==216)return;let n=2,i,a,o;for(;n+4<=e.length;){for(;n<e.length&&e[n]===255;)n+=1;let t=e[n++];if(t===void 0||t===217||t===218)break;if(t===1||t>=208&&t<=215)continue;if(n+2>e.length)break;let s=r(e,n);if(s<2||n+s>e.length)break;let c=n+2,u=s-2;t===225&&(o??=l(e,c,u)),[192,193,194,195,197,198,199,201,202,203,205,206,207].includes(t)&&u>=5&&(a=r(e,c+1),i=r(e,c+3)),n+=s}return t&&(!i||!a)?void 0:{format:`JPEG`,width:i,height:a,animated:!1,hasAlpha:!1,orientation:o}}function d(e,t){if(e.length<24||![137,80,78,71,13,10,26,10].every((t,n)=>e[n]===t))return;let r=8,a,o,s,c,l=!1;for(;r+12<=e.length;){let t=i(e,r),u=n(e,r+4,4),d=r+12+t;if(t>e.length||d>e.length)break;if(u===`IHDR`&&t===13)a=i(e,r+8),o=i(e,r+12),s=e[r+17]===4||e[r+17]===6;else if(u===`acTL`&&t===8)c=i(e,r+8);else if(u===`tRNS`)s=!0;else if(u===`IEND`){l=!0;break}r=d}if(!(!a||!o||t&&!l))return{format:c?`APNG`:`PNG`,width:a,height:o,animated:!!(c&&c>1),frameCount:c,hasAlpha:s}}function f(e,t){let n=t;for(;n<e.length;){let t=e[n++];if(t===0)return n;if(n+=t,n>e.length)return-1}return-1}function p(e,t){if(e.length<13||![`GIF87a`,`GIF89a`].includes(n(e,0,6)))return;let r=e[6]|e[7]<<8,i=e[8]|e[9]<<8,a=e[10],o=13+(a&128?3*2**((a&7)+1):0),s=0,c=!1,l=!1;for(;o<e.length;){let n=e[o++];if(n===59){c=!0;break}if(n===33)e[o++]===249&&e[o]===4&&(l||=!!(e[o+1]&1)),o=f(e,o);else if(n===44){if(s+=1,o+9>e.length)return t?void 0:{format:`GIF`,width:r,height:i,animated:s>1,frameCount:s,hasAlpha:l};let n=e[o+8];o+=9+(n&128?3*2**((n&7)+1):0),o+=1,o=f(e,o)}else return t?void 0:{format:`GIF`,width:r,height:i,animated:s>1,frameCount:s,hasAlpha:l};if(o<0)return t?void 0:{format:`GIF`,width:r,height:i,animated:s>1,frameCount:s,hasAlpha:l}}if(!(!s||t&&!c))return{format:`GIF`,width:r,height:i,animated:s>1,frameCount:s,hasAlpha:l}}function m(e,t,n){if(t===`VP8X`&&n+10<=e.length)return{width:a(e,n+4)+1,height:a(e,n+7)+1};if(t===`VP8L`&&n+5<=e.length&&e[n]===47){let t=s(e,n+1);return{width:(t&16383)+1,height:(t>>>14&16383)+1}}if(t===`VP8 `&&n+10<=e.length&&e[n+3]===157&&e[n+4]===1&&e[n+5]===42)return{width:(e[n+6]|e[n+7]<<8)&16383,height:(e[n+8]|e[n+9]<<8)&16383}}function h(e,t){if(e.length<20||n(e,0,4)!==`RIFF`||n(e,8,4)!==`WEBP`)return;let r=s(e,4)+8;if(t&&r>e.length)return;let i=12,a,o,c=!1,l=!1,u=0;for(;i+8<=e.length&&i<r;){let t=n(e,i,4),r=s(e,i+4),d=i+8,f=d+r+r%2;if(f>e.length)break;let p=m(e,t,d);a??=p?.width,o??=p?.height,t===`VP8X`&&(c||=!!(e[d]&16),l||=!!(e[d]&2)),t===`VP8L`&&r>=5&&(c||=!!(s(e,d+1)&268435456)),t===`ALPH`&&(c=!0),t===`ANMF`&&(u+=1),i=f}if(!(!a||!o||t&&i<r))return{format:`WebP`,width:a,height:o,animated:l,frameCount:u||void 0,hasAlpha:c}}function g(e){let t=0,r=!1;for(;t+8<=e.length;){let a=i(e,t),o=n(e,t+4,4),s=a===1?16:8;if(t+s>e.length)return!1;let l=a===0?e.length-t:a===1?c(e,t+8):a;if(l===void 0||l<s||t+l>e.length)return!1;r||=o===`meta`,t+=l}return t===e.length&&r}function _(e,r){if(e.length<16||n(e,4,4)!==`ftyp`)return;let a=i(e,0);if(a<16||a>e.length)return;let o=[n(e,8,4)];for(let t=16;t+4<=a;t+=4)o.push(n(e,t,4));if(!(!o.includes(`avif`)&&!o.includes(`avis`))&&!(r&&!g(e)))return{format:`AVIF`,animated:o.includes(`avis`),...t(e)}}function v(e,t){if(e.length<26||n(e,0,2)!==`BM`)return;let r=s(e,2),i=s(e,10),a=s(e,14);if(r<26||i<14+a||i>r||t&&r>e.length)return;let c,l,u=!1;if(a===12)c=o(e,18),l=o(e,20);else if(a>=40&&e.length>=54){let t=new DataView(e.buffer,e.byteOffset,e.byteLength);c=Math.abs(t.getInt32(18,!0)),l=Math.abs(t.getInt32(22,!0)),u=t.getUint16(28,!0)===32}else return;if(!(!c||!l))return{format:`BMP`,width:c,height:l,animated:!1,hasAlpha:u}}function y(e,t){if(e.length<22||o(e,0)!==0)return;let n=o(e,2),r=o(e,4);if(n!==1&&n!==2||r===0||e.length<6+r*16)return;let i=0,a=0;for(let n=0;n<r;n+=1){let o=6+n*16,c=e[o]||256,l=e[o+1]||256,u=s(e,o+8),d=s(e,o+12);if(!u||d<6+r*16||t&&d+u>e.length)return;c*l>i*a&&(i=c,a=l)}return{format:n===1?`ICO`:`CUR`,width:i,height:a,animated:!1,hasAlpha:!0}}function b(e,t=!1){return u(e,t)??d(e,t)??p(e,t)??h(e,t)??_(e,t)??v(e,t)??y(e,t)}async function x(t,n,r){if(r.aborted||(await new Promise((i,a)=>{let o=!1,s=e=>{o||(o=!0,r.removeEventListener(`abort`,c),t.onload=null,t.onerror=null,e?a(e):i())},c=()=>{t.removeAttribute(`src`),s(e())};t.onload=()=>s(),t.onerror=()=>s(Error(`Image decoding failed.`)),r.addEventListener(`abort`,c,{once:!0}),t.src=n,typeof t.decode==`function`&&t.decode().then(()=>s(),e=>s(e))}),r.aborted))throw e()}export{b as n,x as t};
1
+ import{o as e}from"./index-DtiyOy_J.js";function t(e){let t=new DataView(e.buffer,e.byteOffset,e.byteLength),n=0,r=0,i=0,a=[{start:0,end:e.length,kind:`root`}];for(;a.length;){let o=a.pop(),s=o.start;for(;s+8<=o.end;){if(++i>4096)return;let c=t.getUint32(s),l=8,u=String.fromCharCode(...e.subarray(s+4,s+8));if(c===1){if(s+16>o.end)return;let e=t.getBigUint64(s+8);if(e>BigInt(2**53-1))return;c=Number(e),l=16}if(c===0&&(c=o.end-s),c<l||s+c>o.end)return;let d=s+l,f=s+c;if(o.kind===`root`&&u===`meta`){if(d+4>f)return;a.push({start:d+4,end:f,kind:`meta`})}else if(o.kind===`meta`&&u===`iprp`)a.push({start:d,end:f,kind:`iprp`});else if(o.kind===`iprp`&&u===`ipco`)a.push({start:d,end:f,kind:`ipco`});else if(o.kind===`ipco`&&u===`ispe`){if(f-d!==12||t.getUint32(d)!==0)return;let e=t.getUint32(d+4),i=t.getUint32(d+8);if(!e||!i)return;n=Math.max(n,e),r=Math.max(r,i)}s=f}if(s!==o.end)return}return n&&r?{width:n,height:r}:void 0}function n(e,t,n){return String.fromCharCode(...e.subarray(t,t+n))}function r(e,t){return e[t]<<8|e[t+1]}function i(e,t){return(e[t]<<24>>>0)+(e[t+1]<<16)+(e[t+2]<<8)+e[t+3]>>>0}function a(e,t){return e[t]|e[t+1]<<8|e[t+2]<<16}function o(e,t){return e[t]|e[t+1]<<8}function s(e,t){return e[t]+(e[t+1]<<8)+(e[t+2]<<16)+(e[t+3]<<24>>>0)>>>0}function c(e,t){let n=i(e,t),r=i(e,t+4),a=n*2**32+r;return Number.isSafeInteger(a)?a:void 0}function l(e,t,r){if(r<14||n(e,t,6)!==`Exif\0\0`)return;let i=t+6,a=n(e,i,2)===`II`;if(!a&&n(e,i,2)!==`MM`)return;let o=new DataView(e.buffer,e.byteOffset,e.byteLength),s=e=>o.getUint16(e,a),c=e=>o.getUint32(e,a);if(s(i+2)!==42)return;let l=i+c(i+4);if(l+2>t+r)return;let u=s(l);for(let e=0;e<u;e+=1){let n=l+2+e*12;if(n+12>t+r)return;if(s(n)===274&&s(n+2)===3&&c(n+4)===1){let e=s(n+8);return e>=1&&e<=8?e:void 0}}}function u(e,t){if(e.length<4||e[0]!==255||e[1]!==216)return;let n=2,i,a,o;for(;n+4<=e.length;){for(;n<e.length&&e[n]===255;)n+=1;let t=e[n++];if(t===void 0||t===217||t===218)break;if(t===1||t>=208&&t<=215)continue;if(n+2>e.length)break;let s=r(e,n);if(s<2||n+s>e.length)break;let c=n+2,u=s-2;t===225&&(o??=l(e,c,u)),[192,193,194,195,197,198,199,201,202,203,205,206,207].includes(t)&&u>=5&&(a=r(e,c+1),i=r(e,c+3)),n+=s}return t&&(!i||!a)?void 0:{format:`JPEG`,width:i,height:a,animated:!1,hasAlpha:!1,orientation:o}}function d(e,t){if(e.length<24||![137,80,78,71,13,10,26,10].every((t,n)=>e[n]===t))return;let r=8,a,o,s,c,l=!1;for(;r+12<=e.length;){let t=i(e,r),u=n(e,r+4,4),d=r+12+t;if(t>e.length||d>e.length)break;if(u===`IHDR`&&t===13)a=i(e,r+8),o=i(e,r+12),s=e[r+17]===4||e[r+17]===6;else if(u===`acTL`&&t===8)c=i(e,r+8);else if(u===`tRNS`)s=!0;else if(u===`IEND`){l=!0;break}r=d}if(!(!a||!o||t&&!l))return{format:c?`APNG`:`PNG`,width:a,height:o,animated:!!(c&&c>1),frameCount:c,hasAlpha:s}}function f(e,t){let n=t;for(;n<e.length;){let t=e[n++];if(t===0)return n;if(n+=t,n>e.length)return-1}return-1}function p(e,t){if(e.length<13||![`GIF87a`,`GIF89a`].includes(n(e,0,6)))return;let r=e[6]|e[7]<<8,i=e[8]|e[9]<<8,a=e[10],o=13+(a&128?3*2**((a&7)+1):0),s=0,c=!1,l=!1;for(;o<e.length;){let n=e[o++];if(n===59){c=!0;break}if(n===33)e[o++]===249&&e[o]===4&&(l||=!!(e[o+1]&1)),o=f(e,o);else if(n===44){if(s+=1,o+9>e.length)return t?void 0:{format:`GIF`,width:r,height:i,animated:s>1,frameCount:s,hasAlpha:l};let n=e[o+8];o+=9+(n&128?3*2**((n&7)+1):0),o+=1,o=f(e,o)}else return t?void 0:{format:`GIF`,width:r,height:i,animated:s>1,frameCount:s,hasAlpha:l};if(o<0)return t?void 0:{format:`GIF`,width:r,height:i,animated:s>1,frameCount:s,hasAlpha:l}}if(!(!s||t&&!c))return{format:`GIF`,width:r,height:i,animated:s>1,frameCount:s,hasAlpha:l}}function m(e,t,n){if(t===`VP8X`&&n+10<=e.length)return{width:a(e,n+4)+1,height:a(e,n+7)+1};if(t===`VP8L`&&n+5<=e.length&&e[n]===47){let t=s(e,n+1);return{width:(t&16383)+1,height:(t>>>14&16383)+1}}if(t===`VP8 `&&n+10<=e.length&&e[n+3]===157&&e[n+4]===1&&e[n+5]===42)return{width:(e[n+6]|e[n+7]<<8)&16383,height:(e[n+8]|e[n+9]<<8)&16383}}function h(e,t){if(e.length<20||n(e,0,4)!==`RIFF`||n(e,8,4)!==`WEBP`)return;let r=s(e,4)+8;if(t&&r>e.length)return;let i=12,a,o,c=!1,l=!1,u=0;for(;i+8<=e.length&&i<r;){let t=n(e,i,4),r=s(e,i+4),d=i+8,f=d+r+r%2;if(f>e.length)break;let p=m(e,t,d);a??=p?.width,o??=p?.height,t===`VP8X`&&(c||=!!(e[d]&16),l||=!!(e[d]&2)),t===`VP8L`&&r>=5&&(c||=!!(s(e,d+1)&268435456)),t===`ALPH`&&(c=!0),t===`ANMF`&&(u+=1),i=f}if(!(!a||!o||t&&i<r))return{format:`WebP`,width:a,height:o,animated:l,frameCount:u||void 0,hasAlpha:c}}function g(e){let t=0,r=!1;for(;t+8<=e.length;){let a=i(e,t),o=n(e,t+4,4),s=a===1?16:8;if(t+s>e.length)return!1;let l=a===0?e.length-t:a===1?c(e,t+8):a;if(l===void 0||l<s||t+l>e.length)return!1;r||=o===`meta`,t+=l}return t===e.length&&r}function _(e,r){if(e.length<16||n(e,4,4)!==`ftyp`)return;let a=i(e,0);if(a<16||a>e.length)return;let o=[n(e,8,4)];for(let t=16;t+4<=a;t+=4)o.push(n(e,t,4));if(!(!o.includes(`avif`)&&!o.includes(`avis`))&&!(r&&!g(e)))return{format:`AVIF`,animated:o.includes(`avis`),...t(e)}}function v(e,t){if(e.length<26||n(e,0,2)!==`BM`)return;let r=s(e,2),i=s(e,10),a=s(e,14);if(r<26||i<14+a||i>r||t&&r>e.length)return;let c,l,u=!1;if(a===12)c=o(e,18),l=o(e,20);else if(a>=40&&e.length>=54){let t=new DataView(e.buffer,e.byteOffset,e.byteLength);c=Math.abs(t.getInt32(18,!0)),l=Math.abs(t.getInt32(22,!0)),u=t.getUint16(28,!0)===32}else return;if(!(!c||!l))return{format:`BMP`,width:c,height:l,animated:!1,hasAlpha:u}}function y(e,t){if(e.length<22||o(e,0)!==0)return;let n=o(e,2),r=o(e,4);if(n!==1&&n!==2||r===0||e.length<6+r*16)return;let i=0,a=0;for(let n=0;n<r;n+=1){let o=6+n*16,c=e[o]||256,l=e[o+1]||256,u=s(e,o+8),d=s(e,o+12);if(!u||d<6+r*16||t&&d+u>e.length)return;c*l>i*a&&(i=c,a=l)}return{format:n===1?`ICO`:`CUR`,width:i,height:a,animated:!1,hasAlpha:!0}}function b(e,t=!1){return u(e,t)??d(e,t)??p(e,t)??h(e,t)??_(e,t)??v(e,t)??y(e,t)}async function x(t,n,r){if(r.aborted||(await new Promise((i,a)=>{let o=!1,s=e=>{o||(o=!0,r.removeEventListener(`abort`,c),t.onload=null,t.onerror=null,e?a(e):i())},c=()=>{t.removeAttribute(`src`),s(e())};t.onload=()=>s(),t.onerror=()=>s(Error(`Image decoding failed.`)),r.addEventListener(`abort`,c,{once:!0}),t.src=n,typeof t.decode==`function`&&t.decode().then(()=>s(),e=>s(e))}),r.aborted))throw e()}export{b as n,x as t};