textmode.overlay.js 1.0.0-beta.1
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 -0
- package/dist/textmode.overlay.esm.js +1 -0
- package/dist/textmode.overlay.umd.js +1 -0
- package/dist/types/OverlayPlugin.d.ts +15 -0
- package/dist/types/augmentations.d.ts +8 -0
- package/dist/types/index.d.ts +33 -0
- package/dist/types/runtime/OverlayGeometry.d.ts +36 -0
- package/dist/types/runtime/OverlaySynchronizer.d.ts +33 -0
- package/dist/types/runtime/TextmodeOverlayController.d.ts +31 -0
- package/dist/types/types.d.ts +130 -0
- package/package.json +97 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 humanbydefinition
|
|
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
ADDED
|
@@ -0,0 +1,115 @@
|
|
|
1
|
+
# textmode.overlay.js
|
|
2
|
+
|
|
3
|
+
<div align="center">
|
|
4
|
+
|
|
5
|
+
<img alt="textmode.overlay.js — overlay textmode above any target" src=".github/assets/readme-og.png" />
|
|
6
|
+
|
|
7
|
+
| [](https://www.typescriptlang.org/) [](https://vitejs.dev/) | [](https://code.textmode.art/api/textmode.overlay.js/) [](https://code.textmode.art/) [](https://discord.gg/sjrw8QXNks) | [](https://ko-fi.com/V7V8JG2FY) [](https://github.com/sponsors/humanbydefinition) |
|
|
8
|
+
|:---|:---|:---|
|
|
9
|
+
|
|
10
|
+
</div>
|
|
11
|
+
|
|
12
|
+
`textmode.overlay.js` is the official target-overlay add-on for [`textmode.js`](https://github.com/humanbydefinition/textmode.js), giving a live canvas or video element a textmode twin. The output canvas renders directly on top of the target and stays pinned there through resizes, scrolling, and window changes — so the textmode view tracks the element as the page moves.
|
|
13
|
+
|
|
14
|
+
Bind a target once with `t.overlay.setTarget()`, then sample it with the same character, color, conversion, and transform settings as any other source. Show, hide, or toggle the overlay independently while drawing continues, retarget freely between elements, or leave a target detached until it mounts - the add-on owns the geometry and DOM lifecycle so you can focus on the composition.
|
|
15
|
+
|
|
16
|
+
## Features
|
|
17
|
+
|
|
18
|
+
- **Synchronous target binding** - `setTarget()` runs immediately after `textmode.create()` and returns a fully configurable `TextmodeTexture`
|
|
19
|
+
- **Live canvas and video sampling** - Sample HTMLCanvasElement or HTMLVideoElement targets through the standard character, color, conversion, and transform settings
|
|
20
|
+
- **Frame-coalesced geometry sync** - Target resize, captured scroll, window resize, video metadata, and post-draw notifications settle into one animation frame
|
|
21
|
+
- **DOM lifecycle ownership** - Clearing or uninstalling the plugin restores the output canvas to its original DOM location and modified inline styles
|
|
22
|
+
- **Disconnected-target watching** - Targets are watched until they are mounted into the document
|
|
23
|
+
- **Output visibility controls** - Show, hide, and toggle only the output canvas while sampling and sketch execution continue
|
|
24
|
+
- **Axis-aligned positioning** - Rotated or skewed CSS targets are rejected rather than approximated
|
|
25
|
+
|
|
26
|
+
## Installation
|
|
27
|
+
|
|
28
|
+
Follow the [official installation guide](https://code.textmode.art/docs/installation) to install
|
|
29
|
+
`textmode.overlay.js` alongside `textmode.js` with npm or browser-ready UMD bundles.
|
|
30
|
+
|
|
31
|
+
```bash
|
|
32
|
+
npm install textmode.js textmode.overlay.js
|
|
33
|
+
```
|
|
34
|
+
|
|
35
|
+
## Usage
|
|
36
|
+
|
|
37
|
+
```ts
|
|
38
|
+
import { textmode } from 'textmode.js';
|
|
39
|
+
import { OverlayPlugin } from 'textmode.overlay.js';
|
|
40
|
+
|
|
41
|
+
const t = textmode.create({
|
|
42
|
+
plugins: [OverlayPlugin],
|
|
43
|
+
});
|
|
44
|
+
|
|
45
|
+
const source = t.overlay.setTarget(sourceCanvas);
|
|
46
|
+
source.characters(' .:-=+*#%@').charColorMode('sampled');
|
|
47
|
+
|
|
48
|
+
t.draw(() => {
|
|
49
|
+
t.image(t.overlay.source!, t.grid.cols, t.grid.rows);
|
|
50
|
+
});
|
|
51
|
+
```
|
|
52
|
+
|
|
53
|
+
`setTarget()` is synchronous and can run immediately after `textmode.create()`. The returned `TextmodeTexture` supports the normal character, color, conversion, and transform settings.
|
|
54
|
+
|
|
55
|
+
## Migration from core overlay mode
|
|
56
|
+
|
|
57
|
+
In `textmode.js` 0.18, the built-in `{ overlay: true }` target-overlay mode was extracted into this add-on. Use the table below to update an existing sketch.
|
|
58
|
+
|
|
59
|
+
| Before | After |
|
|
60
|
+
| --- | --- |
|
|
61
|
+
| `textmode.create({ canvas: target, overlay: true })` | `textmode.create({ plugins: [OverlayPlugin] })` |
|
|
62
|
+
| `t.overlay` as the sampled image | `t.overlay.setTarget(target)`; read the sampled `TextmodeTexture` from `t.overlay.source` |
|
|
63
|
+
| Target following owned by core | Controller lifecycle owned by the add-on |
|
|
64
|
+
| Available without installing anything | Install and import `textmode.overlay.js` |
|
|
65
|
+
|
|
66
|
+
## Next steps
|
|
67
|
+
|
|
68
|
+
- **[Read the documentation](https://code.textmode.art/)** for core concepts and plugin workflows.
|
|
69
|
+
- **[Browse the API reference](https://code.textmode.art/api/textmode.overlay.js/)** for the complete controller and plugin API.
|
|
70
|
+
- **[Explore the examples](./examples/)** to see canvas, video, retargeting, and visibility patterns in action.
|
|
71
|
+
|
|
72
|
+
## Contributing
|
|
73
|
+
|
|
74
|
+
Thank you for considering contributing to this project! (✿◠‿◠)
|
|
75
|
+
|
|
76
|
+
Please read the [Contributing Guide](./CONTRIBUTING.md) to get started.
|
|
77
|
+
|
|
78
|
+
<!-- TEXTMODE-CONTRIBUTORS:START -->
|
|
79
|
+
<!-- prettier-ignore-start -->
|
|
80
|
+
<!-- Generated from https://github.com/humanbydefinition/code.textmode.art/blob/main/.vitepress/data/contributors.json and https://github.com/humanbydefinition/code.textmode.art/blob/main/.vitepress/data/contribution-types.json. Do not edit this section directly. -->
|
|
81
|
+
## Contributors
|
|
82
|
+
|
|
83
|
+
Thanks to the people who contribute code, documentation, design, examples, ideas, infrastructure, and care
|
|
84
|
+
across the textmode.js ecosystem.
|
|
85
|
+
|
|
86
|
+
<!-- markdownlint-disable MD033 -->
|
|
87
|
+
<table>
|
|
88
|
+
<tbody>
|
|
89
|
+
<tr>
|
|
90
|
+
<td align="center" valign="top" width="14.28%">
|
|
91
|
+
<a href="https://github.com/humanbydefinition">
|
|
92
|
+
<img src="https://github.com/humanbydefinition.png?s=100" width="100px" alt="humanbydefinition avatar" />
|
|
93
|
+
<br /><sub><b>humanbydefinition</b></sub>
|
|
94
|
+
</a>
|
|
95
|
+
<br /><span title="Code: Commits and pull requests" aria-label="Code: Commits and pull requests">💻</span> <span title="Documentation: README, guides, and API documentation" aria-label="Documentation: README, guides, and API documentation">📖</span> <span title="Design: User experience, branding, and visual design" aria-label="Design: User experience, branding, and visual design">🎨</span> <span title="Examples: Usage examples and creative sketches" aria-label="Examples: Usage examples and creative sketches">💡</span> <span title="Ideas and planning: Feature proposals, planning, and feedback" aria-label="Ideas and planning: Feature proposals, planning, and feedback">🤔</span> <span title="Maintenance: Refactoring and project upkeep" aria-label="Maintenance: Refactoring and project upkeep">🚧</span> <span title="Infrastructure: Continuous integration, hosting, and build systems" aria-label="Infrastructure: Continuous integration, hosting, and build systems">🚇</span> <span title="Tools: Developer and community tooling" aria-label="Tools: Developer and community tooling">🔧</span> <span title="Plugins and libraries: Plugin and utility library development" aria-label="Plugins and libraries: Plugin and utility library development">🔌</span> <span title="Code review: Reviewing pull requests" aria-label="Code review: Reviewing pull requests">👀</span>
|
|
96
|
+
</td>
|
|
97
|
+
<td align="center" valign="top" width="14.28%">
|
|
98
|
+
<a href="https://github.com/trintlermint">
|
|
99
|
+
<img src="https://github.com/trintlermint.png?s=100" width="100px" alt="trintlermint avatar" />
|
|
100
|
+
<br /><sub><b>trintlermint</b></sub>
|
|
101
|
+
</a>
|
|
102
|
+
<br /><span title="Design: User experience, branding, and visual design" aria-label="Design: User experience, branding, and visual design">🎨</span> <span title="Examples: Usage examples and creative sketches" aria-label="Examples: Usage examples and creative sketches">💡</span>
|
|
103
|
+
</td>
|
|
104
|
+
</tr>
|
|
105
|
+
</tbody>
|
|
106
|
+
</table>
|
|
107
|
+
<!-- markdownlint-enable MD033 -->
|
|
108
|
+
|
|
109
|
+
Contribution details and profile links are maintained on the [textmode.js contributors page](https://code.textmode.art/docs/contributors).
|
|
110
|
+
<!-- prettier-ignore-end -->
|
|
111
|
+
<!-- TEXTMODE-CONTRIBUTORS:END -->
|
|
112
|
+
|
|
113
|
+
## License
|
|
114
|
+
|
|
115
|
+
`textmode.overlay.js` is licensed under the [MIT License](./LICENSE).
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
var t="[textmode.overlay.js]",i=1e-8;function s(s){if(!s||"none"===s)return;const e=/^matrix\(([^)]+)\)$/.exec(s);if(e){const t=e[1].split(",").map(Number);if(6===t.length&&Math.abs(t[1])<=i&&Math.abs(t[2])<=i)return}const n=/^matrix3d\(([^)]+)\)$/.exec(s);if(n){const t=n[1].split(",").map(Number);if(16===t.length&&[1,2,3,4,6,7,8,9,11].every(s=>Math.abs(t[s])<=i))return}throw new Error(`${t} Rotated and skewed overlay targets are not supported.`)}function e(t){return Math.round(100*t)/100}var n=class{t;i;h;o;l;u;v=!0;m;p;_=!1;T;M;L=()=>this.request();constructor(t,i){var s;this.t=t,this.i=i,this.h=t.parentNode,this.o=t.nextSibling,this.l={position:(s=t).style.position,left:s.style.left,top:s.style.top,width:s.style.width,height:s.style.height,zIndex:s.style.zIndex,display:s.style.display,pointerEvents:s.style.pointerEvents}}bind(t,i){this.u=t,this.v=i,this.C()&&this.H(),this.request()}request(){this.u&&void 0===this.T&&(this.u.isConnected?this.T=window.requestAnimationFrame(()=>{this.T=void 0,this.O()}):this.S())}setVisible(t){this.v=t,t?(this.V("display",this.l.display),this.C(),this.request()):this.V("display","none")}clear(t){this.$(),this.N(),this.u=void 0,this.M=void 0,t.restoreCanvas&&this.j()}dispose(){this.clear({restoreCanvas:!0})}O(){const t=this.u;if(!t||!this.C())return;const i=function(t,i){s(getComputedStyle(t).transform);const n=t.getBoundingClientRect(),h=t instanceof HTMLCanvasElement?t.width:t.videoWidth,o=t instanceof HTMLCanvasElement?t.height:t.videoHeight,r=e(n.width>0?n.width:h),a=e(n.height>0?n.height:o);if(r<=0||a<=0)return;const d=function(t,i){const s=i.offsetParent;if(s instanceof HTMLElement&&s!==document.body&&s!==document.documentElement){const i=s.getBoundingClientRect();return{left:t.left-i.left+s.scrollLeft-s.clientLeft,top:t.top-i.top+s.scrollTop-s.clientTop}}return{left:t.left+window.scrollX,top:t.top+window.scrollY}}(n,i);return{left:e(d.left),top:e(d.top),width:r,height:a}}(t,this.t);if(!i||(h=i,(n=this.M)&&n.left===h.left&&n.top===h.top&&n.width===h.width&&n.height===h.height))return;var n,h;const o=this.M,r=!o||o.width!==i.width||o.height!==i.height;this.M=i,this.V("left",`${i.left}px`),this.V("top",`${i.top}px`),r&&this.i(i.width,i.height)}H(){const t=this.u;t&&!this._&&(this._=!0,"undefined"!=typeof ResizeObserver&&(this.m=new ResizeObserver(this.L),this.m.observe(t,{box:"border-box"})),window.addEventListener("resize",this.L),window.addEventListener("scroll",this.L,!0),t instanceof HTMLVideoElement&&(t.addEventListener("loadedmetadata",this.L),t.addEventListener("resize",this.L)))}C(){const t=this.u;if(!t)return!1;if(!t.isConnected||!t.parentNode)return this.S(),!1;this.p?.disconnect(),this.p=void 0,this.t.previousSibling===t&&this.t.parentNode===t.parentNode||t.parentNode.insertBefore(this.t,t.nextSibling);const i=Number.parseFloat(getComputedStyle(t).zIndex);return this.V("position","absolute"),this.V("zIndex",String((Number.isFinite(i)?i:0)+1)),this.V("pointerEvents","auto"),this.V("display",this.v?this.l.display:"none"),!0}S(){if(this.p||"undefined"==typeof MutationObserver)return;const t=document.documentElement;t&&(this.p=new MutationObserver(()=>{this.u?.isConnected&&(this.C()&&this.H(),this.request())}),this.p.observe(t,{childList:!0,subtree:!0}))}N(){this.m?.disconnect(),this.m=void 0,this.p?.disconnect(),this.p=void 0;const t=this.u;this._=!1,window.removeEventListener("resize",this.L),window.removeEventListener("scroll",this.L,!0),t instanceof HTMLVideoElement&&(t.removeEventListener("loadedmetadata",this.L),t.removeEventListener("resize",this.L))}$(){void 0!==this.T&&(window.cancelAnimationFrame(this.T),this.T=void 0)}j(){if(this.t.isConnected&&this.h){const t=this.o;this.h.insertBefore(this.t,t?.parentNode===this.h?t:null)}Object.assign(this.t.style,this.l)}V(t,i){this.t.style[t]!==i&&(this.t.style[t]=i)}},h=class{F;t;q;u;A;v=!0;R=!1;constructor(t){this.F=t,this.t=t.canvas,this.q=new n(this.t,(t,i)=>this.F.resizeCanvas(t,i))}get target(){return this.I(),this.u}get source(){return this.I(),this.A}setTarget(i){return this.I(),function(i,e){const n="undefined"!=typeof HTMLCanvasElement&&i instanceof HTMLCanvasElement,h="undefined"!=typeof HTMLVideoElement&&i instanceof HTMLVideoElement;if(!n&&!h)throw new TypeError(`${t} setTarget() requires an HTMLCanvasElement or HTMLVideoElement.`);if(i===e)throw new TypeError(`${t} The textmode output canvas cannot be used as its own overlay target.`);s(getComputedStyle(i).transform)}(i,this.t),i===this.u&&this.A?(this.requestSynchronization(),this.A):(this.P(!1),this.u=i,this.A=this.F.createTexture(i),this.q.bind(i,this.v),this.A)}clearTarget(){this.I(),this.P(!0)}show(){this.I(),this.v=!0,this.q.setVisible(!0)}hide(){this.I(),this.v&&(this.v=!1,this.q.setVisible(!1))}toggle(){this.I(),this.v?this.hide():this.show()}isVisible(){return this.I(),this.v}requestSynchronization(){this.I(),this.q.request()}dispose(){this.R||(this.P(!0),this.q.dispose(),this.R=!0)}I(){if(this.R)throw new Error("[textmode.overlay.js] This overlay controller has been disposed.")}P(t){this.q.clear({restoreCanvas:t}),this.A?.dispose(),this.A=void 0,this.u=void 0}},o={name:"textmode.overlay.js",install(t,i){const s=new h(t),e=i.on("postDraw",()=>s.requestSynchronization());try{i.defineExtension("textmodifier","overlay",{get:()=>s})}catch(n){throw s.dispose(),e(),n}return()=>{s.dispose(),e()}}};"undefined"!=typeof window&&(window.OverlayPlugin=o);export{o as OverlayPlugin};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
!function(t,i){"object"==typeof exports&&"undefined"!=typeof module?i(exports):"function"==typeof define&&define.amd?define(["exports"],i):i((t="undefined"!=typeof globalThis?globalThis:t||self).textmodeOverlay={})}(this,function(t){Object.defineProperty(t,Symbol.toStringTag,{value:"Module"});var i="[textmode.overlay.js]",e=1e-8;function s(t){if(!t||"none"===t)return;const s=/^matrix\(([^)]+)\)$/.exec(t);if(s){const t=s[1].split(",").map(Number);if(6===t.length&&Math.abs(t[1])<=e&&Math.abs(t[2])<=e)return}const n=/^matrix3d\(([^)]+)\)$/.exec(t);if(n){const t=n[1].split(",").map(Number);if(16===t.length&&[1,2,3,4,6,7,8,9,11].every(i=>Math.abs(t[i])<=e))return}throw new Error(`${i} Rotated and skewed overlay targets are not supported.`)}function n(t){return Math.round(100*t)/100}var o=class{t;i;o;h;l;u;v=!0;p;m;_=!1;T;M;L=()=>this.request();constructor(t,i){var e;this.t=t,this.i=i,this.o=t.parentNode,this.h=t.nextSibling,this.l={position:(e=t).style.position,left:e.style.left,top:e.style.top,width:e.style.width,height:e.style.height,zIndex:e.style.zIndex,display:e.style.display,pointerEvents:e.style.pointerEvents}}bind(t,i){this.u=t,this.v=i,this.C()&&this.H(),this.request()}request(){this.u&&void 0===this.T&&(this.u.isConnected?this.T=window.requestAnimationFrame(()=>{this.T=void 0,this.O()}):this.S())}setVisible(t){this.v=t,t?(this.V("display",this.l.display),this.C(),this.request()):this.V("display","none")}clear(t){this.$(),this.j(),this.u=void 0,this.M=void 0,t.restoreCanvas&&this.N()}dispose(){this.clear({restoreCanvas:!0})}O(){const t=this.u;if(!t||!this.C())return;const i=function(t,i){s(getComputedStyle(t).transform);const e=t.getBoundingClientRect(),o=t instanceof HTMLCanvasElement?t.width:t.videoWidth,h=t instanceof HTMLCanvasElement?t.height:t.videoHeight,r=n(e.width>0?e.width:o),a=n(e.height>0?e.height:h);if(r<=0||a<=0)return;const d=function(t,i){const e=i.offsetParent;if(e instanceof HTMLElement&&e!==document.body&&e!==document.documentElement){const i=e.getBoundingClientRect();return{left:t.left-i.left+e.scrollLeft-e.clientLeft,top:t.top-i.top+e.scrollTop-e.clientTop}}return{left:t.left+window.scrollX,top:t.top+window.scrollY}}(e,i);return{left:n(d.left),top:n(d.top),width:r,height:a}}(t,this.t);if(!i||(o=i,(e=this.M)&&e.left===o.left&&e.top===o.top&&e.width===o.width&&e.height===o.height))return;var e,o;const h=this.M,r=!h||h.width!==i.width||h.height!==i.height;this.M=i,this.V("left",`${i.left}px`),this.V("top",`${i.top}px`),r&&this.i(i.width,i.height)}H(){const t=this.u;t&&!this._&&(this._=!0,"undefined"!=typeof ResizeObserver&&(this.p=new ResizeObserver(this.L),this.p.observe(t,{box:"border-box"})),window.addEventListener("resize",this.L),window.addEventListener("scroll",this.L,!0),t instanceof HTMLVideoElement&&(t.addEventListener("loadedmetadata",this.L),t.addEventListener("resize",this.L)))}C(){const t=this.u;if(!t)return!1;if(!t.isConnected||!t.parentNode)return this.S(),!1;this.m?.disconnect(),this.m=void 0,this.t.previousSibling===t&&this.t.parentNode===t.parentNode||t.parentNode.insertBefore(this.t,t.nextSibling);const i=Number.parseFloat(getComputedStyle(t).zIndex);return this.V("position","absolute"),this.V("zIndex",String((Number.isFinite(i)?i:0)+1)),this.V("pointerEvents","auto"),this.V("display",this.v?this.l.display:"none"),!0}S(){if(this.m||"undefined"==typeof MutationObserver)return;const t=document.documentElement;t&&(this.m=new MutationObserver(()=>{this.u?.isConnected&&(this.C()&&this.H(),this.request())}),this.m.observe(t,{childList:!0,subtree:!0}))}j(){this.p?.disconnect(),this.p=void 0,this.m?.disconnect(),this.m=void 0;const t=this.u;this._=!1,window.removeEventListener("resize",this.L),window.removeEventListener("scroll",this.L,!0),t instanceof HTMLVideoElement&&(t.removeEventListener("loadedmetadata",this.L),t.removeEventListener("resize",this.L))}$(){void 0!==this.T&&(window.cancelAnimationFrame(this.T),this.T=void 0)}N(){if(this.t.isConnected&&this.o){const t=this.h;this.o.insertBefore(this.t,t?.parentNode===this.o?t:null)}Object.assign(this.t.style,this.l)}V(t,i){this.t.style[t]!==i&&(this.t.style[t]=i)}},h=class{F;t;q;u;A;v=!0;R=!1;constructor(t){this.F=t,this.t=t.canvas,this.q=new o(this.t,(t,i)=>this.F.resizeCanvas(t,i))}get target(){return this.I(),this.u}get source(){return this.I(),this.A}setTarget(t){return this.I(),function(t,e){const n="undefined"!=typeof HTMLCanvasElement&&t instanceof HTMLCanvasElement,o="undefined"!=typeof HTMLVideoElement&&t instanceof HTMLVideoElement;if(!n&&!o)throw new TypeError(`${i} setTarget() requires an HTMLCanvasElement or HTMLVideoElement.`);if(t===e)throw new TypeError(`${i} The textmode output canvas cannot be used as its own overlay target.`);s(getComputedStyle(t).transform)}(t,this.t),t===this.u&&this.A?(this.requestSynchronization(),this.A):(this.P(!1),this.u=t,this.A=this.F.createTexture(t),this.q.bind(t,this.v),this.A)}clearTarget(){this.I(),this.P(!0)}show(){this.I(),this.v=!0,this.q.setVisible(!0)}hide(){this.I(),this.v&&(this.v=!1,this.q.setVisible(!1))}toggle(){this.I(),this.v?this.hide():this.show()}isVisible(){return this.I(),this.v}requestSynchronization(){this.I(),this.q.request()}dispose(){this.R||(this.P(!0),this.q.dispose(),this.R=!0)}I(){if(this.R)throw new Error("[textmode.overlay.js] This overlay controller has been disposed.")}P(t){this.q.clear({restoreCanvas:t}),this.A?.dispose(),this.A=void 0,this.u=void 0}},r={name:"textmode.overlay.js",install(t,i){const e=new h(t),s=i.on("postDraw",()=>e.requestSynchronization());try{i.defineExtension("textmodifier","overlay",{get:()=>e})}catch(n){throw e.dispose(),s(),n}return()=>{e.dispose(),s()}}};"undefined"!=typeof window&&(window.OverlayPlugin=r),t.OverlayPlugin=r});
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import type { TextmodePlugin } from 'textmode.js';
|
|
2
|
+
/**
|
|
3
|
+
* Installs an isolated overlay controller on each textmode.js instance.
|
|
4
|
+
*
|
|
5
|
+
* @category Workflow
|
|
6
|
+
*
|
|
7
|
+
* @example
|
|
8
|
+
* ```ts
|
|
9
|
+
* const t = textmode.create({ plugins: [OverlayPlugin] });
|
|
10
|
+
* t.overlay.setTarget(document.querySelector('canvas'));
|
|
11
|
+
* ```
|
|
12
|
+
*
|
|
13
|
+
* @see {@link https://code.textmode.art/api/textmode.overlay.js/variables/OverlayPlugin | OverlayPlugin API reference}
|
|
14
|
+
*/
|
|
15
|
+
export declare const OverlayPlugin: TextmodePlugin;
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @packageDocumentation
|
|
3
|
+
*
|
|
4
|
+
* DOM overlay target capture and geometry synchronization for textmode.js.
|
|
5
|
+
*
|
|
6
|
+
* ## Sketch workflow
|
|
7
|
+
*
|
|
8
|
+
* 1. Add {@link OverlayPlugin} to the sketch's plugins.
|
|
9
|
+
* 2. Bind a live canvas or video with `t.overlay.setTarget()`.
|
|
10
|
+
* 3. Shape the returned texture with the standard character, color, conversion,
|
|
11
|
+
* and transform settings.
|
|
12
|
+
* 4. Show, hide, or toggle the output canvas while drawing continues.
|
|
13
|
+
*
|
|
14
|
+
* @categoryDescription Workflow
|
|
15
|
+
* The plugin that installs the overlay controller on textmode.js layers.
|
|
16
|
+
*
|
|
17
|
+
* @categoryDescription Overlay controller
|
|
18
|
+
* The per-instance controller that samples a target and keeps the output aligned.
|
|
19
|
+
*
|
|
20
|
+
* @categoryDescription Target types
|
|
21
|
+
* The live browser media elements the overlay can sample.
|
|
22
|
+
*
|
|
23
|
+
* @showCategories
|
|
24
|
+
*/
|
|
25
|
+
import './augmentations';
|
|
26
|
+
export { OverlayPlugin } from './OverlayPlugin';
|
|
27
|
+
export type { TextmodeOverlayController, TextmodeOverlayTarget } from './types';
|
|
28
|
+
import type { TextmodePlugin } from 'textmode.js';
|
|
29
|
+
declare global {
|
|
30
|
+
interface Window {
|
|
31
|
+
OverlayPlugin?: TextmodePlugin;
|
|
32
|
+
}
|
|
33
|
+
}
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
import type { TextmodeOverlayTarget } from '../types';
|
|
2
|
+
/**
|
|
3
|
+
* Internal immutable geometry value used by the synchronizer.
|
|
4
|
+
*
|
|
5
|
+
* @internal
|
|
6
|
+
*/
|
|
7
|
+
export type OverlayGeometry = Readonly<{
|
|
8
|
+
left: number;
|
|
9
|
+
top: number;
|
|
10
|
+
width: number;
|
|
11
|
+
height: number;
|
|
12
|
+
}>;
|
|
13
|
+
/**
|
|
14
|
+
* Validate a target and preserve the package's public error contract.
|
|
15
|
+
*
|
|
16
|
+
* @internal
|
|
17
|
+
*/
|
|
18
|
+
export declare function assertValidTarget(target: unknown, output: HTMLCanvasElement): asserts target is TextmodeOverlayTarget;
|
|
19
|
+
/**
|
|
20
|
+
* Reject transforms that cannot be represented by axis-aligned overlay geometry.
|
|
21
|
+
*
|
|
22
|
+
* @internal
|
|
23
|
+
*/
|
|
24
|
+
export declare function assertAxisAlignedTransform(transform: string): void;
|
|
25
|
+
/**
|
|
26
|
+
* Measure and round a target in the output canvas's coordinate space.
|
|
27
|
+
*
|
|
28
|
+
* @internal
|
|
29
|
+
*/
|
|
30
|
+
export declare function measureOverlayGeometry(target: TextmodeOverlayTarget, output: HTMLCanvasElement): OverlayGeometry | undefined;
|
|
31
|
+
/**
|
|
32
|
+
* Compare complete geometry values.
|
|
33
|
+
*
|
|
34
|
+
* @internal
|
|
35
|
+
*/
|
|
36
|
+
export declare function sameGeometry(a: OverlayGeometry | undefined, b: OverlayGeometry): boolean;
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
import type { TextmodeOverlayTarget } from '../types';
|
|
2
|
+
/** @internal */
|
|
3
|
+
export declare class OverlaySynchronizer {
|
|
4
|
+
private readonly _output;
|
|
5
|
+
private readonly _resizeCanvas;
|
|
6
|
+
private readonly _originalParent;
|
|
7
|
+
private readonly _originalNextSibling;
|
|
8
|
+
private readonly _originalStyle;
|
|
9
|
+
private _target;
|
|
10
|
+
private _visible;
|
|
11
|
+
private _resizeObserver;
|
|
12
|
+
private _mountObserver;
|
|
13
|
+
private _isObserving;
|
|
14
|
+
private _animationFrame;
|
|
15
|
+
private _lastGeometry;
|
|
16
|
+
private readonly _scheduleFromEvent;
|
|
17
|
+
constructor(output: HTMLCanvasElement, resizeCanvas: (width: number, height: number) => void);
|
|
18
|
+
bind(target: TextmodeOverlayTarget, visible: boolean): void;
|
|
19
|
+
request(): void;
|
|
20
|
+
setVisible(visible: boolean): void;
|
|
21
|
+
clear(options: {
|
|
22
|
+
restoreCanvas: boolean;
|
|
23
|
+
}): void;
|
|
24
|
+
dispose(): void;
|
|
25
|
+
private _synchronize;
|
|
26
|
+
private _observeTarget;
|
|
27
|
+
private _insertWhenPossible;
|
|
28
|
+
private _watchForMount;
|
|
29
|
+
private _disconnectObserversAndListeners;
|
|
30
|
+
private _cancelAnimationFrame;
|
|
31
|
+
private _restoreCanvas;
|
|
32
|
+
private _setStyle;
|
|
33
|
+
}
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
import type { TextmodeTexture, Textmodifier } from 'textmode.js';
|
|
2
|
+
import type { TextmodeOverlayController, TextmodeOverlayTarget } from '../types';
|
|
3
|
+
/** @internal */
|
|
4
|
+
export declare class TextmodeOverlayControllerImpl implements TextmodeOverlayController {
|
|
5
|
+
private readonly _textmodifier;
|
|
6
|
+
private readonly _output;
|
|
7
|
+
private readonly _synchronizer;
|
|
8
|
+
private _target;
|
|
9
|
+
private _source;
|
|
10
|
+
private _visible;
|
|
11
|
+
private _disposed;
|
|
12
|
+
constructor(textmodifier: Textmodifier);
|
|
13
|
+
get target(): TextmodeOverlayTarget | undefined;
|
|
14
|
+
get source(): TextmodeTexture | undefined;
|
|
15
|
+
setTarget(target: TextmodeOverlayTarget): TextmodeTexture;
|
|
16
|
+
clearTarget(): void;
|
|
17
|
+
show(): void;
|
|
18
|
+
hide(): void;
|
|
19
|
+
toggle(): void;
|
|
20
|
+
isVisible(): boolean;
|
|
21
|
+
/**
|
|
22
|
+
* Request synchronization from the host plugin adapter.
|
|
23
|
+
*
|
|
24
|
+
* @internal
|
|
25
|
+
*/
|
|
26
|
+
requestSynchronization(): void;
|
|
27
|
+
/** Release all plugin-owned resources. */
|
|
28
|
+
dispose(): void;
|
|
29
|
+
private _assertActive;
|
|
30
|
+
private _releaseBinding;
|
|
31
|
+
}
|
|
@@ -0,0 +1,130 @@
|
|
|
1
|
+
import type { TextmodeTexture } from 'textmode.js';
|
|
2
|
+
/**
|
|
3
|
+
* A live browser media element that can be sampled by the overlay controller.
|
|
4
|
+
*
|
|
5
|
+
* @category Target types
|
|
6
|
+
*
|
|
7
|
+
* @see {@link https://code.textmode.art/api/textmode.overlay.js/type-aliases/TextmodeOverlayTarget | TextmodeOverlayTarget API reference}
|
|
8
|
+
*/
|
|
9
|
+
export type TextmodeOverlayTarget = HTMLCanvasElement | HTMLVideoElement;
|
|
10
|
+
/**
|
|
11
|
+
* Controls the sampled target and DOM alignment for one textmode.js instance.
|
|
12
|
+
*
|
|
13
|
+
* The controller never owns the output canvas. Clearing or uninstalling the plugin
|
|
14
|
+
* restores the canvas to its original DOM location and inline styles.
|
|
15
|
+
*
|
|
16
|
+
* @category Overlay controller
|
|
17
|
+
*
|
|
18
|
+
* @categoryDescription Controller state
|
|
19
|
+
* The current sampled target, its configurable texture source, and output visibility state.
|
|
20
|
+
*
|
|
21
|
+
* @categoryDescription Target binding
|
|
22
|
+
* Attach a target to sample and release it to restore the output canvas.
|
|
23
|
+
*
|
|
24
|
+
* @categoryDescription Visibility
|
|
25
|
+
* Show, hide, and toggle only the output canvas while sampling continues.
|
|
26
|
+
*
|
|
27
|
+
* @see {@link https://code.textmode.art/api/textmode.overlay.js/interfaces/TextmodeOverlayController | TextmodeOverlayController API reference}
|
|
28
|
+
*/
|
|
29
|
+
export interface TextmodeOverlayController {
|
|
30
|
+
/**
|
|
31
|
+
* The currently sampled canvas or video.
|
|
32
|
+
*
|
|
33
|
+
* @category Controller state
|
|
34
|
+
*
|
|
35
|
+
* @see {@link https://code.textmode.art/api/textmode.overlay.js/interfaces/TextmodeOverlayController#target | TextmodeOverlayController.target API reference}
|
|
36
|
+
*/
|
|
37
|
+
readonly target: TextmodeOverlayTarget | undefined;
|
|
38
|
+
/**
|
|
39
|
+
* The configurable texture created from {@link target}.
|
|
40
|
+
*
|
|
41
|
+
* @category Controller state
|
|
42
|
+
*
|
|
43
|
+
* @see {@link https://code.textmode.art/api/textmode.overlay.js/interfaces/TextmodeOverlayController#source | TextmodeOverlayController.source API reference}
|
|
44
|
+
*/
|
|
45
|
+
readonly source: TextmodeTexture | undefined;
|
|
46
|
+
/**
|
|
47
|
+
* Sample a target and align the textmode output canvas above it.
|
|
48
|
+
*
|
|
49
|
+
* @category Target binding
|
|
50
|
+
*
|
|
51
|
+
* @param target Canvas or video to sample.
|
|
52
|
+
* @returns The configurable texture source.
|
|
53
|
+
*
|
|
54
|
+
* @example
|
|
55
|
+
* ```ts
|
|
56
|
+
* const source = t.overlay.setTarget(canvas);
|
|
57
|
+
* source.characters(' .:-=+*#%@');
|
|
58
|
+
* ```
|
|
59
|
+
*
|
|
60
|
+
* @see {@link https://code.textmode.art/api/textmode.overlay.js/interfaces/TextmodeOverlayController#settarget | TextmodeOverlayController.setTarget API reference}
|
|
61
|
+
*/
|
|
62
|
+
setTarget(target: TextmodeOverlayTarget): TextmodeTexture;
|
|
63
|
+
/**
|
|
64
|
+
* Stop sampling and restore the output canvas.
|
|
65
|
+
*
|
|
66
|
+
* @category Target binding
|
|
67
|
+
*
|
|
68
|
+
* @example
|
|
69
|
+
* ```ts
|
|
70
|
+
* t.overlay.clearTarget();
|
|
71
|
+
* ```
|
|
72
|
+
*
|
|
73
|
+
* @see {@link https://code.textmode.art/api/textmode.overlay.js/interfaces/TextmodeOverlayController#cleartarget | TextmodeOverlayController.clearTarget API reference}
|
|
74
|
+
*/
|
|
75
|
+
clearTarget(): void;
|
|
76
|
+
/**
|
|
77
|
+
* Show the output canvas and request a fresh geometry synchronization.
|
|
78
|
+
*
|
|
79
|
+
* @category Visibility
|
|
80
|
+
*
|
|
81
|
+
* @example
|
|
82
|
+
* ```ts
|
|
83
|
+
* t.overlay.show();
|
|
84
|
+
* ```
|
|
85
|
+
*
|
|
86
|
+
* @see {@link https://code.textmode.art/api/textmode.overlay.js/interfaces/TextmodeOverlayController#show | TextmodeOverlayController.show API reference}
|
|
87
|
+
*/
|
|
88
|
+
show(): void;
|
|
89
|
+
/**
|
|
90
|
+
* Hide only the output canvas. Sampling and sketch execution continue.
|
|
91
|
+
*
|
|
92
|
+
* @category Visibility
|
|
93
|
+
*
|
|
94
|
+
* @example
|
|
95
|
+
* ```ts
|
|
96
|
+
* t.overlay.hide();
|
|
97
|
+
* ```
|
|
98
|
+
*
|
|
99
|
+
* @see {@link https://code.textmode.art/api/textmode.overlay.js/interfaces/TextmodeOverlayController#hide | TextmodeOverlayController.hide API reference}
|
|
100
|
+
*/
|
|
101
|
+
hide(): void;
|
|
102
|
+
/**
|
|
103
|
+
* Toggle output-canvas visibility.
|
|
104
|
+
*
|
|
105
|
+
* @category Visibility
|
|
106
|
+
*
|
|
107
|
+
* @example
|
|
108
|
+
* ```ts
|
|
109
|
+
* t.overlay.toggle();
|
|
110
|
+
* ```
|
|
111
|
+
*
|
|
112
|
+
* @see {@link https://code.textmode.art/api/textmode.overlay.js/interfaces/TextmodeOverlayController#toggle | TextmodeOverlayController.toggle API reference}
|
|
113
|
+
*/
|
|
114
|
+
toggle(): void;
|
|
115
|
+
/**
|
|
116
|
+
* Report the controller's intended output visibility.
|
|
117
|
+
*
|
|
118
|
+
* @category Visibility
|
|
119
|
+
*
|
|
120
|
+
* @returns Whether the output canvas is shown.
|
|
121
|
+
*
|
|
122
|
+
* @example
|
|
123
|
+
* ```ts
|
|
124
|
+
* if (t.overlay.isVisible()) t.overlay.hide();
|
|
125
|
+
* ```
|
|
126
|
+
*
|
|
127
|
+
* @see {@link https://code.textmode.art/api/textmode.overlay.js/interfaces/TextmodeOverlayController#isvisible | TextmodeOverlayController.isVisible API reference}
|
|
128
|
+
*/
|
|
129
|
+
isVisible(): boolean;
|
|
130
|
+
}
|
package/package.json
ADDED
|
@@ -0,0 +1,97 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "textmode.overlay.js",
|
|
3
|
+
"version": "1.0.0-beta.1",
|
|
4
|
+
"description": "DOM overlay target plugin for textmode.js",
|
|
5
|
+
"type": "module",
|
|
6
|
+
"devEngines": {
|
|
7
|
+
"runtime": {
|
|
8
|
+
"name": "node",
|
|
9
|
+
"version": "^24.0.0",
|
|
10
|
+
"onFail": "error"
|
|
11
|
+
},
|
|
12
|
+
"packageManager": {
|
|
13
|
+
"name": "npm",
|
|
14
|
+
"version": "^11.0.0",
|
|
15
|
+
"onFail": "error"
|
|
16
|
+
}
|
|
17
|
+
},
|
|
18
|
+
"main": "./dist/textmode.overlay.umd.js",
|
|
19
|
+
"module": "./dist/textmode.overlay.esm.js",
|
|
20
|
+
"types": "./dist/types/index.d.ts",
|
|
21
|
+
"exports": {
|
|
22
|
+
".": {
|
|
23
|
+
"types": "./dist/types/index.d.ts",
|
|
24
|
+
"import": "./dist/textmode.overlay.esm.js",
|
|
25
|
+
"require": "./dist/textmode.overlay.umd.js"
|
|
26
|
+
}
|
|
27
|
+
},
|
|
28
|
+
"sideEffects": [
|
|
29
|
+
"./dist/textmode.overlay.esm.js",
|
|
30
|
+
"./dist/textmode.overlay.umd.js"
|
|
31
|
+
],
|
|
32
|
+
"files": [
|
|
33
|
+
"dist"
|
|
34
|
+
],
|
|
35
|
+
"scripts": {
|
|
36
|
+
"prebuild": "npm run clean",
|
|
37
|
+
"clean": "rm -rf dist",
|
|
38
|
+
"dev": "textmode-build dev --port 5180 --host",
|
|
39
|
+
"build:bundle": "textmode-build build",
|
|
40
|
+
"build:types": "textmode-types build",
|
|
41
|
+
"build": "npm run build:bundle && npm run build:types",
|
|
42
|
+
"check": "npm run format:check && npm run lint && npm run lint:markdown && npm run typecheck && npm run docs:check && npm run test && npm run build && npm run types:verify",
|
|
43
|
+
"docs:links:add": "textmode-docs links add",
|
|
44
|
+
"docs:api:check": "textmode-docs api-check",
|
|
45
|
+
"docs:check": "textmode-docs check",
|
|
46
|
+
"docs:dev": "textmode-docs watch",
|
|
47
|
+
"docs:build": "textmode-docs build",
|
|
48
|
+
"preview": "textmode-build preview",
|
|
49
|
+
"format": "textmode-lint format",
|
|
50
|
+
"format:check": "textmode-lint format:check",
|
|
51
|
+
"typecheck": "textmode-types check",
|
|
52
|
+
"types:verify": "textmode-types verify",
|
|
53
|
+
"lint:markdown": "textmode-lint lint:markdown",
|
|
54
|
+
"lint:markdown:fix": "textmode-lint lint:markdown --fix",
|
|
55
|
+
"lint": "textmode-lint lint src",
|
|
56
|
+
"prepare": "textmode-release hooks",
|
|
57
|
+
"prepack": "npm run build && npm run types:verify",
|
|
58
|
+
"release": "textmode-release release",
|
|
59
|
+
"test": "textmode-build test",
|
|
60
|
+
"test:watch": "textmode-build test:watch",
|
|
61
|
+
"test:unit": "textmode-build test --project unit",
|
|
62
|
+
"test:integration": "textmode-build test --project integration"
|
|
63
|
+
},
|
|
64
|
+
"peerDependencies": {
|
|
65
|
+
"textmode.js": "^0.18.0-beta.2"
|
|
66
|
+
},
|
|
67
|
+
"devDependencies": {
|
|
68
|
+
"@textmode/build": "^0.1.0",
|
|
69
|
+
"@textmode/docs": "^0.3.0",
|
|
70
|
+
"@textmode/lint": "^0.1.0",
|
|
71
|
+
"@textmode/release": "^0.2.0",
|
|
72
|
+
"@textmode/tsconfig": "^0.2.1",
|
|
73
|
+
"@types/node": "^24.0.0",
|
|
74
|
+
"textmode.js": "^0.18.0-beta.2",
|
|
75
|
+
"typescript": "^6.0.3",
|
|
76
|
+
"vitest": "^4.1.10"
|
|
77
|
+
},
|
|
78
|
+
"keywords": [
|
|
79
|
+
"ascii",
|
|
80
|
+
"textmode",
|
|
81
|
+
"canvas",
|
|
82
|
+
"video",
|
|
83
|
+
"overlay",
|
|
84
|
+
"creative-coding"
|
|
85
|
+
],
|
|
86
|
+
"author": "humanbydefinition <hello@textmode.art> (https://code.textmode.art)",
|
|
87
|
+
"license": "MIT",
|
|
88
|
+
"homepage": "https://code.textmode.art",
|
|
89
|
+
"prettier": "@textmode/lint/prettier",
|
|
90
|
+
"repository": {
|
|
91
|
+
"type": "git",
|
|
92
|
+
"url": "git+https://github.com/humanbydefinition/textmode.overlay.js.git"
|
|
93
|
+
},
|
|
94
|
+
"bugs": {
|
|
95
|
+
"url": "https://github.com/humanbydefinition/textmode.overlay.js/issues"
|
|
96
|
+
}
|
|
97
|
+
}
|