fragment-tools 0.1.13 → 0.1.15

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 (184) hide show
  1. package/.prettierignore +1 -2
  2. package/.prettierrc +23 -7
  3. package/README.md +28 -9
  4. package/bin/index.js +70 -10
  5. package/package.json +14 -6
  6. package/src/cli/build.js +125 -0
  7. package/src/cli/create.js +238 -0
  8. package/src/cli/createConfig.js +82 -0
  9. package/src/cli/createFragmentFile.js +70 -0
  10. package/src/cli/getEntries.js +85 -0
  11. package/src/cli/log.js +36 -24
  12. package/src/cli/plugins/check-dependencies.js +88 -42
  13. package/src/cli/plugins/hot-shader-replacement.js +408 -0
  14. package/src/cli/plugins/hot-sketch-reload.js +21 -25
  15. package/src/cli/plugins/save.js +101 -0
  16. package/src/cli/preview.js +55 -0
  17. package/src/cli/prompts.js +260 -0
  18. package/src/cli/run.js +131 -0
  19. package/src/cli/templates/blank/index.js +33 -0
  20. package/src/cli/templates/blank/meta.json +4 -0
  21. package/src/cli/templates/default/index.js +39 -0
  22. package/src/cli/templates/default/meta.json +5 -0
  23. package/src/cli/templates/fragment-gl/index.js +37 -0
  24. package/src/cli/templates/fragment-gl/meta.json +4 -0
  25. package/src/cli/templates/p5/index.js +32 -0
  26. package/src/cli/templates/p5/meta.json +5 -0
  27. package/src/cli/templates/p5-webgl/fragment.fs +14 -0
  28. package/src/cli/templates/p5-webgl/index.js +67 -0
  29. package/src/cli/templates/p5-webgl/meta.json +5 -0
  30. package/src/cli/templates/three-fragment/fragment.fs +10 -0
  31. package/src/cli/templates/three-fragment/index.js +95 -0
  32. package/src/cli/templates/three-fragment/meta.json +5 -0
  33. package/src/cli/templates/three-orthographic/index.js +55 -0
  34. package/src/cli/templates/three-orthographic/meta.json +5 -0
  35. package/src/cli/templates/three-perspective/index.js +52 -0
  36. package/src/cli/templates/three-perspective/meta.json +5 -0
  37. package/src/cli/utils.js +70 -0
  38. package/src/cli/ws.js +87 -78
  39. package/src/client/app/App.svelte +3 -3
  40. package/src/client/app/client.js +55 -39
  41. package/src/client/app/components/IconCross.svelte +18 -18
  42. package/src/client/app/components/Init.svelte +40 -8
  43. package/src/client/app/components/KeyBinding.svelte +22 -22
  44. package/src/client/app/helpers.js +42 -0
  45. package/src/client/app/hooks.js +20 -0
  46. package/src/client/app/inputs/Input.js +9 -9
  47. package/src/client/app/inputs/Keyboard.js +13 -15
  48. package/src/client/app/inputs/MIDI.js +14 -15
  49. package/src/client/app/inputs/Mouse.js +1 -1
  50. package/src/client/app/inputs/Webcam.js +89 -88
  51. package/src/client/app/lib/canvas-recorder/CanvasRecorder.js +41 -21
  52. package/src/client/app/lib/canvas-recorder/FrameRecorder.js +7 -6
  53. package/src/client/app/lib/canvas-recorder/H264Recorder.js +45 -0
  54. package/src/client/app/lib/canvas-recorder/MP4Recorder.js +7 -9
  55. package/src/client/app/lib/canvas-recorder/WebMRecorder.js +3 -4
  56. package/src/client/app/lib/canvas-recorder/mp4.js +1649 -15
  57. package/src/client/app/lib/canvas-recorder/utils.js +33 -17
  58. package/src/client/app/lib/gl/Geometry.js +11 -8
  59. package/src/client/app/lib/gl/Program.js +38 -19
  60. package/src/client/app/lib/gl/Renderer.js +163 -156
  61. package/src/client/app/lib/gl/Texture.js +113 -85
  62. package/src/client/app/lib/gl/index.js +12 -12
  63. package/src/client/app/lib/gl/utils.js +1 -3
  64. package/src/client/app/lib/helpers/frameDebounce.js +30 -30
  65. package/src/client/app/lib/loader/index.js +10 -10
  66. package/src/client/app/lib/loader/loadImage.js +15 -15
  67. package/src/client/app/lib/loader/loadScript.js +1 -1
  68. package/src/client/app/lib/paper-sizes.js +75 -76
  69. package/src/client/app/lib/presets.js +25 -5
  70. package/src/client/app/lib/tempo/Analyser.js +18 -17
  71. package/src/client/app/lib/tempo/Range.js +15 -12
  72. package/src/client/app/lib/tempo/index.js +34 -27
  73. package/src/client/app/modules/AudioAnalyser/Range.svelte +69 -72
  74. package/src/client/app/modules/AudioAnalyser/Spectrum.svelte +20 -19
  75. package/src/client/app/modules/AudioAnalyser.svelte +52 -35
  76. package/src/client/app/modules/Console/ConsoleLine.svelte +193 -172
  77. package/src/client/app/modules/Console.svelte +76 -74
  78. package/src/client/app/modules/Exports.svelte +62 -43
  79. package/src/client/app/modules/MidiPanel.svelte +100 -101
  80. package/src/client/app/modules/Monitor.svelte +57 -57
  81. package/src/client/app/modules/Params.svelte +128 -103
  82. package/src/client/app/renderers/2DRenderer.js +3 -3
  83. package/src/client/app/renderers/FragmentRenderer.js +30 -23
  84. package/src/client/app/renderers/P5GLRenderer.js +144 -0
  85. package/src/client/app/renderers/P5Renderer.js +10 -7
  86. package/src/client/app/renderers/THREERenderer.js +136 -94
  87. package/src/client/app/stores/audioAnalysis.js +3 -4
  88. package/src/client/app/stores/console.js +9 -10
  89. package/src/client/app/stores/errors.js +1 -1
  90. package/src/client/app/stores/exports.js +36 -20
  91. package/src/client/app/stores/index.js +2 -2
  92. package/src/client/app/stores/layout.js +143 -138
  93. package/src/client/app/stores/multisampling.js +4 -4
  94. package/src/client/app/stores/props.js +76 -13
  95. package/src/client/app/stores/renderers.js +26 -15
  96. package/src/client/app/stores/rendering.js +108 -89
  97. package/src/client/app/stores/sketches.js +7 -9
  98. package/src/client/app/stores/time.js +18 -18
  99. package/src/client/app/stores/utils.js +95 -38
  100. package/src/client/app/transitions/fade.js +3 -3
  101. package/src/client/app/transitions/index.js +6 -7
  102. package/src/client/app/transitions/splitX.js +2 -2
  103. package/src/client/app/transitions/splitY.js +2 -2
  104. package/src/client/app/triggers/Keyboard.js +88 -79
  105. package/src/client/app/triggers/MIDI.js +110 -84
  106. package/src/client/app/triggers/Mouse.js +73 -65
  107. package/src/client/app/triggers/Trigger.js +59 -58
  108. package/src/client/app/triggers/index.js +7 -7
  109. package/src/client/app/triggers/shared.js +5 -5
  110. package/src/client/app/ui/Build.svelte +70 -71
  111. package/src/client/app/ui/ErrorOverlay.svelte +118 -104
  112. package/src/client/app/ui/Field.svelte +393 -258
  113. package/src/client/app/ui/FieldGroup.svelte +106 -94
  114. package/src/client/app/ui/FieldSection.svelte +127 -116
  115. package/src/client/app/ui/FieldSpace.svelte +29 -30
  116. package/src/client/app/ui/FieldTrigger.svelte +256 -244
  117. package/src/client/app/ui/FieldTriggers.svelte +46 -46
  118. package/src/client/app/ui/FloatingParams.svelte +29 -30
  119. package/src/client/app/ui/Layout.svelte +31 -32
  120. package/src/client/app/ui/LayoutColumn.svelte +4 -4
  121. package/src/client/app/ui/LayoutComponent.svelte +239 -225
  122. package/src/client/app/ui/LayoutResizer.svelte +195 -176
  123. package/src/client/app/ui/LayoutRoot.svelte +6 -6
  124. package/src/client/app/ui/LayoutRow.svelte +4 -4
  125. package/src/client/app/ui/LayoutToolbar.svelte +191 -194
  126. package/src/client/app/ui/Module.svelte +134 -135
  127. package/src/client/app/ui/ModuleHeaderAction.svelte +81 -78
  128. package/src/client/app/ui/ModuleHeaderButton.svelte +12 -12
  129. package/src/client/app/ui/ModuleHeaderSelect.svelte +47 -37
  130. package/src/client/app/ui/ModuleRenderer.svelte +26 -27
  131. package/src/client/app/ui/OutputRenderer.svelte +112 -105
  132. package/src/client/app/ui/ParamsMultisampling.svelte +96 -95
  133. package/src/client/app/ui/ParamsOutput.svelte +130 -113
  134. package/src/client/app/ui/Preview.svelte +7 -8
  135. package/src/client/app/ui/SelectChevrons.svelte +27 -15
  136. package/src/client/app/ui/SketchRenderer.svelte +780 -667
  137. package/src/client/app/ui/SketchSelect.svelte +50 -44
  138. package/src/client/app/ui/fields/ButtonInput.svelte +61 -48
  139. package/src/client/app/ui/fields/CheckboxInput.svelte +67 -61
  140. package/src/client/app/ui/fields/ColorInput.svelte +294 -238
  141. package/src/client/app/ui/fields/FieldInputRow.svelte +8 -8
  142. package/src/client/app/ui/fields/ImageInput.svelte +123 -121
  143. package/src/client/app/ui/fields/Input.svelte +100 -111
  144. package/src/client/app/ui/fields/IntervalInput.svelte +268 -0
  145. package/src/client/app/ui/fields/ListInput.svelte +96 -96
  146. package/src/client/app/ui/fields/NumberInput.svelte +120 -116
  147. package/src/client/app/ui/fields/ProgressInput.svelte +99 -73
  148. package/src/client/app/ui/fields/Select.svelte +137 -124
  149. package/src/client/app/ui/fields/TextInput.svelte +10 -11
  150. package/src/client/app/ui/fields/VectorInput.svelte +86 -82
  151. package/src/client/app/utils/canvas.utils.js +189 -208
  152. package/src/client/app/utils/color.utils.js +138 -101
  153. package/src/client/app/utils/fields.utils.js +131 -0
  154. package/src/client/app/utils/file.utils.js +209 -37
  155. package/src/client/app/utils/glsl.utils.js +2 -2
  156. package/src/client/app/utils/glslErrors.js +49 -31
  157. package/src/client/app/utils/index.js +32 -29
  158. package/src/client/app/utils/math.utils.js +14 -10
  159. package/src/client/index.html +16 -16
  160. package/src/client/main.js +4 -4
  161. package/src/client/public/css/global.css +26 -16
  162. package/src/cli/db.js +0 -17
  163. package/src/cli/index.js +0 -198
  164. package/src/cli/plugins/db.js +0 -12
  165. package/src/cli/plugins/hot-shader-reload.js +0 -86
  166. package/src/cli/plugins/screenshot.js +0 -46
  167. package/src/cli/server.js +0 -153
  168. package/src/cli/templates/2d.js +0 -15
  169. package/src/cli/templates/blank.js +0 -13
  170. package/src/cli/templates/fragment.js +0 -18
  171. package/src/cli/templates/index.js +0 -27
  172. package/src/cli/templates/p5.js +0 -13
  173. package/src/cli/templates/three-fragment.js +0 -53
  174. package/src/cli/templates/three-orthographic.js +0 -23
  175. package/src/cli/templates/three-perspective.js +0 -20
  176. package/src/client/app/lib/canvas-recorder/FFMPEGRecorder.js +0 -56
  177. package/src/client/app/utils/props.utils.js +0 -51
  178. package/src/client/public/fonts/Inter-Bold.woff2 +0 -0
  179. package/src/client/public/fonts/Inter-Italic.woff2 +0 -0
  180. package/src/client/public/fonts/Inter-Regular.woff2 +0 -0
  181. package/src/client/public/fonts/Inter-SemiBold.woff2 +0 -0
  182. package/src/client/public/js/ffmpeg.min.js +0 -2
  183. package/src/client/public/js/ffmpeg.min.js.map +0 -1
  184. /package/src/cli/templates/{fragment.fs → fragment-gl/fragment.fs} +0 -0
