@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.
package/dist/index.cjs CHANGED
@@ -2322,36 +2322,6 @@ function KjunSkeleton({
2322
2322
  ))
2323
2323
  }
2324
2324
  ),
2325
- type === "chart" && /* @__PURE__ */ (0, import_jsx_runtime15.jsxs)(import_react_native16.View, { style: [frame, { height: height || import_tokens13.tokens.extensions.skeleton.chartHeight }], children: [
2326
- /* @__PURE__ */ (0, import_jsx_runtime15.jsx)(
2327
- import_react_native16.View,
2328
- {
2329
- style: {
2330
- flex: 1,
2331
- flexDirection: "row",
2332
- alignItems: "flex-end",
2333
- justifyContent: "space-around",
2334
- gap: import_tokens13.tokens.extensions.skeleton.gap
2335
- // Bars stand on the axis line, like ChartSkeleton.
2336
- },
2337
- children: [40, 65, 50, 80, 60, 90, 75].map((h, i) => /* @__PURE__ */ (0, import_jsx_runtime15.jsx)(
2338
- import_react_native16.Animated.View,
2339
- {
2340
- style: {
2341
- flex: 1,
2342
- maxWidth: import_tokens13.tokens.extensions.skeleton.chartBarMaxWidth,
2343
- height: `${h}%`,
2344
- backgroundColor: shimmer,
2345
- borderTopLeftRadius: import_tokens13.tokens.radius.radius4,
2346
- borderTopRightRadius: import_tokens13.tokens.radius.radius4
2347
- }
2348
- },
2349
- i
2350
- ))
2351
- }
2352
- ),
2353
- block("100%", import_tokens13.tokens.extensions.skeleton.chartAxisHeight, { backgroundColor: colors.border })
2354
- ] }),
2355
2325
  type === "stat" && /* @__PURE__ */ (0, import_jsx_runtime15.jsxs)(
2356
2326
  import_react_native16.View,
2357
2327
  {
@@ -6256,6 +6226,24 @@ var import_react53 = require("react");
6256
6226
  var import_react_native42 = require("react-native");
6257
6227
  var import_react_native_svg5 = __toESM(require("react-native-svg"), 1);
6258
6228
 
6229
+ // shared/package-runtime/chart-skeleton.ts
6230
+ var chartFrameViewBox = "0 0 600 240";
6231
+ var chartFramePath = "M20 10V220H590 M20 65H590 M20 120H590 M20 175H590";
6232
+ var chartSkeletonMaxCount = 100;
6233
+ function chartSkeletonCount(value) {
6234
+ return Number.isFinite(value) ? Math.min(chartSkeletonMaxCount, Math.max(1, Math.floor(value))) : 1;
6235
+ }
6236
+ function chartMatrixMuted(row, column) {
6237
+ return (row + column + 2) % 3 === 0;
6238
+ }
6239
+ var chartDonutRatio = 0.8;
6240
+ function chartDonutHole(height, thickness) {
6241
+ return Math.max(0, height * chartDonutRatio - 2 * thickness);
6242
+ }
6243
+ function chartSkeletonKind(kind) {
6244
+ return kind === "donut" || kind === "matrix" ? kind : "frame";
6245
+ }
6246
+
6259
6247
  // packages/native/src/market-skeleton.tsx
6260
6248
  var import_tokens38 = require("@kjun-ui/tokens");
6261
6249
  var import_react_native41 = require("react-native");
@@ -6413,26 +6401,23 @@ function KjunFormSkeleton({
6413
6401
  }
6414
6402
  );
6415
6403
  }
6404
+ var chartPart = (name) => import_react_native42.Platform.OS === "web" ? { dataSet: { kjunChartPart: name } } : {};
6416
6405
  function KjunChartSkeleton({
6406
+ kind: requestedKind = "frame",
6407
+ height = import_tokens39.tokens.extensions.chartSkeleton.height,
6417
6408
  loadingText = "\uCC28\uD2B8\uB97C \uBD88\uB7EC\uC624\uB294 \uC911",
6418
- kind = "line",
6419
- height = import_tokens39.tokens.extensions.chartSkeleton.height
6409
+ skeleton = true,
6410
+ loadingDelay = 0,
6411
+ rows = 8,
6412
+ columns = 14
6420
6413
  }) {
6421
- const { colors } = useKjunStyles(), reduced = useReducedMotion(), opacity = (0, import_react53.useRef)(new import_react_native42.Animated.Value(1)).current;
6414
+ const kind = chartSkeletonKind(requestedKind), { colors } = useKjunStyles(), reduced = useReducedMotion(), opacity = (0, import_react53.useRef)(new import_react_native42.Animated.Value(1)).current, revealed = useLoadingReveal(true, loadingDelay), [measured, setMeasured] = (0, import_react53.useState)(0), thickness = import_tokens39.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" };
6422
6415
  (0, import_react53.useEffect)(() => {
6423
- if (reduced) return;
6416
+ if (reduced || !skeleton) return;
6424
6417
  const loop = import_react_native42.Animated.loop(
6425
6418
  import_react_native42.Animated.sequence([
6426
- import_react_native42.Animated.timing(opacity, {
6427
- toValue: 0.55,
6428
- duration: import_tokens39.tokens.motion.shimmer / 2,
6429
- useNativeDriver: true
6430
- }),
6431
- import_react_native42.Animated.timing(opacity, {
6432
- toValue: 1,
6433
- duration: import_tokens39.tokens.motion.shimmer / 2,
6434
- useNativeDriver: true
6435
- })
6419
+ import_react_native42.Animated.timing(opacity, { toValue: 0.55, duration: import_tokens39.tokens.motion.shimmer / 2, useNativeDriver: true }),
6420
+ import_react_native42.Animated.timing(opacity, { toValue: 1, duration: import_tokens39.tokens.motion.shimmer / 2, useNativeDriver: true })
6436
6421
  ])
6437
6422
  );
6438
6423
  loop.start();
@@ -6440,92 +6425,68 @@ function KjunChartSkeleton({
6440
6425
  loop.stop();
6441
6426
  opacity.setValue(1);
6442
6427
  };
6443
- }, [opacity, reduced]);
6444
- return /* @__PURE__ */ (0, import_jsx_runtime39.jsxs)(
6428
+ }, [opacity, reduced, skeleton]);
6429
+ return /* @__PURE__ */ (0, import_jsx_runtime39.jsx)(
6445
6430
  import_react_native42.Animated.View,
6446
6431
  {
6447
- style: {
6448
- height,
6449
- alignItems: "center",
6450
- justifyContent: "center",
6451
- width: "100%",
6452
- minWidth: 0,
6453
- opacity
6454
- },
6455
- accessibilityElementsHidden: true,
6456
- importantForAccessibility: "no-hide-descendants",
6457
- children: [
6432
+ onLayout: typeof height === "number" ? void 0 : (event) => setMeasured(event.nativeEvent.layout.height),
6433
+ style: { height, alignItems: "center", justifyContent: "center", width: "100%", minWidth: 0, opacity: revealed ? opacity : 0 },
6434
+ "aria-hidden": revealed ? void 0 : true,
6435
+ importantForAccessibility: revealed ? void 0 : "no-hide-descendants",
6436
+ ...import_react_native42.Platform.OS === "web" ? { dataSet: { kjunChartKind: kind, skeleton: skeleton ? void 0 : "false" } } : {},
6437
+ children: !skeleton ? /* @__PURE__ */ (0, import_jsx_runtime39.jsxs)(import_react_native42.View, { ...chartPart("loading"), role: status, style: { alignItems: "center", gap: import_tokens39.tokens.dimension.value12 }, children: [
6438
+ /* @__PURE__ */ (0, import_jsx_runtime39.jsx)(import_react_native42.View, { ...hidden, children: /* @__PURE__ */ (0, import_jsx_runtime39.jsx)(KjunSpinner, { size: "md" }) }),
6439
+ !!loadingText && /* @__PURE__ */ (0, import_jsx_runtime39.jsx)(KText, { style: { ...typeStyle("body"), color: colors.textSecondary, textAlign: "center", maxWidth: "100%" }, children: loadingText })
6440
+ ] }) : /* @__PURE__ */ (0, import_jsx_runtime39.jsxs)(import_jsx_runtime39.Fragment, { children: [
6458
6441
  kind === "donut" ? /* @__PURE__ */ (0, import_jsx_runtime39.jsx)(
6459
6442
  import_react_native42.View,
6460
6443
  {
6461
- style: {
6462
- height: "80%",
6463
- aspectRatio: 1,
6464
- borderWidth: import_tokens39.tokens.extensions.chartSkeleton.donutThickness,
6465
- borderColor: colors.skeleton,
6466
- borderRadius: import_tokens39.tokens.radius.radius9999,
6467
- alignItems: "center",
6468
- justifyContent: "center"
6469
- },
6470
- children: /* @__PURE__ */ (0, import_jsx_runtime39.jsx)(KjunSkeleton, { type: "block", width: import_tokens39.tokens.extensions.chartSkeleton.donutLabelWidth, height: import_tokens39.tokens.extensions.chartSkeleton.donutLabelHeight })
6444
+ ...chartPart("donut"),
6445
+ ...hidden,
6446
+ style: { height: `${chartDonutRatio * 100}%`, aspectRatio: 1, borderWidth: thickness, borderColor: colors.skeleton, borderRadius: import_tokens39.tokens.radius.radius9999 }
6471
6447
  }
6472
- ) : /* @__PURE__ */ (0, import_jsx_runtime39.jsxs)(
6473
- import_react_native_svg5.default,
6448
+ ) : kind === "matrix" ? /* @__PURE__ */ (0, import_jsx_runtime39.jsx)(import_react_native42.View, { ...chartPart("matrix"), ...hidden, style: { alignSelf: "stretch", flex: 1, gap: import_tokens39.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_tokens39.tokens.dimension.value4 }, children: Array.from({ length: columnCount }, (_2, column) => /* @__PURE__ */ (0, import_jsx_runtime39.jsx)(
6449
+ import_react_native42.View,
6474
6450
  {
6475
- viewBox: "0 0 600 240",
6476
- preserveAspectRatio: "none",
6477
- width: "100%",
6478
- height: "100%",
6479
- children: [
6480
- /* @__PURE__ */ (0, import_jsx_runtime39.jsx)(
6481
- import_react_native_svg5.Path,
6482
- {
6483
- d: "M20 10V220H590 M20 65H590 M20 120H590 M20 175H590",
6484
- fill: "none",
6485
- stroke: colors.border,
6486
- strokeWidth: 1
6487
- }
6488
- ),
6489
- 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" }),
6490
- 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)(
6491
- import_react_native_svg5.Rect,
6492
- {
6493
- x: 24 + col * 40,
6494
- y: 12 + row * 26,
6495
- width: 36,
6496
- height: 22,
6497
- rx: 2,
6498
- fill: colors.skeleton,
6499
- opacity: (row + col + 2) % 3 === 0 ? 0.55 : 1
6451
+ ...chartPart("cell"),
6452
+ style: {
6453
+ flex: 1,
6454
+ borderRadius: import_tokens39.tokens.extensions.skeleton.lineRadius,
6455
+ backgroundColor: colors.skeleton,
6456
+ opacity: chartMatrixMuted(row, column) ? import_tokens39.tokens.states.opacity.pending : 1
6457
+ }
6458
+ },
6459
+ column
6460
+ )) }, 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_tokens39.tokens.border.defaultWidth, vectorEffect: "non-scaling-stroke" }) }) }),
6461
+ !!loadingText && /* @__PURE__ */ (0, import_jsx_runtime39.jsx)(
6462
+ import_react_native42.View,
6463
+ {
6464
+ ...chartPart("status"),
6465
+ role: status,
6466
+ accessibilityLiveRegion: status ? "polite" : void 0,
6467
+ pointerEvents: "none",
6468
+ style: { position: "absolute", inset: 0, alignItems: "center", justifyContent: "center" },
6469
+ children: /* @__PURE__ */ (0, import_jsx_runtime39.jsx)(
6470
+ KText,
6471
+ {
6472
+ style: {
6473
+ ...typeStyle("body"),
6474
+ paddingHorizontal: import_tokens39.tokens.dimension.value12,
6475
+ paddingVertical: import_tokens39.tokens.dimension.value4,
6476
+ borderRadius: import_tokens39.tokens.radius.radius6,
6477
+ borderWidth: kind === "donut" ? 0 : import_tokens39.tokens.border.defaultWidth,
6478
+ borderColor: colors.chartGrid,
6479
+ backgroundColor: colors.surface,
6480
+ color: colors.textSecondary,
6481
+ maxWidth: kind === "donut" && hole != null ? hole : "90%",
6482
+ textAlign: "center"
6500
6483
  },
6501
- col
6502
- )) }, row)) : (kind === "bar" || kind === "candle") && [60, 100, 85, 140, 110, 165, 180].map((h, i) => /* @__PURE__ */ (0, import_jsx_runtime39.jsxs)(import_react53.Fragment, { children: [
6503
- kind === "candle" && /* @__PURE__ */ (0, import_jsx_runtime39.jsx)(
6504
- import_react_native_svg5.Path,
6505
- {
6506
- d: `M${55 + i * 75} ${195 - h}V${225 - h / 2}`,
6507
- fill: "none",
6508
- stroke: colors.skeleton,
6509
- strokeWidth: 4
6510
- }
6511
- ),
6512
- /* @__PURE__ */ (0, import_jsx_runtime39.jsx)(
6513
- import_react_native_svg5.Rect,
6514
- {
6515
- x: 35 + i * 75,
6516
- y: kind === "candle" ? 210 - h : 220 - h,
6517
- width: kind === "candle" ? 28 : 42,
6518
- height: kind === "candle" ? h / 2 : h,
6519
- rx: 3,
6520
- fill: colors.skeleton
6521
- }
6522
- )
6523
- ] }, i))
6524
- ]
6484
+ children: loadingText
6485
+ }
6486
+ )
6525
6487
  }
6526
- ),
6527
- /* @__PURE__ */ (0, import_jsx_runtime39.jsx)(import_react_native42.View, { pointerEvents: "none", style: { position: "absolute", inset: 0, alignItems: "center", justifyContent: "center", gap: import_tokens39.tokens.dimension.value12 }, children: !!loadingText && /* @__PURE__ */ (0, import_jsx_runtime39.jsx)(KText, { style: { ...typeStyle("body"), paddingHorizontal: import_tokens39.tokens.dimension.value12, paddingVertical: import_tokens39.tokens.dimension.value4, borderRadius: import_tokens39.tokens.radius.radius6, backgroundColor: colors.surface, color: colors.textSecondary, maxWidth: "90%", textAlign: "center" }, children: loadingText }) })
6528
- ]
6488
+ )
6489
+ ] })
6529
6490
  }
6530
6491
  );
6531
6492
  }