@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,8 +1,6 @@
1
- //#region src/badge-tags.d.ts
2
1
  export type TagBadgeKind = "hot" | "new" | "sale";
3
2
  export type TagBadge = {
4
3
  kind: TagBadgeKind;
5
4
  label: string;
6
5
  };
7
- export declare function tagBadges(tags: readonly string[] | null | undefined): TagBadge[];
8
- //#endregion
6
+ export declare function tagBadges(tags: readonly string[] | null | undefined): TagBadge[];
@@ -1,4 +1,4 @@
1
- //#region src/badge-tags.ts
1
+ // src/badge-tags.ts
2
2
  const TAG_BADGE = /^tag__(hot|new|sale)_+(.+)$/i;
3
3
  function tagBadges(tags) {
4
4
  return (tags ?? []).flatMap((tag) => {
@@ -9,5 +9,4 @@ function tagBadges(tags) {
9
9
  }] : [];
10
10
  });
11
11
  }
12
- //#endregion
13
12
  export { tagBadges };
package/dist/bytes.d.ts CHANGED
@@ -1,4 +1,3 @@
1
- //#region src/bytes.d.ts
2
1
  /**
3
2
  * Binary (1024-step) sizes, one decimal, with a bare `.0` trimmed off.
4
3
  *
@@ -14,5 +13,4 @@
14
13
  * that already carried: 1048575 B is under 1 MiB, but at one decimal it is
15
14
  * "1024.0 KB" — a KB figure no one writes.
16
15
  */
17
- export declare function formatBytes(bytes: number): string;
18
- //#endregion
16
+ export declare function formatBytes(bytes: number): string;
package/dist/bytes.js CHANGED
@@ -1,4 +1,4 @@
1
- //#region src/bytes.ts
1
+ // src/bytes.ts
2
2
  const BYTE_UNITS = [
3
3
  "B",
4
4
  "KB",
@@ -29,5 +29,4 @@ function formatBytes(bytes) {
29
29
  }
30
30
  return `${value.toFixed(1).replace(/\.0$/, "")} ${BYTE_UNITS[unit]}`;
31
31
  }
32
- //#endregion
33
32
  export { formatBytes };
@@ -1,6 +1,4 @@
1
- //#region src/cart-note.d.ts
2
1
  /** The API's cap on a cart note, in characters. Past it, `cartNoteUpdate`
3
2
  * answers `VALIDATION_ERROR` on `field: "note"`; a note field mirrors it as
4
3
  * `maxLength` so the buyer never meets that error. */
5
- export declare const CART_NOTE_MAX_LENGTH = 1000;
6
- //#endregion
4
+ export declare const CART_NOTE_MAX_LENGTH = 1000;
package/dist/cart-note.js CHANGED
@@ -1,7 +1,6 @@
1
- //#region src/cart-note.ts
1
+ // src/cart-note.ts
2
2
  /** The API's cap on a cart note, in characters. Past it, `cartNoteUpdate`
3
3
  * answers `VALIDATION_ERROR` on `field: "note"`; a note field mirrors it as
4
4
  * `maxLength` so the buyer never meets that error. */
5
5
  const CART_NOTE_MAX_LENGTH = 1e3;
6
- //#endregion
7
6
  export { CART_NOTE_MAX_LENGTH };
package/dist/color.d.ts CHANGED
@@ -1,4 +1,3 @@
1
- //#region src/color.d.ts
2
1
  export interface Rgba {
3
2
  r: number;
4
3
  g: number;
@@ -30,5 +29,4 @@ export declare function rgbTriplet({ r, g, b }: Rgba): string;
30
29
  export declare function mix(color: Rgba, other: Rgba, weight: number): Rgba;
31
30
  /** A complete CSS color. Alpha is emitted only when it isn't opaque, which
32
31
  * keeps the common case readable in devtools. */
33
- export declare function toCss(color: Rgba): string;
34
- //#endregion
32
+ export declare function toCss(color: Rgba): string;
package/dist/color.js CHANGED
@@ -1,4 +1,4 @@
1
- //#region src/color.ts
1
+ // src/color.ts
2
2
  const HEX_RE = /^#([0-9a-f]{3,8})$/i;
3
3
  const RGB_RE = /^rgba?\(([^)]+)\)$/i;
