@wcstack/debounce 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 t={triggerAttribute:"data-debouncetarget",tagNames:{debounce:"wcs-debounce",throttle:"wcs-throttle"}};var e="@wcstack/debounce",i="4.
|
|
1
|
+
const t={triggerAttribute:"data-debouncetarget",tagNames:{debounce:"wcs-debounce",throttle:"wcs-throttle"}};var e="@wcstack/debounce",i="4.13.0";function n(t){return[{name:"value",event:`${t}:settled`,semantics:"state",getter:t=>t.detail.value},{name:"fired",event:`${t}:fired`,semantics:"event",getter:t=>t.detail.args},{name:"pending",event:`${t}:pending-changed`,semantics:"state"}]}class s extends EventTarget{static wcBindable={protocol:"wc-bindable",version:1,properties:n("wcs-debounce"),commands:[{name:"trigger"},{name:"cancel"},{name:"flush"}]};_prefix;_target;_wait=0;_leading=!1;_trailing=!0;_maxWait=0;_hasMaxWait=!1;_lastCallTime=void 0;_lastInvokeTime=0;_timerId=null;_timerGen=0;_pendingKind=null;_pendingValue=void 0;_pendingArgs=void 0;_value=void 0;_lastArgs=[];_pending=!1;_gen=0;_ready=Promise.resolve();constructor(t="wcs-debounce",e,i){super(),this._prefix=t,this._target=e??this,i&&this.configure(i)}get ready(){return this._ready}observe(){return this._ready}dispose(){this._gen++,this.cancel()}configure(t={}){"number"==typeof t.wait&&Number.isFinite(t.wait)&&t.wait>=0&&(this._wait=t.wait),"boolean"==typeof t.leading&&(this._leading=t.leading),"boolean"==typeof t.trailing&&(this._trailing=t.trailing);const e=t.maxWait;"number"==typeof e&&Number.isFinite(e)&&e>=0?(this._maxWait=Math.max(e,this._wait),this._hasMaxWait=!0):(this._maxWait=0,this._hasMaxWait=!1)}get value(){return this._value}get fired(){return this._lastArgs}get pending(){return this._pending}setSource(t){this._schedule("value",t,void 0)}trigger(...t){this._schedule("signal",void 0,t)}cancel(){this._clearTimer(),this._lastInvokeTime=0,this._lastCallTime=void 0,this._pendingKind=null,this._pendingValue=void 0,this._pendingArgs=void 0,this._setPending(!1)}flush(){if(null===this._timerId&&null===this._pendingKind)return;const t=Date.now();this._clearTimer(),null!==this._pendingKind&&this._invoke(t),this._pendingKind=null,this._pendingValue=void 0,this._pendingArgs=void 0,this._setPending(!1)}_schedule(t,e,i){const n=Date.now(),s=this._shouldInvoke(n);if(this._pendingKind=t,"value"===t?this._pendingValue=e:this._pendingArgs=i,this._lastCallTime=n,this._setPending(!0),s){if(null===this._timerId)return void this._leadingEdge(n);if(this._hasMaxWait)return this._clearTimer(),this._armTimer(this._wait),void this._invoke(n)}null===this._timerId&&this._armTimer(this._wait)}_shouldInvoke(t){if(void 0===this._lastCallTime)return!0;const e=t-this._lastCallTime,i=t-this._lastInvokeTime;return e>=this._wait||e<0||this._hasMaxWait&&i>=this._maxWait}_remainingWait(t){const e=t-this._lastCallTime,i=t-this._lastInvokeTime,n=this._wait-e;return this._hasMaxWait?Math.min(n,this._maxWait-i):n}_timerExpired=()=>{if(this._timerGen!==this._gen)return;const t=Date.now();this._shouldInvoke(t)?this._trailingEdge(t):this._armTimer(this._remainingWait(t))};_leadingEdge(t){this._lastInvokeTime=t,this._armTimer(this._wait),this._leading&&this._invoke(t)}_trailingEdge(t){this._timerId=null,this._trailing&&null!==this._pendingKind&&this._invoke(t),this._pendingKind=null,this._pendingValue=void 0,this._pendingArgs=void 0,this._setPending(!1)}_invoke(t){this._lastInvokeTime=t;const e=this._pendingKind;"value"===e?(this._value=this._pendingValue,this._dispatch(`${this._prefix}:settled`,{value:this._value})):"signal"===e&&(this._lastArgs=this._pendingArgs??[],this._dispatch(`${this._prefix}:fired`,{args:this._lastArgs})),this._pendingKind=null}_setPending(t){this._pending!==t&&(this._pending=t,this._dispatch(`${this._prefix}:pending-changed`,t))}_dispatch(t,e){this._target.dispatchEvent(new CustomEvent(t,{detail:e,bubbles:!0}))}_armTimer(t){this._timerGen=this._gen,this._timerId=setTimeout(this._timerExpired,t)}_clearTimer(){null!==this._timerId&&(clearTimeout(this._timerId),this._timerId=null)}}let a=!1;function r(e){const i=e.target;if(!(i instanceof Element))return;const n=i.closest(`[${t.triggerAttribute}]`);if(!n)return;const s=n.getAttribute(t.triggerAttribute);if(!s)return;const a=customElements.get(t.tagNames.debounce),r=customElements.get(t.tagNames.throttle),o=document.getElementById(s);if(!o)return;(a&&o instanceof a||r&&o instanceof r)&&(e.preventDefault(),o.trigger())}function o(t,e){let i=Object.getPrototypeOf(t);for(;null!==i;){const t=Object.getOwnPropertyDescriptor(i,e);if(void 0!==t)return"function"==typeof t.get||"function"==typeof t.set;i=Object.getPrototypeOf(i)}return!1}const l=new WeakSet;function c(t,e,i){if(l.has(t))return;l.add(t);const n=t.localName??"element";console.warn(`[wcs/input-as-attribute] <${n}> has the attribute ${e}="${i}": 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.)`,t)}const h=new WeakMap;function d(t,e){let i=h.get(t);return void 0===i&&(i=new Map,h.set(t,i)),i.has(e)||i.set(e,t.getAttribute(e)),i.get(e)}function u(t,e,i){null===i?t.removeAttribute(e):t.setAttribute(e,i)}function g(t,e,i){const n=d(t,e);u(t,e,void 0===i?n:null===i?null:String(i))}function _(t,e,i){const n=d(t,e);u(t,e,void 0===i?n:i?"":null)}class m extends HTMLElement{static hasConnectedCallbackPromise=!0;static eventPrefix="wcs-debounce";static wcBindable={protocol:"wc-bindable",version:1,properties:n("wcs-debounce"),inputs:[{name:"source"},{name:"wait",attribute:"wait"},{name:"leading"},{name:"trailing"},{name:"maxWait",attribute:"max-wait"}],commands:[{name:"trigger"},{name:"cancel"},{name:"flush"}]};_core;_source=void 0;_connectedCallbackPromise=Promise.resolve();_internals=null;constructor(){super(),this._core=new s(this.constructor.eventPrefix,this),this._internals=this._initInternals();const t=this.constructor.eventPrefix;this._wireStates({[`${t}:pending-changed`]:t=>({pending:!0===t})})}get debugStates(){return this._internals?[...this._internals.states]:[]}_initInternals(){try{if("function"!=typeof this.attachInternals)return null;const t=this.attachInternals();return t.states.add("wcs-probe"),t.states.delete("wcs-probe"),t}catch{return null}}_wireStates(t){if(null===this._internals)return;const e=this._internals.states;for(const[i,n]of Object.entries(t))this.addEventListener(i,t=>{const i=this.hasAttribute("debug-states");for(const[s,a]of Object.entries(n(t.detail))){try{a?e.add(s):e.delete(s)}catch{}i&&this.toggleAttribute(`data-wcs-state-${s}`,a)}})}get connectedCallbackPromise(){return this._connectedCallbackPromise}get wait(){const t=this.getAttribute("wait");if(null===t||""===t.trim())return this._defaultWait();const e=Number(t);return Number.isFinite(e)&&e>=0?e:this._defaultWait()}set wait(t){g(this,"wait",t)}get leading(){return this.hasAttribute("leading")}set leading(t){_(this,"leading",t)}get trailing(){return!this.hasAttribute("no-trailing")}set trailing(t){_(this,"no-trailing",null==t?t:!t)}get maxWait(){const t=this.getAttribute("max-wait");if(null===t||""===t.trim())return this._defaultMaxWait();const e=Number(t);return Number.isFinite(e)&&e>=0?e:this._defaultMaxWait()}set maxWait(t){g(this,"max-wait",t)}get source(){return this._source}set source(t){this._source=t,this._core.configure(this._options()),this._core.setSource(t)}get value(){return this._core.value}get fired(){return this._core.fired}get pending(){return this._core.pending}trigger(...t){this._core.configure(this._options()),this._core.trigger(...t)}cancel(){this._core.cancel()}flush(){this._core.flush()}_defaultWait(){return 250}_resolveLeading(){return this.leading}_defaultMaxWait(){}_options(){return{wait:this.wait,leading:this._resolveLeading(),trailing:this.trailing,maxWait:this.maxWait}}connectedCallback(){!function(t){const e=t.constructor?.wcBindable,i=e?.inputs;if(void 0===i)return;const n=t.getAttribute;for(const e of i){const i=e.name,s="function"==typeof n?n.call(t,i.toLowerCase()):null;if(null!==s&&s.startsWith("[object ")&&c(t,i,s),!Object.prototype.hasOwnProperty.call(t,i))continue;if(!o(t,i))continue;const a=t,r=a[i];delete a[i],a[i]=r}}(this),this.style.display="none",a||(a=!0,document.addEventListener("click",r)),this._connectedCallbackPromise=this._core.observe()}disconnectedCallback(){this._core.dispose()}}class f extends m{static eventPrefix="wcs-throttle";static wcBindable={...m.wcBindable,properties:n("wcs-throttle")};get leading(){return!this.hasAttribute("no-leading")}set leading(t){_(this,"no-leading",null==t?t:!t)}_defaultMaxWait(){return this.wait}}const p=Symbol.for("wcstack.package"),b=new WeakSet;function v(t,e){Object.defineProperty(t,p,{value:e,configurable:!0})}function w(t,e,i,n,s){if(void 0!==n&&(i===n||i.prototype instanceof n))return;const a=i[p];if(a===s||b.has(t))return;b.add(t);const r=s.slice(0,s.lastIndexOf("@"));console.warn(`[${r}] [wcs/package-twice] <${e}> is already defined by ${a??`another copy of ${r} that does not name its version`}; this copy, ${s}, does nothing. Load each package once.`)}function x(n=customElements){!function(t,e,i){for(const[n,s]of i){const i=t.get(n);void 0===i?(v(s,e),t.define(n,s)):w(t,n,i,s,e)}}(n,`${e}@${i}`,[[t.tagNames.debounce,m],[t.tagNames.throttle,f]])}var k;x(k);
|
|
2
2
|
//# sourceMappingURL=auto.min.js.map
|
package/dist/index.esm.js
CHANGED
|
@@ -66,7 +66,7 @@ function setConfig(partialConfig) {
|
|
|
66
66
|
frozenConfig = null;
|
|
67
67
|
}
|
|
68
68
|
|
|
69
|
-
var pkg = {"name":"@wcstack/debounce","version":"4.
|
|
69
|
+
var pkg = {"name":"@wcstack/debounce","version":"4.13.0"};
|
|
70
70
|
|
|
71
71
|
/**
|
|
72
72
|
* Build the wc-bindable `properties` list for a debounce/throttle element, with
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@wcstack/debounce",
|
|
3
|
-
"version": "4.
|
|
3
|
+
"version": "4.13.0",
|
|
4
4
|
"description": "Declarative debounce/throttle components for Web Components. Framework-agnostic signal coalescing via wc-bindable-protocol.",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "./dist/index.esm.js",
|