2 lines
6.5 KiB
JavaScript
2 lines
6.5 KiB
JavaScript
|
"use strict";var e=require("postcss-value-parser"),t=require("fs"),n=require("path"),s=require("postcss");function r(e){return e&&"object"==typeof e&&"default"in e?e:{default:e}}function o(e){if(e&&e.__esModule)return e;var t=Object.create(null);return e&&Object.keys(e).forEach((function(n){if("default"!==n){var s=Object.getOwnPropertyDescriptor(e,n);Object.defineProperty(t,n,s.get?s:{enumerable:!0,get:function(){return e[n]}})}})),t.default=e,Object.freeze(t)}var i=r(e),a=r(t),c=r(n);function u(e,t){const n=[];let s="",r=!1,o=0,i=-1;for(;++i<e.length;){const a=e[i];"("===a?o+=1:")"===a?o>0&&(o-=1):0===o&&(t&&p.test(s+a)?r=!0:t||","!==a||(r=!0)),r?(n.push(t?new l(s+a):new d(s)),s="",r=!1):s+=a}return""!==s&&n.push(t?new l(s):new d(s)),n}class f{constructor(e){this.nodes=u(e)}invert(){return this.nodes.forEach((e=>{e.invert()})),this}clone(){return new f(String(this))}toString(){return this.nodes.join(",")}}class d{constructor(e){const[,t,n,s]=e.match(m),[,r="",o=" ",i="",a="",c="",f="",d="",l=""]=n.match(w)||[],p={before:t,after:s,afterModifier:o,originalModifier:r||"",beforeAnd:a,and:c,beforeExpression:f},h=u(d||l,!0);Object.assign(this,{modifier:r,type:i,raws:p,nodes:h})}clone(e){const t=new d(String(this));return Object.assign(t,e),t}invert(){return this.modifier=this.modifier?"":this.raws.originalModifier,this}toString(){const{raws:e}=this;return`${e.before}${this.modifier}${this.modifier?`${e.afterModifier}`:""}${this.type}${e.beforeAnd}${e.and}${e.beforeExpression}${this.nodes.join("")}${this.raws.after}`}}class l{constructor(e){const[,t,n="",s="",r=""]=e.match(p)||[null,e],o={after:n,and:s,afterAnd:r};Object.assign(this,{value:t,raws:o})}clone(e){const t=new l(String(this));return Object.assign(t,e),t}toString(){const{raws:e}=this;return`${this.value}${e.after}${e.and}${e.afterAnd}`}}const p=new RegExp("^([\\W\\w]+)(?:(?:(\\s+)(and))(\\s+))$","i"),m=new RegExp("^(\\s*)([\\W\\w]*)(\\s*)$"),w=new RegExp("^(?:(not|only)(\\s+))?(?:(all|print|screen|speech)(?:(?:(\\s+)(and))(\\s+)([\\W\\w]+))?|([\\W\\w]+))$","i");var h=e=>new f(e),g=(e,t)=>{const n={};return e.nodes.slice().forEach((e=>{if("atrule"!==e.type)return;if("custom-media"!==e.name.toLowerCase())return;let s=null;try{s=i.default(e.params)}catch(e){return}if(!s||!s.nodes||!s.nodes.length)return;let r=-1;for(let e=0;e<s.nodes.length;e++){const t=s.nodes[e];if("space"!==t.type&&"comment"!==t.type){if("word"===t.type&&t.value.startsWith("--")){r=e;break}return}}if(r<0)return;const o=s.nodes[r].value.trim(),a=i.default.stringify(s.nodes.slice(r+1)).trim();n[o]=h(a),Object(t).preserve||e.remove()})),n};function b(e){const t=Object.assign({},Object(e).customMedia,Object(e)["custom-media"]);for(const e in t)t[e]=h(t[e]);return t}function y(e){return e.map((e=>{if(e instanceof Promise)return e;if(e instanceof Function)return e();const t=e===Object(e)?e:{from:String(e)};if(Object(t).customMedia||Object(t)["custom-media"])return t;const n=c.default.resolve(String(t.from||""));return{type:(t.type||c.default.extname(n).slice(1)).toLowerCase(),from:n}})).reduce((async(e,t)=>{const{type:n,from:r}=await t;return"css"===n||"pcss"===n?Object.assign(await e,await async function(e){const t=await j(e),n=s.parse(t,{from:e});return g(n,{preserve:!0})}(r)):"js"===n?Object.assign(await e,await async function(e){var t;return b(await(t=e,Promise.resolve().then((function(){return o(require(t))}))))}(r)):"json"===n?Object.assign(await e,await async function(e){return b(await O(e))}(r)):Object.assign(await e,b(await t))}),{})}const j=e=>new Promise(((t,n)=>{a.default.readFile(e,"utf8",((e,s)=>{e?n(e):t(s)}))})),O=async e=>JSON.parse(await j(e));function v(e){if(!e)return;let t=null;try{t=i.default(e)}catch(e){return}if(!t||!t.nodes||!t.nodes.length)return;if(1!==t.nodes.length)return;for(;"function"===t.nodes[0].type&&""===t.nodes[0].value;)t=t.nodes[0];let n=-1;for(let e=0;e<t.nodes.length;e++){const s=t.nodes[e];if("space"!==s.type&&"comment"!==s.type){if("word"===s.type&&s.value.startsWith("--")){n=e;break}return}}return n<0?void 0:t.nodes[n].value.trim()}function $(e,t){let n=e.nodes.
|