@teacss/autocomplete 0.3.0

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/LICENSE ADDED
@@ -0,0 +1,22 @@
1
+ # MIT License
2
+
3
+ Copyright (c) 2021-PRESENT Anthony Fu <https://github.com/antfu>
4
+ Copyright (c) 2026-PRESENT Billgo <hi@billgo.me>
5
+
6
+ Permission is hereby granted, free of charge, to any person obtaining a copy
7
+ of this software and associated documentation files (the "Software"), to deal
8
+ in the Software without restriction, including without limitation the rights
9
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10
+ copies of the Software, and to permit persons to whom the Software is
11
+ furnished to do so, subject to the following conditions:
12
+
13
+ The above copyright notice and this permission notice shall be included in all
14
+ copies or substantial portions of the Software.
15
+
16
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
22
+ SOFTWARE.
package/README.md ADDED
@@ -0,0 +1,38 @@
1
+ # @teacss/autocomplete
2
+
3
+ **Completion suggestions for TeaCSS tooling.**
4
+
5
+ ## Purpose
6
+
7
+ `@teacss/autocomplete` turns the autocomplete metadata from a configured
8
+ TeaCSS generator into bounded utility suggestions for partial tokens and cursor
9
+ positions. It is intended for language-service and editor-tooling authors.
10
+
11
+ It does not discover CSS-entry configuration, define a utility vocabulary,
12
+ generate CSS, or implement an editor protocol. Callers supply the configured
13
+ generator and decide how suggestions are transported and presented.
14
+
15
+ ## Usage
16
+
17
+ ```ts
18
+ import { createAutocomplete } from "@teacss/autocomplete";
19
+
20
+ const autocomplete = createAutocomplete(generator, { matchType: "prefix" });
21
+
22
+ await autocomplete.suggest("bg-color:r");
23
+ await autocomplete.suggestInFile(code, offset);
24
+ ```
25
+
26
+ File-aware suggestions recognize both quoted class attributes and valid
27
+ unquoted values such as `class=p:`.
28
+
29
+ Used by `@teacss/language-service`.
30
+
31
+ ## Status
32
+
33
+ Pre-1.0. Completion output follows the resolved TeaCSS config. Each public
34
+ completion request is intentionally bounded to at most 1,000 suggestions and
35
+ 600,000 suggestion characters, so very large candidate spaces return a
36
+ query-directed result set instead of an exhaustive list. Candidate scanning,
37
+ async template concurrency, and the shared completion cache are bounded
38
+ independently as well.
@@ -0,0 +1,59 @@
1
+ import { AutoCompleteFunction, SuggestResult, TeacssGenerator } from "@teacss/core";
2
+ import { LRUCache } from "lru-cache";
3
+ //#region src/parse.d.ts
4
+ declare class AutocompleteParseError extends Error {
5
+ readonly template?: string | undefined;
6
+ constructor(message: string, template?: string | undefined);
7
+ toString(): string;
8
+ }
9
+ declare const shorthands: Record<string, string>;
10
+ declare const ignoredThemeKeys: string[];
11
+ declare function parseAutocomplete(template: string, theme?: any, extraShorthands?: Record<string, string>): ParsedAutocompleteTemplate;
12
+ //#endregion
13
+ //#region src/types.d.ts
14
+ type AutoCompleteMatchType = "prefix" | "fuzzy";
15
+ interface AutocompleteOptions {
16
+ matchType?: AutoCompleteMatchType;
17
+ throwErrors?: boolean;
18
+ }
19
+ type AutocompleteTemplatePart = AutocompleteTemplateStatic | AutocompleteTemplateGroup | AutocompleteTemplateTheme;
20
+ interface AutocompleteTemplateStatic {
21
+ type: "static";
22
+ value: string;
23
+ }
24
+ interface AutocompleteTemplateGroup {
25
+ type: "group";
26
+ values: string[];
27
+ }
28
+ interface AutocompleteTemplateTheme {
29
+ type: "theme";
30
+ objects: Record<string, unknown>[];
31
+ }
32
+ interface ParsedAutocompleteTemplate {
33
+ parts: AutocompleteTemplatePart[];
34
+ suggest: (input: string, matchType?: AutoCompleteMatchType) => string[] | undefined;
35
+ errors: AutocompleteParseError[];
36
+ }
37
+ interface TeacssAutocomplete {
38
+ suggest: (input: string, allowsEmptyInput?: boolean) => Promise<string[]>;
39
+ suggestInFile: (content: string, cursor: number) => Promise<SuggestResult | undefined>;
40
+ templates: (string | AutoCompleteFunction)[];
41
+ cache: LRUCache<string, string[]>;
42
+ errorCache: Map<string, AutocompleteParseError[]>;
43
+ reset: () => void;
44
+ enumerate: () => Promise<Set<string>>;
45
+ }
46
+ //#endregion
47
+ //#region src/create.d.ts
48
+ declare function createAutocomplete(generator: TeacssGenerator, options?: AutocompleteOptions): TeacssAutocomplete;
49
+ //#endregion
50
+ //#region src/utils.d.ts
51
+ declare function searchUsageBoundary(line: string, index: number, attributify?: boolean): {
52
+ content: string;
53
+ start: number;
54
+ end: number;
55
+ } | undefined;
56
+ declare function searchAttrKey(content: string, cursor: number): string | undefined;
57
+ declare function cartesian<T>(arr: T[][]): T[][];
58
+ //#endregion
59
+ export { AutoCompleteMatchType, AutocompleteOptions, AutocompleteParseError, AutocompleteTemplateGroup, AutocompleteTemplatePart, AutocompleteTemplateStatic, AutocompleteTemplateTheme, ParsedAutocompleteTemplate, TeacssAutocomplete, cartesian, createAutocomplete, ignoredThemeKeys, parseAutocomplete, searchAttrKey, searchUsageBoundary, shorthands };
package/dist/index.js ADDED
@@ -0,0 +1,2 @@
1
+ import{toArray as e,uniq as t}from"@teacss/core";import{Fzf as n,byLengthAsc as r,byStartAsc as i}from"fzf";import{LRUCache as a}from"lru-cache";var o=`@teacss/autocomplete`;const s=2e6,c=5e4,l=4096,u=1e3,d=5e7,f=1e5,p=new Map(Array.from(`ÀÁÂÃÄÅÇÈÉÊËÌÍÎÏÑÒÓÔÕÖØÙÚÛÜÝßàáâãäåçèéêëìíîïñòóôõöøùúûüýÿĀāĂ㥹ĆćĈĉĊċČčĎďđĒēĔĕĖėĘęĚěĜĝĞğĠġĢģĤĥħĨĩĪīĬĭĮįİıĴĵĶķĹĺĻļĽľŀłŃńŅņŇňŌōŎŏŐőŔŕŖŗŘřŚśŜŝŞşŠšŢţŤťŧŨũŪūŬŭŮůŰűŲųŴŵŶŷŸŹźŻżŽžſƀƁƃƆƈƉƊƌƎƐƒƓƗƙƚƜƝƞƟƠơƥƫƭƮƯưƲƴƶǍǎǏǐǑǒǓǔǗǘǝǥǦǧǨǩǪǫǰǴǵǸǹȀȁȂȃȄȅȆȇȈȉȊȋȌȍȎȏȐȑȒȓȔȕȖȗȘșȚțȞȟȠȡȥȦȧȨȩȮȯȲȳȴȵȶȷȺȻȼȽȾȿɀɃɄɅɆɇɈɉɊɋɌɍɎɏɐɑɓɔɕɖɗɘɛɜɝɞɟɠɡɢɥɦɨɪɫɬɭɯɰɱɲɳɴɵɹɺɻɼɽɾɿʀʁʂʇʈʉʋʌʍʎʏʐʑʗʙʚʛʜʝʞʟʠʮͣͤͥͦͧͨͩͪͫͬͭͮͯᴀᴃᴄᴅᴇᴈᴉᴊᴋᴌᴍᴎᴏᴐᴑᴒᴓᴖᴗᴘᴙᴚᴛᴜᴝᴞᴟᴠᴡᴢᵢᵣᵤᵥḀḁḂḃḄḅḆḇḊḋḌḍḎḏḐḑḒḓḘḙḚḛḞḟḠḡḢḣḤḥḦḧḨḩḪḫḬḭḮḯḰḱḲḳḴḵḶḷḺḻḼḽḾḿṀṁṂṃṄṅṆṇṈṉṊṋṔṕṖṗṘṙṚṛṞṟṠṡṢṣṪṫṬṭṮṯṰṱṲṳṴṵṶṷṼṽṾṿẀẁẂẃẄẅẆẇẈẉẊẋẌẍẎẏẐẑẒẓẔẕẖẗẘẙẚẛẠạẢảẤấẦầẨẩẪẫẬậẮắẰằẲẳẴẵẶặẸẹẺẻẼẽẾếỀềỂểỄễỆệỈỉỊịỌọỎỏỐốỒồỔổỖỗỘộỚớỜờỞởỠỡỢợỤụỦủỨứỪừỬửỮữỰựỲỳỴỵỶỷỸỹⁱₕₖₗₘₙₚₛₜↄ`,(e,t)=>[e,`AAAAAACEEEEIIIINOOOOOOUUUUYsaaaaaaceeeeiiiinoooooouuuuyyAaAaAaCcCcCcCcDddEeEeEeEeEeGgGgGgGgHhhIiIiIiIiIiJjKkLlLlLlllNnNnNnOoOoOoRrRrRrSsSsSsSsTtTttUuUuUuUuUuUuWwYyYZzZzZzsbBbOcDDdEEfGIklMNnOOopttTUuVyzAaIiOoUuUuegGgKkOojGgNnAaAaEeEeIiIiOoOoRrRrUuUuSsTtHhNdzAaEeOoYylntjACcLTszBUVEeJjQqRrYyaabocddeeeeejggGhhiIlllmmmnnNorrrrrrrRRsttuvvwyYzzcBeGHjkLqhaeioucdhmrtvxABCDEeiJKLMNOOoooooPRRTUuumVWZiruvAaBbBbBbDdDdDdDdDdEeEeFfGgHhHhHhHhHhIiIiKkKkKkLlLlLlMmMmMmNnNnNnNnPpPpRrRrRrSsSsTtTtTtTtUuUuUuVvVvWwWwWwWwWwXxXxYyZzZzZzhtwyasAaAaAaAaAaAaAaAaAaAaAaAaEeEeEeEeEeEeEeEeIiIiOoOoOoOoOoOoOoOoOoOoOoOoUuUuUuUuUuUuUuYyYyYyYyihklmnpstc`[t]])),m={maxAttempts:c,maxCandidateLength:l,maxCandidates:5e4,maxCharacters:s,maxScans:f,maxScannedCharacters:5e7},h={...m,maxCandidateLength:s,maxCandidates:u};function g(){return{suggestions:[],attempts:0,candidates:0,characters:0,scans:0,truncated:!1}}const _=new WeakMap,v=new WeakMap;function y(e,t,n){let r=_.get(e);if(!r){let n=e.suggest(t,`prefix`)??[];return{suggestions:n,attempts:n.length,candidates:n.length,characters:n.reduce((e,t)=>e+t.length,0),scans:n.length,truncated:!1}}return r(t,n)}function b(e,t,n){let r=v.get(e);return r?r(t,n):y(e,t,n)}var x=class extends Error{template;constructor(e,t){super(e),this.template=t,this.name=o,this.template=t}toString(){return`⚠️ [${this.name}]: ${this.message}. ${this.template?`Template: ${this.template}.`:``}`}};const S={directions:`(x|y|t|b|l|r|s|e)`,num:`(${[0,1,2,3,4,5,6,8,10,12,24,36].join(`|`)})`,percent:`(${[0,10,20,30,40,50,60,70,80,90,100].join(`|`)})`,percentage:`(${[`10%`,`20%`,`30%`,`40%`,`50%`,`60%`,`70%`,`80%`,`90%`,`100%`].join(`|`)})`},C=[`DEFAULT`];function w(e,t,n,r){let i=0;Array.from(e.matchAll(t)).forEach(t=>{let a=t.index;i!==a&&r(e.slice(i,a),i,a),n(t),i=a+t[0].length}),i!==e.length&&r(e.slice(i),i,e.length)}function ee(e,t={},r={}){let i=[],a=[],o={...S,...r};e=e.replace(/<([\w-]+)>/g,(e,t,n,r)=>Object.hasOwn(o,t)?o[t]:(a.push(new x(`Unknown template shorthand: <${t}>`,r)),e)),d(e),a.length&&(i.length=0);let s={parts:i,suggest:f,errors:a};return _.set(s,y),v.set(s,p),s;function c(e){w(e,/\$([\w.|-]+)/g,e=>{i.push({type:`theme`,objects:e[1].split(`|`).map(n=>n.split(`.`).reduce((t,n)=>!n||typeof t!=`object`||!t||!Object.hasOwn(t,n)||!t[n]?(a.push(new x(`Invalid theme key: ${n}`,e.input)),{}):t[n],t))})},e=>{i.push({type:`static`,value:e})})}function d(e){w(e,/\((.*?)\)/g,e=>{if(!e[1].includes(`|`)){i.push({type:`static`,value:e[0]});return}i.push({type:`group`,values:e[1].split(`|`)})},e=>{c(e)})}function f(e,t=`prefix`){if(e.length>1&&t===`fuzzy`){let t=e!==e.toLowerCase(),r=N(e,t),a=y(e,{maxCandidates:u}).suggestions.filter(e=>A(r,N(e,t),e,0));if(r.length>l)return a;let o=ke(i,{},e).candidates;if(a.length){let e=new Set(a);if(o.every(t=>e.has(t)))return a}if(re(e,o.reduce((e,t)=>e+t.length,0))){let t=te(o,e),n=t.filter(t=>oe(t,e));return n.length?we(n,[...a,...t]):we(a,t)}return we(a,new n(o,{fuzzy:`v1`,limit:u}).find(e).map(e=>e.item))}return p(e).suggestions}function p(e,t={}){let n={...h,...t},r=O(e);if(r.length>n.maxCandidateLength)return g();let a=T(i);if(a){let t=E(i,0,a.index);if(!L(t,e)&&!L(O(t),r))return g();let o=E(i,a.index+1,i.length);return me(a.part,t,o,e,a.suppressPartialRoots,n)}let o=D(i);return o&&!L(o,e)&&!L(O(o),O(e))?g():ce(i,e,n)}function y(e,t={}){let n={...m,...t},r=p(e,n),a=D(i);if(r.suggestions.length||!a)return r;let o={...n,maxAttempts:n.maxAttempts-r.attempts,maxCandidates:n.maxCandidates-r.candidates,maxCharacters:n.maxCharacters-r.characters,maxScans:n.maxScans-r.scans},s=p(a+e,o);return{suggestions:s.suggestions,attempts:r.attempts+s.attempts,candidates:r.candidates+s.candidates,characters:r.characters+s.characters,scans:r.scans+s.scans,truncated:r.truncated||s.truncated}}}function T(e){let t,n=!1;for(let r=0;r<e.length;r++){let i=e[r];if(i.type!==`static`){if(i.type===`group`&&i.values.length>0&&i.values.every(e=>e===``)){n=!0;continue}if(i.type!==`theme`||t)return;t={index:r,part:i}}}return t&&{...t,suppressPartialRoots:n}}function E(e,t,n){let r=``;for(let i=t;i<n;i++){let t=e[i];t.type===`static`&&(r+=t.value)}return r}function D(e){let t=e.findIndex(e=>e.type!==`static`);return E(e,0,t<0?e.length:t)}function O(e){return e.replace(/-/g,``)}function te(e,t){return k(e,t)}function k(e,t,n={}){let r={...m,maxCandidates:u,...n};if(!t)return ne(e,r);let i=t!==t.toLowerCase(),a=N(t,i);if(a.length>r.maxCandidateLength)return[];let o={characters:0,items:[],retained:new Set},s=new Set,c=e[Symbol.iterator](),l=0,d=0;for(;l<r.maxAttempts&&d<r.maxScannedCharacters;){let e=c.next();if(e.done)break;let t=e.value,n=l++;if(!t||t.length>r.maxCandidateLength||s.has(t)||t.length>r.maxScannedCharacters-d)continue;s.add(t),d+=t.length;let u=A(a,N(t,i),t,n);u&&ie(o,u,r.maxCandidates,r.maxCharacters)}return o.items.sort(M).map(({candidate:e})=>e)}function ne(e,t){let n=[],r=new Set,i=e[Symbol.iterator](),a=0,o=0,s=0;for(;a<t.maxAttempts&&n.length<t.maxCandidates&&o<t.maxCharacters&&s<t.maxScannedCharacters;){let e=i.next();if(e.done)break;let c=e.value;a++,!(!c||c.length>t.maxCandidateLength||r.has(c)||c.length>t.maxScannedCharacters-s)&&(r.add(c),s+=c.length,!(o+c.length>t.maxCharacters)&&(n.push(c),o+=c.length))}return n}function re(e,t){return e.length*t>d}function A(e,t,n,r){if(t===e)return{candidate:n,category:0,gaps:0,longestRun:e.length,start:0,order:r};if(t.startsWith(e))return{candidate:n,category:1,gaps:0,longestRun:e.length,start:0,order:r};let i=0,a=-1,o=-1,s=0,c=0,l=0;for(let n=0;n<t.length&&i<e.length;n++)t[n]===e[i]&&(a<0&&(a=n),o>=0&&(l+=n-o-1),s=n===o+1?s+1:1,c=Math.max(c,s),o=n,i++);if(i===e.length)return{candidate:n,category:2,gaps:l,longestRun:c,start:a,order:r}}function ie(e,t,n,r){e.retained.has(t.candidate)||(e.items.length<n&&e.characters+t.candidate.length<=r?(e.items.push(t),e.retained.add(t.candidate),e.characters+=t.candidate.length,j(e.items,e.items.length-1)):e.items.length&&M(t,e.items[0])<0&&e.characters-e.items[0].candidate.length+t.candidate.length<=r&&(e.retained.delete(e.items[0].candidate),e.characters+=t.candidate.length-e.items[0].candidate.length,e.items[0]=t,e.retained.add(t.candidate),ae(e.items,0)))}function j(e,t){for(;t>0;){let n=t-1>>>1;if(M(e[t],e[n])<=0)return;[e[n],e[t]]=[e[t],e[n]],t=n}}function ae(e,t){for(;;){let n=t*2+1;if(n>=e.length)return;let r=n+1,i=n;if(r<e.length&&M(e[r],e[n])>0&&(i=r),M(e[i],e[t])<=0)return;[e[t],e[i]]=[e[i],e[t]],t=i}}function M(e,t){return e.category-t.category||e.gaps-t.gaps||t.longestRun-e.longestRun||e.start-t.start||e.candidate.length-t.candidate.length||e.order-t.order}function oe(e,t){let n=t!==t.toLowerCase();return N(e,n)===N(t,n)}function N(e,t){let n=e.normalize(),r=se(n)?n:Array.from(n,e=>p.get(e)??e).join(``);return t?r:r.toLowerCase()}function se(e){for(let t=0;t<e.length;t++)if(e.charCodeAt(t)>127)return!1;return!0}function ce(e,t,n={}){let r={...m,...n};if(r.maxAttempts<=0||r.maxCandidates<=0||r.maxCharacters<=0)return g();let i=O(t),a=le(),o=le(),s=r.maxCandidates,c=B(r.maxScans),l=[],u=Array.from({length:e.length},()=>``),d=Array.from({length:e.length+1},()=>0),f=Array.from({length:e.length+1},()=>0),p=Array.from({length:e.length+1},()=>0),h=[],_=new Set,v=0,y=0;for(;y>=0&&!c.truncated;){if(y===e.length){let e=u.join(``),n=f[y]>=t.length,c=p[y]>=i.length;if((n||c)&&e.length<=r.maxCharacters){let t=!_.has(e);(!t||v<r.maxAttempts)&&(t&&(_.add(e),v++),n&&ue(a,e,h,s,r),c&&ue(o,e,h,s,r))}y--;continue}if(v>=r.maxAttempts)break;let n=l[y];n||(n={choiceIndex:0,iterator:Te(e[y],r.maxCandidateLength-d[y],c)},l[y]=n);let m=n.iterator.next();if(m.done){l.pop(),y--;continue}let g=n.choiceIndex++,b=m.value,x=d[y]+b.length;if(x>r.maxCandidateLength)continue;let S=f[y]<0?-1:I(t,f[y],b,!1),C=p[y]<0?-1:I(i,p[y],b,!0);if(S<0&&C<0)continue;for(;h.length&&!(h.at(-1).depth<y);)h.pop();g>0&&h.push({depth:y,index:g}),u[y]=b;let w=y+1;d[w]=x,f[w]=S,p[w]=C,l.length=w,y=w}let b=a.entries.length?a:o;b.entries.sort((e,t)=>F(e.path,t.path));let x=b.entries.map(e=>e.candidate);return{suggestions:x,attempts:v,candidates:x.length,characters:b.characters,scans:c.initial-c.remaining,truncated:c.truncated}}function le(){return{characters:0,entries:[],indices:new Map}}function ue(e,t,n,r,i){let a=e.indices.get(t);if(a!==void 0){let t=e.entries[a];F(n,t.path)<0&&(t.path=n.slice(),P(e,a));return}if(r<=0||t.length>i.maxCharacters)return;let o={candidate:t,path:n.slice()};if(e.entries.length>=r){if(F(o.path,e.entries[0].path)>=0)return;de(e)}for(;e.entries.length&&e.characters+t.length>i.maxCharacters;){if(F(o.path,e.entries[0].path)>=0)return;de(e)}e.characters+t.length>i.maxCharacters||(e.indices.set(t,e.entries.length),e.entries.push(o),e.characters+=t.length,fe(e,e.entries.length-1))}function de(e){let t=e.entries[0],n=e.entries.pop();e.indices.delete(t.candidate),e.characters-=t.candidate.length,e.entries.length&&(e.entries[0]=n,e.indices.set(n.candidate,0),P(e,0))}function fe(e,t){for(;t>0;){let n=t-1>>>1;if(F(e.entries[t].path,e.entries[n].path)<=0)return;pe(e,n,t),t=n}}function P(e,t){for(;;){let n=t*2+1;if(n>=e.entries.length)return;let r=n+1,i=n;if(r<e.entries.length&&F(e.entries[r].path,e.entries[n].path)>0&&(i=r),F(e.entries[i].path,e.entries[t].path)<=0)return;pe(e,i,t),t=i}}function pe(e,t,n){[e.entries[t],e.entries[n]]=[e.entries[n],e.entries[t]],e.indices.set(e.entries[t].candidate,t),e.indices.set(e.entries[n].candidate,n)}function F(e,t){let n=e.length-1,r=t.length-1;for(;n>=0||r>=0;){let i=n>=0?e[n].depth:-1,a=r>=0?t[r].depth:-1,o=Math.max(i,a),s=i===o?e[n--].index:0,c=a===o?t[r--].index:0;if(s!==c)return s-c}return 0}function I(e,t,n,r){let i=t;for(let t=0;t<n.length;t++){let a=n[t];if(!(r&&a===`-`)){if(i<e.length&&e[i]!==a)return-1;i++}}return i}function L(e,t){return e.length<=t.length?t.startsWith(e):e.startsWith(t)}function me(e,t,n,r,i,a){let o={...m,...a};if(t.length+1>o.maxCandidateLength)return g();let s=B(o.maxScans),c=he(e.objects,s),l=ge(r,!1,o),u=ge(O(r),!0,o);R(c,t,n,o.maxCandidateLength,i,l,u,s);let d=ve(l,s);if(d.suggestions.length||!d.exhausted)return d;let f=ve(u,s);return{suggestions:f.suggestions,attempts:d.attempts+f.attempts,candidates:d.candidates+f.candidates,characters:d.characters+f.characters,scans:f.scans,truncated:f.truncated}}function R(e,t,n,r,i,a,o,s){for(let c of e){let e=t+c.key,l=ye(e,a.input,!1),u=ye(e,o.input,!0);if(l===`none`&&u===`none`)continue;let d=xe(c.objects,e,n,a.input,o.input,r),f=l===`partial`||u===`partial`?Se(d,s):void 0,p=f!==void 0;if(be(a,l,c.hasLeaf,p,e,n,i),be(o,u,c.hasLeaf,p,e,n,i),a.blocked)return;for(f??=Se(d,s);f;){if((l===`reached`||i&&l===`partial`)&&_e(a,f.candidate,f.rawMatch),(u===`reached`||i&&u===`partial`)&&_e(o,f.candidate,f.normalizedMatch),a.blocked)return;f=Se(d,s)}if(s.truncated||a.blocked)return}}function z(e){return!!e&&e[0]!==`_`&&!C.includes(e)}function B(e=f){let t=Math.max(0,e);return{initial:t,remaining:t,truncated:!1}}function V(e){return e.remaining<=0?(e.truncated=!0,!1):(e.remaining--,!0)}function*H(e){yield*Object.keys(e)}function he(e,t){let n=new Map;outer:for(let r of e)for(let e of H(r)){if(!V(t))break outer;if(!z(e))continue;let i=r[e];if(i==null)continue;let a=n.get(e)??{key:e,hasLeaf:!1,objects:[]};if(typeof i!=`object`||Array.isArray(i))a.hasLeaf=!0;else{let e=i;a.objects.push(e),a.hasLeaf||=Object.hasOwn(e,`DEFAULT`)&&e.DEFAULT!==null&&e.DEFAULT!==void 0}n.set(e,a)}return[...n.values()]}function ge(e,t,n){return{attempts:0,blocked:n.maxAttempts<=0||n.maxCandidates<=0||n.maxCharacters<=0,characters:0,input:e,limits:n,normalize:t,seen:new Set,suggestions:[]}}function _e(e,t,n){!n||e.blocked||e.seen.has(t)||(e.seen.add(t),e.attempts++,t.length<=e.limits.maxCandidateLength&&e.characters+t.length<=e.limits.maxCharacters&&(e.suggestions.push(t),e.characters+=t.length),e.blocked||=e.attempts>=e.limits.maxAttempts||e.suggestions.length>=e.limits.maxCandidates||e.characters>=e.limits.maxCharacters)}function ve(e,t){return{suggestions:e.suggestions,attempts:e.attempts,candidates:e.suggestions.length,characters:e.characters,scans:t.initial-t.remaining,truncated:t.truncated,exhausted:!e.blocked&&!t.truncated}}function ye(e,t,n){let r=n?O(e):e;return t.startsWith(r)?`reached`:r.startsWith(t)?`partial`:`none`}function be(e,t,n,r,i,a,o){if(t===`none`)return;if(t===`partial`&&r){(n||!o)&&_e(e,i,!0);return}if(!n)return;let s=i+a;_e(e,s,(e.normalize?O(s):s).startsWith(e.input))}function xe(e,t,n,r,i,a){return{base:t,fragments:[],frames:[],maxCandidateLength:a,normalizedInput:i,normalizedMatchedLength:I(i,0,t,!0),objectIndex:0,objects:e,rawInput:r,rawMatchedLength:I(r,0,t,!1),staticSuffix:n}}function Se(e,t){for(;!t.truncated;){if(!e.frames.length){if(e.objectIndex>=e.objects.length)return;let t=e.objects[e.objectIndex++];e.frames.push({depth:0,iterator:H(t),normalizedMatchedLength:e.normalizedMatchedLength,object:t,rawMatchedLength:e.rawMatchedLength,valueLength:0})}let n=e.frames.at(-1),r=n.iterator.next();if(r.done){e.frames.pop(),e.fragments.length=n.depth;continue}if(!V(t))return;let i=r.value;if(!z(i))continue;let a=n.object[i];if(a==null)continue;let o=n.valueLength+ +!!n.depth+i.length;if(e.base.length+o+e.staticSuffix.length+1>e.maxCandidateLength)continue;let s=`-${i}`,c=n.rawMatchedLength<0?-1:I(e.rawInput,n.rawMatchedLength,s,!1),l=n.normalizedMatchedLength<0?-1:I(e.normalizedInput,n.normalizedMatchedLength,s,!0);if(c<0&&l<0)continue;e.fragments.length=n.depth,e.fragments.push(i);let u=typeof a==`object`&&!Array.isArray(a)?a:void 0;if(u&&e.frames.push({depth:n.depth+1,iterator:H(u),normalizedMatchedLength:l,object:u,rawMatchedLength:c,valueLength:o}),!(!u||Object.hasOwn(u,`DEFAULT`)&&u.DEFAULT!==null&&u.DEFAULT!==void 0))continue;let d=Ce(e.rawInput,c,e.staticSuffix,!1),f=Ce(e.normalizedInput,l,e.staticSuffix,!0);if(!(!d&&!f))return{candidate:`${e.base}-${e.fragments.join(`-`)}${e.staticSuffix}`,normalizedMatch:f,rawMatch:d}}}function Ce(e,t,n,r){return t<0?!1:I(e,t,n,r)>=e.length}function we(e,t){let n=[],r=new Set,i=0,a=(e,t)=>{for(let a of e){if(n.length===t)return;if(!(!a||r.has(a)||a.length>l)){if(i+a.length>s)return;r.add(a),n.push(a),i+=a.length}}};return a(e,t.length?750:u),a(t,u),a(e,u),n}function*Te(e,t,n){e.type===`theme`?yield*De(e.objects,t,n):yield*Ee(e,t,n)}function*Ee(e,t,n){if(e.type===`static`){e.value.length<=t&&(yield e.value);return}if(e.type===`group`)for(let r of e.values){if(!V(n))return;r.length<=t&&(yield r)}}function*De(e,t,n){let r=[];for(let i of e){r.length=0;let e=[{depth:0,iterator:H(i),object:i,valueLength:0}];for(;e.length&&!n.truncated;){let i=e.at(-1),a=i.iterator.next();if(a.done){e.pop(),r.length=i.depth;continue}if(!V(n))return;let o=a.value;if(!z(o))continue;let s=i.object[o];if(s==null)continue;let c=i.valueLength+ +!!i.depth+o.length;if(c>t)continue;r.length=i.depth,r.push(o);let l=typeof s==`object`&&!Array.isArray(s)?s:void 0;l&&e.push({depth:i.depth+1,iterator:H(l),object:l,valueLength:c}),(!l||Object.hasOwn(l,`DEFAULT`)&&l.DEFAULT!==null&&l.DEFAULT!==void 0)&&(yield r.join(`-`))}}}function Oe(e,t){let n=B(t.maxScans),r=e.map(e=>({done:!1,iterator:Te(e,t.maxCandidateLength,n),pending:void 0,seen:new Set,values:[]})),i=e.length+Math.max(0,t.maxCandidates-1),a=r.length,o=0,s=0,c=!1,l=r.length;for(;l&&!n.truncated;){let e=!1;for(let n of r){if(!n.values.length&&n.pending!==void 0&&o+n.pending.length<=t.maxCharacters){n.values.push(n.pending),o+=n.pending.length,n.pending=void 0,s++,l--,e=!0;continue}if(n.done)continue;let r=n.iterator.next();if(e=!0,r.done){n.done=!0,a--;continue}if(n.seen.has(r.value))continue;if(n.seen.add(r.value),!n.values.length){o+r.value.length<=t.maxCharacters?(n.values.push(r.value),o+=r.value.length,s++,l--):(n.pending===void 0||r.value.length<n.pending.length)&&(n.pending=r.value,c=!0);continue}let i=n.values[0];r.value.length<i.length&&(n.values[0]=r.value,o+=r.value.length-i.length,c=!0)}if(!e)break}for(;a&&s<i&&o<t.maxCharacters&&!n.truncated;){let e=!1;for(let n of r){if(n.done)continue;let r=n.iterator.next();if(r.done){n.done=!0,a--;continue}if(e=!0,!n.seen.has(r.value)){if(n.seen.add(r.value),o+r.value.length>t.maxCharacters){c=!0;continue}if(n.values.push(r.value),o+=r.value.length,s++,s===i)break}}if(!e)break}return c||=n.truncated||a>0||l>0,{scans:n.initial-n.remaining,truncated:c,values:r.map(e=>e.values)}}function ke(e,t={},n=``){let r={...m,...t},i=Oe(e,r),a=i.values,o=i.scans,s,l=()=>{if(s===void 0){let t=Ae(a,n,r);s=t?{combination:t,scans:0}:je(e,n,r,Math.max(0,r.maxScans-o)),o+=s.scans}return s};if(a.some(e=>!e.length)){let e=i.truncated?l().combination:void 0;if(!e)return{candidates:[],truncated:i.truncated,attempts:0,scans:o};let t=Ne(r),n={remaining:r.maxAttempts};return U(t,n,0)&&W(t,e),{candidates:[...t.candidates],truncated:!0,attempts:r.maxAttempts-n.remaining,scans:o}}let u=0;for(let e of a){let t=e[0].length;for(let n=1;n<e.length;n++)t=Math.min(t,e[n].length);if(u+=t,u>Math.min(r.maxCandidateLength,r.maxCharacters)){let e=i.truncated?l().combination:void 0;if(!e)return{candidates:[],truncated:!0,attempts:0,scans:o};let t=Ne(r),n={remaining:r.maxAttempts};return U(t,n,0)&&W(t,e),{candidates:[...t.candidates],truncated:!0,attempts:r.maxAttempts-n.remaining,scans:o}}}let f=1,p=0,h=i.truncated;for(let e of a){if(h)continue;let t=0;for(let n of e)if(t+=n.length,t>r.maxCharacters)break;let n=p*e.length,i=f*t;f>r.maxCandidates/e.length||f>r.maxAttempts/e.length||n>r.maxCharacters||i>r.maxCharacters-n?h=!0:(f*=e.length,p=n+i)}let g={remaining:r.maxAttempts};if(!h){let e=Ne(r);return Re(e,a,f,g),{candidates:[...e.candidates],truncated:!1,attempts:r.maxAttempts-g.remaining,scans:o}}let _=Ne(r),v=a.map(e=>e[0]),y=a.flatMap((e,t)=>e.length>1?[t]:[]),b=l().combination;b&&U(_,g,0)&&W(_,b),U(_,g,0)&&W(_,v);let x=Math.min(c,Math.max(0,g.remaining));return e.length&&x>d/e.length?{candidates:[..._.candidates],truncated:!0,attempts:r.maxAttempts-g.remaining,scans:o}:(Pe(_,a,v,y,g),Ie(_,a,v,y,g),Fe(_,a,v,y,g),Le(_,a,v,y,g),Re(_,a,r.maxAttempts,g,!0),{candidates:[..._.candidates],truncated:!0,attempts:r.maxAttempts-g.remaining,scans:o})}function Ae(e,t,n){if(!t||e.some(e=>!e.length))return;let r=t!==t.toLowerCase(),i=N(t,r);if(!i||i.length>n.maxCandidateLength)return;let a=Math.min(n.maxCandidateLength,n.maxCharacters),o=Array.from({length:e.length+1},()=>0);for(let t=e.length-1;t>=0;t--){let n=e[t][0].length;for(let r=1;r<e[t].length;r++)n=Math.min(n,e[t][r].length);o[t]=o[t+1]+n}if(o[0]>a)return;let s=[],c=0,l=0;for(let t=0;t<e.length;t++){let n,u=l;for(let s of e[t]){if(c+s.length+o[t+1]>a)continue;let e=Me(i,l,N(s,r)),d=e>l,f=u>l;(n===void 0||d&&!f||d===f&&(s.length<n.length||s.length===n.length&&e>u))&&(n=s,u=e)}if(n===void 0)return;s.push(n),c+=n.length,l=u}if(l<i.length)return;let u=s.join(``);if(A(i,N(u,r),u,0))return s}function je(e,t,n,r){let i=B(r),a=e=>({combination:e,scans:i.initial-i.remaining});if(!t)return a();let o=t!==t.toLowerCase(),s=N(t,o);if(!s||s.length>n.maxCandidateLength)return a();let l=Math.min(n.maxCandidateLength,n.maxCharacters),u=[{characters:0,choice:``,matched:0}],f=0,p=0;for(let t of e){let e=new Map,n=new Set;for(let r of Te(t,l,i)){if(n.has(r))continue;n.add(r);let t={normalized:N(r,o),raw:r};for(let n of u){if(p++,f+=t.normalized.length,p>c||f>d)return a();let r=n.characters+t.raw.length;if(r>l)continue;let i=Me(s,n.matched,t.normalized),o=e.get(i);o&&o.characters<=r||e.set(i,{characters:r,choice:t.raw,matched:i,previous:n})}}if(!e.size)return a();let r=1/0;u=[...e.values()].sort((e,t)=>t.matched-e.matched||e.characters-t.characters).filter(e=>e.characters>=r?!1:(r=e.characters,!0))}let m=u.find(e=>e.matched===s.length);if(!m)return a();let h=Array.from({length:e.length},()=>``),g=m;for(let t=e.length-1;t>=0;t--)h[t]=g.choice,g=g.previous;let _=h.join(``);return A(s,N(_,o),_,0)?a(h):a()}function Me(e,t,n){for(let r=0;r<n.length&&t<e.length;r++)n[r]===e[t]&&t++;return t}function Ne(e){return{candidates:new Set,characters:0,maxCandidateLength:e.maxCandidateLength,maxCandidates:e.maxCandidates,maxCharacters:e.maxCharacters}}function U(e,t,n){return n>=c||t.remaining<=0||e.candidates.size>=e.maxCandidates||e.characters>=e.maxCharacters?!1:(t.remaining--,!0)}function Pe(e,t,n,r,i){let a=0;for(let o of r){if(!U(e,i,a))return;a++;let r=n.slice();r[o]=t[o].at(-1),W(e,r)}}function Fe(e,t,n,r,i){let a=0;for(let o=0;o<r.length;o++)for(let s=o+1;s<r.length;s++){if(!U(e,i,a))return;a++;let c=r[o],l=r[s],u=n.slice();u[c]=t[c].at(-1),u[l]=t[l].at(-1),W(e,u)}}function Ie(e,t,n,r,i){let a=0;for(let o of r)for(let r=1;r<t[o].length-1;r++){if(!U(e,i,a))return;a++;let s=n.slice();s[o]=t[o][r],W(e,s)}}function Le(e,t,n,r,i){let a=0;for(let o=0;o<r.length;o++)for(let s=o+1;s<r.length;s++){let c=r[o],l=r[s];for(let r=1;r<t[c].length;r++)for(let o=1;o<t[l].length;o++){if(r===t[c].length-1&&o===t[l].length-1)continue;if(!U(e,i,a))return;a++;let s=n.slice();s[c]=t[c][r],s[l]=t[l][o],W(e,s)}}}function Re(e,t,n,r,i=!1){if(!t.length){U(e,r,0)&&W(e,[``]);return}let a=t.map(()=>0),o=t.flatMap((e,t)=>e.length>1?[t]:[]),s=()=>{let e=o.length-1;for(;e>=0;){let n=o[e];if(a[n]++,a[n]<t[n].length)return!0;a[n]=0,e--}return!1};if(i&&!s())return;let l=Math.min(n,c);for(let n=0;n<l;n++){if(!U(e,r,n))return;if(W(e,t.map((e,t)=>e[a[t]])),!s())break}}function W(e,t){let n=e.maxCharacters-e.characters,r=0;for(let i of t)if(r+=i.length,r>Math.min(e.maxCandidateLength,n))return;let i=t.join(``);e.candidates.has(i)||e.candidates.size===e.maxCandidates||e.characters+i.length>e.maxCharacters||(e.candidates.add(i),e.characters+=i.length)}function ze(e,t,n=!0){let r=t,i=t,a=/[^\s>"'`;]/;for(;r&&a.test(e.charAt(r-1));)--r;for(;i<e.length&&a.test(e.charAt(i));)++i;if(n)return{content:e.slice(r,i),start:r,end:i};let o=Je(e,t),s=o?.key.toLowerCase();if(o&&(s?.endsWith(`class`)||s?.endsWith(`classname`)))return r=Math.max(r,o.valueStart),{content:e.slice(r,i),start:r,end:i};let c=e.slice(0,r).trimEnd();if(/(?:^|[\s;{])@apply$/.test(c))return{content:e.slice(r,i),start:r,end:i}}const Be=new Set(`a abbr address area article aside audio b base bdi bdo blockquote body br button canvas caption cite code col colgroup data datalist dd del details dfn dialog div dl dt em embed fieldset figcaption figure footer form h1 h2 h3 h4 h5 h6 head header hgroup hr html i iframe img input ins kbd label legend li link main map mark menu meta meter nav noscript object ol optgroup option output p picture pre progress q rp rt ruby s samp script search section select slot small source span strong style sub summary sup table tbody td template textarea tfoot th thead time title tr track u ul var video wbr svg`.split(` `)),Ve=new Set(`=([{,:;!?&|>~`);function He(e){return e>=65&&e<=90||e>=97&&e<=122}function Ue(e){return He(e)||e===95}function We(e){return Ue(e)||e>=48&&e<=57||e===36||e===45||e===46||e===58}function Ge(e,t,n){let r=t-n.length;return r<0||e.slice(r,t)!==n?!1:r===0||!We(e.charCodeAt(r-1))}function Ke(e,t,n,r){if(Be.has(n.toLowerCase())||n.includes(`-`)||r&&n.charCodeAt(0)>=65&&n.charCodeAt(0)<=90)return!0;let i=t-1;for(;i>=0&&/\s/.test(e.charAt(i));)i--;return i<0||Ve.has(e.charAt(i))?!0:Ge(e,i+1,`return`)}function qe(e){let t,n=!1,r,i=0;for(;i<e.length;){if(t){let a=e.charAt(i);r?a===`\\`?i++:a===r&&(r=void 0):a===`"`||a===`'`?r=a:a===`>`&&(t=void 0,n=!0),i++;continue}if(e.charAt(i)===`;`&&(n=!1),e.charCodeAt(i)!==60){i++;continue}let a=i++;if(!Ue(e.charCodeAt(i)))continue;let o=i;for(;i<e.length&&We(e.charCodeAt(i));)i++;if(i<e.length&&!/[\s/>]/.test(e.charAt(i)))continue;let s=e.slice(o,i);Ke(e,a,s,n)&&(t={name:s,start:a})}return t}function Je(e,t){let n=e.substring(0,t),r=qe(n);if(!r)return;let i=r.start+1,a=n.slice(i),o=-1,s=-1,c=-1,l=-1,u=-1,d=-1,f;for(let e=0;e<a.length;e++){let t=a.charAt(e);if(f){t===`\\`?e++:t===f&&(f=void 0);continue}if(t===`"`||t===`'`){f=t,o<0&&(o=e);continue}if(/\s/.test(t)){o>=0&&(s=o,c=e,o=-1);continue}if(t===`=`){let t=o>=0?o:s,n=o>=0?e:c;t>=0&&n>t&&t>=l&&(l=t,u=n,d=e)}o<0&&(o=e)}if(l<0)return;let p=d+1;for(;/\s/.test(a.charAt(p));)p++;let m=a.charAt(p);if(m===`"`||m===`'`){p++;for(let e=p;e<a.length;e++){let t=a.charAt(e);if(t===`\\`)e++;else if(t===m)return}}else if(/[\s>]/.test(a.slice(p)))return;return{key:a.slice(l,u),valueStart:i+p}}function Ye(e,t){return Je(e,t)?.key}function Xe(e){return e.reduce((e,t)=>{let n=[];return e.forEach(e=>{t.forEach(t=>{n.push(e.concat([t]))})}),n},[[]])}const G=1e3,Ze=6e5,Qe=5e7,$e=6e4,K=3e5,et=5e4,tt=2e5,nt=5e3,q={...m,maxAttempts:15e3,maxCandidates:15e3,maxCharacters:6e5,maxScans:3e5};function rt(){return{active:0,waiters:[]}}function J(e){return e>=48&&e<=57}function it(e){for(let t=0;t<e.length;t++)if(J(e.charCodeAt(t)))return!0;return!1}function at(e,t){let n=0,r=0;for(;n<e.length&&r<t.length;){let i=e.charCodeAt(n),a=t.charCodeAt(r),o=J(i),s=J(a);if(o&&s){let i=n+1,a=r+1;for(;i<e.length&&J(e.charCodeAt(i));)i++;for(;a<t.length&&J(t.charCodeAt(a));)a++;let o=n,s=r;for(;o<i-1&&e.charCodeAt(o)===48;)o++;for(;s<a-1&&t.charCodeAt(s)===48;)s++;let c=i-o,l=a-s;if(c!==l)return c<l?-1:1;for(;o<i;){let n=e.charCodeAt(o)-t.charCodeAt(s);if(n)return n<0?-1:1;o++,s++}n=i,r=a;continue}if(i!==a)return i<a?-1:1;n++,r++}return n!==e.length||r!==t.length?n===e.length?-1:1:0}function Y(e,t){let n=it(e);return n===it(t)?at(e,t)||(e===t?0:e<t?-1:1):n?1:-1}function X(e,t=K,n=Qe){return{attempts:0,heap:[],limit:e,maxAttempts:t,maxScannedCharacters:n,retained:new Set,scannedCharacters:0}}function Z(e){return e.attempts<e.maxAttempts&&e.scannedCharacters<e.maxScannedCharacters}function Q(e,t){return Z(e)?(e.attempts++,!t||e.retained.has(t)||t.length>$e||t.length>e.maxScannedCharacters-e.scannedCharacters?!0:(e.scannedCharacters+=t.length,ot(e,t),!0)):!1}function ot(e,t){if(!(!t||e.retained.has(t)||t.length>$e)){if(e.heap.length<e.limit){e.heap.push(t),e.retained.add(t),st(e.heap,e.heap.length-1);return}Y(t,e.heap[0])>=0||(e.retained.delete(e.heap[0]),e.heap[0]=t,e.retained.add(t),ct(e.heap,0))}}function st(e,t){let n=t;for(;n>0;){let t=Math.floor((n-1)/2);if(Y(e[t],e[n])>=0)return;[e[t],e[n]]=[e[n],e[t]],n=t}}function ct(e,t){let n=t;for(;;){let t=n*2+1;if(t>=e.length)return;let r=t+1,i=r<e.length&&Y(e[r],e[t])>0?r:t;if(Y(e[n],e[i])>=0)return;[e[n],e[i]]=[e[i],e[n]],n=i}}function $(e){let t=[],n=0;for(let r of e.heap.sort(Y))n+r.length>Ze||(t.push(r),n+=r.length);return t}function lt(e,t,n,r){return Math.floor((t+n)*e/r)-Math.floor(t*e/r)}function*ut(e){let t=e.filter(e=>e.length).map(e=>({index:0,source:e})),n=0;for(;t.length;){let e=t[n];yield e.source[e.index++],e.index===e.source.length?t.splice(n,1):n++,n===t.length&&(n=0)}}function*dt(e,t,n,r,i,a){for(;n.attempts<r&&n.characters<i;){let r=e.next();if(r.done)return;let o=r.value;n.attempts++,!(!o||t.has(o)||o.length>a||o.length>i-n.characters)&&(t.add(o),n.characters+=o.length,yield o)}}function ft(e){let t=``;for(let n of e.parts){if(n.type!==`static`)break;t+=n.value}return t}function pt(e,t){if(!t)return{priorityCount:0,templates:[...e]};let n=t.replace(/-/g,``),r=[],i=[];for(let a=0;a<e.length;a++){let o=e[a],s=ft(o),c=s.replace(/-/g,``),l=-1;s&&t.startsWith(s)?l=0:c&&n.startsWith(c)?l=1:s.startsWith(t)?l=2:c.startsWith(n)&&(l=3),l<0?i.push(o):r.push({category:l,index:a,parsed:o,prefixLength:l<2?l?c.length:s.length:0})}return r.sort((e,t)=>e.category-t.category||t.prefixLength-e.prefixLength||e.index-t.index),{priorityCount:r.length,templates:[...r.map(({parsed:e})=>e),...i]}}function mt(e,t){return e.length<=t?[...e]:t<=0?[]:t===1?[e[0]]:Array.from({length:t},(n,r)=>e[Math.floor(r*(e.length-1)/(t-1))])}async function ht(e,t,n){let r=Array(e.length),i=0,a=!1,o=Array.from({length:Math.min(t,e.length)},async()=>{for(;!a&&i<e.length;){let t=i++;try{r[t]=await n(e[t])}catch(e){throw a=!0,e}}});return await Promise.all(o),r}function gt(e,t=G){let n=X(t);for(let t of e)if(!Q(n,t))break;return $(n)}function _t(e,t){let n=[],r=new Set,i=0,a=0;for(let o of e)if(o.startsWith(t)){if(i===K||n.length===G||a>=Ze)break;i++,!(!o||r.has(o)||o.length>$e||a+o.length>Ze)&&(r.add(o),n.push(o),a+=o.length)}return n}function vt(o,s={}){let c=new Map,l=new a({max:nt,maxSize:32e6,sizeCalculation:(e,t)=>Math.max(1,t.length*2+e.reduce((e,t)=>e+t.length*2+8,0))}),u=new Map,d=o.config,f=0,p=[],h,g,_=[],v=0,x=new Set,S=new Set,C=[],w=new Map,T=new Set,E=rt(),{matchType:D=`prefix`,throwErrors:O=!0}=s;return me(),{suggest:A,suggestInFile:j,templates:C,cache:l,errorCache:u,reset:me,enumerate:te};async function te(){let e=Array.from(`abcdefghijklmnopqrstuvwxyz`),t=[...e,`-`],n=e.flatMap(e=>[e,...t.map(t=>`${e}${t}`)]);for(;;){R();let e=d,t=f,r=new Set;if(await ne(n,r,e,t,e=>e)&&await ne([...r].filter(e=>/^\w+$/.test(e)&&e.length>3),r,e,t,e=>`${e}-`))return r}}async function ne(e,t,n,r,i){for(let a=0;a<e.length;a+=128){let o=await B(Promise.all(e.slice(a,a+128).map(e=>A(i(e)))),n,r);if(o.stale)return!1;for(let e of o.value)for(let n of e)t.add(n)}return!0}async function A(e,t=!1){if(R(),!t&&e.length<1)return[];if(l.has(e))return l.get(e);let n=w.get(e);if(n)return n;let r=ie(e,t);w.set(e,r);try{return await r}finally{w.get(e)===r&&w.delete(e)}}async function ie(e,t){for(;;){R();let n=d,r=f;if(!t&&e.length<1)return[];if(l.has(e))return l.get(e);let i=n.presets.find(e=>e.name===`@teacss/preset-attributify`)?.options?.prefix,a=i?e.startsWith(i)?e.slice(i.length):e.replace(`:${i}`,`:`):e,s=await B(o.matchVariants(a),n,r);if(s.stale)continue;let c=await B(Promise.all(s.value.map(async([,t])=>{let i=t?e.indexOf(t):e.length;i===-1&&(i=0);let a=e.slice(0,i),o=e.slice(i+t.length),s=D===`fuzzy`?[M(t,n,r),se(t,n,r),N(t),oe(t)]:[M(t,n,r),oe(t),N(t),se(t,n,r)];return V(await Promise.all(s),a,o)})),n,r);if(c.stale)continue;let u=c.value.flat();if(u=D===`fuzzy`?P(k(u,e,{maxCandidates:q.maxCandidates,maxCharacters:q.maxCharacters}),e):gt(u),!z(n,r))return l.set(e,u),u}}async function j(e,t){R();let n=d,r=f,i=Ye(e,t)!==void 0,a=await B(ae(e,t,n),n,r);if(a.stale)return j(e,t);let o=a.value;if(o){let a=await A(o.extracted,i);if(z(n,r))return j(e,t);let s=o.transformSuggestions?o.transformSuggestions(a):a;return{suggestions:a.map((e,t)=>[e,s[t]]),resolveReplacement:o.resolveReplacement}}let s=ze(e,t,n.presets.some(e=>e.name===`@teacss/preset-attributify`));if(!s)return;let c=await A(s.content,i);return z(n,r)?j(e,t):{suggestions:c.map(e=>[e,e]),resolveReplacement:e=>({start:s.start,end:s.end,replacement:e})}}async function ae(e,t,n){if(!n.autocomplete.extractors.length)return null;for(let r of n.autocomplete.extractors){let n=await r.extract({content:e,cursor:t});if(n)return n}return null}async function M(e,t,n){let r=await o.parseToken(e,`-`);return r&&!z(t,n)&&(S.delete(e),S.add(e),S.size>nt&&S.delete(S.values().next().value)),r?[e]:[]}async function oe(e){if(D===`fuzzy`){let t=pe(),n=P(_,e,t,v),r=k(F(),e,{maxAttempts:K,maxCandidates:750,maxCharacters:6e4});return k([...n,...r],e,{maxCandidates:G,maxCharacters:q.maxCharacters})}return h??=[...p].sort(Y),_t(h,e)}async function N(e){return gt(t());function*t(){for(let t of S)t.startsWith(e)&&(yield t);for(let[t,n]of o.cache){if(!n)continue;let r=t.replace(/ -$/,``);r.startsWith(e)&&(yield r)}}}async function se(e,t,n){let r=C.filter(e=>typeof e==`function`);if(D!==`fuzzy`){let i=I(e),a=await ce(r,e,t,n);return[...i,...a]}let i=L(e),a=await le(r,e,t,n);return[...i,...a]}async function ce(e,t,n,r){if(!e.length)return[];let i=X(G),a=X(G);for(let o=0;o<e.length;o+=8){let s=await ht(e.slice(o,o+8),8,e=>ue(e,t,n,r));if(z(n,r))return[];let c=lt(K,o,s.length,e.length),l=lt(Qe,o,s.length,e.length),u=X(G,c,l),d=ut(s.filter(e=>!!e?.length));for(;Z(u);){let e=d.next();if(e.done)break;Q(u,e.value)}for(let e of $(u))ot(i,e);let f=X(G,c,l);for(;Z(f);){let e=d.next();if(e.done)break;Q(f,e.value)}for(let e of $(f))ot(i,e);for(;Z(a);){let e=d.next();if(e.done)break;Q(a,e.value)}}for(let e of $(a))ot(i,e);return $(i)}async function le(e,t,n,r){if(!e.length)return[];let i=[],a=new Set,o={attempts:0,characters:0};for(let s=0;s<e.length;s+=32){let c=await ht(e.slice(s,s+32),32,e=>ue(e,t,n,r));if(z(n,r))return[];let l=ut(c.filter(e=>!!e?.length)),u=lt(K,s,c.length,e.length),d=lt(m.maxScannedCharacters,s,c.length,e.length),f=k(l,t,{maxAttempts:u,maxCandidates:G,maxCharacters:q.maxCharacters,maxScannedCharacters:d});i=k([...i,...f],t,{maxAttempts:i.length+f.length,maxCandidates:G,maxCharacters:q.maxCharacters});let p=k(dt(l,a,{attempts:0,characters:0},u,d,m.maxCandidateLength),t,{maxAttempts:u,maxCandidates:750,maxCharacters:q.maxCharacters,maxScannedCharacters:d});i=k([...i,...p],t,{maxAttempts:i.length+p.length,maxCandidates:G,maxCharacters:q.maxCharacters});let h=k(dt(l,a,{attempts:0,characters:0},u,d,m.maxCandidateLength),t,{maxAttempts:u,maxCandidates:750,maxCharacters:q.maxCharacters,maxScannedCharacters:d});i=k([...i,...h],t,{maxAttempts:i.length+h.length,maxCandidates:G,maxCharacters:q.maxCharacters});let g=k(dt(l,a,o,K,m.maxScannedCharacters,m.maxCandidateLength),t,{maxAttempts:K-o.attempts,maxCandidates:750,maxCharacters:q.maxCharacters,maxScannedCharacters:m.maxScannedCharacters-o.characters});i=k([...i,...g],t,{maxAttempts:i.length+g.length,maxCandidates:G,maxCharacters:q.maxCharacters})}return i}async function ue(e,t,n,r){let i=E;await de(i);try{if(z(n,r))return;try{return await e(t)}catch{return}}finally{fe(i)}}async function de(e){if(e.active<128){e.active++;return}await new Promise(t=>e.waiters.push(t))}function fe(e){let t=e.waiters.shift();t?t():e.active--}function P(e,t,a,o){return re(t,o??e.reduce((e,t)=>e+t.length,0))?k(e,t,{maxCandidates:G,maxCharacters:q.maxCharacters}):(a??new n(e,{fuzzy:`v1`,limit:G,tiebreakers:[i,r]})).find(t).map(e=>e.item)}function pe(){if(g)return g;let e=new Set,t=0,a=0,o=n=>!n||e.has(n)||n.length>q.maxCandidateLength||e.size===q.maxCandidates||t+n.length>q.maxCharacters?!1:(e.add(n),t+=n.length,!0),s=0;for(;s<p.length&&a<q.maxAttempts&&e.size<q.maxCandidates&&t<q.maxCharacters;){let e=p[s++];a++,o(e)&&x.add(e)}return _=[...e],v=t,g=new n(_,{fuzzy:`v1`,limit:G,tiebreakers:[i,r]}),g}function*F(){for(let e of p)x.has(e)||(yield e)}function I(e){let t=X(G),n=0,r=0,i=0,a=pt([...c.values()],e).templates.slice(0,et);for(let o=0;o<a.length;o++){let s=K-n,c=Qe-r,l=tt-i;if(c<=0||s<=0||l<=0||!Z(t))break;let u=a.length-o,d=Math.max(1,Math.floor(s/u)),f=b(a[o],e,{maxAttempts:d,maxCandidateLength:$e,maxCandidates:d,maxCharacters:Math.max(1,Math.floor(c/u)),maxScans:Math.max(1,Math.floor(l/u))});n+=f.attempts,r+=f.characters,i+=f.scans;for(let e of f.suggestions)if(!Q(t,e))break}return $(t)}function L(e){let t=[],n=new Set,r=0,i=0,a=0,o=0,s=pt([...c.values()],e).templates.slice(0,et),l=e=>{!e||n.has(e)||e.length>m.maxCandidateLength||a>=q.maxCandidates||r+e.length>q.maxCharacters||(n.add(e),t.push(e),a++,r+=e.length)},u=0;for(let t of k(f(),e,{maxAttempts:et,maxCandidates:750,maxCharacters:q.maxCharacters}))l(t);let d=mt(s,Math.max(1,Math.floor(Math.min(q.maxAttempts,q.maxCandidates-a)/2)));for(let t=0;t<d.length;t++){let n=q.maxAttempts-i,s=q.maxCandidates-a,c=q.maxCharacters-r,u=q.maxScans-o;if(n<=0||s<=0||c<=0||u<=0)break;let f=d.length-t,p={maxAttempts:Math.max(2,Math.floor(n/f)),maxCandidates:Math.max(2,Math.floor(s/f)),maxCharacters:Math.max(1,Math.floor(c/f)),maxScans:Math.max(1,Math.floor(u/f))},m;if(e.length<=1){let n=b(d[t],e,p);m=n.suggestions,i+=n.attempts,o+=n.scans}else{let n=ke(d[t].parts,p,e);m=n.candidates,i+=n.attempts,o+=n.scans}for(let e of m)l(e)}return k(t,e,{maxAttempts:q.maxAttempts,maxCandidates:750,maxCharacters:q.maxCharacters});function*f(){for(let t=0;t<s.length;t++){let n=tt-u;if(n<=0)return;let r=s.length-t,i=(e.length<=1?b:y)(s[t],e,{maxAttempts:1,maxCandidates:1,maxCharacters:m.maxCandidateLength,maxScans:Math.max(1,Math.floor(n/r))});u+=i.scans,yield*i.suggestions}}}function me(){let t=o.config,n=[...Object.keys(t.rulesStaticMap),...t.shortcuts.filter(e=>typeof e[0]==`string`).map(e=>e[0])],r=[...t.autocomplete.templates||[],...t.rulesDynamic.flatMap(t=>e(t?.[2]?.autocomplete||[])),...t.shortcuts.flatMap(t=>e(t?.[2]?.autocomplete||[])),...t.variants.flatMap(t=>e(t.autocomplete||[]))],i=new Map,a=new Map;for(let e of r)if(typeof e!=`function`){if(i.has(e)||a.has(e))continue;let n=ee(e,t.theme,t.autocomplete.shorthands);n.errors.length&&a.set(e,n.errors),i.set(e,n)}if(a.size&&O){u.clear();for(let[e,t]of a)u.set(e,t);let e=Array.from(a.values()).flat().map(e=>e.toString()).join(`
2
+ `);throw Error(e)}f++;for(let e of[...T])e();d=t,p=n,h=void 0,C.length=0,C.push(...r),c.clear();for(let[e,t]of i)c.set(e,t);l.clear(),w.clear(),E=rt(),u.clear();for(let[e,t]of a)u.set(e,t);g=void 0,_=[],v=0,x.clear(),S.clear()}function R(){d!==o.config&&me()}function z(e,t){return e!==o.config||t!==f}function B(e,t,n){return new Promise((r,i)=>{let a=!1,s=e=>{a||(a=!0,l(),T.delete(c),r(e))},c=()=>s({stale:!0}),l=o.events.on(`config`,e=>{e!==t&&c()});T.add(c),Promise.resolve(e).then(e=>s({stale:!1,value:e}),e=>{a||(a=!0,l(),T.delete(c),i(e))}),z(t,n)&&c()})}function V(e,n=``,r=``){let i=t(e.flat()).filter(e=>!!(e&&!e.endsWith(`-`)&&!o.isBlocked(e)&&!o.isBlocked(n+e+r)));D!==`fuzzy`&&i.sort(Y);let a=i.map(e=>n+e+r);return D===`fuzzy`?a:gt(a)}}export{x as AutocompleteParseError,Xe as cartesian,vt as createAutocomplete,C as ignoredThemeKeys,ee as parseAutocomplete,Ye as searchAttrKey,ze as searchUsageBoundary,S as shorthands};
package/package.json ADDED
@@ -0,0 +1,32 @@
1
+ {
2
+ "name": "@teacss/autocomplete",
3
+ "version": "0.3.0",
4
+ "description": "TeaCSS suggestion engine — utility-class completions for a partial token or a position in a file.",
5
+ "homepage": "https://css.teasim.com",
6
+ "funding": "https://github.com/sponsors/billgo",
7
+ "license": "MIT",
8
+ "author": "Billgo <hi@billgo.me>",
9
+ "sideEffects": false,
10
+ "type": "module",
11
+ "exports": {
12
+ ".": "./dist/index.js",
13
+ "./package.json": "./package.json"
14
+ },
15
+ "types": "./dist/index.d.ts",
16
+ "files": [
17
+ "dist",
18
+ "README.md"
19
+ ],
20
+ "scripts": {
21
+ "build": "bunx rimraf dist && bunx tsdown --config tsdown.config.mts",
22
+ "dev": "tsdown --config-loader unrun --watch"
23
+ },
24
+ "dependencies": {
25
+ "@teacss/core": "0.3.0",
26
+ "fzf": "^0.5.2",
27
+ "lru-cache": "^11.5.2"
28
+ },
29
+ "publishConfig": {
30
+ "access": "public"
31
+ }
32
+ }