"use strict"; var __defProp = Object.defineProperty; var __getOwnPropDesc = Object.getOwnPropertyDescriptor; var __getOwnPropNames = Object.getOwnPropertyNames; var __hasOwnProp = Object.prototype.hasOwnProperty; var __export = (target, all) => { for (var name in all) __defProp(target, name, { get: all[name], enumerable: true }); }; var __copyProps = (to, from, except, desc) => { if (from && typeof from === "object" || typeof from === "function") { for (let key of __getOwnPropNames(from)) if (!__hasOwnProp.call(to, key) && key !== except) __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable }); } return to; }; var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod); // src/index.ts var src_exports = {}; __export(src_exports, { default: () => src_default }); module.exports = __toCommonJS(src_exports); // src/shared.ts var DEFAULTS = { root: ":not(#\\9)", keyword: "@specificity", sourceType: "css" }; var increaseSpecificityOfRule = (rule, settings) => { rule.selectors = rule.selectors.map((selector) => { if (["html", ":root", ":host", settings.root].some((s) => selector.startsWith(s))) { const [root, ...rest] = selector.split(" "); return [root + settings.root.repeat(settings.repeat), ...rest].join(" "); } return [settings.root.repeat(settings.repeat), selector].join(" "); }); }; var processComment = (comment, settings, mediaStack) => { const isImportantComment = comment.text.startsWith("!"); const text = isImportantComment ? comment.text.replace(/^!\s*/, "") : comment.text; if (!text.startsWith(settings.keyword)) return; const isDecoratorInside = settings.sourceType === "scss"; const rule = isDecoratorInside ? comment.parent : comment.next(); if (!rule || rule.type !== "rule") { !isImportantComment && comment.remove(); return; } const repeat = parseInt(comment.text.replace(settings.keyword, "").trim(), 10) || 1; isDecoratorInside && mediaStack.push({ selector: rule.selector, repeat }); increaseSpecificityOfRule(rule, { ...settings, repeat }); !isImportantComment && comment.remove(); }; var processRule = (rule, settings, mediaStack) => { const m = mediaStack.find((i) => i.selector === rule.selector); if (!m) return; if (rule.parent?.type === "atrule" && ("name" in rule.parent && rule.parent.name === "media")) { increaseSpecificityOfRule(rule, { ...settings, repeat: m.repeat }); } }; // src/index.ts var plugin = (options = {}) => { const settings = { ...DEFAULTS, ...options }; let mediaStack = []; return { postcssPlugin: "postcss-specificity-decorator", OnceExit: () => { mediaStack = []; }, Rule: (rule) => processRule(rule, settings, mediaStack), Comment: (comment) => processComment(comment, settings, mediaStack) }; }; plugin.postcss = true; var src_default = plugin;