rrjs 1.0.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/README.md ADDED
@@ -0,0 +1,73 @@
1
+ # RRJS - Rick Roll JS
2
+
3
+ A simple solution to annoy anyone poking around your website.
4
+
5
+ ## Quick Start
6
+
7
+ ### Browser (HTML) - Direct Link (recommended)
8
+ Just put this in your .html file.
9
+
10
+ ```html
11
+ <script src="https://raw.githubusercontent.com/terraegg/rrjs/main/asciiPlayer.js"></script><script>new AsciiPlayer({autoPlay:1,loop:1}).loadAnimation('https://raw.githubusercontent.com/terraegg/rrjs/main/data/ascii_animation.json')</script>
12
+ ```
13
+
14
+ ### Browser (HTML) - NPM Package
15
+
16
+ ```bash
17
+ npm install rrjs
18
+ ```
19
+
20
+ Then in your HTML:
21
+
22
+ ```html
23
+ <script src="node_modules/rrjs/asciiPlayer.js"></script>
24
+ <script>
25
+ const player = new AsciiPlayer({ autoPlay: true, loop: true });
26
+ player.loadAnimation('node_modules/rrjs/data/ascii_animation.json');
27
+ </script>
28
+ ```
29
+
30
+ Or with a bundler (Webpack/Vite):
31
+
32
+ ```javascript
33
+ import AsciiPlayer from 'rrjs';
34
+
35
+ const player = new AsciiPlayer({ autoPlay: true, loop: true });
36
+ player.loadAnimation('node_modules/rrjs/data/ascii_animation.json');
37
+ ```
38
+
39
+ ## JSON Format
40
+
41
+ If you decide you want to change out the ASCII art, edit in the following format:
42
+
43
+ ```json
44
+ {
45
+ "frame_count": 23,
46
+ "width_chars": 80,
47
+ "frames": [
48
+ {
49
+ "frame": 0,
50
+ "duration_ms": 100,
51
+ "ascii": [
52
+ "line 1 of ascii art",
53
+ "line 2 of ascii art",
54
+ "..."
55
+ ]
56
+ },
57
+ ...
58
+ ]
59
+ }
60
+ ```
61
+
62
+ ## API
63
+
64
+ ### Constructor
65
+
66
+ ```javascript
67
+ const player = new AsciiPlayer({
68
+ animationData: null,
69
+ frameDelay: 100,
70
+ autoPlay: true,
71
+ loop: true
72
+ });
73
+ ```
package/asciiPlayer.js ADDED
@@ -0,0 +1,109 @@
1
+ (function(globalThis) {
2
+ 'use strict';
3
+
4
+ class AsciiPlayer {
5
+ constructor(options = {}) {
6
+ this.animationData = options.animationData || null;
7
+ this.frameDelay = options.frameDelay || 100;
8
+ this.autoPlay = options.autoPlay !== false;
9
+ this.loop = options.loop !== false;
10
+
11
+ this.currentFrame = 0;
12
+ this.isPlaying = false;
13
+ this.animationId = null;
14
+ this.lastFrameTime = 0;
15
+ }
16
+
17
+
18
+ async loadAnimation(dataOrUrl) {
19
+ if (typeof dataOrUrl === 'string') {
20
+ const response = await fetch(dataOrUrl);
21
+ this.animationData = await response.json();
22
+ } else if (typeof dataOrUrl === 'object') {
23
+ this.animationData = dataOrUrl;
24
+ }
25
+
26
+ if (this.autoPlay) {
27
+ this.play();
28
+ }
29
+ return this.animationData;
30
+ }
31
+
32
+ getCurrentFrame() {
33
+ if (!this.animationData || !this.animationData.frames) {
34
+ return null;
35
+ }
36
+ return this.animationData.frames[this.currentFrame];
37
+ }
38
+
39
+ renderFrame() {
40
+ const frame = this.getCurrentFrame();
41
+ if (!frame) return;
42
+
43
+ if (Array.isArray(frame.ascii)) {
44
+ console.log(frame.ascii.join('\n'));
45
+ } else if (typeof frame.ascii === 'string') {
46
+ console.log(frame.ascii);
47
+ }
48
+ }
49
+
50
+ play() {
51
+ if (this.isPlaying) return;
52
+
53
+ this.isPlaying = true;
54
+ this.lastFrameTime = Date.now();
55
+ this._nextFrame();
56
+ }
57
+
58
+ _nextFrame() {
59
+ if (!this.isPlaying) return;
60
+
61
+ const now = Date.now();
62
+ const frame = this.getCurrentFrame();
63
+ const frameDuration = frame ? frame.duration_ms : this.frameDelay;
64
+
65
+ if (now - this.lastFrameTime >= frameDuration) {
66
+ this.renderFrame();
67
+ this.lastFrameTime = now;
68
+ this.currentFrame++;
69
+
70
+ if (this.currentFrame >= this.animationData.frame_count) {
71
+ if (this.loop) {
72
+ this.currentFrame = 0;
73
+ } else {
74
+ this.isPlaying = false;
75
+ return;
76
+ }
77
+ }
78
+ }
79
+
80
+ this.animationId = requestAnimationFrame(() => this._nextFrame());
81
+ }
82
+
83
+ goToFrame(frameNumber) {
84
+ if (frameNumber >= 0 && frameNumber < this.animationData.frame_count) {
85
+ this.currentFrame = frameNumber;
86
+ this.renderFrame();
87
+ }
88
+ }
89
+
90
+ getInfo() {
91
+ if (!this.animationData) return null;
92
+ return {
93
+ frameCount: this.animationData.frame_count,
94
+ width: this.animationData.width_chars,
95
+ currentFrame: this.currentFrame,
96
+ isPlaying: this.isPlaying
97
+ };
98
+ }
99
+ }
100
+
101
+ if (typeof module !== 'undefined' && module.exports) {
102
+ module.exports = AsciiPlayer;
103
+ } else if (typeof define === 'function' && define.amd) {
104
+ define(function() { return AsciiPlayer; });
105
+ } else {
106
+ globalThis.AsciiPlayer = AsciiPlayer;
107
+ }
108
+
109
+ })(typeof globalThis !== 'undefined' ? globalThis : typeof window !== 'undefined' ? window : typeof global !== 'undefined' ? global : this);