dictate-button 0.2.0 → 1.0.0

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.
@@ -1 +1 @@
1
- export declare const dictateButtonStyles = "\n:host([theme=\"dark\"]) {\n color-scheme: only dark;\n}\n:host([theme=\"light\"]) {\n color-scheme: only light;\n}\n\n:host .dictate-button__container {\n margin: 5px;\n}\n\n:host .dictate-button__button {\n cursor: pointer;\n padding: 2px;\n display: inline-flex;\n align-items: center;\n justify-content: center;\n opacity: 0.8;\n transition: opacity 0.2s ease-in-out;\n}\n\n:host .dictate-button__button .dictate-button__icon {\n width: 100%;\n height: 100%;\n}\n\n:host .dictate-button__button .dictate-button__icon.dictate-button__icon--processing {\n animation: dictate-button-rotate 1s linear infinite;\n}\n\n@keyframes dictate-button-rotate {\n 0% { transform: rotate(0deg); }\n 100% { transform: rotate(360deg); }\n}\n";
1
+ export declare const dictateButtonStyles = "\n:host([theme=\"dark\"]) {\n color-scheme: only dark;\n}\n:host([theme=\"light\"]) {\n color-scheme: only light;\n}\n\n:host .dictate-button__button {\n cursor: pointer;\n padding: 8px;\n display: inline-flex;\n align-items: center;\n justify-content: center;\n color: light-dark(rgba(0, 0, 0, 0.6), rgba(0, 0, 0, 0.95));\n background-color: light-dark(rgba(0, 0, 0, 0.05), rgba(255, 255, 255, 0.7));\n border-radius: 50%;\n border: none;\n transition: box-shadow 0.05s linear;\n box-sizing: border-box;\n}\n:host .dictate-button__button:hover, :host .dictate-button__button:focus {\n background-color: light-dark(rgba(0, 0, 0, 0.1), rgba(255, 255, 255, 0.6));\n}\n\n:host .dictate-button__button .dictate-button__icon {\n width: 100%;\n height: 100%;\n}\n\n:host .dictate-button__button .dictate-button__icon.dictate-button__icon--processing {\n animation: dictate-button-rotate 1s linear infinite;\n}\n\n@keyframes dictate-button-rotate {\n 0% { transform: rotate(0deg); }\n 100% { transform: rotate(360deg); }\n}\n";
@@ -0,0 +1,42 @@
1
+ function r() {
2
+ const i = document.querySelectorAll(
3
+ 'textarea[data-dictate-button-on]:not([data-dictate-button-enabled]), input[type="text"][data-dictate-button-on]:not([data-dictate-button-enabled])'
4
+ );
5
+ for (const n of i) {
6
+ const o = document.createElement("div");
7
+ o.style.position = "relative", o.style.display = "inline-block", o.style.width = "auto", o.style.color = "inherit", n.parentNode.insertBefore(o, n), n.setAttribute("data-dictate-button-enabled", ""), o.appendChild(n), n.style.boxSizing = "border-box";
8
+ const t = document.createElement("dictate-button");
9
+ t.size = 30, t.style.position = "absolute", t.style.right = "0", t.style.top = d(o, n) + "px", t.style.margin = "10px";
10
+ const a = document.documentElement.lang;
11
+ a && a.length === 2 && (t.language = a), t.addEventListener("recording:started", (e) => {
12
+ console.log("recording:started", e);
13
+ }), t.addEventListener("recording:stopped", (e) => {
14
+ console.log("recording:stopped", e);
15
+ }), t.addEventListener("recording:failed", (e) => {
16
+ console.log("recording:failed", e);
17
+ }), t.addEventListener("transcribing:started", (e) => {
18
+ console.log("transcribing:started", e);
19
+ }), t.addEventListener("transcribing:finished", (e) => {
20
+ console.log("transcribing:finished", e);
21
+ const s = e.detail;
22
+ c(n, s);
23
+ }), t.addEventListener("transcribing:failed", (e) => {
24
+ console.log("transcribing:failed", e);
25
+ }), o.appendChild(t);
26
+ }
27
+ }
28
+ function d(i, n) {
29
+ return n.tagName.toLowerCase() === "textarea" ? 0 : Math.round(
30
+ i.clientHeight / 2 - 30 / 2 - 10
31
+ );
32
+ }
33
+ function c(i, n) {
34
+ const o = i.selectionStart || 0, t = i.selectionEnd || 0;
35
+ i.value = i.value.substring(0, o) + n + i.value.substring(t);
36
+ }
37
+ document.addEventListener("DOMContentLoaded", () => {
38
+ r(), new MutationObserver(r).observe(document.body, {
39
+ childList: !0,
40
+ subtree: !0
41
+ });
42
+ });
@@ -0,0 +1,42 @@
1
+ function r() {
2
+ const i = document.querySelectorAll(
3
+ 'textarea:not([data-dictate-button-off]):not([data-dictate-button-enabled]), input[type="text"]:not([data-dictate-button-off]):not([data-dictate-button-enabled])'
4
+ );
5
+ for (const n of i) {
6
+ const o = document.createElement("div");
7
+ o.style.position = "relative", o.style.display = "inline-block", o.style.width = "auto", o.style.color = "inherit", n.parentNode.insertBefore(o, n), n.setAttribute("data-dictate-button-enabled", ""), o.appendChild(n), n.style.boxSizing = "border-box";
8
+ const t = document.createElement("dictate-button");
9
+ t.size = 30, t.style.position = "absolute", t.style.right = "0", t.style.top = d(o, n) + "px", t.style.margin = "10px";
10
+ const a = document.documentElement.lang;
11
+ a && a.length === 2 && (t.language = a), t.addEventListener("recording:started", (e) => {
12
+ console.log("recording:started", e);
13
+ }), t.addEventListener("recording:stopped", (e) => {
14
+ console.log("recording:stopped", e);
15
+ }), t.addEventListener("recording:failed", (e) => {
16
+ console.log("recording:failed", e);
17
+ }), t.addEventListener("transcribing:started", (e) => {
18
+ console.log("transcribing:started", e);
19
+ }), t.addEventListener("transcribing:finished", (e) => {
20
+ console.log("transcribing:finished", e);
21
+ const s = e.detail;
22
+ c(n, s);
23
+ }), t.addEventListener("transcribing:failed", (e) => {
24
+ console.log("transcribing:failed", e);
25
+ }), o.appendChild(t);
26
+ }
27
+ }
28
+ function d(i, n) {
29
+ return n.tagName.toLowerCase() === "textarea" ? 0 : Math.round(
30
+ i.clientHeight / 2 - 30 / 2 - 10
31
+ );
32
+ }
33
+ function c(i, n) {
34
+ const o = i.selectionStart || 0, t = i.selectionEnd || 0;
35
+ i.value = i.value.substring(0, o) + n + i.value.substring(t);
36
+ }
37
+ document.addEventListener("DOMContentLoaded", () => {
38
+ r(), new MutationObserver(r).observe(document.body, {
39
+ childList: !0,
40
+ subtree: !0
41
+ });
42
+ });
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "dictate-button",
3
- "version": "0.2.0",
3
+ "version": "1.0.0",
4
4
  "description": "Dictate Button (Web Component)",
