@ixfx/ui 0.36.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/__tests__/test.d.ts +2 -0
- package/dist/__tests__/test.d.ts.map +1 -0
- package/dist/__tests__/test.js +1 -0
- package/dist/src/index.d.ts +2 -0
- package/dist/src/index.d.ts.map +1 -0
- package/dist/src/index.js +1 -0
- package/dist/src/rx/browser-resize.d.ts +21 -0
- package/dist/src/rx/browser-resize.d.ts.map +1 -0
- package/dist/src/rx/browser-resize.js +40 -0
- package/dist/src/rx/browser-theme-change.d.ts +13 -0
- package/dist/src/rx/browser-theme-change.d.ts.map +1 -0
- package/dist/src/rx/browser-theme-change.js +28 -0
- package/dist/src/rx/colour.d.ts +8 -0
- package/dist/src/rx/colour.d.ts.map +1 -0
- package/dist/src/rx/colour.js +20 -0
- package/dist/src/rx/dom-source.d.ts +96 -0
- package/dist/src/rx/dom-source.d.ts.map +1 -0
- package/dist/src/rx/dom-source.js +373 -0
- package/dist/src/rx/dom-types.d.ts +128 -0
- package/dist/src/rx/dom-types.d.ts.map +1 -0
- package/dist/src/rx/dom-types.js +1 -0
- package/dist/src/rx/dom.d.ts +284 -0
- package/dist/src/rx/dom.d.ts.map +1 -0
- package/dist/src/rx/dom.js +727 -0
- package/dist/src/rx/index.d.ts +7 -0
- package/dist/src/rx/index.d.ts.map +1 -0
- package/dist/src/rx/index.js +5 -0
- package/dist/tsconfig.tsbuildinfo +1 -0
- package/package.json +32 -0
@@ -0,0 +1,128 @@
|
|
1
|
+
import type { Reactive } from "@ixfx/rx";
|
2
|
+
import type { EventSourceOptions } from "@ixfx/rx/from";
|
3
|
+
export type DomBindValueTarget = {
|
4
|
+
/**
|
5
|
+
* If _true_ `innerHTML` is set (a shortcut for elField:`innerHTML`)
|
6
|
+
*/
|
7
|
+
htmlContent?: boolean;
|
8
|
+
/**
|
9
|
+
* If _true_, 'textContent' is set (a shortcut for elField:'textContext')
|
10
|
+
*/
|
11
|
+
textContent?: boolean;
|
12
|
+
/**
|
13
|
+
* If set, this DOM element field is set. Eg 'textContent'
|
14
|
+
*/
|
15
|
+
elField?: string;
|
16
|
+
/**
|
17
|
+
* If set, this DOM attribute is set, Eg 'width'
|
18
|
+
*/
|
19
|
+
attribName?: string;
|
20
|
+
/**
|
21
|
+
* If set, this CSS variable is set, Eg 'hue' (sets '--hue')
|
22
|
+
*/
|
23
|
+
cssVariable?: string;
|
24
|
+
/**
|
25
|
+
* If set, this CSS property is set, Eg 'background-color'
|
26
|
+
*/
|
27
|
+
cssProperty?: string;
|
28
|
+
};
|
29
|
+
export type ElementBind = {
|
30
|
+
/**
|
31
|
+
* Tag name for this binding.
|
32
|
+
* Overrides `defaultTag`
|
33
|
+
*/
|
34
|
+
tagName?: string;
|
35
|
+
/**
|
36
|
+
* If _true_, sub-paths are appended to element, rather than `container`
|
37
|
+
*/
|
38
|
+
nestChildren?: boolean;
|
39
|
+
transform?: (value: any) => string;
|
40
|
+
};
|
41
|
+
export type ElementsOptions = {
|
42
|
+
container: HTMLElement | string;
|
43
|
+
defaultTag: string;
|
44
|
+
binds: Record<string, DomBindValueTarget & ElementBind>;
|
45
|
+
};
|
46
|
+
export type DomBindTargetNode = {
|
47
|
+
query?: string;
|
48
|
+
element?: HTMLElement;
|
49
|
+
};
|
50
|
+
export type DomBindTargetNodeResolved = {
|
51
|
+
element: HTMLElement;
|
52
|
+
};
|
53
|
+
export type DomBindUnresolvedSource<TSource, TDestination> = DomBindTargetNode & DomBindSourceValue<TSource, TDestination> & DomBindValueTarget;
|
54
|
+
export type DomBindResolvedSource<TSource, TDestination> = DomBindTargetNodeResolved & DomBindSourceValue<TSource, TDestination> & DomBindValueTarget;
|
55
|
+
export type DomBindSourceValue<TSource, TDestination> = {
|
56
|
+
twoway?: boolean;
|
57
|
+
/**
|
58
|
+
* Field from source value to pluck and use.
|
59
|
+
* This will also be the value passed to the transform
|
60
|
+
*/
|
61
|
+
sourceField?: keyof TSource;
|
62
|
+
transform?: (input: TSource) => TDestination;
|
63
|
+
transformValue?: (input: any) => TDestination;
|
64
|
+
};
|
65
|
+
export type DomBindInputOptions<TSource, TDestination> = DomBindSourceValue<TSource, TDestination> & {
|
66
|
+
transformFromInput: (input: TDestination) => TSource;
|
67
|
+
};
|
68
|
+
export type BindUpdateOpts<V> = {
|
69
|
+
initial: (v: V, el: HTMLElement) => void;
|
70
|
+
binds: Record<string, DomBindValueTarget & {
|
71
|
+
transform?: (value: any) => string;
|
72
|
+
}>;
|
73
|
+
};
|
74
|
+
export type DomCreateOptions = {
|
75
|
+
tagName: string;
|
76
|
+
parentEl: string | HTMLElement;
|
77
|
+
};
|
78
|
+
export type PipeDomBinding = {
|
79
|
+
/**
|
80
|
+
* Remove binding and optionally delete element(s) (false by default)
|
81
|
+
*/
|
82
|
+
remove(deleteElements: boolean): void;
|
83
|
+
};
|
84
|
+
export type DomValueOptions = EventSourceOptions & {
|
85
|
+
/**
|
86
|
+
* If true, the current value will be emitted even though it wasn't
|
87
|
+
* triggered by an event.
|
88
|
+
* Default: false
|
89
|
+
*/
|
90
|
+
emitInitialValue: boolean;
|
91
|
+
attributeName: string;
|
92
|
+
fieldName: string;
|
93
|
+
/**
|
94
|
+
* Respond to when value has changed or when value is changing
|
95
|
+
* Default: `changed`
|
96
|
+
*/
|
97
|
+
when: `changed` | `changing`;
|
98
|
+
fallbackValue: string;
|
99
|
+
upstreamSource?: Reactive<unknown>;
|
100
|
+
upstreamFilter?: (value: unknown) => string;
|
101
|
+
};
|
102
|
+
export type DomFormOptions<T extends Record<string, unknown>> = EventSourceOptions & {
|
103
|
+
/**
|
104
|
+
* If true, the current value will be emitted even though it wasn't
|
105
|
+
* triggered by an event.
|
106
|
+
* Default: false
|
107
|
+
*/
|
108
|
+
emitInitialValue: boolean;
|
109
|
+
/**
|
110
|
+
* Respond to when value has changed or when value is changing
|
111
|
+
* Default: `changed`
|
112
|
+
*/
|
113
|
+
when: `changed` | `changing`;
|
114
|
+
upstreamSource?: Reactive<T>;
|
115
|
+
upstreamFilter?: (name: string, value: unknown) => string;
|
116
|
+
};
|
117
|
+
export type DomNumberInputValueOptions = DomValueOptions & {
|
118
|
+
/**
|
119
|
+
* If true, sets up INPUT element to operate with relative values
|
120
|
+
*/
|
121
|
+
relative?: boolean;
|
122
|
+
/**
|
123
|
+
* If true, when setting up, sets max to be on left side
|
124
|
+
*/
|
125
|
+
inverted?: boolean;
|
126
|
+
upstreamSource?: Reactive<number>;
|
127
|
+
};
|
128
|
+
//# sourceMappingURL=dom-types.d.ts.map
|
@@ -0,0 +1 @@
|
|
1
|
+
{"version":3,"file":"dom-types.d.ts","sourceRoot":"","sources":["../../../src/rx/dom-types.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,UAAU,CAAA;AACxC,OAAO,KAAK,EAAE,kBAAkB,EAAE,MAAM,eAAe,CAAA;AAEvD,MAAM,MAAM,kBAAkB,GAAG;IAC/B;;OAEG;IACH,WAAW,CAAC,EAAE,OAAO,CAAA;IACrB;;OAEG;IACH,WAAW,CAAC,EAAE,OAAO,CAAA;IACrB;;OAEG;IACH,OAAO,CAAC,EAAE,MAAM,CAAA;IAChB;;OAEG;IACH,UAAU,CAAC,EAAE,MAAM,CAAA;IACnB;;OAEG;IACH,WAAW,CAAC,EAAE,MAAM,CAAA;IACpB;;OAEG;IACH,WAAW,CAAC,EAAE,MAAM,CAAA;CACrB,CAAA;AAED,MAAM,MAAM,WAAW,GAAG;IACxB;;;OAGG;IACH,OAAO,CAAC,EAAE,MAAM,CAAA;IAChB;;OAEG;IACH,YAAY,CAAC,EAAE,OAAO,CAAA;IACtB,SAAS,CAAC,EAAE,CAAC,KAAK,EAAE,GAAG,KAAK,MAAM,CAAA;CACnC,CAAA;AACD,MAAM,MAAM,eAAe,GAAG;IAC5B,SAAS,EAAE,WAAW,GAAG,MAAM,CAAA;IAC/B,UAAU,EAAE,MAAM,CAAC;IACnB,KAAK,EAAE,MAAM,C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
export {};
|
@@ -0,0 +1,284 @@
|
|
1
|
+
import { type PathDataChange } from "@ixfx/core/records";
|
2
|
+
import * as Rx from "@ixfx/rx";
|
3
|
+
import type { ElementsOptions, PipeDomBinding, BindUpdateOpts, DomBindSourceValue, DomBindValueTarget, DomBindUnresolvedSource } from './dom-types.js';
|
4
|
+
/**
|
5
|
+
* Reactive stream of array of elements that match `query`.
|
6
|
+
* @param query
|
7
|
+
* @returns
|
8
|
+
*/
|
9
|
+
export declare function fromDomQuery(query: string): Rx.Reactive<HTMLElement[]> & {
|
10
|
+
set(value: HTMLElement[]): void;
|
11
|
+
} & {
|
12
|
+
onField(fieldName: string, handler: (result: Rx.ObjectFieldHandler) => void): () => void;
|
13
|
+
onDiff(changes: (changes: PathDataChange<any>[]) => void): () => void;
|
14
|
+
update(changedPart: (import("@ixfx/core").RecursivePartial<HTMLElement> | undefined)[]): HTMLElement[];
|
15
|
+
updateField(field: string, value: any): void;
|
16
|
+
} & {
|
17
|
+
last(): HTMLElement[];
|
18
|
+
};
|
19
|
+
/**
|
20
|
+
* Updates an element's `textContent` when the source value changes.
|
21
|
+
* ```js
|
22
|
+
* bindText(source, `#blah`);
|
23
|
+
* ```
|
24
|
+
* @param elOrQuery
|
25
|
+
* @param source
|
26
|
+
* @param bindOpts
|
27
|
+
*/
|
28
|
+
export declare const bindText: <TSource>(source: Rx.Reactive<TSource>, elOrQuery: string | HTMLElement | null, bindOpts?: Partial<DomBindSourceValue<TSource, string>>) => PipeDomBinding;
|
29
|
+
/**
|
30
|
+
* Updates an element's `value` (as well as the 'value' attribute) when the source value changes.s
|
31
|
+
* @param source
|
32
|
+
* @param elOrQuery
|
33
|
+
* @param bindOpts
|
34
|
+
* @returns
|
35
|
+
*/
|
36
|
+
export declare const bindValueText: <TSource>(source: Rx.Reactive<TSource>, elOrQuery: string | HTMLInputElement | null, bindOpts?: Partial<DomBindSourceValue<TSource, string>>) => PipeDomBinding;
|
37
|
+
/**
|
38
|
+
* Updates an element's `innerHTML` when the source value changes
|
39
|
+
* ```js
|
40
|
+
* bindHtml(source, `#blah`);
|
41
|
+
* ```
|
42
|
+
*
|
43
|
+
* Uses {@link bindElement}, with `{elField:'innerHTML'}` as the options.
|
44
|
+
* @param elOrQuery
|
45
|
+
* @param source
|
46
|
+
* @param bindOpts
|
47
|
+
* @returns
|
48
|
+
*/
|
49
|
+
export declare const bindHtml: <TSource>(source: Rx.Reactive<TSource>, elOrQuery: string | HTMLElement | null, bindOpts?: DomBindSourceValue<TSource, string>) => PipeDomBinding;
|
50
|
+
/**
|
51
|
+
* Shortcut to bind to an elements attribute
|
52
|
+
* @param elOrQuery
|
53
|
+
* @param source
|
54
|
+
* @param attribute
|
55
|
+
* @param bindOpts
|
56
|
+
* @returns
|
57
|
+
*/
|
58
|
+
/**
|
59
|
+
* Shortcut to bind to a CSS variable
|
60
|
+
* @param elOrQuery
|
61
|
+
* @param source
|
62
|
+
* @param cssVariable
|
63
|
+
* @param bindOpts
|
64
|
+
* @returns
|
65
|
+
*/
|
66
|
+
/**
|
67
|
+
* Creates a new HTML element, calling {@link bind} on it to update when `source` emits new values.
|
68
|
+
*
|
69
|
+
*
|
70
|
+
* ```js
|
71
|
+
* // Set textContent of a SPAN with values from `source`
|
72
|
+
* create(source, { tagName: `span`, parentEl: document.body })
|
73
|
+
* ```
|
74
|
+
*
|
75
|
+
* If `parentEl` is not given in the options, the created element needs to be manually added
|
76
|
+
* ```js
|
77
|
+
* const b = create(source);
|
78
|
+
* someEl.append(b.el); // Append manually
|
79
|
+
* ```
|
80
|
+
*
|
81
|
+
* ```
|
82
|
+
* // Set 'title' attribute based on values from `source`
|
83
|
+
* create(source, { parentEl: document.body, attribName: `title` })
|
84
|
+
* ```
|
85
|
+
* @param source
|
86
|
+
* @param options
|
87
|
+
* @returns
|
88
|
+
*/
|
89
|
+
/**
|
90
|
+
* Update a DOM element's field, attribute or CSS variable when `source` produces a value.
|
91
|
+
*
|
92
|
+
* ```js
|
93
|
+
* // Access via DOM query. Binds to 'textContent' by default
|
94
|
+
* bind(readableSource, `#someEl`);
|
95
|
+
*
|
96
|
+
* // Set innerHTML instead
|
97
|
+
* bind(readableSource, someEl, { elField: `innerHTML` });
|
98
|
+
*
|
99
|
+
* // An attribute
|
100
|
+
* bind(readableSource, someEl, { attribName: `width` });
|
101
|
+
*
|
102
|
+
* // A css variable ('--' optiona)
|
103
|
+
* bind(readableSource, someEl, { cssVariable: `hue` });
|
104
|
+
*
|
105
|
+
* // Pluck a particular field from source data.
|
106
|
+
* // Ie someEl.textContent = value.colour
|
107
|
+
* bind(readableSource, someEl, { sourceField: `colour` });
|
108
|
+
*
|
109
|
+
* // Transform value before setting it to field
|
110
|
+
* bind(readableSource, someEl, {
|
111
|
+
* field: `innerHTML`,
|
112
|
+
* transform: (v) => `Colour: ${v.colour}`
|
113
|
+
* })
|
114
|
+
* ```
|
115
|
+
*
|
116
|
+
* If `source` has an initial value, this is used when first bound.
|
117
|
+
*
|
118
|
+
* Returns {@link PipeDomBinding} to control binding:
|
119
|
+
* ```js
|
120
|
+
* const bind = bind(source, `#someEl`);
|
121
|
+
* bind.remove(); // Unbind
|
122
|
+
* bind.remove(true); // Unbind and remove HTML element
|
123
|
+
* ```
|
124
|
+
*
|
125
|
+
* If several fields need to be updated based on a new value, consider using {@link bindUpdate} instead.
|
126
|
+
* @param elOrQuery Element to update to, or query string such as '#someid'
|
127
|
+
* @param source Source of data
|
128
|
+
* @param binds Bindings
|
129
|
+
*/
|
130
|
+
export declare const bindElement: <TSource, TDestination>(source: Rx.Reactive<TSource>, elOrQuery: string | HTMLElement | null, ...binds: (DomBindSourceValue<TSource, TDestination> & DomBindValueTarget)[]) => PipeDomBinding;
|
131
|
+
/**
|
132
|
+
* Binds `source` to one or more element(s). One or more bindings for the same source
|
133
|
+
* can be provided.
|
134
|
+
*
|
135
|
+
* ```js
|
136
|
+
* bind(source,
|
137
|
+
* // Binds .name field of source values to textContent of #some-element
|
138
|
+
* { query: `#some-element`, sourceField: `name` },
|
139
|
+
* { query: `section`, }
|
140
|
+
* );
|
141
|
+
* ```
|
142
|
+
*
|
143
|
+
* Can update
|
144
|
+
* * CSS variables
|
145
|
+
* * CSS styles
|
146
|
+
* * textContent / innerHTML
|
147
|
+
* * HTML DOM attributes and object fields
|
148
|
+
*
|
149
|
+
* Can use a particular field on source values, or use the whole value. These can
|
150
|
+
* pass through `transformValue` or `transform` respectively.
|
151
|
+
*
|
152
|
+
* Returns a function to unbind from source and optionally remove HTML element
|
153
|
+
* ```js
|
154
|
+
* const unbind = bind( . . . );
|
155
|
+
* unbind(); // Unbind
|
156
|
+
* unbind(true); // Unbind and remove HTML element(s)
|
157
|
+
* ```
|
158
|
+
* @param source
|
159
|
+
* @param bindsUnresolvedElements
|
160
|
+
* @returns
|
161
|
+
*/
|
162
|
+
export declare const bind: <TSource, TDestination>(source: Rx.Reactive<TSource>, ...bindsUnresolvedElements: DomBindUnresolvedSource<TSource, TDestination>[]) => PipeDomBinding;
|
163
|
+
/**
|
164
|
+
* Calls `updater` whenever `source` produces a value. Useful when several fields from a value
|
165
|
+
* are needed to update an element.
|
166
|
+
* ```js
|
167
|
+
* bindUpdate(source, `#someEl`, (v, el) => {
|
168
|
+
* el.setAttribute(`width`, v.width);
|
169
|
+
* el.setAttribute(`height`, v.height);
|
170
|
+
* });
|
171
|
+
* ```
|
172
|
+
*
|
173
|
+
* Returns a {@link PipeDomBinding} to manage binding
|
174
|
+
* ```js
|
175
|
+
* const b = bindUpdate(...);
|
176
|
+
* b.remove(); // Disconnect binding
|
177
|
+
* b.remove(true); // Disconnect binding and remove element
|
178
|
+
* b.el; // HTML element
|
179
|
+
* ```
|
180
|
+
* @param elOrQuery
|
181
|
+
* @param source
|
182
|
+
* @param updater
|
183
|
+
* @returns
|
184
|
+
*/
|
185
|
+
export declare const bindUpdate: <V>(source: Rx.Reactive<V>, elOrQuery: string | HTMLElement, updater: (v: V, el: HTMLElement) => void) => PipeDomBinding;
|
186
|
+
/**
|
187
|
+
* Updates a HTML element based on diffs on an object.
|
188
|
+
* ```js
|
189
|
+
* // Wrap an object
|
190
|
+
* const o = Rx.object({ name: `Jane`, ticks: 0 });
|
191
|
+
* const b = bindDiffUpdate(`#test`, o, (diffs, el) => {
|
192
|
+
* // el = reference to #test
|
193
|
+
* // diff = Array of Changes,
|
194
|
+
* // eg [ { path: `ticks`, value: 797, previous: 0 } ]
|
195
|
+
* for (const diff of diffs) {
|
196
|
+
* if (diff.path === `ticks`) el.textContent = `${diff.previous} -> ${diff.value}`
|
197
|
+
* }
|
198
|
+
* })
|
199
|
+
*
|
200
|
+
* // Eg. update field
|
201
|
+
* o.updateField(`ticks`, Math.floor(Math.random()*1000));
|
202
|
+
* ```
|
203
|
+
*
|
204
|
+
* If `initial` is provided as an option, this will be called if `source` has an initial value. Without this, the DOM won't be updated until the first data
|
205
|
+
* update happens.
|
206
|
+
* ```js
|
207
|
+
* bindDiffUpdate(el, source, updater, {
|
208
|
+
* initial: (v, el) => {
|
209
|
+
* el.innerHTML = v.name;
|
210
|
+
* }
|
211
|
+
* })
|
212
|
+
* ```
|
213
|
+
* @param elOrQuery
|
214
|
+
* @param source
|
215
|
+
* @param updater
|
216
|
+
* @param opts
|
217
|
+
* @returns
|
218
|
+
*/
|
219
|
+
export declare const bindDiffUpdate: <V>(source: Rx.ReactiveDiff<V>, elOrQuery: string | HTMLElement | null, updater: (diffs: PathDataChange<any>[], el: HTMLElement) => void, opts?: Partial<BindUpdateOpts<V>>) => PipeDomBinding & {
|
220
|
+
refresh: () => void;
|
221
|
+
};
|
222
|
+
/**
|
223
|
+
* Creates a new HTML element and calls `bindUpdate` so values from `source` can be used
|
224
|
+
* to update it.
|
225
|
+
*
|
226
|
+
*
|
227
|
+
* ```js
|
228
|
+
* // Creates a span, adding it to <body>
|
229
|
+
* const b = createUpdate(dataSource, (value, el) => {
|
230
|
+
* el.width = value.width;
|
231
|
+
* el.height = value.height;
|
232
|
+
* }, {
|
233
|
+
* tagName: `SPAN`,
|
234
|
+
* parentEl: document.body
|
235
|
+
* })
|
236
|
+
* ```
|
237
|
+
* @param source
|
238
|
+
* @param updater
|
239
|
+
* @param options
|
240
|
+
* @returns
|
241
|
+
*/
|
242
|
+
/**
|
243
|
+
* Creates, updates & deletes elements based on pathed values from a reactive.
|
244
|
+
*
|
245
|
+
* This means that elements are only manipulated if its associated data changes,
|
246
|
+
* and elements are not modified if there's no need to.
|
247
|
+
* @param source
|
248
|
+
* @param options
|
249
|
+
*/
|
250
|
+
export declare const elements: <T>(source: Rx.ReactiveDiff<T> | (Rx.ReactiveDiff<T> & Rx.ReactiveInitial<T>), options: Partial<ElementsOptions>) => void;
|
251
|
+
export declare function win(): {
|
252
|
+
dispose: (reason?: string) => void;
|
253
|
+
size: Rx.Reactive<{
|
254
|
+
lazy: string;
|
255
|
+
transform: () => {
|
256
|
+
width: number;
|
257
|
+
height: number;
|
258
|
+
};
|
259
|
+
}> & {
|
260
|
+
last(): {
|
261
|
+
lazy: string;
|
262
|
+
transform: () => {
|
263
|
+
width: number;
|
264
|
+
height: number;
|
265
|
+
};
|
266
|
+
};
|
267
|
+
};
|
268
|
+
pointer: Rx.Reactive<{
|
269
|
+
lazy: string;
|
270
|
+
transform: (args: Event | undefined) => {
|
271
|
+
x: number;
|
272
|
+
y: number;
|
273
|
+
};
|
274
|
+
}> & {
|
275
|
+
last(): {
|
276
|
+
lazy: string;
|
277
|
+
transform: (args: Event | undefined) => {
|
278
|
+
x: number;
|
279
|
+
y: number;
|
280
|
+
};
|
281
|
+
};
|
282
|
+
};
|
283
|
+
};
|
284
|
+
//# sourceMappingURL=dom.d.ts.map
|
@@ -0,0 +1 @@
|
|
1
|
+
{"version":3,"file":"dom.d.ts","sourceRoot":"","sources":["../../../src/rx/dom.ts"],"names":[],"mappings":"AAEA,OAAO,EAAkC,KAAK,cAAc,EAAE,MAAM,oBAAoB,CAAC;AACzF,OAAO,KAAK,EAAE,MAAM,UAAU,CAAC;AAE/B,OAAO,KAAK,EAAE,eAAe,EAAE,c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