nuxt-ai-ready 2.4.1 → 2.5.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/README.md +8 -4
- package/dist/chunks/agent-skills.mjs +1 -1
- package/dist/chunks/prerender.mjs +1 -1
- package/dist/module.json +1 -1
- package/dist/module.mjs +1 -1
- package/dist/runtime/app/plugins/md-hints.prerender.js +4 -4
- package/dist/runtime/llms-txt-utils.js +2 -6
- package/dist/runtime/markdown-path.d.ts +7 -3
- package/dist/runtime/markdown-path.js +6 -6
- package/dist/runtime/server/db/queries.js +28 -5
- package/dist/runtime/server/middleware/markdown.js +1 -1
- package/dist/runtime/server/middleware/markdown.prerender.js +1 -0
- package/dist/runtime/server/utils/checkStale.js +13 -2
- package/dist/runtime/server/utils/cloudflare.js +3 -1
- package/dist/runtime/server/utils/frontmatter.d.ts +6 -0
- package/dist/runtime/server/utils/frontmatter.js +23 -1
- package/dist/runtime/server/utils/indexPage.js +4 -1
- package/dist/runtime/server/utils/sitemap-routes.js +2 -1
- package/dist/runtime/server/utils.d.ts +8 -4
- package/dist/runtime/server/utils.js +15 -19
- package/dist/runtime/types.d.ts +8 -4
- package/dist/shared/{nuxt-ai-ready.CxJE2WLA.mjs → nuxt-ai-ready.CLSWou20.mjs} +6 -10
- package/node_modules/@mdream/js/LICENSE.md +9 -0
- package/node_modules/@mdream/js/README.md +792 -0
- package/node_modules/@mdream/js/bin/mdream.mjs +2 -0
- package/node_modules/@mdream/js/dist/_chunks/const.mjs +134 -0
- package/node_modules/@mdream/js/dist/_chunks/index.d.mts +9 -0
- package/node_modules/@mdream/js/dist/_chunks/markdown-processor.mjs +1968 -0
- package/node_modules/@mdream/js/dist/_chunks/minimal.d.mts +6 -0
- package/node_modules/@mdream/js/dist/_chunks/parse.mjs +2756 -0
- package/node_modules/@mdream/js/dist/_chunks/plugins.mjs +725 -0
- package/node_modules/@mdream/js/dist/_chunks/resolve-plugins.mjs +44 -0
- package/node_modules/@mdream/js/dist/_chunks/stream.mjs +37 -0
- package/node_modules/@mdream/js/dist/_chunks/types.d.mts +473 -0
- package/node_modules/@mdream/js/dist/cli.d.mts +1 -0
- package/node_modules/@mdream/js/dist/cli.mjs +32 -0
- package/node_modules/@mdream/js/dist/core.d.mts +15 -0
- package/node_modules/@mdream/js/dist/core.mjs +28 -0
- package/node_modules/@mdream/js/dist/index.d.mts +4 -0
- package/node_modules/@mdream/js/dist/index.mjs +58 -0
- package/node_modules/@mdream/js/dist/llms-txt.d.mts +86 -0
- package/node_modules/@mdream/js/dist/llms-txt.mjs +308 -0
- package/node_modules/@mdream/js/dist/negotiate.d.mts +35 -0
- package/node_modules/@mdream/js/dist/negotiate.mjs +121 -0
- package/node_modules/@mdream/js/dist/parse.d.mts +90 -0
- package/node_modules/@mdream/js/dist/parse.mjs +2 -0
- package/node_modules/@mdream/js/dist/plugins.d.mts +85 -0
- package/node_modules/@mdream/js/dist/plugins.mjs +2 -0
- package/node_modules/@mdream/js/dist/preset/minimal.d.mts +2 -0
- package/node_modules/@mdream/js/dist/preset/minimal.mjs +33 -0
- package/node_modules/@mdream/js/dist/splitter.d.mts +18 -0
- package/node_modules/@mdream/js/dist/splitter.mjs +194 -0
- package/node_modules/@mdream/js/package.json +103 -0
- package/node_modules/cac/LICENSE +21 -0
- package/node_modules/cac/README.md +492 -0
- package/node_modules/cac/dist/index.d.ts +196 -0
- package/node_modules/cac/dist/index.js +638 -0
- package/node_modules/cac/package.json +72 -0
- package/node_modules/mdream/LICENSE.md +9 -0
- package/node_modules/mdream/README.md +1091 -0
- package/node_modules/mdream/bin/mdream.mjs +46 -0
- package/node_modules/mdream/dist/browser.d.mts +105 -0
- package/node_modules/mdream/dist/browser.mjs +262 -0
- package/node_modules/mdream/dist/edge.d.mts +100 -0
- package/node_modules/mdream/dist/edge.mjs +250 -0
- package/node_modules/mdream/dist/iife.js +605 -0
- package/node_modules/mdream/dist/index.d.mts +89 -0
- package/node_modules/mdream/dist/index.mjs +184 -0
- package/node_modules/mdream/dist/wasm.d.mts +100 -0
- package/node_modules/mdream/dist/wasm.mjs +140 -0
- package/node_modules/mdream/dist/worker.d.mts +101 -0
- package/node_modules/mdream/dist/worker.mjs +217 -0
- package/node_modules/mdream/napi/index.d.mts +127 -0
- package/node_modules/mdream/napi/index.d.ts +127 -0
- package/node_modules/mdream/napi/index.mjs +725 -0
- package/node_modules/mdream/napi/rust.android-arm-eabi.node +0 -0
- package/node_modules/mdream/napi/rust.android-arm64.node +0 -0
- package/node_modules/mdream/napi/rust.darwin-arm64.node +0 -0
- package/node_modules/mdream/napi/rust.darwin-x64.node +0 -0
- package/node_modules/mdream/napi/rust.freebsd-x64.node +0 -0
- package/node_modules/mdream/napi/rust.linux-arm-gnueabihf.node +0 -0
- package/node_modules/mdream/napi/rust.linux-arm64-gnu.node +0 -0
- package/node_modules/mdream/napi/rust.linux-arm64-musl.node +0 -0
- package/node_modules/mdream/napi/rust.linux-x64-gnu.node +0 -0
- package/node_modules/mdream/napi/rust.linux-x64-musl.node +0 -0
- package/node_modules/mdream/napi/rust.wasi.cjs +2144 -0
- package/node_modules/mdream/napi/rust.wasm32-wasi.wasm +0 -0
- package/node_modules/mdream/napi/rust.win32-arm64-msvc.node +0 -0
- package/node_modules/mdream/napi/rust.win32-x64-msvc.node +0 -0
- package/node_modules/mdream/node_modules/@emnapi/core/LICENSE +21 -0
- package/node_modules/mdream/node_modules/@emnapi/core/README.md +1 -0
- package/node_modules/mdream/node_modules/@emnapi/core/dist/emnapi-core.d.ts +392 -0
- package/node_modules/mdream/node_modules/@emnapi/core/dist/emnapi-core.full.d.ts +392 -0
- package/node_modules/mdream/node_modules/@emnapi/core/dist/emnapi-core.full.js +8351 -0
- package/node_modules/mdream/node_modules/@emnapi/core/dist/emnapi-core.js +7268 -0
- package/node_modules/mdream/node_modules/@emnapi/core/dist/plugins/async-work.d.ts +5 -0
- package/node_modules/mdream/node_modules/@emnapi/core/dist/plugins/async-work.js +843 -0
- package/node_modules/mdream/node_modules/@emnapi/core/dist/plugins/index.d.ts +4 -0
- package/node_modules/mdream/node_modules/@emnapi/core/dist/plugins/index.js +3 -0
- package/node_modules/mdream/node_modules/@emnapi/core/dist/plugins/threadsafe-function.d.ts +5 -0
- package/node_modules/mdream/node_modules/@emnapi/core/dist/plugins/threadsafe-function.js +1010 -0
- package/node_modules/mdream/node_modules/@emnapi/core/dist/plugins/v8.d.ts +5 -0
- package/node_modules/mdream/node_modules/@emnapi/core/dist/plugins/v8.js +1446 -0
- package/node_modules/mdream/node_modules/@emnapi/core/package.json +39 -0
- package/node_modules/mdream/node_modules/@emnapi/core/rollup.config.js +60 -0
- package/node_modules/mdream/node_modules/@emnapi/runtime/LICENSE +21 -0
- package/node_modules/mdream/node_modules/@emnapi/runtime/README.md +1 -0
- package/node_modules/mdream/node_modules/@emnapi/runtime/dist/emnapi.d.ts +833 -0
- package/node_modules/mdream/node_modules/@emnapi/runtime/dist/emnapi.js +2306 -0
- package/node_modules/mdream/node_modules/@emnapi/runtime/dist/emnapi.js.map +1 -0
- package/node_modules/mdream/node_modules/@emnapi/runtime/index.cjs +63 -0
- package/node_modules/mdream/node_modules/@emnapi/runtime/package.json +39 -0
- package/node_modules/mdream/node_modules/@emnapi/runtime/rollup.config.js +25 -0
- package/node_modules/mdream/node_modules/@emnapi/wasi-threads/LICENSE +21 -0
- package/node_modules/mdream/node_modules/@emnapi/wasi-threads/README.md +203 -0
- package/node_modules/mdream/node_modules/@emnapi/wasi-threads/dist/wasi-threads.d.ts +236 -0
- package/node_modules/mdream/node_modules/@emnapi/wasi-threads/dist/wasi-threads.js +1086 -0
- package/node_modules/mdream/node_modules/@emnapi/wasi-threads/package.json +35 -0
- package/node_modules/mdream/node_modules/@emnapi/wasi-threads/rollup.config.js +6 -0
- package/node_modules/mdream/node_modules/@napi-rs/wasm-runtime/dist/emnapi-plugins.cjs +1472 -0
- package/node_modules/mdream/node_modules/@napi-rs/wasm-runtime/dist/emnapi-plugins.js +1470 -0
- package/node_modules/mdream/node_modules/@napi-rs/wasm-runtime/dist/fs-proxy.cjs +237 -0
- package/node_modules/mdream/node_modules/@napi-rs/wasm-runtime/dist/fs.js +18260 -0
- package/node_modules/mdream/node_modules/@napi-rs/wasm-runtime/fs-proxy.js +317 -0
- package/node_modules/mdream/node_modules/@napi-rs/wasm-runtime/package.json +67 -0
- package/node_modules/mdream/node_modules/@napi-rs/wasm-runtime/runtime.cjs +39 -0
- package/node_modules/mdream/node_modules/@napi-rs/wasm-runtime/runtime.js +36 -0
- package/node_modules/mdream/node_modules/@tybys/wasm-util/LICENSE +21 -0
- package/node_modules/mdream/node_modules/@tybys/wasm-util/README.md +193 -0
- package/node_modules/mdream/node_modules/@tybys/wasm-util/dist/tsdoc-metadata.json +11 -0
- package/node_modules/mdream/node_modules/@tybys/wasm-util/dist/wasm-util.d.ts +423 -0
- package/node_modules/mdream/node_modules/@tybys/wasm-util/dist/wasm-util.esm-bundler.js +2932 -0
- package/node_modules/mdream/node_modules/@tybys/wasm-util/dist/wasm-util.esm.js +2932 -0
- package/node_modules/mdream/node_modules/@tybys/wasm-util/dist/wasm-util.esm.min.js +1 -0
- package/node_modules/mdream/node_modules/@tybys/wasm-util/dist/wasm-util.js +2954 -0
- package/node_modules/mdream/node_modules/@tybys/wasm-util/dist/wasm-util.min.js +1 -0
- package/node_modules/mdream/node_modules/@tybys/wasm-util/lib/cjs/asyncify.js +158 -0
- package/node_modules/mdream/node_modules/@tybys/wasm-util/lib/cjs/index.js +13 -0
- package/node_modules/mdream/node_modules/@tybys/wasm-util/lib/cjs/jspi.js +46 -0
- package/node_modules/mdream/node_modules/@tybys/wasm-util/lib/cjs/load.js +97 -0
- package/node_modules/mdream/node_modules/@tybys/wasm-util/lib/cjs/memory.js +35 -0
- package/node_modules/mdream/node_modules/@tybys/wasm-util/lib/cjs/wasi/error.js +103 -0
- package/node_modules/mdream/node_modules/@tybys/wasm-util/lib/cjs/wasi/fd.js +268 -0
- package/node_modules/mdream/node_modules/@tybys/wasm-util/lib/cjs/wasi/fs.js +3 -0
- package/node_modules/mdream/node_modules/@tybys/wasm-util/lib/cjs/wasi/index.js +192 -0
- package/node_modules/mdream/node_modules/@tybys/wasm-util/lib/cjs/wasi/path.js +316 -0
- package/node_modules/mdream/node_modules/@tybys/wasm-util/lib/cjs/wasi/preview1.js +1599 -0
- package/node_modules/mdream/node_modules/@tybys/wasm-util/lib/cjs/wasi/rights.js +141 -0
- package/node_modules/mdream/node_modules/@tybys/wasm-util/lib/cjs/wasi/types.js +220 -0
- package/node_modules/mdream/node_modules/@tybys/wasm-util/lib/cjs/wasi/util.js +128 -0
- package/node_modules/mdream/node_modules/@tybys/wasm-util/lib/cjs/webassembly.js +13 -0
- package/node_modules/mdream/node_modules/@tybys/wasm-util/lib/mjs/asyncify.mjs +153 -0
- package/node_modules/mdream/node_modules/@tybys/wasm-util/lib/mjs/index.mjs +9 -0
- package/node_modules/mdream/node_modules/@tybys/wasm-util/lib/mjs/jspi.mjs +39 -0
- package/node_modules/mdream/node_modules/@tybys/wasm-util/lib/mjs/load.mjs +89 -0
- package/node_modules/mdream/node_modules/@tybys/wasm-util/lib/mjs/memory.mjs +28 -0
- package/node_modules/mdream/node_modules/@tybys/wasm-util/lib/mjs/wasi/error.mjs +97 -0
- package/node_modules/mdream/node_modules/@tybys/wasm-util/lib/mjs/wasi/fd.mjs +256 -0
- package/node_modules/mdream/node_modules/@tybys/wasm-util/lib/mjs/wasi/fs.mjs +1 -0
- package/node_modules/mdream/node_modules/@tybys/wasm-util/lib/mjs/wasi/index.mjs +186 -0
- package/node_modules/mdream/node_modules/@tybys/wasm-util/lib/mjs/wasi/path.mjs +310 -0
- package/node_modules/mdream/node_modules/@tybys/wasm-util/lib/mjs/wasi/preview1.mjs +1593 -0
- package/node_modules/mdream/node_modules/@tybys/wasm-util/lib/mjs/wasi/rights.mjs +135 -0
- package/node_modules/mdream/node_modules/@tybys/wasm-util/lib/mjs/wasi/types.mjs +216 -0
- package/node_modules/mdream/node_modules/@tybys/wasm-util/lib/mjs/wasi/util.mjs +113 -0
- package/node_modules/mdream/node_modules/@tybys/wasm-util/lib/mjs/webassembly.mjs +9 -0
- package/node_modules/mdream/node_modules/@tybys/wasm-util/package.json +58 -0
- package/node_modules/mdream/node_modules/tslib/CopyrightNotice.txt +15 -0
- package/node_modules/mdream/node_modules/tslib/LICENSE.txt +12 -0
- package/node_modules/mdream/node_modules/tslib/README.md +164 -0
- package/node_modules/mdream/node_modules/tslib/SECURITY.md +41 -0
- package/node_modules/mdream/node_modules/tslib/modules/index.d.ts +38 -0
- package/node_modules/mdream/node_modules/tslib/modules/index.js +70 -0
- package/node_modules/mdream/node_modules/tslib/modules/package.json +3 -0
- package/node_modules/mdream/node_modules/tslib/package.json +47 -0
- package/node_modules/mdream/node_modules/tslib/tslib.d.ts +460 -0
- package/node_modules/mdream/node_modules/tslib/tslib.es6.html +1 -0
- package/node_modules/mdream/node_modules/tslib/tslib.es6.js +402 -0
- package/node_modules/mdream/node_modules/tslib/tslib.es6.mjs +401 -0
- package/node_modules/mdream/node_modules/tslib/tslib.html +1 -0
- package/node_modules/mdream/node_modules/tslib/tslib.js +484 -0
- package/node_modules/mdream/package.json +110 -0
- package/node_modules/mdream/skills/mdream/SKILL.md +124 -0
- package/node_modules/mdream/skills/mdream/references/runtimes.md +49 -0
- package/node_modules/mdream/wasm/mdream_edge.d.ts +90 -0
- package/node_modules/mdream/wasm/mdream_edge.js +517 -0
- package/node_modules/mdream/wasm/mdream_edge_bg.wasm +0 -0
- package/node_modules/mdream/wasm/mdream_edge_bg.wasm.d.ts +20 -0
- package/node_modules/mdream/wasm/package.json +17 -0
- package/node_modules/mdream/wasm-bundler/mdream_edge.d.ts +45 -0
- package/node_modules/mdream/wasm-bundler/mdream_edge.js +13 -0
- package/node_modules/mdream/wasm-bundler/mdream_edge_bg.js +413 -0
- package/node_modules/mdream/wasm-bundler/mdream_edge_bg.wasm +0 -0
- package/node_modules/mdream/wasm-bundler/mdream_edge_bg.wasm.d.ts +20 -0
- package/node_modules/mdream/wasm-bundler/package.json +19 -0
- package/node_modules/pathe/LICENSE +70 -0
- package/node_modules/pathe/README.md +73 -0
- package/node_modules/pathe/dist/index.cjs +39 -0
- package/node_modules/pathe/dist/index.d.cts +47 -0
- package/node_modules/pathe/dist/index.d.mts +47 -0
- package/node_modules/pathe/dist/index.d.ts +47 -0
- package/node_modules/pathe/dist/index.mjs +19 -0
- package/node_modules/pathe/dist/shared/pathe.BSlhyZSM.cjs +266 -0
- package/node_modules/pathe/dist/shared/pathe.M-eThtNZ.mjs +249 -0
- package/node_modules/pathe/dist/utils.cjs +82 -0
- package/node_modules/pathe/dist/utils.d.cts +32 -0
- package/node_modules/pathe/dist/utils.d.mts +32 -0
- package/node_modules/pathe/dist/utils.d.ts +32 -0
- package/node_modules/pathe/dist/utils.mjs +77 -0
- package/node_modules/pathe/package.json +61 -0
- package/node_modules/pathe/utils.d.ts +1 -0
- package/package.json +11 -67
- package/skills/nuxt-ai-ready/SKILL.md +123 -0
- package/skills/nuxt-ai-ready/references/runtime-indexing.md +75 -0
- package/dist/runtime/server/plugins/mcp-data.d.ts +0 -10
- package/dist/runtime/server/plugins/mcp-data.js +0 -22
|
@@ -0,0 +1,725 @@
|
|
|
1
|
+
import { TagIdMap } from "./const.mjs";
|
|
2
|
+
function createPlugin(plugin) {
|
|
3
|
+
return plugin;
|
|
4
|
+
}
|
|
5
|
+
function createTagSelector(tagName) {
|
|
6
|
+
return {
|
|
7
|
+
matches: (element) => element.name === tagName,
|
|
8
|
+
toString: () => tagName
|
|
9
|
+
};
|
|
10
|
+
}
|
|
11
|
+
function createIdSelector(selector) {
|
|
12
|
+
const id = selector.slice(1);
|
|
13
|
+
return {
|
|
14
|
+
matches: (element) => element.attributes?.id === id,
|
|
15
|
+
toString: () => `#${id}`
|
|
16
|
+
};
|
|
17
|
+
}
|
|
18
|
+
function createClassSelector(selector) {
|
|
19
|
+
const className = selector.slice(1);
|
|
20
|
+
return {
|
|
21
|
+
matches: (element) => {
|
|
22
|
+
if (!element.attributes?.class) return false;
|
|
23
|
+
return element.attributes.class.trim().split(" ").filter(Boolean).includes(className);
|
|
24
|
+
},
|
|
25
|
+
toString: () => `.${className}`
|
|
26
|
+
};
|
|
27
|
+
}
|
|
28
|
+
function parseAttributeSelector(selector) {
|
|
29
|
+
if (selector.charCodeAt(0) !== 91) return null;
|
|
30
|
+
const end = selector.indexOf("]", 1);
|
|
31
|
+
if (end === -1) return null;
|
|
32
|
+
const inner = selector.slice(1, end);
|
|
33
|
+
let opIdx = -1;
|
|
34
|
+
for (let i = 0; i < inner.length; i++) {
|
|
35
|
+
const c = inner.charCodeAt(i);
|
|
36
|
+
if (c === 61 || c === 126 || c === 124 || c === 94 || c === 36 || c === 42) {
|
|
37
|
+
opIdx = i;
|
|
38
|
+
break;
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
if (opIdx === -1) return { attr: inner };
|
|
42
|
+
const attr = inner.slice(0, opIdx);
|
|
43
|
+
let opEnd = opIdx + 1;
|
|
44
|
+
if (opEnd < inner.length && inner.charCodeAt(opEnd) === 61) opEnd++;
|
|
45
|
+
const op = inner.slice(opIdx, opEnd);
|
|
46
|
+
let value = inner.slice(opEnd);
|
|
47
|
+
if ((value.charCodeAt(0) === 34 || value.charCodeAt(0) === 39) && value.charCodeAt(value.length - 1) === value.charCodeAt(0)) value = value.slice(1, -1);
|
|
48
|
+
return {
|
|
49
|
+
attr,
|
|
50
|
+
op,
|
|
51
|
+
value
|
|
52
|
+
};
|
|
53
|
+
}
|
|
54
|
+
function createAttributeSelector(selector) {
|
|
55
|
+
const parsed = parseAttributeSelector(selector);
|
|
56
|
+
const attrName = parsed ? parsed.attr : selector.slice(1, -1);
|
|
57
|
+
const operator = parsed?.op;
|
|
58
|
+
const attrValue = parsed?.value;
|
|
59
|
+
return {
|
|
60
|
+
matches: (element) => {
|
|
61
|
+
if (!(attrName in (element.attributes || {}))) return false;
|
|
62
|
+
if (!operator || !attrValue) return true;
|
|
63
|
+
const value = element.attributes[attrName];
|
|
64
|
+
if (value === void 0) return false;
|
|
65
|
+
switch (operator) {
|
|
66
|
+
case "=": return value === attrValue;
|
|
67
|
+
case "^=": return value.startsWith(attrValue);
|
|
68
|
+
case "$=": return value.endsWith(attrValue);
|
|
69
|
+
case "*=": return value.includes(attrValue);
|
|
70
|
+
case "~=": return value.trim().split(" ").filter(Boolean).includes(attrValue);
|
|
71
|
+
case "|=": return value === attrValue || value.startsWith(`${attrValue}-`);
|
|
72
|
+
default: return false;
|
|
73
|
+
}
|
|
74
|
+
},
|
|
75
|
+
toString: () => {
|
|
76
|
+
if (!operator || !attrValue) return `[${attrName}]`;
|
|
77
|
+
return `[${attrName}${operator}${attrValue}]`;
|
|
78
|
+
}
|
|
79
|
+
};
|
|
80
|
+
}
|
|
81
|
+
function createCompoundSelector(selectors) {
|
|
82
|
+
return {
|
|
83
|
+
matches: (element) => selectors.every((selector) => selector.matches(element)),
|
|
84
|
+
toString: () => selectors.map((s) => s.toString()).join("")
|
|
85
|
+
};
|
|
86
|
+
}
|
|
87
|
+
function createSelectorList(selectors) {
|
|
88
|
+
return {
|
|
89
|
+
matches(element) {
|
|
90
|
+
for (let i = 0; i < selectors.length; i++) if (selectors[i].matches(element)) return true;
|
|
91
|
+
return false;
|
|
92
|
+
},
|
|
93
|
+
toString: () => selectors.map((s) => s.toString()).join(", ")
|
|
94
|
+
};
|
|
95
|
+
}
|
|
96
|
+
function parseCompoundSelector(selector) {
|
|
97
|
+
const selectorParts = [];
|
|
98
|
+
let current = "";
|
|
99
|
+
let inAttribute = false;
|
|
100
|
+
for (let i = 0; i < selector.length; i++) {
|
|
101
|
+
const char = selector[i];
|
|
102
|
+
if ((char === "." || char === "#" || char === "[") && current) {
|
|
103
|
+
if (current[0] === ".") selectorParts.push(createClassSelector(current));
|
|
104
|
+
else if (current[0] === "#") selectorParts.push(createIdSelector(current));
|
|
105
|
+
else if (current[0] === "[") selectorParts.push(createAttributeSelector(current));
|
|
106
|
+
else if (current) selectorParts.push(createTagSelector(current));
|
|
107
|
+
current = char;
|
|
108
|
+
} else current += char;
|
|
109
|
+
if (char === "[") inAttribute = true;
|
|
110
|
+
if (char === "]") inAttribute = false;
|
|
111
|
+
if (inAttribute && char !== "[") {}
|
|
112
|
+
}
|
|
113
|
+
if (current) {
|
|
114
|
+
if (current[0] === ".") selectorParts.push(createClassSelector(current));
|
|
115
|
+
else if (current[0] === "#") selectorParts.push(createIdSelector(current));
|
|
116
|
+
else if (current[0] === "[") selectorParts.push(createAttributeSelector(current));
|
|
117
|
+
else if (current) selectorParts.push(createTagSelector(current));
|
|
118
|
+
}
|
|
119
|
+
if (selectorParts.length === 1) return selectorParts[0];
|
|
120
|
+
return createCompoundSelector(selectorParts);
|
|
121
|
+
}
|
|
122
|
+
function parseSelector(selector) {
|
|
123
|
+
selector = selector.trim();
|
|
124
|
+
if (!selector) throw new Error("Empty selector");
|
|
125
|
+
const selectors = [];
|
|
126
|
+
let start = 0;
|
|
127
|
+
let inAttribute = false;
|
|
128
|
+
let quote = 0;
|
|
129
|
+
let escaped = false;
|
|
130
|
+
for (let i = 0; i < selector.length; i++) {
|
|
131
|
+
const char = selector.charCodeAt(i);
|
|
132
|
+
if (quote) {
|
|
133
|
+
if (escaped) escaped = false;
|
|
134
|
+
else if (char === 92) escaped = true;
|
|
135
|
+
else if (char === quote) quote = 0;
|
|
136
|
+
continue;
|
|
137
|
+
}
|
|
138
|
+
if (inAttribute) {
|
|
139
|
+
if (char === 34 || char === 39) quote = char;
|
|
140
|
+
else if (char === 93) inAttribute = false;
|
|
141
|
+
continue;
|
|
142
|
+
}
|
|
143
|
+
if (char === 91) inAttribute = true;
|
|
144
|
+
else if (char === 44) {
|
|
145
|
+
const part = selector.slice(start, i).trim();
|
|
146
|
+
if (!part) return createTagSelector(selector);
|
|
147
|
+
selectors.push(parseCompoundSelector(part));
|
|
148
|
+
start = i + 1;
|
|
149
|
+
}
|
|
150
|
+
}
|
|
151
|
+
if (!selectors.length) return parseCompoundSelector(selector);
|
|
152
|
+
const last = selector.slice(start).trim();
|
|
153
|
+
if (!last) return createTagSelector(selector);
|
|
154
|
+
selectors.push(parseCompoundSelector(last));
|
|
155
|
+
return createSelectorList(selectors);
|
|
156
|
+
}
|
|
157
|
+
function extractionPlugin(selectors) {
|
|
158
|
+
const matcherCallbacks = Object.entries(selectors).map(([selector, callback]) => ({
|
|
159
|
+
matcher: parseSelector(selector),
|
|
160
|
+
callback
|
|
161
|
+
}));
|
|
162
|
+
const trackedElements = /* @__PURE__ */ new Map();
|
|
163
|
+
return createPlugin({
|
|
164
|
+
onNodeEnter(element) {
|
|
165
|
+
let callbacks;
|
|
166
|
+
for (let i = 0; i < matcherCallbacks.length; i++) {
|
|
167
|
+
const { matcher, callback } = matcherCallbacks[i];
|
|
168
|
+
if (matcher.matches(element)) {
|
|
169
|
+
callbacks ||= [];
|
|
170
|
+
callbacks.push(callback);
|
|
171
|
+
}
|
|
172
|
+
}
|
|
173
|
+
if (callbacks) trackedElements.set(element, {
|
|
174
|
+
textContent: "",
|
|
175
|
+
callbacks
|
|
176
|
+
});
|
|
177
|
+
},
|
|
178
|
+
processTextNode(textNode) {
|
|
179
|
+
let currentParent = textNode.parent;
|
|
180
|
+
while (currentParent) {
|
|
181
|
+
const tracked = trackedElements.get(currentParent);
|
|
182
|
+
if (tracked) tracked.textContent += textNode.value;
|
|
183
|
+
currentParent = currentParent.parent;
|
|
184
|
+
}
|
|
185
|
+
},
|
|
186
|
+
onNodeExit(element, state) {
|
|
187
|
+
const tracked = trackedElements.get(element);
|
|
188
|
+
if (tracked) {
|
|
189
|
+
for (let i = 0; i < tracked.callbacks.length; i++) {
|
|
190
|
+
const extractedElement = {
|
|
191
|
+
...element,
|
|
192
|
+
attributes: { ...element.attributes },
|
|
193
|
+
textContent: tracked.textContent.trim()
|
|
194
|
+
};
|
|
195
|
+
tracked.callbacks[i](extractedElement, state);
|
|
196
|
+
}
|
|
197
|
+
trackedElements.delete(element);
|
|
198
|
+
}
|
|
199
|
+
}
|
|
200
|
+
});
|
|
201
|
+
}
|
|
202
|
+
function extractionCollectorPlugin(config) {
|
|
203
|
+
const matchers = Object.entries(config).map(([selector, callback]) => ({
|
|
204
|
+
selector,
|
|
205
|
+
matcher: parseSelector(selector),
|
|
206
|
+
callback
|
|
207
|
+
}));
|
|
208
|
+
const results = [];
|
|
209
|
+
const trackedElements = /* @__PURE__ */ new Map();
|
|
210
|
+
const plugin = createPlugin({
|
|
211
|
+
onNodeEnter(element) {
|
|
212
|
+
let selectors;
|
|
213
|
+
for (let i = 0; i < matchers.length; i++) {
|
|
214
|
+
const m = matchers[i];
|
|
215
|
+
if (m.matcher.matches(element)) {
|
|
216
|
+
selectors ||= [];
|
|
217
|
+
selectors.push(m.selector);
|
|
218
|
+
}
|
|
219
|
+
}
|
|
220
|
+
if (selectors) trackedElements.set(element, {
|
|
221
|
+
textContent: "",
|
|
222
|
+
selectors
|
|
223
|
+
});
|
|
224
|
+
},
|
|
225
|
+
processTextNode(textNode) {
|
|
226
|
+
let currentParent = textNode.parent;
|
|
227
|
+
while (currentParent) {
|
|
228
|
+
const tracked = trackedElements.get(currentParent);
|
|
229
|
+
if (tracked) tracked.textContent += textNode.value;
|
|
230
|
+
currentParent = currentParent.parent;
|
|
231
|
+
}
|
|
232
|
+
},
|
|
233
|
+
onNodeExit(element) {
|
|
234
|
+
const tracked = trackedElements.get(element);
|
|
235
|
+
if (tracked) {
|
|
236
|
+
for (let i = 0; i < tracked.selectors.length; i++) {
|
|
237
|
+
const extracted = {
|
|
238
|
+
selector: tracked.selectors[i],
|
|
239
|
+
tagName: element.name,
|
|
240
|
+
textContent: tracked.textContent.trim(),
|
|
241
|
+
attributes: { ...element.attributes }
|
|
242
|
+
};
|
|
243
|
+
results.push(extracted);
|
|
244
|
+
}
|
|
245
|
+
trackedElements.delete(element);
|
|
246
|
+
}
|
|
247
|
+
}
|
|
248
|
+
});
|
|
249
|
+
function callHandlers() {
|
|
250
|
+
for (let i = 0; i < results.length; i++) {
|
|
251
|
+
const el = results[i];
|
|
252
|
+
for (let j = 0; j < matchers.length; j++) if (matchers[j].selector === el.selector) {
|
|
253
|
+
matchers[j].callback(el);
|
|
254
|
+
break;
|
|
255
|
+
}
|
|
256
|
+
}
|
|
257
|
+
}
|
|
258
|
+
return {
|
|
259
|
+
plugin,
|
|
260
|
+
getResults: () => results,
|
|
261
|
+
callHandlers
|
|
262
|
+
};
|
|
263
|
+
}
|
|
264
|
+
function compileSelector(selector) {
|
|
265
|
+
if (typeof selector === "number") return {
|
|
266
|
+
matches: (element) => element.tagId === selector,
|
|
267
|
+
toString: () => String(selector)
|
|
268
|
+
};
|
|
269
|
+
const tagId = TagIdMap[selector];
|
|
270
|
+
if (tagId !== void 0) return {
|
|
271
|
+
matches: (element) => element.tagId === tagId,
|
|
272
|
+
toString: () => selector
|
|
273
|
+
};
|
|
274
|
+
return parseSelector(selector);
|
|
275
|
+
}
|
|
276
|
+
function isHidden(element) {
|
|
277
|
+
const style = element.attributes?.style;
|
|
278
|
+
if (style && (style.includes("display:none") || style.includes("display: none") || style.includes("visibility:hidden") || style.includes("visibility: hidden") || style.includes("position:absolute") || style.includes("position: absolute") || style.includes("position:fixed") || style.includes("position: fixed"))) return true;
|
|
279
|
+
const hidden = element.attributes?.hidden;
|
|
280
|
+
return hidden !== void 0 && hidden.toLowerCase() !== "until-found";
|
|
281
|
+
}
|
|
282
|
+
function filterPlugin(options = {}) {
|
|
283
|
+
const includeSelectors = options.include?.map((selector) => compileSelector(selector)) || [];
|
|
284
|
+
const excludeSelectors = options.exclude?.map((selector) => compileSelector(selector)) || [];
|
|
285
|
+
const processChildren = options.processChildren !== false;
|
|
286
|
+
const skippedSubtrees = /* @__PURE__ */ new WeakSet();
|
|
287
|
+
const skippedByInclude = /* @__PURE__ */ new WeakSet();
|
|
288
|
+
function excludesSubtree(element) {
|
|
289
|
+
if (skippedSubtrees.has(element)) return true;
|
|
290
|
+
if ((element.parent ? skippedSubtrees.has(element.parent) : false) || isHidden(element) || excludeSelectors.some((selector) => selector.matches(element))) {
|
|
291
|
+
skippedSubtrees.add(element);
|
|
292
|
+
return true;
|
|
293
|
+
}
|
|
294
|
+
return false;
|
|
295
|
+
}
|
|
296
|
+
return createPlugin({
|
|
297
|
+
excludesOverflowSubtree: excludesSubtree,
|
|
298
|
+
beforeNodeProcess(event) {
|
|
299
|
+
const { node } = event;
|
|
300
|
+
if (node.type === 2) {
|
|
301
|
+
const textNode = node;
|
|
302
|
+
const parent = textNode.parent;
|
|
303
|
+
if (parent && skippedSubtrees.has(parent)) return { skip: true };
|
|
304
|
+
if (parent && skippedByInclude.has(parent)) textNode.excludedFromMarkdown = true;
|
|
305
|
+
return;
|
|
306
|
+
}
|
|
307
|
+
if (node.type !== 1) return;
|
|
308
|
+
const element = node;
|
|
309
|
+
if (excludesSubtree(element)) return { skip: true };
|
|
310
|
+
if (includeSelectors.length) {
|
|
311
|
+
let currentElement = element;
|
|
312
|
+
while (currentElement) {
|
|
313
|
+
if (includeSelectors.some((selector) => selector.matches(currentElement))) return;
|
|
314
|
+
if (!processChildren) break;
|
|
315
|
+
currentElement = currentElement.parent;
|
|
316
|
+
}
|
|
317
|
+
skippedByInclude.add(element);
|
|
318
|
+
return { skip: true };
|
|
319
|
+
}
|
|
320
|
+
}
|
|
321
|
+
});
|
|
322
|
+
}
|
|
323
|
+
const BACKSLASH_RE = /\\/g;
|
|
324
|
+
const DOUBLE_QUOTE_RE = /"/g;
|
|
325
|
+
const ESCAPED_DOUBLE_QUOTE_RE = /\\"/g;
|
|
326
|
+
function frontmatterPlugin(options = {}) {
|
|
327
|
+
const additionalFields = options.additionalFields || {};
|
|
328
|
+
const metaFields = /* @__PURE__ */ new Set([
|
|
329
|
+
"description",
|
|
330
|
+
"keywords",
|
|
331
|
+
"author",
|
|
332
|
+
"date",
|
|
333
|
+
"og:title",
|
|
334
|
+
"og:description",
|
|
335
|
+
"twitter:title",
|
|
336
|
+
"twitter:description",
|
|
337
|
+
...options.metaFields || []
|
|
338
|
+
]);
|
|
339
|
+
const frontmatter = {
|
|
340
|
+
...additionalFields,
|
|
341
|
+
meta: {}
|
|
342
|
+
};
|
|
343
|
+
let inHead = false;
|
|
344
|
+
function formatValue(_name, value) {
|
|
345
|
+
value = value.replace(BACKSLASH_RE, "\\\\").replace(DOUBLE_QUOTE_RE, "\\\"");
|
|
346
|
+
if (value.includes("\n") || value.includes(":") || value.includes("#") || value.includes(" ")) return `"${value}"`;
|
|
347
|
+
return value;
|
|
348
|
+
}
|
|
349
|
+
function getStructuredData() {
|
|
350
|
+
const result = {};
|
|
351
|
+
if (frontmatter.title) {
|
|
352
|
+
const raw = frontmatter.title;
|
|
353
|
+
result.title = raw.startsWith("\"") && raw.endsWith("\"") ? raw.slice(1, -1).replace(ESCAPED_DOUBLE_QUOTE_RE, "\"") : raw;
|
|
354
|
+
}
|
|
355
|
+
for (const [k, v] of Object.entries(frontmatter.meta)) {
|
|
356
|
+
const cleanKey = k.startsWith("\"") && k.endsWith("\"") ? k.slice(1, -1) : k;
|
|
357
|
+
result[cleanKey] = typeof v === "string" && v.startsWith("\"") && v.endsWith("\"") ? v.slice(1, -1).replace(ESCAPED_DOUBLE_QUOTE_RE, "\"") : String(v);
|
|
358
|
+
}
|
|
359
|
+
if (additionalFields) {
|
|
360
|
+
for (const [k, v] of Object.entries(additionalFields)) if (typeof v === "string") result[k] = v;
|
|
361
|
+
}
|
|
362
|
+
return Object.keys(result).length > 0 ? result : void 0;
|
|
363
|
+
}
|
|
364
|
+
const plugin = createPlugin({
|
|
365
|
+
onNodeEnter(node) {
|
|
366
|
+
if (node.excludedFromMarkdown) return;
|
|
367
|
+
if (node.tagId === 1) {
|
|
368
|
+
inHead = true;
|
|
369
|
+
return;
|
|
370
|
+
}
|
|
371
|
+
if (inHead && node.type === 1 && node.tagId === 4) return;
|
|
372
|
+
if (inHead && node.type === 1 && node.tagId === 5) {
|
|
373
|
+
const { name, property, content } = node.attributes || {};
|
|
374
|
+
const metaName = property || name;
|
|
375
|
+
if (metaName && content && metaFields.has(metaName)) frontmatter.meta[metaName.includes(":") ? `"${metaName}"` : metaName] = formatValue(metaName, content);
|
|
376
|
+
return;
|
|
377
|
+
}
|
|
378
|
+
},
|
|
379
|
+
onNodeExit(node, state) {
|
|
380
|
+
if (node.excludedFromMarkdown) return void 0;
|
|
381
|
+
if (node.type === 1 && node.tagId === 1) {
|
|
382
|
+
inHead = false;
|
|
383
|
+
if (state.options?.format === "text") return void 0;
|
|
384
|
+
if (Object.keys(frontmatter).length > 0) {
|
|
385
|
+
const frontmatterContent = generateFrontmatter();
|
|
386
|
+
if (frontmatterContent) {
|
|
387
|
+
state.buffer.push(frontmatterContent);
|
|
388
|
+
state.lastContentCache = frontmatterContent;
|
|
389
|
+
}
|
|
390
|
+
}
|
|
391
|
+
}
|
|
392
|
+
},
|
|
393
|
+
processTextNode(node) {
|
|
394
|
+
if (node.parent?.excludedFromMarkdown) return;
|
|
395
|
+
if (!inHead) return;
|
|
396
|
+
const parent = node.parent;
|
|
397
|
+
if (parent && parent.tagId === 4 && node.value) {
|
|
398
|
+
frontmatter.title = formatValue("title", node.value.trim());
|
|
399
|
+
return {
|
|
400
|
+
content: "",
|
|
401
|
+
skip: true
|
|
402
|
+
};
|
|
403
|
+
}
|
|
404
|
+
}
|
|
405
|
+
});
|
|
406
|
+
plugin.getFrontmatter = getStructuredData;
|
|
407
|
+
return plugin;
|
|
408
|
+
function generateFrontmatter() {
|
|
409
|
+
if (Object.keys(frontmatter).length === 0) return "";
|
|
410
|
+
let yamlLines = [];
|
|
411
|
+
const entries = Object.entries(frontmatter).sort(([a], [b]) => {
|
|
412
|
+
if (a === "title") return -1;
|
|
413
|
+
if (b === "title") return 1;
|
|
414
|
+
if (a === "description") return -1;
|
|
415
|
+
if (b === "description") return 1;
|
|
416
|
+
return a.localeCompare(b);
|
|
417
|
+
});
|
|
418
|
+
for (const [key, value] of entries) if (key === "meta" && typeof value === "object" && value && Object.keys(value).length > 0) {
|
|
419
|
+
yamlLines.push("meta:");
|
|
420
|
+
const metaEntries = Object.entries(value).sort(([a], [b]) => a.localeCompare(b)).map(([metaKey, metaValue]) => ` ${metaKey}: ${metaValue}`);
|
|
421
|
+
yamlLines.push(...metaEntries);
|
|
422
|
+
} else if (key !== "meta" && typeof value === "string") yamlLines.push(`${key}: ${value}`);
|
|
423
|
+
if (Object.keys(frontmatter.meta).length === 0) yamlLines = yamlLines.filter((line) => !line.startsWith("meta:"));
|
|
424
|
+
return `---\n${yamlLines.join("\n")}\n---\n\n`;
|
|
425
|
+
}
|
|
426
|
+
}
|
|
427
|
+
function isolateMainPlugin() {
|
|
428
|
+
let mainElement = null;
|
|
429
|
+
let firstHeaderElement = null;
|
|
430
|
+
let afterFooter = false;
|
|
431
|
+
const headerTagIds = /* @__PURE__ */ new Set([
|
|
432
|
+
7,
|
|
433
|
+
8,
|
|
434
|
+
9,
|
|
435
|
+
10,
|
|
436
|
+
11,
|
|
437
|
+
12
|
|
438
|
+
]);
|
|
439
|
+
return createPlugin({ beforeNodeProcess(event) {
|
|
440
|
+
const { node } = event;
|
|
441
|
+
if (node.excludedFromMarkdown || node.parent?.excludedFromMarkdown) return;
|
|
442
|
+
if (node.type === 1) {
|
|
443
|
+
const element = node;
|
|
444
|
+
if (!mainElement && element.tagId === 104 && element.depth <= 5) {
|
|
445
|
+
mainElement = element;
|
|
446
|
+
return;
|
|
447
|
+
}
|
|
448
|
+
if (mainElement) {
|
|
449
|
+
let current = element.parent;
|
|
450
|
+
let isInsideMain = element === mainElement;
|
|
451
|
+
while (current && !isInsideMain) {
|
|
452
|
+
if (current === mainElement) {
|
|
453
|
+
isInsideMain = true;
|
|
454
|
+
break;
|
|
455
|
+
}
|
|
456
|
+
current = current.parent;
|
|
457
|
+
}
|
|
458
|
+
if (!isInsideMain) return { skip: true };
|
|
459
|
+
return;
|
|
460
|
+
}
|
|
461
|
+
if (!firstHeaderElement && element.tagId !== void 0 && headerTagIds.has(element.tagId)) {
|
|
462
|
+
let current = element.parent;
|
|
463
|
+
let isInHeaderTag = false;
|
|
464
|
+
while (current) {
|
|
465
|
+
if (current.tagId === 105) {
|
|
466
|
+
isInHeaderTag = true;
|
|
467
|
+
break;
|
|
468
|
+
}
|
|
469
|
+
current = current.parent;
|
|
470
|
+
}
|
|
471
|
+
if (!isInHeaderTag) {
|
|
472
|
+
firstHeaderElement = element;
|
|
473
|
+
return;
|
|
474
|
+
}
|
|
475
|
+
}
|
|
476
|
+
if (firstHeaderElement && !afterFooter && element.tagId === 47) {
|
|
477
|
+
if (element.depth - firstHeaderElement.depth <= 5) {
|
|
478
|
+
afterFooter = true;
|
|
479
|
+
return { skip: true };
|
|
480
|
+
}
|
|
481
|
+
}
|
|
482
|
+
if (!firstHeaderElement) {
|
|
483
|
+
if (element.tagId === 1) return;
|
|
484
|
+
let current = element.parent;
|
|
485
|
+
while (current) {
|
|
486
|
+
if (current.tagId === 1) return;
|
|
487
|
+
current = current.parent;
|
|
488
|
+
}
|
|
489
|
+
return { skip: true };
|
|
490
|
+
}
|
|
491
|
+
if (afterFooter) return { skip: true };
|
|
492
|
+
}
|
|
493
|
+
if (node.type === 2) {
|
|
494
|
+
if (mainElement) {
|
|
495
|
+
let current = node.parent;
|
|
496
|
+
let isInsideMain = false;
|
|
497
|
+
while (current) {
|
|
498
|
+
if (current === mainElement) {
|
|
499
|
+
isInsideMain = true;
|
|
500
|
+
break;
|
|
501
|
+
}
|
|
502
|
+
current = current.parent;
|
|
503
|
+
}
|
|
504
|
+
if (!isInsideMain) return { skip: true };
|
|
505
|
+
return;
|
|
506
|
+
}
|
|
507
|
+
if (!firstHeaderElement || afterFooter) {
|
|
508
|
+
let current = node.parent;
|
|
509
|
+
while (current) {
|
|
510
|
+
if (current.tagId === 1) return;
|
|
511
|
+
current = current.parent;
|
|
512
|
+
}
|
|
513
|
+
return { skip: true };
|
|
514
|
+
}
|
|
515
|
+
}
|
|
516
|
+
} });
|
|
517
|
+
}
|
|
518
|
+
const TAILWIND_TO_MARKDOWN_MAP = {
|
|
519
|
+
"font-bold": {
|
|
520
|
+
prefix: "**",
|
|
521
|
+
suffix: "**"
|
|
522
|
+
},
|
|
523
|
+
"font-semibold": {
|
|
524
|
+
prefix: "**",
|
|
525
|
+
suffix: "**"
|
|
526
|
+
},
|
|
527
|
+
"font-black": {
|
|
528
|
+
prefix: "**",
|
|
529
|
+
suffix: "**"
|
|
530
|
+
},
|
|
531
|
+
"font-extrabold": {
|
|
532
|
+
prefix: "**",
|
|
533
|
+
suffix: "**"
|
|
534
|
+
},
|
|
535
|
+
"font-medium": {
|
|
536
|
+
prefix: "**",
|
|
537
|
+
suffix: "**"
|
|
538
|
+
},
|
|
539
|
+
"font-italic": {
|
|
540
|
+
prefix: "*",
|
|
541
|
+
suffix: "*"
|
|
542
|
+
},
|
|
543
|
+
"italic": {
|
|
544
|
+
prefix: "*",
|
|
545
|
+
suffix: "*"
|
|
546
|
+
},
|
|
547
|
+
"line-through": {
|
|
548
|
+
prefix: "~~",
|
|
549
|
+
suffix: "~~"
|
|
550
|
+
},
|
|
551
|
+
"hidden": { hidden: true },
|
|
552
|
+
"invisible": { hidden: true },
|
|
553
|
+
"absolute": { hidden: true },
|
|
554
|
+
"fixed": { hidden: true },
|
|
555
|
+
"sticky": { hidden: true }
|
|
556
|
+
};
|
|
557
|
+
function extractBaseClass(className) {
|
|
558
|
+
for (const bp of [
|
|
559
|
+
"sm:",
|
|
560
|
+
"md:",
|
|
561
|
+
"lg:",
|
|
562
|
+
"xl:",
|
|
563
|
+
"2xl:"
|
|
564
|
+
]) if (className.startsWith(bp)) return {
|
|
565
|
+
baseClass: className.substring(bp.length),
|
|
566
|
+
breakpoint: bp
|
|
567
|
+
};
|
|
568
|
+
return {
|
|
569
|
+
baseClass: className,
|
|
570
|
+
breakpoint: ""
|
|
571
|
+
};
|
|
572
|
+
}
|
|
573
|
+
function sortByBreakpoint(classes) {
|
|
574
|
+
const breakpointOrder = {
|
|
575
|
+
"": 0,
|
|
576
|
+
"sm:": 1,
|
|
577
|
+
"md:": 2,
|
|
578
|
+
"lg:": 3,
|
|
579
|
+
"xl:": 4,
|
|
580
|
+
"2xl:": 5
|
|
581
|
+
};
|
|
582
|
+
return classes.toSorted((a, b) => {
|
|
583
|
+
const aBreakpoint = extractBaseClass(a).breakpoint;
|
|
584
|
+
const bBreakpoint = extractBaseClass(b).breakpoint;
|
|
585
|
+
return (breakpointOrder[aBreakpoint] || 0) - (breakpointOrder[bBreakpoint] || 0);
|
|
586
|
+
});
|
|
587
|
+
}
|
|
588
|
+
function groupByFormattingType(classes) {
|
|
589
|
+
const sorted = sortByBreakpoint(classes);
|
|
590
|
+
const groups = {
|
|
591
|
+
emphasis: [],
|
|
592
|
+
weight: [],
|
|
593
|
+
decoration: [],
|
|
594
|
+
display: [],
|
|
595
|
+
position: [],
|
|
596
|
+
other: []
|
|
597
|
+
};
|
|
598
|
+
for (const cls of sorted) {
|
|
599
|
+
const { baseClass } = extractBaseClass(cls);
|
|
600
|
+
if (baseClass.includes("italic")) groups.emphasis?.push(cls);
|
|
601
|
+
else if (baseClass.includes("font-") || baseClass === "bold") groups.weight?.push(cls);
|
|
602
|
+
else if (baseClass.includes("line-through") || baseClass.includes("underline")) groups.decoration?.push(cls);
|
|
603
|
+
else if (baseClass === "hidden" || baseClass.includes("invisible")) groups.display?.push(cls);
|
|
604
|
+
else if ([
|
|
605
|
+
"absolute",
|
|
606
|
+
"fixed",
|
|
607
|
+
"sticky"
|
|
608
|
+
].includes(baseClass)) groups.position?.push(cls);
|
|
609
|
+
else groups.other?.push(cls);
|
|
610
|
+
}
|
|
611
|
+
return groups;
|
|
612
|
+
}
|
|
613
|
+
function normalizeClasses(classes) {
|
|
614
|
+
const result = [];
|
|
615
|
+
const mobileClasses = classes.filter((cls) => !hasBreakpoint(cls));
|
|
616
|
+
const breakpointClasses = classes.filter((cls) => hasBreakpoint(cls));
|
|
617
|
+
result.push(...mobileClasses);
|
|
618
|
+
result.push(...breakpointClasses);
|
|
619
|
+
return result;
|
|
620
|
+
}
|
|
621
|
+
function hasBreakpoint(className) {
|
|
622
|
+
const { breakpoint } = extractBaseClass(className);
|
|
623
|
+
return breakpoint !== "";
|
|
624
|
+
}
|
|
625
|
+
function processTailwindClasses(classes) {
|
|
626
|
+
let prefix = "";
|
|
627
|
+
let suffix = "";
|
|
628
|
+
let hidden = false;
|
|
629
|
+
const grouped = groupByFormattingType(normalizeClasses(classes));
|
|
630
|
+
if (grouped.weight && grouped.weight.length > 0) {
|
|
631
|
+
const { baseClass } = extractBaseClass(grouped.weight[0]);
|
|
632
|
+
const mapping = TAILWIND_TO_MARKDOWN_MAP[baseClass];
|
|
633
|
+
if (mapping) {
|
|
634
|
+
if (mapping.prefix) prefix += mapping.prefix;
|
|
635
|
+
if (mapping.suffix) suffix = mapping.suffix + suffix;
|
|
636
|
+
}
|
|
637
|
+
}
|
|
638
|
+
if (grouped.emphasis && grouped.emphasis.length > 0) {
|
|
639
|
+
const { baseClass } = extractBaseClass(grouped.emphasis[0]);
|
|
640
|
+
const mapping = TAILWIND_TO_MARKDOWN_MAP[baseClass];
|
|
641
|
+
if (mapping) {
|
|
642
|
+
if (mapping.prefix) prefix += mapping.prefix;
|
|
643
|
+
if (mapping.suffix) suffix = mapping.suffix + suffix;
|
|
644
|
+
}
|
|
645
|
+
}
|
|
646
|
+
if (grouped.decoration && grouped.decoration.length > 0) {
|
|
647
|
+
const { baseClass } = extractBaseClass(grouped.decoration[0]);
|
|
648
|
+
const mapping = TAILWIND_TO_MARKDOWN_MAP[baseClass];
|
|
649
|
+
if (mapping) {
|
|
650
|
+
if (mapping.prefix) prefix += mapping.prefix;
|
|
651
|
+
if (mapping.suffix) suffix = mapping.suffix + suffix;
|
|
652
|
+
}
|
|
653
|
+
}
|
|
654
|
+
if (grouped.display) for (const cls of grouped.display) {
|
|
655
|
+
const { baseClass } = extractBaseClass(cls);
|
|
656
|
+
const mapping = TAILWIND_TO_MARKDOWN_MAP[baseClass];
|
|
657
|
+
if (mapping && mapping.hidden) {
|
|
658
|
+
hidden = true;
|
|
659
|
+
break;
|
|
660
|
+
}
|
|
661
|
+
}
|
|
662
|
+
if (grouped.position) for (const cls of grouped.position) {
|
|
663
|
+
const { baseClass } = extractBaseClass(cls);
|
|
664
|
+
const mapping = TAILWIND_TO_MARKDOWN_MAP[baseClass];
|
|
665
|
+
if (mapping && mapping.hidden) {
|
|
666
|
+
hidden = true;
|
|
667
|
+
break;
|
|
668
|
+
}
|
|
669
|
+
}
|
|
670
|
+
return {
|
|
671
|
+
prefix,
|
|
672
|
+
suffix,
|
|
673
|
+
hidden
|
|
674
|
+
};
|
|
675
|
+
}
|
|
676
|
+
function tailwindPlugin() {
|
|
677
|
+
return createPlugin({
|
|
678
|
+
excludesOverflowSubtree(node) {
|
|
679
|
+
if (node.parent?.context?.tailwind?.hidden) return true;
|
|
680
|
+
const classes = node.attributes?.class?.trim().split(" ").filter(Boolean);
|
|
681
|
+
return classes ? processTailwindClasses(classes).hidden : false;
|
|
682
|
+
},
|
|
683
|
+
processAttributes(node) {
|
|
684
|
+
const parentHidden = node.parent?.context?.tailwind?.hidden;
|
|
685
|
+
const classAttr = node.attributes?.class;
|
|
686
|
+
if (!classAttr && !parentHidden) return;
|
|
687
|
+
let prefix = "";
|
|
688
|
+
let suffix = "";
|
|
689
|
+
let hidden = false;
|
|
690
|
+
if (classAttr) {
|
|
691
|
+
const result = processTailwindClasses(classAttr.trim().split(" ").filter(Boolean));
|
|
692
|
+
prefix = result.prefix;
|
|
693
|
+
suffix = result.suffix;
|
|
694
|
+
hidden = result.hidden;
|
|
695
|
+
}
|
|
696
|
+
node.context = node.context || {};
|
|
697
|
+
node.context.tailwind = {
|
|
698
|
+
prefix,
|
|
699
|
+
suffix,
|
|
700
|
+
hidden: hidden || !!parentHidden
|
|
701
|
+
};
|
|
702
|
+
},
|
|
703
|
+
processTextNode(node, state) {
|
|
704
|
+
const parentNode = node.parent;
|
|
705
|
+
if (!parentNode || parentNode.type !== 1) return;
|
|
706
|
+
const tailwindData = parentNode.context?.tailwind;
|
|
707
|
+
if (tailwindData?.hidden) return {
|
|
708
|
+
content: "",
|
|
709
|
+
skip: true
|
|
710
|
+
};
|
|
711
|
+
const prefix = state.options?.format === "text" ? "" : tailwindData?.prefix || "";
|
|
712
|
+
const suffix = state.options?.format === "text" ? "" : tailwindData?.suffix || "";
|
|
713
|
+
if (prefix || suffix) node.generatedMarkdown = {
|
|
714
|
+
prefix,
|
|
715
|
+
suffix
|
|
716
|
+
};
|
|
717
|
+
},
|
|
718
|
+
beforeNodeProcess({ node }) {
|
|
719
|
+
if (node.type === 1) {
|
|
720
|
+
if (node.context?.tailwind?.hidden) return { skip: true };
|
|
721
|
+
}
|
|
722
|
+
}
|
|
723
|
+
});
|
|
724
|
+
}
|
|
725
|
+
export { createPlugin, extractionCollectorPlugin, extractionPlugin, filterPlugin, frontmatterPlugin, isolateMainPlugin, tailwindPlugin };
|