wimui 0.27.0 → 0.29.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/charts.cjs +1 -1
  2. package/dist/charts.d.ts +4 -0
  3. package/dist/charts.js +5 -1
  4. package/dist/components/_internal/barSpan.cjs +2 -0
  5. package/dist/components/_internal/barSpan.d.ts +60 -0
  6. package/dist/components/_internal/barSpan.js +13 -0
  7. package/dist/components/_internal/chartTableData.cjs +0 -0
  8. package/dist/components/_internal/chartTableData.d.ts +55 -0
  9. package/dist/components/_internal/chartTableData.js +0 -0
  10. package/dist/components/charts/BoxPlot/BoxPlot.cjs +2 -0
  11. package/dist/components/charts/BoxPlot/BoxPlot.d.ts +50 -0
  12. package/dist/components/charts/BoxPlot/BoxPlot.js +130 -0
  13. package/dist/components/charts/BoxPlot/box-plot.module.cjs +2 -0
  14. package/dist/components/charts/BoxPlot/box-plot.module.js +11 -0
  15. package/dist/components/charts/CandlestickChart/CandlestickChart.cjs +2 -0
  16. package/dist/components/charts/CandlestickChart/CandlestickChart.d.ts +48 -0
  17. package/dist/components/charts/CandlestickChart/CandlestickChart.js +119 -0
  18. package/dist/components/charts/CandlestickChart/candlestick-chart.module.cjs +2 -0
  19. package/dist/components/charts/CandlestickChart/candlestick-chart.module.js +13 -0
  20. package/dist/components/charts/SankeyChart/SankeyChart.cjs +2 -0
  21. package/dist/components/charts/SankeyChart/SankeyChart.d.ts +54 -0
  22. package/dist/components/charts/SankeyChart/SankeyChart.js +106 -0
  23. package/dist/components/charts/SankeyChart/sankey-chart.module.cjs +2 -0
  24. package/dist/components/charts/SankeyChart/sankey-chart.module.js +9 -0
  25. package/dist/components/charts/SankeyChart/warn-unknown-node.cjs +2 -0
  26. package/dist/components/charts/SankeyChart/warn-unknown-node.d.ts +9 -0
  27. package/dist/components/charts/SankeyChart/warn-unknown-node.js +5 -0
  28. package/dist/components/charts/WaterfallChart/WaterfallChart.cjs +2 -0
  29. package/dist/components/charts/WaterfallChart/WaterfallChart.d.ts +53 -0
  30. package/dist/components/charts/WaterfallChart/WaterfallChart.js +128 -0
  31. package/dist/components/charts/WaterfallChart/waterfall-chart.module.cjs +2 -0
  32. package/dist/components/charts/WaterfallChart/waterfall-chart.module.js +9 -0
  33. package/dist/components/data-display/Barcode/Barcode.cjs +2 -0
  34. package/dist/components/data-display/Barcode/Barcode.d.ts +86 -0
  35. package/dist/components/data-display/Barcode/Barcode.js +120 -0
  36. package/dist/components/data-display/Barcode/barcode.module.cjs +2 -0
  37. package/dist/components/data-display/Barcode/barcode.module.js +13 -0
  38. package/dist/components/data-display/Barcode/encode.cjs +2 -0
  39. package/dist/components/data-display/Barcode/encode.d.ts +64 -0
  40. package/dist/components/data-display/Barcode/encode.js +113 -0
  41. package/dist/components/data-display/Barcode/warn-unencodable-value.cjs +2 -0
  42. package/dist/components/data-display/Barcode/warn-unencodable-value.d.ts +3 -0
  43. package/dist/components/data-display/Barcode/warn-unencodable-value.js +4 -0
  44. package/dist/components/data-display/Comment/Comment.cjs +2 -0
  45. package/dist/components/data-display/Comment/Comment.d.ts +132 -0
  46. package/dist/components/data-display/Comment/Comment.js +86 -0
  47. package/dist/components/data-display/Comment/comment.module.cjs +2 -0
  48. package/dist/components/data-display/Comment/comment.module.js +19 -0
  49. package/dist/data-display-core.d.ts +2 -0
  50. package/dist/data-display.cjs +1 -1
  51. package/dist/data-display.js +5 -3
  52. package/dist/i18n/generated/keys.d.ts +1 -1
  53. package/dist/i18n/generated/resources.cjs +1 -1
  54. package/dist/i18n/generated/resources.js +33 -0
  55. package/dist/index.cjs +1 -1
  56. package/dist/index.js +42 -40
  57. package/dist/llms-full.txt +82 -1
  58. package/dist/llms.txt +7 -1
  59. package/dist/locales/en/common.json +20 -7
  60. package/dist/locales/en/components.json +3 -1
  61. package/dist/locales/en/data-display.json +1 -2
  62. package/dist/locales/ja/common.json +20 -7
  63. package/dist/locales/ja/components.json +3 -1
  64. package/dist/locales/ja/data-display.json +1 -2
  65. package/dist/locales/pt/common.json +20 -7
  66. package/dist/locales/pt/components.json +3 -1
  67. package/dist/locales/pt/data-display.json +1 -2
  68. package/dist/styles.css +1 -1
  69. package/dist/wimui.umd.css +1 -1
  70. package/dist/wimui.umd.js +5 -5
  71. package/package.json +2 -2
