From 3fc17b0fb5ed2e557e5c07d1716bf428b6aa266c Mon Sep 17 00:00:00 2001 From: Keith Cirkel Date: Mon, 26 Feb 2024 23:33:26 +0000 Subject: [PATCH] always minify --- invoker.min.js | 2 +- package.json | 1 + 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/invoker.min.js b/invoker.min.js index dc5cce2..28b30f8 100644 --- a/invoker.min.js +++ b/invoker.min.js @@ -1 +1 @@ -(()=>{if(typeof HTMLButtonElement>"u"||typeof HTMLButtonElement.prototype!="object"||"invokeTargetElement"in HTMLButtonElement.prototype)return;document.addEventListener("invoke",t=>{t.type=="invoke"&&t.isTrusted&&t.stopImmediatePropagation()},!0);function h(t,e){Object.defineProperty(t,e,{...Object.getOwnPropertyDescriptor(t,e),enumerable:!0})}function s(t){return t&&typeof t.getRootNode=="function"?t.getRootNode():t&&t.parentNode?s(t.parentNode):t}const d=globalThis.ShadowRoot||function(){},l=new WeakMap,c=new WeakMap;class a extends Event{constructor(e,o={}){super(e,o);const{invoker:i,action:n}=o;if(i!=null&&!(i instanceof Element))throw new TypeError("invoker must be an element");l.set(this,i||null),c.set(this,n!==void 0?String(n):"auto")}get[Symbol.toStringTag](){return"InvokeEvent"}get invoker(){if(!l.has(this))throw new TypeError("illegal invocation");const e=l.get(this);if(!(e instanceof Element))return null;const o=s(e);return o!==s(this.target||document)?o.host:e}get action(){if(!c.has(this))throw new TypeError("illegal invocation");return c.get(this)}}h(a.prototype,"invoker"),h(a.prototype,"action");const u=new WeakMap;function p(t){Object.defineProperties(t.prototype,{invokeTargetElement:{enumerable:!0,configurable:!0,set(e){if(e===null)this.removeAttribute("invoketarget"),u.delete(this);else if(e instanceof Element){this.setAttribute("invoketarget","");const o=s(e);s(this)===o||o===this.ownerDocument?u.set(this,e):u.delete(this)}else throw new TypeError("invokeTargetElement must be an element or null")},get(){if(this.localName!=="button"&&this.localName!=="input"||this.localName==="input"&&this.type!=="reset"&&this.type!=="image"&&this.type!=="button"||this.disabled||this.form&&this.type==="submit")return null;const e=u.get(this);if(e)return e.isConnected?e:(u.delete(this),null);const o=s(this),i=this.getAttribute("invoketarget");return(o instanceof Document||o instanceof d)&&i&&o.getElementById(i)||null}},invokeAction:{enumerable:!0,configurable:!0,get(){const e=this.getAttribute("invokeaction")||"";return e||"auto"},set(e){this.setAttribute("invokeaction",e)}}})}function v(t){if(t.defaultPrevented||t.type!=="click")return;const e=t.target.closest("button[invoketarget], input[invoketarget]");if(!e)return;const o=e.invokeTargetElement,i=new a("invoke",{action:e.invokeAction,invoker:e});if(o.dispatchEvent(i),i.defaultPrevented)return;const n=i.action.toLowerCase();if(o.popover){const r=!o.matches(":popover-open");r&&(n==="auto"||n==="togglepopover"||n==="showpopover")?o.showPopover():!r&&(n==="auto"||n==="hidepopover")&&o.hidePopover()}else if(o.localName==="dialog"){const r=!o.hasAttribute("open");r&&(n==="auto"||n==="showmodal")?o.showModal():!r&&(n==="auto"||n==="close")&&o.close()}}function f(t){t.addEventListener("click",v,!0)}function g(t,e){const o=t.prototype.attachShadow;t.prototype.attachShadow=function(n){const r=o.call(this,n);return e(r),r};const i=t.prototype.attachInternals;t.prototype.attachInternals=function(){const n=i.call(this);return n.shadowRoot&&e(n.shadowRoot),n}}p(globalThis.HTMLButtonElement||function(){}),p(globalThis.HTMLInputElement||function(){}),g(globalThis.HTMLElement||function(){},t=>{f(t)}),f(document),Object.defineProperty(window,"InvokeEvent",{value:a,configurable:!0,writable:!0})})(); +(()=>{if(typeof HTMLButtonElement>"u"||typeof HTMLButtonElement.prototype!="object"||"invokeTargetElement"in HTMLButtonElement.prototype)return;document.addEventListener("invoke",t=>{t.type=="invoke"&&t.isTrusted&&t.stopImmediatePropagation()},!0);function h(t,e){Object.defineProperty(t,e,{...Object.getOwnPropertyDescriptor(t,e),enumerable:!0})}function s(t){return t&&typeof t.getRootNode=="function"?t.getRootNode():t&&t.parentNode?s(t.parentNode):t}const d=globalThis.ShadowRoot||function(){},l=new WeakMap,c=new WeakMap;class a extends Event{constructor(e,o={}){super(e,o);const{invoker:i,action:n}=o;if(i!=null&&!(i instanceof Element))throw new TypeError("invoker must be an element");l.set(this,i||null),c.set(this,n!==void 0?String(n):"")}get[Symbol.toStringTag](){return"InvokeEvent"}get invoker(){if(!l.has(this))throw new TypeError("illegal invocation");const e=l.get(this);if(!(e instanceof Element))return null;const o=s(e);return o!==s(this.target||document)?o.host:e}get action(){if(!c.has(this))throw new TypeError("illegal invocation");return c.get(this)}}h(a.prototype,"invoker"),h(a.prototype,"action");const u=new WeakMap;function p(t){Object.defineProperties(t.prototype,{invokeTargetElement:{enumerable:!0,configurable:!0,set(e){if(e===null)this.removeAttribute("invoketarget"),u.delete(this);else if(e instanceof Element){this.setAttribute("invoketarget","");const o=s(e);s(this)===o||o===this.ownerDocument?u.set(this,e):u.delete(this)}else throw new TypeError("invokeTargetElement must be an element or null")},get(){if(this.localName!=="button"&&this.localName!=="input"||this.localName==="input"&&this.type!=="reset"&&this.type!=="image"&&this.type!=="button"||this.disabled||this.form&&this.type==="submit")return null;const e=u.get(this);if(e)return e.isConnected?e:(u.delete(this),null);const o=s(this),i=this.getAttribute("invoketarget");return(o instanceof Document||o instanceof d)&&i&&o.getElementById(i)||null}},invokeAction:{enumerable:!0,configurable:!0,get(){const e=this.getAttribute("invokeaction")||"";return e||""},set(e){this.setAttribute("invokeaction",e)}}})}function v(t){if(t.defaultPrevented||t.type!=="click")return;const e=t.target.closest("button[invoketarget], input[invoketarget]");if(!e)return;const o=e.invokeTargetElement,i=new a("invoke",{action:e.invokeAction,invoker:e});if(o.dispatchEvent(i),i.defaultPrevented)return;const n=i.action.toLowerCase();if(o.popover){const r=!o.matches(":popover-open");r&&(n===""||n==="togglepopover"||n==="showpopover")?o.showPopover():!r&&(n===""||n==="hidepopover")&&o.hidePopover()}else if(o.localName==="dialog"){const r=!o.hasAttribute("open");r&&(n===""||n==="showmodal")?o.showModal():!r&&(n===""||n==="close")&&o.close()}}function f(t){t.addEventListener("click",v,!0)}function g(t,e){const o=t.prototype.attachShadow;t.prototype.attachShadow=function(n){const r=o.call(this,n);return e(r),r};const i=t.prototype.attachInternals;t.prototype.attachInternals=function(){const n=i.call(this);return n.shadowRoot&&e(n.shadowRoot),n}}p(globalThis.HTMLButtonElement||function(){}),p(globalThis.HTMLInputElement||function(){}),g(globalThis.HTMLElement||function(){},t=>{f(t)}),f(document),Object.defineProperty(window,"InvokeEvent",{value:a,configurable:!0,writable:!0})})(); diff --git a/package.json b/package.json index 3cb1cb8..552b322 100644 --- a/package.json +++ b/package.json @@ -16,6 +16,7 @@ "invoker.min.js" ], "scripts": { + "prepublishOnly": "npm run minify", "minify": "esbuild --minify invoker.js > invoker.min.js", "test": "echo TODO! Run ./wpt serve --inject-script=../invoker-buttons/invoker.js for now." },