@blinkk/root 3.1.4 → 3.1.5
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-AJR6VAT7.js +694 -0
- package/dist/chunk-AJR6VAT7.js.map +7 -0
- package/dist/core/types.d.ts +7 -0
- package/dist/jsx/jsx-render.d.ts +6 -1
- package/dist/jsx.js +1 -1
- package/dist/render/render.d.ts +3 -0
- package/dist/render.js +16 -10
- package/dist/render.js.map +2 -2
- package/package.json +1 -1
- package/dist/chunk-OQRFLH2X.js +0 -545
- package/dist/chunk-OQRFLH2X.js.map +0 -7
|
@@ -0,0 +1,694 @@
|
|
|
1
|
+
import {
|
|
2
|
+
Fragment
|
|
3
|
+
} from "./chunk-3Z5TNZEP.js";
|
|
4
|
+
|
|
5
|
+
// src/jsx/jsx-render.ts
|
|
6
|
+
import { options as preactOptions } from "preact";
|
|
7
|
+
var VOID_ELEMENTS = /* @__PURE__ */ new Set([
|
|
8
|
+
"area",
|
|
9
|
+
"base",
|
|
10
|
+
"br",
|
|
11
|
+
"col",
|
|
12
|
+
"embed",
|
|
13
|
+
"hr",
|
|
14
|
+
"img",
|
|
15
|
+
"input",
|
|
16
|
+
"link",
|
|
17
|
+
"meta",
|
|
18
|
+
"param",
|
|
19
|
+
"source",
|
|
20
|
+
"track",
|
|
21
|
+
"wbr"
|
|
22
|
+
]);
|
|
23
|
+
var RAW_CONTENT_ELEMENTS = /* @__PURE__ */ new Set(["pre", "textarea", "script", "style"]);
|
|
24
|
+
var DEFAULT_BLOCK_ELEMENTS = /* @__PURE__ */ new Set([
|
|
25
|
+
"address",
|
|
26
|
+
"article",
|
|
27
|
+
"aside",
|
|
28
|
+
"base",
|
|
29
|
+
"blockquote",
|
|
30
|
+
"body",
|
|
31
|
+
"dd",
|
|
32
|
+
"details",
|
|
33
|
+
"dialog",
|
|
34
|
+
"div",
|
|
35
|
+
"dl",
|
|
36
|
+
"dt",
|
|
37
|
+
"fieldset",
|
|
38
|
+
"figcaption",
|
|
39
|
+
"figure",
|
|
40
|
+
"footer",
|
|
41
|
+
"form",
|
|
42
|
+
"h1",
|
|
43
|
+
"h2",
|
|
44
|
+
"h3",
|
|
45
|
+
"h4",
|
|
46
|
+
"h5",
|
|
47
|
+
"h6",
|
|
48
|
+
"head",
|
|
49
|
+
"header",
|
|
50
|
+
"hgroup",
|
|
51
|
+
"hr",
|
|
52
|
+
"html",
|
|
53
|
+
"li",
|
|
54
|
+
"link",
|
|
55
|
+
"main",
|
|
56
|
+
"meta",
|
|
57
|
+
"nav",
|
|
58
|
+
"noscript",
|
|
59
|
+
"ol",
|
|
60
|
+
"optgroup",
|
|
61
|
+
"option",
|
|
62
|
+
"p",
|
|
63
|
+
"pre",
|
|
64
|
+
"script",
|
|
65
|
+
"search",
|
|
66
|
+
"section",
|
|
67
|
+
"select",
|
|
68
|
+
"style",
|
|
69
|
+
"summary",
|
|
70
|
+
"table",
|
|
71
|
+
"tbody",
|
|
72
|
+
"td",
|
|
73
|
+
"tfoot",
|
|
74
|
+
"th",
|
|
75
|
+
"thead",
|
|
76
|
+
"title",
|
|
77
|
+
"tr",
|
|
78
|
+
"ul"
|
|
79
|
+
]);
|
|
80
|
+
var ALWAYS_BLOCK_ELEMENTS = /* @__PURE__ */ new Set([
|
|
81
|
+
"base",
|
|
82
|
+
"link",
|
|
83
|
+
"meta",
|
|
84
|
+
"script",
|
|
85
|
+
"style",
|
|
86
|
+
"title"
|
|
87
|
+
]);
|
|
88
|
+
var TAG_FLAG_VOID = 1;
|
|
89
|
+
var TAG_FLAG_ALWAYS_BLOCK = 2;
|
|
90
|
+
var TAG_FLAG_RAW = 4;
|
|
91
|
+
var TAG_FLAG_BLOCK = 8;
|
|
92
|
+
var TAG_STATIC_FLAGS = /* @__PURE__ */ new Map();
|
|
93
|
+
for (const t of VOID_ELEMENTS) {
|
|
94
|
+
TAG_STATIC_FLAGS.set(t, (TAG_STATIC_FLAGS.get(t) || 0) | TAG_FLAG_VOID);
|
|
95
|
+
}
|
|
96
|
+
for (const t of ALWAYS_BLOCK_ELEMENTS) {
|
|
97
|
+
TAG_STATIC_FLAGS.set(
|
|
98
|
+
t,
|
|
99
|
+
(TAG_STATIC_FLAGS.get(t) || 0) | TAG_FLAG_ALWAYS_BLOCK
|
|
100
|
+
);
|
|
101
|
+
}
|
|
102
|
+
for (const t of RAW_CONTENT_ELEMENTS) {
|
|
103
|
+
TAG_STATIC_FLAGS.set(t, (TAG_STATIC_FLAGS.get(t) || 0) | TAG_FLAG_RAW);
|
|
104
|
+
}
|
|
105
|
+
for (const t of DEFAULT_BLOCK_ELEMENTS) {
|
|
106
|
+
TAG_STATIC_FLAGS.set(t, (TAG_STATIC_FLAGS.get(t) || 0) | TAG_FLAG_BLOCK);
|
|
107
|
+
}
|
|
108
|
+
var BOOLEAN_ATTRS = /* @__PURE__ */ new Set([
|
|
109
|
+
"allowfullscreen",
|
|
110
|
+
"async",
|
|
111
|
+
"autofocus",
|
|
112
|
+
"autoplay",
|
|
113
|
+
"capture",
|
|
114
|
+
"checked",
|
|
115
|
+
"controls",
|
|
116
|
+
"default",
|
|
117
|
+
"defer",
|
|
118
|
+
"disabled",
|
|
119
|
+
"disableremoteplayback",
|
|
120
|
+
"download",
|
|
121
|
+
"draggable",
|
|
122
|
+
"formnovalidate",
|
|
123
|
+
"hidden",
|
|
124
|
+
"inert",
|
|
125
|
+
"ismap",
|
|
126
|
+
"itemscope",
|
|
127
|
+
"loop",
|
|
128
|
+
"multiple",
|
|
129
|
+
"muted",
|
|
130
|
+
"nomodule",
|
|
131
|
+
"novalidate",
|
|
132
|
+
"open",
|
|
133
|
+
"playsinline",
|
|
134
|
+
"popover",
|
|
135
|
+
"readonly",
|
|
136
|
+
"required",
|
|
137
|
+
"reversed",
|
|
138
|
+
"selected"
|
|
139
|
+
]);
|
|
140
|
+
var PROP_TO_ATTR = Object.assign(
|
|
141
|
+
/* @__PURE__ */ Object.create(null),
|
|
142
|
+
{
|
|
143
|
+
acceptCharset: "accept-charset",
|
|
144
|
+
autoCapitalize: "autocapitalize",
|
|
145
|
+
autoComplete: "autocomplete",
|
|
146
|
+
autoFocus: "autofocus",
|
|
147
|
+
autoPlay: "autoplay",
|
|
148
|
+
charSet: "charset",
|
|
149
|
+
className: "class",
|
|
150
|
+
colSpan: "colspan",
|
|
151
|
+
contentEditable: "contenteditable",
|
|
152
|
+
crossOrigin: "crossorigin",
|
|
153
|
+
dateTime: "datetime",
|
|
154
|
+
disableRemotePlayback: "disableremoteplayback",
|
|
155
|
+
encType: "enctype",
|
|
156
|
+
formAction: "formaction",
|
|
157
|
+
formEncType: "formenctype",
|
|
158
|
+
formMethod: "formmethod",
|
|
159
|
+
formNoValidate: "formnovalidate",
|
|
160
|
+
formTarget: "formtarget",
|
|
161
|
+
frameBorder: "frameborder",
|
|
162
|
+
hrefLang: "hreflang",
|
|
163
|
+
htmlFor: "for",
|
|
164
|
+
httpEquiv: "http-equiv",
|
|
165
|
+
inputMode: "inputmode",
|
|
166
|
+
itemProp: "itemprop",
|
|
167
|
+
itemRef: "itemref",
|
|
168
|
+
itemScope: "itemscope",
|
|
169
|
+
itemType: "itemtype",
|
|
170
|
+
maxLength: "maxlength",
|
|
171
|
+
mediaGroup: "mediagroup",
|
|
172
|
+
minLength: "minlength",
|
|
173
|
+
noModule: "nomodule",
|
|
174
|
+
noValidate: "novalidate",
|
|
175
|
+
playsInline: "playsinline",
|
|
176
|
+
readOnly: "readonly",
|
|
177
|
+
referrerPolicy: "referrerpolicy",
|
|
178
|
+
rowSpan: "rowspan",
|
|
179
|
+
spellCheck: "spellcheck",
|
|
180
|
+
srcDoc: "srcdoc",
|
|
181
|
+
srcLang: "srclang",
|
|
182
|
+
srcSet: "srcset",
|
|
183
|
+
tabIndex: "tabindex",
|
|
184
|
+
useMap: "usemap",
|
|
185
|
+
// SVG presentation attributes (camelCase -> kebab-case).
|
|
186
|
+
clipPath: "clip-path",
|
|
187
|
+
clipRule: "clip-rule",
|
|
188
|
+
colorInterpolation: "color-interpolation",
|
|
189
|
+
colorInterpolationFilters: "color-interpolation-filters",
|
|
190
|
+
dominantBaseline: "dominant-baseline",
|
|
191
|
+
fillOpacity: "fill-opacity",
|
|
192
|
+
fillRule: "fill-rule",
|
|
193
|
+
floodColor: "flood-color",
|
|
194
|
+
floodOpacity: "flood-opacity",
|
|
195
|
+
imageRendering: "image-rendering",
|
|
196
|
+
letterSpacing: "letter-spacing",
|
|
197
|
+
lightingColor: "lighting-color",
|
|
198
|
+
markerEnd: "marker-end",
|
|
199
|
+
markerMid: "marker-mid",
|
|
200
|
+
markerStart: "marker-start",
|
|
201
|
+
paintOrder: "paint-order",
|
|
202
|
+
pointerEvents: "pointer-events",
|
|
203
|
+
shapeRendering: "shape-rendering",
|
|
204
|
+
stopColor: "stop-color",
|
|
205
|
+
stopOpacity: "stop-opacity",
|
|
206
|
+
strokeDasharray: "stroke-dasharray",
|
|
207
|
+
strokeDashoffset: "stroke-dashoffset",
|
|
208
|
+
strokeLinecap: "stroke-linecap",
|
|
209
|
+
strokeLinejoin: "stroke-linejoin",
|
|
210
|
+
strokeMiterlimit: "stroke-miterlimit",
|
|
211
|
+
strokeOpacity: "stroke-opacity",
|
|
212
|
+
strokeWidth: "stroke-width",
|
|
213
|
+
textAnchor: "text-anchor",
|
|
214
|
+
textDecoration: "text-decoration",
|
|
215
|
+
textRendering: "text-rendering",
|
|
216
|
+
transformOrigin: "transform-origin",
|
|
217
|
+
vectorEffect: "vector-effect",
|
|
218
|
+
wordSpacing: "word-spacing",
|
|
219
|
+
writingMode: "writing-mode"
|
|
220
|
+
}
|
|
221
|
+
);
|
|
222
|
+
var AMP = "&";
|
|
223
|
+
var LT = "<";
|
|
224
|
+
var GT = ">";
|
|
225
|
+
var QUOT = """;
|
|
226
|
+
var HTML_ESCAPE_RE = /[&<>]/;
|
|
227
|
+
var ATTR_ESCAPE_RE = /[&<>"]/;
|
|
228
|
+
var EMPTY_GLOBAL_CTX = {};
|
|
229
|
+
function isDef(value) {
|
|
230
|
+
return value !== null && value !== void 0;
|
|
231
|
+
}
|
|
232
|
+
function escapeHtml(str) {
|
|
233
|
+
if (!HTML_ESCAPE_RE.test(str)) return str;
|
|
234
|
+
let result = "";
|
|
235
|
+
let last = 0;
|
|
236
|
+
for (let i = 0; i < str.length; i++) {
|
|
237
|
+
const ch = str.charCodeAt(i);
|
|
238
|
+
let escaped;
|
|
239
|
+
if (ch === 38) escaped = AMP;
|
|
240
|
+
else if (ch === 60) escaped = LT;
|
|
241
|
+
else if (ch === 62) escaped = GT;
|
|
242
|
+
if (escaped) {
|
|
243
|
+
result += str.slice(last, i) + escaped;
|
|
244
|
+
last = i + 1;
|
|
245
|
+
}
|
|
246
|
+
}
|
|
247
|
+
return result + str.slice(last);
|
|
248
|
+
}
|
|
249
|
+
function escapeAttr(str) {
|
|
250
|
+
if (!ATTR_ESCAPE_RE.test(str)) return str;
|
|
251
|
+
let result = "";
|
|
252
|
+
let last = 0;
|
|
253
|
+
for (let i = 0; i < str.length; i++) {
|
|
254
|
+
const ch = str.charCodeAt(i);
|
|
255
|
+
let escaped;
|
|
256
|
+
if (ch === 38) escaped = AMP;
|
|
257
|
+
else if (ch === 34) escaped = QUOT;
|
|
258
|
+
else if (ch === 60) escaped = LT;
|
|
259
|
+
else if (ch === 62) escaped = GT;
|
|
260
|
+
if (escaped) {
|
|
261
|
+
result += str.slice(last, i) + escaped;
|
|
262
|
+
last = i + 1;
|
|
263
|
+
}
|
|
264
|
+
}
|
|
265
|
+
return result + str.slice(last);
|
|
266
|
+
}
|
|
267
|
+
var STYLE_KEY_CACHE = /* @__PURE__ */ new Map();
|
|
268
|
+
var UPPERCASE_RE = /[A-Z]/g;
|
|
269
|
+
function toKebabCase(key) {
|
|
270
|
+
let cached = STYLE_KEY_CACHE.get(key);
|
|
271
|
+
if (cached === void 0) {
|
|
272
|
+
cached = key.replace(UPPERCASE_RE, (m) => "-" + m.toLowerCase());
|
|
273
|
+
STYLE_KEY_CACHE.set(key, cached);
|
|
274
|
+
}
|
|
275
|
+
return cached;
|
|
276
|
+
}
|
|
277
|
+
function styleToString(style) {
|
|
278
|
+
let result = "";
|
|
279
|
+
let first = true;
|
|
280
|
+
for (const key in style) {
|
|
281
|
+
const value = style[key];
|
|
282
|
+
if (!isDef(value) || value === "") continue;
|
|
283
|
+
if (first) {
|
|
284
|
+
first = false;
|
|
285
|
+
} else {
|
|
286
|
+
result += ";";
|
|
287
|
+
}
|
|
288
|
+
result += `${toKebabCase(key)}:${value}`;
|
|
289
|
+
}
|
|
290
|
+
return result;
|
|
291
|
+
}
|
|
292
|
+
function renderJsxToString(vnode, options) {
|
|
293
|
+
const mode = options?.mode ?? "pretty";
|
|
294
|
+
const isPretty = mode === "pretty";
|
|
295
|
+
let customBlockSet;
|
|
296
|
+
if (isPretty && options?.blockElements && options.blockElements.length > 0) {
|
|
297
|
+
customBlockSet = /* @__PURE__ */ new Set();
|
|
298
|
+
for (const el of options.blockElements) {
|
|
299
|
+
if (!DEFAULT_BLOCK_ELEMENTS.has(el)) {
|
|
300
|
+
customBlockSet.add(el);
|
|
301
|
+
}
|
|
302
|
+
}
|
|
303
|
+
if (customBlockSet.size === 0) {
|
|
304
|
+
customBlockSet = void 0;
|
|
305
|
+
}
|
|
306
|
+
}
|
|
307
|
+
let contextStacks;
|
|
308
|
+
let ctxVersion = 0;
|
|
309
|
+
let cachedGlobalCtx = EMPTY_GLOBAL_CTX;
|
|
310
|
+
let cachedGlobalCtxVersion = 0;
|
|
311
|
+
let nlFlag = false;
|
|
312
|
+
function pushCtx(contextId, value) {
|
|
313
|
+
if (!contextStacks) {
|
|
314
|
+
contextStacks = /* @__PURE__ */ new Map();
|
|
315
|
+
}
|
|
316
|
+
let stack = contextStacks.get(contextId);
|
|
317
|
+
if (!stack) {
|
|
318
|
+
stack = [];
|
|
319
|
+
contextStacks.set(contextId, stack);
|
|
320
|
+
}
|
|
321
|
+
stack.push(value);
|
|
322
|
+
ctxVersion++;
|
|
323
|
+
}
|
|
324
|
+
function popCtx(contextId) {
|
|
325
|
+
const stack = contextStacks?.get(contextId);
|
|
326
|
+
if (stack) {
|
|
327
|
+
stack.pop();
|
|
328
|
+
if (stack.length === 0) {
|
|
329
|
+
contextStacks?.delete(contextId);
|
|
330
|
+
}
|
|
331
|
+
}
|
|
332
|
+
ctxVersion++;
|
|
333
|
+
}
|
|
334
|
+
function buildGlobalContext() {
|
|
335
|
+
if (ctxVersion === cachedGlobalCtxVersion) return cachedGlobalCtx;
|
|
336
|
+
if (!contextStacks || contextStacks.size === 0) {
|
|
337
|
+
cachedGlobalCtx = EMPTY_GLOBAL_CTX;
|
|
338
|
+
cachedGlobalCtxVersion = ctxVersion;
|
|
339
|
+
return cachedGlobalCtx;
|
|
340
|
+
}
|
|
341
|
+
const globalCtx = {};
|
|
342
|
+
for (const [contextId, stack] of contextStacks) {
|
|
343
|
+
if (stack.length > 0) {
|
|
344
|
+
globalCtx[contextId] = {
|
|
345
|
+
props: { value: stack[stack.length - 1] },
|
|
346
|
+
sub: noop
|
|
347
|
+
};
|
|
348
|
+
}
|
|
349
|
+
}
|
|
350
|
+
cachedGlobalCtx = globalCtx;
|
|
351
|
+
cachedGlobalCtxVersion = ctxVersion;
|
|
352
|
+
return globalCtx;
|
|
353
|
+
}
|
|
354
|
+
function render(node, inline) {
|
|
355
|
+
const t = typeof node;
|
|
356
|
+
if (t === "string") {
|
|
357
|
+
nlFlag = node.indexOf("\n") >= 0;
|
|
358
|
+
return escapeHtml(node);
|
|
359
|
+
}
|
|
360
|
+
if (t === "object") {
|
|
361
|
+
if (node === null) {
|
|
362
|
+
nlFlag = false;
|
|
363
|
+
return "";
|
|
364
|
+
}
|
|
365
|
+
if (Array.isArray(node)) {
|
|
366
|
+
let out = "";
|
|
367
|
+
let anyNewline = false;
|
|
368
|
+
for (let i = 0; i < node.length; i++) {
|
|
369
|
+
const child = node[i];
|
|
370
|
+
if (typeof child === "string") {
|
|
371
|
+
out += escapeHtml(child);
|
|
372
|
+
anyNewline = anyNewline || child.indexOf("\n") >= 0;
|
|
373
|
+
} else {
|
|
374
|
+
out += render(child, inline);
|
|
375
|
+
anyNewline = anyNewline || nlFlag;
|
|
376
|
+
}
|
|
377
|
+
}
|
|
378
|
+
nlFlag = anyNewline;
|
|
379
|
+
return out;
|
|
380
|
+
}
|
|
381
|
+
if (!("type" in node)) {
|
|
382
|
+
nlFlag = false;
|
|
383
|
+
return "";
|
|
384
|
+
}
|
|
385
|
+
const type = node.type;
|
|
386
|
+
if (typeof type === "string") {
|
|
387
|
+
return renderElement(type, node.props, inline);
|
|
388
|
+
}
|
|
389
|
+
if (type === Fragment) {
|
|
390
|
+
return renderChildren(node.props ? node.props.children : void 0);
|
|
391
|
+
}
|
|
392
|
+
if (typeof type === "function") {
|
|
393
|
+
return renderComponent(node);
|
|
394
|
+
}
|
|
395
|
+
return "";
|
|
396
|
+
}
|
|
397
|
+
if (t === "number" || t === "bigint") {
|
|
398
|
+
nlFlag = false;
|
|
399
|
+
return String(node);
|
|
400
|
+
}
|
|
401
|
+
nlFlag = false;
|
|
402
|
+
return "";
|
|
403
|
+
}
|
|
404
|
+
function renderComponent(vnode2) {
|
|
405
|
+
const { type, props } = vnode2;
|
|
406
|
+
const fn = type;
|
|
407
|
+
const fnAny = fn;
|
|
408
|
+
if (fnAny._isProvider && fnAny._context) {
|
|
409
|
+
const ctx = fnAny._context;
|
|
410
|
+
ctx._stack.push(props.value);
|
|
411
|
+
const result = activeChildren(props.children);
|
|
412
|
+
ctx._stack.pop();
|
|
413
|
+
return result;
|
|
414
|
+
}
|
|
415
|
+
let contextId;
|
|
416
|
+
if (typeof fnAny.__c === "string" && fnAny.__c.startsWith("__cC")) {
|
|
417
|
+
contextId = fnAny.__c;
|
|
418
|
+
} else if (fnAny.__ && typeof fnAny.__ === "object" && fnAny.__.__c) {
|
|
419
|
+
contextId = fnAny.__.__c;
|
|
420
|
+
}
|
|
421
|
+
if (contextId) {
|
|
422
|
+
pushCtx(contextId, props.value);
|
|
423
|
+
const result = activeChildren(props.children);
|
|
424
|
+
popCtx(contextId);
|
|
425
|
+
return result;
|
|
426
|
+
}
|
|
427
|
+
if (fn.contextType) {
|
|
428
|
+
const ctx = fn.contextType;
|
|
429
|
+
const ctxId = ctx.__c;
|
|
430
|
+
const stack = contextStacks?.get(ctxId);
|
|
431
|
+
const value = stack && stack.length > 0 ? stack[stack.length - 1] : ctx.__;
|
|
432
|
+
if (typeof props.children === "function") {
|
|
433
|
+
return activeRender(props.children(value));
|
|
434
|
+
}
|
|
435
|
+
return activeChildren(props.children);
|
|
436
|
+
}
|
|
437
|
+
const component = {
|
|
438
|
+
props,
|
|
439
|
+
context: buildGlobalContext(),
|
|
440
|
+
state: {},
|
|
441
|
+
__v: vnode2,
|
|
442
|
+
// _vnode
|
|
443
|
+
__d: false,
|
|
444
|
+
// _dirty
|
|
445
|
+
__h: [],
|
|
446
|
+
// _renderCallbacks
|
|
447
|
+
__s: {},
|
|
448
|
+
// _nextState
|
|
449
|
+
__H: null
|
|
450
|
+
// _hooks (initialised by hooks addon)
|
|
451
|
+
};
|
|
452
|
+
vnode2.__c = component;
|
|
453
|
+
preactOptions.__b?.(vnode2);
|
|
454
|
+
preactOptions.__r?.(vnode2);
|
|
455
|
+
try {
|
|
456
|
+
if (fn.prototype && fn.prototype.render) {
|
|
457
|
+
const instance = new fn(props, component.context);
|
|
458
|
+
instance.__n = component.__n;
|
|
459
|
+
instance.__H = component.__H;
|
|
460
|
+
vnode2.__c = instance;
|
|
461
|
+
preactOptions.__r?.(vnode2);
|
|
462
|
+
return activeRender(instance.render(instance.props, instance.state));
|
|
463
|
+
}
|
|
464
|
+
const rendered = fn(props, component.context);
|
|
465
|
+
return activeRender(rendered);
|
|
466
|
+
} finally {
|
|
467
|
+
preactOptions.diffed?.(vnode2);
|
|
468
|
+
}
|
|
469
|
+
}
|
|
470
|
+
function renderElement(tag, props, inline) {
|
|
471
|
+
const flags = TAG_STATIC_FLAGS.get(tag) || 0;
|
|
472
|
+
const isBlock = (flags & TAG_FLAG_ALWAYS_BLOCK) !== 0 || !inline && ((flags & TAG_FLAG_BLOCK) !== 0 || customBlockSet !== void 0 && customBlockSet.has(tag));
|
|
473
|
+
const attrs = renderAttrs(tag, props);
|
|
474
|
+
const openTag = "<" + tag + attrs + ">";
|
|
475
|
+
if ((flags & TAG_FLAG_VOID) !== 0) {
|
|
476
|
+
if (isBlock) {
|
|
477
|
+
nlFlag = true;
|
|
478
|
+
return openTag + "\n";
|
|
479
|
+
}
|
|
480
|
+
nlFlag = false;
|
|
481
|
+
return openTag;
|
|
482
|
+
}
|
|
483
|
+
let inner = "";
|
|
484
|
+
let innerHasNewline = false;
|
|
485
|
+
if (props) {
|
|
486
|
+
const dsih = props.dangerouslySetInnerHTML;
|
|
487
|
+
if (dsih && dsih.__html != null) {
|
|
488
|
+
inner = dsih.__html;
|
|
489
|
+
innerHasNewline = inner.includes("\n");
|
|
490
|
+
} else if (props.children != null) {
|
|
491
|
+
const children = props.children;
|
|
492
|
+
if (typeof children === "string") {
|
|
493
|
+
inner = escapeHtml(children);
|
|
494
|
+
innerHasNewline = children.indexOf("\n") >= 0;
|
|
495
|
+
} else {
|
|
496
|
+
inner = renderChildren(children);
|
|
497
|
+
innerHasNewline = nlFlag;
|
|
498
|
+
}
|
|
499
|
+
} else if (tag === "textarea") {
|
|
500
|
+
const textVal = props.value ?? props.defaultValue;
|
|
501
|
+
if (textVal != null) {
|
|
502
|
+
inner = escapeHtml(String(textVal));
|
|
503
|
+
innerHasNewline = inner.includes("\n");
|
|
504
|
+
}
|
|
505
|
+
}
|
|
506
|
+
}
|
|
507
|
+
if (isBlock) {
|
|
508
|
+
nlFlag = true;
|
|
509
|
+
const hasBlockChildren = (flags & TAG_FLAG_RAW) === 0 && innerHasNewline;
|
|
510
|
+
if (hasBlockChildren) {
|
|
511
|
+
return openTag + "\n" + inner + "</" + tag + ">\n";
|
|
512
|
+
}
|
|
513
|
+
return openTag + inner + "</" + tag + ">\n";
|
|
514
|
+
}
|
|
515
|
+
nlFlag = innerHasNewline;
|
|
516
|
+
return openTag + inner + "</" + tag + ">";
|
|
517
|
+
}
|
|
518
|
+
function renderAttrs(tag, props) {
|
|
519
|
+
if (!props) return "";
|
|
520
|
+
const isTextarea = tag === "textarea";
|
|
521
|
+
let result = "";
|
|
522
|
+
for (const key in props) {
|
|
523
|
+
const value = props[key];
|
|
524
|
+
if (value == null) continue;
|
|
525
|
+
if (key === "children" || key === "dangerouslySetInnerHTML" || key === "key" || key === "ref" || key === "__self" || key === "__source") {
|
|
526
|
+
continue;
|
|
527
|
+
}
|
|
528
|
+
if (isTextarea && (key === "value" || key === "defaultValue")) {
|
|
529
|
+
continue;
|
|
530
|
+
}
|
|
531
|
+
const attrName = PROP_TO_ATTR[key] || key;
|
|
532
|
+
const valueType = typeof value;
|
|
533
|
+
if (valueType === "string") {
|
|
534
|
+
result += " " + attrName + '="' + escapeAttr(value) + '"';
|
|
535
|
+
} else if (valueType === "number") {
|
|
536
|
+
result += " " + attrName + '="' + value + '"';
|
|
537
|
+
} else if (value === true) {
|
|
538
|
+
result += BOOLEAN_ATTRS.has(attrName) ? " " + attrName : " " + attrName + '="true"';
|
|
539
|
+
} else if (value === false) {
|
|
540
|
+
if (!BOOLEAN_ATTRS.has(attrName)) {
|
|
541
|
+
result += " " + attrName + '="false"';
|
|
542
|
+
}
|
|
543
|
+
} else if (valueType === "function") {
|
|
544
|
+
continue;
|
|
545
|
+
} else if (key === "style" && valueType === "object") {
|
|
546
|
+
const styleStr = styleToString(value);
|
|
547
|
+
if (styleStr) {
|
|
548
|
+
result += " " + attrName + '="' + escapeAttr(styleStr) + '"';
|
|
549
|
+
}
|
|
550
|
+
} else {
|
|
551
|
+
result += " " + attrName + '="' + escapeAttr(String(value)) + '"';
|
|
552
|
+
}
|
|
553
|
+
}
|
|
554
|
+
return result;
|
|
555
|
+
}
|
|
556
|
+
function hasMixedContent(children) {
|
|
557
|
+
let hasText = false;
|
|
558
|
+
let hasElement = false;
|
|
559
|
+
for (let i = 0; i < children.length; i++) {
|
|
560
|
+
const child = children[i];
|
|
561
|
+
const t = typeof child;
|
|
562
|
+
if (t === "string" || t === "number" || t === "bigint") {
|
|
563
|
+
hasText = true;
|
|
564
|
+
} else if (t === "object" && child !== null && "type" in child) {
|
|
565
|
+
hasElement = true;
|
|
566
|
+
}
|
|
567
|
+
if (hasText && hasElement) return true;
|
|
568
|
+
}
|
|
569
|
+
return false;
|
|
570
|
+
}
|
|
571
|
+
function renderChildren(children) {
|
|
572
|
+
if (children == null) {
|
|
573
|
+
nlFlag = false;
|
|
574
|
+
return "";
|
|
575
|
+
}
|
|
576
|
+
if (Array.isArray(children)) {
|
|
577
|
+
const inline = hasMixedContent(children);
|
|
578
|
+
let out = "";
|
|
579
|
+
let anyNewline = false;
|
|
580
|
+
for (let i = 0; i < children.length; i++) {
|
|
581
|
+
const child = children[i];
|
|
582
|
+
if (typeof child === "string") {
|
|
583
|
+
out += escapeHtml(child);
|
|
584
|
+
anyNewline = anyNewline || child.indexOf("\n") >= 0;
|
|
585
|
+
} else {
|
|
586
|
+
out += render(child, inline);
|
|
587
|
+
anyNewline = anyNewline || nlFlag;
|
|
588
|
+
}
|
|
589
|
+
}
|
|
590
|
+
nlFlag = anyNewline;
|
|
591
|
+
return out;
|
|
592
|
+
}
|
|
593
|
+
return render(children);
|
|
594
|
+
}
|
|
595
|
+
function mRender(node) {
|
|
596
|
+
const t = typeof node;
|
|
597
|
+
if (t === "string") {
|
|
598
|
+
return escapeHtml(node);
|
|
599
|
+
}
|
|
600
|
+
if (t === "object") {
|
|
601
|
+
if (node === null) {
|
|
602
|
+
return "";
|
|
603
|
+
}
|
|
604
|
+
if (Array.isArray(node)) {
|
|
605
|
+
let out = "";
|
|
606
|
+
for (let i = 0; i < node.length; i++) {
|
|
607
|
+
const child = node[i];
|
|
608
|
+
out += typeof child === "string" ? escapeHtml(child) : mRender(child);
|
|
609
|
+
}
|
|
610
|
+
return out;
|
|
611
|
+
}
|
|
612
|
+
if (!("type" in node)) {
|
|
613
|
+
return "";
|
|
614
|
+
}
|
|
615
|
+
const type = node.type;
|
|
616
|
+
if (typeof type === "string") {
|
|
617
|
+
return mElement(type, node.props);
|
|
618
|
+
}
|
|
619
|
+
if (type === Fragment) {
|
|
620
|
+
return mChildren(node.props ? node.props.children : void 0);
|
|
621
|
+
}
|
|
622
|
+
if (typeof type === "function") {
|
|
623
|
+
return renderComponent(node);
|
|
624
|
+
}
|
|
625
|
+
return "";
|
|
626
|
+
}
|
|
627
|
+
if (t === "number" || t === "bigint") {
|
|
628
|
+
return String(node);
|
|
629
|
+
}
|
|
630
|
+
return "";
|
|
631
|
+
}
|
|
632
|
+
function mElement(tag, props) {
|
|
633
|
+
const attrs = renderAttrs(tag, props);
|
|
634
|
+
if (VOID_ELEMENTS.has(tag)) {
|
|
635
|
+
return "<" + tag + attrs + ">";
|
|
636
|
+
}
|
|
637
|
+
let inner = "";
|
|
638
|
+
if (props) {
|
|
639
|
+
const dsih = props.dangerouslySetInnerHTML;
|
|
640
|
+
if (dsih && dsih.__html != null) {
|
|
641
|
+
inner = dsih.__html;
|
|
642
|
+
} else {
|
|
643
|
+
const children = props.children;
|
|
644
|
+
if (children != null) {
|
|
645
|
+
inner = typeof children === "string" ? escapeHtml(children) : mChildren(children);
|
|
646
|
+
} else if (tag === "textarea") {
|
|
647
|
+
const textVal = props.value ?? props.defaultValue;
|
|
648
|
+
if (textVal != null) {
|
|
649
|
+
inner = escapeHtml(String(textVal));
|
|
650
|
+
}
|
|
651
|
+
}
|
|
652
|
+
}
|
|
653
|
+
}
|
|
654
|
+
return "<" + tag + attrs + ">" + inner + "</" + tag + ">";
|
|
655
|
+
}
|
|
656
|
+
function mChildren(children) {
|
|
657
|
+
if (children == null) {
|
|
658
|
+
return "";
|
|
659
|
+
}
|
|
660
|
+
if (Array.isArray(children)) {
|
|
661
|
+
let out = "";
|
|
662
|
+
for (let i = 0; i < children.length; i++) {
|
|
663
|
+
const child = children[i];
|
|
664
|
+
const t2 = typeof child;
|
|
665
|
+
if (t2 === "string") {
|
|
666
|
+
out += escapeHtml(child);
|
|
667
|
+
} else if (t2 === "object" && child !== null && typeof child.type === "string") {
|
|
668
|
+
out += mElement(child.type, child.props);
|
|
669
|
+
} else {
|
|
670
|
+
out += mRender(child);
|
|
671
|
+
}
|
|
672
|
+
}
|
|
673
|
+
return out;
|
|
674
|
+
}
|
|
675
|
+
const t = typeof children;
|
|
676
|
+
if (t === "string") {
|
|
677
|
+
return escapeHtml(children);
|
|
678
|
+
}
|
|
679
|
+
if (t === "object" && children !== null && typeof children.type === "string") {
|
|
680
|
+
return mElement(children.type, children.props);
|
|
681
|
+
}
|
|
682
|
+
return mRender(children);
|
|
683
|
+
}
|
|
684
|
+
const activeRender = isPretty ? render : mRender;
|
|
685
|
+
const activeChildren = isPretty ? renderChildren : mChildren;
|
|
686
|
+
return activeRender(vnode);
|
|
687
|
+
}
|
|
688
|
+
function noop() {
|
|
689
|
+
}
|
|
690
|
+
|
|
691
|
+
export {
|
|
692
|
+
renderJsxToString
|
|
693
|
+
};
|
|
694
|
+
//# sourceMappingURL=chunk-AJR6VAT7.js.map
|