astro 4.3.7 → 4.4.0

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 (89) hide show
  1. package/components/Image.astro +4 -0
  2. package/components/Picture.astro +4 -0
  3. package/dist/assets/internal.js +14 -0
  4. package/dist/assets/types.d.ts +23 -2
  5. package/dist/assets/utils/metadata.js +3 -3
  6. package/dist/assets/utils/remoteProbe.d.ts +2 -0
  7. package/dist/assets/utils/remoteProbe.js +35 -0
  8. package/dist/assets/utils/vendor/image-size/detector.d.ts +2 -0
  9. package/dist/assets/utils/vendor/image-size/detector.js +24 -0
  10. package/dist/assets/utils/vendor/image-size/lookup.d.ts +10 -0
  11. package/dist/assets/utils/vendor/image-size/lookup.js +26 -0
  12. package/dist/assets/utils/vendor/image-size/types/bmp.d.ts +2 -0
  13. package/dist/assets/utils/vendor/image-size/types/bmp.js +11 -0
  14. package/dist/assets/utils/vendor/image-size/types/cur.d.ts +2 -0
  15. package/dist/assets/utils/vendor/image-size/types/cur.js +17 -0
  16. package/dist/assets/utils/vendor/image-size/types/dds.d.ts +2 -0
  17. package/dist/assets/utils/vendor/image-size/types/dds.js +11 -0
  18. package/dist/assets/utils/vendor/image-size/types/gif.d.ts +2 -0
  19. package/dist/assets/utils/vendor/image-size/types/gif.js +12 -0
  20. package/dist/assets/utils/vendor/image-size/types/heif.d.ts +2 -0
  21. package/dist/assets/utils/vendor/image-size/types/heif.js +53 -0
  22. package/dist/assets/utils/vendor/image-size/types/icns.d.ts +2 -0
  23. package/dist/assets/utils/vendor/image-size/types/icns.js +85 -0
  24. package/dist/assets/utils/vendor/image-size/types/ico.d.ts +2 -0
  25. package/dist/assets/utils/vendor/image-size/types/ico.js +43 -0
  26. package/dist/assets/utils/vendor/image-size/types/index.d.ts +3 -0
  27. package/dist/assets/utils/vendor/image-size/types/index.js +43 -0
  28. package/dist/assets/utils/vendor/image-size/types/interface.d.ts +13 -0
  29. package/dist/assets/utils/vendor/image-size/types/interface.js +0 -0
  30. package/dist/assets/utils/vendor/image-size/types/j2c.d.ts +2 -0
  31. package/dist/assets/utils/vendor/image-size/types/j2c.js +12 -0
  32. package/dist/assets/utils/vendor/image-size/types/jp2.d.ts +2 -0
  33. package/dist/assets/utils/vendor/image-size/types/jp2.js +25 -0
  34. package/dist/assets/utils/vendor/image-size/types/jpg.d.ts +2 -0
  35. package/dist/assets/utils/vendor/image-size/types/jpg.js +97 -0
  36. package/dist/assets/utils/vendor/image-size/types/ktx.d.ts +2 -0
  37. package/dist/assets/utils/vendor/image-size/types/ktx.js +19 -0
  38. package/dist/assets/utils/vendor/image-size/types/png.d.ts +2 -0
  39. package/dist/assets/utils/vendor/image-size/types/png.js +34 -0
  40. package/dist/assets/utils/vendor/image-size/types/pnm.d.ts +2 -0
  41. package/dist/assets/utils/vendor/image-size/types/pnm.js +69 -0
  42. package/dist/assets/utils/vendor/image-size/types/psd.d.ts +2 -0
  43. package/dist/assets/utils/vendor/image-size/types/psd.js +11 -0
  44. package/dist/assets/utils/vendor/image-size/types/svg.d.ts +2 -0
  45. package/dist/assets/utils/vendor/image-size/types/svg.js +94 -0
  46. package/dist/assets/utils/vendor/image-size/types/tga.d.ts +2 -0
  47. package/dist/assets/utils/vendor/image-size/types/tga.js +15 -0
  48. package/dist/assets/utils/vendor/image-size/types/tiff.d.ts +2 -0
  49. package/dist/assets/utils/vendor/image-size/types/tiff.js +66 -0
  50. package/dist/assets/utils/vendor/image-size/types/utils.d.ts +15 -0
  51. package/dist/assets/utils/vendor/image-size/types/utils.js +60 -0
  52. package/dist/assets/utils/vendor/image-size/types/webp.d.ts +2 -0
  53. package/dist/assets/utils/vendor/image-size/types/webp.js +52 -0
  54. package/dist/cli/add/index.js +9 -2
  55. package/dist/content/runtime.js +3 -1
  56. package/dist/content/types-generator.js +3 -23
  57. package/dist/core/build/plugins/plugin-css.js +6 -5
  58. package/dist/core/build/plugins/plugin-hoisted-scripts.js +6 -5
  59. package/dist/core/build/plugins/util.d.ts +2 -1
  60. package/dist/core/build/plugins/util.js +12 -1
  61. package/dist/core/constants.js +1 -1
  62. package/dist/core/dev/dev.js +1 -1
  63. package/dist/core/errors/errors-data.d.ts +16 -3
  64. package/dist/core/errors/errors-data.js +9 -2
  65. package/dist/core/messages.js +2 -2
  66. package/dist/core/routing/manifest/create.js +11 -27
  67. package/dist/prerender/routing.js +20 -20
  68. package/dist/runtime/client/dev-toolbar/apps/astro.js +1 -1
  69. package/dist/runtime/client/dev-toolbar/apps/audit/index.d.ts +1 -1
  70. package/dist/runtime/client/dev-toolbar/apps/audit/index.js +115 -6
  71. package/dist/runtime/client/dev-toolbar/apps/audit/perf.d.ts +2 -0
  72. package/dist/runtime/client/dev-toolbar/apps/audit/perf.js +110 -0
  73. package/dist/runtime/client/dev-toolbar/apps/utils/highlight.d.ts +1 -1
  74. package/dist/runtime/client/dev-toolbar/apps/utils/highlight.js +6 -1
  75. package/dist/runtime/client/dev-toolbar/ui-library/card.js +1 -1
  76. package/dist/runtime/server/astro-island.js +10 -1
  77. package/dist/runtime/server/astro-island.prebuilt-dev.d.ts +7 -0
  78. package/dist/runtime/server/astro-island.prebuilt-dev.js +4 -0
  79. package/dist/runtime/server/astro-island.prebuilt.d.ts +1 -1
  80. package/dist/runtime/server/astro-island.prebuilt.js +1 -1
  81. package/dist/runtime/server/render/astro/render.d.ts +1 -0
  82. package/dist/runtime/server/render/astro/render.js +81 -2
  83. package/dist/runtime/server/render/component.js +6 -0
  84. package/dist/runtime/server/render/page.js +15 -2
  85. package/dist/runtime/server/render/util.d.ts +7 -0
  86. package/dist/runtime/server/render/util.js +15 -0
  87. package/dist/runtime/server/scripts.js +2 -4
  88. package/dist/runtime/server/transition.js +14 -1
  89. package/package.json +5 -5
