@csstools/postcss-color-function 2.0.1 → 2.2.0

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/CHANGELOG.md CHANGED
@@ -1,5 +1,15 @@
1
1
  # Changes to PostCSS Color Function
2
2
 
3
+ ### 2.2.0 (March 25, 2023)
4
+
5
+ - Add `@csstools/css-color-parser` dependency for all color value transformations.
6
+ - Add support for `calc` expressions in color components.
7
+ - Remove support for missing channel values (`color(display-p3 1)`). This was never documented and was removed from the specification.
8
+
9
+ ### 2.1.0 (February 6, 2023)
10
+
11
+ - Add: `@csstools/color-helpers` dependency for all color value transformations.
12
+
3
13
  ### 2.0.1 (January 28, 2023)
4
14
 
5
15
  - Improve `types` declaration in `package.json`
package/README.md CHANGED
@@ -17,11 +17,11 @@ CSS, following the [CSS Color] specification.
17
17
  /* becomes */
18
18
 
19
19
  .color {
20
- color: rgb(179,35,35);
20
+ color: rgb(179, 35, 35);
21
21
  }
22
22
 
23
23
  :root {
24
- --a-color: rgb(164,49,43);
24
+ --a-color: rgb(164, 49, 43);
25
25
  }
26
26
  ```
27
27
 
@@ -78,12 +78,12 @@ postcssColorFunction({ preserve: true })
78
78
  /* becomes */
79
79
 
80
80
  .color {
81
- color: rgb(179,35,35);
81
+ color: rgb(179, 35, 35);
82
82
  color: color(display-p3 0.64331 0.19245 0.16771);
83
83
  }
84
84
 
85
85
  :root {
86
- --a-color: rgb(164,49,43);
86
+ --a-color: rgb(164, 49, 43);
87
87
  }
88
88
 
89
89
  @supports (color: color(srgb 0 0 0)) {
@@ -116,12 +116,12 @@ postcssColorFunction({ enableProgressiveCustomProperties: false })
116
116
  /* becomes */
117
117
 
118
118
  .color {
119
- color: rgb(179,35,35);
119
+ color: rgb(179, 35, 35);
120
120
  color: color(display-p3 0.64331 0.19245 0.16771);
121
121
  }
122
122
 
123
123
  :root {
124
- --a-color: rgb(164,49,43);
124
+ --a-color: rgb(164, 49, 43);
125
125
  --a-color: color(srgb 0.64331 0.19245 0.16771);
126
126
  }
127
127
  ```
@@ -144,20 +144,6 @@ _Custom properties do not fallback to the previous declaration_
144
144
  }
