@shop-on/theme-runtime 0.9.0 → 0.11.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (71) hide show
  1. package/dist/badge-tags.d.ts +1 -3
  2. package/dist/badge-tags.js +1 -2
  3. package/dist/bytes.d.ts +1 -3
  4. package/dist/bytes.js +1 -2
  5. package/dist/cart-note.d.ts +1 -3
  6. package/dist/cart-note.js +1 -2
  7. package/dist/color.d.ts +1 -3
  8. package/dist/color.js +1 -2
  9. package/dist/fonts.d.ts +7 -8
  10. package/dist/fonts.js +20 -9
  11. package/dist/index.d.ts +6 -7
  12. package/dist/index.js +2 -3
  13. package/dist/initials.d.ts +1 -3
  14. package/dist/initials.js +1 -2
  15. package/dist/json-ld-escape.d.ts +1 -3
  16. package/dist/json-ld-escape.js +1 -2
  17. package/dist/line-groups.d.ts +2 -4
  18. package/dist/line-groups.js +1 -2
  19. package/dist/line-item-attributes.d.ts +0 -2
  20. package/dist/line-item-attributes.js +1 -2
  21. package/dist/listing-filters.d.ts +7 -24
  22. package/dist/listing-filters.js +19 -39
  23. package/dist/listing-price.d.ts +1 -3
  24. package/dist/listing-price.js +1 -2
  25. package/dist/money.d.ts +1 -3
  26. package/dist/money.js +1 -2
  27. package/dist/parse-embed-url.d.ts +1 -3
  28. package/dist/parse-embed-url.js +1 -2
  29. package/dist/playable-video.d.ts +1 -3
  30. package/dist/playable-video.js +1 -2
  31. package/dist/product-href.d.ts +1 -3
  32. package/dist/product-href.js +1 -2
  33. package/dist/product-variants/build-availability-index.d.ts +1 -3
  34. package/dist/product-variants/build-availability-index.js +1 -2
  35. package/dist/product-variants/build-variant-state.d.ts +1 -3
  36. package/dist/product-variants/build-variant-state.js +1 -2
  37. package/dist/product-variants/find-closest-variant.d.ts +1 -3
  38. package/dist/product-variants/find-closest-variant.js +1 -2
  39. package/dist/product-variants/index.d.ts +2 -2
  40. package/dist/product-variants/index.js +1 -1
  41. package/dist/product-variants/is-default-single-variant.d.ts +1 -3
  42. package/dist/product-variants/is-default-single-variant.js +1 -2
  43. package/dist/product-variants/is-variant-selectable.d.ts +1 -3
  44. package/dist/product-variants/is-variant-selectable.js +1 -2
  45. package/dist/product-variants/resolve-selected-variant.d.ts +1 -3
  46. package/dist/product-variants/resolve-selected-variant.js +1 -2
  47. package/dist/product-variants/selection-key.d.ts +1 -3
  48. package/dist/product-variants/selection-key.js +1 -2
  49. package/dist/product-variants/stale-variant.d.ts +1 -3
  50. package/dist/product-variants/stale-variant.js +1 -2
  51. package/dist/product-variants/swatch-source.d.ts +4 -4
  52. package/dist/product-variants/swatch-source.js +9 -13
  53. package/dist/product-variants/types.d.ts +8 -17
  54. package/dist/product-variants/variant-price-range.d.ts +1 -3
  55. package/dist/product-variants/variant-price-range.js +1 -2
  56. package/dist/richtext.d.ts +1 -3
  57. package/dist/richtext.js +10 -10
  58. package/dist/sale.d.ts +1 -3
  59. package/dist/sale.js +1 -2
  60. package/dist/seo.d.ts +13 -5
  61. package/dist/seo.js +17 -5
  62. package/dist/strip-handoff-url.d.ts +1 -3
  63. package/dist/strip-handoff-url.js +1 -2
  64. package/dist/template-types.d.ts +1 -3
  65. package/dist/thumbhash.d.ts +1 -3
  66. package/dist/thumbhash.js +1 -2
  67. package/package.json +5 -7
  68. package/dist/cart-discounts.d.ts +0 -16
  69. package/dist/cart-discounts.js +0 -21
  70. package/dist/page-cursor.d.ts +0 -20
  71. package/dist/page-cursor.js +0 -24
