@observablehq/stdlib
Advanced tools
Comparing version 5.4.0 to 5.4.1
@@ -1,2 +0,2 @@ | ||
// @observablehq/stdlib v5.4.0 Copyright 2023 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 s(e){var t,n=e.getUTCHours(),r=e.getUTCMinutes(),a=e.getUTCSeconds(),s=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)+(s?"T"+o(n,2)+":"+o(r,2)+":"+o(a,2)+"."+o(s,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 i(e){var o=new RegExp('["'+e+"\n\r]"),i=e.charCodeAt(0);function c(e,r){var a,o=[],s=e.length,c=0,l=0,u=s<=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++<s&&34!==e.charCodeAt(c)||34===e.charCodeAt(++c););return(r=c)>=s?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<s;){if(10===(a=e.charCodeAt(r=c++)))f=!0;else if(13===a)f=!0,10===e.charCodeAt(c)&&++c;else if(a!==i)continue;return e.slice(o,r)}return u=!0,e.slice(o,s)}for(10===e.charCodeAt(s-1)&&--s,13===e.charCodeAt(s-1)&&--s;(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?s(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=i(","),l=c.parse,u=c.parseRows,f=i("\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.8.2","dist/d3.min.js"),y=w("@observablehq/inputs","0.10.4","dist/inputs.min.js"),v=w("@observablehq/plot","0.6.2","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"),A=w("@observablehq/katex","0.11.1","dist/katex.min.js"),T=w("lodash","4.17.21","lodash.min.js"),j=w("htl","0.3.1","dist/htl.min.js"),x=w("jszip","3.10.1","dist/jszip.min.js"),N=w("marked","0.3.12","marked.min.js"),O=w("sql.js","1.8.0","dist/sql-wasm.js"),C=w("vega","5.22.1","build/vega.min.js"),$=w("vega-lite","5.6.0","build/vega-lite.min.js"),R=w("vega-lite-api","5.0.0","build/vega-lite-api.min.js"),k=w("apache-arrow","4.0.1","Arrow.es2015.min.js"),q=w("apache-arrow","9.0.0","+esm"),L=w("arquero","4.8.8","dist/arquero.min.js"),S=w("topojson-client","3.1.0","dist/topojson-client.min.js"),I=w("exceljs","4.3.0","dist/exceljs.min.js"),M=w("mermaid","9.2.2","dist/mermaid.min.js"),P=w("leaflet","1.9.3","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-.+]+)?$/,V=/(?:\.[^/]*|\/)$/;class RequireError extends Error{constructor(e){super(e)}}function G(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=G(r);if(!o)return`${e}${r}`;if(!o.version&&null!=a&&a.startsWith(e)){const t=await n(G(a.substring(e.length)));o.version=t.dependencies&&t.dependencies[o.name]||t.peerDependencies&&t.peerDependencies[o.name]}if(o.path&&!V.test(o.path)&&(o.path+=".js"),o.path&&o.version&&z.test(o.version))return`${e}${o.name}@${o.version}/${o.path}`;const s=await n(o);return`${e}${s.name}@${s.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)),V.test(t)?t:`${t}.js`}}(s)||"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,s=o.map((e=>Object.fromEntries(e.map(((e,t)=>[a[t],e])))));return s.columns=a,s}(this._db,e,t)}async queryRow(e,t){return(await this.query(e,t))[0]||null}async explain(e,t){return se("pre",{className:"observablehq--inspect"},[ie((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_%' ORDER BY schema, name`,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 se("table",{value:t},[se("thead",[se("tr",n.map((e=>se("th",[ie(e)]))))]),se("tbody",t.map((e=>se("tr",n.map((t=>se("td",[ie(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 se(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 ie(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,s]]=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,s=n-1]]=e.split(":").map(fe);return[[r,a],[o,s]]}(t,e);const i=n?e._rows[a++]:null;let c=new Set(["#"]);for(let e=r;e<=o;e++){const t=i?ce(i.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(s-a+1);for(let t=a;t<=s;t++){const n=l[t-a]=Object.create(null,{"#":{value:t+1}}),s=e.getRow(t+1);if(s.hasValues)for(let e=r;e<=o;e++){const t=ce(s.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}${q.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(I.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 s in t)a=(r=s).indexOf(":"),n=t[s],a>=0&&"xmlns"!==(r=s.slice(0,a))&&(s=s.slice(a+1)),we.hasOwnProperty(r)?o.setAttributeNS(we[r],s,n):o.setAttribute(s,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 Ae(){return this}function Te(e,t){let n=!1;if("function"!=typeof t)throw new Error("dispose is not a function");return{[Symbol.iterator]:Ae,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]:Ae,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:Te,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]:Ae,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 Te(n,(()=>{n.terminate(),URL.revokeObjectURL(t)}))}});function Oe(e){return e&&"function"==typeof e.toArrowBuffer}function Ce(e){return e&&"function"==typeof e.getChild&&"function"==typeof e.toArray&&e.schema&&Array.isArray(e.schema.fields)}function $e(e){return e.schema.fields.map(Re)}function Re(e){return{name:e.name,type:ke(e.type),nullable:e.nullable,databaseType:String(e.type)}}function ke(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 qe(){return await import(`${te}${q.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:$e(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:Me(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(Ce(t))await Se(n,e,t);else if(Array.isArray(t))await Ie(n,e,t);else if(Oe(t))await async function(e,t,n){const r=(await qe()).tableFromIPC(n.toArrowBuffer());return await Se(e,t,r)}(n,e,t);else if("data"in t){const{data:r,...a}=t;Ce(r)?await Se(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",...r}).catch((async e=>{if(e.toString().includes("Could not convert"))return await async function(e,t,n){const r=await e.prepare(`CREATE TABLE '${n}' AS SELECT * FROM read_csv_auto(?, ALL_VARCHAR=TRUE)`);return await r.send(t.name)}(o,n,t)}));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 Se(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 qe()).tableFromJSON(n);return await Se(e,t,a,r)}function Me(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,s,i,c,l,u,f=n[0],d=[],m=null,h=-1;for(i=1,c=arguments.length;i<c;++i){if((r=arguments[i])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[i]}if(m=e(f),++h>0){for(o=new Array(h),s=document.createTreeWalker(m,NodeFilter.SHOW_COMMENT,null,!1);s.nextNode();)a=s.currentNode,/^o:/.test(a.nodeValue)&&(o[+a.nodeValue.slice(2)]=a);for(i=0;i<h;++i)(a=o[i])&&a.parentNode.replaceChild(d[i],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 _e=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*De(){for(;;)yield Date.now()}var Fe=new Map;function Be(e,t){var n;return(n=Fe.get(e=+e))?n.then((()=>t)):(n=Date.now())>=e?Promise.resolve(t):function(e,t){var n=new Promise((function(n){Fe.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 Fe.set(t,n),n}(n,e).then((()=>t))}var We=Object.freeze({__proto__:null,delay:function(e,t){return new Promise((function(n){setTimeout((function(){n(t)}),e)}))},tick:function(e,t){return Be(Math.ceil((Date.now()+1)/e)*e,t)},when:Be});function He(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 ze=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 Ve=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 Ye(){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 Ze(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!==tt}function Je(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)||Xe(e)||Ke(e))||et(e);var t,n}function Qe(e){return et(e)||Xe(e)||Ke(e)}function Xe(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 Ke(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 et(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 tt=Object.assign((async(e,t,n,r)=>{if(Ze(e=await rt(await e,r)))return st(e,it(t,e),n);if(Je(e))return Nt(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 at(await e,n),arguments,t)}});function nt(e){const t=new WeakMap;return(n,r)=>{if(!n)throw new Error("data source not found");let a=t.get(n);return(!a||Je(n)&&n.length!==a._numRows)&&(a=e(n,r),a._numRows=n.length,t.set(n,a)),a}}const rt=nt((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 ot(e,t);throw new Error(`unsupported file type: ${e.mimeType}`)}return Ce(e)||Oe(e)?ot(e,t):e})),at=nt((async(e,t)=>{if(e instanceof FileAttachment){switch(e.mimeType){case"text/csv":case"text/tab-separated-values":case"application/json":return ot(e,t);case"application/x-sqlite3":return e.sqlite()}if(/\.(arrow|parquet)$/i.test(e.name))return ot(e,t);throw new Error(`unsupported file type: ${e.mimeType}`)}return Je(e)?ot(await async function(e,t){const n=await qe();return Qe(e)?n.tableFromArrays({[t]:e}):n.tableFromJSON(e)}(e,t),t):Ce(e)||Oe(e)?ot(e,t):e}));function ot(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 it(e,t){const n="function"==typeof t.escape?t.escape:e=>e,{select:r,from:a,filter:o,sort:s,slice:i}=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=new Map(e.names?.map((({column:e,name:t})=>[e,t]))),l=[[`SELECT ${r.columns?r.columns.map((e=>{const t=c.get(e);return t?`${n(e)} AS ${n(t)}`:n(e)})).join(", "):"*"} FROM ${ct(a.table,n)}`]];for(let e=0;e<o.length;++e)lt(e?"\nAND ":"\nWHERE ",l),ft(o[e],l,n);for(let e=0;e<s.length;++e)lt(e?", ":"\nORDER BY ",l),ut(s[e],l,n);if("mssql"===t.dialect||"oracle"===t.dialect){if(null!==i.to||null!==i.from){if(!s.length){if(!r.columns)throw new Error("at least one column must be explicitly specified. Received '*'.");lt("\nORDER BY ",l),ut({column:r.columns[0],direction:"ASC"},l,n)}lt(`\nOFFSET ${i.from||0} ROWS`,l),lt(`\nFETCH NEXT ${null!==i.to?i.to-(i.from||0):1e9} ROWS ONLY`,l)}}else null===i.to&&null===i.from||lt("\nLIMIT "+(null!==i.to?i.to-(i.from||0):1e9),l),null!==i.from&<(` OFFSET ${i.from}`,l);return l}function ct(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 lt(e,t){const n=t[0];n[n.length-1]+=e}function ut({column:e,direction:t},n,r){lt(`${r(e)} ${t.toUpperCase()}`,n)}function ft({type:e,operands:t},n,r){if(t.length<1)throw new Error("Invalid operand length");if(1===t.length||"v"===e||"nv"===e)switch(dt(t[0],n,r),e){case"n":case"nv":return void lt(" IS NULL",n);case"nn":case"v":return void lt(" IS NOT NULL",n);default:throw new Error("Invalid filter operation")}if(2!==t.length||["in","nin"].includes(e)){var a;switch(dt(t[0],n,r),e){case"in":lt(" IN (",n);break;case"nin":lt(" 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:lt(",",t),t.push(r.value),t[0].push("")}(t.slice(1),n),lt(")",n)}else{if(["c","nc"].includes(e)){switch(dt(t[0],n,r),e){case"c":lt(" LIKE ",n);break;case"nc":lt(" NOT LIKE ",n)}return void dt((a=t[1],{...a,value:`%${a.value}%`}),n,r)}switch(dt(t[0],n,r),e){case"eq":lt(" = ",n);break;case"ne":lt(" <> ",n);break;case"gt":lt(" > ",n);break;case"lt":lt(" < ",n);break;case"gte":lt(" >= ",n);break;case"lte":lt(" <= ",n);break;default:throw new Error("Invalid filter operation")}dt(t[1],n,r)}}function dt(e,t,n){"column"===e.type?lt(n(e.value),t):(t.push(e.value),t[0].push(""))}function mt(e,t){return(null==e||!(e>=e))-(null==t||!(t>=t))}function ht(e,t){return mt(e,t)||(e<t?-1:e>t?1:0)}function pt(e,t){return mt(e,t)||(e>t?-1:e<t?1:0)}const wt=e=>"number"==typeof e&&!Number.isNaN(e),bt=e=>"string"==typeof e,yt=e=>"boolean"==typeof e,vt=e=>"bigint"==typeof e,gt=e=>e instanceof Date&&!isNaN(e),Et=e=>e instanceof ArrayBuffer,At=e=>Array.isArray(e),Tt=e=>"object"==typeof e&&null!==e,jt=e=>null!=e;function xt(e){switch(e){case"string":return bt;case"bigint":return vt;case"boolean":return yt;case"number":return wt;case"date":return gt;case"buffer":return Et;case"array":return At;case"object":return Tt;default:return jt}}function Nt(e,t){const n=e;let{schema:r,columns:a}=e,o=Qe(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"v":{const[n]=a,r=xt(n);e=e.filter((e=>r(e[t])));break}case"nv":{const[n]=a,r=xt(n);e=e.filter((e=>!r(e[t])));break}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?pt:ht;e===n&&(e=e.slice()),e.sort(((e,n)=>t(e[r],n[r])))}let{from:s,to:i}=t.slice;if(s=null==s?0:Math.max(0,s),i=null==i?1/0:Math.max(0,i),(s>0||i<1/0)&&(e=e.slice(Math.max(0,s),Math.max(0,i))),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]])))))}if(!o&&t.names){const n=new Map(t.names.map((e=>[e.column,e])));r&&(r=r.map((e=>{const t=n.get(e.name);return{...e,...t?{name:t.name}:null}}))),a&&(a=a.map((e=>n.get(e)?.name??e))),e=e.map((e=>Object.fromEntries(Object.keys(e).map((t=>[n.get(t)?.name??t,e[t]])))))}return o&&(e=e.map((e=>e.value))),e!==n&&(r&&(e.schema=r),a&&(e.columns=a)),e}const Ot=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:De,width:Ye,dot:()=>t(g.resolve()),htl:()=>t(j.resolve()),html:()=>_e,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:()=>ze,tex:()=>function(e){return Promise.all([e(A.resolve()),e.resolve(A.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(Ve.apply(String,arguments),n,e),n.removeChild(n.firstChild)}}return n.options=r,n.block=r({displayMode:!0}),n}))}(t),_:()=>t(T.resolve()),aq:()=>t.alias({"apache-arrow":k.resolve()})(L.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(P.resolve());if(!t._style){const n=document.createElement("link");n.rel="stylesheet",n.href=await e.resolve(P.resolve("dist/leaflet.css")),t._style=document.head.appendChild(n)}return t}(t),mermaid:()=>async function(e){const t=await e(M.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:()=>tt,require:()=>t,resolve:()=>He,SQLite:()=>re(t),SQLiteDatabaseClient:()=>SQLiteDatabaseClient,topojson:()=>t(S.resolve()),vl:()=>async function(e){const[t,n,r]=await Promise.all([C,$,R].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:We},Object.fromEntries(Object.entries(n).map(Ct))))}),{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 Ct([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=Ot,e.applyDataTableOperations=Nt,e.arrayIsPrimitive=Qe,e.getArrowTableSchema=$e,e.getTypeValidator=xt,e.isArqueroTable=Oe,e.isArrowTable=Ce,e.isDataArray=Je,e.isDatabaseClient=Ze,e.loadDataSource=async function(e,t,n){switch(t){case"table":return rt(e,n);case"sql":return at(e,n)}return e},e.makeQueryTemplate=it})); | ||
// @observablehq/stdlib v5.4.1 Copyright 2023 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 s(e){var t,n=e.getUTCHours(),r=e.getUTCMinutes(),a=e.getUTCSeconds(),s=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)+(s?"T"+o(n,2)+":"+o(r,2)+":"+o(a,2)+"."+o(s,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 i(e){var o=new RegExp('["'+e+"\n\r]"),i=e.charCodeAt(0);function c(e,r){var a,o=[],s=e.length,c=0,u=0,l=s<=0,f=!1;function d(){if(l)return n;if(f)return f=!1,t;var r,a,o=c;if(34===e.charCodeAt(o)){for(;c++<s&&34!==e.charCodeAt(c)||34===e.charCodeAt(++c););return(r=c)>=s?l=!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<s;){if(10===(a=e.charCodeAt(r=c++)))f=!0;else if(13===a)f=!0,10===e.charCodeAt(c)&&++c;else if(a!==i)continue;return e.slice(o,r)}return l=!0,e.slice(o,s)}for(10===e.charCodeAt(s-1)&&--s,13===e.charCodeAt(s-1)&&--s;(a=d())!==n;){for(var m=[];a!==t&&a!==n;)m.push(a),a=d();r&&null==(m=r(m,u++))||o.push(m)}return o}function u(t,n){return t.map((function(t){return n.map((function(e){return f(t[e])})).join(e)}))}function l(t){return t.map(f).join(e)}function f(e){return null==e?"":e instanceof Date?s(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(u(t,n)).join("\n")},formatBody:function(e,t){return null==t&&(t=a(e)),u(e,t).join("\n")},formatRows:function(e){return e.map(l).join("\n")},formatRow:l,formatValue:f}}var c=i(","),u=c.parse,l=c.parseRows,f=i("\t"),d=f.parse,m=f.parseRows;function p(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;h&&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 h=new Date("2019-01-01T00:00").getHours()||new Date("2019-07-01T00:00").getHours();function b(e,t,n){return{resolve:(r=n)=>`${e}@${t}/${r}`}}const w=b("d3","7.8.2","dist/d3.min.js"),y=b("@observablehq/inputs","0.10.4","dist/inputs.min.js"),v=b("@observablehq/plot","0.6.3","dist/plot.umd.min.js"),g=b("@observablehq/graphviz","0.2.1","dist/graphviz.min.js"),E=b("@observablehq/highlight.js","2.0.0","highlight.min.js"),A=b("@observablehq/katex","0.11.1","dist/katex.min.js"),T=b("lodash","4.17.21","lodash.min.js"),N=b("htl","0.3.1","dist/htl.min.js"),j=b("jszip","3.10.1","dist/jszip.min.js"),x=b("marked","0.3.12","marked.min.js"),O=b("sql.js","1.8.0","dist/sql-wasm.js"),C=b("vega","5.22.1","build/vega.min.js"),$=b("vega-lite","5.6.0","build/vega-lite.min.js"),R=b("vega-lite-api","5.0.0","build/vega-lite-api.min.js"),k=b("apache-arrow","4.0.1","Arrow.es2015.min.js"),q=b("apache-arrow","9.0.0","+esm"),L=b("arquero","4.8.8","dist/arquero.min.js"),I=b("topojson-client","3.1.0","dist/topojson-client.min.js"),S=b("exceljs","4.3.0","dist/exceljs.min.js"),M=b("mermaid","9.2.2","dist/mermaid.min.js"),P=b("leaflet","1.9.3","dist/leaflet.js"),_=b("@duckdb/duckdb-wasm","1.17.0","+esm"),D=new Map,U=[],F=U.map,B=U.some,W=U.hasOwnProperty,H=/^((?:@[^/@]+\/)?[^/@]+)(?:@([^/]+))?(?:\/(.*))?$/,z=/^\d+\.\d+\.\d+(-[\w-.+]+)?$/,V=/(?:\.[^/]*|\/)$/;class RequireError extends Error{constructor(e){super(e)}}function G(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=D.get(n);return r||D.set(n,r=fetch(n).then((e=>{if(!e.ok)throw new RequireError("unable to load package.json");return e.redirected&&!D.has(e.url)&&D.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=G(r);if(!o)return`${e}${r}`;if(!o.version&&null!=a&&a.startsWith(e)){const t=await n(G(a.substring(e.length)));o.version=t.dependencies&&t.dependencies[o.name]||t.peerDependencies&&t.peerDependencies[o.name]}if(o.path&&!V.test(o.path)&&(o.path+=".js"),o.path&&o.version&&z.test(o.version))return`${e}${o.name}@${o.version}/${o.path}`;const s=await n(o);return`${e}${s.name}@${s.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)),V.test(t)?t:`${t}.js`}}(s)||"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(U.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),U.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,s=o.map((e=>Object.fromEntries(e.map(((e,t)=>[a[t],e])))));return s.columns=a,s}(this._db,e,t)}async queryRow(e,t){return(await this.query(e,t))[0]||null}async explain(e,t){return se("pre",{className:"observablehq--inspect"},[ie((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_%' ORDER BY schema, name`,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 se("table",{value:t},[se("thead",[se("tr",n.map((e=>se("th",[ie(e)]))))]),se("tbody",t.map((e=>se("tr",n.map((t=>se("td",[ie(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 se(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 ie(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,s]]=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,s=n-1]]=e.split(":").map(fe);return[[r,a],[o,s]]}(t,e);const i=n?e._rows[a++]:null;let c=new Set(["#"]);for(let e=r;e<=o;e++){const t=i?ce(i.findCell(e+1)):null;let n=t&&t+""||le(e);for(;c.has(n);)n+="_";c.add(n)}c=new Array(r).concat(Array.from(c));const u=new Array(s-a+1);for(let t=a;t<=s;t++){const n=u[t-a]=Object.create(null,{"#":{value:t+1}}),s=e.getRow(t+1);if(s.hasValues)for(let e=r;e<=o;e++){const t=ce(s.findCell(e+1));null!=t&&(n[c[e+1]]=t)}}return u.columns=c.filter((()=>!0)),u}(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 ue(t);if(t.text){let{text:e}=t;return e.richText&&(e=ue(e)),t.hyperlink&&t.hyperlink!==e?`${t.hyperlink} ${e}`:e}return t}return t}function ue(e){return e.richText.map((e=>e.text)).join("")}function le(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?l:u)(a,r&&p)}class pe{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}${q.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(j.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 pe{constructor(e,t,n){super(t,n),Object.defineProperty(this,"_url",{value:e})}async url(){return await this._url+""}}function he(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 pe{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 be={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 we=0;function ye(e){return new ve("O-"+(null==e?"":e+"-")+ ++we)}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=be.hasOwnProperty(r)?document.createElementNS(be[r],e):document.createElement(e);if(t)for(var s in t)a=(r=s).indexOf(":"),n=t[s],a>=0&&"xmlns"!==(r=s.slice(0,a))&&(s=s.slice(a+1)),be.hasOwnProperty(r)?o.setAttributeNS(be[r],s,n):o.setAttribute(s,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 Ae(){return this}function Te(e,t){let n=!1;if("function"!=typeof t)throw new Error("dispose is not a function");return{[Symbol.iterator]:Ae,next:()=>n?{done:!0}:(n=!0,{done:!1,value:e}),return:()=>(n=!0,t(e),{done:!0}),throw:()=>({done:n=!0})}}function Ne(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]:Ae,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 je(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 xe=Object.freeze({__proto__:null,disposable:Te,filter:function*(e,t){for(var n,r=-1;!(n=e.next()).done;)t(n.value,++r)&&(yield n.value)},input:function(e){return Ne((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=je(e);function a(){t(je(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:Ne,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]:Ae,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 Te(n,(()=>{n.terminate(),URL.revokeObjectURL(t)}))}});function Oe(e){return e&&"function"==typeof e.toArrowBuffer}function Ce(e){return e&&"function"==typeof e.getChild&&"function"==typeof e.toArray&&e.schema&&Array.isArray(e.schema.fields)}function $e(e){return e.schema.fields.map(Re)}function Re(e){return{name:e.name,type:ke(e.type),nullable:e.nullable,databaseType:String(e.type)}}function ke(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 qe(){return await import(`${te}${q.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:$e(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:Me(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(Ce(t))await Ie(n,e,t);else if(Array.isArray(t))await Se(n,e,t);else if(Oe(t))await async function(e,t,n){const r=(await qe()).tableFromIPC(n.toArrowBuffer());return await Ie(e,t,r)}(n,e,t);else if("data"in t){const{data:r,...a}=t;Ce(r)?await Ie(n,e,r,a):await Se(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",...r}).catch((async e=>{if(e.toString().includes("Could not convert"))return await async function(e,t,n){const r=await e.prepare(`CREATE TABLE '${n}' AS SELECT * FROM read_csv_auto(?, ALL_VARCHAR=TRUE)`);return await r.send(t.name)}(o,n,t)}));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 Ie(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 Se(e,t,n,r){const a=(await qe()).tableFromJSON(n);return await Ie(e,t,a,r)}function Me(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,s,i,c,u,l,f=n[0],d=[],m=null,p=-1;for(i=1,c=arguments.length;i<c;++i){if((r=arguments[i])instanceof Node)d[++p]=r,f+="\x3c!--o:"+p+"--\x3e";else if(Array.isArray(r)){for(u=0,l=r.length;u<l;++u)(a=r[u])instanceof Node?(null===m&&(d[++p]=m=document.createDocumentFragment(),f+="\x3c!--o:"+p+"--\x3e"),m.appendChild(a)):(m=null,f+=a);m=null}else f+=r;f+=n[i]}if(m=e(f),++p>0){for(o=new Array(p),s=document.createTreeWalker(m,NodeFilter.SHOW_COMMENT,null,!1);s.nextNode();)a=s.currentNode,/^o:/.test(a.nodeValue)&&(o[+a.nodeValue.slice(2)]=a);for(i=0;i<p;++i)(a=o[i])&&a.parentNode.replaceChild(d[i],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 _e=Pe((function(e){var t=document.createElement("template");return t.innerHTML=e.trim(),document.importNode(t.content,!0)}),(function(){return document.createElement("span")}));function De(e){let t;Object.defineProperties(this,{generator:{value:Ne((e=>{t=e}))},value:{get:()=>e,set:n=>t(e=n)}}),void 0!==e&&t(e)}function*Ue(){for(;;)yield Date.now()}var Fe=new Map;function Be(e,t){var n;return(n=Fe.get(e=+e))?n.then((()=>t)):(n=Date.now())>=e?Promise.resolve(t):function(e,t){var n=new Promise((function(n){Fe.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 Fe.set(t,n),n}(n,e).then((()=>t))}var We=Object.freeze({__proto__:null,delay:function(e,t){return new Promise((function(n){setTimeout((function(){n(t)}),e)}))},tick:function(e,t){return Be(Math.ceil((Date.now()+1)/e)*e,t)},when:Be});function He(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 ze=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 Ve=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 Ye(){return Ne((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 Ze(e,t){return null==e||null==t?NaN:e<t?-1:e>t?1:e>=t?0:NaN}function Je(e,t=Ze){let n,r=!1;if(1===t.length){let a;for(const o of e){const e=t(o);(r?Ze(e,a)>0:0===Ze(e,e))&&(n=o,a=e,r=!0)}}else for(const a of e)(r?t(a,n)>0:0===t(a,a))&&(n=a,r=!0);return n}function Qe(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!==ot}function Xe(e){return Array.isArray(e)&&(Ke(e.schema)||(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)||nt(e)||rt(e))||at(e);var t}function Ke(e){return Array.isArray(e)&&e.every(et)}function et(e){return e&&"string"==typeof e.name&&"string"==typeof e.type}function tt(e){return at(e)||nt(e)||rt(e)}function nt(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 rt(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 at(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 ot=Object.assign((async(e,t,n,r)=>{if(Qe(e=await it(await e,r)))return lt(e,ft(t,e),n);if(Xe(e))return Lt(e,t);if(!e)throw new Error("missing data source");throw new Error("invalid data source")}),{sql:(e,t,n)=>async function(){return lt(await ct(await e,n),arguments,t)}});function st(e){const t=new WeakMap;return(n,r)=>{if(!n)throw new Error("data source not found");let a=t.get(n);return(!a||Xe(n)&&n.length!==a._numRows)&&(a=e(n,r),a._numRows=n.length,t.set(n,a)),a}}const it=st((async(e,t)=>{if(e instanceof FileAttachment){switch(e.mimeType){case"text/csv":return e.csv();case"text/tab-separated-values":return e.tsv();case"application/json":return e.json();case"application/x-sqlite3":return e.sqlite()}if(/\.(arrow|parquet)$/i.test(e.name))return ut(e,t);throw new Error(`unsupported file type: ${e.mimeType}`)}return Ce(e)||Oe(e)?ut(e,t):Xe(e)&&tt(e)?Array.from(e,(e=>({value:e}))):e})),ct=st((async(e,t)=>{if(e instanceof FileAttachment){switch(e.mimeType){case"text/csv":case"text/tab-separated-values":case"application/json":return ut(e,t);case"application/x-sqlite3":return e.sqlite()}if(/\.(arrow|parquet)$/i.test(e.name))return ut(e,t);throw new Error(`unsupported file type: ${e.mimeType}`)}return Xe(e)?ut(await async function(e,t){const n=await qe();return tt(e)?n.tableFromArrays({[t]:e}):n.tableFromJSON(e)}(e,t),t):Ce(e)||Oe(e)?ut(e,t):e}));function ut(e,t=(e instanceof FileAttachment?function(e){return e.name.replace(/@\d+(?=\.|$)/,"").replace(/\.\w+$/,"")}(e):"__table")){return DuckDBClient.of({[t]:e})}async function lt(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 ft(e,t){const n="function"==typeof t.escape?t.escape:e=>e,{select:r,from:a,filter:o,sort:s,slice:i}=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=new Map(e.names?.map((({column:e,name:t})=>[e,t]))),u=[[`SELECT ${r.columns?r.columns.map((e=>{const t=c.get(e);return t?`${n(e)} AS ${n(t)}`:n(e)})).join(", "):"*"} FROM ${dt(a.table,n)}`]];for(let e=0;e<o.length;++e)mt(e?"\nAND ":"\nWHERE ",u),ht(o[e],u,n);for(let e=0;e<s.length;++e)mt(e?", ":"\nORDER BY ",u),pt(s[e],u,n);if("mssql"===t.dialect||"oracle"===t.dialect){if(null!==i.to||null!==i.from){if(!s.length){if(!r.columns)throw new Error("at least one column must be explicitly specified. Received '*'.");mt("\nORDER BY ",u),pt({column:r.columns[0],direction:"ASC"},u,n)}mt(`\nOFFSET ${i.from||0} ROWS`,u),mt(`\nFETCH NEXT ${null!==i.to?i.to-(i.from||0):1e9} ROWS ONLY`,u)}}else null===i.to&&null===i.from||mt("\nLIMIT "+(null!==i.to?i.to-(i.from||0):1e9),u),null!==i.from&&mt(` OFFSET ${i.from}`,u);return u}function dt(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 mt(e,t){const n=t[0];n[n.length-1]+=e}function pt({column:e,direction:t},n,r){mt(`${r(e)} ${t.toUpperCase()}`,n)}function ht({type:e,operands:t},n,r){if(t.length<1)throw new Error("Invalid operand length");if(1===t.length||"v"===e||"nv"===e)switch(bt(t[0],n,r),e){case"n":case"nv":return void mt(" IS NULL",n);case"nn":case"v":return void mt(" IS NOT NULL",n);default:throw new Error("Invalid filter operation")}if(2!==t.length||["in","nin"].includes(e)){var a;switch(bt(t[0],n,r),e){case"in":mt(" IN (",n);break;case"nin":mt(" 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:mt(",",t),t.push(r.value),t[0].push("")}(t.slice(1),n),mt(")",n)}else{if(["c","nc"].includes(e)){switch(bt(t[0],n,r),e){case"c":mt(" LIKE ",n);break;case"nc":mt(" NOT LIKE ",n)}return void bt((a=t[1],{...a,value:`%${a.value}%`}),n,r)}switch(bt(t[0],n,r),e){case"eq":mt(" = ",n);break;case"ne":mt(" <> ",n);break;case"gt":mt(" > ",n);break;case"lt":mt(" < ",n);break;case"gte":mt(" >= ",n);break;case"lte":mt(" <= ",n);break;default:throw new Error("Invalid filter operation")}bt(t[1],n,r)}}function bt(e,t,n){"column"===e.type?mt(n(e.value),t):(t.push(e.value),t[0].push(""))}function wt(e,t){return(null==e||!(e>=e))-(null==t||!(t>=t))}function yt(e,t){return wt(e,t)||(e<t?-1:e>t?1:0)}function vt(e,t){return wt(e,t)||(e>t?-1:e<t?1:0)}const gt=e=>"number"==typeof e&&!Number.isNaN(e),Et=e=>Number.isInteger(e)&&!Number.isNaN(e),At=e=>"string"==typeof e,Tt=e=>"boolean"==typeof e,Nt=e=>"bigint"==typeof e,jt=e=>e instanceof Date&&!isNaN(e),xt=e=>e instanceof ArrayBuffer,Ot=e=>Array.isArray(e),Ct=e=>"object"==typeof e&&null!==e,$t=e=>null!=e;function Rt(e){switch(e){case"string":return At;case"bigint":return Nt;case"boolean":return Tt;case"number":return gt;case"integer":return Et;case"date":return jt;case"buffer":return xt;case"array":return Ot;case"object":return Ct;default:return $t}}const kt=/^(([-+]\d{2})?\d{4}(-\d{2}(-\d{2}))|(\d{1,2})\/(\d{1,2})\/(\d{2,4}))([T ]\d{2}:\d{2}(:\d{2}(\.\d{3})?)?(Z|[-+]\d{2}:\d{2})?)?$/;function qt(e,t){switch(t){case"string":return"string"==typeof e||null==e?e:String(e);case"boolean":if("string"==typeof e){const t=e.trim().toLowerCase();return"true"===t||"false"!==t&&null}return"boolean"==typeof e||null==e?e:Boolean(e);case"bigint":return"bigint"==typeof e||null==e?e:Number.isInteger("string"!=typeof e||e.trim()?+e:NaN)?BigInt(e):void 0;case"integer":case"number":return"number"==typeof e?e:null==e||"string"==typeof e&&!e.trim()?NaN:Number(e);case"date":{if(e instanceof Date||null==e)return e;if("number"==typeof e)return new Date(e);const t=String(e).trim();return"string"!=typeof e||t?new Date(kt.test(t)?t:NaN):null}case"array":case"object":case"buffer":case"other":return e;default:throw new Error(`Unable to coerce to type: ${t}`)}}function Lt(e,t){const n=e;let{schema:r,columns:a}=e,o=!1;Ke(r)||(r=Mt(e,a),o=!0);const s=new Map(r.map((({name:e,type:t})=>[e,t])));if(t.type){for(const{name:e,type:a}of t.type){s.set(e,a),r===n.schema&&(r=r.slice());const t=r.findIndex((t=>t.name===e));t>-1&&(r[t]={...r[t],type:a})}e=e.map((e=>It(e,s,r)))}else o&&(e=e.map((e=>It(e,s,r))));for(const{type:n,operands:r}of t.filter){const[{value:t}]=r,a=r.slice(1).map((({value:e})=>e));switch(n){case"v":{const[n]=a,r=Rt(n);e=e.filter((e=>r(e[t])));break}case"nv":{const[n]=a,r=Rt(n);e=e.filter((e=>!r(e[t])));break}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?vt:yt;e===n&&(e=e.slice()),e.sort(((e,n)=>t(e[r],n[r])))}let{from:i,to:c}=t.slice;if(i=null==i?0:Math.max(0,i),c=null==c?1/0:Math.max(0,c),(i>0||c<1/0)&&(e=e.slice(Math.max(0,i),Math.max(0,c))),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]])))))}if(t.names){const n=new Map(t.names.map((e=>[e.column,e])));r&&(r=r.map((e=>{const t=n.get(e.name);return{...e,...t?{name:t.name}:null}}))),a&&(a=a.map((e=>n.get(e)?.name??e))),e=e.map((e=>Object.fromEntries(Object.keys(e).map((t=>[n.get(t)?.name??t,e[t]])))))}return e!==n&&(r&&(e.schema=r),a&&(e.columns=a)),e}function It(e,t,n){const r={};for(const a of n){const n=t.get(a.name),o=e[a.name];r[a.name]="raw"===n?o:qt(o,n)}return r}const St=["boolean","integer","number","date","bigint","array","object","buffer"];function Mt(e,t=function(e){const t=new Set;for(const n of e)if(n)for(const e in n)Object.prototype.hasOwnProperty.call(n,e)&&t.add(e);return Array.from(t)}(e)){const n=[],r=e.slice(0,100);for(const e of t){const t={boolean:0,integer:0,number:0,date:0,string:0,array:0,object:0,bigint:0,buffer:0,defined:0};for(const n of r){let r=n[e];if(null==r)continue;const a=typeof r;if("string"!==a)++t.defined,Array.isArray(r)?++t.array:r instanceof Date?++t.date:r instanceof ArrayBuffer?++t.buffer:"number"===a?(++t.number,Number.isInteger(r)&&++t.integer):a in t&&++t[a];else{if(r=r.trim(),!r)continue;++t.defined,++t.string,/^(true|false)$/i.test(r)?++t.boolean:r&&!isNaN(r)?(++t.number,Number.isInteger(+r)&&++t.integer):kt.test(r)&&++t.date}}const a=Math.max(1,.9*t.defined),o=Je(St,(e=>t[e]>=a?t[e]:NaN))??(t.string>=a?"string":"other");n.push({name:e,type:o,inferred:o})}return n}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:()=>he,Mutable:()=>De,now:Ue,width:Ye,dot:()=>t(g.resolve()),htl:()=>t(N.resolve()),html:()=>_e,md:()=>function(e){return e(x.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:()=>ze,tex:()=>function(e){return Promise.all([e(A.resolve()),e.resolve(A.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(Ve.apply(String,arguments),n,e),n.removeChild(n.firstChild)}}return n.options=r,n.block=r({displayMode:!0}),n}))}(t),_:()=>t(T.resolve()),aq:()=>t.alias({"apache-arrow":k.resolve()})(L.resolve()),Arrow:()=>t(k.resolve()),d3:()=>t(w.resolve()),DuckDBClient:()=>DuckDBClient,Inputs:()=>t(y.resolve()).then((e=>({...e,file:e.fileOf(pe)}))),L:()=>async function(e){const t=await e(P.resolve());if(!t._style){const n=document.createElement("link");n.rel="stylesheet",n.href=await e.resolve(P.resolve("dist/leaflet.css")),t._style=document.head.appendChild(n)}return t}(t),mermaid:()=>async function(e){const t=await e(M.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:()=>ot,require:()=>t,resolve:()=>He,SQLite:()=>re(t),SQLiteDatabaseClient:()=>SQLiteDatabaseClient,topojson:()=>t(I.resolve()),vl:()=>async function(e){const[t,n,r]=await Promise.all([C,$,R].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:xe,Promises:We},Object.fromEntries(Object.entries(n).map(_t))))}),{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 _t([e,t]){return[e,{value:t,writable:!0,enumerable:!0}]}e.AbstractFile=pe,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=Lt,e.arrayIsPrimitive=tt,e.getArrowTableSchema=$e,e.getTypeValidator=Rt,e.isArqueroTable=Oe,e.isArrowTable=Ce,e.isDataArray=Xe,e.isDatabaseClient=Qe,e.loadDataSource=async function(e,t,n){switch(t){case"table":return it(e,n);case"sql":return ct(e,n)}return e},e.makeQueryTemplate=ft})); |
{ | ||
"name": "@observablehq/stdlib", | ||
"version": "5.4.0", | ||
"version": "5.4.1", | ||
"author": { | ||
@@ -5,0 +5,0 @@ "name": "Observable, Inc.", |
import {dependency} from "./dependency.js"; | ||
export const d3 = dependency("d3", "7.8.2", "dist/d3.min.js"); | ||
export const inputs = dependency("@observablehq/inputs", "0.10.4", "dist/inputs.min.js"); | ||
export const plot = dependency("@observablehq/plot", "0.6.2", "dist/plot.umd.min.js"); | ||
export const plot = dependency("@observablehq/plot", "0.6.3", "dist/plot.umd.min.js"); | ||
export const graphviz = dependency("@observablehq/graphviz", "0.2.1", "dist/graphviz.min.js"); | ||
@@ -6,0 +6,0 @@ export const highlight = dependency("@observablehq/highlight.js", "2.0.0", "highlight.min.js"); |
207
src/table.js
@@ -1,2 +0,2 @@ | ||
import {reverse} from "d3-array"; | ||
import {greatest, reverse} from "d3-array"; | ||
import {FileAttachment} from "./fileAttachment.js"; | ||
@@ -69,3 +69,6 @@ import {isArqueroTable} from "./arquero.js"; | ||
function isQueryResultSetSchema(schemas) { | ||
return (Array.isArray(schemas) && schemas.every((s) => s && typeof s.name === "string")); | ||
return ( | ||
Array.isArray(schemas) && | ||
schemas.every(isColumnSchema) | ||
); | ||
} | ||
@@ -77,2 +80,6 @@ | ||
function isColumnSchema(schema) { | ||
return schema && typeof schema.name === "string" && typeof schema.type === "string"; | ||
} | ||
// Returns true if the value represents an array of primitives (i.e., a | ||
@@ -196,4 +203,4 @@ // single-column table). This should only be passed values for which | ||
switch (source.mimeType) { | ||
case "text/csv": return source.csv({typed: true}); | ||
case "text/tab-separated-values": return source.tsv({typed: true}); | ||
case "text/csv": return source.csv(); | ||
case "text/tab-separated-values": return source.tsv(); | ||
case "application/json": return source.json(); | ||
@@ -206,2 +213,4 @@ case "application/x-sqlite3": return source.sqlite(); | ||
if (isArrowTable(source) || isArqueroTable(source)) return loadDuckDBClient(source, name); | ||
if (isDataArray(source) && arrayIsPrimitive(source)) | ||
return Array.from(source, (value) => ({value})); | ||
return source; | ||
@@ -515,2 +524,3 @@ }); | ||
const isValidNumber = (value) => typeof value === "number" && !Number.isNaN(value); | ||
const isValidInteger = (value) => Number.isInteger(value) && !Number.isNaN(value); | ||
const isValidString = (value) => typeof value === "string"; | ||
@@ -536,2 +546,4 @@ const isValidBoolean = (value) => typeof value === "boolean"; | ||
return isValidNumber; | ||
case "integer": | ||
return isValidInteger; | ||
case "date": | ||
@@ -551,2 +563,52 @@ return isValidDate; | ||
// Accepts dates in the form of ISOString and LocaleDateString, with or without time | ||
const DATE_TEST = /^(([-+]\d{2})?\d{4}(-\d{2}(-\d{2}))|(\d{1,2})\/(\d{1,2})\/(\d{2,4}))([T ]\d{2}:\d{2}(:\d{2}(\.\d{3})?)?(Z|[-+]\d{2}:\d{2})?)?$/; | ||
export function coerceToType(value, type) { | ||
switch (type) { | ||
case "string": | ||
return typeof value === "string" || value == null ? value : String(value); | ||
case "boolean": | ||
if (typeof value === "string") { | ||
const trimValue = value.trim().toLowerCase(); | ||
return trimValue === "true" | ||
? true | ||
: trimValue === "false" | ||
? false | ||
: null; | ||
} | ||
return typeof value === "boolean" || value == null | ||
? value | ||
: Boolean(value); | ||
case "bigint": | ||
return typeof value === "bigint" || value == null | ||
? value | ||
: Number.isInteger(typeof value === "string" && !value.trim() ? NaN : +value) | ||
? BigInt(value) // eslint-disable-line no-undef | ||
: undefined; | ||
case "integer": // not a target type for coercion, but can be inferred | ||
case "number": { | ||
return typeof value === "number" | ||
? value | ||
: value == null || (typeof value === "string" && !value.trim()) | ||
? NaN | ||
: Number(value); | ||
} | ||
case "date": { | ||
if (value instanceof Date || value == null) return value; | ||
if (typeof value === "number") return new Date(value); | ||
const trimValue = String(value).trim(); | ||
if (typeof value === "string" && !trimValue) return null; | ||
return new Date(DATE_TEST.test(trimValue) ? trimValue : NaN); | ||
} | ||
case "array": | ||
case "object": | ||
case "buffer": | ||
case "other": | ||
return value; | ||
default: | ||
throw new Error(`Unable to coerce to type: ${type}`); | ||
} | ||
} | ||
// This function applies table cell operations to an in-memory table (array of | ||
@@ -559,4 +621,23 @@ // objects); it should be equivalent to the corresponding SQL query. TODO Use | ||
let {schema, columns} = source; | ||
let primitive = arrayIsPrimitive(source); | ||
if (primitive) source = Array.from(source, (value) => ({value})); | ||
let inferredSchema = false; | ||
if (!isQueryResultSetSchema(schema)) { | ||
schema = inferSchema(source, columns); | ||
inferredSchema = true; | ||
} | ||
// Combine column types from schema with user-selected types in operations | ||
const types = new Map(schema.map(({name, type}) => [name, type])); | ||
if (operations.type) { | ||
for (const {name, type} of operations.type) { | ||
types.set(name, type); | ||
// update schema with user-selected type | ||
if (schema === input.schema) schema = schema.slice(); // copy on write | ||
const colIndex = schema.findIndex((col) => col.name === name); | ||
if (colIndex > -1) schema[colIndex] = {...schema[colIndex], type}; | ||
} | ||
source = source.map(d => coerceRow(d, types, schema)); | ||
} else if (inferredSchema) { | ||
// Coerce data according to new schema, unless that happened due to | ||
// operations.type, above. | ||
source = source.map(d => coerceRow(d, types, schema)); | ||
} | ||
for (const {type, operands} of operations.filter) { | ||
@@ -674,3 +755,3 @@ const [{value: column}] = operands; | ||
} | ||
if (!primitive && operations.names) { | ||
if (operations.names) { | ||
const overridesByName = new Map(operations.names.map((n) => [n.column, n])); | ||
@@ -696,3 +777,2 @@ if (schema) { | ||
} | ||
if (primitive) source = source.map((d) => d.value); | ||
if (source !== input) { | ||
@@ -704,1 +784,112 @@ if (schema) source.schema = schema; | ||
} | ||
function coerceRow(object, types, schema) { | ||
const coerced = {}; | ||
for (const col of schema) { | ||
const type = types.get(col.name); | ||
const value = object[col.name]; | ||
coerced[col.name] = type === "raw" ? value : coerceToType(value, type); | ||
} | ||
return coerced; | ||
} | ||
function createTypeCount() { | ||
return { | ||
boolean: 0, | ||
integer: 0, | ||
number: 0, | ||
date: 0, | ||
string: 0, | ||
array: 0, | ||
object: 0, | ||
bigint: 0, | ||
buffer: 0, | ||
defined: 0 | ||
}; | ||
} | ||
// Caution: the order below matters! 🌶️ The first one that passes the ≥90% test | ||
// should be the one that we chose, and therefore these types should be listed | ||
// from most specific to least specific. | ||
const types = [ | ||
"boolean", | ||
"integer", | ||
"number", | ||
"date", | ||
"bigint", | ||
"array", | ||
"object", | ||
"buffer" | ||
// Note: "other" and "string" are intentionally omitted; see below! | ||
]; | ||
// We need to show *all* keys present in the array of Objects | ||
function getAllKeys(rows) { | ||
const keys = new Set(); | ||
for (const row of rows) { | ||
// avoid crash if row is null or undefined | ||
if (row) { | ||
// only enumerable properties | ||
for (const key in row) { | ||
// only own properties | ||
if (Object.prototype.hasOwnProperty.call(row, key)) { | ||
// unique properties, in the order they appear | ||
keys.add(key); | ||
} | ||
} | ||
} | ||
} | ||
return Array.from(keys); | ||
} | ||
export function inferSchema(source, columns = getAllKeys(source)) { | ||
const schema = []; | ||
const sampleSize = 100; | ||
const sample = source.slice(0, sampleSize); | ||
const typeCounts = {}; | ||
for (const col of columns) { | ||
const colCount = typeCounts[col] = createTypeCount(); | ||
for (const d of sample) { | ||
let value = d[col]; | ||
if (value == null) continue; | ||
const type = typeof value; | ||
if (type !== "string") { | ||
++colCount.defined; | ||
if (Array.isArray(value)) ++colCount.array; | ||
else if (value instanceof Date) ++colCount.date; | ||
else if (value instanceof ArrayBuffer) ++colCount.buffer; | ||
else if (type === "number") { | ||
++colCount.number; | ||
if (Number.isInteger(value)) ++colCount.integer; | ||
} | ||
// bigint, boolean, or object | ||
else if (type in colCount) ++colCount[type]; | ||
} else { | ||
value = value.trim(); | ||
if (!value) continue; | ||
++colCount.defined; | ||
++colCount.string; | ||
if (/^(true|false)$/i.test(value)) { | ||
++colCount.boolean; | ||
} else if (value && !isNaN(value)) { | ||
++colCount.number; | ||
if (Number.isInteger(+value)) ++colCount.integer; | ||
} else if (DATE_TEST.test(value)) ++colCount.date; | ||
} | ||
} | ||
// Chose the non-string, non-other type with the greatest count that is also | ||
// ≥90%; or if no such type meets that criterion, fallback to string if | ||
// ≥90%; and lastly fallback to other. | ||
const minCount = Math.max(1, colCount.defined * 0.9); | ||
const type = | ||
greatest(types, (type) => | ||
colCount[type] >= minCount ? colCount[type] : NaN | ||
) ?? (colCount.string >= minCount ? "string" : "other"); | ||
schema.push({ | ||
name: col, | ||
type: type, | ||
inferred: type | ||
}); | ||
} | ||
return schema; | ||
} |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
172550
2400