UNPKG

@shufo/tailwindcss-class-sorter

Version:

A tailwindcss class sorter that respects tailwind config file

11 lines (8 loc) 2.33 kB
import path from 'path'; import { fileURLToPath } from 'url'; import { createRequire as topLevelCreateRequire } from 'module'; const require = topLevelCreateRequire(import.meta.url); const __filename = fileURLToPath(import.meta.url); const __dirname = path.dirname(__filename); var y=(t=>typeof require<"u"?require:typeof Proxy<"u"?new Proxy(t,{get:(n,r)=>(typeof require<"u"?require:n)[r]}):t)(function(t){if(typeof require<"u")return require.apply(this,arguments);throw new Error('Dynamic require of "'+t+'" is not supported')});var u=y("url").pathToFileURL(__filename);import O from"tailwindcss/lib/lib/setupContextUtils.js";import _ from"tailwindcss/lib/lib/generateRules.js";import N from"tailwindcss/resolveConfig.js";import x from"tailwindcss/loadConfig.js";import U from"escalade/sync";import k from"object-hash";import m from"path";import P from"fs";import{fileURLToPath as b}from"url";var E=b(u),S=m.dirname(E),a={content:[],theme:{}},d=new Map,g="tailwind.config.js";function C(t){let n=t>0n,r=t<0n;return n-r}function p(t,n){let r=t.tailwindConfig.prefix;return typeof r=="function"?r(n):r+n}function j(t,n){let r=new Set([p(n,"group"),p(n,"peer")]),o=[];for(let i of t){let s=_(new Set([i]),n).sort(([l],[c])=>C(c-l))[0]?.[0]??null;s===null&&r.has(i)&&(s=n.layerOrder.components),o.push([i,s])}return o}function Y(t,n={}){let r=U(S,(e,f)=>{if(f.includes(g))return g});if(a.content=["no-op"],r&&(a=w(r)),n.tailwindConfig&&n.tailwindConfigPath)throw new Error("You can not specify tailwinfConfig or tailwinfConfigPath. Please specify either one.");n.tailwindConfigPath&&(a=w(n.tailwindConfigPath)),n.tailwindConfig&&(a=n.tailwindConfig);let o=k(a,{ignoreUnknown:!0}),i,s=d.get(o);s&&s.hash===o?i=s.context:(i=O.createContext(N(a)),d.set(o,{context:i,hash:o}));let l=t.split(/\s+/).filter(e=>e!==""&&e!=="|"),c=[],h=(i.getClassOrder?i.getClassOrder(l):j(l,i)).sort(([,e],[,f])=>e===f?0:e===null?-1:f===null?1:C(e-f)).map(([e])=>e);return[...c,...h].join(" ")}function w(t){if(!P.existsSync(t))throw new Error("tailwind config could not be found at: "+m);try{return x(t)}catch(n){throw n.code==="MODULE_NOT_FOUND"&&n.moduleName===m.resolve(t)?new Error("tailwind config could not be found at: "+t):n}}export{Y as sortClasses}; //# sourceMappingURL=main.js.map