@snowcone-app/ui 0.12.2 → 0.13.2
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 +22 -0
- package/dist/chunk-GY6TC6M6.js +86 -0
- package/dist/chunk-GY6TC6M6.js.map +1 -0
- package/dist/index.cjs +225 -51
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +45 -3
- package/dist/index.d.ts +45 -3
- package/dist/index.js +194 -52
- package/dist/index.js.map +1 -1
- package/dist/personalization/bridge.cjs.map +1 -1
- package/dist/personalization/bridge.d.cts +1 -1
- package/dist/personalization/bridge.d.ts +1 -1
- package/dist/personalization/bridge.js +1 -1
- package/dist/{types-CNJT8FUd.d.cts → types-BObPMwP5.d.cts} +17 -1
- package/dist/{types-CNJT8FUd.d.ts → types-BObPMwP5.d.ts} +17 -1
- package/package.json +1 -1
- package/src/composed/HeroProductImage.tsx +137 -64
- package/src/composed/__tests__/HeroProductImage.mountsOnLiveFrame.test.tsx +147 -0
- package/src/composed/__tests__/HeroProductImage.swap.test.tsx +105 -0
- package/src/patterns/RealtimeProvider.tsx +32 -1
- package/src/patterns/__tests__/RealtimeProvider.blobLifecycle.test.tsx +73 -0
- package/src/personalization/PersonalizationInputs.tsx +2 -0
- package/src/personalization/PersonalizationProvider.tsx +95 -14
- package/src/personalization/__tests__/PersonalizationProvider.last-keystroke.test.tsx +81 -0
- package/src/personalization/__tests__/fit.test.ts +75 -0
- package/src/personalization/index.ts +2 -1
- package/src/personalization/types.ts +16 -0
- package/src/personalization/utils.ts +68 -0
- package/dist/chunk-WDOT4BST.js +0 -50
- package/dist/chunk-WDOT4BST.js.map +0 -1
package/dist/index.cjs
CHANGED
|
@@ -224,6 +224,7 @@ __export(src_exports, {
|
|
|
224
224
|
FACET_SECTIONS: () => FACET_SECTIONS,
|
|
225
225
|
FIRST_VIEW_MARGIN: () => FIRST_VIEW_MARGIN,
|
|
226
226
|
FIRST_VIEW_PICTURE_ASPECT: () => FIRST_VIEW_PICTURE_ASPECT,
|
|
227
|
+
FIT_MARGIN: () => FIT_MARGIN,
|
|
227
228
|
Fieldset: () => Fieldset,
|
|
228
229
|
Filters: () => Filters,
|
|
229
230
|
FiltersButton: () => FiltersButton,
|
|
@@ -345,15 +346,18 @@ __export(src_exports, {
|
|
|
345
346
|
UiRouterProvider: () => UiRouterProvider,
|
|
346
347
|
VISIBILITY_THRESHOLDS: () => VISIBILITY_THRESHOLDS,
|
|
347
348
|
ZoomOverlay: () => ZoomOverlay,
|
|
349
|
+
anyTyped: () => anyTyped,
|
|
348
350
|
badgeVariants: () => badgeVariants,
|
|
349
351
|
blockingSessionError: () => blockingSessionError,
|
|
350
352
|
brandAssets: () => brandAssets,
|
|
351
353
|
buttonVariants: () => buttonVariants,
|
|
352
354
|
canvasExportService: () => canvasExportService,
|
|
355
|
+
canvasFontString: () => canvasFontString,
|
|
353
356
|
checkComponentStyles: () => checkComponentStyles,
|
|
354
357
|
checkTailwindConfig: () => checkTailwindConfig,
|
|
355
358
|
checkThemeTokens: () => checkThemeTokens,
|
|
356
359
|
createScrollDirectionTracker: () => createScrollDirectionTracker,
|
|
360
|
+
decodedPicture: () => decodedPicture,
|
|
357
361
|
describeProductArtAlignment: () => import_sdk16.describeProductArtAlignment,
|
|
358
362
|
firstView: () => firstView,
|
|
359
363
|
firstViewAnchorOfSlide: () => firstViewAnchorOfSlide,
|
|
@@ -376,17 +380,21 @@ __export(src_exports, {
|
|
|
376
380
|
linkVariants: () => linkVariants,
|
|
377
381
|
linkedPlacementsLabel: () => linkedPlacementsLabel,
|
|
378
382
|
listProducts: () => import_sdk15.listProducts,
|
|
383
|
+
measureTextLine: () => measureTextLine,
|
|
379
384
|
normalizeHex: () => normalizeHex,
|
|
380
385
|
observe: () => observe,
|
|
381
386
|
pictureRenderState: () => pictureRenderState,
|
|
387
|
+
pictureSwapOf: () => pictureSwapOf,
|
|
382
388
|
placementArtFor: () => placementArtFor,
|
|
383
389
|
runConfigChecks: () => runConfigChecks,
|
|
384
390
|
scrollInputAboveKeyboard: () => scrollInputAboveKeyboard,
|
|
385
391
|
searchClient: () => searchClient,
|
|
392
|
+
shrinkFontSizeToFit: () => shrinkFontSizeToFit,
|
|
386
393
|
slideFirstViewFields: () => slideFirstViewFields,
|
|
387
394
|
slideFirstViewProps: () => slideFirstViewProps,
|
|
388
395
|
spinnerVariants: () => spinnerVariants,
|
|
389
396
|
surfaceVariants: () => surfaceVariants,
|
|
397
|
+
textValueFor: () => textValueFor,
|
|
390
398
|
useArtworkAlignment: () => useArtworkAlignment,
|
|
391
399
|
useBrand: () => useBrand,
|
|
392
400
|
useCanvasContext: () => useCanvasContext,
|
|
@@ -6397,6 +6405,8 @@ function RealtimeProvider({
|
|
|
6397
6405
|
const rerenderTimerRef = (0, import_react25.useRef)(null);
|
|
6398
6406
|
const fullFrameRerenderIdsRef = (0, import_react25.useRef)(/* @__PURE__ */ new Set());
|
|
6399
6407
|
const fullFrameRerenderTimerRef = (0, import_react25.useRef)(null);
|
|
6408
|
+
const rerenderFullFrameRef = (0, import_react25.useRef)(null);
|
|
6409
|
+
const lostFrameAskedRef = (0, import_react25.useRef)(/* @__PURE__ */ new Set());
|
|
6400
6410
|
(0, import_react25.useEffect)(
|
|
6401
6411
|
() => () => {
|
|
6402
6412
|
if (fullFrameRerenderTimerRef.current) clearTimeout(fullFrameRerenderTimerRef.current);
|
|
@@ -6448,6 +6458,7 @@ function RealtimeProvider({
|
|
|
6448
6458
|
}, [revokeBlobUrl]);
|
|
6449
6459
|
const markBlobShown = (0, import_react25.useCallback)((owner, url, consumer = "default") => {
|
|
6450
6460
|
ackUrl(url);
|
|
6461
|
+
lostFrameAskedRef.current.delete(owner);
|
|
6451
6462
|
const list = blobsByOwnerRef.current.get(owner);
|
|
6452
6463
|
if (!list || list.indexOf(url) < 0) return;
|
|
6453
6464
|
const shown = shownBlobByOwnerRef.current.get(owner) ?? /* @__PURE__ */ new Map();
|
|
@@ -6457,6 +6468,22 @@ function RealtimeProvider({
|
|
|
6457
6468
|
}, [releaseOlderFrames, ackUrl]);
|
|
6458
6469
|
const frameFailed = (0, import_react25.useCallback)((url) => {
|
|
6459
6470
|
ackUrl(url);
|
|
6471
|
+
if (!url.startsWith("blob:")) return;
|
|
6472
|
+
let mockupId;
|
|
6473
|
+
mockupUrlCacheRef.current.forEach((entry, id) => {
|
|
6474
|
+
if (entry.url === url) mockupId = id;
|
|
6475
|
+
});
|
|
6476
|
+
if (!mockupId) return;
|
|
6477
|
+
if (pendingMockupIdsRef.current.has(mockupId)) return;
|
|
6478
|
+
if (compositeQueueRef.current.has(mockupId) || compositeBusyRef.current.has(mockupId)) return;
|
|
6479
|
+
if (lostFrameAskedRef.current.has(mockupId)) return;
|
|
6480
|
+
lostFrameAskedRef.current.add(mockupId);
|
|
6481
|
+
console.error(
|
|
6482
|
+
`[RealtimeProvider] E_FRAME_LOST: ${mockupId}'s newest frame could not be loaded (gone before any element drew it); re-rendering that picture.`
|
|
6483
|
+
);
|
|
6484
|
+
mockupUrlCacheRef.current.delete(mockupId);
|
|
6485
|
+
mockupResultsRef.current = mockupResultsRef.current.filter((r) => r.imageUrl !== url);
|
|
6486
|
+
rerenderFullFrameRef.current?.(mockupId);
|
|
6460
6487
|
}, [ackUrl]);
|
|
6461
6488
|
const releaseBlobConsumer = (0, import_react25.useCallback)((owner, consumer) => {
|
|
6462
6489
|
const shown = shownBlobByOwnerRef.current.get(owner);
|
|
@@ -6563,6 +6590,7 @@ function RealtimeProvider({
|
|
|
6563
6590
|
},
|
|
6564
6591
|
[sendFullFrameConfig, forceRerenderByConfig, sendRerenderPaced]
|
|
6565
6592
|
);
|
|
6593
|
+
rerenderFullFrameRef.current = rerenderFullFrame;
|
|
6566
6594
|
const maybeFlipCrop = (0, import_react25.useCallback)(() => {
|
|
6567
6595
|
if (!croppedDeliveryEnabled || !cropCapableRef.current) return;
|
|
6568
6596
|
if (croppedActiveRef.current) return;
|
|
@@ -11134,6 +11162,23 @@ function heroSize(stripView, cropWidth, width) {
|
|
|
11134
11162
|
if (isCrop(stripView)) return cropWidth !== void 0 ? { stripView, width: cropWidth } : { stripView };
|
|
11135
11163
|
return { width };
|
|
11136
11164
|
}
|
|
11165
|
+
function pictureSwapOf(shownUrl, nextUrl) {
|
|
11166
|
+
if (!shownUrl) return "instant";
|
|
11167
|
+
return nextUrl.startsWith("blob:") || shownUrl.startsWith("blob:") ? "instant" : "crossfade";
|
|
11168
|
+
}
|
|
11169
|
+
function decodedPicture(img) {
|
|
11170
|
+
if (typeof img.decode === "function") {
|
|
11171
|
+
return img.decode().catch((e) => {
|
|
11172
|
+
if (img.complete && img.naturalWidth > 0) return;
|
|
11173
|
+
throw e;
|
|
11174
|
+
});
|
|
11175
|
+
}
|
|
11176
|
+
return new Promise((resolve, reject) => {
|
|
11177
|
+
if (img.complete) return resolve();
|
|
11178
|
+
img.onload = () => resolve();
|
|
11179
|
+
img.onerror = () => reject(new Error("E_FRAME_UNAVAILABLE"));
|
|
11180
|
+
});
|
|
11181
|
+
}
|
|
11137
11182
|
var EMPTY_IMAGES = [];
|
|
11138
11183
|
var DESIGN_BUSY_RETRY_MS = 1500;
|
|
11139
11184
|
function blockingSessionError(error) {
|
|
@@ -11298,7 +11343,13 @@ var HeroProductImage = (0, import_react48.memo)(function HeroProductImage2({
|
|
|
11298
11343
|
const priorityRegisteredRef = (0, import_react48.useRef)(false);
|
|
11299
11344
|
const onLoadCalledRef = (0, import_react48.useRef)(false);
|
|
11300
11345
|
const prevArtworkSrcRef = (0, import_react48.useRef)(void 0);
|
|
11301
|
-
const
|
|
11346
|
+
const artIdentityRef = (0, import_react48.useRef)(void 0);
|
|
11347
|
+
artIdentityRef.current = artIdentity(artworkSrc || selectedArtworkSrc, placementArtKey);
|
|
11348
|
+
const mountedOnLiveFrame = !!realtimeUrl && (realtimeUrl.startsWith("blob:") || !!actualMockupId && realtimeUrl === realtimeContext?.getMockupUrl?.(actualMockupId));
|
|
11349
|
+
const realtimeArtworkSrcRef = (0, import_react48.useRef)(
|
|
11350
|
+
mountedOnLiveFrame ? artIdentity(artworkSrc || selectedArtworkSrc, placementArtKey) : void 0
|
|
11351
|
+
);
|
|
11352
|
+
const artSeenRef = (0, import_react48.useRef)(false);
|
|
11302
11353
|
const hasReceivedRealtimeRef = (0, import_react48.useRef)(false);
|
|
11303
11354
|
const isPendingExportRef = (0, import_react48.useRef)(false);
|
|
11304
11355
|
const onUrlGeneratedRef = (0, import_react48.useRef)(onUrlGenerated);
|
|
@@ -11357,6 +11408,7 @@ var HeroProductImage = (0, import_react48.memo)(function HeroProductImage2({
|
|
|
11357
11408
|
const handleMockupResult = (result) => {
|
|
11358
11409
|
if (!result?.imageUrl) return;
|
|
11359
11410
|
hasReceivedRealtimeRef.current = true;
|
|
11411
|
+
realtimeArtworkSrcRef.current = artIdentityRef.current;
|
|
11360
11412
|
isPendingExportRef.current = false;
|
|
11361
11413
|
const cachedUrl = realtimeContext.getMockupUrl(result.mockupId);
|
|
11362
11414
|
if (!cachedUrl) return;
|
|
@@ -11408,7 +11460,11 @@ var HeroProductImage = (0, import_react48.memo)(function HeroProductImage2({
|
|
|
11408
11460
|
const frameErrorRef = (0, import_react48.useRef)(null);
|
|
11409
11461
|
const showVersionOf = (0, import_react48.useCallback)((url) => {
|
|
11410
11462
|
const e = versionByUrlRef.current.get(url);
|
|
11411
|
-
if (!e
|
|
11463
|
+
if (!e) {
|
|
11464
|
+
renderVersionRef.current = 0;
|
|
11465
|
+
renderVersionsRef.current = null;
|
|
11466
|
+
return;
|
|
11467
|
+
}
|
|
11412
11468
|
renderVersionRef.current = e.v;
|
|
11413
11469
|
renderVersionsRef.current = e.versions;
|
|
11414
11470
|
frameErrorRef.current = null;
|
|
@@ -11552,8 +11608,11 @@ var HeroProductImage = (0, import_react48.memo)(function HeroProductImage2({
|
|
|
11552
11608
|
lastUrlRef.current = null;
|
|
11553
11609
|
prevArtworkSrcRef.current = currentSrc;
|
|
11554
11610
|
onLoadCalledRef.current = false;
|
|
11555
|
-
|
|
11556
|
-
|
|
11611
|
+
if (artSeenRef.current) {
|
|
11612
|
+
hasReceivedRealtimeRef.current = false;
|
|
11613
|
+
realtimeArtworkSrcRef.current = void 0;
|
|
11614
|
+
}
|
|
11615
|
+
artSeenRef.current = true;
|
|
11557
11616
|
}
|
|
11558
11617
|
}, [artworkSrc, selectedArtworkSrc, placementArtKey]);
|
|
11559
11618
|
const contextSelectionRef = (0, import_react48.useRef)(context?.selection);
|
|
@@ -11708,8 +11767,9 @@ var HeroProductImage = (0, import_react48.memo)(function HeroProductImage2({
|
|
|
11708
11767
|
const topLayer = layers[layers.length - 1];
|
|
11709
11768
|
const displayUrl = topLayer?.url || realtimeUrl || initialStaticUrl;
|
|
11710
11769
|
const CROSSFADE_MS = 400;
|
|
11711
|
-
const [
|
|
11712
|
-
const
|
|
11770
|
+
const [incoming, setIncoming] = (0, import_react48.useState)(null);
|
|
11771
|
+
const incomingRef = (0, import_react48.useRef)(incoming);
|
|
11772
|
+
incomingRef.current = incoming;
|
|
11713
11773
|
const [renderedUrl, setRenderedUrl] = (0, import_react48.useState)(displayUrl);
|
|
11714
11774
|
const renderedUrlRef = (0, import_react48.useRef)(renderedUrl);
|
|
11715
11775
|
renderedUrlRef.current = renderedUrl;
|
|
@@ -11741,32 +11801,35 @@ var HeroProductImage = (0, import_react48.memo)(function HeroProductImage2({
|
|
|
11741
11801
|
setRenderedUrl(displayUrl);
|
|
11742
11802
|
return;
|
|
11743
11803
|
}
|
|
11744
|
-
const
|
|
11745
|
-
|
|
11746
|
-
|
|
11747
|
-
|
|
11748
|
-
|
|
11749
|
-
|
|
11750
|
-
|
|
11751
|
-
|
|
11752
|
-
requestAnimationFrame(() => setShowNew(true));
|
|
11753
|
-
});
|
|
11754
|
-
};
|
|
11755
|
-
if (preload.complete) startCrossfade();
|
|
11756
|
-
else preload.onload = startCrossfade;
|
|
11757
|
-
preload.onerror = () => {
|
|
11758
|
-
frameErrorRef.current = "E_FRAME_UNAVAILABLE";
|
|
11759
|
-
frameFailedRef.current?.(displayUrl);
|
|
11760
|
-
applyRenderStampRef.current?.();
|
|
11761
|
-
};
|
|
11762
|
-
return () => {
|
|
11763
|
-
preload.onload = null;
|
|
11764
|
-
preload.onerror = null;
|
|
11765
|
-
};
|
|
11804
|
+
const skipped = incomingRef.current;
|
|
11805
|
+
if (displayUrl === renderedUrlRef.current) {
|
|
11806
|
+
if (skipped && !skipped.ready) frameFailedRef.current?.(skipped.url);
|
|
11807
|
+
setIncoming(null);
|
|
11808
|
+
return;
|
|
11809
|
+
}
|
|
11810
|
+
if (skipped && !skipped.ready && skipped.url !== displayUrl) frameFailedRef.current?.(skipped.url);
|
|
11811
|
+
setIncoming({ url: displayUrl, kind: pictureSwapOf(renderedUrlRef.current, displayUrl), ready: false });
|
|
11766
11812
|
}, [displayUrl]);
|
|
11767
|
-
const
|
|
11768
|
-
|
|
11769
|
-
|
|
11813
|
+
const onIncomingError = (0, import_react48.useCallback)((url) => {
|
|
11814
|
+
if (incomingRef.current?.url !== url) return;
|
|
11815
|
+
frameErrorRef.current = "E_FRAME_UNAVAILABLE";
|
|
11816
|
+
frameFailedRef.current?.(url);
|
|
11817
|
+
applyRenderStampRef.current?.();
|
|
11818
|
+
setIncoming(null);
|
|
11819
|
+
}, []);
|
|
11820
|
+
const onIncomingLoad = (0, import_react48.useCallback)((el, url) => {
|
|
11821
|
+
(typeof el.decode === "function" ? decodedPicture(el) : Promise.resolve()).then(
|
|
11822
|
+
() => {
|
|
11823
|
+
const cur = incomingRef.current;
|
|
11824
|
+
if (!cur || cur.url !== url) return;
|
|
11825
|
+
setIncoming({ ...cur, ready: true });
|
|
11826
|
+
if (cur.kind === "instant") setRenderedUrl(url);
|
|
11827
|
+
},
|
|
11828
|
+
() => onIncomingError(url)
|
|
11829
|
+
);
|
|
11830
|
+
}, [onIncomingError]);
|
|
11831
|
+
const onIncomingShown = (0, import_react48.useCallback)((url) => {
|
|
11832
|
+
if (incomingRef.current?.url === url) setRenderedUrl(url);
|
|
11770
11833
|
}, []);
|
|
11771
11834
|
const handleLoaderExited = (0, import_react48.useCallback)(() => setLoaderMounted(false), []);
|
|
11772
11835
|
if (!hasArtwork) {
|
|
@@ -11825,6 +11888,7 @@ var HeroProductImage = (0, import_react48.memo)(function HeroProductImage2({
|
|
|
11825
11888
|
"data-picture-failed-src": failedSrc,
|
|
11826
11889
|
"data-mockup-unavailable": unavailable ? unavailable.code : void 0,
|
|
11827
11890
|
"data-design-refused": designRefused ?? void 0,
|
|
11891
|
+
"data-hero-incoming": incoming ? incoming.ready ? "showing" : "loading" : void 0,
|
|
11828
11892
|
children: [
|
|
11829
11893
|
unavailable && /* @__PURE__ */ (0, import_jsx_runtime63.jsx)(
|
|
11830
11894
|
"div",
|
|
@@ -11861,6 +11925,7 @@ var HeroProductImage = (0, import_react48.memo)(function HeroProductImage2({
|
|
|
11861
11925
|
}
|
|
11862
11926
|
onUrlGeneratedRef.current?.(renderedUrl);
|
|
11863
11927
|
if (renderedUrl) onShownRef.current?.(renderedUrl);
|
|
11928
|
+
if (renderedUrl && incomingRef.current?.url === renderedUrl) setIncoming(null);
|
|
11864
11929
|
},
|
|
11865
11930
|
onError: () => {
|
|
11866
11931
|
if (renderedUrl && retriedUrlRef.current !== renderedUrl) {
|
|
@@ -11905,7 +11970,7 @@ var HeroProductImage = (0, import_react48.memo)(function HeroProductImage2({
|
|
|
11905
11970
|
},
|
|
11906
11971
|
retryNonce
|
|
11907
11972
|
),
|
|
11908
|
-
imgFailed && !
|
|
11973
|
+
imgFailed && !incoming?.ready && /* @__PURE__ */ (0, import_jsx_runtime63.jsx)("div", { className: "absolute inset-0 flex items-center justify-center bg-muted", children: /* @__PURE__ */ (0, import_jsx_runtime63.jsx)("p", { className: "text-muted-foreground text-xs", children: unavailableText }) }),
|
|
11909
11974
|
realtimeContext?.renderError && /* @__PURE__ */ (0, import_jsx_runtime63.jsx)(
|
|
11910
11975
|
"div",
|
|
11911
11976
|
{
|
|
@@ -11916,20 +11981,26 @@ var HeroProductImage = (0, import_react48.memo)(function HeroProductImage2({
|
|
|
11916
11981
|
children: realtimeContext.renderError.retryable ? realtimeContext.renderError.message : `Render blocked: ${realtimeContext.renderError.code} \u2014 ${realtimeContext.renderError.message}`
|
|
11917
11982
|
}
|
|
11918
11983
|
),
|
|
11919
|
-
|
|
11984
|
+
incoming && /* @__PURE__ */ (0, import_jsx_runtime63.jsx)(
|
|
11920
11985
|
"img",
|
|
11921
11986
|
{
|
|
11922
11987
|
alt: "",
|
|
11988
|
+
"aria-hidden": true,
|
|
11923
11989
|
crossOrigin: "anonymous",
|
|
11924
11990
|
className: `absolute inset-0 w-full h-full ${fit === "whole" ? "object-contain" : "object-cover"}`,
|
|
11925
|
-
src:
|
|
11991
|
+
src: incoming.url,
|
|
11992
|
+
loading: "eager",
|
|
11993
|
+
decoding: "async",
|
|
11926
11994
|
style: {
|
|
11927
|
-
opacity:
|
|
11928
|
-
transition: `opacity ${CROSSFADE_MS}ms ease-in-out
|
|
11995
|
+
opacity: incoming.ready ? 1 : 0,
|
|
11996
|
+
transition: incoming.kind === "crossfade" ? `opacity ${CROSSFADE_MS}ms ease-in-out` : void 0,
|
|
11929
11997
|
pointerEvents: "none"
|
|
11930
11998
|
},
|
|
11931
|
-
|
|
11932
|
-
|
|
11999
|
+
onLoad: (e) => onIncomingLoad(e.currentTarget, incoming.url),
|
|
12000
|
+
onError: () => onIncomingError(incoming.url),
|
|
12001
|
+
onTransitionEnd: () => onIncomingShown(incoming.url)
|
|
12002
|
+
},
|
|
12003
|
+
incoming.url
|
|
11933
12004
|
),
|
|
11934
12005
|
loaderMounted && /* @__PURE__ */ (0, import_jsx_runtime63.jsx)(
|
|
11935
12006
|
LoadingOverlayPrismCandyInline,
|
|
@@ -16973,6 +17044,36 @@ function isValidImageUrl(url) {
|
|
|
16973
17044
|
return false;
|
|
16974
17045
|
}
|
|
16975
17046
|
}
|
|
17047
|
+
function anyTyped(fields, values) {
|
|
17048
|
+
return fields.some((f) => f.type === "text" && typeof values[f.name] === "string" && values[f.name].trim().length > 0);
|
|
17049
|
+
}
|
|
17050
|
+
function textValueFor(field, values, typed = false) {
|
|
17051
|
+
const v = values[field.name] ?? "";
|
|
17052
|
+
if (field.sample) return typed ? v : null;
|
|
17053
|
+
return v;
|
|
17054
|
+
}
|
|
17055
|
+
function canvasFontString(style, fontSize = style.fontSize) {
|
|
17056
|
+
return [style.italic ? "italic" : "", style.bold ? "bold" : "", `${fontSize}px`, style.fontFamily].filter(Boolean).join(" ");
|
|
17057
|
+
}
|
|
17058
|
+
var FIT_MARGIN = 0.03;
|
|
17059
|
+
function shrinkFontSizeToFit(text, style, maxWidth, measure) {
|
|
17060
|
+
const limit = maxWidth * (1 - FIT_MARGIN);
|
|
17061
|
+
if (!text || !(limit > 0)) return style.fontSize;
|
|
17062
|
+
const at = measure(text, style.fontSize);
|
|
17063
|
+
if (at <= limit) return style.fontSize;
|
|
17064
|
+
const spacing = (style.letterSpacing ?? 0) * text.length;
|
|
17065
|
+
let size = Math.max(1, style.fontSize * Math.max(1, limit - spacing) / Math.max(1, at - spacing));
|
|
17066
|
+
for (let i = 0; i < 40 && size > 1 && measure(text, size) > limit; i++) size *= 0.98;
|
|
17067
|
+
return Math.max(1, Math.floor(size * 2) / 2);
|
|
17068
|
+
}
|
|
17069
|
+
var measureCtx = null;
|
|
17070
|
+
function measureTextLine(text, style, fontSize = style.fontSize) {
|
|
17071
|
+
if (typeof document === "undefined") return 0;
|
|
17072
|
+
measureCtx ??= document.createElement("canvas").getContext("2d");
|
|
17073
|
+
if (!measureCtx) return 0;
|
|
17074
|
+
measureCtx.font = canvasFontString(style, fontSize);
|
|
17075
|
+
return measureCtx.measureText(text).width + (style.letterSpacing ?? 0) * text.length;
|
|
17076
|
+
}
|
|
16976
17077
|
function useDebouncedValue(value, delay) {
|
|
16977
17078
|
const [debounced, setDebounced] = (0, import_react70.useState)(value);
|
|
16978
17079
|
(0, import_react70.useEffect)(() => {
|
|
@@ -16999,7 +17100,7 @@ function scrollInputAboveKeyboard(input) {
|
|
|
16999
17100
|
var import_jsx_runtime91 = require("react/jsx-runtime");
|
|
17000
17101
|
function createBridgeFromCanvas(canvasModule) {
|
|
17001
17102
|
const { useEditor, useCommands, useImageBinding } = canvasModule;
|
|
17002
|
-
function TextBinder({ name, value }) {
|
|
17103
|
+
function TextBinder({ name, value, fit, sample }) {
|
|
17003
17104
|
const { elements } = useEditor();
|
|
17004
17105
|
const { executeElementUpdate } = useCommands();
|
|
17005
17106
|
const elementsRef = import_react71.default.useRef(elements);
|
|
@@ -17007,19 +17108,52 @@ function createBridgeFromCanvas(canvasModule) {
|
|
|
17007
17108
|
const executeRef = import_react71.default.useRef(executeElementUpdate);
|
|
17008
17109
|
executeRef.current = executeElementUpdate;
|
|
17009
17110
|
const hasUserInput = import_react71.default.useRef(false);
|
|
17111
|
+
const designed = import_react71.default.useRef(/* @__PURE__ */ new Map());
|
|
17010
17112
|
import_react71.default.useEffect(() => {
|
|
17011
|
-
if (value
|
|
17012
|
-
if (value === "" && !hasUserInput.current) return;
|
|
17113
|
+
if (value === null && !hasUserInput.current) return;
|
|
17114
|
+
if (value === "" && !hasUserInput.current && !sample) return;
|
|
17013
17115
|
hasUserInput.current = true;
|
|
17014
|
-
|
|
17015
|
-
|
|
17016
|
-
|
|
17017
|
-
if (!(
|
|
17018
|
-
|
|
17019
|
-
|
|
17020
|
-
|
|
17116
|
+
let cancelled = false;
|
|
17117
|
+
const bound = elementsRef.current.filter((el) => el.name === name && typeof el.setText === "function");
|
|
17118
|
+
for (const el of bound) {
|
|
17119
|
+
if (!designed.current.has(el.id)) designed.current.set(el.id, { text: typeof el.getText === "function" ? el.getText() : el.text, fontSize: el.fontSize });
|
|
17120
|
+
}
|
|
17121
|
+
const apply = (sizes) => {
|
|
17122
|
+
if (cancelled) return;
|
|
17123
|
+
const exec = executeRef.current;
|
|
17124
|
+
for (const el of elementsRef.current) {
|
|
17125
|
+
if (el.name !== name) continue;
|
|
17126
|
+
if (!("setText" in el) || typeof el.setText !== "function") continue;
|
|
17127
|
+
const own = designed.current.get(el.id);
|
|
17128
|
+
const cloned = el.clone();
|
|
17129
|
+
cloned.setText(value ?? own?.text ?? "");
|
|
17130
|
+
const size = value === null ? own?.fontSize : sizes.get(el.id);
|
|
17131
|
+
if (size !== void 0) cloned.fontSize = size;
|
|
17132
|
+
exec(el, cloned);
|
|
17133
|
+
}
|
|
17134
|
+
};
|
|
17135
|
+
if (fit !== "shrink" || value === null) {
|
|
17136
|
+
apply(/* @__PURE__ */ new Map());
|
|
17137
|
+
return () => {
|
|
17138
|
+
cancelled = true;
|
|
17139
|
+
};
|
|
17021
17140
|
}
|
|
17022
|
-
|
|
17141
|
+
const styled = bound.map((el) => {
|
|
17142
|
+
const style = { fontSize: designed.current.get(el.id).fontSize, fontFamily: el.fontFamily, bold: el.bold, italic: el.italic, letterSpacing: el.letterSpacing };
|
|
17143
|
+
return { id: el.id, style, boxWidth: Number(el.transformData?.width) || 0 };
|
|
17144
|
+
});
|
|
17145
|
+
const fonts = typeof document !== "undefined" && document.fonts ? Promise.all(styled.map((st) => document.fonts.load(canvasFontString(st.style)).catch(() => []))) : Promise.resolve([]);
|
|
17146
|
+
void fonts.then(() => {
|
|
17147
|
+
const sizes = /* @__PURE__ */ new Map();
|
|
17148
|
+
for (const st of styled) {
|
|
17149
|
+
sizes.set(st.id, st.boxWidth > 0 ? shrinkFontSizeToFit(value, st.style, st.boxWidth, (t, size) => measureTextLine(t, st.style, size)) : st.style.fontSize);
|
|
17150
|
+
}
|
|
17151
|
+
apply(sizes);
|
|
17152
|
+
});
|
|
17153
|
+
return () => {
|
|
17154
|
+
cancelled = true;
|
|
17155
|
+
};
|
|
17156
|
+
}, [value, name, fit, sample, elements.length]);
|
|
17023
17157
|
return null;
|
|
17024
17158
|
}
|
|
17025
17159
|
function ColorBinder({ originalColor, newColor }) {
|
|
@@ -17084,9 +17218,10 @@ function createBridgeFromCanvas(canvasModule) {
|
|
|
17084
17218
|
return null;
|
|
17085
17219
|
}
|
|
17086
17220
|
return function PersonalizationBridge({ fields = [], values = {} } = {}) {
|
|
17221
|
+
const typed = anyTyped(fields, values);
|
|
17087
17222
|
return /* @__PURE__ */ (0, import_jsx_runtime91.jsx)(import_jsx_runtime91.Fragment, { children: fields.map((field) => {
|
|
17088
17223
|
if (field.type === "text") {
|
|
17089
|
-
return /* @__PURE__ */ (0, import_jsx_runtime91.jsx)(TextBinder, { name: field.name, value: values
|
|
17224
|
+
return /* @__PURE__ */ (0, import_jsx_runtime91.jsx)(TextBinder, { name: field.name, value: textValueFor(field, values, typed), fit: field.fit, sample: field.sample }, `text-${field.name}`);
|
|
17090
17225
|
}
|
|
17091
17226
|
if (field.type === "color") {
|
|
17092
17227
|
return /* @__PURE__ */ (0, import_jsx_runtime91.jsx)(ColorBinder, { originalColor: field.color, newColor: values[field.color] ?? field.color }, `color-${field.color}`);
|
|
@@ -17098,6 +17233,7 @@ function createBridgeFromCanvas(canvasModule) {
|
|
|
17098
17233
|
}) });
|
|
17099
17234
|
};
|
|
17100
17235
|
}
|
|
17236
|
+
var PERSONALIZATION_EXPORT_DEBOUNCE_MS = 250;
|
|
17101
17237
|
var cachedCanvasComponent = null;
|
|
17102
17238
|
var cachedBridgeComponent = null;
|
|
17103
17239
|
var cachedSerialize = null;
|
|
@@ -17156,10 +17292,30 @@ function PersonalizationProvider({
|
|
|
17156
17292
|
}
|
|
17157
17293
|
};
|
|
17158
17294
|
}, []);
|
|
17295
|
+
const canvasRef = (0, import_react71.useRef)(null);
|
|
17296
|
+
const lastChangeAtRef = (0, import_react71.useRef)(0);
|
|
17297
|
+
const lastExportAtRef = (0, import_react71.useRef)(0);
|
|
17159
17298
|
const updateField = (0, import_react71.useCallback)((key, value) => {
|
|
17160
17299
|
setIsActive(true);
|
|
17300
|
+
lastChangeAtRef.current = Date.now();
|
|
17161
17301
|
setPersonValues((prev) => ({ ...prev, [key]: value }));
|
|
17162
17302
|
}, []);
|
|
17303
|
+
const settleMs = (exportConfig?.debounceMs ?? PERSONALIZATION_EXPORT_DEBOUNCE_MS) + (exportConfig?.maxWaitMs ?? 1e3) + 300;
|
|
17304
|
+
(0, import_react71.useEffect)(() => {
|
|
17305
|
+
if (!isActive || lastChangeAtRef.current === 0) return;
|
|
17306
|
+
const changedAt = lastChangeAtRef.current;
|
|
17307
|
+
const timer = setTimeout(() => {
|
|
17308
|
+
if (lastExportAtRef.current >= changedAt) return;
|
|
17309
|
+
const exportArtboards = canvasRef.current?.exportArtboards;
|
|
17310
|
+
if (!exportArtboards) return;
|
|
17311
|
+
void exportArtboards({ format: "blob", scale: exportConfig?.scale ?? 1, all: false }).then((exports2) => {
|
|
17312
|
+
if (lastChangeAtRef.current !== changedAt || lastExportAtRef.current >= changedAt) return;
|
|
17313
|
+
if (exports2 && Object.keys(exports2).length > 0) handleExportRef.current?.(exports2);
|
|
17314
|
+
}).catch(() => {
|
|
17315
|
+
});
|
|
17316
|
+
}, settleMs);
|
|
17317
|
+
return () => clearTimeout(timer);
|
|
17318
|
+
}, [personValues, isActive, settleMs, exportConfig?.scale]);
|
|
17163
17319
|
const reset = (0, import_react71.useCallback)(() => {
|
|
17164
17320
|
setPersonValues({});
|
|
17165
17321
|
setIsActive(false);
|
|
@@ -17167,6 +17323,7 @@ function PersonalizationProvider({
|
|
|
17167
17323
|
}, []);
|
|
17168
17324
|
const handleExport = (0, import_react71.useCallback)(
|
|
17169
17325
|
(exports2) => {
|
|
17326
|
+
lastExportAtRef.current = Date.now();
|
|
17170
17327
|
const newUrls = {};
|
|
17171
17328
|
for (const [name, data] of Object.entries(exports2)) {
|
|
17172
17329
|
if (blobUrlsRef.current[name]) {
|
|
@@ -17199,6 +17356,10 @@ function PersonalizationProvider({
|
|
|
17199
17356
|
},
|
|
17200
17357
|
[realtime, placementOverride]
|
|
17201
17358
|
);
|
|
17359
|
+
const handleExportRef = (0, import_react71.useRef)(null);
|
|
17360
|
+
(0, import_react71.useEffect)(() => {
|
|
17361
|
+
handleExportRef.current = handleExport;
|
|
17362
|
+
}, [handleExport]);
|
|
17202
17363
|
const handleExportScheduled = (0, import_react71.useCallback)(() => {
|
|
17203
17364
|
setIsExporting(true);
|
|
17204
17365
|
}, []);
|
|
@@ -17233,13 +17394,16 @@ function PersonalizationProvider({
|
|
|
17233
17394
|
children: /* @__PURE__ */ (0, import_jsx_runtime91.jsx)(
|
|
17234
17395
|
CanvasComponent,
|
|
17235
17396
|
{
|
|
17397
|
+
ref: canvasRef,
|
|
17236
17398
|
initialElements: canvasState?.elements,
|
|
17237
17399
|
artboards: canvasState?.artboards,
|
|
17238
17400
|
kit: "embed-only",
|
|
17239
17401
|
inheritTheme: true,
|
|
17240
17402
|
autoExportConfig: {
|
|
17241
17403
|
enabled: true,
|
|
17242
|
-
|
|
17404
|
+
// Typing cadence (~100-200 ms a key): one render per pause, not one per key (each render is a new picture
|
|
17405
|
+
// on every mockup); maxWaitMs still shows progress during a long burst.
|
|
17406
|
+
debounceMs: exportConfig?.debounceMs ?? PERSONALIZATION_EXPORT_DEBOUNCE_MS,
|
|
17243
17407
|
maxWaitMs: exportConfig?.maxWaitMs ?? 1e3
|
|
17244
17408
|
},
|
|
17245
17409
|
autoExportFormat: "blob",
|
|
@@ -17304,7 +17468,9 @@ function PersonalizationInputs({
|
|
|
17304
17468
|
"input",
|
|
17305
17469
|
{
|
|
17306
17470
|
type: "text",
|
|
17471
|
+
"aria-label": field.label,
|
|
17307
17472
|
placeholder: field.placeholder || field.label,
|
|
17473
|
+
maxLength: field.maxLength,
|
|
17308
17474
|
value: personValues[field.name] ?? "",
|
|
17309
17475
|
onChange: (e) => updateField(field.name, e.target.value),
|
|
17310
17476
|
onFocus: handleFocus,
|
|
@@ -17505,6 +17671,7 @@ function usePersonalizationShimmer(containerRef, safetyTimeoutMs = 1e4) {
|
|
|
17505
17671
|
FACET_SECTIONS,
|
|
17506
17672
|
FIRST_VIEW_MARGIN,
|
|
17507
17673
|
FIRST_VIEW_PICTURE_ASPECT,
|
|
17674
|
+
FIT_MARGIN,
|
|
17508
17675
|
Fieldset,
|
|
17509
17676
|
Filters,
|
|
17510
17677
|
FiltersButton,
|
|
@@ -17626,15 +17793,18 @@ function usePersonalizationShimmer(containerRef, safetyTimeoutMs = 1e4) {
|
|
|
17626
17793
|
UiRouterProvider,
|
|
17627
17794
|
VISIBILITY_THRESHOLDS,
|
|
17628
17795
|
ZoomOverlay,
|
|
17796
|
+
anyTyped,
|
|
17629
17797
|
badgeVariants,
|
|
17630
17798
|
blockingSessionError,
|
|
17631
17799
|
brandAssets,
|
|
17632
17800
|
buttonVariants,
|
|
17633
17801
|
canvasExportService,
|
|
17802
|
+
canvasFontString,
|
|
17634
17803
|
checkComponentStyles,
|
|
17635
17804
|
checkTailwindConfig,
|
|
17636
17805
|
checkThemeTokens,
|
|
17637
17806
|
createScrollDirectionTracker,
|
|
17807
|
+
decodedPicture,
|
|
17638
17808
|
describeProductArtAlignment,
|
|
17639
17809
|
firstView,
|
|
17640
17810
|
firstViewAnchorOfSlide,
|
|
@@ -17657,17 +17827,21 @@ function usePersonalizationShimmer(containerRef, safetyTimeoutMs = 1e4) {
|
|
|
17657
17827
|
linkVariants,
|
|
17658
17828
|
linkedPlacementsLabel,
|
|
17659
17829
|
listProducts,
|
|
17830
|
+
measureTextLine,
|
|
17660
17831
|
normalizeHex,
|
|
17661
17832
|
observe,
|
|
17662
17833
|
pictureRenderState,
|
|
17834
|
+
pictureSwapOf,
|
|
17663
17835
|
placementArtFor,
|
|
17664
17836
|
runConfigChecks,
|
|
17665
17837
|
scrollInputAboveKeyboard,
|
|
17666
17838
|
searchClient,
|
|
17839
|
+
shrinkFontSizeToFit,
|
|
17667
17840
|
slideFirstViewFields,
|
|
17668
17841
|
slideFirstViewProps,
|
|
17669
17842
|
spinnerVariants,
|
|
17670
17843
|
surfaceVariants,
|
|
17844
|
+
textValueFor,
|
|
17671
17845
|
useArtworkAlignment,
|
|
17672
17846
|
useBrand,
|
|
17673
17847
|
useCanvasContext,
|