From 8b4a2d3ad4b6c2e07c48f5eeed1fb62efb513078 Mon Sep 17 00:00:00 2001 From: Nate Clark Date: Tue, 26 Nov 2024 18:07:37 -0500 Subject: [PATCH] directly host improv wifi JS --- js/launch-button.js | 1 + js/serial-launch-button.js | 1 + wifi.html | 3 ++- 3 files changed, 4 insertions(+), 1 deletion(-) create mode 100644 js/launch-button.js create mode 100644 js/serial-launch-button.js diff --git a/js/launch-button.js b/js/launch-button.js new file mode 100644 index 0000000..304bd8a --- /dev/null +++ b/js/launch-button.js @@ -0,0 +1 @@ +class o extends HTMLElement{connectedCallback(){if(this.renderRoot)return;if(this.renderRoot=this.attachShadow({mode:"open"}),!o.isSupported||!o.isAllowed)return this.toggleAttribute("not-supported",!0),void(this.renderRoot.innerHTML=o.isAllowed?"Your browser does not support bluetooth provisioning. Use Google Chrome or Microsoft Edge.":"You can only use Improv on HTTPS sites or localhost.");this.toggleAttribute("supported",!0),this.addEventListener("mouseover",(()=>{import("./provision-095c1472.js").then((function(o){return o.p}))}));const e=document.createElement("slot");e.name="activate";const t=document.createElement("button");if(t.innerText="Connect device to Wi-Fi",e.append(t),e.addEventListener("click",(async o=>{o.preventDefault();(await import("./provision-095c1472.js").then((function(o){return o.p}))).startProvisioning(this)})),"adoptedStyleSheets"in Document.prototype&&"replaceSync"in CSSStyleSheet.prototype){const e=new CSSStyleSheet;e.replaceSync(o.style),this.renderRoot.adoptedStyleSheets=[e]}else{const e=document.createElement("style");e.innerText=o.style,this.renderRoot.append(e)}this.renderRoot.append(e)}}o.isSupported="bluetooth"in navigator,o.isAllowed=window.isSecureContext,o.style='\n button {\n position: relative;\n cursor: pointer;\n font-size: 14px;\n padding: 8px 28px;\n color: var(--improv-on-primary-color, #fff);\n background-color: var(--improv-primary-color, #03a9f4);\n border: none;\n border-radius: 4px;\n box-shadow: 0 2px 2px 0 rgba(0,0,0,.14), 0 3px 1px -2px rgba(0,0,0,.12), 0 1px 5px 0 rgba(0,0,0,.2);\n }\n button::before {\n content: " ";\n position: absolute;\n top: 0;\n bottom: 0;\n left: 0;\n right: 0;\n opacity: 0.2;\n border-radius: 4px;\n }\n button:hover {\n box-shadow: 0 4px 8px 0 rgba(0,0,0,.14), 0 1px 7px 0 rgba(0,0,0,.12), 0 3px 1px -1px rgba(0,0,0,.2);\n }\n button:hover::before {\n background-color: rgba(255,255,255,.8);\n }\n button:focus {\n outline: none;\n }\n button:focus::before {\n background-color: white;\n }\n button:active::before {\n background-color: grey;\n }\n',customElements.define("improv-wifi-launch-button",o); diff --git a/js/serial-launch-button.js b/js/serial-launch-button.js new file mode 100644 index 0000000..f5ca1ee --- /dev/null +++ b/js/serial-launch-button.js @@ -0,0 +1 @@ +const e=(e,o,t,n)=>{n=n||{};const r=new CustomEvent(o,{bubbles:void 0===n.bubbles||n.bubbles,cancelable:Boolean(n.cancelable),composed:void 0===n.composed||n.composed,detail:t});e.dispatchEvent(r)};class o extends HTMLElement{connectedCallback(){if(this.renderRoot)return;if(this.renderRoot=this.attachShadow({mode:"open"}),!o.isSupported||!o.isAllowed)return this.toggleAttribute("not-supported",!0),void(this.renderRoot.innerHTML=o.isAllowed?"Your browser does not support serial provisioning. Use Google Chrome or Microsoft Edge.":"You can only use Improv on HTTPS sites or localhost.");this.toggleAttribute("supported",!0);const t=document.createElement("slot");t.name="activate";const n=document.createElement("button");if(n.innerText="Connect device to Wi-Fi",t.append(n),t.addEventListener("click",(async o=>{o.preventDefault(),(async o=>{let t;import("./serial-provision-dialog-8dcc4267.js");try{t=await navigator.serial.requestPort()}catch(e){if("NotFoundError"===e.name)return;return void alert(`Error: ${e.message}`)}if(!t)return;await t.open({baudRate:115200});const n=document.createElement("improv-wifi-serial-provision-dialog");n.port=t,n.addEventListener("closed",(async n=>{await t.close(),e(o,"closed",n.detail)}),{once:!0}),document.body.appendChild(n)})(this)})),"adoptedStyleSheets"in Document.prototype&&"replaceSync"in CSSStyleSheet.prototype){const e=new CSSStyleSheet;e.replaceSync(o.style),this.renderRoot.adoptedStyleSheets=[e]}else{const e=document.createElement("style");e.innerText=o.style,this.renderRoot.append(e)}this.renderRoot.append(t)}}o.isSupported="serial"in navigator,o.isAllowed=window.isSecureContext,o.style='\n button {\n position: relative;\n cursor: pointer;\n font-size: 14px;\n padding: 8px 28px;\n color: var(--improv-on-primary-color, #fff);\n background-color: var(--improv-primary-color, #03a9f4);\n border: none;\n border-radius: 4px;\n box-shadow: 0 2px 2px 0 rgba(0,0,0,.14), 0 3px 1px -2px rgba(0,0,0,.12), 0 1px 5px 0 rgba(0,0,0,.2);\n }\n button::before {\n content: " ";\n position: absolute;\n top: 0;\n bottom: 0;\n left: 0;\n right: 0;\n opacity: 0.2;\n border-radius: 4px;\n }\n button:hover {\n box-shadow: 0 4px 8px 0 rgba(0,0,0,.14), 0 1px 7px 0 rgba(0,0,0,.12), 0 3px 1px -1px rgba(0,0,0,.2);\n }\n button:hover::before {\n background-color: rgba(255,255,255,.8);\n }\n button:focus {\n outline: none;\n }\n button:focus::before {\n background-color: white;\n }\n button:active::before {\n background-color: grey;\n }\n',customElements.define("improv-wifi-serial-launch-button",o);export{e as f}; diff --git a/wifi.html b/wifi.html index 2676ac8..bda8b1a 100644 --- a/wifi.html +++ b/wifi.html @@ -51,7 +51,8 @@ .badge.beta{background: #fdf0d7;} improv-wifi-launch-button{zoom:1.5;} - + +