@decidables/prospectable-elements
Version:
prospectable-elements: Web Components for visualizing Cumulative Prospect Theory
1,639 lines (1,590 loc) • 1.61 MB
JavaScript
/**
* @license
* Copyright 2019 Google LLC
* SPDX-License-Identifier: BSD-3-Clause
*/
const t$2 = globalThis,
e$3 = t$2.ShadowRoot && (void 0 === t$2.ShadyCSS || t$2.ShadyCSS.nativeShadow) && "adoptedStyleSheets" in Document.prototype && "replace" in CSSStyleSheet.prototype,
s$4 = Symbol(),
o$6 = new WeakMap();
let n$4 = class n {
constructor(t, e, o) {
if (this._$cssResult$ = true, o !== s$4) throw Error("CSSResult is not constructable. Use `unsafeCSS` or `css` instead.");
this.cssText = t, this.t = e;
}
get styleSheet() {
let t = this.o;
const s = this.t;
if (e$3 && void 0 === t) {
const e = void 0 !== s && 1 === s.length;
e && (t = o$6.get(s)), void 0 === t && ((this.o = t = new CSSStyleSheet()).replaceSync(this.cssText), e && o$6.set(s, t));
}
return t;
}
toString() {
return this.cssText;
}
};
const r$4 = t => new n$4("string" == typeof t ? t : t + "", void 0, s$4),
i$5 = (t, ...e) => {
const o = 1 === t.length ? t[0] : e.reduce((e, s, o) => e + (t => {
if (true === t._$cssResult$) return t.cssText;
if ("number" == typeof t) return t;
throw Error("Value passed to 'css' function must be a 'css' function result: " + t + ". Use 'unsafeCSS' to pass non-literal values, but take care to ensure page security.");
})(s) + t[o + 1], t[0]);
return new n$4(o, t, s$4);
},
S$1 = (s, o) => {
if (e$3) s.adoptedStyleSheets = o.map(t => t instanceof CSSStyleSheet ? t : t.styleSheet);else for (const e of o) {
const o = document.createElement("style"),
n = t$2.litNonce;
void 0 !== n && o.setAttribute("nonce", n), o.textContent = e.cssText, s.appendChild(o);
}
},
c$6 = e$3 ? t => t : t => t instanceof CSSStyleSheet ? (t => {
let e = "";
for (const s of t.cssRules) e += s.cssText;
return r$4(e);
})(t) : t;
/**
* @license
* Copyright 2017 Google LLC
* SPDX-License-Identifier: BSD-3-Clause
*/
const {
is: i$4,
defineProperty: e$2,
getOwnPropertyDescriptor: h$2,
getOwnPropertyNames: r$3,
getOwnPropertySymbols: o$5,
getPrototypeOf: n$3
} = Object,
a$3 = globalThis,
c$5 = a$3.trustedTypes,
l$1 = c$5 ? c$5.emptyScript : "",
p$1 = a$3.reactiveElementPolyfillSupport,
d$2 = (t, s) => t,
u$1 = {
toAttribute(t, s) {
switch (s) {
case Boolean:
t = t ? l$1 : null;
break;
case Object:
case Array:
t = null == t ? t : JSON.stringify(t);
}
return t;
},
fromAttribute(t, s) {
let i = t;
switch (s) {
case Boolean:
i = null !== t;
break;
case Number:
i = null === t ? null : Number(t);
break;
case Object:
case Array:
try {
i = JSON.parse(t);
} catch (t) {
i = null;
}
}
return i;
}
},
f$3 = (t, s) => !i$4(t, s),
b$2 = {
attribute: true,
type: String,
converter: u$1,
reflect: false,
useDefault: false,
hasChanged: f$3
};
Symbol.metadata ??= Symbol("metadata"), a$3.litPropertyMetadata ??= new WeakMap();
let y$2 = class y extends HTMLElement {
static addInitializer(t) {
this._$Ei(), (this.l ??= []).push(t);
}
static get observedAttributes() {
return this.finalize(), this._$Eh && [...this._$Eh.keys()];
}
static createProperty(t, s = b$2) {
if (s.state && (s.attribute = false), this._$Ei(), this.prototype.hasOwnProperty(t) && ((s = Object.create(s)).wrapped = true), this.elementProperties.set(t, s), !s.noAccessor) {
const i = Symbol(),
h = this.getPropertyDescriptor(t, i, s);
void 0 !== h && e$2(this.prototype, t, h);
}
}
static getPropertyDescriptor(t, s, i) {
const {
get: e,
set: r
} = h$2(this.prototype, t) ?? {
get() {
return this[s];
},
set(t) {
this[s] = t;
}
};
return {
get: e,
set(s) {
const h = e?.call(this);
r?.call(this, s), this.requestUpdate(t, h, i);
},
configurable: true,
enumerable: true
};
}
static getPropertyOptions(t) {
return this.elementProperties.get(t) ?? b$2;
}
static _$Ei() {
if (this.hasOwnProperty(d$2("elementProperties"))) return;
const t = n$3(this);
t.finalize(), void 0 !== t.l && (this.l = [...t.l]), this.elementProperties = new Map(t.elementProperties);
}
static finalize() {
if (this.hasOwnProperty(d$2("finalized"))) return;
if (this.finalized = true, this._$Ei(), this.hasOwnProperty(d$2("properties"))) {
const t = this.properties,
s = [...r$3(t), ...o$5(t)];
for (const i of s) this.createProperty(i, t[i]);
}
const t = this[Symbol.metadata];
if (null !== t) {
const s = litPropertyMetadata.get(t);
if (void 0 !== s) for (const [t, i] of s) this.elementProperties.set(t, i);
}
this._$Eh = new Map();
for (const [t, s] of this.elementProperties) {
const i = this._$Eu(t, s);
void 0 !== i && this._$Eh.set(i, t);
}
this.elementStyles = this.finalizeStyles(this.styles);
}
static finalizeStyles(s) {
const i = [];
if (Array.isArray(s)) {
const e = new Set(s.flat(1 / 0).reverse());
for (const s of e) i.unshift(c$6(s));
} else void 0 !== s && i.push(c$6(s));
return i;
}
static _$Eu(t, s) {
const i = s.attribute;
return false === i ? void 0 : "string" == typeof i ? i : "string" == typeof t ? t.toLowerCase() : void 0;
}
constructor() {
super(), this._$Ep = void 0, this.isUpdatePending = false, this.hasUpdated = false, this._$Em = null, this._$Ev();
}
_$Ev() {
this._$ES = new Promise(t => this.enableUpdating = t), this._$AL = new Map(), this._$E_(), this.requestUpdate(), this.constructor.l?.forEach(t => t(this));
}
addController(t) {
(this._$EO ??= new Set()).add(t), void 0 !== this.renderRoot && this.isConnected && t.hostConnected?.();
}
removeController(t) {
this._$EO?.delete(t);
}
_$E_() {
const t = new Map(),
s = this.constructor.elementProperties;
for (const i of s.keys()) this.hasOwnProperty(i) && (t.set(i, this[i]), delete this[i]);
t.size > 0 && (this._$Ep = t);
}
createRenderRoot() {
const t = this.shadowRoot ?? this.attachShadow(this.constructor.shadowRootOptions);
return S$1(t, this.constructor.elementStyles), t;
}
connectedCallback() {
this.renderRoot ??= this.createRenderRoot(), this.enableUpdating(true), this._$EO?.forEach(t => t.hostConnected?.());
}
enableUpdating(t) {}
disconnectedCallback() {
this._$EO?.forEach(t => t.hostDisconnected?.());
}
attributeChangedCallback(t, s, i) {
this._$AK(t, i);
}
_$ET(t, s) {
const i = this.constructor.elementProperties.get(t),
e = this.constructor._$Eu(t, i);
if (void 0 !== e && true === i.reflect) {
const h = (void 0 !== i.converter?.toAttribute ? i.converter : u$1).toAttribute(s, i.type);
this._$Em = t, null == h ? this.removeAttribute(e) : this.setAttribute(e, h), this._$Em = null;
}
}
_$AK(t, s) {
const i = this.constructor,
e = i._$Eh.get(t);
if (void 0 !== e && this._$Em !== e) {
const t = i.getPropertyOptions(e),
h = "function" == typeof t.converter ? {
fromAttribute: t.converter
} : void 0 !== t.converter?.fromAttribute ? t.converter : u$1;
this._$Em = e;
const r = h.fromAttribute(s, t.type);
this[e] = r ?? this._$Ej?.get(e) ?? r, this._$Em = null;
}
}
requestUpdate(t, s, i) {
if (void 0 !== t) {
const e = this.constructor,
h = this[t];
if (i ??= e.getPropertyOptions(t), !((i.hasChanged ?? f$3)(h, s) || i.useDefault && i.reflect && h === this._$Ej?.get(t) && !this.hasAttribute(e._$Eu(t, i)))) return;
this.C(t, s, i);
}
false === this.isUpdatePending && (this._$ES = this._$EP());
}
C(t, s, {
useDefault: i,
reflect: e,
wrapped: h
}, r) {
i && !(this._$Ej ??= new Map()).has(t) && (this._$Ej.set(t, r ?? s ?? this[t]), true !== h || void 0 !== r) || (this._$AL.has(t) || (this.hasUpdated || i || (s = void 0), this._$AL.set(t, s)), true === e && this._$Em !== t && (this._$Eq ??= new Set()).add(t));
}
async _$EP() {
this.isUpdatePending = true;
try {
await this._$ES;
} catch (t) {
Promise.reject(t);
}
const t = this.scheduleUpdate();
return null != t && (await t), !this.isUpdatePending;
}
scheduleUpdate() {
return this.performUpdate();
}
performUpdate() {
if (!this.isUpdatePending) return;
if (!this.hasUpdated) {
if (this.renderRoot ??= this.createRenderRoot(), this._$Ep) {
for (const [t, s] of this._$Ep) this[t] = s;
this._$Ep = void 0;
}
const t = this.constructor.elementProperties;
if (t.size > 0) for (const [s, i] of t) {
const {
wrapped: t
} = i,
e = this[s];
true !== t || this._$AL.has(s) || void 0 === e || this.C(s, void 0, i, e);
}
}
let t = false;
const s = this._$AL;
try {
t = this.shouldUpdate(s), t ? (this.willUpdate(s), this._$EO?.forEach(t => t.hostUpdate?.()), this.update(s)) : this._$EM();
} catch (s) {
throw t = false, this._$EM(), s;
}
t && this._$AE(s);
}
willUpdate(t) {}
_$AE(t) {
this._$EO?.forEach(t => t.hostUpdated?.()), this.hasUpdated || (this.hasUpdated = true, this.firstUpdated(t)), this.updated(t);
}
_$EM() {
this._$AL = new Map(), this.isUpdatePending = false;
}
get updateComplete() {
return this.getUpdateComplete();
}
getUpdateComplete() {
return this._$ES;
}
shouldUpdate(t) {
return true;
}
update(t) {
this._$Eq &&= this._$Eq.forEach(t => this._$ET(t, this[t])), this._$EM();
}
updated(t) {}
firstUpdated(t) {}
};
y$2.elementStyles = [], y$2.shadowRootOptions = {
mode: "open"
}, y$2[d$2("elementProperties")] = new Map(), y$2[d$2("finalized")] = new Map(), p$1?.({
ReactiveElement: y$2
}), (a$3.reactiveElementVersions ??= []).push("2.1.1");
/**
* @license
* Copyright 2017 Google LLC
* SPDX-License-Identifier: BSD-3-Clause
*/
const t$1 = globalThis,
i$3 = t$1.trustedTypes,
s$3 = i$3 ? i$3.createPolicy("lit-html", {
createHTML: t => t
}) : void 0,
e$1 = "$lit$",
h$1 = `lit$${Math.random().toFixed(9).slice(2)}$`,
o$4 = "?" + h$1,
n$2 = `<${o$4}>`,
r$2 = document,
l = () => r$2.createComment(""),
c$4 = t => null === t || "object" != typeof t && "function" != typeof t,
a$2 = Array.isArray,
u = t => a$2(t) || "function" == typeof t?.[Symbol.iterator],
d$1 = "[ \t\n\f\r]",
f$2 = /<(?:(!--|\/[^a-zA-Z])|(\/?[a-zA-Z][^>\s]*)|(\/?$))/g,
v$1 = /-->/g,
_ = />/g,
m = RegExp(`>|${d$1}(?:([^\\s"'>=/]+)(${d$1}*=${d$1}*(?:[^ \t\n\f\r"'\`<>=]|("|')|))|$)`, "g"),
p = /'/g,
g$1 = /"/g,
$ = /^(?:script|style|textarea|title)$/i,
y$1 = t => (i, ...s) => ({
_$litType$: t,
strings: i,
values: s
}),
x$2 = y$1(1),
b$1 = y$1(2),
T = Symbol.for("lit-noChange"),
E$1 = Symbol.for("lit-nothing"),
A$2 = new WeakMap(),
C$1 = r$2.createTreeWalker(r$2, 129);
function P(t, i) {
if (!a$2(t) || !t.hasOwnProperty("raw")) throw Error("invalid template strings array");
return void 0 !== s$3 ? s$3.createHTML(i) : i;
}
const V = (t, i) => {
const s = t.length - 1,
o = [];
let r,
l = 2 === i ? "<svg>" : 3 === i ? "<math>" : "",
c = f$2;
for (let i = 0; i < s; i++) {
const s = t[i];
let a,
u,
d = -1,
y = 0;
for (; y < s.length && (c.lastIndex = y, u = c.exec(s), null !== u);) y = c.lastIndex, c === f$2 ? "!--" === u[1] ? c = v$1 : void 0 !== u[1] ? c = _ : void 0 !== u[2] ? ($.test(u[2]) && (r = RegExp("</" + u[2], "g")), c = m) : void 0 !== u[3] && (c = m) : c === m ? ">" === u[0] ? (c = r ?? f$2, d = -1) : void 0 === u[1] ? d = -2 : (d = c.lastIndex - u[2].length, a = u[1], c = void 0 === u[3] ? m : '"' === u[3] ? g$1 : p) : c === g$1 || c === p ? c = m : c === v$1 || c === _ ? c = f$2 : (c = m, r = void 0);
const x = c === m && t[i + 1].startsWith("/>") ? " " : "";
l += c === f$2 ? s + n$2 : d >= 0 ? (o.push(a), s.slice(0, d) + e$1 + s.slice(d) + h$1 + x) : s + h$1 + (-2 === d ? i : x);
}
return [P(t, l + (t[s] || "<?>") + (2 === i ? "</svg>" : 3 === i ? "</math>" : "")), o];
};
let N$1 = class N {
constructor({
strings: t,
_$litType$: s
}, n) {
let r;
this.parts = [];
let c = 0,
a = 0;
const u = t.length - 1,
d = this.parts,
[f, v] = V(t, s);
if (this.el = N.createElement(f, n), C$1.currentNode = this.el.content, 2 === s || 3 === s) {
const t = this.el.content.firstChild;
t.replaceWith(...t.childNodes);
}
for (; null !== (r = C$1.nextNode()) && d.length < u;) {
if (1 === r.nodeType) {
if (r.hasAttributes()) for (const t of r.getAttributeNames()) if (t.endsWith(e$1)) {
const i = v[a++],
s = r.getAttribute(t).split(h$1),
e = /([.?@])?(.*)/.exec(i);
d.push({
type: 1,
index: c,
name: e[2],
strings: s,
ctor: "." === e[1] ? H : "?" === e[1] ? I : "@" === e[1] ? L : k$1
}), r.removeAttribute(t);
} else t.startsWith(h$1) && (d.push({
type: 6,
index: c
}), r.removeAttribute(t));
if ($.test(r.tagName)) {
const t = r.textContent.split(h$1),
s = t.length - 1;
if (s > 0) {
r.textContent = i$3 ? i$3.emptyScript : "";
for (let i = 0; i < s; i++) r.append(t[i], l()), C$1.nextNode(), d.push({
type: 2,
index: ++c
});
r.append(t[s], l());
}
}
} else if (8 === r.nodeType) if (r.data === o$4) d.push({
type: 2,
index: c
});else {
let t = -1;
for (; -1 !== (t = r.data.indexOf(h$1, t + 1));) d.push({
type: 7,
index: c
}), t += h$1.length - 1;
}
c++;
}
}
static createElement(t, i) {
const s = r$2.createElement("template");
return s.innerHTML = t, s;
}
};
function S(t, i, s = t, e) {
if (i === T) return i;
let h = void 0 !== e ? s._$Co?.[e] : s._$Cl;
const o = c$4(i) ? void 0 : i._$litDirective$;
return h?.constructor !== o && (h?._$AO?.(false), void 0 === o ? h = void 0 : (h = new o(t), h._$AT(t, s, e)), void 0 !== e ? (s._$Co ??= [])[e] = h : s._$Cl = h), void 0 !== h && (i = S(t, h._$AS(t, i.values), h, e)), i;
}
let M$1 = class M {
constructor(t, i) {
this._$AV = [], this._$AN = void 0, this._$AD = t, this._$AM = i;
}
get parentNode() {
return this._$AM.parentNode;
}
get _$AU() {
return this._$AM._$AU;
}
u(t) {
const {
el: {
content: i
},
parts: s
} = this._$AD,
e = (t?.creationScope ?? r$2).importNode(i, true);
C$1.currentNode = e;
let h = C$1.nextNode(),
o = 0,
n = 0,
l = s[0];
for (; void 0 !== l;) {
if (o === l.index) {
let i;
2 === l.type ? i = new R(h, h.nextSibling, this, t) : 1 === l.type ? i = new l.ctor(h, l.name, l.strings, this, t) : 6 === l.type && (i = new z(h, this, t)), this._$AV.push(i), l = s[++n];
}
o !== l?.index && (h = C$1.nextNode(), o++);
}
return C$1.currentNode = r$2, e;
}
p(t) {
let i = 0;
for (const s of this._$AV) void 0 !== s && (void 0 !== s.strings ? (s._$AI(t, s, i), i += s.strings.length - 2) : s._$AI(t[i])), i++;
}
};
class R {
get _$AU() {
return this._$AM?._$AU ?? this._$Cv;
}
constructor(t, i, s, e) {
this.type = 2, this._$AH = E$1, this._$AN = void 0, this._$AA = t, this._$AB = i, this._$AM = s, this.options = e, this._$Cv = e?.isConnected ?? true;
}
get parentNode() {
let t = this._$AA.parentNode;
const i = this._$AM;
return void 0 !== i && 11 === t?.nodeType && (t = i.parentNode), t;
}
get startNode() {
return this._$AA;
}
get endNode() {
return this._$AB;
}
_$AI(t, i = this) {
t = S(this, t, i), c$4(t) ? t === E$1 || null == t || "" === t ? (this._$AH !== E$1 && this._$AR(), this._$AH = E$1) : t !== this._$AH && t !== T && this._(t) : void 0 !== t._$litType$ ? this.$(t) : void 0 !== t.nodeType ? this.T(t) : u(t) ? this.k(t) : this._(t);
}
O(t) {
return this._$AA.parentNode.insertBefore(t, this._$AB);
}
T(t) {
this._$AH !== t && (this._$AR(), this._$AH = this.O(t));
}
_(t) {
this._$AH !== E$1 && c$4(this._$AH) ? this._$AA.nextSibling.data = t : this.T(r$2.createTextNode(t)), this._$AH = t;
}
$(t) {
const {
values: i,
_$litType$: s
} = t,
e = "number" == typeof s ? this._$AC(t) : (void 0 === s.el && (s.el = N$1.createElement(P(s.h, s.h[0]), this.options)), s);
if (this._$AH?._$AD === e) this._$AH.p(i);else {
const t = new M$1(e, this),
s = t.u(this.options);
t.p(i), this.T(s), this._$AH = t;
}
}
_$AC(t) {
let i = A$2.get(t.strings);
return void 0 === i && A$2.set(t.strings, i = new N$1(t)), i;
}
k(t) {
a$2(this._$AH) || (this._$AH = [], this._$AR());
const i = this._$AH;
let s,
e = 0;
for (const h of t) e === i.length ? i.push(s = new R(this.O(l()), this.O(l()), this, this.options)) : s = i[e], s._$AI(h), e++;
e < i.length && (this._$AR(s && s._$AB.nextSibling, e), i.length = e);
}
_$AR(t = this._$AA.nextSibling, i) {
for (this._$AP?.(false, true, i); t !== this._$AB;) {
const i = t.nextSibling;
t.remove(), t = i;
}
}
setConnected(t) {
void 0 === this._$AM && (this._$Cv = t, this._$AP?.(t));
}
}
let k$1 = class k {
get tagName() {
return this.element.tagName;
}
get _$AU() {
return this._$AM._$AU;
}
constructor(t, i, s, e, h) {
this.type = 1, this._$AH = E$1, this._$AN = void 0, this.element = t, this.name = i, this._$AM = e, this.options = h, s.length > 2 || "" !== s[0] || "" !== s[1] ? (this._$AH = Array(s.length - 1).fill(new String()), this.strings = s) : this._$AH = E$1;
}
_$AI(t, i = this, s, e) {
const h = this.strings;
let o = false;
if (void 0 === h) t = S(this, t, i, 0), o = !c$4(t) || t !== this._$AH && t !== T, o && (this._$AH = t);else {
const e = t;
let n, r;
for (t = h[0], n = 0; n < h.length - 1; n++) r = S(this, e[s + n], i, n), r === T && (r = this._$AH[n]), o ||= !c$4(r) || r !== this._$AH[n], r === E$1 ? t = E$1 : t !== E$1 && (t += (r ?? "") + h[n + 1]), this._$AH[n] = r;
}
o && !e && this.j(t);
}
j(t) {
t === E$1 ? this.element.removeAttribute(this.name) : this.element.setAttribute(this.name, t ?? "");
}
};
class H extends k$1 {
constructor() {
super(...arguments), this.type = 3;
}
j(t) {
this.element[this.name] = t === E$1 ? void 0 : t;
}
}
class I extends k$1 {
constructor() {
super(...arguments), this.type = 4;
}
j(t) {
this.element.toggleAttribute(this.name, !!t && t !== E$1);
}
}
class L extends k$1 {
constructor(t, i, s, e, h) {
super(t, i, s, e, h), this.type = 5;
}
_$AI(t, i = this) {
if ((t = S(this, t, i, 0) ?? E$1) === T) return;
const s = this._$AH,
e = t === E$1 && s !== E$1 || t.capture !== s.capture || t.once !== s.once || t.passive !== s.passive,
h = t !== E$1 && (s === E$1 || e);
e && this.element.removeEventListener(this.name, this, s), h && this.element.addEventListener(this.name, this, t), this._$AH = t;
}
handleEvent(t) {
"function" == typeof this._$AH ? this._$AH.call(this.options?.host ?? this.element, t) : this._$AH.handleEvent(t);
}
}
class z {
constructor(t, i, s) {
this.element = t, this.type = 6, this._$AN = void 0, this._$AM = i, this.options = s;
}
get _$AU() {
return this._$AM._$AU;
}
_$AI(t) {
S(this, t);
}
}
const j$1 = t$1.litHtmlPolyfillSupport;
j$1?.(N$1, R), (t$1.litHtmlVersions ??= []).push("3.3.1");
const B$1 = (t, i, s) => {
const e = s?.renderBefore ?? i;
let h = e._$litPart$;
if (void 0 === h) {
const t = s?.renderBefore ?? null;
e._$litPart$ = h = new R(i.insertBefore(l(), t), t, void 0, s ?? {});
}
return h._$AI(t), h;
};
/**
* @license
* Copyright 2017 Google LLC
* SPDX-License-Identifier: BSD-3-Clause
*/
const s$2 = globalThis;
let i$2 = class i extends y$2 {
constructor() {
super(...arguments), this.renderOptions = {
host: this
}, this._$Do = void 0;
}
createRenderRoot() {
const t = super.createRenderRoot();
return this.renderOptions.renderBefore ??= t.firstChild, t;
}
update(t) {
const r = this.render();
this.hasUpdated || (this.renderOptions.isConnected = this.isConnected), super.update(t), this._$Do = B$1(r, this.renderRoot, this.renderOptions);
}
connectedCallback() {
super.connectedCallback(), this._$Do?.setConnected(true);
}
disconnectedCallback() {
super.disconnectedCallback(), this._$Do?.setConnected(false);
}
render() {
return T;
}
};
i$2._$litElement$ = true, i$2["finalized"] = true, s$2.litElementHydrateSupport?.({
LitElement: i$2
});
const o$3 = s$2.litElementPolyfillSupport;
o$3?.({
LitElement: i$2
});
(s$2.litElementVersions ??= []).push("4.2.1");
function ascending$1(a, b) {
return a == null || b == null ? NaN : a < b ? -1 : a > b ? 1 : a >= b ? 0 : NaN;
}
function descending$1(a, b) {
return a == null || b == null ? NaN : b < a ? -1 : b > a ? 1 : b >= a ? 0 : NaN;
}
function bisector(f) {
let compare1, compare2, delta;
// If an accessor is specified, promote it to a comparator. In this case we
// can test whether the search value is (self-) comparable. We can’t do this
// for a comparator (except for specific, known comparators) because we can’t
// tell if the comparator is symmetric, and an asymmetric comparator can’t be
// used to test whether a single value is comparable.
if (f.length !== 2) {
compare1 = ascending$1;
compare2 = (d, x) => ascending$1(f(d), x);
delta = (d, x) => f(d) - x;
} else {
compare1 = f === ascending$1 || f === descending$1 ? f : zero$1;
compare2 = f;
delta = f;
}
function left(a, x, lo = 0, hi = a.length) {
if (lo < hi) {
if (compare1(x, x) !== 0) return hi;
do {
const mid = lo + hi >>> 1;
if (compare2(a[mid], x) < 0) lo = mid + 1;else hi = mid;
} while (lo < hi);
}
return lo;
}
function right(a, x, lo = 0, hi = a.length) {
if (lo < hi) {
if (compare1(x, x) !== 0) return hi;
do {
const mid = lo + hi >>> 1;
if (compare2(a[mid], x) <= 0) lo = mid + 1;else hi = mid;
} while (lo < hi);
}
return lo;
}
function center(a, x, lo = 0, hi = a.length) {
const i = left(a, x, lo, hi - 1);
return i > lo && delta(a[i - 1], x) > -delta(a[i], x) ? i - 1 : i;
}
return {
left,
center,
right
};
}
function zero$1() {
return 0;
}
function number$4(x) {
return x === null ? NaN : +x;
}
function* numbers(values, valueof) {
if (valueof === undefined) {
for (let value of values) {
if (value != null && (value = +value) >= value) {
yield value;
}
}
} else {
let index = -1;
for (let value of values) {
if ((value = valueof(value, ++index, values)) != null && (value = +value) >= value) {
yield value;
}
}
}
}
const ascendingBisect = bisector(ascending$1);
const bisectRight = ascendingBisect.right;
bisector(number$4).center;
function count(values, valueof) {
let count = 0;
{
for (let value of values) {
if (value != null && (value = +value) >= value) {
++count;
}
}
}
return count;
}
function length$1(array) {
return array.length | 0;
}
function empty$1(length) {
return !(length > 0);
}
function arrayify$1(values) {
return typeof values !== "object" || "length" in values ? values : Array.from(values);
}
function reducer(reduce) {
return values => reduce(...values);
}
function cross(...values) {
const reduce = typeof values[values.length - 1] === "function" && reducer(values.pop());
values = values.map(arrayify$1);
const lengths = values.map(length$1);
const j = values.length - 1;
const index = new Array(j + 1).fill(0);
const product = [];
if (j < 0 || lengths.some(empty$1)) return product;
while (true) {
product.push(index.map((j, i) => values[i][j]));
let i = j;
while (++index[i] === lengths[i]) {
if (i === 0) return reduce ? product.map(reduce) : product;
index[i--] = 0;
}
}
}
function cumsum(values, valueof) {
var sum = 0;
return Float64Array.from(values, v => sum += +v || 0 );
}
function variance(values, valueof) {
let count = 0;
let delta;
let mean = 0;
let sum = 0;
if (valueof === undefined) {
for (let value of values) {
if (value != null && (value = +value) >= value) {
delta = value - mean;
mean += delta / ++count;
sum += delta * (value - mean);
}
}
} else {
let index = -1;
for (let value of values) {
if ((value = valueof(value, ++index, values)) != null && (value = +value) >= value) {
delta = value - mean;
mean += delta / ++count;
sum += delta * (value - mean);
}
}
}
if (count > 1) return sum / (count - 1);
}
function deviation(values, valueof) {
const v = variance(values, valueof);
return v ? Math.sqrt(v) : v;
}
function extent$1(values, valueof) {
let min;
let max;
if (valueof === undefined) {
for (const value of values) {
if (value != null) {
if (min === undefined) {
if (value >= value) min = max = value;
} else {
if (min > value) min = value;
if (max < value) max = value;
}
}
}
} else {
let index = -1;
for (let value of values) {
if ((value = valueof(value, ++index, values)) != null) {
if (min === undefined) {
if (value >= value) min = max = value;
} else {
if (min > value) min = value;
if (max < value) max = value;
}
}
}
}
return [min, max];
}
// https://github.com/python/cpython/blob/a74eea238f5baba15797e2e8b570d153bc8690a7/Modules/mathmodule.c#L1423
class Adder {
constructor() {
this._partials = new Float64Array(32);
this._n = 0;
}
add(x) {
const p = this._partials;
let i = 0;
for (let j = 0; j < this._n && j < 32; j++) {
const y = p[j],
hi = x + y,
lo = Math.abs(x) < Math.abs(y) ? x - (hi - y) : y - (hi - x);
if (lo) p[i++] = lo;
x = hi;
}
p[i] = x;
this._n = i + 1;
return this;
}
valueOf() {
const p = this._partials;
let n = this._n,
x,
y,
lo,
hi = 0;
if (n > 0) {
hi = p[--n];
while (n > 0) {
x = hi;
y = p[--n];
hi = x + y;
lo = y - (hi - x);
if (lo) break;
}
if (n > 0 && (lo < 0 && p[n - 1] < 0 || lo > 0 && p[n - 1] > 0)) {
y = lo * 2;
x = hi + y;
if (y == x - hi) hi = x;
}
}
return hi;
}
}
class InternMap extends Map {
constructor(entries, key = keyof$1) {
super();
Object.defineProperties(this, {
_intern: {
value: new Map()
},
_key: {
value: key
}
});
if (entries != null) for (const [key, value] of entries) this.set(key, value);
}
get(key) {
return super.get(intern_get(this, key));
}
has(key) {
return super.has(intern_get(this, key));
}
set(key, value) {
return super.set(intern_set(this, key), value);
}
delete(key) {
return super.delete(intern_delete(this, key));
}
}
class InternSet extends Set {
constructor(values, key = keyof$1) {
super();
Object.defineProperties(this, {
_intern: {
value: new Map()
},
_key: {
value: key
}
});
if (values != null) for (const value of values) this.add(value);
}
has(value) {
return super.has(intern_get(this, value));
}
add(value) {
return super.add(intern_set(this, value));
}
delete(value) {
return super.delete(intern_delete(this, value));
}
}
function intern_get({
_intern,
_key
}, value) {
const key = _key(value);
return _intern.has(key) ? _intern.get(key) : value;
}
function intern_set({
_intern,
_key
}, value) {
const key = _key(value);
if (_intern.has(key)) return _intern.get(key);
_intern.set(key, value);
return value;
}
function intern_delete({
_intern,
_key
}, value) {
const key = _key(value);
if (_intern.has(key)) {
value = _intern.get(key);
_intern.delete(key);
}
return value;
}
function keyof$1(value) {
return value !== null && typeof value === "object" ? value.valueOf() : value;
}
function identity$9(x) {
return x;
}
function group(values, ...keys) {
return nest(values, identity$9, identity$9, keys);
}
function rollup(values, reduce, ...keys) {
return nest(values, identity$9, reduce, keys);
}
function rollups(values, reduce, ...keys) {
return nest(values, Array.from, reduce, keys);
}
function nest(values, map, reduce, keys) {
return function regroup(values, i) {
if (i >= keys.length) return reduce(values);
const groups = new InternMap();
const keyof = keys[i++];
let index = -1;
for (const value of values) {
const key = keyof(value, ++index, values);
const group = groups.get(key);
if (group) group.push(value);else groups.set(key, [value]);
}
for (const [key, values] of groups) {
groups.set(key, regroup(values, i));
}
return map(groups);
}(values, 0);
}
function permute(source, keys) {
return Array.from(keys, key => source[key]);
}
function sort$1(values, ...F) {
if (typeof values[Symbol.iterator] !== "function") throw new TypeError("values is not iterable");
values = Array.from(values);
let [f] = F;
if (f && f.length !== 2 || F.length > 1) {
const index = Uint32Array.from(values, (d, i) => i);
if (F.length > 1) {
F = F.map(f => values.map(f));
index.sort((i, j) => {
for (const f of F) {
const c = ascendingDefined$1(f[i], f[j]);
if (c) return c;
}
});
} else {
f = values.map(f);
index.sort((i, j) => ascendingDefined$1(f[i], f[j]));
}
return permute(values, index);
}
return values.sort(compareDefined(f));
}
function compareDefined(compare = ascending$1) {
if (compare === ascending$1) return ascendingDefined$1;
if (typeof compare !== "function") throw new TypeError("compare is not a function");
return (a, b) => {
const x = compare(a, b);
if (x || x === 0) return x;
return (compare(b, b) === 0) - (compare(a, a) === 0);
};
}
function ascendingDefined$1(a, b) {
return (a == null || !(a >= a)) - (b == null || !(b >= b)) || (a < b ? -1 : a > b ? 1 : 0);
}
function groupSort(values, reduce, key) {
return (reduce.length !== 2 ? sort$1(rollup(values, reduce, key), ([ak, av], [bk, bv]) => ascending$1(av, bv) || ascending$1(ak, bk)) : sort$1(group(values, key), ([ak, av], [bk, bv]) => reduce(av, bv) || ascending$1(ak, bk))).map(([key]) => key);
}
const e10 = Math.sqrt(50),
e5 = Math.sqrt(10),
e2 = Math.sqrt(2);
function tickSpec(start, stop, count) {
const step = (stop - start) / Math.max(0, count),
power = Math.floor(Math.log10(step)),
error = step / Math.pow(10, power),
factor = error >= e10 ? 10 : error >= e5 ? 5 : error >= e2 ? 2 : 1;
let i1, i2, inc;
if (power < 0) {
inc = Math.pow(10, -power) / factor;
i1 = Math.round(start * inc);
i2 = Math.round(stop * inc);
if (i1 / inc < start) ++i1;
if (i2 / inc > stop) --i2;
inc = -inc;
} else {
inc = Math.pow(10, power) * factor;
i1 = Math.round(start / inc);
i2 = Math.round(stop / inc);
if (i1 * inc < start) ++i1;
if (i2 * inc > stop) --i2;
}
if (i2 < i1 && 0.5 <= count && count < 2) return tickSpec(start, stop, count * 2);
return [i1, i2, inc];
}
function ticks(start, stop, count) {
stop = +stop, start = +start, count = +count;
if (!(count > 0)) return [];
if (start === stop) return [start];
const reverse = stop < start,
[i1, i2, inc] = reverse ? tickSpec(stop, start, count) : tickSpec(start, stop, count);
if (!(i2 >= i1)) return [];
const n = i2 - i1 + 1,
ticks = new Array(n);
if (reverse) {
if (inc < 0) for (let i = 0; i < n; ++i) ticks[i] = (i2 - i) / -inc;else for (let i = 0; i < n; ++i) ticks[i] = (i2 - i) * inc;
} else {
if (inc < 0) for (let i = 0; i < n; ++i) ticks[i] = (i1 + i) / -inc;else for (let i = 0; i < n; ++i) ticks[i] = (i1 + i) * inc;
}
return ticks;
}
function tickIncrement(start, stop, count) {
stop = +stop, start = +start, count = +count;
return tickSpec(start, stop, count)[2];
}
function tickStep(start, stop, count) {
stop = +stop, start = +start, count = +count;
const reverse = stop < start,
inc = reverse ? tickIncrement(stop, start, count) : tickIncrement(start, stop, count);
return (reverse ? -1 : 1) * (inc < 0 ? 1 / -inc : inc);
}
function thresholdSturges(values) {
return Math.max(1, Math.ceil(Math.log(count(values)) / Math.LN2) + 1);
}
function max$1(values, valueof) {
let max;
if (valueof === undefined) {
for (const value of values) {
if (value != null && (max < value || max === undefined && value >= value)) {
max = value;
}
}
} else {
let index = -1;
for (let value of values) {
if ((value = valueof(value, ++index, values)) != null && (max < value || max === undefined && value >= value)) {
max = value;
}
}
}
return max;
}
function maxIndex(values, valueof) {
let max;
let maxIndex = -1;
let index = -1;
if (valueof === undefined) {
for (const value of values) {
++index;
if (value != null && (max < value || max === undefined && value >= value)) {
max = value, maxIndex = index;
}
}
} else {
for (let value of values) {
if ((value = valueof(value, ++index, values)) != null && (max < value || max === undefined && value >= value)) {
max = value, maxIndex = index;
}
}
}
return maxIndex;
}
function min$1(values, valueof) {
let min;
if (valueof === undefined) {
for (const value of values) {
if (value != null && (min > value || min === undefined && value >= value)) {
min = value;
}
}
} else {
let index = -1;
for (let value of values) {
if ((value = valueof(value, ++index, values)) != null && (min > value || min === undefined && value >= value)) {
min = value;
}
}
}
return min;
}
function minIndex(values, valueof) {
let min;
let minIndex = -1;
let index = -1;
if (valueof === undefined) {
for (const value of values) {
++index;
if (value != null && (min > value || min === undefined && value >= value)) {
min = value, minIndex = index;
}
}
} else {
for (let value of values) {
if ((value = valueof(value, ++index, values)) != null && (min > value || min === undefined && value >= value)) {
min = value, minIndex = index;
}
}
}
return minIndex;
}
// Based on https://github.com/mourner/quickselect
// ISC license, Copyright 2018 Vladimir Agafonkin.
function quickselect(array, k, left = 0, right = Infinity, compare) {
k = Math.floor(k);
left = Math.floor(Math.max(0, left));
right = Math.floor(Math.min(array.length - 1, right));
if (!(left <= k && k <= right)) return array;
compare = compare === undefined ? ascendingDefined$1 : compareDefined(compare);
while (right > left) {
if (right - left > 600) {
const n = right - left + 1;
const m = k - left + 1;
const z = Math.log(n);
const s = 0.5 * Math.exp(2 * z / 3);
const sd = 0.5 * Math.sqrt(z * s * (n - s) / n) * (m - n / 2 < 0 ? -1 : 1);
const newLeft = Math.max(left, Math.floor(k - m * s / n + sd));
const newRight = Math.min(right, Math.floor(k + (n - m) * s / n + sd));
quickselect(array, k, newLeft, newRight, compare);
}
const t = array[k];
let i = left;
let j = right;
swap(array, left, k);
if (compare(array[right], t) > 0) swap(array, left, right);
while (i < j) {
swap(array, i, j), ++i, --j;
while (compare(array[i], t) < 0) ++i;
while (compare(array[j], t) > 0) --j;
}
if (compare(array[left], t) === 0) swap(array, left, j);else ++j, swap(array, j, right);
if (j <= k) left = j + 1;
if (k <= j) right = j - 1;
}
return array;
}
function swap(array, i, j) {
const t = array[i];
array[i] = array[j];
array[j] = t;
}
function greatest(values, compare = ascending$1) {
let max;
let defined = false;
if (compare.length === 1) {
let maxValue;
for (const element of values) {
const value = compare(element);
if (defined ? ascending$1(value, maxValue) > 0 : ascending$1(value, value) === 0) {
max = element;
maxValue = value;
defined = true;
}
}
} else {
for (const value of values) {
if (defined ? compare(value, max) > 0 : compare(value, value) === 0) {
max = value;
defined = true;
}
}
}
return max;
}
function quantile$1(values, p, valueof) {
values = Float64Array.from(numbers(values, valueof));
if (!(n = values.length) || isNaN(p = +p)) return;
if (p <= 0 || n < 2) return min$1(values);
if (p >= 1) return max$1(values);
var n,
i = (n - 1) * p,
i0 = Math.floor(i),
value0 = max$1(quickselect(values, i0).subarray(0, i0 + 1)),
value1 = min$1(values.subarray(i0 + 1));
return value0 + (value1 - value0) * (i - i0);
}
function quantileSorted(values, p, valueof = number$4) {
if (!(n = values.length) || isNaN(p = +p)) return;
if (p <= 0 || n < 2) return +valueof(values[0], 0, values);
if (p >= 1) return +valueof(values[n - 1], n - 1, values);
var n,
i = (n - 1) * p,
i0 = Math.floor(i),
value0 = +valueof(values[i0], i0, values),
value1 = +valueof(values[i0 + 1], i0 + 1, values);
return value0 + (value1 - value0) * (i - i0);
}
function thresholdFreedmanDiaconis(values, min, max) {
const c = count(values),
d = quantile$1(values, 0.75) - quantile$1(values, 0.25);
return c && d ? Math.ceil((max - min) / (2 * d * Math.pow(c, -1 / 3))) : 1;
}
function thresholdScott(values, min, max) {
const c = count(values),
d = deviation(values);
return c && d ? Math.ceil((max - min) * Math.cbrt(c) / (3.49 * d)) : 1;
}
function mean(values, valueof) {
let count = 0;
let sum = 0;
if (valueof === undefined) {
for (let value of values) {
if (value != null && (value = +value) >= value) {
++count, sum += value;
}
}
} else {
let index = -1;
for (let value of values) {
if ((value = valueof(value, ++index, values)) != null && (value = +value) >= value) {
++count, sum += value;
}
}
}
if (count) return sum / count;
}
function median(values, valueof) {
return quantile$1(values, 0.5, valueof);
}
function* flatten(arrays) {
for (const array of arrays) {
yield* array;
}
}
function merge(arrays) {
return Array.from(flatten(arrays));
}
function mode(values, valueof) {
const counts = new InternMap();
if (valueof === undefined) {
for (let value of values) {
if (value != null && value >= value) {
counts.set(value, (counts.get(value) || 0) + 1);
}
}
} else {
let index = -1;
for (let value of values) {
if ((value = valueof(value, ++index, values)) != null && value >= value) {
counts.set(value, (counts.get(value) || 0) + 1);
}
}
}
let modeValue;
let modeCount = 0;
for (const [value, count] of counts) {
if (count > modeCount) {
modeCount = count;
modeValue = value;
}
}
return modeValue;
}
function pairs(values, pairof = pair) {
const pairs = [];
let previous;
let first = false;
for (const value of values) {
if (first) pairs.push(pairof(previous, value));
previous = value;
first = true;
}
return pairs;
}
function pair(a, b) {
return [a, b];
}
function range$1(start, stop, step) {
start = +start, stop = +stop, step = (n = arguments.length) < 2 ? (stop = start, start = 0, 1) : n < 3 ? 1 : +step;
var i = -1,
n = Math.max(0, Math.ceil((stop - start) / step)) | 0,
range = new Array(n);
while (++i < n) {
range[i] = start + i * step;
}
return range;
}
function sum(values, valueof) {
let sum = 0;
if (valueof === undefined) {
for (let value of values) {
if (value = +value) {
sum += value;
}
}
} else {
let index = -1;
for (let value of values) {
if (value = +valueof(value, ++index, values)) {
sum += value;
}
}
}
return sum;
}
function reverse(values) {
if (typeof values[Symbol.iterator] !== "function") throw new TypeError("values is not iterable");
return Array.from(values).reverse();
}
function identity$8 (x) {
return x;
}
var top = 1,
right = 2,
bottom = 3,
left = 4,
epsilon$3 = 1e-6;
function translateX(x) {
return "translate(" + x + ",0)";
}
function translateY(y) {
return "translate(0," + y + ")";
}
function number$3(scale) {
return d => +scale(d);
}
function center(scale, offset) {
offset = Math.max(0, scale.bandwidth() - offset * 2) / 2;
if (scale.round()) offset = Math.round(offset);
return d => +scale(d) + offset;
}
function entering() {
return !this.__axis;
}
function axis(orient, scale) {
var tickArguments = [],
tickValues = null,
tickFormat = null,
tickSizeInner = 6,
tickSizeOuter = 6,
tickPadding = 3,
offset = typeof window !== "undefined" && window.devicePixelRatio > 1 ? 0 : 0.5,
k = orient === top || orient === left ? -1 : 1,
x = orient === left || orient === right ? "x" : "y",
transform = orient === top || orient === bottom ? translateX : translateY;
function axis(context) {
var values = tickValues == null ? scale.ticks ? scale.ticks.apply(scale, tickArguments) : scale.domain() : tickValues,
format = tickFormat == null ? scale.tickFormat ? scale.tickFormat.apply(scale, tickArguments) : identity$8 : tickFormat,
spacing = Math.max(tickSizeInner, 0) + tickPadding,
range = scale.range(),
range0 = +range[0] + offset,
range1 = +range[range.length - 1] + offset,
position = (scale.bandwidth ? center : number$3)(scale.copy(), offset),
selection = context.selection ? context.selection() : context,
path = selection.selectAll(".domain").data([null]),
tick = selection.selectAll(".tick").data(values, scale).order(),
tickExit = tick.exit(),
tickEnter = tick.enter().append("g").attr("class", "tick"),
line = tick.select("line"),
text = tick.select("text");
path = path.merge(path.enter().insert("path", ".tick").attr("class", "domain").attr("stroke", "currentColor"));
tick = tick.merge(tickEnter);
line = line.merge(tickEnter.append("line").attr("stroke", "currentColor").attr(x + "2", k * tickSizeInner));
text = text.merge(tickEnter.append("text").attr("fill", "currentColor").attr(x, k * spacing).attr("dy", orient === top ? "0em" : orient === bottom ? "0.71em" : "0.32em"));
if (context !== selection) {
path = path.transition(context);
tick = tick.transition(context);
line = line.transition(context);
text = text.transition(context);
tickExit = tickExit.transition(context).attr("opacity", epsilon$3).attr("transform", function (d) {
return isFinite(d = position(d)) ? transform(d + offset) : this.getAttribute("transform");
});
tickEnter.attr("opacity", epsilon$3).attr("transform", function (d) {
var p = this.parentNode.__axis;
return transform((p && isFinite(p = p(d)) ? p : position(d)) + offset);
});
}
tickExit.remove();
path.attr("d", orient === left || orient === right ? tickSizeOuter ? "M" + k * tickSizeOuter + "," + range0 + "H" + offset + "V" + range1 + "H" + k * tickSizeOuter : "M" + offset + "," + range0 + "V" + range1 : tickSizeOuter ? "M" + range0 + "," + k * tickSizeOuter + "V" + offset + "H" + range1 + "V" + k * tickSizeOuter : "M" + range0 + "," + offset + "H" + range1);
tick.attr("opacity", 1).attr("transform", function (d) {
return transform(position(d) + offset);
});
line.attr(x + "2", k * tickSizeInner);
text.attr(x, k * spacing).text(format);
selection.filter(entering).attr("fill", "none").attr("font-size", 10).attr("font-family", "sans-serif").attr("text-anchor", orient === right ? "start" : orient === left ? "end" : "middle");
selection.each(function () {
this.__axis = position;
});
}
axis.scale = function (_) {
return arguments.length ? (scale = _, axis) : scale;
};
axis.ticks = function () {
return tickArguments = Array.from(arguments), axis;
};
axis.tickArguments = function (_) {
return arguments.length ? (tickArguments = _ == null ? [] : Array.from(_), axis) : tickArguments.slice();
};
axis.tickValues = function (_) {
return arguments.length ? (tickValues = _ == null ? null : Array.from(_), axis) : tickValues && tickValues.slice();
};
axis.tickFormat = function (_) {
return arguments.length ? (tickFormat = _, axis) : tickFormat;
};
axis.tickSize = function (_) {
return arguments.length ? (tickSizeInner = tickSizeOuter = +_, axis) : tickSizeInner;
};
axis.tickSizeInner = function (_) {
return arguments.length ? (tickSizeInner = +_, axis) : tickSizeInner;
};
axis.tickSizeOuter = function (_) {
return arguments.length ? (tickSizeOuter = +_, axis) : tickSizeOuter;
};
axis.tickPadding = function (_) {
return arguments.length ? (tickPadding = +_, axis) : tickPadding;
};
axis.offset = function (_) {
return arguments.length ? (offset = +_, axis) : offset;
};
return axis;
}
function axisBottom(scale) {
return axis(bottom, scale);
}
function axisLeft(scale) {
return axis(left, scale);
}
var noop$2 = {
value: () => {}
};
function dispatch() {
for (var i = 0, n = arguments.length, _ = {}, t; i < n; ++i) {
if (!(t = arguments[i] + "") || t in _ || /[\s.]/.test(t)) throw new Error("illegal type: " + t);
_[t] = [];
}
return new Dispatch(_);
}
function Dispatch(_) {
this._ = _;
}
function parseTypenames$1(typenames, types) {
return typenames.trim().split(/^|\s+/).map(function (t) {
var name = "",
i = t.indexOf(".");
if (i >= 0) name = t.slice(i + 1), t = t.slice(0, i);
if (t && !types.hasOwnProperty(t)) throw new Error("unknown type: " + t);
return {
type: t,
name: name
};
});
}
Dispatch.prototype = dispatch.prototype = {
constructor: Dispatch,
on: function (typename, callback) {
var _ = this._,
T = parseTypenames$1(typename + "", _),
t,
i = -1,
n = T.length;
// If no callback was specified, return the callback of the given type and name.
if (arguments.length < 2) {
while (++i < n) if ((t = (typename = T[i]).type) && (t = get$1(_[t], typename.name))) return t;
return;
}
// If a type was specified, set the callback for the given type and name.
// Otherwise, if a null callback was specified, remove callbacks of the given name.
if (callback != null && typeof callback !== "function") throw new Error("invalid callback: " + callback);
while (++i < n) {
if (t = (typename = T[i]).type) _[t] = set$1(_[t], typename.name, callback);else if (callback == null) for (t in _) _[t] = set$1(_[t], typename.name, null);
}
return this;
},
copy: function () {
var copy = {},
_ = this._;
for (var t in _) copy[t] = _[t].slice();
return new Dispatch(copy);
},
call: function (type, that) {
if ((n = arguments.length - 2) > 0) for (var args = new Array(n), i = 0, n, t; i < n; ++i) args[i] = arguments[i + 2];
if (!this._.hasOwnProperty(type)) throw new Error("unknown type: " + type);
for (t = this._[type], i = 0, n = t.length; i < n; ++i) t[i].value.apply(that, args);
},
apply: function (type, that, args) {
if (!this._.hasOwnProperty(type)) throw new Error("unknown type: " + type);
for (var t = this._[type], i = 0, n = t.length; i < n; ++i) t[i].value.apply(that, args);
}
};
function get$1(type, name) {
for (var i = 0, n = type.length, c; i < n; ++i) {
if ((c = type[i]).name === name) {
return c.value;
}
}
}
function set$1(type, name, callback) {
for (var i = 0, n = type.length; i < n; ++i) {
if (type[i].name === name) {
type[i] = noop$2, type = type.slice(0, i).concat(type.slice(i + 1));
break;
}
}
if (callback != null) type.push({
name: name,
value: callback
});
return type;
}
var xhtml = "http://www.w3.org/1999/xhtml";
var namespaces = {
svg: "http://www.w3.org/2000/svg",
xhtml: xhtml,
xlink: "http://www.w3.org/1999/xlink",
xml: "http://www.w3.org/XML/1998/namespace",
xmlns: "http://www.w3.org/2000/xmlns/"
};
function namespace (name) {
var prefix = name += "",
i = prefix.indexOf(":");
if (i >= 0 && (prefix = name.slice(0, i)) !== "xmlns") name = name.slice(i + 1);
return namespaces.hasOwnProperty(prefix) ? {
space: namespaces[prefix],
local: name
} : name; // eslint-disable-line no-prototype-builtins
}
function creatorInherit(name) {
return function () {
var document = this.ownerDocument,
uri = this.namespaceURI;
return uri === xhtml && document.documentElement.namespaceURI === xhtml ? document.createElement(name) : document.createElementNS(uri, name);
};
}
function creatorFixed(fullname) {
return function () {
return th