@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 +94 -1
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +1 -0
- package/dist/index.d.ts +1 -0
- package/dist/index.mjs +93 -1
- package/dist/index.mjs.map +1 -1
- package/dist/security.cjs +1 -1
- package/dist/security.cjs.map +1 -1
- package/dist/security.d.cts +1 -1
- package/dist/security.d.ts +1 -1
- package/dist/security.mjs +1 -1
- package/dist/security.mjs.map +1 -1
- package/dist/streaming/custom-matcher.cjs +119 -0
- package/dist/streaming/custom-matcher.cjs.map +1 -0
- package/dist/streaming/custom-matcher.d.cts +22 -0
- package/dist/streaming/custom-matcher.d.ts +22 -0
- package/dist/streaming/custom-matcher.mjs +94 -0
- package/dist/streaming/custom-matcher.mjs.map +1 -0
- package/package.json +10 -2
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
|
|
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,
|