@@ -1,89 +1,106 @@
1
- import { writable } from "svelte/store";
2
- import { client } from "../client";
3
- import { createStore } from "./utils";
4
- import { getDimensionsForPreset } from "../lib/presets";
1
+ import { writable } from 'svelte/store';
2
+ import { client } from '../client';
3
+ import { createStore } from './utils';
4
+ import { PRESET_ORIENTATIONS, getDimensionsForPreset } from '../lib/presets';
5
5
 
6
6
  export const SIZES = {
7
- FIXED: "fixed",
8
- PRESET: "preset",
9
- ASPECT_RATIO: "aspect-ratio",
10
- WINDOW: "window",
11
- SCALE: "scale",
7
+ FIXED: 'fixed',
8
+ PRESET: 'preset',
9
+ ASPECT_RATIO: 'aspect-ratio',
10
+ WINDOW: 'window',
11
+ SCALE: 'scale',
12
12
  };
13
13
 
14
- export const rendering = createStore(`rendering`, {
15
- width: 1024,
16
- height: 1024,
17
- pixelRatio: 1,
18
- resizing: SIZES.FIXED,
19
- aspectRatio: 1,
20
- scale: 1,
21
- preset: 'a4',
22
- }, {
23
- persist: !__BUILD__,
24
- reset: false,
25
- });
14
+ export const rendering = createStore(
15
+ `rendering`,
16
+ {
17
+ width: 1024,
18
+ height: 1024,
19
+ pixelRatio: 1,
20
+ resizing: SIZES.FIXED,
21
+ aspectRatio: 1,
22
+ scale: 1,
23
+ preset: 'a4',
24
+ presetOrientation: PRESET_ORIENTATIONS.PORTRAIT,
25
+ },
26
+ {
27
+ persist: !__BUILD__,
28
+ reset: false,
29
+ },
30
+ );
26
31
 
