epiphany/node_modules/@csstools/css-calc/dist/index.cjs

2 lines
26 KiB
JavaScript
Raw Normal View History

2023-12-09 22:48:07 -08:00
"use strict";var e=require("@csstools/css-parser-algorithms"),n=require("@csstools/css-tokenizer");const o=/[A-Z]/g;function toLowerCaseAZ(e){return e.replace(o,(e=>String.fromCharCode(e.charCodeAt(0)+32)))}const t={cm:"px",in:"px",mm:"px",pc:"px",pt:"px",px:"px",q:"px",deg:"deg",grad:"deg",rad:"deg",turn:"deg",ms:"s",s:"s",hz:"hz",khz:"hz"},r=new Map([["cm",e=>e],["mm",e=>10*e],["q",e=>40*e],["in",e=>e/2.54],["pc",e=>e/2.54*6],["pt",e=>e/2.54*72],["px",e=>e/2.54*96]]),u=new Map([["deg",e=>e],["grad",e=>e/.9],["rad",e=>e/180*Math.PI],["turn",e=>e/360]]),i=new Map([["deg",e=>.9*e],["grad",e=>e],["rad",e=>.9*e/180*Math.PI],["turn",e=>.9*e/360]]),a=new Map([["hz",e=>e],["khz",e=>e/1e3]]),l=new Map([["cm",e=>2.54*e],["mm",e=>25.4*e],["q",e=>25.4*e*4],["in",e=>e],["pc",e=>6*e],["pt",e=>72*e],["px",e=>96*e]]),s=new Map([["hz",e=>1e3*e],["khz",e=>e]]),c=new Map([["cm",e=>e/10],["mm",e=>e],["q",e=>4*e],["in",e=>e/25.4],["pc",e=>e/25.4*6],["pt",e=>e/25.4*72],["px",e=>e/25.4*96]]),T=new Map([["ms",e=>e],["s",e=>e/1e3]]),p=new Map([["cm",e=>e/6*2.54],["mm",e=>e/6*25.4],["q",e=>e/6*25.4*4],["in",e=>e/6],["pc",e=>e],["pt",e=>e/6*72],["px",e=>e/6*96]]),v=new Map([["cm",e=>e/72*2.54],["mm",e=>e/72*25.4],["q",e=>e/72*25.4*4],["in",e=>e/72],["pc",e=>e/72*6],["pt",e=>e],["px",e=>e/72*96]]),m=new Map([["cm",e=>e/96*2.54],["mm",e=>e/96*25.4],["q",e=>e/96*25.4*4],["in",e=>e/96],["pc",e=>e/96*6],["pt",e=>e/96*72],["px",e=>e]]),N=new Map([["cm",e=>e/4/10],["mm",e=>e/4],["q",e=>e],["in",e=>e/4/25.4],["pc",e=>e/4/25.4*6],["pt",e=>e/4/25.4*72],["px",e=>e/4/25.4*96]]),f=new Map([["deg",e=>180*e/Math.PI],["grad",e=>180*e/Math.PI/.9],["rad",e=>e],["turn",e=>180*e/Math.PI/360]]),y=new Map([["ms",e=>1e3*e],["s",e=>e]]),k=new Map([["deg",e=>360*e],["grad",e=>360*e/.9],["rad",e=>360*e/180*Math.PI],["turn",e=>e]]),d=new Map([["cm",r],["mm",c],["q",N],["in",l],["pc",p],["pt",v],["px",m],["ms",T],["s",y],["deg",u],["grad",i],["rad",f],["turn",k],["hz",a],["khz",s]]);function convertUnit(e,o){if(e[0]!==n.TokenType.Dimension)return o;if(o[0]!==n.TokenType.Dimension)return o;const t=toLowerCaseAZ(e[4].unit),r=toLowerCaseAZ(o[4].unit);if(t===r)return o;const u=d.get(r);if(!u)return o;const i=u.get(t);if(!i)return o;const a=i(o[4].value);return[n.TokenType.Dimension,a.toString()+e[4].unit,o[2],o[3],{value:a,unit:e[4].unit,type:Number.isInteger(a)?n.NumberType.Integer:n.NumberType.Number}]}function toCanonicalUnit(e){if(e[0]!==n.TokenType.Dimension)return e;const o=toLowerCaseAZ(e[4].unit),r=t[o];if(o===r)return e;const u=d.get(o);if(!u)return e;const i=u.get(r);if(!i)return e;const a=i(e[4].value);return[n.TokenType.Dimension,a.toString()+r,e[2],e[3],{value:a,unit:r,type:Number.isInteger(a)?n.NumberType.Integer:n.NumberType.Number}]}function addition(o){if(2!==o.length)return-1;const t=o[0].value;let r=o[1].value;if(t[0]===n.TokenType.Number&&r[0]===n.TokenType.Number){const o=t[4].value+r[4].value;return new e.TokenNode([n.TokenType.Number,o.toString(),t[2],r[3],{value:o,type:t[4].type===n.NumberType.Integer&&r[4].type===n.NumberType.Integer?n.NumberType.Integer:n.NumberType.Number}])}if(t[0]===n.TokenType.Percentage&&r[0]===n.TokenType.Percentage){const o=t[4].value+r[4].value;return new e.TokenNode([n.TokenType.Percentage,o.toString()+"%",t[2],r[3],{value:o}])}if(t[0]===n.TokenType.Dimension&&r[0]===n.TokenType.Dimension&&(r=convertUnit(t,r),toLowerCaseAZ(t[4].unit)===toLowerCaseAZ(r[4].unit))){const o=t[4].value+r[4].value;return new e.TokenNode([n.TokenType.Dimension,o.toString()+t[4].unit,t[2],r[3],{value:o,type:t[4].type===n.NumberType.Integer&&r[4].type===n.NumberType.Integer?n.NumberType.Integer:n.NumberType.Number,unit:t[4].unit}])}return-1}function division(o){if(2!==o.length)return-1;const t=o[0].value,r=o[1].value;if(t[0]===n.TokenType.Number&&r[0]===n.TokenType.Number){const o=t[4].value/r[4].value;return new e.TokenNode([n.TokenType.Number,o.toString(),t[2],r[3],{value:o,type:Number.isInteger(o)?n.NumberType.Integer:n.NumberType.Number}])}if(t[0]===n.TokenType.Percentage&&r[0]===n.TokenType.Number){const o=t[4].value/r[4].value;return new e.Toke