@jyiro/ascii-script 0.1.0

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,285 @@
1
+ var __typeError = (msg) => {
2
+ throw TypeError(msg);
3
+ };
4
+ var __accessCheck = (obj, member, msg) => member.has(obj) || __typeError("Cannot " + msg);
5
+ var __privateGet = (obj, member, getter) => (__accessCheck(obj, member, "read from private field"), getter ? getter.call(obj) : member.get(obj));
6
+ var __privateAdd = (obj, member, value) => member.has(obj) ? __typeError("Cannot add the same private member more than once") : member instanceof WeakSet ? member.add(obj) : member.set(obj, value);
7
+ var __privateSet = (obj, member, value, setter) => (__accessCheck(obj, member, "write to private field"), setter ? setter.call(obj, value) : member.set(obj, value), value);
8
+ var __privateMethod = (obj, member, method) => (__accessCheck(obj, member, "access private method"), method);
9
+ var _minScale, _maxScale, _speed, _easingFn, _amplitude, _frequency, _speed2, _easingFn2, _speed3, _spread, _saturation, _lightness, _baseColor, _variations, _speed4, _mode, _ColorGradientEffect_instances, hexToHSL_fn, getVariation_fn, _rotateX, _rotateY, _rotateZ, _perspective, _speed5;
10
+ import { B as BaseEffect } from "./text-CKJIlRsq.js";
11
+ const easing = {
12
+ linear: (t) => t,
13
+ easeInQuad: (t) => t * t,
14
+ easeOutQuad: (t) => t * (2 - t),
15
+ easeInOutQuad: (t) => t < 0.5 ? 2 * t * t : -1 + (4 - 2 * t) * t,
16
+ easeInCubic: (t) => t * t * t,
17
+ easeOutCubic: (t) => --t * t * t + 1,
18
+ easeInOutCubic: (t) => t < 0.5 ? 4 * t * t * t : (t - 1) * (2 * t - 2) * (2 * t - 2) + 1
19
+ };
20
+ class PulseEffect extends BaseEffect {
21
+ constructor(config = {}) {
22
+ super(config);
23
+ __privateAdd(this, _minScale, 0.95);
24
+ __privateAdd(this, _maxScale, 1.05);
25
+ __privateAdd(this, _speed, 2e-3);
26
+ __privateAdd(this, _easingFn, easing.easeInOutQuad);
27
+ __privateSet(this, _minScale, config.minScale || 0.95);
28
+ __privateSet(this, _maxScale, config.maxScale || 1.05);
29
+ __privateSet(this, _speed, config.speed || 2e-3);
30
+ __privateSet(this, _easingFn, easing[config.easing] || easing.easeInOutQuad);
31
+ }
32
+ render(text, elapsed, context = {}) {
33
+ const element = context.element;
34
+ if (!element) return text;
35
+ const time = elapsed * __privateGet(this, _speed);
36
+ const pulse2 = (Math.sin(time) + 1) / 2;
37
+ const scale = __privateGet(this, _minScale) + (__privateGet(this, _maxScale) - __privateGet(this, _minScale)) * pulse2;
38
+ element.style.transform = `scale(${scale})`;
39
+ element.style.transformOrigin = "center";
40
+ return text;
41
+ }
42
+ }
43
+ _minScale = new WeakMap();
44
+ _maxScale = new WeakMap();
45
+ _speed = new WeakMap();
46
+ _easingFn = new WeakMap();
47
+ const pulse = /* @__PURE__ */ Object.freeze(/* @__PURE__ */ Object.defineProperty({
48
+ __proto__: null,
49
+ PulseEffect
50
+ }, Symbol.toStringTag, { value: "Module" }));
51
+ class WaveEffect extends BaseEffect {
52
+ constructor(config = {}) {
53
+ super(config);
54
+ __privateAdd(this, _amplitude, 3);
55
+ __privateAdd(this, _frequency, 0.8);
56
+ __privateAdd(this, _speed2, 2e-3);
57
+ __privateAdd(this, _easingFn2, easing.linear);
58
+ __privateSet(this, _amplitude, config.amplitude || 3);
59
+ __privateSet(this, _frequency, config.frequency || 0.8);
60
+ __privateSet(this, _speed2, config.speed || 2e-3);
61
+ __privateSet(this, _easingFn2, easing[config.easing] || easing.linear);
62
+ }
63
+ render(text, elapsed, context = {}) {
64
+ const lines = text.split("\n");
65
+ const time = elapsed * __privateGet(this, _speed2);
66
+ const waved = lines.map((line, i) => {
67
+ const offset = Math.sin(i * __privateGet(this, _frequency) + time) * __privateGet(this, _amplitude);
68
+ const charOffset = Math.round(offset);
69
+ if (charOffset > 0) {
70
+ return " ".repeat(charOffset) + line;
71
+ } else if (charOffset < 0) {
72
+ const absOffset = Math.abs(charOffset);
73
+ const trimmed = line.replace(/^ {1,}/, (spaces) => {
74
+ const trimAmount = Math.min(spaces.length, absOffset);
75
+ return spaces.slice(trimAmount);
76
+ });
77
+ return trimmed;
78
+ }
79
+ return line;
80
+ });
81
+ return waved.join("\n");
82
+ }
83
+ }
84
+ _amplitude = new WeakMap();
85
+ _frequency = new WeakMap();
86
+ _speed2 = new WeakMap();
87
+ _easingFn2 = new WeakMap();
88
+ const wave = /* @__PURE__ */ Object.freeze(/* @__PURE__ */ Object.defineProperty({
89
+ __proto__: null,
90
+ WaveEffect
91
+ }, Symbol.toStringTag, { value: "Module" }));
92
+ class ColorCycleEffect extends BaseEffect {
93
+ constructor(config = {}) {
94
+ super(config);
95
+ __privateAdd(this, _speed3, 1e-3);
96
+ __privateAdd(this, _spread, 10);
97
+ __privateAdd(this, _saturation, 70);
98
+ __privateAdd(this, _lightness, 50);
99
+ __privateSet(this, _speed3, config.speed || 1e-3);
100
+ __privateSet(this, _spread, config.spread || 10);
101
+ __privateSet(this, _saturation, config.saturation || 70);
102
+ __privateSet(this, _lightness, config.lightness || 50);
103
+ }
104
+ render(text, elapsed, context = {}) {
105
+ const lines = text.split("\n");
106
+ let charIndex = 0;
107
+ const time = elapsed * __privateGet(this, _speed3);
108
+ const colored = lines.map((line, lineIndex) => {
109
+ return line.split("").map((char, colIndex) => {
110
+ if (char === " ") return char;
111
+ const hue = (time + charIndex * __privateGet(this, _spread)) % 360;
112
+ charIndex++;
113
+ return `<span style="color: hsl(${hue}, ${__privateGet(this, _saturation)}%, ${__privateGet(this, _lightness)}%)">${char}</span>`;
114
+ }).join("");
115
+ });
116
+ const html = colored.join("<br>");
117
+ return { __html: html, __text: text };
118
+ }
119
+ }
120
+ _speed3 = new WeakMap();
121
+ _spread = new WeakMap();
122
+ _saturation = new WeakMap();
123
+ _lightness = new WeakMap();
124
+ const colorCycle = /* @__PURE__ */ Object.freeze(/* @__PURE__ */ Object.defineProperty({
125
+ __proto__: null,
126
+ ColorCycleEffect
127
+ }, Symbol.toStringTag, { value: "Module" }));
128
+ class ColorGradientEffect extends BaseEffect {
129
+ // 'lightness', 'saturation', 'both'
130
+ constructor(config = {}) {
131
+ super(config);
132
+ __privateAdd(this, _ColorGradientEffect_instances);
133
+ __privateAdd(this, _baseColor, "#00aaff");
134
+ // Azure blue
135
+ __privateAdd(this, _variations, 5);
136
+ __privateAdd(this, _speed4, 1e-3);
137
+ __privateAdd(this, _mode, "lightness");
138
+ __privateSet(this, _baseColor, config.baseColor || "#00aaff");
139
+ __privateSet(this, _variations, config.variations || 5);
140
+ __privateSet(this, _speed4, config.speed || 1e-3);
141
+ __privateSet(this, _mode, config.mode || "lightness");
142
+ }
143
+ render(text, elapsed, context = {}) {
144
+ const lines = text.split("\n");
145
+ const baseHSL = __privateMethod(this, _ColorGradientEffect_instances, hexToHSL_fn).call(this, __privateGet(this, _baseColor));
146
+ const time = elapsed * __privateGet(this, _speed4);
147
+ let charIndex = 0;
148
+ const totalChars = text.replace(/\s/g, "").length;
149
+ const colored = lines.map((line) => {
150
+ return line.split("").map((char) => {
151
+ if (char === " " || char === "\n") return char;
152
+ const color = __privateMethod(this, _ColorGradientEffect_instances, getVariation_fn).call(this, baseHSL, charIndex, totalChars, time);
153
+ charIndex++;
154
+ return `<span style="color: ${color}">${char}</span>`;
155
+ }).join("");
156
+ });
157
+ const html = colored.join("<br>");
158
+ return { __html: html, __text: text };
159
+ }
160
+ }
161
+ _baseColor = new WeakMap();
162
+ _variations = new WeakMap();
163
+ _speed4 = new WeakMap();
164
+ _mode = new WeakMap();
165
+ _ColorGradientEffect_instances = new WeakSet();
166
+ /**
167
+ * Convert hex to HSL
168
+ */
169
+ hexToHSL_fn = function(hex) {
170
+ hex = hex.replace("#", "");
171
+ const r = parseInt(hex.substr(0, 2), 16) / 255;
172
+ const g = parseInt(hex.substr(2, 2), 16) / 255;
173
+ const b = parseInt(hex.substr(4, 2), 16) / 255;
174
+ const max = Math.max(r, g, b);
175
+ const min = Math.min(r, g, b);
176
+ let h, s, l = (max + min) / 2;
177
+ if (max === min) {
178
+ h = s = 0;
179
+ } else {
180
+ const d = max - min;
181
+ s = l > 0.5 ? d / (2 - max - min) : d / (max + min);
182
+ switch (max) {
183
+ case r:
184
+ h = ((g - b) / d + (g < b ? 6 : 0)) / 6;
185
+ break;
186
+ case g:
187
+ h = ((b - r) / d + 2) / 6;
188
+ break;
189
+ case b:
190
+ h = ((r - g) / d + 4) / 6;
191
+ break;
192
+ }
193
+ }
194
+ return {
195
+ h: Math.round(h * 360),
196
+ s: Math.round(s * 100),
197
+ l: Math.round(l * 100)
198
+ };
199
+ };
200
+ /**
201
+ * Generate color variation
202
+ */
203
+ getVariation_fn = function(baseHSL, index, total, time) {
204
+ const { h, s, l } = baseHSL;
205
+ const progress = index / total + time;
206
+ const isGrayscale = s < 5;
207
+ let newH = h;
208
+ let newS = s;
209
+ let newL = l;
210
+ switch (__privateGet(this, _mode)) {
211
+ case "lightness":
212
+ newL = 20 + progress % 1 * 60;
213
+ break;
214
+ case "saturation":
215
+ if (isGrayscale) {
216
+ newH = progress % 1 * 360;
217
+ newS = 30 + progress % 1 * 70;
218
+ } else {
219
+ newS = 30 + progress % 1 * 70;
220
+ }
221
+ break;
222
+ case "both":
223
+ if (isGrayscale) {
224
+ newH = progress % 1 * 360;
225
+ newL = 30 + (Math.sin(progress * Math.PI * 2) * 0.5 + 0.5) * 50;
226
+ newS = 40 + (Math.cos(progress * Math.PI * 2) * 0.5 + 0.5) * 60;
227
+ } else {
228
+ newL = 30 + (Math.sin(progress * Math.PI * 2) * 0.5 + 0.5) * 50;
229
+ newS = 40 + (Math.cos(progress * Math.PI * 2) * 0.5 + 0.5) * 60;
230
+ }
231
+ break;
232
+ case "hue-shift":
233
+ newH = (h + progress % 1 * 60 - 30 + 360) % 360;
234
+ break;
235
+ }
236
+ return `hsl(${newH}, ${newS}%, ${newL}%)`;
237
+ };
238
+ const colorGradient = /* @__PURE__ */ Object.freeze(/* @__PURE__ */ Object.defineProperty({
239
+ __proto__: null,
240
+ ColorGradientEffect
241
+ }, Symbol.toStringTag, { value: "Module" }));
242
+ class PerspectiveEffect extends BaseEffect {
243
+ constructor(config = {}) {
244
+ super(config);
245
+ __privateAdd(this, _rotateX, 0);
246
+ __privateAdd(this, _rotateY, 0);
247
+ __privateAdd(this, _rotateZ, 0);
248
+ __privateAdd(this, _perspective, 1e3);
249
+ __privateAdd(this, _speed5, 1e-3);
250
+ __privateSet(this, _rotateX, config.rotateX || 0);
251
+ __privateSet(this, _rotateY, config.rotateY || 0);
252
+ __privateSet(this, _rotateZ, config.rotateZ || 0);
253
+ __privateSet(this, _perspective, config.perspective || 1e3);
254
+ __privateSet(this, _speed5, config.speed || 1e-3);
255
+ }
256
+ render(text, elapsed, context = {}) {
257
+ const element = context.element;
258
+ if (!element) return text;
259
+ const time = elapsed * __privateGet(this, _speed5);
260
+ const rx = __privateGet(this, _rotateX) * Math.sin(time);
261
+ const ry = __privateGet(this, _rotateY) * Math.cos(time);
262
+ const rz = __privateGet(this, _rotateZ) * Math.sin(time * 0.5);
263
+ element.style.perspective = `${__privateGet(this, _perspective)}px`;
264
+ element.style.transform = `rotateX(${rx}deg) rotateY(${ry}deg) rotateZ(${rz}deg)`;
265
+ element.style.transformStyle = "preserve-3d";
266
+ return text;
267
+ }
268
+ }
269
+ _rotateX = new WeakMap();
270
+ _rotateY = new WeakMap();
271
+ _rotateZ = new WeakMap();
272
+ _perspective = new WeakMap();
273
+ _speed5 = new WeakMap();
274
+ const perspective = /* @__PURE__ */ Object.freeze(/* @__PURE__ */ Object.defineProperty({
275
+ __proto__: null,
276
+ PerspectiveEffect
277
+ }, Symbol.toStringTag, { value: "Module" }));
278
+ export {
279
+ colorGradient as a,
280
+ perspective as b,
281
+ colorCycle as c,
282
+ easing as e,
283
+ pulse as p,
284
+ wave as w
285
+ };