@stream-mdx/core 0.0.0 → 0.0.2

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 (55) hide show
  1. package/CHANGELOG.md +13 -0
  2. package/README.md +26 -37
  3. package/dist/code-highlighting.cjs +0 -1
  4. package/dist/code-highlighting.mjs +0 -1
  5. package/dist/index.cjs +94 -2
  6. package/dist/index.d.cts +1 -0
  7. package/dist/index.d.ts +1 -0
  8. package/dist/index.mjs +93 -2
  9. package/dist/inline-parser.cjs +0 -1
  10. package/dist/inline-parser.mjs +0 -1
  11. package/dist/mixed-content.cjs +0 -1
  12. package/dist/mixed-content.mjs +0 -1
  13. package/dist/perf/backpressure.cjs +0 -1
  14. package/dist/perf/backpressure.mjs +0 -1
  15. package/dist/perf/patch-batching.cjs +0 -1
  16. package/dist/perf/patch-batching.mjs +0 -1
  17. package/dist/perf/patch-coalescing.cjs +0 -1
  18. package/dist/perf/patch-coalescing.mjs +0 -1
  19. package/dist/security.cjs +1 -2
  20. package/dist/security.d.cts +1 -1
  21. package/dist/security.d.ts +1 -1
  22. package/dist/security.mjs +1 -2
  23. package/dist/streaming/custom-matcher.cjs +118 -0
  24. package/dist/streaming/custom-matcher.d.cts +22 -0
  25. package/dist/streaming/custom-matcher.d.ts +22 -0
  26. package/dist/streaming/custom-matcher.mjs +93 -0
  27. package/dist/types.cjs +0 -1
  28. package/dist/types.mjs +0 -1
  29. package/dist/utils.cjs +0 -1
  30. package/dist/utils.mjs +0 -1
  31. package/dist/worker-html-sanitizer.cjs +0 -1
  32. package/dist/worker-html-sanitizer.mjs +0 -1
  33. package/package.json +12 -2
  34. package/dist/code-highlighting.cjs.map +0 -1
  35. package/dist/code-highlighting.mjs.map +0 -1
  36. package/dist/index.cjs.map +0 -1
  37. package/dist/index.mjs.map +0 -1
  38. package/dist/inline-parser.cjs.map +0 -1
  39. package/dist/inline-parser.mjs.map +0 -1
  40. package/dist/mixed-content.cjs.map +0 -1
  41. package/dist/mixed-content.mjs.map +0 -1
  42. package/dist/perf/backpressure.cjs.map +0 -1
  43. package/dist/perf/backpressure.mjs.map +0 -1
  44. package/dist/perf/patch-batching.cjs.map +0 -1
  45. package/dist/perf/patch-batching.mjs.map +0 -1
  46. package/dist/perf/patch-coalescing.cjs.map +0 -1
  47. package/dist/perf/patch-coalescing.mjs.map +0 -1
  48. package/dist/security.cjs.map +0 -1
  49. package/dist/security.mjs.map +0 -1
  50. package/dist/types.cjs.map +0 -1
  51. package/dist/types.mjs.map +0 -1
  52. package/dist/utils.cjs.map +0 -1
  53. package/dist/utils.mjs.map +0 -1
  54. package/dist/worker-html-sanitizer.cjs.map +0 -1
  55. package/dist/worker-html-sanitizer.mjs.map +0 -1
package/CHANGELOG.md ADDED
@@ -0,0 +1,13 @@
1
+ # @stream-mdx/core
2
+
3
+ ## 0.0.2
4
+
5
+ ### Patch Changes
6
+
7
+ - 9e94660: Docs and release-quality improvements: ship package READMEs/CHANGELOGs, add pack+install smoke tests, expose MDX parity helper entrypoints, and add a deployable docs site workflow.
8
+
9
+ ## 0.0.1
10
+
11
+ ### Patch Changes
12
+
13
+ - Release maintenance: CI/build fixes, missing runtime deps (e.g. `rehype-katex`), and improved docs/README wiring for the `stream-mdx` package page.
package/README.md CHANGED
@@ -1,6 +1,10 @@
1
1
  # `@stream-mdx/core`
