@occluze/tether 0.6.8 → 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.
Files changed (259) hide show
  1. package/README.md +11 -11
  2. package/dist/esm/astro.js +2 -2
  3. package/dist/esm/chunks/account-UIPWJQ3Y.js +1 -0
  4. package/dist/esm/chunks/account-pages-6ROA6Y4V.js +1 -0
  5. package/dist/esm/chunks/analytics-2V632IRV.js +1 -0
  6. package/dist/esm/chunks/chunk-4GCXM764.js +1 -0
  7. package/dist/esm/chunks/chunk-56FCLJJD.js +1 -0
  8. package/dist/esm/chunks/chunk-5Z5O3767.js +1 -0
  9. package/dist/esm/chunks/chunk-6OZJCAGZ.js +1 -0
  10. package/dist/esm/chunks/chunk-A5SYCVQM.js +1 -0
  11. package/dist/esm/chunks/chunk-BA4LQJJQ.js +1 -0
  12. package/dist/esm/chunks/chunk-BFTZR4OB.js +4 -0
  13. package/dist/esm/chunks/chunk-C5JYQCWH.js +1 -0
  14. package/dist/esm/chunks/chunk-E5YO6274.js +1 -0
  15. package/dist/esm/chunks/chunk-MPDWM2NN.js +1 -0
  16. package/dist/esm/chunks/chunk-T44MUL4Y.js +1 -0
  17. package/dist/esm/chunks/chunk-YLUULATY.js +1 -0
  18. package/dist/esm/chunks/diagnose-3FEKRIEK.js +14 -0
  19. package/dist/esm/chunks/extras-6POFBNOP.js +1 -0
  20. package/dist/esm/chunks/markets-ui-FD6NI2OG.js +1 -0
  21. package/dist/esm/chunks/search-UJ73YBQ5.js +1 -0
  22. package/dist/esm/index.js +1 -1
  23. package/dist/esm/server.js +2 -2
  24. package/dist/presets/barba.esm.js +19 -23
  25. package/dist/tether.account-pages.js +320 -365
  26. package/dist/tether.account-pages.min.js +1 -1
  27. package/dist/tether.account.js +242 -491
  28. package/dist/tether.account.min.js +1 -1
  29. package/dist/tether.analytics.js +66 -88
  30. package/dist/tether.analytics.min.js +1 -1
  31. package/dist/tether.diagnose.js +36 -33
  32. package/dist/tether.diagnose.min.js +2 -2
  33. package/dist/tether.extras.js +28 -36
  34. package/dist/tether.extras.min.js +1 -1
  35. package/dist/tether.js +1270 -894
  36. package/dist/tether.markets.js +73 -90
  37. package/dist/tether.markets.min.js +1 -1
  38. package/dist/tether.min.js +0 -0
  39. package/dist/tether.min.js.map +4 -4
  40. package/dist/tether.search.js +44 -68
  41. package/dist/tether.search.min.js +1 -1
  42. package/dist/types/server/src/shared/account-orders.d.ts +44 -0
  43. package/dist/types/server/src/shared/account-routes.d.ts +153 -0
  44. package/dist/types/server/src/shared/api-versions.d.ts +13 -0
  45. package/dist/types/server/src/shared/error-message.d.ts +2 -0
  46. package/dist/types/server/src/shared/json.d.ts +25 -0
  47. package/dist/types/server/src/shared/market-codes.d.ts +16 -0
  48. package/dist/types/src/account/addresses-view.d.ts +5 -0
  49. package/dist/types/src/account/answers.d.ts +40 -0
  50. package/dist/types/src/account/markup.d.ts +19 -0
  51. package/dist/types/src/account/operations.d.ts +41 -0
  52. package/dist/types/src/account/order-lines.d.ts +13 -0
  53. package/dist/types/src/account/order-list.d.ts +12 -0
  54. package/dist/types/src/account/order-page.d.ts +6 -0
  55. package/dist/types/src/account/page-answers.d.ts +182 -0
  56. package/dist/types/src/account/page-events.d.ts +2 -0
  57. package/dist/types/src/account/server-client.d.ts +60 -0
  58. package/dist/types/src/account/subscriptions-view.d.ts +2 -0
  59. package/dist/types/src/account-api.d.ts +18 -0
  60. package/dist/types/src/account-marks.d.ts +15 -0
  61. package/dist/types/src/account-pages.d.ts +8 -0
  62. package/dist/types/src/account.d.ts +64 -0
  63. package/dist/types/src/amounts.d.ts +12 -0
  64. package/dist/types/src/analytics-shopify.d.ts +41 -0
  65. package/dist/types/src/analytics.d.ts +2 -0
  66. package/dist/types/src/api-version.d.ts +28 -0
  67. package/dist/types/src/astro.d.ts +42 -0
  68. package/dist/types/src/cart/cart-shape.d.ts +43 -0
  69. package/dist/types/src/cart/checkout.d.ts +16 -0
  70. package/dist/types/src/cart/drawer.d.ts +18 -0
  71. package/dist/types/src/cart/mutations.d.ts +79 -0
  72. package/dist/types/src/cart/render.d.ts +17 -0
  73. package/dist/types/src/cart/store.d.ts +182 -0
  74. package/dist/types/src/cart.d.ts +106 -0
  75. package/dist/types/src/client.d.ts +100 -0
  76. package/dist/types/src/collection.d.ts +25 -0
  77. package/dist/types/src/config-sections.d.ts +40 -0
  78. package/dist/types/src/config.d.ts +185 -0
  79. package/dist/types/src/controls/cart-controls.d.ts +2 -0
  80. package/dist/types/src/controls/discount.d.ts +2 -0
  81. package/dist/types/src/controls/extras.d.ts +5 -0
  82. package/dist/types/src/controls/navigation.d.ts +12 -0
  83. package/dist/types/src/diagnose-markup.d.ts +19 -0
  84. package/dist/types/src/diagnose.d.ts +60 -0
  85. package/dist/types/src/dom.d.ts +75 -0
  86. package/dist/types/src/extras.d.ts +21 -0
  87. package/dist/types/src/fragments.d.ts +158 -0
  88. package/dist/types/src/globals.d.ts +15 -0
  89. package/dist/types/src/images.d.ts +20 -0
  90. package/dist/types/src/index.d.ts +167 -0
  91. package/dist/types/src/initial.d.ts +56 -0
  92. package/dist/types/src/lazy.d.ts +28 -0
  93. package/dist/types/src/loader.d.ts +84 -0
  94. package/dist/types/src/market-codes.d.ts +6 -0
  95. package/dist/types/src/markets-ui.d.ts +32 -0
  96. package/dist/types/src/markets.d.ts +72 -0
  97. package/dist/types/src/markup.d.ts +131 -0
  98. package/dist/types/src/mounting.d.ts +46 -0
  99. package/dist/types/src/page-market.d.ts +27 -0
  100. package/dist/types/src/presets/barba.d.ts +56 -0
  101. package/dist/types/src/product-events.d.ts +2 -0
  102. package/dist/types/src/product-render.d.ts +17 -0
  103. package/dist/types/src/product-shape.d.ts +88 -0
  104. package/dist/types/src/product-state.d.ts +110 -0
  105. package/dist/types/src/product.d.ts +66 -0
  106. package/dist/types/src/repeaters.d.ts +16 -0
  107. package/dist/types/src/search.d.ts +33 -0
  108. package/dist/types/src/selling-plans.d.ts +64 -0
  109. package/dist/types/src/server.d.ts +88 -0
  110. package/dist/types/src/shopify-values.d.ts +46 -0
  111. package/dist/types/src/status.d.ts +33 -0
  112. package/dist/types/src/storage.d.ts +12 -0
  113. package/dist/types/src/store-html.d.ts +39 -0
  114. package/dist/types/src/storefront/catalog.d.ts +38 -0
  115. package/dist/types/src/storefront/json-ld.d.ts +20 -0
  116. package/dist/types/src/variant-render.d.ts +14 -0
  117. package/package.json +24 -23
  118. package/src/account/addresses-view.ts +58 -0
  119. package/src/account/answers.ts +79 -0
  120. package/src/account/markup.ts +36 -0
  121. package/src/account/operations.ts +145 -0
  122. package/src/account/{order-lines.js → order-lines.ts} +20 -41
  123. package/src/account/order-list.ts +107 -0
  124. package/src/account/order-page.ts +137 -0
  125. package/src/account/page-answers.ts +317 -0
  126. package/src/account/{page-events.js → page-events.ts} +55 -90
  127. package/src/account/server-client.ts +183 -0
  128. package/src/account/{subscriptions-view.js → subscriptions-view.ts} +25 -68
  129. package/src/account-api.ts +98 -0
  130. package/src/account-marks.ts +35 -0
  131. package/src/{account-pages.js → account-pages.ts} +29 -37
  132. package/src/account.ts +284 -0
  133. package/src/amounts.ts +64 -0
  134. package/src/{analytics-shopify.js → analytics-shopify.ts} +112 -107
  135. package/src/analytics.ts +315 -0
  136. package/src/{api-version.js → api-version.ts} +25 -31
  137. package/src/{astro.js → astro.ts} +110 -104
  138. package/src/cart/cart-shape.ts +25 -0
  139. package/src/cart/checkout.ts +101 -0
  140. package/src/cart/{drawer.js → drawer.ts} +18 -31
  141. package/src/cart/mutations.ts +237 -0
  142. package/src/cart/{render.js → render.ts} +68 -96
  143. package/src/cart/store.ts +279 -0
  144. package/src/{cart.js → cart.ts} +82 -128
  145. package/src/client.ts +391 -0
  146. package/src/{collection.js → collection.ts} +30 -38
  147. package/src/config-sections.ts +284 -0
  148. package/src/config.ts +480 -0
  149. package/src/controls/{cart-controls.js → cart-controls.ts} +22 -54
  150. package/src/controls/{discount.js → discount.ts} +13 -34
  151. package/src/controls/{extras.js → extras.ts} +15 -24
  152. package/src/controls/{navigation.js → navigation.ts} +24 -30
  153. package/src/{diagnose-markup.js → diagnose-markup.ts} +37 -72
  154. package/src/{diagnose.js → diagnose.ts} +95 -96
  155. package/src/dom.ts +268 -0
  156. package/src/{extras.js → extras.ts} +43 -52
  157. package/src/fragments.ts +261 -0
  158. package/src/globals.d.ts +15 -0
  159. package/src/{images.js → images.ts} +30 -43
  160. package/src/index.ts +415 -0
  161. package/src/initial.ts +101 -0
  162. package/src/lazy-iife.ts +197 -0
  163. package/src/lazy.ts +42 -0
  164. package/src/{loader.js → loader.ts} +149 -123
  165. package/src/market-codes.ts +6 -0
  166. package/src/{markets-ui.js → markets-ui.ts} +91 -68
  167. package/src/markets.ts +246 -0
  168. package/src/markup.ts +127 -0
  169. package/src/{mounting.js → mounting.ts} +88 -101
  170. package/src/{page-market.js → page-market.ts} +32 -38
  171. package/src/part-integrity.ts +7 -0
  172. package/src/parts/account-pages.ts +7 -0
  173. package/src/parts/account.ts +7 -0
  174. package/src/parts/analytics.ts +7 -0
  175. package/src/parts/diagnose.ts +7 -0
  176. package/src/parts/extras.ts +7 -0
  177. package/src/parts/markets.ts +7 -0
  178. package/src/parts/search.ts +7 -0
  179. package/src/presets/barba.ts +194 -0
  180. package/src/{product-events.js → product-events.ts} +33 -48
  181. package/src/{product-render.js → product-render.ts} +38 -77
  182. package/src/product-shape.ts +49 -0
  183. package/src/product-state.ts +318 -0
  184. package/src/{product.js → product.ts} +90 -126
  185. package/src/{repeaters.js → repeaters.ts} +40 -52
  186. package/src/{search.js → search.ts} +85 -103
  187. package/src/selling-plans.ts +145 -0
  188. package/src/server.ts +211 -0
  189. package/src/{shopify-values.js → shopify-values.ts} +24 -22
  190. package/src/{status.js → status.ts} +34 -54
  191. package/src/storage.ts +34 -0
  192. package/src/store-html.ts +359 -0
  193. package/src/storefront/catalog.ts +196 -0
  194. package/src/storefront/{json-ld.js → json-ld.ts} +45 -68
  195. package/src/{variant-render.js → variant-render.ts} +24 -50
  196. package/dist/esm/chunks/account-C3NP6HFB.js +0 -1
  197. package/dist/esm/chunks/account-pages-WLK374FO.js +0 -1
  198. package/dist/esm/chunks/analytics-G3SAWMNL.js +0 -1
  199. package/dist/esm/chunks/chunk-27PJJZGC.js +0 -1
  200. package/dist/esm/chunks/chunk-2FSXS55U.js +0 -1
  201. package/dist/esm/chunks/chunk-FCSWQDVV.js +0 -1
  202. package/dist/esm/chunks/chunk-FOMSMIAM.js +0 -1
  203. package/dist/esm/chunks/chunk-GZJTCLLW.js +0 -1
  204. package/dist/esm/chunks/chunk-HEQILZVR.js +0 -1
  205. package/dist/esm/chunks/chunk-JOOEXYF3.js +0 -4
  206. package/dist/esm/chunks/chunk-MPTQYLSM.js +0 -1
  207. package/dist/esm/chunks/chunk-NEHZ37TU.js +0 -3
  208. package/dist/esm/chunks/chunk-V74KGEJF.js +0 -1
  209. package/dist/esm/chunks/chunk-VT4CDUJJ.js +0 -1
  210. package/dist/esm/chunks/chunk-YJLWX2HK.js +0 -1
  211. package/dist/esm/chunks/diagnose-6VVGZNTY.js +0 -14
  212. package/dist/esm/chunks/extras-GJVRDFM3.js +0 -1
  213. package/dist/esm/chunks/markets-ui-UNB4PTA7.js +0 -1
  214. package/dist/esm/chunks/search-OU75RNQL.js +0 -1
  215. package/src/account/addresses-view.js +0 -92
  216. package/src/account/browser-session.js +0 -359
  217. package/src/account/markup.js +0 -48
  218. package/src/account/operations.js +0 -180
  219. package/src/account/order-list.js +0 -91
  220. package/src/account/order-page.js +0 -192
  221. package/src/account/server-client.js +0 -172
  222. package/src/account/shared.js +0 -111
  223. package/src/account/shopify-auth.js +0 -150
  224. package/src/account-api.js +0 -118
  225. package/src/account-links.js +0 -35
  226. package/src/account.js +0 -342
  227. package/src/amounts.js +0 -36
  228. package/src/analytics.js +0 -352
  229. package/src/cart/checkout.js +0 -97
  230. package/src/cart/mutations.js +0 -234
  231. package/src/cart/store.js +0 -326
  232. package/src/client.js +0 -267
  233. package/src/config.js +0 -349
  234. package/src/dom.js +0 -287
  235. package/src/fragments.js +0 -237
  236. package/src/index.js +0 -353
  237. package/src/initial.js +0 -87
  238. package/src/lazy-iife.js +0 -116
  239. package/src/lazy.js +0 -39
  240. package/src/market-codes.js +0 -35
  241. package/src/markets.js +0 -334
  242. package/src/markup.js +0 -64
  243. package/src/parts/account-pages.js +0 -6
  244. package/src/parts/account.js +0 -6
  245. package/src/parts/analytics.js +0 -6
  246. package/src/parts/diagnose.js +0 -6
  247. package/src/parts/extras.js +0 -6
  248. package/src/parts/markets.js +0 -6
  249. package/src/parts/search.js +0 -6
  250. package/src/presets/barba.js +0 -190
  251. package/src/product-state.js +0 -318
  252. package/src/selling-plans.js +0 -154
  253. package/src/server.js +0 -215
  254. package/src/store-html.js +0 -0
  255. package/src/storefront/catalog.js +0 -199
  256. package/types/astro.d.ts +0 -28
  257. package/types/barba.d.ts +0 -16
  258. package/types/index.d.ts +0 -577
  259. package/types/server.d.ts +0 -182
