@khairold/xml-render 0.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.
Files changed (58) hide show
  1. package/README.md +372 -0
  2. package/dist/index.d.ts +33 -0
  3. package/dist/index.d.ts.map +1 -0
  4. package/dist/index.js +41 -0
  5. package/dist/index.js.map +1 -0
  6. package/dist/parser.d.ts +129 -0
  7. package/dist/parser.d.ts.map +1 -0
  8. package/dist/parser.js +321 -0
  9. package/dist/parser.js.map +1 -0
  10. package/dist/react/ErrorBoundary.d.ts +56 -0
  11. package/dist/react/ErrorBoundary.d.ts.map +1 -0
  12. package/dist/react/ErrorBoundary.js +69 -0
  13. package/dist/react/ErrorBoundary.js.map +1 -0
  14. package/dist/react/XmlRender.d.ts +62 -0
  15. package/dist/react/XmlRender.d.ts.map +1 -0
  16. package/dist/react/XmlRender.js +90 -0
  17. package/dist/react/XmlRender.js.map +1 -0
  18. package/dist/react/catalog.d.ts +99 -0
  19. package/dist/react/catalog.d.ts.map +1 -0
  20. package/dist/react/catalog.js +55 -0
  21. package/dist/react/catalog.js.map +1 -0
  22. package/dist/react/context.d.ts +66 -0
  23. package/dist/react/context.d.ts.map +1 -0
  24. package/dist/react/context.js +63 -0
  25. package/dist/react/context.js.map +1 -0
  26. package/dist/react/index.d.ts +35 -0
  27. package/dist/react/index.d.ts.map +1 -0
  28. package/dist/react/index.js +41 -0
  29. package/dist/react/index.js.map +1 -0
  30. package/dist/react-native/ErrorBoundary.d.ts +60 -0
  31. package/dist/react-native/ErrorBoundary.d.ts.map +1 -0
  32. package/dist/react-native/ErrorBoundary.js +84 -0
  33. package/dist/react-native/ErrorBoundary.js.map +1 -0
  34. package/dist/react-native/XmlRender.d.ts +62 -0
  35. package/dist/react-native/XmlRender.d.ts.map +1 -0
  36. package/dist/react-native/XmlRender.js +91 -0
  37. package/dist/react-native/XmlRender.js.map +1 -0
  38. package/dist/react-native/catalog.d.ts +100 -0
  39. package/dist/react-native/catalog.d.ts.map +1 -0
  40. package/dist/react-native/catalog.js +56 -0
  41. package/dist/react-native/catalog.js.map +1 -0
  42. package/dist/react-native/context.d.ts +66 -0
  43. package/dist/react-native/context.d.ts.map +1 -0
  44. package/dist/react-native/context.js +63 -0
  45. package/dist/react-native/context.js.map +1 -0
  46. package/dist/react-native/index.d.ts +35 -0
  47. package/dist/react-native/index.d.ts.map +1 -0
  48. package/dist/react-native/index.js +41 -0
  49. package/dist/react-native/index.js.map +1 -0
  50. package/dist/registry.d.ts +99 -0
  51. package/dist/registry.d.ts.map +1 -0
  52. package/dist/registry.js +93 -0
  53. package/dist/registry.js.map +1 -0
  54. package/dist/types.d.ts +436 -0
  55. package/dist/types.d.ts.map +1 -0
  56. package/dist/types.js +28 -0
  57. package/dist/types.js.map +1 -0
  58. package/package.json +60 -0
