@thanhphi/unistyles-ui 0.0.0-stage → 0.2.6

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 (61) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +374 -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 +138 -0
  10. package/dist/fields.js +240 -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 +51 -0
  15. package/dist/image.d.ts +20 -0
  16. package/dist/image.js +34 -0
  17. package/dist/index.d.ts +12 -0
  18. package/dist/index.js +30 -0
  19. package/dist/module/choices.js +135 -0
  20. package/dist/module/colors/index.js +1 -0
  21. package/dist/module/colors/package.json +1 -0
  22. package/dist/module/date.js +145 -0
  23. package/dist/module/fields.js +232 -0
  24. package/dist/module/form/index.js +62 -0
  25. package/dist/module/form/package.json +1 -0
  26. package/dist/module/icons.js +15 -0
  27. package/dist/module/image.js +31 -0
  28. package/dist/module/index.js +10 -0
  29. package/dist/module/overlays.js +102 -0
  30. package/dist/module/package.json +1 -0
  31. package/dist/module/primitives.js +432 -0
  32. package/dist/module/process-graph.js +125 -0
  33. package/dist/module/rich-html/html-styles.js +55 -0
  34. package/dist/module/rich-html/image-renderers.js +141 -0
  35. package/dist/module/rich-html/index.js +54 -0
  36. package/dist/module/rich-html/normalize-inline-colors.js +93 -0
  37. package/dist/module/rich-html/package.json +1 -0
  38. package/dist/module/rich-html/rich-html.js +118 -0
  39. package/dist/module/theme.js +62 -0
  40. package/dist/module/toast.js +30 -0
  41. package/dist/overlays.d.ts +52 -0
  42. package/dist/overlays.js +109 -0
  43. package/dist/primitives.d.ts +157 -0
  44. package/dist/primitives.js +480 -0
  45. package/dist/process-graph.d.ts +33 -0
  46. package/dist/process-graph.js +161 -0
  47. package/dist/rich-html/html-styles.d.ts +23 -0
  48. package/dist/rich-html/html-styles.js +63 -0
  49. package/dist/rich-html/image-renderers.d.ts +12 -0
  50. package/dist/rich-html/image-renderers.js +144 -0
  51. package/dist/rich-html/index.d.ts +18 -0
  52. package/dist/rich-html/index.js +92 -0
  53. package/dist/rich-html/normalize-inline-colors.d.ts +8 -0
  54. package/dist/rich-html/normalize-inline-colors.js +99 -0
  55. package/dist/rich-html/rich-html.d.ts +7 -0
  56. package/dist/rich-html/rich-html.js +123 -0
  57. package/dist/theme.d.ts +67 -0
  58. package/dist/theme.js +68 -0
  59. package/dist/toast.d.ts +3 -0
  60. package/dist/toast.js +69 -0
  61. package/package.json +35 -4
@@ -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,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
+ });
package/package.json CHANGED
@@ -1,6 +1,37 @@
1
1
  {
2
2
  "name": "@thanhphi/unistyles-ui",
3
- "version": "0.0.0-stage",
4
- "stub": true,
5
- "description": "Temporary package placeholder for staged publishing"
6
- }
3
+ "version": "0.2.6",
4
+ "description": "React Native UI components with app-owned themes and Unistyles integration",
5
+ "license": "MIT",
6
+ "main": "dist/index.js",
7
+ "module": "dist/module/index.js",
8
+ "types": "dist/index.d.ts",
9
+ "react-native": "dist/index.js",
10
+ "exports": {
11
+ ".": {"types": "./dist/index.d.ts", "react-native": "./dist/index.js", "import": "./dist/module/index.js", "require": "./dist/index.js"},
12
+ "./form": {"types": "./dist/form/index.d.ts", "react-native": "./dist/form/index.js", "import": "./dist/module/form/index.js", "require": "./dist/form/index.js"},
13
+ "./rich-html": {"types": "./dist/rich-html/index.d.ts", "react-native": "./dist/rich-html/index.js", "import": "./dist/module/rich-html/index.js", "require": "./dist/rich-html/index.js"},
14
+ "./toast": {"types": "./dist/toast.d.ts", "react-native": "./dist/toast.js", "import": "./dist/module/toast.js", "require": "./dist/toast.js"},
15
+ "./package.json": "./package.json"
16
+ },
17
+ "files": ["dist", "README.md", "LICENSE"],
18
+ "sideEffects": false,
19
+ "peerDependencies": {
20
+ "expo-image": ">=55.0.0 <56",
21
+ "react": ">=19.0.0 <20",
22
+ "react-native": ">=0.83.0 <0.84",
23
+ "react-native-calendars": ">=1.1314.0 <2",
24
+ "react-native-keyboard-controller": ">=1.21.7 <2",
25
+ "react-native-render-html": "6.3.4",
26
+ "react-native-safe-area-context": ">=5.6.0 <6",
27
+ "react-native-svg": ">=15.15.0 <16",
28
+ "react-native-toast-message": ">=2.3.3 <3"
29
+ },
30
+ "peerDependenciesMeta": {
31
+ "react-native-keyboard-controller": {"optional": true},
32
+ "react-native-render-html": {"optional": true},
33
+ "react-native-toast-message": {"optional": true}
34
+ },
35
+ "publishConfig": {"access": "public", "registry": "https://registry.npmjs.org/"},
36
+ "engines": {"node": ">=20"}
37
+ }