@prtcl/plonk-hooks 1.1.1 → 1.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/dist/index.cjs CHANGED
@@ -21,21 +21,49 @@ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: tru
21
21
  // src/index.ts
22
22
  var index_exports = {};
23
23
  __export(index_exports, {
24
+ useDrunk: () => useDrunk,
25
+ useEnv: () => useEnv,
26
+ useFold: () => useFold,
24
27
  useFrames: () => useFrames,
25
28
  useMetro: () => useMetro,
26
- usePrevious: () => usePrevious
29
+ usePrevious: () => usePrevious,
30
+ useRand: () => useRand,
31
+ useScale: () => useScale,
32
+ useSine: () => useSine,
33
+ useWrap: () => useWrap
27
34
  });
28
35
  module.exports = __toCommonJS(index_exports);
29
36
  var import_client_only = require("client-only");
30
37
 
31
- // src/useFrames.ts
32
- var import_react2 = require("react");
38
+ // src/useDrunk.ts
39
+ var import_react = require("react");
33
40
  var import_plonk = require("@prtcl/plonk");
41
+ var useDrunk = (opts) => {
42
+ return (0, import_react.useMemo)(() => new import_plonk.Drunk(opts), []);
43
+ };
44
+
45
+ // src/useEnv.ts
46
+ var import_react2 = require("react");
47
+ var import_plonk2 = require("@prtcl/plonk");
48
+ var useEnv = (opts) => {
49
+ return (0, import_react2.useMemo)(() => new import_plonk2.Env(opts), []);
50
+ };
51
+
52
+ // src/useFold.ts
53
+ var import_react3 = require("react");
54
+ var import_plonk3 = require("@prtcl/plonk");
55
+ var useFold = (opts) => {
56
+ return (0, import_react3.useMemo)(() => new import_plonk3.Fold(opts), []);
57
+ };
58
+
59
+ // src/useFrames.ts
60
+ var import_react5 = require("react");
61
+ var import_plonk4 = require("@prtcl/plonk");
34
62
 
35
63
  // src/usePrevious.ts
