castle-web-sdk 0.4.13 → 0.4.15

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.
Files changed (2) hide show
  1. package/dist/runtime.js +39 -3
  2. package/package.json +1 -1
package/dist/runtime.js CHANGED
@@ -28,6 +28,21 @@ export function setup() {
28
28
  initHostCapture();
29
29
  initPlaySelection();
30
30
  initPlayCard();
31
+ logPanelLoad();
32
+ }
33
+ // Every panel boot leaves a line, so a reload from ANY cause shows up -- a load
34
+ // with no preceding reason line is one we do not yet explain.
35
+ function panelTag() {
36
+ try {
37
+ const q = new URLSearchParams(location.search);
38
+ return q.get("panel") || q.get("file") || "deck";
39
+ }
40
+ catch {
41
+ return "deck";
42
+ }
43
+ }
44
+ function logPanelLoad() {
45
+ setTimeout(() => console.log(`[reload] ${panelTag()} LOADED`), 0);
31
46
  }
32
47
  export function writeFile(path, contents) {
33
48
  return sendLocalRequest({
@@ -120,6 +135,26 @@ function initPlayCard() {
120
135
  }
121
136
  `;
122
137
  document.head.appendChild(style);
138
+ // Mark whatever this turns into a card, the way `initCard` marks the one it
139
+ // creates. Anything looking for "the card" -- a capture cropping to it, in
140
+ // page or headless -- otherwise finds nothing here and has to guess at the
141
+ // viewport, which is not the same rectangle: standalone chrome insets the
142
+ // card, so a viewport shot carries a border the card does not have.
143
+ //
144
+ // Runs on a timer as well as now because `setup()` is called before a deck
145
+ // renders, so #root is usually still empty at this point; a deck that mounts
146
+ // later still gets its card marked.
147
+ function markCard() {
148
+ const el = document.querySelector("#root > *");
149
+ if (el)
150
+ el.dataset.castleCard = "";
151
+ }
152
+ markCard();
153
+ requestAnimationFrame(markCard);
154
+ new MutationObserver(markCard).observe(document.documentElement, {
155
+ childList: true,
156
+ subtree: true,
157
+ });
123
158
  function resize() {
124
159
  const { w, h } = computeCardSize();
125
160
  document.documentElement.style.setProperty("--castle-card-w", w + "px");
@@ -481,7 +516,7 @@ function handleLocalMessage(msg) {
481
516
  });
482
517
  }
483
518
  else if (msg.type === "restart") {
484
- scheduleReload(RESTART_DEBOUNCE_MS);
519
+ scheduleReload(RESTART_DEBOUNCE_MS, "restart message");
485
520
  }
486
521
  else if (msg.type === "files_changed") {
487
522
  dispatchFilesChanged(msg);
@@ -590,9 +625,10 @@ function stashReloadState() {
590
625
  // Reload this page after honoring the save hooks. Consumers call this when a
591
626
  // files-changed event tells them code they run on has changed.
592
627
  export function requestReload() {
593
- scheduleReload(REQUEST_RELOAD_DEBOUNCE_MS);
628
+ scheduleReload(REQUEST_RELOAD_DEBOUNCE_MS, "requestReload");
594
629
  }
595
- function scheduleReload(delayMs) {
630
+ function scheduleReload(delayMs, reason = "unknown") {
631
+ console.log(`[reload] ${panelTag()} scheduling reload (${reason})`);
596
632
  if (restartTimer !== null)
597
633
  clearTimeout(restartTimer);
598
634
  restartTimer = setTimeout(() => {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "castle-web-sdk",
3
- "version": "0.4.13",
3
+ "version": "0.4.15",
4
4
  "type": "module",
5
5
  "main": "dist/castle.js",
6
6
  "types": "dist/castle.d.ts",