textmode.overlay.js 1.0.1 → 1.0.3
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 +1 -1
- package/dist/textmode.overlay.esm.js +1 -1
- package/dist/textmode.overlay.umd.js +1 -1
- package/dist/types/augmentations.d.ts +2 -3
- package/dist/types/index.d.ts +3 -2
- package/dist/types/runtime/OverlayGeometry.d.ts +2 -0
- package/dist/types/runtime/OverlaySynchronizer.d.ts +3 -0
- package/dist/types/runtime/TextmodeOverlayController.d.ts +8 -0
- package/package.json +6 -4
package/README.md
CHANGED
|
@@ -4,7 +4,7 @@
|
|
|
4
4
|
|
|
5
5
|
<img alt="textmode.overlay.js — overlay textmode above any target" src=".github/assets/readme-og.png" />
|
|
6
6
|
|
|
7
|
-
| [](https://www.typescriptlang.org/) [](https://vitejs.dev/) | [](https://code.textmode.art/api/textmode.overlay.js/) [](https://code.textmode.art/)
|
|
7
|
+
| [](https://www.typescriptlang.org/) [](https://vitejs.dev/) | [](https://code.textmode.art/api/textmode.overlay.js/) [](https://code.textmode.art/) | [](https://ko-fi.com/V7V8JG2FY) [](https://github.com/sponsors/humanbydefinition) |
|
|
8
8
|
|:---|:---|:---|
|
|
9
9
|
|
|
10
10
|
</div>
|
|
@@ -1 +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.
|
|
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())}synchronizeImmediately(t={}){this.$(),this.O(t.forceResize??!1)}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.F()}dispose(){this.clear({restoreCanvas:!0})}O(t=!1){const i=this.u;if(!i||!this.C())return;const n=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}}(i,this.t);if(!n||!t&&(o=n,(h=this.M)&&h.left===o.left&&h.top===o.top&&h.width===o.width&&h.height===o.height))return;var h,o;const r=this.M,a=t||!r||r.width!==n.width||r.height!==n.height;this.M=n,this.V("left",`${n.left}px`),this.V("top",`${n.top}px`),a&&this.i(n.width,n.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)}F(){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{I;t;R;u;j;v=!0;q=!1;constructor(t){this.I=t,this.t=t.canvas,this.R=new n(this.t,(t,i)=>this.I.resizeCanvas(t,i))}get target(){return this.A(),this.u}get source(){return this.A(),this.j}setTarget(i){return this.A(),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.j?(this.requestSynchronization(),this.j):(this.P(!1),this.u=i,this.j=this.I.createTexture(i),this.R.bind(i,this.v),this.j)}clearTarget(){this.A(),this.P(!0)}show(){this.A(),this.v=!0,this.R.setVisible(!0)}hide(){this.A(),this.v&&(this.v=!1,this.R.setVisible(!1))}toggle(){this.A(),this.v?this.hide():this.show()}isVisible(){return this.A(),this.v}requestSynchronization(){this.A(),this.R.request()}synchronizeImmediately(t={}){this.A(),this.R.synchronizeImmediately(t)}dispose(){this.q||(this.P(!0),this.R.dispose(),this.q=!0)}A(){if(this.q)throw new Error(`${t} This overlay controller has been disposed.`)}P(t){this.R.clear({restoreCanvas:t}),this.j?.dispose(),this.j=void 0,this.u=void 0}},o={name:"textmode.overlay.js",install(t,i){const s=new h(t),e=i.on("preSetup",()=>s.synchronizeImmediately({forceResize:!0})),n=i.on("postDraw",()=>s.requestSynchronization());try{i.defineExtension("textmodifier","overlay",{get:()=>s})}catch(o){throw s.dispose(),e(),n(),o}return()=>{s.dispose(),e(),n()}}};"undefined"!=typeof window&&(window.OverlayPlugin=o);export{o as OverlayPlugin};
|
|
@@ -1 +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
|
|
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 h=class{t;i;h;o;l;u;v=!0;m;p;_=!1;T;M;L=()=>this.request();constructor(t,i){var e;this.t=t,this.i=i,this.h=t.parentNode,this.o=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())}synchronizeImmediately(t={}){this.$(),this.O(t.forceResize??!1)}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(t=!1){const i=this.u;if(!i||!this.C())return;const e=function(t,i){s(getComputedStyle(t).transform);const e=t.getBoundingClientRect(),h=t instanceof HTMLCanvasElement?t.width:t.videoWidth,o=t instanceof HTMLCanvasElement?t.height:t.videoHeight,r=n(e.width>0?e.width:h),a=n(e.height>0?e.height:o);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}}(i,this.t);if(!e||!t&&(o=e,(h=this.M)&&h.left===o.left&&h.top===o.top&&h.width===o.width&&h.height===o.height))return;var h,o;const r=this.M,a=t||!r||r.width!==e.width||r.height!==e.height;this.M=e,this.V("left",`${e.left}px`),this.V("top",`${e.top}px`),a&&this.i(e.width,e.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}))}j(){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)}N(){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)}},o=class{F;t;I;u;R;v=!0;q=!1;constructor(t){this.F=t,this.t=t.canvas,this.I=new h(this.t,(t,i)=>this.F.resizeCanvas(t,i))}get target(){return this.A(),this.u}get source(){return this.A(),this.R}setTarget(t){return this.A(),function(t,e){const n="undefined"!=typeof HTMLCanvasElement&&t instanceof HTMLCanvasElement,h="undefined"!=typeof HTMLVideoElement&&t instanceof HTMLVideoElement;if(!n&&!h)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.R?(this.requestSynchronization(),this.R):(this.P(!1),this.u=t,this.R=this.F.createTexture(t),this.I.bind(t,this.v),this.R)}clearTarget(){this.A(),this.P(!0)}show(){this.A(),this.v=!0,this.I.setVisible(!0)}hide(){this.A(),this.v&&(this.v=!1,this.I.setVisible(!1))}toggle(){this.A(),this.v?this.hide():this.show()}isVisible(){return this.A(),this.v}requestSynchronization(){this.A(),this.I.request()}synchronizeImmediately(t={}){this.A(),this.I.synchronizeImmediately(t)}dispose(){this.q||(this.P(!0),this.I.dispose(),this.q=!0)}A(){if(this.q)throw new Error(`${i} This overlay controller has been disposed.`)}P(t){this.I.clear({restoreCanvas:t}),this.R?.dispose(),this.R=void 0,this.u=void 0}},r={name:"textmode.overlay.js",install(t,i){const e=new o(t),s=i.on("preSetup",()=>e.synchronizeImmediately({forceResize:!0})),n=i.on("postDraw",()=>e.requestSynchronization());try{i.defineExtension("textmodifier","overlay",{get:()=>e})}catch(h){throw e.dispose(),s(),n(),h}return()=>{e.dispose(),s(),n()}}};"undefined"!=typeof window&&(window.OverlayPlugin=r),t.OverlayPlugin=r});
|
|
@@ -1,7 +1,6 @@
|
|
|
1
|
-
import 'textmode.js';
|
|
2
1
|
import type { TextmodeOverlayController } from './types';
|
|
3
|
-
declare module 'textmode.js' {
|
|
4
|
-
interface
|
|
2
|
+
declare module 'textmode.js/addon' {
|
|
3
|
+
interface TextmodifierExtensions {
|
|
5
4
|
/** Controller installed by {@link OverlayPlugin}. */
|
|
6
5
|
readonly overlay: TextmodeOverlayController;
|
|
7
6
|
}
|
package/dist/types/index.d.ts
CHANGED
|
@@ -23,9 +23,10 @@
|
|
|
23
23
|
* @showCategories
|
|
24
24
|
*/
|
|
25
25
|
import './augmentations';
|
|
26
|
-
export { OverlayPlugin } from './OverlayPlugin';
|
|
27
|
-
export type { TextmodeOverlayController, TextmodeOverlayTarget } from './types';
|
|
28
26
|
import type { TextmodePlugin } from 'textmode.js';
|
|
27
|
+
import { OverlayPlugin } from './OverlayPlugin';
|
|
28
|
+
export { OverlayPlugin };
|
|
29
|
+
export type { TextmodeOverlayController, TextmodeOverlayTarget } from './types';
|
|
29
30
|
declare global {
|
|
30
31
|
interface Window {
|
|
31
32
|
OverlayPlugin?: TextmodePlugin;
|
|
@@ -17,6 +17,9 @@ export declare class OverlaySynchronizer {
|
|
|
17
17
|
constructor(output: HTMLCanvasElement, resizeCanvas: (width: number, height: number) => void);
|
|
18
18
|
bind(target: TextmodeOverlayTarget, visible: boolean): void;
|
|
19
19
|
request(): void;
|
|
20
|
+
synchronizeImmediately(options?: {
|
|
21
|
+
forceResize?: boolean;
|
|
22
|
+
}): void;
|
|
20
23
|
setVisible(visible: boolean): void;
|
|
21
24
|
clear(options: {
|
|
22
25
|
restoreCanvas: boolean;
|
|
@@ -24,6 +24,14 @@ export declare class TextmodeOverlayControllerImpl implements TextmodeOverlayCon
|
|
|
24
24
|
* @internal
|
|
25
25
|
*/
|
|
26
26
|
requestSynchronization(): void;
|
|
27
|
+
/**
|
|
28
|
+
* Synchronize target geometry immediately at a host lifecycle boundary.
|
|
29
|
+
*
|
|
30
|
+
* @internal
|
|
31
|
+
*/
|
|
32
|
+
synchronizeImmediately(options?: {
|
|
33
|
+
forceResize?: boolean;
|
|
34
|
+
}): void;
|
|
27
35
|
/** Release all plugin-owned resources. */
|
|
28
36
|
dispose(): void;
|
|
29
37
|
private _assertActive;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "textmode.overlay.js",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.3",
|
|
4
4
|
"description": "DOM overlay target plugin for textmode.js",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"devEngines": {
|
|
@@ -33,6 +33,8 @@
|
|
|
33
33
|
"dist"
|
|
34
34
|
],
|
|
35
35
|
"scripts": {
|
|
36
|
+
"prebuild": "npm run clean",
|
|
37
|
+
"clean": "rm -rf dist",
|
|
36
38
|
"dev": "textmode-build dev --port 5180 --host",
|
|
37
39
|
"build:bundle": "textmode-build build",
|
|
38
40
|
"build:types": "textmode-types build",
|
|
@@ -60,16 +62,16 @@
|
|
|
60
62
|
"test:integration": "textmode-build test --project integration"
|
|
61
63
|
},
|
|
62
64
|
"peerDependencies": {
|
|
63
|
-
"textmode.js": "^0.
|
|
65
|
+
"textmode.js": "^0.18.0"
|
|
64
66
|
},
|
|
65
67
|
"devDependencies": {
|
|
66
68
|
"@textmode/build": "^0.1.0",
|
|
67
69
|
"@textmode/docs": "^0.3.0",
|
|
68
70
|
"@textmode/lint": "^0.1.0",
|
|
69
71
|
"@textmode/release": "^0.2.0",
|
|
70
|
-
"@textmode/tsconfig": "^0.2.
|
|
72
|
+
"@textmode/tsconfig": "^0.2.1",
|
|
71
73
|
"@types/node": "^24.0.0",
|
|
72
|
-
"textmode.js": "^0.
|
|
74
|
+
"textmode.js": "^0.18.0",
|
|
73
75
|
"typescript": "^6.0.3",
|
|
74
76
|
"vitest": "^4.1.10"
|
|
75
77
|
},
|