astro 4.3.7 → 4.4.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 (172) hide show
  1. package/components/Image.astro +4 -0
  2. package/components/Picture.astro +4 -0
  3. package/dist/@types/astro.d.ts +42 -42
  4. package/dist/assets/build/generate.d.ts +1 -1
  5. package/dist/assets/build/generate.js +1 -2
  6. package/dist/assets/internal.js +14 -0
  7. package/dist/assets/types.d.ts +23 -2
  8. package/dist/assets/utils/metadata.js +3 -3
  9. package/dist/assets/utils/remoteProbe.d.ts +2 -0
  10. package/dist/assets/utils/remoteProbe.js +35 -0
  11. package/dist/assets/utils/vendor/image-size/detector.d.ts +2 -0
  12. package/dist/assets/utils/vendor/image-size/detector.js +24 -0
  13. package/dist/assets/utils/vendor/image-size/lookup.d.ts +10 -0
  14. package/dist/assets/utils/vendor/image-size/lookup.js +26 -0
  15. package/dist/assets/utils/vendor/image-size/types/bmp.d.ts +2 -0
  16. package/dist/assets/utils/vendor/image-size/types/bmp.js +11 -0
  17. package/dist/assets/utils/vendor/image-size/types/cur.d.ts +2 -0
  18. package/dist/assets/utils/vendor/image-size/types/cur.js +17 -0
  19. package/dist/assets/utils/vendor/image-size/types/dds.d.ts +2 -0
  20. package/dist/assets/utils/vendor/image-size/types/dds.js +11 -0
  21. package/dist/assets/utils/vendor/image-size/types/gif.d.ts +2 -0
  22. package/dist/assets/utils/vendor/image-size/types/gif.js +12 -0
  23. package/dist/assets/utils/vendor/image-size/types/heif.d.ts +2 -0
  24. package/dist/assets/utils/vendor/image-size/types/heif.js +53 -0
  25. package/dist/assets/utils/vendor/image-size/types/icns.d.ts +2 -0
  26. package/dist/assets/utils/vendor/image-size/types/icns.js +85 -0
  27. package/dist/assets/utils/vendor/image-size/types/ico.d.ts +2 -0
  28. package/dist/assets/utils/vendor/image-size/types/ico.js +43 -0
  29. package/dist/assets/utils/vendor/image-size/types/index.d.ts +3 -0
  30. package/dist/assets/utils/vendor/image-size/types/index.js +43 -0
  31. package/dist/assets/utils/vendor/image-size/types/interface.d.ts +13 -0
  32. package/dist/assets/utils/vendor/image-size/types/interface.js +0 -0
  33. package/dist/assets/utils/vendor/image-size/types/j2c.d.ts +2 -0
  34. package/dist/assets/utils/vendor/image-size/types/j2c.js +12 -0
  35. package/dist/assets/utils/vendor/image-size/types/jp2.d.ts +2 -0
  36. package/dist/assets/utils/vendor/image-size/types/jp2.js +25 -0
  37. package/dist/assets/utils/vendor/image-size/types/jpg.d.ts +2 -0
  38. package/dist/assets/utils/vendor/image-size/types/jpg.js +97 -0
  39. package/dist/assets/utils/vendor/image-size/types/ktx.d.ts +2 -0
  40. package/dist/assets/utils/vendor/image-size/types/ktx.js +19 -0
  41. package/dist/assets/utils/vendor/image-size/types/png.d.ts +2 -0
  42. package/dist/assets/utils/vendor/image-size/types/png.js +34 -0
  43. package/dist/assets/utils/vendor/image-size/types/pnm.d.ts +2 -0
  44. package/dist/assets/utils/vendor/image-size/types/pnm.js +69 -0
  45. package/dist/assets/utils/vendor/image-size/types/psd.d.ts +2 -0
  46. package/dist/assets/utils/vendor/image-size/types/psd.js +11 -0
  47. package/dist/assets/utils/vendor/image-size/types/svg.d.ts +2 -0
  48. package/dist/assets/utils/vendor/image-size/types/svg.js +94 -0
  49. package/dist/assets/utils/vendor/image-size/types/tga.d.ts +2 -0
  50. package/dist/assets/utils/vendor/image-size/types/tga.js +15 -0
  51. package/dist/assets/utils/vendor/image-size/types/tiff.d.ts +2 -0
  52. package/dist/assets/utils/vendor/image-size/types/tiff.js +66 -0
  53. package/dist/assets/utils/vendor/image-size/types/utils.d.ts +15 -0
  54. package/dist/assets/utils/vendor/image-size/types/utils.js +60 -0
  55. package/dist/assets/utils/vendor/image-size/types/webp.d.ts +2 -0
  56. package/dist/assets/utils/vendor/image-size/types/webp.js +52 -0
  57. package/dist/cli/add/babel.d.ts +1 -1
  58. package/dist/cli/add/index.js +10 -3
  59. package/dist/cli/db/index.js +2 -0
  60. package/dist/cli/info/index.js +2 -0
  61. package/dist/cli/preferences/index.js +2 -0
  62. package/dist/content/runtime.js +3 -1
  63. package/dist/content/types-generator.js +7 -27
  64. package/dist/core/app/index.js +39 -122
  65. package/dist/core/app/pipeline.d.ts +7 -0
  66. package/dist/core/app/pipeline.js +39 -0
  67. package/dist/core/base-pipeline.d.ts +59 -0
  68. package/dist/core/base-pipeline.js +27 -0
  69. package/dist/core/build/generate.d.ts +1 -1
  70. package/dist/core/build/generate.js +39 -109
  71. package/dist/core/build/index.js +0 -4
  72. package/dist/core/build/{buildPipeline.d.ts → pipeline.d.ts} +13 -13
  73. package/dist/core/build/pipeline.js +180 -0
  74. package/dist/core/build/plugins/plugin-css.js +6 -5
  75. package/dist/core/build/plugins/plugin-hoisted-scripts.js +6 -5
  76. package/dist/core/build/plugins/util.d.ts +2 -1
  77. package/dist/core/build/plugins/util.js +12 -1
  78. package/dist/core/build/types.d.ts +0 -2
  79. package/dist/core/constants.d.ts +10 -1
  80. package/dist/core/constants.js +14 -4
  81. package/dist/core/dev/dev.js +1 -1
  82. package/dist/core/dev/restart.js +1 -1
  83. package/dist/core/endpoint/index.d.ts +5 -4
  84. package/dist/core/endpoint/index.js +7 -34
  85. package/dist/core/errors/errors-data.d.ts +16 -3
  86. package/dist/core/errors/errors-data.js +9 -2
  87. package/dist/core/messages.js +2 -2
  88. package/dist/core/middleware/callMiddleware.d.ts +1 -1
  89. package/dist/core/middleware/callMiddleware.js +2 -9
  90. package/dist/core/middleware/index.d.ts +2 -2
  91. package/dist/core/middleware/index.js +74 -9
  92. package/dist/core/module-loader/vite.js +4 -4
  93. package/dist/core/preview/index.js +2 -0
  94. package/dist/core/preview/static-preview-server.js +1 -7
  95. package/dist/core/redirects/helpers.d.ts +1 -3
  96. package/dist/core/redirects/helpers.js +0 -29
  97. package/dist/core/redirects/index.d.ts +2 -1
  98. package/dist/core/redirects/index.js +3 -3
  99. package/dist/core/redirects/render.d.ts +2 -0
  100. package/dist/core/redirects/render.js +33 -0
  101. package/dist/core/render/index.d.ts +7 -13
  102. package/dist/core/render/index.js +7 -7
  103. package/dist/core/render/params-and-props.d.ts +8 -3
  104. package/dist/core/render/params-and-props.js +24 -16
  105. package/dist/core/render/result.d.ts +6 -5
  106. package/dist/core/render/result.js +3 -4
  107. package/dist/core/render-context.d.ts +32 -0
  108. package/dist/core/render-context.js +219 -0
  109. package/dist/core/routing/index.d.ts +0 -1
  110. package/dist/core/routing/index.js +0 -2
  111. package/dist/core/routing/manifest/create.js +11 -27
  112. package/dist/core/routing/params.d.ts +1 -7
  113. package/dist/core/routing/params.js +0 -15
  114. package/dist/core/sync/index.js +3 -3
  115. package/dist/i18n/middleware.d.ts +0 -5
  116. package/dist/i18n/middleware.js +61 -69
  117. package/dist/i18n/utils.d.ts +25 -0
  118. package/dist/{core/render/context.js → i18n/utils.js} +3 -49
  119. package/dist/prerender/routing.d.ts +1 -1
  120. package/dist/prerender/routing.js +20 -21
  121. package/dist/runtime/client/dev-toolbar/apps/astro.js +14 -10
  122. package/dist/runtime/client/dev-toolbar/apps/audit/a11y.js +2 -2
  123. package/dist/runtime/client/dev-toolbar/apps/audit/index.d.ts +1 -1
  124. package/dist/runtime/client/dev-toolbar/apps/audit/index.js +115 -6
  125. package/dist/runtime/client/dev-toolbar/apps/audit/perf.d.ts +2 -0
  126. package/dist/runtime/client/dev-toolbar/apps/audit/perf.js +110 -0
  127. package/dist/runtime/client/dev-toolbar/apps/utils/highlight.d.ts +1 -1
  128. package/dist/runtime/client/dev-toolbar/apps/utils/highlight.js +6 -1
  129. package/dist/runtime/client/dev-toolbar/ui-library/card.js +1 -1
  130. package/dist/runtime/server/astro-island.js +10 -1
  131. package/dist/runtime/server/astro-island.prebuilt-dev.d.ts +7 -0
  132. package/dist/runtime/server/astro-island.prebuilt-dev.js +4 -0
  133. package/dist/runtime/server/astro-island.prebuilt.d.ts +1 -1
  134. package/dist/runtime/server/astro-island.prebuilt.js +1 -1
  135. package/dist/runtime/server/endpoint.js +2 -2
  136. package/dist/runtime/server/render/astro/render.d.ts +1 -0
  137. package/dist/runtime/server/render/astro/render.js +81 -2
  138. package/dist/runtime/server/render/component.js +6 -0
  139. package/dist/runtime/server/render/page.js +15 -2
  140. package/dist/runtime/server/render/util.d.ts +7 -0
  141. package/dist/runtime/server/render/util.js +15 -0
  142. package/dist/runtime/server/scripts.js +2 -4
  143. package/dist/runtime/server/transition.js +14 -1
  144. package/dist/vite-plugin-astro/hmr.d.ts +1 -0
  145. package/dist/vite-plugin-astro/hmr.js +7 -4
  146. package/dist/vite-plugin-astro-server/error.d.ts +2 -2
  147. package/dist/vite-plugin-astro-server/error.js +2 -5
  148. package/dist/vite-plugin-astro-server/index.d.ts +0 -6
  149. package/dist/vite-plugin-astro-server/index.js +0 -19
  150. package/dist/vite-plugin-astro-server/pipeline.d.ts +19 -0
  151. package/dist/vite-plugin-astro-server/pipeline.js +117 -0
  152. package/dist/vite-plugin-astro-server/plugin.js +3 -4
  153. package/dist/vite-plugin-astro-server/request.d.ts +3 -4
  154. package/dist/vite-plugin-astro-server/request.js +6 -9
  155. package/dist/vite-plugin-astro-server/route.d.ts +3 -4
  156. package/dist/vite-plugin-astro-server/route.js +34 -162
  157. package/dist/vite-plugin-dev-toolbar/vite-plugin-dev-toolbar.js +3 -3
  158. package/package.json +7 -12
  159. package/dist/core/app/ssrPipeline.d.ts +0 -3
  160. package/dist/core/app/ssrPipeline.js +0 -6
  161. package/dist/core/build/buildPipeline.js +0 -150
  162. package/dist/core/pipeline.d.ts +0 -39
  163. package/dist/core/pipeline.js +0 -107
  164. package/dist/core/render/context.d.ts +0 -52
  165. package/dist/core/render/core.d.ts +0 -10
  166. package/dist/core/render/core.js +0 -65
  167. package/dist/core/render/environment.d.ts +0 -34
  168. package/dist/core/render/environment.js +0 -6
  169. package/dist/runtime/server/consts.d.ts +0 -1
  170. package/dist/runtime/server/consts.js +0 -4
  171. package/dist/vite-plugin-astro-server/devPipeline.d.ts +0 -22
  172. package/dist/vite-plugin-astro-server/devPipeline.js +0 -65
