@symbiotejs/symbiote 3.5.4 → 3.5.6
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/core/Symbiote.js +1 -0
- package/node/SSR.js +35 -11
- package/package.json +1 -1
- package/types/core/Symbiote.d.ts.map +1 -1
- package/types/node/SSR.d.ts.map +1 -1
package/core/Symbiote.js
CHANGED
|
@@ -531,6 +531,7 @@ export class Symbiote extends HTMLElement {
|
|
|
531
531
|
|
|
532
532
|
destructionDelay = 100;
|
|
533
533
|
disconnectedCallback() {
|
|
534
|
+
if (globalThis.__SYMBIOTE_SSR) return;
|
|
534
535
|
// if element wasn't connected, there is no need to disconnect it
|
|
535
536
|
if (!this.connectedOnce) {
|
|
536
537
|
return;
|
package/node/SSR.js
CHANGED
|
@@ -41,6 +41,21 @@ function extractCSS(sheet) {
|
|
|
41
41
|
return text;
|
|
42
42
|
}
|
|
43
43
|
|
|
44
|
+
/**
|
|
45
|
+
* Check if a node is inside a <pre> or <code> ancestor.
|
|
46
|
+
* @param {Node} node
|
|
47
|
+
* @returns {boolean}
|
|
48
|
+
*/
|
|
49
|
+
function isInsidePreformatted(node) {
|
|
50
|
+
let el = node.parentElement;
|
|
51
|
+
while (el) {
|
|
52
|
+
let tag = el.localName;
|
|
53
|
+
if (tag === 'pre' || tag === 'code') return true;
|
|
54
|
+
el = el.parentElement;
|
|
55
|
+
}
|
|
56
|
+
return false;
|
|
57
|
+
}
|
|
58
|
+
|
|
44
59
|
/**
|
|
45
60
|
* Resolve {{prop}} text node tokens by reading values from the closest custom element.
|
|
46
61
|
* @param {string} text
|
|
@@ -146,8 +161,9 @@ function serializeAttrs(el) {
|
|
|
146
161
|
* @returns {string}
|
|
147
162
|
*/
|
|
148
163
|
function serializeNode(node, emittedStyles, nonce) {
|
|
149
|
-
|
|
150
|
-
|
|
164
|
+
let preformatted = isInsidePreformatted(node);
|
|
165
|
+
// Custom element — recurse (skip inside pre/code):
|
|
166
|
+
if (!preformatted && node.nodeType === 1 && /** @type {Element} */ (node).localName?.includes('-')) {
|
|
151
167
|
return serializeElement(/** @type {HTMLElement} */ (node), emittedStyles, nonce);
|
|
152
168
|
}
|
|
153
169
|
// Regular element:
|
|
@@ -162,6 +178,7 @@ function serializeNode(node, emittedStyles, nonce) {
|
|
|
162
178
|
}
|
|
163
179
|
// Text node:
|
|
164
180
|
if (node.nodeType === 3) {
|
|
181
|
+
if (preformatted) return node.textContent || '';
|
|
165
182
|
return resolveTextTokens(node.textContent || '', node);
|
|
166
183
|
}
|
|
167
184
|
// Comment:
|
|
@@ -233,7 +250,9 @@ async function* streamElement(el, emittedStyles, nonce) {
|
|
|
233
250
|
* @returns {AsyncGenerator<string>}
|
|
234
251
|
*/
|
|
235
252
|
async function* streamNode(node, emittedStyles, nonce) {
|
|
236
|
-
|
|
253
|
+
let preformatted = isInsidePreformatted(node);
|
|
254
|
+
// Custom element — stream (skip inside pre/code):
|
|
255
|
+
if (!preformatted && node.nodeType === 1 && /** @type {Element} */ (node).localName?.includes('-')) {
|
|
237
256
|
yield* streamElement(/** @type {HTMLElement} */ (node), emittedStyles, nonce);
|
|
238
257
|
return;
|
|
239
258
|
}
|
|
@@ -252,7 +271,11 @@ async function* streamNode(node, emittedStyles, nonce) {
|
|
|
252
271
|
return;
|
|
253
272
|
}
|
|
254
273
|
if (node.nodeType === 3) {
|
|
255
|
-
|
|
274
|
+
if (preformatted) {
|
|
275
|
+
yield node.textContent || '';
|
|
276
|
+
} else {
|
|
277
|
+
yield resolveTextTokens(node.textContent || '', node);
|
|
278
|
+
}
|
|
256
279
|
return;
|
|
257
280
|
}
|
|
258
281
|
if (node.nodeType === 8) {
|
|
@@ -342,9 +365,6 @@ export class SSR {
|
|
|
342
365
|
* Called automatically by processHtml(). Call manually only after renderToString/renderToStream.
|
|
343
366
|
*/
|
|
344
367
|
static destroy() {
|
|
345
|
-
if (SSR.#doc) {
|
|
346
|
-
SSR.#doc.body.innerHTML = '';
|
|
347
|
-
}
|
|
348
368
|
delete globalThis.__SYMBIOTE_SSR;
|
|
349
369
|
delete globalThis.document;
|
|
350
370
|
delete globalThis.window;
|
|
@@ -375,6 +395,13 @@ export class SSR {
|
|
|
375
395
|
* ```
|
|
376
396
|
*/
|
|
377
397
|
static async processHtml(html, options = {}) {
|
|
398
|
+
let doctype = '';
|
|
399
|
+
let doctypeMatch = html.match(/^(\s*<!doctype[^>]*>\s*)/i);
|
|
400
|
+
if (doctypeMatch) {
|
|
401
|
+
doctype = doctypeMatch[1];
|
|
402
|
+
html = html.slice(doctypeMatch[0].length);
|
|
403
|
+
}
|
|
404
|
+
|
|
378
405
|
let autoInited = !SSR.#doc;
|
|
379
406
|
if (autoInited) {
|
|
380
407
|
await SSR.init();
|
|
@@ -385,11 +412,10 @@ export class SSR {
|
|
|
385
412
|
for (let child of SSR.#doc.body.childNodes) {
|
|
386
413
|
result += serializeNode(child, emittedStyles, options.nonce);
|
|
387
414
|
}
|
|
388
|
-
SSR.#doc.body.innerHTML = '';
|
|
389
415
|
if (autoInited) {
|
|
390
416
|
SSR.destroy();
|
|
391
417
|
}
|
|
392
|
-
return result;
|
|
418
|
+
return doctype + result;
|
|
393
419
|
}
|
|
394
420
|
|
|
395
421
|
/**
|
|
@@ -422,7 +448,6 @@ export class SSR {
|
|
|
422
448
|
html = serializeElement(el, new Set(), options.nonce);
|
|
423
449
|
el.remove();
|
|
424
450
|
}
|
|
425
|
-
SSR.#doc.body.innerHTML = '';
|
|
426
451
|
return html;
|
|
427
452
|
}
|
|
428
453
|
|
|
@@ -454,7 +479,6 @@ export class SSR {
|
|
|
454
479
|
yield* streamElement(el, new Set(), options.nonce);
|
|
455
480
|
el.remove();
|
|
456
481
|
}
|
|
457
|
-
SSR.#doc.body.innerHTML = '';
|
|
458
482
|
}
|
|
459
483
|
}
|
|
460
484
|
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"type": "module",
|
|
3
3
|
"name": "@symbiotejs/symbiote",
|
|
4
|
-
"version": "3.5.
|
|
4
|
+
"version": "3.5.6",
|
|
5
5
|
"description": "Symbiote.js - zero-dependency close-to-platform frontend library to build super-powered web components",
|
|
6
6
|
"author": "team@rnd-pro.com",
|
|
7
7
|
"license": "MIT",
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Symbiote.d.ts","sourceRoot":"","sources":["../../core/Symbiote.js"],"names":[],"mappings":";;AAoBA,sBADc,CAAC;IAuBb,cADW,mBAAmB,CACjB;IAEb,iCAEC;IAED,8BAEC;IAkBD,wBAAgB;IA8JhB,+BAJwB,CAAC,SAAZ,aAAU,uBAEZ,CAAC;;;MA0CX;IAuQD,qCAA+B;
|
|
1
|
+
{"version":3,"file":"Symbiote.d.ts","sourceRoot":"","sources":["../../core/Symbiote.js"],"names":[],"mappings":";;AAoBA,sBADc,CAAC;IAuBb,cADW,mBAAmB,CACjB;IAEb,iCAEC;IAED,8BAEC;IAkBD,wBAAgB;IA8JhB,+BAJwB,CAAC,SAAZ,aAAU,uBAEZ,CAAC;;;MA0CX;IAuQD,qCAA+B;IAqC/B,iDAFa,OAAO,QAAQ,CAkB3B;IAED,wBAKC;IAGD;;aAYC;IAmHD,6BADY,SAAS,aAAa,QAOjC;IAGD,+BADY,SAAS,aAAa,QAOjC;IAGD,8BADY,SAAS,aAAa,EAIjC;IAGD,gCADY,SAAS,aAAa,EAIjC;IA1kBD,cA6BC;IAzID,gCAEC;IAED,qBAAiB;IACjB,uBAAmB;IAiBnB,kBAHW,SAAS,gBAAgB,0BAuFnC;IAxDG,aAAiD;IA6DnD,OADW,CAAC,CACoB;IAEhC;;MAAmC;IAEnC,oBADW,GAAG,CAAC,CAAC,EAAE,EAAE,gBAAgB,gBAAW,EAAE,KAAK,eAAU,KAAK,IAAI,CAAC,CACvC;IAEnC;;MAA8B;IAC9B,kBAAwB;IAExB,qBAAwB;IAExB,sBAAyB;IAEzB,wBAA0B;IAE1B,0BAA6B;IAI7B,iBAAoB;IAEpB,6BAAgC;IAEhC,mBAAsB;IAEtB,4BAA8B;IAIhC,yBAEC;IAGD,sBASC;IAGD,4BAKC;IAGD,6BAEC;IAuDD,IALuB,CAAC,SAAX,MAAO,CAAE,QACX,CAAC,WACD,CAAC,KAAK,EAAE,CAAC,CAAC,CAAC,CAAC,KAAK,IAAI,wBAuC/B;IAGD,2BAIC;IAGD,uBAIC;IAQD,IALuB,CAAC,SAAX,MAAO,CAAE,qBAEX,CAAC,CAAC,CAAC,CAAC,2BAOd;IAMD,UAHW,OAAO,CAAC,CAAC,CAAC,2BAOpB;IAGD,SADc,CAAC,CA6Bd;IAMD,YAHW,OAAO,CAAC,CAAC,CAAC,mCAcpB;IAED,8BAgBC;IAdG,4CASE;IAmFF,0BAAwC;IAwB1C,uBAAyB;IAG3B,0BAEC;IAED,wBAAoB;IAUpB,yBAAuB;IACvB,6BA2BC;IA+CD,oEAeC;IAMD,yDAoBC;IAYD,0BAME;IAMF,0CAFW,GAAG,QAgBb;IAED,yBAGC;IAOD,8EAmBC;;CA+BF;;mBA3uBkB,aAAa;qBAEX,iBAAiB;2BACX,iBAAiB"}
|
package/types/node/SSR.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"SSR.d.ts","sourceRoot":"","sources":["../../node/SSR.js"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"SSR.d.ts","sourceRoot":"","sources":["../../node/SSR.js"],"names":[],"mappings":"AA6RA;IAEE,8BAAmB;IACnB,8BAAmB;IAMnB;;;OAkEC;IAMD,uBAYC;IAkBD,yBAZW,MAAM,YACN;QAAE,KAAK,CAAC,EAAE,MAAM,CAAA;KAAE,GAChB,OAAO,CAAC,MAAM,CAAC,CAgC3B;IAWD,+BALW,MAAM;;iBAEN;QAAE,KAAK,CAAC,EAAE,MAAM,CAAA;KAAE,GAChB,MAAM,CAwBlB;IAWD,+BALW,MAAM;;iBAEN;QAAE,KAAK,CAAC,EAAE,MAAM,CAAA;KAAE,GAChB,cAAc,CAAC,MAAM,CAAC,CAqBlC;CACF"}
|