@pradip1995/segment-primitives 0.4.14 → 0.4.15

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@pradip1995/segment-primitives",
3
- "version": "0.4.14",
3
+ "version": "0.4.15",
4
4
  "license": "MIT",
5
5
  "publishConfig": {
6
6
  "access": "public"
@@ -17,6 +17,8 @@
17
17
  "./card": "./src/Card.tsx",
18
18
  "./format-price": "./src/format-price.ts",
19
19
  "./resolve-media-url": "./src/resolve-media-url.ts",
20
+ "./skip-image-optimization": "./src/skip-image-optimization.ts",
21
+ "./optimized-image-src": "./src/optimized-image-src.ts",
20
22
  "./section-variants": "./src/section-variants.ts",
21
23
  "./product-variants": "./src/product-variants.ts",
22
24
  "./product-selection-context": "./src/product-selection-context.tsx",
package/src/Button.tsx CHANGED
@@ -1,19 +1,19 @@
1
- import type { ButtonHTMLAttributes, ReactNode } from "react"
2
-
3
- type ButtonProps = ButtonHTMLAttributes<HTMLButtonElement> & {
4
- children: ReactNode
5
- variant?: "primary" | "secondary"
6
- }
7
-
8
- export function Button({ children, variant = "primary", className = "", ...props }: ButtonProps) {
9
- const base = "inline-flex items-center justify-center px-4 py-2 text-sm font-semibold transition-colors"
10
- const styles =
11
- variant === "primary"
12
- ? "bg-brand-accent text-inverse"
13
- : "border border-brand-accent text-brand-accent"
14
- return (
15
- <button className={`${base} ${styles} ${className}`} {...props}>
16
- {children}
17
- </button>
18
- )
19
- }
1
+ import type { ButtonHTMLAttributes, ReactNode } from "react"
2
+
3
+ type ButtonProps = ButtonHTMLAttributes<HTMLButtonElement> & {
4
+ children: ReactNode
5
+ variant?: "primary" | "secondary"
6
+ }
7
+
8
+ export function Button({ children, variant = "primary", className = "", ...props }: ButtonProps) {
9
+ const base = "inline-flex items-center justify-center px-4 py-2 text-sm font-semibold transition-colors"
10
+ const styles =
11
+ variant === "primary"
12
+ ? "bg-brand-accent text-inverse"
13
+ : "border border-brand-accent text-brand-accent"
14
+ return (
15
+ <button className={`${base} ${styles} ${className}`} {...props}>
16
+ {children}
17
+ </button>
18
+ )
19
+ }
package/src/Card.tsx CHANGED
@@ -1,10 +1,10 @@
1
- import type { ReactNode } from "react"
2
-
3
- type CardProps = {
4
- children: ReactNode
5
- className?: string
6
- }
7
-
8
- export function Card({ children, className = "" }: CardProps) {
9
- return <div className={`bg-surface rounded-lg p-4 ${className}`}>{children}</div>
10
- }
1
+ import type { ReactNode } from "react"
2
+
3
+ type CardProps = {
4
+ children: ReactNode
5
+ className?: string
6
+ }
7
+
8
+ export function Card({ children, className = "" }: CardProps) {
9
+ return <div className={`bg-surface rounded-lg p-4 ${className}`}>{children}</div>
10
+ }
@@ -1,73 +1,73 @@
1
- import { describe, it } from "node:test"
2
- import assert from "node:assert/strict"
3
- import {
4
- COUPON_APPLY_NO_ITEM_MATCH,
5
- COUPON_APPLY_SUCCESS,
6
- couponApplyKind,
7
- couponApplyMessage,
8
- type CouponApplyCart,
9
- type CouponApplyKind,
10
- } from "./coupon-apply-result.ts"
11
-
12
- const KIND_CASES: { name: string; cart: CouponApplyCart; want: CouponApplyKind }[] = [
13
- {
14
- name: "positive discount_total is success",
15
- cart: { discount_total: 86 },
16
- want: "success",
17
- },
18
- {
19
- name: "explicit zero discount_total means the code did not hit bag items",
20
- cart: { discount_total: 0, promotions: [{ code: "WELCOME10" }] },
21
- want: "no-item-match",
22
- },
23
- {
24
- name: "missing discount_total after a successful apply is not a false error",
25
- cart: { promotions: [{ code: "WELCOME10" }] },
26
- want: "success",
27
- },
28
- {
29
- name: "null discount_total after a successful apply is not a false error",
30
- cart: { discount_total: null },
31
- want: "success",
32
- },
33
- {
34
- name: "retrieve failure after a successful apply is not a false error",
35
- cart: null,
36
- want: "success",
37
- },
38
- ]
39
-
40
- const MESSAGE_CASES: { name: string; kind: CouponApplyKind; wantError: string; wantSuccess: string }[] =
41
- [
42
- {
43
- name: "success copy",
44
- kind: "success",
45
- wantError: "",
46
- wantSuccess: COUPON_APPLY_SUCCESS,
47
- },
48
- {
49
- name: "no-item-match copy",
50
- kind: "no-item-match",
51
- wantError: COUPON_APPLY_NO_ITEM_MATCH,
52
- wantSuccess: "",
53
- },
54
- ]
55
-
56
- describe("couponApplyKind", () => {
57
- for (const tc of KIND_CASES) {
58
- it(tc.name, () => {
59
- assert.equal(couponApplyKind(tc.cart), tc.want)
60
- })
61
- }
62
- })
63
-
64
- describe("couponApplyMessage", () => {
65
- for (const tc of MESSAGE_CASES) {
66
- it(tc.name, () => {
67
- assert.deepEqual(couponApplyMessage(tc.kind), {
68
- error: tc.wantError,
69
- success: tc.wantSuccess,
70
- })
71
- })
72
- }
73
- })
1
+ import { describe, it } from "node:test"
2
+ import assert from "node:assert/strict"
3
+ import {
4
+ COUPON_APPLY_NO_ITEM_MATCH,
5
+ COUPON_APPLY_SUCCESS,
6
+ couponApplyKind,
7
+ couponApplyMessage,
8
+ type CouponApplyCart,
9
+ type CouponApplyKind,
10
+ } from "./coupon-apply-result.ts"
11
+
12
+ const KIND_CASES: { name: string; cart: CouponApplyCart; want: CouponApplyKind }[] = [
13
+ {
14
+ name: "positive discount_total is success",
15
+ cart: { discount_total: 86 },
16
+ want: "success",
17
+ },
18
+ {
19
+ name: "explicit zero discount_total means the code did not hit bag items",
20
+ cart: { discount_total: 0, promotions: [{ code: "WELCOME10" }] },
21
+ want: "no-item-match",
22
+ },
23
+ {
24
+ name: "missing discount_total after a successful apply is not a false error",
25
+ cart: { promotions: [{ code: "WELCOME10" }] },
26
+ want: "success",
27
+ },
28
+ {
29
+ name: "null discount_total after a successful apply is not a false error",
30
+ cart: { discount_total: null },
31
+ want: "success",
32
+ },
33
+ {
34
+ name: "retrieve failure after a successful apply is not a false error",
35
+ cart: null,
36
+ want: "success",
37
+ },
38
+ ]
39
+
40
+ const MESSAGE_CASES: { name: string; kind: CouponApplyKind; wantError: string; wantSuccess: string }[] =
41
+ [
42
+ {
43
+ name: "success copy",
44
+ kind: "success",
45
+ wantError: "",
46
+ wantSuccess: COUPON_APPLY_SUCCESS,
47
+ },
48
+ {
49
+ name: "no-item-match copy",
50
+ kind: "no-item-match",
51
+ wantError: COUPON_APPLY_NO_ITEM_MATCH,
52
+ wantSuccess: "",
53
+ },
54
+ ]
55
+
56
+ describe("couponApplyKind", () => {
57
+ for (const tc of KIND_CASES) {
58
+ it(tc.name, () => {
59
+ assert.equal(couponApplyKind(tc.cart), tc.want)
60
+ })
61
+ }
62
+ })
63
+
64
+ describe("couponApplyMessage", () => {
65
+ for (const tc of MESSAGE_CASES) {
66
+ it(tc.name, () => {
67
+ assert.deepEqual(couponApplyMessage(tc.kind), {
68
+ error: tc.wantError,
69
+ success: tc.wantSuccess,
70
+ })
71
+ })
72
+ }
73
+ })
@@ -1,41 +1,41 @@
1
- export type CouponApplyKind = "success" | "no-item-match"
2
-
3
- export type CouponApplyCart = {
4
- discount_total?: number | null
5
- promotions?: { code?: string | null }[] | null
6
- } | null
7
-
8
- export const COUPON_APPLY_SUCCESS = "Coupon applied successfully!"
9
- export const COUPON_APPLY_NO_ITEM_MATCH =
10
- "Coupon added, but it doesn't apply to the items in your bag."
11
-
12
- /**
13
- * `applyPromotions` already succeeded. Decide checkout copy from the cart
14
- * fetched afterwards — missing `discount_total` must not look like a failed coupon.
15
- */
16
- export function couponApplyKind(cart: CouponApplyCart): CouponApplyKind {
17
- if (cart == null) {
18
- return "success"
19
- }
20
-
21
- if (cart.discount_total != null && Number(cart.discount_total) === 0) {
22
- return "no-item-match"
23
- }
24
-
25
- if (Number(cart.discount_total ?? 0) > 0) {
26
- return "success"
27
- }
28
-
29
- return "success"
30
- }
31
-
32
- export function couponApplyMessage(kind: CouponApplyKind): {
33
- error: string
34
- success: string
35
- } {
36
- if (kind === "success") {
37
- return { error: "", success: COUPON_APPLY_SUCCESS }
38
- }
39
-
40
- return { error: COUPON_APPLY_NO_ITEM_MATCH, success: "" }
41
- }
1
+ export type CouponApplyKind = "success" | "no-item-match"
2
+
3
+ export type CouponApplyCart = {
4
+ discount_total?: number | null
5
+ promotions?: { code?: string | null }[] | null
6
+ } | null
7
+
8
+ export const COUPON_APPLY_SUCCESS = "Coupon applied successfully!"
9
+ export const COUPON_APPLY_NO_ITEM_MATCH =
10
+ "Coupon added, but it doesn't apply to the items in your bag."
11
+
12
+ /**
13
+ * `applyPromotions` already succeeded. Decide checkout copy from the cart
14
+ * fetched afterwards — missing `discount_total` must not look like a failed coupon.
15
+ */
16
+ export function couponApplyKind(cart: CouponApplyCart): CouponApplyKind {
17
+ if (cart == null) {
18
+ return "success"
19
+ }
20
+
21
+ if (cart.discount_total != null && Number(cart.discount_total) === 0) {
22
+ return "no-item-match"
23
+ }
24
+
25
+ if (Number(cart.discount_total ?? 0) > 0) {
26
+ return "success"
27
+ }
28
+
29
+ return "success"
30
+ }
31
+
32
+ export function couponApplyMessage(kind: CouponApplyKind): {
33
+ error: string
34
+ success: string
35
+ } {
36
+ if (kind === "success") {
37
+ return { error: "", success: COUPON_APPLY_SUCCESS }
38
+ }
39
+
40
+ return { error: COUPON_APPLY_NO_ITEM_MATCH, success: "" }
41
+ }