@@ -0,0 +1,13 @@
1
+ export type ISize = {
2
+ width: number | undefined;
3
+ height: number | undefined;
4
+ orientation?: number;
5
+ type?: string;
6
+ };
7
+ export type ISizeCalculationResult = {
8
+ images?: ISize[];
9
+ } & ISize;
10
+ export type IImage = {
11
+ validate: (input: Uint8Array) => boolean;
12
+ calculate: (input: Uint8Array) => ISizeCalculationResult;
13
+ };
@@ -0,0 +1,2 @@
1
+ import type { IImage } from './interface.ts';
2
+ export declare const J2C: IImage;
@@ -0,0 +1,12 @@
1
+ import { toHexString, readUInt32BE } from "./utils.js";
2
+ const J2C = {
3
+ // TODO: this doesn't seem right. SIZ marker doesn't have to be right after the SOC
4
+ validate: (input) => toHexString(input, 0, 4) === "ff4fff51",
5
+ calculate: (input) => ({
6
+ height: readUInt32BE(input, 12),
7
+ width: readUInt32BE(input, 8)
8
+ })
9
+ };
10
+ export {
11
+ J2C
12
+ };
@@ -0,0 +1,2 @@
1
+ import type { IImage } from './interface.ts';
2
+ export declare const JP2: IImage;
@@ -0,0 +1,25 @@
1
+ import { readUInt32BE, findBox } from "./utils.js";
2
+ const JP2 = {
3
+ validate(input) {
4
+ if (readUInt32BE(input, 4) !== 1783636e3 || readUInt32BE(input, 0) < 1)
5
+ return false;
6
+ const ftypBox = findBox(input, "ftyp", 0);
7
+ if (!ftypBox)
8
+ return false;
9
+ return readUInt32BE(input, ftypBox.offset + 4) === 1718909296;
10
+ },
11
+ calculate(input) {
12
+ const jp2hBox = findBox(input, "jp2h", 0);
13
+ const ihdrBox = jp2hBox && findBox(input, "ihdr", jp2hBox.offset + 8);
14
+ if (ihdrBox) {
15
+ return {
16
+ height: readUInt32BE(input, ihdrBox.offset + 8),
17
+ width: readUInt32BE(input, ihdrBox.offset + 12)
18
+ };
19
+ }
20
+ throw new TypeError("Unsupported JPEG 2000 format");
21
+ }
22
+ };
23
+ export {
24
+ JP2
25
+ };
@@ -0,0 +1,2 @@
1
+ import type { IImage } from './interface.ts';
2
+ export declare const JPG: IImage;
@@ -0,0 +1,97 @@
1
+ import { readUInt, readUInt16BE, toHexString } from "./utils.js";
2
+ const EXIF_MARKER = "45786966";
3
+ const APP1_DATA_SIZE_BYTES = 2;
4
+ const EXIF_HEADER_BYTES = 6;
5
+ const TIFF_BYTE_ALIGN_BYTES = 2;
6
+ const BIG_ENDIAN_BYTE_ALIGN = "4d4d";
7
+ const LITTLE_ENDIAN_BYTE_ALIGN = "4949";
8
+ const IDF_ENTRY_BYTES = 12;
9
+ const NUM_DIRECTORY_ENTRIES_BYTES = 2;
10
+ function isEXIF(input) {
11
+ return toHexString(input, 2, 6) === EXIF_MARKER;
12
+ }
13
+ function extractSize(input, index) {
14
+ return {
15
+ height: readUInt16BE(input, index),
16
+ width: readUInt16BE(input, index + 2)
17
+ };
18
+ }
19
+ function extractOrientation(exifBlock, isBigEndian) {
20
+ const idfOffset = 8;
21
+ const offset = EXIF_HEADER_BYTES + idfOffset;
22
+ const idfDirectoryEntries = readUInt(exifBlock, 16, offset, isBigEndian);
23
+ for (let directoryEntryNumber = 0; directoryEntryNumber < idfDirectoryEntries; directoryEntryNumber++) {
24
+ const start = offset + NUM_DIRECTORY_ENTRIES_BYTES + directoryEntryNumber * IDF_ENTRY_BYTES;
25
+ const end = start + IDF_ENTRY_BYTES;
26
+ if (start > exifBlock.length) {
27
+ return;
28
+ }
29
+ const block = exifBlock.slice(start, end);
30
+ const tagNumber = readUInt(block, 16, 0, isBigEndian);
31
+ if (tagNumber === 274) {
32
+ const dataFormat = readUInt(block, 16, 2, isBigEndian);
33
+ if (dataFormat !== 3) {
34
+ return;
35
+ }
36
+ const numberOfComponents = readUInt(block, 32, 4, isBigEndian);
37
+ if (numberOfComponents !== 1) {
38
+ return;
39
+ }
40
+ return readUInt(block, 16, 8, isBigEndian);
41
+ }
42
+ }
43
+ }
44
+ function validateExifBlock(input, index) {
45
+ const exifBlock = input.slice(APP1_DATA_SIZE_BYTES, index);
46
+ const byteAlign = toHexString(
47
+ exifBlock,
48
+ EXIF_HEADER_BYTES,
49
+ EXIF_HEADER_BYTES + TIFF_BYTE_ALIGN_BYTES
50
+ );
51
+ const isBigEndian = byteAlign === BIG_ENDIAN_BYTE_ALIGN;
52
+ const isLittleEndian = byteAlign === LITTLE_ENDIAN_BYTE_ALIGN;
53
+ if (isBigEndian || isLittleEndian) {
54
+ return extractOrientation(exifBlock, isBigEndian);
55
+ }
56
+ }
57
+ function validateInput(input, index) {
58
+ if (index > input.length) {
59
+ throw new TypeError("Corrupt JPG, exceeded buffer limits");
60
+ }
61
+ }
62
+ const JPG = {
63
+ validate: (input) => toHexString(input, 0, 2) === "ffd8",
64
+ calculate(input) {
65
+ input = input.slice(4);
66
+ let orientation;
67
+ let next;
68
+ while (input.length) {
69
+ const i = readUInt16BE(input, 0);
70
+ if (input[i] !== 255) {
71
+ input = input.slice(1);
72
+ continue;
73
+ }
74
+ if (isEXIF(input)) {
75
+ orientation = validateExifBlock(input, i);
76
+ }
77
+ validateInput(input, i);
78
+ next = input[i + 1];
79
+ if (next === 192 || next === 193 || next === 194) {
80
+ const size = extractSize(input, i + 5);
81
+ if (!orientation) {
82
+ return size;
83
+ }
84
+ return {
85
+ height: size.height,
86
+ orientation,
87
+ width: size.width
88
+ };
89
+ }
90
+ input = input.slice(i + 2);
91
+ }
92
+ throw new TypeError("Invalid JPG, no size found");
93
+ }
94
+ };
95
+ export {
96
+ JPG
97
+ };
@@ -0,0 +1,2 @@
1
+ import type { IImage } from './interface.ts';
2
+ export declare const KTX: IImage;
@@ -0,0 +1,19 @@
1
+ import { toUTF8String, readUInt32LE } from "./utils.js";
2
+ const KTX = {
3
+ validate: (input) => {
4
+ const signature = toUTF8String(input, 1, 7);
5
+ return ["KTX 11", "KTX 20"].includes(signature);
6
+ },
7
+ calculate: (input) => {
8
+ const type = input[5] === 49 ? "ktx" : "ktx2";
9
+ const offset = type === "ktx" ? 36 : 20;
10
+ return {
11
+ height: readUInt32LE(input, offset + 4),
12
+ width: readUInt32LE(input, offset),
13
+ type
14
+ };
15
+ }
16
+ };
17
+ export {
18
+ KTX
19
+ };
@@ -0,0 +1,2 @@
1
+ import type { IImage } from './interface.ts';
2
+ export declare const PNG: IImage;
@@ -0,0 +1,34 @@
1
+ import { toUTF8String, readUInt32BE } from "./utils.js";
2
+ const pngSignature = "PNG\r\n\n";
3
+ const pngImageHeaderChunkName = "IHDR";
4
+ const pngFriedChunkName = "CgBI";
5
+ const PNG = {
6
+ validate(input) {
7
+ if (pngSignature === toUTF8String(input, 1, 8)) {
8
+ let chunkName = toUTF8String(input, 12, 16);
9
+ if (chunkName === pngFriedChunkName) {
10
+ chunkName = toUTF8String(input, 28, 32);
11
+ }
12
+ if (chunkName !== pngImageHeaderChunkName) {
13
+ throw new TypeError("Invalid PNG");
14
+ }
15
+ return true;
16
+ }
17
+ return false;
18
+ },
19
+ calculate(input) {
20
+ if (toUTF8String(input, 12, 16) === pngFriedChunkName) {
21
+ return {
22
+ height: readUInt32BE(input, 36),
23
+ width: readUInt32BE(input, 32)
24
+ };
25
+ }
26
+ return {
27
+ height: readUInt32BE(input, 20),
28
+ width: readUInt32BE(input, 16)
29
+ };
30
+ }
31
+ };
32
+ export {
33
+ PNG
34
+ };
@@ -0,0 +1,2 @@
1
+ import type { IImage } from './interface.ts';
2
+ export declare const PNM: IImage;
@@ -0,0 +1,69 @@
1
+ import { toUTF8String } from "./utils.js";
2
+ const PNMTypes = {
3
+ P1: "pbm/ascii",
4
+ P2: "pgm/ascii",
5
+ P3: "ppm/ascii",
6
+ P4: "pbm",
7
+ P5: "pgm",
8
+ P6: "ppm",
9
+ P7: "pam",
10
+ PF: "pfm"
11
+ };
12
+ const handlers = {
13
+ default: (lines) => {
14
+ let dimensions = [];
15
+ while (lines.length > 0) {
16
+ const line = lines.shift();
17
+ if (line[0] === "#") {
18
+ continue;
19
+ }
20
+ dimensions = line.split(" ");
21
+ break;
22
+ }
23
+ if (dimensions.length === 2) {
24
+ return {
25
+ height: parseInt(dimensions[1], 10),
26
+ width: parseInt(dimensions[0], 10)
27
+ };
28
+ } else {
29
+ throw new TypeError("Invalid PNM");
30
+ }
31
+ },
32
+ pam: (lines) => {
33
+ const size = {};
34
+ while (lines.length > 0) {
35
+ const line = lines.shift();
36
+ if (line.length > 16 || line.charCodeAt(0) > 128) {
37
+ continue;
38
+ }
39
+ const [key, value] = line.split(" ");
40
+ if (key && value) {
41
+ size[key.toLowerCase()] = parseInt(value, 10);
42
+ }
43
+ if (size.height && size.width) {
44
+ break;
45
+ }
46
+ }
47
+ if (size.height && size.width) {
48
+ return {
49
+ height: size.height,
50
+ width: size.width
51
+ };
52
+ } else {
53
+ throw new TypeError("Invalid PAM");
54
+ }
55
+ }
56
+ };
57
+ const PNM = {
58
+ validate: (input) => toUTF8String(input, 0, 2) in PNMTypes,
59
+ calculate(input) {
60
+ const signature = toUTF8String(input, 0, 2);
61
+ const type = PNMTypes[signature];
62
+ const lines = toUTF8String(input, 3).split(/[\r\n]+/);
63
+ const handler = handlers[type] || handlers.default;
64
+ return handler(lines);
65
+ }
66
+ };
67
+ export {
68
+ PNM
69
+ };
@@ -0,0 +1,2 @@
1
+ import type { IImage } from './interface.ts';
2
+ export declare const PSD: IImage;
@@ -0,0 +1,11 @@
1
+ import { toUTF8String, readUInt32BE } from "./utils.js";
2
+ const PSD = {
3
+ validate: (input) => toUTF8String(input, 0, 4) === "8BPS",
4
+ calculate: (input) => ({
5
+ height: readUInt32BE(input, 14),
6
+ width: readUInt32BE(input, 18)
7
+ })
8
+ };
9
+ export {
10
+ PSD
11
+ };
@@ -0,0 +1,2 @@
1
+ import type { IImage } from './interface.ts';
2
+ export declare const SVG: IImage;
@@ -0,0 +1,94 @@
1
+ import { toUTF8String } from "./utils.js";
2
+ const svgReg = /<svg\s([^>"']|"[^"]*"|'[^']*')*>/;
3
+ const extractorRegExps = {
4
+ height: /\sheight=(['"])([^%]+?)\1/,
5
+ root: svgReg,
6
+ viewbox: /\sviewBox=(['"])(.+?)\1/i,
7
+ width: /\swidth=(['"])([^%]+?)\1/
8
+ };
9
+ const INCH_CM = 2.54;
10
+ const units = {
11
+ in: 96,
12
+ cm: 96 / INCH_CM,
13
+ em: 16,
14
+ ex: 8,
15
+ m: 96 / INCH_CM * 100,
16
+ mm: 96 / INCH_CM / 10,
17
+ pc: 96 / 72 / 12,
18
+ pt: 96 / 72,
19
+ px: 1
20
+ };
21
+ const unitsReg = new RegExp(
22
+ // eslint-disable-next-line regexp/prefer-d
23
+ `^([0-9.]+(?:e\\d+)?)(${Object.keys(units).join("|")})?$`
24
+ );
25
+ function parseLength(len) {
26
+ const m = unitsReg.exec(len);
27
+ if (!m) {
28
+ return void 0;
29
+ }
30
+ return Math.round(Number(m[1]) * (units[m[2]] || 1));
31
+ }
32
+ function parseViewbox(viewbox) {
33
+ const bounds = viewbox.split(" ");
34
+ return {
35
+ height: parseLength(bounds[3]),
36
+ width: parseLength(bounds[2])
37
+ };
38
+ }
39
+ function parseAttributes(root) {
40
+ const width = root.match(extractorRegExps.width);
41
+ const height = root.match(extractorRegExps.height);
42
+ const viewbox = root.match(extractorRegExps.viewbox);
43
+ return {
44
+ height: height && parseLength(height[2]),
45
+ // eslint-disable-next-line @typescript-eslint/no-unnecessary-type-assertion
46
+ viewbox: viewbox && parseViewbox(viewbox[2]),
47
+ width: width && parseLength(width[2])
48
+ };
49
+ }
50
+ function calculateByDimensions(attrs) {
51
+ return {
52
+ height: attrs.height,
53
+ width: attrs.width
54
+ };
55
+ }
56
+ function calculateByViewbox(attrs, viewbox) {
57
+ const ratio = viewbox.width / viewbox.height;
58
+ if (attrs.width) {
59
+ return {
60
+ height: Math.floor(attrs.width / ratio),
61
+ width: attrs.width
62
+ };
63
+ }
64
+ if (attrs.height) {
65
+ return {
66
+ height: attrs.height,
67
+ width: Math.floor(attrs.height * ratio)
68
+ };
69
+ }
70
+ return {
71
+ height: viewbox.height,
72
+ width: viewbox.width
73
+ };
74
+ }
75
+ const SVG = {
76
+ // Scan only the first kilo-byte to speed up the check on larger files
77
+ validate: (input) => svgReg.test(toUTF8String(input, 0, 1e3)),
78
+ calculate(input) {
79
+ const root = toUTF8String(input).match(extractorRegExps.root);
80
+ if (root) {
81
+ const attrs = parseAttributes(root[0]);
82
+ if (attrs.width && attrs.height) {
83
+ return calculateByDimensions(attrs);
84
+ }
85
+ if (attrs.viewbox) {
86
+ return calculateByViewbox(attrs, attrs.viewbox);
87
+ }
88
+ }
89
+ throw new TypeError("Invalid SVG");
90
+ }
91
+ };
92
+ export {
93
+ SVG
94
+ };
@@ -0,0 +1,2 @@
1
+ import type { IImage } from './interface.ts';
2
+ export declare const TGA: IImage;
@@ -0,0 +1,15 @@
1
+ import { readUInt16LE } from "./utils.js";
2
+ const TGA = {
3
+ validate(input) {
4
+ return readUInt16LE(input, 0) === 0 && readUInt16LE(input, 4) === 0;
5
+ },
6
+ calculate(input) {
7
+ return {
8
+ height: readUInt16LE(input, 14),
9
+ width: readUInt16LE(input, 12)
10
+ };
11
+ }
12
+ };
13
+ export {
14
+ TGA
15
+ };
@@ -0,0 +1,2 @@
1
+ import type { IImage } from './interface.ts';
2
+ export declare const TIFF: IImage;
@@ -0,0 +1,66 @@
1
+ import { readUInt, toHexString, toUTF8String } from "./utils.js";
2
+ function readIFD(input, isBigEndian) {
3
+ const ifdOffset = readUInt(input, 32, 4, isBigEndian);
4
+ return input.slice(ifdOffset + 2);
5
+ }
6
+ function readValue(input, isBigEndian) {
7
+ const low = readUInt(input, 16, 8, isBigEndian);
8
+ const high = readUInt(input, 16, 10, isBigEndian);
9
+ return (high << 16) + low;
10
+ }
11
+ function nextTag(input) {
12
+ if (input.length > 24) {
13
+ return input.slice(12);
14
+ }
15
+ }
16
+ function extractTags(input, isBigEndian) {
17
+ const tags = {};
18
+ let temp = input;
19
+ while (temp && temp.length) {
20
+ const code = readUInt(temp, 16, 0, isBigEndian);
21
+ const type = readUInt(temp, 16, 2, isBigEndian);
22
+ const length = readUInt(temp, 32, 4, isBigEndian);
23
+ if (code === 0) {
24
+ break;
25
+ } else {
26
+ if (length === 1 && (type === 3 || type === 4)) {
27
+ tags[code] = readValue(temp, isBigEndian);
28
+ }
29
+ temp = nextTag(temp);
30
+ }
31
+ }
32
+ return tags;
33
+ }
34
+ function determineEndianness(input) {
35
+ const signature = toUTF8String(input, 0, 2);
36
+ if ("II" === signature) {
37
+ return "LE";
38
+ } else if ("MM" === signature) {
39
+ return "BE";
40
+ }
41
+ }
42
+ const signatures = [
43
+ // '492049', // currently not supported
44
+ "49492a00",
45
+ // Little endian
46
+ "4d4d002a"
47
+ // Big Endian
48
+ // '4d4d002a', // BigTIFF > 4GB. currently not supported
49
+ ];
50
+ const TIFF = {
51
+ validate: (input) => signatures.includes(toHexString(input, 0, 4)),
52
+ calculate(input) {
53
+ const isBigEndian = determineEndianness(input) === "BE";
54
+ const ifdBuffer = readIFD(input, isBigEndian);
55
+ const tags = extractTags(ifdBuffer, isBigEndian);
56
+ const width = tags[256];
57
+ const height = tags[257];
58
+ if (!width || !height) {
59
+ throw new TypeError("Invalid Tiff. Missing tags");
60
+ }
61
+ return { height, width };
62
+ }
63
+ };
64
+ export {
65
+ TIFF
66
+ };
@@ -0,0 +1,15 @@
1
+ export declare const toUTF8String: (input: Uint8Array, start?: number, end?: number) => string;
2
+ export declare const toHexString: (input: Uint8Array, start?: number, end?: number) => string;
3
+ export declare const readInt16LE: (input: Uint8Array, offset?: number) => number;
4
+ export declare const readUInt16BE: (input: Uint8Array, offset?: number) => number;
5
+ export declare const readUInt16LE: (input: Uint8Array, offset?: number) => number;
6
+ export declare const readUInt24LE: (input: Uint8Array, offset?: number) => number;
7
+ export declare const readInt32LE: (input: Uint8Array, offset?: number) => number;
8
+ export declare const readUInt32BE: (input: Uint8Array, offset?: number) => number;
9
+ export declare const readUInt32LE: (input: Uint8Array, offset?: number) => number;
10
+ export declare function readUInt(input: Uint8Array, bits: 16 | 32, offset: number, isBigEndian: boolean): number;
11
+ export declare function findBox(buffer: Uint8Array, boxName: string, offset: number): {
12
+ name: string;
13
+ offset: number;
14
+ size: number;
15
+ } | undefined;
@@ -0,0 +1,60 @@
1
+ const decoder = new TextDecoder();
2
+ const toUTF8String = (input, start = 0, end = input.length) => decoder.decode(input.slice(start, end));
3
+ const toHexString = (input, start = 0, end = input.length) => input.slice(start, end).reduce((memo, i) => memo + ("0" + i.toString(16)).slice(-2), "");
4
+ const readInt16LE = (input, offset = 0) => {
5
+ const val = input[offset] + input[offset + 1] * 2 ** 8;
6
+ return val | (val & 2 ** 15) * 131070;
7
+ };
8
+ const readUInt16BE = (input, offset = 0) => input[offset] * 2 ** 8 + input[offset + 1];
9
+ const readUInt16LE = (input, offset = 0) => input[offset] + input[offset + 1] * 2 ** 8;
10
+ const readUInt24LE = (input, offset = 0) => input[offset] + input[offset + 1] * 2 ** 8 + input[offset + 2] * 2 ** 16;
11
+ const readInt32LE = (input, offset = 0) => input[offset] + input[offset + 1] * 2 ** 8 + input[offset + 2] * 2 ** 16 + (input[offset + 3] << 24);
12
+ const readUInt32BE = (input, offset = 0) => input[offset] * 2 ** 24 + input[offset + 1] * 2 ** 16 + input[offset + 2] * 2 ** 8 + input[offset + 3];
13
+ const readUInt32LE = (input, offset = 0) => input[offset] + input[offset + 1] * 2 ** 8 + input[offset + 2] * 2 ** 16 + input[offset + 3] * 2 ** 24;
14
+ const methods = {
15
+ readUInt16BE,
16
+ readUInt16LE,
17
+ readUInt32BE,
18
+ readUInt32LE
19
+ };
20
+ function readUInt(input, bits, offset, isBigEndian) {
21
+ offset = offset || 0;
22
+ const endian = isBigEndian ? "BE" : "LE";
23
+ const methodName = "readUInt" + bits + endian;
24
+ return methods[methodName](input, offset);
25
+ }
26
+ function readBox(buffer, offset) {
27
+ if (buffer.length - offset < 4)
28
+ return;
29
+ const boxSize = readUInt32BE(buffer, offset);
30
+ if (buffer.length - offset < boxSize)
31
+ return;
32
+ return {
33
+ name: toUTF8String(buffer, 4 + offset, 8 + offset),
34
+ offset,
35
+ size: boxSize
36
+ };
37
+ }
38
+ function findBox(buffer, boxName, offset) {
39
+ while (offset < buffer.length) {
40
+ const box = readBox(buffer, offset);
41
+ if (!box)
42
+ break;
43
+ if (box.name === boxName)
44
+ return box;
45
+ offset += box.size;
46
+ }
47
+ }
48
+ export {
49
+ findBox,
50
+ readInt16LE,
51
+ readInt32LE,
52
+ readUInt,
53
+ readUInt16BE,
54
+ readUInt16LE,
55
+ readUInt24LE,
56
+ readUInt32BE,
57
+ readUInt32LE,
58
+ toHexString,
59
+ toUTF8String
60
+ };
@@ -0,0 +1,2 @@
1
+ import type { IImage } from './interface.ts';
2
+ export declare const WEBP: IImage;
@@ -0,0 +1,52 @@
1
+ import { toHexString, toUTF8String, readInt16LE, readUInt24LE } from "./utils.js";
2
+ function calculateExtended(input) {
3
+ return {
4
+ height: 1 + readUInt24LE(input, 7),
5
+ width: 1 + readUInt24LE(input, 4)
6
+ };
7
+ }
8
+ function calculateLossless(input) {
9
+ return {
10
+ height: 1 + ((input[4] & 15) << 10 | input[3] << 2 | (input[2] & 192) >> 6),
11
+ width: 1 + ((input[2] & 63) << 8 | input[1])
12
+ };
13
+ }
14
+ function calculateLossy(input) {
15
+ return {
16
+ height: readInt16LE(input, 8) & 16383,
17
+ width: readInt16LE(input, 6) & 16383
18
+ };
19
+ }
20
+ const WEBP = {
21
+ validate(input) {
22
+ const riffHeader = "RIFF" === toUTF8String(input, 0, 4);
23
+ const webpHeader = "WEBP" === toUTF8String(input, 8, 12);
24
+ const vp8Header = "VP8" === toUTF8String(input, 12, 15);
25
+ return riffHeader && webpHeader && vp8Header;
26
+ },
27
+ calculate(input) {
28
+ const chunkHeader = toUTF8String(input, 12, 16);
29
+ input = input.slice(20, 30);
30
+ if (chunkHeader === "VP8X") {
31
+ const extendedHeader = input[0];
32
+ const validStart = (extendedHeader & 192) === 0;
33
+ const validEnd = (extendedHeader & 1) === 0;
34
+ if (validStart && validEnd) {
35
+ return calculateExtended(input);
36
+ } else {
37
+ throw new TypeError("Invalid WebP");
38
+ }
39
+ }
40
+ if (chunkHeader === "VP8 " && input[0] !== 47) {
41
+ return calculateLossy(input);
42
+ }
43
+ const signature = toHexString(input, 3, 6);
44
+ if (chunkHeader === "VP8L" && signature !== "9d012a") {
45
+ return calculateLossless(input);
46
+ }
47
+ throw new TypeError("Invalid WebP");
48
+ }
49
+ };
50
+ export {
51
+ WEBP
52
+ };