@kjun-ui/native 0.7.0 → 0.8.1

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.
@@ -2417,36 +2417,6 @@ function KjunSkeleton({
2417
2417
  ))
2418
2418
  }
2419
2419
  ),
2420
- type === "chart" && /* @__PURE__ */ (0, import_jsx_runtime15.jsxs)(import_react_native16.View, { style: [frame, { height: height || import_tokens13.tokens.extensions.skeleton.chartHeight }], children: [
2421
- /* @__PURE__ */ (0, import_jsx_runtime15.jsx)(
2422
- import_react_native16.View,
2423
- {
2424
- style: {
2425
- flex: 1,
2426
- flexDirection: "row",
2427
- alignItems: "flex-end",
2428
- justifyContent: "space-around",
2429
- gap: import_tokens13.tokens.extensions.skeleton.gap
2430
- // Bars stand on the axis line, like ChartSkeleton.
2431
- },
2432
- children: [40, 65, 50, 80, 60, 90, 75].map((h, i) => /* @__PURE__ */ (0, import_jsx_runtime15.jsx)(
2433
- import_react_native16.Animated.View,
2434
- {
2435
- style: {
2436
- flex: 1,
2437
- maxWidth: import_tokens13.tokens.extensions.skeleton.chartBarMaxWidth,
2438
- height: `${h}%`,
2439
- backgroundColor: shimmer,
2440
- borderTopLeftRadius: import_tokens13.tokens.radius.radius4,
2441
- borderTopRightRadius: import_tokens13.tokens.radius.radius4
2442
- }
2443
- },
2444
- i
2445
- ))
2446
- }
2447
- ),
2448
- block("100%", import_tokens13.tokens.extensions.skeleton.chartAxisHeight, { backgroundColor: colors.border })
2449
- ] }),
2450
2420
  type === "stat" && /* @__PURE__ */ (0, import_jsx_runtime15.jsxs)(
2451
2421
  import_react_native16.View,
2452
2422
  {
@@ -6511,6 +6481,24 @@ var import_react57 = require("react");
6511
6481
  var import_react_native42 = require("react-native");
6512
6482
  var import_react_native_svg5 = __toESM(require("react-native-svg"), 1);
6513
6483
 
6484
+ // shared/package-runtime/chart-skeleton.ts
6485
+ var chartFrameViewBox = "0 0 600 240";
6486
+ var chartFramePath = "M20 10V220H590 M20 65H590 M20 120H590 M20 175H590";
6487
+ var chartSkeletonMaxCount = 100;
6488
+ function chartSkeletonCount(value) {
6489
+ return Number.isFinite(value) ? Math.min(chartSkeletonMaxCount, Math.max(1, Math.floor(value))) : 1;
6490
+ }
6491
+ function chartMatrixMuted(row, column) {
6492
+ return (row + column + 2) % 3 === 0;
6493
+ }
6494
+ var chartDonutRatio = 0.8;
6495
+ function chartDonutHole(height, thickness) {
6496
+ return Math.max(0, height * chartDonutRatio - 2 * thickness);
6497
+ }
6498
+ function chartSkeletonKind(kind) {
6499
+ return kind === "donut" || kind === "matrix" ? kind : "frame";
6500
+ }
6501
+
6514
6502
  // packages/native/src/market-skeleton.tsx
6515
6503
  var import_tokens39 = require("@kjun-ui/tokens");
6516
6504
  var import_react_native41 = require("react-native");
@@ -6668,26 +6656,23 @@ function KjunFormSkeleton({
6668
6656
  }
6669
6657
  );
6670
6658
  }
6659
+ var chartPart = (name) => import_react_native42.Platform.OS === "web" ? { dataSet: { kjunChartPart: name } } : {};
6671
6660
  function KjunChartSkeleton({
6661
+ kind: requestedKind = "frame",
6662
+ height = import_tokens40.tokens.extensions.chartSkeleton.height,
6672
6663
  loadingText = "\uCC28\uD2B8\uB97C \uBD88\uB7EC\uC624\uB294 \uC911",
6673
- kind = "line",
6674
- height = import_tokens40.tokens.extensions.chartSkeleton.height
6664
+ skeleton = true,
6665
+ loadingDelay = 0,
6666
+ rows = 8,
6667
+ columns = 14
6675
6668
  }) {
6676
- const { colors } = useKjunStyles(), reduced = useReducedMotion(), opacity = (0, import_react57.useRef)(new import_react_native42.Animated.Value(1)).current;
6669
+ const kind = chartSkeletonKind(requestedKind), { colors } = useKjunStyles(), reduced = useReducedMotion(), opacity = (0, import_react57.useRef)(new import_react_native42.Animated.Value(1)).current, revealed = useLoadingReveal(true, loadingDelay), [measured, setMeasured] = (0, import_react57.useState)(0), thickness = import_tokens40.tokens.extensions.chartSkeleton.donutThickness, boxHeight = typeof height === "number" ? height : measured, hole = boxHeight > 0 ? chartDonutHole(boxHeight, thickness) : void 0, rowCount = chartSkeletonCount(rows), columnCount = chartSkeletonCount(columns), status = revealed && loadingText ? "status" : void 0, hidden = { "aria-hidden": true, importantForAccessibility: "no-hide-descendants" };
6677
6670
  (0, import_react57.useEffect)(() => {
6678
- if (reduced) return;
6671
+ if (reduced || !skeleton) return;
6679
6672
  const loop = import_react_native42.Animated.loop(
6680
6673
  import_react_native42.Animated.sequence([
6681
- import_react_native42.Animated.timing(opacity, {
6682
- toValue: 0.55,
6683
- duration: import_tokens40.tokens.motion.shimmer / 2,
6684
- useNativeDriver: true
6685
- }),
6686
- import_react_native42.Animated.timing(opacity, {
6687
- toValue: 1,
6688
- duration: import_tokens40.tokens.motion.shimmer / 2,
6689
- useNativeDriver: true
6690
- })
6674
+ import_react_native42.Animated.timing(opacity, { toValue: 0.55, duration: import_tokens40.tokens.motion.shimmer / 2, useNativeDriver: true }),
6675
+ import_react_native42.Animated.timing(opacity, { toValue: 1, duration: import_tokens40.tokens.motion.shimmer / 2, useNativeDriver: true })
6691
6676
  ])
6692
6677
  );
6693
6678
  loop.start();
@@ -6695,92 +6680,68 @@ function KjunChartSkeleton({
6695
6680
  loop.stop();
6696
6681
  opacity.setValue(1);
6697
6682
  };
6698
- }, [opacity, reduced]);
6699
- return /* @__PURE__ */ (0, import_jsx_runtime39.jsxs)(
6683
+ }, [opacity, reduced, skeleton]);
6684
+ return /* @__PURE__ */ (0, import_jsx_runtime39.jsx)(
6700
6685
  import_react_native42.Animated.View,
6701
6686
  {
6702
- style: {
6703
- height,
6704
- alignItems: "center",
6705
- justifyContent: "center",
6706
- width: "100%",
6707
- minWidth: 0,
6708
- opacity
6709
- },
6710
- accessibilityElementsHidden: true,
6711
- importantForAccessibility: "no-hide-descendants",
6712
- children: [
6687
+ onLayout: typeof height === "number" ? void 0 : (event) => setMeasured(event.nativeEvent.layout.height),
6688
+ style: { height, alignItems: "center", justifyContent: "center", width: "100%", minWidth: 0, opacity: revealed ? opacity : 0 },
6689
+ "aria-hidden": revealed ? void 0 : true,
6690
+ importantForAccessibility: revealed ? void 0 : "no-hide-descendants",
6691
+ ...import_react_native42.Platform.OS === "web" ? { dataSet: { kjunChartKind: kind, skeleton: skeleton ? void 0 : "false" } } : {},
6692
+ children: !skeleton ? /* @__PURE__ */ (0, import_jsx_runtime39.jsxs)(import_react_native42.View, { ...chartPart("loading"), role: status, style: { alignItems: "center", gap: import_tokens40.tokens.dimension.value12 }, children: [
6693
+ /* @__PURE__ */ (0, import_jsx_runtime39.jsx)(import_react_native42.View, { ...hidden, children: /* @__PURE__ */ (0, import_jsx_runtime39.jsx)(KjunSpinner, { size: "md" }) }),
6694
+ !!loadingText && /* @__PURE__ */ (0, import_jsx_runtime39.jsx)(KText, { style: { ...typeStyle("body"), color: colors.textSecondary, textAlign: "center", maxWidth: "100%" }, children: loadingText })
6695
+ ] }) : /* @__PURE__ */ (0, import_jsx_runtime39.jsxs)(import_jsx_runtime39.Fragment, { children: [
6713
6696
  kind === "donut" ? /* @__PURE__ */ (0, import_jsx_runtime39.jsx)(
6714
6697
  import_react_native42.View,
6715
6698
  {
6716
- style: {
6717
- height: "80%",
6718
- aspectRatio: 1,
6719
- borderWidth: import_tokens40.tokens.extensions.chartSkeleton.donutThickness,
6720
- borderColor: colors.skeleton,
6721
- borderRadius: import_tokens40.tokens.radius.radius9999,
6722
- alignItems: "center",
6723
- justifyContent: "center"
6724
- },
6725
- children: /* @__PURE__ */ (0, import_jsx_runtime39.jsx)(KjunSkeleton, { type: "block", width: import_tokens40.tokens.extensions.chartSkeleton.donutLabelWidth, height: import_tokens40.tokens.extensions.chartSkeleton.donutLabelHeight })
6699
+ ...chartPart("donut"),
6700
+ ...hidden,
6701
+ style: { height: `${chartDonutRatio * 100}%`, aspectRatio: 1, borderWidth: thickness, borderColor: colors.skeleton, borderRadius: import_tokens40.tokens.radius.radius9999 }
6726
6702
  }
6727
- ) : /* @__PURE__ */ (0, import_jsx_runtime39.jsxs)(
6728
- import_react_native_svg5.default,
6703
+ ) : kind === "matrix" ? /* @__PURE__ */ (0, import_jsx_runtime39.jsx)(import_react_native42.View, { ...chartPart("matrix"), ...hidden, style: { alignSelf: "stretch", flex: 1, gap: import_tokens40.tokens.dimension.value4 }, children: Array.from({ length: rowCount }, (_, row) => /* @__PURE__ */ (0, import_jsx_runtime39.jsx)(import_react_native42.View, { style: { flex: 1, flexDirection: "row", gap: import_tokens40.tokens.dimension.value4 }, children: Array.from({ length: columnCount }, (_2, column) => /* @__PURE__ */ (0, import_jsx_runtime39.jsx)(
6704
+ import_react_native42.View,
6729
6705
  {
6730
- viewBox: "0 0 600 240",
6731
- preserveAspectRatio: "none",
6732
- width: "100%",
6733
- height: "100%",
6734
- children: [
6735
- /* @__PURE__ */ (0, import_jsx_runtime39.jsx)(
6736
- import_react_native_svg5.Path,
6737
- {
6738
- d: "M20 10V220H590 M20 65H590 M20 120H590 M20 175H590",
6739
- fill: "none",
6740
- stroke: colors.border,
6741
- strokeWidth: 1
6742
- }
6743
- ),
6744
- kind === "line" && /* @__PURE__ */ (0, import_jsx_runtime39.jsx)(import_react_native_svg5.Path, { d: "M20 190 L100 160 L180 172 L260 120 L340 140 L420 96 L500 110 L590 64", fill: "none", stroke: colors.skeleton, strokeWidth: 4, strokeLinecap: "round", strokeLinejoin: "round" }),
6745
- kind === "matrix" ? Array.from({ length: 8 }, (_, row) => /* @__PURE__ */ (0, import_jsx_runtime39.jsx)(import_react_native_svg5.G, { children: Array.from({ length: 14 }, (_2, col) => /* @__PURE__ */ (0, import_jsx_runtime39.jsx)(
6746
- import_react_native_svg5.Rect,
6747
- {
6748
- x: 24 + col * 40,
6749
- y: 12 + row * 26,
6750
- width: 36,
6751
- height: 22,
6752
- rx: 2,
6753
- fill: colors.skeleton,
6754
- opacity: (row + col + 2) % 3 === 0 ? 0.55 : 1
6706
+ ...chartPart("cell"),
6707
+ style: {
6708
+ flex: 1,
6709
+ borderRadius: import_tokens40.tokens.extensions.skeleton.lineRadius,
6710
+ backgroundColor: colors.skeleton,
6711
+ opacity: chartMatrixMuted(row, column) ? import_tokens40.tokens.states.opacity.pending : 1
6712
+ }
6713
+ },
6714
+ column
6715
+ )) }, row)) }) : /* @__PURE__ */ (0, import_jsx_runtime39.jsx)(import_react_native42.View, { ...chartPart("plot"), ...hidden, style: { alignSelf: "stretch", flex: 1 }, children: /* @__PURE__ */ (0, import_jsx_runtime39.jsx)(import_react_native_svg5.default, { viewBox: chartFrameViewBox, preserveAspectRatio: "none", width: "100%", height: "100%", children: /* @__PURE__ */ (0, import_jsx_runtime39.jsx)(import_react_native_svg5.Path, { d: chartFramePath, fill: "none", stroke: colors.chartGrid, strokeWidth: import_tokens40.tokens.border.defaultWidth, vectorEffect: "non-scaling-stroke" }) }) }),
6716
+ !!loadingText && /* @__PURE__ */ (0, import_jsx_runtime39.jsx)(
6717
+ import_react_native42.View,
6718
+ {
6719
+ ...chartPart("status"),
6720
+ role: status,
6721
+ accessibilityLiveRegion: status ? "polite" : void 0,
6722
+ pointerEvents: "none",
6723
+ style: { position: "absolute", inset: 0, alignItems: "center", justifyContent: "center" },
6724
+ children: /* @__PURE__ */ (0, import_jsx_runtime39.jsx)(
6725
+ KText,
6726
+ {
6727
+ style: {
6728
+ ...typeStyle("body"),
6729
+ paddingHorizontal: import_tokens40.tokens.dimension.value12,
6730
+ paddingVertical: import_tokens40.tokens.dimension.value4,
6731
+ borderRadius: import_tokens40.tokens.radius.radius6,
6732
+ borderWidth: kind === "donut" ? 0 : import_tokens40.tokens.border.defaultWidth,
6733
+ borderColor: colors.chartGrid,
6734
+ backgroundColor: colors.surface,
6735
+ color: colors.textSecondary,
6736
+ maxWidth: kind === "donut" && hole != null ? hole : "90%",
6737
+ textAlign: "center"
6755
6738
  },
6756
- col
6757
- )) }, row)) : (kind === "bar" || kind === "candle") && [60, 100, 85, 140, 110, 165, 180].map((h, i) => /* @__PURE__ */ (0, import_jsx_runtime39.jsxs)(import_react57.Fragment, { children: [
6758
- kind === "candle" && /* @__PURE__ */ (0, import_jsx_runtime39.jsx)(
6759
- import_react_native_svg5.Path,
6760
- {
6761
- d: `M${55 + i * 75} ${195 - h}V${225 - h / 2}`,
6762
- fill: "none",
6763
- stroke: colors.skeleton,
6764
- strokeWidth: 4
6765
- }
6766
- ),
6767
- /* @__PURE__ */ (0, import_jsx_runtime39.jsx)(
6768
- import_react_native_svg5.Rect,
6769
- {
6770
- x: 35 + i * 75,
6771
- y: kind === "candle" ? 210 - h : 220 - h,
6772
- width: kind === "candle" ? 28 : 42,
6773
- height: kind === "candle" ? h / 2 : h,
6774
- rx: 3,
6775
- fill: colors.skeleton
6776
- }
6777
- )
6778
- ] }, i))
6779
- ]
6739
+ children: loadingText
6740
+ }
6741
+ )
6780
6742
  }
6781
- ),
6782
- /* @__PURE__ */ (0, import_jsx_runtime39.jsx)(import_react_native42.View, { pointerEvents: "none", style: { position: "absolute", inset: 0, alignItems: "center", justifyContent: "center", gap: import_tokens40.tokens.dimension.value12 }, children: !!loadingText && /* @__PURE__ */ (0, import_jsx_runtime39.jsx)(KText, { style: { ...typeStyle("body"), paddingHorizontal: import_tokens40.tokens.dimension.value12, paddingVertical: import_tokens40.tokens.dimension.value4, borderRadius: import_tokens40.tokens.radius.radius6, backgroundColor: colors.surface, color: colors.textSecondary, maxWidth: "90%", textAlign: "center" }, children: loadingText }) })
6783
- ]
6743
+ )
6744
+ ] })
6784
6745
  }
6785
6746
  );
6786
6747
  }