@forgeax/engine-image 0.1.2

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 (122) hide show
  1. package/LICENSE +202 -0
  2. package/README.md +168 -0
  3. package/dist/.tsbuildinfo +1 -0
  4. package/dist/__tests__/compression-mode.unit.test.d.ts +2 -0
  5. package/dist/__tests__/compression-mode.unit.test.d.ts.map +1 -0
  6. package/dist/__tests__/encode-source-too-large.unit.test.d.ts +2 -0
  7. package/dist/__tests__/encode-source-too-large.unit.test.d.ts.map +1 -0
  8. package/dist/__tests__/errors.test-d.d.ts +2 -0
  9. package/dist/__tests__/errors.test-d.d.ts.map +1 -0
  10. package/dist/__tests__/image-importer-conversion-failure.unit.test.d.ts +2 -0
  11. package/dist/__tests__/image-importer-conversion-failure.unit.test.d.ts.map +1 -0
  12. package/dist/__tests__/image-importer-hdr-equirect.test.d.ts +2 -0
  13. package/dist/__tests__/image-importer-hdr-equirect.test.d.ts.map +1 -0
  14. package/dist/__tests__/image-importer-topology.unit.test.d.ts +2 -0
  15. package/dist/__tests__/image-importer-topology.unit.test.d.ts.map +1 -0
  16. package/dist/__tests__/image-importer.test.d.ts +2 -0
  17. package/dist/__tests__/image-importer.test.d.ts.map +1 -0
  18. package/dist/__tests__/image-local-artifacts.test.d.ts +2 -0
  19. package/dist/__tests__/image-local-artifacts.test.d.ts.map +1 -0
  20. package/dist/__tests__/image.unit.test.d.ts +2 -0
  21. package/dist/__tests__/image.unit.test.d.ts.map +1 -0
  22. package/dist/__tests__/ktx2-basis-importer.unit.test.d.ts +2 -0
  23. package/dist/__tests__/ktx2-basis-importer.unit.test.d.ts.map +1 -0
  24. package/dist/__tests__/ktx2-encode-mode-owner.test-d.d.ts +2 -0
  25. package/dist/__tests__/ktx2-encode-mode-owner.test-d.d.ts.map +1 -0
  26. package/dist/__tests__/make-fixture.d.ts +12 -0
  27. package/dist/__tests__/make-fixture.d.ts.map +1 -0
  28. package/dist/__tests__/parse-image-downscale.test.d.ts +2 -0
  29. package/dist/__tests__/parse-image-downscale.test.d.ts.map +1 -0
  30. package/dist/__tests__/runtime-decode.unit.test.d.ts +2 -0
  31. package/dist/__tests__/runtime-decode.unit.test.d.ts.map +1 -0
  32. package/dist/__tests__/source-key.unit.test.d.ts +2 -0
  33. package/dist/__tests__/source-key.unit.test.d.ts.map +1 -0
  34. package/dist/__tests__/tga.unit.test.d.ts +2 -0
  35. package/dist/__tests__/tga.unit.test.d.ts.map +1 -0
  36. package/dist/decode-image-from-file.d.ts +40 -0
  37. package/dist/decode-image-from-file.d.ts.map +1 -0
  38. package/dist/decode-image-from-file.mjs +590 -0
  39. package/dist/decode-image-from-file.mjs.map +1 -0
  40. package/dist/errors.d.ts +14 -0
  41. package/dist/errors.d.ts.map +1 -0
  42. package/dist/hdr-decoder.d.ts +28 -0
  43. package/dist/hdr-decoder.d.ts.map +1 -0
  44. package/dist/hdr-decoder.mjs +212 -0
  45. package/dist/hdr-decoder.mjs.map +1 -0
  46. package/dist/image-decoder-browser.d.ts +22 -0
  47. package/dist/image-decoder-browser.d.ts.map +1 -0
  48. package/dist/image-decoder-node.d.ts +50 -0
  49. package/dist/image-decoder-node.d.ts.map +1 -0
  50. package/dist/image-importer.d.ts +15 -0
  51. package/dist/image-importer.d.ts.map +1 -0
  52. package/dist/image-importer.mjs +1107 -0
  53. package/dist/image-importer.mjs.map +1 -0
  54. package/dist/index.d.ts +19 -0
  55. package/dist/index.d.ts.map +1 -0
  56. package/dist/index.mjs +503 -0
  57. package/dist/index.mjs.map +1 -0
  58. package/dist/ktx2-encode.d.ts +84 -0
  59. package/dist/ktx2-encode.d.ts.map +1 -0
  60. package/dist/ktx2-encode.mjs +100 -0
  61. package/dist/ktx2-encode.mjs.map +1 -0
  62. package/dist/parse-image.d.ts +48 -0
  63. package/dist/parse-image.d.ts.map +1 -0
  64. package/dist/parse-image.mjs +231 -0
  65. package/dist/parse-image.mjs.map +1 -0
  66. package/dist/reimport-reuse-meta.d.ts +81 -0
  67. package/dist/reimport-reuse-meta.d.ts.map +1 -0
  68. package/dist/resize-image.d.ts +7 -0
  69. package/dist/resize-image.d.ts.map +1 -0
  70. package/dist/result.d.ts +2 -0
  71. package/dist/result.d.ts.map +1 -0
  72. package/dist/runtime/__tests__/asset-decoders.unit.test.d.ts +2 -0
  73. package/dist/runtime/__tests__/asset-decoders.unit.test.d.ts.map +1 -0
  74. package/dist/runtime/asset-decoders.d.ts +4 -0
  75. package/dist/runtime/asset-decoders.d.ts.map +1 -0
  76. package/dist/runtime/decode-image-bytes.d.ts +7 -0
  77. package/dist/runtime/decode-image-bytes.d.ts.map +1 -0
  78. package/dist/runtime/image-error.d.ts +3 -0
  79. package/dist/runtime/image-error.d.ts.map +1 -0
  80. package/dist/source-key.d.ts +21 -0
  81. package/dist/source-key.d.ts.map +1 -0
  82. package/dist/sub-asset-key.d.ts +50 -0
  83. package/dist/sub-asset-key.d.ts.map +1 -0
  84. package/dist/to-asset-pack.d.ts +61 -0
  85. package/dist/to-asset-pack.d.ts.map +1 -0
  86. package/package.json +105 -0
  87. package/src/__tests__/compression-mode.unit.test.ts +104 -0
  88. package/src/__tests__/encode-source-too-large.unit.test.ts +81 -0
  89. package/src/__tests__/errors.test-d.ts +148 -0
  90. package/src/__tests__/image-importer-conversion-failure.unit.test.ts +297 -0
  91. package/src/__tests__/image-importer-hdr-equirect.test.ts +218 -0
  92. package/src/__tests__/image-importer-topology.unit.test.ts +209 -0
  93. package/src/__tests__/image-importer.test.ts +12 -0
  94. package/src/__tests__/image-local-artifacts.test.ts +38 -0
  95. package/src/__tests__/image.unit.test.ts +1387 -0
  96. package/src/__tests__/ktx2-basis-importer.unit.test.ts +126 -0
  97. package/src/__tests__/ktx2-encode-mode-owner.test-d.ts +70 -0
  98. package/src/__tests__/make-fixture.ts +100 -0
  99. package/src/__tests__/parse-image-downscale.test.ts +26 -0
  100. package/src/__tests__/runtime-decode.unit.test.ts +22 -0
  101. package/src/__tests__/source-key.unit.test.ts +65 -0
  102. package/src/__tests__/tga.unit.test.ts +59 -0
  103. package/src/decode-image-from-file.ts +298 -0
  104. package/src/errors.ts +60 -0
  105. package/src/hdr-decoder.ts +255 -0
  106. package/src/image-decoder-browser.ts +88 -0
  107. package/src/image-decoder-node.ts +67 -0
  108. package/src/image-decoders.d.ts +23 -0
  109. package/src/image-importer.ts +780 -0
  110. package/src/index.ts +46 -0
  111. package/src/ktx2-encode.ts +221 -0
  112. package/src/parse-image.ts +276 -0
  113. package/src/reimport-reuse-meta.ts +160 -0
  114. package/src/resize-image.ts +39 -0
  115. package/src/result.ts +13 -0
  116. package/src/runtime/__tests__/asset-decoders.unit.test.ts +66 -0
  117. package/src/runtime/asset-decoders.ts +152 -0
  118. package/src/runtime/decode-image-bytes.ts +41 -0
  119. package/src/runtime/image-error.ts +8 -0
  120. package/src/source-key.ts +41 -0
  121. package/src/sub-asset-key.ts +67 -0
  122. package/src/to-asset-pack.ts +95 -0
