!function(t,s){"object"==typeof exports&&"undefined"!=typeof module?s(exports):"function"==typeof define&&define.amd?define(["exports"],s):s((t="undefined"!=typeof globalThis?globalThis:t||self).cssTools={})}(this,function(t){"use strict";class s extends Error{reason;filename;line;column;source;constructor(t,s,e,i,n){super(`${t}:${e}:${i}: ${s}`),this.reason=s,this.filename=t,this.line=e,this.column=i,this.source=n}}class e{start;end;source;constructor(t,s,e){this.start=t,this.end=s,this.source=e}}var i;t.CssTypes=void 0,(i=t.CssTypes||(t.CssTypes={})).stylesheet="stylesheet",i.rule="rule",i.declaration="declaration",i.comment="comment",i.atRule="at-rule",i.container="container",i.charset="charset",i.counterStyle="counter-style",i.document="document",i.customMedia="custom-media",i.fontFace="font-face",i.fontFeatureValues="font-feature-values",i.host="host",i.import="import",i.keyframes="keyframes",i.keyframe="keyframe",i.layer="layer",i.media="media",i.namespace="namespace",i.page="page",i.pageMarginBox="page-margin-box",i.positionTry="position-try",i.property="property",i.scope="scope",i.startingStyle="starting-style",i.supports="supports",i.viewTransition="view-transition";const n=(t,s,e)=>{let i=e,n=1e4;do{const e=s.map(s=>t.indexOf(s,i));e.push(t.indexOf("\\",i));const r=e.filter(t=>-1!==t);if(0===r.length)return-1;const o=Math.min(...r);if("\\"!==t[o])return o;i=o+2,n--}while(n>0);throw new Error("Too many escaping")},r=(t,s,e)=>{let i=e,o=1e4;do{const e=s.map(s=>t.indexOf(s,i));e.push(t.indexOf("(",i)),e.push(t.indexOf('"',i)),e.push(t.indexOf("'",i)),e.push(t.indexOf("\\",i));const c=e.filter(t=>-1!==t);if(0===c.length)return-1;const h=Math.min(...c);switch(t[h]){case"\\":i=h+2;break;case"(":{const s=r(t,[")"],h+1);if(-1===s)return-1;i=s+1}break;case'"':{const s=n(t,['"'],h+1);if(-1===s)return-1;i=s+1}break;case"'":{const s=n(t,["'"],h+1);if(-1===s)return-1;i=s+1}break;default:return h}o--}while(o>0);throw new Error("Too many escaping")},o=/\/\*[^]*?(?:\*\/|$)/g;function c(t){return t?t.trim():""}function h(t,s){const e=t&&"string"==typeof t.type,i=e?t:s;for(const s in t){const e=t[s];Array.isArray(e)?e.forEach(t=>{h(t,i)}):e&&"object"==typeof e&&h(e,i)}return e&&Object.defineProperty(t,"parent",{configurable:!0,writable:!0,enumerable:!1,value:s||null}),t}class a{level=0;indentation=" ";compress=!1;constructor(t){"string"==typeof t?.indent&&(this.indentation=t?.indent),t?.compress&&(this.compress=!0)}emit(t,s){return t}indent(t){return this.level=this.level||1,t?(this.level+=t,""):Array(this.level).join(this.indentation)}visit(s){switch(s.type){case t.CssTypes.stylesheet:return this.stylesheet(s);case t.CssTypes.rule:return this.rule(s);case t.CssTypes.declaration:return this.declaration(s);case t.CssTypes.comment:return this.comment(s);case t.CssTypes.container:return this.container(s);case t.CssTypes.charset:return this.charset(s);case t.CssTypes.counterStyle:return this.counterStyle(s);case t.CssTypes.document:return this.document(s);case t.CssTypes.customMedia:return this.customMedia(s);case t.CssTypes.fontFace:return this.fontFace(s);case t.CssTypes.fontFeatureValues:return this.fontFeatureValues(s);case t.CssTypes.host:return this.host(s);case t.CssTypes.import:return this.import(s);case t.CssTypes.keyframes:return this.keyframes(s);case t.CssTypes.keyframe:return this.keyframe(s);case t.CssTypes.layer:return this.layer(s);case t.CssTypes.media:return this.media(s);case t.CssTypes.namespace:return this.namespace(s);case t.CssTypes.page:return this.page(s);case t.CssTypes.pageMarginBox:return this.pageMarginBox(s);case t.CssTypes.positionTry:return this.positionTry(s);case t.CssTypes.property:return this.property(s);case t.CssTypes.scope:return this.scope(s);case t.CssTypes.startingStyle:return this.startingStyle(s);case t.CssTypes.supports:return this.supports(s);case t.CssTypes.viewTransition:return this.viewTransition(s);case t.CssTypes.atRule:return this.genericAtRule(s)}}mapVisit(t,s){let e="";s=s||"";for(let i=0,n=t.length;is.type!==t.CssTypes.declaration&&s.type!==t.CssTypes.comment),n=i?"\n\n":"\n";return this.emit(`${this.indent()}@${s.name}${e}`,s.position)+this.emit(i?` {\n${this.indent(1)}`:" {\n")+this.emit(i?"":this.indent(1))+this.mapVisit(s.rules,n)+this.emit(i?`\n${this.indent(-1)}${this.indent()}}`:`${this.indent(-1)}\n${this.indent()}}`)}rule(t){const s=t.declarations;if(!s.length)return"";if(this.compress)return this.emit(t.selectors.join(","),t.position)+this.emit("{")+this.mapVisit(s)+this.emit("}");const e=this.indent();return this.emit(t.selectors.map(t=>e+t).join(",\n"),t.position)+this.emit(" {\n")+this.emit(this.indent(1))+this.mapVisit(s,"\n")+this.emit(this.indent(-1))+this.emit(`\n${this.indent()}}`)}declaration(t){return this.compress?this.emit(`${t.property}:${t.value}`,t.position)+this.emit(";"):"grid-template-areas"===t.property?this.emit(this.indent())+this.emit(t.property+": "+t.value.split("\n").join("\n".padEnd(22)+this.indent()),t.position)+this.emit(";"):this.emit(this.indent())+this.emit(`${t.property}: ${t.value}`,t.position)+this.emit(";")}}const m=(i,n)=>{n=n||{};let a=1,m=1;function u(){const t={line:a,column:m};return s=>(s.position=new e(t,{line:a,column:m},n?.source||""),g(),s)}const p=[];function l(t){const e=new s(n?.source||"",t,a,m,i);if(!n?.silent)throw e;p.push(e)}function f(){const t=/^{\s*/.exec(i);return!!t&&(d(t),!0)}function y(){const t=/^}/.exec(i);return!!t&&(d(t),!0)}function d(t){const s=t[0];return function(t){const s=t.match(/\n/g);s&&(a+=s.length);const e=t.lastIndexOf("\n");m=~e?t.length-e:m+t.length}(s),i=i.slice(s.length),t}function g(){const t=/^\s*/.exec(i);t&&d(t)}function $(t){t=t||[];let s=T();for(;s;)t.push(s),s=T();return t}function T(){const s=u();if("/"!==i.charAt(0)||"*"!==i.charAt(1))return;const e=/^\/\*[^]*?\*\//.exec(i);return e?(d(e),s({type:t.CssTypes.comment,comment:e[0].slice(2,-2)})):l("End of comment missing")}function x(){const t=r(i,["{"]);if(-1===t||0===t)return;const s=i.substring(0,t);d([s]);return((t,s)=>{const e=[];let i=0;for(;ic(t))}function C(){const s=u(),e=/^(\*?[-#/*\\\w]+(\[[0-9a-z_-]+\])?)\s*/.exec(i);if(!e)return;d(e);const n=c(e[0]),h=/^:\s*/.exec(i);if(!h)return l("property missing ':'");d(h);let a="";const m=r(i,[";","}"]);if(-1!==m){a=i.substring(0,m);d([a]),a=c(a).replace(o,"")}const p=s({type:t.CssTypes.declaration,property:n.replace(o,""),value:a}),f=/^[;\s]*/.exec(i);return f&&d(f),p}function V(){const t=[];if(!f())return l("missing '{'");$(t);let s=C();for(;s;)t.push(s),$(t),s=C();for(;n?.silent&&i.length&&"}"!==i.charAt(0);){const e=i.indexOf(";"),n=i.indexOf("}");if(-1===e||!(-1===n||e{const e=u(),n=s.exec(i);if(!n)return;const r=d(n),o={type:t};return o[t]=r[1].trim(),e(o)}}function S(){if("@"===i[0])return function(){const s=u(),e=/^@([-\w]+)?keyframes\s*/.exec(i);if(!e)return;const n=d(e)[1],r=/^([-\w]+)\s*/.exec(i);if(!r)return l("@keyframes missing name");const o=d(r)[1];if(!f())return l("@keyframes missing '{'");let c=$(),h=k();for(;h;)c.push(h),c=c.concat($()),h=k();return y()?s({type:t.CssTypes.keyframes,name:o,vendor:n,keyframes:c}):l("@keyframes missing '}'")}()||function(){const s=u(),e=/^@media *([^{]+)/.exec(i);if(!e)return;const n=c(d(e)[1]);if(!f())return l("@media missing '{'");const r=w();return y()?s({type:t.CssTypes.media,media:n,rules:r}):l("@media missing '}'")}()||function(){const s=u(),e=/^@custom-media\s+(--\S+)\s+([^{;\s][^{;]*);/.exec(i);if(!e)return;const n=d(e);return s({type:t.CssTypes.customMedia,name:c(n[1]),media:c(n[2])})}()||function(){const s=u(),e=/^@supports *([^{]+)/.exec(i);if(!e)return;const n=c(d(e)[1]);if(!f())return l("@supports missing '{'");const r=w();return y()?s({type:t.CssTypes.supports,supports:n,rules:r}):l("@supports missing '}'")}()||O()||j()||F()||function(){const s=u(),e=/^@([-\w]+)?document *([^{]+)/.exec(i);if(!e)return;const n=d(e),r=c(n[1]),o=c(n[2]);if(!f())return l("@document missing '{'");const h=w();return y()?s({type:t.CssTypes.document,document:o,vendor:r,rules:h}):l("@document missing '}'")}()||function(){const s=u(),e=/^@page */.exec(i);if(!e)return;d(e);const n=x()||[];if(!f())return l("@page missing '{'");const r=[];for($(r);i.length&&"}"!==i.charAt(0);){if("@"===i.charAt(0)){const t=S();if(t){r.push(t),$(r);continue}}const t=C();if(!t)break;r.push(t),$(r)}return y()?s({type:t.CssTypes.page,selectors:n,declarations:r}):l("@page missing '}'")}()||function(){const s=u(),e=/^@host\s*/.exec(i);if(!e)return;if(d(e),!f())return l("@host missing '{'");const n=w();return y()?s({type:t.CssTypes.host,rules:n}):l("@host missing '}'")}()||function(){const s=u(),e=/^@font-face\s*/.exec(i);if(!e)return;if(d(e),!f())return l("@font-face missing '{'");let n=$(),r=C();for(;r;)n.push(r),n=n.concat($()),r=C();return y()?s({type:t.CssTypes.fontFace,declarations:n}):l("@font-face missing '}'")}()||function(){const s=u(),e=/^@font-feature-values\s+([^{]+)/.exec(i);if(!e)return;const n=c(d(e)[1]);if(!f())return l("@font-feature-values missing '{'");const r=w();return y()?s({type:t.CssTypes.fontFeatureValues,fontFamily:n,rules:r}):l("@font-feature-values missing '}'")}()||function(){const s=u(),e=/^@container *([^{]+)/.exec(i);if(!e)return;const n=c(d(e)[1]);if(!f())return l("@container missing '{'");const r=w();return y()?s({type:t.CssTypes.container,container:n,rules:r}):l("@container missing '}'")}()||function(){const s=u(),e=/^@starting-style\s*/.exec(i);if(!e)return;if(d(e),!f())return l("@starting-style missing '{'");const n=w();return y()?s({type:t.CssTypes.startingStyle,rules:n}):l("@starting-style missing '}'")}()||function(){const s=u(),e=/^@layer *([^{;@]+)/.exec(i);if(!e)return;const n=c(d(e)[1]);if(!f()){const e=/^[;\s]*/.exec(i);return e&&d(e),s({type:t.CssTypes.layer,layer:n})}const r=w();return y()?s({type:t.CssTypes.layer,layer:n,rules:r}):l("@layer missing '}'")}()||function(){const s=u(),e=/^@property\s+(--[-\w]+)\s*/.exec(i);if(!e)return;const n=d(e)[1];if(!f())return l("@property missing '{'");let r=$(),o=C();for(;o;)r.push(o),r=r.concat($()),o=C();return y()?s({type:t.CssTypes.property,name:n,declarations:r}):l("@property missing '}'")}()||function(){const s=u(),e=/^@counter-style\s+([-\w]+)\s*/.exec(i);if(!e)return;const n=d(e)[1];if(!f())return l("@counter-style missing '{'");let r=$(),o=C();for(;o;)r.push(o),r=r.concat($()),o=C();return y()?s({type:t.CssTypes.counterStyle,name:n,declarations:r}):l("@counter-style missing '}'")}()||function(){const s=u(),e=/^@scope\s*([^{]*)/.exec(i);if(!e)return;const n=c(d(e)[1]);if(!f())return l("@scope missing '{'");const r=w();return y()?s({type:t.CssTypes.scope,scope:n,rules:r}):l("@scope missing '}'")}()||function(){const s=u(),e=/^@view-transition\s*/.exec(i);if(!e)return;if(d(e),!f())return l("@view-transition missing '{'");let n=$(),r=C();for(;r;)n.push(r),n=n.concat($()),r=C();return y()?s({type:t.CssTypes.viewTransition,declarations:n}):l("@view-transition missing '}'")}()||function(){const s=u(),e=/^@position-try\s+(--[-\w]+)\s*/.exec(i);if(!e)return;const n=d(e)[1];if(!f())return l("@position-try missing '{'");let r=$(),o=C();for(;o;)r.push(o),r=r.concat($()),o=C();return y()?s({type:t.CssTypes.positionTry,name:n,declarations:r}):l("@position-try missing '}'")}()||function(){const s=u(),e=A.exec(i);if(!e)return;const n=d(e)[1];if(!f())return l(`@${n} missing '{'`);let r=$(),o=C();for(;o;)r.push(o),r=r.concat($()),o=C();return y()?s({type:t.CssTypes.pageMarginBox,name:n,declarations:r}):l(`@${n} missing '}'`)}()||function(){const s=u(),e=/^@([-\w]+)\s*/.exec(i);if(!e)return;const n=d(e)[1];let o="";const h=r(i,["{",";"]);-1!==h&&h>0&&(o=c(i.substring(0,h)),d([i.substring(0,h)]));if(f()){const e=w();return y()?s({type:t.CssTypes.atRule,name:n,prelude:o,rules:e}):l(`@${n} missing '}'`)}const a=/^[;\s]*/.exec(i);return a&&d(a),s({type:t.CssTypes.atRule,name:n,prelude:o})}()}function E(){const s=u(),e=x();return e?($(),s({type:t.CssTypes.rule,selectors:e,declarations:b()||[]})):l("selector missing")}return h(function(){const s=function(){let t;const s=[];g(),$(s);for(;i.length;){if("}"===i.charAt(0)){if(n?.silent){l("extra '}'");d(["}"]),g(),$(s);continue}break}if(t=S()||E(),!t){if(n?.silent){d([i.charAt(0)]),g(),$(s);continue}break}s.push(t),$(s)}return s}();return{type:t.CssTypes.stylesheet,stylesheet:{source:n?.source,rules:s,parsingErrors:p}}}())},u=(t,s)=>new a(s||{}).compile(t);var p={parse:m,stringify:u};t.default=p,t.parse=m,t.stringify=u,Object.defineProperty(t,"__esModule",{value:!0})}); //# sourceMappingURL=adobe-css-tools.js.map