36
- var import_react = require("react");
64
+ var import_react4 = require("react");
37
65
  var usePrevious = (value) => {
38
- const ref = (0, import_react.useRef)({
66
+ const ref = (0, import_react4.useRef)({
39
67
  value,
40
68
  prev: void 0
41
69
  });
@@ -52,21 +80,21 @@ var usePrevious = (value) => {
52
80
  // src/useFrames.ts
53
81
  var useFrames = (callback, opts) => {
54
82
  const { autostart = true } = opts || {};
55
- const callbackRef = (0, import_react2.useRef)(callback);
56
- const optsRef = (0, import_react2.useRef)(opts);
83
+ const callbackRef = (0, import_react5.useRef)(callback);
84
+ const optsRef = (0, import_react5.useRef)(opts);
57
85
  const prevOpts = usePrevious(opts);
58
86
  callbackRef.current = callback;
59
- const frames = (0, import_react2.useMemo)(() => {
60
- return new import_plonk.Frames((m) => {
87
+ const frames = (0, import_react5.useMemo)(() => {
88
+ return new import_plonk4.Frames((m) => {
61
89
  callbackRef.current(m);
62
90
  }, optsRef.current);
63
91
  }, []);
64
- (0, import_react2.useEffect)(() => {
92
+ (0, import_react5.useEffect)(() => {
65
93
  if (opts && prevOpts && opts.fps !== prevOpts.fps) {
66
94
  frames.setFPS(opts.fps);
67
95
  }
68
96
  }, [opts, prevOpts, frames]);
69
- (0, import_react2.useEffect)(() => {
97
+ (0, import_react5.useEffect)(() => {
70
98
  if (autostart) {
71
99
  frames.run();
72
100
  }
@@ -78,25 +106,25 @@ var useFrames = (callback, opts) => {
78
106
  };
79
107
 
80
108
  // src/useMetro.ts
81
- var import_react3 = require("react");
82
- var import_plonk2 = require("@prtcl/plonk");
109
+ var import_react6 = require("react");
110
+ var import_plonk5 = require("@prtcl/plonk");
83
111
  var useMetro = (callback, opts) => {
84
112
  const { autostart = true } = opts || {};
85
- const callbackRef = (0, import_react3.useRef)(callback);
86
- const optsRef = (0, import_react3.useRef)(opts);
113
+ const callbackRef = (0, import_react6.useRef)(callback);
114
+ const optsRef = (0, import_react6.useRef)(opts);
87
115
  const prevOpts = usePrevious(opts);
88
116
  callbackRef.current = callback;
89
- const metro = (0, import_react3.useMemo)(() => {
90
- return new import_plonk2.Metro((m) => {
117
+ const metro = (0, import_react6.useMemo)(() => {
118
+ return new import_plonk5.Metro((m) => {
91
119
  callbackRef.current(m);
92
120
  }, optsRef.current);
93
121
  }, []);
94
- (0, import_react3.useEffect)(() => {
122
+ (0, import_react6.useEffect)(() => {
95
123
  if (opts && prevOpts && opts.time !== prevOpts.time) {
96
124
  metro.setTime(opts.time);
97
125
  }
98
126
  }, [opts, prevOpts, metro]);
99
- (0, import_react3.useEffect)(() => {
127
+ (0, import_react6.useEffect)(() => {
100
128
  if (autostart) {
101
129
  metro.run();
102
130
  }
@@ -106,10 +134,45 @@ var useMetro = (callback, opts) => {
106
134
  }, [metro]);
107
135
  return metro;
108
136
  };
137
+
138
+ // src/useRand.ts
139
+ var import_react7 = require("react");
140
+ var import_plonk6 = require("@prtcl/plonk");
141
+ var useRand = (opts) => {
142
+ return (0, import_react7.useMemo)(() => new import_plonk6.Rand(opts), []);
143
+ };
144
+
145
+ // src/useScale.ts
146
+ var import_react8 = require("react");
147
+ var import_plonk7 = require("@prtcl/plonk");
148
+ var useScale = (opts) => {
149
+ return (0, import_react8.useMemo)(() => new import_plonk7.Scale(opts), []);
150
+ };
151
+
152
+ // src/useSine.ts
153
+ var import_react9 = require("react");
154
+ var import_plonk8 = require("@prtcl/plonk");
155
+ var useSine = (opts) => {
156
+ return (0, import_react9.useMemo)(() => new import_plonk8.Sine(opts), []);
157
+ };
158
+
159
+ // src/useWrap.ts
160
+ var import_react10 = require("react");
161
+ var import_plonk9 = require("@prtcl/plonk");
162
+ var useWrap = (opts) => {
163
+ return (0, import_react10.useMemo)(() => new import_plonk9.Wrap(opts), []);
164
+ };
109
165
  // Annotate the CommonJS export names for ESM import in node:
110
166
  0 && (module.exports = {
167
+ useDrunk,
168
+ useEnv,
169
+ useFold,
111
170
  useFrames,
112
171
  useMetro,
113
- usePrevious
172
+ usePrevious,
173
+ useRand,
174
+ useScale,
175
+ useSine,
176
+ useWrap
114
177
  });
115
178
  //# sourceMappingURL=index.cjs.map
@@ -1 +1 @@
1
- {"version":3,"sources":["../src/index.ts","../src/useFrames.ts","../src/usePrevious.ts","../src/useMetro.ts"],"sourcesContent":["'use client';\n\nimport 'client-only';\n\nexport { useFrames, type UseFramesOptions } from './useFrames';\nexport { useMetro, type UseMetroOptions } from './useMetro';\nexport { usePrevious } from './usePrevious';\n","import { useEffect, useMemo, useRef } from 'react';\nimport { Frames, type FramesOptions, type TimerCallback } from '@prtcl/plonk';\nimport { usePrevious } from './usePrevious';\n\nexport type UseFramesOptions = FramesOptions & {\n autostart?: boolean;\n};\n\n/**\n * Hook wrapper for Frames, autostart begins on mount and stops on unmount.\n * @param callback - {@link TimerCallback} called on each frame tick.\n * @param opts - {@link UseFramesOptions} for configuring frame rate and autostart.\n * @returns The underlying Frames instance.\n */\nexport const useFrames = (callback: TimerCallback<Frames>, opts?: UseFramesOptions) => {\n const { autostart = true } = opts || {};\n const callbackRef = useRef<TimerCallback<Frames>>(callback);\n const optsRef = useRef<UseFramesOptions | undefined>(opts);\n const prevOpts = usePrevious(opts);\n\n callbackRef.current = callback;\n\n const frames = useMemo<Frames>(() => {\n return new Frames((m) => {\n callbackRef.current(m);\n }, optsRef.current);\n }, []);\n\n useEffect(() => {\n if (opts && prevOpts && opts.fps !== prevOpts.fps) {\n frames.setFPS(opts.fps);\n }\n }, [opts, prevOpts, frames]);\n\n useEffect(() => {\n if (autostart) {\n frames.run();\n }\n\n return () => {\n frames.stop();\n };\n }, [frames]);\n\n return frames;\n};\n","import { useRef } from 'react';\n\ntype ValueCache<Value> = {\n value: Value;\n prev: Value | undefined;\n};\n\n/**\n * Returns the previous value of a variable without causing additional renders.\n * @param value - The current value to track.\n * @returns The value from the previous render, or undefined on the first render.\n */\nexport const usePrevious = <Value>(value: Value): Value | undefined => {\n const ref = useRef<ValueCache<Value>>({\n value,\n prev: undefined,\n });\n\n const current = ref.current.value;\n\n if (value !== current) {\n ref.current = {\n value,\n prev: current,\n };\n }\n\n return ref.current.prev;\n};\n","import { useEffect, useMemo, useRef } from 'react';\nimport { Metro, type MetroOptions, type TimerCallback } from '@prtcl/plonk';\nimport { usePrevious } from './usePrevious';\n\nexport type UseMetroOptions = MetroOptions & {\n autostart?: boolean;\n};\n\n/**\n * Hook wrapper for Metro, autostart begins on mount and stops on unmount.\n * @param callback - {@link TimerCallback} called on each tick.\n * @param opts - {@link UseMetroOptions} for configuring the timer and autostart.\n * @returns The underlying Metro instance.\n */\nexport const useMetro = (callback: TimerCallback<Metro>, opts?: UseMetroOptions) => {\n const { autostart = true } = opts || {};\n const callbackRef = useRef<TimerCallback<Metro>>(callback);\n const optsRef = useRef<UseMetroOptions | undefined>(opts);\n const prevOpts = usePrevious(opts);\n\n callbackRef.current = callback;\n\n const metro = useMemo<Metro>(() => {\n return new Metro((m) => {\n callbackRef.current(m);\n }, optsRef.current);\n }, []);\n\n useEffect(() => {\n if (opts && prevOpts && opts.time !== prevOpts.time) {\n metro.setTime(opts.time);\n }\n }, [opts, prevOpts, metro]);\n\n useEffect(() => {\n if (autostart) {\n metro.run();\n }\n\n return () => {\n metro.stop();\n };\n }, [metro]);\n\n return metro;\n};\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAEA,yBAAO;;;ACFP,IAAAA,gBAA2C;AAC3C,mBAA+D;;;ACD/D,mBAAuB;AAYhB,IAAM,cAAc,CAAQ,UAAoC;AACrE,QAAM,UAAM,qBAA0B;AAAA,IACpC;AAAA,IACA,MAAM;AAAA,EACR,CAAC;AAED,QAAM,UAAU,IAAI,QAAQ;AAE5B,MAAI,UAAU,SAAS;AACrB,QAAI,UAAU;AAAA,MACZ;AAAA,MACA,MAAM;AAAA,IACR;AAAA,EACF;AAEA,SAAO,IAAI,QAAQ;AACrB;;;ADdO,IAAM,YAAY,CAAC,UAAiC,SAA4B;AACrF,QAAM,EAAE,YAAY,KAAK,IAAI,QAAQ,CAAC;AACtC,QAAM,kBAAc,sBAA8B,QAAQ;AAC1D,QAAM,cAAU,sBAAqC,IAAI;AACzD,QAAM,WAAW,YAAY,IAAI;AAEjC,cAAY,UAAU;AAEtB,QA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{"version":3,"sources":["../src/index.ts","../src/useDrunk.ts","../src/useEnv.ts","../src/useFold.ts","../src/useFrames.ts","../src/usePrevious.ts","../src/useMetro.ts","../src/useRand.ts","../src/useScale.ts","../src/useSine.ts","../src/useWrap.ts"],"sourcesContent":["'use client';\n\nimport 'client-only';\n\nexport { useDrunk } from './useDrunk';\nexport { useEnv } from './useEnv';\nexport { useFold } from './useFold';\nexport { useFrames, type UseFramesOptions } from './useFrames';\nexport { useMetro, type UseMetroOptions } from './useMetro';\nexport { usePrevious } from './usePrevious';\nexport { useRand } from './useRand';\nexport { useScale } from './useScale';\nexport { useSine } from './useSine';\nexport { useWrap } from './useWrap';\n","import { useMemo } from 'react';\nimport { Drunk, type DrunkOptions } from '@prtcl/plonk';\n\n/**\n * Hook wrapper for Drunk, instantiates a Drunk generator on mount.\n * @param opts - {@link DrunkOptions} for configuring the random walk.\n * @returns The underlying Drunk instance.\n */\nexport const useDrunk = (opts?: DrunkOptions) => {\n return useMemo(() => new Drunk(opts), []);\n};\n","import { useMemo } from 'react';\nimport { Env, type EnvOptions } from '@prtcl/plonk';\n\n/**\n * Hook wrapper for Env, instantiates an Env generator on mount.\n * @param opts - {@link EnvOptions} for configuring the envelope.\n * @returns The underlying Env instance.\n */\nexport const useEnv = (opts: EnvOptions) => {\n return useMemo(() => new Env(opts), []);\n};\n","import { useMemo } from 'react';\nimport { Fold, type FoldOptions } from '@prtcl/plonk';\n\n/**\n * Hook wrapper for Fold, instantiates a Fold transformer on mount.\n * @param opts - {@link FoldOptions} for configuring the range.\n * @returns The underlying Fold instance.\n */\nexport const useFold = (opts?: FoldOptions) => {\n return useMemo(() => new Fold(opts), []);\n};\n","import { useEffect, useMemo, useRef } from 'react';\nimport { Frames, type FramesOptions, type TimerCallback } from '@prtcl/plonk';\nimport { usePrevious } from './usePrevious';\n\nexport type UseFramesOptions = FramesOptions & {\n autostart?: boolean;\n};\n\n/**\n * Hook wrapper for Frames, autostart begins on mount and stops on unmount.\n * @param callback - {@link TimerCallback} called on each frame tick.\n * @param opts - {@link UseFramesOptions} for configuring frame rate and autostart.\n * @returns The underlying Frames instance.\n */\nexport const useFrames = (callback: TimerCallback<Frames>, opts?: UseFramesOptions) => {\n const { autostart = true } = opts || {};\n const callbackRef = useRef<TimerCallback<Frames>>(callback);\n const optsRef = useRef<UseFramesOptions | undefined>(opts);\n const prevOpts = usePrevious(opts);\n\n callbackRef.current = callback;\n\n const frames = useMemo<Frames>(() => {\n return new Frames((m) => {\n callbackRef.current(m);\n }, optsRef.current);\n }, []);\n\n useEffect(() => {\n if (opts && prevOpts && opts.fps !== prevOpts.fps) {\n frames.setFPS(opts.fps);\n }\n }, [opts, prevOpts, frames]);\n\n useEffect(() => {\n if (autostart) {\n frames.run();\n }\n\n return () => {\n frames.stop();\n };\n }, [frames]);\n\n return frames;\n};\n","import { useRef } from 'react';\n\ntype ValueCache<Value> = {\n value: Value;\n prev: Value | undefined;\n};\n\n/**\n * Returns the previous value of a variable without causing additional renders.\n * @param value - The current value to track.\n * @returns The value from the previous render, or undefined on the first render.\n */\nexport const usePrevious = <Value>(value: Value): Value | undefined => {\n const ref = useRef<ValueCache<Value>>({\n value,\n prev: undefined,\n });\n\n const current = ref.current.value;\n\n if (value !== current) {\n ref.current = {\n value,\n prev: current,\n };\n }\n\n return ref.current.prev;\n};\n","import { useEffect, useMemo, useRef } from 'react';\nimport { Metro, type MetroOptions, type TimerCallback } from '@prtcl/plonk';\nimport { usePrevious } from './usePrevious';\n\nexport type UseMetroOptions = MetroOptions & {\n autostart?: boolean;\n};\n\n/**\n * Hook wrapper for Metro, autostart begins on mount and stops on unmount.\n * @param callback - {@link TimerCallback} called on each tick.\n * @param opts - {@link UseMetroOptions} for configuring the timer and autostart.\n * @returns The underlying Metro instance.\n */\nexport const useMetro = (callback: TimerCallback<Metro>, opts?: UseMetroOptions) => {\n const { autostart = true } = opts || {};\n const callbackRef = useRef<TimerCallback<Metro>>(callback);\n const optsRef = useRef<UseMetroOptions | undefined>(opts);\n const prevOpts = usePrevious(opts);\n\n callbackRef.current = callback;\n\n const metro = useMemo<Metro>(() => {\n return new Metro((m) => {\n callbackRef.current(m);\n }, optsRef.current);\n }, []);\n\n useEffect(() => {\n if (opts && prevOpts && opts.time !== prevOpts.time) {\n metro.setTime(opts.time);\n }\n }, [opts, prevOpts, metro]);\n\n useEffect(() => {\n if (autostart) {\n metro.run();\n }\n\n return () => {\n metro.stop();\n };\n }, [metro]);\n\n return metro;\n};\n","import { useMemo } from 'react';\nimport { Rand, type RandOptions } from '@prtcl/plonk';\n\n/**\n * Hook wrapper for Rand, instantiates a Rand generator on mount.\n * @param opts - {@link RandOptions} for configuring the random range.\n * @returns The underlying Rand instance.\n */\nexport const useRand = (opts?: RandOptions) => {\n return useMemo(() => new Rand(opts), []);\n};\n","import { useMemo } from 'react';\nimport { Scale, type ScaleOptions } from '@prtcl/plonk';\n\n/**\n * Hook wrapper for Scale, instantiates a Scale mapper on mount.\n * @param opts - {@link ScaleOptions} for configuring the input/output ranges.\n * @returns The underlying Scale instance.\n */\nexport const useScale = (opts?: ScaleOptions) => {\n return useMemo(() => new Scale(opts), []);\n};\n","import { useMemo } from 'react';\nimport { Sine, type SineOptions } from '@prtcl/plonk';\n\n/**\n * Hook wrapper for Sine, instantiates a Sine oscillator on mount.\n * @param opts - {@link SineOptions} for configuring the oscillator.\n * @returns The underlying Sine instance.\n */\nexport const useSine = (opts: SineOptions) => {\n return useMemo(() => new Sine(opts), []);\n};\n","import { useMemo } from 'react';\nimport { Wrap, type WrapOptions } from '@prtcl/plonk';\n\n/**\n * Hook wrapper for Wrap, instantiates a Wrap transformer on mount.\n * @param opts - {@link WrapOptions} for configuring the range.\n * @returns The underlying Wrap instance.\n */\nexport const useWrap = (opts?: WrapOptions) => {\n return useMemo(() => new Wrap(opts), []);\n};\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAA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,IAAI,oBAAM,IAAI,GAAG,CAAC,CAAC;AAC1C;;;ACVA,IAAAC,gBAAwB;AACxB,IAAAC,gBAAuC;AAOhC,IAAM,UAAU,CAAC,SAAsB;AAC5C,aAAO,uBAAQ,MAAM,IAAI,mBAAK,IAAI,GAAG,CAAC,CAAC;AACzC;;;ACVA,IAAAC,iBAAwB;AACxB,IAAAC,gBAAuC;AAOhC,IAAM,UAAU,CAAC,SAAuB;AAC7C,aAAO,wBAAQ,MAAM,IAAI,mBAAK,IAAI,GAAG,CAAC,CAAC;AACzC;","names":["import_react","import_plonk","import_react","import_plonk","import_react","import_plonk","import_react","import_react","import_plonk","import_react","import_plonk","import_react","import_plonk","import_react","import_plonk","import_react","import_plonk"]}
package/dist/index.d.cts CHANGED
@@ -1,4 +1,25 @@
1
- import { FramesOptions, TimerCallback, Frames, MetroOptions, Metro } from '@prtcl/plonk';
1
+ import { DrunkOptions, Drunk, EnvOptions, Env, FoldOptions, Fold, FramesOptions, TimerCallback, Frames, MetroOptions, Metro, RandOptions, Rand, ScaleOptions, Scale, SineOptions, Sine, WrapOptions, Wrap } from '@prtcl/plonk';
2
+
3
+ /**
4
+ * Hook wrapper for Drunk, instantiates a Drunk generator on mount.
5
+ * @param opts - {@link DrunkOptions} for configuring the random walk.
6
+ * @returns The underlying Drunk instance.
7
+ */
8
+ declare const useDrunk: (opts?: DrunkOptions) => Drunk;
9
+
10
+ /**
11
+ * Hook wrapper for Env, instantiates an Env generator on mount.
12
+ * @param opts - {@link EnvOptions} for configuring the envelope.
13
+ * @returns The underlying Env instance.
14
+ */
15
+ declare const useEnv: (opts: EnvOptions) => Env;
16
+
17
+ /**
18
+ * Hook wrapper for Fold, instantiates a Fold transformer on mount.
19
+ * @param opts - {@link FoldOptions} for configuring the range.
20
+ * @returns The underlying Fold instance.
21
+ */
22
+ declare const useFold: (opts?: FoldOptions) => Fold;
2
23
 
3
24
  type UseFramesOptions = FramesOptions & {
4
25
  autostart?: boolean;
@@ -29,4 +50,32 @@ declare const useMetro: (callback: TimerCallback<Metro>, opts?: UseMetroOptions)
29
50
  */
30
51
  declare const usePrevious: <Value>(value: Value) => Value | undefined;
31
52
 
32
- export { type UseFramesOptions, type UseMetroOptions, useFrames, useMetro, usePrevious };
53
+ /**
54
+ * Hook wrapper for Rand, instantiates a Rand generator on mount.
55
+ * @param opts - {@link RandOptions} for configuring the random range.
56
+ * @returns The underlying Rand instance.
57
+ */
58
+ declare const useRand: (opts?: RandOptions) => Rand;
59
+
60
+ /**
61
+ * Hook wrapper for Scale, instantiates a Scale mapper on mount.
62
+ * @param opts - {@link ScaleOptions} for configuring the input/output ranges.
63
+ * @returns The underlying Scale instance.
64
+ */
65
+ declare const useScale: (opts?: ScaleOptions) => Scale;
66
+
67
+ /**
68
+ * Hook wrapper for Sine, instantiates a Sine oscillator on mount.
69
+ * @param opts - {@link SineOptions} for configuring the oscillator.
70
+ * @returns The underlying Sine instance.
71
+ */
72
+ declare const useSine: (opts: SineOptions) => Sine;
73
+
74
+ /**
75
+ * Hook wrapper for Wrap, instantiates a Wrap transformer on mount.
76
+ * @param opts - {@link WrapOptions} for configuring the range.
77
+ * @returns The underlying Wrap instance.
78
+ */
79
+ declare const useWrap: (opts?: WrapOptions) => Wrap;
80
+
81
+ export { type UseFramesOptions, type UseMetroOptions, useDrunk, useEnv, useFold, useFrames, useMetro, usePrevious, useRand, useScale, useSine, useWrap };
package/dist/index.d.ts CHANGED
@@ -1,4 +1,25 @@
1
- import { FramesOptions, TimerCallback, Frames, MetroOptions, Metro } from '@prtcl/plonk';
1
+ import { DrunkOptions, Drunk, EnvOptions, Env, FoldOptions, Fold, FramesOptions, TimerCallback, Frames, MetroOptions, Metro, RandOptions, Rand, ScaleOptions, Scale, SineOptions, Sine, WrapOptions, Wrap } from '@prtcl/plonk';
2
+
3
+ /**
4
+ * Hook wrapper for Drunk, instantiates a Drunk generator on mount.
5
+ * @param opts - {@link DrunkOptions} for configuring the random walk.
6
+ * @returns The underlying Drunk instance.
7
+ */
8
+ declare const useDrunk: (opts?: DrunkOptions) => Drunk;
9
+
10
+ /**
11
+ * Hook wrapper for Env, instantiates an Env generator on mount.
12
+ * @param opts - {@link EnvOptions} for configuring the envelope.
13
+ * @returns The underlying Env instance.
14
+ */
15
+ declare const useEnv: (opts: EnvOptions) => Env;
16
+
17
+ /**
18
+ * Hook wrapper for Fold, instantiates a Fold transformer on mount.
19
+ * @param opts - {@link FoldOptions} for configuring the range.
20
+ * @returns The underlying Fold instance.
21
+ */
22
+ declare const useFold: (opts?: FoldOptions) => Fold;
2
23
 
3
24
  type UseFramesOptions = FramesOptions & {
4
25
  autostart?: boolean;
@@ -29,4 +50,32 @@ declare const useMetro: (callback: TimerCallback<Metro>, opts?: UseMetroOptions)
29
50
  */
30
51
  declare const usePrevious: <Value>(value: Value) => Value | undefined;
31
52
 
32
- export { type UseFramesOptions, type UseMetroOptions, useFrames, useMetro, usePrevious };
53
+ /**
54
+ * Hook wrapper for Rand, instantiates a Rand generator on mount.
55
+ * @param opts - {@link RandOptions} for configuring the random range.
56
+ * @returns The underlying Rand instance.
57
+ */
58
+ declare const useRand: (opts?: RandOptions) => Rand;
59
+
60
+ /**
61
+ * Hook wrapper for Scale, instantiates a Scale mapper on mount.
62
+ * @param opts - {@link ScaleOptions} for configuring the input/output ranges.
63
+ * @returns The underlying Scale instance.
64
+ */
65
+ declare const useScale: (opts?: ScaleOptions) => Scale;
66
+
67
+ /**
68
+ * Hook wrapper for Sine, instantiates a Sine oscillator on mount.
69
+ * @param opts - {@link SineOptions} for configuring the oscillator.
70
+ * @returns The underlying Sine instance.
71
+ */
72
+ declare const useSine: (opts: SineOptions) => Sine;
73
+
74
+ /**
75
+ * Hook wrapper for Wrap, instantiates a Wrap transformer on mount.
76
+ * @param opts - {@link WrapOptions} for configuring the range.
77
+ * @returns The underlying Wrap instance.
78
+ */
79
+ declare const useWrap: (opts?: WrapOptions) => Wrap;
80
+
81
+ export { type UseFramesOptions, type UseMetroOptions, useDrunk, useEnv, useFold, useFrames, useMetro, usePrevious, useRand, useScale, useSine, useWrap };
package/dist/index.js CHANGED
@@ -3,8 +3,29 @@
3
3
  // src/index.ts
4
4
  import "client-only";
5
5
 
6
+ // src/useDrunk.ts
7
+ import { useMemo } from "react";
8
+ import { Drunk } from "@prtcl/plonk";
9
+ var useDrunk = (opts) => {
10
+ return useMemo(() => new Drunk(opts), []);
11
+ };
12
+
13
+ // src/useEnv.ts
14
+ import { useMemo as useMemo2 } from "react";
15
+ import { Env } from "@prtcl/plonk";
16
+ var useEnv = (opts) => {
17
+ return useMemo2(() => new Env(opts), []);
18
+ };
19
+
20
+ // src/useFold.ts
21
+ import { useMemo as useMemo3 } from "react";
22
+ import { Fold } from "@prtcl/plonk";
23
+ var useFold = (opts) => {
24
+ return useMemo3(() => new Fold(opts), []);
25
+ };
26
+
6
27
  // src/useFrames.ts
7
- import { useEffect, useMemo, useRef as useRef2 } from "react";
28
+ import { useEffect, useMemo as useMemo4, useRef as useRef2 } from "react";
8
29
  import { Frames } from "@prtcl/plonk";
9
30
 
10
31
  // src/usePrevious.ts
@@ -31,7 +52,7 @@ var useFrames = (callback, opts) => {
31
52
  const optsRef = useRef2(opts);
32
53
  const prevOpts = usePrevious(opts);
33
54
  callbackRef.current = callback;
34
- const frames = useMemo(() => {
55
+ const frames = useMemo4(() => {
35
56
  return new Frames((m) => {
36
57
  callbackRef.current(m);
37
58
  }, optsRef.current);
@@ -53,7 +74,7 @@ var useFrames = (callback, opts) => {
53
74
  };
54
75
 
55
76
  // src/useMetro.ts
56
- import { useEffect as useEffect2, useMemo as useMemo2, useRef as useRef3 } from "react";
77
+ import { useEffect as useEffect2, useMemo as useMemo5, useRef as useRef3 } from "react";
57
78
  import { Metro } from "@prtcl/plonk";
58
79
  var useMetro = (callback, opts) => {
59
80
  const { autostart = true } = opts || {};
@@ -61,7 +82,7 @@ var useMetro = (callback, opts) => {
61
82
  const optsRef = useRef3(opts);
62
83
  const prevOpts = usePrevious(opts);
63
84
  callbackRef.current = callback;
64
- const metro = useMemo2(() => {
85
+ const metro = useMemo5(() => {
65
86
  return new Metro((m) => {
66
87
  callbackRef.current(m);
67
88
  }, optsRef.current);
@@ -81,9 +102,44 @@ var useMetro = (callback, opts) => {
81
102
  }, [metro]);
82
103
  return metro;
83
104
  };
105
+
106
+ // src/useRand.ts
107
+ import { useMemo as useMemo6 } from "react";
108
+ import { Rand } from "@prtcl/plonk";
109
+ var useRand = (opts) => {
110
+ return useMemo6(() => new Rand(opts), []);
111
+ };
112
+
113
+ // src/useScale.ts
114
+ import { useMemo as useMemo7 } from "react";
115
+ import { Scale } from "@prtcl/plonk";
116
+ var useScale = (opts) => {
117
+ return useMemo7(() => new Scale(opts), []);
118
+ };
119
+
120
+ // src/useSine.ts
121
+ import { useMemo as useMemo8 } from "react";
122
+ import { Sine } from "@prtcl/plonk";
123
+ var useSine = (opts) => {
124
+ return useMemo8(() => new Sine(opts), []);
125
+ };
126
+
127
+ // src/useWrap.ts
128
+ import { useMemo as useMemo9 } from "react";
129
+ import { Wrap } from "@prtcl/plonk";
130
+ var useWrap = (opts) => {
131
+ return useMemo9(() => new Wrap(opts), []);
132
+ };
84
133
  export {
134
+ useDrunk,
135
+ useEnv,
136
+ useFold,
85
137
  useFrames,
86
138
  useMetro,
87
- usePrevious
139
+ usePrevious,
140
+ useRand,
141
+ useScale,
142
+ useSine,
143
+ useWrap
88
144
  };
89
145
  //# sourceMappingURL=index.js.map
package/dist/index.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"sources":["../src/index.ts","../src/useFrames.ts","../src/usePrevious.ts","../src/useMetro.ts"],"sourcesContent":["'use client';\n\nimport 'client-only';\n\nexport { useFrames, type UseFramesOptions } from './useFrames';\nexport { useMetro, type UseMetroOptions } from './useMetro';\nexport { usePrevious } from './usePrevious';\n","import { useEffect, useMemo, useRef } from 'react';\nimport { Frames, type FramesOptions, type TimerCallback } from '@prtcl/plonk';\nimport { usePrevious } from './usePrevious';\n\nexport type UseFramesOptions = FramesOptions & {\n autostart?: boolean;\n};\n\n/**\n * Hook wrapper for Frames, autostart begins on mount and stops on unmount.\n * @param callback - {@link TimerCallback} called on each frame tick.\n * @param opts - {@link UseFramesOptions} for configuring frame rate and autostart.\n * @returns The underlying Frames instance.\n */\nexport const useFrames = (callback: TimerCallback<Frames>, opts?: UseFramesOptions) => {\n const { autostart = true } = opts || {};\n const callbackRef = useRef<TimerCallback<Frames>>(callback);\n const optsRef = useRef<UseFramesOptions | undefined>(opts);\n const prevOpts = usePrevious(opts);\n\n callbackRef.current = callback;\n\n const frames = useMemo<Frames>(() => {\n return new Frames((m) => {\n callbackRef.current(m);\n }, optsRef.current);\n }, []);\n\n useEffect(() => {\n if (opts && prevOpts && opts.fps !== prevOpts.fps) {\n frames.setFPS(opts.fps);\n }\n }, [opts, prevOpts, frames]);\n\n useEffect(() => {\n if (autostart) {\n frames.run();\n }\n\n return () => {\n frames.stop();\n };\n }, [frames]);\n\n return frames;\n};\n","import { useRef } from 'react';\n\ntype ValueCache<Value> = {\n value: Value;\n prev: Value | undefined;\n};\n\n/**\n * Returns the previous value of a variable without causing additional renders.\n * @param value - The current value to track.\n * @returns The value from the previous render, or undefined on the first render.\n */\nexport const usePrevious = <Value>(value: Value): Value | undefined => {\n const ref = useRef<ValueCache<Value>>({\n value,\n prev: undefined,\n });\n\n const current = ref.current.value;\n\n if (value !== current) {\n ref.current = {\n value,\n prev: current,\n };\n }\n\n return ref.current.prev;\n};\n","import { useEffect, useMemo, useRef } from 'react';\nimport { Metro, type MetroOptions, type TimerCallback } from '@prtcl/plonk';\nimport { usePrevious } from './usePrevious';\n\nexport type UseMetroOptions = MetroOptions & {\n autostart?: boolean;\n};\n\n/**\n * Hook wrapper for Metro, autostart begins on mount and stops on unmount.\n * @param callback - {@link TimerCallback} called on each tick.\n * @param opts - {@link UseMetroOptions} for configuring the timer and autostart.\n * @returns The underlying Metro instance.\n */\nexport const useMetro = (callback: TimerCallback<Metro>, opts?: UseMetroOptions) => {\n const { autostart = true } = opts || {};\n const callbackRef = useRef<TimerCallback<Metro>>(callback);\n const optsRef = useRef<UseMetroOptions | undefined>(opts);\n const prevOpts = usePrevious(opts);\n\n callbackRef.current = callback;\n\n const metro = useMemo<Metro>(() => {\n return new Metro((m) => {\n callbackRef.current(m);\n }, optsRef.current);\n }, []);\n\n useEffect(() => {\n if (opts && prevOpts && opts.time !== prevOpts.time) {\n metro.setTime(opts.time);\n }\n }, [opts, prevOpts, metro]);\n\n useEffect(() => {\n if (autostart) {\n metro.run();\n }\n\n return () => {\n metro.stop();\n };\n }, [metro]);\n\n return metro;\n};\n"],"mappings":";;;AAEA,OAAO;;;ACFP,SAAS,WAAW,SAAS,UAAAA,eAAc;AAC3C,SAAS,cAAsD;;;ACD/D,SAAS,cAAc;AAYhB,IAAM,cAAc,CAAQ,UAAoC;AACrE,QAAM,MAAM,OAA0B;AAAA,IACpC;AAAA,IACA,MAAM;AAAA,EACR,CAAC;AAED,QAAM,UAAU,IAAI,QAAQ;AAE5B,MAAI,UAAU,SAAS;AACrB,QAAI,UAAU;AAAA,MACZ;AAAA,MACA,MAAM;AAAA,IACR;AAAA,EACF;AAEA,SAAO,IAAI,QAAQ;AACrB;;;ADdO,IAAM,YAAY,CAAC,UAAiC,SAA4B;AACrF,QAAM,EAAE,YAAY,KAAK,IAAI,QAAQ,CAAC;AACtC,QAAM,cAAcC,QAA8B,QAAQ;AAC1D,QAAM,UAAUA,QAAqC,IAAI;AACzD,QAAM,WAAW,YAAY,IAAI;AAEjC,cAAY,UAAU;AAEtB,QAAM,SAAS,QAAgB,MAAM;AACnC,WAAO,IAAI,OAAO,CAAC,MAAM;AACvB,kBAAY,QAAQ,CAAC;AAAA,IACvB,GAAG,QAAQ,OAAO;AAAA,EACpB,GAAG,CAAC,CAAC;AAEL,YAAU,MAAM;AACd,QAAI,QAAQ,YAAY,KAAK,QAAQ,SAAS,KAAK;AACjD,aAAO,OAAO,KAAK,GAAG;AAAA,IACxB;AAAA,EACF,GAAG,CAAC,MAAM,UAAU,MAAM,CAAC;AAE3B,YAAU,MAAM;AACd,QAAI,WAAW;AACb,aAAO,IAAI;AAAA,IACb;AAEA,WAAO,MAAM;AACX,aAAO,KAAK;AAAA,IACd;AAAA,EACF,GAAG,CAAC,MAAM,CAAC;AAEX,SAAO;AACT;;;AE7CA,SAAS,aAAAC,YAAW,WAAAC,UAAS,UAAAC,eAAc;AAC3C,SAAS,aAAoD;AAatD,IAAM,WAAW,CAAC,UAAgC,SAA2B;AAClF,QAAM,EAAE,YAAY,KAAK,IAAI,QAAQ,CAAC;AACtC,QAAM,cAAcC,QAA6B,QAAQ;AACzD,QAAM,UAAUA,QAAoC,IAAI;AACxD,QAAM,WAAW,YAAY,IAAI;AAEjC,cAAY,UAAU;AAEtB,QAAM,QAAQC,SAAe,MAAM;AACjC,WAAO,IAAI,MAAM,CAAC,MAAM;AACtB,kBAAY,QAAQ,CAAC;AAAA,IACvB,GAAG,QAAQ,OAAO;AAAA,EACpB,GAAG,CAAC,CAAC;AAEL,EAAAC,WAAU,MAAM;AACd,QAAI,QAAQ,YAAY,KAAK,SAAS,SAAS,MAAM;AACnD,YAAM,QAAQ,KAAK,IAAI;AAAA,IACzB;AAAA,EACF,GAAG,CAAC,MAAM,UAAU,KAAK,CAAC;AAE1B,EAAAA,WAAU,MAAM;AACd,QAAI,WAAW;AACb,YAAM,IAAI;AAAA,IACZ;AAEA,WAAO,MAAM;AACX,YAAM,KAAK;AAAA,IACb;AAAA,EACF,GAAG,CAAC,KAAK,CAAC;AAEV,SAAO;AACT;","names":["useRef","useRef","useEffect","useMemo","useRef","useRef","useMemo","useEffect"]}
1
+ {"version":3,"sources":["../src/index.ts","../src/useDrunk.ts","../src/useEnv.ts","../src/useFold.ts","../src/useFrames.ts","../src/usePrevious.ts","../src/useMetro.ts","../src/useRand.ts","../src/useScale.ts","../src/useSine.ts","../src/useWrap.ts"],"sourcesContent":["'use client';\n\nimport 'client-only';\n\nexport { useDrunk } from './useDrunk';\nexport { useEnv } from './useEnv';\nexport { useFold } from './useFold';\nexport { useFrames, type UseFramesOptions } from './useFrames';\nexport { useMetro, type UseMetroOptions } from './useMetro';\nexport { usePrevious } from './usePrevious';\nexport { useRand } from './useRand';\nexport { useScale } from './useScale';\nexport { useSine } from './useSine';\nexport { useWrap } from './useWrap';\n","import { useMemo } from 'react';\nimport { Drunk, type DrunkOptions } from '@prtcl/plonk';\n\n/**\n * Hook wrapper for Drunk, instantiates a Drunk generator on mount.\n * @param opts - {@link DrunkOptions} for configuring the random walk.\n * @returns The underlying Drunk instance.\n */\nexport const useDrunk = (opts?: DrunkOptions) => {\n return useMemo(() => new Drunk(opts), []);\n};\n","import { useMemo } from 'react';\nimport { Env, type EnvOptions } from '@prtcl/plonk';\n\n/**\n * Hook wrapper for Env, instantiates an Env generator on mount.\n * @param opts - {@link EnvOptions} for configuring the envelope.\n * @returns The underlying Env instance.\n */\nexport const useEnv = (opts: EnvOptions) => {\n return useMemo(() => new Env(opts), []);\n};\n","import { useMemo } from 'react';\nimport { Fold, type FoldOptions } from '@prtcl/plonk';\n\n/**\n * Hook wrapper for Fold, instantiates a Fold transformer on mount.\n * @param opts - {@link FoldOptions} for configuring the range.\n * @returns The underlying Fold instance.\n */\nexport const useFold = (opts?: FoldOptions) => {\n return useMemo(() => new Fold(opts), []);\n};\n","import { useEffect, useMemo, useRef } from 'react';\nimport { Frames, type FramesOptions, type TimerCallback } from '@prtcl/plonk';\nimport { usePrevious } from './usePrevious';\n\nexport type UseFramesOptions = FramesOptions & {\n autostart?: boolean;\n};\n\n/**\n * Hook wrapper for Frames, autostart begins on mount and stops on unmount.\n * @param callback - {@link TimerCallback} called on each frame tick.\n * @param opts - {@link UseFramesOptions} for configuring frame rate and autostart.\n * @returns The underlying Frames instance.\n */\nexport const useFrames = (callback: TimerCallback<Frames>, opts?: UseFramesOptions) => {\n const { autostart = true } = opts || {};\n const callbackRef = useRef<TimerCallback<Frames>>(callback);\n const optsRef = useRef<UseFramesOptions | undefined>(opts);\n const prevOpts = usePrevious(opts);\n\n callbackRef.current = callback;\n\n const frames = useMemo<Frames>(() => {\n return new Frames((m) => {\n callbackRef.current(m);\n }, optsRef.current);\n }, []);\n\n useEffect(() => {\n if (opts && prevOpts && opts.fps !== prevOpts.fps) {\n frames.setFPS(opts.fps);\n }\n }, [opts, prevOpts, frames]);\n\n useEffect(() => {\n if (autostart) {\n frames.run();\n }\n\n return () => {\n frames.stop();\n };\n }, [frames]);\n\n return frames;\n};\n","import { useRef } from 'react';\n\ntype ValueCache<Value> = {\n value: Value;\n prev: Value | undefined;\n};\n\n/**\n * Returns the previous value of a variable without causing additional renders.\n * @param value - The current value to track.\n * @returns The value from the previous render, or undefined on the first render.\n */\nexport const usePrevious = <Value>(value: Value): Value | undefined => {\n const ref = useRef<ValueCache<Value>>({\n value,\n prev: undefined,\n });\n\n const current = ref.current.value;\n\n if (value !== current) {\n ref.current = {\n value,\n prev: current,\n };\n }\n\n return ref.current.prev;\n};\n","import { useEffect, useMemo, useRef } from 'react';\nimport { Metro, type MetroOptions, type TimerCallback } from '@prtcl/plonk';\nimport { usePrevious } from './usePrevious';\n\nexport type UseMetroOptions = MetroOptions & {\n autostart?: boolean;\n};\n\n/**\n * Hook wrapper for Metro, autostart begins on mount and stops on unmount.\n * @param callback - {@link TimerCallback} called on each tick.\n * @param opts - {@link UseMetroOptions} for configuring the timer and autostart.\n * @returns The underlying Metro instance.\n */\nexport const useMetro = (callback: TimerCallback<Metro>, opts?: UseMetroOptions) => {\n const { autostart = true } = opts || {};\n const callbackRef = useRef<TimerCallback<Metro>>(callback);\n const optsRef = useRef<UseMetroOptions | undefined>(opts);\n const prevOpts = usePrevious(opts);\n\n callbackRef.current = callback;\n\n const metro = useMemo<Metro>(() => {\n return new Metro((m) => {\n callbackRef.current(m);\n }, optsRef.current);\n }, []);\n\n useEffect(() => {\n if (opts && prevOpts && opts.time !== prevOpts.time) {\n metro.setTime(opts.time);\n }\n }, [opts, prevOpts, metro]);\n\n useEffect(() => {\n if (autostart) {\n metro.run();\n }\n\n return () => {\n metro.stop();\n };\n }, [metro]);\n\n return metro;\n};\n","import { useMemo } from 'react';\nimport { Rand, type RandOptions } from '@prtcl/plonk';\n\n/**\n * Hook wrapper for Rand, instantiates a Rand generator on mount.\n * @param opts - {@link RandOptions} for configuring the random range.\n * @returns The underlying Rand instance.\n */\nexport const useRand = (opts?: RandOptions) => {\n return useMemo(() => new Rand(opts), []);\n};\n","import { useMemo } from 'react';\nimport { Scale, type ScaleOptions } from '@prtcl/plonk';\n\n/**\n * Hook wrapper for Scale, instantiates a Scale mapper on mount.\n * @param opts - {@link ScaleOptions} for configuring the input/output ranges.\n * @returns The underlying Scale instance.\n */\nexport const useScale = (opts?: ScaleOptions) => {\n return useMemo(() => new Scale(opts), []);\n};\n","import { useMemo } from 'react';\nimport { Sine, type SineOptions } from '@prtcl/plonk';\n\n/**\n * Hook wrapper for Sine, instantiates a Sine oscillator on mount.\n * @param opts - {@link SineOptions} for configuring the oscillator.\n * @returns The underlying Sine instance.\n */\nexport const useSine = (opts: SineOptions) => {\n return useMemo(() => new Sine(opts), []);\n};\n","import { useMemo } from 'react';\nimport { Wrap, type WrapOptions } from '@prtcl/plonk';\n\n/**\n * Hook wrapper for Wrap, instantiates a Wrap transformer on mount.\n * @param opts - {@link WrapOptions} for configuring the range.\n * @returns The underlying Wrap instance.\n */\nexport const useWrap = (opts?: WrapOptions) => {\n return useMemo(() => new Wrap(opts), []);\n};\n"],"mappings":";;;AAEA,OAAO;;;ACFP,SAAS,eAAe;AACxB,SAAS,aAAgC;AAOlC,IAAM,WAAW,CAAC,SAAwB;AAC/C,SAAO,QAAQ,MAAM,IAAI,MAAM,IAAI,GAAG,CAAC,CAAC;AAC1C;;;ACVA,SAAS,WAAAA,gBAAe;AACxB,SAAS,WAA4B;AAO9B,IAAM,SAAS,CAAC,SAAqB;AAC1C,SAAOA,SAAQ,MAAM,IAAI,IAAI,IAAI,GAAG,CAAC,CAAC;AACxC;;;ACVA,SAA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SAAuB;AAC7C,SAAOA,SAAQ,MAAM,IAAI,KAAK,IAAI,GAAG,CAAC,CAAC;AACzC;","names":["useMemo","useMemo","useMemo","useRef","useRef","useMemo","useEffect","useMemo","useRef","useRef","useMemo","useEffect","useMemo","useMemo","useMemo","useMemo"]}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@prtcl/plonk-hooks",
3
- "version": "1.1.1",
3
+ "version": "1.1.2",
4
4
  "description": "React hook wrappers for plonk",
5
5
  "author": "Cory O'Brien <cory@prtcl.cc>",
6
6
  "license": "MIT",
@@ -23,7 +23,7 @@
23
23
  "test": "vitest --browser.name=chrome --browser.headless --watch=false"
24
24
  },
25
25
  "dependencies": {
26
- "@prtcl/plonk": "1.1.1",
26
+ "@prtcl/plonk": "1.1.2",
27
27
  "client-only": "^0.0.1"
28
28
  },
29
29
  "peerDependencies": {