@symbo.ls/scratch 3.14.2 → 3.14.4
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 +19 -0
- package/dist/cjs/index.js +1 -0
- package/dist/cjs/package.json +1 -0
- package/dist/cjs/src/defaultConfig/animation.js +1 -0
- package/dist/cjs/src/defaultConfig/cases.js +1 -0
- package/dist/cjs/src/defaultConfig/class.js +1 -0
- package/dist/cjs/src/defaultConfig/color.js +1 -0
- package/dist/cjs/src/defaultConfig/document.js +1 -0
- package/dist/cjs/src/defaultConfig/font-family.js +1 -0
- package/dist/cjs/src/defaultConfig/font.js +1 -0
- package/dist/cjs/src/defaultConfig/grid.js +1 -0
- package/dist/cjs/src/defaultConfig/icons.js +1 -0
- package/dist/cjs/src/defaultConfig/index.js +1 -0
- package/dist/cjs/src/defaultConfig/media.js +1 -0
- package/dist/cjs/src/defaultConfig/responsive.js +1 -0
- package/dist/cjs/src/defaultConfig/sequence.js +1 -0
- package/dist/cjs/src/defaultConfig/shadow.js +1 -0
- package/dist/cjs/src/defaultConfig/spacing.js +1 -0
- package/dist/cjs/src/defaultConfig/svg.js +1 -0
- package/dist/cjs/src/defaultConfig/templates.js +1 -0
- package/dist/cjs/src/defaultConfig/theme.js +1 -0
- package/dist/cjs/src/defaultConfig/timing.js +1 -0
- package/dist/cjs/src/defaultConfig/typography.js +1 -0
- package/dist/cjs/src/defaultConfig/unit.js +1 -0
- package/dist/cjs/src/factory.js +1 -0
- package/dist/cjs/src/index.js +1 -0
- package/dist/cjs/src/set.js +1 -0
- package/dist/cjs/src/system/color.js +1 -0
- package/dist/cjs/src/system/document.js +1 -0
- package/dist/cjs/src/system/font.js +1 -0
- package/dist/cjs/src/system/index.js +1 -0
- package/dist/cjs/src/system/reset.js +1 -0
- package/dist/cjs/src/system/shadow.js +1 -0
- package/dist/cjs/src/system/spacing.js +1 -0
- package/dist/cjs/src/system/svg.js +1 -0
- package/dist/cjs/src/system/theme.js +1 -0
- package/dist/cjs/src/system/timing.js +1 -0
- package/dist/cjs/src/system/typography.js +1 -0
- package/dist/cjs/src/tests/index.js +1 -0
- package/dist/cjs/src/transforms/index.js +1 -0
- package/dist/cjs/src/utils/color.js +1 -0
- package/dist/cjs/src/utils/font.js +9 -0
- package/dist/cjs/src/utils/index.js +1 -0
- package/dist/cjs/src/utils/sequence.js +1 -0
- package/dist/cjs/src/utils/sprite.js +1 -0
- package/dist/cjs/src/utils/theme.js +1 -0
- package/dist/cjs/src/utils/unit.js +1 -0
- package/dist/cjs/src/utils/var.js +1 -0
- package/dist/esm/index.js +1 -0
- package/dist/esm/src/defaultConfig/animation.js +1 -0
- package/dist/esm/src/defaultConfig/cases.js +1 -0
- package/dist/esm/src/defaultConfig/class.js +1 -0
- package/dist/esm/src/defaultConfig/color.js +1 -0
- package/dist/esm/src/defaultConfig/document.js +1 -0
- package/dist/esm/src/defaultConfig/font-family.js +1 -0
- package/dist/esm/src/defaultConfig/font.js +1 -0
- package/dist/esm/src/defaultConfig/grid.js +1 -0
- package/dist/esm/src/defaultConfig/icons.js +1 -0
- package/dist/esm/src/defaultConfig/index.js +1 -0
- package/dist/esm/src/defaultConfig/media.js +1 -0
- package/dist/esm/src/defaultConfig/responsive.js +1 -0
- package/dist/esm/src/defaultConfig/sequence.js +1 -0
- package/dist/esm/src/defaultConfig/shadow.js +1 -0
- package/dist/esm/src/defaultConfig/spacing.js +1 -0
- package/dist/esm/src/defaultConfig/svg.js +1 -0
- package/dist/esm/src/defaultConfig/templates.js +1 -0
- package/dist/esm/src/defaultConfig/theme.js +1 -0
- package/dist/esm/src/defaultConfig/timing.js +1 -0
- package/dist/esm/src/defaultConfig/typography.js +1 -0
- package/dist/esm/src/defaultConfig/unit.js +1 -0
- package/dist/esm/src/factory.js +1 -0
- package/dist/esm/src/index.js +1 -0
- package/dist/esm/src/set.js +1 -0
- package/dist/esm/src/system/color.js +1 -0
- package/dist/esm/src/system/document.js +1 -0
- package/dist/esm/src/system/font.js +1 -0
- package/dist/esm/src/system/index.js +1 -0
- package/dist/esm/src/system/reset.js +1 -0
- package/dist/esm/src/system/shadow.js +1 -0
- package/dist/esm/src/system/spacing.js +1 -0
- package/dist/esm/src/system/svg.js +1 -0
- package/dist/esm/src/system/theme.js +1 -0
- package/dist/esm/src/system/timing.js +1 -0
- package/dist/esm/src/system/typography.js +1 -0
- package/dist/esm/src/tests/index.js +1 -0
- package/dist/esm/src/transforms/index.js +1 -0
- package/dist/esm/src/utils/color.js +1 -0
- package/dist/esm/src/utils/font.js +9 -0
- package/dist/esm/src/utils/index.js +1 -0
- package/dist/esm/src/utils/sequence.js +1 -0
- package/dist/esm/src/utils/sprite.js +1 -0
- package/dist/esm/src/utils/theme.js +1 -0
- package/dist/esm/src/utils/unit.js +1 -0
- package/dist/esm/src/utils/var.js +1 -0
- package/package.json +18 -17
- package/index.js +0 -1
- package/src/defaultConfig/animation.js +0 -3
- package/src/defaultConfig/cases.js +0 -3
- package/src/defaultConfig/class.js +0 -6
- package/src/defaultConfig/color.js +0 -9
- package/src/defaultConfig/document.js +0 -3
- package/src/defaultConfig/font-family.js +0 -15
- package/src/defaultConfig/font.js +0 -12
- package/src/defaultConfig/grid.js +0 -5
- package/src/defaultConfig/icons.js +0 -4
- package/src/defaultConfig/index.js +0 -24
- package/src/defaultConfig/media.js +0 -10
- package/src/defaultConfig/responsive.js +0 -29
- package/src/defaultConfig/sequence.js +0 -24
- package/src/defaultConfig/shadow.js +0 -3
- package/src/defaultConfig/spacing.js +0 -19
- package/src/defaultConfig/svg.js +0 -4
- package/src/defaultConfig/templates.js +0 -3
- package/src/defaultConfig/theme.js +0 -13
- package/src/defaultConfig/timing.js +0 -18
- package/src/defaultConfig/typography.js +0 -22
- package/src/defaultConfig/unit.js +0 -5
- package/src/factory.js +0 -135
- package/src/index.js +0 -24
- package/src/set.js +0 -353
- package/src/system/color.js +0 -327
- package/src/system/document.js +0 -16
- package/src/system/font.js +0 -66
- package/src/system/index.js +0 -12
- package/src/system/reset.js +0 -119
- package/src/system/shadow.js +0 -107
- package/src/system/spacing.js +0 -152
- package/src/system/svg.js +0 -132
- package/src/system/theme.js +0 -454
- package/src/system/timing.js +0 -32
- package/src/system/typography.js +0 -110
- package/src/tests/index.js +0 -4
- package/src/transforms/index.js +0 -270
- package/src/utils/color.js +0 -269
- package/src/utils/font.js +0 -116
- package/src/utils/index.js +0 -9
- package/src/utils/sequence.js +0 -386
- package/src/utils/sprite.js +0 -107
- package/src/utils/theme.js +0 -8
- package/src/utils/unit.js +0 -72
- package/src/utils/var.js +0 -129
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import{merge as p}from"@symbo.ls/utils";import{getActiveConfig as r}from"../factory.js";import{applyMediaSequenceVars as h,applySequenceVars as N,findHeadings as b,generateSequence as u,getSequenceValuePropertyPair as w}from"../utils/index.js";const M=e=>{const n=r(),{typography:s,media:c}=n;for(const a in e){const o=a.slice(0,1)==="@",t=e[a];if(!o)continue;const{mediaRegenerate:i}=e,m=a.slice(1),{type:d,base:y,ratio:S,range:f,subSequence:v,h1Matches:P,unit:g}=e;p(t,{type:d,base:y,ratio:S,range:f,subSequence:v,h1Matches:P,unit:g});const q=new Set(["vw","vh","vmin","vmax","svw","svh","lvw","lvh","dvw","dvh"]),H=t.unit||g,I=!t.unit&&q.has(g)?"rem":H,l=c[m],G="@media "+(l==="print"?`${l}`:`screen and ${l}`);if(s.templates[G]={fontSize:t.base/s.browserDefault+I},!i){p(t,{sequence:{},scales:{},vars:{}}),u(t),h(e,a);continue}p(t,{sequence:{},scales:{},templates:{},vars:{}}),u(t),h(e,a)}},V=e=>{const n=r();if(e.h1Matches){const s=e.unit,c=b(e),{templates:a}=e;for(const o in c){const t=`h${parseInt(o)+1}`,i=a[t];a[t]={fontSize:n.useVariable?`var(${c[o]?.variable})`:`${c[o]?.scaling}${s}`,margin:i?i.margin:0,lineHeight:i?i.lineHeight:e.lineHeight,letterSpacing:i?i.letterSpacing:e.letterSpacing,fontWeight:i?i.fontWeight:900-o*100}}}},D=()=>{const e=r(),{typography:n}=e;u(n),V(n),N(n),M(n)},E=e=>{const n=r(),{typography:s}=n;return w(e,"fontSize",s)};export{V as applyHeadings,D as applyTypographySequence,E as getFontSizeByKey,M as runThroughMedia};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
const A=(o,t)=>{},c=(o,t)=>{};export{A as testWCAGAA,c as testWCAGAAA};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import{isString as a,isObject as R,exec as O}from"@symbo.ls/utils";import{getActiveConfig as T}from"../factory.js";import{getSpacingByKey as p,getColor as m,getShadow as b,getMediaColor as g,getTimingByKey as h,getTimingFunction as j,getSpacingBasedOnRatio as B,checkIfBoxSize as E,splitSpacedValue as z}from"../system/index.js";import{getFnPrefixAndValue as I,isResolvedColor as d,isCSSVar as l,CSS_NATIVE_COLOR_REGEX as x,splitTopLevelCommas as C,parseColorToken as $}from"../utils/index.js";const A=new Set(["none","hidden","dotted","dashed","solid","double","groove","ridge","inset","outset","initial"]),G=new Set(["to","top","bottom","left","right","center","at","circle","ellipse","closest-side","farthest-side","closest-corner","farthest-corner"]),_=r=>A.has(r),y=r=>{const e=r+"";if(x.test(e))return e;const n=e.trim();return n==="none"||n==="0"||n==="initial"||n==="inherit"||n==="unset"?e:e.split(/\s+/).map(i=>{if(i=i.trim(),!i)return"";if(l(i))return`var(${i})`;if(_(i)||/^\d/.test(i)||i==="0")return i;const s=m(i);if(d(s))return s;const u=p(i,"border");return u&&u.border?u.border:i}).join(" ")},P=r=>x.test(r)?r:r.split(/\s+/).map(e=>{if(e=e.trim(),!e)return"";if(l(e))return`var(${e})`;if(/^\d/.test(e)||e.includes("px")||e==="0")return e;const n=m(e);return d(n)?n:e}).join(" "),Y=(r,e)=>b(r,e),M=(r,e)=>x.test(r)?r:C(r).map(n=>(n=n.trim(),n?n.split(/\s+/).map(t=>{if(t=t.trim(),!t)return"";if(l(t))return`var(${t})`;if(t==="inset"||t==="none")return t;const i=m(t);if(d(i)){const u=g(t,e);return R(u)?Object.values(u).filter(f=>f.includes(": "+e))[0]:u}if(/^\d/.test(t)||t==="0"||t.includes("px")||t.slice(-2)==="em")return t;const s=p(t,"shadow");return s&&s.shadow?s.shadow:t}).join(" "):"")).join(", "),D=(r,e)=>{const n=r.indexOf("(");if(n===-1)return r;const t=r.slice(0,n+1),i=r.slice(n+1,r.lastIndexOf(")")),s=")",f=C(i).map(c=>(c=c.trim(),c.split(/\s+/).map(o=>{if(!o||/^\d/.test(o)||o==="0"||G.has(o)||o==="transparent"||x.test(o))return o;const S=m(o);return d(S)?S:o}).join(" ")));return t+f.join(", ")+s},X=(r,e)=>{const n=T();return r.split(", ").map(t=>l(t)?`var(${t})`:t.includes("url")?t:t.includes("gradient")?D(t,e):n.gradient[r]?{backgroundImage:g(r,e||n.globalTheme)}:t.includes("/")||t.startsWith("http")||t.includes(".")&&!$(t)?`url(${t})`:t).join(" ")},H=r=>a(r)&&r.split(" ").map(e=>p(e,"gap").gap).join(" "),V=r=>{const e=r.split(" ");return e.length?e.map(n=>l(n)?`var(${n})`:n.length<3||n.includes("ms")?h(n).timing||n:j(n)?j(n):n).join(" "):r},J=(r,e,n)=>{if(a(r))return r.split(",").map(t=>h(t).timing||t).join(",")},N=r=>{const e=r.split(",");if(e.length)return e.map(V).join(",")};function W(r,e,n={},t={}){let i=O.call(this,e||n[r]);if(i==null)return;let s;if(a(i)){if(i.includes("(")){const c=I(i);s=c[0],i=c[1]}const u=n.scaleBoxSize,f=E(r);!u&&f&&!t.ratio&&(i=z(i))}return t.ratio?B(n,r,i,s):p(i,r,void 0,s)}const Q=(r,e=null,n)=>W(r,e,n,{ratio:!0}),U=(r,e,n)=>{if(a(r))return{borderRadius:r.split(" ").map((t,i)=>B(e,n,t)[n]).join(" ")}};export{D as resolveColorsInGradient,N as splitTransition,X as transformBackgroundImage,y as transformBorder,U as transformBorderRadius,M as transformBoxShadow,J as transformDuration,Y as transformShadow,W as transformSize,Q as transformSizeRatio,P as transformTextStroke,V as transformTransition,H as transfromGap};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import{document as a,window as h,isString as c,isNumber as x,isNotProduction as d}from"@symbo.ls/utils";const p=t=>{if(t==="")return[0,0,0,0];if(t.toLowerCase()==="transparent")return[0,0,0,0];if(t[0]==="#")return t.length<7&&(t="#"+t[1]+t[1]+t[2]+t[2]+t[3]+t[3]+(t.length>4?t[4]+t[4]:"")),[parseInt(t.substr(1,2),16),parseInt(t.substr(3,2),16),parseInt(t.substr(5,2),16),t.length>7?parseInt(t.substr(7,2),16)/255:1];if(t.indexOf("rgb")===-1&&a&&h){const e=a.body.appendChild(a.createElement("fictum")),r="rgb(1, 2, 3)";if(e.style.color=r,e.style.color!==r){a.body.removeChild(e);return}if(e.style.color=t,e.style.color===r||e.style.color==="")return a.body.removeChild(e),[0,0,0,0];t=h.getComputedStyle(e).color,a.body.removeChild(e)}return t.indexOf("rgb")===0?(t.indexOf("rgba")===-1&&(t=`${t}, 1`),t.match(/[\.\d]+/g).map(e=>+e)):[0,0,0,0]},O=(t,e,r=.5)=>(t=p(t),e=p(e),T(t,e,r)),E=(t,e=1)=>{const[r,s,n]=t.match(/\w\w/g).map(i=>parseInt(i,16));return`rgb(${r},${s},${n})`},m=(t,e=1)=>{const[r,s,n]=t.match(/\w\w/g).map(i=>parseInt(i,16));return[r,s,n]},L=(t,e,r)=>"#"+(1<<24|t<<16|e<<8|r).toString(16).slice(1),b=([t,e,r])=>((1<<24)+(t<<16)+(e<<8)+r).toString(16).slice(1),F=(t,e=1)=>{const[r,s,n]=t.match(/\w\w/g).map(i=>parseInt(i,16));return`rgba(${r},${s},${n},${e})`},_=(t,e,r=.5)=>{const s=[];for(let n=0;n<3;n++)s[n]=~~(t[n]+(e[n]-t[n])*r);return`rgb(${s})`},A=(t,e)=>{const[r,s,n]=e,i=Math.max(0,Math.min(100,n+parseFloat(t)));return[r,s,i]},l=(t,e,r)=>{const s=Math.max(t,e,r),n=s-Math.min(t,e,r),i=1-Math.abs(s+s-n-1),o=n&&(s==t?(e-r)/n:s==e?2+(r-t)/n:4+(t-e)/n);return[60*(o<0?o+6:o),i?n/i:0,(s+s-n)/2]},w=(t,e,r,s=e*Math.min(r,1-r),n=(i,o=(i+t/30)%12)=>r-s*Math.max(Math.min(o-3,9-o,1),-1))=>[n(0),n(8),n(4)],C=(t,e)=>{const r=parseInt(t,16);let s=(r>>16)+e;s>255?s=255:s<0&&(s=0);let n=(r>>8&255)+e;n>255?n=255:n<0&&(n=0);let i=(r&255)+e;return i>255?i=255:i<0&&(i=0),((i|n<<8|s<<16)+16777216).toString(16).slice(1)},T=(t,e,r=.5)=>{const s=[];for(let n=0;n<4;n++){const i=n===3?o=>o:Math.round;s[n]=i(t[n]+(e[n]-t[n])*r)}return`rgba(${s})`},H=(t,e)=>{const r=p(t);if(!r){d()&&console.warn(t+" color is not rgba");return}return r[3]=e,`rgba(${r})`},R=t=>t.charCodeAt(0)===45&&t.charCodeAt(1)===45,y=/(?:rgba?\(|hsla?\(|#[0-9a-fA-F]{3,8}\b)/,S=/^([a-zA-Z]\w*)(?:\.(\d+))?(?:([+-]\d+|=\d+))?$/,N=t=>{if(!c(t))return null;if(y.test(t))return{passthrough:t};if(R(t))return{cssVar:t};const e=t.match(S);if(!e)return null;const[,r,s,n]=e,i=s!==void 0?`0.${s}`:void 0,o=n&&n[0]==="="?n.slice(1):n;return{name:r,alpha:i,tone:o}},V=t=>c(t)&&(t.includes("rgb")||t.includes("var(")||t.includes("#")),j=t=>{const e=[];let r="",s=0;for(const n of t){if(n==="("?s+=1:n===")"&&s>0&&(s-=1),n===","&&s===0){e.push(r),r="";continue}r+=n}return(r.length||!e.length)&&e.push(r),e},G=(t,e)=>{c(t)&&t.includes("rgb")&&(t=p(t).join(", ")),c(t)&&(t=t.split(",").map(n=>parseFloat(n.trim()))),x(e)&&(e+="");const r=b(t),s=e.slice(0,1);if(s==="-"||s==="+"){const n=C(r,parseFloat(e));return m(n).join(", ")}else{const[n,i,o]=t,u=l(n,i,o),[f,g,$]=u;return w(f,g,parseFloat(e)/100*255)}};export{y as CSS_NATIVE_COLOR_REGEX,A as changeLightness,p as colorStringToRgbaArray,C as getColorShade,G as getRgbTone,E as hexToRgb,m as hexToRgbArray,F as hexToRgba,w as hslToRgb,R as isCSSVar,V as isResolvedColor,O as mixTwoColors,_ as mixTwoRgb,T as mixTwoRgba,H as opacify,N as parseColorToken,b as rgbArrayToHex,l as rgbToHSL,L as rgbToHex,j as splitTopLevelCommas};
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
const c=(t,r)=>{if(!t||!r)return null;try{return new URL(t),null}catch{}const n=r[t];return n?n.content&&n.content.src:null},k=(t,r)=>{if(t[r])return t[r].value;if(t.default)return t[t.default].value;const n=Object.keys(t)[0];return n&&t[n]&&t[n].value},$=t=>{if(typeof t!="string"||!t)return null;const r=t.split(/[#?]/)[0].split(".").pop().trim();return["woff2","woff","ttf","otf","eot"].includes(r)?r:null},S=t=>t&&(t.includes("fonts.googleapis.com")||t.includes("fonts.gstatic.com")),x=t=>`@import url('${t}');`,d=t=>`@font-face { ${t} }`,y=(t,r,n,o={})=>{const l=(Array.isArray(r)?r:[r]).filter(s=>typeof s=="string"&&s).map(s=>{const f=$(s),u=f?` format('${f}')`:"";return`url('${s}')${u}`}).join(`,
|
|
2
|
+
`);return`
|
|
3
|
+
font-family: '${t}';
|
|
4
|
+
font-style: ${o.fontStyle||"normal"};${n?`
|
|
5
|
+
font-weight: ${n};`:""}${o.fontStretch?`
|
|
6
|
+
font-stretch: ${o.fontStretch};`:""}${o.fontDisplay?`
|
|
7
|
+
font-display: ${o.fontDisplay};`:""}
|
|
8
|
+
src: ${l};`},i=(t,r,n,o)=>`@font-face {${y(t,r,n,o)}
|
|
9
|
+
}`,m=(t,r,n)=>Object.keys(r).map(a=>{const{url:e,fontWeight:l,fontStyle:s,fontDisplay:f,fontStretch:u}=r[a],F=Array.isArray(e)?e.map(p=>c(p,n)||p):c(e,n)||e;return y(t,F,l,{fontStyle:s,fontDisplay:f,fontStretch:u})}),v=t=>Object.keys(t).map(n=>m(n,t[n].value)),D=(t,r,n)=>{if(r&&r.isVariable){const e=c(r.url,n)||r.url;return S(e)?x(e):i(t,e,r.fontWeight,{fontStretch:r.fontStretch,fontDisplay:r.fontDisplay||"swap"})}if(r[0])return m(t,r,n).map(d);const a=Array.isArray(r.url)?r.url.map(e=>c(e,n)||e):c(r.url,n)||r.url;return i(t,a,r.fontWeight,{fontStyle:r.fontStyle,fontDisplay:r.fontDisplay,fontStretch:r.fontStretch})},U=(t,r)=>Object.keys(t).map(o=>D(o,t[o].value,r));export{k as getDefaultOrFirstKey,v as getFontFace,m as getFontFaceEach,D as getFontFaceEachString,U as getFontFaceString,$ as getFontFormat,S as isGoogleFontsUrl,c as resolveFileUrl,y as setCustomFont,i as setCustomFontMedia,x as setFontImport,d as setInCustomFontMedia};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export*from"./unit.js";export*from"./color.js";export*from"./theme.js";export*from"./font.js";export*from"./sequence.js";export*from"./var.js";export*from"./sprite.js";
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import{isString as w}from"@symbo.ls/utils";import{toDashCase as K}from"@symbo.ls/utils";import{getActiveConfig as y}from"../factory.js";import{CSS_UNITS as N,isScalingUnit as R}from"./unit.js";import{isCSSVar as T}from"./color.js";const S={"-6":"U","-5":"V","-4":"W","-3":"X","-2":"Y","-1":"Z",0:"A",1:"B",2:"C",3:"D",4:"E",5:"F",6:"G",7:"H",8:"I",9:"J",10:"K",11:"L",12:"M",13:"N",14:"O",15:"P",16:"Q",17:"R",18:"S",19:"T"},M=(t,n)=>{const{key:r,variable:s,value:c,scaling:e,index:o,scalingVariable:p}=t;n.sequence[r]={key:r,decimal:~~(c*100)/100,val:~~c,scaling:e,index:o,scalingVariable:p,variable:s},n.scales[r]=e;const a=A.has(n.unit)?"rem":n.unit;n.vars[s]=e+a},_=t=>{if(!t.includes("("))return t;const n=t.split("(")[0],r=t.slice(t.indexOf("(")+1,t.lastIndexOf(")"));return[n,r]},A=new Set(["vw","vh","vmin","vmax","svw","svh","lvw","lvh","dvw","dvh"]),I=(t,n)=>{const{base:r,type:s,unit:c}=n,e=A.has(c)?"rem":c,o=(R(e)?1:r)+e;if(t===0)return o;const a="--"+(n.varPrefix?n.varPrefix+"-":"")+(s&&s.replace(".","-")),u=`${a}-ratio`;if(t>0){const l=S[t-1];return`calc(var(${a}-${l}) * var(${u}))`}if(t<0){const l=S[t+1],$=Math.abs(t),h=Math.pow(C,2*$),x=S[$];return x?`max(calc(var(${a}-${l}) / var(${u})), calc(var(${a}-${x}) / ${h.toFixed(4)}))`:`calc(var(${a}-${l}) / var(${u}))`}},F=(t,n,r,s)=>{const{type:c}=s,o=t===2&&n.length===2?t+1:t,u=`${"--"+(s.varPrefix?s.varPrefix+"-":"")+(c&&c.replace(".","-"))}-sub-ratio-`;return`calc(var(${r}) * var(${u+o}))`},L=(t,n)=>{const s=(t*n-t)/1.618,c=t*n-s,e=t+s,o=(c+e)/2;return[c,o,e]},Z=(t,n)=>L(t,n).map(r=>r/t),O=(t,n)=>{const{key:r,base:s,value:c,ratio:e,variable:o,index:p}=t,u=~~(c*e)-~~c;let l;const[$,h,x]=L(c,e);u>16?l=[$,h,x]:l=[$,x],l.forEach((d,i)=>{const g=~~(d/s*1e3)/1e3,m=o+(i+1),V=p+(i+1)/10,f=F(i+1,l,o,n),b={key:r+(i+1),variable:m,value:d,scaling:g,scalingVariable:f,index:V};M(b,n)})},C=1.618,j=(t,n,r)=>{if(t>=0)return n*Math.pow(r,t);const s=Math.abs(t),c=n*Math.pow(r,t),e=n*Math.pow(r,s)/Math.pow(C,2*s);return Math.max(c,e)},J=t=>{const{type:n,base:r,ratio:s,range:c,subSequence:e}=t,o=Math.abs(c[0])+Math.abs(c[1]),a="--"+(t.varPrefix?t.varPrefix+"-":"")+(n&&n.replace(".","-"))+"-";for(let u=0;u<=o;u++){const l=c[1]-u,$=S[l],h=j(l,r,s),x=~~(h/r*100)/100,d=a+$,i=I(l,t),g={key:$,variable:d,value:h,base:r,scaling:x,scalingVariable:i,ratio:s,index:l};M(g,t),e&&O(g,t)}return t},Q=(t,n=0)=>{const{type:r,base:s,ratio:c,subSequence:e}=t,o=w(n)?n:S[n],p=w(n)?Object.entries(S).find(([,g])=>g===n)?.[0]:n;if(!o)return console.warn(`Position ${n} is out of range in numToLetterMap`),null;const a={sequence:{},scales:{},vars:{},...t},u=s*Math.pow(c,p),l=~~(u/s*100)/100,x="--"+(t.varPrefix?t.varPrefix+"-":"")+(r&&r.replace(".","-"))+"-"+o,d=I(p,t),i={key:o,variable:x,value:u,base:s,scaling:l,scalingVariable:d,ratio:c,index:p};return M(i,a),e&&O(i,a),a},U=(t="A",n)=>{const r=y(),{unit:s}=r;if(w(t)&&T(t))return`var(${t})`;const{sequence:c,unit:e=s.default,useVariable:o}=n,p=/^-?[a-zA-Z]/i,a=p.test(t);if(N.some(f=>t.includes(f))||!a||["none","auto","max-content","min-content","fit-content","inherit","initial","unset","revert","revert-layer"].includes(t))return t;const h=`--${n.varPrefix?n.varPrefix+"-":""}${K(n.type.replace(".","-"))}-`,x=t.toUpperCase(),d=x.slice(0,1)==="-"?"-":"";let i=d?x.slice(1):x,g="";i.includes("_")&&(g="_"+i.split("_")[1].toLowerCase(),i=i.split("_")[0]);const m=f=>p.test(f)?`var(${h}${f}${g})`:f;if(i.includes("+")){const[f,b]=i.split("+"),v=`${m(f)} + ${m(b)}`;return d?`calc((${v}) * -1)`:`calc(${v})`}else if(i.includes("*")){const[f,b]=i.split("*"),v=`${m(f)} * ${m(b)}`;return d?`calc((${v}) * -1)`:`calc(${v})`}else if(i.includes("-")){const[f,b]=i.split("-"),v=`${m(f)} - ${m(b)}`;return d?`calc((${v}) * -1)`:`calc(${v})`}if(!c[i]&&i.length===2&&(r.verbose&&console.warn(i,"- value is not found because `subSequence` is set to false"),i=i.slice(0,1)),o||r.useVariable){const f=`var(${h}${i}${g})`;return d?`calc(${f} * -1)`:f}const V=c?c[i]:null;return V?e==="ms"||e==="s"?d+V.val+e:d+V.scaling+e:console.warn("can't find",c,i)},D=(t,n)=>{if(!["+","-","*","/",","].filter(e=>t.includes(e+" ")).length)return t;const s=/(\s*[+\-*/,]\s*)/;return t.split(s).map(e=>{const o=e.trim();return!o||["+","-","*","/",","].includes(o)?e:U(o,n)}).join("")},X=(t,n,r,s)=>{if(typeof t!="string")return y().verbose&&console.warn(n,t,"is not a string"),{[n]:t};if(t==="-"||t==="")return{};if(!s&&t.includes("(")){const e=_(t);s=e[0],t=e[1]}return["+","-","*","/",","].filter(e=>t.includes(e+" ")).length?t=D(t,r):t=U(t,r),{[n]:s?`${s}(${t})`:t}},W=(t,n)=>S[t-n],Y=t=>{const{h1Matches:n,sequence:r}=t;return new Array(6).fill(null).map((s,c)=>{const e=W(n,c);return r[e]})};export{W as findHeadingLetter,Y as findHeadings,J as generateSequence,Q as generateSequencePosition,O as generateSubSequence,_ as getFnPrefixAndValue,U as getSequenceValue,D as getSequenceValueBySymbols,X as getSequenceValuePropertyPair,Z as getSubratio,L as getSubratioDifference,S as numToLetterMap,I as setScalingVar,F as setSubScalingVar};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import{isNotProduction as p,isString as a}from"@symbo.ls/utils";import{getActiveConfig as g}from"../factory.js";const u=p(),S=e=>{const r=g();let t="";for(const o in e)r.__svgCache[o]||(r.__svgCache[o]=!0,t+=e[o]);return t},$=e=>{const r=e&&(e.default||e);if(!a(r))return u&&console.warn("parseRootAttributes:",r,"is not a string"),{};const t=r.match(/<svg\s+(.*?)>/);if(!t||!t[1])return{};const c=t[1].match(/(\S+)=["']?((?:.(?!["']?\s+(?:\S+)=|\s*\/?[>"']))+.)["']?/gm);return c?c.reduce((s,i)=>{const[l,n]=i.split("=");return s[l]=n.replace(/['"]/g,""),s},{}):{}},d=(e,r)=>{const t=[];if(e.replace(/id="([^"]*)"/g,(c,s)=>(t.push(s),c)),!t.length)return e;let o=e;for(const c of t){const s=c.replace(/[.*+?^${}()|[\]\\]/g,"\\$&"),i=`${r}-${c}`;o=o.replace(new RegExp(`id="${s}"`,"g"),`id="${i}"`).replace(new RegExp(`url\\(#${s}\\)`,"g"),`url(#${i})`).replace(new RegExp(`xlink:href="#${s}"`,"g"),`xlink:href="#${i}"`).replace(new RegExp(`href="#${s}"`,"g"),`href="#${i}"`)}return o},C=(e,r)=>{const t=$(r),{width:o,height:c}=t,s=t.viewBox||`0 0 ${o||24} ${c||24}`;let n=d(r,e).replace("<svg",`<symbol id="${e}" xmlns="http://www.w3.org/2000/svg" viewBox="${s}"`);return n=n.replace(/width="[^"]*"/,""),n=n.replace(/height="[^"]*"/,""),n=n.replace("</svg","</symbol"),n=x(n),n},f="line|circle|ellipse|rect|polyline|polygon|path|stop|use|image",h=new RegExp(`<(${f})\\b([^>]*?)\\s*/>`,"g"),x=e=>e.replace(h,"<$1$2></$1>");export{C as convertSvgToSymbol,S as generateSprite};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
const u=(e,t)=>{if(e)return e.themes&&e.themes[t]?e.themes[t]:e[t]?[e,e[t]]:e};export{u as returnSubThemeOrDefault};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
const m=c=>c==="em"||c==="rem"||c==="vw"||c==="vh"||c==="vmax"||c==="vmin",v=["px","cm","mm","in","pt","pc","em","rem","ex","cap","ch","ic","lh","rlh","%","vw","vh","vmin","vmax","svw","svh","lvw","lvh","dvw","dvh","cqw","cqh","cqi","cqb","cqmin","cqmax","deg","rad","grad","turn","s","ms","dpi","dpcm","dppx","fr","auto"];export{v as CSS_UNITS,m as isScalingUnit};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import{isObjectLike as _}from"@symbo.ls/utils";import{getActiveConfig as y}from"../factory.js";import{getSubratio as g}from"./sequence.js";import{isScalingUnit as w}from"./unit.js";const G=(e,i)=>{const m=y(),{cssVars:c}=m;_(e.value)||(c[e.var]=e.value)},I=(e,i,m)=>{const c=y(),{unit:p}=c,o=i.unit||p.default,{base:n,ratio:s,type:l}=i,t="--"+(i.varPrefix?i.varPrefix+"-":"")+(l&&l.replace(".","-"));e[`${t}-base`]=n,e[`${t}-unit`]=o;const d=`${t}-ratio`;e[d]=s;const[a,v,r]=g(n,s);e[`${t}-sub-ratio-1`]=`calc(var(${t}-ratio) * ${a/s})`,e[`${t}-sub-ratio-2`]=`calc(var(${t}-ratio) * ${v/s})`,e[`${t}-sub-ratio-3`]=`calc(var(${t}-ratio) * ${r/s})`},N=new Set(["vw","vh","vmin","vmax","svw","svh","lvw","lvh","dvw","dvh"]),M=(e,i={})=>{const m=y(),{unit:c,timing:p,cssVars:o}=m,n=e.unit||c.default,s=N.has(n)?"rem":n,{mediaRegenerate:l,sequence:f,scales:t}=e;l||I(o,e,i);for(const d in f){const a=f[d],v=(e.type===p.type?f[d].val:t[d])+s;if(!l){o[a.variable+"_default"]=v,o[a.variable]=a.scalingVariable;continue}i.useDefault===!1?o[a.variable]=v:(o[a.variable+"_default"]=v,o[a.variable]=`var(${a.variable+"_default"})`)}},k=(e,i,m={})=>{const c=y(),{unit:p,media:o,cssVars:n}=c,s=i.slice(1),l=e[i],f=l.unit||e.unit||p.default,t=N.has(f)?"rem":f,{mediaRegenerate:d}=e,{sequence:a,scales:v}=l,r=o[s];if(!r&&c.verbose&&console.warn("Can't find media query ",r),!d){let u=n[`@media ${r}`];u||(u=n[`@media ${r}`]={}),I(u,l,m);const $=e.unit||p.default;if(t!==$&&a)for(const S in a){const b=a[S],V=v[S]+t;u[b.variable+"_default"]=V,u[b.variable]=V}return}for(const u in a){const $=a[u],S=(w(t)?v[u]:a[u].val)+t;!r&&c.verbose&&console.warn("Can't find query ",r);let b=n[`@media ${r}`];b||(b=n[`@media ${r}`]={}),b[$.variable]=`var(${$.variable+"_"+s})`,n[$.variable+"_"+s]=S}};export{k as applyMediaSequenceVars,I as applySequenceGlobalVars,M as applySequenceVars,G as setVariables};
|
package/package.json
CHANGED
|
@@ -2,39 +2,40 @@
|
|
|
2
2
|
"name": "@symbo.ls/scratch",
|
|
3
3
|
"description": "Φ / CSS framework and methodology.",
|
|
4
4
|
"author": "symbo.ls",
|
|
5
|
-
"version": "3.14.
|
|
5
|
+
"version": "3.14.4",
|
|
6
6
|
"files": [
|
|
7
7
|
"dist",
|
|
8
|
-
"*.
|
|
9
|
-
"
|
|
8
|
+
"*.md",
|
|
9
|
+
"LICENSE"
|
|
10
10
|
],
|
|
11
11
|
"repository": "https://github.com/symbo-ls/smbls",
|
|
12
12
|
"type": "module",
|
|
13
|
-
"module": "./index.js",
|
|
14
|
-
"
|
|
15
|
-
"jsdelivr": "./dist/iife/index.js",
|
|
16
|
-
"main": "./index.js",
|
|
13
|
+
"module": "./dist/esm/index.js",
|
|
14
|
+
"main": "./dist/cjs/index.js",
|
|
17
15
|
"exports": {
|
|
18
|
-
".":
|
|
16
|
+
".": {
|
|
17
|
+
"development": "./index.js",
|
|
18
|
+
"import": "./dist/esm/index.js",
|
|
19
|
+
"require": "./dist/cjs/index.js",
|
|
20
|
+
"default": "./dist/esm/index.js"
|
|
21
|
+
},
|
|
19
22
|
"./package.json": "./package.json"
|
|
20
23
|
},
|
|
21
24
|
"source": "src/index.js",
|
|
22
25
|
"publishConfig": {
|
|
23
|
-
"access": "
|
|
26
|
+
"access": "restricted"
|
|
24
27
|
},
|
|
25
28
|
"scripts": {
|
|
26
|
-
"
|
|
27
|
-
"build:
|
|
28
|
-
"build
|
|
29
|
-
"
|
|
30
|
-
"build": "node ../../build/build.js",
|
|
31
|
-
"prepublish": "npm run build && npm run copy:package:cjs"
|
|
29
|
+
"build:esm": "esbuild $(find . -type f -name \"*.js\" -not -path \"*/dist/*\" -not -path \"*/node_modules/*\" -not -path \"*/__tests__/*\" -not -path \"*/test/*\" -not -path \"*/demo/*\" -not -path \"*/demos/*\" -not -path \"*/examples/*\" -not -path \"*/fixtures/*\" -not -name \"*.test.js\") --target=es2022 --format=esm --outbase=. --outdir=dist/esm --minify --log-level=warning",
|
|
30
|
+
"build:cjs": "esbuild $(find . -type f -name \"*.js\" -not -path \"*/dist/*\" -not -path \"*/node_modules/*\" -not -path \"*/__tests__/*\" -not -path \"*/test/*\" -not -path \"*/demo/*\" -not -path \"*/demos/*\" -not -path \"*/examples/*\" -not -path \"*/fixtures/*\" -not -name \"*.test.js\") --target=node20 --format=cjs --outbase=. --outdir=dist/cjs --minify --log-level=warning",
|
|
31
|
+
"build": "rimraf dist && npm run build:esm && npm run build:cjs && node -e \"require('fs').writeFileSync('dist/cjs/package.json', '{\\\"type\\\": \\\"commonjs\\\"}')\"",
|
|
32
|
+
"prepublishOnly": "npm run build"
|
|
32
33
|
},
|
|
33
34
|
"dependencies": {
|
|
34
|
-
"@symbo.ls/utils": "^3.14.
|
|
35
|
+
"@symbo.ls/utils": "^3.14.5",
|
|
35
36
|
"color-contrast-checker": "^1.5.0"
|
|
36
37
|
},
|
|
37
38
|
"gitHead": "9fc1b79b41cdc725ca6b24aec64920a599634681",
|
|
38
|
-
"browser": "./index.js",
|
|
39
|
+
"browser": "./dist/esm/index.js",
|
|
39
40
|
"sideEffects": true
|
|
40
41
|
}
|
package/index.js
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export * from './src/index.js'
|
|
@@ -1,15 +0,0 @@
|
|
|
1
|
-
'use strict'
|
|
2
|
-
|
|
3
|
-
var defaultFont = { // eslint-disable-line
|
|
4
|
-
name: '',
|
|
5
|
-
family: '',
|
|
6
|
-
type: ''
|
|
7
|
-
}
|
|
8
|
-
|
|
9
|
-
export const fontFamily = {}
|
|
10
|
-
export const fontFamilyTypes = {
|
|
11
|
-
'sans-serif': 'Helvetica, Arial, sans-serif, --system-default',
|
|
12
|
-
serif: 'Times New Roman, Georgia, serif, --system-default',
|
|
13
|
-
monospace: 'Courier New, monospace, --system-default'
|
|
14
|
-
}
|
|
15
|
-
export const fontFace = {}
|
|
@@ -1,24 +0,0 @@
|
|
|
1
|
-
'use strict'
|
|
2
|
-
|
|
3
|
-
export * from './sequence.js'
|
|
4
|
-
export * from './unit.js'
|
|
5
|
-
export * from './typography.js'
|
|
6
|
-
export * from './font.js'
|
|
7
|
-
export * from './font-family.js'
|
|
8
|
-
export * from './media.js'
|
|
9
|
-
export * from './spacing.js'
|
|
10
|
-
export * from './color.js'
|
|
11
|
-
export * from './theme.js'
|
|
12
|
-
export * from './shadow.js'
|
|
13
|
-
export * from './icons.js'
|
|
14
|
-
export * from './timing.js'
|
|
15
|
-
export * from './document.js'
|
|
16
|
-
export * from './responsive.js'
|
|
17
|
-
export * from './animation.js'
|
|
18
|
-
export * from './svg.js'
|
|
19
|
-
export * from './templates.js'
|
|
20
|
-
export * from './grid.js'
|
|
21
|
-
export * from './class.js'
|
|
22
|
-
|
|
23
|
-
export const reset = {}
|
|
24
|
-
export const vars = {}
|
|
@@ -1,29 +0,0 @@
|
|
|
1
|
-
'use strict'
|
|
2
|
-
|
|
3
|
-
export const breakpoints = {
|
|
4
|
-
screenL: 1920,
|
|
5
|
-
screenM: 1680,
|
|
6
|
-
screenS: 1440,
|
|
7
|
-
tabletL: 1366,
|
|
8
|
-
tabletM: 1280,
|
|
9
|
-
tabletS: 1024,
|
|
10
|
-
mobileL: 768,
|
|
11
|
-
mobileM: 560,
|
|
12
|
-
mobileS: 480,
|
|
13
|
-
mobileXS: 375
|
|
14
|
-
}
|
|
15
|
-
|
|
16
|
-
export const devices = {
|
|
17
|
-
screenXXL: [2560, 1440],
|
|
18
|
-
screenXL: [2240, 1260],
|
|
19
|
-
screenL: [1920, 1024],
|
|
20
|
-
screenM: [1680, 1024],
|
|
21
|
-
screenS: [1440, 720],
|
|
22
|
-
tabletL: [1366, 926],
|
|
23
|
-
tabletM: [1280, 768],
|
|
24
|
-
tabletS: [1024, 768],
|
|
25
|
-
mobileL: [768, 375],
|
|
26
|
-
mobileM: [560, 768],
|
|
27
|
-
mobileS: [480, 768],
|
|
28
|
-
mobileXS: [375, 768]
|
|
29
|
-
}
|
|
@@ -1,24 +0,0 @@
|
|
|
1
|
-
'use strict'
|
|
2
|
-
|
|
3
|
-
export const sequence = {
|
|
4
|
-
'minor-second': 1.067,
|
|
5
|
-
'major-second': 1.125,
|
|
6
|
-
'minor-third': 1.2,
|
|
7
|
-
'major-third': 1.25,
|
|
8
|
-
'perfect-fourth': 1.333,
|
|
9
|
-
'augmented-fourth': 1.414,
|
|
10
|
-
'perfect-fifth': 1.5,
|
|
11
|
-
'minor-sixth': 1.6,
|
|
12
|
-
phi: 1.618, // golden-ratio
|
|
13
|
-
'major-sixth': 1.667,
|
|
14
|
-
'square-root-3': 1.732, // theodorus
|
|
15
|
-
'minor-seventh': 1.778,
|
|
16
|
-
'major-seventh': 1.875,
|
|
17
|
-
octave: 2,
|
|
18
|
-
'square-root-5': 2.23, // pythagoras
|
|
19
|
-
'major-tenth': 2.5,
|
|
20
|
-
'major-eleventh': 2.667,
|
|
21
|
-
'major-twelfth': 3,
|
|
22
|
-
pi: 3.14, // archimedes
|
|
23
|
-
'double-octave': 4
|
|
24
|
-
}
|
|
@@ -1,19 +0,0 @@
|
|
|
1
|
-
'use strict'
|
|
2
|
-
|
|
3
|
-
import { sequence } from './sequence.js'
|
|
4
|
-
import { typography } from './typography.js'
|
|
5
|
-
|
|
6
|
-
const defaultProps = {
|
|
7
|
-
base: typography.base,
|
|
8
|
-
type: 'spacing',
|
|
9
|
-
ratio: sequence.phi,
|
|
10
|
-
range: [-5, +15],
|
|
11
|
-
subSequence: true,
|
|
12
|
-
mediaRegenerate: false,
|
|
13
|
-
unit: 'em',
|
|
14
|
-
sequence: {},
|
|
15
|
-
scales: {},
|
|
16
|
-
vars: {}
|
|
17
|
-
}
|
|
18
|
-
|
|
19
|
-
export const spacing = defaultProps
|
package/src/defaultConfig/svg.js
DELETED
|
@@ -1,13 +0,0 @@
|
|
|
1
|
-
'use strict'
|
|
2
|
-
|
|
3
|
-
const themeA = { // eslint-disable-line no-unused-vars
|
|
4
|
-
text: 'blue',
|
|
5
|
-
background: 'white',
|
|
6
|
-
border: 'black', // .opacity(0.2),
|
|
7
|
-
active: {},
|
|
8
|
-
helpers: [],
|
|
9
|
-
themes: {},
|
|
10
|
-
inverse: {} // schemeAInverse
|
|
11
|
-
}
|
|
12
|
-
|
|
13
|
-
export const theme = {}
|
|
@@ -1,18 +0,0 @@
|
|
|
1
|
-
'use strict'
|
|
2
|
-
|
|
3
|
-
import { sequence } from './sequence.js'
|
|
4
|
-
|
|
5
|
-
const defaultProps = {
|
|
6
|
-
default: 150,
|
|
7
|
-
base: 150,
|
|
8
|
-
type: 'timing',
|
|
9
|
-
ratio: sequence['perfect-fourth'],
|
|
10
|
-
range: [-3, +12],
|
|
11
|
-
mediaRegenerate: false,
|
|
12
|
-
unit: 'ms',
|
|
13
|
-
sequence: {},
|
|
14
|
-
scales: {},
|
|
15
|
-
vars: {}
|
|
16
|
-
}
|
|
17
|
-
|
|
18
|
-
export const timing = defaultProps
|
|
@@ -1,22 +0,0 @@
|
|
|
1
|
-
'use strict'
|
|
2
|
-
|
|
3
|
-
import { sequence } from './sequence.js'
|
|
4
|
-
|
|
5
|
-
const defaultProps = {
|
|
6
|
-
browserDefault: 16,
|
|
7
|
-
base: 16,
|
|
8
|
-
type: 'font-size',
|
|
9
|
-
ratio: sequence['minor-third'],
|
|
10
|
-
range: [-3, +12],
|
|
11
|
-
h1Matches: +6,
|
|
12
|
-
lineHeight: 1.5,
|
|
13
|
-
subSequence: true,
|
|
14
|
-
mediaRegenerate: false,
|
|
15
|
-
unit: 'em',
|
|
16
|
-
templates: {},
|
|
17
|
-
sequence: {},
|
|
18
|
-
scales: {},
|
|
19
|
-
vars: {}
|
|
20
|
-
}
|
|
21
|
-
|
|
22
|
-
export const typography = defaultProps
|
package/src/factory.js
DELETED
|
@@ -1,135 +0,0 @@
|
|
|
1
|
-
'use strict'
|
|
2
|
-
|
|
3
|
-
import {
|
|
4
|
-
deepClone,
|
|
5
|
-
deepMerge,
|
|
6
|
-
isDefined,
|
|
7
|
-
isObject
|
|
8
|
-
} from '@symbo.ls/utils'
|
|
9
|
-
import * as CONF from './defaultConfig/index.js'
|
|
10
|
-
|
|
11
|
-
export const cssVars = {}
|
|
12
|
-
export const cssMediaVars = {}
|
|
13
|
-
|
|
14
|
-
// Build CONFIG with lowercase/camelCase keys as canonical
|
|
15
|
-
const _CONF = CONF
|
|
16
|
-
const _confLower = {}
|
|
17
|
-
export const toCamel = (s) => s.replace(/_([a-z])/g, (_, c) => c.toUpperCase())
|
|
18
|
-
for (const key in _CONF) {
|
|
19
|
-
const lower = key.toLowerCase()
|
|
20
|
-
_confLower[lower] = _CONF[key]
|
|
21
|
-
// camelCase alias (e.g. font_family -> fontFamily, semanticIcons -> semanticIcons)
|
|
22
|
-
const camel = toCamel(lower)
|
|
23
|
-
if (camel !== lower) _confLower[camel] = _CONF[key]
|
|
24
|
-
// keep original key if different from lower
|
|
25
|
-
if (lower !== key) _confLower[key] = _CONF[key]
|
|
26
|
-
}
|
|
27
|
-
|
|
28
|
-
export const CONFIG = {
|
|
29
|
-
verbose: false,
|
|
30
|
-
useVariable: true,
|
|
31
|
-
useReset: true,
|
|
32
|
-
globalTheme: 'auto',
|
|
33
|
-
cssVars,
|
|
34
|
-
cssMediaVars,
|
|
35
|
-
CSS_VARS: cssVars,
|
|
36
|
-
CSS_MEDIA_VARS: cssMediaVars,
|
|
37
|
-
_scratchConfig: true,
|
|
38
|
-
..._confLower
|
|
39
|
-
}
|
|
40
|
-
|
|
41
|
-
const cachedConfig = deepClone(CONFIG)
|
|
42
|
-
|
|
43
|
-
export const FACTORY = {
|
|
44
|
-
active: '0',
|
|
45
|
-
0: CONFIG
|
|
46
|
-
}
|
|
47
|
-
|
|
48
|
-
export const activateConfig = (def) => {
|
|
49
|
-
if (isDefined(def)) { FACTORY.active = def }
|
|
50
|
-
return FACTORY[def || FACTORY.active]
|
|
51
|
-
}
|
|
52
|
-
|
|
53
|
-
// Config stack for context-local resolution
|
|
54
|
-
// When processing an element, its context.designSystem is pushed
|
|
55
|
-
// so all getActiveConfig() calls resolve to the right config
|
|
56
|
-
const configStack = []
|
|
57
|
-
|
|
58
|
-
export const pushConfig = (config) => {
|
|
59
|
-
if (config && config._scratchConfig) configStack.push(config)
|
|
60
|
-
}
|
|
61
|
-
|
|
62
|
-
export const popConfig = () => {
|
|
63
|
-
configStack.pop()
|
|
64
|
-
}
|
|
65
|
-
|
|
66
|
-
export const getActiveConfig = (def) => {
|
|
67
|
-
if (configStack.length) return configStack[configStack.length - 1]
|
|
68
|
-
return FACTORY[def || FACTORY.active] || CONFIG
|
|
69
|
-
}
|
|
70
|
-
|
|
71
|
-
export const setActiveConfig = (newConfig) => {
|
|
72
|
-
if (!isObject(newConfig)) return
|
|
73
|
-
FACTORY.active = '1'
|
|
74
|
-
FACTORY['1'] = deepMerge(newConfig, deepClone(cachedConfig))
|
|
75
|
-
return newConfig
|
|
76
|
-
}
|
|
77
|
-
|
|
78
|
-
// App-level flags that should NOT be inherited by isolated configs
|
|
79
|
-
const APP_FLAGS = [
|
|
80
|
-
'useReset', 'useVariable', 'useFontImport', 'useIconSprite',
|
|
81
|
-
'useSvgSprite', 'useDocumentTheme', 'useDefaultIcons', 'useDefaultConfig',
|
|
82
|
-
'verbose', 'globalTheme'
|
|
83
|
-
]
|
|
84
|
-
|
|
85
|
-
// Keep case-variant aliases pointing to the same object. `factory.js`
|
|
86
|
-
// bootstrap wires these as shared refs, but `deepClone` in `createConfig`
|
|
87
|
-
// breaks the sharing and a later `deepMerge` only writes into one spelling
|
|
88
|
-
// — downstream code that destructures a different spelling then reads
|
|
89
|
-
// stale data (e.g. `applyDocument` reads `fontFamily` while `setValue`
|
|
90
|
-
// writes to `fontfamily`, leaving `DOCUMENT.fontFamily` unset).
|
|
91
|
-
const ALIAS_GROUPS = [
|
|
92
|
-
['fontfamily', 'fontFamily', 'font_family'],
|
|
93
|
-
['fontfamilytypes', 'fontFamilyTypes'],
|
|
94
|
-
['semanticicons', 'semanticIcons'],
|
|
95
|
-
['svgdata', 'svgData']
|
|
96
|
-
]
|
|
97
|
-
const aliasCaseVariants = (cfg) => {
|
|
98
|
-
for (const vs of ALIAS_GROUPS) {
|
|
99
|
-
let merged
|
|
100
|
-
for (const v of vs) {
|
|
101
|
-
const val = cfg[v]
|
|
102
|
-
if (!isObject(val)) continue
|
|
103
|
-
merged = merged ? deepMerge(val, merged) : val
|
|
104
|
-
}
|
|
105
|
-
if (!merged) continue
|
|
106
|
-
for (const v of vs) if (isObject(cfg[v])) cfg[v] = merged
|
|
107
|
-
}
|
|
108
|
-
}
|
|
109
|
-
|
|
110
|
-
export const createConfig = (name, overrides, { cleanBase = false } = {}) => {
|
|
111
|
-
// Secondary apps inheriting the primary app's processed config used to
|
|
112
|
-
// drag primary-specific tokens (e.g. an editor's brand themes like
|
|
113
|
-
// `sepia`, `canvas-card`) into the secondary's design system — breaking
|
|
114
|
-
// iframe isolation. When `cleanBase: true` is passed, clone the initial
|
|
115
|
-
// framework cache instead so the secondary starts from the same blank
|
|
116
|
-
// slate as the primary did. Legacy callers (no option) keep the old
|
|
117
|
-
// active-inherit behavior for backward compatibility.
|
|
118
|
-
const activeBase = cleanBase ? null : getActiveConfig()
|
|
119
|
-
const base = deepClone(
|
|
120
|
-
!cleanBase && activeBase && activeBase._scratchConfig ? activeBase : cachedConfig
|
|
121
|
-
)
|
|
122
|
-
// Remove app-level flags — they must come from overrides explicitly
|
|
123
|
-
for (const flag of APP_FLAGS) {
|
|
124
|
-
delete base[flag]
|
|
125
|
-
}
|
|
126
|
-
const cfg = deepMerge(overrides || {}, base)
|
|
127
|
-
cfg.cssVars = {}
|
|
128
|
-
cfg.cssMediaVars = {}
|
|
129
|
-
cfg.CSS_VARS = cfg.cssVars
|
|
130
|
-
cfg.CSS_MEDIA_VARS = cfg.cssMediaVars
|
|
131
|
-
cfg._scratchConfig = true
|
|
132
|
-
aliasCaseVariants(cfg)
|
|
133
|
-
if (name) FACTORY[name] = cfg
|
|
134
|
-
return cfg
|
|
135
|
-
}
|
package/src/index.js
DELETED
|
@@ -1,24 +0,0 @@
|
|
|
1
|
-
'use strict'
|
|
2
|
-
|
|
3
|
-
// Note on the dual-form imports below: each `./X/index.js` is referenced
|
|
4
|
-
// twice in this file — once as a namespace import, once as a barrel
|
|
5
|
-
// re-export. That dual reference is load-bearing for parcel's optimizer:
|
|
6
|
-
// if a directory is only seen via barrel `export *` here AND via
|
|
7
|
-
// `import * as` in a different file (as factory.js does for
|
|
8
|
-
// ./defaultConfig), parcel collapses the dep-map entry to the bare
|
|
9
|
-
// directory form and marks it `false`, breaking runtime `require` for
|
|
10
|
-
// the explicit `/index.js` path. Keeping the namespace import in this
|
|
11
|
-
// file alongside the barrel forces parcel to track both forms.
|
|
12
|
-
|
|
13
|
-
import * as scratchUtils from './utils/index.js'
|
|
14
|
-
import * as scratchSystem from './system/index.js'
|
|
15
|
-
import * as scratchDefaultConfig from './defaultConfig/index.js'
|
|
16
|
-
|
|
17
|
-
export * from './factory.js'
|
|
18
|
-
export * from './defaultConfig/index.js'
|
|
19
|
-
export * from './system/index.js'
|
|
20
|
-
export * from './utils/index.js'
|
|
21
|
-
export * from './transforms/index.js'
|
|
22
|
-
export * from './set.js'
|
|
23
|
-
|
|
24
|
-
export { scratchUtils, scratchSystem, scratchDefaultConfig }
|