@@ -1,4 +1,4 @@
1
- //#region src/product-variants/build-availability-index.ts
1
+ // src/product-variants/build-availability-index.ts
2
2
  function buildAvailabilityIndex(options, variants) {
3
3
  const index = /* @__PURE__ */ new Map();
4
4
  for (const option of options) {
@@ -21,5 +21,4 @@ function buildAvailabilityIndex(options, variants) {
21
21
  }
22
22
  return index;
23
23
  }
24
- //#endregion
25
24
  export { buildAvailabilityIndex };
@@ -1,9 +1,7 @@
1
1
  import { ProductOption, ProductVariant, VariantState } from "./types.js";
2
- //#region src/product-variants/build-variant-state.d.ts
3
2
  export type ProductForVariantState = {
4
3
  options: ProductOption[];
5
4
  variants: ProductVariant[];
6
5
  defaultVariant: ProductVariant;
7
6
  };
8
- export declare function buildVariantState(product: ProductForVariantState, urlVariantId: string | undefined): VariantState;
9
- //#endregion
7
+ export declare function buildVariantState(product: ProductForVariantState, urlVariantId: string | undefined): VariantState;
@@ -1,6 +1,6 @@
1
1
  import { buildAvailabilityIndex } from "./build-availability-index.js";
2
2
  import { resolveSelectedVariant } from "./resolve-selected-variant.js";
3
- //#region src/product-variants/build-variant-state.ts
3
+ // src/product-variants/build-variant-state.ts
4
4
  function buildVariantState(product, urlVariantId) {
5
5
  const { selected, wasInvalidId } = resolveSelectedVariant(product.variants, product.defaultVariant, urlVariantId);
6
6
  const availability = buildAvailabilityIndex(product.options, product.variants);
@@ -12,5 +12,4 @@ function buildVariantState(product, urlVariantId) {
12
12
  wasInvalidId
13
13
  };
14
14
  }
15
- //#endregion
16
15
  export { buildVariantState };
@@ -1,4 +1,2 @@
1
1
  import { ProductVariant, SelectedOption } from "./types.js";
2
- //#region src/product-variants/find-closest-variant.d.ts
3
- export declare function findClosestVariant(clickedOptionName: string, clickedValue: string, currentSelection: readonly SelectedOption[], variants: readonly ProductVariant[]): ProductVariant | null;
4
- //#endregion
2
+ export declare function findClosestVariant(clickedOptionName: string, clickedValue: string, currentSelection: readonly SelectedOption[], variants: readonly ProductVariant[]): ProductVariant | null;
@@ -1,4 +1,4 @@
1
- //#region src/product-variants/find-closest-variant.ts
1
+ // src/product-variants/find-closest-variant.ts
2
2
  function findClosestVariant(clickedOptionName, clickedValue, currentSelection, variants) {
3
3
  let best = null;
4
4
  let bestScore = -1;
@@ -22,5 +22,4 @@ function optionMapOf(variant) {
22
22
  for (const sel of variant.selectedOptions) m.set(sel.name, sel.value);
23
23
  return m;
24
24
  }
25
- //#endregion
26
25
  export { findClosestVariant };
@@ -1,4 +1,4 @@
1
- import { LinkedMetafieldRef, LinkedMetaobject, LinkedMetaobjectField, OptionAvailability, ProductOption, ProductOptionValue, ProductVariant, SelectedOption, SwatchVariant, VariantState } from "./types.js";
1
+ import { OptionAvailability, OptionSwatch, ProductOption, ProductOptionValue, ProductVariant, SelectedOption, SwatchVariant, VariantState } from "./types.js";
2
2
  import { buildAvailabilityIndex } from "./build-availability-index.js";
3
3
  import { ProductForVariantState, buildVariantState } from "./build-variant-state.js";
4
4
  import { findClosestVariant } from "./find-closest-variant.js";
@@ -9,4 +9,4 @@ import { selectionKey } from "./selection-key.js";
9
9
  import { staleVariantFlag } from "./stale-variant.js";
10
10
  import { SwatchSource, isSwatchOption, swatchSource } from "./swatch-source.js";
11
11
  import { VariantPriceRange, variantPriceRange } from "./variant-price-range.js";
12
- export { type LinkedMetafieldRef, type LinkedMetaobject, type LinkedMetaobjectField, type OptionAvailability, type ProductForVariantState, type ProductOption, type ProductOptionValue, type ProductVariant, type ResolvedVariant, type SelectedOption, type SwatchSource, type SwatchVariant, type VariantPriceRange, type VariantState, buildAvailabilityIndex, buildVariantState, findClosestVariant, isDefaultSingleVariant, isSwatchOption, isVariantSelectable, resolveSelectedVariant, selectionKey, staleVariantFlag, swatchSource, variantPriceRange };
12
+ export { type OptionAvailability, type OptionSwatch, type ProductForVariantState, type ProductOption, type ProductOptionValue, type ProductVariant, type ResolvedVariant, type SelectedOption, type SwatchSource, type SwatchVariant, type VariantPriceRange, type VariantState, buildAvailabilityIndex, buildVariantState, findClosestVariant, isDefaultSingleVariant, isSwatchOption, isVariantSelectable, resolveSelectedVariant, selectionKey, staleVariantFlag, swatchSource, variantPriceRange };
@@ -1,9 +1,9 @@
1
1
  import { buildAvailabilityIndex } from "./build-availability-index.js";
2
- import { resolveSelectedVariant } from "./resolve-selected-variant.js";
3
2
  import { buildVariantState } from "./build-variant-state.js";
4
3
  import { findClosestVariant } from "./find-closest-variant.js";
5
4
  import { isDefaultSingleVariant } from "./is-default-single-variant.js";
6
5
  import { isVariantSelectable } from "./is-variant-selectable.js";
6
+ import { resolveSelectedVariant } from "./resolve-selected-variant.js";
7
7
  import { selectionKey } from "./selection-key.js";
8
8
  import { staleVariantFlag } from "./stale-variant.js";
9
9
  import { isSwatchOption, swatchSource } from "./swatch-source.js";
@@ -1,4 +1,2 @@
1
1
  import { ProductOption } from "./types.js";
2
- //#region src/product-variants/is-default-single-variant.d.ts
3
- export declare function isDefaultSingleVariant(options: readonly ProductOption[]): boolean;
4
- //#endregion
2
+ export declare function isDefaultSingleVariant(options: readonly ProductOption[]): boolean;
@@ -1,8 +1,7 @@
1
- //#region src/product-variants/is-default-single-variant.ts
1
+ // src/product-variants/is-default-single-variant.ts
2
2
  function isDefaultSingleVariant(options) {
3
3
  if (options.length === 0) return true;
4
4
  if (options.length === 1 && options[0].values.length <= 1) return true;
5
5
  return false;
6
6
  }
7
- //#endregion
8
7
  export { isDefaultSingleVariant };
@@ -1,4 +1,2 @@
1
1
  import { OptionAvailability, SelectedOption } from "./types.js";
2
- //#region src/product-variants/is-variant-selectable.d.ts
3
- export declare function isVariantSelectable(candidateOptionName: string, candidateValue: string, currentSelection: readonly SelectedOption[], availability: OptionAvailability): boolean;
4
- //#endregion
2
+ export declare function isVariantSelectable(candidateOptionName: string, candidateValue: string, currentSelection: readonly SelectedOption[], availability: OptionAvailability): boolean;
@@ -1,4 +1,4 @@
1
- //#region src/product-variants/is-variant-selectable.ts
1
+ // src/product-variants/is-variant-selectable.ts
2
2
  function isVariantSelectable(candidateOptionName, candidateValue, currentSelection, availability) {
3
3
  const candidateSet = availability.get(candidateOptionName)?.get(candidateValue);
4
4
  if (!candidateSet || candidateSet.size === 0) return false;
@@ -18,5 +18,4 @@ function intersect(a, b) {
18
18
  for (const v of small) if (large.has(v)) out.add(v);
19
19
  return out;
20
20
  }
21
- //#endregion
22
21
  export { isVariantSelectable };
@@ -1,8 +1,6 @@
1
1
  import { ProductVariant } from "./types.js";
2
- //#region src/product-variants/resolve-selected-variant.d.ts
3
2
  export type ResolvedVariant = {
4
3
  selected: ProductVariant;
5
4
  wasInvalidId: boolean;
6
5
  };
7
- export declare function resolveSelectedVariant(variants: readonly ProductVariant[], defaultVariant: ProductVariant, urlVariantId: string | undefined): ResolvedVariant;
8
- //#endregion
6
+ export declare function resolveSelectedVariant(variants: readonly ProductVariant[], defaultVariant: ProductVariant, urlVariantId: string | undefined): ResolvedVariant;
@@ -1,4 +1,4 @@
1
- //#region src/product-variants/resolve-selected-variant.ts
1
+ // src/product-variants/resolve-selected-variant.ts
2
2
  function resolveSelectedVariant(variants, defaultVariant, urlVariantId) {
3
3
  if (!urlVariantId) return {
4
4
  selected: defaultVariant,
@@ -14,5 +14,4 @@ function resolveSelectedVariant(variants, defaultVariant, urlVariantId) {
14
14
  wasInvalidId: true
15
15
  };
16
16
  }
17
- //#endregion
18
17
  export { resolveSelectedVariant };
@@ -1,4 +1,2 @@
1
1
  import { ProductOption, SelectedOption } from "./types.js";
2
- //#region src/product-variants/selection-key.d.ts
3
- export declare function selectionKey(selected: readonly SelectedOption[], options: readonly ProductOption[]): string;
4
- //#endregion
2
+ export declare function selectionKey(selected: readonly SelectedOption[], options: readonly ProductOption[]): string;
@@ -1,7 +1,6 @@
1
- //#region src/product-variants/selection-key.ts
1
+ // src/product-variants/selection-key.ts
2
2
  function selectionKey(selected, options) {
3
3
  const order = new Map(options.map((o) => [o.name, o.position]));
4
4
  return [...selected].sort((a, b) => (order.get(a.name) ?? 0) - (order.get(b.name) ?? 0)).map((s) => `${s.name}=${s.value}`).join("|");
5
5
  }
6
- //#endregion
7
6
  export { selectionKey };
@@ -1,9 +1,7 @@
1
1
  import { TemplateJSON } from "../template-types.js";
2
- //#region src/product-variants/stale-variant.d.ts
3
2
  /** The product page's flag for a `?variant=` that named no variant: spread
4
3
  * onto the template a theme returns, and the shared PDP route redirects to the
5
4
  * URL without it. Nothing when the param was absent or matched. */
6
5
  export declare function staleVariantFlag(state: {
7
6
  wasInvalidId: boolean;
8
- } | null | undefined): Pick<TemplateJSON, "staleVariant">;
9
- //#endregion
7
+ } | null | undefined): Pick<TemplateJSON, "staleVariant">;
@@ -1,9 +1,8 @@
1
- //#region src/product-variants/stale-variant.ts
1
+ // src/product-variants/stale-variant.ts
2
2
  /** The product page's flag for a `?variant=` that named no variant: spread
3
3
  * onto the template a theme returns, and the shared PDP route redirects to the
4
4
  * URL without it. Nothing when the param was absent or matched. */
5
5
  function staleVariantFlag(state) {
6
6
  return state?.wasInvalidId ? { staleVariant: true } : {};
7
7
  }
8
- //#endregion
9
8
  export { staleVariantFlag };
@@ -1,5 +1,4 @@
1
1
  import { ProductOption, ProductOptionValue } from "./types.js";
2
- //#region src/product-variants/swatch-source.d.ts
3
2
  export type SwatchSource = {
4
3
  kind: "color";
5
4
  hex: string;
@@ -7,6 +6,7 @@ export type SwatchSource = {
7
6
  kind: "image";
8
7
  url: string;
9
8
  };
10
- export declare function swatchSource(option: ProductOption, value: ProductOptionValue): SwatchSource | null;
11
- export declare function isSwatchOption(option: ProductOption): boolean;
12
- //#endregion
9
+ export declare function swatchSource(value: ProductOptionValue): SwatchSource | null;
10
+ /** Whether an option draws as swatches: any of its values is linked to an
11
+ * entry a buyer may see. */
12
+ export declare function isSwatchOption(option: ProductOption): boolean;
@@ -1,22 +1,18 @@
1
- //#region src/product-variants/swatch-source.ts
2
- function swatchSource(option, value) {
3
- if (!isSwatchOption(option)) return null;
4
- const meta = value.linkedMetaobject;
5
- if (!meta) return null;
6
- const imageField = meta.fields.find((f) => f.key === "image");
7
- if (imageField?.imageUrl) return {
1
+ // src/product-variants/swatch-source.ts
2
+ function swatchSource(value) {
3
+ if (value.swatch?.image) return {
8
4
  kind: "image",
9
- url: imageField.imageUrl
5
+ url: value.swatch.image
10
6
  };
11
- const colorField = meta.fields.find((f) => f.key === "color");
12
- if (colorField?.value) return {
7
+ if (value.swatch?.color) return {
13
8
  kind: "color",
14
- hex: colorField.value
9
+ hex: value.swatch.color
15
10
  };
16
11
  return null;
17
12
  }
13
+ /** Whether an option draws as swatches: any of its values is linked to an
14
+ * entry a buyer may see. */
18
15
  function isSwatchOption(option) {
19
- return option.linkedMetafield?.namespace === "shopon" && option.linkedMetafield.key === "color_pattern";
16
+ return option.values.some((value) => value.swatch !== null);
20
17
  }
21
- //#endregion
22
18
  export { isSwatchOption, swatchSource };
@@ -1,24 +1,17 @@
1
1
  import { Money } from "../money.js";
2
- //#region src/product-variants/types.d.ts
3
- export type LinkedMetafieldRef = {
4
- namespace: string;
5
- key: string;
6
- };
7
- export type LinkedMetaobjectField = {
8
- key: string;
9
- value: string | null;
10
- imageUrl?: string | null;
11
- };
12
- export type LinkedMetaobject = {
13
- id: string;
14
- fields: LinkedMetaobjectField[];
2
+ /** How an option value's swatch draws, from the entry the value is linked to:
3
+ * its colour (a CSS colour) and its image (a URL at swatch size). Null on a
4
+ * value no entry of a storefront-visible type is linked to. */
5
+ export type OptionSwatch = {
6
+ color: string | null;
7
+ image: string | null;
15
8
  };
16
9
  export type ProductOptionValue = {
17
10
  id: string;
18
11
  name: string;
19
12
  position: number;
20
13
  hasVariants: boolean;
21
- linkedMetaobject: LinkedMetaobject | null;
14
+ swatch: OptionSwatch | null;
22
15
  firstSelectableVariant?: SwatchVariant | null;
23
16
  };
24
17
  export type SwatchVariant = Pick<ProductVariant, "id" | "availableForSale" | "sku" | "priceV2" | "compareAtV2" | "featuredMedia">;
@@ -26,7 +19,6 @@ export type ProductOption = {
26
19
  id: string;
27
20
  name: string;
28
21
  position: number;
29
- linkedMetafield: LinkedMetafieldRef | null;
30
22
  values: ProductOptionValue[];
31
23
  };
32
24
  export type SelectedOption = {
@@ -55,5 +47,4 @@ export type VariantState = {
55
47
  variants: ProductVariant[];
56
48
  availability: OptionAvailability;
57
49
  wasInvalidId: boolean;
58
- };
59
- //#endregion
50
+ };
@@ -1,5 +1,4 @@
1
1
  import { ProductVariant } from "./types.js";
2
- //#region src/product-variants/variant-price-range.d.ts
3
2
  /** Low/high variant price plus how many variants back it. Feeds the
4
3
  * `AggregateOffer` node in `ProductSchemaSource` / `<ProductJsonLd>`. */
5
4
  export type VariantPriceRange = {
@@ -23,5 +22,4 @@ export type VariantPriceRange = {
23
22
  * Currency is deliberately NOT read here: the caller already has the product's
24
23
  * currency and variants of one product cannot be priced in different ones.
25
24
  */
26
- export declare function variantPriceRange(variants: ProductVariant[] | undefined | null): VariantPriceRange | null;
27
- //#endregion
25
+ export declare function variantPriceRange(variants: ProductVariant[] | undefined | null): VariantPriceRange | null;
@@ -1,4 +1,4 @@
1
- //#region src/product-variants/variant-price-range.ts
1
+ // src/product-variants/variant-price-range.ts
2
2
  /**
3
3
  * The price spread across a product's purchasable variants.
4
4
  *
@@ -34,5 +34,4 @@ function variantPriceRange(variants) {
34
34
  offerCount: prices.length
35
35
  };
36
36
  }
37
- //#endregion
38
37
  export { variantPriceRange };
@@ -1,3 +1 @@
1
- //#region src/richtext.d.ts
2
- export declare function serializeRichText(value: string): string | null;
3
- //#endregion
1
+ export declare function serializeRichText(root: unknown): string | null;
package/dist/richtext.js CHANGED
@@ -1,5 +1,5 @@
1
1
  import { escapeInertHtmlText } from "@shop-on/theme-contract";
2
- //#region src/richtext.ts
2
+ // src/richtext.ts
3
3
  const MAX_LENGTH = 1e5;
4
4
  const MAX_DEPTH = 40;
5
5
  const LINK_SCHEMES = /* @__PURE__ */ new Set([
@@ -11,18 +11,19 @@ const LINK_SCHEMES = /* @__PURE__ */ new Set([
11
11
  const IMG_SCHEMES = /* @__PURE__ */ new Set(["http", "https"]);
12
12
  const SCHEME = /^([a-z][a-z0-9+.-]*):/i;
13
13
  const HEX = /^#[0-9a-fA-F]{3,8}$/;
14
- function serializeRichText(value) {
15
- if (typeof value !== "string" || value.length > MAX_LENGTH) return null;
16
- let root;
17
- try {
18
- root = JSON.parse(value);
19
- } catch {
20
- return null;
21
- }
14
+ function serializeRichText(root) {
22
15
  if (!isNode(root) || root.type !== "root") return null;
23
16
  const html = renderChildren(root.children, renderBlock, 1);
17
+ if (html === null || jsonLength(root) > MAX_LENGTH) return null;
24
18
  return html ? html : null;
25
19
  }
20
+ function jsonLength(value) {
21
+ try {
22
+ return JSON.stringify(value).length;
23
+ } catch {
24
+ return Number.POSITIVE_INFINITY;
25
+ }
26
+ }
26
27
  function isNode(value) {
27
28
  return typeof value === "object" && value !== null && !Array.isArray(value);
28
29
  }
@@ -141,5 +142,4 @@ function escapeText(value) {
141
142
  function escapeAttr(value) {
142
143
  return escapeText(value).replace(/"/g, "&quot;");
143
144
  }
144
- //#endregion
145
145
  export { serializeRichText };
package/dist/sale.d.ts CHANGED
@@ -1,5 +1,3 @@
1
1
  import { Money } from "./money.js";
2
- //#region src/sale.d.ts
3
2
  export declare function isOnSale(price: Money, compareAt: Money | null | undefined): compareAt is Money;
4
- export declare function savePercent(price: Money, compareAt: Money | null | undefined): number;
5
- //#endregion
3
+ export declare function savePercent(price: Money, compareAt: Money | null | undefined): number;
package/dist/sale.js CHANGED
@@ -1,4 +1,4 @@
1
- //#region src/sale.ts
1
+ // src/sale.ts
2
2
  function isOnSale(price, compareAt) {
3
3
  return compareAt != null && compareAt.amount > price.amount;
4
4
  }
@@ -6,5 +6,4 @@ function savePercent(price, compareAt) {
6
6
  if (!isOnSale(price, compareAt)) return 0;
7
7
  return Math.round((1 - price.amount / compareAt.amount) * 100);
8
8
  }
9
- //#endregion
10
9
  export { isOnSale, savePercent };
package/dist/seo.d.ts CHANGED
@@ -1,4 +1,3 @@
1
- //#region src/seo.d.ts
2
1
  /**
3
2
  * Hard cap for every SEO description the storefront emits — the `<meta
4
3
  * name="description">` / `og:description` / `twitter:description` trio AND the
@@ -21,14 +20,24 @@ export declare function truncateSeoDescription(text: string | null | undefined):
21
20
  * TanStack gives a directory INDEX route a `match.pathname` with a trailing
22
21
  * slash — `/collections/` for the route served at `/collections`. Feeding that
23
22
  * straight into a canonical produced a self-reference pointing at a URL that
24
- * 307s back to the page declaring it, and it disagreed with the Rails sitemap,
25
- * which emits the slash-less form. Three producers of one URL have to agree or
23
+ * 307s back to the page declaring it, and it disagreed with the sitemap, which
24
+ * emits the slash-less form. Three producers of one URL have to agree or
26
25
  * Search Console reports the cluster as broken.
27
26
  *
28
27
  * The root is the one path that keeps its slash: `/` is the URL, and `""`
29
28
  * would resolve to whatever the crawler was looking at.
30
29
  */
31
30
  export declare function canonicalPath(path: string): string;
31
+ /**
32
+ * A page's absolute URL in `locale`: `path` (locale-less, with any query) on
33
+ * `origin`, unprefixed in the shop's primary language and under
34
+ * `/{locale}` otherwise, where the home page is `/en`, never `/en/` (a
35
+ * query rides on it: `/en?page=2`). The one rule for a localised URL that
36
+ * a crawler compares: the head's hreflang links (`HreflangLinks`) and the
37
+ * sitemap's (`@shop-on/theme-server/seo-documents`) name every page by it,
38
+ * and Search Console reports a cluster whose two copies differ as broken.
39
+ */
40
+ export declare function localizedUrl(origin: string, path: string, locale: string, primaryLocale: string): string;
32
41
  export interface BuildSeoHeadArgs {
33
42
  /** Page title override from `seo.title` (may be empty/undefined). */
34
43
  seoTitle?: string | null;
@@ -93,5 +102,4 @@ export declare function isNarrowedListing(state: {
93
102
  /** The listing's default ordering. An explicit `?sort=` naming it produces a
94
103
  * page byte-identical to the bare listing — which the sort control emits
95
104
  * whenever a buyer re-picks the default — so it must not count as narrowing. */
96
- defaultSort?: string): boolean;
97
- //#endregion
105
+ defaultSort?: string): boolean;
package/dist/seo.js CHANGED
@@ -1,4 +1,4 @@
1
- //#region src/seo.ts
1
+ // src/seo.ts
2
2
  /**
3
3
  * Hard cap for every SEO description the storefront emits — the `<meta
4
4
  * name="description">` / `og:description` / `twitter:description` trio AND the
@@ -23,8 +23,8 @@ function truncateSeoDescription(text) {
23
23
  * TanStack gives a directory INDEX route a `match.pathname` with a trailing
24
24
  * slash — `/collections/` for the route served at `/collections`. Feeding that
25
25
  * straight into a canonical produced a self-reference pointing at a URL that
26
- * 307s back to the page declaring it, and it disagreed with the Rails sitemap,
27
- * which emits the slash-less form. Three producers of one URL have to agree or
26
+ * 307s back to the page declaring it, and it disagreed with the sitemap, which
27
+ * emits the slash-less form. Three producers of one URL have to agree or
28
28
  * Search Console reports the cluster as broken.
29
29
  *
30
30
  * The root is the one path that keeps its slash: `/` is the URL, and `""`
@@ -34,6 +34,19 @@ function canonicalPath(path) {
34
34
  if (!path) return "/";
35
35
  return path.replace(/\/+$/, "") || "/";
36
36
  }
37
+ /**
38
+ * A page's absolute URL in `locale`: `path` (locale-less, with any query) on
39
+ * `origin`, unprefixed in the shop's primary language and under
40
+ * `/{locale}` otherwise, where the home page is `/en`, never `/en/` (a
41
+ * query rides on it: `/en?page=2`). The one rule for a localised URL that
42
+ * a crawler compares: the head's hreflang links (`HreflangLinks`) and the
43
+ * sitemap's (`@shop-on/theme-server/seo-documents`) name every page by it,
44
+ * and Search Console reports a cluster whose two copies differ as broken.
45
+ */
46
+ function localizedUrl(origin, path, locale, primaryLocale) {
47
+ if (locale === primaryLocale) return `${origin}${path}`;
48
+ return path === "/" || path.startsWith("/?") ? `${origin}/${locale}${path.slice(1)}` : `${origin}/${locale}${path}`;
49
+ }
37
50
  function buildSeoHead(args) {
38
51
  const { seoTitle, fallbackTitle, seoDescription, fallbackDescription, path, origin, ogType = "website", imageUrl, siteName } = args;
39
52
  const baseTitle = (seoTitle?.trim() || fallbackTitle).trim();
@@ -115,5 +128,4 @@ function isNarrowedListing(state, defaultSort) {
115
128
  if (state.price_min || state.price_max) return true;
116
129
  return Object.values(state.filters).some((values) => values.length > 0);
117
130
  }
118
- //#endregion
119
- export { SEO_DESCRIPTION_MAX_LENGTH, buildSeoHead, canonicalPath, isNarrowedListing, truncateSeoDescription };
131
+ export { SEO_DESCRIPTION_MAX_LENGTH, buildSeoHead, canonicalPath, isNarrowedListing, localizedUrl, truncateSeoDescription };
@@ -1,3 +1 @@
1
- //#region src/strip-handoff-url.d.ts
2
- export declare function stripPostAuthParams(pathname: string, searchStr: string): string;
3
- //#endregion
1
+ export declare function stripPostAuthParams(pathname: string, searchStr: string): string;
@@ -1,4 +1,4 @@
1
- //#region src/strip-handoff-url.ts
1
+ // src/strip-handoff-url.ts
2
2
  function stripPostAuthParams(pathname, searchStr) {
3
3
  const params = new URLSearchParams(searchStr);
4
4
  params.delete("customer_handoff");
@@ -7,5 +7,4 @@ function stripPostAuthParams(pathname, searchStr) {
7
7
  const qs = params.toString();
8
8
  return pathname + (qs ? `?${qs}` : "");
9
9
  }
10
- //#endregion
11
10
  export { stripPostAuthParams };
@@ -1,5 +1,4 @@
1
1
  import { TemplateBlock, TemplateSection } from "@shop-on/theme-contract";
2
- //#region src/template-types.d.ts
3
2
  export type BlockInstance = TemplateBlock;
4
3
  export interface SectionGroupConfig {
5
4
  sections: Record<string, TemplateSection>;
@@ -177,5 +176,4 @@ export interface TemplateJSON {
177
176
  google: string | null;
178
177
  bing: string | null;
179
178
  };
180
- }
181
- //#endregion
179
+ }
@@ -1,3 +1 @@
1
- //#region src/thumbhash.d.ts
2
- export declare function thumbhashDataUrl(thumbhash?: string | null): string | null;
3
- //#endregion
1
+ export declare function thumbhashDataUrl(thumbhash?: string | null): string | null;
package/dist/thumbhash.js CHANGED
@@ -1,5 +1,5 @@
1
1
  import { thumbHashToDataURL } from "thumbhash";
2
- //#region src/thumbhash.ts
2
+ // src/thumbhash.ts
3
3
  const dataUrlCache = /* @__PURE__ */ new Map();
4
4
  function decodeBase64(value) {
5
5
  if (typeof globalThis.atob !== "function") return null;
@@ -19,5 +19,4 @@ function thumbhashDataUrl(thumbhash) {
19
19
  dataUrlCache.set(thumbhash, dataUrl);
20
20
  return dataUrl;
21
21
  }
22
- //#endregion
23
22
  export { thumbhashDataUrl };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@shop-on/theme-runtime",
3
- "version": "0.9.0",
3
+ "version": "0.11.0",
4
4
  "license": "SEE LICENSE IN dist/LICENSE.md",
5
5
  "files": [
6
6
  "dist"
@@ -10,7 +10,6 @@
10
10
  ".": "./dist/index.js",
11
11
  "./badge-tags": "./dist/badge-tags.js",
12
12
  "./bytes": "./dist/bytes.js",
13
- "./cart-discounts": "./dist/cart-discounts.js",
14
13
  "./cart-note": "./dist/cart-note.js",
15
14
  "./color": "./dist/color.js",
16
15
  "./fonts": "./dist/fonts.js",
@@ -21,7 +20,6 @@
21
20
  "./listing-filters": "./dist/listing-filters.js",
22
21
  "./listing-price": "./dist/listing-price.js",
23
22
  "./money": "./dist/money.js",
24
- "./page-cursor": "./dist/page-cursor.js",
25
23
  "./parse-embed-url": "./dist/parse-embed-url.js",
26
24
  "./playable-video": "./dist/playable-video.js",
27
25
  "./product-href": "./dist/product-href.js",
@@ -35,13 +33,13 @@
35
33
  "./package.json": "./package.json"
36
34
  },
37
35
  "dependencies": {
38
- "thumbhash": "0.1.1",
39
- "@shop-on/theme-contract": "0.9.0"
36
+ "@shop-on/theme-contract": "0.11.0",
37
+ "thumbhash": "0.1.1"
40
38
  },
41
39
  "devDependencies": {
42
- "@types/node": "26.6.5",
40
+ "@types/node": "26.6.6",
43
41
  "typescript": "7.0.2",
44
- "vitest": "5.0.5"
42
+ "vitest": "5.1.0"
45
43
  },
46
44
  "scripts": {
47
45
  "check-types": "tsc --noEmit",
@@ -1,16 +0,0 @@
1
- import { Money } from "./money.js";
2
- //#region src/cart-discounts.d.ts
3
- export type CartDiscountAllocationLike = {
4
- targetLineItemId: string | null;
5
- amount: Money;
6
- };
7
- export type CartDiscountApplicationLike = {
8
- allocations: ReadonlyArray<CartDiscountAllocationLike>;
9
- };
10
- /** Flatten a cart's discount applications into a `lineId → total deduction`
11
- * map, for strike-through pricing on line rows. Order-level allocations
12
- * (`targetLineItemId === null`) are skipped — they come off the subtotal, not
13
- * a line. Several applications on one line are summed, keeping the first
14
- * allocation's `currencyCode`. */
15
- export declare function indexLineDiscounts(applications: ReadonlyArray<CartDiscountApplicationLike>): Map<string, Money>;
16
- //#endregion
@@ -1,21 +0,0 @@
1
- //#region src/cart-discounts.ts
2
- /** Flatten a cart's discount applications into a `lineId → total deduction`
3
- * map, for strike-through pricing on line rows. Order-level allocations
4
- * (`targetLineItemId === null`) are skipped — they come off the subtotal, not
5
- * a line. Several applications on one line are summed, keeping the first
6
- * allocation's `currencyCode`. */
7
- function indexLineDiscounts(applications) {
8
- const byLine = /* @__PURE__ */ new Map();
9
- for (const app of applications) for (const alloc of app.allocations) {
10
- if (alloc.targetLineItemId === null) continue;
11
- const prior = byLine.get(alloc.targetLineItemId);
12
- if (prior) byLine.set(alloc.targetLineItemId, {
13
- amount: prior.amount + alloc.amount.amount,
14
- currencyCode: prior.currencyCode
15
- });
16
- else byLine.set(alloc.targetLineItemId, alloc.amount);
17
- }
18
- return byLine;
19
- }
20
- //#endregion
21
- export { indexLineDiscounts };
@@ -1,20 +0,0 @@
1
- //#region src/page-cursor.d.ts
2
- /**
3
- * The `after` cursor that skips straight to page N of a listing.
4
- *
5
- * `?page=` is a number in the URL because that is what a buyer and a crawler can
6
- * both read, but the API speaks cursors — so the number is translated here
7
- * rather than by walking the connection a page at a time.
8
- *
9
- * INTERNAL-MONOREPO CONTRACT: apps/api runs graphql-ruby with NO custom
10
- * `cursor_encoder`, so connections use the built-in `Base64Encoder` and
11
- * `RelationConnection#cursor_for` emits `base64url(no padding)` of the item's
12
- * 1-based offset. Skipping `(page-1)*perPage` rows therefore means an `after` of
13
- * `base64url((page-1)*perPage)`. Regression check: `grep -r cursor_encoder
14
- * apps/api` must stay empty. Page 1 needs no cursor at all.
15
- *
16
- * `btoa` is a global in Node ≥ 18 and in browsers; the input is always a decimal
17
- * ASCII string, so it is safe.
18
- */
19
- export declare function pageCursor(page: number, perPage: number): string;
20
- //#endregion