snapse 0.0.0-stage → 0.9.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.
Files changed (86) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +1169 -2
  3. package/dist/DOM/domFunctions.d.ts +12 -0
  4. package/dist/DOM/elements/DOMElements.d.ts +141 -0
  5. package/dist/DOM/elements/SVGElements.d.ts +65 -0
  6. package/dist/DOM/elements/elementAttributeTypes.d.ts +100 -0
  7. package/dist/DOM/nodeControllers/ComponentController.d.ts +10 -0
  8. package/dist/DOM/nodeControllers/ElementController.d.ts +14 -0
  9. package/dist/DOM/nodeControllers/NodeController.d.ts +81 -0
  10. package/dist/DOM/nodeControllers/RootController.d.ts +12 -0
  11. package/dist/DOM/nodeControllers/SVGElementController.d.ts +4 -0
  12. package/dist/DOM/nodeControllers/StateController.d.ts +43 -0
  13. package/dist/DOM/server/serialize.d.ts +2 -0
  14. package/dist/DOM/server/serverNodes.d.ts +41 -0
  15. package/dist/DOM/types.d.ts +84 -0
  16. package/dist/DOM/util/RenderError.d.ts +10 -0
  17. package/dist/DOM/util/childShape.d.ts +7 -0
  18. package/dist/DOM/util/deferredNodes.d.ts +7 -0
  19. package/dist/DOM/util/domNode.d.ts +2 -0
  20. package/dist/DOM/util/moveBeforeSupport.d.ts +1 -0
  21. package/dist/DOM/util/nodeCount.d.ts +2 -0
  22. package/dist/DOM/util/util.d.ts +2 -0
  23. package/dist/DOM.d.ts +4 -0
  24. package/dist/SVG.d.ts +3 -0
  25. package/dist/common/computeMutation.d.ts +16 -0
  26. package/dist/common/dev.d.ts +1 -0
  27. package/dist/common/shorthands.d.ts +1 -0
  28. package/dist/common/undoUtils.d.ts +1 -0
  29. package/dist/common/util.d.ts +4 -0
  30. package/dist/index.d.ts +7 -0
  31. package/dist/lint/index.d.ts +7 -0
  32. package/dist/lint/index.js +8 -0
  33. package/dist/lint/noBooleanStateArgument.d.ts +2 -0
  34. package/dist/lint/noBooleanStateArgument.js +43 -0
  35. package/dist/lint/noStateTruthiness.d.ts +2 -0
  36. package/dist/lint/noStateTruthiness.js +92 -0
  37. package/dist/lint/stateTypes.d.ts +4 -0
  38. package/dist/lint/stateTypes.js +14 -0
  39. package/dist/server.d.ts +2 -0
  40. package/dist/snapse.DOM.cjs +1 -0
  41. package/dist/snapse.DOM.development.cjs +115 -0
  42. package/dist/snapse.DOM.development.js +1 -0
  43. package/dist/snapse.SVG.cjs +1 -0
  44. package/dist/snapse.SVG.development.cjs +66 -0
  45. package/dist/snapse.SVG.development.js +1 -0
  46. package/dist/snapse.SVG.js +1 -0
  47. package/dist/snapse.cjs +1 -0
  48. package/dist/snapse.development.cjs +13 -0
  49. package/dist/snapse.development.js +1 -0
  50. package/dist/snapse.js +75 -0
  51. package/dist/snapse.server.cjs +1 -0
  52. package/dist/snapse.server.development.cjs +3 -0
  53. package/dist/snapse.server.development.js +1 -0
  54. package/dist/snapseCore-Bc8ZDYHa.cjs +1 -0
  55. package/dist/snapseCore-DpadpXgD.js +3002 -0
  56. package/dist/snapseCore-Xfnvf03Z.cjs +4135 -0
  57. package/dist/state/common/refCountAndType.d.ts +8 -0
  58. package/dist/state/common/stateProperty.d.ts +1 -0
  59. package/dist/state/compute.d.ts +2 -0
  60. package/dist/state/state.d.ts +39 -0
  61. package/dist/state/stateInternals/LightState.d.ts +20 -0
  62. package/dist/state/stateInternals/internalFunctions.d.ts +13 -0
  63. package/dist/state/stateInternals/notify.d.ts +7 -0
  64. package/dist/state/stateInternals/poison.d.ts +4 -0
  65. package/dist/state/stateInternals/stateUpdate.d.ts +9 -0
  66. package/dist/state/subscribeChanges.d.ts +2 -0
  67. package/dist/state/transforms/CallbackTransform.d.ts +13 -0
  68. package/dist/state/transforms/ChainFunctionTransform.d.ts +8 -0
  69. package/dist/state/transforms/ChangeAggregateTransform.d.ts +20 -0
  70. package/dist/state/transforms/ChangeCallbackTransform.d.ts +5 -0
  71. package/dist/state/transforms/ComputeTransform.d.ts +4 -0
  72. package/dist/state/transforms/DOMRootTransform.d.ts +8 -0
  73. package/dist/state/transforms/FunctionTransform.d.ts +5 -0
  74. package/dist/state/transforms/IsTransform.d.ts +25 -0
  75. package/dist/state/transforms/LightStateFunctionTransform.d.ts +3 -0
  76. package/dist/state/transforms/MapArrayTransform.d.ts +10 -0
  77. package/dist/state/transforms/MapValueTransform.d.ts +3 -0
  78. package/dist/state/transforms/OptTransform.d.ts +10 -0
  79. package/dist/state/transforms/PromiseTransform.d.ts +6 -0
  80. package/dist/state/transforms/SubscribeTransform.d.ts +13 -0
  81. package/dist/state/transforms/Transform.d.ts +35 -0
  82. package/dist/state/transforms/transforms.d.ts +30 -0
  83. package/dist/state/types/stateTypes.d.ts +175 -0
  84. package/dist/state/types/types.d.ts +35 -0
  85. package/dist/undo/undo.d.ts +39 -0
  86. package/package.json +141 -4
