@snowcone-app/sdk 0.24.2 → 0.24.3
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 +6 -0
- package/dist/index.cjs +31 -0
- package/dist/index.d.cts +11 -1
- package/dist/index.d.ts +11 -1
- package/dist/index.js +30 -0
- package/package.json +1 -1
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,11 @@
|
|
|
1
1
|
# Changelog
|
|
2
2
|
|
|
3
|
+
## 0.24.3
|
|
4
|
+
|
|
5
|
+
### Patch Changes
|
|
6
|
+
|
|
7
|
+
- [#4074](https://github.com/snowcone-app/snowcone-monorepo/pull/4074) [`8682d87`](https://github.com/snowcone-app/snowcone-monorepo/commit/8682d876466cee5ee80ff05b1401a5679a410007) Thanks [@kevinsproles](https://github.com/kevinsproles)! - A selected size with no scene previews a listed variant that differs only by size. The cart, SKU and price keep the selected size.
|
|
8
|
+
|
|
3
9
|
## 0.24.2
|
|
4
10
|
|
|
5
11
|
### Patch Changes
|
package/dist/index.cjs
CHANGED
|
@@ -138,6 +138,7 @@ __export(index_exports, {
|
|
|
138
138
|
registerStandardComponents: () => registerStandardComponents,
|
|
139
139
|
resolveBestCombination: () => resolveBestCombination,
|
|
140
140
|
resolveMockupId: () => resolveMockupId,
|
|
141
|
+
resolvePreviewVariantId: () => resolvePreviewVariantId,
|
|
141
142
|
resolveVariantId: () => resolveVariantId,
|
|
142
143
|
retryOperation: () => retryOperation,
|
|
143
144
|
searchDesigns: () => searchDesigns,
|
|
@@ -1951,6 +1952,35 @@ function resolveVariantId(context, providedGvid, providedVariantId) {
|
|
|
1951
1952
|
}
|
|
1952
1953
|
return "default";
|
|
1953
1954
|
}
|
|
1955
|
+
var SIZE_ATTRIBUTE = /^size$/i;
|
|
1956
|
+
var NOT_THE_PICTURE = /* @__PURE__ */ new Set(["variantId", "price"]);
|
|
1957
|
+
function resolvePreviewVariantId(context, variantId, mockupId) {
|
|
1958
|
+
const all = context?.product?.mockups ?? [];
|
|
1959
|
+
const mockups = mockupId ? all.filter((m) => m.id === mockupId) : all;
|
|
1960
|
+
const lists = (m, id) => (m.gvids ?? []).includes(id);
|
|
1961
|
+
if (mockups.length === 0 || mockups.some((m) => lists(m, variantId))) return variantId;
|
|
1962
|
+
const combinations = context?.combinations ?? [];
|
|
1963
|
+
const selected = combinations.find((c) => c.variantId === variantId);
|
|
1964
|
+
if (!selected) return variantId;
|
|
1965
|
+
const sizeKey = Object.keys(selected).find((k) => SIZE_ATTRIBUTE.test(k));
|
|
1966
|
+
if (!sizeKey) return variantId;
|
|
1967
|
+
const pictureKeys = (row) => Object.keys(row).filter((k) => k !== sizeKey && !NOT_THE_PICTURE.has(k));
|
|
1968
|
+
const sameExceptSize = (row) => {
|
|
1969
|
+
const keys = pictureKeys(row);
|
|
1970
|
+
return keys.length === pictureKeys(selected).length && keys.every((k) => row[k] === selected[k]);
|
|
1971
|
+
};
|
|
1972
|
+
let best = variantId;
|
|
1973
|
+
let bestCount = 0;
|
|
1974
|
+
for (const row of combinations) {
|
|
1975
|
+
if (typeof row.variantId !== "string" || row.variantId === variantId || !sameExceptSize(row)) continue;
|
|
1976
|
+
const count = mockups.filter((m) => lists(m, row.variantId)).length;
|
|
1977
|
+
if (count > bestCount) {
|
|
1978
|
+
best = row.variantId;
|
|
1979
|
+
bestCount = count;
|
|
1980
|
+
}
|
|
1981
|
+
}
|
|
1982
|
+
return best;
|
|
1983
|
+
}
|
|
1954
1984
|
function resolveMockupId(context, variantId, providedMockupId) {
|
|
1955
1985
|
if (providedMockupId) return providedMockupId;
|
|
1956
1986
|
if (context?.product?.mockups?.length) {
|
|
@@ -6561,6 +6591,7 @@ function createClient(config) {
|
|
|
6561
6591
|
registerStandardComponents,
|
|
6562
6592
|
resolveBestCombination,
|
|
6563
6593
|
resolveMockupId,
|
|
6594
|
+
resolvePreviewVariantId,
|
|
6564
6595
|
resolveVariantId,
|
|
6565
6596
|
retryOperation,
|
|
6566
6597
|
searchDesigns,
|
package/dist/index.d.cts
CHANGED
|
@@ -1070,6 +1070,16 @@ declare function getVariant(selection: UserSelection, product: {
|
|
|
1070
1070
|
* Used by React/Vue/WC components that have context
|
|
1071
1071
|
*/
|
|
1072
1072
|
declare function resolveVariantId(context: any, providedGvid?: string, providedVariantId?: string): string;
|
|
1073
|
+
/**
|
|
1074
|
+
* The variant to PREVIEW for a selected one. Scenes exist only for the variants a mockup lists, and a size doesn't change
|
|
1075
|
+
* the picture, so a size with no scene previews a listed variant that differs ONLY by size. Anything else about the
|
|
1076
|
+
* row (a colour, another garment) must match, so it can't show the wrong colour; with no such variant this returns the
|
|
1077
|
+
* selected one, and the render's typed failure stands.
|
|
1078
|
+
*
|
|
1079
|
+
* Preview only. The cart, SKU, price and print file keep the selected variant (createCartDetail doesn't read this).
|
|
1080
|
+
* Without a `mockupId` (a realtime session, one variant for all its mockups) it picks the sibling most mockups list.
|
|
1081
|
+
*/
|
|
1082
|
+
declare function resolvePreviewVariantId(context: any, variantId: string, mockupId?: string | null): string;
|
|
1073
1083
|
/**
|
|
1074
1084
|
* Internal helper - determines the mockup ID based on variant and available mockups
|
|
1075
1085
|
* Used by React/Vue/WC components that have context
|
|
@@ -3426,4 +3436,4 @@ declare function searchDesigns(query?: string, options?: SearchDesignsOptions):
|
|
|
3426
3436
|
*/
|
|
3427
3437
|
declare function createClient(config: SdkConfig): SnowconeClient;
|
|
3428
3438
|
|
|
3429
|
-
export { AbstractTemplateRenderer, type AddToCartOptions, Animations, type ArtSelectorContext, type ArtSelectorDescriptor, type ArtSelectorOptions, type ArtworkData, type AspectRatio, Attributes, type BaseDescriptor, type BlendConfig, type BuildMockupUrlConfig, type CartDetail, type CatalogDesign, type CatalogListResponse, type CatalogProduct, ClassNames, type ColorDesignElement, ColorPickerUtils, Combination, CommonProps, ComponentContext, type ComponentDefinition, ComponentDescriptor, ComponentEventManager, ComponentFactory, ComponentLifecycle, ComponentLifecycleHooks, type ComponentMetadata, ComponentProps, ComponentRegistry, ComponentState, type ComponentTemplate, ComponentTemplates, type ContainerDescriptor, ContextBridge, type ContextComparator, type ContextConsumer, ContextInjector, type ContextProviderConfig, type ContextSubscriber, ContextSynchronizer, type CreateDesignStateInput, type CreatedDesignState, DEFAULT_ARTWORK_URL, DEFAULT_ASPECT_RATIO, DEFAULT_BUY_BASE, DEFAULT_COLOR, DEFAULT_GRANT_BASE, DEFAULT_MOCKUP_BASE, DEFAULT_PLACEMENT_DIMENSIONS, type Descriptor, type Design, type DesignElement, type DesignGenerationContext, type DesignLike, type DesignsSearchResponse, type Effects, Elements, type ErrorContext, type ErrorHandler, ErrorManager, type EventDefinition, EventDelegator, EventEmitter, EventHandler, type EventListener, type EventPayload, type FailedAsset, type FetchMockupImageOptions, type Fill, Focus, FrameworkAdapter, FrameworkUtilities, type GetMockupUrlOptions, type ImageAlignment, type ImageDesignElement, type LifecycleHook, LifecycleManager, type LifecyclePhase, type LifecycleTransition, LitAdapter, type MaskOverride, type MockupGenerationOptions, type MockupImage, MockupResult, type MockupService, type MockupServiceConfig, OptionAttribute, type OptionChoice, type OptionChoiceRenderData, type OptionRenderData, OptionSelection, type Placement, type PlacementDesign, PlacementSettings, type ProductArtAlignmentContext, type ProductArtAlignmentDescriptor, type ProductArtAlignmentOptions, type ProductContext, type ProductContextEvents, ProductContextManager, type ProductData, type ProductFetcher, type ProductImageDescriptor, type ProductImageOptions, ProductLoader, type ProductMockupData, type ProductOptionChoice, type ProductOptionData, type ProductOptionsDescriptor, type ProductOptionsOptions, type ProductPlacement, type ProductPriceDescriptor, type ProductPriceOptions, ProductProps, type ProductSpec, type ProductTitleDescriptor, type ProductTitleOptions, type ProductVariant, type PropDefinition, type PropSchema, type PropType, PropertyManager, REALTIME_WS_URL, type RateLimitState, type RealtimeGrant, RealtimeMockupService, RealtimeRenderError, type RegularArtwork, type RenderProduct, type RenderProductAttribute, type RenderProductAttributeChoice, type RenderProductCombination, type RenderProductMockup, type RenderProductOptions, type RenderProductRequiredPlacement, RenderSession, type RenderSessionOptions, type RenderState, type SdkConfig, type SeamlessPattern, type SearchDesignsOptions, type SignedUrlResponse, type SnowconeClient, SnowconeSdkError, type SnowconeSdkErrorCode, StandardComponents, StandardEvents, StateManager, type StateManagerOptions, type StateMiddleware, type StateSelector, type StateSubscriber, type StateUpdater, Styles, SvelteAdapter, SwatchUtils, type TagName, TemplateBuilder, type TemplateNode, type TemplateNodeType, type TemplateRenderer, type TextDescriptor, type TileCount, UniversalContextProvider, type UserSelection, type ValidationError, type ValidationResult, VueAdapter, assertVariantSelected, autoRegister, bffSigner, buildMockupUrl, componentRegistry, createAddToCartEvent, createAddToCartHandler, createCartDetail, createClient, createContextProvider, createDesignForPlacements, createDesignState, createErrorHandler, createEventManager, createLifecycle, createLitComponent, createProductContext, createProductLoader, createPropertyManager, createStateHook, createStateStore, createSvelteComponent, createUniversalProvider, createVueComponent, describeArtSelector, describeProductArtAlignment, describeProductImage, describeProductOptions, describeProductPrice, describeProductTitle, extractProductId, fetchMockupImage, fetchRealtimeGrant, filterImagePlacements, findClosestSnapPoint, findVariantForSelection, formatPrice, formatValidationErrors, getBuyUrl, getDefaultVariantId, getEffectiveAlignment, getIncompleteSelectionMessage, getMissingSelections, getMockupUrl, getOptionRenderType, getProduct, getSelectionDisplayText, getSnapPoints, getVariant, handleOptionChange, imageKindOf, isSelectionComplete, isSnowconeSdkError, isValidAlignment, isValidTileCount, listProducts, mintRealtimeGrant, mockupUrl, normalizeChoice, prepareOptionRenderData, registerStandardComponents, resolveMockupId, resolveVariantId, retryOperation, searchDesigns, simulateCartOperation, toCombinations, toOptionAttributes, useFrameworkAdapter as useVueAdapter, validateAlignment, validateDesignElement, validateEffects, validateImageUrl, validateMockupOptions, validateProductSelection, validateProductSpec, validateRequiredOptions, validateTileCount, warnVariantNotSelected, withContext, withErrorHandling, withSyncErrorHandling };
|
|
3439
|
+
export { AbstractTemplateRenderer, type AddToCartOptions, Animations, type ArtSelectorContext, type ArtSelectorDescriptor, type ArtSelectorOptions, type ArtworkData, type AspectRatio, Attributes, type BaseDescriptor, type BlendConfig, type BuildMockupUrlConfig, type CartDetail, type CatalogDesign, type CatalogListResponse, type CatalogProduct, ClassNames, type ColorDesignElement, ColorPickerUtils, Combination, CommonProps, ComponentContext, type ComponentDefinition, ComponentDescriptor, ComponentEventManager, ComponentFactory, ComponentLifecycle, ComponentLifecycleHooks, type ComponentMetadata, ComponentProps, ComponentRegistry, ComponentState, type ComponentTemplate, ComponentTemplates, type ContainerDescriptor, ContextBridge, type ContextComparator, type ContextConsumer, ContextInjector, type ContextProviderConfig, type ContextSubscriber, ContextSynchronizer, type CreateDesignStateInput, type CreatedDesignState, DEFAULT_ARTWORK_URL, DEFAULT_ASPECT_RATIO, DEFAULT_BUY_BASE, DEFAULT_COLOR, DEFAULT_GRANT_BASE, DEFAULT_MOCKUP_BASE, DEFAULT_PLACEMENT_DIMENSIONS, type Descriptor, type Design, type DesignElement, type DesignGenerationContext, type DesignLike, type DesignsSearchResponse, type Effects, Elements, type ErrorContext, type ErrorHandler, ErrorManager, type EventDefinition, EventDelegator, EventEmitter, EventHandler, type EventListener, type EventPayload, type FailedAsset, type FetchMockupImageOptions, type Fill, Focus, FrameworkAdapter, FrameworkUtilities, type GetMockupUrlOptions, type ImageAlignment, type ImageDesignElement, type LifecycleHook, LifecycleManager, type LifecyclePhase, type LifecycleTransition, LitAdapter, type MaskOverride, type MockupGenerationOptions, type MockupImage, MockupResult, type MockupService, type MockupServiceConfig, OptionAttribute, type OptionChoice, type OptionChoiceRenderData, type OptionRenderData, OptionSelection, type Placement, type PlacementDesign, PlacementSettings, type ProductArtAlignmentContext, type ProductArtAlignmentDescriptor, type ProductArtAlignmentOptions, type ProductContext, type ProductContextEvents, ProductContextManager, type ProductData, type ProductFetcher, type ProductImageDescriptor, type ProductImageOptions, ProductLoader, type ProductMockupData, type ProductOptionChoice, type ProductOptionData, type ProductOptionsDescriptor, type ProductOptionsOptions, type ProductPlacement, type ProductPriceDescriptor, type ProductPriceOptions, ProductProps, type ProductSpec, type ProductTitleDescriptor, type ProductTitleOptions, type ProductVariant, type PropDefinition, type PropSchema, type PropType, PropertyManager, REALTIME_WS_URL, type RateLimitState, type RealtimeGrant, RealtimeMockupService, RealtimeRenderError, type RegularArtwork, type RenderProduct, type RenderProductAttribute, type RenderProductAttributeChoice, type RenderProductCombination, type RenderProductMockup, type RenderProductOptions, type RenderProductRequiredPlacement, RenderSession, type RenderSessionOptions, type RenderState, type SdkConfig, type SeamlessPattern, type SearchDesignsOptions, type SignedUrlResponse, type SnowconeClient, SnowconeSdkError, type SnowconeSdkErrorCode, StandardComponents, StandardEvents, StateManager, type StateManagerOptions, type StateMiddleware, type StateSelector, type StateSubscriber, type StateUpdater, Styles, SvelteAdapter, SwatchUtils, type TagName, TemplateBuilder, type TemplateNode, type TemplateNodeType, type TemplateRenderer, type TextDescriptor, type TileCount, UniversalContextProvider, type UserSelection, type ValidationError, type ValidationResult, VueAdapter, assertVariantSelected, autoRegister, bffSigner, buildMockupUrl, componentRegistry, createAddToCartEvent, createAddToCartHandler, createCartDetail, createClient, createContextProvider, createDesignForPlacements, createDesignState, createErrorHandler, createEventManager, createLifecycle, createLitComponent, createProductContext, createProductLoader, createPropertyManager, createStateHook, createStateStore, createSvelteComponent, createUniversalProvider, createVueComponent, describeArtSelector, describeProductArtAlignment, describeProductImage, describeProductOptions, describeProductPrice, describeProductTitle, extractProductId, fetchMockupImage, fetchRealtimeGrant, filterImagePlacements, findClosestSnapPoint, findVariantForSelection, formatPrice, formatValidationErrors, getBuyUrl, getDefaultVariantId, getEffectiveAlignment, getIncompleteSelectionMessage, getMissingSelections, getMockupUrl, getOptionRenderType, getProduct, getSelectionDisplayText, getSnapPoints, getVariant, handleOptionChange, imageKindOf, isSelectionComplete, isSnowconeSdkError, isValidAlignment, isValidTileCount, listProducts, mintRealtimeGrant, mockupUrl, normalizeChoice, prepareOptionRenderData, registerStandardComponents, resolveMockupId, resolvePreviewVariantId, resolveVariantId, retryOperation, searchDesigns, simulateCartOperation, toCombinations, toOptionAttributes, useFrameworkAdapter as useVueAdapter, validateAlignment, validateDesignElement, validateEffects, validateImageUrl, validateMockupOptions, validateProductSelection, validateProductSpec, validateRequiredOptions, validateTileCount, warnVariantNotSelected, withContext, withErrorHandling, withSyncErrorHandling };
|
package/dist/index.d.ts
CHANGED
|
@@ -1070,6 +1070,16 @@ declare function getVariant(selection: UserSelection, product: {
|
|
|
1070
1070
|
* Used by React/Vue/WC components that have context
|
|
1071
1071
|
*/
|
|
1072
1072
|
declare function resolveVariantId(context: any, providedGvid?: string, providedVariantId?: string): string;
|
|
1073
|
+
/**
|
|
1074
|
+
* The variant to PREVIEW for a selected one. Scenes exist only for the variants a mockup lists, and a size doesn't change
|
|
1075
|
+
* the picture, so a size with no scene previews a listed variant that differs ONLY by size. Anything else about the
|
|
1076
|
+
* row (a colour, another garment) must match, so it can't show the wrong colour; with no such variant this returns the
|
|
1077
|
+
* selected one, and the render's typed failure stands.
|
|
1078
|
+
*
|
|
1079
|
+
* Preview only. The cart, SKU, price and print file keep the selected variant (createCartDetail doesn't read this).
|
|
1080
|
+
* Without a `mockupId` (a realtime session, one variant for all its mockups) it picks the sibling most mockups list.
|
|
1081
|
+
*/
|
|
1082
|
+
declare function resolvePreviewVariantId(context: any, variantId: string, mockupId?: string | null): string;
|
|
1073
1083
|
/**
|
|
1074
1084
|
* Internal helper - determines the mockup ID based on variant and available mockups
|
|
1075
1085
|
* Used by React/Vue/WC components that have context
|
|
@@ -3426,4 +3436,4 @@ declare function searchDesigns(query?: string, options?: SearchDesignsOptions):
|
|
|
3426
3436
|
*/
|
|
3427
3437
|
declare function createClient(config: SdkConfig): SnowconeClient;
|
|
3428
3438
|
|
|
3429
|
-
export { AbstractTemplateRenderer, type AddToCartOptions, Animations, type ArtSelectorContext, type ArtSelectorDescriptor, type ArtSelectorOptions, type ArtworkData, type AspectRatio, Attributes, type BaseDescriptor, type BlendConfig, type BuildMockupUrlConfig, type CartDetail, type CatalogDesign, type CatalogListResponse, type CatalogProduct, ClassNames, type ColorDesignElement, ColorPickerUtils, Combination, CommonProps, ComponentContext, type ComponentDefinition, ComponentDescriptor, ComponentEventManager, ComponentFactory, ComponentLifecycle, ComponentLifecycleHooks, type ComponentMetadata, ComponentProps, ComponentRegistry, ComponentState, type ComponentTemplate, ComponentTemplates, type ContainerDescriptor, ContextBridge, type ContextComparator, type ContextConsumer, ContextInjector, type ContextProviderConfig, type ContextSubscriber, ContextSynchronizer, type CreateDesignStateInput, type CreatedDesignState, DEFAULT_ARTWORK_URL, DEFAULT_ASPECT_RATIO, DEFAULT_BUY_BASE, DEFAULT_COLOR, DEFAULT_GRANT_BASE, DEFAULT_MOCKUP_BASE, DEFAULT_PLACEMENT_DIMENSIONS, type Descriptor, type Design, type DesignElement, type DesignGenerationContext, type DesignLike, type DesignsSearchResponse, type Effects, Elements, type ErrorContext, type ErrorHandler, ErrorManager, type EventDefinition, EventDelegator, EventEmitter, EventHandler, type EventListener, type EventPayload, type FailedAsset, type FetchMockupImageOptions, type Fill, Focus, FrameworkAdapter, FrameworkUtilities, type GetMockupUrlOptions, type ImageAlignment, type ImageDesignElement, type LifecycleHook, LifecycleManager, type LifecyclePhase, type LifecycleTransition, LitAdapter, type MaskOverride, type MockupGenerationOptions, type MockupImage, MockupResult, type MockupService, type MockupServiceConfig, OptionAttribute, type OptionChoice, type OptionChoiceRenderData, type OptionRenderData, OptionSelection, type Placement, type PlacementDesign, PlacementSettings, type ProductArtAlignmentContext, type ProductArtAlignmentDescriptor, type ProductArtAlignmentOptions, type ProductContext, type ProductContextEvents, ProductContextManager, type ProductData, type ProductFetcher, type ProductImageDescriptor, type ProductImageOptions, ProductLoader, type ProductMockupData, type ProductOptionChoice, type ProductOptionData, type ProductOptionsDescriptor, type ProductOptionsOptions, type ProductPlacement, type ProductPriceDescriptor, type ProductPriceOptions, ProductProps, type ProductSpec, type ProductTitleDescriptor, type ProductTitleOptions, type ProductVariant, type PropDefinition, type PropSchema, type PropType, PropertyManager, REALTIME_WS_URL, type RateLimitState, type RealtimeGrant, RealtimeMockupService, RealtimeRenderError, type RegularArtwork, type RenderProduct, type RenderProductAttribute, type RenderProductAttributeChoice, type RenderProductCombination, type RenderProductMockup, type RenderProductOptions, type RenderProductRequiredPlacement, RenderSession, type RenderSessionOptions, type RenderState, type SdkConfig, type SeamlessPattern, type SearchDesignsOptions, type SignedUrlResponse, type SnowconeClient, SnowconeSdkError, type SnowconeSdkErrorCode, StandardComponents, StandardEvents, StateManager, type StateManagerOptions, type StateMiddleware, type StateSelector, type StateSubscriber, type StateUpdater, Styles, SvelteAdapter, SwatchUtils, type TagName, TemplateBuilder, type TemplateNode, type TemplateNodeType, type TemplateRenderer, type TextDescriptor, type TileCount, UniversalContextProvider, type UserSelection, type ValidationError, type ValidationResult, VueAdapter, assertVariantSelected, autoRegister, bffSigner, buildMockupUrl, componentRegistry, createAddToCartEvent, createAddToCartHandler, createCartDetail, createClient, createContextProvider, createDesignForPlacements, createDesignState, createErrorHandler, createEventManager, createLifecycle, createLitComponent, createProductContext, createProductLoader, createPropertyManager, createStateHook, createStateStore, createSvelteComponent, createUniversalProvider, createVueComponent, describeArtSelector, describeProductArtAlignment, describeProductImage, describeProductOptions, describeProductPrice, describeProductTitle, extractProductId, fetchMockupImage, fetchRealtimeGrant, filterImagePlacements, findClosestSnapPoint, findVariantForSelection, formatPrice, formatValidationErrors, getBuyUrl, getDefaultVariantId, getEffectiveAlignment, getIncompleteSelectionMessage, getMissingSelections, getMockupUrl, getOptionRenderType, getProduct, getSelectionDisplayText, getSnapPoints, getVariant, handleOptionChange, imageKindOf, isSelectionComplete, isSnowconeSdkError, isValidAlignment, isValidTileCount, listProducts, mintRealtimeGrant, mockupUrl, normalizeChoice, prepareOptionRenderData, registerStandardComponents, resolveMockupId, resolveVariantId, retryOperation, searchDesigns, simulateCartOperation, toCombinations, toOptionAttributes, useFrameworkAdapter as useVueAdapter, validateAlignment, validateDesignElement, validateEffects, validateImageUrl, validateMockupOptions, validateProductSelection, validateProductSpec, validateRequiredOptions, validateTileCount, warnVariantNotSelected, withContext, withErrorHandling, withSyncErrorHandling };
|
|
3439
|
+
export { AbstractTemplateRenderer, type AddToCartOptions, Animations, type ArtSelectorContext, type ArtSelectorDescriptor, type ArtSelectorOptions, type ArtworkData, type AspectRatio, Attributes, type BaseDescriptor, type BlendConfig, type BuildMockupUrlConfig, type CartDetail, type CatalogDesign, type CatalogListResponse, type CatalogProduct, ClassNames, type ColorDesignElement, ColorPickerUtils, Combination, CommonProps, ComponentContext, type ComponentDefinition, ComponentDescriptor, ComponentEventManager, ComponentFactory, ComponentLifecycle, ComponentLifecycleHooks, type ComponentMetadata, ComponentProps, ComponentRegistry, ComponentState, type ComponentTemplate, ComponentTemplates, type ContainerDescriptor, ContextBridge, type ContextComparator, type ContextConsumer, ContextInjector, type ContextProviderConfig, type ContextSubscriber, ContextSynchronizer, type CreateDesignStateInput, type CreatedDesignState, DEFAULT_ARTWORK_URL, DEFAULT_ASPECT_RATIO, DEFAULT_BUY_BASE, DEFAULT_COLOR, DEFAULT_GRANT_BASE, DEFAULT_MOCKUP_BASE, DEFAULT_PLACEMENT_DIMENSIONS, type Descriptor, type Design, type DesignElement, type DesignGenerationContext, type DesignLike, type DesignsSearchResponse, type Effects, Elements, type ErrorContext, type ErrorHandler, ErrorManager, type EventDefinition, EventDelegator, EventEmitter, EventHandler, type EventListener, type EventPayload, type FailedAsset, type FetchMockupImageOptions, type Fill, Focus, FrameworkAdapter, FrameworkUtilities, type GetMockupUrlOptions, type ImageAlignment, type ImageDesignElement, type LifecycleHook, LifecycleManager, type LifecyclePhase, type LifecycleTransition, LitAdapter, type MaskOverride, type MockupGenerationOptions, type MockupImage, MockupResult, type MockupService, type MockupServiceConfig, OptionAttribute, type OptionChoice, type OptionChoiceRenderData, type OptionRenderData, OptionSelection, type Placement, type PlacementDesign, PlacementSettings, type ProductArtAlignmentContext, type ProductArtAlignmentDescriptor, type ProductArtAlignmentOptions, type ProductContext, type ProductContextEvents, ProductContextManager, type ProductData, type ProductFetcher, type ProductImageDescriptor, type ProductImageOptions, ProductLoader, type ProductMockupData, type ProductOptionChoice, type ProductOptionData, type ProductOptionsDescriptor, type ProductOptionsOptions, type ProductPlacement, type ProductPriceDescriptor, type ProductPriceOptions, ProductProps, type ProductSpec, type ProductTitleDescriptor, type ProductTitleOptions, type ProductVariant, type PropDefinition, type PropSchema, type PropType, PropertyManager, REALTIME_WS_URL, type RateLimitState, type RealtimeGrant, RealtimeMockupService, RealtimeRenderError, type RegularArtwork, type RenderProduct, type RenderProductAttribute, type RenderProductAttributeChoice, type RenderProductCombination, type RenderProductMockup, type RenderProductOptions, type RenderProductRequiredPlacement, RenderSession, type RenderSessionOptions, type RenderState, type SdkConfig, type SeamlessPattern, type SearchDesignsOptions, type SignedUrlResponse, type SnowconeClient, SnowconeSdkError, type SnowconeSdkErrorCode, StandardComponents, StandardEvents, StateManager, type StateManagerOptions, type StateMiddleware, type StateSelector, type StateSubscriber, type StateUpdater, Styles, SvelteAdapter, SwatchUtils, type TagName, TemplateBuilder, type TemplateNode, type TemplateNodeType, type TemplateRenderer, type TextDescriptor, type TileCount, UniversalContextProvider, type UserSelection, type ValidationError, type ValidationResult, VueAdapter, assertVariantSelected, autoRegister, bffSigner, buildMockupUrl, componentRegistry, createAddToCartEvent, createAddToCartHandler, createCartDetail, createClient, createContextProvider, createDesignForPlacements, createDesignState, createErrorHandler, createEventManager, createLifecycle, createLitComponent, createProductContext, createProductLoader, createPropertyManager, createStateHook, createStateStore, createSvelteComponent, createUniversalProvider, createVueComponent, describeArtSelector, describeProductArtAlignment, describeProductImage, describeProductOptions, describeProductPrice, describeProductTitle, extractProductId, fetchMockupImage, fetchRealtimeGrant, filterImagePlacements, findClosestSnapPoint, findVariantForSelection, formatPrice, formatValidationErrors, getBuyUrl, getDefaultVariantId, getEffectiveAlignment, getIncompleteSelectionMessage, getMissingSelections, getMockupUrl, getOptionRenderType, getProduct, getSelectionDisplayText, getSnapPoints, getVariant, handleOptionChange, imageKindOf, isSelectionComplete, isSnowconeSdkError, isValidAlignment, isValidTileCount, listProducts, mintRealtimeGrant, mockupUrl, normalizeChoice, prepareOptionRenderData, registerStandardComponents, resolveMockupId, resolvePreviewVariantId, resolveVariantId, retryOperation, searchDesigns, simulateCartOperation, toCombinations, toOptionAttributes, useFrameworkAdapter as useVueAdapter, validateAlignment, validateDesignElement, validateEffects, validateImageUrl, validateMockupOptions, validateProductSelection, validateProductSpec, validateRequiredOptions, validateTileCount, warnVariantNotSelected, withContext, withErrorHandling, withSyncErrorHandling };
|
package/dist/index.js
CHANGED
|
@@ -1516,6 +1516,35 @@ function resolveVariantId(context, providedGvid, providedVariantId) {
|
|
|
1516
1516
|
}
|
|
1517
1517
|
return "default";
|
|
1518
1518
|
}
|
|
1519
|
+
var SIZE_ATTRIBUTE = /^size$/i;
|
|
1520
|
+
var NOT_THE_PICTURE = /* @__PURE__ */ new Set(["variantId", "price"]);
|
|
1521
|
+
function resolvePreviewVariantId(context, variantId, mockupId) {
|
|
1522
|
+
const all = context?.product?.mockups ?? [];
|
|
1523
|
+
const mockups = mockupId ? all.filter((m) => m.id === mockupId) : all;
|
|
1524
|
+
const lists = (m, id) => (m.gvids ?? []).includes(id);
|
|
1525
|
+
if (mockups.length === 0 || mockups.some((m) => lists(m, variantId))) return variantId;
|
|
1526
|
+
const combinations = context?.combinations ?? [];
|
|
1527
|
+
const selected = combinations.find((c) => c.variantId === variantId);
|
|
1528
|
+
if (!selected) return variantId;
|
|
1529
|
+
const sizeKey = Object.keys(selected).find((k) => SIZE_ATTRIBUTE.test(k));
|
|
1530
|
+
if (!sizeKey) return variantId;
|
|
1531
|
+
const pictureKeys = (row) => Object.keys(row).filter((k) => k !== sizeKey && !NOT_THE_PICTURE.has(k));
|
|
1532
|
+
const sameExceptSize = (row) => {
|
|
1533
|
+
const keys = pictureKeys(row);
|
|
1534
|
+
return keys.length === pictureKeys(selected).length && keys.every((k) => row[k] === selected[k]);
|
|
1535
|
+
};
|
|
1536
|
+
let best = variantId;
|
|
1537
|
+
let bestCount = 0;
|
|
1538
|
+
for (const row of combinations) {
|
|
1539
|
+
if (typeof row.variantId !== "string" || row.variantId === variantId || !sameExceptSize(row)) continue;
|
|
1540
|
+
const count = mockups.filter((m) => lists(m, row.variantId)).length;
|
|
1541
|
+
if (count > bestCount) {
|
|
1542
|
+
best = row.variantId;
|
|
1543
|
+
bestCount = count;
|
|
1544
|
+
}
|
|
1545
|
+
}
|
|
1546
|
+
return best;
|
|
1547
|
+
}
|
|
1519
1548
|
function resolveMockupId(context, variantId, providedMockupId) {
|
|
1520
1549
|
if (providedMockupId) return providedMockupId;
|
|
1521
1550
|
if (context?.product?.mockups?.length) {
|
|
@@ -5264,6 +5293,7 @@ export {
|
|
|
5264
5293
|
registerStandardComponents,
|
|
5265
5294
|
resolveBestCombination,
|
|
5266
5295
|
resolveMockupId,
|
|
5296
|
+
resolvePreviewVariantId,
|
|
5267
5297
|
resolveVariantId,
|
|
5268
5298
|
retryOperation,
|
|
5269
5299
|
searchDesigns,
|