145
145
  ```
146
146
 
147
- ## Out of gamut colors
148
-
149
- Depending on the browser implementation out of gamut colors may be clipped, resulting in a different color.<br>
150
- Fallback values generated by [PostCSS Color Function] are always mapped to a close alternative in sRGB.
151
-
152
- When setting `preserve` to `true` the original values will be used by some browsers and these may be clipped.<br>
153
- Certain browsers will have an incorrect color if this occurs.
154
-
155
- If the plugin detects out of gamut colors it will emit a warning :
156
-
157
- > "color(srgb-linear -0.01656 0.23079 0.25298)" is out of gamut for "srgb-linear". When "preserve: true" is set this will lead to unexpected results in some browsers.
158
-
159
- To resolve this warning pick a larger color space when declaring the original value.
160
-
161
147
  ## Copyright : color conversions
162
148
 
163
149
  This software or document includes material copied from or derived from https://github.com/w3c/csswg-drafts/tree/main/css-color-4. Copyright © 2022 W3C® (MIT, ERCIM, Keio, Beihang).
package/dist/index.cjs CHANGED
@@ -1,29 +1 @@
1
- "use strict";var t=require("@csstools/postcss-progressive-custom-properties"),e=require("postcss-value-parser");function hasFallback(t){const e=t.parent;if(!e)return!1;const r=t.prop.toLowerCase(),n=e.index(t);for(let t=0;t<n;t++){const n=e.nodes[t];if("decl"===n.type&&n.prop.toLowerCase()===r)return!0}return!1}function hasSupportsAtRuleAncestor(t){let e=t.parent;for(;e;)if("atrule"===e.type){if("supports"===e.name&&-1!==e.params.indexOf("color("))return!0;e=e.parent}else e=e.parent;return!1}
2
- /**
3
- * Simple matrix (and vector) multiplication
4
- * Warning: No error handling for incompatible dimensions!
5
- * @author Lea Verou 2020 MIT License
6
- *
7
- * @license W3C
8
- * https://www.w3.org/Consortium/Legal/2015/copyright-software-and-document
9
- *
10
- * @copyright This software or document includes material copied from or derived from https://github.com/w3c/csswg-drafts/blob/main/css-color-4/multiply-matrices.js. Copyright © 2022 W3C® (MIT, ERCIM, Keio, Beihang).
11
- *
12
- * @see https://github.com/w3c/csswg-drafts/blob/main/css-color-4/multiply-matrices.js
13
- */function multiplyMatrices(t,e){const r=t.length;let n,a;n=Array.isArray(t[0])?t:[t],Array.isArray(e[0])||(a=e.map((t=>[t])));const o=a[0].length,s=a[0].map(((t,e)=>a.map((t=>t[e]))));let i=n.map((t=>s.map((e=>Array.isArray(t)?t.reduce(((t,r,n)=>t+r*(e[n]||0)),0):e.reduce(((e,r)=>e+r*t),0)))));return 1===r&&(i=i[0]),1===o?i.map((t=>t[0])):i}
14
- /**
15
- * @license W3C
16
- * https://www.w3.org/Consortium/Legal/2015/copyright-software-and-document
17
- *
18
- * @copyright This software or document includes material copied from or derived from https://github.com/w3c/csswg-drafts/blob/main/css-color-4/conversions.js. Copyright © 2022 W3C® (MIT, ERCIM, Keio, Beihang).
19
- *
20
- * @see https://github.com/w3c/csswg-drafts/blob/main/css-color-4/conversions.js
21
- */function lin_sRGB(t){return t.map((function(t){const e=t<0?-1:1,r=Math.abs(t);return r<.04045?t/12.92:e*Math.pow((r+.055)/1.055,2.4)}))}function gam_sRGB(t){return t.map((function(t){const e=t<0?-1:1,r=Math.abs(t);return r>.0031308?e*(1.055*Math.pow(r,1/2.4)-.055):12.92*t}))}function lin_sRGB_to_XYZ(t){return multiplyMatrices([[.41239079926595934,.357584339383878,.1804807884018343],[.21263900587151027,.715168678767756,.07219231536073371],[.01933081871559182,.11919477979462598,.9505321522496607]],t)}function XYZ_to_lin_sRGB(t){return multiplyMatrices([[3.2409699419045226,-1.537383177570094,-.4986107602930034],[-.9692436362808796,1.8759675015077202,.04155505740717559],[.05563007969699366,-.20397695888897652,1.0569715142428786]],t)}function lin_2020(t){const e=1.09929682680944;return t.map((function(t){const r=t<0?-1:1,n=Math.abs(t);return n<.08124285829863151?t/4.5:r*Math.pow((n+e-1)/e,1/.45)}))}function D50_to_D65(t){return multiplyMatrices([[.9554734527042182,-.023098536874261423,.0632593086610217],[-.028369706963208136,1.0099954580058226,.021041398966943008],[.012314001688319899,-.020507696433477912,1.3303659366080753]],t)}function XYZ_to_OKLab(t){const e=multiplyMatrices([[.8190224432164319,.3619062562801221,-.12887378261216414],[.0329836671980271,.9292868468965546,.03614466816999844],[.048177199566046255,.26423952494422764,.6335478258136937]],t);return multiplyMatrices([[.2104542553,.793617785,-.0040720468],[1.9779984951,-2.428592205,.4505937099],[.0259040371,.7827717662,-.808675766]],e.map((t=>Math.cbrt(t))))}function OKLab_to_XYZ(t){const e=multiplyMatrices([[.9999999984505198,.39633779217376786,.2158037580607588],[1.0000000088817609,-.10556134232365635,-.06385417477170591],[1.0000000546724108,-.08948418209496575,-1.2914855378640917]],t);return multiplyMatrices([[1.2268798733741557,-.5578149965554813,.28139105017721583],[-.04057576262431372,1.1122868293970594,-.07171106666151701],[-.07637294974672142,-.4214933239627914,1.5869240244272418]],e.map((t=>t**3)))}function OKLab_to_OKLCH(t){const e=180*Math.atan2(t[2],t[1])/Math.PI;return[t[0],Math.sqrt(t[1]**2+t[2]**2),e>=0?e:e+360]}function OKLCH_to_OKLab(t){return[t[0],t[1]*Math.cos(t[2]*Math.PI/180),t[1]*Math.sin(t[2]*Math.PI/180)]}
22
- /**
23
- * @license W3C
24
- * https://www.w3.org/Consortium/Legal/2015/copyright-software-and-document
25
- *
26
- * @copyright This software or document includes material copied from or derived from https://github.com/w3c/csswg-drafts/blob/main/css-color-4/deltaEOK.js. Copyright © 2022 W3C® (MIT, ERCIM, Keio, Beihang).
27
- *
28
- * @see https://github.com/w3c/csswg-drafts/blob/main/css-color-4/deltaEOK.js
29
- */function deltaEOK(t,e){const[r,n,a]=t,[o,s,i]=e,u=r-o,c=n-s,l=a-i;return Math.sqrt(u**2+c**2+l**2)}function mapGamut(t,e,r){return binarySearchGamut(t,e,r)}function binarySearchGamut(t,e,r){let n=0,a=t[1];const o=t;for(;a-n>1e-4;){const t=clip(e(o));deltaEOK(OKLCH_to_OKLab(o),OKLCH_to_OKLab(r(t)))-.02<1e-4?n=o[1]:a=o[1],o[1]=(a+n)/2}return clip(e([...o]))}function clip(t){return t.map((t=>t<0?0:t>1?1:t))}function inGamut(t){const[e,r,n]=t;return e>=-1e-4&&e<=1.0001&&r>=-1e-4&&r<=1.0001&&n>=-1e-4&&n<=1.0001}function a98RgbToSRgb(t){let e=t.slice();e=e.map((function(t){const e=t<0?-1:1,r=Math.abs(t);return e*Math.pow(r,563/256)})),e=multiplyMatrices([[.5766690429101305,.1855582379065463,.1882286462349947],[.29734497525053605,.6273635662554661,.07529145849399788],[.02703136138641234,.07068885253582723,.9913375368376388]],e);let r=e.slice();return r=XYZ_to_OKLab(r),r=OKLab_to_OKLCH(r),r[0]<1e-6&&(r=[0,0,0]),r[0]>.999999&&(r=[1,0,0]),e=XYZ_to_lin_sRGB(e),e=gam_sRGB(e),inGamut(e)?clip(e):mapGamut(r,(t=>gam_sRGB(t=XYZ_to_lin_sRGB(t=OKLab_to_XYZ(t=OKLCH_to_OKLab(t))))),(t=>OKLab_to_OKLCH(t=XYZ_to_OKLab(t=lin_sRGB_to_XYZ(t=lin_sRGB(t))))))}function cieXyz50ToSRgb(t){let e=t.slice();e=D50_to_D65(e);let r=e.slice();return r=XYZ_to_OKLab(r),r=OKLab_to_OKLCH(r),r[0]<1e-6&&(r=[0,0,0]),r[0]>.999999&&(r=[1,0,0]),e=XYZ_to_lin_sRGB(e),e=gam_sRGB(e),inGamut(e)?clip(e):mapGamut(r,(t=>gam_sRGB(t=XYZ_to_lin_sRGB(t=OKLab_to_XYZ(t=OKLCH_to_OKLab(t))))),(t=>OKLab_to_OKLCH(t=XYZ_to_OKLab(t=lin_sRGB_to_XYZ(t=lin_sRGB(t))))))}function cieXyz65ToSRgb(t){let e=t.slice(),r=e.slice();return r=XYZ_to_OKLab(r),r=OKLab_to_OKLCH(r),r[0]<1e-6&&(r=[0,0,0]),r[0]>.999999&&(r=[1,0,0]),e=XYZ_to_lin_sRGB(e),e=gam_sRGB(e),inGamut(e)?clip(e):mapGamut(r,(t=>gam_sRGB(t=XYZ_to_lin_sRGB(t=OKLab_to_XYZ(t=OKLCH_to_OKLab(t))))),(t=>OKLab_to_OKLCH(t=XYZ_to_OKLab(t=lin_sRGB_to_XYZ(t=lin_sRGB(t))))))}function displayP3ToSRgb(t){let e=t.slice();e=lin_sRGB(e),e=multiplyMatrices([[.4865709486482162,.26566769316909306,.1982172852343625],[.2289745640697488,.6917385218365064,.079286914093745],[0,.04511338185890264,1.043944368900976]],e);let r=e.slice();return r=XYZ_to_OKLab(r),r=OKLab_to_OKLCH(r),r[0]<1e-6&&(r=[0,0,0]),r[0]>.999999&&(r=[1,0,0]),e=XYZ_to_lin_sRGB(e),e=gam_sRGB(e),inGamut(e)?clip(e):mapGamut(r,(t=>gam_sRGB(t=XYZ_to_lin_sRGB(t=OKLab_to_XYZ(t=OKLCH_to_OKLab(t))))),(t=>OKLab_to_OKLCH(t=XYZ_to_OKLab(t=lin_sRGB_to_XYZ(t=lin_sRGB(t))))))}function prophotoRgbToSRgb(t){let e=t.slice();e=e.map((function(t){const e=t<0?-1:1;return Math.abs(t)<=.03125?t/16:e*Math.pow(t,1.8)})),e=multiplyMatrices([[.7977604896723027,.13518583717574031,.0313493495815248],[.2880711282292934,.7118432178101014,8565396060525902e-20],[0,0,.8251046025104601]],e),e=D50_to_D65(e);let r=e.slice();return r=XYZ_to_OKLab(r),r=OKLab_to_OKLCH(r),r[0]<1e-6&&(r=[0,0,0]),r[0]>.999999&&(r=[1,0,0]),e=XYZ_to_lin_sRGB(e),e=gam_sRGB(e),inGamut(e)?clip(e):mapGamut(r,(t=>gam_sRGB(t=XYZ_to_lin_sRGB(t=OKLab_to_XYZ(t=OKLCH_to_OKLab(t))))),(t=>OKLab_to_OKLCH(t=XYZ_to_OKLab(t=lin_sRGB_to_XYZ(t=lin_sRGB(t))))))}function rec2020ToSRgb(t){let e=t.slice();e=lin_2020(e),e=multiplyMatrices([[.6369580483012914,.14461690358620832,.1688809751641721],[.2627002120112671,.6779980715188708,.05930171646986196],[0,.028072693049087428,1.060985057710791]],e);let r=e.slice();return r=XYZ_to_OKLab(r),r=OKLab_to_OKLCH(r),r[0]<1e-6&&(r=[0,0,0]),r[0]>.999999&&(r=[1,0,0]),e=XYZ_to_lin_sRGB(e),e=gam_sRGB(e),inGamut(e)?clip(e):mapGamut(r,(t=>gam_sRGB(t=XYZ_to_lin_sRGB(t=OKLab_to_XYZ(t=OKLCH_to_OKLab(t))))),(t=>OKLab_to_OKLCH(t=XYZ_to_OKLab(t=lin_sRGB_to_XYZ(t=lin_sRGB(t))))))}function sRgbLinearToSRgb(t){let e=t.slice();e=lin_sRGB_to_XYZ(e);let r=e.slice();return r=XYZ_to_OKLab(r),r=OKLab_to_OKLCH(r),r[0]<1e-6&&(r=[0,0,0]),r[0]>.999999&&(r=[1,0,0]),e=XYZ_to_lin_sRGB(e),e=gam_sRGB(e),inGamut(e)?clip(e):mapGamut(r,(t=>gam_sRGB(t=XYZ_to_lin_sRGB(t=OKLab_to_XYZ(t=OKLCH_to_OKLab(t))))),(t=>OKLab_to_OKLCH(t=XYZ_to_OKLab(t=lin_sRGB_to_XYZ(t=lin_sRGB(t))))))}function sRgbToSRgb(t){let e=t.slice();e=lin_sRGB(e),e=lin_sRGB_to_XYZ(e);let r=e.slice();return r=XYZ_to_OKLab(r),r=OKLab_to_OKLCH(r),r[0]<1e-6&&(r=[0,0,0]),r[0]>.999999&&(r=[1,0,0]),e=XYZ_to_lin_sRGB(e),e=gam_sRGB(e),inGamut(e)?clip(e):mapGamut(r,(t=>gam_sRGB(t=XYZ_to_lin_sRGB(t=OKLab_to_XYZ(t=OKLCH_to_OKLab(t))))),(t=>OKLab_to_OKLCH(t=XYZ_to_OKLab(t=lin_sRGB_to_XYZ(t=lin_sRGB(t))))))}function onCSSFunctionSRgb(t,r,n,a){const o=e.stringify(t),s=t.value,i=t.nodes.slice().filter((t=>"comment"!==t.type&&"space"!==t.type));let u,c=null;if("color"===s.toLowerCase()&&(c=colorFunctionContents(i)),!c)return;switch(t.value="rgb",transformAlpha(t,c.slash,c.alpha),c.colorSpace){case"srgb":u=sRgbToSRgb;break;case"srgb-linear":u=sRgbLinearToSRgb;break;case"a98-rgb":u=a98RgbToSRgb;break;case"prophoto-rgb":u=prophotoRgbToSRgb;break;case"display-p3":u=displayP3ToSRgb;break;case"rec2020":u=rec2020ToSRgb;break;case"xyz-d50":u=cieXyz50ToSRgb;break;case"xyz-d65":case"xyz":u=cieXyz65ToSRgb;break;default:return}const l=(_=c,_.parameters.map((t=>t.value))).map((t=>parseFloat(t.number)));var _;const p=u(l);!inGamut(l)&&a&&r.warn(n,`"${o}" is out of gamut for "${c.colorSpace}". Given "preserve: true" is set, this will lead to unexpected results in some browsers.`),t.nodes=[{sourceIndex:0,sourceEndIndex:1,value:String(Math.round(255*p[0])),type:"word"},{sourceIndex:0,sourceEndIndex:1,value:",",type:"div",before:"",after:""},{sourceIndex:0,sourceEndIndex:1,value:String(Math.round(255*p[1])),type:"word"},{sourceIndex:0,sourceEndIndex:1,value:",",type:"div",before:"",after:""},{sourceIndex:0,sourceEndIndex:1,value:String(Math.round(255*p[2])),type:"word"}],c.alpha&&(t.nodes.push({sourceIndex:0,sourceEndIndex:1,value:",",type:"div",before:"",after:""}),t.nodes.push(c.alpha))}function isColorSpaceNode(t){if(!t||"word"!==t.type)return!1;switch(t.value.toLowerCase()){case"srgb":case"srgb-linear":case"display-p3":case"a98-rgb":case"prophoto-rgb":case"rec2020":case"xyz-d50":case"xyz-d65":case"xyz":return!0;default:return!1}}function isNumericNode(t){if(!t||"word"!==t.type)return!1;if(!canParseAsUnit(t))return!1;const r=e.unit(t.value);return!!r&&!!r.number}function isNumericNodePercentageOrNumber(t){if(!t||"word"!==t.type)return!1;if(!canParseAsUnit(t))return!1;const r=e.unit(t.value);return!!r&&("%"===r.unit||""===r.unit)}function isCalcNode(t){return t&&"function"===t.type&&"calc"===t.value.toLowerCase()}function isVarNode(t){return t&&"function"===t.type&&"var"===t.value.toLowerCase()}function colorFunctionContents(t){if(!isColorSpaceNode(t[0]))return null;const r={colorSpace:t[0].value.toLowerCase(),colorSpaceNode:t[0],parameters:[]};for(let a=1;a<t.length;a++)if((n=t[a])&&"div"===n.type&&"/"===n.value)r.slash=t[a];else{if(r.slash&&(isNumericNodePercentageOrNumber(t[a])||isCalcNode(t[a])||isVarNode(t[a]))){r.alpha=t[a];break}if(!isNumericNodePercentageOrNumber(t[a]))return null;{const n=e.unit(t[a].value);"%"===n.unit&&(n.number=String(parseFloat(n.number)/100),n.unit="",t[a].value=String(n.number)),r.parameters.push({value:n,node:t[a]})}}var n;return 0===r.parameters.length||(r.parameters.length<3&&(r.parameters=[...r.parameters,{node:{sourceIndex:0,sourceEndIndex:1,value:"0",type:"word"},value:{number:"0",unit:""}},{node:{sourceIndex:0,sourceEndIndex:1,value:"0",type:"word"},value:{number:"0",unit:""}}]),r.parameters.length>3&&(r.parameters=r.parameters.slice(0,3))),r}function transformAlpha(t,r,n){if(!r||!n)return;if(t.value="rgba",r.value=",",r.before="",!isNumericNode(n))return;const a=e.unit(n.value);a&&"%"===a.unit&&(a.number=String(parseFloat(a.number)/100),n.value=String(a.number))}function canParseAsUnit(t){if(!t||!t.value)return!1;try{return!1!==e.unit(t.value)}catch(t){return!1}}function modifiedValues(t,r,n,a){let o;try{o=e(t)}catch(e){r.warn(n,`Failed to parse value '${t}' as a color function. Leaving the original value intact.`)}if(void 0===o)return;o.walk((t=>{t.type&&"function"===t.type&&"color"===t.value.toLowerCase()&&onCSSFunctionSRgb(t,r,n,a)}));const s=String(o);return s!==t?s:void 0}const basePlugin=t=>{const e="preserve"in Object(t)&&Boolean(t.preserve);return{postcssPlugin:"postcss-color-function",Declaration:(t,{result:r})=>{if(hasFallback(t))return;if(hasSupportsAtRuleAncestor(t))return;const n=t.value;if(!n.toLowerCase().includes("color("))return;const a=modifiedValues(n,t,r,e);void 0!==a&&(t.cloneBefore({value:a}),e||t.remove())}}};basePlugin.postcss=!0;const postcssPlugin=e=>{const r=Object.assign({preserve:!1,enableProgressiveCustomProperties:!0},e);return r.enableProgressiveCustomProperties&&r.preserve?{postcssPlugin:"postcss-color-function",plugins:[t(),basePlugin(r)]}:basePlugin(r)};postcssPlugin.postcss=!0,module.exports=postcssPlugin;
1
+ "use strict";var e=require("@csstools/postcss-progressive-custom-properties"),s=require("@csstools/css-tokenizer"),r=require("@csstools/css-color-parser"),o=require("@csstools/css-parser-algorithms");function hasFallback(e){const s=e.parent;if(!s)return!1;const r=e.prop.toLowerCase(),o=s.index(e);for(let e=0;e<o;e++){const o=s.nodes[e];if("decl"===o.type&&o.prop.toLowerCase()===r)return!0}return!1}function hasSupportsAtRuleAncestor(e){let s=e.parent;for(;s;)if("atrule"===s.type){if("supports"===s.name&&-1!==s.params.indexOf("color("))return!0;s=s.parent}else s=s.parent;return!1}const t=/(color)\(/i,n=/^(color)$/i,basePlugin=e=>({postcssPlugin:"postcss-color-function",Declaration:c=>{const a=c.value;if(!t.test(a.toLowerCase()))return;if(hasFallback(c))return;if(hasSupportsAtRuleAncestor(c))return;const i=s.tokenize({css:a}),l=o.replaceComponentValues(o.parseCommaSeparatedListOfComponentValues(i),(e=>{if(o.isFunctionNode(e)&&n.test(e.getName())){const s=r.color(e);if(!s)return;if(s.syntaxFlags.has(r.SyntaxFlag.HasNoneKeywords))return;return r.serializeRGB(s)}})),p=o.stringify(l);p!==a&&(c.cloneBefore({value:p}),null!=e&&e.preserve||c.remove())}});basePlugin.postcss=!0;const postcssPlugin=s=>{const r=Object.assign({preserve:!1,enableProgressiveCustomProperties:!0},s);return r.enableProgressiveCustomProperties&&r.preserve?{postcssPlugin:"postcss-color-function",plugins:[e(),basePlugin(r)]}:basePlugin(r)};postcssPlugin.postcss=!0,module.exports=postcssPlugin;
package/dist/index.mjs CHANGED
@@ -1,29 +1 @@
1
- import t from"@csstools/postcss-progressive-custom-properties";import e from"postcss-value-parser";function hasFallback(t){const e=t.parent;if(!e)return!1;const n=t.prop.toLowerCase(),r=e.index(t);for(let t=0;t<r;t++){const r=e.nodes[t];if("decl"===r.type&&r.prop.toLowerCase()===n)return!0}return!1}function hasSupportsAtRuleAncestor(t){let e=t.parent;for(;e;)if("atrule"===e.type){if("supports"===e.name&&-1!==e.params.indexOf("color("))return!0;e=e.parent}else e=e.parent;return!1}
2
- /**
3
- * Simple matrix (and vector) multiplication
4
- * Warning: No error handling for incompatible dimensions!
5
- * @author Lea Verou 2020 MIT License
6
- *
7
- * @license W3C
8
- * https://www.w3.org/Consortium/Legal/2015/copyright-software-and-document
9
- *
10
- * @copyright This software or document includes material copied from or derived from https://github.com/w3c/csswg-drafts/blob/main/css-color-4/multiply-matrices.js. Copyright © 2022 W3C® (MIT, ERCIM, Keio, Beihang).
11
- *
12
- * @see https://github.com/w3c/csswg-drafts/blob/main/css-color-4/multiply-matrices.js
13
- */function multiplyMatrices(t,e){const n=t.length;let r,o;r=Array.isArray(t[0])?t:[t],Array.isArray(e[0])||(o=e.map((t=>[t])));const a=o[0].length,s=o[0].map(((t,e)=>o.map((t=>t[e]))));let i=r.map((t=>s.map((e=>Array.isArray(t)?t.reduce(((t,n,r)=>t+n*(e[r]||0)),0):e.reduce(((e,n)=>e+n*t),0)))));return 1===n&&(i=i[0]),1===a?i.map((t=>t[0])):i}
14
- /**
15
- * @license W3C
16
- * https://www.w3.org/Consortium/Legal/2015/copyright-software-and-document
17
- *
18
- * @copyright This software or document includes material copied from or derived from https://github.com/w3c/csswg-drafts/blob/main/css-color-4/conversions.js. Copyright © 2022 W3C® (MIT, ERCIM, Keio, Beihang).
19
- *
20
- * @see https://github.com/w3c/csswg-drafts/blob/main/css-color-4/conversions.js
21
- */function lin_sRGB(t){return t.map((function(t){const e=t<0?-1:1,n=Math.abs(t);return n<.04045?t/12.92:e*Math.pow((n+.055)/1.055,2.4)}))}function gam_sRGB(t){return t.map((function(t){const e=t<0?-1:1,n=Math.abs(t);return n>.0031308?e*(1.055*Math.pow(n,1/2.4)-.055):12.92*t}))}function lin_sRGB_to_XYZ(t){return multiplyMatrices([[.41239079926595934,.357584339383878,.1804807884018343],[.21263900587151027,.715168678767756,.07219231536073371],[.01933081871559182,.11919477979462598,.9505321522496607]],t)}function XYZ_to_lin_sRGB(t){return multiplyMatrices([[3.2409699419045226,-1.537383177570094,-.4986107602930034],[-.9692436362808796,1.8759675015077202,.04155505740717559],[.05563007969699366,-.20397695888897652,1.0569715142428786]],t)}function lin_2020(t){const e=1.09929682680944;return t.map((function(t){const n=t<0?-1:1,r=Math.abs(t);return r<.08124285829863151?t/4.5:n*Math.pow((r+e-1)/e,1/.45)}))}function D50_to_D65(t){return multiplyMatrices([[.9554734527042182,-.023098536874261423,.0632593086610217],[-.028369706963208136,1.0099954580058226,.021041398966943008],[.012314001688319899,-.020507696433477912,1.3303659366080753]],t)}function XYZ_to_OKLab(t){const e=multiplyMatrices([[.8190224432164319,.3619062562801221,-.12887378261216414],[.0329836671980271,.9292868468965546,.03614466816999844],[.048177199566046255,.26423952494422764,.6335478258136937]],t);return multiplyMatrices([[.2104542553,.793617785,-.0040720468],[1.9779984951,-2.428592205,.4505937099],[.0259040371,.7827717662,-.808675766]],e.map((t=>Math.cbrt(t))))}function OKLab_to_XYZ(t){const e=multiplyMatrices([[.9999999984505198,.39633779217376786,.2158037580607588],[1.0000000088817609,-.10556134232365635,-.06385417477170591],[1.0000000546724108,-.08948418209496575,-1.2914855378640917]],t);return multiplyMatrices([[1.2268798733741557,-.5578149965554813,.28139105017721583],[-.04057576262431372,1.1122868293970594,-.07171106666151701],[-.07637294974672142,-.4214933239627914,1.5869240244272418]],e.map((t=>t**3)))}function OKLab_to_OKLCH(t){const e=180*Math.atan2(t[2],t[1])/Math.PI;return[t[0],Math.sqrt(t[1]**2+t[2]**2),e>=0?e:e+360]}function OKLCH_to_OKLab(t){return[t[0],t[1]*Math.cos(t[2]*Math.PI/180),t[1]*Math.sin(t[2]*Math.PI/180)]}
22
- /**
23
- * @license W3C
24
- * https://www.w3.org/Consortium/Legal/2015/copyright-software-and-document
25
- *
26
- * @copyright This software or document includes material copied from or derived from https://github.com/w3c/csswg-drafts/blob/main/css-color-4/deltaEOK.js. Copyright © 2022 W3C® (MIT, ERCIM, Keio, Beihang).
27
- *
28
- * @see https://github.com/w3c/csswg-drafts/blob/main/css-color-4/deltaEOK.js
29
- */function deltaEOK(t,e){const[n,r,o]=t,[a,s,i]=e,u=n-a,c=r-s,l=o-i;return Math.sqrt(u**2+c**2+l**2)}function mapGamut(t,e,n){return binarySearchGamut(t,e,n)}function binarySearchGamut(t,e,n){let r=0,o=t[1];const a=t;for(;o-r>1e-4;){const t=clip(e(a));deltaEOK(OKLCH_to_OKLab(a),OKLCH_to_OKLab(n(t)))-.02<1e-4?r=a[1]:o=a[1],a[1]=(o+r)/2}return clip(e([...a]))}function clip(t){return t.map((t=>t<0?0:t>1?1:t))}function inGamut(t){const[e,n,r]=t;return e>=-1e-4&&e<=1.0001&&n>=-1e-4&&n<=1.0001&&r>=-1e-4&&r<=1.0001}function a98RgbToSRgb(t){let e=t.slice();e=e.map((function(t){const e=t<0?-1:1,n=Math.abs(t);return e*Math.pow(n,563/256)})),e=multiplyMatrices([[.5766690429101305,.1855582379065463,.1882286462349947],[.29734497525053605,.6273635662554661,.07529145849399788],[.02703136138641234,.07068885253582723,.9913375368376388]],e);let n=e.slice();return n=XYZ_to_OKLab(n),n=OKLab_to_OKLCH(n),n[0]<1e-6&&(n=[0,0,0]),n[0]>.999999&&(n=[1,0,0]),e=XYZ_to_lin_sRGB(e),e=gam_sRGB(e),inGamut(e)?clip(e):mapGamut(n,(t=>gam_sRGB(t=XYZ_to_lin_sRGB(t=OKLab_to_XYZ(t=OKLCH_to_OKLab(t))))),(t=>OKLab_to_OKLCH(t=XYZ_to_OKLab(t=lin_sRGB_to_XYZ(t=lin_sRGB(t))))))}function cieXyz50ToSRgb(t){let e=t.slice();e=D50_to_D65(e);let n=e.slice();return n=XYZ_to_OKLab(n),n=OKLab_to_OKLCH(n),n[0]<1e-6&&(n=[0,0,0]),n[0]>.999999&&(n=[1,0,0]),e=XYZ_to_lin_sRGB(e),e=gam_sRGB(e),inGamut(e)?clip(e):mapGamut(n,(t=>gam_sRGB(t=XYZ_to_lin_sRGB(t=OKLab_to_XYZ(t=OKLCH_to_OKLab(t))))),(t=>OKLab_to_OKLCH(t=XYZ_to_OKLab(t=lin_sRGB_to_XYZ(t=lin_sRGB(t))))))}function cieXyz65ToSRgb(t){let e=t.slice(),n=e.slice();return n=XYZ_to_OKLab(n),n=OKLab_to_OKLCH(n),n[0]<1e-6&&(n=[0,0,0]),n[0]>.999999&&(n=[1,0,0]),e=XYZ_to_lin_sRGB(e),e=gam_sRGB(e),inGamut(e)?clip(e):mapGamut(n,(t=>gam_sRGB(t=XYZ_to_lin_sRGB(t=OKLab_to_XYZ(t=OKLCH_to_OKLab(t))))),(t=>OKLab_to_OKLCH(t=XYZ_to_OKLab(t=lin_sRGB_to_XYZ(t=lin_sRGB(t))))))}function displayP3ToSRgb(t){let e=t.slice();e=lin_sRGB(e),e=multiplyMatrices([[.4865709486482162,.26566769316909306,.1982172852343625],[.2289745640697488,.6917385218365064,.079286914093745],[0,.04511338185890264,1.043944368900976]],e);let n=e.slice();return n=XYZ_to_OKLab(n),n=OKLab_to_OKLCH(n),n[0]<1e-6&&(n=[0,0,0]),n[0]>.999999&&(n=[1,0,0]),e=XYZ_to_lin_sRGB(e),e=gam_sRGB(e),inGamut(e)?clip(e):mapGamut(n,(t=>gam_sRGB(t=XYZ_to_lin_sRGB(t=OKLab_to_XYZ(t=OKLCH_to_OKLab(t))))),(t=>OKLab_to_OKLCH(t=XYZ_to_OKLab(t=lin_sRGB_to_XYZ(t=lin_sRGB(t))))))}function prophotoRgbToSRgb(t){let e=t.slice();e=e.map((function(t){const e=t<0?-1:1;return Math.abs(t)<=.03125?t/16:e*Math.pow(t,1.8)})),e=multiplyMatrices([[.7977604896723027,.13518583717574031,.0313493495815248],[.2880711282292934,.7118432178101014,8565396060525902e-20],[0,0,.8251046025104601]],e),e=D50_to_D65(e);let n=e.slice();return n=XYZ_to_OKLab(n),n=OKLab_to_OKLCH(n),n[0]<1e-6&&(n=[0,0,0]),n[0]>.999999&&(n=[1,0,0]),e=XYZ_to_lin_sRGB(e),e=gam_sRGB(e),inGamut(e)?clip(e):mapGamut(n,(t=>gam_sRGB(t=XYZ_to_lin_sRGB(t=OKLab_to_XYZ(t=OKLCH_to_OKLab(t))))),(t=>OKLab_to_OKLCH(t=XYZ_to_OKLab(t=lin_sRGB_to_XYZ(t=lin_sRGB(t))))))}function rec2020ToSRgb(t){let e=t.slice();e=lin_2020(e),e=multiplyMatrices([[.6369580483012914,.14461690358620832,.1688809751641721],[.2627002120112671,.6779980715188708,.05930171646986196],[0,.028072693049087428,1.060985057710791]],e);let n=e.slice();return n=XYZ_to_OKLab(n),n=OKLab_to_OKLCH(n),n[0]<1e-6&&(n=[0,0,0]),n[0]>.999999&&(n=[1,0,0]),e=XYZ_to_lin_sRGB(e),e=gam_sRGB(e),inGamut(e)?clip(e):mapGamut(n,(t=>gam_sRGB(t=XYZ_to_lin_sRGB(t=OKLab_to_XYZ(t=OKLCH_to_OKLab(t))))),(t=>OKLab_to_OKLCH(t=XYZ_to_OKLab(t=lin_sRGB_to_XYZ(t=lin_sRGB(t))))))}function sRgbLinearToSRgb(t){let e=t.slice();e=lin_sRGB_to_XYZ(e);let n=e.slice();return n=XYZ_to_OKLab(n),n=OKLab_to_OKLCH(n),n[0]<1e-6&&(n=[0,0,0]),n[0]>.999999&&(n=[1,0,0]),e=XYZ_to_lin_sRGB(e),e=gam_sRGB(e),inGamut(e)?clip(e):mapGamut(n,(t=>gam_sRGB(t=XYZ_to_lin_sRGB(t=OKLab_to_XYZ(t=OKLCH_to_OKLab(t))))),(t=>OKLab_to_OKLCH(t=XYZ_to_OKLab(t=lin_sRGB_to_XYZ(t=lin_sRGB(t))))))}function sRgbToSRgb(t){let e=t.slice();e=lin_sRGB(e),e=lin_sRGB_to_XYZ(e);let n=e.slice();return n=XYZ_to_OKLab(n),n=OKLab_to_OKLCH(n),n[0]<1e-6&&(n=[0,0,0]),n[0]>.999999&&(n=[1,0,0]),e=XYZ_to_lin_sRGB(e),e=gam_sRGB(e),inGamut(e)?clip(e):mapGamut(n,(t=>gam_sRGB(t=XYZ_to_lin_sRGB(t=OKLab_to_XYZ(t=OKLCH_to_OKLab(t))))),(t=>OKLab_to_OKLCH(t=XYZ_to_OKLab(t=lin_sRGB_to_XYZ(t=lin_sRGB(t))))))}function onCSSFunctionSRgb(t,n,r,o){const a=e.stringify(t),s=t.value,i=t.nodes.slice().filter((t=>"comment"!==t.type&&"space"!==t.type));let u,c=null;if("color"===s.toLowerCase()&&(c=colorFunctionContents(i)),!c)return;switch(t.value="rgb",transformAlpha(t,c.slash,c.alpha),c.colorSpace){case"srgb":u=sRgbToSRgb;break;case"srgb-linear":u=sRgbLinearToSRgb;break;case"a98-rgb":u=a98RgbToSRgb;break;case"prophoto-rgb":u=prophotoRgbToSRgb;break;case"display-p3":u=displayP3ToSRgb;break;case"rec2020":u=rec2020ToSRgb;break;case"xyz-d50":u=cieXyz50ToSRgb;break;case"xyz-d65":case"xyz":u=cieXyz65ToSRgb;break;default:return}const l=(_=c,_.parameters.map((t=>t.value))).map((t=>parseFloat(t.number)));var _;const p=u(l);!inGamut(l)&&o&&n.warn(r,`"${a}" is out of gamut for "${c.colorSpace}". Given "preserve: true" is set, this will lead to unexpected results in some browsers.`),t.nodes=[{sourceIndex:0,sourceEndIndex:1,value:String(Math.round(255*p[0])),type:"word"},{sourceIndex:0,sourceEndIndex:1,value:",",type:"div",before:"",after:""},{sourceIndex:0,sourceEndIndex:1,value:String(Math.round(255*p[1])),type:"word"},{sourceIndex:0,sourceEndIndex:1,value:",",type:"div",before:"",after:""},{sourceIndex:0,sourceEndIndex:1,value:String(Math.round(255*p[2])),type:"word"}],c.alpha&&(t.nodes.push({sourceIndex:0,sourceEndIndex:1,value:",",type:"div",before:"",after:""}),t.nodes.push(c.alpha))}function isColorSpaceNode(t){if(!t||"word"!==t.type)return!1;switch(t.value.toLowerCase()){case"srgb":case"srgb-linear":case"display-p3":case"a98-rgb":case"prophoto-rgb":case"rec2020":case"xyz-d50":case"xyz-d65":case"xyz":return!0;default:return!1}}function isNumericNode(t){if(!t||"word"!==t.type)return!1;if(!canParseAsUnit(t))return!1;const n=e.unit(t.value);return!!n&&!!n.number}function isNumericNodePercentageOrNumber(t){if(!t||"word"!==t.type)return!1;if(!canParseAsUnit(t))return!1;const n=e.unit(t.value);return!!n&&("%"===n.unit||""===n.unit)}function isCalcNode(t){return t&&"function"===t.type&&"calc"===t.value.toLowerCase()}function isVarNode(t){return t&&"function"===t.type&&"var"===t.value.toLowerCase()}function colorFunctionContents(t){if(!isColorSpaceNode(t[0]))return null;const n={colorSpace:t[0].value.toLowerCase(),colorSpaceNode:t[0],parameters:[]};for(let o=1;o<t.length;o++)if((r=t[o])&&"div"===r.type&&"/"===r.value)n.slash=t[o];else{if(n.slash&&(isNumericNodePercentageOrNumber(t[o])||isCalcNode(t[o])||isVarNode(t[o]))){n.alpha=t[o];break}if(!isNumericNodePercentageOrNumber(t[o]))return null;{const r=e.unit(t[o].value);"%"===r.unit&&(r.number=String(parseFloat(r.number)/100),r.unit="",t[o].value=String(r.number)),n.parameters.push({value:r,node:t[o]})}}var r;return 0===n.parameters.length||(n.parameters.length<3&&(n.parameters=[...n.parameters,{node:{sourceIndex:0,sourceEndIndex:1,value:"0",type:"word"},value:{number:"0",unit:""}},{node:{sourceIndex:0,sourceEndIndex:1,value:"0",type:"word"},value:{number:"0",unit:""}}]),n.parameters.length>3&&(n.parameters=n.parameters.slice(0,3))),n}function transformAlpha(t,n,r){if(!n||!r)return;if(t.value="rgba",n.value=",",n.before="",!isNumericNode(r))return;const o=e.unit(r.value);o&&"%"===o.unit&&(o.number=String(parseFloat(o.number)/100),r.value=String(o.number))}function canParseAsUnit(t){if(!t||!t.value)return!1;try{return!1!==e.unit(t.value)}catch(t){return!1}}function modifiedValues(t,n,r,o){let a;try{a=e(t)}catch(e){n.warn(r,`Failed to parse value '${t}' as a color function. Leaving the original value intact.`)}if(void 0===a)return;a.walk((t=>{t.type&&"function"===t.type&&"color"===t.value.toLowerCase()&&onCSSFunctionSRgb(t,n,r,o)}));const s=String(a);return s!==t?s:void 0}const basePlugin=t=>{const e="preserve"in Object(t)&&Boolean(t.preserve);return{postcssPlugin:"postcss-color-function",Declaration:(t,{result:n})=>{if(hasFallback(t))return;if(hasSupportsAtRuleAncestor(t))return;const r=t.value;if(!r.toLowerCase().includes("color("))return;const o=modifiedValues(r,t,n,e);void 0!==o&&(t.cloneBefore({value:o}),e||t.remove())}}};basePlugin.postcss=!0;const postcssPlugin=e=>{const n=Object.assign({preserve:!1,enableProgressiveCustomProperties:!0},e);return n.enableProgressiveCustomProperties&&n.preserve?{postcssPlugin:"postcss-color-function",plugins:[t(),basePlugin(n)]}:basePlugin(n)};postcssPlugin.postcss=!0;export{postcssPlugin as default};
1
+ import s from"@csstools/postcss-progressive-custom-properties";import{tokenize as r}from"@csstools/css-tokenizer";import{color as e,SyntaxFlag as o,serializeRGB as t}from"@csstools/css-color-parser";import{replaceComponentValues as n,parseCommaSeparatedListOfComponentValues as c,isFunctionNode as p,stringify as a}from"@csstools/css-parser-algorithms";function hasFallback(s){const r=s.parent;if(!r)return!1;const e=s.prop.toLowerCase(),o=r.index(s);for(let s=0;s<o;s++){const o=r.nodes[s];if("decl"===o.type&&o.prop.toLowerCase()===e)return!0}return!1}function hasSupportsAtRuleAncestor(s){let r=s.parent;for(;r;)if("atrule"===r.type){if("supports"===r.name&&-1!==r.params.indexOf("color("))return!0;r=r.parent}else r=r.parent;return!1}const i=/(color)\(/i,l=/^(color)$/i,basePlugin=s=>({postcssPlugin:"postcss-color-function",Declaration:u=>{const f=u.value;if(!i.test(f.toLowerCase()))return;if(hasFallback(u))return;if(hasSupportsAtRuleAncestor(u))return;const m=r({css:f}),g=n(c(m),(s=>{if(p(s)&&l.test(s.getName())){const r=e(s);if(!r)return;if(r.syntaxFlags.has(o.HasNoneKeywords))return;return t(r)}})),v=a(g);v!==f&&(u.cloneBefore({value:v}),null!=s&&s.preserve||u.remove())}});basePlugin.postcss=!0;const postcssPlugin=r=>{const e=Object.assign({preserve:!1,enableProgressiveCustomProperties:!0},r);return e.enableProgressiveCustomProperties&&e.preserve?{postcssPlugin:"postcss-color-function",plugins:[s(),basePlugin(e)]}:basePlugin(e)};postcssPlugin.postcss=!0;export{postcssPlugin as default};
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@csstools/postcss-color-function",
3
3
  "description": "Use the color() function in CSS",
4
- "version": "2.0.1",
4
+ "version": "2.2.0",
5
5
  "author": "Jonathan Neal <jonathantneal@hotmail.com>",
6
6
  "license": "CC0-1.0",
7
7
  "funding": {
@@ -29,26 +29,24 @@
29
29
  "dist"
30
30
  ],
31
31
  "dependencies": {
32
- "@csstools/postcss-progressive-custom-properties": "^2.0.0",
33
- "postcss-value-parser": "^4.2.0"
32
+ "@csstools/css-color-parser": "^1.0.0",
33
+ "@csstools/css-parser-algorithms": "^2.0.1",
34
+ "@csstools/css-tokenizer": "^2.1.0",
35
+ "@csstools/postcss-progressive-custom-properties": "^2.0.0"
34
36
  },
35
37
  "peerDependencies": {
36
38
  "postcss": "^8.4"
37
39
  },
38
40
  "devDependencies": {
39
- "postcss-lab-function": "^4.0.3"
41
+ "@csstools/postcss-tape": "*",
42
+ "postcss-lab-function": "^5.0.0"
40
43
  },
41
44
  "scripts": {
42
- "prebuild": "npm run clean",
43
45
  "build": "rollup -c ../../rollup/default.mjs",
44
- "clean": "node -e \"fs.rmSync('./dist', { recursive: true, force: true }); fs.mkdirSync('./dist');\"",
45
46
  "docs": "node ../../.github/bin/generate-docs/install.mjs && node ../../.github/bin/generate-docs/readme.mjs",
46
- "lint": "npm run lint:eslint && npm run lint:package-json",
47
- "lint:eslint": "eslint ./src --ext .js --ext .ts --ext .mjs --no-error-on-unmatched-pattern",
48
- "lint:package-json": "node ../../.github/bin/format-package-json.mjs",
49
- "prepublishOnly": "npm run clean && npm run build && npm run test",
50
- "test": "node .tape.mjs && npm run test:exports",
51
- "test:exports": "node ./test/_import.mjs && node ./test/_require.cjs",
47
+ "lint": "node ../../.github/bin/format-package-json.mjs",
48
+ "prepublishOnly": "npm run build && npm run test",
49
+ "test": "node .tape.mjs && node ./test/_import.mjs && node ./test/_require.cjs",
52
50
  "test:rewrite-expects": "REWRITE_EXPECTS=true node .tape.mjs"
53
51
  },
54
52
  "homepage": "https://github.com/csstools/postcss-plugins/tree/main/plugins/postcss-color-function#readme",
@@ -1,3 +0,0 @@
1
- type color = [number, number, number];
2
- export declare function a98RgbToSRgb(a98: color): color;
3
- export {};
@@ -1,3 +0,0 @@
1
- type color = [number, number, number];
2
- export declare function cieXyz50ToSRgb(xyz: color): color;
3
- export {};
@@ -1,3 +0,0 @@
1
- type color = [number, number, number];
2
- export declare function cieXyz65ToSRgb(xyz: color): color;
3
- export {};
@@ -1,3 +0,0 @@
1
- type color = [number, number, number];
2
- export declare function displayP3ToSRgb(displayP3: color): color;
3
- export {};
@@ -1,3 +0,0 @@
1
- type color = [number, number, number];
2
- export declare function prophotoRgbToSRgb(prophoto: color): color;
3
- export {};
@@ -1,3 +0,0 @@
1
- type color = [number, number, number];
2
- export declare function rec2020ToSRgb(rec: color): color;
3
- export {};
@@ -1,3 +0,0 @@
1
- type color = [number, number, number];
2
- export declare function sRgbLinearToSRgb(linearSRgb: color): color;
3
- export {};
@@ -1,3 +0,0 @@
1
- type color = [number, number, number];
2
- export declare function sRgbToSRgb(sRgb: color): color;
3
- export {};
@@ -1,47 +0,0 @@
1
- /**
2
- * @license W3C
3
- * https://www.w3.org/Consortium/Legal/2015/copyright-software-and-document
4
- *
5
- * @copyright This software or document includes material copied from or derived from https://github.com/w3c/csswg-drafts/blob/main/css-color-4/conversions.js. Copyright © 2022 W3C® (MIT, ERCIM, Keio, Beihang).
6
- *
7
- * @see https://github.com/w3c/csswg-drafts/blob/main/css-color-4/conversions.js
8
- */
9
- type color = [number, number, number];
10
- export declare const D50: number[];
11
- export declare const D65: number[];
12
- export declare function lin_sRGB(RGB: color): color;
13
- export declare function gam_sRGB(RGB: color): color;
14
- export declare function lin_sRGB_to_XYZ(rgb: color): color;
15
- export declare function XYZ_to_lin_sRGB(XYZ: color): color;
16
- export declare function lin_P3(RGB: color): color;
17
- export declare function gam_P3(RGB: color): color;
18
- export declare function lin_P3_to_XYZ(rgb: color): color;
19
- export declare function XYZ_to_lin_P3(XYZ: color): color;
20
- export declare function lin_ProPhoto(RGB: color): color;
21
- export declare function gam_ProPhoto(RGB: color): color;
22
- export declare function lin_ProPhoto_to_XYZ(rgb: color): color;
23
- export declare function XYZ_to_lin_ProPhoto(XYZ: color): color;
24
- export declare function lin_a98rgb(RGB: color): color;
25
- export declare function gam_a98rgb(RGB: color): color;
26
- export declare function lin_a98rgb_to_XYZ(rgb: color): color;
27
- export declare function XYZ_to_lin_a98rgb(XYZ: color): color;
28
- export declare function lin_2020(RGB: color): color;
29
- export declare function gam_2020(RGB: color): color;
30
- export declare function lin_2020_to_XYZ(rgb: color): color;
31
- export declare function XYZ_to_lin_2020(XYZ: color): color;
32
- export declare function D65_to_D50(XYZ: color): color;
33
- export declare function D50_to_D65(XYZ: color): color;
34
- export declare function XYZ_to_Lab(XYZ: color): color;
35
- export declare function Lab_to_XYZ(Lab: color): color;
36
- export declare function Lab_to_LCH(Lab: color): color;
37
- export declare function LCH_to_Lab(LCH: color): color;
38
- export declare function XYZ_to_OKLab(XYZ: color): color;
39
- export declare function OKLab_to_XYZ(OKLab: color): color;
40
- export declare function OKLab_to_OKLCH(OKLab: color): color;
41
- export declare function OKLCH_to_OKLab(OKLCH: color): color;
42
- export declare function rectangular_premultiply(color: color, alpha: number): color;
43
- export declare function rectangular_un_premultiply(color: color, alpha: number): color;
44
- export declare function polar_premultiply(color: color, alpha: number, hueIndex: number): color;
45
- export declare function polar_un_premultiply(color: color, alpha: number, hueIndex: number): color;
46
- export declare function hsl_premultiply(color: color, alpha: number): color;
47
- export {};
@@ -1,11 +0,0 @@
1
- /**
2
- * @license W3C
3
- * https://www.w3.org/Consortium/Legal/2015/copyright-software-and-document
4
- *
5
- * @copyright This software or document includes material copied from or derived from https://github.com/w3c/csswg-drafts/blob/main/css-color-4/deltaEOK.js. Copyright © 2022 W3C® (MIT, ERCIM, Keio, Beihang).
6
- *
7
- * @see https://github.com/w3c/csswg-drafts/blob/main/css-color-4/deltaEOK.js
8
- */
9
- type color = [number, number, number];
10
- export declare function deltaEOK(reference: color, sample: color): number;
11
- export {};
@@ -1,5 +0,0 @@
1
- type color = [number, number, number];
2
- export declare function mapGamut(startOKLCH: color, toDestination: (x: color) => color, fromDestination: (x: color) => color): color;
3
- export declare function clip(color: color): color;
4
- export declare function inGamut(x: color): boolean;
5
- export {};
@@ -1,13 +0,0 @@
1
- /**
2
- * Simple matrix (and vector) multiplication
3
- * Warning: No error handling for incompatible dimensions!
4
- * @author Lea Verou 2020 MIT License
5
- *
6
- * @license W3C
7
- * https://www.w3.org/Consortium/Legal/2015/copyright-software-and-document
8
- *
9
- * @copyright This software or document includes material copied from or derived from https://github.com/w3c/csswg-drafts/blob/main/css-color-4/multiply-matrices.js. Copyright © 2022 W3C® (MIT, ERCIM, Keio, Beihang).
10
- *
11
- * @see https://github.com/w3c/csswg-drafts/blob/main/css-color-4/multiply-matrices.js
12
- */
13
- export declare function multiplyMatrices(a: Array<Array<number>> | Array<number>, b: Array<Array<number>> | Array<number>): Array<Array<number>> | Array<number>;
@@ -1,25 +0,0 @@
1
- /**
2
- * @license W3C
3
- * https://www.w3.org/Consortium/Legal/2015/copyright-software-and-document
4
- *
5
- * @copyright This software or document includes material copied from or derived from https://github.com/w3c/csswg-drafts/blob/main/css-color-4/utilities.js. Copyright © 2022 W3C® (MIT, ERCIM, Keio, Beihang).
6
- *
7
- * @see https://github.com/w3c/csswg-drafts/blob/main/css-color-4/utilities.js
8
- */
9
- type color = [number, number, number];
10
- export declare function sRGB_to_luminance(RGB: color): number;
11
- export declare function contrast(RGB1: color, RGB2: color): number;
12
- export declare function sRGB_to_LCH(RGB: color): color;
13
- export declare function P3_to_LCH(RGB: color): color;
14
- export declare function r2020_to_LCH(RGB: color): color;
15
- export declare function LCH_to_sRGB(LCH: color): color;
16
- export declare function LCH_to_P3(LCH: color): color;
17
- export declare function LCH_to_r2020(LCH: color): color;
18
- export declare function hslToRgb(hsl: color): color;
19
- export declare function hueToRgb(t1: number, t2: number, hue: number): number;
20
- export declare function naive_CMYK_to_sRGB(CMYK: [number, number, number, number]): color;
21
- export declare function naive_sRGB_to_CMYK(RGB: color): [number, number, number, number];
22
- export declare function XYZ_to_xy(XYZ: color): [number, number];
23
- export declare function xy_to_uv(xy: [number, number]): [number, number];
24
- export declare function XYZ_to_uv(XYZ: color): [number, number];
25
- export {};
@@ -1,2 +0,0 @@
1
- import type { Declaration, Result } from 'postcss';
2
- export declare function modifiedValues(originalValue: string, decl: Declaration, result: Result, preserve: boolean): string | undefined;
@@ -1,3 +0,0 @@
1
- import type { Declaration, Result } from 'postcss';
2
- import type { FunctionNode } from 'postcss-value-parser';
3
- export declare function onCSSFunctionSRgb(node: FunctionNode, decl: Declaration, result: Result, preserve: boolean): void;