@magic-spells/cart-progress-bar 0.1.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.
@@ -0,0 +1,355 @@
1
+ (function (global, factory) {
2
+ typeof exports === 'object' && typeof module !== 'undefined' ? factory(exports) :
3
+ typeof define === 'function' && define.amd ? define(['exports'], factory) :
4
+ (global = typeof globalThis !== 'undefined' ? globalThis : global || self, factory(global.CartProgressBar = {}));
5
+ })(this, (function (exports) { 'use strict';
6
+
7
+ /**
8
+ * ProgressBar helper class for the visual progress bar element
9
+ */
10
+ class ProgressBar extends HTMLElement {
11
+ constructor() {
12
+ super();
13
+ this.#setupProgressBar();
14
+ }
15
+
16
+ #setupProgressBar() {
17
+ this.setAttribute('role', 'progressbar');
18
+ this.setAttribute('aria-valuemin', '0');
19
+ this.setAttribute('aria-valuemax', '100');
20
+ this.setAttribute('aria-valuenow', '0');
21
+
22
+ // Create the visual progress bar
23
+ this.innerHTML = '<div class="progress-bar-fill"></div>';
24
+ }
25
+
26
+ setPercent(percent) {
27
+ const clampedPercent = Math.max(0, Math.min(100, percent));
28
+ this.style.setProperty('--cart-progress-percent', `${clampedPercent}%`);
29
+ this.setAttribute('aria-valuenow', clampedPercent);
30
+ }
31
+ }
32
+
33
+ // Define ProgressBar custom element immediately so it's available for CartProgressBar
34
+ customElements.define('progress-bar', ProgressBar);
35
+
36
+ /**
37
+ * CartProgressBar main component
38
+ */
39
+ class CartProgressBar extends HTMLElement {
40
+ // Private fields
41
+ #minAmount = 0;
42
+ #currentAmount = 0;
43
+ #progressPercent = 0;
44
+ #originalAboveMessage = '';
45
+ #originalBelowMessage = '';
46
+ #progressBar = null;
47
+ #messageElement = null;
48
+
49
+ /**
50
+ * Define which attributes should be observed for changes
51
+ */
52
+ static get observedAttributes() {
53
+ return ['threshold', 'current', 'message-above', 'message-below'];
54
+ }
55
+
56
+ constructor() {
57
+ super();
58
+ this.#init();
59
+ }
60
+
61
+ #init() {
62
+ // Read initial attributes
63
+ this.#minAmount = parseFloat(this.getAttribute('threshold')) || 0;
64
+ this.#currentAmount = parseFloat(this.getAttribute('current')) || 0;
65
+
66
+ // Store original message templates
67
+ this.#originalAboveMessage = this.getAttribute('message-above') || '';
68
+ this.#originalBelowMessage = this.getAttribute('message-below') || '';
69
+ }
70
+
71
+ async connectedCallback() {
72
+ // ensure the child custom element has been registered
73
+ await customElements.whenDefined('progress-bar');
74
+
75
+ if (!customElements.get('progress-bar')) {
76
+ throw new Error('<progress-bar> must be registered before <cart-progress-bar> runs');
77
+ }
78
+
79
+ this.#render();
80
+ this.#updateProgress();
81
+ this.#attachListeners();
82
+ }
83
+
84
+ attributeChangedCallback(name, oldValue, newValue) {
85
+ if (oldValue === newValue) return;
86
+
87
+ switch (name) {
88
+ case 'threshold':
89
+ this.#minAmount = parseFloat(newValue) || 0;
90
+ this.#updateProgress();
91
+ break;
92
+ case 'current':
93
+ this.#currentAmount = parseFloat(newValue) || 0;
94
+ this.#updateProgress();
95
+ break;
96
+ case 'message-above':
97
+ this.#originalAboveMessage = newValue || '';
98
+ this.#updateMessages();
99
+ break;
100
+ case 'message-below':
101
+ this.#originalBelowMessage = newValue || '';
102
+ this.#updateMessages();
103
+ break;
104
+ }
105
+ }
106
+
107
+ #render() {
108
+ // Find or create the message element
109
+ this.#messageElement =
110
+ this.querySelector('[data-content-cart-progress-message]') ||
111
+ this.querySelector('p[data-content-cart-progress-message]');
112
+
113
+ // Find existing progress bar (user can add their own)
114
+ this.#progressBar = this.querySelector('progress-bar');
115
+
116
+ // Create message element if it doesn't exist but we have message templates
117
+ if (!this.#messageElement && (this.#originalAboveMessage || this.#originalBelowMessage)) {
118
+ this.#messageElement = document.createElement('p');
119
+ this.#messageElement.setAttribute('data-content-cart-progress-message', '');
120
+ this.appendChild(this.#messageElement);
121
+ }
122
+
123
+ // Create progress bar if it doesn't exist - add it at the end (below text message)
124
+ if (!this.#progressBar) {
125
+ // Ensure progress-bar is defined before creating
126
+ if (customElements.get('progress-bar')) {
127
+ this.#progressBar = document.createElement('progress-bar');
128
+ this.appendChild(this.#progressBar);
129
+ } else {
130
+ // Fallback: wait for definition
131
+ customElements.whenDefined('progress-bar').then(() => {
132
+ if (!this.#progressBar) {
133
+ this.#progressBar = document.createElement('progress-bar');
134
+ this.appendChild(this.#progressBar);
135
+ this.#updateProgress(); // Update progress after creating
136
+ }
137
+ });
138
+ }
139
+ }
140
+ }
141
+
142
+ #updateProgress() {
143
+ if (this.#minAmount === 0) {
144
+ this.#progressPercent = 100;
145
+ } else {
146
+ this.#progressPercent = Math.min(100, (this.#currentAmount / this.#minAmount) * 100);
147
+ }
148
+
149
+ // Update progress bar
150
+ if (this.#progressBar) {
151
+ this.#progressBar.setPercent(this.#progressPercent);
152
+ }
153
+
154
+ // Update messages
155
+ this.#updateMessages();
156
+
157
+ // Update component state
158
+ this.#updateComponentState();
159
+ }
160
+
161
+ #attachListeners() {
162
+ // Find the nearest cart-panel component
163
+ const cartPanel = this.closest('cart-panel');
164
+
165
+ if (cartPanel) {
166
+ // Listen for cart data changes
167
+ cartPanel.addEventListener('cart-dialog:data-changed', (event) => {
168
+ this.#handleCartDataChange(event);
169
+ });
170
+ }
171
+ }
172
+
173
+ #handleCartDataChange(event) {
174
+ const updatedCart = event.detail;
175
+
176
+ if (updatedCart && typeof updatedCart.total_price !== 'undefined') {
177
+ // Convert from cents to dollars if needed (Shopify typically returns cents)
178
+ const currentAmount = updatedCart.total_price / 100;
179
+ this.setCurrentAmount(currentAmount);
180
+ }
181
+ }
182
+
183
+ #updateMessages() {
184
+ const isComplete = this.#currentAmount >= this.#minAmount;
185
+ const remainingAmount = Math.max(0, this.#minAmount - this.#currentAmount);
186
+
187
+ // Format remaining amount as currency (assuming USD for now)
188
+ const formattedAmount = this.#formatCurrency(remainingAmount);
189
+
190
+ // Update the single message element
191
+ if (this.#messageElement) {
192
+ let messageTemplate;
193
+
194
+ if (isComplete && this.#originalAboveMessage) {
195
+ // Show success message when complete
196
+ messageTemplate = this.#originalAboveMessage;
197
+ } else if (!isComplete) {
198
+ // Show progress message when incomplete
199
+ messageTemplate = this.#originalBelowMessage || this.#originalAboveMessage;
200
+ }
201
+
202
+ if (messageTemplate) {
203
+ const message = messageTemplate.replace(/\$\{left\}/g, formattedAmount);
204
+ this.#messageElement.textContent = message;
205
+ this.#messageElement.style.display = 'block';
206
+ } else {
207
+ // Hide message if no template available for current state
208
+ this.#messageElement.style.display = 'none';
209
+ }
210
+ }
211
+ }
212
+
213
+ #updateComponentState() {
214
+ const isComplete = this.#currentAmount >= this.#minAmount;
215
+
216
+ if (isComplete) {
217
+ this.setAttribute('data-complete', 'true');
218
+ this.removeAttribute('data-incomplete');
219
+ } else {
220
+ this.setAttribute('data-incomplete', 'true');
221
+ this.removeAttribute('data-complete');
222
+ }
223
+
224
+ // Set progress level classes for styling
225
+ this.classList.remove('progress-low', 'progress-medium', 'progress-high', 'progress-complete');
226
+
227
+ if (isComplete) {
228
+ this.classList.add('progress-complete');
229
+ } else if (this.#progressPercent >= 75) {
230
+ this.classList.add('progress-high');
231
+ } else if (this.#progressPercent >= 50) {
232
+ this.classList.add('progress-medium');
233
+ } else {
234
+ this.classList.add('progress-low');
235
+ }
236
+ }
237
+
238
+ #formatCurrency(amount) {
239
+ // Basic currency formatting - could be enhanced with locale/currency options
240
+ return new Intl.NumberFormat('en-US', {
241
+ style: 'currency',
242
+ currency: 'USD',
243
+ minimumFractionDigits: 2,
244
+ maximumFractionDigits: 2,
245
+ }).format(amount);
246
+ }
247
+
248
+ /**
249
+ * Public API: Set the progress percentage directly
250
+ * @param {number} percent - Progress percentage (0-100)
251
+ */
252
+ setPercent(percent) {
253
+ const clampedPercent = Math.max(0, Math.min(100, percent));
254
+ this.#progressPercent = clampedPercent;
255
+
256
+ if (this.#progressBar) {
257
+ this.#progressBar.setPercent(clampedPercent);
258
+ }
259
+
260
+ // Calculate current amount based on percentage
261
+ this.#currentAmount = (clampedPercent / 100) * this.#minAmount;
262
+ this.setAttribute('current', this.#currentAmount.toString());
263
+
264
+ this.#updateMessages();
265
+ this.#updateComponentState();
266
+ }
267
+
268
+ /**
269
+ * Public API: Set the current cart amount
270
+ * @param {number} amount - Current cart amount
271
+ */
272
+ setCurrentAmount(amount) {
273
+ this.#currentAmount = parseFloat(amount) || 0;
274
+ this.setAttribute('current', this.#currentAmount.toString());
275
+ this.#updateProgress();
276
+ }
277
+
278
+ /**
279
+ * Public API: Set the threshold amount for free shipping
280
+ * @param {number} amount - Threshold amount for free shipping
281
+ */
282
+ setThresholdAmount(amount) {
283
+ this.#minAmount = parseFloat(amount) || 0;
284
+ this.setAttribute('threshold', this.#minAmount.toString());
285
+ this.#updateProgress();
286
+ }
287
+
288
+ /**
289
+ * Public API: Set the minimum amount for free shipping (deprecated - use setThresholdAmount)
290
+ * @param {number} amount - Minimum amount threshold
291
+ * @deprecated Use setThresholdAmount instead
292
+ */
293
+ setMinAmount(amount) {
294
+ this.setThresholdAmount(amount);
295
+ }
296
+
297
+ /**
298
+ * Public API: Get current progress information
299
+ */
300
+ getProgress() {
301
+ return {
302
+ currentAmount: this.#currentAmount,
303
+ thresholdAmount: this.#minAmount,
304
+ minAmount: this.#minAmount, // backwards compatibility
305
+ remainingAmount: Math.max(0, this.#minAmount - this.#currentAmount),
306
+ percent: this.#progressPercent,
307
+ isComplete: this.#currentAmount >= this.#minAmount,
308
+ };
309
+ }
310
+
311
+ /**
312
+ * Public API: Update message templates
313
+ * @param {string} aboveMessage - Message template for above the bar
314
+ * @param {string} belowMessage - Message template for below the bar
315
+ */
316
+ setMessages(aboveMessage = null, belowMessage = null) {
317
+ if (aboveMessage !== null) {
318
+ this.#originalAboveMessage = aboveMessage;
319
+ this.setAttribute('message-above', aboveMessage);
320
+ }
321
+
322
+ if (belowMessage !== null) {
323
+ this.#originalBelowMessage = belowMessage;
324
+ this.setAttribute('message-below', belowMessage);
325
+ }
326
+
327
+ this.#updateMessages();
328
+ }
329
+
330
+ // Getters
331
+ get currentAmount() {
332
+ return this.#currentAmount;
333
+ }
334
+ get thresholdAmount() {
335
+ return this.#minAmount;
336
+ }
337
+ get minAmount() {
338
+ return this.#minAmount;
339
+ } // backwards compatibility
340
+ get percent() {
341
+ return this.#progressPercent;
342
+ }
343
+ get isComplete() {
344
+ return this.#currentAmount >= this.#minAmount;
345
+ }
346
+ }
347
+
348
+ // Define CartProgressBar custom element
349
+ customElements.define('cart-progress-bar', CartProgressBar);
350
+
351
+ exports.CartProgressBar = CartProgressBar;
352
+ exports.ProgressBar = ProgressBar;
353
+
354
+ }));
355
+ //# sourceMappingURL=cart-progress-bar.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"cart-progress-bar.js","sources":["../src/cart-progress-bar.js"],"sourcesContent":["import './cart-progress-bar.scss';\n\n/**\n * ProgressBar helper class for the visual progress bar element\n */\nclass ProgressBar extends HTMLElement {\n\tconstructor() {\n\t\tsuper();\n\t\tthis.#setupProgressBar();\n\t}\n\n\t#setupProgressBar() {\n\t\tthis.setAttribute('role', 'progressbar');\n\t\tthis.setAttribute('aria-valuemin', '0');\n\t\tthis.setAttribute('aria-valuemax', '100');\n\t\tthis.setAttribute('aria-valuenow', '0');\n\n\t\t// Create the visual progress bar\n\t\tthis.innerHTML = '<div class=\"progress-bar-fill\"></div>';\n\t}\n\n\tsetPercent(percent) {\n\t\tconst clampedPercent = Math.max(0, Math.min(100, percent));\n\t\tthis.style.setProperty('--cart-progress-percent', `${clampedPercent}%`);\n\t\tthis.setAttribute('aria-valuenow', clampedPercent);\n\t}\n}\n\n// Define ProgressBar custom element immediately so it's available for CartProgressBar\ncustomElements.define('progress-bar', ProgressBar);\n\n/**\n * CartProgressBar main component\n */\nclass CartProgressBar extends HTMLElement {\n\t// Private fields\n\t#minAmount = 0;\n\t#currentAmount = 0;\n\t#progressPercent = 0;\n\t#originalAboveMessage = '';\n\t#originalBelowMessage = '';\n\t#progressBar = null;\n\t#messageElement = null;\n\n\t/**\n\t * Define which attributes should be observed for changes\n\t */\n\tstatic get observedAttributes() {\n\t\treturn ['threshold', 'current', 'message-above', 'message-below'];\n\t}\n\n\tconstructor() {\n\t\tsuper();\n\t\tthis.#init();\n\t}\n\n\t#init() {\n\t\t// Read initial attributes\n\t\tthis.#minAmount = parseFloat(this.getAttribute('threshold')) || 0;\n\t\tthis.#currentAmount = parseFloat(this.getAttribute('current')) || 0;\n\n\t\t// Store original message templates\n\t\tthis.#originalAboveMessage = this.getAttribute('message-above') || '';\n\t\tthis.#originalBelowMessage = this.getAttribute('message-below') || '';\n\t}\n\n\tasync connectedCallback() {\n\t\t// ensure the child custom element has been registered\n\t\tawait customElements.whenDefined('progress-bar');\n\n\t\tif (!customElements.get('progress-bar')) {\n\t\t\tthrow new Error('<progress-bar> must be registered before <cart-progress-bar> runs');\n\t\t}\n\n\t\tthis.#render();\n\t\tthis.#updateProgress();\n\t\tthis.#attachListeners();\n\t}\n\n\tattributeChangedCallback(name, oldValue, newValue) {\n\t\tif (oldValue === newValue) return;\n\n\t\tswitch (name) {\n\t\t\tcase 'threshold':\n\t\t\t\tthis.#minAmount = parseFloat(newValue) || 0;\n\t\t\t\tthis.#updateProgress();\n\t\t\t\tbreak;\n\t\t\tcase 'current':\n\t\t\t\tthis.#currentAmount = parseFloat(newValue) || 0;\n\t\t\t\tthis.#updateProgress();\n\t\t\t\tbreak;\n\t\t\tcase 'message-above':\n\t\t\t\tthis.#originalAboveMessage = newValue || '';\n\t\t\t\tthis.#updateMessages();\n\t\t\t\tbreak;\n\t\t\tcase 'message-below':\n\t\t\t\tthis.#originalBelowMessage = newValue || '';\n\t\t\t\tthis.#updateMessages();\n\t\t\t\tbreak;\n\t\t}\n\t}\n\n\t#render() {\n\t\t// Find or create the message element\n\t\tthis.#messageElement =\n\t\t\tthis.querySelector('[data-content-cart-progress-message]') ||\n\t\t\tthis.querySelector('p[data-content-cart-progress-message]');\n\n\t\t// Find existing progress bar (user can add their own)\n\t\tthis.#progressBar = this.querySelector('progress-bar');\n\n\t\t// Create message element if it doesn't exist but we have message templates\n\t\tif (!this.#messageElement && (this.#originalAboveMessage || this.#originalBelowMessage)) {\n\t\t\tthis.#messageElement = document.createElement('p');\n\t\t\tthis.#messageElement.setAttribute('data-content-cart-progress-message', '');\n\t\t\tthis.appendChild(this.#messageElement);\n\t\t}\n\n\t\t// Create progress bar if it doesn't exist - add it at the end (below text message)\n\t\tif (!this.#progressBar) {\n\t\t\t// Ensure progress-bar is defined before creating\n\t\t\tif (customElements.get('progress-bar')) {\n\t\t\t\tthis.#progressBar = document.createElement('progress-bar');\n\t\t\t\tthis.appendChild(this.#progressBar);\n\t\t\t} else {\n\t\t\t\t// Fallback: wait for definition\n\t\t\t\tcustomElements.whenDefined('progress-bar').then(() => {\n\t\t\t\t\tif (!this.#progressBar) {\n\t\t\t\t\t\tthis.#progressBar = document.createElement('progress-bar');\n\t\t\t\t\t\tthis.appendChild(this.#progressBar);\n\t\t\t\t\t\tthis.#updateProgress(); // Update progress after creating\n\t\t\t\t\t}\n\t\t\t\t});\n\t\t\t}\n\t\t}\n\t}\n\n\t#updateProgress() {\n\t\tif (this.#minAmount === 0) {\n\t\t\tthis.#progressPercent = 100;\n\t\t} else {\n\t\t\tthis.#progressPercent = Math.min(100, (this.#currentAmount / this.#minAmount) * 100);\n\t\t}\n\n\t\t// Update progress bar\n\t\tif (this.#progressBar) {\n\t\t\tthis.#progressBar.setPercent(this.#progressPercent);\n\t\t}\n\n\t\t// Update messages\n\t\tthis.#updateMessages();\n\n\t\t// Update component state\n\t\tthis.#updateComponentState();\n\t}\n\n\t#attachListeners() {\n\t\t// Find the nearest cart-panel component\n\t\tconst cartPanel = this.closest('cart-panel');\n\n\t\tif (cartPanel) {\n\t\t\t// Listen for cart data changes\n\t\t\tcartPanel.addEventListener('cart-dialog:data-changed', (event) => {\n\t\t\t\tthis.#handleCartDataChange(event);\n\t\t\t});\n\t\t}\n\t}\n\n\t#handleCartDataChange(event) {\n\t\tconst updatedCart = event.detail;\n\n\t\tif (updatedCart && typeof updatedCart.total_price !== 'undefined') {\n\t\t\t// Convert from cents to dollars if needed (Shopify typically returns cents)\n\t\t\tconst currentAmount = updatedCart.total_price / 100;\n\t\t\tthis.setCurrentAmount(currentAmount);\n\t\t}\n\t}\n\n\t#updateMessages() {\n\t\tconst isComplete = this.#currentAmount >= this.#minAmount;\n\t\tconst remainingAmount = Math.max(0, this.#minAmount - this.#currentAmount);\n\n\t\t// Format remaining amount as currency (assuming USD for now)\n\t\tconst formattedAmount = this.#formatCurrency(remainingAmount);\n\n\t\t// Update the single message element\n\t\tif (this.#messageElement) {\n\t\t\tlet messageTemplate;\n\n\t\t\tif (isComplete && this.#originalAboveMessage) {\n\t\t\t\t// Show success message when complete\n\t\t\t\tmessageTemplate = this.#originalAboveMessage;\n\t\t\t} else if (!isComplete) {\n\t\t\t\t// Show progress message when incomplete\n\t\t\t\tmessageTemplate = this.#originalBelowMessage || this.#originalAboveMessage;\n\t\t\t}\n\n\t\t\tif (messageTemplate) {\n\t\t\t\tconst message = messageTemplate.replace(/\\$\\{left\\}/g, formattedAmount);\n\t\t\t\tthis.#messageElement.textContent = message;\n\t\t\t\tthis.#messageElement.style.display = 'block';\n\t\t\t} else {\n\t\t\t\t// Hide message if no template available for current state\n\t\t\t\tthis.#messageElement.style.display = 'none';\n\t\t\t}\n\t\t}\n\t}\n\n\t#updateComponentState() {\n\t\tconst isComplete = this.#currentAmount >= this.#minAmount;\n\n\t\tif (isComplete) {\n\t\t\tthis.setAttribute('data-complete', 'true');\n\t\t\tthis.removeAttribute('data-incomplete');\n\t\t} else {\n\t\t\tthis.setAttribute('data-incomplete', 'true');\n\t\t\tthis.removeAttribute('data-complete');\n\t\t}\n\n\t\t// Set progress level classes for styling\n\t\tthis.classList.remove('progress-low', 'progress-medium', 'progress-high', 'progress-complete');\n\n\t\tif (isComplete) {\n\t\t\tthis.classList.add('progress-complete');\n\t\t} else if (this.#progressPercent >= 75) {\n\t\t\tthis.classList.add('progress-high');\n\t\t} else if (this.#progressPercent >= 50) {\n\t\t\tthis.classList.add('progress-medium');\n\t\t} else {\n\t\t\tthis.classList.add('progress-low');\n\t\t}\n\t}\n\n\t#formatCurrency(amount) {\n\t\t// Basic currency formatting - could be enhanced with locale/currency options\n\t\treturn new Intl.NumberFormat('en-US', {\n\t\t\tstyle: 'currency',\n\t\t\tcurrency: 'USD',\n\t\t\tminimumFractionDigits: 2,\n\t\t\tmaximumFractionDigits: 2,\n\t\t}).format(amount);\n\t}\n\n\t/**\n\t * Public API: Set the progress percentage directly\n\t * @param {number} percent - Progress percentage (0-100)\n\t */\n\tsetPercent(percent) {\n\t\tconst clampedPercent = Math.max(0, Math.min(100, percent));\n\t\tthis.#progressPercent = clampedPercent;\n\n\t\tif (this.#progressBar) {\n\t\t\tthis.#progressBar.setPercent(clampedPercent);\n\t\t}\n\n\t\t// Calculate current amount based on percentage\n\t\tthis.#currentAmount = (clampedPercent / 100) * this.#minAmount;\n\t\tthis.setAttribute('current', this.#currentAmount.toString());\n\n\t\tthis.#updateMessages();\n\t\tthis.#updateComponentState();\n\t}\n\n\t/**\n\t * Public API: Set the current cart amount\n\t * @param {number} amount - Current cart amount\n\t */\n\tsetCurrentAmount(amount) {\n\t\tthis.#currentAmount = parseFloat(amount) || 0;\n\t\tthis.setAttribute('current', this.#currentAmount.toString());\n\t\tthis.#updateProgress();\n\t}\n\n\t/**\n\t * Public API: Set the threshold amount for free shipping\n\t * @param {number} amount - Threshold amount for free shipping\n\t */\n\tsetThresholdAmount(amount) {\n\t\tthis.#minAmount = parseFloat(amount) || 0;\n\t\tthis.setAttribute('threshold', this.#minAmount.toString());\n\t\tthis.#updateProgress();\n\t}\n\n\t/**\n\t * Public API: Set the minimum amount for free shipping (deprecated - use setThresholdAmount)\n\t * @param {number} amount - Minimum amount threshold\n\t * @deprecated Use setThresholdAmount instead\n\t */\n\tsetMinAmount(amount) {\n\t\tthis.setThresholdAmount(amount);\n\t}\n\n\t/**\n\t * Public API: Get current progress information\n\t */\n\tgetProgress() {\n\t\treturn {\n\t\t\tcurrentAmount: this.#currentAmount,\n\t\t\tthresholdAmount: this.#minAmount,\n\t\t\tminAmount: this.#minAmount, // backwards compatibility\n\t\t\tremainingAmount: Math.max(0, this.#minAmount - this.#currentAmount),\n\t\t\tpercent: this.#progressPercent,\n\t\t\tisComplete: this.#currentAmount >= this.#minAmount,\n\t\t};\n\t}\n\n\t/**\n\t * Public API: Update message templates\n\t * @param {string} aboveMessage - Message template for above the bar\n\t * @param {string} belowMessage - Message template for below the bar\n\t */\n\tsetMessages(aboveMessage = null, belowMessage = null) {\n\t\tif (aboveMessage !== null) {\n\t\t\tthis.#originalAboveMessage = aboveMessage;\n\t\t\tthis.setAttribute('message-above', aboveMessage);\n\t\t}\n\n\t\tif (belowMessage !== null) {\n\t\t\tthis.#originalBelowMessage = belowMessage;\n\t\t\tthis.setAttribute('message-below', belowMessage);\n\t\t}\n\n\t\tthis.#updateMessages();\n\t}\n\n\t// Getters\n\tget currentAmount() {\n\t\treturn this.#currentAmount;\n\t}\n\tget thresholdAmount() {\n\t\treturn this.#minAmount;\n\t}\n\tget minAmount() {\n\t\treturn this.#minAmount;\n\t} // backwards compatibility\n\tget percent() {\n\t\treturn this.#progressPercent;\n\t}\n\tget isComplete() {\n\t\treturn this.#currentAmount >= this.#minAmount;\n\t}\n}\n\n// Define CartProgressBar custom element\ncustomElements.define('cart-progress-bar', CartProgressBar);\n\n// Export components for external use\nexport { CartProgressBar, ProgressBar };\n"],"names":[],"mappings":";;;;;;CAEA;CACA;CACA;CACA,MAAM,WAAW,SAAS,WAAW,CAAC;CACtC,CAAC,WAAW,GAAG;CACf,EAAE,KAAK,EAAE,CAAC;CACV,EAAE,IAAI,CAAC,iBAAiB,EAAE,CAAC;CAC3B,EAAE;AACF;CACA,CAAC,iBAAiB,GAAG;CACrB,EAAE,IAAI,CAAC,YAAY,CAAC,MAAM,EAAE,aAAa,CAAC,CAAC;CAC3C,EAAE,IAAI,CAAC,YAAY,CAAC,eAAe,EAAE,GAAG,CAAC,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,GAAG,IAAI,CAAC,qBAAqB,GAAG,YAAY,CAAC;CAC7C,GAAG,IAAI,CAAC,YAAY,CAAC,eAAe,EAAE,YAAY,CAAC,CAAC;CACpD,GAAG;AACH;CACA,EAAE,IAAI,CAAC,eAAe,EAAE,CAAC;CACzB,EAAE;AACF;CACA;CACA,CAAC,IAAI,aAAa,GAAG;CACrB,EAAE,OAAO,IAAI,CAAC,cAAc,CAAC;CAC7B,EAAE;CACF,CAAC,IAAI,eAAe,GAAG;CACvB,EAAE,OAAO,IAAI,CAAC,UAAU,CAAC;CACzB,EAAE;CACF,CAAC,IAAI,SAAS,GAAG;CACjB,EAAE,OAAO,IAAI,CAAC,UAAU,CAAC;CACzB,EAAE;CACF,CAAC,IAAI,OAAO,GAAG;CACf,EAAE,OAAO,IAAI,CAAC,gBAAgB,CAAC;CAC/B,EAAE;CACF,CAAC,IAAI,UAAU,GAAG;CAClB,EAAE,OAAO,IAAI,CAAC,cAAc,IAAI,IAAI,CAAC,UAAU,CAAC;CAChD,EAAE;CACF,CAAC;AACD;CACA;CACA,cAAc,CAAC,MAAM,CAAC,mBAAmB,EAAE,eAAe,CAAC;;;;;;;;;"}
@@ -0,0 +1 @@
1
+ cart-progress-bar{--cart-progress-bar-height:12px;--cart-progress-bar-border-radius:6px;--cart-progress-bar-bg:#e9ecef;--cart-progress-bar-fill-bg:#28a745;--cart-progress-bar-complete-bg:#007bff;--cart-progress-bar-shadow:inset 0 1px 2px rgba(0,0,0,.1);--cart-progress-bar-transition-duration:0.3s;--cart-progress-message-font-size:0.875rem;--cart-progress-message-line-height:1.4;--cart-progress-message-color:#495057;--cart-progress-message-complete-color:#155724;--cart-progress-message-margin:0.5rem;--cart-progress-percent:0%;display:block;max-width:100%;width:100%}cart-progress-bar p[data-content-cart-progress-message]{color:var(--cart-progress-message-color);font-size:var(--cart-progress-message-font-size);line-height:var(--cart-progress-message-line-height);margin:var(--cart-progress-message-margin) 0;text-align:center;transition:color var(--cart-progress-bar-transition-duration) ease}@media (max-width:768px){cart-progress-bar p[data-content-cart-progress-message]{font-size:calc(var(--cart-progress-message-font-size)*.9);margin:calc(var(--cart-progress-message-margin)*.75) 0}}cart-progress-bar[data-complete=true] p[data-content-cart-progress-message]{color:var(--cart-progress-message-complete-color);font-weight:600}cart-progress-bar.progress-low{--cart-progress-bar-fill-bg:#dc3545}cart-progress-bar.progress-medium{--cart-progress-bar-fill-bg:#ffc107}cart-progress-bar.progress-high{--cart-progress-bar-fill-bg:#fd7e14}cart-progress-bar.progress-complete{--cart-progress-bar-fill-bg:var(--cart-progress-bar-complete-bg)}cart-progress-bar.progress-complete p[data-content-cart-progress-message]{color:var(--cart-progress-message-complete-color)}progress-bar{background-color:var(--cart-progress-bar-bg);box-shadow:var(--cart-progress-bar-shadow);display:block;height:var(--cart-progress-bar-height);overflow:hidden;width:100%}progress-bar,progress-bar .progress-bar-fill{border-radius:var(--cart-progress-bar-border-radius);position:relative}progress-bar .progress-bar-fill{background-color:var(--cart-progress-bar-fill-bg);background-image:linear-gradient(45deg,hsla(0,0%,100%,.1) 25%,transparent 0,transparent 50%,hsla(0,0%,100%,.1) 0,hsla(0,0%,100%,.1) 75%,transparent 0,transparent);background-size:12px 12px;height:100%;transition:width var(--cart-progress-bar-transition-duration) ease,background-color var(--cart-progress-bar-transition-duration) ease;width:var(--cart-progress-percent)}progress-bar .progress-bar-fill:after{background:linear-gradient(90deg,transparent,hsla(0,0%,100%,.4),transparent);content:"";height:100%;left:-100%;position:absolute;top:0;transition:left .5s ease;width:100%}cart-progress-bar.progress-complete progress-bar .progress-bar-fill:after,cart-progress-bar[data-complete=true] progress-bar .progress-bar-fill:after{left:100%}progress-bar:focus-visible{outline:2px solid #007bff;outline-offset:2px}@media (prefers-contrast:high){progress-bar{--cart-progress-bar-bg:#000;--cart-progress-bar-fill-bg:#fff;border:1px solid #fff}}@media (prefers-reduced-motion:reduce){progress-bar .progress-bar-fill,progress-bar .progress-bar-fill:after{transition:none}}@media (max-width:768px){cart-progress-bar{--cart-progress-bar-height:10px;--cart-progress-message-margin:0.375rem}}@media (prefers-color-scheme:dark){cart-progress-bar{--cart-progress-bar-bg:#343a40;--cart-progress-message-color:#e9ecef;--cart-progress-message-complete-color:#28a745}}@media print{cart-progress-bar .above-message,cart-progress-bar .below-message{color:#000!important}cart-progress-bar progress-bar{border:1px solid #000}cart-progress-bar progress-bar .progress-bar-fill{background-color:#000!important;background-image:none!important}}
@@ -0,0 +1 @@
1
+ !function(e,t){"object"==typeof exports&&"undefined"!=typeof module?t(exports):"function"==typeof define&&define.amd?define(["exports"],t):t((e="undefined"!=typeof globalThis?globalThis:e||self).CartProgressBar={})}(this,function(e){"use strict";class ProgressBar extends HTMLElement{constructor(){super(),this.#e()}#e(){this.setAttribute("role","progressbar"),this.setAttribute("aria-valuemin","0"),this.setAttribute("aria-valuemax","100"),this.setAttribute("aria-valuenow","0"),this.innerHTML='<div class="progress-bar-fill"></div>'}setPercent(e){const t=Math.max(0,Math.min(100,e));this.style.setProperty("--cart-progress-percent",`${t}%`),this.setAttribute("aria-valuenow",t)}}customElements.define("progress-bar",ProgressBar);class CartProgressBar extends HTMLElement{#t=0;#s=0;#r=0;#i="";#n="";#a=null;#o=null;static get observedAttributes(){return["threshold","current","message-above","message-below"]}constructor(){super(),this.#h()}#h(){this.#t=parseFloat(this.getAttribute("threshold"))||0,this.#s=parseFloat(this.getAttribute("current"))||0,this.#i=this.getAttribute("message-above")||"",this.#n=this.getAttribute("message-below")||""}async connectedCallback(){if(await customElements.whenDefined("progress-bar"),!customElements.get("progress-bar"))throw new Error("<progress-bar> must be registered before <cart-progress-bar> runs");this.#u(),this.#m(),this.#g()}attributeChangedCallback(e,t,s){if(t!==s)switch(e){case"threshold":this.#t=parseFloat(s)||0,this.#m();break;case"current":this.#s=parseFloat(s)||0,this.#m();break;case"message-above":this.#i=s||"",this.#l();break;case"message-below":this.#n=s||"",this.#l()}}#u(){this.#o=this.querySelector("[data-content-cart-progress-message]")||this.querySelector("p[data-content-cart-progress-message]"),this.#a=this.querySelector("progress-bar"),this.#o||!this.#i&&!this.#n||(this.#o=document.createElement("p"),this.#o.setAttribute("data-content-cart-progress-message",""),this.appendChild(this.#o)),this.#a||(customElements.get("progress-bar")?(this.#a=document.createElement("progress-bar"),this.appendChild(this.#a)):customElements.whenDefined("progress-bar").then(()=>{this.#a||(this.#a=document.createElement("progress-bar"),this.appendChild(this.#a),this.#m())}))}#m(){0===this.#t?this.#r=100:this.#r=Math.min(100,this.#s/this.#t*100),this.#a&&this.#a.setPercent(this.#r),this.#l(),this.#c()}#g(){const e=this.closest("cart-panel");e&&e.addEventListener("cart-dialog:data-changed",e=>{this.#p(e)})}#p(e){const t=e.detail;if(t&&void 0!==t.total_price){const e=t.total_price/100;this.setCurrentAmount(e)}}#l(){const e=this.#s>=this.#t,t=Math.max(0,this.#t-this.#s),s=this.#d(t);if(this.#o){let t;if(e&&this.#i?t=this.#i:e||(t=this.#n||this.#i),t){const e=t.replace(/\$\{left\}/g,s);this.#o.textContent=e,this.#o.style.display="block"}else this.#o.style.display="none"}}#c(){const e=this.#s>=this.#t;e?(this.setAttribute("data-complete","true"),this.removeAttribute("data-incomplete")):(this.setAttribute("data-incomplete","true"),this.removeAttribute("data-complete")),this.classList.remove("progress-low","progress-medium","progress-high","progress-complete"),e?this.classList.add("progress-complete"):this.#r>=75?this.classList.add("progress-high"):this.#r>=50?this.classList.add("progress-medium"):this.classList.add("progress-low")}#d(e){return new Intl.NumberFormat("en-US",{style:"currency",currency:"USD",minimumFractionDigits:2,maximumFractionDigits:2}).format(e)}setPercent(e){const t=Math.max(0,Math.min(100,e));this.#r=t,this.#a&&this.#a.setPercent(t),this.#s=t/100*this.#t,this.setAttribute("current",this.#s.toString()),this.#l(),this.#c()}setCurrentAmount(e){this.#s=parseFloat(e)||0,this.setAttribute("current",this.#s.toString()),this.#m()}setThresholdAmount(e){this.#t=parseFloat(e)||0,this.setAttribute("threshold",this.#t.toString()),this.#m()}setMinAmount(e){this.setThresholdAmount(e)}getProgress(){return{currentAmount:this.#s,thresholdAmount:this.#t,minAmount:this.#t,remainingAmount:Math.max(0,this.#t-this.#s),percent:this.#r,isComplete:this.#s>=this.#t}}setMessages(e=null,t=null){null!==e&&(this.#i=e,this.setAttribute("message-above",e)),null!==t&&(this.#n=t,this.setAttribute("message-below",t)),this.#l()}get currentAmount(){return this.#s}get thresholdAmount(){return this.#t}get minAmount(){return this.#t}get percent(){return this.#r}get isComplete(){return this.#s>=this.#t}}customElements.define("cart-progress-bar",CartProgressBar),e.CartProgressBar=CartProgressBar,e.ProgressBar=ProgressBar});
@@ -0,0 +1,202 @@
1
+ // SCSS Variables (can be overridden before import)
2
+ $cart-progress-bar-height: 12px !default;
3
+ $cart-progress-bar-border-radius: 6px !default;
4
+ $cart-progress-bar-bg: #e9ecef !default;
5
+ $cart-progress-bar-fill-bg: #28a745 !default;
6
+ $cart-progress-bar-complete-bg: #007bff !default;
7
+ $cart-progress-bar-shadow: inset 0 1px 2px rgba(0, 0, 0, 0.1) !default;
8
+ $cart-progress-bar-transition-duration: 0.3s !default;
9
+
10
+ // Message styling
11
+ $cart-progress-message-font-size: 0.875rem !default;
12
+ $cart-progress-message-line-height: 1.4 !default;
13
+ $cart-progress-message-color: #495057 !default;
14
+ $cart-progress-message-complete-color: #155724 !default;
15
+ $cart-progress-message-margin: 0.5rem !default;
16
+
17
+ // Responsive breakpoints
18
+ $cart-progress-mobile-breakpoint: 768px !default;
19
+
20
+ // Cart progress bar component styles
21
+ cart-progress-bar {
22
+ // CSS Custom Properties for customization (mapped from SCSS variables)
23
+ --cart-progress-bar-height: #{$cart-progress-bar-height};
24
+ --cart-progress-bar-border-radius: #{$cart-progress-bar-border-radius};
25
+ --cart-progress-bar-bg: #{$cart-progress-bar-bg};
26
+ --cart-progress-bar-fill-bg: #{$cart-progress-bar-fill-bg};
27
+ --cart-progress-bar-complete-bg: #{$cart-progress-bar-complete-bg};
28
+ --cart-progress-bar-shadow: #{$cart-progress-bar-shadow};
29
+ --cart-progress-bar-transition-duration: #{$cart-progress-bar-transition-duration};
30
+ --cart-progress-message-font-size: #{$cart-progress-message-font-size};
31
+ --cart-progress-message-line-height: #{$cart-progress-message-line-height};
32
+ --cart-progress-message-color: #{$cart-progress-message-color};
33
+ --cart-progress-message-complete-color: #{$cart-progress-message-complete-color};
34
+ --cart-progress-message-margin: #{$cart-progress-message-margin};
35
+
36
+ // Dynamic progress percentage (set by JavaScript)
37
+ --cart-progress-percent: 0%;
38
+
39
+ display: block;
40
+ width: 100%;
41
+ max-width: 100%;
42
+
43
+ // Message styling
44
+ p[data-content-cart-progress-message] {
45
+ font-size: var(--cart-progress-message-font-size);
46
+ line-height: var(--cart-progress-message-line-height);
47
+ color: var(--cart-progress-message-color);
48
+ margin: var(--cart-progress-message-margin) 0;
49
+ text-align: center;
50
+ transition: color var(--cart-progress-bar-transition-duration) ease;
51
+
52
+ @media (max-width: $cart-progress-mobile-breakpoint) {
53
+ font-size: calc(var(--cart-progress-message-font-size) * 0.9);
54
+ margin: calc(var(--cart-progress-message-margin) * 0.75) 0;
55
+ }
56
+ }
57
+
58
+ // State-based styling
59
+ &[data-complete='true'] {
60
+ p[data-content-cart-progress-message] {
61
+ color: var(--cart-progress-message-complete-color);
62
+ font-weight: 600;
63
+ }
64
+ }
65
+
66
+ // Progress level classes for additional styling hooks
67
+ &.progress-low {
68
+ --cart-progress-bar-fill-bg: #dc3545; // red for low progress
69
+ }
70
+
71
+ &.progress-medium {
72
+ --cart-progress-bar-fill-bg: #ffc107; // yellow for medium progress
73
+ }
74
+
75
+ &.progress-high {
76
+ --cart-progress-bar-fill-bg: #fd7e14; // orange for high progress
77
+ }
78
+
79
+ &.progress-complete {
80
+ --cart-progress-bar-fill-bg: var(--cart-progress-bar-complete-bg);
81
+
82
+ p[data-content-cart-progress-message] {
83
+ color: var(--cart-progress-message-complete-color);
84
+ }
85
+ }
86
+ }
87
+
88
+ // Progress bar component styles
89
+ progress-bar {
90
+ display: block;
91
+ width: 100%;
92
+ height: var(--cart-progress-bar-height);
93
+ background-color: var(--cart-progress-bar-bg);
94
+ border-radius: var(--cart-progress-bar-border-radius);
95
+ box-shadow: var(--cart-progress-bar-shadow);
96
+ overflow: hidden;
97
+ position: relative;
98
+
99
+ .progress-bar-fill {
100
+ height: 100%;
101
+ width: var(--cart-progress-percent);
102
+ background-color: var(--cart-progress-bar-fill-bg);
103
+ border-radius: var(--cart-progress-bar-border-radius);
104
+ transition:
105
+ width var(--cart-progress-bar-transition-duration) ease,
106
+ background-color var(--cart-progress-bar-transition-duration) ease;
107
+ position: relative;
108
+
109
+ // Subtle gradient effect
110
+ background-image: linear-gradient(
111
+ 45deg,
112
+ rgba(255, 255, 255, 0.1) 25%,
113
+ transparent 25%,
114
+ transparent 50%,
115
+ rgba(255, 255, 255, 0.1) 50%,
116
+ rgba(255, 255, 255, 0.1) 75%,
117
+ transparent 75%,
118
+ transparent
119
+ );
120
+ background-size: 12px 12px;
121
+
122
+ // Shine effect for completed state
123
+ &::after {
124
+ content: '';
125
+ position: absolute;
126
+ top: 0;
127
+ left: -100%;
128
+ width: 100%;
129
+ height: 100%;
130
+ background: linear-gradient(90deg, transparent, rgba(255, 255, 255, 0.4), transparent);
131
+ transition: left 0.5s ease;
132
+ }
133
+ }
134
+
135
+ // Animate shine effect when complete
136
+ cart-progress-bar[data-complete='true'] &,
137
+ cart-progress-bar.progress-complete & {
138
+ .progress-bar-fill::after {
139
+ left: 100%;
140
+ }
141
+ }
142
+
143
+ // Accessibility improvements
144
+ &:focus-visible {
145
+ outline: 2px solid #007bff;
146
+ outline-offset: 2px;
147
+ }
148
+
149
+ // High contrast mode support
150
+ @media (prefers-contrast: high) {
151
+ --cart-progress-bar-bg: #000000;
152
+ --cart-progress-bar-fill-bg: #ffffff;
153
+ border: 1px solid #ffffff;
154
+ }
155
+
156
+ // Reduced motion support
157
+ @media (prefers-reduced-motion: reduce) {
158
+ .progress-bar-fill {
159
+ transition: none;
160
+ }
161
+
162
+ .progress-bar-fill::after {
163
+ transition: none;
164
+ }
165
+ }
166
+ }
167
+
168
+ // Responsive adjustments
169
+ @media (max-width: $cart-progress-mobile-breakpoint) {
170
+ cart-progress-bar {
171
+ --cart-progress-bar-height: 10px;
172
+ --cart-progress-message-margin: 0.375rem;
173
+ }
174
+ }
175
+
176
+ // Dark mode support
177
+ @media (prefers-color-scheme: dark) {
178
+ cart-progress-bar {
179
+ --cart-progress-bar-bg: #343a40;
180
+ --cart-progress-message-color: #e9ecef;
181
+ --cart-progress-message-complete-color: #28a745;
182
+ }
183
+ }
184
+
185
+ // Print styles
186
+ @media print {
187
+ cart-progress-bar {
188
+ .above-message,
189
+ .below-message {
190
+ color: #000000 !important;
191
+ }
192
+
193
+ progress-bar {
194
+ border: 1px solid #000000;
195
+
196
+ .progress-bar-fill {
197
+ background-color: #000000 !important;
198
+ background-image: none !important;
199
+ }
200
+ }
201
+ }
202
+ }