@hozo/semantics 0.1.0 → 0.3.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 (58) hide show
  1. package/CHANGELOG.md +40 -0
  2. package/README.md +39 -0
  3. package/dist/generated/badge.d.ts +2 -0
  4. package/dist/generated/badge.d.ts.map +1 -0
  5. package/dist/generated/badge.js +2 -0
  6. package/dist/generated/badge.js.map +1 -0
  7. package/dist/generated/badge.native.d.ts +2 -0
  8. package/dist/generated/badge.native.d.ts.map +1 -0
  9. package/dist/generated/badge.native.js +2 -0
  10. package/dist/generated/badge.native.js.map +1 -0
  11. package/dist/generated/meter.d.ts +2 -0
  12. package/dist/generated/meter.d.ts.map +1 -0
  13. package/dist/generated/meter.js +2 -0
  14. package/dist/generated/meter.js.map +1 -0
  15. package/dist/generated/meter.native.d.ts +2 -0
  16. package/dist/generated/meter.native.d.ts.map +1 -0
  17. package/dist/generated/meter.native.js +2 -0
  18. package/dist/generated/meter.native.js.map +1 -0
  19. package/dist/generated/table.d.ts +2 -0
  20. package/dist/generated/table.d.ts.map +1 -0
  21. package/dist/generated/table.js +2 -0
  22. package/dist/generated/table.js.map +1 -0
  23. package/dist/generated/table.native.d.ts +2 -0
  24. package/dist/generated/table.native.d.ts.map +1 -0
  25. package/dist/generated/table.native.js +2 -0
  26. package/dist/generated/table.native.js.map +1 -0
  27. package/dist/index.d.ts +58 -0
  28. package/dist/index.d.ts.map +1 -1
  29. package/dist/index.js +74 -16
  30. package/dist/index.js.map +1 -1
  31. package/dist/index.native.d.ts +60 -0
  32. package/dist/index.native.d.ts.map +1 -1
  33. package/dist/index.native.js +83 -6
  34. package/dist/index.native.js.map +1 -1
  35. package/dist/meter-gauge.d.ts +30 -0
  36. package/dist/meter-gauge.d.ts.map +1 -0
  37. package/dist/meter-gauge.js +36 -0
  38. package/dist/meter-gauge.js.map +1 -0
  39. package/dist/table.d.ts +45 -0
  40. package/dist/table.d.ts.map +1 -0
  41. package/dist/table.js +31 -0
  42. package/dist/table.js.map +1 -0
  43. package/dist/table.native.d.ts +92 -0
  44. package/dist/table.native.d.ts.map +1 -0
  45. package/dist/table.native.js +207 -0
  46. package/dist/table.native.js.map +1 -0
  47. package/package.json +28 -3
  48. package/src/generated/badge.native.ts +1 -0
  49. package/src/generated/badge.ts +1 -0
  50. package/src/generated/meter.native.ts +1 -0
  51. package/src/generated/meter.ts +1 -0
  52. package/src/generated/table.native.ts +7 -0
  53. package/src/generated/table.ts +7 -0
  54. package/src/index.native.tsx +151 -6
  55. package/src/index.tsx +255 -45
  56. package/src/meter-gauge.ts +54 -0
  57. package/src/table.native.tsx +446 -0
  58. package/src/table.tsx +144 -0
@@ -1,5 +1,5 @@
1
1
  import { jsx as _jsx } from "react/jsx-runtime";
2
- import { hozoTextChildren } from '@hozo/behaviors';
2
+ import { hozoTextChildren, useHozoMessage } from '@hozo/behaviors';
3
3
  import { hozoPreflight } from '@hozo/engine/project';
4
4
  import React, {} from 'react';
5
5
  // The components rather than their names. These files used to render
@@ -12,6 +12,7 @@ import React, {} from 'react';
12
12
  // half through `react-dom/server`.
13
13
  import { Text, View, } from 'react-native';
14
14
  import { HozoDetails, HozoSummary } from './disclosure.native.js';
15
+ import { meterGauge } from './meter-gauge.js';
15
16
  export function Main({ role = 'main', children, ...props }) {
16
17
  return React.createElement(View, { role, ...props }, hozoTextChildren(children));
17
18
  }
