@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.
- package/LICENSE +21 -0
- package/README.md +669 -0
- package/dist/ascii-art-DCOQt4Se.js +285 -0
- package/dist/ascii-script.js +892 -0
- package/dist/procedural-BY9bCgT3.js +66 -0
- package/dist/text-CKJIlRsq.js +262 -0
- package/package.json +49 -0
|
@@ -0,0 +1,66 @@
|
|
|
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 _lineHeight, _opacity, _speed, _color;
|
|
9
|
+
import { B as BaseEffect } from "./text-CKJIlRsq.js";
|
|
10
|
+
class ScanlinesEffect extends BaseEffect {
|
|
11
|
+
constructor(config = {}) {
|
|
12
|
+
super(config);
|
|
13
|
+
__privateAdd(this, _lineHeight, 2);
|
|
14
|
+
__privateAdd(this, _opacity, 0.1);
|
|
15
|
+
__privateAdd(this, _speed, 0.5);
|
|
16
|
+
__privateAdd(this, _color, "rgba(0, 0, 0, 0.3)");
|
|
17
|
+
__privateSet(this, _lineHeight, config.lineHeight || 2);
|
|
18
|
+
__privateSet(this, _opacity, config.opacity || 0.1);
|
|
19
|
+
__privateSet(this, _speed, config.speed || 0.5);
|
|
20
|
+
__privateSet(this, _color, config.color || __privateGet(this, _color));
|
|
21
|
+
}
|
|
22
|
+
render(text, elapsed, context = {}) {
|
|
23
|
+
const element = context.element;
|
|
24
|
+
if (!element) return text;
|
|
25
|
+
if (!element.querySelector(".ascii-scanlines")) {
|
|
26
|
+
const overlay = document.createElement("div");
|
|
27
|
+
overlay.className = "ascii-scanlines";
|
|
28
|
+
overlay.style.cssText = `
|
|
29
|
+
position: absolute;
|
|
30
|
+
top: 0;
|
|
31
|
+
left: 0;
|
|
32
|
+
width: 100%;
|
|
33
|
+
height: 100%;
|
|
34
|
+
pointer-events: none;
|
|
35
|
+
background: repeating-linear-gradient(
|
|
36
|
+
0deg,
|
|
37
|
+
${__privateGet(this, _color)} 0px,
|
|
38
|
+
transparent ${__privateGet(this, _lineHeight)}px
|
|
39
|
+
);
|
|
40
|
+
opacity: ${__privateGet(this, _opacity)};
|
|
41
|
+
animation: scanlines ${__privateGet(this, _speed)}s linear infinite;
|
|
42
|
+
`;
|
|
43
|
+
if (!document.getElementById("scanlines-animation")) {
|
|
44
|
+
const style = document.createElement("style");
|
|
45
|
+
style.id = "scanlines-animation";
|
|
46
|
+
style.textContent = `
|
|
47
|
+
@keyframes scanlines {
|
|
48
|
+
0% { transform: translateY(0); }
|
|
49
|
+
100% { transform: translateY(${__privateGet(this, _lineHeight)}px); }
|
|
50
|
+
}
|
|
51
|
+
`;
|
|
52
|
+
document.head.appendChild(style);
|
|
53
|
+
}
|
|
54
|
+
element.style.position = "relative";
|
|
55
|
+
element.appendChild(overlay);
|
|
56
|
+
}
|
|
57
|
+
return text;
|
|
58
|
+
}
|
|
59
|
+
}
|
|
60
|
+
_lineHeight = new WeakMap();
|
|
61
|
+
_opacity = new WeakMap();
|
|
62
|
+
_speed = new WeakMap();
|
|
63
|
+
_color = new WeakMap();
|
|
64
|
+
export {
|
|
65
|
+
ScanlinesEffect
|
|
66
|
+
};
|
|
@@ -0,0 +1,262 @@
|
|
|
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 _config, _duration, _startTime, _intensity, _speed, _offsetRange, _corruptChars, _charset, _speed2, _density, _columns, _initialized, _MatrixRainEffect_instances, initColumns_fn, randomChar_fn, _charset2, _revealMode, _easingFn, _ScrambleEffect_instances, renderProgressive_fn, renderRandom_fn, randomChar_fn2, _placeholder, _easingFn2, _speed3, _cursor, _showCursor, _blinkSpeed;
|
|
10
|
+
import { e as easing } from "./ascii-art-DCOQt4Se.js";
|
|
11
|
+
class BaseEffect {
|
|
12
|
+
constructor(config = {}) {
|
|
13
|
+
__privateAdd(this, _config, {});
|
|
14
|
+
__privateAdd(this, _duration, 1e3);
|
|
15
|
+
__privateAdd(this, _startTime, 0);
|
|
16
|
+
__privateSet(this, _config, config);
|
|
17
|
+
__privateSet(this, _duration, config.duration || 1e3);
|
|
18
|
+
}
|
|
19
|
+
/**
|
|
20
|
+
* Render effect (override in subclasses)
|
|
21
|
+
* @param {string} text - Input text
|
|
22
|
+
* @param {number} elapsed - Time elapsed since start
|
|
23
|
+
* @param {Object} context - Additional context
|
|
24
|
+
* @returns {string} Processed text
|
|
25
|
+
*/
|
|
26
|
+
render(text, elapsed, context = {}) {
|
|
27
|
+
throw new Error("render() must be implemented");
|
|
28
|
+
}
|
|
29
|
+
/**
|
|
30
|
+
* Get progress (0-1)
|
|
31
|
+
*/
|
|
32
|
+
getProgress(elapsed) {
|
|
33
|
+
return Math.min(elapsed / __privateGet(this, _duration), 1);
|
|
34
|
+
}
|
|
35
|
+
get duration() {
|
|
36
|
+
return __privateGet(this, _duration);
|
|
37
|
+
}
|
|
38
|
+
get config() {
|
|
39
|
+
return __privateGet(this, _config);
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
_config = new WeakMap();
|
|
43
|
+
_duration = new WeakMap();
|
|
44
|
+
_startTime = new WeakMap();
|
|
45
|
+
class GlitchEffect extends BaseEffect {
|
|
46
|
+
constructor(config = {}) {
|
|
47
|
+
super(config);
|
|
48
|
+
__privateAdd(this, _intensity, 0.1);
|
|
49
|
+
__privateAdd(this, _speed, 0.05);
|
|
50
|
+
__privateAdd(this, _offsetRange, 5);
|
|
51
|
+
__privateAdd(this, _corruptChars, "▓▒░█▀▄");
|
|
52
|
+
__privateSet(this, _intensity, config.intensity || 0.1);
|
|
53
|
+
__privateSet(this, _speed, config.speed || 0.05);
|
|
54
|
+
__privateSet(this, _offsetRange, config.offsetRange || 5);
|
|
55
|
+
__privateSet(this, _corruptChars, config.corruptChars || __privateGet(this, _corruptChars));
|
|
56
|
+
}
|
|
57
|
+
render(text, elapsed, context = {}) {
|
|
58
|
+
const element = context.element;
|
|
59
|
+
const lines = text.split("\n");
|
|
60
|
+
const glitched = lines.map((line, i) => {
|
|
61
|
+
if (Math.random() < __privateGet(this, _intensity)) {
|
|
62
|
+
const offset = Math.floor(Math.random() * __privateGet(this, _offsetRange) * 2) - __privateGet(this, _offsetRange);
|
|
63
|
+
const spaces = " ".repeat(Math.max(0, offset));
|
|
64
|
+
line = spaces + line;
|
|
65
|
+
}
|
|
66
|
+
return line.split("").map((char) => {
|
|
67
|
+
if (char === " " || char === "\n") return char;
|
|
68
|
+
if (Math.random() < __privateGet(this, _intensity)) {
|
|
69
|
+
return __privateGet(this, _corruptChars)[Math.floor(Math.random() * __privateGet(this, _corruptChars).length)];
|
|
70
|
+
}
|
|
71
|
+
return char;
|
|
72
|
+
}).join("");
|
|
73
|
+
});
|
|
74
|
+
if (element && Math.random() < __privateGet(this, _intensity) * 0.5) {
|
|
75
|
+
const offsetX = (Math.random() - 0.5) * 4;
|
|
76
|
+
const offsetY = (Math.random() - 0.5) * 4;
|
|
77
|
+
element.style.transform = `translate(${offsetX}px, ${offsetY}px)`;
|
|
78
|
+
} else if (element) {
|
|
79
|
+
element.style.transform = "none";
|
|
80
|
+
}
|
|
81
|
+
return glitched.join("\n");
|
|
82
|
+
}
|
|
83
|
+
}
|
|
84
|
+
_intensity = new WeakMap();
|
|
85
|
+
_speed = new WeakMap();
|
|
86
|
+
_offsetRange = new WeakMap();
|
|
87
|
+
_corruptChars = new WeakMap();
|
|
88
|
+
const glitch = /* @__PURE__ */ Object.freeze(/* @__PURE__ */ Object.defineProperty({
|
|
89
|
+
__proto__: null,
|
|
90
|
+
GlitchEffect
|
|
91
|
+
}, Symbol.toStringTag, { value: "Module" }));
|
|
92
|
+
class MatrixRainEffect extends BaseEffect {
|
|
93
|
+
constructor(config = {}) {
|
|
94
|
+
super(config);
|
|
95
|
+
__privateAdd(this, _MatrixRainEffect_instances);
|
|
96
|
+
__privateAdd(this, _charset, "ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789@#$%^&*");
|
|
97
|
+
__privateAdd(this, _speed2, 0.05);
|
|
98
|
+
__privateAdd(this, _density, 0.05);
|
|
99
|
+
__privateAdd(this, _columns, []);
|
|
100
|
+
__privateAdd(this, _initialized, false);
|
|
101
|
+
__privateSet(this, _charset, config.charset || __privateGet(this, _charset));
|
|
102
|
+
__privateSet(this, _speed2, config.speed || 0.05);
|
|
103
|
+
__privateSet(this, _density, config.density || 0.05);
|
|
104
|
+
}
|
|
105
|
+
render(text, elapsed, context = {}) {
|
|
106
|
+
var _a;
|
|
107
|
+
const lines = text.split("\n");
|
|
108
|
+
if (!__privateGet(this, _initialized)) {
|
|
109
|
+
__privateMethod(this, _MatrixRainEffect_instances, initColumns_fn).call(this, ((_a = lines[0]) == null ? void 0 : _a.length) || 0);
|
|
110
|
+
__privateSet(this, _initialized, true);
|
|
111
|
+
}
|
|
112
|
+
const result = lines.map((line, lineIndex) => {
|
|
113
|
+
return line.split("").map((char, colIndex) => {
|
|
114
|
+
const column = __privateGet(this, _columns)[colIndex];
|
|
115
|
+
if (!column) return char;
|
|
116
|
+
column.y += __privateGet(this, _speed2);
|
|
117
|
+
if (column.y > lines.length) {
|
|
118
|
+
column.y = -Math.random() * 10;
|
|
119
|
+
}
|
|
120
|
+
if (Math.abs(lineIndex - column.y) < 1) {
|
|
121
|
+
return __privateMethod(this, _MatrixRainEffect_instances, randomChar_fn).call(this);
|
|
122
|
+
}
|
|
123
|
+
if (lineIndex > column.y && lineIndex < column.y + 5) {
|
|
124
|
+
return Math.random() < 0.3 ? __privateMethod(this, _MatrixRainEffect_instances, randomChar_fn).call(this) : char;
|
|
125
|
+
}
|
|
126
|
+
return char;
|
|
127
|
+
}).join("");
|
|
128
|
+
});
|
|
129
|
+
return result.join("\n");
|
|
130
|
+
}
|
|
131
|
+
}
|
|
132
|
+
_charset = new WeakMap();
|
|
133
|
+
_speed2 = new WeakMap();
|
|
134
|
+
_density = new WeakMap();
|
|
135
|
+
_columns = new WeakMap();
|
|
136
|
+
_initialized = new WeakMap();
|
|
137
|
+
_MatrixRainEffect_instances = new WeakSet();
|
|
138
|
+
initColumns_fn = function(width) {
|
|
139
|
+
__privateSet(this, _columns, Array(width).fill(null).map(() => ({
|
|
140
|
+
y: -Math.random() * 20,
|
|
141
|
+
speed: 0.5 + Math.random() * 0.5
|
|
142
|
+
})));
|
|
143
|
+
};
|
|
144
|
+
randomChar_fn = function() {
|
|
145
|
+
return __privateGet(this, _charset)[Math.floor(Math.random() * __privateGet(this, _charset).length)];
|
|
146
|
+
};
|
|
147
|
+
const matrixRain = /* @__PURE__ */ Object.freeze(/* @__PURE__ */ Object.defineProperty({
|
|
148
|
+
__proto__: null,
|
|
149
|
+
MatrixRainEffect
|
|
150
|
+
}, Symbol.toStringTag, { value: "Module" }));
|
|
151
|
+
class ScrambleEffect extends BaseEffect {
|
|
152
|
+
constructor(config = {}) {
|
|
153
|
+
super(config);
|
|
154
|
+
__privateAdd(this, _ScrambleEffect_instances);
|
|
155
|
+
__privateAdd(this, _charset2, "!@#$%^&*()_+-=[]{}|;:,.<>?/~`");
|
|
156
|
+
__privateAdd(this, _revealMode, "progressive");
|
|
157
|
+
// 'progressive' | 'random'
|
|
158
|
+
__privateAdd(this, _easingFn, easing.easeOutQuad);
|
|
159
|
+
__privateSet(this, _charset2, config.charset || __privateGet(this, _charset2));
|
|
160
|
+
__privateSet(this, _revealMode, config.revealMode || "progressive");
|
|
161
|
+
__privateSet(this, _easingFn, easing[config.easing] || easing.easeOutQuad);
|
|
162
|
+
}
|
|
163
|
+
render(text, elapsed, context = {}) {
|
|
164
|
+
const progress = __privateGet(this, _easingFn).call(this, this.getProgress(elapsed));
|
|
165
|
+
const chars = text.split("");
|
|
166
|
+
if (__privateGet(this, _revealMode) === "progressive") {
|
|
167
|
+
return __privateMethod(this, _ScrambleEffect_instances, renderProgressive_fn).call(this, chars, progress);
|
|
168
|
+
} else {
|
|
169
|
+
return __privateMethod(this, _ScrambleEffect_instances, renderRandom_fn).call(this, chars, progress);
|
|
170
|
+
}
|
|
171
|
+
}
|
|
172
|
+
}
|
|
173
|
+
_charset2 = new WeakMap();
|
|
174
|
+
_revealMode = new WeakMap();
|
|
175
|
+
_easingFn = new WeakMap();
|
|
176
|
+
_ScrambleEffect_instances = new WeakSet();
|
|
177
|
+
renderProgressive_fn = function(chars, progress) {
|
|
178
|
+
const revealCount = Math.floor(chars.length * progress);
|
|
179
|
+
return chars.map((char, i) => {
|
|
180
|
+
if (i < revealCount) return char;
|
|
181
|
+
if (char === " " || char === "\n") return char;
|
|
182
|
+
return __privateMethod(this, _ScrambleEffect_instances, randomChar_fn2).call(this);
|
|
183
|
+
}).join("");
|
|
184
|
+
};
|
|
185
|
+
renderRandom_fn = function(chars, progress) {
|
|
186
|
+
return chars.map((char) => {
|
|
187
|
+
if (char === " " || char === "\n") return char;
|
|
188
|
+
if (Math.random() < progress) return char;
|
|
189
|
+
return __privateMethod(this, _ScrambleEffect_instances, randomChar_fn2).call(this);
|
|
190
|
+
}).join("");
|
|
191
|
+
};
|
|
192
|
+
randomChar_fn2 = function() {
|
|
193
|
+
return __privateGet(this, _charset2)[Math.floor(Math.random() * __privateGet(this, _charset2).length)];
|
|
194
|
+
};
|
|
195
|
+
const scramble = /* @__PURE__ */ Object.freeze(/* @__PURE__ */ Object.defineProperty({
|
|
196
|
+
__proto__: null,
|
|
197
|
+
ScrambleEffect
|
|
198
|
+
}, Symbol.toStringTag, { value: "Module" }));
|
|
199
|
+
class RevealEffect extends BaseEffect {
|
|
200
|
+
constructor(config = {}) {
|
|
201
|
+
super(config);
|
|
202
|
+
__privateAdd(this, _placeholder, "█");
|
|
203
|
+
__privateAdd(this, _easingFn2, easing.easeOutCubic);
|
|
204
|
+
__privateSet(this, _placeholder, config.placeholder || "█");
|
|
205
|
+
__privateSet(this, _easingFn2, easing[config.easing] || easing.easeOutCubic);
|
|
206
|
+
}
|
|
207
|
+
render(text, elapsed, context = {}) {
|
|
208
|
+
const progress = __privateGet(this, _easingFn2).call(this, this.getProgress(elapsed));
|
|
209
|
+
const chars = text.split("");
|
|
210
|
+
const revealCount = Math.floor(chars.length * progress);
|
|
211
|
+
return chars.map((char, i) => {
|
|
212
|
+
if (i < revealCount) return char;
|
|
213
|
+
if (char === " " || char === "\n") return char;
|
|
214
|
+
return __privateGet(this, _placeholder);
|
|
215
|
+
}).join("");
|
|
216
|
+
}
|
|
217
|
+
}
|
|
218
|
+
_placeholder = new WeakMap();
|
|
219
|
+
_easingFn2 = new WeakMap();
|
|
220
|
+
const reveal = /* @__PURE__ */ Object.freeze(/* @__PURE__ */ Object.defineProperty({
|
|
221
|
+
__proto__: null,
|
|
222
|
+
RevealEffect
|
|
223
|
+
}, Symbol.toStringTag, { value: "Module" }));
|
|
224
|
+
class TypewriterEffect extends BaseEffect {
|
|
225
|
+
constructor(config = {}) {
|
|
226
|
+
super(config);
|
|
227
|
+
__privateAdd(this, _speed3, 50);
|
|
228
|
+
// ms per character
|
|
229
|
+
__privateAdd(this, _cursor, "|");
|
|
230
|
+
__privateAdd(this, _showCursor, true);
|
|
231
|
+
__privateAdd(this, _blinkSpeed, 500);
|
|
232
|
+
__privateSet(this, _speed3, config.speed || 50);
|
|
233
|
+
__privateSet(this, _cursor, config.cursor || "|");
|
|
234
|
+
__privateSet(this, _showCursor, config.showCursor !== false);
|
|
235
|
+
__privateSet(this, _blinkSpeed, config.blinkSpeed || 500);
|
|
236
|
+
}
|
|
237
|
+
render(text, elapsed, context = {}) {
|
|
238
|
+
const charCount = Math.floor(elapsed / __privateGet(this, _speed3));
|
|
239
|
+
const revealed = text.slice(0, Math.min(charCount, text.length));
|
|
240
|
+
if (__privateGet(this, _showCursor) && charCount < text.length) {
|
|
241
|
+
const blink = Math.floor(elapsed / __privateGet(this, _blinkSpeed)) % 2 === 0;
|
|
242
|
+
return revealed + (blink ? __privateGet(this, _cursor) : "");
|
|
243
|
+
}
|
|
244
|
+
return revealed;
|
|
245
|
+
}
|
|
246
|
+
}
|
|
247
|
+
_speed3 = new WeakMap();
|
|
248
|
+
_cursor = new WeakMap();
|
|
249
|
+
_showCursor = new WeakMap();
|
|
250
|
+
_blinkSpeed = new WeakMap();
|
|
251
|
+
const typewriter = /* @__PURE__ */ Object.freeze(/* @__PURE__ */ Object.defineProperty({
|
|
252
|
+
__proto__: null,
|
|
253
|
+
TypewriterEffect
|
|
254
|
+
}, Symbol.toStringTag, { value: "Module" }));
|
|
255
|
+
export {
|
|
256
|
+
BaseEffect as B,
|
|
257
|
+
glitch as g,
|
|
258
|
+
matrixRain as m,
|
|
259
|
+
reveal as r,
|
|
260
|
+
scramble as s,
|
|
261
|
+
typewriter as t
|
|
262
|
+
};
|
package/package.json
ADDED
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@jyiro/ascii-script",
|
|
3
|
+
"version": "0.1.0",
|
|
4
|
+
"description": "Micro-librería para render y animación ASCII en el DOM",
|
|
5
|
+
"type": "module",
|
|
6
|
+
"main": "./dist/ascii-script.js",
|
|
7
|
+
"module": "./dist/ascii-script.js",
|
|
8
|
+
"exports": {
|
|
9
|
+
".": {
|
|
10
|
+
"import": "./dist/ascii-script.js"
|
|
11
|
+
}
|
|
12
|
+
},
|
|
13
|
+
"files": [
|
|
14
|
+
"dist"
|
|
15
|
+
],
|
|
16
|
+
"scripts": {
|
|
17
|
+
"dev": "vite",
|
|
18
|
+
"build": "vite build",
|
|
19
|
+
"test": "vitest",
|
|
20
|
+
"test:ui": "vitest --ui",
|
|
21
|
+
"lint": "eslint src --ext .js",
|
|
22
|
+
"preview": "vite preview"
|
|
23
|
+
},
|
|
24
|
+
"keywords": [
|
|
25
|
+
"ascii",
|
|
26
|
+
"animation",
|
|
27
|
+
"effects",
|
|
28
|
+
"dom",
|
|
29
|
+
"canvas",
|
|
30
|
+
"art"
|
|
31
|
+
],
|
|
32
|
+
"author": "Jyiro <https://github.com/Jyiro>",
|
|
33
|
+
"license": "MIT",
|
|
34
|
+
"repository": {
|
|
35
|
+
"type": "git",
|
|
36
|
+
"url": "https://github.com/Jyiro/ascii-script.git"
|
|
37
|
+
},
|
|
38
|
+
"homepage": "https://github.com/Jyiro/ascii-script#readme",
|
|
39
|
+
"bugs": {
|
|
40
|
+
"url": "https://github.com/Jyiro/ascii-script/issues"
|
|
41
|
+
},
|
|
42
|
+
"devDependencies": {
|
|
43
|
+
"eslint": "^8.56.0",
|
|
44
|
+
"happy-dom": "^20.6.1",
|
|
45
|
+
"jsdom": "^28.1.0",
|
|
46
|
+
"vite": "^5.0.0",
|
|
47
|
+
"vitest": "^1.0.0"
|
|
48
|
+
}
|
|
49
|
+
}
|