@wcstack/worker 4.13.0 → 4.14.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-worker-target",tagNames:{worker:"wcs-worker"}};var e="@wcstack/worker",r="4.13.0";const s="capability-missing",n="invalid-argument",a="worker-error";const o=Symbol.for("wcstack.trustedTypes.policy"),i=Symbol.for("wcstack.trustedTypes.internal"),c="wcstack";function l(){const t=globalThis[o];return null===t||"object"!=typeof t?null:t}let u=!1;function h(t){const e=function(){const t=globalThis,e=t[i];if(void 0!==e)return e;const r=globalThis.trustedTypes;let s=null;if(r&&"function"==typeof r.createPolicy)try{s=r.createPolicy(c,{createHTML:t=>t,createScriptURL:t=>t})}catch(t){"function"!=typeof l()?.createScriptURL&&console.error(`[@wcstack/worker] Could not create the Trusted Types policy "${c}". Allow it in the CSP (\`trusted-types ${c};\`), or inject your own policy at globalThis[Symbol.for("wcstack.trustedTypes.policy")]. See docs/csp.md section 7.`,t)}return t[i]=s,s}(),r=e?.createScriptURL;if("function"==typeof r)return r.call(e,t);if(!("trustedTypes"in globalThis))return t;const s=l(),n=s?.createScriptURL;return"function"==typeof n?(u||(u=!0,console.warn(`[@wcstack/worker] Falling back to the injected Trusted Types policy to sign the worker URL, because the "${c}" policy could not be created. Allow \`trusted-types ${c};\` in the CSP to avoid this. See docs/csp.md section 7.`)),n.call(s,t)):t}class m extends EventTarget{static wcBindable={protocol:"wc-bindable",version:1,properties:[{name:"message",event:"wcs-worker:message",semantics:"event"},{name:"error",event:"wcs-worker:error",semantics:"state"},{name:"errorInfo",event:"wcs-worker:error-info-changed",semantics:"state"},{name:"running",event:"wcs-worker:running-changed",semantics:"state"}],commands:[{name:"start"},{name:"post"},{name:"terminate"}]};_target;_worker=null;_message=null;_error=null;_errorInfo=null;_running=!1;_src="";_type="module";_name="";_restartOnError=!1;_maxRestarts=1/0;_restartInterval=0;_restartCount=0;_restartTimer=null;_gen=0;_ready=Promise.resolve();_toldNotReady=!1;_toldUncloneable=!1;constructor(t){super(),this._target=t??this}get ready(){return this._ready}observe(){return this._ready}get message(){return this._message}get error(){return this._error}get errorInfo(){return this._errorInfo}get running(){return this._running}_setMessage(t){this._message=t,this._target.dispatchEvent(new CustomEvent("wcs-worker:message",{detail:t,bubbles:!0}))}_setError(t){this._error!==t&&(this._error=t,this._commitErrorInfo(null===t?null:function(t){const{name:e,message:r}=t;return"TypeError"===e&&"src is required."===r?{code:n,phase:"start",recoverable:!1,message:r}:"TypeError"===e||"ReferenceError"===e?{code:s,phase:"probe",recoverable:!1,message:r}:{code:a,phase:"execute",recoverable:!1,message:r}}(t)),this._target.dispatchEvent(new CustomEvent("wcs-worker:error",{detail:t,bubbles:!0})))}_commitErrorInfo(t){this._errorInfo=t,this._target.dispatchEvent(new CustomEvent("wcs-worker:error-info-changed",{detail:t,bubbles:!0}))}_setRunning(t){this._running=t,this._target.dispatchEvent(new CustomEvent("wcs-worker:running-changed",{detail:t,bubbles:!0}))}start(t,e={}){t?this._worker&&this._src===t||(this._clearRestartTimer(),this._terminateWorker(),this._src=t,this._type=e.type??"module",this._name=e.name??"",this._restartOnError=e.restartOnError??!1,this._maxRestarts=e.maxRestarts??1/0,this._restartInterval=e.restartInterval??0,this._restartCount=0,this._setError(null),this._spawn()):this._setError({name:"TypeError",message:"src is required."})}post(t,e){if(!this._worker)return this._setError({name:"InvalidStateError",message:"Worker is not running. Call start(src) before post()."}),void this._warnNotReady();try{e&&e.length>0?this._worker.postMessage(t,e):this._worker.postMessage(t)}catch(t){this._setError(this._normalizeError(t)),this._warnUncloneable(t)}}_warnUncloneable(t){this._toldUncloneable||"DataCloneError"!==t?.name||(this._toldUncloneable=!0,console.warn("[@wcstack/worker] [wcs/post-uncloneable] post() was refused: the message cannot be structured-cloned (DataCloneError), so it is lost. It goes to `error` too. A framework's reactive proxy is the usual cause — Vue's toRaw() unwraps one level only: pass a deep plain copy (JSON.parse(JSON.stringify(value)), or toRaw on each level). (Said once per element.)",this._target))}_warnNotReady(){this._toldNotReady||(this._toldNotReady=!0,console.warn("[@wcstack/worker] [wcs/command-not-ready] post() was refused: no worker is running, so the message is lost. It goes to `error` too. Give the element a `src` (or call start(src)) first. (Said once until a worker starts again.)",this._target))}terminate(){this._clearRestartTimer(),this._terminateWorker()}dispose(){this._gen++,this._clearRestartTimer(),this._terminateWorker(),this._setError(null)}_spawn(){try{this._worker=new Worker(h(this._src),{type:this._type,name:this._name||void 0})}catch(t){return void this._setError(this._normalizeError(t))}this._worker.addEventListener("message",this._onMessage),this._worker.addEventListener("messageerror",this._onMessageError),this._worker.addEventListener("error",this._onError),this._toldNotReady=!1,this._setRunning(!0)}_onMessage=t=>{this._setMessage(t.data)};_onMessageError=()=>{this._setError({name:"DataError",message:"Failed to deserialize a message received from the worker."})};_onError=t=>{this._setError({name:"Error",message:t.message||"Worker script error.",filename:t.filename,lineno:t.lineno,colno:t.colno}),this._restartOnError&&this._restartCount<this._maxRestarts&&this._scheduleRestart()};_scheduleRestart(){this._clearRestartTimer();const t=this._gen;this._restartTimer=setTimeout(()=>{t===this._gen&&(this._restartTimer=null,this._restartCount++,this._terminateWorker(),this._setError(null),this._spawn())},this._restartInterval)}_clearRestartTimer(){null!==this._restartTimer&&(clearTimeout(this._restartTimer),this._restartTimer=null)}_terminateWorker(){this._worker&&(this._worker.removeEventListener("message",this._onMessage),this._worker.removeEventListener("messageerror",this._onMessageError),this._worker.removeEventListener("error",this._onError),this._worker.terminate(),this._worker=null,this._setRunning(!1))}_normalizeError(t){return t instanceof Error?{name:t.name,message:t.message}:{name:"Error",message:String(t)}}}let d=!1;const _="data-worker-text";function g(e){const r=e.target;if(!(r instanceof Element))return;const s=r.closest(`[${t.triggerAttribute}]`);if(!s)return;const n=s.getAttribute(t.triggerAttribute);if(!n)return;const a=customElements.get(t.tagNames.worker),o=document.getElementById(n);if(!(a&&o instanceof a))return;const i=function(t){if(t.hasAttribute(_))return t.getAttribute(_)??"";const e=t.getAttribute("data-worker-from");if(!e)return null;let r;try{r=document.querySelector(e)}catch{return null}return r?r instanceof HTMLInputElement||r instanceof HTMLTextAreaElement||r instanceof HTMLSelectElement?r.value:r.textContent??"":null}(s);null!==i&&(e.preventDefault(),o.post(i))}function p(t,e){let r=Object.getPrototypeOf(t);for(;null!==r;){const t=Object.getOwnPropertyDescriptor(r,e);if(void 0!==t)return"function"==typeof t.get||"function"==typeof t.set;r=Object.getPrototypeOf(r)}return!1}const w=new WeakSet;function f(t,e,r){if(w.has(t))return;w.add(t);const s=t.localName??"element";console.warn(`[wcs/input-as-attribute] <${s}> has the attribute ${e}="${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.)`,t)}const b=new WeakMap;function y(t,e){let r=b.get(t);return void 0===r&&(r=new Map,b.set(t,r)),r.has(e)||r.set(e,t.getAttribute(e)),r.get(e)}function k(t,e,r){null===r?t.removeAttribute(e):t.setAttribute(e,r)}function v(t,e,r){const s=y(t,e);k(t,e,void 0===r?s:null===r?null:String(r))}function E(t,e,r){const s=y(t,e);k(t,e,void 0===r?s:r?"":null)}class T extends HTMLElement{static hasConnectedCallbackPromise=!0;static wcBindable={...m.wcBindable,inputs:[{name:"src",attribute:"src"},{name:"type",attribute:"type"},{name:"name",attribute:"name"},{name:"manual",attribute:"manual"},{name:"keepAlive",attribute:"keep-alive"},{name:"restartOnError",attribute:"restart-on-error"},{name:"maxRestarts",attribute:"max-restarts"},{name:"restartInterval",attribute:"restart-interval"}],commands:m.wcBindable.commands};static get observedAttributes(){return["src"]}_core;_connectedCallbackPromise=Promise.resolve();_everConnected=!1;_startPending=!1;_internals=null;constructor(){super(),this._core=new m(this),this._internals=this._initInternals(),this._wireStates({"wcs-worker:running-changed":t=>({running:!0===t}),"wcs-worker:error":t=>({error:null!=t})})}get connectedCallbackPromise(){return this._connectedCallbackPromise}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[r,s]of Object.entries(t))this.addEventListener(r,t=>{const r=this.hasAttribute("debug-states");for(const[n,a]of Object.entries(s(t.detail))){try{a?e.add(n):e.delete(n)}catch{}r&&this.toggleAttribute(`data-wcs-state-${n}`,a)}})}get src(){return this.getAttribute("src")||""}set src(t){v(this,"src",t)}get type(){return"classic"===this.getAttribute("type")?"classic":"module"}set type(t){v(this,"type",t)}get name(){return this.getAttribute("name")||""}set name(t){v(this,"name",t)}get manual(){return this.hasAttribute("manual")}set manual(t){E(this,"manual",t)}get keepAlive(){return this.hasAttribute("keep-alive")}set keepAlive(t){E(this,"keep-alive",t)}get restartOnError(){return this.hasAttribute("restart-on-error")}set restartOnError(t){E(this,"restart-on-error",t)}get maxRestarts(){const t=this.getAttribute("max-restarts");if("Infinity"===t)return 1/0;const e=t?parseInt(t,10):1/0;return Number.isNaN(e)?1/0:e}set maxRestarts(t){v(this,"max-restarts",t)}get restartInterval(){const t=this.getAttribute("restart-interval"),e=t?parseInt(t,10):0;return Number.isNaN(e)?0:e}set restartInterval(t){v(this,"restart-interval",t)}get message(){return this._core.message}get error(){return this._core.error}get errorInfo(){return this._core.errorInfo}get running(){return this._core.running}start(){this._startPending=!1,this._core.start(this.src,{type:this.type,name:this.name,restartOnError:this.restartOnError,maxRestarts:this.maxRestarts,restartInterval:this.restartInterval})}post(t,e){this._core.post(t,e)}terminate(){this._startPending=!1,this._core.terminate()}attributeChangedCallback(t,e,r){"src"===t&&this.isConnected&&!this.manual&&r&&!this._startPending&&this.start()}_scheduleStart(){this._startPending||(this._startPending=!0,queueMicrotask(()=>{this._startPending&&(this._startPending=!1,this.isConnected&&!this.manual&&this.src&&this.start())}))}connectedCallback(){!function(t){const e=t.constructor?.wcBindable,r=e?.inputs;if(void 0===r)return;const s=t.getAttribute;for(const e of r){const r=e.name,n="function"==typeof s?s.call(t,r.toLowerCase()):null;if(null!==n&&n.startsWith("[object ")&&f(t,r,n),!Object.prototype.hasOwnProperty.call(t,r))continue;if(!p(t,r))continue;const a=t,o=a[r];delete a[r],a[r]=o}}(this),this.style.display="none",d||(d=!0,document.addEventListener("click",g)),this._connectedCallbackPromise=this._core.observe(),this._everConnected?this._scheduleStart():(this._everConnected=!0,!this.manual&&this.src&&this.start())}disconnectedCallback(){this.keepAlive||this._core.dispose()}}const R=Symbol.for("wcstack.package"),A=new WeakSet;function C(t,e){Object.defineProperty(t,R,{value:e,configurable:!0})}function I(t,e,r,s,n){if(void 0!==s&&(r===s||r.prototype instanceof s))return;const a=r[R];if(a===n||A.has(t))return;A.add(t);const o=n.slice(0,n.lastIndexOf("@"));console.warn(`[${o}] [wcs/package-twice] <${e}> is already defined by ${a??`another copy of ${o} that does not name its version`}; this copy, ${n}, does nothing. Load each package once.`)}function S(s=customElements){!function(t,e,r){for(const[s,n]of r){const r=t.get(s);void 0===r?(C(n,e),t.define(s,n)):I(t,s,r,n,e)}}(s,`${e}@${r}`,[[t.tagNames.worker,T]])}var P;S(P);
|
|
1
|
+
const t={triggerAttribute:"data-worker-target",tagNames:{worker:"wcs-worker"}};var e="@wcstack/worker",r="4.14.0";const s="capability-missing",n="invalid-argument",a="worker-error";const o=Symbol.for("wcstack.trustedTypes.policy"),i=Symbol.for("wcstack.trustedTypes.internal"),c="wcstack";function l(){const t=globalThis[o];return null===t||"object"!=typeof t?null:t}let u=!1;function h(t){const e=function(){const t=globalThis,e=t[i];if(void 0!==e)return e;const r=globalThis.trustedTypes;let s=null;if(r&&"function"==typeof r.createPolicy)try{s=r.createPolicy(c,{createHTML:t=>t,createScriptURL:t=>t})}catch(t){"function"!=typeof l()?.createScriptURL&&console.error(`[@wcstack/worker] Could not create the Trusted Types policy "${c}". Allow it in the CSP (\`trusted-types ${c};\`), or inject your own policy at globalThis[Symbol.for("wcstack.trustedTypes.policy")]. See docs/csp.md section 7.`,t)}return t[i]=s,s}(),r=e?.createScriptURL;if("function"==typeof r)return r.call(e,t);if(!("trustedTypes"in globalThis))return t;const s=l(),n=s?.createScriptURL;return"function"==typeof n?(u||(u=!0,console.warn(`[@wcstack/worker] Falling back to the injected Trusted Types policy to sign the worker URL, because the "${c}" policy could not be created. Allow \`trusted-types ${c};\` in the CSP to avoid this. See docs/csp.md section 7.`)),n.call(s,t)):t}class m extends EventTarget{static wcBindable={protocol:"wc-bindable",version:1,properties:[{name:"message",event:"wcs-worker:message",semantics:"event"},{name:"error",event:"wcs-worker:error",semantics:"state"},{name:"errorInfo",event:"wcs-worker:error-info-changed",semantics:"state"},{name:"running",event:"wcs-worker:running-changed",semantics:"state"}],commands:[{name:"start"},{name:"post"},{name:"terminate"}]};_target;_worker=null;_message=null;_error=null;_errorInfo=null;_running=!1;_src="";_type="module";_name="";_restartOnError=!1;_maxRestarts=1/0;_restartInterval=0;_restartCount=0;_restartTimer=null;_gen=0;_ready=Promise.resolve();_toldNotReady=!1;_toldUncloneable=!1;constructor(t){super(),this._target=t??this}get ready(){return this._ready}observe(){return this._ready}get message(){return this._message}get error(){return this._error}get errorInfo(){return this._errorInfo}get running(){return this._running}_setMessage(t){this._message=t,this._target.dispatchEvent(new CustomEvent("wcs-worker:message",{detail:t,bubbles:!0}))}_setError(t){this._error!==t&&(this._error=t,this._commitErrorInfo(null===t?null:function(t){const{name:e,message:r}=t;return"TypeError"===e&&"src is required."===r?{code:n,phase:"start",recoverable:!1,message:r}:"TypeError"===e||"ReferenceError"===e?{code:s,phase:"probe",recoverable:!1,message:r}:{code:a,phase:"execute",recoverable:!1,message:r}}(t)),this._target.dispatchEvent(new CustomEvent("wcs-worker:error",{detail:t,bubbles:!0})))}_commitErrorInfo(t){this._errorInfo=t,this._target.dispatchEvent(new CustomEvent("wcs-worker:error-info-changed",{detail:t,bubbles:!0}))}_setRunning(t){this._running=t,this._target.dispatchEvent(new CustomEvent("wcs-worker:running-changed",{detail:t,bubbles:!0}))}start(t,e={}){t?this._worker&&this._src===t||(this._clearRestartTimer(),this._terminateWorker(),this._src=t,this._type=e.type??"module",this._name=e.name??"",this._restartOnError=e.restartOnError??!1,this._maxRestarts=e.maxRestarts??1/0,this._restartInterval=e.restartInterval??0,this._restartCount=0,this._setError(null),this._spawn()):this._setError({name:"TypeError",message:"src is required."})}post(t,e){if(!this._worker)return this._setError({name:"InvalidStateError",message:"Worker is not running. Call start(src) before post()."}),void this._warnNotReady();try{e&&e.length>0?this._worker.postMessage(t,e):this._worker.postMessage(t)}catch(t){this._setError(this._normalizeError(t)),this._warnUncloneable(t)}}_warnUncloneable(t){this._toldUncloneable||"DataCloneError"!==t?.name||(this._toldUncloneable=!0,console.warn("[@wcstack/worker] [wcs/post-uncloneable] post() was refused: the message cannot be structured-cloned (DataCloneError), so it is lost. It goes to `error` too. A framework's reactive proxy is the usual cause — Vue's toRaw() unwraps one level only: pass a deep plain copy (JSON.parse(JSON.stringify(value)), or toRaw on each level). (Said once per element.)",this._target))}_warnNotReady(){this._toldNotReady||(this._toldNotReady=!0,console.warn("[@wcstack/worker] [wcs/command-not-ready] post() was refused: no worker is running, so the message is lost. It goes to `error` too. Give the element a `src` (or call start(src)) first. (Said once until a worker starts again.)",this._target))}terminate(){this._clearRestartTimer(),this._terminateWorker()}dispose(){this._gen++,this._clearRestartTimer(),this._terminateWorker(),this._setError(null)}_spawn(){try{this._worker=new Worker(h(this._src),{type:this._type,name:this._name||void 0})}catch(t){return void this._setError(this._normalizeError(t))}this._worker.addEventListener("message",this._onMessage),this._worker.addEventListener("messageerror",this._onMessageError),this._worker.addEventListener("error",this._onError),this._toldNotReady=!1,this._setRunning(!0)}_onMessage=t=>{this._setMessage(t.data)};_onMessageError=()=>{this._setError({name:"DataError",message:"Failed to deserialize a message received from the worker."})};_onError=t=>{this._setError({name:"Error",message:t.message||"Worker script error.",filename:t.filename,lineno:t.lineno,colno:t.colno}),this._restartOnError&&this._restartCount<this._maxRestarts&&this._scheduleRestart()};_scheduleRestart(){this._clearRestartTimer();const t=this._gen;this._restartTimer=setTimeout(()=>{t===this._gen&&(this._restartTimer=null,this._restartCount++,this._terminateWorker(),this._setError(null),this._spawn())},this._restartInterval)}_clearRestartTimer(){null!==this._restartTimer&&(clearTimeout(this._restartTimer),this._restartTimer=null)}_terminateWorker(){this._worker&&(this._worker.removeEventListener("message",this._onMessage),this._worker.removeEventListener("messageerror",this._onMessageError),this._worker.removeEventListener("error",this._onError),this._worker.terminate(),this._worker=null,this._setRunning(!1))}_normalizeError(t){return t instanceof Error?{name:t.name,message:t.message}:{name:"Error",message:String(t)}}}let d=!1;const _="data-worker-text";function g(e){const r=e.target;if(!(r instanceof Element))return;const s=r.closest(`[${t.triggerAttribute}]`);if(!s)return;const n=s.getAttribute(t.triggerAttribute);if(!n)return;const a=customElements.get(t.tagNames.worker),o=document.getElementById(n);if(!(a&&o instanceof a))return;const i=function(t){if(t.hasAttribute(_))return t.getAttribute(_)??"";const e=t.getAttribute("data-worker-from");if(!e)return null;let r;try{r=document.querySelector(e)}catch{return null}return r?r instanceof HTMLInputElement||r instanceof HTMLTextAreaElement||r instanceof HTMLSelectElement?r.value:r.textContent??"":null}(s);null!==i&&(e.preventDefault(),o.post(i))}function p(t,e){let r=Object.getPrototypeOf(t);for(;null!==r;){const t=Object.getOwnPropertyDescriptor(r,e);if(void 0!==t)return"function"==typeof t.get||"function"==typeof t.set;r=Object.getPrototypeOf(r)}return!1}const w=new WeakSet;function f(t,e,r){if(w.has(t))return;w.add(t);const s=t.localName??"element";console.warn(`[wcs/input-as-attribute] <${s}> has the attribute ${e}="${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.)`,t)}const b=new WeakMap;function y(t,e){let r=b.get(t);return void 0===r&&(r=new Map,b.set(t,r)),r.has(e)||r.set(e,t.getAttribute(e)),r.get(e)}function k(t,e,r){null===r?t.removeAttribute(e):t.setAttribute(e,r)}function v(t,e,r){const s=y(t,e);k(t,e,void 0===r?s:null===r?null:String(r))}function E(t,e,r){const s=y(t,e);k(t,e,void 0===r?s:r?"":null)}class T extends HTMLElement{static hasConnectedCallbackPromise=!0;static wcBindable={...m.wcBindable,inputs:[{name:"src",attribute:"src"},{name:"type",attribute:"type"},{name:"name",attribute:"name"},{name:"manual",attribute:"manual"},{name:"keepAlive",attribute:"keep-alive"},{name:"restartOnError",attribute:"restart-on-error"},{name:"maxRestarts",attribute:"max-restarts"},{name:"restartInterval",attribute:"restart-interval"}],commands:m.wcBindable.commands};static get observedAttributes(){return["src"]}_core;_connectedCallbackPromise=Promise.resolve();_everConnected=!1;_startPending=!1;_internals=null;constructor(){super(),this._core=new m(this),this._internals=this._initInternals(),this._wireStates({"wcs-worker:running-changed":t=>({running:!0===t}),"wcs-worker:error":t=>({error:null!=t})})}get connectedCallbackPromise(){return this._connectedCallbackPromise}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[r,s]of Object.entries(t))this.addEventListener(r,t=>{const r=this.hasAttribute("debug-states");for(const[n,a]of Object.entries(s(t.detail))){try{a?e.add(n):e.delete(n)}catch{}r&&this.toggleAttribute(`data-wcs-state-${n}`,a)}})}get src(){return this.getAttribute("src")||""}set src(t){v(this,"src",t)}get type(){return"classic"===this.getAttribute("type")?"classic":"module"}set type(t){v(this,"type",t)}get name(){return this.getAttribute("name")||""}set name(t){v(this,"name",t)}get manual(){return this.hasAttribute("manual")}set manual(t){E(this,"manual",t)}get keepAlive(){return this.hasAttribute("keep-alive")}set keepAlive(t){E(this,"keep-alive",t)}get restartOnError(){return this.hasAttribute("restart-on-error")}set restartOnError(t){E(this,"restart-on-error",t)}get maxRestarts(){const t=this.getAttribute("max-restarts");if("Infinity"===t)return 1/0;const e=t?parseInt(t,10):1/0;return Number.isNaN(e)?1/0:e}set maxRestarts(t){v(this,"max-restarts",t)}get restartInterval(){const t=this.getAttribute("restart-interval"),e=t?parseInt(t,10):0;return Number.isNaN(e)?0:e}set restartInterval(t){v(this,"restart-interval",t)}get message(){return this._core.message}get error(){return this._core.error}get errorInfo(){return this._core.errorInfo}get running(){return this._core.running}start(){this._startPending=!1,this._core.start(this.src,{type:this.type,name:this.name,restartOnError:this.restartOnError,maxRestarts:this.maxRestarts,restartInterval:this.restartInterval})}post(t,e){this._core.post(t,e)}terminate(){this._startPending=!1,this._core.terminate()}attributeChangedCallback(t,e,r){"src"===t&&this.isConnected&&!this.manual&&r&&!this._startPending&&this.start()}_scheduleStart(){this._startPending||(this._startPending=!0,queueMicrotask(()=>{this._startPending&&(this._startPending=!1,this.isConnected&&!this.manual&&this.src&&this.start())}))}connectedCallback(){!function(t){const e=t.constructor?.wcBindable,r=e?.inputs;if(void 0===r)return;const s=t.getAttribute;for(const e of r){const r=e.name,n="function"==typeof s?s.call(t,r.toLowerCase()):null;if(null!==n&&n.startsWith("[object ")&&f(t,r,n),!Object.prototype.hasOwnProperty.call(t,r))continue;if(!p(t,r))continue;const a=t,o=a[r];delete a[r],a[r]=o}}(this),this.style.display="none",d||(d=!0,document.addEventListener("click",g)),this._connectedCallbackPromise=this._core.observe(),this._everConnected?this._scheduleStart():(this._everConnected=!0,!this.manual&&this.src&&this.start())}disconnectedCallback(){this.keepAlive||this._core.dispose()}}const R=Symbol.for("wcstack.package"),A=new WeakSet;function C(t,e){Object.defineProperty(t,R,{value:e,configurable:!0})}function I(t,e,r,s,n){if(void 0!==s&&(r===s||r.prototype instanceof s))return;const a=r[R];if(a===n||A.has(t))return;A.add(t);const o=n.slice(0,n.lastIndexOf("@"));console.warn(`[${o}] [wcs/package-twice] <${e}> is already defined by ${a??`another copy of ${o} that does not name its version`}; this copy, ${n}, does nothing. Load each package once.`)}function S(s=customElements){!function(t,e,r){for(const[s,n]of r){const r=t.get(s);void 0===r?(C(n,e),t.define(s,n)):I(t,s,r,n,e)}}(s,`${e}@${r}`,[[t.tagNames.worker,T]])}var P;S(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/worker",
|
|
3
|
-
"version": "4.
|
|
3
|
+
"version": "4.14.0",
|
|
4
4
|
"description": "Declarative Web Worker component for Web Components. Framework-agnostic Dedicated Worker primitive via wc-bindable-protocol.",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "./dist/index.esm.js",
|