@daysnap/utils 0.1.27 → 0.1.29

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.
@@ -0,0 +1,8 @@
1
+ // src/toPosix.ts
2
+ function toPosix(value) {
3
+ return value.replace(/\\/g, "/");
4
+ }
5
+
6
+ export {
7
+ toPosix
8
+ };
@@ -0,0 +1,319 @@
1
+ // src/sounds.ts
2
+ var audioContext = null;
3
+ function getAudioContext() {
4
+ if (!audioContext) {
5
+ audioContext = new AudioContext();
6
+ }
7
+ if (audioContext.state === "suspended") {
8
+ audioContext.resume();
9
+ }
10
+ return audioContext;
11
+ }
12
+ var sounds = {
13
+ click: () => {
14
+ try {
15
+ const ctx = getAudioContext();
16
+ const t = ctx.currentTime;
17
+ const noise = ctx.createBufferSource();
18
+ const buf = ctx.createBuffer(1, ctx.sampleRate * 8e-3, ctx.sampleRate);
19
+ const data = buf.getChannelData(0);
20
+ for (let i = 0; i < data.length; i++) {
21
+ data[i] = (Math.random() * 2 - 1) * Math.exp(-i / 50);
22
+ }
23
+ noise.buffer = buf;
24
+ const filter = ctx.createBiquadFilter();
25
+ filter.type = "bandpass";
26
+ filter.frequency.value = 4e3 + Math.random() * 1e3;
27
+ filter.Q.value = 3;
28
+ const gain = ctx.createGain();
29
+ gain.gain.value = 0.5 + Math.random() * 0.15;
30
+ noise.connect(filter);
31
+ filter.connect(gain);
32
+ gain.connect(ctx.destination);
33
+ noise.start(t);
34
+ } catch {
35
+ console.error("Error playing click sound");
36
+ }
37
+ },
38
+ pop: () => {
39
+ try {
40
+ const ctx = getAudioContext();
41
+ const t = ctx.currentTime;
42
+ const osc = ctx.createOscillator();
43
+ const gain = ctx.createGain();
44
+ osc.type = "sine";
45
+ osc.frequency.setValueAtTime(400, t);
46
+ osc.frequency.exponentialRampToValueAtTime(150, t + 0.04);
47
+ gain.gain.setValueAtTime(0.35, t);
48
+ gain.gain.exponentialRampToValueAtTime(1e-3, t + 0.05);
49
+ osc.connect(gain);
50
+ gain.connect(ctx.destination);
51
+ osc.start(t);
52
+ osc.stop(t + 0.05);
53
+ } catch {
54
+ console.error("Error playing pop sound");
55
+ }
56
+ },
57
+ toggle: () => {
58
+ try {
59
+ const ctx = getAudioContext();
60
+ const t = ctx.currentTime;
61
+ const noise = ctx.createBufferSource();
62
+ const buf = ctx.createBuffer(1, ctx.sampleRate * 0.012, ctx.sampleRate);
63
+ const data = buf.getChannelData(0);
64
+ for (let i = 0; i < data.length; i++) {
65
+ data[i] = (Math.random() * 2 - 1) * Math.exp(-i / 80);
66
+ }
67
+ noise.buffer = buf;
68
+ const filter = ctx.createBiquadFilter();
69
+ filter.type = "bandpass";
70
+ filter.frequency.value = 2500;
71
+ filter.Q.value = 4;
72
+ const gain = ctx.createGain();
73
+ gain.gain.value = 0.4;
74
+ noise.connect(filter);
75
+ filter.connect(gain);
76
+ gain.connect(ctx.destination);
77
+ noise.start(t);
78
+ const osc = ctx.createOscillator();
79
+ const oscGain = ctx.createGain();
80
+ osc.type = "sine";
81
+ osc.frequency.setValueAtTime(800, t);
82
+ osc.frequency.exponentialRampToValueAtTime(400, t + 0.03);
83
+ oscGain.gain.setValueAtTime(0.15, t);
84
+ oscGain.gain.exponentialRampToValueAtTime(1e-3, t + 0.04);
85
+ osc.connect(oscGain);
86
+ oscGain.connect(ctx.destination);
87
+ osc.start(t);
88
+ osc.stop(t + 0.04);
89
+ } catch {
90
+ console.error("Error playing toggle sound");
91
+ }
92
+ },
93
+ tick: () => {
94
+ try {
95
+ const ctx = getAudioContext();
96
+ const t = ctx.currentTime;
97
+ const noise = ctx.createBufferSource();
98
+ const buf = ctx.createBuffer(1, ctx.sampleRate * 4e-3, ctx.sampleRate);
99
+ const data = buf.getChannelData(0);
100
+ for (let i = 0; i < data.length; i++) {
101
+ data[i] = (Math.random() * 2 - 1) * Math.exp(-i / 20);
102
+ }
103
+ noise.buffer = buf;
104
+ const filter = ctx.createBiquadFilter();
105
+ filter.type = "highpass";
106
+ filter.frequency.value = 3e3;
107
+ const gain = ctx.createGain();
108
+ gain.gain.value = 0.3;
109
+ noise.connect(filter);
110
+ filter.connect(gain);
111
+ gain.connect(ctx.destination);
112
+ noise.start(t);
113
+ } catch {
114
+ console.error("Error playing tick sound");
115
+ }
116
+ },
117
+ whoosh: () => {
118
+ try {
119
+ const ctx = getAudioContext();
120
+ const t = ctx.currentTime;
121
+ const noise = ctx.createBufferSource();
122
+ const buf = ctx.createBuffer(1, ctx.sampleRate * 0.08, ctx.sampleRate);
123
+ const data = buf.getChannelData(0);
124
+ for (let i = 0; i < data.length; i++) {
125
+ const env = Math.sin(i / data.length * Math.PI);
126
+ data[i] = (Math.random() * 2 - 1) * env;
127
+ }
128
+ noise.buffer = buf;
129
+ const filter = ctx.createBiquadFilter();
130
+ filter.type = "bandpass";
131
+ filter.frequency.setValueAtTime(4e3, t);
132
+ filter.frequency.exponentialRampToValueAtTime(1500, t + 0.08);
133
+ filter.Q.value = 1;
134
+ const gain = ctx.createGain();
135
+ gain.gain.value = 0.15;
136
+ noise.connect(filter);
137
+ filter.connect(gain);
138
+ gain.connect(ctx.destination);
139
+ noise.start(t);
140
+ } catch {
141
+ console.error("Error playing whoosh sound");
142
+ }
143
+ },
144
+ success: () => {
145
+ try {
146
+ const ctx = getAudioContext();
147
+ const t = ctx.currentTime;
148
+ const notes = [523.25, 659.25, 783.99];
149
+ const spacing = 0.08;
150
+ notes.forEach((freq, i) => {
151
+ const osc = ctx.createOscillator();
152
+ const osc2 = ctx.createOscillator();
153
+ const gain = ctx.createGain();
154
+ const filter = ctx.createBiquadFilter();
155
+ osc.type = "triangle";
156
+ osc.frequency.value = freq;
157
+ osc2.type = "sine";
158
+ osc2.frequency.value = freq * 2;
159
+ filter.type = "lowpass";
160
+ filter.frequency.value = 3e3;
161
+ const start = t + i * spacing;
162
+ const duration = 0.15;
163
+ gain.gain.setValueAtTime(0, start);
164
+ gain.gain.linearRampToValueAtTime(0.25, start + 0.01);
165
+ gain.gain.exponentialRampToValueAtTime(1e-3, start + duration);
166
+ osc.connect(gain);
167
+ osc2.connect(gain);
168
+ gain.connect(filter);
169
+ filter.connect(ctx.destination);
170
+ osc.start(start);
171
+ osc2.start(start);
172
+ osc.stop(start + duration);
173
+ osc2.stop(start + duration);
174
+ });
175
+ const shimmer = ctx.createOscillator();
176
+ const shimmerGain = ctx.createGain();
177
+ shimmer.type = "sine";
178
+ shimmer.frequency.value = 1046.5;
179
+ shimmerGain.gain.setValueAtTime(0, t + 0.24);
180
+ shimmerGain.gain.linearRampToValueAtTime(0.15, t + 0.26);
181
+ shimmerGain.gain.exponentialRampToValueAtTime(1e-3, t + 0.45);
182
+ shimmer.connect(shimmerGain);
183
+ shimmerGain.connect(ctx.destination);
184
+ shimmer.start(t + 0.24);
185
+ shimmer.stop(t + 0.45);
186
+ } catch {
187
+ console.error("Error playing success sound");
188
+ }
189
+ },
190
+ confirm: () => {
191
+ try {
192
+ const ctx = getAudioContext();
193
+ const t = ctx.currentTime;
194
+ const noise = ctx.createBufferSource();
195
+ const buf = ctx.createBuffer(1, ctx.sampleRate * 0.015, ctx.sampleRate);
196
+ const data = buf.getChannelData(0);
197
+ for (let i = 0; i < data.length; i++) {
198
+ data[i] = (Math.random() * 2 - 1) * Math.exp(-i / 100);
199
+ }
200
+ noise.buffer = buf;
201
+ const filter = ctx.createBiquadFilter();
202
+ filter.type = "bandpass";
203
+ filter.frequency.value = 2e3;
204
+ filter.Q.value = 2;
205
+ const gain = ctx.createGain();
206
+ gain.gain.value = 0.4;
207
+ noise.connect(filter);
208
+ filter.connect(gain);
209
+ gain.connect(ctx.destination);
210
+ noise.start(t);
211
+ const osc = ctx.createOscillator();
212
+ const oscGain = ctx.createGain();
213
+ osc.type = "sine";
214
+ osc.frequency.setValueAtTime(150, t);
215
+ osc.frequency.exponentialRampToValueAtTime(60, t + 0.05);
216
+ oscGain.gain.setValueAtTime(0.25, t);
217
+ oscGain.gain.exponentialRampToValueAtTime(1e-3, t + 0.06);
218
+ osc.connect(oscGain);
219
+ oscGain.connect(ctx.destination);
220
+ osc.start(t);
221
+ osc.stop(t + 0.06);
222
+ } catch {
223
+ console.error("Error playing confirm sound");
224
+ }
225
+ },
226
+ error: () => {
227
+ try {
228
+ const ctx = getAudioContext();
229
+ const t = ctx.currentTime;
230
+ const osc1 = ctx.createOscillator();
231
+ const osc2 = ctx.createOscillator();
232
+ const gain = ctx.createGain();
233
+ const distortion = ctx.createWaveShaper();
234
+ const curve = new Float32Array(256);
235
+ for (let i = 0; i < 256; i++) {
236
+ const x = i / 128 - 1;
237
+ curve[i] = Math.tanh(x * 2);
238
+ }
239
+ distortion.curve = curve;
240
+ osc1.type = "sawtooth";
241
+ osc1.frequency.setValueAtTime(180, t);
242
+ osc1.frequency.exponentialRampToValueAtTime(80, t + 0.25);
243
+ osc2.type = "square";
244
+ osc2.frequency.setValueAtTime(190, t);
245
+ osc2.frequency.exponentialRampToValueAtTime(85, t + 0.25);
246
+ gain.gain.setValueAtTime(0, t);
247
+ gain.gain.linearRampToValueAtTime(0.3, t + 0.02);
248
+ gain.gain.setValueAtTime(0.3, t + 0.08);
249
+ gain.gain.linearRampToValueAtTime(0.25, t + 0.1);
250
+ gain.gain.exponentialRampToValueAtTime(1e-3, t + 0.3);
251
+ const filter = ctx.createBiquadFilter();
252
+ filter.type = "lowpass";
253
+ filter.frequency.value = 800;
254
+ osc1.connect(distortion);
255
+ osc2.connect(distortion);
256
+ distortion.connect(gain);
257
+ gain.connect(filter);
258
+ filter.connect(ctx.destination);
259
+ osc1.start(t);
260
+ osc2.start(t);
261
+ osc1.stop(t + 0.3);
262
+ osc2.stop(t + 0.3);
263
+ } catch {
264
+ console.error("Error playing error sound");
265
+ }
266
+ },
267
+ warning: () => {
268
+ try {
269
+ const ctx = getAudioContext();
270
+ const t = ctx.currentTime;
271
+ [0, 0.15].forEach((delay, i) => {
272
+ const osc = ctx.createOscillator();
273
+ const gain = ctx.createGain();
274
+ const filter = ctx.createBiquadFilter();
275
+ osc.type = "triangle";
276
+ osc.frequency.value = i === 0 ? 880 : 698.46;
277
+ filter.type = "bandpass";
278
+ filter.frequency.value = 1200;
279
+ filter.Q.value = 1;
280
+ const start = t + delay;
281
+ gain.gain.setValueAtTime(0, start);
282
+ gain.gain.linearRampToValueAtTime(0.3, start + 0.01);
283
+ gain.gain.setValueAtTime(0.3, start + 0.08);
284
+ gain.gain.exponentialRampToValueAtTime(1e-3, start + 0.12);
285
+ osc.connect(filter);
286
+ filter.connect(gain);
287
+ gain.connect(ctx.destination);
288
+ osc.start(start);
289
+ osc.stop(start + 0.12);
290
+ });
291
+ } catch {
292
+ console.error("Error playing warning sound");
293
+ }
294
+ },
295
+ hover: () => {
296
+ try {
297
+ const ctx = getAudioContext();
298
+ const t = ctx.currentTime;
299
+ const osc = ctx.createOscillator();
300
+ const gain = ctx.createGain();
301
+ osc.type = "sine";
302
+ osc.frequency.setValueAtTime(950, t);
303
+ osc.frequency.linearRampToValueAtTime(700, t + 0.12);
304
+ gain.gain.setValueAtTime(0, t);
305
+ gain.gain.linearRampToValueAtTime(0.08, t + 0.02);
306
+ gain.gain.linearRampToValueAtTime(0.01, t + 0.12);
307
+ osc.connect(gain);
308
+ gain.connect(ctx.destination);
309
+ osc.start(t);
310
+ osc.stop(t + 0.13);
311
+ } catch {
312
+ console.error("Error playing hover sound");
313
+ }
314
+ }
315
+ };
316
+
317
+ export {
318
+ sounds
319
+ };
package/es/index.d.ts CHANGED
@@ -124,6 +124,7 @@ export { roundUpToNearestInteger } from './roundUpToNearestInteger.js';
124
124
  export { scrollToTop } from './scrollToTop.js';
