@snowcone-app/sdk 0.31.2 → 0.31.5

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/CHANGELOG.md CHANGED
@@ -1,5 +1,23 @@
1
1
  # Changelog
2
2
 
3
+ ## 0.31.5
4
+
5
+ ### Patch Changes
6
+
7
+ - [#5693](https://github.com/snowcone-app/snowcone-monorepo/pull/5693) [`23dee39`](https://github.com/snowcone-app/snowcone-monorepo/commit/23dee39f7dbc3d2f922ac8dd308f8ec93facc94c) Thanks [@kevinsproles](https://github.com/kevinsproles)! - Export `MOCKUP_VIEW_WHOLE_STRIP` (`"2.7@0.25"`): the `view=` value for a plate's whole 8:3 strip at its own pixels, for a window wider than 2.6 (where `mockupViewFor` returns null).
8
+
9
+ ## 0.31.4
10
+
11
+ ### Patch Changes
12
+
13
+ - [#5688](https://github.com/snowcone-app/snowcone-monorepo/pull/5688) [`cec468f`](https://github.com/snowcone-app/snowcone-monorepo/commit/cec468fc5799297a192a5183edbf1a6b460c6d56) Thanks [@kevinsproles](https://github.com/kevinsproles)! - `getMockupUrl`'s `stripView` doc: a `width` beside it is a downscale (the crop is never enlarged), as the grammar accepts since #5684.
14
+
15
+ ## 0.31.3
16
+
17
+ ### Patch Changes
18
+
19
+ - [#5682](https://github.com/snowcone-app/snowcone-monorepo/pull/5682) [`5fda4b9`](https://github.com/snowcone-app/snowcone-monorepo/commit/5fda4b9c7fbb226c1bd61024cf01c38ac31bddeb) Thanks [@kevinsproles](https://github.com/kevinsproles)! - The editor's live preview is cropped like the product page's hero. SDK: the realtime config takes `views: { <mockupId>: MockupView }` (that mockup's live frame is `aspect=8:3&view=<v>`, the hero's crop); `sendConfig` sends only the views of the config's own `mockupIds` and throws before sending what the box refuses (`E_VIEW_PARAM_INVALID` off the grid, `E_REALTIME_VIEWS_WITH_CROP_RECT` beside an overlayCrop rect); `sessionViews` is exported. UI: `RealtimeProvider` gets `setMockupViews(views)` (carried on every config it sends; a change re-sends the config and re-seeds the cropped-delivery backgrounds) and `frameViewOf(url)` (which crop a frame it handed out is).
20
+
3
21
  ## 0.31.2
4
22
 
5
23
  ### Patch Changes
@@ -54,7 +54,8 @@ var PARAMS = {
54
54
  aspect: "aspect",
55
55
  /**
56
56
  * `view=<r>@<f>`: a crop of a plate's 8:3 strip, for a page hero that shows only part of it ({@link canonicalMockupView}).
57
- * Goes with `aspect=8:3` only and never with `width=`: the crop is delivered at its own pixels.
57
+ * Goes with `aspect=8:3` only. Without `width=` the crop is delivered at its own pixels; with `width=` at that width when
58
+ * smaller (the box only ever downscales: a page asks crop width x DPR, capped at the crop).
58
59
  */
59
60
  view: "view",
60
61
  /**
@@ -79,20 +80,22 @@ var PARAMS = {
79
80
  };
80
81
  var BG_TRANSPARENT = "transparent";
81
82
  var viewGrid = (from, to, step) => Array.from({ length: Math.round((to - from) / step) + 1 }, (_, i) => Math.round((from + i * step) * 1e3) / 1e3);
82
- var MOCKUP_VIEW_SHAPES = viewGrid(1.3, 2.6, 0.1);
83
+ var MOCKUP_VIEW_SHAPES = viewGrid(1.3, 2.7, 0.1);
84
+ var MOCKUP_VIEW_WHOLE_STRIP = "2.7@0.25";
83
85
  var MOCKUP_VIEW_PLACES = [...viewGrid(0.25, 0.475, 0.025), ...viewGrid(0.525, 0.75, 0.025)];
84
86
  function canonicalMockupView(raw) {
85
87
  const m = /^\s*(\d+(?:\.\d+)?)@(\d+(?:\.\d+)?)\s*$/.exec(String(raw));
86
88
  if (!m) return null;
87
89
  const r = MOCKUP_VIEW_SHAPES.find((x) => Math.abs(x - Number(m[1])) < 1e-9);
88
90
  const f = MOCKUP_VIEW_PLACES.find((x) => Math.abs(x - Number(m[2])) < 1e-9);
89
- return r === void 0 || f === void 0 ? null : `${r.toFixed(1)}@${String(f)}`;
91
+ if (r === void 0 || f === void 0) return null;
92
+ return r === 2.7 ? MOCKUP_VIEW_WHOLE_STRIP : `${r.toFixed(1)}@${String(f)}`;
90
93
  }
91
94
  function mockupViewFor(windowWidth, windowHeight, productCentreX) {
92
95
  if (!(windowWidth > 0 && windowHeight > 0)) return null;
93
96
  const rawR = windowWidth / windowHeight;
94
97
  const r = MOCKUP_VIEW_SHAPES.find((x) => x >= rawR - 1e-9);
95
- if (r === void 0) return null;
98
+ if (r === void 0 || r === 2.7) return null;
96
99
  const rawF = productCentreX / windowWidth;
97
100
  const f = MOCKUP_VIEW_PLACES.reduce((best, x) => Math.abs(x - rawF) < Math.abs(best - rawF) ? x : best, MOCKUP_VIEW_PLACES[0]);
98
101
  return `${r.toFixed(1)}@${String(f)}`;
@@ -101,7 +104,8 @@ function requireMockupView(view, ctx) {
101
104
  const v = canonicalMockupView(view);
102
105
  if (!v) throw new Error(`[snowcone] E_VIEW_PARAM_INVALID: view "${view}" is not on the grid: <r>@<f>, r one of ${MOCKUP_VIEW_SHAPES.join(", ")} and f one of ${MOCKUP_VIEW_PLACES.join(", ")} (mockupViewFor computes it); a scene is mockup=<sceneId>, not view`);
103
106
  if (ctx.aspect !== "8:3") throw new Error(`[snowcone] E_VIEW_PARAM_INVALID: view is a crop of a plate's 8:3 strip and goes with aspect "8:3" only (got ${ctx.aspect === void 0 ? "no aspect" : `"${ctx.aspect}"`})`);
104
- if (ctx.width !== void 0 || ctx.preset !== void 0) throw new Error(`[snowcone] E_VIEW_PARAM_INVALID: view takes no width or preset: the crop is delivered at its own pixels; drop ${ctx.width !== void 0 ? "width" : "preset"}`);
107
+ if (ctx.preset !== void 0) throw new Error(`[snowcone] E_VIEW_PARAM_INVALID: view takes no preset (a preset sets its own aspect); drop preset`);
108
+ if (ctx.width !== void 0 && !(Number.isFinite(ctx.width) && ctx.width > 0)) throw new Error(`[snowcone] E_VIEW_PARAM_INVALID: width ${ctx.width} beside view must be a positive number of px (or omit it: the crop's own px)`);
105
109
  return v;
106
110
  }
107
111
  var MOCKUP_PRESETS = {
@@ -218,7 +222,7 @@ function buildMockupUrl(options, cfg) {
218
222
  }
219
223
  }
220
224
  const view = options.view !== void 0 ? requireMockupView(options.view, { aspect: options.aspect, width: options.width }) : void 0;
221
- const width = view ? void 0 : normalizeWidth(options.width);
225
+ const width = view ? options.width !== void 0 ? normalizeWidth(options.width) : void 0 : normalizeWidth(options.width);
222
226
  const base = cfg.mockupBaseUrl.replace(/\/+$/, "");
223
227
  const path = `/${encodeURIComponent(options.productId)}`;
224
228
  let queryString = `${PARAMS.shop}=${encodeURIComponent(cfg.shop)}`;
@@ -407,6 +411,7 @@ export {
407
411
  SNOWCONE_HOSTS,
408
412
  SNOWCONE_REALTIME_WS_URL,
409
413
  MOCKUP_VIEW_SHAPES,
414
+ MOCKUP_VIEW_WHOLE_STRIP,
410
415
  MOCKUP_VIEW_PLACES,
411
416
  canonicalMockupView,
412
417
  mockupViewFor,
@@ -1,11 +1,32 @@
1
1
  import {
2
- SNOWCONE_REALTIME_WS_URL
3
- } from "./chunk-WPVMN73Y.js";
2
+ SNOWCONE_REALTIME_WS_URL,
3
+ canonicalMockupView
4
+ } from "./chunk-KCOLSFYH.js";
4
5
 
5
6
  // src/realtime/constants.ts
6
7
  var REALTIME_WS_URL = SNOWCONE_REALTIME_WS_URL;
7
8
 
8
9
  // src/realtime/websocket.ts
10
+ function sessionViews(config) {
11
+ const raw = config.views;
12
+ if (raw === void 0) return void 0;
13
+ if (config.overlayCrop !== void 0 && config.overlayCrop !== "auto") {
14
+ throw new Error(
15
+ "[snowcone] E_REALTIME_VIEWS_WITH_CROP_RECT: a config with views takes no overlayCrop rect (a view IS the crop); send overlayCrop 'auto' (the print area inside the view) or none"
16
+ );
17
+ }
18
+ const out = {};
19
+ for (const [mockupId, v] of Object.entries(raw)) {
20
+ const canonical = canonicalMockupView(String(v));
21
+ if (!canonical) {
22
+ throw new Error(
23
+ `[snowcone] E_VIEW_PARAM_INVALID: views[${mockupId}] = ${JSON.stringify(v)} is not on the view grid <r>@<f> (compute it with mockupViewFor from @snowcone-app/sdk)`
24
+ );
25
+ }
26
+ if (config.mockupIds.includes(mockupId)) out[mockupId] = canonical;
27
+ }
28
+ return Object.keys(out).length ? out : void 0;
29
+ }
9
30
  function pruneUndefined(obj) {
10
31
  const out = {};
11
32
  for (const [k, v] of Object.entries(obj)) {
@@ -486,6 +507,7 @@ var RealtimeMockupService = class {
486
507
  data.imageUrl = frame.objectUrl;
487
508
  }
488
509
  sendConfig(config) {
510
+ const views = sessionViews(config);
489
511
  if (!this.ws || this.ws.readyState !== WebSocket.OPEN) {
490
512
  this.addLog("WebSocket not connected, caching config");
491
513
  this.config = config;
@@ -535,7 +557,8 @@ var RealtimeMockupService = class {
535
557
  // socket (mockup_frame binary messages) instead of making us fetch the
536
558
  // imageUrl — saves a network round trip per render. Servers that don't
537
559
  // know the flag ignore it and we fall back to the URL.
538
- config: { ...config, binaryFrames: true }
560
+ // views go out pruned to this config's mockupIds (undefined = the key is dropped by JSON).
561
+ config: { ...config, views, binaryFrames: true }
539
562
  };
540
563
  const messageStr = JSON.stringify(message);
541
564
  this.addLog(`\u{1F4E4} Sending config: ${JSON.stringify(message, null, 2)}`, "sent");
@@ -995,5 +1018,6 @@ ${versionToSend}
995
1018
 
996
1019
  export {
997
1020
  REALTIME_WS_URL,
1021
+ sessionViews,
998
1022
  RealtimeMockupService
999
1023
  };
package/dist/index.cjs CHANGED
@@ -51,6 +51,7 @@ __export(src_exports, {
51
51
  LitAdapter: () => LitAdapter,
52
52
  MOCKUP_VIEW_PLACES: () => MOCKUP_VIEW_PLACES,
53
53
  MOCKUP_VIEW_SHAPES: () => MOCKUP_VIEW_SHAPES,
54
+ MOCKUP_VIEW_WHOLE_STRIP: () => MOCKUP_VIEW_WHOLE_STRIP,
54
55
  PDP_GALLERY_LIMIT: () => PDP_GALLERY_LIMIT,
55
56
  ProductContextManager: () => ProductContextManager,
56
57
  ProductLoader: () => ProductLoader,
@@ -156,6 +157,7 @@ __export(src_exports, {
156
157
  resolveVariantId: () => resolveVariantId,
157
158
  retryOperation: () => retryOperation,
158
159
  searchDesigns: () => searchDesigns,
160
+ sessionViews: () => sessionViews,
159
161
  simulateCartOperation: () => simulateCartOperation,
160
162
  toCombinations: () => toCombinations,
161
163
  toOptionAttributes: () => toOptionAttributes,
@@ -322,7 +324,8 @@ var PARAMS = {
322
324
  aspect: "aspect",
323
325
  /**
324
326
  * `view=<r>@<f>`: a crop of a plate's 8:3 strip, for a page hero that shows only part of it ({@link canonicalMockupView}).
325
- * Goes with `aspect=8:3` only and never with `width=`: the crop is delivered at its own pixels.
327
+ * Goes with `aspect=8:3` only. Without `width=` the crop is delivered at its own pixels; with `width=` at that width when
328
+ * smaller (the box only ever downscales: a page asks crop width x DPR, capped at the crop).
326
329
  */
327
330
  view: "view",
328
331
  /**
@@ -347,20 +350,22 @@ var PARAMS = {
347
350
  };
348
351
  var BG_TRANSPARENT = "transparent";
349
352
  var viewGrid = (from, to, step) => Array.from({ length: Math.round((to - from) / step) + 1 }, (_, i) => Math.round((from + i * step) * 1e3) / 1e3);
350
- var MOCKUP_VIEW_SHAPES = viewGrid(1.3, 2.6, 0.1);
353
+ var MOCKUP_VIEW_SHAPES = viewGrid(1.3, 2.7, 0.1);
354
+ var MOCKUP_VIEW_WHOLE_STRIP = "2.7@0.25";
351
355
  var MOCKUP_VIEW_PLACES = [...viewGrid(0.25, 0.475, 0.025), ...viewGrid(0.525, 0.75, 0.025)];
352
356
  function canonicalMockupView(raw) {
353
357
  const m = /^\s*(\d+(?:\.\d+)?)@(\d+(?:\.\d+)?)\s*$/.exec(String(raw));
354
358
  if (!m) return null;
355
359
  const r = MOCKUP_VIEW_SHAPES.find((x) => Math.abs(x - Number(m[1])) < 1e-9);
356
360
  const f = MOCKUP_VIEW_PLACES.find((x) => Math.abs(x - Number(m[2])) < 1e-9);
357
- return r === void 0 || f === void 0 ? null : `${r.toFixed(1)}@${String(f)}`;
361
+ if (r === void 0 || f === void 0) return null;
362
+ return r === 2.7 ? MOCKUP_VIEW_WHOLE_STRIP : `${r.toFixed(1)}@${String(f)}`;
358
363
  }
359
364
  function mockupViewFor(windowWidth, windowHeight, productCentreX) {
360
365
  if (!(windowWidth > 0 && windowHeight > 0)) return null;
361
366
  const rawR = windowWidth / windowHeight;
362
367
  const r = MOCKUP_VIEW_SHAPES.find((x) => x >= rawR - 1e-9);
363
- if (r === void 0) return null;
368
+ if (r === void 0 || r === 2.7) return null;
364
369
  const rawF = productCentreX / windowWidth;
365
370
  const f = MOCKUP_VIEW_PLACES.reduce((best, x) => Math.abs(x - rawF) < Math.abs(best - rawF) ? x : best, MOCKUP_VIEW_PLACES[0]);
366
371
  return `${r.toFixed(1)}@${String(f)}`;
@@ -369,7 +374,8 @@ function requireMockupView(view, ctx) {
369
374
  const v = canonicalMockupView(view);
370
375
  if (!v) throw new Error(`[snowcone] E_VIEW_PARAM_INVALID: view "${view}" is not on the grid: <r>@<f>, r one of ${MOCKUP_VIEW_SHAPES.join(", ")} and f one of ${MOCKUP_VIEW_PLACES.join(", ")} (mockupViewFor computes it); a scene is mockup=<sceneId>, not view`);
371
376
  if (ctx.aspect !== "8:3") throw new Error(`[snowcone] E_VIEW_PARAM_INVALID: view is a crop of a plate's 8:3 strip and goes with aspect "8:3" only (got ${ctx.aspect === void 0 ? "no aspect" : `"${ctx.aspect}"`})`);
372
- if (ctx.width !== void 0 || ctx.preset !== void 0) throw new Error(`[snowcone] E_VIEW_PARAM_INVALID: view takes no width or preset: the crop is delivered at its own pixels; drop ${ctx.width !== void 0 ? "width" : "preset"}`);
377
+ if (ctx.preset !== void 0) throw new Error(`[snowcone] E_VIEW_PARAM_INVALID: view takes no preset (a preset sets its own aspect); drop preset`);
378
+ if (ctx.width !== void 0 && !(Number.isFinite(ctx.width) && ctx.width > 0)) throw new Error(`[snowcone] E_VIEW_PARAM_INVALID: width ${ctx.width} beside view must be a positive number of px (or omit it: the crop's own px)`);
373
379
  return v;
374
380
  }
375
381
  var MOCKUP_PRESETS = {
@@ -486,7 +492,7 @@ function buildMockupUrl(options, cfg) {
486
492
  }
487
493
  }
488
494
  const view = options.view !== void 0 ? requireMockupView(options.view, { aspect: options.aspect, width: options.width }) : void 0;
489
- const width = view ? void 0 : normalizeWidth(options.width);
495
+ const width = view ? options.width !== void 0 ? normalizeWidth(options.width) : void 0 : normalizeWidth(options.width);
490
496
  const base = cfg.mockupBaseUrl.replace(/\/+$/, "");
491
497
  const path = `/${encodeURIComponent(options.productId)}`;
492
498
  let queryString = `${PARAMS.shop}=${encodeURIComponent(cfg.shop)}`;
@@ -5199,6 +5205,26 @@ function createSvelteComponent(descriptor, svelte) {
5199
5205
  var REALTIME_WS_URL = SNOWCONE_REALTIME_WS_URL;
5200
5206
 
5201
5207
  // src/realtime/websocket.ts
5208
+ function sessionViews(config) {
5209
+ const raw = config.views;
5210
+ if (raw === void 0) return void 0;
5211
+ if (config.overlayCrop !== void 0 && config.overlayCrop !== "auto") {
5212
+ throw new Error(
5213
+ "[snowcone] E_REALTIME_VIEWS_WITH_CROP_RECT: a config with views takes no overlayCrop rect (a view IS the crop); send overlayCrop 'auto' (the print area inside the view) or none"
5214
+ );
5215
+ }
5216
+ const out = {};
5217
+ for (const [mockupId, v] of Object.entries(raw)) {
5218
+ const canonical = canonicalMockupView(String(v));
5219
+ if (!canonical) {
5220
+ throw new Error(
5221
+ `[snowcone] E_VIEW_PARAM_INVALID: views[${mockupId}] = ${JSON.stringify(v)} is not on the view grid <r>@<f> (compute it with mockupViewFor from @snowcone-app/sdk)`
5222
+ );
5223
+ }
5224
+ if (config.mockupIds.includes(mockupId)) out[mockupId] = canonical;
5225
+ }
5226
+ return Object.keys(out).length ? out : void 0;
5227
+ }
5202
5228
  function pruneUndefined(obj) {
5203
5229
  const out = {};
5204
5230
  for (const [k, v] of Object.entries(obj)) {
@@ -5679,6 +5705,7 @@ var RealtimeMockupService = class {
5679
5705
  data.imageUrl = frame.objectUrl;
5680
5706
  }
5681
5707
  sendConfig(config) {
5708
+ const views = sessionViews(config);
5682
5709
  if (!this.ws || this.ws.readyState !== WebSocket.OPEN) {
5683
5710
  this.addLog("WebSocket not connected, caching config");
5684
5711
  this.config = config;
@@ -5728,7 +5755,8 @@ var RealtimeMockupService = class {
5728
5755
  // socket (mockup_frame binary messages) instead of making us fetch the
5729
5756
  // imageUrl — saves a network round trip per render. Servers that don't
5730
5757
  // know the flag ignore it and we fall back to the URL.
5731
- config: { ...config, binaryFrames: true }
5758
+ // views go out pruned to this config's mockupIds (undefined = the key is dropped by JSON).
5759
+ config: { ...config, views, binaryFrames: true }
5732
5760
  };
5733
5761
  const messageStr = JSON.stringify(message);
5734
5762
  this.addLog(`\u{1F4E4} Sending config: ${JSON.stringify(message, null, 2)}`, "sent");
@@ -6801,6 +6829,7 @@ function createClient(config) {
6801
6829
  LitAdapter,
6802
6830
  MOCKUP_VIEW_PLACES,
6803
6831
  MOCKUP_VIEW_SHAPES,
6832
+ MOCKUP_VIEW_WHOLE_STRIP,
6804
6833
  PDP_GALLERY_LIMIT,
6805
6834
  ProductContextManager,
6806
6835
  ProductLoader,
@@ -6906,6 +6935,7 @@ function createClient(config) {
6906
6935
  resolveVariantId,
6907
6936
  retryOperation,
6908
6937
  searchDesigns,
6938
+ sessionViews,
6909
6939
  simulateCartOperation,
6910
6940
  toCombinations,
6911
6941
  toOptionAttributes,
package/dist/index.d.cts CHANGED
@@ -1,9 +1,9 @@
1
1
  export { createDevFetcher } from './dev-fetcher.cjs';
2
2
  import { PublicDesign, PublicFill, PublicOptions, MockupView, MockupAspect, MockupPreset } from '@snowcone-app/mockup-url';
3
- export { MOCKUP_VIEW_PLACES, MOCKUP_VIEW_SHAPES, MockupView, SNOWCONE_HOSTS, SNOWCONE_REALTIME_WS_URL, SnowconeHostRole, canonicalMockupView, mockupViewFor } from '@snowcone-app/mockup-url';
3
+ export { MOCKUP_VIEW_PLACES, MOCKUP_VIEW_SHAPES, MOCKUP_VIEW_WHOLE_STRIP, MockupView, SNOWCONE_HOSTS, SNOWCONE_REALTIME_WS_URL, SnowconeHostRole, canonicalMockupView, mockupViewFor } from '@snowcone-app/mockup-url';
4
4
  export { GalleryReason, GalleryStanding, MockupRole, OrdinaryMockups, PDP_GALLERY_LIMIT, SIZE_PICTURE, gallerySizePicture, galleryStanding, mockupRole, ordinaryMockups, pictureForVariant, primaryMockup } from './mockup-role.cjs';
5
- import { O as OptionAttribute, a as OptionSelection, C as Combination, F as FrameworkAdapter, b as ComponentProps, c as ComponentDescriptor, d as ComponentState, e as ComponentContext, f as ComponentLifecycleHooks, E as EventHandler, g as FrameworkUtilities, P as PlacementSettings, M as MockupResult, R as RealtimeRenderError, h as RealtimeMockupService } from './websocket-CvN0UU2j.cjs';
6
- export { A as AdapterRegistry, i as ProductComponentContext, j as RealtimeMockupCallbacks, k as RealtimeMockupState, l as RenderResult, W as WebSocketConfig, m as WebSocketMessage, n as adapterRegistry, o as computeDisabledChoices, p as createComponent, q as defineComponent, r as deriveDefaultSelection, s as findBestCombination, t as getPricePreview, u as isOptionAvailable, v as resolveBestCombination } from './websocket-CvN0UU2j.cjs';
5
+ import { O as OptionAttribute, a as OptionSelection, C as Combination, F as FrameworkAdapter, b as ComponentProps, c as ComponentDescriptor, d as ComponentState, e as ComponentContext, f as ComponentLifecycleHooks, E as EventHandler, g as FrameworkUtilities, P as PlacementSettings, M as MockupResult, R as RealtimeRenderError, h as RealtimeMockupService } from './websocket-CSJT_g8j.cjs';
6
+ export { A as AdapterRegistry, i as ProductComponentContext, j as RealtimeMockupCallbacks, k as RealtimeMockupState, l as RenderResult, W as WebSocketConfig, m as WebSocketMessage, n as adapterRegistry, o as computeDisabledChoices, p as createComponent, q as defineComponent, r as deriveDefaultSelection, s as findBestCombination, t as getPricePreview, u as isOptionAvailable, v as resolveBestCombination, w as sessionViews } from './websocket-CSJT_g8j.cjs';
7
7
 
8
8
  interface CatalogProduct {
9
9
  id: string;
@@ -389,8 +389,9 @@ interface GetMockupUrlOptions {
389
389
  view?: string;
390
390
  /**
391
391
  * A crop of a plate's 8:3 strip, emitted as `view=<r>@<f>` ({@link mockupViewFor} computes it from the window the page
392
- * shows): for a page hero that shows only part of the strip. Needs `aspect: "8:3"`; refuses `width` and `preset` (the
393
- * crop is delivered at its own pixels). Only mockups whose catalog entry carries `strip` answer it.
392
+ * shows): for a page hero that shows only part of the strip. Needs `aspect: "8:3"`; refuses `preset`. Without `width`
393
+ * the crop comes at its own pixels; a `width` is a downscale (ask the crop's CSS width x devicePixelRatio, capped at the
394
+ * crop: the box never enlarges). Only mockups whose catalog entry carries `strip` answer it.
394
395
  */
395
396
  stripView?: MockupView;
396
397
  /** Specific mockup scene/angle override. Alias of {@link GetMockupUrlOptions.view}. */
package/dist/index.d.ts CHANGED
@@ -1,9 +1,9 @@
1
1
  export { createDevFetcher } from './dev-fetcher.js';
2
2
  import { PublicDesign, PublicFill, PublicOptions, MockupView, MockupAspect, MockupPreset } from '@snowcone-app/mockup-url';
3
- export { MOCKUP_VIEW_PLACES, MOCKUP_VIEW_SHAPES, MockupView, SNOWCONE_HOSTS, SNOWCONE_REALTIME_WS_URL, SnowconeHostRole, canonicalMockupView, mockupViewFor } from '@snowcone-app/mockup-url';
3
+ export { MOCKUP_VIEW_PLACES, MOCKUP_VIEW_SHAPES, MOCKUP_VIEW_WHOLE_STRIP, MockupView, SNOWCONE_HOSTS, SNOWCONE_REALTIME_WS_URL, SnowconeHostRole, canonicalMockupView, mockupViewFor } from '@snowcone-app/mockup-url';
4
4
  export { GalleryReason, GalleryStanding, MockupRole, OrdinaryMockups, PDP_GALLERY_LIMIT, SIZE_PICTURE, gallerySizePicture, galleryStanding, mockupRole, ordinaryMockups, pictureForVariant, primaryMockup } from './mockup-role.js';
5
- import { O as OptionAttribute, a as OptionSelection, C as Combination, F as FrameworkAdapter, b as ComponentProps, c as ComponentDescriptor, d as ComponentState, e as ComponentContext, f as ComponentLifecycleHooks, E as EventHandler, g as FrameworkUtilities, P as PlacementSettings, M as MockupResult, R as RealtimeRenderError, h as RealtimeMockupService } from './websocket-CvN0UU2j.js';
6
- export { A as AdapterRegistry, i as ProductComponentContext, j as RealtimeMockupCallbacks, k as RealtimeMockupState, l as RenderResult, W as WebSocketConfig, m as WebSocketMessage, n as adapterRegistry, o as computeDisabledChoices, p as createComponent, q as defineComponent, r as deriveDefaultSelection, s as findBestCombination, t as getPricePreview, u as isOptionAvailable, v as resolveBestCombination } from './websocket-CvN0UU2j.js';
5
+ import { O as OptionAttribute, a as OptionSelection, C as Combination, F as FrameworkAdapter, b as ComponentProps, c as ComponentDescriptor, d as ComponentState, e as ComponentContext, f as ComponentLifecycleHooks, E as EventHandler, g as FrameworkUtilities, P as PlacementSettings, M as MockupResult, R as RealtimeRenderError, h as RealtimeMockupService } from './websocket-CSJT_g8j.js';
6
+ export { A as AdapterRegistry, i as ProductComponentContext, j as RealtimeMockupCallbacks, k as RealtimeMockupState, l as RenderResult, W as WebSocketConfig, m as WebSocketMessage, n as adapterRegistry, o as computeDisabledChoices, p as createComponent, q as defineComponent, r as deriveDefaultSelection, s as findBestCombination, t as getPricePreview, u as isOptionAvailable, v as resolveBestCombination, w as sessionViews } from './websocket-CSJT_g8j.js';
7
7
 
8
8
  interface CatalogProduct {
9
9
  id: string;
@@ -389,8 +389,9 @@ interface GetMockupUrlOptions {
389
389
  view?: string;
390
390
  /**
391
391
  * A crop of a plate's 8:3 strip, emitted as `view=<r>@<f>` ({@link mockupViewFor} computes it from the window the page
392
- * shows): for a page hero that shows only part of the strip. Needs `aspect: "8:3"`; refuses `width` and `preset` (the
393
- * crop is delivered at its own pixels). Only mockups whose catalog entry carries `strip` answer it.
392
+ * shows): for a page hero that shows only part of the strip. Needs `aspect: "8:3"`; refuses `preset`. Without `width`
393
+ * the crop comes at its own pixels; a `width` is a downscale (ask the crop's CSS width x devicePixelRatio, capped at the
394
+ * crop: the box never enlarges). Only mockups whose catalog entry carries `strip` answer it.
394
395
  */
395
396
  stripView?: MockupView;
396
397
  /** Specific mockup scene/angle override. Alias of {@link GetMockupUrlOptions.view}. */
package/dist/index.js CHANGED
@@ -1,13 +1,15 @@
1
1
  import {
2
2
  REALTIME_WS_URL,
3
- RealtimeMockupService
4
- } from "./chunk-5LYS3YP5.js";
3
+ RealtimeMockupService,
4
+ sessionViews
5
+ } from "./chunk-N5WOD5X2.js";
5
6
  import {
6
7
  createDevFetcher
7
8
  } from "./chunk-7VO4EL2V.js";
8
9
  import {
9
10
  MOCKUP_VIEW_PLACES,
10
11
  MOCKUP_VIEW_SHAPES,
12
+ MOCKUP_VIEW_WHOLE_STRIP,
11
13
  SNOWCONE_HOSTS,
12
14
  SNOWCONE_REALTIME_WS_URL,
13
15
  buildMockupUrl,
@@ -17,7 +19,7 @@ import {
17
19
  mockupViewFor,
18
20
  normalizeDesignElements,
19
21
  normalizeWidth
20
- } from "./chunk-WPVMN73Y.js";
22
+ } from "./chunk-KCOLSFYH.js";
21
23
  import {
22
24
  PDP_GALLERY_LIMIT,
23
25
  SIZE_PICTURE,
@@ -5228,6 +5230,7 @@ export {
5228
5230
  LitAdapter,
5229
5231
  MOCKUP_VIEW_PLACES,
5230
5232
  MOCKUP_VIEW_SHAPES,
5233
+ MOCKUP_VIEW_WHOLE_STRIP,
5231
5234
  PDP_GALLERY_LIMIT,
5232
5235
  ProductContextManager,
5233
5236
  ProductLoader,
@@ -5333,6 +5336,7 @@ export {
5333
5336
  resolveVariantId,
5334
5337
  retryOperation,
5335
5338
  searchDesigns,
5339
+ sessionViews,
5336
5340
  simulateCartOperation,
5337
5341
  toCombinations,
5338
5342
  toOptionAttributes,
package/dist/react.cjs CHANGED
@@ -88,7 +88,8 @@ var PARAMS = {
88
88
  aspect: "aspect",
89
89
  /**
90
90
  * `view=<r>@<f>`: a crop of a plate's 8:3 strip, for a page hero that shows only part of it ({@link canonicalMockupView}).
91
- * Goes with `aspect=8:3` only and never with `width=`: the crop is delivered at its own pixels.
91
+ * Goes with `aspect=8:3` only. Without `width=` the crop is delivered at its own pixels; with `width=` at that width when
92
+ * smaller (the box only ever downscales: a page asks crop width x DPR, capped at the crop).
92
93
  */
93
94
  view: "view",
94
95
  /**
@@ -112,8 +113,17 @@ var PARAMS = {
112
113
  seal: "seal"
113
114
  };
114
115
  var viewGrid = (from, to, step) => Array.from({ length: Math.round((to - from) / step) + 1 }, (_, i) => Math.round((from + i * step) * 1e3) / 1e3);
115
- var MOCKUP_VIEW_SHAPES = viewGrid(1.3, 2.6, 0.1);
116
+ var MOCKUP_VIEW_SHAPES = viewGrid(1.3, 2.7, 0.1);
117
+ var MOCKUP_VIEW_WHOLE_STRIP = "2.7@0.25";
116
118
  var MOCKUP_VIEW_PLACES = [...viewGrid(0.25, 0.475, 0.025), ...viewGrid(0.525, 0.75, 0.025)];
119
+ function canonicalMockupView(raw) {
120
+ const m = /^\s*(\d+(?:\.\d+)?)@(\d+(?:\.\d+)?)\s*$/.exec(String(raw));
121
+ if (!m) return null;
122
+ const r = MOCKUP_VIEW_SHAPES.find((x) => Math.abs(x - Number(m[1])) < 1e-9);
123
+ const f = MOCKUP_VIEW_PLACES.find((x) => Math.abs(x - Number(m[2])) < 1e-9);
124
+ if (r === void 0 || f === void 0) return null;
125
+ return r === 2.7 ? MOCKUP_VIEW_WHOLE_STRIP : `${r.toFixed(1)}@${String(f)}`;
126
+ }
117
127
  var MOCKUP_PRESETS = {
118
128
  tiktok: { aspect: "9:16", width: 1200 },
119
129
  // 1080x1920
@@ -173,6 +183,26 @@ var PUBLIC_PARAM_NAMES = [
173
183
  var REALTIME_WS_URL = SNOWCONE_REALTIME_WS_URL;
174
184
 
175
185
  // src/realtime/websocket.ts
186
+ function sessionViews(config) {
187
+ const raw = config.views;
188
+ if (raw === void 0) return void 0;
189
+ if (config.overlayCrop !== void 0 && config.overlayCrop !== "auto") {
190
+ throw new Error(
191
+ "[snowcone] E_REALTIME_VIEWS_WITH_CROP_RECT: a config with views takes no overlayCrop rect (a view IS the crop); send overlayCrop 'auto' (the print area inside the view) or none"
192
+ );
193
+ }
194
+ const out = {};
195
+ for (const [mockupId, v] of Object.entries(raw)) {
196
+ const canonical = canonicalMockupView(String(v));
197
+ if (!canonical) {
198
+ throw new Error(
199
+ `[snowcone] E_VIEW_PARAM_INVALID: views[${mockupId}] = ${JSON.stringify(v)} is not on the view grid <r>@<f> (compute it with mockupViewFor from @snowcone-app/sdk)`
200
+ );
201
+ }
202
+ if (config.mockupIds.includes(mockupId)) out[mockupId] = canonical;
203
+ }
204
+ return Object.keys(out).length ? out : void 0;
205
+ }
176
206
  function pruneUndefined(obj) {
177
207
  const out = {};
178
208
  for (const [k, v] of Object.entries(obj)) {
@@ -653,6 +683,7 @@ var RealtimeMockupService = class {
653
683
  data.imageUrl = frame.objectUrl;
654
684
  }
655
685
  sendConfig(config) {
686
+ const views = sessionViews(config);
656
687
  if (!this.ws || this.ws.readyState !== WebSocket.OPEN) {
657
688
  this.addLog("WebSocket not connected, caching config");
658
689
  this.config = config;
@@ -702,7 +733,8 @@ var RealtimeMockupService = class {
702
733
  // socket (mockup_frame binary messages) instead of making us fetch the
703
734
  // imageUrl — saves a network round trip per render. Servers that don't
704
735
  // know the flag ignore it and we fall back to the URL.
705
- config: { ...config, binaryFrames: true }
736
+ // views go out pruned to this config's mockupIds (undefined = the key is dropped by JSON).
737
+ config: { ...config, views, binaryFrames: true }
706
738
  };
707
739
  const messageStr = JSON.stringify(message);
708
740
  this.addLog(`\u{1F4E4} Sending config: ${JSON.stringify(message, null, 2)}`, "sent");
package/dist/react.d.cts CHANGED
@@ -1,5 +1,6 @@
1
- import { M as MockupResult, R as RealtimeRenderError, j as RealtimeMockupCallbacks, W as WebSocketConfig, P as PlacementSettings, w as RealtimeAcksState, F as FrameworkAdapter, b as ComponentProps, d as ComponentState, e as ComponentContext, f as ComponentLifecycleHooks, E as EventHandler, c as ComponentDescriptor, g as FrameworkUtilities } from './websocket-CvN0UU2j.cjs';
1
+ import { M as MockupResult, R as RealtimeRenderError, j as RealtimeMockupCallbacks, W as WebSocketConfig, P as PlacementSettings, x as RealtimeAcksState, F as FrameworkAdapter, b as ComponentProps, d as ComponentState, e as ComponentContext, f as ComponentLifecycleHooks, E as EventHandler, c as ComponentDescriptor, g as FrameworkUtilities } from './websocket-CSJT_g8j.cjs';
2
2
  import { CSSProperties, ReactNode } from 'react';
3
+ import '@snowcone-app/mockup-url';
3
4
 
4
5
  interface UseRealtimeMockupOptions {
5
6
  wsUrl?: string;
package/dist/react.d.ts CHANGED
@@ -1,5 +1,6 @@
1
- import { M as MockupResult, R as RealtimeRenderError, j as RealtimeMockupCallbacks, W as WebSocketConfig, P as PlacementSettings, w as RealtimeAcksState, F as FrameworkAdapter, b as ComponentProps, d as ComponentState, e as ComponentContext, f as ComponentLifecycleHooks, E as EventHandler, c as ComponentDescriptor, g as FrameworkUtilities } from './websocket-CvN0UU2j.js';
1
+ import { M as MockupResult, R as RealtimeRenderError, j as RealtimeMockupCallbacks, W as WebSocketConfig, P as PlacementSettings, x as RealtimeAcksState, F as FrameworkAdapter, b as ComponentProps, d as ComponentState, e as ComponentContext, f as ComponentLifecycleHooks, E as EventHandler, c as ComponentDescriptor, g as FrameworkUtilities } from './websocket-CSJT_g8j.js';
2
2
  import { CSSProperties, ReactNode } from 'react';
3
+ import '@snowcone-app/mockup-url';
3
4
 
4
5
  interface UseRealtimeMockupOptions {
5
6
  wsUrl?: string;
package/dist/react.js CHANGED
@@ -1,8 +1,8 @@
1
1
  import {
2
2
  REALTIME_WS_URL,
3
3
  RealtimeMockupService
4
- } from "./chunk-5LYS3YP5.js";
5
- import "./chunk-WPVMN73Y.js";
4
+ } from "./chunk-N5WOD5X2.js";
5
+ import "./chunk-KCOLSFYH.js";
6
6
 
7
7
  // src/realtime/react.ts
8
8
  import { useCallback, useEffect, useRef, useState } from "react";
package/dist/server.cjs CHANGED
@@ -87,7 +87,8 @@ var PARAMS = {
87
87
  aspect: "aspect",
88
88
  /**
89
89
  * `view=<r>@<f>`: a crop of a plate's 8:3 strip, for a page hero that shows only part of it ({@link canonicalMockupView}).
90
- * Goes with `aspect=8:3` only and never with `width=`: the crop is delivered at its own pixels.
90
+ * Goes with `aspect=8:3` only. Without `width=` the crop is delivered at its own pixels; with `width=` at that width when
91
+ * smaller (the box only ever downscales: a page asks crop width x DPR, capped at the crop).
91
92
  */
92
93
  view: "view",
93
94
  /**
@@ -111,7 +112,7 @@ var PARAMS = {
111
112
  seal: "seal"
112
113
  };
113
114
  var viewGrid = (from, to, step) => Array.from({ length: Math.round((to - from) / step) + 1 }, (_, i) => Math.round((from + i * step) * 1e3) / 1e3);
114
- var MOCKUP_VIEW_SHAPES = viewGrid(1.3, 2.6, 0.1);
115
+ var MOCKUP_VIEW_SHAPES = viewGrid(1.3, 2.7, 0.1);
115
116
  var MOCKUP_VIEW_PLACES = [...viewGrid(0.25, 0.475, 0.025), ...viewGrid(0.525, 0.75, 0.025)];
116
117
  var MOCKUP_PRESETS = {
117
118
  tiktok: { aspect: "9:16", width: 1200 },
package/dist/server.js CHANGED
@@ -2,7 +2,7 @@ import {
2
2
  SNOWCONE_HOSTS,
3
3
  canonicalForSig,
4
4
  signDevSig
5
- } from "./chunk-WPVMN73Y.js";
5
+ } from "./chunk-KCOLSFYH.js";
6
6
 
7
7
  // src/server.ts
8
8
  function json(body, status = 200) {
@@ -1,3 +1,5 @@
1
+ import { MockupView } from '@snowcone-app/mockup-url';
2
+
1
3
  type OptionSelection = Record<string, string>;
2
4
  interface OptionAttribute {
3
5
  key: string;
@@ -205,6 +207,13 @@ declare class AdapterRegistry {
205
207
  }
206
208
  declare const adapterRegistry: AdapterRegistry;
207
209
 
210
+ /**
211
+ * The `views` a config goes out with (lane shapes #5520, rendercenter rc#898): canonical, and only for mockups the config
212
+ * renders (`mockupIds`), so a session that narrows its set (the viewport policy, a priority update) never names a mockup
213
+ * the box would refuse; undefined when none is left. Throws, the fix in the message, on what the box refuses outright:
214
+ * a value off the view grid, or views beside an overlayCrop RECT (overlayCrop 'auto' is the print area inside the view).
215
+ */
216
+ declare function sessionViews(config: Pick<WebSocketConfig, 'views' | 'mockupIds' | 'overlayCrop'>): Record<string, MockupView> | undefined;
208
217
  interface PlacementSettings {
209
218
  tiles?: 0.25 | 0.5 | 1 | 2 | 4 | 8 | 16;
210
219
  scaleMode?: 'fill' | 'fit';
@@ -291,6 +300,13 @@ interface WebSocketConfig {
291
300
  * single product it is refused (`E_NOT_A_BUNDLE`).
292
301
  */
293
302
  picks?: Record<string, string>;
303
+ /**
304
+ * Per mockup, the crop of its plate's 8:3 strip the page's hero shows (`view=<r>@<f>`, lane shapes #5520): that
305
+ * mockup's live frame is `aspect=8:3&view=<v>` with no width, the same crop the static hero asks for, so it drops into
306
+ * the hero's box; with overlayCrop 'auto' the cropped frame's rect comes in the VIEW's fractions. Sent only for mockups
307
+ * in `mockupIds` ({@link sessionViews}); every other mockup renders as before. Not with an overlayCrop rect.
308
+ */
309
+ views?: Record<string, MockupView>;
294
310
  /**
295
311
  * ADR-0099 (bundle records only): the variant per slot — `role → gvid`.
296
312
  * A bundle session names its variants per ROLE; a bare `variantId` on a
@@ -668,4 +684,4 @@ declare class RealtimeMockupService {
668
684
  clearMockups(): void;
669
685
  }
670
686
 
671
- export { AdapterRegistry as A, type Combination as C, type EventHandler as E, type FrameworkAdapter as F, type MockupResult as M, type OptionAttribute as O, type PlacementSettings as P, type RealtimeRenderError as R, type WebSocketConfig as W, type OptionSelection as a, type ComponentProps as b, type ComponentDescriptor as c, type ComponentState as d, type ComponentContext as e, type ComponentLifecycleHooks as f, type FrameworkUtilities as g, RealtimeMockupService as h, type ProductComponentContext as i, type RealtimeMockupCallbacks as j, type RealtimeMockupState as k, type RenderResult as l, type WebSocketMessage as m, adapterRegistry as n, computeDisabledChoices as o, createComponent as p, defineComponent as q, deriveDefaultSelection as r, findBestCombination as s, getPricePreview as t, isOptionAvailable as u, resolveBestCombination as v, type RealtimeAcksState as w };
687
+ export { AdapterRegistry as A, type Combination as C, type EventHandler as E, type FrameworkAdapter as F, type MockupResult as M, type OptionAttribute as O, type PlacementSettings as P, type RealtimeRenderError as R, type WebSocketConfig as W, type OptionSelection as a, type ComponentProps as b, type ComponentDescriptor as c, type ComponentState as d, type ComponentContext as e, type ComponentLifecycleHooks as f, type FrameworkUtilities as g, RealtimeMockupService as h, type ProductComponentContext as i, type RealtimeMockupCallbacks as j, type RealtimeMockupState as k, type RenderResult as l, type WebSocketMessage as m, adapterRegistry as n, computeDisabledChoices as o, createComponent as p, defineComponent as q, deriveDefaultSelection as r, findBestCombination as s, getPricePreview as t, isOptionAvailable as u, resolveBestCombination as v, sessionViews as w, type RealtimeAcksState as x };
@@ -1,3 +1,5 @@
1
+ import { MockupView } from '@snowcone-app/mockup-url';
2
+
1
3
  type OptionSelection = Record<string, string>;
2
4
  interface OptionAttribute {
3
5
  key: string;
@@ -205,6 +207,13 @@ declare class AdapterRegistry {
205
207
  }
206
208
  declare const adapterRegistry: AdapterRegistry;
207
209
 
210
+ /**
211
+ * The `views` a config goes out with (lane shapes #5520, rendercenter rc#898): canonical, and only for mockups the config
212
+ * renders (`mockupIds`), so a session that narrows its set (the viewport policy, a priority update) never names a mockup
213
+ * the box would refuse; undefined when none is left. Throws, the fix in the message, on what the box refuses outright:
214
+ * a value off the view grid, or views beside an overlayCrop RECT (overlayCrop 'auto' is the print area inside the view).
215
+ */
216
+ declare function sessionViews(config: Pick<WebSocketConfig, 'views' | 'mockupIds' | 'overlayCrop'>): Record<string, MockupView> | undefined;
208
217
  interface PlacementSettings {
209
218
  tiles?: 0.25 | 0.5 | 1 | 2 | 4 | 8 | 16;
210
219
  scaleMode?: 'fill' | 'fit';
@@ -291,6 +300,13 @@ interface WebSocketConfig {
291
300
  * single product it is refused (`E_NOT_A_BUNDLE`).
292
301
  */
293
302
  picks?: Record<string, string>;
303
+ /**
304
+ * Per mockup, the crop of its plate's 8:3 strip the page's hero shows (`view=<r>@<f>`, lane shapes #5520): that
305
+ * mockup's live frame is `aspect=8:3&view=<v>` with no width, the same crop the static hero asks for, so it drops into
306
+ * the hero's box; with overlayCrop 'auto' the cropped frame's rect comes in the VIEW's fractions. Sent only for mockups
307
+ * in `mockupIds` ({@link sessionViews}); every other mockup renders as before. Not with an overlayCrop rect.
308
+ */
309
+ views?: Record<string, MockupView>;
294
310
  /**
295
311
  * ADR-0099 (bundle records only): the variant per slot — `role → gvid`.
296
312
  * A bundle session names its variants per ROLE; a bare `variantId` on a
@@ -668,4 +684,4 @@ declare class RealtimeMockupService {
668
684
  clearMockups(): void;
669
685
  }
670
686
 
671
- export { AdapterRegistry as A, type Combination as C, type EventHandler as E, type FrameworkAdapter as F, type MockupResult as M, type OptionAttribute as O, type PlacementSettings as P, type RealtimeRenderError as R, type WebSocketConfig as W, type OptionSelection as a, type ComponentProps as b, type ComponentDescriptor as c, type ComponentState as d, type ComponentContext as e, type ComponentLifecycleHooks as f, type FrameworkUtilities as g, RealtimeMockupService as h, type ProductComponentContext as i, type RealtimeMockupCallbacks as j, type RealtimeMockupState as k, type RenderResult as l, type WebSocketMessage as m, adapterRegistry as n, computeDisabledChoices as o, createComponent as p, defineComponent as q, deriveDefaultSelection as r, findBestCombination as s, getPricePreview as t, isOptionAvailable as u, resolveBestCombination as v, type RealtimeAcksState as w };
687
+ export { AdapterRegistry as A, type Combination as C, type EventHandler as E, type FrameworkAdapter as F, type MockupResult as M, type OptionAttribute as O, type PlacementSettings as P, type RealtimeRenderError as R, type WebSocketConfig as W, type OptionSelection as a, type ComponentProps as b, type ComponentDescriptor as c, type ComponentState as d, type ComponentContext as e, type ComponentLifecycleHooks as f, type FrameworkUtilities as g, RealtimeMockupService as h, type ProductComponentContext as i, type RealtimeMockupCallbacks as j, type RealtimeMockupState as k, type RenderResult as l, type WebSocketMessage as m, adapterRegistry as n, computeDisabledChoices as o, createComponent as p, defineComponent as q, deriveDefaultSelection as r, findBestCombination as s, getPricePreview as t, isOptionAvailable as u, resolveBestCombination as v, sessionViews as w, type RealtimeAcksState as x };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@snowcone-app/sdk",
3
- "version": "0.31.2",
3
+ "version": "0.31.5",
4
4
  "description": "Snowcone SDK for product mockups and print-on-demand",
5
5
  "keywords": [
6
6
  "merch",