@yeonseong/magic-loading 0.1.0 → 0.2.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.
Files changed (2) hide show
  1. package/README.md +251 -0
  2. package/package.json +1 -1
package/README.md ADDED
@@ -0,0 +1,251 @@
1
+ # magic-loading
2
+
3
+ Turn boring loading spinners into unique fantasy magic circles.
4
+
5
+ Each text string deterministically generates a distinct magic circle with runes, alchemical symbols, concentric rings, and polygons — all rendered as resolution-independent SVG.
6
+
7
+ ## Features
8
+
9
+ - **Deterministic** — same text always produces the same magic circle
10
+ - **Framework-agnostic** — Web Component + Programmatic API
11
+ - **Lightweight** — ~5KB gzipped, zero dependencies
12
+ - **SVG-based** — crisp at any resolution
13
+ - **Animated** — determinate progress, indeterminate pulsing, burst completion
14
+ - **Customizable** — CSS custom properties for color override
15
+
16
+ ## Install
17
+
18
+ ```bash
19
+ npm install @yeonseong/magic-loading
20
+ ```
21
+
22
+ ## Quick Start
23
+
24
+ ### 1. Import
25
+
26
+ ```js
27
+ // ESM
28
+ import '@yeonseong/magic-loading';
29
+
30
+ // CommonJS
31
+ require('@yeonseong/magic-loading');
32
+ ```
33
+
34
+ ### 2. Use as Web Component
35
+
36
+ ```html
37
+ <magic-loading text="Loading..." progress="0.5" size="120"></magic-loading>
38
+ ```
39
+
40
+ That's it! The component auto-registers on import.
41
+
42
+ ---
43
+
44
+ ## Usage
45
+
46
+ ### Web Component
47
+
48
+ ```html
49
+ <script type="module">
50
+ import '@yeonseong/magic-loading';
51
+ </script>
52
+
53
+ <!-- Determinate: progress bar style (0~1) -->
54
+ <magic-loading text="Uploading file" progress="0.7" size="150"></magic-loading>
55
+
56
+ <!-- Indeterminate: pulsating animation (omit progress) -->
57
+ <magic-loading text="Connecting..." size="150"></magic-loading>
58
+ ```
59
+
60
+ #### Attributes
61
+
62
+ | Attribute | Type | Default | Description |
63
+ |-----------|------|---------|-------------|
64
+ | `text` | `string` | — | Text to hash into a magic circle (required) |
65
+ | `progress` | `number \| null` | `null` | Progress 0–1. Omit for indeterminate mode |
66
+ | `size` | `number` | `120` | Width/height in pixels |
67
+
68
+ - **`text`** — Different text produces a completely different magic circle. Use it to visually distinguish loading states (e.g. `"Uploading"` vs `"Processing"`).
69
+ - **`progress`** — Set `0` to `1` to animate layers sequentially. Omit entirely for a looping pulse animation.
70
+ - **`size`** — SVG scales cleanly to any size.
71
+
72
+ #### Methods
73
+
74
+ ```js
75
+ const el = document.querySelector('magic-loading');
76
+
77
+ // Trigger burst completion animation
78
+ await el.complete();
79
+ ```
80
+
81
+ #### Dynamic Updates
82
+
83
+ ```js
84
+ const el = document.querySelector('magic-loading');
85
+
86
+ // Update progress
87
+ el.setAttribute('progress', '0.8');
88
+
89
+ // Change text → regenerates the entire circle
90
+ el.setAttribute('text', 'Almost done...');
91
+
92
+ // Switch to indeterminate mode
93
+ el.removeAttribute('progress');
94
+ ```
95
+
96
+ ### Programmatic API
97
+
98
+ For more control, use `create()`:
99
+
100
+ ```js
101
+ import { create } from '@yeonseong/magic-loading';
102
+
103
+ // Mount into a container element
104
+ const loader = create(document.getElementById('my-container'), {
105
+ text: 'Loading...',
106
+ size: 160,
107
+ progress: 0, // optional: omit for indeterminate
108
+ });
109
+
110
+ // Update progress (e.g. from fetch/upload callback)
111
+ loader.setProgress(0.5);
112
+
113
+ // Change text (regenerates the circle)
114
+ loader.setText('Almost done...');
115
+
116
+ // Burst completion animation (returns a Promise)
117
+ await loader.complete();
118
+
119
+ // Remove from DOM
120
+ loader.destroy();
121
+ ```
122
+
123
+ ### CDN (no build step)
124
+
125
+ ```html
126
+ <script src="https://unpkg.com/@yeonseong/magic-loading/dist/index.global.js"></script>
127
+
128
+ <div id="loader"></div>
129
+
130
+ <script>
131
+ const loader = MagicLoading.create(
132
+ document.getElementById('loader'),
133
+ { text: 'Hello', size: 120 }
134
+ );
135
+ </script>
136
+ ```
137
+
138
+ ### Framework Examples
139
+
140
+ #### React
141
+
142
+ ```jsx
143
+ import '@yeonseong/magic-loading';
144
+
145
+ function Loader({ text, progress }) {
146
+ return <magic-loading text={text} progress={progress} size={120} />;
147
+ }
148
+ ```
149
+
150
+ #### Vue
151
+
152
+ ```vue
153
+ <script setup>
154
+ import '@yeonseong/magic-loading';
155
+ </script>
156
+
157
+ <template>
158
+ <magic-loading :text="text" :progress="progress" size="120" />
159
+ </template>
160
+ ```
161
+
162
+ #### Svelte
163
+
164
+ ```svelte
165
+ <script>
166
+ import '@yeonseong/magic-loading';
167
+ export let text;
168
+ export let progress;
169
+ </script>
170
+
171
+ <magic-loading {text} {progress} size="120" />
172
+ ```
173
+
174
+ ## Customization
175
+
176
+ Override colors with CSS custom properties:
177
+
178
+ ```css
179
+ magic-loading {
180
+ --ml-color-primary: #ff6b6b;
181
+ --ml-color-secondary: #ffd93d;
182
+ --ml-color-glow: #ff6b6b;
183
+ }
184
+ ```
185
+
186
+ | Property | Default | Description |
187
+ |----------|---------|-------------|
188
+ | `--ml-color-primary` | Auto (from text hash) | Ring strokes, glyphs, center symbol |
189
+ | `--ml-color-secondary` | Auto (from text hash) | Inner polygon strokes |
190
+ | `--ml-color-glow` | Auto (from text hash) | Glow filter color |
191
+
192
+ By default, colors are deterministically derived from the text hash — each text gets its own unique color palette. Use CSS custom properties to override when you need brand-consistent colors.
193
+
194
+ ### Scoped overrides
195
+
196
+ ```css
197
+ /* All loaders on the page */
198
+ magic-loading {
199
+ --ml-color-primary: #00ffcc;
200
+ }
201
+
202
+ /* Only loaders inside .dark-panel */
203
+ .dark-panel magic-loading {
204
+ --ml-color-primary: #ff00ff;
205
+ --ml-color-secondary: #8800ff;
206
+ }
207
+ ```
208
+
209
+ ## Animation Modes
210
+
211
+ ### Determinate (`progress` set)
212
+
213
+ Layers activate sequentially as progress increases from 0 to 1:
214
+
215
+ | Progress | Effect |
216
+ |----------|--------|
217
+ | 0% | All layers dim (0.15 opacity), slow rotation |
218
+ | ~25% | Outer ring fully visible |
219
+ | ~50% | Second ring activates, glow intensifies |
220
+ | ~75% | Inner polygon appears |
221
+ | 100% | Everything at full brightness, fast rotation |
222
+
223
+ ### Indeterminate (`progress` omitted)
224
+
225
+ All layers pulse with a sine-wave rhythm. Constant rotation, gentle glow oscillation.
226
+
227
+ ### Burst (`.complete()`)
228
+
229
+ A ~0.5s flash — all layers max brightness, rotation accelerates, glow flares to 3x, then fades out.
230
+
231
+ ## How It Works
232
+
233
+ 1. Input text is hashed with FNV-1a to produce deterministic parameters
234
+ 2. Parameters control: ring count, polygon sides, glyph set (runes / alchemy / zodiac / geometric), colors, rotation directions
235
+ 3. SVG is generated with concentric rings, glyphs, inner polygons, and a central symbol
236
+ 4. Animation adapts to progress — layers activate sequentially, rotation accelerates, glow intensifies
237
+
238
+ ## Glyph Sets
239
+
240
+ | Set | Symbols |
241
+ |-----|---------|
242
+ | Elder Futhark | ᚠ ᚢ ᚦ ᚨ ᚱ ᚲ ᚷ ᚹ ... |
243
+ | Alchemy | ☉ ☽ ☿ ♀ ♂ ♃ ♄ △ ... |
244
+ | Zodiac | ♈ ♉ ♊ ♋ ♌ ♍ ♎ ♏ ... |
245
+ | Geometric | ✡ ⬡ ◈ △ ☆ ✧ ◇ ◉ ... |
246
+
247
+ The glyph set is automatically selected based on text hash. Each text produces a unique combination.
248
+
249
+ ## License
250
+
251
+ MIT
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@yeonseong/magic-loading",
3
- "version": "0.1.0",
3
+ "version": "0.2.0",
4
4
  "description": "Transform boring loading spinners into unique fantasy magic circles generated from text",
5
5
  "type": "module",
6
6
  "main": "./dist/index.cjs",