pdfequips-footer 0.1.11 → 0.1.13

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.
@@ -0,0 +1,1830 @@
1
+ import 'piccolore';
2
+ import { escape } from 'html-escaper';
3
+ import { clsx } from 'clsx';
4
+ import { decodeBase64, encodeBase64, encodeHexUpperCase } from '@oslojs/encoding';
5
+ import { z } from 'zod';
6
+ import 'cssesc';
7
+
8
+ function normalizeLF(code) {
9
+ return code.replace(/\r\n|\r(?!\n)|\n/g, "\n");
10
+ }
11
+
12
+ function codeFrame(src, loc) {
13
+ if (!loc || loc.line === void 0 || loc.column === void 0) {
14
+ return "";
15
+ }
16
+ const lines = normalizeLF(src).split("\n").map((ln) => ln.replace(/\t/g, " "));
17
+ const visibleLines = [];
18
+ for (let n = -2; n <= 2; n++) {
19
+ if (lines[loc.line + n]) visibleLines.push(loc.line + n);
20
+ }
21
+ let gutterWidth = 0;
22
+ for (const lineNo of visibleLines) {
23
+ let w = `> ${lineNo}`;
24
+ if (w.length > gutterWidth) gutterWidth = w.length;
25
+ }
26
+ let output = "";
27
+ for (const lineNo of visibleLines) {
28
+ const isFocusedLine = lineNo === loc.line - 1;
29
+ output += isFocusedLine ? "> " : " ";
30
+ output += `${lineNo + 1} | ${lines[lineNo]}
31
+ `;
32
+ if (isFocusedLine)
33
+ output += `${Array.from({ length: gutterWidth }).join(" ")} | ${Array.from({
34
+ length: loc.column
35
+ }).join(" ")}^
36
+ `;
37
+ }
38
+ return output;
39
+ }
40
+
41
+ class AstroError extends Error {
42
+ loc;
43
+ title;
44
+ hint;
45
+ frame;
46
+ type = "AstroError";
47
+ constructor(props, options) {
48
+ const { name, title, message, stack, location, hint, frame } = props;
49
+ super(message, options);
50
+ this.title = title;
51
+ this.name = name;
52
+ if (message) this.message = message;
53
+ this.stack = stack ? stack : this.stack;
54
+ this.loc = location;
55
+ this.hint = hint;
56
+ this.frame = frame;
57
+ }
58
+ setLocation(location) {
59
+ this.loc = location;
60
+ }
61
+ setName(name) {
62
+ this.name = name;
63
+ }
64
+ setMessage(message) {
65
+ this.message = message;
66
+ }
67
+ setHint(hint) {
68
+ this.hint = hint;
69
+ }
70
+ setFrame(source, location) {
71
+ this.frame = codeFrame(source, location);
72
+ }
73
+ static is(err) {
74
+ return err.type === "AstroError";
75
+ }
76
+ }
77
+
78
+ const MissingMediaQueryDirective = {
79
+ name: "MissingMediaQueryDirective",
80
+ title: "Missing value for `client:media` directive.",
81
+ message: 'Media query not provided for `client:media` directive. A media query similar to `client:media="(max-width: 600px)"` must be provided'
82
+ };
83
+ const NoMatchingRenderer = {
84
+ name: "NoMatchingRenderer",
85
+ title: "No matching renderer found.",
86
+ message: (componentName, componentExtension, plural, validRenderersCount) => `Unable to render \`${componentName}\`.
87
+
88
+ ${validRenderersCount > 0 ? `There ${plural ? "are" : "is"} ${validRenderersCount} renderer${plural ? "s" : ""} configured in your \`astro.config.mjs\` file,
89
+ but ${plural ? "none were" : "it was not"} able to server-side render \`${componentName}\`.` : `No valid renderer was found ${componentExtension ? `for the \`.${componentExtension}\` file extension.` : `for this file extension.`}`}`,
90
+ hint: (probableRenderers) => `Did you mean to enable the ${probableRenderers} integration?
91
+
92
+ See https://docs.astro.build/en/guides/framework-components/ for more information on how to install and configure integrations.`
93
+ };
94
+ const NoClientOnlyHint = {
95
+ name: "NoClientOnlyHint",
96
+ title: "Missing hint on client:only directive.",
97
+ message: (componentName) => `Unable to render \`${componentName}\`. When using the \`client:only\` hydration strategy, Astro needs a hint to use the correct renderer.`,
98
+ hint: (probableRenderers) => `Did you mean to pass \`client:only="${probableRenderers}"\`? See https://docs.astro.build/en/reference/directives-reference/#clientonly for more information on client:only`
99
+ };
100
+ const NoMatchingImport = {
101
+ name: "NoMatchingImport",
102
+ title: "No import found for component.",
103
+ message: (componentName) => `Could not render \`${componentName}\`. No matching import has been found for \`${componentName}\`.`,
104
+ hint: "Please make sure the component is properly imported."
105
+ };
106
+ const InvalidComponentArgs = {
107
+ name: "InvalidComponentArgs",
108
+ title: "Invalid component arguments.",
109
+ message: (name) => `Invalid arguments passed to${name ? ` <${name}>` : ""} component.`,
110
+ hint: "Astro components cannot be rendered directly via function call, such as `Component()` or `{items.map(Component)}`."
111
+ };
112
+ const AstroGlobUsedOutside = {
113
+ name: "AstroGlobUsedOutside",
114
+ title: "Astro.glob() used outside of an Astro file.",
115
+ message: (globStr) => `\`Astro.glob(${globStr})\` can only be used in \`.astro\` files. \`import.meta.glob(${globStr})\` can be used instead to achieve a similar result.`,
116
+ hint: "See Vite's documentation on `import.meta.glob` for more information: https://vite.dev/guide/features.html#glob-import"
117
+ };
118
+ const AstroGlobNoMatch = {
119
+ name: "AstroGlobNoMatch",
120
+ title: "Astro.glob() did not match any files.",
121
+ message: (globStr) => `\`Astro.glob(${globStr})\` did not return any matching files.`,
122
+ hint: "Check the pattern for typos."
123
+ };
124
+
125
+ function validateArgs(args) {
126
+ if (args.length !== 3) return false;
127
+ if (!args[0] || typeof args[0] !== "object") return false;
128
+ return true;
129
+ }
130
+ function baseCreateComponent(cb, moduleId, propagation) {
131
+ const name = moduleId?.split("/").pop()?.replace(".astro", "") ?? "";
132
+ const fn = (...args) => {
133
+ if (!validateArgs(args)) {
134
+ throw new AstroError({
135
+ ...InvalidComponentArgs,
136
+ message: InvalidComponentArgs.message(name)
137
+ });
138
+ }
139
+ return cb(...args);
140
+ };
141
+ Object.defineProperty(fn, "name", { value: name, writable: false });
142
+ fn.isAstroComponentFactory = true;
143
+ fn.moduleId = moduleId;
144
+ fn.propagation = propagation;
145
+ return fn;
146
+ }
147
+ function createComponentWithOptions(opts) {
148
+ const cb = baseCreateComponent(opts.factory, opts.moduleId, opts.propagation);
149
+ return cb;
150
+ }
151
+ function createComponent(arg1, moduleId, propagation) {
152
+ if (typeof arg1 === "function") {
153
+ return baseCreateComponent(arg1, moduleId, propagation);
154
+ } else {
155
+ return createComponentWithOptions(arg1);
156
+ }
157
+ }
158
+
159
+ const ASTRO_VERSION = "5.16.0";
160
+ const NOOP_MIDDLEWARE_HEADER = "X-Astro-Noop";
161
+
162
+ function createAstroGlobFn() {
163
+ const globHandler = (importMetaGlobResult) => {
164
+ console.warn(`Astro.glob is deprecated and will be removed in a future major version of Astro.
165
+ Use import.meta.glob instead: https://vitejs.dev/guide/features.html#glob-import`);
166
+ if (typeof importMetaGlobResult === "string") {
167
+ throw new AstroError({
168
+ ...AstroGlobUsedOutside,
169
+ message: AstroGlobUsedOutside.message(JSON.stringify(importMetaGlobResult))
170
+ });
171
+ }
172
+ let allEntries = [...Object.values(importMetaGlobResult)];
173
+ if (allEntries.length === 0) {
174
+ throw new AstroError({
175
+ ...AstroGlobNoMatch,
176
+ message: AstroGlobNoMatch.message(JSON.stringify(importMetaGlobResult))
177
+ });
178
+ }
179
+ return Promise.all(allEntries.map((fn) => fn()));
180
+ };
181
+ return globHandler;
182
+ }
183
+ function createAstro(site) {
184
+ return {
185
+ site: void 0,
186
+ generator: `Astro v${ASTRO_VERSION}`,
187
+ glob: createAstroGlobFn()
188
+ };
189
+ }
190
+
191
+ function isPromise(value) {
192
+ return !!value && typeof value === "object" && "then" in value && typeof value.then === "function";
193
+ }
194
+
195
+ const escapeHTML = escape;
196
+ class HTMLString extends String {
197
+ get [Symbol.toStringTag]() {
198
+ return "HTMLString";
199
+ }
200
+ }
201
+ const markHTMLString = (value) => {
202
+ if (value instanceof HTMLString) {
203
+ return value;
204
+ }
205
+ if (typeof value === "string") {
206
+ return new HTMLString(value);
207
+ }
208
+ return value;
209
+ };
210
+ function isHTMLString(value) {
211
+ return Object.prototype.toString.call(value) === "[object HTMLString]";
212
+ }
213
+
214
+ function isAstroComponentFactory(obj) {
215
+ return obj == null ? false : obj.isAstroComponentFactory === true;
216
+ }
217
+ function isAPropagatingComponent(result, factory) {
218
+ const hint = getPropagationHint(result, factory);
219
+ return hint === "in-tree" || hint === "self";
220
+ }
221
+ function getPropagationHint(result, factory) {
222
+ let hint = factory.propagation || "none";
223
+ if (factory.moduleId && result.componentMetadata.has(factory.moduleId) && hint === "none") {
224
+ hint = result.componentMetadata.get(factory.moduleId).propagation;
225
+ }
226
+ return hint;
227
+ }
228
+
229
+ const PROP_TYPE = {
230
+ Value: 0,
231
+ JSON: 1,
232
+ // Actually means Array
233
+ RegExp: 2,
234
+ Date: 3,
235
+ Map: 4,
236
+ Set: 5,
237
+ BigInt: 6,
238
+ URL: 7,
239
+ Uint8Array: 8,
240
+ Uint16Array: 9,
241
+ Uint32Array: 10,
242
+ Infinity: 11
243
+ };
244
+ function serializeArray(value, metadata = {}, parents = /* @__PURE__ */ new WeakSet()) {
245
+ if (parents.has(value)) {
246
+ throw new Error(`Cyclic reference detected while serializing props for <${metadata.displayName} client:${metadata.hydrate}>!
247
+
248
+ Cyclic references cannot be safely serialized for client-side usage. Please remove the cyclic reference.`);
249
+ }
250
+ parents.add(value);
251
+ const serialized = value.map((v) => {
252
+ return convertToSerializedForm(v, metadata, parents);
253
+ });
254
+ parents.delete(value);
255
+ return serialized;
256
+ }
257
+ function serializeObject(value, metadata = {}, parents = /* @__PURE__ */ new WeakSet()) {
258
+ if (parents.has(value)) {
259
+ throw new Error(`Cyclic reference detected while serializing props for <${metadata.displayName} client:${metadata.hydrate}>!
260
+
261
+ Cyclic references cannot be safely serialized for client-side usage. Please remove the cyclic reference.`);
262
+ }
263
+ parents.add(value);
264
+ const serialized = Object.fromEntries(
265
+ Object.entries(value).map(([k, v]) => {
266
+ return [k, convertToSerializedForm(v, metadata, parents)];
267
+ })
268
+ );
269
+ parents.delete(value);
270
+ return serialized;
271
+ }
272
+ function convertToSerializedForm(value, metadata = {}, parents = /* @__PURE__ */ new WeakSet()) {
273
+ const tag = Object.prototype.toString.call(value);
274
+ switch (tag) {
275
+ case "[object Date]": {
276
+ return [PROP_TYPE.Date, value.toISOString()];
277
+ }
278
+ case "[object RegExp]": {
279
+ return [PROP_TYPE.RegExp, value.source];
280
+ }
281
+ case "[object Map]": {
282
+ return [PROP_TYPE.Map, serializeArray(Array.from(value), metadata, parents)];
283
+ }
284
+ case "[object Set]": {
285
+ return [PROP_TYPE.Set, serializeArray(Array.from(value), metadata, parents)];
286
+ }
287
+ case "[object BigInt]": {
288
+ return [PROP_TYPE.BigInt, value.toString()];
289
+ }
290
+ case "[object URL]": {
291
+ return [PROP_TYPE.URL, value.toString()];
292
+ }
293
+ case "[object Array]": {
294
+ return [PROP_TYPE.JSON, serializeArray(value, metadata, parents)];
295
+ }
296
+ case "[object Uint8Array]": {
297
+ return [PROP_TYPE.Uint8Array, Array.from(value)];
298
+ }
299
+ case "[object Uint16Array]": {
300
+ return [PROP_TYPE.Uint16Array, Array.from(value)];
301
+ }
302
+ case "[object Uint32Array]": {
303
+ return [PROP_TYPE.Uint32Array, Array.from(value)];
304
+ }
305
+ default: {
306
+ if (value !== null && typeof value === "object") {
307
+ return [PROP_TYPE.Value, serializeObject(value, metadata, parents)];
308
+ }
309
+ if (value === Infinity) {
310
+ return [PROP_TYPE.Infinity, 1];
311
+ }
312
+ if (value === -Infinity) {
313
+ return [PROP_TYPE.Infinity, -1];
314
+ }
315
+ if (value === void 0) {
316
+ return [PROP_TYPE.Value];
317
+ }
318
+ return [PROP_TYPE.Value, value];
319
+ }
320
+ }
321
+ }
322
+ function serializeProps(props, metadata) {
323
+ const serialized = JSON.stringify(serializeObject(props, metadata));
324
+ return serialized;
325
+ }
326
+
327
+ const transitionDirectivesToCopyOnIsland = Object.freeze([
328
+ "data-astro-transition-scope",
329
+ "data-astro-transition-persist",
330
+ "data-astro-transition-persist-props"
331
+ ]);
332
+ function extractDirectives(inputProps, clientDirectives) {
333
+ let extracted = {
334
+ isPage: false,
335
+ hydration: null,
336
+ props: {},
337
+ propsWithoutTransitionAttributes: {}
338
+ };
339
+ for (const [key, value] of Object.entries(inputProps)) {
340
+ if (key.startsWith("server:")) {
341
+ if (key === "server:root") {
342
+ extracted.isPage = true;
343
+ }
344
+ }
345
+ if (key.startsWith("client:")) {
346
+ if (!extracted.hydration) {
347
+ extracted.hydration = {
348
+ directive: "",
349
+ value: "",
350
+ componentUrl: "",
351
+ componentExport: { value: "" }
352
+ };
353
+ }
354
+ switch (key) {
355
+ case "client:component-path": {
356
+ extracted.hydration.componentUrl = value;
357
+ break;
358
+ }
359
+ case "client:component-export": {
360
+ extracted.hydration.componentExport.value = value;
361
+ break;
362
+ }
363
+ // This is a special prop added to prove that the client hydration method
364
+ // was added statically.
365
+ case "client:component-hydration": {
366
+ break;
367
+ }
368
+ case "client:display-name": {
369
+ break;
370
+ }
371
+ default: {
372
+ extracted.hydration.directive = key.split(":")[1];
373
+ extracted.hydration.value = value;
374
+ if (!clientDirectives.has(extracted.hydration.directive)) {
375
+ const hydrationMethods = Array.from(clientDirectives.keys()).map((d) => `client:${d}`).join(", ");
376
+ throw new Error(
377
+ `Error: invalid hydration directive "${key}". Supported hydration methods: ${hydrationMethods}`
378
+ );
379
+ }
380
+ if (extracted.hydration.directive === "media" && typeof extracted.hydration.value !== "string") {
381
+ throw new AstroError(MissingMediaQueryDirective);
382
+ }
383
+ break;
384
+ }
385
+ }
386
+ } else {
387
+ extracted.props[key] = value;
388
+ if (!transitionDirectivesToCopyOnIsland.includes(key)) {
389
+ extracted.propsWithoutTransitionAttributes[key] = value;
390
+ }
391
+ }
392
+ }
393
+ for (const sym of Object.getOwnPropertySymbols(inputProps)) {
394
+ extracted.props[sym] = inputProps[sym];
395
+ extracted.propsWithoutTransitionAttributes[sym] = inputProps[sym];
396
+ }
397
+ return extracted;
398
+ }
399
+ async function generateHydrateScript(scriptOptions, metadata) {
400
+ const { renderer, result, astroId, props, attrs } = scriptOptions;
401
+ const { hydrate, componentUrl, componentExport } = metadata;
402
+ if (!componentExport.value) {
403
+ throw new AstroError({
404
+ ...NoMatchingImport,
405
+ message: NoMatchingImport.message(metadata.displayName)
406
+ });
407
+ }
408
+ const island = {
409
+ children: "",
410
+ props: {
411
+ // This is for HMR, probably can avoid it in prod
412
+ uid: astroId
413
+ }
414
+ };
415
+ if (attrs) {
416
+ for (const [key, value] of Object.entries(attrs)) {
417
+ island.props[key] = escapeHTML(value);
418
+ }
419
+ }
420
+ island.props["component-url"] = await result.resolve(decodeURI(componentUrl));
421
+ if (renderer.clientEntrypoint) {
422
+ island.props["component-export"] = componentExport.value;
423
+ island.props["renderer-url"] = await result.resolve(
424
+ decodeURI(renderer.clientEntrypoint.toString())
425
+ );
426
+ island.props["props"] = escapeHTML(serializeProps(props, metadata));
427
+ }
428
+ island.props["ssr"] = "";
429
+ island.props["client"] = hydrate;
430
+ let beforeHydrationUrl = await result.resolve("astro:scripts/before-hydration.js");
431
+ if (beforeHydrationUrl.length) {
432
+ island.props["before-hydration-url"] = beforeHydrationUrl;
433
+ }
434
+ island.props["opts"] = escapeHTML(
435
+ JSON.stringify({
436
+ name: metadata.displayName,
437
+ value: metadata.hydrateArgs || ""
438
+ })
439
+ );
440
+ transitionDirectivesToCopyOnIsland.forEach((name) => {
441
+ if (typeof props[name] !== "undefined") {
442
+ island.props[name] = props[name];
443
+ }
444
+ });
445
+ return island;
446
+ }
447
+
448
+ /**
449
+ * shortdash - https://github.com/bibig/node-shorthash
450
+ *
451
+ * @license
452
+ *
453
+ * (The MIT License)
454
+ *
455
+ * Copyright (c) 2013 Bibig <bibig@me.com>
456
+ *
457
+ * Permission is hereby granted, free of charge, to any person
458
+ * obtaining a copy of this software and associated documentation
459
+ * files (the "Software"), to deal in the Software without
460
+ * restriction, including without limitation the rights to use,
461
+ * copy, modify, merge, publish, distribute, sublicense, and/or sell
462
+ * copies of the Software, and to permit persons to whom the
463
+ * Software is furnished to do so, subject to the following
464
+ * conditions:
465
+ *
466
+ * The above copyright notice and this permission notice shall be
467
+ * included in all copies or substantial portions of the Software.
468
+ *
469
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
470
+ * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
471
+ * OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
472
+ * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
473
+ * HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
474
+ * WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
475
+ * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
476
+ * OTHER DEALINGS IN THE SOFTWARE.
477
+ */
478
+ const dictionary = "0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXY";
479
+ const binary = dictionary.length;
480
+ function bitwise(str) {
481
+ let hash = 0;
482
+ if (str.length === 0) return hash;
483
+ for (let i = 0; i < str.length; i++) {
484
+ const ch = str.charCodeAt(i);
485
+ hash = (hash << 5) - hash + ch;
486
+ hash = hash & hash;
487
+ }
488
+ return hash;
489
+ }
490
+ function shorthash(text) {
491
+ let num;
492
+ let result = "";
493
+ let integer = bitwise(text);
494
+ const sign = integer < 0 ? "Z" : "";
495
+ integer = Math.abs(integer);
496
+ while (integer >= binary) {
497
+ num = integer % binary;
498
+ integer = Math.floor(integer / binary);
499
+ result = dictionary[num] + result;
500
+ }
501
+ if (integer > 0) {
502
+ result = dictionary[integer] + result;
503
+ }
504
+ return sign + result;
505
+ }
506
+
507
+ const headAndContentSym = Symbol.for("astro.headAndContent");
508
+ function isHeadAndContent(obj) {
509
+ return typeof obj === "object" && obj !== null && !!obj[headAndContentSym];
510
+ }
511
+ function createThinHead() {
512
+ return {
513
+ [headAndContentSym]: true
514
+ };
515
+ }
516
+
517
+ var astro_island_prebuilt_default = `(()=>{var A=Object.defineProperty;var g=(i,o,a)=>o in i?A(i,o,{enumerable:!0,configurable:!0,writable:!0,value:a}):i[o]=a;var d=(i,o,a)=>g(i,typeof o!="symbol"?o+"":o,a);{let i={0:t=>m(t),1:t=>a(t),2:t=>new RegExp(t),3:t=>new Date(t),4:t=>new Map(a(t)),5:t=>new Set(a(t)),6:t=>BigInt(t),7:t=>new URL(t),8:t=>new Uint8Array(t),9:t=>new Uint16Array(t),10:t=>new Uint32Array(t),11:t=>1/0*t},o=t=>{let[l,e]=t;return l in i?i[l](e):void 0},a=t=>t.map(o),m=t=>typeof t!="object"||t===null?t:Object.fromEntries(Object.entries(t).map(([l,e])=>[l,o(e)]));class y extends HTMLElement{constructor(){super(...arguments);d(this,"Component");d(this,"hydrator");d(this,"hydrate",async()=>{var b;if(!this.hydrator||!this.isConnected)return;let e=(b=this.parentElement)==null?void 0:b.closest("astro-island[ssr]");if(e){e.addEventListener("astro:hydrate",this.hydrate,{once:!0});return}let c=this.querySelectorAll("astro-slot"),n={},h=this.querySelectorAll("template[data-astro-template]");for(let r of h){let s=r.closest(this.tagName);s!=null&&s.isSameNode(this)&&(n[r.getAttribute("data-astro-template")||"default"]=r.innerHTML,r.remove())}for(let r of c){let s=r.closest(this.tagName);s!=null&&s.isSameNode(this)&&(n[r.getAttribute("name")||"default"]=r.innerHTML)}let p;try{p=this.hasAttribute("props")?m(JSON.parse(this.getAttribute("props"))):{}}catch(r){let s=this.getAttribute("component-url")||"<unknown>",v=this.getAttribute("component-export");throw v&&(s+=\` (export \${v})\`),console.error(\`[hydrate] Error parsing props for component \${s}\`,this.getAttribute("props"),r),r}let u;await this.hydrator(this)(this.Component,p,n,{client:this.getAttribute("client")}),this.removeAttribute("ssr"),this.dispatchEvent(new CustomEvent("astro:hydrate"))});d(this,"unmount",()=>{this.isConnected||this.dispatchEvent(new CustomEvent("astro:unmount"))})}disconnectedCallback(){document.removeEventListener("astro:after-swap",this.unmount),document.addEventListener("astro:after-swap",this.unmount,{once:!0})}connectedCallback(){if(!this.hasAttribute("await-children")||document.readyState==="interactive"||document.readyState==="complete")this.childrenConnectedCallback();else{let e=()=>{document.removeEventListener("DOMContentLoaded",e),c.disconnect(),this.childrenConnectedCallback()},c=new MutationObserver(()=>{var n;((n=this.lastChild)==null?void 0:n.nodeType)===Node.COMMENT_NODE&&this.lastChild.nodeValue==="astro:end"&&(this.lastChild.remove(),e())});c.observe(this,{childList:!0}),document.addEventListener("DOMContentLoaded",e)}}async childrenConnectedCallback(){let e=this.getAttribute("before-hydration-url");e&&await import(e),this.start()}async start(){let e=JSON.parse(this.getAttribute("opts")),c=this.getAttribute("client");if(Astro[c]===void 0){window.addEventListener(\`astro:\${c}\`,()=>this.start(),{once:!0});return}try{await Astro[c](async()=>{let n=this.getAttribute("renderer-url"),[h,{default:p}]=await Promise.all([import(this.getAttribute("component-url")),n?import(n):()=>()=>{}]),u=this.getAttribute("component-export")||"default";if(!u.includes("."))this.Component=h[u];else{this.Component=h;for(let f of u.split("."))this.Component=this.Component[f]}return this.hydrator=p,this.hydrate},e,this)}catch(n){console.error(\`[astro-island] Error hydrating \${this.getAttribute("component-url")}\`,n)}}attributeChangedCallback(){this.hydrate()}}d(y,"observedAttributes",["props"]),customElements.get("astro-island")||customElements.define("astro-island",y)}})();`;
518
+
519
+ var astro_island_prebuilt_dev_default = `(()=>{var A=Object.defineProperty;var g=(i,o,a)=>o in i?A(i,o,{enumerable:!0,configurable:!0,writable:!0,value:a}):i[o]=a;var l=(i,o,a)=>g(i,typeof o!="symbol"?o+"":o,a);{let i={0:t=>y(t),1:t=>a(t),2:t=>new RegExp(t),3:t=>new Date(t),4:t=>new Map(a(t)),5:t=>new Set(a(t)),6:t=>BigInt(t),7:t=>new URL(t),8:t=>new Uint8Array(t),9:t=>new Uint16Array(t),10:t=>new Uint32Array(t),11:t=>1/0*t},o=t=>{let[h,e]=t;return h in i?i[h](e):void 0},a=t=>t.map(o),y=t=>typeof t!="object"||t===null?t:Object.fromEntries(Object.entries(t).map(([h,e])=>[h,o(e)]));class f extends HTMLElement{constructor(){super(...arguments);l(this,"Component");l(this,"hydrator");l(this,"hydrate",async()=>{var b;if(!this.hydrator||!this.isConnected)return;let e=(b=this.parentElement)==null?void 0:b.closest("astro-island[ssr]");if(e){e.addEventListener("astro:hydrate",this.hydrate,{once:!0});return}let c=this.querySelectorAll("astro-slot"),n={},p=this.querySelectorAll("template[data-astro-template]");for(let r of p){let s=r.closest(this.tagName);s!=null&&s.isSameNode(this)&&(n[r.getAttribute("data-astro-template")||"default"]=r.innerHTML,r.remove())}for(let r of c){let s=r.closest(this.tagName);s!=null&&s.isSameNode(this)&&(n[r.getAttribute("name")||"default"]=r.innerHTML)}let u;try{u=this.hasAttribute("props")?y(JSON.parse(this.getAttribute("props"))):{}}catch(r){let s=this.getAttribute("component-url")||"<unknown>",v=this.getAttribute("component-export");throw v&&(s+=\` (export \${v})\`),console.error(\`[hydrate] Error parsing props for component \${s}\`,this.getAttribute("props"),r),r}let d,m=this.hydrator(this);d=performance.now(),await m(this.Component,u,n,{client:this.getAttribute("client")}),d&&this.setAttribute("client-render-time",(performance.now()-d).toString()),this.removeAttribute("ssr"),this.dispatchEvent(new CustomEvent("astro:hydrate"))});l(this,"unmount",()=>{this.isConnected||this.dispatchEvent(new CustomEvent("astro:unmount"))})}disconnectedCallback(){document.removeEventListener("astro:after-swap",this.unmount),document.addEventListener("astro:after-swap",this.unmount,{once:!0})}connectedCallback(){if(!this.hasAttribute("await-children")||document.readyState==="interactive"||document.readyState==="complete")this.childrenConnectedCallback();else{let e=()=>{document.removeEventListener("DOMContentLoaded",e),c.disconnect(),this.childrenConnectedCallback()},c=new MutationObserver(()=>{var n;((n=this.lastChild)==null?void 0:n.nodeType)===Node.COMMENT_NODE&&this.lastChild.nodeValue==="astro:end"&&(this.lastChild.remove(),e())});c.observe(this,{childList:!0}),document.addEventListener("DOMContentLoaded",e)}}async childrenConnectedCallback(){let e=this.getAttribute("before-hydration-url");e&&await import(e),this.start()}async start(){let e=JSON.parse(this.getAttribute("opts")),c=this.getAttribute("client");if(Astro[c]===void 0){window.addEventListener(\`astro:\${c}\`,()=>this.start(),{once:!0});return}try{await Astro[c](async()=>{let n=this.getAttribute("renderer-url"),[p,{default:u}]=await Promise.all([import(this.getAttribute("component-url")),n?import(n):()=>()=>{}]),d=this.getAttribute("component-export")||"default";if(!d.includes("."))this.Component=p[d];else{this.Component=p;for(let m of d.split("."))this.Component=this.Component[m]}return this.hydrator=u,this.hydrate},e,this)}catch(n){console.error(\`[astro-island] Error hydrating \${this.getAttribute("component-url")}\`,n)}}attributeChangedCallback(){this.hydrate()}}l(f,"observedAttributes",["props"]),customElements.get("astro-island")||customElements.define("astro-island",f)}})();`;
520
+
521
+ const ISLAND_STYLES = "astro-island,astro-slot,astro-static-slot{display:contents}";
522
+
523
+ function determineIfNeedsHydrationScript(result) {
524
+ if (result._metadata.hasHydrationScript) {
525
+ return false;
526
+ }
527
+ return result._metadata.hasHydrationScript = true;
528
+ }
529
+ function determinesIfNeedsDirectiveScript(result, directive) {
530
+ if (result._metadata.hasDirectives.has(directive)) {
531
+ return false;
532
+ }
533
+ result._metadata.hasDirectives.add(directive);
534
+ return true;
535
+ }
536
+ function getDirectiveScriptText(result, directive) {
537
+ const clientDirectives = result.clientDirectives;
538
+ const clientDirective = clientDirectives.get(directive);
539
+ if (!clientDirective) {
540
+ throw new Error(`Unknown directive: ${directive}`);
541
+ }
542
+ return clientDirective;
543
+ }
544
+ function getPrescripts(result, type, directive) {
545
+ switch (type) {
546
+ case "both":
547
+ return `<style>${ISLAND_STYLES}</style><script>${getDirectiveScriptText(result, directive)}</script><script>${process.env.NODE_ENV === "development" ? astro_island_prebuilt_dev_default : astro_island_prebuilt_default}</script>`;
548
+ case "directive":
549
+ return `<script>${getDirectiveScriptText(result, directive)}</script>`;
550
+ }
551
+ }
552
+
553
+ function renderCspContent(result) {
554
+ const finalScriptHashes = /* @__PURE__ */ new Set();
555
+ const finalStyleHashes = /* @__PURE__ */ new Set();
556
+ for (const scriptHash of result.scriptHashes) {
557
+ finalScriptHashes.add(`'${scriptHash}'`);
558
+ }
559
+ for (const styleHash of result.styleHashes) {
560
+ finalStyleHashes.add(`'${styleHash}'`);
561
+ }
562
+ for (const styleHash of result._metadata.extraStyleHashes) {
563
+ finalStyleHashes.add(`'${styleHash}'`);
564
+ }
565
+ for (const scriptHash of result._metadata.extraScriptHashes) {
566
+ finalScriptHashes.add(`'${scriptHash}'`);
567
+ }
568
+ let directives;
569
+ if (result.directives.length > 0) {
570
+ directives = result.directives.join(";") + ";";
571
+ }
572
+ let scriptResources = "'self'";
573
+ if (result.scriptResources.length > 0) {
574
+ scriptResources = result.scriptResources.map((r) => `${r}`).join(" ");
575
+ }
576
+ let styleResources = "'self'";
577
+ if (result.styleResources.length > 0) {
578
+ styleResources = result.styleResources.map((r) => `${r}`).join(" ");
579
+ }
580
+ const strictDynamic = result.isStrictDynamic ? ` 'strict-dynamic'` : "";
581
+ const scriptSrc = `script-src ${scriptResources} ${Array.from(finalScriptHashes).join(" ")}${strictDynamic};`;
582
+ const styleSrc = `style-src ${styleResources} ${Array.from(finalStyleHashes).join(" ")};`;
583
+ return [directives, scriptSrc, styleSrc].filter(Boolean).join(" ");
584
+ }
585
+
586
+ const RenderInstructionSymbol = Symbol.for("astro:render");
587
+ function createRenderInstruction(instruction) {
588
+ return Object.defineProperty(instruction, RenderInstructionSymbol, {
589
+ value: true
590
+ });
591
+ }
592
+ function isRenderInstruction(chunk) {
593
+ return chunk && typeof chunk === "object" && chunk[RenderInstructionSymbol];
594
+ }
595
+
596
+ const voidElementNames = /^(area|base|br|col|command|embed|hr|img|input|keygen|link|meta|param|source|track|wbr)$/i;
597
+ const htmlBooleanAttributes = /^(?:allowfullscreen|async|autofocus|autoplay|checked|controls|default|defer|disabled|disablepictureinpicture|disableremoteplayback|formnovalidate|hidden|inert|loop|muted|nomodule|novalidate|open|playsinline|readonly|required|reversed|scoped|seamless|selected|itemscope)$/i;
598
+ const AMPERSAND_REGEX = /&/g;
599
+ const DOUBLE_QUOTE_REGEX = /"/g;
600
+ const STATIC_DIRECTIVES = /* @__PURE__ */ new Set(["set:html", "set:text"]);
601
+ const toIdent = (k) => k.trim().replace(/(?!^)\b\w|\s+|\W+/g, (match, index) => {
602
+ if (/\W/.test(match)) return "";
603
+ return index === 0 ? match : match.toUpperCase();
604
+ });
605
+ const toAttributeString = (value, shouldEscape = true) => shouldEscape ? String(value).replace(AMPERSAND_REGEX, "&#38;").replace(DOUBLE_QUOTE_REGEX, "&#34;") : value;
606
+ const kebab = (k) => k.toLowerCase() === k ? k : k.replace(/[A-Z]/g, (match) => `-${match.toLowerCase()}`);
607
+ const toStyleString = (obj) => Object.entries(obj).filter(([_, v]) => typeof v === "string" && v.trim() || typeof v === "number").map(([k, v]) => {
608
+ if (k[0] !== "-" && k[1] !== "-") return `${kebab(k)}:${v}`;
609
+ return `${k}:${v}`;
610
+ }).join(";");
611
+ function defineScriptVars(vars) {
612
+ let output = "";
613
+ for (const [key, value] of Object.entries(vars)) {
614
+ output += `const ${toIdent(key)} = ${JSON.stringify(value)?.replace(
615
+ /<\/script>/g,
616
+ "\\x3C/script>"
617
+ )};
618
+ `;
619
+ }
620
+ return markHTMLString(output);
621
+ }
622
+ function formatList(values) {
623
+ if (values.length === 1) {
624
+ return values[0];
625
+ }
626
+ return `${values.slice(0, -1).join(", ")} or ${values[values.length - 1]}`;
627
+ }
628
+ function isCustomElement(tagName) {
629
+ return tagName.includes("-");
630
+ }
631
+ function handleBooleanAttribute(key, value, shouldEscape, tagName) {
632
+ if (tagName && isCustomElement(tagName)) {
633
+ return markHTMLString(` ${key}="${toAttributeString(value, shouldEscape)}"`);
634
+ }
635
+ return markHTMLString(value ? ` ${key}` : "");
636
+ }
637
+ function addAttribute(value, key, shouldEscape = true, tagName = "") {
638
+ if (value == null) {
639
+ return "";
640
+ }
641
+ if (STATIC_DIRECTIVES.has(key)) {
642
+ console.warn(`[astro] The "${key}" directive cannot be applied dynamically at runtime. It will not be rendered as an attribute.
643
+
644
+ Make sure to use the static attribute syntax (\`${key}={value}\`) instead of the dynamic spread syntax (\`{...{ "${key}": value }}\`).`);
645
+ return "";
646
+ }
647
+ if (key === "class:list") {
648
+ const listValue = toAttributeString(clsx(value), shouldEscape);
649
+ if (listValue === "") {
650
+ return "";
651
+ }
652
+ return markHTMLString(` ${key.slice(0, -5)}="${listValue}"`);
653
+ }
654
+ if (key === "style" && !(value instanceof HTMLString)) {
655
+ if (Array.isArray(value) && value.length === 2) {
656
+ return markHTMLString(
657
+ ` ${key}="${toAttributeString(`${toStyleString(value[0])};${value[1]}`, shouldEscape)}"`
658
+ );
659
+ }
660
+ if (typeof value === "object") {
661
+ return markHTMLString(` ${key}="${toAttributeString(toStyleString(value), shouldEscape)}"`);
662
+ }
663
+ }
664
+ if (key === "className") {
665
+ return markHTMLString(` class="${toAttributeString(value, shouldEscape)}"`);
666
+ }
667
+ if (typeof value === "string" && value.includes("&") && isHttpUrl(value)) {
668
+ return markHTMLString(` ${key}="${toAttributeString(value, false)}"`);
669
+ }
670
+ if (htmlBooleanAttributes.test(key)) {
671
+ return handleBooleanAttribute(key, value, shouldEscape, tagName);
672
+ }
673
+ if (value === "") {
674
+ return markHTMLString(` ${key}`);
675
+ }
676
+ if (key === "popover" && typeof value === "boolean") {
677
+ return handleBooleanAttribute(key, value, shouldEscape, tagName);
678
+ }
679
+ if (key === "download" && typeof value === "boolean") {
680
+ return handleBooleanAttribute(key, value, shouldEscape, tagName);
681
+ }
682
+ return markHTMLString(` ${key}="${toAttributeString(value, shouldEscape)}"`);
683
+ }
684
+ function internalSpreadAttributes(values, shouldEscape = true, tagName) {
685
+ let output = "";
686
+ for (const [key, value] of Object.entries(values)) {
687
+ output += addAttribute(value, key, shouldEscape, tagName);
688
+ }
689
+ return markHTMLString(output);
690
+ }
691
+ function renderElement(name, { props: _props, children = "" }, shouldEscape = true) {
692
+ const { lang: _, "data-astro-id": astroId, "define:vars": defineVars, ...props } = _props;
693
+ if (defineVars) {
694
+ if (name === "style") {
695
+ delete props["is:global"];
696
+ delete props["is:scoped"];
697
+ }
698
+ if (name === "script") {
699
+ delete props.hoist;
700
+ children = defineScriptVars(defineVars) + "\n" + children;
701
+ }
702
+ }
703
+ if ((children == null || children == "") && voidElementNames.test(name)) {
704
+ return `<${name}${internalSpreadAttributes(props, shouldEscape, name)}>`;
705
+ }
706
+ return `<${name}${internalSpreadAttributes(props, shouldEscape, name)}>${children}</${name}>`;
707
+ }
708
+ const noop = () => {
709
+ };
710
+ class BufferedRenderer {
711
+ chunks = [];
712
+ renderPromise;
713
+ destination;
714
+ /**
715
+ * Determines whether buffer has been flushed
716
+ * to the final destination.
717
+ */
718
+ flushed = false;
719
+ constructor(destination, renderFunction) {
720
+ this.destination = destination;
721
+ this.renderPromise = renderFunction(this);
722
+ if (isPromise(this.renderPromise)) {
723
+ Promise.resolve(this.renderPromise).catch(noop);
724
+ }
725
+ }
726
+ write(chunk) {
727
+ if (this.flushed) {
728
+ this.destination.write(chunk);
729
+ } else {
730
+ this.chunks.push(chunk);
731
+ }
732
+ }
733
+ flush() {
734
+ if (this.flushed) {
735
+ throw new Error("The render buffer has already been flushed.");
736
+ }
737
+ this.flushed = true;
738
+ for (const chunk of this.chunks) {
739
+ this.destination.write(chunk);
740
+ }
741
+ return this.renderPromise;
742
+ }
743
+ }
744
+ function createBufferedRenderer(destination, renderFunction) {
745
+ return new BufferedRenderer(destination, renderFunction);
746
+ }
747
+ typeof process !== "undefined" && Object.prototype.toString.call(process) === "[object process]";
748
+ const VALID_PROTOCOLS = ["http:", "https:"];
749
+ function isHttpUrl(url) {
750
+ try {
751
+ const parsedUrl = new URL(url);
752
+ return VALID_PROTOCOLS.includes(parsedUrl.protocol);
753
+ } catch {
754
+ return false;
755
+ }
756
+ }
757
+
758
+ const uniqueElements = (item, index, all) => {
759
+ const props = JSON.stringify(item.props);
760
+ const children = item.children;
761
+ return index === all.findIndex((i) => JSON.stringify(i.props) === props && i.children == children);
762
+ };
763
+ function renderAllHeadContent(result) {
764
+ result._metadata.hasRenderedHead = true;
765
+ let content = "";
766
+ if (result.shouldInjectCspMetaTags && result.cspDestination === "meta") {
767
+ content += renderElement(
768
+ "meta",
769
+ {
770
+ props: {
771
+ "http-equiv": "content-security-policy",
772
+ content: renderCspContent(result)
773
+ },
774
+ children: ""
775
+ },
776
+ false
777
+ );
778
+ }
779
+ const styles = Array.from(result.styles).filter(uniqueElements).map(
780
+ (style) => style.props.rel === "stylesheet" ? renderElement("link", style) : renderElement("style", style)
781
+ );
782
+ result.styles.clear();
783
+ const scripts = Array.from(result.scripts).filter(uniqueElements).map((script) => {
784
+ if (result.userAssetsBase) {
785
+ script.props.src = (result.base === "/" ? "" : result.base) + result.userAssetsBase + script.props.src;
786
+ }
787
+ return renderElement("script", script, false);
788
+ });
789
+ const links = Array.from(result.links).filter(uniqueElements).map((link) => renderElement("link", link, false));
790
+ content += styles.join("\n") + links.join("\n") + scripts.join("\n");
791
+ if (result._metadata.extraHead.length > 0) {
792
+ for (const part of result._metadata.extraHead) {
793
+ content += part;
794
+ }
795
+ }
796
+ return markHTMLString(content);
797
+ }
798
+ function renderHead() {
799
+ return createRenderInstruction({ type: "head" });
800
+ }
801
+
802
+ const ALGORITHMS = {
803
+ "SHA-256": "sha256-",
804
+ "SHA-384": "sha384-",
805
+ "SHA-512": "sha512-"
806
+ };
807
+ const ALGORITHM_VALUES = Object.values(ALGORITHMS);
808
+ z.enum(Object.keys(ALGORITHMS)).optional().default("SHA-256");
809
+ z.custom((value) => {
810
+ if (typeof value !== "string") {
811
+ return false;
812
+ }
813
+ return ALGORITHM_VALUES.some((allowedValue) => {
814
+ return value.startsWith(allowedValue);
815
+ });
816
+ });
817
+ const ALLOWED_DIRECTIVES = [
818
+ "base-uri",
819
+ "child-src",
820
+ "connect-src",
821
+ "default-src",
822
+ "fenced-frame-src",
823
+ "font-src",
824
+ "form-action",
825
+ "frame-ancestors",
826
+ "frame-src",
827
+ "img-src",
828
+ "manifest-src",
829
+ "media-src",
830
+ "object-src",
831
+ "referrer",
832
+ "report-to",
833
+ "report-uri",
834
+ "require-trusted-types-for",
835
+ "sandbox",
836
+ "trusted-types",
837
+ "upgrade-insecure-requests",
838
+ "worker-src"
839
+ ];
840
+ z.custom((value) => {
841
+ if (typeof value !== "string") {
842
+ return false;
843
+ }
844
+ return ALLOWED_DIRECTIVES.some((allowedValue) => {
845
+ return value.startsWith(allowedValue);
846
+ });
847
+ });
848
+
849
+ const ALGORITHM = "AES-GCM";
850
+ async function decodeKey(encoded) {
851
+ const bytes = decodeBase64(encoded);
852
+ return crypto.subtle.importKey("raw", bytes.buffer, ALGORITHM, true, [
853
+ "encrypt",
854
+ "decrypt"
855
+ ]);
856
+ }
857
+ const encoder = new TextEncoder();
858
+ new TextDecoder();
859
+ const IV_LENGTH = 24;
860
+ async function encryptString(key, raw) {
861
+ const iv = crypto.getRandomValues(new Uint8Array(IV_LENGTH / 2));
862
+ const data = encoder.encode(raw);
863
+ const buffer = await crypto.subtle.encrypt(
864
+ {
865
+ name: ALGORITHM,
866
+ iv
867
+ },
868
+ key,
869
+ data
870
+ );
871
+ return encodeHexUpperCase(iv) + encodeBase64(new Uint8Array(buffer));
872
+ }
873
+ async function generateCspDigest(data, algorithm) {
874
+ const hashBuffer = await crypto.subtle.digest(algorithm, encoder.encode(data));
875
+ const hash = encodeBase64(new Uint8Array(hashBuffer));
876
+ return `${ALGORITHMS[algorithm]}${hash}`;
877
+ }
878
+
879
+ const renderTemplateResultSym = Symbol.for("astro.renderTemplateResult");
880
+ class RenderTemplateResult {
881
+ [renderTemplateResultSym] = true;
882
+ htmlParts;
883
+ expressions;
884
+ error;
885
+ constructor(htmlParts, expressions) {
886
+ this.htmlParts = htmlParts;
887
+ this.error = void 0;
888
+ this.expressions = expressions.map((expression) => {
889
+ if (isPromise(expression)) {
890
+ return Promise.resolve(expression).catch((err) => {
891
+ if (!this.error) {
892
+ this.error = err;
893
+ throw err;
894
+ }
895
+ });
896
+ }
897
+ return expression;
898
+ });
899
+ }
900
+ render(destination) {
901
+ const flushers = this.expressions.map((exp) => {
902
+ return createBufferedRenderer(destination, (bufferDestination) => {
903
+ if (exp || exp === 0) {
904
+ return renderChild(bufferDestination, exp);
905
+ }
906
+ });
907
+ });
908
+ let i = 0;
909
+ const iterate = () => {
910
+ while (i < this.htmlParts.length) {
911
+ const html = this.htmlParts[i];
912
+ const flusher = flushers[i];
913
+ i++;
914
+ if (html) {
915
+ destination.write(markHTMLString(html));
916
+ }
917
+ if (flusher) {
918
+ const result = flusher.flush();
919
+ if (isPromise(result)) {
920
+ return result.then(iterate);
921
+ }
922
+ }
923
+ }
924
+ };
925
+ return iterate();
926
+ }
927
+ }
928
+ function isRenderTemplateResult(obj) {
929
+ return typeof obj === "object" && obj !== null && !!obj[renderTemplateResultSym];
930
+ }
931
+ function renderTemplate(htmlParts, ...expressions) {
932
+ return new RenderTemplateResult(htmlParts, expressions);
933
+ }
934
+
935
+ const slotString = Symbol.for("astro:slot-string");
936
+ class SlotString extends HTMLString {
937
+ instructions;
938
+ [slotString];
939
+ constructor(content, instructions) {
940
+ super(content);
941
+ this.instructions = instructions;
942
+ this[slotString] = true;
943
+ }
944
+ }
945
+ function isSlotString(str) {
946
+ return !!str[slotString];
947
+ }
948
+ function renderSlot(result, slotted, fallback) {
949
+ return {
950
+ async render(destination) {
951
+ await renderChild(destination, typeof slotted === "function" ? slotted(result) : slotted);
952
+ }
953
+ };
954
+ }
955
+ async function renderSlotToString(result, slotted, fallback) {
956
+ let content = "";
957
+ let instructions = null;
958
+ const temporaryDestination = {
959
+ write(chunk) {
960
+ if (chunk instanceof SlotString) {
961
+ content += chunk;
962
+ if (chunk.instructions) {
963
+ instructions ??= [];
964
+ instructions.push(...chunk.instructions);
965
+ }
966
+ } else if (chunk instanceof Response) return;
967
+ else if (typeof chunk === "object" && "type" in chunk && typeof chunk.type === "string") {
968
+ if (instructions === null) {
969
+ instructions = [];
970
+ }
971
+ instructions.push(chunk);
972
+ } else {
973
+ content += chunkToString(result, chunk);
974
+ }
975
+ }
976
+ };
977
+ const renderInstance = renderSlot(result, slotted);
978
+ await renderInstance.render(temporaryDestination);
979
+ return markHTMLString(new SlotString(content, instructions));
980
+ }
981
+ async function renderSlots(result, slots = {}) {
982
+ let slotInstructions = null;
983
+ let children = {};
984
+ if (slots) {
985
+ await Promise.all(
986
+ Object.entries(slots).map(
987
+ ([key, value]) => renderSlotToString(result, value).then((output) => {
988
+ if (output.instructions) {
989
+ if (slotInstructions === null) {
990
+ slotInstructions = [];
991
+ }
992
+ slotInstructions.push(...output.instructions);
993
+ }
994
+ children[key] = output;
995
+ })
996
+ )
997
+ );
998
+ }
999
+ return { slotInstructions, children };
1000
+ }
1001
+
1002
+ const internalProps = /* @__PURE__ */ new Set([
1003
+ "server:component-path",
1004
+ "server:component-export",
1005
+ "server:component-directive",
1006
+ "server:defer"
1007
+ ]);
1008
+ function containsServerDirective(props) {
1009
+ return "server:component-directive" in props;
1010
+ }
1011
+ const SCRIPT_RE = /<\/script/giu;
1012
+ const COMMENT_RE = /<!--/gu;
1013
+ const SCRIPT_REPLACER = "<\\/script";
1014
+ const COMMENT_REPLACER = "\\u003C!--";
1015
+ function safeJsonStringify(obj) {
1016
+ return JSON.stringify(obj).replace(SCRIPT_RE, SCRIPT_REPLACER).replace(COMMENT_RE, COMMENT_REPLACER);
1017
+ }
1018
+ function createSearchParams(componentExport, encryptedProps, slots) {
1019
+ const params = new URLSearchParams();
1020
+ params.set("e", componentExport);
1021
+ params.set("p", encryptedProps);
1022
+ params.set("s", slots);
1023
+ return params;
1024
+ }
1025
+ function isWithinURLLimit(pathname, params) {
1026
+ const url = pathname + "?" + params.toString();
1027
+ const chars = url.length;
1028
+ return chars < 2048;
1029
+ }
1030
+ class ServerIslandComponent {
1031
+ result;
1032
+ props;
1033
+ slots;
1034
+ displayName;
1035
+ hostId;
1036
+ islandContent;
1037
+ componentPath;
1038
+ componentExport;
1039
+ componentId;
1040
+ constructor(result, props, slots, displayName) {
1041
+ this.result = result;
1042
+ this.props = props;
1043
+ this.slots = slots;
1044
+ this.displayName = displayName;
1045
+ }
1046
+ async init() {
1047
+ const content = await this.getIslandContent();
1048
+ if (this.result.cspDestination) {
1049
+ this.result._metadata.extraScriptHashes.push(
1050
+ await generateCspDigest(SERVER_ISLAND_REPLACER, this.result.cspAlgorithm)
1051
+ );
1052
+ const contentDigest = await generateCspDigest(content, this.result.cspAlgorithm);
1053
+ this.result._metadata.extraScriptHashes.push(contentDigest);
1054
+ }
1055
+ return createThinHead();
1056
+ }
1057
+ async render(destination) {
1058
+ const hostId = await this.getHostId();
1059
+ const islandContent = await this.getIslandContent();
1060
+ destination.write(createRenderInstruction({ type: "server-island-runtime" }));
1061
+ destination.write("<!--[if astro]>server-island-start<![endif]-->");
1062
+ for (const name in this.slots) {
1063
+ if (name === "fallback") {
1064
+ await renderChild(destination, this.slots.fallback(this.result));
1065
+ }
1066
+ }
1067
+ destination.write(
1068
+ `<script type="module" data-astro-rerun data-island-id="${hostId}">${islandContent}</script>`
1069
+ );
1070
+ }
1071
+ getComponentPath() {
1072
+ if (this.componentPath) {
1073
+ return this.componentPath;
1074
+ }
1075
+ const componentPath = this.props["server:component-path"];
1076
+ if (!componentPath) {
1077
+ throw new Error(`Could not find server component path`);
1078
+ }
1079
+ this.componentPath = componentPath;
1080
+ return componentPath;
1081
+ }
1082
+ getComponentExport() {
1083
+ if (this.componentExport) {
1084
+ return this.componentExport;
1085
+ }
1086
+ const componentExport = this.props["server:component-export"];
1087
+ if (!componentExport) {
1088
+ throw new Error(`Could not find server component export`);
1089
+ }
1090
+ this.componentExport = componentExport;
1091
+ return componentExport;
1092
+ }
1093
+ async getHostId() {
1094
+ if (!this.hostId) {
1095
+ this.hostId = await crypto.randomUUID();
1096
+ }
1097
+ return this.hostId;
1098
+ }
1099
+ async getIslandContent() {
1100
+ if (this.islandContent) {
1101
+ return this.islandContent;
1102
+ }
1103
+ const componentPath = this.getComponentPath();
1104
+ const componentExport = this.getComponentExport();
1105
+ const componentId = this.result.serverIslandNameMap.get(componentPath);
1106
+ if (!componentId) {
1107
+ throw new Error(`Could not find server component name`);
1108
+ }
1109
+ for (const key2 of Object.keys(this.props)) {
1110
+ if (internalProps.has(key2)) {
1111
+ delete this.props[key2];
1112
+ }
1113
+ }
1114
+ const renderedSlots = {};
1115
+ for (const name in this.slots) {
1116
+ if (name !== "fallback") {
1117
+ const content = await renderSlotToString(this.result, this.slots[name]);
1118
+ renderedSlots[name] = content.toString();
1119
+ }
1120
+ }
1121
+ const key = await this.result.key;
1122
+ const propsEncrypted = Object.keys(this.props).length === 0 ? "" : await encryptString(key, JSON.stringify(this.props));
1123
+ const slotsEncrypted = Object.keys(renderedSlots).length === 0 ? "" : await encryptString(key, JSON.stringify(renderedSlots));
1124
+ const hostId = await this.getHostId();
1125
+ const slash = this.result.base.endsWith("/") ? "" : "/";
1126
+ let serverIslandUrl = `${this.result.base}${slash}_server-islands/${componentId}${this.result.trailingSlash === "always" ? "/" : ""}`;
1127
+ const potentialSearchParams = createSearchParams(
1128
+ componentExport,
1129
+ propsEncrypted,
1130
+ slotsEncrypted
1131
+ );
1132
+ const useGETRequest = isWithinURLLimit(serverIslandUrl, potentialSearchParams);
1133
+ if (useGETRequest) {
1134
+ serverIslandUrl += "?" + potentialSearchParams.toString();
1135
+ this.result._metadata.extraHead.push(
1136
+ markHTMLString(
1137
+ `<link rel="preload" as="fetch" href="${serverIslandUrl}" crossorigin="anonymous">`
1138
+ )
1139
+ );
1140
+ }
1141
+ const adapterHeaders = this.result.internalFetchHeaders || {};
1142
+ const headersJson = safeJsonStringify(adapterHeaders);
1143
+ const method = useGETRequest ? (
1144
+ // GET request
1145
+ `const headers = new Headers(${headersJson});
1146
+ let response = await fetch('${serverIslandUrl}', { headers });`
1147
+ ) : (
1148
+ // POST request
1149
+ `let data = {
1150
+ componentExport: ${safeJsonStringify(componentExport)},
1151
+ encryptedProps: ${safeJsonStringify(propsEncrypted)},
1152
+ encryptedSlots: ${safeJsonStringify(slotsEncrypted)},
1153
+ };
1154
+ const headers = new Headers({ 'Content-Type': 'application/json', ...${headersJson} });
1155
+ let response = await fetch('${serverIslandUrl}', {
1156
+ method: 'POST',
1157
+ body: JSON.stringify(data),
1158
+ headers,
1159
+ });`
1160
+ );
1161
+ this.islandContent = `${method}replaceServerIsland('${hostId}', response);`;
1162
+ return this.islandContent;
1163
+ }
1164
+ }
1165
+ const renderServerIslandRuntime = () => {
1166
+ return `<script>${SERVER_ISLAND_REPLACER}</script>`;
1167
+ };
1168
+ const SERVER_ISLAND_REPLACER = markHTMLString(
1169
+ `async function replaceServerIsland(id, r) {
1170
+ let s = document.querySelector(\`script[data-island-id="\${id}"]\`);
1171
+ // If there's no matching script, or the request fails then return
1172
+ if (!s || r.status !== 200 || r.headers.get('content-type')?.split(';')[0].trim() !== 'text/html') return;
1173
+ // Load the HTML before modifying the DOM in case of errors
1174
+ let html = await r.text();
1175
+ // Remove any placeholder content before the island script
1176
+ while (s.previousSibling && s.previousSibling.nodeType !== 8 && s.previousSibling.data !== '[if astro]>server-island-start<![endif]')
1177
+ s.previousSibling.remove();
1178
+ s.previousSibling?.remove();
1179
+ // Insert the new HTML
1180
+ s.before(document.createRange().createContextualFragment(html));
1181
+ // Remove the script. Prior to v5.4.2, this was the trick to force rerun of scripts. Keeping it to minimize change to the existing behavior.
1182
+ s.remove();
1183
+ }`.split("\n").map((line) => line.trim()).filter((line) => line && !line.startsWith("//")).join(" ")
1184
+ );
1185
+
1186
+ const Fragment = Symbol.for("astro:fragment");
1187
+ const Renderer = Symbol.for("astro:renderer");
1188
+ new TextEncoder();
1189
+ const decoder = new TextDecoder();
1190
+ function stringifyChunk(result, chunk) {
1191
+ if (isRenderInstruction(chunk)) {
1192
+ const instruction = chunk;
1193
+ switch (instruction.type) {
1194
+ case "directive": {
1195
+ const { hydration } = instruction;
1196
+ let needsHydrationScript = hydration && determineIfNeedsHydrationScript(result);
1197
+ let needsDirectiveScript = hydration && determinesIfNeedsDirectiveScript(result, hydration.directive);
1198
+ if (needsHydrationScript) {
1199
+ let prescripts = getPrescripts(result, "both", hydration.directive);
1200
+ return markHTMLString(prescripts);
1201
+ } else if (needsDirectiveScript) {
1202
+ let prescripts = getPrescripts(result, "directive", hydration.directive);
1203
+ return markHTMLString(prescripts);
1204
+ } else {
1205
+ return "";
1206
+ }
1207
+ }
1208
+ case "head": {
1209
+ if (result._metadata.hasRenderedHead || result.partial) {
1210
+ return "";
1211
+ }
1212
+ return renderAllHeadContent(result);
1213
+ }
1214
+ case "maybe-head": {
1215
+ if (result._metadata.hasRenderedHead || result._metadata.headInTree || result.partial) {
1216
+ return "";
1217
+ }
1218
+ return renderAllHeadContent(result);
1219
+ }
1220
+ case "renderer-hydration-script": {
1221
+ const { rendererSpecificHydrationScripts } = result._metadata;
1222
+ const { rendererName } = instruction;
1223
+ if (!rendererSpecificHydrationScripts.has(rendererName)) {
1224
+ rendererSpecificHydrationScripts.add(rendererName);
1225
+ return instruction.render();
1226
+ }
1227
+ return "";
1228
+ }
1229
+ case "server-island-runtime": {
1230
+ if (result._metadata.hasRenderedServerIslandRuntime) {
1231
+ return "";
1232
+ }
1233
+ result._metadata.hasRenderedServerIslandRuntime = true;
1234
+ return renderServerIslandRuntime();
1235
+ }
1236
+ default: {
1237
+ throw new Error(`Unknown chunk type: ${chunk.type}`);
1238
+ }
1239
+ }
1240
+ } else if (chunk instanceof Response) {
1241
+ return "";
1242
+ } else if (isSlotString(chunk)) {
1243
+ let out = "";
1244
+ const c = chunk;
1245
+ if (c.instructions) {
1246
+ for (const instr of c.instructions) {
1247
+ out += stringifyChunk(result, instr);
1248
+ }
1249
+ }
1250
+ out += chunk.toString();
1251
+ return out;
1252
+ }
1253
+ return chunk.toString();
1254
+ }
1255
+ function chunkToString(result, chunk) {
1256
+ if (ArrayBuffer.isView(chunk)) {
1257
+ return decoder.decode(chunk);
1258
+ } else {
1259
+ return stringifyChunk(result, chunk);
1260
+ }
1261
+ }
1262
+ function isRenderInstance(obj) {
1263
+ return !!obj && typeof obj === "object" && "render" in obj && typeof obj.render === "function";
1264
+ }
1265
+
1266
+ function renderChild(destination, child) {
1267
+ if (isPromise(child)) {
1268
+ return child.then((x) => renderChild(destination, x));
1269
+ }
1270
+ if (child instanceof SlotString) {
1271
+ destination.write(child);
1272
+ return;
1273
+ }
1274
+ if (isHTMLString(child)) {
1275
+ destination.write(child);
1276
+ return;
1277
+ }
1278
+ if (Array.isArray(child)) {
1279
+ return renderArray(destination, child);
1280
+ }
1281
+ if (typeof child === "function") {
1282
+ return renderChild(destination, child());
1283
+ }
1284
+ if (!child && child !== 0) {
1285
+ return;
1286
+ }
1287
+ if (typeof child === "string") {
1288
+ destination.write(markHTMLString(escapeHTML(child)));
1289
+ return;
1290
+ }
1291
+ if (isRenderInstance(child)) {
1292
+ return child.render(destination);
1293
+ }
1294
+ if (isRenderTemplateResult(child)) {
1295
+ return child.render(destination);
1296
+ }
1297
+ if (isAstroComponentInstance(child)) {
1298
+ return child.render(destination);
1299
+ }
1300
+ if (ArrayBuffer.isView(child)) {
1301
+ destination.write(child);
1302
+ return;
1303
+ }
1304
+ if (typeof child === "object" && (Symbol.asyncIterator in child || Symbol.iterator in child)) {
1305
+ if (Symbol.asyncIterator in child) {
1306
+ return renderAsyncIterable(destination, child);
1307
+ }
1308
+ return renderIterable(destination, child);
1309
+ }
1310
+ destination.write(child);
1311
+ }
1312
+ function renderArray(destination, children) {
1313
+ const flushers = children.map((c) => {
1314
+ return createBufferedRenderer(destination, (bufferDestination) => {
1315
+ return renderChild(bufferDestination, c);
1316
+ });
1317
+ });
1318
+ const iterator = flushers[Symbol.iterator]();
1319
+ const iterate = () => {
1320
+ for (; ; ) {
1321
+ const { value: flusher, done } = iterator.next();
1322
+ if (done) {
1323
+ break;
1324
+ }
1325
+ const result = flusher.flush();
1326
+ if (isPromise(result)) {
1327
+ return result.then(iterate);
1328
+ }
1329
+ }
1330
+ };
1331
+ return iterate();
1332
+ }
1333
+ function renderIterable(destination, children) {
1334
+ const iterator = children[Symbol.iterator]();
1335
+ const iterate = () => {
1336
+ for (; ; ) {
1337
+ const { value, done } = iterator.next();
1338
+ if (done) {
1339
+ break;
1340
+ }
1341
+ const result = renderChild(destination, value);
1342
+ if (isPromise(result)) {
1343
+ return result.then(iterate);
1344
+ }
1345
+ }
1346
+ };
1347
+ return iterate();
1348
+ }
1349
+ async function renderAsyncIterable(destination, children) {
1350
+ for await (const value of children) {
1351
+ await renderChild(destination, value);
1352
+ }
1353
+ }
1354
+
1355
+ const astroComponentInstanceSym = Symbol.for("astro.componentInstance");
1356
+ class AstroComponentInstance {
1357
+ [astroComponentInstanceSym] = true;
1358
+ result;
1359
+ props;
1360
+ slotValues;
1361
+ factory;
1362
+ returnValue;
1363
+ constructor(result, props, slots, factory) {
1364
+ this.result = result;
1365
+ this.props = props;
1366
+ this.factory = factory;
1367
+ this.slotValues = {};
1368
+ for (const name in slots) {
1369
+ let didRender = false;
1370
+ let value = slots[name](result);
1371
+ this.slotValues[name] = () => {
1372
+ if (!didRender) {
1373
+ didRender = true;
1374
+ return value;
1375
+ }
1376
+ return slots[name](result);
1377
+ };
1378
+ }
1379
+ }
1380
+ init(result) {
1381
+ if (this.returnValue !== void 0) {
1382
+ return this.returnValue;
1383
+ }
1384
+ this.returnValue = this.factory(result, this.props, this.slotValues);
1385
+ if (isPromise(this.returnValue)) {
1386
+ this.returnValue.then((resolved) => {
1387
+ this.returnValue = resolved;
1388
+ }).catch(() => {
1389
+ });
1390
+ }
1391
+ return this.returnValue;
1392
+ }
1393
+ render(destination) {
1394
+ const returnValue = this.init(this.result);
1395
+ if (isPromise(returnValue)) {
1396
+ return returnValue.then((x) => this.renderImpl(destination, x));
1397
+ }
1398
+ return this.renderImpl(destination, returnValue);
1399
+ }
1400
+ renderImpl(destination, returnValue) {
1401
+ if (isHeadAndContent(returnValue)) {
1402
+ return returnValue.content.render(destination);
1403
+ } else {
1404
+ return renderChild(destination, returnValue);
1405
+ }
1406
+ }
1407
+ }
1408
+ function validateComponentProps(props, clientDirectives, displayName) {
1409
+ if (props != null) {
1410
+ const directives = [...clientDirectives.keys()].map((directive) => `client:${directive}`);
1411
+ for (const prop of Object.keys(props)) {
1412
+ if (directives.includes(prop)) {
1413
+ console.warn(
1414
+ `You are attempting to render <${displayName} ${prop} />, but ${displayName} is an Astro component. Astro components do not render in the client and should not have a hydration directive. Please use a framework component for client rendering.`
1415
+ );
1416
+ }
1417
+ }
1418
+ }
1419
+ }
1420
+ function createAstroComponentInstance(result, displayName, factory, props, slots = {}) {
1421
+ validateComponentProps(props, result.clientDirectives, displayName);
1422
+ const instance = new AstroComponentInstance(result, props, slots, factory);
1423
+ if (isAPropagatingComponent(result, factory)) {
1424
+ result._metadata.propagators.add(instance);
1425
+ }
1426
+ return instance;
1427
+ }
1428
+ function isAstroComponentInstance(obj) {
1429
+ return typeof obj === "object" && obj !== null && !!obj[astroComponentInstanceSym];
1430
+ }
1431
+
1432
+ function componentIsHTMLElement(Component) {
1433
+ return typeof HTMLElement !== "undefined" && HTMLElement.isPrototypeOf(Component);
1434
+ }
1435
+ async function renderHTMLElement(result, constructor, props, slots) {
1436
+ const name = getHTMLElementName(constructor);
1437
+ let attrHTML = "";
1438
+ for (const attr in props) {
1439
+ attrHTML += ` ${attr}="${toAttributeString(await props[attr])}"`;
1440
+ }
1441
+ return markHTMLString(
1442
+ `<${name}${attrHTML}>${await renderSlotToString(result, slots?.default)}</${name}>`
1443
+ );
1444
+ }
1445
+ function getHTMLElementName(constructor) {
1446
+ const definedName = customElements.getName(constructor);
1447
+ if (definedName) return definedName;
1448
+ const assignedName = constructor.name.replace(/^HTML|Element$/g, "").replace(/[A-Z]/g, "-$&").toLowerCase().replace(/^-/, "html-");
1449
+ return assignedName;
1450
+ }
1451
+
1452
+ const rendererAliases = /* @__PURE__ */ new Map([["solid", "solid-js"]]);
1453
+ const clientOnlyValues = /* @__PURE__ */ new Set(["solid-js", "react", "preact", "vue", "svelte"]);
1454
+ function guessRenderers(componentUrl) {
1455
+ const extname = componentUrl?.split(".").pop();
1456
+ switch (extname) {
1457
+ case "svelte":
1458
+ return ["@astrojs/svelte"];
1459
+ case "vue":
1460
+ return ["@astrojs/vue"];
1461
+ case "jsx":
1462
+ case "tsx":
1463
+ return ["@astrojs/react", "@astrojs/preact", "@astrojs/solid-js", "@astrojs/vue (jsx)"];
1464
+ case void 0:
1465
+ default:
1466
+ return [
1467
+ "@astrojs/react",
1468
+ "@astrojs/preact",
1469
+ "@astrojs/solid-js",
1470
+ "@astrojs/vue",
1471
+ "@astrojs/svelte"
1472
+ ];
1473
+ }
1474
+ }
1475
+ function isFragmentComponent(Component) {
1476
+ return Component === Fragment;
1477
+ }
1478
+ function isHTMLComponent(Component) {
1479
+ return Component && Component["astro:html"] === true;
1480
+ }
1481
+ const ASTRO_SLOT_EXP = /<\/?astro-slot\b[^>]*>/g;
1482
+ const ASTRO_STATIC_SLOT_EXP = /<\/?astro-static-slot\b[^>]*>/g;
1483
+ function removeStaticAstroSlot(html, supportsAstroStaticSlot = true) {
1484
+ const exp = supportsAstroStaticSlot ? ASTRO_STATIC_SLOT_EXP : ASTRO_SLOT_EXP;
1485
+ return html.replace(exp, "");
1486
+ }
1487
+ async function renderFrameworkComponent(result, displayName, Component, _props, slots = {}) {
1488
+ if (!Component && "client:only" in _props === false) {
1489
+ throw new Error(
1490
+ `Unable to render ${displayName} because it is ${Component}!
1491
+ Did you forget to import the component or is it possible there is a typo?`
1492
+ );
1493
+ }
1494
+ const { renderers, clientDirectives } = result;
1495
+ const metadata = {
1496
+ astroStaticSlot: true,
1497
+ displayName
1498
+ };
1499
+ const { hydration, isPage, props, propsWithoutTransitionAttributes } = extractDirectives(
1500
+ _props,
1501
+ clientDirectives
1502
+ );
1503
+ let html = "";
1504
+ let attrs = void 0;
1505
+ if (hydration) {
1506
+ metadata.hydrate = hydration.directive;
1507
+ metadata.hydrateArgs = hydration.value;
1508
+ metadata.componentExport = hydration.componentExport;
1509
+ metadata.componentUrl = hydration.componentUrl;
1510
+ }
1511
+ const probableRendererNames = guessRenderers(metadata.componentUrl);
1512
+ const validRenderers = renderers.filter((r) => r.name !== "astro:jsx");
1513
+ const { children, slotInstructions } = await renderSlots(result, slots);
1514
+ let renderer;
1515
+ if (metadata.hydrate !== "only") {
1516
+ let isTagged = false;
1517
+ try {
1518
+ isTagged = Component && Component[Renderer];
1519
+ } catch {
1520
+ }
1521
+ if (isTagged) {
1522
+ const rendererName = Component[Renderer];
1523
+ renderer = renderers.find(({ name }) => name === rendererName);
1524
+ }
1525
+ if (!renderer) {
1526
+ let error;
1527
+ for (const r of renderers) {
1528
+ try {
1529
+ if (await r.ssr.check.call({ result }, Component, props, children)) {
1530
+ renderer = r;
1531
+ break;
1532
+ }
1533
+ } catch (e) {
1534
+ error ??= e;
1535
+ }
1536
+ }
1537
+ if (!renderer && error) {
1538
+ throw error;
1539
+ }
1540
+ }
1541
+ if (!renderer && typeof HTMLElement === "function" && componentIsHTMLElement(Component)) {
1542
+ const output = await renderHTMLElement(
1543
+ result,
1544
+ Component,
1545
+ _props,
1546
+ slots
1547
+ );
1548
+ return {
1549
+ render(destination) {
1550
+ destination.write(output);
1551
+ }
1552
+ };
1553
+ }
1554
+ } else {
1555
+ if (metadata.hydrateArgs) {
1556
+ const rendererName = rendererAliases.has(metadata.hydrateArgs) ? rendererAliases.get(metadata.hydrateArgs) : metadata.hydrateArgs;
1557
+ if (clientOnlyValues.has(rendererName)) {
1558
+ renderer = renderers.find(
1559
+ ({ name }) => name === `@astrojs/${rendererName}` || name === rendererName
1560
+ );
1561
+ }
1562
+ }
1563
+ if (!renderer && validRenderers.length === 1) {
1564
+ renderer = validRenderers[0];
1565
+ }
1566
+ if (!renderer) {
1567
+ const extname = metadata.componentUrl?.split(".").pop();
1568
+ renderer = renderers.find(({ name }) => name === `@astrojs/${extname}` || name === extname);
1569
+ }
1570
+ }
1571
+ let componentServerRenderEndTime;
1572
+ if (!renderer) {
1573
+ if (metadata.hydrate === "only") {
1574
+ const rendererName = rendererAliases.has(metadata.hydrateArgs) ? rendererAliases.get(metadata.hydrateArgs) : metadata.hydrateArgs;
1575
+ if (clientOnlyValues.has(rendererName)) {
1576
+ const plural = validRenderers.length > 1;
1577
+ throw new AstroError({
1578
+ ...NoMatchingRenderer,
1579
+ message: NoMatchingRenderer.message(
1580
+ metadata.displayName,
1581
+ metadata?.componentUrl?.split(".").pop(),
1582
+ plural,
1583
+ validRenderers.length
1584
+ ),
1585
+ hint: NoMatchingRenderer.hint(
1586
+ formatList(probableRendererNames.map((r) => "`" + r + "`"))
1587
+ )
1588
+ });
1589
+ } else {
1590
+ throw new AstroError({
1591
+ ...NoClientOnlyHint,
1592
+ message: NoClientOnlyHint.message(metadata.displayName),
1593
+ hint: NoClientOnlyHint.hint(
1594
+ probableRendererNames.map((r) => r.replace("@astrojs/", "")).join("|")
1595
+ )
1596
+ });
1597
+ }
1598
+ } else if (typeof Component !== "string") {
1599
+ const matchingRenderers = validRenderers.filter(
1600
+ (r) => probableRendererNames.includes(r.name)
1601
+ );
1602
+ const plural = validRenderers.length > 1;
1603
+ if (matchingRenderers.length === 0) {
1604
+ throw new AstroError({
1605
+ ...NoMatchingRenderer,
1606
+ message: NoMatchingRenderer.message(
1607
+ metadata.displayName,
1608
+ metadata?.componentUrl?.split(".").pop(),
1609
+ plural,
1610
+ validRenderers.length
1611
+ ),
1612
+ hint: NoMatchingRenderer.hint(
1613
+ formatList(probableRendererNames.map((r) => "`" + r + "`"))
1614
+ )
1615
+ });
1616
+ } else if (matchingRenderers.length === 1) {
1617
+ renderer = matchingRenderers[0];
1618
+ ({ html, attrs } = await renderer.ssr.renderToStaticMarkup.call(
1619
+ { result },
1620
+ Component,
1621
+ propsWithoutTransitionAttributes,
1622
+ children,
1623
+ metadata
1624
+ ));
1625
+ } else {
1626
+ throw new Error(`Unable to render ${metadata.displayName}!
1627
+
1628
+ This component likely uses ${formatList(probableRendererNames)},
1629
+ but Astro encountered an error during server-side rendering.
1630
+
1631
+ Please ensure that ${metadata.displayName}:
1632
+ 1. Does not unconditionally access browser-specific globals like \`window\` or \`document\`.
1633
+ If this is unavoidable, use the \`client:only\` hydration directive.
1634
+ 2. Does not conditionally return \`null\` or \`undefined\` when rendered on the server.
1635
+
1636
+ If you're still stuck, please open an issue on GitHub or join us at https://astro.build/chat.`);
1637
+ }
1638
+ }
1639
+ } else {
1640
+ if (metadata.hydrate === "only") {
1641
+ html = await renderSlotToString(result, slots?.fallback);
1642
+ } else {
1643
+ const componentRenderStartTime = performance.now();
1644
+ ({ html, attrs } = await renderer.ssr.renderToStaticMarkup.call(
1645
+ { result },
1646
+ Component,
1647
+ propsWithoutTransitionAttributes,
1648
+ children,
1649
+ metadata
1650
+ ));
1651
+ if (process.env.NODE_ENV === "development")
1652
+ componentServerRenderEndTime = performance.now() - componentRenderStartTime;
1653
+ }
1654
+ }
1655
+ if (!html && typeof Component === "string") {
1656
+ const Tag = sanitizeElementName(Component);
1657
+ const childSlots = Object.values(children).join("");
1658
+ const renderTemplateResult = renderTemplate`<${Tag}${internalSpreadAttributes(
1659
+ props,
1660
+ true,
1661
+ Tag
1662
+ )}${markHTMLString(
1663
+ childSlots === "" && voidElementNames.test(Tag) ? `/>` : `>${childSlots}</${Tag}>`
1664
+ )}`;
1665
+ html = "";
1666
+ const destination = {
1667
+ write(chunk) {
1668
+ if (chunk instanceof Response) return;
1669
+ html += chunkToString(result, chunk);
1670
+ }
1671
+ };
1672
+ await renderTemplateResult.render(destination);
1673
+ }
1674
+ if (!hydration) {
1675
+ return {
1676
+ render(destination) {
1677
+ if (slotInstructions) {
1678
+ for (const instruction of slotInstructions) {
1679
+ destination.write(instruction);
1680
+ }
1681
+ }
1682
+ if (isPage || renderer?.name === "astro:jsx") {
1683
+ destination.write(html);
1684
+ } else if (html && html.length > 0) {
1685
+ destination.write(
1686
+ markHTMLString(removeStaticAstroSlot(html, renderer?.ssr?.supportsAstroStaticSlot))
1687
+ );
1688
+ }
1689
+ }
1690
+ };
1691
+ }
1692
+ const astroId = shorthash(
1693
+ `<!--${metadata.componentExport.value}:${metadata.componentUrl}-->
1694
+ ${html}
1695
+ ${serializeProps(
1696
+ props,
1697
+ metadata
1698
+ )}`
1699
+ );
1700
+ const island = await generateHydrateScript(
1701
+ { renderer, result, astroId, props, attrs },
1702
+ metadata
1703
+ );
1704
+ if (componentServerRenderEndTime && process.env.NODE_ENV === "development")
1705
+ island.props["server-render-time"] = componentServerRenderEndTime;
1706
+ let unrenderedSlots = [];
1707
+ if (html) {
1708
+ if (Object.keys(children).length > 0) {
1709
+ for (const key of Object.keys(children)) {
1710
+ let tagName = renderer?.ssr?.supportsAstroStaticSlot ? !!metadata.hydrate ? "astro-slot" : "astro-static-slot" : "astro-slot";
1711
+ let expectedHTML = key === "default" ? `<${tagName}>` : `<${tagName} name="${key}">`;
1712
+ if (!html.includes(expectedHTML)) {
1713
+ unrenderedSlots.push(key);
1714
+ }
1715
+ }
1716
+ }
1717
+ } else {
1718
+ unrenderedSlots = Object.keys(children);
1719
+ }
1720
+ const template = unrenderedSlots.length > 0 ? unrenderedSlots.map(
1721
+ (key) => `<template data-astro-template${key !== "default" ? `="${key}"` : ""}>${children[key]}</template>`
1722
+ ).join("") : "";
1723
+ island.children = `${html ?? ""}${template}`;
1724
+ if (island.children) {
1725
+ island.props["await-children"] = "";
1726
+ island.children += `<!--astro:end-->`;
1727
+ }
1728
+ return {
1729
+ render(destination) {
1730
+ if (slotInstructions) {
1731
+ for (const instruction of slotInstructions) {
1732
+ destination.write(instruction);
1733
+ }
1734
+ }
1735
+ destination.write(createRenderInstruction({ type: "directive", hydration }));
1736
+ if (hydration.directive !== "only" && renderer?.ssr.renderHydrationScript) {
1737
+ destination.write(
1738
+ createRenderInstruction({
1739
+ type: "renderer-hydration-script",
1740
+ rendererName: renderer.name,
1741
+ render: renderer.ssr.renderHydrationScript
1742
+ })
1743
+ );
1744
+ }
1745
+ const renderedElement = renderElement("astro-island", island, false);
1746
+ destination.write(markHTMLString(renderedElement));
1747
+ }
1748
+ };
1749
+ }
1750
+ function sanitizeElementName(tag) {
1751
+ const unsafe = /[&<>'"\s]+/;
1752
+ if (!unsafe.test(tag)) return tag;
1753
+ return tag.trim().split(unsafe)[0].trim();
1754
+ }
1755
+ async function renderFragmentComponent(result, slots = {}) {
1756
+ const children = await renderSlotToString(result, slots?.default);
1757
+ return {
1758
+ render(destination) {
1759
+ if (children == null) return;
1760
+ destination.write(children);
1761
+ }
1762
+ };
1763
+ }
1764
+ async function renderHTMLComponent(result, Component, _props, slots = {}) {
1765
+ const { slotInstructions, children } = await renderSlots(result, slots);
1766
+ const html = Component({ slots: children });
1767
+ const hydrationHtml = slotInstructions ? slotInstructions.map((instr) => chunkToString(result, instr)).join("") : "";
1768
+ return {
1769
+ render(destination) {
1770
+ destination.write(markHTMLString(hydrationHtml + html));
1771
+ }
1772
+ };
1773
+ }
1774
+ function renderAstroComponent(result, displayName, Component, props, slots = {}) {
1775
+ if (containsServerDirective(props)) {
1776
+ const serverIslandComponent = new ServerIslandComponent(result, props, slots, displayName);
1777
+ result._metadata.propagators.add(serverIslandComponent);
1778
+ return serverIslandComponent;
1779
+ }
1780
+ const instance = createAstroComponentInstance(result, displayName, Component, props, slots);
1781
+ return {
1782
+ render(destination) {
1783
+ return instance.render(destination);
1784
+ }
1785
+ };
1786
+ }
1787
+ function renderComponent(result, displayName, Component, props, slots = {}) {
1788
+ if (isPromise(Component)) {
1789
+ return Component.catch(handleCancellation).then((x) => {
1790
+ return renderComponent(result, displayName, x, props, slots);
1791
+ });
1792
+ }
1793
+ if (isFragmentComponent(Component)) {
1794
+ return renderFragmentComponent(result, slots).catch(handleCancellation);
1795
+ }
1796
+ props = normalizeProps(props);
1797
+ if (isHTMLComponent(Component)) {
1798
+ return renderHTMLComponent(result, Component, props, slots).catch(handleCancellation);
1799
+ }
1800
+ if (isAstroComponentFactory(Component)) {
1801
+ return renderAstroComponent(result, displayName, Component, props, slots);
1802
+ }
1803
+ return renderFrameworkComponent(result, displayName, Component, props, slots).catch(
1804
+ handleCancellation
1805
+ );
1806
+ function handleCancellation(e) {
1807
+ if (result.cancelled)
1808
+ return {
1809
+ render() {
1810
+ }
1811
+ };
1812
+ throw e;
1813
+ }
1814
+ }
1815
+ function normalizeProps(props) {
1816
+ if (props["class:list"] !== void 0) {
1817
+ const value = props["class:list"];
1818
+ delete props["class:list"];
1819
+ props["class"] = clsx(props["class"], value);
1820
+ if (props["class"] === "") {
1821
+ delete props["class"];
1822
+ }
1823
+ }
1824
+ return props;
1825
+ }
1826
+
1827
+ "0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ-_".split("").reduce((v, c) => (v[c.charCodeAt(0)] = c, v), []);
1828
+ "-0123456789_".split("").reduce((v, c) => (v[c.charCodeAt(0)] = c, v), []);
1829
+
1830
+ export { NOOP_MIDDLEWARE_HEADER as N, createAstro as a, addAttribute as b, createComponent as c, renderComponent as d, renderTemplate as e, decodeKey as f, renderHead as r };