@conloca/mdx 0.1.15 → 0.2.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 (86) hide show
  1. package/README.md +62 -18
  2. package/dist/code-block-frame.d.ts +41 -0
  3. package/dist/code-block-frame.d.ts.map +1 -0
  4. package/dist/code-block-frame.js +187 -0
  5. package/dist/code-block-frame.js.map +1 -0
  6. package/dist/editor-core.d.ts +56 -0
  7. package/dist/editor-core.d.ts.map +1 -0
  8. package/dist/editor-core.js +225 -0
  9. package/dist/editor-core.js.map +1 -0
  10. package/dist/esm-passthrough.d.ts +36 -0
  11. package/dist/esm-passthrough.d.ts.map +1 -0
  12. package/dist/esm-passthrough.js +237 -0
  13. package/dist/esm-passthrough.js.map +1 -0
  14. package/dist/fragments.d.ts +37 -0
  15. package/dist/fragments.d.ts.map +1 -0
  16. package/dist/fragments.js +53 -0
  17. package/dist/fragments.js.map +1 -0
  18. package/dist/index.d.ts +6 -0
  19. package/dist/index.d.ts.map +1 -0
  20. package/dist/index.js +4 -0
  21. package/dist/index.js.map +1 -0
  22. package/dist/markdown-options.d.ts +3 -0
  23. package/dist/markdown-options.d.ts.map +1 -0
  24. package/dist/markdown-options.js +20 -0
  25. package/dist/markdown-options.js.map +1 -0
  26. package/dist/mdx/compile-request.d.ts +5 -0
  27. package/dist/mdx/compile-request.d.ts.map +1 -0
  28. package/dist/mdx/compile-request.js +40 -0
  29. package/dist/mdx/compile-request.js.map +1 -0
  30. package/dist/mdx/compile.d.ts +3 -0
  31. package/dist/mdx/compile.d.ts.map +1 -0
  32. package/dist/mdx/compile.js +47 -0
  33. package/dist/mdx/compile.js.map +1 -0
  34. package/dist/mdx/evaluate.d.ts +39 -0
  35. package/dist/mdx/evaluate.d.ts.map +1 -0
  36. package/dist/mdx/evaluate.js +131 -0
  37. package/dist/mdx/evaluate.js.map +1 -0
  38. package/dist/mdx/heading-outline.d.ts +46 -0
  39. package/dist/mdx/heading-outline.d.ts.map +1 -0
  40. package/dist/mdx/heading-outline.js +114 -0
  41. package/dist/mdx/heading-outline.js.map +1 -0
  42. package/dist/mdx/restrict-expressions.d.ts +43 -0
  43. package/dist/mdx/restrict-expressions.d.ts.map +1 -0
  44. package/dist/mdx/restrict-expressions.js +160 -0
  45. package/dist/mdx/restrict-expressions.js.map +1 -0
  46. package/dist/mdx-editor.d.ts +7 -0
  47. package/dist/mdx-editor.d.ts.map +1 -0
  48. package/dist/mdx-editor.js +8 -0
  49. package/dist/mdx-editor.js.map +1 -0
  50. package/dist/node.d.ts +18 -0
  51. package/dist/node.d.ts.map +1 -0
  52. package/dist/node.js +18 -0
  53. package/dist/node.js.map +1 -0
  54. package/dist/sandbox-frame.d.ts +114 -0
  55. package/dist/sandbox-frame.d.ts.map +1 -0
  56. package/dist/sandbox-frame.js +234 -0
  57. package/dist/sandbox-frame.js.map +1 -0
  58. package/dist/types.d.ts +19 -0
  59. package/dist/types.d.ts.map +1 -0
  60. package/dist/types.js +2 -0
  61. package/dist/types.js.map +1 -0
  62. package/package.json +82 -26
  63. package/src/code-block-frame.tsx +262 -0
  64. package/src/editor-core.tsx +403 -0
  65. package/src/editor-styles.css +282 -0
  66. package/src/esm-passthrough.ts +269 -0
  67. package/src/fragments.ts +91 -0
  68. package/src/index.ts +5 -0
  69. package/src/markdown-options.ts +21 -0
  70. package/src/mdx/compile-request.ts +53 -0
  71. package/src/mdx/compile.ts +51 -0
  72. package/src/mdx/evaluate.ts +144 -0
  73. package/src/mdx/heading-outline.ts +153 -0
  74. package/src/mdx/restrict-expressions.ts +173 -0
  75. package/src/mdx-editor.tsx +15 -0
  76. package/src/node.ts +25 -0
  77. package/src/sandbox-frame.ts +277 -0
  78. package/src/types.ts +23 -0
  79. package/dist/index.d.mts +0 -96
  80. package/dist/index.d.mts.map +0 -1
  81. package/dist/index.mjs +0 -425
  82. package/dist/index.mjs.map +0 -1
  83. package/dist/node.d.mts +0 -107
  84. package/dist/node.d.mts.map +0 -1
  85. package/dist/node.mjs +0 -125
  86. package/dist/node.mjs.map +0 -1
