@occluze/tether 0.6.8 → 0.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.
Files changed (215) hide show
  1. package/README.md +28 -28
  2. package/dist/esm/astro.js +2 -2
  3. package/dist/esm/chunks/account-CXMA5RPZ.js +1 -0
  4. package/dist/esm/chunks/account-pages-IZO7FEOZ.js +1 -0
  5. package/dist/esm/chunks/analytics-PG5FPRDN.js +1 -0
  6. package/dist/esm/chunks/chunk-4HD4J5JC.js +1 -0
  7. package/dist/esm/chunks/chunk-6TFMLT4A.js +4 -0
  8. package/dist/esm/chunks/chunk-BBVUVPMO.js +1 -0
  9. package/dist/esm/chunks/chunk-E5YO6274.js +1 -0
  10. package/dist/esm/chunks/chunk-EW5SYO6L.js +1 -0
  11. package/dist/esm/chunks/chunk-HJY2JSNB.js +1 -0
  12. package/dist/esm/chunks/chunk-MQYB6BH4.js +1 -0
  13. package/dist/esm/chunks/chunk-N3V45JPS.js +1 -0
  14. package/dist/esm/chunks/chunk-RPMBCAGS.js +1 -0
  15. package/dist/esm/chunks/chunk-VFNHIGCS.js +1 -0
  16. package/dist/esm/chunks/chunk-WT7RGGJU.js +1 -0
  17. package/dist/esm/chunks/chunk-YN6LEBEN.js +1 -0
  18. package/dist/esm/chunks/chunk-Z6HS3H7K.js +1 -0
  19. package/dist/esm/chunks/diagnose-XCEBQKBO.js +14 -0
  20. package/dist/esm/chunks/extras-4HU3VSBQ.js +1 -0
  21. package/dist/esm/chunks/markets-ui-M4IQ62CT.js +1 -0
  22. package/dist/esm/chunks/search-A5DS2IOS.js +1 -0
  23. package/dist/esm/index.js +1 -1
  24. package/dist/esm/server.js +2 -2
  25. package/dist/presets/barba.esm.js +19 -23
  26. package/dist/tether.account-pages.js +332 -367
  27. package/dist/tether.account-pages.min.js +1 -1
  28. package/dist/tether.account.js +253 -492
  29. package/dist/tether.account.min.js +1 -1
  30. package/dist/tether.analytics.js +82 -89
  31. package/dist/tether.analytics.min.js +1 -1
  32. package/dist/tether.diagnose.js +52 -34
  33. package/dist/tether.diagnose.min.js +2 -2
  34. package/dist/tether.extras.js +42 -37
  35. package/dist/tether.extras.min.js +1 -1
  36. package/dist/tether.js +1361 -935
  37. package/dist/tether.markets.js +89 -91
  38. package/dist/tether.markets.min.js +1 -1
  39. package/dist/tether.min.js +0 -0
  40. package/dist/tether.min.js.map +4 -4
  41. package/dist/tether.search.js +60 -69
  42. package/dist/tether.search.min.js +1 -1
  43. package/dist/types/server/src/shared/account-orders.d.ts +44 -0
  44. package/dist/types/server/src/shared/account-routes.d.ts +153 -0
  45. package/dist/types/server/src/shared/api-versions.d.ts +13 -0
  46. package/dist/types/server/src/shared/cart-id.d.ts +2 -0
  47. package/dist/types/server/src/shared/error-message.d.ts +2 -0
  48. package/dist/types/server/src/shared/json.d.ts +25 -0
  49. package/dist/types/server/src/shared/market-codes.d.ts +16 -0
  50. package/dist/types/src/account/addresses-view.d.ts +5 -0
  51. package/dist/types/src/account/answers.d.ts +40 -0
  52. package/dist/types/src/account/markup.d.ts +19 -0
  53. package/dist/types/src/account/operations.d.ts +41 -0
  54. package/dist/types/src/account/order-lines.d.ts +13 -0
  55. package/dist/types/src/account/order-list.d.ts +12 -0
  56. package/dist/types/src/account/order-page.d.ts +6 -0
  57. package/dist/types/src/account/page-answers.d.ts +182 -0
  58. package/dist/types/src/account/page-events.d.ts +2 -0
  59. package/dist/types/src/account/server-client.d.ts +60 -0
  60. package/dist/types/src/account/subscriptions-view.d.ts +2 -0
  61. package/dist/types/src/account-api.d.ts +18 -0
  62. package/dist/types/src/account-marks.d.ts +15 -0
  63. package/dist/types/src/account-pages.d.ts +8 -0
  64. package/dist/types/src/account.d.ts +64 -0
  65. package/dist/types/src/amounts.d.ts +12 -0
  66. package/dist/types/src/analytics-shopify.d.ts +41 -0
  67. package/dist/types/src/analytics.d.ts +2 -0
  68. package/dist/types/src/api-version.d.ts +28 -0
  69. package/dist/types/src/astro.d.ts +42 -0
  70. package/dist/types/src/cart/cart-shape.d.ts +43 -0
  71. package/dist/types/src/cart/checkout.d.ts +16 -0
  72. package/dist/types/src/cart/drawer.d.ts +18 -0
  73. package/dist/types/src/cart/mutations.d.ts +85 -0
  74. package/dist/types/src/cart/render.d.ts +17 -0
  75. package/dist/types/src/cart/store.d.ts +185 -0
  76. package/dist/types/src/cart.d.ts +106 -0
  77. package/dist/types/src/client.d.ts +134 -0
  78. package/dist/types/src/collection.d.ts +25 -0
  79. package/dist/types/src/config-sections.d.ts +40 -0
  80. package/dist/types/src/config.d.ts +190 -0
  81. package/dist/types/src/controls/cart-controls.d.ts +2 -0
  82. package/dist/types/src/controls/discount.d.ts +2 -0
  83. package/dist/types/src/controls/extras.d.ts +5 -0
  84. package/dist/types/src/controls/navigation.d.ts +12 -0
  85. package/dist/types/src/diagnose-markup.d.ts +19 -0
  86. package/dist/types/src/diagnose.d.ts +60 -0
  87. package/dist/types/src/dom.d.ts +75 -0
  88. package/dist/types/src/extras.d.ts +21 -0
  89. package/dist/types/src/fragments.d.ts +158 -0
  90. package/dist/types/src/globals.d.ts +15 -0
  91. package/dist/types/src/images.d.ts +20 -0
  92. package/dist/types/src/index.d.ts +167 -0
  93. package/dist/types/src/initial.d.ts +56 -0
  94. package/dist/types/src/lazy.d.ts +28 -0
  95. package/dist/types/src/loader.d.ts +84 -0
  96. package/dist/types/src/market-codes.d.ts +6 -0
  97. package/dist/types/src/markets-ui.d.ts +32 -0
  98. package/dist/types/src/markets.d.ts +72 -0
  99. package/dist/types/src/markup.d.ts +131 -0
  100. package/dist/types/src/mounting.d.ts +46 -0
  101. package/dist/types/src/page-market.d.ts +27 -0
  102. package/dist/types/src/presets/barba.d.ts +56 -0
  103. package/dist/types/src/product-events.d.ts +2 -0
  104. package/dist/types/src/product-render.d.ts +17 -0
  105. package/dist/types/src/product-shape.d.ts +90 -0
  106. package/dist/types/src/product-state.d.ts +110 -0
  107. package/dist/types/src/product.d.ts +66 -0
  108. package/dist/types/src/repeaters.d.ts +16 -0
  109. package/dist/types/src/search.d.ts +33 -0
  110. package/dist/types/src/selling-plans.d.ts +64 -0
  111. package/dist/types/src/server.d.ts +88 -0
  112. package/dist/types/src/shopify-values.d.ts +46 -0
  113. package/dist/types/src/status.d.ts +33 -0
  114. package/dist/types/src/storage.d.ts +12 -0
  115. package/dist/types/src/store-html.d.ts +39 -0
  116. package/dist/types/src/storefront/catalog.d.ts +38 -0
  117. package/dist/types/src/storefront/json-ld.d.ts +20 -0
  118. package/dist/types/src/variant-render.d.ts +14 -0
  119. package/package.json +24 -24
  120. package/dist/esm/chunks/account-C3NP6HFB.js +0 -1
  121. package/dist/esm/chunks/account-pages-WLK374FO.js +0 -1
  122. package/dist/esm/chunks/analytics-G3SAWMNL.js +0 -1
  123. package/dist/esm/chunks/chunk-27PJJZGC.js +0 -1
  124. package/dist/esm/chunks/chunk-2FSXS55U.js +0 -1
  125. package/dist/esm/chunks/chunk-FCSWQDVV.js +0 -1
  126. package/dist/esm/chunks/chunk-FOMSMIAM.js +0 -1
  127. package/dist/esm/chunks/chunk-GZJTCLLW.js +0 -1
  128. package/dist/esm/chunks/chunk-HEQILZVR.js +0 -1
  129. package/dist/esm/chunks/chunk-JOOEXYF3.js +0 -4
  130. package/dist/esm/chunks/chunk-MPTQYLSM.js +0 -1
  131. package/dist/esm/chunks/chunk-NEHZ37TU.js +0 -3
  132. package/dist/esm/chunks/chunk-V74KGEJF.js +0 -1
  133. package/dist/esm/chunks/chunk-VT4CDUJJ.js +0 -1
  134. package/dist/esm/chunks/chunk-YJLWX2HK.js +0 -1
  135. package/dist/esm/chunks/diagnose-6VVGZNTY.js +0 -14
  136. package/dist/esm/chunks/extras-GJVRDFM3.js +0 -1
  137. package/dist/esm/chunks/markets-ui-UNB4PTA7.js +0 -1
  138. package/dist/esm/chunks/search-OU75RNQL.js +0 -1
  139. package/src/account/addresses-view.js +0 -92
  140. package/src/account/browser-session.js +0 -359
  141. package/src/account/markup.js +0 -48
  142. package/src/account/operations.js +0 -180
  143. package/src/account/order-lines.js +0 -96
  144. package/src/account/order-list.js +0 -91
  145. package/src/account/order-page.js +0 -192
  146. package/src/account/page-events.js +0 -288
  147. package/src/account/server-client.js +0 -172
  148. package/src/account/shared.js +0 -111
  149. package/src/account/shopify-auth.js +0 -150
  150. package/src/account/subscriptions-view.js +0 -158
  151. package/src/account-api.js +0 -118
  152. package/src/account-links.js +0 -35
  153. package/src/account-pages.js +0 -89
  154. package/src/account.js +0 -342
  155. package/src/amounts.js +0 -36
  156. package/src/analytics-shopify.js +0 -241
  157. package/src/analytics.js +0 -352
  158. package/src/api-version.js +0 -85
  159. package/src/astro.js +0 -266
  160. package/src/cart/checkout.js +0 -97
  161. package/src/cart/drawer.js +0 -138
  162. package/src/cart/mutations.js +0 -234
  163. package/src/cart/render.js +0 -294
  164. package/src/cart/store.js +0 -326
  165. package/src/cart.js +0 -391
  166. package/src/client.js +0 -267
  167. package/src/collection.js +0 -183
  168. package/src/config.js +0 -349
  169. package/src/controls/cart-controls.js +0 -155
  170. package/src/controls/discount.js +0 -96
  171. package/src/controls/extras.js +0 -63
  172. package/src/controls/navigation.js +0 -83
  173. package/src/diagnose-markup.js +0 -333
  174. package/src/diagnose.js +0 -295
  175. package/src/dom.js +0 -287
  176. package/src/extras.js +0 -145
  177. package/src/fragments.js +0 -237
  178. package/src/images.js +0 -104
  179. package/src/index.js +0 -353
  180. package/src/initial.js +0 -87
  181. package/src/lazy-iife.js +0 -116
  182. package/src/lazy.js +0 -39
  183. package/src/loader.js +0 -337
  184. package/src/market-codes.js +0 -35
  185. package/src/markets-ui.js +0 -204
  186. package/src/markets.js +0 -334
  187. package/src/markup.js +0 -64
  188. package/src/mounting.js +0 -277
  189. package/src/page-market.js +0 -116
  190. package/src/parts/account-pages.js +0 -6
  191. package/src/parts/account.js +0 -6
  192. package/src/parts/analytics.js +0 -6
  193. package/src/parts/diagnose.js +0 -6
  194. package/src/parts/extras.js +0 -6
  195. package/src/parts/markets.js +0 -6
  196. package/src/parts/search.js +0 -6
  197. package/src/presets/barba.js +0 -190
  198. package/src/product-events.js +0 -130
  199. package/src/product-render.js +0 -257
  200. package/src/product-state.js +0 -318
  201. package/src/product.js +0 -344
  202. package/src/repeaters.js +0 -173
  203. package/src/search.js +0 -323
  204. package/src/selling-plans.js +0 -154
  205. package/src/server.js +0 -215
  206. package/src/shopify-values.js +0 -89
  207. package/src/status.js +0 -126
  208. package/src/store-html.js +0 -0
  209. package/src/storefront/catalog.js +0 -199
  210. package/src/storefront/json-ld.js +0 -167
  211. package/src/variant-render.js +0 -165
  212. package/types/astro.d.ts +0 -28
  213. package/types/barba.d.ts +0 -16
  214. package/types/index.d.ts +0 -577
  215. package/types/server.d.ts +0 -182
