"undefined"!=typeof globalThis?globalThis:"undefined"!=typeof window?window:"undefined"!=typeof global?global:"undefined"!=typeof self&&self;var e={},t={exports:{}};t.exports=(()=>{var e={162:function(e,t,r){var n=this&&this.__createBinding||(Object.create?function(e,t,r,n){void 0===n&&(n=r),Object.defineProperty(e,n,{enumerable:!0,get:function(){return t[r]}})}:function(e,t,r,n){void 0===n&&(n=r),e[n]=t[r]}),a=this&&this.__setModuleDefault||(Object.create?function(e,t){Object.defineProperty(e,"default",{enumerable:!0,value:t})}:function(e,t){e.default=t}),o=this&&this.__importStar||function(e){if(e&&e.__esModule)return e;var t={};if(null!=e)for(var r in e)"default"!==r&&Object.prototype.hasOwnProperty.call(e,r)&&n(t,e,r);return a(t,e),t};Object.defineProperty(t,"__esModule",{value:!0}),t.createDbWorker=void 0;const i=o(r(375));async function s(e){if(e.data&&"eval"===e.data.action){const t=new Int32Array(e.data.notify,0,2),r=new Uint8Array(e.data.notify,8);let n;try{n={ok:await u(e.data.request)}}catch(t){console.error("worker request error",e.data.request,t),n={err:String(t)}}const a=(new TextEncoder).encode(JSON.stringify(n));r.set(a,0),t[1]=a.length,Atomics.notify(t,0)}}function l(e){if("BODY"===e.tagName)return"body";const t=[];for(;e.parentElement&&"BODY"!==e.tagName;){if(e.id){t.unshift("#"+e.id);break}{let r=1,n=e;for(;n.previousElementSibling;)n=n.previousElementSibling,r++;t.unshift(e.tagName.toLowerCase()+":nth-child("+r+")")}e=e.parentElement}return t.join(" > ")}function c(e){return Object.keys(e)}async function u(e){if(console.log("dom vtable request",e),"select"===e.type)return[...document.querySelectorAll(e.selector)].map((t=>{const r={};for(const n of e.columns)"selector"===n?r.selector=l(t):"parent"===n?t.parentElement&&(r.parent=t.parentElement?l(t.parentElement):null):"idx"===n||(r[n]=t[n]);return r}));if("insert"===e.type){if(!e.value.parent)throw Error('"parent" column must be set when inserting');const t=document.querySelectorAll(e.value.parent);if(0===t.length)throw Error(`Parent element ${e.value.parent} could not be found`);if(t.length>1)throw Error(`Parent element ${e.value.parent} ambiguous (${t.length} results)`);const r=t[0];if(!e.value.tagName)throw Error("tagName must be set for inserting");const n=document.createElement(e.value.tagName);for(const t of c(e.value))if(null!==e.value[t]){if("tagName"===t||"parent"===t)continue;if("idx"===t||"selector"===t)throw Error(`${t} can't be set`);n[t]=e.value[t]}return r.appendChild(n),null}if("update"===e.type){const t=document.querySelector(e.value.selector);if(!t)throw Error(`Element ${e.value.selector} not found!`);const r=[];for(const n of c(e.value)){const a=e.value[n];if("parent"!==n){if("idx"!==n&&"selector"!==n&&a!==t[n]){if(console.log("SETTING ",n,t[n],"->",a),"tagName"===n)throw Error("can't change tagName");r.push(n)}}else if(a!==l(t.parentElement)){const e=document.querySelectorAll(a);if(1!==e.length)throw Error(`Invalid target parent: found ${e.length} matches`);e[0].appendChild(t)}}for(const n of r)t[n]=e.value[n];return null}throw Error(`unknown request ${e.type}`)}i.transferHandlers.set("WORKERSQLPROXIES",{canHandle:e=>!1,serialize(e){throw Error("no")},deserialize:e=>(e.start(),i.wrap(e))}),t.createDbWorker=async function(e,t,r,n=1/0){const a=new Worker(t),o=i.wrap(a),l=await o.SplitFileHttpDatabase(r,e,void 0,n);return a.addEventListener("message",s),{db:l,worker:o,configs:e}}},432:function(e,t,r){var n=this&&this.__createBinding||(Object.create?function(e,t,r,n){void 0===n&&(n=r),Object.defineProperty(e,n,{enumerable:!0,get:function(){return t[r]}})}:function(e,t,r,n){void 0===n&&(n=r),e[n]=t[r]}),a=this&&this.__exportStar||function(e,t){for(var r in e)"default"===r||Object.prototype.hasOwnProperty.call(t,r)||n(t,e,r)};Object.defineProperty(t,"__esModule",{value:!0}),a(r(162),t)},375:(e,t,r)=>{r.r(t),r.d(t,{createEndpoint:()=>a,expose:()=>c,proxy:()=>g,proxyMarker:()=>n,releaseProxy:()=>o,transfer:()=>b,transferHandlers:()=>l,windowEndpoint:()=>v,wrap:()=>d});const n=Symbol("Comlink.proxy"),a=Symbol("Comlink.endpoint"),o=Symbol("Comlink.releaseProxy"),i=Symbol("Comlink.thrown"),s=e=>"object"==typeof e&&null!==e||"function"==typeof e,l=new Map([["proxy",{canHandle:e=>s(e)&&e[n],serialize(e){const{port1:t,port2:r}=new MessageChannel;return c(e,t),[r,[r]]},deserialize:e=>(e.start(),d(e))}],["throw",{canHandle:e=>s(e)&&i in e,serialize({value:e}){let t;return t=e instanceof Error?{isError:!0,value:{message:e.message,name:e.name,stack:e.stack}}:{isError:!1,value:e},[t,[]]},deserialize(e){if(e.isError)throw Object.assign(new Error(e.value.message),e.value);throw e.value}}]]);function c(e,t=self){t.addEventListener("message",(function r(n){if(!n||!n.data)return;const{id:a,type:o,path:s}=Object.assign({path:[]},n.data),l=(n.data.argumentList||[]).map(E);let d;try{const t=s.slice(0,-1).reduce(((e,t)=>e[t]),e),r=s.reduce(((e,t)=>e[t]),e);switch(o){case"GET":d=r;break;case"SET":t[s.slice(-1)[0]]=E(n.data.value),d=!0;break;case"APPLY":d=r.apply(t,l);break;case"CONSTRUCT":d=g(new r(...l));break;case"ENDPOINT":{const{port1:t,port2:r}=new MessageChannel;c(e,r),d=b(t,[t])}break;case"RELEASE":d=void 0;break;default:return}}catch(e){d={value:e,[i]:0}}Promise.resolve(d).catch((e=>({value:e,[i]:0}))).then((e=>{const[n,i]=h(e);t.postMessage(Object.assign(Object.assign({},n),{id:a}),i),"RELEASE"===o&&(t.removeEventListener("message",r),u(t))}))})),t.start&&t.start()}function u(e){(function(e){return"MessagePort"===e.constructor.name})(e)&&e.close()}function d(e,t){return p(e,[],t)}function f(e){if(e)throw new Error("Proxy has been released and is not useable")}function p(e,t=[],r=function(){}){let n=!1;const i=new Proxy(r,{get(r,a){if(f(n),a===o)return()=>w(e,{type:"RELEASE",path:t.map((e=>e.toString()))}).then((()=>{u(e),n=!0}));if("then"===a){if(0===t.length)return{then:()=>i};const r=w(e,{type:"GET",path:t.map((e=>e.toString()))}).then(E);return r.then.bind(r)}return p(e,[...t,a])},set(r,a,o){f(n);const[i,s]=h(o);return w(e,{type:"SET",path:[...t,a].map((e=>e.toString())),value:i},s).then(E)},apply(r,o,i){f(n);const s=t[t.length-1];if(s===a)return w(e,{type:"ENDPOINT"}).then(E);if("bind"===s)return p(e,t.slice(0,-1));const[l,c]=m(i);return w(e,{type:"APPLY",path:t.map((e=>e.toString())),argumentList:l},c).then(E)},construct(r,a){f(n);const[o,i]=m(a);return w(e,{type:"CONSTRUCT",path:t.map((e=>e.toString())),argumentList:o},i).then(E)}});return i}function m(e){const t=e.map(h);return[t.map((e=>e[0])),(r=t.map((e=>e[1])),Array.prototype.concat.apply([],r))];var r}const y=new WeakMap;function b(e,t){return y.set(e,t),e}function g(e){return Object.assign(e,{[n]:!0})}function v(e,t=self,r="*"){return{postMessage:(t,n)=>e.postMessage(t,r,n),addEventListener:t.addEventListener.bind(t),removeEventListener:t.removeEventListener.bind(t)}}function h(e){for(const[t,r]of l)if(r.canHandle(e)){const[n,a]=r.serialize(e);return[{type:"HANDLER",name:t,value:n},a]}return[{type:"RAW",value:e},y.get(e)||[]]}function E(e){switch(e.type){case"HANDLER":return l.get(e.name).deserialize(e.value);case"RAW":return e.value}}function w(e,t,r){return new Promise((n=>{const a=new Array(4).fill(0).map((()=>Math.floor(Math.random()*Number.MAX_SAFE_INTEGER).toString(16))).join("-");e.addEventListener("message",(function t(r){r.data&&r.data.id&&r.data.id===a&&(e.removeEventListener("message",t),n(r.data))})),e.start&&e.start(),e.postMessage(Object.assign({id:a},t),r)}))}}},t={};function r(n){var a=t[n];if(void 0!==a)return a.exports;var o=t[n]={exports:{}};return e[n].call(o.exports,o,o.exports,r),o.exports}return r.d=(e,t)=>{for(var n in t)r.o(t,n)&&!r.o(e,n)&&Object.defineProperty(e,n,{enumerable:!0,get:t[n]})},r.o=(e,t)=>Object.prototype.hasOwnProperty.call(e,t),r.r=e=>{"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(e,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(e,"__esModule",{value:!0})},r(432)})(),Object.defineProperty(e,"__esModule",{value:!0});var r=e.isInitialized=e.execQuery=e.createUrlDbWorker=e.createBundledDbWorker=void 0;const n=t.exports;let a=null;var o=e.createBundledDbWorker=async function(e,t,r){const o=URL.createObjectURL(new Blob([t])),i=new Blob([r],{type:"application/wasm"}),s=URL.createObjectURL(i);a=await(0,n.createDbWorker)(e,o.toString(),s.toString())};var i=e.createUrlDbWorker=async function(e,t,r){a=await(0,n.createDbWorker)(e,t,r)};var s=e.execQuery=function(e){return null!==a?a.db.query(e):Promise.reject(new Error("Global worker is undefined."))};r=e.isInitialized=function(){return null!==a};export{o as createBundledDbWorker,i as createUrlDbWorker,e as default,s as execQuery,r as isInitialized};