@@ -0,0 +1,91 @@
1
+ import { jsx as _jsx } from "react/jsx-runtime";
2
+ import { View, Text } from "react-native";
3
+ import { useXmlRenderContext } from "./context";
4
+ import { ErrorBoundary } from "./ErrorBoundary";
5
+ /**
6
+ * Default text renderer - renders plain text in a Text component
7
+ */
8
+ function DefaultTextRenderer({ segment, }) {
9
+ return _jsx(Text, { children: segment.content });
10
+ }
11
+ /**
12
+ * Default fallback renderer for unknown segment types
13
+ */
14
+ function DefaultFallback({ segment, }) {
15
+ // In development, show a warning; in production, render content as text
16
+ if (process.env.NODE_ENV === "development") {
17
+ console.warn(`XmlRender: No renderer found for segment type "${String(segment.type)}"`);
18
+ }
19
+ return _jsx(Text, { children: segment.content });
20
+ }
21
+ /**
22
+ * Render a single segment using the catalog (without key or ErrorBoundary wrapper)
23
+ */
24
+ function renderSegmentContent(segment, index, catalog, fallback) {
25
+ const segmentType = segment.type;
26
+ // Handle text segments
27
+ if (segmentType === "text") {
28
+ const TextRenderer = catalog.getTextRenderer();
29
+ if (TextRenderer) {
30
+ return (_jsx(TextRenderer, { segment: segment, index: index }));
31
+ }
32
+ return _jsx(DefaultTextRenderer, { segment: segment });
33
+ }
34
+ // Handle registered tag segments
35
+ const Renderer = catalog.getRenderer(segmentType);
36
+ if (Renderer) {
37
+ return _jsx(Renderer, { segment: segment, index: index });
38
+ }
39
+ // Use fallback for unknown segment types
40
+ if (fallback) {
41
+ return fallback(segment, index);
42
+ }
43
+ return _jsx(DefaultFallback, { segment: segment });
44
+ }
45
+ /**
46
+ * Renders an array of parsed XML segments using the component catalog.
47
+ *
48
+ * Each segment is matched to its corresponding renderer component from the catalog.
49
+ * Text segments use the catalog's text renderer or a default Text component renderer.
50
+ * Unknown segment types use the fallback prop or render content as plain text.
51
+ *
52
+ * @example
53
+ * ```tsx
54
+ * import { XmlRender, XmlRenderProvider } from '@aura/xml-render/react-native';
55
+ * import { createParser } from '@aura/xml-render';
56
+ * import { registry, catalog } from './xml-config';
57
+ *
58
+ * function RichContent({ text }: { text: string }) {
59
+ * const parser = createParser(registry);
60
+ * const segments = parser.parse(text);
61
+ *
62
+ * return (
63
+ * <XmlRenderProvider catalog={catalog}>
64
+ * <XmlRender segments={segments} />
65
+ * </XmlRenderProvider>
66
+ * );
67
+ * }
68
+ * ```
69
+ *
70
+ * @example With custom fallback
71
+ * ```tsx
72
+ * <XmlRender
73
+ * segments={segments}
74
+ * fallback={(segment, index) => (
75
+ * <View style={styles.unknownSegment}>
76
+ * <Text>Unknown: {segment.type} - {segment.content}</Text>
77
+ * </View>
78
+ * )}
79
+ * />
80
+ * ```
81
+ */
82
+ export function XmlRender({ segments, fallback, catalog: catalogProp, errorFallback, }) {
83
+ // Use provided catalog or get from context
84
+ const contextValue = catalogProp ? null : useXmlRenderContext();
85
+ const catalog = catalogProp ?? contextValue?.catalog;
86
+ if (!catalog) {
87
+ throw new Error("XmlRender requires a catalog prop or must be used within XmlRenderProvider");
88
+ }
89
+ return (_jsx(View, { children: segments.map((segment, index) => (_jsx(ErrorBoundary, { segmentType: String(segment.type), fallback: errorFallback, children: renderSegmentContent(segment, index, catalog, fallback) }, index))) }));
90
+ }
91
+ //# sourceMappingURL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CAAC,WAA0B,CAAC,CAAC;IACjE,IAAI,QAAQ,EAAE,CAAC;QACb,OAAO,KAAC,QAAQ,IAAC,OAAO,EAAE,OAA4C,EAAE,KAAK,EAAE,KAAK,GAAI,CAAC;IAC3F,CAAC;IAED,yCAAyC;IACzC,IAAI,QAAQ,EAAE,CAAC;QACb,OAAO,QAAQ,CAAC,OAAO,EAAE,KAAK,CAAC,CAAC;IAClC,CAAC;IAED,OAAO,KAAC,eAAe,IAAC,OAAO,EAAE,OAAO,GAAI,CAAC;AAC/C,CAAC;AAED;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAoCG;AACH,MAAM,UAAU,SAAS,CAA+B,EACtD,QAAQ,EACR,QAAQ,EACR,OAAO,EAAE,WAAW,EACpB,aAAa,GACS;IACtB,2CAA2C;IAC3C,MAAM,YAAY,GAAG,WAAW,CAAC,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC,mBAAmB,EAAS,CAAC;IACvE,MAAM,OAAO,GAAG,WAAW,IAAI,YAAY,EAAE,OAAO,CAAC;IAErD,IAAI,CAAC,OAAO,EAAE,CAAC;QACb,MAAM,IAAI,KAAK,CACb,4EAA4E,CAC7E,CAAC;IACJ,CAAC;IAED,OAAO,CACL,KAAC,IAAI,cACF,QAAQ,CAAC,GAAG,CAAC,CAAC,OAAO,EAAE,KAAK,EAAE,EAAE,CAAC,CAChC,KAAC,aAAa,IAEZ,WAAW,EAAE,MAAM,CAAC,OAAO,CAAC,IAAI,CAAC,EACjC,QAAQ,EAAE,aAAa,YAEtB,oBAAoB,CAAC,OAAO,EAAE,KAAK,EAAE,OAAO,EAAE,QAAQ,CAAC,IAJnD,KAAK,CAKI,CACjB,CAAC,GACG,CACR,CAAC;AACJ,CAAC"}
@@ -0,0 +1,100 @@
1
+ /**
2
+ * Component Catalog for React Native XML Renderer
3
+ *
4
+ * Creates a type-safe mapping from segment types to React Native components.
5
+ * The catalog ensures that each registered tag type has a corresponding
6
+ * renderer component with properly typed props.
7
+ */
8
+ import type { ComponentType } from "react";
9
+ import type { TagDefinitions, Registry } from "../registry";
10
+ import type { ParsedSegment } from "../parser";
11
+ /**
12
+ * Props passed to segment renderer components
13
+ */
14
+ export interface SegmentProps<TDefs extends TagDefinitions, TType extends keyof TDefs | "text"> {
15
+ /** The segment being rendered */
16
+ segment: ParsedSegment<TDefs, TType>;
17
+ /** Index of this segment in the segments array */
18
+ index: number;
19
+ }
20
+ /**
21
+ * Props for the text segment renderer
22
+ */
23
+ export interface TextSegmentProps<TDefs extends TagDefinitions> {
24
+ segment: ParsedSegment<TDefs, "text">;
25
+ index: number;
26
+ }
27
+ /**
28
+ * A component that renders a specific segment type
29
+ */
30
+ export type SegmentRenderer<TDefs extends TagDefinitions, TType extends keyof TDefs> = ComponentType<SegmentProps<TDefs, TType>>;
31
+ /**
32
+ * A component that renders text segments
33
+ */
34
+ export type TextRenderer<TDefs extends TagDefinitions> = ComponentType<TextSegmentProps<TDefs>>;
35
+ /**
36
+ * Component definitions for the catalog - maps tag names to renderers
37
+ */
38
+ export type CatalogComponents<TDefs extends TagDefinitions> = {
39
+ [K in keyof TDefs]: SegmentRenderer<TDefs, K>;
40
+ };
41
+ /**
42
+ * The catalog interface returned by createCatalog
43
+ */
44
+ export interface Catalog<TDefs extends TagDefinitions> {
45
+ /** Get the renderer component for a specific segment type */
46
+ getRenderer<K extends keyof TDefs>(type: K): SegmentRenderer<TDefs, K> | undefined;
47
+ /** Get the text segment renderer */
48
+ getTextRenderer(): TextRenderer<TDefs> | undefined;
49
+ /** Check if a renderer exists for a segment type */
50
+ hasRenderer(type: keyof TDefs | "text"): boolean;
51
+ /** The registry this catalog is based on */
52
+ readonly registry: Registry<TDefs>;
53
+ /** All registered component renderers */
54
+ readonly components: Readonly<Partial<CatalogComponents<TDefs>>>;
55
+ }
56
+ /**
57
+ * Options for creating a catalog
58
+ */
59
+ export interface CatalogOptions<TDefs extends TagDefinitions> {
60
+ /** Component renderers for each tag type */
61
+ components: Partial<CatalogComponents<TDefs>>;
62
+ /** Optional text segment renderer (default renders plain text in a Text component) */
63
+ textRenderer?: TextRenderer<TDefs>;
64
+ }
65
+ /**
66
+ * Create a component catalog for rendering XML segments in React Native.
67
+ *
68
+ * The catalog maps registered tag types to React Native components that render them.
69
+ * TypeScript ensures that component props match the tag's attribute schema.
70
+ *
71
+ * @example
72
+ * ```tsx
73
+ * import { createCatalog } from '@aura/xml-render/react-native';
74
+ * import { View, Text } from 'react-native';
75
+ * import { registry } from './xml-registry';
76
+ *
77
+ * const catalog = createCatalog(registry, {
78
+ * components: {
79
+ * callout: ({ segment }) => (
80
+ * <View style={styles.callout}>
81
+ * <Text>{segment.content}</Text>
82
+ * </View>
83
+ * ),
84
+ * chart: ({ segment }) => (
85
+ * <ChartComponent
86
+ * type={segment.attributes?.type}
87
+ * data={segment.content}
88
+ * />
89
+ * ),
90
+ * },
91
+ * textRenderer: ({ segment }) => <Text>{segment.content}</Text>,
92
+ * });
93
+ * ```
94
+ *
95
+ * @param registry - The tag registry defining valid segment types
96
+ * @param options - Component renderers and optional text renderer
97
+ * @returns A catalog instance for use with XmlRenderProvider
98
+ */
99
+ export declare function createCatalog<TDefs extends TagDefinitions>(registry: Registry<TDefs>, options: CatalogOptions<TDefs>): Catalog<TDefs>;
100
+ //# sourceMappingURL=catalog.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"catalog.d.ts","sourceRoot":"","sources":["../../src/react-native/catalog.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AACH,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,OAAO,CAAC;AAC3C,OAAO,KAAK,EACV,cAAc,EACd,QAAQ,EAET,MAAM,aAAa,CAAC;AACrB,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,WAAW,CAAC;AAE/C;;GAEG;AACH,MAAM,WAAW,YAAY,CAC3B,KAAK,SAAS,cAAc,EAC5B,KAAK,SAAS,MAAM,KAAK,GAAG,MAAM;IAElC,iCAAiC;IACjC,OAAO,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AC,CAAC,CAAC;CAClE;AAED;;GAEG;AACH,MAAM,WAAW,cAAc,CAAC,KAAK,SAAS,cAAc;IAC1D,4CAA4C;IAC5C,UAAU,EAAE,OAAO,CAAC,iBAAiB,CAAC,KAAK,CAAC,CAAC,CAAC;IAC9C,sFAAsF;IACtF,YAAY,CAAC,EAAE,YAAY,CAAC,KAAK,CAAC,CAAC;CACpC;AAED;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAiCG;AACH,wBAAgB,aAAa,CAAC,KAAK,SAAS,cAAc,EACxD,QAAQ,EAAE,QAAQ,CAAC,KAAK,CAAC,EACzB,OAAO,EAAE,cAAc,CAAC,KAAK,CAAC,GAC7B,OAAO,CAAC,KAAK,CAAC,CA4BhB"}
@@ -0,0 +1,56 @@
1
+ /**
2
+ * Create a component catalog for rendering XML segments in React Native.
3
+ *
4
+ * The catalog maps registered tag types to React Native components that render them.
5
+ * TypeScript ensures that component props match the tag's attribute schema.
6
+ *
7
+ * @example
8
+ * ```tsx
9
+ * import { createCatalog } from '@aura/xml-render/react-native';
10
+ * import { View, Text } from 'react-native';
11
+ * import { registry } from './xml-registry';
12
+ *
13
+ * const catalog = createCatalog(registry, {
14
+ * components: {
15
+ * callout: ({ segment }) => (
16
+ * <View style={styles.callout}>
17
+ * <Text>{segment.content}</Text>
18
+ * </View>
19
+ * ),
20
+ * chart: ({ segment }) => (
21
+ * <ChartComponent
22
+ * type={segment.attributes?.type}
23
+ * data={segment.content}
24
+ * />
25
+ * ),
26
+ * },
27
+ * textRenderer: ({ segment }) => <Text>{segment.content}</Text>,
28
+ * });
29
+ * ```
30
+ *
31
+ * @param registry - The tag registry defining valid segment types
32
+ * @param options - Component renderers and optional text renderer
33
+ * @returns A catalog instance for use with XmlRenderProvider
34
+ */
35
+ export function createCatalog(registry, options) {
36
+ const { components, textRenderer } = options;
37
+ const frozenComponents = Object.freeze({ ...components });
38
+ const catalog = {
39
+ registry,
40
+ components: frozenComponents,
41
+ getRenderer(type) {
42
+ return frozenComponents[type];
43
+ },
44
+ getTextRenderer() {
45
+ return textRenderer;
46
+ },
47
+ hasRenderer(type) {
48
+ if (type === "text") {
49
+ return textRenderer !== undefined;
50
+ }
51
+ return type in frozenComponents;
52
+ },
53
+ };
54
+ return Object.freeze(catalog);
55
+ }
56
+ //# sourceMappingURL=catalog.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"catalog.js","sourceRoot":"","sources":["../../src/react-native/catalog.ts"],"names":[],"mappings":"AAwFA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAiCG;AACH,MAAM,UAAU,aAAa,CAC3B,QAAyB,EACzB,OAA8B;IAE9B,MAAM,EAAE,UAAU,EAAE,YAAY,EAAE,GAAG,OAAO,CAAC;IAE7C,MAAM,gBAAgB,GAAG,MAAM,CAAC,MAAM,CAAC,EAAE,GAAG,UAAU,EAAE,CAEvD,CAAC;IAEF,MAAM,OAAO,GAAmB;QAC9B,QAAQ;QACR,UAAU,EAAE,gBAAgB;QAE5B,WAAW,CAAwB,IAAO;YACxC,OAAO,gBAAgB,CAAC,IAAI,CAA0C,CAAC;QACzE,CAAC;QAED,eAAe;YACb,OAAO,YAAY,CAAC;QACtB,CAAC;QAED,WAAW,CAAC,IAA0B;YACpC,IAAI,IAAI,KAAK,MAAM,EAAE,CAAC;gBACpB,OAAO,YAAY,KAAK,SAAS,CAAC;YACpC,CAAC;YACD,OAAO,IAAI,IAAI,gBAAgB,CAAC;QAClC,CAAC;KACF,CAAC;IAEF,OAAO,MAAM,CAAC,MAAM,CAAC,OAAO,CAAC,CAAC;AAChC,CAAC"}
@@ -0,0 +1,66 @@
1
+ /**
2
+ * React Native Context for XML Render
3
+ *
4
+ * Provides the component catalog to the render tree via React Context.
5
+ * This allows XmlRender components to access the catalog without prop drilling.
6
+ */
7
+ import React, { type ReactNode } from "react";
8
+ import type { TagDefinitions } from "../registry";
9
+ import type { Catalog } from "./catalog";
10
+ /**
11
+ * Context value type containing the catalog
12
+ */
13
+ interface XmlRenderContextValue<TDefs extends TagDefinitions> {
14
+ catalog: Catalog<TDefs>;
15
+ }
16
+ /**
17
+ * Props for XmlRenderProvider
18
+ */
19
+ export interface XmlRenderProviderProps<TDefs extends TagDefinitions> {
20
+ /** The component catalog to provide to the tree */
21
+ catalog: Catalog<TDefs>;
22
+ /** Child components that can use XmlRender */
23
+ children: ReactNode;
24
+ }
25
+ /**
26
+ * Provider component that makes the catalog available to XmlRender components.
27
+ *
28
+ * Wrap your application or component tree with this provider to enable
29
+ * XML segment rendering in React Native.
30
+ *
31
+ * @example
32
+ * ```tsx
33
+ * import { XmlRenderProvider } from '@aura/xml-render/react-native';
34
+ * import { catalog } from './xml-catalog';
35
+ *
36
+ * function App() {
37
+ * return (
38
+ * <XmlRenderProvider catalog={catalog}>
39
+ * <MyContent />
40
+ * </XmlRenderProvider>
41
+ * );
42
+ * }
43
+ * ```
44
+ */
45
+ export declare function XmlRenderProvider<TDefs extends TagDefinitions>({ catalog, children, }: XmlRenderProviderProps<TDefs>): React.ReactElement;
46
+ /**
47
+ * Hook to access the XML render catalog from context.
48
+ *
49
+ * Must be used within an XmlRenderProvider.
50
+ *
51
+ * @throws Error if used outside of XmlRenderProvider
52
+ * @returns The current catalog from context
53
+ *
54
+ * @example
55
+ * ```tsx
56
+ * import { useXmlRenderContext } from '@aura/xml-render/react-native';
57
+ *
58
+ * function CustomRenderer() {
59
+ * const { catalog } = useXmlRenderContext();
60
+ * // Use catalog to look up renderers...
61
+ * }
62
+ * ```
63
+ */
64
+ export declare function useXmlRenderContext<TDefs extends TagDefinitions = TagDefinitions>(): XmlRenderContextValue<TDefs>;
65
+ export {};
66
+ //# sourceMappingURL=context.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"context.d.ts","sourceRoot":"","sources":["../../src/react-native/context.tsx"],"names":[],"mappings":"AAAA;;;;;GAKG;AACH,OAAO,KAAK,EAAE,EAA6B,KAAK,SAAS,EAAE,MAAM,OAAO,CAAC;AACzE,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,aAAa,CAAC;AAClD,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,WAAW,CAAC;AAEzC;;GAEG;AACH,UAAU,qBAAqB,CAAC,KAAK,SAAS,cAAc;IAC1D,OAAO,EAAE,OAAO,CAAC,KAAK,CAAC,CAAC;CACzB;AAeD;;GAEG;AACH,MAAM,WAAW,sBAAsB,CAAC,KAAK,SAAS,cAAc;IAClE,mDAAmD;IACnD,OAAO,EAAE,OAAO,CAAC,KAAK,CAAC,CAAC;IACxB,8CAA8C;IAC9C,QAAQ,EAAE,SAAS,CAAC;CACrB;AAED;;;;;;;;;;;;;;;;;;;GAmBG;AACH,wBAAgB,iBAAiB,CAAC,KAAK,SAAS,cAAc,EAAE,EAC9D,OAAO,EACP,QAAQ,GACT,EAAE,sBAAsB,CAAC,KAAK,CAAC,GAAG,KAAK,CAAC,YAAY,CAQpD;AAED;;;;;;;;;;;;;;;;;GAiBG;AACH,wBAAgB,mBAAmB,CACjC,KAAK,SAAS,cAAc,GAAG,cAAc,KAC1C,qBAAqB,CAAC,KAAK,CAAC,CAWhC"}
@@ -0,0 +1,63 @@
1
+ import { jsx as _jsx } from "react/jsx-runtime";
2
+ /**
3
+ * React Native Context for XML Render
4
+ *
5
+ * Provides the component catalog to the render tree via React Context.
6
+ * This allows XmlRender components to access the catalog without prop drilling.
7
+ */
8
+ import { createContext, useContext } from "react";
9
+ /**
10
+ * Internal context - stores catalog as unknown, typed at provider/consumer level
11
+ */
12
+ const XmlRenderContext = createContext(null);
13
+ /**
14
+ * Provider component that makes the catalog available to XmlRender components.
15
+ *
16
+ * Wrap your application or component tree with this provider to enable
17
+ * XML segment rendering in React Native.
18
+ *
19
+ * @example
20
+ * ```tsx
21
+ * import { XmlRenderProvider } from '@aura/xml-render/react-native';
22
+ * import { catalog } from './xml-catalog';
23
+ *
24
+ * function App() {
25
+ * return (
26
+ * <XmlRenderProvider catalog={catalog}>
27
+ * <MyContent />
28
+ * </XmlRenderProvider>
29
+ * );
30
+ * }
31
+ * ```
32
+ */
33
+ export function XmlRenderProvider({ catalog, children, }) {
34
+ const value = { catalog };
35
+ return (_jsx(XmlRenderContext.Provider, { value: value, children: children }));
36
+ }
37
+ /**
38
+ * Hook to access the XML render catalog from context.
39
+ *
40
+ * Must be used within an XmlRenderProvider.
41
+ *
42
+ * @throws Error if used outside of XmlRenderProvider
43
+ * @returns The current catalog from context
44
+ *
45
+ * @example
46
+ * ```tsx
47
+ * import { useXmlRenderContext } from '@aura/xml-render/react-native';
48
+ *
49
+ * function CustomRenderer() {
50
+ * const { catalog } = useXmlRenderContext();
51
+ * // Use catalog to look up renderers...
52
+ * }
53
+ * ```
54
+ */
55
+ export function useXmlRenderContext() {
56
+ const context = useContext(XmlRenderContext);
57
+ if (!context) {
58
+ throw new Error("useXmlRenderContext must be used within an XmlRenderProvider");
59
+ }
60
+ // Cast the internal unknown catalog back to the typed version
61
+ return { catalog: context.catalog };
62
+ }
63
+ //# sourceMappingURL=context.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"context.js","sourceRoot":"","sources":["../../src/react-native/context.tsx"],"names":[],"mappings":";AAAA;;;;;GAKG;AACH,OAAc,EAAE,aAAa,EAAE,UAAU,EAAkB,MAAM,OAAO,CAAC;AAmBzE;;GAEG;AACH,MAAM,gBAAgB,GAAG,aAAa,CAA8B,IAAI,CAAC,CAAC;AAY1E;;;;;;;;;;;;;;;;;;;GAmBG;AACH,MAAM,UAAU,iBAAiB,CAA+B,EAC9D,OAAO,EACP,QAAQ,GACsB;IAC9B,MAAM,KAAK,GAAyB,EAAE,OAAO,EAAE,CAAC;IAEhD,OAAO,CACL,KAAC,gBAAgB,CAAC,QAAQ,IAAC,KAAK,EAAE,KAAK,YACpC,QAAQ,GACiB,CAC7B,CAAC;AACJ,CAAC;AAED;;;;;;;;;;;;;;;;;GAiBG;AACH,MAAM,UAAU,mBAAmB;IAGjC,MAAM,OAAO,GAAG,UAAU,CAAC,gBAAgB,CAAC,CAAC;IAE7C,IAAI,CAAC,OAAO,EAAE,CAAC;QACb,MAAM,IAAI,KAAK,CACb,8DAA8D,CAC/D,CAAC;IACJ,CAAC;IAED,8DAA8D;IAC9D,OAAO,EAAE,OAAO,EAAE,OAAO,CAAC,OAAyB,EAAE,CAAC;AACxD,CAAC"}
@@ -0,0 +1,35 @@
1
+ /**
2
+ * @aura/xml-render/react-native - React Native Renderer
3
+ *
4
+ * React Native components for rendering parsed XML segments.
5
+ * Use this entry point for mobile applications.
6
+ *
7
+ * @example
8
+ * ```tsx
9
+ * import { XmlRenderProvider, XmlRender, createCatalog } from '@aura/xml-render/react-native';
10
+ * import { createParser, createRegistry } from '@aura/xml-render';
11
+ *
12
+ * // Create catalog with your component renderers
13
+ * const catalog = createCatalog(registry, {
14
+ * components: {
15
+ * callout: ({ segment }) => <Callout type={segment.attributes?.type}>{segment.content}</Callout>,
16
+ * },
17
+ * });
18
+ *
19
+ * // Render segments
20
+ * <XmlRenderProvider catalog={catalog}>
21
+ * <XmlRender segments={parser.parse(text)} />
22
+ * </XmlRenderProvider>
23
+ * ```
24
+ *
25
+ * @packageDocumentation
26
+ */
27
+ export { createCatalog } from "./catalog";
28
+ export { XmlRenderProvider, useXmlRenderContext } from "./context";
29
+ export { XmlRender } from "./XmlRender";
30
+ export { ErrorBoundary } from "./ErrorBoundary";
31
+ export type { Catalog, CatalogOptions, CatalogComponents, SegmentProps, SegmentRenderer, TextRenderer, TextSegmentProps, } from "./catalog";
32
+ export type { XmlRenderProviderProps } from "./context";
33
+ export type { XmlRenderProps } from "./XmlRender";
34
+ export type { ErrorBoundaryProps } from "./ErrorBoundary";
35
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/react-native/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;GAyBG;AAOH,OAAO,EAAE,aAAa,EAAE,MAAM,WAAW,CAAC;AAO1C,OAAO,EAAE,iBAAiB,EAAE,mBAAmB,EAAE,MAAM,WAAW,CAAC;AAGnE,OAAO,EAAE,SAAS,EAAE,MAAM,aAAa,CAAC;AAGxC,OAAO,EAAE,aAAa,EAAE,MAAM,iBAAiB,CAAC;AAOhD,YAAY,EACV,OAAO,EACP,cAAc,EACd,iBAAiB,EACjB,YAAY,EACZ,eAAe,EACf,YAAY,EACZ,gBAAgB,GACjB,MAAM,WAAW,CAAC;AAGnB,YAAY,EAAE,sBAAsB,EAAE,MAAM,WAAW,CAAC;AAGxD,YAAY,EAAE,cAAc,EAAE,MAAM,aAAa,CAAC;AAGlD,YAAY,EAAE,kBAAkB,EAAE,MAAM,iBAAiB,CAAC"}
@@ -0,0 +1,41 @@
1
+ /**
2
+ * @aura/xml-render/react-native - React Native Renderer
3
+ *
4
+ * React Native components for rendering parsed XML segments.
5
+ * Use this entry point for mobile applications.
6
+ *
7
+ * @example
8
+ * ```tsx
9
+ * import { XmlRenderProvider, XmlRender, createCatalog } from '@aura/xml-render/react-native';
10
+ * import { createParser, createRegistry } from '@aura/xml-render';
11
+ *
12
+ * // Create catalog with your component renderers
13
+ * const catalog = createCatalog(registry, {
14
+ * components: {
15
+ * callout: ({ segment }) => <Callout type={segment.attributes?.type}>{segment.content}</Callout>,
16
+ * },
17
+ * });
18
+ *
19
+ * // Render segments
20
+ * <XmlRenderProvider catalog={catalog}>
21
+ * <XmlRender segments={parser.parse(text)} />
22
+ * </XmlRenderProvider>
23
+ * ```
24
+ *
25
+ * @packageDocumentation
26
+ */
27
+ // ============================================================================
28
+ // Core Functions
29
+ // ============================================================================
30
+ // Catalog - Create component mappings
31
+ export { createCatalog } from "./catalog";
32
+ // ============================================================================
33
+ // Components
34
+ // ============================================================================
35
+ // Provider and consumer hook
36
+ export { XmlRenderProvider, useXmlRenderContext } from "./context";
37
+ // Main render component
38
+ export { XmlRender } from "./XmlRender";
39
+ // Error boundary for safe rendering
40
+ export { ErrorBoundary } from "./ErrorBoundary";
41
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/react-native/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;GAyBG;AAEH,+EAA+E;AAC/E,iBAAiB;AACjB,+EAA+E;AAE/E,sCAAsC;AACtC,OAAO,EAAE,aAAa,EAAE,MAAM,WAAW,CAAC;AAE1C,+EAA+E;AAC/E,aAAa;AACb,+EAA+E;AAE/E,6BAA6B;AAC7B,OAAO,EAAE,iBAAiB,EAAE,mBAAmB,EAAE,MAAM,WAAW,CAAC;AAEnE,wBAAwB;AACxB,OAAO,EAAE,SAAS,EAAE,MAAM,aAAa,CAAC;AAExC,oCAAoC;AACpC,OAAO,EAAE,aAAa,EAAE,MAAM,iBAAiB,CAAC"}
@@ -0,0 +1,99 @@
1
+ /**
2
+ * Tag Registry for XML Render
3
+ *
4
+ * Creates an immutable registry of XML tag definitions with Zod schema validation.
5
+ * TypeScript infers attribute types directly from the Zod schemas.
6
+ */
7
+ import type { ZodType, infer as ZodInfer } from "zod";
8
+ /**
9
+ * Definition for a single XML tag in the registry
10
+ */
11
+ export interface TagDefinition<TSchema extends ZodType = ZodType> {
12
+ /** Zod schema for validating and typing tag attributes */
13
+ schema: TSchema;
14
+ /** Whether the tag contains inner content (default: true) */
15
+ hasContent?: boolean;
16
+ /** Whether the tag is self-closing like <image /> (default: false) */
17
+ selfClosing?: boolean;
18
+ }
19
+ /**
20
+ * Input type for createRegistry - a record of tag names to definitions
21
+ */
22
+ export type TagDefinitions = Record<string, TagDefinition>;
23
+ /**
24
+ * Infer the attribute type from a TagDefinition's Zod schema
25
+ */
26
+ export type InferAttributes<T extends TagDefinition> = ZodInfer<T["schema"]>;
27
+ /**
28
+ * Safe parse result type for validateAttributes
29
+ */
30
+ export type SafeParseResult<T> = {
31
+ success: true;
32
+ data: T;
33
+ } | {
34
+ success: false;
35
+ error: unknown;
36
+ };
37
+ /**
38
+ * The immutable registry type returned by createRegistry
39
+ */
40
+ export interface Registry<TDefs extends TagDefinitions> {
41
+ /** Get all registered tag names */
42
+ readonly tagNames: ReadonlyArray<keyof TDefs & string>;
43
+ /** Get the definition for a specific tag */
44
+ getTag<K extends keyof TDefs>(name: K): Readonly<TDefs[K]> | undefined;
45
+ /** Check if a tag name is registered */
46
+ hasTag(name: string): name is keyof TDefs & string;
47
+ /** Get the Zod schema for a tag's attributes */
48
+ getSchema<K extends keyof TDefs>(name: K): TDefs[K]["schema"] | undefined;
49
+ /** Validate attributes for a tag using its Zod schema */
50
+ validateAttributes<K extends keyof TDefs>(name: K, attributes: unknown): SafeParseResult<InferAttributes<TDefs[K]>>;
51
+ /** Check if a tag is self-closing */
52
+ isSelfClosing<K extends keyof TDefs>(name: K): boolean;
53
+ /** Check if a tag has content */
54
+ hasContent<K extends keyof TDefs>(name: K): boolean;
55
+ /** The raw definitions (frozen) */
56
+ readonly definitions: Readonly<TDefs>;
57
+ }
58
+ /**
59
+ * Create an immutable tag registry from tag definitions.
60
+ *
61
+ * The registry provides type-safe access to tag definitions and their
62
+ * Zod schemas for attribute validation.
63
+ *
64
+ * @example
65
+ * ```ts
66
+ * import { z } from 'zod';
67
+ * import { createRegistry } from '@aura/xml-render';
68
+ *
69
+ * const registry = createRegistry({
70
+ * chart: {
71
+ * schema: z.object({
72
+ * type: z.enum(['bar', 'line', 'pie']),
73
+ * title: z.string().optional(),
74
+ * }),
75
+ * hasContent: true,
76
+ * },
77
+ * image: {
78
+ * schema: z.object({
79
+ * src: z.string(),
80
+ * alt: z.string().optional(),
81
+ * }),
82
+ * selfClosing: true,
83
+ * hasContent: false,
84
+ * },
85
+ * });
86
+ *
87
+ * // TypeScript knows the exact tag names
88
+ * registry.tagNames; // ['chart', 'image']
89
+ *
90
+ * // Attribute types are inferred from Zod schemas
91
+ * type ChartAttrs = InferAttributes<typeof registry.definitions.chart>;
92
+ * // { type: 'bar' | 'line' | 'pie'; title?: string }
93
+ * ```
94
+ *
95
+ * @param definitions - Record of tag names to their definitions
96
+ * @returns An immutable registry instance
97
+ */
98
+ export declare function createRegistry<TDefs extends TagDefinitions>(definitions: TDefs): Registry<TDefs>;
99
+ //# sourceMappingURL=registry.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"registry.d.ts","sourceRoot":"","sources":["../src/registry.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AACH,OAAO,KAAK,EAAE,OAAO,EAAE,KAAK,IAAI,QAAQ,EAAsB,MAAM,KAAK,CAAC;AAE1E;;GAEG;AACH,MAAM,WAAW,aAAa,CAAC,OAAO,SAAS,OAAO,GAAG,OAAO;IAC9D,0DAA0D;IAC1D,MAAM,EAAE,OAAO,CAAC;IAChB,6DAA6D;IAC7D,UAAU,CAAC,EAAE,OAAO,CAAC;IACrB,sEAAsE;IACtE,WAAW,CAAC,EAAE,OAAO,CAAC;CACvB;AAED;;GAEG;AACH,MAAM,MAAM,cAAc,GAAG,MAAM,CAAC,MAAM,EAAE,aAAa,CAAC,CAAC;AAE3D;;GAEG;AACH,MAAM,MAAM,eAAe,CAAC,CAAC,SAAS,aAAa,IAAI,QAAQ,CAAC,CAAC,CAAC,QAAQ,CAAC,CAAC,CAAC;AAE7E;;GAEG;AACH,MAAM,MAAM,eAAe,CAAC,CAAC,IACzB;IAAE,OAAO,EAAE,IAAI,CAAC;IAAC,IAAI,EAAE,CAAC,CAAA;CAAE,GAC1B;IAAE,OAAO,EAAE,KAAK,CAAC;IAAC,KAAK,EAAE,OAAO,CAAA;CAAE,CAAC;AAEvC;;GAEG;AACH,MAAM,WAAW,QAAQ,CAAC,KAAK,SAAS,cAAc;IACpD,mCAAmC;IACnC,QAAQ,CAAC,QAAQ,EAAE,aAAa,CAAC,MAAM,KAAK,GAAG,MAAM,CAAC,CAAC;IAEvD,4CAA4C;IAC5C,MAAM,CAAC,CAAC,SAAS,MAAM,KAAK,EAAE,IAAI,EAAE,CAAC,GAAG,QAAQ,CAAC,KAAK,CAAC,CAAC,C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