@blinkk/root 2.5.11 → 2.5.12-alpha.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/chunk-P6EPJRRM.js +448 -0
- package/dist/chunk-P6EPJRRM.js.map +1 -0
- package/dist/cli.d.ts +2 -1
- package/dist/core.d.ts +3 -2
- package/dist/core.js.map +1 -1
- package/dist/jsx-render-BCCySLjz.d.ts +127 -0
- package/dist/jsx.d.ts +565 -0
- package/dist/jsx.js +21 -0
- package/dist/jsx.js.map +1 -0
- package/dist/middleware.d.ts +3 -2
- package/dist/node.d.ts +2 -1
- package/dist/render.d.ts +2 -1
- package/dist/render.js +43 -9
- package/dist/render.js.map +1 -1
- package/dist/{types-BXpvdaTX.d.ts → types-yeULDLJI.d.ts} +30 -0
- package/package.json +11 -4
|
@@ -0,0 +1,448 @@
|
|
|
1
|
+
// src/jsx/jsx-runtime.ts
|
|
2
|
+
var options = {};
|
|
3
|
+
function Fragment(props) {
|
|
4
|
+
return props.children;
|
|
5
|
+
}
|
|
6
|
+
function jsx(type, props, key) {
|
|
7
|
+
const resolvedKey = key !== void 0 ? key : props.key ?? null;
|
|
8
|
+
const vnode = {
|
|
9
|
+
type,
|
|
10
|
+
props,
|
|
11
|
+
key: resolvedKey
|
|
12
|
+
};
|
|
13
|
+
if (props.key !== void 0) {
|
|
14
|
+
const { key: _, ...rest } = props;
|
|
15
|
+
vnode.props = rest;
|
|
16
|
+
}
|
|
17
|
+
if (options.vnode) {
|
|
18
|
+
options.vnode(vnode);
|
|
19
|
+
}
|
|
20
|
+
return vnode;
|
|
21
|
+
}
|
|
22
|
+
function createElement(type, props, ...children) {
|
|
23
|
+
const normalizedProps = { ...props || {} };
|
|
24
|
+
if (children.length === 1) {
|
|
25
|
+
normalizedProps.children = children[0];
|
|
26
|
+
} else if (children.length > 1) {
|
|
27
|
+
normalizedProps.children = children;
|
|
28
|
+
}
|
|
29
|
+
const vnode = {
|
|
30
|
+
type,
|
|
31
|
+
props: normalizedProps,
|
|
32
|
+
key: normalizedProps.key ?? null
|
|
33
|
+
};
|
|
34
|
+
if (normalizedProps.key !== void 0) {
|
|
35
|
+
delete normalizedProps.key;
|
|
36
|
+
}
|
|
37
|
+
if (options.vnode) {
|
|
38
|
+
options.vnode(vnode);
|
|
39
|
+
}
|
|
40
|
+
return vnode;
|
|
41
|
+
}
|
|
42
|
+
function createContext(defaultValue) {
|
|
43
|
+
const ctx = {
|
|
44
|
+
_defaultValue: defaultValue,
|
|
45
|
+
_stack: [],
|
|
46
|
+
Provider: null
|
|
47
|
+
};
|
|
48
|
+
const Provider = () => {
|
|
49
|
+
return null;
|
|
50
|
+
};
|
|
51
|
+
Provider.displayName = "ContextProvider";
|
|
52
|
+
Provider._isProvider = true;
|
|
53
|
+
Provider._context = ctx;
|
|
54
|
+
ctx.Provider = Provider;
|
|
55
|
+
return ctx;
|
|
56
|
+
}
|
|
57
|
+
function useContext(context) {
|
|
58
|
+
const stack = context._stack;
|
|
59
|
+
if (stack.length > 0) {
|
|
60
|
+
return stack[stack.length - 1];
|
|
61
|
+
}
|
|
62
|
+
return context._defaultValue;
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
// src/jsx/jsx-render.ts
|
|
66
|
+
import { options as preactOptions } from "preact";
|
|
67
|
+
var VOID_ELEMENTS = /* @__PURE__ */ new Set([
|
|
68
|
+
"area",
|
|
69
|
+
"base",
|
|
70
|
+
"br",
|
|
71
|
+
"col",
|
|
72
|
+
"embed",
|
|
73
|
+
"hr",
|
|
74
|
+
"img",
|
|
75
|
+
"input",
|
|
76
|
+
"link",
|
|
77
|
+
"meta",
|
|
78
|
+
"param",
|
|
79
|
+
"source",
|
|
80
|
+
"track",
|
|
81
|
+
"wbr"
|
|
82
|
+
]);
|
|
83
|
+
var RAW_CONTENT_ELEMENTS = /* @__PURE__ */ new Set(["pre", "textarea", "script", "style"]);
|
|
84
|
+
var DEFAULT_BLOCK_ELEMENTS = /* @__PURE__ */ new Set([
|
|
85
|
+
"address",
|
|
86
|
+
"article",
|
|
87
|
+
"aside",
|
|
88
|
+
"blockquote",
|
|
89
|
+
"body",
|
|
90
|
+
"dd",
|
|
91
|
+
"details",
|
|
92
|
+
"dialog",
|
|
93
|
+
"div",
|
|
94
|
+
"dl",
|
|
95
|
+
"dt",
|
|
96
|
+
"fieldset",
|
|
97
|
+
"figcaption",
|
|
98
|
+
"figure",
|
|
99
|
+
"footer",
|
|
100
|
+
"form",
|
|
101
|
+
"h1",
|
|
102
|
+
"h2",
|
|
103
|
+
"h3",
|
|
104
|
+
"h4",
|
|
105
|
+
"h5",
|
|
106
|
+
"h6",
|
|
107
|
+
"head",
|
|
108
|
+
"header",
|
|
109
|
+
"hgroup",
|
|
110
|
+
"hr",
|
|
111
|
+
"html",
|
|
112
|
+
"li",
|
|
113
|
+
"link",
|
|
114
|
+
"main",
|
|
115
|
+
"meta",
|
|
116
|
+
"nav",
|
|
117
|
+
"noscript",
|
|
118
|
+
"ol",
|
|
119
|
+
"p",
|
|
120
|
+
"pre",
|
|
121
|
+
"script",
|
|
122
|
+
"search",
|
|
123
|
+
"section",
|
|
124
|
+
"style",
|
|
125
|
+
"summary",
|
|
126
|
+
"table",
|
|
127
|
+
"tbody",
|
|
128
|
+
"td",
|
|
129
|
+
"tfoot",
|
|
130
|
+
"th",
|
|
131
|
+
"thead",
|
|
132
|
+
"title",
|
|
133
|
+
"tr",
|
|
134
|
+
"ul"
|
|
135
|
+
]);
|
|
136
|
+
var PROP_TO_ATTR = {
|
|
137
|
+
acceptCharset: "accept-charset",
|
|
138
|
+
autoCapitalize: "autocapitalize",
|
|
139
|
+
autoComplete: "autocomplete",
|
|
140
|
+
autoFocus: "autofocus",
|
|
141
|
+
autoPlay: "autoplay",
|
|
142
|
+
charSet: "charset",
|
|
143
|
+
className: "class",
|
|
144
|
+
colSpan: "colspan",
|
|
145
|
+
contentEditable: "contenteditable",
|
|
146
|
+
crossOrigin: "crossorigin",
|
|
147
|
+
dateTime: "datetime",
|
|
148
|
+
encType: "enctype",
|
|
149
|
+
formAction: "formaction",
|
|
150
|
+
formEncType: "formenctype",
|
|
151
|
+
formMethod: "formmethod",
|
|
152
|
+
formNoValidate: "formnovalidate",
|
|
153
|
+
formTarget: "formtarget",
|
|
154
|
+
frameBorder: "frameborder",
|
|
155
|
+
hrefLang: "hreflang",
|
|
156
|
+
htmlFor: "for",
|
|
157
|
+
httpEquiv: "http-equiv",
|
|
158
|
+
inputMode: "inputmode",
|
|
159
|
+
itemProp: "itemprop",
|
|
160
|
+
itemRef: "itemref",
|
|
161
|
+
itemScope: "itemscope",
|
|
162
|
+
itemType: "itemtype",
|
|
163
|
+
maxLength: "maxlength",
|
|
164
|
+
mediaGroup: "mediagroup",
|
|
165
|
+
minLength: "minlength",
|
|
166
|
+
noModule: "nomodule",
|
|
167
|
+
noValidate: "novalidate",
|
|
168
|
+
playsInline: "playsinline",
|
|
169
|
+
readOnly: "readonly",
|
|
170
|
+
referrerPolicy: "referrerpolicy",
|
|
171
|
+
rowSpan: "rowspan",
|
|
172
|
+
spellCheck: "spellcheck",
|
|
173
|
+
srcDoc: "srcdoc",
|
|
174
|
+
srcLang: "srclang",
|
|
175
|
+
srcSet: "srcset",
|
|
176
|
+
tabIndex: "tabindex",
|
|
177
|
+
useMap: "usemap"
|
|
178
|
+
};
|
|
179
|
+
var AMP = "&";
|
|
180
|
+
var LT = "<";
|
|
181
|
+
var GT = ">";
|
|
182
|
+
var QUOT = """;
|
|
183
|
+
function isDef(value) {
|
|
184
|
+
return value !== null && value !== void 0;
|
|
185
|
+
}
|
|
186
|
+
function escapeHtml(str) {
|
|
187
|
+
const parts = [];
|
|
188
|
+
let last = 0;
|
|
189
|
+
for (let i = 0; i < str.length; i++) {
|
|
190
|
+
const ch = str.charCodeAt(i);
|
|
191
|
+
let escaped;
|
|
192
|
+
if (ch === 38) escaped = AMP;
|
|
193
|
+
else if (ch === 60) escaped = LT;
|
|
194
|
+
else if (ch === 62) escaped = GT;
|
|
195
|
+
if (escaped) {
|
|
196
|
+
parts.push(str.slice(last, i), escaped);
|
|
197
|
+
last = i + 1;
|
|
198
|
+
}
|
|
199
|
+
}
|
|
200
|
+
if (last === 0) return str;
|
|
201
|
+
parts.push(str.slice(last));
|
|
202
|
+
return parts.join("");
|
|
203
|
+
}
|
|
204
|
+
function escapeAttr(str) {
|
|
205
|
+
const parts = [];
|
|
206
|
+
let last = 0;
|
|
207
|
+
for (let i = 0; i < str.length; i++) {
|
|
208
|
+
const ch = str.charCodeAt(i);
|
|
209
|
+
let escaped;
|
|
210
|
+
if (ch === 38) escaped = AMP;
|
|
211
|
+
else if (ch === 34) escaped = QUOT;
|
|
212
|
+
else if (ch === 60) escaped = LT;
|
|
213
|
+
else if (ch === 62) escaped = GT;
|
|
214
|
+
if (escaped) {
|
|
215
|
+
parts.push(str.slice(last, i), escaped);
|
|
216
|
+
last = i + 1;
|
|
217
|
+
}
|
|
218
|
+
}
|
|
219
|
+
if (last === 0) return str;
|
|
220
|
+
parts.push(str.slice(last));
|
|
221
|
+
return parts.join("");
|
|
222
|
+
}
|
|
223
|
+
function styleToString(style) {
|
|
224
|
+
const parts = [];
|
|
225
|
+
for (const key in style) {
|
|
226
|
+
const value = style[key];
|
|
227
|
+
if (!isDef(value) || value === "") continue;
|
|
228
|
+
const cssKey = key.replace(/[A-Z]/g, (m) => "-" + m.toLowerCase());
|
|
229
|
+
parts.push(`${cssKey}:${value}`);
|
|
230
|
+
}
|
|
231
|
+
return parts.join(";");
|
|
232
|
+
}
|
|
233
|
+
function renderJsxToString(vnode, options2) {
|
|
234
|
+
const mode = options2?.mode ?? "pretty";
|
|
235
|
+
const isPretty = mode === "pretty";
|
|
236
|
+
const blockSet = new Set(DEFAULT_BLOCK_ELEMENTS);
|
|
237
|
+
if (options2?.blockElements) {
|
|
238
|
+
for (const el of options2.blockElements) {
|
|
239
|
+
blockSet.add(el);
|
|
240
|
+
}
|
|
241
|
+
}
|
|
242
|
+
const contextStacks = /* @__PURE__ */ new Map();
|
|
243
|
+
function pushCtx(contextId, value) {
|
|
244
|
+
let stack = contextStacks.get(contextId);
|
|
245
|
+
if (!stack) {
|
|
246
|
+
stack = [];
|
|
247
|
+
contextStacks.set(contextId, stack);
|
|
248
|
+
}
|
|
249
|
+
stack.push(value);
|
|
250
|
+
}
|
|
251
|
+
function popCtx(contextId) {
|
|
252
|
+
contextStacks.get(contextId)?.pop();
|
|
253
|
+
}
|
|
254
|
+
function buildGlobalContext() {
|
|
255
|
+
const globalCtx = {};
|
|
256
|
+
for (const [contextId, stack] of contextStacks) {
|
|
257
|
+
if (stack.length > 0) {
|
|
258
|
+
globalCtx[contextId] = {
|
|
259
|
+
props: { value: stack[stack.length - 1] },
|
|
260
|
+
sub: noop
|
|
261
|
+
};
|
|
262
|
+
}
|
|
263
|
+
}
|
|
264
|
+
return globalCtx;
|
|
265
|
+
}
|
|
266
|
+
function render(node, inline) {
|
|
267
|
+
if (!isDef(node) || typeof node === "boolean") return "";
|
|
268
|
+
if (typeof node === "string") return escapeHtml(node);
|
|
269
|
+
if (typeof node === "number" || typeof node === "bigint")
|
|
270
|
+
return String(node);
|
|
271
|
+
if (Array.isArray(node)) return node.map((n) => render(n, inline)).join("");
|
|
272
|
+
if (typeof node !== "object" || !("type" in node)) return "";
|
|
273
|
+
const { type, props } = node;
|
|
274
|
+
if (type === Fragment) {
|
|
275
|
+
return renderChildren(props?.children);
|
|
276
|
+
}
|
|
277
|
+
if (typeof type === "function") {
|
|
278
|
+
return renderComponent(node);
|
|
279
|
+
}
|
|
280
|
+
if (typeof type === "string") {
|
|
281
|
+
return renderElement(type, props, inline);
|
|
282
|
+
}
|
|
283
|
+
return "";
|
|
284
|
+
}
|
|
285
|
+
function renderComponent(vnode2) {
|
|
286
|
+
const { type, props } = vnode2;
|
|
287
|
+
const fn = type;
|
|
288
|
+
const fnAny = fn;
|
|
289
|
+
if (fnAny._isProvider && fnAny._context) {
|
|
290
|
+
const ctx = fnAny._context;
|
|
291
|
+
ctx._stack.push(props.value);
|
|
292
|
+
const result = renderChildren(props.children);
|
|
293
|
+
ctx._stack.pop();
|
|
294
|
+
return result;
|
|
295
|
+
}
|
|
296
|
+
let contextId;
|
|
297
|
+
if (typeof fnAny.__c === "string" && fnAny.__c.startsWith("__cC")) {
|
|
298
|
+
contextId = fnAny.__c;
|
|
299
|
+
} else if (fnAny.__ && typeof fnAny.__ === "object" && fnAny.__.__c) {
|
|
300
|
+
contextId = fnAny.__.__c;
|
|
301
|
+
}
|
|
302
|
+
if (contextId) {
|
|
303
|
+
pushCtx(contextId, props.value);
|
|
304
|
+
const result = renderChildren(props.children);
|
|
305
|
+
popCtx(contextId);
|
|
306
|
+
return result;
|
|
307
|
+
}
|
|
308
|
+
if (fn.contextType) {
|
|
309
|
+
const ctx = fn.contextType;
|
|
310
|
+
const ctxId = ctx.__c;
|
|
311
|
+
const stack = contextStacks.get(ctxId);
|
|
312
|
+
const value = stack && stack.length > 0 ? stack[stack.length - 1] : ctx.__;
|
|
313
|
+
if (typeof props.children === "function") {
|
|
314
|
+
return render(props.children(value));
|
|
315
|
+
}
|
|
316
|
+
return renderChildren(props.children);
|
|
317
|
+
}
|
|
318
|
+
const component = {
|
|
319
|
+
props,
|
|
320
|
+
context: buildGlobalContext(),
|
|
321
|
+
state: {},
|
|
322
|
+
__v: vnode2,
|
|
323
|
+
// _vnode
|
|
324
|
+
__d: false,
|
|
325
|
+
// _dirty
|
|
326
|
+
__h: [],
|
|
327
|
+
// _renderCallbacks
|
|
328
|
+
__s: {},
|
|
329
|
+
// _nextState
|
|
330
|
+
__H: null
|
|
331
|
+
// _hooks (initialised by hooks addon)
|
|
332
|
+
};
|
|
333
|
+
vnode2.__c = component;
|
|
334
|
+
preactOptions.__b?.(vnode2);
|
|
335
|
+
preactOptions.__r?.(vnode2);
|
|
336
|
+
try {
|
|
337
|
+
if (fn.prototype && fn.prototype.render) {
|
|
338
|
+
const instance = new fn(props, component.context);
|
|
339
|
+
instance.__n = component.__n;
|
|
340
|
+
instance.__H = component.__H;
|
|
341
|
+
vnode2.__c = instance;
|
|
342
|
+
preactOptions.__r?.(vnode2);
|
|
343
|
+
return render(instance.render(instance.props, instance.state));
|
|
344
|
+
}
|
|
345
|
+
const rendered = fn(props, component.context);
|
|
346
|
+
return render(rendered);
|
|
347
|
+
} finally {
|
|
348
|
+
preactOptions.diffed?.(vnode2);
|
|
349
|
+
}
|
|
350
|
+
}
|
|
351
|
+
function renderElement(tag, props, inline) {
|
|
352
|
+
const isBlock = isPretty && !inline && blockSet.has(tag);
|
|
353
|
+
const isVoid = VOID_ELEMENTS.has(tag);
|
|
354
|
+
const parts = ["<", tag, renderAttrs(tag, props), ">"];
|
|
355
|
+
if (isVoid) {
|
|
356
|
+
if (isBlock) parts.push("\n");
|
|
357
|
+
return parts.join("");
|
|
358
|
+
}
|
|
359
|
+
let inner = "";
|
|
360
|
+
if (isDef(props?.dangerouslySetInnerHTML?.__html)) {
|
|
361
|
+
inner = props.dangerouslySetInnerHTML.__html;
|
|
362
|
+
} else if (isDef(props?.children)) {
|
|
363
|
+
inner = renderChildren(props.children);
|
|
364
|
+
} else if (tag === "textarea" && props) {
|
|
365
|
+
const textVal = props.value ?? props.defaultValue;
|
|
366
|
+
if (isDef(textVal)) {
|
|
367
|
+
inner = escapeHtml(String(textVal));
|
|
368
|
+
}
|
|
369
|
+
}
|
|
370
|
+
if (isBlock) {
|
|
371
|
+
const hasBlockChildren = !RAW_CONTENT_ELEMENTS.has(tag) && inner.includes("\n");
|
|
372
|
+
if (hasBlockChildren) {
|
|
373
|
+
parts.push("\n", inner, "</", tag, ">\n");
|
|
374
|
+
} else {
|
|
375
|
+
parts.push(inner, "</", tag, ">\n");
|
|
376
|
+
}
|
|
377
|
+
} else {
|
|
378
|
+
parts.push(inner, "</", tag, ">");
|
|
379
|
+
}
|
|
380
|
+
return parts.join("");
|
|
381
|
+
}
|
|
382
|
+
function renderAttrs(tag, props) {
|
|
383
|
+
if (!props) return "";
|
|
384
|
+
const parts = [];
|
|
385
|
+
for (const key in props) {
|
|
386
|
+
if (key === "children" || key === "dangerouslySetInnerHTML" || key === "key" || key === "ref" || key === "__self" || key === "__source") {
|
|
387
|
+
continue;
|
|
388
|
+
}
|
|
389
|
+
if (tag === "textarea" && (key === "value" || key === "defaultValue")) {
|
|
390
|
+
continue;
|
|
391
|
+
}
|
|
392
|
+
if (key.length > 2 && key[0] === "o" && key[1] === "n") continue;
|
|
393
|
+
let value = props[key];
|
|
394
|
+
if (!isDef(value)) continue;
|
|
395
|
+
if (value === false && !key.startsWith("data-")) continue;
|
|
396
|
+
const attrName = PROP_TO_ATTR[key] || key;
|
|
397
|
+
if (value === true) {
|
|
398
|
+
parts.push(" ", attrName);
|
|
399
|
+
continue;
|
|
400
|
+
}
|
|
401
|
+
if (key === "style" && typeof value === "object") {
|
|
402
|
+
value = styleToString(value);
|
|
403
|
+
if (!value) continue;
|
|
404
|
+
}
|
|
405
|
+
parts.push(" ", attrName, '="', escapeAttr(String(value)), '"');
|
|
406
|
+
}
|
|
407
|
+
return parts.join("");
|
|
408
|
+
}
|
|
409
|
+
function isTextNode(child) {
|
|
410
|
+
if (!isDef(child) || typeof child === "boolean") return false;
|
|
411
|
+
return typeof child === "string" || typeof child === "number" || typeof child === "bigint";
|
|
412
|
+
}
|
|
413
|
+
function hasMixedContent(children) {
|
|
414
|
+
let hasText = false;
|
|
415
|
+
let hasElement = false;
|
|
416
|
+
for (const child of children) {
|
|
417
|
+
if (isTextNode(child)) {
|
|
418
|
+
hasText = true;
|
|
419
|
+
} else if (isDef(child) && typeof child === "object" && "type" in child) {
|
|
420
|
+
hasElement = true;
|
|
421
|
+
}
|
|
422
|
+
if (hasText && hasElement) return true;
|
|
423
|
+
}
|
|
424
|
+
return false;
|
|
425
|
+
}
|
|
426
|
+
function renderChildren(children) {
|
|
427
|
+
if (!isDef(children)) return "";
|
|
428
|
+
if (Array.isArray(children)) {
|
|
429
|
+
const inline = isPretty && hasMixedContent(children);
|
|
430
|
+
return children.map((child) => render(child, inline)).join("");
|
|
431
|
+
}
|
|
432
|
+
return render(children);
|
|
433
|
+
}
|
|
434
|
+
return render(vnode);
|
|
435
|
+
}
|
|
436
|
+
function noop() {
|
|
437
|
+
}
|
|
438
|
+
|
|
439
|
+
export {
|
|
440
|
+
options,
|
|
441
|
+
Fragment,
|
|
442
|
+
jsx,
|
|
443
|
+
createElement,
|
|
444
|
+
createContext,
|
|
445
|
+
useContext,
|
|
446
|
+
renderJsxToString
|
|
447
|
+
};
|
|
448
|
+
//# sourceMappingURL=chunk-P6EPJRRM.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/jsx/jsx-runtime.ts","../src/jsx/jsx-render.ts"],"sourcesContent":["/**\n * @module jsx-runtime\n *\n * Server-side JSX runtime for Root.js. Replaces Preact as the JSX renderer\n * for server-side rendering (SSR/SSG). This module provides the automatic\n * JSX transform entry point (`jsxImportSource`).\n *\n * Supports:\n * - Automatic JSX transform (jsx, jsxs, Fragment)\n * - Classic JSX transform (createElement / h)\n * - Context API (createContext, useContext)\n * - Server-side renderToString\n */\n\n// =============================================================================\n// Types\n// =============================================================================\n\nexport type Key = string | number | null;\n\n/**\n * A virtual DOM node representing an element, component, or fragment.\n */\nexport interface VNode<P = Record<string, unknown>> {\n type:\n | string\n | FunctionalComponent<P>\n | typeof Fragment\n | (new (...args: any[]) => any);\n props: P;\n key: Key;\n}\n\n/**\n * Valid children types for JSX elements.\n */\nexport type ComponentChildren =\n | VNode<any>\n | string\n | number\n | bigint\n | boolean\n | null\n | undefined\n | ComponentChildren[];\n\nexport type ComponentChild = ComponentChildren;\n\n/**\n * A function component that receives props and returns a VNode or null.\n */\nexport interface FunctionalComponent<P = Record<string, unknown>> {\n (props: P): VNode<any> | null;\n displayName?: string;\n /** @internal Marks this component as a context Provider. */\n _isProvider?: boolean;\n /** @internal Reference to the context object for Provider components. */\n _context?: Context<any>;\n}\n\n/**\n * Generic component type (function components only for SSR).\n */\nexport type ComponentType<P = Record<string, unknown>> = FunctionalComponent<P>;\n\n// =============================================================================\n// Options (vnode lifecycle hook)\n// =============================================================================\n\n/**\n * Global options object. The `vnode` callback is invoked for every VNode\n * created via `jsx()`, `jsxs()`, or `createElement()`. This is used by the\n * renderer to inject nonce values into script/style tags.\n */\nexport const options: {vnode?: (vnode: VNode<any>) => void} = {};\n\n// =============================================================================\n// Fragment\n// =============================================================================\n\n/**\n * Fragment component. Renders its children without a wrapper DOM element.\n * Used as `<>...</>` or `<Fragment>...</Fragment>` in JSX.\n */\nexport function Fragment(props: {children?: ComponentChildren}): any {\n return props.children;\n}\n\n// =============================================================================\n// JSX Automatic Runtime (jsx / jsxs)\n// =============================================================================\n\n/**\n * Creates a VNode. Used by the automatic JSX transform for elements with\n * a single child or no children.\n */\nexport function jsx(\n type: string | FunctionalComponent<any> | typeof Fragment,\n props: Record<string, any>,\n key?: Key\n): VNode {\n const resolvedKey = key !== undefined ? key : props.key ?? null;\n const vnode: VNode = {\n type,\n props,\n key: resolvedKey,\n };\n\n // Strip `key` from props (it's stored on the VNode directly).\n if (props.key !== undefined) {\n const {key: _, ...rest} = props;\n vnode.props = rest;\n }\n\n if (options.vnode) {\n options.vnode(vnode);\n }\n\n return vnode;\n}\n\n/**\n * Creates a VNode with static children. Used by the automatic JSX transform\n * for elements with multiple children. Identical to `jsx()` for SSR since\n * we don't need to diff children.\n */\nexport {jsx as jsxs};\n\n// =============================================================================\n// Classic Runtime (createElement / h)\n// =============================================================================\n\n/**\n * Creates a VNode. Compatible with the classic `React.createElement` API.\n *\n * ```ts\n * createElement('div', {className: 'foo'}, 'Hello', ' ', 'World');\n * ```\n */\nexport function createElement(\n type: string | FunctionalComponent<any> | typeof Fragment,\n props?: Record<string, any> | null,\n ...children: any[]\n): VNode {\n const normalizedProps: Record<string, any> = {...(props || {})};\n\n if (children.length === 1) {\n normalizedProps.children = children[0];\n } else if (children.length > 1) {\n normalizedProps.children = children;\n }\n\n const vnode: VNode = {\n type,\n props: normalizedProps,\n key: normalizedProps.key ?? null,\n };\n\n if (normalizedProps.key !== undefined) {\n delete normalizedProps.key;\n }\n\n if (options.vnode) {\n options.vnode(vnode);\n }\n\n return vnode;\n}\n\nexport {createElement as h};\n\n// =============================================================================\n// Context API\n// =============================================================================\n\n/**\n * A context object created by `createContext()`. Provides a `Provider`\n * component and can be read via `useContext()`.\n */\nexport interface Context<T> {\n /** @internal Default value for this context. */\n _defaultValue: T;\n /** @internal Stack of provided values (managed by renderToString). */\n _stack: T[];\n /** Provider component that supplies a context value to descendants. */\n Provider: FunctionalComponent<{value: T; children?: ComponentChildren}>;\n}\n\n/**\n * Creates a new context with an optional default value. Returns a context\n * object with a `Provider` component.\n *\n * ```ts\n * const ThemeContext = createContext('light');\n *\n * // In a parent component:\n * <ThemeContext.Provider value=\"dark\">\n * <App />\n * </ThemeContext.Provider>\n *\n * // In a child component:\n * const theme = useContext(ThemeContext);\n * ```\n */\nexport function createContext<T>(defaultValue: T): Context<T> {\n const ctx: Context<T> = {\n _defaultValue: defaultValue,\n _stack: [],\n Provider: null as any,\n };\n\n const Provider: FunctionalComponent<{\n value: T;\n children?: ComponentChildren;\n }> = () => {\n // Provider rendering is handled specially by renderToString, which\n // pushes/pops the context value around rendering children. This function\n // body is never actually called during normal SSR rendering.\n return null;\n };\n Provider.displayName = 'ContextProvider';\n Provider._isProvider = true;\n Provider._context = ctx;\n ctx.Provider = Provider;\n\n return ctx;\n}\n\n/**\n * Reads the current value of a context. Must be called during the render\n * of a function component that is a descendant of a matching Provider.\n * Returns the default value if no Provider is found.\n *\n * ```ts\n * const theme = useContext(ThemeContext);\n * ```\n */\nexport function useContext<T>(context: Context<T>): T {\n const stack = context._stack;\n if (stack.length > 0) {\n return stack[stack.length - 1];\n }\n return context._defaultValue;\n}\n\n// Re-export JSX namespace for the automatic transform.\n// TypeScript resolves JSX types from `{jsxImportSource}/jsx-runtime`.\nexport type {JSX} from './types.js';\n","import {options as preactOptions} from 'preact';\nimport {VNode, Fragment} from './jsx-runtime.js';\n\n/** HTML void elements (self-closing, no end tag). */\nconst VOID_ELEMENTS = new Set([\n 'area',\n 'base',\n 'br',\n 'col',\n 'embed',\n 'hr',\n 'img',\n 'input',\n 'link',\n 'meta',\n 'param',\n 'source',\n 'track',\n 'wbr',\n]);\n\n/** Tags whose text content may contain literal newlines that should not be treated as block-child indicators. */\nconst RAW_CONTENT_ELEMENTS = new Set(['pre', 'textarea', 'script', 'style']);\n\n/** Standard HTML block-level elements. */\nconst DEFAULT_BLOCK_ELEMENTS = new Set([\n 'address',\n 'article',\n 'aside',\n 'blockquote',\n 'body',\n 'dd',\n 'details',\n 'dialog',\n 'div',\n 'dl',\n 'dt',\n 'fieldset',\n 'figcaption',\n 'figure',\n 'footer',\n 'form',\n 'h1',\n 'h2',\n 'h3',\n 'h4',\n 'h5',\n 'h6',\n 'head',\n 'header',\n 'hgroup',\n 'hr',\n 'html',\n 'li',\n 'link',\n 'main',\n 'meta',\n 'nav',\n 'noscript',\n 'ol',\n 'p',\n 'pre',\n 'script',\n 'search',\n 'section',\n 'style',\n 'summary',\n 'table',\n 'tbody',\n 'td',\n 'tfoot',\n 'th',\n 'thead',\n 'title',\n 'tr',\n 'ul',\n]);\n\n/** JSX prop name -> HTML attribute name. */\nconst PROP_TO_ATTR: Record<string, string> = {\n acceptCharset: 'accept-charset',\n autoCapitalize: 'autocapitalize',\n autoComplete: 'autocomplete',\n autoFocus: 'autofocus',\n autoPlay: 'autoplay',\n charSet: 'charset',\n className: 'class',\n colSpan: 'colspan',\n contentEditable: 'contenteditable',\n crossOrigin: 'crossorigin',\n dateTime: 'datetime',\n encType: 'enctype',\n formAction: 'formaction',\n formEncType: 'formenctype',\n formMethod: 'formmethod',\n formNoValidate: 'formnovalidate',\n formTarget: 'formtarget',\n frameBorder: 'frameborder',\n hrefLang: 'hreflang',\n htmlFor: 'for',\n httpEquiv: 'http-equiv',\n inputMode: 'inputmode',\n itemProp: 'itemprop',\n itemRef: 'itemref',\n itemScope: 'itemscope',\n itemType: 'itemtype',\n maxLength: 'maxlength',\n mediaGroup: 'mediagroup',\n minLength: 'minlength',\n noModule: 'nomodule',\n noValidate: 'novalidate',\n playsInline: 'playsinline',\n readOnly: 'readonly',\n referrerPolicy: 'referrerpolicy',\n rowSpan: 'rowspan',\n spellCheck: 'spellcheck',\n srcDoc: 'srcdoc',\n srcLang: 'srclang',\n srcSet: 'srcset',\n tabIndex: 'tabindex',\n useMap: 'usemap',\n};\n\nconst AMP = '&';\nconst LT = '<';\nconst GT = '>';\nconst QUOT = '"';\n\n/** Returns `true` when `value` is neither `null` nor `undefined`. */\nfunction isDef<T>(value: T | null | undefined): value is T {\n return value !== null && value !== undefined;\n}\n\nfunction escapeHtml(str: string): string {\n const parts: string[] = [];\n let last = 0;\n for (let i = 0; i < str.length; i++) {\n const ch = str.charCodeAt(i);\n let escaped: string | undefined;\n if (ch === 38) escaped = AMP;\n else if (ch === 60) escaped = LT;\n else if (ch === 62) escaped = GT;\n if (escaped) {\n parts.push(str.slice(last, i), escaped);\n last = i + 1;\n }\n }\n if (last === 0) return str;\n parts.push(str.slice(last));\n return parts.join('');\n}\n\nfunction escapeAttr(str: string): string {\n const parts: string[] = [];\n let last = 0;\n for (let i = 0; i < str.length; i++) {\n const ch = str.charCodeAt(i);\n let escaped: string | undefined;\n if (ch === 38) escaped = AMP;\n else if (ch === 34) escaped = QUOT;\n else if (ch === 60) escaped = LT;\n else if (ch === 62) escaped = GT;\n if (escaped) {\n parts.push(str.slice(last, i), escaped);\n last = i + 1;\n }\n }\n if (last === 0) return str;\n parts.push(str.slice(last));\n return parts.join('');\n}\n\nfunction styleToString(style: Record<string, any>): string {\n const parts: string[] = [];\n for (const key in style) {\n const value = style[key];\n if (!isDef(value) || value === '') continue;\n // Convert camelCase to kebab-case.\n const cssKey = key.replace(/[A-Z]/g, (m) => '-' + m.toLowerCase());\n parts.push(`${cssKey}:${value}`);\n }\n return parts.join(';');\n}\n\nexport interface JsxRenderOptions {\n /** Render mode. `'pretty'` adds newlines around block elements; `'minimal'` outputs compact HTML. Default: `'pretty'`. */\n mode?: 'pretty' | 'minimal';\n /** Additional tag names to treat as block-level elements in pretty mode. */\n blockElements?: string[];\n}\n\n/**\n * Renders a Preact VNode tree to an HTML string.\n */\nexport function renderJsxToString(\n vnode: VNode,\n options?: JsxRenderOptions\n): string {\n const mode = options?.mode ?? 'pretty';\n const isPretty = mode === 'pretty';\n const blockSet = new Set(DEFAULT_BLOCK_ELEMENTS);\n if (options?.blockElements) {\n for (const el of options.blockElements) {\n blockSet.add(el);\n }\n }\n\n // Context stacks: context.__c (id) -> value[]\n const contextStacks = new Map<string, any[]>();\n\n function pushCtx(contextId: string, value: any) {\n let stack = contextStacks.get(contextId);\n if (!stack) {\n stack = [];\n contextStacks.set(contextId, stack);\n }\n stack.push(value);\n }\n\n function popCtx(contextId: string) {\n contextStacks.get(contextId)?.pop();\n }\n\n /** Builds the __n (global context) map for hooks. */\n function buildGlobalContext(): Record<string, any> {\n const globalCtx: Record<string, any> = {};\n for (const [contextId, stack] of contextStacks) {\n if (stack.length > 0) {\n // useContext expects provider.props.value and provider.sub().\n globalCtx[contextId] = {\n props: {value: stack[stack.length - 1]},\n sub: noop,\n };\n }\n }\n return globalCtx;\n }\n\n function render(node: any, inline?: boolean): string {\n if (!isDef(node) || typeof node === 'boolean') return '';\n if (typeof node === 'string') return escapeHtml(node);\n if (typeof node === 'number' || typeof node === 'bigint')\n return String(node);\n if (Array.isArray(node)) return node.map((n) => render(n, inline)).join('');\n\n // Must be a VNode-like object.\n if (typeof node !== 'object' || !('type' in node)) return '';\n\n const {type, props} = node;\n\n // Fragment.\n if (type === Fragment) {\n return renderChildren(props?.children);\n }\n\n // Component (function or class).\n if (typeof type === 'function') {\n return renderComponent(node);\n }\n\n // HTML element.\n if (typeof type === 'string') {\n return renderElement(type, props, inline);\n }\n\n return '';\n }\n\n function renderComponent(vnode: VNode): string {\n const {type, props} = vnode;\n const fn = type as Function;\n\n // Detect context Provider.\n // Root.js local JSX runtime: Provider._isProvider === true, Provider._context\n // is the Context object with a _stack array.\n // Preact >=10.27: Provider === Context (same function). `fn.__c` is the\n // context id string (e.g. \"__cC0\").\n // Preact <10.27: Provider._contextRef (mangled `fn.__`) points to the\n // context object which has `__c` (id) and `__` (default value).\n const fnAny = fn as any;\n if (fnAny._isProvider && fnAny._context) {\n const ctx = fnAny._context;\n ctx._stack.push((props as any).value);\n const result = renderChildren(props.children);\n ctx._stack.pop();\n return result;\n }\n let contextId: string | undefined;\n if (typeof fnAny.__c === 'string' && fnAny.__c.startsWith('__cC')) {\n contextId = fnAny.__c;\n } else if (fnAny.__ && typeof fnAny.__ === 'object' && fnAny.__.__c) {\n contextId = fnAny.__.__c;\n }\n if (contextId) {\n pushCtx(contextId, (props as any).value);\n const result = renderChildren(props.children);\n popCtx(contextId);\n return result;\n }\n\n // Detect context Consumer.\n if ((fn as any).contextType) {\n const ctx = (fn as any).contextType;\n const ctxId: string = ctx.__c;\n const stack = contextStacks.get(ctxId);\n const value =\n stack && stack.length > 0 ? stack[stack.length - 1] : ctx.__;\n if (typeof props.children === 'function') {\n return render(props.children(value));\n }\n return renderChildren(props.children);\n }\n\n // Regular component — set up a fake component instance so Preact hooks\n // (useContext, useState, useMemo, etc.) work during SSR.\n // Preact's useContext reads from `component.context[context.__c]`.\n const component: any = {\n props,\n context: buildGlobalContext(),\n state: {},\n __v: vnode, // _vnode\n __d: false, // _dirty\n __h: [], // _renderCallbacks\n __s: {}, // _nextState\n __H: null, // _hooks (initialised by hooks addon)\n };\n (vnode as any).__c = component;\n\n // Trigger Preact option hooks so the hooks addon can set currentComponent.\n (preactOptions as any).__b?.(vnode);\n (preactOptions as any).__r?.(vnode);\n\n try {\n // Class component.\n if (fn.prototype && fn.prototype.render) {\n const instance = new (fn as any)(props, component.context);\n instance.__n = component.__n;\n instance.__H = component.__H;\n (vnode as any).__c = instance;\n (preactOptions as any).__r?.(vnode);\n return render(instance.render(instance.props, instance.state));\n }\n\n // Functional component.\n const rendered = fn(props, component.context);\n return render(rendered);\n } finally {\n preactOptions.diffed?.(vnode as any);\n }\n }\n\n function renderElement(\n tag: string,\n props: Record<string, any>,\n inline?: boolean\n ): string {\n const isBlock = isPretty && !inline && blockSet.has(tag);\n const isVoid = VOID_ELEMENTS.has(tag);\n\n const parts: string[] = ['<', tag, renderAttrs(tag, props), '>'];\n\n if (isVoid) {\n if (isBlock) parts.push('\\n');\n return parts.join('');\n }\n\n let inner = '';\n if (isDef(props?.dangerouslySetInnerHTML?.__html)) {\n inner = props.dangerouslySetInnerHTML.__html;\n } else if (isDef(props?.children)) {\n inner = renderChildren(props.children);\n } else if (tag === 'textarea' && props) {\n // For <textarea>, render value/defaultValue as text content since\n // browsers ignore the value attribute on textarea elements.\n const textVal = props.value ?? props.defaultValue;\n if (isDef(textVal)) {\n inner = escapeHtml(String(textVal));\n }\n }\n\n if (isBlock) {\n // When inner content contains block children (indicated by newlines),\n // add a newline after the opening tag so content starts on its own line.\n // Exempt raw-content elements (pre, textarea, script, style) where\n // newlines are literal text, not block-child indicators.\n const hasBlockChildren =\n !RAW_CONTENT_ELEMENTS.has(tag) && inner.includes('\\n');\n if (hasBlockChildren) {\n parts.push('\\n', inner, '</', tag, '>\\n');\n } else {\n parts.push(inner, '</', tag, '>\\n');\n }\n } else {\n parts.push(inner, '</', tag, '>');\n }\n\n return parts.join('');\n }\n\n function renderAttrs(tag: string, props: Record<string, any>): string {\n if (!props) return '';\n const parts: string[] = [];\n for (const key in props) {\n if (\n key === 'children' ||\n key === 'dangerouslySetInnerHTML' ||\n key === 'key' ||\n key === 'ref' ||\n key === '__self' ||\n key === '__source'\n ) {\n continue;\n }\n // Skip value/defaultValue on textarea — rendered as text content.\n if (tag === 'textarea' && (key === 'value' || key === 'defaultValue')) {\n continue;\n }\n // Skip event handlers.\n if (key.length > 2 && key[0] === 'o' && key[1] === 'n') continue;\n\n let value = props[key];\n if (!isDef(value)) continue;\n // For standard and boolean attributes, `false` removes the attribute.\n // For data-* attributes, `false` is rendered as the string \"false\".\n if (value === false && !key.startsWith('data-')) continue;\n\n const attrName = PROP_TO_ATTR[key] || key;\n\n // Boolean attributes.\n if (value === true) {\n parts.push(' ', attrName);\n continue;\n }\n\n // Style objects.\n if (key === 'style' && typeof value === 'object') {\n value = styleToString(value);\n if (!value) continue;\n }\n\n parts.push(' ', attrName, '=\"', escapeAttr(String(value)), '\"');\n }\n return parts.join('');\n }\n\n /**\n * Returns true if a child node is a text-like value (string, number).\n */\n function isTextNode(child: any): boolean {\n if (!isDef(child) || typeof child === 'boolean') return false;\n return (\n typeof child === 'string' ||\n typeof child === 'number' ||\n typeof child === 'bigint'\n );\n }\n\n /**\n * Checks if an array of children contains a mix of text nodes and elements.\n * When mixed, block elements should render inline to avoid breaking text flow.\n */\n function hasMixedContent(children: any[]): boolean {\n let hasText = false;\n let hasElement = false;\n for (const child of children) {\n if (isTextNode(child)) {\n hasText = true;\n } else if (isDef(child) && typeof child === 'object' && 'type' in child) {\n hasElement = true;\n }\n if (hasText && hasElement) return true;\n }\n return false;\n }\n\n function renderChildren(children: any): string {\n if (!isDef(children)) return '';\n if (Array.isArray(children)) {\n const inline = isPretty && hasMixedContent(children);\n return children.map((child) => render(child, inline)).join('');\n }\n return render(children);\n }\n\n return render(vnode);\n}\n\nfunction noop() {}\n"],"mappings":";AA0EO,IAAM,UAAiD,CAAC;AAUxD,SAAS,SAAS,OAA4C;AACnE,SAAO,MAAM;AACf;AAUO,SAAS,IACd,MACA,OACA,KACO;AACP,QAAM,cAAc,QAAQ,SAAY,MAAM,MAAM,OAAO;AAC3D,QAAM,QAAe;AAAA,IACnB;AAAA,IACA;AAAA,IACA,KAAK;AAAA,EACP;AAGA,MAAI,MAAM,QAAQ,QAAW;AAC3B,UAAM,EAAC,KAAK,GAAG,GAAG,KAAI,IAAI;AAC1B,UAAM,QAAQ;AAAA,EAChB;AAEA,MAAI,QAAQ,OAAO;AACjB,YAAQ,MAAM,KAAK;AAAA,EACrB;A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;AAAA,MACF;AAGA,UAAI,QAAQ,WAAW,OAAO,UAAU,UAAU;AAChD,gBAAQ,cAAc,KAAK;AAC3B,YAAI,CAAC,MAAO;AAAA,MACd;AAEA,YAAM,KAAK,KAAK,UAAU,MAAM,WAAW,OAAO,KAAK,CAAC,GAAG,GAAG;AAAA,IAChE;AACA,WAAO,MAAM,KAAK,EAAE;AAAA,EACtB;AAKA,WAAS,WAAW,OAAqB;AACvC,QAAI,CAAC,MAAM,KAAK,KAAK,OAAO,UAAU,UAAW,QAAO;AACxD,WACE,OAAO,UAAU,YACjB,OAAO,UAAU,YACjB,OAAO,UAAU;AAAA,EAErB;AAMA,WAAS,gBAAgB,UAA0B;AACjD,QAAI,UAAU;AACd,QAAI,aAAa;AACjB,eAAW,SAAS,UAAU;AAC5B,UAAI,WAAW,KAAK,GAAG;AACrB,kBAAU;AAAA,MACZ,WAAW,MAAM,KAAK,KAAK,OAAO,UAAU,YAAY,UAAU,OAAO;AACvE,qBAAa;AAAA,MACf;AACA,UAAI,WAAW,WAAY,QAAO;AAAA,IACpC;AACA,WAAO;AAAA,EACT;AAEA,WAAS,eAAe,UAAuB;AAC7C,QAAI,CAAC,MAAM,QAAQ,EAAG,QAAO;AAC7B,QAAI,MAAM,QAAQ,QAAQ,GAAG;AAC3B,YAAM,SAAS,YAAY,gBAAgB,QAAQ;AACnD,aAAO,SAAS,IAAI,CAAC,UAAU,OAAO,OAAO,MAAM,CAAC,EAAE,KAAK,EAAE;AAAA,IAC/D;AACA,WAAO,OAAO,QAAQ;AAAA,EACxB;AAEA,SAAO,OAAO,KAAK;AACrB;AAEA,SAAS,OAAO;AAAC;","names":["options","vnode"]}
|
package/dist/cli.d.ts
CHANGED
|
@@ -1,9 +1,10 @@
|
|
|
1
|
-
import { S as Server } from './types-
|
|
1
|
+
import { S as Server } from './types-yeULDLJI.js';
|
|
2
2
|
import 'express';
|
|
3
3
|
import 'preact';
|
|
4
4
|
import 'vite';
|
|
5
5
|
import 'html-minifier-terser';
|
|
6
6
|
import 'js-beautify';
|
|
7
|
+
import './jsx-render-BCCySLjz.js';
|
|
7
8
|
|
|
8
9
|
interface BuildOptions {
|
|
9
10
|
ssrOnly?: boolean;
|
package/dist/core.d.ts
CHANGED
|
@@ -1,11 +1,12 @@
|
|
|
1
|
-
import { R as Route } from './types-
|
|
2
|
-
export { j as ConfigureServerHook, k as ConfigureServerOptions, C as ContentSecurityPolicyConfig, w as GetStaticContent, q as GetStaticPaths, G as GetStaticProps, u as Handler, H as HandlerContext, z as HandlerRenderFn, y as HandlerRenderOptions, L as LocaleGroup, M as MultipartFile, N as NextFunction, m as Plugin, l as PluginHooks, P as PostBuildOptions, s as Request, r as RequestMiddleware, t as Response, d as RootBuildConfig, b as RootConfig, f as RootHeaderConfig, c as RootI18nConfig, e as RootRedirectConfig, g as RootSecurityConfig, h as RootServerConfig, a as RootUserConfig, x as RouteModule, p as RouteParams, S as Server, A as Sitemap, B as SitemapItem, v as StaticContentResult, X as XFrameOptionsConfig, n as configureServerPlugins, i as defineConfig, o as getVitePlugins } from './types-
|
|
1
|
+
import { R as Route } from './types-yeULDLJI.js';
|
|
2
|
+
export { j as ConfigureServerHook, k as ConfigureServerOptions, C as ContentSecurityPolicyConfig, w as GetStaticContent, q as GetStaticPaths, G as GetStaticProps, u as Handler, H as HandlerContext, z as HandlerRenderFn, y as HandlerRenderOptions, L as LocaleGroup, M as MultipartFile, N as NextFunction, m as Plugin, l as PluginHooks, P as PostBuildOptions, s as Request, r as RequestMiddleware, t as Response, d as RootBuildConfig, b as RootConfig, f as RootHeaderConfig, c as RootI18nConfig, e as RootRedirectConfig, g as RootSecurityConfig, h as RootServerConfig, a as RootUserConfig, x as RouteModule, p as RouteParams, S as Server, A as Sitemap, B as SitemapItem, v as StaticContentResult, X as XFrameOptionsConfig, n as configureServerPlugins, i as defineConfig, o as getVitePlugins } from './types-yeULDLJI.js';
|
|
3
3
|
import * as preact$1 from 'preact';
|
|
4
4
|
import { FunctionalComponent, ComponentChildren } from 'preact';
|
|
5
5
|
import 'express';
|
|
6
6
|
import 'vite';
|
|
7
7
|
import 'html-minifier-terser';
|
|
8
8
|
import 'js-beautify';
|
|
9
|
+
import './jsx-render-BCCySLjz.js';
|
|
9
10
|
|
|
10
11
|
type BodyProps = preact.JSX.HTMLAttributes<HTMLBodyElement> & {
|
|
11
12
|
children?: ComponentChildren;
|
package/dist/core.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/core/config.ts","../src/core/components/Body.tsx","../src/core/components/Head.ts","../src/core/components/Script.ts","../src/core/hooks/useStringParams.tsx","../src/core/hooks/useTranslationsMiddleware.tsx","../src/core/hooks/useTranslations.ts"],"sourcesContent":["import {UserConfig as ViteUserConfig} from 'vite';\nimport {HtmlMinifyOptions} from '../render/html-minify.js';\nimport {HtmlPrettyOptions} from '../render/html-pretty.js';\nimport {Plugin} from './plugin.js';\nimport {RequestMiddleware} from './types.js';\n\nexport interface RootUserConfig {\n /**\n * Canonical domain the website will serve on. Useful for things like the\n * sitemap, SEO tags, etc.\n */\n domain?: string;\n\n /**\n * The base URL path that the site will serve on. Defaults to `/`;\n */\n base?: string;\n\n /**\n * Config for auto-injecting custom element dependencies.\n */\n elements?: {\n /**\n * A list of directories to use to look for custom elements. The dir path\n * should be relative to the project dir, e.g. \"path/to/elements\".\n */\n include?: string[];\n\n /**\n * A list of RegEx patterns to exclude. The string passed to the RegEx is\n * the file URL relative to the project root, e.g. \"/elements/foo/foo.ts\".\n */\n exclude?: RegExp[];\n };\n\n /**\n * Config for manually injecting stylesheet entries as\n * `<link rel=\"stylesheet\">` tags.\n */\n styles?: {\n /**\n * Project-root-relative stylesheet files to include on every rendered\n * page, e.g. `styles/index.css`.\n *\n * Entries are normalized as URL paths, so both `styles/index.css` and\n * `/styles/index.css` resolve to `/styles/index.css`.\n *\n * Manual entries are injected first, then auto-collected CSS\n * dependencies are merged after. Duplicate URLs are de-duped so each\n * stylesheet is only injected once.\n */\n entries?: string[];\n };\n\n /**\n * Config options for localization and internationalization.\n */\n i18n?: RootI18nConfig;\n\n /**\n * Config options for the Root.js express server.\n */\n server?: RootServerConfig;\n\n /**\n * Build options for the `root build` command.\n */\n build?: RootBuildConfig;\n\n /**\n * Vite config.\n * @see {@link https://vitejs.dev/config/} for more information.\n */\n vite?: ViteUserConfig;\n\n /**\n * Whether to automatically minify HTML output. This is enabled by default,\n * in order to disable, pass `minifyHtml: false` to root.config.ts.\n */\n minifyHtml?: boolean;\n\n /**\n * Options to pass to html-minifier-terser.\n */\n minifyHtmlOptions?: HtmlMinifyOptions;\n\n /**\n * Whether to pretty print HTML output.\n */\n prettyHtml?: boolean;\n\n /**\n * Options to pass to js-beautify.\n */\n prettyHtmlOptions?: HtmlPrettyOptions;\n\n /**\n * Whether to include a sitemap.xml file to the build output.\n */\n sitemap?: boolean;\n\n /**\n * Plugins.\n */\n plugins?: Plugin[];\n\n /**\n * Experimental config options. Note: these are subject to change at any time.\n */\n experiments?: {\n /** Whether to render `<script>` tags with `async`. */\n enableScriptAsync?: boolean;\n };\n}\n\nexport type RootConfig = RootUserConfig & {\n rootDir: string;\n};\n\nexport interface LocaleGroup {\n label?: string;\n locales: string[];\n}\n\nexport interface RootI18nConfig {\n /**\n * Locales enabled for the site.\n */\n locales?: string[];\n\n /**\n * The default locale to use. Defaults is `en`.\n */\n defaultLocale?: string;\n\n /**\n * URL format for localized content. Default is `/[locale]/[base]/[path]`.\n */\n urlFormat?: string;\n\n /**\n * Localization groups, to help UIs (like Root.js CMS) logically group\n * locales.\n */\n groups?: Record<string, LocaleGroup>;\n}\n\nexport interface RootBuildConfig {\n /**\n * Excludes the `/intl/{defaultLocale}/...` path from the SSG build.\n */\n excludeDefaultLocaleFromIntlPaths?: boolean;\n}\n\nexport interface RootRedirectConfig {\n /**\n * The source path to redirect. Accepts placeholders in the format\n * `[key]` or `[...key]`. Use `[key]` for single segments and\n * `[...key]` for multi-segment wildcards.\n * @example \"/old-path/[id]\" or \"/old-path/[...wildcard]\"\n */\n source: string;\n\n /**\n * The destination to redirect to. Placeholders from the source can\n * optionally be inserted into the destination using the same\n * placeholder format.\n * @example \"/new-path/[id]\" or \"/new-path/[...wildcard]\"\n */\n destination: string;\n\n /**\n * The redirect type (`301` = permanent, `302` = temporary). If unspecified,\n * defaults to `302` (temporary).\n */\n type?: 301 | 302;\n}\n\nexport interface RootHeaderConfig {\n /** A glob pattern match (regex not supported yet). */\n source: string;\n headers: Array<{\n key: string;\n value: string;\n }>;\n}\n\nexport interface ContentSecurityPolicyConfig {\n directives?: Record<string, string[]>;\n reportOnly?: boolean;\n}\n\nexport interface XFrameOptionsConfig {\n action: 'DENY' | 'SAMEORIGIN';\n}\n\nexport interface RootSecurityConfig {\n /**\n * Content-Security-Policy config. If enabled, a nonce is auto-generated\n * for every request and appended to script and stylesheet tags. You can\n * validate your CSP headers using a tool like {@link https://csp-evaluator.withgoogle.com/}.\n *\n * @see {@link https://developer.mozilla.org/en-US/docs/Web/HTTP/CSP}\n */\n contentSecurityPolicy?: ContentSecurityPolicyConfig | boolean;\n\n /**\n * Strict-Transport-Security config. When enabled, the header value is set\n * to `Strict-Transport-Security: max-age=63072000; includeSubDomains; preload`.\n */\n strictTransportSecurity?: boolean;\n\n /**\n * X-Content-Type-Options config. When enabled, the header value is set to\n * `X-Content-Type-Options: nosniff`.\n */\n xContentTypeOptions?: boolean;\n\n /**\n * X-Frame-Options config. Setting this value to `true` will default the\n * header value to `X-Frame-Options: SAMEORIGIN`.\n *\n * @see {@link https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/X-Frame-Options}\n */\n xFrameOptions?: 'DENY' | 'SAMEORIGIN' | boolean;\n\n /**\n * X-XSS-Protection config. When enabled, the header value is set to\n * `X-XSS-Protection: 1; mode=block`.\n */\n xXssProtection?: boolean;\n}\n\nexport interface RootServerConfig {\n /**\n * An array of middleware to add to the express server. These middleware are\n * added to the beginning of the express app.\n */\n middlewares?: RequestMiddleware[];\n\n /**\n * The `trailingSlash` config allows you to control how the server handles\n * trailing slashes. This config only affects URLs that do not have a file\n * extension (i.e. HTML paths).\n *\n * - When `true`, the server redirects URLs to add a trailing slash\n * - When `false`, the server redirects URLs to remove a trailing slash\n * - When unspecified, the server allows URLs with and without trailing slash\n */\n trailingSlash?: boolean;\n\n /**\n * Cookie secret for the session middleware.\n *\n * Generate a secure secret with:\n * ```\n * node -e \"console.log(require('crypto').randomBytes(32).toString('hex'))\"\n * ```\n */\n sessionCookieSecret?: string | string[];\n\n /**\n * List of redirects. Supports optional wildcards.\n *\n * @example\n * ```ts\n * redirects: [\n * {\n * source: '/old-path/[id]',\n * destination: '/new-path/[id]',\n * type: 301,\n * },\n * {\n * source: '/old-path/[...wildcard]',\n * destination: '/new-path/[...wildcard]',\n * },\n * ]\n * ```\n */\n redirects?: RootRedirectConfig[];\n\n /**\n * HTTP headers to add to a response.\n */\n headers?: RootHeaderConfig[];\n\n /**\n * HTTP security settings. By default, all security settings are enabled with\n * commonly used default values.\n */\n security?: RootSecurityConfig;\n\n /**\n * Home page URL path, which is printed when the dev server starts.\n */\n homePagePath?: string;\n}\n\nexport function defineConfig(config: RootUserConfig): RootUserConfig {\n return config;\n}\n","import {ComponentChildren, FunctionalComponent} from 'preact';\nimport {useContext} from 'preact/hooks';\nimport {HTML_CONTEXT} from './Html.js';\n\nexport type BodyProps = preact.JSX.HTMLAttributes<HTMLBodyElement> & {\n children?: ComponentChildren;\n};\n\n/**\n * The `<Body>` component can be used to update attrs in the `<body>` tag.\n *\n * Usage:\n *\n * ```tsx\n * <Body className=\"body\">\n * <h1>Hello world</h1>\n * </Body>\n * ```\n *\n * Output:\n *\n * ```html\n * <body class=\"body\">\n * <h1>Hello world</h1>\n * </body>\n */\nexport const Body: FunctionalComponent<BodyProps> = ({children, ...attrs}) => {\n const context = useContext(HTML_CONTEXT);\n if (!context) {\n throw new Error(\n 'HTML_CONTEXT not found, double-check usage of the <Body> component'\n );\n }\n context.bodyAttrs = attrs;\n return <>{children}</>;\n};\n","import {ComponentChildren, FunctionalComponent} from 'preact';\nimport {useContext} from 'preact/hooks';\nimport {HTML_CONTEXT} from './Html.js';\n\nexport type HeadProps = preact.JSX.HTMLAttributes<HTMLHeadElement> & {\n children?: ComponentChildren;\n};\n\n/**\n * The <Head> component can be used for injecting elements into the HTML head\n * tag from any part of a page. The <Head> can be added via any component or\n * sub-component and will automatically be hoisted to the `<head>` element.\n *\n * Usage:\n *\n * ```tsx\n * <Head>\n * <link rel=\"preconnect\" href=\"https://fonts.googleapis.com\" />\n * </Head>\n * ```\n */\nexport const Head: FunctionalComponent<HeadProps> = ({children, ...attrs}) => {\n const context = useContext(HTML_CONTEXT);\n if (!context) {\n throw new Error(\n 'HTML_CONTEXT not found, double-check usage of the <Head> component'\n );\n }\n context.headComponents.push(children);\n context.headAttrs = attrs;\n return null;\n};\n","import {FunctionalComponent} from 'preact';\nimport {useContext} from 'preact/hooks';\nimport {HTML_CONTEXT} from './Html.js';\n\nexport type ScriptProps = preact.JSX.HTMLAttributes<HTMLScriptElement> & {\n // Cast the \"src\" attr to string. See:\n // https://github.com/blinkk/rootjs/issues/519\n src?: string;\n};\n\n/**\n * The <Script> component is used for rendering any custom script modules. At\n * the moment, the system only pre-renders and bundles files that are in the\n * `/bundles` folder at the root of the project.\n *\n * Usage:\n *\n * ```tsx\n * <Script src=\"/bundles/main.ts\" />\n * ```\n */\nexport const Script: FunctionalComponent<ScriptProps> = (props) => {\n const context = useContext(HTML_CONTEXT);\n if (!context) {\n throw new Error(\n 'HTML_CONTEXT not found, double-check usage of the <Script> component'\n );\n }\n context.scriptDeps.push(props);\n return null;\n};\n","import {ComponentChildren, FunctionalComponent, createContext} from 'preact';\nimport {useContext} from 'preact/hooks';\n\nexport type StringParamsContext = Record<string, string>;\n\nexport const STRING_PARAMS_CONTEXT = createContext<StringParamsContext | null>(\n null\n);\n\nexport interface StringParamsProviderProps {\n value?: StringParamsContext;\n children?: ComponentChildren;\n}\n\nexport const StringParamsProvider: FunctionalComponent<\n StringParamsProviderProps\n> = (props) => {\n // Allow for nested param values from parent content providers.\n const parent = useContext(STRING_PARAMS_CONTEXT) || {};\n const merged = {...parent, ...props.value};\n return (\n <STRING_PARAMS_CONTEXT.Provider value={merged}>\n {props.children}\n </STRING_PARAMS_CONTEXT.Provider>\n );\n};\n\n/**\n * A hook that returns a map of string params, configured via the\n * `StringParamsProvider` context provider. These params are automatically\n * applied to the `useTranslations()` hook.\n *\n *\n * Usage:\n *\n * ```\n * export default function Page() {\n * return (\n * <StringParamsProvider value={{name: 'Alice'}}>\n * <SayHello />\n * </StringParamsProvider>\n * );\n * }\n *\n * function SayHello() {\n * const t = useTranslations();\n * return <h1>{t('Hello, {name}!')}</h1>;\n * }\n * ```\n *\n * This should render `<h1>Hello, Alice!</h1>`.\n */\nexport function useStringParams() {\n return useContext(STRING_PARAMS_CONTEXT) || {};\n}\n","import {ComponentChildren, FunctionalComponent, createContext} from 'preact';\nimport {useContext} from 'preact/hooks';\n\ntype TransformFn = (str: string) => string;\n\nexport interface TranslationMiddleware {\n /** Transform the string before translation lookup. */\n beforeTranslate?: TransformFn;\n /** Transform the string after translation lookup. */\n afterTranslate?: TransformFn;\n /** Transform the string before `{param}` values are replaced. */\n beforeReplaceParams?: TransformFn;\n /** Transform the string after `{param}` values are replaced. */\n afterReplaceParams?: TransformFn;\n}\n\nexport interface TranslationMiddlewareContext {\n beforeTranslateFns: TransformFn[];\n afterTranslateFns: TransformFn[];\n beforeReplaceParamsFns: TransformFn[];\n afterReplaceParamsFns: TransformFn[];\n}\n\nconst TRANSLATION_MIDDLEWARE_CONTEXT =\n createContext<TranslationMiddlewareContext | null>(null);\n\nexport interface TranslationMiddlewareProviderProps {\n value?: TranslationMiddleware;\n children?: ComponentChildren;\n}\n\nexport const TranslationMiddlewareProvider: FunctionalComponent<\n TranslationMiddlewareProviderProps\n> = (props) => {\n const parent = useContext(TRANSLATION_MIDDLEWARE_CONTEXT) || {\n beforeTranslateFns: [],\n afterTranslateFns: [],\n beforeReplaceParamsFns: [],\n afterReplaceParamsFns: [],\n };\n const merged: TranslationMiddlewareContext = {\n beforeTranslateFns: [...parent.beforeTranslateFns],\n afterTranslateFns: [...parent.afterTranslateFns],\n beforeReplaceParamsFns: [...parent.beforeReplaceParamsFns],\n afterReplaceParamsFns: [...parent.afterReplaceParamsFns],\n };\n if (props.value?.beforeTranslate) {\n merged.beforeTranslateFns.push(props.value.beforeTranslate);\n }\n if (props.value?.afterTranslate) {\n merged.afterTranslateFns.push(props.value.afterTranslate);\n }\n if (props.value?.beforeReplaceParams) {\n merged.beforeReplaceParamsFns.push(props.value.beforeReplaceParams);\n }\n if (props.value?.afterReplaceParams) {\n merged.afterReplaceParamsFns.push(props.value.afterReplaceParams);\n }\n return (\n <TRANSLATION_MIDDLEWARE_CONTEXT.Provider value={merged}>\n {props.children}\n </TRANSLATION_MIDDLEWARE_CONTEXT.Provider>\n );\n};\n\nexport function useTranslationMiddleware(): TranslationMiddlewareContext {\n return (\n useContext(TRANSLATION_MIDDLEWARE_CONTEXT) || {\n beforeTranslateFns: [],\n afterTranslateFns: [],\n beforeReplaceParamsFns: [],\n afterReplaceParamsFns: [],\n }\n );\n}\n","import {I18nContext, useI18nContext} from './useI18nContext.js';\nimport {useStringParams} from './useStringParams.js';\nimport {useTranslationMiddleware} from './useTranslationsMiddleware.js';\n\n/**\n * A hook that returns a function that can be used to translate a string, and\n * optionally replace any parameterized values that are surrounded in curly\n * braces.\n *\n * Usage:\n *\n * ```ts\n * const t = useTranslations();\n * t('Hello {name}', {name: 'Bob'});\n * // => 'Bounjour Bob'\n * ```\n */\nexport function useTranslations() {\n // Ignore I18nContext not found error when used with client-side rehydration.\n let i18nContext: I18nContext | null = null;\n try {\n i18nContext = useI18nContext();\n } catch (err) {\n console.warn('I18nContext not found');\n }\n const translations = i18nContext?.translations || {};\n const stringParams = useStringParams();\n const middleware = useTranslationMiddleware();\n\n function t(str: string, params?: Record<string, string | number>): string;\n function t(\n str: string | null | undefined,\n params?: Record<string, string | number>\n ): string | undefined {\n // Suppress verbatim `'undefined'` and `'null'` output, which can occur when\n // using `useTranslations` with undefined values.\n if (typeof str === 'undefined' || str === null) {\n // Return `undefined` to suppress empty props, e.g.\n // <a title={t(undefined)}>Learn more</a>\n return undefined;\n }\n let input = normalizeString(str);\n middleware.beforeTranslateFns.forEach((fn) => {\n input = fn(input);\n });\n let translation = translations[input] ?? input ?? '';\n middleware.afterTranslateFns.forEach((fn) => {\n translation = fn(translation);\n });\n\n // Replace string params, e.g. \"Hello, {name}\".\n middleware.beforeReplaceParamsFns.forEach((fn) => {\n translation = fn(translation);\n });\n if (testHasStringParams(translation)) {\n translation = replaceStringParams(translation, {\n ...stringParams,\n ...params,\n });\n }\n middleware.afterReplaceParamsFns.forEach((fn) => {\n translation = fn(translation);\n });\n\n return translation;\n }\n return t;\n}\n\n/**\n * Cleans a string that's used for translations. Performs the following:\n * - Removes any leading/trailing whitespace\n * - Removes spaces at the end of any line\n */\nexport function normalizeString(str: string) {\n const lines = String(str)\n .trim()\n .split('\\n')\n .map((line) => removeTrailingWhitespace(line));\n return lines.join('\\n');\n}\n\nfunction removeTrailingWhitespace(str: string) {\n return String(str)\n .trimEnd()\n .replace(/ $/, '');\n}\n\nfunction testHasStringParams(str: string) {\n return str.includes('{') && str.includes('}');\n}\n\n/**\n * Replaces string placeholder params, e.g.\n *\n * ```\n * replaceStringParams('Hello, {name}!', {name: 'Joe'})\n * // => 'Hello, Joe!'\n * ```\n */\nfunction replaceStringParams(\n str: string,\n params: Record<string, string | number>\n): string {\n return str.replace(/{([^}]+)}/g, (match, key) => {\n if (key in params) {\n return String(params[key]);\n }\n return match;\n });\n}\n"],"mappings":";;;;;;;;;;;;;;;AA0SO,SAAS,aAAa,QAAwC;AACnE,SAAO;AACT;;;AC3SA,SAAQ,kBAAiB;AAiChB;AARF,IAAM,OAAuC,CAAC,EAAC,UAAU,GAAG,MAAK,MAAM;AAC5E,QAAM,UAAU,WAAW,YAAY;AACvC,MAAI,CAAC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QAAI,QAAQ,gBAAgB,GAAG;AAC/B,eAAW,mBAAmB,QAAQ,CAAC,OAAO;AAC5C,cAAQ,GAAG,KAAK;AAAA,IAClB,CAAC;AACD,QAAI,cAAc,aAAa,KAAK,KAAK,SAAS;AAClD,eAAW,kBAAkB,QAAQ,CAAC,OAAO;AAC3C,oBAAc,GAAG,WAAW;AAAA,IAC9B,CAAC;AAGD,eAAW,uBAAuB,QAAQ,CAAC,OAAO;AAChD,oBAAc,GAAG,WAAW;AAAA,IAC9B,CAAC;AACD,QAAI,oBAAoB,WAAW,GAAG;AACpC,oBAAc,oBAAoB,aAAa;AAAA,QAC7C,GAAG;AAAA,QACH,GAAG;AAAA,MACL,CAAC;AAAA,IACH;AACA,eAAW,sBAAsB,QAAQ,CAAC,OAAO;AAC/C,oBAAc,GAAG,WAAW;AAAA,IAC9B,CAAC;AAED,WAAO;AAAA,EACT;AACA,SAAO;AACT;AAOO,SAAS,gBAAgB,KAAa;AAC3C,QAAM,QAAQ,OAAO,GAAG,EACrB,KAAK,EACL,MAAM,IAAI,EACV,IAAI,CAAC,SAAS,yBAAyB,IAAI,CAAC;AAC/C,SAAO,MAAM,KAAK,IAAI;AACxB;AAEA,SAAS,yBAAyB,KAAa;AAC7C,SAAO,OAAO,GAAG,EACd,QAAQ,EACR,QAAQ,WAAW,EAAE;AAC1B;AAEA,SAAS,oBAAoB,KAAa;AACxC,SAAO,IAAI,SAAS,GAAG,KAAK,IAAI,SAAS,GAAG;AAC9C;AAUA,SAAS,oBACP,KACA,QACQ;AACR,SAAO,IAAI,QAAQ,cAAc,CAAC,OAAO,QAAQ;AAC/C,QAAI,OAAO,QAAQ;AACjB,aAAO,OAAO,OAAO,GAAG,CAAC;AAAA,IAC3B;AACA,WAAO;AAAA,EACT,CAAC;AACH;","names":["useContext","useContext","useContext","useContext","useContext","jsx","createContext","useContext","jsx"]}
|
|
1
|
+
{"version":3,"sources":["../src/core/config.ts","../src/core/components/Body.tsx","../src/core/components/Head.ts","../src/core/components/Script.ts","../src/core/hooks/useStringParams.tsx","../src/core/hooks/useTranslationsMiddleware.tsx","../src/core/hooks/useTranslations.ts"],"sourcesContent":["import {UserConfig as ViteUserConfig} from 'vite';\nimport {HtmlMinifyOptions} from '../render/html-minify.js';\nimport {HtmlPrettyOptions} from '../render/html-pretty.js';\nimport {JsxRenderOptions} from '../jsx/jsx-render.js';\nimport {Plugin} from './plugin.js';\nimport {RequestMiddleware} from './types.js';\n\nexport interface RootUserConfig {\n /**\n * Canonical domain the website will serve on. Useful for things like the\n * sitemap, SEO tags, etc.\n */\n domain?: string;\n\n /**\n * The base URL path that the site will serve on. Defaults to `/`;\n */\n base?: string;\n\n /**\n * Config for auto-injecting custom element dependencies.\n */\n elements?: {\n /**\n * A list of directories to use to look for custom elements. The dir path\n * should be relative to the project dir, e.g. \"path/to/elements\".\n */\n include?: string[];\n\n /**\n * A list of RegEx patterns to exclude. The string passed to the RegEx is\n * the file URL relative to the project root, e.g. \"/elements/foo/foo.ts\".\n */\n exclude?: RegExp[];\n };\n\n /**\n * Config for manually injecting stylesheet entries as\n * `<link rel=\"stylesheet\">` tags.\n */\n styles?: {\n /**\n * Project-root-relative stylesheet files to include on every rendered\n * page, e.g. `styles/index.css`.\n *\n * Entries are normalized as URL paths, so both `styles/index.css` and\n * `/styles/index.css` resolve to `/styles/index.css`.\n *\n * Manual entries are injected first, then auto-collected CSS\n * dependencies are merged after. Duplicate URLs are de-duped so each\n * stylesheet is only injected once.\n */\n entries?: string[];\n };\n\n /**\n * Config options for localization and internationalization.\n */\n i18n?: RootI18nConfig;\n\n /**\n * Config options for the Root.js express server.\n */\n server?: RootServerConfig;\n\n /**\n * Build options for the `root build` command.\n */\n build?: RootBuildConfig;\n\n /**\n * Vite config.\n * @see {@link https://vitejs.dev/config/} for more information.\n */\n vite?: ViteUserConfig;\n\n /**\n * Config for the built-in JSX-to-HTML renderer.\n *\n * - `mode: 'pretty'` (default) — block-level elements render on their own\n * line with no indentation.\n * - `mode: 'minimal'` — compact output with no extra whitespace.\n *\n * Use `blockElements` to specify additional custom element tag names that\n * should be treated as block-level in pretty mode.\n *\n * @example\n * ```ts\n * export default defineConfig({\n * jsxRenderer: {\n * mode: 'pretty',\n * blockElements: ['my-card', 'my-section'],\n * },\n * });\n * ```\n */\n jsxRenderer?: JsxRenderOptions;\n\n /**\n * Whether to automatically minify HTML output. This is enabled by default,\n * in order to disable, pass `minifyHtml: false` to root.config.ts.\n */\n minifyHtml?: boolean;\n\n /**\n * Options to pass to html-minifier-terser.\n */\n minifyHtmlOptions?: HtmlMinifyOptions;\n\n /**\n * Whether to pretty print HTML output.\n */\n prettyHtml?: boolean;\n\n /**\n * Options to pass to js-beautify.\n */\n prettyHtmlOptions?: HtmlPrettyOptions;\n\n /**\n * Whether to include a sitemap.xml file to the build output.\n */\n sitemap?: boolean;\n\n /**\n * Plugins.\n */\n plugins?: Plugin[];\n\n /**\n * Experimental config options. Note: these are subject to change at any time.\n */\n experiments?: {\n /** Whether to render `<script>` tags with `async`. */\n enableScriptAsync?: boolean;\n };\n}\n\nexport type RootConfig = RootUserConfig & {\n rootDir: string;\n};\n\nexport interface LocaleGroup {\n label?: string;\n locales: string[];\n}\n\nexport interface RootI18nConfig {\n /**\n * Locales enabled for the site.\n */\n locales?: string[];\n\n /**\n * The default locale to use. Defaults is `en`.\n */\n defaultLocale?: string;\n\n /**\n * URL format for localized content. Default is `/[locale]/[base]/[path]`.\n */\n urlFormat?: string;\n\n /**\n * Localization groups, to help UIs (like Root.js CMS) logically group\n * locales.\n */\n groups?: Record<string, LocaleGroup>;\n}\n\nexport interface RootBuildConfig {\n /**\n * Excludes the `/intl/{defaultLocale}/...` path from the SSG build.\n */\n excludeDefaultLocaleFromIntlPaths?: boolean;\n}\n\nexport interface RootRedirectConfig {\n /**\n * The source path to redirect. Accepts placeholders in the format\n * `[key]` or `[...key]`. Use `[key]` for single segments and\n * `[...key]` for multi-segment wildcards.\n * @example \"/old-path/[id]\" or \"/old-path/[...wildcard]\"\n */\n source: string;\n\n /**\n * The destination to redirect to. Placeholders from the source can\n * optionally be inserted into the destination using the same\n * placeholder format.\n * @example \"/new-path/[id]\" or \"/new-path/[...wildcard]\"\n */\n destination: string;\n\n /**\n * The redirect type (`301` = permanent, `302` = temporary). If unspecified,\n * defaults to `302` (temporary).\n */\n type?: 301 | 302;\n}\n\nexport interface RootHeaderConfig {\n /** A glob pattern match (regex not supported yet). */\n source: string;\n headers: Array<{\n key: string;\n value: string;\n }>;\n}\n\nexport interface ContentSecurityPolicyConfig {\n directives?: Record<string, string[]>;\n reportOnly?: boolean;\n}\n\nexport interface XFrameOptionsConfig {\n action: 'DENY' | 'SAMEORIGIN';\n}\n\nexport interface RootSecurityConfig {\n /**\n * Content-Security-Policy config. If enabled, a nonce is auto-generated\n * for every request and appended to script and stylesheet tags. You can\n * validate your CSP headers using a tool like {@link https://csp-evaluator.withgoogle.com/}.\n *\n * @see {@link https://developer.mozilla.org/en-US/docs/Web/HTTP/CSP}\n */\n contentSecurityPolicy?: ContentSecurityPolicyConfig | boolean;\n\n /**\n * Strict-Transport-Security config. When enabled, the header value is set\n * to `Strict-Transport-Security: max-age=63072000; includeSubDomains; preload`.\n */\n strictTransportSecurity?: boolean;\n\n /**\n * X-Content-Type-Options config. When enabled, the header value is set to\n * `X-Content-Type-Options: nosniff`.\n */\n xContentTypeOptions?: boolean;\n\n /**\n * X-Frame-Options config. Setting this value to `true` will default the\n * header value to `X-Frame-Options: SAMEORIGIN`.\n *\n * @see {@link https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/X-Frame-Options}\n */\n xFrameOptions?: 'DENY' | 'SAMEORIGIN' | boolean;\n\n /**\n * X-XSS-Protection config. When enabled, the header value is set to\n * `X-XSS-Protection: 1; mode=block`.\n */\n xXssProtection?: boolean;\n}\n\nexport interface RootServerConfig {\n /**\n * An array of middleware to add to the express server. These middleware are\n * added to the beginning of the express app.\n */\n middlewares?: RequestMiddleware[];\n\n /**\n * The `trailingSlash` config allows you to control how the server handles\n * trailing slashes. This config only affects URLs that do not have a file\n * extension (i.e. HTML paths).\n *\n * - When `true`, the server redirects URLs to add a trailing slash\n * - When `false`, the server redirects URLs to remove a trailing slash\n * - When unspecified, the server allows URLs with and without trailing slash\n */\n trailingSlash?: boolean;\n\n /**\n * Cookie secret for the session middleware.\n *\n * Generate a secure secret with:\n * ```\n * node -e \"console.log(require('crypto').randomBytes(32).toString('hex'))\"\n * ```\n */\n sessionCookieSecret?: string | string[];\n\n /**\n * List of redirects. Supports optional wildcards.\n *\n * @example\n * ```ts\n * redirects: [\n * {\n * source: '/old-path/[id]',\n * destination: '/new-path/[id]',\n * type: 301,\n * },\n * {\n * source: '/old-path/[...wildcard]',\n * destination: '/new-path/[...wildcard]',\n * },\n * ]\n * ```\n */\n redirects?: RootRedirectConfig[];\n\n /**\n * HTTP headers to add to a response.\n */\n headers?: RootHeaderConfig[];\n\n /**\n * HTTP security settings. By default, all security settings are enabled with\n * commonly used default values.\n */\n security?: RootSecurityConfig;\n\n /**\n * Home page URL path, which is printed when the dev server starts.\n */\n homePagePath?: string;\n}\n\nexport function defineConfig(config: RootUserConfig): RootUserConfig {\n return config;\n}\n","import {ComponentChildren, FunctionalComponent} from 'preact';\nimport {useContext} from 'preact/hooks';\nimport {HTML_CONTEXT} from './Html.js';\n\nexport type BodyProps = preact.JSX.HTMLAttributes<HTMLBodyElement> & {\n children?: ComponentChildren;\n};\n\n/**\n * The `<Body>` component can be used to update attrs in the `<body>` tag.\n *\n * Usage:\n *\n * ```tsx\n * <Body className=\"body\">\n * <h1>Hello world</h1>\n * </Body>\n * ```\n *\n * Output:\n *\n * ```html\n * <body class=\"body\">\n * <h1>Hello world</h1>\n * </body>\n */\nexport const Body: FunctionalComponent<BodyProps> = ({children, ...attrs}) => {\n const context = useContext(HTML_CONTEXT);\n if (!context) {\n throw new Error(\n 'HTML_CONTEXT not found, double-check usage of the <Body> component'\n );\n }\n context.bodyAttrs = attrs;\n return <>{children}</>;\n};\n","import {ComponentChildren, FunctionalComponent} from 'preact';\nimport {useContext} from 'preact/hooks';\nimport {HTML_CONTEXT} from './Html.js';\n\nexport type HeadProps = preact.JSX.HTMLAttributes<HTMLHeadElement> & {\n children?: ComponentChildren;\n};\n\n/**\n * The <Head> component can be used for injecting elements into the HTML head\n * tag from any part of a page. The <Head> can be added via any component or\n * sub-component and will automatically be hoisted to the `<head>` element.\n *\n * Usage:\n *\n * ```tsx\n * <Head>\n * <link rel=\"preconnect\" href=\"https://fonts.googleapis.com\" />\n * </Head>\n * ```\n */\nexport const Head: FunctionalComponent<HeadProps> = ({children, ...attrs}) => {\n const context = useContext(HTML_CONTEXT);\n if (!context) {\n throw new Error(\n 'HTML_CONTEXT not found, double-check usage of the <Head> component'\n );\n }\n context.headComponents.push(children);\n context.headAttrs = attrs;\n return null;\n};\n","import {FunctionalComponent} from 'preact';\nimport {useContext} from 'preact/hooks';\nimport {HTML_CONTEXT} from './Html.js';\n\nexport type ScriptProps = preact.JSX.HTMLAttributes<HTMLScriptElement> & {\n // Cast the \"src\" attr to string. See:\n // https://github.com/blinkk/rootjs/issues/519\n src?: string;\n};\n\n/**\n * The <Script> component is used for rendering any custom script modules. At\n * the moment, the system only pre-renders and bundles files that are in the\n * `/bundles` folder at the root of the project.\n *\n * Usage:\n *\n * ```tsx\n * <Script src=\"/bundles/main.ts\" />\n * ```\n */\nexport const Script: FunctionalComponent<ScriptProps> = (props) => {\n const context = useContext(HTML_CONTEXT);\n if (!context) {\n throw new Error(\n 'HTML_CONTEXT not found, double-check usage of the <Script> component'\n );\n }\n context.scriptDeps.push(props);\n return null;\n};\n","import {ComponentChildren, FunctionalComponent, createContext} from 'preact';\nimport {useContext} from 'preact/hooks';\n\nexport type StringParamsContext = Record<string, string>;\n\nexport const STRING_PARAMS_CONTEXT = createContext<StringParamsContext | null>(\n null\n);\n\nexport interface StringParamsProviderProps {\n value?: StringParamsContext;\n children?: ComponentChildren;\n}\n\nexport const StringParamsProvider: FunctionalComponent<\n StringParamsProviderProps\n> = (props) => {\n // Allow for nested param values from parent content providers.\n const parent = useContext(STRING_PARAMS_CONTEXT) || {};\n const merged = {...parent, ...props.value};\n return (\n <STRING_PARAMS_CONTEXT.Provider value={merged}>\n {props.children}\n </STRING_PARAMS_CONTEXT.Provider>\n );\n};\n\n/**\n * A hook that returns a map of string params, configured via the\n * `StringParamsProvider` context provider. These params are automatically\n * applied to the `useTranslations()` hook.\n *\n *\n * Usage:\n *\n * ```\n * export default function Page() {\n * return (\n * <StringParamsProvider value={{name: 'Alice'}}>\n * <SayHello />\n * </StringParamsProvider>\n * );\n * }\n *\n * function SayHello() {\n * const t = useTranslations();\n * return <h1>{t('Hello, {name}!')}</h1>;\n * }\n * ```\n *\n * This should render `<h1>Hello, Alice!</h1>`.\n */\nexport function useStringParams() {\n return useContext(STRING_PARAMS_CONTEXT) || {};\n}\n","import {ComponentChildren, FunctionalComponent, createContext} from 'preact';\nimport {useContext} from 'preact/hooks';\n\ntype TransformFn = (str: string) => string;\n\nexport interface TranslationMiddleware {\n /** Transform the string before translation lookup. */\n beforeTranslate?: TransformFn;\n /** Transform the string after translation lookup. */\n afterTranslate?: TransformFn;\n /** Transform the string before `{param}` values are replaced. */\n beforeReplaceParams?: TransformFn;\n /** Transform the string after `{param}` values are replaced. */\n afterReplaceParams?: TransformFn;\n}\n\nexport interface TranslationMiddlewareContext {\n beforeTranslateFns: TransformFn[];\n afterTranslateFns: TransformFn[];\n beforeReplaceParamsFns: TransformFn[];\n afterReplaceParamsFns: TransformFn[];\n}\n\nconst TRANSLATION_MIDDLEWARE_CONTEXT =\n createContext<TranslationMiddlewareContext | null>(null);\n\nexport interface TranslationMiddlewareProviderProps {\n value?: TranslationMiddleware;\n children?: ComponentChildren;\n}\n\nexport const TranslationMiddlewareProvider: FunctionalComponent<\n TranslationMiddlewareProviderProps\n> = (props) => {\n const parent = useContext(TRANSLATION_MIDDLEWARE_CONTEXT) || {\n beforeTranslateFns: [],\n afterTranslateFns: [],\n beforeReplaceParamsFns: [],\n afterReplaceParamsFns: [],\n };\n const merged: TranslationMiddlewareContext = {\n beforeTranslateFns: [...parent.beforeTranslateFns],\n afterTranslateFns: [...parent.afterTranslateFns],\n beforeReplaceParamsFns: [...parent.beforeReplaceParamsFns],\n afterReplaceParamsFns: [...parent.afterReplaceParamsFns],\n };\n if (props.value?.beforeTranslate) {\n merged.beforeTranslateFns.push(props.value.beforeTranslate);\n }\n if (props.value?.afterTranslate) {\n merged.afterTranslateFns.push(props.value.afterTranslate);\n }\n if (props.value?.beforeReplaceParams) {\n merged.beforeReplaceParamsFns.push(props.value.beforeReplaceParams);\n }\n if (props.value?.afterReplaceParams) {\n merged.afterReplaceParamsFns.push(props.value.afterReplaceParams);\n }\n return (\n <TRANSLATION_MIDDLEWARE_CONTEXT.Provider value={merged}>\n {props.children}\n </TRANSLATION_MIDDLEWARE_CONTEXT.Provider>\n );\n};\n\nexport function useTranslationMiddleware(): TranslationMiddlewareContext {\n return (\n useContext(TRANSLATION_MIDDLEWARE_CONTEXT) || {\n beforeTranslateFns: [],\n afterTranslateFns: [],\n beforeReplaceParamsFns: [],\n afterReplaceParamsFns: [],\n }\n );\n}\n","import {I18nContext, useI18nContext} from './useI18nContext.js';\nimport {useStringParams} from './useStringParams.js';\nimport {useTranslationMiddleware} from './useTranslationsMiddleware.js';\n\n/**\n * A hook that returns a function that can be used to translate a string, and\n * optionally replace any parameterized values that are surrounded in curly\n * braces.\n *\n * Usage:\n *\n * ```ts\n * const t = useTranslations();\n * t('Hello {name}', {name: 'Bob'});\n * // => 'Bounjour Bob'\n * ```\n */\nexport function useTranslations() {\n // Ignore I18nContext not found error when used with client-side rehydration.\n let i18nContext: I18nContext | null = null;\n try {\n i18nContext = useI18nContext();\n } catch (err) {\n console.warn('I18nContext not found');\n }\n const translations = i18nContext?.translations || {};\n const stringParams = useStringParams();\n const middleware = useTranslationMiddleware();\n\n function t(str: string, params?: Record<string, string | number>): string;\n function t(\n str: string | null | undefined,\n params?: Record<string, string | number>\n ): string | undefined {\n // Suppress verbatim `'undefined'` and `'null'` output, which can occur when\n // using `useTranslations` with undefined values.\n if (typeof str === 'undefined' || str === null) {\n // Return `undefined` to suppress empty props, e.g.\n // <a title={t(undefined)}>Learn more</a>\n return undefined;\n }\n let input = normalizeString(str);\n middleware.beforeTranslateFns.forEach((fn) => {\n input = fn(input);\n });\n let translation = translations[input] ?? input ?? '';\n middleware.afterTranslateFns.forEach((fn) => {\n translation = fn(translation);\n });\n\n // Replace string params, e.g. \"Hello, {name}\".\n middleware.beforeReplaceParamsFns.forEach((fn) => {\n translation = fn(translation);\n });\n if (testHasStringParams(translation)) {\n translation = replaceStringParams(translation, {\n ...stringParams,\n ...params,\n });\n }\n middleware.afterReplaceParamsFns.forEach((fn) => {\n translation = fn(translation);\n });\n\n return translation;\n }\n return t;\n}\n\n/**\n * Cleans a string that's used for translations. Performs the following:\n * - Removes any leading/trailing whitespace\n * - Removes spaces at the end of any line\n */\nexport function normalizeString(str: string) {\n const lines = String(str)\n .trim()\n .split('\\n')\n .map((line) => removeTrailingWhitespace(line));\n return lines.join('\\n');\n}\n\nfunction removeTrailingWhitespace(str: string) {\n return String(str)\n .trimEnd()\n .replace(/ $/, '');\n}\n\nfunction testHasStringParams(str: string) {\n return str.includes('{') && str.includes('}');\n}\n\n/**\n * Replaces string placeholder params, e.g.\n *\n * ```\n * replaceStringParams('Hello, {name}!', {name: 'Joe'})\n * // => 'Hello, Joe!'\n * ```\n */\nfunction replaceStringParams(\n str: string,\n params: Record<string, string | number>\n): string {\n return str.replace(/{([^}]+)}/g, (match, key) => {\n if (key in params) {\n return String(params[key]);\n }\n return match;\n });\n}\n"],"mappings":";;;;;;;;;;;;;;;AAiUO,SAAS,aAAa,QAAwC;AACnE,SAAO;AACT;;;AClUA,SAAQ,kBAAiB;AAiChB;AARF,IAAM,OAAuC,CAAC,EAAC,UAAU,GAAG,MAAK,MAAM;AAC5E,QAAM,UAAU,WAAW,YAAY;AACvC,MAAI,CAAC,SAAS;AACZ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