5
5
  "keywords": [
6
6
  "custom-element",
@@ -17,38 +17,42 @@
17
17
  "web-component"
18
18
  ],
19
19
  "license": "Apache-2.0",
20
- "main": "dist/dictate-button.cjs.js",
21
- "module": "dist/dictate-button.es.js",
20
+ "type": "module",
22
21
  "types": "dist/dictate-button.d.ts",
23
22
  "exports": {
24
23
  ".": {
25
24
  "types": "./dist/dictate-button.d.ts",
26
- "import": "./dist/dictate-button.es.js",
27
- "require": "./dist/dictate-button.cjs.js"
28
- },
29
- "./inject": {
30
- "import": "./dist/inject.es.js",
31
- "require": "./dist/inject.cjs.js"
25
+ "import": "./dist/dictate-button.js",
26
+ "default": "./dist/dictate-button.js"
32
27
  },
33
28
  "./inject-exclusive": {
34
- "import": "./dist/inject-exclusive.es.js",
35
- "require": "./dist/inject-exclusive.cjs.js"
29
+ "types": "./dist/inject-exclusive.d.ts",
30
+ "import": "./dist/inject-exclusive.js",
31
+ "default": "./dist/inject-exclusive.js"
36
32
  },
37
33
  "./inject-inclusive": {
38
- "import": "./dist/inject-inclusive.es.js",
39
- "require": "./dist/inject-inclusive.cjs.js"
34
+ "types": "./dist/inject-inclusive.d.ts",
35
+ "import": "./dist/inject-inclusive.js",
36
+ "default": "./dist/inject-inclusive.js"
40
37
  }
41
38
  },