27
32
  export const monitors = createStore('monitors', []);
28
33
  export const preview = createStore('preview', null);
29
34
 
30
35
  export const override = (config) => {
31
- const { canvasSize = SIZES.WINDOW } = config;
32
- const resizing = canvasSize;
33
-
34
- const overrides = {
35
- resizing,
36
- };
37
-
38
- if (config.dimensions && config.dimensions.length === 2) {
39
- const { dimensions } = config;
40
- overrides.width = dimensions[0];
41
- overrides.height = dimensions[1];
42
-
43
- if (!config.canvasSize) {
44
- overrides.resizing = SIZES.FIXED;
45
- }
46
- }
47
-
48
- if (resizing === SIZES.PRESET) {
49
- if (config.preset) {
50
- const [ width, height ] = getDimensionsForPreset(config.preset, { pixelsPerInch: 300 });
51
-
52
- overrides.width = width;
53
- overrides.height = height;
54
- } else {
55
- overrides.resizing = SIZES.WINDOW;
56
- console.warn(`Cannot apply canvasSize preset if 'preset' is not specified in config.`);
57
- }
58
- }
59
-
60
- if (resizing === SIZES.ASPECT_RATIO) {
61
- if (isNaN(config.aspectRatio)) {
62
- overrides.resizing = SIZES.WINDOW;
63
- console.warn(`Cannot apply canvasSize:"aspectRatio" if 'aspectRatio' is not specified in config.`);
64
- }
65
- }
66
-
67
- if (resizing === SIZES.SCALE) {
68
- if (!config.dimensions) {
69
- console.warn(`Cannot apply canvasSize:"scale" if no dimensions are specified.`);
70
- overrides.resizing = SIZES.WINDOW;
71
- }
72
-
73
- if (isNaN(config.scale)) {
74
- console.warn(`Cannot apply canvasSize:"scale" if 'scale' is not specified in config.`);
75
- overrides.resizing = SIZES.WINDOW;
76
- } else {
77
- overrides.scale = config.scale;
78
- }
79
- }
80
-
81
- if (config.pixelRatio) {
82
- const { pixelRatio } = config;
83
- overrides.pixelRatio = typeof pixelRatio === "function" ? pixelRatio() : pixelRatio;
84
- }
85
-
86
- rendering.update((curr) => ({...curr, ...overrides}));
36
+ const { canvasSize = SIZES.WINDOW } = config;
37
+ const resizing = canvasSize;
38
+
39
+ const overrides = {
40
+ resizing,
41
+ };
42
+
43
+ if (config.dimensions && config.dimensions.length === 2) {
44
+ const { dimensions } = config;
45
+ overrides.width = dimensions[0];
46
+ overrides.height = dimensions[1];
47
+
48
+ if (!config.canvasSize) {
49
+ overrides.resizing = SIZES.FIXED;
50
+ }
51
+ }
52
+
53
+ if (resizing === SIZES.PRESET) {
54
+ if (config.preset) {
55
+ const [width, height] = getDimensionsForPreset(config.preset, {
56
+ pixelsPerInch: 300,
57
+ orientation: config.presetOrientation,
58
+ });
59
+
60
+ overrides.width = width;
61
+ overrides.height = height;
62
+ } else {
63
+ overrides.resizing = SIZES.WINDOW;
64
+ console.warn(
65
+ `Cannot apply canvasSize preset if 'preset' is not specified in config.`,
66
+ );
67
+ }
68
+ }
69
+
70
+ if (resizing === SIZES.ASPECT_RATIO) {
71
+ if (isNaN(config.aspectRatio)) {
72
+ overrides.resizing = SIZES.WINDOW;
73
+ console.warn(
74
+ `Cannot apply canvasSize:"aspectRatio" if 'aspectRatio' is not specified in config.`,
75
+ );
76
+ }
77
+ }
78
+
79
+ if (resizing === SIZES.SCALE) {
80
+ if (!config.dimensions) {
81
+ console.warn(
82
+ `Cannot apply canvasSize:"scale" if no dimensions are specified.`,
83
+ );
84
+ overrides.resizing = SIZES.WINDOW;
85
+ }
86
+
87
+ if (isNaN(config.scale)) {
88
+ console.warn(
89
+ `Cannot apply canvasSize:"scale" if 'scale' is not specified in config.`,
90
+ );
91
+ overrides.resizing = SIZES.WINDOW;
92
+ } else {
93
+ overrides.scale = config.scale;
94
+ }
95
+ }
96
+
97
+ if (config.pixelRatio) {
98
+ const { pixelRatio } = config;
99
+ overrides.pixelRatio =
100
+ typeof pixelRatio === 'function' ? pixelRatio() : pixelRatio;
101
+ }
102
+
103
+ rendering.update((curr) => ({ ...curr, ...overrides }));
87
104
  };
