@lime-bundles/widget 0.2.0 → 2.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.cjs CHANGED
@@ -27,374 +27,2489 @@ module.exports = __toCommonJS(index_exports);
27
27
  // src/lime-bundle.ts
28
28
  var import_core4 = require("@lime-bundles/core");
29
29
 
30
- // src/renderers/fixed.ts
30
+ // src/renderers/pricing.ts
31
31
  var import_core = require("@lime-bundles/core");
32
- function renderFixedBundle(container, bundle, onAddToCart) {
32
+
33
+ // src/renderers/countdown.ts
34
+ var import_core2 = require("@lime-bundles/core");
35
+ function renderCountdown(endsAtIso) {
36
+ const parsed = parseIso(endsAtIso);
37
+ if (parsed === null) return null;
38
+ if (parsed <= Date.now()) return null;
39
+ const target = parsed;
40
+ const wrap = document.createElement("div");
41
+ wrap.className = "lb-bundle-countdown";
42
+ wrap.setAttribute("data-countdown", "");
43
+ const labelWrap = document.createElement("div");
44
+ labelWrap.className = "lb-bundle-countdown__label";
45
+ const labelText = document.createElement("span");
46
+ labelText.textContent = "Ends in";
47
+ labelWrap.appendChild(labelText);
48
+ wrap.appendChild(labelWrap);
49
+ const timer = document.createElement("span");
50
+ timer.className = "lb-bundle-countdown__timer";
51
+ timer.setAttribute("data-countdown-timer", "");
52
+ wrap.appendChild(timer);
53
+ let intervalId = null;
54
+ function tick() {
55
+ const msLeft = target - Date.now();
56
+ if (msLeft <= 0) {
57
+ wrap.style.display = "none";
58
+ stop();
59
+ return;
60
+ }
61
+ timer.textContent = (0, import_core2.formatCountdown)(msLeft);
62
+ }
63
+ function stop() {
64
+ if (intervalId !== null) {
65
+ clearInterval(intervalId);
66
+ intervalId = null;
67
+ }
68
+ }
69
+ tick();
70
+ intervalId = setInterval(tick, 1e3);
71
+ return { el: wrap, stop };
72
+ }
73
+ function parseIso(iso) {
74
+ const t = Date.parse(iso);
75
+ return Number.isFinite(t) ? t : null;
76
+ }
77
+
78
+ // src/renderers/dom.ts
79
+ function el(tag, className, attrs = {}) {
80
+ const node = document.createElement(tag);
81
+ if (className) node.className = className;
82
+ for (const [k, v] of Object.entries(attrs)) {
83
+ node.setAttribute(k, v);
84
+ }
85
+ return node;
86
+ }
87
+
88
+ // src/renderers/image.ts
89
+ var import_core3 = require("@lime-bundles/core");
90
+
91
+ // src/renderers/fixed.ts
92
+ var PLACEHOLDER_THUMB_SVG = `
93
+ <svg class="lb-bundle-placeholder-icon" viewBox="0 0 28 28" xmlns="http://www.w3.org/2000/svg" aria-hidden="true" focusable="false">
94
+ <rect x="4" y="4" width="20" height="20" rx="3"></rect>
95
+ <line x1="4" y1="20" x2="24" y2="20"></line>
96
+ <circle cx="10" cy="12" r="2"></circle>
97
+ </svg>`;
98
+ function renderFixedBundle(container, bundle, onAddToCart, onCleanup) {
99
+ const wc = bundle.widgetConfig;
100
+ const qtyFor = (productId, variantId) => {
101
+ const vq = bundle.variantQuantities[variantId];
102
+ if (vq !== void 0) return vq;
103
+ return bundle.productQuantities[productId] ?? 1;
104
+ };
105
+ const rows = [];
106
+ let oosCount = 0;
107
+ bundle.products.forEach((product, idx) => {
108
+ const row = buildRowState(bundle, product, idx);
109
+ if (row.qty === 0) return;
110
+ if (row.isOos) {
111
+ oosCount++;
112
+ if (wc.outOfStockBehavior === "hide") return;
113
+ }
114
+ rows.push(row);
115
+ });
116
+ if (rows.length === 0) return;
33
117
  const currency = bundle.products[0]?.priceRange.minVariantPrice.currencyCode ?? "USD";
34
- const title = document.createElement("h3");
35
- title.className = "lb-bundle__title";
118
+ const root = el("div", "lb-fixed", {
119
+ "data-discount-type": bundle.discountConfig.discountType,
120
+ "data-discount-value": String(bundle.discountConfig.discountValue)
121
+ });
122
+ const headerHandle = renderHeader(bundle, currency);
123
+ root.appendChild(headerHandle.el);
124
+ if (wc.countdown.showCountdown && bundle.endsAt) {
125
+ const countdown = renderCountdown(bundle.endsAt);
126
+ if (countdown) {
127
+ root.appendChild(countdown.el);
128
+ onCleanup?.(countdown.stop);
129
+ }
130
+ }
131
+ const list = el("div", "lb-fixed__products");
132
+ const rowHandles = [];
133
+ rows.forEach((rowState) => {
134
+ const handle = renderProductRow(rowState, currency, qtyFor, () => {
135
+ updatePricing();
136
+ });
137
+ rowHandles.push(handle);
138
+ list.appendChild(handle.el);
139
+ });
140
+ root.appendChild(list);
141
+ root.appendChild(el("div", "lb-bundle-divider"));
142
+ const pricingHandle = renderPricingRow(bundle);
143
+ root.appendChild(pricingHandle.el);
144
+ const savingsBarHandle = wc.savingsBar.visible ? renderSavingsBar() : null;
145
+ if (savingsBarHandle) root.appendChild(savingsBarHandle.el);
146
+ const cta = renderCta(bundle, oosCount, () => {
147
+ const lines = rows.filter((r) => r.selected).map((r) => ({
148
+ merchandiseId: r.selected.id,
149
+ quantity: r.qty,
150
+ attributes: [
151
+ { key: "_lime_bundle_gid", value: bundle.id },
152
+ { key: "_lime_bundle_type", value: bundle.bundleType }
153
+ ]
154
+ }));
155
+ if (lines.length === 0) return;
156
+ onAddToCart(lines);
157
+ });
158
+ root.appendChild(cta);
159
+ root.appendChild(
160
+ el("p", "lb-bundle-error", { "data-error": "", "aria-live": "polite" })
161
+ );
162
+ root.appendChild(
163
+ el("span", "lb-visually-hidden", {
164
+ "data-status": "",
165
+ "aria-live": "polite"
166
+ })
167
+ );
168
+ container.appendChild(root);
169
+ updatePricing();
170
+ function updatePricing() {
171
+ const totalCents = rows.reduce((sum, r) => {
172
+ if (!r.selected) return sum;
173
+ const unit = (0, import_core.parseCents)(r.selected.price.amount);
174
+ return sum + unit * r.qty;
175
+ }, 0);
176
+ const saleCents = computeSale(totalCents, bundle.discountConfig, rows);
177
+ const savingsCents = Math.max(0, totalCents - saleCents);
178
+ pricingHandle.update({ totalCents, saleCents, savingsCents, currency });
179
+ if (savingsBarHandle) {
180
+ savingsBarHandle.update({ savingsCents, currency });
181
+ }
182
+ headerHandle.refresh(
183
+ deriveHeaderBadge(bundle, totalCents, saleCents, currency)
184
+ );
185
+ }
186
+ }
187
+ function buildRowState(bundle, product, productIndex) {
188
+ const selectedVariantIds = bundle.selectedVariantIds?.[productIndex] ?? null;
189
+ const available = product.variants.nodes.filter(
190
+ (v) => v.availableForSale
191
+ );
192
+ const eligibleVariants = selectedVariantIds && selectedVariantIds.length > 0 ? available.filter((v) => selectedVariantIds.includes(v.id)) : available;
193
+ const isOos = eligibleVariants.length === 0;
194
+ const selected = eligibleVariants[0] ?? null;
195
+ const productQty = bundle.productQuantities[product.id] ?? 1;
196
+ const variantQty = selected ? bundle.variantQuantities[selected.id] : void 0;
197
+ const qty = variantQty ?? productQty;
198
+ return { product, eligibleVariants, selected, qty, isOos };
199
+ }
200
+ function renderHeader(bundle, currency) {
201
+ const wc = bundle.widgetConfig;
202
+ const header = el("div", "lb-bundle-header");
203
+ const content = el("div", "lb-bundle-header__content");
204
+ const title = el("h3", "lb-bundle-title");
36
205
  title.textContent = bundle.title;
37
- title.setAttribute("part", "title");
38
- container.appendChild(title);
39
- if (bundle.discountLabel) {
40
- const badge = document.createElement("span");
41
- badge.className = "lb-bundle__discount-badge";
42
- badge.textContent = bundle.discountLabel;
43
- container.appendChild(badge);
44
- }
45
- const productsDiv = document.createElement("div");
46
- productsDiv.className = "lb-bundle__products";
47
- for (const product of bundle.products) {
48
- const productEl = document.createElement("div");
49
- productEl.className = "lb-bundle__product";
50
- productEl.setAttribute("part", "product");
51
- if (product.featuredImage) {
52
- const img = document.createElement("img");
53
- img.src = product.featuredImage.url;
54
- img.alt = product.featuredImage.altText ?? product.title;
55
- img.className = "lb-bundle__product-image";
56
- img.loading = "lazy";
57
- productEl.appendChild(img);
58
- }
59
- const info = document.createElement("div");
60
- info.className = "lb-bundle__product-info";
61
- info.innerHTML = `
62
- <p class="lb-bundle__product-title">${escapeHtml(product.title)}</p>
63
- <p class="lb-bundle__product-price">${escapeHtml((0, import_core.formatMoney)(product.priceRange.minVariantPrice.amount, currency))}</p>
64
- `;
65
- productEl.appendChild(info);
66
- productsDiv.appendChild(productEl);
206
+ content.appendChild(title);
207
+ if (bundle.description) {
208
+ const subtitle = el("p", "lb-bundle-subtitle");
209
+ subtitle.textContent = bundle.description;
210
+ content.appendChild(subtitle);
67
211
  }
68
- container.appendChild(productsDiv);
212
+ header.appendChild(content);
213
+ const badgeEl = el("span", "lb-bundle-header__badge", {
214
+ "data-header-badge": ""
215
+ });
216
+ header.appendChild(badgeEl);
217
+ const initialPricing = (0, import_core.computeFixedPricing)(
218
+ bundle,
219
+ bundle.productQuantities,
220
+ wc.pricing.showSaveBadge
221
+ );
222
+ if (initialPricing.headerBadge) {
223
+ badgeEl.textContent = initialPricing.headerBadge;
224
+ } else {
225
+ badgeEl.style.display = "none";
226
+ }
227
+ void currency;
228
+ return {
229
+ el: header,
230
+ refresh(badgeText) {
231
+ if (!wc.pricing.showSaveBadge) {
232
+ badgeEl.style.display = "none";
233
+ return;
234
+ }
235
+ if (badgeText) {
236
+ badgeEl.textContent = badgeText;
237
+ badgeEl.style.display = "";
238
+ } else {
239
+ badgeEl.style.display = "none";
240
+ }
241
+ }
242
+ };
243
+ }
244
+ function deriveHeaderBadge(bundle, totalCents, saleCents, currency) {
245
+ if (!bundle.widgetConfig.pricing.showSaveBadge) return "";
246
+ const savings = totalCents - saleCents;
247
+ if (savings <= 0) return "";
248
+ const dc = bundle.discountConfig;
249
+ if (dc.discountType === "percentage" && dc.discountValue > 0) {
250
+ return `-${Math.round(dc.discountValue)}%`;
251
+ }
252
+ if (dc.discountType === "fixed_amount" && dc.discountValue > 0) {
253
+ return `-${(0, import_core.formatCents)(Math.round(dc.discountValue * 100), currency)}`;
254
+ }
255
+ return `-${(0, import_core.formatCents)(savings, currency)}`;
256
+ }
257
+ function renderProductRow(state, currency, qtyFor, onVariantChange) {
258
+ const rowEl = el(
259
+ "div",
260
+ state.isOos ? "lb-bundle-product-row lb-bundle-product-row--oos" : "lb-bundle-product-row",
261
+ {
262
+ "data-product-id": state.product.id.replace(/^.*\//, ""),
263
+ ...state.isOos ? { "aria-disabled": "true" } : {}
264
+ }
265
+ );
266
+ const thumb = el("div", "lb-bundle-thumbnail", { "data-thumbnail": "" });
267
+ if (state.product.featuredImage) {
268
+ const img = document.createElement("img");
269
+ img.src = (0, import_core3.transformImageUrl)(state.product.featuredImage.url, {
270
+ width: import_core3.THUMB_PX,
271
+ height: import_core3.THUMB_PX,
272
+ crop: "center"
273
+ });
274
+ img.alt = state.product.featuredImage.altText ?? state.product.title;
275
+ img.width = import_core3.THUMB_PX;
276
+ img.height = import_core3.THUMB_PX;
277
+ img.loading = "lazy";
278
+ thumb.appendChild(img);
279
+ } else {
280
+ thumb.insertAdjacentHTML("beforeend", PLACEHOLDER_THUMB_SVG);
281
+ }
282
+ let qtyBadgeRef = null;
283
+ if (!state.isOos) {
284
+ qtyBadgeRef = el("span", "lb-bundle-qty-badge", {
285
+ "data-qty-badge": ""
286
+ });
287
+ qtyBadgeRef.textContent = String(state.qty);
288
+ thumb.appendChild(qtyBadgeRef);
289
+ }
290
+ rowEl.appendChild(thumb);
291
+ const info = el("div", "lb-bundle-product-info");
292
+ const name = document.createElement("a");
293
+ name.className = "lb-bundle-product-name";
294
+ name.href = `/products/${state.product.handle}`;
295
+ name.textContent = state.product.title;
296
+ info.appendChild(name);
297
+ if (state.isOos) {
298
+ const oosLabel = el("span", "lb-bundle-oos-label");
299
+ oosLabel.textContent = "Out of stock";
300
+ info.appendChild(oosLabel);
301
+ } else if (state.selected) {
302
+ const prices = el("span", "lb-bundle-product-prices");
303
+ const compare = el("span", "lb-bundle-product-compare-price", {
304
+ "data-product-compare-price": ""
305
+ });
306
+ const priceEl = el("span", "lb-bundle-product-price", {
307
+ "data-product-price": ""
308
+ });
309
+ prices.appendChild(compare);
310
+ prices.appendChild(priceEl);
311
+ info.appendChild(prices);
312
+ const applyVariantToRow = (variant) => {
313
+ const unit = (0, import_core.parseCents)(variant.price.amount);
314
+ priceEl.textContent = (0, import_core.formatCents)(unit, currency);
315
+ if (variant.compareAtPrice) {
316
+ const cmp = (0, import_core.parseCents)(variant.compareAtPrice.amount);
317
+ if (cmp > unit) {
318
+ compare.textContent = (0, import_core.formatCents)(cmp, currency);
319
+ compare.removeAttribute("hidden");
320
+ } else {
321
+ compare.setAttribute("hidden", "");
322
+ }
323
+ } else {
324
+ compare.setAttribute("hidden", "");
325
+ }
326
+ };
327
+ applyVariantToRow(state.selected);
328
+ if (state.eligibleVariants.length > 1) {
329
+ const select = document.createElement("select");
330
+ select.className = "lb-bundle-variant-select";
331
+ select.setAttribute("data-variant-select", "");
332
+ select.setAttribute(
333
+ "aria-label",
334
+ `Select variant for ${state.product.title}`
335
+ );
336
+ state.eligibleVariants.forEach((variant) => {
337
+ const opt = document.createElement("option");
338
+ opt.value = variant.id;
339
+ opt.textContent = variant.title;
340
+ if (variant.id === state.selected?.id) opt.selected = true;
341
+ select.appendChild(opt);
342
+ });
343
+ select.addEventListener("change", () => {
344
+ const variant = state.eligibleVariants.find(
345
+ (v) => v.id === select.value
346
+ );
347
+ if (!variant) return;
348
+ state.selected = variant;
349
+ state.qty = qtyFor(state.product.id, variant.id);
350
+ if (qtyBadgeRef) qtyBadgeRef.textContent = String(state.qty);
351
+ applyVariantToRow(variant);
352
+ onVariantChange();
353
+ });
354
+ info.appendChild(select);
355
+ } else if (state.eligibleVariants.length === 1 && state.product.variants.nodes.length > 1) {
356
+ const badge = el("span", "lb-bundle-variant-badge");
357
+ badge.textContent = state.eligibleVariants[0].title;
358
+ info.appendChild(badge);
359
+ }
360
+ }
361
+ rowEl.appendChild(info);
362
+ return { el: rowEl, state };
363
+ }
364
+ function renderPricingRow(bundle) {
365
+ const row = el("div", "lb-bundle-pricing");
366
+ const label = el("span", "lb-bundle-pricing__label");
367
+ label.textContent = "Bundle price";
368
+ row.appendChild(label);
369
+ const prices = el("span", "lb-bundle-pricing__prices");
370
+ const compare = el("span", "lb-bundle-compare-price", {
371
+ "data-compare-price": ""
372
+ });
373
+ compare.style.display = "none";
374
+ prices.appendChild(compare);
375
+ const sale = el("span", "lb-bundle-sale-price", {
376
+ "data-sale-price": ""
377
+ });
378
+ prices.appendChild(sale);
379
+ row.appendChild(prices);
380
+ return {
381
+ el: row,
382
+ update({ totalCents, saleCents, savingsCents, currency }) {
383
+ sale.textContent = (0, import_core.formatCents)(saleCents, currency);
384
+ if (bundle.widgetConfig.pricing.showCompareAtPrice && savingsCents > 0) {
385
+ compare.textContent = (0, import_core.formatCents)(totalCents, currency);
386
+ compare.style.display = "";
387
+ } else {
388
+ compare.style.display = "none";
389
+ }
390
+ }
391
+ };
392
+ }
393
+ function renderSavingsBar() {
394
+ const bar = el("div", "lb-bundle-savings-bar", {
395
+ "data-savings-bar": ""
396
+ });
397
+ const label = document.createElement("span");
398
+ label.textContent = "You save";
399
+ bar.appendChild(label);
400
+ const amount = el("span", "", { "data-savings-amount": "" });
401
+ bar.appendChild(amount);
402
+ return {
403
+ el: bar,
404
+ update({ savingsCents, currency }) {
405
+ if (savingsCents <= 0) {
406
+ bar.style.display = "none";
407
+ return;
408
+ }
409
+ bar.style.display = "";
410
+ amount.textContent = (0, import_core.formatCents)(savingsCents, currency);
411
+ }
412
+ };
413
+ }
414
+ function renderCta(bundle, oosCount, onClick) {
69
415
  const button = document.createElement("button");
70
- button.className = "lb-bundle__cta";
71
- button.textContent = bundle.widgetConfig.ctaText ?? "Add Bundle to Cart";
72
- button.setAttribute("part", "button");
73
- button.addEventListener("click", () => {
74
- const lines = bundle.products.filter((p) => p.variants.nodes.some((v) => v.availableForSale)).map((p) => {
75
- const variant = p.variants.nodes.find((v) => v.availableForSale);
76
- return {
416
+ button.type = "button";
417
+ button.className = "lb-bundle-cta";
418
+ button.setAttribute("data-add-bundle", "");
419
+ if (oosCount > 0) {
420
+ button.disabled = true;
421
+ button.textContent = `${oosCount} item${oosCount === 1 ? "" : "s"} out of stock`;
422
+ } else {
423
+ button.textContent = bundle.widgetConfig.cta.ctaText || "Add to cart";
424
+ button.addEventListener("click", () => {
425
+ if (button.disabled) return;
426
+ onClick();
427
+ });
428
+ }
429
+ return button;
430
+ }
431
+ function computeSale(totalCents, discount, rows) {
432
+ if (discount.discountType === "percentage") {
433
+ let saleCents = 0;
434
+ for (const r of rows) {
435
+ if (!r.selected) continue;
436
+ const unit = (0, import_core.parseCents)(r.selected.price.amount);
437
+ const off = Math.floor(unit * discount.discountValue / 100);
438
+ const perUnit = Math.max(0, unit - off);
439
+ saleCents += perUnit * r.qty;
440
+ }
441
+ return saleCents;
442
+ }
443
+ return Math.max(0, totalCents - Math.round(discount.discountValue * 100));
444
+ }
445
+
446
+ // src/renderers/mix-match.ts
447
+ var PLACEHOLDER_THUMB_SVG2 = `
448
+ <svg class="lb-bundle-placeholder-icon" viewBox="0 0 28 28" xmlns="http://www.w3.org/2000/svg" aria-hidden="true" focusable="false">
449
+ <rect x="4" y="4" width="20" height="20" rx="3"></rect>
450
+ <line x1="4" y1="20" x2="24" y2="20"></line>
451
+ <circle cx="10" cy="12" r="2"></circle>
452
+ </svg>`;
453
+ var PLUS_ICON_SVG = `
454
+ <svg width="18" height="18" viewBox="0 0 18 18" fill="none" xmlns="http://www.w3.org/2000/svg" aria-hidden="true">
455
+ <line x1="9" y1="3" x2="9" y2="15" stroke="currentColor" stroke-width="2" stroke-linecap="round"/>
456
+ <line x1="3" y1="9" x2="15" y2="9" stroke="currentColor" stroke-width="2" stroke-linecap="round"/>
457
+ </svg>`;
458
+ var CLOSE_ICON_SVG = `
459
+ <svg width="20" height="20" viewBox="0 0 20 20" fill="none" xmlns="http://www.w3.org/2000/svg" aria-hidden="true">
460
+ <line x1="5" y1="5" x2="15" y2="15" stroke="currentColor" stroke-width="2" stroke-linecap="round"/>
461
+ <line x1="15" y1="5" x2="5" y2="15" stroke="currentColor" stroke-width="2" stroke-linecap="round"/>
462
+ </svg>`;
463
+ var SEARCH_CLEAR_ICON_SVG = `
464
+ <svg width="16" height="16" viewBox="0 0 20 20" fill="currentColor" xmlns="http://www.w3.org/2000/svg" aria-hidden="true">
465
+ <path d="M14.348 5.652a.5.5 0 0 0-.707 0L10 9.293 6.36 5.652a.5.5 0 1 0-.708.707L9.293 10l-3.641 3.641a.5.5 0 0 0 .708.707L10 10.707l3.641 3.641a.5.5 0 0 0 .707-.707L10.707 10l3.641-3.641a.5.5 0 0 0 0-.707z"/>
466
+ </svg>`;
467
+ function renderMixMatchBundle(container, bundle, onAddToCart, onCleanup) {
468
+ const wc = bundle.widgetConfig;
469
+ const currency = bundle.products[0]?.priceRange.minVariantPrice.currencyCode ?? "USD";
470
+ const requiredQty = bundle.minQuantity ?? 1;
471
+ const maxQty = bundle.maxQuantity ?? requiredQty;
472
+ const eligible = buildEligibleProducts(bundle, wc.outOfStockBehavior);
473
+ const inStockCount = eligible.filter((e) => !e.isOos).length;
474
+ if (inStockCount < requiredQty) return;
475
+ const selections = [];
476
+ const root = el("div", "lb-mix-match", {
477
+ "data-required-quantity": String(requiredQty),
478
+ "data-max-quantity": String(maxQty)
479
+ });
480
+ const header = renderHeader2(bundle);
481
+ root.appendChild(header);
482
+ if (wc.countdown.showCountdown && bundle.endsAt) {
483
+ const countdown = renderCountdown(bundle.endsAt);
484
+ if (countdown) {
485
+ root.appendChild(countdown.el);
486
+ onCleanup?.(countdown.stop);
487
+ }
488
+ }
489
+ const progress = renderProgress(requiredQty);
490
+ root.appendChild(progress.el);
491
+ const slotsContainer = el("div", "lb-mix-match__slots", {
492
+ "data-selection-slots": ""
493
+ });
494
+ root.appendChild(slotsContainer);
495
+ root.appendChild(el("div", "lb-bundle-divider"));
496
+ const pricingSection = renderPricingSection(wc.pricing.showCompareAtPrice);
497
+ root.appendChild(pricingSection.el);
498
+ const savingsBar = wc.savingsBar.visible ? renderSavingsBar2() : null;
499
+ if (savingsBar) root.appendChild(savingsBar.el);
500
+ const placeholder = el("div", "lb-mix-match__price-placeholder", {
501
+ "data-price-placeholder": ""
502
+ });
503
+ const placeholderText = el(
504
+ "span",
505
+ "lb-mix-match__price-placeholder-text"
506
+ );
507
+ placeholderText.textContent = `Select ${requiredQty} items to see price`;
508
+ placeholder.appendChild(placeholderText);
509
+ root.appendChild(placeholder);
510
+ const modal = renderModal(bundle, eligible, currency, {
511
+ showSearch: wc.showSearch,
512
+ onAdd: (product, variant) => addSelection(product, variant),
513
+ onRemove: (productId, variantId) => removeSelection(productId, variantId),
514
+ countFor: (productId, variantId) => selections.filter(
515
+ (s) => s.productId === productId && s.variantId === variantId
516
+ ).length,
517
+ isOverMax: () => selections.length >= maxQty
518
+ });
519
+ root.appendChild(modal.el);
520
+ const cta = document.createElement("button");
521
+ cta.type = "button";
522
+ cta.className = "lb-bundle-cta";
523
+ cta.setAttribute("data-add-bundle", "");
524
+ cta.disabled = true;
525
+ cta.textContent = `Select ${requiredQty} items to unlock`;
526
+ cta.addEventListener("click", () => {
527
+ if (cta.disabled) return;
528
+ const lines = selections.map((s) => ({
529
+ merchandiseId: s.variantId,
530
+ quantity: 1,
531
+ attributes: [
532
+ { key: "_lime_bundle_gid", value: bundle.id },
533
+ { key: "_lime_bundle_type", value: bundle.bundleType }
534
+ ]
535
+ }));
536
+ onAddToCart(lines);
537
+ });
538
+ root.appendChild(cta);
539
+ root.appendChild(
540
+ el("p", "lb-bundle-error", { "data-error": "", "aria-live": "polite" })
541
+ );
542
+ root.appendChild(
543
+ el("span", "lb-visually-hidden", {
544
+ "data-status": "",
545
+ "aria-live": "polite"
546
+ })
547
+ );
548
+ container.appendChild(root);
549
+ renderSlots();
550
+ function addSelection(product, variant) {
551
+ if (selections.length >= maxQty) return;
552
+ selections.push({
553
+ productId: product.id,
554
+ productTitle: product.title,
555
+ variantId: variant.id,
556
+ variantTitle: variant.title,
557
+ imageUrl: product.featuredImage?.url ?? null,
558
+ priceCents: (0, import_core.parseCents)(variant.price.amount),
559
+ compareCents: variant.compareAtPrice ? (0, import_core.parseCents)(variant.compareAtPrice.amount) : null
560
+ });
561
+ afterMutation();
562
+ }
563
+ function removeSelection(productId, variantId) {
564
+ const idx = selections.findIndex(
565
+ (s) => s.productId === productId && s.variantId === variantId
566
+ );
567
+ if (idx === -1) return;
568
+ selections.splice(idx, 1);
569
+ afterMutation();
570
+ }
571
+ function removeSlotAt(index) {
572
+ if (index < 0 || index >= selections.length) return;
573
+ selections.splice(index, 1);
574
+ afterMutation();
575
+ }
576
+ function afterMutation() {
577
+ renderSlots();
578
+ progress.update(selections.length);
579
+ pricingSection.update(selections, bundle, currency);
580
+ if (savingsBar) savingsBar.update(selections, bundle, currency);
581
+ placeholder.style.display = selections.length === 0 ? "" : "none";
582
+ modal.refreshCounts();
583
+ updateCta();
584
+ }
585
+ function renderSlots() {
586
+ slotsContainer.innerHTML = "";
587
+ const totalSlots = Math.max(requiredQty, selections.length);
588
+ for (let i = 0; i < totalSlots; i++) {
589
+ const selection = selections[i];
590
+ if (selection) {
591
+ slotsContainer.appendChild(
592
+ renderFilledSlot(selection, i, currency, () => removeSlotAt(i))
593
+ );
594
+ } else {
595
+ slotsContainer.appendChild(
596
+ renderEmptySlot(i, () => modal.open())
597
+ );
598
+ }
599
+ }
600
+ }
601
+ function updateCta() {
602
+ const count = selections.length;
603
+ if (count < requiredQty) {
604
+ cta.disabled = true;
605
+ cta.textContent = `Select ${requiredQty - count} more to unlock`;
606
+ } else {
607
+ cta.disabled = false;
608
+ cta.textContent = wc.cta.ctaText || "Add to cart";
609
+ }
610
+ }
611
+ }
612
+ function renderHeader2(bundle) {
613
+ const wc = bundle.widgetConfig;
614
+ const header = el("div", "lb-bundle-header");
615
+ const content = el("div", "lb-bundle-header__content");
616
+ const title = el("h3", "lb-bundle-title");
617
+ title.textContent = bundle.title;
618
+ content.appendChild(title);
619
+ header.appendChild(content);
620
+ if (wc.pricing.showSaveBadge) {
621
+ const { discountType, discountValue } = bundle.discountConfig;
622
+ let label = null;
623
+ if (discountType === "percentage" && discountValue > 0) {
624
+ label = `-${Math.round(discountValue)}%`;
625
+ } else if (discountType === "fixed_amount" && discountValue > 0) {
626
+ label = `-${(0, import_core.formatCents)(
627
+ Math.round(discountValue * 100),
628
+ bundle.products[0]?.priceRange.minVariantPrice.currencyCode ?? "USD"
629
+ )}`;
630
+ }
631
+ if (label) {
632
+ const badge = el("span", "lb-bundle-header__badge");
633
+ badge.textContent = label;
634
+ header.appendChild(badge);
635
+ }
636
+ }
637
+ return header;
638
+ }
639
+ function renderProgress(requiredQty) {
640
+ const wrap = el("div", "lb-mix-match__progress");
641
+ const labels = el("div", "lb-mix-match__progress-labels");
642
+ const count = el("span", "lb-mix-match__progress-count", {
643
+ "data-progress-count": ""
644
+ });
645
+ count.textContent = `0 of ${requiredQty} selected`;
646
+ labels.appendChild(count);
647
+ const remaining = el("span", "lb-mix-match__progress-remaining", {
648
+ "data-progress-remaining": ""
649
+ });
650
+ remaining.textContent = `${requiredQty} more to go`;
651
+ labels.appendChild(remaining);
652
+ wrap.appendChild(labels);
653
+ const track = el("div", "lb-mix-match__progress-track", {
654
+ role: "progressbar",
655
+ "aria-valuenow": "0",
656
+ "aria-valuemin": "0",
657
+ "aria-valuemax": String(requiredQty)
658
+ });
659
+ const fill = el("div", "lb-mix-match__progress-fill", {
660
+ "data-progress-fill": ""
661
+ });
662
+ fill.style.width = "0%";
663
+ track.appendChild(fill);
664
+ wrap.appendChild(track);
665
+ function update(selected) {
666
+ const pct = Math.min(100, selected / requiredQty * 100);
667
+ count.textContent = `${selected} of ${requiredQty} selected`;
668
+ if (selected >= requiredQty) {
669
+ remaining.textContent = "Complete";
670
+ } else {
671
+ remaining.textContent = `${requiredQty - selected} more to go`;
672
+ }
673
+ fill.style.width = `${pct}%`;
674
+ track.setAttribute("aria-valuenow", String(Math.min(selected, requiredQty)));
675
+ }
676
+ return { el: wrap, update };
677
+ }
678
+ function renderEmptySlot(index, onClick) {
679
+ const slot = el(
680
+ "div",
681
+ "lb-bundle-product-row lb-mix-match__slot lb-mix-match__slot--empty",
682
+ {
683
+ "data-slot": String(index + 1),
684
+ tabindex: "0",
685
+ role: "button",
686
+ "aria-label": "Add a product to the bundle"
687
+ }
688
+ );
689
+ const thumb = el("div", "lb-mix-match__empty-thumb");
690
+ thumb.innerHTML = PLUS_ICON_SVG;
691
+ slot.appendChild(thumb);
692
+ const text = el("span", "lb-mix-match__empty-text");
693
+ text.textContent = "Choose an item";
694
+ slot.appendChild(text);
695
+ slot.addEventListener("click", onClick);
696
+ slot.addEventListener("keydown", (e) => {
697
+ if (e.key === "Enter" || e.key === " ") {
698
+ e.preventDefault();
699
+ onClick();
700
+ }
701
+ });
702
+ return slot;
703
+ }
704
+ function renderFilledSlot(selection, index, currency, onRemove) {
705
+ const slot = el(
706
+ "div",
707
+ "lb-bundle-product-row lb-mix-match__slot lb-mix-match__slot--filled",
708
+ { "data-slot": String(index + 1) }
709
+ );
710
+ const thumb = el("div", "lb-bundle-thumbnail", { "data-thumbnail": "" });
711
+ if (selection.imageUrl) {
712
+ const img = document.createElement("img");
713
+ img.src = (0, import_core3.transformImageUrl)(selection.imageUrl, {
714
+ width: import_core3.THUMB_PX,
715
+ height: import_core3.THUMB_PX,
716
+ crop: "center"
717
+ });
718
+ img.alt = selection.productTitle;
719
+ img.width = import_core3.THUMB_PX;
720
+ img.height = import_core3.THUMB_PX;
721
+ img.loading = "lazy";
722
+ thumb.appendChild(img);
723
+ } else {
724
+ thumb.insertAdjacentHTML("beforeend", PLACEHOLDER_THUMB_SVG2);
725
+ }
726
+ slot.appendChild(thumb);
727
+ const info = el("div", "lb-mix-match__filled-info");
728
+ const title = el("span", "lb-mix-match__filled-title");
729
+ title.textContent = selection.productTitle;
730
+ info.appendChild(title);
731
+ if (selection.variantTitle && selection.variantTitle !== "Default Title") {
732
+ const variant = el("span", "lb-mix-match__filled-variant");
733
+ variant.textContent = selection.variantTitle;
734
+ info.appendChild(variant);
735
+ }
736
+ const priceWrap = el("span", "lb-mix-match__filled-price");
737
+ if (selection.compareCents && selection.compareCents > selection.priceCents) {
738
+ const compare = el("span", "lb-mix-match__filled-compare");
739
+ compare.textContent = (0, import_core.formatCents)(selection.compareCents, currency);
740
+ priceWrap.appendChild(compare);
741
+ }
742
+ const priceEl = document.createElement("span");
743
+ priceEl.textContent = (0, import_core.formatCents)(selection.priceCents, currency);
744
+ priceWrap.appendChild(priceEl);
745
+ info.appendChild(priceWrap);
746
+ slot.appendChild(info);
747
+ const remove = document.createElement("button");
748
+ remove.type = "button";
749
+ remove.className = "lb-mix-match__slot-remove";
750
+ remove.setAttribute("aria-label", `Remove ${selection.productTitle}`);
751
+ remove.innerHTML = CLOSE_ICON_SVG;
752
+ remove.addEventListener("click", (e) => {
753
+ e.stopPropagation();
754
+ onRemove();
755
+ });
756
+ slot.appendChild(remove);
757
+ return slot;
758
+ }
759
+ function renderPricingSection(showCompareAtPrice) {
760
+ const wrap = el("div", "lb-bundle-pricing", { "data-pricing-section": "" });
761
+ wrap.style.display = "none";
762
+ const label = el("span", "lb-bundle-pricing__label");
763
+ label.textContent = "Bundle price";
764
+ wrap.appendChild(label);
765
+ const prices = el("span", "lb-bundle-pricing__prices");
766
+ const compare = el("span", "lb-bundle-compare-price", {
767
+ "data-compare-price": ""
768
+ });
769
+ if (showCompareAtPrice) prices.appendChild(compare);
770
+ const sale = el("span", "lb-bundle-sale-price", { "data-sale-price": "" });
771
+ prices.appendChild(sale);
772
+ wrap.appendChild(prices);
773
+ function update(selections, bundle, currency) {
774
+ if (selections.length === 0) {
775
+ wrap.style.display = "none";
776
+ return;
777
+ }
778
+ wrap.style.display = "";
779
+ const totalCents = selections.reduce((s, sel) => s + sel.priceCents, 0);
780
+ const saleCents = (0, import_core.computeBundleSaleCents)(totalCents, bundle.discountConfig);
781
+ if (showCompareAtPrice && totalCents > saleCents) {
782
+ compare.textContent = (0, import_core.formatCents)(totalCents, currency);
783
+ compare.style.display = "";
784
+ } else {
785
+ compare.style.display = "none";
786
+ }
787
+ sale.textContent = (0, import_core.formatCents)(saleCents, currency);
788
+ }
789
+ return { el: wrap, update };
790
+ }
791
+ function renderSavingsBar2() {
792
+ const wrap = el("div", "lb-bundle-savings-bar", {
793
+ "data-savings-bar": ""
794
+ });
795
+ wrap.style.display = "none";
796
+ const labelEl = document.createElement("span");
797
+ labelEl.textContent = "You save";
798
+ wrap.appendChild(labelEl);
799
+ const amount = el("span", "", { "data-savings-amount": "" });
800
+ wrap.appendChild(amount);
801
+ function update(selections, bundle, currency) {
802
+ if (selections.length === 0) {
803
+ wrap.style.display = "none";
804
+ return;
805
+ }
806
+ const totalCents = selections.reduce((s, sel) => s + sel.priceCents, 0);
807
+ const saleCents = (0, import_core.computeBundleSaleCents)(totalCents, bundle.discountConfig);
808
+ const savings = Math.max(0, totalCents - saleCents);
809
+ if (savings <= 0) {
810
+ wrap.style.display = "none";
811
+ return;
812
+ }
813
+ wrap.style.display = "";
814
+ amount.textContent = (0, import_core.formatCents)(savings, currency);
815
+ }
816
+ return { el: wrap, update };
817
+ }
818
+ function renderModal(bundle, eligible, currency, handlers) {
819
+ const overlay = el("div", "lb-mix-match__modal-overlay", {
820
+ "data-modal-overlay": "",
821
+ "data-bundle-gid": bundle.id
822
+ });
823
+ overlay.style.display = "none";
824
+ const modal = el("div", "lb-mix-match__modal", {
825
+ role: "dialog",
826
+ "aria-modal": "true",
827
+ "aria-labelledby": `lb-modal-title-${sanitizeId(bundle.id)}`,
828
+ tabindex: "-1"
829
+ });
830
+ const modalHeader = el("div", "lb-mix-match__modal-header");
831
+ const modalTitle = el("h4", "lb-mix-match__modal-title", {
832
+ id: `lb-modal-title-${sanitizeId(bundle.id)}`
833
+ });
834
+ modalTitle.textContent = "Pick an item";
835
+ modalHeader.appendChild(modalTitle);
836
+ const closeBtn = document.createElement("button");
837
+ closeBtn.type = "button";
838
+ closeBtn.className = "lb-mix-match__modal-close";
839
+ closeBtn.setAttribute("data-modal-close", "");
840
+ closeBtn.setAttribute("aria-label", "Close");
841
+ closeBtn.innerHTML = CLOSE_ICON_SVG;
842
+ closeBtn.addEventListener("click", close);
843
+ modalHeader.appendChild(closeBtn);
844
+ modal.appendChild(modalHeader);
845
+ let searchInput = null;
846
+ let searchClearBtn = null;
847
+ if (handlers.showSearch) {
848
+ const searchWrap = el("div", "lb-mix-match__modal-search");
849
+ searchInput = document.createElement("input");
850
+ searchInput.type = "text";
851
+ searchInput.className = "lb-mix-match__modal-search-input";
852
+ searchInput.setAttribute("data-modal-search", "");
853
+ searchInput.setAttribute("role", "searchbox");
854
+ searchInput.setAttribute("aria-label", "Search products");
855
+ searchInput.setAttribute("placeholder", "Search products");
856
+ searchInput.autocomplete = "off";
857
+ searchInput.addEventListener("input", () => applySearch());
858
+ searchWrap.appendChild(searchInput);
859
+ searchClearBtn = document.createElement("button");
860
+ searchClearBtn.type = "button";
861
+ searchClearBtn.className = "lb-mix-match__modal-search-clear";
862
+ searchClearBtn.setAttribute("data-modal-search-clear", "");
863
+ searchClearBtn.setAttribute("aria-label", "Clear search");
864
+ searchClearBtn.style.display = "none";
865
+ searchClearBtn.innerHTML = SEARCH_CLEAR_ICON_SVG;
866
+ searchClearBtn.addEventListener("click", () => {
867
+ if (!searchInput) return;
868
+ searchInput.value = "";
869
+ applySearch();
870
+ searchInput.focus();
871
+ });
872
+ searchWrap.appendChild(searchClearBtn);
873
+ modal.appendChild(searchWrap);
874
+ }
875
+ const list = el("div", "lb-mix-match__modal-list", {
876
+ "data-modal-list": ""
877
+ });
878
+ modal.appendChild(list);
879
+ const empty = el("div", "lb-mix-match__modal-empty", {
880
+ "data-modal-empty": ""
881
+ });
882
+ empty.style.display = "none";
883
+ const emptyText = document.createElement("p");
884
+ emptyText.textContent = "No products match your search.";
885
+ empty.appendChild(emptyText);
886
+ modal.appendChild(empty);
887
+ const live = el("span", "lb-visually-hidden", {
888
+ "data-modal-live": "",
889
+ "aria-live": "polite"
890
+ });
891
+ modal.appendChild(live);
892
+ overlay.appendChild(modal);
893
+ let rowsBuilt = false;
894
+ const productRows = [];
895
+ function buildRows() {
896
+ if (rowsBuilt) return;
897
+ rowsBuilt = true;
898
+ list.innerHTML = "";
899
+ eligible.forEach((ep) => {
900
+ const variant = ep.firstAvailableVariant ?? ep.variants[0];
901
+ if (!variant) return;
902
+ const productEl = el(
903
+ "div",
904
+ ep.isOos ? "lb-mix-match__modal-product lb-mix-match__modal-product--sold-out" : "lb-mix-match__modal-product",
905
+ { "data-product-id": ep.product.id.replace(/^.*\//, "") }
906
+ );
907
+ const thumb = el("div", "lb-mix-match__modal-product-thumb");
908
+ if (ep.product.featuredImage) {
909
+ const img = document.createElement("img");
910
+ img.src = (0, import_core3.transformImageUrl)(ep.product.featuredImage.url, {
911
+ width: import_core3.THUMB_PX,
912
+ height: import_core3.THUMB_PX,
913
+ crop: "center"
914
+ });
915
+ img.alt = ep.product.featuredImage.altText ?? ep.product.title;
916
+ img.width = import_core3.THUMB_PX;
917
+ img.height = import_core3.THUMB_PX;
918
+ img.loading = "lazy";
919
+ thumb.appendChild(img);
920
+ } else {
921
+ thumb.insertAdjacentHTML("beforeend", PLACEHOLDER_THUMB_SVG2);
922
+ }
923
+ productEl.appendChild(thumb);
924
+ const info = el("div", "lb-mix-match__modal-product-info");
925
+ const title = el("span", "lb-mix-match__modal-product-title");
926
+ title.textContent = ep.product.title;
927
+ info.appendChild(title);
928
+ const price = el("span", "lb-mix-match__modal-product-price");
929
+ price.textContent = (0, import_core.formatCents)((0, import_core.parseCents)(variant.price.amount), currency);
930
+ info.appendChild(price);
931
+ if (ep.isOos) {
932
+ const soldOut = el("span", "lb-mix-match__modal-sold-out-label");
933
+ soldOut.textContent = "Sold out";
934
+ info.appendChild(soldOut);
935
+ }
936
+ productEl.appendChild(info);
937
+ if (!ep.isOos) {
938
+ const addBtn = document.createElement("button");
939
+ addBtn.type = "button";
940
+ addBtn.className = "lb-mix-match__modal-add";
941
+ addBtn.setAttribute("aria-label", `Add ${ep.product.title}`);
942
+ addBtn.innerHTML = PLUS_ICON_SVG;
943
+ const countBadge = el("span", "lb-bundle-qty-badge");
944
+ countBadge.style.display = "none";
945
+ addBtn.appendChild(countBadge);
946
+ addBtn.addEventListener("click", () => {
947
+ if (handlers.isOverMax()) return;
948
+ handlers.onAdd(ep.product, variant);
949
+ });
950
+ productEl.appendChild(addBtn);
951
+ const removeBtn = document.createElement("button");
952
+ removeBtn.type = "button";
953
+ removeBtn.className = "lb-mix-match__slot-remove";
954
+ removeBtn.setAttribute("aria-label", `Remove one ${ep.product.title}`);
955
+ removeBtn.style.display = "none";
956
+ removeBtn.innerHTML = CLOSE_ICON_SVG;
957
+ removeBtn.addEventListener("click", (e) => {
958
+ e.stopPropagation();
959
+ handlers.onRemove(ep.product.id, variant.id);
960
+ });
961
+ productEl.appendChild(removeBtn);
962
+ productRows.push({
963
+ el: productEl,
964
+ product: ep.product,
965
+ variant,
966
+ updateCount: () => {
967
+ const count = handlers.countFor(ep.product.id, variant.id);
968
+ if (count > 0) {
969
+ countBadge.textContent = String(count);
970
+ countBadge.style.display = "";
971
+ removeBtn.style.display = "";
972
+ } else {
973
+ countBadge.style.display = "none";
974
+ removeBtn.style.display = "none";
975
+ }
976
+ }
977
+ });
978
+ } else {
979
+ productRows.push({
980
+ el: productEl,
981
+ product: ep.product,
982
+ variant,
983
+ updateCount: () => {
984
+ }
985
+ });
986
+ }
987
+ list.appendChild(productEl);
988
+ });
989
+ refreshCounts();
990
+ }
991
+ function applySearch() {
992
+ if (!searchInput) return;
993
+ const query = searchInput.value.trim().toLowerCase();
994
+ if (searchClearBtn) {
995
+ searchClearBtn.style.display = query ? "" : "none";
996
+ }
997
+ let visibleCount = 0;
998
+ productRows.forEach((row) => {
999
+ const match = !query || row.product.title.toLowerCase().includes(query);
1000
+ row.el.style.display = match ? "" : "none";
1001
+ if (match) visibleCount++;
1002
+ });
1003
+ empty.style.display = visibleCount === 0 && query ? "" : "none";
1004
+ }
1005
+ let lastFocused = null;
1006
+ function onKeydown(e) {
1007
+ if (e.key === "Escape") {
1008
+ e.preventDefault();
1009
+ close();
1010
+ return;
1011
+ }
1012
+ if (e.key === "Tab") {
1013
+ trapFocus(e, modal);
1014
+ }
1015
+ }
1016
+ let isOpen = false;
1017
+ function open() {
1018
+ if (isOpen) return;
1019
+ if (handlers.isOverMax()) return;
1020
+ isOpen = true;
1021
+ buildRows();
1022
+ lastFocused = overlay.getRootNode().activeElement;
1023
+ overlay.style.display = "";
1024
+ overlay.classList.add("lb-mix-match__modal-overlay--open");
1025
+ modal.focus();
1026
+ document.addEventListener("keydown", onKeydown);
1027
+ overlay.addEventListener("click", onOverlayClick);
1028
+ }
1029
+ function close() {
1030
+ if (!isOpen) return;
1031
+ isOpen = false;
1032
+ overlay.classList.remove("lb-mix-match__modal-overlay--open");
1033
+ overlay.style.display = "none";
1034
+ document.removeEventListener("keydown", onKeydown);
1035
+ overlay.removeEventListener("click", onOverlayClick);
1036
+ if (lastFocused instanceof HTMLElement) {
1037
+ lastFocused.focus();
1038
+ }
1039
+ }
1040
+ function onOverlayClick(e) {
1041
+ if (e.target === overlay) close();
1042
+ }
1043
+ function refreshCounts() {
1044
+ productRows.forEach((r) => r.updateCount());
1045
+ }
1046
+ return { el: overlay, open, close, refreshCounts };
1047
+ }
1048
+ function buildEligibleProducts(bundle, oosBehavior) {
1049
+ const result = [];
1050
+ const seen = /* @__PURE__ */ new Set();
1051
+ for (const product of bundle.products) {
1052
+ if (seen.has(product.id)) continue;
1053
+ seen.add(product.id);
1054
+ const available = product.variants.nodes.filter((v) => v.availableForSale);
1055
+ const isOos = available.length === 0;
1056
+ if (isOos && oosBehavior === "hide") continue;
1057
+ result.push({
1058
+ product,
1059
+ variants: product.variants.nodes,
1060
+ firstAvailableVariant: available[0] ?? null,
1061
+ isOos
1062
+ });
1063
+ }
1064
+ return result;
1065
+ }
1066
+ function trapFocus(e, container) {
1067
+ const focusables = container.querySelectorAll(
1068
+ 'button, [href], input, select, textarea, [tabindex]:not([tabindex="-1"])'
1069
+ );
1070
+ if (focusables.length === 0) return;
1071
+ const first = focusables[0];
1072
+ const last = focusables[focusables.length - 1];
1073
+ const active = container.getRootNode().activeElement;
1074
+ if (e.shiftKey && active === first) {
1075
+ e.preventDefault();
1076
+ last.focus();
1077
+ } else if (!e.shiftKey && active === last) {
1078
+ e.preventDefault();
1079
+ first.focus();
1080
+ }
1081
+ }
1082
+ function sanitizeId(gid) {
1083
+ return gid.replace(/[^a-zA-Z0-9_-]/g, "-");
1084
+ }
1085
+
1086
+ // src/renderers/volume.ts
1087
+ function renderVolumeBundle(container, bundle, onAddToCart, onCleanup) {
1088
+ const wc = bundle.widgetConfig;
1089
+ const product = bundle.products[0];
1090
+ const variant = product?.variants.nodes.find((v) => v.availableForSale);
1091
+ if (!variant && wc.outOfStockBehavior === "hide") return;
1092
+ const basePriceCents = variant ? (0, import_core.parseCents)(variant.price.amount) : 0;
1093
+ const currency = variant?.price.currencyCode ?? "USD";
1094
+ const resolved = bundle.volumeTiers.map((tier, index) => {
1095
+ let perUnit;
1096
+ if (tier.discountType === "fixed_amount") {
1097
+ const amt = Math.round(tier.discountValue * 100);
1098
+ perUnit = Math.max(0, basePriceCents - amt);
1099
+ } else {
1100
+ const discount = Math.floor(
1101
+ basePriceCents * tier.discountValue / 100
1102
+ );
1103
+ perUnit = Math.max(0, basePriceCents - discount);
1104
+ }
1105
+ return {
1106
+ tier,
1107
+ index,
1108
+ qty: tier.minQuantity,
1109
+ pricePerUnitCents: perUnit,
1110
+ basePricePerUnitCents: basePriceCents
1111
+ };
1112
+ });
1113
+ const bestTierIndex = pickBestTierIndex(resolved);
1114
+ let selectedIndex = wc.defaultTier === "best_value" ? bestTierIndex : 0;
1115
+ if (typeof wc.defaultTier === "number") {
1116
+ selectedIndex = clamp(wc.defaultTier, 0, resolved.length - 1);
1117
+ }
1118
+ const popularIndex = wc.popularBadge.tierIndex !== void 0 ? clamp(wc.popularBadge.tierIndex, 0, resolved.length - 1) : bestTierIndex;
1119
+ const root = el("div", "lb-volume");
1120
+ root.appendChild(renderHeader3(bundle, resolved, selectedIndex, currency));
1121
+ if (wc.countdown.showCountdown && bundle.endsAt) {
1122
+ const countdown = renderCountdown(bundle.endsAt);
1123
+ if (countdown) {
1124
+ root.appendChild(countdown.el);
1125
+ onCleanup?.(countdown.stop);
1126
+ }
1127
+ }
1128
+ const tierGroup = el("div", "lb-volume__tiers", {
1129
+ role: "radiogroup",
1130
+ "aria-label": "Quantity tiers",
1131
+ "data-tier-group": ""
1132
+ });
1133
+ resolved.forEach((r) => {
1134
+ const tierEl = renderTierCard(
1135
+ r,
1136
+ r.index === selectedIndex,
1137
+ currency,
1138
+ wc.popularBadge.visible && r.index === popularIndex ? wc.popularBadge.text : null,
1139
+ wc.pricing.showComparePrice,
1140
+ wc.pricing.showPerUnitPrice
1141
+ );
1142
+ tierEl.addEventListener("click", () => selectTier(r.index));
1143
+ tierEl.addEventListener("keydown", (e) => {
1144
+ if (e.key === "Enter" || e.key === " ") {
1145
+ e.preventDefault();
1146
+ selectTier(r.index);
1147
+ return;
1148
+ }
1149
+ if (e.key === "ArrowDown" || e.key === "ArrowRight" || e.key === "ArrowUp" || e.key === "ArrowLeft") {
1150
+ e.preventDefault();
1151
+ const delta = e.key === "ArrowDown" || e.key === "ArrowRight" ? 1 : -1;
1152
+ const next = (r.index + delta + resolved.length) % resolved.length;
1153
+ selectTier(next);
1154
+ const target = tierGroup.children[next];
1155
+ target?.focus();
1156
+ }
1157
+ });
1158
+ tierGroup.appendChild(tierEl);
1159
+ });
1160
+ root.appendChild(tierGroup);
1161
+ root.appendChild(el("div", "lb-bundle-divider"));
1162
+ let pricingEl = renderPricingRow2(
1163
+ resolved,
1164
+ selectedIndex,
1165
+ currency,
1166
+ wc.pricing.showItemCount,
1167
+ wc.pricing.showCompareAtPrice
1168
+ );
1169
+ root.appendChild(pricingEl);
1170
+ let savingsBarEl = wc.savingsBar.visible ? renderSavingsBar3(resolved, selectedIndex, currency) : null;
1171
+ if (savingsBarEl) root.appendChild(savingsBarEl);
1172
+ const cta = renderCta2(bundle, () => {
1173
+ if (!variant) return;
1174
+ const r = resolved[selectedIndex];
1175
+ if (!r) return;
1176
+ onAddToCart([
1177
+ {
77
1178
  merchandiseId: variant.id,
78
- quantity: 1,
1179
+ quantity: r.qty,
79
1180
  attributes: [
80
1181
  { key: "_lime_bundle_gid", value: bundle.id },
81
1182
  { key: "_lime_bundle_type", value: bundle.bundleType }
82
1183
  ]
83
- };
1184
+ }
1185
+ ]);
1186
+ });
1187
+ root.appendChild(cta);
1188
+ root.appendChild(
1189
+ el("p", "lb-bundle-error", { "data-error": "", "aria-live": "polite" })
1190
+ );
1191
+ root.appendChild(
1192
+ el("span", "lb-visually-hidden", {
1193
+ "data-status": "",
1194
+ "aria-live": "polite"
1195
+ })
1196
+ );
1197
+ container.appendChild(root);
1198
+ function selectTier(idx) {
1199
+ if (idx === selectedIndex || idx < 0 || idx >= resolved.length) return;
1200
+ selectedIndex = idx;
1201
+ Array.from(tierGroup.children).forEach((card, i) => {
1202
+ card.setAttribute("aria-checked", String(i === idx));
1203
+ card.tabIndex = i === idx ? 0 : -1;
84
1204
  });
85
- if (lines.length === 0) return;
86
- onAddToCart(lines);
1205
+ const newPricing = renderPricingRow2(
1206
+ resolved,
1207
+ idx,
1208
+ currency,
1209
+ wc.pricing.showItemCount,
1210
+ wc.pricing.showCompareAtPrice
1211
+ );
1212
+ pricingEl.replaceWith(newPricing);
1213
+ pricingEl = newPricing;
1214
+ if (savingsBarEl) {
1215
+ const newBar = renderSavingsBar3(resolved, idx, currency);
1216
+ savingsBarEl.replaceWith(newBar);
1217
+ savingsBarEl = newBar;
1218
+ }
1219
+ const badgeEl = root.querySelector("[data-header-badge]");
1220
+ if (badgeEl) {
1221
+ const label = badgeFor(resolved[idx], currency);
1222
+ if (label) {
1223
+ badgeEl.textContent = label;
1224
+ badgeEl.style.display = "";
1225
+ } else {
1226
+ badgeEl.style.display = "none";
1227
+ }
1228
+ }
1229
+ }
1230
+ }
1231
+ function renderHeader3(bundle, resolved, selectedIndex, currency) {
1232
+ const wc = bundle.widgetConfig;
1233
+ const header = el("div", "lb-bundle-header");
1234
+ const content = el("div", "lb-bundle-header__content");
1235
+ const title = el("h3", "lb-bundle-title");
1236
+ title.textContent = bundle.title;
1237
+ content.appendChild(title);
1238
+ header.appendChild(content);
1239
+ if (wc.pricing.showSaveBadge) {
1240
+ const badge = badgeFor(resolved[selectedIndex], currency);
1241
+ if (badge) {
1242
+ const badgeEl = el("span", "lb-bundle-header__badge", {
1243
+ "data-header-badge": ""
1244
+ });
1245
+ badgeEl.textContent = badge;
1246
+ header.appendChild(badgeEl);
1247
+ }
1248
+ }
1249
+ return header;
1250
+ }
1251
+ function renderTierCard(r, isSelected, currency, popularLabel, showComparePrice, showPerUnitPrice) {
1252
+ const tier = el("div", "lb-volume__tier", {
1253
+ role: "radio",
1254
+ "aria-checked": String(isSelected),
1255
+ tabindex: isSelected ? "0" : "-1",
1256
+ "data-tier-index": String(r.index),
1257
+ "data-tier-qty": String(r.qty)
1258
+ });
1259
+ const radio = el("span", "lb-volume__radio");
1260
+ radio.appendChild(el("span", "lb-volume__radio-dot"));
1261
+ tier.appendChild(radio);
1262
+ const grid = el("span", "lb-volume__tier-grid");
1263
+ const label = el("span", "lb-volume__tier-label");
1264
+ label.textContent = `Buy ${r.qty}`;
1265
+ grid.appendChild(label);
1266
+ const price = el("span", "lb-volume__tier-price");
1267
+ if (showComparePrice && r.pricePerUnitCents < r.basePricePerUnitCents) {
1268
+ const compare = el("span", "lb-volume__tier-compare");
1269
+ compare.textContent = (0, import_core.formatCents)(r.basePricePerUnitCents, currency);
1270
+ price.appendChild(compare);
1271
+ }
1272
+ if (showPerUnitPrice) {
1273
+ const each = document.createElement("span");
1274
+ each.setAttribute("data-tier-price-each", "");
1275
+ each.textContent = (0, import_core.formatCents)(r.pricePerUnitCents, currency);
1276
+ price.appendChild(each);
1277
+ const unit = el("span", "lb-volume__tier-unit");
1278
+ unit.textContent = " each";
1279
+ price.appendChild(unit);
1280
+ }
1281
+ grid.appendChild(price);
1282
+ tier.appendChild(grid);
1283
+ const badge = el("span", "lb-volume__tier-badge");
1284
+ if (popularLabel) {
1285
+ badge.textContent = popularLabel;
1286
+ } else {
1287
+ badge.style.display = "none";
1288
+ }
1289
+ tier.appendChild(badge);
1290
+ return tier;
1291
+ }
1292
+ function renderPricingRow2(resolved, selectedIndex, currency, showItemCount, showCompareAtPrice) {
1293
+ const r = resolved[selectedIndex];
1294
+ const totalCents = r ? r.pricePerUnitCents * r.qty : 0;
1295
+ const undiscountedCents = r ? r.basePricePerUnitCents * r.qty : 0;
1296
+ const savings = Math.max(0, undiscountedCents - totalCents);
1297
+ const row = el("div", "lb-bundle-pricing");
1298
+ const label = el("span", "lb-bundle-pricing__label", {
1299
+ "data-total-label": ""
87
1300
  });
88
- container.appendChild(button);
1301
+ label.textContent = "Total";
1302
+ if (showItemCount && r) {
1303
+ const count = document.createElement("span");
1304
+ count.setAttribute("data-item-count", "");
1305
+ count.textContent = ` (${r.qty} item${r.qty === 1 ? "" : "s"})`;
1306
+ label.appendChild(count);
1307
+ }
1308
+ row.appendChild(label);
1309
+ const prices = el("span", "lb-bundle-pricing__prices");
1310
+ if (showCompareAtPrice && savings > 0) {
1311
+ const compare = el("span", "lb-bundle-compare-price", {
1312
+ "data-compare-price": ""
1313
+ });
1314
+ compare.textContent = (0, import_core.formatCents)(undiscountedCents, currency);
1315
+ prices.appendChild(compare);
1316
+ }
1317
+ const sale = el("span", "lb-bundle-sale-price", { "data-total-price": "" });
1318
+ sale.textContent = (0, import_core.formatCents)(totalCents, currency);
1319
+ prices.appendChild(sale);
1320
+ row.appendChild(prices);
1321
+ return row;
1322
+ }
1323
+ function renderSavingsBar3(resolved, selectedIndex, currency) {
1324
+ const r = resolved[selectedIndex];
1325
+ const totalCents = r ? r.pricePerUnitCents * r.qty : 0;
1326
+ const undiscountedCents = r ? r.basePricePerUnitCents * r.qty : 0;
1327
+ const savings = Math.max(0, undiscountedCents - totalCents);
1328
+ const bar = el("div", "lb-bundle-savings-bar", { "data-savings-bar": "" });
1329
+ if (savings <= 0) bar.style.display = "none";
1330
+ const labelEl = document.createElement("span");
1331
+ labelEl.textContent = "You save";
1332
+ bar.appendChild(labelEl);
1333
+ const amount = el("span", "", { "data-savings-amount": "" });
1334
+ amount.textContent = (0, import_core.formatCents)(savings, currency);
1335
+ bar.appendChild(amount);
1336
+ return bar;
1337
+ }
1338
+ function renderCta2(bundle, onClick) {
1339
+ const product = bundle.products[0];
1340
+ const isAvailable = product?.variants.nodes.some((v) => v.availableForSale);
1341
+ const button = document.createElement("button");
1342
+ button.type = "button";
1343
+ button.className = "lb-bundle-cta";
1344
+ button.setAttribute("data-add-bundle", "");
1345
+ if (!isAvailable) button.disabled = true;
1346
+ button.textContent = isAvailable ? bundle.widgetConfig.cta.ctaText || "Add to cart" : "Sold out";
1347
+ button.addEventListener("click", () => {
1348
+ if (button.disabled) return;
1349
+ onClick();
1350
+ });
1351
+ return button;
1352
+ }
1353
+ function badgeFor(resolved, currency) {
1354
+ if (!resolved) return null;
1355
+ const { tier } = resolved;
1356
+ if (tier.discountType === "fixed_amount" && tier.discountValue > 0) {
1357
+ return `-${(0, import_core.formatCents)(Math.round(tier.discountValue * 100), currency)}`;
1358
+ }
1359
+ if (tier.discountType === "percentage" && tier.discountValue > 0) {
1360
+ return `-${Math.round(tier.discountValue)}%`;
1361
+ }
1362
+ return null;
1363
+ }
1364
+ function pickBestTierIndex(resolved) {
1365
+ let bestSavings = 0;
1366
+ let bestIndex = 0;
1367
+ resolved.forEach((r, i) => {
1368
+ const savings = r.basePricePerUnitCents - r.pricePerUnitCents;
1369
+ if (savings > bestSavings) {
1370
+ bestSavings = savings;
1371
+ bestIndex = i;
1372
+ }
1373
+ });
1374
+ return bestIndex;
1375
+ }
1376
+ function clamp(n, min, max) {
1377
+ return Math.max(min, Math.min(max, n));
1378
+ }
1379
+
1380
+ // src/lime-bundle.ts
1381
+ var import_core5 = require("@lime-bundles/core");
1382
+
1383
+ // src/styles/bundle-css.ts
1384
+ var BUNDLE_BASE_CSS = `/* Lime Bundles \u2014 shared base styles for all bundle widget types */
1385
+
1386
+ .lb-bundle-widget.lb-bundle-widget,
1387
+ .lb-bundle-widget.lb-bundle-widget * {
1388
+ line-height: normal;
1389
+ }
1390
+
1391
+ .lb-bundle-widget {
1392
+ /* Internal CSS-only vars (not merchant-configurable). */
1393
+ --lb-text-muted: #666666;
1394
+ --lb-thumbnail-bg: #F0F0F0;
1395
+ --lb-widget-pad: 20px;
1396
+ --lb-progress-color: var(--lb-primary-color);
1397
+
1398
+ font-family: inherit;
1399
+ font-size: 16px;
1400
+ background: var(--lb-bg);
1401
+ border: var(--lb-border-width) solid var(--lb-border);
1402
+ border-radius: var(--lb-radius);
1403
+ padding: var(--lb-widget-pad) var(--lb-widget-pad) 20px;
1404
+ box-sizing: border-box;
1405
+ }
1406
+
1407
+ /* Countdown timer bar \u2014 sits below the gradient header */
1408
+ .lb-bundle-countdown {
1409
+ margin: 0 calc(-1 * var(--lb-widget-pad)) 20px;
1410
+ padding: 12px 20px;
1411
+ background: var(--lb-countdown-bg);
1412
+ border-top: 1px solid rgba(0, 0, 0, 0.06);
1413
+ display: flex;
1414
+ align-items: center;
1415
+ justify-content: space-between;
1416
+ }
1417
+
1418
+ .lb-bundle-countdown__label {
1419
+ display: flex;
1420
+ align-items: center;
1421
+ gap: 8px;
1422
+ }
1423
+
1424
+ .lb-bundle-countdown__label svg {
1425
+ width: 16px;
1426
+ height: 16px;
1427
+ flex-shrink: 0;
1428
+ color: var(--lb-countdown-text);
1429
+ }
1430
+
1431
+ .lb-bundle-countdown__label span {
1432
+ font-size: 12px;
1433
+ font-weight: 500;
1434
+ line-height: 1;
1435
+ color: var(--lb-countdown-text);
1436
+ }
1437
+
1438
+ .lb-bundle-countdown__timer {
1439
+ font-family: 'SF Mono', 'Roboto Mono', ui-monospace, monospace;
1440
+ font-size: 12px;
1441
+ font-weight: 600;
1442
+ line-height: 1;
1443
+ color: var(--lb-countdown-text);
1444
+ letter-spacing: 0.02em;
1445
+ }
1446
+
1447
+ /* Hide wrapper when the inner snippet rendered nothing (product OOS / unfulfillable) */
1448
+ .lb-bundle-widget:not(:has(.lb-fixed, .lb-mix-match, .lb-volume)) {
1449
+ display: none;
1450
+ }
1451
+
1452
+ /* Adjacent widget spacing \u2014 separates multiple bundles on the same product page */
1453
+ .lb-bundle-widget + .lb-bundle-widget {
1454
+ margin-top: 24px;
1455
+ padding-top: 24px;
1456
+ border-top: 1px solid var(--lb-border);
1457
+ }
1458
+
1459
+ /* Header \u2014 gradient banner with title + savings badge */
1460
+ .lb-bundle-header {
1461
+ margin: calc(-1 * var(--lb-widget-pad)) calc(-1 * var(--lb-widget-pad)) 20px;
1462
+ padding: 20px 20px;
1463
+ background: var(--lb-header-bg);
1464
+ /* Match the widget's inner border curve so there's no background gap at the top corners. */
1465
+ border-radius: max(0px, calc(var(--lb-radius) - var(--lb-border-width))) max(0px, calc(var(--lb-radius) - var(--lb-border-width))) 0 0;
1466
+ display: flex;
1467
+ align-items: center;
1468
+ justify-content: space-between;
1469
+ gap: 16px;
1470
+ }
1471
+
1472
+ /* When countdown follows header, remove header bottom margin */
1473
+ .lb-bundle-header:has(+ .lb-bundle-countdown) {
1474
+ margin-bottom: 0;
1475
+ }
1476
+
1477
+ .lb-bundle-header__content {
1478
+ flex: 1;
1479
+ min-width: 0;
1480
+ }
1481
+
1482
+ .lb-bundle-title {
1483
+ font-size: 20px;
1484
+ font-weight: 700;
1485
+ line-height: 28px;
1486
+ letter-spacing: -0.02em;
1487
+ color: var(--lb-text);
1488
+ margin: 0;
1489
+ }
1490
+
1491
+ .lb-bundle-header .lb-bundle-title {
1492
+ color: var(--lb-header-text);
1493
+ }
1494
+
1495
+ .lb-bundle-subtitle {
1496
+ font-size: 16px;
1497
+ font-weight: 400;
1498
+ line-height: 20px;
1499
+ color: var(--lb-text-muted);
1500
+ margin: 4px 0 0;
1501
+ }
1502
+
1503
+ .lb-bundle-header .lb-bundle-subtitle {
1504
+ color: var(--lb-header-text);
1505
+ opacity: 0.85;
1506
+ margin-top: 8px;
1507
+ }
1508
+
1509
+ .lb-bundle-header:has(.lb-bundle-subtitle) {
1510
+ align-items: flex-start;
1511
+ }
1512
+
1513
+ .lb-bundle-header__badge {
1514
+ background: var(--lb-save-badge-bg);
1515
+ color: var(--lb-save-badge-text);
1516
+ border: var(--lb-save-badge-border-width) solid var(--lb-save-badge-border-color);
1517
+ font-size: 16px;
1518
+ font-weight: 700;
1519
+ line-height: 1;
1520
+ padding: 4px 12px;
1521
+ border-radius: var(--lb-save-badge-radius);
1522
+ white-space: nowrap;
1523
+ flex-shrink: 0;
1524
+ }
1525
+
1526
+ /* Override Dawn's \`div:empty { display: none }\` reset for decorative elements */
1527
+ .lb-bundle-divider:empty,
1528
+ .lb-mix-match__progress-fill:empty {
1529
+ display: block;
1530
+ }
1531
+
1532
+ /* Divider */
1533
+ .lb-bundle-divider {
1534
+ height: 1px;
1535
+ background: color-mix(in srgb, var(--lb-text) 7%, transparent);
1536
+ margin: 16px 0;
1537
+ }
1538
+
1539
+ /* Product rows */
1540
+ .lb-bundle-product-row {
1541
+ display: flex;
1542
+ gap: 12px;
1543
+ padding: 12px 0;
1544
+ }
1545
+
1546
+ .lb-bundle-thumbnail {
1547
+ position: relative;
1548
+ width: 48px;
1549
+ height: 48px;
1550
+ min-width: 48px;
1551
+ background: var(--lb-thumbnail-bg);
1552
+ border-radius: 8px;
1553
+ overflow: hidden;
1554
+ display: flex;
1555
+ align-items: center;
1556
+ justify-content: center;
1557
+ }
1558
+
1559
+ .lb-bundle-thumbnail img {
1560
+ width: 100%;
1561
+ height: 100%;
1562
+ object-fit: cover;
1563
+ }
1564
+
1565
+ .lb-bundle-thumbnail svg {
1566
+ width: 28px;
1567
+ height: 28px;
1568
+ color: #BBBBBB;
1569
+ }
1570
+
1571
+ .lb-bundle-product-info {
1572
+ flex: 1;
1573
+ min-width: 0;
1574
+ }
1575
+
1576
+ .lb-bundle-product-name {
1577
+ font-size: 16px;
1578
+ font-weight: 700;
1579
+ line-height: 20px;
1580
+ color: var(--lb-text);
1581
+ margin: 0;
1582
+ text-decoration: none;
1583
+ display: block;
1584
+ }
1585
+
1586
+ .lb-bundle-product-name:hover {
1587
+ text-decoration: underline;
1588
+ }
1589
+
1590
+ .lb-bundle-product-price {
1591
+ /* --lb-product-price-display fallback is the "on" branch; Liquid sets 'none' when merchant disables. */
1592
+ display: var(--lb-product-price-display, block);
1593
+ font-size: 12px;
1594
+ font-weight: 400;
1595
+ line-height: 20px;
1596
+ color: var(--lb-text);
1597
+ }
1598
+
1599
+ .lb-bundle-product-prices {
1600
+ display: flex;
1601
+ align-items: baseline;
1602
+ gap: 6px;
1603
+ flex-wrap: wrap;
1604
+ margin-top: 2px;
1605
+ }
1606
+
1607
+ .lb-bundle-product-compare-price {
1608
+ /* --lb-product-compare-display fallback is the "on" branch; Liquid sets 'none' when merchant disables. */
1609
+ display: var(--lb-product-compare-display, inline);
1610
+ font-size: 12px;
1611
+ font-weight: 400;
1612
+ line-height: 20px;
1613
+ color: color-mix(in srgb, var(--lb-text) 60%, transparent);
1614
+ text-decoration: line-through;
1615
+ }
1616
+
1617
+ /* Setting \`display\` above outranks the UA [hidden] rule \u2014 restore it so rows
1618
+ without a compare-at price don't leave a phantom flex item + gap. */
1619
+ .lb-bundle-product-compare-price[hidden] {
1620
+ display: none;
1621
+ }
1622
+
1623
+ .lb-bundle-variant-badge {
1624
+ display: inline-block;
1625
+ border: var(--lb-variant-border-width) solid var(--lb-variant-border-color);
1626
+ border-radius: var(--lb-variant-radius);
1627
+ padding: 8px 12px;
1628
+ font-size: 12px;
1629
+ line-height: 16px;
1630
+ color: var(--lb-text-muted);
1631
+ margin-top: 8px;
1632
+ }
1633
+
1634
+ .lb-bundle-quantity {
1635
+ font-size: 12px;
1636
+ line-height: 16px;
1637
+ color: var(--lb-text-muted);
1638
+ margin-left: 8px;
1639
+ white-space: nowrap;
1640
+ }
1641
+
1642
+ /* Pricing row \u2014 label left, prices right */
1643
+ .lb-bundle-pricing {
1644
+ display: flex;
1645
+ align-items: baseline;
1646
+ justify-content: space-between;
1647
+ padding: 4px 0 8px;
1648
+ gap: 12px;
1649
+ }
1650
+
1651
+ .lb-bundle-pricing__label {
1652
+ font-size: 16px;
1653
+ font-weight: 400;
1654
+ line-height: 20px;
1655
+ color: var(--lb-text);
1656
+ white-space: nowrap;
1657
+ }
1658
+
1659
+ .lb-bundle-pricing__prices {
1660
+ display: flex;
1661
+ align-items: baseline;
1662
+ gap: 8px;
1663
+ }
1664
+
1665
+ .lb-bundle-sale-price {
1666
+ font-size: 20px;
1667
+ font-weight: 700;
1668
+ line-height: 1;
1669
+ letter-spacing: -0.02em;
1670
+ color: var(--lb-text);
1671
+ }
1672
+
1673
+ .lb-bundle-compare-price {
1674
+ font-size: 16px;
1675
+ font-weight: 400;
1676
+ line-height: 20px;
1677
+ color: color-mix(in srgb, var(--lb-text) 60%, transparent);
1678
+ text-decoration: line-through;
1679
+ }
1680
+
1681
+ /* Savings bar \u2014 green banner below pricing */
1682
+ .lb-bundle-savings-bar {
1683
+ display: flex;
1684
+ align-items: center;
1685
+ justify-content: space-between;
1686
+ background: var(--lb-savings-bar-bg);
1687
+ color: var(--lb-savings-bar-text);
1688
+ border: var(--lb-savings-bar-border-width) solid var(--lb-savings-bar-border-color);
1689
+ font-size: 16px;
1690
+ font-weight: 600;
1691
+ line-height: 20px;
1692
+ padding: 12px 16px;
1693
+ border-radius: var(--lb-savings-bar-radius);
1694
+ margin-bottom: 12px;
1695
+ }
1696
+
1697
+ /* Quantity badge \u2014 overlay on thumbnail top-right */
1698
+ .lb-bundle-qty-badge.lb-bundle-qty-badge {
1699
+ position: absolute;
1700
+ top: -8px;
1701
+ right: -8px;
1702
+ /* --lb-qty-badge-display fallback is the "on" branch; Liquid sets 'none' when merchant disables. */
1703
+ display: var(--lb-qty-badge-display, flex);
1704
+ align-items: center;
1705
+ justify-content: center;
1706
+ width: 24px;
1707
+ height: 24px;
1708
+ border-radius: 50%;
1709
+ background: var(--lb-qty-badge-bg);
1710
+ border: var(--lb-image-border-width) solid var(--lb-image-border-color);
1711
+ color: var(--lb-qty-badge-color);
1712
+ font-size: 12px;
1713
+ font-weight: 700;
1714
+ line-height: 0;
1715
+ text-align: center;
1716
+ z-index: 1;
1717
+ box-shadow: 0 1px 3px rgba(0, 0, 0, 0.08);
1718
+ }
1719
+
1720
+ /* Override Dawn's \`div:empty\` for savings bar when hidden */
1721
+ .lb-bundle-savings-bar:empty {
1722
+ display: none;
1723
+ }
1724
+
1725
+ /* CTA button */
1726
+ .lb-bundle-cta {
1727
+ display: block;
1728
+ width: 100%;
1729
+ padding: 16px;
1730
+ border: var(--lb-cta-border-width) solid var(--lb-cta-border-color);
1731
+ border-radius: var(--lb-cta-radius);
1732
+ font-size: 16px;
1733
+ font-weight: 600;
1734
+ line-height: 20px;
1735
+ cursor: pointer;
1736
+ text-align: center;
1737
+ transition: opacity 0.15s ease;
1738
+ font-family: inherit;
1739
+ }
1740
+
1741
+ .lb-bundle-cta:not(:disabled) {
1742
+ background: var(--lb-primary-color);
1743
+ color: var(--lb-btn-text);
1744
+ }
1745
+
1746
+ .lb-bundle-cta:not(:disabled):hover {
1747
+ opacity: 0.9;
1748
+ }
1749
+
1750
+ .lb-bundle-cta:disabled {
1751
+ background: color-mix(in srgb, var(--lb-primary-color) 35%, var(--lb-bg));
1752
+ color: color-mix(in srgb, var(--lb-btn-text) 85%, transparent);
1753
+ cursor: not-allowed;
1754
+ }
1755
+
1756
+ .lb-bundle-cta[data-loading="true"] {
1757
+ opacity: 0.7;
1758
+ cursor: wait;
1759
+ pointer-events: none;
1760
+ }
1761
+
1762
+ /* Error message */
1763
+ .lb-bundle-error {
1764
+ font-size: 16px;
1765
+ color: #D72C0D;
1766
+ margin-top: 8px;
1767
+ display: none;
1768
+ }
1769
+
1770
+ .lb-bundle-error[data-visible="true"] {
1771
+ display: block;
1772
+ }
1773
+
1774
+ /* Visually hidden \u2014 accessible to screen readers only */
1775
+ .lb-visually-hidden {
1776
+ position: absolute !important;
1777
+ width: 1px !important;
1778
+ height: 1px !important;
1779
+ padding: 0 !important;
1780
+ margin: -1px !important;
1781
+ overflow: hidden !important;
1782
+ clip-path: inset(50%) !important;
1783
+ white-space: nowrap !important;
1784
+ border: 0 !important;
1785
+ }
1786
+
1787
+ /* Placeholder SVG icon for missing images */
1788
+ .lb-bundle-placeholder-icon {
1789
+ width: 28px;
1790
+ height: 28px;
1791
+ stroke: #BBBBBB;
1792
+ stroke-width: 1.5;
1793
+ fill: none;
1794
+ }
1795
+
1796
+ /* Out-of-stock product row */
1797
+ .lb-bundle-product-row--oos {
1798
+ opacity: 0.5;
1799
+ }
1800
+
1801
+ .lb-bundle-oos-label {
1802
+ font-size: 12px;
1803
+ font-weight: 500;
1804
+ color: #D72C0D;
1805
+ white-space: nowrap;
1806
+ margin-left: auto;
1807
+ }
1808
+
1809
+ /* A/B test: hide save badge until JS swaps the label (prevents flash of default) */
1810
+ .lb-ab-pending {
1811
+ visibility: hidden;
1812
+ }
1813
+ `;
1814
+ var BUNDLE_FIXED_CSS = `/* Lime Bundles \u2014 Fixed bundle styles */
1815
+
1816
+ .lb-fixed__products {
1817
+ display: flex;
1818
+ flex-direction: column;
1819
+ gap: 0;
1820
+ margin: 0;
1821
+ }
1822
+
1823
+ /* Fixed bundles: product rows */
1824
+ .lb-fixed .lb-bundle-product-row {
1825
+ gap: 16px;
1826
+ align-items: center;
1827
+ }
1828
+
1829
+ /* Fixed bundles: larger thumbnails */
1830
+ .lb-fixed .lb-bundle-thumbnail {
1831
+ width: 60px;
1832
+ height: 60px;
1833
+ min-width: 60px;
1834
+ border-radius: var(--lb-image-border-radius);
1835
+ border: var(--lb-image-border-width) solid var(--lb-image-border-color);
1836
+ box-sizing: border-box;
1837
+ overflow: visible;
1838
+ }
1839
+
1840
+ .lb-fixed .lb-bundle-thumbnail img {
1841
+ border-radius: max(0px, calc(var(--lb-image-border-radius) - var(--lb-image-border-width)));
1842
+ border: none;
1843
+ }
1844
+
1845
+ /* Variant picker select \u2014 styled to match the variant badge aesthetic */
1846
+ .lb-bundle-variant-select {
1847
+ margin-top: 8px;
1848
+ display: inline-block;
1849
+ border: var(--lb-variant-border-width) solid var(--lb-variant-border-color);
1850
+ border-radius: var(--lb-variant-radius);
1851
+ padding: 8px 32px 8px 12px;
1852
+ font-size: 12px;
1853
+ line-height: 16px;
1854
+ color: var(--lb-text);
1855
+ background: var(--lb-bg);
1856
+ font-family: inherit;
1857
+ cursor: pointer;
1858
+ appearance: none;
1859
+ -webkit-appearance: none;
1860
+ background-image: var(--lb-variant-chevron);
1861
+ background-repeat: no-repeat;
1862
+ background-position: right 8px center;
1863
+ background-size: 12px;
1864
+ max-width: 100%;
1865
+ }
1866
+
1867
+ .lb-bundle-variant-select:focus-visible {
1868
+ outline: 2px solid var(--lb-primary-color);
1869
+ outline-offset: 2px;
1870
+ }
1871
+ `;
1872
+ var BUNDLE_MIX_MATCH_CSS = `/* Lime Bundles \u2014 Mix & Match styles */
1873
+
1874
+ /* === Progress Bar === */
1875
+ .lb-mix-match__progress {
1876
+ margin-bottom: 16px;
1877
+ }
1878
+
1879
+ .lb-mix-match__progress-labels {
1880
+ display: flex;
1881
+ justify-content: space-between;
1882
+ margin-bottom: 8px;
1883
+ }
1884
+
1885
+ .lb-mix-match__progress-count {
1886
+ font-size: 12px;
1887
+ font-weight: 500;
1888
+ line-height: 16px;
1889
+ color: color-mix(in srgb, var(--lb-text) 60%, transparent);
89
1890
  }
90
- function escapeHtml(str) {
91
- const div = document.createElement("div");
92
- div.textContent = str;
93
- return div.innerHTML;
1891
+
1892
+ .lb-mix-match__progress-remaining {
1893
+ font-size: 12px;
1894
+ font-weight: 500;
1895
+ line-height: 16px;
1896
+ color: var(--lb-text);
94
1897
  }
95
1898
 
96
- // src/renderers/mix-match.ts
97
- var import_core2 = require("@lime-bundles/core");
98
- function renderMixMatchBundle(container, bundle, onAddToCart) {
99
- const currency = bundle.products[0]?.priceRange.minVariantPrice.currencyCode ?? "USD";
100
- const selections = /* @__PURE__ */ new Map();
101
- const title = document.createElement("h3");
102
- title.className = "lb-bundle__title";
103
- title.textContent = bundle.title;
104
- title.setAttribute("part", "title");
105
- container.appendChild(title);
106
- const instructions = document.createElement("p");
107
- instructions.className = "lb-bundle__instructions";
108
- instructions.textContent = bundle.minQuantity && bundle.maxQuantity ? `Select ${bundle.minQuantity}\u2013${bundle.maxQuantity} items` : bundle.minQuantity ? `Select at least ${bundle.minQuantity} items` : "Select your items";
109
- container.appendChild(instructions);
110
- const productsDiv = document.createElement("div");
111
- productsDiv.className = "lb-bundle__products lb-bundle__products--selectable";
112
- for (const product of bundle.products) {
113
- const variant = product.variants.nodes.find((v) => v.availableForSale) ?? product.variants.nodes[0];
114
- if (!variant) continue;
115
- const productEl = document.createElement("div");
116
- productEl.className = "lb-bundle__product lb-bundle__product--selectable";
117
- if (product.featuredImage) {
118
- const img = document.createElement("img");
119
- img.src = product.featuredImage.url;
120
- img.alt = product.featuredImage.altText ?? product.title;
121
- img.className = "lb-bundle__product-image";
122
- img.loading = "lazy";
123
- productEl.appendChild(img);
124
- }
125
- const info = document.createElement("div");
126
- info.className = "lb-bundle__product-info";
127
- info.innerHTML = `
128
- <p class="lb-bundle__product-title">${escapeHtml2(product.title)}</p>
129
- <p class="lb-bundle__product-price">${escapeHtml2((0, import_core2.formatMoney)(variant.price.amount, currency))}</p>
130
- `;
131
- productEl.appendChild(info);
132
- const selectBtn = document.createElement("button");
133
- selectBtn.className = "lb-bundle__select-btn";
134
- selectBtn.textContent = variant.availableForSale ? "Select" : "Sold out";
135
- selectBtn.disabled = !variant.availableForSale;
136
- selectBtn.addEventListener("click", () => {
137
- const key = product.id;
138
- if (selections.has(key)) {
139
- selections.delete(key);
140
- productEl.classList.remove("lb-bundle__product--selected");
141
- selectBtn.textContent = "Select";
142
- } else {
143
- selections.set(key, { variantId: variant.id, quantity: 1 });
144
- productEl.classList.add("lb-bundle__product--selected");
145
- selectBtn.textContent = "Selected";
146
- }
147
- updateCta();
148
- });
149
- productEl.appendChild(selectBtn);
150
- productsDiv.appendChild(productEl);
1899
+ .lb-mix-match__progress-track {
1900
+ width: 100%;
1901
+ height: 4px;
1902
+ background: color-mix(in srgb, var(--lb-text) 10%, transparent);
1903
+ border-radius: 4px;
1904
+ overflow: hidden;
1905
+ }
1906
+
1907
+ .lb-mix-match__progress-fill {
1908
+ height: 100%;
1909
+ background: var(--lb-text);
1910
+ border-radius: 4px;
1911
+ transition: width 0.3s ease;
1912
+ }
1913
+
1914
+ /* === Slots === */
1915
+ .lb-mix-match__slot {
1916
+ cursor: pointer;
1917
+ }
1918
+
1919
+ .lb-mix-match .lb-bundle-product-row {
1920
+ align-items: center;
1921
+ }
1922
+
1923
+ .lb-mix-match__slot--empty:focus-visible {
1924
+ outline: 2px solid var(--lb-primary-color);
1925
+ outline-offset: 2px;
1926
+ border-radius: 8px;
1927
+ }
1928
+
1929
+ .lb-mix-match__slot--empty .lb-mix-match__empty-thumb {
1930
+ width: 60px;
1931
+ height: 60px;
1932
+ min-width: 60px;
1933
+ border: var(--lb-image-border-width) dashed color-mix(in srgb, var(--lb-text) 20%, transparent);
1934
+ border-radius: var(--lb-image-border-radius);
1935
+ box-sizing: border-box;
1936
+ display: flex;
1937
+ align-items: center;
1938
+ justify-content: center;
1939
+ color: color-mix(in srgb, var(--lb-text) 35%, transparent);
1940
+ }
1941
+
1942
+ .lb-mix-match__empty-text {
1943
+ font-size: 16px;
1944
+ line-height: 20px;
1945
+ color: color-mix(in srgb, var(--lb-text) 45%, transparent);
1946
+ }
1947
+
1948
+ /* Filled slot */
1949
+ .lb-mix-match__slot--filled {
1950
+ cursor: default;
1951
+ }
1952
+
1953
+ .lb-mix-match .lb-bundle-thumbnail {
1954
+ width: 60px;
1955
+ height: 60px;
1956
+ min-width: 60px;
1957
+ border-radius: var(--lb-image-border-radius);
1958
+ border: var(--lb-image-border-width) solid var(--lb-image-border-color);
1959
+ box-sizing: border-box;
1960
+ overflow: visible;
1961
+ }
1962
+
1963
+ .lb-mix-match .lb-bundle-thumbnail img {
1964
+ border-radius: max(0px, calc(var(--lb-image-border-radius) - var(--lb-image-border-width)));
1965
+ border: none;
1966
+ }
1967
+
1968
+ .lb-mix-match__slot--filled .lb-mix-match__filled-info {
1969
+ flex: 1;
1970
+ min-width: 0;
1971
+ display: flex;
1972
+ flex-direction: column;
1973
+ }
1974
+
1975
+ .lb-mix-match__slot--filled .lb-mix-match__filled-title {
1976
+ font-size: 16px;
1977
+ font-weight: 700;
1978
+ line-height: 20px;
1979
+ color: var(--lb-text);
1980
+ text-decoration: none;
1981
+ overflow-wrap: break-word;
1982
+ }
1983
+
1984
+ .lb-mix-match__slot--filled a.lb-mix-match__filled-title:hover {
1985
+ text-decoration: underline;
1986
+ }
1987
+
1988
+ .lb-mix-match__slot--filled .lb-mix-match__filled-variant {
1989
+ font-size: 12px;
1990
+ line-height: 20px;
1991
+ margin-top: 2px;
1992
+ color: color-mix(in srgb, var(--lb-text) 60%, transparent);
1993
+ }
1994
+
1995
+ .lb-mix-match__filled-price {
1996
+ /* --lb-product-price-display fallback is the "on" branch; Liquid sets 'none' when merchant disables. */
1997
+ display: var(--lb-product-price-display, block);
1998
+ font-size: 12px;
1999
+ line-height: 20px;
2000
+ margin-top: 4px;
2001
+ color: var(--lb-text);
2002
+ font-weight: 500;
2003
+ }
2004
+
2005
+ .lb-mix-match__filled-compare {
2006
+ /* --lb-product-compare-display fallback is the "on" branch; Liquid sets 'none' when merchant disables. */
2007
+ display: var(--lb-product-compare-display, inline);
2008
+ font-size: 12px;
2009
+ font-weight: 400;
2010
+ color: color-mix(in srgb, var(--lb-text) 60%, transparent);
2011
+ text-decoration: line-through;
2012
+ margin-right: 4px;
2013
+ }
2014
+
2015
+ .lb-mix-match__slot-remove {
2016
+ min-width: 44px;
2017
+ min-height: 44px;
2018
+ display: flex;
2019
+ align-items: center;
2020
+ justify-content: center;
2021
+ background: none;
2022
+ border: none;
2023
+ cursor: pointer;
2024
+ color: var(--lb-text);
2025
+ padding: 0;
2026
+ margin-left: auto;
2027
+ border-radius: 8px;
2028
+ }
2029
+
2030
+ .lb-mix-match__slot-remove:hover {
2031
+ color: var(--lb-text);
2032
+ }
2033
+
2034
+ .lb-mix-match__slot-remove:focus-visible {
2035
+ outline: 2px solid var(--lb-primary-color);
2036
+ outline-offset: 2px;
2037
+ }
2038
+
2039
+ /* Price placeholder */
2040
+ .lb-mix-match__price-placeholder {
2041
+ padding: 4px 0 16px;
2042
+ text-align: center;
2043
+ }
2044
+
2045
+ .lb-mix-match__price-placeholder-text {
2046
+ font-size: 16px;
2047
+ color: var(--lb-text);
2048
+ }
2049
+
2050
+ /* === Modal Overlay === */
2051
+ .lb-mix-match__modal-overlay {
2052
+ position: fixed;
2053
+ top: 0;
2054
+ left: 0;
2055
+ right: 0;
2056
+ bottom: 0;
2057
+ background: rgba(0, 0, 0, 0.5);
2058
+ z-index: 9999;
2059
+ display: flex;
2060
+ align-items: center;
2061
+ justify-content: center;
2062
+ opacity: 0;
2063
+ transition: opacity 0.2s ease-out;
2064
+ }
2065
+
2066
+ .lb-mix-match__modal-overlay--open {
2067
+ opacity: 1;
2068
+ }
2069
+
2070
+ /* === Modal Panel === */
2071
+ .lb-mix-match__modal {
2072
+ background: var(--lb-picker-bg);
2073
+ color: var(--lb-picker-text);
2074
+ border-radius: var(--lb-picker-radius);
2075
+ border: var(--lb-picker-border-width) solid var(--lb-picker-border-color);
2076
+ box-sizing: border-box;
2077
+ width: 100%;
2078
+ max-width: 480px;
2079
+ max-height: 70vh;
2080
+ display: flex;
2081
+ flex-direction: column;
2082
+ overflow: hidden;
2083
+ box-shadow: 0 8px 32px rgba(0, 0, 0, 0.16);
2084
+ transform: translateY(24px);
2085
+ transition: transform 0.25s ease-out;
2086
+ will-change: transform;
2087
+ }
2088
+
2089
+ .lb-mix-match__modal-overlay--open .lb-mix-match__modal {
2090
+ transform: translateY(0);
2091
+ }
2092
+
2093
+ /* === Modal Header === */
2094
+ .lb-mix-match__modal-header {
2095
+ display: flex;
2096
+ align-items: center;
2097
+ justify-content: space-between;
2098
+ padding: 20px 20px 12px;
2099
+ flex-shrink: 0;
2100
+ }
2101
+
2102
+ .lb-mix-match__modal-title {
2103
+ font-size: 20px;
2104
+ font-weight: 600;
2105
+ line-height: 24px;
2106
+ margin: 0;
2107
+ color: inherit;
2108
+ }
2109
+
2110
+ .lb-mix-match__modal-close {
2111
+ min-width: 44px;
2112
+ min-height: 44px;
2113
+ display: flex;
2114
+ align-items: center;
2115
+ justify-content: center;
2116
+ background: none;
2117
+ border: none;
2118
+ cursor: pointer;
2119
+ color: var(--lb-picker-text);
2120
+ border-radius: 8px;
2121
+ padding: 0;
2122
+ margin: -12px -12px -12px 0;
2123
+ }
2124
+
2125
+ .lb-mix-match__modal-close:focus-visible {
2126
+ outline: 2px solid var(--lb-primary-color);
2127
+ outline-offset: 2px;
2128
+ }
2129
+
2130
+ /* === Modal Search === */
2131
+ .lb-mix-match__modal-search {
2132
+ padding: 0 20px 12px;
2133
+ position: relative;
2134
+ flex-shrink: 0;
2135
+ }
2136
+
2137
+ .lb-mix-match__modal-search-input {
2138
+ width: 100%;
2139
+ padding: 12px 40px 12px 16px;
2140
+ border: var(--lb-picker-search-border-width) solid var(--lb-picker-search-border-color);
2141
+ border-radius: var(--lb-picker-search-radius);
2142
+ font-size: 16px;
2143
+ line-height: 20px;
2144
+ color: var(--lb-picker-text);
2145
+ background: var(--lb-picker-bg);
2146
+ box-sizing: border-box;
2147
+ -webkit-appearance: none;
2148
+ appearance: none;
2149
+ }
2150
+
2151
+ .lb-mix-match__modal-search-input::placeholder {
2152
+ color: color-mix(in srgb, var(--lb-picker-text) 50%, transparent);
2153
+ }
2154
+
2155
+ .lb-mix-match__modal-search-input:focus {
2156
+ outline: none;
2157
+ box-shadow: 0 0 0 1px var(--lb-primary-color);
2158
+ }
2159
+
2160
+ .lb-mix-match__modal-search-clear {
2161
+ position: absolute;
2162
+ right: 32px;
2163
+ /* Anchor to the input area only \u2014 parent has padding-bottom: 12px which would
2164
+ otherwise push a top:50% center down by 6px. */
2165
+ top: 0;
2166
+ bottom: 12px;
2167
+ min-width: 32px;
2168
+ min-height: 32px;
2169
+ display: flex;
2170
+ align-items: center;
2171
+ justify-content: center;
2172
+ background: none;
2173
+ border: none;
2174
+ cursor: pointer;
2175
+ color: var(--lb-picker-text);
2176
+ padding: 0;
2177
+ }
2178
+
2179
+ /* === Modal Product List === */
2180
+ .lb-mix-match__modal-list {
2181
+ overflow-y: auto;
2182
+ flex: 1;
2183
+ padding: 0 20px;
2184
+ -webkit-overflow-scrolling: touch;
2185
+ }
2186
+
2187
+ .lb-mix-match__modal-product {
2188
+ display: flex;
2189
+ align-items: center;
2190
+ gap: 12px;
2191
+ padding: 12px 0;
2192
+ border-bottom: 1px solid color-mix(in srgb, var(--lb-picker-text) 7%, transparent);
2193
+ }
2194
+
2195
+ .lb-mix-match__modal-product:last-child {
2196
+ border-bottom: none;
2197
+ }
2198
+
2199
+ .lb-mix-match__modal-product-thumb {
2200
+ position: relative;
2201
+ width: 48px;
2202
+ height: 48px;
2203
+ min-width: 48px;
2204
+ border-radius: var(--lb-picker-product-radius);
2205
+ border: var(--lb-picker-product-border-width) solid var(--lb-picker-product-border-color);
2206
+ box-sizing: border-box;
2207
+ overflow: visible;
2208
+ background: #F0F0F0;
2209
+ }
2210
+
2211
+ /* Qty badge inside the picker modal inherits picker-product border (width + color) plus
2212
+ inverted picker bg/text for clear contrast against the modal \u2014 always stays round
2213
+ (the badge shape is independent of the thumbnail shape). */
2214
+ .lb-mix-match__modal-product-thumb .lb-bundle-qty-badge.lb-bundle-qty-badge {
2215
+ /* --lb-picker-qty-badge-display fallback is the "on" branch; Liquid sets 'none' when merchant disables. */
2216
+ display: var(--lb-picker-qty-badge-display, flex);
2217
+ background: var(--lb-picker-qty-badge-bg);
2218
+ color: var(--lb-picker-qty-badge-color);
2219
+ border: var(--lb-picker-product-border-width) solid var(--lb-picker-product-border-color);
2220
+ }
2221
+
2222
+ .lb-mix-match__modal-product-thumb img {
2223
+ width: 100%;
2224
+ height: 100%;
2225
+ object-fit: cover;
2226
+ border-radius: max(0px, calc(var(--lb-picker-product-radius) - var(--lb-picker-product-border-width)));
2227
+ }
2228
+
2229
+ .lb-mix-match__modal-product-info {
2230
+ flex: 1;
2231
+ min-width: 0;
2232
+ }
2233
+
2234
+ .lb-mix-match__modal-product-title {
2235
+ font-size: 16px;
2236
+ font-weight: 700;
2237
+ line-height: 20px;
2238
+ color: inherit;
2239
+ margin: 0;
2240
+ }
2241
+
2242
+ .lb-mix-match__modal-product-price {
2243
+ font-size: 12px;
2244
+ line-height: 20px;
2245
+ color: inherit;
2246
+ margin: 4px 0 0;
2247
+ }
2248
+
2249
+ .lb-mix-match__variant-select {
2250
+ font-size: 12px;
2251
+ margin: 4px 0 0;
2252
+ padding: 4px 24px 4px 8px;
2253
+ border: var(--lb-picker-variant-border-width) solid var(--lb-picker-variant-border-color);
2254
+ border-radius: var(--lb-picker-variant-radius);
2255
+ background-color: var(--lb-picker-bg);
2256
+ background-image: var(--lb-picker-variant-chevron);
2257
+ background-repeat: no-repeat;
2258
+ background-position: right 6px center;
2259
+ background-size: 12px;
2260
+ color: var(--lb-picker-text);
2261
+ font-family: inherit;
2262
+ min-height: 32px;
2263
+ cursor: pointer;
2264
+ max-width: 120px;
2265
+ appearance: none;
2266
+ -webkit-appearance: none;
2267
+ }
2268
+
2269
+ .lb-mix-match__variant-select:focus-visible {
2270
+ outline: 2px solid var(--lb-primary-color);
2271
+ outline-offset: 2px;
2272
+ }
2273
+
2274
+ .lb-mix-match__modal-add {
2275
+ padding: 8px 20px;
2276
+ background: var(--lb-picker-add-bg);
2277
+ color: var(--lb-picker-add-label);
2278
+ border: var(--lb-picker-add-border-width) solid var(--lb-picker-add-border-color);
2279
+ border-radius: var(--lb-picker-add-radius);
2280
+ box-sizing: border-box;
2281
+ font-size: 12px;
2282
+ font-weight: 600;
2283
+ cursor: pointer;
2284
+ white-space: nowrap;
2285
+ flex-shrink: 0;
2286
+ }
2287
+
2288
+ .lb-mix-match__modal-add:hover {
2289
+ opacity: 0.9;
2290
+ }
2291
+
2292
+ .lb-mix-match__modal-add:focus-visible {
2293
+ outline: 2px solid var(--lb-primary-color);
2294
+ outline-offset: 2px;
2295
+ }
2296
+
2297
+ .lb-mix-match__modal-add:disabled {
2298
+ background: color-mix(in srgb, var(--lb-picker-add-bg) 35%, var(--lb-picker-bg));
2299
+ color: color-mix(in srgb, var(--lb-picker-add-label) 85%, transparent);
2300
+ cursor: not-allowed;
2301
+ }
2302
+
2303
+ /* Sold out product row */
2304
+ .lb-mix-match__modal-product--sold-out {
2305
+ opacity: 0.5;
2306
+ }
2307
+
2308
+ .lb-mix-match__modal-product--sold-out .lb-mix-match__modal-sold-out-label {
2309
+ font-size: 12px;
2310
+ color: inherit;
2311
+ font-weight: 500;
2312
+ white-space: nowrap;
2313
+ }
2314
+
2315
+ /* === Modal Empty State === */
2316
+ .lb-mix-match__modal-empty {
2317
+ padding: 32px 20px;
2318
+ text-align: center;
2319
+ }
2320
+
2321
+ .lb-mix-match__modal-empty p {
2322
+ margin: 0;
2323
+ font-size: 16px;
2324
+ color: var(--lb-picker-text);
2325
+ }
2326
+
2327
+ /* Hidden utility for search filtering */
2328
+ .lb-hidden {
2329
+ display: none !important;
2330
+ }
2331
+
2332
+ /* === Mobile Full-Screen Modal === */
2333
+ @media (max-width: 767px) {
2334
+ .lb-mix-match__modal-overlay {
2335
+ align-items: flex-end;
151
2336
  }
152
- container.appendChild(productsDiv);
153
- const validationEl = document.createElement("p");
154
- validationEl.className = "lb-bundle__validation";
155
- container.appendChild(validationEl);
156
- const button = document.createElement("button");
157
- button.className = "lb-bundle__cta";
158
- button.setAttribute("part", "button");
159
- button.disabled = true;
160
- container.appendChild(button);
161
- function updateCta() {
162
- const total = Array.from(selections.values()).reduce(
163
- (s, v) => s + v.quantity,
164
- 0
165
- );
166
- const validation = (0, import_core2.validateQuantity)(
167
- total,
168
- bundle.minQuantity,
169
- bundle.maxQuantity
170
- );
171
- button.disabled = !validation.valid;
172
- button.textContent = bundle.widgetConfig.ctaText ?? `Add ${total} Items to Cart`;
173
- validationEl.textContent = validation.message ?? "";
2337
+
2338
+ .lb-mix-match__modal {
2339
+ max-width: 100%;
2340
+ max-height: 90vh;
2341
+ border-radius: 16px 16px 0 0;
2342
+ transform: translateY(100%);
2343
+ }
2344
+
2345
+ .lb-mix-match__modal-overlay--open .lb-mix-match__modal {
2346
+ transform: translateY(0);
174
2347
  }
175
- updateCta();
176
- button.addEventListener("click", () => {
177
- const lines = Array.from(selections.values()).map((s) => ({
178
- merchandiseId: s.variantId,
179
- quantity: s.quantity,
180
- attributes: [
181
- { key: "_lime_bundle_gid", value: bundle.id },
182
- { key: "_lime_bundle_type", value: bundle.bundleType }
183
- ]
184
- }));
185
- if (lines.length === 0) return;
186
- onAddToCart(lines);
187
- });
188
2348
  }
189
- function escapeHtml2(str) {
190
- const div = document.createElement("div");
191
- div.textContent = str;
192
- return div.innerHTML;
2349
+
2350
+ /* === Reduced Motion === */
2351
+ @media (prefers-reduced-motion: reduce) {
2352
+ .lb-mix-match__modal-overlay,
2353
+ .lb-mix-match__modal,
2354
+ .lb-mix-match__progress-fill {
2355
+ transition: none;
2356
+ }
193
2357
  }
2358
+ `;
2359
+ var BUNDLE_VOLUME_CSS = `/* Lime Bundles \u2014 Volume / Quantity Breaks styles */
194
2360
 
195
- // src/renderers/volume.ts
196
- var import_core3 = require("@lime-bundles/core");
197
- function renderVolumeBundle(container, bundle, onAddToCart) {
198
- const product = bundle.products[0];
199
- if (!product) return;
200
- const basePrice = parseFloat(product.priceRange.minVariantPrice.amount);
201
- const currency = product.priceRange.minVariantPrice.currencyCode;
202
- let quantity = 1;
203
- const title = document.createElement("h3");
204
- title.className = "lb-bundle__title";
205
- title.textContent = bundle.title;
206
- title.setAttribute("part", "title");
207
- container.appendChild(title);
208
- const productEl = document.createElement("div");
209
- productEl.className = "lb-bundle__product lb-bundle__product--volume";
210
- if (product.featuredImage) {
211
- const img = document.createElement("img");
212
- img.src = product.featuredImage.url;
213
- img.alt = product.featuredImage.altText ?? product.title;
214
- img.className = "lb-bundle__product-image";
215
- img.loading = "lazy";
216
- productEl.appendChild(img);
217
- }
218
- const info = document.createElement("div");
219
- info.className = "lb-bundle__product-info";
220
- info.innerHTML = `
221
- <p class="lb-bundle__product-title">${escapeHtml3(product.title)}</p>
222
- <p class="lb-bundle__product-price">${escapeHtml3((0, import_core3.formatMoney)(basePrice, currency))} each</p>
223
- `;
224
- productEl.appendChild(info);
225
- container.appendChild(productEl);
226
- const tiersDiv = document.createElement("div");
227
- tiersDiv.className = "lb-bundle__tiers";
228
- tiersDiv.setAttribute("role", "table");
229
- tiersDiv.setAttribute("aria-label", "Volume discounts");
230
- container.appendChild(tiersDiv);
231
- const qtyWrapper = document.createElement("div");
232
- qtyWrapper.className = "lb-bundle__quantity-selector";
233
- const label = document.createElement("label");
234
- label.textContent = "Quantity";
235
- qtyWrapper.appendChild(label);
236
- const qtyControl = document.createElement("div");
237
- qtyControl.className = "lb-bundle__quantity-control";
238
- const minusBtn = document.createElement("button");
239
- minusBtn.textContent = "\u2212";
240
- minusBtn.setAttribute("aria-label", "Decrease quantity");
241
- const qtyInput = document.createElement("input");
242
- qtyInput.type = "number";
243
- qtyInput.min = "1";
244
- qtyInput.value = "1";
245
- qtyInput.className = "lb-bundle__quantity-input";
246
- const plusBtn = document.createElement("button");
247
- plusBtn.textContent = "+";
248
- plusBtn.setAttribute("aria-label", "Increase quantity");
249
- qtyControl.append(minusBtn, qtyInput, plusBtn);
250
- qtyWrapper.appendChild(qtyControl);
251
- container.appendChild(qtyWrapper);
252
- const button = document.createElement("button");
253
- button.className = "lb-bundle__cta";
254
- button.setAttribute("part", "button");
255
- container.appendChild(button);
256
- function updateTiers() {
257
- const savings = (0, import_core3.calculateTierSavings)(
258
- bundle.volumeTiers,
259
- basePrice,
260
- quantity
261
- );
262
- tiersDiv.innerHTML = "";
263
- for (const ts of savings) {
264
- const row = document.createElement("div");
265
- row.className = `lb-bundle__tier${ts.isActive ? " lb-bundle__tier--active" : ""}`;
266
- row.setAttribute("role", "row");
267
- row.innerHTML = `
268
- <span class="lb-bundle__tier-quantity" role="cell">${ts.tier.minQuantity}+ items</span>
269
- <span class="lb-bundle__tier-price" role="cell">${escapeHtml3((0, import_core3.formatMoney)(ts.unitPrice, currency))} each</span>
270
- <span class="lb-bundle__tier-savings" role="cell">Save ${ts.savingsPercent.toFixed(0)}%</span>
271
- ${ts.tier.label ? `<span class="lb-bundle__tier-label" role="cell">${escapeHtml3(ts.tier.label)}</span>` : ""}
272
- `;
273
- tiersDiv.appendChild(row);
274
- }
275
- button.textContent = bundle.widgetConfig.ctaText ?? `Add ${quantity} to Cart`;
276
- }
277
- updateTiers();
278
- minusBtn.addEventListener("click", () => {
279
- if (quantity > 1) {
280
- quantity--;
281
- qtyInput.value = String(quantity);
282
- updateTiers();
283
- }
284
- });
285
- plusBtn.addEventListener("click", () => {
286
- quantity++;
287
- qtyInput.value = String(quantity);
288
- updateTiers();
289
- });
290
- qtyInput.addEventListener("change", () => {
291
- const val = parseInt(qtyInput.value, 10);
292
- if (!isNaN(val) && val > 0) {
293
- quantity = val;
294
- updateTiers();
295
- }
296
- });
297
- button.addEventListener("click", () => {
298
- const variant = product.variants.nodes.find((v) => v.availableForSale);
299
- if (!variant) return;
300
- onAddToCart([
301
- {
302
- merchandiseId: variant.id,
303
- quantity,
304
- attributes: [
305
- { key: "_lime_bundle_gid", value: bundle.id },
306
- { key: "_lime_bundle_type", value: bundle.bundleType }
307
- ]
308
- }
309
- ]);
310
- });
2361
+ .lb-volume__tiers {
2362
+ display: flex;
2363
+ flex-direction: column;
2364
+ gap: 12px;
311
2365
  }
312
- function escapeHtml3(str) {
313
- const div = document.createElement("div");
314
- div.textContent = str;
315
- return div.innerHTML;
2366
+
2367
+ .lb-volume__tier {
2368
+ display: flex;
2369
+ align-items: center;
2370
+ gap: 12px;
2371
+ border: var(--lb-tier-border-width) solid var(--lb-tier-border-color);
2372
+ border-radius: var(--lb-tier-radius);
2373
+ padding: 12px 16px;
2374
+ cursor: pointer;
2375
+ position: relative;
2376
+ transition: border-color 0.15s ease;
316
2377
  }
317
2378
 
318
- // src/styles/widget-styles.ts
319
- var WIDGET_STYLES = `
320
- :host {
321
- display: block;
322
- --lb-primary-color: #000;
323
- --lb-secondary-color: #666;
324
- --lb-accent-color: #2563eb;
325
- --lb-background: #fff;
326
- --lb-border-color: #e5e7eb;
327
- --lb-border-radius: 8px;
328
- --lb-font-family: inherit;
329
- --lb-font-size: 14px;
330
- --lb-spacing-sm: 8px;
331
- --lb-spacing-md: 16px;
332
- --lb-spacing-lg: 24px;
333
- --lb-button-bg: var(--lb-accent-color);
334
- --lb-button-text: #fff;
335
- --lb-button-radius: var(--lb-border-radius);
336
- --lb-savings-color: #16a34a;
337
- --lb-error-color: #dc2626;
338
- }
339
-
340
- .lb-bundle {
341
- font-family: var(--lb-font-family);
342
- font-size: var(--lb-font-size);
343
- color: var(--lb-primary-color);
344
- background: var(--lb-background);
345
- border: 1px solid var(--lb-border-color);
346
- border-radius: var(--lb-border-radius);
347
- padding: var(--lb-spacing-lg);
348
- }
349
-
350
- .lb-bundle__title { margin: 0 0 var(--lb-spacing-md); font-size: 1.25em; font-weight: 600; }
351
- .lb-bundle__discount-badge { display: inline-block; background: var(--lb-savings-color); color: #fff; padding: 2px 8px; border-radius: 4px; font-size: 0.85em; font-weight: 600; margin-bottom: var(--lb-spacing-md); }
352
- .lb-bundle__products { display: grid; gap: var(--lb-spacing-md); margin-bottom: var(--lb-spacing-lg); }
353
- .lb-bundle__product { display: flex; gap: var(--lb-spacing-md); align-items: center; padding: var(--lb-spacing-sm); border: 1px solid var(--lb-border-color); border-radius: var(--lb-border-radius); }
354
- .lb-bundle__product--selected { border-color: var(--lb-accent-color); }
355
- .lb-bundle__product-image { width: 64px; height: 64px; object-fit: cover; border-radius: calc(var(--lb-border-radius) - 2px); flex-shrink: 0; }
356
- .lb-bundle__product-info { flex: 1; min-width: 0; }
357
- .lb-bundle__product-title { margin: 0; font-weight: 500; }
358
- .lb-bundle__product-price { margin: 4px 0 0; color: var(--lb-secondary-color); }
359
- .lb-bundle__instructions { color: var(--lb-secondary-color); margin: 0 0 var(--lb-spacing-md); }
360
- .lb-bundle__tiers { margin-bottom: var(--lb-spacing-lg); }
361
- .lb-bundle__tier { display: flex; align-items: center; gap: var(--lb-spacing-md); padding: var(--lb-spacing-sm) var(--lb-spacing-md); border: 1px solid var(--lb-border-color); border-radius: var(--lb-border-radius); margin-bottom: var(--lb-spacing-sm); }
362
- .lb-bundle__tier--active { border-color: var(--lb-savings-color); }
363
- .lb-bundle__tier-savings { color: var(--lb-savings-color); font-weight: 600; }
364
- .lb-bundle__quantity-selector { margin-bottom: var(--lb-spacing-lg); }
365
- .lb-bundle__quantity-selector label { display: block; margin-bottom: var(--lb-spacing-sm); font-weight: 500; }
366
- .lb-bundle__quantity-control { display: inline-flex; align-items: center; border: 1px solid var(--lb-border-color); border-radius: var(--lb-border-radius); }
367
- .lb-bundle__quantity-control button { width: 32px; height: 32px; border: none; background: transparent; cursor: pointer; font-size: 1.1em; display: flex; align-items: center; justify-content: center; }
368
- .lb-bundle__quantity-input { width: 40px; text-align: center; border: none; border-left: 1px solid var(--lb-border-color); border-right: 1px solid var(--lb-border-color); height: 32px; font-size: var(--lb-font-size); -moz-appearance: textfield; }
369
- .lb-bundle__quantity-input::-webkit-outer-spin-button, .lb-bundle__quantity-input::-webkit-inner-spin-button { -webkit-appearance: none; }
370
- .lb-bundle__select-btn { padding: 6px 12px; border: 1px solid var(--lb-border-color); border-radius: var(--lb-border-radius); background: transparent; cursor: pointer; }
371
- .lb-bundle__select-btn:disabled { opacity: 0.5; cursor: not-allowed; }
372
- .lb-bundle__cta { width: 100%; padding: 12px 24px; border: none; border-radius: var(--lb-button-radius); background: var(--lb-button-bg); color: var(--lb-button-text); font-size: 1em; font-weight: 600; cursor: pointer; transition: opacity 0.15s; }
373
- .lb-bundle__cta:hover:not(:disabled) { opacity: 0.9; }
374
- .lb-bundle__cta:disabled { opacity: 0.5; cursor: not-allowed; }
375
- .lb-bundle__error { color: var(--lb-error-color); margin: var(--lb-spacing-sm) 0; font-size: 0.9em; }
376
- .lb-bundle__validation { color: var(--lb-secondary-color); margin: var(--lb-spacing-sm) 0; font-size: 0.9em; }
377
-
378
- .lb-skeleton { background: linear-gradient(90deg, #f0f0f0 25%, #e0e0e0 50%, #f0f0f0 75%); background-size: 200% 100%; animation: lb-shimmer 1.5s infinite; border-radius: var(--lb-border-radius); }
379
- .lb-skeleton--title { height: 24px; width: 60%; margin-bottom: var(--lb-spacing-md); }
380
- .lb-skeleton--products { height: 200px; }
381
- @keyframes lb-shimmer { 0% { background-position: 200% 0; } 100% { background-position: -200% 0; } }
2379
+ .lb-volume__tier:hover {
2380
+ border-color: color-mix(in srgb, var(--lb-tier-border-color) 50%, black);
2381
+ }
2382
+
2383
+ .lb-volume__tier:focus-visible {
2384
+ outline: 2px solid var(--lb-primary-color);
2385
+ outline-offset: 2px;
2386
+ }
2387
+
2388
+ .lb-volume__tier[aria-checked="true"] {
2389
+ border-color: var(--lb-tier-selected-border-color);
2390
+ outline: var(--lb-tier-selected-border-width) solid var(--lb-tier-selected-border-color);
2391
+ outline-offset: calc(-1 * var(--lb-tier-selected-border-width));
2392
+ }
2393
+
2394
+ .lb-volume__radio {
2395
+ width: 20px;
2396
+ height: 20px;
2397
+ min-width: 20px;
2398
+ border: 2px solid var(--lb-text);
2399
+ border-radius: 50%;
2400
+ display: flex;
2401
+ align-items: center;
2402
+ justify-content: center;
2403
+ transition: border-color 0.15s ease;
2404
+ }
2405
+
2406
+ .lb-volume__tier[aria-checked="true"] .lb-volume__radio {
2407
+ border-color: var(--lb-text);
2408
+ }
2409
+
2410
+ .lb-volume__radio-dot {
2411
+ width: 12px;
2412
+ height: 12px;
2413
+ border-radius: 50%;
2414
+ background: transparent;
2415
+ transition: background 0.15s ease;
2416
+ }
2417
+
2418
+ .lb-volume__tier[aria-checked="true"] .lb-volume__radio-dot {
2419
+ background: var(--lb-text);
2420
+ }
2421
+
2422
+ /* Tier content: 2x2 grid layout */
2423
+ .lb-volume__tier-grid {
2424
+ flex: 1;
2425
+ display: grid;
2426
+ row-gap: 4px;
2427
+ align-items: center;
2428
+ }
2429
+
2430
+ .lb-volume__tier-label {
2431
+ font-size: 16px;
2432
+ font-weight: 700;
2433
+ color: var(--lb-text);
2434
+ }
2435
+
2436
+ .lb-volume__tier-badge {
2437
+ flex-shrink: 0;
2438
+ font-size: 12px;
2439
+ line-height: 16px;
2440
+ color: var(--lb-popular-badge-text);
2441
+ background: var(--lb-popular-badge-bg);
2442
+ border: var(--lb-popular-badge-border-width) solid var(--lb-popular-badge-border-color);
2443
+ border-radius: var(--lb-popular-badge-radius);
2444
+ padding: 4px 8px;
2445
+ }
2446
+
2447
+ .lb-volume__tier-price {
2448
+ grid-column: 1 / -1;
2449
+ font-size: 12px;
2450
+ font-weight: 500;
2451
+ color: var(--lb-text);
2452
+ }
2453
+
2454
+ .lb-volume__tier-unit {
2455
+ font-size: 12px;
2456
+ color: var(--lb-text);
2457
+ }
2458
+
2459
+ /* Compare-at (strikethrough) price */
2460
+ .lb-volume__tier-compare {
2461
+ font-size: 12px;
2462
+ line-height: 16px;
2463
+ color: color-mix(in srgb, var(--lb-text) 60%, transparent);
2464
+ text-decoration: line-through;
2465
+ margin-right: 4px;
2466
+ }
2467
+
2468
+
382
2469
  `;
383
2470
 
384
2471
  // src/lime-bundle.ts
2472
+ var cartStorageKey = (shopDomain) => `lb_cart_id:${shopDomain}`;
2473
+ function resolveProductHandle(explicit) {
2474
+ if (explicit) return explicit.trim() || null;
2475
+ if (typeof document !== "undefined") {
2476
+ const meta = document.querySelector(
2477
+ 'meta[name="shopify:product-handle"]'
2478
+ );
2479
+ if (meta?.content) return meta.content.trim() || null;
2480
+ }
2481
+ if (typeof window !== "undefined") {
2482
+ const match = window.location.pathname.match(/\/products\/([^/?#]+)/);
2483
+ if (match?.[1]) return decodeURIComponent(match[1]);
2484
+ }
2485
+ return null;
2486
+ }
385
2487
  var LimeBundleElement = class extends HTMLElement {
386
2488
  static observedAttributes = [
387
2489
  "shop-domain",
388
2490
  "storefront-token",
389
2491
  "bundle-gid",
2492
+ "product-handle",
390
2493
  "app-url",
391
2494
  "analytics",
392
2495
  "locale"
393
2496
  ];
394
2497
  shadow;
395
- bundle = null;
2498
+ bundles = [];
396
2499
  abortController = null;
397
- impressionCleanup = null;
2500
+ impressionCleanups = [];
2501
+ /**
2502
+ * Tick / observer / listener cleanups registered by individual renderers
2503
+ * (e.g. countdown setInterval handles). Flushed in disconnectedCallback
2504
+ * so we never leak timers or event listeners when the widget is removed.
2505
+ */
2506
+ renderCleanups = [];
2507
+ /**
2508
+ * Merchant custom CSS fetched from the shop metafield. Injected inside
2509
+ * the shadow root alongside the bundle stylesheets so selectors like
2510
+ * `.lb-bundle-widget { ... }` reach the widget's DOM.
2511
+ */
2512
+ shopCustomCss = null;
398
2513
  constructor() {
399
2514
  super();
400
2515
  this.shadow = this.attachShadow({ mode: "open" });
@@ -405,16 +2520,21 @@ var LimeBundleElement = class extends HTMLElement {
405
2520
  }
406
2521
  disconnectedCallback() {
407
2522
  this.abortController?.abort();
408
- this.teardownImpression();
2523
+ this.teardownImpressions();
2524
+ this.teardownRenderers();
409
2525
  }
410
- teardownImpression() {
411
- this.impressionCleanup?.();
412
- this.impressionCleanup = null;
2526
+ teardownImpressions() {
2527
+ for (const cleanup of this.impressionCleanups) cleanup();
2528
+ this.impressionCleanups = [];
2529
+ }
2530
+ teardownRenderers() {
2531
+ for (const cleanup of this.renderCleanups) cleanup();
2532
+ this.renderCleanups = [];
413
2533
  }
414
2534
  attributeChangedCallback(name, oldValue, newValue) {
415
2535
  if (oldValue === newValue || !this.isConnected) return;
416
- if (name === "bundle-gid" || name === "shop-domain" || name === "storefront-token") {
417
- if (this.shopDomain && this.storefrontToken && this.bundleGid) {
2536
+ if (name === "bundle-gid" || name === "product-handle" || name === "shop-domain" || name === "storefront-token") {
2537
+ if (this.shopDomain && this.storefrontToken) {
418
2538
  this.fetchBundle();
419
2539
  }
420
2540
  }
@@ -428,6 +2548,9 @@ var LimeBundleElement = class extends HTMLElement {
428
2548
  get bundleGid() {
429
2549
  return this.getAttribute("bundle-gid") ?? "";
430
2550
  }
2551
+ get productHandleAttr() {
2552
+ return this.getAttribute("product-handle") ?? "";
2553
+ }
431
2554
  get appUrl() {
432
2555
  return this.getAttribute("app-url") ?? "";
433
2556
  }
@@ -435,9 +2558,9 @@ var LimeBundleElement = class extends HTMLElement {
435
2558
  return this.getAttribute("analytics") !== "false";
436
2559
  }
437
2560
  async fetchBundle() {
438
- if (!this.shopDomain || !this.storefrontToken || !this.bundleGid) {
2561
+ if (!this.shopDomain || !this.storefrontToken) {
439
2562
  this.renderError(
440
- "Missing required attributes: shop-domain, storefront-token, bundle-gid"
2563
+ "Missing required attributes: shop-domain, storefront-token"
441
2564
  );
442
2565
  return;
443
2566
  }
@@ -445,152 +2568,309 @@ var LimeBundleElement = class extends HTMLElement {
445
2568
  const controller = new AbortController();
446
2569
  this.abortController = controller;
447
2570
  this.renderLoading();
2571
+ const client = (0, import_core4.createStorefrontClient)({
2572
+ shopDomain: this.shopDomain,
2573
+ accessToken: this.storefrontToken
2574
+ });
448
2575
  try {
449
- const client = (0, import_core4.createStorefrontClient)({
450
- shopDomain: this.shopDomain,
451
- accessToken: this.storefrontToken
452
- });
453
- const [bundleData, cssData] = await Promise.all([
454
- client.query(
455
- import_core4.BUNDLE_METAOBJECT_QUERY,
456
- { id: this.bundleGid },
457
- { signal: controller.signal }
458
- ),
459
- client.query(
460
- import_core4.SHOP_CUSTOM_CSS_QUERY,
461
- void 0,
462
- { signal: controller.signal }
463
- ).catch(() => null)
464
- ]);
2576
+ let bundlePromise;
2577
+ let singleBundleMode = false;
2578
+ if (this.bundleGid) {
2579
+ singleBundleMode = true;
2580
+ bundlePromise = this.fetchSingleBundle(client, controller.signal);
2581
+ } else {
2582
+ const handle = resolveProductHandle(this.productHandleAttr);
2583
+ if (!handle) {
2584
+ this.teardownImpressions();
2585
+ this.renderError(
2586
+ "No bundle-gid or product-handle provided, and the current URL doesn't match /products/<handle>."
2587
+ );
2588
+ return;
2589
+ }
2590
+ bundlePromise = this.fetchProductBundles(
2591
+ client,
2592
+ controller.signal,
2593
+ handle
2594
+ );
2595
+ }
2596
+ const cssPromise = client.query(import_core4.SHOP_CUSTOM_CSS_QUERY, void 0, {
2597
+ signal: controller.signal
2598
+ }).catch(() => null);
2599
+ await bundlePromise;
465
2600
  if (controller.signal.aborted) return;
466
- if (!bundleData.metaobject) {
467
- this.bundle = null;
468
- this.teardownImpression();
2601
+ if (singleBundleMode && this.bundles.length === 0) {
2602
+ this.teardownImpressions();
469
2603
  this.renderError("Bundle not found");
470
2604
  return;
471
2605
  }
472
- this.bundle = (0, import_core4.parseMetaobjectBundle)(
473
- bundleData.metaobject.id,
474
- bundleData.metaobject.fields
475
- );
476
- if (!this.bundle) {
477
- this.teardownImpression();
478
- this.renderError("Bundle is not active or has expired");
479
- return;
480
- }
481
- if (cssData?.shop?.metafield?.value) {
482
- (0, import_core4.injectCustomCss)(this.shopDomain, cssData.shop.metafield.value);
2606
+ const css = await cssPromise;
2607
+ if (css?.shop?.metafield?.value) {
2608
+ (0, import_core4.injectCustomCss)(this.shopDomain, css.shop.metafield.value);
2609
+ const sanitized = (0, import_core4.sanitizeCustomCss)(css.shop.metafield.value);
2610
+ if (sanitized.ok) this.shopCustomCss = sanitized.css;
483
2611
  }
484
- this.renderBundle();
485
- this.setupImpression();
2612
+ await this.applyABVariants();
2613
+ this.renderBundles();
486
2614
  } catch (err) {
487
2615
  if (controller.signal.aborted) return;
488
- this.bundle = null;
489
- this.teardownImpression();
2616
+ this.bundles = [];
2617
+ this.teardownImpressions();
490
2618
  this.renderError(
491
2619
  err instanceof Error ? err.message : "Failed to load bundle"
492
2620
  );
493
2621
  }
494
2622
  }
495
2623
  /**
496
- * Dispatch add-to-cart for merchant handling. Returns true the widget
497
- * reports success optimistically. If the merchant's cart mutation fails,
498
- * they're responsible for surfacing that error in their own UI.
2624
+ * Resolve the visitor's A/B bucket for every bundle with an active test
2625
+ * and merge Variant B overrides where applicable. Runs in parallel; any
2626
+ * assignment failure logs internally but still renders Variant A (safe
2627
+ * default). The `getABTestAssignment` helper also persists the bucket
2628
+ * via a first-party cookie + POSTs to /api/ab-assign for server-side
2629
+ * analytics.
499
2630
  */
500
- dispatchAddToCart = (lines) => {
501
- this.dispatchEvent(
502
- new CustomEvent("lime-bundle:add-to-cart", {
503
- detail: { lines },
504
- bubbles: true,
505
- composed: true
2631
+ async applyABVariants() {
2632
+ if (!this.appUrl || this.bundles.length === 0) return;
2633
+ const results = await Promise.all(
2634
+ this.bundles.map(async (bundle) => {
2635
+ if (!bundle.abTestId || !bundle.abVariantB) return bundle;
2636
+ try {
2637
+ const assignment = await (0, import_core4.getABTestAssignment)(
2638
+ this.appUrl,
2639
+ this.shopDomain,
2640
+ bundle.abTestId,
2641
+ bundle.id
2642
+ );
2643
+ if (assignment?.variant === "B") {
2644
+ return (0, import_core4.applyABVariantB)(bundle);
2645
+ }
2646
+ } catch (err) {
2647
+ console.warn(
2648
+ `[lime-bundle] A/B assignment failed for bundle ${bundle.id}; falling back to Variant A.`,
2649
+ err
2650
+ );
2651
+ }
2652
+ return bundle;
506
2653
  })
507
2654
  );
508
- if (this.analyticsEnabled && this.appUrl && this.bundle) {
509
- const quantity = lines.reduce((sum, l) => sum + l.quantity, 0);
510
- const totalPrice = lines.reduce((sum, line) => {
511
- const product = this.bundle.products.find(
512
- (p) => p.variants.nodes.some((v) => v.id === line.merchandiseId)
513
- );
514
- const variant = product?.variants.nodes.find(
515
- (v) => v.id === line.merchandiseId
516
- );
517
- const price = variant ? parseFloat(variant.price.amount) : 0;
518
- return sum + price * line.quantity;
519
- }, 0);
520
- (0, import_core4.reportAddToCart)(
521
- { shopDomain: this.shopDomain, appUrl: this.appUrl },
522
- {
523
- bundleGid: this.bundleGid,
524
- bundleType: this.bundle.bundleType,
525
- productId: this.bundle.products[0]?.id ?? "",
526
- quantity,
527
- totalPrice: Math.round(totalPrice * 100) / 100
528
- }
529
- );
2655
+ this.bundles = results;
2656
+ }
2657
+ async fetchSingleBundle(client, signal) {
2658
+ const data = await client.query(
2659
+ import_core4.BUNDLE_METAOBJECT_QUERY,
2660
+ { id: this.bundleGid },
2661
+ { signal }
2662
+ );
2663
+ if (!data.metaobject) {
2664
+ this.bundles = [];
2665
+ return;
2666
+ }
2667
+ const parsed = (0, import_core4.parseMetaobjectBundle)(
2668
+ data.metaobject.id,
2669
+ data.metaobject.fields
2670
+ );
2671
+ this.bundles = parsed ? [parsed] : [];
2672
+ }
2673
+ async fetchProductBundles(client, signal, productHandle) {
2674
+ const data = await client.query(
2675
+ import_core4.BUNDLES_FOR_PRODUCT_QUERY,
2676
+ { handle: productHandle },
2677
+ { signal }
2678
+ );
2679
+ if (!data.product) {
2680
+ this.bundles = [];
2681
+ return;
2682
+ }
2683
+ const refs = data.product.metafield?.references?.nodes ?? [];
2684
+ const bundles = [];
2685
+ for (const ref of refs) {
2686
+ const parsed = (0, import_core4.parseMetaobjectBundle)(ref.id, ref.fields);
2687
+ if (parsed) bundles.push(parsed);
2688
+ }
2689
+ this.bundles = bundles;
2690
+ }
2691
+ /**
2692
+ * Dispatch add-to-cart with a cancelable event, then — unless a listener
2693
+ * called preventDefault — execute the default cart-and-checkout flow.
2694
+ *
2695
+ * `fire-and-forget` against `reportAddToCart` runs regardless so merchants
2696
+ * with BYO cart still get analytics.
2697
+ */
2698
+ handleAddToCart = async (bundle, lines) => {
2699
+ const ev = new CustomEvent("lime-bundle:add-to-cart", {
2700
+ detail: { lines },
2701
+ bubbles: true,
2702
+ composed: true,
2703
+ cancelable: true
2704
+ });
2705
+ const allowDefault = this.dispatchEvent(ev);
2706
+ this.reportAddToCartEvent(bundle, lines);
2707
+ if (allowDefault) {
2708
+ await this.defaultAddToCart(lines);
530
2709
  }
531
2710
  };
532
- renderBundle() {
533
- if (!this.bundle) return;
534
- const container = document.createElement("div");
535
- container.className = "lb-bundle";
536
- container.setAttribute("role", "region");
537
- container.setAttribute("aria-label", this.bundle.title);
538
- switch (this.bundle.bundleType) {
539
- case "fixed":
540
- renderFixedBundle(
541
- container,
542
- this.bundle,
543
- this.dispatchAddToCart
2711
+ /**
2712
+ * Default cart flow: Shopify's Storefront Cart API is tokenless, so we
2713
+ * don't need any additional scopes. Persist the cart ID in localStorage
2714
+ * so subsequent adds on the same browser session join the existing cart
2715
+ * instead of creating a new one every click.
2716
+ */
2717
+ async defaultAddToCart(lines) {
2718
+ if (typeof window === "undefined") return;
2719
+ const client = (0, import_core4.createStorefrontClient)({
2720
+ shopDomain: this.shopDomain,
2721
+ accessToken: this.storefrontToken
2722
+ });
2723
+ const storage = window.localStorage;
2724
+ const key = cartStorageKey(this.shopDomain);
2725
+ const existingCartId = storage?.getItem(key) ?? null;
2726
+ try {
2727
+ let checkoutUrl = null;
2728
+ if (existingCartId) {
2729
+ const res = await client.query(
2730
+ import_core4.CART_LINES_ADD_MUTATION,
2731
+ { cartId: existingCartId, lines }
544
2732
  );
545
- break;
546
- case "mix_match":
547
- renderMixMatchBundle(
548
- container,
549
- this.bundle,
550
- this.dispatchAddToCart
2733
+ const payload = res.cartLinesAdd;
2734
+ if (payload?.userErrors?.length) {
2735
+ storage?.removeItem(key);
2736
+ } else if (payload?.cart) {
2737
+ checkoutUrl = payload.cart.checkoutUrl;
2738
+ }
2739
+ }
2740
+ if (!checkoutUrl) {
2741
+ const res = await client.query(
2742
+ import_core4.CART_CREATE_MUTATION,
2743
+ { input: { lines } }
551
2744
  );
552
- break;
553
- case "volume":
554
- renderVolumeBundle(
555
- container,
556
- this.bundle,
557
- this.dispatchAddToCart
2745
+ const payload = res.cartCreate;
2746
+ if (payload?.cart) {
2747
+ storage?.setItem(key, payload.cart.id);
2748
+ checkoutUrl = payload.cart.checkoutUrl;
2749
+ }
2750
+ }
2751
+ if (checkoutUrl) {
2752
+ window.location.assign(checkoutUrl);
2753
+ } else {
2754
+ this.dispatchEvent(
2755
+ new CustomEvent("lime-bundle:error", {
2756
+ detail: { message: "Cart creation failed", code: "CART_ERROR" },
2757
+ bubbles: true,
2758
+ composed: true
2759
+ })
558
2760
  );
559
- break;
2761
+ }
2762
+ } catch (err) {
2763
+ this.dispatchEvent(
2764
+ new CustomEvent("lime-bundle:error", {
2765
+ detail: {
2766
+ message: err instanceof Error ? err.message : "Cart mutation failed",
2767
+ code: "CART_ERROR"
2768
+ },
2769
+ bubbles: true,
2770
+ composed: true
2771
+ })
2772
+ );
560
2773
  }
2774
+ }
2775
+ reportAddToCartEvent(bundle, lines) {
2776
+ if (!this.analyticsEnabled || !this.appUrl) return;
2777
+ const quantity = lines.reduce((sum, l) => sum + l.quantity, 0);
2778
+ const totalPrice = lines.reduce((sum, line) => {
2779
+ const product = bundle.products.find(
2780
+ (p) => p.variants.nodes.some((v) => v.id === line.merchandiseId)
2781
+ );
2782
+ const variant = product?.variants.nodes.find(
2783
+ (v) => v.id === line.merchandiseId
2784
+ );
2785
+ const price = variant ? parseFloat(variant.price.amount) : 0;
2786
+ return sum + price * line.quantity;
2787
+ }, 0);
2788
+ (0, import_core4.reportAddToCart)(
2789
+ { shopDomain: this.shopDomain, appUrl: this.appUrl },
2790
+ {
2791
+ bundleGid: bundle.id,
2792
+ bundleType: bundle.bundleType,
2793
+ productId: bundle.products[0]?.id ?? "",
2794
+ quantity,
2795
+ totalPrice: Math.round(totalPrice * 100) / 100
2796
+ }
2797
+ );
2798
+ }
2799
+ renderBundles() {
2800
+ this.teardownImpressions();
2801
+ this.teardownRenderers();
561
2802
  this.shadow.innerHTML = "";
562
2803
  const style = document.createElement("style");
563
- style.textContent = WIDGET_STYLES;
2804
+ style.textContent = [
2805
+ BUNDLE_BASE_CSS,
2806
+ BUNDLE_FIXED_CSS,
2807
+ BUNDLE_MIX_MATCH_CSS,
2808
+ BUNDLE_VOLUME_CSS
2809
+ ].join("\n");
564
2810
  this.shadow.appendChild(style);
565
- this.shadow.appendChild(container);
2811
+ if (this.shopCustomCss) {
2812
+ const customStyle = document.createElement("style");
2813
+ customStyle.setAttribute("data-lime-bundles", "shop-custom-css");
2814
+ customStyle.textContent = this.shopCustomCss;
2815
+ this.shadow.appendChild(customStyle);
2816
+ }
2817
+ for (const bundle of this.bundles) {
2818
+ const container = document.createElement("div");
2819
+ container.className = "lb-bundle-widget";
2820
+ container.setAttribute("role", "region");
2821
+ container.setAttribute("aria-label", bundle.title);
2822
+ container.setAttribute("data-bundle-type", bundle.bundleType);
2823
+ container.setAttribute("data-bundle-gid", bundle.id);
2824
+ (0, import_core5.applyWidgetConfigVars)(container, bundle.widgetConfig);
2825
+ const dispatch = (lines) => this.handleAddToCart(bundle, lines);
2826
+ const registerCleanup = (fn) => this.renderCleanups.push(fn);
2827
+ switch (bundle.bundleType) {
2828
+ case "fixed":
2829
+ renderFixedBundle(container, bundle, dispatch, registerCleanup);
2830
+ break;
2831
+ case "mix_match":
2832
+ renderMixMatchBundle(container, bundle, dispatch, registerCleanup);
2833
+ break;
2834
+ case "volume":
2835
+ renderVolumeBundle(container, bundle, dispatch, registerCleanup);
2836
+ break;
2837
+ }
2838
+ this.shadow.appendChild(container);
2839
+ this.setupImpressionFor(bundle, container);
2840
+ }
2841
+ const first = this.bundles[0];
566
2842
  this.dispatchEvent(
567
2843
  new CustomEvent("lime-bundle:loaded", {
568
2844
  detail: {
569
- bundleType: this.bundle.bundleType,
570
- title: this.bundle.title
2845
+ bundleCount: this.bundles.length,
2846
+ bundleTypes: this.bundles.map((b) => b.bundleType),
2847
+ // Legacy fields — meaningful only in single-bundle mode. Preserved
2848
+ // for merchants who attached listeners against the pre-1.0 shape.
2849
+ bundleType: first?.bundleType,
2850
+ title: first?.title
571
2851
  },
572
2852
  bubbles: true,
573
2853
  composed: true
574
2854
  })
575
2855
  );
576
2856
  }
577
- setupImpression() {
578
- if (!this.analyticsEnabled || !this.bundle || !this.appUrl) return;
579
- this.impressionCleanup?.();
580
- this.impressionCleanup = (0, import_core4.observeImpression)(this, () => {
2857
+ setupImpressionFor(bundle, element) {
2858
+ if (!this.analyticsEnabled || !this.appUrl) return;
2859
+ const cleanup = (0, import_core4.observeImpression)(element, () => {
581
2860
  (0, import_core4.reportImpression)(
582
2861
  { shopDomain: this.shopDomain, appUrl: this.appUrl },
583
2862
  {
584
- bundleGid: this.bundleGid,
585
- bundleType: this.bundle.bundleType
2863
+ bundleGid: bundle.id,
2864
+ bundleType: bundle.bundleType
586
2865
  }
587
2866
  );
588
2867
  });
2868
+ this.impressionCleanups.push(cleanup);
589
2869
  }
590
2870
  renderLoading() {
591
2871
  this.shadow.innerHTML = `
592
- <style>${WIDGET_STYLES}</style>
593
- <div class="lb-bundle lb-bundle--loading">
2872
+ <style>${BUNDLE_BASE_CSS}</style>
2873
+ <div class="lb-bundle-widget lb-bundle-widget--loading" aria-busy="true">
594
2874
  <div class="lb-skeleton lb-skeleton--title"></div>
595
2875
  <div class="lb-skeleton lb-skeleton--products"></div>
596
2876
  </div>
@@ -607,7 +2887,7 @@ var LimeBundleElement = class extends HTMLElement {
607
2887
  );
608
2888
  }
609
2889
  render() {
610
- this.shadow.innerHTML = `<style>${WIDGET_STYLES}</style>`;
2890
+ this.shadow.innerHTML = `<style>${BUNDLE_BASE_CSS}</style>`;
611
2891
  }
612
2892
  };
613
2893