@@ -1,4 +1,3 @@
1
- "use strict";
2
1
  (() => {
3
2
  var __defProp = Object.defineProperty;
4
3
  var __export = (target, all) => {
@@ -6,7 +5,7 @@
6
5
  __defProp(target, name, { get: all[name], enumerable: true });
7
6
  };
8
7
 
9
- // src/markets-ui.js
8
+ // src/markets-ui.ts
10
9
  var markets_ui_exports = {};
11
10
  __export(markets_ui_exports, {
12
11
  detectMarket: () => detectMarket,
@@ -15,65 +14,69 @@
15
14
  setCountry: () => setCountry
16
15
  });
17
16
 
18
- // tether-core:config.js
19
- var m = window.Tether.__core["config.js"];
20
- var { DEFAULTS, cfg, configure, isConfigured, log, reportError, resolveConfig, toMetafieldIdentifier, warn } = m;
17
+ // tether-core:config.ts
18
+ var m = window.Tether.__core["config.ts"];
19
+ var [cfg, isConfigured, log, MARKET_SOURCES, parseMarkets, reportError, warn] = m;
21
20
 
22
- // tether-core:client.js
23
- var m2 = window.Tether.__core["client.js"];
24
- var { TetherError, endpoint, gql, request, unwrap, withContext } = m2;
21
+ // tether-core:client.ts
22
+ var m2 = window.Tether.__core["client.ts"];
23
+ var [endpoint, gql, orNull, shaped, TetherError] = m2;
25
24
 
26
- // tether-core:cart.js
27
- var m3 = window.Tether.__core["cart.js"];
28
- var { Cart, trapFocus } = m3;
25
+ // tether-core:cart.ts
26
+ var m3 = window.Tether.__core["cart.ts"];
27
+ var [Cart] = m3;
29
28
 
30
- // tether-core:collection.js
31
- var m4 = window.Tether.__core["collection.js"];
32
- var { ListScope, listSelector } = m4;
29
+ // tether-core:collection.ts
30
+ var m4 = window.Tether.__core["collection.ts"];
31
+ var [listSelector] = m4;
33
32
 
34
- // tether-core:loader.js
35
- var m5 = window.Tether.__core["loader.js"];
36
- var { clearProductCache, getProduct, getProducts, getRecommendations, hydrateProducts, normalizeProductKey, primeProduct, refreshProducts, takeStale } = m5;
33
+ // tether-core:loader.ts
34
+ var m5 = window.Tether.__core["loader.ts"];
35
+ var [clearProductCache, getProduct] = m5;
37
36
 
38
- // tether-core:dom.js
39
- var m6 = window.Tether.__core["dom.js"];
40
- var { attr, busy, cdnUrl, emit, formatDate, formatMoney, formatPercent, get, has, hasTemplate, imageUrl, notifyLayoutChanged, parseJSONAttr, productUrl, qsa, repeat, repeatKeyed, sameImage, scoped, sel, setImage, setSelected, setStoreHtml, setText, setTextTracked, show, toAttributes, watchImages } = m6;
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;
41
40
 
42
- // tether-core:mounting.js
43
- var m7 = window.Tether.__core["mounting.js"];
44
- var { hydrateFromPage, liveLists, liveProducts, mountProduct, mountedLists, mountedProducts, pruneLive, retryFailed, settleMarket, trackMarket, within } = m7;
41
+ // tether-core:mounting.ts
42
+ var m7 = window.Tether.__core["mounting.ts"];
43
+ var [liveLists, liveProducts, mountedProducts, mountProduct, pruneLive, within] = m7;
45
44
 
46
- // tether-core:market-codes.js
47
- var m8 = window.Tether.__core["market-codes.js"];
48
- var { toCountry, toLanguage } = m8;
45
+ // tether-core:market-codes.ts
46
+ var m8 = window.Tether.__core["market-codes.ts"];
47
+ var [toCountry, toLanguage] = m8;
49
48
 
50
- // src/markets.js
51
- var ALL_SOURCES = ["saved", "server", "webflow"];
52
- var DEFAULT_COOKIE = "tether_country";
53
- var storageKey = () => `${cfg.prefix}:market:${cfg.domain}`;
54
- function localStorageIfAllowed() {
55
- if (typeof window === "undefined") return null;
49
+ // src/storage.ts
50
+ function getStored(key, area = "localStorage") {
56
51
  try {
57
- return window.localStorage;
52
+ return window[area].getItem(key);
58
53
  } catch {
59
54
  return null;
60
55
  }
61
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";
66
+ var storageKey = () => `${cfg.prefix}:market:${cfg.domain}`;
67
+ var pageStorage = { getItem: (key) => getStored(key) };
62
68
  function pageEnv() {
63
69
  const hasWindow = typeof window !== "undefined";
64
70
  return {
65
71
  document: typeof document !== "undefined" ? document : null,
66
72
  location: hasWindow ? window.location : null,
67
- storage: localStorageIfAllowed(),
73
+ storage: pageStorage,
68
74
  global: hasWindow ? window : {}
69
75
  };
70
76
  }
71
77
  function parseJsonOrNull(text) {
72
78
  try {
73
- return (
74
- /** @type {unknown} */
75
- JSON.parse(text)
76
- );
79
+ return JSON.parse(text);
77
80
  } catch (error) {
78
81
  if (error instanceof SyntaxError) return null;
79
82
  throw error;
@@ -83,18 +86,15 @@
83
86
  if (typeof value !== "object" || value === null) return null;
84
87
  const country = toCountry(Reflect.get(value, "country"));
85
88
  if (!country) return null;
86
- const locale = (
87
- /** @type {unknown} */
88
- Reflect.get(value, "locale")
89
- );
89
+ const locale = Reflect.get(value, "locale");
90
90
  return {
91
91
  country,
92
92
  language: toLanguage(Reflect.get(value, "language")) ?? void 0,
93
93
  locale: typeof locale === "string" && locale ? locale : void 0
94
94
  };
95
95
  }
96
- function readSavedMarket(storage = localStorageIfAllowed()) {
97
- const text = storage?.getItem(storageKey());
96
+ function readSavedMarket(storage = pageStorage) {
97
+ const text = storage.getItem(storageKey());
98
98
  return text ? toMarket(parseJsonOrNull(text)) : null;
99
99
  }
100
100
  function readCookie(doc, name) {
@@ -110,9 +110,12 @@
110
110
  }
111
111
  function readServerHint(markets, env) {
112
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);
113
116
  return {
114
- country: Reflect.get(env.global, "TETHER_COUNTRY") || meta("tether-country") || readCookie(env.document, markets.cookie || DEFAULT_COOKIE),
115
- language: Reflect.get(env.global, "TETHER_LANGUAGE") || meta("tether-language")
117
+ country: globalCountry || pageCountry,
118
+ language: globalLanguage || meta("tether-language")
116
119
  };
117
120
  }
118
121
  function readWebflowLocale(markets, env) {
@@ -137,17 +140,12 @@
137
140
  return readWebflowLocale(markets, env);
138
141
  }
139
142
  }
140
- var isMarketSource = (name) => ALL_SOURCES.some((source) => source === name);
141
143
  function sourcesFor(detect) {
142
144
  if (!detect) return ["saved"];
143
- if (detect === true) return ALL_SOURCES;
144
- return (
145
- /** @type {unknown[]} */
146
- [detect].flat().filter(isMarketSource)
147
- );
145
+ return detect === true ? MARKET_SOURCES : detect;
148
146
  }
149
147
  function detectMarket(markets = cfg.markets, env = pageEnv()) {
150
- const config = markets ?? {};
148
+ const config = (markets === cfg.markets ? markets : parseMarkets(markets)) ?? {};
151
149
  if (config.detect === false) return {};
152
150
  const sources = {};
153
151
  const found = { sources };
@@ -172,40 +170,34 @@
172
170
  }
173
171
  return found;
174
172
  }
175
- function storeIfAllowed(key, value) {
176
- try {
177
- localStorage.setItem(key, value);
178
- } catch {
179
- return;
180
- }
181
- }
182
173
  function rememberMarket(market) {
183
174
  if (cfg.markets?.remember === false) return;
184
175
  const saved = { country: market.country, language: market.language || void 0, locale: market.locale || void 0 };
185
- storeIfAllowed(storageKey(), JSON.stringify(saved));
176
+ setStored(storageKey(), JSON.stringify(saved));
186
177
  }
178
+
179
+ // src/markets-ui.ts
180
+ var DEFAULT_LABEL = "{name} ({currency})";
181
+ var DEFAULT_BIND = "name";
187
182
  var localizationPromise = null;
188
183
  function clearLocalization() {
189
184
  localizationPromise = null;
190
185
  }
191
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
+ });
192
191
  function getLocalization() {
193
- if (!localizationPromise) {
194
- const loading = gql(LOCALIZATION_QUERY);
195
- localizationPromise = loading.then(
196
- (data) => data.localization,
197
- (error) => {
198
- localizationPromise = null;
199
- throw error;
200
- }
201
- );
202
- }
192
+ localizationPromise ?? (localizationPromise = gql(LOCALIZATION_QUERY, {}, isLocalizationAnswer).then(
193
+ (data) => data.localization,
194
+ (error) => {
195
+ localizationPromise = null;
196
+ throw error;
197
+ }
198
+ ));
203
199
  return localizationPromise;
204
200
  }
205
-
206
- // src/markets-ui.js
207
- var DEFAULT_LABEL = "{name} ({currency})";
208
- var DEFAULT_BIND = "name";
209
201
  function countryField(country, field) {
210
202
  switch (field) {
211
203
  case "name":
@@ -220,10 +212,7 @@
220
212
  return "";
221
213
  }
222
214
  }
223
- var fillLabel = (template, country) => template.replace(
224
- /\{(name|code|currency|symbol)\}/g,
225
- (_match, field) => countryField(country, field)
226
- );
215
+ var fillLabel = (template, country) => template.replace(/\{(name|code|currency|symbol)\}/g, (_match, field) => countryField(country, field));
227
216
  function fillCountrySelect(select, countries, current) {
228
217
  const template = select.getAttribute(attr("country-label")) || DEFAULT_LABEL;
229
218
  const only = (select.getAttribute(attr("countries")) || "").toUpperCase().split(/[\s,]+/).filter(Boolean);
@@ -247,10 +236,7 @@
247
236
  });
