@lightspeed-js/core 0.4.3 → 0.4.4

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/compile.js CHANGED
@@ -71,7 +71,7 @@ var START = "lsp ";
71
71
  var END = "/lsp";
72
72
  var MARKER_END = `<!--${END}-->`;
73
73
  function serializeMarker(payload) {
74
- const json = JSON.stringify(payload).replace(/-(?=-)/g, "\\u002d");
74
+ const json = JSON.stringify(payload).replace(/-(?=-)/g, "\\u002d").replace(/</g, "\\u003c");
75
75
  return `<!--${START}${json}-->`;
76
76
  }
77
77
 
package/dist/index.js CHANGED
@@ -1275,6 +1275,11 @@ function isSlotStash(node) {
1275
1275
  function slotNodesFor(payload, between) {
1276
1276
  if (!payload.ssr)
1277
1277
  return between;
1278
+ if (payload.slot) {
1279
+ const template = document.createElement("template");
1280
+ template.innerHTML = payload.slot;
1281
+ return Array.from(template.content.childNodes);
1282
+ }
1278
1283
  const stash = between.find(isSlotStash);
1279
1284
  return stash ? Array.from(stash.content.childNodes) : [];
1280
1285
  }
package/dist/ssg.js CHANGED
@@ -1260,7 +1260,7 @@ var START = "lsp ";
1260
1260
  var END = "/lsp";
1261
1261
  var MARKER_END = `<!--${END}-->`;
1262
1262
  function serializeMarker(payload) {
1263
- const json = JSON.stringify(payload).replace(/-(?=-)/g, "\\u002d");
1263
+ const json = JSON.stringify(payload).replace(/-(?=-)/g, "\\u002d").replace(/</g, "\\u003c");
1264
1264
  return `<!--${START}${json}-->`;
1265
1265
  }
1266
1266
  function isMarkerStart(node) {
@@ -1298,6 +1298,11 @@ function isSlotStash(node) {
1298
1298
  function slotNodesFor(payload, between) {
1299
1299
  if (!payload.ssr)
1300
1300
  return between;
1301
+ if (payload.slot) {
1302
+ const template = document.createElement("template");
1303
+ template.innerHTML = payload.slot;
1304
+ return Array.from(template.content.childNodes);
1305
+ }
1301
1306
  const stash = between.find(isSlotStash);
1302
1307
  return stash ? Array.from(stash.content.childNodes) : [];
1303
1308
  }
@@ -3355,7 +3360,7 @@ function readIslands(document2) {
3355
3360
  hydrate: payload?.hydrate,
3356
3361
  binds: Object.values(payload?.bind ?? {}),
3357
3362
  handlers: Object.keys(payload?.on ?? {}).length,
3358
- slotted: false,
3363
+ slotted: !!payload?.slot,
3359
3364
  children: []
3360
3365
  };
3361
3366
  (stack[stack.length - 1]?.children ?? roots).push(island);
@@ -3366,9 +3371,6 @@ function readIslands(document2) {
3366
3371
  for (let cursor = island.start.nextSibling;cursor && cursor !== island.end; cursor = cursor.nextSibling) {
3367
3372
  if (cursor.nodeType !== 1)
3368
3373
  continue;
3369
- if (cursor.hasAttribute("data-lsp-slot")) {
3370
- island.slotted = true;
3371
- }
3372
3374
  const id = cursor.getAttribute("data-lsp-instance");
3373
3375
  if (id && !island.instance)
3374
3376
  island.instance = id;
@@ -3430,13 +3432,9 @@ function markRendered(document2, slots) {
3430
3432
  continue;
3431
3433
  }
3432
3434
  payload.ssr = 1;
3435
+ if (slot.html.trim())
3436
+ payload.slot = slot.html;
3433
3437
  slot.start.data = serializeMarker(payload).slice(4, -3);
3434
- if (slot.html.trim()) {
3435
- const template = document2.createElement("template");
3436
- template.setAttribute("data-lsp-slot", "");
3437
- template.innerHTML = slot.html;
3438
- slot.start.parentNode?.insertBefore(template, slot.start.nextSibling);
3439
- }
3440
3438
  rendered++;
3441
3439
  }
3442
3440
  return { rendered, skipped };
@@ -60,11 +60,24 @@ export interface MarkerPayload {
60
60
  needs?: string[];
61
61
  /** Set by the build: the content between the markers is rendered output. */
62
62
  ssr?: number;
63
+ /**
64
+ * Set by the build: the island's slot content, as HTML, for the client to
65
+ * rebuild from - the content between the markers is output, not slot
66
+ * content.
67
+ *
68
+ * In the marker rather than in an element beside the output, because an
69
+ * element there is a sibling the page's CSS can see: a stash before each
70
+ * island broke `.item + .item` in the build's HTML, and the layout shifted
71
+ * when hydration took the stash away.
72
+ */
73
+ slot?: string;
63
74
  }
64
75
  export declare const MARKER_END = "<!--/lsp-->";
65
76
  /**
66
77
  * A comment may not contain `--`, so any run of dashes in the payload is
67
- * escaped. `-` parses back to `-`, so the round trip is lossless.
78
+ * escaped; nor `<!--`, which slot content full of nested markers would bring,
79
+ * so `<` is escaped too. Both parse back to themselves: the round trip is
80
+ * lossless.
68
81
  */
69
82
  export declare function serializeMarker(payload: MarkerPayload): string;
70
83
  export declare function isMarkerStart(node: Node): boolean;
@@ -75,13 +88,17 @@ export declare function parseMarker(node: Node): MarkerPayload | null;
75
88
  * Returns -1 if unterminated.
76
89
  */
77
90
  export declare function findMarkerEnd(nodes: Node[], start: number): number;
78
- /** The inert `<template data-lsp-slot>` a server-rendered island keeps its slot content in. */
91
+ /**
92
+ * The inert `<template data-lsp-slot>` a server-rendered island kept its slot
93
+ * content in before 0.4.4. The payload's `slot` replaced it; this stays so a
94
+ * page built by an older version still hydrates.
95
+ */
79
96
  export declare function isSlotStash(node: Node): boolean;
80
97
  /**
81
98
  * The slot content for a marker.
82
99
  *
83
100
  * For a server-rendered island the nodes between the comments are *output*,
84
- * not slot content - the original is stashed in an inert
85
- * `<template data-lsp-slot>` so the client can rebuild from it.
101
+ * not slot content - the original travels in the payload's `slot` (or, from
102
+ * builds before 0.4.4, in a `<template data-lsp-slot>` stash).
86
103
  */
87
104
  export declare function slotNodesFor(payload: MarkerPayload, between: Node[]): Node[];
package/dist/vite.js CHANGED
@@ -691,7 +691,7 @@ var START = "lsp ";
691
691
  var END = "/lsp";
692
692
  var MARKER_END = `<!--${END}-->`;
693
693
  function serializeMarker(payload) {
694
- const json = JSON.stringify(payload).replace(/-(?=-)/g, "\\u002d");
694
+ const json = JSON.stringify(payload).replace(/-(?=-)/g, "\\u002d").replace(/</g, "\\u003c");
695
695
  return `<!--${START}${json}-->`;
696
696
  }
697
697
  function isMarkerStart(node) {
@@ -729,6 +729,11 @@ function isSlotStash(node) {
729
729
  function slotNodesFor(payload, between) {
730
730
  if (!payload.ssr)
731
731
  return between;
732
+ if (payload.slot) {
733
+ const template = document.createElement("template");
734
+ template.innerHTML = payload.slot;
735
+ return Array.from(template.content.childNodes);
736
+ }
732
737
  const stash = between.find(isSlotStash);
733
738
  return stash ? Array.from(stash.content.childNodes) : [];
734
739
  }
@@ -4746,7 +4751,7 @@ function readIslands(document2) {
4746
4751
  hydrate: payload?.hydrate,
4747
4752
  binds: Object.values(payload?.bind ?? {}),
4748
4753
  handlers: Object.keys(payload?.on ?? {}).length,
4749
- slotted: false,
4754
+ slotted: !!payload?.slot,
4750
4755
  children: []
4751
4756
  };
4752
4757
  (stack[stack.length - 1]?.children ?? roots).push(island);
@@ -4757,9 +4762,6 @@ function readIslands(document2) {
4757
4762
  for (let cursor = island.start.nextSibling;cursor && cursor !== island.end; cursor = cursor.nextSibling) {
4758
4763
  if (cursor.nodeType !== 1)
4759
4764
  continue;
4760
- if (cursor.hasAttribute("data-lsp-slot")) {
4761
- island.slotted = true;
4762
- }
4763
4765
  const id = cursor.getAttribute("data-lsp-instance");
4764
4766
  if (id && !island.instance)
4765
4767
  island.instance = id;
@@ -4821,13 +4823,9 @@ function markRendered(document2, slots) {
4821
4823
  continue;
4822
4824
  }
4823
4825
  payload.ssr = 1;
4826
+ if (slot.html.trim())
4827
+ payload.slot = slot.html;
4824
4828
  slot.start.data = serializeMarker(payload).slice(4, -3);
4825
- if (slot.html.trim()) {
4826
- const template = document2.createElement("template");
4827
- template.setAttribute("data-lsp-slot", "");
4828
- template.innerHTML = slot.html;
4829
- slot.start.parentNode?.insertBefore(template, slot.start.nextSibling);
4830
- }
4831
4829
  rendered++;
4832
4830
  }
4833
4831
  return { rendered, skipped };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@lightspeed-js/core",
3
- "version": "0.4.3",
3
+ "version": "0.4.4",
4
4
  "description": "Lightspeed: a compile-first framework for islands of reactivity in static HTML.",
5
5
  "keywords": [
6
6
  "lightspeed",