"use strict";self;(()=>{var e={d:(exports,definition)=>{for(var key in definition)e.o(definition,key)&&!e.o(exports,key)&&Object.defineProperty(exports,key,{enumerable:!0,get:definition[key]})},o:(obj,prop)=>Object.prototype.hasOwnProperty.call(obj,prop)},t={};const FROM_CSS={domain:"domains","url-prefix":"urlPrefixes",url:"urls",regexp:"regexps"};function extractSections({code,styleId,fast=!0}){const hasSingleEscapes=/([^\\]|^)\\([^\\]|$)/,parser=new parserlib.css.Parser({noValidation:!0,starHack:!0,topDocOnly:fast}),sectionStack=[{code:"",start:0}],errors=[],sections=[];let mozStyle;parser.addListener("startstylesheet",()=>{mozStyle=parser.stream.source.string}),parser.addListener("startdocument",e=>{const lastSection=sectionStack[sectionStack.length-1];let outerText=mozStyle.slice(lastSection.start,e.offset);const lastCmt=getLastComment(outerText),section={code:"",start:e.brace.offset+1};lastCmt.includes("AGENT_SHEET")||/==userstyle==/i.test(lastCmt)||(lastCmt&&(section.code=lastCmt+"\n",outerText=outerText.slice(0,-lastCmt.length)),outerText=outerText.match(/^\s*/)[0]+outerText.trim()),outerText.trim()&&(lastSection.code=outerText,doAddSection(lastSection),lastSection.code="");for(const t of e.functions){const{name,expr}=t,aType=FROM_CSS[name.toLowerCase()],e=expr&&expr.parts[0],{uri:val=(e&&"regexps"===aType&&hasSingleEscapes.test(e.text)?e.text.slice(1,-1):e.string)}=t;(section[aType]=section[aType]||[]).push(val||"")}sectionStack.push(section)}),parser.addListener("enddocument",e=>{const section=sectionStack.pop(),lastSection=sectionStack[sectionStack.length-1];section.code+=mozStyle.slice(section.start,e.offset),lastSection.start=e.offset+1,doAddSection(section)}),parser.addListener("endstylesheet",()=>{const lastSection=sectionStack[sectionStack.length-1];lastSection.code+=mozStyle.slice(lastSection.start),sectionStack.forEach(doAddSection)}),parser.addListener("error",e=>{errors.push(e);const t=e.offset,s=Math.max(mozStyle.lastIndexOf("\n",t-5)+1,t-100),r=Math.min(mozStyle.indexOf("\n",t-s>5?t:t+5)+1||1e9,t+100);e.context=mozStyle.slice(s,r).trim()});try{parser.parse(code,{reuseCache:!extractSections.lastStyleId||styleId===extractSections.lastStyleId})}catch(e){errors.push(e)}for(const err of errors){for(const[e,t]of Object.entries(err))"object"==typeof t&&delete err[e];err.message=`${err.line}:${err.col} ${err.message}`}return extractSections.lastStyleId=styleId,{sections,errors};function doAddSection(section){section.code=section.code.trim(),(section.code||section.urls||section.urlPrefixes||section.domains||section.regexps)&&"@namespace url(http://www.w3.org/1999/xhtml);"!==section.code&&sections.push(Object.assign({},section))}function getLastComment(text){let close,open=text.length;for(;open&&(close=text.lastIndexOf("*/",open-2),!(close<0));){if(!!text.substring(close+2,open).trim())break;const prevClose=text.lastIndexOf("*/",close-2);open=text.indexOf("/*",prevClose<0?0:prevClose+2)}return open?text.slice(open):text}}e.d(t,{default:()=>extractSections}),self.extractSections=t.default})();