@snowcone-app/sdk 0.31.2 → 0.31.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/CHANGELOG.md +12 -0
- package/dist/{chunk-5LYS3YP5.js → chunk-2MNYYJHG.js} +27 -3
- package/dist/{chunk-WPVMN73Y.js → chunk-KCIDK2T7.js} +5 -3
- package/dist/index.cjs +30 -4
- package/dist/index.d.cts +5 -4
- package/dist/index.d.ts +5 -4
- package/dist/index.js +5 -3
- package/dist/react.cjs +32 -2
- package/dist/react.d.cts +2 -1
- package/dist/react.d.ts +2 -1
- package/dist/react.js +2 -2
- package/dist/server.cjs +2 -1
- package/dist/server.js +1 -1
- package/dist/{websocket-CvN0UU2j.d.cts → websocket-CSJT_g8j.d.cts} +17 -1
- package/dist/{websocket-CvN0UU2j.d.ts → websocket-CSJT_g8j.d.ts} +17 -1
- package/package.json +1 -1
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,17 @@
|
|
|
1
1
|
# Changelog
|
|
2
2
|
|
|
3
|
+
## 0.31.4
|
|
4
|
+
|
|
5
|
+
### Patch Changes
|
|
6
|
+
|
|
7
|
+
- [#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.
|
|
8
|
+
|
|
9
|
+
## 0.31.3
|
|
10
|
+
|
|
11
|
+
### Patch Changes
|
|
12
|
+
|
|
13
|
+
- [#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).
|
|
14
|
+
|
|
3
15
|
## 0.31.2
|
|
4
16
|
|
|
5
17
|
### Patch Changes
|
|
@@ -1,11 +1,32 @@
|
|
|
1
1
|
import {
|
|
2
|
-
SNOWCONE_REALTIME_WS_URL
|
|
3
|
-
|
|
2
|
+
SNOWCONE_REALTIME_WS_URL,
|
|
3
|
+
canonicalMockupView
|
|
4
|
+
} from "./chunk-KCIDK2T7.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
|
-
|
|
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
|
};
|
|
@@ -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
|
|
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
|
/**
|
|
@@ -101,7 +102,8 @@ function requireMockupView(view, ctx) {
|
|
|
101
102
|
const v = canonicalMockupView(view);
|
|
102
103
|
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
104
|
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.
|
|
105
|
+
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`);
|
|
106
|
+
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
107
|
return v;
|
|
106
108
|
}
|
|
107
109
|
var MOCKUP_PRESETS = {
|
|
@@ -218,7 +220,7 @@ function buildMockupUrl(options, cfg) {
|
|
|
218
220
|
}
|
|
219
221
|
}
|
|
220
222
|
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);
|
|
223
|
+
const width = view ? options.width !== void 0 ? normalizeWidth(options.width) : void 0 : normalizeWidth(options.width);
|
|
222
224
|
const base = cfg.mockupBaseUrl.replace(/\/+$/, "");
|
|
223
225
|
const path = `/${encodeURIComponent(options.productId)}`;
|
|
224
226
|
let queryString = `${PARAMS.shop}=${encodeURIComponent(cfg.shop)}`;
|
package/dist/index.cjs
CHANGED
|
@@ -156,6 +156,7 @@ __export(src_exports, {
|
|
|
156
156
|
resolveVariantId: () => resolveVariantId,
|
|
157
157
|
retryOperation: () => retryOperation,
|
|
158
158
|
searchDesigns: () => searchDesigns,
|
|
159
|
+
sessionViews: () => sessionViews,
|
|
159
160
|
simulateCartOperation: () => simulateCartOperation,
|
|
160
161
|
toCombinations: () => toCombinations,
|
|
161
162
|
toOptionAttributes: () => toOptionAttributes,
|
|
@@ -322,7 +323,8 @@ var PARAMS = {
|
|
|
322
323
|
aspect: "aspect",
|
|
323
324
|
/**
|
|
324
325
|
* `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
|
|
326
|
+
* Goes with `aspect=8:3` only. Without `width=` the crop is delivered at its own pixels; with `width=` at that width when
|
|
327
|
+
* smaller (the box only ever downscales: a page asks crop width x DPR, capped at the crop).
|
|
326
328
|
*/
|
|
327
329
|
view: "view",
|
|
328
330
|
/**
|
|
@@ -369,7 +371,8 @@ function requireMockupView(view, ctx) {
|
|
|
369
371
|
const v = canonicalMockupView(view);
|
|
370
372
|
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
373
|
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.
|
|
374
|
+
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`);
|
|
375
|
+
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
376
|
return v;
|
|
374
377
|
}
|
|
375
378
|
var MOCKUP_PRESETS = {
|
|
@@ -486,7 +489,7 @@ function buildMockupUrl(options, cfg) {
|
|
|
486
489
|
}
|
|
487
490
|
}
|
|
488
491
|
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);
|
|
492
|
+
const width = view ? options.width !== void 0 ? normalizeWidth(options.width) : void 0 : normalizeWidth(options.width);
|
|
490
493
|
const base = cfg.mockupBaseUrl.replace(/\/+$/, "");
|
|
491
494
|
const path = `/${encodeURIComponent(options.productId)}`;
|
|
492
495
|
let queryString = `${PARAMS.shop}=${encodeURIComponent(cfg.shop)}`;
|
|
@@ -5199,6 +5202,26 @@ function createSvelteComponent(descriptor, svelte) {
|
|
|
5199
5202
|
var REALTIME_WS_URL = SNOWCONE_REALTIME_WS_URL;
|
|
5200
5203
|
|
|
5201
5204
|
// src/realtime/websocket.ts
|
|
5205
|
+
function sessionViews(config) {
|
|
5206
|
+
const raw = config.views;
|
|
5207
|
+
if (raw === void 0) return void 0;
|
|
5208
|
+
if (config.overlayCrop !== void 0 && config.overlayCrop !== "auto") {
|
|
5209
|
+
throw new Error(
|
|
5210
|
+
"[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"
|
|
5211
|
+
);
|
|
5212
|
+
}
|
|
5213
|
+
const out = {};
|
|
5214
|
+
for (const [mockupId, v] of Object.entries(raw)) {
|
|
5215
|
+
const canonical = canonicalMockupView(String(v));
|
|
5216
|
+
if (!canonical) {
|
|
5217
|
+
throw new Error(
|
|
5218
|
+
`[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)`
|
|
5219
|
+
);
|
|
5220
|
+
}
|
|
5221
|
+
if (config.mockupIds.includes(mockupId)) out[mockupId] = canonical;
|
|
5222
|
+
}
|
|
5223
|
+
return Object.keys(out).length ? out : void 0;
|
|
5224
|
+
}
|
|
5202
5225
|
function pruneUndefined(obj) {
|
|
5203
5226
|
const out = {};
|
|
5204
5227
|
for (const [k, v] of Object.entries(obj)) {
|
|
@@ -5679,6 +5702,7 @@ var RealtimeMockupService = class {
|
|
|
5679
5702
|
data.imageUrl = frame.objectUrl;
|
|
5680
5703
|
}
|
|
5681
5704
|
sendConfig(config) {
|
|
5705
|
+
const views = sessionViews(config);
|
|
5682
5706
|
if (!this.ws || this.ws.readyState !== WebSocket.OPEN) {
|
|
5683
5707
|
this.addLog("WebSocket not connected, caching config");
|
|
5684
5708
|
this.config = config;
|
|
@@ -5728,7 +5752,8 @@ var RealtimeMockupService = class {
|
|
|
5728
5752
|
// socket (mockup_frame binary messages) instead of making us fetch the
|
|
5729
5753
|
// imageUrl — saves a network round trip per render. Servers that don't
|
|
5730
5754
|
// know the flag ignore it and we fall back to the URL.
|
|
5731
|
-
|
|
5755
|
+
// views go out pruned to this config's mockupIds (undefined = the key is dropped by JSON).
|
|
5756
|
+
config: { ...config, views, binaryFrames: true }
|
|
5732
5757
|
};
|
|
5733
5758
|
const messageStr = JSON.stringify(message);
|
|
5734
5759
|
this.addLog(`\u{1F4E4} Sending config: ${JSON.stringify(message, null, 2)}`, "sent");
|
|
@@ -6906,6 +6931,7 @@ function createClient(config) {
|
|
|
6906
6931
|
resolveVariantId,
|
|
6907
6932
|
retryOperation,
|
|
6908
6933
|
searchDesigns,
|
|
6934
|
+
sessionViews,
|
|
6909
6935
|
simulateCartOperation,
|
|
6910
6936
|
toCombinations,
|
|
6911
6937
|
toOptionAttributes,
|
package/dist/index.d.cts
CHANGED
|
@@ -2,8 +2,8 @@ export { createDevFetcher } from './dev-fetcher.cjs';
|
|
|
2
2
|
import { PublicDesign, PublicFill, PublicOptions, MockupView, MockupAspect, MockupPreset } from '@snowcone-app/mockup-url';
|
|
3
3
|
export { MOCKUP_VIEW_PLACES, MOCKUP_VIEW_SHAPES, 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-
|
|
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-
|
|
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 `
|
|
393
|
-
* crop
|
|
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
|
@@ -2,8 +2,8 @@ export { createDevFetcher } from './dev-fetcher.js';
|
|
|
2
2
|
import { PublicDesign, PublicFill, PublicOptions, MockupView, MockupAspect, MockupPreset } from '@snowcone-app/mockup-url';
|
|
3
3
|
export { MOCKUP_VIEW_PLACES, MOCKUP_VIEW_SHAPES, 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-
|
|
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-
|
|
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 `
|
|
393
|
-
* crop
|
|
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,7 +1,8 @@
|
|
|
1
1
|
import {
|
|
2
2
|
REALTIME_WS_URL,
|
|
3
|
-
RealtimeMockupService
|
|
4
|
-
|
|
3
|
+
RealtimeMockupService,
|
|
4
|
+
sessionViews
|
|
5
|
+
} from "./chunk-2MNYYJHG.js";
|
|
5
6
|
import {
|
|
6
7
|
createDevFetcher
|
|
7
8
|
} from "./chunk-7VO4EL2V.js";
|
|
@@ -17,7 +18,7 @@ import {
|
|
|
17
18
|
mockupViewFor,
|
|
18
19
|
normalizeDesignElements,
|
|
19
20
|
normalizeWidth
|
|
20
|
-
} from "./chunk-
|
|
21
|
+
} from "./chunk-KCIDK2T7.js";
|
|
21
22
|
import {
|
|
22
23
|
PDP_GALLERY_LIMIT,
|
|
23
24
|
SIZE_PICTURE,
|
|
@@ -5333,6 +5334,7 @@ export {
|
|
|
5333
5334
|
resolveVariantId,
|
|
5334
5335
|
retryOperation,
|
|
5335
5336
|
searchDesigns,
|
|
5337
|
+
sessionViews,
|
|
5336
5338
|
simulateCartOperation,
|
|
5337
5339
|
toCombinations,
|
|
5338
5340
|
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
|
|
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
|
/**
|
|
@@ -114,6 +115,13 @@ var PARAMS = {
|
|
|
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
116
|
var MOCKUP_VIEW_SHAPES = viewGrid(1.3, 2.6, 0.1);
|
|
116
117
|
var MOCKUP_VIEW_PLACES = [...viewGrid(0.25, 0.475, 0.025), ...viewGrid(0.525, 0.75, 0.025)];
|
|
118
|
+
function canonicalMockupView(raw) {
|
|
119
|
+
const m = /^\s*(\d+(?:\.\d+)?)@(\d+(?:\.\d+)?)\s*$/.exec(String(raw));
|
|
120
|
+
if (!m) return null;
|
|
121
|
+
const r = MOCKUP_VIEW_SHAPES.find((x) => Math.abs(x - Number(m[1])) < 1e-9);
|
|
122
|
+
const f = MOCKUP_VIEW_PLACES.find((x) => Math.abs(x - Number(m[2])) < 1e-9);
|
|
123
|
+
return r === void 0 || f === void 0 ? null : `${r.toFixed(1)}@${String(f)}`;
|
|
124
|
+
}
|
|
117
125
|
var MOCKUP_PRESETS = {
|
|
118
126
|
tiktok: { aspect: "9:16", width: 1200 },
|
|
119
127
|
// 1080x1920
|
|
@@ -173,6 +181,26 @@ var PUBLIC_PARAM_NAMES = [
|
|
|
173
181
|
var REALTIME_WS_URL = SNOWCONE_REALTIME_WS_URL;
|
|
174
182
|
|
|
175
183
|
// src/realtime/websocket.ts
|
|
184
|
+
function sessionViews(config) {
|
|
185
|
+
const raw = config.views;
|
|
186
|
+
if (raw === void 0) return void 0;
|
|
187
|
+
if (config.overlayCrop !== void 0 && config.overlayCrop !== "auto") {
|
|
188
|
+
throw new Error(
|
|
189
|
+
"[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"
|
|
190
|
+
);
|
|
191
|
+
}
|
|
192
|
+
const out = {};
|
|
193
|
+
for (const [mockupId, v] of Object.entries(raw)) {
|
|
194
|
+
const canonical = canonicalMockupView(String(v));
|
|
195
|
+
if (!canonical) {
|
|
196
|
+
throw new Error(
|
|
197
|
+
`[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)`
|
|
198
|
+
);
|
|
199
|
+
}
|
|
200
|
+
if (config.mockupIds.includes(mockupId)) out[mockupId] = canonical;
|
|
201
|
+
}
|
|
202
|
+
return Object.keys(out).length ? out : void 0;
|
|
203
|
+
}
|
|
176
204
|
function pruneUndefined(obj) {
|
|
177
205
|
const out = {};
|
|
178
206
|
for (const [k, v] of Object.entries(obj)) {
|
|
@@ -653,6 +681,7 @@ var RealtimeMockupService = class {
|
|
|
653
681
|
data.imageUrl = frame.objectUrl;
|
|
654
682
|
}
|
|
655
683
|
sendConfig(config) {
|
|
684
|
+
const views = sessionViews(config);
|
|
656
685
|
if (!this.ws || this.ws.readyState !== WebSocket.OPEN) {
|
|
657
686
|
this.addLog("WebSocket not connected, caching config");
|
|
658
687
|
this.config = config;
|
|
@@ -702,7 +731,8 @@ var RealtimeMockupService = class {
|
|
|
702
731
|
// socket (mockup_frame binary messages) instead of making us fetch the
|
|
703
732
|
// imageUrl — saves a network round trip per render. Servers that don't
|
|
704
733
|
// know the flag ignore it and we fall back to the URL.
|
|
705
|
-
|
|
734
|
+
// views go out pruned to this config's mockupIds (undefined = the key is dropped by JSON).
|
|
735
|
+
config: { ...config, views, binaryFrames: true }
|
|
706
736
|
};
|
|
707
737
|
const messageStr = JSON.stringify(message);
|
|
708
738
|
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,
|
|
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,
|
|
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-
|
|
5
|
-
import "./chunk-
|
|
4
|
+
} from "./chunk-2MNYYJHG.js";
|
|
5
|
+
import "./chunk-KCIDK2T7.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
|
|
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
|
/**
|
package/dist/server.js
CHANGED
|
@@ -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
|
|
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
|
|
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 };
|