fragment-tools 0.1.13 → 0.1.14
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/bin/index.js +2 -2
- package/package.json +4 -5
- package/src/cli/log.js +31 -21
- package/src/cli/plugins/check-dependencies.js +47 -30
- package/src/cli/plugins/hot-shader-replacement.js +384 -0
- package/src/cli/plugins/hot-sketch-reload.js +3 -13
- package/src/cli/plugins/screenshot.js +57 -20
- package/src/cli/server.js +144 -133
- package/src/client/app/App.svelte +3 -3
- package/src/client/app/client.js +55 -39
- package/src/client/app/components/Init.svelte +12 -9
- package/src/client/app/helpers.js +42 -0
- package/src/client/app/hooks.js +20 -0
- package/src/client/app/inputs/Keyboard.js +13 -15
- package/src/client/app/inputs/MIDI.js +14 -15
- package/src/client/app/lib/canvas-recorder/CanvasRecorder.js +41 -21
- package/src/client/app/lib/gl/Renderer.js +127 -139
- package/src/client/app/modules/Exports.svelte +62 -43
- package/src/client/app/modules/MidiPanel.svelte +100 -101
- package/src/client/app/modules/Params.svelte +116 -103
- package/src/client/app/renderers/2DRenderer.js +3 -3
- package/src/client/app/renderers/FragmentRenderer.js +30 -23
- package/src/client/app/renderers/P5Renderer.js +10 -7
- package/src/client/app/renderers/THREERenderer.js +136 -94
- package/src/client/app/stores/exports.js +36 -20
- package/src/client/app/stores/props.js +28 -5
- package/src/client/app/stores/renderers.js +22 -15
- package/src/client/app/stores/sketches.js +7 -9
- package/src/client/app/stores/utils.js +95 -38
- package/src/client/app/triggers/Keyboard.js +88 -79
- package/src/client/app/triggers/MIDI.js +110 -84
- package/src/client/app/ui/Field.svelte +343 -240
- package/src/client/app/ui/FieldGroup.svelte +106 -94
- package/src/client/app/ui/FieldSection.svelte +125 -116
- package/src/client/app/ui/ParamsMultisampling.svelte +96 -95
- package/src/client/app/ui/ParamsOutput.svelte +113 -113
- package/src/client/app/ui/SelectChevrons.svelte +27 -15
- package/src/client/app/ui/SketchRenderer.svelte +761 -667
- package/src/client/app/ui/fields/ButtonInput.svelte +61 -48
- package/src/client/app/ui/fields/CheckboxInput.svelte +67 -61
- package/src/client/app/ui/fields/ColorInput.svelte +294 -238
- package/src/client/app/ui/fields/ImageInput.svelte +123 -121
- package/src/client/app/ui/fields/Input.svelte +100 -111
- package/src/client/app/ui/fields/ListInput.svelte +96 -96
- package/src/client/app/ui/fields/NumberInput.svelte +121 -116
- package/src/client/app/ui/fields/ProgressInput.svelte +80 -73
- package/src/client/app/ui/fields/Select.svelte +137 -124
- package/src/client/app/ui/fields/VectorInput.svelte +86 -82
- package/src/client/app/utils/canvas.utils.js +228 -201
- package/src/client/app/utils/file.utils.js +38 -34
- package/src/client/public/css/global.css +27 -21
- package/src/cli/plugins/hot-shader-reload.js +0 -86
|
@@ -1,95 +1,104 @@
|
|
|
1
|
-
import Trigger from
|
|
2
|
-
import Keyboard from
|
|
3
|
-
import { wildcard, getContext } from
|
|
4
|
-
import { addToMapArray, removeFromMapArray } from
|
|
1
|
+
import Trigger from './Trigger';
|
|
2
|
+
import Keyboard from '../inputs/Keyboard';
|
|
3
|
+
import { wildcard, getContext } from './shared';
|
|
4
|
+
import { addToMapArray, removeFromMapArray } from '../utils';
|
|
5
5
|
|
|
6
6
|
const pressedKeys = new Map();
|
|
7
7
|
const upKeys = new Map();
|
|
8
8
|
const downKeys = new Map();
|
|
9
9
|
|
|
10
10
|
export const removeHotListeners = (context) => {
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
11
|
+
function removeHotFrom(collection) {
|
|
12
|
+
for (let trigger of collection) {
|
|
13
|
+
const [key, triggers] = trigger;
|
|
14
|
+
|
|
15
|
+
collection.set(
|
|
16
|
+
key,
|
|
17
|
+
triggers.filter((trigger) => trigger.context !== context),
|
|
18
|
+
);
|
|
19
|
+
}
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
removeHotFrom(pressedKeys);
|
|
23
|
+
removeHotFrom(upKeys);
|
|
24
|
+
removeHotFrom(downKeys);
|
|
22
25
|
};
|
|
23
26
|
|
|
24
27
|
function createEventListener(collection) {
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
28
|
+
return (event) => {
|
|
29
|
+
const { key, target } = event;
|
|
30
|
+
|
|
31
|
+
if (!target.classList.contains('input')) {
|
|
32
|
+
const triggers = [
|
|
33
|
+
...(collection.has(key) ? collection.get(key) : []),
|
|
34
|
+
...(collection.has(wildcard) ? collection.get(wildcard) : []),
|
|
35
|
+
];
|
|
36
|
+
|
|
37
|
+
triggers.forEach((trigger) => {
|
|
38
|
+
if (!Keyboard.enabled) return;
|
|
39
|
+
|
|
40
|
+
trigger.run(event);
|
|
41
|
+
});
|
|
42
|
+
}
|
|
43
|
+
};
|
|
41
44
|
}
|
|
42
45
|
|
|
43
46
|
function createTrigger(eventName, collection) {
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
47
|
+
return (key, fn, options = {}) => {
|
|
48
|
+
if (typeof key === 'function') {
|
|
49
|
+
if (typeof fn === 'object') {
|
|
50
|
+
options = {
|
|
51
|
+
...options,
|
|
52
|
+
...fn,
|
|
53
|
+
};
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
fn = key;
|
|
57
|
+
key = '*';
|
|
58
|
+
|
|
59
|
+
if (options.key) {
|
|
60
|
+
key = options.key;
|
|
61
|
+
}
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
const { hot, enabled, ...params } = options;
|
|
65
|
+
const context = getContext();
|
|
66
|
+
|
|
67
|
+
const keys = Array.isArray(key)
|
|
68
|
+
? key
|
|
69
|
+
: [...`${key}`.split(',').map((k) => (k !== ' ' ? k.trim() : k))];
|
|
70
|
+
|
|
71
|
+
const trigger = new Trigger({
|
|
72
|
+
inputType: 'Keyboard',
|
|
73
|
+
eventName,
|
|
74
|
+
fn,
|
|
75
|
+
context,
|
|
76
|
+
params: { ...params, key: keys },
|
|
77
|
+
hot,
|
|
78
|
+
enabled,
|
|
79
|
+
destroy: () => {
|
|
80
|
+
keys.forEach((key) => {
|
|
81
|
+
removeFromMapArray(
|
|
82
|
+
collection,
|
|
83
|
+
key,
|
|
84
|
+
(item) => item.id === trigger.id,
|
|
85
|
+
);
|
|
86
|
+
});
|
|
87
|
+
},
|
|
88
|
+
});
|
|
89
|
+
|
|
90
|
+
keys.forEach((key) => {
|
|
91
|
+
addToMapArray(collection, key, trigger);
|
|
92
|
+
});
|
|
93
|
+
|
|
94
|
+
return trigger;
|
|
95
|
+
};
|
|
96
|
+
}
|
|
88
97
|
|
|
89
|
-
window.addEventListener(
|
|
90
|
-
window.addEventListener(
|
|
91
|
-
window.addEventListener(
|
|
98
|
+
window.addEventListener('keypress', createEventListener(pressedKeys));
|
|
99
|
+
window.addEventListener('keyup', createEventListener(upKeys));
|
|
100
|
+
window.addEventListener('keydown', createEventListener(downKeys));
|
|
92
101
|
|
|
93
102
|
export const onKeyPress = createTrigger('onKeyPress', pressedKeys);
|
|
94
|
-
export const onKeyDown = createTrigger('onKeyDown', downKeys);
|
|
103
|
+
export const onKeyDown = createTrigger('onKeyDown', downKeys);
|
|
95
104
|
export const onKeyUp = createTrigger('onKeyUp', upKeys);
|
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
import Trigger from
|
|
2
|
-
import MIDI from
|
|
3
|
-
import { addToMapArray, removeFromMapArray } from
|
|
4
|
-
import { wildcard, getContext } from
|
|
1
|
+
import Trigger from './Trigger';
|
|
2
|
+
import MIDI from '../inputs/MIDI.js';
|
|
3
|
+
import { addToMapArray, removeFromMapArray } from '../utils';
|
|
4
|
+
import { wildcard, getContext } from './shared';
|
|
5
5
|
|
|
6
6
|
const noteons = new Map();
|
|
7
7
|
const noteoffs = new Map();
|
|
@@ -11,33 +11,36 @@ const controlchanges = new Map();
|
|
|
11
11
|
|
|
12
12
|
/**
|
|
13
13
|
* Remove listeners from a specific context
|
|
14
|
-
* @param {string} context
|
|
14
|
+
* @param {string} context
|
|
15
15
|
*/
|
|
16
16
|
export const removeHotListeners = (context) => {
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
17
|
+
function removeHotFrom(collection) {
|
|
18
|
+
for (let trigger of collection) {
|
|
19
|
+
const [key, triggers] = trigger;
|
|
20
|
+
|
|
21
|
+
collection.set(
|
|
22
|
+
key,
|
|
23
|
+
triggers.filter((trigger) => trigger.context !== context),
|
|
24
|
+
);
|
|
25
|
+
}
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
removeHotFrom(noteons);
|
|
29
|
+
removeHotFrom(noteoffs);
|
|
30
|
+
removeHotFrom(numberons);
|
|
31
|
+
removeHotFrom(numberoffs);
|
|
32
|
+
removeHotFrom(controlchanges);
|
|
30
33
|
};
|
|
31
34
|
|
|
32
35
|
/**
|
|
33
36
|
* Check all registered listeners for a specific key
|
|
34
|
-
* @param {Map} collection
|
|
35
|
-
* @param {function} getKey
|
|
37
|
+
* @param {Map} collection
|
|
38
|
+
* @param {function} getKey
|
|
36
39
|
* @returns {function} listener
|
|
37
40
|
*/
|
|
38
41
|
function createEventListener(collection, getKey = (event) => event.key) {
|
|
39
|
-
|
|
40
|
-
|
|
42
|
+
return (event) => {
|
|
43
|
+
const key = getKey(event);
|
|
41
44
|
const { id } = event.srcElement;
|
|
42
45
|
|
|
43
46
|
const triggers = [
|
|
@@ -46,78 +49,101 @@ function createEventListener(collection, getKey = (event) => event.key) {
|
|
|
46
49
|
];
|
|
47
50
|
|
|
48
51
|
if (MIDI.enabled && id === MIDI.selectedInputID) {
|
|
49
|
-
triggers.forEach(trigger => {
|
|
52
|
+
triggers.forEach((trigger) => {
|
|
50
53
|
trigger.run(event);
|
|
51
54
|
});
|
|
52
55
|
}
|
|
53
|
-
|
|
56
|
+
};
|
|
54
57
|
}
|
|
55
58
|
|
|
56
59
|
/**
|
|
57
60
|
* Create a registering function for a specific event
|
|
58
|
-
* @param {string} eventName
|
|
59
|
-
* @param {Map} collection
|
|
60
|
-
* @returns {function} createListener
|
|
61
|
+
* @param {string} eventName
|
|
62
|
+
* @param {Map} collection
|
|
63
|
+
* @returns {function} createListener
|
|
61
64
|
*/
|
|
62
65
|
function createTrigger(eventName, collection) {
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
};
|
|
66
|
+
return (key, fn, options = {}) => {
|
|
67
|
+
if (typeof key === 'function') {
|
|
68
|
+
if (typeof fn === 'object') {
|
|
69
|
+
options = {
|
|
70
|
+
...options,
|
|
71
|
+
...fn,
|
|
72
|
+
};
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
fn = key;
|
|
76
|
+
key = '*';
|
|
77
|
+
|
|
78
|
+
if (options.key) {
|
|
79
|
+
key = options.key;
|
|
80
|
+
}
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
const { hot, enabled, ...params } = options;
|
|
84
|
+
let keys = Array.isArray(key)
|
|
85
|
+
? key
|
|
86
|
+
: [...`${key}`.split(',').map((k) => k.trim())];
|
|
87
|
+
|
|
88
|
+
if (
|
|
89
|
+
['onControlChange', 'onNumberOn', 'onNumberOff'].includes(eventName)
|
|
90
|
+
) {
|
|
91
|
+
keys = keys.map((k) => (!isNaN(Number(k)) ? Number(k) : k));
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
if (!MIDI.enabled) {
|
|
95
|
+
MIDI.request();
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
const context = getContext();
|
|
99
|
+
|
|
100
|
+
const trigger = new Trigger({
|
|
101
|
+
inputType: 'MIDI',
|
|
102
|
+
eventName,
|
|
103
|
+
fn,
|
|
104
|
+
params: { ...params, key: keys },
|
|
105
|
+
hot,
|
|
106
|
+
context,
|
|
107
|
+
enabled,
|
|
108
|
+
destroy: () => {
|
|
109
|
+
keys.forEach((key) => {
|
|
110
|
+
removeFromMapArray(
|
|
111
|
+
collection,
|
|
112
|
+
key,
|
|
113
|
+
(item) => item.id === trigger.id,
|
|
114
|
+
);
|
|
115
|
+
});
|
|
116
|
+
},
|
|
117
|
+
});
|
|
118
|
+
|
|
119
|
+
keys.forEach((k) => {
|
|
120
|
+
addToMapArray(collection, k, trigger);
|
|
121
|
+
});
|
|
122
|
+
|
|
123
|
+
return trigger;
|
|
124
|
+
};
|
|
125
|
+
}
|
|
115
126
|
|
|
116
|
-
MIDI.addEventListener(
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
MIDI.addEventListener(
|
|
127
|
+
MIDI.addEventListener(
|
|
128
|
+
'noteon',
|
|
129
|
+
createEventListener(noteons, (event) => event.note.name),
|
|
130
|
+
);
|
|
131
|
+
MIDI.addEventListener(
|
|
132
|
+
'noteoff',
|
|
133
|
+
createEventListener(noteoffs, (event) => event.note.name),
|
|
134
|
+
);
|
|
135
|
+
MIDI.addEventListener(
|
|
136
|
+
'noteon',
|
|
137
|
+
createEventListener(numberons, (event) => event.note.number),
|
|
138
|
+
);
|
|
139
|
+
MIDI.addEventListener(
|
|
140
|
+
'noteoff',
|
|
141
|
+
createEventListener(numberoffs, (event) => event.note.number),
|
|
142
|
+
);
|
|
143
|
+
MIDI.addEventListener(
|
|
144
|
+
'controlchange',
|
|
145
|
+
createEventListener(controlchanges, (event) => event.note.number),
|
|
146
|
+
);
|
|
121
147
|
|
|
122
148
|
export const onNoteOn = createTrigger('onNoteOn', noteons);
|
|
123
149
|
export const onNoteOff = createTrigger('onNoteOff', noteoffs);
|