@thanhphi/unistyles-ui 0.0.0-stage → 0.2.7

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 (70) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +384 -2
  3. package/dist/choices.d.ts +52 -0
  4. package/dist/choices.js +143 -0
  5. package/dist/colors/index.d.ts +79 -0
  6. package/dist/colors/index.js +2 -0
  7. package/dist/date.d.ts +40 -0
  8. package/dist/date.js +153 -0
  9. package/dist/fields.d.ts +140 -0
  10. package/dist/fields.js +233 -0
  11. package/dist/form/index.d.ts +14 -0
  12. package/dist/form/index.js +68 -0
  13. package/dist/icons.d.ts +10 -0
  14. package/dist/icons.js +52 -0
  15. package/dist/image.d.ts +20 -0
  16. package/dist/image.js +34 -0
  17. package/dist/index.d.ts +15 -0
  18. package/dist/index.js +33 -0
  19. package/dist/list-picker.d.ts +45 -0
  20. package/dist/list-picker.js +76 -0
  21. package/dist/module/choices.js +135 -0
  22. package/dist/module/colors/index.js +1 -0
  23. package/dist/module/colors/package.json +1 -0
  24. package/dist/module/date.js +145 -0
  25. package/dist/module/fields.js +225 -0
  26. package/dist/module/form/index.js +62 -0
  27. package/dist/module/form/package.json +1 -0
  28. package/dist/module/icons.js +16 -0
  29. package/dist/module/image.js +31 -0
  30. package/dist/module/index.js +13 -0
  31. package/dist/module/list-picker.js +70 -0
  32. package/dist/module/overlays.js +138 -0
  33. package/dist/module/package.json +1 -0
  34. package/dist/module/primitives.js +432 -0
  35. package/dist/module/process-graph.js +125 -0
  36. package/dist/module/rich-html/html-styles.js +55 -0
  37. package/dist/module/rich-html/image-renderers.js +141 -0
  38. package/dist/module/rich-html/index.js +54 -0
  39. package/dist/module/rich-html/normalize-inline-colors.js +93 -0
  40. package/dist/module/rich-html/package.json +1 -0
  41. package/dist/module/rich-html/rich-html.js +118 -0
  42. package/dist/module/search.js +88 -0
  43. package/dist/module/theme.js +62 -0
  44. package/dist/module/toast.js +30 -0
  45. package/dist/module/ui-modal.js +145 -0
  46. package/dist/overlays.d.ts +72 -0
  47. package/dist/overlays.js +146 -0
  48. package/dist/primitives.d.ts +157 -0
  49. package/dist/primitives.js +480 -0
  50. package/dist/process-graph.d.ts +33 -0
  51. package/dist/process-graph.js +161 -0
  52. package/dist/rich-html/html-styles.d.ts +23 -0
  53. package/dist/rich-html/html-styles.js +63 -0
  54. package/dist/rich-html/image-renderers.d.ts +12 -0
  55. package/dist/rich-html/image-renderers.js +144 -0
  56. package/dist/rich-html/index.d.ts +18 -0
  57. package/dist/rich-html/index.js +92 -0
  58. package/dist/rich-html/normalize-inline-colors.d.ts +8 -0
  59. package/dist/rich-html/normalize-inline-colors.js +99 -0
  60. package/dist/rich-html/rich-html.d.ts +7 -0
  61. package/dist/rich-html/rich-html.js +123 -0
  62. package/dist/search.d.ts +27 -0
  63. package/dist/search.js +91 -0
  64. package/dist/theme.d.ts +67 -0
  65. package/dist/theme.js +68 -0
  66. package/dist/toast.d.ts +3 -0
  67. package/dist/toast.js +69 -0
  68. package/dist/ui-modal.d.ts +17 -0
  69. package/dist/ui-modal.js +151 -0
  70. package/package.json +35 -4
