@khesira/textflow 1.0.0 → 1.0.2
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 +115 -7
- package/package.json +11 -1
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 Mika Jünger
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
CHANGED
|
@@ -1,15 +1,123 @@
|
|
|
1
|
-
# textflow
|
|
1
|
+
# @khesira/textflow
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
A lightweight, high-performance, framework-agnostic canvas physics text slider written in TypeScript.
|
|
4
|
+
|
|
5
|
+
This library packages a 2D physics engine into a native **Web Component (Custom Element)**, allowing you to create beautiful, dynamic text streams that float and collide organically across the screen. It works seamlessly with **Astro, Svelte, Vue, React**, or pure HTML.
|
|
6
|
+
|
|
7
|
+
---
|
|
8
|
+
|
|
9
|
+
## Features
|
|
10
|
+
|
|
11
|
+
* 🚀 **Framework Agnostic:** Built on the native Web Components standard. Zero runtime dependencies.
|
|
12
|
+
* 🛡️ **Resource-Efficient & Leak-Proof:** Automatically pauses the physics loops when the browser tab is blurred (`visibilitychange`) or the element is removed from the DOM (`disconnectedCallback`).
|
|
13
|
+
* 🖥️ **High-DPI / Retina Ready:** Canvas automatically scales with `window.devicePixelRatio` for razor-sharp text rendering on 4K and OLED displays.
|
|
14
|
+
* 🧠 **Smart Physics-Engine:** Text speed and impulse-exchange upon collision are calculated based on the text's font size (mass-inertia principle).
|
|
15
|
+
* ⚙️ **Runtime Validated:** Built-in sanitization catches malformed JSON configuration gracefully without crashing the engine.
|
|
16
|
+
|
|
17
|
+
---
|
|
18
|
+
|
|
19
|
+
## Installation
|
|
20
|
+
|
|
21
|
+
Install the package via your favorite package manager:
|
|
4
22
|
|
|
5
23
|
```bash
|
|
6
|
-
bun
|
|
24
|
+
bun add @khesira/textflow
|
|
25
|
+
# or npm install @khesira/textflow
|
|
7
26
|
```
|
|
8
27
|
|
|
9
|
-
|
|
28
|
+
## Usage
|
|
10
29
|
|
|
11
|
-
|
|
12
|
-
|
|
30
|
+
1. In Astro (or similar Frontend Frameworks)
|
|
31
|
+
Register the custom element in your client-side script and pass your configuration via data-* attributes.
|
|
32
|
+
|
|
33
|
+
```html
|
|
34
|
+
---
|
|
35
|
+
import type { Settings } from '@khesira/textflow';
|
|
36
|
+
|
|
37
|
+
interface Props {
|
|
38
|
+
texts: string[];
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
const { texts } = Astro.props;
|
|
42
|
+
|
|
43
|
+
const settings: Settings = {
|
|
44
|
+
font: "Inter, sans-serif",
|
|
45
|
+
color: "#ffffff",
|
|
46
|
+
background: "transparent",
|
|
47
|
+
maxTexts: 12,
|
|
48
|
+
maxAcceleration: 4,
|
|
49
|
+
marginTop: 20,
|
|
50
|
+
marginBottom: 20,
|
|
51
|
+
debug: false
|
|
52
|
+
};
|
|
53
|
+
---
|
|
54
|
+
|
|
55
|
+
<textflow-container
|
|
56
|
+
data-texts={JSON.stringify(texts)}
|
|
57
|
+
data-settings={JSON.stringify(settings)}
|
|
58
|
+
></textflow-container>
|
|
59
|
+
|
|
60
|
+
<script>
|
|
61
|
+
import { registerTextFlowSlider } from '@khesira/textflow';
|
|
62
|
+
|
|
63
|
+
// Teaches the browser the new HTML tag <textflow-container>
|
|
64
|
+
registerTextFlowSlider();
|
|
65
|
+
</script>
|
|
66
|
+
```
|
|
67
|
+
|
|
68
|
+
## 2. Pure HTML / JavaScript
|
|
69
|
+
|
|
70
|
+
```html
|
|
71
|
+
<!DOCTYPE html>
|
|
72
|
+
<html lang="en">
|
|
73
|
+
<head>
|
|
74
|
+
<meta charset="UTF-8">
|
|
75
|
+
<title>TextFlow Demo</title>
|
|
76
|
+
<style>
|
|
77
|
+
body { background: #111; }
|
|
78
|
+
textflow-container { margin: 2rem auto; }
|
|
79
|
+
</style>
|
|
80
|
+
</head>
|
|
81
|
+
<body>
|
|
82
|
+
|
|
83
|
+
<textflow-container
|
|
84
|
+
data-texts='["TypeScript", "Bun", "Astro", "Canvas", "Physics"]'
|
|
85
|
+
data-settings='{"maxTexts": 8, "color": "#00ffcc"}'>
|
|
86
|
+
</textflow-container>
|
|
87
|
+
|
|
88
|
+
<script type="module">
|
|
89
|
+
import { registerTextFlowSlider } from './node_modules/@khesira/textflow/dist/textflow.js';
|
|
90
|
+
registerTextFlowSlider();
|
|
91
|
+
</script>
|
|
92
|
+
</body>
|
|
93
|
+
</html>
|
|
13
94
|
```
|
|
14
95
|
|
|
15
|
-
|
|
96
|
+
## Configuration (Settings)
|
|
97
|
+
|
|
98
|
+
| Property | Type | Default Value | Description |
|
|
99
|
+
| :--- | :--- | :--- | :--- |
|
|
100
|
+
| `width` | `string` | `"100%"` | CSS width of the slider component (e.g., `"100%"`, `"400px"`). |
|
|
101
|
+
| `height` | `string` | `"150px"` | CSS height of the slider component. |
|
|
102
|
+
| `font` | `string` | `"sans-serif"` | Font family used inside the Canvas rendering context. |
|
|
103
|
+
| `color` | `string` | `"#ffffff"` | Text color (accepts hex, rgb, rgba, or CSS color names). |
|
|
104
|
+
| `background` | `string` | `"transparent"` | Background color of the canvas container. |
|
|
105
|
+
| `maxTexts` | `number` | `10` | Maximum number of text elements allowed on screen simultaneously. |
|
|
106
|
+
| `maxAcceleration` | `number` | `3` | Maximum velocity cap for the text particles. |
|
|
107
|
+
| `marginTop` | `number` | `0` | Top boundary padding (in pixels) to restrict the spawn area. |
|
|
108
|
+
| `marginBottom` | `number` | `0` | Bottom boundary padding (in pixels) to restrict the spawn area. |
|
|
109
|
+
| `debug` | `boolean` | `false` | Enables red AABB bounding boxes and highlights the canvas clear zones. |
|
|
110
|
+
|
|
111
|
+
## Architecture
|
|
112
|
+
|
|
113
|
+
The library follows a strict Model-View-Controller (MVC) inspired architecture to decouple data, state machine, and side effects:
|
|
114
|
+
|
|
115
|
+
- TextElement: Represents the physical text particle, housing position, speed, and bounding box.
|
|
116
|
+
- World: The state machine driving the physics engine, handling backward-loop garbage collection and processing 2D broad-phase collisions.
|
|
117
|
+
- TextFlowView: Isolated rendering layer that handles drawing text onto the high-DPI scaled 2D context.
|
|
118
|
+
- TextWriter: Factory class that manages the pseudo-randomized generation of new TextElement batches based on viewport requirements.
|
|
119
|
+
- TextFlowElement: The HTML Custom Element orchestrating the components and bridging browser lifecycles.
|
|
120
|
+
|
|
121
|
+
## License
|
|
122
|
+
|
|
123
|
+
MIT License - feel free to use it in your personal portfolio or commercial projects!
|
package/package.json
CHANGED
|
@@ -1,8 +1,18 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@khesira/textflow",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.2",
|
|
4
|
+
"license": "MIT",
|
|
5
|
+
"author": "Mika Jünger",
|
|
4
6
|
"description": "A framework agnostic canvas physics text slider",
|
|
5
7
|
"type": "module",
|
|
8
|
+
"repository": {
|
|
9
|
+
"type": "git",
|
|
10
|
+
"url": "git+https://github.com/khesira/textflow.git"
|
|
11
|
+
},
|
|
12
|
+
"bugs": {
|
|
13
|
+
"url": "https://github.com/khesira/textflow/issues"
|
|
14
|
+
},
|
|
15
|
+
"homepage": "https://github.com/khesira/textflow#readme",
|
|
6
16
|
"main": "./dist/textflow.umd.cjs",
|
|
7
17
|
"module": "./dist/textflow.es.js",
|
|
8
18
|
"types": "./dist/index.d.ts",
|