@stanko/ctrls 0.1.8 → 0.1.9
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.
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import DualRangeInput from "@stanko/dual-range-input";
|
|
2
|
-
import type { Ctrl, CtrlChangeHandler, CtrlType,
|
|
2
|
+
import type { Ctrl, CtrlChangeHandler, CtrlType, ConfigFor } from ".";
|
|
3
3
|
export type DualRangeControlOptions = {
|
|
4
4
|
min: number;
|
|
5
5
|
max: number;
|
|
@@ -25,7 +25,7 @@ export declare class DualRangeCtrl implements Ctrl<DualRangeValue> {
|
|
|
25
25
|
maxInput: HTMLInputElement;
|
|
26
26
|
dualRange: DualRangeInput;
|
|
27
27
|
valueSpan: HTMLSpanElement;
|
|
28
|
-
constructor(config:
|
|
28
|
+
constructor(config: ConfigFor<"dual-range">, onChange: CtrlChangeHandler<DualRangeValue>, onInput: CtrlChangeHandler<DualRangeValue>);
|
|
29
29
|
parse: (string: string) => {
|
|
30
30
|
min: number;
|
|
31
31
|
max: number;
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type { Ctrl, CtrlChangeHandler, CtrlType,
|
|
1
|
+
import type { Ctrl, CtrlChangeHandler, CtrlType, ConfigFor } from ".";
|
|
2
2
|
export type Easing = [number, number, number, number];
|
|
3
3
|
export declare class EasingCtrl implements Ctrl<Easing> {
|
|
4
4
|
type: CtrlType;
|
|
@@ -15,7 +15,7 @@ export declare class EasingCtrl implements Ctrl<Easing> {
|
|
|
15
15
|
lines: SVGLineElement[];
|
|
16
16
|
path: SVGPathElement;
|
|
17
17
|
presets: Record<string, Easing>;
|
|
18
|
-
constructor(config:
|
|
18
|
+
constructor(config: ConfigFor<"easing">, onChange: CtrlChangeHandler<Easing>, onInput: CtrlChangeHandler<Easing>);
|
|
19
19
|
parse: (string: string) => Easing;
|
|
20
20
|
getRandomValue: () => Easing;
|
|
21
21
|
getDefaultValue: () => Easing;
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type { Ctrl, CtrlChangeHandler, CtrlType,
|
|
1
|
+
import type { Ctrl, CtrlChangeHandler, CtrlType, ConfigFor } from ".";
|
|
2
2
|
type Option = {
|
|
3
3
|
label: string;
|
|
4
4
|
value: string;
|
|
@@ -18,7 +18,7 @@ export declare class RadioCtrl implements Ctrl<string> {
|
|
|
18
18
|
element: HTMLElement;
|
|
19
19
|
columns: 1 | 2 | 3 | 4 | 5;
|
|
20
20
|
id: string;
|
|
21
|
-
constructor(config:
|
|
21
|
+
constructor(config: ConfigFor<"radio">, onChange: CtrlChangeHandler<string>, onInput: CtrlChangeHandler<string>);
|
|
22
22
|
parse: (string: string) => string;
|
|
23
23
|
getRandomValue: () => string;
|
|
24
24
|
getDefaultValue: () => string;
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type { Ctrl, CtrlChangeHandler, CtrlType,
|
|
1
|
+
import type { Ctrl, CtrlChangeHandler, CtrlType, ConfigFor } from ".";
|
|
2
2
|
export declare class RangeCtrl implements Ctrl<number> {
|
|
3
3
|
type: CtrlType;
|
|
4
4
|
name: string;
|
|
@@ -13,7 +13,7 @@ export declare class RangeCtrl implements Ctrl<number> {
|
|
|
13
13
|
element: HTMLElement;
|
|
14
14
|
input: HTMLInputElement;
|
|
15
15
|
valueSpan: HTMLSpanElement;
|
|
16
|
-
constructor(config:
|
|
16
|
+
constructor(config: ConfigFor<"range">, onChange: CtrlChangeHandler<number>, onInput: CtrlChangeHandler<number>);
|
|
17
17
|
parse: (string: string) => number;
|
|
18
18
|
getRandomValue: () => number;
|
|
19
19
|
getDefaultValue: () => number;
|
package/dist/ctrls/index.d.ts
CHANGED
|
@@ -31,57 +31,51 @@ export interface Ctrl<T> {
|
|
|
31
31
|
update: (value: T) => void;
|
|
32
32
|
element: HTMLElement;
|
|
33
33
|
}
|
|
34
|
-
export
|
|
35
|
-
export type ControlConstructor<T> = new (...args: any[]) => T;
|
|
36
|
-
export interface CtrlTypeRegistry {
|
|
34
|
+
export interface CtrlTypeMap {
|
|
37
35
|
boolean: {
|
|
38
|
-
config: CtrlConfig<boolean>;
|
|
39
|
-
instance: BooleanCtrl;
|
|
40
36
|
value: boolean;
|
|
41
37
|
};
|
|
42
38
|
range: {
|
|
43
|
-
config: CtrlConfig<number> & {
|
|
44
|
-
min: number;
|
|
45
|
-
max: number;
|
|
46
|
-
step?: number;
|
|
47
|
-
};
|
|
48
|
-
instance: RangeCtrl;
|
|
49
39
|
value: number;
|
|
40
|
+
min: number;
|
|
41
|
+
max: number;
|
|
42
|
+
step?: number;
|
|
50
43
|
};
|
|
51
44
|
radio: {
|
|
52
|
-
config: CtrlConfig<string> & {
|
|
53
|
-
items: Record<string, string>;
|
|
54
|
-
columns?: 1 | 2 | 3 | 4 | 5;
|
|
55
|
-
};
|
|
56
|
-
instance: RadioCtrl;
|
|
57
45
|
value: string;
|
|
46
|
+
items: Record<string, string>;
|
|
47
|
+
columns?: 1 | 2 | 3 | 4 | 5;
|
|
58
48
|
};
|
|
59
49
|
seed: {
|
|
60
|
-
config: CtrlConfig<string>;
|
|
61
|
-
instance: SeedCtrl;
|
|
62
50
|
value: string;
|
|
63
51
|
};
|
|
64
52
|
easing: {
|
|
65
|
-
config: CtrlConfig<Easing> & {
|
|
66
|
-
presets?: Record<string, Easing>;
|
|
67
|
-
};
|
|
68
|
-
instance: EasingCtrl;
|
|
69
53
|
value: Easing;
|
|
54
|
+
presets?: Record<string, Easing>;
|
|
70
55
|
};
|
|
71
56
|
"dual-range": {
|
|
72
|
-
config: CtrlConfig<DualRangeValue> & {
|
|
73
|
-
min: number;
|
|
74
|
-
max: number;
|
|
75
|
-
step?: number;
|
|
76
|
-
};
|
|
77
|
-
instance: DualRangeCtrl;
|
|
78
57
|
value: DualRangeValue;
|
|
58
|
+
min: number;
|
|
59
|
+
max: number;
|
|
60
|
+
step?: number;
|
|
79
61
|
};
|
|
80
62
|
}
|
|
81
|
-
export type TypedControlConfig =
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
63
|
+
export type TypedControlConfig = {
|
|
64
|
+
[K in CtrlType]: {
|
|
65
|
+
type: K;
|
|
66
|
+
name: string;
|
|
67
|
+
label?: string;
|
|
68
|
+
defaultValue?: CtrlTypeMap[K]["value"];
|
|
69
|
+
isRandomizationDisabled?: boolean;
|
|
70
|
+
} & Omit<CtrlTypeMap[K], "value">;
|
|
71
|
+
}[CtrlType];
|
|
72
|
+
export type ConfigFor<T extends CtrlType> = Extract<TypedControlConfig, {
|
|
73
|
+
type: T;
|
|
74
|
+
}>;
|
|
75
|
+
type ExtractValues<Configs extends readonly TypedControlConfig[]> = {
|
|
76
|
+
[C in Configs[number] as C["name"]]: CtrlTypeMap[C["type"]]["value"];
|
|
77
|
+
};
|
|
78
|
+
type DerivedProps<Configs extends readonly TypedControlConfig[]> = {
|
|
85
79
|
[C in Extract<Configs[number], {
|
|
86
80
|
type: "easing";
|
|
87
81
|
}> as `${C["name"]}Easing`]: ReturnType<typeof BezierEasing>;
|
|
@@ -90,6 +84,7 @@ type OptionsMap<Configs extends readonly TypedControlConfig[]> = {
|
|
|
90
84
|
type: "seed";
|
|
91
85
|
}> as `${C["name"]}Rng`]: PRNG;
|
|
92
86
|
};
|
|
87
|
+
type OptionsMap<Configs extends readonly TypedControlConfig[]> = ExtractValues<Configs> & DerivedProps<Configs>;
|
|
93
88
|
type ControlsOptions = {
|
|
94
89
|
showRandomizeButton?: boolean;
|
|
95
90
|
storage?: "hash" | "none";
|
|
@@ -97,10 +92,11 @@ type ControlsOptions = {
|
|
|
97
92
|
parent?: Element;
|
|
98
93
|
title?: string;
|
|
99
94
|
};
|
|
95
|
+
type CtrlComponent = BooleanCtrl | RangeCtrl | RadioCtrl | SeedCtrl | EasingCtrl | DualRangeCtrl;
|
|
100
96
|
export declare class Ctrls<Configs extends readonly TypedControlConfig[]> {
|
|
101
97
|
options: ControlsOptions;
|
|
102
|
-
controls:
|
|
103
|
-
controlsMap: Record<string,
|
|
98
|
+
controls: CtrlComponent[];
|
|
99
|
+
controlsMap: Record<string, CtrlComponent>;
|
|
104
100
|
element: HTMLDivElement;
|
|
105
101
|
onChange?: (updatedValues: Partial<ReturnType<typeof this.getValues>>) => void;
|
|
106
102
|
onInput?: (updatedValues: Partial<ReturnType<typeof this.getValues>>) => void;
|
|
@@ -1,9 +1,11 @@
|
|
|
1
|
+
import Alea from "./alea";
|
|
1
2
|
import random from "./random";
|
|
2
3
|
import { words } from "./words";
|
|
4
|
+
const rng = Alea();
|
|
3
5
|
export default function generateSeed() {
|
|
4
6
|
return [1, 2, 3]
|
|
5
7
|
.map(() => {
|
|
6
|
-
const index = random(0, words.length - 1,
|
|
8
|
+
const index = random(0, words.length - 1, rng, 0);
|
|
7
9
|
return words[index];
|
|
8
10
|
})
|
|
9
11
|
.join("-");
|