@screenbook/ui 0.0.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 (101) hide show
  1. package/.astro/content-assets.mjs +1 -0
  2. package/.astro/content-modules.mjs +1 -0
  3. package/.astro/content.d.ts +199 -0
  4. package/.astro/data-store.json +1 -0
  5. package/.astro/settings.json +5 -0
  6. package/.astro/types.d.ts +2 -0
  7. package/.prettierrc +15 -0
  8. package/.screenbook/coverage.json +37 -0
  9. package/.screenbook/screens.json +90 -0
  10. package/LICENSE +21 -0
  11. package/astro.config.mjs +18 -0
  12. package/dist/client/_astro/_baseUniq.BGai4mcc.js +1 -0
  13. package/dist/client/_astro/arc.DUp0dfXj.js +1 -0
  14. package/dist/client/_astro/architectureDiagram-VXUJARFQ.De_Gt-YC.js +36 -0
  15. package/dist/client/_astro/blockDiagram-VD42YOAC.BBt_VNhR.js +122 -0
  16. package/dist/client/_astro/c4Diagram-YG6GDRKO.DfgUlHvt.js +10 -0
  17. package/dist/client/_astro/channel.CNyr52v1.js +1 -0
  18. package/dist/client/_astro/chunk-4BX2VUAB.BL0ar6du.js +1 -0
  19. package/dist/client/_astro/chunk-55IACEB6.CI6SkZkY.js +1 -0
  20. package/dist/client/_astro/chunk-B4BG7PRW.Z25N80K6.js +165 -0
  21. package/dist/client/_astro/chunk-DI55MBZ5.BqjPVmi1.js +220 -0
  22. package/dist/client/_astro/chunk-FMBD7UC4.bZ9DWnFm.js +15 -0
  23. package/dist/client/_astro/chunk-QN33PNHL.BkzuUgWB.js +1 -0
  24. package/dist/client/_astro/chunk-QZHKN3VN.C__d68N_.js +1 -0
  25. package/dist/client/_astro/chunk-TZMSLE5B.BIpu8bMn.js +1 -0
  26. package/dist/client/_astro/classDiagram-2ON5EDUG.CxT3aW-h.js +1 -0
  27. package/dist/client/_astro/classDiagram-v2-WZHVMYZB.CxT3aW-h.js +1 -0
  28. package/dist/client/_astro/clone.U_lSZ6fe.js +1 -0
  29. package/dist/client/_astro/cose-bilkent-S5V4N54A.D48yfMll.js +1 -0
  30. package/dist/client/_astro/coverage.CKIVg4LY.css +1 -0
  31. package/dist/client/_astro/coverage.DDJMzKCq.css +1 -0
  32. package/dist/client/_astro/cytoscape.esm.DtBltrT8.js +331 -0
  33. package/dist/client/_astro/dagre-6UL2VRFP.LKVH7b30.js +4 -0
  34. package/dist/client/_astro/defaultLocale.C4B-KCzX.js +1 -0
  35. package/dist/client/_astro/diagram-PSM6KHXK.AHgUjH56.js +24 -0
  36. package/dist/client/_astro/diagram-QEK2KX5R.DvS33xWZ.js +43 -0
  37. package/dist/client/_astro/diagram-S2PKOQOG.BWisaYrQ.js +24 -0
  38. package/dist/client/_astro/erDiagram-Q2GNP2WA.B7oID6oT.js +60 -0
  39. package/dist/client/_astro/flowDiagram-NV44I4VS.Bb1qJLxr.js +162 -0
  40. package/dist/client/_astro/ganttDiagram-JELNMOA3.3vGHETyo.js +267 -0
  41. package/dist/client/_astro/gitGraphDiagram-NY62KEGX.Co2SKcif.js +65 -0
  42. package/dist/client/_astro/graph.B5fevUwB.js +1 -0
  43. package/dist/client/_astro/graph.astro_astro_type_script_index_0_lang.1HlATQ1g.js +1 -0
  44. package/dist/client/_astro/impact.Cvhl64u1.css +1 -0
  45. package/dist/client/_astro/impact.astro_astro_type_script_index_0_lang.D4cAR9AL.js +6 -0
  46. package/dist/client/_astro/infoDiagram-WHAUD3N6.B6ULtps1.js +2 -0
  47. package/dist/client/_astro/init.Gi6I4Gst.js +1 -0
  48. package/dist/client/_astro/journeyDiagram-XKPGCS4Q.BSOCzWmw.js +139 -0
  49. package/dist/client/_astro/kanban-definition-3W4ZIXB7.D8KKGc1o.js +89 -0
  50. package/dist/client/_astro/katex.XbL3y5x-.js +261 -0
  51. package/dist/client/_astro/layout.8vv24qEg.js +1 -0
  52. package/dist/client/_astro/linear.B6O9ymuK.js +1 -0
  53. package/dist/client/_astro/mermaid.core.CReXU7YN.js +256 -0
  54. package/dist/client/_astro/min.CdGMGVU0.js +1 -0
  55. package/dist/client/_astro/mindmap-definition-VGOIOE7T.G14HgtDw.js +68 -0
  56. package/dist/client/_astro/ordinal.BYWQX77i.js +1 -0
  57. package/dist/client/_astro/pieDiagram-ADFJNKIX.bC2VkyoW.js +30 -0
  58. package/dist/client/_astro/quadrantDiagram-AYHSOK5B.BlLaQQxO.js +7 -0
  59. package/dist/client/_astro/requirementDiagram-UZGBJVZJ.DHRnMofO.js +64 -0
  60. package/dist/client/_astro/sankeyDiagram-TZEHDZUN.BMuaJBmt.js +10 -0
  61. package/dist/client/_astro/sequenceDiagram-WL72ISMW.CnU62wqy.js +145 -0
  62. package/dist/client/_astro/stateDiagram-FKZM4ZOC.CewI55YO.js +1 -0
  63. package/dist/client/_astro/stateDiagram-v2-4FDKWEC3.7xUQqoNr.js +1 -0
  64. package/dist/client/_astro/timeline-definition-IT6M3QCI.D1PLRwss.js +61 -0
  65. package/dist/client/_astro/treemap-KMMF4GRG.D3VNVvXF.js +128 -0
  66. package/dist/client/_astro/xychartDiagram-PRI3JC2R.CQex0-ul.js +7 -0
  67. package/dist/client/logo.svg +5 -0
  68. package/dist/server/_@astrojs-ssr-adapter.mjs +1 -0
  69. package/dist/server/_noop-middleware.mjs +3 -0
  70. package/dist/server/chunks/_@astrojs-ssr-adapter_DgsYudHz.mjs +4385 -0
  71. package/dist/server/chunks/astro/server_m7yT4wCr.mjs +2787 -0
  72. package/dist/server/chunks/astro-designed-error-pages_BvPhMmw0.mjs +364 -0
  73. package/dist/server/chunks/fs-lite_COtHaKzy.mjs +157 -0
  74. package/dist/server/chunks/impactAnalysis_Bz5lMdmy.mjs +188 -0
  75. package/dist/server/chunks/loadScreens_DJf-tycc.mjs +39 -0
  76. package/dist/server/chunks/node_DoTkMCOi.mjs +1673 -0
  77. package/dist/server/chunks/remote_B3W5fv4r.mjs +188 -0
  78. package/dist/server/chunks/sharp_DHNfMLYY.mjs +99 -0
  79. package/dist/server/entry.mjs +47 -0
  80. package/dist/server/manifest_-V1HEnR8.mjs +101 -0
  81. package/dist/server/noop-entrypoint.mjs +3 -0
  82. package/dist/server/pages/_image.astro.mjs +2 -0
  83. package/dist/server/pages/coverage.astro.mjs +65 -0
  84. package/dist/server/pages/graph.astro.mjs +107 -0
  85. package/dist/server/pages/impact.astro.mjs +52 -0
  86. package/dist/server/pages/index.astro.mjs +28 -0
  87. package/dist/server/pages/screen/_id_.astro.mjs +52 -0
  88. package/dist/server/renderers.mjs +3 -0
  89. package/package.json +42 -0
  90. package/public/logo.svg +5 -0
  91. package/src/layouts/Layout.astro +60 -0
  92. package/src/pages/coverage.astro +399 -0
  93. package/src/pages/graph.astro +330 -0
  94. package/src/pages/impact.astro +459 -0
  95. package/src/pages/index.astro +167 -0
  96. package/src/pages/screen/[id].astro +186 -0
  97. package/src/styles/global.css +862 -0
  98. package/src/utils/impactAnalysis.ts +297 -0
  99. package/src/utils/loadCoverage.ts +30 -0
  100. package/src/utils/loadScreens.ts +18 -0
  101. package/tsconfig.json +9 -0
