@microsoft/fast-element 1.10.0 → 2.0.0-beta.1
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/.eslintrc.json +1 -12
- package/CHANGELOG.json +396 -1
- package/CHANGELOG.md +68 -2
- package/README.md +2 -2
- package/dist/dts/components/attributes.d.ts +4 -1
- package/dist/dts/components/controller.d.ts +12 -11
- package/dist/dts/components/fast-definitions.d.ts +8 -2
- package/dist/dts/components/fast-element.d.ts +5 -4
- package/dist/dts/debug.d.ts +1 -0
- package/dist/dts/hooks.d.ts +20 -0
- package/dist/dts/index.d.ts +16 -15
- package/dist/dts/index.debug.d.ts +2 -0
- package/dist/dts/index.rollup.d.ts +2 -0
- package/dist/dts/index.rollup.debug.d.ts +3 -0
- package/dist/dts/interfaces.d.ts +144 -0
- package/dist/dts/observation/arrays.d.ts +207 -0
- package/dist/dts/observation/behavior.d.ts +5 -5
- package/dist/dts/observation/notifier.d.ts +18 -18
- package/dist/dts/observation/observable.d.ts +86 -29
- package/dist/dts/observation/splice-strategies.d.ts +13 -0
- package/dist/dts/observation/update-queue.d.ts +40 -0
- package/dist/dts/platform.d.ts +18 -67
- package/dist/dts/polyfills.d.ts +8 -0
- package/dist/dts/styles/css-directive.d.ts +43 -5
- package/dist/dts/styles/css.d.ts +19 -3
- package/dist/dts/styles/element-styles.d.ts +42 -62
- package/dist/dts/templating/binding.d.ts +320 -64
- package/dist/dts/templating/children.d.ts +18 -15
- package/dist/dts/templating/compiler.d.ts +47 -28
- package/dist/dts/templating/dom.d.ts +41 -0
- package/dist/dts/templating/html-directive.d.ts +179 -43
- package/dist/dts/templating/markup.d.ts +48 -0
- package/dist/dts/templating/node-observation.d.ts +45 -29
- package/dist/dts/templating/ref.d.ts +6 -12
- package/dist/dts/templating/repeat.d.ts +72 -14
- package/dist/dts/templating/slotted.d.ts +13 -14
- package/dist/dts/templating/template.d.ts +78 -23
- package/dist/dts/templating/view.d.ts +16 -23
- package/dist/dts/utilities.d.ts +40 -0
- package/dist/esm/components/attributes.js +25 -24
- package/dist/esm/components/controller.js +77 -57
- package/dist/esm/components/fast-definitions.js +14 -22
- package/dist/esm/debug.js +29 -0
- package/dist/esm/hooks.js +32 -0
- package/dist/esm/index.debug.js +2 -0
- package/dist/esm/index.js +19 -14
- package/dist/esm/index.rollup.debug.js +3 -0
- package/dist/esm/index.rollup.js +2 -0
- package/dist/esm/interfaces.js +8 -1
- package/dist/esm/observation/arrays.js +269 -0
- package/dist/esm/observation/notifier.js +75 -83
- package/dist/esm/observation/observable.js +80 -107
- package/dist/esm/observation/{array-change-records.js → splice-strategies.js} +136 -62
- package/dist/esm/observation/update-queue.js +67 -0
- package/dist/esm/platform.js +36 -42
- package/dist/esm/polyfills.js +85 -0
- package/dist/esm/styles/css-directive.js +29 -13
- package/dist/esm/styles/css.js +27 -40
- package/dist/esm/styles/element-styles.js +65 -104
- package/dist/esm/templating/binding.js +465 -155
- package/dist/esm/templating/children.js +33 -23
- package/dist/esm/templating/compiler.js +235 -152
- package/dist/esm/templating/dom.js +49 -0
- package/dist/esm/templating/html-directive.js +125 -40
- package/dist/esm/templating/markup.js +75 -0
- package/dist/esm/templating/node-observation.js +50 -45
- package/dist/esm/templating/ref.js +7 -16
- package/dist/esm/templating/repeat.js +38 -43
- package/dist/esm/templating/slotted.js +23 -20
- package/dist/esm/templating/template.js +71 -95
- package/dist/esm/templating/view.js +44 -43
- package/dist/esm/templating/when.js +2 -1
- package/dist/esm/utilities.js +139 -0
- package/dist/fast-element.api.json +14062 -5235
- package/dist/fast-element.d.ts +1434 -579
- package/dist/fast-element.debug.js +3824 -0
- package/dist/fast-element.debug.min.js +1 -0
- package/dist/fast-element.js +3565 -4014
- package/dist/fast-element.min.js +1 -1
- package/dist/fast-element.untrimmed.d.ts +2908 -0
- package/dist/tsdoc-metadata.json +1 -1
- package/docs/api-report.md +590 -231
- package/docs/fast-element-2-changes.md +15 -0
- package/docs/guide/declaring-templates.md +5 -4
- package/docs/guide/defining-elements.md +3 -2
- package/docs/guide/leveraging-css.md +1 -0
- package/docs/guide/next-steps.md +3 -2
- package/docs/guide/observables-and-state.md +2 -1
- package/docs/guide/using-directives.md +2 -1
- package/docs/guide/working-with-shadow-dom.md +1 -0
- package/karma.conf.cjs +6 -17
- package/package.json +48 -14
- package/dist/dts/dom.d.ts +0 -112
- package/dist/dts/observation/array-change-records.d.ts +0 -48
- package/dist/dts/observation/array-observer.d.ts +0 -9
- package/dist/esm/dom.js +0 -207
- package/dist/esm/observation/array-observer.js +0 -173
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { Disposable } from "../interfaces.js";
|
|
1
2
|
import type { Notifier, Subscriber } from "./notifier.js";
|
|
2
3
|
/**
|
|
3
4
|
* Represents a getter/setter property accessor on an object.
|
|
@@ -25,7 +26,7 @@ export interface Accessor {
|
|
|
25
26
|
* as part of a template binding update.
|
|
26
27
|
* @public
|
|
27
28
|
*/
|
|
28
|
-
export declare type Binding<TSource = any, TReturn = any,
|
|
29
|
+
export declare type Binding<TSource = any, TReturn = any, TContext extends ExecutionContext = ExecutionContext> = (source: TSource, context: TContext) => TReturn;
|
|
29
30
|
/**
|
|
30
31
|
* A record of observable property access.
|
|
31
32
|
* @public
|
|
@@ -44,23 +45,28 @@ export interface ObservationRecord {
|
|
|
44
45
|
* Enables evaluation of and subscription to a binding.
|
|
45
46
|
* @public
|
|
46
47
|
*/
|
|
47
|
-
export interface BindingObserver<TSource = any, TReturn = any, TParent = any> extends Notifier {
|
|
48
|
+
export interface BindingObserver<TSource = any, TReturn = any, TParent = any> extends Notifier, Disposable {
|
|
48
49
|
/**
|
|
49
50
|
* Begins observing the binding for the source and returns the current value.
|
|
50
51
|
* @param source - The source that the binding is based on.
|
|
51
52
|
* @param context - The execution context to execute the binding within.
|
|
52
53
|
* @returns The value of the binding.
|
|
53
54
|
*/
|
|
54
|
-
observe(source: TSource, context
|
|
55
|
-
/**
|
|
56
|
-
* Unsubscribe from all dependent observables of the binding.
|
|
57
|
-
*/
|
|
58
|
-
disconnect(): void;
|
|
55
|
+
observe(source: TSource, context?: ExecutionContext<TParent>): TReturn;
|
|
59
56
|
/**
|
|
60
57
|
* Gets {@link ObservationRecord|ObservationRecords} that the {@link BindingObserver}
|
|
61
58
|
* is observing.
|
|
62
59
|
*/
|
|
63
60
|
records(): IterableIterator<ObservationRecord>;
|
|
61
|
+
/**
|
|
62
|
+
* Sets the update mode used by the observer.
|
|
63
|
+
* @param isAsync - Indicates whether updates should be asynchronous.
|
|
64
|
+
* @remarks
|
|
65
|
+
* By default, the update mode is asynchronous, since that provides the best
|
|
66
|
+
* performance for template rendering scenarios. Passing false to setMode will
|
|
67
|
+
* instead cause the observer to notify subscribers immediately when changes occur.
|
|
68
|
+
*/
|
|
69
|
+
setMode(isAsync: boolean): void;
|
|
64
70
|
}
|
|
65
71
|
/**
|
|
66
72
|
* Common Observable APIs.
|
|
@@ -76,7 +82,7 @@ export declare const Observable: Readonly<{
|
|
|
76
82
|
* Gets a notifier for an object or Array.
|
|
77
83
|
* @param source - The object or Array to get the notifier for.
|
|
78
84
|
*/
|
|
79
|
-
getNotifier: (source: any) =>
|
|
85
|
+
getNotifier: <T extends Notifier = Notifier>(source: any) => T;
|
|
80
86
|
/**
|
|
81
87
|
* Records a property change for a source object.
|
|
82
88
|
* @param source - The object to record the change against.
|
|
@@ -114,13 +120,13 @@ export declare const Observable: Readonly<{
|
|
|
114
120
|
* @param initialSubscriber - An initial subscriber to changes in the binding value.
|
|
115
121
|
* @param isVolatileBinding - Indicates whether the binding's dependency list must be re-evaluated on every value evaluation.
|
|
116
122
|
*/
|
|
117
|
-
binding<TSource = any, TReturn = any
|
|
123
|
+
binding<TSource = any, TReturn = any>(binding: Binding<TSource, TReturn, ExecutionContext<any>>, initialSubscriber?: Subscriber, isVolatileBinding?: boolean): BindingObserver<TSource, TReturn, any>;
|
|
118
124
|
/**
|
|
119
125
|
* Determines whether a binding expression is volatile and needs to have its dependency list re-evaluated
|
|
120
126
|
* on every evaluation of the value.
|
|
121
127
|
* @param binding - The binding to inspect.
|
|
122
128
|
*/
|
|
123
|
-
isVolatileBinding<TSource_1 = any, TReturn_1 = any
|
|
129
|
+
isVolatileBinding<TSource_1 = any, TReturn_1 = any>(binding: Binding<TSource_1, TReturn_1, ExecutionContext<any>>): boolean;
|
|
124
130
|
}>;
|
|
125
131
|
/**
|
|
126
132
|
* Decorator: Defines an observable property on the target.
|
|
@@ -141,61 +147,112 @@ export declare function volatile(target: {}, name: string | Accessor, descriptor
|
|
|
141
147
|
* Provides additional contextual information available to behaviors and expressions.
|
|
142
148
|
* @public
|
|
143
149
|
*/
|
|
144
|
-
export
|
|
150
|
+
export interface RootContext {
|
|
145
151
|
/**
|
|
146
|
-
* The
|
|
152
|
+
* The current event within an event handler.
|
|
147
153
|
*/
|
|
148
|
-
|
|
154
|
+
readonly event: Event;
|
|
149
155
|
/**
|
|
150
|
-
*
|
|
156
|
+
* Returns the typed event detail of a custom event.
|
|
157
|
+
*/
|
|
158
|
+
eventDetail<TDetail = any>(): TDetail;
|
|
159
|
+
/**
|
|
160
|
+
* Returns the typed event target of the event.
|
|
151
161
|
*/
|
|
152
|
-
|
|
162
|
+
eventTarget<TTarget extends EventTarget = EventTarget>(): TTarget;
|
|
153
163
|
/**
|
|
154
|
-
*
|
|
164
|
+
* Creates a new execution context descendent from the current context.
|
|
165
|
+
* @param source - The source for the context if different than the parent.
|
|
166
|
+
* @returns A child execution context.
|
|
155
167
|
*/
|
|
156
|
-
|
|
168
|
+
createChildContext<TParentSource>(source: TParentSource): ChildContext<TParentSource>;
|
|
169
|
+
}
|
|
170
|
+
/**
|
|
171
|
+
* Provides additional contextual information when inside a child template.
|
|
172
|
+
* @public
|
|
173
|
+
*/
|
|
174
|
+
export interface ChildContext<TParentSource = any> extends RootContext {
|
|
175
|
+
/**
|
|
176
|
+
* The parent data source within a nested context.
|
|
177
|
+
*/
|
|
178
|
+
readonly parent: TParentSource;
|
|
157
179
|
/**
|
|
158
180
|
* The parent execution context when in nested context scenarios.
|
|
159
181
|
*/
|
|
160
|
-
parentContext:
|
|
182
|
+
readonly parentContext: ChildContext<TParentSource>;
|
|
161
183
|
/**
|
|
162
|
-
*
|
|
184
|
+
* Creates a new execution context descent suitable for use in list rendering.
|
|
185
|
+
* @param item - The list item to serve as the source.
|
|
186
|
+
* @param index - The index of the item in the list.
|
|
187
|
+
* @param length - The length of the list.
|
|
188
|
+
*/
|
|
189
|
+
createItemContext(index: number, length: number): ItemContext<TParentSource>;
|
|
190
|
+
}
|
|
191
|
+
/**
|
|
192
|
+
* Provides additional contextual information when inside a repeat item template.s
|
|
193
|
+
* @public
|
|
194
|
+
*/
|
|
195
|
+
export interface ItemContext<TParentSource = any> extends ChildContext<TParentSource> {
|
|
196
|
+
/**
|
|
197
|
+
* The index of the current item within a repeat context.
|
|
163
198
|
*/
|
|
164
|
-
|
|
199
|
+
readonly index: number;
|
|
200
|
+
/**
|
|
201
|
+
* The length of the current collection within a repeat context.
|
|
202
|
+
*/
|
|
203
|
+
readonly length: number;
|
|
165
204
|
/**
|
|
166
205
|
* Indicates whether the current item within a repeat context
|
|
167
206
|
* has an even index.
|
|
168
207
|
*/
|
|
169
|
-
|
|
208
|
+
readonly isEven: boolean;
|
|
170
209
|
/**
|
|
171
210
|
* Indicates whether the current item within a repeat context
|
|
172
211
|
* has an odd index.
|
|
173
212
|
*/
|
|
174
|
-
|
|
213
|
+
readonly isOdd: boolean;
|
|
175
214
|
/**
|
|
176
215
|
* Indicates whether the current item within a repeat context
|
|
177
216
|
* is the first item in the collection.
|
|
178
217
|
*/
|
|
179
|
-
|
|
218
|
+
readonly isFirst: boolean;
|
|
180
219
|
/**
|
|
181
220
|
* Indicates whether the current item within a repeat context
|
|
182
221
|
* is somewhere in the middle of the collection.
|
|
183
222
|
*/
|
|
184
|
-
|
|
223
|
+
readonly isInMiddle: boolean;
|
|
185
224
|
/**
|
|
186
225
|
* Indicates whether the current item within a repeat context
|
|
187
226
|
* is the last item in the collection.
|
|
188
227
|
*/
|
|
189
|
-
|
|
228
|
+
readonly isLast: boolean;
|
|
229
|
+
/**
|
|
230
|
+
* Updates the position/size on a context associated with a list item.
|
|
231
|
+
* @param index - The new index of the item.
|
|
232
|
+
* @param length - The new length of the list.
|
|
233
|
+
*/
|
|
234
|
+
updatePosition(index: number, length: number): void;
|
|
235
|
+
}
|
|
236
|
+
/**
|
|
237
|
+
* The common execution context APIs.
|
|
238
|
+
* @public
|
|
239
|
+
*/
|
|
240
|
+
export declare const ExecutionContext: Readonly<{
|
|
241
|
+
default: RootContext;
|
|
190
242
|
/**
|
|
191
243
|
* Sets the event for the current execution context.
|
|
192
244
|
* @param event - The event to set.
|
|
193
245
|
* @internal
|
|
194
246
|
*/
|
|
195
|
-
|
|
196
|
-
|
|
247
|
+
setEvent(event: Event | null): void;
|
|
248
|
+
/**
|
|
249
|
+
* Creates a new root execution context.
|
|
250
|
+
* @returns A new execution context.
|
|
251
|
+
*/
|
|
252
|
+
create(): RootContext;
|
|
253
|
+
}>;
|
|
197
254
|
/**
|
|
198
|
-
*
|
|
255
|
+
* Represents some sort of execution context.
|
|
199
256
|
* @public
|
|
200
257
|
*/
|
|
201
|
-
export declare
|
|
258
|
+
export declare type ExecutionContext<TParentSource = any> = RootContext | ChildContext<TParentSource> | ItemContext<TParentSource>;
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import { SpliceStrategy } from "./arrays.js";
|
|
2
|
+
/**
|
|
3
|
+
* A SpliceStrategy that attempts to merge all splices into the minimal set of
|
|
4
|
+
* splices needed to represent the change from the old array to the new array.
|
|
5
|
+
* @public
|
|
6
|
+
*/
|
|
7
|
+
export declare const mergeSpliceStrategy: SpliceStrategy;
|
|
8
|
+
/**
|
|
9
|
+
* A splice strategy that doesn't create splices, but instead
|
|
10
|
+
* tracks every change as a full array reset.
|
|
11
|
+
* @public
|
|
12
|
+
*/
|
|
13
|
+
export declare const resetSpliceStrategy: SpliceStrategy;
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
import { Callable } from "../interfaces.js";
|
|
2
|
+
/**
|
|
3
|
+
* A work queue used to synchronize writes to the DOM.
|
|
4
|
+
* @public
|
|
5
|
+
*/
|
|
6
|
+
export interface UpdateQueue {
|
|
7
|
+
/**
|
|
8
|
+
* Schedules DOM update work in the next batch.
|
|
9
|
+
* @param callable - The callable function or object to queue.
|
|
10
|
+
*/
|
|
11
|
+
enqueue(callable: Callable): void;
|
|
12
|
+
/**
|
|
13
|
+
* Resolves with the next DOM update.
|
|
14
|
+
*/
|
|
15
|
+
next(): Promise<void>;
|
|
16
|
+
/**
|
|
17
|
+
* Immediately processes all work previously scheduled
|
|
18
|
+
* through enqueue.
|
|
19
|
+
* @remarks
|
|
20
|
+
* This also forces next() promises
|
|
21
|
+
* to resolve.
|
|
22
|
+
*/
|
|
23
|
+
process(): void;
|
|
24
|
+
/**
|
|
25
|
+
* Sets the update mode used by enqueue.
|
|
26
|
+
* @param isAsync - Indicates whether DOM updates should be asynchronous.
|
|
27
|
+
* @remarks
|
|
28
|
+
* By default, the update mode is asynchronous, since that provides the best
|
|
29
|
+
* performance in the browser. Passing false to setMode will instead cause
|
|
30
|
+
* the queue to be immediately processed for each call to enqueue. However,
|
|
31
|
+
* ordering will still be preserved so that nested tasks do not run until
|
|
32
|
+
* after parent tasks complete.
|
|
33
|
+
*/
|
|
34
|
+
setMode(isAsync: boolean): void;
|
|
35
|
+
}
|
|
36
|
+
/**
|
|
37
|
+
* The default UpdateQueue.
|
|
38
|
+
* @public
|
|
39
|
+
*/
|
|
40
|
+
export declare const Updates: UpdateQueue;
|
package/dist/dts/platform.d.ts
CHANGED
|
@@ -1,84 +1,35 @@
|
|
|
1
|
-
|
|
2
|
-
* A policy for use with the standard trustedTypes platform API.
|
|
3
|
-
* @public
|
|
4
|
-
*/
|
|
5
|
-
export declare type TrustedTypesPolicy = {
|
|
6
|
-
/**
|
|
7
|
-
* Creates trusted HTML.
|
|
8
|
-
* @param html - The HTML to clear as trustworthy.
|
|
9
|
-
*/
|
|
10
|
-
createHTML(html: string): string;
|
|
11
|
-
};
|
|
12
|
-
/**
|
|
13
|
-
* Enables working with trusted types.
|
|
14
|
-
* @public
|
|
15
|
-
*/
|
|
16
|
-
export declare type TrustedTypes = {
|
|
17
|
-
/**
|
|
18
|
-
* Creates a trusted types policy.
|
|
19
|
-
* @param name - The policy name.
|
|
20
|
-
* @param rules - The policy rules implementation.
|
|
21
|
-
*/
|
|
22
|
-
createPolicy(name: string, rules: TrustedTypesPolicy): TrustedTypesPolicy;
|
|
23
|
-
};
|
|
1
|
+
import type { FASTGlobal } from "./interfaces.js";
|
|
24
2
|
/**
|
|
25
3
|
* The FAST global.
|
|
26
4
|
* @internal
|
|
27
5
|
*/
|
|
28
|
-
export
|
|
29
|
-
/**
|
|
30
|
-
* The list of loaded versions.
|
|
31
|
-
*/
|
|
32
|
-
readonly versions: string[];
|
|
33
|
-
/**
|
|
34
|
-
* Gets a kernel value.
|
|
35
|
-
* @param id - The id to get the value for.
|
|
36
|
-
* @param initialize - Creates the initial value for the id if not already existing.
|
|
37
|
-
*/
|
|
38
|
-
getById<T>(id: string | number): T | null;
|
|
39
|
-
getById<T>(id: string | number, initialize: () => T): T;
|
|
40
|
-
}
|
|
41
|
-
/**
|
|
42
|
-
* The platform global type.
|
|
43
|
-
* @public
|
|
44
|
-
*/
|
|
45
|
-
export declare type Global = typeof globalThis & {
|
|
46
|
-
/**
|
|
47
|
-
* Enables working with trusted types.
|
|
48
|
-
*/
|
|
49
|
-
trustedTypes: TrustedTypes;
|
|
50
|
-
/**
|
|
51
|
-
* The FAST global.
|
|
52
|
-
* @internal
|
|
53
|
-
*/
|
|
54
|
-
readonly FAST: FASTGlobal;
|
|
55
|
-
};
|
|
6
|
+
export declare const FAST: FASTGlobal;
|
|
56
7
|
/**
|
|
57
|
-
* A
|
|
58
|
-
*
|
|
8
|
+
* A readonly, empty array.
|
|
9
|
+
* @remarks
|
|
10
|
+
* Typically returned by APIs that return arrays when there are
|
|
11
|
+
* no actual items to return.
|
|
59
12
|
* @public
|
|
60
13
|
*/
|
|
61
|
-
export declare const
|
|
14
|
+
export declare const emptyArray: readonly never[];
|
|
62
15
|
/**
|
|
63
|
-
*
|
|
16
|
+
* Do not change. Part of shared kernel contract.
|
|
64
17
|
* @internal
|
|
65
18
|
*/
|
|
66
|
-
export
|
|
19
|
+
export interface TypeDefinition {
|
|
20
|
+
type: Function;
|
|
21
|
+
}
|
|
67
22
|
/**
|
|
68
|
-
*
|
|
23
|
+
* Do not change. Part of shared kernel contract.
|
|
69
24
|
* @internal
|
|
70
25
|
*/
|
|
71
|
-
export
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
elementRegistry = 4
|
|
26
|
+
export interface TypeRegistry<TDefinition extends TypeDefinition> {
|
|
27
|
+
register(definition: TDefinition): boolean;
|
|
28
|
+
getByType(key: Function): TDefinition | undefined;
|
|
29
|
+
getForInstance(object: any): TDefinition | undefined;
|
|
76
30
|
}
|
|
77
31
|
/**
|
|
78
|
-
*
|
|
79
|
-
* @remarks
|
|
80
|
-
* Typically returned by APIs that return arrays when there are
|
|
81
|
-
* no actual items to return.
|
|
32
|
+
* Do not change. Part of shared kernel contract.
|
|
82
33
|
* @internal
|
|
83
34
|
*/
|
|
84
|
-
export declare
|
|
35
|
+
export declare function createTypeRegistry<TDefinition extends TypeDefinition>(): TypeRegistry<TDefinition>;
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import type { StyleStrategy, StyleTarget } from "./interfaces.js";
|
|
2
|
+
export declare class StyleElementStrategy implements StyleStrategy {
|
|
3
|
+
private readonly styles;
|
|
4
|
+
private readonly styleClass;
|
|
5
|
+
constructor(styles: string[]);
|
|
6
|
+
addStylesTo(target: StyleTarget): void;
|
|
7
|
+
removeStylesFrom(target: StyleTarget): void;
|
|
8
|
+
}
|
|
@@ -1,19 +1,57 @@
|
|
|
1
|
+
import type { Constructable } from "../interfaces.js";
|
|
1
2
|
import type { Behavior } from "../observation/behavior.js";
|
|
2
3
|
import type { ComposableStyles } from "./element-styles.js";
|
|
4
|
+
/**
|
|
5
|
+
* Used to add behaviors when constructing styles.
|
|
6
|
+
* @public
|
|
7
|
+
*/
|
|
8
|
+
export declare type AddBehavior = (behavior: Behavior<HTMLElement>) => void;
|
|
3
9
|
/**
|
|
4
10
|
* Directive for use in {@link css}.
|
|
5
11
|
*
|
|
6
12
|
* @public
|
|
7
13
|
*/
|
|
8
|
-
export
|
|
14
|
+
export interface CSSDirective {
|
|
9
15
|
/**
|
|
10
16
|
* Creates a CSS fragment to interpolate into the CSS document.
|
|
11
17
|
* @returns - the string to interpolate into CSS
|
|
12
18
|
*/
|
|
13
|
-
createCSS(): ComposableStyles;
|
|
19
|
+
createCSS(add: AddBehavior): ComposableStyles;
|
|
20
|
+
}
|
|
21
|
+
/**
|
|
22
|
+
* Defines metadata for a CSSDirective.
|
|
23
|
+
* @public
|
|
24
|
+
*/
|
|
25
|
+
export interface CSSDirectiveDefinition<TType extends Constructable<CSSDirective> = Constructable<CSSDirective>> {
|
|
14
26
|
/**
|
|
15
|
-
*
|
|
16
|
-
* @returns - the behavior to bind to the host element, or undefined.
|
|
27
|
+
* The type that the definition provides metadata for.
|
|
17
28
|
*/
|
|
18
|
-
|
|
29
|
+
readonly type: TType;
|
|
19
30
|
}
|
|
31
|
+
/**
|
|
32
|
+
* Instructs the css engine to provide dynamic styles or
|
|
33
|
+
* associate behaviors with styles.
|
|
34
|
+
* @public
|
|
35
|
+
*/
|
|
36
|
+
export declare const CSSDirective: Readonly<{
|
|
37
|
+
/**
|
|
38
|
+
* Gets the directive definition associated with the instance.
|
|
39
|
+
* @param instance - The directive instance to retrieve the definition for.
|
|
40
|
+
*/
|
|
41
|
+
getForInstance: (object: any) => CSSDirectiveDefinition<Constructable<CSSDirective>> | undefined;
|
|
42
|
+
/**
|
|
43
|
+
* Gets the directive definition associated with the specified type.
|
|
44
|
+
* @param type - The directive type to retrieve the definition for.
|
|
45
|
+
*/
|
|
46
|
+
getByType: (key: Function) => CSSDirectiveDefinition<Constructable<CSSDirective>> | undefined;
|
|
47
|
+
/**
|
|
48
|
+
* Defines a CSSDirective.
|
|
49
|
+
* @param type - The type to define as a directive.
|
|
50
|
+
*/
|
|
51
|
+
define<TType extends Constructable<CSSDirective>>(type: any): TType;
|
|
52
|
+
}>;
|
|
53
|
+
/**
|
|
54
|
+
* Decorator: Defines a CSSDirective.
|
|
55
|
+
* @public
|
|
56
|
+
*/
|
|
57
|
+
export declare function cssDirective(): (type: Constructable<CSSDirective>) => void;
|
package/dist/dts/styles/css.d.ts
CHANGED
|
@@ -6,13 +6,29 @@ import { ComposableStyles, ElementStyles } from "./element-styles.js";
|
|
|
6
6
|
* @param values - The values that are interpolated with the string fragments.
|
|
7
7
|
* @remarks
|
|
8
8
|
* The css helper supports interpolation of strings and ElementStyle instances.
|
|
9
|
+
* Use the .partial method to create partial CSS fragments.
|
|
9
10
|
* @public
|
|
10
11
|
*/
|
|
11
|
-
export declare
|
|
12
|
+
export declare type CSSTemplateTag = ((strings: TemplateStringsArray, ...values: (ComposableStyles | CSSDirective)[]) => ElementStyles) & {
|
|
13
|
+
/**
|
|
14
|
+
* Transforms a template literal string into partial CSS.
|
|
15
|
+
* @param strings - The string fragments that are interpolated with the values.
|
|
16
|
+
* @param values - The values that are interpolated with the string fragments.
|
|
17
|
+
* @public
|
|
18
|
+
*/
|
|
19
|
+
partial(strings: TemplateStringsArray, ...values: (ComposableStyles | CSSDirective)[]): CSSDirective;
|
|
20
|
+
};
|
|
12
21
|
/**
|
|
13
|
-
* Transforms a template literal string into
|
|
22
|
+
* Transforms a template literal string into styles.
|
|
14
23
|
* @param strings - The string fragments that are interpolated with the values.
|
|
15
24
|
* @param values - The values that are interpolated with the string fragments.
|
|
25
|
+
* @remarks
|
|
26
|
+
* The css helper supports interpolation of strings and ElementStyle instances.
|
|
27
|
+
* @public
|
|
28
|
+
*/
|
|
29
|
+
export declare const css: CSSTemplateTag;
|
|
30
|
+
/**
|
|
31
|
+
* @deprecated Use css.partial instead.
|
|
16
32
|
* @public
|
|
17
33
|
*/
|
|
18
|
-
export declare
|
|
34
|
+
export declare const cssPartial: (strings: TemplateStringsArray, ...values: (ComposableStyles | CSSDirective)[]) => CSSDirective;
|
|
@@ -1,55 +1,42 @@
|
|
|
1
1
|
import type { Behavior } from "../observation/behavior.js";
|
|
2
|
-
|
|
3
|
-
* A node that can be targeted by styles.
|
|
4
|
-
* @public
|
|
5
|
-
*/
|
|
6
|
-
export interface StyleTarget {
|
|
7
|
-
/**
|
|
8
|
-
* Stylesheets to be adopted by the node.
|
|
9
|
-
*/
|
|
10
|
-
adoptedStyleSheets?: CSSStyleSheet[];
|
|
11
|
-
/**
|
|
12
|
-
* Adds styles to the target by appending the styles.
|
|
13
|
-
* @param styles - The styles element to add.
|
|
14
|
-
*/
|
|
15
|
-
append(styles: HTMLStyleElement): void;
|
|
16
|
-
/**
|
|
17
|
-
* Adds styles to the target by prepending the styles.
|
|
18
|
-
* @param styles - The styles element to add.
|
|
19
|
-
* @deprecated - use append()
|
|
20
|
-
*/
|
|
21
|
-
prepend(styles: HTMLStyleElement): void;
|
|
22
|
-
/**
|
|
23
|
-
* Removes styles from the target.
|
|
24
|
-
* @param styles - The styles element to remove.
|
|
25
|
-
*/
|
|
26
|
-
removeChild(styles: HTMLStyleElement): void;
|
|
27
|
-
/**
|
|
28
|
-
* Returns all element descendants of node that match selectors.
|
|
29
|
-
* @param selectors - The CSS selector to use for the query.
|
|
30
|
-
*/
|
|
31
|
-
querySelectorAll<E extends Element = Element>(selectors: string): NodeListOf<E>;
|
|
32
|
-
}
|
|
2
|
+
import { StyleStrategy, StyleTarget } from "../interfaces.js";
|
|
33
3
|
/**
|
|
34
4
|
* Represents styles that can be composed into the ShadowDOM of a custom element.
|
|
35
5
|
* @public
|
|
36
6
|
*/
|
|
37
7
|
export declare type ComposableStyles = string | ElementStyles | CSSStyleSheet;
|
|
38
8
|
/**
|
|
39
|
-
*
|
|
9
|
+
* A type that instantiates a StyleStrategy.
|
|
40
10
|
* @public
|
|
41
11
|
*/
|
|
42
|
-
export declare type
|
|
12
|
+
export declare type ConstructibleStyleStrategy = {
|
|
13
|
+
/**
|
|
14
|
+
* Creates an instance of the strategy.
|
|
15
|
+
* @param styles - The styles to initialize the strategy with.
|
|
16
|
+
*/
|
|
17
|
+
new (styles: (string | CSSStyleSheet)[]): StyleStrategy;
|
|
18
|
+
};
|
|
43
19
|
/**
|
|
44
20
|
* Represents styles that can be applied to a custom element.
|
|
45
21
|
* @public
|
|
46
22
|
*/
|
|
47
|
-
export declare
|
|
23
|
+
export declare class ElementStyles {
|
|
24
|
+
readonly styles: ReadonlyArray<ComposableStyles>;
|
|
48
25
|
private targets;
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
26
|
+
private _strategy;
|
|
27
|
+
/**
|
|
28
|
+
* The behaviors associated with this set of styles.
|
|
29
|
+
*/
|
|
30
|
+
readonly behaviors: ReadonlyArray<Behavior<HTMLElement>> | null;
|
|
31
|
+
/**
|
|
32
|
+
* Gets the StyleStrategy associated with these element styles.
|
|
33
|
+
*/
|
|
34
|
+
get strategy(): StyleStrategy;
|
|
35
|
+
/**
|
|
36
|
+
* Creates an instance of ElementStyles.
|
|
37
|
+
* @param styles - The styles that will be associated with elements.
|
|
38
|
+
*/
|
|
39
|
+
constructor(styles: ReadonlyArray<ComposableStyles>);
|
|
53
40
|
/** @internal */
|
|
54
41
|
addStylesTo(target: StyleTarget): void;
|
|
55
42
|
/** @internal */
|
|
@@ -60,11 +47,21 @@ export declare abstract class ElementStyles {
|
|
|
60
47
|
* Associates behaviors with this set of styles.
|
|
61
48
|
* @param behaviors - The behaviors to associate.
|
|
62
49
|
*/
|
|
63
|
-
withBehaviors(...behaviors: Behavior[]): this;
|
|
50
|
+
withBehaviors(...behaviors: Behavior<HTMLElement>[]): this;
|
|
51
|
+
/**
|
|
52
|
+
* Sets the strategy that handles adding/removing these styles for an element.
|
|
53
|
+
* @param strategy - The strategy to use.
|
|
54
|
+
*/
|
|
55
|
+
withStrategy(Strategy: ConstructibleStyleStrategy): this;
|
|
56
|
+
/**
|
|
57
|
+
* Sets the default strategy type to use when creating style strategies.
|
|
58
|
+
* @param Strategy - The strategy type to construct.
|
|
59
|
+
*/
|
|
60
|
+
static setDefaultStrategy(Strategy: ConstructibleStyleStrategy): void;
|
|
64
61
|
/**
|
|
65
|
-
*
|
|
62
|
+
* Indicates whether the DOM supports the adoptedStyleSheets feature.
|
|
66
63
|
*/
|
|
67
|
-
static readonly
|
|
64
|
+
static readonly supportsAdoptedStyleSheets: boolean;
|
|
68
65
|
}
|
|
69
66
|
/**
|
|
70
67
|
* https://wicg.github.io/construct-stylesheets/
|
|
@@ -72,27 +69,10 @@ export declare abstract class ElementStyles {
|
|
|
72
69
|
*
|
|
73
70
|
* @internal
|
|
74
71
|
*/
|
|
75
|
-
export declare class
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
private get styleSheets();
|
|
80
|
-
readonly behaviors: ReadonlyArray<Behavior> | null;
|
|
81
|
-
constructor(styles: ComposableStyles[], styleSheetCache: Map<string, CSSStyleSheet>);
|
|
82
|
-
addStylesTo(target: StyleTarget): void;
|
|
83
|
-
removeStylesFrom(target: StyleTarget): void;
|
|
84
|
-
}
|
|
85
|
-
/**
|
|
86
|
-
* @internal
|
|
87
|
-
*/
|
|
88
|
-
export declare class StyleElementStyles extends ElementStyles {
|
|
89
|
-
styles: ComposableStyles[];
|
|
90
|
-
private readonly styleSheets;
|
|
91
|
-
private readonly styleClass;
|
|
92
|
-
readonly behaviors: ReadonlyArray<Behavior> | null;
|
|
93
|
-
constructor(styles: ComposableStyles[]);
|
|
72
|
+
export declare class AdoptedStyleSheetsStrategy implements StyleStrategy {
|
|
73
|
+
/** @internal */
|
|
74
|
+
readonly sheets: CSSStyleSheet[];
|
|
75
|
+
constructor(styles: (string | CSSStyleSheet)[]);
|
|
94
76
|
addStylesTo(target: StyleTarget): void;
|
|
95
77
|
removeStylesFrom(target: StyleTarget): void;
|
|
96
|
-
isAttachedTo(target: StyleTarget): boolean;
|
|
97
|
-
private normalizeTarget;
|
|
98
78
|
}
|