oklchtohex 0.6.0 → 0.6.1
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/dist/converter.js +1 -1
- package/dist/index.js +1 -1
- package/dist/postcss-plugin.cjs +1 -1
- package/dist/postcss-plugin.js +1 -1
- package/dist/vite-plugin.js +1 -1
- package/package.json +1 -1
package/dist/converter.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
|
|
1
|
+
import{getTailwindDefaultHexForVar as g}from"./tailwind-default-hex.js";const H=/oklch\(([^)]*)\)/gi,C=/color-mix\(\s*in\s+oklab\s*,\s*var\(\s*(--[\w-]+)\s*\)\s*([0-9.]+)%\s*,\s*transparent\s*\)/gi;function l(e,t,r){return Math.min(r,Math.max(t,e))}function u(e){const t=Number.parseFloat(e);if(Number.isNaN(t))throw new Error(`Invalid numeric token: "${e}"`);return t}function T(e){const t=e.trim().toLowerCase();if(t.endsWith("%"))return l(u(t.slice(0,-1))/100,0,1);const r=u(t);return r>1&&r<=100?l(r/100,0,1):l(r,0,1)}function I(e){const t=e.trim().toLowerCase();return t.endsWith("deg")?u(t.slice(0,-3)):t.endsWith("rad")?u(t.slice(0,-3))*180/Math.PI:t.endsWith("turn")?u(t.slice(0,-4))*360:u(t)}function L(e){if(typeof e!="string")return 1;const t=e.trim().toLowerCase();return t.endsWith("%")?l(u(t.slice(0,-1))/100,0,1):l(u(t),0,1)}function x(e){const t=e%360;return t<0?t+360:t}function k(e){if(typeof e!="string")throw new Error("parseOklch expects a string like oklch(70% 0.2 30)");const t=e.trim(),r=t.toLowerCase();if(!r.startsWith("oklch(")||!r.endsWith(")"))throw new Error(`Invalid OKLCH function: "${e}"`);const n=t.slice(t.indexOf("(")+1,-1).trim(),s=n.indexOf("/"),o=s===-1?n:n.slice(0,s).trim(),a=s===-1?void 0:n.slice(s+1).trim(),c=o.replace(/,/g," ").split(/\s+/).filter(Boolean);if(c.length<3)throw new Error(`Invalid OKLCH channels: "${e}"`);const i=T(c[0]),h=Math.max(0,u(c[1])),m=x(I(c[2])),f=L(a);return{l:i,c:h,h:m,alpha:f}}function O(e,t,r){const n=e+.3963377774*t+.2158037573*r,s=e-.1055613458*t-.0638541728*r,o=e-.0894841775*t-1.291485548*r,a=n*n*n,c=s*s*s,i=o*o*o;return{r:4.0767416621*a-3.3077115913*c+.2309699292*i,g:-1.2684380046*a+2.6097574011*c-.3413193965*i,b:-.0041960863*a-.7034186147*c+1.707614701*i}}function d(e,t,r){const n=r*Math.PI/180,s=t*Math.cos(n),o=t*Math.sin(n);return O(e,s,o)}function b(e){return e.r>=0&&e.r<=1&&e.g>=0&&e.g<=1&&e.b>=0&&e.b<=1}function M(e,t,r){const n=d(e,t,r);if(b(n))return t;let s=0,o=t;for(let a=0;a<24;a+=1){const c=(s+o)/2,i=d(e,c,r);b(i)?s=c:o=c}return s}function w(e){return e<=.0031308?12.92*e:1.055*e**(1/2.4)-.055}function p(e){const t=l(e,0,1);return Math.round(t*255).toString(16).padStart(2,"0")}function $(e){const t=e.trim().toLowerCase();if(!t.startsWith("#"))return null;const r=t.slice(1);return r.length===3?`#${r[0]}${r[0]}${r[1]}${r[1]}${r[2]}${r[2]}`:r.length===4?`#${r[0]}${r[0]}${r[1]}${r[1]}${r[2]}${r[2]}${r[3]}${r[3]}`:r.length===6||r.length===8?`#${r}`:null}function N(e){const t=$(e);if(!t)return null;const r=t.slice(1),n=r.slice(0,6),s=r.length===8?r.slice(6,8):"ff";return{rgbHex:n,alphaHex:s}}function v(e){return p(l(e,0,1))}function y(e,t){const n=Number.parseInt(e,16)/255*l(t/100,0,1);return v(n)}function E(e){if(typeof e=="string")return k(e);if(e&&typeof e=="object"&&typeof e.l=="number"&&typeof e.c=="number"&&typeof e.h=="number")return{l:l(e.l,0,1),c:Math.max(0,e.c),h:x(e.h),alpha:l(e.alpha??1,0,1)};throw new Error("Input must be an OKLCH string or { l, c, h, alpha } object")}function A(e,t={}){const{gamut:r="clip",includeAlpha:n="auto",uppercase:s=!1}=t,o=E(e),a=r==="fit"?M(o.l,o.c,o.h):o.c,c=d(o.l,a,o.h),i=w(c.r),h=w(c.g),m=w(c.b);let f=`#${p(i)}${p(h)}${p(m)}`;return(n===!0||n==="always"||n==="auto"&&o.alpha<1)&&(f+=p(o.alpha)),s?f.toUpperCase():f}function W(e){const t=/(--color-[a-z]+-\d{2,3})(\s*:\s*)oklch\(([^)]*)\)/gi;return e.replace(t,(r,n,s)=>{const o=g(n.toLowerCase());return o?`${n}${s}${o}`:r})}function S(e){const t=/(--[\w-]+)\s*:\s*(#[0-9a-fA-F]{3,8})\s*;/g,r=new Map;let n=t.exec(e);for(;n;){const s=n[1].toLowerCase(),o=$(n[2]);o&&r.set(s,o),n=t.exec(e)}return r}function _(e,t){return e.replace(C,(r,n,s)=>{const o=String(n).toLowerCase(),a=Number.parseFloat(s);if(Number.isNaN(a))return r;const c=t.get(o)??g(o);if(!c)return r;const i=N(c);if(!i)return r;const h=y(i.alphaHex,a);return`#${i.rgbHex}${h}`})}function z(e,t={}){if(typeof e!="string")throw new Error("replaceOklchInText expects a string");const{onError:r="preserve",...n}=t,o=W(e).replace(H,c=>{try{return A(c,n)}catch(i){if(r==="throw")throw i;return c}}),a=S(o);return _(o,a)}function F(e,t={}){return z(e,t)}export{F as convertTailwindCssToHex,A as oklchToHex,k as parseOklch,z as replaceOklchInText};
|
package/dist/index.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
|
|
1
|
+
export*from"./converter.js";import{oklchToHexVitePlugin as t}from"./vite-plugin.js";import{oklchToHexPostcssPlugin as l}from"./postcss-plugin.js";export{l as oklchToHexPostcssPlugin,t as oklchToHexVitePlugin};
|
package/dist/postcss-plugin.cjs
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
var
|
|
1
|
+
var p=Object.create;var i=Object.defineProperty;var r=Object.getOwnPropertyDescriptor;var u=Object.getOwnPropertyNames;var a=Object.getPrototypeOf,g=Object.prototype.hasOwnProperty;var x=(s,o,t,e)=>{if(o&&typeof o=="object"||typeof o=="function")for(let n of u(o))!g.call(s,n)&&n!==t&&i(s,n,{get:()=>o[n],enumerable:!(e=r(o,n))||e.enumerable});return s};var d=(s,o,t)=>(t=s!=null?p(a(s)):{},x(o||!s||!s.__esModule?i(t,"default",{value:s,enumerable:!0}):t,s));function c(s){const o=s||{};return{postcssPlugin:"oklchtohex-postcss-plugin",async Once(t){const e=t.toString();if(!e.toLowerCase().includes("oklch("))return;const l=(await import("./converter.js")).replaceOklchInText(e,o);l!==e&&(t.removeAll(),t.append(l))}}}c.postcss=!0,module.exports=c,module.exports.default=c,module.exports.oklchToHexPostcssPlugin=c;
|
package/dist/postcss-plugin.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
|
|
1
|
+
import{replaceOklchInText as c}from"./converter.js";function t(n={}){return{postcssPlugin:"oklchtohex-postcss-plugin",Once(e){const s=e.toString();if(!s.toLowerCase().includes("oklch("))return;const o=c(s,n);o!==s&&(e.removeAll(),e.append(o))}}}t.postcss=!0;var r=t;export{r as default,t as oklchToHexPostcssPlugin};
|
package/dist/vite-plugin.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
|
|
1
|
+
import{replaceOklchInText as m}from"./converter.js";const g=/\.(css|pcss|postcss|scss|sass|less|styl|stylus)(?:$|\?)/i;function y(e,n){return e instanceof RegExp?(e.lastIndex=0,e.test(n)):!1}function a(e,n){return e?e instanceof RegExp?y(e,n):typeof e=="function"?!!e(n):!1:!0}function p(e,n,t){return!(!a(n,e)||t&&a(t,e))}function d(e,n){if(typeof e!="string"||!e.toLowerCase().includes("oklch("))return null;const t=m(e,n);return t===e?null:t}function E(e={}){const{include:n=g,exclude:t,convertDev:v=!0,convertBuild:l=!0,...c}=e;let u="build";return{name:"oklchtohex-vite-plugin",enforce:"post",configResolved(r){u=r.command},transform(r,i){if(u==="serve"&&!v||u==="build"&&!l||!p(i,n,t))return null;const s=d(r,c);return s?{code:s,map:null}:null},generateBundle(r,i){if(l)for(const[s,o]of Object.entries(i)){if(o.type!=="asset"||!p(s,n,t)||typeof o.source!="string")continue;const f=d(o.source,c);f&&(o.source=f)}}}}export{E as oklchToHexVitePlugin};
|