Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

@observablehq/stdlib

Package Overview
Dependencies
Maintainers
5
Versions
117
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@observablehq/stdlib - npm Package Compare versions

Comparing version 5.0.2 to 5.1.0

4

dist/stdlib.js

@@ -1,2 +0,2 @@

// @observablehq/stdlib v5.0.2 Copyright 2022 Observable, Inc.
!function(e,t){"object"==typeof exports&&"undefined"!=typeof module?t(exports):"function"==typeof define&&define.amd?define(["exports"],t):t((e="undefined"!=typeof globalThis?globalThis:e||self).observablehq=e.observablehq||{})}(this,(function(e){"use strict";var t={},n={};function r(e){return new Function("d","return {"+e.map((function(e,t){return JSON.stringify(e)+": d["+t+'] || ""'})).join(",")+"}")}function a(e){var t=Object.create(null),n=[];return e.forEach((function(e){for(var r in e)r in t||n.push(t[r]=r)})),n}function o(e,t){var n=e+"",r=n.length;return r<t?new Array(t-r+1).join(0)+n:n}function i(e){var t,n=e.getUTCHours(),r=e.getUTCMinutes(),a=e.getUTCSeconds(),i=e.getUTCMilliseconds();return isNaN(e)?"Invalid Date":((t=e.getUTCFullYear())<0?"-"+o(-t,6):t>9999?"+"+o(t,6):o(t,4))+"-"+o(e.getUTCMonth()+1,2)+"-"+o(e.getUTCDate(),2)+(i?"T"+o(n,2)+":"+o(r,2)+":"+o(a,2)+"."+o(i,3)+"Z":a?"T"+o(n,2)+":"+o(r,2)+":"+o(a,2)+"Z":r||n?"T"+o(n,2)+":"+o(r,2)+"Z":"")}function s(e){var o=new RegExp('["'+e+"\n\r]"),s=e.charCodeAt(0);function c(e,r){var a,o=[],i=e.length,c=0,l=0,u=i<=0,f=!1;function d(){if(u)return n;if(f)return f=!1,t;var r,a,o=c;if(34===e.charCodeAt(o)){for(;c++<i&&34!==e.charCodeAt(c)||34===e.charCodeAt(++c););return(r=c)>=i?u=!0:10===(a=e.charCodeAt(c++))?f=!0:13===a&&(f=!0,10===e.charCodeAt(c)&&++c),e.slice(o+1,r-1).replace(/""/g,'"')}for(;c<i;){if(10===(a=e.charCodeAt(r=c++)))f=!0;else if(13===a)f=!0,10===e.charCodeAt(c)&&++c;else if(a!==s)continue;return e.slice(o,r)}return u=!0,e.slice(o,i)}for(10===e.charCodeAt(i-1)&&--i,13===e.charCodeAt(i-1)&&--i;(a=d())!==n;){for(var m=[];a!==t&&a!==n;)m.push(a),a=d();r&&null==(m=r(m,l++))||o.push(m)}return o}function l(t,n){return t.map((function(t){return n.map((function(e){return f(t[e])})).join(e)}))}function u(t){return t.map(f).join(e)}function f(e){return null==e?"":e instanceof Date?i(e):o.test(e+="")?'"'+e.replace(/"/g,'""')+'"':e}return{parse:function(e,t){var n,a,o=c(e,(function(e,o){if(n)return n(e,o-1);a=e,n=t?function(e,t){var n=r(e);return function(r,a){return t(n(r),a,e)}}(e,t):r(e)}));return o.columns=a||[],o},parseRows:c,format:function(t,n){return null==n&&(n=a(t)),[n.map(f).join(e)].concat(l(t,n)).join("\n")},formatBody:function(e,t){return null==t&&(t=a(e)),l(e,t).join("\n")},formatRows:function(e){return e.map(u).join("\n")},formatRow:u,formatValue:f}}var c=s(","),l=c.parse,u=c.parseRows,f=s("\t"),d=f.parse,m=f.parseRows;function h(e){for(var t in e){var n,r,a=e[t].trim();if(a)if("true"===a)a=!0;else if("false"===a)a=!1;else if("NaN"===a)a=NaN;else if(isNaN(n=+a)){if(!(r=a.match(/^([-+]\d{2})?\d{4}(-\d{2}(-\d{2})?)?(T\d{2}:\d{2}(:\d{2}(\.\d{3})?)?(Z|[-+]\d{2}:\d{2})?)?$/)))continue;p&&r[4]&&!r[7]&&(a=a.replace(/-/g,"/").replace(/T/," ")),a=new Date(a)}else a=n;else a=null;e[t]=a}return e}const p=new Date("2019-01-01T00:00").getHours()||new Date("2019-07-01T00:00").getHours();function w(e,t,n){return{resolve:(r=n)=>`${e}@${t}/${r}`}}const b=w("d3","7.6.1","dist/d3.min.js"),y=w("@observablehq/inputs","0.10.4","dist/inputs.min.js"),v=w("@observablehq/plot","0.6.0","dist/plot.umd.min.js"),g=w("@observablehq/graphviz","0.2.1","dist/graphviz.min.js"),E=w("@observablehq/highlight.js","2.0.0","highlight.min.js"),T=w("@observablehq/katex","0.11.1","dist/katex.min.js"),A=w("lodash","4.17.21","lodash.min.js"),j=w("htl","0.3.1","dist/htl.min.js"),x=w("jszip","3.10.0","dist/jszip.min.js"),N=w("marked","0.3.12","marked.min.js"),C=w("sql.js","1.7.0","dist/sql-wasm.js"),O=w("vega","5.22.1","build/vega.min.js"),k=w("vega-lite","5.5.0","build/vega-lite.min.js"),q=w("vega-lite-api","5.0.0","build/vega-lite-api.min.js"),$=w("apache-arrow","4.0.1","Arrow.es2015.min.js"),L=w("apache-arrow","9.0.0","+esm"),R=w("arquero","4.8.8","dist/arquero.min.js"),I=w("topojson-client","3.1.0","dist/topojson-client.min.js"),S=w("exceljs","4.3.0","dist/exceljs.min.js"),P=w("mermaid","9.1.6","dist/mermaid.min.js"),M=w("leaflet","1.8.0","dist/leaflet.js"),U=w("@duckdb/duckdb-wasm","1.17.0","+esm"),_=new Map,D=[],F=D.map,B=D.some,W=D.hasOwnProperty,H=/^((?:@[^/@]+\/)?[^/@]+)(?:@([^/]+))?(?:\/(.*))?$/,z=/^\d+\.\d+\.\d+(-[\w-.+]+)?$/,G=/(?:\.[^/]*|\/)$/;class RequireError extends Error{constructor(e){super(e)}}function V(e){const t=H.exec(e);return t&&{name:t[1],version:t[2],path:t[3]}}function Y(e="https://cdn.jsdelivr.net/npm/",t=["unpkg","jsdelivr","browser","main"]){if(!/\/$/.test(e))throw new Error("origin lacks trailing slash");function n(t){const n=`${e}${t.name}${t.version?`@${t.version}`:""}/package.json`;let r=_.get(n);return r||_.set(n,r=fetch(n).then((e=>{if(!e.ok)throw new RequireError("unable to load package.json");return e.redirected&&!_.has(e.url)&&_.set(e.url,r),e.json()}))),r}return async function(r,a){if(r.startsWith(e)&&(r=r.substring(e.length)),/^(\w+:)|\/\//i.test(r))return r;if(/^[.]{0,2}\//i.test(r))return new URL(r,null==a?location:a).href;if(!r.length||/^[\s._]/.test(r)||/\s$/.test(r))throw new RequireError("illegal name");const o=V(r);if(!o)return`${e}${r}`;if(!o.version&&null!=a&&a.startsWith(e)){const t=await n(V(a.substring(e.length)));o.version=t.dependencies&&t.dependencies[o.name]||t.peerDependencies&&t.peerDependencies[o.name]}if(o.path&&!G.test(o.path)&&(o.path+=".js"),o.path&&o.version&&z.test(o.version))return`${e}${o.name}@${o.version}/${o.path}`;const i=await n(o);return`${e}${i.name}@${i.version}/${o.path||function(e){for(const n of t){let t=e[n];if("string"==typeof t)return t.startsWith("./")&&(t=t.slice(2)),G.test(t)?t:`${t}.js`}}(i)||"index.js"}`}}RequireError.prototype.name=RequireError.name;var Z=J(Y());function J(e){const t=new Map,n=a(null);function r(e){if("string"!=typeof e)return e;let n=t.get(e);return n||t.set(e,n=new Promise(((t,n)=>{const r=document.createElement("script");r.onload=()=>{try{t(D.pop()(a(e)))}catch(e){n(new RequireError("invalid module"))}r.remove()},r.onerror=()=>{n(new RequireError("unable to load module")),r.remove()},r.async=!0,r.src=e,window.define=ee,document.head.appendChild(r)}))),n}function a(t){return n=>Promise.resolve(e(n,t)).then(r)}function o(e){return arguments.length>1?Promise.all(F.call(arguments,n)).then(Q):n(e)}return o.alias=function(t){return J(((n,r)=>n in t&&(r=null,"string"!=typeof(n=t[n]))?n:e(n,r)))},o.resolve=e,o}function Q(e){const t={};for(const n of e)for(const e in n)W.call(n,e)&&(null==n[e]?Object.defineProperty(t,e,{get:X(n,e)}):t[e]=n[e]);return t}function X(e,t){return()=>e[t]}function K(e){return"exports"===(e+="")||"module"===e}function ee(e,t,n){const r=arguments.length;r<2?(n=e,t=[]):r<3&&(n=t,t="string"==typeof e?[]:e),D.push(B.call(t,K)?e=>{const r={},a={exports:r};return Promise.all(F.call(t,(t=>"exports"===(t+="")?r:"module"===t?a:e(t)))).then((e=>(n.apply(null,e),a.exports)))}:e=>Promise.all(F.call(t,e)).then((e=>"function"==typeof n?n.apply(null,e):n)))}ee.amd={};const te="https://cdn.observableusercontent.com/npm/";let ne=Z;async function re(e){const[t,n]=await Promise.all([e(C.resolve()),e.resolve(C.resolve("dist/"))]);return t({locateFile:e=>`${n}${e}`})}class SQLiteDatabaseClient{constructor(e){Object.defineProperties(this,{_db:{value:e}})}static async open(e){const[t,n]=await Promise.all([re(ne),Promise.resolve(e).then(oe)]);return new SQLiteDatabaseClient(new t.Database(n))}async query(e,t){return await async function(e,t,n){const[r]=await e.exec(t,n);if(!r)return[];const{columns:a,values:o}=r,i=o.map((e=>Object.fromEntries(e.map(((e,t)=>[a[t],e])))));return i.columns=a,i}(this._db,e,t)}async queryRow(e,t){return(await this.query(e,t))[0]||null}async explain(e,t){return ie("pre",{className:"observablehq--inspect"},[se((await this.query(`EXPLAIN QUERY PLAN ${e}`,t)).map((e=>e.detail)).join("\n"))])}async describeTables({schema:e}={}){return this.query(`SELECT NULLIF(schema, 'main') AS schema, name FROM pragma_table_list() WHERE type = 'table'${null==e?"":" AND schema = ?"} AND name NOT LIKE 'sqlite_%'`,null==e?[]:[e])}async describeColumns({schema:e,table:t}={}){if(null==t)throw new Error("missing table");const n=await this.query(`SELECT name, type, "notnull" FROM pragma_table_info(?${null==e?"":", ?"}) ORDER BY cid`,null==e?[t]:[t,e]);if(!n.length)throw new Error(`table not found: ${t}`);return n.map((({name:e,type:t,notnull:n})=>({name:e,type:ae(t),databaseType:t,nullable:!n})))}async describe(e){const t=await(void 0===e?this.query("SELECT name FROM sqlite_master WHERE type = 'table'"):this.query("SELECT * FROM pragma_table_info(?)",[e]));if(!t.length)throw new Error("Not found");const{columns:n}=t;return ie("table",{value:t},[ie("thead",[ie("tr",n.map((e=>ie("th",[se(e)]))))]),ie("tbody",t.map((e=>ie("tr",n.map((t=>ie("td",[se(e[t])])))))))])}async sql(){return this.query(...this.queryTag.apply(this,arguments))}queryTag(e,...t){return[e.join("?"),t]}}function ae(e){switch(e){case"NULL":return"null";case"INT":case"INTEGER":case"TINYINT":case"SMALLINT":case"MEDIUMINT":case"BIGINT":case"UNSIGNED BIG INT":case"INT2":case"INT8":return"integer";case"TEXT":case"CLOB":case"DATE":case"DATETIME":return"string";case"REAL":case"DOUBLE":case"DOUBLE PRECISION":case"FLOAT":case"NUMERIC":return"number";case"BLOB":return"buffer";default:return/^(?:(?:(?:VARYING|NATIVE) )?CHARACTER|(?:N|VAR|NVAR)CHAR)\(/.test(e)?"string":/^(?:DECIMAL|NUMERIC)\(/.test(e)?"number":"other"}}function oe(e){return"string"==typeof e?fetch(e).then(oe):e instanceof Response||e instanceof Blob?e.arrayBuffer().then(oe):e instanceof ArrayBuffer?new Uint8Array(e):e}function ie(e,t,n){2===arguments.length&&(n=t,t=void 0);const r=document.createElement(e);if(void 0!==t)for(const e in t)r[e]=t[e];if(void 0!==n)for(const e of n)r.appendChild(e);return r}function se(e){return document.createTextNode(e)}Object.defineProperty(SQLiteDatabaseClient.prototype,"dialect",{value:"sqlite"});class Workbook{constructor(e){Object.defineProperties(this,{_:{value:e},sheetNames:{value:e.worksheets.map((e=>e.name)),enumerable:!0}})}sheet(e,t){const n="number"==typeof e?this.sheetNames[e]:this.sheetNames.includes(e+="")?e:null;if(null==n)throw new Error(`Sheet not found: ${e}`);return function(e,{range:t,headers:n}={}){let[[r,a],[o,i]]=function(e=":",{columnCount:t,rowCount:n}){if(!(e+="").match(/^[A-Z]*\d*:[A-Z]*\d*$/))throw new Error("Malformed range specifier");const[[r=0,a=0],[o=t-1,i=n-1]]=e.split(":").map(fe);return[[r,a],[o,i]]}(t,e);const s=n?e._rows[a++]:null;let c=new Set(["#"]);for(let e=r;e<=o;e++){const t=s?ce(s.findCell(e+1)):null;let n=t&&t+""||ue(e);for(;c.has(n);)n+="_";c.add(n)}c=new Array(r).concat(Array.from(c));const l=new Array(i-a+1);for(let t=a;t<=i;t++){const n=l[t-a]=Object.create(null,{"#":{value:t+1}}),i=e.getRow(t+1);if(i.hasValues)for(let e=r;e<=o;e++){const t=ce(i.findCell(e+1));null!=t&&(n[c[e+1]]=t)}}return l.columns=c.filter((()=>!0)),l}(this._.getWorksheet(n),t)}}function ce(e){if(!e)return;const{value:t}=e;if(t&&"object"==typeof t&&!(t instanceof Date)){if(t.formula||t.sharedFormula)return t.result&&t.result.error?NaN:t.result;if(t.richText)return le(t);if(t.text){let{text:e}=t;return e.richText&&(e=le(e)),t.hyperlink&&t.hyperlink!==e?`${t.hyperlink} ${e}`:e}return t}return t}function le(e){return e.richText.map((e=>e.text)).join("")}function ue(e){let t="";e++;do{t=String.fromCharCode(64+(e%26||26))+t}while(e=Math.floor((e-1)/26));return t}function fe(e){const[,t,n]=e.match(/^([A-Z]*)(\d*)$/);let r=0;if(t)for(let e=0;e<t.length;e++)r+=Math.pow(26,t.length-e-1)*(t.charCodeAt(e)-64);return[r?r-1:void 0,n?+n-1:void 0]}async function de(e){const t=await fetch(await e.url());if(!t.ok)throw new Error(`Unable to load file: ${e.name}`);return t}async function me(e,t,{array:n=!1,typed:r=!1}={}){const a=await e.text();return("\t"===t?n?m:d:n?u:l)(a,r&&h)}class he{constructor(e,t){Object.defineProperty(this,"name",{value:e,enumerable:!0}),void 0!==t&&Object.defineProperty(this,"mimeType",{value:t+"",enumerable:!0})}async blob(){return(await de(this)).blob()}async arrayBuffer(){return(await de(this)).arrayBuffer()}async text(){return(await de(this)).text()}async json(){return(await de(this)).json()}async stream(){return(await de(this)).body}async csv(e){return me(this,",",e)}async tsv(e){return me(this,"\t",e)}async image(e){const t=await this.url();return new Promise(((n,r)=>{const a=new Image;new URL(t,document.baseURI).origin!==new URL(location).origin&&(a.crossOrigin="anonymous"),Object.assign(a,e),a.onload=()=>n(a),a.onerror=()=>r(new Error(`Unable to load file: ${this.name}`)),a.src=t}))}async arrow({version:e=4}={}){switch(e){case 4:{const[e,t]=await Promise.all([ne($.resolve()),de(this)]);return e.Table.from(t)}case 9:{const[e,t]=await Promise.all([import(`${te}${L.resolve()}`),de(this)]);return e.tableFromIPC(t)}default:throw new Error(`unsupported arrow version: ${e}`)}}async sqlite(){return SQLiteDatabaseClient.open(de(this))}async zip(){const[e,t]=await Promise.all([ne(x.resolve()),this.arrayBuffer()]);return new ZipArchive(await e.loadAsync(t))}async xml(e="application/xml"){return(new DOMParser).parseFromString(await this.text(),e)}async html(){return this.xml("text/html")}async xlsx(){const[e,t]=await Promise.all([ne(S.resolve()),this.arrayBuffer()]);return new Workbook(await(new e.Workbook).xlsx.load(t))}}class FileAttachment extends he{constructor(e,t,n){super(t,n),Object.defineProperty(this,"_url",{value:e})}async url(){return await this._url+""}}function pe(e){throw new Error(`File not found: ${e}`)}class ZipArchive{constructor(e){Object.defineProperty(this,"_",{value:e}),this.filenames=Object.keys(e.files).filter((t=>!e.files[t].dir))}file(e){const t=this._.file(e+="");if(!t||t.dir)throw new Error(`file not found: ${e}`);return new ZipArchiveEntry(t)}}class ZipArchiveEntry extends he{constructor(e){super(e.name),Object.defineProperty(this,"_",{value:e}),Object.defineProperty(this,"_url",{writable:!0})}async url(){return this._url||(this._url=this.blob().then(URL.createObjectURL))}async blob(){return this._.async("blob")}async arrayBuffer(){return this._.async("arraybuffer")}async text(){return this._.async("text")}async json(){return JSON.parse(await this.text())}}var we={math:"http://www.w3.org/1998/Math/MathML",svg:"http://www.w3.org/2000/svg",xhtml:"http://www.w3.org/1999/xhtml",xlink:"http://www.w3.org/1999/xlink",xml:"http://www.w3.org/XML/1998/namespace",xmlns:"http://www.w3.org/2000/xmlns/"};var be=0;function ye(e){return new ve("O-"+(null==e?"":e+"-")+ ++be)}function ve(e){this.id=e,this.href=new URL(`#${e}`,location)+""}ve.prototype.toString=function(){return"url("+this.href+")"};var ge=Object.freeze({__proto__:null,canvas:function(e,t){var n=document.createElement("canvas");return n.width=e,n.height=t,n},context2d:function(e,t,n){null==n&&(n=devicePixelRatio);var r=document.createElement("canvas");r.width=e*n,r.height=t*n,r.style.width=e+"px";var a=r.getContext("2d");return a.scale(n,n),a},download:function(e,t="untitled",n="Save"){const r=document.createElement("a"),a=r.appendChild(document.createElement("button"));async function o(){await new Promise(requestAnimationFrame),URL.revokeObjectURL(r.href),r.removeAttribute("href"),a.textContent=n,a.disabled=!1}return a.textContent=n,r.download=t,r.onclick=async t=>{if(a.disabled=!0,r.href)return o();a.textContent="Saving…";try{const t=await("function"==typeof e?e():e);a.textContent="Download",r.href=URL.createObjectURL(t)}catch(e){a.textContent=n}if(t.eventPhase)return o();a.disabled=!1},r},element:function(e,t){var n,r=e+="",a=r.indexOf(":");a>=0&&"xmlns"!==(r=e.slice(0,a))&&(e=e.slice(a+1));var o=we.hasOwnProperty(r)?document.createElementNS(we[r],e):document.createElement(e);if(t)for(var i in t)a=(r=i).indexOf(":"),n=t[i],a>=0&&"xmlns"!==(r=i.slice(0,a))&&(i=i.slice(a+1)),we.hasOwnProperty(r)?o.setAttributeNS(we[r],i,n):o.setAttribute(i,n);return o},input:function(e){var t=document.createElement("input");return null!=e&&(t.type=e),t},range:function(e,t,n){1===arguments.length&&(t=e,e=null);var r=document.createElement("input");return r.min=e=null==e?0:+e,r.max=t=null==t?1:+t,r.step=null==n?"any":n=+n,r.type="range",r},select:function(e){var t=document.createElement("select");return Array.prototype.forEach.call(e,(function(e){var n=document.createElement("option");n.value=n.textContent=e,t.appendChild(n)})),t},svg:function(e,t){var n=document.createElementNS("http://www.w3.org/2000/svg","svg");return n.setAttribute("viewBox",[0,0,e,t]),n.setAttribute("width",e),n.setAttribute("height",t),n},text:function(e){return document.createTextNode(e)},uid:ye});var Ee=Object.freeze({__proto__:null,buffer:function(e){return new Promise((function(t,n){var r=new FileReader;r.onload=function(){t(r.result)},r.onerror=n,r.readAsArrayBuffer(e)}))},text:function(e){return new Promise((function(t,n){var r=new FileReader;r.onload=function(){t(r.result)},r.onerror=n,r.readAsText(e)}))},url:function(e){return new Promise((function(t,n){var r=new FileReader;r.onload=function(){t(r.result)},r.onerror=n,r.readAsDataURL(e)}))}});function Te(){return this}function Ae(e,t){let n=!1;if("function"!=typeof t)throw new Error("dispose is not a function");return{[Symbol.iterator]:Te,next:()=>n?{done:!0}:(n=!0,{done:!1,value:e}),return:()=>(n=!0,t(e),{done:!0}),throw:()=>({done:n=!0})}}function je(e){let t,n,r=!1;const a=e((function(e){n?(n(e),n=null):r=!0;return t=e}));if(null!=a&&"function"!=typeof a)throw new Error("function"==typeof a.then?"async initializers are not supported":"initializer returned something, but not a dispose function");return{[Symbol.iterator]:Te,throw:()=>({done:!0}),return:()=>(null!=a&&a(),{done:!0}),next:function(){return{done:!1,value:r?(r=!1,Promise.resolve(t)):new Promise((e=>n=e))}}}}function xe(e){switch(e.type){case"range":case"number":return e.valueAsNumber;case"date":return e.valueAsDate;case"checkbox":return e.checked;case"file":return e.multiple?e.files:e.files[0];case"select-multiple":return Array.from(e.selectedOptions,(e=>e.value));default:return e.value}}var Ne=Object.freeze({__proto__:null,disposable:Ae,filter:function*(e,t){for(var n,r=-1;!(n=e.next()).done;)t(n.value,++r)&&(yield n.value)},input:function(e){return je((function(t){var n=function(e){switch(e.type){case"button":case"submit":case"checkbox":return"click";case"file":return"change";default:return"input"}}(e),r=xe(e);function a(){t(xe(e))}return e.addEventListener(n,a),void 0!==r&&t(r),function(){e.removeEventListener(n,a)}}))},map:function*(e,t){for(var n,r=-1;!(n=e.next()).done;)yield t(n.value,++r)},observe:je,queue:function(e){let t;const n=[],r=e((function(e){n.push(e),t&&(t(n.shift()),t=null);return e}));if(null!=r&&"function"!=typeof r)throw new Error("function"==typeof r.then?"async initializers are not supported":"initializer returned something, but not a dispose function");return{[Symbol.iterator]:Te,throw:()=>({done:!0}),return:()=>(null!=r&&r(),{done:!0}),next:function(){return{done:!1,value:n.length?Promise.resolve(n.shift()):new Promise((e=>t=e))}}}},range:function*(e,t,n){e=+e,t=+t,n=(a=arguments.length)<2?(t=e,e=0,1):a<3?1:+n;for(var r=-1,a=0|Math.max(0,Math.ceil((t-e)/n));++r<a;)yield e+r*n},valueAt:function(e,t){if(!(!isFinite(t=+t)||t<0||t!=t|0))for(var n,r=-1;!(n=e.next()).done;)if(++r===t)return n.value},worker:function(e){const t=URL.createObjectURL(new Blob([e],{type:"text/javascript"})),n=new Worker(t);return Ae(n,(()=>{n.terminate(),URL.revokeObjectURL(t)}))}});function Ce(e){return e&&"function"==typeof e.getChild&&"function"==typeof e.toArray&&e.schema&&Array.isArray(e.schema.fields)}function Oe(e){return e.schema.fields.map(ke)}function ke(e){return{name:e.name,type:qe(e.type),nullable:e.nullable,databaseType:String(e.type)}}function qe(e){switch(e.typeId){case 2:return"integer";case 3:case 7:return"number";case 4:case 15:return"buffer";case 5:return"string";case 6:return"boolean";case 8:case 9:case 10:return"date";case 12:case 16:return"array";case 13:case 14:return"object";default:return"other"}}class DuckDBClient{constructor(e){Object.defineProperties(this,{_db:{value:e}})}async queryStream(e,t){const n=await this._db.connect();let r,a;try{if(t?.length>0){const a=await n.prepare(e);r=await a.send(...t)}else r=await n.send(e);if(a=await r.next(),a.done)throw new Error("missing first batch")}catch(e){throw await n.close(),e}return{schema:Oe(a.value),async*readRows(){try{for(;!a.done;)yield a.value.toArray(),a=await r.next()}finally{await n.close()}}}}async query(e,t){const n=await this.queryStream(e,t),r=[];for await(const e of n.readRows())for(const t of e)r.push(t);return r.schema=n.schema,r}async queryRow(e,t){const n=(await this.queryStream(e,t)).readRows();try{const{done:e,value:t}=await n.next();return e||!t.length?null:t[0]}finally{await n.return()}}async sql(e,...t){return await this.query(e.join("?"),t)}queryTag(e,...t){return[e.join("?"),t]}escape(e){return`"${e}"`}async describeTables(){return(await this.query("SHOW TABLES")).map((({name:e})=>({name:e})))}async describeColumns({table:e}={}){return(await this.query(`DESCRIBE ${e}`)).map((({column_name:e,column_type:t,null:n})=>({name:e,type:Se(t),nullable:"NO"!==n,databaseType:t})))}static async of(e={},t={}){const n=await async function(){const e=await import(`${te}${U.resolve()}`),t=await e.selectBundle({mvp:{mainModule:`${te}${U.resolve("dist/duckdb-mvp.wasm")}`,mainWorker:`${te}${U.resolve("dist/duckdb-browser-mvp.worker.js")}`},eh:{mainModule:`${te}${U.resolve("dist/duckdb-eh.wasm")}`,mainWorker:`${te}${U.resolve("dist/duckdb-browser-eh.worker.js")}`}}),n=new e.ConsoleLogger,r=await e.createWorker(t.mainWorker),a=new e.AsyncDuckDB(n,r);return await a.instantiate(t.mainModule),a}();return void 0===t.query?.castTimestampToDate&&(t={...t,query:{...t.query,castTimestampToDate:!0}}),await n.open(t),await Promise.all(Object.entries(e).map((async([e,t])=>{if(t instanceof FileAttachment)await $e(n,e,t);else if(Ce(t))await Le(n,e,t);else if(Array.isArray(t))await Re(n,e,t);else if("data"in t){const{data:r,...a}=t;Ce(r)?await Le(n,e,r,a):await Re(n,e,r,a)}else{if(!("file"in t))throw new Error(`invalid source: ${t}`);{const{file:r,...a}=t;await $e(n,e,r,a)}}}))),new DuckDBClient(n)}}async function $e(e,t,n,r){const a=await n.url();if(a.startsWith("blob:")){const t=await n.arrayBuffer();await e.registerFileBuffer(n.name,new Uint8Array(t))}else await e.registerFileURL(n.name,a);const o=await e.connect();try{switch(n.mimeType){case"text/csv":return await o.insertCSVFromPath(n.name,{name:t,schema:"main",...r});case"application/json":return await o.insertJSONFromPath(n.name,{name:t,schema:"main",...r});default:if(/\.arrow$/i.test(n.name)){const e=new Uint8Array(await n.arrayBuffer());return await o.insertArrowFromIPCStream(e,{name:t,schema:"main",...r})}if(/\.parquet$/i.test(n.name))return await o.query(`CREATE VIEW '${t}' AS SELECT * FROM parquet_scan('${n.name}')`);throw new Error(`unknown file type: ${n.mimeType}`)}}finally{await o.close()}}async function Le(e,t,n,r){const a=(await Ie()).tableToIPC(n),o=await e.connect();try{await o.insertArrowFromIPCStream(a,{name:t,schema:"main",...r})}finally{await o.close()}}async function Re(e,t,n,r){const a=(await Ie()).tableFromJSON(n);return await Le(e,t,a,r)}async function Ie(){return await import(`${te}${L.resolve()}`)}function Se(e){switch(e){case"BIGINT":case"HUGEINT":case"UBIGINT":return"bigint";case"DOUBLE":case"REAL":return"number";case"INTEGER":case"SMALLINT":case"TINYINT":case"USMALLINT":case"UINTEGER":case"UTINYINT":return"integer";case"BOOLEAN":return"boolean";case"DATE":case"TIMESTAMP":case"TIMESTAMP WITH TIME ZONE":return"date";case"VARCHAR":case"UUID":return"string";default:return/^DECIMAL\(/.test(e)?"integer":"other"}}function Pe(e,t){return function(n){var r,a,o,i,s,c,l,u,f=n[0],d=[],m=null,h=-1;for(s=1,c=arguments.length;s<c;++s){if((r=arguments[s])instanceof Node)d[++h]=r,f+="\x3c!--o:"+h+"--\x3e";else if(Array.isArray(r)){for(l=0,u=r.length;l<u;++l)(a=r[l])instanceof Node?(null===m&&(d[++h]=m=document.createDocumentFragment(),f+="\x3c!--o:"+h+"--\x3e"),m.appendChild(a)):(m=null,f+=a);m=null}else f+=r;f+=n[s]}if(m=e(f),++h>0){for(o=new Array(h),i=document.createTreeWalker(m,NodeFilter.SHOW_COMMENT,null,!1);i.nextNode();)a=i.currentNode,/^o:/.test(a.nodeValue)&&(o[+a.nodeValue.slice(2)]=a);for(s=0;s<h;++s)(a=o[s])&&a.parentNode.replaceChild(d[s],a)}return 1===m.childNodes.length?m.removeChild(m.firstChild):11===m.nodeType?((a=t()).appendChild(m),a):m}}Object.defineProperty(DuckDBClient.prototype,"dialect",{value:"duckdb"});const Me=Pe((function(e){var t=document.createElement("template");return t.innerHTML=e.trim(),document.importNode(t.content,!0)}),(function(){return document.createElement("span")}));function Ue(e){let t;Object.defineProperties(this,{generator:{value:je((e=>{t=e}))},value:{get:()=>e,set:n=>t(e=n)}}),void 0!==e&&t(e)}function*_e(){for(;;)yield Date.now()}var De=new Map;function Fe(e,t){var n;return(n=De.get(e=+e))?n.then((()=>t)):(n=Date.now())>=e?Promise.resolve(t):function(e,t){var n=new Promise((function(n){De.delete(t);var r=t-e;if(!(r>0))throw new Error("invalid time");if(r>2147483647)throw new Error("too long to wait");setTimeout(n,r)}));return De.set(t,n),n}(n,e).then((()=>t))}var Be=Object.freeze({__proto__:null,delay:function(e,t){return new Promise((function(n){setTimeout((function(){n(t)}),e)}))},tick:function(e,t){return Fe(Math.ceil((Date.now()+1)/e)*e,t)},when:Fe});function We(e,t){if(/^(\w+:)|\/\//i.test(e))return e;if(/^[.]{0,2}\//i.test(e))return new URL(e,null==t?location:t).href;if(!e.length||/^[\s._]/.test(e)||/\s$/.test(e))throw new Error("illegal name");return"https://unpkg.com/"+e}const He=Pe((function(e){var t=document.createElementNS("http://www.w3.org/2000/svg","g");return t.innerHTML=e.trim(),t}),(function(){return document.createElementNS("http://www.w3.org/2000/svg","g")}));var ze=String.raw;function Ge(e){return new Promise((function(t,n){var r=document.createElement("link");r.rel="stylesheet",r.href=e,r.onerror=n,r.onload=t,document.head.appendChild(r)}))}function Ve(){return je((function(e){var t=e(document.body.clientWidth);function n(){var n=document.body.clientWidth;n!==t&&e(t=n)}return window.addEventListener("resize",n),function(){window.removeEventListener("resize",n)}}))}function Ye(e,t){return null==e||null==t?NaN:e<t?-1:e>t?1:e>=t?0:NaN}function Ze(e,t){return null==e||null==t?NaN:t<e?-1:t>e?1:t>=e?0:NaN}function Je(e,t){return e&&("function"==typeof e.sql||"function"==typeof e.queryTag&&("function"==typeof e.query||"function"==typeof e.queryStream))&&("table"!==t||"function"==typeof e.describeColumns)&&e!==nt}function Qe(e){return Array.isArray(e)&&(n=e.schema,Array.isArray(n)&&n.every((e=>e&&"string"==typeof e.name))||(t=e.columns,Array.isArray(t)&&t.every((e=>"string"==typeof e)))||function(e){const t=Math.min(20,e.length);for(let n=0;n<t;++n){const t=e[n];if(null===t||"object"!=typeof t)return!1}return t>0&&function(e){for(const t in e)return!0;return!1}(e[0])}(e)||Ke(e)||et(e))||tt(e);var t,n}function Xe(e){return tt(e)||Ke(e)||et(e)}function Ke(e){const t=Math.min(20,e.length);if(!(t>0))return!1;let n,r=!1;for(let a=0;a<t;++a){const t=e[a];if(null==t)continue;const o=typeof t;if(void 0===n)switch(o){case"number":case"boolean":case"string":case"bigint":n=o;break;default:return!1}else if(o!==n)return!1;r=!0}return r}function et(e){const t=Math.min(20,e.length);if(!(t>0))return!1;let n=!1;for(let r=0;r<t;++r){const t=e[r];if(null!=t){if(!(t instanceof Date))return!1;n=!0}}return n}function tt(e){return e instanceof Int8Array||e instanceof Int16Array||e instanceof Int32Array||e instanceof Uint8Array||e instanceof Uint8ClampedArray||e instanceof Uint16Array||e instanceof Uint32Array||e instanceof Float32Array||e instanceof Float64Array}const nt=Object.assign((async(e,t,n)=>{if(Je(e=await rt(await e,"table")))return at(e,ot(t,e),n);if(Qe(e))return function(e,t){const n=e;let{schema:r,columns:a}=e,o=Xe(e);o&&(e=Array.from(e,(e=>({value:e}))));for(const{type:n,operands:r}of t.filter){const[{value:t}]=r,a=r.slice(1).map((({value:e})=>e));switch(n){case"eq":{const[n]=a;if(n instanceof Date){const r=+n;e=e.filter((e=>+e[t]===r))}else e=e.filter((e=>e[t]===n));break}case"ne":{const[n]=a;e=e.filter((e=>e[t]!==n));break}case"c":{const[n]=a;e=e.filter((e=>"string"==typeof e[t]&&e[t].includes(n)));break}case"nc":{const[n]=a;e=e.filter((e=>"string"==typeof e[t]&&!e[t].includes(n)));break}case"in":{const n=new Set(a);e=e.filter((e=>n.has(e[t])));break}case"nin":{const n=new Set(a);e=e.filter((e=>!n.has(e[t])));break}case"n":e=e.filter((e=>null==e[t]));break;case"nn":e=e.filter((e=>null!=e[t]));break;case"lt":{const[n]=a;e=e.filter((e=>e[t]<n));break}case"lte":{const[n]=a;e=e.filter((e=>e[t]<=n));break}case"gt":{const[n]=a;e=e.filter((e=>e[t]>n));break}case"gte":{const[n]=a;e=e.filter((e=>e[t]>=n));break}default:throw new Error(`unknown filter type: ${n}`)}}for(const{column:r,direction:a}of function(e){if("function"!=typeof e[Symbol.iterator])throw new TypeError("values is not iterable");return Array.from(e).reverse()}(t.sort)){const t="desc"===a?Ze:Ye;e===n&&(e=e.slice()),e.sort(((e,n)=>t(e[r],n[r])))}let{from:i,to:s}=t.slice;i=null==i?0:Math.max(0,i),s=null==s?1/0:Math.max(0,s),(i>0||s<1/0)&&(e=e.slice(Math.max(0,i),Math.max(0,s)));if(t.select.columns){if(r){const e=new Map(r.map((e=>[e.name,e])));r=t.select.columns.map((t=>e.get(t)))}a&&(a=t.select.columns),e=e.map((e=>Object.fromEntries(t.select.columns.map((t=>[t,e[t]])))))}o&&(e=e.map((e=>e.value)));e!==n&&(r&&(e.schema=r),a&&(e.columns=a));return e}(e,t);if(!e)throw new Error("missing data source");throw new Error("invalid data source")}),{sql:(e,t)=>async function(){return at(await rt(await e,"sql"),arguments,t)}});async function rt(e,t){if(e instanceof FileAttachment){if("table"===t)switch(e.mimeType){case"text/csv":return e.csv({typed:!0});case"text/tab-separated-values":return e.tsv({typed:!0});case"application/json":return e.json()}if(("table"===t||"sql"===t)&&"application/x-sqlite3"===e.mimeType)return e.sqlite();throw new Error(`unsupported file type: ${e.mimeType}`)}return e}async function at(e,t,n){if(!e)throw new Error("missing data source");if("function"==typeof e.queryTag){const r=new AbortController,a={signal:r.signal};if(n.then((()=>r.abort("invalidated"))),"function"==typeof e.queryStream)return async function*(e){let t=performance.now();const n=await e,r=[];r.done=!1,r.error=null,r.schema=n.schema;try{for await(const e of n.readRows()){performance.now()-t>10&&r.length>0&&(yield r,t=performance.now());for(const t of e)r.push(t)}r.done=!0,yield r}catch(e){r.error=e,yield r}}(e.queryStream(...e.queryTag.apply(e,t),a));if("function"==typeof e.query)return e.query(...e.queryTag.apply(e,t),a)}if("function"==typeof e.sql)return e.sql.apply(e,t);throw new Error("source does not implement query, queryStream, or sql")}function ot(e,t){const n="function"==typeof t.escape?t.escape:e=>e,{select:r,from:a,filter:o,sort:i,slice:s}=e;if(!a.table)throw new Error("missing from table");if(r.columns&&0===r.columns.length)throw new Error("at least one column must be selected");const c=[[`SELECT ${r.columns?r.columns.map((e=>`t.${n(e)}`)):"*"} FROM ${it(a.table,n)} t`]];for(let e=0;e<o.length;++e)st(e?"\nAND ":"\nWHERE ",c),lt(o[e],c,n);for(let e=0;e<i.length;++e)st(e?", ":"\nORDER BY ",c),ct(i[e],c,n);if("mssql"===t.dialect){if(null!==s.to||null!==s.from){if(!i.length){if(!r.columns)throw new Error("at least one column must be explicitly specified. Received '*'.");st("\nORDER BY ",c),ct({column:r.columns[0],direction:"ASC"},c,n)}st(`\nOFFSET ${s.from||0} ROWS`,c),st(`\nFETCH NEXT ${null!==s.to?s.to-(s.from||0):1e9} ROWS ONLY`,c)}}else null===s.to&&null===s.from||st("\nLIMIT "+(null!==s.to?s.to-(s.from||0):1e9),c),null!==s.from&&st(` OFFSET ${s.from}`,c);return c}function it(e,t){if("object"==typeof e){let n="";return null!=e.database&&(n+=t(e.database)+"."),null!=e.schema&&(n+=t(e.schema)+"."),n+=t(e.table),n}return e}function st(e,t){const n=t[0];n[n.length-1]+=e}function ct({column:e,direction:t},n,r){st(`t.${r(e)} ${t.toUpperCase()}`,n)}function lt({type:e,operands:t},n,r){if(t.length<1)throw new Error("Invalid operand length");if(1===t.length)switch(ut(t[0],n,r),e){case"n":return void st(" IS NULL",n);case"nn":return void st(" IS NOT NULL",n);default:throw new Error("Invalid filter operation")}if(2!==t.length||["in","nin"].includes(e)){var a;switch(ut(t[0],n,r),e){case"in":st(" IN (",n);break;case"nin":st(" NOT IN (",n);break;default:throw new Error("Invalid filter operation")}!function(e,t){let n=!0;for(const r of e)n?n=!1:st(",",t),t.push(r.value),t[0].push("")}(t.slice(1),n),st(")",n)}else{if(["c","nc"].includes(e)){switch(ut(t[0],n,r),e){case"c":st(" LIKE ",n);break;case"nc":st(" NOT LIKE ",n)}return void ut((a=t[1],{...a,value:`%${a.value}%`}),n,r)}switch(ut(t[0],n,r),e){case"eq":st(" = ",n);break;case"ne":st(" <> ",n);break;case"gt":st(" > ",n);break;case"lt":st(" < ",n);break;case"gte":st(" >= ",n);break;case"lte":st(" <= ",n);break;default:throw new Error("Invalid filter operation")}ut(t[1],n,r)}}function ut(e,t,n){"column"===e.type?st(`t.${n(e.value)}`,t):(t.push(e.value),t[0].push(""))}const ft=Object.assign(Object.defineProperties((function(e){const t=function(e){return null==e?ne:J(e)}(e);var n;Object.defineProperties(this,(n={FileAttachment:()=>pe,Mutable:()=>Ue,now:_e,width:Ve,dot:()=>t(g.resolve()),htl:()=>t(j.resolve()),html:()=>Me,md:()=>function(e){return e(N.resolve()).then((function(t){return Pe((function(n){var r=document.createElement("div");r.innerHTML=t(n,{langPrefix:""}).trim();var a=r.querySelectorAll("pre code[class]");return a.length>0&&e(E.resolve()).then((function(t){a.forEach((function(n){function r(){t.highlightBlock(n),n.parentNode.classList.add("observablehq--md-pre")}t.getLanguage(n.className)?r():e(E.resolve("async-languages/index.js")).then((r=>{if(r.has(n.className))return e(E.resolve("async-languages/"+r.get(n.className))).then((e=>{t.registerLanguage(n.className,e)}))})).then(r,r)}))})),r}),(function(){return document.createElement("div")}))}))}(t),svg:()=>He,tex:()=>function(e){return Promise.all([e(T.resolve()),e.resolve(T.resolve("dist/katex.min.css")).then(Ge)]).then((function(e){var t=e[0],n=r();function r(e){return function(){var n=document.createElement("div");return t.render(ze.apply(String,arguments),n,e),n.removeChild(n.firstChild)}}return n.options=r,n.block=r({displayMode:!0}),n}))}(t),_:()=>t(A.resolve()),aq:()=>t.alias({"apache-arrow":$.resolve()})(R.resolve()),Arrow:()=>t($.resolve()),d3:()=>t(b.resolve()),DuckDBClient:()=>DuckDBClient,Inputs:()=>t(y.resolve()).then((e=>({...e,file:e.fileOf(he)}))),L:()=>async function(e){const t=await e(M.resolve());if(!t._style){const n=document.createElement("link");n.rel="stylesheet",n.href=await e.resolve(M.resolve("dist/leaflet.css")),t._style=document.head.appendChild(n)}return t}(t),mermaid:()=>async function(e){const t=await e(P.resolve());return t.initialize({securityLevel:"loose",theme:"neutral"}),function(){const e=document.createElement("div");return e.innerHTML=t.render(ye().id,String.raw.apply(String,arguments)),e.removeChild(e.firstChild)}}(t),Plot:()=>t(v.resolve()),__query:()=>nt,require:()=>t,resolve:()=>We,SQLite:()=>re(t),SQLiteDatabaseClient:()=>SQLiteDatabaseClient,topojson:()=>t(I.resolve()),vl:()=>async function(e){const[t,n,r]=await Promise.all([O,k,q].map((t=>e(t.resolve()))));return r.register(t,n)}(t),aapl:()=>new FileAttachment("https://static.observableusercontent.com/files/3ccff97fd2d93da734e76829b2b066eafdaac6a1fafdec0faf6ebc443271cfc109d29e80dd217468fcb2aff1e6bffdc73f356cc48feb657f35378e6abbbb63b9").csv({typed:!0}),alphabet:()=>new FileAttachment("https://static.observableusercontent.com/files/75d52e6c3130b1cae83cda89305e17b50f33e7420ef205587a135e8562bcfd22e483cf4fa2fb5df6dff66f9c5d19740be1cfaf47406286e2eb6574b49ffc685d").csv({typed:!0}),cars:()=>new FileAttachment("https://static.observableusercontent.com/files/048ec3dfd528110c0665dfa363dd28bc516ffb7247231f3ab25005036717f5c4c232a5efc7bb74bc03037155cb72b1abe85a33d86eb9f1a336196030443be4f6").csv({typed:!0}),citywages:()=>new FileAttachment("https://static.observableusercontent.com/files/39837ec5121fcc163131dbc2fe8c1a2e0b3423a5d1e96b5ce371e2ac2e20a290d78b71a4fb08b9fa6a0107776e17fb78af313b8ea70f4cc6648fad68ddf06f7a").csv({typed:!0}),diamonds:()=>new FileAttachment("https://static.observableusercontent.com/files/87942b1f5d061a21fa4bb8f2162db44e3ef0f7391301f867ab5ba718b225a63091af20675f0bfe7f922db097b217b377135203a7eab34651e21a8d09f4e37252").csv({typed:!0}),flare:()=>new FileAttachment("https://static.observableusercontent.com/files/a6b0d94a7f5828fd133765a934f4c9746d2010e2f342d335923991f31b14120de96b5cb4f160d509d8dc627f0107d7f5b5070d2516f01e4c862b5b4867533000").csv({typed:!0}),industries:()=>new FileAttachment("https://static.observableusercontent.com/files/76f13741128340cc88798c0a0b7fa5a2df8370f57554000774ab8ee9ae785ffa2903010cad670d4939af3e9c17e5e18e7e05ed2b38b848ac2fc1a0066aa0005f").csv({typed:!0}),miserables:()=>new FileAttachment("https://static.observableusercontent.com/files/31d904f6e21d42d4963ece9c8cc4fbd75efcbdc404bf511bc79906f0a1be68b5a01e935f65123670ed04e35ca8cae3c2b943f82bf8db49c5a67c85cbb58db052").json(),olympians:()=>new FileAttachment("https://static.observableusercontent.com/files/31ca24545a0603dce099d10ee89ee5ae72d29fa55e8fc7c9ffb5ded87ac83060d80f1d9e21f4ae8eb04c1e8940b7287d179fe8060d887fb1f055f430e210007c").csv({typed:!0}),penguins:()=>new FileAttachment("https://static.observableusercontent.com/files/715db1223e067f00500780077febc6cebbdd90c151d3d78317c802732252052ab0e367039872ab9c77d6ef99e5f55a0724b35ddc898a1c99cb14c31a379af80a").csv({typed:!0}),weather:()=>new FileAttachment("https://static.observableusercontent.com/files/693a46b22b33db0f042728700e0c73e836fa13d55446df89120682d55339c6db7cc9e574d3d73f24ecc9bc7eb9ac9a1e7e104a1ee52c00aab1e77eb102913c1f").csv({typed:!0}),DOM:ge,Files:Ee,Generators:Ne,Promises:Be},Object.fromEntries(Object.entries(n).map(dt))))}),{resolve:{get:()=>ne.resolve,enumerable:!0,configurable:!0},require:{get:()=>ne,set:function(e){ne=e},enumerable:!0,configurable:!0}}),{resolveFrom:Y,requireFrom:J});function dt([e,t]){return[e,{value:t,writable:!0,enumerable:!0}]}e.AbstractFile=he,e.FileAttachments=function(e){return Object.assign((t=>{const n=e(t+="");if(null==n)throw new Error(`File not found: ${t}`);if("object"==typeof n&&"url"in n){const{url:e,mimeType:r}=n;return new FileAttachment(e,t,r)}return new FileAttachment(n,t)}),{prototype:FileAttachment.prototype})},e.Library=ft,e.arrayIsPrimitive=Xe,e.getArrowTableSchema=Oe,e.isArrowTable=Ce,e.isDataArray=Qe,e.isDatabaseClient=Je,e.loadDataSource=rt,e.makeQueryTemplate=ot}));
// @observablehq/stdlib v5.1.0 Copyright 2022 Observable, Inc.
!function(e,t){"object"==typeof exports&&"undefined"!=typeof module?t(exports):"function"==typeof define&&define.amd?define(["exports"],t):t((e="undefined"!=typeof globalThis?globalThis:e||self).observablehq=e.observablehq||{})}(this,(function(e){"use strict";var t={},n={};function r(e){return new Function("d","return {"+e.map((function(e,t){return JSON.stringify(e)+": d["+t+'] || ""'})).join(",")+"}")}function a(e){var t=Object.create(null),n=[];return e.forEach((function(e){for(var r in e)r in t||n.push(t[r]=r)})),n}function o(e,t){var n=e+"",r=n.length;return r<t?new Array(t-r+1).join(0)+n:n}function i(e){var t,n=e.getUTCHours(),r=e.getUTCMinutes(),a=e.getUTCSeconds(),i=e.getUTCMilliseconds();return isNaN(e)?"Invalid Date":((t=e.getUTCFullYear())<0?"-"+o(-t,6):t>9999?"+"+o(t,6):o(t,4))+"-"+o(e.getUTCMonth()+1,2)+"-"+o(e.getUTCDate(),2)+(i?"T"+o(n,2)+":"+o(r,2)+":"+o(a,2)+"."+o(i,3)+"Z":a?"T"+o(n,2)+":"+o(r,2)+":"+o(a,2)+"Z":r||n?"T"+o(n,2)+":"+o(r,2)+"Z":"")}function s(e){var o=new RegExp('["'+e+"\n\r]"),s=e.charCodeAt(0);function c(e,r){var a,o=[],i=e.length,c=0,l=0,u=i<=0,f=!1;function d(){if(u)return n;if(f)return f=!1,t;var r,a,o=c;if(34===e.charCodeAt(o)){for(;c++<i&&34!==e.charCodeAt(c)||34===e.charCodeAt(++c););return(r=c)>=i?u=!0:10===(a=e.charCodeAt(c++))?f=!0:13===a&&(f=!0,10===e.charCodeAt(c)&&++c),e.slice(o+1,r-1).replace(/""/g,'"')}for(;c<i;){if(10===(a=e.charCodeAt(r=c++)))f=!0;else if(13===a)f=!0,10===e.charCodeAt(c)&&++c;else if(a!==s)continue;return e.slice(o,r)}return u=!0,e.slice(o,i)}for(10===e.charCodeAt(i-1)&&--i,13===e.charCodeAt(i-1)&&--i;(a=d())!==n;){for(var m=[];a!==t&&a!==n;)m.push(a),a=d();r&&null==(m=r(m,l++))||o.push(m)}return o}function l(t,n){return t.map((function(t){return n.map((function(e){return f(t[e])})).join(e)}))}function u(t){return t.map(f).join(e)}function f(e){return null==e?"":e instanceof Date?i(e):o.test(e+="")?'"'+e.replace(/"/g,'""')+'"':e}return{parse:function(e,t){var n,a,o=c(e,(function(e,o){if(n)return n(e,o-1);a=e,n=t?function(e,t){var n=r(e);return function(r,a){return t(n(r),a,e)}}(e,t):r(e)}));return o.columns=a||[],o},parseRows:c,format:function(t,n){return null==n&&(n=a(t)),[n.map(f).join(e)].concat(l(t,n)).join("\n")},formatBody:function(e,t){return null==t&&(t=a(e)),l(e,t).join("\n")},formatRows:function(e){return e.map(u).join("\n")},formatRow:u,formatValue:f}}var c=s(","),l=c.parse,u=c.parseRows,f=s("\t"),d=f.parse,m=f.parseRows;function h(e){for(var t in e){var n,r,a=e[t].trim();if(a)if("true"===a)a=!0;else if("false"===a)a=!1;else if("NaN"===a)a=NaN;else if(isNaN(n=+a)){if(!(r=a.match(/^([-+]\d{2})?\d{4}(-\d{2}(-\d{2})?)?(T\d{2}:\d{2}(:\d{2}(\.\d{3})?)?(Z|[-+]\d{2}:\d{2})?)?$/)))continue;p&&r[4]&&!r[7]&&(a=a.replace(/-/g,"/").replace(/T/," ")),a=new Date(a)}else a=n;else a=null;e[t]=a}return e}const p=new Date("2019-01-01T00:00").getHours()||new Date("2019-07-01T00:00").getHours();function w(e,t,n){return{resolve:(r=n)=>`${e}@${t}/${r}`}}const b=w("d3","7.6.1","dist/d3.min.js"),y=w("@observablehq/inputs","0.10.4","dist/inputs.min.js"),v=w("@observablehq/plot","0.6.0","dist/plot.umd.min.js"),g=w("@observablehq/graphviz","0.2.1","dist/graphviz.min.js"),E=w("@observablehq/highlight.js","2.0.0","highlight.min.js"),T=w("@observablehq/katex","0.11.1","dist/katex.min.js"),A=w("lodash","4.17.21","lodash.min.js"),j=w("htl","0.3.1","dist/htl.min.js"),x=w("jszip","3.10.0","dist/jszip.min.js"),N=w("marked","0.3.12","marked.min.js"),O=w("sql.js","1.7.0","dist/sql-wasm.js"),C=w("vega","5.22.1","build/vega.min.js"),q=w("vega-lite","5.5.0","build/vega-lite.min.js"),$=w("vega-lite-api","5.0.0","build/vega-lite-api.min.js"),k=w("apache-arrow","4.0.1","Arrow.es2015.min.js"),L=w("apache-arrow","9.0.0","+esm"),R=w("arquero","4.8.8","dist/arquero.min.js"),I=w("topojson-client","3.1.0","dist/topojson-client.min.js"),S=w("exceljs","4.3.0","dist/exceljs.min.js"),P=w("mermaid","9.1.6","dist/mermaid.min.js"),M=w("leaflet","1.8.0","dist/leaflet.js"),_=w("@duckdb/duckdb-wasm","1.17.0","+esm"),U=new Map,D=[],F=D.map,B=D.some,W=D.hasOwnProperty,H=/^((?:@[^/@]+\/)?[^/@]+)(?:@([^/]+))?(?:\/(.*))?$/,z=/^\d+\.\d+\.\d+(-[\w-.+]+)?$/,G=/(?:\.[^/]*|\/)$/;class RequireError extends Error{constructor(e){super(e)}}function V(e){const t=H.exec(e);return t&&{name:t[1],version:t[2],path:t[3]}}function Y(e="https://cdn.jsdelivr.net/npm/",t=["unpkg","jsdelivr","browser","main"]){if(!/\/$/.test(e))throw new Error("origin lacks trailing slash");function n(t){const n=`${e}${t.name}${t.version?`@${t.version}`:""}/package.json`;let r=U.get(n);return r||U.set(n,r=fetch(n).then((e=>{if(!e.ok)throw new RequireError("unable to load package.json");return e.redirected&&!U.has(e.url)&&U.set(e.url,r),e.json()}))),r}return async function(r,a){if(r.startsWith(e)&&(r=r.substring(e.length)),/^(\w+:)|\/\//i.test(r))return r;if(/^[.]{0,2}\//i.test(r))return new URL(r,null==a?location:a).href;if(!r.length||/^[\s._]/.test(r)||/\s$/.test(r))throw new RequireError("illegal name");const o=V(r);if(!o)return`${e}${r}`;if(!o.version&&null!=a&&a.startsWith(e)){const t=await n(V(a.substring(e.length)));o.version=t.dependencies&&t.dependencies[o.name]||t.peerDependencies&&t.peerDependencies[o.name]}if(o.path&&!G.test(o.path)&&(o.path+=".js"),o.path&&o.version&&z.test(o.version))return`${e}${o.name}@${o.version}/${o.path}`;const i=await n(o);return`${e}${i.name}@${i.version}/${o.path||function(e){for(const n of t){let t=e[n];if("string"==typeof t)return t.startsWith("./")&&(t=t.slice(2)),G.test(t)?t:`${t}.js`}}(i)||"index.js"}`}}RequireError.prototype.name=RequireError.name;var Z=J(Y());function J(e){const t=new Map,n=a(null);function r(e){if("string"!=typeof e)return e;let n=t.get(e);return n||t.set(e,n=new Promise(((t,n)=>{const r=document.createElement("script");r.onload=()=>{try{t(D.pop()(a(e)))}catch(e){n(new RequireError("invalid module"))}r.remove()},r.onerror=()=>{n(new RequireError("unable to load module")),r.remove()},r.async=!0,r.src=e,window.define=ee,document.head.appendChild(r)}))),n}function a(t){return n=>Promise.resolve(e(n,t)).then(r)}function o(e){return arguments.length>1?Promise.all(F.call(arguments,n)).then(Q):n(e)}return o.alias=function(t){return J(((n,r)=>n in t&&(r=null,"string"!=typeof(n=t[n]))?n:e(n,r)))},o.resolve=e,o}function Q(e){const t={};for(const n of e)for(const e in n)W.call(n,e)&&(null==n[e]?Object.defineProperty(t,e,{get:X(n,e)}):t[e]=n[e]);return t}function X(e,t){return()=>e[t]}function K(e){return"exports"===(e+="")||"module"===e}function ee(e,t,n){const r=arguments.length;r<2?(n=e,t=[]):r<3&&(n=t,t="string"==typeof e?[]:e),D.push(B.call(t,K)?e=>{const r={},a={exports:r};return Promise.all(F.call(t,(t=>"exports"===(t+="")?r:"module"===t?a:e(t)))).then((e=>(n.apply(null,e),a.exports)))}:e=>Promise.all(F.call(t,e)).then((e=>"function"==typeof n?n.apply(null,e):n)))}ee.amd={};const te="https://cdn.observableusercontent.com/npm/";let ne=Z;async function re(e){const[t,n]=await Promise.all([e(O.resolve()),e.resolve(O.resolve("dist/"))]);return t({locateFile:e=>`${n}${e}`})}class SQLiteDatabaseClient{constructor(e){Object.defineProperties(this,{_db:{value:e}})}static async open(e){const[t,n]=await Promise.all([re(ne),Promise.resolve(e).then(oe)]);return new SQLiteDatabaseClient(new t.Database(n))}async query(e,t){return await async function(e,t,n){const[r]=await e.exec(t,n);if(!r)return[];const{columns:a,values:o}=r,i=o.map((e=>Object.fromEntries(e.map(((e,t)=>[a[t],e])))));return i.columns=a,i}(this._db,e,t)}async queryRow(e,t){return(await this.query(e,t))[0]||null}async explain(e,t){return ie("pre",{className:"observablehq--inspect"},[se((await this.query(`EXPLAIN QUERY PLAN ${e}`,t)).map((e=>e.detail)).join("\n"))])}async describeTables({schema:e}={}){return this.query(`SELECT NULLIF(schema, 'main') AS schema, name FROM pragma_table_list() WHERE type = 'table'${null==e?"":" AND schema = ?"} AND name NOT LIKE 'sqlite_%'`,null==e?[]:[e])}async describeColumns({schema:e,table:t}={}){if(null==t)throw new Error("missing table");const n=await this.query(`SELECT name, type, "notnull" FROM pragma_table_info(?${null==e?"":", ?"}) ORDER BY cid`,null==e?[t]:[t,e]);if(!n.length)throw new Error(`table not found: ${t}`);return n.map((({name:e,type:t,notnull:n})=>({name:e,type:ae(t),databaseType:t,nullable:!n})))}async describe(e){const t=await(void 0===e?this.query("SELECT name FROM sqlite_master WHERE type = 'table'"):this.query("SELECT * FROM pragma_table_info(?)",[e]));if(!t.length)throw new Error("Not found");const{columns:n}=t;return ie("table",{value:t},[ie("thead",[ie("tr",n.map((e=>ie("th",[se(e)]))))]),ie("tbody",t.map((e=>ie("tr",n.map((t=>ie("td",[se(e[t])])))))))])}async sql(){return this.query(...this.queryTag.apply(this,arguments))}queryTag(e,...t){return[e.join("?"),t]}}function ae(e){switch(e){case"NULL":return"null";case"INT":case"INTEGER":case"TINYINT":case"SMALLINT":case"MEDIUMINT":case"BIGINT":case"UNSIGNED BIG INT":case"INT2":case"INT8":return"integer";case"TEXT":case"CLOB":case"DATE":case"DATETIME":return"string";case"REAL":case"DOUBLE":case"DOUBLE PRECISION":case"FLOAT":case"NUMERIC":return"number";case"BLOB":return"buffer";default:return/^(?:(?:(?:VARYING|NATIVE) )?CHARACTER|(?:N|VAR|NVAR)CHAR)\(/.test(e)?"string":/^(?:DECIMAL|NUMERIC)\(/.test(e)?"number":"other"}}function oe(e){return"string"==typeof e?fetch(e).then(oe):e instanceof Response||e instanceof Blob?e.arrayBuffer().then(oe):e instanceof ArrayBuffer?new Uint8Array(e):e}function ie(e,t,n){2===arguments.length&&(n=t,t=void 0);const r=document.createElement(e);if(void 0!==t)for(const e in t)r[e]=t[e];if(void 0!==n)for(const e of n)r.appendChild(e);return r}function se(e){return document.createTextNode(e)}Object.defineProperty(SQLiteDatabaseClient.prototype,"dialect",{value:"sqlite"});class Workbook{constructor(e){Object.defineProperties(this,{_:{value:e},sheetNames:{value:e.worksheets.map((e=>e.name)),enumerable:!0}})}sheet(e,t){const n="number"==typeof e?this.sheetNames[e]:this.sheetNames.includes(e+="")?e:null;if(null==n)throw new Error(`Sheet not found: ${e}`);return function(e,{range:t,headers:n}={}){let[[r,a],[o,i]]=function(e=":",{columnCount:t,rowCount:n}){if(!(e+="").match(/^[A-Z]*\d*:[A-Z]*\d*$/))throw new Error("Malformed range specifier");const[[r=0,a=0],[o=t-1,i=n-1]]=e.split(":").map(fe);return[[r,a],[o,i]]}(t,e);const s=n?e._rows[a++]:null;let c=new Set(["#"]);for(let e=r;e<=o;e++){const t=s?ce(s.findCell(e+1)):null;let n=t&&t+""||ue(e);for(;c.has(n);)n+="_";c.add(n)}c=new Array(r).concat(Array.from(c));const l=new Array(i-a+1);for(let t=a;t<=i;t++){const n=l[t-a]=Object.create(null,{"#":{value:t+1}}),i=e.getRow(t+1);if(i.hasValues)for(let e=r;e<=o;e++){const t=ce(i.findCell(e+1));null!=t&&(n[c[e+1]]=t)}}return l.columns=c.filter((()=>!0)),l}(this._.getWorksheet(n),t)}}function ce(e){if(!e)return;const{value:t}=e;if(t&&"object"==typeof t&&!(t instanceof Date)){if(t.formula||t.sharedFormula)return t.result&&t.result.error?NaN:t.result;if(t.richText)return le(t);if(t.text){let{text:e}=t;return e.richText&&(e=le(e)),t.hyperlink&&t.hyperlink!==e?`${t.hyperlink} ${e}`:e}return t}return t}function le(e){return e.richText.map((e=>e.text)).join("")}function ue(e){let t="";e++;do{t=String.fromCharCode(64+(e%26||26))+t}while(e=Math.floor((e-1)/26));return t}function fe(e){const[,t,n]=e.match(/^([A-Z]*)(\d*)$/);let r=0;if(t)for(let e=0;e<t.length;e++)r+=Math.pow(26,t.length-e-1)*(t.charCodeAt(e)-64);return[r?r-1:void 0,n?+n-1:void 0]}async function de(e){const t=await fetch(await e.url());if(!t.ok)throw new Error(`Unable to load file: ${e.name}`);return t}async function me(e,t,{array:n=!1,typed:r=!1}={}){const a=await e.text();return("\t"===t?n?m:d:n?u:l)(a,r&&h)}class he{constructor(e,t){Object.defineProperty(this,"name",{value:e,enumerable:!0}),void 0!==t&&Object.defineProperty(this,"mimeType",{value:t+"",enumerable:!0})}async blob(){return(await de(this)).blob()}async arrayBuffer(){return(await de(this)).arrayBuffer()}async text(){return(await de(this)).text()}async json(){return(await de(this)).json()}async stream(){return(await de(this)).body}async csv(e){return me(this,",",e)}async tsv(e){return me(this,"\t",e)}async image(e){const t=await this.url();return new Promise(((n,r)=>{const a=new Image;new URL(t,document.baseURI).origin!==new URL(location).origin&&(a.crossOrigin="anonymous"),Object.assign(a,e),a.onload=()=>n(a),a.onerror=()=>r(new Error(`Unable to load file: ${this.name}`)),a.src=t}))}async arrow({version:e=4}={}){switch(e){case 4:{const[e,t]=await Promise.all([ne(k.resolve()),de(this)]);return e.Table.from(t)}case 9:{const[e,t]=await Promise.all([import(`${te}${L.resolve()}`),de(this)]);return e.tableFromIPC(t)}default:throw new Error(`unsupported arrow version: ${e}`)}}async sqlite(){return SQLiteDatabaseClient.open(de(this))}async zip(){const[e,t]=await Promise.all([ne(x.resolve()),this.arrayBuffer()]);return new ZipArchive(await e.loadAsync(t))}async xml(e="application/xml"){return(new DOMParser).parseFromString(await this.text(),e)}async html(){return this.xml("text/html")}async xlsx(){const[e,t]=await Promise.all([ne(S.resolve()),this.arrayBuffer()]);return new Workbook(await(new e.Workbook).xlsx.load(t))}}class FileAttachment extends he{constructor(e,t,n){super(t,n),Object.defineProperty(this,"_url",{value:e})}async url(){return await this._url+""}}function pe(e){throw new Error(`File not found: ${e}`)}class ZipArchive{constructor(e){Object.defineProperty(this,"_",{value:e}),this.filenames=Object.keys(e.files).filter((t=>!e.files[t].dir))}file(e){const t=this._.file(e+="");if(!t||t.dir)throw new Error(`file not found: ${e}`);return new ZipArchiveEntry(t)}}class ZipArchiveEntry extends he{constructor(e){super(e.name),Object.defineProperty(this,"_",{value:e}),Object.defineProperty(this,"_url",{writable:!0})}async url(){return this._url||(this._url=this.blob().then(URL.createObjectURL))}async blob(){return this._.async("blob")}async arrayBuffer(){return this._.async("arraybuffer")}async text(){return this._.async("text")}async json(){return JSON.parse(await this.text())}}var we={math:"http://www.w3.org/1998/Math/MathML",svg:"http://www.w3.org/2000/svg",xhtml:"http://www.w3.org/1999/xhtml",xlink:"http://www.w3.org/1999/xlink",xml:"http://www.w3.org/XML/1998/namespace",xmlns:"http://www.w3.org/2000/xmlns/"};var be=0;function ye(e){return new ve("O-"+(null==e?"":e+"-")+ ++be)}function ve(e){this.id=e,this.href=new URL(`#${e}`,location)+""}ve.prototype.toString=function(){return"url("+this.href+")"};var ge=Object.freeze({__proto__:null,canvas:function(e,t){var n=document.createElement("canvas");return n.width=e,n.height=t,n},context2d:function(e,t,n){null==n&&(n=devicePixelRatio);var r=document.createElement("canvas");r.width=e*n,r.height=t*n,r.style.width=e+"px";var a=r.getContext("2d");return a.scale(n,n),a},download:function(e,t="untitled",n="Save"){const r=document.createElement("a"),a=r.appendChild(document.createElement("button"));async function o(){await new Promise(requestAnimationFrame),URL.revokeObjectURL(r.href),r.removeAttribute("href"),a.textContent=n,a.disabled=!1}return a.textContent=n,r.download=t,r.onclick=async t=>{if(a.disabled=!0,r.href)return o();a.textContent="Saving…";try{const t=await("function"==typeof e?e():e);a.textContent="Download",r.href=URL.createObjectURL(t)}catch(e){a.textContent=n}if(t.eventPhase)return o();a.disabled=!1},r},element:function(e,t){var n,r=e+="",a=r.indexOf(":");a>=0&&"xmlns"!==(r=e.slice(0,a))&&(e=e.slice(a+1));var o=we.hasOwnProperty(r)?document.createElementNS(we[r],e):document.createElement(e);if(t)for(var i in t)a=(r=i).indexOf(":"),n=t[i],a>=0&&"xmlns"!==(r=i.slice(0,a))&&(i=i.slice(a+1)),we.hasOwnProperty(r)?o.setAttributeNS(we[r],i,n):o.setAttribute(i,n);return o},input:function(e){var t=document.createElement("input");return null!=e&&(t.type=e),t},range:function(e,t,n){1===arguments.length&&(t=e,e=null);var r=document.createElement("input");return r.min=e=null==e?0:+e,r.max=t=null==t?1:+t,r.step=null==n?"any":n=+n,r.type="range",r},select:function(e){var t=document.createElement("select");return Array.prototype.forEach.call(e,(function(e){var n=document.createElement("option");n.value=n.textContent=e,t.appendChild(n)})),t},svg:function(e,t){var n=document.createElementNS("http://www.w3.org/2000/svg","svg");return n.setAttribute("viewBox",[0,0,e,t]),n.setAttribute("width",e),n.setAttribute("height",t),n},text:function(e){return document.createTextNode(e)},uid:ye});var Ee=Object.freeze({__proto__:null,buffer:function(e){return new Promise((function(t,n){var r=new FileReader;r.onload=function(){t(r.result)},r.onerror=n,r.readAsArrayBuffer(e)}))},text:function(e){return new Promise((function(t,n){var r=new FileReader;r.onload=function(){t(r.result)},r.onerror=n,r.readAsText(e)}))},url:function(e){return new Promise((function(t,n){var r=new FileReader;r.onload=function(){t(r.result)},r.onerror=n,r.readAsDataURL(e)}))}});function Te(){return this}function Ae(e,t){let n=!1;if("function"!=typeof t)throw new Error("dispose is not a function");return{[Symbol.iterator]:Te,next:()=>n?{done:!0}:(n=!0,{done:!1,value:e}),return:()=>(n=!0,t(e),{done:!0}),throw:()=>({done:n=!0})}}function je(e){let t,n,r=!1;const a=e((function(e){n?(n(e),n=null):r=!0;return t=e}));if(null!=a&&"function"!=typeof a)throw new Error("function"==typeof a.then?"async initializers are not supported":"initializer returned something, but not a dispose function");return{[Symbol.iterator]:Te,throw:()=>({done:!0}),return:()=>(null!=a&&a(),{done:!0}),next:function(){return{done:!1,value:r?(r=!1,Promise.resolve(t)):new Promise((e=>n=e))}}}}function xe(e){switch(e.type){case"range":case"number":return e.valueAsNumber;case"date":return e.valueAsDate;case"checkbox":return e.checked;case"file":return e.multiple?e.files:e.files[0];case"select-multiple":return Array.from(e.selectedOptions,(e=>e.value));default:return e.value}}var Ne=Object.freeze({__proto__:null,disposable:Ae,filter:function*(e,t){for(var n,r=-1;!(n=e.next()).done;)t(n.value,++r)&&(yield n.value)},input:function(e){return je((function(t){var n=function(e){switch(e.type){case"button":case"submit":case"checkbox":return"click";case"file":return"change";default:return"input"}}(e),r=xe(e);function a(){t(xe(e))}return e.addEventListener(n,a),void 0!==r&&t(r),function(){e.removeEventListener(n,a)}}))},map:function*(e,t){for(var n,r=-1;!(n=e.next()).done;)yield t(n.value,++r)},observe:je,queue:function(e){let t;const n=[],r=e((function(e){n.push(e),t&&(t(n.shift()),t=null);return e}));if(null!=r&&"function"!=typeof r)throw new Error("function"==typeof r.then?"async initializers are not supported":"initializer returned something, but not a dispose function");return{[Symbol.iterator]:Te,throw:()=>({done:!0}),return:()=>(null!=r&&r(),{done:!0}),next:function(){return{done:!1,value:n.length?Promise.resolve(n.shift()):new Promise((e=>t=e))}}}},range:function*(e,t,n){e=+e,t=+t,n=(a=arguments.length)<2?(t=e,e=0,1):a<3?1:+n;for(var r=-1,a=0|Math.max(0,Math.ceil((t-e)/n));++r<a;)yield e+r*n},valueAt:function(e,t){if(!(!isFinite(t=+t)||t<0||t!=t|0))for(var n,r=-1;!(n=e.next()).done;)if(++r===t)return n.value},worker:function(e){const t=URL.createObjectURL(new Blob([e],{type:"text/javascript"})),n=new Worker(t);return Ae(n,(()=>{n.terminate(),URL.revokeObjectURL(t)}))}});function Oe(e){return e&&"function"==typeof e.getChild&&"function"==typeof e.toArray&&e.schema&&Array.isArray(e.schema.fields)}function Ce(e){return e.schema.fields.map(qe)}function qe(e){return{name:e.name,type:$e(e.type),nullable:e.nullable,databaseType:String(e.type)}}function $e(e){switch(e.typeId){case 2:return"integer";case 3:case 7:return"number";case 4:case 15:return"buffer";case 5:return"string";case 6:return"boolean";case 8:case 9:case 10:return"date";case 12:case 16:return"array";case 13:case 14:return"object";default:return"other"}}async function ke(){return await import(`${te}${L.resolve()}`)}class DuckDBClient{constructor(e){Object.defineProperties(this,{_db:{value:e}})}async queryStream(e,t){const n=await this._db.connect();let r,a;try{if(t?.length>0){const a=await n.prepare(e);r=await a.send(...t)}else r=await n.send(e);if(a=await r.next(),a.done)throw new Error("missing first batch")}catch(e){throw await n.close(),e}return{schema:Ce(a.value),async*readRows(){try{for(;!a.done;)yield a.value.toArray(),a=await r.next()}finally{await n.close()}}}}async query(e,t){const n=await this.queryStream(e,t),r=[];for await(const e of n.readRows())for(const t of e)r.push(t);return r.schema=n.schema,r}async queryRow(e,t){const n=(await this.queryStream(e,t)).readRows();try{const{done:e,value:t}=await n.next();return e||!t.length?null:t[0]}finally{await n.return()}}async sql(e,...t){return await this.query(e.join("?"),t)}queryTag(e,...t){return[e.join("?"),t]}escape(e){return`"${e}"`}async describeTables(){return(await this.query("SHOW TABLES")).map((({name:e})=>({name:e})))}async describeColumns({table:e}={}){return(await this.query(`DESCRIBE ${this.escape(e)}`)).map((({column_name:e,column_type:t,null:n})=>({name:e,type:Se(t),nullable:"NO"!==n,databaseType:t})))}static async of(e={},t={}){const n=await async function(){const e=await import(`${te}${_.resolve()}`),t=await e.selectBundle({mvp:{mainModule:`${te}${_.resolve("dist/duckdb-mvp.wasm")}`,mainWorker:`${te}${_.resolve("dist/duckdb-browser-mvp.worker.js")}`},eh:{mainModule:`${te}${_.resolve("dist/duckdb-eh.wasm")}`,mainWorker:`${te}${_.resolve("dist/duckdb-browser-eh.worker.js")}`}}),n=new e.ConsoleLogger,r=await e.createWorker(t.mainWorker),a=new e.AsyncDuckDB(n,r);return await a.instantiate(t.mainModule),a}();return void 0===t.query?.castTimestampToDate&&(t={...t,query:{...t.query,castTimestampToDate:!0}}),await n.open(t),await Promise.all(Object.entries(e).map((async([e,t])=>{if(t instanceof FileAttachment)await Le(n,e,t);else if(Oe(t))await Re(n,e,t);else if(Array.isArray(t))await Ie(n,e,t);else if("data"in t){const{data:r,...a}=t;Oe(r)?await Re(n,e,r,a):await Ie(n,e,r,a)}else{if(!("file"in t))throw new Error(`invalid source: ${t}`);{const{file:r,...a}=t;await Le(n,e,r,a)}}}))),new DuckDBClient(n)}}async function Le(e,t,n,r){const a=await n.url();if(a.startsWith("blob:")){const t=await n.arrayBuffer();await e.registerFileBuffer(n.name,new Uint8Array(t))}else await e.registerFileURL(n.name,a);const o=await e.connect();try{switch(n.mimeType){case"text/csv":case"text/tab-separated-values":return await o.insertCSVFromPath(n.name,{name:t,schema:"main",delimiter:"text/csv"===n.mimeType?",":"\t",...r});case"application/json":return await o.insertJSONFromPath(n.name,{name:t,schema:"main",...r});default:if(/\.arrow$/i.test(n.name)){const e=new Uint8Array(await n.arrayBuffer());return await o.insertArrowFromIPCStream(e,{name:t,schema:"main",...r})}if(/\.parquet$/i.test(n.name))return await o.query(`CREATE VIEW '${t}' AS SELECT * FROM parquet_scan('${n.name}')`);throw new Error(`unknown file type: ${n.mimeType}`)}}finally{await o.close()}}async function Re(e,t,n,r){const a=await e.connect();try{await a.insertArrowTable(n,{name:t,schema:"main",...r})}finally{await a.close()}}async function Ie(e,t,n,r){const a=(await ke()).tableFromJSON(n);return await Re(e,t,a,r)}function Se(e){switch(e){case"BIGINT":case"HUGEINT":case"UBIGINT":return"bigint";case"DOUBLE":case"REAL":case"FLOAT":return"number";case"INTEGER":case"SMALLINT":case"TINYINT":case"USMALLINT":case"UINTEGER":case"UTINYINT":return"integer";case"BOOLEAN":return"boolean";case"DATE":case"TIMESTAMP":case"TIMESTAMP WITH TIME ZONE":return"date";case"VARCHAR":case"UUID":return"string";default:return/^DECIMAL\(/.test(e)?"integer":"other"}}function Pe(e,t){return function(n){var r,a,o,i,s,c,l,u,f=n[0],d=[],m=null,h=-1;for(s=1,c=arguments.length;s<c;++s){if((r=arguments[s])instanceof Node)d[++h]=r,f+="\x3c!--o:"+h+"--\x3e";else if(Array.isArray(r)){for(l=0,u=r.length;l<u;++l)(a=r[l])instanceof Node?(null===m&&(d[++h]=m=document.createDocumentFragment(),f+="\x3c!--o:"+h+"--\x3e"),m.appendChild(a)):(m=null,f+=a);m=null}else f+=r;f+=n[s]}if(m=e(f),++h>0){for(o=new Array(h),i=document.createTreeWalker(m,NodeFilter.SHOW_COMMENT,null,!1);i.nextNode();)a=i.currentNode,/^o:/.test(a.nodeValue)&&(o[+a.nodeValue.slice(2)]=a);for(s=0;s<h;++s)(a=o[s])&&a.parentNode.replaceChild(d[s],a)}return 1===m.childNodes.length?m.removeChild(m.firstChild):11===m.nodeType?((a=t()).appendChild(m),a):m}}Object.defineProperty(DuckDBClient.prototype,"dialect",{value:"duckdb"});const Me=Pe((function(e){var t=document.createElement("template");return t.innerHTML=e.trim(),document.importNode(t.content,!0)}),(function(){return document.createElement("span")}));function _e(e){let t;Object.defineProperties(this,{generator:{value:je((e=>{t=e}))},value:{get:()=>e,set:n=>t(e=n)}}),void 0!==e&&t(e)}function*Ue(){for(;;)yield Date.now()}var De=new Map;function Fe(e,t){var n;return(n=De.get(e=+e))?n.then((()=>t)):(n=Date.now())>=e?Promise.resolve(t):function(e,t){var n=new Promise((function(n){De.delete(t);var r=t-e;if(!(r>0))throw new Error("invalid time");if(r>2147483647)throw new Error("too long to wait");setTimeout(n,r)}));return De.set(t,n),n}(n,e).then((()=>t))}var Be=Object.freeze({__proto__:null,delay:function(e,t){return new Promise((function(n){setTimeout((function(){n(t)}),e)}))},tick:function(e,t){return Fe(Math.ceil((Date.now()+1)/e)*e,t)},when:Fe});function We(e,t){if(/^(\w+:)|\/\//i.test(e))return e;if(/^[.]{0,2}\//i.test(e))return new URL(e,null==t?location:t).href;if(!e.length||/^[\s._]/.test(e)||/\s$/.test(e))throw new Error("illegal name");return"https://unpkg.com/"+e}const He=Pe((function(e){var t=document.createElementNS("http://www.w3.org/2000/svg","g");return t.innerHTML=e.trim(),t}),(function(){return document.createElementNS("http://www.w3.org/2000/svg","g")}));var ze=String.raw;function Ge(e){return new Promise((function(t,n){var r=document.createElement("link");r.rel="stylesheet",r.href=e,r.onerror=n,r.onload=t,document.head.appendChild(r)}))}function Ve(){return je((function(e){var t=e(document.body.clientWidth);function n(){var n=document.body.clientWidth;n!==t&&e(t=n)}return window.addEventListener("resize",n),function(){window.removeEventListener("resize",n)}}))}function Ye(e,t){return null==e||null==t?NaN:e<t?-1:e>t?1:e>=t?0:NaN}function Ze(e,t){return null==e||null==t?NaN:t<e?-1:t>e?1:t>=e?0:NaN}function Je(e,t){return e&&("function"==typeof e.sql||"function"==typeof e.queryTag&&("function"==typeof e.query||"function"==typeof e.queryStream))&&("table"!==t||"function"==typeof e.describeColumns)&&e!==nt}function Qe(e){return Array.isArray(e)&&(n=e.schema,Array.isArray(n)&&n.every((e=>e&&"string"==typeof e.name))||(t=e.columns,Array.isArray(t)&&t.every((e=>"string"==typeof e)))||function(e){const t=Math.min(20,e.length);for(let n=0;n<t;++n){const t=e[n];if(null===t||"object"!=typeof t)return!1}return t>0&&function(e){for(const t in e)return!0;return!1}(e[0])}(e)||Ke(e)||et(e))||tt(e);var t,n}function Xe(e){return tt(e)||Ke(e)||et(e)}function Ke(e){const t=Math.min(20,e.length);if(!(t>0))return!1;let n,r=!1;for(let a=0;a<t;++a){const t=e[a];if(null==t)continue;const o=typeof t;if(void 0===n)switch(o){case"number":case"boolean":case"string":case"bigint":n=o;break;default:return!1}else if(o!==n)return!1;r=!0}return r}function et(e){const t=Math.min(20,e.length);if(!(t>0))return!1;let n=!1;for(let r=0;r<t;++r){const t=e[r];if(null!=t){if(!(t instanceof Date))return!1;n=!0}}return n}function tt(e){return e instanceof Int8Array||e instanceof Int16Array||e instanceof Int32Array||e instanceof Uint8Array||e instanceof Uint8ClampedArray||e instanceof Uint16Array||e instanceof Uint32Array||e instanceof Float32Array||e instanceof Float64Array}const nt=Object.assign((async(e,t,n,r)=>{if(Je(e=await at(await e,r)))return st(e,ct(t,e),n);if(Qe(e))return ht(e,t);if(!e)throw new Error("missing data source");throw new Error("invalid data source")}),{sql:(e,t,n)=>async function(){return st(await ot(await e,n),arguments,t)}});function rt(e){const t=new WeakMap;return(n,r)=>{if(!n)throw new Error("data source not found");let a=t.get(n);return a||(a=e(n,r),t.set(n,a)),a}}const at=rt((async(e,t)=>{if(e instanceof FileAttachment){switch(e.mimeType){case"text/csv":return e.csv({typed:!0});case"text/tab-separated-values":return e.tsv({typed:!0});case"application/json":return e.json();case"application/x-sqlite3":return e.sqlite()}if(/\.(arrow|parquet)$/i.test(e.name))return it(e,t);throw new Error(`unsupported file type: ${e.mimeType}`)}return Oe(e)?it(e,t):e})),ot=rt((async(e,t)=>{if(e instanceof FileAttachment){switch(e.mimeType){case"text/csv":case"text/tab-separated-values":case"application/json":return it(e,t);case"application/x-sqlite3":return e.sqlite()}if(/\.(arrow|parquet)$/i.test(e.name))return it(e,t);throw new Error(`unsupported file type: ${e.mimeType}`)}return Qe(e)?it(await async function(e,t){const n=await ke();return Xe(e)?n.tableFromArrays({[t]:e}):n.tableFromJSON(e)}(e,t),t):Oe(e)?it(e,t):e}));function it(e,t=(e instanceof FileAttachment?function(e){return e.name.replace(/@\d+(?=\.|$)/,"").replace(/\.\w+$/,"")}(e):"__table")){return DuckDBClient.of({[t]:e})}async function st(e,t,n){if(!e)throw new Error("missing data source");if("function"==typeof e.queryTag){const r=new AbortController,a={signal:r.signal};if(n.then((()=>r.abort("invalidated"))),"function"==typeof e.queryStream)return async function*(e){let t=performance.now();const n=await e,r=[];r.done=!1,r.error=null,r.schema=n.schema;try{for await(const e of n.readRows()){performance.now()-t>10&&r.length>0&&(yield r,t=performance.now());for(const t of e)r.push(t)}r.done=!0,yield r}catch(e){r.error=e,yield r}}(e.queryStream(...e.queryTag.apply(e,t),a));if("function"==typeof e.query)return e.query(...e.queryTag.apply(e,t),a)}if("function"==typeof e.sql)return e.sql.apply(e,t);throw new Error("source does not implement query, queryStream, or sql")}function ct(e,t){const n="function"==typeof t.escape?t.escape:e=>e,{select:r,from:a,filter:o,sort:i,slice:s}=e;if(!a.table)throw new Error("missing from table");if(r.columns&&0===r.columns.length)throw new Error("at least one column must be selected");const c=[[`SELECT ${r.columns?r.columns.map(n).join(", "):"*"} FROM ${lt(a.table,n)}`]];for(let e=0;e<o.length;++e)ut(e?"\nAND ":"\nWHERE ",c),dt(o[e],c,n);for(let e=0;e<i.length;++e)ut(e?", ":"\nORDER BY ",c),ft(i[e],c,n);if("mssql"===t.dialect){if(null!==s.to||null!==s.from){if(!i.length){if(!r.columns)throw new Error("at least one column must be explicitly specified. Received '*'.");ut("\nORDER BY ",c),ft({column:r.columns[0],direction:"ASC"},c,n)}ut(`\nOFFSET ${s.from||0} ROWS`,c),ut(`\nFETCH NEXT ${null!==s.to?s.to-(s.from||0):1e9} ROWS ONLY`,c)}}else null===s.to&&null===s.from||ut("\nLIMIT "+(null!==s.to?s.to-(s.from||0):1e9),c),null!==s.from&&ut(` OFFSET ${s.from}`,c);return c}function lt(e,t){if("object"==typeof e){let n="";return null!=e.database&&(n+=t(e.database)+"."),null!=e.schema&&(n+=t(e.schema)+"."),n+=t(e.table),n}return t(e)}function ut(e,t){const n=t[0];n[n.length-1]+=e}function ft({column:e,direction:t},n,r){ut(`${r(e)} ${t.toUpperCase()}`,n)}function dt({type:e,operands:t},n,r){if(t.length<1)throw new Error("Invalid operand length");if(1===t.length)switch(mt(t[0],n,r),e){case"n":return void ut(" IS NULL",n);case"nn":return void ut(" IS NOT NULL",n);default:throw new Error("Invalid filter operation")}if(2!==t.length||["in","nin"].includes(e)){var a;switch(mt(t[0],n,r),e){case"in":ut(" IN (",n);break;case"nin":ut(" NOT IN (",n);break;default:throw new Error("Invalid filter operation")}!function(e,t){let n=!0;for(const r of e)n?n=!1:ut(",",t),t.push(r.value),t[0].push("")}(t.slice(1),n),ut(")",n)}else{if(["c","nc"].includes(e)){switch(mt(t[0],n,r),e){case"c":ut(" LIKE ",n);break;case"nc":ut(" NOT LIKE ",n)}return void mt((a=t[1],{...a,value:`%${a.value}%`}),n,r)}switch(mt(t[0],n,r),e){case"eq":ut(" = ",n);break;case"ne":ut(" <> ",n);break;case"gt":ut(" > ",n);break;case"lt":ut(" < ",n);break;case"gte":ut(" >= ",n);break;case"lte":ut(" <= ",n);break;default:throw new Error("Invalid filter operation")}mt(t[1],n,r)}}function mt(e,t,n){"column"===e.type?ut(n(e.value),t):(t.push(e.value),t[0].push(""))}function ht(e,t){const n=e;let{schema:r,columns:a}=e,o=Xe(e);o&&(e=Array.from(e,(e=>({value:e}))));for(const{type:n,operands:r}of t.filter){const[{value:t}]=r,a=r.slice(1).map((({value:e})=>e));switch(n){case"eq":{const[n]=a;if(n instanceof Date){const r=+n;e=e.filter((e=>+e[t]===r))}else e=e.filter((e=>e[t]===n));break}case"ne":{const[n]=a;e=e.filter((e=>e[t]!==n));break}case"c":{const[n]=a;e=e.filter((e=>"string"==typeof e[t]&&e[t].includes(n)));break}case"nc":{const[n]=a;e=e.filter((e=>"string"==typeof e[t]&&!e[t].includes(n)));break}case"in":{const n=new Set(a);e=e.filter((e=>n.has(e[t])));break}case"nin":{const n=new Set(a);e=e.filter((e=>!n.has(e[t])));break}case"n":e=e.filter((e=>null==e[t]));break;case"nn":e=e.filter((e=>null!=e[t]));break;case"lt":{const[n]=a;e=e.filter((e=>e[t]<n));break}case"lte":{const[n]=a;e=e.filter((e=>e[t]<=n));break}case"gt":{const[n]=a;e=e.filter((e=>e[t]>n));break}case"gte":{const[n]=a;e=e.filter((e=>e[t]>=n));break}default:throw new Error(`unknown filter type: ${n}`)}}for(const{column:r,direction:a}of function(e){if("function"!=typeof e[Symbol.iterator])throw new TypeError("values is not iterable");return Array.from(e).reverse()}(t.sort)){const t="desc"===a?Ze:Ye;e===n&&(e=e.slice()),e.sort(((e,n)=>t(e[r],n[r])))}let{from:i,to:s}=t.slice;if(i=null==i?0:Math.max(0,i),s=null==s?1/0:Math.max(0,s),(i>0||s<1/0)&&(e=e.slice(Math.max(0,i),Math.max(0,s))),t.select.columns){if(r){const e=new Map(r.map((e=>[e.name,e])));r=t.select.columns.map((t=>e.get(t)))}a&&(a=t.select.columns),e=e.map((e=>Object.fromEntries(t.select.columns.map((t=>[t,e[t]])))))}return o&&(e=e.map((e=>e.value))),e!==n&&(r&&(e.schema=r),a&&(e.columns=a)),e}const pt=Object.assign(Object.defineProperties((function(e){const t=function(e){return null==e?ne:J(e)}(e);var n;Object.defineProperties(this,(n={FileAttachment:()=>pe,Mutable:()=>_e,now:Ue,width:Ve,dot:()=>t(g.resolve()),htl:()=>t(j.resolve()),html:()=>Me,md:()=>function(e){return e(N.resolve()).then((function(t){return Pe((function(n){var r=document.createElement("div");r.innerHTML=t(n,{langPrefix:""}).trim();var a=r.querySelectorAll("pre code[class]");return a.length>0&&e(E.resolve()).then((function(t){a.forEach((function(n){function r(){t.highlightBlock(n),n.parentNode.classList.add("observablehq--md-pre")}t.getLanguage(n.className)?r():e(E.resolve("async-languages/index.js")).then((r=>{if(r.has(n.className))return e(E.resolve("async-languages/"+r.get(n.className))).then((e=>{t.registerLanguage(n.className,e)}))})).then(r,r)}))})),r}),(function(){return document.createElement("div")}))}))}(t),svg:()=>He,tex:()=>function(e){return Promise.all([e(T.resolve()),e.resolve(T.resolve("dist/katex.min.css")).then(Ge)]).then((function(e){var t=e[0],n=r();function r(e){return function(){var n=document.createElement("div");return t.render(ze.apply(String,arguments),n,e),n.removeChild(n.firstChild)}}return n.options=r,n.block=r({displayMode:!0}),n}))}(t),_:()=>t(A.resolve()),aq:()=>t.alias({"apache-arrow":k.resolve()})(R.resolve()),Arrow:()=>t(k.resolve()),d3:()=>t(b.resolve()),DuckDBClient:()=>DuckDBClient,Inputs:()=>t(y.resolve()).then((e=>({...e,file:e.fileOf(he)}))),L:()=>async function(e){const t=await e(M.resolve());if(!t._style){const n=document.createElement("link");n.rel="stylesheet",n.href=await e.resolve(M.resolve("dist/leaflet.css")),t._style=document.head.appendChild(n)}return t}(t),mermaid:()=>async function(e){const t=await e(P.resolve());return t.initialize({securityLevel:"loose",theme:"neutral"}),function(){const e=document.createElement("div");return e.innerHTML=t.render(ye().id,String.raw.apply(String,arguments)),e.removeChild(e.firstChild)}}(t),Plot:()=>t(v.resolve()),__query:()=>nt,require:()=>t,resolve:()=>We,SQLite:()=>re(t),SQLiteDatabaseClient:()=>SQLiteDatabaseClient,topojson:()=>t(I.resolve()),vl:()=>async function(e){const[t,n,r]=await Promise.all([C,q,$].map((t=>e(t.resolve()))));return r.register(t,n)}(t),aapl:()=>new FileAttachment("https://static.observableusercontent.com/files/3ccff97fd2d93da734e76829b2b066eafdaac6a1fafdec0faf6ebc443271cfc109d29e80dd217468fcb2aff1e6bffdc73f356cc48feb657f35378e6abbbb63b9").csv({typed:!0}),alphabet:()=>new FileAttachment("https://static.observableusercontent.com/files/75d52e6c3130b1cae83cda89305e17b50f33e7420ef205587a135e8562bcfd22e483cf4fa2fb5df6dff66f9c5d19740be1cfaf47406286e2eb6574b49ffc685d").csv({typed:!0}),cars:()=>new FileAttachment("https://static.observableusercontent.com/files/048ec3dfd528110c0665dfa363dd28bc516ffb7247231f3ab25005036717f5c4c232a5efc7bb74bc03037155cb72b1abe85a33d86eb9f1a336196030443be4f6").csv({typed:!0}),citywages:()=>new FileAttachment("https://static.observableusercontent.com/files/39837ec5121fcc163131dbc2fe8c1a2e0b3423a5d1e96b5ce371e2ac2e20a290d78b71a4fb08b9fa6a0107776e17fb78af313b8ea70f4cc6648fad68ddf06f7a").csv({typed:!0}),diamonds:()=>new FileAttachment("https://static.observableusercontent.com/files/87942b1f5d061a21fa4bb8f2162db44e3ef0f7391301f867ab5ba718b225a63091af20675f0bfe7f922db097b217b377135203a7eab34651e21a8d09f4e37252").csv({typed:!0}),flare:()=>new FileAttachment("https://static.observableusercontent.com/files/a6b0d94a7f5828fd133765a934f4c9746d2010e2f342d335923991f31b14120de96b5cb4f160d509d8dc627f0107d7f5b5070d2516f01e4c862b5b4867533000").csv({typed:!0}),industries:()=>new FileAttachment("https://static.observableusercontent.com/files/76f13741128340cc88798c0a0b7fa5a2df8370f57554000774ab8ee9ae785ffa2903010cad670d4939af3e9c17e5e18e7e05ed2b38b848ac2fc1a0066aa0005f").csv({typed:!0}),miserables:()=>new FileAttachment("https://static.observableusercontent.com/files/31d904f6e21d42d4963ece9c8cc4fbd75efcbdc404bf511bc79906f0a1be68b5a01e935f65123670ed04e35ca8cae3c2b943f82bf8db49c5a67c85cbb58db052").json(),olympians:()=>new FileAttachment("https://static.observableusercontent.com/files/31ca24545a0603dce099d10ee89ee5ae72d29fa55e8fc7c9ffb5ded87ac83060d80f1d9e21f4ae8eb04c1e8940b7287d179fe8060d887fb1f055f430e210007c").csv({typed:!0}),penguins:()=>new FileAttachment("https://static.observableusercontent.com/files/715db1223e067f00500780077febc6cebbdd90c151d3d78317c802732252052ab0e367039872ab9c77d6ef99e5f55a0724b35ddc898a1c99cb14c31a379af80a").csv({typed:!0}),weather:()=>new FileAttachment("https://static.observableusercontent.com/files/693a46b22b33db0f042728700e0c73e836fa13d55446df89120682d55339c6db7cc9e574d3d73f24ecc9bc7eb9ac9a1e7e104a1ee52c00aab1e77eb102913c1f").csv({typed:!0}),DOM:ge,Files:Ee,Generators:Ne,Promises:Be},Object.fromEntries(Object.entries(n).map(wt))))}),{resolve:{get:()=>ne.resolve,enumerable:!0,configurable:!0},require:{get:()=>ne,set:function(e){ne=e},enumerable:!0,configurable:!0}}),{resolveFrom:Y,requireFrom:J});function wt([e,t]){return[e,{value:t,writable:!0,enumerable:!0}]}e.AbstractFile=he,e.FileAttachments=function(e){return Object.assign((t=>{const n=e(t+="");if(null==n)throw new Error(`File not found: ${t}`);if("object"==typeof n&&"url"in n){const{url:e,mimeType:r}=n;return new FileAttachment(e,t,r)}return new FileAttachment(n,t)}),{prototype:FileAttachment.prototype})},e.Library=pt,e.applyDataTableOperations=ht,e.arrayIsPrimitive=Xe,e.getArrowTableSchema=Ce,e.isArrowTable=Oe,e.isDataArray=Qe,e.isDatabaseClient=Je,e.loadDataSource=async function(e,t,n){switch(t){case"table":return at(e,n);case"sql":return ot(e,n)}return e},e.makeQueryTemplate=ct}));
{
"name": "@observablehq/stdlib",
"version": "5.0.2",
"version": "5.1.0",
"author": {

@@ -5,0 +5,0 @@ "name": "Observable, Inc.",

@@ -0,1 +1,4 @@

import {arrow9 as arrow} from "./dependencies.js";
import {cdn} from "./require.js";
// Returns true if the vaue is an Apache Arrow table. This uses a “duck” test

@@ -59,1 +62,5 @@ // (instead of strict instanceof) because we want it to work with a range of

}
export async function loadArrow() {
return await import(`${cdn}${arrow.resolve()}`);
}

@@ -1,3 +0,3 @@

import {getArrowTableSchema, isArrowTable} from "./arrow.js";
import {arrow9 as arrow, duckdb} from "./dependencies.js";
import {getArrowTableSchema, isArrowTable, loadArrow} from "./arrow.js";
import {duckdb} from "./dependencies.js";
import {FileAttachment} from "./fileAttachment.js";

@@ -114,3 +114,3 @@ import {cdn} from "./require.js";

async describeColumns({table} = {}) {
const columns = await this.query(`DESCRIBE ${table}`);
const columns = await this.query(`DESCRIBE ${this.escape(table)}`);
return columns.map(({column_name, column_type, null: nullable}) => ({

@@ -173,5 +173,7 @@ name: column_name,

case "text/csv":
case "text/tab-separated-values":
return await connection.insertCSVFromPath(file.name, {
name,
schema: "main",
delimiter: file.mimeType === "text/csv" ? "," : "\t",
...options

@@ -207,7 +209,5 @@ });

async function insertArrowTable(database, name, table, options) {
const arrow = await loadArrow();
const buffer = arrow.tableToIPC(table);
const connection = await database.connect();
try {
await connection.insertArrowFromIPCStream(buffer, {
await connection.insertArrowTable(table, {
name,

@@ -247,6 +247,2 @@ schema: "main",

async function loadArrow() {
return await import(`${cdn}${arrow.resolve()}`);
}
// https://duckdb.org/docs/sql/data_types/overview

@@ -261,2 +257,3 @@ function getDuckDBType(type) {

case "REAL":
case "FLOAT":
return "number";

@@ -263,0 +260,0 @@ case "INTEGER":

export {FileAttachments, AbstractFile} from "./fileAttachment.js";
export {Library} from "./library.js";
export {getArrowTableSchema, isArrowTable} from "./arrow.js";
export {makeQueryTemplate, loadDataSource, arrayIsPrimitive, isDataArray, isDatabaseClient} from "./table.js";
export {
makeQueryTemplate,
loadDataSource,
arrayIsPrimitive,
isDataArray,
isDatabaseClient,
__table as applyDataTableOperations
} from "./table.js";
import {ascending, descending, reverse} from "d3-array";
import {FileAttachment} from "./fileAttachment.js";
import {isArrowTable, loadArrow} from "./arrow.js";
import {DuckDBClient} from "./duckdb.js";

@@ -144,4 +146,4 @@ const nChecks = 20; // number of values to check in each array

export const __query = Object.assign(
async (source, operations, invalidation) => {
source = await loadDataSource(await source, "table");
async (source, operations, invalidation, name) => {
source = await loadTableDataSource(await source, name);
if (isDatabaseClient(source)) return evaluateQuery(source, makeQueryTemplate(operations, source), invalidation);

@@ -153,5 +155,5 @@ if (isDataArray(source)) return __table(source, operations);

{
sql(source, invalidation) {
sql(source, invalidation, name) {
return async function () {
return evaluateQuery(await loadDataSource(await source, "sql"), arguments, invalidation);
return evaluateQuery(await loadSqlDataSource(await source, name), arguments, invalidation);
};

@@ -162,21 +164,82 @@ }

export async function loadDataSource(source, mode) {
export async function loadDataSource(source, mode, name) {
switch (mode) {
case "table": return loadTableDataSource(source, name);
case "sql": return loadSqlDataSource(source, name);
}
return source;
}
// We use a weak map to cache loaded data sources by key so that we don’t have
// to e.g. create separate SQLiteDatabaseClients every time we’re querying the
// same SQLite file attachment. Since this is a weak map, unused references will
// be garbage collected when they are no longer desired. Note: the name should
// be consistent, as it is not part of the cache key!
function sourceCache(loadSource) {
const cache = new WeakMap();
return (source, name) => {
if (!source) throw new Error("data source not found");
let promise = cache.get(source);
if (!promise) {
// Warning: do not await here! We need to populate the cache synchronously.
promise = loadSource(source, name);
cache.set(source, promise);
}
return promise;
};
}
const loadTableDataSource = sourceCache(async (source, name) => {
if (source instanceof FileAttachment) {
if (mode === "table") {
switch (source.mimeType) {
case "text/csv": return source.csv({typed: true});
case "text/tab-separated-values": return source.tsv({typed: true});
case "application/json": return source.json();
}
switch (source.mimeType) {
case "text/csv": return source.csv({typed: true});
case "text/tab-separated-values": return source.tsv({typed: true});
case "application/json": return source.json();
case "application/x-sqlite3": return source.sqlite();
}
if (mode === "table" || mode === "sql") {
switch (source.mimeType) {
case "application/x-sqlite3": return source.sqlite();
}
if (/\.(arrow|parquet)$/i.test(source.name)) return loadDuckDBClient(source, name);
throw new Error(`unsupported file type: ${source.mimeType}`);
}
if (isArrowTable(source)) return loadDuckDBClient(source, name);
return source;
});
const loadSqlDataSource = sourceCache(async (source, name) => {
if (source instanceof FileAttachment) {
switch (source.mimeType) {
case "text/csv":
case "text/tab-separated-values":
case "application/json": return loadDuckDBClient(source, name);
case "application/x-sqlite3": return source.sqlite();
}
if (/\.(arrow|parquet)$/i.test(source.name)) return loadDuckDBClient(source, name);
throw new Error(`unsupported file type: ${source.mimeType}`);
}
if (isDataArray(source)) return loadDuckDBClient(await asArrowTable(source, name), name);
if (isArrowTable(source)) return loadDuckDBClient(source, name);
return source;
});
async function asArrowTable(array, name) {
const arrow = await loadArrow();
return arrayIsPrimitive(array)
? arrow.tableFromArrays({[name]: array})
: arrow.tableFromJSON(array);
}
function loadDuckDBClient(
source,
name = source instanceof FileAttachment
? getFileSourceName(source)
: "__table"
) {
return DuckDBClient.of({[name]: source});
}
function getFileSourceName(file) {
return file.name
.replace(/@\d+(?=\.|$)/, "") // strip Observable file version number
.replace(/\.\w+$/, ""); // strip file extension
}
async function evaluateQuery(source, args, invalidation) {

@@ -248,5 +311,5 @@ if (!source) throw new Error("missing data source");

throw new Error("at least one column must be selected");
const columns = select.columns ? select.columns.map((c) => `t.${escaper(c)}`) : "*";
const columns = select.columns ? select.columns.map(escaper).join(", ") : "*";
const args = [
[`SELECT ${columns} FROM ${formatTable(from.table, escaper)} t`]
[`SELECT ${columns} FROM ${formatTable(from.table, escaper)}`]
];

@@ -304,4 +367,5 @@ for (let i = 0; i < filter.length; ++i) {

return from;
} else {
return escaper(table);
}
return table;
}

@@ -315,3 +379,3 @@

function appendOrderBy({column, direction}, args, escaper) {
appendSql(`t.${escaper(column)} ${direction.toUpperCase()}`, args);
appendSql(`${escaper(column)} ${direction.toUpperCase()}`, args);
}

@@ -401,3 +465,3 @@

if (o.type === "column") {
appendSql(`t.${escaper(o.value)}`, args);
appendSql(escaper(o.value), args);
} else {

@@ -425,3 +489,5 @@ args.push(o.value);

// This function applies table cell operations to an in-memory table (array of
// objects); it should be equivalent to the corresponding SQL query.
// objects); it should be equivalent to the corresponding SQL query. TODO Use
// DuckDBClient for data arrays, too, and then we wouldn’t need our own __table
// function to do table operations on in-memory data?
export function __table(source, operations) {

@@ -428,0 +494,0 @@ const input = source;

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc