@toaq-oss/omni-mdx 1.1.0 → 1.1.1

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/dist/index.js CHANGED
@@ -14,7 +14,7 @@ var parseProps = (propValue) => {
14
14
  }
15
15
  if (val.startsWith("[") && val.endsWith("]") || val.startsWith("{") && val.endsWith("}")) {
16
16
  try {
17
- return new Function(`return ${val}`)();
17
+ return JSON.parse(val);
18
18
  } catch {
19
19
  return propValue;
20
20
  }
package/dist/index.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"sources":["../src/utils/parserHelpers.ts","../src/index.ts"],"sourcesContent":["/**\n * Parses a stringified JSX property value into its native JavaScript type.\n *\n * Useful in custom components that receive props from the MDX AST —\n * especially for expression attributes like `data={[1, 2, 3]}` or `config={{ a: 1 }}`.\n *\n * @param propValue - Raw property value from the Rust AST (may be a string representation)\n * @returns Parsed JS value — object, array, boolean, number, or original string as fallback\n */\nexport const parseProps = (propValue: any): any => {\n if (typeof propValue !== \"string\") return propValue;\n \n const cleanVal = propValue.trim();\n \n // Primitives\n if (cleanVal === \"true\") return true;\n if (cleanVal === \"false\") return false;\n if (cleanVal !== \"\" && !isNaN(Number(cleanVal))) return Number(cleanVal);\n \n // Unwrap double JSX braces: {{ a: 1 }} → { a: 1 }\n let val = cleanVal;\n if (val.startsWith(\"{\") && val.endsWith(\"}\")) {\n const inner = val.slice(1, -1).trim();\n if (\n (inner.startsWith(\"[\") && inner.endsWith(\"]\")) ||\n (inner.startsWith(\"{\") && inner.endsWith(\"}\"))\n ) {\n val = inner;\n }\n }\n \n // Evaluate arrays and objects (relaxed JS syntax, not strict JSON)\n if (\n (val.startsWith(\"[\") && val.endsWith(\"]\")) ||\n (val.startsWith(\"{\") && val.endsWith(\"}\"))\n ) {\n try {\n return new Function(`return ${val}`)();\n } catch {\n return propValue;\n }\n }\n \n return propValue;\n};\n ","/**\n * @toaq/omni-mdx\n *\n * Safe entry point — types only; no server/native/wasm imports.\n * To parse and render, use:\n * import { parseMdx, MDXServerRenderer } from '@toaq/omni-mdx/server'\n * import { MDXClientRenderer } from '@toaq/omni-mdx/client'\n */\n\nimport React from \"react\";\n\n// Types only (no runtime imports)\nexport type { AstNode, AttrValueKind, MDXComponents } from \"./types/MdxAST\";\nexport type {\n MdxInput\n} from './types/MdxInput';\n\n// Component registry (empty by default; to be expanded)\nexport const MDX_COMPONENTS: Record<string, React.ComponentType<any>> = {};\n\n// Utility for parsing props in custom components\nexport { parseProps } from \"./utils/parserHelpers\";"],"mappings":";AASO,IAAM,aAAa,CAAC,cAAwB;AACjD,MAAI,OAAO,cAAc,SAAU,QAAO;AAE1C,QAAM,WAAW,UAAU,KAAK;AAGhC,MAAI,aAAa,OAAS,QAAO;AACjC,MAAI,aAAa,QAAS,QAAO;AACjC,MAAI,aAAa,MAAM,CAAC,MAAM,OAAO,QAAQ,CAAC,EAAG,QAAO,OAAO,QAAQ;AAGvE,MAAI,MAAM;AACV,MAAI,IAAI,WAAW,GAAG,KAAK,IAAI,SAAS,GAAG,GAAG;AAC5C,UAAM,QAAQ,IAAI,MAAM,GAAG,EAAE,EAAE,KAAK;AACpC,QACG,MAAM,WAAW,GAAG,KAAK,MAAM,SAAS,GAAG,KAC3C,MAAM,WAAW,GAAG,KAAK,MAAM,SAAS,GAAG,GAC5C;AACA,YAAM;AAAA,IACR;AAAA,EACF;AAGA,MACG,IAAI,WAAW,GAAG,KAAK,IAAI,SAAS,GAAG,KACvC,IAAI,WAAW,GAAG,KAAK,IAAI,SAAS,GAAG,GACxC;AACA,QAAI;AACF,aAAO,IAAI,SAAS,UAAU,GAAG,EAAE,EAAE;AAAA,IACvC,QAAQ;AACN,aAAO;AAAA,IACT;AAAA,EACF;AAEA,SAAO;AACT;;;AC1BO,IAAM,iBAA2D,CAAC;","names":[]}
1
+ {"version":3,"sources":["../src/utils/parserHelpers.ts","../src/index.ts"],"sourcesContent":["/**\n * Parses a stringified JSX property value into its native JavaScript type.\n *\n * Useful in custom components that receive props from the MDX AST —\n * especially for expression attributes like `data={[1, 2, 3]}` or `config={{ a: 1 }}`.\n *\n * @param propValue - Raw property value from the Rust AST (may be a string representation)\n * @returns Parsed JS value — object, array, boolean, number, or original string as fallback\n */\nexport const parseProps = (propValue: any): any => {\n if (typeof propValue !== \"string\") return propValue;\n \n const cleanVal = propValue.trim();\n \n // Primitives\n if (cleanVal === \"true\") return true;\n if (cleanVal === \"false\") return false;\n if (cleanVal !== \"\" && !isNaN(Number(cleanVal))) return Number(cleanVal);\n \n // Unwrap double JSX braces: {{ a: 1 }} → { a: 1 }\n let val = cleanVal;\n if (val.startsWith(\"{\") && val.endsWith(\"}\")) {\n const inner = val.slice(1, -1).trim();\n if (\n (inner.startsWith(\"[\") && inner.endsWith(\"]\")) ||\n (inner.startsWith(\"{\") && inner.endsWith(\"}\"))\n ) {\n val = inner;\n }\n }\n \n // Evaluate arrays and objects (relaxed JS syntax, not strict JSON)\n if (\n (val.startsWith(\"[\") && val.endsWith(\"]\")) ||\n (val.startsWith(\"{\") && val.endsWith(\"}\"))\n ) {\n try {\n return JSON.parse(val);\n } catch {\n return propValue;\n }\n }\n \n return propValue;\n};\n ","/**\n * @toaq/omni-mdx\n *\n * Safe entry point — types only; no server/native/wasm imports.\n * To parse and render, use:\n * import { parseMdx, MDXServerRenderer } from '@toaq/omni-mdx/server'\n * import { MDXClientRenderer } from '@toaq/omni-mdx/client'\n */\n\nimport React from \"react\";\n\n// Types only (no runtime imports)\nexport type { AstNode, AttrValueKind, MDXComponents } from \"./types/MdxAST\";\nexport type {\n MdxInput\n} from './types/MdxInput';\n\n// Component registry (empty by default; to be expanded)\nexport const MDX_COMPONENTS: Record<string, React.ComponentType<any>> = {};\n\n// Utility for parsing props in custom components\nexport { parseProps } from \"./utils/parserHelpers\";"],"mappings":";AASO,IAAM,aAAa,CAAC,cAAwB;AACjD,MAAI,OAAO,cAAc,SAAU,QAAO;AAE1C,QAAM,WAAW,UAAU,KAAK;AAGhC,MAAI,aAAa,OAAS,QAAO;AACjC,MAAI,aAAa,QAAS,QAAO;AACjC,MAAI,aAAa,MAAM,CAAC,MAAM,OAAO,QAAQ,CAAC,EAAG,QAAO,OAAO,QAAQ;AAGvE,MAAI,MAAM;AACV,MAAI,IAAI,WAAW,GAAG,KAAK,IAAI,SAAS,GAAG,GAAG;AAC5C,UAAM,QAAQ,IAAI,MAAM,GAAG,EAAE,EAAE,KAAK;AACpC,QACG,MAAM,WAAW,GAAG,KAAK,MAAM,SAAS,GAAG,KAC3C,MAAM,WAAW,GAAG,KAAK,MAAM,SAAS,GAAG,GAC5C;AACA,YAAM;AAAA,IACR;AAAA,EACF;AAGA,MACG,IAAI,WAAW,GAAG,KAAK,IAAI,SAAS,GAAG,KACvC,IAAI,WAAW,GAAG,KAAK,IAAI,SAAS,GAAG,GACxC;AACA,QAAI;AACF,aAAO,KAAK,MAAM,GAAG;AAAA,IACvB,QAAQ;AACN,aAAO;AAAA,IACT;AAAA,EACF;AAEA,SAAO;AACT;;;AC1BO,IAAM,iBAA2D,CAAC;","names":[]}
Binary file
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@toaq-oss/omni-mdx",
3
- "version": "1.1.0",
3
+ "version": "1.1.1",
4
4
  "description": "MDX parser + renderer for Next.js — Rust core, RSC-compatible",
5
5
  "license": "MIT",
6
6
  "type": "module",