2
2
 
3
- Pure TypeScript primitives shared across the streaming renderer stack. This package intentionally contains **no DOM/React code**; everything exported is structured-clone-safe so it can cross `postMessage` boundaries without serialization hacks.
3
+ Core types + utilities shared across the StreamMDX stack.
4
+
5
+ This package is intentionally React-free. It contains structured-clone-safe types and helpers used by both the worker and the renderer.
6
+
7
+ Most consumers should install `stream-mdx` and follow the main docs. Use `@stream-mdx/core` directly if you’re building tooling or customizing lower-level behavior.
4
8
 
5
9
  ## Install
6
10
 
@@ -8,47 +12,32 @@ Pure TypeScript primitives shared across the streaming renderer stack. This pack
8
12
  npm install @stream-mdx/core
9
13
  ```
10
14
 
11
- ## Exports
15
+ ## Entry points
12
16
 
13
- | Module | Description |
14
- | --- | --- |
15
- | `types` | `Block`, `InlineNode`, `Patch`, `PatchBatch`, `RendererMetrics`, worker message unions. |
16
- | `block-snapshot` | Helpers for cloning/mutating block trees in the worker. |
17
- | `code-highlighting` | Shiki token utilities (`CodeLine`, `flattenHighlights`). |
18
- | `mixed-content` | Inline HTML/Multi-block parsing helpers. |
19
- | `inline-parser` | Incremental inline AST parser (Lezer wrappers). |
20
- | `security` | Sanitization schema + trusted-types friendly helpers. |
21
- | `utils` | Tree traversal, node ID generation, list depth normalization. |
22
- | `perf/backpressure` | Back-pressure defaults + smoothing functions shared by worker/renderer. |
23
- | `worker-html-sanitizer` | Preconfigured DOMPurify-like sanitization for worker context. |
17
+ - `@stream-mdx/core` (root)
18
+ - `@stream-mdx/core/types`
19
+ - `@stream-mdx/core/utils`
20
+ - `@stream-mdx/core/code-highlighting`
21
+ - `@stream-mdx/core/inline-parser`
22
+ - `@stream-mdx/core/mixed-content`
23
+ - `@stream-mdx/core/worker-html-sanitizer`
24
+ - `@stream-mdx/core/security`
25
+ - `@stream-mdx/core/perf/backpressure`
26
+ - `@stream-mdx/core/perf/patch-batching`
27
+ - `@stream-mdx/core/perf/patch-coalescing`
28
+ - `@stream-mdx/core/streaming/custom-matcher`
24
29
 
25
- See `packages/markdown-v2-core/src/index.ts` for the canonical export list.
26
-
27
- ## Usage
30
+ ## Example
28
31
 
29
32
  ```ts
30
- import type { Patch } from "@stream-mdx/core";
31
- import { applyPatchBatch } from "@stream-mdx/core/block-snapshot";
32
-
33
- export function replay(patches: Patch[]) {
34
- const snapshot = createInitialSnapshot();
35
- for (const patch of patches) {
36
- applyPatchBatch(snapshot, [patch]);
37
- }
38
- return snapshot;
33
+ import { DEFAULT_BACKPRESSURE_CONFIG } from "@stream-mdx/core/perf/backpressure";
34
+
35
+ export function makeConfig(overrides?: Partial<typeof DEFAULT_BACKPRESSURE_CONFIG>) {
36
+ return { ...DEFAULT_BACKPRESSURE_CONFIG, ...overrides };
39
37
  }
40
38
  ```
41
39
 
42
- The worker bundle (`@stream-mdx/worker`) consumes these helpers to build `Patch` batches, and the renderer uses the same types for its store/scheduler.
43
-
44
- > For end-to-end math/MDX registration steps (worker + renderer), see [`docs/STREAMING_MARKDOWN_PLUGINS_COOKBOOK.md#5-math--mdx-workerrenderer-registration`](../../docs/STREAMING_MARKDOWN_PLUGINS_COOKBOOK.md#5-math--mdx-workerrenderer-registration).
45
-
46
- ## Security notes
47
-
48
- - Sanitization helpers assume you pass trusted markdown inputs or run the worker in an isolated thread. If you enable raw HTML rendering, ensure you serve KaTeX/MDX assets from trusted origins and set CSP headers accordingly.
49
- - `worker-html-sanitizer` exports a minimal schema. Override/augment it if you need to allow additional tags/attributes (e.g., custom `data-*` props).
50
-
51
- ## Roadmap
40
+ ## Docs
52
41
 
53
- - Document semver guarantees once `1.0.0` ships.
54
- - Publish detailed inline docs for every exported type (linkable from `docs/PUBLIC_API.md`).
42
+ - API reference: `docs/PUBLIC_API.md`
43
+ - Security model: `docs/SECURITY_MODEL.md`
@@ -217,4 +217,3 @@ function filterAllowedAttributes(attrs) {
217
217
  extractHighlightedLines,
218
218
  stripCodeFence
219
219
  });