88
105
 
89
106
  /* sync across clients */
@@ -92,18 +109,20 @@ let isSynchronized = false;
92
109
  export const sync = writable(isSynchronized);
93
110
 
94
111
  function checkForSync({ clientCount } = {}) {
95
- let prev = isSynchronized;
96
- isSynchronized = clientCount > 0;
97
-
98
- if (prev && !isSynchronized) {
99
- console.warn("[fragment] Sketch is running at specified framerate.");
100
- } else if (!prev && isSynchronized) {
101
- console.warn("[fragment] Multiple instances of Fragment detected. Running sketch(s) at simulated framerate.");
102
- }
103
-
104
- if (prev !== isSynchronized) {
105
- sync.set(isSynchronized);
106
- }
112
+ let prev = isSynchronized;
113
+ isSynchronized = clientCount > 0;
114
+
115
+ if (prev && !isSynchronized) {
116
+ console.warn('[fragment] Sketch is running at specified framerate.');
117
+ } else if (!prev && isSynchronized) {
118
+ console.warn(
119
+ '[fragment] Multiple instances of Fragment detected. Running sketch(s) at simulated framerate.',
120
+ );
121
+ }
122
+
123
+ if (prev !== isSynchronized) {
124
+ sync.set(isSynchronized);
125
+ }
107
126
  }
