@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.
- package/CHANGELOG.md +13 -0
- package/README.md +26 -37
- package/dist/code-highlighting.cjs +0 -1
- package/dist/code-highlighting.mjs +0 -1
- package/dist/index.cjs +94 -2
- package/dist/index.d.cts +1 -0
- package/dist/index.d.ts +1 -0
- package/dist/index.mjs +93 -2
- package/dist/inline-parser.cjs +0 -1
- package/dist/inline-parser.mjs +0 -1
- package/dist/mixed-content.cjs +0 -1
- package/dist/mixed-content.mjs +0 -1
- package/dist/perf/backpressure.cjs +0 -1
- package/dist/perf/backpressure.mjs +0 -1
- package/dist/perf/patch-batching.cjs +0 -1
- package/dist/perf/patch-batching.mjs +0 -1
- package/dist/perf/patch-coalescing.cjs +0 -1
- package/dist/perf/patch-coalescing.mjs +0 -1
- package/dist/security.cjs +1 -2
- package/dist/security.d.cts +1 -1
- package/dist/security.d.ts +1 -1
- package/dist/security.mjs +1 -2
- package/dist/streaming/custom-matcher.cjs +118 -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 +93 -0
- package/dist/types.cjs +0 -1
- package/dist/types.mjs +0 -1
- package/dist/utils.cjs +0 -1
- package/dist/utils.mjs +0 -1
- package/dist/worker-html-sanitizer.cjs +0 -1
- package/dist/worker-html-sanitizer.mjs +0 -1
- package/package.json +12 -2
- package/dist/code-highlighting.cjs.map +0 -1
- package/dist/code-highlighting.mjs.map +0 -1
- package/dist/index.cjs.map +0 -1
- package/dist/index.mjs.map +0 -1
- package/dist/inline-parser.cjs.map +0 -1
- package/dist/inline-parser.mjs.map +0 -1
- package/dist/mixed-content.cjs.map +0 -1
- package/dist/mixed-content.mjs.map +0 -1
- package/dist/perf/backpressure.cjs.map +0 -1
- package/dist/perf/backpressure.mjs.map +0 -1
- package/dist/perf/patch-batching.cjs.map +0 -1
- package/dist/perf/patch-batching.mjs.map +0 -1
- package/dist/perf/patch-coalescing.cjs.map +0 -1
- package/dist/perf/patch-coalescing.mjs.map +0 -1
- package/dist/security.cjs.map +0 -1
- package/dist/security.mjs.map +0 -1
- package/dist/types.cjs.map +0 -1
- package/dist/types.mjs.map +0 -1
- package/dist/utils.cjs.map +0 -1
- package/dist/utils.mjs.map +0 -1
- package/dist/worker-html-sanitizer.cjs.map +0 -1
- 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
|
-
|
|
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
|
-
##
|
|
15
|
+
## Entry points
|
|
12
16
|
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
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
|
-
|
|
26
|
-
|
|
27
|
-
## Usage
|
|
30
|
+
## Example
|
|
28
31
|
|
|
29
32
|
```ts
|
|
30
|
-
import
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
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
|
-
|
|
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
|
-
-
|
|
54
|
-
-
|
|
42
|
+
- API reference: `docs/PUBLIC_API.md`
|
|
43
|
+
- Security model: `docs/SECURITY_MODEL.md`
|
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
|
|
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
|
|
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
|
package/dist/inline-parser.cjs
CHANGED
package/dist/inline-parser.mjs
CHANGED
package/dist/mixed-content.cjs
CHANGED
package/dist/mixed-content.mjs
CHANGED
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
|
|
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
|
package/dist/security.d.cts
CHANGED
|
@@ -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):
|
|
10
|
+
declare function createTrustedHTML(html: string): string;
|
|
11
11
|
/**
|
|
12
12
|
* Sanitize HTML content for safe rendering
|
|
13
13
|
*/
|
package/dist/security.d.ts
CHANGED
|
@@ -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):
|
|
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
|
|
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 };
|