@master/css-compiler 2.0.0-beta.11 → 2.0.0-beta.110

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 CHANGED
@@ -1,80 +1,158 @@
1
- <br><br>
1
+ <br>
2
2
  <div align="center">
3
3
 
4
4
  <p align="center">
5
- <img src="https://raw.githubusercontent.com/master-co/package/document/images/logo-and-text.svg" alt="logo" width="142">
5
+ <a href="https://css.master.co">
6
+ <picture>
7
+ <source media="(prefers-color-scheme: dark)" srcset="https://user-images.githubusercontent.com/33840671/201701649-3bb7d698-abec-4d5f-ac30-ccc4d7bafcd4.svg">
8
+ <source media="(prefers-color-scheme: light)" srcset="https://user-images.githubusercontent.com/33840671/201703010-77bf2373-9899-40cc-98f5-30cf9b546941.svg">
9
+ <img alt="Master CSS" src="https://user-images.githubusercontent.com/33840671/201703010-77bf2373-9899-40cc-98f5-30cf9b546941.svg" width="100%">
10
+ </picture>
11
+ </a>
6
12
  </p>
13
+ <p align="center">The ahead-of-time compiler of Master CSS</p>
14
+
7
15
  <p align="center">
8
- <b><!-- name -->CSS Compiler<!----></b>
16
+ <a aria-label="overview" href="https://github.com/master-co/css/tree/beta">
17
+ <picture>
18
+ <source media="(prefers-color-scheme: dark)" srcset="https://img.shields.io/badge/%E2%AC%85%20back-%20?color=212022&style=for-the-badge">
19
+ <source media="(prefers-color-scheme: light)" srcset="https://img.shields.io/badge/%E2%AC%85%20back-%20?color=f6f7f8&style=for-the-badge">
20
+ <img alt="NPM Version" src="https://img.shields.io/badge/%E2%AC%85%20back-%20?color=f6f7f8&style=for-the-badge">
21
+ </picture>
22
+ </a>
23
+ <a aria-label="GitHub release (latest by date including pre-releases)" href="https://github.com/master-co/css/releases">
24
+ <picture>
25
+ <source media="(prefers-color-scheme: dark)" srcset="https://img.shields.io/github/v/release/master-co/css?include_prereleases&color=212022&label=&style=for-the-badge&logo=github&logoColor=fff">
26
+ <source media="(prefers-color-scheme: light)" srcset="https://img.shields.io/github/v/release/master-co/css?include_prereleases&color=f6f7f8&label=&style=for-the-badge&logo=github&logoColor=%23000">
27
+ <img alt="NPM Version" src="https://img.shields.io/github/v/release/master-co/css?include_prereleases&color=f6f7f8&label=&style=for-the-badge&logo=github">
28
+ </picture>
29
+ </a>
30
+ <a aria-label="NPM Package" href="https://www.npmjs.com/package/@master/css-compiler">
31
+ <picture>
32
+ <source media="(prefers-color-scheme: dark)" srcset="https://img.shields.io/npm/dm/@master/css-compiler?color=212022&label=%20&logo=npm&style=for-the-badge">
33
+ <source media="(prefers-color-scheme: light)" srcset="https://img.shields.io/npm/dm/@master/css-compiler?color=f6f7f8&label=%20&logo=npm&style=for-the-badge">
34
+ <img alt="NPM package ( download / month )" src="https://img.shields.io/npm/dm/@master/css-compiler?color=f6f7f8&label=%20&logo=npm&style=for-the-badge">
35
+ </picture>
36
+ </a>
37
+ <a aria-label="Discord Community" href="https://discord.gg/sZNKpAAAw6">
38
+ <picture>
39
+ <source media="(prefers-color-scheme: dark)" srcset="https://img.shields.io/discord/917780624314613760?color=212022&label=%20&logo=discord&style=for-the-badge">
40
+ <source media="(prefers-color-scheme: light)" srcset="https://img.shields.io/discord/917780624314613760?color=f6f7f8&label=%20&logo=discord&style=for-the-badge">
41
+ <img alt="Discord online" src="https://img.shields.io/discord/917780624314613760?color=f6f7f8&label=%20&logo=discord&style=for-the-badge">
42
+ </picture>
43
+ </a>
44
+ <a aria-label="Follow @mastercorg" href="https://twitter.com/mastercorg">
45
+ <picture>
46
+ <source media="(prefers-color-scheme: dark)" srcset="https://img.shields.io/static/v1?label=%20&message=twitter&color=212022&logo=twitter&style=for-the-badge">
47
+ <source media="(prefers-color-scheme: light)" srcset="https://img.shields.io/static/v1?label=%20&message=twitter&color=f6f7f8&logo=twitter&style=for-the-badge">
48
+ <img alt="Follow @mastercorg" src="https://img.shields.io/static/v1?label=%20&message=twitter&color=f6f7f8&logo=twitter&style=for-the-badge">
49
+ </picture>
50
+ </a>
51
+ <a aria-label="Github Actions" href="https://github.com/1aron/repo/actions/workflows/release.yml">
52
+ <picture>
53
+ <source media="(prefers-color-scheme: dark)" srcset="https://img.shields.io/github/actions/workflow/status/master-co/css/release.yml?branch=beta&label=%20&message=twitter&color=212022&logo=githubactions&style=for-the-badge">
54
+ <source media="(prefers-color-scheme: light)" srcset="https://img.shields.io/github/actions/workflow/status/master-co/css/release.yml?branch=beta&label=%20&message=twitter&color=f6f7f8&logo=githubactions&style=for-the-badge&logoColor=%23000">
55
+ <img alt="Github release actions" src="https://img.shields.io/github/actions/workflow/status/master-co/css/release.yml?branch=beta&label=%20&message=twitter&color=f6f7f8&logo=githubactions&style=for-the-badge&logoColor=%23000">
56
+ </picture>
57
+ </a>
9
58
  </p>
