@neeleshyadav/react-native-html-renderer 1.1.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.
- package/LICENSE +20 -0
- package/README.md +407 -0
- package/lib/module/HtmlRenderer.js +183 -0
- package/lib/module/HtmlRenderer.js.map +1 -0
- package/lib/module/context/index.js +32 -0
- package/lib/module/context/index.js.map +1 -0
- package/lib/module/hooks/index.js +6 -0
- package/lib/module/hooks/index.js.map +1 -0
- package/lib/module/hooks/useContentWidth.js +12 -0
- package/lib/module/hooks/useContentWidth.js.map +1 -0
- package/lib/module/hooks/useHtmlParser.js +16 -0
- package/lib/module/hooks/useHtmlParser.js.map +1 -0
- package/lib/module/hooks/useTagStyle.js +26 -0
- package/lib/module/hooks/useTagStyle.js.map +1 -0
- package/lib/module/index.js +23 -0
- package/lib/module/index.js.map +1 -0
- package/lib/module/package.json +1 -0
- package/lib/module/parser/index.js +62 -0
- package/lib/module/parser/index.js.map +1 -0
- package/lib/module/renderer/ErrorBoundary.js +66 -0
- package/lib/module/renderer/ErrorBoundary.js.map +1 -0
- package/lib/module/renderer/NodeRenderer.js +279 -0
- package/lib/module/renderer/NodeRenderer.js.map +1 -0
- package/lib/module/renderer/index.js +5 -0
- package/lib/module/renderer/index.js.map +1 -0
- package/lib/module/renderer/tags/BlockTags.js +28 -0
- package/lib/module/renderer/tags/BlockTags.js.map +1 -0
- package/lib/module/renderer/tags/FormTags.js +129 -0
- package/lib/module/renderer/tags/FormTags.js.map +1 -0
- package/lib/module/renderer/tags/ImageTag.js +163 -0
- package/lib/module/renderer/tags/ImageTag.js.map +1 -0
- package/lib/module/renderer/tags/LinkTag.js +50 -0
- package/lib/module/renderer/tags/LinkTag.js.map +1 -0
- package/lib/module/renderer/tags/ListTags.js +96 -0
- package/lib/module/renderer/tags/ListTags.js.map +1 -0
- package/lib/module/renderer/tags/MediaTags.js +69 -0
- package/lib/module/renderer/tags/MediaTags.js.map +1 -0
- package/lib/module/renderer/tags/TableTags.js +48 -0
- package/lib/module/renderer/tags/TableTags.js.map +1 -0
- package/lib/module/renderer/tags/TextTags.js +87 -0
- package/lib/module/renderer/tags/TextTags.js.map +1 -0
- package/lib/module/renderer/tags/index.js +11 -0
- package/lib/module/renderer/tags/index.js.map +1 -0
- package/lib/module/styles/cssToRn.js +34 -0
- package/lib/module/styles/cssToRn.js.map +1 -0
- package/lib/module/styles/darkModeStyles.js +81 -0
- package/lib/module/styles/darkModeStyles.js.map +1 -0
- package/lib/module/styles/defaultStyles.js +218 -0
- package/lib/module/styles/defaultStyles.js.map +1 -0
- package/lib/module/styles/index.js +7 -0
- package/lib/module/styles/index.js.map +1 -0
- package/lib/module/styles/mergeStyles.js +47 -0
- package/lib/module/styles/mergeStyles.js.map +1 -0
- package/lib/module/types/index.js +4 -0
- package/lib/module/types/index.js.map +1 -0
- package/lib/module/utils/accessibility.js +108 -0
- package/lib/module/utils/accessibility.js.map +1 -0
- package/lib/module/utils/cache.js +69 -0
- package/lib/module/utils/cache.js.map +1 -0
- package/lib/module/utils/index.js +95 -0
- package/lib/module/utils/index.js.map +1 -0
- package/lib/module/utils/sanitize.js +102 -0
- package/lib/module/utils/sanitize.js.map +1 -0
- package/lib/typescript/package.json +1 -0
- package/lib/typescript/src/HtmlRenderer.d.ts +15 -0
- package/lib/typescript/src/HtmlRenderer.d.ts.map +1 -0
- package/lib/typescript/src/context/index.d.ts +5 -0
- package/lib/typescript/src/context/index.d.ts.map +1 -0
- package/lib/typescript/src/hooks/index.d.ts +4 -0
- package/lib/typescript/src/hooks/index.d.ts.map +1 -0
- package/lib/typescript/src/hooks/useContentWidth.d.ts +6 -0
- package/lib/typescript/src/hooks/useContentWidth.d.ts.map +1 -0
- package/lib/typescript/src/hooks/useHtmlParser.d.ts +11 -0
- package/lib/typescript/src/hooks/useHtmlParser.d.ts.map +1 -0
- package/lib/typescript/src/hooks/useTagStyle.d.ts +11 -0
- package/lib/typescript/src/hooks/useTagStyle.d.ts.map +1 -0
- package/lib/typescript/src/index.d.ts +9 -0
- package/lib/typescript/src/index.d.ts.map +1 -0
- package/lib/typescript/src/parser/index.d.ts +10 -0
- package/lib/typescript/src/parser/index.d.ts.map +1 -0
- package/lib/typescript/src/renderer/ErrorBoundary.d.ts +22 -0
- package/lib/typescript/src/renderer/ErrorBoundary.d.ts.map +1 -0
- package/lib/typescript/src/renderer/NodeRenderer.d.ts +7 -0
- package/lib/typescript/src/renderer/NodeRenderer.d.ts.map +1 -0
- package/lib/typescript/src/renderer/index.d.ts +3 -0
- package/lib/typescript/src/renderer/index.d.ts.map +1 -0
- package/lib/typescript/src/renderer/tags/BlockTags.d.ts +18 -0
- package/lib/typescript/src/renderer/tags/BlockTags.d.ts.map +1 -0
- package/lib/typescript/src/renderer/tags/FormTags.d.ts +16 -0
- package/lib/typescript/src/renderer/tags/FormTags.d.ts.map +1 -0
- package/lib/typescript/src/renderer/tags/ImageTag.d.ts +18 -0
- package/lib/typescript/src/renderer/tags/ImageTag.d.ts.map +1 -0
- package/lib/typescript/src/renderer/tags/LinkTag.d.ts +19 -0
- package/lib/typescript/src/renderer/tags/LinkTag.d.ts.map +1 -0
- package/lib/typescript/src/renderer/tags/ListTags.d.ts +15 -0
- package/lib/typescript/src/renderer/tags/ListTags.d.ts.map +1 -0
- package/lib/typescript/src/renderer/tags/MediaTags.d.ts +14 -0
- package/lib/typescript/src/renderer/tags/MediaTags.d.ts.map +1 -0
- package/lib/typescript/src/renderer/tags/TableTags.d.ts +15 -0
- package/lib/typescript/src/renderer/tags/TableTags.d.ts.map +1 -0
- package/lib/typescript/src/renderer/tags/TextTags.d.ts +22 -0
- package/lib/typescript/src/renderer/tags/TextTags.d.ts.map +1 -0
- package/lib/typescript/src/renderer/tags/index.d.ts +9 -0
- package/lib/typescript/src/renderer/tags/index.d.ts.map +1 -0
- package/lib/typescript/src/styles/cssToRn.d.ts +11 -0
- package/lib/typescript/src/styles/cssToRn.d.ts.map +1 -0
- package/lib/typescript/src/styles/darkModeStyles.d.ts +7 -0
- package/lib/typescript/src/styles/darkModeStyles.d.ts.map +1 -0
- package/lib/typescript/src/styles/defaultStyles.d.ts +8 -0
- package/lib/typescript/src/styles/defaultStyles.d.ts.map +1 -0
- package/lib/typescript/src/styles/index.d.ts +5 -0
- package/lib/typescript/src/styles/index.d.ts.map +1 -0
- package/lib/typescript/src/styles/mergeStyles.d.ts +10 -0
- package/lib/typescript/src/styles/mergeStyles.d.ts.map +1 -0
- package/lib/typescript/src/types/index.d.ts +158 -0
- package/lib/typescript/src/types/index.d.ts.map +1 -0
- package/lib/typescript/src/utils/accessibility.d.ts +32 -0
- package/lib/typescript/src/utils/accessibility.d.ts.map +1 -0
- package/lib/typescript/src/utils/cache.d.ts +24 -0
- package/lib/typescript/src/utils/cache.d.ts.map +1 -0
- package/lib/typescript/src/utils/index.d.ts +33 -0
- package/lib/typescript/src/utils/index.d.ts.map +1 -0
- package/lib/typescript/src/utils/sanitize.d.ts +11 -0
- package/lib/typescript/src/utils/sanitize.d.ts.map +1 -0
- package/package.json +171 -0
- package/src/HtmlRenderer.tsx +216 -0
- package/src/context/index.tsx +30 -0
- package/src/hooks/index.ts +3 -0
- package/src/hooks/useContentWidth.ts +9 -0
- package/src/hooks/useHtmlParser.ts +18 -0
- package/src/hooks/useTagStyle.ts +23 -0
- package/src/index.tsx +39 -0
- package/src/parser/index.ts +80 -0
- package/src/renderer/ErrorBoundary.tsx +80 -0
- package/src/renderer/NodeRenderer.tsx +345 -0
- package/src/renderer/index.tsx +2 -0
- package/src/renderer/tags/BlockTags.tsx +49 -0
- package/src/renderer/tags/FormTags.tsx +169 -0
- package/src/renderer/tags/ImageTag.tsx +215 -0
- package/src/renderer/tags/LinkTag.tsx +76 -0
- package/src/renderer/tags/ListTags.tsx +148 -0
- package/src/renderer/tags/MediaTags.tsx +81 -0
- package/src/renderer/tags/TableTags.tsx +94 -0
- package/src/renderer/tags/TextTags.tsx +139 -0
- package/src/renderer/tags/index.ts +8 -0
- package/src/styles/cssToRn.ts +45 -0
- package/src/styles/darkModeStyles.ts +80 -0
- package/src/styles/defaultStyles.ts +176 -0
- package/src/styles/index.ts +4 -0
- package/src/styles/mergeStyles.ts +59 -0
- package/src/types/index.ts +229 -0
- package/src/utils/accessibility.ts +132 -0
- package/src/utils/cache.ts +83 -0
- package/src/utils/index.ts +151 -0
- package/src/utils/sanitize.ts +149 -0
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import { type ReactNode } from 'react';
|
|
2
|
+
import type { DOMNode, DOMElement, RNStyle, HtmlRendererContextValue } from '../../types';
|
|
3
|
+
interface TextBlockProps {
|
|
4
|
+
tag: string;
|
|
5
|
+
node: DOMElement;
|
|
6
|
+
style: RNStyle;
|
|
7
|
+
children: DOMNode[];
|
|
8
|
+
nodeKey: string;
|
|
9
|
+
ctx: HtmlRendererContextValue;
|
|
10
|
+
renderNodes: (nodes: DOMNode[], ctx: HtmlRendererContextValue, keyPrefix: string) => ReactNode[];
|
|
11
|
+
}
|
|
12
|
+
/**
|
|
13
|
+
* Renders a text-block tag (`<p>`, `<h1>`-`<h6>`, `<pre>`, `<label>`, etc.)
|
|
14
|
+
* as a single `<Text>` component.
|
|
15
|
+
*/
|
|
16
|
+
export declare const TextBlock: import("react").MemoExoticComponent<({ node, style, children, nodeKey, ctx, renderNodes, }: TextBlockProps) => import("react/jsx-runtime").JSX.Element>;
|
|
17
|
+
/**
|
|
18
|
+
* Renders inline content (text nodes + inline tags) as nested `<Text>` elements.
|
|
19
|
+
*/
|
|
20
|
+
export declare function renderInlineNodes(nodes: DOMNode[], ctx: HtmlRendererContextValue, keyPrefix: string, renderNodes: (nodes: DOMNode[], ctx: HtmlRendererContextValue, keyPrefix: string) => ReactNode[]): ReactNode[];
|
|
21
|
+
export {};
|
|
22
|
+
//# sourceMappingURL=TextTags.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"TextTags.d.ts","sourceRoot":"","sources":["../../../../../src/renderer/tags/TextTags.tsx"],"names":[],"mappings":"AAAA,OAAO,EAAQ,KAAK,SAAS,EAAE,MAAM,OAAO,CAAC;AAE7C,OAAO,KAAK,EACV,OAAO,EACP,UAAU,EACV,OAAO,EACP,wBAAwB,EACzB,MAAM,aAAa,CAAC;AAIrB,UAAU,cAAc;IACtB,GAAG,EAAE,MAAM,CAAC;IACZ,IAAI,EAAE,UAAU,CAAC;IACjB,KAAK,EAAE,OAAO,CAAC;IACf,QAAQ,EAAE,OAAO,EAAE,CAAC;IACpB,OAAO,EAAE,MAAM,CAAC;IAChB,GAAG,EAAE,wBAAwB,CAAC;IAC9B,WAAW,EAAE,CACX,KAAK,EAAE,OAAO,EAAE,EAChB,GAAG,EAAE,wBAAwB,EAC7B,SAAS,EAAE,MAAM,KACd,SAAS,EAAE,CAAC;CAClB;AAED;;;GAGG;AACH,eAAO,MAAM,SAAS,8FAOnB,cAAc,6CAwBf,CAAC;AAEH;;GAEG;AACH,wBAAgB,iBAAiB,CAC/B,KAAK,EAAE,OAAO,EAAE,EAChB,GAAG,EAAE,wBAAwB,EAC7B,SAAS,EAAE,MAAM,EACjB,WAAW,EAAE,CACX,KAAK,EAAE,OAAO,EAAE,EAChB,GAAG,EAAE,wBAAwB,EAC7B,SAAS,EAAE,MAAM,KACd,SAAS,EAAE,GACf,SAAS,EAAE,CAgEb"}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
export { TextBlock, renderInlineNodes } from './TextTags';
|
|
2
|
+
export { ImageTag } from './ImageTag';
|
|
3
|
+
export { LinkTag } from './LinkTag';
|
|
4
|
+
export { ListTag } from './ListTags';
|
|
5
|
+
export { TableTag } from './TableTags';
|
|
6
|
+
export { BlockTag } from './BlockTags';
|
|
7
|
+
export { InputTag, TextareaTag, ButtonTag, SelectTag } from './FormTags';
|
|
8
|
+
export { VideoTag, AudioTag } from './MediaTags';
|
|
9
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../../src/renderer/tags/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,iBAAiB,EAAE,MAAM,YAAY,CAAC;AAC1D,OAAO,EAAE,QAAQ,EAAE,MAAM,YAAY,CAAC;AACtC,OAAO,EAAE,OAAO,EAAE,MAAM,WAAW,CAAC;AACpC,OAAO,EAAE,OAAO,EAAE,MAAM,YAAY,CAAC;AACrC,OAAO,EAAE,QAAQ,EAAE,MAAM,aAAa,CAAC;AACvC,OAAO,EAAE,QAAQ,EAAE,MAAM,aAAa,CAAC;AACvC,OAAO,EAAE,QAAQ,EAAE,WAAW,EAAE,SAAS,EAAE,SAAS,EAAE,MAAM,YAAY,CAAC;AACzE,OAAO,EAAE,QAAQ,EAAE,QAAQ,EAAE,MAAM,aAAa,CAAC"}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import type { RNStyle } from '../types';
|
|
2
|
+
/**
|
|
3
|
+
* Parse an inline CSS `style` attribute string into a React Native style object.
|
|
4
|
+
*
|
|
5
|
+
* @param styleString - The raw CSS string (e.g. `"color: red; font-size: 18px"`).
|
|
6
|
+
* @param ignoredStyles - CSS property names to exclude.
|
|
7
|
+
* @param allowedStyles - If provided, only these CSS property names are kept.
|
|
8
|
+
* @returns A React Native compatible style object.
|
|
9
|
+
*/
|
|
10
|
+
export declare function parseInlineStyle(styleString: string, ignoredStyles?: Set<string>, allowedStyles?: Set<string> | null): RNStyle;
|
|
11
|
+
//# sourceMappingURL=cssToRn.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"cssToRn.d.ts","sourceRoot":"","sources":["../../../../src/styles/cssToRn.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,UAAU,CAAC;AAExC;;;;;;;GAOG;AACH,wBAAgB,gBAAgB,CAC9B,WAAW,EAAE,MAAM,EACnB,aAAa,CAAC,EAAE,GAAG,CAAC,MAAM,CAAC,EAC3B,aAAa,CAAC,EAAE,GAAG,CAAC,MAAM,CAAC,GAAG,IAAI,GACjC,OAAO,CA6BT"}
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import type { TagsStyles } from '../types';
|
|
2
|
+
/**
|
|
3
|
+
* Default dark mode style overrides. These are merged on top of the
|
|
4
|
+
* default light-mode tag styles when the system color scheme is 'dark'.
|
|
5
|
+
*/
|
|
6
|
+
export declare function getDefaultDarkModeStyles(): TagsStyles;
|
|
7
|
+
//# sourceMappingURL=darkModeStyles.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"darkModeStyles.d.ts","sourceRoot":"","sources":["../../../../src/styles/darkModeStyles.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,UAAU,CAAC;AAE3C;;;GAGG;AACH,wBAAgB,wBAAwB,IAAI,UAAU,CAwErD"}
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import type { TagsStyles } from '../types';
|
|
2
|
+
/**
|
|
3
|
+
* Returns the default styles for all supported HTML tags.
|
|
4
|
+
*
|
|
5
|
+
* @param emSize - Base em unit in pixels (used for heading sizes etc.).
|
|
6
|
+
*/
|
|
7
|
+
export declare function getDefaultTagStyles(emSize: number): TagsStyles;
|
|
8
|
+
//# sourceMappingURL=defaultStyles.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"defaultStyles.d.ts","sourceRoot":"","sources":["../../../../src/styles/defaultStyles.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,UAAU,CAAC;AAE3C;;;;GAIG;AACH,wBAAgB,mBAAmB,CAAC,MAAM,EAAE,MAAM,GAAG,UAAU,CAuK9D"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../src/styles/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,gBAAgB,EAAE,MAAM,WAAW,CAAC;AAC7C,OAAO,EAAE,mBAAmB,EAAE,MAAM,iBAAiB,CAAC;AACtD,OAAO,EAAE,wBAAwB,EAAE,MAAM,kBAAkB,CAAC;AAC5D,OAAO,EAAE,qBAAqB,EAAE,MAAM,eAAe,CAAC"}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import type { RNStyle, TagsStyles, ClassesStyles, IdsStyles, DOMElement } from '../types';
|
|
2
|
+
/**
|
|
3
|
+
* Merge all style layers for a given DOM element in the correct cascade order:
|
|
4
|
+
*
|
|
5
|
+
* defaultTagStyle → tagsStyles → classesStyles → idsStyles → inline style
|
|
6
|
+
*
|
|
7
|
+
* Later layers override earlier ones.
|
|
8
|
+
*/
|
|
9
|
+
export declare function mergeStylesForElement(node: DOMElement, defaultStyles: TagsStyles, tagsStyles: TagsStyles, classesStyles: ClassesStyles, idsStyles: IdsStyles, ignoredStyles?: Set<string>, allowedStyles?: Set<string> | null): RNStyle;
|
|
10
|
+
//# sourceMappingURL=mergeStyles.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"mergeStyles.d.ts","sourceRoot":"","sources":["../../../../src/styles/mergeStyles.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EACV,OAAO,EACP,UAAU,EACV,aAAa,EACb,SAAS,EACT,UAAU,EACX,MAAM,UAAU,CAAC;AAGlB;;;;;;GAMG;AACH,wBAAgB,qBAAqB,CACnC,IAAI,EAAE,UAAU,EAChB,aAAa,EAAE,UAAU,EACzB,UAAU,EAAE,UAAU,EACtB,aAAa,EAAE,aAAa,EAC5B,SAAS,EAAE,SAAS,EACpB,aAAa,CAAC,EAAE,GAAG,CAAC,MAAM,CAAC,EAC3B,aAAa,CAAC,EAAE,GAAG,CAAC,MAAM,CAAC,GAAG,IAAI,GACjC,OAAO,CAkCT"}
|
|
@@ -0,0 +1,158 @@
|
|
|
1
|
+
import type { ReactNode } from 'react';
|
|
2
|
+
import type { TextStyle, ViewStyle, ImageStyle, TextProps, ViewProps, ColorSchemeName } from 'react-native';
|
|
3
|
+
/** A parsed DOM node — either an element or a text node. */
|
|
4
|
+
export type DOMNode = DOMElement | DOMText;
|
|
5
|
+
/** An HTML element node with tag, attributes, and children. */
|
|
6
|
+
export interface DOMElement {
|
|
7
|
+
type: 'element';
|
|
8
|
+
tag: string;
|
|
9
|
+
attributes: Record<string, string>;
|
|
10
|
+
children: DOMNode[];
|
|
11
|
+
}
|
|
12
|
+
/** A text node containing raw string data. */
|
|
13
|
+
export interface DOMText {
|
|
14
|
+
type: 'text';
|
|
15
|
+
data: string;
|
|
16
|
+
}
|
|
17
|
+
/** Union of all React Native style types. */
|
|
18
|
+
export type RNStyle = ViewStyle | TextStyle | ImageStyle;
|
|
19
|
+
/** Per-tag style overrides keyed by HTML tag name. */
|
|
20
|
+
export type TagsStyles = Record<string, RNStyle>;
|
|
21
|
+
/** Per-class style overrides keyed by HTML class name. */
|
|
22
|
+
export type ClassesStyles = Record<string, RNStyle>;
|
|
23
|
+
/** Per-id style overrides keyed by HTML element id. */
|
|
24
|
+
export type IdsStyles = Record<string, RNStyle>;
|
|
25
|
+
/** Props passed to a custom renderer function. */
|
|
26
|
+
export interface CustomRendererProps {
|
|
27
|
+
/** The DOM element node being rendered. */
|
|
28
|
+
node: DOMElement;
|
|
29
|
+
/** Pre-rendered children as React nodes. */
|
|
30
|
+
children: ReactNode[];
|
|
31
|
+
/** Merged style for this element. */
|
|
32
|
+
style: RNStyle;
|
|
33
|
+
/** Attributes from the HTML element. */
|
|
34
|
+
attributes: Record<string, string>;
|
|
35
|
+
/** Extra props passed via renderersProps[tag]. */
|
|
36
|
+
passProps: Record<string, unknown>;
|
|
37
|
+
/** Render helper — call with child DOMNodes to render them. */
|
|
38
|
+
renderChildren: (nodes: DOMNode[]) => ReactNode[];
|
|
39
|
+
/** Current content width from context. */
|
|
40
|
+
contentWidth: number;
|
|
41
|
+
}
|
|
42
|
+
/** A custom renderer receives props and returns a ReactNode. */
|
|
43
|
+
export type CustomRenderer = (props: CustomRendererProps) => ReactNode;
|
|
44
|
+
export interface ListPrefixRendererProps {
|
|
45
|
+
index: number;
|
|
46
|
+
nestLevel: number;
|
|
47
|
+
}
|
|
48
|
+
export interface ListsPrefixesRenderers {
|
|
49
|
+
ul?: (props: ListPrefixRendererProps) => ReactNode;
|
|
50
|
+
ol?: (props: ListPrefixRendererProps) => ReactNode;
|
|
51
|
+
}
|
|
52
|
+
/** Props for the main `<HtmlRenderer />` component. */
|
|
53
|
+
export interface HtmlRendererProps {
|
|
54
|
+
/** Raw HTML string to render. */
|
|
55
|
+
html: string;
|
|
56
|
+
/** Available width for content layout and image scaling. */
|
|
57
|
+
contentWidth: number;
|
|
58
|
+
/** Base style applied to the root container. */
|
|
59
|
+
baseStyle?: ViewStyle;
|
|
60
|
+
/** Per-tag style overrides. */
|
|
61
|
+
tagsStyles?: TagsStyles;
|
|
62
|
+
/** Styles applied by HTML class name. */
|
|
63
|
+
classesStyles?: ClassesStyles;
|
|
64
|
+
/** Styles applied by HTML element id. */
|
|
65
|
+
idsStyles?: IdsStyles;
|
|
66
|
+
/** Override rendering for specific tags. */
|
|
67
|
+
customRenderers?: Record<string, CustomRenderer>;
|
|
68
|
+
/** Called when a link (`<a>`) is pressed. */
|
|
69
|
+
onLinkPress?: (href: string, attributes: Record<string, string>) => void;
|
|
70
|
+
/** Called when an image is pressed. */
|
|
71
|
+
onImagePress?: (src: string, attributes: Record<string, string>) => void;
|
|
72
|
+
/** Called when an error occurs during parsing or rendering. */
|
|
73
|
+
onError?: (error: Error) => void;
|
|
74
|
+
/** Custom fallback UI to show when an error occurs. If omitted, a default error message is shown. Set to `null` to render nothing on error. */
|
|
75
|
+
fallback?: ReactNode;
|
|
76
|
+
/** Tags to completely ignore (including their children). */
|
|
77
|
+
ignoredTags?: string[];
|
|
78
|
+
/** CSS property names to ignore during style conversion. */
|
|
79
|
+
ignoredStyles?: string[];
|
|
80
|
+
/** Whitelist of CSS property names to allow (if set, only these are kept). */
|
|
81
|
+
allowedStyles?: string[];
|
|
82
|
+
/** Default props passed to every `<Text>` component. */
|
|
83
|
+
defaultTextProps?: TextProps;
|
|
84
|
+
/** Default props passed to every `<View>` component. */
|
|
85
|
+
defaultViewProps?: ViewProps;
|
|
86
|
+
/** Extra props forwarded to specific tag renderers. */
|
|
87
|
+
renderersProps?: Record<string, Record<string, unknown>>;
|
|
88
|
+
/** Maximum width for images. */
|
|
89
|
+
maxImagesWidth?: number;
|
|
90
|
+
/** Placeholder dimensions before image loads. */
|
|
91
|
+
imagesInitialDimensions?: {
|
|
92
|
+
width: number;
|
|
93
|
+
height: number;
|
|
94
|
+
};
|
|
95
|
+
/** Custom bullet/number renderers for lists. */
|
|
96
|
+
listsPrefixesRenderers?: ListsPrefixesRenderers;
|
|
97
|
+
/** Base em unit in pixels (default 14). */
|
|
98
|
+
emSize?: number;
|
|
99
|
+
/** List of available system fonts. */
|
|
100
|
+
systemFonts?: string[];
|
|
101
|
+
/** Map unsupported font families to fallback fonts. */
|
|
102
|
+
fallbackFonts?: Record<string, string>;
|
|
103
|
+
/** Log parsed DOM and computed styles to the console. */
|
|
104
|
+
debug?: boolean;
|
|
105
|
+
/**
|
|
106
|
+
* When false (default), dangerous tags (`<script>`, `<iframe>`, `<object>`,
|
|
107
|
+
* `<embed>`, `<form>`) and `javascript:` hrefs are stripped automatically.
|
|
108
|
+
* Set to true to allow all HTML through (use with caution).
|
|
109
|
+
*/
|
|
110
|
+
allowDangerousHtml?: boolean;
|
|
111
|
+
/** Per-tag style overrides applied when the system is in dark mode. */
|
|
112
|
+
darkModeStyles?: TagsStyles;
|
|
113
|
+
/**
|
|
114
|
+
* Override color scheme detection. When omitted the system scheme is used
|
|
115
|
+
* via `useColorScheme()`.
|
|
116
|
+
*/
|
|
117
|
+
colorScheme?: ColorSchemeName;
|
|
118
|
+
/** Allow system font-size accessibility scaling (default true). */
|
|
119
|
+
allowFontScaling?: boolean;
|
|
120
|
+
/** Cap the font-size multiplier for accessibility scaling. */
|
|
121
|
+
maxFontSizeMultiplier?: number;
|
|
122
|
+
}
|
|
123
|
+
/** Shape of the context shared through the renderer tree. */
|
|
124
|
+
export interface HtmlRendererContextValue {
|
|
125
|
+
contentWidth: number;
|
|
126
|
+
tagsStyles: TagsStyles;
|
|
127
|
+
classesStyles: ClassesStyles;
|
|
128
|
+
idsStyles: IdsStyles;
|
|
129
|
+
customRenderers: Record<string, CustomRenderer>;
|
|
130
|
+
onLinkPress?: (href: string, attributes: Record<string, string>) => void;
|
|
131
|
+
onImagePress?: (src: string, attributes: Record<string, string>) => void;
|
|
132
|
+
renderersProps: Record<string, Record<string, unknown>>;
|
|
133
|
+
emSize: number;
|
|
134
|
+
debug: boolean;
|
|
135
|
+
ignoredTags: Set<string>;
|
|
136
|
+
ignoredStyles: Set<string>;
|
|
137
|
+
allowedStyles: Set<string> | null;
|
|
138
|
+
defaultTextProps?: TextProps;
|
|
139
|
+
defaultViewProps?: ViewProps;
|
|
140
|
+
maxImagesWidth?: number;
|
|
141
|
+
imagesInitialDimensions: {
|
|
142
|
+
width: number;
|
|
143
|
+
height: number;
|
|
144
|
+
};
|
|
145
|
+
listsPrefixesRenderers?: ListsPrefixesRenderers;
|
|
146
|
+
systemFonts?: string[];
|
|
147
|
+
fallbackFonts?: Record<string, string>;
|
|
148
|
+
nestLevel: number;
|
|
149
|
+
/** Resolved color scheme — 'dark' | 'light' | null | undefined. */
|
|
150
|
+
colorScheme: ColorSchemeName | null | undefined;
|
|
151
|
+
/** Dark mode tag style overrides (merged into tagsStyles when dark). */
|
|
152
|
+
darkModeStyles: TagsStyles;
|
|
153
|
+
/** Allow system font scaling on Text components. */
|
|
154
|
+
allowFontScaling: boolean;
|
|
155
|
+
/** Cap the font size multiplier. */
|
|
156
|
+
maxFontSizeMultiplier?: number;
|
|
157
|
+
}
|
|
158
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceR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AAS,CAAC;IAChD,wEAAwE;IACxE,cAAc,EAAE,UAAU,CAAC;IAC3B,oDAAoD;IACpD,gBAAgB,EAAE,OAAO,CAAC;IAC1B,oCAAoC;IACpC,qBAAqB,CAAC,EAAE,MAAM,CAAC;CAChC"}
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
import type { AccessibilityRole } from 'react-native';
|
|
2
|
+
import type { DOMElement } from '../types';
|
|
3
|
+
/** Accessibility props derived from a DOM element's attributes. */
|
|
4
|
+
export interface A11yProps {
|
|
5
|
+
accessibilityRole?: AccessibilityRole;
|
|
6
|
+
accessibilityLabel?: string;
|
|
7
|
+
accessibilityHint?: string;
|
|
8
|
+
accessibilityState?: {
|
|
9
|
+
disabled?: boolean;
|
|
10
|
+
selected?: boolean;
|
|
11
|
+
checked?: boolean | 'mixed';
|
|
12
|
+
busy?: boolean;
|
|
13
|
+
expanded?: boolean;
|
|
14
|
+
};
|
|
15
|
+
accessible?: boolean;
|
|
16
|
+
importantForAccessibility?: 'auto' | 'yes' | 'no' | 'no-hide-descendants';
|
|
17
|
+
}
|
|
18
|
+
/**
|
|
19
|
+
* Extract accessibility props from a DOMElement's HTML attributes.
|
|
20
|
+
* Supports: aria-label, aria-hidden, aria-role, role, alt, title,
|
|
21
|
+
* aria-disabled, aria-selected, aria-checked, aria-busy, aria-expanded.
|
|
22
|
+
*/
|
|
23
|
+
export declare function getAccessibilityProps(node: DOMElement): A11yProps;
|
|
24
|
+
/**
|
|
25
|
+
* Build an accessibility label for an image from its attributes.
|
|
26
|
+
*/
|
|
27
|
+
export declare function getImageA11yLabel(node: DOMElement): string | undefined;
|
|
28
|
+
/**
|
|
29
|
+
* Build an accessibility label for a link from its children text.
|
|
30
|
+
*/
|
|
31
|
+
export declare function getLinkA11yLabel(node: DOMElement): string | undefined;
|
|
32
|
+
//# sourceMappingURL=accessibility.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"accessibility.d.ts","sourceRoot":"","sources":["../../../../src/utils/accessibility.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,cAAc,CAAC;AACtD,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,UAAU,CAAC;AAqB3C,mEAAmE;AACnE,MAAM,WAAW,SAAS;IACxB,iBAAiB,CAAC,EAAE,iBAAiB,CAAC;IACtC,kBAAkB,CAAC,EAAE,MAAM,CAAC;IAC5B,iBAAiB,CAAC,EAAE,MAAM,CAAC;IAC3B,kBAAkB,CAAC,EAAE;QACnB,QAAQ,CAAC,EAAE,OAAO,CAAC;QACnB,QAAQ,CAAC,EAAE,OAAO,CAAC;QACnB,OAAO,CAAC,EAAE,OAAO,GAAG,OAAO,CAAC;QAC5B,IAAI,CAAC,EAAE,OAAO,CAAC;QACf,QAAQ,CAAC,EAAE,OAAO,CAAC;KACpB,CAAC;IACF,UAAU,CAAC,EAAE,OAAO,CAAC;IACrB,yBAAyB,CAAC,EAAE,MAAM,GAAG,KAAK,GAAG,IAAI,GAAG,qBAAqB,CAAC;CAC3E;AAED;;;;GAIG;AACH,wBAAgB,qBAAqB,CAAC,IAAI,EAAE,UAAU,GAAG,SAAS,CAkEjE;AAED;;GAEG;AACH,wBAAgB,iBAAiB,CAAC,IAAI,EAAE,UAAU,GAAG,MAAM,GAAG,SAAS,CAOtE;AAED;;GAEG;AACH,wBAAgB,gBAAgB,CAAC,IAAI,EAAE,UAAU,GAAG,MAAM,GAAG,SAAS,CAKrE"}
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import type { DOMNode } from '../types';
|
|
2
|
+
interface ImageDimensions {
|
|
3
|
+
width: number;
|
|
4
|
+
height: number;
|
|
5
|
+
}
|
|
6
|
+
/** Get cached image dimensions for a URL. */
|
|
7
|
+
export declare function getCachedImageDimensions(uri: string): ImageDimensions | undefined;
|
|
8
|
+
/** Cache image dimensions for a URL. */
|
|
9
|
+
export declare function setCachedImageDimensions(uri: string, dimensions: ImageDimensions): void;
|
|
10
|
+
/** Clear the image dimension cache (useful for testing). */
|
|
11
|
+
export declare function clearImageDimensionCache(): void;
|
|
12
|
+
/**
|
|
13
|
+
* Build a composite cache key that incorporates all parameters affecting
|
|
14
|
+
* the parse/sanitize result, preventing cache poisoning.
|
|
15
|
+
*/
|
|
16
|
+
export declare function buildDOMCacheKey(html: string, allowDangerousHtml: boolean, ignoredTags: Set<string>): string;
|
|
17
|
+
/** Get cached parsed DOM for a cache key. */
|
|
18
|
+
export declare function getCachedDOM(cacheKey: string): DOMNode[] | undefined;
|
|
19
|
+
/** Cache parsed DOM for a cache key. */
|
|
20
|
+
export declare function setCachedDOM(cacheKey: string, nodes: DOMNode[]): void;
|
|
21
|
+
/** Clear the DOM cache (useful for testing). */
|
|
22
|
+
export declare function clearDOMCache(): void;
|
|
23
|
+
export {};
|
|
24
|
+
//# sourceMappingURL=cache.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"cache.d.ts","sourceRoot":"","sources":["../../../../src/utils/cache.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,UAAU,CAAC;AAMxC,UAAU,eAAe;IACvB,KAAK,EAAE,MAAM,CAAC;IACd,MAAM,EAAE,MAAM,CAAC;CAChB;AAKD,6CAA6C;AAC7C,wBAAgB,wBAAwB,CACtC,GAAG,EAAE,MAAM,GACV,eAAe,GAAG,SAAS,CAE7B;AAED,wCAAwC;AACxC,wBAAgB,wBAAwB,CACtC,GAAG,EAAE,MAAM,EACX,UAAU,EAAE,eAAe,GAC1B,IAAI,CAQN;AAED,4DAA4D;AAC5D,wBAAgB,wBAAwB,IAAI,IAAI,CAE/C;AAWD;;;GAGG;AACH,wBAAgB,gBAAgB,CAC9B,IAAI,EAAE,MAAM,EACZ,kBAAkB,EAAE,OAAO,EAC3B,WAAW,EAAE,GAAG,CAAC,MAAM,CAAC,GACvB,MAAM,CAIR;AAED,6CAA6C;AAC7C,wBAAgB,YAAY,CAAC,QAAQ,EAAE,MAAM,GAAG,OAAO,EAAE,GAAG,SAAS,CAEpE;AAED,wCAAwC;AACxC,wBAAgB,YAAY,CAAC,QAAQ,EAAE,MAAM,EAAE,KAAK,EAAE,OAAO,EAAE,GAAG,IAAI,CAQrE;AAED,gDAAgD;AAChD,wBAAgB,aAAa,IAAI,IAAI,CAEpC"}
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
import type { DOMNode, DOMElement } from '../types';
|
|
2
|
+
export { sanitizeDOM } from './sanitize';
|
|
3
|
+
export { getAccessibilityProps, getImageA11yLabel, getLinkA11yLabel, type A11yProps, } from './accessibility';
|
|
4
|
+
export { getCachedImageDimensions, setCachedImageDimensions, clearImageDimensionCache, getCachedDOM, setCachedDOM, clearDOMCache, buildDOMCacheKey, } from './cache';
|
|
5
|
+
/**
|
|
6
|
+
* Convert a CSS value string to a numeric pixel value.
|
|
7
|
+
* Supports: px, em, rem, bare numbers. Percentage returns NaN (handled upstream).
|
|
8
|
+
*/
|
|
9
|
+
export declare function cssValueToNumeric(value: string, emSize: number): number | undefined;
|
|
10
|
+
/** Tags that are inherently inline (text-level). */
|
|
11
|
+
export declare const INLINE_TAGS: Set<string>;
|
|
12
|
+
/** Tags that are text containers (rendered as `<Text>` at block level). */
|
|
13
|
+
export declare const TEXT_BLOCK_TAGS: Set<string>;
|
|
14
|
+
/** Tags that should be silently skipped (no output). */
|
|
15
|
+
export declare const ALWAYS_IGNORED_TAGS: Set<string>;
|
|
16
|
+
/**
|
|
17
|
+
* Returns true if every child of the given list is either a text node
|
|
18
|
+
* or an inline-level element whose descendants are also all inline.
|
|
19
|
+
*/
|
|
20
|
+
export declare function isInlineContent(nodes: DOMNode[]): boolean;
|
|
21
|
+
/**
|
|
22
|
+
* Resolve a potentially relative URL against a base URL.
|
|
23
|
+
*/
|
|
24
|
+
export declare function resolveUrl(url: string, baseUrl?: string): string;
|
|
25
|
+
/**
|
|
26
|
+
* Type-guard: checks if a DOMNode is a DOMElement.
|
|
27
|
+
*/
|
|
28
|
+
export declare function isDOMElement(node: DOMNode): node is DOMElement;
|
|
29
|
+
/**
|
|
30
|
+
* Extract all text content from a node tree (for accessibility labels, etc.).
|
|
31
|
+
*/
|
|
32
|
+
export declare function extractTextContent(nodes: DOMNode[]): string;
|
|
33
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../src/utils/index.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,OAAO,EAAE,UAAU,EAAE,MAAM,UAAU,CAAC;AAGpD,OAAO,EAAE,WAAW,EAAE,MAAM,YAAY,CAAC;AACzC,OAAO,EACL,qBAAqB,EACrB,iBAAiB,EACjB,gBAAgB,EAChB,KAAK,SAAS,GACf,MAAM,iBAAiB,CAAC;AACzB,OAAO,EACL,wBAAwB,EACxB,wBAAwB,EACxB,wBAAwB,EACxB,YAAY,EACZ,YAAY,EACZ,aAAa,EACb,gBAAgB,GACjB,MAAM,SAAS,CAAC;AAMjB;;;GAGG;AACH,wBAAgB,iBAAiB,CAC/B,KAAK,EAAE,MAAM,EACb,MAAM,EAAE,MAAM,GACb,MAAM,GAAG,SAAS,CAcpB;AAMD,oDAAoD;AACpD,eAAO,MAAM,WAAW,aAkBtB,CAAC;AAEH,2EAA2E;AAC3E,eAAO,MAAM,eAAe,aAe1B,CAAC;AAEH,wDAAwD;AACxD,eAAO,MAAM,mBAAmB,aAQ9B,CAAC;AAEH;;;GAGG;AACH,wBAAgB,eAAe,CAAC,KAAK,EAAE,OAAO,EAAE,GAAG,OAAO,CAQzD;AAED;;GAEG;AACH,wBAAgB,UAAU,CAAC,GAAG,EAAE,MAAM,EAAE,OAAO,CAAC,EAAE,MAAM,GAAG,MAAM,CAMhE;AAED;;GAEG;AACH,wBAAgB,YAAY,CAAC,IAAI,EAAE,OAAO,GAAG,IAAI,IAAI,UAAU,CAE9D;AAED;;GAEG;AACH,wBAAgB,kBAAkB,CAAC,KAAK,EAAE,OAAO,EAAE,GAAG,MAAM,CAc3D"}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import type { DOMNode } from '../types';
|
|
2
|
+
/**
|
|
3
|
+
* Recursively sanitize a DOM tree:
|
|
4
|
+
* - Remove dangerous tags entirely (including children)
|
|
5
|
+
* - Strip ALL event handler attributes (any attribute starting with `on`)
|
|
6
|
+
* - Neutralize dangerous URLs in all URL-bearing attributes
|
|
7
|
+
* - Guard against prototype pollution via attribute keys
|
|
8
|
+
* - Enforce a max recursion depth to prevent stack overflow
|
|
9
|
+
*/
|
|
10
|
+
export declare function sanitizeDOM(nodes: DOMNode[], depth?: number): DOMNode[];
|
|
11
|
+
//# sourceMappingURL=sanitize.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"sanitize.d.ts","sourceRoot":"","sources":["../../../../src/utils/sanitize.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,OAAO,EAAc,MAAM,UAAU,CAAC;AAuFpD;;;;;;;GAOG;AACH,wBAAgB,WAAW,CAAC,KAAK,EAAE,OAAO,EAAE,EAAE,KAAK,GAAE,MAAU,GAAG,OAAO,EAAE,CAqD1E"}
|
package/package.json
ADDED
|
@@ -0,0 +1,171 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@neeleshyadav/react-native-html-renderer",
|
|
3
|
+
"version": "1.1.0",
|
|
4
|
+
"description": "Renders HTML into 100% native React Native views — actively maintained, TypeScript-first.",
|
|
5
|
+
"main": "./lib/module/index.js",
|
|
6
|
+
"types": "./lib/typescript/src/index.d.ts",
|
|
7
|
+
"exports": {
|
|
8
|
+
".": {
|
|
9
|
+
"source": "./src/index.tsx",
|
|
10
|
+
"types": "./lib/typescript/src/index.d.ts",
|
|
11
|
+
"default": "./lib/module/index.js"
|
|
12
|
+
},
|
|
13
|
+
"./package.json": "./package.json"
|
|
14
|
+
},
|
|
15
|
+
"files": [
|
|
16
|
+
"src",
|
|
17
|
+
"lib",
|
|
18
|
+
"!**/__tests__",
|
|
19
|
+
"!**/__fixtures__",
|
|
20
|
+
"!**/__mocks__",
|
|
21
|
+
"!**/.*"
|
|
22
|
+
],
|
|
23
|
+
"scripts": {
|
|
24
|
+
"example": "yarn workspace react-native-html-renderer-example",
|
|
25
|
+
"clean": "del-cli android/build example/android/build example/android/app/build example/ios/build lib",
|
|
26
|
+
"prepare": "bob build",
|
|
27
|
+
"typecheck": "tsc",
|
|
28
|
+
"lint": "eslint \"**/*.{js,ts,tsx}\"",
|
|
29
|
+
"test": "jest",
|
|
30
|
+
"release": "release-it --only-version",
|
|
31
|
+
"web": "vite",
|
|
32
|
+
"build:web": "vite build"
|
|
33
|
+
},
|
|
34
|
+
"keywords": [
|
|
35
|
+
"react-native",
|
|
36
|
+
"html",
|
|
37
|
+
"renderer",
|
|
38
|
+
"render-html",
|
|
39
|
+
"native",
|
|
40
|
+
"views",
|
|
41
|
+
"typescript",
|
|
42
|
+
"ios",
|
|
43
|
+
"android"
|
|
44
|
+
],
|
|
45
|
+
"repository": {
|
|
46
|
+
"type": "git",
|
|
47
|
+
"url": "git+https://github.com/Neelesh-FS-Dev/react-native-html-renderer.git"
|
|
48
|
+
},
|
|
49
|
+
"author": "Neelesh Yadav <neeleshy263@gmail.com> (https://github.com/Neelesh-FS-Dev)",
|
|
50
|
+
"license": "MIT",
|
|
51
|
+
"bugs": {
|
|
52
|
+
"url": "https://github.com/Neelesh-FS-Dev/react-native-html-renderer/issues"
|
|
53
|
+
},
|
|
54
|
+
"homepage": "https://github.com/Neelesh-FS-Dev/react-native-html-renderer#readme",
|
|
55
|
+
"publishConfig": {
|
|
56
|
+
"registry": "https://registry.npmjs.org/"
|
|
57
|
+
},
|
|
58
|
+
"devDependencies": {
|
|
59
|
+
"@commitlint/config-conventional": "^20.5.0",
|
|
60
|
+
"@eslint/compat": "^2.0.3",
|
|
61
|
+
"@eslint/eslintrc": "^3.3.5",
|
|
62
|
+
"@eslint/js": "^10.0.1",
|
|
63
|
+
"@jest/globals": "^30.0.0",
|
|
64
|
+
"@react-native/babel-preset": "0.84.1",
|
|
65
|
+
"@react-native/eslint-config": "0.84.1",
|
|
66
|
+
"@release-it/conventional-changelog": "^10.0.6",
|
|
67
|
+
"@testing-library/react-native": "^13.3.3",
|
|
68
|
+
"@types/react": "^19.2.0",
|
|
69
|
+
"@types/react-test-renderer": "^19",
|
|
70
|
+
"commitlint": "^20.5.0",
|
|
71
|
+
"del-cli": "^7.0.0",
|
|
72
|
+
"eslint": "^9.39.4",
|
|
73
|
+
"eslint-config-prettier": "^10.1.8",
|
|
74
|
+
"eslint-plugin-ft-flow": "^3.0.11",
|
|
75
|
+
"eslint-plugin-prettier": "^5.5.5",
|
|
76
|
+
"jest": "^30.3.0",
|
|
77
|
+
"lefthook": "^2.1.4",
|
|
78
|
+
"prettier": "^3.8.1",
|
|
79
|
+
"react": "19.2.4",
|
|
80
|
+
"react-native": "0.84.1",
|
|
81
|
+
"react-native-builder-bob": "^0.41.0",
|
|
82
|
+
"react-native-web": "~0.21.1",
|
|
83
|
+
"react-test-renderer": "19.2.4",
|
|
84
|
+
"release-it": "^19.2.4",
|
|
85
|
+
"turbo": "^2.8.21",
|
|
86
|
+
"typescript": "^6.0.2"
|
|
87
|
+
},
|
|
88
|
+
"peerDependencies": {
|
|
89
|
+
"react": ">=18.0.0",
|
|
90
|
+
"react-native": ">=0.71.0"
|
|
91
|
+
},
|
|
92
|
+
"workspaces": [
|
|
93
|
+
"example"
|
|
94
|
+
],
|
|
95
|
+
"packageManager": "yarn@4.11.0",
|
|
96
|
+
"react-native-builder-bob": {
|
|
97
|
+
"source": "src",
|
|
98
|
+
"output": "lib",
|
|
99
|
+
"targets": [
|
|
100
|
+
[
|
|
101
|
+
"module",
|
|
102
|
+
{
|
|
103
|
+
"esm": true
|
|
104
|
+
}
|
|
105
|
+
],
|
|
106
|
+
[
|
|
107
|
+
"typescript",
|
|
108
|
+
{
|
|
109
|
+
"project": "tsconfig.build.json"
|
|
110
|
+
}
|
|
111
|
+
]
|
|
112
|
+
]
|
|
113
|
+
},
|
|
114
|
+
"prettier": {
|
|
115
|
+
"quoteProps": "consistent",
|
|
116
|
+
"singleQuote": true,
|
|
117
|
+
"tabWidth": 2,
|
|
118
|
+
"trailingComma": "es5",
|
|
119
|
+
"useTabs": false
|
|
120
|
+
},
|
|
121
|
+
"jest": {
|
|
122
|
+
"preset": "react-native",
|
|
123
|
+
"modulePathIgnorePatterns": [
|
|
124
|
+
"<rootDir>/example/node_modules",
|
|
125
|
+
"<rootDir>/lib/"
|
|
126
|
+
],
|
|
127
|
+
"transformIgnorePatterns": [
|
|
128
|
+
"node_modules/(?!(react-native|@react-native|htmlparser2|dom-serializer|domelementtype|domhandler|domutils|entities|css-to-react-native|css-color-keywords|postcss-value-parser)/)"
|
|
129
|
+
]
|
|
130
|
+
},
|
|
131
|
+
"commitlint": {
|
|
132
|
+
"extends": [
|
|
133
|
+
"@commitlint/config-conventional"
|
|
134
|
+
]
|
|
135
|
+
},
|
|
136
|
+
"release-it": {
|
|
137
|
+
"git": {
|
|
138
|
+
"commitMessage": "chore: release ${version}",
|
|
139
|
+
"tagName": "v${version}"
|
|
140
|
+
},
|
|
141
|
+
"npm": {
|
|
142
|
+
"publish": true
|
|
143
|
+
},
|
|
144
|
+
"github": {
|
|
145
|
+
"release": true
|
|
146
|
+
},
|
|
147
|
+
"plugins": {
|
|
148
|
+
"@release-it/conventional-changelog": {
|
|
149
|
+
"preset": {
|
|
150
|
+
"name": "angular"
|
|
151
|
+
}
|
|
152
|
+
}
|
|
153
|
+
}
|
|
154
|
+
},
|
|
155
|
+
"create-react-native-library": {
|
|
156
|
+
"type": "library",
|
|
157
|
+
"languages": "js",
|
|
158
|
+
"tools": [
|
|
159
|
+
"eslint",
|
|
160
|
+
"jest",
|
|
161
|
+
"lefthook",
|
|
162
|
+
"release-it",
|
|
163
|
+
"vite"
|
|
164
|
+
],
|
|
165
|
+
"version": "0.59.0"
|
|
166
|
+
},
|
|
167
|
+
"dependencies": {
|
|
168
|
+
"css-to-react-native": "^3.2.0",
|
|
169
|
+
"htmlparser2": "^12.0.0"
|
|
170
|
+
}
|
|
171
|
+
}
|