248
237
  }
249
238
  function renderCountrySelects(root = document) {
250
- const selects = (
251
- /** @type {HTMLSelectElement[]} */
252
- within(root, `select${sel("country-select")}`)
253
- );
239
+ const selects = within(root, `select${sel("country-select")}`);
254
240
  const binds = within(root, sel("country-bind"));
255
241
  if (!selects.length && !binds.length) return Promise.resolve();
256
242
  return getLocalization().then((localization) => {
@@ -291,7 +277,7 @@
291
277
  const ownLocale = locale || entry?.locale;
292
278
  const nextLocale = ownLocale || cfg.locale;
293
279
  const nextLanguage = languageFor(language, entry);
294
- const changed = country !== cfg.country?.toUpperCase() || nextLanguage !== cfg.language || nextLocale !== cfg.locale;
280
+ const changed = country !== cfg.country || nextLanguage !== cfg.language || nextLocale !== cfg.locale;
295
281
  cfg.country = country;
296
282
  cfg.language = nextLanguage || void 0;
297
283
  cfg.locale = nextLocale;
@@ -308,11 +294,8 @@
308
294
  return Cart.state;
309
295
  }
310
296
 
311
- // src/parts/markets.js
312
- var { Tether } = (
313
- /** @type {Window & { Tether?: { __parts: Record<string, unknown> } }} */
314
- window
315
- );
297
+ // src/parts/markets.ts
298
+ var { Tether } = window;
316
299
  if (!Tether) throw new Error("tether.markets.js runs after the Tether script, which loads it");
317
- Tether.__parts["markets"] = markets_ui_exports;
300
+ Tether.__parts.markets = markets_ui_exports;
318
301
  })();
