@valbuild/shared 0.150.12 → 0.150.13

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.
@@ -3,6 +3,24 @@
3
3
  var createForOfIteratorHelper = require('./createForOfIteratorHelper-f2d7ac6d.cjs.dev.js');
4
4
  var core = require('@valbuild/core');
5
5
 
6
+ function _interopNamespace(e) {
7
+ if (e && e.__esModule) return e;
8
+ var n = Object.create(null);
9
+ if (e) {
10
+ Object.keys(e).forEach(function (k) {
11
+ if (k !== 'default') {
12
+ var d = Object.getOwnPropertyDescriptor(e, k);
13
+ Object.defineProperty(n, k, d.get ? d : {
14
+ enumerable: true,
15
+ get: function () { return e[k]; }
16
+ });
17
+ }
18
+ });
19
+ }
20
+ n["default"] = e;
21
+ return Object.freeze(n);
22
+ }
23
+
6
24
  var VAL_CONFIG_SESSION_STORAGE_KEY = "val-config";
7
25
  var VAL_THEME_SESSION_STORAGE_KEY = "val-theme";
8
26
  var VAL_AI_SESSION_STORAGE_KEY = "val-ai-session";
@@ -324,7 +342,7 @@ function isValCanvasPageMessage(data) {
324
342
  if (createForOfIteratorHelper._typeof(data) !== "object" || data === null) return false;
325
343
  var message = data;
326
344
  if (message.val !== VAL_CANVAS_MESSAGE) return false;
327
- return message.type === "ready" || message.type === "elements" || message.type === "clicked" || message.type === "pinch" || message.type === "zoom" || message.type === "refreshing" || message.type === "elementPickingStopped" || message.type === "elementPicked" && isPickedElement(data.element) || message.type === "location" && isPageLocation(data) || message.type === "pageRead" && typeof data.requestId === "string" || message.type === "quickPreviewStored" && typeof data.id === "string";
345
+ return message.type === "ready" || message.type === "elements" || message.type === "clicked" || message.type === "pinch" || message.type === "zoom" || message.type === "refreshing" || message.type === "elementPickingStopped" || message.type === "elementPicked" && isPickedElement(data.element) || message.type === "location" && isPageLocation(data) || message.type === "pageRead" && typeof data.requestId === "string" || message.type === "pageScreenshot" && typeof data.requestId === "string" || message.type === "quickPreviewStored" && typeof data.id === "string";
328
346
  }
