textmode.overlay.js 1.0.2 → 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 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
- | [![TypeScript](https://img.shields.io/badge/TypeScript-3178C6?logo=typescript&logoColor=white)](https://www.typescriptlang.org/) [![Vite](https://img.shields.io/badge/Vite-646CFF?logo=vite&logoColor=white)](https://vitejs.dev/) | [![API](https://img.shields.io/badge/API-typedoc-3178c6?logo=typescript&logoColor=white)](https://code.textmode.art/api/textmode.overlay.js/) [![docs](https://img.shields.io/badge/docs-vitepress-646cff?logo=vitepress&logoColor=white)](https://code.textmode.art/) [![Discord](https://img.shields.io/discord/1357070706181017691?color=5865F2&label=Discord&logo=discord&logoColor=white)](https://discord.gg/sjrw8QXNks) | [![ko-fi](https://shields.io/badge/ko--fi-donate-ff5f5f?logo=ko-fi)](https://ko-fi.com/V7V8JG2FY) [![GitHub-sponsors](https://img.shields.io/badge/sponsor-30363D?logo=GitHub-Sponsors&logoColor=#EA4AAA)](https://github.com/sponsors/humanbydefinition) |
7
+ | [![TypeScript](https://img.shields.io/badge/TypeScript-3178C6?logo=typescript&logoColor=white)](https://www.typescriptlang.org/) [![Vite](https://img.shields.io/badge/Vite-646CFF?logo=vite&logoColor=white)](https://vitejs.dev/) | [![API](https://img.shields.io/badge/API-typedoc-3178c6?logo=typescript&logoColor=white)](https://code.textmode.art/api/textmode.overlay.js/) [![docs](https://img.shields.io/badge/docs-vitepress-646cff?logo=vitepress&logoColor=white)](https://code.textmode.art/) | [![ko-fi](https://shields.io/badge/ko--fi-donate-ff5f5f?logo=ko-fi)](https://ko-fi.com/V7V8JG2FY) [![GitHub-sponsors](https://img.shields.io/badge/sponsor-30363D?logo=GitHub-Sponsors&logoColor=#EA4AAA)](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())}synchronizeImmediately(t={}){this.V(),this.O(t.forceResize??!1)}setVisible(t){this.v=t,t?(this.$("display",this.l.display),this.C(),this.request()):this.$("display","none")}clear(t){this.V(),this.N(),this.u=void 0,this.M=void 0,t.restoreCanvas&&this.j()}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.$("left",`${n.left}px`),this.$("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.$("position","absolute"),this.$("zIndex",String((Number.isFinite(i)?i:0)+1)),this.$("pointerEvents","auto"),this.$("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))}V(){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)}$(t,i){this.t.style[t]!==i&&(this.t.style[t]=i)}},h=class{F;t;I;u;R;v=!0;q=!1;constructor(t){this.F=t,this.t=t.canvas,this.I=new n(this.t,(t,i)=>this.F.resizeCanvas(t,i))}get target(){return this.A(),this.u}get source(){return this.A(),this.R}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.R?(this.requestSynchronization(),this.R):(this.P(!1),this.u=i,this.R=this.F.createTexture(i),this.I.bind(i,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("[textmode.overlay.js] This overlay controller has been disposed.")}P(t){this.I.clear({restoreCanvas:t}),this.R?.dispose(),this.R=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
+ 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 o=class{t;i;o;h;l;u;v=!0;m;p;_=!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())}synchronizeImmediately(t={}){this.V(),this.O(t.forceResize??!1)}setVisible(t){this.v=t,t?(this.$("display",this.l.display),this.C(),this.request()):this.$("display","none")}clear(t){this.V(),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(),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}}(i,this.t);if(!e||!t&&(h=e,(o=this.M)&&o.left===h.left&&o.top===h.top&&o.width===h.width&&o.height===h.height))return;var o,h;const r=this.M,a=t||!r||r.width!==e.width||r.height!==e.height;this.M=e,this.$("left",`${e.left}px`),this.$("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.$("position","absolute"),this.$("zIndex",String((Number.isFinite(i)?i:0)+1)),this.$("pointerEvents","auto"),this.$("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))}V(){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)}$(t,i){this.t.style[t]!==i&&(this.t.style[t]=i)}},h=class{F;t;I;u;R;v=!0;q=!1;constructor(t){this.F=t,this.t=t.canvas,this.I=new o(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,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.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("[textmode.overlay.js] 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 h(t),s=i.on("preSetup",()=>e.synchronizeImmediately({forceResize:!0})),n=i.on("postDraw",()=>e.requestSynchronization());try{i.defineExtension("textmodifier","overlay",{get:()=>e})}catch(o){throw e.dispose(),s(),n(),o}return()=>{e.dispose(),s(),n()}}};"undefined"!=typeof window&&(window.OverlayPlugin=r),t.OverlayPlugin=r});
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});
@@ -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;
@@ -1,4 +1,6 @@
1
1
  import type { TextmodeOverlayTarget } from '../types';
2
+ /** @internal */
3
+ export declare const ERROR_PREFIX = "[textmode.overlay.js]";
2
4
  /**
3
5
  * Internal immutable geometry value used by the synchronizer.
4
6
  *
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "textmode.overlay.js",
3
- "version": "1.0.2",
3
+ "version": "1.0.3",
4
4
  "description": "DOM overlay target plugin for textmode.js",
5
5
  "type": "module",
6
6
  "devEngines": {