@@ -134,11 +135,14 @@ export function Progress({ value, max, role = 'progressbar', accessibilityValue,
134
135
  return React.createElement(View, {
135
136
  role,
136
137
  accessibilityRole: 'progressbar',
137
- accessibilityValue: accessibilityValue ?? {
138
- min: 0,
139
- max: max ?? 100,
140
- now: value,
141
- },
138
+ // One element, or Android never focuses it; see `Meter`.
139
+ accessible: true,
140
+ // Scaled to 0..100 when `max` is given: Android takes whole numbers, so
141
+ // 0.5 of 1 would otherwise be read as "0" (#789).
142
+ accessibilityValue: accessibilityValue ??
143
+ (max !== undefined && value !== undefined
144
+ ? { min: 0, max: 100, now: Math.round((value / max) * 100) }
145
+ : { min: 0, max: max ?? 100, now: value }),
142
146
  // The box the browser gives `<progress>` and React Native gives
143
147
  // nothing. Measured in headless Chrome under this project’s own
144
148
  // preflight: 160 x 16. Without it a `View` is zero pixels in both
@@ -151,4 +155,77 @@ export function Progress({ value, max, role = 'progressbar', accessibilityValue,
151
155
  ...props,
152
156
  }, hozoTextChildren(children));
153
157
  }
158
+ /**
159
+ * A short status label, on React Native: a `Text`, which -- unlike a
160
+ * `<span>` -- may carry an `accessibilityLabel`, so a count is the digit
161
+ * drawn and the sentence read with nothing hidden.
162
+ */
163
+ export function Badge({ count, max, accessibilityLabel, children, ...props }) {
164
+ const message = useHozoMessage();
165
+ if (count === undefined) {
166
+ return React.createElement(Text, { accessibilityLabel, ...props }, children);
167
+ }
168
+ const over = max !== undefined && count > max;
169
+ const shown = over ? `${max}+` : String(count);
170
+ const label = accessibilityLabel ?? (over ? message('hozo.badge.overflow', { max: max }) : shown);
171
+ return React.createElement(Text, { ...props, accessibilityLabel: label }, shown);
172
+ }
173
+ /**
174
+ * A loading placeholder, on React Native: a `View` hidden from assistive
175
+ * technology. Compiled, an animation class on it runs only when motion is
176
+ * allowed; this fallback for an uncompiled file draws whatever `style` it is
177
+ * given.
178
+ */
179
+ export function Skeleton({ children, ...props }) {
180
+ return React.createElement(View, { ...props, 'aria-hidden': true }, children);
181
+ }
182
+ /**
183
+ * An amount within a known range, on React Native: the bar the browser draws
184
+ * for `<meter>`, and the amount a reader hears.
185
+ *
186
+ * React Native accepts `role="meter"`, and Android does not map it to a
187
+ * platform role yet, so the amount is carried by `accessibilityValue`,
188
+ * which a reader announces either way. The range is 0 to 1 when left out,
189
+ * as `<meter>` reads it.
190
+ *
191
+ * The bar is a track and a fill, coloured by `low`, `high` and `optimum` the
192
+ * way Chrome colours its own (#788): the three colours are read off its
193
+ * pixels, not chosen. The author's `style` -- compiled from `className` --
194
+ * is the track's, so `bg-*`, `rounded-*` and the size all land where they
195
+ * would on the Web; the fill is clipped to it. Children are a `<meter>`'s
196
+ * fallback content, which no browser draws, so neither does this.
197
+ */
198
+ export function Meter({ value, min, max, low, high, optimum, role = 'meter', accessibilityValue, style, children: _children, ...props }) {
199
+ const { fraction, region } = meterGauge({ value, min, max, low, high, optimum });
200
+ return React.createElement(View, {
201
+ role,
202
+ // A View is one element for a screen reader on Android only when it
203
+ // says so; without this TalkBack's focus never landed on it (#789).
204
+ accessible: true,
205
+ // A percentage text and no range: Android rounds a range to whole
206
+ // numbers, and TalkBack calls anything with one a "progress bar" (#789).
207
+ accessibilityValue: accessibilityValue ?? { text: `${Math.round(fraction * 100)}%` },
208
+ // `<meter>`'s box in Chrome, 80 x 16, for the reason `Progress` has
209
+ // one: a View with none is zero pixels and absent from the tree.
210
+ style: [METER_TRACK, style],
211
+ ...props,
212
+ }, React.createElement(View, {
213
+ style: [METER_FILL, { width: `${fraction * 100}%`, backgroundColor: METER_COLOURS[region] }],
214
+ }));
215
+ }
216
+ const METER_TRACK = {
217
+ width: 80,
218
+ height: 16,
219
+ backgroundColor: '#efefef',
220
+ overflow: 'hidden',
221
+ flexDirection: 'row',
222
+ };
223
+ const METER_FILL = { height: '100%' };
224
+ /** Chrome's, sampled from a rendered `<meter>` in each region. */
225
+ const METER_COLOURS = {
226
+ optimum: '#107c10',
227
+ suboptimal: '#ffb900',
228
+ 'even-less-good': '#d83b01',
229
+ };
230
+ export { HozoTable, HozoTableCaption, HozoTableCell, HozoTableRow, HozoTableSection, Table, TableBody, TableCaption, TableCell, TableFooter, TableHead, TableHeader, TableRow, } from './table.native.js';
154
231
  //# sourceMappingURL=index.native.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.native.js","sourceRoot":"","sources":["../src/index.native.tsx"],"names":[],"mappings":";AAAA,OAAO,EAAE,gBAAgB,EAAE,MAAM,iBAAiB,CAAA;AAClD,OAAO,EAAE,aAAa,EAAE,MAAM,sBAAsB,CAAA;AACpD,OAAO,KAAK,EAAE,EAAuC,MAAM,O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ount sits and which of its three colours it gets,
3
+ * worked out the way the browser does, so React Native can draw the bar the
4
+ * Web is given for free.
5
+ *
6
+ * The clamping follows the HTML standard's `<meter>` attributes: the range is
7
+ * 0 to 1 when left out, `max` is never below `min`, `value` and `optimum` sit
8
+ * inside the range, `low` inside it, and `high` between `low` and `max`. The
9
+ * regions are the browser's: an optimum between `low` and `high` makes that
10
+ * middle stretch good and both sides fair; an optimum beyond either boundary
11
+ * makes its own end good, the middle fair and the far end poor. A boundary
12
+ * belongs to the better side, every time -- read off Chromium's own pixels
13
+ * for 110 combinations, which is what the tests' edge cases are.
14
+ */
15
+ export type MeterRegion = 'optimum' | 'suboptimal' | 'even-less-good';
16
+ export interface MeterGauge {
17
+ /** How far along the range the amount is, 0 to 1. */
18
+ fraction: number;
19
+ region: MeterRegion;
20
+ }
21
+ export interface MeterRange {
22
+ value: number;
23
+ min?: number;
24
+ max?: number;
25
+ low?: number;
26
+ high?: number;
27
+ optimum?: number;
28
+ }
29
+ export declare function meterGauge({ value, min, max, low, high, optimum }: MeterRange): MeterGauge;
30
+ //# sourceMappingURL=meter-gauge.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"meter-gauge.d.ts","sourceRoot":"","sources":["../src/meter-gauge.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;GAaG;AAEH,MAAM,MAAM,WAAW,GAAG,SAAS,GAAG,YAAY,GAAG,gBAAgB,CAAA;AAErE,MAAM,WAAW,UAAU;IACzB,qDAAqD;IACrD,QAAQ,EAAE,MAAM,CAAA;IAChB,MAAM,EAAE,WAAW,CAAA;CACpB;AAED,MAAM,WAAW,UAAU;IACzB,KAAK,EAAE,MAAM,CAAA;IACb,GAAG,CAAC,EAAE,MAAM,CAAA;IACZ,GAAG,CAAC,EAAE,MAAM,CAAA;IACZ,GAAG,CAAC,EAAE,MAAM,CAAA;IACZ,IAAI,CAAC,EAAE,MAAM,CAAA;IACb,OAAO,CAAC,EAAE,MAAM,CAAA;CACjB;AAKD,wBAAgB,UAAU,CAAC,EAAE,KAAK,EAAE,GAAG,EAAE,GAAG,EAAE,GAAG,EAAE,IAAI,EAAE,OAAO,EAAE,EAAE,UAAU,GAAG,UAAU,CAkB1F"}
@@ -0,0 +1,36 @@
1
+ /**
2
+ * Where a `<meter>`'s amount sits and which of its three colours it gets,
3
+ * worked out the way the browser does, so React Native can draw the bar the
4
+ * Web is given for free.
5
+ *
6
+ * The clamping follows the HTML standard's `<meter>` attributes: the range is
7
+ * 0 to 1 when left out, `max` is never below `min`, `value` and `optimum` sit
8
+ * inside the range, `low` inside it, and `high` between `low` and `max`. The
9
+ * regions are the browser's: an optimum between `low` and `high` makes that
10
+ * middle stretch good and both sides fair; an optimum beyond either boundary
11
+ * makes its own end good, the middle fair and the far end poor. A boundary
12
+ * belongs to the better side, every time -- read off Chromium's own pixels
13
+ * for 110 combinations, which is what the tests' edge cases are.
14
+ */
15
+ const clamp = (value, lowest, highest) => Math.min(Math.max(value, lowest), highest);
16
+ export function meterGauge({ value, min, max, low, high, optimum }) {
17
+ const start = min ?? 0;
18
+ const end = Math.max(start, max ?? 1);
19
+ const amount = clamp(value, start, end);
20
+ const lowBound = clamp(low ?? start, start, end);
21
+ const highBound = clamp(high ?? end, lowBound, end);
22
+ const best = clamp(optimum ?? (start + end) / 2, start, end);
23
+ const fraction = end === start ? 0 : (amount - start) / (end - start);
24
+ let region;
25
+ if (lowBound <= best && best <= highBound) {
26
+ region = lowBound <= amount && amount <= highBound ? 'optimum' : 'suboptimal';
27
+ }
28
+ else if (highBound < best) {
29
+ region = highBound <= amount ? 'optimum' : lowBound <= amount ? 'suboptimal' : 'even-less-good';
30
+ }
31
+ else {
32
+ region = amount <= lowBound ? 'optimum' : amount <= highBound ? 'suboptimal' : 'even-less-good';
33
+ }
34
+ return { fraction, region };
35
+ }
36
+ //# sourceMappingURL=meter-gauge.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"meter-gauge.js","sourceRoot":"","sources":["../src/meter-gauge.ts"],"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;SAAM,IAAI,SAAS,GAAG,IAAI,EAAE,CAAC;QAC5B,MAAM,GAAG,SAAS,IAAI,MAAM,CAAC,CAAC,CAAC,SAAS,CAAC,CAAC,CAAC,QAAQ,IAAI,MAAM,CAAC,CAAC,CAAC,YAAY,CAAC,CAAC,CAAC,gBAAgB,CAAA;IACjG,CAAC;SAAM,CAAC;QACN,MAAM,GAAG,MAAM,IAAI,QAAQ,CAAC,CAAC,CAAC,SAAS,CAAC,CAAC,CAAC,MAAM,IAAI,SAAS,CAAC,CAAC,CAAC,YAAY,CAAC,CAAC,CAAC,gBAAgB,CAAA;IACjG,CAAC;IACD,OAAO,EAAE,QAAQ,EAAE,MAAM,EAAE,CAAA;AAC7B,CAAC"}
@@ -0,0 +1,45 @@
1
+ import type { CSSProperties, ReactNode, Ref } from 'react';
2
+ /**
3
+ * A data table on the Web: the table elements themselves, which already lay
4
+ * out their columns from every cell and give a reader row and column
5
+ * navigation. These are what a file the compiler did not read renders;
6
+ * compiled, the same names lower to the elements directly.
7
+ *
8
+ * The `Hozo…` names are the ones compiled Native output imports. They exist
9
+ * here too so a module that names them type-checks on both platforms.
10
+ */
11
+ interface PartProps {
12
+ children?: ReactNode;
13
+ className?: string;
14
+ style?: CSSProperties;
15
+ testID?: string;
16
+ }
17
+ export interface HozoTableProps extends PartProps {
18
+ /** Native only: scroll sideways when the table does not fit. */
19
+ scrollable?: boolean;
20
+ accessibilityLabel?: string;
21
+ }
22
+ export declare function HozoTable({ children, className, style, testID, accessibilityLabel, }: HozoTableProps): import("react").JSX.Element;
23
+ export type HozoTableCaptionProps = PartProps;
24
+ export declare function HozoTableCaption({ children, className, style }: HozoTableCaptionProps): import("react").JSX.Element;
25
+ export interface HozoTableSectionProps extends PartProps {
26
+ section?: 'header' | 'body' | 'footer';
27
+ }
28
+ export declare function HozoTableSection({ section, children, className, style, }: HozoTableSectionProps): import("react").JSX.Element;
29
+ export type HozoTableRowProps = PartProps;
30
+ export declare function HozoTableRow({ children, className, style }: HozoTableRowProps): import("react").JSX.Element;
31
+ export interface HozoTableCellProps extends PartProps {
32
+ /** The cell element, for focusing or measuring it. */
33
+ ref?: Ref<HTMLTableCellElement>;
34
+ head?: boolean;
35
+ scope?: 'col' | 'row';
36
+ colSpan?: number;
37
+ accessibilityLabel?: string;
38
+ }
39
+ export declare function HozoTableCell({ head, scope, colSpan, accessibilityLabel, children, className, style, ref, }: HozoTableCellProps): import("react").JSX.Element;
40
+ export declare function TableHeader(props: Omit<HozoTableSectionProps, 'section'>): import("react").JSX.Element;
41
+ export declare function TableBody(props: Omit<HozoTableSectionProps, 'section'>): import("react").JSX.Element;
42
+ export declare function TableFooter(props: Omit<HozoTableSectionProps, 'section'>): import("react").JSX.Element;
43
+ export declare function TableHead(props: Omit<HozoTableCellProps, 'head'>): import("react").JSX.Element;
44
+ export { HozoTable as Table, HozoTableCaption as TableCaption, type HozoTableCaptionProps as TableCaptionProps, HozoTableCell as TableCell, type HozoTableCellProps as TableCellProps, type HozoTableProps as TableProps, HozoTableRow as TableRow, type HozoTableRowProps as TableRowProps, type HozoTableSectionProps as TableSectionProps, };
45
+ //# sourceMappingURL=table.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"table.d.ts","sourceRoot":"","sources":["../src/table.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,aAAa,EAAE,SAAS,EAAE,GAAG,EAAE,MAAM,OAAO,CAAA;AAE1D;;;;;;;;GAQG;AAEH,UAAU,SAAS;IACjB,QAAQ,CAAC,EAAE,SAAS,CAAA;IACpB,SAAS,CAAC,EAAE,MAAM,CAAA;IAClB,KAAK,CAAC,EAAE,aAAa,CAAA;IACrB,MAAM,CAAC,EAAE,MAAM,CAAA;CAChB;AAED,MAAM,WAAW,cAAe,SAAQ,SAAS;IAC/C,gEAAgE;IAChE,UAAU,CAAC,EAAE,OAAO,CAAA;IACpB,kBAAkB,CAAC,EAAE,MAAM,CAAA;CAC5B;AAED,wBAAgB,SAAS,CAAC,EACxB,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AAC,+BAExE;AACD,wBAAgB,SAAS,CAAC,KAAK,EAAE,IAAI,CAAC,kBAAkB,EAAE,MAAM,CAAC,+BAEhE;AAED,OAAO,EACL,SAAS,IAAI,KAAK,EAClB,gBAAgB,IAAI,YAAY,EAChC,KAAK,qBAAqB,IAAI,iBAAiB,EAC/C,aAAa,IAAI,SAAS,EAC1B,KAAK,kBAAkB,IAAI,cAAc,EACzC,KAAK,cAAc,IAAI,UAAU,EACjC,YAAY,IAAI,QAAQ,EACxB,KAAK,iBAAiB,IAAI,aAAa,EACvC,KAAK,qBAAqB,IAAI,iBAAiB,GAChD,CAAA"}
package/dist/table.js ADDED
@@ -0,0 +1,31 @@
1
+ import { jsx as _jsx } from "react/jsx-runtime";
2
+ export function HozoTable({ children, className, style, testID, accessibilityLabel, }) {
3
+ return (_jsx("table", { className: className, style: style, "data-testid": testID, "aria-label": accessibilityLabel, children: children }));
4
+ }
5
+ export function HozoTableCaption({ children, className, style }) {
6
+ return (_jsx("caption", { className: className, style: style, children: children }));
7
+ }
8
+ export function HozoTableSection({ section = 'body', children, className, style, }) {
9
+ const Tag = section === 'header' ? 'thead' : section === 'footer' ? 'tfoot' : 'tbody';
10
+ return (_jsx(Tag, { className: className, style: style, children: children }));
11
+ }
12
+ export function HozoTableRow({ children, className, style }) {
13
+ return (_jsx("tr", { className: className, style: style, children: children }));
14
+ }
15
+ export function HozoTableCell({ head, scope, colSpan, accessibilityLabel, children, className, style, ref, }) {
16
+ return head ? (_jsx("th", { ref: ref, scope: scope ?? 'col', colSpan: colSpan, "aria-label": accessibilityLabel, className: className, style: style, children: children })) : (_jsx("td", { ref: ref, colSpan: colSpan, "aria-label": accessibilityLabel, className: className, style: style, children: children }));
17
+ }
18
+ export function TableHeader(props) {
19
+ return _jsx(HozoTableSection, { ...props, section: "header" });
20
+ }
21
+ export function TableBody(props) {
22
+ return _jsx(HozoTableSection, { ...props, section: "body" });
23
+ }
24
+ export function TableFooter(props) {
25
+ return _jsx(HozoTableSection, { ...props, section: "footer" });
26
+ }
27
+ export function TableHead(props) {
28
+ return _jsx(HozoTableCell, { ...props, head: true });
29
+ }
30
+ export { HozoTable as Table, HozoTableCaption as TableCaption, HozoTableCell as TableCell, HozoTableRow as TableRow, };
31
+ //# sourceMappingURL=table.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"table.js","sourceRoot":"","sources":["../src/table.tsx"],"names":[],"mappings":";AAyBA,MAAM,UAAU,SAAS,CAAC,EACxB,QAAQ,EACR,SAAS,EACT,KAAK,EACL,MAAM,EACN,kBAAkB,GACH;IACf,OAAO,CACL,gBAAO,SAAS,EAAE,SAAS,EAAE,KAAK,EAAE,KAAK,iBAAe,MAAM,gBAAc,kBAAkB,YAC3F,QAAQ,GACH,CACT,CAAA;AACH,CAAC;AAID,MAAM,UAAU,gBAAgB,CAAC,EAAE,QAAQ,EAAE,SAAS,EAAE,KAAK,EAAyB;IACpF,OAAO,CACL,kBAAS,SAAS,EAAE,SAAS,EAAE,KAAK,EAAE,KAAK,YACxC,QAAQ,GACD,CACX,CAAA;AACH,CAAC;AAMD,MAAM,UAAU,gBAAgB,CAAC,EAC/B,OAAO,GAAG,MAAM,EAChB,QAAQ,EACR,SAAS,EACT,KAAK,GACiB;IACtB,MAAM,GAAG,GAAG,OAAO,KAAK,QAAQ,CAAC,CAAC,CAAC,OAAO,CAAC,CAAC,CAAC,OAAO,KAAK,QAAQ,CAAC,CAAC,CAAC,OAAO,CAAC,CAAC,CAAC,OAAO,CAAA;IACrF,OAAO,CACL,KAAC,GAAG,IAAC,SAAS,EAAE,SAAS,EAAE,KAAK,EAAE,KAAK,YACpC,QAAQ,GACL,CACP,CAAA;AACH,CAAC;AAID,MAAM,UAAU,YAAY,CAAC,EAAE,QAAQ,EAAE,SAAS,EAAE,KAAK,EAAqB;IAC5E,OAAO,CACL,aAAI,SAAS,EAAE,SAAS,EAAE,KAAK,EAAE,KAAK,YACnC,QAAQ,GACN,CACN,CAAA;AACH,CAAC;AAWD,MAAM,UAAU,aAAa,CAAC,EAC5B,IAAI,EACJ,KAAK,EACL,OAAO,EACP,kBAAkB,EAClB,QAAQ,EACR,SAAS,EACT,KAAK,EACL,GAAG,GACgB;IACnB,OAAO,IAAI,CAAC,CAAC,CAAC,CACZ,aACE,GAAG,EAAE,GAAG,EACR,KAAK,EAAE,KAAK,IAAI,KAAK,EACrB,OAAO,EAAE,OAAO,gBACJ,kBAAkB,EAC9B,SAAS,EAAE,SAAS,EACpB,KAAK,EAAE,KAAK,YAEX,QAAQ,GACN,CACN,CAAC,CAAC,CAAC,CACF,aACE,GAAG,EAAE,GAAG,EACR,OAAO,EAAE,OAAO,gBACJ,kBAAkB,EAC9B,SAAS,EAAE,SAAS,EACpB,KAAK,EAAE,KAAK,YAEX,QAAQ,GACN,CACN,CAAA;AACH,CAAC;AAED,MAAM,UAAU,WAAW,CAAC,KAA6C;IACvE,OAAO,KAAC,gBAAgB,OAAK,KAAK,EAAE,OAAO,EAAC,QAAQ,GAAG,CAAA;AACzD,CAAC;AACD,MAAM,UAAU,SAAS,CAAC,KAA6C;IACrE,OAAO,KAAC,gBAAgB,OAAK,KAAK,EAAE,OAAO,EAAC,MAAM,GAAG,CAAA;AACvD,CAAC;AACD,MAAM,UAAU,WAAW,CAAC,KAA6C;IACvE,OAAO,KAAC,gBAAgB,OAAK,KAAK,EAAE,OAAO,EAAC,QAAQ,GAAG,CAAA;AACzD,CAAC;AACD,MAAM,UAAU,SAAS,CAAC,KAAuC;IAC/D,OAAO,KAAC,aAAa,OAAK,KAAK,EAAE,IAAI,SAAG,CAAA;AAC1C,CAAC;AAED,OAAO,EACL,SAAS,IAAI,KAAK,EAClB,gBAAgB,IAAI,YAAY,EAEhC,aAAa,IAAI,SAAS,EAG1B,YAAY,IAAI,QAAQ,GAGzB,CAAA"}
@@ -0,0 +1,92 @@
1
+ import { type ComponentRef, type ReactNode, type Ref } from 'react';
2
+ import { type StyleProp, type TextStyle, View, type ViewStyle } from 'react-native';
3
+ export interface HozoTableProps {
4
+ children?: ReactNode;
5
+ style?: StyleProp<ViewStyle | TextStyle>;
6
+ /** Keep the table's width and scroll sideways when it does not fit. */
7
+ scrollable?: boolean;
8
+ accessibilityLabel?: string;
9
+ testID?: string;
10
+ /** Read by the compiler; see `SemanticsNativeProps.className`. */
11
+ className?: string;
12
+ }
13
+ export declare function HozoTable({ children, style, scrollable, accessibilityLabel, testID, }: HozoTableProps): import("react").JSX.Element;
14
+ export interface HozoTableSectionProps {
15
+ children?: ReactNode;
16
+ section?: 'header' | 'body' | 'footer';
17
+ style?: StyleProp<ViewStyle>;
18
+ testID?: string;
19
+ /** Read by the compiler; see `SemanticsNativeProps.className`. */
20
+ className?: string;
21
+ }
22
+ /** `<thead>`, `<tbody>` or `<tfoot>`: a group of rows, and nothing to read. */
23
+ export declare function HozoTableSection({ children, style, testID }: HozoTableSectionProps): import("react").JSX.Element;
24
+ export declare namespace HozoTableSection {
25
+ var hozoTablePart: "section";
26
+ }
27
+ export interface HozoTableRowProps {
28
+ children?: ReactNode;
29
+ style?: StyleProp<ViewStyle>;
30
+ testID?: string;
31
+ /** Read by the compiler; see `SemanticsNativeProps.className`. */
32
+ className?: string;
33
+ }
34
+ /** `<tr>`: numbers its cells, columns spanned included. */
35
+ export declare function HozoTableRow({ children, style, testID }: HozoTableRowProps): import("react").JSX.Element;
36
+ export declare namespace HozoTableRow {
37
+ var hozoTablePart: "row";
38
+ }
39
+ export interface HozoTableCellProps {
40
+ children?: ReactNode;
41
+ /** A header cell: `<th>`. */
42
+ head?: boolean;
43
+ /** `"row"` for a header that heads its row rather than its column. */
44
+ scope?: 'col' | 'row';
45
+ colSpan?: number;
46
+ accessibilityLabel?: string;
47
+ style?: StyleProp<ViewStyle | TextStyle>;
48
+ testID?: string;
49
+ /** Read by the compiler; see `SemanticsNativeProps.className`. */
50
+ className?: string;
51
+ /**
52
+ * The cell's View: for focusing it, or measuring where it landed. A prop
53
+ * rather than `forwardRef`, as React 19 hands a function component its ref.
54
+ */
55
+ ref?: Ref<ComponentRef<typeof View>>;
56
+ }
57
+ /** `<th>` or `<td>`. */
58
+ export declare function HozoTableCell({ children, head, scope, accessibilityLabel, style, testID, ref, }: HozoTableCellProps): import("react").JSX.Element;
59
+ export declare namespace HozoTableCell {
60
+ var hozoTablePart: "cell";
61
+ }
62
+ export interface HozoTableCaptionProps {
63
+ children?: ReactNode;
64
+ style?: StyleProp<TextStyle>;
65
+ testID?: string;
66
+ /** Read by the compiler; see `SemanticsNativeProps.className`. */
67
+ className?: string;
68
+ }
69
+ /** `<caption>`: the table's name, above it. */
70
+ export declare function HozoTableCaption({ children, style, testID }: HozoTableCaptionProps): import("react").JSX.Element;
71
+ /**
72
+ * The names a file the compiler did not read renders. Compiled, each is
73
+ * lowered to the component above it.
74
+ */
75
+ export declare function TableHeader(props: Omit<HozoTableSectionProps, 'section'>): import("react").JSX.Element;
76
+ export declare namespace TableHeader {
77
+ var hozoTablePart: "section";
78
+ }
79
+ export declare function TableBody(props: Omit<HozoTableSectionProps, 'section'>): import("react").JSX.Element;
80
+ export declare namespace TableBody {
81
+ var hozoTablePart: "section";
82
+ }
83
+ export declare function TableFooter(props: Omit<HozoTableSectionProps, 'section'>): import("react").JSX.Element;
84
+ export declare namespace TableFooter {
85
+ var hozoTablePart: "section";
86
+ }
87
+ export declare function TableHead(props: Omit<HozoTableCellProps, 'head'>): import("react").JSX.Element;
88
+ export declare namespace TableHead {
89
+ var hozoTablePart: "head";
90
+ }
91
+ export { HozoTable as Table, HozoTableCaption as TableCaption, type HozoTableCaptionProps as TableCaptionProps, HozoTableCell as TableCell, type HozoTableCellProps as TableCellProps, type HozoTableProps as TableProps, HozoTableRow as TableRow, type HozoTableRowProps as TableRowProps, type HozoTableSectionProps as TableSectionProps, };
92
+ //# sourceMappingURL=table.native.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"table.native.d.ts","sourceRoot":"","sources":["../src/table.native.tsx"],"names":[],"mappings":"AAAA,OAAO,EAEL,KAAK,YAAY,E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AAE,IAAI,CAAC,qBAAqB,EAAE,SAAS,CAAC,+BAEtE;yBAFe,SAAS;;;AAIzB,wBAAgB,WAAW,CAAC,KAAK,EAAE,IAAI,CAAC,qBAAqB,EAAE,SAAS,CAAC,+BAExE;yBAFe,WAAW;;;AAI3B,wBAAgB,SAAS,CAAC,KAAK,EAAE,IAAI,CAAC,kBAAkB,EAAE,MAAM,CAAC,+BAEhE;yBAFe,SAAS;;;AAKzB,OAAO,EACL,SAAS,IAAI,KAAK,EAClB,gBAAgB,IAAI,YAAY,EAChC,KAAK,qBAAqB,IAAI,iBAAiB,EAC/C,aAAa,IAAI,SAAS,EAC1B,KAAK,kBAAkB,IAAI,cAAc,EACzC,KAAK,cAAc,IAAI,UAAU,EACjC,YAAY,IAAI,QAAQ,EACxB,KAAK,iBAAiB,IAAI,aAAa,EACvC,KAAK,qBAAqB,IAAI,iBAAiB,GAChD,CAAA"}
@@ -0,0 +1,207 @@
1
+ import { jsx as _jsx } from "react/jsx-runtime";
2
+ import { Children, createContext, isValidElement, useCallback, useContext, useMemo, useRef, useState, } from 'react';
3
+ import { ScrollView, StyleSheet, Text, View, } from 'react-native';
4
+ const TableContext = createContext(null);
5
+ const RowContext = createContext(null);
6
+ const CellContext = createContext(null);
7
+ /** The words in a cell, for naming it, or `undefined` if it holds more. */
8
+ function textOf(node) {
9
+ if (typeof node === 'string' || typeof node === 'number')
10
+ return String(node);
11
+ if (Array.isArray(node)) {
12
+ const parts = node.map(textOf);
13
+ return parts.every((part) => part !== undefined) ? parts.join('') : undefined;
14
+ }
15
+ if (isValidElement(node))
16
+ return textOf(node.props.children);
17
+ return undefined;
18
+ }
19
+ const elements = (children) => Children.toArray(children).filter(isValidElement);
20
+ const part = (element) => element.type.hozoTablePart;
21
+ const isHeadCell = (cell) => part(cell) === 'head' || isHead(cell.props.head);
22
+ const span = (cell) => typeof cell.props.colSpan === 'number' && cell.props.colSpan > 1 ? cell.props.colSpan : 1;
23
+ /**
24
+ * Rows in document order and the cells in each, read off the element tree
25
+ * rather than counted as they render, so the numbering does not depend on
26
+ * render order and survives `rows.map(...)`.
27
+ */
28
+ function structure(children) {
29
+ const rows = [];
30
+ for (const child of elements(children)) {
31
+ if (part(child) === 'section')
32
+ rows.push(...elements(child.props.children));
33
+ else if (part(child) === 'row')
34
+ rows.push(child);
35
+ }
36
+ return rows.map((row) => elements(row.props.children));
37
+ }
38
+ export function HozoTable({ children, style, scrollable, accessibilityLabel, testID, }) {
39
+ const rows = structure(children);
40
+ const columnCount = Math.max(0, ...rows.map((cells) => cells.reduce((sum, cell) => sum + span(cell), 0)));
41
+ // What the measurement depends on: every cell's text, and the shape. A
42
+ // cell holding more than text contributes only its place.
43
+ const signature = rows
44
+ .map((cells) => cells
45
+ .map((cell) => `${span(cell)}:${textOf(cell.props.children) ?? '*'}`)
46
+ .join('|'))
47
+ .join('\n');
48
+ const headers = [];
49
+ for (const cells of rows) {
50
+ let column = 0;
51
+ for (const cell of cells) {
52
+ if (isHeadCell(cell) && cell.props.scope !== 'row' && headers[column] === undefined) {
53
+ headers[column] = textOf(cell.props.children);
54
+ }
55
+ column += span(cell);
56
+ }
57
+ }
58
+ const measured = useRef(new Map());
59
+ const takenFor = useRef(signature);
60
+ if (takenFor.current !== signature) {
61
+ // The cells changed since these were taken: start again.
62
+ measured.current = new Map();
63
+ takenFor.current = signature;
64
+ }
65
+ const [natural, setNatural] = useState(null);
66
+ const [measuredFor, setMeasuredFor] = useState(null);
67
+ const [available, setAvailable] = useState(null);
68
+ const measuring = measuredFor !== signature;
69
+ const expected = rows.reduce((sum, cells) => sum + cells.filter((cell) => span(cell) === 1).length, 0);
70
+ const report = useCallback((key, column, width) => {
71
+ measured.current.set(key, { column, width });
72
+ if (measured.current.size < expected)
73
+ return;
74
+ const widths = Array.from({ length: columnCount }, () => 0);
75
+ for (const entry of measured.current.values()) {
76
+ widths[entry.column] = Math.max(widths[entry.column] ?? 0, entry.width);
77
+ }
78
+ setNatural(widths);
79
+ setMeasuredFor(signature);
80
+ }, [columnCount, expected, signature]);
81
+ const flat = (StyleSheet.flatten(style) ?? {});
82
+ const fills = flat.width !== undefined || flat.flex !== undefined || flat.alignSelf === 'stretch';
83
+ const widths = useMemo(() => {
84
+ if (!natural || measuring)
85
+ return null;
86
+ const total = natural.reduce((sum, w) => sum + w, 0);
87
+ if (available === null || total === 0)
88
+ return natural;
89
+ const scale = (fills && total < available) || (!scrollable && total > available) ? available / total : 1;
90
+ return natural.map((w) => w * scale);
91
+ }, [available, fills, measuring, natural, scrollable]);
92
+ const info = { widths, headers, measuring, report };
93
+ const table = (_jsx(View, { style: [TABLE, style, measuring ? HIDDEN : null], accessibilityLabel: accessibilityLabel, testID: testID, children: _jsx(TableContext.Provider, { value: info, children: numbered(children) }) }));
94
+ return (_jsx(View, { onLayout: (event) => setAvailable(event.nativeEvent.layout.width), style: OUTER, children: scrollable ? (_jsx(ScrollView, { horizontal: true, showsHorizontalScrollIndicator: true, children: table })) : (table) }));
95
+ }
96
+ const isHead = (value) => value !== undefined && value !== false;
97
+ /** Gives each row its index in document order, sections included. */
98
+ function numbered(children) {
99
+ let row = 0;
100
+ const wrap = (child) => {
101
+ const index = row++;
102
+ return (_jsx(RowContext.Provider, { value: { row: index }, children: child }, child.key ?? index));
103
+ };
104
+ return elements(children).map((child) => {
105
+ if (part(child) === 'section') {
106
+ const rows = elements(child.props.children).map(wrap);
107
+ return { ...child, props: { ...child.props, children: rows } };
108
+ }
109
+ if (part(child) === 'row')
110
+ return wrap(child);
111
+ return child;
112
+ });
113
+ }
114
+ /** `<thead>`, `<tbody>` or `<tfoot>`: a group of rows, and nothing to read. */
115
+ export function HozoTableSection({ children, style, testID }) {
116
+ return (_jsx(View, { style: style, testID: testID, children: children }));
117
+ }
118
+ /** `<tr>`: numbers its cells, columns spanned included. */
119
+ export function HozoTableRow({ children, style, testID }) {
120
+ let column = 0;
121
+ return (_jsx(View, { style: [ROW, style], testID: testID, children: elements(children).map((cell, index) => {
122
+ const at = column;
123
+ column += span(cell);
124
+ return (_jsx(CellContext.Provider, { value: { column: at, span: span(cell) }, children: cell }, cell.key ?? index));
125
+ }) }));
126
+ }
127
+ /** What a `View` cannot draw: handed to the cell's `Text`. */
128
+ const TEXT_KEYS = new Set([
129
+ 'color',
130
+ 'fontFamily',
131
+ 'fontSize',
132
+ 'fontStyle',
133
+ 'fontVariant',
134
+ 'fontWeight',
135
+ 'letterSpacing',
136
+ 'lineHeight',
137
+ 'textAlign',
138
+ 'textDecorationLine',
139
+ 'textTransform',
140
+ ]);
141
+ /** `<th>` or `<td>`. */
142
+ export function HozoTableCell({ children, head, scope, accessibilityLabel, style, testID, ref, }) {
143
+ const table = useContext(TableContext);
144
+ const row = useContext(RowContext);
145
+ const cell = useContext(CellContext) ?? { column: 0, span: 1 };
146
+ const key = `${row?.row ?? 0}:${cell.column}`;
147
+ const box = {};
148
+ const text = {};
149
+ for (const [name, value] of Object.entries(StyleSheet.flatten(style) ?? {})) {
150
+ ;
151
+ (TEXT_KEYS.has(name) ? text : box)[name] = value;
152
+ }
153
+ const width = table?.widths
154
+ ? table.widths.slice(cell.column, cell.column + cell.span).reduce((sum, w) => sum + w, 0)
155
+ : undefined;
156
+ const words = textOf(children);
157
+ const header = isHead(head);
158
+ const columnHeader = table?.headers[cell.column];
159
+ const label = accessibilityLabel ??
160
+ (!header && words !== undefined && columnHeader ? `${columnHeader}, ${words}` : undefined);
161
+ return (_jsx(View, { ref: ref, style: [CELL, box, width !== undefined ? { width } : null], testID: testID, onLayout: table?.measuring && cell.span === 1
162
+ ? (event) => table.report(key, cell.column, event.nativeEvent.layout.width)
163
+ : undefined, accessible: words !== undefined ? true : undefined, accessibilityLabel: label, ...{
164
+ accessibilityCollectionItem: {
165
+ rowIndex: row?.row ?? 0,
166
+ rowSpan: 1,
167
+ columnIndex: cell.column,
168
+ columnSpan: cell.span,
169
+ heading: header && scope !== 'row',
170
+ },
171
+ }, children: words !== undefined ? _jsx(Text, { style: text, children: children }) : children }));
172
+ }
173
+ /** `<caption>`: the table's name, above it. */
174
+ export function HozoTableCaption({ children, style, testID }) {
175
+ return (_jsx(Text, { style: style, testID: testID, children: children }));
176
+ }
177
+ const OUTER = { alignSelf: 'stretch' };
178
+ // Shrink-to-fit, as a Web table with no width is.
179
+ const TABLE = { alignSelf: 'flex-start' };
180
+ const ROW = { flexDirection: 'row' };
181
+ const CELL = { flexShrink: 0 };
182
+ const HIDDEN = { opacity: 0 };
183
+ HozoTableSection.hozoTablePart = 'section';
184
+ HozoTableRow.hozoTablePart = 'row';
185
+ HozoTableCell.hozoTablePart = 'cell';
186
+ /**
187
+ * The names a file the compiler did not read renders. Compiled, each is
188
+ * lowered to the component above it.
189
+ */
190
+ export function TableHeader(props) {
191
+ return _jsx(HozoTableSection, { ...props, section: "header" });
192
+ }
193
+ TableHeader.hozoTablePart = 'section';
194
+ export function TableBody(props) {
195
+ return _jsx(HozoTableSection, { ...props, section: "body" });
196
+ }
197
+ TableBody.hozoTablePart = 'section';
198
+ export function TableFooter(props) {
199
+ return _jsx(HozoTableSection, { ...props, section: "footer" });
200
+ }
201
+ TableFooter.hozoTablePart = 'section';
202
+ export function TableHead(props) {
203
+ return _jsx(HozoTableCell, { ...props, head: true });
204
+ }
205
+ TableHead.hozoTablePart = 'head';
206
+ export { HozoTable as Table, HozoTableCaption as TableCaption, HozoTableCell as TableCell, HozoTableRow as TableRow, };
207
+ //# sourceMappingURL=table.native.js.map