4
4
  function clamp(value, min, max) {
@@ -141,5 +141,4 @@ function toCss(color) {
141
141
  const { r, g, b, a } = color;
142
142
  return a >= 1 ? `rgb(${r} ${g} ${b})` : `rgb(${r} ${g} ${b} / ${a})`;
143
143
  }
144
- //#endregion
145
144
  export { brightness, contrastRatio, mix, parseColor, rgbTriplet, shiftLightness, toCss };
package/dist/fonts.d.ts CHANGED
@@ -1,4 +1,3 @@
1
- //#region src/fonts.d.ts
2
1
  export type FontFormat = "woff2" | "woff" | "truetype" | "opentype";
3
2
  export type UploadedFace = {
4
3
  url: string;
@@ -9,7 +8,7 @@ export type UploadedFace = {
9
8
  style: "normal" | "italic";
10
9
  };
11
10
  export type UploadedFont = {
12
- /** The family's node id, exactly as the setting stores it. */
11
+ /** The family's wire id (`font_family_…`), exactly as the setting stores it. */
13
12
  id: string;
14
13
  faces: UploadedFace[];
15
14
  };
@@ -17,9 +16,9 @@ export type UploadedFont = {
17
16
  * What `font-family` names an uploaded family by, in the `@font-face` rules
18
17
  * and in a theme's font stack alike. Never the merchant's own name for it: a
19
18
  * family they called "Inter" must not merge into Google's. Null when the id is
20
- * not the bare token the API returns, and the theme then uses its fallback.
19
+ * not a font family's wire id, and the theme then uses its fallback.
21
20
  */
22
- export declare function uploadedFontFamily(nodeId: string): string | null;
21
+ export declare function uploadedFontFamily(id: string): string | null;
23
22
  /** The `format()` hint for a stored content type, or null for one that is not
24
23
  * a font the library accepts. */
25
24
  export declare function fontFormat(contentType: string): FontFormat | null;
@@ -65,11 +64,11 @@ export type FontSetting = {
65
64
  *
66
65
  * Null is "use the theme's fallback": nothing is picked, the value could not
67
66
  * be a family name, or the setting holds the id of a family that is deleted,
68
- * was never resolved, or is not the one beside it. An id is never `named`, in
69
- * either of its spellings (`nodeGid`), so it cannot reach a Google Fonts URL.
67
+ * was never resolved, or is not the one beside it. An id is never `named`, of
68
+ * whatever kind, a legacy node id included, so it cannot reach a Google Fonts
69
+ * URL (css2 refuses the whole stylesheet for one family it does not know).
70
70
  */
71
71
  export declare function fontSetting(settings: Record<string, unknown>, id: string): FontSetting | null;
72
72
  /** The uploaded families the named settings draw in, each once: what
73
73
  * `fontFaceCss` declares. */
74
- export declare function uploadedFonts(settings: Record<string, unknown>, ids: readonly string[]): UploadedFont[];
75
- //#endregion
74
+ export declare function uploadedFonts(settings: Record<string, unknown>, ids: readonly string[]): UploadedFont[];
package/dist/fonts.js CHANGED
@@ -1,13 +1,13 @@
1
- import { isNodeIdToken, nodeGid } from "@shop-on/theme-contract";
2
- //#region src/fonts.ts
1
+ import { isWireId } from "@shop-on/theme-contract";
2
+ // src/fonts.ts
3
3
  /**
4
4
  * What `font-family` names an uploaded family by, in the `@font-face` rules
5
5
  * and in a theme's font stack alike. Never the merchant's own name for it: a
6
6
  * family they called "Inter" must not merge into Google's. Null when the id is
7
- * not the bare token the API returns, and the theme then uses its fallback.
7
+ * not a font family's wire id, and the theme then uses its fallback.
8
8
  */
9
- function uploadedFontFamily(nodeId) {
10
- return isNodeIdToken(nodeId) ? `uploaded-${nodeId}` : null;
9
+ function uploadedFontFamily(id) {
10
+ return isWireId(id, "font_family") ? `uploaded-${id}` : null;
11
11
  }
12
12
  const FORMATS = /* @__PURE__ */ new Map([
13
13
  ["font/woff2", "woff2"],
@@ -88,6 +88,17 @@ function fontPreloads(targets) {
88
88
  return [...preloads.values()];
89
89
  }
90
90
  const NOT_A_FAMILY_NAME = /[<>"\\\n\r\f]/;
91
+ const LEGACY_GID = /^gid:\/\/[^/]+\/[^/]+\/\d+$/;
92
+ const LEGACY_TOKEN = /^[A-Za-z0-9_-]{16,512}$/;
93
+ function isLegacyNodeId(value) {
94
+ if (LEGACY_GID.test(value)) return true;
95
+ if (!LEGACY_TOKEN.test(value)) return false;
96
+ try {
97
+ return LEGACY_GID.test(atob(value.replace(/-/g, "+").replace(/_/g, "/")));
98
+ } catch {
99
+ return false;
100
+ }
101
+ }
91
102
  function isUploadedFont(value) {
92
103
  if (typeof value !== "object" || value === null) return false;
93
104
  const { id, faces } = value;
@@ -103,14 +114,15 @@ function isUploadedFont(value) {
103
114
  *
104
115
  * Null is "use the theme's fallback": nothing is picked, the value could not
105
116
  * be a family name, or the setting holds the id of a family that is deleted,
106
- * was never resolved, or is not the one beside it. An id is never `named`, in
107
- * either of its spellings (`nodeGid`), so it cannot reach a Google Fonts URL.
117
+ * was never resolved, or is not the one beside it. An id is never `named`, of
118
+ * whatever kind, a legacy node id included, so it cannot reach a Google Fonts
119
+ * URL (css2 refuses the whole stylesheet for one family it does not know).
108
120
  */
109
121
  function fontSetting(settings, id) {
110
122
  const raw = settings[id];
111
123
  const value = typeof raw === "string" ? raw.trim() : "";
112
124
  if (!value) return null;
113
- if (nodeGid(value) === null) return NOT_A_FAMILY_NAME.test(value) ? null : {
125
+ if (!isWireId(value)) return NOT_A_FAMILY_NAME.test(value) || isLegacyNodeId(value) ? null : {
114
126
  source: "named",
115
127
  family: value
116
128
  };
@@ -133,5 +145,4 @@ function uploadedFonts(settings, ids) {
133
145
  }
134
146
  return [...fonts.values()];
135
147
  }
136
- //#endregion
137
148
  export { fontFaceCss, fontFormat, fontPreloads, fontSetting, isRenderableFace, uploadedFontFamily, uploadedFonts };
package/dist/index.d.ts CHANGED
@@ -1,10 +1,9 @@
1
- import { Money, currencySymbol, formatMoney, formatMoneyWithCurrency } from "./money.js";
2
1
  import { initials } from "./initials.js";
3
2
  import { escapeForScriptTag } from "./json-ld-escape.js";
4
3
  import { defaultPriceMaxBound } from "./listing-price.js";
5
- import { pageCursor } from "./page-cursor.js";
4
+ import { Money, currencySymbol, formatMoney, formatMoneyWithCurrency } from "./money.js";
6
5
  import { Embed, EmbedKind, PlayerEmbed, embedBackgroundSrc, parseEmbedUrl } from "./parse-embed-url.js";
7
- import { LinkedMetafieldRef, LinkedMetaobject, LinkedMetaobjectField, OptionAvailability, ProductOption, ProductOptionValue, ProductVariant, SelectedOption, SwatchVariant, VariantState } from "./product-variants/types.js";
6
+ import { OptionAvailability, OptionSwatch, ProductOption, ProductOptionValue, ProductVariant, SelectedOption, SwatchVariant, VariantState } from "./product-variants/types.js";
8
7
  import { buildAvailabilityIndex } from "./product-variants/build-availability-index.js";
9
8
  import { ProductForVariantState, buildVariantState } from "./product-variants/build-variant-state.js";
10
9
  import { findClosestVariant } from "./product-variants/find-closest-variant.js";
@@ -12,14 +11,14 @@ import { isDefaultSingleVariant } from "./product-variants/is-default-single-var
12
11
  import { isVariantSelectable } from "./product-variants/is-variant-selectable.js";
13
12
  import { ResolvedVariant, resolveSelectedVariant } from "./product-variants/resolve-selected-variant.js";
14
13
  import { selectionKey } from "./product-variants/selection-key.js";
15
- import { ArticleSchemaSource, BlockInstance, BreadcrumbSchemaSource, OrganizationSchemaSource, ProductSchemaSource, ReturnPolicySchemaSource, SectionGroupConfig, TemplateJSON, TemplateSeoSource, WebsiteSchemaSource } from "./template-types.js";
14
+ import "./product-variants/index.js";
16
15
  import { staleVariantFlag } from "./product-variants/stale-variant.js";
17
16
  import { SwatchSource, isSwatchOption, swatchSource } from "./product-variants/swatch-source.js";
18
17
  import { VariantPriceRange, variantPriceRange } from "./product-variants/variant-price-range.js";
19
- import "./product-variants/index.js";
20
18
  import { productHref } from "./product-href.js";
21
19
  import { isOnSale, savePercent } from "./sale.js";
22
- import { BuildSeoHeadArgs, SEO_DESCRIPTION_MAX_LENGTH, SeoHead, buildSeoHead, canonicalPath, isNarrowedListing, truncateSeoDescription } from "./seo.js";
20
+ import { BuildSeoHeadArgs, SEO_DESCRIPTION_MAX_LENGTH, SeoHead, buildSeoHead, canonicalPath, isNarrowedListing, localizedUrl, truncateSeoDescription } from "./seo.js";
23
21
  import { stripPostAuthParams } from "./strip-handoff-url.js";
22
+ import { ArticleSchemaSource, BlockInstance, BreadcrumbSchemaSource, OrganizationSchemaSource, ProductSchemaSource, ReturnPolicySchemaSource, SectionGroupConfig, TemplateJSON, TemplateSeoSource, WebsiteSchemaSource } from "./template-types.js";
24
23
  import { thumbhashDataUrl } from "./thumbhash.js";
25
- export { ArticleSchemaSource, BlockInstance, BreadcrumbSchemaSource, BuildSeoHeadArgs, Embed, EmbedKind, type LinkedMetafieldRef, type LinkedMetaobject, type LinkedMetaobjectField, Money, type OptionAvailability, OrganizationSchemaSource, PlayerEmbed, type ProductForVariantState, type ProductOption, type ProductOptionValue, ProductSchemaSource, type ProductVariant, type ResolvedVariant, ReturnPolicySchemaSource, SEO_DESCRIPTION_MAX_LENGTH, SectionGroupConfig, type SelectedOption, SeoHead, type SwatchSource, type SwatchVariant, TemplateJSON, TemplateSeoSource, type VariantPriceRange, type VariantState, WebsiteSchemaSource, buildAvailabilityIndex, buildSeoHead, buildVariantState, canonicalPath, currencySymbol, defaultPriceMaxBound, embedBackgroundSrc, escapeForScriptTag, findClosestVariant, formatMoney, formatMoneyWithCurrency, initials, isDefaultSingleVariant, isNarrowedListing, isOnSale, isSwatchOption, isVariantSelectable, pageCursor, parseEmbedUrl, productHref, resolveSelectedVariant, savePercent, selectionKey, staleVariantFlag, stripPostAuthParams, swatchSource, thumbhashDataUrl, truncateSeoDescription, variantPriceRange };
24
+ export { ArticleSchemaSource, BlockInstance, BreadcrumbSchemaSource, BuildSeoHeadArgs, Embed, EmbedKind, Money, type OptionAvailability, type OptionSwatch, OrganizationSchemaSource, PlayerEmbed, type ProductForVariantState, type ProductOption, type ProductOptionValue, ProductSchemaSource, type ProductVariant, type ResolvedVariant, ReturnPolicySchemaSource, SEO_DESCRIPTION_MAX_LENGTH, SectionGroupConfig, type SelectedOption, SeoHead, type SwatchSource, type SwatchVariant, TemplateJSON, TemplateSeoSource, type VariantPriceRange, type VariantState, WebsiteSchemaSource, buildAvailabilityIndex, buildSeoHead, buildVariantState, canonicalPath, currencySymbol, defaultPriceMaxBound, embedBackgroundSrc, escapeForScriptTag, findClosestVariant, formatMoney, formatMoneyWithCurrency, initials, isDefaultSingleVariant, isNarrowedListing, isOnSale, isSwatchOption, isVariantSelectable, localizedUrl, parseEmbedUrl, productHref, resolveSelectedVariant, savePercent, selectionKey, staleVariantFlag, stripPostAuthParams, swatchSource, thumbhashDataUrl, truncateSeoDescription, variantPriceRange };
package/dist/index.js CHANGED
@@ -2,7 +2,6 @@ import { initials } from "./initials.js";
2
2
  import { escapeForScriptTag } from "./json-ld-escape.js";
3
3
  import { defaultPriceMaxBound } from "./listing-price.js";
4
4
  import { currencySymbol, formatMoney, formatMoneyWithCurrency } from "./money.js";
5
- import { pageCursor } from "./page-cursor.js";
6
5
  import { embedBackgroundSrc, parseEmbedUrl } from "./parse-embed-url.js";
7
6
  import { buildAvailabilityIndex } from "./product-variants/build-availability-index.js";
8
7
  import { resolveSelectedVariant } from "./product-variants/resolve-selected-variant.js";
@@ -16,7 +15,7 @@ import { isSwatchOption, swatchSource } from "./product-variants/swatch-source.j
16
15
  import { variantPriceRange } from "./product-variants/variant-price-range.js";
17
16
  import { productHref } from "./product-href.js";
18
17
  import { isOnSale, savePercent } from "./sale.js";
19
- import { SEO_DESCRIPTION_MAX_LENGTH, buildSeoHead, canonicalPath, isNarrowedListing, truncateSeoDescription } from "./seo.js";
18
+ import { SEO_DESCRIPTION_MAX_LENGTH, buildSeoHead, canonicalPath, isNarrowedListing, localizedUrl, truncateSeoDescription } from "./seo.js";
20
19
  import { stripPostAuthParams } from "./strip-handoff-url.js";
21
20
  import { thumbhashDataUrl } from "./thumbhash.js";
22
- export { SEO_DESCRIPTION_MAX_LENGTH, buildAvailabilityIndex, buildSeoHead, buildVariantState, canonicalPath, currencySymbol, defaultPriceMaxBound, embedBackgroundSrc, escapeForScriptTag, findClosestVariant, formatMoney, formatMoneyWithCurrency, initials, isDefaultSingleVariant, isNarrowedListing, isOnSale, isSwatchOption, isVariantSelectable, pageCursor, parseEmbedUrl, productHref, resolveSelectedVariant, savePercent, selectionKey, staleVariantFlag, stripPostAuthParams, swatchSource, thumbhashDataUrl, truncateSeoDescription, variantPriceRange };
21
+ export { SEO_DESCRIPTION_MAX_LENGTH, buildAvailabilityIndex, buildSeoHead, buildVariantState, canonicalPath, currencySymbol, defaultPriceMaxBound, embedBackgroundSrc, escapeForScriptTag, findClosestVariant, formatMoney, formatMoneyWithCurrency, initials, isDefaultSingleVariant, isNarrowedListing, isOnSale, isSwatchOption, isVariantSelectable, localizedUrl, parseEmbedUrl, productHref, resolveSelectedVariant, savePercent, selectionKey, staleVariantFlag, stripPostAuthParams, swatchSource, thumbhashDataUrl, truncateSeoDescription, variantPriceRange };
@@ -1,3 +1 @@
1
- //#region src/initials.d.ts
2
- export declare function initials(name: string): string;
3
- //#endregion
1
+ export declare function initials(name: string): string;
package/dist/initials.js CHANGED
@@ -1,9 +1,8 @@
1
- //#region src/initials.ts
1
+ // src/initials.ts
2
2
  function initials(name) {
3
3
  const words = name.trim().split(/\s+/).filter(Boolean);
4
4
  if (words.length === 0) return "?";
5
5
  if (words.length === 1) return words[0].slice(0, 1).toUpperCase();
6
6
  return (words[0].slice(0, 1) + words[words.length - 1].slice(0, 1)).toUpperCase();
7
7
  }
8
- //#endregion
9
8
  export { initials };
@@ -1,3 +1 @@
1
- //#region src/json-ld-escape.d.ts
2
- export declare function escapeForScriptTag(json: string): string;
3
- //#endregion
1
+ export declare function escapeForScriptTag(json: string): string;
@@ -1,6 +1,5 @@
1
- //#region src/json-ld-escape.ts
1
+ // src/json-ld-escape.ts
2
2
  function escapeForScriptTag(json) {
3
3
  return json.replace(/</g, "\\u003c").replace(/>/g, "\\u003e");
4
4
  }
5
- //#endregion
6
5
  export { escapeForScriptTag };
@@ -1,4 +1,3 @@
1
- //#region src/line-groups.d.ts
2
1
  export type GroupedLines<T, G> = Array<{
3
2
  kind: "line";
4
3
  line: T;
@@ -13,8 +12,7 @@ export type GroupedLines<T, G> = Array<{
13
12
  * a mixed ordering still lands every component under its bundle.
14
13
  */
15
14
  export declare function groupLines<T extends {
16
- lineGroup: {
15
+ lineGroup?: {
17
16
  id: string;
18
17
  } | null;
19
- }>(lines: readonly T[]): GroupedLines<T, NonNullable<T["lineGroup"]>>;
20
- //#endregion
18
+ }>(lines: readonly T[]): GroupedLines<T, NonNullable<T["lineGroup"]>>;
@@ -1,4 +1,4 @@
1
- //#region src/line-groups.ts
1
+ // src/line-groups.ts
2
2
  /**
3
3
  * Folds lines sharing a `lineGroup` into one entry placed where the group's
4
4
  * first line was. Lines of one group need not be adjacent: a page boundary or
@@ -31,5 +31,4 @@ function groupLines(lines) {
31
31
  }
32
32
  return out;
33
33
  }
34
- //#endregion
35
34
  export { groupLines };
@@ -1,4 +1,3 @@
1
- //#region src/line-item-attributes.d.ts
2
1
  /** One custom attribute on a line; `visible: false` keeps it from the buyer. */
3
2
  export type LineItemAttribute = {
4
3
  name: string;
@@ -40,5 +39,4 @@ export declare function collectGiftAttributes(recipient: GiftRecipient, labels:
40
39
  message: string;
41
40
  sendOn: string;
42
41
  }): LineItemAttribute[];
43
- //#endregion
44
42
  export {};
@@ -1,4 +1,4 @@
1
- //#region src/line-item-attributes.ts
1
+ // src/line-item-attributes.ts
2
2
  /** What one field puts on the line, or nothing — the rules a `properties[…]`
3
3
  * form post follows on Shopify: an unchecked checkbox is not in the post at all,
4
4
  * a blank value is dropped, and a key starting with `_` is kept from the buyer. */
@@ -78,5 +78,4 @@ function collectGiftAttributes(recipient, labels) {
78
78
  visible: true
79
79
  }]);
80
80
  }
81
- //#endregion
82
81
  export { GIFT_CARD_RECIPIENT_EMAIL_ATTRIBUTE, GIFT_CARD_RECIPIENT_MESSAGE_ATTRIBUTE, GIFT_CARD_RECIPIENT_NAME_ATTRIBUTE, GIFT_CARD_RECIPIENT_SEND_ON_ATTRIBUTE, collectGiftAttributes, createPropertyRegistry, propertyAttribute };
@@ -1,4 +1,3 @@
1
- //#region src/listing-filters.d.ts
2
1
  /** A raw route search dict, or the next one a control navigates to. */
3
2
  export type ListingSearch = Record<string, unknown>;
4
3
  /** The filter half of a parsed listing URL. Structurally a subset of the route
@@ -6,21 +5,9 @@ export type ListingSearch = Record<string, unknown>;
6
5
  export interface ListingFilters {
7
6
  price_min?: string;
8
7
  price_max?: string;
9
- /** `"<namespace>.<key>"` → the ticked values, in URL order. */
8
+ /** A facet's key → the ticked values, in URL order. */
10
9
  filters: Record<string, string[]>;
11
10
  }
12
- export interface ListingMetafieldFilter {
13
- namespace: string;
14
- key: string;
15
- values: string[];
16
- }
17
- /** The API's `CollectionProductFilterInput`, declared here so the runtime does
18
- * not depend on the server package. */
19
- export interface ListingFilterInput {
20
- metafields?: ListingMetafieldFilter[];
21
- priceMin?: string;
22
- priceMax?: string;
23
- }
24
11
  /** A route param as the string it was typed as, whatever TanStack coerced it
25
12
  * to. Loader-side only: re-stringifying inside a `validateSearch` is the 307
26
13
  * redirect loop. */
@@ -28,14 +15,14 @@ export declare function asParam(v: unknown): string | undefined;
28
15
  /** One `filter.*` param's value for a list of facet values. */
29
16
  export declare function joinFilterValues(values: readonly string[]): string;
30
17
  /** The URL param a facet writes to. */
31
- export declare function filterParam(namespace: string, key: string): string;
18
+ export declare function filterParam(key: string): string;
32
19
  /** A price as a buyer typed it, as a decimal string, or `undefined` when it is
33
20
  * not one. Grouping separators are stripped first: MNT has no minor unit, so a
34
21
  * comma in `1,000` is always grouping. A currency symbol at either end goes too,
35
22
  * since an input can carry the one it formatted itself with. */
36
23
  export declare function parsePriceInput(input: string): string | undefined;
37
- /** Every `filter.<namespace>.<key>` param plus the price bounds. Malformed
38
- * entries drop silently — a listing must render for any URL a buyer can type. */
24
+ /** Every `filter.<key>` param plus the price bounds. Malformed entries drop
25
+ * silently — a listing must render for any URL a buyer can type. */
39
26
  export declare function parseListingFilters(search: unknown): ListingFilters;
40
27
  /** The filter params in one stable order — facets by name with their values
41
28
  * sorted, then `price_min`, then `price_max` — so two URLs selecting the same
@@ -52,9 +39,9 @@ export declare function carryForward(prev: ListingSearch, drop: readonly string[
52
39
  export declare function urlValue(s: string): string | number | boolean;
53
40
  /** Tick or untick one facet value. An emptied facet leaves the URL, and the
54
41
  * page drops: a different result set has no page N. */
55
- export declare function toggleFilterValue(prev: ListingSearch, namespace: string, key: string, value: string): ListingSearch;
42
+ export declare function toggleFilterValue(prev: ListingSearch, key: string, value: string): ListingSearch;
56
43
  /** Untick every value of one facet. */
57
- export declare function removeFilter(prev: ListingSearch, namespace: string, key: string): ListingSearch;
44
+ export declare function removeFilter(prev: ListingSearch, key: string): ListingSearch;
58
45
  /** Replace the price bounds with what the buyer typed. A blank or invalid bound
59
46
  * drops its key. */
60
47
  export declare function setPriceRange(prev: ListingSearch, range: {
@@ -79,10 +66,6 @@ export declare function clearListingFilters(prev: ListingSearch, keep?: readonly
79
66
  export declare function narrowedListingPath(pathname: string, state: ListingFilters & {
80
67
  page?: number;
81
68
  }, sort?: string, defaultSort?: string): string;
82
- /** The API filter input, or `undefined` with nothing applied so the resolver
83
- * short-circuits to the unfiltered scope. */
84
- export declare function toFilterInput(state: ListingFilters): ListingFilterInput | undefined;
85
69
  /** Ticked values plus one for a price bound — price is one control whichever
86
70
  * end moved. */
87
- export declare function activeFilterCount(state: ListingFilters): number;
88
- //#endregion
71
+ export declare function activeFilterCount(state: ListingFilters): number;
@@ -1,7 +1,7 @@
1
- //#region src/listing-filters.ts
1
+ // src/listing-filters.ts
2
2
  const FILTER_PREFIX = "filter.";
3
- /** Non-negative decimal. Anything else is dropped: the API's `Decimal` scalar
4
- * raises on it, which would turn a typo'd URL into an error page. */
3
+ /** Non-negative decimal. Anything else is dropped: the listing's price bound
4
+ * refuses it, which would turn a typo'd URL into an error page. */
5
5
  const DECIMAL_RE = /^\d+(\.\d+)?$/;
6
6
  /** A decimal a facet or tag value may carry, sign included (`-5`). Only
7
7
  * `urlValue` reads it — a price bound is never negative. */
@@ -42,8 +42,8 @@ function joinFilterValues(values) {
42
42
  return values.map(escapeValue).join(",");
43
43
  }
44
44
  /** The URL param a facet writes to. */
45
- function filterParam(namespace, key) {
46
- return `${FILTER_PREFIX}${namespace}.${key}`;
45
+ function filterParam(key) {
46
+ return `${FILTER_PREFIX}${key}`;
47
47
  }
48
48
  function asDecimal(v) {
49
49
  const s = asParam(v);
@@ -58,20 +58,20 @@ function parsePriceInput(input) {
58
58
  const s = input.replace(GROUPING_RE, "").replace(/^[^\d.]+|[^\d.]+$/g, "");
59
59
  return DECIMAL_RE.test(s) ? s : void 0;
60
60
  }
61
- /** Every `filter.<namespace>.<key>` param plus the price bounds. Malformed
62
- * entries drop silently — a listing must render for any URL a buyer can type. */
61
+ /** Every `filter.<key>` param plus the price bounds. Malformed entries drop
62
+ * silently — a listing must render for any URL a buyer can type. */
63
63
  function parseListingFilters(search) {
64
64
  const raw = search ?? {};
65
65
  const filters = {};
66
66
  for (const [k, v] of Object.entries(raw)) {
67
67
  if (!k.startsWith(FILTER_PREFIX)) continue;
68
- const path = k.slice(7);
69
- const dot = path.indexOf(".");
70
- if (dot <= 0 || dot === path.length - 1) continue;
68
+ const key = k.slice(7);
69
+ const dot = key.indexOf(".");
70
+ if (dot <= 0 || dot === key.length - 1) continue;
71
71
  const csv = asParam(v);
72
72
  if (!csv) continue;
73
73
  const values = splitValues(csv);
74
- if (values.length > 0) filters[path] = values;
74
+ if (values.length > 0) filters[key] = values;
75
75
  }
76
76
  return {
77
77
  price_min: asDecimal(raw.price_min),
@@ -84,9 +84,9 @@ function parseListingFilters(search) {
84
84
  * set serialize identically whatever order the buyer clicked in. */
85
85
  function listingFilterParams(state) {
86
86
  const params = [];
87
- for (const nsKey of Object.keys(state.filters).sort()) {
88
- const values = state.filters[nsKey];
89
- if (values?.length) params.push([`${FILTER_PREFIX}${nsKey}`, joinFilterValues([...values].sort())]);
87
+ for (const key of Object.keys(state.filters).sort()) {
88
+ const values = state.filters[key];
89
+ if (values?.length) params.push([filterParam(key), joinFilterValues([...values].sort())]);
90
90
  }
91
91
  if (state.price_min) params.push(["price_min", state.price_min]);
92
92
  if (state.price_max) params.push(["price_max", state.price_max]);
@@ -126,8 +126,8 @@ function searchText(s) {
126
126
  }
127
127
  /** Tick or untick one facet value. An emptied facet leaves the URL, and the
128
128
  * page drops: a different result set has no page N. */
129
- function toggleFilterValue(prev, namespace, key, value) {
130
- const param = filterParam(namespace, key);
129
+ function toggleFilterValue(prev, key, value) {
130
+ const param = filterParam(key);
131
131
  const current = splitValues(asParam(prev[param]) ?? "");
132
132
  const next = current.includes(value) ? current.filter((v) => v !== value) : [...current, value];
133
133
  const out = carryForward(prev, ["page", param]);
@@ -135,8 +135,8 @@ function toggleFilterValue(prev, namespace, key, value) {
135
135
  return out;
136
136
  }
137
137
  /** Untick every value of one facet. */
138
- function removeFilter(prev, namespace, key) {
139
- return carryForward(prev, ["page", filterParam(namespace, key)]);
138
+ function removeFilter(prev, key) {
139
+ return carryForward(prev, ["page", filterParam(key)]);
140
140
  }
141
141
  /** Replace the price bounds with what the buyer typed. A blank or invalid bound
142
142
  * drops its key. */
@@ -178,29 +178,9 @@ function narrowedListingPath(pathname, state, sort, defaultSort) {
178
178
  const query = new URLSearchParams(params).toString();
179
179
  return query ? `${pathname}?${query}` : pathname;
180
180
  }
181
- /** The API filter input, or `undefined` with nothing applied so the resolver
182
- * short-circuits to the unfiltered scope. */
183
- function toFilterInput(state) {
184
- const metafields = [];
185
- for (const [nsKey, values] of Object.entries(state.filters)) {
186
- const dot = nsKey.indexOf(".");
187
- if (dot <= 0 || values.length === 0) continue;
188
- metafields.push({
189
- namespace: nsKey.slice(0, dot),
190
- key: nsKey.slice(dot + 1),
191
- values
192
- });
193
- }
194
- const out = {};
195
- if (metafields.length > 0) out.metafields = metafields;
196
- if (state.price_min) out.priceMin = state.price_min;
197
- if (state.price_max) out.priceMax = state.price_max;
198
- return Object.keys(out).length > 0 ? out : void 0;
199
- }
200
181
  /** Ticked values plus one for a price bound — price is one control whichever
201
182
  * end moved. */
202
183
  function activeFilterCount(state) {
203
184
  return Object.values(state.filters).reduce((n, list) => n + list.length, 0) + (state.price_min || state.price_max ? 1 : 0);
204
185
  }
205
- //#endregion
206
- export { activeFilterCount, asParam, carryForward, clearListingFilters, filterParam, joinFilterValues, listingFilterParams, narrowedListingPath, parseListingFilters, parsePriceInput, removeFilter, setPriceRange, toFilterInput, toggleFilterValue, urlValue };
186
+ export { activeFilterCount, asParam, carryForward, clearListingFilters, filterParam, joinFilterValues, listingFilterParams, narrowedListingPath, parseListingFilters, parsePriceInput, removeFilter, setPriceRange, toggleFilterValue, urlValue };
@@ -1,3 +1 @@
1
- //#region src/listing-price.d.ts
2
- export declare function defaultPriceMaxBound(currencyCode: string): number;
3
- //#endregion
1
+ export declare function defaultPriceMaxBound(currencyCode: string): number;
@@ -1,4 +1,4 @@
1
- //#region src/listing-price.ts
1
+ // src/listing-price.ts
2
2
  const DEFAULT_PRICE_MAX_BOUND = {
3
3
  MNT: 2e6,
4
4
  KRW: 2e6,
@@ -9,5 +9,4 @@ const DEFAULT_PRICE_MAX_BOUND = {
9
9
  function defaultPriceMaxBound(currencyCode) {
10
10
  return DEFAULT_PRICE_MAX_BOUND[currencyCode] ?? 2e3;
11
11
  }
12
- //#endregion
13
12
  export { defaultPriceMaxBound };
package/dist/money.d.ts CHANGED
@@ -1,4 +1,3 @@
1
- //#region src/money.d.ts
2
1
  export type Money = {
3
2
  amount: number;
4
3
  currencyCode: string;
@@ -12,5 +11,4 @@ export declare function formatMoneyWithCurrency(money: Money, locale?: string):
12
11
  * — which, for a code with no symbol of its own (`CHF`), is the code itself.
13
12
  * A malformed code has none: `Intl` throws on it, and a price field is not
14
13
  * worth failing the page over. */
15
- export declare function currencySymbol(currencyCode: string): string;
16
- //#endregion
14
+ export declare function currencySymbol(currencyCode: string): string;
package/dist/money.js CHANGED
@@ -1,4 +1,4 @@
1
- //#region src/money.ts
1
+ // src/money.ts
2
2
  const SUFFIX_SYMBOLS = { MNT: "₮" };
3
3
  const FORMATTER_CACHE = /* @__PURE__ */ new Map();
4
4
  function formatMoney({ amount, currencyCode }, locale = "en-US") {
@@ -47,5 +47,4 @@ function currencySymbol(currencyCode) {
47
47
  }
48
48
  return fmt.formatToParts(0).find((part) => part.type === "currency")?.value ?? "";
49
49
  }
50
- //#endregion
51
50
  export { currencySymbol, formatMoney, formatMoneyWithCurrency };
@@ -1,4 +1,3 @@
1
- //#region src/parse-embed-url.d.ts
2
1
  export type EmbedKind = "youtube" | "vimeo" | "file";
3
2
  export type Embed = {
4
3
  type: "youtube";
@@ -24,5 +23,4 @@ export type PlayerEmbed = Exclude<Embed, {
24
23
  * preference: both platforms refuse to autoplay with sound. YouTube is the
25
24
  * no-cookie host, and loops a single video only when it is also the whole
26
25
  * playlist. */
27
- export declare function embedBackgroundSrc(embed: PlayerEmbed, loop: boolean): string;
28
- //#endregion
26
+ export declare function embedBackgroundSrc(embed: PlayerEmbed, loop: boolean): string;
@@ -1,4 +1,4 @@
1
- //#region src/parse-embed-url.ts
1
+ // src/parse-embed-url.ts
2
2
  function parseEmbedUrl(url) {
3
3
  try {
4
4
  const u = new URL(url);
@@ -67,5 +67,4 @@ function embedBackgroundSrc(embed, loop) {
67
67
  if (loop) params.set("loop", "1");
68
68
  return `https://player.vimeo.com/video/${embed.videoId}?${params}`;
69
69
  }
70
- //#endregion
71
70
  export { embedBackgroundSrc, parseEmbedUrl };
@@ -1,6 +1,4 @@
1
- //#region src/playable-video.d.ts
2
1
  export declare function playableVideo<T extends {
3
2
  url?: string | null;
4
3
  hlsUrl?: string | null;
5
- }>(video: T | null | undefined): T | null;
6
- //#endregion
4
+ }>(video: T | null | undefined): T | null;
@@ -1,6 +1,5 @@
1
- //#region src/playable-video.ts
1
+ // src/playable-video.ts
2
2
  function playableVideo(video) {
3
3
  return video && (video.url || video.hlsUrl) ? video : null;
4
4
  }
5
- //#endregion
6
5
  export { playableVideo };
@@ -1,3 +1 @@
1
- //#region src/product-href.d.ts
2
- export declare function productHref(handle?: string, collectionHandle?: string): string | null;
3
- //#endregion
1
+ export declare function productHref(handle?: string, collectionHandle?: string): string | null;
@@ -1,8 +1,7 @@
1
- //#region src/product-href.ts
1
+ // src/product-href.ts
2
2
  function productHref(handle, collectionHandle) {
3
3
  if (!handle) return null;
4
4
  if (collectionHandle) return `/collections/${collectionHandle}/products/${handle}`;
5
5
  return `/products/${handle}`;
6
6
  }
7
- //#endregion
8
7
  export { productHref };
@@ -1,4 +1,2 @@
1
1
  import { OptionAvailability, ProductOption, ProductVariant } from "./types.js";
2
- //#region src/product-variants/build-availability-index.d.ts
3
- export declare function buildAvailabilityIndex(options: readonly ProductOption[], variants: readonly ProductVariant[]): OptionAvailability;
4
- //#endregion
2
+ export declare function buildAvailabilityIndex(options: readonly ProductOption[], variants: readonly ProductVariant[]): OptionAvailability;