wimui 0.44.0 → 0.45.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.
@@ -1,2 +1,2 @@
1
1
  "use client";
2
- const e=require("../../../_virtual/_rolldown/runtime.cjs"),t=require("../../../i18n/useWimTranslation.cjs"),n=require("../../../hooks/useMergedRef.cjs"),r=require("../Table/Table.cjs"),i=require("./layoutPivot.cjs"),a=require("./pivot-table.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=o.default.forwardRef(({rows:e,columns:l,getValue:u,rowAxisLabel:d,caption:f,columnSubtotals:p=!1,totalRow:m=!1,totalColumn:h=!1,labels:g,className:_,...v},y)=>{let{t:b}=t.useWimTranslation(`components`),x=o.default.useId(),S=g?.total??b(`pivottable.total`),C=(0,o.useMemo)(()=>i.layoutPivotColumns(l,{subtotals:p,total:h}),[l,p,h]),w=(0,o.useMemo)(()=>i.layoutPivotRows(e),[e]),T=d!=null&&d!==!1,E=`${x}corner`,D=e=>`${x}c${e}`,O=e=>`${x}r${e}`,k=`${x}total`,A=(0,o.useMemo)(()=>C.columns.map(e=>e.headerIds.map(e=>`${x}c${e}`).join(` `)),[C,x]),j=o.default.useRef(null),M=o.default.useRef(null),[N,P]=o.default.useState(!1);o.default.useLayoutEffect(()=>{let e=j.current,t=M.current;if(!e||!t||typeof ResizeObserver>`u`)return;let n=()=>P(e.scrollWidth>e.clientWidth);n();let r=new ResizeObserver(n);return r.observe(e),r.observe(t),()=>r.disconnect()},[]);let F=n.useMergedRef(y,M),I=`${x}caption`,L=f?{"aria-labelledby":I}:v[`aria-label`]?{"aria-label":v[`aria-label`]}:v[`aria-labelledby`]?{"aria-labelledby":v[`aria-labelledby`]}:null;return(0,c.jsx)(`div`,{ref:j,className:a.default.scroller,tabIndex:N?0:void 0,...N&&L?{role:`region`,...L}:null,children:(0,c.jsxs)(`table`,{ref:F,className:(0,s.default)(`wim-pivot-table`,a.default.root,_),...v,children:[f&&(0,c.jsx)(`caption`,{id:I,className:a.default.caption,children:f}),(0,c.jsx)(`colgroup`,{}),C.groupSpans.map((e,t)=>(0,c.jsx)(`colgroup`,{span:e},t)),(0,c.jsx)(r.Table.Header,{children:C.headerRows.map((e,t)=>(0,c.jsxs)(`tr`,{children:[t===0&&(T?(0,c.jsx)(`th`,{id:E,scope:`col`,rowSpan:C.depth,className:(0,s.default)(a.default.columnHeader,a.default.corner,a.default.bottom),children:d}):(0,c.jsx)(`td`,{rowSpan:C.depth,className:(0,s.default)(a.default.columnHeader,a.default.bottom)})),e.map(e=>(0,c.jsx)(`th`,{id:D(e.id),scope:e.kind===`group`&&e.topLevel?`colgroup`:`col`,colSpan:e.colSpan>1?e.colSpan:void 0,rowSpan:e.rowSpan>1?e.rowSpan:void 0,className:(0,s.default)(a.default.columnHeader,e.kind===`group`&&a.default.group,e.reachesBottom&&a.default.bottom,e.startsGroup&&a.default.groupStart),children:e.kind===`group`||e.kind===`leaf`?e.node?.label:S},e.id))]},t))}),(0,c.jsx)(r.Table.Body,{children:w.map((e,t)=>{let n=[...e.ancestors.map(O),O(t)].join(` `),i=[...T?[E]:[],...e.ancestors.map(O)].join(` `);return(0,c.jsxs)(r.Table.Row,{className:(0,s.default)(e.hasChildren&&a.default.groupRow),children:[(0,c.jsx)(`th`,{id:O(t),scope:`row`,headers:i||void 0,className:a.default.rowHeader,style:{"--wim-pivot-table-depth":e.depth},children:e.node.label}),C.columns.map((t,i)=>(0,c.jsx)(r.Table.Cell,{headers:`${n} ${A[i]}`,className:(0,s.default)(a.default.value,t.kind!==`leaf`&&a.default.aggregate,t.startsGroup&&a.default.groupStart),children:u(e.key,t.key)},i))]},e.key)})}),m&&(0,c.jsx)(r.Table.Footer,{children:(0,c.jsxs)(r.Table.Row,{className:a.default.totalRow,children:[(0,c.jsx)(`th`,{id:k,scope:`row`,headers:T?E:void 0,className:a.default.rowHeader,children:S}),C.columns.map((e,t)=>(0,c.jsx)(r.Table.Cell,{headers:`${k} ${A[t]}`,className:(0,s.default)(a.default.value,e.startsGroup&&a.default.groupStart),children:u(null,e.key)},t))]})})]})})});l.displayName=`PivotTable`,exports.PivotTable=l;
2
+ const e=require("../../../_virtual/_rolldown/runtime.cjs"),t=require("../../../i18n/useWimTranslation.cjs"),n=require("../../../icon/chevron-right.cjs"),r=require("../../media/Icon/Icon.cjs"),i=require("../../../hooks/useMergedRef.cjs"),a=require("../Table/Table.cjs"),o=require("./layoutPivot.cjs"),s=require("./pivot-table.module.cjs");let c=require("react");c=e.__toESM(c,1);let l=require("classnames");l=e.__toESM(l,1);let u=require("react/jsx-runtime");var d=(e,t=[])=>{for(let n of e)n.children?.length&&(t.push(n.key),d(n.children,t));return t},f=c.default.forwardRef(({rows:e,columns:f,getValue:p,rowAxisLabel:m,caption:h,expandedValues:g,defaultExpandedValues:_,onExpandedChange:v,maxHeight:y,stickyHeader:b=!1,stickyRowHeaders:ee=!1,columnSubtotals:x=!1,totalRow:te=!1,totalColumn:S=!1,labels:C,className:w,...T},ne)=>{let{t:re}=t.useWimTranslation(`components`),E=c.default.useId(),D=C?.total??re(`pivottable.total`),O=(0,c.useMemo)(()=>o.layoutPivotColumns(f,{subtotals:x,total:S}),[f,x,S]),[k,A]=(0,c.useState)(()=>_??d(e)),j=g??k,M=(0,c.useMemo)(()=>new Set(j),[j]),N=(0,c.useCallback)(e=>{let t=M.has(e)?j.filter(t=>t!==e):[...j,e];g===void 0&&A(t),v?.(t)},[j,M,g,v]),P=(0,c.useMemo)(()=>o.layoutPivotRows(e,e=>M.has(e)),[e,M]),F=(0,c.useMemo)(()=>d(e).length>0,[e]),I=m!=null&&m!==!1,L=`${E}corner`,ie=e=>`${E}c${e}`,R=e=>`${E}r${e}`,z=`${E}total`,B=(0,c.useMemo)(()=>O.columns.map(e=>e.headerIds.map(e=>`${E}c${e}`).join(` `)),[O,E]),V=c.default.useRef(null),H=c.default.useRef(null),[U,W]=c.default.useState(!1),[G,K]=c.default.useState(!0);c.default.useLayoutEffect(()=>{let e=V.current,t=H.current;if(!e||!t||typeof ResizeObserver>`u`)return;let n=()=>{W(e.scrollWidth>e.clientWidth||e.scrollHeight>e.clientHeight);let n=t.rows[0]?.cells[0];K(!n||n.offsetWidth<=e.clientWidth/2)};n();let r=new ResizeObserver(n);return r.observe(e),r.observe(t),()=>r.disconnect()},[]);let q=i.useMergedRef(ne,H),J=ee&&G,Y=c.default.useRef([]),[ae,oe]=(0,c.useState)([]),X=O.depth;c.default.useLayoutEffect(()=>{if(!b)return;let e=Y.current.slice(0,X),t=()=>{let t=0,n=e.map(e=>{let n=t;return t+=e?.getBoundingClientRect().height??0,n});oe(e=>e.length===n.length&&e.every((e,t)=>e===n[t])?e:n)};if(t(),typeof ResizeObserver>`u`)return;let n=new ResizeObserver(t);return e.forEach(e=>e&&n.observe(e)),()=>n.disconnect()},[b,X]);let Z=(e,t=!1)=>b?{top:Math.floor(ae[e]??0),zIndex:10+X-e+ +!!t}:void 0,Q=`${E}caption`,$=h?{"aria-labelledby":Q}:T[`aria-label`]?{"aria-label":T[`aria-label`]}:T[`aria-labelledby`]?{"aria-labelledby":T[`aria-labelledby`]}:null;return(0,u.jsx)(`div`,{ref:V,className:s.default.scroller,style:y===void 0?void 0:{maxHeight:y},tabIndex:U?0:void 0,...U&&$?{role:`region`,...$}:null,children:(0,u.jsxs)(`table`,{ref:q,className:(0,l.default)(`wim-pivot-table`,s.default.root,w),...T,children:[h&&(0,u.jsx)(`caption`,{id:Q,className:s.default.caption,children:h}),(0,u.jsx)(`colgroup`,{}),O.groupSpans.map((e,t)=>(0,u.jsx)(`colgroup`,{span:e},t)),(0,u.jsx)(a.Table.Header,{children:O.headerRows.map((e,t)=>(0,u.jsxs)(`tr`,{ref:e=>{Y.current[t]=e},children:[t===0&&(I?(0,u.jsx)(`th`,{id:L,scope:`col`,rowSpan:O.depth,className:(0,l.default)(s.default.columnHeader,s.default.corner,s.default.bottom,b&&s.default.stickyTop,J&&s.default.stickyLeft),style:Z(0,!0),children:m}):(0,u.jsx)(`td`,{rowSpan:O.depth,className:(0,l.default)(s.default.columnHeader,s.default.bottom,b&&s.default.stickyTop,J&&s.default.stickyLeft),style:Z(0,!0)})),e.map((e,n)=>(0,u.jsx)(`th`,{id:ie(e.id),scope:e.kind===`group`&&e.topLevel?`colgroup`:`col`,colSpan:e.colSpan>1?e.colSpan:void 0,rowSpan:e.rowSpan>1?e.rowSpan:void 0,className:(0,l.default)(s.default.columnHeader,e.kind===`group`&&s.default.group,e.reachesBottom&&s.default.bottom,e.startsGroup&&!(J&&n===0)&&s.default.groupStart,b&&s.default.stickyTop),style:Z(t),children:e.kind===`group`||e.kind===`leaf`?e.node?.label:D},e.id))]},t))}),(0,u.jsx)(a.Table.Body,{children:P.map((e,t)=>{let i=[...e.ancestors.map(R),R(t)].join(` `),o=[...I?[L]:[],...e.ancestors.map(R)].join(` `);return(0,u.jsxs)(a.Table.Row,{className:(0,l.default)(e.hasChildren&&s.default.groupRow),children:[(0,u.jsx)(`th`,{id:R(t),scope:`row`,headers:o||void 0,className:(0,l.default)(s.default.rowHeader,J&&s.default.stickyLeft),style:{"--wim-pivot-table-depth":e.depth},children:e.hasChildren?(0,u.jsxs)(`button`,{type:`button`,className:s.default.toggle,"aria-expanded":e.expanded,onClick:()=>N(e.key),children:[(0,u.jsx)(`span`,{className:(0,l.default)(s.default.chevron,e.expanded&&s.default.open),"aria-hidden":`true`,children:(0,u.jsx)(r.Icon,{component:n.default,size:`sm`})}),e.node.label]}):(0,u.jsx)(`span`,{className:(0,l.default)(F&&s.default.leafLabel),children:e.node.label})}),O.columns.map((t,n)=>(0,u.jsx)(a.Table.Cell,{headers:`${i} ${B[n]}`,className:(0,l.default)(s.default.value,t.kind!==`leaf`&&s.default.aggregate,t.startsGroup&&!(J&&n===0)&&s.default.groupStart),children:p(e.key,t.key)},n))]},e.key)})}),te&&(0,u.jsx)(a.Table.Footer,{children:(0,u.jsxs)(a.Table.Row,{className:s.default.totalRow,children:[(0,u.jsx)(`th`,{id:z,scope:`row`,headers:I?L:void 0,className:(0,l.default)(s.default.rowHeader,J&&s.default.stickyLeft),children:(0,u.jsx)(`span`,{className:(0,l.default)(F&&s.default.leafLabel),children:D})}),O.columns.map((e,t)=>(0,u.jsx)(a.Table.Cell,{headers:`${z} ${B[t]}`,className:(0,l.default)(s.default.value,e.startsGroup&&!(J&&t===0)&&s.default.groupStart),children:p(null,e.key)},t))]})})]})})});f.displayName=`PivotTable`,exports.PivotTable=f;
@@ -2,7 +2,10 @@ import { default as React } from 'react';
2
2
  export type PivotTableAxisNode = {
3
3
  /** Unique within its axis. Passed back to `getValue`. */
4
4
  key: string;
5
- /** Heading shown for this row or column. */
5
+ /**
6
+ * Heading shown for this row or column. On the row axis the label of a group is drawn
7
+ * inside its expand / collapse button, so it must not contain links or other controls.
8
+ */
6
9
  label: React.ReactNode;
7
10
  /** Nested headings. A node with children is a group; its own value is the subtotal. */
8
11
  children?: PivotTableAxisNode[];
@@ -26,6 +29,31 @@ export type PivotTableProps = Omit<React.ComponentPropsWithoutRef<"table">, "chi
26
29
  rowAxisLabel?: React.ReactNode;
27
30
  /** Visible title of the table, also its accessible name. */
28
31
  caption?: React.ReactNode;
32
+ /**
33
+ * Keys of the expanded row groups (controlled). A group that is not listed shows only
34
+ * its own row, which carries its subtotal.
35
+ */
36
+ expandedValues?: string[];
37
+ /** Row groups expanded on first render (uncontrolled). Defaults to every group. */
38
+ defaultExpandedValues?: string[];
39
+ /** Called with the new list of expanded row groups when a group is expanded or collapsed. */
40
+ onExpandedChange?: (values: string[]) => void;
41
+ /**
42
+ * Maximum height of the table (a number is px). Past it the table scrolls vertically
43
+ * inside its own box.
44
+ */
45
+ maxHeight?: string | number;
46
+ /**
47
+ * Keeps the column headings in view while the table scrolls vertically. Every heading
48
+ * level stays, stacked in order. Only has an effect together with `maxHeight`.
49
+ */
50
+ stickyHeader?: boolean;
51
+ /**
52
+ * Keeps the row headings in view while the table scrolls sideways. The column is only
53
+ * pinned while it takes at most half of the visible width; in a narrower container it
54
+ * scrolls with the rest, so that the values stay readable.
55
+ */
56
+ stickyRowHeaders?: boolean;
29
57
  /** Adds a subtotal column after the columns of each column group. */
30
58
  columnSubtotals?: boolean;
31
59
  /** Adds a grand total row at the bottom. */
@@ -40,6 +68,10 @@ export type PivotTableProps = Omit<React.ComponentPropsWithoutRef<"table">, "chi
40
68
  * headings, subtotals and grand totals. It only draws: grouping and summing stay with the
41
69
  * caller, who answers `getValue(rowKey, columnKey)` for every cell.
42
70
  *
71
+ * Row groups can be collapsed to their subtotal row with the button in their heading
72
+ * (Enter or Space). The button is named by the group label, so the heading still reads as
73
+ * the plain label when a cell announces it.
74
+ *
43
75
  * Every cell lists the headings it belongs to in its `headers` attribute, so a screen
44
76
  * reader announces the full row path and column path of a value.
45
77
  *
@@ -65,6 +97,31 @@ export declare const PivotTable: React.ForwardRefExoticComponent<Omit<Omit<React
65
97
  rowAxisLabel?: React.ReactNode;
66
98
  /** Visible title of the table, also its accessible name. */
67
99
  caption?: React.ReactNode;
100
+ /**
101
+ * Keys of the expanded row groups (controlled). A group that is not listed shows only
102
+ * its own row, which carries its subtotal.
103
+ */
104
+ expandedValues?: string[];
105
+ /** Row groups expanded on first render (uncontrolled). Defaults to every group. */
106
+ defaultExpandedValues?: string[];
107
+ /** Called with the new list of expanded row groups when a group is expanded or collapsed. */
108
+ onExpandedChange?: (values: string[]) => void;
109
+ /**
110
+ * Maximum height of the table (a number is px). Past it the table scrolls vertically
111
+ * inside its own box.
112
+ */
113
+ maxHeight?: string | number;
114
+ /**
115
+ * Keeps the column headings in view while the table scrolls vertically. Every heading
116
+ * level stays, stacked in order. Only has an effect together with `maxHeight`.
117
+ */
118
+ stickyHeader?: boolean;
119
+ /**
120
+ * Keeps the row headings in view while the table scrolls sideways. The column is only
121
+ * pinned while it takes at most half of the visible width; in a narrower container it
122
+ * scrolls with the rest, so that the values stay readable.
123
+ */
124
+ stickyRowHeaders?: boolean;
68
125
  /** Adds a subtotal column after the columns of each column group. */
69
126
  columnSubtotals?: boolean;
70
127
  /** Adds a grand total row at the bottom. */
@@ -1,104 +1,166 @@
1
1
  "use client";
2
2
  import { useWimTranslation as e } from "../../../i18n/useWimTranslation.js";
3
- import { useMergedRef as t } from "../../../hooks/useMergedRef.js";
4
- import { Table as n } from "../Table/Table.js";
5
- import { layoutPivotColumns as r, layoutPivotRows as i } from "./layoutPivot.js";
6
- import a from "./pivot-table.module.js";
7
- import o, { useMemo as s } from "react";
8
- import c from "classnames";
9
- import { jsx as l, jsxs as u } from "react/jsx-runtime";
3
+ import t from "../../../icon/chevron-right.js";
4
+ import { Icon as n } from "../../media/Icon/Icon.js";
5
+ import { useMergedRef as r } from "../../../hooks/useMergedRef.js";
6
+ import { Table as i } from "../Table/Table.js";
7
+ import { layoutPivotColumns as a, layoutPivotRows as o } from "./layoutPivot.js";
8
+ import s from "./pivot-table.module.js";
9
+ import c, { useCallback as ee, useMemo as l, useState as u } from "react";
10
+ import d from "classnames";
11
+ import { jsx as f, jsxs as p } from "react/jsx-runtime";
10
12
  //#region src/components/data-display/PivotTable/PivotTable.tsx
11
- var d = o.forwardRef(({ rows: d, columns: f, getValue: p, rowAxisLabel: m, caption: h, columnSubtotals: g = !1, totalRow: _ = !1, totalColumn: v = !1, labels: y, className: b, ...x }, S) => {
12
- let { t: C } = e("components"), w = o.useId(), T = y?.total ?? C("pivottable.total"), E = s(() => r(f, {
13
- subtotals: g,
14
- total: v
13
+ var m = (e, t = []) => {
14
+ for (let n of e) n.children?.length && (t.push(n.key), m(n.children, t));
15
+ return t;
16
+ }, h = c.forwardRef(({ rows: h, columns: g, getValue: _, rowAxisLabel: v, caption: y, expandedValues: b, defaultExpandedValues: x, onExpandedChange: S, maxHeight: C, stickyHeader: w = !1, stickyRowHeaders: te = !1, columnSubtotals: T = !1, totalRow: ne = !1, totalColumn: E = !1, labels: D, className: re, ...O }, ie) => {
17
+ let { t: k } = e("components"), A = c.useId(), j = D?.total ?? k("pivottable.total"), M = l(() => a(g, {
18
+ subtotals: T,
19
+ total: E
15
20
  }), [
16
- f,
17
21
  g,
18
- v
19
- ]), D = s(() => i(d), [d]), O = m != null && m !== !1, k = `${w}corner`, A = (e) => `${w}c${e}`, j = (e) => `${w}r${e}`, M = `${w}total`, N = s(() => E.columns.map((e) => e.headerIds.map((e) => `${w}c${e}`).join(" ")), [E, w]), P = o.useRef(null), F = o.useRef(null), [I, L] = o.useState(!1);
20
- o.useLayoutEffect(() => {
21
- let e = P.current, t = F.current;
22
+ T,
23
+ E
24
+ ]), [N, P] = u(() => x ?? m(h)), F = b ?? N, I = l(() => new Set(F), [F]), L = ee((e) => {
25
+ let t = I.has(e) ? F.filter((t) => t !== e) : [...F, e];
26
+ b === void 0 && P(t), S?.(t);
27
+ }, [
28
+ F,
29
+ I,
30
+ b,
31
+ S
32
+ ]), R = l(() => o(h, (e) => I.has(e)), [h, I]), z = l(() => m(h).length > 0, [h]), B = v != null && v !== !1, V = `${A}corner`, ae = (e) => `${A}c${e}`, H = (e) => `${A}r${e}`, U = `${A}total`, W = l(() => M.columns.map((e) => e.headerIds.map((e) => `${A}c${e}`).join(" ")), [M, A]), G = c.useRef(null), K = c.useRef(null), [q, oe] = c.useState(!1), [se, ce] = c.useState(!0);
33
+ c.useLayoutEffect(() => {
34
+ let e = G.current, t = K.current;
22
35
  if (!e || !t || typeof ResizeObserver > "u") return;
23
- let n = () => L(e.scrollWidth > e.clientWidth);
36
+ let n = () => {
37
+ oe(e.scrollWidth > e.clientWidth || e.scrollHeight > e.clientHeight);
38
+ let n = t.rows[0]?.cells[0];
39
+ ce(!n || n.offsetWidth <= e.clientWidth / 2);
40
+ };
24
41
  n();
25
42
  let r = new ResizeObserver(n);
26
43
  return r.observe(e), r.observe(t), () => r.disconnect();
27
44
  }, []);
28
- let R = t(S, F), z = `${w}caption`, B = h ? { "aria-labelledby": z } : x["aria-label"] ? { "aria-label": x["aria-label"] } : x["aria-labelledby"] ? { "aria-labelledby": x["aria-labelledby"] } : null;
29
- return /* @__PURE__ */ l("div", {
30
- ref: P,
31
- className: a.scroller,
32
- tabIndex: I ? 0 : void 0,
33
- ...I && B ? {
45
+ let le = r(ie, K), J = te && se, Y = c.useRef([]), [ue, de] = u([]), X = M.depth;
46
+ c.useLayoutEffect(() => {
47
+ if (!w) return;
48
+ let e = Y.current.slice(0, X), t = () => {
49
+ let t = 0, n = e.map((e) => {
50
+ let n = t;
51
+ return t += e?.getBoundingClientRect().height ?? 0, n;
52
+ });
53
+ de((e) => e.length === n.length && e.every((e, t) => e === n[t]) ? e : n);
54
+ };
55
+ if (t(), typeof ResizeObserver > "u") return;
56
+ let n = new ResizeObserver(t);
57
+ return e.forEach((e) => e && n.observe(e)), () => n.disconnect();
58
+ }, [w, X]);
59
+ let Z = (e, t = !1) => w ? {
60
+ top: Math.floor(ue[e] ?? 0),
61
+ zIndex: 10 + X - e + +!!t
62
+ } : void 0, Q = `${A}caption`, $ = y ? { "aria-labelledby": Q } : O["aria-label"] ? { "aria-label": O["aria-label"] } : O["aria-labelledby"] ? { "aria-labelledby": O["aria-labelledby"] } : null;
63
+ return /* @__PURE__ */ f("div", {
64
+ ref: G,
65
+ className: s.scroller,
66
+ style: C === void 0 ? void 0 : { maxHeight: C },
67
+ tabIndex: q ? 0 : void 0,
68
+ ...q && $ ? {
34
69
  role: "region",
35
- ...B
70
+ ...$
36
71
  } : null,
37
- children: /* @__PURE__ */ u("table", {
38
- ref: R,
39
- className: c("wim-pivot-table", a.root, b),
40
- ...x,
72
+ children: /* @__PURE__ */ p("table", {
73
+ ref: le,
74
+ className: d("wim-pivot-table", s.root, re),
75
+ ...O,
41
76
  children: [
42
- h && /* @__PURE__ */ l("caption", {
43
- id: z,
44
- className: a.caption,
45
- children: h
77
+ y && /* @__PURE__ */ f("caption", {
78
+ id: Q,
79
+ className: s.caption,
80
+ children: y
46
81
  }),
47
- /* @__PURE__ */ l("colgroup", {}),
48
- E.groupSpans.map((e, t) => /* @__PURE__ */ l("colgroup", { span: e }, t)),
49
- /* @__PURE__ */ l(n.Header, { children: E.headerRows.map((e, t) => /* @__PURE__ */ u("tr", { children: [t === 0 && (O ? /* @__PURE__ */ l("th", {
50
- id: k,
51
- scope: "col",
52
- rowSpan: E.depth,
53
- className: c(a.columnHeader, a.corner, a.bottom),
54
- children: m
55
- }) : /* @__PURE__ */ l("td", {
56
- rowSpan: E.depth,
57
- className: c(a.columnHeader, a.bottom)
58
- })), e.map((e) => /* @__PURE__ */ l("th", {
59
- id: A(e.id),
60
- scope: e.kind === "group" && e.topLevel ? "colgroup" : "col",
61
- colSpan: e.colSpan > 1 ? e.colSpan : void 0,
62
- rowSpan: e.rowSpan > 1 ? e.rowSpan : void 0,
63
- className: c(a.columnHeader, e.kind === "group" && a.group, e.reachesBottom && a.bottom, e.startsGroup && a.groupStart),
64
- children: e.kind === "group" || e.kind === "leaf" ? e.node?.label : T
65
- }, e.id))] }, t)) }),
66
- /* @__PURE__ */ l(n.Body, { children: D.map((e, t) => {
67
- let r = [...e.ancestors.map(j), j(t)].join(" "), i = [...O ? [k] : [], ...e.ancestors.map(j)].join(" ");
68
- return /* @__PURE__ */ u(n.Row, {
69
- className: c(e.hasChildren && a.groupRow),
70
- children: [/* @__PURE__ */ l("th", {
71
- id: j(t),
82
+ /* @__PURE__ */ f("colgroup", {}),
83
+ M.groupSpans.map((e, t) => /* @__PURE__ */ f("colgroup", { span: e }, t)),
84
+ /* @__PURE__ */ f(i.Header, { children: M.headerRows.map((e, t) => /* @__PURE__ */ p("tr", {
85
+ ref: (e) => {
86
+ Y.current[t] = e;
87
+ },
88
+ children: [t === 0 && (B ? /* @__PURE__ */ f("th", {
89
+ id: V,
90
+ scope: "col",
91
+ rowSpan: M.depth,
92
+ className: d(s.columnHeader, s.corner, s.bottom, w && s.stickyTop, J && s.stickyLeft),
93
+ style: Z(0, !0),
94
+ children: v
95
+ }) : /* @__PURE__ */ f("td", {
96
+ rowSpan: M.depth,
97
+ className: d(s.columnHeader, s.bottom, w && s.stickyTop, J && s.stickyLeft),
98
+ style: Z(0, !0)
99
+ })), e.map((e, n) => /* @__PURE__ */ f("th", {
100
+ id: ae(e.id),
101
+ scope: e.kind === "group" && e.topLevel ? "colgroup" : "col",
102
+ colSpan: e.colSpan > 1 ? e.colSpan : void 0,
103
+ rowSpan: e.rowSpan > 1 ? e.rowSpan : void 0,
104
+ className: d(s.columnHeader, e.kind === "group" && s.group, e.reachesBottom && s.bottom, e.startsGroup && !(J && n === 0) && s.groupStart, w && s.stickyTop),
105
+ style: Z(t),
106
+ children: e.kind === "group" || e.kind === "leaf" ? e.node?.label : j
107
+ }, e.id))]
108
+ }, t)) }),
109
+ /* @__PURE__ */ f(i.Body, { children: R.map((e, r) => {
110
+ let a = [...e.ancestors.map(H), H(r)].join(" "), o = [...B ? [V] : [], ...e.ancestors.map(H)].join(" ");
111
+ return /* @__PURE__ */ p(i.Row, {
112
+ className: d(e.hasChildren && s.groupRow),
113
+ children: [/* @__PURE__ */ f("th", {
114
+ id: H(r),
72
115
  scope: "row",
73
- headers: i || void 0,
74
- className: a.rowHeader,
116
+ headers: o || void 0,
117
+ className: d(s.rowHeader, J && s.stickyLeft),
75
118
  style: { "--wim-pivot-table-depth": e.depth },
76
- children: e.node.label
77
- }), E.columns.map((t, i) => /* @__PURE__ */ l(n.Cell, {
78
- headers: `${r} ${N[i]}`,
79
- className: c(a.value, t.kind !== "leaf" && a.aggregate, t.startsGroup && a.groupStart),
80
- children: p(e.key, t.key)
81
- }, i))]
119
+ children: e.hasChildren ? /* @__PURE__ */ p("button", {
120
+ type: "button",
121
+ className: s.toggle,
122
+ "aria-expanded": e.expanded,
123
+ onClick: () => L(e.key),
124
+ children: [/* @__PURE__ */ f("span", {
125
+ className: d(s.chevron, e.expanded && s.open),
126
+ "aria-hidden": "true",
127
+ children: /* @__PURE__ */ f(n, {
128
+ component: t,
129
+ size: "sm"
130
+ })
131
+ }), e.node.label]
132
+ }) : /* @__PURE__ */ f("span", {
133
+ className: d(z && s.leafLabel),
134
+ children: e.node.label
135
+ })
136
+ }), M.columns.map((t, n) => /* @__PURE__ */ f(i.Cell, {
137
+ headers: `${a} ${W[n]}`,
138
+ className: d(s.value, t.kind !== "leaf" && s.aggregate, t.startsGroup && !(J && n === 0) && s.groupStart),
139
+ children: _(e.key, t.key)
140
+ }, n))]
82
141
  }, e.key);
83
142
  }) }),
84
- _ && /* @__PURE__ */ l(n.Footer, { children: /* @__PURE__ */ u(n.Row, {
85
- className: a.totalRow,
86
- children: [/* @__PURE__ */ l("th", {
87
- id: M,
143
+ ne && /* @__PURE__ */ f(i.Footer, { children: /* @__PURE__ */ p(i.Row, {
144
+ className: s.totalRow,
145
+ children: [/* @__PURE__ */ f("th", {
146
+ id: U,
88
147
  scope: "row",
89
- headers: O ? k : void 0,
90
- className: a.rowHeader,
91
- children: T
92
- }), E.columns.map((e, t) => /* @__PURE__ */ l(n.Cell, {
93
- headers: `${M} ${N[t]}`,
94
- className: c(a.value, e.startsGroup && a.groupStart),
95
- children: p(null, e.key)
148
+ headers: B ? V : void 0,
149
+ className: d(s.rowHeader, J && s.stickyLeft),
150
+ children: /* @__PURE__ */ f("span", {
151
+ className: d(z && s.leafLabel),
152
+ children: j
153
+ })
154
+ }), M.columns.map((e, t) => /* @__PURE__ */ f(i.Cell, {
155
+ headers: `${U} ${W[t]}`,
156
+ className: d(s.value, e.startsGroup && !(J && t === 0) && s.groupStart),
157
+ children: _(null, e.key)
96
158
  }, t))]
97
159
  }) })
98
160
  ]
99
161
  })
100
162
  });
101
163
  });
102
- d.displayName = "PivotTable";
164
+ h.displayName = "PivotTable";
103
165
  //#endregion
104
- export { d as PivotTable };
166
+ export { h as PivotTable };
@@ -1,2 +1,2 @@
1
1
  "use client";
2
- var e=e=>!!e.children?.length,t=n=>n.reduce((n,r)=>Math.max(n,1+(e(r)?t(r.children):0)),0);function n(n,r={}){let i=Math.max(1,t(n)),a=Array.from({length:i},()=>[]),o=[],s=[],c=0,l=(e,t,n,r,s,l)=>{let u=c++,d=e?.key??null;a[n].push({id:u,key:d,node:e,kind:t,colSpan:1,rowSpan:i-n,reachesBottom:!0,startsGroup:l,topLevel:s}),o.push({key:d,kind:t,headerIds:[...r,u],startsGroup:l})},u=(t,n,i,o)=>{let s=n===0;if(!e(t))return l(t,`leaf`,n,i,s,o),1;let d={id:c++,key:t.key,node:t,kind:`group`,colSpan:0,rowSpan:1,reachesBottom:!1,startsGroup:o,topLevel:s};a[n].push(d);let f=[...i,d.id],p=0;return t.children.forEach((e,t)=>{p+=u(e,n+1,f,o&&t===0)}),r.subtotals&&(l(t,`subtotal`,n+1,f,!1,!1),p+=1),d.colSpan=p,p};for(let e of n)s.push(u(e,0,[],!0));return r.total&&(l(null,`total`,0,[],!0,!0),s.push(1)),{headerRows:a,columns:o,depth:i,groupSpans:s}}function r(t){let n=[],r=(t,i,a)=>{for(let o of t){let t=n.length,s=e(o);n.push({key:o.key,node:o,depth:i,hasChildren:s,ancestors:a}),s&&r(o.children,i+1,[...a,t])}};return r(t,0,[]),n}exports.layoutPivotColumns=n,exports.layoutPivotRows=r;
2
+ var e=e=>!!e.children?.length,t=n=>n.reduce((n,r)=>Math.max(n,1+(e(r)?t(r.children):0)),0);function n(n,r={}){let i=Math.max(1,t(n)),a=Array.from({length:i},()=>[]),o=[],s=[],c=0,l=(e,t,n,r,s,l)=>{let u=c++,d=e?.key??null;a[n].push({id:u,key:d,node:e,kind:t,colSpan:1,rowSpan:i-n,reachesBottom:!0,startsGroup:l,topLevel:s}),o.push({key:d,kind:t,headerIds:[...r,u],startsGroup:l})},u=(t,n,i,o)=>{let s=n===0;if(!e(t))return l(t,`leaf`,n,i,s,o),1;let d={id:c++,key:t.key,node:t,kind:`group`,colSpan:0,rowSpan:1,reachesBottom:!1,startsGroup:o,topLevel:s};a[n].push(d);let f=[...i,d.id],p=0;return t.children.forEach((e,t)=>{p+=u(e,n+1,f,o&&t===0)}),r.subtotals&&(l(t,`subtotal`,n+1,f,!1,!1),p+=1),d.colSpan=p,p};for(let e of n)s.push(u(e,0,[],!0));return r.total&&(l(null,`total`,0,[],!0,!0),s.push(1)),{headerRows:a,columns:o,depth:i,groupSpans:s}}function r(t,n=()=>!0){let r=[],i=(t,a,o)=>{for(let s of t){let t=r.length,c=e(s),l=c&&n(s.key);r.push({key:s.key,node:s,depth:a,hasChildren:c,expanded:l,ancestors:o}),l&&i(s.children,a+1,[...o,t])}};return i(t,0,[]),r}exports.layoutPivotColumns=n,exports.layoutPivotRows=r;
@@ -44,6 +44,8 @@ export type PivotRow<T extends PivotAxisInput = PivotAxisInput> = {
44
44
  node: T;
45
45
  depth: number;
46
46
  hasChildren: boolean;
47
+ /** 子の行が出ているか(グループでない行は常に `false`)。 */
48
+ expanded: boolean;
47
49
  /** 祖先の行の番号(返り値の配列の中の位置。根から順)。 */
48
50
  ancestors: number[];
49
51
  };
@@ -58,5 +60,8 @@ export declare function layoutPivotColumns<T extends PivotAxisInput>(nodes: T[],
58
60
  subtotals?: boolean;
59
61
  total?: boolean;
60
62
  }): PivotColumnLayout<T>;
61
- /** 行の軸の木を、深さ優先で 1 行ずつに並べる(アウトライン形式: グループも 1 行を持つ)。 */
62
- export declare function layoutPivotRows<T extends PivotAxisInput>(nodes: T[]): PivotRow<T>[];
63
+ /**
64
+ * 行の軸の木を、深さ優先で 1 行ずつに並べる(アウトライン形式: グループも 1 行を持つ)。
65
+ * 折りたたまれたグループは自分の行だけを出し、配下の行は出さない。
66
+ */
67
+ export declare function layoutPivotRows<T extends PivotAxisInput>(nodes: T[], isExpanded?: (key: string) => boolean): PivotRow<T>[];
@@ -48,20 +48,21 @@ function n(n, r = {}) {
48
48
  groupSpans: s
49
49
  };
50
50
  }
51
- function r(t) {
52
- let n = [], r = (t, i, a) => {
53
- for (let o of t) {
54
- let t = n.length, s = e(o);
55
- n.push({
56
- key: o.key,
57
- node: o,
58
- depth: i,
59
- hasChildren: s,
60
- ancestors: a
61
- }), s && r(o.children, i + 1, [...a, t]);
51
+ function r(t, n = () => !0) {
52
+ let r = [], i = (t, a, o) => {
53
+ for (let s of t) {
54
+ let t = r.length, c = e(s), l = c && n(s.key);
55
+ r.push({
56
+ key: s.key,
57
+ node: s,
58
+ depth: a,
59
+ hasChildren: c,
60
+ expanded: l,
61
+ ancestors: o
62
+ }), l && i(s.children, a + 1, [...o, t]);
62
63
  }
63
64
  };
64
- return r(t, 0, []), n;
65
+ return i(t, 0, []), r;
65
66
  }
66
67
  //#endregion
67
68
  export { n as layoutPivotColumns, r as layoutPivotRows };
@@ -1,2 +1,2 @@
1
1
  "use client";
2
- var e=`_scroller_x2q1s_7`,t=`_root_x2q1s_20`,n=`_caption_x2q1s_27`,r=`_columnHeader_x2q1s_34`,i=`_group_x2q1s_48`,a=`_bottom_x2q1s_56`,o=`_corner_x2q1s_60`,s=`_rowHeader_x2q1s_63`,c=`_value_x2q1s_72`,l=`_groupRow_x2q1s_77`,u=`_aggregate_x2q1s_82`,d=`_groupStart_x2q1s_86`,f=`_totalRow_x2q1s_89`,p={scroller:e,root:t,caption:n,columnHeader:r,group:i,bottom:a,corner:o,rowHeader:s,value:c,groupRow:l,aggregate:u,groupStart:d,totalRow:f};exports.aggregate=u,exports.bottom=a,exports.caption=n,exports.columnHeader=r,exports.corner=o,exports.default=p,exports.group=i,exports.groupRow=l,exports.groupStart=d,exports.root=t,exports.rowHeader=s,exports.scroller=e,exports.totalRow=f,exports.value=c;
2
+ var e=`_scroller_1xfhj_7`,t=`_root_1xfhj_22`,n=`_caption_1xfhj_34`,r=`_columnHeader_1xfhj_41`,i=`_group_1xfhj_55`,a=`_bottom_1xfhj_62`,o=`_corner_1xfhj_65`,s=`_rowHeader_1xfhj_68`,c=`_toggle_1xfhj_81`,l=`_chevron_1xfhj_100`,u=`_open_1xfhj_116`,d=`_leafLabel_1xfhj_120`,f=`_value_1xfhj_127`,p=`_groupRow_1xfhj_133`,m=`_aggregate_1xfhj_138`,h=`_groupStart_1xfhj_142`,g=`_totalRow_1xfhj_145`,_=`_stickyTop_1xfhj_154`,v=`_stickyLeft_1xfhj_159`,y={scroller:e,root:t,caption:n,columnHeader:r,group:i,bottom:a,corner:o,rowHeader:s,toggle:c,chevron:l,open:u,leafLabel:d,value:f,groupRow:p,aggregate:m,groupStart:h,totalRow:g,stickyTop:_,stickyLeft:v};exports.aggregate=m,exports.bottom=a,exports.caption=n,exports.chevron=l,exports.columnHeader=r,exports.corner=o,exports.default=y,exports.group=i,exports.groupRow=p,exports.groupStart=h,exports.leafLabel=d,exports.open=u,exports.root=t,exports.rowHeader=s,exports.scroller=e,exports.stickyLeft=v,exports.stickyTop=_,exports.toggle=c,exports.totalRow=g,exports.value=f;
@@ -1,6 +1,6 @@
1
1
  "use client";
2
2
  //#region src/components/data-display/PivotTable/pivot-table.module.scss
3
- var e = "_scroller_x2q1s_7", t = "_root_x2q1s_20", n = "_caption_x2q1s_27", r = "_columnHeader_x2q1s_34", i = "_group_x2q1s_48", a = "_bottom_x2q1s_56", o = "_corner_x2q1s_60", s = "_rowHeader_x2q1s_63", c = "_value_x2q1s_72", l = "_groupRow_x2q1s_77", u = "_aggregate_x2q1s_82", d = "_groupStart_x2q1s_86", f = "_totalRow_x2q1s_89", p = {
3
+ var e = "_scroller_1xfhj_7", t = "_root_1xfhj_22", n = "_caption_1xfhj_34", r = "_columnHeader_1xfhj_41", i = "_group_1xfhj_55", a = "_bottom_1xfhj_62", o = "_corner_1xfhj_65", s = "_rowHeader_1xfhj_68", c = "_toggle_1xfhj_81", l = "_chevron_1xfhj_100", u = "_open_1xfhj_116", d = "_leafLabel_1xfhj_120", f = "_value_1xfhj_127", p = "_groupRow_1xfhj_133", m = "_aggregate_1xfhj_138", h = "_groupStart_1xfhj_142", g = "_totalRow_1xfhj_145", _ = "_stickyTop_1xfhj_154", v = "_stickyLeft_1xfhj_159", y = {
4
4
  scroller: e,
5
5
  root: t,
6
6
  caption: n,
@@ -9,11 +9,17 @@ var e = "_scroller_x2q1s_7", t = "_root_x2q1s_20", n = "_caption_x2q1s_27", r =
9
9
  bottom: a,
10
10
  corner: o,
11
11
  rowHeader: s,
12
- value: c,
13
- groupRow: l,
14
- aggregate: u,
15
- groupStart: d,
16
- totalRow: f
12
+ toggle: c,
13
+ chevron: l,
14
+ open: u,
15
+ leafLabel: d,
16
+ value: f,
17
+ groupRow: p,
18
+ aggregate: m,
19
+ groupStart: h,
20
+ totalRow: g,
21
+ stickyTop: _,
22
+ stickyLeft: v
17
23
  };
18
24
  //#endregion
19
- export { u as aggregate, a as bottom, n as caption, r as columnHeader, o as corner, p as default, i as group, l as groupRow, d as groupStart, t as root, s as rowHeader, e as scroller, f as totalRow, c as value };
25
+ export { m as aggregate, a as bottom, n as caption, l as chevron, r as columnHeader, o as corner, y as default, i as group, p as groupRow, h as groupStart, d as leafLabel, u as open, t as root, s as rowHeader, e as scroller, v as stickyLeft, _ as stickyTop, c as toggle, g as totalRow, f as value };
@@ -1,2 +1,2 @@
1
1
  "use client";
2
- const e=require("../../../../_virtual/_rolldown/runtime.cjs");let t=require("react");t=e.__toESM(t,1);function n({src:e,autoPlay:n,loop:r,muted:i,fit:a,videoId:o,resumePlayback:s,playlist:c,autoPlayNext:l,qualities:u,customControls:d,advancedControls:f,poster:p,containerRef:m}){let h=t.default.useRef(null),g=t.default.useRef(null),_=m??g,[v,y]=(0,t.useState)(!1),[b,x]=(0,t.useState)(0),[S,C]=(0,t.useState)(0),[w,T]=(0,t.useState)(1),[E,D]=(0,t.useState)(i),[O,k]=(0,t.useState)(!1),[A,j]=(0,t.useState)(1),[M,N]=(0,t.useState)(a),[P,F]=(0,t.useState)(0),[I,L]=(0,t.useState)(0),[R,z]=(0,t.useState)(null),[B,V]=(0,t.useState)(null),[H,U]=(0,t.useState)({show:!1,direction:`forward`}),W=u&&u.length>0?u[I].src:c&&c.length>0?c[P].src:e,G=c&&c.length>0&&c[P].poster||p,K=!(d||f);(0,t.useEffect)(()=>{if(o&&s&&h.current){let e=c&&c.length>0?`${o}-${P}`:o,t=localStorage.getItem(`wimui-video-resume-${e}`);t&&(h.current.currentTime=parseFloat(t))}},[o,s,P,c]),(0,t.useEffect)(()=>{n&&h.current&&h.current.play().catch(e=>{})},[n,W]),(0,t.useEffect)(()=>{h.current&&(h.current.volume=w,h.current.muted=E,h.current.playbackRate=A,h.current.loop=r&&(!c||c.length<=1))},[w,E,A,r,c]),(0,t.useEffect)(()=>{let e=()=>{k(!!document.fullscreenElement)};return document.addEventListener(`fullscreenchange`,e),()=>document.removeEventListener(`fullscreenchange`,e)},[]);let q=(0,t.useCallback)(e=>{if(h.current){let t=Math.max(0,Math.min(h.current.currentTime+e,S));h.current.currentTime=t,x(t)}},[S]),J=(0,t.useCallback)(()=>{h.current&&(v?h.current.pause():h.current.play(),y(!v))},[v]),Y=(0,t.useCallback)(()=>{D(!E)},[E]),X=(0,t.useCallback)(()=>{_.current&&(document.fullscreenElement?(document.exitFullscreen(),k(!1)):(_.current.requestFullscreen().catch(e=>{}),k(!0)))},[_]),Z=(0,t.useCallback)(async()=>{if(h.current)try{document.pictureInPictureElement?await document.exitPictureInPicture():document.pictureInPictureEnabled&&await h.current.requestPictureInPicture()}catch{}},[]),Q=e=>{if(!h.current)return;let t=h.current.currentTime,n=!h.current.paused;L(e),setTimeout(()=>{h.current&&(h.current.currentTime=t,n&&h.current.play())},50),z(`main`)},$=(0,t.useCallback)(e=>{F(e),h.current&&(h.current.currentTime=0,setTimeout(()=>h.current?.play(),100))},[]);return(0,t.useEffect)(()=>{let e=e=>{if(![`INPUT`,`TEXTAREA`,`SELECT`].includes(e.target.tagName)&&(d||f)&&(_.current?.contains(document.activeElement)||document.fullscreenElement===_.current||document.activeElement===document.body))switch(e.key.toLowerCase()){case` `:case`k`:e.preventDefault(),J();break;case`arrowright`:e.preventDefault(),q(10);break;case`arrowleft`:e.preventDefault(),q(-10);break;case`arrowup`:{e.preventDefault();let t=Math.min(1,w+.1);T(t),t>0&&D(!1);break}case`arrowdown`:{e.preventDefault();let t=Math.max(0,w-.1);T(t);break}case`m`:e.preventDefault(),Y();break;case`f`:e.preventDefault(),X();break;case`p`:e.preventDefault(),Z()}};return window.addEventListener(`keydown`,e),()=>window.removeEventListener(`keydown`,e)},[v,w,S,d,f,q,Y,J,X,Z,_]),{videoRef:h,containerRef:_,isPlaying:v,currentTime:b,duration:S,volume:w,isMuted:E,isFullscreen:O,playbackRate:A,activeFit:M,currentPlayIndex:P,currentQualityIndex:I,activeMenu:R,skipIndicator:H,activeSrc:W,activePoster:G,showNativeControls:K,setVolume:T,setIsMuted:D,setPlaybackRate:j,setActiveFit:N,setCurrentPlayIndex:F,setActiveMenu:z,togglePlay:J,toggleMute:Y,toggleFullscreen:X,togglePiP:Z,skip:q,handleQualityChange:Q,playPlaylistItem:$,handleTimeUpdate:()=>{if(h.current){let e=h.current.currentTime;if(x(e),o&&s&&Math.floor(e)%5==0&&S>0&&e<S-2){let t=c&&c.length>0?`${o}-${P}`:o;localStorage.setItem(`wimui-video-resume-${t}`,e.toString())}}},handleLoadedMetadata:()=>{h.current&&C(h.current.duration)},handleEnded:()=>{if(o&&s){let e=c&&c.length>0?`${o}-${P}`:o;localStorage.removeItem(`wimui-video-resume-${e}`)}c&&c.length>0&&l&&P<c.length-1?(F(e=>e+1),h.current&&setTimeout(()=>{h.current?.play()},100)):y(!1)},handleSeek:e=>{let t=parseFloat(e.target.value);h.current&&(h.current.currentTime=t,x(t))},handleVolumeChange:e=>{let t=parseFloat(e.target.value);T(t),t>0&&D(!1)},handleVideoClick:e=>{if(!d&&!f)return;let t=new Date().getTime(),n=e.currentTarget.getBoundingClientRect(),r=e.clientX-n.left,i=n.width;B&&t-B.time<300?(r>i/2?(q(10),U({show:!0,direction:`forward`})):(q(-10),U({show:!0,direction:`backward`})),setTimeout(()=>U({show:!1,direction:`forward`}),600),V(null)):(V({time:t,x:r}),setTimeout(()=>{Date.now()-t>=290&&J()},300))},formatTime:e=>`${Math.floor(e/60)}:${Math.floor(e%60).toString().padStart(2,`0`)}`}}exports.useVideoPlayer=n;
2
+ const e=require("../../../../_virtual/_rolldown/runtime.cjs");let t=require("react");t=e.__toESM(t,1);function n({src:e,autoPlay:n,loop:r,muted:i,fit:a,videoId:o,resumePlayback:s,playlist:c,autoPlayNext:l,qualities:u,customControls:d,advancedControls:f,poster:p,containerRef:m}){let h=t.default.useRef(null),g=t.default.useRef(null),_=m??g,v=t.default.useRef(new Set),y=(0,t.useCallback)((e,t)=>{let n=setTimeout(()=>{v.current.delete(n),e()},t);v.current.add(n)},[]);(0,t.useEffect)(()=>{let e=v.current;return()=>{e.forEach(clearTimeout),e.clear()}},[]);let[b,x]=(0,t.useState)(!1),[S,C]=(0,t.useState)(0),[w,T]=(0,t.useState)(0),[E,D]=(0,t.useState)(1),[O,k]=(0,t.useState)(i),[A,j]=(0,t.useState)(!1),[M,N]=(0,t.useState)(1),[P,F]=(0,t.useState)(a),[I,L]=(0,t.useState)(0),[R,z]=(0,t.useState)(0),[B,V]=(0,t.useState)(null),[H,U]=(0,t.useState)(null),[W,G]=(0,t.useState)({show:!1,direction:`forward`}),K=u&&u.length>0?u[R].src:c&&c.length>0?c[I].src:e,q=c&&c.length>0&&c[I].poster||p,J=!(d||f);(0,t.useEffect)(()=>{if(o&&s&&h.current){let e=c&&c.length>0?`${o}-${I}`:o,t=localStorage.getItem(`wimui-video-resume-${e}`);t&&(h.current.currentTime=parseFloat(t))}},[o,s,I,c]),(0,t.useEffect)(()=>{n&&h.current&&h.current.play().catch(e=>{})},[n,K]),(0,t.useEffect)(()=>{h.current&&(h.current.volume=E,h.current.muted=O,h.current.playbackRate=M,h.current.loop=r&&(!c||c.length<=1))},[E,O,M,r,c]),(0,t.useEffect)(()=>{let e=()=>{j(!!document.fullscreenElement)};return document.addEventListener(`fullscreenchange`,e),()=>document.removeEventListener(`fullscreenchange`,e)},[]);let Y=(0,t.useCallback)(e=>{if(h.current){let t=Math.max(0,Math.min(h.current.currentTime+e,w));h.current.currentTime=t,C(t)}},[w]),X=(0,t.useCallback)(()=>{h.current&&(b?h.current.pause():h.current.play(),x(!b))},[b]),Z=(0,t.useCallback)(()=>{k(!O)},[O]),Q=(0,t.useCallback)(()=>{_.current&&(document.fullscreenElement?(document.exitFullscreen(),j(!1)):(_.current.requestFullscreen().catch(e=>{}),j(!0)))},[_]),$=(0,t.useCallback)(async()=>{if(h.current)try{document.pictureInPictureElement?await document.exitPictureInPicture():document.pictureInPictureEnabled&&await h.current.requestPictureInPicture()}catch{}},[]),ee=e=>{if(!h.current)return;let t=h.current.currentTime,n=!h.current.paused;z(e),y(()=>{h.current&&(h.current.currentTime=t,n&&h.current.play())},50),V(`main`)},te=(0,t.useCallback)(e=>{L(e),h.current&&(h.current.currentTime=0,y(()=>h.current?.play(),100))},[y]);return(0,t.useEffect)(()=>{let e=e=>{if(![`INPUT`,`TEXTAREA`,`SELECT`].includes(e.target.tagName)&&(d||f)&&(_.current?.contains(document.activeElement)||document.fullscreenElement===_.current||document.activeElement===document.body))switch(e.key.toLowerCase()){case` `:case`k`:e.preventDefault(),X();break;case`arrowright`:e.preventDefault(),Y(10);break;case`arrowleft`:e.preventDefault(),Y(-10);break;case`arrowup`:{e.preventDefault();let t=Math.min(1,E+.1);D(t),t>0&&k(!1);break}case`arrowdown`:{e.preventDefault();let t=Math.max(0,E-.1);D(t);break}case`m`:e.preventDefault(),Z();break;case`f`:e.preventDefault(),Q();break;case`p`:e.preventDefault(),$()}};return window.addEventListener(`keydown`,e),()=>window.removeEventListener(`keydown`,e)},[b,E,w,d,f,Y,Z,X,Q,$,_]),{videoRef:h,containerRef:_,isPlaying:b,currentTime:S,duration:w,volume:E,isMuted:O,isFullscreen:A,playbackRate:M,activeFit:P,currentPlayIndex:I,currentQualityIndex:R,activeMenu:B,skipIndicator:W,activeSrc:K,activePoster:q,showNativeControls:J,setVolume:D,setIsMuted:k,setPlaybackRate:N,setActiveFit:F,setCurrentPlayIndex:L,setActiveMenu:V,togglePlay:X,toggleMute:Z,toggleFullscreen:Q,togglePiP:$,skip:Y,handleQualityChange:ee,playPlaylistItem:te,handleTimeUpdate:()=>{if(h.current){let e=h.current.currentTime;if(C(e),o&&s&&Math.floor(e)%5==0&&w>0&&e<w-2){let t=c&&c.length>0?`${o}-${I}`:o;localStorage.setItem(`wimui-video-resume-${t}`,e.toString())}}},handleLoadedMetadata:()=>{h.current&&T(h.current.duration)},handleEnded:()=>{if(o&&s){let e=c&&c.length>0?`${o}-${I}`:o;localStorage.removeItem(`wimui-video-resume-${e}`)}c&&c.length>0&&l&&I<c.length-1?(L(e=>e+1),h.current&&y(()=>{h.current?.play()},100)):x(!1)},handleSeek:e=>{let t=parseFloat(e.target.value);h.current&&(h.current.currentTime=t,C(t))},handleVolumeChange:e=>{let t=parseFloat(e.target.value);D(t),t>0&&k(!1)},handleVideoClick:e=>{if(!d&&!f)return;let t=new Date().getTime(),n=e.currentTarget.getBoundingClientRect(),r=e.clientX-n.left,i=n.width;H&&t-H.time<300?(r>i/2?(Y(10),G({show:!0,direction:`forward`})):(Y(-10),G({show:!0,direction:`backward`})),y(()=>G({show:!1,direction:`forward`}),600),U(null)):(U({time:t,x:r}),y(()=>{Date.now()-t>=290&&X()},300))},formatTime:e=>`${Math.floor(e/60)}:${Math.floor(e%60).toString().padStart(2,`0`)}`}}exports.useVideoPlayer=n;