parseman 0.45.0 → 0.46.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/dist/analysis/choice-cost-gate.d.ts +158 -0
- package/dist/analysis/choice-cost-gate.d.ts.map +1 -0
- package/dist/analysis/choice-cost-render.d.ts +88 -0
- package/dist/analysis/choice-cost-render.d.ts.map +1 -0
- package/dist/analysis/choice-cost.d.ts +383 -0
- package/dist/analysis/choice-cost.d.ts.map +1 -0
- package/dist/analysis/corpus.d.ts +73 -0
- package/dist/analysis/corpus.d.ts.map +1 -0
- package/dist/analysis/diagnose-render.d.ts +65 -0
- package/dist/analysis/diagnose-render.d.ts.map +1 -0
- package/dist/analysis/diagnose.d.ts +15 -0
- package/dist/analysis/diagnose.d.ts.map +1 -1
- package/dist/analysis/diagnostics.cjs +11272 -0
- package/dist/analysis/diagnostics.cjs.map +7 -0
- package/dist/analysis/diagnostics.d.ts +27 -0
- package/dist/analysis/diagnostics.d.ts.map +1 -0
- package/dist/analysis/diagnostics.js +11249 -0
- package/dist/analysis/diagnostics.js.map +7 -0
- package/dist/analysis/fix-render.d.ts +43 -0
- package/dist/analysis/fix-render.d.ts.map +1 -0
- package/dist/analysis/fix.d.ts +172 -0
- package/dist/analysis/fix.d.ts.map +1 -0
- package/dist/analysis/gating.d.ts +8 -0
- package/dist/analysis/gating.d.ts.map +1 -1
- package/dist/analysis/rebuild.d.ts +61 -0
- package/dist/analysis/rebuild.d.ts.map +1 -0
- package/dist/analysis/terminal.d.ts +142 -0
- package/dist/analysis/terminal.d.ts.map +1 -0
- package/dist/cli/index.cjs +12507 -0
- package/dist/cli/index.cjs.map +7 -0
- package/dist/cli/index.d.ts +3 -0
- package/dist/cli/index.d.ts.map +1 -0
- package/dist/cli/index.js +12484 -0
- package/dist/cli/index.js.map +7 -0
- package/dist/compiler/build-arity.d.ts.map +1 -1
- package/dist/compiler/linker.d.ts +44 -6
- package/dist/compiler/linker.d.ts.map +1 -1
- package/dist/compiler/module-hoist.d.ts +106 -0
- package/dist/compiler/module-hoist.d.ts.map +1 -0
- package/dist/index.cjs +1297 -297
- package/dist/index.cjs.map +4 -4
- package/dist/index.d.ts +8 -2
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +1297 -297
- package/dist/index.js.map +4 -4
- package/dist/language-service/index.cjs.map +2 -2
- package/dist/language-service/index.js.map +2 -2
- package/dist/plugin/evaluator.d.ts +1 -1
- package/dist/plugin/evaluator.d.ts.map +1 -1
- package/dist/plugin/free-identifiers.d.ts +23 -0
- package/dist/plugin/free-identifiers.d.ts.map +1 -0
- package/dist/plugin/index.cjs +429 -43
- package/dist/plugin/index.cjs.map +4 -4
- package/dist/plugin/index.d.ts.map +1 -1
- package/dist/plugin/index.js +429 -43
- package/dist/plugin/index.js.map +4 -4
- package/dist/plugin/reducer-resolver.d.ts +17 -1
- package/dist/plugin/reducer-resolver.d.ts.map +1 -1
- package/dist/spec/index.cjs +2 -1
- package/dist/spec/index.cjs.map +2 -2
- package/dist/spec/index.js +2 -1
- package/dist/spec/index.js.map +2 -2
- package/dist/version.d.ts +1 -1
- package/package.json +18 -3
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"build-arity.d.ts","sourceRoot":"","sources":["../../src/compiler/build-arity.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,aAAa,CAAA;AAG5C;;;;;;;;;;GAUG;AAEH,KAAK,OAAO,GAAG,OAAO,CAAC,SAAS,EAAE;IAAE,GAAG,EAAE,MAAM,CAAA;CAAE,CAAC,CAAA;AAElD;;;;;;;;;;GAUG;AACH,wBAAgB,aAAa,CAAC,KAAK,EAAE,OAAO,GAAG,OAAO,CAErD;AAgCD;;;GAGG;AACH,wBAAgB,mBAAmB,CAAC,GAAG,EAAE,MAAM,GAAG,MAAM,GAAG,IAAI,CAgC9D;AAoHD;;;;;;;;;;GAUG;AACH,wBAAgB,gBAAgB,CAAC,GAAG,EAAE,OAAO,GAAG,MAAM,CAErD;
|
|
1
|
+
{"version":3,"file":"build-arity.d.ts","sourceRoot":"","sources":["../../src/compiler/build-arity.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,aAAa,CAAA;AAG5C;;;;;;;;;;GAUG;AAEH,KAAK,OAAO,GAAG,OAAO,CAAC,SAAS,EAAE;IAAE,GAAG,EAAE,MAAM,CAAA;CAAE,CAAC,CAAA;AAElD;;;;;;;;;;GAUG;AACH,wBAAgB,aAAa,CAAC,KAAK,EAAE,OAAO,GAAG,OAAO,CAErD;AAgCD;;;GAGG;AACH,wBAAgB,mBAAmB,CAAC,GAAG,EAAE,MAAM,GAAG,MAAM,GAAG,IAAI,CAgC9D;AAoHD;;;;;;;;;;GAUG;AACH,wBAAgB,gBAAgB,CAAC,GAAG,EAAE,OAAO,GAAG,MAAM,CAErD;AAqCD;;;;;;;;;;;;;;GAcG;AACH,wBAAgB,oBAAoB,CAAC,GAAG,EAAE,OAAO,GAAG,MAAM,GAAG,IAAI,CAkBhE;AAED,uFAAuF;AACvF,wBAAgB,kBAAkB,CAAC,GAAG,EAAE,OAAO,GAAG,OAAO,CAKxD;AAED,0FAA0F;AAC1F,wBAAgB,aAAa,CAAC,GAAG,EAAE,OAAO,GAAG,OAAO,CAKnD;AAED,sFAAsF;AACtF,wBAAgB,gBAAgB,CAAC,GAAG,EAAE,OAAO,GAAG,OAAO,CAKtD;AAED,sFAAsF;AACtF,wBAAgB,eAAe,CAAC,GAAG,EAAE,OAAO,GAAG,OAAO,CAKrD"}
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import type { LinkablePieces, HostMode } from './codegen.ts';
|
|
2
2
|
import type { BuildHost, Combinator, CstCollapsePredicate, ParseContext, ParseResult } from '../types.ts';
|
|
3
|
+
import type { ModuleHoist } from './module-hoist.ts';
|
|
3
4
|
export declare function linkable(rulesMap: Record<string, Combinator<unknown>>, ns?: string, trivia?: Combinator<unknown>, hostMode?: HostMode): LinkablePieces;
|
|
4
5
|
export type CstBuildHostOptions = {
|
|
5
6
|
/**
|
|
@@ -61,7 +62,7 @@ export declare function pickPieces(pieces: LinkablePieces[], names: string[]): L
|
|
|
61
62
|
* for any non-inlined callbacks) and the `_env` to bind. In macro mode callbacks
|
|
62
63
|
* are inlined from source, so `_env` is empty and the body is fully static.
|
|
63
64
|
*/
|
|
64
|
-
export declare function fusedBody(pieces: LinkablePieces[]): {
|
|
65
|
+
export declare function fusedBody(pieces: LinkablePieces[], hoist?: ModuleHoist): {
|
|
65
66
|
body: string;
|
|
66
67
|
env: Record<string, unknown>;
|
|
67
68
|
};
|
|
@@ -81,7 +82,7 @@ export declare function fusedHostElidedOf(registry: object): boolean;
|
|
|
81
82
|
* Requires every callback to be inlined from source (macro mode); throws if any
|
|
82
83
|
* artifact carries runtime-only callback functions.
|
|
83
84
|
*/
|
|
84
|
-
export declare function emitFusedSource(pieces: LinkablePieces[]): string;
|
|
85
|
+
export declare function emitFusedSource(pieces: LinkablePieces[], hoist?: ModuleHoist): string;
|
|
85
86
|
/** The carried pieces a `compose()`/`composeLeaf()` result holds, or `undefined` when
|
|
86
87
|
* the value is not a composed grammar. This is what makes a fused grammar analysable:
|
|
87
88
|
* the pieces are re-lowerable IR even though the fused map itself is only functions. */
|
|
@@ -155,9 +156,46 @@ opts?: {
|
|
|
155
156
|
}): Record<string, FusedRule>;
|
|
156
157
|
/**
|
|
157
158
|
* Compose a terminal grammar. This is for a leaf parser that overlays local
|
|
158
|
-
* semantic reductions on reusable recognition rules.
|
|
159
|
-
*
|
|
160
|
-
*
|
|
159
|
+
* semantic reductions on reusable recognition rules.
|
|
160
|
+
*
|
|
161
|
+
* Under the macro this lowers to STATIC fused source (functions), exactly like
|
|
162
|
+
* `compose()`. It is still macro-only as a *compiled* artifact: without macro
|
|
163
|
+
* lowering there is no safe way to keep lexical builders out of carried IR, so it
|
|
164
|
+
* never falls back to runtime CODEGEN composition.
|
|
165
|
+
*
|
|
166
|
+
* Called at runtime (no macro) it returns the INTERPRETED fuse of the same items
|
|
167
|
+
* — a combinator map, not a map of compiled functions (`fuseInterpreted`). That is
|
|
168
|
+
* the supported way to run/inspect a leaf grammar without a build step: drive it
|
|
169
|
+
* with `run()` / `parseDoc()`, which accept either shape. The declared return type
|
|
170
|
+
* is the MACRO-path type (a leaf grammar is shipped compiled); use
|
|
171
|
+
* `isInterpretedFuse(map)` when a caller must tell the two apart.
|
|
172
|
+
*/
|
|
173
|
+
export declare function composeLeaf(items: Array<LinkablePieces | Record<string, unknown>>): Record<string, FusedRule>;
|
|
174
|
+
/** Whether `map` is an interpreted fuse (a combinator map) rather than a compiled
|
|
175
|
+
* `compose()` result (a map of fused functions). */
|
|
176
|
+
export declare function isInterpretedFuse(map: object): boolean;
|
|
177
|
+
/**
|
|
178
|
+
* Materialize a composition as a RUNNABLE INTERPRETED rule map — the interpreted
|
|
179
|
+
* counterpart of `compose()`, with identical fuse semantics (later piece wins,
|
|
180
|
+
* override reroutes the base's own calls, composing trivia governs every rule).
|
|
181
|
+
* No codegen, no `new Function`, no macro build step: the result is a plain map of
|
|
182
|
+
* combinators that `run()` / `parseDoc()` accept exactly like a fused map.
|
|
183
|
+
*
|
|
184
|
+
* This is what diagnostics and profiling run against — they must stay in
|
|
185
|
+
* interpreted mode, and before this they could not see a composed grammar at all.
|
|
186
|
+
*
|
|
187
|
+
* Items are the SAME items `compose()`/`composeLeaf()` take: `rules()` maps
|
|
188
|
+
* (the intended input), a prior `fuseInterpreted()` result, or a runtime
|
|
189
|
+
* `compose()` result (re-lowered from its carried IR — note that carried IR cannot
|
|
190
|
+
* materialize direct `node()` builders, so prefer the source maps). A precompiled
|
|
191
|
+
* `linkable()` artifact is rejected: it has no combinator graph.
|
|
192
|
+
*
|
|
193
|
+
* MUTATION: binding a cross-piece hole rewrites the shared placeholder object every
|
|
194
|
+
* call site already holds — that IS how an override reaches a base piece's own
|
|
195
|
+
* calls. A second, DIFFERENT fusion over the same piece objects therefore throws
|
|
196
|
+
* rather than silently rewriting the first one's parser.
|
|
161
197
|
*/
|
|
162
|
-
export declare function
|
|
198
|
+
export declare function fuseInterpreted(items: Array<LinkablePieces | Record<string, unknown>>, opts?: {
|
|
199
|
+
hostMode?: HostMode;
|
|
200
|
+
}): Record<string, Combinator<unknown>>;
|
|
163
201
|
//# sourceMappingURL=linker.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"linker.d.ts","sourceRoot":"","sources":["../../src/compiler/linker.ts"],"names":[],"mappings":"AAuBA,OAAO,KAAK,EAAE,cAAc,EAAkB,QAAQ,EAAE,MAAM,cAAc,CAAA;AAG5E,OAAO,KAAK,EAAE,SAAS,EAAE,UAAU,EAAE,oBAAoB,EAAY,YAAY,EAAE,WAAW,EAAE,MAAM,aAAa,CAAA;
|
|
1
|
+
{"version":3,"file":"linker.d.ts","sourceRoot":"","sources":["../../src/compiler/linker.ts"],"names":[],"mappings":"AAuBA,OAAO,KAAK,EAAE,cAAc,EAAkB,QAAQ,EAAE,MAAM,cAAc,CAAA;AAG5E,OAAO,KAAK,EAAE,SAAS,EAAE,UAAU,EAAE,oBAAoB,EAAY,YAAY,EAAE,WAAW,EAAE,MAAM,aAAa,CAAA;AAEnH,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,mBAAmB,CAAA;AAapD,wBAAgB,QAAQ,CACtB,QAAQ,EAAE,MAAM,CAAC,MAAM,EAAE,UAAU,CAAC,OAAO,CAAC,CAAC,EAC7C,EAAE,CAAC,EAAE,MAAM,EACX,MAAM,CAAC,EAAE,UAAU,CAAC,OAAO,CAAC,EAK5B,QAAQ,CAAC,EAAE,QAAQ,GAClB,cAAc,CAQhB;AAED,MAAM,MAAM,mBAAmB,GAAG;IAChC;;;;;;OAMG;IACH,QAAQ,CAAC,EAAE,OAAO,GAAG,SAAS,MAAM,EAAE,GAAG,oBAAoB,CAAA;IAC7D;;;OAGG;IACH,IAAI,CAAC,EAAE,OAAO,CAAA;CACf,CAAA;A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AC,CAAC,GACrD,MAAM,CAAC,MAAM,EAAE,SAAS,CAAC,CAyB3B;AAqDD;oDACoD;AACpD,wBAAgB,iBAAiB,CAAC,GAAG,EAAE,MAAM,GAAG,OAAO,CAEtD;AAgFD;;;;;;;;;;;;;;;;;;;;GAoBG;AACH,wBAAgB,eAAe,CAC7B,KAAK,EAAE,KAAK,CAAC,cAAc,GAAG,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC,EACtD,IAAI,CAAC,EAAE;IAAE,QAAQ,CAAC,EAAE,QAAQ,CAAA;CAAE,GAC7B,MAAM,CAAC,MAAM,EAAE,UAAU,CAAC,OAAO,CAAC,CAAC,CAErC"}
|
|
@@ -0,0 +1,106 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* MODULE-LEVEL HOIST OF BYTE-IDENTICAL FUSED DECLARATIONS
|
|
3
|
+
* ======================================================
|
|
4
|
+
*
|
|
5
|
+
* Every `compose()` / `composeLeaf()` in a module lowers to its OWN self-contained
|
|
6
|
+
* IIFE (`emitFusedSource` → `/* @__PURE__ */ (() => { … })()`). A module that
|
|
7
|
+
* publishes N variants of one grammar — the jess shape: shared recognition pieces
|
|
8
|
+
* plus N leaves differing only in `hostMode` / `trackLines` — therefore emits the
|
|
9
|
+
* recognition piece's rule functions N times, under the SAME namespaced names,
|
|
10
|
+
* in N sibling scopes. The namespace is content-addressed, so those N copies are
|
|
11
|
+
* byte-identical: `probe/variants-4` emits 5 `_r_` rule functions, four of which
|
|
12
|
+
* have exactly one distinct body across all four IIFEs.
|
|
13
|
+
*
|
|
14
|
+
* Measured on the committed size probe (bench/size/probe.ts), byte-identical
|
|
15
|
+
* declaration text available for dedup:
|
|
16
|
+
*
|
|
17
|
+
* probe/variants-2 41,446 B generated 9,557 B duplicated (23.1%)
|
|
18
|
+
* probe/variants-4 82,058 B generated 29,286 B duplicated (35.7%)
|
|
19
|
+
*
|
|
20
|
+
* This module collects the top-level declarations of every fused IIFE in one
|
|
21
|
+
* module, decides which are safe to emit ONCE at module scope, and rewrites each
|
|
22
|
+
* IIFE to drop its copy.
|
|
23
|
+
*
|
|
24
|
+
* THE CORRECTNESS PROBLEM, AND WHY THE DECISION IS KEYED ON THE NAME
|
|
25
|
+
* -----------------------------------------------------------------
|
|
26
|
+
* `_pfFail` is an identity sentinel: a rule function signals failure by returning
|
|
27
|
+
* it and every caller tests `v === _pfFail`. Each IIFE declares its own
|
|
28
|
+
* `const _pfFail = {}`, so today the producer and the consumer are always the same
|
|
29
|
+
* object. A PARTIAL hoist breaks that: if some scopes read the module-level
|
|
30
|
+
* sentinel while others keep a local one, a rule that FAILED returns object A and
|
|
31
|
+
* its caller compares against object B — the test is false, and the failure is
|
|
32
|
+
* read as a SUCCESS carrying the value `{}`. Silent wrong output, the worst class
|
|
33
|
+
* of bug this compiler can have.
|
|
34
|
+
*
|
|
35
|
+
* So the hoist decision is made per DECLARED NAME, not per occurrence:
|
|
36
|
+
*
|
|
37
|
+
* a name is hoistable only if EVERY declaration of that name anywhere in the
|
|
38
|
+
* module is byte-identical,
|
|
39
|
+
*
|
|
40
|
+
* and when it is, EVERY occurrence is removed and one copy is emitted at module
|
|
41
|
+
* scope. A mixed state is unrepresentable: there is no code path that removes one
|
|
42
|
+
* occurrence and keeps another. If two scopes ever disagreed about `_pfFail`'s
|
|
43
|
+
* text, the name would have two distinct texts, would fail the uniformity test,
|
|
44
|
+
* and NO scope would hoist it. `test/unit/module-hoist.test.ts` asserts both
|
|
45
|
+
* directions.
|
|
46
|
+
*
|
|
47
|
+
* `_pfEnd` (`let _pfEnd`) is a single-slot out-parameter and is safe to share
|
|
48
|
+
* unconditionally: the write is the last statement before a rule function returns
|
|
49
|
+
* (src/compiler/codegen.ts, `pushNamedFnDecl` — `_pfEnd = <end>` immediately
|
|
50
|
+
* precedes `return <value>`) and the read is the next statement at the call site
|
|
51
|
+
* (`emitNamedFnCall` — `const _pfe = _pfEnd` immediately follows the sentinel
|
|
52
|
+
* test). Nothing user-controlled runs between the write and the read, so even a
|
|
53
|
+
* builder that re-enters another grammar cannot observe a stale slot: the nested
|
|
54
|
+
* parse completes entirely before the outer write.
|
|
55
|
+
*
|
|
56
|
+
* FREE-VARIABLE FIXPOINT
|
|
57
|
+
* ----------------------
|
|
58
|
+
* A hoisted declaration must not reference anything that stayed IIFE-local. Every
|
|
59
|
+
* top-level name of every IIFE is known here (the declarations ARE the input), so
|
|
60
|
+
* a hoisted text is rejected if it mentions any name that is not itself hoisted,
|
|
61
|
+
* iterated to a fixpoint. Reference detection is a `\bNAME\b` scan over the
|
|
62
|
+
* declaration text: that over-approximates (it also matches inside strings and
|
|
63
|
+
* comments), and over-approximation is the safe direction — it only ever blocks a
|
|
64
|
+
* hoist, never permits an unsound one.
|
|
65
|
+
*
|
|
66
|
+
* This also disposes of the un-namespaced `_wcf<N>` hazard. `withCtx` names its
|
|
67
|
+
* wrapper `_wcf${namedParsers.size}` with no namespace prefix, so two different
|
|
68
|
+
* artifacts can both declare `_wcf0` with DIFFERENT bodies. Such a name has two
|
|
69
|
+
* distinct texts, so it is not hoistable, and by the fixpoint nothing that
|
|
70
|
+
* references it is hoistable either.
|
|
71
|
+
*
|
|
72
|
+
* SCOPE
|
|
73
|
+
* -----
|
|
74
|
+
* Hoisting is sound only because every macro replacement is made from the
|
|
75
|
+
* plugin's top-level `for (const stmt of body)` loop — the call sites are all
|
|
76
|
+
* module-level statements, so an IIFE's free variables can only resolve to
|
|
77
|
+
* module-level bindings, which are still in scope at module level. The prelude is
|
|
78
|
+
* inserted at the START of the earliest top-level statement that carries a
|
|
79
|
+
* replacement, which is never earlier than the earliest IIFE, so no binding those
|
|
80
|
+
* declarations already depended on moves out of scope.
|
|
81
|
+
*/
|
|
82
|
+
/** Non-global marker test, for asking whether a generated replacement claimed any
|
|
83
|
+
* declarations (a `/g` regex would carry `lastIndex` between calls). */
|
|
84
|
+
export declare const HOIST_MARKER_PROBE: RegExp;
|
|
85
|
+
/** The names a generated top-level declaration binds. */
|
|
86
|
+
export declare function declaredNames(text: string): string[];
|
|
87
|
+
export type HoistResult = {
|
|
88
|
+
/** Declarations to emit ONCE at module scope, in first-claim order. Empty when
|
|
89
|
+
* nothing qualified. Ends with a newline when non-empty. */
|
|
90
|
+
prelude: string;
|
|
91
|
+
/** Replace every marker in a generated source string with either nothing (the
|
|
92
|
+
* declaration was hoisted) or its original text (it was not). */
|
|
93
|
+
resolve(src: string): string;
|
|
94
|
+
/** Diagnostics: bytes removed from the IIFEs, minus the bytes re-emitted once. */
|
|
95
|
+
savedBytes: number;
|
|
96
|
+
/** Names emitted at module scope. */
|
|
97
|
+
hoistedNames: string[];
|
|
98
|
+
};
|
|
99
|
+
export type ModuleHoist = {
|
|
100
|
+
/** Register one fused IIFE's top-level declarations; returns the marker lines to
|
|
101
|
+
* emit in their place. */
|
|
102
|
+
claim(decls: readonly string[]): string[];
|
|
103
|
+
finalize(): HoistResult;
|
|
104
|
+
};
|
|
105
|
+
export declare function createModuleHoist(): ModuleHoist;
|
|
106
|
+
//# sourceMappingURL=module-hoist.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"module-hoist.d.ts","sourceRoot":"","sources":["../../src/compiler/module-hoist.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAgFG;AASH;yEACyE;AACzE,eAAO,MAAM,kBAAkB,QAAsB,CAAA;AAWrD,yDAAyD;AACzD,wBAAgB,aAAa,CAAC,IAAI,EAAE,MAAM,GAAG,MAAM,EAAE,CAOpD;AAED,MAAM,MAAM,WAAW,GAAG;IACxB;iEAC6D;IAC7D,OAAO,EAAE,MAAM,CAAA;IACf;sEACkE;IAClE,OAAO,CAAC,GAAG,EAAE,MAAM,GAAG,MAAM,CAAA;IAC5B,kFAAkF;IAClF,UAAU,EAAE,MAAM,CAAA;IAClB,qCAAqC;IACrC,YAAY,EAAE,MAAM,EAAE,CAAA;CACvB,CAAA;AAED,MAAM,MAAM,WAAW,GAAG;IACxB;+BAC2B;IAC3B,KAAK,CAAC,KAAK,EAAE,SAAS,MAAM,EAAE,GAAG,MAAM,EAAE,CAAA;IACzC,QAAQ,IAAI,WAAW,CAAA;CACxB,CAAA;AAED,wBAAgB,iBAAiB,IAAI,WAAW,CAkF/C"}
|