108
127
 
109
128
  client.on('start', checkForSync);
@@ -1,6 +1,6 @@
1
- import { createStore } from "./utils.js";
2
- import { displayError } from "../stores/errors";
3
- import { sketches as all, onSketchReload } from "@fragment/sketches";
1
+ import { createStore } from './utils.js';
2
+ import { displayError } from '../stores/errors';
3
+ import { sketches as all } from '@fragment/sketches';
4
4
 
5
5
  export const sketches = createStore('sketches', {});
6
6
  export const sketchesKeys = createStore('sketchesKeys', Object.keys(all));
@@ -16,9 +16,11 @@ async function loadSketch(collection, key) {
16
16
  }
17
17
  }
18
18
 
19
- async function loadAll(collection) {
19
+ export async function loadAll(collection) {
20
20
  const keys = [...Object.keys(collection)];
21
- const loadedSketches = await Promise.all(keys.map((key) => loadSketch(collection, key)));
21
+ const loadedSketches = await Promise.all(
22
+ keys.map((key) => loadSketch(collection, key)),
23
+ );
22
24
 
23
25
  const newSketches = keys.reduce((all, key, index) => {
24
26
  if (loadedSketches[index]) {
@@ -34,7 +36,3 @@ async function loadAll(collection) {
34
36
  }
35
37
 
36
38
  loadAll(all);
37
-
38
- onSketchReload(({ sketches }) => {
39
- loadAll(sketches);
40
- });
@@ -1,27 +1,27 @@
1
- import { readable } from "svelte/store";
1
+ import { readable } from 'svelte/store';
2
2
 
3
- export const current = readable({ time: 0, deltaTime: 0 }, set => {
4
- let _raf;
5
- let lastTime = performance.now();
6
- let startTime = lastTime - __START_TIME__;
7
- let time = startTime;
3
+ export const current = readable({ time: 0, deltaTime: 0 }, (set) => {
4
+ let _raf;
5
+ let lastTime = performance.now();
6
+ let startTime = lastTime - __START_TIME__;
7
+ let time = startTime;
8
8
 
9
- function update(dt = 0) {
10
- lastTime = time;
9
+ function update(dt = 0) {
10
+ lastTime = time;
11
11
 
12
- let currentTime = performance.now();
13
- let deltaTime = currentTime - lastTime;
12
+ let currentTime = performance.now();
13
+ let deltaTime = currentTime - lastTime;
14
14
 
15
- time = currentTime;
15
+ time = currentTime;
16
16
 
17
- set({ time, deltaTime, startTime });
17
+ set({ time, deltaTime, startTime });
18
18
 
19
- _raf = requestAnimationFrame(update)
20
- }
19
+ _raf = requestAnimationFrame(update);
20
+ }
21
21
 
22
- update();
22
+ update();
23
23
 
24
- return () => {
25
- cancelAnimationFrame(_raf);
26
- }
24
+ return () => {
25
+ cancelAnimationFrame(_raf);
26
+ };
27
27
  });
@@ -1,66 +1,123 @@
1
- import { writable } from "svelte/store";
1
+ import { writable } from 'svelte/store';
2
+ import { getContext } from '../triggers/shared';
2
3
 
3
4
  let stores = new Map();
4
5
 
5
6
  /**
6
7
  * Returns the value stored in localStorage for key or return defaultValue if it doesn't exist
7
- * @param {string} key
8
- * @param {any} defaultValue
9
- * @param {boolean} override
8
+ * @param {string} key
9
+ * @param {any} defaultValue
10
+ * @param {boolean} override
10
11
  * @returns {any} result
11
12
  */
12
13
  export function rehydrate(key, defaultValue) {
13
- const storedValue = localStorage.getItem(`fragment.${key}`);
14
+ const storedValue = localStorage.getItem(`fragment.${key}`);
14
15
 
15
- if (storedValue) {
16
- return typeof storedValue === "string" ? JSON.parse(storedValue) : storedValue;
17
- }
16
+ if (storedValue) {
17
+ return typeof storedValue === 'string'
18
+ ? JSON.parse(storedValue)
19
+ : storedValue;
20
+ }
18
21
 
19
- return defaultValue;
20
- };
22
+ return defaultValue;
23
+ }
21
24
 
22
25
  /**
23
26
  * Save value in localStorage
24
- * @param {string} key
25
- * @param {any} value
27
+ * @param {string} key
28
+ * @param {any} value
26
29
  */
27
30
  export function save(key, value) {
28
- localStorage.setItem(`fragment.${key}`, JSON.stringify(value));
29
- };
31
+ localStorage.setItem(`fragment.${key}`, JSON.stringify(value));
32
+ }
30
33
 
31
34
  /**
32
35
  * Create store and register it for later usage
33
- * @param {string} key
34
- * @param {any} initialValue
36
+ * @param {string} key
37
+ * @param {any} initialValue
35
38
  * @param {object} options
36
- * @returns {object} store
39
+ * @returns {import('svelte/store').Writable} store
37
40
  */
38
- export function createStore(key, initialValue, { persist = false, reset = false } = {}) {
39
- const value = (persist && !reset) ? rehydrate(key, initialValue) : initialValue;
40
- const store = writable(value);
41
+ export function createStore(
42
+ key,
43
+ initialValue,
44
+ { persist = false, reset = false } = {},
45
+ ) {
46
+ const value =
47
+ persist && !reset ? rehydrate(key, initialValue) : initialValue;
48
+ const store = writable(value);
41
49
 
42
- if (persist) {
43
- store.subscribe((current) => {
44
- save(key, current);
45
- });
46
- }
47
-
48
- stores.set(key, store);
50
+ if (persist) {
51
+ store.subscribe((current) => {
52
+ save(key, current);
53
+ });
54
+ }
49
55
 
50
- return store;
51
- };
56
+ stores.set(key, store);
57
+
58
+ return store;
59
+ }
52
60
 
53
61
  /**
54
62
  * Get an existing store from key or create it if it doesn't exist yet
55
- * @param {string} key
56
- * @param {any} initialValue
63
+ * @param {string} key
64
+ * @param {any} initialValue
57
65
  * @param {object} options
58
- * @returns {object} store
66
+ * @returns {import('svelte/store').Writable} store
59
67
  */
60
- export function getStore(key, initialValue, { persist = false, reset = false } = {}) {
61
- if (!stores.has(key)) {
62
- return createStore(key, initialValue, { persist, reset });
63
- }
68
+ export function getStore(
69
+ key,
70
+ initialValue,
71
+ { persist = false, reset = false } = {},
72
+ ) {
73
+ if (!stores.has(key)) {
74
+ return createStore(key, initialValue, { persist, reset });
75
+ }
76
+
77
+ return stores.get(key);
78
+ }
79
+
80
+ /**
81
+ * Create a new store to register callbacks grouped by context
82
+ * @param {string} name
83
+ */
84
+ export function createHookStore(name) {
85
+ const store = writable(new Map());
86
+
87
+ const hook = (fn, { context = getContext() } = {}) => {
88
+ if (typeof fn !== 'function') {
89
+ console.warn(`${name} argument must be a function.`);
90
+ }
91
+
92
+ store.update((hooks) => {
93
+ if (!hooks.has(context)) {
94
+ hooks.set(context, []);
95
+ }
96
+
97
+ hooks.set(context, [...hooks.get(context), fn]);
98
+
99
+ return hooks;
100
+ });
101
+
102
+ return () => {
103
+ store.update((hooks) => {
104
+ hooks.set(
105
+ context,
106
+ [...hooks.get(context)].filter((hook) => hook !== fn),
107
+ );
108
+
109
+ return hooks;
110
+ });
111
+ };
112
+ };
113
+
114
+ const remove = (context) => {
115
+ store.update((hooks) => {
116
+ hooks.delete(context);
117
+
118
+ return hooks;
119
+ });
120
+ };
64
121
 
65
- return stores.get(key);
66
- };
122
+ return [store, hook, remove];
123
+ }
@@ -1,8 +1,8 @@
1
- export let name = "Fade";
1
+ export let name = 'Fade';
2
2
 
3
3
  export let props = {};
4
4
 
5
- export let fragmentShader = /* glsl */`
5
+ export let fragmentShader = /* glsl */ `
6
6
  precision highp float;
7
7
 
8
8
  uniform sampler2D uSampler0;
@@ -14,4 +14,4 @@ varying vec2 vUv;
14
14
  void main() {
15
15
  gl_FragColor = mix(texture2D(uSampler0, vUv), texture2D(uSampler1, vUv), threshold);
16
16
  }
17
- `;
17
+ `;
@@ -1,12 +1,11 @@
1
-
2
1
  // This file is generated by Fragment. Do not edit it.
3
2
 
4
- import * as transition0 from "./fade.js";
5
- import * as transition1 from "./splitX.js";
6
- import * as transition2 from "./splitY.js";
3
+ import * as transition0 from './fade.js';
4
+ import * as transition1 from './splitX.js';
5
+ import * as transition2 from './splitY.js';
7
6
 
8
7
  export const transitions = {
9
- "fade.js": transition0,
10
- "splitX.js": transition1,
11
- "splitY.js": transition2,
8
+ 'fade.js': transition0,
9
+ 'splitX.js': transition1,
10
+ 'splitY.js': transition2,
12
11
  };
@@ -1,7 +1,7 @@
1
- export let name = "SplitX";
1
+ export let name = 'SplitX';
2
2
  export let props = {};
3
3
 
4
- export let fragmentShader = /* glsl */`
4
+ export let fragmentShader = /* glsl */ `
5
5
  precision highp float;
6
6
 
7
7
  uniform float threshold;
@@ -1,7 +1,7 @@
1
- export let name = "SplitY";
1
+ export let name = 'SplitY';
2
2
  export let props = {};
3
3
 
4
- export let fragmentShader = /* glsl */`
4
+ export let fragmentShader = /* glsl */ `
5
5
  precision highp float;
6
6
 
7
7
  uniform float threshold;