39
+ "files": [
40
+ "dist",
41
+ "!dist/404.html"
42
+ ],
43
+ "publishConfig": {
44
+ "access": "public"
45
+ },
42
46
  "dependencies": {
43
47
  "solid-element": "^1.9.1",
44
- "solid-js": "^1.9.7"
48
+ "solid-js": "^1.9.9"
45
49
  },
46
50
  "devDependencies": {
47
51
  "prettier": "^3.6.2",
48
- "typescript": "^5.8.3",
49
- "vite": "^7.0.6",
52
+ "typescript": "^5.9.2",
53
+ "vite": "^7.1.3",
50
54
  "vite-plugin-dts": "^4.5.4",
51
- "vite-plugin-solid": "^2.11.7",
55
+ "vite-plugin-solid": "^2.11.8",
52
56
  "vite-plugin-static-copy": "^3.1.1"
53
57
  },
54
58
  "homepage": "https://github.com/kkomelin/dictate-button",
package/.firebaserc DELETED
@@ -1,5 +0,0 @@
1
- {
2
- "projects": {
3
- "default": "dictate-button"
4
- }
5
- }
package/.prettierrc.mjs DELETED
@@ -1,10 +0,0 @@
1
- /** @type {import("prettier").Config} */
2
- const config = {
3
- trailingComma: 'es5',
4
- tabWidth: 2,
5
- useTabs: false,
6
- semi: false,
7
- singleQuote: true,
8
- }
9
-
10
- export default config
package/404.html DELETED
@@ -1,17 +0,0 @@
1
- <!DOCTYPE html>
2
- <html lang="en">
3
-
4
- <head>
5
- <meta charset="UTF-8">
6
- <meta name="viewport" content="width=device-width, initial-scale=1.0">
7
- <title>Dictate Button CDN</title>
8
- </head>
9
-
10
- <body
11
- style="display: flex; flex-direction: column; justify-content: center; align-items: center; gap: 1rem; height: 100vh;">
12
- <h1>404 - Not Found</h1>
13
- <p>Check the correct url in the docs <a href="https://github.com/kkomelin/dictate-button">kkomelin/dictate-button</a>
14
- </p>
15
- </body>
16
-
17
- </html>
package/dist/404.html DELETED
@@ -1,17 +0,0 @@
1
- <!DOCTYPE html>
2
- <html lang="en">
3
-
4
- <head>
5
- <meta charset="UTF-8">
6
- <meta name="viewport" content="width=device-width, initial-scale=1.0">
7
- <title>Dictate Button CDN</title>
8
- </head>
9
-
10
- <body
11
- style="display: flex; flex-direction: column; justify-content: center; align-items: center; gap: 1rem; height: 100vh;">
12
- <h1>404 - Not Found</h1>
13
- <p>Check the correct url in the docs <a href="https://github.com/kkomelin/dictate-button">kkomelin/dictate-button</a>
14
- </p>
15
- </body>
16
-
17
- </html>
@@ -1,36 +0,0 @@
1
- "use strict";const st=(t,e)=>t===e,T={equals:st};let rt=Q;const w=1,O=2,q={owned:null,cleanups:null,context:null,owner:null};var b=null;let R=null,it=null,f=null,p=null,_=null,B=0;function ot(t,e){const n=f,r=b,s=t.length===0,i=e===void 0?r:e,l=s?q:{owned:null,cleanups:null,context:i?i.context:null,owner:i},o=s?t:()=>t(()=>L(()=>E(l)));b=l,f=null;try{return A(o,!0)}finally{f=n,b=r}}function z(t,e){e=e?Object.assign({},T,e):T;const n={value:t,observers:null,observerSlots:null,comparator:e.equals||void 0},r=s=>(typeof s=="function"&&(s=s(n.value)),H(n,s));return[G.bind(n),r]}function P(t,e,n){const r=Z(t,e,!1,w);M(r)}function lt(t,e,n){n=n?Object.assign({},T,n):T;const r=Z(t,e,!0,0);return r.observers=null,r.observerSlots=null,r.comparator=n.equals||void 0,M(r),G.bind(r)}function L(t){if(f===null)return t();const e=f;f=null;try{return t()}finally{f=e}}function G(){if(this.sources&&this.state)if(this.state===w)M(this);else{const t=p;p=null,A(()=>j(this),!1),p=t}if(f){const t=this.observers?this.observers.length:0;f.sources?(f.sources.push(this),f.sourceSlots.push(t)):(f.sources=[this],f.sourceSlots=[t]),this.observers?(this.observers.push(f),this.observerSlots.push(f.sources.length-1)):(this.observers=[f],this.observerSlots=[f.sources.length-1])}return this.value}function H(t,e,n){let r=t.value;return(!t.comparator||!t.comparator(r,e))&&(t.value=e,t.observers&&t.observers.length&&A(()=>{for(let s=0;s<t.observers.length;s+=1){const i=t.observers[s],l=R&&R.running;l&&R.disposed.has(i),(l?!i.tState:!i.state)&&(i.pure?p.push(i):_.push(i),i.observers&&W(i)),l||(i.state=w)}if(p.length>1e6)throw p=[],new Error},!1)),e}function M(t){if(!t.fn)return;E(t);const e=B;ct(t,t.value,e)}function ct(t,e,n){let r;const s=b,i=f;f=b=t;try{r=t.fn(e)}catch(l){return t.pure&&(t.state=w,t.owned&&t.owned.forEach(E),t.owned=null),t.updatedAt=n+1,X(l)}finally{f=i,b=s}(!t.updatedAt||t.updatedAt<=n)&&(t.updatedAt!=null&&"observers"in t?H(t,r):t.value=r,t.updatedAt=n)}function Z(t,e,n,r=w,s){const i={fn:t,state:r,updatedAt:null,owned:null,sources:null,sourceSlots:null,cleanups:null,value:e,owner:b,context:b?b.context:null,pure:n};return b===null||b!==q&&(b.owned?b.owned.push(i):b.owned=[i]),i}function J(t){if(t.state===0)return;if(t.state===O)return j(t);if(t.suspense&&L(t.suspense.inFallback))return t.suspense.effects.push(t);const e=[t];for(;(t=t.owner)&&(!t.updatedAt||t.updatedAt<B);)t.state&&e.push(t);for(let n=e.length-1;n>=0;n--)if(t=e[n],t.state===w)M(t);else if(t.state===O){const r=p;p=null,A(()=>j(t,e[0]),!1),p=r}}function A(t,e){if(p)return t();let n=!1;e||(p=[]),_?n=!0:_=[],B++;try{const r=t();return at(n),r}catch(r){n||(_=null),p=null,X(r)}}function at(t){if(p&&(Q(p),p=null),t)return;const e=_;_=null,e.length&&A(()=>rt(e),!1)}function Q(t){for(let e=0;e<t.length;e++)J(t[e])}function j(t,e){t.state=0;for(let n=0;n<t.sources.length;n+=1){const r=t.sources[n];if(r.sources){const s=r.state;s===w?r!==e&&(!r.updatedAt||r.updatedAt<B)&&J(r):s===O&&j(r,e)}}}function W(t){for(let e=0;e<t.observers.length;e+=1){const n=t.observers[e];n.state||(n.state=O,n.pure?p.push(n):_.push(n),n.observers&&W(n))}}function E(t){let e;if(t.sources)for(;t.sources.length;){const n=t.sources.pop(),r=t.sourceSlots.pop(),s=n.observers;if(s&&s.length){const i=s.pop(),l=n.observerSlots.pop();r<s.length&&(i.sourceSlots[l]=r,s[r]=i,n.observerSlots[r]=l)}}if(t.tOwned){for(e=t.tOwned.length-1;e>=0;e--)E(t.tOwned[e]);delete t.tOwned}if(t.owned){for(e=t.owned.length-1;e>=0;e--)E(t.owned[e]);t.owned=null}if(t.cleanups){for(e=t.cleanups.length-1;e>=0;e--)t.cleanups[e]();t.cleanups=null}t.state=0}function ut(t){return t instanceof Error?t:new Error(typeof t=="string"?t:"Unknown error",{cause:t})}function X(t,e=b){throw ut(t)}function x(t,e){return L(()=>t(e||{}))}const $=t=>lt(()=>t());function ft(t,e,n){let r=n.length,s=e.length,i=r,l=0,o=0,c=e[s-1].nextSibling,a=null;for(;l<s||o<i;){if(e[l]===n[o]){l++,o++;continue}for(;e[s-1]===n[i-1];)s--,i--;if(s===l){const u=i<r?o?n[o-1].nextSibling:n[i-o]:c;for(;o<i;)t.insertBefore(n[o++],u)}else if(i===o)for(;l<s;)(!a||!a.has(e[l]))&&e[l].remove(),l++;else if(e[l]===n[i-1]&&n[o]===e[s-1]){const u=e[--s].nextSibling;t.insertBefore(n[o++],e[l++].nextSibling),t.insertBefore(n[--i],u),e[s]=n[i]}else{if(!a){a=new Map;let h=o;for(;h<i;)a.set(n[h],h++)}const u=a.get(e[l]);if(u!=null)if(o<u&&u<i){let h=l,y=1,g;for(;++h<s&&h<i&&!((g=a.get(e[h]))==null||g!==u+y);)y++;if(y>u-o){const d=e[l];for(;o<u;)t.insertBefore(n[o++],d)}else t.replaceChild(n[o++],e[l++])}else l++;else e[l++].remove()}}}const U="_$DX_DELEGATE";function m(t,e,n,r){let s;const i=()=>{const o=document.createElement("template");return o.innerHTML=t,o.content.firstChild},l=()=>(s||(s=i())).cloneNode(!0);return l.cloneNode=l,l}function dt(t,e=window.document){const n=e[U]||(e[U]=new Set);for(let r=0,s=t.length;r<s;r++){const i=t[r];n.has(i)||(n.add(i),e.addEventListener(i,pt))}}function Y(t,e,n){n==null?t.removeAttribute(e):t.setAttribute(e,n)}function ht(t,e,n){if(!e)return n?Y(t,"style"):e;const r=t.style;if(typeof e=="string")return r.cssText=e;typeof n=="string"&&(r.cssText=n=void 0),n||(n={}),e||(e={});let s,i;for(i in n)e[i]==null&&r.removeProperty(i),delete n[i];for(i in e)s=e[i],s!==n[i]&&(r.setProperty(i,s),n[i]=s);return n}function S(t,e,n,r){if(n!==void 0&&!r&&(r=[]),typeof e!="function")return N(t,e,r,n);P(s=>N(t,e(),s,n),r)}function pt(t){let e=t.target;const n=`$$${t.type}`,r=t.target,s=t.currentTarget,i=c=>Object.defineProperty(t,"target",{configurable:!0,value:c}),l=()=>{const c=e[n];if(c&&!e.disabled){const a=e[`${n}Data`];if(a!==void 0?c.call(e,a,t):c.call(e,t),t.cancelBubble)return}return e.host&&typeof e.host!="string"&&!e.host._$host&&e.contains(t.target)&&i(e.host),!0},o=()=>{for(;l()&&(e=e._$host||e.parentNode||e.host););};if(Object.defineProperty(t,"currentTarget",{configurable:!0,get(){return e||document}}),t.composedPath){const c=t.composedPath();i(c[0]);for(let a=0;a<c.length-2&&(e=c[a],!!l());a++){if(e._$host){e=e._$host,o();break}if(e.parentNode===s)break}}else o();i(r)}function N(t,e,n,r,s){for(;typeof n=="function";)n=n();if(e===n)return n;const i=typeof e,l=r!==void 0;if(t=l&&n[0]&&n[0].parentNode||t,i==="string"||i==="number"){if(i==="number"&&(e=e.toString(),e===n))return n;if(l){let o=n[0];o&&o.nodeType===3?o.data!==e&&(o.data=e):o=document.createTextNode(e),n=C(t,n,r,o)}else n!==""&&typeof n=="string"?n=t.firstChild.data=e:n=t.textContent=e}else if(e==null||i==="boolean")n=C(t,n,r);else{if(i==="function")return P(()=>{let o=e();for(;typeof o=="function";)o=o();n=N(t,o,n,r)}),()=>n;if(Array.isArray(e)){const o=[],c=n&&Array.isArray(n);if(F(o,e,n,s))return P(()=>n=N(t,o,n,r,!0)),()=>n;if(o.length===0){if(n=C(t,n,r),l)return n}else c?n.length===0?V(t,o,r):ft(t,n,o):(n&&C(t),V(t,o));n=o}else if(e.nodeType){if(Array.isArray(n)){if(l)return n=C(t,n,r,e);C(t,n,null,e)}else n==null||n===""||!t.firstChild?t.appendChild(e):t.replaceChild(e,t.firstChild);n=e}}return n}function F(t,e,n,r){let s=!1;for(let i=0,l=e.length;i<l;i++){let o=e[i],c=n&&n[t.length],a;if(!(o==null||o===!0||o===!1))if((a=typeof o)=="object"&&o.nodeType)t.push(o);else if(Array.isArray(o))s=F(t,o,c)||s;else if(a==="function")if(r){for(;typeof o=="function";)o=o();s=F(t,Array.isArray(o)?o:[o],Array.isArray(c)?c:[c])||s}else t.push(o),s=!0;else{const u=String(o);c&&c.nodeType===3&&c.data===u?t.push(c):t.push(document.createTextNode(u))}}return s}function V(t,e,n=null){for(let r=0,s=e.length;r<s;r++)t.insertBefore(e[r],n)}function C(t,e,n,r){if(n===void 0)return t.textContent="";const s=r||document.createTextNode("");if(e.length){let i=!1;for(let l=e.length-1;l>=0;l--){const o=e[l];if(s!==o){const c=o.parentNode===t;!i&&!l?c?t.replaceChild(s,o):t.insertBefore(s,n):c&&o.remove()}else i=!0}}else t.insertBefore(s,n);return[s]}function gt(t){return Object.keys(t).reduce((n,r)=>{const s=t[r];return n[r]=Object.assign({},s),et(s.value)&&!Ct(s.value)&&!Array.isArray(s.value)&&(n[r].value=Object.assign({},s.value)),Array.isArray(s.value)&&(n[r].value=s.value.slice(0)),n},{})}function bt(t){return t?Object.keys(t).reduce((n,r)=>{const s=t[r];return n[r]=et(s)&&"value"in s?s:{value:s},n[r].attribute||(n[r].attribute=wt(r)),n[r].parse="parse"in n[r]?n[r].parse:typeof n[r].value!="string",n},{}):{}}function yt(t){return Object.keys(t).reduce((n,r)=>(n[r]=t[r].value,n),{})}function _t(t,e){const n=gt(e);return Object.keys(e).forEach(s=>{const i=n[s],l=t.getAttribute(i.attribute),o=t[s];l!=null&&(i.value=i.parse?tt(l):l),o!=null&&(i.value=Array.isArray(o)?o.slice(0):o),i.reflect&&D(t,i.attribute,i.value,!!i.parse),Object.defineProperty(t,s,{get(){return i.value},set(c){const a=i.value;i.value=c,i.reflect&&D(this,i.attribute,i.value,!!i.parse);for(let u=0,h=this.__propertyChangedCallbacks.length;u<h;u++)this.__propertyChangedCallbacks[u](s,c,a)},enumerable:!0,configurable:!0})}),n}function tt(t){if(t)try{return JSON.parse(t)}catch{return t}}function D(t,e,n,r){if(n==null||n===!1)return t.removeAttribute(e);let s=r?JSON.stringify(n):n;t.__updating[e]=!0,s==="true"&&(s=""),t.setAttribute(e,s),Promise.resolve().then(()=>delete t.__updating[e])}function wt(t){return t.replace(/\.?([A-Z]+)/g,(e,n)=>"-"+n.toLowerCase()).replace("_","-").replace(/^-/,"")}function et(t){return t!=null&&(typeof t=="object"||typeof t=="function")}function Ct(t){return Object.prototype.toString.call(t)==="[object Function]"}function vt(t){return typeof t=="function"&&t.toString().indexOf("class")===0}let I;function St(t,e){const n=Object.keys(e);return class extends t{static get observedAttributes(){return n.map(s=>e[s].attribute)}constructor(){super(),this.__initialized=!1,this.__released=!1,this.__releaseCallbacks=[],this.__propertyChangedCallbacks=[],this.__updating={},this.props={}}connectedCallback(){if(this.__initialized)return;this.__releaseCallbacks=[],this.__propertyChangedCallbacks=[],this.__updating={},this.props=_t(this,e);const s=yt(this.props),i=this.Component,l=I;try{I=this,this.__initialized=!0,vt(i)?new i(s,{element:this}):i(s,{element:this})}finally{I=l}}async disconnectedCallback(){if(await Promise.resolve(),this.isConnected)return;this.__propertyChangedCallbacks.length=0;let s=null;for(;s=this.__releaseCallbacks.pop();)s(this);delete this.__initialized,this.__released=!0}attributeChangedCallback(s,i,l){if(this.__initialized&&!this.__updating[s]&&(s=this.lookupProp(s),s in e)){if(l==null&&!this[s])return;this[s]=e[s].parse?tt(l):l}}lookupProp(s){if(e)return n.find(i=>s===i||s===e[i].attribute)}get renderRoot(){return this.shadowRoot||this.attachShadow({mode:"open"})}addReleaseCallback(s){this.__releaseCallbacks.push(s)}addPropertyChangedCallback(s){this.__propertyChangedCallbacks.push(s)}}}function Et(t,e={},n={}){const{BaseElement:r=HTMLElement,extension:s,customElements:i=window.customElements}=n;return l=>{let o=i.get(t);return o?(o.prototype.Component=l,o):(o=St(r,bt(e)),o.prototype.Component=l,o.prototype.registeredTag=t,i.define(t,o,s),o)}}function At(t){const e=Object.keys(t),n={};for(let r=0;r<e.length;r++){const[s,i]=z(t[e[r]]);Object.defineProperty(n,e[r],{get:s,set(l){i(()=>l)}})}return n}function mt(t){if(t.assignedSlot&&t.assignedSlot._$owner)return t.assignedSlot._$owner;let e=t.parentNode;for(;e&&!e._$owner&&!(e.assignedSlot&&e.assignedSlot._$owner);)e=e.parentNode;return e&&e.assignedSlot?e.assignedSlot._$owner:t._$owner}function xt(t){return(e,n)=>{const{element:r}=n;return ot(s=>{const i=At(e);r.addPropertyChangedCallback((o,c)=>i[o]=c),r.addReleaseCallback(()=>{r.renderRoot.textContent="",s()});const l=t(i,n);return S(r.renderRoot,l)},mt(r))}}function $t(t,e,n){return arguments.length===2&&(n=e,e={}),Et(t,e)(xt(n))}const kt=`
2
- :host([theme="dark"]) {
3
- color-scheme: only dark;
4
- }
5
- :host([theme="light"]) {
6
- color-scheme: only light;
7
- }
8
-
9
- :host .dictate-button__container {
10
- margin: 5px;
11
- }
12
-
13
- :host .dictate-button__button {
14
- cursor: pointer;
15
- padding: 2px;
16
- display: inline-flex;
17
- align-items: center;
18
- justify-content: center;
19
- opacity: 0.8;
20
- transition: opacity 0.2s ease-in-out;
21
- }
22
-
23
- :host .dictate-button__button .dictate-button__icon {
24
- width: 100%;
25
- height: 100%;
26
- }
27
-
28
- :host .dictate-button__button .dictate-button__icon.dictate-button__icon--processing {
29
- animation: dictate-button-rotate 1s linear infinite;
30
- }
31
-
32
- @keyframes dictate-button-rotate {
33
- 0% { transform: rotate(0deg); }
34
- 100% { transform: rotate(360deg); }
35
- }
36
- `;var Tt=m("<div part=container class=dictate-button__container><style></style><button part=button class=dictate-button__button>"),Ot=m('<svg part=icon class="dictate-button__icon dictate-button__icon--idle"fill=none viewBox="0 0 24 24"stroke-width=1.5 stroke=currentColor><path stroke-linecap=round stroke-linejoin=round d="M12 18.75a6 6 0 0 0 6-6v-1.5m-6 7.5a6 6 0 0 1-6-6v-1.5m6 7.5v3.75m-3.75 0h7.5M12 15.75a3 3 0 0 1-3-3V4.5a3 3 0 1 1 6 0v8.25a3 3 0 0 1-3 3Z">'),Pt=m('<svg part=icon class="dictate-button__icon dictate-button__icon--recording"viewBox="0 0 24 24"fill=currentColor><path fill-rule=evenodd d="M4.5 7.5a3 3 0 0 1 3-3h9a3 3 0 0 1 3 3v9a3 3 0 0 1-3 3h-9a3 3 0 0 1-3-3v-9Z"clip-rule=evenodd>'),jt=m('<svg part=icon class="dictate-button__icon dictate-button__icon--processing"fill=none viewBox="0 0 24 24"stroke-width=1.5 stroke=currentColor><path stroke-linecap=round stroke-linejoin=round d="M16.023 9.348h4.992v-.001M2.985 19.644v-4.992m0 0h4.992m-4.993 0 3.181 3.183a8.25 8.25 0 0 0 13.803-3.7M4.031 9.865a8.25 8.25 0 0 1 13.803-3.7l3.181 3.182m0-4.991v4.99">'),Nt=m('<svg part=icon class="dictate-button__icon dictate-button__icon--error"fill=none viewBox="0 0 24 24"stroke-width=1.5 stroke=currentColor><path stroke-linecap=round stroke-linejoin=round d="M6 18 18 6M6 6l12 12">');console.debug("dictate-button version:","0.2.0");const Bt="https://api.dictate-button.io/transcribe",k="dictate-button.io";$t("dictate-button",{size:24,apiEndpoint:Bt},(t,{element:e})=>{const{size:n,apiEndpoint:r}=t;console.debug("api",r);const[s,i]=z("idle");let l=null,o=[];const c=()=>{l&&l.state!=="inactive"&&l.stop(),o=[]};e.addEventListener("disconnected",c);const a=async()=>{if(c(),s()==="idle")try{const h=await navigator.mediaDevices.getUserMedia({audio:!0});l=new MediaRecorder(h,{mimeType:"audio/webm"}),o=[],l.ondataavailable=y=>{o.push(y.data)},l.onstop=async()=>{i("processing"),v(e,"transcribing:started","Started transcribing");const y=new Blob(o,{type:"audio/webm"});try{const g=await fetch(r,{method:"POST",body:y});if(!g.ok)throw new Error("Failed to transcribe audio");const d=await g.json();if(s()!=="processing")return;v(e,"transcribing:finished",d.text),i("idle")}catch(g){console.error("Failed to transcribe audio:",g),v(e,"transcribing:failed","Failed to transcribe audio"),u()}},l.start(),v(e,"recording:started","Started recording"),i("recording")}catch(h){console.error("Failed to start recording:",h),v(e,"recording:failed","Failed to start recording"),u()}else v(e,"recording:stopped","Stopped recording"),i("idle")},u=()=>{i("error"),setTimeout(()=>i("idle"),2e3)};return(()=>{var h=Tt(),y=h.firstChild,g=y.nextSibling;return S(y,kt),g.$$click=a,S(g,(()=>{var d=$(()=>s()==="idle");return()=>d()&&x(Rt,{})})(),null),S(g,(()=>{var d=$(()=>s()==="recording");return()=>d()&&x(It,{})})(),null),S(g,(()=>{var d=$(()=>s()==="processing");return()=>d()&&x(Ft,{})})(),null),S(g,(()=>{var d=$(()=>s()==="error");return()=>d()&&x(Lt,{})})(),null),P(d=>{var nt=`width:${n}px;height:${n}px"`,K=Mt(s());return d.e=ht(g,nt,d.e),K!==d.t&&Y(g,"title",d.t=K),d},{e:void 0,t:void 0}),h})()});const Mt=t=>{switch(t){case"idle":return`Start dictation (${k})`;case"recording":return`Stop dictation (${k})`;case"processing":return`Stop processing (${k})`;case"error":return`Click to reset (${k})`}},v=(t,e,n)=>{t.dispatchEvent(new CustomEvent(e,{detail:n,bubbles:!0,composed:!0}))},Rt=()=>Ot(),It=()=>Pt(),Ft=()=>jt(),Lt=()=>Nt();dt(["click"]);