329
347
  function isPageLocation(value) {
330
348
  var location = value;
@@ -381,6 +399,10 @@ function isValCanvasStudioMessage(data) {
381
399
  var preview = data;
382
400
  return typeof preview.id === "string" && /^[A-Za-z0-9_-]{1,64}$/.test(preview.id) && isQuickPreviewFiles(preview.files);
383
401
  }
402
+ if (message.type === "screenshotPage") {
403
+ var asked = data;
404
+ return typeof asked.requestId === "string" && (asked.fullPage === undefined || typeof asked.fullPage === "boolean");
405
+ }
384
406
  if (message.type === "readPage") {
385
407
  var read = data;
386
408
  return typeof read.requestId === "string" && (read.selector === undefined || typeof read.selector === "string") && (read.maxItems === undefined || typeof read.maxItems === "number");
@@ -1139,6 +1161,137 @@ function selectorOf(element, root) {
1139
1161
  return parts.join(" > ");
1140
1162
  }
1141
1163
 
1164
+ /**
1165
+ * A picture of the page, taken in the page: the assistant's
1166
+ * `screenshot_page`, so it can see a change it made rather than only read it
1167
+ * (`read_page` gives the words and the boxes).
1168
+ *
1169
+ * Taken HERE because nothing else can: the design tab is another origin than
1170
+ * the proposal's page in its frame, and a browser lets no page photograph a
1171
+ * frame of another origin. So the bridge renders its own document --
1172
+ * `modern-screenshot` draws the DOM, with its computed styles, fonts and
1173
+ * same-origin images, into a canvas -- and hands back a JPEG.
1174
+ *
1175
+ * It is a rendering of the DOM, not of the screen: an image from another
1176
+ * origin that does not allow it, a video frame, a `<canvas>` a script drew
1177
+ * and an iframe come out blank. Good enough to see a layout, a colour, a
1178
+ * button that wrapped; the tool says what it cannot show.
1179
+ *
1180
+ * Loaded when asked: the library is not in a page that is never
1181
+ * photographed.
1182
+ */
1183
+
1184
+ /** What `screenshotPage` answers. */
1185
+
1186
+ /** Wider than this is scaled down: a model reads a page no better larger. */
1187
+ var MAX_WIDTH = 1280;
1188
+ /** A whole page longer than this, in CSS pixels, is cut off below it. */
1189
+ var MAX_FULL_PAGE_HEIGHT = 4000;
1190
+ var JPEG_QUALITY = 0.85;
1191
+ /** How long an image or a font on the page is waited for. */
1192
+ var LOAD_TIMEOUT_MS = 8000;
1193
+
1194
+ /**
1195
+ * The page in `win`, as it is now: what is on screen, or (`fullPage`) the
1196
+ * whole page from the top, cut off at {@link MAX_FULL_PAGE_HEIGHT}. Elements
1197
+ * `exclude` says are not the page's -- the picker's highlight -- are left
1198
+ * out.
1199
+ */
1200
+ function screenshotPage(_x) {
1201
+ return _screenshotPage.apply(this, arguments);
1202
+ }
1203
+
1204
+ /** What the page is drawn on: the body's background, else the root's, else white. */
1205
+ function _screenshotPage() {
1206
+ _screenshotPage = createForOfIteratorHelper._asyncToGenerator(/*#__PURE__*/createForOfIteratorHelper._regenerator().m(function _callee(win) {
1207
+ var _doc$body$scrollHeigh, _doc$body;
1208
+ var options,
1209
+ _yield$import,
1210
+ domToCanvas,
1211
+ doc,
1212
+ root,
1213
+ fullPage,
1214
+ pageWidth,
1215
+ pageHeight,
1216
+ top,
1217
+ height,
1218
+ exclude,
1219
+ drawn,
1220
+ scale,
1221
+ out,
1222
+ context,
1223
+ _args = arguments;
1224
+ return createForOfIteratorHelper._regenerator().w(function (_context) {
1225
+ while (1) switch (_context.n) {
1226
+ case 0:
1227
+ options = _args.length > 1 && _args[1] !== undefined ? _args[1] : {};
1228
+ _context.n = 1;
1229
+ return Promise.resolve().then(function () { return /*#__PURE__*/_interopNamespace(require('modern-screenshot')); });
1230
+ case 1:
1231
+ _yield$import = _context.v;
1232
+ domToCanvas = _yield$import.domToCanvas;
1233
+ doc = win.document;
1234
+ root = doc.documentElement;
1235
+ fullPage = options.fullPage === true;
1236
+ pageWidth = root.clientWidth || win.innerWidth;
1237
+ pageHeight = Math.max(root.scrollHeight, (_doc$body$scrollHeigh = (_doc$body = doc.body) === null || _doc$body === void 0 ? void 0 : _doc$body.scrollHeight) !== null && _doc$body$scrollHeigh !== void 0 ? _doc$body$scrollHeigh : 0);
1238
+ top = fullPage ? 0 : win.scrollY;
1239
+ height = fullPage ? Math.min(pageHeight, MAX_FULL_PAGE_HEIGHT) : Math.min(win.innerHeight, pageHeight - top);
1240
+ exclude = options.exclude; // Drawn to the bottom of what is wanted, and no further: the cost is the
1241
+ // page's size, so a viewport near the top is cheap.
1242
+ _context.n = 2;
1243
+ return domToCanvas(root, createForOfIteratorHelper._objectSpread2({
1244
+ width: pageWidth,
1245
+ height: top + height,
1246
+ scale: 1,
1247
+ backgroundColor: pageBackground(win),
1248
+ timeout: LOAD_TIMEOUT_MS
1249
+ }, exclude !== undefined ? {
1250
+ filter: function filter(node) {
1251
+ return !(isElement(node) && exclude(node));
1252
+ }
1253
+ } : {}));
1254
+ case 2:
1255
+ drawn = _context.v;
1256
+ scale = Math.min(1, MAX_WIDTH / pageWidth);
1257
+ out = doc.createElement("canvas");
1258
+ out.width = Math.round(pageWidth * scale);
1259
+ out.height = Math.round(height * scale);
1260
+ context = out.getContext("2d");
1261
+ if (!(context === null)) {
1262
+ _context.n = 3;
1263
+ break;
1264
+ }
1265
+ throw new Error("This browser would not draw the picture.");
1266
+ case 3:
1267
+ context.drawImage(drawn, 0, top, pageWidth, height, 0, 0, out.width, out.height);
1268
+ return _context.a(2, {
1269
+ dataUrl: out.toDataURL("image/jpeg", JPEG_QUALITY),
1270
+ width: out.width,
1271
+ height: out.height,
1272
+ fullPage: fullPage,
1273
+ clipped: top + height < pageHeight
1274
+ });
1275
+ }
1276
+ }, _callee);
1277
+ }));
1278
+ return _screenshotPage.apply(this, arguments);
1279
+ }
1280
+ function pageBackground(win) {
1281
+ for (var _i = 0, _arr = [win.document.body, win.document.documentElement]; _i < _arr.length; _i++) {
1282
+ var element = _arr[_i];
1283
+ if (element === null) continue;
1284
+ var color = win.getComputedStyle(element).backgroundColor;
1285
+ if (color && color !== "transparent" && color !== "rgba(0, 0, 0, 0)") {
1286
+ return color;
1287
+ }
1288
+ }
1289
+ return "#ffffff";
1290
+ }
1291
+ function isElement(node) {
1292
+ return node.nodeType === 1;
1293
+ }
1294
+
1142
1295
  function parseRoutePattern(pattern) {
1143
1296
  if (pattern === "" || pattern === "/") {
1144
1297
  return [];
@@ -1414,6 +1567,7 @@ exports.parseRoutePattern = parseRoutePattern;
1414
1567
  exports.quickPreviewSiteOrigin = quickPreviewSiteOrigin;
1415
1568
  exports.readPageSnapshot = readPageSnapshot;
1416
1569
  exports.restoreScroll = restoreScroll;
1570
+ exports.screenshotPage = screenshotPage;
1417
1571
  exports.startElementPicking = startElementPicking;
1418
1572
  exports.storeQuickPreview = storeQuickPreview;
1419
1573
  exports.watchPageLocation = watchPageLocation;
@@ -7,7 +7,7 @@ var core = require('@valbuild/core');
7
7
  var zod = require('zod');
8
8
  var protocol = require('../../dist/protocol-d0efb8cd.cjs.dev.js');
9
9
  var zodValidationError = require('zod-validation-error');
10
- var getSitemapTree = require('../../dist/getSitemapTree-d934ff9c.cjs.dev.js');
10
+ var getSitemapTree = require('../../dist/getSitemapTree-98642b57.cjs.dev.js');
11
11
  var FlexSearch = require('flexsearch');
12
12
  var wrapNativeSuper = require('../../dist/wrapNativeSuper-933f991e.cjs.dev.js');
13
13
  var utils = require('../../dist/utils-d3d8b4b5.cjs.dev.js');
@@ -8785,6 +8785,7 @@ exports.parseRoutePattern = getSitemapTree.parseRoutePattern;
8785
8785
  exports.quickPreviewSiteOrigin = getSitemapTree.quickPreviewSiteOrigin;
8786
8786
  exports.readPageSnapshot = getSitemapTree.readPageSnapshot;
8787
8787
  exports.restoreScroll = getSitemapTree.restoreScroll;
8788
+ exports.screenshotPage = getSitemapTree.screenshotPage;
8788
8789
  exports.startElementPicking = getSitemapTree.startElementPicking;
8789
8790
  exports.storeQuickPreview = getSitemapTree.storeQuickPreview;
8790
8791
  exports.watchPageLocation = getSitemapTree.watchPageLocation;
@@ -7,7 +7,7 @@ var core = require('@valbuild/core');
7
7
  var zod = require('zod');
8
8
  var protocol = require('../../dist/protocol-b1055ef0.cjs.prod.js');
9
9
  var zodValidationError = require('zod-validation-error');
10
- var getSitemapTree = require('../../dist/getSitemapTree-5354ce90.cjs.prod.js');
10
+ var getSitemapTree = require('../../dist/getSitemapTree-97713490.cjs.prod.js');
11
11
  var FlexSearch = require('flexsearch');
12
12
  var wrapNativeSuper = require('../../dist/wrapNativeSuper-8673414f.cjs.prod.js');
13
13
  var utils = require('../../dist/utils-32bcaca2.cjs.prod.js');
@@ -8785,6 +8785,7 @@ exports.parseRoutePattern = getSitemapTree.parseRoutePattern;
8785
8785
  exports.quickPreviewSiteOrigin = getSitemapTree.quickPreviewSiteOrigin;
8786
8786
  exports.readPageSnapshot = getSitemapTree.readPageSnapshot;
8787
8787
  exports.restoreScroll = getSitemapTree.restoreScroll;
8788
+ exports.screenshotPage = getSitemapTree.screenshotPage;
8788
8789
  exports.startElementPicking = getSitemapTree.startElementPicking;
8789
8790
  exports.storeQuickPreview = getSitemapTree.storeQuickPreview;
8790
8791
  exports.watchPageLocation = getSitemapTree.watchPageLocation;
@@ -4,7 +4,7 @@ import { z } from 'zod';
4
4
  import { _ as _objectWithoutProperties } from '../../dist/protocol-55cfa3cf.esm.js';
5
5
  export { P as PublishProtocolError, b as parseArtifacts, p as parseBuildTarget, l as parseCancel, a as parseDeclare, m as parseDiscard, j as parseJob, n as parseNewestCiRun, h as parsePress, g as parseProblems, f as parseProjectSource, d as parsePromote, o as parsePublishToken, k as parseRenew, i as parseRequestStatus, e as parseStatus, q as parseUpdateTarget, c as parseVerify } from '../../dist/protocol-55cfa3cf.esm.js';
6
6
  import { fromError } from 'zod-validation-error';
7
- export { D as DEFAULT_CANVAS_SELECTION, e as DEFAULT_CANVAS_SELECTION_SOFT, Q as QUICK_PREVIEW_PARAM, t as QUICK_PREVIEW_SERVICE_WORKER_PATH, x as QUICK_PREVIEW_SERVICE_WORKER_SOURCE, u as QUICK_PREVIEW_STORE_MESSAGE, b as VAL_AI_SESSION_STORAGE_KEY, d as VAL_CANVAS_MESSAGE, c as VAL_CANVAS_PARAM, V as VAL_CONFIG_SESSION_STORAGE_KEY, a as VAL_THEME_SESSION_STORAGE_KEY, j as attachElementPicker, k as createPickerOverlay, h as describeElement, l as elementLabel, q as findBySelector, E as formatRoutePattern, F as getNextAppRouterSourceFolder, J as getPageRouterSitemapTree, H as getPageRouterSourceFolder, K as getPatternFromModuleFilePath, G as getTanStackRouterSourceFolder, B as isDesignTabOrigin, v as isQuickPreviewFiles, I as isTanStackRoutesFolder, g as isValCanvasFrame, i as isValCanvasPageMessage, f as isValCanvasStudioMessage, m as modifierLabel, p as pageLocationOf, C as parseRoutePattern, A as quickPreviewSiteOrigin, o as readPageSnapshot, r as restoreScroll, s as startElementPicking, y as storeQuickPreview, n as watchPageLocation, z as withQuickPreviewParam, w as withValCanvasParam } from '../../dist/getSitemapTree-97b3166f.esm.js';
7
+ export { D as DEFAULT_CANVAS_SELECTION, e as DEFAULT_CANVAS_SELECTION_SOFT, Q as QUICK_PREVIEW_PARAM, u as QUICK_PREVIEW_SERVICE_WORKER_PATH, y as QUICK_PREVIEW_SERVICE_WORKER_SOURCE, v as QUICK_PREVIEW_STORE_MESSAGE, b as VAL_AI_SESSION_STORAGE_KEY, d as VAL_CANVAS_MESSAGE, c as VAL_CANVAS_PARAM, V as VAL_CONFIG_SESSION_STORAGE_KEY, a as VAL_THEME_SESSION_STORAGE_KEY, j as attachElementPicker, k as createPickerOverlay, h as describeElement, l as elementLabel, q as findBySelector, F as formatRoutePattern, G as getNextAppRouterSourceFolder, K as getPageRouterSitemapTree, I as getPageRouterSourceFolder, L as getPatternFromModuleFilePath, H as getTanStackRouterSourceFolder, C as isDesignTabOrigin, x as isQuickPreviewFiles, J as isTanStackRoutesFolder, g as isValCanvasFrame, i as isValCanvasPageMessage, f as isValCanvasStudioMessage, m as modifierLabel, p as pageLocationOf, E as parseRoutePattern, B as quickPreviewSiteOrigin, o as readPageSnapshot, r as restoreScroll, t as screenshotPage, s as startElementPicking, z as storeQuickPreview, n as watchPageLocation, A as withQuickPreviewParam, w as withValCanvasParam } from '../../dist/getSitemapTree-7c848c94.esm.js';
8
8
  import FlexSearch from 'flexsearch';
9
9
  import { a as _createClass, c as _classCallCheck } from '../../dist/wrapNativeSuper-639b12b7.esm.js';
10
10
  import { b as base64DataUrlToUint8Array } from '../../dist/utils-00f3e1df.esm.js';
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@valbuild/shared",
3
- "version": "0.150.12",
3
+ "version": "0.150.13",
4
4
  "private": false,
5
5
  "description": "Val shared types and utilities",
6
6
  "repository": {
@@ -50,6 +50,7 @@
50
50
  },
51
51
  "dependencies": {
52
52
  "flexsearch": "^0.8.212",
53
+ "modern-screenshot": "^4.7.0",
53
54
  "yaml": "^2.9.0",
54
55
  "zod": "^4.4.3",
55
56
  "zod-validation-error": "^5.0.0",