@context-action/lit-ui 0.0.0-stage → 0.1.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.
@@ -0,0 +1,644 @@
1
+ import { LitElement, PropertyValues, ReactiveController, ReactiveControllerHost, nothing } from "lit";
2
+ import { Context, Context as Context$1, ContextConsumer, ContextProvider, createContext } from "@lit/context";
3
+ import { ActionDispatcher, ActionNames, ActionPayloadMap, ActionRegister, DispatchArgs } from "@context-action/core";
4
+ import { ControllerScope, ControllerScopeOptions, EqualityFn, ReadableStore, Selector } from "@context-action/lit";
5
+ import * as React from "react";
6
+ /**
7
+ * Standard form validity flags as defined in the HTML Living Standard.
8
+ */
9
+ interface ValidityStateFlags {
10
+ badInput?: boolean;
11
+ customError?: boolean;
12
+ patternMismatch?: boolean;
13
+ rangeOverflow?: boolean;
14
+ rangeUnderflow?: boolean;
15
+ stepMismatch?: boolean;
16
+ tooLong?: boolean;
17
+ tooShort?: boolean;
18
+ typeMismatch?: boolean;
19
+ valueMissing?: boolean;
20
+ }
21
+ /**
22
+ * Abstract Form-Associated Custom Element (FACE) base class extending LitElement.
23
+ *
24
+ * Provides:
25
+ * - Native form participation via `ElementInternals` and `static formAssociated = true`
26
+ * - Defensive fallbacks for server-side rendering (SSR) and headless test environments (JSDOM)
27
+ * - Complete Form value management (`setFormValue`, `getFormValue`, `formValue`)
28
+ * - Constraint validation APIs (`setValidity`, `validity`, `validationMessage`, `checkValidity`, `reportValidity`, `setCustomValidity`)
29
+ * - Lifecycle callbacks (`formResetCallback`, `formDisabledCallback`, `formStateRestoreCallback`, `formAssociatedCallback`)
30
+ * - Standard overridable hooks (`onFormReset`, `onFormDisabled`, `onFormStateRestore`, `onFormAssociated`)
31
+ * - Automatic form reset event synchronization and leak-free unbinding on disconnect
32
+ */
33
+ export declare class FormAssociatedLitElement extends LitElement {
34
+ #private;
35
+ /**
36
+ * Identifies this custom element as form-associated according to the HTML specification.
37
+ * Enables the browser engine to attach ElementInternals and include this element in form submission.
38
+ */
39
+ static readonly formAssociated = true;
40
+ /**
41
+ * The ElementInternals controller instance for this custom element.
42
+ * Undefined in environments where attachInternals is unsupported.
43
+ */
44
+ readonly internals?: ElementInternals;
45
+ name: string;
46
+ type: string;
47
+ disabled: boolean;
48
+ required: boolean;
49
+ constructor();
50
+ /**
51
+ * The associated HTMLFormElement, if any.
52
+ * Resolves first via ElementInternals.form, then checks the 'form' attribute by ID,
53
+ * and finally falls back to the closest ancestor <form>.
54
+ */
55
+ get form(): HTMLFormElement | null;
56
+ /**
57
+ * Sets the element's form submission value and optional state restoration value.
58
+ *
59
+ * @param value The value to submit with the form: string, File, FormData, or null (clears submission).
60
+ * @param state Optional state object used for session restoration / autocomplete.
61
+ */
62
+ setFormValue(value: File | string | FormData | null, state?: File | string | FormData | null): void;
63
+ /**
64
+ * Returns the current form submission value.
65
+ */
66
+ getFormValue(): File | string | FormData | null;
67
+ /**
68
+ * Getter alias for getFormValue() for uniform property access.
69
+ */
70
+ get formValue(): File | string | FormData | null;
71
+ /**
72
+ * Returns the current state restoration object.
73
+ */
74
+ get formState(): unknown;
75
+ /**
76
+ * Sets the validity flags, validation error message, and optional anchor element.
77
+ *
78
+ * @param flags A map of ValidityStateFlags indicating constraint violations.
79
+ * @param message A human-readable validation error message (required if any flag is true).
80
+ * @param anchor An optional HTMLElement inside the element's ShadowRoot used to anchor browser tooltips.
81
+ */
82
+ setValidity(flags?: ValidityStateFlags, message?: string, anchor?: HTMLElement): void;
83
+ /**
84
+ * Returns the current ValidityState object representing constraint validation status.
85
+ */
86
+ get validity(): ValidityState;
87
+ /**
88
+ * Returns the current validation error message, or an empty string if valid.
89
+ */
90
+ get validationMessage(): string;
91
+ /**
92
+ * Returns true if the element participates in constraint validation and is not disabled.
93
+ */
94
+ get willValidate(): boolean;
95
+ /**
96
+ * Checks whether the element satisfies all validation constraints.
97
+ * If invalid, fires a cancelable 'invalid' event on the element and returns false.
98
+ * If valid (or validation is disabled), returns true.
99
+ */
100
+ checkValidity(): boolean;
101
+ /**
102
+ * Checks validity, reports errors to the user (e.g. browser popup), and returns validity status.
103
+ */
104
+ reportValidity(): boolean;
105
+ /**
106
+ * Sets a custom validation error message. If message is non-empty, sets customError to true.
107
+ * If message is empty, clears custom validity errors.
108
+ */
109
+ setCustomValidity(message: string): void;
110
+ /**
111
+ * Native FACE callback invoked by the browser engine when the associated form is reset.
112
+ * Dispatches to the overridable onFormReset() hook.
113
+ */
114
+ formResetCallback(): void;
115
+ /**
116
+ * Overridable lifecycle hook called when the associated form is reset.
117
+ * Subclasses should restore default values, re-evaluate validation, and request updates.
118
+ */
119
+ protected onFormReset(): void;
120
+ /**
121
+ * Native FACE callback invoked when the element or parent fieldset is disabled/enabled.
122
+ */
123
+ formDisabledCallback(disabled: boolean): void;
124
+ /**
125
+ * Overridable lifecycle hook called when the disabled state changes.
126
+ */
127
+ protected onFormDisabled(_disabled: boolean): void;
128
+ /**
129
+ * Native FACE callback invoked when the browser restores form state (history navigation / autofill).
130
+ */
131
+ formStateRestoreCallback(state: unknown, mode: 'restore' | 'autocomplete'): void;
132
+ /**
133
+ * Overridable lifecycle hook called when the browser restores form state.
134
+ */
135
+ protected onFormStateRestore(_state: unknown, _mode: 'restore' | 'autocomplete'): void;
136
+ /**
137
+ * Native FACE callback invoked when the element is associated or disassociated with a form.
138
+ */
139
+ formAssociatedCallback(form: HTMLFormElement | null): void;
140
+ /**
141
+ * Overridable lifecycle hook called when the element's form association changes.
142
+ */
143
+ protected onFormAssociated(_form: HTMLFormElement | null): void;
144
+ connectedCallback(): void;
145
+ disconnectedCallback(): void;
146
+ }
147
+ /**
148
+ * Standard W3C Context token for an ActionRegister.
149
+ * Uses Symbol.for to ensure singleton identity across independent bundle chunks and micro-frontends.
150
+ *
151
+ * @implements action-pipeline-system
152
+ * @memberof api-terms
153
+ */
154
+ export declare const actionRegisterContext: Context<symbol, ActionRegister<any>>;
155
+ /**
156
+ * Standard W3C Context token for an ActionDispatcher function.
157
+ * Uses Symbol.for to ensure singleton identity across independent bundle chunks.
158
+ *
159
+ * @implements action-pipeline-system
160
+ * @memberof api-terms
161
+ */
162
+ export declare const actionDispatcherContext: Context<symbol, ActionDispatcher<any>>;
163
+ /**
164
+ * Factory function creating a strongly-typed W3C Context token for a named Context-Action store.
165
+ *
166
+ * Distinct store names yield isolated contexts. Identical store names across different
167
+ * modules or micro-frontend bundles share the same underlying global Symbol.
168
+ *
169
+ * @template T State type managed by the store.
170
+ * @param name Unique name of the store domain (e.g. 'cart', 'auth', 'theme').
171
+ * @returns A Context token for the named ReadableStore.
172
+ *
173
+ * @example
174
+ * ```typescript
175
+ * export const cartStoreContext = createStoreContext<CartState>('cart');
176
+ * ```
177
+ *
178
+ * @implements store-integration-pattern
179
+ * @memberof api-terms
180
+ */
181
+ export declare function createStoreContext<T = unknown>(name: string): Context<symbol, ReadableStore<T>>;
182
+ /**
183
+ * Factory function creating a strongly-typed ActionRegister context token for a specific action map.
184
+ *
185
+ * @template A Action payload map.
186
+ * @param name Optional domain qualifier. Defaults to the root action register.
187
+ * @returns A typed Context token for ActionRegister<A>.
188
+ */
189
+ export declare function createActionRegisterContext<A extends ActionPayloadMap = ActionPayloadMap>(name?: string): Context<symbol, ActionRegister<A>>;
190
+ /**
191
+ * Factory function creating a strongly-typed ActionDispatcher context token for a specific action map.
192
+ *
193
+ * @template A Action payload map.
194
+ * @param name Optional domain qualifier. Defaults to the root action dispatcher.
195
+ * @returns A typed Context token for ActionDispatcher<A>.
196
+ */
197
+ export declare function createActionDispatcherContext<A extends ActionPayloadMap = ActionPayloadMap>(name?: string): Context<symbol, ActionDispatcher<A>>;
198
+ /**
199
+ * Imperatively attaches an ActionRegister ContextProvider to a host element.
200
+ *
201
+ * @template A Action payload map.
202
+ * @param host The hosting LitElement or ReactiveElement.
203
+ * @param register The ActionRegister instance to provide.
204
+ * @param context Optional custom context token (defaults to actionRegisterContext).
205
+ * @returns The initialized ContextProvider instance.
206
+ */
207
+ export declare function provideActionRegister<A extends ActionPayloadMap = ActionPayloadMap>(host: HTMLElement & ReactiveControllerHost, register: ActionRegister<A>, context?: Context<unknown, ActionRegister<A>>): ContextProvider<Context<unknown, ActionRegister<A>>>;
208
+ /**
209
+ * Imperatively attaches an ActionDispatcher ContextProvider to a host element.
210
+ *
211
+ * @template A Action payload map.
212
+ * @param host The hosting LitElement or ReactiveElement.
213
+ * @param dispatcher The ActionDispatcher function to provide.
214
+ * @param context Optional custom context token (defaults to actionDispatcherContext).
215
+ * @returns The initialized ContextProvider instance.
216
+ */
217
+ export declare function provideActionDispatcher<A extends ActionPayloadMap = ActionPayloadMap>(host: HTMLElement & ReactiveControllerHost, dispatcher: ActionDispatcher<A>, context?: Context<unknown, ActionDispatcher<A>>): ContextProvider<Context<unknown, ActionDispatcher<A>>>;
218
+ /**
219
+ * Imperatively attaches a ReadableStore ContextProvider to a host element.
220
+ *
221
+ * @template T Store state type.
222
+ * @param host The hosting LitElement or ReactiveElement.
223
+ * @param context The store Context token created via `createStoreContext`.
224
+ * @param store The ReadableStore instance to provide.
225
+ * @returns The initialized ContextProvider instance.
226
+ */
227
+ export declare function provideStore<T>(host: HTMLElement & ReactiveControllerHost, context: Context<unknown, ReadableStore<T>>, store: ReadableStore<T>): ContextProvider<Context<unknown, ReadableStore<T>>>;
228
+ /**
229
+ * Options for `ContextStoreController`.
230
+ *
231
+ * @template T Source store state type.
232
+ * @template Selected Projected output type.
233
+ */
234
+ interface ContextStoreControllerOptions<T, Selected = T> {
235
+ /** The W3C Context token created via `createStoreContext`. */
236
+ context: Context<unknown, ReadableStore<T>>;
237
+ /** Optional projection selector to derive a slice of state. */
238
+ selector?: Selector<T, Selected>;
239
+ /** Optional equality comparator to prevent redundant rerenders. Defaults to Object.is. */
240
+ equalityFn?: EqualityFn<Selected>;
241
+ }
242
+ /**
243
+ * ReactiveController that consumes a Context-Action ReadableStore from the W3C Context
244
+ * hierarchy across Shadow DOM boundaries, subscribes to state updates, and triggers host re-renders.
245
+ *
246
+ * Key guarantees:
247
+ * 1. Attaches to host via `host.addController(this)`.
248
+ * 2. Uses `@lit/context` ContextConsumer to dynamically resolve store instances across Shadow DOM boundaries.
249
+ * 3. Supports selective projections with memoization (`equalityFn`).
250
+ * 4. Ensures ZERO memory leaks: completely terminates store subscription when `hostDisconnected()` runs.
251
+ * 5. Re-evaluates store state and resubscribes on `hostConnected()`.
252
+ *
253
+ * @template T Source store state type.
254
+ * @template Selected Derived slice type.
255
+ *
256
+ * @implements store-integration-pattern
257
+ * @implements reactive-state-management
258
+ * @memberof core-concepts
259
+ */
260
+ export declare class ContextStoreController<T = unknown, Selected = T> implements ReactiveController {
261
+ #private;
262
+ constructor(host: ReactiveControllerHost & HTMLElement, options: ContextStoreControllerOptions<T, Selected>);
263
+ /** Current projected state derived from the injected store, or undefined if not yet provided. */
264
+ get value(): Selected | undefined;
265
+ /** The resolved ReadableStore instance currently bound to this controller. */
266
+ get store(): ReadableStore<T> | undefined;
267
+ /** Indicates whether the context request has been satisfied by an ancestor provider. */
268
+ get isResolved(): boolean;
269
+ hostConnected(): void;
270
+ hostDisconnected(): void;
271
+ }
272
+ /**
273
+ * Options for `ContextActionController`.
274
+ *
275
+ * @template A Action payload map.
276
+ */
277
+ interface ContextActionControllerOptions<A extends ActionPayloadMap = ActionPayloadMap> {
278
+ /** Optional custom context token (defaults to actionRegisterContext). */
279
+ context?: Context<unknown, ActionRegister<A>>;
280
+ }
281
+ /**
282
+ * ReactiveController that consumes an ActionRegister from the W3C Context hierarchy
283
+ * across Shadow DOM boundaries and exposes typed dispatch methods.
284
+ *
285
+ * @template A Action payload map.
286
+ *
287
+ * @implements action-pipeline-system
288
+ * @implements action-controller
289
+ * @memberof core-concepts
290
+ */
291
+ export declare class ContextActionController<A extends ActionPayloadMap = ActionPayloadMap> implements ReactiveController {
292
+ #private;
293
+ constructor(host: ReactiveControllerHost & HTMLElement, options?: ContextActionControllerOptions<A>);
294
+ /** The resolved ActionRegister instance, or undefined if no provider is present. */
295
+ get register(): ActionRegister<A> | undefined;
296
+ /** Whether an action dispatch is currently in progress. */
297
+ get isPending(): boolean;
298
+ /** The last error thrown during an action dispatch, if any. */
299
+ get lastError(): Error | undefined;
300
+ /**
301
+ * Dispatches an action through the context-injected ActionRegister pipeline.
302
+ *
303
+ * @template K Action name.
304
+ * @param action Name of the registered action.
305
+ * @param args Action payload arguments.
306
+ */
307
+ dispatch<K extends ActionNames<A>>(action: K, ...args: DispatchArgs<A[K]>): Promise<void>;
308
+ /**
309
+ * Dispatches an action and returns the pipeline execution result.
310
+ *
311
+ * @template K Action name.
312
+ * @template R Expected return value.
313
+ * @param action Name of the registered action.
314
+ * @param args Action payload arguments.
315
+ * @returns Pipeline result promise.
316
+ */
317
+ dispatchWithResult<K extends ActionNames<A>, R = unknown>(action: K, ...args: DispatchArgs<A[K]>): Promise<R>;
318
+ hostConnected(): void;
319
+ hostDisconnected(): void;
320
+ }
321
+ /**
322
+ * @module facade
323
+ *
324
+ * Purpose:
325
+ * Provides zero-dependency OOP Facade utilities (`PublicActionMethods`,
326
+ * `ImperativeHandleFactory`, `createElementFacade`) that project a Custom
327
+ * Element's public contract into an encapsulated handle without exposing raw
328
+ * `HTMLElement` or `ShadowRoot` internals.
329
+ *
330
+ * Invariants:
331
+ * - Pure TypeScript/ES2022 runtime with zero Lit or React dependencies,
332
+ * usable in Vanilla DOM, Lit, or React bridges alike.
333
+ * - `createElementFacade` returns a frozen object (`instanceof HTMLElement === false`),
334
+ * binds methods lazily to the live element, and caches bound function
335
+ * identities in a `WeakMap` so detached elements are never retained.
336
+ * - Rejects writes to read-only properties with a `TypeError` and throws a
337
+ * descriptive error when accessed while unmounted.
338
+ */
339
+ /**
340
+ * Maps selected action keys from an ActionPayloadMap-compatible record into
341
+ * object-oriented method signatures while hiding internal action keys.
342
+ */
343
+ type PublicActionMethods<Actions extends Record<string, any>, PublicKeys extends keyof Actions = keyof Actions, ReturnMap extends Partial<Record<PublicKeys, unknown>> = Record<never, never>> = { readonly [K in PublicKeys]: [Actions[K]] extends [void | undefined] ? () => K extends keyof ReturnMap ? Promise<ReturnMap[K]> : Promise<void> : (payload: Actions[K]) => K extends keyof ReturnMap ? Promise<ReturnMap[K]> : Promise<void>; };
344
+ /**
345
+ * Host-agnostic factory function that creates an encapsulated OOP handle
346
+ * from a lazy custom element getter, hiding raw `HTMLElement` internals.
347
+ */
348
+ type ImperativeHandleFactory<Element extends HTMLElement, Handle> = (getElement: () => Element | null) => Handle;
349
+ /**
350
+ * Creates a reusable host-agnostic handle factory that exposes only the specified
351
+ * properties and methods from a Custom Element, hiding raw `HTMLElement` APIs.
352
+ * Can be used directly with Vanilla DOM, Lit, or
353
+ * `createLitElementBridge({ createHandle })`.
354
+ *
355
+ * Methods are bound to the current element and cached per element, so repeated
356
+ * reads return the same function identity until the element or the underlying
357
+ * method changes. The cache is keyed weakly and never retains a detached element.
358
+ *
359
+ * @example
360
+ * ```ts
361
+ * const TimelineElement = createLitElementBridge<TimelineProps, TimelineElement, TimelineHandle>({
362
+ * tagName: 'st-timeline',
363
+ * properties: ['input', 'set'],
364
+ * createHandle: createElementFacade(['focusItem', 'scrollTo', 'commitSelection']),
365
+ * });
366
+ * ```
367
+ */
368
+ export declare function createElementFacade<Element extends HTMLElement, const Keys extends readonly (keyof Element)[]>(keys: Keys): ImperativeHandleFactory<Element, Pick<Element, Keys[number]>>;
369
+ /**
370
+ * Configuration options for the Lit React Bridge.
371
+ * Controls direct property assignment, custom event mapping, and facade handles.
372
+ */
373
+ interface LitBridgeConfig<Props extends Record<string, any>, Element extends HTMLElement = any, Handle = any> {
374
+ /**
375
+ * Property keys that should be assigned directly as DOM element properties
376
+ * rather than rendered as HTML attributes.
377
+ *
378
+ * This is critical for React 18 compatibility, which stringifies complex objects,
379
+ * arrays, functions, and class instances (such as Context-Action stores) to `"[object Object]"`.
380
+ *
381
+ * On a later render, a key previously assigned by the bridge and then omitted
382
+ * from props is reset to `undefined` so stale objects never remain on the
383
+ * element. Untouched element defaults are preserved, and read-only properties
384
+ * are left to the element adapter's interpretation.
385
+ */
386
+ properties?: readonly (keyof Props)[];
387
+ /**
388
+ * Map of React prop handler names to native DOM CustomEvent names.
389
+ *
390
+ * Listeners are reconciled by handler identity: a re-render with the same
391
+ * handler performs no DOM work, while a changed handler (or `undefined`)
392
+ * removes and re-attaches only that event.
393
+ *
394
+ * @example
395
+ * ```ts
396
+ * events: {
397
+ * onQuantityChange: 'quantity-change',
398
+ * onCartBadgeClick: 'cart-badge-click',
399
+ * }
400
+ * ```
401
+ */
402
+ events?: Record<string, string>;
403
+ /**
404
+ * Optional factory for `useImperativeHandle` that encapsulates the underlying
405
+ * `Element` and exposes only an object-oriented Facade handle to parent refs.
406
+ * When omitted, the raw `Element` instance is forwarded for backward compatibility.
407
+ *
408
+ * Use `createElementFacade(['focusItem', 'scrollTo'])` for a zero-dependency
409
+ * allow-list facade.
410
+ */
411
+ createHandle?: ImperativeHandleFactory<Element, Handle>;
412
+ }
413
+ /**
414
+ * Options object signature for createLitElementBridge, including the custom element tagName.
415
+ */
416
+ interface LitBridgeOptions<Props extends Record<string, any>, Element extends HTMLElement = HTMLElement, Handle = Element> extends LitBridgeConfig<Props, Element, Handle> {
417
+ /**
418
+ * The registered custom element HTML tag name, e.g. 'lit-quantity-stepper'.
419
+ */
420
+ tagName: string;
421
+ }
422
+ /**
423
+ * Strongly typed React ForwardRefExoticComponent representing the bridged Custom Element.
424
+ */
425
+ type LitElementComponent<Props extends Record<string, any>, Element extends HTMLElement = HTMLElement, Handle = Element> = React.ForwardRefExoticComponent<React.PropsWithoutRef<Props & Omit<React.HTMLAttributes<Element>, keyof Props>> & React.RefAttributes<Handle>>;
426
+ /**
427
+ * Overload 1: Two-argument form `(tagName, config?)`.
428
+ *
429
+ * @example
430
+ * ```tsx
431
+ * const ReactStepper = createLitElementBridge<StepperProps, LitQuantityStepper>(
432
+ * 'lit-quantity-stepper',
433
+ * {
434
+ * properties: ['metadata', 'cartStore'],
435
+ * events: { onQuantityChange: 'quantity-change' },
436
+ * }
437
+ * );
438
+ * ```
439
+ */
440
+ export declare function createLitElementBridge<Props extends Record<string, any> = Record<string, any>, Element extends HTMLElement = HTMLElement, Handle = Element>(tagName: string, config?: LitBridgeConfig<Props, Element, Handle>): LitElementComponent<Props, Element, Handle>;
441
+ /**
442
+ * Overload 2: Single-argument options form `(options)`.
443
+ *
444
+ * @example
445
+ * ```tsx
446
+ * const ReactTimeline = createLitElementBridge<TimelineProps, TimelineElement, TimelineHandle>({
447
+ * tagName: 'st-timeline',
448
+ * properties: ['input', 'set'],
449
+ * events: { onSelectionChange: 'selection-change' },
450
+ * createHandle: createElementFacade(['focusItem', 'scrollTo', 'commitSelection']),
451
+ * });
452
+ * ```
453
+ */
454
+ export declare function createLitElementBridge<Props extends Record<string, any> = Record<string, any>, Element extends HTMLElement = HTMLElement, Handle = Element>(options: LitBridgeOptions<Props, Element, Handle>): LitElementComponent<Props, Element, Handle>;
455
+ /**
456
+ * Event detail payload dispatched by <lit-quantity-stepper> on change and input events.
457
+ */
458
+ interface QuantityChangeEventDetail {
459
+ value: number;
460
+ }
461
+ /**
462
+ * Reference Form-Associated Custom Element providing a numerical stepper control.
463
+ *
464
+ * Features:
465
+ * - Native <form> submission and `new FormData()` integration via `ElementInternals`.
466
+ * - HTML5 constraint validation (`rangeUnderflow`, `rangeOverflow`, `stepMismatch`, `badInput`).
467
+ * - Form reset lifecycle restoration via `onFormReset()`.
468
+ * - Disabled and readonly state propagation.
469
+ * - Increment / Decrement methods with step precision and boundary clamping.
470
+ * - Standard CustomEvent dispatching (`change`, `input`, `quantity-change`) with `{ bubbles: true, composed: true }`.
471
+ * - Fully encapsulated Shadow DOM styling with `::part(button)` and `::part(input)` styling hooks.
472
+ */
473
+ export declare class LitQuantityStepper extends FormAssociatedLitElement {
474
+ #private;
475
+ static styles: import("lit").CSSResult;
476
+ /**
477
+ * The current numerical value of the stepper.
478
+ */
479
+ value: number;
480
+ /**
481
+ * Minimum permissible value (inclusive).
482
+ */
483
+ min: number;
484
+ /**
485
+ * Maximum permissible value (inclusive).
486
+ */
487
+ max: number;
488
+ /**
489
+ * Step increment/decrement delta. Must be greater than 0.
490
+ */
491
+ step: number;
492
+ /**
493
+ * Whether the control prevents user modification while remaining form-submittable.
494
+ */
495
+ readonly: boolean;
496
+ /**
497
+ * Default value used to restore state when the enclosing form is reset.
498
+ */
499
+ defaultValue?: number;
500
+ private focused;
501
+ private inputEl?;
502
+ connectedCallback(): void;
503
+ updated(changedProperties: PropertyValues<this>): void;
504
+ /**
505
+ * Increments the current value by the configured step.
506
+ * If at or above max, or if disabled/readonly, this operation is a no-op.
507
+ */
508
+ increment(): void;
509
+ /**
510
+ * Decrements the current value by the configured step.
511
+ * If at or below min, or if disabled/readonly, this operation is a no-op.
512
+ */
513
+ decrement(): void;
514
+ /**
515
+ * Sets the value imperatively with optional event dispatching.
516
+ *
517
+ * @param val New numerical value.
518
+ * @param options.dispatchEvents If true, emits `input` and `change` events.
519
+ */
520
+ setValue(val: number, options?: {
521
+ dispatchEvents?: boolean;
522
+ }): void;
523
+ /**
524
+ * Invoked by FormAssociatedLitElement when the parent form executes a reset.
525
+ * Restores initial value, clears validation, and synchronizes form value.
526
+ */
527
+ protected onFormReset(): void;
528
+ render(): import("lit").TemplateResult<1>;
529
+ }
530
+ declare global {
531
+ interface HTMLElementTagNameMap {
532
+ 'lit-quantity-stepper': LitQuantityStepper;
533
+ }
534
+ }
535
+ /**
536
+ * Standard W3C Context token for the shopping cart domain store.
537
+ * Uses Symbol.for to guarantee singleton identity across independent bundle chunks.
538
+ */
539
+ export declare const cartStoreContext: Context$1<symbol, ReadableStore<any>>;
540
+ /**
541
+ * Custom event detail emitted when the cart badge button is clicked.
542
+ */
543
+ interface CartBadgeClickEventDetail {
544
+ count: number;
545
+ isPending: boolean;
546
+ }
547
+ /**
548
+ * Default projection selector that extracts total quantity from diverse cart store state structures:
549
+ * - Primitive numbers (e.g. `5`)
550
+ * - State objects with `totalCount`, `count`, or `total` numerical fields
551
+ * - State objects with `items` arrays containing quantity numbers or objects (`{ quantity: n }`)
552
+ */
553
+ export declare function defaultCartCountSelector(state: unknown): number;
554
+ /**
555
+ * Reference Custom Element for displaying a dynamic shopping cart badge.
556
+ *
557
+ * Supports two consumption paradigms:
558
+ * 1. Direct property assignment: `.store=${cartStore}` and `.register=${actionRegister}`.
559
+ * 2. W3C Context Protocol: automatically injects `cartStoreContext` and `actionRegisterContext`
560
+ * from ancestor providers across Shadow DOM boundaries.
561
+ */
562
+ export declare class LitCartBadge extends LitElement {
563
+ #private;
564
+ static styles: import("lit").CSSResult;
565
+ /**
566
+ * Explicit ReadableStore instance passed directly to this component.
567
+ * If provided, overrides context-based store resolution.
568
+ */
569
+ store?: ReadableStore<any>;
570
+ /**
571
+ * Explicit ActionRegister instance passed directly to this component.
572
+ * If provided, overrides context-based action register resolution.
573
+ */
574
+ register?: ActionRegister<any>;
575
+ /**
576
+ * Custom projection selector for deriving the total quantity from store state.
577
+ */
578
+ selector?: Selector<any, number>;
579
+ /**
580
+ * Custom equality comparator function used for selective projection memoization.
581
+ */
582
+ equalityFn?: EqualityFn<number>;
583
+ /**
584
+ * Optional custom W3C Context token for resolving a cart store from ancestor providers.
585
+ */
586
+ storeContext?: Context$1<unknown, ReadableStore<any>>;
587
+ /**
588
+ * Optional custom W3C Context token for resolving an ActionRegister from ancestor providers.
589
+ */
590
+ actionContext?: Context$1<unknown, ActionRegister<any>>;
591
+ /**
592
+ * Static numerical count override. If defined, overrides both store and context values.
593
+ */
594
+ value: number | undefined;
595
+ /**
596
+ * Maximum count displayed before truncating with a '+' suffix (e.g. 99 -> '99+').
597
+ */
598
+ maxCount: number;
599
+ /**
600
+ * When true, hides the badge completely when count is 0.
601
+ */
602
+ hideZero: boolean;
603
+ /**
604
+ * Label text rendered next to the count. Defaults to 'Cart'.
605
+ */
606
+ label: string;
607
+ /**
608
+ * Optional action name dispatched on click through the configured ActionRegister.
609
+ */
610
+ actionName?: string;
611
+ /**
612
+ * Optional payload passed when dispatching actionName.
613
+ */
614
+ actionPayload?: unknown;
615
+ /**
616
+ * Whether the badge button is disabled.
617
+ */
618
+ disabled: boolean;
619
+ /**
620
+ * Visual variant: 'primary' | 'secondary' | 'accent' | 'danger'
621
+ */
622
+ variant: 'primary' | 'secondary' | 'accent' | 'danger';
623
+ private isPulsing;
624
+ constructor();
625
+ willUpdate(changedProperties: PropertyValues<this>): void;
626
+ /**
627
+ * Derives the current total count from direct override, direct store, or context store.
628
+ */
629
+ get count(): number;
630
+ set count(val: number | undefined);
631
+ /**
632
+ * Indicates whether an action dispatch is currently in flight.
633
+ */
634
+ get isPending(): boolean;
635
+ updated(changedProperties: PropertyValues<this>): void;
636
+ render(): typeof nothing | import("lit").TemplateResult<1>;
637
+ }
638
+ declare global {
639
+ interface HTMLElementTagNameMap {
640
+ 'lit-cart-badge': LitCartBadge;
641
+ }
642
+ }
643
+ export { type CartBadgeClickEventDetail, type Context, type ContextActionControllerOptions, ContextConsumer, ContextProvider, type ContextStoreControllerOptions, ControllerScope, type ControllerScopeOptions, type ImperativeHandleFactory, type LitBridgeConfig, type LitBridgeOptions, type LitElementComponent, type PublicActionMethods, type QuantityChangeEventDetail, type ValidityStateFlags, createContext, createLitElementBridge as createCustomElementBridge, createLitElementBridge as createLitBridge };
644
+ //# sourceMappingURL=index.d.cts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.cts","names":["_0","Context"],"sources":["../src/form-associated-element.ts","../src/context.ts","../src/facade.ts","../src/react-bridge.ts","../src/components/quantity-stepper.ts","../src/components/cart-badge.ts"],"mappings":";;;;;;;;UAgBiB;EACf;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;;;;;;;;;;;;;;qBA2DW,iCAAiC;;;;;;kBAK5B;;;;;WAMA,YAAY;EAI5B;EAGA;EAGA;EAGA;;;;;;;MAgCI,QAAQ;;;;;;;EAwBL,aACL,OAAO,gBAAgB,iBACvB,QAAQ,gBAAgB;;;;EAiBnB,gBAAgB,g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