Urara-Blog/node_modules/.pnpm-store/v3/files/8b/ffbc56c9249f2ce6cfa6a94f5b457ec381f9032bd359c4999ea59831e891c6d028d79f45522f52115815ed17ed8fc3911c02fc4ee5c10fd815a95672e1bac7
2022-08-14 01:14:53 +08:00

82 lines
2 KiB
Text

'use strict';
Object.defineProperty(exports, '__esModule', { value: true });
const core = require('@unocss/core');
const MARKER = "__TAGIFY__";
const htmlTagRE = /<([\w\d-:]+)/g;
const extractorTagify = (options) => {
const {
prefix = "",
excludedTags = ["b", /^h\d+$/, "table"]
} = options;
return {
name: "tagify",
extract({ code }) {
return new Set(
Array.from(code.matchAll(htmlTagRE)).filter(({ 1: match }) => {
for (const exclude of excludedTags) {
if (typeof exclude === "string") {
if (match === exclude)
return false;
} else {
if (exclude.test(match))
return false;
}
}
return match.startsWith(prefix);
}).map(([, matched]) => `${MARKER}${matched}`)
);
}
};
};
const variantTagify = (options) => {
const { extraProperties } = options;
const prefix = `${MARKER}${options.prefix ?? ""}`;
return {
name: "tagify",
match(input) {
if (!input.startsWith(prefix))
return;
const matcher = input.slice(prefix.length);
const handler = {
matcher,
selector: (i) => i.slice(MARKER.length + 1)
};
if (extraProperties) {
if (typeof extraProperties === "function")
handler.body = (entries) => [...entries, ...Object.entries(extraProperties(matcher) ?? {})];
else
handler.body = (entries) => [...entries, ...Object.entries(extraProperties)];
}
return handler;
}
};
};
function tagifyPreset(options = {}) {
const {
defaultExtractor = true
} = options;
const variants = [
variantTagify(options)
];
const extractors = [
extractorTagify(options)
];
if (defaultExtractor)
extractors.push(core.extractorSplit);
return {
name: "@unocss/preset-tagify",
variants,
extractors
};
}
exports.MARKER = MARKER;
exports["default"] = tagifyPreset;
exports.extractorTagify = extractorTagify;
exports.htmlTagRE = htmlTagRE;
exports.variantTagify = variantTagify;