@@ -0,0 +1,160 @@
1
+ /** A JSON-literal attribute expression (`{3}`, `{true}`, `{"x"}`) is a static
2
+ * value with no executable content — the editor's prop serializers already
3
+ * treat these as data. Anything that doesn't `JSON.parse` is author-controlled
4
+ * code and is dropped. */
5
+ function isLiteralExpression(value) {
6
+ if (!value || typeof value !== 'object')
7
+ return true;
8
+ const raw = value.value;
9
+ if (typeof raw !== 'string')
10
+ return true;
11
+ try {
12
+ JSON.parse(raw.trim());
13
+ return true;
14
+ }
15
+ catch {
16
+ return false;
17
+ }
18
+ }
19
+ /** URL-bearing attributes the browser fetches or navigates to. React neutralizes
20
+ * `javascript:` itself but NOT `data:text/html`, so these are scheme-filtered
21
+ * here regardless of who renders the tree. */
22
+ const URL_ATTR = /^(?:href|src|xlink:href|formaction|action|poster|background|cite)$/i;
23
+ /** Script-bearing URL schemes. Mirrors the mdast serializer's list so the
24
+ * compile gate and the raw-HTML serializer neutralize the same schemes. */
25
+ const DANGEROUS_URL_SCHEME = /^(?:javascript|vbscript):|^data:text\/html/i;
26
+ /** Intrinsic HTML elements that execute script, navigate, or embed regardless of
27
+ * their attributes. React renders author-written `<script>` verbatim, so these
28
+ * are never neutralized downstream and must be dropped here. Capitalized JSX
29
+ * (registered components) is never matched — only lowercase raw-HTML tags. */
30
+ const DANGEROUS_ELEMENTS = new Set([
31
+ 'script',
32
+ 'style',
33
+ 'iframe',
34
+ 'object',
35
+ 'embed',
36
+ 'link',
37
+ 'meta',
38
+ 'base',
39
+ 'frame',
40
+ 'frameset',
41
+ 'applet',
42
+ ]);
43
+ function hasDangerousScheme(value) {
44
+ return DANGEROUS_URL_SCHEME.test(value.replace(/[\p{Cc} ]+/gu, ''));
45
+ }
46
+ function isDangerousElement(node) {
47
+ if (node?.type !== 'mdxJsxFlowElement' && node?.type !== 'mdxJsxTextElement')
48
+ return false;
49
+ const name = typeof node.name === 'string' ? node.name : '';
50
+ return /^[a-z]/.test(name) && DANGEROUS_ELEMENTS.has(name.toLowerCase());
51
+ }
52
+ /** A JSON-literal expression whose parsed value is a dangerous-scheme URL string
53
+ * (`href={"data:text/html,…"}` round-trips through `JSON.parse` yet navigates). */
54
+ function isDangerousLiteralUrl(value) {
55
+ const raw = value?.value;
56
+ if (typeof raw !== 'string')
57
+ return false;
58
+ try {
59
+ const parsed = JSON.parse(raw.trim());
60
+ return typeof parsed === 'string' && hasDangerousScheme(parsed);
61
+ }
62
+ catch {
63
+ return false;
64
+ }
65
+ }
66
+ /** Filter/neutralize a JSX element's attributes: drop the `dangerouslySetInnerHTML`
67
+ * raw-HTML sink and inline `on*` handlers, drop non-literal expression props, and
68
+ * empty a URL-bearing attribute carrying a dangerous scheme. */
69
+ function sanitizeAttributes(attributes) {
70
+ const out = [];
71
+ for (const attr of attributes) {
72
+ if (attr?.type === 'mdxJsxExpressionAttribute')
73
+ continue; // `{...spread}` — arbitrary props
74
+ if (attr?.type !== 'mdxJsxAttribute' || typeof attr.name !== 'string') {
75
+ out.push(attr);
76
+ continue;
77
+ }
78
+ const name = attr.name;
79
+ // React's only raw-HTML escape hatch. A JSON-literal object
80
+ // (`{"__html": "<script>…"}`) passes the literal exemption yet injects live
81
+ // HTML on the published path, so drop it regardless of value shape.
82
+ if (name.toLowerCase() === 'dangerouslysetinnerhtml')
83
+ continue;
84
+ // Inline event handlers are never content. React strips string handlers, but
85
+ // dropping them here keeps the gate renderer-agnostic.
86
+ if (/^on/i.test(name))
87
+ continue;
88
+ const value = attr.value;
89
+ if (value && typeof value === 'object') {
90
+ if (!isLiteralExpression(value))
91
+ continue; // non-literal expression prop
92
+ if (URL_ATTR.test(name) && isDangerousLiteralUrl(value)) {
93
+ out.push({ ...attr, value: '' });
94
+ continue;
95
+ }
96
+ out.push(attr);
97
+ continue;
98
+ }
99
+ if (typeof value === 'string' && URL_ATTR.test(name) && hasDangerousScheme(value)) {
100
+ out.push({ ...attr, value: '' });
101
+ continue;
102
+ }
103
+ out.push(attr);
104
+ }
105
+ return out;
106
+ }
107
+ /** Remark transform that neutralizes the author-code AND HTML-injection vectors
108
+ * in authored MDX at every compile/eval entry point.
109
+ *
110
+ * Two layers, because expression-restriction is NOT HTML sanitization:
111
+ * 1. Author code — standalone `{…}` flow/text expressions (`mdxFlowExpression`/
112
+ * `mdxTextExpression`) and top-level ESM `import`/`export` (`mdxjsEsm`) reach
113
+ * `new AsyncFunction`/`evaluate()` as live code, so they fail the compile
114
+ * with a clear error; content fragments never legitimately need either.
115
+ * 2. HTML injection — `dangerouslySetInnerHTML` (React's raw-HTML escape hatch,
116
+ * which a JSON-literal object slips past the expression exemption), inline
117
+ * `on*` handlers, dangerous URL schemes (`javascript:`/`vbscript:`/
118
+ * `data:text/html`) on URL-bearing attributes and markdown link/image URLs,
119
+ * and script/navigate/embed intrinsic elements (`<script>`, `<iframe>`, …)
120
+ * are dropped or emptied. This layers atop React's own SSR neutralization
121
+ * (it blocks `javascript:` URLs, strips string `on*` handlers, and escapes
122
+ * all text/attribute values). The set above is a renderer-agnostic superset:
123
+ * some of it (`javascript:`, string `on*`) React also covers, but it is
124
+ * re-applied here for the compile and mdast-serializer paths where React is
125
+ * not in the loop, and it adds what React does NOT handle (`data:text/html`,
126
+ * `dangerouslySetInnerHTML`, raw `<script>`/embed elements) — which the
127
+ * published `evaluateMDXToComponent` path would otherwise emit verbatim to
128
+ * every visitor.
129
+ *
130
+ * Non-literal JSX attribute and spread expressions are dropped so a component
131
+ * still renders with its safe props. Shared by `compileMDX` (editor preview) and
132
+ * `evaluateMDXToComponent` (published-site render), so the control is identical
133
+ * on both. In the editor the sandbox is the sufficient boundary; on the published
134
+ * path this transform is the boundary, so it must close the class, not just the
135
+ * eval vector. */
136
+ export function remarkRestrictExpressions() {
137
+ return (tree) => {
138
+ const walk = (node) => {
139
+ if (node.type === 'mdxFlowExpression' || node.type === 'mdxTextExpression') {
140
+ throw new Error('MDX expressions are not allowed: remove the `{…}` expression from the content.');
141
+ }
142
+ if (node.type === 'mdxjsEsm') {
143
+ throw new Error('MDX import/export statements are not allowed: remove the top-level `import`/`export` from the content.');
144
+ }
145
+ if ((node.type === 'link' || node.type === 'image') &&
146
+ typeof node.url === 'string' &&
147
+ hasDangerousScheme(node.url)) {
148
+ node.url = '';
149
+ }
150
+ if (Array.isArray(node.attributes))
151
+ node.attributes = sanitizeAttributes(node.attributes);
152
+ if (Array.isArray(node.children)) {
153
+ node.children = node.children.filter((child) => !isDangerousElement(child));
154
+ node.children.forEach(walk);
155
+ }
156
+ };
157
+ walk(tree);
158
+ };
159
+ }
160
+ //# sourceMappingURL=restrict-expressions.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"restrict-expressions.js","sourceRoot":"","sources":["../../src/mdx/restrict-expressions.ts"],"names":[],"mappings":"AAaA;;;0BAG0B;AAC1B,SAAS,mBAAmB,CAAC,KAAc;IACzC,IAAI,CAAC,KAAK,IAAI,OAAO,KAAK,KAAK,QAAQ;QAAE,OAAO,IAAI,CAAC;IACrD,MAAM,GAAG,GAAI,KAA6B,CAAC,KAAK,CAAC;IACjD,IAAI,OAAO,GAAG,KAAK,QAAQ;QAAE,OAAO,IAAI,CAAC;IACzC,IAAI,CAAC;QACH,IAAI,CAAC,KAAK,CAAC,GAAG,CAAC,IAAI,EAAE,CAAC,CAAC;QACvB,OAAO,IAAI,CAAC;IACd,CAAC;IAAC,MAAM,CAAC;QACP,OAAO,KAAK,CAAC;IACf,CAAC;AACH,CAAC;AAED;;8CAE8C;AAC9C,MAAM,QAAQ,GAAG,qEAAqE,CAAC;AAEvF;2EAC2E;AAC3E,MAAM,oBAAoB,GAAG,6CAA6C,CAAC;AAE3E;;;8EAG8E;AAC9E,MAAM,kBAAkB,GAAG,IAAI,GAAG,CAAC;IACjC,QAAQ;IACR,OAAO;IACP,QAAQ;IACR,QAAQ;IACR,OAAO;IACP,MAAM;IACN,MAAM;IACN,MAAM;IACN,OAAO;IACP,UAAU;IACV,QAAQ;CACT,CAAC,CAAC;AAEH,SAAS,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AC/B,MAAM,IAAI,GAAG,CAAC,IAAe,EAAQ,EAAE;YACrC,IAAI,IAAI,CAAC,IAAI,KAAK,mBAAmB,IAAI,IAAI,CAAC,IAAI,KAAK,mBAAmB,EAAE,CAAC;gBAC3E,MAAM,IAAI,KAAK,CAAC,gFAAgF,CAAC,CAAC;YACpG,CAAC;YACD,IAAI,IAAI,CAAC,IAAI,KAAK,UAAU,EAAE,CAAC;gBAC7B,MAAM,IAAI,KAAK,CACb,wGAAwG,CACzG,CAAC;YACJ,CAAC;YACD,IACE,CAAC,IAAI,CAAC,IAAI,KAAK,MAAM,IAAI,IAAI,CAAC,IAAI,KAAK,OAAO,CAAC;gBAC/C,OAAO,IAAI,CAAC,GAAG,KAAK,QAAQ;gBAC5B,kBAAkB,CAAC,IAAI,CAAC,GAAG,CAAC,EAC5B,CAAC;gBACD,IAAI,CAAC,GAAG,GAAG,EAAE,CAAC;YAChB,CAAC;YACD,IAAI,KAAK,CAAC,OAAO,CAAC,IAAI,CAAC,UAAU,CAAC;gBAAE,IAAI,CAAC,UAAU,GAAG,kBAAkB,CAAC,IAAI,CAAC,UAAU,CAAC,CAAC;YAC1F,IAAI,KAAK,CAAC,OAAO,CAAC,IAAI,CAAC,QAAQ,CAAC,EAAE,CAAC;gBACjC,IAAI,CAAC,QAAQ,GAAG,IAAI,CAAC,QAAQ,CAAC,MAAM,CAAC,CAAC,KAAK,EAAE,EAAE,CAAC,CAAC,kBAAkB,CAAC,KAAK,CAAC,CAAC,CAAC;gBAC5E,IAAI,CAAC,QAAQ,CAAC,OAAO,CAAC,IAAI,CAAC,CAAC;YAC9B,CAAC;QACH,CAAC,CAAC;QACF,IAAI,CAAC,IAAI,CAAC,CAAC;IACb,CAAC,CAAC;AACJ,CAAC"}
@@ -0,0 +1,7 @@
1
+ import type { MDXEditorMethods } from '@mdxeditor/editor';
2
+ import React from 'react';
3
+ import { type BaseMDXEditorProps } from './editor-core.js';
4
+ export interface MDXEditorProps extends Omit<BaseMDXEditorProps, 'disableImageSettingsButton' | 'imageButtonRef' | 'imageDialog' | 'onImageShortcut'> {
5
+ }
6
+ export declare const MDXEditor: React.ForwardRefExoticComponent<MDXEditorProps & React.RefAttributes<MDXEditorMethods>>;
7
+ //# sourceMappingURL=mdx-editor.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"mdx-editor.d.ts","sourceRoot":"","sources":["../src/mdx-editor.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,mBAAmB,CAAC;AAC1D,OAAO,KAAK,MAAM,OAAO,CAAC;AAC1B,OAAO,EAAiB,KAAK,kBAAkB,EAAE,MAAM,kBAAkB,CAAC;AAE1E,MAAM,WAAW,cACf,SAAQ,IAAI,CACV,kBAAkB,EAClB,4BAA4B,GAAG,gBAAgB,GAAG,aAAa,GAAG,iBAAiB,CACpF;CAAG;AAEN,eAAO,MAAM,SAAS,yFAEpB,CAAC"}
@@ -0,0 +1,8 @@
1
+ import { jsx as _jsx } from "react/jsx-runtime";
2
+ import React from 'react';
3
+ import { BaseMDXEditor } from './editor-core.js';
4
+ export const MDXEditor = React.forwardRef((props, ref) => {
5
+ return _jsx(BaseMDXEditor, { ref: ref, ...props });
6
+ });
7
+ MDXEditor.displayName = 'MDXEditor';
8
+ //# sourceMappingURL=mdx-editor.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"mdx-editor.js","sourceRoot":"","sources":["../src/mdx-editor.tsx"],"names":[],"mappings":";AACA,OAAO,KAAK,MAAM,OAAO,CAAC;AAC1B,OAAO,EAAE,aAAa,EAA2B,MAAM,kBAAkB,CAAC;AAQ1E,MAAM,CAAC,MAAM,SAAS,GAAG,KAAK,CAAC,UAAU,CAAmC,CAAC,KAAK,EAAE,GAAG,EAAE,EAAE;IACzF,OAAO,KAAC,aAAa,IAAC,GAAG,EAAE,GAAG,KAAM,KAAK,GAAI,CAAC;AAChD,CAAC,CAAC,CAAC;AAEH,SAAS,CAAC,WAAW,GAAG,WAAW,CAAC"}
package/dist/node.d.ts ADDED
@@ -0,0 +1,18 @@
1
+ /**
2
+ * Node.js-specific exports for @conloca/mdx
3
+ *
4
+ * These exports require Node.js runtime APIs and should not be imported in browser environments.
5
+ * Import from '@conloca/mdx/node' for server-side MDX operations.
6
+ *
7
+ * @example
8
+ * ```typescript
9
+ * // Server-side code (Astro, Next.js, etc.)
10
+ * import { evaluateMDXToComponent } from '@conloca/mdx/node';
11
+ * ```
12
+ */
13
+ export { evaluateMDXFragments } from './fragments.js';
14
+ export { compileMDX } from './mdx/compile.js';
15
+ export { handleMDXCompileRequest } from './mdx/compile-request.js';
16
+ export { evaluateMDXToComponent } from './mdx/evaluate.js';
17
+ export type { EvaluatedMDXFragment, FailedMDXFragmentEvaluation, MDXCompileResult, MDXFragmentEvaluationResult, } from './types.js';
18
+ //# sourceMappingURL=node.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"node.d.ts","sourceRoot":"","sources":["../src/node.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;GAWG;AAEH,OAAO,EAAE,oBAAoB,EAAE,MAAM,gBAAgB,CAAC;AAEtD,OAAO,EAAE,UAAU,EAAE,MAAM,kBAAkB,CAAC;AAC9C,OAAO,EAAE,uBAAuB,EAAE,MAAM,0BAA0B,CAAC;AACnE,OAAO,EAAE,sBAAsB,EAAE,MAAM,mBAAmB,CAAC;AAE3D,YAAY,EACV,oBAAoB,EACpB,2BAA2B,EAC3B,gBAAgB,EAChB,2BAA2B,GAC5B,MAAM,YAAY,CAAC"}
package/dist/node.js ADDED
@@ -0,0 +1,18 @@
1
+ /**
2
+ * Node.js-specific exports for @conloca/mdx
3
+ *
4
+ * These exports require Node.js runtime APIs and should not be imported in browser environments.
5
+ * Import from '@conloca/mdx/node' for server-side MDX operations.
6
+ *
7
+ * @example
8
+ * ```typescript
9
+ * // Server-side code (Astro, Next.js, etc.)
10
+ * import { evaluateMDXToComponent } from '@conloca/mdx/node';
11
+ * ```
12
+ */
13
+ export { evaluateMDXFragments } from './fragments.js';
14
+ // MDX compilation and evaluation (Node.js only)
15
+ export { compileMDX } from './mdx/compile.js';
16
+ export { handleMDXCompileRequest } from './mdx/compile-request.js';
17
+ export { evaluateMDXToComponent } from './mdx/evaluate.js';
18
+ //# sourceMappingURL=node.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"node.js","sourceRoot":"","sources":["../src/node.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;GAWG;AAEH,OAAO,EAAE,oBAAoB,EAAE,MAAM,gBAAgB,CAAC;AACtD,gDAAgD;AAChD,OAAO,EAAE,UAAU,EAAE,MAAM,kBAAkB,CAAC;AAC9C,OAAO,EAAE,uBAAuB,EAAE,MAAM,0BAA0B,CAAC;AACnE,OAAO,EAAE,sBAAsB,EAAE,MAAM,mBAAmB,CAAC"}
@@ -0,0 +1,114 @@
1
+ /**
2
+ * Opaque-origin MDX preview frame document + runtime. Confines the MDX
3
+ * `'unsafe-eval'` to this frame — see `SANDBOX_FRAME_CSP` below.
4
+ * Shared by the cms-spa ContentSandbox and the server route that serves this
5
+ * frame's HTML at `SANDBOX_FRAME_PATH`.
6
+ */
7
+ /**
8
+ * Build a jsx runtime that constructs real DOM nodes instead of React
9
+ * elements. The two isolated MDX preview surfaces render markdown-subset MDX
10
+ * with no component map supplied, so intrinsic elements plus `Fragment` cover
11
+ * everything they emit; this keeps the frame dependency-free (no React bundle
12
+ * to inline). Inline event-handler props are dropped defensively.
13
+ */
14
+ /** Discriminated messages the frame and its host exchange. */
15
+ export interface SandboxRenderMessage {
16
+ __conlocaSandbox: true;
17
+ kind: 'render';
18
+ mode: 'mdx' | 'html';
19
+ /** Compiled MDX function body (mode `mdx`) or sanitized HTML (mode `html`). */
20
+ payload: string;
21
+ /** Optional stylesheet text injected into the frame for preview fidelity. */
22
+ styles?: string;
23
+ }
24
+ export type SandboxOutboundMessage = {
25
+ __conlocaSandbox: true;
26
+ k: string;
27
+ kind: 'ready';
28
+ } | {
29
+ __conlocaSandbox: true;
30
+ k: string;
31
+ kind: 'height';
32
+ px: number;
33
+ } | {
34
+ __conlocaSandbox: true;
35
+ k: string;
36
+ kind: 'link';
37
+ href: string;
38
+ } | {
39
+ __conlocaSandbox: true;
40
+ k: string;
41
+ kind: 'interact';
42
+ } | {
43
+ __conlocaSandbox: true;
44
+ k: string;
45
+ kind: 'rendered';
46
+ } | {
47
+ __conlocaSandbox: true;
48
+ k: string;
49
+ kind: 'error';
50
+ message: string;
51
+ };
52
+ export declare function createSandboxRuntime(): {
53
+ Fragment: symbol;
54
+ jsx: (type: unknown, props: Record<string, unknown>) => Node;
55
+ jsxs: (type: unknown, props: Record<string, unknown>) => Node;
56
+ jsxDEV: (type: unknown, props: Record<string, unknown>) => Node;
57
+ };
58
+ /**
59
+ * Evaluate a pre-compiled MDX function body. This is the `new AsyncFunction`
60
+ * eval that used to run in the privileged parent (`useMDXEvaluation`) — it now
61
+ * runs only here, inside the sandbox, which is why `'unsafe-eval'` is confined
62
+ * to the frame CSP. Returns the module's default export (the MDX component).
63
+ */
64
+ export declare function runCompiledMdx(code: string, runtime: Record<string, unknown>): Promise<{
65
+ default?: (props: Record<string, unknown>) => Node;
66
+ }>;
67
+ /**
68
+ * The frame entry point. Wires the message listener, height reporting, and
69
+ * link/interaction interception, then announces readiness. Every dependency
70
+ * arrives as `deps` so the serialized source carries no free identifiers a
71
+ * minifier could rename.
72
+ */
73
+ export declare function sandboxFrameMain(deps: {
74
+ createSandboxRuntime: typeof createSandboxRuntime;
75
+ runCompiledMdx: typeof runCompiledMdx;
76
+ }): void;
77
+ /**
78
+ * The frame's own Content-Security-Policy. `'unsafe-eval'` is intentional and
79
+ * confined here (the MDX eval lives in the frame). What it does and does NOT
80
+ * close, stated precisely:
81
+ * - The isolation that HOLDS: no `allow-same-origin` gives the frame an opaque
82
+ * origin, so it exposes no cookies, no privileged globals, and no
83
+ * `window.parent` — nothing privileged is reachable to exfiltrate.
84
+ * - Structured-data egress is closed: with no `connect-src`, `fetch`/XHR/
85
+ * WebSocket/`sendBeacon` cannot post data out.
86
+ * - Metadata-only leak channels REMAIN OPEN and are an accepted residual risk.
87
+ * A hostile preview script can still leak the previewing admin's IP/UA/timing
88
+ * (plus author-encoded data) to an external host two ways: (a) passive
89
+ * img/font GETs to `https:` (`img-src`/`font-src`, which `connect-src` does
90
+ * not govern — kept for remote-image/`@font-face` fidelity, CSP-toggleable
91
+ * below); and (b) self-navigation — `location.href`/`location.replace` or a
92
+ * `<meta http-equiv=refresh>` — which is inherent to `allow-scripts` and NOT
93
+ * closeable by CSP (`navigate-to` is unsupported in browsers) or the sandbox
94
+ * flags (same-frame navigation is always allowed), short of dropping
95
+ * `allow-scripts` and the interactive preview with it.
96
+ * Owner toggle: replacing `https:` with just `data: blob:` in `img-src`/`font-src`
97
+ * below closes (a) at a remote-image/-font fidelity cost — but not (b), which has
98
+ * no CSP mitigation. Both leak only request metadata, never privileged content.
99
+ */
100
+ export declare const SANDBOX_FRAME_CSP = "default-src 'none'; script-src 'unsafe-inline' 'unsafe-eval'; style-src 'unsafe-inline'; img-src data: https: blob:; font-src data: https:";
101
+ /**
102
+ * Assemble the sandbox frame document. The runtime functions are injected as
103
+ * argument expressions to `sandboxFrameMain` so no cross-function identifier
104
+ * has to survive minification by name.
105
+ *
106
+ * The editor loads this from `GET /api/v1/mdx/sandbox-frame` (own response CSP
107
+ * with unsafe-eval). Do NOT use srcdoc/blob from the parent document: those
108
+ * inherit the parent CSP, which forbids unsafe-inline/unsafe-eval and leaves
109
+ * MDX fragment previews as empty white boxes.
110
+ */
111
+ export declare function buildSandboxSrcdoc(): string;
112
+ /** Well-known path where a host serves {@link buildSandboxSrcdoc}. */
113
+ export declare const SANDBOX_FRAME_PATH = "/api/v1/mdx/sandbox-frame";
114
+ //# sourceMappingURL=sandbox-frame.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"sandbox-frame.d.ts","sourceRoot":"","sources":["../src/sandbox-frame.ts"],"names":[],"mappings":"AAAA;;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AAI,EAAE,OAAO,EAAE,KAAK,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,KAAK,IAAI,CAAC;IAC9D,MAAM,EAAE,CAAC,IAAI,EAAE,OAAO,EAAE,KAAK,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,KAAK,IAAI,CAAC;CACjE,CAyCA;AAED;;;;;GAKG;AACH,wBAAgB,cAAc,CAC5B,IAAI,EAAE,MAAM,EACZ,OAAO,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,GAC/B,OAAO,CAAC;IAAE,OAAO,CAAC,EAAE,CAAC,KAAK,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,KAAK,IAAI,CAAA;CAAE,CAAC,CAKjE;AAED;;;;;GAKG;AACH,wBAAgB,gBAAgB,CAAC,IAAI,EAAE;IACrC,oBAAoB,EAAE,OAAO,oBAAoB,CAAC;IAClD,cAAc,EAAE,OAAO,cAAc,CAAC;CACvC,GAAG,IAAI,CA0GP;AAED;;;;;;;;;;;;;;;;;;;;;;GAsBG;AACH,eAAO,MAAM,iBAAiB,+IACgH,CAAC;AAU/I;;;;;;;;;GASG;AACH,wBAAgB,kBAAkB,IAAI,MAAM,CAc3C;AAED,sEAAsE;AACtE,eAAO,MAAM,kBAAkB,8BAA8B,CAAC"}
@@ -0,0 +1,234 @@
1
+ /**
2
+ * Opaque-origin MDX preview frame document + runtime. Confines the MDX
3
+ * `'unsafe-eval'` to this frame — see `SANDBOX_FRAME_CSP` below.
4
+ * Shared by the cms-spa ContentSandbox and the server route that serves this
5
+ * frame's HTML at `SANDBOX_FRAME_PATH`.
6
+ */
7
+ export function createSandboxRuntime() {
8
+ const Fragment = Symbol('sandbox.fragment');
9
+ const toNodes = (value) => {
10
+ if (value == null || value === true || value === false)
11
+ return [];
12
+ if (Array.isArray(value))
13
+ return value.flatMap(toNodes);
14
+ if (typeof value === 'string' || typeof value === 'number')
15
+ return [document.createTextNode(String(value))];
16
+ if (value instanceof Node)
17
+ return [value];
18
+ return [document.createTextNode(String(value))];
19
+ };
20
+ const jsx = (type, props) => {
21
+ const p = props || {};
22
+ if (type === Fragment) {
23
+ const frag = document.createDocumentFragment();
24
+ for (const child of toNodes(p.children))
25
+ frag.appendChild(child);
26
+ return frag;
27
+ }
28
+ if (typeof type === 'function')
29
+ return type(p);
30
+ if (typeof type === 'string') {
31
+ const el = document.createElement(type);
32
+ for (const key in p) {
33
+ if (key === 'children' || key === 'key')
34
+ continue;
35
+ const value = p[key];
36
+ if (/^on/i.test(key))
37
+ continue; // never wire an event handler
38
+ if (key === 'className') {
39
+ el.setAttribute('class', String(value));
40
+ }
41
+ else if (key === 'style' && value && typeof value === 'object') {
42
+ Object.assign(el.style, value);
43
+ }
44
+ else if (value === true) {
45
+ el.setAttribute(key, '');
46
+ }
47
+ else if (value != null && value !== false) {
48
+ el.setAttribute(key, String(value));
49
+ }
50
+ }
51
+ for (const child of toNodes(p.children))
52
+ el.appendChild(child);
53
+ return el;
54
+ }
55
+ const missing = document.createElement('span');
56
+ missing.setAttribute('data-sandbox-unknown', '');
57
+ return missing;
58
+ };
59
+ return { Fragment, jsx, jsxs: jsx, jsxDEV: jsx };
60
+ }
61
+ /**
62
+ * Evaluate a pre-compiled MDX function body. This is the `new AsyncFunction`
63
+ * eval that used to run in the privileged parent (`useMDXEvaluation`) — it now
64
+ * runs only here, inside the sandbox, which is why `'unsafe-eval'` is confined
65
+ * to the frame CSP. Returns the module's default export (the MDX component).
66
+ */
67
+ export function runCompiledMdx(code, runtime) {
68
+ const AsyncFunction = Object.getPrototypeOf(async () => { }).constructor;
69
+ return new AsyncFunction(String(code))(runtime);
70
+ }
71
+ /**
72
+ * The frame entry point. Wires the message listener, height reporting, and
73
+ * link/interaction interception, then announces readiness. Every dependency
74
+ * arrives as `deps` so the serialized source carries no free identifiers a
75
+ * minifier could rename.
76
+ */
77
+ export function sandboxFrameMain(deps) {
78
+ const root = document.getElementById('__sandbox_root');
79
+ if (!root)
80
+ return;
81
+ // Per-instance key from ?k= so the host can accept messages without relying
82
+ // on event.source === iframe.contentWindow (broken for opaque sandboxes in Chromium).
83
+ let frameKey = '';
84
+ try {
85
+ frameKey = new URL(location.href).searchParams.get('k') || '';
86
+ }
87
+ catch {
88
+ frameKey = '';
89
+ }
90
+ const post = (message) => {
91
+ parent.postMessage({ ...message, k: frameKey, __conlocaSandbox: true }, '*');
92
+ };
93
+ let lastHeight = -1;
94
+ const postHeight = () => {
95
+ // Child margins (prose p/h1) collapse out of a normal block root, so
96
+ // getBoundingClientRect(root) under-reports. flow-root on the root
97
+ // contains them; also take scrollHeight so a short iframe cannot
98
+ // circularly clamp the measure.
99
+ const px = Math.ceil(Math.max(root.getBoundingClientRect().height, root.scrollHeight, document.body.scrollHeight, document.documentElement.scrollHeight));
100
+ if (px !== lastHeight) {
101
+ lastHeight = px;
102
+ post({ __conlocaSandbox: true, kind: 'height', px });
103
+ }
104
+ };
105
+ document.addEventListener('click', (event) => {
106
+ const target = event.target;
107
+ const anchor = target && 'closest' in target ? target.closest('a') : null;
108
+ if (anchor) {
109
+ event.preventDefault();
110
+ post({ __conlocaSandbox: true, kind: 'link', href: anchor.getAttribute('href') || '' });
111
+ }
112
+ }, true);
113
+ document.addEventListener('pointerdown', () => post({ __conlocaSandbox: true, kind: 'interact' }), true);
114
+ const applyStyles = (css) => {
115
+ let style = document.getElementById('__sandbox_styles');
116
+ if (!style) {
117
+ style = document.createElement('style');
118
+ style.id = '__sandbox_styles';
119
+ document.head.appendChild(style);
120
+ }
121
+ style.textContent = css;
122
+ };
123
+ const renderMdx = (code) => {
124
+ const runtime = deps.createSandboxRuntime();
125
+ deps
126
+ .runCompiledMdx(code, runtime)
127
+ .then((module) => {
128
+ const Component = module?.default;
129
+ root.textContent = '';
130
+ if (typeof Component === 'function') {
131
+ const output = Component({});
132
+ if (output)
133
+ root.appendChild(output);
134
+ }
135
+ post({ __conlocaSandbox: true, kind: 'rendered' });
136
+ postHeight();
137
+ })
138
+ .catch((error) => {
139
+ post({
140
+ __conlocaSandbox: true,
141
+ kind: 'error',
142
+ message: error instanceof Error ? error.message : String(error),
143
+ });
144
+ });
145
+ };
146
+ const renderHtml = (html) => {
147
+ // Already allowlist-sanitized by the host; the sandbox contains anything
148
+ // that slips through (opaque origin, no privileged globals, strict CSP).
149
+ root.innerHTML = html;
150
+ post({ __conlocaSandbox: true, kind: 'rendered' });
151
+ postHeight();
152
+ };
153
+ window.addEventListener('message', (event) => {
154
+ // Brand + kind only. Requiring event.source === parent drops legitimate
155
+ // host posts under some nested/opaque-origin Chromium cases.
156
+ const data = event.data;
157
+ if (data?.__conlocaSandbox !== true || data.kind !== 'render')
158
+ return;
159
+ if (typeof data.styles === 'string')
160
+ applyStyles(data.styles);
161
+ try {
162
+ if (data.mode === 'mdx')
163
+ renderMdx(data.payload);
164
+ else
165
+ renderHtml(data.payload);
166
+ }
167
+ catch (error) {
168
+ post({ __conlocaSandbox: true, kind: 'error', message: error instanceof Error ? error.message : String(error) });
169
+ }
170
+ });
171
+ const ResizeObs = window.ResizeObserver;
172
+ if (ResizeObs)
173
+ new ResizeObs(postHeight).observe(root);
174
+ post({ __conlocaSandbox: true, kind: 'ready' });
175
+ }
176
+ /**
177
+ * The frame's own Content-Security-Policy. `'unsafe-eval'` is intentional and
178
+ * confined here (the MDX eval lives in the frame). What it does and does NOT
179
+ * close, stated precisely:
180
+ * - The isolation that HOLDS: no `allow-same-origin` gives the frame an opaque
181
+ * origin, so it exposes no cookies, no privileged globals, and no
182
+ * `window.parent` — nothing privileged is reachable to exfiltrate.
183
+ * - Structured-data egress is closed: with no `connect-src`, `fetch`/XHR/
184
+ * WebSocket/`sendBeacon` cannot post data out.
185
+ * - Metadata-only leak channels REMAIN OPEN and are an accepted residual risk.
186
+ * A hostile preview script can still leak the previewing admin's IP/UA/timing
187
+ * (plus author-encoded data) to an external host two ways: (a) passive
188
+ * img/font GETs to `https:` (`img-src`/`font-src`, which `connect-src` does
189
+ * not govern — kept for remote-image/`@font-face` fidelity, CSP-toggleable
190
+ * below); and (b) self-navigation — `location.href`/`location.replace` or a
191
+ * `<meta http-equiv=refresh>` — which is inherent to `allow-scripts` and NOT
192
+ * closeable by CSP (`navigate-to` is unsupported in browsers) or the sandbox
193
+ * flags (same-frame navigation is always allowed), short of dropping
194
+ * `allow-scripts` and the interactive preview with it.
195
+ * Owner toggle: replacing `https:` with just `data: blob:` in `img-src`/`font-src`
196
+ * below closes (a) at a remote-image/-font fidelity cost — but not (b), which has
197
+ * no CSP mitigation. Both leak only request metadata, never privileged content.
198
+ */
199
+ export const SANDBOX_FRAME_CSP = "default-src 'none'; script-src 'unsafe-inline' 'unsafe-eval'; style-src 'unsafe-inline'; img-src data: https: blob:; font-src data: https:";
200
+ /**
201
+ * esbuild-style bundlers inject `/* @__PURE__ *\/ __name(fn, "id")` around
202
+ * function expressions when keepNames is on. That helper exists in the bundle
203
+ * scope but NOT inside the iframe document after Function#toString() copy.
204
+ * Provide a no-op so the serialized bootstrap can run in isolation.
205
+ */
206
+ const SANDBOX_BUNDLE_HELPERS = 'var __name=function(fn){return fn};';
207
+ /**
208
+ * Assemble the sandbox frame document. The runtime functions are injected as
209
+ * argument expressions to `sandboxFrameMain` so no cross-function identifier
210
+ * has to survive minification by name.
211
+ *
212
+ * The editor loads this from `GET /api/v1/mdx/sandbox-frame` (own response CSP
213
+ * with unsafe-eval). Do NOT use srcdoc/blob from the parent document: those
214
+ * inherit the parent CSP, which forbids unsafe-inline/unsafe-eval and leaves
215
+ * MDX fragment previews as empty white boxes.
216
+ */
217
+ export function buildSandboxSrcdoc() {
218
+ const bootstrap = `${SANDBOX_BUNDLE_HELPERS}(${sandboxFrameMain.toString()})({createSandboxRuntime:${createSandboxRuntime.toString()},runCompiledMdx:${runCompiledMdx.toString()}})`;
219
+ return [
220
+ '<!doctype html><html><head><meta charset="utf-8">',
221
+ `<meta http-equiv="Content-Security-Policy" content="${SANDBOX_FRAME_CSP}">`,
222
+ '<style>html,body{margin:0;padding:0}#__sandbox_root{box-sizing:border-box;display:flow-root}</style>',
223
+ // `conloca-prose` is the documented scope class for prose surfaces
224
+ // (the MDX editor's contenteditable carries it too). Sites can scope
225
+ // typography to `.conloca-prose <tag>` in their registered styles and
226
+ // it applies inside this sandbox as well as the editor.
227
+ '</head><body><div id="__sandbox_root" class="conloca-prose"></div>',
228
+ `<script>${bootstrap}</script>`,
229
+ '</body></html>',
230
+ ].join('');
231
+ }
232
+ /** Well-known path where a host serves {@link buildSandboxSrcdoc}. */
233
+ export const SANDBOX_FRAME_PATH = '/api/v1/mdx/sandbox-frame';
234
+ //# sourceMappingURL=sandbox-frame.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"sandbox-frame.js","sourceRoot":"","sources":["../src/sandbox-frame.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AA6BH,MAAM,UAAU,oBAAoB;IAMlC,MAAM,QAAQ,GAAG,MAAM,CAAC,kBAAkB,CAAC,CAAC;IAC5C,MAAM,OAAO,GAAG,CAAC,KAAc,EAAU,EAAE;QACzC,IAAI,KAAK,IAAI,IAAI,IAAI,KAAK,KAAK,IAAI,IAAI,KAAK,KAAK,KAAK;YAAE,OAAO,EAAE,CAAC;QAClE,IAAI,KAAK,CAAC,OAAO,CAAC,KAAK,CAAC;YAAE,OAAO,KAAK,CAAC,OAAO,CAAC,OAAO,CAAC,CAAC;QACxD,IAAI,OAAO,KAAK,KAAK,QAAQ,IAAI,OAAO,KAAK,KAAK,QAAQ;YAAE,OAAO,CAAC,QAAQ,CAAC,cAAc,CAAC,MAAM,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC;QAC5G,IAAI,KAAK,YAAY,IAAI;YAAE,OAAO,CAAC,KAAK,CAAC,CAAC;QAC1C,OAAO,CAAC,QAAQ,CAAC,cAAc,CAAC,MAAM,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC;IAClD,CAAC,CAAC;IACF,MAAM,GAAG,GAAG,CAAC,IAAa,EAAE,KAA8B,EAAQ,EAAE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AC,CAAC,MAAM,CAAC,KAAK,CAAC,EAAE,CAAC,CAAC;QACnH,CAAC;IACH,CAAC,CAAC,CAAC;IAEH,MAAM,SAAS,GACb,MACD,CAAC,cAAc,CAAC;IACjB,IAAI,SAAS;QAAE,IAAI,SAAS,CAAC,UAAU,CAAC,CAAC,OAAO,CAAC,IAAI,CAAC,CAAC;IACvD,IAAI,CAAC,EAAE,gBAAgB,EAAE,IAAI,EAAE,IAAI,EAAE,OAAO,EAAE,CAAC,CAAC;AAClD,CAAC;AAED;;;;;;;;;;;;;;;;;;;;;;GAsBG;AACH,MAAM,CAAC,MAAM,iBAAiB,GAC5B,4IAA4I,CAAC;AAE/I;;;;;GAKG;AACH,MAAM,sBAAsB,GAAG,qCAAqC,CAAC;AAErE;;;;;;;;;GASG;AACH,MAAM,UAAU,kBAAkB;IAChC,MAAM,SAAS,GAAG,GAAG,sBAAsB,IAAI,gBAAgB,CAAC,QAAQ,EAAE,2BAA2B,oBAAoB,CAAC,QAAQ,EAAE,mBAAmB,cAAc,CAAC,QAAQ,EAAE,IAAI,CAAC;IACrL,OAAO;QACL,mDAAmD;QACnD,uDAAuD,iBAAiB,IAAI;QAC5E,sGAAsG;QACtG,mEAAmE;QACnE,qEAAqE;QACrE,sEAAsE;QACtE,wDAAwD;QACxD,oEAAoE;QACpE,WAAW,SAAS,WAAW;QAC/B,gBAAgB;KACjB,CAAC,IAAI,CAAC,EAAE,CAAC,CAAC;AACb,CAAC;AAED,sEAAsE;AACtE,MAAM,CAAC,MAAM,kBAAkB,GAAG,2BAA2B,CAAC"}
@@ -0,0 +1,19 @@
1
+ import type { ComponentType } from 'react';
2
+ export type { MDXCompileResponse as MDXCompileResult, MDXHeading } from '@conloca/content-api';
3
+ import type { MDXHeading as Heading } from '@conloca/content-api';
4
+ export interface EvaluatedMDXFragment {
5
+ ok: true;
6
+ id: string;
7
+ title: string;
8
+ Component: ComponentType;
9
+ /** The fragment's headings, for a host block that shows a contents list. */
10
+ outline: readonly Heading[];
11
+ }
12
+ export interface FailedMDXFragmentEvaluation {
13
+ ok: false;
14
+ id: string;
15
+ title: string;
16
+ error: Error;
17
+ }
18
+ export type MDXFragmentEvaluationResult = EvaluatedMDXFragment | FailedMDXFragmentEvaluation;
19
+ //# sourceMappingURL=types.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,OAAO,CAAC;AAE3C,YAAY,EAAE,kBAAkB,IAAI,gBAAgB,EAAE,UAAU,EAAE,MAAM,sBAAsB,CAAC;AAE/F,OAAO,KAAK,EAAE,UAAU,IAAI,OAAO,EAAE,MAAM,sBAAsB,CAAC;AAElE,MAAM,WAAW,oBAAoB;IACnC,EAAE,EAAE,IAAI,CAAC;IACT,EAAE,EAAE,MAAM,CAAC;IACX,KAAK,EAAE,MAAM,CAAC;IACd,SAAS,EAAE,aAAa,CAAC;IACzB,4EAA4E;IAC5E,OAAO,EAAE,SAAS,OAAO,EAAE,CAAC;CAC7B;AAED,MAAM,WAAW,2BAA2B;IAC1C,EAAE,EAAE,KAAK,CAAC;IACV,EAAE,EAAE,MAAM,CAAC;IACX,KAAK,EAAE,MAAM,CAAC;IACd,KAAK,EAAE,KAAK,CAAC;CACd;AAED,MAAM,MAAM,2BAA2B,GAAG,oBAAoB,GAAG,2BAA2B,CAAC"}
package/dist/types.js ADDED
@@ -0,0 +1,2 @@
1
+ export {};
2
+ //# sourceMappingURL=types.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"types.js","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":""}