@occluze/tether 0.6.7 → 0.7.0
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 +11 -11
- package/dist/esm/astro.js +2 -2
- package/dist/esm/chunks/account-UIPWJQ3Y.js +1 -0
- package/dist/esm/chunks/account-pages-6ROA6Y4V.js +1 -0
- package/dist/esm/chunks/analytics-2V632IRV.js +1 -0
- package/dist/esm/chunks/chunk-4GCXM764.js +1 -0
- package/dist/esm/chunks/chunk-56FCLJJD.js +1 -0
- package/dist/esm/chunks/chunk-5Z5O3767.js +1 -0
- package/dist/esm/chunks/chunk-6OZJCAGZ.js +1 -0
- package/dist/esm/chunks/chunk-A5SYCVQM.js +1 -0
- package/dist/esm/chunks/chunk-BA4LQJJQ.js +1 -0
- package/dist/esm/chunks/chunk-BFTZR4OB.js +4 -0
- package/dist/esm/chunks/chunk-C5JYQCWH.js +1 -0
- package/dist/esm/chunks/chunk-E5YO6274.js +1 -0
- package/dist/esm/chunks/chunk-MPDWM2NN.js +1 -0
- package/dist/esm/chunks/chunk-T44MUL4Y.js +1 -0
- package/dist/esm/chunks/chunk-YLUULATY.js +1 -0
- package/dist/esm/chunks/diagnose-3FEKRIEK.js +14 -0
- package/dist/esm/chunks/extras-6POFBNOP.js +1 -0
- package/dist/esm/chunks/markets-ui-FD6NI2OG.js +1 -0
- package/dist/esm/chunks/search-UJ73YBQ5.js +1 -0
- package/dist/esm/index.js +1 -1
- package/dist/esm/server.js +2 -1
- package/dist/presets/barba.esm.js +55 -39
- package/dist/tether.account-pages.js +781 -495
- package/dist/tether.account-pages.min.js +1 -1
- package/dist/tether.account.js +462 -381
- package/dist/tether.account.min.js +1 -1
- package/dist/tether.analytics.js +299 -194
- package/dist/tether.analytics.min.js +1 -1
- package/dist/tether.diagnose.js +354 -262
- package/dist/tether.diagnose.min.js +2 -2
- package/dist/tether.extras.js +82 -45
- package/dist/tether.extras.min.js +1 -1
- package/dist/tether.js +3653 -2116
- package/dist/tether.markets.js +238 -150
- package/dist/tether.markets.min.js +1 -1
- package/dist/tether.min.js +3 -3
- package/dist/tether.min.js.map +4 -4
- package/dist/tether.search.js +207 -136
- package/dist/tether.search.min.js +1 -1
- package/dist/types/server/src/shared/account-orders.d.ts +44 -0
- package/dist/types/server/src/shared/account-routes.d.ts +153 -0
- package/dist/types/server/src/shared/api-versions.d.ts +13 -0
- package/dist/types/server/src/shared/error-message.d.ts +2 -0
- package/dist/types/server/src/shared/json.d.ts +25 -0
- package/dist/types/server/src/shared/market-codes.d.ts +16 -0
- package/dist/types/src/account/addresses-view.d.ts +5 -0
- package/dist/types/src/account/answers.d.ts +40 -0
- package/dist/types/src/account/markup.d.ts +19 -0
- package/dist/types/src/account/operations.d.ts +41 -0
- package/dist/types/src/account/order-lines.d.ts +13 -0
- package/dist/types/src/account/order-list.d.ts +12 -0
- package/dist/types/src/account/order-page.d.ts +6 -0
- package/dist/types/src/account/page-answers.d.ts +182 -0
- package/dist/types/src/account/page-events.d.ts +2 -0
- package/dist/types/src/account/server-client.d.ts +60 -0
- package/dist/types/src/account/subscriptions-view.d.ts +2 -0
- package/dist/types/src/account-api.d.ts +18 -0
- package/dist/types/src/account-marks.d.ts +15 -0
- package/dist/types/src/account-pages.d.ts +8 -0
- package/dist/types/src/account.d.ts +64 -0
- package/dist/types/src/amounts.d.ts +12 -0
- package/dist/types/src/analytics-shopify.d.ts +41 -0
- package/dist/types/src/analytics.d.ts +2 -0
- package/dist/types/src/api-version.d.ts +28 -0
- package/dist/types/src/astro.d.ts +42 -0
- package/dist/types/src/cart/cart-shape.d.ts +43 -0
- package/dist/types/src/cart/checkout.d.ts +16 -0
- package/dist/types/src/cart/drawer.d.ts +18 -0
- package/dist/types/src/cart/mutations.d.ts +79 -0
- package/dist/types/src/cart/render.d.ts +17 -0
- package/dist/types/src/cart/store.d.ts +182 -0
- package/dist/types/src/cart.d.ts +106 -0
- package/dist/types/src/client.d.ts +100 -0
- package/dist/types/src/collection.d.ts +25 -0
- package/dist/types/src/config-sections.d.ts +40 -0
- package/dist/types/src/config.d.ts +185 -0
- package/dist/types/src/controls/cart-controls.d.ts +2 -0
- package/dist/types/src/controls/discount.d.ts +2 -0
- package/dist/types/src/controls/extras.d.ts +5 -0
- package/dist/types/src/controls/navigation.d.ts +12 -0
- package/dist/types/src/diagnose-markup.d.ts +19 -0
- package/dist/types/src/diagnose.d.ts +60 -0
- package/dist/types/src/dom.d.ts +75 -0
- package/dist/types/src/extras.d.ts +21 -0
- package/dist/types/src/fragments.d.ts +158 -0
- package/dist/types/src/globals.d.ts +15 -0
- package/dist/types/src/images.d.ts +20 -0
- package/dist/types/src/index.d.ts +167 -0
- package/dist/types/src/initial.d.ts +56 -0
- package/dist/types/src/lazy.d.ts +28 -0
- package/dist/types/src/loader.d.ts +84 -0
- package/dist/types/src/market-codes.d.ts +6 -0
- package/dist/types/src/markets-ui.d.ts +32 -0
- package/dist/types/src/markets.d.ts +72 -0
- package/dist/types/src/markup.d.ts +131 -0
- package/dist/types/src/mounting.d.ts +46 -0
- package/dist/types/src/page-market.d.ts +27 -0
- package/dist/types/src/presets/barba.d.ts +56 -0
- package/dist/types/src/product-events.d.ts +2 -0
- package/dist/types/src/product-render.d.ts +17 -0
- package/dist/types/src/product-shape.d.ts +88 -0
- package/dist/types/src/product-state.d.ts +110 -0
- package/dist/types/src/product.d.ts +66 -0
- package/dist/types/src/repeaters.d.ts +16 -0
- package/dist/types/src/search.d.ts +33 -0
- package/dist/types/src/selling-plans.d.ts +64 -0
- package/dist/types/src/server.d.ts +88 -0
- package/dist/types/src/shopify-values.d.ts +46 -0
- package/dist/types/src/status.d.ts +33 -0
- package/dist/types/src/storage.d.ts +12 -0
- package/dist/types/src/store-html.d.ts +39 -0
- package/dist/types/src/storefront/catalog.d.ts +38 -0
- package/dist/types/src/storefront/json-ld.d.ts +20 -0
- package/dist/types/src/variant-render.d.ts +14 -0
- package/package.json +42 -22
- package/src/account/addresses-view.ts +58 -0
- package/src/account/answers.ts +79 -0
- package/src/account/markup.ts +36 -0
- package/src/account/operations.ts +145 -0
- package/src/account/order-lines.ts +75 -0
- package/src/account/order-list.ts +107 -0
- package/src/account/order-page.ts +137 -0
- package/src/account/page-answers.ts +317 -0
- package/src/account/page-events.ts +253 -0
- package/src/account/server-client.ts +183 -0
- package/src/account/subscriptions-view.ts +115 -0
- package/src/account-api.ts +98 -0
- package/src/account-marks.ts +35 -0
- package/src/account-pages.ts +81 -0
- package/src/account.ts +284 -0
- package/src/amounts.ts +64 -0
- package/src/analytics-shopify.ts +246 -0
- package/src/analytics.ts +315 -0
- package/src/api-version.ts +79 -0
- package/src/astro.ts +272 -0
- package/src/cart/cart-shape.ts +25 -0
- package/src/cart/checkout.ts +101 -0
- package/src/cart/drawer.ts +125 -0
- package/src/cart/mutations.ts +237 -0
- package/src/cart/render.ts +266 -0
- package/src/cart/store.ts +279 -0
- package/src/cart.ts +345 -0
- package/src/client.ts +391 -0
- package/src/collection.ts +175 -0
- package/src/config-sections.ts +284 -0
- package/src/config.ts +480 -0
- package/src/controls/cart-controls.ts +123 -0
- package/src/controls/discount.ts +75 -0
- package/src/controls/extras.ts +54 -0
- package/src/controls/navigation.ts +77 -0
- package/src/diagnose-markup.ts +298 -0
- package/src/diagnose.ts +294 -0
- package/src/dom.ts +268 -0
- package/src/extras.ts +136 -0
- package/src/fragments.ts +261 -0
- package/src/globals.d.ts +15 -0
- package/src/images.ts +91 -0
- package/src/index.ts +415 -0
- package/src/initial.ts +101 -0
- package/src/lazy-iife.ts +197 -0
- package/src/lazy.ts +42 -0
- package/src/loader.ts +363 -0
- package/src/market-codes.ts +6 -0
- package/src/markets-ui.ts +227 -0
- package/src/markets.ts +246 -0
- package/src/markup.ts +127 -0
- package/src/mounting.ts +264 -0
- package/src/page-market.ts +110 -0
- package/src/part-integrity.ts +7 -0
- package/src/parts/account-pages.ts +7 -0
- package/src/parts/account.ts +7 -0
- package/src/parts/analytics.ts +7 -0
- package/src/parts/diagnose.ts +7 -0
- package/src/parts/extras.ts +7 -0
- package/src/parts/markets.ts +7 -0
- package/src/parts/search.ts +7 -0
- package/src/presets/barba.ts +194 -0
- package/src/product-events.ts +115 -0
- package/src/product-render.ts +218 -0
- package/src/product-shape.ts +49 -0
- package/src/product-state.ts +318 -0
- package/src/product.ts +308 -0
- package/src/repeaters.ts +161 -0
- package/src/search.ts +305 -0
- package/src/selling-plans.ts +145 -0
- package/src/server.ts +211 -0
- package/src/shopify-values.ts +91 -0
- package/src/status.ts +106 -0
- package/src/storage.ts +34 -0
- package/src/store-html.ts +359 -0
- package/src/storefront/catalog.ts +196 -0
- package/src/storefront/json-ld.ts +144 -0
- package/src/variant-render.ts +139 -0
- package/dist/esm/chunks/account-Q6E2TFEV.js +0 -1
- package/dist/esm/chunks/account-pages-UZXR4R5F.js +0 -1
- package/dist/esm/chunks/analytics-IJBKATUP.js +0 -1
- package/dist/esm/chunks/chunk-4QJKLPYR.js +0 -1
- package/dist/esm/chunks/chunk-64TUD3QR.js +0 -1
- package/dist/esm/chunks/chunk-AJLPU2JC.js +0 -4
- package/dist/esm/chunks/chunk-FIOZPPC5.js +0 -1
- package/dist/esm/chunks/chunk-K2YEQAIH.js +0 -1
- package/dist/esm/chunks/chunk-KIDH76B7.js +0 -1
- package/dist/esm/chunks/chunk-PAYT5ZD7.js +0 -1
- package/dist/esm/chunks/chunk-RREHGH4A.js +0 -1
- package/dist/esm/chunks/chunk-SSJT43CJ.js +0 -1
- package/dist/esm/chunks/chunk-VC46IEJQ.js +0 -1
- package/dist/esm/chunks/diagnose-3WVAWNTX.js +0 -14
- package/dist/esm/chunks/extras-7I7WJX35.js +0 -1
- package/dist/esm/chunks/markets-ui-545XLFTE.js +0 -1
- package/dist/esm/chunks/search-NILMGYXG.js +0 -1
- package/src/account-pages.js +0 -318
- package/src/account.js +0 -385
- package/src/analytics.js +0 -232
- package/src/api-version.js +0 -35
- package/src/astro.js +0 -101
- package/src/cart.js +0 -559
- package/src/client.js +0 -131
- package/src/collection.js +0 -114
- package/src/config.js +0 -85
- package/src/diagnose.js +0 -246
- package/src/dom.js +0 -288
- package/src/extras.js +0 -63
- package/src/fragments.js +0 -144
- package/src/index.js +0 -395
- package/src/initial.js +0 -75
- package/src/lazy-iife.js +0 -46
- package/src/lazy.js +0 -18
- package/src/loader.js +0 -198
- package/src/markets-ui.js +0 -90
- package/src/markets.js +0 -133
- package/src/mounting.js +0 -154
- package/src/parts/account-pages.js +0 -3
- package/src/parts/account.js +0 -3
- package/src/parts/analytics.js +0 -3
- package/src/parts/diagnose.js +0 -3
- package/src/parts/extras.js +0 -3
- package/src/parts/markets.js +0 -3
- package/src/parts/search.js +0 -3
- package/src/presets/barba.js +0 -100
- package/src/product.js +0 -570
- package/src/search.js +0 -153
- package/src/selling-plans.js +0 -94
- package/src/server.js +0 -252
- package/src/status.js +0 -66
- package/types/astro.d.ts +0 -17
- package/types/barba.d.ts +0 -16
- package/types/index.d.ts +0 -426
- package/types/server.d.ts +0 -110
package/dist/tether.markets.js
CHANGED
|
@@ -5,7 +5,7 @@
|
|
|
5
5
|
__defProp(target, name, { get: all[name], enumerable: true });
|
|
6
6
|
};
|
|
7
7
|
|
|
8
|
-
// src/markets-ui.
|
|
8
|
+
// src/markets-ui.ts
|
|
9
9
|
var markets_ui_exports = {};
|
|
10
10
|
__export(markets_ui_exports, {
|
|
11
11
|
detectMarket: () => detectMarket,
|
|
@@ -14,187 +14,253 @@
|
|
|
14
14
|
setCountry: () => setCountry
|
|
15
15
|
});
|
|
16
16
|
|
|
17
|
-
// tether-core:config.
|
|
18
|
-
var m = window.Tether.__core["config.
|
|
19
|
-
var
|
|
17
|
+
// tether-core:config.ts
|
|
18
|
+
var m = window.Tether.__core["config.ts"];
|
|
19
|
+
var [cfg, isConfigured, log, MARKET_SOURCES, parseMarkets, reportError, warn] = m;
|
|
20
20
|
|
|
21
|
-
// tether-core:client.
|
|
22
|
-
var m2 = window.Tether.__core["client.
|
|
23
|
-
var
|
|
21
|
+
// tether-core:client.ts
|
|
22
|
+
var m2 = window.Tether.__core["client.ts"];
|
|
23
|
+
var [endpoint, gql, orNull, shaped, TetherError] = m2;
|
|
24
24
|
|
|
25
|
-
// tether-core:cart.
|
|
26
|
-
var m3 = window.Tether.__core["cart.
|
|
27
|
-
var
|
|
25
|
+
// tether-core:cart.ts
|
|
26
|
+
var m3 = window.Tether.__core["cart.ts"];
|
|
27
|
+
var [Cart] = m3;
|
|
28
28
|
|
|
29
|
-
// tether-core:collection.
|
|
30
|
-
var m4 = window.Tether.__core["collection.
|
|
31
|
-
var
|
|
29
|
+
// tether-core:collection.ts
|
|
30
|
+
var m4 = window.Tether.__core["collection.ts"];
|
|
31
|
+
var [listSelector] = m4;
|
|
32
32
|
|
|
33
|
-
// tether-core:loader.
|
|
34
|
-
var m5 = window.Tether.__core["loader.
|
|
35
|
-
var
|
|
33
|
+
// tether-core:loader.ts
|
|
34
|
+
var m5 = window.Tether.__core["loader.ts"];
|
|
35
|
+
var [clearProductCache, getProduct] = m5;
|
|
36
36
|
|
|
37
|
-
// tether-core:dom.
|
|
38
|
-
var m6 = window.Tether.__core["dom.
|
|
39
|
-
var
|
|
37
|
+
// tether-core:dom.ts
|
|
38
|
+
var m6 = window.Tether.__core["dom.ts"];
|
|
39
|
+
var [ANALYTICS_EVENTS, attr, attributesFromJson, emit, formatDate, formatMoney, get, has, hasTemplate, isOwnEvent, parseJSONAttr, productUrl, qsa, repeat, sel, setImage, setText, show] = m6;
|
|
40
40
|
|
|
41
|
-
// tether-core:mounting.
|
|
42
|
-
var m7 = window.Tether.__core["mounting.
|
|
43
|
-
var
|
|
41
|
+
// tether-core:mounting.ts
|
|
42
|
+
var m7 = window.Tether.__core["mounting.ts"];
|
|
43
|
+
var [liveLists, liveProducts, mountedProducts, mountProduct, pruneLive, within] = m7;
|
|
44
44
|
|
|
45
|
-
//
|
|
46
|
-
var
|
|
47
|
-
var
|
|
45
|
+
// tether-core:market-codes.ts
|
|
46
|
+
var m8 = window.Tether.__core["market-codes.ts"];
|
|
47
|
+
var [toCountry, toLanguage] = m8;
|
|
48
|
+
|
|
49
|
+
// src/storage.ts
|
|
50
|
+
function getStored(key, area = "localStorage") {
|
|
51
|
+
try {
|
|
52
|
+
return window[area].getItem(key);
|
|
53
|
+
} catch {
|
|
54
|
+
return null;
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
function setStored(key, value, area = "localStorage") {
|
|
58
|
+
try {
|
|
59
|
+
window[area].setItem(key, value);
|
|
60
|
+
} catch {
|
|
61
|
+
}
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
// src/markets.ts
|
|
65
|
+
var DEFAULT_COOKIE = "tether_country";
|
|
48
66
|
var storageKey = () => `${cfg.prefix}:market:${cfg.domain}`;
|
|
49
|
-
var
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
67
|
+
var pageStorage = { getItem: (key) => getStored(key) };
|
|
68
|
+
function pageEnv() {
|
|
69
|
+
const hasWindow = typeof window !== "undefined";
|
|
70
|
+
return {
|
|
71
|
+
document: typeof document !== "undefined" ? document : null,
|
|
72
|
+
location: hasWindow ? window.location : null,
|
|
73
|
+
storage: pageStorage,
|
|
74
|
+
global: hasWindow ? window : {}
|
|
75
|
+
};
|
|
76
|
+
}
|
|
77
|
+
function parseJsonOrNull(text) {
|
|
78
|
+
try {
|
|
79
|
+
return JSON.parse(text);
|
|
80
|
+
} catch (error) {
|
|
81
|
+
if (error instanceof SyntaxError) return null;
|
|
82
|
+
throw error;
|
|
83
|
+
}
|
|
84
|
+
}
|
|
85
|
+
function toMarket(value) {
|
|
86
|
+
if (typeof value !== "object" || value === null) return null;
|
|
87
|
+
const country = toCountry(Reflect.get(value, "country"));
|
|
88
|
+
if (!country) return null;
|
|
89
|
+
const locale = Reflect.get(value, "locale");
|
|
90
|
+
return {
|
|
91
|
+
country,
|
|
92
|
+
language: toLanguage(Reflect.get(value, "language")) ?? void 0,
|
|
93
|
+
locale: typeof locale === "string" && locale ? locale : void 0
|
|
94
|
+
};
|
|
64
95
|
}
|
|
65
|
-
function
|
|
66
|
-
const
|
|
67
|
-
|
|
68
|
-
if (REGIONAL_LANGUAGES.has(raw)) return raw;
|
|
69
|
-
const primary = raw.split("_")[0];
|
|
70
|
-
return /^[A-Z]{2,3}$/.test(primary) ? primary : null;
|
|
96
|
+
function readSavedMarket(storage = pageStorage) {
|
|
97
|
+
const text = storage.getItem(storageKey());
|
|
98
|
+
return text ? toMarket(parseJsonOrNull(text)) : null;
|
|
71
99
|
}
|
|
72
100
|
function readCookie(doc, name) {
|
|
73
101
|
if (!doc || !name) return null;
|
|
74
|
-
const
|
|
75
|
-
return
|
|
102
|
+
const cookie = doc.cookie.split(";").map((part) => part.trim()).find((part) => part.startsWith(`${name}=`));
|
|
103
|
+
return cookie ? decodeURIComponent(cookie.slice(name.length + 1)) : null;
|
|
76
104
|
}
|
|
77
|
-
|
|
105
|
+
function lookupLocale(locales, key) {
|
|
78
106
|
if (!locales || !key) return null;
|
|
79
|
-
const
|
|
80
|
-
const found = Object.keys(locales).find((
|
|
81
|
-
return found ? locales[found] : null;
|
|
82
|
-
}
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
107
|
+
const wanted = key.toLowerCase();
|
|
108
|
+
const found = Object.keys(locales).find((name) => name.toLowerCase() === wanted);
|
|
109
|
+
return found ? locales[found] ?? null : null;
|
|
110
|
+
}
|
|
111
|
+
function readServerHint(markets, env) {
|
|
112
|
+
const meta = (name) => env.document?.querySelector(`meta[name="${name}"]`)?.getAttribute("content");
|
|
113
|
+
const globalCountry = Reflect.get(env.global, "TETHER_COUNTRY");
|
|
114
|
+
const globalLanguage = Reflect.get(env.global, "TETHER_LANGUAGE");
|
|
115
|
+
const pageCountry = meta("tether-country") || readCookie(env.document, markets.cookie || DEFAULT_COOKIE);
|
|
116
|
+
return {
|
|
117
|
+
country: globalCountry || pageCountry,
|
|
118
|
+
language: globalLanguage || meta("tether-language")
|
|
119
|
+
};
|
|
120
|
+
}
|
|
121
|
+
function readWebflowLocale(markets, env) {
|
|
122
|
+
const segment = (env.location?.pathname ?? "/").split("/").find((part) => part !== "");
|
|
123
|
+
const fromPath = lookupLocale(markets.locales, segment);
|
|
124
|
+
if (fromPath) return fromPath;
|
|
125
|
+
const lang = env.document?.documentElement.getAttribute("lang");
|
|
126
|
+
if (!lang) return null;
|
|
127
|
+
const mapped = lookupLocale(markets.locales, lang) ?? lookupLocale(markets.locales, lang.split("-")[0]);
|
|
128
|
+
if (mapped) return { locale: lang, ...mapped };
|
|
129
|
+
if (markets.locales && markets.strict) return null;
|
|
130
|
+
const region = lang.split("-")[1];
|
|
131
|
+
return { language: lang, country: region?.length === 2 ? region : null, locale: lang };
|
|
132
|
+
}
|
|
133
|
+
function readSource(source, markets, env) {
|
|
134
|
+
switch (source) {
|
|
135
|
+
case "saved":
|
|
136
|
+
return markets.remember === false ? null : readSavedMarket(env.storage);
|
|
137
|
+
case "server":
|
|
138
|
+
return readServerHint(markets, env);
|
|
139
|
+
case "webflow":
|
|
140
|
+
return readWebflowLocale(markets, env);
|
|
141
|
+
}
|
|
142
|
+
}
|
|
143
|
+
function sourcesFor(detect) {
|
|
144
|
+
if (!detect) return ["saved"];
|
|
145
|
+
return detect === true ? MARKET_SOURCES : detect;
|
|
146
|
+
}
|
|
147
|
+
function detectMarket(markets = cfg.markets, env = pageEnv()) {
|
|
148
|
+
const config = (markets === cfg.markets ? markets : parseMarkets(markets)) ?? {};
|
|
149
|
+
if (config.detect === false) return {};
|
|
150
|
+
const sources = {};
|
|
151
|
+
const found = { sources };
|
|
152
|
+
for (const source of sourcesFor(config.detect)) {
|
|
153
|
+
const hint = readSource(source, config, env);
|
|
154
|
+
if (!hint) continue;
|
|
155
|
+
const country = toCountry(hint.country);
|
|
156
|
+
const language = toLanguage(hint.language);
|
|
157
|
+
const locale = typeof hint.locale === "string" && hint.locale ? hint.locale : null;
|
|
158
|
+
if (country && !found.country) {
|
|
159
|
+
found.country = country;
|
|
160
|
+
sources.country = source;
|
|
161
|
+
}
|
|
162
|
+
if (language && !found.language) {
|
|
163
|
+
found.language = language;
|
|
164
|
+
sources.language = source;
|
|
165
|
+
}
|
|
166
|
+
if (locale && !found.locale) {
|
|
167
|
+
found.locale = locale;
|
|
168
|
+
sources.locale = source;
|
|
90
169
|
}
|
|
91
|
-
},
|
|
92
|
-
server(m8, env) {
|
|
93
|
-
const meta = (name) => env.document?.querySelector?.(`meta[name="${name}"]`)?.getAttribute("content");
|
|
94
|
-
const country = env.global.TETHER_COUNTRY || meta("tether-country") || readCookie(env.document, m8.cookie || "tether_country");
|
|
95
|
-
const language = env.global.TETHER_LANGUAGE || meta("tether-language");
|
|
96
|
-
return { country, language };
|
|
97
|
-
},
|
|
98
|
-
webflow(m8, env) {
|
|
99
|
-
const segment = (env.location?.pathname || "/").split("/").filter(Boolean)[0];
|
|
100
|
-
const fromPath = lookup(m8.locales, segment);
|
|
101
|
-
if (fromPath) return fromPath;
|
|
102
|
-
const lang = env.document?.documentElement?.getAttribute("lang");
|
|
103
|
-
if (!lang) return null;
|
|
104
|
-
const mapped = lookup(m8.locales, lang) || lookup(m8.locales, lang.split("-")[0]);
|
|
105
|
-
if (mapped) return { locale: lang, ...mapped };
|
|
106
|
-
if (m8.locales && m8.strict) return null;
|
|
107
|
-
const region = lang.split("-")[1];
|
|
108
|
-
return { language: lang, country: region && region.length === 2 ? region : null, locale: lang };
|
|
109
170
|
}
|
|
110
|
-
|
|
111
|
-
function detectMarket(markets = cfg.markets, env = defaultEnv()) {
|
|
112
|
-
const m8 = markets || {};
|
|
113
|
-
if (m8.detect === false) return {};
|
|
114
|
-
const list = !m8.detect ? ["saved"] : m8.detect === true ? ["saved", "server", "webflow"] : [].concat(m8.detect);
|
|
115
|
-
markets = m8;
|
|
116
|
-
const out = { sources: {} };
|
|
117
|
-
list.forEach((name) => {
|
|
118
|
-
const r = readers[name]?.(markets, env);
|
|
119
|
-
if (!r) return;
|
|
120
|
-
const vals = { country: toCountry(r.country), language: toLanguage(r.language), locale: r.locale || null };
|
|
121
|
-
Object.entries(vals).forEach(([k, v]) => {
|
|
122
|
-
if (v && !out[k]) {
|
|
123
|
-
out[k] = v;
|
|
124
|
-
out.sources[k] = name;
|
|
125
|
-
}
|
|
126
|
-
});
|
|
127
|
-
});
|
|
128
|
-
return out;
|
|
171
|
+
return found;
|
|
129
172
|
}
|
|
130
173
|
function rememberMarket(market) {
|
|
131
174
|
if (cfg.markets?.remember === false) return;
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
} catch {
|
|
135
|
-
}
|
|
175
|
+
const saved = { country: market.country, language: market.language || void 0, locale: market.locale || void 0 };
|
|
176
|
+
setStored(storageKey(), JSON.stringify(saved));
|
|
136
177
|
}
|
|
178
|
+
|
|
179
|
+
// src/markets-ui.ts
|
|
180
|
+
var DEFAULT_LABEL = "{name} ({currency})";
|
|
181
|
+
var DEFAULT_BIND = "name";
|
|
137
182
|
var localizationPromise = null;
|
|
138
183
|
function clearLocalization() {
|
|
139
184
|
localizationPromise = null;
|
|
140
185
|
}
|
|
186
|
+
var LOCALIZATION_QUERY = `query TetherLocalization{localization{country{isoCode name currency{isoCode symbol}}language{isoCode name}availableCountries{isoCode name currency{isoCode symbol}availableLanguages{isoCode name}}}}`;
|
|
187
|
+
var COUNTRY = { isoCode: "string", name: "string", currency: "object" };
|
|
188
|
+
var isLocalizationAnswer = shaped({
|
|
189
|
+
localization: { country: COUNTRY, availableCountries: [COUNTRY] }
|
|
190
|
+
});
|
|
141
191
|
function getLocalization() {
|
|
142
|
-
|
|
143
|
-
|
|
192
|
+
localizationPromise ?? (localizationPromise = gql(LOCALIZATION_QUERY, {}, isLocalizationAnswer).then(
|
|
193
|
+
(data) => data.localization,
|
|
194
|
+
(error) => {
|
|
144
195
|
localizationPromise = null;
|
|
145
|
-
throw
|
|
146
|
-
}
|
|
147
|
-
|
|
196
|
+
throw error;
|
|
197
|
+
}
|
|
198
|
+
));
|
|
148
199
|
return localizationPromise;
|
|
149
200
|
}
|
|
150
|
-
|
|
151
|
-
|
|
201
|
+
function countryField(country, field) {
|
|
202
|
+
switch (field) {
|
|
203
|
+
case "name":
|
|
204
|
+
return country.name;
|
|
205
|
+
case "code":
|
|
206
|
+
return country.isoCode;
|
|
207
|
+
case "currency":
|
|
208
|
+
return country.currency.isoCode;
|
|
209
|
+
case "symbol":
|
|
210
|
+
return country.currency.symbol;
|
|
211
|
+
default:
|
|
212
|
+
return "";
|
|
213
|
+
}
|
|
214
|
+
}
|
|
215
|
+
var fillLabel = (template, country) => template.replace(/\{(name|code|currency|symbol)\}/g, (_match, field) => countryField(country, field));
|
|
216
|
+
function fillCountrySelect(select, countries, current) {
|
|
217
|
+
const template = select.getAttribute(attr("country-label")) || DEFAULT_LABEL;
|
|
218
|
+
const only = (select.getAttribute(attr("countries")) || "").toUpperCase().split(/[\s,]+/).filter(Boolean);
|
|
219
|
+
const listed = only.length ? only.map((code) => countries.find((country) => country.isoCode === code)).filter((country) => country !== void 0) : countries;
|
|
220
|
+
select.replaceChildren(...listed.map((country) => new Option(fillLabel(template, country), country.isoCode)));
|
|
221
|
+
select.value = current;
|
|
222
|
+
if (select.value !== current) select.selectedIndex = -1;
|
|
223
|
+
select.disabled = listed.length < 2 && !select.hasAttribute(attr("always-enabled"));
|
|
224
|
+
}
|
|
225
|
+
function fillCountries(selects, binds, localization) {
|
|
226
|
+
const current = (cfg.country || localization.country.isoCode).toUpperCase();
|
|
227
|
+
const countries = [...localization.availableCountries].sort(
|
|
228
|
+
(a, b) => a.name.localeCompare(b.name, cfg.locale || void 0)
|
|
229
|
+
);
|
|
230
|
+
const inUse = countries.find((country) => country.isoCode === current) ?? localization.country;
|
|
231
|
+
selects.forEach((select) => {
|
|
232
|
+
fillCountrySelect(select, countries, current);
|
|
233
|
+
});
|
|
234
|
+
binds.forEach((el) => {
|
|
235
|
+
el.textContent = countryField(inUse, get(el, "country-bind") || DEFAULT_BIND);
|
|
236
|
+
});
|
|
237
|
+
}
|
|
152
238
|
function renderCountrySelects(root = document) {
|
|
153
239
|
const selects = within(root, `select${sel("country-select")}`);
|
|
154
240
|
const binds = within(root, sel("country-bind"));
|
|
155
241
|
if (!selects.length && !binds.length) return Promise.resolve();
|
|
156
|
-
return getLocalization().then((
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
selects.forEach((s) => {
|
|
162
|
-
const tpl = s.getAttribute(attr("country-label")) || "{name} ({currency})";
|
|
163
|
-
const only = (s.getAttribute(attr("countries")) || "").toUpperCase().split(/[\s,]+/).filter(Boolean);
|
|
164
|
-
const list = only.length ? only.map((c) => countries.find((x) => x.isoCode === c)).filter(Boolean) : countries;
|
|
165
|
-
s.innerHTML = "";
|
|
166
|
-
list.forEach((c) => s.appendChild(new Option(fill(tpl, c), c.isoCode)));
|
|
167
|
-
s.value = current;
|
|
168
|
-
if (s.value !== current) s.selectedIndex = -1;
|
|
169
|
-
s.disabled = list.length < 2 && !s.hasAttribute(attr("always-enabled"));
|
|
170
|
-
});
|
|
171
|
-
binds.forEach((el) => {
|
|
172
|
-
const k = get(el, "country-bind") || "name";
|
|
173
|
-
const v = { name: info?.name, code: info?.isoCode, currency: info?.currency?.isoCode, symbol: info?.currency?.symbol }[k];
|
|
174
|
-
el.textContent = v || "";
|
|
175
|
-
});
|
|
176
|
-
}).catch((err) => reportError(err, "country select"));
|
|
242
|
+
return getLocalization().then((localization) => {
|
|
243
|
+
fillCountries(selects, binds, localization);
|
|
244
|
+
}).catch((error) => {
|
|
245
|
+
reportError(error, "country select");
|
|
246
|
+
});
|
|
177
247
|
}
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
if (
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
const changed = country !== String(cfg.country || "").toUpperCase() || lang !== cfg.language || loc !== cfg.locale;
|
|
186
|
-
cfg.country = country;
|
|
187
|
-
cfg.language = lang || void 0;
|
|
188
|
-
cfg.locale = loc;
|
|
189
|
-
if (remember) rememberMarket({ country, language: lang, locale: own });
|
|
190
|
-
if (!changed) {
|
|
191
|
-
renderCountrySelects();
|
|
192
|
-
return Cart.state;
|
|
193
|
-
}
|
|
248
|
+
var localeEntryFor = (country) => Object.values(cfg.markets?.locales ?? {}).find((entry) => toCountry(entry.country) === country);
|
|
249
|
+
function languageFor(language, entry) {
|
|
250
|
+
if (language !== void 0) return toLanguage(language);
|
|
251
|
+
if (!entry) return cfg.language;
|
|
252
|
+
return entry.language ? toLanguage(entry.language) : void 0;
|
|
253
|
+
}
|
|
254
|
+
function rerenderInMarket(country) {
|
|
194
255
|
clearProductCache();
|
|
195
256
|
const jobs = [];
|
|
196
|
-
if (
|
|
197
|
-
|
|
257
|
+
if (Cart.id()) {
|
|
258
|
+
jobs.push(
|
|
259
|
+
Cart.setBuyerIdentity({ countryCode: country }, { create: false }).catch((error) => {
|
|
260
|
+
reportError(error, "cart country");
|
|
261
|
+
})
|
|
262
|
+
);
|
|
263
|
+
}
|
|
198
264
|
pruneLive();
|
|
199
265
|
liveLists.forEach((list) => jobs.push(list.load()));
|
|
200
266
|
liveProducts.forEach((el) => {
|
|
@@ -202,12 +268,34 @@
|
|
|
202
268
|
mountedProducts.delete(el);
|
|
203
269
|
mountProduct(el);
|
|
204
270
|
});
|
|
205
|
-
|
|
271
|
+
return jobs;
|
|
272
|
+
}
|
|
273
|
+
async function setCountry(code, { language, locale, remember = true } = {}) {
|
|
274
|
+
const country = toCountry(code);
|
|
275
|
+
if (!country) throw new TetherError(`Not a country code: ${code}`, { code: "INVALID_COUNTRY" });
|
|
276
|
+
const entry = localeEntryFor(country);
|
|
277
|
+
const ownLocale = locale || entry?.locale;
|
|
278
|
+
const nextLocale = ownLocale || cfg.locale;
|
|
279
|
+
const nextLanguage = languageFor(language, entry);
|
|
280
|
+
const changed = country !== cfg.country || nextLanguage !== cfg.language || nextLocale !== cfg.locale;
|
|
281
|
+
cfg.country = country;
|
|
282
|
+
cfg.language = nextLanguage || void 0;
|
|
283
|
+
cfg.locale = nextLocale;
|
|
284
|
+
if (remember) rememberMarket({ country, language: nextLanguage, locale: ownLocale });
|
|
285
|
+
if (!changed) {
|
|
286
|
+
void renderCountrySelects();
|
|
287
|
+
return Cart.state;
|
|
288
|
+
}
|
|
289
|
+
if (language !== void 0) clearLocalization();
|
|
290
|
+
const jobs = rerenderInMarket(country);
|
|
291
|
+
void renderCountrySelects();
|
|
206
292
|
emit("country-changed", { country, language: cfg.language });
|
|
207
293
|
await Promise.all(jobs);
|
|
208
294
|
return Cart.state;
|
|
209
295
|
}
|
|
210
296
|
|
|
211
|
-
// src/parts/markets.
|
|
212
|
-
|
|
297
|
+
// src/parts/markets.ts
|
|
298
|
+
var { Tether } = window;
|
|
299
|
+
if (!Tether) throw new Error("tether.markets.js runs after the Tether script, which loads it");
|
|
300
|
+
Tether.__parts.markets = markets_ui_exports;
|
|
213
301
|
})();
|
|
@@ -1 +1 @@
|
|
|
1
|
-
(()=>{var
|
|
1
|
+
(()=>{var K=Object.defineProperty;var W=(e,t)=>{for(var n in t)K(e,n,{get:t[n],enumerable:!0})};var L={};W(L,{detectMarket:()=>F,getLocalization:()=>$,renderCountrySelects:()=>h,setCountry:()=>be});var G=window.Tether.__core["config.ts"],[c,Te,ve,M,S,p,xe]=G;var V=window.Tether.__core["client.ts"],[Pe,b,Ae,E,T]=V;var Q=window.Tether.__core["cart.ts"],[g]=Q;var Z=window.Tether.__core["collection.ts"],[v]=Z;var X=window.Tether.__core["loader.ts"],[x,Oe]=X;var ee=window.Tether.__core["dom.ts"],[Ue,m,He,_,De,Fe,P,je,qe,$e,Je,Ye,Be,Ke,C,We,Ge,Ve]=ee;var te=window.Tether.__core["mounting.ts"],[A,I,z,N,O,w]=te;var ne=window.Tether.__core["market-codes.ts"],[s,d]=ne;function R(e,t="localStorage"){try{return window[t].getItem(e)}catch{return null}}function U(e,t,n="localStorage"){try{window[n].setItem(e,t)}catch{}}var oe="tether_country",H=()=>`${c.prefix}:market:${c.domain}`,D={getItem:e=>R(e)};function re(){let e=typeof window<"u";return{document:typeof document<"u"?document:null,location:e?window.location:null,storage:D,global:e?window:{}}}function ae(e){try{return JSON.parse(e)}catch(t){if(t instanceof SyntaxError)return null;throw t}}function ce(e){if(typeof e!="object"||e===null)return null;let t=s(Reflect.get(e,"country"));if(!t)return null;let n=Reflect.get(e,"locale");return{country:t,language:d(Reflect.get(e,"language"))??void 0,locale:typeof n=="string"&&n?n:void 0}}function ie(e=D){let t=e.getItem(H());return t?ce(ae(t)):null}function le(e,t){if(!e||!t)return null;let n=e.cookie.split(";").map(a=>a.trim()).find(a=>a.startsWith(`${t}=`));return n?decodeURIComponent(n.slice(t.length+1)):null}function k(e,t){if(!e||!t)return null;let n=t.toLowerCase(),a=Object.keys(e).find(o=>o.toLowerCase()===n);return a?e[a]??null:null}function ue(e,t){let n=r=>t.document?.querySelector(`meta[name="${r}"]`)?.getAttribute("content"),a=Reflect.get(t.global,"TETHER_COUNTRY"),o=Reflect.get(t.global,"TETHER_LANGUAGE"),i=n("tether-country")||le(t.document,e.cookie||oe);return{country:a||i,language:o||n("tether-language")}}function se(e,t){let n=(t.location?.pathname??"/").split("/").find(l=>l!==""),a=k(e.locales,n);if(a)return a;let o=t.document?.documentElement.getAttribute("lang");if(!o)return null;let i=k(e.locales,o)??k(e.locales,o.split("-")[0]);if(i)return{locale:o,...i};if(e.locales&&e.strict)return null;let r=o.split("-")[1];return{language:o,country:r?.length===2?r:null,locale:o}}function de(e,t,n){switch(e){case"saved":return t.remember===!1?null:ie(n.storage);case"server":return ue(t,n);case"webflow":return se(t,n)}}function ge(e){return e?e===!0?M:e:["saved"]}function F(e=c.markets,t=re()){let n=(e===c.markets?e:S(e))??{};if(n.detect===!1)return{};let a={},o={sources:a};for(let i of ge(n.detect)){let r=de(i,n,t);if(!r)continue;let l=s(r.country),u=d(r.language),f=typeof r.locale=="string"&&r.locale?r.locale:null;l&&!o.country&&(o.country=l,a.country=i),u&&!o.language&&(o.language=u,a.language=i),f&&!o.locale&&(o.locale=f,a.locale=i)}return o}function j(e){if(c.markets?.remember===!1)return;let t={country:e.country,language:e.language||void 0,locale:e.locale||void 0};U(H(),JSON.stringify(t))}var fe="{name} ({currency})",me="name",y=null;function ye(){y=null}var pe="query TetherLocalization{localization{country{isoCode name currency{isoCode symbol}}language{isoCode name}availableCountries{isoCode name currency{isoCode symbol}availableLanguages{isoCode name}}}}",q={isoCode:"string",name:"string",currency:"object"},Ce=E({localization:{country:q,availableCountries:[q]}});function $(){return y??(y=b(pe,{},Ce).then(e=>e.localization,e=>{throw y=null,e})),y}function J(e,t){switch(t){case"name":return e.name;case"code":return e.isoCode;case"currency":return e.currency.isoCode;case"symbol":return e.currency.symbol;default:return""}}var we=(e,t)=>e.replace(/\{(name|code|currency|symbol)\}/g,(n,a)=>J(t,a));function ke(e,t,n){let a=e.getAttribute(m("country-label"))||fe,o=(e.getAttribute(m("countries"))||"").toUpperCase().split(/[\s,]+/).filter(Boolean),i=o.length?o.map(r=>t.find(l=>l.isoCode===r)).filter(r=>r!==void 0):t;e.replaceChildren(...i.map(r=>new Option(we(a,r),r.isoCode))),e.value=n,e.value!==n&&(e.selectedIndex=-1),e.disabled=i.length<2&&!e.hasAttribute(m("always-enabled"))}function he(e,t,n){let a=(c.country||n.country.isoCode).toUpperCase(),o=[...n.availableCountries].sort((r,l)=>r.name.localeCompare(l.name,c.locale||void 0)),i=o.find(r=>r.isoCode===a)??n.country;e.forEach(r=>{ke(r,o,a)}),t.forEach(r=>{r.textContent=J(i,P(r,"country-bind")||me)})}function h(e=document){let t=w(e,`select${C("country-select")}`),n=w(e,C("country-bind"));return!t.length&&!n.length?Promise.resolve():$().then(a=>{he(t,n,a)}).catch(a=>{p(a,"country select")})}var Le=e=>Object.values(c.markets?.locales??{}).find(t=>s(t.country)===e);function Me(e,t){return e!==void 0?d(e):t?t.language?d(t.language):void 0:c.language}function Se(e){x();let t=[];return g.id()&&t.push(g.setBuyerIdentity({countryCode:e},{create:!1}).catch(n=>{p(n,"cart country")})),O(),A.forEach(n=>t.push(n.load())),I.forEach(n=>{n.closest(v())||(z.delete(n),N(n))}),t}async function be(e,{language:t,locale:n,remember:a=!0}={}){let o=s(e);if(!o)throw new T(`Not a country code: ${e}`,{code:"INVALID_COUNTRY"});let i=Le(o),r=n||i?.locale,l=r||c.locale,u=Me(t,i),f=o!==c.country||u!==c.language||l!==c.locale;if(c.country=o,c.language=u||void 0,c.locale=l,a&&j({country:o,language:u,locale:r}),!f)return h(),g.state;t!==void 0&&ye();let B=Se(o);return h(),_("country-changed",{country:o,language:c.language}),await Promise.all(B),g.state}var{Tether:Y}=window;if(!Y)throw new Error("tether.markets.js runs after the Tether script, which loads it");Y.__parts.markets=L;})();
|