@@ -0,0 +1,33 @@
1
+ import React from "react";
2
+ import { StyleProp, ViewStyle } from "react-native";
3
+ export type ProcessGraphTone = "success" | "warning" | "danger" | "accent" | "neutral";
4
+ export interface ProcessGraphPerson {
5
+ id: string;
6
+ label: string;
7
+ statusLabel?: string;
8
+ tone?: ProcessGraphTone;
9
+ }
10
+ export interface ProcessGraphNode {
11
+ id: string;
12
+ title: string;
13
+ statusLabel: string;
14
+ tone: ProcessGraphTone;
15
+ people: ProcessGraphPerson[];
16
+ }
17
+ export interface ProcessGraphToneColors {
18
+ dot: string;
19
+ background: string;
20
+ border: string;
21
+ text: string;
22
+ }
23
+ export interface ProcessGraphProps {
24
+ /** Already ordered by the app. Repeated stages retain distinct node IDs. */
25
+ nodes: ProcessGraphNode[];
26
+ startAdornment?: React.ReactNode;
27
+ connector?: React.ReactNode;
28
+ tones?: Partial<Record<ProcessGraphTone, ProcessGraphToneColors>>;
29
+ style?: StyleProp<ViewStyle>;
30
+ accessibilityLabel?: string;
31
+ }
32
+ /** Pure presentation: apps own loading, workflow permissions, statuses and people. */
33
+ export declare function ProcessGraph({ nodes, startAdornment, connector, tones, style, accessibilityLabel, }: ProcessGraphProps): React.JSX.Element;
@@ -0,0 +1,161 @@
1
+ "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
9
+ }) : (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ o[k2] = m[k];
12
+ }));
13
+ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
14
+ Object.defineProperty(o, "default", { enumerable: true, value: v });
15
+ }) : function(o, v) {
16
+ o["default"] = v;
17
+ });
18
+ var __importStar = (this && this.__importStar) || (function () {
19
+ var ownKeys = function(o) {
20
+ ownKeys = Object.getOwnPropertyNames || function (o) {
21
+ var ar = [];
22
+ for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
23
+ return ar;
24
+ };
25
+ return ownKeys(o);
26
+ };
27
+ return function (mod) {
28
+ if (mod && mod.__esModule) return mod;
29
+ var result = {};
30
+ if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
31
+ __setModuleDefault(result, mod);
32
+ return result;
33
+ };
34
+ })();
35
+ Object.defineProperty(exports, "__esModule", { value: true });
36
+ exports.ProcessGraph = ProcessGraph;
37
+ const jsx_runtime_1 = require("react/jsx-runtime");
38
+ const react_1 = require("react");
39
+ const react_native_1 = require("react-native");
40
+ const react_native_svg_1 = __importStar(require("react-native-svg"));
41
+ const primitives_1 = require("./primitives");
42
+ const theme_1 = require("./theme");
43
+ /** Pure presentation: apps own loading, workflow permissions, statuses and people. */
44
+ function ProcessGraph({ nodes, startAdornment, connector, tones, style, accessibilityLabel, }) {
45
+ const { colors: c, spacing: s, radius: r, typography: t } = (0, theme_1.useUITheme)();
46
+ const patternId = `process-dots-${(0, react_1.useId)().replace(/[^a-zA-Z0-9_-]/g, "")}`;
47
+ const palette = {
48
+ success: {
49
+ dot: c.success500,
50
+ background: c.success50,
51
+ border: c.success300,
52
+ text: c.success700,
53
+ },
54
+ warning: {
55
+ dot: c.warning500,
56
+ background: c.warning50,
57
+ border: c.warning300,
58
+ text: c.warning700,
59
+ },
60
+ danger: {
61
+ dot: c.danger500,
62
+ background: c.danger50,
63
+ border: c.danger300,
64
+ text: c.danger700,
65
+ },
66
+ accent: {
67
+ dot: c.secondary500,
68
+ background: c.secondary50,
69
+ border: c.secondary300,
70
+ text: c.secondary700,
71
+ },
72
+ neutral: {
73
+ dot: c.gray400,
74
+ background: c.gray50,
75
+ border: c.gray300,
76
+ text: c.content2,
77
+ },
78
+ ...tones,
79
+ };
80
+ return ((0, jsx_runtime_1.jsxs)(react_native_1.View, { accessibilityLabel: accessibilityLabel, style: [
81
+ {
82
+ backgroundColor: c.background,
83
+ padding: s.lg,
84
+ alignItems: "center",
85
+ overflow: "hidden",
86
+ },
87
+ style,
88
+ ], children: [(0, jsx_runtime_1.jsx)(react_native_1.View, { pointerEvents: "none", accessible: false, style: react_native_1.StyleSheet.absoluteFill, children: (0, jsx_runtime_1.jsxs)(react_native_svg_1.default, { width: "100%", height: "100%", children: [(0, jsx_runtime_1.jsx)(react_native_svg_1.Defs, { children: (0, jsx_runtime_1.jsx)(react_native_svg_1.Pattern, { id: patternId, width: s.xl, height: s.xl, patternUnits: "userSpaceOnUse", children: (0, jsx_runtime_1.jsx)(react_native_svg_1.Circle, { cx: s.xl / 2, cy: s.xl / 2, r: 0.8, fill: c.content4 }) }) }), (0, jsx_runtime_1.jsx)(react_native_svg_1.Rect, { width: "100%", height: "100%", fill: `url(#${patternId})` })] }) }), startAdornment, nodes.map((node) => {
89
+ const colors = palette[node.tone];
90
+ return ((0, jsx_runtime_1.jsxs)(react_native_1.View, { style: { width: "100%", maxWidth: 448, alignItems: "center" }, children: [(0, jsx_runtime_1.jsx)(react_native_1.View, { accessible: false, style: {
91
+ minHeight: s.xxl + s.lg,
92
+ justifyContent: "center",
93
+ alignItems: "center",
94
+ }, children: connector ?? ((0, jsx_runtime_1.jsx)(react_native_1.View, { style: {
95
+ width: 1,
96
+ height: s.xxl,
97
+ backgroundColor: palette.success.dot,
98
+ } })) }), (0, jsx_runtime_1.jsxs)(react_native_1.View, { style: {
99
+ width: "100%",
100
+ minHeight: 110,
101
+ borderWidth: 1,
102
+ borderColor: colors.border,
103
+ borderRadius: r.lg + s.xs,
104
+ padding: s.lg,
105
+ backgroundColor: colors.background,
106
+ gap: s.md,
107
+ }, children: [(0, jsx_runtime_1.jsxs)(react_native_1.View, { style: {
108
+ flexDirection: "row",
109
+ alignItems: "flex-start",
110
+ gap: s.sm,
111
+ }, children: [(0, jsx_runtime_1.jsxs)(react_native_1.View, { style: {
112
+ flexDirection: "row",
113
+ flex: 1,
114
+ minWidth: 0,
115
+ alignItems: "center",
116
+ gap: s.sm,
117
+ }, children: [(0, jsx_runtime_1.jsx)(react_native_1.View, { style: {
118
+ width: 9,
119
+ height: 9,
120
+ borderRadius: r.full,
121
+ backgroundColor: colors.dot,
122
+ } }), (0, jsx_runtime_1.jsx)(primitives_1.UIText, { weight: "600", style: {
123
+ flex: 1,
124
+ fontSize: t.body,
125
+ lineHeight: t.body * 1.45,
126
+ }, children: node.title })] }), (0, jsx_runtime_1.jsx)(primitives_1.UIText, { style: {
127
+ maxWidth: "43%",
128
+ fontSize: t.label,
129
+ lineHeight: t.body * 1.45,
130
+ color: c.content2,
131
+ textAlign: "right",
132
+ }, children: node.statusLabel })] }), (0, jsx_runtime_1.jsx)(react_native_1.View, { style: { gap: s.xs }, children: node.people.map((person) => {
133
+ const personColors = palette[person.tone ?? node.tone];
134
+ return ((0, jsx_runtime_1.jsxs)(react_native_1.View, { style: {
135
+ flexDirection: "row",
136
+ alignItems: "center",
137
+ gap: s.sm,
138
+ backgroundColor: c.background,
139
+ borderRadius: r.lg,
140
+ paddingHorizontal: s.md,
141
+ paddingVertical: s.sm,
142
+ minHeight: 38,
143
+ }, children: [(0, jsx_runtime_1.jsx)(primitives_1.UIText, { selectable: true, numberOfLines: 1, accessibilityLabel: person.label, style: {
144
+ flex: 1,
145
+ minWidth: 0,
146
+ fontSize: t.body,
147
+ lineHeight: t.body * 1.45,
148
+ }, children: person.label }), !!person.statusLabel && ((0, jsx_runtime_1.jsx)(react_native_1.View, { style: {
149
+ maxWidth: "47%",
150
+ borderRadius: r.full,
151
+ paddingHorizontal: s.sm,
152
+ paddingVertical: s.xs / 2,
153
+ backgroundColor: personColors.background,
154
+ }, children: (0, jsx_runtime_1.jsx)(primitives_1.UIText, { weight: "500", style: {
155
+ fontSize: t.label,
156
+ lineHeight: t.label * 1.4,
157
+ color: personColors.text,
158
+ }, children: person.statusLabel }) }))] }, person.id));
159
+ }) })] })] }, node.id));
160
+ })] }));
161
+ }
@@ -0,0 +1,23 @@
1
+ import type { MixedStyleDeclaration, MixedStyleRecord } from "react-native-render-html";
2
+ export declare const scale: (size: number) => number;
3
+ export declare function safeLineHeight(lineHeight: number): number;
4
+ export declare function richHtmlTextSize(size: number): {
5
+ fontSize: number;
6
+ lineHeight: number;
7
+ };
8
+ export declare function mergeRichHtmlStyle(defaults: MixedStyleDeclaration, override?: MixedStyleDeclaration): MixedStyleDeclaration;
9
+ export declare function mergeRichHtmlStyleRecord(defaults: MixedStyleRecord, overrides?: MixedStyleRecord): MixedStyleRecord;
10
+ export declare const quillClassesStyles: {
11
+ "ql-size-small": {
12
+ fontSize: number;
13
+ lineHeight: number;
14
+ };
15
+ "ql-size-large": {
16
+ fontSize: number;
17
+ lineHeight: number;
18
+ };
19
+ "ql-size-huge": {
20
+ fontSize: number;
21
+ lineHeight: number;
22
+ };
23
+ };
@@ -0,0 +1,63 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.quillClassesStyles = exports.scale = void 0;
4
+ exports.safeLineHeight = safeLineHeight;
5
+ exports.richHtmlTextSize = richHtmlTextSize;
6
+ exports.mergeRichHtmlStyle = mergeRichHtmlStyle;
7
+ exports.mergeRichHtmlStyleRecord = mergeRichHtmlStyleRecord;
8
+ const react_native_1 = require("react-native");
9
+ const BASE_WIDTH = 375;
10
+ const BASE_HEIGHT = 812;
11
+ const { width, height } = react_native_1.Dimensions.get("window");
12
+ const scale = (size) => {
13
+ const scaleFactor = Math.min(width / BASE_WIDTH, height / BASE_HEIGHT);
14
+ // return Math.round(size * scaleFactor); // if not considering pixelRatio
15
+ const newSize = size * scaleFactor;
16
+ return Math.round(react_native_1.PixelRatio.roundToNearestPixel(newSize));
17
+ };
18
+ exports.scale = scale;
19
+ function safeLineHeight(lineHeight) {
20
+ if (react_native_1.Platform.OS !== "ios" || lineHeight === 0)
21
+ return lineHeight;
22
+ // Give Yoga enough rounding room to keep the last line visible on iOS.
23
+ // https://github.com/react/react-native/issues/58970
24
+ const ratio = react_native_1.PixelRatio.get();
25
+ return Math.ceil(lineHeight * ratio - 1e-6) / ratio + 0.001;
26
+ }
27
+ function richHtmlTextSize(size) {
28
+ const fontSize = (0, exports.scale)(size);
29
+ return { fontSize, lineHeight: safeLineHeight(fontSize * 1.5) };
30
+ }
31
+ function mergeRichHtmlStyle(defaults, override) {
32
+ if (!override)
33
+ return defaults;
34
+ const style = { ...defaults, ...override };
35
+ const { fontSize, lineHeight } = override;
36
+ if (typeof lineHeight === "number" && Number.isFinite(lineHeight)) {
37
+ style.lineHeight = safeLineHeight(lineHeight);
38
+ }
39
+ else if (lineHeight === undefined &&
40
+ typeof fontSize === "number" &&
41
+ Number.isFinite(fontSize) &&
42
+ fontSize > 0) {
43
+ style.lineHeight = safeLineHeight(fontSize * 1.5);
44
+ }
45
+ return style;
46
+ }
47
+ function mergeRichHtmlStyleRecord(defaults, overrides) {
48
+ if (!overrides)
49
+ return defaults;
50
+ const styles = { ...defaults };
51
+ for (const name of Object.keys(overrides)) {
52
+ styles[name] = mergeRichHtmlStyle(styles[name] ?? {}, overrides[name]);
53
+ }
54
+ return styles;
55
+ }
56
+ // Quill stores font sizes as class names instead of inline font-size values.
57
+ // react-native-render-html does not include Quill's stylesheet, so these
58
+ // classes must be translated to native text styles explicitly.
59
+ exports.quillClassesStyles = {
60
+ "ql-size-small": richHtmlTextSize(14 * 0.75),
61
+ "ql-size-large": richHtmlTextSize(14 * 1.5),
62
+ "ql-size-huge": richHtmlTextSize(14 * 2.5),
63
+ };
@@ -0,0 +1,12 @@
1
+ import { type ImageWithSkeletonSource } from "../image";
2
+ export interface RichHtmlImageRendererOptions {
3
+ fallbackSource?: ImageWithSkeletonSource;
4
+ onImagePress?: (uri: string) => void;
5
+ imageAccessibilityLabel?: string;
6
+ animateSkeleton?: boolean;
7
+ }
8
+ /** Opt in to skeletons, image-only tables and tappable images in rich HTML. */
9
+ export declare function createRichHtmlImageRenderers(options?: RichHtmlImageRendererOptions): {
10
+ img: import("react").FunctionComponent<import("react-native-render-html").CustomRendererProps<import("react-native-render-html").TBlock>>;
11
+ table: import("react").FunctionComponent<import("react-native-render-html").CustomRendererProps<import("react-native-render-html").TBlock>>;
12
+ };
@@ -0,0 +1,144 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.createRichHtmlImageRenderers = createRichHtmlImageRenderers;
4
+ const jsx_runtime_1 = require("react/jsx-runtime");
5
+ const react_1 = require("react");
6
+ const react_native_1 = require("react-native");
7
+ const react_native_render_html_1 = require("react-native-render-html");
8
+ const image_1 = require("../image");
9
+ const html_styles_1 = require("./html-styles");
10
+ const DEFAULT_ASPECT_RATIO = 16 / 9;
11
+ const PHOTO_GAP = (0, html_styles_1.scale)(6);
12
+ const getImageUri = (value) => {
13
+ const uri = typeof value === "string" ? value.trim() : "";
14
+ return /^(https?:\/\/|data:image\/)/i.test(uri) ? uri : undefined;
15
+ };
16
+ function readDimensions(width, height) {
17
+ const w = Number(width);
18
+ const h = Number(height);
19
+ if (Number.isFinite(w) && Number.isFinite(h) && w > 0 && h > 0) {
20
+ return { width: w, height: h };
21
+ }
22
+ }
23
+ const imageContentFit = {
24
+ stretch: "fill",
25
+ center: "none",
26
+ contain: "contain",
27
+ };
28
+ function InlineImage({ options, image, }) {
29
+ const [naturalSize, setNaturalSize] = (0, react_1.useState)();
30
+ const [failed, setFailed] = (0, react_1.useState)(false);
31
+ const width = image.contentWidth || (0, html_styles_1.scale)(200);
32
+ const htmlSize = readDimensions(image.width, image.height);
33
+ // Start the request with a reserved frame and read missing dimensions from
34
+ // Expo Image's load event instead of requesting the same image via getSize.
35
+ const state = (0, react_native_render_html_1.useIMGElementStateWithCache)({
36
+ ...image,
37
+ cachedNaturalDimensions: naturalSize ??
38
+ htmlSize ?? {
39
+ width,
40
+ height: width / DEFAULT_ASPECT_RATIO,
41
+ },
42
+ });
43
+ const uri = getImageUri(state.source.uri);
44
+ const onImagePress = options.onImagePress;
45
+ const canOpenImage = Boolean(uri && !failed && onImagePress);
46
+ const resizeMode = state.type === "success" ? state.imageStyle.resizeMode : undefined;
47
+ const contentFit = (resizeMode && imageContentFit[resizeMode]) || "cover";
48
+ return ((0, jsx_runtime_1.jsx)(react_native_render_html_1.IMGElementContainer, { ...image.containerProps, testID: image.testID, style: state.containerStyle, accessibilityRole: canOpenImage ? "button" : undefined, accessibilityLabel: image.alt || options.imageAccessibilityLabel, onPress: uri && !failed && onImagePress ? () => onImagePress(uri) : undefined, children: (0, jsx_runtime_1.jsx)(image_1.ImageWithSkeleton, { source: state.source.uri ? state.source : undefined, style: state.dimensions, contentFit: contentFit, testID: "article-image", fallbackSource: options.fallbackSource, waitForDisplay: true, skeletonProps: {
49
+ animated: options.animateSkeleton,
50
+ pointerEvents: "none",
51
+ }, onLoad: ({ source }) => {
52
+ if (!htmlSize && !failed) {
53
+ setNaturalSize(readDimensions(source.width, source.height));
54
+ }
55
+ }, onError: () => setFailed(true) }) }));
56
+ }
57
+ const significantChildren = (element) => element.children.filter((child) => child.type !== "comment" && !((0, react_native_render_html_1.isDomText)(child) && !child.data.trim()));
58
+ function findCellImage(node) {
59
+ if (!(0, react_native_render_html_1.isDomElement)(node))
60
+ return;
61
+ if (node.name === "img" && node.attribs.src?.trim())
62
+ return node;
63
+ if (!["td", "p", "span", "div"].includes(node.name))
64
+ return;
65
+ const children = significantChildren(node);
66
+ if (children.length === 1)
67
+ return findCellImage(children[0]);
68
+ }
69
+ function getPhotoRows(table) {
70
+ const rows = significantChildren(table).flatMap((node) => (0, react_native_render_html_1.isDomElement)(node) && ["thead", "tbody", "tfoot"].includes(node.name)
71
+ ? significantChildren(node)
72
+ : [node]);
73
+ const photoRows = [];
74
+ let columnCount;
75
+ for (const row of rows) {
76
+ if (!(0, react_native_render_html_1.isDomElement)(row) || row.name !== "tr")
77
+ return;
78
+ const photos = [];
79
+ let rowColumns = 0;
80
+ for (const cell of significantChildren(row)) {
81
+ if (!(0, react_native_render_html_1.isDomElement)(cell) ||
82
+ cell.name !== "td" ||
83
+ Number(cell.attribs.rowspan ?? 1) !== 1) {
84
+ return;
85
+ }
86
+ const columnSpan = Number(cell.attribs.colspan ?? 1);
87
+ if (!Number.isSafeInteger(columnSpan) || columnSpan < 1)
88
+ return;
89
+ const photo = findCellImage(cell);
90
+ if (!photo)
91
+ return;
92
+ photos.push({ image: photo, columnSpan });
93
+ rowColumns += columnSpan;
94
+ }
95
+ if (!photos.length ||
96
+ (columnCount !== undefined && columnCount !== rowColumns))
97
+ return;
98
+ columnCount = rowColumns;
99
+ photoRows.push(photos);
100
+ }
101
+ if (photoRows.length)
102
+ return photoRows;
103
+ }
104
+ function GridImage({ image, columnSpan, options, }) {
105
+ const { src, alt, width, height } = image.attribs;
106
+ const uri = getImageUri((0, react_native_render_html_1.useNormalizedUrl)(src));
107
+ const [failed, setFailed] = (0, react_1.useState)(false);
108
+ const size = readDimensions(width, height);
109
+ const onImagePress = options.onImagePress;
110
+ // A spanning cell includes the gutters between the columns it covers.
111
+ const cellStyle = [
112
+ styles.cell,
113
+ { flexGrow: columnSpan, flexBasis: PHOTO_GAP * (columnSpan - 1) },
114
+ ];
115
+ const photo = ((0, jsx_runtime_1.jsx)(image_1.ImageWithSkeleton, { source: uri, style: {
116
+ aspectRatio: size ? size.width / size.height : DEFAULT_ASPECT_RATIO,
117
+ }, contentFit: "contain", testID: "article-image", fallbackSource: options.fallbackSource, waitForDisplay: true, skeletonProps: {
118
+ animated: options.animateSkeleton,
119
+ pointerEvents: "none",
120
+ }, onError: () => setFailed(true), accessibilityLabel: onImagePress ? undefined : alt || options.imageAccessibilityLabel }));
121
+ if (!uri || !onImagePress)
122
+ return (0, jsx_runtime_1.jsx)(react_native_1.View, { style: cellStyle, children: photo });
123
+ return ((0, jsx_runtime_1.jsx)(react_native_1.TouchableOpacity, { style: cellStyle, disabled: failed, onPress: () => onImagePress(uri), accessibilityRole: "button", accessibilityLabel: alt || options.imageAccessibilityLabel, activeOpacity: 0.85, children: photo }));
124
+ }
125
+ /** Opt in to skeletons, image-only tables and tappable images in rich HTML. */
126
+ function createRichHtmlImageRenderers(options = {}) {
127
+ const img = function ArticleImageRenderer(props) {
128
+ const { rendererProps } = (0, react_native_render_html_1.useInternalRenderer)("img", props);
129
+ return ((0, jsx_runtime_1.jsx)(InlineImage, { image: rendererProps, options: options }, rendererProps.source.uri));
130
+ };
131
+ const table = function ArticleTableRenderer(props) {
132
+ const { tnode, TDefaultRenderer } = props;
133
+ const rows = tnode.domNode && getPhotoRows(tnode.domNode);
134
+ if (!rows)
135
+ return (0, jsx_runtime_1.jsx)(TDefaultRenderer, { ...props });
136
+ return ((0, jsx_runtime_1.jsx)(react_native_1.View, { style: styles.grid, children: rows.map((row, rowIndex) => ((0, jsx_runtime_1.jsx)(react_native_1.View, { style: styles.row, testID: "article-photo-row", children: row.map(({ image, columnSpan }, columnIndex) => ((0, jsx_runtime_1.jsx)(GridImage, { image: image, columnSpan: columnSpan, options: options }, `${columnIndex}:${image.attribs.src}`))) }, rowIndex))) }));
137
+ };
138
+ return { img, table };
139
+ }
140
+ const styles = react_native_1.StyleSheet.create({
141
+ grid: { gap: PHOTO_GAP, marginBottom: PHOTO_GAP },
142
+ row: { flexDirection: "row", alignItems: "flex-start", gap: PHOTO_GAP },
143
+ cell: { flex: 1, minWidth: 0 },
144
+ });
@@ -0,0 +1,18 @@
1
+ import React from "react";
2
+ import { type RenderHTMLProps } from "react-native-render-html";
3
+ export { createRichHtmlImageRenderers, type RichHtmlImageRendererOptions, } from "./image-renderers";
4
+ interface RichHtmlColors {
5
+ textColor: string;
6
+ linkColor: string;
7
+ }
8
+ type RichHtmlStyleOverrides = Pick<RenderHTMLProps, "baseStyle" | "tagsStyles" | "classesStyles">;
9
+ type RichHtmlConfig = RichHtmlColors & RichHtmlStyleOverrides;
10
+ export interface RichHtmlContentProps extends RichHtmlConfig {
11
+ content?: string | null;
12
+ contentWidth: number;
13
+ imageUrls?: readonly string[];
14
+ renderers?: RenderHTMLProps["renderers"];
15
+ }
16
+ /** Reuse one render engine and config for a list of articles. */
17
+ export declare const RichHtmlProvider: ({ children, textColor, linkColor, baseStyle, tagsStyles, classesStyles, }: React.PropsWithChildren<RichHtmlConfig>) => React.JSX.Element;
18
+ export declare const RichHtmlContent: React.NamedExoticComponent<RichHtmlContentProps>;
@@ -0,0 +1,92 @@
1
+ "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
9
+ }) : (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ o[k2] = m[k];
12
+ }));
13
+ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
14
+ Object.defineProperty(o, "default", { enumerable: true, value: v });
15
+ }) : function(o, v) {
16
+ o["default"] = v;
17
+ });
18
+ var __importStar = (this && this.__importStar) || (function () {
19
+ var ownKeys = function(o) {
20
+ ownKeys = Object.getOwnPropertyNames || function (o) {
21
+ var ar = [];
22
+ for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
23
+ return ar;
24
+ };
25
+ return ownKeys(o);
26
+ };
27
+ return function (mod) {
28
+ if (mod && mod.__esModule) return mod;
29
+ var result = {};
30
+ if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
31
+ __setModuleDefault(result, mod);
32
+ return result;
33
+ };
34
+ })();
35
+ Object.defineProperty(exports, "__esModule", { value: true });
36
+ exports.RichHtmlContent = exports.RichHtmlProvider = exports.createRichHtmlImageRenderers = void 0;
37
+ const jsx_runtime_1 = require("react/jsx-runtime");
38
+ const react_1 = __importStar(require("react"));
39
+ const react_native_render_html_1 = __importStar(require("react-native-render-html"));
40
+ const rich_html_1 = require("./rich-html");
41
+ const html_styles_1 = require("./html-styles");
42
+ var image_renderers_1 = require("./image-renderers");
43
+ Object.defineProperty(exports, "createRichHtmlImageRenderers", { enumerable: true, get: function () { return image_renderers_1.createRichHtmlImageRenderers; } });
44
+ const defaultTextProps = { allowFontScaling: false };
45
+ const renderersProps = { img: { enableExperimentalPercentWidth: true } };
46
+ const SharedHtmlContext = react_1.default.createContext(null);
47
+ function useRichHtmlStyles({ textColor, linkColor, baseStyle, tagsStyles, classesStyles, }, inherited) {
48
+ return (0, react_1.useMemo)(() => {
49
+ const defaultBaseStyle = {
50
+ color: textColor,
51
+ ...(0, html_styles_1.richHtmlTextSize)(14),
52
+ textAlign: "left",
53
+ };
54
+ const defaultTagsStyles = {
55
+ ...rich_html_1.richHtmlTagsStyles,
56
+ a: { color: linkColor, textDecorationLine: "underline" },
57
+ };
58
+ return {
59
+ baseStyle: (0, html_styles_1.mergeRichHtmlStyle)((0, html_styles_1.mergeRichHtmlStyle)(defaultBaseStyle, inherited?.baseStyle), baseStyle),
60
+ tagsStyles: (0, html_styles_1.mergeRichHtmlStyleRecord)((0, html_styles_1.mergeRichHtmlStyleRecord)(defaultTagsStyles, inherited?.tagsStyles), tagsStyles),
61
+ classesStyles: (0, html_styles_1.mergeRichHtmlStyleRecord)((0, html_styles_1.mergeRichHtmlStyleRecord)(rich_html_1.richHtmlClassesStyles, inherited?.classesStyles), classesStyles),
62
+ };
63
+ }, [textColor, linkColor, baseStyle, tagsStyles, classesStyles, inherited]);
64
+ }
65
+ /** Reuse one render engine and config for a list of articles. */
66
+ const RichHtmlProvider = ({ children, textColor, linkColor, baseStyle, tagsStyles, classesStyles, }) => {
67
+ const config = (0, react_1.useMemo)(() => ({ textColor, linkColor, baseStyle, tagsStyles, classesStyles }), [textColor, linkColor, baseStyle, tagsStyles, classesStyles]);
68
+ const styles = useRichHtmlStyles(config);
69
+ return ((0, jsx_runtime_1.jsx)(react_native_render_html_1.TRenderEngineProvider, { enableCSSInlineProcessing: true, ...styles, domVisitors: rich_html_1.richHtmlDomVisitors, children: (0, jsx_runtime_1.jsx)(react_native_render_html_1.RenderHTMLConfigProvider, { defaultTextProps: defaultTextProps, renderersProps: renderersProps, enableExperimentalGhostLinesPrevention: true, enableExperimentalBRCollapsing: true, children: (0, jsx_runtime_1.jsx)(SharedHtmlContext.Provider, { value: config, children: children }) }) }));
70
+ };
71
+ exports.RichHtmlProvider = RichHtmlProvider;
72
+ const StandaloneRichHtml = ({ source, contentWidth, renderers, inherited, ...config }) => {
73
+ const styles = useRichHtmlStyles(config, inherited);
74
+ return ((0, jsx_runtime_1.jsx)(react_native_render_html_1.default, { contentWidth: contentWidth, source: source, enableCSSInlineProcessing: true, ...styles, domVisitors: rich_html_1.richHtmlDomVisitors, defaultTextProps: defaultTextProps, enableExperimentalGhostLinesPrevention: true, enableExperimentalBRCollapsing: true, renderers: renderers, renderersProps: renderersProps }));
75
+ };
76
+ exports.RichHtmlContent = react_1.default.memo(function RichHtmlContent({ content, contentWidth, imageUrls, renderers, textColor, linkColor, baseStyle, tagsStyles, classesStyles, }) {
77
+ const sharedConfig = react_1.default.use(SharedHtmlContext);
78
+ const source = (0, react_1.useMemo)(() => ({ html: (0, rich_html_1.buildRichHtml)(content, imageUrls) }), [content, imageUrls]);
79
+ if (!source.html)
80
+ return null;
81
+ const width = Math.max(0, contentWidth);
82
+ // A document with its own rendering options uses a separate engine.
83
+ if (!renderers &&
84
+ !baseStyle &&
85
+ !tagsStyles &&
86
+ !classesStyles &&
87
+ sharedConfig?.textColor === textColor &&
88
+ sharedConfig.linkColor === linkColor) {
89
+ return (0, jsx_runtime_1.jsx)(react_native_render_html_1.RenderHTMLSource, { source: source, contentWidth: width });
90
+ }
91
+ return ((0, jsx_runtime_1.jsx)(StandaloneRichHtml, { contentWidth: width, source: source, renderers: renderers, textColor: textColor, linkColor: linkColor, baseStyle: baseStyle, tagsStyles: tagsStyles, classesStyles: classesStyles, inherited: sharedConfig ?? undefined }));
92
+ });
@@ -0,0 +1,8 @@
1
+ export declare const convertInlineTagsToHtml: (html: string) => string;
2
+ /**
3
+ * Converts text entered in a multiline input into safe HTML for RenderHTML.
4
+ * HTML collapses newline characters, so each newline must be represented by a
5
+ * line-break element to retain the author's formatting after it is stored.
6
+ */
7
+ export declare const textToHtml: (text?: string | null) => string;
8
+ export declare const normalizeInlineColors: (html?: string | null) => string;