@wcstack/idle 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 +1 -1
- package/dist/index.esm.js +1 -1
- package/package.json +1 -1
package/dist/auto.min.js
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
const e={tagNames:{idle:"wcs-idle"}};var t="@wcstack/idle",r="4.
|
|
1
|
+
const e={tagNames:{idle:"wcs-idle"}};var t="@wcstack/idle",r="4.13.0";const s="capability-missing",n="not-allowed",o="idle-error";class i extends EventTarget{static wcBindable={protocol:"wc-bindable",version:1,properties:[{name:"userState",event:"wcs-idle:change",semantics:"state",getter:e=>e.detail.userState},{name:"screenState",event:"wcs-idle:change",semantics:"state",getter:e=>e.detail.screenState},{name:"active",event:"wcs-idle:change",semantics:"state",getter:e=>"active"===e.detail.userState},{name:"error",event:"wcs-idle:error",semantics:"state"},{name:"errorInfo",event:"wcs-idle:error-info-changed",semantics:"state"}],commands:[{name:"requestPermission",async:!0},{name:"start",async:!0},{name:"stop"}]};_target;_userState=null;_screenState=null;_error=null;_errorInfo=null;_detector=null;_abortController=null;_gen=0;_ready=Promise.resolve();_toldNotReady=!1;constructor(e){super(),this._target=e??this}get ready(){return this._ready}get userState(){return this._userState}get screenState(){return this._screenState}get active(){return"active"===this._userState}get error(){return this._error}get errorInfo(){return this._errorInfo}observe(){return this._ready}dispose(){this.stop()}_api(){const e=globalThis;return"function"==typeof e.IdleDetector?e.IdleDetector:void 0}_setState(e,t){this._userState===e&&this._screenState===t||(this._userState=e,this._screenState=t,this._target.dispatchEvent(new CustomEvent("wcs-idle:change",{detail:{userState:e,screenState:t},bubbles:!0})))}_setError(e,t){this._error!==e&&(this._error=e,this._commitErrorInfo(null===e?null:function(e,t){return"unsupported"===e?{code:s,phase:"probe",recoverable:!1,message:t}:"NotAllowedError"===e?{code:n,phase:"start",recoverable:!1,message:t}:{code:o,phase:"execute",recoverable:!1,message:t}}(t,this._errorInfoMessage(e))),this._target.dispatchEvent(new CustomEvent("wcs-idle:error",{detail:e,bubbles:!0})))}_errorInfoMessage(e){const t=null!=e&&"object"==typeof e&&"error"in e?e.error:e;return"string"==typeof t?.message?t.message:String(t)}_commitErrorInfo(e){this._errorInfo=e,this._target.dispatchEvent(new CustomEvent("wcs-idle:error-info-changed",{detail:e,bubbles:!0}))}async requestPermission(){const e=this._api();if(!e)return this._setError({message:"IdleDetector is not supported in this browser"},"unsupported"),"denied";try{const t=await e.requestPermission();return this._setError(null),"granted"===t?"granted":"denied"}catch(e){return this._setError({error:e},e?.name),"denied"}}async start(e=6e4){this.stop();const t=this._api();if(!t)return void this._setError({message:"IdleDetector is not supported in this browser"},"unsupported");const r=new AbortController;this._abortController=r;const s=++this._gen;try{const n=new t;if(n.addEventListener("change",this._onChange),this._detector=n,await n.start({threshold:e,signal:r.signal}),s!==this._gen)return;this._toldNotReady=!1,this._setError(null),this._setState(n.userState,n.screenState)}catch(e){if(s!==this._gen)return;this._detector?.removeEventListener("change",this._onChange),this._detector=null,this._abortController=null,this._setError({error:e},e?.name),"NotAllowedError"===e?.name&&this._warnNotReady()}}_warnNotReady(){this._toldNotReady||(this._toldNotReady=!0,console.warn("[@wcstack/idle] [wcs/command-not-ready] start() was refused: the idle-detection permission is not granted (NotAllowedError), so nothing is detected. It goes to `error` too (`not-allowed`). Ask with requestPermission() first (from a user gesture), and start once it is granted. (Said once until a start() succeeds again.)",this._target))}stop(){this._gen++,this._abortController?.abort(),this._abortController=null,this._detector&&(this._detector.removeEventListener("change",this._onChange),this._detector=null)}_onChange=e=>{const t=e.target;this._setState(t.userState,t.screenState)}}function a(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 c=new WeakSet;function l(e,t,r){if(c.has(e))return;c.add(e);const s=e.localName??"element";console.warn(`[wcs/input-as-attribute] <${s}> 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 h(e,t,r){const s=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?s:null===r?null:String(r))}class u extends HTMLElement{static hasConnectedCallbackPromise=!0;static wcBindable={...i.wcBindable,inputs:[{name:"threshold",attribute:"threshold"}],commands:i.wcBindable.commands};_core;_connectedCallbackPromise=Promise.resolve();_internals=null;constructor(){super(),this._core=new i(this),this._internals=this._initInternals(),this._wireStates({"wcs-idle:change":e=>({active:"active"===e.userState}),"wcs-idle: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,s]of Object.entries(e))this.addEventListener(r,e=>{const r=this.hasAttribute("debug-states");for(const[n,o]of Object.entries(s(e.detail))){try{o?t.add(n):t.delete(n)}catch{}r&&this.toggleAttribute(`data-wcs-state-${n}`,o)}})}get threshold(){const e=this.getAttribute("threshold");if(null===e||""===e.trim())return 6e4;const t=Number(e);return Number.isFinite(t)?t:6e4}set threshold(e){h(this,"threshold",e)}get userState(){return this._core.userState}get screenState(){return this._core.screenState}get active(){return this._core.active}get error(){return this._core.error}get errorInfo(){return this._core.errorInfo}get connectedCallbackPromise(){return this._connectedCallbackPromise}requestPermission(){return this._core.requestPermission()}start(e){return this._core.start(e??this.threshold)}stop(){this._core.stop()}connectedCallback(){!function(e){const t=e.constructor?.wcBindable,r=t?.inputs;if(void 0===r)return;const s=e.getAttribute;for(const t of r){const r=t.name,n="function"==typeof s?s.call(e,r.toLowerCase()):null;if(null!==n&&n.startsWith("[object ")&&l(e,r,n),!Object.prototype.hasOwnProperty.call(e,r))continue;if(!a(e,r))continue;const o=e,i=o[r];delete o[r],o[r]=i}}(this),this.style.display="none",this._connectedCallbackPromise=this._core.observe()}disconnectedCallback(){this._core.dispose()}}const _=Symbol.for("wcstack.package"),g=new WeakSet;function f(e,t){Object.defineProperty(e,_,{value:t,configurable:!0})}function m(e,t,r,s,n){if(void 0!==s&&(r===s||r.prototype instanceof s))return;const o=r[_];if(o===n||g.has(e))return;g.add(e);const i=n.slice(0,n.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, ${n}, does nothing. Load each package once.`)}function b(s=customElements){!function(e,t,r){for(const[s,n]of r){const r=e.get(s);void 0===r?(f(n,t),e.define(s,n)):m(e,s,r,n,t)}}(s,`${t}@${r}`,[[e.tagNames.idle,u]])}var p;b(p);
|
|
2
2
|
//# sourceMappingURL=auto.min.js.map
|
package/dist/index.esm.js
CHANGED
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@wcstack/idle",
|
|
3
|
-
"version": "4.
|
|
3
|
+
"version": "4.13.0",
|
|
4
4
|
"description": "Declarative Idle Detection component for Web Components. Framework-agnostic IdleDetector wrapper via wc-bindable-protocol.",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "./dist/index.esm.js",
|