@stream-mdx/core 0.0.0 → 0.0.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.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,