@@ -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
+ };
@@ -61,14 +61,21 @@ const OFFICIAL_ADAPTER_TO_IMPORT_MAP = {
61
61
  cloudflare: "@astrojs/cloudflare",
62
62
  node: "@astrojs/node"
63
63
  };
64
+ let _registry;
64
65
  async function getRegistry() {
66
+ if (_registry)
67
+ return _registry;
68
+ const fallback = "https://registry.npmjs.org";
65
69
  const packageManager = (await preferredPM(process.cwd()))?.name || "npm";
66
70
  try {
67
71
  const { stdout } = await execa(packageManager, ["config", "get", "registry"]);
68
- return stdout?.trim()?.replace(/\/$/, "") || "https://registry.npmjs.org";
72
+ _registry = stdout?.trim()?.replace(/\/$/, "") || fallback;
73
+ if (!new URL(_registry).host)
74
+ _registry = fallback;
69
75
  } catch (e) {
70
- return "https://registry.npmjs.org";
76
+ _registry = fallback;
71
77
  }
78
+ return _registry;
72
79
  }
73
80
  async function add(names, { flags }) {
74
81
  ensureProcessNodeEnv("production");
@@ -45,7 +45,9 @@ function createGetCollection({
45
45
  type = "data";
46
46
  } else {
47
47
  console.warn(
48
- `The collection **${collection}** does not exist or is empty. Ensure a collection directory with this name exists.`
48
+ `The collection ${JSON.stringify(
49
+ collection
50
+ )} does not exist or is empty. Ensure a collection directory with this name exists.`
49
51
  );
50
52
  return;
51
53
  }
@@ -247,13 +247,6 @@ async function createContentTypesGenerator({
247
247
  viteServer
248
248
  });
249
249
  invalidateVirtualMod(viteServer);
250
- if (observable.status === "loaded") {
251
- warnNonexistentCollections({
252
- logger,
253
- contentConfig: observable.config,
254
- collectionEntryMap
255
- });
256
- }
257
250
  }
258
251
  }
259
252
  return { init, queueEvent };
@@ -280,6 +273,9 @@ async function writeContentFiles({
280
273
  }) {
281
274
  let contentTypesStr = "";
282
275
  let dataTypesStr = "";
276
+ for (const [collection, config] of Object.entries(contentConfig?.collections ?? {})) {
277
+ collectionEntryMap[JSON.stringify(collection)] ??= { type: config.type, entries: {} };
278
+ }
283
279
  for (const collectionKey of Object.keys(collectionEntryMap).sort()) {
284
280
  const collectionConfig = contentConfig?.collections[JSON.parse(collectionKey)];
285
281
  const collection = collectionEntryMap[collectionKey];
@@ -370,22 +366,6 @@ async function writeContentFiles({
370
366
  typeTemplateContent
371
367
  );
372
368
  }
373
- function warnNonexistentCollections({
374
- contentConfig,
375
- collectionEntryMap,
376
- logger
377
- }) {
378
- for (const configuredCollection in contentConfig.collections) {
379
- if (!collectionEntryMap[JSON.stringify(configuredCollection)]) {
380
- logger.warn(
381
- "content",
382
- `The ${bold(configuredCollection)} collection is defined but no ${bold(
383
- "content/" + configuredCollection
384
- )} folder exists in the content directory. Create a new folder for the collection, or check your content configuration file for typos.`
385
- );
386
- }
387
- }
388
- }
389
369
  export {
390
370
  createContentTypesGenerator
391
371
  };