@@ -1,165 +0,0 @@
1
- /**
2
- * The DOM writes of a product scope that follow the visitor's choice, on every change: `product-state.js`'s view as
3
- * text, selected and unavailable states, `tether-show` conditions and the add-to-cart buttons.
4
- */
5
- import { attr, sel, get, qsa, formatMoney, formatPercent, setText, setImage, setSelected, show } from './dom.js';
6
- import { STATUS_KEYS, ownedBy } from './status.js';
7
- import { allocationFor } from './selling-plans.js';
8
- import { isValueAvailable, planBindTexts, variantBindTexts } from './product-state.js';
9
- import { isSelect, selectsIn } from './product-render.js';
10
- /** @import { Formatters, ProductView } from './product-state.js' */
11
- /** @import { RenderScope } from './product-render.js' */
12
-
13
- /** @type {Formatters} */
14
- const FORMAT = { money: formatMoney, percent: formatPercent };
15
-
16
- /**
17
- * @param {Element} el
18
- * @returns {el is HTMLInputElement}
19
- */
20
- const isInput = (el) => el.tagName === 'INPUT';
21
-
22
- /**
23
- * The element of an add-to-cart button that holds its label, with the label as written kept in
24
- * `data-tether-label`, so mode-dependent texts (`tether-subscribe-text`, `tether-soldout-text`) can be undone.
25
- *
26
- * @param {HTMLElement} button
27
- * @returns {{ label: HTMLElement, original: string }}
28
- */
29
- export function addButtonLabel(button) {
30
- const label = qsa(button, sel('add-label'))[0] ?? button;
31
- const original = label.dataset['tetherLabel'] ?? (isInput(label) ? label.value : label.textContent);
32
- label.dataset['tetherLabel'] = original;
33
- return { label, original };
34
- }
35
-
36
- /**
37
- * @param {RenderScope} scope
38
- * @param {ProductView} view
39
- */
40
- function renderOptionStates(scope, view) {
41
- const { product } = scope;
42
- const selectedValue = (/** @type {string | null} */ authored) => view.selected[scope.optName(authored)] ?? '';
43
- scope.$(sel('option-selected')).forEach((el) => {
44
- setText(el, selectedValue(get(el, 'option-selected')));
45
- });
46
- scope.$(sel('option-list')).forEach((container) => {
47
- const name = scope.optName(get(container, 'option-list'));
48
- qsa(container, sel('option-value')).forEach((node) => {
49
- const value = get(node, 'option-value') ?? '';
50
- setSelected(node, view.selected[name] === value);
51
- const unavailable = !isValueAvailable(product, view.selected, name, value);
52
- node.classList.toggle('is-unavailable', unavailable);
53
- node.setAttribute('data-unavailable', unavailable ? 'true' : 'false');
54
- });
55
- });
56
- selectsIn(scope, sel('option')).forEach((select) => {
57
- select.value = selectedValue(get(select, 'option'));
58
- });
59
- selectsIn(scope, sel('variant-select')).forEach((select) => {
60
- select.value = view.variant.id;
61
- });
62
- }
63
-
64
- /**
65
- * The purchase toggles and the plan list and select.
66
- *
67
- * @param {RenderScope} scope
68
- * @param {ProductView} view
69
- */
70
- function renderPurchaseStates(scope, view) {
71
- const { variant, purchase, isSubscription } = view;
72
- scope.$(sel('purchase')).forEach((el) => {
73
- if (isSelect(el)) {
74
- el.value = purchase.kind;
75
- return;
76
- }
77
- const mode = get(el, 'purchase');
78
- setSelected(el, mode === purchase.kind);
79
- const unavailable = mode === 'subscription' ? !view.subscriptionAvailable : scope.product.requiresSellingPlan;
80
- el.classList.toggle('is-unavailable', unavailable);
81
- });
82
- scope.$(sel('plan-value')).forEach((node) => {
83
- const planId = get(node, 'plan-value') ?? '';
84
- setSelected(node, isSubscription && planId === purchase.planId);
85
- node.classList.toggle('is-unavailable', !allocationFor(variant, planId));
86
- const plan = scope.plans.find((candidate) => candidate.id === planId);
87
- const texts = planBindTexts(variant, planId, plan, FORMAT);
88
- qsa(node, sel('plan-bind')).forEach((el) => {
89
- const text = texts.get(get(el, 'plan-bind') ?? '');
90
- if (text) setText(el, text());
91
- });
92
- });
93
- selectsIn(scope, sel('plan')).forEach((select) => {
94
- select.value = isSubscription ? (purchase.planId ?? '') : '';
95
- });
96
- }
97
-
98
- /**
99
- * The `tether-show` conditions, with the scope's own status: a product scope that renders is ready.
100
- *
101
- * @param {RenderScope} scope
102
- * @param {ProductView} view
103
- */
104
- function renderConditions(scope, view) {
105
- /** @type {Map<string, boolean>} */
106
- const conditions = new Map(Object.entries(view.show));
107
- STATUS_KEYS.forEach((status) => conditions.set(status, status === 'ready'));
108
- scope.$(sel('show')).forEach((el) => {
109
- const key = get(el, 'show') ?? '';
110
- const visible = conditions.get(key);
111
- if (visible === undefined) return;
112
- // State blocks of a list nested in this product belong to that list.
113
- if (STATUS_KEYS.some((status) => status === key) && !ownedBy(el, scope.root)) return;
114
- show(el, visible);
115
- });
116
- }
117
-
118
- /**
119
- * @param {RenderScope} scope
120
- * @param {ProductView} view
121
- */
122
- function renderAddButtons(scope, view) {
123
- const disabled = !view.variant.availableForSale;
124
- scope.$(sel('add-to-cart')).forEach((button) => {
125
- button.classList.toggle('is-disabled', disabled);
126
- button.setAttribute('aria-disabled', String(disabled));
127
- // A <button> or <input> is disabled; a link or div carries only aria-disabled.
128
- if ('disabled' in button) button.disabled = disabled;
129
- const soldOutText = get(button, 'soldout-text');
130
- const subscribeText = get(button, 'subscribe-text');
131
- if (!soldOutText && !subscribeText) return;
132
- const { label, original } = addButtonLabel(button);
133
- let text = original;
134
- if (view.isSubscription && subscribeText) text = subscribeText;
135
- if (disabled && soldOutText) text = soldOutText;
136
- if (button.getAttribute('aria-busy') !== 'true') setText(label, text);
137
- });
138
- }
139
-
140
- /**
141
- * Writes what follows the variant and purchase.
142
- *
143
- * @param {RenderScope} scope
144
- * @param {ProductView} view
145
- */
146
- export function writeVariant(scope, view) {
147
- const { variant } = view;
148
- const { product } = scope;
149
- const texts = variantBindTexts(view, FORMAT);
150
- scope.$(sel('bind')).forEach((el) => {
151
- const key = get(el, 'bind') ?? '';
152
- if (key === 'variant-image') {
153
- setImage(el, variant.image?.url || product.featuredImage?.url, variant.image?.altText || product.title);
154
- return;
155
- }
156
- const text = texts.get(key);
157
- if (text) setText(el, text());
158
- });
159
- renderOptionStates(scope, view);
160
- renderPurchaseStates(scope, view);
161
- renderConditions(scope, view);
162
- scope.root.classList.toggle('is-subscription', view.isSubscription);
163
- scope.root.setAttribute(attr('purchase-mode'), view.isSubscription ? 'subscription' : 'one-time');
164
- renderAddButtons(scope, view);
165
- }
package/types/astro.d.ts DELETED
@@ -1,28 +0,0 @@
1
- import type { TetherConfig } from './index.js';
2
-
3
- type Serializable<T> = {
4
- [
5
- K in keyof T as T[K] extends ((...args: any[]) => any) | null | undefined
6
- ? Exclude<T[K], null | undefined> extends (...args: any[]) => any
7
- ? never
8
- : K
9
- : K
10
- ]: T[K];
11
- };
12
-
13
- export interface TetherAstroOptions extends Partial<Serializable<TetherConfig>> {
14
- /** Add the Tether script to every page (default true). False: import and init it yourself. */
15
- inject?: boolean;
16
- /** Files that restart the dev server when they change (default: src/shop.config.js/.mjs/.ts). */
17
- watch?: string[];
18
- }
19
-
20
- /**
21
- * Astro integration: Tether on every page, store and token from .env
22
- * (PUBLIC_SHOPIFY_DOMAIN, PUBLIC_SHOPIFY_STOREFRONT_TOKEN). Functions (onError, hooks) go in
23
- * window.TETHER_CONFIG in your layout.
24
- */
25
- export default function tether(options?: TetherAstroOptions): {
26
- name: string;
27
- hooks: Record<string, (...args: any[]) => unknown>;
28
- };
package/types/barba.d.ts DELETED
@@ -1,16 +0,0 @@
1
- import type { TetherConfig } from './index.js';
2
-
3
- export interface BarbaPresetOptions {
4
- gsap?: () => unknown;
5
- lenis?: (() => { resize?(): void; stop?(): void; start?(): void } | null | undefined) | null;
6
- scrollTrigger?: () => unknown;
7
- lockScroll?: ((drawer: HTMLElement) => void) | null;
8
- unlockScroll?: (() => void) | null;
9
- onResize?: (() => void) | null;
10
- onValueChange?: ((el: HTMLElement, previousText: string) => void) | null;
11
- animateLines?: boolean;
12
- lineDuration?: number;
13
- }
14
-
15
- /** Hooks for sites with page transitions, smooth scroll and GSAP: spread into Tether.init(). */
16
- export declare function barbaPreset(options?: BarbaPresetOptions): Partial<TetherConfig>;