125
125
  export { setScrollTop } from './setScrollTop.js';
126
126
  export { sleep } from './sleep.js';
127
+ export { sounds } from './sounds.js';
127
128
  export { splitArray } from './splitArray.js';
128
129
  export { getCache, getLocal } from './storage/index.js';
129
130
  export { stringTrim } from './stringTrim.js';
@@ -133,6 +134,7 @@ export { throttle, throttleLeading, throttleTrailing } from './throttle.js';
133
134
  export { toCDB } from './toCDB.js';
134
135
  export { toDBC } from './toDBC.js';
135
136
  export { toFormData } from './toFormData.js';
137
+ export { toPosix } from './toPosix.js';
136
138
  export { Trap, createTrapInstance, trap } from './trap.js';
137
139
  export { typeOf } from './typeOf.js';
138
140
  export { withCache } from './withCache.js';
package/es/index.js CHANGED
@@ -1,3 +1,10 @@
1
+ import {
2
+ toPosix
3
+ } from "./chunk-6CNTNYSN.js";
4
+ import {
5
+ createTrapInstance,
6
+ trap
7
+ } from "./chunk-LOPD7SSH.js";
1
8
  import {
2
9
  typeOf
3
10
  } from "./chunk-MTF3ACKC.js";
@@ -17,6 +24,9 @@ import {
17
24
  import {
18
25
  Storage
19
26
  } from "./chunk-56QUZDMU.js";
27
+ import {
28
+ splitArray
29
+ } from "./chunk-BNF4U7EJ.js";
20
30
  import {
21
31
  stringTrim
22
32
  } from "./chunk-IF7JMIDO.js";
@@ -40,10 +50,6 @@ import {
40
50
  import {
41
51
  toFormData
42
52
  } from "./chunk-EITVKZJB.js";
43
- import {
44
- createTrapInstance,
45
- trap
46
- } from "./chunk-LOPD7SSH.js";
47
53
  import {
48
54
  reserve
49
55
  } from "./chunk-TXWIC3L7.js";
@@ -63,8 +69,8 @@ import {
63
69
  setScrollTop
64
70
  } from "./chunk-BULTIEJG.js";
65
71
  import {
66
- splitArray
67
- } from "./chunk-BNF4U7EJ.js";
72
+ sounds
73
+ } from "./chunk-ODZQXCS4.js";
68
74
  import {
69
75
  parseQuery
70
76
  } from "./chunk-WFPQI6HC.js";
@@ -563,6 +569,7 @@ export {
563
569
  scrollToTop,
564
570
  setScrollTop,
565
571
  sleep,
572
+ sounds,
566
573
  splitArray,
567
574
  stringTrim,
568
575
  stringifyQuery,
@@ -573,6 +580,7 @@ export {
573
580
  toCDB,
574
581
  toDBC,
575
582
  toFormData,
583
+ toPosix,
576
584
  trap,
577
585
  typeOf,
578
586
  withCache,
package/es/sounds.d.ts ADDED
@@ -0,0 +1,14 @@
1
+ declare const sounds: {
2
+ click: () => void;
3
+ pop: () => void;
4
+ toggle: () => void;
5
+ tick: () => void;
6
+ whoosh: () => void;
7
+ success: () => void;
8
+ confirm: () => void;
9
+ error: () => void;
10
+ warning: () => void;
11
+ hover: () => void;
12
+ };
13
+
14
+ export { sounds };
package/es/sounds.js ADDED
@@ -0,0 +1,6 @@
1
+ import {
2
+ sounds
3
+ } from "./chunk-ODZQXCS4.js";
4
+ export {
5
+ sounds
6
+ };
@@ -0,0 +1,6 @@
1
+ /**
2
+ * 转换到 Posix 标准
3
+ */
4
+ declare function toPosix(value: string): string;
5
+
6
+ export { toPosix };
package/es/toPosix.js ADDED
@@ -0,0 +1,6 @@
1
+ import {
2
+ toPosix
3
+ } from "./chunk-6CNTNYSN.js";
4
+ export {
5
+ toPosix
6
+ };
@@ -0,0 +1,8 @@
1
+ "use strict";Object.defineProperty(exports, "__esModule", {value: true});// src/toPosix.ts
2
+ function toPosix(value) {
3
+ return value.replace(/\\/g, "/");
4
+ }
5
+
6
+
7
+
8
+ exports.toPosix = toPosix;