@wcstack/midi 4.11.2 → 4.13.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.
package/dist/auto.min.js CHANGED
@@ -1,2 +1,2 @@
1
- const e={tagNames:{midi:"wcs-midi"}};var t="@wcstack/midi",s="4.11.2";const n="capability-missing",i="not-allowed",r="access-error",o="send-failed";const a={type:"other",channel:null,note:null,velocity:null,control:null,value:null};const c="unsupported",u=e=>e.detail,l=e=>t=>u(t)?.[e]??null;class h extends EventTarget{static wcBindable={protocol:"wc-bindable",version:1,properties:[{name:"message",event:"wcs-midi:message",semantics:"event"},{name:"type",event:"wcs-midi:message",semantics:"event",getter:l("type")},{name:"channel",event:"wcs-midi:message",semantics:"event",getter:l("channel")},{name:"note",event:"wcs-midi:message",semantics:"event",getter:l("note")},{name:"velocity",event:"wcs-midi:message",semantics:"event",getter:l("velocity")},{name:"control",event:"wcs-midi:message",semantics:"event",getter:l("control")},{name:"value",event:"wcs-midi:message",semantics:"event",getter:l("value")},{name:"devices",event:"wcs-midi:devices",semantics:"state"},{name:"connected",event:"wcs-midi:statechange",semantics:"state"},{name:"permission",event:"wcs-midi:permission",semantics:"state"},{name:"granted",event:"wcs-midi:permission",semantics:"state",getter:e=>"granted"===u(e)},{name:"denied",event:"wcs-midi:permission",semantics:"state",getter:e=>"denied"===u(e)},{name:"unsupported",event:"wcs-midi:permission",semantics:"state",getter:e=>u(e)===c},{name:"error",event:"wcs-midi:error",semantics:"state"},{name:"errorInfo",event:"wcs-midi:error-info-changed",semantics:"state"}],commands:[{name:"request",async:!0},{name:"close"},{name:"send"}]};_target;_options={};_access=null;_hookedInputs=new Set;_message=null;_devices=[];_connected=!1;_permission="prompt";_error=null;_errorInfo=null;_permissionStatus=null;_gen=0;_ready=Promise.resolve();constructor(e,t){super(),this._target=t??this,e&&(this._options={...e})}get message(){return this._message}get type(){return this._message?.type??null}get channel(){return this._message?.channel??null}get note(){return this._message?.note??null}get velocity(){return this._message?.velocity??null}get control(){return this._message?.control??null}get value(){return this._message?.value??null}get devices(){return this._devices}get connected(){return this._connected}get permission(){return this._permission}get granted(){return"granted"===this._permission}get denied(){return"denied"===this._permission}get unsupported(){return this._permission===c}get error(){return this._error}get errorInfo(){return this._errorInfo}get ready(){return this._ready}observe(e){const t=null===this._access;return this.setOptions(e),e.auto&&t&&(this._ready=this.request()),this._ready}setOptions(e){this._options={...this._options,...e},this._access&&this._hookInputs(this._access)}request(){const e=this._resolveApi();if(!e)return this._setPermission(c),this._setError(c,c),this._ready=Promise.resolve(),this._ready;const t=++this._gen;return this._probePermission(),this._ready=e({sysex:!0===this._options.sysex}).then(e=>{t===this._gen&&(this._access=e,e.onstatechange=this._onStateChange,this._setError(null),this._setPermission("granted"),this._hookInputs(e),this._publishDevices(e),this._setConnected(!0))},e=>{t===this._gen&&(this._setPermission("denied"),this._setError(this._messageOf(e),e?.name))}),this._ready}close(){this._gen++,this._unhookInputs(),this._access&&(this._access.onstatechange=null,this._access=null),this._setConnected(!1)}send(e,t){const s=this._resolveOutput();if(s)try{s.send(e,t)}catch(e){this._setError(this._messageOf(e),"send")}}dispose(){this.close(),this._permissionStatus&&(this._permissionStatus.removeEventListener("change",this._onPermissionChange),this._permissionStatus=null)}_resolveApi(){const e=globalThis.navigator;return e&&"function"==typeof e.requestMIDIAccess?t=>e.requestMIDIAccess(t):null}_messageOf(e){return"string"==typeof e?.message&&""!==e.message?e.message:"MIDI error"}_probePermission(){if(this._permissionStatus)return;const e=globalThis.navigator.permissions;if(!e||"function"!=typeof e.query)return;const t=this._gen;e.query({name:"midi",sysex:!0===this._options.sysex}).then(e=>{t===this._gen&&(this._permissionStatus=e,this._setPermission(e.state),e.addEventListener("change",this._onPermissionChange))},()=>{})}_onPermissionChange=e=>{this._setPermission(e.target.state)};_matches(e,t){if(e.id===t)return!0;return(e.name??"").toLowerCase().startsWith(t.toLowerCase())}_selectedInputs(e){const t=[...e.inputs.values()],s=this._options.input;return null==s||""===s?t:t.filter(e=>this._matches(e,s))}_resolveOutput(){if(!this._access)return null;const e=[...this._access.outputs.values()],t=this._options.output;return null==t||""===t?e[0]??null:e.find(e=>this._matches(e,t))??null}_hookInputs(e){const t=new Set(this._selectedInputs(e));for(const e of this._hookedInputs)t.has(e)||(e.onmidimessage=null,this._hookedInputs.delete(e));for(const e of t)this._hookedInputs.has(e)||(e.onmidimessage=this._onMidiMessage,this._hookedInputs.add(e))}_unhookInputs(){for(const e of this._hookedInputs)e.onmidimessage=null;this._hookedInputs.clear()}_onStateChange=()=>{const e=this._access;this._hookInputs(e),this._publishDevices(e)};_onMidiMessage=e=>{const t=e.data;if(!t)return;const s=function(e){const t=e[0];if("number"!=typeof t)return a;const s="number"==typeof e[1]?e[1]:0,n="number"==typeof e[2]?e[2]:0;if(t>=240)return{...a,type:240===t?"sysex":"other"};if(t<128)return a;const i=1+(15&t);switch(240&t){case 128:return{type:"noteoff",channel:i,note:s,velocity:n/127,control:null,value:null};case 144:return n>0?{type:"noteon",channel:i,note:s,velocity:n/127,control:null,value:null}:{type:"noteoff",channel:i,note:s,velocity:0,control:null,value:null};case 160:return{type:"polyaftertouch",channel:i,note:s,velocity:null,control:null,value:n};case 176:return{type:"controlchange",channel:i,note:null,velocity:null,control:s,value:n};case 192:return{type:"programchange",channel:i,note:null,velocity:null,control:null,value:s};case 208:return{type:"aftertouch",channel:i,note:null,velocity:null,control:null,value:s};default:return{type:"pitchbend",channel:i,note:null,velocity:null,control:null,value:((n<<7|s)-8192)/8192}}}(t),n=this._options.channel;if(null!=n&&null!==s.channel&&s.channel!==n)return;const i=e.target;this._publishMessage({...s,data:new Uint8Array(t),port:i?.id??"",portName:i?.name??"",timestamp:e.timeStamp??0})};_publishMessage(e){this._message=e,this._target.dispatchEvent(new CustomEvent("wcs-midi:message",{detail:e,bubbles:!0}))}_publishDevices(e){const t=this._snapshotDevices(e);this._sameDevices(t)||(this._devices=t,this._target.dispatchEvent(new CustomEvent("wcs-midi:devices",{detail:t,bubbles:!0})))}_snapshotDevices(e){const t=(e,t)=>[...e.values()].map(e=>({id:e.id,name:e.name??"",manufacturer:e.manufacturer??"",direction:t,state:"connected"===e.state?"connected":"disconnected"}));return[...t(e.inputs,"input"),...t(e.outputs,"output")]}_sameDevices(e){return e.length===this._devices.length&&e.every((e,t)=>{const s=this._devices[t];return s.id===e.id&&s.state===e.state&&s.direction===e.direction&&s.name===e.name})}_setConnected(e){this._connected!==e&&(this._connected=e,this._target.dispatchEvent(new CustomEvent("wcs-midi:statechange",{detail:e,bubbles:!0})))}_setPermission(e){this._permission!==e&&(this._permission=e,this._target.dispatchEvent(new CustomEvent("wcs-midi:permission",{detail:e,bubbles:!0})))}_setError(e,t){this._error!==e&&(this._error=e,this._target.dispatchEvent(new CustomEvent("wcs-midi:error",{detail:e,bubbles:!0}))),this._commitErrorInfo(null===e?null:function(e,t){return"unsupported"===e?{code:n,phase:"probe",recoverable:!1,message:t}:"send"===e?{code:o,phase:"execute",recoverable:!0,message:t}:"SecurityError"===e||"NotAllowedError"===e?{code:i,phase:"start",recoverable:!1,message:t}:{code:r,phase:"start",recoverable:!0,message:t}}(t,e))}_commitErrorInfo(e){null===this._errorInfo&&null===e||(this._errorInfo=e,this._target.dispatchEvent(new CustomEvent("wcs-midi:error-info-changed",{detail:e,bubbles:!0})))}}function d(e,t){let s=Object.getPrototypeOf(e);for(;null!==s;){const e=Object.getOwnPropertyDescriptor(s,t);if(void 0!==e)return"function"==typeof e.get||"function"==typeof e.set;s=Object.getPrototypeOf(s)}return!1}const m=new WeakSet;function _(e,t,s){if(m.has(e))return;m.add(e);const n=e.localName??"element";console.warn(`[wcs/input-as-attribute] <${n}> has the attribute ${t}="${s}": an object was written as an attribute, so the element did not receive it. A framework does that when the property is set before the element's definition loads (React 19), or when told to (Vue's .attr). Load the definition before rendering, or assign the property through a ref (Vue: .prop). (Said once per element.)`,e)}const p=new WeakMap;function g(e,t){let s=p.get(e);return void 0===s&&(s=new Map,p.set(e,s)),s.has(t)||s.set(t,e.getAttribute(t)),s.get(t)}function v(e,t,s){null===s?e.removeAttribute(t):e.setAttribute(t,s)}function f(e,t,s){const n=g(e,t);v(e,t,void 0===s?n:null===s?null:String(s))}function b(e,t,s){const n=g(e,t);v(e,t,void 0===s?n:s?"":null)}class y extends HTMLElement{static hasConnectedCallbackPromise=!0;static observedAttributes=["input","output","channel"];static wcBindable={...h.wcBindable,inputs:[{name:"input",attribute:"input"},{name:"output",attribute:"output"},{name:"channel",attribute:"channel"},{name:"sysex",attribute:"sysex"},{name:"auto",attribute:"auto"}]};_core;_connectedCallbackPromise=Promise.resolve();_connectResolve=null;_requestPending=!1;_autoCancelled=!1;_internals=null;constructor(){super(),this._core=new h(null,this),this._internals=this._initInternals(),this._wireStates({"wcs-midi:permission":e=>({granted:"granted"===e,denied:"denied"===e,unsupported:"unsupported"===e}),"wcs-midi:statechange":e=>({connected:!0===e}),"wcs-midi:error":e=>({error:null!==e})})}get debugStates(){return this._internals?[...this._internals.states]:[]}_initInternals(){try{if("function"!=typeof this.attachInternals)return null;const e=this.attachInternals();return e.states.add("wcs-probe"),e.states.delete("wcs-probe"),e}catch{return null}}_wireStates(e){if(null===this._internals)return;const t=this._internals.states;for(const[s,n]of Object.entries(e))this.addEventListener(s,e=>{const s=this.hasAttribute("debug-states");for(const[i,r]of Object.entries(n(e.detail))){try{r?t.add(i):t.delete(i)}catch{}s&&this.toggleAttribute(`data-wcs-state-${i}`,r)}})}get input(){return this.getAttribute("input")??""}set input(e){f(this,"input",e)}get output(){return this.getAttribute("output")??""}set output(e){f(this,"output",e)}get channel(){const e=this.getAttribute("channel");if(null===e)return null;const t=Number(e);return Number.isFinite(t)?t:null}set channel(e){f(this,"channel",e)}get sysex(){return this.hasAttribute("sysex")}set sysex(e){b(this,"sysex",e)}get auto(){return this.hasAttribute("auto")}set auto(e){b(this,"auto",e)}get message(){return this._core.message}get type(){return this._core.type}get note(){return this._core.note}get velocity(){return this._core.velocity}get control(){return this._core.control}get value(){return this._core.value}get devices(){return this._core.devices}get connected(){return this._core.connected}get permission(){return this._core.permission}get granted(){return this._core.granted}get denied(){return this._core.denied}get unsupported(){return this._core.unsupported}get error(){return this._core.error}get errorInfo(){return this._core.errorInfo}get core(){return this._core}get connectedCallbackPromise(){return this._connectedCallbackPromise}request(){return this._core.setOptions(this._options()),this._core.request()}close(){null!==this._connectResolve&&(this._autoCancelled=!0),this._core.close()}send(e,t){this._core.send(e,t)}_options(){return{input:this.input,output:this.output,channel:this.channel,sysex:this.sysex,auto:this.auto}}_scheduleRequest(){this._requestPending||(this._requestPending=!0,queueMicrotask(()=>{this._requestPending=!1;const e=this._connectResolve;if(this._connectResolve=null,null===e)return;const t=this._options();this._autoCancelled&&(t.auto=!1),this._autoCancelled=!1,e(this._core.observe(t))}))}connectedCallback(){!function(e){const t=e.constructor?.wcBindable,s=t?.inputs;if(void 0===s)return;const n=e.getAttribute;for(const t of s){const s=t.name,i="function"==typeof n?n.call(e,s.toLowerCase()):null;if(null!==i&&i.startsWith("[object ")&&_(e,s,i),!Object.prototype.hasOwnProperty.call(e,s))continue;if(!d(e,s))continue;const r=e,o=r[s];delete r[s],r[s]=o}}(this),this.style.display="none",this._connectedCallbackPromise=new Promise(e=>{this._connectResolve=e}),this._scheduleRequest()}disconnectedCallback(){this._connectResolve?.(),this._connectResolve=null,this._autoCancelled=!1,this._core.dispose()}attributeChangedCallback(e,t,s){t!==s&&this.isConnected&&this._core.setOptions(this._options())}}const w=Symbol.for("wcstack.package"),I=new WeakSet;function C(e,t){Object.defineProperty(e,w,{value:t,configurable:!0})}function k(e,t,s,n,i){if(void 0!==n&&(s===n||s.prototype instanceof n))return;const r=s[w];if(r===i||I.has(e))return;I.add(e);const o=i.slice(0,i.lastIndexOf("@"));console.warn(`[${o}] [wcs/package-twice] <${t}> is already defined by ${r??`another copy of ${o} that does not name its version`}; this copy, ${i}, does nothing. Load each package once.`)}function P(n=customElements){!function(e,t,s){for(const[n,i]of s){const s=e.get(n);void 0===s?(C(i,t),e.define(n,i)):k(e,n,s,i,t)}}(n,`${t}@${s}`,[[e.tagNames.midi,y]])}var E;P(E);
1
+ const e={tagNames:{midi:"wcs-midi"}};var t="@wcstack/midi",s="4.13.0";const n="capability-missing",i="not-allowed",r="access-error",o="send-failed";const a={type:"other",channel:null,note:null,velocity:null,control:null,value:null};const c="unsupported",u=e=>e.detail,l=e=>t=>u(t)?.[e]??null;class h extends EventTarget{static wcBindable={protocol:"wc-bindable",version:1,properties:[{name:"message",event:"wcs-midi:message",semantics:"event"},{name:"type",event:"wcs-midi:message",semantics:"event",getter:l("type")},{name:"channel",event:"wcs-midi:message",semantics:"event",getter:l("channel")},{name:"note",event:"wcs-midi:message",semantics:"event",getter:l("note")},{name:"velocity",event:"wcs-midi:message",semantics:"event",getter:l("velocity")},{name:"control",event:"wcs-midi:message",semantics:"event",getter:l("control")},{name:"value",event:"wcs-midi:message",semantics:"event",getter:l("value")},{name:"devices",event:"wcs-midi:devices",semantics:"state"},{name:"connected",event:"wcs-midi:statechange",semantics:"state"},{name:"permission",event:"wcs-midi:permission",semantics:"state"},{name:"granted",event:"wcs-midi:permission",semantics:"state",getter:e=>"granted"===u(e)},{name:"denied",event:"wcs-midi:permission",semantics:"state",getter:e=>"denied"===u(e)},{name:"unsupported",event:"wcs-midi:permission",semantics:"state",getter:e=>u(e)===c},{name:"error",event:"wcs-midi:error",semantics:"state"},{name:"errorInfo",event:"wcs-midi:error-info-changed",semantics:"state"}],commands:[{name:"request",async:!0},{name:"close"},{name:"send"}]};_target;_options={};_access=null;_hookedInputs=new Set;_message=null;_devices=[];_connected=!1;_permission="prompt";_error=null;_errorInfo=null;_permissionStatus=null;_gen=0;_ready=Promise.resolve();constructor(e,t){super(),this._target=t??this,e&&(this._options={...e})}get message(){return this._message}get type(){return this._message?.type??null}get channel(){return this._message?.channel??null}get note(){return this._message?.note??null}get velocity(){return this._message?.velocity??null}get control(){return this._message?.control??null}get value(){return this._message?.value??null}get devices(){return this._devices}get connected(){return this._connected}get permission(){return this._permission}get granted(){return"granted"===this._permission}get denied(){return"denied"===this._permission}get unsupported(){return this._permission===c}get error(){return this._error}get errorInfo(){return this._errorInfo}get ready(){return this._ready}observe(e){const t=null===this._access;return this.setOptions(e),e.auto&&t&&(this._ready=this.request()),this._ready}setOptions(e){this._options={...this._options,...e},this._access&&this._hookInputs(this._access)}request(){const e=this._resolveApi();if(!e)return this._setPermission(c),this._setError(c,c),this._ready=Promise.resolve(),this._ready;const t=++this._gen;return this._probePermission(),this._ready=e({sysex:!0===this._options.sysex}).then(e=>{t===this._gen&&(this._access=e,e.onstatechange=this._onStateChange,this._setError(null),this._setPermission("granted"),this._hookInputs(e),this._publishDevices(e),this._setConnected(!0))},e=>{t===this._gen&&(this._setPermission("denied"),this._setError(this._messageOf(e),e?.name))}),this._ready}close(){this._gen++,this._unhookInputs(),this._access&&(this._access.onstatechange=null,this._access=null),this._setConnected(!1)}send(e,t){const s=this._resolveOutput();if(s)try{s.send(e,t)}catch(e){this._setError(this._messageOf(e),"send")}}dispose(){this.close(),this._permissionStatus&&(this._permissionStatus.removeEventListener("change",this._onPermissionChange),this._permissionStatus=null)}_resolveApi(){const e=globalThis.navigator;return e&&"function"==typeof e.requestMIDIAccess?t=>e.requestMIDIAccess(t):null}_messageOf(e){return"string"==typeof e?.message&&""!==e.message?e.message:"MIDI error"}_probePermission(){if(this._permissionStatus)return;const e=globalThis.navigator.permissions;if(!e||"function"!=typeof e.query)return;const t=this._gen;e.query({name:"midi",sysex:!0===this._options.sysex}).then(e=>{t===this._gen&&(this._permissionStatus=e,this._setPermission(e.state),e.addEventListener("change",this._onPermissionChange))},()=>{})}_onPermissionChange=e=>{this._setPermission(e.target.state)};_matches(e,t){if(e.id===t)return!0;return(e.name??"").toLowerCase().startsWith(t.toLowerCase())}_selectedInputs(e){const t=[...e.inputs.values()],s=this._options.input;return null==s||""===s?t:t.filter(e=>this._matches(e,s))}_resolveOutput(){if(!this._access)return null;const e=[...this._access.outputs.values()],t=this._options.output;return null==t||""===t?e[0]??null:e.find(e=>this._matches(e,t))??null}_hookInputs(e){const t=new Set(this._selectedInputs(e));for(const e of this._hookedInputs)t.has(e)||(e.onmidimessage=null,this._hookedInputs.delete(e));for(const e of t)this._hookedInputs.has(e)||(e.onmidimessage=this._onMidiMessage,this._hookedInputs.add(e))}_unhookInputs(){for(const e of this._hookedInputs)e.onmidimessage=null;this._hookedInputs.clear()}_onStateChange=()=>{const e=this._access;this._hookInputs(e),this._publishDevices(e)};_onMidiMessage=e=>{const t=e.data;if(!t)return;const s=function(e){const t=e[0];if("number"!=typeof t)return a;const s="number"==typeof e[1]?e[1]:0,n="number"==typeof e[2]?e[2]:0;if(t>=240)return{...a,type:240===t?"sysex":"other"};if(t<128)return a;const i=1+(15&t);switch(240&t){case 128:return{type:"noteoff",channel:i,note:s,velocity:n/127,control:null,value:null};case 144:return n>0?{type:"noteon",channel:i,note:s,velocity:n/127,control:null,value:null}:{type:"noteoff",channel:i,note:s,velocity:0,control:null,value:null};case 160:return{type:"polyaftertouch",channel:i,note:s,velocity:null,control:null,value:n};case 176:return{type:"controlchange",channel:i,note:null,velocity:null,control:s,value:n};case 192:return{type:"programchange",channel:i,note:null,velocity:null,control:null,value:s};case 208:return{type:"aftertouch",channel:i,note:null,velocity:null,control:null,value:s};default:return{type:"pitchbend",channel:i,note:null,velocity:null,control:null,value:((n<<7|s)-8192)/8192}}}(t),n=this._options.channel;if(null!=n&&null!==s.channel&&s.channel!==n)return;const i=e.target;this._publishMessage({...s,data:new Uint8Array(t),port:i?.id??"",portName:i?.name??"",timestamp:e.timeStamp??0})};_publishMessage(e){this._message=e,this._target.dispatchEvent(new CustomEvent("wcs-midi:message",{detail:e,bubbles:!0}))}_publishDevices(e){const t=this._snapshotDevices(e);this._sameDevices(t)||(this._devices=t,this._target.dispatchEvent(new CustomEvent("wcs-midi:devices",{detail:t,bubbles:!0})))}_snapshotDevices(e){const t=(e,t)=>[...e.values()].map(e=>({id:e.id,name:e.name??"",manufacturer:e.manufacturer??"",direction:t,state:"connected"===e.state?"connected":"disconnected"}));return[...t(e.inputs,"input"),...t(e.outputs,"output")]}_sameDevices(e){return e.length===this._devices.length&&e.every((e,t)=>{const s=this._devices[t];return s.id===e.id&&s.state===e.state&&s.direction===e.direction&&s.name===e.name})}_setConnected(e){this._connected!==e&&(this._connected=e,this._target.dispatchEvent(new CustomEvent("wcs-midi:statechange",{detail:e,bubbles:!0})))}_setPermission(e){this._permission!==e&&(this._permission=e,this._target.dispatchEvent(new CustomEvent("wcs-midi:permission",{detail:e,bubbles:!0})))}_setError(e,t){this._error!==e&&(this._error=e,this._target.dispatchEvent(new CustomEvent("wcs-midi:error",{detail:e,bubbles:!0}))),this._commitErrorInfo(null===e?null:function(e,t){return"unsupported"===e?{code:n,phase:"probe",recoverable:!1,message:t}:"send"===e?{code:o,phase:"execute",recoverable:!0,message:t}:"SecurityError"===e||"NotAllowedError"===e?{code:i,phase:"start",recoverable:!1,message:t}:{code:r,phase:"start",recoverable:!0,message:t}}(t,e))}_commitErrorInfo(e){null===this._errorInfo&&null===e||(this._errorInfo=e,this._target.dispatchEvent(new CustomEvent("wcs-midi:error-info-changed",{detail:e,bubbles:!0})))}}function d(e,t){let s=Object.getPrototypeOf(e);for(;null!==s;){const e=Object.getOwnPropertyDescriptor(s,t);if(void 0!==e)return"function"==typeof e.get||"function"==typeof e.set;s=Object.getPrototypeOf(s)}return!1}const m=new WeakSet;function _(e,t,s){if(m.has(e))return;m.add(e);const n=e.localName??"element";console.warn(`[wcs/input-as-attribute] <${n}> has the attribute ${t}="${s}": an object was written as an attribute, so the element did not receive it. A framework does that when the property is set before the element's definition loads (React 19), or when told to (Vue's .attr). Load the definition before rendering, or assign the property through a ref (Vue: .prop). (Said once per element.)`,e)}const p=new WeakMap;function g(e,t){let s=p.get(e);return void 0===s&&(s=new Map,p.set(e,s)),s.has(t)||s.set(t,e.getAttribute(t)),s.get(t)}function v(e,t,s){null===s?e.removeAttribute(t):e.setAttribute(t,s)}function f(e,t,s){const n=g(e,t);v(e,t,void 0===s?n:null===s?null:String(s))}function b(e,t,s){const n=g(e,t);v(e,t,void 0===s?n:s?"":null)}class y extends HTMLElement{static hasConnectedCallbackPromise=!0;static observedAttributes=["input","output","channel"];static wcBindable={...h.wcBindable,inputs:[{name:"input",attribute:"input"},{name:"output",attribute:"output"},{name:"channel",attribute:"channel"},{name:"sysex",attribute:"sysex"},{name:"auto",attribute:"auto"}]};_core;_connectedCallbackPromise=Promise.resolve();_connectResolve=null;_requestPending=!1;_autoCancelled=!1;_internals=null;constructor(){super(),this._core=new h(null,this),this._internals=this._initInternals(),this._wireStates({"wcs-midi:permission":e=>({granted:"granted"===e,denied:"denied"===e,unsupported:"unsupported"===e}),"wcs-midi:statechange":e=>({connected:!0===e}),"wcs-midi:error":e=>({error:null!==e})})}get debugStates(){return this._internals?[...this._internals.states]:[]}_initInternals(){try{if("function"!=typeof this.attachInternals)return null;const e=this.attachInternals();return e.states.add("wcs-probe"),e.states.delete("wcs-probe"),e}catch{return null}}_wireStates(e){if(null===this._internals)return;const t=this._internals.states;for(const[s,n]of Object.entries(e))this.addEventListener(s,e=>{const s=this.hasAttribute("debug-states");for(const[i,r]of Object.entries(n(e.detail))){try{r?t.add(i):t.delete(i)}catch{}s&&this.toggleAttribute(`data-wcs-state-${i}`,r)}})}get input(){return this.getAttribute("input")??""}set input(e){f(this,"input",e)}get output(){return this.getAttribute("output")??""}set output(e){f(this,"output",e)}get channel(){const e=this.getAttribute("channel");if(null===e)return null;const t=Number(e);return Number.isFinite(t)?t:null}set channel(e){f(this,"channel",e)}get sysex(){return this.hasAttribute("sysex")}set sysex(e){b(this,"sysex",e)}get auto(){return this.hasAttribute("auto")}set auto(e){b(this,"auto",e)}get message(){return this._core.message}get type(){return this._core.type}get note(){return this._core.note}get velocity(){return this._core.velocity}get control(){return this._core.control}get value(){return this._core.value}get devices(){return this._core.devices}get connected(){return this._core.connected}get permission(){return this._core.permission}get granted(){return this._core.granted}get denied(){return this._core.denied}get unsupported(){return this._core.unsupported}get error(){return this._core.error}get errorInfo(){return this._core.errorInfo}get core(){return this._core}get connectedCallbackPromise(){return this._connectedCallbackPromise}request(){return this._core.setOptions(this._options()),this._core.request()}close(){null!==this._connectResolve&&(this._autoCancelled=!0),this._core.close()}send(e,t){this._core.send(e,t)}_options(){return{input:this.input,output:this.output,channel:this.channel,sysex:this.sysex,auto:this.auto}}_scheduleRequest(){this._requestPending||(this._requestPending=!0,queueMicrotask(()=>{this._requestPending=!1;const e=this._connectResolve;if(this._connectResolve=null,null===e)return;const t=this._options();this._autoCancelled&&(t.auto=!1),this._autoCancelled=!1,e(this._core.observe(t))}))}connectedCallback(){!function(e){const t=e.constructor?.wcBindable,s=t?.inputs;if(void 0===s)return;const n=e.getAttribute;for(const t of s){const s=t.name,i="function"==typeof n?n.call(e,s.toLowerCase()):null;if(null!==i&&i.startsWith("[object ")&&_(e,s,i),!Object.prototype.hasOwnProperty.call(e,s))continue;if(!d(e,s))continue;const r=e,o=r[s];delete r[s],r[s]=o}}(this),this.style.display="none",this._connectedCallbackPromise=new Promise(e=>{this._connectResolve=e}),this._scheduleRequest()}disconnectedCallback(){this._connectResolve?.(),this._connectResolve=null,this._autoCancelled=!1,this._core.dispose()}attributeChangedCallback(e,t,s){t!==s&&this.isConnected&&this._core.setOptions(this._options())}}const w=Symbol.for("wcstack.package"),I=new WeakSet;function C(e,t){Object.defineProperty(e,w,{value:t,configurable:!0})}function k(e,t,s,n,i){if(void 0!==n&&(s===n||s.prototype instanceof n))return;const r=s[w];if(r===i||I.has(e))return;I.add(e);const o=i.slice(0,i.lastIndexOf("@"));console.warn(`[${o}] [wcs/package-twice] <${t}> is already defined by ${r??`another copy of ${o} that does not name its version`}; this copy, ${i}, does nothing. Load each package once.`)}function P(n=customElements){!function(e,t,s){for(const[n,i]of s){const s=e.get(n);void 0===s?(C(i,t),e.define(n,i)):k(e,n,s,i,t)}}(n,`${t}@${s}`,[[e.tagNames.midi,y]])}var E;P(E);
2
2
  //# sourceMappingURL=auto.min.js.map
package/dist/index.esm.js CHANGED
@@ -58,7 +58,7 @@ function setConfig(partialConfig) {
58
58
  frozenConfig = null;
59
59
  }
60
60
 
61
- var pkg = {"name":"@wcstack/midi","version":"4.11.2"};
61
+ var pkg = {"name":"@wcstack/midi","version":"4.13.0"};
62
62
 
63
63
  /**
64
64
  * midiCapabilities.ts
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@wcstack/midi",
3
- "version": "4.11.2",
3
+ "version": "4.13.0",
4
4
  "description": "Declarative Web MIDI component for Web Components. Framework-agnostic MIDI input/output via wc-bindable-protocol.",
5
5
  "type": "module",
6
6
  "main": "./dist/index.esm.js",