@wcstack/timer 4.17.0 → 4.18.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-timertarget",tagNames:{timer:"wcs-timer"}};var e="@wcstack/timer",i="4.
|
|
1
|
+
const t={triggerAttribute:"data-timertarget",tagNames:{timer:"wcs-timer"}};var e="@wcstack/timer",i="4.18.0";class n extends EventTarget{static wcBindable={protocol:"wc-bindable",version:1,properties:[{name:"tick",event:"wcs-timer:tick",semantics:"state",getter:t=>t.detail.count},{name:"elapsed",event:"wcs-timer:tick",semantics:"state",getter:t=>t.detail.elapsed},{name:"running",event:"wcs-timer:running-changed",semantics:"state"}],commands:[{name:"start"},{name:"stop"},{name:"reset"},{name:"pause"},{name:"resume"}]};_target;_timerId=null;_gen=0;_runGen=0;_ready=Promise.resolve();_tick=0;_running=!1;_paused=!1;_runStartTick=0;_interval=1e3;_repeat=0;_accumulatedElapsed=0;_segmentStart=null;constructor(t){super(),this._target=t??this}get tick(){return this._tick}get elapsed(){return this._currentElapsed()}get running(){return this._running}get ready(){return this._ready}observe(){return this._ready}dispose(){this._gen++,this.stop()}_dispatchTick(){this._target.dispatchEvent(new CustomEvent("wcs-timer:tick",{detail:{count:this._tick,elapsed:this._currentElapsed()},bubbles:!0}))}_setRunning(t){this._running!==t&&(this._running=t,this._target.dispatchEvent(new CustomEvent("wcs-timer:running-changed",{detail:t,bubbles:!0})))}start(t={}){if(this._running)return;this._paused=!1,"number"==typeof t.interval&&Number.isFinite(t.interval)&&t.interval>0&&(this._interval=t.interval),this._repeat="number"==typeof t.repeat&&t.repeat>0?t.repeat:0;const e=!0===t.immediate;this._setRunning(!0),this._segmentStart=Date.now(),this._runStartTick=this._tick,this._runGen=++this._gen,e&&this._fire(),this._running&&(this._timerId=setInterval(this._fire,this._interval))}changeInterval(t){this._running&&"number"==typeof t&&Number.isFinite(t)&&t>0&&t!==this._interval&&(this._interval=t,this._clearTimer(),this._timerId=setInterval(this._fire,this._interval))}stop(){this._clearTimer(),this._foldElapsed(),this._paused=!1,this._setRunning(!1)}reset(){this._clearTimer(),this._paused=!1,this._tick=0,this._accumulatedElapsed=0,this._segmentStart=null,this._setRunning(!1),this._dispatchTick()}pause(){this._running&&!this._paused&&(this._clearTimer(),this._foldElapsed(),this._paused=!0,this._setRunning(!1))}resume(){if(!this._paused)return;this._paused=!1,this._setRunning(!0),this._segmentStart=Date.now(),this._runGen=++this._gen;const t=this._interval-this._accumulatedElapsed%this._interval;this._timerId=setTimeout(this._onResumeBoundary,t)}_onResumeBoundary=()=>{this._runGen===this._gen&&(this._timerId=null,this._fire(),this._running&&(this._timerId=setInterval(this._fire,this._interval)))};_fire=()=>{this._runGen===this._gen&&(this._tick++,this._dispatchTick(),this._repeat>0&&this._tick-this._runStartTick>=this._repeat&&(this._clearTimer(),this._foldElapsed(),this._setRunning(!1)))};_clearTimer(){null!==this._timerId&&(clearTimeout(this._timerId),clearInterval(this._timerId),this._timerId=null)}_foldElapsed(){null!==this._segmentStart&&(this._accumulatedElapsed+=Date.now()-this._segmentStart,this._segmentStart=null)}_currentElapsed(){return this._accumulatedElapsed+(null!==this._segmentStart?Date.now()-this._segmentStart:0)}}let s=!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 r=customElements.get(t.tagNames.timer),a=document.getElementById(s);r&&a instanceof r&&(e.preventDefault(),a.start())}function a(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 c=new WeakSet;function o(t,e,i){if(c.has(t))return;c.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 u=new WeakMap;function h(t,e){let i=u.get(t);return void 0===i&&(i=new Map,u.set(t,i)),i.has(e)||i.set(e,t.getAttribute(e)),i.get(e)}function l(t,e,i){null===i?t.removeAttribute(e):t.setAttribute(e,i)}function d(t,e,i){const n=h(t,e);l(t,e,void 0===i?n:null===i?null:String(i))}function _(t,e,i){const n=h(t,e);l(t,e,void 0===i?n:i?"":null)}class m extends HTMLElement{static hasConnectedCallbackPromise=!0;static wcBindable={...n.wcBindable,properties:[...n.wcBindable.properties,{name:"trigger",event:"wcs-timer:trigger-changed",semantics:"state"}],inputs:[{name:"interval",attribute:"interval"},{name:"once",attribute:"once"},{name:"repeat",attribute:"repeat"},{name:"immediate",attribute:"immediate"},{name:"manual",attribute:"manual"},{name:"trigger"}]};static get observedAttributes(){return["interval"]}_core;_trigger=!1;_connectedCallbackPromise=Promise.resolve();_startPending=!1;_internals=null;constructor(){super(),this._core=new n(this),this._internals=this._initInternals(),this._wireStates({"wcs-timer:running-changed":t=>({running:!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,r]of Object.entries(n(t.detail))){try{r?e.add(s):e.delete(s)}catch{}i&&this.toggleAttribute(`data-wcs-state-${s}`,r)}})}get connectedCallbackPromise(){return this._connectedCallbackPromise}get interval(){const t=this.getAttribute("interval");if(null===t||""===t.trim())return 1e3;const e=Number(t);return Number.isFinite(e)&&e>0?e:1e3}set interval(t){d(this,"interval",t)}get once(){return this.hasAttribute("once")}set once(t){_(this,"once",t)}get repeat(){const t=this.getAttribute("repeat");if(null===t||""===t.trim())return 0;const e=Number(t);return Number.isFinite(e)&&e>0?e:0}set repeat(t){d(this,"repeat",t)}get immediate(){return this.hasAttribute("immediate")}set immediate(t){_(this,"immediate",t)}get manual(){return this.hasAttribute("manual")}set manual(t){_(this,"manual",t)}get tick(){return this._core.tick}get elapsed(){return this._core.elapsed}get running(){return this._core.running}get trigger(){return this._trigger}set trigger(t){!!t&&(this._trigger=!0,this.start(),this._trigger=!1,this.dispatchEvent(new CustomEvent("wcs-timer:trigger-changed",{detail:!1,bubbles:!0})))}start(){const t=this.repeat>0?this.repeat:this.once?1:0;this._core.start({interval:this.interval,repeat:t,immediate:this.immediate})}stop(){this._startPending=!1,this._core.stop()}reset(){this._startPending=!1,this._core.reset()}pause(){this._startPending&&(this._startPending=!1,this.isConnected&&!this.manual&&this.start()),this._core.pause()}resume(){this._core.resume()}attributeChangedCallback(t,e,i){"interval"===t&&e!==i&&this.isConnected&&this.running&&this._core.changeInterval(this.interval)}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 ")&&o(t,i,s),!Object.prototype.hasOwnProperty.call(t,i))continue;if(!a(t,i))continue;const r=t,c=r[i];delete r[i],r[i]=c}}(this),this.style.display="none",s||(s=!0,document.addEventListener("click",r)),this._connectedCallbackPromise=this._core.observe(),this._scheduleStart()}_scheduleStart(){this._startPending||(this._startPending=!0,queueMicrotask(()=>{this._startPending&&(this._startPending=!1,this.isConnected&&!this.manual&&this.start())}))}disconnectedCallback(){this._core.dispose()}}const g=Symbol.for("wcstack.package"),p=new WeakSet;function b(t,e){Object.defineProperty(t,g,{value:e,configurable:!0})}function f(t,e,i,n,s){if(void 0!==n&&(i===n||i.prototype instanceof n))return;const r=i[g];if(r===s||p.has(t))return;p.add(t);const a=s.slice(0,s.lastIndexOf("@"));console.warn(`[${a}] [wcs/package-twice] <${e}> is already defined by ${r??`another copy of ${a} that does not name its version`}; this copy, ${s}, does nothing. Load each package once.`)}function v(n=customElements){!function(t,e,i){for(const[n,s]of i){const i=t.get(n);void 0===i?(b(s,e),t.define(n,s)):f(t,n,i,s,e)}}(n,`${e}@${i}`,[[t.tagNames.timer,m]])}var w;v(w);
|
|
2
2
|
//# sourceMappingURL=auto.min.js.map
|
package/dist/index.esm.js
CHANGED
|
@@ -70,7 +70,7 @@ function setConfig(partialConfig) {
|
|
|
70
70
|
frozenConfig = null;
|
|
71
71
|
}
|
|
72
72
|
|
|
73
|
-
var pkg = {"name":"@wcstack/timer","version":"4.
|
|
73
|
+
var pkg = {"name":"@wcstack/timer","version":"4.18.0"};
|
|
74
74
|
|
|
75
75
|
/**
|
|
76
76
|
* Headless timer primitive. A thin, framework-agnostic wrapper around
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@wcstack/timer",
|
|
3
|
-
"version": "4.
|
|
3
|
+
"version": "4.18.0",
|
|
4
4
|
"description": "Declarative timer component for Web Components. Framework-agnostic interval/timeout primitive via wc-bindable-protocol.",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "./dist/index.esm.js",
|