@@ -0,0 +1,106 @@
1
+ "use client";
2
+ import { Title as e } from "../../typography/Title/Title.js";
3
+ import { CHART_COLORS as t, CHART_HIDDEN_A11Y_PROPS as n, CHART_THEME as r } from "../../helpers.js";
4
+ import { ChartDataTable as i } from "../../_internal/ChartDataTable.js";
5
+ import { linkTable as a } from "../../_internal/chartTableData.js";
6
+ import { warnDuplicateSankeyNode as o, warnUnknownSankeyNode as s } from "./warn-unknown-node.js";
7
+ import c from "./sankey-chart.module.js";
8
+ import "react";
9
+ import { jsx as l, jsxs as u } from "react/jsx-runtime";
10
+ import { ResponsiveContainer as d, Sankey as f, Tooltip as p } from "recharts";
11
+ //#region src/components/charts/SankeyChart/SankeyChart.tsx
12
+ var m = 12, h = 24, g = 8, _ = ({ x: e = 0, y: n = 0, width: r = 0, height: i = 0, index: a = 0, payload: o }) => {
13
+ let s = (o?.targetNodes?.length ?? 0) === 0;
14
+ return /* @__PURE__ */ u("g", { children: [/* @__PURE__ */ l("rect", {
15
+ x: e,
16
+ y: n,
17
+ width: r,
18
+ height: i,
19
+ fill: t[a % t.length],
20
+ rx: 2
21
+ }), /* @__PURE__ */ l("text", {
22
+ className: c.label,
23
+ x: s ? e - g : e + r + g,
24
+ y: n + i / 2,
25
+ textAnchor: s ? "end" : "start",
26
+ dominantBaseline: "middle",
27
+ children: o?.name
28
+ })] });
29
+ }, v = ({ sourceX: e = 0, targetX: n = 0, sourceY: r = 0, targetY: i = 0, sourceControlX: a = 0, targetControlX: o = 0, linkWidth: s = 0, payload: c, colorIndexOf: u }) => {
30
+ let d = c?.source?.name, f = (d === void 0 ? void 0 : u?.get(d)) ?? 0;
31
+ return /* @__PURE__ */ l("path", {
32
+ d: `M${e},${r}C${a},${r} ${o},${i} ${n},${i}`,
33
+ fill: "none",
34
+ stroke: t[f % t.length],
35
+ strokeWidth: s,
36
+ strokeOpacity: .28
37
+ });
38
+ }, y = ({ nodes: t, links: g, height: y = 300, width: b = "100%", title: x, "aria-label": S }) => {
39
+ let C = S ?? x, w = /* @__PURE__ */ new Map();
40
+ t.forEach((e, t) => {
41
+ if (w.has(e)) {
42
+ o(e);
43
+ return;
44
+ }
45
+ w.set(e, t);
46
+ });
47
+ let T = g.filter((e) => {
48
+ let n = w.has(e.source) ? w.has(e.target) ? null : e.target : e.source;
49
+ return n === null ? !0 : (s(n, t), !1);
50
+ }), E = a(T);
51
+ return /* @__PURE__ */ u("div", {
52
+ className: `wim-sankey-chart ${c.root}`,
53
+ style: { width: b },
54
+ role: C ? "figure" : void 0,
55
+ "aria-label": C,
56
+ children: [
57
+ x && /* @__PURE__ */ l(e, {
58
+ tag: "h3",
59
+ size: "md",
60
+ style: { marginBottom: "var(--wim-spacing-md)" },
61
+ children: x
62
+ }),
63
+ /* @__PURE__ */ l("div", {
64
+ className: c.container,
65
+ style: { height: y },
66
+ "aria-hidden": "true",
67
+ children: /* @__PURE__ */ l(d, {
68
+ width: "100%",
69
+ height: "100%",
70
+ children: /* @__PURE__ */ l(f, {
71
+ ...n,
72
+ data: {
73
+ nodes: t.map((e) => ({ name: e })),
74
+ links: T.map((e) => ({
75
+ source: w.get(e.source),
76
+ target: w.get(e.target),
77
+ value: e.value
78
+ }))
79
+ },
80
+ nodeWidth: m,
81
+ nodePadding: h,
82
+ margin: {
83
+ top: 8,
84
+ right: 8,
85
+ bottom: 8,
86
+ left: 8
87
+ },
88
+ node: /* @__PURE__ */ l(_, {}),
89
+ link: /* @__PURE__ */ l(v, { colorIndexOf: w }),
90
+ children: /* @__PURE__ */ l(p, {
91
+ contentStyle: r.tooltip.contentStyle,
92
+ cursor: r.tooltip.cursor
93
+ })
94
+ })
95
+ })
96
+ }),
97
+ /* @__PURE__ */ l(i, {
98
+ caption: C,
99
+ columns: E.columns,
100
+ rows: E.rows
101
+ })
102
+ ]
103
+ });
104
+ };
105
+ //#endregion
106
+ export { y as SankeyChart };
@@ -0,0 +1,2 @@
1
+ "use client";
2
+ var e=`_root_165yr_3`,t=`_container_165yr_6`,n=`_label_165yr_14`,r={root:e,container:t,label:n};exports.container=t,exports.default=r,exports.label=n,exports.root=e;
@@ -0,0 +1,9 @@
1
+ "use client";
2
+ //#region src/components/charts/SankeyChart/sankey-chart.module.scss
3
+ var e = "_root_165yr_3", t = "_container_165yr_6", n = "_label_165yr_14", r = {
4
+ root: e,
5
+ container: t,
6
+ label: n
7
+ };
8
+ //#endregion
9
+ export { t as container, r as default, n as label, e as root };
@@ -0,0 +1,2 @@
1
+ "use client";
2
+ function e(e,t){}function t(e){}exports.warnDuplicateSankeyNode=t,exports.warnUnknownSankeyNode=e;
@@ -0,0 +1,9 @@
1
+ /** `links` が `nodes` に無い名前を指した。その流れは描けないので落とす。 */
2
+ export declare function warnUnknownSankeyNode(missing: string, nodes: readonly string[]): void;
3
+ /**
4
+ * `nodes` に同じ名前が 2 つ以上ある。`links` は名前で node を指すので、
5
+ * **2 つ目以降には 1 本も届かない** ── その段は空のまま描かれ、量だけが消える。
6
+ */
7
+ export declare function warnDuplicateSankeyNode(duplicate: string): void;
8
+ /** Test seam — the warn-once set is module state. */
9
+ export declare function resetSankeyWarnings(): void;
@@ -0,0 +1,5 @@
1
+ "use client";
2
+ function e(e, t) {}
3
+ function t(e) {}
4
+ //#endregion
5
+ export { t as warnDuplicateSankeyNode, e as warnUnknownSankeyNode };
@@ -0,0 +1,2 @@
1
+ "use client";
2
+ const e=require("../../../_virtual/_rolldown/runtime.cjs"),t=require("../../typography/Title/Title.cjs"),n=require("../../helpers.cjs"),r=require("../../_internal/ChartDataTable.cjs"),i=require("../../_internal/chartTableData.cjs"),a=require("../../_internal/barSpan.cjs"),o=require("./waterfall-chart.module.cjs");let s=require("react");s=e.__toESM(s,1);let c=require("react/jsx-runtime"),l=require("recharts");var u={increase:`var(--wim-color-chart-success)`,decrease:`var(--wim-color-chart-danger)`,total:`var(--wim-color-chart-primary)`},d=e=>{let t=0;return(e??[]).map(e=>{let n=a.isFiniteNumber(e?.value)?e.value:0;if(e?.total){let n=t<0?[t,0]:[0,t];return{name:e.name,span:n,kind:`total`,amount:t,running:t}}let r=t;t+=n;let i=r<t?[r,t]:[t,r];return{name:e.name,span:i,kind:n<0?`decrease`:`increase`,amount:n,running:t}})},f=e=>e.kind===`total`||e.amount<0?String(e.amount):`+${e.amount}`,p=({x:e=0,y:t=0,width:n=0,height:r=0,payload:i})=>i?(0,c.jsxs)(`g`,{children:[(0,c.jsx)(`rect`,{x:e,y:t,width:n,height:Math.max(r,1),fill:u[i.kind],rx:2}),(0,c.jsx)(`text`,{className:o.default.value,x:e+n/2,y:t-6,textAnchor:`middle`,children:f(i)})]}):null,m=({data:e,height:a=300,width:s=`100%`,title:u,"aria-label":m})=>{let h=m??u,g=d(e),_=i.stepTable(g.map(e=>({name:e.name,change:f(e),running:e.running})));return(0,c.jsxs)(`div`,{className:`wim-waterfall-chart ${o.default.root}`,style:{width:s},role:h?`figure`:void 0,"aria-label":h,children:[u&&(0,c.jsx)(t.Title,{tag:`h3`,size:`md`,style:{marginBottom:`var(--wim-spacing-md)`},children:u}),(0,c.jsx)(`div`,{className:o.default.container,style:{height:a},"aria-hidden":`true`,children:(0,c.jsx)(l.ResponsiveContainer,{width:`100%`,height:`100%`,children:(0,c.jsxs)(l.BarChart,{...n.CHART_HIDDEN_A11Y_PROPS,data:g,margin:{top:20,right:30,left:0,bottom:5},children:[(0,c.jsx)(l.CartesianGrid,{...n.CHART_THEME.grid,vertical:!1}),(0,c.jsx)(l.XAxis,{dataKey:`name`,interval:0,...n.CHART_THEME.axis,tickLine:!1,axisLine:!1}),(0,c.jsx)(l.YAxis,{width:44,...n.CHART_THEME.axis,tickLine:!1,axisLine:!1}),(0,c.jsx)(l.Tooltip,{contentStyle:n.CHART_THEME.tooltip.contentStyle,cursor:n.CHART_THEME.tooltip.cursor}),(0,c.jsx)(l.Bar,{dataKey:`span`,shape:(0,c.jsx)(p,{}),isAnimationActive:!1})]})})}),(0,c.jsx)(r.ChartDataTable,{caption:h,columns:_.columns,rows:_.rows})]})};exports.WaterfallChart=m;
@@ -0,0 +1,53 @@
1
+ import { default as React } from 'react';
2
+ export type WaterfallItem = {
3
+ /** Label for this step, shown on the X axis. */
4
+ name: string;
5
+ /**
6
+ * How much this step adds (positive) or removes (negative) from the running
7
+ * total. On a `total` step this is ignored — the bar is drawn to the running
8
+ * total instead.
9
+ */
10
+ value: number;
11
+ /**
12
+ * Draw this step as a total: a bar from the baseline up to the running total,
13
+ * rather than a floating change. Use it for the opening and closing columns.
14
+ * @default false
15
+ */
16
+ total?: boolean;
17
+ };
18
+ export type WaterfallChartProps = {
19
+ /** The steps, in the order they are applied. */
20
+ data: WaterfallItem[];
21
+ /**
22
+ * The height of the chart in pixels.
23
+ * @default 300
24
+ */
25
+ height?: number;
26
+ /**
27
+ * The width of the chart (e.g., "100%", 500).
28
+ * @default "100%"
29
+ */
30
+ width?: string | number;
31
+ /** Optional title displayed above the chart. */
32
+ title?: string;
33
+ /**
34
+ * Accessible name for the chart. Defaults to `title` when omitted; pass this
35
+ * when the chart has no visible title, or when the title is not descriptive
36
+ * enough on its own.
37
+ */
38
+ "aria-label"?: string;
39
+ };
40
+ /**
41
+ * Shows how a starting number becomes an ending number, one contribution at a
42
+ * time — revenue to profit, last month's headcount to this month's, a budget
43
+ * to what is left of it.
44
+ *
45
+ * **Each bar floats between the running total before and after that step**,
46
+ * which is what a stacked `BarChart` cannot express: stacking shows the parts
47
+ * of one total, not the arithmetic that produced it.
48
+ *
49
+ * Composition Contract:
50
+ * - Managed by: App consumption
51
+ * - Scroll lock: No
52
+ */
53
+ export declare const WaterfallChart: ({ data, height, width, title, "aria-label": ariaLabel, }: WaterfallChartProps) => React.JSX.Element;
@@ -0,0 +1,128 @@
1
+ "use client";
2
+ import { Title as e } from "../../typography/Title/Title.js";
3
+ import { CHART_HIDDEN_A11Y_PROPS as t, CHART_THEME as n } from "../../helpers.js";
4
+ import { ChartDataTable as r } from "../../_internal/ChartDataTable.js";
5
+ import { stepTable as i } from "../../_internal/chartTableData.js";
6
+ import { isFiniteNumber as a } from "../../_internal/barSpan.js";
7
+ import o from "./waterfall-chart.module.js";
8
+ import "react";
9
+ import { jsx as s, jsxs as c } from "react/jsx-runtime";
10
+ import { Bar as l, BarChart as u, CartesianGrid as d, ResponsiveContainer as f, Tooltip as p, XAxis as m, YAxis as h } from "recharts";
11
+ //#region src/components/charts/WaterfallChart/WaterfallChart.tsx
12
+ var g = {
13
+ increase: "var(--wim-color-chart-success)",
14
+ decrease: "var(--wim-color-chart-danger)",
15
+ total: "var(--wim-color-chart-primary)"
16
+ }, _ = (e) => {
17
+ let t = 0;
18
+ return (e ?? []).map((e) => {
19
+ let n = a(e?.value) ? e.value : 0;
20
+ if (e?.total) {
21
+ let n = t < 0 ? [t, 0] : [0, t];
22
+ return {
23
+ name: e.name,
24
+ span: n,
25
+ kind: "total",
26
+ amount: t,
27
+ running: t
28
+ };
29
+ }
30
+ let r = t;
31
+ t += n;
32
+ let i = r < t ? [r, t] : [t, r];
33
+ return {
34
+ name: e.name,
35
+ span: i,
36
+ kind: n < 0 ? "decrease" : "increase",
37
+ amount: n,
38
+ running: t
39
+ };
40
+ });
41
+ }, v = (e) => e.kind === "total" || e.amount < 0 ? String(e.amount) : `+${e.amount}`, y = ({ x: e = 0, y: t = 0, width: n = 0, height: r = 0, payload: i }) => i ? /* @__PURE__ */ c("g", { children: [/* @__PURE__ */ s("rect", {
42
+ x: e,
43
+ y: t,
44
+ width: n,
45
+ height: Math.max(r, 1),
46
+ fill: g[i.kind],
47
+ rx: 2
48
+ }), /* @__PURE__ */ s("text", {
49
+ className: o.value,
50
+ x: e + n / 2,
51
+ y: t - 6,
52
+ textAnchor: "middle",
53
+ children: v(i)
54
+ })] }) : null, b = ({ data: a, height: g = 300, width: b = "100%", title: x, "aria-label": S }) => {
55
+ let C = S ?? x, w = _(a), T = i(w.map((e) => ({
56
+ name: e.name,
57
+ change: v(e),
58
+ running: e.running
59
+ })));
60
+ return /* @__PURE__ */ c("div", {
61
+ className: `wim-waterfall-chart ${o.root}`,
62
+ style: { width: b },
63
+ role: C ? "figure" : void 0,
64
+ "aria-label": C,
65
+ children: [
66
+ x && /* @__PURE__ */ s(e, {
67
+ tag: "h3",
68
+ size: "md",
69
+ style: { marginBottom: "var(--wim-spacing-md)" },
70
+ children: x
71
+ }),
72
+ /* @__PURE__ */ s("div", {
73
+ className: o.container,
74
+ style: { height: g },
75
+ "aria-hidden": "true",
76
+ children: /* @__PURE__ */ s(f, {
77
+ width: "100%",
78
+ height: "100%",
79
+ children: /* @__PURE__ */ c(u, {
80
+ ...t,
81
+ data: w,
82
+ margin: {
83
+ top: 20,
84
+ right: 30,
85
+ left: 0,
86
+ bottom: 5
87
+ },
88
+ children: [
89
+ /* @__PURE__ */ s(d, {
90
+ ...n.grid,
91
+ vertical: !1
92
+ }),
93
+ /* @__PURE__ */ s(m, {
94
+ dataKey: "name",
95
+ interval: 0,
96
+ ...n.axis,
97
+ tickLine: !1,
98
+ axisLine: !1
99
+ }),
100
+ /* @__PURE__ */ s(h, {
101
+ width: 44,
102
+ ...n.axis,
103
+ tickLine: !1,
104
+ axisLine: !1
105
+ }),
106
+ /* @__PURE__ */ s(p, {
107
+ contentStyle: n.tooltip.contentStyle,
108
+ cursor: n.tooltip.cursor
109
+ }),
110
+ /* @__PURE__ */ s(l, {
111
+ dataKey: "span",
112
+ shape: /* @__PURE__ */ s(y, {}),
113
+ isAnimationActive: !1
114
+ })
115
+ ]
116
+ })
117
+ })
118
+ }),
119
+ /* @__PURE__ */ s(r, {
120
+ caption: C,
121
+ columns: T.columns,
122
+ rows: T.rows
123
+ })
124
+ ]
125
+ });
126
+ };
127
+ //#endregion
128
+ export { b as WaterfallChart };
@@ -0,0 +1,2 @@
1
+ "use client";
2
+ var e=`_root_1bf2i_3`,t=`_container_1bf2i_6`,n=`_value_1bf2i_14`,r={root:e,container:t,value:n};exports.container=t,exports.default=r,exports.root=e,exports.value=n;
@@ -0,0 +1,9 @@
1
+ "use client";
2
+ //#region src/components/charts/WaterfallChart/waterfall-chart.module.scss
3
+ var e = "_root_1bf2i_3", t = "_container_1bf2i_6", n = "_value_1bf2i_14", r = {
4
+ root: e,
5
+ container: t,
6
+ value: n
7
+ };
8
+ //#endregion
9
+ export { t as container, r as default, e as root, n as value };
@@ -0,0 +1,2 @@
1
+ "use client";
2
+ const e=require("../../../_virtual/_rolldown/runtime.cjs"),t=require("../../../i18n/useWimTranslation.cjs"),n=require("../../../hooks/useMergedRef.cjs"),r=require("./encode.cjs"),i=require("./warn-unencodable-value.cjs"),a=require("./barcode.module.cjs");let o=require("react");o=e.__toESM(o,1);let s=require("classnames");s=e.__toESM(s,1);let c=require("react/jsx-runtime");var l={code128:`Code 128`,ean13:`EAN-13`},u=11,d=8,f=.35,p=7,m=o.default.forwardRef(({value:e,format:m=`code128`,height:h=64,moduleWidth:g=2,showValue:_=!0,label:v,className:y,...b},x)=>{let{t:S}=t.useWimTranslation(`common`),C=r.encodeBarcode(e,m),w=o.default.useRef(null),[T,E]=o.default.useState(!1);o.default.useLayoutEffect(()=>{let e=w.current;if(!e||typeof ResizeObserver>`u`)return;let t=()=>E(e.scrollWidth>e.clientWidth);t();let n=new ResizeObserver(t);return n.observe(e),()=>n.disconnect()},[C?.modules,g]);let D=n.useMergedRef(x,w);if(!C){i.warnUnencodableValue(e,m,l[m]);let t=S(`barcode.invalid`,{format:l[m]});return(0,c.jsxs)(`div`,{ref:D,"data-invalid":`true`,className:(0,s.default)(`wim-barcode`,a.default.root,a.default.invalid,y),...b,children:[(0,c.jsx)(`span`,{className:a.default.invalidMessage,children:t}),(0,c.jsx)(`span`,{className:a.default.invalidValue,children:e})]})}let O=C.modules.length+u*2,k=O*g,A=u,j=r.toRuns(C.modules).map(([e,t])=>{let n=A;return A+=t,e?{x:n,width:t,module:n-u}:null}),M=m===`ean13`&&_?C.print:void 0,N=M?Math.min(d*g,h*f):0,P=h-N,F=e=>M?M.guards.some(([t,n])=>e.module>=t&&e.module+e.width<=n):!1,I=M?[...[...M.left.text].map((e,t)=>({key:`l${t}`,digit:e,module:M.left.from+t*p+p/2})),...[...M.right.text].map((e,t)=>({key:`r${t}`,digit:e,module:M.right.from+t*p+p/2}))]:[];return(0,c.jsxs)(`div`,{ref:D,role:`img`,tabIndex:T?0:void 0,"aria-label":v??S(`barcode.aria_label`,{value:C.text}),"data-format":m,className:(0,s.default)(`wim-barcode`,a.default.root,y),...b,children:[M?(0,c.jsxs)(`svg`,{className:a.default.symbol,width:k,height:h,viewBox:`0 0 ${k} ${h}`,shapeRendering:`crispEdges`,"aria-hidden":`true`,children:[j.map(e=>e?(0,c.jsx)(`rect`,{x:e.x*g,y:0,width:e.width*g,height:F(e)?h:P,"data-guard":F(e)?`true`:void 0},e.x):null),(0,c.jsx)(`text`,{className:a.default.printedDigit,x:(u-1)*g,y:h,textAnchor:`end`,fontSize:N*.86,children:M.lead}),I.map(e=>(0,c.jsx)(`text`,{className:a.default.printedDigit,x:(u+e.module)*g,y:h,textAnchor:`middle`,fontSize:N*.86,children:e.digit},e.key))]}):(0,c.jsx)(`svg`,{className:a.default.symbol,width:k,height:h,viewBox:`0 0 ${O} ${h}`,preserveAspectRatio:`none`,shapeRendering:`crispEdges`,"aria-hidden":`true`,children:j.map(e=>e?(0,c.jsx)(`rect`,{x:e.x,y:0,width:e.width,height:h},e.x):null)}),_&&!M?(0,c.jsx)(`span`,{className:a.default.value,children:C.text}):null]})});m.displayName=`Barcode`,exports.Barcode=m;
@@ -0,0 +1,86 @@
1
+ import { default as React } from 'react';
2
+ import { BarcodeFormat } from './encode';
3
+ export type { BarcodeFormat };
4
+ export type BarcodeProps = Omit<React.ComponentPropsWithoutRef<"div">, "children"> & {
5
+ /**
6
+ * Value to encode. For `ean13`, 12 digits (the check digit is calculated) or
7
+ * 13 digits (the check digit is verified).
8
+ */
9
+ value: string;
10
+ /**
11
+ * Symbology to encode `value` in.
12
+ * @default "code128"
13
+ */
14
+ format?: BarcodeFormat;
15
+ /**
16
+ * Height of the bars, in px.
17
+ * @default 64
18
+ */
19
+ height?: number;
20
+ /**
21
+ * Width of the narrowest bar, in px. Below 2 most phone cameras stop reading
22
+ * the symbol on screen.
23
+ * @default 2
24
+ */
25
+ moduleWidth?: number;
26
+ /**
27
+ * Whether the value is printed under the bars.
28
+ * @default true
29
+ */
30
+ showValue?: boolean;
31
+ /**
32
+ * Accessible name. Defaults to the value, so that a screen reader can read out
33
+ * what a scanner would read.
34
+ */
35
+ label?: string;
36
+ };
37
+ /**
38
+ * Draws a scannable 1D barcode — Code 128 for logistics, tickets and internal
39
+ * SKUs, EAN-13 for retail product codes.
40
+ *
41
+ * Two things are deliberate. **The symbol keeps dark bars on a light background
42
+ * in both themes**: laser and CCD scanners are built for that polarity and read
43
+ * an inverted symbol unreliably, so following the theme here would produce a
44
+ * barcode that looks right and does not scan. And **a value that cannot be
45
+ * encoded is never drawn** — an approximate barcode scans to the wrong thing,
46
+ * which is worse than one that is visibly missing. For the same reason the
47
+ * symbol is never scaled down to fit a narrow container: it scrolls instead,
48
+ * because a squeezed symbol looks identical and stops being read.
49
+ *
50
+ * Composition Contract:
51
+ * - Managed by: App consumption
52
+ * - Scroll lock: No
53
+ */
54
+ export declare const Barcode: React.ForwardRefExoticComponent<Omit<Omit<React.DetailedHTMLProps<React.HTMLAttributes<HTMLDivElement>, HTMLDivElement>, "ref">, "children"> & {
55
+ /**
56
+ * Value to encode. For `ean13`, 12 digits (the check digit is calculated) or
57
+ * 13 digits (the check digit is verified).
58
+ */
59
+ value: string;
60
+ /**
61
+ * Symbology to encode `value` in.
62
+ * @default "code128"
63
+ */
64
+ format?: BarcodeFormat;
65
+ /**
66
+ * Height of the bars, in px.
67
+ * @default 64
68
+ */
69
+ height?: number;
70
+ /**
71
+ * Width of the narrowest bar, in px. Below 2 most phone cameras stop reading
72
+ * the symbol on screen.
73
+ * @default 2
74
+ */
75
+ moduleWidth?: number;
76
+ /**
77
+ * Whether the value is printed under the bars.
78
+ * @default true
79
+ */
80
+ showValue?: boolean;
81
+ /**
82
+ * Accessible name. Defaults to the value, so that a screen reader can read out
83
+ * what a scanner would read.
84
+ */
85
+ label?: string;
86
+ } & React.RefAttributes<HTMLDivElement>>;
@@ -0,0 +1,120 @@
1
+ "use client";
2
+ import { useWimTranslation as e } from "../../../i18n/useWimTranslation.js";
3
+ import { useMergedRef as t } from "../../../hooks/useMergedRef.js";
4
+ import { encodeBarcode as n, toRuns as r } from "./encode.js";
5
+ import { warnUnencodableValue as i } from "./warn-unencodable-value.js";
6
+ import a from "./barcode.module.js";
7
+ import o from "react";
8
+ import s from "classnames";
9
+ import { jsx as c, jsxs as l } from "react/jsx-runtime";
10
+ //#region src/components/data-display/Barcode/Barcode.tsx
11
+ var u = {
12
+ code128: "Code 128",
13
+ ean13: "EAN-13"
14
+ }, d = 11, f = 8, p = .35, m = 7, h = o.forwardRef(({ value: h, format: g = "code128", height: _ = 64, moduleWidth: v = 2, showValue: y = !0, label: b, className: x, ...S }, C) => {
15
+ let { t: w } = e("common"), T = n(h, g), E = o.useRef(null), [D, O] = o.useState(!1);
16
+ o.useLayoutEffect(() => {
17
+ let e = E.current;
18
+ if (!e || typeof ResizeObserver > "u") return;
19
+ let t = () => O(e.scrollWidth > e.clientWidth);
20
+ t();
21
+ let n = new ResizeObserver(t);
22
+ return n.observe(e), () => n.disconnect();
23
+ }, [T?.modules, v]);
24
+ let k = t(C, E);
25
+ if (!T) {
26
+ i(h, g, u[g]);
27
+ let e = w("barcode.invalid", { format: u[g] });
28
+ return /* @__PURE__ */ l("div", {
29
+ ref: k,
30
+ "data-invalid": "true",
31
+ className: s("wim-barcode", a.root, a.invalid, x),
32
+ ...S,
33
+ children: [/* @__PURE__ */ c("span", {
34
+ className: a.invalidMessage,
35
+ children: e
36
+ }), /* @__PURE__ */ c("span", {
37
+ className: a.invalidValue,
38
+ children: h
39
+ })]
40
+ });
41
+ }
42
+ let A = T.modules.length + d * 2, j = A * v, M = d, N = r(T.modules).map(([e, t]) => {
43
+ let n = M;
44
+ return M += t, e ? {
45
+ x: n,
46
+ width: t,
47
+ module: n - d
48
+ } : null;
49
+ }), P = g === "ean13" && y ? T.print : void 0, F = P ? Math.min(f * v, _ * p) : 0, I = _ - F, L = (e) => P ? P.guards.some(([t, n]) => e.module >= t && e.module + e.width <= n) : !1, R = P ? [...[...P.left.text].map((e, t) => ({
50
+ key: `l${t}`,
51
+ digit: e,
52
+ module: P.left.from + t * m + m / 2
53
+ })), ...[...P.right.text].map((e, t) => ({
54
+ key: `r${t}`,
55
+ digit: e,
56
+ module: P.right.from + t * m + m / 2
57
+ }))] : [];
58
+ return /* @__PURE__ */ l("div", {
59
+ ref: k,
60
+ role: "img",
61
+ tabIndex: D ? 0 : void 0,
62
+ "aria-label": b ?? w("barcode.aria_label", { value: T.text }),
63
+ "data-format": g,
64
+ className: s("wim-barcode", a.root, x),
65
+ ...S,
66
+ children: [P ? /* @__PURE__ */ l("svg", {
67
+ className: a.symbol,
68
+ width: j,
69
+ height: _,
70
+ viewBox: `0 0 ${j} ${_}`,
71
+ shapeRendering: "crispEdges",
72
+ "aria-hidden": "true",
73
+ children: [
74
+ N.map((e) => e ? /* @__PURE__ */ c("rect", {
75
+ x: e.x * v,
76
+ y: 0,
77
+ width: e.width * v,
78
+ height: L(e) ? _ : I,
79
+ "data-guard": L(e) ? "true" : void 0
80
+ }, e.x) : null),
81
+ /* @__PURE__ */ c("text", {
82
+ className: a.printedDigit,
83
+ x: (d - 1) * v,
84
+ y: _,
85
+ textAnchor: "end",
86
+ fontSize: F * .86,
87
+ children: P.lead
88
+ }),
89
+ R.map((e) => /* @__PURE__ */ c("text", {
90
+ className: a.printedDigit,
91
+ x: (d + e.module) * v,
92
+ y: _,
93
+ textAnchor: "middle",
94
+ fontSize: F * .86,
95
+ children: e.digit
96
+ }, e.key))
97
+ ]
98
+ }) : /* @__PURE__ */ c("svg", {
99
+ className: a.symbol,
100
+ width: j,
101
+ height: _,
102
+ viewBox: `0 0 ${A} ${_}`,
103
+ preserveAspectRatio: "none",
104
+ shapeRendering: "crispEdges",
105
+ "aria-hidden": "true",
106
+ children: N.map((e) => e ? /* @__PURE__ */ c("rect", {
107
+ x: e.x,
108
+ y: 0,
109
+ width: e.width,
110
+ height: _
111
+ }, e.x) : null)
112
+ }), y && !P ? /* @__PURE__ */ c("span", {
113
+ className: a.value,
114
+ children: T.text
115
+ }) : null]
116
+ });
117
+ });
118
+ h.displayName = "Barcode";
119
+ //#endregion
120
+ export { h as Barcode };
@@ -0,0 +1,2 @@
1
+ "use client";
2
+ var e=`_root_4sqdu_34`,t=`_symbol_4sqdu_64`,n=`_printedDigit_4sqdu_82`,r=`_value_4sqdu_92`,i=`_invalid_4sqdu_108`,a=`_invalidMessage_4sqdu_114`,o=`_invalidValue_4sqdu_120`,s={root:e,symbol:t,printedDigit:n,value:r,invalid:i,invalidMessage:a,invalidValue:o};exports.default=s,exports.invalid=i,exports.invalidMessage=a,exports.invalidValue=o,exports.printedDigit=n,exports.root=e,exports.symbol=t,exports.value=r;
@@ -0,0 +1,13 @@
1
+ "use client";
2
+ //#region src/components/data-display/Barcode/barcode.module.scss
3
+ var e = "_root_4sqdu_34", t = "_symbol_4sqdu_64", n = "_printedDigit_4sqdu_82", r = "_value_4sqdu_92", i = "_invalid_4sqdu_108", a = "_invalidMessage_4sqdu_114", o = "_invalidValue_4sqdu_120", s = {
4
+ root: e,
5
+ symbol: t,
6
+ printedDigit: n,
7
+ value: r,
8
+ invalid: i,
9
+ invalidMessage: a,
10
+ invalidValue: o
11
+ };
12
+ //#endregion
13
+ export { s as default, i as invalid, a as invalidMessage, o as invalidValue, n as printedDigit, e as root, t as symbol, r as value };
@@ -0,0 +1,2 @@
1
+ "use client";
2
+ var e=`212222.222122.222221.121223.121322.131222.122213.122312.132212.221213.221312.231212.112232.122132.122231.113222.123122.123221.223211.221132.221231.213212.223112.312131.311222.321122.321221.312212.322112.322211.212123.212321.232121.111323.131123.131321.112313.132113.132311.211313.231113.231311.112133.112331.132131.113123.113321.133121.313121.211331.231131.213113.213311.213131.311123.311321.331121.312113.312311.332111.314111.221411.431111.111224.111422.121124.121421.141122.141221.112214.112412.122114.122411.142112.142211.241211.221114.413111.241112.134111.111242.121142.121241.114212.124112.124211.411212.421112.421211.212141.214121.412121.111143.111341.131141.114113.114311.411113.411311.113141.114131.311141.411131.211412.211214.211232`.split(`.`),t=`2331112`,n=104,r=105,i=103,a=e=>{let t=``;for(let n=0;n<e.length;n+=1)t+=(n%2==0?`1`:`0`).repeat(Number(e[n]));return t},o=o=>{if(o.length===0)return null;let s=[];if(/^\d+$/.test(o)&&o.length%2==0){s.push(r);for(let e=0;e<o.length;e+=2)s.push(Number(o.slice(e,e+2)))}else{if(!/^[\x20-\x7e]+$/.test(o))return null;s.push(n);for(let e of o)s.push(e.charCodeAt(0)-32)}let c=s.reduce((e,t,n)=>e+t*(n===0?1:n),0)%i;return s.push(c),{modules:s.map(t=>a(e[t])).join(``)+a(t),text:o}},s=[`0001101`,`0011001`,`0010011`,`0111101`,`0100011`,`0110001`,`0101111`,`0111011`,`0110111`,`0001011`],c=[`0100111`,`0110011`,`0011011`,`0100001`,`0011101`,`0111001`,`0000101`,`0010001`,`0001001`,`0010111`],l=[`1110010`,`1100110`,`1101100`,`1000010`,`1011100`,`1001110`,`1010000`,`1000100`,`1001000`,`1110100`],u=[`LLLLLL`,`LLGLGG`,`LLGGLG`,`LLGGGL`,`LGLLGG`,`LGGLLG`,`LGGGLL`,`LGLGLG`,`LGLGGL`,`LGGLGL`],d=`101`,f=`01010`,p=e=>{let t=0;for(let n=0;n<12;n+=1)t+=Number(e[n])*(n%2==0?1:3);return(10-t%10)%10},m=e=>{if(!/^\d{12,13}$/.test(e))return null;let t=e.slice(0,12),n=p(t);if(e.length===13&&Number(e[12])!==n)return null;let r=`${t}${n}`,i=u[Number(r[0])],a=``;for(let e=0;e<6;e+=1){let t=Number(r[e+1]);a+=i[e]===`L`?s[t]:c[t]}let o=``;for(let e=7;e<13;e+=1)o+=l[Number(r[e])];return{modules:`${d}${a}${f}${o}${d}`,text:r,print:{guards:[[0,3],[45,50],[92,95]],lead:r[0],left:{text:r.slice(1,7),from:3,to:45},right:{text:r.slice(7),from:50,to:92}}}},h=(e,t)=>t===`ean13`?m(e):o(e),g=e=>{let t=[];for(let n of e){let e=n===`1`,r=t[t.length-1];r&&r[0]===e?r[1]+=1:t.push([e,1])}return t};exports.ean13CheckDigit=p,exports.encodeBarcode=h,exports.toRuns=g;
@@ -0,0 +1,64 @@
1
+ /**
2
+ * 1 次元シンボル体系のエンコーダ。**描画から切り離してある**のは、バーの並びが
3
+ * 規格で決まっていて単体で検証できるものだからで、`Barcode.tsx` 側は
4
+ * 「1 と 0 の列をどう塗るか」だけを持つ。
5
+ *
6
+ * 対応は Code 128 と EAN-13 の 2 つ。前者は物流・チケット・社内 SKU、後者は
7
+ * 小売の商品コードで、この 2 つで「バーコードを出したい」の大半が埋まる。
8
+ * 体系を増やすのは後方互換なので、要求が出てから足せばよい。
9
+ */
10
+ export type BarcodeFormat = "code128" | "ean13";
11
+ /**
12
+ * EAN-13 の正規の印字レイアウト(T233)。
13
+ *
14
+ * 数字をバーの下へまとめて置くのは**近いけれど別の物**で、店頭の商品と見比べると
15
+ * 違って見える。正規の印字では **ガードバーが数字の帯の底まで伸び**、**先頭桁が
16
+ * シンボルの左外**に出て、残りが左右半分それぞれの下に 6 桁ずつ付く。
17
+ *
18
+ * **スキャナが読むのはバーだけなので、モジュール列は 1 文字も変えない。**
19
+ * ここに出すのは「どこに何を印字するか」だけで、位置はすべてモジュール座標
20
+ * (シンボルの先頭を 0 とする添字)で返す ── 画素は器の幅で変わるが、
21
+ * モジュールの割り付けは体系が決めていて変わらないため。
22
+ */
23
+ export type Ean13PrintLayout = {
24
+ /** 下へ伸ばすガードバーのモジュール範囲 `[開始, 終了)`。左・中央・右の 3 組。 */
25
+ guards: ReadonlyArray<readonly [number, number]>;
26
+ /** シンボルの左外に置く 1 桁目。 */
27
+ lead: string;
28
+ /** 左半分の 6 桁と、その下に敷くモジュール範囲。 */
29
+ left: {
30
+ text: string;
31
+ from: number;
32
+ to: number;
33
+ };
34
+ /** 右半分の 6 桁と、その下に敷くモジュール範囲。 */
35
+ right: {
36
+ text: string;
37
+ from: number;
38
+ to: number;
39
+ };
40
+ };
41
+ export type EncodedBarcode = {
42
+ /** 1 = bar, 0 = space. One character per module. */
43
+ modules: string;
44
+ /** Human-readable interpretation printed under the bars. */
45
+ text: string;
46
+ /**
47
+ * How the digits are printed, for the formats that specify it. Code 128 does
48
+ * not, so it stays undefined and the value is printed under the bars as one
49
+ * run of text.
50
+ */
51
+ print?: Ean13PrintLayout;
52
+ };
53
+ /** Test seam: the raw pattern table, so its invariants can be measured. */
54
+ export declare const code128Patterns: () => readonly string[];
55
+ /** 右から重み 1,3,1,3… を掛けて 10 の補数を取る(GS1 のモジュラス 10)。 */
56
+ export declare const ean13CheckDigit: (first12: string) => number;
57
+ /**
58
+ * Encodes `value` into a module string, or returns `null` when the value cannot
59
+ * be represented in `format` — an unencodable value must not be drawn, because a
60
+ * barcode that scans to the wrong thing is worse than one that is missing.
61
+ */
62
+ export declare const encodeBarcode: (value: string, format: BarcodeFormat) => EncodedBarcode | null;
63
+ /** Consecutive runs of the same module, as `[isBar, width]` pairs. */
64
+ export declare const toRuns: (modules: string) => Array<[boolean, number]>;