10
- <p align="center"><!-- package.description -->Compile Master CSS ahead of time with zero-configuration integration with build tools<!----></p>
11
-
12
- [![MIT License](https://flat.badgen.net/github/license/master-co/css?color=yellow)](https://github.com/master-co/css-compiler/blob/main/LICENSE)
13
- [![Latest Release](https://flat.badgen.net/npm/v/@master/css-compiler?icon=npm&label&color=yellow)](https://www.npmjs.com/package/@master/css-compiler)
14
- [![Documentation](https://flat.badgen.net/badge/icon/Documentation?icon=awesome&label&color=yellow)](https://css.master.co)
15
- [![Github](https://flat.badgen.net/badge/icon/master-co%2Fcss-compiler?icon=github&label&color=yellow)](https://github.com/master-co/css)
16
- [![Discord](https://flat.badgen.net/badge/icon/discord?icon=discord&label&color=yellow)](https://discord.gg/sZNKpAAAw6)
17
- [![CI](https://flat.badgen.net/github/status/master-co/css-compiler/main/ci/circleci?icon=circleci)](https://circleci.com/gh/master-co/workflows/css-compiler/tree/main)
18
59
 
19
60
  </div>
20
61
 
21
- ##### On this page
62
+ ## Usage
63
+ ```bash
64
+ npm install @master/css-compiler
65
+ ```
22
66
 
23
- - [Usage](#usage)
24
- - [`webpack.config.js`](#webpackconfigjs)
25
- - [`vite.config.js`](#viteconfigjs)
26
- - [`next.config.js`](#nextconfigjs)
27
- - [Related](#related)
67
+ ```ts
68
+ const compiler = await new MasterCSSCompiler()
69
+ ```
28
70
 
29
- ---
71
+ ## Options
72
+ ```ts
73
+ {
74
+ // specify virtual CSS module id (e.g. virtual:master.css)
75
+ module: 'master.css',
76
+ // specify config file path or set `Config`
77
+ config: 'master.css.{ts,js,mjs,cjs}',
78
+ // forcibly specify sources for scanning, not excluded by `options.exclude`
79
+ sources: [],
80
+ // specify sources for scanning
81
+ include: ['**/*.{html,js,jsx,ts,tsx,svelte,astro,vue,md,mdx,pug,php}'],
82
+ // specify sources to exclude
83
+ exclude: [
84
+ '**/node_modules/**',
85
+ '**/*.d.ts',
86
+ '**/*.test.*',
87
+ 'node_modules',
88
+ 'master.css.{js,ts,mjs,cjs}',
89
+ 'dist',
90
+ 'out',
91
+ 'README.md'
92
+ ],
93
+ classes: {
94
+ // whitelist of class names for unpredictable dynamics
95
+ fixed: [],
96
+ // blacklist of class names to exclude accidentally captured
97
+ ignored: [] // or RegExp[]
98
+ },
99
+ cwd: process.cwd()
100
+ }
101
+ ```
30
102
 
31
- # Usage
103
+ ## Methods
32
104
 
33
- ## `webpack.config.js`
34
- ```js
35
- const { MasterCSSWebpackPlugin } = require('@master/css-compiler')
105
+ ```ts
106
+ // Reload the compiler and MasterCSS
107
+ refresh(): this
108
+ ```
36
109
 
37
- module.exports = {
38
- plugins: [
39
- new MasterCSSWebpackPlugin()
40
- ]
41
- };
110
+ ```ts
111
+ // Scan sources, extract class names, and generate CSS rules
112
+ compile()
42
113
  ```
43
114
 
44
- ## `vite.config.js`
45
- ```js
46
- import { MasterCSSVitePlugin } from '@master/css-compiler'
115
+ ```ts
116
+ // Extract potential class names from the given file content
117
+ extract(name: string, content: string): string[]
118
+ ```
47
119
 
48
- export default defineConfig({
49
- plugins: [
50
- MasterCSSVitePlugin()
51
- ]
52
- })
120
+ ```ts
121
+ // `extract(name, content)`, insert extractions, and generate CSS rules
122
+ insert(name: string, content: string): boolean
53
123
  ```
54
124
 
55
- ## `next.config.js`
56
- ```js
57
- const { MasterCSSWebpackPlugin } = require('@master/css-compiler')
58
-
59
- const nextConfig = {
60
- ...,
61
- webpack: (config) => {
62
- config.plugins.push(
63
- new MasterCSSWebpackPlugin({
64
- output: {
65
- path: 'static/css'
66
- }
67
- })
68
- )
69
- return config
70
- }
71
- }
125
+ ```ts
126
+ // Read file source paths by `options.include` and `options.exclude`
127
+ get sources(): string[]
128
+ ```
72
129
 
73
- module.exports = nextConfig
130
+ ```ts
131
+ // Check source file path by `options.include` and `options.exclude`
132
+ checkSourcePath(name: string): boolean
74
133
  ```
75
134
 
76
- ---
135
+ ```ts
136
+ // Read user config file by `options.config`
137
+ readConfig(): Config
138
+ ```
77
139
 
78
- # Related
79
- - [@master/css](https://github.com/master-co/css) - A Virtual CSS language with enhanced syntax. ( ~13KB )
80
- - [@master/css.react](https://github.com/master-co/css.react) - React hooks for Master CSS
140
+ ```ts
141
+ // Get user config path
142
+ get configPath(): string
143
+ ```
144
+
145
+ ```ts
146
+ // Get resolved user config path
147
+ get resolvedConfigPath(): string
148
+ ```
149
+
150
+ ## Properties
151
+
152
+ ```ts
153
+ export default class MasterCSSCompiler {
154
+ css: MasterCSS
155
+ extractions = new Set<string>()
156
+ ...
157
+ }
158
+ ```
@@ -1,11 +1,19 @@
1
- import { MasterCSSCompilerOptions, MasterCSSCompilerSource } from './options';
2
- import MasterCSS from '@master/css';
3
- export default class MasterCSSCompiler {
4
- options?: MasterCSSCompilerOptions;
5
- constructor(options?: MasterCSSCompilerOptions);
1
+ import { Options } from './options';
2
+ import MasterCSS, { Rule } from '@master/css';
3
+ import type { Config } from '@master/css';
4
+ import Techor from 'techor';
5
+ export default class MasterCSSCompiler extends Techor<Options, Config> {
6
6
  css: MasterCSS;
7
7
  extractions: Set<string>;
8
- extract({ name, content }: MasterCSSCompilerSource): string[];
9
- insert(extractions: any): void;
10
- log(name: any, content: any): void;
8
+ get resolvedModuleId(): string;
9
+ get moduleHMREvent(): string;
10
+ constructor(options?: Options);
11
+ refresh(): Promise<this>;
12
+ compile(): Promise<this>;
13
+ extract(name: string, content: string): string[];
14
+ insert(name: string, content: string): Promise<boolean>;
15
+ createRules(extraction: string): Promise<Rule[]>;
16
+ get sources(): string[];
17
+ checkSourcePath(name: string): boolean;
18
+ get config(): Config;
11
19
  }
@@ -0,0 +1,3 @@
1
+ import MasterCSS from '@master/css';
2
+ import type { Source } from './options';
3
+ export default function extract({ content }: Source, { config, classes }: MasterCSS): string[];
package/dist/index.cjs CHANGED
@@ -1,2 +1,10 @@
1
- var z=Object.create;var w=Object.defineProperty;var W=Object.getOwnPropertyDescriptor;var B=Object.getOwnPropertyNames;var G=Object.getPrototypeOf,V=Object.prototype.hasOwnProperty;var q=(t,e)=>{for(var s in e)w(t,s,{get:e[s],enumerable:!0})},F=(t,e,s,r)=>{if(e&&typeof e=="object"||typeof e=="function")for(let o of B(e))!V.call(t,o)&&o!==s&&w(t,o,{get:()=>e[o],enumerable:!(r=W(e,o))||r.enumerable});return t};var u=(t,e,s)=>(s=t!=null?z(G(t)):{},F(e||!t||!t.__esModule?w(s,"default",{value:t,enumerable:!0}):s,t)),J=t=>F(w({},"__esModule",{value:!0}),t);var L={};q(L,{MasterCSSCompiler:()=>l,MasterCSSVitePlugin:()=>_,MasterCSSWebpackPlugin:()=>h});module.exports=J(L);var M=u(require("path")),c=u(require("chalk"));var I=require("@master/css");function v({content:t}){let e=t.match(/[^\s]+/g)??[],s=new Set;for(let r of e){let o=P(r);if(o.size)for(let n of o)s.add(n);else s.add(A(r))}return[...s].filter(r=>r&&!U(r))}var A=t=>{let e=t;return t=t.replace(/^([\w={[(\\]*["'`])/,""),t.match(/^content:((?<!\\)["'`])((?:\\\1|(?:(?!\1))[\S\s])*)((?<!\\)\1)$/)||(t=t.replace(/(\.*|[([{\\:#]*|["'`].*)$/,"")),e===t?t:A(t)},P=t=>{let e=new Set,s=/((?<!\\)["'`])((?:\\\1|(?:(?!\1))[\S\s])*)((?<!\\)\1)/g,r;for(;(r=s.exec(t))!==null;){r.index===s.lastIndex&&s.lastIndex++;let o=P(r[2]);if(o.size)for(let n of o)e.add(n);else e.add(A(r[2]))}return e},U=t=>!t||!t.match(/(?:^[\w-]+:[\w$#]+)|(?:^[@~][\w-]+$)/)&&!Object.keys(I.defaultSemantics).includes(t)||t.match(/\*\*/)||t.match(/:\[/)||t.match(/\$\{/)||t.match(/\{\{/)||t.match(/\(\{[^}]*\}/)||t.match(/<\w+>|<\/\w+>/);var K={output:{name:"master.css",dir:""},accept({name:t}){if(t.match(/[\\/]node_modules[\\/]/))return!1;if(t.match(/\.(html|js|jsx|ts|tsx|svelte|astro|vue)$/i))return!0},extract:v},N=K;var y=u(require("@master/css")),E=require("perf_hooks"),l=class{constructor(e){this.options=e;this.options=(0,y.extend)(N,e);let s;try{s=require(M.default.resolve(process.cwd(),e.config||"./master.css.js"))}catch{}this.css=new y.default(s)}css;extractions=new Set;extract({name:e,content:s}){if(!e||!s||!this.options.accept?.({content:s,name:e}))return[];let r=[];this.log("accepts",` \u2192 ${M.default.relative(process.cwd(),e)}`);for(let o of this.options.extract({content:s,name:e}))this.extractions.has(o)||(this.extractions.add(o),r.push(o));return r}insert(e){let s=E.performance.now();for(let n of e)this.css.findAndInsert(n);let r=Math.round((E.performance.now()-s)*1e3),o=this.css.rules.map(n=>n.className);console.log(`[Master CSS] process ${c.default.green(e.length)} extractions in ${c.default.green(r)} \xB5s [${c.default.green(this.css.rules.length)} rules in ${c.default.green(M.default.join(this.options.output.dir,this.options.output.name))}]`),this.log("extractions",` \u2192 ${c.default.green(e.length)} extractions: ${c.default.blue(e.join(" "))}`),this.log("validClasses",` \u2192 ${c.default.green(o.length)} total valid classes: ${c.default.blue(o.join(" "))}`)}log(e,s){(this.options.debug===!0||Array.isArray(this.options.debug)&&this.options.debug.includes(e))&&console.log(s)}};var D=u(require("path"));var T="MasterCSSWebpackPlugin",h=class extends l{apply(e){let{webpack:s}=e,{Template:r,RuntimeGlobals:o,RuntimeModule:n}=s,{RawSource:S}=s.sources,{Compilation:g}=s,{options:i}=this,a=D.default.join(i.output.dir||"",i.output.name),k=a.replace(/\\/g,"/");e.hooks.compilation.tap(T,p=>{p.hooks.finishModules.tap(T,f=>{let{modifiedFiles:m,watching:H}=e,O=[];for(let C of f){let d=C.resource,x=C._source?.source();H&&m?.size&&!m.has(d)||O.push(...this.extract({name:d,content:x}))}if(O.length){let C=this.css.text;this.insert(O);let d=this.css.text;if(d!==C){let x=new S(d);p.getAsset(a)?p.updateAsset(a,x):p.emitAsset(a,x)}}}),p.hooks.processAssets.tap({name:T,stage:g.PROCESS_ASSETS_STAGE_ADDITIONS},()=>{p.chunks.forEach(f=>{f.files.add(a)})})})}};var j=u(require("path"));var b=u(require("fs")),R=u(require("path"));function $(t,e,s){let r=R.default.dirname(t);b.default.existsSync(r)||b.default.mkdirSync(r,{recursive:!0}),b.default.writeFileSync(t,e,s)}function _(t){let e=new l(t),s=j.default.join(e.options.output.dir||"",e.options.output.name),r,o,n,S=!1,g=(i,a)=>{let k=e.extract({name:i,content:a});if(k.length){let p=e.css.text;e.insert(k);let f=e.css.text;if(f!==p&&r){$(o,f);let m=()=>{r.ws.send({type:"update",updates:[{path:n,timestamp:Date.now()}]})};S?m():(setTimeout(m,500),S=!0)}}};return{name:"vite-plugin-master-css",enforce:"pre",configureServer(i){r=i},buildStart(){o=j.default.resolve(r?.config.cacheDir??process.cwd(),s),r&&($(o,""),n=(r.config.cacheDir.slice(process.cwd().length)+"/"+s).replace(/\\/g,"/"))},resolveId(i){if(i.endsWith("master.css?direct"))return"\0"+i},transform(i,a){g(a,i)},transformIndexHtml(i){return i.replace(/(<head>)/,`$1<link rel="stylesheet" href="${n}">`)},async handleHotUpdate(i){g(i.file,await i.read())},generateBundle(){let i=this.emitFile({type:"asset",name:s,source:e.css.text});n="/"+this.getFileName(i)}}}0&&(module.exports={MasterCSSCompiler,MasterCSSVitePlugin,MasterCSSWebpackPlugin});
2
- //# sourceMappingURL=index.cjs.map
1
+ var $e=Object.create;var E=Object.defineProperty;var Oe=Object.getOwnPropertyDescriptor;var we=Object.getOwnPropertyNames;var Te=Object.getPrototypeOf,Ce=Object.prototype.hasOwnProperty;var Re=(r,e)=>{for(var t in e)E(r,t,{get:e[t],enumerable:!0})},q=(r,e,t,s)=>{if(e&&typeof e=="object"||typeof e=="function")for(let n of we(e))!Ce.call(r,n)&&n!==t&&E(r,n,{get:()=>e[n],enumerable:!(s=Oe(e,n))||s.enumerable});return r};var m=(r,e,t)=>(t=r!=null?$e(Te(r)):{},q(e||!r||!r.__esModule?E(t,"default",{value:r,enumerable:!0}):t,r)),Ee=r=>q(E({},"__esModule",{value:!0}),r);var fr={};Re(fr,{default:()=>R,options:()=>k});module.exports=Ee(fr);var A=m(require("upath"));var ke={module:"master.css",config:"master.css.{ts,js,mjs,cjs}",sources:[],include:["**/*.{html,js,jsx,ts,tsx,svelte,astro,vue,md,mdx,pug,php}"],exclude:["**/node_modules/**","**/*.d.ts","**/*.test.*","node_modules","master.css.{js,ts,mjs,cjs}","dist","out","README.md","public"],classes:{fixed:[],ignored:[]}},k=ke;var U=m(require("@master/css")),V=require("perf_hooks");var K=require("@master/css");function F({content:r},{config:e,classes:t}){r=Se(r);let s=[...new Set(Object.keys(e.semantics??K.semantics).concat(Object.keys(t)))],n=r.match(/\S+/g)??[],i=new Set;for(let l of n){i.add(P(l,s));let a=Q(l);if(a.size)for(let p of a)i.add(P(p,s))}return[...i].filter(l=>l&&!Ne(l,s))}var P=(r,e)=>{let t=r,s=r.match(/(?:calc\(.*\)|\d+(?:%|ch|cm|em|ex|in|mm|pc|pt|px|rem|vh|vmax|vmin|vw|deg|grad|rad|turn|s)?)x(?:calc\(.*\)|\d+(?:%|ch|cm|em|ex|in|mm|pc|pt|px|rem|vh|vmax|vmin|vw|deg|grad|rad|turn|s)?)/g);return(s?.length?e.concat(s):e).find(n=>t.startsWith(n))?r=I(r,n=>n.replace(/^[^:@~(]*(?<!@>?)=/,"").replace(/(?:[([{\\:#=.]+|["'`].*)$/,"")):r=I(r,n=>n.replace(/^[^:@~(]*(?:["'`]|(?<!@>?)=)/,"").replace(/(?:[([{\\:#=.]+|["'`].*)$/,"")),t===r||!r?r:P(r,e)},z=r=>r.match(/((?<!\\)["'`])(?:\\\1|(?:(?!\1))[\S\s])*(?<!\\)\1/g),Z=(r,e)=>(e?.forEach((t,s)=>{r=r.replace(t,`COMPLETE-STRING--${s}--`)}),r),I=(r,e)=>{let t=z(r);return r=Z(r,t),r=e(r),t?.forEach((s,n)=>{r=r.replace(`COMPLETE-STRING--${n}--`,s)}),r},Q=r=>{let e=new Set,t=/((?<!\\)["'`])((?:\\\1|(?:(?!\1))[\S\s])*)((?<!\\)\1)/g,s;for(;(s=t.exec(r))!==null;){s.index===t.lastIndex&&t.lastIndex++,e.add(s[2]);let n=Q(s[2]);if(n.size)for(let i of n)e.add(i)}return e},Se=r=>I(r,e=>e.replace(/\/\*(?:(?!\*\/)[\S\s])*\*\//g,"").replace(/<!--(?:(?!-->)[\S\s])*-->/g,"").replace(/<style[^>]*>(?:(?!<\/style>)[\S\s])*<\/style>/g,"").replace(/import.*from\s*COMPLETE-STRING--\d+--/g,"").replace(/import\s*(?:COMPLETE-STRING--\d+--|\([^;\s]*\))/g,"").replace(/require\([^;\s]*\)/g,"")),Ne=(r,e)=>{let t=z(r),s=Z(r,t),n=/{(.*)}/,i;for(;(i=n.exec(s))!==null;)return i[1].split(";").find(a=>J(a,e))!==void 0;return J(s,e)||je(r)},J=(r,e)=>!r||!r.match(/(?:\S*\{\S*\})|(?:^[\w\-()]+:\S+)|(?:^[\w-]+\(\S+\))|(?:^[@~]\S+$)/)&&!r.match(/^(?:calc\(.*\)|\d+(?:%|ch|cm|em|ex|in|mm|pc|pt|px|rem|vh|vmax|vmin|vw|deg|grad|rad|turn|s)?)x(?:calc\(.*\)|\d+(?:%|ch|cm|em|ex|in|mm|pc|pt|px|rem|vh|vmax|vmin|vw|deg|grad|rad|turn|s)?)$/)&&!e.find(t=>r.startsWith(t))||r.match(/\*\*/)||r.match(/:\[/)||r.match(/\$\{/)||r.match(/\{\{/)||r.match(/\(\{[^}]*\}/)||r.match(/<\w+>|<\/\w+>/)||r.match(/;$/)||r.match(/^\w+:\/\//)||r.match(/^@(?:ts-[^\s]+|charset|import|namespace|media|supports|document|page|font-face|keyframes|counter-style|font-feature-values|property|layer)$/)||r.match(/^~\/.+.\w+$/)||r.match(/function\(|\(.*\)=>/),je=r=>{let e=[],t;for(let s=0;s<r.length;s++)switch(r[s]){case"(":case"[":case"{":e.push(r[s]);break;case")":case"]":case"}":if(t=e.pop(),r[s]===")"&&t!=="("||r[s]==="]"&&t!=="["||r[s]==="}"&&t!=="{")return!0;break}return e.length>0};var me=m(require("fs")),H=m(require("fast-glob")),B=m(require("minimatch")),be=m(require("techor"));var j=m(require("node:process"),1),he=m(require("node:os"),1),L=m(require("node:tty"),1),Ae=Object.create,ge=Object.defineProperty,Be=Object.getOwnPropertyDescriptor,Me=Object.getOwnPropertyNames,Pe=Object.getPrototypeOf,Ie=Object.prototype.hasOwnProperty,Fe=(r,e)=>()=>(e||r((e={exports:{}}).exports,e),e.exports),_e=(r,e,t,s)=>{if(e&&typeof e=="object"||typeof e=="function")for(let n of Me(e))!Ie.call(r,n)&&n!==t&&ge(r,n,{get:()=>e[n],enumerable:!(s=Be(e,n))||s.enumerable});return r},Ge=(r,e,t)=>(t=r!=null?Ae(Pe(r)):{},_e(e||!r||!r.__esModule?ge(t,"default",{value:r,enumerable:!0}):t,r)),Le=Fe((r,e)=>{"use strict";function t(s){var n=void 0;typeof s=="string"?n=[s]:n=s.raw;for(var i="",l=0;l<n.length;l++)i+=n[l].replace(/\\\n[ \t]*/g,"").replace(/\\`/g,"`"),l<(arguments.length<=1?0:arguments.length-1)&&(i+=arguments.length<=l+1?void 0:arguments[l+1]);var a=i.split(`
2
+ `),p=null;return a.forEach(function(u){var f=u.match(/^(\s+)\S+/);if(f){var x=f[1].length;p?p=Math.min(p,x):p=x}}),p!==null&&(i=a.map(function(u){return u[0]===" "?u.slice(p):u}).join(`
3
+ `)),i=i.trim(),i.replace(/\\n/g,`
4
+ `)}typeof e<"u"&&(e.exports=t)}),b=(r,e)=>{if(!r)throw new Error(e)},Ye=r=>{let e={joined:!0,spacerNoNeighbour:" ",spacerNeighbour:"\u2502 ",keyNoNeighbour:"\u2514\u2500 ",keyNeighbour:"\u251C\u2500 ",separator:": ",renderFn:t=>["boolean","string","number"].includes(typeof t)?t:void 0,sortFn:null,breakCircularWith:" (circular ref.)",...r};return b(Object.keys(e).length===9,"Unexpected Option(s) provided"),b(typeof e.joined=="boolean",'Option "joined" has invalid format'),b(typeof e.spacerNoNeighbour=="string",'Option "spacerNoNeighbour" has invalid format'),b(typeof e.spacerNeighbour=="string",'Option "spacerNeighbour" has invalid format'),b(typeof e.keyNoNeighbour=="string",'Option "keyNoNeighbour" has invalid format'),b(typeof e.keyNeighbour=="string",'Option "keyNeighbour" has invalid format'),b(typeof e.separator=="string",'Option "separator" has invalid format'),b(typeof e.renderFn=="function",'Option "renderFn" has invalid format'),b(typeof e.sortFn=="function"||e.sortFn===null,'Option "sortFn" has invalid format'),b(typeof e.breakCircularWith=="string"||e.breakCircularWith===null,'Option "breakCircularWith" has invalid format'),e},pe=(r,e={})=>{let t=Ye(e),s=[],n=t.renderFn(r);n!==void 0&&s.push(String(n));let i=u=>t.sortFn===null?u.reverse():u.sort((f,x)=>t.sortFn(x,f)),l=[],a=i(Object.keys(r)).map(u=>[u]),p=[r];for(;a.length!==0;){let u=a.pop(),f=p[u.length-1][u[u.length-1]],x=t.breakCircularWith!==null&&p.includes(f);l[u.length-1]=a.length!==0&&a[a.length-1].length===u.length;let xe=t.renderFn(f);s.push([l.slice(0,u.length-1).map(M=>M?t.spacerNeighbour:t.spacerNoNeighbour).join(""),l[u.length-1]?t.keyNeighbour:t.keyNoNeighbour,u[u.length-1],xe===void 0?"":`${t.separator}${f}`,x?t.breakCircularWith:""].join("")),f instanceof Object&&!Array.isArray(f)&&!x&&(a.push(...i(Object.keys(f)).map(M=>u.concat(M))),p[u.length]=f)}return t.joined===!0?s.join(`
5
+ `):s},X=(r=0)=>e=>`\x1B[${e+r}m`,ee=(r=0)=>e=>`\x1B[${38+r};5;${e}m`,re=(r=0)=>(e,t,s)=>`\x1B[${38+r};2;${e};${t};${s}m`,c={modifier:{reset:[0,0],bold:[1,22],dim:[2,22],italic:[3,23],underline:[4,24],overline:[53,55],inverse:[7,27],hidden:[8,28],strikethrough:[9,29]},color:{black:[30,39],red:[31,39],green:[32,39],yellow:[33,39],blue:[34,39],magenta:[35,39],cyan:[36,39],white:[37,39],blackBright:[90,39],gray:[90,39],grey:[90,39],redBright:[91,39],greenBright:[92,39],yellowBright:[93,39],blueBright:[94,39],magentaBright:[95,39],cyanBright:[96,39],whiteBright:[97,39]},bgColor:{bgBlack:[40,49],bgRed:[41,49],bgGreen:[42,49],bgYellow:[43,49],bgBlue:[44,49],bgMagenta:[45,49],bgCyan:[46,49],bgWhite:[47,49],bgBlackBright:[100,49],bgGray:[100,49],bgGrey:[100,49],bgRedBright:[101,49],bgGreenBright:[102,49],bgYellowBright:[103,49],bgBlueBright:[104,49],bgMagentaBright:[105,49],bgCyanBright:[106,49],bgWhiteBright:[107,49]}},yr=Object.keys(c.modifier),De=Object.keys(c.color),We=Object.keys(c.bgColor),xr=[...De,...We];function Ue(){let r=new Map;for(let[e,t]of Object.entries(c)){for(let[s,n]of Object.entries(t))c[s]={open:`\x1B[${n[0]}m`,close:`\x1B[${n[1]}m`},t[s]=c[s],r.set(n[0],n[1]);Object.defineProperty(c,e,{value:t,enumerable:!1})}return Object.defineProperty(c,"codes",{value:r,enumerable:!1}),c.color.close="\x1B[39m",c.bgColor.close="\x1B[49m",c.color.ansi=X(),c.color.ansi256=ee(),c.color.ansi16m=re(),c.bgColor.ansi=X(10),c.bgColor.ansi256=ee(10),c.bgColor.ansi16m=re(10),Object.defineProperties(c,{rgbToAnsi256:{value(e,t,s){return e===t&&t===s?e<8?16:e>248?231:Math.round((e-8)/247*24)+232:16+36*Math.round(e/255*5)+6*Math.round(t/255*5)+Math.round(s/255*5)},enumerable:!1},hexToRgb:{value(e){let t=/[a-f\d]{6}|[a-f\d]{3}/i.exec(e.toString(16));if(!t)return[0,0,0];let[s]=t;s.length===3&&(s=[...s].map(i=>i+i).join(""));let n=Number.parseInt(s,16);return[n>>16&255,n>>8&255,n&255]},enumerable:!1},hexToAnsi256:{value:e=>c.rgbToAnsi256(...c.hexToRgb(e)),enumerable:!1},ansi256ToAnsi:{value(e){if(e<8)return 30+e;if(e<16)return 90+(e-8);let t,s,n;if(e>=232)t=((e-232)*10+8)/255,s=t,n=t;else{e-=16;let a=e%36;t=Math.floor(e/36)/5,s=Math.floor(a/6)/5,n=a%6/5}let i=Math.max(t,s,n)*2;if(i===0)return 30;let l=30+(Math.round(n)<<2|Math.round(s)<<1|Math.round(t));return i===2&&(l+=60),l},enumerable:!1},rgbToAnsi:{value:(e,t,s)=>c.ansi256ToAnsi(c.rgbToAnsi256(e,t,s)),enumerable:!1},hexToAnsi:{value:e=>c.ansi256ToAnsi(c.hexToAnsi256(e)),enumerable:!1}}),c}var Ve=Ue(),v=Ve;function d(r,e=globalThis.Deno?globalThis.Deno.args:j.default.argv){let t=r.startsWith("-")?"":r.length===1?"-":"--",s=e.indexOf(t+r),n=e.indexOf("--");return s!==-1&&(n===-1||s<n)}var{env:g}=j.default,S;d("no-color")||d("no-colors")||d("color=false")||d("color=never")?S=0:(d("color")||d("colors")||d("color=true")||d("color=always"))&&(S=1);function He(){if("FORCE_COLOR"in g)return g.FORCE_COLOR==="true"?1:g.FORCE_COLOR==="false"?0:g.FORCE_COLOR.length===0?1:Math.min(Number.parseInt(g.FORCE_COLOR,10),3)}function qe(r){return r===0?!1:{level:r,hasBasic:!0,has256:r>=2,has16m:r>=3}}function Je(r,{streamIsTTY:e,sniffFlags:t=!0}={}){let s=He();s!==void 0&&(S=s);let n=t?S:s;if(n===0)return 0;if(t){if(d("color=16m")||d("color=full")||d("color=truecolor"))return 3;if(d("color=256"))return 2}if("TF_BUILD"in g&&"AGENT_NAME"in g)return 1;if(r&&!e&&n===void 0)return 0;let i=n||0;if(g.TERM==="dumb")return i;if(j.default.platform==="win32"){let l=he.default.release().split(".");return Number(l[0])>=10&&Number(l[2])>=10586?Number(l[2])>=14931?3:2:1}if("CI"in g)return"GITHUB_ACTIONS"in g?3:["TRAVIS","CIRCLECI","APPVEYOR","GITLAB_CI","BUILDKITE","DRONE"].some(l=>l in g)||g.CI_NAME==="codeship"?1:i;if("TEAMCITY_VERSION"in g)return/^(9\.(0*[1-9]\d*)\.|\d{2,}\.)/.test(g.TEAMCITY_VERSION)?1:0;if(g.COLORTERM==="truecolor"||g.TERM==="xterm-kitty")return 3;if("TERM_PROGRAM"in g){let l=Number.parseInt((g.TERM_PROGRAM_VERSION||"").split(".")[0],10);switch(g.TERM_PROGRAM){case"iTerm.app":return l>=3?3:2;case"Apple_Terminal":return 2}}return/-256(color)?$/i.test(g.TERM)?2:/^screen|^xterm|^vt100|^vt220|^rxvt|color|ansi|cygwin|linux/i.test(g.TERM)||"COLORTERM"in g?1:i}function te(r,e={}){let t=Je(r,{streamIsTTY:r&&r.isTTY,...e});return qe(t)}var Ke={stdout:te({isTTY:L.default.isatty(1)}),stderr:te({isTTY:L.default.isatty(2)})},ze=Ke;function Ze(r,e,t){let s=r.indexOf(e);if(s===-1)return r;let n=e.length,i=0,l="";do l+=r.slice(i,s)+e+t,i=s+n,s=r.indexOf(e,i);while(s!==-1);return l+=r.slice(i),l}function Qe(r,e,t,s){let n=0,i="";do{let l=r[s-1]==="\r";i+=r.slice(n,l?s-1:s)+e+(l?`\r
6
+ `:`
7
+ `)+t,n=s+1,s=r.indexOf(`
8
+ `,n)}while(s!==-1);return i+=r.slice(n),i}var{stdout:se,stderr:ne}=ze,Y=Symbol("GENERATOR"),$=Symbol("STYLER"),T=Symbol("IS_EMPTY"),ie=["ansi","ansi","ansi256","ansi16m"],O=Object.create(null),Xe=(r,e={})=>{if(e.level&&!(Number.isInteger(e.level)&&e.level>=0&&e.level<=3))throw new Error("The `level` option should be an integer from 0 to 3");let t=se?se.level:0;r.level=e.level===void 0?t:e.level},er=r=>{let e=(...t)=>t.join(" ");return Xe(e,r),Object.setPrototypeOf(e,C.prototype),e};function C(r){return er(r)}Object.setPrototypeOf(C.prototype,Function.prototype);for(let[r,e]of Object.entries(v))O[r]={get(){let t=N(this,W(e.open,e.close,this[$]),this[T]);return Object.defineProperty(this,r,{value:t}),t}};O.visible={get(){let r=N(this,this[$],!0);return Object.defineProperty(this,"visible",{value:r}),r}};var D=(r,e,t,...s)=>r==="rgb"?e==="ansi16m"?v[t].ansi16m(...s):e==="ansi256"?v[t].ansi256(v.rgbToAnsi256(...s)):v[t].ansi(v.rgbToAnsi(...s)):r==="hex"?D("rgb",e,t,...v.hexToRgb(...s)):v[t][r](...s),rr=["rgb","hex","ansi256"];for(let r of rr){O[r]={get(){let{level:t}=this;return function(...s){let n=W(D(r,ie[t],"color",...s),v.color.close,this[$]);return N(this,n,this[T])}}};let e="bg"+r[0].toUpperCase()+r.slice(1);O[e]={get(){let{level:t}=this;return function(...s){let n=W(D(r,ie[t],"bgColor",...s),v.bgColor.close,this[$]);return N(this,n,this[T])}}}}var tr=Object.defineProperties(()=>{},{...O,level:{enumerable:!0,get(){return this[Y].level},set(r){this[Y].level=r}}}),W=(r,e,t)=>{let s,n;return t===void 0?(s=r,n=e):(s=t.openAll+r,n=e+t.closeAll),{open:r,close:e,openAll:s,closeAll:n,parent:t}},N=(r,e,t)=>{let s=(...n)=>sr(s,n.length===1?""+n[0]:n.join(" "));return Object.setPrototypeOf(s,tr),s[Y]=r,s[$]=e,s[T]=t,s},sr=(r,e)=>{if(r.level<=0||!e)return r[T]?"":e;let t=r[$];if(t===void 0)return e;let{openAll:s,closeAll:n}=t;if(e.includes("\x1B"))for(;t!==void 0;)e=Ze(e,t.close,t.open),t=t.parent;let i=e.indexOf(`
9
+ `);return i!==-1&&(e=Qe(e,n,s,i)),s+e+n};Object.defineProperties(C.prototype,O);var nr=C(),$r=C({level:ne?ne.level:0}),o=nr;function y(r){return r.split(" ").map(e=>e.replace(/^(\d*\.?\d*)$/g,`${o.blue("$1")}`).replace(/^(\d*\.?\d*)(YB|ZB|EB|PB|TB|GB|MB|KB|B|mb|kb|bit|zs|as|fs|ps|ns|µs|ms|s|m|h|d|m|y)$/g,`${o.cyan("$1")}${o.magenta("$2")}`).replace(/^((?:[0-1]?[0-9]|[2][0-3]):[0-5][0-9]:[0-5][0-9] (?:AM|PM)?)$/g,`${o.dim("$1")}`).replace(/^\[(.*?)\]$/g,`${o.dim("[")}${o.magenta("$1")}${o.dim("]")}`).replace(/^`(.*?)`$/g,`${o.dim("`")}$1${o.dim("`")}`).replace(/^\((.*?)\)$/g,`${o.dim("(")}$1${o.dim(")")}`).replace(/^<(.*?)>$/g,`${o.dim("<")}${o.gray("$1")}${o.dim(">")}`).replace(/->/g,o.dim("\u2192")).replace(/<-/g,o.dim("\u2190")).replace(/^\$t$/g,`${o.dim(new Date().toLocaleTimeString())}`).replace(/^\*\*(.*?)\*\*$/g,`${o.bold.white("$1")}`).replace(/^~~(.*?)~~$/g,`${o.strikethrough("$1")}`).replace(/^__(.*?)__$/g,`${o.underline("$1")}`).replace(/^\.\.(.*?)\.\.$/g,`${o.dim("$1")}`).replace(/^!!(.*?)!!$/g,`${o.yellow("$1")}`).replace(/^\*(.*?)\*$/g,`${o.italic("$1")}`).replace(/^_(.*?)_$/g,`${o.italic("$1")}`).replace(/^\+(.*?)\+$/g,`${o.green("$1")}`).replace(/^-(.*?)-$/g,`${o.red("$1")}`)).join(" ")}function h(r,e){let t="";if(Array.isArray(r))for(let s=0;s<r.length;s++)t+=_(r[s])+_(e[s]);else t=[r,...e].map(s=>_(s)).join(" ");return y(t)}var _=r=>r?Array.isArray(r)?r.map(e=>{switch(typeof e){case"string":return`'${o.yellow(e)}'`;case"number":case"boolean":return o.blue(e);default:return e}}).join(o.gray(", ")):r:"",oe=(r,...e)=>{let t=o.green("+")+" "+h(r,e);return console.log(t),t},le=(r,...e)=>{let t=o.bgRed.bold.white(" \u{1D5EB} ERROR ")+" "+h(r,e);return console.log(t),t},ir=(r,...e)=>{let t=o.bgYellow.bold.white(" \u26A0\uFE0F CONFLICT ")+" "+o.yellow(h(r,e));return console.log(t),t},or=(r,...e)=>{let t=o.green("\u2713 ")+h(r,e);return console.log(t),t},G=(r,...e)=>{let t=o.red("-")+" "+h(r,e);return console.log(t),t},ae=(r,...e)=>{let t=o.green("\u25CB ")+h(r,e);return console.log(t),t},ce=(r,...e)=>{let t=o.red("\u2717 ")+h(r,e);return console.log(t),t},ue=(r,...e)=>{let t=y("$t ")+h(r,e);return console.log(t),t},lr=(r,...e)=>{let t=o.green("\u23FA Success ")+h(r,e);return console.log(t),t},ar=(r,...e)=>{let t=o.yellow("\u23FA Warn ")+h(r,e);return console.log(t),t},cr=(r,...e)=>{let t=o.bgGreen.bold.white(" \u2713 PASS ")+" "+h(r,e);return console.log(t),t},ur=r=>{console.log(pe(fe(JSON.parse(JSON.stringify(r))),{spacerNeighbour:y("..\u2502..")+" ",keyNoNeighbour:y("..\u2514\u2500..")+" ",keyNeighbour:y("..\u251C\u2500..")+" ",separator:y("..:..")+" "}))};function fe(r){for(let e in r){let t=r[e];Array.isArray(t)?r[e]=t.map(s=>y(`**${s}**`)).join(y("..,..")):typeof t=="object"?fe(t):r[e]=y(`**${t}**`)}return r}var gr=(r,...e)=>{let t=o.red("\u23FA Fail ")+h(r,e);return console.log(t),t},pr=Ge(Le());function hr(r){let{message:e,stack:t}=typeof r=="string"?new Error(r):r,s={};return(0,pr.default)(t.replace(e,"").replace(/^Error: /,"")).split(`
10
+ `).forEach(n=>{s[n.split(" ").map(i=>i.replace(/^\((.+)\)$/,`${o.cyan("$1")}`).replace(/\./g,`${o.dim(".")}`).replace(/^at$/,l=>o.dim(l))).join(" ")]=null}),{message:e.trim().replace(/Error: /g,""),stackTree:s}}var de=(r,...e)=>{if(r instanceof Error){let{message:t,stackTree:s}=hr(r);return console.log(""),console.log(o.bgRed.bold.white(" \u{1D5EB} ERROR ")+" "+o.bold.red(t)),console.log(pe(s,{spacerNeighbour:o.redBright.dim("\u2502\u2000\u2000"),keyNoNeighbour:o.redBright.dim("\u2514\u2500\u2000"),keyNeighbour:o.redBright.dim("\u251C\u2500 "),separator:o.redBright.dim(":\u2000")})),console.log(""),t}else{let t=h(r,e);return console.log(t),t}};Object.assign(de,{a:oe,add:oe,d:G,del:G,delete:G,o:ae,valid:ae,x:ce,invalid:ce,i:ue,info:ue,e:le,error:le,success:lr,fail:gr,warn:ar,pass:cr,conflict:ir,ok:or,tree:ur,paint:y});var w=de;var ve=m(require("stylelint")),ye=m(require("to-extend")),R=class extends be.default{css;extractions=new Set;get resolvedModuleId(){return"\0"+this.options.module}get moduleHMREvent(){return`HMR:${this.options.module}`}constructor(e){super(k,e);let t=this.readConfig(null);this.options=(0,ye.default)(this.options,t?.compilerOptions,e),console.log(""),this.css=t?.css??new U.default(t?.config)}async refresh(){return this.extractions.clear(),console.log(""),this.css=new U.default(this.readConfig()),await this.compile(),this}async compile(){if(this.options.classes?.fixed?.length)for(let e of this.options.classes.fixed)this.css.insert(e);return await Promise.all(this.sources.map(async e=>{let t=me.default.readFileSync(A.default.resolve(this.options.cwd,e),{encoding:"utf-8"}).toString();await this.insert(e,t)})),this}extract(e,t){if(!e||!t||!this.checkSourcePath(e))return[];let s=[];for(let n of F({content:t,name:e},this.css))this.extractions.has(n)||(this.extractions.add(n),s.push(n));return s}async insert(e,t){let s=this.extract(e,t);if(!s.length)return!1;let n=V.performance.now(),i=[];await Promise.all(s.map(async a=>{let p=await this.createRules(a);p.length&&(this.css.insertRules(p),i.push(a))}));let l=Math.round((V.performance.now()-n)*100)/100;if(s.length&&(console.log(""),w`**${A.default.relative(this.options.cwd,e)}** ..${A.default.resolve(this.options.cwd,e)}..`,w`[extract] ${s.length} potential`),this.css.rules.length){let a=i.filter(p=>!s.includes(p));a.length&&w`[exclude] ${a.length} unknow ${a}`,w`[compile] +${i.length}+ valid inserted ${o.gray("in")} ${l}ms ${i}`,w`[virtual] ${this.css.rules.length} total ${o.gray("in")} ${this.options.module}`}return this.options.classes?.ignored?.length&&(s=s.filter(a=>{for(let p of this.options.classes.ignored)if(typeof p=="string"){if(p===a)return!1}else if(p.test(a))return!1;return!0})),!0}async createRules(e){return(await Promise.all(this.css.create(e).map(async t=>(await ve.default.lint({code:t.text,cache:!1,config:{rules:{"color-no-invalid-hex":!0,"named-grid-areas-no-invalid":!0,"at-rule-no-unknown":!0,"function-no-unknown":!0,"media-feature-name-no-unknown":!0,"property-no-unknown":!0,"selector-pseudo-class-no-unknown":!0,"selector-pseudo-element-no-unknown":!0,"selector-type-no-unknown":!0,"unit-no-unknown":!0}}})).errored?null:t))).filter(t=>t)}get sources(){let{include:e,exclude:t,sources:s}=this.options,n=H.default.sync(e,{cwd:this.options.cwd,ignore:t});return s?.length&&n.push(...H.default.sync(s,{cwd:this.options.cwd})),n}checkSourcePath(e){let{include:t,exclude:s,sources:n}=this.options;for(let i of n)if((0,B.default)(e,i))return!0;for(let i of t)if(!(0,B.default)(e,i))return!1;for(let i of s)if((0,B.default)(e,i))return!1;return!0}get config(){return this.css.config}};0&&(module.exports={options});
package/dist/index.d.ts CHANGED
@@ -1,3 +1,3 @@
1
- export { default as MasterCSSCompiler } from './compiler';
2
- export { default as MasterCSSWebpackPlugin } from './webpack';
3
- export { default as MasterCSSVitePlugin } from './vite';
1
+ export { default } from './compiler';
2
+ export { default as options } from './options';
3
+ export type { Options, Source } from './options';
package/dist/index.mjs CHANGED
@@ -1,2 +1,10 @@
1
- var v=(t=>typeof require<"u"?require:typeof Proxy<"u"?new Proxy(t,{get:(e,s)=>(typeof require<"u"?require:e)[s]}):t)(function(t){if(typeof require<"u")return require.apply(this,arguments);throw new Error('Dynamic require of "'+t+'" is not supported')});import $ from"path";import l from"chalk";import{defaultSemantics as I}from"@master/css";function y({content:t}){let e=t.match(/[^\s]+/g)??[],s=new Set;for(let r of e){let i=A(r);if(i.size)for(let n of i)s.add(n);else s.add(b(r))}return[...s].filter(r=>r&&!P(r))}var b=t=>{let e=t;return t=t.replace(/^([\w={[(\\]*["'`])/,""),t.match(/^content:((?<!\\)["'`])((?:\\\1|(?:(?!\1))[\S\s])*)((?<!\\)\1)$/)||(t=t.replace(/(\.*|[([{\\:#]*|["'`].*)$/,"")),e===t?t:b(t)},A=t=>{let e=new Set,s=/((?<!\\)["'`])((?:\\\1|(?:(?!\1))[\S\s])*)((?<!\\)\1)/g,r;for(;(r=s.exec(t))!==null;){r.index===s.lastIndex&&s.lastIndex++;let i=A(r[2]);if(i.size)for(let n of i)e.add(n);else e.add(b(r[2]))}return e},P=t=>!t||!t.match(/(?:^[\w-]+:[\w$#]+)|(?:^[@~][\w-]+$)/)&&!Object.keys(I).includes(t)||t.match(/\*\*/)||t.match(/:\[/)||t.match(/\$\{/)||t.match(/\{\{/)||t.match(/\(\{[^}]*\}/)||t.match(/<\w+>|<\/\w+>/);var N={output:{name:"master.css",dir:""},accept({name:t}){if(t.match(/[\\/]node_modules[\\/]/))return!1;if(t.match(/\.(html|js|jsx|ts|tsx|svelte|astro|vue)$/i))return!0},extract:y},E=N;import D,{extend as R}from"@master/css";import{performance as T}from"perf_hooks";var p=class{constructor(e){this.options=e;this.options=R(E,e);let s;try{s=v($.resolve(process.cwd(),e.config||"./master.css.js"))}catch{}this.css=new D(s)}css;extractions=new Set;extract({name:e,content:s}){if(!e||!s||!this.options.accept?.({content:s,name:e}))return[];let r=[];this.log("accepts",` \u2192 ${$.relative(process.cwd(),e)}`);for(let i of this.options.extract({content:s,name:e}))this.extractions.has(i)||(this.extractions.add(i),r.push(i));return r}insert(e){let s=T.now();for(let n of e)this.css.findAndInsert(n);let r=Math.round((T.now()-s)*1e3),i=this.css.rules.map(n=>n.className);console.log(`[Master CSS] process ${l.green(e.length)} extractions in ${l.green(r)} \xB5s [${l.green(this.css.rules.length)} rules in ${l.green($.join(this.options.output.dir,this.options.output.name))}]`),this.log("extractions",` \u2192 ${l.green(e.length)} extractions: ${l.blue(e.join(" "))}`),this.log("validClasses",` \u2192 ${l.green(i.length)} total valid classes: ${l.blue(i.join(" "))}`)}log(e,s){(this.options.debug===!0||Array.isArray(this.options.debug)&&this.options.debug.includes(e))&&console.log(s)}};import _ from"path";var k="MasterCSSWebpackPlugin",C=class extends p{apply(e){let{webpack:s}=e,{Template:r,RuntimeGlobals:i,RuntimeModule:n}=s,{RawSource:d}=s.sources,{Compilation:h}=s,{options:o}=this,a=_.join(o.output.dir||"",o.output.name),w=a.replace(/\\/g,"/");e.hooks.compilation.tap(k,c=>{c.hooks.finishModules.tap(k,u=>{let{modifiedFiles:f,watching:F}=e,M=[];for(let S of u){let m=S.resource,g=S._source?.source();F&&f?.size&&!f.has(m)||M.push(...this.extract({name:m,content:g}))}if(M.length){let S=this.css.text;this.insert(M);let m=this.css.text;if(m!==S){let g=new d(m);c.getAsset(a)?c.updateAsset(a,g):c.emitAsset(a,g)}}}),c.hooks.processAssets.tap({name:k,stage:h.PROCESS_ASSETS_STAGE_ADDITIONS},()=>{c.chunks.forEach(u=>{u.files.add(a)})})})}};import j from"path";import O from"fs";import H from"path";function x(t,e,s){let r=H.dirname(t);O.existsSync(r)||O.mkdirSync(r,{recursive:!0}),O.writeFileSync(t,e,s)}function z(t){let e=new p(t),s=j.join(e.options.output.dir||"",e.options.output.name),r,i,n,d=!1,h=(o,a)=>{let w=e.extract({name:o,content:a});if(w.length){let c=e.css.text;e.insert(w);let u=e.css.text;if(u!==c&&r){x(i,u);let f=()=>{r.ws.send({type:"update",updates:[{path:n,timestamp:Date.now()}]})};d?f():(setTimeout(f,500),d=!0)}}};return{name:"vite-plugin-master-css",enforce:"pre",configureServer(o){r=o},buildStart(){i=j.resolve(r?.config.cacheDir??process.cwd(),s),r&&(x(i,""),n=(r.config.cacheDir.slice(process.cwd().length)+"/"+s).replace(/\\/g,"/"))},resolveId(o){if(o.endsWith("master.css?direct"))return"\0"+o},transform(o,a){h(a,o)},transformIndexHtml(o){return o.replace(/(<head>)/,`$1<link rel="stylesheet" href="${n}">`)},async handleHotUpdate(o){h(o.file,await o.read())},generateBundle(){let o=this.emitFile({type:"asset",name:s,source:e.css.text});n="/"+this.getFileName(o)}}}export{p as MasterCSSCompiler,z as MasterCSSVitePlugin,C as MasterCSSWebpackPlugin};
2
- //# sourceMappingURL=index.mjs.map
1
+ import G from"upath";var pe={module:"master.css",config:"master.css.{ts,js,mjs,cjs}",sources:[],include:["**/*.{html,js,jsx,ts,tsx,svelte,astro,vue,md,mdx,pug,php}"],exclude:["**/node_modules/**","**/*.d.ts","**/*.test.*","node_modules","master.css.{js,ts,mjs,cjs}","dist","out","README.md","public"],classes:{fixed:[],ignored:[]}},S=pe;import ae from"@master/css";import{performance as ce}from"perf_hooks";import{semantics as he}from"@master/css";function A({content:r},{config:e,classes:t}){r=fe(r);let s=[...new Set(Object.keys(e.semantics??he).concat(Object.keys(t)))],n=r.match(/\S+/g)??[],i=new Set;for(let l of n){i.add(N(l,s));let a=U(l);if(a.size)for(let p of a)i.add(N(p,s))}return[...i].filter(l=>l&&!de(l,s))}var N=(r,e)=>{let t=r,s=r.match(/(?:calc\(.*\)|\d+(?:%|ch|cm|em|ex|in|mm|pc|pt|px|rem|vh|vmax|vmin|vw|deg|grad|rad|turn|s)?)x(?:calc\(.*\)|\d+(?:%|ch|cm|em|ex|in|mm|pc|pt|px|rem|vh|vmax|vmin|vw|deg|grad|rad|turn|s)?)/g);return(s?.length?e.concat(s):e).find(n=>t.startsWith(n))?r=j(r,n=>n.replace(/^[^:@~(]*(?<!@>?)=/,"").replace(/(?:[([{\\:#=.]+|["'`].*)$/,"")):r=j(r,n=>n.replace(/^[^:@~(]*(?:["'`]|(?<!@>?)=)/,"").replace(/(?:[([{\\:#=.]+|["'`].*)$/,"")),t===r||!r?r:N(r,e)},D=r=>r.match(/((?<!\\)["'`])(?:\\\1|(?:(?!\1))[\S\s])*(?<!\\)\1/g),W=(r,e)=>(e?.forEach((t,s)=>{r=r.replace(t,`COMPLETE-STRING--${s}--`)}),r),j=(r,e)=>{let t=D(r);return r=W(r,t),r=e(r),t?.forEach((s,n)=>{r=r.replace(`COMPLETE-STRING--${n}--`,s)}),r},U=r=>{let e=new Set,t=/((?<!\\)["'`])((?:\\\1|(?:(?!\1))[\S\s])*)((?<!\\)\1)/g,s;for(;(s=t.exec(r))!==null;){s.index===t.lastIndex&&t.lastIndex++,e.add(s[2]);let n=U(s[2]);if(n.size)for(let i of n)e.add(i)}return e},fe=r=>j(r,e=>e.replace(/\/\*(?:(?!\*\/)[\S\s])*\*\//g,"").replace(/<!--(?:(?!-->)[\S\s])*-->/g,"").replace(/<style[^>]*>(?:(?!<\/style>)[\S\s])*<\/style>/g,"").replace(/import.*from\s*COMPLETE-STRING--\d+--/g,"").replace(/import\s*(?:COMPLETE-STRING--\d+--|\([^;\s]*\))/g,"").replace(/require\([^;\s]*\)/g,"")),de=(r,e)=>{let t=D(r),s=W(r,t),n=/{(.*)}/,i;for(;(i=n.exec(s))!==null;)return i[1].split(";").find(a=>Y(a,e))!==void 0;return Y(s,e)||me(r)},Y=(r,e)=>!r||!r.match(/(?:\S*\{\S*\})|(?:^[\w\-()]+:\S+)|(?:^[\w-]+\(\S+\))|(?:^[@~]\S+$)/)&&!r.match(/^(?:calc\(.*\)|\d+(?:%|ch|cm|em|ex|in|mm|pc|pt|px|rem|vh|vmax|vmin|vw|deg|grad|rad|turn|s)?)x(?:calc\(.*\)|\d+(?:%|ch|cm|em|ex|in|mm|pc|pt|px|rem|vh|vmax|vmin|vw|deg|grad|rad|turn|s)?)$/)&&!e.find(t=>r.startsWith(t))||r.match(/\*\*/)||r.match(/:\[/)||r.match(/\$\{/)||r.match(/\{\{/)||r.match(/\(\{[^}]*\}/)||r.match(/<\w+>|<\/\w+>/)||r.match(/;$/)||r.match(/^\w+:\/\//)||r.match(/^@(?:ts-[^\s]+|charset|import|namespace|media|supports|document|page|font-face|keyframes|counter-style|font-feature-values|property|layer)$/)||r.match(/^~\/.+.\w+$/)||r.match(/function\(|\(.*\)=>/),me=r=>{let e=[],t;for(let s=0;s<r.length;s++)switch(r[s]){case"(":case"[":case"{":e.push(r[s]);break;case")":case"]":case"}":if(t=e.pop(),r[s]===")"&&t!=="("||r[s]==="]"&&t!=="["||r[s]==="}"&&t!=="{")return!0;break}return e.length>0};import er from"fs";import ue from"fast-glob";import L from"minimatch";import rr from"techor";import _ from"node:process";import je from"node:os";import J from"node:tty";var be=Object.create,ne=Object.defineProperty,ve=Object.getOwnPropertyDescriptor,ye=Object.getOwnPropertyNames,xe=Object.getPrototypeOf,$e=Object.prototype.hasOwnProperty,Oe=(r,e)=>()=>(e||r((e={exports:{}}).exports,e),e.exports),we=(r,e,t,s)=>{if(e&&typeof e=="object"||typeof e=="function")for(let n of ye(e))!$e.call(r,n)&&n!==t&&ne(r,n,{get:()=>e[n],enumerable:!(s=ve(e,n))||s.enumerable});return r},Te=(r,e,t)=>(t=r!=null?be(xe(r)):{},we(e||!r||!r.__esModule?ne(t,"default",{value:r,enumerable:!0}):t,r)),Ce=Oe((r,e)=>{"use strict";function t(s){var n=void 0;typeof s=="string"?n=[s]:n=s.raw;for(var i="",l=0;l<n.length;l++)i+=n[l].replace(/\\\n[ \t]*/g,"").replace(/\\`/g,"`"),l<(arguments.length<=1?0:arguments.length-1)&&(i+=arguments.length<=l+1?void 0:arguments[l+1]);var a=i.split(`
2
+ `),p=null;return a.forEach(function(u){var f=u.match(/^(\s+)\S+/);if(f){var y=f[1].length;p?p=Math.min(p,y):p=y}}),p!==null&&(i=a.map(function(u){return u[0]===" "?u.slice(p):u}).join(`
3
+ `)),i=i.trim(),i.replace(/\\n/g,`
4
+ `)}typeof e<"u"&&(e.exports=t)}),m=(r,e)=>{if(!r)throw new Error(e)},Re=r=>{let e={joined:!0,spacerNoNeighbour:" ",spacerNeighbour:"\u2502 ",keyNoNeighbour:"\u2514\u2500 ",keyNeighbour:"\u251C\u2500 ",separator:": ",renderFn:t=>["boolean","string","number"].includes(typeof t)?t:void 0,sortFn:null,breakCircularWith:" (circular ref.)",...r};return m(Object.keys(e).length===9,"Unexpected Option(s) provided"),m(typeof e.joined=="boolean",'Option "joined" has invalid format'),m(typeof e.spacerNoNeighbour=="string",'Option "spacerNoNeighbour" has invalid format'),m(typeof e.spacerNeighbour=="string",'Option "spacerNeighbour" has invalid format'),m(typeof e.keyNoNeighbour=="string",'Option "keyNoNeighbour" has invalid format'),m(typeof e.keyNeighbour=="string",'Option "keyNeighbour" has invalid format'),m(typeof e.separator=="string",'Option "separator" has invalid format'),m(typeof e.renderFn=="function",'Option "renderFn" has invalid format'),m(typeof e.sortFn=="function"||e.sortFn===null,'Option "sortFn" has invalid format'),m(typeof e.breakCircularWith=="string"||e.breakCircularWith===null,'Option "breakCircularWith" has invalid format'),e},ie=(r,e={})=>{let t=Re(e),s=[],n=t.renderFn(r);n!==void 0&&s.push(String(n));let i=u=>t.sortFn===null?u.reverse():u.sort((f,y)=>t.sortFn(y,f)),l=[],a=i(Object.keys(r)).map(u=>[u]),p=[r];for(;a.length!==0;){let u=a.pop(),f=p[u.length-1][u[u.length-1]],y=t.breakCircularWith!==null&&p.includes(f);l[u.length-1]=a.length!==0&&a[a.length-1].length===u.length;let ge=t.renderFn(f);s.push([l.slice(0,u.length-1).map(k=>k?t.spacerNeighbour:t.spacerNoNeighbour).join(""),l[u.length-1]?t.keyNeighbour:t.keyNoNeighbour,u[u.length-1],ge===void 0?"":`${t.separator}${f}`,y?t.breakCircularWith:""].join("")),f instanceof Object&&!Array.isArray(f)&&!y&&(a.push(...i(Object.keys(f)).map(k=>u.concat(k))),p[u.length]=f)}return t.joined===!0?s.join(`
5
+ `):s},V=(r=0)=>e=>`\x1B[${e+r}m`,H=(r=0)=>e=>`\x1B[${38+r};5;${e}m`,q=(r=0)=>(e,t,s)=>`\x1B[${38+r};2;${e};${t};${s}m`,c={modifier:{reset:[0,0],bold:[1,22],dim:[2,22],italic:[3,23],underline:[4,24],overline:[53,55],inverse:[7,27],hidden:[8,28],strikethrough:[9,29]},color:{black:[30,39],red:[31,39],green:[32,39],yellow:[33,39],blue:[34,39],magenta:[35,39],cyan:[36,39],white:[37,39],blackBright:[90,39],gray:[90,39],grey:[90,39],redBright:[91,39],greenBright:[92,39],yellowBright:[93,39],blueBright:[94,39],magentaBright:[95,39],cyanBright:[96,39],whiteBright:[97,39]},bgColor:{bgBlack:[40,49],bgRed:[41,49],bgGreen:[42,49],bgYellow:[43,49],bgBlue:[44,49],bgMagenta:[45,49],bgCyan:[46,49],bgWhite:[47,49],bgBlackBright:[100,49],bgGray:[100,49],bgGrey:[100,49],bgRedBright:[101,49],bgGreenBright:[102,49],bgYellowBright:[103,49],bgBlueBright:[104,49],bgMagentaBright:[105,49],bgCyanBright:[106,49],bgWhiteBright:[107,49]}},ar=Object.keys(c.modifier),Ee=Object.keys(c.color),ke=Object.keys(c.bgColor),cr=[...Ee,...ke];function Se(){let r=new Map;for(let[e,t]of Object.entries(c)){for(let[s,n]of Object.entries(t))c[s]={open:`\x1B[${n[0]}m`,close:`\x1B[${n[1]}m`},t[s]=c[s],r.set(n[0],n[1]);Object.defineProperty(c,e,{value:t,enumerable:!1})}return Object.defineProperty(c,"codes",{value:r,enumerable:!1}),c.color.close="\x1B[39m",c.bgColor.close="\x1B[49m",c.color.ansi=V(),c.color.ansi256=H(),c.color.ansi16m=q(),c.bgColor.ansi=V(10),c.bgColor.ansi256=H(10),c.bgColor.ansi16m=q(10),Object.defineProperties(c,{rgbToAnsi256:{value(e,t,s){return e===t&&t===s?e<8?16:e>248?231:Math.round((e-8)/247*24)+232:16+36*Math.round(e/255*5)+6*Math.round(t/255*5)+Math.round(s/255*5)},enumerable:!1},hexToRgb:{value(e){let t=/[a-f\d]{6}|[a-f\d]{3}/i.exec(e.toString(16));if(!t)return[0,0,0];let[s]=t;s.length===3&&(s=[...s].map(i=>i+i).join(""));let n=Number.parseInt(s,16);return[n>>16&255,n>>8&255,n&255]},enumerable:!1},hexToAnsi256:{value:e=>c.rgbToAnsi256(...c.hexToRgb(e)),enumerable:!1},ansi256ToAnsi:{value(e){if(e<8)return 30+e;if(e<16)return 90+(e-8);let t,s,n;if(e>=232)t=((e-232)*10+8)/255,s=t,n=t;else{e-=16;let a=e%36;t=Math.floor(e/36)/5,s=Math.floor(a/6)/5,n=a%6/5}let i=Math.max(t,s,n)*2;if(i===0)return 30;let l=30+(Math.round(n)<<2|Math.round(s)<<1|Math.round(t));return i===2&&(l+=60),l},enumerable:!1},rgbToAnsi:{value:(e,t,s)=>c.ansi256ToAnsi(c.rgbToAnsi256(e,t,s)),enumerable:!1},hexToAnsi:{value:e=>c.ansi256ToAnsi(c.hexToAnsi256(e)),enumerable:!1}}),c}var Ne=Se(),b=Ne;function d(r,e=globalThis.Deno?globalThis.Deno.args:_.argv){let t=r.startsWith("-")?"":r.length===1?"-":"--",s=e.indexOf(t+r),n=e.indexOf("--");return s!==-1&&(n===-1||s<n)}var{env:g}=_,C;d("no-color")||d("no-colors")||d("color=false")||d("color=never")?C=0:(d("color")||d("colors")||d("color=true")||d("color=always"))&&(C=1);function Ae(){if("FORCE_COLOR"in g)return g.FORCE_COLOR==="true"?1:g.FORCE_COLOR==="false"?0:g.FORCE_COLOR.length===0?1:Math.min(Number.parseInt(g.FORCE_COLOR,10),3)}function Be(r){return r===0?!1:{level:r,hasBasic:!0,has256:r>=2,has16m:r>=3}}function Me(r,{streamIsTTY:e,sniffFlags:t=!0}={}){let s=Ae();s!==void 0&&(C=s);let n=t?C:s;if(n===0)return 0;if(t){if(d("color=16m")||d("color=full")||d("color=truecolor"))return 3;if(d("color=256"))return 2}if("TF_BUILD"in g&&"AGENT_NAME"in g)return 1;if(r&&!e&&n===void 0)return 0;let i=n||0;if(g.TERM==="dumb")return i;if(_.platform==="win32"){let l=je.release().split(".");return Number(l[0])>=10&&Number(l[2])>=10586?Number(l[2])>=14931?3:2:1}if("CI"in g)return"GITHUB_ACTIONS"in g?3:["TRAVIS","CIRCLECI","APPVEYOR","GITLAB_CI","BUILDKITE","DRONE"].some(l=>l in g)||g.CI_NAME==="codeship"?1:i;if("TEAMCITY_VERSION"in g)return/^(9\.(0*[1-9]\d*)\.|\d{2,}\.)/.test(g.TEAMCITY_VERSION)?1:0;if(g.COLORTERM==="truecolor"||g.TERM==="xterm-kitty")return 3;if("TERM_PROGRAM"in g){let l=Number.parseInt((g.TERM_PROGRAM_VERSION||"").split(".")[0],10);switch(g.TERM_PROGRAM){case"iTerm.app":return l>=3?3:2;case"Apple_Terminal":return 2}}return/-256(color)?$/i.test(g.TERM)?2:/^screen|^xterm|^vt100|^vt220|^rxvt|color|ansi|cygwin|linux/i.test(g.TERM)||"COLORTERM"in g?1:i}function K(r,e={}){let t=Me(r,{streamIsTTY:r&&r.isTTY,...e});return Be(t)}var Pe={stdout:K({isTTY:J.isatty(1)}),stderr:K({isTTY:J.isatty(2)})},Ie=Pe;function Fe(r,e,t){let s=r.indexOf(e);if(s===-1)return r;let n=e.length,i=0,l="";do l+=r.slice(i,s)+e+t,i=s+n,s=r.indexOf(e,i);while(s!==-1);return l+=r.slice(i),l}function _e(r,e,t,s){let n=0,i="";do{let l=r[s-1]==="\r";i+=r.slice(n,l?s-1:s)+e+(l?`\r
6
+ `:`
7
+ `)+t,n=s+1,s=r.indexOf(`
8
+ `,n)}while(s!==-1);return i+=r.slice(n),i}var{stdout:z,stderr:Z}=Ie,P=Symbol("GENERATOR"),x=Symbol("STYLER"),w=Symbol("IS_EMPTY"),Q=["ansi","ansi","ansi256","ansi16m"],$=Object.create(null),Ge=(r,e={})=>{if(e.level&&!(Number.isInteger(e.level)&&e.level>=0&&e.level<=3))throw new Error("The `level` option should be an integer from 0 to 3");let t=z?z.level:0;r.level=e.level===void 0?t:e.level},Le=r=>{let e=(...t)=>t.join(" ");return Ge(e,r),Object.setPrototypeOf(e,T.prototype),e};function T(r){return Le(r)}Object.setPrototypeOf(T.prototype,Function.prototype);for(let[r,e]of Object.entries(b))$[r]={get(){let t=R(this,F(e.open,e.close,this[x]),this[w]);return Object.defineProperty(this,r,{value:t}),t}};$.visible={get(){let r=R(this,this[x],!0);return Object.defineProperty(this,"visible",{value:r}),r}};var I=(r,e,t,...s)=>r==="rgb"?e==="ansi16m"?b[t].ansi16m(...s):e==="ansi256"?b[t].ansi256(b.rgbToAnsi256(...s)):b[t].ansi(b.rgbToAnsi(...s)):r==="hex"?I("rgb",e,t,...b.hexToRgb(...s)):b[t][r](...s),Ye=["rgb","hex","ansi256"];for(let r of Ye){$[r]={get(){let{level:t}=this;return function(...s){let n=F(I(r,Q[t],"color",...s),b.color.close,this[x]);return R(this,n,this[w])}}};let e="bg"+r[0].toUpperCase()+r.slice(1);$[e]={get(){let{level:t}=this;return function(...s){let n=F(I(r,Q[t],"bgColor",...s),b.bgColor.close,this[x]);return R(this,n,this[w])}}}}var De=Object.defineProperties(()=>{},{...$,level:{enumerable:!0,get(){return this[P].level},set(r){this[P].level=r}}}),F=(r,e,t)=>{let s,n;return t===void 0?(s=r,n=e):(s=t.openAll+r,n=e+t.closeAll),{open:r,close:e,openAll:s,closeAll:n,parent:t}},R=(r,e,t)=>{let s=(...n)=>We(s,n.length===1?""+n[0]:n.join(" "));return Object.setPrototypeOf(s,De),s[P]=r,s[x]=e,s[w]=t,s},We=(r,e)=>{if(r.level<=0||!e)return r[w]?"":e;let t=r[x];if(t===void 0)return e;let{openAll:s,closeAll:n}=t;if(e.includes("\x1B"))for(;t!==void 0;)e=Fe(e,t.close,t.open),t=t.parent;let i=e.indexOf(`
9
+ `);return i!==-1&&(e=_e(e,n,s,i)),s+e+n};Object.defineProperties(T.prototype,$);var Ue=T(),hr=T({level:Z?Z.level:0}),o=Ue;function v(r){return r.split(" ").map(e=>e.replace(/^(\d*\.?\d*)$/g,`${o.blue("$1")}`).replace(/^(\d*\.?\d*)(YB|ZB|EB|PB|TB|GB|MB|KB|B|mb|kb|bit|zs|as|fs|ps|ns|µs|ms|s|m|h|d|m|y)$/g,`${o.cyan("$1")}${o.magenta("$2")}`).replace(/^((?:[0-1]?[0-9]|[2][0-3]):[0-5][0-9]:[0-5][0-9] (?:AM|PM)?)$/g,`${o.dim("$1")}`).replace(/^\[(.*?)\]$/g,`${o.dim("[")}${o.magenta("$1")}${o.dim("]")}`).replace(/^`(.*?)`$/g,`${o.dim("`")}$1${o.dim("`")}`).replace(/^\((.*?)\)$/g,`${o.dim("(")}$1${o.dim(")")}`).replace(/^<(.*?)>$/g,`${o.dim("<")}${o.gray("$1")}${o.dim(">")}`).replace(/->/g,o.dim("\u2192")).replace(/<-/g,o.dim("\u2190")).replace(/^\$t$/g,`${o.dim(new Date().toLocaleTimeString())}`).replace(/^\*\*(.*?)\*\*$/g,`${o.bold.white("$1")}`).replace(/^~~(.*?)~~$/g,`${o.strikethrough("$1")}`).replace(/^__(.*?)__$/g,`${o.underline("$1")}`).replace(/^\.\.(.*?)\.\.$/g,`${o.dim("$1")}`).replace(/^!!(.*?)!!$/g,`${o.yellow("$1")}`).replace(/^\*(.*?)\*$/g,`${o.italic("$1")}`).replace(/^_(.*?)_$/g,`${o.italic("$1")}`).replace(/^\+(.*?)\+$/g,`${o.green("$1")}`).replace(/^-(.*?)-$/g,`${o.red("$1")}`)).join(" ")}function h(r,e){let t="";if(Array.isArray(r))for(let s=0;s<r.length;s++)t+=B(r[s])+B(e[s]);else t=[r,...e].map(s=>B(s)).join(" ");return v(t)}var B=r=>r?Array.isArray(r)?r.map(e=>{switch(typeof e){case"string":return`'${o.yellow(e)}'`;case"number":case"boolean":return o.blue(e);default:return e}}).join(o.gray(", ")):r:"",X=(r,...e)=>{let t=o.green("+")+" "+h(r,e);return console.log(t),t},ee=(r,...e)=>{let t=o.bgRed.bold.white(" \u{1D5EB} ERROR ")+" "+h(r,e);return console.log(t),t},Ve=(r,...e)=>{let t=o.bgYellow.bold.white(" \u26A0\uFE0F CONFLICT ")+" "+o.yellow(h(r,e));return console.log(t),t},He=(r,...e)=>{let t=o.green("\u2713 ")+h(r,e);return console.log(t),t},M=(r,...e)=>{let t=o.red("-")+" "+h(r,e);return console.log(t),t},re=(r,...e)=>{let t=o.green("\u25CB ")+h(r,e);return console.log(t),t},te=(r,...e)=>{let t=o.red("\u2717 ")+h(r,e);return console.log(t),t},se=(r,...e)=>{let t=v("$t ")+h(r,e);return console.log(t),t},qe=(r,...e)=>{let t=o.green("\u23FA Success ")+h(r,e);return console.log(t),t},Je=(r,...e)=>{let t=o.yellow("\u23FA Warn ")+h(r,e);return console.log(t),t},Ke=(r,...e)=>{let t=o.bgGreen.bold.white(" \u2713 PASS ")+" "+h(r,e);return console.log(t),t},ze=r=>{console.log(ie(oe(JSON.parse(JSON.stringify(r))),{spacerNeighbour:v("..\u2502..")+" ",keyNoNeighbour:v("..\u2514\u2500..")+" ",keyNeighbour:v("..\u251C\u2500..")+" ",separator:v("..:..")+" "}))};function oe(r){for(let e in r){let t=r[e];Array.isArray(t)?r[e]=t.map(s=>v(`**${s}**`)).join(v("..,..")):typeof t=="object"?oe(t):r[e]=v(`**${t}**`)}return r}var Ze=(r,...e)=>{let t=o.red("\u23FA Fail ")+h(r,e);return console.log(t),t},Qe=Te(Ce());function Xe(r){let{message:e,stack:t}=typeof r=="string"?new Error(r):r,s={};return(0,Qe.default)(t.replace(e,"").replace(/^Error: /,"")).split(`
10
+ `).forEach(n=>{s[n.split(" ").map(i=>i.replace(/^\((.+)\)$/,`${o.cyan("$1")}`).replace(/\./g,`${o.dim(".")}`).replace(/^at$/,l=>o.dim(l))).join(" ")]=null}),{message:e.trim().replace(/Error: /g,""),stackTree:s}}var le=(r,...e)=>{if(r instanceof Error){let{message:t,stackTree:s}=Xe(r);return console.log(""),console.log(o.bgRed.bold.white(" \u{1D5EB} ERROR ")+" "+o.bold.red(t)),console.log(ie(s,{spacerNeighbour:o.redBright.dim("\u2502\u2000\u2000"),keyNoNeighbour:o.redBright.dim("\u2514\u2500\u2000"),keyNeighbour:o.redBright.dim("\u251C\u2500 "),separator:o.redBright.dim(":\u2000")})),console.log(""),t}else{let t=h(r,e);return console.log(t),t}};Object.assign(le,{a:X,add:X,d:M,del:M,delete:M,o:re,valid:re,x:te,invalid:te,i:se,info:se,e:ee,error:ee,success:qe,fail:Ze,warn:Je,pass:Ke,conflict:Ve,ok:He,tree:ze,paint:v});var O=le;import tr from"stylelint";import sr from"to-extend";var E=class extends rr{css;extractions=new Set;get resolvedModuleId(){return"\0"+this.options.module}get moduleHMREvent(){return`HMR:${this.options.module}`}constructor(e){super(S,e);let t=this.readConfig(null);this.options=sr(this.options,t?.compilerOptions,e),console.log(""),this.css=t?.css??new ae(t?.config)}async refresh(){return this.extractions.clear(),console.log(""),this.css=new ae(this.readConfig()),await this.compile(),this}async compile(){if(this.options.classes?.fixed?.length)for(let e of this.options.classes.fixed)this.css.insert(e);return await Promise.all(this.sources.map(async e=>{let t=er.readFileSync(G.resolve(this.options.cwd,e),{encoding:"utf-8"}).toString();await this.insert(e,t)})),this}extract(e,t){if(!e||!t||!this.checkSourcePath(e))return[];let s=[];for(let n of A({content:t,name:e},this.css))this.extractions.has(n)||(this.extractions.add(n),s.push(n));return s}async insert(e,t){let s=this.extract(e,t);if(!s.length)return!1;let n=ce.now(),i=[];await Promise.all(s.map(async a=>{let p=await this.createRules(a);p.length&&(this.css.insertRules(p),i.push(a))}));let l=Math.round((ce.now()-n)*100)/100;if(s.length&&(console.log(""),O`**${G.relative(this.options.cwd,e)}** ..${G.resolve(this.options.cwd,e)}..`,O`[extract] ${s.length} potential`),this.css.rules.length){let a=i.filter(p=>!s.includes(p));a.length&&O`[exclude] ${a.length} unknow ${a}`,O`[compile] +${i.length}+ valid inserted ${o.gray("in")} ${l}ms ${i}`,O`[virtual] ${this.css.rules.length} total ${o.gray("in")} ${this.options.module}`}return this.options.classes?.ignored?.length&&(s=s.filter(a=>{for(let p of this.options.classes.ignored)if(typeof p=="string"){if(p===a)return!1}else if(p.test(a))return!1;return!0})),!0}async createRules(e){return(await Promise.all(this.css.create(e).map(async t=>(await tr.lint({code:t.text,cache:!1,config:{rules:{"color-no-invalid-hex":!0,"named-grid-areas-no-invalid":!0,"at-rule-no-unknown":!0,"function-no-unknown":!0,"media-feature-name-no-unknown":!0,"property-no-unknown":!0,"selector-pseudo-class-no-unknown":!0,"selector-pseudo-element-no-unknown":!0,"selector-type-no-unknown":!0,"unit-no-unknown":!0}}})).errored?null:t))).filter(t=>t)}get sources(){let{include:e,exclude:t,sources:s}=this.options,n=ue.sync(e,{cwd:this.options.cwd,ignore:t});return s?.length&&n.push(...ue.sync(s,{cwd:this.options.cwd})),n}checkSourcePath(e){let{include:t,exclude:s,sources:n}=this.options;for(let i of n)if(L(e,i))return!0;for(let i of t)if(!L(e,i))return!1;for(let i of s)if(L(e,i))return!1;return!0}get config(){return this.css.config}};export{E as default,S as options};
@@ -1,16 +1,20 @@
1
- declare const defaultOptions: MasterCSSCompilerOptions;
2
- export declare type MasterCSSCompilerSource = {
1
+ import { Config } from '@master/css';
2
+ import type { Pattern as FastGlobPattern } from 'fast-glob';
3
+ import type { Options as TechorOptions } from 'techor';
4
+ declare const options: Options;
5
+ export declare type Source = {
3
6
  name: string;
4
7
  content: string;
5
8
  };
6
- export interface MasterCSSCompilerOptions {
7
- output?: {
8
- name: string;
9
- dir: string;
9
+ export interface Options extends TechorOptions<Config> {
10
+ output?: string;
11
+ module?: string;
12
+ sources?: FastGlobPattern[];
13
+ include?: FastGlobPattern[];
14
+ exclude?: FastGlobPattern[];
15
+ classes?: {
16
+ fixed?: string[];
17
+ ignored?: string[] | RegExp[];
10
18
  };
11
- accept?: (source: MasterCSSCompilerSource) => boolean;
12
- extract?: (source: MasterCSSCompilerSource) => string[];
13
- config?: string;
14
- debug?: string[] | boolean;
15
19
  }
16
- export default defaultOptions;
20
+ export default options;
package/package.json CHANGED
@@ -1,145 +1 @@
1
- {
2
- "name": "@master/css-compiler",
3
- "license": "MIT",
4
- "description": "Compile Master CSS ahead of time with zero-configuration integration with build tools",
5
- "author": "Aoyue Design LLC.",
6
- "funding": "https://docs.master.co/css/donate",
7
- "homepage": "https://css.master.co",
8
- "repository": {
9
- "type": "git",
10
- "url": "https://github.com/master-co/css-compiler.git"
11
- },
12
- "keywords": [
13
- "webpack",
14
- "plugin",
15
- "integration",
16
- "vite",
17
- "parcel",
18
- "build tools",
19
- "css",
20
- "mastercss",
21
- "vite-plugin"
22
- ],
23
- "sideEffects": false,
24
- "scripts": {
25
- "build:cjs": "esbuild src/index.ts --bundle --outfile=dist/index.cjs --format=cjs --platform=node --external:@master/css --external:chalk",
26
- "build:esm": "esbuild src/index.ts --bundle --outfile=dist/index.mjs --format=esm --platform=node --external:@master/css --external:chalk",
27
- "dev:cjs": "npm run build:cjs -- --watch",
28
- "dev:esm": "npm run build:esm -- --watch",
29
- "prod": "rm -rf dist && npm run build:cjs -- --minify --sourcemap && npm run build:esm -- --minify --sourcemap && tsc --emitDeclarationOnly",
30
- "test": "jest",
31
- "lint": "eslint ./src"
32
- },
33
- "main": "./dist/index.cjs",
34
- "jsnext:main": "./dist/index.mjs",
35
- "browser": "./dist/index.browser.js",
36
- "esnext": "./dist/index.mjs",
37
- "module": "./dist/index.mjs",
38
- "types": "./dist/index.d.ts",
39
- "exports": {
40
- ".": {
41
- "require": "./dist/index.cjs",
42
- "import": "./dist/index.mjs",
43
- "types": "./dist/index.d.ts"
44
- }
45
- },
46
- "jest": {
47
- "testEnvironment": "node",
48
- "transform": {
49
- "^.+\\.(t|j)sx?$": "@swc/jest"
50
- },
51
- "testMatch": [
52
- "<rootDir>/tests/*.ts",
53
- "<rootDir>/src/**/*.test.ts"
54
- ]
55
- },
56
- "private": false,
57
- "publishConfig": {
58
- "access": "public"
59
- },
60
- "engines": {
61
- "node": ">=14"
62
- },
63
- "release": {
64
- "plugins": [
65
- [
66
- "@semantic-release/commit-analyzer",
67
- {
68
- "preset": "angular",
69
- "releaseRules": [
70
- {
71
- "type": "docs",
72
- "scope": "README",
73
- "release": "patch"
74
- },
75
- {
76
- "type": "refactor",
77
- "release": "patch"
78
- },
79
- {
80
- "type": "style",
81
- "release": "patch"
82
- }
83
- ],
84
- "parserOpts": {
85
- "noteKeywords": [
86
- "BREAKING CHANGE",
87
- "BREAKING CHANGES"
88
- ]
89
- }
90
- }
91
- ],
92
- "@semantic-release/release-notes-generator",
93
- [
94
- "@semantic-release/exec",
95
- {
96
- "prepareCmd": "npm run prod"
97
- }
98
- ],
99
- [
100
- "@semantic-release/github"
101
- ],
102
- [
103
- "@semantic-release/npm"
104
- ]
105
- ],
106
- "branches": [
107
- "+([0-9])?(.{+([0-9]),x}).x",
108
- "main",
109
- "next",
110
- "next-major",
111
- {
112
- "name": "beta",
113
- "prerelease": true
114
- },
115
- {
116
- "name": "alpha",
117
- "prerelease": true
118
- }
119
- ]
120
- },
121
- "files": [
122
- "dist"
123
- ],
124
- "devDependencies": {
125
- "@semantic-release/exec": "^6.0.3",
126
- "@swc/core": "^1.3.9",
127
- "@swc/jest": "^0.2.23",
128
- "@types/jest": "^29.2.0",
129
- "@types/node": "^18.11.0",
130
- "@types/webpack": "^5.28.0",
131
- "@typescript-eslint/eslint-plugin": "^5.40.1",
132
- "@typescript-eslint/parser": "^5.40.1",
133
- "esbuild": "^0.15.10",
134
- "eslint": "^8.25.0",
135
- "jest": "^29.2.2",
136
- "semantic-release": "^19.0.5",
137
- "typescript": "^4.8.4",
138
- "vite": "^3.1.8"
139
- },
140
- "peerDependencies": {
141
- "@master/css": "^2.0.0-beta.11",
142
- "chalk": "^4.0.0"
143
- },
144
- "version": "2.0.0-beta.11"
145
- }
1
+ {"name":"@master/css-compiler","scripts":{"build":"aron pack --platform=node","dev":"npm run build -- --watch","lint":"eslint ./src","test":"jest"},"license":"MIT","description":"The ahead-of-time compiler of Master CSS","author":"Aoyue Design LLC.","funding":"https://docs.master.co/css/donate","homepage":"https://css.master.co","bugs":{"url":"https://github.com/master-co/css/issues"},"repository":{"type":"git","url":"https://github.com/master-co/css.git","directory":"packages/compiler"},"keywords":["webpack","plugin","integration","vite","parcel","build tools","css","mastercss","vite-plugin"],"sideEffects":false,"main":"./dist/index.cjs","jsnext:main":"./dist/index.mjs","esnext":"./dist/index.mjs","module":"./dist/index.mjs","types":"./dist/index.d.ts","exports":{".":{"require":"./dist/index.cjs","import":"./dist/index.mjs","types":"./dist/index.d.ts"}},"files":["dist"],"publishConfig":{"access":"public"},"dependencies":{"@master/css":"^2.0.0-beta.110","fast-glob":"^3.2.12","minimatch":"^5.1.1","stylelint":"^14.16.0","techor":"^1.0.9","to-extend":"^1.5.0","upath":"^2.0.1"},"version":"2.0.0-beta.110"}
package/LICENSE DELETED
@@ -1,21 +0,0 @@
1
- The MIT License
2
-
3
- Copyright (c) Aoyue Design LLC.
4
-
5
- Permission is hereby granted, free of charge, to any person obtaining a copy
6
- of this software and associated documentation files (the "Software"), to deal
7
- in the Software without restriction, including without limitation the rights
8
- to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
- copies of the Software, and to permit persons to whom the Software is
10
- furnished to do so, subject to the following conditions:
11
-
12
- The above copyright notice and this permission notice shall be included in
13
- all copies or substantial portions of the Software.
14
-
15
- THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
- IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
- FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
- AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
- LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
- OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21
- THE SOFTWARE.
@@ -1,7 +0,0 @@
1
- {
2
- "version": 3,
3
- "sources": ["../src/index.ts", "../src/compiler.ts", "../src/options/extract.ts", "../src/options/index.ts", "../src/webpack.ts", "../src/vite.ts", "../src/utils/write-file.ts"],
4
- "sourcesContent": ["\nexport { default as MasterCSSCompiler } from './compiler'\nexport { default as MasterCSSWebpackPlugin } from './webpack'\nexport { default as MasterCSSVitePlugin } from './vite'\n", "import path from 'path'\nimport chalk from 'chalk'\nimport defaultOptions, { MasterCSSCompilerOptions, MasterCSSCompilerSource } from './options'\nimport MasterCSS, { extend } from '@master/css'\nimport { performance } from 'perf_hooks'\nimport type { MasterCSSConfig } from '@master/css'\n\nexport default class MasterCSSCompiler {\n\n constructor(\n public options?: MasterCSSCompilerOptions\n ) {\n this.options = extend(defaultOptions, options)\n let userConfig: MasterCSSConfig\n try {\n userConfig = require(path.resolve(process.cwd(), options.config || './master.css.js'))\n // eslint-disable-next-line no-empty\n } catch (err) { }\n this.css = new MasterCSS(userConfig)\n }\n\n css: MasterCSS\n extractions = new Set<string>()\n\n extract({ name, content }: MasterCSSCompilerSource) {\n if (\n !name || !content\n || !this.options.accept?.({ content, name })\n ) {\n return []\n }\n const eachExtractions: string[] = []\n\n this.log('accepts', ` \u2192 ${path.relative(process.cwd(), name)}`)\n\n for (const eachNewExtraction of this.options.extract({ content, name })) {\n if (this.extractions.has(eachNewExtraction)) {\n continue\n } else {\n this.extractions.add(eachNewExtraction)\n eachExtractions.push(eachNewExtraction)\n }\n }\n return eachExtractions\n }\n\n insert(extractions) {\n const p1 = performance.now()\n\n /* \u6839\u64DA\u985E\u540D\u5C0B\u627E\u4E26\u63D2\u5165\u898F\u5247 ( MasterCSS \u672C\u8EAB\u5E36\u6709\u5FEB\u53D6\u6A5F\u5236\uFF0C\u91CD\u8907\u7684\u985E\u540D\u4E0D\u6703\u518D\u7DE8\u8B6F\u53CA\u7522\u751F ) */\n for (const eachExtraction of extractions) {\n this.css.findAndInsert(eachExtraction)\n }\n\n const spent = Math.round((performance.now() - p1) * 1000)\n const validClasses = this.css.rules.map((rule) => rule.className)\n\n /* \u5370\u51FA Master CSS \u7DE8\u8B6F\u6642\u9593 */\n console.log(`[Master CSS] process ${chalk.green(extractions.length)} extractions in ${chalk.green(spent)} \u00B5s [${chalk.green(this.css.rules.length)} rules in ${chalk.green(path.join(this.options.output.dir, this.options.output.name))}]`)\n\n this.log('extractions', ` \u2192 ${chalk.green(extractions.length)} extractions: ${chalk.blue(extractions.join(' '))}`)\n this.log('validClasses', ` \u2192 ${chalk.green(validClasses.length)} total valid classes: ${chalk.blue(validClasses.join(' '))}`)\n }\n\n log(name, content) {\n if (this.options.debug === true || Array.isArray(this.options.debug) && this.options.debug.includes(name)) {\n console.log(content)\n }\n }\n}", "import { defaultSemantics } from '@master/css'\nimport type { MasterCSSCompilerSource } from './index'\n\nexport default function extract({ content }: MasterCSSCompilerSource) {\n const blocks = content.match(/[^\\s]+/g) ?? []\n const strings = new Set<string>()\n for (const block of blocks) {\n const result = peelString(block)\n if (result.size) {\n for (const string of result) {\n strings.add(string)\n }\n } else {\n strings.add(trimString(block))\n }\n }\n return [...strings].filter(x => x && !checkToExclude(x))\n}\n\nconst trimString = (content) => {\n const originContent = content\n content = content.replace(/^([\\w={[(\\\\]*[\"'`])/, '')\n if (!content.match(/^content:((?<!\\\\)[\"'`])((?:\\\\\\1|(?:(?!\\1))[\\S\\s])*)((?<!\\\\)\\1)$/)) {\n content = content.replace(/(\\.*|[([{\\\\:#]*|[\"'`].*)$/, '')\n }\n if (originContent === content) {\n return content\n } else {\n return trimString(content)\n }\n}\n\nconst peelString = (content) => {\n const strings = new Set<string>()\n const stringRegx = /((?<!\\\\)[\"'`])((?:\\\\\\1|(?:(?!\\1))[\\S\\s])*)((?<!\\\\)\\1)/g\n let m\n while ((m = stringRegx.exec(content)) !== null) {\n if (m.index === stringRegx.lastIndex) {\n stringRegx.lastIndex++\n }\n const result = peelString(m[2])\n if (result.size) {\n for (const string of result) {\n strings.add(string)\n }\n } else {\n strings.add(trimString(m[2]))\n }\n }\n return strings\n}\n\nconst checkToExclude = (content) => {\n return !content\n || (!content.match(/(?:^[\\w-]+:[\\w$#]+)|(?:^[@~][\\w-]+$)/) && !Object.keys(defaultSemantics).includes(content))\n || content.match(/\\*\\*/)\n || content.match(/:\\[/)\n || content.match(/\\$\\{/)\n || content.match(/\\{\\{/)\n || content.match(/\\(\\{[^}]*\\}/)\n || content.match(/<\\w+>|<\\/\\w+>/)\n}", "import extract from './extract'\n\nconst defaultOptions: MasterCSSCompilerOptions = {\n output: {\n name: 'master.css',\n dir: ''\n },\n accept({ name }) {\n if (name.match(/[\\\\/]node_modules[\\\\/]/)) {\n return false\n }\n if (name.match(/\\.(html|js|jsx|ts|tsx|svelte|astro|vue)$/i)) {\n return true\n }\n },\n extract\n}\n\nexport declare type MasterCSSCompilerSource = {\n name: string\n content: string\n}\n\nexport interface MasterCSSCompilerOptions {\n output?: {\n name: string\n dir: string\n },\n accept?: (source: MasterCSSCompilerSource) => boolean\n extract?: (source: MasterCSSCompilerSource) => string[]\n config?: string\n debug?: string[] | boolean\n}\n\nexport default defaultOptions", "import path from 'path'\nimport MasterCSSCompiler from './compiler'\nimport type { Compiler } from 'webpack'\n\nconst NAME = 'MasterCSSWebpackPlugin'\n\nexport default class MasterCSSWebpackPlugin extends MasterCSSCompiler {\n\n apply(compiler: Compiler) {\n const { webpack } = compiler\n const { Template, RuntimeGlobals, RuntimeModule } = webpack\n const { RawSource } = webpack.sources\n const { Compilation } = webpack\n const { options } = this\n const outputPath = path.join(options.output.dir || '', options.output.name)\n const linkHref = outputPath.replace(/\\\\/g, '/')\n\n // compiler.hooks.thisCompilation.tap(NAME, (compilation) => {\n\n // const enabledChunks = new WeakSet()\n\n // const handler = (chunk, set) => {\n // if (enabledChunks.has(chunk))\n // return\n\n // enabledChunks.add(chunk)\n\n // set.add(RuntimeGlobals.publicPath)\n\n // compilation.addRuntimeModule(chunk, new CssLoadingRuntimeModule(set))\n // }\n\n // compilation.hooks.runtimeRequirementInTree\n // .for(RuntimeGlobals.ensureChunkHandlers)\n // .tap(NAME, handler)\n // compilation.hooks.runtimeRequirementInTree\n // .for(RuntimeGlobals.hmrDownloadUpdateHandlers)\n // .tap(NAME, handler)\n\n // class CssLoadingRuntimeModule extends RuntimeModule {\n\n // runtimeRequirements: Set<string>\n\n // constructor(runtimeRequirements: Set<string>) {\n // super('master-css-loading', 10)\n\n // this.runtimeRequirements = runtimeRequirements\n // }\n\n // generate() {\n // const { runtimeRequirements } = this\n // const withHmr = runtimeRequirements.has(RuntimeGlobals.hmrDownloadUpdateHandlers)\n // if (!withHmr)\n // return ''\n\n // return Template.asString([\n // Date.now().toString(),\n // `const link = document.querySelector('[href*=\\\\'${linkHref}\\\\'][rel=stylesheet]')`,\n // 'if (link) {',\n // Template.indent([\n // 'link.href = link.href.replace(/ts=[0-9]+/, \\'ts=\\' + Date.now())'\n // ]),\n // '}'\n // ])\n // }\n // }\n // })\n\n compiler.hooks.compilation.tap(NAME, (compilation) => {\n // \u589E\u52A0\u984D\u5916\u7684 `master.css` assets\n compilation.hooks.finishModules.tap(NAME, (modules) => {\n const { modifiedFiles, watching } = compiler\n const eachExtractions: string[] = []\n\n for (const eachModule of modules) {\n const name = eachModule['resource']\n // \u5F9E\u8A18\u61B6\u9AD4\u6216\u5FEB\u53D6\u53D6\u5F97\u7576\u524D module \u7684\u539F\u59CB\u78BC\n const content = eachModule['_source']?.source()\n // \u5728 watch \u6A21\u5F0F\u4E0B\u50C5\u8655\u7406\u7576\u4E0B\u8B8A\u66F4\u7684\u6A94\u6848\n if (watching && modifiedFiles?.size && !modifiedFiles.has(name)) { continue }\n eachExtractions.push(...this.extract({ name, content }))\n }\n\n if (eachExtractions.length) {\n const originalCssText = this.css.text\n /* \u6BD4\u5C0D\u63D0\u53D6\u7269\u4E26\u63D2\u5165 CSS \u898F\u5247 */\n this.insert(eachExtractions)\n /* \u6839\u64DA cssText \u751F\u6210 `master.css` \u4E26\u52A0\u5165\u5230 Webpack \u7684 assets \u4E2D */\n const cssText = this.css.text\n if (cssText !== originalCssText) {\n const newSource = new RawSource(cssText)\n if (compilation.getAsset(outputPath)) {\n compilation.updateAsset(outputPath, newSource)\n } else {\n compilation.emitAsset(outputPath, newSource)\n }\n }\n }\n })\n\n compilation.hooks.processAssets.tap({\n name: NAME,\n stage: Compilation.PROCESS_ASSETS_STAGE_ADDITIONS,\n }, () => {\n compilation.chunks.forEach((chunk) => {\n chunk.files.add(outputPath)\n })\n })\n })\n }\n}\n", "import MasterCSSCompiler from './compiler'\nimport path from 'path'\nimport writeFile from './utils/write-file'\nimport type { MasterCSSCompilerOptions } from './options'\nimport type { PluginOption } from 'vite'\n\nexport default function (options?: MasterCSSCompilerOptions): PluginOption {\n const compiler = new MasterCSSCompiler(options)\n const outputPath = path.join(compiler.options.output.dir || '', compiler.options.output.name)\n\n let server\n let outputFilePath: string\n let linkHref: string\n let rendered = false\n\n const extract = (name, content) => {\n const eachExtractions = compiler.extract({ name, content })\n if (eachExtractions.length) {\n const originalCssText = compiler.css.text\n /* \u6BD4\u5C0D\u63D0\u53D6\u7269\u4E26\u63D2\u5165 CSS \u898F\u5247 */\n compiler.insert(eachExtractions)\n /* \u6839\u64DA cssText \u751F\u6210 `master.css` \u4E26\u52A0\u5165\u5230 Webpack \u7684 assets \u4E2D */\n const cssText = compiler.css.text\n if (cssText !== originalCssText) {\n if (server) {\n writeFile(outputFilePath, cssText)\n\n const notify = () => {\n server.ws.send({\n type: 'update',\n updates: [{\n path: linkHref,\n timestamp: Date.now()\n }]\n })\n }\n\n if (rendered) {\n notify()\n } else {\n setTimeout(notify, 500)\n\n rendered = true\n }\n }\n }\n }\n }\n\n return {\n name: 'vite-plugin-master-css',\n enforce: 'pre',\n configureServer(_server) {\n server = _server\n },\n buildStart() {\n outputFilePath = path.resolve(server?.config.cacheDir ?? process.cwd(), outputPath)\n if (server) {\n writeFile(outputFilePath, '')\n\n linkHref = (server.config.cacheDir.slice(process.cwd().length) + '/' + outputPath).replace(/\\\\/g, '/')\n }\n },\n resolveId(source) {\n if (source.endsWith('master.css?direct'))\n return '\\0' + source\n },\n transform(code, id) {\n extract(id, code)\n },\n transformIndexHtml(html) {\n return html.replace(\n /(<head>)/,\n `$1<link rel=\"stylesheet\" href=\"${linkHref}\">`\n )\n },\n async handleHotUpdate(hmrContext) {\n extract(hmrContext.file, await hmrContext.read())\n },\n generateBundle() {\n const referenceId = this.emitFile({\n type: 'asset',\n name: outputPath,\n source: compiler.css.text\n })\n linkHref = '/' + this.getFileName(referenceId)\n }\n } as PluginOption\n}", "import fs from 'fs'\nimport path from 'path'\n\nexport default function writeFile(filePath: string, data: string | NodeJS.ArrayBufferView, options?: fs.WriteFileOptions) {\n const dirname = path.dirname(filePath)\n if (!fs.existsSync(dirname)) {\n fs.mkdirSync(dirname, { recursive: true })\n }\n fs.writeFileSync(filePath, data, options)\n\n}\n"],
5
- "mappings": "6iBAAA,IAAAA,EAAA,GAAAC,EAAAD,EAAA,uBAAAE,EAAA,wBAAAC,EAAA,2BAAAC,IAAA,eAAAC,EAAAL,GCAA,IAAAM,EAAiB,mBACjBC,EAAkB,oBCDlB,IAAAC,EAAiC,uBAGlB,SAARC,EAAyB,CAAE,QAAAC,CAAQ,EAA4B,CAClE,IAAMC,EAASD,EAAQ,MAAM,SAAS,GAAK,CAAC,EACtCE,EAAU,IAAI,IACpB,QAAWC,KAASF,EAAQ,CACxB,IAAMG,EAASC,EAAWF,CAAK,EAC/B,GAAIC,EAAO,KACP,QAAWE,KAAUF,EACjBF,EAAQ,IAAII,CAAM,OAGtBJ,EAAQ,IAAIK,EAAWJ,CAAK,CAAC,CAErC,CACA,MAAO,CAAC,GAAGD,CAAO,EAAE,OAAOM,GAAKA,GAAK,CAACC,EAAeD,CAAC,CAAC,CAC3D,CAEA,IAAMD,EAAcP,GAAY,CAC5B,IAAMU,EAAgBV,EAKtB,OAJAA,EAAUA,EAAQ,QAAQ,sBAAuB,EAAE,EAC9CA,EAAQ,MAAM,iEAAiE,IAChFA,EAAUA,EAAQ,QAAQ,4BAA6B,EAAE,GAEzDU,IAAkBV,EACXA,EAEAO,EAAWP,CAAO,CAEjC,EAEMK,EAAcL,GAAY,CAC5B,IAAME,EAAU,IAAI,I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C,GAAQ,OAAO,UAAY,QAAQ,IAAI,EAAGF,CAAU,EAC9EE,IACAU,EAAUT,EAAgB,EAAE,EAE5BC,GAAYF,EAAO,OAAO,SAAS,MAAM,QAAQ,IAAI,EAAE,MAAM,EAAI,IAAMF,GAAY,QAAQ,MAAO,GAAG,EAE7G,EACA,UAAUe,EAAQ,CACd,GAAIA,EAAO,SAAS,mBAAmB,EACnC,MAAO,KAAOA,CACtB,EACA,UAAUC,EAAMC,EAAI,CAChBX,EAAQW,EAAID,CAAI,CACpB,EACA,mBAAmBE,EAAM,CACrB,OAAOA,EAAK,QACR,WACA,kCAAkCd,KACtC,CACJ,EACA,MAAM,gBAAgBe,EAAY,CAC9Bb,EAAQa,EAAW,KAAM,MAAMA,EAAW,KAAK,CAAC,CACpD,EACA,gBAAiB,CACb,IAAMC,EAAc,KAAK,SAAS,CAC9B,KAAM,QACN,KAAMpB,EACN,OAAQF,EAAS,IAAI,IACzB,CAAC,EACDM,EAAW,IAAM,KAAK,YAAYgB,CAAW,CACjD,CACJ,CACJ",
6
- "names": ["src_exports", "__export", "MasterCSSCompiler", "vite_default", "MasterCSSWebpackPlugin", "__toCommonJS", "import_path", "import_chalk", "import_css", "extract", "content", "blocks", "strings", "block", "result", "peelString", "string", "trimString", "x", "checkToExclude", "originContent", "stringRegx", "m", "defaultOptions", "name", "extract", "options_default", "import_css", "import_perf_hooks", "MasterCSSCompiler", "options", "options_default", "userConfig", "path", "MasterCSS", "name", "content", "eachExtractions", "eachNewExtraction", "extractions", "p1", "eachExtraction", "spent", "validClasses", "rule", "chalk", "import_path", "NAME", "MasterCSSWebpackPlugin", "MasterCSSCompiler", "compiler", "webpack", "Template", "RuntimeGlobals", "RuntimeModule", "RawSource", "Compilation", "options", "outputPath", "path", "linkHref", "compilation", "modules", "modifiedFiles", "watching", "eachExtractions", "eachModule", "name", "content", "originalCssText", "cssText", "newSource", "chunk", "import_path", "import_fs", "import_path", "writeFile", "filePath", "data", "options", "dirname", "path", "fs", "vite_default", "options", "compiler", "MasterCSSCompiler", "outputPath", "path", "server", "outputFilePath", "linkHref", "rendered", "extract", "name", "content", "eachExtractions", "originalCssText", "cssText", "writeFile", "notify", "_server", "source", "code", "id", "html", "hmrContext", "referenceId"]
7
- }
@@ -1,7 +0,0 @@
1
- {
2
- "version": 3,
3
- "sources": ["../src/compiler.ts", "../src/options/extract.ts", "../src/options/index.ts", "../src/webpack.ts", "../src/vite.ts", "../src/utils/write-file.ts"],
4
- "sourcesContent": ["import path from 'path'\nimport chalk from 'chalk'\nimport defaultOptions, { MasterCSSCompilerOptions, MasterCSSCompilerSource } from './options'\nimport MasterCSS, { extend } from '@master/css'\nimport { performance } from 'perf_hooks'\nimport type { MasterCSSConfig } from '@master/css'\n\nexport default class MasterCSSCompiler {\n\n constructor(\n public options?: MasterCSSCompilerOptions\n ) {\n this.options = extend(defaultOptions, options)\n let userConfig: MasterCSSConfig\n try {\n userConfig = require(path.resolve(process.cwd(), options.config || './master.css.js'))\n // eslint-disable-next-line no-empty\n } catch (err) { }\n this.css = new MasterCSS(userConfig)\n }\n\n css: MasterCSS\n extractions = new Set<string>()\n\n extract({ name, content }: MasterCSSCompilerSource) {\n if (\n !name || !content\n || !this.options.accept?.({ content, name })\n ) {\n return []\n }\n const eachExtractions: string[] = []\n\n this.log('accepts', ` \u2192 ${path.relative(process.cwd(), name)}`)\n\n for (const eachNewExtraction of this.options.extract({ content, name })) {\n if (this.extractions.has(eachNewExtraction)) {\n continue\n } else {\n this.extractions.add(eachNewExtraction)\n eachExtractions.push(eachNewExtraction)\n }\n }\n return eachExtractions\n }\n\n insert(extractions) {\n const p1 = performance.now()\n\n /* \u6839\u64DA\u985E\u540D\u5C0B\u627E\u4E26\u63D2\u5165\u898F\u5247 ( MasterCSS \u672C\u8EAB\u5E36\u6709\u5FEB\u53D6\u6A5F\u5236\uFF0C\u91CD\u8907\u7684\u985E\u540D\u4E0D\u6703\u518D\u7DE8\u8B6F\u53CA\u7522\u751F ) */\n for (const eachExtraction of extractions) {\n this.css.findAndInsert(eachExtraction)\n }\n\n const spent = Math.round((performance.now() - p1) * 1000)\n const validClasses = this.css.rules.map((rule) => rule.className)\n\n /* \u5370\u51FA Master CSS \u7DE8\u8B6F\u6642\u9593 */\n console.log(`[Master CSS] process ${chalk.green(extractions.length)} extractions in ${chalk.green(spent)} \u00B5s [${chalk.green(this.css.rules.length)} rules in ${chalk.green(path.join(this.options.output.dir, this.options.output.name))}]`)\n\n this.log('extractions', ` \u2192 ${chalk.green(extractions.length)} extractions: ${chalk.blue(extractions.join(' '))}`)\n this.log('validClasses', ` \u2192 ${chalk.green(validClasses.length)} total valid classes: ${chalk.blue(validClasses.join(' '))}`)\n }\n\n log(name, content) {\n if (this.options.debug === true || Array.isArray(this.options.debug) && this.options.debug.includes(name)) {\n console.log(content)\n }\n }\n}", "import { defaultSemantics } from '@master/css'\nimport type { MasterCSSCompilerSource } from './index'\n\nexport default function extract({ content }: MasterCSSCompilerSource) {\n const blocks = content.match(/[^\\s]+/g) ?? []\n const strings = new Set<string>()\n for (const block of blocks) {\n const result = peelString(block)\n if (result.size) {\n for (const string of result) {\n strings.add(string)\n }\n } else {\n strings.add(trimString(block))\n }\n }\n return [...strings].filter(x => x && !checkToExclude(x))\n}\n\nconst trimString = (content) => {\n const originContent = content\n content = content.replace(/^([\\w={[(\\\\]*[\"'`])/, '')\n if (!content.match(/^content:((?<!\\\\)[\"'`])((?:\\\\\\1|(?:(?!\\1))[\\S\\s])*)((?<!\\\\)\\1)$/)) {\n content = content.replace(/(\\.*|[([{\\\\:#]*|[\"'`].*)$/, '')\n }\n if (originContent === content) {\n return content\n } else {\n return trimString(content)\n }\n}\n\nconst peelString = (content) => {\n const strings = new Set<string>()\n const stringRegx = /((?<!\\\\)[\"'`])((?:\\\\\\1|(?:(?!\\1))[\\S\\s])*)((?<!\\\\)\\1)/g\n let m\n while ((m = stringRegx.exec(content)) !== null) {\n if (m.index === stringRegx.lastIndex) {\n stringRegx.lastIndex++\n }\n const result = peelString(m[2])\n if (result.size) {\n for (const string of result) {\n strings.add(string)\n }\n } else {\n strings.add(trimString(m[2]))\n }\n }\n return strings\n}\n\nconst checkToExclude = (content) => {\n return !content\n || (!content.match(/(?:^[\\w-]+:[\\w$#]+)|(?:^[@~][\\w-]+$)/) && !Object.keys(defaultSemantics).includes(content))\n || content.match(/\\*\\*/)\n || content.match(/:\\[/)\n || content.match(/\\$\\{/)\n || content.match(/\\{\\{/)\n || content.match(/\\(\\{[^}]*\\}/)\n || content.match(/<\\w+>|<\\/\\w+>/)\n}", "import extract from './extract'\n\nconst defaultOptions: MasterCSSCompilerOptions = {\n output: {\n name: 'master.css',\n dir: ''\n },\n accept({ name }) {\n if (name.match(/[\\\\/]node_modules[\\\\/]/)) {\n return false\n }\n if (name.match(/\\.(html|js|jsx|ts|tsx|svelte|astro|vue)$/i)) {\n return true\n }\n },\n extract\n}\n\nexport declare type MasterCSSCompilerSource = {\n name: string\n content: string\n}\n\nexport interface MasterCSSCompilerOptions {\n output?: {\n name: string\n dir: string\n },\n accept?: (source: MasterCSSCompilerSource) => boolean\n extract?: (source: MasterCSSCompilerSource) => string[]\n config?: string\n debug?: string[] | boolean\n}\n\nexport default defaultOptions", "import path from 'path'\nimport MasterCSSCompiler from './compiler'\nimport type { Compiler } from 'webpack'\n\nconst NAME = 'MasterCSSWebpackPlugin'\n\nexport default class MasterCSSWebpackPlugin extends MasterCSSCompiler {\n\n apply(compiler: Compiler) {\n const { webpack } = compiler\n const { Template, RuntimeGlobals, RuntimeModule } = webpack\n const { RawSource } = webpack.sources\n const { Compilation } = webpack\n const { options } = this\n const outputPath = path.join(options.output.dir || '', options.output.name)\n const linkHref = outputPath.replace(/\\\\/g, '/')\n\n // compiler.hooks.thisCompilation.tap(NAME, (compilation) => {\n\n // const enabledChunks = new WeakSet()\n\n // const handler = (chunk, set) => {\n // if (enabledChunks.has(chunk))\n // return\n\n // enabledChunks.add(chunk)\n\n // set.add(RuntimeGlobals.publicPath)\n\n // compilation.addRuntimeModule(chunk, new CssLoadingRuntimeModule(set))\n // }\n\n // compilation.hooks.runtimeRequirementInTree\n // .for(RuntimeGlobals.ensureChunkHandlers)\n // .tap(NAME, handler)\n // compilation.hooks.runtimeRequirementInTree\n // .for(RuntimeGlobals.hmrDownloadUpdateHandlers)\n // .tap(NAME, handler)\n\n // class CssLoadingRuntimeModule extends RuntimeModule {\n\n // runtimeRequirements: Set<string>\n\n // constructor(runtimeRequirements: Set<string>) {\n // super('master-css-loading', 10)\n\n // this.runtimeRequirements = runtimeRequirements\n // }\n\n // generate() {\n // const { runtimeRequirements } = this\n // const withHmr = runtimeRequirements.has(RuntimeGlobals.hmrDownloadUpdateHandlers)\n // if (!withHmr)\n // return ''\n\n // return Template.asString([\n // Date.now().toString(),\n // `const link = document.querySelector('[href*=\\\\'${linkHref}\\\\'][rel=stylesheet]')`,\n // 'if (link) {',\n // Template.indent([\n // 'link.href = link.href.replace(/ts=[0-9]+/, \\'ts=\\' + Date.now())'\n // ]),\n // '}'\n // ])\n // }\n // }\n // })\n\n compiler.hooks.compilation.tap(NAME, (compilation) => {\n // \u589E\u52A0\u984D\u5916\u7684 `master.css` assets\n compilation.hooks.finishModules.tap(NAME, (modules) => {\n const { modifiedFiles, watching } = compiler\n const eachExtractions: string[] = []\n\n for (const eachModule of modules) {\n const name = eachModule['resource']\n // \u5F9E\u8A18\u61B6\u9AD4\u6216\u5FEB\u53D6\u53D6\u5F97\u7576\u524D module \u7684\u539F\u59CB\u78BC\n const content = eachModule['_source']?.source()\n // \u5728 watch \u6A21\u5F0F\u4E0B\u50C5\u8655\u7406\u7576\u4E0B\u8B8A\u66F4\u7684\u6A94\u6848\n if (watching && modifiedFiles?.size && !modifiedFiles.has(name)) { continue }\n eachExtractions.push(...this.extract({ name, content }))\n }\n\n if (eachExtractions.length) {\n const originalCssText = this.css.text\n /* \u6BD4\u5C0D\u63D0\u53D6\u7269\u4E26\u63D2\u5165 CSS \u898F\u5247 */\n this.insert(eachExtractions)\n /* \u6839\u64DA cssText \u751F\u6210 `master.css` \u4E26\u52A0\u5165\u5230 Webpack \u7684 assets \u4E2D */\n const cssText = this.css.text\n if (cssText !== originalCssText) {\n const newSource = new RawSource(cssText)\n if (compilation.getAsset(outputPath)) {\n compilation.updateAsset(outputPath, newSource)\n } else {\n compilation.emitAsset(outputPath, newSource)\n }\n }\n }\n })\n\n compilation.hooks.processAssets.tap({\n name: NAME,\n stage: Compilation.PROCESS_ASSETS_STAGE_ADDITIONS,\n }, () => {\n compilation.chunks.forEach((chunk) => {\n chunk.files.add(outputPath)\n })\n })\n })\n }\n}\n", "import MasterCSSCompiler from './compiler'\nimport path from 'path'\nimport writeFile from './utils/write-file'\nimport type { MasterCSSCompilerOptions } from './options'\nimport type { PluginOption } from 'vite'\n\nexport default function (options?: MasterCSSCompilerOptions): PluginOption {\n const compiler = new MasterCSSCompiler(options)\n const outputPath = path.join(compiler.options.output.dir || '', compiler.options.output.name)\n\n let server\n let outputFilePath: string\n let linkHref: string\n let rendered = false\n\n const extract = (name, content) => {\n const eachExtractions = compiler.extract({ name, content })\n if (eachExtractions.length) {\n const originalCssText = compiler.css.text\n /* \u6BD4\u5C0D\u63D0\u53D6\u7269\u4E26\u63D2\u5165 CSS \u898F\u5247 */\n compiler.insert(eachExtractions)\n /* \u6839\u64DA cssText \u751F\u6210 `master.css` \u4E26\u52A0\u5165\u5230 Webpack \u7684 assets \u4E2D */\n const cssText = compiler.css.text\n if (cssText !== originalCssText) {\n if (server) {\n writeFile(outputFilePath, cssText)\n\n const notify = () => {\n server.ws.send({\n type: 'update',\n updates: [{\n path: linkHref,\n timestamp: Date.now()\n }]\n })\n }\n\n if (rendered) {\n notify()\n } else {\n setTimeout(notify, 500)\n\n rendered = true\n }\n }\n }\n }\n }\n\n return {\n name: 'vite-plugin-master-css',\n enforce: 'pre',\n configureServer(_server) {\n server = _server\n },\n buildStart() {\n outputFilePath = path.resolve(server?.config.cacheDir ?? process.cwd(), outputPath)\n if (server) {\n writeFile(outputFilePath, '')\n\n linkHref = (server.config.cacheDir.slice(process.cwd().length) + '/' + outputPath).replace(/\\\\/g, '/')\n }\n },\n resolveId(source) {\n if (source.endsWith('master.css?direct'))\n return '\\0' + source\n },\n transform(code, id) {\n extract(id, code)\n },\n transformIndexHtml(html) {\n return html.replace(\n /(<head>)/,\n `$1<link rel=\"stylesheet\" href=\"${linkHref}\">`\n )\n },\n async handleHotUpdate(hmrContext) {\n extract(hmrContext.file, await hmrContext.read())\n },\n generateBundle() {\n const referenceId = this.emitFile({\n type: 'asset',\n name: outputPath,\n source: compiler.css.text\n })\n linkHref = '/' + this.getFileName(referenceId)\n }\n } as PluginOption\n}", "import fs from 'fs'\nimport path from 'path'\n\nexport default function writeFile(filePath: string, data: string | NodeJS.ArrayBufferView, options?: fs.WriteFileOptions) {\n const dirname = path.dirname(filePath)\n if (!fs.existsSync(dirname)) {\n fs.mkdirSync(dirname, { recursive: true })\n }\n fs.writeFileSync(filePath, data, options)\n\n}\n"],
5
- "mappings": "6PAAA,OAAOA,MAAU,OACjB,OAAOC,MAAW,QCDlB,OAAS,oBAAAC,MAAwB,cAGlB,SAARC,EAAyB,CAAE,QAAAC,CAAQ,EAA4B,CAClE,IAAMC,EAASD,EAAQ,MAAM,SAAS,GAAK,CAAC,EACtCE,EAAU,IAAI,IACpB,QAAWC,KAASF,EAAQ,CACxB,IAAMG,EAASC,EAAWF,CAAK,EAC/B,GAAIC,EAAO,KACP,QAAWE,KAAUF,EACjBF,EAAQ,IAAII,CAAM,OAGtBJ,EAAQ,IAAIK,EAAWJ,CAAK,CAAC,CAErC,CACA,MAAO,CAAC,GAAGD,CAAO,EAAE,OAAOM,GAAKA,GAAK,CAACC,EAAeD,CAAC,CAAC,CAC3D,CAEA,IAAMD,EAAcP,GAAY,CAC5B,IAAMU,EAAgBV,EAKtB,OAJAA,EAAUA,EAAQ,QAAQ,sBAAuB,EAAE,EAC9CA,EAAQ,MAAM,iEAAiE,IAChFA,EAAUA,EAAQ,QAAQ,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CACTX,EAAiBF,EAAK,QAAQC,GAAQ,OAAO,UAAY,QAAQ,IAAI,EAAGF,CAAU,EAC9EE,IACAU,EAAUT,EAAgB,EAAE,EAE5BC,GAAYF,EAAO,OAAO,SAAS,MAAM,QAAQ,IAAI,EAAE,MAAM,EAAI,IAAMF,GAAY,QAAQ,MAAO,GAAG,EAE7G,EACA,UAAUe,EAAQ,CACd,GAAIA,EAAO,SAAS,mBAAmB,EACnC,MAAO,KAAOA,CACtB,EACA,UAAUC,EAAMC,EAAI,CAChBX,EAAQW,EAAID,CAAI,CACpB,EACA,mBAAmBE,EAAM,CACrB,OAAOA,EAAK,QACR,WACA,kCAAkCd,KACtC,CACJ,EACA,MAAM,gBAAgBe,EAAY,CAC9Bb,EAAQa,EAAW,KAAM,MAAMA,EAAW,KAAK,CAAC,CACpD,EACA,gBAAiB,CACb,IAAMC,EAAc,KAAK,SAAS,CAC9B,KAAM,QACN,KAAMpB,EACN,OAAQF,EAAS,IAAI,IACzB,CAAC,EACDM,EAAW,IAAM,KAAK,YAAYgB,CAAW,CACjD,CACJ,CACJ",
6
- "names": ["path", "chalk", "defaultSemantics", "extract", "content", "blocks", "strings", "block", "result", "peelString", "string", "trimString", "x", "checkToExclude", "originContent", "stringRegx", "m", "defaultOptions", "name", "extract", "options_default", "MasterCSS", "extend", "performance", "MasterCSSCompiler", "options", "extend", "options_default", "userConfig", "__require", "path", "MasterCSS", "name", "content", "eachExtractions", "eachNewExtraction", "extractions", "p1", "performance", "eachExtraction", "spent", "validClasses", "rule", "chalk", "path", "NAME", "MasterCSSWebpackPlugin", "MasterCSSCompiler", "compiler", "webpack", "Template", "RuntimeGlobals", "RuntimeModule", "RawSource", "Compilation", "options", "outputPath", "path", "linkHref", "compilation", "modules", "modifiedFiles", "watching", "eachExtractions", "eachModule", "name", "content", "originalCssText", "cssText", "newSource", "chunk", "path", "fs", "path", "writeFile", "filePath", "data", "options", "dirname", "vite_default", "options", "compiler", "MasterCSSCompiler", "outputPath", "path", "server", "outputFilePath", "linkHref", "rendered", "extract", "name", "content", "eachExtractions", "originalCssText", "cssText", "writeFile", "notify", "_server", "source", "code", "id", "html", "hmrContext", "referenceId"]
7
- }
@@ -1,2 +0,0 @@
1
- import type { MasterCSSCompilerSource } from './index';
2
- export default function extract({ content }: MasterCSSCompilerSource): string[];
@@ -1,4 +0,0 @@
1
- /// <reference types="node" />
2
- /// <reference types="node" />
3
- import fs from 'fs';
4
- export default function writeFile(filePath: string, data: string | NodeJS.ArrayBufferView, options?: fs.WriteFileOptions): void;
package/dist/vite.d.ts DELETED
@@ -1,3 +0,0 @@
1
- import type { MasterCSSCompilerOptions } from './options';
2
- import type { PluginOption } from 'vite';
3
- export default function (options?: MasterCSSCompilerOptions): PluginOption;
package/dist/webpack.d.ts DELETED
@@ -1,5 +0,0 @@
1
- import MasterCSSCompiler from './compiler';
2
- import type { Compiler } from 'webpack';
3
- export default class MasterCSSWebpackPlugin extends MasterCSSCompiler {
4
- apply(compiler: Compiler): void;
5
- }
package/readme.md DELETED
@@ -1,80 +0,0 @@
1
- <br><br>
2
- <div align="center">
3
-
4
- <p align="center">
5
- <img src="https://raw.githubusercontent.com/master-co/package/document/images/logo-and-text.svg" alt="logo" width="142">
6
- </p>
7
- <p align="center">
8
- <b><!-- name -->CSS Compiler<!----></b>
9
- </p>
10
- <p align="center"><!-- package.description -->Compile Master CSS ahead of time with zero-configuration integration with build tools<!----></p>
11
-
12
- [![MIT License](https://flat.badgen.net/github/license/master-co/css?color=yellow)](https://github.com/master-co/css-compiler/blob/main/LICENSE)
13
- [![Latest Release](https://flat.badgen.net/npm/v/@master/css-compiler?icon=npm&label&color=yellow)](https://www.npmjs.com/package/@master/css-compiler)
14
- [![Documentation](https://flat.badgen.net/badge/icon/Documentation?icon=awesome&label&color=yellow)](https://css.master.co)
15
- [![Github](https://flat.badgen.net/badge/icon/master-co%2Fcss-compiler?icon=github&label&color=yellow)](https://github.com/master-co/css)
16
- [![Discord](https://flat.badgen.net/badge/icon/discord?icon=discord&label&color=yellow)](https://discord.gg/sZNKpAAAw6)
17
- [![CI](https://flat.badgen.net/github/status/master-co/css-compiler/main/ci/circleci?icon=circleci)](https://circleci.com/gh/master-co/workflows/css-compiler/tree/main)
18
-
19
- </div>
20
-
21
- ##### On this page
22
-
23
- - [Usage](#usage)
24
- - [`webpack.config.js`](#webpackconfigjs)
25
- - [`vite.config.js`](#viteconfigjs)
26
- - [`next.config.js`](#nextconfigjs)
27
- - [Related](#related)
28
-
29
- ---
30
-
31
- # Usage
32
-
33
- ## `webpack.config.js`
34
- ```js
35
- const { MasterCSSWebpackPlugin } = require('@master/css-compiler')
36
-
37
- module.exports = {
38
- plugins: [
39
- new MasterCSSWebpackPlugin()
40
- ]
41
- };
42
- ```
43
-
44
- ## `vite.config.js`
45
- ```js
46
- import { MasterCSSVitePlugin } from '@master/css-compiler'
47
-
48
- export default defineConfig({
49
- plugins: [
50
- MasterCSSVitePlugin()
51
- ]
52
- })
53
- ```
54
-
55
- ## `next.config.js`
56
- ```js
57
- const { MasterCSSWebpackPlugin } = require('@master/css-compiler')
58
-
59
- const nextConfig = {
60
- ...,
61
- webpack: (config) => {
62
- config.plugins.push(
63
- new MasterCSSWebpackPlugin({
64
- output: {
65
- path: 'static/css'
66
- }
67
- })
68
- )
69
- return config
70
- }
71
- }
72
-
73
- module.exports = nextConfig
74
- ```
75
-
76
- ---
77
-
78
- # Related
79
- - [@master/css](https://github.com/master-co/css) - A Virtual CSS language with enhanced syntax. ( ~13KB )
80
- - [@master/css.react](https://github.com/master-co/css.react) - React hooks for Master CSS