bitsnap-react 1.6.1 → 1.7.1
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/README.md +135 -0
- package/dist/CartProvider-F2VH7WFO.mjs +2 -0
- package/dist/CartProvider-F2VH7WFO.mjs.map +1 -0
- package/dist/CartProvider-PDEV6GCV.css +2 -0
- package/dist/CartProvider-PDEV6GCV.css.map +1 -0
- package/dist/appearance-core-Dt2grZdl.d.mts +19 -0
- package/dist/appearance-core-Dt2grZdl.d.ts +19 -0
- package/dist/catalog.css +2 -0
- package/dist/catalog.css.map +1 -0
- package/dist/catalog.d.mts +214 -0
- package/dist/catalog.d.ts +214 -0
- package/dist/catalog.js +2 -0
- package/dist/catalog.js.map +1 -0
- package/dist/catalog.mjs +2 -0
- package/dist/catalog.mjs.map +1 -0
- package/dist/chunk-3TENJTY4.mjs +2 -0
- package/dist/chunk-3TENJTY4.mjs.map +1 -0
- package/dist/chunk-4HOZFM6V.mjs +2 -0
- package/dist/chunk-4HOZFM6V.mjs.map +1 -0
- package/dist/chunk-6KQBDN7M.mjs +2 -0
- package/dist/chunk-6KQBDN7M.mjs.map +1 -0
- package/dist/chunk-FTYJTO6O.mjs +2 -0
- package/dist/chunk-FTYJTO6O.mjs.map +1 -0
- package/dist/chunk-RATFYRKZ.mjs +4 -0
- package/dist/chunk-RATFYRKZ.mjs.map +1 -0
- package/dist/index.css +1 -1
- package/dist/index.css.map +1 -1
- package/dist/index.d.mts +62 -23
- package/dist/index.d.ts +62 -23
- package/dist/index.js +2 -2
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +1 -3
- package/dist/index.mjs.map +1 -1
- package/dist/methods-PFZSMZFU.mjs +2 -0
- package/dist/methods-PFZSMZFU.mjs.map +1 -0
- package/dist/methods-QAZED7TJ.css +2 -0
- package/dist/methods-QAZED7TJ.css.map +1 -0
- package/dist/models.d.mts +54 -0
- package/dist/models.d.ts +54 -0
- package/dist/models.js +1 -1
- package/dist/models.js.map +1 -1
- package/dist/models.mjs +1 -1
- package/dist/models.mjs.map +1 -1
- package/dist/returns.d.mts +602 -52
- package/dist/returns.d.ts +602 -52
- package/dist/returns.js +1 -1
- package/dist/returns.js.map +1 -1
- package/dist/returns.mjs +1 -1
- package/package.json +21 -26
- package/dist/chunk-O4ICBP4G.mjs +0 -2
- package/dist/chunk-O4ICBP4G.mjs.map +0 -1
|
@@ -0,0 +1,214 @@
|
|
|
1
|
+
import * as react_jsx_runtime from 'react/jsx-runtime';
|
|
2
|
+
import { ReactNode } from 'react';
|
|
3
|
+
import { S as SlotAppearance, A as AppearanceElements } from './appearance-core-Dt2grZdl.js';
|
|
4
|
+
import { BitsnapModels } from './models.js';
|
|
5
|
+
import 'zod';
|
|
6
|
+
|
|
7
|
+
/**
|
|
8
|
+
* Product list appearance API.
|
|
9
|
+
*
|
|
10
|
+
* It mirrors `CheckoutAppearance` and `ReturnsAppearance` (theme, tokens,
|
|
11
|
+
* elements) so a shop can reuse one brand object for all of them. The resolver
|
|
12
|
+
* is pure: it turns the caller input into a theme name, the tokens in effect,
|
|
13
|
+
* the slot overrides and the inline style for the theme boundary.
|
|
14
|
+
*/
|
|
15
|
+
type ProductListTheme = "light" | "dark";
|
|
16
|
+
type ProductListAppearanceTokens = {
|
|
17
|
+
/** Font family of the list. The library never loads fonts. */
|
|
18
|
+
fontFamily?: string;
|
|
19
|
+
/** Base font size. */
|
|
20
|
+
fontSize?: string;
|
|
21
|
+
/** List background. */
|
|
22
|
+
background?: string;
|
|
23
|
+
/** Raised surfaces: cards, image placeholders, skeletons. */
|
|
24
|
+
surface?: string;
|
|
25
|
+
/** Main text color. */
|
|
26
|
+
foreground?: string;
|
|
27
|
+
/** Secondary text: descriptions, the struck-through price. */
|
|
28
|
+
mutedForeground?: string;
|
|
29
|
+
/** Borders of cards and buttons. */
|
|
30
|
+
border?: string;
|
|
31
|
+
/** "Add to cart" button background. */
|
|
32
|
+
buttonBackground?: string;
|
|
33
|
+
/** "Add to cart" button text. */
|
|
34
|
+
buttonForeground?: string;
|
|
35
|
+
/** "Add to cart" button background on hover. */
|
|
36
|
+
buttonHoverBackground?: string;
|
|
37
|
+
/** Hover surface of cards and secondary buttons. */
|
|
38
|
+
hoverSurface?: string;
|
|
39
|
+
/** Focus ring color. */
|
|
40
|
+
focusRing?: string;
|
|
41
|
+
/** Error and unavailable state color. */
|
|
42
|
+
error?: string;
|
|
43
|
+
/** Badge background (subscription, unavailable). */
|
|
44
|
+
badgeBackground?: string;
|
|
45
|
+
/** Badge text. */
|
|
46
|
+
badgeForeground?: string;
|
|
47
|
+
/** Corner radius of cards, images and buttons. */
|
|
48
|
+
radius?: string;
|
|
49
|
+
};
|
|
50
|
+
/**
|
|
51
|
+
* Stable slot names. They are exposed as `data-bitsnap-products-slot`
|
|
52
|
+
* attributes so they can also be targeted from plain CSS.
|
|
53
|
+
*/
|
|
54
|
+
declare const PRODUCT_LIST_SLOT_NAMES: readonly ["root", "grid", "card", "cardLink", "image", "imagePlaceholder", "body", "name", "description", "price", "comparePrice", "badge", "actions", "addToCartButton", "selectButton", "message", "pagination", "paginationButton", "pageIndicator", "emptyState", "error", "retryButton", "skeleton"];
|
|
55
|
+
type ProductListSlotName = (typeof PRODUCT_LIST_SLOT_NAMES)[number];
|
|
56
|
+
type ProductListSlotAppearance = SlotAppearance;
|
|
57
|
+
type ProductListAppearanceElements = AppearanceElements<ProductListSlotName>;
|
|
58
|
+
type ProductListAppearance = {
|
|
59
|
+
/** `"light"` or `"dark"`. Omitted means `"light"`. */
|
|
60
|
+
theme?: ProductListTheme;
|
|
61
|
+
/** Partial overrides applied over the theme preset. */
|
|
62
|
+
tokens?: ProductListAppearanceTokens;
|
|
63
|
+
/** Per element `className`/`style` overrides. */
|
|
64
|
+
elements?: ProductListAppearanceElements;
|
|
65
|
+
};
|
|
66
|
+
|
|
67
|
+
type PublicListProduct = BitsnapModels.PublicListProduct;
|
|
68
|
+
type ProductListData = BitsnapModels.ProductListResponse;
|
|
69
|
+
|
|
70
|
+
/**
|
|
71
|
+
* Every string `ProductList` renders. Pass a partial object through the
|
|
72
|
+
* `texts` prop to override any of them, whatever the locale. Placeholders
|
|
73
|
+
* (`{price}`, `{page}`, `{pageCount}`) are filled by the component.
|
|
74
|
+
*/
|
|
75
|
+
type ProductListTexts = {
|
|
76
|
+
/** "Add to cart" button of products that can be bought straight from the list. */
|
|
77
|
+
addToCart: string;
|
|
78
|
+
/** Button label while the product is being added. */
|
|
79
|
+
addingToCart: string;
|
|
80
|
+
/** Button label after the product was added. */
|
|
81
|
+
addedToCart: string;
|
|
82
|
+
/** Message shown when adding to the cart failed. */
|
|
83
|
+
addToCartError: string;
|
|
84
|
+
/** Link of products with variants, to pick one on the product page. */
|
|
85
|
+
chooseOptions: string;
|
|
86
|
+
/** Link of products that cannot be added from the list (subscriptions). */
|
|
87
|
+
viewProduct: string;
|
|
88
|
+
/** Label of products that are out of stock. */
|
|
89
|
+
unavailable: string;
|
|
90
|
+
/** Badge of subscription products. */
|
|
91
|
+
subscription: string;
|
|
92
|
+
/** Price of products whose variants differ in price. `{price}` is the lowest one. */
|
|
93
|
+
priceFrom: string;
|
|
94
|
+
/** Screen reader label of the struck-through regular price. */
|
|
95
|
+
originalPrice: string;
|
|
96
|
+
/** Accessible label of the loading skeleton. */
|
|
97
|
+
loading: string;
|
|
98
|
+
/** Shown when the shop has no products (or none matches the search). */
|
|
99
|
+
empty: string;
|
|
100
|
+
/** Shown when the products could not be loaded. */
|
|
101
|
+
error: string;
|
|
102
|
+
/** Retry button of the error state. */
|
|
103
|
+
retry: string;
|
|
104
|
+
/** Accessible label of the pagination. */
|
|
105
|
+
pagination: string;
|
|
106
|
+
previousPage: string;
|
|
107
|
+
nextPage: string;
|
|
108
|
+
/** Page indicator. `{page}` and `{pageCount}` are filled in. */
|
|
109
|
+
pageOf: string;
|
|
110
|
+
};
|
|
111
|
+
type ProductListTextKey = keyof ProductListTexts;
|
|
112
|
+
|
|
113
|
+
type UseProductsOptions = {
|
|
114
|
+
/** Project (shop) ID. */
|
|
115
|
+
projectID: string;
|
|
116
|
+
/**
|
|
117
|
+
* Origin of the Bitsnap backend. Defaults to the library host
|
|
118
|
+
* (`https://bitsnap.pl`, or what `setCustomHost` had set when the component
|
|
119
|
+
* first rendered; later `setCustomHost` calls do not move an existing list).
|
|
120
|
+
* On a custom domain pass the domain itself, or an empty string for
|
|
121
|
+
* same-origin requests.
|
|
122
|
+
*/
|
|
123
|
+
host?: string;
|
|
124
|
+
locale?: string;
|
|
125
|
+
/** Products per page, 1 to 48. Defaults to 24. */
|
|
126
|
+
pageSize?: number;
|
|
127
|
+
search?: string;
|
|
128
|
+
/**
|
|
129
|
+
* First page, loaded on the server. It is always used for the first request
|
|
130
|
+
* of the mounted list (the first fetch is skipped and the products are
|
|
131
|
+
* available on the first render), so it has to be the page the props ask
|
|
132
|
+
* for: page 1 with the same `pageSize`, `locale` and `search`. Later changes
|
|
133
|
+
* of the props fetch again.
|
|
134
|
+
*/
|
|
135
|
+
initialData?: ProductListData;
|
|
136
|
+
};
|
|
137
|
+
type UseProductsResult = {
|
|
138
|
+
/** Products of the current page. Keeps the previous page while loading. */
|
|
139
|
+
products: PublicListProduct[];
|
|
140
|
+
totalCount: number;
|
|
141
|
+
/** Current page, starting at 1. */
|
|
142
|
+
page: number;
|
|
143
|
+
pageCount: number;
|
|
144
|
+
setPage: (page: number) => void;
|
|
145
|
+
/** `true` until the current page is available, also during server rendering. */
|
|
146
|
+
isLoading: boolean;
|
|
147
|
+
error: Error | undefined;
|
|
148
|
+
/** Loads the current page again. */
|
|
149
|
+
refetch: () => void;
|
|
150
|
+
};
|
|
151
|
+
/**
|
|
152
|
+
* Loads the product catalog page by page. It uses a plain `fetch` without
|
|
153
|
+
* credentials, never reads global state (`setProjectID`, `setCustomHost`) other
|
|
154
|
+
* than the default host, and does nothing during server rendering - pass
|
|
155
|
+
* `initialData` to render products in the server HTML.
|
|
156
|
+
*/
|
|
157
|
+
declare function useProducts(options: UseProductsOptions): UseProductsResult;
|
|
158
|
+
|
|
159
|
+
/** What `renderItem` gets next to the product. */
|
|
160
|
+
type ProductListItemContext = {
|
|
161
|
+
/** Product page URL from `productHref`. */
|
|
162
|
+
href: string;
|
|
163
|
+
/** Price formatted for the locale and currency, without the "from" prefix. */
|
|
164
|
+
price: string;
|
|
165
|
+
/** Formatted regular price when the product is discounted. */
|
|
166
|
+
compareAtPrice: string | null;
|
|
167
|
+
texts: ProductListTexts;
|
|
168
|
+
locale: string;
|
|
169
|
+
/** Adds the product to the cart the way the built-in button does. */
|
|
170
|
+
addToCart: () => Promise<void>;
|
|
171
|
+
};
|
|
172
|
+
type ProductListProps = UseProductsOptions & {
|
|
173
|
+
/**
|
|
174
|
+
* Product page URL. Defaults to the relative `/p/{uniqueSlug}`, which works
|
|
175
|
+
* on a Bitsnap custom domain. Embedded on another site, return the full
|
|
176
|
+
* URL of the product page.
|
|
177
|
+
*/
|
|
178
|
+
productHref?: (product: PublicListProduct) => string;
|
|
179
|
+
appearance?: ProductListAppearance;
|
|
180
|
+
/** Text overrides, applied whatever the locale. */
|
|
181
|
+
texts?: Partial<ProductListTexts>;
|
|
182
|
+
/** Replaces the content of a card. The card frame stays. */
|
|
183
|
+
renderItem?: (product: PublicListProduct, context: ProductListItemContext) => ReactNode;
|
|
184
|
+
/**
|
|
185
|
+
* Called by the "Add to cart" button instead of the default action
|
|
186
|
+
* (`Bitsnap.addProductToCart`). A rejected promise shows the error message.
|
|
187
|
+
*/
|
|
188
|
+
onAddToCart?: (product: PublicListProduct) => void | Promise<void>;
|
|
189
|
+
/** Open the cart drawer after the default add to cart. Defaults to `true`. */
|
|
190
|
+
showCartOnAdd?: boolean;
|
|
191
|
+
className?: string;
|
|
192
|
+
};
|
|
193
|
+
/**
|
|
194
|
+
* Responsive grid of the shop's products with pagination, loading, empty and
|
|
195
|
+
* error states. Cards link to the product page and can add to the cart.
|
|
196
|
+
*
|
|
197
|
+
* ```tsx
|
|
198
|
+
* <ProductList projectID="…" locale="pl-PL" initialData={firstPage} />
|
|
199
|
+
* ```
|
|
200
|
+
*
|
|
201
|
+
* It renders on the server: pass `initialData` (the first page, fetched on the
|
|
202
|
+
* server) to have the products in the HTML; without it the server renders the
|
|
203
|
+
* loading skeleton and the browser fetches the first page.
|
|
204
|
+
*/
|
|
205
|
+
declare function ProductList({ productHref, appearance, texts, renderItem, onAddToCart, showCartOnAdd, className, ...options }: ProductListProps): react_jsx_runtime.JSX.Element;
|
|
206
|
+
|
|
207
|
+
/**
|
|
208
|
+
* Formats a price in minor units (grosze, cents) for the locale, the same way
|
|
209
|
+
* the cart does (`amount / 100`). An unknown locale falls back to Polish and an
|
|
210
|
+
* invalid currency code to a plain number followed by the code.
|
|
211
|
+
*/
|
|
212
|
+
declare function formatProductPrice(amount: number, currency: string, locale?: string): string;
|
|
213
|
+
|
|
214
|
+
export { PRODUCT_LIST_SLOT_NAMES, ProductList, type ProductListAppearance, type ProductListAppearanceElements, type ProductListAppearanceTokens, type ProductListData, type ProductListItemContext, type ProductListProps, type ProductListSlotAppearance, type ProductListSlotName, type ProductListTextKey, type ProductListTexts, type ProductListTheme, type PublicListProduct, type UseProductsOptions, type UseProductsResult, formatProductPrice, useProducts };
|
package/dist/catalog.js
ADDED
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
"use strict";Object.defineProperty(exports,"__esModule",{value:!0});var r=require("./index.js");exports.ProductList=r.ProductList;exports.useProducts=r.useProducts;exports.formatProductPrice=r.formatProductPrice;exports.PRODUCT_LIST_SLOT_NAMES=r.PRODUCT_LIST_SLOT_NAMES;
|
|
2
|
+
//# sourceMappingURL=catalog.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/catalog/index.ts"],"sourcesContent":["Object.defineProperty(exports,\"__esModule\",{value:true});\nvar m=require(\"./index.js\");\nexports.ProductList=m.ProductList;\nexports.useProducts=m.useProducts;\nexports.formatProductPrice=m.formatProductPrice;\nexports.PRODUCT_LIST_SLOT_NAMES=m.PRODUCT_LIST_SLOT_NAMES;"],"mappings":"aAAA,OAAO,eAAe,QAAQ,aAAa,CAAC,MAAM,EAAI,CAAC,EACvD,IAAIA,EAAE,QAAQ,YAAY,EAC1B,QAAQ,YAAYA,EAAE,YACtB,QAAQ,YAAYA,EAAE,YACtB,QAAQ,mBAAmBA,EAAE,mBAC7B,QAAQ,wBAAwBA,EAAE","names":["m"]}
|
package/dist/catalog.mjs
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":[],"sourcesContent":[],"mappings":"","names":[]}
|
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
var u="https://bitsnap.pl",d=u;function h(t){console.log("setCustomHost",t),d=t}function x(t,e){return e.toLowerCase().startsWith("en")?t.en:t.pl}function g(t,e){let n={...t};if(e!=null)for(let[r,o]of Object.entries(e))o!=null&&(n[r]=o);return n}function c(t,e,n){return g(x(t,e),n)}function T(t,e){return t[e]??e}var y={en:{cart:"Cart",emptyCart:"Your cart is empty.",total:"Total:",delivery:"+ delivery",chooseCountry:"Choose a country",nextStep:"Next step",unavailableProducts:"Not all products are available."},pl:{cart:"Koszyk",emptyCart:"Brak produkt\xF3w w koszyku.",total:"Suma:",delivery:"+ dostawa",chooseCountry:"Wybierz kraj",nextStep:"Nast\u0119pny krok",unavailableProducts:"Nie wszystkie produkty s\u0105 dost\u0119pne w magazynie."}};function k(t,e){return c(y,t,e)}function R(t,e,n){return T(k(e,n),t)}var i="pl-PL",p="bitsnap-locale",a;function L(t){let e=t?.trim();a=e?e.toLowerCase()==="en"?"en-US":e.toLowerCase()==="pl"?i:e:void 0,typeof localStorage<"u"&&(a==null?localStorage.removeItem(p):localStorage.setItem(p,a))}function E(){return a??(typeof localStorage<"u"?localStorage.getItem(p)??i:i)}import{clsx as m}from"clsx";import{twMerge as f}from"tailwind-merge";function z(...t){return f(m(t))}function S(t){let e={};for(let[n,r]of Object.entries(t))r!=null&&(e[n]=r);return e}function b(t){return Object.values(t).some(e=>e!=null&&(e.className!=null||e.style!=null))}function C(t,e,n){let r={};for(let[o,l]of Object.entries(e)){let s=t[o];s!=null&&(r[l]=s)}for(let{token:o,variable:l}of n){let s=t[o];s!=null&&(r[l]=s)}return r}function H(t,e){let n=t?.theme??e.defaultTheme,r=S({...e.presets[n],...t?.tokens}),o=t?.elements??{};return{theme:n,isCustomized:t?.theme!=null||Object.keys(r).length>0||b(o),tokens:r,elements:o,boundaryStyle:C(r,e.variables,e.shadcnVariables)}}function N(t,e){return t[e]}export{z as a,u as b,d as c,h as d,H as e,N as f,x as g,c as h,R as i,i as j,L as k,E as l};
|
|
2
|
+
//# sourceMappingURL=chunk-3TENJTY4.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/components/checkout/constants.ts","../src/lib/texts.ts","../src/components/checkout/texts.ts","../src/components/checkout/locale.ts","../src/lib/utils.ts","../src/lib/appearance-core.ts"],"sourcesContent":["export const DEFAULT_HOST = \"https://bitsnap.pl\";\nexport let HOST = DEFAULT_HOST;\n\nexport function setCustomHost(host: string) {\n console.log(\"setCustomHost\", host);\n HOST = host;\n}\n","/**\n * Shared text machinery: typed string tables per locale, the locale fallback\n * and a merge with caller overrides. Each module (checkout, later returns)\n * supplies its own key type and default tables.\n */\n\n/** Strings of one locale, keyed by text key. */\nexport type TextTable<Key extends string> = Record<Key, string>;\n\n/** Default tables for the supported locales. */\nexport type LocaleTables<Key extends string> = {\n en: TextTable<Key>;\n pl: TextTable<Key>;\n};\n\n/**\n * Picks the table for a locale. Any locale starting with `en` (case\n * insensitive, so `en`, `en-US`, `EN-gb`) gets English; everything else,\n * including unknown locales, gets the Polish default.\n */\nexport function pickLocaleTable<Key extends string>(\n tables: LocaleTables<Key>,\n locale: string,\n): TextTable<Key> {\n return locale.toLowerCase().startsWith(\"en\") ? tables.en : tables.pl;\n}\n\n/**\n * Merges caller overrides over a table. Overrides apply regardless of the\n * locale; `undefined`/`null` entries are ignored so the default stays.\n */\nexport function mergeTexts<Key extends string>(\n table: TextTable<Key>,\n overrides?: Partial<TextTable<Key>>,\n): TextTable<Key> {\n const result: Record<string, string> = { ...table };\n\n if (overrides != null) {\n for (const [key, value] of Object.entries<string | undefined>(overrides)) {\n if (value != null) {\n result[key] = value;\n }\n }\n }\n\n return result as TextTable<Key>;\n}\n\n/** Locale table merged with the caller overrides. */\nexport function resolveTexts<Key extends string>(\n tables: LocaleTables<Key>,\n locale: string,\n overrides?: Partial<TextTable<Key>>,\n): TextTable<Key> {\n return mergeTexts(pickLocaleTable(tables, locale), overrides);\n}\n\n/** Looks up a single text. Unknown keys return the key itself. */\nexport function lookupText<Key extends string>(\n texts: TextTable<Key>,\n key: Key,\n): string {\n return (texts as Record<string, string | undefined>)[key] ?? key;\n}\n","import {\n lookupText,\n resolveTexts,\n type LocaleTables,\n} from \"@/src/lib/texts\";\n\n/**\n * Every string the checkout renders. Pass a partial object through the\n * `texts` prop of `BitsnapCheckout` to override any of them, whatever the\n * locale.\n */\nexport type CheckoutTexts = {\n /** Drawer title. */\n cart: string;\n /** Shown when the cart has no products. */\n emptyCart: string;\n /** Label next to the total price. */\n total: string;\n /** Delivery note next to the total price. */\n delivery: string;\n /** Country selector placeholder. */\n chooseCountry: string;\n /** Checkout button label. */\n nextStep: string;\n /** Error shown when some products are out of stock. */\n unavailableProducts: string;\n};\n\nexport type CheckoutTextKey = keyof CheckoutTexts;\n\nexport const CHECKOUT_TEXT_TABLES: LocaleTables<CheckoutTextKey> = {\n en: {\n cart: \"Cart\",\n emptyCart: \"Your cart is empty.\",\n total: \"Total:\",\n delivery: \"+ delivery\",\n chooseCountry: \"Choose a country\",\n nextStep: \"Next step\",\n unavailableProducts: \"Not all products are available.\",\n },\n pl: {\n cart: \"Koszyk\",\n emptyCart: \"Brak produktów w koszyku.\",\n total: \"Suma:\",\n delivery: \"+ dostawa\",\n chooseCountry: \"Wybierz kraj\",\n nextStep: \"Następny krok\",\n unavailableProducts: \"Nie wszystkie produkty są dostępne w magazynie.\",\n },\n};\n\n/** Default texts for a locale merged with the caller overrides. */\nexport function resolveCheckoutTexts(\n locale: string,\n overrides?: Partial<CheckoutTexts>,\n): CheckoutTexts {\n return resolveTexts(CHECKOUT_TEXT_TABLES, locale, overrides);\n}\n\nexport function getCheckoutText(\n key: CheckoutTextKey,\n locale: string,\n overrides?: Partial<CheckoutTexts>,\n): string {\n return lookupText(resolveCheckoutTexts(locale, overrides), key);\n}\n","import { pickLocaleTable } from \"@/src/lib/texts\";\nimport { CHECKOUT_TEXT_TABLES } from \"./texts\";\n\nexport const DEFAULT_LOCALE = \"pl-PL\" as const;\nconst localeStorageKey = \"bitsnap-locale\";\n\nlet activeLocale: string | undefined;\n\nexport function setLocale(locale?: string): void {\n const value = locale?.trim();\n activeLocale = value\n ? value.toLowerCase() === \"en\"\n ? \"en-US\"\n : value.toLowerCase() === \"pl\"\n ? DEFAULT_LOCALE\n : value\n : undefined;\n if (typeof localStorage !== \"undefined\") {\n if (activeLocale == null) {\n localStorage.removeItem(localeStorageKey);\n } else {\n localStorage.setItem(localeStorageKey, activeLocale);\n }\n }\n}\n\nexport function getLocale(): string {\n if (activeLocale != null) {\n return activeLocale;\n }\n if (typeof localStorage !== \"undefined\") {\n return localStorage.getItem(localeStorageKey) ?? DEFAULT_LOCALE;\n }\n return DEFAULT_LOCALE;\n}\n\nexport function translate(key: string, locale: string = getLocale()): string {\n return (\n (pickLocaleTable(CHECKOUT_TEXT_TABLES, locale) as Record<string, string>)[\n key\n ] ?? key\n );\n}\n","import { type ClassValue, clsx } from \"clsx\";\nimport { twMerge } from \"tailwind-merge\";\n\nexport function cn(...inputs: ClassValue[]) {\n return twMerge(clsx(inputs));\n}\n\nexport type Modify<T, R> = Omit<T, keyof R> & R;\n\nexport type Partial<T> = {\n [P in keyof T]?: T[P];\n};\n","import type { CSSProperties } from \"react\";\n\n/**\n * Generic building blocks shared by the appearance modules (checkout, and\n * later returns). Each module supplies its own token to CSS variable map, theme\n * presets and shadcn mapping, and keeps its own public types. Everything here\n * is pure so it can be tested without a DOM.\n */\n\n/** Caller overrides for a single slot. */\nexport type SlotAppearance = {\n /** Merged after the built-in classes with `cn`, so Tailwind conflicts resolve. */\n className?: string;\n /** Merged after the built-in inline styles. */\n style?: CSSProperties;\n};\n\n/** Typed partial map of slot name to its overrides. */\nexport type AppearanceElements<Slot extends string> = Partial<\n Record<Slot, SlotAppearance>\n>;\n\n/** CSS custom property used for each token. */\nexport type TokenVariables<Token extends string> = Readonly<\n Record<Token, string>\n>;\n\n/**\n * Remaps a token onto a shadcn theme variable (`--background`, `--ring`, ...)\n * so shared UI primitives follow the module's tokens. Only written when the\n * token is in effect.\n */\nexport type ShadcnVariableMapping<Token extends string> = readonly {\n token: Token;\n variable: string;\n}[];\n\nexport type AppearanceCoreConfig<Token extends string, Theme extends string> = {\n /** Theme used when the caller does not select one. */\n defaultTheme: Theme;\n /** Partial token sets applied underneath the caller tokens. */\n presets: Record<Theme, Partial<Record<Token, string>>>;\n variables: TokenVariables<Token>;\n shadcnVariables: ShadcnVariableMapping<Token>;\n};\n\nexport type ResolvedAppearanceCore<\n Token extends string,\n Theme extends string,\n Slot extends string,\n> = {\n theme: Theme;\n /** `true` as soon as the caller passed a theme, a token or a slot override. */\n isCustomized: boolean;\n /** Tokens that are in effect. Empty entries were dropped. */\n tokens: Partial<Record<Token, string>>;\n elements: AppearanceElements<Slot>;\n /** Inline custom properties for the theme boundary. */\n boundaryStyle: CSSProperties;\n};\n\n/** Drops `undefined`/`null` tokens so unset values keep the stylesheet default. */\nexport function omitUndefined<Token extends string>(\n tokens: Partial<Record<Token, string>>,\n): Partial<Record<Token, string>> {\n const result: Record<string, unknown> = {};\n\n for (const [key, value] of Object.entries(tokens)) {\n if (value != null) {\n result[key] = value;\n }\n }\n\n return result as Partial<Record<Token, string>>;\n}\n\nexport function hasAnyElement<Slot extends string>(\n elements: AppearanceElements<Slot>,\n): boolean {\n return Object.values<SlotAppearance | undefined>(elements).some(\n (element) =>\n element != null && (element.className != null || element.style != null),\n );\n}\n\n/**\n * Token to CSS variable resolution, followed by the shadcn remapping. Only\n * tokens that are in effect produce a variable.\n */\nexport function resolveBoundaryStyle<Token extends string>(\n tokens: Partial<Record<Token, string>>,\n variables: TokenVariables<Token>,\n shadcnVariables: ShadcnVariableMapping<Token>,\n): CSSProperties {\n const style: Record<string, string> = {};\n\n for (const [token, variable] of Object.entries<string>(variables)) {\n const value = tokens[token as Token];\n if (value != null) {\n style[variable] = value;\n }\n }\n\n for (const { token, variable } of shadcnVariables) {\n const value = tokens[token];\n if (value != null) {\n style[variable] = value;\n }\n }\n\n return style as CSSProperties;\n}\n\n/**\n * Resolves theme, tokens, slot overrides and the boundary style. The resolver\n * never invents values: a token is only present when the caller provided it or\n * selected a theme preset that carries it.\n */\nexport function resolveAppearanceCore<\n Token extends string,\n Theme extends string,\n Slot extends string,\n>(\n appearance:\n | {\n theme?: Theme;\n tokens?: Partial<Record<Token, string>>;\n elements?: AppearanceElements<Slot>;\n }\n | undefined,\n config: AppearanceCoreConfig<Token, Theme>,\n): ResolvedAppearanceCore<Token, Theme, Slot> {\n const theme: Theme = appearance?.theme ?? config.defaultTheme;\n\n const tokens = omitUndefined<Token>({\n ...config.presets[theme],\n ...appearance?.tokens,\n });\n\n const elements = appearance?.elements ?? {};\n\n return {\n theme,\n isCustomized:\n appearance?.theme != null ||\n Object.keys(tokens).length > 0 ||\n hasAnyElement(elements),\n tokens,\n elements,\n boundaryStyle: resolveBoundaryStyle(\n tokens,\n config.variables,\n config.shadcnVariables,\n ),\n };\n}\n\n/** Caller overrides for a slot, if any were provided. */\nexport function getSlotAppearance<Slot extends string>(\n elements: AppearanceElements<Slot>,\n slot: Slot,\n): SlotAppearance | undefined {\n return elements[slot];\n}\n"],"mappings":"AAAO,IAAMA,EAAe,qBACjBC,EAAOD,EAEX,SAASE,EAAcC,EAAc,CAC1C,QAAQ,IAAI,gBAAiBA,CAAI,EACjCF,EAAOE,CACT,CCcO,SAASC,EACdC,EACAC,EAC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AC5B,OAAOb,EAASa,CAAI,CACtB","names":["DEFAULT_HOST","HOST","setCustomHost","host","pickLocaleTable","tables","locale","mergeTexts","table","overrides","result","key","value","resolveTexts","lookupText","texts","CHECKOUT_TEXT_TABLES","resolveCheckoutTexts","locale","overrides","resolveTexts","getCheckoutText","key","lookupText","DEFAULT_LOCALE","localeStorageKey","activeLocale","setLocale","locale","value","getLocale","clsx","twMerge","cn","inputs","omitUndefined","tokens","result","key","value","hasAnyElement","elements","element","resolveBoundaryStyle","variables","shadcnVariables","style","token","variable","resolveAppearanceCore","appearance","config","theme","getSlotAppearance","slot"]}
|