@stanko/ctrls 0.1.1 → 0.1.2
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/README.md +8 -8
- package/dist/ctrls/ctrl-radio.d.ts +1 -0
- package/dist/ctrls/ctrl-radio.js +4 -1
- package/dist/ctrls/index.d.ts +1 -0
- package/dist/ctrls/index.js +3 -0
- package/dist/utils/get-random-string.d.ts +1 -0
- package/dist/utils/get-random-string.js +5 -0
- package/package.json +4 -3
- package/public/ctrls-ratio-2-perspective.png +0 -0
- package/public/ctrls-ratio-2.png +0 -0
package/README.md
CHANGED
|
@@ -8,7 +8,7 @@ Minimal library for controlling parameters, designed specifically for algorithmi
|
|
|
8
8
|
|
|
9
9
|
I built Ctrls for my [algorithmic art projects](https://muffinman.io/art/). By default, the state is saved in the URL, which lets you navigate history and share links easily. Along with standard components like checkboxes and ranges, it includes two especially useful for generative work: RNG seed and easing. These not only let you adjust parameters but also expose functions (rng and easing) you can call directly.
|
|
10
10
|
|
|
11
|
-
Play with the live example above or check the older version in my [Space Invaders generator](https://muffinman.io/invaders/)
|
|
11
|
+
Play with the live example above or check the older version in my [Space Invaders generator](https://muffinman.io/invaders/).
|
|
12
12
|
|
|
13
13
|
## Features
|
|
14
14
|
|
|
@@ -103,14 +103,14 @@ type ControlsOptions = {
|
|
|
103
103
|
showRandomizeButton?: boolean; // default: true
|
|
104
104
|
storage?: "hash" | "none"; // default: "hash"
|
|
105
105
|
theme?: "system" | "light" | "dark"; // default: "system"
|
|
106
|
+
parent?: Element; // if passed, the Ctrls element will be appended to this HTML element
|
|
106
107
|
};
|
|
107
108
|
```
|
|
108
109
|
|
|
109
110
|
Public API:
|
|
110
111
|
|
|
111
112
|
```ts
|
|
112
|
-
// The main Ctrls element
|
|
113
|
-
// document.querySelector('.my-controls').appendChild(options.element);
|
|
113
|
+
// The main Ctrls element
|
|
114
114
|
.element: HTMLDivElement
|
|
115
115
|
|
|
116
116
|
// Change handler called whenever any of the values is changed.
|
|
@@ -145,7 +145,7 @@ All controls share the following properties:
|
|
|
145
145
|
label?: string;
|
|
146
146
|
// Depends on the control type, the default value for the control
|
|
147
147
|
defaultValue?: T;
|
|
148
|
-
//
|
|
148
|
+
// Disabled the value randomization (via randomize method or button)
|
|
149
149
|
isRandomizationDisabled?: boolean; // default: false
|
|
150
150
|
}
|
|
151
151
|
```
|
|
@@ -372,14 +372,14 @@ Thank you for stopping by! If you end up using Ctrls, please let me know, I woul
|
|
|
372
372
|
|
|
373
373
|
## TODO
|
|
374
374
|
|
|
375
|
-
* [ ] Demo - favicon and metadata
|
|
376
|
-
* [ ] Readme - screenshots
|
|
377
|
-
* [ ] Prefix input names' with `ctrl_${id}_${name}` to avoid collisions
|
|
378
375
|
* [ ] Allow users to pass a custom PRNG lib
|
|
379
376
|
* [ ] Hash storage - check if there is an instance using hash storage already
|
|
380
|
-
* [ ] Demo - stop animation when not in viewport
|
|
381
377
|
* [ ] Add title which collapses the controls
|
|
382
378
|
* [ ] Storage - local storage
|
|
379
|
+
* [x] Prefix input names' with `ctrl_${id}_${name}` to avoid collisions
|
|
380
|
+
* [x] Demo - stop animation when not in viewport
|
|
381
|
+
* [x] Demo - favicon and metadata
|
|
382
|
+
* [x] Readme - screenshots
|
|
383
383
|
* [x] Use web safe / system fonts by default
|
|
384
384
|
* [x] Experiment with chroma for light and dark shades of the main color
|
|
385
385
|
* [x] On input event / handler
|
|
@@ -17,6 +17,7 @@ export declare class RadioCtrl implements Ctrl<string> {
|
|
|
17
17
|
items: Option[];
|
|
18
18
|
element: HTMLElement;
|
|
19
19
|
columns: 1 | 2 | 3 | 4 | 5;
|
|
20
|
+
id: string;
|
|
20
21
|
constructor(config: CtrlTypeRegistry["radio"]["config"], onChange: CtrlChangeHandler<string>, onInput: CtrlChangeHandler<string>);
|
|
21
22
|
parse: (string: string) => string;
|
|
22
23
|
getRandomValue: () => string;
|
package/dist/ctrls/ctrl-radio.js
CHANGED
|
@@ -1,4 +1,6 @@
|
|
|
1
1
|
import random from "../utils/random";
|
|
2
|
+
import { toKebabCase } from "../utils/string-utils";
|
|
3
|
+
import { getRandomString } from "../utils/get-random-string";
|
|
2
4
|
export class RadioCtrl {
|
|
3
5
|
constructor(config, onChange, onInput) {
|
|
4
6
|
this.type = "radio";
|
|
@@ -21,7 +23,7 @@ export class RadioCtrl {
|
|
|
21
23
|
const inputs = items.map((item) => {
|
|
22
24
|
const input = document.createElement("input");
|
|
23
25
|
input.setAttribute("type", "radio");
|
|
24
|
-
input.setAttribute("name", this.
|
|
26
|
+
input.setAttribute("name", this.id);
|
|
25
27
|
input.setAttribute("value", item.value);
|
|
26
28
|
input.checked = item.value === value;
|
|
27
29
|
input.addEventListener("change", () => {
|
|
@@ -75,6 +77,7 @@ export class RadioCtrl {
|
|
|
75
77
|
this.columns = config.columns || 3;
|
|
76
78
|
this.name = config.name;
|
|
77
79
|
this.label = config.label || config.name;
|
|
80
|
+
this.id = `ctrls-${getRandomString()}-${toKebabCase(this.name)}`;
|
|
78
81
|
const defaultValue = this.items.find((item) => item.value === config.defaultValue);
|
|
79
82
|
this.value = defaultValue?.value || this.getDefaultValue();
|
|
80
83
|
this.isRandomizationDisabled = config.isRandomizationDisabled || false;
|
package/dist/ctrls/index.d.ts
CHANGED
|
@@ -94,6 +94,7 @@ type ControlsOptions = {
|
|
|
94
94
|
showRandomizeButton?: boolean;
|
|
95
95
|
storage?: "hash" | "none";
|
|
96
96
|
theme?: "system" | "light" | "dark";
|
|
97
|
+
parent?: Element;
|
|
97
98
|
};
|
|
98
99
|
export declare class Ctrls<Configs extends readonly TypedControlConfig[]> {
|
|
99
100
|
options: ControlsOptions;
|
package/dist/ctrls/index.js
CHANGED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare const getRandomString: (slice?: number) => string;
|
package/package.json
CHANGED
|
@@ -1,12 +1,13 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@stanko/ctrls",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.2",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"scripts": {
|
|
6
|
-
"start": "vite",
|
|
7
|
-
"build": "tsc && vite build",
|
|
6
|
+
"start": "npm run parse-markdown && vite",
|
|
7
|
+
"build": "npm run parse-markdown && tsc && rm -rf ./docs && vite build && touch ./docs/.nojekyll",
|
|
8
8
|
"build-css": "sass ./src/scss/index.scss ./dist/ctrls.css",
|
|
9
9
|
"build-lib": "rm -rf ./dist && tsc -p ./tsconfig-lib.json && npm run build-css",
|
|
10
|
+
"parse-markdown": "node ./parse-markdown.js",
|
|
10
11
|
"preview": "vite preview",
|
|
11
12
|
"prepare": "cp ./pre-commit ./.git/hooks/pre-commit && chmod +x ./.git/hooks/pre-commit"
|
|
12
13
|
},
|
|
Binary file
|
|
Binary file
|