@@ -1 +1 @@
1
- "use strict";(()=>{var B=Object.defineProperty;var H=(e,t)=>{for(var o in t)B(e,o,{get:t[o],enumerable:!0})};var T={};H(T,{detectMarket:()=>F,getLocalization:()=>y,renderCountrySelects:()=>L,setCountry:()=>be});var J=window.Tether.__core["config.js"],{DEFAULTS:Te,cfg:a,configure:_e,isConfigured:xe,log:Ee,reportError:h,resolveConfig:Se,toMetafieldIdentifier:Ae,warn:Pe}=J;var K=window.Tether.__core["client.js"],{TetherError:_,endpoint:ke,gql:x,request:Ue,unwrap:ve,withContext:je}=K;var W=window.Tether.__core["cart.js"],{Cart:f,trapFocus:Re}=W;var Y=window.Tether.__core["collection.js"],{ListScope:Fe,listSelector:E}=Y;var G=window.Tether.__core["loader.js"],{clearProductCache:S,getProduct:ze,getProducts:De,getRecommendations:qe,hydrateProducts:$e,normalizeProductKey:Be,primeProduct:He,refreshProducts:Je,takeStale:Ke}=G;var Q=window.Tether.__core["dom.js"],{attr:p,busy:Ye,cdnUrl:Ge,emit:A,formatDate:Qe,formatMoney:Ve,formatPercent:Ze,get:P,has:Xe,hasTemplate:et,imageUrl:tt,notifyLayoutChanged:ot,parseJSONAttr:nt,productUrl:rt,qsa:ct,repeat:at,repeatKeyed:lt,sameImage:it,scoped:ut,sel:w,setImage:st,setSelected:dt,setStoreHtml:ft,setText:gt,setTextTracked:mt,show:pt,toAttributes:yt,watchImages:ht}=Q;var V=window.Tether.__core["mounting.js"],{hydrateFromPage:Ct,liveLists:I,liveProducts:k,mountProduct:U,mountedLists:bt,mountedProducts:v,pruneLive:j,retryFailed:Lt,settleMarket:Tt,trackMarket:_t,within:C}=V;var Z=window.Tether.__core["market-codes.js"],{toCountry:s,toLanguage:d}=Z;var O=["saved","server","webflow"],X="tether_country",R=()=>`${a.prefix}:market:${a.domain}`;function M(){if(typeof window>"u")return null;try{return window.localStorage}catch{return null}}function ee(){let e=typeof window<"u";return{document:typeof document<"u"?document:null,location:e?window.location:null,storage:M(),global:e?window:{}}}function te(e){try{return JSON.parse(e)}catch(t){if(t instanceof SyntaxError)return null;throw t}}function oe(e){if(typeof e!="object"||e===null)return null;let t=s(Reflect.get(e,"country"));if(!t)return null;let o=Reflect.get(e,"locale");return{country:t,language:d(Reflect.get(e,"language"))??void 0,locale:typeof o=="string"&&o?o:void 0}}function ne(e=M()){let t=e?.getItem(R());return t?oe(te(t)):null}function re(e,t){if(!e||!t)return null;let o=e.cookie.split(";").map(r=>r.trim()).find(r=>r.startsWith(`${t}=`));return o?decodeURIComponent(o.slice(t.length+1)):null}function b(e,t){if(!e||!t)return null;let o=t.toLowerCase(),r=Object.keys(e).find(n=>n.toLowerCase()===o);return r?e[r]??null:null}function ce(e,t){let o=r=>t.document?.querySelector(`meta[name="${r}"]`)?.getAttribute("content");return{country:Reflect.get(t.global,"TETHER_COUNTRY")||o("tether-country")||re(t.document,e.cookie||X),language:Reflect.get(t.global,"TETHER_LANGUAGE")||o("tether-language")}}function ae(e,t){let o=(t.location?.pathname??"/").split("/").find(i=>i!==""),r=b(e.locales,o);if(r)return r;let n=t.document?.documentElement.getAttribute("lang");if(!n)return null;let l=b(e.locales,n)??b(e.locales,n.split("-")[0]);if(l)return{locale:n,...l};if(e.locales&&e.strict)return null;let c=n.split("-")[1];return{language:n,country:c?.length===2?c:null,locale:n}}function le(e,t,o){switch(e){case"saved":return t.remember===!1?null:ne(o.storage);case"server":return ce(t,o);case"webflow":return ae(t,o)}}var ie=e=>O.some(t=>t===e);function ue(e){return e?e===!0?O:[e].flat().filter(ie):["saved"]}function F(e=a.markets,t=ee()){let o=e??{};if(o.detect===!1)return{};let r={},n={sources:r};for(let l of ue(o.detect)){let c=le(l,o,t);if(!c)continue;let i=s(c.country),u=d(c.language),m=typeof c.locale=="string"&&c.locale?c.locale:null;i&&!n.country&&(n.country=i,r.country=l),u&&!n.language&&(n.language=u,r.language=l),m&&!n.locale&&(n.locale=m,r.locale=l)}return n}function se(e,t){try{localStorage.setItem(e,t)}catch{return}}function N(e){if(a.markets?.remember===!1)return;let t={country:e.country,language:e.language||void 0,locale:e.locale||void 0};se(R(),JSON.stringify(t))}var g=null;function z(){g=null}var de="query TetherLocalization{localization{country{isoCode name currency{isoCode symbol}}language{isoCode name}availableCountries{isoCode name currency{isoCode symbol}availableLanguages{isoCode name}}}}";function y(){return g||(g=x(de).then(t=>t.localization,t=>{throw g=null,t})),g}var fe="{name} ({currency})",ge="name";function D(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 me=(e,t)=>e.replace(/\{(name|code|currency|symbol)\}/g,(o,r)=>D(t,r));function pe(e,t,o){let r=e.getAttribute(p("country-label"))||fe,n=(e.getAttribute(p("countries"))||"").toUpperCase().split(/[\s,]+/).filter(Boolean),l=n.length?n.map(c=>t.find(i=>i.isoCode===c)).filter(c=>c!==void 0):t;e.replaceChildren(...l.map(c=>new Option(me(r,c),c.isoCode))),e.value=o,e.value!==o&&(e.selectedIndex=-1),e.disabled=l.length<2&&!e.hasAttribute(p("always-enabled"))}function ye(e,t,o){let r=(a.country||o.country.isoCode).toUpperCase(),n=[...o.availableCountries].sort((c,i)=>c.name.localeCompare(i.name,a.locale||void 0)),l=n.find(c=>c.isoCode===r)??o.country;e.forEach(c=>{pe(c,n,r)}),t.forEach(c=>{c.textContent=D(l,P(c,"country-bind")||ge)})}function L(e=document){let t=C(e,`select${w("country-select")}`),o=C(e,w("country-bind"));return!t.length&&!o.length?Promise.resolve():y().then(r=>{ye(t,o,r)}).catch(r=>{h(r,"country select")})}var he=e=>Object.values(a.markets?.locales??{}).find(t=>s(t.country)===e);function we(e,t){return e!==void 0?d(e):t?t.language?d(t.language):void 0:a.language}function Ce(e){S();let t=[];return f.id()&&t.push(f.setBuyerIdentity({countryCode:e},{create:!1}).catch(o=>{h(o,"cart country")})),j(),I.forEach(o=>t.push(o.load())),k.forEach(o=>{o.closest(E())||(v.delete(o),U(o))}),t}async function be(e,{language:t,locale:o,remember:r=!0}={}){let n=s(e);if(!n)throw new _(`Not a country code: ${e}`,{code:"INVALID_COUNTRY"});let l=he(n),c=o||l?.locale,i=c||a.locale,u=we(t,l),m=n!==a.country?.toUpperCase()||u!==a.language||i!==a.locale;if(a.country=n,a.language=u||void 0,a.locale=i,r&&N({country:n,language:u,locale:c}),!m)return L(),f.state;t!==void 0&&z();let $=Ce(n);return L(),A("country-changed",{country:n,language:a.language}),await Promise.all($),f.state}var{Tether:q}=window;if(!q)throw new Error("tether.markets.js runs after the Tether script, which loads it");q.__parts.markets=T;})();
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;})();
Binary file