@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,99 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.normalizeInlineColors = exports.textToHtml = exports.convertInlineTagsToHtml = void 0;
4
+ const convertInlineTagsToHtml = (html) => {
5
+ if (!html || typeof html !== "string") {
6
+ return "";
7
+ }
8
+ let result = html;
9
+ // 1. Convert <text> to <span> (plain text wrapper)
10
+ result = result.replace(/<text>([^<]*)<\/text>/gi, "<span>$1</span>");
11
+ // 2. Convert <bold> to <strong>
12
+ result = result.replace(/<bold>([^<]*)<\/bold>/gi, "<strong>$1</strong>");
13
+ // 3. Convert <italic> to <i>
14
+ result = result.replace(/<italic>([^<]*)<\/italic>/gi, "<i>$1</i>");
15
+ // 4. Convert <underline> to <u>
16
+ result = result.replace(/<underline>([^<]*)<\/underline>/gi, "<u>$1</u>");
17
+ // 5. Convert <strike> to <s>
18
+ result = result.replace(/<strike>([^<]*)<\/strike>/gi, "<s>$1</s>");
19
+ // 6. Convert <highlightColor backgroundColor="..."> to span with background-color
20
+ result = result.replace(/<highlightColor\s+backgroundColor="([^"]+)">([^<]*)<\/highlightColor>/gi, (_, bgColor, content) => `<span style="background-color: ${bgColor};">${content}</span>`);
21
+ // Map custom tags tới inline style
22
+ const tagStyleMap = {
23
+ // Single style (no color)
24
+ italic: () => `font-style: italic;`,
25
+ // Single style + color
26
+ colorSpan: (color) => `color: ${color};`,
27
+ boldColor: (color) => `font-weight: bold; color: ${color};`,
28
+ italicColor: (color) => `font-style: italic; color: ${color};`,
29
+ underlineColor: (color) => `text-decoration: underline; color: ${color};`,
30
+ strikeColor: (color) => `text-decoration: line-through; color: ${color};`,
31
+ // Combo 2 styles (không màu)
32
+ boldItalic: () => `font-weight: bold; font-style: italic;`,
33
+ boldUnderline: () => `font-weight: bold; text-decoration: underline;`,
34
+ italicUnderline: () => `font-style: italic; text-decoration: underline;`,
35
+ // Combo 2 styles + color
36
+ boldItalicColor: (color) => `font-weight: bold; font-style: italic; color: ${color};`,
37
+ boldUnderlineColor: (color) => `font-weight: bold; text-decoration: underline; color: ${color};`,
38
+ italicUnderlineColor: (color) => `font-style: italic; text-decoration: underline; color: ${color};`,
39
+ // Combo 3 styles (không màu)
40
+ boldItalicUnderline: () => `font-weight: bold; font-style: italic; text-decoration: underline;`,
41
+ // Combo 3 styles + color
42
+ boldItalicUnderlineColor: (color) => `font-weight: bold; font-style: italic; text-decoration: underline; color: ${color};`,
43
+ };
44
+ // Process each custom tag
45
+ Object.keys(tagStyleMap).forEach((tagName) => {
46
+ // Match tags with color attribute: <tagName color="...">content</tagName>
47
+ const regexWithColor = new RegExp(`<${tagName}\\s+color="([^"]+)">([^<]*)</${tagName}>`, "gi");
48
+ result = result.replace(regexWithColor, (_, color, content) => {
49
+ const style = tagStyleMap[tagName](color);
50
+ return `<span style="${style}">${content}</span>`;
51
+ });
52
+ // Match tags without color attribute: <tagName>content</tagName>
53
+ const regexWithoutColor = new RegExp(`<${tagName}>([^<]*)</${tagName}>`, "gi");
54
+ result = result.replace(regexWithoutColor, (_, content) => {
55
+ const style = tagStyleMap[tagName]();
56
+ return style ? `<span style="${style}">${content}</span>` : content;
57
+ });
58
+ });
59
+ return result;
60
+ };
61
+ exports.convertInlineTagsToHtml = convertInlineTagsToHtml;
62
+ const clamp255 = (n) => Math.max(0, Math.min(255, n));
63
+ const rgbToHex = (r, g, b) => {
64
+ const toHex = (v) => clamp255(v).toString(16).padStart(2, "0");
65
+ return `#${toHex(r)}${toHex(g)}${toHex(b)}`;
66
+ };
67
+ /**
68
+ * Converts text entered in a multiline input into safe HTML for RenderHTML.
69
+ * HTML collapses newline characters, so each newline must be represented by a
70
+ * line-break element to retain the author's formatting after it is stored.
71
+ */
72
+ const textToHtml = (text) => {
73
+ if (!text || typeof text !== "string") {
74
+ return "";
75
+ }
76
+ return text
77
+ .replace(/&/g, "&amp;")
78
+ .replace(/</g, "&lt;")
79
+ .replace(/>/g, "&gt;")
80
+ .replace(/\r\n?|\n/g, "<br />");
81
+ };
82
+ exports.textToHtml = textToHtml;
83
+ const normalizeInlineColors = (html) => {
84
+ if (!html || typeof html !== "string") {
85
+ return "";
86
+ }
87
+ // Step 1: Convert custom inline tags to HTML span tags with inline styles
88
+ let normalized = (0, exports.convertInlineTagsToHtml)(html);
89
+ // Step 2: Convert rgb() colors to hex format
90
+ normalized = normalized.replace(/color\s*:\s*rgb\(\s*(\d{1,3})\s*,\s*(\d{1,3})\s*,\s*(\d{1,3})\s*\)\s*;?/gi, (_, r, g, b) => `color: ${rgbToHex(Number(r), Number(g), Number(b))};`);
91
+ // Step 3: Convert rgb() background-colors to hex format
92
+ normalized = normalized.replace(/background-color\s*:\s*rgb\(\s*(\d{1,3})\s*,\s*(\d{1,3})\s*,\s*(\d{1,3})\s*\)\s*;?/gi, (_, r, g, b) => `background-color: ${rgbToHex(Number(r), Number(g), Number(b))};`);
93
+ // Older posts can be stored as plain text. Preserve their line breaks when
94
+ // rendering while leaving rich HTML content unchanged.
95
+ return /<\/?[a-z][^>]*>/i.test(normalized)
96
+ ? normalized
97
+ : (0, exports.textToHtml)(normalized);
98
+ };
99
+ exports.normalizeInlineColors = normalizeInlineColors;
@@ -0,0 +1,7 @@
1
+ import { type DomVisitorCallbacks, type MixedStyleRecord } from "react-native-render-html";
2
+ /** Shared display-only cleanup; never decode escaped HTML into executable markup. */
3
+ export declare const normalizeRichHtml: (content?: string | null) => string;
4
+ export declare const buildRichHtml: (content?: string | null, imageUrls?: readonly string[]) => string;
5
+ export declare const richHtmlDomVisitors: DomVisitorCallbacks;
6
+ export declare const richHtmlClassesStyles: MixedStyleRecord;
7
+ export declare const richHtmlTagsStyles: MixedStyleRecord;
@@ -0,0 +1,123 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.richHtmlTagsStyles = exports.richHtmlClassesStyles = exports.richHtmlDomVisitors = exports.buildRichHtml = exports.normalizeRichHtml = void 0;
4
+ const react_native_render_html_1 = require("react-native-render-html");
5
+ const normalize_inline_colors_1 = require("./normalize-inline-colors");
6
+ const html_styles_1 = require("./html-styles");
7
+ const addLineHeightForInlineFontSize = (html) => html.replace(/<[^>]+>/g, (tag) => tag.replace(/\bstyle\s*=\s*(['"])([\s\S]*?)\1/gi, (attribute, quote, style) => {
8
+ if (/line-height\s*:/i.test(style))
9
+ return attribute;
10
+ const match = style.match(/font-size\s*:\s*(\d*\.?\d+)\s*(px|em|rem)\b/i);
11
+ if (!match)
12
+ return attribute;
13
+ const size = Number(match[1]);
14
+ const fontSize = match[2].toLowerCase() === "px" ? size : size * (0, html_styles_1.scale)(14);
15
+ const lineHeight = (0, html_styles_1.safeLineHeight)(Math.round(fontSize * 1.5 * 100) / 100);
16
+ const separator = /;\s*$/.test(style) ? " " : "; ";
17
+ // Preserve an authored line-height; otherwise prevent large inline text
18
+ // from inheriting the smaller body line-height and being clipped.
19
+ return `style=${quote}${style}${separator}line-height: ${lineHeight}px${quote}`;
20
+ }));
21
+ /** Shared display-only cleanup; never decode escaped HTML into executable markup. */
22
+ const normalizeRichHtml = (content) => {
23
+ // Some legacy responses still escape attribute quotes after JSON decoding.
24
+ const html = typeof content === "string"
25
+ ? content.replace(/<[^>]+>/g, (tag) => tag.replace(/\\+"/g, '"'))
26
+ : "";
27
+ return addLineHeightForInlineFontSize((0, normalize_inline_colors_1.normalizeInlineColors)(html));
28
+ };
29
+ exports.normalizeRichHtml = normalizeRichHtml;
30
+ const escapeAttribute = (value) => value
31
+ .replace(/&/g, "&amp;")
32
+ .replace(/"/g, "&quot;")
33
+ .replace(/</g, "&lt;")
34
+ .replace(/>/g, "&gt;");
35
+ const buildRichHtml = (content, imageUrls = []) => {
36
+ // Normalize the body BEFORE appending images: a plain-text body still needs
37
+ // escaping and explicit line breaks. Do not normalize it twice.
38
+ const body = (0, exports.normalizeRichHtml)(content);
39
+ const images = imageUrls
40
+ .filter((url) => typeof url === "string" && Boolean(url))
41
+ .map((url) => `<img src="${escapeAttribute(url)}" style="width: 100%; height: auto;" />`)
42
+ .join("");
43
+ return body + images;
44
+ };
45
+ exports.buildRichHtml = buildRichHtml;
46
+ const hasChildren = (node) => "children" in node;
47
+ const flowTags = /^(article|aside|section|div|p|h[1-6]|blockquote|figure|figcaption|span|li)$/;
48
+ const fixedFlowStyles = /(^|;)\s*(?:(?:min-|max-)?(?:width|height)|overflow(?:-[xy])?|(?:-webkit-)?line-clamp|text-overflow)\s*:[^;]*/gi;
49
+ const noWrapStyles = /(^|;)\s*white-space\s*:\s*nowrap(?:\s*!important)?(?=\s*(?:;|$))/gi;
50
+ const mediaSpacingStyles = /(^|;)\s*(?:margin|padding)(?:-(?:block(?:-start|-end)?|top|bottom))?\s*:[^;]*/gi;
51
+ const paragraphSpacingStyles = /(^|;)\s*margin(?:-(?:block(?:-start|-end)?|top|bottom))?\s*:[^;]*/gi;
52
+ exports.richHtmlDomVisitors = {
53
+ onDocument(document) {
54
+ const visit = (node, preserveWhitespace = false) => {
55
+ const tagName = (0, react_native_render_html_1.isDomElement)(node) ? node.name : undefined;
56
+ const preserve = preserveWhitespace || tagName === "pre" || tagName === "code";
57
+ if ((0, react_native_render_html_1.isDomElement)(node) && node.attribs.style) {
58
+ // Native justification stretches glyphs on narrow screens. Keep other
59
+ // authored alignment (center/right), colors and font sizes unchanged.
60
+ node.attribs.style = node.attribs.style.replace(/(^|;)\s*text-align\s*:\s*justify(?:\s*!important)?(?=\s*(?:;|$))/gi, "$1text-align: left");
61
+ // The web editor can save fixed desktop dimensions and clipping styles.
62
+ // Let mobile paragraphs grow and wrap. Keep media dimensions intact.
63
+ if (!preserve && flowTags.test(node.name)) {
64
+ node.attribs.style = node.attribs.style
65
+ .replace(fixedFlowStyles, "$1")
66
+ .replace(noWrapStyles, "$1");
67
+ }
68
+ if (node.name === "figure" ||
69
+ node.name === "img" ||
70
+ node.name === "figcaption") {
71
+ node.attribs.style = node.attribs.style.replace(mediaSpacingStyles, "$1");
72
+ }
73
+ if (node.name === "p" && !preserve) {
74
+ node.attribs.style = node.attribs.style.replace(paragraphSpacingStyles, "$1");
75
+ }
76
+ }
77
+ if ((0, react_native_render_html_1.isDomText)(node) && !preserve) {
78
+ // Quill posts can contain NBSP between every word. Normalize only text
79
+ // nodes, not link/image attributes, so native text can wrap naturally.
80
+ node.data = node.data.replace(/\u00a0/g, " ");
81
+ }
82
+ if (hasChildren(node)) {
83
+ node.children.forEach((child) => visit(child, preserve));
84
+ }
85
+ };
86
+ visit(document);
87
+ },
88
+ };
89
+ exports.richHtmlClassesStyles = {
90
+ ...html_styles_1.quillClassesStyles,
91
+ "ql-align-justify": { textAlign: "left" },
92
+ "ql-align-center": { textAlign: "center" },
93
+ "ql-align-right": { textAlign: "right" },
94
+ };
95
+ // Inline tags inherit font size, color and weight from their parent. In
96
+ // particular, <strong><em>...</em></strong> must remain both bold and italic.
97
+ exports.richHtmlTagsStyles = {
98
+ p: { marginTop: 0, marginBottom: 6 },
99
+ strong: { fontWeight: "bold" },
100
+ b: { fontWeight: "bold" },
101
+ em: { fontStyle: "italic" },
102
+ i: { fontStyle: "italic" },
103
+ u: { textDecorationLine: "underline" },
104
+ s: { textDecorationLine: "line-through" },
105
+ h1: (0, html_styles_1.richHtmlTextSize)(24),
106
+ h2: (0, html_styles_1.richHtmlTextSize)(19),
107
+ h3: (0, html_styles_1.richHtmlTextSize)(18),
108
+ h4: (0, html_styles_1.richHtmlTextSize)(16),
109
+ h5: (0, html_styles_1.richHtmlTextSize)(14),
110
+ h6: (0, html_styles_1.richHtmlTextSize)(14),
111
+ ul: { paddingLeft: 20, marginTop: 0, marginBottom: 8 },
112
+ ol: { paddingLeft: 20, marginTop: 0, marginBottom: 8 },
113
+ li: { paddingLeft: 0 },
114
+ figure: { marginTop: 6, marginBottom: 8, marginLeft: 0, marginRight: 0 },
115
+ img: { marginTop: 4, marginBottom: 4, borderRadius: 12 },
116
+ figcaption: {
117
+ fontSize: (0, html_styles_1.scale)(12),
118
+ fontStyle: "italic",
119
+ textAlign: "center",
120
+ marginTop: 2,
121
+ marginBottom: 0,
122
+ },
123
+ };
@@ -0,0 +1,27 @@
1
+ import React from "react";
2
+ import { StyleProp, TextStyle, ViewStyle } from "react-native";
3
+ export interface SearchBarFilter {
4
+ onPress: () => void;
5
+ count?: number;
6
+ accessibilityLabel?: string;
7
+ icon?: React.ReactNode;
8
+ testID?: string;
9
+ }
10
+ export interface SearchBarProps {
11
+ value?: string;
12
+ onChangeText?: (value: string) => void;
13
+ onSubmit?: (value: string) => void;
14
+ onClear?: () => void;
15
+ /** Opens a dedicated search screen when the field is pressed. */
16
+ onPress?: () => void;
17
+ autoFocus?: boolean;
18
+ placeholder?: string;
19
+ clearAccessibilityLabel?: string;
20
+ searchIcon?: React.ReactNode;
21
+ clearIcon?: React.ReactNode;
22
+ filter?: SearchBarFilter;
23
+ style?: StyleProp<ViewStyle>;
24
+ fieldStyle?: StyleProp<ViewStyle>;
25
+ textStyle?: StyleProp<TextStyle>;
26
+ }
27
+ export declare function SearchBar({ value, onChangeText, onSubmit, onClear, onPress, autoFocus, placeholder, clearAccessibilityLabel, searchIcon, clearIcon, filter, style, fieldStyle, textStyle, }: SearchBarProps): React.JSX.Element;
package/dist/search.js ADDED
@@ -0,0 +1,91 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.SearchBar = SearchBar;
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 icons_1 = require("./icons");
8
+ const primitives_1 = require("./primitives");
9
+ const theme_1 = require("./theme");
10
+ function SearchBar({ value, onChangeText, onSubmit, onClear, onPress, autoFocus, placeholder = "Search", clearAccessibilityLabel = "Clear search", searchIcon, clearIcon, filter, style, fieldStyle, textStyle, }) {
11
+ const { colors: c, spacing: s, radius: r, typography: t } = (0, theme_1.useUITheme)();
12
+ const [input, setInput] = (0, react_1.useState)("");
13
+ const inputRef = (0, react_1.useRef)(null);
14
+ const keyword = value ?? input;
15
+ const height = s.xxl + s.xl;
16
+ const filterCount = filter?.count ?? 0;
17
+ const hasFilters = filterCount > 0;
18
+ const badgeLabel = filterCount > 99 ? "99+" : String(filterCount);
19
+ const badgeHeight = s.lg;
20
+ const badgeWidth = badgeHeight + (badgeLabel.length - 1) * s.sm;
21
+ // Keep the badge center on the button's top-right arc at 45 degrees.
22
+ const badgeCenterInset = (height / 2) * (1 - Math.SQRT1_2);
23
+ const changeText = (text) => {
24
+ if (value === undefined)
25
+ setInput(text);
26
+ onChangeText?.(text);
27
+ };
28
+ const field = [
29
+ styles.field,
30
+ {
31
+ height,
32
+ paddingHorizontal: s.md,
33
+ gap: s.sm,
34
+ borderRadius: r.full,
35
+ backgroundColor: c.base3,
36
+ },
37
+ fieldStyle,
38
+ ];
39
+ const icon = searchIcon ?? ((0, jsx_runtime_1.jsx)(icons_1.UIIcon, { name: "search", size: s.xxl, color: c.content2 }));
40
+ return ((0, jsx_runtime_1.jsxs)(react_native_1.View, { style: [styles.row, { gap: s.md }, style], children: [onPress ? ((0, jsx_runtime_1.jsxs)(react_native_1.Pressable, { accessibilityRole: "button", onPress: onPress, style: ({ pressed }) => [field, pressed && styles.pressed], children: [icon, (0, jsx_runtime_1.jsx)(primitives_1.UIText, { color: "content2", numberOfLines: 1, style: [styles.input, textStyle], children: placeholder })] })) : ((0, jsx_runtime_1.jsxs)(react_native_1.View, { style: field, children: [icon, (0, jsx_runtime_1.jsx)(react_native_1.TextInput, { ref: inputRef, autoFocus: autoFocus, value: keyword, placeholder: placeholder, placeholderTextColor: c.content2, onChangeText: changeText, onSubmitEditing: () => onSubmit?.(keyword), returnKeyType: "search", style: [
41
+ styles.input,
42
+ {
43
+ color: c.content1,
44
+ fontFamily: t.fontFamily,
45
+ fontSize: t.body,
46
+ lineHeight: t.body + s.xs,
47
+ },
48
+ textStyle,
49
+ ] }), keyword.length > 0 && ((0, jsx_runtime_1.jsx)(react_native_1.Pressable, { accessibilityRole: "button", accessibilityLabel: clearAccessibilityLabel, hitSlop: s.sm, onPress: () => {
50
+ changeText("");
51
+ onClear?.();
52
+ if (autoFocus)
53
+ inputRef.current?.focus();
54
+ }, style: clearIcon == null
55
+ ? [
56
+ styles.center,
57
+ {
58
+ width: t.body,
59
+ height: t.body,
60
+ borderRadius: r.full,
61
+ backgroundColor: c.gray600,
62
+ },
63
+ ]
64
+ : undefined, children: clearIcon ?? ((0, jsx_runtime_1.jsx)(icons_1.UIIcon, { name: "close", size: t.caption, color: c.background })) }))] })), filter && ((0, jsx_runtime_1.jsxs)(react_native_1.Pressable, { testID: filter.testID, accessibilityRole: "button", accessibilityLabel: filter.accessibilityLabel ?? "Filter", accessibilityValue: hasFilters ? { text: String(filterCount) } : undefined, onPress: filter.onPress, style: [
65
+ styles.center,
66
+ {
67
+ width: height,
68
+ height,
69
+ borderRadius: r.full,
70
+ backgroundColor: c.base3,
71
+ },
72
+ ], children: [filter.icon ?? ((0, jsx_runtime_1.jsx)(icons_1.UIIcon, { name: "filter", size: s.xxl, color: hasFilters ? c.primary500 : c.content1 })), hasFilters && ((0, jsx_runtime_1.jsx)(react_native_1.View, { pointerEvents: "none", style: [
73
+ styles.center,
74
+ {
75
+ position: "absolute",
76
+ top: badgeCenterInset - badgeHeight / 2,
77
+ right: badgeCenterInset - badgeWidth / 2,
78
+ width: badgeWidth,
79
+ height: badgeHeight,
80
+ borderRadius: r.full,
81
+ backgroundColor: c.danger,
82
+ },
83
+ ], children: (0, jsx_runtime_1.jsx)(primitives_1.UIText, { color: "textPrimary", variant: "caption", weight: "600", children: badgeLabel }) }))] }))] }));
84
+ }
85
+ const styles = react_native_1.StyleSheet.create({
86
+ row: { flexDirection: "row", alignItems: "center", minWidth: 0 },
87
+ field: { flex: 1, minWidth: 0, flexDirection: "row", alignItems: "center" },
88
+ pressed: { opacity: 0.8 },
89
+ input: { flex: 1, minWidth: 0, padding: 0 },
90
+ center: { alignItems: "center", justifyContent: "center" },
91
+ });
@@ -0,0 +1,67 @@
1
+ import React from "react";
2
+ import type { PaletteColors } from './colors';
3
+ /** Guideline contract only. Every app explicitly supplies its own palette. */
4
+ export type UIColors = PaletteColors & {
5
+ backdrop: string;
6
+ };
7
+ export interface UISpacing {
8
+ xs: number;
9
+ sm: number;
10
+ md: number;
11
+ lg: number;
12
+ xl: number;
13
+ xxl: number;
14
+ }
15
+ export interface UIRadius {
16
+ sm: number;
17
+ md: number;
18
+ lg: number;
19
+ sheet: number;
20
+ full: number;
21
+ }
22
+ export interface UITypography {
23
+ fontFamily?: string;
24
+ caption: number;
25
+ label: number;
26
+ body: number;
27
+ subtitle: number;
28
+ title: number;
29
+ }
30
+ export interface UITheme {
31
+ readonly mode: "light" | "dark";
32
+ readonly colors: Readonly<UIColors>;
33
+ readonly spacing: Readonly<UISpacing>;
34
+ readonly radius: Readonly<UIRadius>;
35
+ readonly typography: Readonly<UITypography>;
36
+ }
37
+ export interface UIThemeOptions {
38
+ mode?: UITheme["mode"];
39
+ /** Scales default geometry once; overrides are already in density-independent pixels. */
40
+ scale?: number;
41
+ colors?: Partial<UIColors>;
42
+ spacing?: Partial<UISpacing>;
43
+ radius?: Partial<UIRadius>;
44
+ typography?: Partial<UITypography>;
45
+ }
46
+ /** Complete app-owned palette; UIThemeOptions remains the partial override type. */
47
+ export type UIThemeInput = Omit<UIThemeOptions, 'colors'> & {
48
+ colors: UIColors;
49
+ };
50
+ /** Returns a fresh, frozen value. It never configures a global native theme. */
51
+ export declare function createUITheme(options: UIThemeInput): UITheme;
52
+ /** Pure theme value usable by Unistyles. Configuration belongs to app entries. */
53
+ export declare function create360Theme(options: UIThemeInput): {
54
+ type: "light" | "dark";
55
+ color: Readonly<UIColors>;
56
+ mode: "light" | "dark";
57
+ colors: Readonly<UIColors>;
58
+ spacing: Readonly<UISpacing>;
59
+ radius: Readonly<UIRadius>;
60
+ typography: Readonly<UITypography>;
61
+ };
62
+ export interface UIThemeProviderProps {
63
+ theme: UITheme;
64
+ children?: React.ReactNode;
65
+ }
66
+ export declare function UIThemeProvider({ theme, children }: UIThemeProviderProps): React.JSX.Element;
67
+ export declare function useUITheme(): UITheme;
package/dist/theme.js ADDED
@@ -0,0 +1,68 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.createUITheme = createUITheme;
4
+ exports.create360Theme = create360Theme;
5
+ exports.UIThemeProvider = UIThemeProvider;
6
+ exports.useUITheme = useUITheme;
7
+ const jsx_runtime_1 = require("react/jsx-runtime");
8
+ const react_1 = require("react");
9
+ function withDefined(base, overrides) {
10
+ const output = { ...base };
11
+ if (overrides)
12
+ for (const key of Object.keys(overrides)) {
13
+ if (overrides[key] !== undefined)
14
+ output[key] = overrides[key];
15
+ }
16
+ return output;
17
+ }
18
+ /** Returns a fresh, frozen value. It never configures a global native theme. */
19
+ function createUITheme(options) {
20
+ if (!options?.colors) {
21
+ throw new Error('UI360 requires an app-owned palette in createUITheme({ colors }).');
22
+ }
23
+ const scale = options.scale ?? 1;
24
+ if (!Number.isFinite(scale) || scale <= 0)
25
+ throw new RangeError("UI theme scale must be positive and finite");
26
+ const mode = options.mode ?? "light";
27
+ return Object.freeze({
28
+ mode,
29
+ colors: Object.freeze({ ...options.colors }),
30
+ spacing: Object.freeze(withDefined({
31
+ xs: 4 * scale,
32
+ sm: 8 * scale,
33
+ md: 12 * scale,
34
+ lg: 16 * scale,
35
+ xl: 20 * scale,
36
+ xxl: 24 * scale,
37
+ }, options.spacing)),
38
+ radius: Object.freeze(withDefined({
39
+ sm: 4 * scale,
40
+ md: 8 * scale,
41
+ lg: 12 * scale,
42
+ sheet: 24 * scale,
43
+ full: 999,
44
+ }, options.radius)),
45
+ typography: Object.freeze(withDefined({
46
+ caption: 10 * scale,
47
+ label: 12 * scale,
48
+ body: 14 * scale,
49
+ subtitle: 16 * scale,
50
+ title: 18 * scale,
51
+ }, options.typography)),
52
+ });
53
+ }
54
+ /** Pure theme value usable by Unistyles. Configuration belongs to app entries. */
55
+ function create360Theme(options) {
56
+ const theme = createUITheme(options);
57
+ return { ...theme, type: theme.mode, color: theme.colors };
58
+ }
59
+ const UIThemeContext = (0, react_1.createContext)(null);
60
+ function UIThemeProvider({ theme, children }) {
61
+ return ((0, jsx_runtime_1.jsx)(UIThemeContext.Provider, { value: theme, children: children }));
62
+ }
63
+ function useUITheme() {
64
+ const theme = (0, react_1.useContext)(UIThemeContext);
65
+ if (!theme)
66
+ throw new Error('UIThemeProvider with an app-owned palette is required.');
67
+ return theme;
68
+ }
@@ -0,0 +1,3 @@
1
+ import React from "react";
2
+ import { type ToastProps } from "react-native-toast-message";
3
+ export declare function AppToast({ config, topOffset, ...props }: ToastProps): React.JSX.Element;
package/dist/toast.js ADDED
@@ -0,0 +1,69 @@
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
+ var __importDefault = (this && this.__importDefault) || function (mod) {
36
+ return (mod && mod.__esModule) ? mod : { "default": mod };
37
+ };
38
+ Object.defineProperty(exports, "__esModule", { value: true });
39
+ exports.AppToast = AppToast;
40
+ const jsx_runtime_1 = require("react/jsx-runtime");
41
+ const react_1 = __importDefault(require("react"));
42
+ const react_native_1 = require("react-native");
43
+ const react_native_safe_area_context_1 = require("react-native-safe-area-context");
44
+ const react_native_toast_message_1 = __importStar(require("react-native-toast-message"));
45
+ function MultilineToast({ variant, ...props }) {
46
+ const { width } = (0, react_native_1.useWindowDimensions)();
47
+ return ((0, jsx_runtime_1.jsx)(react_native_toast_message_1.BaseToast, { ...props, text1NumberOfLines: 0, text2NumberOfLines: 0, style: [
48
+ styles.container,
49
+ styles[variant],
50
+ { width: Math.min(width - 32, 420) },
51
+ ], contentContainerStyle: styles.content, text1Style: [styles.message, props.text1Style], text2Style: [styles.description, props.text2Style] }));
52
+ }
53
+ const defaults = {
54
+ multilineSuccess: (props) => (0, jsx_runtime_1.jsx)(MultilineToast, { ...props, variant: "success" }),
55
+ multilineError: (props) => (0, jsx_runtime_1.jsx)(MultilineToast, { ...props, variant: "error" }),
56
+ };
57
+ function AppToast({ config, topOffset, ...props }) {
58
+ const insets = (0, react_native_safe_area_context_1.useSafeAreaInsets)();
59
+ const resolvedConfig = react_1.default.useMemo(() => (config ? { ...defaults, ...config } : defaults), [config]);
60
+ return ((0, jsx_runtime_1.jsx)(react_native_toast_message_1.default, { ...props, config: resolvedConfig, topOffset: topOffset ?? insets.top }));
61
+ }
62
+ const styles = react_native_1.StyleSheet.create({
63
+ container: { height: "auto", minHeight: 60 },
64
+ success: { borderLeftColor: "#69C779" },
65
+ error: { borderLeftColor: "#FE6301" },
66
+ content: { paddingHorizontal: 20, paddingVertical: 14 },
67
+ message: { fontSize: 14, lineHeight: 20, fontWeight: "500" },
68
+ description: { fontSize: 12, lineHeight: 18 },
69
+ });
@@ -0,0 +1,17 @@
1
+ import React from "react";
2
+ import { type ColorValue, type ModalProps, type StyleProp, type ViewStyle } from "react-native";
3
+ export interface UIModalProps {
4
+ visible: boolean;
5
+ onClose?: () => void;
6
+ onOpened?: () => void;
7
+ onClosed?: () => void;
8
+ position?: "center" | "bottom" | "fullScreen";
9
+ animationType?: ModalProps["animationType"];
10
+ statusBarTranslucent?: boolean;
11
+ keyboardAvoiding?: boolean;
12
+ backdropColor?: ColorValue;
13
+ contentStyle?: StyleProp<ViewStyle>;
14
+ containerStyle?: StyleProp<ViewStyle>;
15
+ children?: React.ReactNode;
16
+ }
17
+ export declare function UIModal({ visible, onClose, onOpened, onClosed, position, animationType, statusBarTranslucent, keyboardAvoiding, backdropColor, contentStyle, containerStyle, children, }: UIModalProps): React.JSX.Element;