220
- //# sourceMappingURL=code-highlighting.cjs.map
@@ -188,4 +188,3 @@ export {
188
188
  extractHighlightedLines,
189
189
  stripCodeFence
190
190
  };
191
- //# sourceMappingURL=code-highlighting.mjs.map
package/dist/index.cjs CHANGED
@@ -31,6 +31,7 @@ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: tru
31
31
  var index_exports = {};
32
32
  __export(index_exports, {
33
33
  CSP_HEADERS: () => CSP_HEADERS,
34
+ CustomStreamingMatcher: () => CustomStreamingMatcher,
34
35
  DEFAULT_BACKPRESSURE_CONFIG: () => DEFAULT_BACKPRESSURE_CONFIG,
35
36
  DEFAULT_COALESCE_CONFIG: () => DEFAULT_COALESCE_CONFIG,
36
37
  InlineParser: () => InlineParser,
@@ -1997,7 +1998,7 @@ function createTrustedHTML(html) {
1997
1998
  if (trustedTypesPolicy) {
1998
1999
  return trustedTypesPolicy.createHTML(html);
1999
2000
  }
2000
- return resolveDOMPurify().sanitize(html, getSanitizationConfig());
2001
+ return sanitizeHTML(html);
2001
2002
  }
2002
2003
  function sanitizeHTML(html) {
2003
2004
  const out = resolveDOMPurify().sanitize(html, getSanitizationConfig());
@@ -2707,9 +2708,101 @@ function coalescePatchesQuadratic(patches, config = DEFAULT_COALESCE_CONFIG) {
2707
2708
  }
2708
2709
  return [...coalesced, ...rest];
2709
2710
  }
2711
+
2712
+ // src/streaming/custom-matcher.ts
2713
+ var CustomStreamingMatcher = class {
2714
+ constructor(pattern) {
2715
+ this.buffer = "";
2716
+ this.possibleMatches = [];
2717
+ this.pattern = pattern;
2718
+ }
2719
+ addCharacter(char) {
2720
+ this.buffer += char;
2721
+ const fullMatch = this.buffer.match(this.pattern);
2722
+ if (fullMatch && fullMatch.index === 0) {
2723
+ const match = {
2724
+ matched: true,
2725
+ content: fullMatch[0],
2726
+ length: fullMatch[0].length,
2727
+ isComplete: true
2728
+ };
2729
+ this.buffer = this.buffer.slice(fullMatch[0].length);
2730
+ this.possibleMatches = [];
2731
+ return match;
2732
+ }
2733
+ const confidence = this.calculatePartialConfidence();
2734
+ return {
2735
+ matched: false,
2736
+ content: this.buffer,
2737
+ length: this.buffer.length,
2738
+ isComplete: false,
2739
+ confidence
2740
+ };
2741
+ }
2742
+ addString(str) {
2743
+ const results = [];
2744
+ for (const char of str) {
2745
+ const result = this.addCharacter(char);
2746
+ if (result.matched) {
2747
+ results.push(result);
2748
+ }
2749
+ }
2750
+ if (results.length === 0 && this.buffer.length > 0) {
2751
+ results.push({
2752
+ matched: false,
2753
+ content: this.buffer,
2754
+ length: this.buffer.length,
2755
+ isComplete: false,
2756
+ confidence: this.calculatePartialConfidence()
2757
+ });
2758
+ }
2759
+ return results;
2760
+ }
2761
+ couldMatch() {
2762
+ if (this.buffer.length === 0) return true;
2763
+ const patternSource = this.pattern.source;
2764
+ const flags = this.pattern.flags;
2765
+ try {
2766
+ const partialPattern = new RegExp(`^${patternSource.replace(/\\$$/, "")}`, flags);
2767
+ const testString = this.buffer + "X".repeat(100);
2768
+ return partialPattern.test(testString);
2769
+ } catch {
2770
+ return this.isValidPrefix();
2771
+ }
2772
+ }
2773
+ reset() {
2774
+ this.buffer = "";
2775
+ this.possibleMatches = [];
2776
+ }
2777
+ getBuffer() {
2778
+ return this.buffer;
2779
+ }
2780
+ calculatePartialConfidence() {
2781
+ if (this.buffer.length === 0) return 0;
2782
+ let confidence = 0.1;
2783
+ confidence += Math.min(0.4, this.buffer.length * 0.1);
2784
+ if (this.couldMatch()) {
2785
+ confidence += 0.3;
2786
+ }
2787
+ if (this.buffer.startsWith("$")) confidence += 0.2;
2788
+ if (this.buffer.startsWith("$$")) confidence += 0.3;
2789
+ return Math.min(1, confidence);
2790
+ }
2791
+ isValidPrefix() {
2792
+ const patternStr = this.pattern.source;
2793
+ if (patternStr.includes("\\$\\$") && (this.buffer === "$" || this.buffer === "$$")) {
2794
+ return true;
2795
+ }
2796
+ if (patternStr.includes("\\$") && this.buffer === "$") {
2797
+ return true;
2798
+ }
2799
+ return false;
2800
+ }
2801
+ };
2710
2802
  // Annotate the CommonJS export names for ESM import in node:
2711
2803
  0 && (module.exports = {
2712
2804
  CSP_HEADERS,
2805
+ CustomStreamingMatcher,
2713
2806
  DEFAULT_BACKPRESSURE_CONFIG,
2714
2807
  DEFAULT_COALESCE_CONFIG,
2715
2808
  InlineParser,
@@ -2761,4 +2854,3 @@ function coalescePatchesQuadratic(patches, config = DEFAULT_COALESCE_CONFIG) {
2761
2854
  smoothCredit,
2762
2855
  stripCodeFence
2763
2856
  });
2764
- //# sourceMappingURL=index.cjs.map
package/dist/index.d.cts CHANGED
@@ -8,6 +8,7 @@ export { InlineParseOptions, InlineParser, InlineParserOptions, applyASTPlugin,
8
8
  export { sanitizeHtmlInWorker } from './worker-html-sanitizer.cjs';
9
9
  export { BackpressureConfig, DEFAULT_BACKPRESSURE_CONFIG, calculateRawCredit, calculateSmoothedCredit, clampCredit, computeHeavyPatchBudget, smoothCredit } from './perf/backpressure.cjs';
10
10
  export { CoalesceConfig, DEFAULT_COALESCE_CONFIG, coalescePatches, coalescePatchesLinear, coalescePatchesQuadratic, coalescePatchesWithMetrics } from './perf/patch-coalescing.cjs';
11
+ export { CustomStreamingMatcher, MatchResult } from './streaming/custom-matcher.cjs';
11
12
  import 'dompurify';
12
13
 
13
14
  declare function cloneBlock(block: Block): Block;
package/dist/index.d.ts CHANGED
@@ -8,6 +8,7 @@ export { InlineParseOptions, InlineParser, InlineParserOptions, applyASTPlugin,
8
8
  export { sanitizeHtmlInWorker } from './worker-html-sanitizer.js';
9
9
  export { BackpressureConfig, DEFAULT_BACKPRESSURE_CONFIG, calculateRawCredit, calculateSmoothedCredit, clampCredit, computeHeavyPatchBudget, smoothCredit } from './perf/backpressure.js';
10
10
  export { CoalesceConfig, DEFAULT_COALESCE_CONFIG, coalescePatches, coalescePatchesLinear, coalescePatchesQuadratic, coalescePatchesWithMetrics } from './perf/patch-coalescing.js';
11
+ export { CustomStreamingMatcher, MatchResult } from './streaming/custom-matcher.js';
11
12
  import 'dompurify';
12
13
 
13
14
  declare function cloneBlock(block: Block): Block;
package/dist/index.mjs CHANGED
@@ -1911,7 +1911,7 @@ function createTrustedHTML(html) {
1911
1911
  if (trustedTypesPolicy) {
1912
1912
  return trustedTypesPolicy.createHTML(html);
1913
1913
  }
1914
- return resolveDOMPurify().sanitize(html, getSanitizationConfig());
1914
+ return sanitizeHTML(html);
1915
1915
  }
1916
1916
  function sanitizeHTML(html) {
1917
1917
  const out = resolveDOMPurify().sanitize(html, getSanitizationConfig());
@@ -2621,8 +2621,100 @@ function coalescePatchesQuadratic(patches, config = DEFAULT_COALESCE_CONFIG) {
2621
2621
  }
2622
2622
  return [...coalesced, ...rest];
2623
2623
  }
2624
+
2625
+ // src/streaming/custom-matcher.ts
2626
+ var CustomStreamingMatcher = class {
2627
+ constructor(pattern) {
2628
+ this.buffer = "";
2629
+ this.possibleMatches = [];
2630
+ this.pattern = pattern;
2631
+ }
2632
+ addCharacter(char) {
2633
+ this.buffer += char;
2634
+ const fullMatch = this.buffer.match(this.pattern);
2635
+ if (fullMatch && fullMatch.index === 0) {
2636
+ const match = {
2637
+ matched: true,
2638
+ content: fullMatch[0],
2639
+ length: fullMatch[0].length,
2640
+ isComplete: true
2641
+ };
2642
+ this.buffer = this.buffer.slice(fullMatch[0].length);
2643
+ this.possibleMatches = [];
2644
+ return match;
2645
+ }
2646
+ const confidence = this.calculatePartialConfidence();
2647
+ return {
2648
+ matched: false,
2649
+ content: this.buffer,
2650
+ length: this.buffer.length,
2651
+ isComplete: false,
2652
+ confidence
2653
+ };
2654
+ }
2655
+ addString(str) {
2656
+ const results = [];
2657
+ for (const char of str) {
2658
+ const result = this.addCharacter(char);
2659
+ if (result.matched) {
2660
+ results.push(result);
2661
+ }
2662
+ }
2663
+ if (results.length === 0 && this.buffer.length > 0) {
2664
+ results.push({
2665
+ matched: false,
2666
+ content: this.buffer,
2667
+ length: this.buffer.length,
2668
+ isComplete: false,
2669
+ confidence: this.calculatePartialConfidence()
2670
+ });
2671
+ }
2672
+ return results;
2673
+ }
2674
+ couldMatch() {
2675
+ if (this.buffer.length === 0) return true;
2676
+ const patternSource = this.pattern.source;
2677
+ const flags = this.pattern.flags;
2678
+ try {
2679
+ const partialPattern = new RegExp(`^${patternSource.replace(/\\$$/, "")}`, flags);
2680
+ const testString = this.buffer + "X".repeat(100);
2681
+ return partialPattern.test(testString);
2682
+ } catch {
2683
+ return this.isValidPrefix();
2684
+ }
2685
+ }
2686
+ reset() {
2687
+ this.buffer = "";
2688
+ this.possibleMatches = [];
2689
+ }
2690
+ getBuffer() {
2691
+ return this.buffer;
2692
+ }
2693
+ calculatePartialConfidence() {
2694
+ if (this.buffer.length === 0) return 0;
2695
+ let confidence = 0.1;
2696
+ confidence += Math.min(0.4, this.buffer.length * 0.1);
2697
+ if (this.couldMatch()) {
2698
+ confidence += 0.3;
2699
+ }
2700
+ if (this.buffer.startsWith("$")) confidence += 0.2;
2701
+ if (this.buffer.startsWith("$$")) confidence += 0.3;
2702
+ return Math.min(1, confidence);
2703
+ }
2704
+ isValidPrefix() {
2705
+ const patternStr = this.pattern.source;
2706
+ if (patternStr.includes("\\$\\$") && (this.buffer === "$" || this.buffer === "$$")) {
2707
+ return true;
2708
+ }
2709
+ if (patternStr.includes("\\$") && this.buffer === "$") {
2710
+ return true;
2711
+ }
2712
+ return false;
2713
+ }
2714
+ };
2624
2715
  export {
2625
2716
  CSP_HEADERS,
2717
+ CustomStreamingMatcher,
2626
2718
  DEFAULT_BACKPRESSURE_CONFIG,
2627
2719
  DEFAULT_COALESCE_CONFIG,
2628
2720
  InlineParser,
@@ -2674,4 +2766,3 @@ export {
2674
2766
  smoothCredit,
2675
2767
  stripCodeFence
2676
2768
  };
2677
- //# sourceMappingURL=index.mjs.map
@@ -293,4 +293,3 @@ function splitTextByRegexWithPrecedence(text, regex, toNode) {
293
293
  applyASTPlugin,
294
294
  applyRegexPlugin
295
295
  });
296
- //# sourceMappingURL=inline-parser.cjs.map
@@ -266,4 +266,3 @@ export {
266
266
  applyASTPlugin,
267
267
  applyRegexPlugin
268
268
  };
269
- //# sourceMappingURL=inline-parser.mjs.map
@@ -370,4 +370,3 @@ function findClosingHtmlTag(lowerSource, lowerTagName, startIndex) {
370
370
  findClosingHtmlTag,
371
371
  isLikelyMdxComponent
372
372
  });
373
- //# sourceMappingURL=mixed-content.cjs.map
@@ -331,4 +331,3 @@ export {
331
331
  findClosingHtmlTag,
332
332
  isLikelyMdxComponent
333
333
  };
334
- //# sourceMappingURL=mixed-content.mjs.map
@@ -101,4 +101,3 @@ function clamp01(value) {
101
101
  computeHeavyPatchBudget,
102
102
  smoothCredit
103
103
  });
104
- //# sourceMappingURL=backpressure.cjs.map
@@ -71,4 +71,3 @@ export {
71
71
  computeHeavyPatchBudget,
72
72
  smoothCredit
73
73
  };
74
- //# sourceMappingURL=backpressure.mjs.map
@@ -135,4 +135,3 @@ function splitPatchBatch(patches, maxLightChunk = DEFAULT_MAX_LIGHT_PATCHES_PER_
135
135
  isHeavyPatch,
136
136
  splitPatchBatch
137
137
  });
138
- //# sourceMappingURL=patch-batching.cjs.map
@@ -109,4 +109,3 @@ export {
109
109
  isHeavyPatch,
110
110
  splitPatchBatch
111
111
  };
112
- //# sourceMappingURL=patch-batching.mjs.map
@@ -427,4 +427,3 @@ function coalescePatchesQuadratic(patches, config = DEFAULT_COALESCE_CONFIG) {
427
427
  coalescePatchesQuadratic,
428
428
  coalescePatchesWithMetrics
429
429
  });
430
- //# sourceMappingURL=patch-coalescing.cjs.map
@@ -398,4 +398,3 @@ export {
398
398
  coalescePatchesQuadratic,
399
399
  coalescePatchesWithMetrics
400
400
  };
401
- //# sourceMappingURL=patch-coalescing.mjs.map
package/dist/security.cjs CHANGED
@@ -154,7 +154,7 @@ function createTrustedHTML(html) {
154
154
  if (trustedTypesPolicy) {
155
155
  return trustedTypesPolicy.createHTML(html);
156
156
  }
157
- return resolveDOMPurify().sanitize(html, getSanitizationConfig());
157
+ return sanitizeHTML(html);
158
158
  }
159
159
  function sanitizeHTML(html) {
160
160
  const out = resolveDOMPurify().sanitize(html, getSanitizationConfig());
@@ -416,4 +416,3 @@ function initializeSecurity() {
416
416
  sanitizeMathHTML,
417
417
  sanitizeURL
418
418
  });
419
- //# sourceMappingURL=security.cjs.map
@@ -7,7 +7,7 @@ declare function initializeTrustedTypesPolicy(): void;
7
7
  /**
8
8
  * Create trusted HTML using DOMPurify and Trusted Types
9
9
  */
10
- declare function createTrustedHTML(html: string): TrustedHTML | string;
10
+ declare function createTrustedHTML(html: string): string;
11
11
  /**
12
12
  * Sanitize HTML content for safe rendering
13
13
  */
@@ -7,7 +7,7 @@ declare function initializeTrustedTypesPolicy(): void;
7
7
  /**
8
8
  * Create trusted HTML using DOMPurify and Trusted Types
9
9
  */
10
- declare function createTrustedHTML(html: string): TrustedHTML | string;
10
+ declare function createTrustedHTML(html: string): string;
11
11
  /**
12
12
  * Sanitize HTML content for safe rendering
13
13
  */
package/dist/security.mjs CHANGED
@@ -112,7 +112,7 @@ function createTrustedHTML(html) {
112
112
  if (trustedTypesPolicy) {
113
113
  return trustedTypesPolicy.createHTML(html);
114
114
  }
115
- return resolveDOMPurify().sanitize(html, getSanitizationConfig());
115
+ return sanitizeHTML(html);
116
116
  }
117
117
  function sanitizeHTML(html) {
118
118
  const out = resolveDOMPurify().sanitize(html, getSanitizationConfig());
@@ -373,4 +373,3 @@ export {
373
373
  sanitizeMathHTML,
374
374
  sanitizeURL
375
375
  };
376
- //# sourceMappingURL=security.mjs.map
@@ -0,0 +1,118 @@
1
+ "use strict";
2
+ var __defProp = Object.defineProperty;
3
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
+ var __getOwnPropNames = Object.getOwnPropertyNames;
5
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
6
+ var __export = (target, all) => {
7
+ for (var name in all)
8
+ __defProp(target, name, { get: all[name], enumerable: true });
9
+ };
10
+ var __copyProps = (to, from, except, desc) => {
11
+ if (from && typeof from === "object" || typeof from === "function") {
12
+ for (let key of __getOwnPropNames(from))
13
+ if (!__hasOwnProp.call(to, key) && key !== except)
14
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
15
+ }
16
+ return to;
17
+ };
18
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
19
+
20
+ // src/streaming/custom-matcher.ts
21
+ var custom_matcher_exports = {};
22
+ __export(custom_matcher_exports, {
23
+ CustomStreamingMatcher: () => CustomStreamingMatcher
24
+ });
25
+ module.exports = __toCommonJS(custom_matcher_exports);
26
+ var CustomStreamingMatcher = class {
27
+ constructor(pattern) {
28
+ this.buffer = "";
29
+ this.possibleMatches = [];
30
+ this.pattern = pattern;
31
+ }
32
+ addCharacter(char) {
33
+ this.buffer += char;
34
+ const fullMatch = this.buffer.match(this.pattern);
35
+ if (fullMatch && fullMatch.index === 0) {
36
+ const match = {
37
+ matched: true,
38
+ content: fullMatch[0],
39
+ length: fullMatch[0].length,
40
+ isComplete: true
41
+ };
42
+ this.buffer = this.buffer.slice(fullMatch[0].length);
43
+ this.possibleMatches = [];
44
+ return match;
45
+ }
46
+ const confidence = this.calculatePartialConfidence();
47
+ return {
48
+ matched: false,
49
+ content: this.buffer,
50
+ length: this.buffer.length,
51
+ isComplete: false,
52
+ confidence
53
+ };
54
+ }
55
+ addString(str) {
56
+ const results = [];
57
+ for (const char of str) {
58
+ const result = this.addCharacter(char);
59
+ if (result.matched) {
60
+ results.push(result);
61
+ }
62
+ }
63
+ if (results.length === 0 && this.buffer.length > 0) {
64
+ results.push({
65
+ matched: false,
66
+ content: this.buffer,
67
+ length: this.buffer.length,
68
+ isComplete: false,
69
+ confidence: this.calculatePartialConfidence()
70
+ });
71
+ }
72
+ return results;
73
+ }
74
+ couldMatch() {
75
+ if (this.buffer.length === 0) return true;
76
+ const patternSource = this.pattern.source;
77
+ const flags = this.pattern.flags;
78
+ try {
79
+ const partialPattern = new RegExp(`^${patternSource.replace(/\\$$/, "")}`, flags);
80
+ const testString = this.buffer + "X".repeat(100);
81
+ return partialPattern.test(testString);
82
+ } catch {
83
+ return this.isValidPrefix();
84
+ }
85
+ }
86
+ reset() {
87
+ this.buffer = "";
88
+ this.possibleMatches = [];
89
+ }
90
+ getBuffer() {
91
+ return this.buffer;
92
+ }
93
+ calculatePartialConfidence() {
94
+ if (this.buffer.length === 0) return 0;
95
+ let confidence = 0.1;
96
+ confidence += Math.min(0.4, this.buffer.length * 0.1);
97
+ if (this.couldMatch()) {
98
+ confidence += 0.3;
99
+ }
100
+ if (this.buffer.startsWith("$")) confidence += 0.2;
101
+ if (this.buffer.startsWith("$$")) confidence += 0.3;
102
+ return Math.min(1, confidence);
103
+ }
104
+ isValidPrefix() {
105
+ const patternStr = this.pattern.source;
106
+ if (patternStr.includes("\\$\\$") && (this.buffer === "$" || this.buffer === "$$")) {
107
+ return true;
108
+ }
109
+ if (patternStr.includes("\\$") && this.buffer === "$") {
110
+ return true;
111
+ }
112
+ return false;
113
+ }
114
+ };
115
+ // Annotate the CommonJS export names for ESM import in node:
116
+ 0 && (module.exports = {
117
+ CustomStreamingMatcher
118
+ });
@@ -0,0 +1,22 @@
1
+ declare class CustomStreamingMatcher {
2
+ private pattern;
3
+ private buffer;
4
+ private possibleMatches;
5
+ constructor(pattern: RegExp);
6
+ addCharacter(char: string): MatchResult;
7
+ addString(str: string): MatchResult[];
8
+ couldMatch(): boolean;
9
+ reset(): void;
10
+ getBuffer(): string;
11
+ private calculatePartialConfidence;
12
+ private isValidPrefix;
13
+ }
14
+ interface MatchResult {
15
+ matched: boolean;
16
+ content: string;
17
+ length: number;
18
+ isComplete: boolean;
19
+ confidence?: number;
20
+ }
21
+
22
+ export { CustomStreamingMatcher, type MatchResult };
@@ -0,0 +1,22 @@
1
+ declare class CustomStreamingMatcher {
2
+ private pattern;
3
+ private buffer;
4
+ private possibleMatches;
5
+ constructor(pattern: RegExp);
6
+ addCharacter(char: string): MatchResult;
7
+ addString(str: string): MatchResult[];
8
+ couldMatch(): boolean;
9
+ reset(): void;
10
+ getBuffer(): string;
11
+ private calculatePartialConfidence;
12
+ private isValidPrefix;
13
+ }
14
+ interface MatchResult {
15
+ matched: boolean;
16
+ content: string;
17
+ length: number;
18
+ isComplete: boolean;
19
+ confidence?: number;
20
+ }
21
+
22
+ export { CustomStreamingMatcher, type MatchResult };