@khipu/design-system 0.3.5-alpha.6 → 0.3.5-alpha.9

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.mjs CHANGED
@@ -1,6 +1,3 @@
1
- // src/theme/KdsThemeProvider.tsx
2
- import { useEffect } from "react";
3
-
4
1
  // src/components/core/utils.ts
5
2
  import { clsx } from "clsx";
6
3
  function hexToRgb(hex) {
@@ -72,106 +69,28 @@ function formatTime(iso) {
72
69
  return `${pad(date.getHours())}:${pad(date.getMinutes())}`;
73
70
  }
74
71
 
72
+ // src/version.ts
73
+ var KDS_VERSION = "0.3.5-alpha.9";
74
+
75
75
  // src/theme/KdsThemeProvider.tsx
76
76
  import { jsx } from "react/jsx-runtime";
77
- var CARD_MIN_DELTA_PX = 8;
78
- var CARD_TRANSITION_MS = 280;
79
- var BODY_CARD_SELECTOR = ".kds-screen > .kds-card-elevated";
80
- var CARD_MARK_ATTRIBUTE = "data-kds-height-transition";
81
- var SCREEN_LAST_HEIGHT_ATTRIBUTE = "data-kds-last-card-height";
82
- function useCardHeightTransition() {
83
- useEffect(() => {
84
- if (typeof window === "undefined" || typeof ResizeObserver === "undefined") {
85
- return;
86
- }
87
- if (typeof Element.prototype.animate !== "function") {
88
- return;
89
- }
90
- if (window.matchMedia?.("(prefers-reduced-motion: reduce)").matches) {
91
- return;
92
- }
93
- const observers = [];
94
- const animate = (card, from, to) => {
95
- card.style.height = `${from}px`;
96
- const animation = card.animate(
97
- [{ height: `${from}px` }, { height: `${to}px` }],
98
- { duration: CARD_TRANSITION_MS, easing: "ease-out" }
99
- );
100
- const release = () => {
101
- card.style.height = "";
102
- };
103
- animation.finished.then(release).catch(release);
104
- return animation;
105
- };
106
- const observe = (card) => {
107
- if (card.getAttribute(CARD_MARK_ATTRIBUTE) === "on") {
108
- return;
109
- }
110
- card.setAttribute(CARD_MARK_ATTRIBUTE, "on");
111
- const screen = card.parentElement;
112
- let previous = card.offsetHeight;
113
- let animating = false;
114
- const remembered = screen?.getAttribute(SCREEN_LAST_HEIGHT_ATTRIBUTE);
115
- if (remembered) {
116
- const from = Number(remembered);
117
- if (Number.isFinite(from) && from > 0 && Math.abs(from - previous) >= CARD_MIN_DELTA_PX) {
118
- animating = true;
119
- animate(card, from, previous).finished.then(() => {
120
- animating = false;
121
- }).catch(() => {
122
- animating = false;
123
- });
124
- }
125
- }
126
- screen?.setAttribute(SCREEN_LAST_HEIGHT_ATTRIBUTE, String(previous));
127
- const observer = new ResizeObserver(() => {
128
- if (animating) {
129
- return;
130
- }
131
- const next = card.offsetHeight;
132
- if (Math.abs(next - previous) < CARD_MIN_DELTA_PX) {
133
- previous = next;
134
- screen?.setAttribute(SCREEN_LAST_HEIGHT_ATTRIBUTE, String(next));
135
- return;
136
- }
137
- animating = true;
138
- const animation = animate(card, previous, next);
139
- previous = next;
140
- screen?.setAttribute(SCREEN_LAST_HEIGHT_ATTRIBUTE, String(next));
141
- animation.finished.then(() => {
142
- animating = false;
143
- previous = card.offsetHeight;
144
- screen?.setAttribute(SCREEN_LAST_HEIGHT_ATTRIBUTE, String(previous));
145
- }).catch(() => {
146
- animating = false;
147
- });
148
- });
149
- observer.observe(card);
150
- observers.push(observer);
151
- };
152
- document.querySelectorAll(BODY_CARD_SELECTOR).forEach(observe);
153
- const tree = new MutationObserver(() => {
154
- document.querySelectorAll(BODY_CARD_SELECTOR).forEach(observe);
155
- });
156
- tree.observe(document.body, { childList: true, subtree: true });
157
- return () => {
158
- tree.disconnect();
159
- observers.forEach((observer) => observer.disconnect());
160
- document.querySelectorAll(BODY_CARD_SELECTOR).forEach((card) => {
161
- card.removeAttribute(CARD_MARK_ATTRIBUTE);
162
- });
163
- };
164
- }, []);
165
- }
166
77
  function KdsThemeProvider({ primaryColor, mode = "light", children }) {
167
- useCardHeightTransition();
168
78
  const style = primaryColor ? {
169
79
  "--primary": primaryColor,
170
80
  "--on-primary": getContrastColor(primaryColor),
171
81
  "--primary-container": lighten(primaryColor, 0.85),
172
82
  "--on-primary-container": primaryColor
173
83
  } : void 0;
174
- return /* @__PURE__ */ jsx("div", { className: `kds-theme-root ${mode}`, "data-theme": mode, style, children });
84
+ return /* @__PURE__ */ jsx(
85
+ "div",
86
+ {
87
+ className: `kds-theme-root ${mode}`,
88
+ "data-theme": mode,
89
+ "data-kds-version": KDS_VERSION,
90
+ style,
91
+ children
92
+ }
93
+ );
175
94
  }
176
95
 
177
96
  // src/tokens/index.ts
@@ -1547,7 +1466,7 @@ var KdsTypography = forwardRef11(
1547
1466
  KdsTypography.displayName = "KdsTypography";
1548
1467
 
1549
1468
  // src/components/core/KdsTabs/KdsTabs.tsx
1550
- import React13, { forwardRef as forwardRef12, Children, useMemo } from "react";
1469
+ import React12, { forwardRef as forwardRef12, Children, useMemo } from "react";
1551
1470
 
1552
1471
  // src/components/core/hooks/useTabsKeyboard.ts
1553
1472
  import { useCallback as useCallback2 } from "react";
@@ -1595,8 +1514,8 @@ var KdsTabs = forwardRef12(
1595
1514
  onKeyDown,
1596
1515
  ...props,
1597
1516
  children: Children.map(children, (child, i) => {
1598
- if (!React13.isValidElement(child)) return child;
1599
- return React13.cloneElement(child, {
1517
+ if (!React12.isValidElement(child)) return child;
1518
+ return React12.cloneElement(child, {
1600
1519
  _active: i === activeIndex,
1601
1520
  _onClick: () => onChange(i)
1602
1521
  });
@@ -1757,12 +1676,12 @@ KdsChip.displayName = "KdsChip";
1757
1676
  import { forwardRef as forwardRef16 } from "react";
1758
1677
 
1759
1678
  // src/components/core/hooks/useAutoHide.ts
1760
- import { useState as useState3, useEffect as useEffect2, useRef } from "react";
1679
+ import { useState as useState3, useEffect, useRef } from "react";
1761
1680
  function useAutoHide(durationMs, onHide) {
1762
1681
  const [visible, setVisible] = useState3(true);
1763
1682
  const onHideRef = useRef(onHide);
1764
1683
  onHideRef.current = onHide;
1765
- useEffect2(() => {
1684
+ useEffect(() => {
1766
1685
  if (durationMs <= 0) return;
1767
1686
  const timer = setTimeout(() => {
1768
1687
  setVisible(false);
@@ -2206,10 +2125,10 @@ var KdsExpandPanel = forwardRef24(
2206
2125
  KdsExpandPanel.displayName = "KdsExpandPanel";
2207
2126
 
2208
2127
  // src/components/core/KdsCountdown/KdsCountdown.tsx
2209
- import { forwardRef as forwardRef25, useEffect as useEffect4, useRef as useRef3 } from "react";
2128
+ import { forwardRef as forwardRef25, useEffect as useEffect3, useRef as useRef3 } from "react";
2210
2129
 
2211
2130
  // src/components/core/hooks/useCountdown.ts
2212
- import { useState as useState6, useEffect as useEffect3 } from "react";
2131
+ import { useState as useState6, useEffect as useEffect2 } from "react";
2213
2132
  function calcRemaining(deadline) {
2214
2133
  const diff = Math.max(0, new Date(deadline).getTime() - Date.now());
2215
2134
  const totalSeconds = Math.floor(diff / 1e3);
@@ -2223,7 +2142,7 @@ function calcRemaining(deadline) {
2223
2142
  }
2224
2143
  function useCountdown(deadline) {
2225
2144
  const [state, setState] = useState6(() => calcRemaining(deadline));
2226
- useEffect3(() => {
2145
+ useEffect2(() => {
2227
2146
  const tick = () => setState(calcRemaining(deadline));
2228
2147
  const id = setInterval(tick, 1e3);
2229
2148
  return () => clearInterval(id);
@@ -2238,7 +2157,7 @@ var KdsCountdown = forwardRef25(
2238
2157
  const { hours, minutes, seconds, expired, urgent } = useCountdown(deadline);
2239
2158
  const onExpireRef = useRef3(onExpire);
2240
2159
  onExpireRef.current = onExpire;
2241
- useEffect4(() => {
2160
+ useEffect3(() => {
2242
2161
  if (expired) {
2243
2162
  onExpireRef.current?.();
2244
2163
  }
@@ -2617,7 +2536,7 @@ KdsMerchantTile.displayName = "KdsMerchantTile";
2617
2536
  import { forwardRef as forwardRef42, useState as useState9 } from "react";
2618
2537
 
2619
2538
  // src/components/domain/KdsInvoiceMerchant/useLogoBackdrop.ts
2620
- import { useEffect as useEffect5, useState as useState8 } from "react";
2539
+ import { useEffect as useEffect4, useState as useState8 } from "react";
2621
2540
 
2622
2541
  // src/components/domain/KdsInvoiceMerchant/logoLuminance.ts
2623
2542
  var LIGHT_LOGO_LUMINANCE_THRESHOLD = 0.72;
@@ -2667,7 +2586,7 @@ function pickLogoBackdrop(luminance) {
2667
2586
  // src/components/domain/KdsInvoiceMerchant/useLogoBackdrop.ts
2668
2587
  function useLogoBackdrop(logoUrl) {
2669
2588
  const [backdrop, setBackdrop] = useState8("light");
2670
- useEffect5(() => {
2589
+ useEffect4(() => {
2671
2590
  let cancelled = false;
2672
2591
  setBackdrop("light");
2673
2592
  if (!logoUrl) {
@@ -2909,12 +2828,12 @@ var guideToFirstInvalidFieldOnBlur = (form) => {
2909
2828
  };
2910
2829
 
2911
2830
  // src/components/core/hooks/useStickyInvoiceCollapse.ts
2912
- import { useEffect as useEffect6, useRef as useRef4 } from "react";
2831
+ import { useEffect as useEffect5, useRef as useRef4 } from "react";
2913
2832
  function useStickyInvoiceCollapse(options = {}) {
2914
2833
  const { onCollapseStart, collapseEnd = 20, mobileBreakpoint = 768 } = options;
2915
2834
  const onCollapseStartRef = useRef4(onCollapseStart);
2916
2835
  onCollapseStartRef.current = onCollapseStart;
2917
- useEffect6(() => {
2836
+ useEffect5(() => {
2918
2837
  let viewportOffset = 0;
2919
2838
  let ticking = false;
2920
2839
  let wasCollapsing = false;
@@ -3036,11 +2955,11 @@ function useExpandToggle(options = {}) {
3036
2955
  }
3037
2956
 
3038
2957
  // src/components/core/hooks/useHideOnScroll.ts
3039
- import { useEffect as useEffect7, useState as useState11 } from "react";
2958
+ import { useEffect as useEffect6, useState as useState11 } from "react";
3040
2959
  function useHideOnScroll(options = {}) {
3041
2960
  const { threshold = 8, topOffset = 0 } = options;
3042
2961
  const [hidden, setHidden] = useState11(false);
3043
- useEffect7(() => {
2962
+ useEffect6(() => {
3044
2963
  let viewportOffset = 0;
3045
2964
  let lastY = 0;
3046
2965
  let ticking = false;
@@ -3083,12 +3002,12 @@ function useHideOnScroll(options = {}) {
3083
3002
  }
3084
3003
 
3085
3004
  // src/components/core/hooks/useMediaQuery.ts
3086
- import { useEffect as useEffect8, useState as useState12 } from "react";
3005
+ import { useEffect as useEffect7, useState as useState12 } from "react";
3087
3006
  function useMediaQuery(query) {
3088
3007
  const [matches, setMatches] = useState12(
3089
3008
  () => typeof window !== "undefined" ? window.matchMedia(query).matches : false
3090
3009
  );
3091
- useEffect8(() => {
3010
+ useEffect7(() => {
3092
3011
  if (typeof window === "undefined") return;
3093
3012
  const mql = window.matchMedia(query);
3094
3013
  setMatches(mql.matches);
@@ -3099,6 +3018,7 @@ function useMediaQuery(query) {
3099
3018
  return matches;
3100
3019
  }
3101
3020
  export {
3021
+ KDS_VERSION,
3102
3022
  KdsAccordion,
3103
3023
  KdsAccordionDetails,
3104
3024
  KdsAccordionSummary,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@khipu/design-system",
3
- "version": "0.3.5-alpha.6",
3
+ "version": "0.3.5-alpha.9",
4
4
  "description": "Khipu Design System - UI components and design tokens for the Khipu payment platform",
5
5
  "main": "dist/index.js",
6
6
  "module": "dist/index.mjs",
@@ -49,7 +49,7 @@
49
49
  },
50
50
  "scripts": {
51
51
  "build": "npm run build:web && npm run tokens:export && node scripts/generate-css-variables.js && npm run beercss:build",
52
- "build:web": "tsup src/index.ts --format cjs,esm --dts --clean",
52
+ "build:web": "node scripts/generate-version.js && tsup src/index.ts --format cjs,esm --dts --clean",
53
53
  "dev": "tsup src/index.ts --format cjs,esm --dts --watch",
54
54
  "demo": "vite --config demo/vite.config.ts",
55
55
  "typecheck": "tsc --noEmit",