@observablehq/stdlib
Advanced tools
Comparing version 2.0.3 to 2.0.4
@@ -1,2 +0,2 @@ | ||
// @observablehq/stdlib v2.0.3 Copyright 2018 Observable, Inc. | ||
!function(e,n){"object"==typeof exports&&"undefined"!=typeof module?n(exports):"function"==typeof define&&define.amd?define(["exports"],n):n(e.observablehq=e.observablehq||{})}(this,function(e){"use strict";function n(e){return function(){return e}}var t={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 r=0;function o(e){this.id=e,this.href=window.location.href+"#"+e}o.prototype.toString=function(){return"url("+this.href+")"};var i={canvas:function(e,n){var t=document.createElement("canvas");return t.width=e,t.height=n,t},context2d:function(e,n,t){null==t&&(t=devicePixelRatio);var r=document.createElement("canvas");r.width=e*t,r.height=n*t,r.style.width=e+"px";var o=r.getContext("2d");return o.scale(t,t),o},download:function(e,n,t){var r=document.createElement("a");return r.appendChild(document.createElement("button")).textContent=null==t?"Download":t,r.download=null==n?"untitled":n,r.onclick=function(){var n=r.href=URL.createObjectURL(e);setTimeout(function(){URL.revokeObjectURL(n)},50)},r},element:function(e,n){var r,o=e+="",i=o.indexOf(":");i>=0&&"xmlns"!==(o=e.slice(0,i))&&(e=e.slice(i+1));var u=t.hasOwnProperty(o)?document.createElementNS(t[o],e):document.createElement(e);if(n)for(var l in n)i=(o=l).indexOf(":"),r=n[l],i>=0&&"xmlns"!==(o=l.slice(0,i))&&(l=l.slice(i+1)),t.hasOwnProperty(o)?u.setAttributeNS(t[o],l,r):u.setAttribute(l,r);return u},input:function(e){var n=document.createElement("input");return null!=e&&(n.type=e),n},range:function(e,n,t){1===arguments.length&&(n=e,e=null);var r=document.createElement("input");return r.min=e=null==e?0:+e,r.max=n=null==n?1:+n,r.step=null==t?"any":t=+t,r.type="range",r},select:function(e){var n=document.createElement("select");return Array.prototype.forEach.call(e,function(e){var t=document.createElement("option");t.value=t.textContent=e,n.appendChild(t)}),n},svg:function(e,n){var t=document.createElementNS("http://www.w3.org/2000/svg","svg");return t.setAttribute("viewBox",[0,0,e,n]),t.setAttribute("width",e),t.setAttribute("height",n),t},text:function(e){return document.createTextNode(e)},uid:function(e){return new o("O-"+(null==e?"":e+"-")+ ++r)}};var u={buffer:function(e){return new Promise(function(n,t){var r=new FileReader;r.onload=function(){n(r.result)},r.onerror=t,r.readAsArrayBuffer(e)})},text:function(e){return new Promise(function(n,t){var r=new FileReader;r.onload=function(){n(r.result)},r.onerror=t,r.readAsText(e)})},url:function(e){return new Promise(function(n,t){var r=new FileReader;r.onload=function(){n(r.result)},r.onerror=t,r.readAsDataURL(e)})}};function l(){return this}function a(e,n){let t=!1;return{[Symbol.iterator]:l,next:()=>t?{done:!0}:(t=!0,{done:!1,value:e}),return:()=>(t=!0,n(e),{done:!0}),throw:()=>({done:t=!0})}}function c(e){let n,t,r=!1;const o=e(function(e){t?(t(e),t=null):r=!0;return n=e});return{[Symbol.iterator]:l,throw:()=>({done:!0}),return:()=>(null!=o&&o(),{done:!0}),next:function(){return{done:!1,value:r?(r=!1,Promise.resolve(n)):new Promise(e=>t=e)}}}}function s(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];default:return e.value}}var f={disposable:a,filter:function*(e,n){for(var t,r=-1;!(t=e.next()).done;)n(t.value,++r)&&(yield t.value)},input:function(e){return c(function(n){var t=function(e){switch(e.type){case"button":case"submit":case"checkbox":return"click";case"file":return"change";default:return"input"}}(e),r=s(e);function o(){n(s(e))}return e.addEventListener(t,o),void 0!==r&&n(r),function(){e.removeEventListener(t,o)}})},map:function*(e,n){for(var t,r=-1;!(t=e.next()).done;)yield n(t.value,++r)},observe:c,queue:function(e){let n;const t=[],r=e(function(e){return t.push(e),n&&(n(t.shift()),n=null),e});return{[Symbol.iterator]:l,throw:()=>({done:!0}),return:()=>(null!=r&&r(),{done:!0}),next:function(){return{done:!1,value:t.length?Promise.resolve(t.shift()):new Promise(e=>n=e)}}}},range:function*(e,n,t){e=+e,n=+n,t=(o=arguments.length)<2?(n=e,e=0,1):o<3?1:+t;for(var r=-1,o=0|Math.max(0,Math.ceil((n-e)/t));++r<o;)yield e+r*t},valueAt:function(e,n){if(!(!isFinite(n=+n)||n<0||n!=n|0))for(var t,r=-1;!(t=e.next()).done;)if(++r===n)return t.value},worker:function(e){const n=URL.createObjectURL(new Blob([e],{type:"text/javascript"})),t=new Worker(n);return a(t,()=>{t.terminate(),URL.revokeObjectURL(n)})}};function d(e,n){return function(t){var r,o,i,u,l,a,c,s,f=t[0],d=[],m=null,h=-1;for(l=1,a=arguments.length;l<a;++l){if((r=arguments[l])instanceof Node)d[++h]=r,f+="\x3c!--o:"+h+"--\x3e";else if(Array.isArray(r)){for(c=0,s=r.length;c<s;++c)(o=r[c])instanceof Node?(null===m&&(d[++h]=m=document.createDocumentFragment(),f+="\x3c!--o:"+h+"--\x3e"),m.appendChild(o)):(m=null,f+=o);m=null}else f+=r;f+=t[l]}if(m=e(f),++h>0){for(i=new Array(h),u=document.createTreeWalker(m,NodeFilter.SHOW_COMMENT,null,!1);u.nextNode();)o=u.currentNode,/^o:/.test(o.nodeValue)&&(i[+o.nodeValue.slice(2)]=o);for(l=0;l<h;++l)(o=i[l])&&o.parentNode.replaceChild(d[l],o)}return 1===m.childNodes.length?m.removeChild(m.firstChild):11===m.nodeType?((o=n()).appendChild(m),o):m}}var m=d(function(e){var n=document.createElement("template");return n.innerHTML=e.trim(),document.importNode(n.content,!0)},function(){return document.createElement("span")});function h(e){let n;Object.defineProperties(this,{generator:{value:c(e=>void(n=e))},value:{get:()=>e,set:t=>n(e=t)}}),void 0!==e&&n(e)}function*v(){for(;;)yield Date.now()}var w=new Map;function p(e,t){var r;return(r=w.get(e=+e))?r.then(n(t)):(r=Date.now())>=e?Promise.resolve(t):function(e,n){var t=new Promise(function(t){w.delete(n);var r=n-e;if(!(r>0))throw new Error("invalid time");if(r>2147483647)throw new Error("too long to wait");setTimeout(t,r)});return w.set(n,t),t}(r,e).then(n(t))}var b={delay:function(e,n){return new Promise(function(t){setTimeout(function(){t(n)},e)})},tick:function(e,n){return p(Math.ceil((Date.now()+1)/e)*e,n)},when:p};function g(e,n){if(/^(\w+:)|\/\//i.test(e))return e;if(/^[.]{0,2}\//i.test(e))return new URL(e,null==n?location:n).href;if(!e.length||/^[\s._]/.test(e)||/\s$/.test(e))throw new Error("illegal name");return"https://unpkg.com/"+e}const x=new Map,y=[],E=y.map,k=y.some,P=y.hasOwnProperty,L="https://unpkg.com/",M=/^((?:@[^\/@]+\/)?[^\/@]+)(?:@([^\/]+))?(?:\/(.*))?$/,j=/^\d+\.\d+\.\d+(-[\w-.+]+)?$/;class RequireError extends Error{constructor(e){super(e)}}function $(e){return"string"==typeof e?e:""}function A(e){const n=M.exec(e);return n&&{name:n[1],version:n[2],path:n[3]}}function N(e){const n=`${L}${e.name}${e.version?`@${e.version}`:""}/package.json`;let t=x.get(n);return t||x.set(n,t=fetch(n).then(e=>{if(!e.ok)throw new RequireError("unable to load package.json");return e.redirected&&!x.has(e.url)&&x.set(e.url,t),e.json()})),t}RequireError.prototype.name=RequireError.name;const O=C(async function(e,n){if(e.startsWith(L)&&(e=e.substring(L.length)),/^(\w+:)|\/\//i.test(e))return e;if(/^[.]{0,2}\//i.test(e))return new URL(e,null==n?location:n).href;if(!e.length||/^[\s._]/.test(e)||/\s$/.test(e))throw new RequireError("illegal name");const t=A(e);if(!t)return`${L}${e}`;if(!t.version&&null!=n&&n.startsWith(L)){const e=await N(A(n.substring(L.length)));t.version=e.dependencies&&e.dependencies[t.name]||e.peerDependencies&&e.peerDependencies[t.name]}if(t.path&&t.version&&j.test(t.version))return`${L}${t.name}@${t.version}/${t.path}`;const r=await N(t);return`${L}${r.name}@${r.version}/${t.path||$(r.unpkg)||$(r.browser)||$(r.main)||"index.js"}`});function C(e){const n=new Map,t=o(null);function r(e){if("string"!=typeof e)return e;let t=n.get(e);return t||n.set(e,t=new Promise((n,t)=>{const r=document.createElement("script");r.onload=(()=>{try{n(y.pop()(o(e)))}catch(e){t(new RequireError("invalid module"))}r.remove()}),r.onerror=(()=>{t(new RequireError("unable to load module")),r.remove()}),r.async=!0,r.src=e,window.define=U,document.head.appendChild(r)})),t}function o(n){return t=>Promise.resolve(e(t,n)).then(r)}function i(e){return arguments.length>1?Promise.all(E.call(arguments,t)).then(R):t(e)}return i.alias=function(n){return C((t,r)=>t in n&&(r=null,"string"!=typeof(t=n[t]))?t:e(t,r))},i.resolve=e,i}function R(e){const n={};for(const t of e)for(const e in t)P.call(t,e)&&(null==t[e]?Object.defineProperty(n,e,{get:S(t,e)}):n[e]=t[e]);return n}function S(e,n){return()=>e[n]}function T(e){return e+""=="exports"}function U(e,n,t){const r=arguments.length;r<2?(t=e,n=[]):r<3&&(t=n,n="string"==typeof e?[]:e),y.push(k.call(n,T)?e=>{const r={};return Promise.all(E.call(n,n=>T(n+="")?r:e(n))).then(e=>(t.apply(null,e),r))}:e=>Promise.all(E.call(n,e)).then(e=>"function"==typeof t?t.apply(null,e):t))}function D(e){return null==e?O:C(e)}U.amd={};var q=d(function(e){var n=document.createElementNS("http://www.w3.org/2000/svg","g");return n.innerHTML=e.trim(),n},function(){return document.createElementNS("http://www.w3.org/2000/svg","g")}),F=String.raw;function W(e){return new Promise(function(n,t){var r=document.createElement("link");r.rel="stylesheet",r.href=e,r.onerror=t,r.onload=n,document.head.appendChild(r)})}function _(){return c(function(e){var n=e(document.body.clientWidth);function t(){var t=document.body.clientWidth;t!==n&&e(n=t)}return window.addEventListener("resize",t),function(){window.removeEventListener("resize",t)}})}e.Library=function(e){const t=D(e);Object.defineProperties(this,{DOM:{value:i,writable:!0,enumerable:!0},Files:{value:u,writable:!0,enumerable:!0},Generators:{value:f,writable:!0,enumerable:!0},html:{value:n(m),writable:!0,enumerable:!0},md:{value:function(e){return function(){return e("marked@0.3.12/marked.min.js").then(function(n){return d(function(t){var r=document.createElement("span");r.innerHTML=n(t,{langPrefix:""}).trim();var o=r.querySelectorAll("pre code[class]");return o.length>0&&e("@observablehq/highlight.js@1.1.1/highlight.min.js").then(function(e){o.forEach(function(n){e.highlightBlock(n),n.parentNode.classList.add("observablehq--md-pre")})}),r},function(){return document.createElement("span")})})}}(t),writable:!0,enumerable:!0},Mutable:{value:n(h),writable:!0,enumerable:!0},now:{value:v,writable:!0,enumerable:!0},Promises:{value:b,writable:!0,enumerable:!0},require:{value:n(t),writable:!0,enumerable:!0},resolve:{value:n(g),writable:!0,enumerable:!0},svg:{value:n(q),writable:!0,enumerable:!0},tex:{value:function(e){return function(){return Promise.all([e("@observablehq/katex@0.10.1/dist/katex.min.js"),e.resolve("@observablehq/katex@0.10.1/dist/katex.min.css").then(W)]).then(function(e){var n=e[0],t=r();function r(e){return function(){var t=document.createElement("div");return n.render(F.apply(String,arguments),t,e),t.removeChild(t.firstChild)}}return t.options=r,t.block=r({displayMode:!0}),t})}}(t),writable:!0,enumerable:!0},width:{value:_,writable:!0,enumerable:!0}})},Object.defineProperty(e,"__esModule",{value:!0})}); | ||
// @observablehq/stdlib v2.0.4 Copyright 2018 Observable, Inc. | ||
!function(e,t){"object"==typeof exports&&"undefined"!=typeof module?t(exports):"function"==typeof define&&define.amd?define(["exports"],t):t(e.observablehq=e.observablehq||{})}(this,function(e){"use strict";function t(e){return function(){return e}}var n={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 r=0;function o(e){this.id=e,this.href=window.location.href+"#"+e}o.prototype.toString=function(){return"url("+this.href+")"};var i={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 o=r.getContext("2d");return o.scale(n,n),o},download:function(e,t="untitled",n="Save"){const r=document.createElement("a"),o=r.appendChild(document.createElement("button"));async function i(){await new Promise(requestAnimationFrame),URL.revokeObjectURL(r.href),r.removeAttribute("href"),o.textContent=n,o.disabled=!1}return o.textContent=n,r.download=t,r.onclick=(async t=>{if(o.disabled=!0,r.href)return i();o.textContent="Saving…";try{const t=await("function"==typeof e?e():e);o.textContent="Download",r.href=URL.createObjectURL(t)}catch(e){o.textContent=n}if(t.eventPhase)return i();o.disabled=!1}),r},element:function(e,t){var r,o=e+="",i=o.indexOf(":");i>=0&&"xmlns"!==(o=e.slice(0,i))&&(e=e.slice(i+1));var u=n.hasOwnProperty(o)?document.createElementNS(n[o],e):document.createElement(e);if(t)for(var a in t)i=(o=a).indexOf(":"),r=t[a],i>=0&&"xmlns"!==(o=a.slice(0,i))&&(a=a.slice(i+1)),n.hasOwnProperty(o)?u.setAttributeNS(n[o],a,r):u.setAttribute(a,r);return u},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:function(e){return new o("O-"+(null==e?"":e+"-")+ ++r)}};var u={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 a(){return this}function l(e,t){let n=!1;return{[Symbol.iterator]:a,next:()=>n?{done:!0}:(n=!0,{done:!1,value:e}),return:()=>(n=!0,t(e),{done:!0}),throw:()=>({done:n=!0})}}function c(e){let t,n,r=!1;const o=e(function(e){n?(n(e),n=null):r=!0;return t=e});return{[Symbol.iterator]:a,throw:()=>({done:!0}),return:()=>(null!=o&&o(),{done:!0}),next:function(){return{done:!1,value:r?(r=!1,Promise.resolve(t)):new Promise(e=>n=e)}}}}function s(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];default:return e.value}}var f={disposable:l,filter:function*(e,t){for(var n,r=-1;!(n=e.next()).done;)t(n.value,++r)&&(yield n.value)},input:function(e){return c(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=s(e);function o(){t(s(e))}return e.addEventListener(n,o),void 0!==r&&t(r),function(){e.removeEventListener(n,o)}})},map:function*(e,t){for(var n,r=-1;!(n=e.next()).done;)yield t(n.value,++r)},observe:c,queue:function(e){let t;const n=[],r=e(function(e){return n.push(e),t&&(t(n.shift()),t=null),e});return{[Symbol.iterator]:a,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=(o=arguments.length)<2?(t=e,e=0,1):o<3?1:+n;for(var r=-1,o=0|Math.max(0,Math.ceil((t-e)/n));++r<o;)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 l(n,()=>{n.terminate(),URL.revokeObjectURL(t)})}};function d(e,t){return function(n){var r,o,i,u,a,l,c,s,f=n[0],d=[],m=null,h=-1;for(a=1,l=arguments.length;a<l;++a){if((r=arguments[a])instanceof Node)d[++h]=r,f+="\x3c!--o:"+h+"--\x3e";else if(Array.isArray(r)){for(c=0,s=r.length;c<s;++c)(o=r[c])instanceof Node?(null===m&&(d[++h]=m=document.createDocumentFragment(),f+="\x3c!--o:"+h+"--\x3e"),m.appendChild(o)):(m=null,f+=o);m=null}else f+=r;f+=n[a]}if(m=e(f),++h>0){for(i=new Array(h),u=document.createTreeWalker(m,NodeFilter.SHOW_COMMENT,null,!1);u.nextNode();)o=u.currentNode,/^o:/.test(o.nodeValue)&&(i[+o.nodeValue.slice(2)]=o);for(a=0;a<h;++a)(o=i[a])&&o.parentNode.replaceChild(d[a],o)}return 1===m.childNodes.length?m.removeChild(m.firstChild):11===m.nodeType?((o=t()).appendChild(m),o):m}}var m=d(function(e){var t=document.createElement("template");return t.innerHTML=e.trim(),document.importNode(t.content,!0)},function(){return document.createElement("span")});function h(e){return function(){return e("marked@0.3.12/marked.min.js").then(function(t){return d(function(n){var r=document.createElement("span");r.innerHTML=t(n,{langPrefix:""}).trim();var o=r.querySelectorAll("pre code[class]");return o.length>0&&e("@observablehq/highlight.js@1.1.1/highlight.min.js").then(function(e){o.forEach(function(t){e.highlightBlock(t),t.parentNode.classList.add("observablehq--md-pre")})}),r},function(){return document.createElement("span")})})}}function v(e){let t;Object.defineProperties(this,{generator:{value:c(e=>void(t=e))},value:{get:()=>e,set:n=>t(e=n)}}),void 0!==e&&t(e)}function*w(){for(;;)yield Date.now()}var p=new Map;function b(e,n){var r;return(r=p.get(e=+e))?r.then(t(n)):(r=Date.now())>=e?Promise.resolve(n):function(e,t){var n=new Promise(function(n){p.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 p.set(t,n),n}(r,e).then(t(n))}var g={delay:function(e,t){return new Promise(function(n){setTimeout(function(){n(t)},e)})},tick:function(e,t){return b(Math.ceil((Date.now()+1)/e)*e,t)},when:b};function x(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 y=new Map,E=[],P=E.map,k=E.some,L=E.hasOwnProperty,j="https://cdn.jsdelivr.net/npm/",A=/^((?:@[^\/@]+\/)?[^\/@]+)(?:@([^\/]+))?(?:\/(.*))?$/,C=/^\d+\.\d+\.\d+(-[\w-.+]+)?$/,M=["unpkg","jsdelivr","browser","main"];class RequireError extends Error{constructor(e){super(e)}}function $(e){const t=A.exec(e);return t&&{name:t[1],version:t[2],path:t[3]}}function N(e){const t=`${j}${e.name}${e.version?`@${e.version}`:""}/package.json`;let n=y.get(t);return n||y.set(t,n=fetch(t).then(e=>{if(!e.ok)throw new RequireError("unable to load package.json");return e.redirected&&!y.has(e.url)&&y.set(e.url,n),e.json()})),n}RequireError.prototype.name=RequireError.name;const O=R(async function(e,t){if(e.startsWith(j)&&(e=e.substring(j.length)),/^(\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 RequireError("illegal name");const n=$(e);if(!n)return`${j}${e}`;if(!n.version&&null!=t&&t.startsWith(j)){const e=await N($(t.substring(j.length)));n.version=e.dependencies&&e.dependencies[n.name]||e.peerDependencies&&e.peerDependencies[n.name]}if(n.path&&!/\.[^\/]*$/.test(n.path)&&(n.path+=".js"),n.path&&n.version&&C.test(n.version))return`${j}${n.name}@${n.version}/${n.path}`;const r=await N(n);return`${j}${r.name}@${r.version}/${n.path||function(e){for(const t of M){const n=e[t];if("string"==typeof n)return n}}(r)||"index.js"}`});function R(e){const t=new Map,n=o(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(E.pop()(o(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=D,document.head.appendChild(r)})),n}function o(t){return n=>Promise.resolve(e(n,t)).then(r)}function i(e){return arguments.length>1?Promise.all(P.call(arguments,n)).then(S):n(e)}return i.alias=function(t){return R((n,r)=>n in t&&(r=null,"string"!=typeof(n=t[n]))?n:e(n,r))},i.resolve=e,i}function S(e){const t={};for(const n of e)for(const e in n)L.call(n,e)&&(null==n[e]?Object.defineProperty(t,e,{get:U(n,e)}):t[e]=n[e]);return t}function U(e,t){return()=>e[t]}function q(e){return e+""=="exports"}function D(e,t,n){const r=arguments.length;r<2?(n=e,t=[]):r<3&&(n=t,t="string"==typeof e?[]:e),E.push(k.call(t,q)?e=>{const r={};return Promise.all(P.call(t,t=>q(t+="")?r:e(t))).then(e=>(n.apply(null,e),r))}:e=>Promise.all(P.call(t,e)).then(e=>"function"==typeof n?n.apply(null,e):n))}function T(e){return null==e?O:R(e)}D.amd={};var F=d(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")}),W=String.raw;function _(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 B(e){return function(){return Promise.all([e("@observablehq/katex@0.10.1/dist/katex.min.js"),e.resolve("@observablehq/katex@0.10.1/dist/katex.min.css").then(_)]).then(function(e){var t=e[0],n=r();function r(e){return function(){var n=document.createElement("div");return t.render(W.apply(String,arguments),n,e),n.removeChild(n.firstChild)}}return n.options=r,n.block=r({displayMode:!0}),n})}}function H(){return c(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)}})}e.Library=function(e){const n=T(e);Object.defineProperties(this,{DOM:{value:i,writable:!0,enumerable:!0},Files:{value:u,writable:!0,enumerable:!0},Generators:{value:f,writable:!0,enumerable:!0},html:{value:t(m),writable:!0,enumerable:!0},md:{value:h(n),writable:!0,enumerable:!0},Mutable:{value:t(v),writable:!0,enumerable:!0},now:{value:w,writable:!0,enumerable:!0},Promises:{value:g,writable:!0,enumerable:!0},require:{value:t(n),writable:!0,enumerable:!0},resolve:{value:t(x),writable:!0,enumerable:!0},svg:{value:t(F),writable:!0,enumerable:!0},tex:{value:B(n),writable:!0,enumerable:!0},width:{value:H,writable:!0,enumerable:!0}})},Object.defineProperty(e,"__esModule",{value:!0})}); |
{ | ||
"name": "@observablehq/stdlib", | ||
"version": "2.0.3", | ||
"version": "2.0.4", | ||
"license": "ISC", | ||
@@ -5,0 +5,0 @@ "main": "dist/stdlib.js", |
@@ -62,2 +62,10 @@ # @observablehq/stdlib | ||
The *object* may also be specified as a function, in which case the function is called when the download button is clicked. For example: | ||
```js | ||
DOM.download(() => new Promise(resolve => canvas.toBlob(resolve))) | ||
``` | ||
If the *object* is a promise, or if it is a function that returns a promise, the promise will be awaited before downloading. If necessary, an additional click may be required to download the asynchronous value. | ||
<a href="#DOM_element" name="DOM_element">#</a> DOM.<b>element</b>(<i>name</i>[, <i>attributes</i>]) [<>](https://github.com/observablehq/stdlib/blob/master/src/dom/element.js "Source") | ||
@@ -64,0 +72,0 @@ |
@@ -1,11 +0,31 @@ | ||
export default function(object, name, label) { | ||
var a = document.createElement("a"), | ||
b = a.appendChild(document.createElement("button")); | ||
b.textContent = label == null ? "Download" : label; | ||
a.download = name == null ? "untitled" : name; | ||
a.onclick = function() { | ||
var url = a.href = URL.createObjectURL(object); | ||
setTimeout(function() { URL.revokeObjectURL(url); }, 50); | ||
export default function(value, name = "untitled", label = "Save") { | ||
const a = document.createElement("a"); | ||
const b = a.appendChild(document.createElement("button")); | ||
b.textContent = label; | ||
a.download = name; | ||
async function reset() { | ||
await new Promise(requestAnimationFrame); | ||
URL.revokeObjectURL(a.href); | ||
a.removeAttribute("href"); | ||
b.textContent = label; | ||
b.disabled = false; | ||
} | ||
a.onclick = async event => { | ||
b.disabled = true; | ||
if (a.href) return reset(); // Already saved. | ||
b.textContent = "Saving…"; | ||
try { | ||
const object = await (typeof value === "function" ? value() : value); | ||
b.textContent = "Download"; | ||
a.href = URL.createObjectURL(object); | ||
} catch (ignore) { | ||
b.textContent = label; | ||
} | ||
if (event.eventPhase) return reset(); // Already downloaded. | ||
b.disabled = false; | ||
}; | ||
return a; | ||
} |
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
68791
602
795