@wcstack/ambient-light-sensor 4.11.0 → 4.11.2

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:{ambientLightSensor:"wcs-ambient-light-sensor"}};var t="@wcstack/ambient-light-sensor",r="4.11.0";const n="capability-missing",s="not-allowed",o="not-readable",i="sensor-error";const a=Object.freeze({illuminance:null});class c extends EventTarget{static wcBindable={protocol:"wc-bindable",version:1,properties:[{name:"illuminance",event:"wcs-ambient-light-sensor:reading",semantics:"state",getter:e=>e.detail.illuminance},{name:"error",event:"wcs-ambient-light-sensor:error",semantics:"state"},{name:"errorInfo",event:"wcs-ambient-light-sensor:error-info-changed",semantics:"state"}],commands:[{name:"start"},{name:"stop"}]};_target;_reading=a;_error=null;_errorInfo=null;_sensor=null;constructor(e){super(),this._target=e??this}get illuminance(){return this._reading.illuminance}get error(){return this._error}get errorInfo(){return this._errorInfo}get ready(){return Promise.resolve()}_setReading(e){this._reading=e,this._target.dispatchEvent(new CustomEvent("wcs-ambient-light-sensor:reading",{detail:e,bubbles:!0}))}_setError(e){var t,r;this._error?.error===e?.error&&this._error?.message===e?.message||(this._error=e,this._commitErrorInfo(null===e?null:(t=e.error,r=e.message,"unsupported"===t?{code:n,phase:"probe",recoverable:!1,message:r}:"SecurityError"===t||"NotAllowedError"===t?{code:s,phase:"start",recoverable:!1,message:r}:"NotReadableError"===t?{code:o,phase:"execute",recoverable:!1,message:r}:{code:i,phase:"execute",recoverable:!1,message:r})),this._target.dispatchEvent(new CustomEvent("wcs-ambient-light-sensor:error",{detail:e,bubbles:!0})))}_commitErrorInfo(e){this._errorInfo=e,this._target.dispatchEvent(new CustomEvent("wcs-ambient-light-sensor:error-info-changed",{detail:e,bubbles:!0}))}start(e){if(this._sensor)return;const t=this._createSensor(e);if(t){t.addEventListener("reading",this._onReading),t.addEventListener("error",this._onError),this._sensor=t;try{t.start()}catch(e){this._teardownSensor(),this._setError({error:e?.name??"error",message:e?.message??String(e)})}}}stop(){if(this._sensor){try{this._sensor.stop()}catch{}this._teardownSensor()}}observe(e){return this.start(e),this.ready}dispose(){this.stop()}_teardownSensor(){this._sensor.removeEventListener("reading",this._onReading),this._sensor.removeEventListener("error",this._onError),this._sensor=null}_createSensor(e){const t=globalThis.AmbientLightSensor;if("function"!=typeof t)return this._setError({error:"unsupported",message:"AmbientLightSensor is not supported"}),null;try{return new t(void 0!==e?{frequency:e}:void 0)}catch(e){return this._setError({error:e?.name??"error",message:e?.message??String(e)}),null}}_onReading=e=>{const t=e.target;this._setReading({illuminance:t.illuminance})};_onError=e=>{const t=e.error;this._setError({error:t?.name??"error",message:t?.message??"Sensor error"})}}function l(e,t){let r=Object.getPrototypeOf(e);for(;null!==r;){const e=Object.getOwnPropertyDescriptor(r,t);if(void 0!==e)return"function"==typeof e.get||"function"==typeof e.set;r=Object.getPrototypeOf(r)}return!1}const u=new WeakSet;function h(e,t,r){if(u.has(e))return;u.add(e);const n=e.localName??"element";console.warn(`[wcs/input-as-attribute] <${n}> has the attribute ${t}="${r}": 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 d=new WeakMap;function m(e,t,r){const n=function(e,t){let r=d.get(e);return void 0===r&&(r=new Map,d.set(e,r)),r.has(t)||r.set(t,e.getAttribute(t)),r.get(t)}(e,t);!function(e,t,r){null===r?e.removeAttribute(t):e.setAttribute(t,r)}(e,t,void 0===r?n:null===r?null:String(r))}class g extends HTMLElement{static hasConnectedCallbackPromise=!0;static wcBindable={...c.wcBindable,inputs:[{name:"frequency"}],commands:c.wcBindable.commands};_core;_connectedCallbackPromise=Promise.resolve();_internals=null;constructor(){super(),this._core=new c(this),this._internals=this._initInternals(),this._wireStates({"wcs-ambient-light-sensor: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[r,n]of Object.entries(e))this.addEventListener(r,e=>{const r=this.hasAttribute("debug-states");for(const[s,o]of Object.entries(n(e.detail))){try{o?t.add(s):t.delete(s)}catch{}r&&this.toggleAttribute(`data-wcs-state-${s}`,o)}})}get frequency(){const e=this.getAttribute("frequency");if(null===e||""===e.trim())return null;const t=Number(e);return Number.isFinite(t)&&t>0?t:null}set frequency(e){m(this,"frequency",e)}get illuminance(){return this._core.illuminance}get error(){return this._core.error}get errorInfo(){return this._core.errorInfo}get connectedCallbackPromise(){return this._connectedCallbackPromise}start(){this._core.start(this.frequency??void 0)}stop(){this._core.stop()}connectedCallback(){!function(e){const t=e.constructor?.wcBindable,r=t?.inputs;if(void 0===r)return;const n=e.getAttribute;for(const t of r){const r=t.name,s="function"==typeof n?n.call(e,r.toLowerCase()):null;if(null!==s&&s.startsWith("[object ")&&h(e,r,s),!Object.prototype.hasOwnProperty.call(e,r))continue;if(!l(e,r))continue;const o=e,i=o[r];delete o[r],o[r]=i}}(this),this.style.display="none",this._connectedCallbackPromise=this._core.ready}disconnectedCallback(){this._core.dispose()}}const f=Symbol.for("wcstack.package"),b=new WeakSet;function _(e,t){Object.defineProperty(e,f,{value:t,configurable:!0})}function p(e,t,r,n,s){if(void 0!==n&&(r===n||r.prototype instanceof n))return;const o=r[f];if(o===s||b.has(e))return;b.add(e);const i=s.slice(0,s.lastIndexOf("@"));console.warn(`[${i}] [wcs/package-twice] <${t}> is already defined by ${o??`another copy of ${i} that does not name its version`}; this copy, ${s}, does nothing. Load each package once.`)}function w(n=customElements){!function(e,t,r){for(const[n,s]of r){const r=e.get(n);void 0===r?(_(s,t),e.define(n,s)):p(e,n,r,s,t)}}(n,`${t}@${r}`,[[e.tagNames.ambientLightSensor,g]])}var v;w(v);
1
+ const e={tagNames:{ambientLightSensor:"wcs-ambient-light-sensor"}};var t="@wcstack/ambient-light-sensor",r="4.11.2";const n="capability-missing",s="not-allowed",o="not-readable",i="sensor-error";const a=Object.freeze({illuminance:null});class c extends EventTarget{static wcBindable={protocol:"wc-bindable",version:1,properties:[{name:"illuminance",event:"wcs-ambient-light-sensor:reading",semantics:"state",getter:e=>e.detail.illuminance},{name:"error",event:"wcs-ambient-light-sensor:error",semantics:"state"},{name:"errorInfo",event:"wcs-ambient-light-sensor:error-info-changed",semantics:"state"}],commands:[{name:"start"},{name:"stop"}]};_target;_reading=a;_error=null;_errorInfo=null;_sensor=null;constructor(e){super(),this._target=e??this}get illuminance(){return this._reading.illuminance}get error(){return this._error}get errorInfo(){return this._errorInfo}get ready(){return Promise.resolve()}_setReading(e){this._reading=e,this._target.dispatchEvent(new CustomEvent("wcs-ambient-light-sensor:reading",{detail:e,bubbles:!0}))}_setError(e){var t,r;this._error?.error===e?.error&&this._error?.message===e?.message||(this._error=e,this._commitErrorInfo(null===e?null:(t=e.error,r=e.message,"unsupported"===t?{code:n,phase:"probe",recoverable:!1,message:r}:"SecurityError"===t||"NotAllowedError"===t?{code:s,phase:"start",recoverable:!1,message:r}:"NotReadableError"===t?{code:o,phase:"execute",recoverable:!1,message:r}:{code:i,phase:"execute",recoverable:!1,message:r})),this._target.dispatchEvent(new CustomEvent("wcs-ambient-light-sensor:error",{detail:e,bubbles:!0})))}_commitErrorInfo(e){this._errorInfo=e,this._target.dispatchEvent(new CustomEvent("wcs-ambient-light-sensor:error-info-changed",{detail:e,bubbles:!0}))}start(e){if(this._sensor)return;const t=this._createSensor(e);if(t){t.addEventListener("reading",this._onReading),t.addEventListener("error",this._onError),this._sensor=t;try{t.start()}catch(e){this._teardownSensor(),this._setError({error:e?.name??"error",message:e?.message??String(e)})}}}stop(){if(this._sensor){try{this._sensor.stop()}catch{}this._teardownSensor()}}observe(e){return this.start(e),this.ready}dispose(){this.stop()}_teardownSensor(){this._sensor.removeEventListener("reading",this._onReading),this._sensor.removeEventListener("error",this._onError),this._sensor=null}_createSensor(e){const t=globalThis.AmbientLightSensor;if("function"!=typeof t)return this._setError({error:"unsupported",message:"AmbientLightSensor is not supported"}),null;try{return new t(void 0!==e?{frequency:e}:void 0)}catch(e){return this._setError({error:e?.name??"error",message:e?.message??String(e)}),null}}_onReading=e=>{const t=e.target;this._setReading({illuminance:t.illuminance})};_onError=e=>{const t=e.error;this._setError({error:t?.name??"error",message:t?.message??"Sensor error"})}}function l(e,t){let r=Object.getPrototypeOf(e);for(;null!==r;){const e=Object.getOwnPropertyDescriptor(r,t);if(void 0!==e)return"function"==typeof e.get||"function"==typeof e.set;r=Object.getPrototypeOf(r)}return!1}const u=new WeakSet;function h(e,t,r){if(u.has(e))return;u.add(e);const n=e.localName??"element";console.warn(`[wcs/input-as-attribute] <${n}> has the attribute ${t}="${r}": 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 d=new WeakMap;function m(e,t,r){const n=function(e,t){let r=d.get(e);return void 0===r&&(r=new Map,d.set(e,r)),r.has(t)||r.set(t,e.getAttribute(t)),r.get(t)}(e,t);!function(e,t,r){null===r?e.removeAttribute(t):e.setAttribute(t,r)}(e,t,void 0===r?n:null===r?null:String(r))}class g extends HTMLElement{static hasConnectedCallbackPromise=!0;static wcBindable={...c.wcBindable,inputs:[{name:"frequency"}],commands:c.wcBindable.commands};_core;_connectedCallbackPromise=Promise.resolve();_internals=null;constructor(){super(),this._core=new c(this),this._internals=this._initInternals(),this._wireStates({"wcs-ambient-light-sensor: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[r,n]of Object.entries(e))this.addEventListener(r,e=>{const r=this.hasAttribute("debug-states");for(const[s,o]of Object.entries(n(e.detail))){try{o?t.add(s):t.delete(s)}catch{}r&&this.toggleAttribute(`data-wcs-state-${s}`,o)}})}get frequency(){const e=this.getAttribute("frequency");if(null===e||""===e.trim())return null;const t=Number(e);return Number.isFinite(t)&&t>0?t:null}set frequency(e){m(this,"frequency",e)}get illuminance(){return this._core.illuminance}get error(){return this._core.error}get errorInfo(){return this._core.errorInfo}get connectedCallbackPromise(){return this._connectedCallbackPromise}start(){this._core.start(this.frequency??void 0)}stop(){this._core.stop()}connectedCallback(){!function(e){const t=e.constructor?.wcBindable,r=t?.inputs;if(void 0===r)return;const n=e.getAttribute;for(const t of r){const r=t.name,s="function"==typeof n?n.call(e,r.toLowerCase()):null;if(null!==s&&s.startsWith("[object ")&&h(e,r,s),!Object.prototype.hasOwnProperty.call(e,r))continue;if(!l(e,r))continue;const o=e,i=o[r];delete o[r],o[r]=i}}(this),this.style.display="none",this._connectedCallbackPromise=this._core.ready}disconnectedCallback(){this._core.dispose()}}const f=Symbol.for("wcstack.package"),b=new WeakSet;function _(e,t){Object.defineProperty(e,f,{value:t,configurable:!0})}function p(e,t,r,n,s){if(void 0!==n&&(r===n||r.prototype instanceof n))return;const o=r[f];if(o===s||b.has(e))return;b.add(e);const i=s.slice(0,s.lastIndexOf("@"));console.warn(`[${i}] [wcs/package-twice] <${t}> is already defined by ${o??`another copy of ${i} that does not name its version`}; this copy, ${s}, does nothing. Load each package once.`)}function w(n=customElements){!function(e,t,r){for(const[n,s]of r){const r=e.get(n);void 0===r?(_(s,t),e.define(n,s)):p(e,n,r,s,t)}}(n,`${t}@${r}`,[[e.tagNames.ambientLightSensor,g]])}var v;w(v);
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/ambient-light-sensor","version":"4.11.0"};
61
+ var pkg = {"name":"@wcstack/ambient-light-sensor","version":"4.11.2"};
62
62
 
63
63
  /**
64
64
  * ambientLightSensorCapabilities.ts
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@wcstack/ambient-light-sensor",
3
- "version": "4.11.0",
3
+ "version": "4.11.2",
4
4
  "description": "Declarative AmbientLightSensor component for Web Components. Framework-agnostic Generic Sensor API (AmbientLightSensor) monitor via wc-bindable-protocol.",
5
5
  "type": "module",
6
6
  "main": "./dist/index.esm.js",