castle-web-sdk 0.4.0 → 0.4.1

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 (3) hide show
  1. package/AGENTS.md +1 -1
  2. package/castle.js +15 -1
  3. package/package.json +1 -1
package/AGENTS.md CHANGED
@@ -6,7 +6,7 @@ Import from `castle-web-sdk` (or `./castle.js` directly).
6
6
 
7
7
  ### `setup()`
8
8
 
9
- Connects to the CLI dev server for console log forwarding, screenshot capture, and live reload. Call once at startup.
9
+ Connects to the CLI dev server for console log forwarding, screenshot capture, and live reload (`restart` command triggers page reload). Call once at startup.
10
10
 
11
11
  ```js
12
12
  import { setup } from 'castle-web-sdk';
package/castle.js CHANGED
@@ -75,11 +75,25 @@ function _interceptConsole() {
75
75
  // --- Screenshot ---
76
76
 
77
77
  async function _captureScreenshot() {
78
+ const card = document.getElementById('castle-card');
78
79
  const canvas = document.querySelector('canvas');
80
+ if (card && canvas) {
81
+ // Capture just the card area
82
+ const cardRect = card.getBoundingClientRect();
83
+ const c = document.createElement('canvas');
84
+ c.width = cardRect.width * devicePixelRatio;
85
+ c.height = cardRect.height * devicePixelRatio;
86
+ const ctx = c.getContext('2d');
87
+ const canvasRect = canvas.getBoundingClientRect();
88
+ const dx = (canvasRect.left - cardRect.left) * devicePixelRatio;
89
+ const dy = (canvasRect.top - cardRect.top) * devicePixelRatio;
90
+ ctx.drawImage(canvas, dx, dy, canvasRect.width * devicePixelRatio, canvasRect.height * devicePixelRatio);
91
+ return c.toDataURL('image/png');
92
+ }
79
93
  if (canvas) return canvas.toDataURL('image/png');
80
94
  try {
81
95
  const { default: html2canvas } = await import('https://esm.sh/html2canvas');
82
- const c = await html2canvas(document.body);
96
+ const c = await html2canvas(card || document.body);
83
97
  return c.toDataURL('image/png');
84
98
  } catch { return null; }
85
99
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "castle-web-sdk",
3
- "version": "0.4.0",
3
+ "version": "0.4.1",
4
4
  "type": "module",
5
5
  "main": "castle.js",
6
6
  "exports": {