@@ -0,0 +1,8 @@
1
+ import { StateType } from '../../state/types/types.js';
2
+ import { LightState } from '../../state/stateInternals/LightState.js';
3
+ export declare const getStateType: (s: LightState) => StateType;
4
+ export declare const setStateType: (s: LightState, stateType: StateType) => number;
5
+ export declare const getRefCount: (s: LightState) => number;
6
+ export declare const setRefCount: (s: LightState, refCount: number) => number;
7
+ export declare const isPromotedElement: (s: LightState) => boolean;
8
+ export declare const markPromotedElement: (s: LightState) => number;
@@ -0,0 +1 @@
1
+ export declare const MAX_ARRAY_SIZE = 8;
@@ -0,0 +1,2 @@
1
+ import { State } from '../state/types/types.js';
2
+ export declare const compute: <T>(computeFunction: () => T) => State<T>;
@@ -0,0 +1,39 @@
1
+ import { AnyState, ArrayState, FunctionState, ObjectState, PrimitiveState, State, SubscribeCallback, SubscribeOptions, ValueOfState } from './types/types.js';
2
+ import { LightState } from './stateInternals/LightState.js';
3
+ import { Transform } from '../state/transforms/Transform.js';
4
+ export declare class CircularDependencyError extends Error {
5
+ constructor();
6
+ }
7
+ export declare const isState: <T = State>(value: unknown) => value is T;
8
+ export declare const isLightState: <T>(value: unknown) => value is LightState<T>;
9
+ export declare const isAnyState: <T>(value: unknown) => value is AnyState<T>;
10
+ export declare const subscribeWith: (state: unknown, createSubscription: (ls: LightState) => [target: LightState, transform: Transform]) => () => void;
11
+ export declare const subscribe: <S>(state: S, callback?: SubscribeCallback<NoInfer<ValueOfState<S>>>, options?: SubscribeOptions) => () => void;
12
+ export declare function findState<T>(name: string | symbol, def?: State<T>): State<T>;
13
+ export declare function findState<S extends ObjectState<unknown> | ArrayState<unknown> | PrimitiveState<unknown> | FunctionState<unknown>>(name: string | symbol, def?: ValueOfState<S>): S;
14
+ export declare const lightState: <T>(value: T) => LightState<T>;
15
+ export type StateCreatorType = {
16
+ <T>(value: T, name?: PropertyKey): State<T>;
17
+ <S extends ObjectState<unknown> | ArrayState<unknown> | PrimitiveState<unknown> | FunctionState<unknown>>(value: ValueOfState<S>, name?: PropertyKey): S;
18
+ };
19
+ export declare const state: StateCreatorType;
20
+ export declare const createStateLightState: <T>(value: T) => LightState<T>;
21
+ export type PeekType = {
22
+ <T>(value: ObjectState<T>): T;
23
+ <T>(value: PrimitiveState<T>): T;
24
+ <T>(value: FunctionState<T>): T;
25
+ <T>(value: ArrayState<T>): T[];
26
+ <T>(value: State<T>): T;
27
+ <T>(value: LightState<T>): T;
28
+ <T>(value: T): T;
29
+ };
30
+ export declare const peek: PeekType;
31
+ export declare const getLightState: <T>(value: T) => LightState | undefined;
32
+ export declare const delightstate: PeekType;
33
+ export declare const destate: PeekType;
34
+ export declare const isInComponent: () => boolean;
35
+ export declare const startCapturingStateCalls: (namedStates?: Record<PropertyKey, State>) => void;
36
+ export declare const stopCapturingStateCalls: () => {
37
+ namedStates: Record<PropertyKey, PrimitiveState<unknown, unknown>> | undefined;
38
+ subscriptions: (() => void)[] | undefined;
39
+ };
@@ -0,0 +1,20 @@
1
+ import { IState } from '../types/types.js';
2
+ import { Transform } from '../transforms/Transform.js';
3
+ export declare class LightState<T = unknown> {
4
+ v: T;
5
+ rct: number;
6
+ ver: number;
7
+ subs: Transform | Transform[] | Set<Transform> | undefined;
8
+ srcs: LightState | LightState[] | Set<LightState> | undefined;
9
+ tf: Transform | undefined;
10
+ prx: IState | undefined;
11
+ drt: number;
12
+ constructor(value: T);
13
+ get<U>(_target: () => void, prop: PropertyKey, receiver: IState<T>): unknown;
14
+ set(_target: () => void, prop: PropertyKey, value: unknown): boolean;
15
+ getPrototypeOf(): object | null;
16
+ apply(_target: () => void, thisArg: object, argumentsList: unknown[]): unknown;
17
+ getOwnPropertyDescriptor(_target: () => void, key: PropertyKey): PropertyDescriptor | undefined;
18
+ deleteProperty(_target: () => void, prop: PropertyKey): boolean;
19
+ ownKeys(): (string | symbol)[];
20
+ }
@@ -0,0 +1,13 @@
1
+ import { InternalFunctionMap } from '../../state/types/types.js';
2
+ import { LightState } from '../../state/stateInternals/LightState.js';
3
+ export { createVersion, refresh, updateValue, upsertProperty } from './stateUpdate.js';
4
+ export declare const orFunction: (source: LightState, value: unknown) => unknown;
5
+ export declare const notFunction: (source: LightState) => boolean;
6
+ export declare const STATE_PRIMITIVE = 0;
7
+ export declare const STATE_ARRAY = 1;
8
+ export declare const STATE_POJO = 2;
9
+ export declare const STATE_FUNCTION = 3;
10
+ export declare const STATE_OBJECT = 4;
11
+ export declare const STATE_DOMOBJECT = 5;
12
+ export declare const STATE_NULLISH_PRIMITIVE = 6;
13
+ export declare const internalFunctions: InternalFunctionMap[];
@@ -0,0 +1,7 @@
1
+ import { State } from '../../state/types/types.js';
2
+ import { LightState } from '../../state/stateInternals/LightState.js';
3
+ export declare const registerFlushPendingWork: (fn: () => void) => void;
4
+ export declare const queueFlush: () => number | true;
5
+ export declare const fastFlush: (f: EventListener, e: Event) => void;
6
+ export declare const flush: (s?: State) => void;
7
+ export declare const notify: (target: LightState) => void;
@@ -0,0 +1,4 @@
1
+ export declare const createPoisonedValue: (cause: unknown) => unknown;
2
+ export declare const isPoisoned: (v: unknown) => v is object;
3
+ export declare const throwIfPoisoned: (v: unknown) => void;
4
+ export declare const getPoisonCause: (v: object) => unknown;
@@ -0,0 +1,9 @@
1
+ import { Version } from '../../state/types/types.js';
2
+ import { LightState } from '../../state/stateInternals/LightState.js';
3
+ export declare const createVersion: () => number;
4
+ export declare const peekVersion: () => number;
5
+ export declare const assertWritable: (ls: LightState) => void;
6
+ export declare const promoteMemberToStateLightState: (owner: LightState, container: Record<PropertyKey, unknown>, prop: PropertyKey) => LightState;
7
+ export declare const upsertProperty: (container: Record<PropertyKey, unknown>, key: PropertyKey, subValue: unknown, version: Version, byOwner?: boolean) => boolean | undefined;
8
+ export declare const updateValue: <T>(ls: LightState<T>, v: T, version?: Version, byOwner?: boolean) => boolean;
9
+ export declare const refresh: <T>(ls: LightState<T>) => void | undefined;
@@ -0,0 +1,2 @@
1
+ import { ChangeRecord, SubscribeCallback, ValueOfState } from './types/types.js';
2
+ export declare const subscribeChanges: <S>(state: S, callback: SubscribeCallback<ValueOfState<S>, ChangeRecord>) => () => void;
@@ -0,0 +1,13 @@
1
+ import { SubscribeCallback } from '../types/types.js';
2
+ import { LightState } from '../../state/stateInternals/LightState.js';
3
+ import { Transform } from './Transform.js';
4
+ export declare class CallbackTransform<T = unknown, U = unknown> extends Transform {
5
+ srcLs: LightState<T>;
6
+ prio: number;
7
+ payload?: U;
8
+ constructor(source: LightState, callback: SubscribeCallback<T, U>, data?: U, priority?: number);
9
+ static flush(): void;
10
+ queue(): void;
11
+ dequeue(): void;
12
+ execute(): unknown;
13
+ }
@@ -0,0 +1,8 @@
1
+ import { LightState } from '../../state/stateInternals/LightState.js';
2
+ import { Transform } from './Transform.js';
3
+ export declare class ChainFunctionTransform extends Transform {
4
+ protected srcLs: LightState;
5
+ private hookName;
6
+ constructor(source: LightState, args: unknown[], name: PropertyKey);
7
+ execute(): unknown;
8
+ }
@@ -0,0 +1,20 @@
1
+ import { LightState } from '../../state/stateInternals/LightState.js';
2
+ import { ChangeRecord } from '../../state/types/types.js';
3
+ import { Transform } from './Transform.js';
4
+ export declare class ChangeAggregateTransform extends Transform {
5
+ protected srcLs: LightState;
6
+ private readonly parent;
7
+ private pathKey;
8
+ private readonly changes;
9
+ private readonly containerChildren;
10
+ private readonly leafValues;
11
+ private previousArrayChildren;
12
+ private seq;
13
+ flg: number;
14
+ static forState(ls: LightState): LightState;
15
+ constructor(source: LightState, parent: ChangeAggregateTransform | undefined, key: string | number, changes: ChangeRecord[], containerChildren: Map<LightState, ChangeAggregateTransform>, leafValues: Map<LightState, unknown>, addChanges?: boolean);
16
+ private buildPath;
17
+ drain(): ChangeRecord[];
18
+ execute(addChanges?: boolean): void;
19
+ handleArrayMutation(currentChildren: LightState[], addChanges: boolean): void;
20
+ }
@@ -0,0 +1,5 @@
1
+ import { ChangeRecord } from '../../state/types/types.js';
2
+ import { CallbackTransform } from './CallbackTransform.js';
3
+ export declare class ChangeCallbackTransform<T = unknown> extends CallbackTransform<T, ChangeRecord> {
4
+ execute(): void;
5
+ }
@@ -0,0 +1,4 @@
1
+ import { Transform } from './Transform.js';
2
+ export declare class ComputeTransform<T = unknown> extends Transform {
3
+ constructor(computeFunction: () => T);
4
+ }
@@ -0,0 +1,8 @@
1
+ import { Transform } from './Transform.js';
2
+ import { RootController } from '../../DOM/nodeControllers/RootController.js';
3
+ export declare class DOMRootTransform extends Transform {
4
+ private readonly rootCtl;
5
+ constructor(root: RootController);
6
+ queue(): void;
7
+ execute(): void;
8
+ }
@@ -0,0 +1,5 @@
1
+ import { Transform } from './Transform.js';
2
+ import { LightState } from '../../state/stateInternals/LightState.js';
3
+ export declare class FunctionTransform<T extends unknown[] = unknown[]> extends Transform {
4
+ constructor(source?: LightState, hookFunction?: (...args: T) => unknown, args?: T);
5
+ }
@@ -0,0 +1,25 @@
1
+ import { Transform } from './Transform.js';
2
+ import { LightState } from '../../state/stateInternals/LightState.js';
3
+ export declare class IsTransform extends Transform {
4
+ protected srcLs: LightState;
5
+ private compared;
6
+ private sourceToKey;
7
+ private oldReference;
8
+ private sourceRefCount;
9
+ private queued;
10
+ private static instances;
11
+ static for(reference: LightState): IsTransform;
12
+ constructor(reference: LightState);
13
+ refreshTarget(target: LightState): void;
14
+ private rekeyCompared;
15
+ execute(): void;
16
+ updateComparedState(ls: LightState, reference: unknown): void;
17
+ popComparedState(ls: LightState): LightState<unknown>;
18
+ private removeCompared;
19
+ queue(target?: LightState): void;
20
+ private isOwnTarget;
21
+ subTo(ls: LightState): void;
22
+ uns(state: LightState): void;
23
+ addCompared(comparedValue: unknown, target: LightState, comparedState?: LightState): void;
24
+ new(compared: unknown): import('../types/stateTypes.ts').ObjectState<LightState<boolean>, LightState<boolean>>;
25
+ }
@@ -0,0 +1,3 @@
1
+ import { FunctionTransform } from './FunctionTransform.js';
2
+ export declare class LightStateFunctionTransform<T extends unknown[] = unknown[]> extends FunctionTransform<T> {
3
+ }
@@ -0,0 +1,10 @@
1
+ import { State } from '../types/types.js';
2
+ import { Transform } from './Transform.js';
3
+ import { LightState } from '../../state/stateInternals/LightState.js';
4
+ export declare class MapArrayTransform extends Transform {
5
+ protected srcLs: LightState<Array<unknown>>;
6
+ private previousElements?;
7
+ private previousIndexStates?;
8
+ execute(): State;
9
+ private mapElement;
10
+ }
@@ -0,0 +1,3 @@
1
+ import { LightStateFunctionTransform } from './LightStateFunctionTransform.js';
2
+ export declare class MapValueTransform<T extends unknown[] = unknown[]> extends LightStateFunctionTransform<T> {
3
+ }
@@ -0,0 +1,10 @@
1
+ import { OptOption } from '../types/types.js';
2
+ import { Transform } from './Transform.js';
3
+ import { LightState } from '../../state/stateInternals/LightState.js';
4
+ export declare class OptTransform<T = unknown> extends Transform {
5
+ protected srcLs: LightState;
6
+ private opt;
7
+ private def?;
8
+ constructor(selector: LightState, options: OptOption<T>, def?: unknown);
9
+ execute(): import('../types/types.js').AnyState<unknown>;
10
+ }
@@ -0,0 +1,6 @@
1
+ import { Transform } from './Transform.js';
2
+ import { LightState } from '../../state/stateInternals/LightState.js';
3
+ export declare class PromiseTransform<T = unknown> extends Transform {
4
+ constructor(promise: Promise<T>);
5
+ execute(): LightState<unknown> | undefined;
6
+ }
@@ -0,0 +1,13 @@
1
+ import { Transform } from './Transform.js';
2
+ import { LightState } from '../../state/stateInternals/LightState.js';
3
+ export declare const getSubState: (owner: LightState, prop: PropertyKey) => LightState | undefined;
4
+ export declare class SubscribeTransform extends Transform {
5
+ protected srcLs: LightState;
6
+ private static instances;
7
+ private pendingSelf;
8
+ private seq;
9
+ static for(ls: LightState): LightState | undefined;
10
+ private constructor();
11
+ queue(target?: LightState): void;
12
+ execute(): void;
13
+ }
@@ -0,0 +1,35 @@
1
+ import { AnyState, State } from '../types/types.js';
2
+ import { LightState } from '../../state/stateInternals/LightState.js';
3
+ export declare const queueRoot: (transform: Transform) => void;
4
+ export declare const acquireSet: () => Set<LightState>;
5
+ export declare const releaseSet: (s: Set<LightState>) => void;
6
+ export declare const TRANSFORM_FLAG_CREATE_LIGHT_STATE = 1;
7
+ export declare const TRANSFORM_FLAG_REBUILDS_CHILDREN = 2;
8
+ export declare const nextRunId: () => number;
9
+ export declare const currentRunId: () => number;
10
+ export declare class Transform {
11
+ protected tgt?: LightState;
12
+ protected srcLs?: LightState;
13
+ flg: number;
14
+ runId: number;
15
+ protected hookFunction?: (...args: unknown[]) => unknown;
16
+ protected hookArgs?: unknown[];
17
+ constructor(source?: LightState, hook?: (...args: unknown[]) => unknown);
18
+ private static isDirty;
19
+ private static sourceIsDirty;
20
+ static throwDelayed(e: unknown): void;
21
+ static flush(): void;
22
+ queue(_target?: LightState): void;
23
+ dequeue(): void;
24
+ subTo(state: LightState): void;
25
+ subscribeSources(state: LightState): void;
26
+ uns(state: LightState): void;
27
+ unsubscribeSources(state: LightState): void;
28
+ rfr(): void;
29
+ execute(): unknown;
30
+ private hasOnlyPassthroughSource;
31
+ protected updateTarget<T>(newValue: T | State<T>, newSources: Set<LightState>): AnyState<T>;
32
+ static connect(target: LightState): void;
33
+ }
34
+ export declare const connectTouchedState: (target: LightState) => void;
35
+ export declare const DERIVED_MEMBER: Transform;
@@ -0,0 +1,30 @@
1
+ import { Transform } from './Transform.js';
2
+ import { ChainFunctionTransform } from './ChainFunctionTransform.js';
3
+ import { MapArrayTransform } from './MapArrayTransform.js';
4
+ import { CallbackTransform } from './CallbackTransform.js';
5
+ import { OptTransform } from './OptTransform.js';
6
+ import { ComputeTransform } from './ComputeTransform.js';
7
+ import { LightStateFunctionTransform } from './LightStateFunctionTransform.js';
8
+ import { FunctionTransform } from './FunctionTransform.js';
9
+ import { IsTransform } from './IsTransform.js';
10
+ import { PromiseTransform } from './PromiseTransform.js';
11
+ import { SubscribeTransform } from './SubscribeTransform.js';
12
+ import { DOMRootTransform } from './DOMRootTransform.js';
13
+ import { MapValueTransform } from './MapValueTransform.js';
14
+ type Transforms = {
15
+ Transform: typeof Transform;
16
+ ChainFunctionTransform: typeof ChainFunctionTransform;
17
+ MapArrayTransform: typeof MapArrayTransform;
18
+ MapValueTransform: typeof MapValueTransform;
19
+ CallbackTransform: typeof CallbackTransform;
20
+ OptTransform: typeof OptTransform;
21
+ ComputeTransform: typeof ComputeTransform;
22
+ LightStateFunctionTransform: typeof LightStateFunctionTransform;
23
+ IsTransform: typeof IsTransform;
24
+ PromiseTransform: typeof PromiseTransform;
25
+ FunctionTransform: typeof FunctionTransform;
26
+ SubscribeTransform: typeof SubscribeTransform;
27
+ DOMRootTransform: typeof DOMRootTransform;
28
+ };
29
+ export declare const transforms: Transforms;
30
+ export {};
@@ -0,0 +1,175 @@
1
+ import { NodeController } from '../../DOM/nodeControllers/NodeController.js';
2
+ type Nullish = null | undefined;
3
+ declare const STATE_BRAND: unique symbol;
4
+ type StateBrand = {
5
+ readonly [STATE_BRAND]: true;
6
+ };
7
+ export type SomeState = StateBrand;
8
+ declare const STATE_VALUE: unique symbol;
9
+ export type ObjectStateOf<V> = {
10
+ [STATE_VALUE]?(value: V): void;
11
+ } & StateBrand;
12
+ export type OrType<T = unknown> = <U>(v: U) => State<T | U>;
13
+ export type CatchType<Full = unknown> = (v: unknown) => State<Full>;
14
+ export type MaybeState<T> = T | State<T>;
15
+ type ArrayStateConstraint<T> = {
16
+ push(...items: T[]): unknown;
17
+ set: unknown;
18
+ };
19
+ export type ValueOfState<S> = S extends FunctionState<infer T> ? T : S extends ArrayState<infer T> ? T[] : S extends ObjectState<infer T> ? T : S extends PrimitiveState<infer T> ? T : S extends PrimitiveStateMethods<infer T> ? T : S;
20
+ type OptKey<Self> = [Extract<Self, PropertyKey>] extends [never] ? string : Extract<Self, PropertyKey>;
21
+ type OptFullMap<Self> = Record<OptKey<Self>, unknown>;
22
+ type OptPartialMap<Self> = Partial<Record<OptKey<Self>, unknown>>;
23
+ type NotOptMap<Self, T> = T extends OptPartialMap<Self> ? never : T;
24
+ export interface OptType<Self = unknown> {
25
+ <T, U = T>(options: ArrayStateConstraint<T>, def: U | State<U>): NoInfer<State<T | U>>;
26
+ <T>(options: ArrayStateConstraint<T>): NoInfer<State<T | undefined>>;
27
+ <T extends OptFullMap<Self>>(options: T): NoInfer<State<T[keyof T] | undefined>>;
28
+ <T extends OptFullMap<Self>>(options: State<T>): NoInfer<State<T[keyof T] | undefined>>;
29
+ <T extends OptPartialMap<Self>, U = T[keyof T]>(options: T, def: U | State<U>): NoInfer<State<T[keyof T] | U>>;
30
+ <T extends OptPartialMap<Self>, U = T[keyof T]>(options: State<T>, def: U | State<U>): NoInfer<State<T[keyof T] | U>>;
31
+ <T, U = T>(options: T[] | State<T[]>, def: U | State<U>): NoInfer<State<T | U>>;
32
+ <T>(options: T[] | State<T[]>): NoInfer<State<T | undefined>>;
33
+ <T, D>(options: NotOptMap<Self, T>, def: D): NoInfer<State<T | ValueOfState<D>>>;
34
+ <T>(options: NotOptMap<Self, T>): NoInfer<State<T | undefined>>;
35
+ }
36
+ type StringState = {
37
+ at(index: number): State<string | undefined>;
38
+ charAt(pos: number): State<string>;
39
+ charCodeAt(index: number): State<number>;
40
+ codePointAt(pos: number): State<number | undefined>;
41
+ concat(...strings: string[]): State<string>;
42
+ endsWith(searchString: string, endPosition?: number): State<boolean>;
43
+ includes(searchString: string, position?: number): State<boolean>;
44
+ indexOf(searchString: string, position?: number): State<number>;
45
+ lastIndexOf(searchString: string, position?: number): State<number>;
46
+ localeCompare(that: string, locales?: string | string[], options?: Intl.CollatorOptions): State<number>;
47
+ match(regexp: string | RegExp): State<RegExpMatchArray | null>;
48
+ matchAll(regexp: RegExp): State<IterableIterator<RegExpMatchArray>>;
49
+ normalize(form?: string): State<string>;
50
+ padEnd(maxLength: number, fillString?: string): State<string>;
51
+ padStart(maxLength: number, fillString?: string): State<string>;
52
+ repeat(count: number): State<string>;
53
+ replace(searchValue: string | RegExp, replaceValue: string): State<string>;
54
+ replace(searchValue: string | RegExp, replacer: (substring: string, ...args: unknown[]) => string): State<string>;
55
+ replaceAll(searchValue: string | RegExp, replaceValue: string): State<string>;
56
+ replaceAll(searchValue: string | RegExp, replacer: (substring: string, ...args: unknown[]) => string): State<string>;
57
+ search(regexp: string | RegExp): State<number>;
58
+ slice(start?: number, end?: number): State<string>;
59
+ split(separator: string | RegExp | undefined, limit?: number): ArrayState<string>;
60
+ startsWith(searchString: string, position?: number): State<boolean>;
61
+ substring(start: number, end?: number): State<string>;
62
+ toLocaleLowerCase(locales?: string | string[]): State<string>;
63
+ toLocaleUpperCase(locales?: string | string[]): State<string>;
64
+ toLowerCase(): State<string>;
65
+ toString(): string;
66
+ toUpperCase(): State<string>;
67
+ trim(): State<string>;
68
+ trimEnd(): State<string>;
69
+ trimStart(): State<string>;
70
+ valueOf(): string;
71
+ };
72
+ type NumberState = {
73
+ toExponential(fractionDigits?: number): State<string>;
74
+ toFixed(fractionDigits?: number): State<string>;
75
+ toLocaleString(locales?: string | string[], options?: Intl.NumberFormatOptions): State<string>;
76
+ toPrecision(precision?: number): State<string>;
77
+ toString(radix?: number): string;
78
+ valueOf(): number;
79
+ };
80
+ type BigIntState = {
81
+ toLocaleString(locales?: string, options?: object): State<string>;
82
+ toString(radix?: number): string;
83
+ valueOf(): bigint;
84
+ };
85
+ type BooleanState = {
86
+ toString(): string;
87
+ valueOf(): boolean;
88
+ };
89
+ type SymbolState = {
90
+ toString(): string;
91
+ valueOf(): symbol;
92
+ };
93
+ type PrimitiveStates<T> = T extends string ? StringState : T extends number ? NumberState : T extends boolean ? BooleanState : T extends bigint ? BigIntState : T extends symbol ? SymbolState : unknown;
94
+ export type PrimitiveStateMethods<T> = {
95
+ opt: OptType<T>;
96
+ or: OrType<T>;
97
+ set(v: MaybeState<T>): void;
98
+ not: () => State<boolean>;
99
+ is: (v: unknown) => State<boolean>;
100
+ } & StateBrand;
101
+ export type PrimitiveState<T = unknown, Full = T> = PrimitiveStates<T> & T & PrimitiveStateMethods<Full>;
102
+ type NullishState<Full> = PrimitiveStateMethods<Full> & {
103
+ [key: string]: undefined;
104
+ };
105
+ export type FunctionState<T = unknown, Full = T> = (T extends (...args: infer A) => infer R ? (...args: A) => State<R> : T) & {
106
+ opt: OptType<Full>;
107
+ or: OrType<Full>;
108
+ set(v: MaybeState<Full>): void;
109
+ } & StateBrand;
110
+ export type ArrayState<T, Full = T[]> = {
111
+ filter<S extends T>(predicate: (value: State<T>, index: number, array: ArrayState<T>) => value is State<S>, thisArg?: unknown): ArrayState<S>;
112
+ filter(predicate: (value: State<T>, index: number, array: ArrayState<T>) => unknown, thisArg?: unknown): ArrayState<T>;
113
+ map<U>(callbackfn: (value: State<T>, index: State<number>, array: ArrayState<T>) => U, thisArg?: unknown): ArrayState<U>;
114
+ flatMap<U, This = undefined>(callback: (this: This, value: State<T>, index: number, array: ArrayState<T>) => U | ReadonlyArray<U>, thisArg?: This): ArrayState<U>;
115
+ find<S extends T>(predicate: (value: State<T>, index: number, obj: ArrayState<T>) => value is State<S>, thisArg?: unknown): State<S | undefined>;
116
+ find(predicate: (value: State<T>, index: number, obj: ArrayState<T>) => unknown, thisArg?: unknown): State<T | undefined>;
117
+ findLast<S extends T>(predicate: (value: State<T>, index: number, array: ArrayState<T>) => value is State<S>, thisArg?: unknown): State<S | undefined>;
118
+ findLast(predicate: (value: State<T>, index: number, array: ArrayState<T>) => unknown, thisArg?: unknown): State<T | undefined>;
119
+ findIndex(predicate: (value: State<T>, index: number, obj: ArrayState<T>) => unknown, thisArg?: unknown): State<number>;
120
+ findLastIndex(predicate: (value: State<T>, index: number, array: ArrayState<T>) => unknown, thisArg?: unknown): State<number>;
121
+ reduce(callbackfn: (previousValue: State<T>, currentValue: State<T>, currentIndex: number, array: ArrayState<T>) => T): State<T>;
122
+ reduce(callbackfn: (previousValue: T, currentValue: State<T>, currentIndex: number, array: ArrayState<T>) => T, initialValue: T): State<T>;
123
+ reduce<U>(callbackfn: (previousValue: U, currentValue: State<T>, currentIndex: number, array: ArrayState<T>) => U, initialValue: U): State<U>;
124
+ reduceRight(callbackfn: (previousValue: State<T>, currentValue: State<T>, currentIndex: number, array: ArrayState<T>) => T): State<T>;
125
+ reduceRight(callbackfn: (previousValue: T, currentValue: State<T>, currentIndex: number, array: ArrayState<T>) => T, initialValue: T): State<T>;
126
+ reduceRight<U>(callbackfn: (previousValue: U, currentValue: State<T>, currentIndex: number, array: ArrayState<T>) => U, initialValue: U): State<U>;
127
+ some(predicate: (value: State<T>, index: number, array: ArrayState<T>) => unknown, thisArg?: unknown): State<boolean>;
128
+ every<S extends T>(predicate: (value: State<T>, index: number, array: ArrayState<T>) => value is State<S>, thisArg?: unknown): State<boolean>;
129
+ every(predicate: (value: State<T>, index: number, array: ArrayState<T>) => unknown, thisArg?: unknown): State<boolean>;
130
+ includes(searchElement: T, fromIndex?: number): State<boolean>;
131
+ indexOf(searchElement: T, fromIndex?: number): State<number>;
132
+ lastIndexOf(searchElement: T, fromIndex?: number): State<number>;
133
+ at(index: number): State<T | undefined>;
134
+ slice(start?: number, end?: number): ArrayState<T>;
135
+ concat(...items: ConcatArray<T>[]): ArrayState<T>;
136
+ concat(...items: (T | ConcatArray<T>)[]): ArrayState<T>;
137
+ join(separator?: string): State<string>;
138
+ toString(): string;
139
+ toLocaleString(): State<string>;
140
+ sort(compareFn?: (a: T, b: T) => number): ArrayState<T, Full>;
141
+ toSorted(compareFn?: (a: T, b: T) => number): ArrayState<T>;
142
+ toReversed(): ArrayState<T>;
143
+ toSpliced(start: number, deleteCount: number, ...items: T[]): ArrayState<T>;
144
+ toSpliced(start: number, deleteCount?: number): ArrayState<T>;
145
+ with(index: number, value: T): ArrayState<T>;
146
+ keys(): State<IterableIterator<number>>;
147
+ values(): State<IterableIterator<T>>;
148
+ entries(): State<IterableIterator<[number, T]>>;
149
+ opt: OptType<Full>;
150
+ or: OrType<Full>;
151
+ set(v: MaybeState<Full>): void;
152
+ [K: number]: State<T>;
153
+ } & T[] & StateBrand;
154
+ type ObjectStateMember<T, K extends keyof T> = K extends 'toString' | 'valueOf' ? T[K] : State<T[K]>;
155
+ export type ObjectState<T, Full = T> = {
156
+ [K in keyof T]: ObjectStateMember<T, K>;
157
+ } & {
158
+ set(v: MaybeState<Full>): void;
159
+ } & {
160
+ [key: string]: unknown;
161
+ } & ObjectStateOf<T>;
162
+ export type DOMObjectState<T, Full = T> = {
163
+ [K in keyof T as K extends 'catch' ? never : K]: State<T[K]>;
164
+ } & {
165
+ set(v: MaybeState<Full>): void;
166
+ } & {
167
+ [key: string]: unknown;
168
+ } & ObjectStateOf<T> & {
169
+ opt: OptType<Full>;
170
+ or: OrType<Full>;
171
+ catch: CatchType<Full>;
172
+ };
173
+ type StateImpl<Member, Full> = Member extends StateBrand ? Member : Member extends number ? PrimitiveState<number, Full> : Member extends string ? PrimitiveState<string, Full> : Member extends boolean ? PrimitiveState<boolean, Full> : Member extends Array<infer U> ? ArrayState<U, Full> : Member extends ArrayState<infer U> ? ArrayState<U, Full> : Member extends Function ? FunctionState<Member, Full> : Member extends NodeController ? DOMObjectState<Member, Full> : Member extends object ? ObjectState<Member, Full> : [Member] extends [Nullish] ? NullishState<Full> : PrimitiveState<Member, Full>;
174
+ export type State<T = unknown> = StateImpl<T, T>;
175
+ export {};
@@ -0,0 +1,35 @@
1
+ import { STATE_ARRAY, STATE_DOMOBJECT, STATE_FUNCTION, STATE_OBJECT, STATE_POJO, STATE_PRIMITIVE } from '../../state/stateInternals/internalFunctions.js';
2
+ import { State } from './stateTypes.js';
3
+ import { LightState } from '../stateInternals/LightState.js';
4
+ export type { PrimitiveState, FunctionState, ArrayState, ObjectState, OptType, State, PrimitiveStateMethods, ValueOfState, MaybeState, ObjectStateOf, SomeState, } from './stateTypes.js';
5
+ export type SubscribeCallback<Value = unknown, Data = unknown> = (n: Value, s?: Data) => void;
6
+ export type SubscribeOptions = {
7
+ deep?: boolean;
8
+ };
9
+ export type ChangeRecord = {
10
+ path?: (string | number)[];
11
+ value?: unknown;
12
+ oldValue?: unknown;
13
+ done?: boolean;
14
+ reorder?: boolean;
15
+ remove?: number[];
16
+ add?: number[];
17
+ common?: number[];
18
+ prefixL?: number;
19
+ suffixL?: number;
20
+ addedValues?: unknown[];
21
+ removedValues?: unknown[];
22
+ };
23
+ export type Version = number;
24
+ export type OptOption<T = unknown> = T | T[] | Record<string, T>;
25
+ export type MapFunction = (value: unknown, index: number, array: unknown[]) => unknown;
26
+ export type InternalStateTarget<T = unknown> = LightState<T & Record<PropertyKey, unknown>>;
27
+ export type InternalFunction<T = unknown> = (target: InternalStateTarget<T>, receiver: IState<T>) => unknown;
28
+ export type InternalFunctionMap = Map<PropertyKey, InternalFunction>;
29
+ export type IState<T = unknown> = {
30
+ [Symbol.toPrimitive]: (...args: unknown[]) => unknown;
31
+ toString: () => string;
32
+ valueOf: () => T;
33
+ } & State<T>;
34
+ export type AnyState<T = unknown> = LightState<T> | IState<T>;
35
+ export type StateType = typeof STATE_PRIMITIVE | typeof STATE_ARRAY | typeof STATE_POJO | typeof STATE_FUNCTION | typeof STATE_OBJECT | typeof STATE_DOMOBJECT;
@@ -0,0 +1,39 @@
1
+ import { ChangeRecord, SomeState, State } from '../state/types/types.js';
2
+ export type { ChangeRecord } from '../state/types/types.js';
3
+ export type HistoryEntry = {
4
+ batch: ChangeRecord[];
5
+ t: number;
6
+ };
7
+ type TrackHistoryOptions = {
8
+ limit?: number;
9
+ addHistoryVersion?: () => number;
10
+ };
11
+ export declare class TrackHistory<S extends SomeState> {
12
+ private readonly tracked;
13
+ private readonly opts?;
14
+ private readonly undoStack;
15
+ private readonly redoStack;
16
+ private batch;
17
+ private applying;
18
+ private batching;
19
+ private readonly unsub;
20
+ undoEmpty: State<boolean>;
21
+ redoEmpty: State<boolean>;
22
+ historyVersions: State<number[]>;
23
+ private onChange;
24
+ private finalizeBatch;
25
+ private updateDerivedState;
26
+ constructor(root: S, opts?: TrackHistoryOptions);
27
+ private walkToNode;
28
+ private applyReorder;
29
+ private applyChange;
30
+ private replay;
31
+ undo: () => boolean;
32
+ redo: () => boolean;
33
+ restoreAt(timestamp: number): void;
34
+ startBatch(): void;
35
+ commitBatch(): void;
36
+ getHistory(): HistoryEntry[];
37
+ setHistory(history: HistoryEntry[]): void;
38
+ unsubscribe(): void;
39
+ }