UNPKG

rvx

Version:

A signal based rendering library

2 lines (1 loc) 1.88 kB
import{View as t,ENV as n,uncapture as r,captureSelf as e,viewNodes as o}from"./rvx.min.js";import{Queue as i,AsyncContext as s,ASYNC as a}from"./rvx.async.min.js";function f(r){if(!(r instanceof t))throw new Error("view is not a View");const e=n.current;if(!(r.first instanceof e.Node))throw new Error("view.first is not a Node");if(!(r.last instanceof e.Node))throw new Error("view.last is not a Node");if(r.first!==r.last){if(!(r.first.parentNode instanceof e.Node))throw new Error("view.first.parent is not a Node");let t=r.first.nextSibling;t:for(;;){if(null===t)throw new Error("view is unterminated");if(!(t instanceof e.Node))throw new Error("view contains non-Node");if(t===r.last)break t;t=t.nextSibling}}}class c extends Error{}async function l(t,n){const r=new AbortController;let e;void 0!==n&&(e=setTimeout(()=>r.abort(new c),n));try{for(;;){const n=await t(r.signal);if(n)return n;r.signal.throwIfAborted(),await new Promise(t=>setTimeout(t,0))}}finally{clearTimeout(e)}}const u=Symbol.for("rvx:test:queues"),w=globalThis[u]??(globalThis[u]=new Map);function h(t,n){let e=w.get(t);return void 0===e&&(e=r(()=>new i),w.set(t,e)),e.block(n)}async function d(t){const n=[],r=new s;async function o(){for(let t=n.length-1;t>=0;t--)n[t]();return r.complete()}try{const i=await t({asyncCtx:r,use:t=>e(e=>(n.push(e),a.inject(r,t)))});return await o(),i}catch(t){try{await o()}catch{}throw t}}function y(t){return e(n=>{try{return t()}finally{n()}})}function m(t,n){for(const r of o(t))if(1===r.nodeType){if(r.matches(n))return r;const t=r.querySelector(n);if(null!==t)return t}return null}function p(t,n){const r=[];for(const e of o(t))1===e.nodeType&&(e.matches(n)&&r.push(e),r.push(...e.querySelectorAll(n)));return r}export{c as PollTimeoutError,f as assertViewState,h as exclusive,l as poll,m as querySelector,p as querySelectorAll,d as runAsyncTest,y as runTest};