@@ -0,0 +1,1673 @@
1
+ import { i as isRemoteAllowed, j as joinPaths, a as isRemotePath, r as removeQueryString, b as isParentDirectory } from './remote_B3W5fv4r.mjs';
2
+ import { A as AstroError, E as ExpectedImage, L as LocalImageUsedWrongly, M as MissingImageDimension, U as UnsupportedImageFormat, I as IncompatibleDescriptorOptions, a as UnsupportedImageConversion, t as toStyleString, N as NoImageMetadata, F as FailedToFetchRemoteImageDimensions, b as ExpectedImageOptions, c as ExpectedNotESMImage, d as InvalidImageService, e as createComponent, f as createAstro, g as ImageMissingAlt, m as maybeRenderHead, h as addAttribute, s as spreadAttributes, r as renderTemplate, i as ExperimentalFontsNotEnabled, j as FontFamilyNotFound, u as unescapeHTML } from './astro/server_m7yT4wCr.mjs';
3
+ import 'clsx';
4
+ import * as mime from 'mrmime';
5
+ import 'piccolore';
6
+ import { readFile } from 'node:fs/promises';
7
+ import { fileURLToPath } from 'node:url';
8
+ import '../renderers.mjs';
9
+
10
+ const VALID_SUPPORTED_FORMATS = [
11
+ "jpeg",
12
+ "jpg",
13
+ "png",
14
+ "tiff",
15
+ "webp",
16
+ "gif",
17
+ "svg",
18
+ "avif"
19
+ ];
20
+ const DEFAULT_OUTPUT_FORMAT = "webp";
21
+ const DEFAULT_HASH_PROPS = [
22
+ "src",
23
+ "width",
24
+ "height",
25
+ "format",
26
+ "quality",
27
+ "fit",
28
+ "position"
29
+ ];
30
+
31
+ const DEFAULT_RESOLUTIONS = [
32
+ 640,
33
+ // older and lower-end phones
34
+ 750,
35
+ // iPhone 6-8
36
+ 828,
37
+ // iPhone XR/11
38
+ 960,
39
+ // older horizontal phones
40
+ 1080,
41
+ // iPhone 6-8 Plus
42
+ 1280,
43
+ // 720p
44
+ 1668,
45
+ // Various iPads
46
+ 1920,
47
+ // 1080p
48
+ 2048,
49
+ // QXGA
50
+ 2560,
51
+ // WQXGA
52
+ 3200,
53
+ // QHD+
54
+ 3840,
55
+ // 4K
56
+ 4480,
57
+ // 4.5K
58
+ 5120,
59
+ // 5K
60
+ 6016
61
+ // 6K
62
+ ];
63
+ const LIMITED_RESOLUTIONS = [
64
+ 640,
65
+ // older and lower-end phones
66
+ 750,
67
+ // iPhone 6-8
68
+ 828,
69
+ // iPhone XR/11
70
+ 1080,
71
+ // iPhone 6-8 Plus
72
+ 1280,
73
+ // 720p
74
+ 1668,
75
+ // Various iPads
76
+ 2048,
77
+ // QXGA
78
+ 2560
79
+ // WQXGA
80
+ ];
81
+ const getWidths = ({
82
+ width,
83
+ layout,
84
+ breakpoints = DEFAULT_RESOLUTIONS,
85
+ originalWidth
86
+ }) => {
87
+ const smallerThanOriginal = (w) => !originalWidth || w <= originalWidth;
88
+ if (layout === "full-width") {
89
+ return breakpoints.filter(smallerThanOriginal);
90
+ }
91
+ if (!width) {
92
+ return [];
93
+ }
94
+ const doubleWidth = width * 2;
95
+ const maxSize = originalWidth ? Math.min(doubleWidth, originalWidth) : doubleWidth;
96
+ if (layout === "fixed") {
97
+ return originalWidth && width > originalWidth ? [originalWidth] : [width, maxSize];
98
+ }
99
+ if (layout === "constrained") {
100
+ return [
101
+ // Always include the image at 1x and 2x the specified width
102
+ width,
103
+ doubleWidth,
104
+ ...breakpoints
105
+ ].filter((w) => w <= maxSize).sort((a, b) => a - b);
106
+ }
107
+ return [];
108
+ };
109
+ const getSizesAttribute = ({
110
+ width,
111
+ layout
112
+ }) => {
113
+ if (!width || !layout) {
114
+ return void 0;
115
+ }
116
+ switch (layout) {
117
+ // If screen is wider than the max size then image width is the max size,
118
+ // otherwise it's the width of the screen
119
+ case "constrained":
120
+ return `(min-width: ${width}px) ${width}px, 100vw`;
121
+ // Image is always the same width, whatever the size of the screen
122
+ case "fixed":
123
+ return `${width}px`;
124
+ // Image is always the width of the screen
125
+ case "full-width":
126
+ return `100vw`;
127
+ case "none":
128
+ default:
129
+ return void 0;
130
+ }
131
+ };
132
+
133
+ function isESMImportedImage(src) {
134
+ return typeof src === "object" || typeof src === "function" && "src" in src;
135
+ }
136
+ function isRemoteImage(src) {
137
+ return typeof src === "string";
138
+ }
139
+ async function resolveSrc(src) {
140
+ if (typeof src === "object" && "then" in src) {
141
+ const resource = await src;
142
+ return resource.default ?? resource;
143
+ }
144
+ return src;
145
+ }
146
+
147
+ function isLocalService(service) {
148
+ if (!service) {
149
+ return false;
150
+ }
151
+ return "transform" in service;
152
+ }
153
+ function parseQuality(quality) {
154
+ let result = parseInt(quality);
155
+ if (Number.isNaN(result)) {
156
+ return quality;
157
+ }
158
+ return result;
159
+ }
160
+ const sortNumeric = (a, b) => a - b;
161
+ function verifyOptions(options) {
162
+ if (!options.src || !isRemoteImage(options.src) && !isESMImportedImage(options.src)) {
163
+ throw new AstroError({
164
+ ...ExpectedImage,
165
+ message: ExpectedImage.message(
166
+ JSON.stringify(options.src),
167
+ typeof options.src,
168
+ JSON.stringify(options, (_, v) => v === void 0 ? null : v)
169
+ )
170
+ });
171
+ }
172
+ if (!isESMImportedImage(options.src)) {
173
+ if (options.src.startsWith("/@fs/") || !isRemotePath(options.src) && !options.src.startsWith("/")) {
174
+ throw new AstroError({
175
+ ...LocalImageUsedWrongly,
176
+ message: LocalImageUsedWrongly.message(options.src)
177
+ });
178
+ }
179
+ let missingDimension;
180
+ if (!options.width && !options.height) {
181
+ missingDimension = "both";
182
+ } else if (!options.width && options.height) {
183
+ missingDimension = "width";
184
+ } else if (options.width && !options.height) {
185
+ missingDimension = "height";
186
+ }
187
+ if (missingDimension) {
188
+ throw new AstroError({
189
+ ...MissingImageDimension,
190
+ message: MissingImageDimension.message(missingDimension, options.src)
191
+ });
192
+ }
193
+ } else {
194
+ if (!VALID_SUPPORTED_FORMATS.includes(options.src.format)) {
195
+ throw new AstroError({
196
+ ...UnsupportedImageFormat,
197
+ message: UnsupportedImageFormat.message(
198
+ options.src.format,
199
+ options.src.src,
200
+ VALID_SUPPORTED_FORMATS
201
+ )
202
+ });
203
+ }
204
+ if (options.widths && options.densities) {
205
+ throw new AstroError(IncompatibleDescriptorOptions);
206
+ }
207
+ if (options.src.format === "svg" && options.format !== "svg" || options.src.format !== "svg" && options.format === "svg") {
208
+ throw new AstroError(UnsupportedImageConversion);
209
+ }
210
+ }
211
+ }
212
+ const baseService = {
213
+ validateOptions(options) {
214
+ if (isESMImportedImage(options.src) && options.src.format === "svg") {
215
+ options.format = "svg";
216
+ }
217
+ verifyOptions(options);
218
+ if (!options.format) {
219
+ options.format = DEFAULT_OUTPUT_FORMAT;
220
+ }
221
+ if (options.width) options.width = Math.round(options.width);
222
+ if (options.height) options.height = Math.round(options.height);
223
+ if (options.layout && options.width && options.height) {
224
+ options.fit ??= "cover";
225
+ delete options.layout;
226
+ }
227
+ if (options.fit === "none") {
228
+ delete options.fit;
229
+ }
230
+ return options;
231
+ },
232
+ getHTMLAttributes(options) {
233
+ const { targetWidth, targetHeight } = getTargetDimensions(options);
234
+ const {
235
+ src,
236
+ width,
237
+ height,
238
+ format,
239
+ quality,
240
+ densities,
241
+ widths,
242
+ formats,
243
+ layout,
244
+ priority,
245
+ fit,
246
+ position,
247
+ ...attributes
248
+ } = options;
249
+ return {
250
+ ...attributes,
251
+ width: targetWidth,
252
+ height: targetHeight,
253
+ loading: attributes.loading ?? "lazy",
254
+ decoding: attributes.decoding ?? "async"
255
+ };
256
+ },
257
+ getSrcSet(options) {
258
+ const { targetWidth, targetHeight } = getTargetDimensions(options);
259
+ const aspectRatio = targetWidth / targetHeight;
260
+ const { widths, densities } = options;
261
+ const targetFormat = options.format ?? DEFAULT_OUTPUT_FORMAT;
262
+ let transformedWidths = (widths ?? []).sort(sortNumeric);
263
+ let imageWidth = options.width;
264
+ let maxWidth = Infinity;
265
+ if (isESMImportedImage(options.src)) {
266
+ imageWidth = options.src.width;
267
+ maxWidth = imageWidth;
268
+ if (transformedWidths.length > 0 && transformedWidths.at(-1) > maxWidth) {
269
+ transformedWidths = transformedWidths.filter((width) => width <= maxWidth);
270
+ transformedWidths.push(maxWidth);
271
+ }
272
+ }
273
+ transformedWidths = Array.from(new Set(transformedWidths));
274
+ const {
275
+ width: transformWidth,
276
+ height: transformHeight,
277
+ ...transformWithoutDimensions
278
+ } = options;
279
+ let allWidths = [];
280
+ if (densities) {
281
+ const densityValues = densities.map((density) => {
282
+ if (typeof density === "number") {
283
+ return density;
284
+ } else {
285
+ return parseFloat(density);
286
+ }
287
+ });
288
+ const densityWidths = densityValues.sort(sortNumeric).map((density) => Math.round(targetWidth * density));
289
+ allWidths = densityWidths.map((width, index) => ({
290
+ width,
291
+ descriptor: `${densityValues[index]}x`
292
+ }));
293
+ } else if (transformedWidths.length > 0) {
294
+ allWidths = transformedWidths.map((width) => ({
295
+ width,
296
+ descriptor: `${width}w`
297
+ }));
298
+ }
299
+ return allWidths.map(({ width, descriptor }) => {
300
+ const height = Math.round(width / aspectRatio);
301
+ const transform = { ...transformWithoutDimensions, width, height };
302
+ return {
303
+ transform,
304
+ descriptor,
305
+ attributes: {
306
+ type: `image/${targetFormat}`
307
+ }
308
+ };
309
+ });
310
+ },
311
+ getURL(options, imageConfig) {
312
+ const searchParams = new URLSearchParams();
313
+ if (isESMImportedImage(options.src)) {
314
+ searchParams.append("href", options.src.src);
315
+ } else if (isRemoteAllowed(options.src, imageConfig)) {
316
+ searchParams.append("href", options.src);
317
+ } else {
318
+ return options.src;
319
+ }
320
+ const params = {
321
+ w: "width",
322
+ h: "height",
323
+ q: "quality",
324
+ f: "format",
325
+ fit: "fit",
326
+ position: "position"
327
+ };
328
+ Object.entries(params).forEach(([param, key]) => {
329
+ options[key] && searchParams.append(param, options[key].toString());
330
+ });
331
+ const imageEndpoint = joinPaths("/", imageConfig.endpoint.route);
332
+ let url = `${imageEndpoint}?${searchParams}`;
333
+ if (imageConfig.assetQueryParams) {
334
+ const assetQueryString = imageConfig.assetQueryParams.toString();
335
+ if (assetQueryString) {
336
+ url += "&" + assetQueryString;
337
+ }
338
+ }
339
+ return url;
340
+ },
341
+ parseURL(url) {
342
+ const params = url.searchParams;
343
+ if (!params.has("href")) {
344
+ return void 0;
345
+ }
346
+ const transform = {
347
+ src: params.get("href"),
348
+ width: params.has("w") ? parseInt(params.get("w")) : void 0,
349
+ height: params.has("h") ? parseInt(params.get("h")) : void 0,
350
+ format: params.get("f"),
351
+ quality: params.get("q"),
352
+ fit: params.get("fit"),
353
+ position: params.get("position") ?? void 0
354
+ };
355
+ return transform;
356
+ }
357
+ };
358
+ function getTargetDimensions(options) {
359
+ let targetWidth = options.width;
360
+ let targetHeight = options.height;
361
+ if (isESMImportedImage(options.src)) {
362
+ const aspectRatio = options.src.width / options.src.height;
363
+ if (targetHeight && !targetWidth) {
364
+ targetWidth = Math.round(targetHeight * aspectRatio);
365
+ } else if (targetWidth && !targetHeight) {
366
+ targetHeight = Math.round(targetWidth / aspectRatio);
367
+ } else if (!targetWidth && !targetHeight) {
368
+ targetWidth = options.src.width;
369
+ targetHeight = options.src.height;
370
+ }
371
+ }
372
+ return {
373
+ targetWidth,
374
+ targetHeight
375
+ };
376
+ }
377
+
378
+ function isImageMetadata(src) {
379
+ return src.fsPath && !("fsPath" in src);
380
+ }
381
+
382
+ const cssFitValues = ["fill", "contain", "cover", "scale-down"];
383
+ function addCSSVarsToStyle(vars, styles) {
384
+ const cssVars = Object.entries(vars).filter(([_, value]) => value !== void 0 && value !== false).map(([key, value]) => `--${key}: ${value};`).join(" ");
385
+ if (!styles) {
386
+ return cssVars;
387
+ }
388
+ const style = typeof styles === "string" ? styles : toStyleString(styles);
389
+ return `${cssVars} ${style}`;
390
+ }
391
+
392
+ const decoder = new TextDecoder();
393
+ const toUTF8String = (input, start = 0, end = input.length) => decoder.decode(input.slice(start, end));
394
+ const toHexString = (input, start = 0, end = input.length) => input.slice(start, end).reduce((memo, i) => memo + ("0" + i.toString(16)).slice(-2), "");
395
+ const readInt16LE = (input, offset = 0) => {
396
+ const val = input[offset] + input[offset + 1] * 2 ** 8;
397
+ return val | (val & 2 ** 15) * 131070;
398
+ };
399
+ const readUInt16BE = (input, offset = 0) => input[offset] * 2 ** 8 + input[offset + 1];
400
+ const readUInt16LE = (input, offset = 0) => input[offset] + input[offset + 1] * 2 ** 8;
401
+ const readUInt24LE = (input, offset = 0) => input[offset] + input[offset + 1] * 2 ** 8 + input[offset + 2] * 2 ** 16;
402
+ const readInt32LE = (input, offset = 0) => input[offset] + input[offset + 1] * 2 ** 8 + input[offset + 2] * 2 ** 16 + (input[offset + 3] << 24);
403
+ const readUInt32BE = (input, offset = 0) => input[offset] * 2 ** 24 + input[offset + 1] * 2 ** 16 + input[offset + 2] * 2 ** 8 + input[offset + 3];
404
+ const readUInt32LE = (input, offset = 0) => input[offset] + input[offset + 1] * 2 ** 8 + input[offset + 2] * 2 ** 16 + input[offset + 3] * 2 ** 24;
405
+ const methods = {
406
+ readUInt16BE,
407
+ readUInt16LE,
408
+ readUInt32BE,
409
+ readUInt32LE
410
+ };
411
+ function readUInt(input, bits, offset, isBigEndian) {
412
+ offset = offset || 0;
413
+ const endian = isBigEndian ? "BE" : "LE";
414
+ const methodName = "readUInt" + bits + endian;
415
+ return methods[methodName](input, offset);
416
+ }
417
+ function readBox(buffer, offset) {
418
+ if (buffer.length - offset < 4) return;
419
+ const boxSize = readUInt32BE(buffer, offset);
420
+ if (buffer.length - offset < boxSize) return;
421
+ return {
422
+ name: toUTF8String(buffer, 4 + offset, 8 + offset),
423
+ offset,
424
+ size: boxSize
425
+ };
426
+ }
427
+ function findBox(buffer, boxName, offset) {
428
+ while (offset < buffer.length) {
429
+ const box = readBox(buffer, offset);
430
+ if (!box) break;
431
+ if (box.name === boxName) return box;
432
+ offset += box.size;
433
+ }
434
+ }
435
+
436
+ const BMP = {
437
+ validate: (input) => toUTF8String(input, 0, 2) === "BM",
438
+ calculate: (input) => ({
439
+ height: Math.abs(readInt32LE(input, 22)),
440
+ width: readUInt32LE(input, 18)
441
+ })
442
+ };
443
+
444
+ const TYPE_ICON = 1;
445
+ const SIZE_HEADER$1 = 2 + 2 + 2;
446
+ const SIZE_IMAGE_ENTRY = 1 + 1 + 1 + 1 + 2 + 2 + 4 + 4;
447
+ function getSizeFromOffset(input, offset) {
448
+ const value = input[offset];
449
+ return value === 0 ? 256 : value;
450
+ }
451
+ function getImageSize$1(input, imageIndex) {
452
+ const offset = SIZE_HEADER$1 + imageIndex * SIZE_IMAGE_ENTRY;
453
+ return {
454
+ height: getSizeFromOffset(input, offset + 1),
455
+ width: getSizeFromOffset(input, offset)
456
+ };
457
+ }
458
+ const ICO = {
459
+ validate(input) {
460
+ const reserved = readUInt16LE(input, 0);
461
+ const imageCount = readUInt16LE(input, 4);
462
+ if (reserved !== 0 || imageCount === 0) return false;
463
+ const imageType = readUInt16LE(input, 2);
464
+ return imageType === TYPE_ICON;
465
+ },
466
+ calculate(input) {
467
+ const nbImages = readUInt16LE(input, 4);
468
+ const imageSize = getImageSize$1(input, 0);
469
+ if (nbImages === 1) return imageSize;
470
+ const imgs = [imageSize];
471
+ for (let imageIndex = 1; imageIndex < nbImages; imageIndex += 1) {
472
+ imgs.push(getImageSize$1(input, imageIndex));
473
+ }
474
+ return {
475
+ height: imageSize.height,
476
+ images: imgs,
477
+ width: imageSize.width
478
+ };
479
+ }
480
+ };
481
+
482
+ const TYPE_CURSOR = 2;
483
+ const CUR = {
484
+ validate(input) {
485
+ const reserved = readUInt16LE(input, 0);
486
+ const imageCount = readUInt16LE(input, 4);
487
+ if (reserved !== 0 || imageCount === 0) return false;
488
+ const imageType = readUInt16LE(input, 2);
489
+ return imageType === TYPE_CURSOR;
490
+ },
491
+ calculate: (input) => ICO.calculate(input)
492
+ };
493
+
494
+ const DDS = {
495
+ validate: (input) => readUInt32LE(input, 0) === 542327876,
496
+ calculate: (input) => ({
497
+ height: readUInt32LE(input, 12),
498
+ width: readUInt32LE(input, 16)
499
+ })
500
+ };
501
+
502
+ const gifRegexp = /^GIF8[79]a/;
503
+ const GIF = {
504
+ validate: (input) => gifRegexp.test(toUTF8String(input, 0, 6)),
505
+ calculate: (input) => ({
506
+ height: readUInt16LE(input, 8),
507
+ width: readUInt16LE(input, 6)
508
+ })
509
+ };
510
+
511
+ const brandMap = {
512
+ avif: "avif",
513
+ avis: "avif",
514
+ // avif-sequence
515
+ mif1: "heif",
516
+ msf1: "heif",
517
+ // heif-sequence
518
+ heic: "heic",
519
+ heix: "heic",
520
+ hevc: "heic",
521
+ // heic-sequence
522
+ hevx: "heic"
523
+ // heic-sequence
524
+ };
525
+ function detectBrands(buffer, start, end) {
526
+ let brandsDetected = {};
527
+ for (let i = start; i <= end; i += 4) {
528
+ const brand = toUTF8String(buffer, i, i + 4);
529
+ if (brand in brandMap) {
530
+ brandsDetected[brand] = 1;
531
+ }
532
+ }
533
+ if ("avif" in brandsDetected || "avis" in brandsDetected) {
534
+ return "avif";
535
+ } else if ("heic" in brandsDetected || "heix" in brandsDetected || "hevc" in brandsDetected || "hevx" in brandsDetected) {
536
+ return "heic";
537
+ } else if ("mif1" in brandsDetected || "msf1" in brandsDetected) {
538
+ return "heif";
539
+ }
540
+ }
541
+ const HEIF = {
542
+ validate(buffer) {
543
+ const ftype = toUTF8String(buffer, 4, 8);
544
+ const brand = toUTF8String(buffer, 8, 12);
545
+ return "ftyp" === ftype && brand in brandMap;
546
+ },
547
+ calculate(buffer) {
548
+ const metaBox = findBox(buffer, "meta", 0);
549
+ const iprpBox = metaBox && findBox(buffer, "iprp", metaBox.offset + 12);
550
+ const ipcoBox = iprpBox && findBox(buffer, "ipco", iprpBox.offset + 8);
551
+ const ispeBox = ipcoBox && findBox(buffer, "ispe", ipcoBox.offset + 8);
552
+ if (ispeBox) {
553
+ return {
554
+ height: readUInt32BE(buffer, ispeBox.offset + 16),
555
+ width: readUInt32BE(buffer, ispeBox.offset + 12),
556
+ type: detectBrands(buffer, 8, metaBox.offset)
557
+ };
558
+ }
559
+ throw new TypeError("Invalid HEIF, no size found");
560
+ }
561
+ };
562
+
563
+ const SIZE_HEADER = 4 + 4;
564
+ const FILE_LENGTH_OFFSET = 4;
565
+ const ENTRY_LENGTH_OFFSET = 4;
566
+ const ICON_TYPE_SIZE = {
567
+ ICON: 32,
568
+ "ICN#": 32,
569
+ // m => 16 x 16
570
+ "icm#": 16,
571
+ icm4: 16,
572
+ icm8: 16,
573
+ // s => 16 x 16
574
+ "ics#": 16,
575
+ ics4: 16,
576
+ ics8: 16,
577
+ is32: 16,
578
+ s8mk: 16,
579
+ icp4: 16,
580
+ // l => 32 x 32
581
+ icl4: 32,
582
+ icl8: 32,
583
+ il32: 32,
584
+ l8mk: 32,
585
+ icp5: 32,
586
+ ic11: 32,
587
+ // h => 48 x 48
588
+ ich4: 48,
589
+ ich8: 48,
590
+ ih32: 48,
591
+ h8mk: 48,
592
+ // . => 64 x 64
593
+ icp6: 64,
594
+ ic12: 32,
595
+ // t => 128 x 128
596
+ it32: 128,
597
+ t8mk: 128,
598
+ ic07: 128,
599
+ // . => 256 x 256
600
+ ic08: 256,
601
+ ic13: 256,
602
+ // . => 512 x 512
603
+ ic09: 512,
604
+ ic14: 512,
605
+ // . => 1024 x 1024
606
+ ic10: 1024
607
+ };
608
+ function readImageHeader(input, imageOffset) {
609
+ const imageLengthOffset = imageOffset + ENTRY_LENGTH_OFFSET;
610
+ return [
611
+ toUTF8String(input, imageOffset, imageLengthOffset),
612
+ readUInt32BE(input, imageLengthOffset)
613
+ ];
614
+ }
615
+ function getImageSize(type) {
616
+ const size = ICON_TYPE_SIZE[type];
617
+ return { width: size, height: size, type };
618
+ }
619
+ const ICNS = {
620
+ validate: (input) => toUTF8String(input, 0, 4) === "icns",
621
+ calculate(input) {
622
+ const inputLength = input.length;
623
+ const fileLength = readUInt32BE(input, FILE_LENGTH_OFFSET);
624
+ let imageOffset = SIZE_HEADER;
625
+ let imageHeader = readImageHeader(input, imageOffset);
626
+ let imageSize = getImageSize(imageHeader[0]);
627
+ imageOffset += imageHeader[1];
628
+ if (imageOffset === fileLength) return imageSize;
629
+ const result = {
630
+ height: imageSize.height,
631
+ images: [imageSize],
632
+ width: imageSize.width
633
+ };
634
+ while (imageOffset < fileLength && imageOffset < inputLength) {
635
+ imageHeader = readImageHeader(input, imageOffset);
636
+ imageSize = getImageSize(imageHeader[0]);
637
+ imageOffset += imageHeader[1];
638
+ result.images.push(imageSize);
639
+ }
640
+ return result;
641
+ }
642
+ };
643
+
644
+ const J2C = {
645
+ // TODO: this doesn't seem right. SIZ marker doesn't have to be right after the SOC
646
+ validate: (input) => toHexString(input, 0, 4) === "ff4fff51",
647
+ calculate: (input) => ({
648
+ height: readUInt32BE(input, 12),
649
+ width: readUInt32BE(input, 8)
650
+ })
651
+ };
652
+
653
+ const JP2 = {
654
+ validate(input) {
655
+ if (readUInt32BE(input, 4) !== 1783636e3 || readUInt32BE(input, 0) < 1) return false;
656
+ const ftypBox = findBox(input, "ftyp", 0);
657
+ if (!ftypBox) return false;
658
+ return readUInt32BE(input, ftypBox.offset + 4) === 1718909296;
659
+ },
660
+ calculate(input) {
661
+ const jp2hBox = findBox(input, "jp2h", 0);
662
+ const ihdrBox = jp2hBox && findBox(input, "ihdr", jp2hBox.offset + 8);
663
+ if (ihdrBox) {
664
+ return {
665
+ height: readUInt32BE(input, ihdrBox.offset + 8),
666
+ width: readUInt32BE(input, ihdrBox.offset + 12)
667
+ };
668
+ }
669
+ throw new TypeError("Unsupported JPEG 2000 format");
670
+ }
671
+ };
672
+
673
+ const EXIF_MARKER = "45786966";
674
+ const APP1_DATA_SIZE_BYTES = 2;
675
+ const EXIF_HEADER_BYTES = 6;
676
+ const TIFF_BYTE_ALIGN_BYTES = 2;
677
+ const BIG_ENDIAN_BYTE_ALIGN = "4d4d";
678
+ const LITTLE_ENDIAN_BYTE_ALIGN = "4949";
679
+ const IDF_ENTRY_BYTES = 12;
680
+ const NUM_DIRECTORY_ENTRIES_BYTES = 2;
681
+ function isEXIF(input) {
682
+ return toHexString(input, 2, 6) === EXIF_MARKER;
683
+ }
684
+ function extractSize(input, index) {
685
+ return {
686
+ height: readUInt16BE(input, index),
687
+ width: readUInt16BE(input, index + 2)
688
+ };
689
+ }
690
+ function extractOrientation(exifBlock, isBigEndian) {
691
+ const idfOffset = 8;
692
+ const offset = EXIF_HEADER_BYTES + idfOffset;
693
+ const idfDirectoryEntries = readUInt(exifBlock, 16, offset, isBigEndian);
694
+ for (let directoryEntryNumber = 0; directoryEntryNumber < idfDirectoryEntries; directoryEntryNumber++) {
695
+ const start = offset + NUM_DIRECTORY_ENTRIES_BYTES + directoryEntryNumber * IDF_ENTRY_BYTES;
696
+ const end = start + IDF_ENTRY_BYTES;
697
+ if (start > exifBlock.length) {
698
+ return;
699
+ }
700
+ const block = exifBlock.slice(start, end);
701
+ const tagNumber = readUInt(block, 16, 0, isBigEndian);
702
+ if (tagNumber === 274) {
703
+ const dataFormat = readUInt(block, 16, 2, isBigEndian);
704
+ if (dataFormat !== 3) {
705
+ return;
706
+ }
707
+ const numberOfComponents = readUInt(block, 32, 4, isBigEndian);
708
+ if (numberOfComponents !== 1) {
709
+ return;
710
+ }
711
+ return readUInt(block, 16, 8, isBigEndian);
712
+ }
713
+ }
714
+ }
715
+ function validateExifBlock(input, index) {
716
+ const exifBlock = input.slice(APP1_DATA_SIZE_BYTES, index);
717
+ const byteAlign = toHexString(
718
+ exifBlock,
719
+ EXIF_HEADER_BYTES,
720
+ EXIF_HEADER_BYTES + TIFF_BYTE_ALIGN_BYTES
721
+ );
722
+ const isBigEndian = byteAlign === BIG_ENDIAN_BYTE_ALIGN;
723
+ const isLittleEndian = byteAlign === LITTLE_ENDIAN_BYTE_ALIGN;
724
+ if (isBigEndian || isLittleEndian) {
725
+ return extractOrientation(exifBlock, isBigEndian);
726
+ }
727
+ }
728
+ function validateInput(input, index) {
729
+ if (index > input.length) {
730
+ throw new TypeError("Corrupt JPG, exceeded buffer limits");
731
+ }
732
+ }
733
+ const JPG = {
734
+ validate: (input) => toHexString(input, 0, 2) === "ffd8",
735
+ calculate(input) {
736
+ input = input.slice(4);
737
+ let orientation;
738
+ let next;
739
+ while (input.length) {
740
+ const i = readUInt16BE(input, 0);
741
+ if (input[i] !== 255) {
742
+ input = input.slice(i);
743
+ continue;
744
+ }
745
+ if (isEXIF(input)) {
746
+ orientation = validateExifBlock(input, i);
747
+ }
748
+ validateInput(input, i);
749
+ next = input[i + 1];
750
+ if (next === 192 || next === 193 || next === 194) {
751
+ const size = extractSize(input, i + 5);
752
+ if (!orientation) {
753
+ return size;
754
+ }
755
+ return {
756
+ height: size.height,
757
+ orientation,
758
+ width: size.width
759
+ };
760
+ }
761
+ input = input.slice(i + 2);
762
+ }
763
+ throw new TypeError("Invalid JPG, no size found");
764
+ }
765
+ };
766
+
767
+ const KTX = {
768
+ validate: (input) => {
769
+ const signature = toUTF8String(input, 1, 7);
770
+ return ["KTX 11", "KTX 20"].includes(signature);
771
+ },
772
+ calculate: (input) => {
773
+ const type = input[5] === 49 ? "ktx" : "ktx2";
774
+ const offset = type === "ktx" ? 36 : 20;
775
+ return {
776
+ height: readUInt32LE(input, offset + 4),
777
+ width: readUInt32LE(input, offset),
778
+ type
779
+ };
780
+ }
781
+ };
782
+
783
+ const pngSignature = "PNG\r\n\n";
784
+ const pngImageHeaderChunkName = "IHDR";
785
+ const pngFriedChunkName = "CgBI";
786
+ const PNG = {
787
+ validate(input) {
788
+ if (pngSignature === toUTF8String(input, 1, 8)) {
789
+ let chunkName = toUTF8String(input, 12, 16);
790
+ if (chunkName === pngFriedChunkName) {
791
+ chunkName = toUTF8String(input, 28, 32);
792
+ }
793
+ if (chunkName !== pngImageHeaderChunkName) {
794
+ throw new TypeError("Invalid PNG");
795
+ }
796
+ return true;
797
+ }
798
+ return false;
799
+ },
800
+ calculate(input) {
801
+ if (toUTF8String(input, 12, 16) === pngFriedChunkName) {
802
+ return {
803
+ height: readUInt32BE(input, 36),
804
+ width: readUInt32BE(input, 32)
805
+ };
806
+ }
807
+ return {
808
+ height: readUInt32BE(input, 20),
809
+ width: readUInt32BE(input, 16)
810
+ };
811
+ }
812
+ };
813
+
814
+ const PNMTypes = {
815
+ P1: "pbm/ascii",
816
+ P2: "pgm/ascii",
817
+ P3: "ppm/ascii",
818
+ P4: "pbm",
819
+ P5: "pgm",
820
+ P6: "ppm",
821
+ P7: "pam",
822
+ PF: "pfm"
823
+ };
824
+ const handlers = {
825
+ default: (lines) => {
826
+ let dimensions = [];
827
+ while (lines.length > 0) {
828
+ const line = lines.shift();
829
+ if (line[0] === "#") {
830
+ continue;
831
+ }
832
+ dimensions = line.split(" ");
833
+ break;
834
+ }
835
+ if (dimensions.length === 2) {
836
+ return {
837
+ height: parseInt(dimensions[1], 10),
838
+ width: parseInt(dimensions[0], 10)
839
+ };
840
+ } else {
841
+ throw new TypeError("Invalid PNM");
842
+ }
843
+ },
844
+ pam: (lines) => {
845
+ const size = {};
846
+ while (lines.length > 0) {
847
+ const line = lines.shift();
848
+ if (line.length > 16 || line.charCodeAt(0) > 128) {
849
+ continue;
850
+ }
851
+ const [key, value] = line.split(" ");
852
+ if (key && value) {
853
+ size[key.toLowerCase()] = parseInt(value, 10);
854
+ }
855
+ if (size.height && size.width) {
856
+ break;
857
+ }
858
+ }
859
+ if (size.height && size.width) {
860
+ return {
861
+ height: size.height,
862
+ width: size.width
863
+ };
864
+ } else {
865
+ throw new TypeError("Invalid PAM");
866
+ }
867
+ }
868
+ };
869
+ const PNM = {
870
+ validate: (input) => toUTF8String(input, 0, 2) in PNMTypes,
871
+ calculate(input) {
872
+ const signature = toUTF8String(input, 0, 2);
873
+ const type = PNMTypes[signature];
874
+ const lines = toUTF8String(input, 3).split(/[\r\n]+/);
875
+ const handler = handlers[type] || handlers.default;
876
+ return handler(lines);
877
+ }
878
+ };
879
+
880
+ const PSD = {
881
+ validate: (input) => toUTF8String(input, 0, 4) === "8BPS",
882
+ calculate: (input) => ({
883
+ height: readUInt32BE(input, 14),
884
+ width: readUInt32BE(input, 18)
885
+ })
886
+ };
887
+
888
+ const svgReg = /<svg\s([^>"']|"[^"]*"|'[^']*')*>/;
889
+ const extractorRegExps = {
890
+ height: /\sheight=(['"])([^%]+?)\1/,
891
+ root: svgReg,
892
+ viewbox: /\sviewBox=(['"])(.+?)\1/i,
893
+ width: /\swidth=(['"])([^%]+?)\1/
894
+ };
895
+ const INCH_CM = 2.54;
896
+ const units = {
897
+ in: 96,
898
+ cm: 96 / INCH_CM,
899
+ em: 16,
900
+ ex: 8,
901
+ m: 96 / INCH_CM * 100,
902
+ mm: 96 / INCH_CM / 10,
903
+ pc: 96 / 72 / 12,
904
+ pt: 96 / 72,
905
+ px: 1
906
+ };
907
+ const unitsReg = new RegExp(
908
+ `^([0-9.]+(?:e\\d+)?)(${Object.keys(units).join("|")})?$`
909
+ );
910
+ function parseLength(len) {
911
+ const m = unitsReg.exec(len);
912
+ if (!m) {
913
+ return void 0;
914
+ }
915
+ return Math.round(Number(m[1]) * (units[m[2]] || 1));
916
+ }
917
+ function parseViewbox(viewbox) {
918
+ const bounds = viewbox.split(" ");
919
+ return {
920
+ height: parseLength(bounds[3]),
921
+ width: parseLength(bounds[2])
922
+ };
923
+ }
924
+ function parseAttributes(root) {
925
+ const width = extractorRegExps.width.exec(root);
926
+ const height = extractorRegExps.height.exec(root);
927
+ const viewbox = extractorRegExps.viewbox.exec(root);
928
+ return {
929
+ height: height && parseLength(height[2]),
930
+ viewbox: viewbox && parseViewbox(viewbox[2]),
931
+ width: width && parseLength(width[2])
932
+ };
933
+ }
934
+ function calculateByDimensions(attrs) {
935
+ return {
936
+ height: attrs.height,
937
+ width: attrs.width
938
+ };
939
+ }
940
+ function calculateByViewbox(attrs, viewbox) {
941
+ const ratio = viewbox.width / viewbox.height;
942
+ if (attrs.width) {
943
+ return {
944
+ height: Math.floor(attrs.width / ratio),
945
+ width: attrs.width
946
+ };
947
+ }
948
+ if (attrs.height) {
949
+ return {
950
+ height: attrs.height,
951
+ width: Math.floor(attrs.height * ratio)
952
+ };
953
+ }
954
+ return {
955
+ height: viewbox.height,
956
+ width: viewbox.width
957
+ };
958
+ }
959
+ const SVG = {
960
+ // Scan only the first kilo-byte to speed up the check on larger files
961
+ validate: (input) => svgReg.test(toUTF8String(input, 0, 1e3)),
962
+ calculate(input) {
963
+ const root = extractorRegExps.root.exec(toUTF8String(input));
964
+ if (root) {
965
+ const attrs = parseAttributes(root[0]);
966
+ if (attrs.width && attrs.height) {
967
+ return calculateByDimensions(attrs);
968
+ }
969
+ if (attrs.viewbox) {
970
+ return calculateByViewbox(attrs, attrs.viewbox);
971
+ }
972
+ }
973
+ throw new TypeError("Invalid SVG");
974
+ }
975
+ };
976
+
977
+ const TGA = {
978
+ validate(input) {
979
+ return readUInt16LE(input, 0) === 0 && readUInt16LE(input, 4) === 0;
980
+ },
981
+ calculate(input) {
982
+ return {
983
+ height: readUInt16LE(input, 14),
984
+ width: readUInt16LE(input, 12)
985
+ };
986
+ }
987
+ };
988
+
989
+ function readIFD(input, isBigEndian) {
990
+ const ifdOffset = readUInt(input, 32, 4, isBigEndian);
991
+ return input.slice(ifdOffset + 2);
992
+ }
993
+ function readValue(input, isBigEndian) {
994
+ const low = readUInt(input, 16, 8, isBigEndian);
995
+ const high = readUInt(input, 16, 10, isBigEndian);
996
+ return (high << 16) + low;
997
+ }
998
+ function nextTag(input) {
999
+ if (input.length > 24) {
1000
+ return input.slice(12);
1001
+ }
1002
+ }
1003
+ function extractTags(input, isBigEndian) {
1004
+ const tags = {};
1005
+ let temp = input;
1006
+ while (temp && temp.length) {
1007
+ const code = readUInt(temp, 16, 0, isBigEndian);
1008
+ const type = readUInt(temp, 16, 2, isBigEndian);
1009
+ const length = readUInt(temp, 32, 4, isBigEndian);
1010
+ if (code === 0) {
1011
+ break;
1012
+ } else {
1013
+ if (length === 1 && (type === 3 || type === 4)) {
1014
+ tags[code] = readValue(temp, isBigEndian);
1015
+ }
1016
+ temp = nextTag(temp);
1017
+ }
1018
+ }
1019
+ return tags;
1020
+ }
1021
+ function determineEndianness(input) {
1022
+ const signature = toUTF8String(input, 0, 2);
1023
+ if ("II" === signature) {
1024
+ return "LE";
1025
+ } else if ("MM" === signature) {
1026
+ return "BE";
1027
+ }
1028
+ }
1029
+ const signatures = [
1030
+ // '492049', // currently not supported
1031
+ "49492a00",
1032
+ // Little endian
1033
+ "4d4d002a"
1034
+ // Big Endian
1035
+ // '4d4d002a', // BigTIFF > 4GB. currently not supported
1036
+ ];
1037
+ const TIFF = {
1038
+ validate: (input) => signatures.includes(toHexString(input, 0, 4)),
1039
+ calculate(input) {
1040
+ const isBigEndian = determineEndianness(input) === "BE";
1041
+ const ifdBuffer = readIFD(input, isBigEndian);
1042
+ const tags = extractTags(ifdBuffer, isBigEndian);
1043
+ const width = tags[256];
1044
+ const height = tags[257];
1045
+ if (!width || !height) {
1046
+ throw new TypeError("Invalid Tiff. Missing tags");
1047
+ }
1048
+ return { height, width };
1049
+ }
1050
+ };
1051
+
1052
+ function calculateExtended(input) {
1053
+ return {
1054
+ height: 1 + readUInt24LE(input, 7),
1055
+ width: 1 + readUInt24LE(input, 4)
1056
+ };
1057
+ }
1058
+ function calculateLossless(input) {
1059
+ return {
1060
+ height: 1 + ((input[4] & 15) << 10 | input[3] << 2 | (input[2] & 192) >> 6),
1061
+ width: 1 + ((input[2] & 63) << 8 | input[1])
1062
+ };
1063
+ }
1064
+ function calculateLossy(input) {
1065
+ return {
1066
+ height: readInt16LE(input, 8) & 16383,
1067
+ width: readInt16LE(input, 6) & 16383
1068
+ };
1069
+ }
1070
+ const WEBP = {
1071
+ validate(input) {
1072
+ const riffHeader = "RIFF" === toUTF8String(input, 0, 4);
1073
+ const webpHeader = "WEBP" === toUTF8String(input, 8, 12);
1074
+ const vp8Header = "VP8" === toUTF8String(input, 12, 15);
1075
+ return riffHeader && webpHeader && vp8Header;
1076
+ },
1077
+ calculate(input) {
1078
+ const chunkHeader = toUTF8String(input, 12, 16);
1079
+ input = input.slice(20, 30);
1080
+ if (chunkHeader === "VP8X") {
1081
+ const extendedHeader = input[0];
1082
+ const validStart = (extendedHeader & 192) === 0;
1083
+ const validEnd = (extendedHeader & 1) === 0;
1084
+ if (validStart && validEnd) {
1085
+ return calculateExtended(input);
1086
+ } else {
1087
+ throw new TypeError("Invalid WebP");
1088
+ }
1089
+ }
1090
+ if (chunkHeader === "VP8 " && input[0] !== 47) {
1091
+ return calculateLossy(input);
1092
+ }
1093
+ const signature = toHexString(input, 3, 6);
1094
+ if (chunkHeader === "VP8L" && signature !== "9d012a") {
1095
+ return calculateLossless(input);
1096
+ }
1097
+ throw new TypeError("Invalid WebP");
1098
+ }
1099
+ };
1100
+
1101
+ const typeHandlers = /* @__PURE__ */ new Map([
1102
+ ["bmp", BMP],
1103
+ ["cur", CUR],
1104
+ ["dds", DDS],
1105
+ ["gif", GIF],
1106
+ ["heif", HEIF],
1107
+ ["icns", ICNS],
1108
+ ["ico", ICO],
1109
+ ["j2c", J2C],
1110
+ ["jp2", JP2],
1111
+ ["jpg", JPG],
1112
+ ["ktx", KTX],
1113
+ ["png", PNG],
1114
+ ["pnm", PNM],
1115
+ ["psd", PSD],
1116
+ ["svg", SVG],
1117
+ ["tga", TGA],
1118
+ ["tiff", TIFF],
1119
+ ["webp", WEBP]
1120
+ ]);
1121
+ const types = Array.from(typeHandlers.keys());
1122
+
1123
+ const firstBytes = /* @__PURE__ */ new Map([
1124
+ [56, "psd"],
1125
+ [66, "bmp"],
1126
+ [68, "dds"],
1127
+ [71, "gif"],
1128
+ [73, "tiff"],
1129
+ [77, "tiff"],
1130
+ [82, "webp"],
1131
+ [105, "icns"],
1132
+ [137, "png"],
1133
+ [255, "jpg"]
1134
+ ]);
1135
+ function detector(input) {
1136
+ const byte = input[0];
1137
+ const type = firstBytes.get(byte);
1138
+ if (type && typeHandlers.get(type).validate(input)) {
1139
+ return type;
1140
+ }
1141
+ return types.find((fileType) => typeHandlers.get(fileType).validate(input));
1142
+ }
1143
+
1144
+ function lookup(input) {
1145
+ const type = detector(input);
1146
+ if (typeof type !== "undefined") {
1147
+ const size = typeHandlers.get(type).calculate(input);
1148
+ if (size !== void 0) {
1149
+ size.type = size.type ?? type;
1150
+ return size;
1151
+ }
1152
+ }
1153
+ throw new TypeError("unsupported file type: " + type);
1154
+ }
1155
+
1156
+ async function imageMetadata(data, src) {
1157
+ let result;
1158
+ try {
1159
+ result = lookup(data);
1160
+ } catch {
1161
+ throw new AstroError({
1162
+ ...NoImageMetadata,
1163
+ message: NoImageMetadata.message(src)
1164
+ });
1165
+ }
1166
+ if (!result.height || !result.width || !result.type) {
1167
+ throw new AstroError({
1168
+ ...NoImageMetadata,
1169
+ message: NoImageMetadata.message(src)
1170
+ });
1171
+ }
1172
+ const { width, height, type, orientation } = result;
1173
+ const isPortrait = (orientation || 0) >= 5;
1174
+ return {
1175
+ width: isPortrait ? height : width,
1176
+ height: isPortrait ? width : height,
1177
+ format: type,
1178
+ orientation
1179
+ };
1180
+ }
1181
+
1182
+ async function inferRemoteSize(url) {
1183
+ const response = await fetch(url);
1184
+ if (!response.body || !response.ok) {
1185
+ throw new AstroError({
1186
+ ...FailedToFetchRemoteImageDimensions,
1187
+ message: FailedToFetchRemoteImageDimensions.message(url)
1188
+ });
1189
+ }
1190
+ const reader = response.body.getReader();
1191
+ let done, value;
1192
+ let accumulatedChunks = new Uint8Array();
1193
+ while (!done) {
1194
+ const readResult = await reader.read();
1195
+ done = readResult.done;
1196
+ if (done) break;
1197
+ if (readResult.value) {
1198
+ value = readResult.value;
1199
+ let tmp = new Uint8Array(accumulatedChunks.length + value.length);
1200
+ tmp.set(accumulatedChunks, 0);
1201
+ tmp.set(value, accumulatedChunks.length);
1202
+ accumulatedChunks = tmp;
1203
+ try {
1204
+ const dimensions = await imageMetadata(accumulatedChunks, url);
1205
+ if (dimensions) {
1206
+ await reader.cancel();
1207
+ return dimensions;
1208
+ }
1209
+ } catch {
1210
+ }
1211
+ }
1212
+ }
1213
+ throw new AstroError({
1214
+ ...NoImageMetadata,
1215
+ message: NoImageMetadata.message(url)
1216
+ });
1217
+ }
1218
+
1219
+ const PLACEHOLDER_BASE = "astro://placeholder";
1220
+ function createPlaceholderURL(pathOrUrl) {
1221
+ return new URL(pathOrUrl, PLACEHOLDER_BASE);
1222
+ }
1223
+ function stringifyPlaceholderURL(url) {
1224
+ return url.href.replace(PLACEHOLDER_BASE, "");
1225
+ }
1226
+
1227
+ async function getConfiguredImageService() {
1228
+ if (!globalThis?.astroAsset?.imageService) {
1229
+ const { default: service } = await import(
1230
+ // @ts-expect-error
1231
+ './sharp_DHNfMLYY.mjs'
1232
+ ).catch((e) => {
1233
+ const error = new AstroError(InvalidImageService);
1234
+ error.cause = e;
1235
+ throw error;
1236
+ });
1237
+ if (!globalThis.astroAsset) globalThis.astroAsset = {};
1238
+ globalThis.astroAsset.imageService = service;
1239
+ return service;
1240
+ }
1241
+ return globalThis.astroAsset.imageService;
1242
+ }
1243
+ async function getImage$1(options, imageConfig) {
1244
+ if (!options || typeof options !== "object") {
1245
+ throw new AstroError({
1246
+ ...ExpectedImageOptions,
1247
+ message: ExpectedImageOptions.message(JSON.stringify(options))
1248
+ });
1249
+ }
1250
+ if (typeof options.src === "undefined") {
1251
+ throw new AstroError({
1252
+ ...ExpectedImage,
1253
+ message: ExpectedImage.message(
1254
+ options.src,
1255
+ "undefined",
1256
+ JSON.stringify(options)
1257
+ )
1258
+ });
1259
+ }
1260
+ if (isImageMetadata(options)) {
1261
+ throw new AstroError(ExpectedNotESMImage);
1262
+ }
1263
+ const service = await getConfiguredImageService();
1264
+ const resolvedOptions = {
1265
+ ...options,
1266
+ src: await resolveSrc(options.src)
1267
+ };
1268
+ let originalWidth;
1269
+ let originalHeight;
1270
+ if (options.inferSize && isRemoteImage(resolvedOptions.src) && isRemotePath(resolvedOptions.src)) {
1271
+ const result = await inferRemoteSize(resolvedOptions.src);
1272
+ resolvedOptions.width ??= result.width;
1273
+ resolvedOptions.height ??= result.height;
1274
+ originalWidth = result.width;
1275
+ originalHeight = result.height;
1276
+ delete resolvedOptions.inferSize;
1277
+ }
1278
+ const originalFilePath = isESMImportedImage(resolvedOptions.src) ? resolvedOptions.src.fsPath : void 0;
1279
+ const clonedSrc = isESMImportedImage(resolvedOptions.src) ? (
1280
+ // @ts-expect-error - clone is a private, hidden prop
1281
+ resolvedOptions.src.clone ?? resolvedOptions.src
1282
+ ) : resolvedOptions.src;
1283
+ if (isESMImportedImage(clonedSrc)) {
1284
+ originalWidth = clonedSrc.width;
1285
+ originalHeight = clonedSrc.height;
1286
+ }
1287
+ if (originalWidth && originalHeight) {
1288
+ const aspectRatio = originalWidth / originalHeight;
1289
+ if (resolvedOptions.height && !resolvedOptions.width) {
1290
+ resolvedOptions.width = Math.round(resolvedOptions.height * aspectRatio);
1291
+ } else if (resolvedOptions.width && !resolvedOptions.height) {
1292
+ resolvedOptions.height = Math.round(resolvedOptions.width / aspectRatio);
1293
+ } else if (!resolvedOptions.width && !resolvedOptions.height) {
1294
+ resolvedOptions.width = originalWidth;
1295
+ resolvedOptions.height = originalHeight;
1296
+ }
1297
+ }
1298
+ resolvedOptions.src = clonedSrc;
1299
+ const layout = options.layout ?? imageConfig.layout ?? "none";
1300
+ if (resolvedOptions.priority) {
1301
+ resolvedOptions.loading ??= "eager";
1302
+ resolvedOptions.decoding ??= "sync";
1303
+ resolvedOptions.fetchpriority ??= "high";
1304
+ delete resolvedOptions.priority;
1305
+ } else {
1306
+ resolvedOptions.loading ??= "lazy";
1307
+ resolvedOptions.decoding ??= "async";
1308
+ resolvedOptions.fetchpriority ??= "auto";
1309
+ }
1310
+ if (layout !== "none") {
1311
+ resolvedOptions.widths ||= getWidths({
1312
+ width: resolvedOptions.width,
1313
+ layout,
1314
+ originalWidth,
1315
+ breakpoints: imageConfig.breakpoints?.length ? imageConfig.breakpoints : isLocalService(service) ? LIMITED_RESOLUTIONS : DEFAULT_RESOLUTIONS
1316
+ });
1317
+ resolvedOptions.sizes ||= getSizesAttribute({ width: resolvedOptions.width, layout });
1318
+ delete resolvedOptions.densities;
1319
+ resolvedOptions.style = addCSSVarsToStyle(
1320
+ {
1321
+ fit: cssFitValues.includes(resolvedOptions.fit ?? "") && resolvedOptions.fit,
1322
+ pos: resolvedOptions.position
1323
+ },
1324
+ resolvedOptions.style
1325
+ );
1326
+ resolvedOptions["data-astro-image"] = layout;
1327
+ }
1328
+ const validatedOptions = service.validateOptions ? await service.validateOptions(resolvedOptions, imageConfig) : resolvedOptions;
1329
+ const srcSetTransforms = service.getSrcSet ? await service.getSrcSet(validatedOptions, imageConfig) : [];
1330
+ let imageURL = await service.getURL(validatedOptions, imageConfig);
1331
+ const matchesValidatedTransform = (transform) => transform.width === validatedOptions.width && transform.height === validatedOptions.height && transform.format === validatedOptions.format;
1332
+ let srcSets = await Promise.all(
1333
+ srcSetTransforms.map(async (srcSet) => {
1334
+ return {
1335
+ transform: srcSet.transform,
1336
+ url: matchesValidatedTransform(srcSet.transform) ? imageURL : await service.getURL(srcSet.transform, imageConfig),
1337
+ descriptor: srcSet.descriptor,
1338
+ attributes: srcSet.attributes
1339
+ };
1340
+ })
1341
+ );
1342
+ if (isLocalService(service) && globalThis.astroAsset.addStaticImage && !(isRemoteImage(validatedOptions.src) && imageURL === validatedOptions.src)) {
1343
+ const propsToHash = service.propertiesToHash ?? DEFAULT_HASH_PROPS;
1344
+ imageURL = globalThis.astroAsset.addStaticImage(
1345
+ validatedOptions,
1346
+ propsToHash,
1347
+ originalFilePath
1348
+ );
1349
+ srcSets = srcSetTransforms.map((srcSet) => {
1350
+ return {
1351
+ transform: srcSet.transform,
1352
+ url: matchesValidatedTransform(srcSet.transform) ? imageURL : globalThis.astroAsset.addStaticImage(srcSet.transform, propsToHash, originalFilePath),
1353
+ descriptor: srcSet.descriptor,
1354
+ attributes: srcSet.attributes
1355
+ };
1356
+ });
1357
+ } else if (imageConfig.assetQueryParams) {
1358
+ const imageURLObj = createPlaceholderURL(imageURL);
1359
+ imageConfig.assetQueryParams.forEach((value, key) => {
1360
+ imageURLObj.searchParams.set(key, value);
1361
+ });
1362
+ imageURL = stringifyPlaceholderURL(imageURLObj);
1363
+ srcSets = srcSets.map((srcSet) => {
1364
+ const urlObj = createPlaceholderURL(srcSet.url);
1365
+ imageConfig.assetQueryParams.forEach((value, key) => {
1366
+ urlObj.searchParams.set(key, value);
1367
+ });
1368
+ return {
1369
+ ...srcSet,
1370
+ url: stringifyPlaceholderURL(urlObj)
1371
+ };
1372
+ });
1373
+ }
1374
+ return {
1375
+ rawOptions: resolvedOptions,
1376
+ options: validatedOptions,
1377
+ src: imageURL,
1378
+ srcSet: {
1379
+ values: srcSets,
1380
+ attribute: srcSets.map((srcSet) => `${srcSet.url} ${srcSet.descriptor}`).join(", ")
1381
+ },
1382
+ attributes: service.getHTMLAttributes !== void 0 ? await service.getHTMLAttributes(validatedOptions, imageConfig) : {}
1383
+ };
1384
+ }
1385
+
1386
+ const $$Astro$2 = createAstro();
1387
+ const $$Image = createComponent(async ($$result, $$props, $$slots) => {
1388
+ const Astro2 = $$result.createAstro($$Astro$2, $$props, $$slots);
1389
+ Astro2.self = $$Image;
1390
+ const props = Astro2.props;
1391
+ if (props.alt === void 0 || props.alt === null) {
1392
+ throw new AstroError(ImageMissingAlt);
1393
+ }
1394
+ if (typeof props.width === "string") {
1395
+ props.width = parseInt(props.width);
1396
+ }
1397
+ if (typeof props.height === "string") {
1398
+ props.height = parseInt(props.height);
1399
+ }
1400
+ const layout = props.layout ?? imageConfig.layout ?? "none";
1401
+ if (layout !== "none") {
1402
+ props.layout ??= imageConfig.layout;
1403
+ props.fit ??= imageConfig.objectFit ?? "cover";
1404
+ props.position ??= imageConfig.objectPosition ?? "center";
1405
+ }
1406
+ const image = await getImage(props);
1407
+ const additionalAttributes = {};
1408
+ if (image.srcSet.values.length > 0) {
1409
+ additionalAttributes.srcset = image.srcSet.attribute;
1410
+ }
1411
+ const { class: className, ...attributes } = { ...additionalAttributes, ...image.attributes };
1412
+ return renderTemplate`${maybeRenderHead()}<img${addAttribute(image.src, "src")}${spreadAttributes(attributes)}${addAttribute(className, "class")}>`;
1413
+ }, "/Users/wadakatu/www/experiments/screenbook/node_modules/.pnpm/astro@5.16.6_@types+node@25.0.3_jiti@2.6.1_lightningcss@1.30.2_rollup@4.54.0_typescript@5.9.3/node_modules/astro/components/Image.astro", void 0);
1414
+
1415
+ const $$Astro$1 = createAstro();
1416
+ const $$Picture = createComponent(async ($$result, $$props, $$slots) => {
1417
+ const Astro2 = $$result.createAstro($$Astro$1, $$props, $$slots);
1418
+ Astro2.self = $$Picture;
1419
+ const defaultFormats = ["webp"];
1420
+ const defaultFallbackFormat = "png";
1421
+ const specialFormatsFallback = ["gif", "svg", "jpg", "jpeg"];
1422
+ const { formats = defaultFormats, pictureAttributes = {}, fallbackFormat, ...props } = Astro2.props;
1423
+ if (props.alt === void 0 || props.alt === null) {
1424
+ throw new AstroError(ImageMissingAlt);
1425
+ }
1426
+ const scopedStyleClass = props.class?.match(/\bastro-\w{8}\b/)?.[0];
1427
+ if (scopedStyleClass) {
1428
+ if (pictureAttributes.class) {
1429
+ pictureAttributes.class = `${pictureAttributes.class} ${scopedStyleClass}`;
1430
+ } else {
1431
+ pictureAttributes.class = scopedStyleClass;
1432
+ }
1433
+ }
1434
+ const layout = props.layout ?? imageConfig.layout ?? "none";
1435
+ const useResponsive = layout !== "none";
1436
+ if (useResponsive) {
1437
+ props.layout ??= imageConfig.layout;
1438
+ props.fit ??= imageConfig.objectFit ?? "cover";
1439
+ props.position ??= imageConfig.objectPosition ?? "center";
1440
+ }
1441
+ for (const key in props) {
1442
+ if (key.startsWith("data-astro-cid")) {
1443
+ pictureAttributes[key] = props[key];
1444
+ }
1445
+ }
1446
+ const originalSrc = await resolveSrc(props.src);
1447
+ const optimizedImages = await Promise.all(
1448
+ formats.map(
1449
+ async (format) => await getImage({
1450
+ ...props,
1451
+ src: originalSrc,
1452
+ format,
1453
+ widths: props.widths,
1454
+ densities: props.densities
1455
+ })
1456
+ )
1457
+ );
1458
+ let resultFallbackFormat = fallbackFormat ?? defaultFallbackFormat;
1459
+ if (!fallbackFormat && isESMImportedImage(originalSrc) && specialFormatsFallback.includes(originalSrc.format)) {
1460
+ resultFallbackFormat = originalSrc.format;
1461
+ }
1462
+ const fallbackImage = await getImage({
1463
+ ...props,
1464
+ format: resultFallbackFormat,
1465
+ widths: props.widths,
1466
+ densities: props.densities
1467
+ });
1468
+ const imgAdditionalAttributes = {};
1469
+ const sourceAdditionalAttributes = {};
1470
+ if (props.sizes) {
1471
+ sourceAdditionalAttributes.sizes = props.sizes;
1472
+ }
1473
+ if (fallbackImage.srcSet.values.length > 0) {
1474
+ imgAdditionalAttributes.srcset = fallbackImage.srcSet.attribute;
1475
+ }
1476
+ const { class: className, ...attributes } = {
1477
+ ...imgAdditionalAttributes,
1478
+ ...fallbackImage.attributes
1479
+ };
1480
+ return renderTemplate`${maybeRenderHead()}<picture${spreadAttributes(pictureAttributes)}> ${Object.entries(optimizedImages).map(([_, image]) => {
1481
+ const srcsetAttribute = props.densities || !props.densities && !props.widths && !useResponsive ? `${image.src}${image.srcSet.values.length > 0 ? ", " + image.srcSet.attribute : ""}` : image.srcSet.attribute;
1482
+ return renderTemplate`<source${addAttribute(srcsetAttribute, "srcset")}${addAttribute(mime.lookup(image.options.format ?? image.src) ?? `image/${image.options.format}`, "type")}${spreadAttributes(sourceAdditionalAttributes)}>`;
1483
+ })} <img${addAttribute(fallbackImage.src, "src")}${spreadAttributes(attributes)}${addAttribute(className, "class")}> </picture>`;
1484
+ }, "/Users/wadakatu/www/experiments/screenbook/node_modules/.pnpm/astro@5.16.6_@types+node@25.0.3_jiti@2.6.1_lightningcss@1.30.2_rollup@4.54.0_typescript@5.9.3/node_modules/astro/components/Picture.astro", void 0);
1485
+
1486
+ const fontsMod = /*#__PURE__*/Object.freeze(/*#__PURE__*/Object.defineProperty({
1487
+ __proto__: null
1488
+ }, Symbol.toStringTag, { value: 'Module' }));
1489
+
1490
+ function filterPreloads(data, preload) {
1491
+ if (!preload) {
1492
+ return null;
1493
+ }
1494
+ if (preload === true) {
1495
+ return data;
1496
+ }
1497
+ return data.filter(
1498
+ ({ weight, style, subset }) => preload.some((p) => {
1499
+ if (p.weight !== void 0 && weight !== void 0 && !checkWeight(p.weight.toString(), weight)) {
1500
+ return false;
1501
+ }
1502
+ if (p.style !== void 0 && p.style !== style) {
1503
+ return false;
1504
+ }
1505
+ if (p.subset !== void 0 && p.subset !== subset) {
1506
+ return false;
1507
+ }
1508
+ return true;
1509
+ })
1510
+ );
1511
+ }
1512
+ function checkWeight(input, target) {
1513
+ const trimmedInput = input.trim();
1514
+ if (trimmedInput.includes(" ")) {
1515
+ return trimmedInput === target;
1516
+ }
1517
+ if (target.includes(" ")) {
1518
+ const [a, b] = target.split(" ");
1519
+ const parsedInput = Number.parseInt(input);
1520
+ return parsedInput >= Number.parseInt(a) && parsedInput <= Number.parseInt(b);
1521
+ }
1522
+ return input === target;
1523
+ }
1524
+
1525
+ const $$Astro = createAstro();
1526
+ const $$Font = createComponent(($$result, $$props, $$slots) => {
1527
+ const Astro2 = $$result.createAstro($$Astro, $$props, $$slots);
1528
+ Astro2.self = $$Font;
1529
+ const { internalConsumableMap } = fontsMod;
1530
+ if (!internalConsumableMap) {
1531
+ throw new AstroError(ExperimentalFontsNotEnabled);
1532
+ }
1533
+ const { cssVariable, preload = false } = Astro2.props;
1534
+ const data = internalConsumableMap.get(cssVariable);
1535
+ if (!data) {
1536
+ throw new AstroError({
1537
+ ...FontFamilyNotFound,
1538
+ message: FontFamilyNotFound.message(cssVariable)
1539
+ });
1540
+ }
1541
+ const filteredPreloadData = filterPreloads(data.preloadData, preload);
1542
+ return renderTemplate`<style>${unescapeHTML(data.css)}</style>${filteredPreloadData?.map(({ url, type }) => renderTemplate`<link rel="preload"${addAttribute(url, "href")} as="font"${addAttribute(`font/${type}`, "type")} crossorigin>`)}`;
1543
+ }, "/Users/wadakatu/www/experiments/screenbook/node_modules/.pnpm/astro@5.16.6_@types+node@25.0.3_jiti@2.6.1_lightningcss@1.30.2_rollup@4.54.0_typescript@5.9.3/node_modules/astro/components/Font.astro", void 0);
1544
+
1545
+ const assetQueryParams = undefined;
1546
+ const imageConfig = {"endpoint":{"route":"/_image","entrypoint":"astro/assets/endpoint/node"},"service":{"entrypoint":"astro/assets/services/sharp","config":{}},"domains":[],"remotePatterns":[],"responsiveStyles":false};
1547
+ Object.defineProperty(imageConfig, 'assetQueryParams', {
1548
+ value: assetQueryParams,
1549
+ enumerable: false,
1550
+ configurable: true,
1551
+ });
1552
+ // This is used by the @astrojs/node integration to locate images.
1553
+ // It's unused on other platforms, but on some platforms like Netlify (and presumably also Vercel)
1554
+ // new URL("dist/...") is interpreted by the bundler as a signal to include that directory
1555
+ // in the Lambda bundle, which would bloat the bundle with images.
1556
+ // To prevent this, we mark the URL construction as pure,
1557
+ // so that it's tree-shaken away for all platforms that don't need it.
1558
+ const outDir = /* #__PURE__ */ new URL("file:///Users/wadakatu/www/experiments/screenbook/packages/ui/dist/client/");
1559
+ const getImage = async (options) => await getImage$1(options, imageConfig);
1560
+
1561
+ const fnv1a52 = (str) => {
1562
+ const len = str.length;
1563
+ let i = 0, t0 = 0, v0 = 8997, t1 = 0, v1 = 33826, t2 = 0, v2 = 40164, t3 = 0, v3 = 52210;
1564
+ while (i < len) {
1565
+ v0 ^= str.charCodeAt(i++);
1566
+ t0 = v0 * 435;
1567
+ t1 = v1 * 435;
1568
+ t2 = v2 * 435;
1569
+ t3 = v3 * 435;
1570
+ t2 += v0 << 8;
1571
+ t3 += v1 << 8;
1572
+ t1 += t0 >>> 16;
1573
+ v0 = t0 & 65535;
1574
+ t2 += t1 >>> 16;
1575
+ v1 = t1 & 65535;
1576
+ v3 = t3 + (t2 >>> 16) & 65535;
1577
+ v2 = t2 & 65535;
1578
+ }
1579
+ return (v3 & 15) * 281474976710656 + v2 * 4294967296 + v1 * 65536 + (v0 ^ v3 >> 4);
1580
+ };
1581
+ const etag = (payload, weak = false) => {
1582
+ const prefix = weak ? 'W/"' : '"';
1583
+ return prefix + fnv1a52(payload).toString(36) + payload.length.toString(36) + '"';
1584
+ };
1585
+
1586
+ async function loadRemoteImage(src) {
1587
+ try {
1588
+ const res = await fetch(src);
1589
+ if (!res.ok) {
1590
+ return void 0;
1591
+ }
1592
+ return Buffer.from(await res.arrayBuffer());
1593
+ } catch {
1594
+ return void 0;
1595
+ }
1596
+ }
1597
+ const handleImageRequest = async ({
1598
+ request,
1599
+ loadLocalImage
1600
+ }) => {
1601
+ const imageService = await getConfiguredImageService();
1602
+ if (!("transform" in imageService)) {
1603
+ throw new Error("Configured image service is not a local service");
1604
+ }
1605
+ const url = new URL(request.url);
1606
+ const transform = await imageService.parseURL(url, imageConfig);
1607
+ if (!transform?.src) {
1608
+ return new Response("Invalid request", { status: 400 });
1609
+ }
1610
+ let inputBuffer = void 0;
1611
+ if (isRemotePath(transform.src)) {
1612
+ if (!isRemoteAllowed(transform.src, imageConfig)) {
1613
+ return new Response("Forbidden", { status: 403 });
1614
+ }
1615
+ inputBuffer = await loadRemoteImage(new URL(transform.src));
1616
+ } else {
1617
+ inputBuffer = await loadLocalImage(removeQueryString(transform.src), url);
1618
+ }
1619
+ if (!inputBuffer) {
1620
+ return new Response("Internal Server Error", { status: 500 });
1621
+ }
1622
+ const { data, format } = await imageService.transform(inputBuffer, transform, imageConfig);
1623
+ return new Response(data, {
1624
+ status: 200,
1625
+ headers: {
1626
+ "Content-Type": mime.lookup(format) ?? `image/${format}`,
1627
+ "Cache-Control": "public, max-age=31536000",
1628
+ ETag: etag(data.toString()),
1629
+ Date: (/* @__PURE__ */ new Date()).toUTCString()
1630
+ }
1631
+ });
1632
+ };
1633
+
1634
+ async function loadLocalImage(src, url) {
1635
+ const idx = url.pathname.indexOf("/_image");
1636
+ if (idx > 0) {
1637
+ src = src.slice(idx);
1638
+ }
1639
+ if (!URL.canParse("." + src, outDir)) {
1640
+ return void 0;
1641
+ }
1642
+ const fileUrl = new URL("." + src, outDir);
1643
+ if (fileUrl.protocol !== "file:") {
1644
+ return void 0;
1645
+ }
1646
+ if (!isParentDirectory(fileURLToPath(outDir), fileURLToPath(fileUrl))) {
1647
+ return void 0;
1648
+ }
1649
+ try {
1650
+ return await readFile(fileUrl);
1651
+ } catch {
1652
+ return void 0;
1653
+ }
1654
+ }
1655
+ const GET = async ({ request }) => {
1656
+ try {
1657
+ return await handleImageRequest({ request, loadLocalImage });
1658
+ } catch (err) {
1659
+ console.error("Could not process image request:", err);
1660
+ return new Response("Internal Server Error", {
1661
+ status: 500
1662
+ });
1663
+ }
1664
+ };
1665
+
1666
+ const _page = /*#__PURE__*/Object.freeze(/*#__PURE__*/Object.defineProperty({
1667
+ __proto__: null,
1668
+ GET
1669
+ }, Symbol.toStringTag, { value: 'Module' }));
1670
+
1671
+ const page = () => _page;
1672
+
1673
+ export { page as a, baseService as b, parseQuality as p };