@copilotkit/angular 0.6.0 → 2.0.0-rc.52
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/.attw.json +1 -2
- package/README.md +31 -133
- package/dist/README.md +31 -133
- package/dist/fesm2022/copilotkit-angular-generative-ui-chart.mjs +28 -0
- package/dist/fesm2022/copilotkit-angular-generative-ui-chart.mjs.map +1 -0
- package/dist/fesm2022/copilotkit-angular-generative-ui-icons.mjs +30 -0
- package/dist/fesm2022/copilotkit-angular-generative-ui-icons.mjs.map +1 -0
- package/dist/fesm2022/copilotkit-angular-generative-ui-map.mjs +28 -0
- package/dist/fesm2022/copilotkit-angular-generative-ui-map.mjs.map +1 -0
- package/dist/fesm2022/copilotkit-angular-generative-ui.mjs +11975 -0
- package/dist/fesm2022/copilotkit-angular-generative-ui.mjs.map +1 -0
- package/dist/fesm2022/copilotkit-angular-mcp-apps.mjs +43 -142
- package/dist/fesm2022/copilotkit-angular-mcp-apps.mjs.map +1 -1
- package/dist/fesm2022/copilotkit-angular.mjs +7422 -7467
- package/dist/fesm2022/copilotkit-angular.mjs.map +1 -1
- package/dist/types/copilotkit-angular-generative-ui-chart.d.ts +16 -0
- package/dist/types/copilotkit-angular-generative-ui-chart.d.ts.map +1 -0
- package/dist/types/copilotkit-angular-generative-ui-icons.d.ts +18 -0
- package/dist/types/copilotkit-angular-generative-ui-icons.d.ts.map +1 -0
- package/dist/types/copilotkit-angular-generative-ui-map.d.ts +16 -0
- package/dist/types/copilotkit-angular-generative-ui-map.d.ts.map +1 -0
- package/dist/types/copilotkit-angular-generative-ui.d.ts +8011 -0
- package/dist/types/copilotkit-angular-generative-ui.d.ts.map +1 -0
- package/dist/types/copilotkit-angular-mcp-apps.d.ts +234 -5560
- package/dist/types/copilotkit-angular-mcp-apps.d.ts.map +1 -1
- package/dist/types/copilotkit-angular.d.ts +1195 -820
- package/dist/types/copilotkit-angular.d.ts.map +1 -1
- package/package.json +54 -39
- package/scripts/generate-stylesheet.mjs +63 -0
- package/tsconfig.json +11 -1
- package/vitest.config.mts +6 -0
- package/dist/fesm2022/copilotkit-angular-a2ui.mjs +0 -1492
- package/dist/fesm2022/copilotkit-angular-a2ui.mjs.map +0 -1
- package/dist/styles.css +0 -2679
- package/dist/types/copilotkit-angular-a2ui.d.ts +0 -178
- package/dist/types/copilotkit-angular-a2ui.d.ts.map +0 -1
- package/scripts/scope-preflight.mjs +0 -100
|
@@ -1,178 +0,0 @@
|
|
|
1
|
-
import * as _angular_core from '@angular/core';
|
|
2
|
-
import { Type, InjectionToken, OnDestroy } from '@angular/core';
|
|
3
|
-
import { ComponentApi, ComponentContext, ResolveA2uiProps, Catalog, SurfaceModel, DataContext, FunctionImplementation } from '@a2ui/web_core/v0_9';
|
|
4
|
-
export { ActionSchema, ChildListSchema, DynamicBooleanSchema, DynamicNumberSchema, DynamicStringSchema } from '@a2ui/web_core/v0_9';
|
|
5
|
-
import { A2UICatalog, A2UIClientEventMessage, A2UISurfaceError } from '@copilotkit/angular';
|
|
6
|
-
import { ZodRawShape, ZodObject, z } from 'zod';
|
|
7
|
-
import * as _copilotkit_angular_a2ui from '@copilotkit/angular/a2ui';
|
|
8
|
-
|
|
9
|
-
/**
|
|
10
|
-
* Web Component catalog entries, copied from `@a2ui/web_core/v0_9/universal`.
|
|
11
|
-
*
|
|
12
|
-
* TODO: delete this file once `@a2ui/web_core` is upgraded to 0.11.0 or later,
|
|
13
|
-
* and import `WebComponentImplementation`, `A2uiWebComponentElement`,
|
|
14
|
-
* `isWebComponentImplementation` and `registerUniversalElement` from
|
|
15
|
-
* `@a2ui/web_core/v0_9/universal` instead. We pin 0.10.4, which predates them.
|
|
16
|
-
*/
|
|
17
|
-
|
|
18
|
-
/** A catalog entry rendered by a Custom Element. */
|
|
19
|
-
interface WebComponentImplementation extends ComponentApi {
|
|
20
|
-
/** The tag name the element is registered under. */
|
|
21
|
-
readonly tagName: string;
|
|
22
|
-
/** The Custom Element class. */
|
|
23
|
-
readonly element: CustomElementConstructor;
|
|
24
|
-
}
|
|
25
|
-
/**
|
|
26
|
-
* The contract a catalog Custom Element fulfills: the renderer assigns
|
|
27
|
-
* `context` after creating it, and the element binds itself from there.
|
|
28
|
-
*/
|
|
29
|
-
interface A2uiWebComponentElement extends HTMLElement {
|
|
30
|
-
context?: ComponentContext;
|
|
31
|
-
}
|
|
32
|
-
|
|
33
|
-
/** A catalog entry rendered by an Angular component. */
|
|
34
|
-
interface CopilotA2UIComponentImplementation extends ComponentApi {
|
|
35
|
-
readonly component: Type<unknown>;
|
|
36
|
-
}
|
|
37
|
-
/** A catalog entry: an Angular component or a Custom Element. */
|
|
38
|
-
type CopilotA2UICatalogEntry = CopilotA2UIComponentImplementation | WebComponentImplementation;
|
|
39
|
-
/** A Custom Element to render a catalog entry with, instead of an Angular component. */
|
|
40
|
-
type A2UIWebComponent = Pick<WebComponentImplementation, "tagName" | "element">;
|
|
41
|
-
interface A2UIComponentDefinition<T extends ZodRawShape = ZodRawShape> {
|
|
42
|
-
props: ZodObject<T>;
|
|
43
|
-
/** Added to the schema advertised to the agent. */
|
|
44
|
-
description?: string;
|
|
45
|
-
}
|
|
46
|
-
type A2UICatalogDefinitions = Record<string, A2UIComponentDefinition<any>>;
|
|
47
|
-
/**
|
|
48
|
-
* Binder-resolved props for definition `K`: dynamic values become
|
|
49
|
-
* primitives, actions become closures, child lists become `{ id, basePath }`
|
|
50
|
-
* references, and dynamic props gain `set*` setters.
|
|
51
|
-
*/
|
|
52
|
-
type A2UIProps<D extends A2UICatalogDefinitions, K extends keyof D> = ResolveA2uiProps<z.infer<D[K]["props"]>>;
|
|
53
|
-
type A2UIChildRef = string | {
|
|
54
|
-
id: string;
|
|
55
|
-
basePath?: string;
|
|
56
|
-
};
|
|
57
|
-
|
|
58
|
-
/**
|
|
59
|
-
* A catalog of Angular components. It carries its own renderer so the main
|
|
60
|
-
* entry point can mount it without importing this one.
|
|
61
|
-
*/
|
|
62
|
-
declare class CopilotA2UICatalog extends Catalog<CopilotA2UICatalogEntry> implements A2UICatalog {
|
|
63
|
-
readonly surfaceComponent: Type<unknown>;
|
|
64
|
-
}
|
|
65
|
-
|
|
66
|
-
/**
|
|
67
|
-
* The A2UI basic catalog rendered with Angular components. Pass it as
|
|
68
|
-
* `a2ui.catalog`, or extend it with `createAngularCatalog(..., { includeBasicCatalog: true })`.
|
|
69
|
-
*/
|
|
70
|
-
declare const basicCatalog: CopilotA2UICatalog;
|
|
71
|
-
|
|
72
|
-
interface ResolvedChildRef {
|
|
73
|
-
id: string;
|
|
74
|
-
basePath: string;
|
|
75
|
-
}
|
|
76
|
-
|
|
77
|
-
/**
|
|
78
|
-
* Renders a child of the current catalog component.
|
|
79
|
-
*
|
|
80
|
-
* @example
|
|
81
|
-
* ```html
|
|
82
|
-
* <copilot-a2ui-child [child]="props().child" />
|
|
83
|
-
* @for (child of props().children; track child.id) {
|
|
84
|
-
* <copilot-a2ui-child [child]="child" />
|
|
85
|
-
* }
|
|
86
|
-
* ```
|
|
87
|
-
*/
|
|
88
|
-
declare class CopilotA2UIChild {
|
|
89
|
-
/** A child id, or a `{ id, basePath }` reference from a resolved child list. */
|
|
90
|
-
readonly child: _angular_core.InputSignal<A2UIChildRef | undefined>;
|
|
91
|
-
protected readonly context: _copilotkit_angular_a2ui.A2UIComponentContext;
|
|
92
|
-
protected readonly reference: _angular_core.Signal<ResolvedChildRef | undefined>;
|
|
93
|
-
static ɵfac: _angular_core.ɵɵFactoryDeclaration<CopilotA2UIChild, never>;
|
|
94
|
-
static ɵcmp: _angular_core.ɵɵComponentDeclaration<CopilotA2UIChild, "copilot-a2ui-child", never, { "child": { "alias": "child"; "required": false; "isSignal": true; }; }, {}, never, never, true, never>;
|
|
95
|
-
}
|
|
96
|
-
|
|
97
|
-
/** Per-instance context of a catalog component; see {@link injectA2UIComponentContext}. */
|
|
98
|
-
interface A2UIComponentContext {
|
|
99
|
-
readonly surfaceId: string;
|
|
100
|
-
readonly componentId: string;
|
|
101
|
-
/** Absolute data-model path this component is scoped to. */
|
|
102
|
-
readonly basePath: string;
|
|
103
|
-
readonly theme: Record<string, unknown>;
|
|
104
|
-
readonly surface: SurfaceModel<CopilotA2UICatalogEntry>;
|
|
105
|
-
readonly dataContext: DataContext;
|
|
106
|
-
/** Dispatch a raw A2UI action, e.g. `{ event: { name, context } }`. */
|
|
107
|
-
dispatch(action: unknown): Promise<void>;
|
|
108
|
-
/** Write into the surface data model at a relative or absolute path. */
|
|
109
|
-
set(path: string, value: unknown): void;
|
|
110
|
-
}
|
|
111
|
-
declare const A2UI_COMPONENT_CONTEXT: InjectionToken<A2UIComponentContext>;
|
|
112
|
-
/** Inject the {@link A2UIComponentContext} of the current catalog component. */
|
|
113
|
-
declare function injectA2UIComponentContext(): A2UIComponentContext;
|
|
114
|
-
|
|
115
|
-
interface CreateAngularCatalogOptions {
|
|
116
|
-
/** Identifier advertised to the agent. */
|
|
117
|
-
catalogId?: string;
|
|
118
|
-
/** Functions for bindings and expressions. Defaults to the A2UI basic functions; pass `[]` to disable. */
|
|
119
|
-
functions?: FunctionImplementation[];
|
|
120
|
-
/** Include the basic catalog's components; definitions with the same name replace them. */
|
|
121
|
-
includeBasicCatalog?: boolean;
|
|
122
|
-
}
|
|
123
|
-
/**
|
|
124
|
-
* Build a {@link CopilotA2UICatalog} from zod definitions and, per entry, an
|
|
125
|
-
* Angular component or a Custom Element (`{ tagName, element }`).
|
|
126
|
-
* Without `includeBasicCatalog` the catalog contains exactly what you
|
|
127
|
-
* register, so include any layout primitives the agent should use.
|
|
128
|
-
*/
|
|
129
|
-
declare function createAngularCatalog<D extends A2UICatalogDefinitions>(definitions: D, components: {
|
|
130
|
-
[K in keyof D]: Type<unknown> | A2UIWebComponent;
|
|
131
|
-
}, options?: CreateAngularCatalogOptions): CopilotA2UICatalog;
|
|
132
|
-
|
|
133
|
-
type Surface = SurfaceModel<CopilotA2UICatalogEntry>;
|
|
134
|
-
/**
|
|
135
|
-
* Renders A2UI operations with a {@link CopilotA2UICatalog}. Place it directly in
|
|
136
|
-
* a template to render operations outside the chat.
|
|
137
|
-
*
|
|
138
|
-
* @example
|
|
139
|
-
* ```html
|
|
140
|
-
* <copilot-a2ui-surface
|
|
141
|
-
* [operations]="operations()"
|
|
142
|
-
* [catalog]="dashboardCatalog"
|
|
143
|
-
* (action)="onAction($event)"
|
|
144
|
-
* />
|
|
145
|
-
* ```
|
|
146
|
-
*/
|
|
147
|
-
declare class CopilotA2UISurface implements OnDestroy {
|
|
148
|
-
/** A2UI operations in v0.9 or legacy shape. */
|
|
149
|
-
readonly operations: _angular_core.InputSignal<readonly unknown[]>;
|
|
150
|
-
readonly catalog: _angular_core.InputSignal<CopilotA2UICatalog>;
|
|
151
|
-
/** Theme for surfaces the renderer creates itself. */
|
|
152
|
-
readonly theme: _angular_core.InputSignal<Record<string, unknown> | undefined>;
|
|
153
|
-
/** Shown until the first surface renders. */
|
|
154
|
-
readonly loadingComponent: _angular_core.InputSignal<Type<unknown> | undefined>;
|
|
155
|
-
readonly action: _angular_core.OutputEmitterRef<A2UIClientEventMessage>;
|
|
156
|
-
readonly error: _angular_core.OutputEmitterRef<A2UISurfaceError>;
|
|
157
|
-
/** Emits after each applied batch of operations. */
|
|
158
|
-
readonly rendered: _angular_core.OutputEmitterRef<void>;
|
|
159
|
-
protected readonly surfaces: _angular_core.WritableSignal<Surface[]>;
|
|
160
|
-
protected readonly errorMessage: _angular_core.WritableSignal<string | null>;
|
|
161
|
-
private readonly revision;
|
|
162
|
-
private processor;
|
|
163
|
-
private processorCatalog;
|
|
164
|
-
private lastOperationsHash;
|
|
165
|
-
private appliedOperationsCount;
|
|
166
|
-
constructor();
|
|
167
|
-
ngOnDestroy(): void;
|
|
168
|
-
/** Drops the processor and everything rendered from it. */
|
|
169
|
-
private reset;
|
|
170
|
-
private getProcessor;
|
|
171
|
-
private process;
|
|
172
|
-
static ɵfac: _angular_core.ɵɵFactoryDeclaration<CopilotA2UISurface, never>;
|
|
173
|
-
static ɵcmp: _angular_core.ɵɵComponentDeclaration<CopilotA2UISurface, "copilot-a2ui-surface", never, { "operations": { "alias": "operations"; "required": false; "isSignal": true; }; "catalog": { "alias": "catalog"; "required": true; "isSignal": true; }; "theme": { "alias": "theme"; "required": false; "isSignal": true; }; "loadingComponent": { "alias": "loadingComponent"; "required": false; "isSignal": true; }; }, { "action": "action"; "error": "error"; "rendered": "rendered"; }, never, never, true, never>;
|
|
174
|
-
}
|
|
175
|
-
|
|
176
|
-
export { A2UI_COMPONENT_CONTEXT, CopilotA2UICatalog, CopilotA2UIChild, CopilotA2UISurface, basicCatalog, createAngularCatalog, injectA2UIComponentContext };
|
|
177
|
-
export type { A2UICatalogDefinitions, A2UIChildRef, A2UIComponentContext, A2UIComponentDefinition, A2UIProps, A2UIWebComponent, A2uiWebComponentElement, CopilotA2UICatalogEntry, CopilotA2UIComponentImplementation, CreateAngularCatalogOptions, WebComponentImplementation };
|
|
178
|
-
//# sourceMappingURL=copilotkit-angular-a2ui.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"copilotkit-angular-a2ui.d.ts","sources":["../../src/a2ui/lib/universal.ts","../../src/a2ui/lib/types.ts","../../src/a2ui/lib/catalog.ts","../../src/a2ui/lib/basic/catalog.ts","../../src/a2ui/lib/child-ref.ts","../../src/a2ui/lib/child.ts","../../src/a2ui/lib/component-context.ts","../../src/a2ui/lib/create-catalog.ts","../../src/a2ui/lib/surface.ts"],"mappings":";;;;;;;;AAAA;;;;;;;AAOG;;AAGH;AACM,UAAW,0BAA2B,SAAQ,YAAY;;AAE9D;;AAEA,sBAAkB,wBAAwB;AAC3C;AAED;;;AAGG;AACG,UAAW,uBAAwB,SAAQ,WAAW;cAChD,gBAAgB;AAC3B;;ACnBD;AACM,UAAW,kCAAmC,SAAQ,YAAY;AACtE,wBAAoB,IAAI;AACzB;AAED;KACY,uBAAuB,GAC/B,kCAAkC,GAClC,0BAA0B;AAE9B;AACM,KAAM,gBAAgB,GAAG,IAAI,CACjC,0BAA0B;UAIX,uBAAuB,WAAW,WAAW,GAAG,WAAW;AAC1E,WAAO,SAAS;;;AAGjB;AAEK,KAAM,sBAAsB,GAAG,MAAM,SAEzC,uBAAuB;AAGzB;;;;AAIG;AACG,KAAM,SAAS,WACT,sBAAsB,uBAE9B,gBAAgB,CAAC,CAAC,CAAC,KAAK;AAEtB,KAAM,YAAY;;;;;ACpCxB;;;AAGG;AACH,cAAa,kBACX,SAAQ,OAAO,CAAC,uBAAuB,aAC5B,WAAW;AAEtB,+BAA2B,IAAI;AAChC;;AC8DD;;;AAGG;AACH,cAAa,YAAY,EAAA,kBAIxB;;UClFgB,gBAAgB;;;AAGhC;;ACAD;;;;;;;;;;AAUG;AACH,cAca,gBAAgB;;oBAEb,aAAA,CAAA,WAAA,CAAA,YAAA;AAEd,gCAA0B,wBAAA,CAAA,oBAAA;AAE1B,kCAA4B,aAAA,CAAA,MAAA,CAAAA,gBAAA;oDANjB,gBAAgB;sDAAhB,gBAAgB;AAU5B;;ACjCD;UACiB,oBAAoB;AACnC;AACA;;AAEA;oBACgB,MAAM;AACtB,sBAAkB,YAAY,CAAC,uBAAuB;AACtD,0BAAsB,WAAW;;+BAEN,OAAO;;;AAGnC;AAED,cAAa,sBAAsB,EAAA,cAAA,CAAA,oBAAA;AAInC;AACA,iBAAgB,0BAA0B,IAAI,oBAAoB;;UCdjD,2BAA2B;;;;AAI1C,gBAAY,sBAAsB;;;AAGnC;AAED;;;;;AAKG;AACH,iBAAgB,oBAAoB,WAAW,sBAAsB;oBAErC,IAAI,YAAY,gBAAgB;AAAE,aACtD,2BAA2B,GACpC,kBAAkB;;ACdrB,KAAK,OAAO,GAAG,YAAY,CAAC,uBAAuB;AAEnD;;;;;;;;;;;;AAYG;AACH,cAsIa,kBAAmB,YAAW,SAAS;;yBAE/B,aAAA,CAAA,WAAA;sBACH,aAAA,CAAA,WAAA,CAAA,kBAAA;;oBAEF,aAAA,CAAA,WAAA,CAAA,MAAA;;+BAEW,aAAA,CAAA,WAAA,CAAA,IAAA;qBAEV,aAAA,CAAA,gBAAA,CAAA,sBAAA;oBACD,aAAA,CAAA,gBAAA,CAAA,gBAAA;;uBAEG,aAAA,CAAA,gBAAA;AAEjB,iCAA2B,aAAA,CAAA,cAAA,CAAA,OAAA;AAC3B,qCAA+B,aAAA,CAAA,cAAA;AAC/B;;;;;;AAgBA;;AAKA;AASA;AAaA;oDA3DW,kBAAkB;sDAAlB,kBAAkB;AAyG9B;;;;","names":["__child_ref.ResolvedChildRef"]}
|
|
@@ -1,100 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Post-processes compiled Tailwind CSS to scope all @layer base rules
|
|
3
|
-
* under [data-copilotkit], preventing CopilotKit styles from leaking
|
|
4
|
-
* into the host application.
|
|
5
|
-
*
|
|
6
|
-
* Run after `tailwindcss` CLI: node scripts/scope-preflight.mjs <file>
|
|
7
|
-
*/
|
|
8
|
-
|
|
9
|
-
import { readFileSync, writeFileSync } from "fs";
|
|
10
|
-
import postcss from "postcss";
|
|
11
|
-
|
|
12
|
-
const SCOPE = "[data-copilotkit]";
|
|
13
|
-
const file = process.argv[2];
|
|
14
|
-
if (!file) {
|
|
15
|
-
console.error("Usage: node scripts/scope-preflight.mjs <css-file>");
|
|
16
|
-
process.exit(1);
|
|
17
|
-
}
|
|
18
|
-
|
|
19
|
-
/** Selectors that are already scoped and should be left alone. */
|
|
20
|
-
function isAlreadyScoped(selector) {
|
|
21
|
-
return (
|
|
22
|
-
selector.includes("[data-copilot") || selector.includes("[data-sidebar")
|
|
23
|
-
);
|
|
24
|
-
}
|
|
25
|
-
|
|
26
|
-
/** Rewrite a single selector to be scoped under [data-copilotkit]. */
|
|
27
|
-
function scopeSelector(sel) {
|
|
28
|
-
sel = sel.trim();
|
|
29
|
-
|
|
30
|
-
// Already scoped — keep as-is
|
|
31
|
-
if (isAlreadyScoped(sel)) return sel;
|
|
32
|
-
|
|
33
|
-
// html, :host → [data-copilotkit]
|
|
34
|
-
if (sel === "html" || sel === ":host" || sel === "html,:host") {
|
|
35
|
-
return SCOPE;
|
|
36
|
-
}
|
|
37
|
-
|
|
38
|
-
// body → null (remove)
|
|
39
|
-
if (sel === "body") return null;
|
|
40
|
-
|
|
41
|
-
// ::backdrop → null (cannot be scoped to a container)
|
|
42
|
-
if (sel === "::backdrop") return null;
|
|
43
|
-
|
|
44
|
-
// Bare universal selector → scope to container + descendants
|
|
45
|
-
if (sel === "*") return `${SCOPE}, ${SCOPE} *`;
|
|
46
|
-
|
|
47
|
-
// Pseudo-elements (::) and vendor pseudo-classes (:-) → descendant only
|
|
48
|
-
// These can't be combined with an attribute selector suffix
|
|
49
|
-
if (sel.startsWith(":")) {
|
|
50
|
-
return `${SCOPE} ${sel}`;
|
|
51
|
-
}
|
|
52
|
-
|
|
53
|
-
// Element / attribute selectors → descendant AND self-matching
|
|
54
|
-
// e.g. button → [data-copilotkit] button, button[data-copilotkit]
|
|
55
|
-
// This ensures <button data-copilotkit> also receives the preflight reset
|
|
56
|
-
return `${SCOPE} ${sel}, ${sel}${SCOPE}`;
|
|
57
|
-
}
|
|
58
|
-
|
|
59
|
-
function scopeRule(rule) {
|
|
60
|
-
const newSelectors = [];
|
|
61
|
-
|
|
62
|
-
for (const sel of rule.selectors) {
|
|
63
|
-
const scoped = scopeSelector(sel);
|
|
64
|
-
if (scoped !== null) {
|
|
65
|
-
// scopeSelector may return comma-separated selectors (for *)
|
|
66
|
-
if (typeof scoped === "string" && scoped.includes(", ")) {
|
|
67
|
-
newSelectors.push(...scoped.split(", "));
|
|
68
|
-
} else if (scoped) {
|
|
69
|
-
newSelectors.push(scoped);
|
|
70
|
-
}
|
|
71
|
-
}
|
|
72
|
-
}
|
|
73
|
-
|
|
74
|
-
if (newSelectors.length === 0) {
|
|
75
|
-
rule.remove();
|
|
76
|
-
} else {
|
|
77
|
-
rule.selectors = newSelectors;
|
|
78
|
-
}
|
|
79
|
-
}
|
|
80
|
-
|
|
81
|
-
/** Recursively scope all rules within a node (handles @supports, @media, etc.) */
|
|
82
|
-
function scopeChildren(node) {
|
|
83
|
-
node.walk((child) => {
|
|
84
|
-
if (child.type === "rule") {
|
|
85
|
-
scopeRule(child);
|
|
86
|
-
}
|
|
87
|
-
// @supports / @media blocks are walked automatically
|
|
88
|
-
});
|
|
89
|
-
}
|
|
90
|
-
|
|
91
|
-
// --- Main ---
|
|
92
|
-
const css = readFileSync(file, "utf8");
|
|
93
|
-
const root = postcss.parse(css);
|
|
94
|
-
|
|
95
|
-
root.walkAtRules("layer", (layer) => {
|
|
96
|
-
if (layer.params !== "base") return;
|
|
97
|
-
scopeChildren(layer);
|
|
98
|
-
});
|
|
99
|
-
|
|
100
|
-
writeFileSync(file, root.toString());
|