You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
2 lines
7.2 KiB
2 lines
7.2 KiB
2 years ago
|
"use strict";var e=require("postcss-value-parser"),t=require("path"),r=require("url"),o=require("postcss"),s=require("fs");function n(e){return e&&"object"==typeof e&&"default"in e?e:{default:e}}function i(e){if(e&&e.__esModule)return e;var t=Object.create(null);return e&&Object.keys(e).forEach((function(r){if("default"!==r){var o=Object.getOwnPropertyDescriptor(e,r);Object.defineProperty(t,r,o.get?o:{enumerable:!0,get:function(){return e[r]}})}})),t.default=e,Object.freeze(t)}var a=n(e),c=n(t);function u(e){const t=e.selector?e:e.parent;return/(!\s*)?postcss-custom-properties:\s*off\b/i.test(t.toString())}function l(e,t){const r=new Map,o=new Map,s=new Map;e.nodes.slice().forEach((e=>{const s=m(e)?r:d(e)?o:null;s&&(e.nodes.slice().forEach((e=>{if(e.variable&&!u(e)){const{prop:r}=e;s.set(r,a.default(e.value)),t.preserve||e.remove()}})),t.preserve||!w(e)||u(e)||e.remove())}));for(const[e,t]of r.entries())s.set(e,t);for(const[e,t]of o.entries())s.set(e,t);return s}const p=/^html$/i,f=/^:root$/i,m=e=>"rule"===e.type&&e.selector.split(",").some((e=>p.test(e)))&&Object(e.nodes).length,d=e=>"rule"===e.type&&e.selector.split(",").some((e=>f.test(e)))&&Object(e.nodes).length,w=e=>0===Object(e.nodes).length;function v(e){const t=new Map;if("customProperties"in e)for(const[r,o]of Object.entries(e.customProperties))t.set(r,a.default(o.toString()));if("custom-properties"in e)for(const[r,o]of Object.entries(e["custom-properties"]))t.set(r,a.default(o.toString()));return t}async function y(e){let t;try{t=await(o=e,Promise.resolve().then((function(){return i(require(o))})))}catch(o){t=await function(e){return Promise.resolve().then((function(){return i(require(e))}))}(r.pathToFileURL(e).href)}var o;return v("default"in t?t.default:t)}async function h(e){const t=(await Promise.all(e.map((async e=>{if(e instanceof Promise?e=await e:e instanceof Function&&(e=await e()),"string"==typeof e){const t=c.default.resolve(e);return{type:c.default.extname(t).slice(1).toLowerCase(),from:t}}if("customProperties"in e&&Object(e.customProperties)===e.customProperties)return e;if("custom-properties"in e&&Object(e["custom-properties"])===e["custom-properties"])return e;if("from"in e){const t=c.default.resolve(e.from);let r=e.type;return r||(r=c.default.extname(t).slice(1).toLowerCase()),{type:r,from:t}}return Object.keys(e).length,null})))).filter((e=>!!e)),r=await Promise.all(t.map((async e=>{if("type"in e&&"from"in e){if("css"===e.type||"pcss"===e.type)return await async function(e){const t=await s.promises.readFile(e);return l(o.parse(t,{from:e.toString()}),{preserve:!0})}(e.from);if("js"===e.type||"cjs"===e.type)return await y(e.from);if("mjs"===e.type)return await y(e.from);if("json"===e.type)return await async function(e){return v(await g(e))}(e.from);throw new Error("Invalid source type: "+e.type)}return v(e)}))),n=new Map;return r.forEach((e=>{for(const[t,r]of e.entries())n.set(t,r)})),n}const g=async e=>JSON.parse((await s.promises.readFile(e)).toString());function b(e,t){return e.nodes&&e.nodes.length&&e.nodes.slice().forEach((r=>{if(O(r)){const[o,...s]=r.nodes.filter((e=>"div"!==e.type)),{value:n}=o,i=e.nodes.indexOf(r);if(t.has(n)){const r=t.get(n).nodes;!function(e,t,r){const o=new Map(t);o.delete(r),b(e,o)}({nodes:r},t,n),i>-1&&e.nodes.splice(i,1,...r)}else s.length&&(i>-1&&e.nodes.splice(i,1,...r.nodes.slice(r.nodes.indexOf(s[0]))),b(e,t))}else b(r,t)})),e.toString()}const j=/^var$/i,O=e=>"function"===e.type&&j.test(e.value)&&Object(e.nodes).length>0;var $=(e,t,r)=>{if(P(e)&&!function(e){const t=e.prev();return Boolean(u(e)||t&&"comment"===t.type&&/(!\s*)?postcss-custom-properties:\s*ignore\s+next\b/i.test(t.text))}(e)){const o=e.value;let s=b(a.default(o),t);const n=new Set;for(;s.includes("--")&&s.includes("var(")&&!n.has(s);){n.add(s);s=b(a.default(s),t)}if(s!==o)if(r.preserve){const t=e.cloneBefore({value:s});x(t)&&(t.raws.value.value=t.value.replace(F,"$1"),t.raws.value.raw=t.raws.value.value+t.raws.value.raw.replace(F,"$2"))}else e.value=s,x(e)&&(e.raws.value.value=e.value.replace(F,"$1"),e.raws.value.raw=e.raws.value.value+e.raws.v
|