@@ -0,0 +1,67 @@
1
+ // Node-only image decoder shell for @forgeax/engine-image.
2
+ //
3
+ // Lazy-loads `upng-js` (PNG) and `jpeg-js` (JPEG) via dynamic imports so the
4
+ // browser bundle tree-shakes both decoders out of the ESM output (the
5
+ // browser path uses createImageBitmap instead). Migrated from the original
6
+ // packages/runtime/src/ home in feat-20260515-learn-render-getting-started
7
+ // M2 T-M2-02 (Open Q-3 option a; plan-strategy section 2.4) -- runtime now
8
+ // only consumes DecodedImage POD and never imports the decoders.
9
+ //
10
+ // The implementation surface is filled out by T-M2-05; this file is staged
11
+ // here in T-M2-02 so the migration touches a single owner directory and the
12
+ // runtime package never ships a half-migrated state.
13
+
14
+ /**
15
+ * Local widening of the upng-js dynamic-import surface (the package ships
16
+ * without a usable @types entry; the d.ts in image-decoders.d.ts only adds
17
+ * the module declaration). Lists the two functions consumed by the Node
18
+ * decoder path; widening here keeps the import site free of `as any` casts
19
+ * (charter P3 explicit failure -- structural typing > escape hatches).
20
+ */
21
+ export interface UpngModule {
22
+ decode: (bytes: Uint8Array | ArrayBuffer) => {
23
+ width: number;
24
+ height: number;
25
+ depth: number;
26
+ ctype: number;
27
+ data: Uint8Array;
28
+ frames?: unknown[];
29
+ };
30
+ toRGBA8: (img: { width: number; height: number; data: Uint8Array }) => ArrayBuffer[];
31
+ }
32
+
33
+ /**
34
+ * Local widening of the jpeg-js dynamic-import surface. Mirrors the subset
35
+ * used by the Node decoder; jpeg-js has @types/jpeg-js but we keep a local
36
+ * shape so the d.ts ambient declaration stays the SSOT for runtime resolution
37
+ * (charter P5 producer / consumer split).
38
+ */
39
+ export interface JpegModule {
40
+ decode: (
41
+ bytes: Uint8Array | ArrayBuffer,
42
+ opts?: { useTArray?: boolean; formatAsRGBA?: boolean },
43
+ ) => {
44
+ width: number;
45
+ height: number;
46
+ data: Uint8Array;
47
+ };
48
+ }
49
+
50
+ /**
51
+ * Lazy-load the upng-js Node decoder module. Browser bundlers tree-shake
52
+ * this dynamic import out when only the createImageBitmap path is reached
53
+ * at runtime; tsup external keeps the package name from being inlined.
54
+ */
55
+ export async function loadUpng(): Promise<UpngModule> {
56
+ const mod = (await import('upng-js')) as { default?: UpngModule } & UpngModule;
57
+ return (mod.default ?? mod) as UpngModule;
58
+ }
59
+
60
+ /**
61
+ * Lazy-load the jpeg-js Node decoder module. Same tree-shake guarantee as
62
+ * loadUpng -- browser bundles never reach this path.
63
+ */
64
+ export async function loadJpeg(): Promise<JpegModule> {
65
+ const mod = (await import('jpeg-js')) as { default?: JpegModule } & JpegModule;
66
+ return (mod.default ?? mod) as JpegModule;
67
+ }
@@ -0,0 +1,23 @@
1
+ // Ambient module declarations for the upng-js (PNG decoder) + jpeg-js (JPEG
2
+ // decoder) dependencies. Both packages ship without shipped .d.ts files
3
+ // (upng-js has no @types; jpeg-js has @types/jpeg-js but we cast through
4
+ // local interfaces to match the subset the Node path uses).
5
+ //
6
+ // The import sites live in src/image-decoder-node.ts (T-M2-05) and are
7
+ // lazy dynamic imports (`await import('upng-js')`) so browser bundles
8
+ // tree-shake them out; tsc needs the module name to resolve nonetheless.
9
+ //
10
+ // For each module we declare only the surface consumed by the Node decoder;
11
+ // widening is handled in consumer site via explicit interface casts.
12
+ //
13
+ // Anchors:
14
+ // - Open Q-3 option a (plan-strategy section 2.4): runtime decoupled from
15
+ // decode APIs; the d.ts + lazy decoder code + upng / jpeg deps were
16
+ // migrated from packages/runtime/src/ to packages/image/src/ in
17
+ // feat-20260515-learn-render-getting-started M2 T-M2-02.
18
+ // - AC-15 grep gate: packages/runtime/src/ contains zero hits of
19
+ // `image-decode` / `decodeImage` after this migration; CI fail-fast
20
+ // enforces the disk-to-memory pipeline isolation (charter P5).
21
+
22
+ declare module 'upng-js';
23
+ declare module 'jpeg-js';