From d9781bb6610dd88e9fcee8591ea073abb1e5702e Mon Sep 17 00:00:00 2001 From: Marius Sarca Date: Tue, 17 Aug 2021 18:21:02 +0300 Subject: [PATCH] Added support for custom selector attribute --- README.md | 2 +- dist/assembler.cjs.js | 29 +++++++++++++++++++++-------- dist/assembler.es.js | 29 +++++++++++++++++++++-------- dist/assembler.js | 29 +++++++++++++++++++++-------- dist/assembler.min.js | 2 +- package.json | 2 +- src/StyleHandler.ts | 21 ++++++++++++++------- src/generators.ts | 7 ++++++- src/helpers.ts | 3 +++ types/StyleHandler.d.ts | 1 + types/helpers.d.ts | 1 + 11 files changed, 91 insertions(+), 35 deletions(-) diff --git a/README.md b/README.md index b2389c1..57bf1f2 100644 --- a/README.md +++ b/README.md @@ -82,7 +82,7 @@ We have conducted intensive manual testing on the following operating systems an - [x] Add support for states - [x] Add support for scopes - [x] Add support for mixins -- [ ] Add support for alternative attribute rules. +- [x] Add support for custom selector attribute - [x] Add support for custom elements - [ ] Add automated tests, so we can make sure we don’t mess up things in future releases - [ ] Cleanup & prepare stable releases diff --git a/dist/assembler.cjs.js b/dist/assembler.cjs.js index 6de9d90..32dec16 100644 --- a/dist/assembler.cjs.js +++ b/dist/assembler.cjs.js @@ -638,6 +638,7 @@ function getUserSettings(dataset) { const generate = dataset.generate === undefined ? false : dataset.generate === 'true'; const constructable = dataset.constructable === undefined ? true : dataset.constructable === 'true'; const desktopFirst = dataset.mode === undefined ? false : dataset.mode === 'desktop-first'; + const selectorAttribute = dataset.selectorAttribute === undefined ? 'class' : dataset.selectorAttribute; const cache = dataset.cache === undefined ? null : dataset.cache; const cacheKey = dataset.cacheKey === undefined ? "assembler-css-cache" : dataset.cacheKey; const dataScopes = dataset.scopes === undefined ? [] : getStringItemList(dataset.scopes); @@ -688,6 +689,7 @@ function getUserSettings(dataset) { breakpoints, media: { xs, sm, md, lg, xl }, xStyleAttribute, + selectorAttribute, }; } function style(item) { @@ -768,6 +770,11 @@ function generateStyles(settings) { const desktopFirst = settings.desktopFirst; const states = settings.states; const tracker = new Set(); + const selectorAttribute = settings.selectorAttribute; + const selectorPfx = selectorAttribute === 'class' + ? '.' + HASH_CLASS_PREFIX + '\\#' + : '[' + selectorAttribute + '~="' + HASH_CLASS_PREFIX + '#'; + const selectorSfx = selectorAttribute === 'class' ? '' : '"]'; result.push(generateRootVariables(settings)); for (let media_index = 0, l = breakpoints.length; media_index < l; media_index++) { const bp = breakpoints[media_index]; @@ -798,7 +805,7 @@ function generateStyles(settings) { prefix += `${variants[i]}:var(${property}) !important;`; } } - str += `.${HASH_CLASS_PREFIX}\\#${hash}${state_index > 0 ? ':' + state : ''}{${prefix}${name}:var(${property}) !important}`; + str += `${selectorPfx + hash + selectorSfx}${state_index > 0 ? ':' + state : ''}{${prefix}${name}:var(${property}) !important}`; } } if (media_index !== 0) { @@ -1073,6 +1080,7 @@ class StyleHandler { this.breakpoints = settings.breakpoints; this.rules = []; this.padding = style.cssRules.length; + this.selectorAttribute = settings.selectorAttribute; } get userSettings() { return this.settings; @@ -1082,7 +1090,7 @@ class StyleHandler { return this.handleStyleRemoved(element, old); } const newEntries = this.getStyleEntries(content); - const classList = element.hasAttribute('class') ? element.getAttribute('class').split(' ') : []; + const classList = element.hasAttribute(this.selectorAttribute) ? element.getAttribute(this.selectorAttribute).split(' ') : []; const assemblerEntries = []; // remove old entries for (const { n: name, p: property, e: entry } of old) { @@ -1106,11 +1114,11 @@ class StyleHandler { element.style.setProperty(property, value); assemblerEntries.push({ e: entry, n: name, p: property }); } - element.setAttribute('class', classList.join(' ')); + element.setAttribute(this.selectorAttribute, classList.join(' ')); return assemblerEntries; } handleStyleRemoved(element, old) { - const classList = element.hasAttribute('class') ? element.getAttribute('class').split(' ') : []; + const classList = element.hasAttribute(this.selectorAttribute) ? element.getAttribute(this.selectorAttribute).split(' ') : []; for (const { p: property, e: entry } of old) { const index = classList.indexOf(entry); if (index >= 0) { @@ -1118,7 +1126,7 @@ class StyleHandler { } element.style.removeProperty(property); } - element.setAttribute('class', classList.join(' ')); + element.setAttribute(this.selectorAttribute, classList.join(' ')); return []; } extract(attr, value = null) { @@ -1238,6 +1246,11 @@ class StyleHandler { const { tracker, mediaSettings, desktopFirst, style } = this; const { hash, media, state, cssProperty, property, scope, rank } = info; const hasMedia = media !== ''; + const selectorAttribute = this.settings.selectorAttribute; + const selectorPfx = selectorAttribute === 'class' + ? '.' + HASH_CLASS_PREFIX + '\\#' + : '[' + selectorAttribute + '~="' + HASH_CLASS_PREFIX + '#'; + const selectorSfx = selectorAttribute === 'class' ? '' : '"]'; tracker.add(hash); if (rank < 0) { return; @@ -1265,7 +1278,7 @@ class StyleHandler { rule += scopeValue.replace(REPLACE_REGEX, (match, p1) => { switch (p1) { case "selector": - return `.${HASH_CLASS_PREFIX}\\#${hash}${state ? ':' + state : ''}`; + return `${selectorPfx + hash + selectorSfx}${state ? ':' + state : ''}`; case "body": return prefix + cssProperty + ': var(' + property + ') !important'; case "variants": @@ -1275,7 +1288,7 @@ class StyleHandler { case "value": return `var(${property})`; case "class": - return `.${HASH_CLASS_PREFIX}\\#${hash}`; + return selectorPfx + hash + selectorSfx; case "state": return state ? ':' + state : ''; case "var": @@ -1285,7 +1298,7 @@ class StyleHandler { }); } else { - rule += `.${HASH_CLASS_PREFIX}\\#${hash}${state ? ':' + state : ''}{${prefix}${cssProperty}: var(${property}) !important}`; + rule += `${selectorPfx + hash + selectorSfx}${state ? ':' + state : ''}{${prefix}${cssProperty}: var(${property}) !important}`; } if (hasMedia) { rule += '}'; diff --git a/dist/assembler.es.js b/dist/assembler.es.js index 97d8403..9ea2797 100644 --- a/dist/assembler.es.js +++ b/dist/assembler.es.js @@ -634,6 +634,7 @@ function getUserSettings(dataset) { const generate = dataset.generate === undefined ? false : dataset.generate === 'true'; const constructable = dataset.constructable === undefined ? true : dataset.constructable === 'true'; const desktopFirst = dataset.mode === undefined ? false : dataset.mode === 'desktop-first'; + const selectorAttribute = dataset.selectorAttribute === undefined ? 'class' : dataset.selectorAttribute; const cache = dataset.cache === undefined ? null : dataset.cache; const cacheKey = dataset.cacheKey === undefined ? "assembler-css-cache" : dataset.cacheKey; const dataScopes = dataset.scopes === undefined ? [] : getStringItemList(dataset.scopes); @@ -684,6 +685,7 @@ function getUserSettings(dataset) { breakpoints, media: { xs, sm, md, lg, xl }, xStyleAttribute, + selectorAttribute, }; } function style(item) { @@ -764,6 +766,11 @@ function generateStyles(settings) { const desktopFirst = settings.desktopFirst; const states = settings.states; const tracker = new Set(); + const selectorAttribute = settings.selectorAttribute; + const selectorPfx = selectorAttribute === 'class' + ? '.' + HASH_CLASS_PREFIX + '\\#' + : '[' + selectorAttribute + '~="' + HASH_CLASS_PREFIX + '#'; + const selectorSfx = selectorAttribute === 'class' ? '' : '"]'; result.push(generateRootVariables(settings)); for (let media_index = 0, l = breakpoints.length; media_index < l; media_index++) { const bp = breakpoints[media_index]; @@ -794,7 +801,7 @@ function generateStyles(settings) { prefix += `${variants[i]}:var(${property}) !important;`; } } - str += `.${HASH_CLASS_PREFIX}\\#${hash}${state_index > 0 ? ':' + state : ''}{${prefix}${name}:var(${property}) !important}`; + str += `${selectorPfx + hash + selectorSfx}${state_index > 0 ? ':' + state : ''}{${prefix}${name}:var(${property}) !important}`; } } if (media_index !== 0) { @@ -1069,6 +1076,7 @@ class StyleHandler { this.breakpoints = settings.breakpoints; this.rules = []; this.padding = style.cssRules.length; + this.selectorAttribute = settings.selectorAttribute; } get userSettings() { return this.settings; @@ -1078,7 +1086,7 @@ class StyleHandler { return this.handleStyleRemoved(element, old); } const newEntries = this.getStyleEntries(content); - const classList = element.hasAttribute('class') ? element.getAttribute('class').split(' ') : []; + const classList = element.hasAttribute(this.selectorAttribute) ? element.getAttribute(this.selectorAttribute).split(' ') : []; const assemblerEntries = []; // remove old entries for (const { n: name, p: property, e: entry } of old) { @@ -1102,11 +1110,11 @@ class StyleHandler { element.style.setProperty(property, value); assemblerEntries.push({ e: entry, n: name, p: property }); } - element.setAttribute('class', classList.join(' ')); + element.setAttribute(this.selectorAttribute, classList.join(' ')); return assemblerEntries; } handleStyleRemoved(element, old) { - const classList = element.hasAttribute('class') ? element.getAttribute('class').split(' ') : []; + const classList = element.hasAttribute(this.selectorAttribute) ? element.getAttribute(this.selectorAttribute).split(' ') : []; for (const { p: property, e: entry } of old) { const index = classList.indexOf(entry); if (index >= 0) { @@ -1114,7 +1122,7 @@ class StyleHandler { } element.style.removeProperty(property); } - element.setAttribute('class', classList.join(' ')); + element.setAttribute(this.selectorAttribute, classList.join(' ')); return []; } extract(attr, value = null) { @@ -1234,6 +1242,11 @@ class StyleHandler { const { tracker, mediaSettings, desktopFirst, style } = this; const { hash, media, state, cssProperty, property, scope, rank } = info; const hasMedia = media !== ''; + const selectorAttribute = this.settings.selectorAttribute; + const selectorPfx = selectorAttribute === 'class' + ? '.' + HASH_CLASS_PREFIX + '\\#' + : '[' + selectorAttribute + '~="' + HASH_CLASS_PREFIX + '#'; + const selectorSfx = selectorAttribute === 'class' ? '' : '"]'; tracker.add(hash); if (rank < 0) { return; @@ -1261,7 +1274,7 @@ class StyleHandler { rule += scopeValue.replace(REPLACE_REGEX, (match, p1) => { switch (p1) { case "selector": - return `.${HASH_CLASS_PREFIX}\\#${hash}${state ? ':' + state : ''}`; + return `${selectorPfx + hash + selectorSfx}${state ? ':' + state : ''}`; case "body": return prefix + cssProperty + ': var(' + property + ') !important'; case "variants": @@ -1271,7 +1284,7 @@ class StyleHandler { case "value": return `var(${property})`; case "class": - return `.${HASH_CLASS_PREFIX}\\#${hash}`; + return selectorPfx + hash + selectorSfx; case "state": return state ? ':' + state : ''; case "var": @@ -1281,7 +1294,7 @@ class StyleHandler { }); } else { - rule += `.${HASH_CLASS_PREFIX}\\#${hash}${state ? ':' + state : ''}{${prefix}${cssProperty}: var(${property}) !important}`; + rule += `${selectorPfx + hash + selectorSfx}${state ? ':' + state : ''}{${prefix}${cssProperty}: var(${property}) !important}`; } if (hasMedia) { rule += '}'; diff --git a/dist/assembler.js b/dist/assembler.js index d8c9ea0..618eed6 100644 --- a/dist/assembler.js +++ b/dist/assembler.js @@ -640,6 +640,7 @@ const generate = dataset.generate === undefined ? false : dataset.generate === 'true'; const constructable = dataset.constructable === undefined ? true : dataset.constructable === 'true'; const desktopFirst = dataset.mode === undefined ? false : dataset.mode === 'desktop-first'; + const selectorAttribute = dataset.selectorAttribute === undefined ? 'class' : dataset.selectorAttribute; const cache = dataset.cache === undefined ? null : dataset.cache; const cacheKey = dataset.cacheKey === undefined ? "assembler-css-cache" : dataset.cacheKey; const dataScopes = dataset.scopes === undefined ? [] : getStringItemList(dataset.scopes); @@ -690,6 +691,7 @@ breakpoints, media: { xs, sm, md, lg, xl }, xStyleAttribute, + selectorAttribute, }; } function style(item) { @@ -770,6 +772,11 @@ const desktopFirst = settings.desktopFirst; const states = settings.states; const tracker = new Set(); + const selectorAttribute = settings.selectorAttribute; + const selectorPfx = selectorAttribute === 'class' + ? '.' + HASH_CLASS_PREFIX + '\\#' + : '[' + selectorAttribute + '~="' + HASH_CLASS_PREFIX + '#'; + const selectorSfx = selectorAttribute === 'class' ? '' : '"]'; result.push(generateRootVariables(settings)); for (let media_index = 0, l = breakpoints.length; media_index < l; media_index++) { const bp = breakpoints[media_index]; @@ -800,7 +807,7 @@ prefix += `${variants[i]}:var(${property}) !important;`; } } - str += `.${HASH_CLASS_PREFIX}\\#${hash}${state_index > 0 ? ':' + state : ''}{${prefix}${name}:var(${property}) !important}`; + str += `${selectorPfx + hash + selectorSfx}${state_index > 0 ? ':' + state : ''}{${prefix}${name}:var(${property}) !important}`; } } if (media_index !== 0) { @@ -1075,6 +1082,7 @@ this.breakpoints = settings.breakpoints; this.rules = []; this.padding = style.cssRules.length; + this.selectorAttribute = settings.selectorAttribute; } get userSettings() { return this.settings; @@ -1084,7 +1092,7 @@ return this.handleStyleRemoved(element, old); } const newEntries = this.getStyleEntries(content); - const classList = element.hasAttribute('class') ? element.getAttribute('class').split(' ') : []; + const classList = element.hasAttribute(this.selectorAttribute) ? element.getAttribute(this.selectorAttribute).split(' ') : []; const assemblerEntries = []; // remove old entries for (const { n: name, p: property, e: entry } of old) { @@ -1108,11 +1116,11 @@ element.style.setProperty(property, value); assemblerEntries.push({ e: entry, n: name, p: property }); } - element.setAttribute('class', classList.join(' ')); + element.setAttribute(this.selectorAttribute, classList.join(' ')); return assemblerEntries; } handleStyleRemoved(element, old) { - const classList = element.hasAttribute('class') ? element.getAttribute('class').split(' ') : []; + const classList = element.hasAttribute(this.selectorAttribute) ? element.getAttribute(this.selectorAttribute).split(' ') : []; for (const { p: property, e: entry } of old) { const index = classList.indexOf(entry); if (index >= 0) { @@ -1120,7 +1128,7 @@ } element.style.removeProperty(property); } - element.setAttribute('class', classList.join(' ')); + element.setAttribute(this.selectorAttribute, classList.join(' ')); return []; } extract(attr, value = null) { @@ -1240,6 +1248,11 @@ const { tracker, mediaSettings, desktopFirst, style } = this; const { hash, media, state, cssProperty, property, scope, rank } = info; const hasMedia = media !== ''; + const selectorAttribute = this.settings.selectorAttribute; + const selectorPfx = selectorAttribute === 'class' + ? '.' + HASH_CLASS_PREFIX + '\\#' + : '[' + selectorAttribute + '~="' + HASH_CLASS_PREFIX + '#'; + const selectorSfx = selectorAttribute === 'class' ? '' : '"]'; tracker.add(hash); if (rank < 0) { return; @@ -1267,7 +1280,7 @@ rule += scopeValue.replace(REPLACE_REGEX, (match, p1) => { switch (p1) { case "selector": - return `.${HASH_CLASS_PREFIX}\\#${hash}${state ? ':' + state : ''}`; + return `${selectorPfx + hash + selectorSfx}${state ? ':' + state : ''}`; case "body": return prefix + cssProperty + ': var(' + property + ') !important'; case "variants": @@ -1277,7 +1290,7 @@ case "value": return `var(${property})`; case "class": - return `.${HASH_CLASS_PREFIX}\\#${hash}`; + return selectorPfx + hash + selectorSfx; case "state": return state ? ':' + state : ''; case "var": @@ -1287,7 +1300,7 @@ }); } else { - rule += `.${HASH_CLASS_PREFIX}\\#${hash}${state ? ':' + state : ''}{${prefix}${cssProperty}: var(${property}) !important}`; + rule += `${selectorPfx + hash + selectorSfx}${state ? ':' + state : ''}{${prefix}${cssProperty}: var(${property}) !important}`; } if (hasMedia) { rule += '}'; diff --git a/dist/assembler.min.js b/dist/assembler.min.js index 0ca069b..e843624 100644 --- a/dist/assembler.min.js +++ b/dist/assembler.min.js @@ -1 +1 @@ -!function(e,t){"object"==typeof exports&&"undefined"!=typeof module?t(exports):"function"==typeof define&&define.amd?define(["exports"],t):t((e="undefined"!=typeof globalThis?globalThis:e||self).AssemblerCSS={})}(this,(function(e){"use strict";const t=/^[0-9]+(\.5)?$/,r=/^-?[0-9]+(\.5)?$/,o=/^(xs|sm|base|lg|([2-9])?xl)$/,i=/^(none|tight|snug|normal|relaxed|loose)$/,s=/^[0-9]|1[0-9]|2[0-4]$/,n=/^[1-6]$/,a=/^(tighter|tight|normal|wide|wider|widest)$/,l=/^(xs|sm|md|lg|xl|pill)$/,p=/^(first|last|none)$/,c=["align-content","align-items","align-self","animation","appearance","backdrop-filter","background","background-attachment","background-blend-mode","background-clip","background-color","background-image","background-position","background-repeat","background-size","backface-visibility","border","border-bottom","border-bottom-color","border-bottom-style","border-bottom-width","border-bottom-left-radius","border-bottom-right-radius","border-collapse","border-color","border-left","border-left-color","border-left-style","border-left-width","border-radius","border-right","border-right-color","border-right-style","border-right-width","border-style","border-top","border-top-color","border-top-style","border-top-width","border-top-left-radius","border-top-right-radius","border-width","bottom","box-shadow","box-sizing","clear","clip","clip-path","color","column-gap","content","cursor","display","filter","flex","flex-basis","flex-direction","flex-flow","flex-grow","flex-shrink","flex-wrap","float","font-family","font-size","font-style","font-weight","font-variant-numeric","gap","grid","grid-area","grid-auto-columns","grid-auto-flow","grid-auto-rows","grid-column","grid-column-end","grid-column-start","grid-row","grid-row-end","grid-row-start","grid-template","grid-template-areas","grid-template-columns","grid-template-rows","height","isolation","justify-content","justify-items","justify-self","left","letter-spacing","line-height","list-style-position","list-style-type","margin","margin-bottom","margin-left","margin-right","margin-top","max-height","max-width","min-height","min-width","object-fit","object-position","opacity","order","outline","outline-offset","overflow","overflow-wrap","overflow-x","overflow-y","overscroll-behavior","overscroll-behavior-x","overscroll-behavior-y","padding","padding-bottom","padding-left","padding-right","padding-top","perspective","perspective-origin","place-content","place-items","place-self","pointer-events","position","resize","right","row-gap","table-layout","text-align","text-decoration","text-decoration-style","text-fill-color","text-overflow","text-shadow","text-transform","top","transform","transform-box","transform-origin","transform-style","transition","user-select","vertical-align","visibility","white-space","width","word-break","z-index"],d={animation:["-webkit-animation"],appearance:["-webkit-appearance","-moz-appearance"],"background-clip":["-webkit-background-clip","-moz-background-clip"],"backdrop-filter":["-webkit-backdrop-filter"],"column-gap":["-moz-column-gap"],"user-select":["-webkit-user-select","-moz-user-select"],"text-fill-color":["-webkit-text-fill-color","-moz-text-fill-color"]},x=["normal","link","visited","empty","placeholder-shown","default","checked","indeterminate","valid","invalid","required","optional","out-of-range","in-range","hover","focus","focus-within","focus-visible","active","read-only","read-write","disabled","enabled"],m={backdrop:"backdrop-filter",bg:"background","bg-attachment":"background-attachment","bg-blend":"background-blend-mode","bg-clip":"background-clip","bg-color":"background-color","bg-image":"background-image","bg-position":"background-position","bg-repeat":"background-repeat","bg-size":"background-size",radius:"border-radius","radius-top":["border-top-left-radius","border-top-right-radius"],"radius-bottom":["border-bottom-left-radius","border-bottom-right-radius"],"radius-left":["border-bottom-left-radius","border-top-left-radius"],"radius-right":["border-bottom-right-radius","border-top-right-radius"],"radius-bl":"border-bottom-left-radius","radius-br":"border-bottom-right-radius","radius-tl":"border-top-left-radius","radius-tr":"border-top-right-radius",b:"border",bc:"border-color",bs:"border-style",bw:"border-width",bt:"border-top",bl:"border-left",br:"border-right",bb:"border-bottom","bt-color":"border-top-color","bt-style":"border-top-style","bt-width":"border-top-width","bl-color":"border-left-color","bl-style":"border-left-style","bl-width":"border-left-width","br-color":"border-right-color","br-style":"border-right-style","br-width":"border-right-width","bb-color":"border-bottom-color","bb-style":"border-bottom-style","bb-width":"border-bottom-width",m:"margin",mt:"margin-top",mb:"margin-bottom",ml:"margin-left",mr:"margin-right",mx:["margin-left","margin-right"],my:["margin-top","margin-bottom"],p:"padding",pt:"padding-top",pb:"padding-bottom",pl:"padding-left",pr:"padding-right",px:["padding-left","padding-right"],py:["padding-top","padding-bottom"],"min-w":"min-width","max-w":"max-width","min-h":"min-height","max-h":"max-height",w:"width",h:"height",img:"background-image",gradient:"background-image","radial-gradient":"background-image","conic-gradient":"background-image","flex-dir":"flex-direction","col-reverse":"flex-direction","row-reverse":"flex-direction","grid-rows":"grid-template-rows","grid-flow":"grid-auto-flow","row-start":"grid-row-start","row-span":"grid-row-end","grid-cols":"grid-template-columns","col-start":"grid-column-start","col-span":"grid-column-end","col-gap":"column-gap","auto-cols":"grid-auto-columns","auto-rows":"grid-auto-rows",e:"box-shadow",shadow:"box-shadow",overscroll:"overscroll-behavior","overscroll-x":"overscroll-behavior-x","overscroll-y":"overscroll-behavior-y",inset:["top","bottom","left","right"],"inset-x":["left","right"],"inset-y":["top","bottom"],z:"z-index",decoration:"text-decoration","v-align":"vertical-align",ws:"white-space",ring:"box-shadow",leading:"line-height",tracking:"letter-spacing",break:e=>"words"===e?["overflow-wrap"]:"all"===e?["word-break"]:["overflow-wrap","word-break"],truncate:["overflow","text-overflow","white-space"],flex:e=>e?"flex":"display","inline-flex":"display",grid:"display","inline-grid":"display",hidden:"display",block:"display","inline-block":"display",static:"position",fixed:"position",absolute:"position",relative:"position",sticky:"position",visible:"visibility",invisible:"visibility","flex-row":"flex-direction","flex-col":"flex-direction",list:e=>"inside"===e||"outside"===e?"list-style-position":"list-style-type",text:e=>o.test(e)?["font-size","line-height"]:"font-size",uppercase:"text-transform",lowercase:"text-transform",capitalize:"text-transform","normal-case":"text-transform",variant:"font-variant-numeric"},u={border:["1px solid transparent"],truncate:["hidden","ellipsis","nowrap"],flex:"flex","inline-flex":"inline-flex",grid:"grid","inline-grid":"inline-grid",hidden:"none",block:"block","inline-block":"inline-block",static:"static",fixed:"fixed",absolute:"absolute",relative:"relative",sticky:"sticky",visible:"visible",invisible:"hidden","flex-row":"row","flex-col":"column","flex-wrap":"wrap","flex-grow":"1","flex-shrink":"1","col-reverse":"column-reverse","row-reverse":"row-reverse",uppercase:"uppercase",lowercase:"lowercase",capitalize:"capitalize","normal-case":"none",radius:"sm",shadow:"1"},b=e=>r.test(e)?`calc(${e} * @unit-size)`:e,g=e=>t.test(e)?`calc(${e} * @unit-size)`:e,h=e=>`repeat(${e}, minmax(0, 1fr))`,f=e=>`span ${e}`,y=e=>l.test(e)?"@border-radius-"+e:e,w={img:e=>`url(${e})`,gradient:e=>`linear-gradient(${e})`,"radial-gradient":e=>`radial-gradient(${e})`,"conic-gradient":e=>`conic-gradient(${e})`,"grid-rows":h,"row-span":f,"grid-cols":h,"col-span":f,e:e=>s.test(e)?`@elevation-${e}`:e,shadow:e=>n.test(e)?`@shadow-${e}`:e,ring:e=>`0 0 0 ${e}`,"font-size":e=>o.test(e)?"@font-size-"+e:e,leading:e=>t.test(e)?`calc(${e} * @unit-size)`:i.test(e)?"@line-height-"+e:e,tracking:e=>a.test(e)?"@letter-spacing-"+e:e,text:e=>o.test(e)?["@font-size-"+e,"@font-size-leading-"+e]:e,radius:y,"radius-top":y,"radius-left":y,"radius-bottom":y,"radius-right":y,"radius-tl":y,"radius-bl":y,"radius-tr":y,"radius-br":y,"border-radius":y,break:e=>"all"===e?"break-all":"words"===e?"break-word":["normal","normal"],"flex-wrap":e=>"reverse"===e?"wrap-reverse":e,"flex-row":e=>"reverse"===e?"row-reverse":e,"flex-col":e=>"reverse"===e?"column-reverse":e,order:e=>p.test(e)?"first"===e?"-9999":"last"===e?"9999":"0":e,padding:g,"padding-top":g,"padding-bottom":g,"padding-left":g,"padding-right":g,p:g,pt:g,pb:g,pl:g,pr:g,px:g,py:g,margin:b,"margin-top":b,"margin-bottom":b,"margin-left":b,"margin-right":b,m:b,mt:b,mb:b,ml:b,mr:b,mx:b,my:b,w:g,h:g,width:g,height:g,"min-w":g,"max-w":g,"min-h":g,"max-h":g,"min-width":g,"max-width":g,"min-height":g,"max-height":g},v=["0px 0px 0px 0px","0px 2px 1px -1px","0px 3px 1px -2px","0px 3px 3px -2px","0px 2px 4px -1px","0px 3px 5px -1px","0px 3px 5px -1px","0px 4px 5px -2px","0px 5px 5px -3px","0px 5px 6px -3px","0px 6px 6px -3px","0px 6px 7px -4px","0px 7px 8px -4px","0px 7px 8px -4px","0px 7px 9px -4px","0px 8px 9px -5px","0px 8px 10px -5px","0px 8px 11px -5px","0px 9px 11px -5px","0px 9px 12px -6px","0px 10px 13px -6px","0px 10px 13px -6px","0px 10px 14px -6px","0px 11px 14px -7px","0px 11px 15px -7px"],$=["0px 0px 0px 0px","0px 1px 1px 0px","0px 2px 2px 0px","0px 3px 4px 0px","0px 4px 5px 0px","0px 5px 8px 0px","0px 6px 10px 0px","0px 7px 10px 1px","0px 8px 10px 1px","0px 9px 12px 1px","0px 10px 14px 1px","0px 11px 15px 1px","0px 12px 17px 2px","0px 13px 19px 2px","0px 14px 21px 2px","0px 15px 22px 2px","0px 16px 24px 2px","0px 17px 26px 2px","0px 18px 28px 2px","0px 19px 29px 2px","0px 20px 31px 3px","0px 21px 33px 3px","0px 22px 35px 3px","0px 23px 36px 3px","0px 24px 38px 3px"],k=["0px 0px 0px 0px","0px 1px 3px 0px","0px 1px 5px 0px","0px 1px 8px 0px","0px 1px 10px 0px","0px 1px 14px 0px","0px 1px 18px 0px","0px 2px 16px 1px","0px 3px 14px 2px","0px 3px 16px 2px","0px 4px 18px 3px","0px 4px 20px 3px","0px 5px 22px 4px","0px 5px 24px 4px","0px 5px 26px 4px","0px 6px 28px 5px","0px 6px 30px 5px","0px 6px 32px 5px","0px 7px 34px 6px","0px 7px 36px 6px","0px 8px 38px 7px","0px 8px 40px 7px","0px 8px 42px 7px","0px 9px 44px 8px","0px 9px 46px 8px"],S={none:"0",xs:"0.125rem",sm:"0.25rem",md:"0.5rem",lg:"0.75rem",xl:"1rem",pill:"9999px"},z={tighter:"-0.05rem",tight:"-0.025rem",normal:"0",wide:"0.025rem",wider:"0.05rem",widest:"0.1rem"},O={none:"1",tight:"1.25",snug:"1.375",normal:"1.5",relaxed:"1.625",loose:"2"},A={xs:"0.75rem",sm:"0.875rem",base:"1rem",lg:"1.125rem",xl:"1.25rem","2xl":"1.5rem","3xl":"1.875rem","4xl":"2.25rem","5xl":"3rem","6xl":"3.75rem","7xl":"4.5rem","8xl":"6rem","9xl":"8rem"},j={xs:"1rem",sm:"1.25rem",base:"1.5rem",lg:"1.75rem",xl:"1.75rem","2xl":"2rem","3xl":"2.25rem","4xl":"2.5rem","5xl":"1","6xl":"1","7xl":"1","8xl":"1","9xl":"1"},C={"sans-serif":"-apple-system, BlinkMacSystemFont, Segoe UI, Roboto, Helvetica Neue, Arial, sans-serif, Apple Color Emoji, Segoe UI Emoji, Segoe UI Symbol",serif:"Georgia, Cambria, Times New Roman, Times, serif",monospace:"Lucida Console, Monaco, monospace"},P=["0px 2px 4px 0px hsla(0, 0%, 20%, 0.1), 0px 6px 6px -8px hsla(0, 0%, 0%, 15%)","0px 2px 8px -1px hsla(0, 0%, 20%, 0.1), 0px 16px 16px -12px hsla(0, 0%, 0%, 15%)","0px 2px 16px -2px hsla(0, 0%, 20%, 0.1), 0px 22px 18px -16px hsla(0, 0%, 0%, 15%)","0px 2px 20px -3px hsla(0, 0%, 20%, 0.1), 0px 28px 22px -18px hsla(0, 0%, 0%, 15%)","0px 2px 32px -2px hsla(0, 0%, 20%, 0.1), 0px 32px 26px -18px hsla(0, 0%, 0%, 15%)","0px 2px 36px -1px hsla(0, 0%, 20%, 0.1), 0px 42px 34px -24px hsla(0, 0%, 0%, 15%)"];function I(e){let t="--elevation-umbra: rgba(0, 0, 0, .2);--elevation-penumbra: rgba(0, 0, 0, .14);--elevation-ambient: rgba(0, 0, 0, .12);";for(let e=0;e<25;e++)t+=`--elevation-${e}:${v[e]} var(--elevation-umbra), ${$[e]} var(--elevation-penumbra), ${k[e]} var(--elevation-ambient);`;for(let e=0;e<6;e++)t+=`--shadow-${e+1}:${P[e]};`;for(const[e,r]of Object.entries(S))t+=`--border-radius-${e}:${r};`;for(const[e,r]of Object.entries(z))t+=`--letter-spacing-${e}:${r};`;for(const[e,r]of Object.entries(O))t+=`--line-height-${e}:${r};`;for(const[e,r]of Object.entries(C))t+=`--${e}:${r};`;for(const[e,r]of Object.entries(A))t+=`--font-size-${e}:${r};`;for(const[e,r]of Object.entries(j))t+=`--font-size-leading-${e}:${r};`;for(const r of e.breakpoints)"all"!==r&&(t+=`--breakpoint-${r}: ${e.media[r]};`);return t+="--unit-size:0.25rem;",":root{"+t+"}"}const R=/([a-z0-9]|(?=[A-Z]))([A-Z])/g,M="--asm-",E=/^(?:(?[a-z]{2})\|)?(?:(?[-a-zA-Z0-9]+)!)?(?[-a-z]+)(?:\.(?[-a-z]+))?$/m;function F(e){if("string"==typeof e)return e.trim();if(Array.isArray(e))return e.map(F).join(";");const t=[];for(const r in e){const o=e[r];if(void 0===o)continue;const i=r.replace(R,"$1-$2").toLowerCase();t.push(null===o?i:i+":"+o)}return t.join(";")}function K(e,t=!0){const r=e.replace(/[,;]/g," ").split(/\s\s*/g).map(L).filter(N);return t?r.filter(_):r}function L(e){return e.trim()}function N(e){return""!==e}function _(e,t,r){return r.indexOf(e)===t}function T(e){if(e.cache){const t=localStorage.getItem(e.cacheKey+":"+e.cache);if(null!==t){const e=JSON.parse(t);return e.tracker=new Set(e.tracker),e}const r=localStorage.getItem(e.cacheKey);null!==r&&localStorage.removeItem(e.cacheKey+":"+r),localStorage.setItem(e.cacheKey,e.cache)}else{const t=localStorage.getItem(e.cacheKey);null!==t&&(localStorage.removeItem(e.cacheKey+":"+t),localStorage.removeItem(e.cacheKey))}const t=x.length,r=[],o=e.breakpoints,i=e.media,s=e.desktopFirst,n=e.states,a=new Set;r.push(I(e));for(let e=0,l=o.length;e0?l+"--":"")+o+(n>0?"__"+i[n]:"");a.add(c);let u=d[o],b="";if(u)for(let e=0,t=u.length;e0?":"+s:""}{${b}${o}:var(${m}) !important}`}}0!==e&&(p+="}"),r.push(p)}const l={content:r.join(""),tracker:a};return e.cache&&(localStorage.setItem(e.cacheKey,e.cache),localStorage.setItem(e.cacheKey+":"+e.cache,JSON.stringify({content:l.content,tracker:[...a]}))),l}let V=null,U=null,W=null;const Z=new WeakMap;function H(e,t){if(Z.has(e))return;const r=e.attributes.getNamedItem(t.userSettings.xStyleAttribute);Z.set(e,r?t.handleStyleChange(e,r.value,[]):[]),function(e,t){null===U&&(U=new MutationObserver((function(e){for(const r of e){const e=r.target;Z.set(e,t.handleStyleChange(e,e.getAttribute(r.attributeName),Z.get(e)))}}))),U.observe(e,{attributes:!0,attributeOldValue:!0,childList:!0,attributeFilter:[t.userSettings.xStyleAttribute]})}(e,t);for(let r=e.firstElementChild;null!=r;r=r.nextElementSibling)H(r,t)}const B=/\\\n/g;const J=new class{constructor(){this.styles=null,this.cache=new Map;const{cache:e}=this;e.set("text-clip--scope","$selector {-webkit-background-clip: text !important;-moz-background-clip:text !important;background-clip:text !important;}"),e.set("l1--scope","$selector > * {$body}"),e.set("l2--scope","$selector > * > * {$body}"),e.set("sibling--scope","$selector > * + * {$body}"),e.set("child--scope","$selector > $class {$body}"),e.set("selection--scope","$selector::selection {$body}"),e.set("placeholder--scope","$selector::placeholder {$body}"),e.set("marker--scope","$selector::marker {$body}"),e.set("marker-l1--scope","$selector > *::marker {$body}"),e.set("before--scope","$selector::before {$body}"),e.set("after--scope","$selector::after {$body}"),e.set("even--scope","$selector:nth-child(even) {$body}"),e.set("odd--scope","$selector:nth-child(odd) {$body}"),e.set("first--scope","$selector:first-child {$body}"),e.set("last--scope","$selector:last-child {$body}"),e.set("first-letter--scope","$selector::first-letter {$body}"),e.set("first-line--scope","$selector::first-line {$body}"),e.set("dark--scope","@media(prefers-color-scheme: dark) {$selector {$body}}"),e.set("light--scope","@media(prefers-color-scheme: light) {$selector {$body}}"),e.set("landscape--scope","@media(orientation: landscape) {$selector {$body}}"),e.set("portrait--scope","@media(orientation: portrait) {$selector {$body}}"),e.set("motion-reduce--scope","@media(prefers-reduced-motion: reduce) {$selector {$body}}"),e.set("motion-safe--scope","@media(prefers-reduced-motion: no-preference) {$selector {$body}}")}getComputedStyles(){if(null===this.styles){this.styles=[];for(let e=0,t=document.styleSheets.length;eJ.getPropertyValue(e+"--mixin").replace(q,((e,r,o)=>t[parseInt(r)]||o||"")))(t,r))}X.set("space-x",(function(e,t,r){return"true"===r?`sibling!mr:${t||"0"}`:`sibling!ml:${t||"0"}`})),X.set("space-y",(function(e,t,r){return"true"===r?`sibling!mb:${t||"0"}`:`sibling!mt:${t||"0"}`})),X.set("grid",(function(){return"grid; l1!wb:break-all; l2!max-w:100%; child!justify-self:normal; child!align-self:normal"})),X.set("stack",(function(){return'grid; grid-template-columns:minmax(0,1fr); grid-template-rows:minmax(0,1fr); \n grid-template-areas:"stackarea"; l1!grid-area:stackarea; l1!z:0; w:100%; h:100%'})),X.set("sr-only",(function(){return"absolute; w:1px; h:1px; p:0; m:-1px; bw:0; overflow:hidden; clip:rect(0, 0, 0, 0); left:-9999px"})),X.set("container",(function(e){return e.desktopFirst?"px: 1rem; mx:auto; max-w:@breakpoint-lg; lg|max-w:@breakpoint-md; md|max-w:@breakpoint-sm; sm|max-w:@breakpoint-xs; xs|max-w:100%":"px: 1rem; mx:auto; max-w:100%; sm|max-w:@breakpoint-sm; md|max-w:@breakpoint-md; lg|max-w:@breakpoint-lg; xl|max-w:@breakpoint-xl"}));const Y=/@([a-zA-Z0-9\-_]+)/g,D=/\$(selector|body|class|value|property|state|variants|var)/g,Q=/;/,ee=/\s*,\s*(?![^(]*\))/gm;class te{constructor(e,t,r){this.style=t,this.settings=e,this.tracker=r,this.mediaSettings=e.media,this.desktopFirst=e.desktopFirst,this.breakpoints=e.breakpoints,this.rules=[],this.padding=t.cssRules.length}get userSettings(){return this.settings}handleStyleChange(e,t,r){if(null===t)return this.handleStyleRemoved(e,r);const o=this.getStyleEntries(t),i=e.hasAttribute("class")?e.getAttribute("class").split(" "):[],s=[];for(const{n:t,p:s,e:n}of r)if(!o.has(t)){const t=i.indexOf(n);t>=0&&i.splice(t,1),e.style.removeProperty(s)}for(const t of o.values()){const{entry:r,property:o,hash:n,value:a,name:l}=t;i.indexOf(r)<0&&i.push(r),this.tracker.has(n)||this.generateCSS(t),e.style.setProperty(o,a),s.push({e:r,n:l,p:o})}return e.setAttribute("class",i.join(" ")),s}handleStyleRemoved(e,t){const r=e.hasAttribute("class")?e.getAttribute("class").split(" "):[];for(const{p:o,e:i}of t){const t=r.indexOf(i);t>=0&&r.splice(t,1),e.style.removeProperty(o)}return e.setAttribute("class",r.join(" ")),[]}extract(e,t=null){var r;const o=null===(r=E.exec(e))||void 0===r?void 0:r.groups;if(!o||!o.property)return[];const i=this.breakpoints.indexOf(o.media||"all"),s=x.indexOf(o.state||"normal");if(i<0||s<0)return[];let n=o.property;const a=n,l=this.settings.scopes;m.hasOwnProperty(n)&&(n=m[n],"function"==typeof n&&(n=n(t))),Array.isArray(n)||(n=[n]),null===t&&(t=u[a]||""),w.hasOwnProperty(a)&&(t=w[a](t,a,i,s)),t=Array.isArray(t)?t.map((e=>e.replace(Y,"var(--$1)"))):Array(n.length).fill(t.replace(Y,"var(--$1)"));const p=[],d=x.length;let b=-1;for(const e of n){b++;const r=c.indexOf(e);if(r<0)continue;const n=o.scope||"",a=(r*d+i)*d+s,x=a.toString(16)+(n?`-${n}`:""),m=1e5*l.indexOf(n),u=(o.media?o.media+"--":"")+(n?n+"__":"")+e+(o.state?"__"+o.state:"");p.push({name:(o.media?o.media+"|":"")+(n?n+"!":"")+e+(o.state?"."+o.state:""),property:M+u,entry:"asm#"+x,value:t[b],media:o.media||"",state:o.state||"",cssProperty:e,hash:x,scope:n,rank:m<0?-1:a+m})}return p}getStyleEntries(e){const t=new Map;for(let r of this.getResolvedProperties(e)){let e=null;const o=r.indexOf(":");o>=0&&(e=r.substr(o+1),r=r.substr(0,o).trim());for(const o of this.extract(r,e))t.set(o.name,o)}return t}getResolvedProperties(e,t=[]){const r=[];for(let o of e.split(Q))if(o=o.trim(),""!==o)if(o.startsWith("^")){const e=o.indexOf(":");let i,s;if(e<0?(i=o.substr(1),s=[]):(i=o.substr(1,e-1),s=o.substr(e+1).split(ee).map(L)),t.indexOf(i)>=0)throw t.push(i),new Error("Recursive mixin detected: "+t.join("->"));t.push(i),r.push(...this.getResolvedProperties(G(this.settings,i,s),t)),t.pop()}else r.push(o);return r}generateCSS(e){const{tracker:t,mediaSettings:r,desktopFirst:o,style:i}=this,{hash:s,media:n,state:a,cssProperty:l,property:p,scope:c,rank:x}=e,m=""!==n;if(t.add(s),x<0)return;let u="";m&&(u+=o?`@media only screen and (max-width: ${r[n]}) {`:`@media only screen and (min-width: ${r[n]}) {`);let b=d[l],g="";if(b)for(let e=0,t=b.length;e{switch(t){case"selector":return`.asm\\#${s}${a?":"+a:""}`;case"body":return g+l+": var("+p+") !important";case"variants":return g;case"property":return l;case"value":return`var(${p})`;case"class":return`.asm\\#${s}`;case"state":return a?":"+a:"";case"var":return p}return t}))}else u+=`.asm\\#${s}${a?":"+a:""}{${g}${l}: var(${p}) !important}`;m&&(u+="}");const h=this.getRuleIndex(x);this.rules.splice(h,0,x);try{i.insertRule(u,this.padding+h)}catch(e){this.rules.splice(h,1),console.warn("Unsupported rule:",u)}}getRuleIndex(e){const{rules:t}=this;for(let r=0,o=t.length;r"words"===e?["overflow-wrap"]:"all"===e?["word-break"]:["overflow-wrap","word-break"],truncate:["overflow","text-overflow","white-space"],flex:e=>e?"flex":"display","inline-flex":"display",grid:"display","inline-grid":"display",hidden:"display",block:"display","inline-block":"display",static:"position",fixed:"position",absolute:"position",relative:"position",sticky:"position",visible:"visibility",invisible:"visibility","flex-row":"flex-direction","flex-col":"flex-direction",list:e=>"inside"===e||"outside"===e?"list-style-position":"list-style-type",text:e=>o.test(e)?["font-size","line-height"]:"font-size",uppercase:"text-transform",lowercase:"text-transform",capitalize:"text-transform","normal-case":"text-transform",variant:"font-variant-numeric"},u={border:["1px solid transparent"],truncate:["hidden","ellipsis","nowrap"],flex:"flex","inline-flex":"inline-flex",grid:"grid","inline-grid":"inline-grid",hidden:"none",block:"block","inline-block":"inline-block",static:"static",fixed:"fixed",absolute:"absolute",relative:"relative",sticky:"sticky",visible:"visible",invisible:"hidden","flex-row":"row","flex-col":"column","flex-wrap":"wrap","flex-grow":"1","flex-shrink":"1","col-reverse":"column-reverse","row-reverse":"row-reverse",uppercase:"uppercase",lowercase:"lowercase",capitalize:"capitalize","normal-case":"none",radius:"sm",shadow:"1"},b=e=>r.test(e)?`calc(${e} * @unit-size)`:e,g=e=>t.test(e)?`calc(${e} * @unit-size)`:e,h=e=>`repeat(${e}, minmax(0, 1fr))`,f=e=>`span ${e}`,y=e=>l.test(e)?"@border-radius-"+e:e,w={img:e=>`url(${e})`,gradient:e=>`linear-gradient(${e})`,"radial-gradient":e=>`radial-gradient(${e})`,"conic-gradient":e=>`conic-gradient(${e})`,"grid-rows":h,"row-span":f,"grid-cols":h,"col-span":f,e:e=>s.test(e)?`@elevation-${e}`:e,shadow:e=>n.test(e)?`@shadow-${e}`:e,ring:e=>`0 0 0 ${e}`,"font-size":e=>o.test(e)?"@font-size-"+e:e,leading:e=>t.test(e)?`calc(${e} * @unit-size)`:i.test(e)?"@line-height-"+e:e,tracking:e=>a.test(e)?"@letter-spacing-"+e:e,text:e=>o.test(e)?["@font-size-"+e,"@font-size-leading-"+e]:e,radius:y,"radius-top":y,"radius-left":y,"radius-bottom":y,"radius-right":y,"radius-tl":y,"radius-bl":y,"radius-tr":y,"radius-br":y,"border-radius":y,break:e=>"all"===e?"break-all":"words"===e?"break-word":["normal","normal"],"flex-wrap":e=>"reverse"===e?"wrap-reverse":e,"flex-row":e=>"reverse"===e?"row-reverse":e,"flex-col":e=>"reverse"===e?"column-reverse":e,order:e=>p.test(e)?"first"===e?"-9999":"last"===e?"9999":"0":e,padding:g,"padding-top":g,"padding-bottom":g,"padding-left":g,"padding-right":g,p:g,pt:g,pb:g,pl:g,pr:g,px:g,py:g,margin:b,"margin-top":b,"margin-bottom":b,"margin-left":b,"margin-right":b,m:b,mt:b,mb:b,ml:b,mr:b,mx:b,my:b,w:g,h:g,width:g,height:g,"min-w":g,"max-w":g,"min-h":g,"max-h":g,"min-width":g,"max-width":g,"min-height":g,"max-height":g},v=["0px 0px 0px 0px","0px 2px 1px -1px","0px 3px 1px -2px","0px 3px 3px -2px","0px 2px 4px -1px","0px 3px 5px -1px","0px 3px 5px -1px","0px 4px 5px -2px","0px 5px 5px -3px","0px 5px 6px -3px","0px 6px 6px -3px","0px 6px 7px -4px","0px 7px 8px -4px","0px 7px 8px -4px","0px 7px 9px -4px","0px 8px 9px -5px","0px 8px 10px -5px","0px 8px 11px -5px","0px 9px 11px -5px","0px 9px 12px -6px","0px 10px 13px -6px","0px 10px 13px -6px","0px 10px 14px -6px","0px 11px 14px -7px","0px 11px 15px -7px"],$=["0px 0px 0px 0px","0px 1px 1px 0px","0px 2px 2px 0px","0px 3px 4px 0px","0px 4px 5px 0px","0px 5px 8px 0px","0px 6px 10px 0px","0px 7px 10px 1px","0px 8px 10px 1px","0px 9px 12px 1px","0px 10px 14px 1px","0px 11px 15px 1px","0px 12px 17px 2px","0px 13px 19px 2px","0px 14px 21px 2px","0px 15px 22px 2px","0px 16px 24px 2px","0px 17px 26px 2px","0px 18px 28px 2px","0px 19px 29px 2px","0px 20px 31px 3px","0px 21px 33px 3px","0px 22px 35px 3px","0px 23px 36px 3px","0px 24px 38px 3px"],k=["0px 0px 0px 0px","0px 1px 3px 0px","0px 1px 5px 0px","0px 1px 8px 0px","0px 1px 10px 0px","0px 1px 14px 0px","0px 1px 18px 0px","0px 2px 16px 1px","0px 3px 14px 2px","0px 3px 16px 2px","0px 4px 18px 3px","0px 4px 20px 3px","0px 5px 22px 4px","0px 5px 24px 4px","0px 5px 26px 4px","0px 6px 28px 5px","0px 6px 30px 5px","0px 6px 32px 5px","0px 7px 34px 6px","0px 7px 36px 6px","0px 8px 38px 7px","0px 8px 40px 7px","0px 8px 42px 7px","0px 9px 44px 8px","0px 9px 46px 8px"],S={none:"0",xs:"0.125rem",sm:"0.25rem",md:"0.5rem",lg:"0.75rem",xl:"1rem",pill:"9999px"},z={tighter:"-0.05rem",tight:"-0.025rem",normal:"0",wide:"0.025rem",wider:"0.05rem",widest:"0.1rem"},A={none:"1",tight:"1.25",snug:"1.375",normal:"1.5",relaxed:"1.625",loose:"2"},O={xs:"0.75rem",sm:"0.875rem",base:"1rem",lg:"1.125rem",xl:"1.25rem","2xl":"1.5rem","3xl":"1.875rem","4xl":"2.25rem","5xl":"3rem","6xl":"3.75rem","7xl":"4.5rem","8xl":"6rem","9xl":"8rem"},j={xs:"1rem",sm:"1.25rem",base:"1.5rem",lg:"1.75rem",xl:"1.75rem","2xl":"2rem","3xl":"2.25rem","4xl":"2.5rem","5xl":"1","6xl":"1","7xl":"1","8xl":"1","9xl":"1"},C={"sans-serif":"-apple-system, BlinkMacSystemFont, Segoe UI, Roboto, Helvetica Neue, Arial, sans-serif, Apple Color Emoji, Segoe UI Emoji, Segoe UI Symbol",serif:"Georgia, Cambria, Times New Roman, Times, serif",monospace:"Lucida Console, Monaco, monospace"},P=["0px 2px 4px 0px hsla(0, 0%, 20%, 0.1), 0px 6px 6px -8px hsla(0, 0%, 0%, 15%)","0px 2px 8px -1px hsla(0, 0%, 20%, 0.1), 0px 16px 16px -12px hsla(0, 0%, 0%, 15%)","0px 2px 16px -2px hsla(0, 0%, 20%, 0.1), 0px 22px 18px -16px hsla(0, 0%, 0%, 15%)","0px 2px 20px -3px hsla(0, 0%, 20%, 0.1), 0px 28px 22px -18px hsla(0, 0%, 0%, 15%)","0px 2px 32px -2px hsla(0, 0%, 20%, 0.1), 0px 32px 26px -18px hsla(0, 0%, 0%, 15%)","0px 2px 36px -1px hsla(0, 0%, 20%, 0.1), 0px 42px 34px -24px hsla(0, 0%, 0%, 15%)"];function I(e){let t="--elevation-umbra: rgba(0, 0, 0, .2);--elevation-penumbra: rgba(0, 0, 0, .14);--elevation-ambient: rgba(0, 0, 0, .12);";for(let e=0;e<25;e++)t+=`--elevation-${e}:${v[e]} var(--elevation-umbra), ${$[e]} var(--elevation-penumbra), ${k[e]} var(--elevation-ambient);`;for(let e=0;e<6;e++)t+=`--shadow-${e+1}:${P[e]};`;for(const[e,r]of Object.entries(S))t+=`--border-radius-${e}:${r};`;for(const[e,r]of Object.entries(z))t+=`--letter-spacing-${e}:${r};`;for(const[e,r]of Object.entries(A))t+=`--line-height-${e}:${r};`;for(const[e,r]of Object.entries(C))t+=`--${e}:${r};`;for(const[e,r]of Object.entries(O))t+=`--font-size-${e}:${r};`;for(const[e,r]of Object.entries(j))t+=`--font-size-leading-${e}:${r};`;for(const r of e.breakpoints)"all"!==r&&(t+=`--breakpoint-${r}: ${e.media[r]};`);return t+="--unit-size:0.25rem;",":root{"+t+"}"}const R=/([a-z0-9]|(?=[A-Z]))([A-Z])/g,M="--asm-",E=/^(?:(?[a-z]{2})\|)?(?:(?[-a-zA-Z0-9]+)!)?(?[-a-z]+)(?:\.(?[-a-z]+))?$/m;function F(e){if("string"==typeof e)return e.trim();if(Array.isArray(e))return e.map(F).join(";");const t=[];for(const r in e){const o=e[r];if(void 0===o)continue;const i=r.replace(R,"$1-$2").toLowerCase();t.push(null===o?i:i+":"+o)}return t.join(";")}function K(e,t=!0){const r=e.replace(/[,;]/g," ").split(/\s\s*/g).map(L).filter(N);return t?r.filter(_):r}function L(e){return e.trim()}function N(e){return""!==e}function _(e,t,r){return r.indexOf(e)===t}function T(e){if(e.cache){const t=localStorage.getItem(e.cacheKey+":"+e.cache);if(null!==t){const e=JSON.parse(t);return e.tracker=new Set(e.tracker),e}const r=localStorage.getItem(e.cacheKey);null!==r&&localStorage.removeItem(e.cacheKey+":"+r),localStorage.setItem(e.cacheKey,e.cache)}else{const t=localStorage.getItem(e.cacheKey);null!==t&&(localStorage.removeItem(e.cacheKey+":"+t),localStorage.removeItem(e.cacheKey))}const t=x.length,r=[],o=e.breakpoints,i=e.media,s=e.desktopFirst,n=e.states,a=new Set,l=e.selectorAttribute,p="class"===l?".asm\\#":"["+l+'~="'+"asm#",m="class"===l?"":'"]';r.push(I(e));for(let e=0,l=o.length;e0?l+"--":"")+o+(n>0?"__"+i[n]:"");a.add(c);let g=d[o],h="";if(g)for(let e=0,t=g.length;e0?":"+s:""}{${h}${o}:var(${b}) !important}`}}0!==e&&(u+="}"),r.push(u)}const u={content:r.join(""),tracker:a};return e.cache&&(localStorage.setItem(e.cacheKey,e.cache),localStorage.setItem(e.cacheKey+":"+e.cache,JSON.stringify({content:u.content,tracker:[...a]}))),u}let V=null,U=null,W=null;const Z=new WeakMap;function H(e,t){if(Z.has(e))return;const r=e.attributes.getNamedItem(t.userSettings.xStyleAttribute);Z.set(e,r?t.handleStyleChange(e,r.value,[]):[]),function(e,t){null===U&&(U=new MutationObserver((function(e){for(const r of e){const e=r.target;Z.set(e,t.handleStyleChange(e,e.getAttribute(r.attributeName),Z.get(e)))}}))),U.observe(e,{attributes:!0,attributeOldValue:!0,childList:!0,attributeFilter:[t.userSettings.xStyleAttribute]})}(e,t);for(let r=e.firstElementChild;null!=r;r=r.nextElementSibling)H(r,t)}const B=/\\\n/g;const J=new class{constructor(){this.styles=null,this.cache=new Map;const{cache:e}=this;e.set("text-clip--scope","$selector {-webkit-background-clip: text !important;-moz-background-clip:text !important;background-clip:text !important;}"),e.set("l1--scope","$selector > * {$body}"),e.set("l2--scope","$selector > * > * {$body}"),e.set("sibling--scope","$selector > * + * {$body}"),e.set("child--scope","$selector > $class {$body}"),e.set("selection--scope","$selector::selection {$body}"),e.set("placeholder--scope","$selector::placeholder {$body}"),e.set("marker--scope","$selector::marker {$body}"),e.set("marker-l1--scope","$selector > *::marker {$body}"),e.set("before--scope","$selector::before {$body}"),e.set("after--scope","$selector::after {$body}"),e.set("even--scope","$selector:nth-child(even) {$body}"),e.set("odd--scope","$selector:nth-child(odd) {$body}"),e.set("first--scope","$selector:first-child {$body}"),e.set("last--scope","$selector:last-child {$body}"),e.set("first-letter--scope","$selector::first-letter {$body}"),e.set("first-line--scope","$selector::first-line {$body}"),e.set("dark--scope","@media(prefers-color-scheme: dark) {$selector {$body}}"),e.set("light--scope","@media(prefers-color-scheme: light) {$selector {$body}}"),e.set("landscape--scope","@media(orientation: landscape) {$selector {$body}}"),e.set("portrait--scope","@media(orientation: portrait) {$selector {$body}}"),e.set("motion-reduce--scope","@media(prefers-reduced-motion: reduce) {$selector {$body}}"),e.set("motion-safe--scope","@media(prefers-reduced-motion: no-preference) {$selector {$body}}")}getComputedStyles(){if(null===this.styles){this.styles=[];for(let e=0,t=document.styleSheets.length;eJ.getPropertyValue(e+"--mixin").replace(q,((e,r,o)=>t[parseInt(r)]||o||"")))(t,r))}X.set("space-x",(function(e,t,r){return"true"===r?`sibling!mr:${t||"0"}`:`sibling!ml:${t||"0"}`})),X.set("space-y",(function(e,t,r){return"true"===r?`sibling!mb:${t||"0"}`:`sibling!mt:${t||"0"}`})),X.set("grid",(function(){return"grid; l1!wb:break-all; l2!max-w:100%; child!justify-self:normal; child!align-self:normal"})),X.set("stack",(function(){return'grid; grid-template-columns:minmax(0,1fr); grid-template-rows:minmax(0,1fr); \n grid-template-areas:"stackarea"; l1!grid-area:stackarea; l1!z:0; w:100%; h:100%'})),X.set("sr-only",(function(){return"absolute; w:1px; h:1px; p:0; m:-1px; bw:0; overflow:hidden; clip:rect(0, 0, 0, 0); left:-9999px"})),X.set("container",(function(e){return e.desktopFirst?"px: 1rem; mx:auto; max-w:@breakpoint-lg; lg|max-w:@breakpoint-md; md|max-w:@breakpoint-sm; sm|max-w:@breakpoint-xs; xs|max-w:100%":"px: 1rem; mx:auto; max-w:100%; sm|max-w:@breakpoint-sm; md|max-w:@breakpoint-md; lg|max-w:@breakpoint-lg; xl|max-w:@breakpoint-xl"}));const Y=/@([a-zA-Z0-9\-_]+)/g,D=/\$(selector|body|class|value|property|state|variants|var)/g,Q=/;/,ee=/\s*,\s*(?![^(]*\))/gm;class te{constructor(e,t,r){this.style=t,this.settings=e,this.tracker=r,this.mediaSettings=e.media,this.desktopFirst=e.desktopFirst,this.breakpoints=e.breakpoints,this.rules=[],this.padding=t.cssRules.length,this.selectorAttribute=e.selectorAttribute}get userSettings(){return this.settings}handleStyleChange(e,t,r){if(null===t)return this.handleStyleRemoved(e,r);const o=this.getStyleEntries(t),i=e.hasAttribute(this.selectorAttribute)?e.getAttribute(this.selectorAttribute).split(" "):[],s=[];for(const{n:t,p:s,e:n}of r)if(!o.has(t)){const t=i.indexOf(n);t>=0&&i.splice(t,1),e.style.removeProperty(s)}for(const t of o.values()){const{entry:r,property:o,hash:n,value:a,name:l}=t;i.indexOf(r)<0&&i.push(r),this.tracker.has(n)||this.generateCSS(t),e.style.setProperty(o,a),s.push({e:r,n:l,p:o})}return e.setAttribute(this.selectorAttribute,i.join(" ")),s}handleStyleRemoved(e,t){const r=e.hasAttribute(this.selectorAttribute)?e.getAttribute(this.selectorAttribute).split(" "):[];for(const{p:o,e:i}of t){const t=r.indexOf(i);t>=0&&r.splice(t,1),e.style.removeProperty(o)}return e.setAttribute(this.selectorAttribute,r.join(" ")),[]}extract(e,t=null){var r;const o=null===(r=E.exec(e))||void 0===r?void 0:r.groups;if(!o||!o.property)return[];const i=this.breakpoints.indexOf(o.media||"all"),s=x.indexOf(o.state||"normal");if(i<0||s<0)return[];let n=o.property;const a=n,l=this.settings.scopes;m.hasOwnProperty(n)&&(n=m[n],"function"==typeof n&&(n=n(t))),Array.isArray(n)||(n=[n]),null===t&&(t=u[a]||""),w.hasOwnProperty(a)&&(t=w[a](t,a,i,s)),t=Array.isArray(t)?t.map((e=>e.replace(Y,"var(--$1)"))):Array(n.length).fill(t.replace(Y,"var(--$1)"));const p=[],d=x.length;let b=-1;for(const e of n){b++;const r=c.indexOf(e);if(r<0)continue;const n=o.scope||"",a=(r*d+i)*d+s,x=a.toString(16)+(n?`-${n}`:""),m=1e5*l.indexOf(n),u=(o.media?o.media+"--":"")+(n?n+"__":"")+e+(o.state?"__"+o.state:"");p.push({name:(o.media?o.media+"|":"")+(n?n+"!":"")+e+(o.state?"."+o.state:""),property:M+u,entry:"asm#"+x,value:t[b],media:o.media||"",state:o.state||"",cssProperty:e,hash:x,scope:n,rank:m<0?-1:a+m})}return p}getStyleEntries(e){const t=new Map;for(let r of this.getResolvedProperties(e)){let e=null;const o=r.indexOf(":");o>=0&&(e=r.substr(o+1),r=r.substr(0,o).trim());for(const o of this.extract(r,e))t.set(o.name,o)}return t}getResolvedProperties(e,t=[]){const r=[];for(let o of e.split(Q))if(o=o.trim(),""!==o)if(o.startsWith("^")){const e=o.indexOf(":");let i,s;if(e<0?(i=o.substr(1),s=[]):(i=o.substr(1,e-1),s=o.substr(e+1).split(ee).map(L)),t.indexOf(i)>=0)throw t.push(i),new Error("Recursive mixin detected: "+t.join("->"));t.push(i),r.push(...this.getResolvedProperties(G(this.settings,i,s),t)),t.pop()}else r.push(o);return r}generateCSS(e){const{tracker:t,mediaSettings:r,desktopFirst:o,style:i}=this,{hash:s,media:n,state:a,cssProperty:l,property:p,scope:c,rank:x}=e,m=""!==n,u=this.settings.selectorAttribute,b="class"===u?".asm\\#":"["+u+'~="'+"asm#",g="class"===u?"":'"]';if(t.add(s),x<0)return;let h="";m&&(h+=o?`@media only screen and (max-width: ${r[n]}) {`:`@media only screen and (min-width: ${r[n]}) {`);let f=d[l],y="";if(f)for(let e=0,t=f.length;e{switch(t){case"selector":return`${b+s+g}${a?":"+a:""}`;case"body":return y+l+": var("+p+") !important";case"variants":return y;case"property":return l;case"value":return`var(${p})`;case"class":return b+s+g;case"state":return a?":"+a:"";case"var":return p}return t}))}else h+=`${b+s+g}${a?":"+a:""}{${y}${l}: var(${p}) !important}`;m&&(h+="}");const w=this.getRuleIndex(x);this.rules.splice(w,0,x);try{i.insertRule(h,this.padding+w)}catch(e){this.rules.splice(w,1),console.warn("Unsupported rule:",h)}}getRuleIndex(e){const{rules:t}=this;for(let r=0,o=t.length;r) { this.style = style; @@ -67,6 +68,7 @@ export default class StyleHandler { this.breakpoints = settings.breakpoints; this.rules = []; this.padding = style.cssRules.length; + this.selectorAttribute = settings.selectorAttribute; } get userSettings(): UserSettings { @@ -80,7 +82,7 @@ export default class StyleHandler { } const newEntries = this.getStyleEntries(content); - const classList = element.hasAttribute('class') ? element.getAttribute('class').split(' ') : []; + const classList = element.hasAttribute(this.selectorAttribute) ? element.getAttribute(this.selectorAttribute).split(' ') : []; const assemblerEntries: AssemblerEntry[] = []; // remove old entries @@ -107,14 +109,14 @@ export default class StyleHandler { assemblerEntries.push({e:entry, n: name, p: property}); } - element.setAttribute('class', classList.join(' ')); + element.setAttribute(this.selectorAttribute, classList.join(' ')); return assemblerEntries; } handleStyleRemoved(element: HTMLElement, old: AssemblerEntry[]): AssemblerEntry[] { - const classList = element.hasAttribute('class') ? element.getAttribute('class').split(' ') : []; + const classList = element.hasAttribute(this.selectorAttribute) ? element.getAttribute(this.selectorAttribute).split(' ') : []; for (const {p:property, e:entry} of old) { const index = classList.indexOf(entry); @@ -124,7 +126,7 @@ export default class StyleHandler { element.style.removeProperty(property); } - element.setAttribute('class', classList.join(' ')); + element.setAttribute(this.selectorAttribute, classList.join(' ')); return []; } @@ -270,6 +272,11 @@ export default class StyleHandler { const {tracker, mediaSettings, desktopFirst, style} = this; const {hash, media, state, cssProperty, property, scope, rank} = info; const hasMedia = media !== ''; + const selectorAttribute = this.settings.selectorAttribute; + const selectorPfx = selectorAttribute === 'class' + ? '.' + HASH_CLASS_PREFIX + '\\#' + : '[' + selectorAttribute + '~="' + HASH_CLASS_PREFIX + '#' ; + const selectorSfx = selectorAttribute === 'class' ? '' : '"]'; tracker.add(hash); @@ -303,7 +310,7 @@ export default class StyleHandler { rule += scopeValue.replace(REPLACE_REGEX, (match, p1) => { switch (p1) { case "selector": - return `.${HASH_CLASS_PREFIX}\\#${hash}${state ? ':' + state : ''}`; + return `${selectorPfx + hash + selectorSfx}${state ? ':' + state : ''}`; case "body": return prefix + cssProperty + ': var(' + property + ') !important'; case "variants": @@ -313,7 +320,7 @@ export default class StyleHandler { case "value": return `var(${property})`; case "class": - return `.${HASH_CLASS_PREFIX}\\#${hash}`; + return selectorPfx + hash + selectorSfx; case "state": return state ? ':' + state : ''; case "var": @@ -322,7 +329,7 @@ export default class StyleHandler { return p1; }); } else { - rule += `.${HASH_CLASS_PREFIX}\\#${hash}${state ? ':' + state : ''}{${prefix}${cssProperty}: var(${property}) !important}`; + rule += `${selectorPfx + hash + selectorSfx}${state ? ':' + state : ''}{${prefix}${cssProperty}: var(${property}) !important}`; } if (hasMedia) { diff --git a/src/generators.ts b/src/generators.ts index 34411da..6d73685 100644 --- a/src/generators.ts +++ b/src/generators.ts @@ -53,6 +53,11 @@ export function generateStyles(settings: UserSettings): GeneratedStyles { const desktopFirst = settings.desktopFirst; const states = settings.states; const tracker = new Set(); + const selectorAttribute = settings.selectorAttribute; + const selectorPfx = selectorAttribute === 'class' + ? '.' + HASH_CLASS_PREFIX + '\\#' + : '[' + selectorAttribute + '~="' + HASH_CLASS_PREFIX + '#' ; + const selectorSfx = selectorAttribute === 'class' ? '' : '"]'; result.push(generateRootVariables(settings)); @@ -90,7 +95,7 @@ export function generateStyles(settings: UserSettings): GeneratedStyles { prefix += `${variants[i]}:var(${property}) !important;`; } } - str += `.${HASH_CLASS_PREFIX}\\#${hash}${state_index > 0 ? ':' + state : ''}{${prefix}${name}:var(${property}) !important}`; + str += `${selectorPfx + hash + selectorSfx}${state_index > 0 ? ':' + state : ''}{${prefix}${name}:var(${property}) !important}`; } } diff --git a/src/helpers.ts b/src/helpers.ts index 854c5e6..c90c24b 100644 --- a/src/helpers.ts +++ b/src/helpers.ts @@ -26,6 +26,7 @@ export type UserSettings = { states: string[], scopes: string[], xStyleAttribute: string, + selectorAttribute: string }; type StyleType = string|{[key: string]: string}; const regex = /([a-z0-9]|(?=[A-Z]))([A-Z])/g; @@ -39,6 +40,7 @@ export function getUserSettings(dataset: {[key: string]: string}): UserSettings const generate = dataset.generate === undefined ? false : dataset.generate === 'true'; const constructable = dataset.constructable === undefined ? true : dataset.constructable === 'true'; const desktopFirst = dataset.mode === undefined ? false : dataset.mode === 'desktop-first'; + const selectorAttribute = dataset.selectorAttribute === undefined ? 'class' : dataset.selectorAttribute; const cache = dataset.cache === undefined ? null : dataset.cache; const cacheKey = dataset.cacheKey === undefined ? "assembler-css-cache" : dataset.cacheKey; const dataScopes = dataset.scopes === undefined ? [] : getStringItemList(dataset.scopes); @@ -96,6 +98,7 @@ export function getUserSettings(dataset: {[key: string]: string}): UserSettings breakpoints, media: {xs, sm, md, lg, xl}, xStyleAttribute, + selectorAttribute, }; } diff --git a/types/StyleHandler.d.ts b/types/StyleHandler.d.ts index c500544..a146fa8 100644 --- a/types/StyleHandler.d.ts +++ b/types/StyleHandler.d.ts @@ -13,6 +13,7 @@ export default class StyleHandler { private readonly breakpoints; private rules; private readonly padding; + private readonly selectorAttribute; constructor(settings: UserSettings, style: CSSStyleSheet, tracker: Set); get userSettings(): UserSettings; handleStyleChange(element: HTMLElement, content: string | null, old: AssemblerEntry[]): AssemblerEntry[]; diff --git a/types/helpers.d.ts b/types/helpers.d.ts index a710d87..0bfa477 100644 --- a/types/helpers.d.ts +++ b/types/helpers.d.ts @@ -16,6 +16,7 @@ export declare type UserSettings = { states: string[]; scopes: string[]; xStyleAttribute: string; + selectorAttribute: string; }; declare type StyleType = string | { [key: string]: string;