@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.js
CHANGED
|
@@ -7,11 +7,17 @@ import {
|
|
|
7
7
|
getThemeVariant
|
|
8
8
|
} from "./chunk-YYDBUSLM.js";
|
|
9
9
|
import {
|
|
10
|
+
FIT_MARGIN,
|
|
11
|
+
anyTyped,
|
|
12
|
+
canvasFontString,
|
|
10
13
|
isValidImageUrl,
|
|
14
|
+
measureTextLine,
|
|
11
15
|
normalizeHex,
|
|
12
16
|
scrollInputAboveKeyboard,
|
|
17
|
+
shrinkFontSizeToFit,
|
|
18
|
+
textValueFor,
|
|
13
19
|
useDebouncedValue
|
|
14
|
-
} from "./chunk-
|
|
20
|
+
} from "./chunk-GY6TC6M6.js";
|
|
15
21
|
import {
|
|
16
22
|
UiRouterProvider,
|
|
17
23
|
useUiRouter,
|
|
@@ -6003,6 +6009,8 @@ function RealtimeProvider({
|
|
|
6003
6009
|
const rerenderTimerRef = useRef12(null);
|
|
6004
6010
|
const fullFrameRerenderIdsRef = useRef12(/* @__PURE__ */ new Set());
|
|
6005
6011
|
const fullFrameRerenderTimerRef = useRef12(null);
|
|
6012
|
+
const rerenderFullFrameRef = useRef12(null);
|
|
6013
|
+
const lostFrameAskedRef = useRef12(/* @__PURE__ */ new Set());
|
|
6006
6014
|
useEffect17(
|
|
6007
6015
|
() => () => {
|
|
6008
6016
|
if (fullFrameRerenderTimerRef.current) clearTimeout(fullFrameRerenderTimerRef.current);
|
|
@@ -6054,6 +6062,7 @@ function RealtimeProvider({
|
|
|
6054
6062
|
}, [revokeBlobUrl]);
|
|
6055
6063
|
const markBlobShown = useCallback10((owner, url, consumer = "default") => {
|
|
6056
6064
|
ackUrl(url);
|
|
6065
|
+
lostFrameAskedRef.current.delete(owner);
|
|
6057
6066
|
const list = blobsByOwnerRef.current.get(owner);
|
|
6058
6067
|
if (!list || list.indexOf(url) < 0) return;
|
|
6059
6068
|
const shown = shownBlobByOwnerRef.current.get(owner) ?? /* @__PURE__ */ new Map();
|
|
@@ -6063,6 +6072,22 @@ function RealtimeProvider({
|
|
|
6063
6072
|
}, [releaseOlderFrames, ackUrl]);
|
|
6064
6073
|
const frameFailed = useCallback10((url) => {
|
|
6065
6074
|
ackUrl(url);
|
|
6075
|
+
if (!url.startsWith("blob:")) return;
|
|
6076
|
+
let mockupId;
|
|
6077
|
+
mockupUrlCacheRef.current.forEach((entry, id) => {
|
|
6078
|
+
if (entry.url === url) mockupId = id;
|
|
6079
|
+
});
|
|
6080
|
+
if (!mockupId) return;
|
|
6081
|
+
if (pendingMockupIdsRef.current.has(mockupId)) return;
|
|
6082
|
+
if (compositeQueueRef.current.has(mockupId) || compositeBusyRef.current.has(mockupId)) return;
|
|
6083
|
+
if (lostFrameAskedRef.current.has(mockupId)) return;
|
|
6084
|
+
lostFrameAskedRef.current.add(mockupId);
|
|
6085
|
+
console.error(
|
|
6086
|
+
`[RealtimeProvider] E_FRAME_LOST: ${mockupId}'s newest frame could not be loaded (gone before any element drew it); re-rendering that picture.`
|
|
6087
|
+
);
|
|
6088
|
+
mockupUrlCacheRef.current.delete(mockupId);
|
|
6089
|
+
mockupResultsRef.current = mockupResultsRef.current.filter((r) => r.imageUrl !== url);
|
|
6090
|
+
rerenderFullFrameRef.current?.(mockupId);
|
|
6066
6091
|
}, [ackUrl]);
|
|
6067
6092
|
const releaseBlobConsumer = useCallback10((owner, consumer) => {
|
|
6068
6093
|
const shown = shownBlobByOwnerRef.current.get(owner);
|
|
@@ -6169,6 +6194,7 @@ function RealtimeProvider({
|
|
|
6169
6194
|
},
|
|
6170
6195
|
[sendFullFrameConfig, forceRerenderByConfig, sendRerenderPaced]
|
|
6171
6196
|
);
|
|
6197
|
+
rerenderFullFrameRef.current = rerenderFullFrame;
|
|
6172
6198
|
const maybeFlipCrop = useCallback10(() => {
|
|
6173
6199
|
if (!croppedDeliveryEnabled || !cropCapableRef.current) return;
|
|
6174
6200
|
if (croppedActiveRef.current) return;
|
|
@@ -10741,6 +10767,23 @@ function heroSize(stripView, cropWidth, width) {
|
|
|
10741
10767
|
if (isCrop(stripView)) return cropWidth !== void 0 ? { stripView, width: cropWidth } : { stripView };
|
|
10742
10768
|
return { width };
|
|
10743
10769
|
}
|
|
10770
|
+
function pictureSwapOf(shownUrl, nextUrl) {
|
|
10771
|
+
if (!shownUrl) return "instant";
|
|
10772
|
+
return nextUrl.startsWith("blob:") || shownUrl.startsWith("blob:") ? "instant" : "crossfade";
|
|
10773
|
+
}
|
|
10774
|
+
function decodedPicture(img) {
|
|
10775
|
+
if (typeof img.decode === "function") {
|
|
10776
|
+
return img.decode().catch((e) => {
|
|
10777
|
+
if (img.complete && img.naturalWidth > 0) return;
|
|
10778
|
+
throw e;
|
|
10779
|
+
});
|
|
10780
|
+
}
|
|
10781
|
+
return new Promise((resolve, reject) => {
|
|
10782
|
+
if (img.complete) return resolve();
|
|
10783
|
+
img.onload = () => resolve();
|
|
10784
|
+
img.onerror = () => reject(new Error("E_FRAME_UNAVAILABLE"));
|
|
10785
|
+
});
|
|
10786
|
+
}
|
|
10744
10787
|
var EMPTY_IMAGES = [];
|
|
10745
10788
|
var DESIGN_BUSY_RETRY_MS = 1500;
|
|
10746
10789
|
function blockingSessionError(error) {
|
|
@@ -10905,7 +10948,13 @@ var HeroProductImage = memo3(function HeroProductImage2({
|
|
|
10905
10948
|
const priorityRegisteredRef = useRef24(false);
|
|
10906
10949
|
const onLoadCalledRef = useRef24(false);
|
|
10907
10950
|
const prevArtworkSrcRef = useRef24(void 0);
|
|
10908
|
-
const
|
|
10951
|
+
const artIdentityRef = useRef24(void 0);
|
|
10952
|
+
artIdentityRef.current = artIdentity(artworkSrc || selectedArtworkSrc, placementArtKey);
|
|
10953
|
+
const mountedOnLiveFrame = !!realtimeUrl && (realtimeUrl.startsWith("blob:") || !!actualMockupId && realtimeUrl === realtimeContext?.getMockupUrl?.(actualMockupId));
|
|
10954
|
+
const realtimeArtworkSrcRef = useRef24(
|
|
10955
|
+
mountedOnLiveFrame ? artIdentity(artworkSrc || selectedArtworkSrc, placementArtKey) : void 0
|
|
10956
|
+
);
|
|
10957
|
+
const artSeenRef = useRef24(false);
|
|
10909
10958
|
const hasReceivedRealtimeRef = useRef24(false);
|
|
10910
10959
|
const isPendingExportRef = useRef24(false);
|
|
10911
10960
|
const onUrlGeneratedRef = useRef24(onUrlGenerated);
|
|
@@ -10964,6 +11013,7 @@ var HeroProductImage = memo3(function HeroProductImage2({
|
|
|
10964
11013
|
const handleMockupResult = (result) => {
|
|
10965
11014
|
if (!result?.imageUrl) return;
|
|
10966
11015
|
hasReceivedRealtimeRef.current = true;
|
|
11016
|
+
realtimeArtworkSrcRef.current = artIdentityRef.current;
|
|
10967
11017
|
isPendingExportRef.current = false;
|
|
10968
11018
|
const cachedUrl = realtimeContext.getMockupUrl(result.mockupId);
|
|
10969
11019
|
if (!cachedUrl) return;
|
|
@@ -11015,7 +11065,11 @@ var HeroProductImage = memo3(function HeroProductImage2({
|
|
|
11015
11065
|
const frameErrorRef = useRef24(null);
|
|
11016
11066
|
const showVersionOf = useCallback19((url) => {
|
|
11017
11067
|
const e = versionByUrlRef.current.get(url);
|
|
11018
|
-
if (!e
|
|
11068
|
+
if (!e) {
|
|
11069
|
+
renderVersionRef.current = 0;
|
|
11070
|
+
renderVersionsRef.current = null;
|
|
11071
|
+
return;
|
|
11072
|
+
}
|
|
11019
11073
|
renderVersionRef.current = e.v;
|
|
11020
11074
|
renderVersionsRef.current = e.versions;
|
|
11021
11075
|
frameErrorRef.current = null;
|
|
@@ -11159,8 +11213,11 @@ var HeroProductImage = memo3(function HeroProductImage2({
|
|
|
11159
11213
|
lastUrlRef.current = null;
|
|
11160
11214
|
prevArtworkSrcRef.current = currentSrc;
|
|
11161
11215
|
onLoadCalledRef.current = false;
|
|
11162
|
-
|
|
11163
|
-
|
|
11216
|
+
if (artSeenRef.current) {
|
|
11217
|
+
hasReceivedRealtimeRef.current = false;
|
|
11218
|
+
realtimeArtworkSrcRef.current = void 0;
|
|
11219
|
+
}
|
|
11220
|
+
artSeenRef.current = true;
|
|
11164
11221
|
}
|
|
11165
11222
|
}, [artworkSrc, selectedArtworkSrc, placementArtKey]);
|
|
11166
11223
|
const contextSelectionRef = useRef24(context?.selection);
|
|
@@ -11315,8 +11372,9 @@ var HeroProductImage = memo3(function HeroProductImage2({
|
|
|
11315
11372
|
const topLayer = layers[layers.length - 1];
|
|
11316
11373
|
const displayUrl = topLayer?.url || realtimeUrl || initialStaticUrl;
|
|
11317
11374
|
const CROSSFADE_MS = 400;
|
|
11318
|
-
const [
|
|
11319
|
-
const
|
|
11375
|
+
const [incoming, setIncoming] = useState32(null);
|
|
11376
|
+
const incomingRef = useRef24(incoming);
|
|
11377
|
+
incomingRef.current = incoming;
|
|
11320
11378
|
const [renderedUrl, setRenderedUrl] = useState32(displayUrl);
|
|
11321
11379
|
const renderedUrlRef = useRef24(renderedUrl);
|
|
11322
11380
|
renderedUrlRef.current = renderedUrl;
|
|
@@ -11348,32 +11406,35 @@ var HeroProductImage = memo3(function HeroProductImage2({
|
|
|
11348
11406
|
setRenderedUrl(displayUrl);
|
|
11349
11407
|
return;
|
|
11350
11408
|
}
|
|
11351
|
-
const
|
|
11352
|
-
|
|
11353
|
-
|
|
11354
|
-
|
|
11355
|
-
|
|
11356
|
-
|
|
11357
|
-
|
|
11358
|
-
|
|
11359
|
-
requestAnimationFrame(() => setShowNew(true));
|
|
11360
|
-
});
|
|
11361
|
-
};
|
|
11362
|
-
if (preload.complete) startCrossfade();
|
|
11363
|
-
else preload.onload = startCrossfade;
|
|
11364
|
-
preload.onerror = () => {
|
|
11365
|
-
frameErrorRef.current = "E_FRAME_UNAVAILABLE";
|
|
11366
|
-
frameFailedRef.current?.(displayUrl);
|
|
11367
|
-
applyRenderStampRef.current?.();
|
|
11368
|
-
};
|
|
11369
|
-
return () => {
|
|
11370
|
-
preload.onload = null;
|
|
11371
|
-
preload.onerror = null;
|
|
11372
|
-
};
|
|
11409
|
+
const skipped = incomingRef.current;
|
|
11410
|
+
if (displayUrl === renderedUrlRef.current) {
|
|
11411
|
+
if (skipped && !skipped.ready) frameFailedRef.current?.(skipped.url);
|
|
11412
|
+
setIncoming(null);
|
|
11413
|
+
return;
|
|
11414
|
+
}
|
|
11415
|
+
if (skipped && !skipped.ready && skipped.url !== displayUrl) frameFailedRef.current?.(skipped.url);
|
|
11416
|
+
setIncoming({ url: displayUrl, kind: pictureSwapOf(renderedUrlRef.current, displayUrl), ready: false });
|
|
11373
11417
|
}, [displayUrl]);
|
|
11374
|
-
const
|
|
11375
|
-
|
|
11376
|
-
|
|
11418
|
+
const onIncomingError = useCallback19((url) => {
|
|
11419
|
+
if (incomingRef.current?.url !== url) return;
|
|
11420
|
+
frameErrorRef.current = "E_FRAME_UNAVAILABLE";
|
|
11421
|
+
frameFailedRef.current?.(url);
|
|
11422
|
+
applyRenderStampRef.current?.();
|
|
11423
|
+
setIncoming(null);
|
|
11424
|
+
}, []);
|
|
11425
|
+
const onIncomingLoad = useCallback19((el, url) => {
|
|
11426
|
+
(typeof el.decode === "function" ? decodedPicture(el) : Promise.resolve()).then(
|
|
11427
|
+
() => {
|
|
11428
|
+
const cur = incomingRef.current;
|
|
11429
|
+
if (!cur || cur.url !== url) return;
|
|
11430
|
+
setIncoming({ ...cur, ready: true });
|
|
11431
|
+
if (cur.kind === "instant") setRenderedUrl(url);
|
|
11432
|
+
},
|
|
11433
|
+
() => onIncomingError(url)
|
|
11434
|
+
);
|
|
11435
|
+
}, [onIncomingError]);
|
|
11436
|
+
const onIncomingShown = useCallback19((url) => {
|
|
11437
|
+
if (incomingRef.current?.url === url) setRenderedUrl(url);
|
|
11377
11438
|
}, []);
|
|
11378
11439
|
const handleLoaderExited = useCallback19(() => setLoaderMounted(false), []);
|
|
11379
11440
|
if (!hasArtwork) {
|
|
@@ -11432,6 +11493,7 @@ var HeroProductImage = memo3(function HeroProductImage2({
|
|
|
11432
11493
|
"data-picture-failed-src": failedSrc,
|
|
11433
11494
|
"data-mockup-unavailable": unavailable ? unavailable.code : void 0,
|
|
11434
11495
|
"data-design-refused": designRefused ?? void 0,
|
|
11496
|
+
"data-hero-incoming": incoming ? incoming.ready ? "showing" : "loading" : void 0,
|
|
11435
11497
|
children: [
|
|
11436
11498
|
unavailable && /* @__PURE__ */ jsx63(
|
|
11437
11499
|
"div",
|
|
@@ -11468,6 +11530,7 @@ var HeroProductImage = memo3(function HeroProductImage2({
|
|
|
11468
11530
|
}
|
|
11469
11531
|
onUrlGeneratedRef.current?.(renderedUrl);
|
|
11470
11532
|
if (renderedUrl) onShownRef.current?.(renderedUrl);
|
|
11533
|
+
if (renderedUrl && incomingRef.current?.url === renderedUrl) setIncoming(null);
|
|
11471
11534
|
},
|
|
11472
11535
|
onError: () => {
|
|
11473
11536
|
if (renderedUrl && retriedUrlRef.current !== renderedUrl) {
|
|
@@ -11512,7 +11575,7 @@ var HeroProductImage = memo3(function HeroProductImage2({
|
|
|
11512
11575
|
},
|
|
11513
11576
|
retryNonce
|
|
11514
11577
|
),
|
|
11515
|
-
imgFailed && !
|
|
11578
|
+
imgFailed && !incoming?.ready && /* @__PURE__ */ jsx63("div", { className: "absolute inset-0 flex items-center justify-center bg-muted", children: /* @__PURE__ */ jsx63("p", { className: "text-muted-foreground text-xs", children: unavailableText }) }),
|
|
11516
11579
|
realtimeContext?.renderError && /* @__PURE__ */ jsx63(
|
|
11517
11580
|
"div",
|
|
11518
11581
|
{
|
|
@@ -11523,20 +11586,26 @@ var HeroProductImage = memo3(function HeroProductImage2({
|
|
|
11523
11586
|
children: realtimeContext.renderError.retryable ? realtimeContext.renderError.message : `Render blocked: ${realtimeContext.renderError.code} \u2014 ${realtimeContext.renderError.message}`
|
|
11524
11587
|
}
|
|
11525
11588
|
),
|
|
11526
|
-
|
|
11589
|
+
incoming && /* @__PURE__ */ jsx63(
|
|
11527
11590
|
"img",
|
|
11528
11591
|
{
|
|
11529
11592
|
alt: "",
|
|
11593
|
+
"aria-hidden": true,
|
|
11530
11594
|
crossOrigin: "anonymous",
|
|
11531
11595
|
className: `absolute inset-0 w-full h-full ${fit === "whole" ? "object-contain" : "object-cover"}`,
|
|
11532
|
-
src:
|
|
11596
|
+
src: incoming.url,
|
|
11597
|
+
loading: "eager",
|
|
11598
|
+
decoding: "async",
|
|
11533
11599
|
style: {
|
|
11534
|
-
opacity:
|
|
11535
|
-
transition: `opacity ${CROSSFADE_MS}ms ease-in-out
|
|
11600
|
+
opacity: incoming.ready ? 1 : 0,
|
|
11601
|
+
transition: incoming.kind === "crossfade" ? `opacity ${CROSSFADE_MS}ms ease-in-out` : void 0,
|
|
11536
11602
|
pointerEvents: "none"
|
|
11537
11603
|
},
|
|
11538
|
-
|
|
11539
|
-
|
|
11604
|
+
onLoad: (e) => onIncomingLoad(e.currentTarget, incoming.url),
|
|
11605
|
+
onError: () => onIncomingError(incoming.url),
|
|
11606
|
+
onTransitionEnd: () => onIncomingShown(incoming.url)
|
|
11607
|
+
},
|
|
11608
|
+
incoming.url
|
|
11540
11609
|
),
|
|
11541
11610
|
loaderMounted && /* @__PURE__ */ jsx63(
|
|
11542
11611
|
LoadingOverlayPrismCandyInline,
|
|
@@ -15417,7 +15486,7 @@ function usePersonalizationContext() {
|
|
|
15417
15486
|
import { Fragment as Fragment21, jsx as jsx91, jsxs as jsxs62 } from "react/jsx-runtime";
|
|
15418
15487
|
function createBridgeFromCanvas(canvasModule) {
|
|
15419
15488
|
const { useEditor, useCommands, useImageBinding } = canvasModule;
|
|
15420
|
-
function TextBinder({ name, value }) {
|
|
15489
|
+
function TextBinder({ name, value, fit, sample }) {
|
|
15421
15490
|
const { elements } = useEditor();
|
|
15422
15491
|
const { executeElementUpdate } = useCommands();
|
|
15423
15492
|
const elementsRef = React58.useRef(elements);
|
|
@@ -15425,19 +15494,52 @@ function createBridgeFromCanvas(canvasModule) {
|
|
|
15425
15494
|
const executeRef = React58.useRef(executeElementUpdate);
|
|
15426
15495
|
executeRef.current = executeElementUpdate;
|
|
15427
15496
|
const hasUserInput = React58.useRef(false);
|
|
15497
|
+
const designed = React58.useRef(/* @__PURE__ */ new Map());
|
|
15428
15498
|
React58.useEffect(() => {
|
|
15429
|
-
if (value
|
|
15430
|
-
if (value === "" && !hasUserInput.current) return;
|
|
15499
|
+
if (value === null && !hasUserInput.current) return;
|
|
15500
|
+
if (value === "" && !hasUserInput.current && !sample) return;
|
|
15431
15501
|
hasUserInput.current = true;
|
|
15432
|
-
|
|
15433
|
-
|
|
15434
|
-
|
|
15435
|
-
if (!(
|
|
15436
|
-
|
|
15437
|
-
|
|
15438
|
-
|
|
15502
|
+
let cancelled = false;
|
|
15503
|
+
const bound = elementsRef.current.filter((el) => el.name === name && typeof el.setText === "function");
|
|
15504
|
+
for (const el of bound) {
|
|
15505
|
+
if (!designed.current.has(el.id)) designed.current.set(el.id, { text: typeof el.getText === "function" ? el.getText() : el.text, fontSize: el.fontSize });
|
|
15506
|
+
}
|
|
15507
|
+
const apply = (sizes) => {
|
|
15508
|
+
if (cancelled) return;
|
|
15509
|
+
const exec = executeRef.current;
|
|
15510
|
+
for (const el of elementsRef.current) {
|
|
15511
|
+
if (el.name !== name) continue;
|
|
15512
|
+
if (!("setText" in el) || typeof el.setText !== "function") continue;
|
|
15513
|
+
const own = designed.current.get(el.id);
|
|
15514
|
+
const cloned = el.clone();
|
|
15515
|
+
cloned.setText(value ?? own?.text ?? "");
|
|
15516
|
+
const size = value === null ? own?.fontSize : sizes.get(el.id);
|
|
15517
|
+
if (size !== void 0) cloned.fontSize = size;
|
|
15518
|
+
exec(el, cloned);
|
|
15519
|
+
}
|
|
15520
|
+
};
|
|
15521
|
+
if (fit !== "shrink" || value === null) {
|
|
15522
|
+
apply(/* @__PURE__ */ new Map());
|
|
15523
|
+
return () => {
|
|
15524
|
+
cancelled = true;
|
|
15525
|
+
};
|
|
15439
15526
|
}
|
|
15440
|
-
|
|
15527
|
+
const styled = bound.map((el) => {
|
|
15528
|
+
const style = { fontSize: designed.current.get(el.id).fontSize, fontFamily: el.fontFamily, bold: el.bold, italic: el.italic, letterSpacing: el.letterSpacing };
|
|
15529
|
+
return { id: el.id, style, boxWidth: Number(el.transformData?.width) || 0 };
|
|
15530
|
+
});
|
|
15531
|
+
const fonts = typeof document !== "undefined" && document.fonts ? Promise.all(styled.map((st) => document.fonts.load(canvasFontString(st.style)).catch(() => []))) : Promise.resolve([]);
|
|
15532
|
+
void fonts.then(() => {
|
|
15533
|
+
const sizes = /* @__PURE__ */ new Map();
|
|
15534
|
+
for (const st of styled) {
|
|
15535
|
+
sizes.set(st.id, st.boxWidth > 0 ? shrinkFontSizeToFit(value, st.style, st.boxWidth, (t, size) => measureTextLine(t, st.style, size)) : st.style.fontSize);
|
|
15536
|
+
}
|
|
15537
|
+
apply(sizes);
|
|
15538
|
+
});
|
|
15539
|
+
return () => {
|
|
15540
|
+
cancelled = true;
|
|
15541
|
+
};
|
|
15542
|
+
}, [value, name, fit, sample, elements.length]);
|
|
15441
15543
|
return null;
|
|
15442
15544
|
}
|
|
15443
15545
|
function ColorBinder({ originalColor, newColor }) {
|
|
@@ -15502,9 +15604,10 @@ function createBridgeFromCanvas(canvasModule) {
|
|
|
15502
15604
|
return null;
|
|
15503
15605
|
}
|
|
15504
15606
|
return function PersonalizationBridge({ fields = [], values = {} } = {}) {
|
|
15607
|
+
const typed = anyTyped(fields, values);
|
|
15505
15608
|
return /* @__PURE__ */ jsx91(Fragment21, { children: fields.map((field) => {
|
|
15506
15609
|
if (field.type === "text") {
|
|
15507
|
-
return /* @__PURE__ */ jsx91(TextBinder, { name: field.name, value: values
|
|
15610
|
+
return /* @__PURE__ */ jsx91(TextBinder, { name: field.name, value: textValueFor(field, values, typed), fit: field.fit, sample: field.sample }, `text-${field.name}`);
|
|
15508
15611
|
}
|
|
15509
15612
|
if (field.type === "color") {
|
|
15510
15613
|
return /* @__PURE__ */ jsx91(ColorBinder, { originalColor: field.color, newColor: values[field.color] ?? field.color }, `color-${field.color}`);
|
|
@@ -15516,6 +15619,7 @@ function createBridgeFromCanvas(canvasModule) {
|
|
|
15516
15619
|
}) });
|
|
15517
15620
|
};
|
|
15518
15621
|
}
|
|
15622
|
+
var PERSONALIZATION_EXPORT_DEBOUNCE_MS = 250;
|
|
15519
15623
|
var cachedCanvasComponent = null;
|
|
15520
15624
|
var cachedBridgeComponent = null;
|
|
15521
15625
|
var cachedSerialize = null;
|
|
@@ -15574,10 +15678,30 @@ function PersonalizationProvider({
|
|
|
15574
15678
|
}
|
|
15575
15679
|
};
|
|
15576
15680
|
}, []);
|
|
15681
|
+
const canvasRef = useRef31(null);
|
|
15682
|
+
const lastChangeAtRef = useRef31(0);
|
|
15683
|
+
const lastExportAtRef = useRef31(0);
|
|
15577
15684
|
const updateField = useCallback27((key, value) => {
|
|
15578
15685
|
setIsActive(true);
|
|
15686
|
+
lastChangeAtRef.current = Date.now();
|
|
15579
15687
|
setPersonValues((prev) => ({ ...prev, [key]: value }));
|
|
15580
15688
|
}, []);
|
|
15689
|
+
const settleMs = (exportConfig?.debounceMs ?? PERSONALIZATION_EXPORT_DEBOUNCE_MS) + (exportConfig?.maxWaitMs ?? 1e3) + 300;
|
|
15690
|
+
useEffect48(() => {
|
|
15691
|
+
if (!isActive || lastChangeAtRef.current === 0) return;
|
|
15692
|
+
const changedAt = lastChangeAtRef.current;
|
|
15693
|
+
const timer = setTimeout(() => {
|
|
15694
|
+
if (lastExportAtRef.current >= changedAt) return;
|
|
15695
|
+
const exportArtboards = canvasRef.current?.exportArtboards;
|
|
15696
|
+
if (!exportArtboards) return;
|
|
15697
|
+
void exportArtboards({ format: "blob", scale: exportConfig?.scale ?? 1, all: false }).then((exports) => {
|
|
15698
|
+
if (lastChangeAtRef.current !== changedAt || lastExportAtRef.current >= changedAt) return;
|
|
15699
|
+
if (exports && Object.keys(exports).length > 0) handleExportRef.current?.(exports);
|
|
15700
|
+
}).catch(() => {
|
|
15701
|
+
});
|
|
15702
|
+
}, settleMs);
|
|
15703
|
+
return () => clearTimeout(timer);
|
|
15704
|
+
}, [personValues, isActive, settleMs, exportConfig?.scale]);
|
|
15581
15705
|
const reset = useCallback27(() => {
|
|
15582
15706
|
setPersonValues({});
|
|
15583
15707
|
setIsActive(false);
|
|
@@ -15585,6 +15709,7 @@ function PersonalizationProvider({
|
|
|
15585
15709
|
}, []);
|
|
15586
15710
|
const handleExport = useCallback27(
|
|
15587
15711
|
(exports) => {
|
|
15712
|
+
lastExportAtRef.current = Date.now();
|
|
15588
15713
|
const newUrls = {};
|
|
15589
15714
|
for (const [name, data] of Object.entries(exports)) {
|
|
15590
15715
|
if (blobUrlsRef.current[name]) {
|
|
@@ -15617,6 +15742,10 @@ function PersonalizationProvider({
|
|
|
15617
15742
|
},
|
|
15618
15743
|
[realtime, placementOverride]
|
|
15619
15744
|
);
|
|
15745
|
+
const handleExportRef = useRef31(null);
|
|
15746
|
+
useEffect48(() => {
|
|
15747
|
+
handleExportRef.current = handleExport;
|
|
15748
|
+
}, [handleExport]);
|
|
15620
15749
|
const handleExportScheduled = useCallback27(() => {
|
|
15621
15750
|
setIsExporting(true);
|
|
15622
15751
|
}, []);
|
|
@@ -15651,13 +15780,16 @@ function PersonalizationProvider({
|
|
|
15651
15780
|
children: /* @__PURE__ */ jsx91(
|
|
15652
15781
|
CanvasComponent,
|
|
15653
15782
|
{
|
|
15783
|
+
ref: canvasRef,
|
|
15654
15784
|
initialElements: canvasState?.elements,
|
|
15655
15785
|
artboards: canvasState?.artboards,
|
|
15656
15786
|
kit: "embed-only",
|
|
15657
15787
|
inheritTheme: true,
|
|
15658
15788
|
autoExportConfig: {
|
|
15659
15789
|
enabled: true,
|
|
15660
|
-
|
|
15790
|
+
// Typing cadence (~100-200 ms a key): one render per pause, not one per key (each render is a new picture
|
|
15791
|
+
// on every mockup); maxWaitMs still shows progress during a long burst.
|
|
15792
|
+
debounceMs: exportConfig?.debounceMs ?? PERSONALIZATION_EXPORT_DEBOUNCE_MS,
|
|
15661
15793
|
maxWaitMs: exportConfig?.maxWaitMs ?? 1e3
|
|
15662
15794
|
},
|
|
15663
15795
|
autoExportFormat: "blob",
|
|
@@ -15722,7 +15854,9 @@ function PersonalizationInputs({
|
|
|
15722
15854
|
"input",
|
|
15723
15855
|
{
|
|
15724
15856
|
type: "text",
|
|
15857
|
+
"aria-label": field.label,
|
|
15725
15858
|
placeholder: field.placeholder || field.label,
|
|
15859
|
+
maxLength: field.maxLength,
|
|
15726
15860
|
value: personValues[field.name] ?? "",
|
|
15727
15861
|
onChange: (e) => updateField(field.name, e.target.value),
|
|
15728
15862
|
onFocus: handleFocus,
|
|
@@ -15922,6 +16056,7 @@ export {
|
|
|
15922
16056
|
FACET_SECTIONS,
|
|
15923
16057
|
FIRST_VIEW_MARGIN,
|
|
15924
16058
|
FIRST_VIEW_PICTURE_ASPECT,
|
|
16059
|
+
FIT_MARGIN,
|
|
15925
16060
|
Fieldset,
|
|
15926
16061
|
Filters,
|
|
15927
16062
|
FiltersButton,
|
|
@@ -16043,15 +16178,18 @@ export {
|
|
|
16043
16178
|
UiRouterProvider,
|
|
16044
16179
|
VISIBILITY_THRESHOLDS,
|
|
16045
16180
|
ZoomOverlay,
|
|
16181
|
+
anyTyped,
|
|
16046
16182
|
badgeVariants,
|
|
16047
16183
|
blockingSessionError,
|
|
16048
16184
|
brandAssets,
|
|
16049
16185
|
buttonVariants,
|
|
16050
16186
|
canvasExportService,
|
|
16187
|
+
canvasFontString,
|
|
16051
16188
|
checkComponentStyles,
|
|
16052
16189
|
checkTailwindConfig,
|
|
16053
16190
|
checkThemeTokens,
|
|
16054
16191
|
createScrollDirectionTracker,
|
|
16192
|
+
decodedPicture,
|
|
16055
16193
|
describeProductArtAlignment2 as describeProductArtAlignment,
|
|
16056
16194
|
firstView,
|
|
16057
16195
|
firstViewAnchorOfSlide,
|
|
@@ -16074,17 +16212,21 @@ export {
|
|
|
16074
16212
|
linkVariants,
|
|
16075
16213
|
linkedPlacementsLabel,
|
|
16076
16214
|
listProducts4 as listProducts,
|
|
16215
|
+
measureTextLine,
|
|
16077
16216
|
normalizeHex,
|
|
16078
16217
|
observe,
|
|
16079
16218
|
pictureRenderState,
|
|
16219
|
+
pictureSwapOf,
|
|
16080
16220
|
placementArtFor,
|
|
16081
16221
|
runConfigChecks,
|
|
16082
16222
|
scrollInputAboveKeyboard,
|
|
16083
16223
|
searchClient,
|
|
16224
|
+
shrinkFontSizeToFit,
|
|
16084
16225
|
slideFirstViewFields,
|
|
16085
16226
|
slideFirstViewProps,
|
|
16086
16227
|
spinnerVariants,
|
|
16087
16228
|
surfaceVariants,
|
|
16229
|
+
textValueFor,
|
|
16088
16230
|
useArtworkAlignment,
|
|
16089
16231
|
useBrand,
|
|
16090
16232
|
useCanvasContext,
|