@markitdownjs/optimizer 0.1.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.
package/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2024 MarkItDownJS Contributors
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
@@ -0,0 +1,4 @@
1
+ export { Optimizer } from "./optimizer.js";
2
+ export type { OptimizerConfig, OptimizerRule } from "./types.js";
3
+ export { BUILTIN_RULES } from "./rules.js";
4
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,MAAM,gBAAgB,CAAC;AAC3C,YAAY,EAAE,eAAe,EAAE,aAAa,EAAE,MAAM,YAAY,CAAC;AACjE,OAAO,EAAE,aAAa,EAAE,MAAM,YAAY,CAAC"}
package/dist/index.js ADDED
@@ -0,0 +1,3 @@
1
+ export { Optimizer } from "./optimizer.js";
2
+ export { BUILTIN_RULES } from "./rules.js";
3
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,MAAM,gBAAgB,CAAC;AAE3C,OAAO,EAAE,aAAa,EAAE,MAAM,YAAY,CAAC"}
@@ -0,0 +1,25 @@
1
+ import type { DocumentNode } from "@markitdownjs/shared";
2
+ import type { OptimizerConfig } from "./types.js";
3
+ /**
4
+ * Semantic noise collapsing pipeline.
5
+ * Runs rules on the AST before rendering to reduce token count.
6
+ * Target: 15-30% reduction on typical enterprise documents.
7
+ */
8
+ export declare class Optimizer {
9
+ private rules;
10
+ constructor(config: OptimizerConfig);
11
+ /**
12
+ * Run all rules on an AST and return the optimized AST.
13
+ * Rules are applied in order. A rule returning null removes the node.
14
+ */
15
+ optimize(ast: DocumentNode): DocumentNode;
16
+ /**
17
+ * Apply a single rule to the entire AST tree.
18
+ */
19
+ private applyRule;
20
+ /**
21
+ * Get the list of active rule names.
22
+ */
23
+ getRuleNames(): string[];
24
+ }
25
+ //# sourceMappingURL=optimizer.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"optimizer.d.ts","sourceRoot":"","sources":["../src/optimizer.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAW,YAAY,EAAE,MAAM,sBAAsB,CAAC;AAClE,OAAO,KAAK,EAAE,eAAe,EAAiB,MAAM,YAAY,CAAC;AAGjE;;;;GAIG;AACH,qBAAa,SAAS;IACpB,OAAO,CAAC,KAAK,CAAkB;gBAEnB,MAAM,EAAE,eAAe;IAqBnC;;;OAGG;IACH,QAAQ,CAAC,GAAG,EAAE,YAAY,GAAG,YAAY;IAazC;;OAEG;IACH,OAAO,CAAC,SAAS;IAqBjB;;OAEG;IACH,YAAY,IAAI,MAAM,EAAE;CAGzB"}
@@ -0,0 +1,70 @@
1
+ import { BUILTIN_RULES } from "./rules.js";
2
+ /**
3
+ * Semantic noise collapsing pipeline.
4
+ * Runs rules on the AST before rendering to reduce token count.
5
+ * Target: 15-30% reduction on typical enterprise documents.
6
+ */
7
+ export class Optimizer {
8
+ rules;
9
+ constructor(config) {
10
+ this.rules = [];
11
+ // Resolve built-in rules by name.
12
+ for (const rule of config.rules) {
13
+ if (typeof rule === "string") {
14
+ const builtin = BUILTIN_RULES[rule];
15
+ if (builtin) {
16
+ this.rules.push(builtin);
17
+ }
18
+ }
19
+ else {
20
+ this.rules.push(rule);
21
+ }
22
+ }
23
+ // Append custom rules.
24
+ if (config.custom) {
25
+ this.rules.push(...config.custom);
26
+ }
27
+ }
28
+ /**
29
+ * Run all rules on an AST and return the optimized AST.
30
+ * Rules are applied in order. A rule returning null removes the node.
31
+ */
32
+ optimize(ast) {
33
+ const optimized = { ...ast, children: [...(ast.children ?? [])] };
34
+ for (const rule of this.rules) {
35
+ const result = this.applyRule(optimized, rule);
36
+ if (result && result.type === "document") {
37
+ Object.assign(optimized, result);
38
+ }
39
+ }
40
+ return optimized;
41
+ }
42
+ /**
43
+ * Apply a single rule to the entire AST tree.
44
+ */
45
+ applyRule(node, rule) {
46
+ if ("children" in node && Array.isArray(node.children)) {
47
+ const children = [];
48
+ for (const child of node.children) {
49
+ const result = this.applyRule(child, rule);
50
+ if (result !== null) {
51
+ children.push(result);
52
+ }
53
+ }
54
+ node = { ...node, children };
55
+ }
56
+ // Apply rule to the current node.
57
+ if (rule.applies(node)) {
58
+ const result = rule.transform(node);
59
+ return result ?? node;
60
+ }
61
+ return node;
62
+ }
63
+ /**
64
+ * Get the list of active rule names.
65
+ */
66
+ getRuleNames() {
67
+ return this.rules.map((r) => r.name);
68
+ }
69
+ }
70
+ //# sourceMappingURL=optimizer.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"optimizer.js","sourceRoot":"","sources":["../src/optimizer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ACnB,CAAC;IAED;;OAEG;IACK,SAAS,CAAC,IAAa,EAAE,IAAmB;QAClD,IAAI,UAAU,IAAI,IAAI,IAAI,KAAK,CAAC,OAAO,CAAC,IAAI,CAAC,QAAQ,CAAC,EAAE,CAAC;YACvD,MAAM,QAAQ,GAAc,EAAE,CAAC;YAC/B,KAAK,MAAM,KAAK,IAAI,IAAI,CAAC,QAAQ,EAAE,CAAC;gBAClC,MAAM,MAAM,GAAG,IAAI,CAAC,SAAS,CAAC,KAAK,EAAE,IAAI,CAAC,CAAC;gBAC3C,IAAI,MAAM,KAAK,IAAI,EAAE,CAAC;oBACpB,QAAQ,CAAC,IAAI,CAAC,MAAM,CAAC,CAAC;gBACxB,CAAC;YACH,CAAC;YACD,IAAI,GAAG,EAAE,GAAG,IAAI,EAAE,QAAQ,EAAE,CAAC;QAC/B,CAAC;QAED,kCAAkC;QAClC,IAAI,IAAI,CAAC,OAAO,CAAC,IAAoB,CAAC,EAAE,CAAC;YACvC,MAAM,MAAM,GAAG,IAAI,CAAC,SAAS,CAAC,IAAI,CAAC,CAAC;YACpC,OAAO,MAAM,IAAI,IAAI,CAAC;QACxB,CAAC;QAED,OAAO,IAAI,CAAC;IACd,CAAC;IAED;;OAEG;IACH,YAAY;QACV,OAAO,IAAI,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,IAAI,CAAC,CAAC;IACvC,CAAC;CACF"}
@@ -0,0 +1,16 @@
1
+ import type { OptimizerRule } from "./types.js";
2
+ /** Strip decorative images (badge SVGs, tracking pixels, icons) */
3
+ export declare const stripDecorativeImages: OptimizerRule;
4
+ /** Collapse repeated table headers (CSV/XLSX with repeated header rows) */
5
+ export declare const collapseRepeatedHeaders: OptimizerRule;
6
+ /** Remove HTML comment blocks from HtmlNode values */
7
+ export declare const removeHtmlComments: OptimizerRule;
8
+ /** Strip whitespace-only text nodes */
9
+ export declare const stripWhitespaceColumns: OptimizerRule;
10
+ /** Deduplicate consecutive identical list items */
11
+ export declare const deduplicateListItems: OptimizerRule;
12
+ /** Strip boilerplate text (copyright footers, page markers) */
13
+ export declare const stripBoilerplate: OptimizerRule;
14
+ /** All built-in rules */
15
+ export declare const BUILTIN_RULES: Record<string, OptimizerRule>;
16
+ //# sourceMappingURL=rules.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"rules.d.ts","sourceRoot":"","sources":["../src/rules.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,YAAY,CAAC;AAWhD,mEAAmE;AACnE,eAAO,MAAM,qBAAqB,EAAE,aAWnC,CAAC;AAEF,2EAA2E;AAC3E,eAAO,MAAM,uBAAuB,EAAE,aAQrC,CAAC;AAEF,sDAAsD;AACtD,eAAO,MAAM,kBAAkB,EAAE,aAYhC,CAAC;AAEF,uCAAuC;AACvC,eAAO,MAAM,sBAAsB,EAAE,aAWpC,CAAC;AAEF,mDAAmD;AACnD,eAAO,MAAM,oBAAoB,EAAE,aAmBlC,CAAC;AAEF,+DAA+D;AAC/D,eAAO,MAAM,gBAAgB,EAAE,aAU9B,CAAC;AAEF,yBAAyB;AACzB,eAAO,MAAM,aAAa,EAAE,MAAM,CAAC,MAAM,EAAE,aAAa,CAOvD,CAAC"}
package/dist/rules.js ADDED
@@ -0,0 +1,103 @@
1
+ /** Regex for decorative/tracking image patterns */
2
+ const DECORATIVE_IMG_RE = /pixel|tracking|spacer|blank|1x1|badge|icon|spinner|loading|analytics/i;
3
+ /** Regex for HTML comments */
4
+ const HTML_COMMENT_RE = /<!--[\s\S]*?-->/g;
5
+ /** Regex for boilerplate footer text */
6
+ const BOILERPLATE_RE = /page \d+ of \d+|copyright ©|\(c\)\s*\d{4}|all rights reserved/i;
7
+ /** Strip decorative images (badge SVGs, tracking pixels, icons) */
8
+ export const stripDecorativeImages = {
9
+ name: "strip-decorative-images",
10
+ applies: () => true,
11
+ transform: (node) => {
12
+ if (node.type === "image") {
13
+ const img = node;
14
+ if (DECORATIVE_IMG_RE.test(img.src))
15
+ return null;
16
+ if (img.width === 1 && img.height === 1)
17
+ return null;
18
+ }
19
+ return node;
20
+ },
21
+ };
22
+ /** Collapse repeated table headers (CSV/XLSX with repeated header rows) */
23
+ export const collapseRepeatedHeaders = {
24
+ name: "collapse-repeated-headers",
25
+ applies: () => true,
26
+ transform: (node) => {
27
+ // This is a placeholder — actual implementation needs table row comparison.
28
+ // The optimizer applies this at the table level in a post-processing step.
29
+ return node;
30
+ },
31
+ };
32
+ /** Remove HTML comment blocks from HtmlNode values */
33
+ export const removeHtmlComments = {
34
+ name: "remove-html-comments",
35
+ applies: () => true,
36
+ transform: (node) => {
37
+ if (node.type === "html") {
38
+ const html = node;
39
+ const cleaned = html.value.replace(HTML_COMMENT_RE, "").trim();
40
+ if (!cleaned)
41
+ return null;
42
+ return { ...html, value: cleaned };
43
+ }
44
+ return node;
45
+ },
46
+ };
47
+ /** Strip whitespace-only text nodes */
48
+ export const stripWhitespaceColumns = {
49
+ name: "strip-whitespace-columns",
50
+ applies: () => true,
51
+ transform: (node) => {
52
+ if (node.type === "text") {
53
+ const text = node;
54
+ const cleaned = text.value.replace(/[ \t]{2,}/g, " ");
55
+ return { ...text, value: cleaned };
56
+ }
57
+ return node;
58
+ },
59
+ };
60
+ /** Deduplicate consecutive identical list items */
61
+ export const deduplicateListItems = {
62
+ name: "deduplicate-list-items",
63
+ applies: () => true,
64
+ transform: (node) => {
65
+ if (node.type === "list") {
66
+ const list = node;
67
+ const deduped = [];
68
+ let lastText = "";
69
+ for (const item of list.children) {
70
+ const text = JSON.stringify(item);
71
+ if (text !== lastText) {
72
+ deduped.push(item);
73
+ lastText = text;
74
+ }
75
+ }
76
+ return { ...list, children: deduped };
77
+ }
78
+ return node;
79
+ },
80
+ };
81
+ /** Strip boilerplate text (copyright footers, page markers) */
82
+ export const stripBoilerplate = {
83
+ name: "strip-boilerplate",
84
+ applies: () => true,
85
+ transform: (node) => {
86
+ if (node.type === "paragraph" || node.type === "text") {
87
+ const text = "value" in node ? node.value : "";
88
+ if (BOILERPLATE_RE.test(text))
89
+ return null;
90
+ }
91
+ return node;
92
+ },
93
+ };
94
+ /** All built-in rules */
95
+ export const BUILTIN_RULES = {
96
+ "strip-decorative-images": stripDecorativeImages,
97
+ "collapse-repeated-headers": collapseRepeatedHeaders,
98
+ "remove-html-comments": removeHtmlComments,
99
+ "strip-whitespace-columns": stripWhitespaceColumns,
100
+ "deduplicate-list-items": deduplicateListItems,
101
+ "strip-boilerplate": stripBoilerplate,
102
+ };
103
+ //# sourceMappingURL=rules.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"rules.js","sourceRoot":"","sources":["../src/rules.ts"],"names":[],"mappings":"AAGA,mDAAmD;AACnD,MAAM,iBAAiB,GAAG,uEAAuE,CAAC;AAElG,8BAA8B;AAC9B,MAAM,eAAe,GAAG,kBAAkB,CAAC;AAE3C,wCAAwC;AACxC,MAAM,cAAc,GAAG,gEAAgE,CAAC;AAExF,mEAAmE;AACnE,MAAM,CAAC,MAAM,qBAAqB,GAAkB;IAClD,IAAI,EAAE,yBAAyB;IAC/B,OAAO,EAAE,GAAG,EAAE,CAAC,IAAI;IACnB,SAAS,EAAE,CAAC,IAAa,EAAkB,EAAE;QAC3C,IAAI,IAAI,CAAC,IAAI,KAAK,OAAO,EAAE,CAAC;YAC1B,MAAM,GAAG,GAAG,IAAiB,CAAC;YAC9B,IAAI,iBAAiB,CAAC,IAAI,CAAC,GAAG,CAAC,GAAG,CAAC;gBAAE,OAAO,IAAI,CAAC;YACjD,IAAI,GAAG,CAAC,KAAK,KAAK,CAAC,IAAI,GAAG,CAAC,MAAM,KAAK,CAAC;gBAAE,OAAO,IAAI,CAAC;QACvD,CAAC;QACD,OAAO,IAAI,CAAC;IACd,CAAC;CACF,CAAC;AAEF,2EAA2E;AAC3E,MAAM,CAAC,MAAM,uBAAuB,GAAkB;IACpD,IAAI,EAAE,2BAA2B;IACjC,OAAO,EAAE,GAAG,EAAE,C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BAAqB;IAChD,2BAA2B,EAAE,uBAAuB;IACpD,sBAAsB,EAAE,kBAAkB;IAC1C,0BAA0B,EAAE,sBAAsB;IAClD,wBAAwB,EAAE,oBAAoB;IAC9C,mBAAmB,EAAE,gBAAgB;CACtC,CAAC"}
@@ -0,0 +1,18 @@
1
+ import type { AnyNode, DocumentNode } from "@markitdownjs/shared";
2
+ /** An optimizer rule that transforms an AST to reduce noise */
3
+ export interface OptimizerRule {
4
+ /** Human-readable rule name */
5
+ name: string;
6
+ /** Returns true if this rule should be applied to the given AST */
7
+ applies: (node: DocumentNode) => boolean;
8
+ /** Transform the AST node. Return null to remove the node, or the transformed node. */
9
+ transform: (node: AnyNode) => AnyNode | null;
10
+ }
11
+ /** Configuration for the Optimizer */
12
+ export interface OptimizerConfig {
13
+ /** Rules to apply (built-in rule names or custom OptimizerRule instances) */
14
+ rules: (string | OptimizerRule)[];
15
+ /** Custom rules (appended after built-in rules) */
16
+ custom?: OptimizerRule[];
17
+ }
18
+ //# 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,OAAO,EAAE,YAAY,EAAE,MAAM,sBAAsB,CAAC;AAElE,+DAA+D;AAC/D,MAAM,WAAW,aAAa;IAC5B,+BAA+B;IAC/B,IAAI,EAAE,MAAM,CAAC;IACb,mEAAmE;IACnE,OAAO,EAAE,CAAC,IAAI,EAAE,YAAY,KAAK,OAAO,CAAC;IACzC,uFAAuF;IACvF,SAAS,EAAE,CAAC,IAAI,EAAE,OAAO,KAAK,OAAO,GAAG,IAAI,CAAC;CAC9C;AAED,sCAAsC;AACtC,MAAM,WAAW,eAAe;IAC9B,6EAA6E;IAC7E,KAAK,EAAE,CAAC,MAAM,GAAG,aAAa,CAAC,EAAE,CAAC;IAClC,mDAAmD;IACnD,MAAM,CAAC,EAAE,aAAa,EAAE,CAAC;CAC1B"}
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":""}
package/package.json ADDED
@@ -0,0 +1,31 @@
1
+ {
2
+ "name": "@markitdownjs/optimizer",
3
+ "version": "0.1.0",
4
+ "description": "Semantic noise collapsing pipeline for MarkItDownJS",
5
+ "license": "MIT",
6
+ "type": "module",
7
+ "main": "./dist/index.js",
8
+ "module": "./dist/index.js",
9
+ "types": "./dist/index.d.ts",
10
+ "exports": {
11
+ ".": {
12
+ "import": "./dist/index.js",
13
+ "types": "./dist/index.d.ts"
14
+ }
15
+ },
16
+ "files": [
17
+ "dist"
18
+ ],
19
+ "dependencies": {
20
+ "@markitdownjs/shared": "0.2.0"
21
+ },
22
+ "devDependencies": {
23
+ "typescript": "^5.5.0"
24
+ },
25
+ "scripts": {
26
+ "build": "tsc --project tsconfig.json",
27
+ "dev": "tsc --watch --project tsconfig.json",
28
+ "typecheck": "tsc --noEmit",
29
+ "clean": "rm -rf dist tsconfig.tsbuildinfo"
30
+ }
31
+ }