chunk-DO7VQYJK.js 1.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667
  1. import {
  2. X,
  3. nt
  4. } from "./chunk-VBRY5KJM.js";
  5. import {
  6. s3 as s
  7. } from "./chunk-EMJ4ZSM2.js";
  8. import {
  9. r,
  10. t
  11. } from "./chunk-GZT4BVFP.js";
  12. // node_modules/@arcgis/core/geometry/support/meshUtils/exporters/gltf/imageutils.js
  13. function i(e) {
  14. const n = m(e);
  15. return r(n) ? n.toDataURL() : "";
  16. }
  17. async function o(t2) {
  18. const r2 = m(t2);
  19. if (t(r2))
  20. throw new s("imageToArrayBuffer", "Unsupported image type");
  21. const a = await c(t2), i2 = await new Promise((e) => r2.toBlob(e, a));
  22. if (!i2)
  23. throw new s("imageToArrayBuffer", "Failed to encode image");
  24. return { data: await i2.arrayBuffer(), type: a };
  25. }
  26. async function c(e) {
  27. if (!(e instanceof HTMLImageElement))
  28. return "image/png";
  29. const t2 = e.src;
  30. if (X(t2)) {
  31. const { mediaType: e2 } = nt(t2);
  32. return e2 === "image/jpeg" ? e2 : "image/png";
  33. }
  34. return /\.png$/i.test(t2) ? "image/png" : /\.(jpg|jpeg)$/i.test(t2) ? "image/jpeg" : "image/png";
  35. }
  36. function m(e) {
  37. if (e instanceof HTMLCanvasElement)
  38. return e;
  39. if (e instanceof HTMLVideoElement)
  40. return null;
  41. const t2 = document.createElement("canvas");
  42. t2.width = e.width, t2.height = e.height;
  43. const n = t2.getContext("2d");
  44. return e instanceof HTMLImageElement ? n.drawImage(e, 0, 0, e.width, e.height) : e instanceof ImageData && n.putImageData(e, 0, 0), t2;
  45. }
  46. function s2(e) {
  47. const t2 = [], n = new Uint8Array(e);
  48. for (let r2 = 0; r2 < n.length; r2++)
  49. t2.push(String.fromCharCode(n[r2]));
  50. return "data:application/octet-stream;base64," + btoa(t2.join(""));
  51. }
  52. function g(e) {
  53. if (e.byteLength < 8)
  54. return false;
  55. const t2 = new Uint8Array(e);
  56. return t2[0] === 137 && t2[1] === 80 && t2[2] === 78 && t2[3] === 71 && t2[4] === 13 && t2[5] === 10 && t2[6] === 26 && t2[7] === 10;
  57. }
  58. export {
  59. i,
  60. o,
  61. m,
  62. s2 as s,
  63. g
  64. };
  65. //# sourceMappingURL=chunk-DO7VQYJK.js.map