diff --git a/components.js b/components.js index 8a5dc36..1dbfa8a 100644 --- a/components.js +++ b/components.js @@ -15,6 +15,9 @@ import * as references from "./components/d-references"; import * as code from "./components/d-code"; import * as math from "./components/d-math"; import * as footnote from "./components/d-footnote"; +import * as footnoteList from "./components/d-footnote-list"; +import * as acknowledgements from "./components/d-acknowledgements"; +import * as cite from "./components/d-cite"; // let codeStyle = document.createElement("style"); // codeStyle.textContent = codeCss; diff --git a/components/citation.js b/components/citation.js new file mode 100644 index 0000000..4e8c8a6 --- /dev/null +++ b/components/citation.js @@ -0,0 +1,165 @@ +export function inline_cite_short(keys){ + function cite_string(key){ + if (key in data.bibliography){ + var n = data.citations.indexOf(key)+1; + return ""+n; + } else { + return "?"; + } + } + return "["+keys.map(cite_string).join(", ")+"]"; +} + +export function inline_cite_long(keys){ + function cite_string(key){ + if (key in data.bibliography){ + var ent = data.bibliography[key]; + var names = ent.author.split(" and "); + names = names.map(name => name.split(",")[0].trim()) + var year = ent.year; + if (names.length == 1) return names[0] + ", " + year; + if (names.length == 2) return names[0] + " & " + names[1] + ", " + year; + if (names.length > 2) return names[0] + ", et al., " + year; + } else { + return "?"; + } + } + return keys.map(cite_string).join(", "); +} + +function author_string(ent, template, sep, finalSep){ + var names = ent.author.split(" and "); + let name_strings = names.map(name => { + name = name.trim(); + if (name.indexOf(",") != -1){ + var last = name.split(",")[0].trim(); + var firsts = name.split(",")[1]; + } else { + var last = name.split(" ").slice(-1)[0].trim(); + var firsts = name.split(" ").slice(0,-1).join(" "); + } + var initials = ""; + if (firsts != undefined) { + initials = firsts.trim().split(" ").map(s => s.trim()[0]); + initials = initials.join(".")+"."; + } + return template.replace("${F}", firsts) + .replace("${L}", last) + .replace("${I}", initials); + }); + if (names.length > 1) { + var str = name_strings.slice(0, names.length-1).join(sep); + str += (finalSep || sep) + name_strings[names.length-1]; + return str; + } else { + return name_strings[0]; + } +} + +function venue_string(ent) { + var cite = (ent.journal || ent.booktitle || "") + if ("volume" in ent){ + var issue = ent.issue || ent.number; + issue = (issue != undefined)? "("+issue+")" : ""; + cite += ", Vol " + ent.volume + issue; + } + if ("pages" in ent){ + cite += ", pp. " + ent.pages + } + if (cite != "") cite += ". " + if ("publisher" in ent){ + cite += ent.publisher; + if (cite[cite.length-1] != ".") cite += "."; + } + return cite; +} + +function link_string(ent){ + if ("url" in ent){ + var url = ent.url; + var arxiv_match = (/arxiv\.org\/abs\/([0-9\.]*)/).exec(url); + if (arxiv_match != null){ + url = `http://arxiv.org/pdf/${arxiv_match[1]}.pdf`; + } + + if (url.slice(-4) == ".pdf"){ + var label = "PDF"; + } else if (url.slice(-5) == ".html") { + var label = "HTML"; + } + return `  [${label||"link"}]`; + }/* else if ("doi" in ent){ + return `  [DOI]`; + }*/ else { + return ""; + } +} +function doi_string(ent, new_line){ + if ("doi" in ent) { + return `${new_line?"
":""} DOI: ${ent.doi}`; + } else { + return ""; + } +} + +export function bibliography_cite(ent, fancy){ + if (ent){ + var cite = "" + ent.title + " " + cite += link_string(ent) + "
"; + cite += author_string(ent, "${L}, ${I}", ", ", " and "); + if (ent.year || ent.date){ + cite += ", " + (ent.year || ent.date) + ". " + } else { + cite += ". " + } + cite += venue_string(ent); + cite += doi_string(ent); + return cite + /*var cite = author_string(ent, "${L}, ${I}", ", ", " and "); + if (ent.year || ent.date){ + cite += ", " + (ent.year || ent.date) + ". " + } else { + cite += ". " + } + cite += "" + ent.title + ". "; + cite += venue_string(ent); + cite += doi_string(ent); + cite += link_string(ent); + return cite*/ + } else { + return "?"; + } +} + +export function hover_cite(ent){ + if (ent){ + var cite = ""; + cite += "" + ent.title + ""; + cite += link_string(ent); + cite += "
" + + var a_str = author_string(ent, "${I} ${L}", ", ") + "."; + var v_str = venue_string(ent).trim() + " " + ent.year + ". " + doi_string(ent, true); + + if ((a_str+v_str).length < Math.min(40, ent.title.length)) { + cite += a_str + " " + v_str; + } else { + cite += a_str + "
" + v_str; + } + return cite; + } else { + return "?"; + } +} + + +//https://scholar.google.com/scholar?q=allintitle%3ADocument+author%3Aolah +function get_GS_URL(ent){ + if (ent){ + var names = ent.author.split(" and "); + names = names.map(name => name.split(",")[0].trim()) + var title = ent.title.split(" ")//.replace(/[,:]/, "") + var url = "http://search.labs.crossref.org/dois?"//""https://scholar.google.com/scholar?" + url += uris({q: names.join(" ") + " " + title.join(" ")}) + } +} diff --git a/components/d-acknowledgements.js b/components/d-acknowledgements.js new file mode 100644 index 0000000..5aab8d7 --- /dev/null +++ b/components/d-acknowledgements.js @@ -0,0 +1,29 @@ +import { Template } from "../mixins/template"; + +const name = 'd-acknowledgements'; + +const T = Template(name, ` + + + +`); + +export default class Acknowledgements extends T(HTMLElement) { + + static get is() { return name; } + +} + +customElements.define(name, Acknowledgements); diff --git a/components/d-appendix.js b/components/d-appendix.js index 5d3e537..dc18787 100644 --- a/components/d-appendix.js +++ b/components/d-appendix.js @@ -1,38 +1,34 @@ -import {Template} from "../mixins/template"; -import {page} from "./layout"; +import { Template } from "../mixins/template"; +import { page } from "./layout"; const T = Template("d-appendix", ` - - -`, false); + +
+ +
+`); export default class Appendix extends T(HTMLElement) { + static get is() { return "d-appendix"; } + } customElements.define(Appendix.is, Appendix); diff --git a/components/d-article.js b/components/d-article.js index bdd9ca5..f77a9b4 100644 --- a/components/d-article.js +++ b/components/d-article.js @@ -21,16 +21,18 @@ const T = Template("d-article", ` /* H2 */ d-article h2 { - font-weight: 500; + font-weight: 400; font-size: 26px; line-height: 1.25em; margin-top: 36px; margin-bottom: 24px; + padding-bottom: 24px; + border-bottom: 1px solid rgba(0, 0, 0, 0.1); } @media(min-width: 1024px) { d-article h2 { - margin-top: 48px; - font-size: 26px; + margin-top: 2em; + font-size: 32px; } } d-article h1 + h2 { @@ -46,7 +48,7 @@ const T = Template("d-article", ` } d-article h1 + h2 { margin-top: 12px; - font-size: 24px; + font-size: 32px; } } diff --git a/components/d-bibliography.js b/components/d-bibliography.js index a6baf3d..f1b3606 100644 --- a/components/d-bibliography.js +++ b/components/d-bibliography.js @@ -1,38 +1,24 @@ -import {Template} from "../mixins/template"; -import {body} from "./layout"; import bibtexParse from "bibtex-parse-js"; -import mustache from "mustache"; -import {page} from "./layout"; +import { Template } from "../mixins/template"; +import { bibliography_cite } from "./citation"; - -let mustacheTemplate = ` +const name = 'd-bibliography'; +const T = Template(name, ` -{{#hasCitations}} -

References

-
    - {{#citations}} -
  1. -
    Unsupervised representation learning with deep convolutional generative adversarial networks  [PDF]
    -
    Radford, A., Metz, L. and Chintala, S., 2015. arXiv preprint arXiv:1511.06434.
    -
  2. - {{/citations}} -
-{{/hasCitations}} -`; -export default class Bibliography extends HTMLElement { - static get is() { return "d-bibliography"; } +

References

+
    +`); + +function parseBibtex(bibtex) { + const bibliography = new Map(); + const parsedEntries = bibtexParse.toJSON(bibtex); + for (const entry of parsedEntries) { + // normalize tags; note entryTags is an object, not Map + for (const tag in entry.entryTags) { + let value = entry.entryTags[tag]; + value = value.replace(/[\t\n ]+/g, " "); + value = value.replace(/{\\["^`\.'acu~Hvs]( )?([a-zA-Z])}/g, + (full, x, char) => char); + value = value.replace(/{\\([a-zA-Z])}/g, + (full, char) => char); + entry.entryTags[tag] = value; + } + entry.entryTags.type = entry.entryType; + // add to bibliography + bibliography.set(entry.citationKey, entry.entryTags); + } + return bibliography; +} + +export default class Bibliography extends T(HTMLElement) { + + constructor() { + super() + + this.citations = new Array(); + this.finishedLoading = false; + } connectedCallback() { - let s = this.querySelector("script"); - if (s) { - let bibliography = new Map(); - let rawBib = s.textContent; - let parsed = bibtexParse.toJSON(rawBib); - if(parsed) { - parsed.forEach(e => { - for (var k in e.entryTags) { - var val = e.entryTags[k]; - val = val.replace(/[\t\n ]+/g, " "); - val = val.replace(/{\\["^`\.'acu~Hvs]( )?([a-zA-Z])}/g, - (full, x, char) => char); - val = val.replace(/{\\([a-zA-Z])}/g, - (full, char) => char); - e.entryTags[k] = val; - } - e.entryTags.type = e.entryType; - bibliography.set(e.citationKey, e.entryTags); - }); + this.list = this.root.querySelector('ol'); + // bibliography is initially hidden + this.root.host.style.display = 'none'; + // parse bibliography + const scriptTag = this.querySelector("script"); + if (scriptTag) { + this.bibliography = parseBibtex(scriptTag.textContent); + this.finishedLoading = true; + // look through document and register existing citations + document.querySelectorAll('d-cite') + .forEach(citation => this.registerCitation(citation)); + } else { + console.error("No script tag with bibtex found in d-bibliography tag!") + } + + } + + getEntry(key) { + return this.bibliography.get(key); + } + + hasEntry(key) { + return this.bibliography.has(key); + } + + getIndex(key) { + return this.citations.indexOf(key); + } + + registerCitation(citation) { + // a d-cite element may cite multiple sources + const keyString = citation.getAttribute("key"); + const keys = keyString ? keyString.split(",") : []; + for (const key of keys) { + if (!this.bibliography.has(key)) { + console.error("Citation key '" + key + "' is not present in bibliography!") + } else if (this.citations.indexOf(key) === -1) { + this.citations.push(key); + const entry = this.getEntry(key); + // ensure citations list is visible + this.root.host.style.display = 'initial'; + // construct and append list item to show citation + const listItem = document.createElement('li'); + listItem.id = key; + listItem.innerHTML = bibliography_cite(entry); + this.list.appendChild(listItem); } - this.data = bibliography; - this.render(); } } - render() { - this.citations = []; - let citationElements = [].slice.apply(document.querySelectorAll("d-cite")); - citationElements.forEach(el => { this.cite(el) }); - this.innerHTML = mustache.render(mustacheTemplate, {hasCitations: this.citations.length > 0, citations: this.citations}); - } - - cite(el) { - let keyString = el.getAttribute("key"); - let keys = keyString ? keyString.split(",") : []; - keys.forEach(key => { - let citation = this.data[key]; - if (!this.data.has(key)) { - console.error("Citation key '" + key + "' not present in bibliography.") - } else if (this.citations.indexOf(key) !== -1) { - // Bibliography entry has already been cited - } else { - this.citations.push(key); - } - }) - - } } customElements.define(Bibliography.is, Bibliography); diff --git a/components/d-byline.js b/components/d-byline.js index 0423abf..93487b3 100644 --- a/components/d-byline.js +++ b/components/d-byline.js @@ -4,162 +4,165 @@ import {page} from "./layout"; const T = Template("d-byline", ` -`, false); + +
    +`); const mustacheTemplate = ` -
    -
    - {{#authors}} -
    - {{#personalURL}} - {{name}} - {{/personalURL}} - {{^personalURL}} -
    {{name}}
    - {{/personalURL}} - {{#affiliation}} - {{#affiliationURL}} - {{affiliation}} - {{/affiliationURL}} - {{^affiliationURL}} -
    {{affiliation}}
    - {{/affiliationURL}} - {{/affiliation}} -
    - {{/authors}} +
    +{{#authors}} +
    + {{#personalURL}} + {{name}} + {{/personalURL}} + {{^personalURL}} +
    {{name}}
    + {{/personalURL}} + {{#affiliation}} + {{#affiliationURL}} + {{affiliation}} + {{/affiliationURL}} + {{^affiliationURL}} +
    {{affiliation}}
    + {{/affiliationURL}} + {{/affiliation}}
    - {{#publishedDate}} -
    -
    {{publishedMonth}}. {{publishedDay}} {{publishedYear}
    -
    {{publishedYear}}
    -
    - {{/publishedDate}} - {{#citation}} - -
    Citation:
    -
    {{concatenatedAuthors}}, {{publishedYear}}
    -
    - {{/citation}} + {{/authors}}
    +{{#publishedDate}} +
    +
    {{publishedMonth}}. {{publishedDay}}
    +
    {{publishedYear}}
    +
    +{{/publishedDate}} +{{#citation}} + +
    Citation:
    +
    {{concatenatedAuthors}}, {{publishedYear}}
    +
    +{{/citation}} `; export default class Byline extends T(HTMLElement) { - static get is() { - return "d-byline"; - } - render(data) { - console.warn("byline!"); - this.innerHTML = mustache.render(mustacheTemplate, data); + + static get is() { return "d-byline"; } + + connectedCallback() { + const frontmatter = document.querySelector('d-front-matter'); + const container = this.root.querySelector('.byline'); + container.innerHTML = mustache.render(mustacheTemplate, frontmatter.data); + console.log(frontmatter.data) } + } customElements.define(Byline.is, Byline); diff --git a/components/d-cite.js b/components/d-cite.js index f340f92..7304794 100644 --- a/components/d-cite.js +++ b/components/d-cite.js @@ -1,10 +1,13 @@ -import {Template} from "../mixins/template"; +import { Template } from "../mixins/template"; +import { hover_cite } from "./citation"; +import { HoverBox } from "./hover-box"; -const T = Template("d-cite", ` - dt-cite { +const T = Template('d-cite', ` + -`, false); -export default class Cite extends T(HTMLElement) { - static get is() { return "d-cite"; } + + + + + + +`); + + +function inline_cite_short(keys, bibliography) { + function cite_string(key) { + if (bibliography.hasEntry(key)){ + return (bibliography.getIndex(key)+1).toString(); + } else { + return "?"; + } + } + return "[" + keys.map(cite_string).join(", ") + "]"; } -customElements.define(Cite.is, Cite); \ No newline at end of file + +export default class Cite extends T(HTMLElement) { + + constructor() { + super() + this._key = null; + + Cite.currentId += 1; + this.citeId = Cite.currentId; + } + + static get observedAttributes() { + return ['key']; + } + + attributeChangedCallback(name, oldValue, newValue) { + // name will always be "key" due to observedAttributes + this._key = newValue; + this.renderContent(); + } + + get key() { + return this._key; + } + + set key(value) { + this.setAttribute('key', value); + } + + renderContent() { + const bibliography = document.querySelector('d-bibliography'); + if (bibliography && bibliography.finishedLoading) { + customElements.whenDefined('d-bibliography').then( () => { + const keys = this.key.split(","); + + // set up hidden hover box + const div = this.root.querySelector('.dt-hover-box'); + div.innerHTML = keys.map( (key) => { + return bibliography.getEntry(key); + }).map(hover_cite).join('

    '); + div.id ='dt-cite-hover-box-' + this.citeId; + + // set up visible citation marker + const outerSpan = this.root.querySelector('#citation-'); + outerSpan.id = `citation-${this.citeId}`; + // outerSpan.setAttribute('data-hover', dataHoverString); // directly tell HoverBox instead? + const innerSpan = this.root.querySelector('.citation-number'); + innerSpan.textContent = inline_cite_short(keys, bibliography); + + HoverBox.get_box(div).bind(outerSpan); + }); + } else { + console.error(`You used a d-cite tag (${key}) without including a d-bibliography tag in your article. We can't lookup your citation this way.`) + } + } + +} + +Cite.currentId = 0; + +customElements.define(Cite.is, Cite); diff --git a/components/d-footnote-list.js b/components/d-footnote-list.js new file mode 100644 index 0000000..055216d --- /dev/null +++ b/components/d-footnote-list.js @@ -0,0 +1,72 @@ +import { Template } from "../mixins/template"; + +const name = 'd-footnote-list'; +const T = Template(name, ` + + +

    Footnotes

    +
      +`); + +export default class FootnoteList extends T(HTMLElement) { + + static get is() { return name; } + + connectedCallback() { + this.list = this.root.querySelector('ol'); + this.footnotes = new Map(); + // footnotes list is initially hidden + this.root.host.style.display = 'none'; + // look through document and register existing footnotes + document.querySelectorAll('d-footnote') + .forEach(footnote => this.registerFootnote(footnote)); + } + + registerFootnote(element) { + // check if we already know about this footnote + if (!this.footnotes.has(element.id)) { + this.footnotes.set(element.id, element); + // ensure footnote list is visible + this.root.host.style.display = 'initial' + // construct and append list item to show footnote + const listItem = document.createElement('li'); + listItem.innerHTML = element.innerHTML; + const backlink = document.createElement('a'); + backlink.setAttribute('class', 'footnote-backlink'); + backlink.textContent = '[↩]'; + backlink.href = `#${element.id}`; + listItem.appendChild(backlink); + this.list.appendChild(listItem); + } /*else { + console.debug('Had already registered footnote ' + element.id + '!') + }*/ + } + +} + +customElements.define(name, FootnoteList); diff --git a/components/d-footnote.js b/components/d-footnote.js index 0336aa0..db5941c 100644 --- a/components/d-footnote.js +++ b/components/d-footnote.js @@ -18,15 +18,16 @@ d-math[block] { `; -const TemplatedFootnote = Template("d-math", templateString); +const TemplatedFootnote = Template("d-footnote", templateString); export class Footnote extends TemplatedFootnote(HTMLElement) { - constructor() { - super(); - + connectedCallback() { + // create numeric ID Footnote.currentFootnoteId += 1; const IdString = Footnote.currentFootnoteId.toString(); + this.root.host.id = 'd-footnote-' + IdString; + // set up hidden hover box const div = this.root.querySelector('.dt-hover-box'); div.id = 'dt-fn-hover-box-' + IdString; @@ -36,8 +37,16 @@ export class Footnote extends TemplatedFootnote(HTMLElement) { span.setAttribute('id', 'fn-' + IdString); span.setAttribute('data-hover-ref', div.id); span.textContent = IdString; - + HoverBox.get_box(div).bind(span); + + // register with footnote list should there be one + const footnoteList = document.querySelector('d-footnote-list'); + if (footnoteList) { + customElements.whenDefined('d-footnote-list').then(() => { + footnoteList.registerFootnote(this); + }); + } } } diff --git a/components/d-front-matter.js b/components/d-front-matter.js index 4c29574..41b1dd5 100644 --- a/components/d-front-matter.js +++ b/components/d-front-matter.js @@ -1,4 +1,5 @@ import ymlParse from "js-yaml"; +import expandData from "../transforms/expand-data" export default class FrontMatter extends HTMLElement { static get is() { return "d-front-matter"; } @@ -7,15 +8,16 @@ export default class FrontMatter extends HTMLElement { this.data = {}; } connectedCallback() { - let el = this.querySelector("script"); + const el = this.querySelector("script"); if (el) { - let text = el.textContent; - this.parse(ymlParse.safeLoad(text)); + const text = el.textContent; + this.parse(ymlParse.safeLoad(text)); } } parse(localData) { this.data.title = localData.title ? localData.title : "Untitled"; this.data.description = localData.description ? localData.description : "No description."; + this.data.publishedDate = localData.published ? new Date(localData.published) : false; this.data.authors = localData.authors ? localData.authors : []; @@ -31,7 +33,7 @@ export default class FrontMatter extends HTMLElement { a.name = name; a.firstName = names.slice(0, names.length - 1).join(" "); a.lastName = names[names.length -1]; - if(localData.affiliations[i]) { + if (localData.affiliations[i]) { let affiliation = Object.keys(localData.affiliations[i])[0]; if ((typeof localData.affiliations[i]) === "string") { affiliation = localData.affiliations[i] @@ -42,7 +44,9 @@ export default class FrontMatter extends HTMLElement { } return a; }); + + expandData(null, this.data); } } -customElements.define(FrontMatter.is, FrontMatter); \ No newline at end of file +customElements.define(FrontMatter.is, FrontMatter); diff --git a/components/d-title.js b/components/d-title.js index b81d102..55630b2 100644 --- a/components/d-title.js +++ b/components/d-title.js @@ -3,13 +3,15 @@ import {page} from "./layout"; const T = Template("d-title", ` -`, false); + + + +`); export default class Title extends T(HTMLElement) { + static get is() { return "d-title"; } + connectedCallback() { super.connectedCallback(); - this.byline = document.createElement("d-byline"); - let frontMatter = document.querySelector("d-front-matter"); - this.byline.render(frontMatter.data); - this.appendChild(this.byline); + + // this.byline = document.createElement("d-byline"); + // this.appendChild(this.byline); } + } customElements.define(Title.is, Title); diff --git a/components/distill-appendix.js b/components/distill-appendix.js index cd80147..66f2809 100644 --- a/components/distill-appendix.js +++ b/components/distill-appendix.js @@ -3,18 +3,6 @@ import mustache from "mustache"; let mustacheTemplate = ` @@ -61,7 +54,7 @@ let mustacheTemplate = ` export default class DistillAppendix extends HTMLElement { static get is() { return "distill-appendix"; } - render(data) { + connectedCallback(data) { this.innerHTML = mustache.render(mustacheTemplate, data); } } diff --git a/components/layout.js b/components/layout.js index eb25978..45141a2 100644 --- a/components/layout.js +++ b/components/layout.js @@ -44,6 +44,29 @@ export function page(selector) { `; } +export function pagePadding(selector) { + return `${selector} { + width: auto; + padding-left: 24px; + padding-right: 24px; + box-sizing: border-box; + } + @media(min-width: 768px) { + ${selector} { + padding-left: 72px; + padding-right: 72px; + } + } + @media(min-width: 1080px) { + ${selector} { + width: 984px; + padding-left: auto; + padding-right: auto; + } + } + `; +} + export function screen(selector) { return `${selector} { width: auto; @@ -65,4 +88,4 @@ export function screen(selector) { } } `; -} \ No newline at end of file +} diff --git a/components/styles-base.css b/components/styles-base.css index 124a2b9..6ec03fb 100644 --- a/components/styles-base.css +++ b/components/styles-base.css @@ -21,6 +21,25 @@ figure { margin: 0; } +table { + border-collapse: collapse; + border-spacing: 0; +} + +table th { + text-align: left; +} + +table thead { + border-bottom: 1px solid rgba(0, 0, 0, 0.05); +} +table thead th { + padding-bottom: 0.5em; +} +table tbody :first-child td { + padding-top: 0.5em; +} + /* html, body, div, span, applet, object, iframe, h1, h2, h3, h4, h5, h6, p, blockquote, pre, diff --git a/components/styles-layout.css b/components/styles-layout.css index e48dea0..b7ab256 100644 --- a/components/styles-layout.css +++ b/components/styles-layout.css @@ -28,6 +28,7 @@ d-article > ul, d-article > d-abstract, d-article > d-code, d-article > d-math, +d-article > table, d-article section > div, d-article section > p, d-article section > h1, @@ -38,7 +39,8 @@ d-article section > figure, d-article section > ul, d-article section > d-abstract, d-article section > d-code, -d-article section > d-math { +d-article section > d-math, +d-article section > table, { width: auto; margin-left: 24px; margin-right: 24px; @@ -63,6 +65,7 @@ d-article section > d-math { d-article > d-abstract, d-article > d-code, d-article > d-math, + d-article > d-math, d-article section > div, d-article section > p, d-article section > h1, @@ -73,7 +76,8 @@ d-article section > d-math { d-article section > ul, d-article section > d-abstract, d-article section > d-code, - d-article section > d-math { + d-article section > d-math, + d-article section > table { margin-left: 72px; margin-right: 72px; } @@ -91,6 +95,7 @@ d-article section > d-math { d-article > d-abstract, d-article > d-code, d-article > d-math, + d-article > table, d-article section > div, d-article section > p, d-article section > h2, @@ -100,7 +105,8 @@ d-article section > d-math { d-article section > ul, d-article section > d-abstract, d-article section > d-code, - d-article section > d-math { + d-article section > d-math, + d-article section > table { margin-left: calc(50% - 984px / 2); width: 648px; } diff --git a/components/styles.js b/components/styles.js index 4fc4c37..2fabc7c 100644 --- a/components/styles.js +++ b/components/styles.js @@ -4,6 +4,6 @@ import article from "./styles-article.css"; import print from "./styles-print.css"; let s = document.createElement("style"); -s.textContent = base + layout + print; +s.textContent = base + layout + print + article; document.querySelector("head").appendChild(s); export default s; diff --git a/dist/components.js b/dist/components.js index d442195..7589d5f 100644 --- a/dist/components.js +++ b/dist/components.js @@ -246,8 +246,6 @@ function Type$2(tag, options) { var type = Type$2; -/*eslint-disable max-len*/ - var common$4 = common$1; var YAMLException$3 = exception; var Type$1 = type; @@ -857,8 +855,6 @@ function createCommonjsModule(fn, module) { return module = { exports: {} }, fn(module, module.exports), module.exports; } -/*eslint-disable no-bitwise*/ - var NodeBuffer; try { @@ -1316,8 +1312,6 @@ var default_full = Schema$6.DEFAULT = new Schema$6({ ] }); -/*eslint-disable max-len,no-use-before-define*/ - var common = common$1; var YAMLException$1 = exception; var Mark = mark; @@ -2909,8 +2903,6 @@ var loader$1 = { safeLoad: safeLoad_1 }; -/*eslint-disable no-use-before-define*/ - var common$7 = common$1; var YAMLException$5 = exception; var DEFAULT_FULL_SCHEMA$2 = default_full; @@ -3780,6 +3772,893 @@ var yaml = jsYaml; var index = yaml; +var t0 = new Date; +var t1 = new Date; + +function newInterval(floori, offseti, count, field) { + + function interval(date) { + return floori(date = new Date(+date)), date; + } + + interval.floor = interval; + + interval.ceil = function(date) { + return floori(date = new Date(date - 1)), offseti(date, 1), floori(date), date; + }; + + interval.round = function(date) { + var d0 = interval(date), + d1 = interval.ceil(date); + return date - d0 < d1 - date ? d0 : d1; + }; + + interval.offset = function(date, step) { + return offseti(date = new Date(+date), step == null ? 1 : Math.floor(step)), date; + }; + + interval.range = function(start, stop, step) { + var range = []; + start = interval.ceil(start); + step = step == null ? 1 : Math.floor(step); + if (!(start < stop) || !(step > 0)) return range; // also handles Invalid Date + do range.push(new Date(+start)); while (offseti(start, step), floori(start), start < stop) + return range; + }; + + interval.filter = function(test) { + return newInterval(function(date) { + if (date >= date) while (floori(date), !test(date)) date.setTime(date - 1); + }, function(date, step) { + if (date >= date) while (--step >= 0) while (offseti(date, 1), !test(date)) {} // eslint-disable-line no-empty + }); + }; + + if (count) { + interval.count = function(start, end) { + t0.setTime(+start), t1.setTime(+end); + floori(t0), floori(t1); + return Math.floor(count(t0, t1)); + }; + + interval.every = function(step) { + step = Math.floor(step); + return !isFinite(step) || !(step > 0) ? null + : !(step > 1) ? interval + : interval.filter(field + ? function(d) { return field(d) % step === 0; } + : function(d) { return interval.count(0, d) % step === 0; }); + }; + } + + return interval; +} + +var millisecond = newInterval(function() { + // noop +}, function(date, step) { + date.setTime(+date + step); +}, function(start, end) { + return end - start; +}); + +// An optimized implementation for this simple case. +millisecond.every = function(k) { + k = Math.floor(k); + if (!isFinite(k) || !(k > 0)) return null; + if (!(k > 1)) return millisecond; + return newInterval(function(date) { + date.setTime(Math.floor(date / k) * k); + }, function(date, step) { + date.setTime(+date + step * k); + }, function(start, end) { + return (end - start) / k; + }); +}; + +var durationSecond = 1e3; +var durationMinute = 6e4; +var durationHour = 36e5; +var durationDay = 864e5; +var durationWeek = 6048e5; + +var second = newInterval(function(date) { + date.setTime(Math.floor(date / durationSecond) * durationSecond); +}, function(date, step) { + date.setTime(+date + step * durationSecond); +}, function(start, end) { + return (end - start) / durationSecond; +}, function(date) { + return date.getUTCSeconds(); +}); + +var minute = newInterval(function(date) { + date.setTime(Math.floor(date / durationMinute) * durationMinute); +}, function(date, step) { + date.setTime(+date + step * durationMinute); +}, function(start, end) { + return (end - start) / durationMinute; +}, function(date) { + return date.getMinutes(); +}); + +var hour = newInterval(function(date) { + var offset = date.getTimezoneOffset() * durationMinute % durationHour; + if (offset < 0) offset += durationHour; + date.setTime(Math.floor((+date - offset) / durationHour) * durationHour + offset); +}, function(date, step) { + date.setTime(+date + step * durationHour); +}, function(start, end) { + return (end - start) / durationHour; +}, function(date) { + return date.getHours(); +}); + +var day = newInterval(function(date) { + date.setHours(0, 0, 0, 0); +}, function(date, step) { + date.setDate(date.getDate() + step); +}, function(start, end) { + return (end - start - (end.getTimezoneOffset() - start.getTimezoneOffset()) * durationMinute) / durationDay; +}, function(date) { + return date.getDate() - 1; +}); + +function weekday(i) { + return newInterval(function(date) { + date.setDate(date.getDate() - (date.getDay() + 7 - i) % 7); + date.setHours(0, 0, 0, 0); + }, function(date, step) { + date.setDate(date.getDate() + step * 7); + }, function(start, end) { + return (end - start - (end.getTimezoneOffset() - start.getTimezoneOffset()) * durationMinute) / durationWeek; + }); +} + +var sunday = weekday(0); +var monday = weekday(1); +var tuesday = weekday(2); +var wednesday = weekday(3); +var thursday = weekday(4); +var friday = weekday(5); +var saturday = weekday(6); + +var month = newInterval(function(date) { + date.setDate(1); + date.setHours(0, 0, 0, 0); +}, function(date, step) { + date.setMonth(date.getMonth() + step); +}, function(start, end) { + return end.getMonth() - start.getMonth() + (end.getFullYear() - start.getFullYear()) * 12; +}, function(date) { + return date.getMonth(); +}); + +var year = newInterval(function(date) { + date.setMonth(0, 1); + date.setHours(0, 0, 0, 0); +}, function(date, step) { + date.setFullYear(date.getFullYear() + step); +}, function(start, end) { + return end.getFullYear() - start.getFullYear(); +}, function(date) { + return date.getFullYear(); +}); + +// An optimized implementation for this simple case. +year.every = function(k) { + return !isFinite(k = Math.floor(k)) || !(k > 0) ? null : newInterval(function(date) { + date.setFullYear(Math.floor(date.getFullYear() / k) * k); + date.setMonth(0, 1); + date.setHours(0, 0, 0, 0); + }, function(date, step) { + date.setFullYear(date.getFullYear() + step * k); + }); +}; + +var utcMinute = newInterval(function(date) { + date.setUTCSeconds(0, 0); +}, function(date, step) { + date.setTime(+date + step * durationMinute); +}, function(start, end) { + return (end - start) / durationMinute; +}, function(date) { + return date.getUTCMinutes(); +}); + +var utcHour = newInterval(function(date) { + date.setUTCMinutes(0, 0, 0); +}, function(date, step) { + date.setTime(+date + step * durationHour); +}, function(start, end) { + return (end - start) / durationHour; +}, function(date) { + return date.getUTCHours(); +}); + +var utcDay = newInterval(function(date) { + date.setUTCHours(0, 0, 0, 0); +}, function(date, step) { + date.setUTCDate(date.getUTCDate() + step); +}, function(start, end) { + return (end - start) / durationDay; +}, function(date) { + return date.getUTCDate() - 1; +}); + +function utcWeekday(i) { + return newInterval(function(date) { + date.setUTCDate(date.getUTCDate() - (date.getUTCDay() + 7 - i) % 7); + date.setUTCHours(0, 0, 0, 0); + }, function(date, step) { + date.setUTCDate(date.getUTCDate() + step * 7); + }, function(start, end) { + return (end - start) / durationWeek; + }); +} + +var utcSunday = utcWeekday(0); +var utcMonday = utcWeekday(1); +var utcTuesday = utcWeekday(2); +var utcWednesday = utcWeekday(3); +var utcThursday = utcWeekday(4); +var utcFriday = utcWeekday(5); +var utcSaturday = utcWeekday(6); + +var utcMonth = newInterval(function(date) { + date.setUTCDate(1); + date.setUTCHours(0, 0, 0, 0); +}, function(date, step) { + date.setUTCMonth(date.getUTCMonth() + step); +}, function(start, end) { + return end.getUTCMonth() - start.getUTCMonth() + (end.getUTCFullYear() - start.getUTCFullYear()) * 12; +}, function(date) { + return date.getUTCMonth(); +}); + +var utcYear = newInterval(function(date) { + date.setUTCMonth(0, 1); + date.setUTCHours(0, 0, 0, 0); +}, function(date, step) { + date.setUTCFullYear(date.getUTCFullYear() + step); +}, function(start, end) { + return end.getUTCFullYear() - start.getUTCFullYear(); +}, function(date) { + return date.getUTCFullYear(); +}); + +// An optimized implementation for this simple case. +utcYear.every = function(k) { + return !isFinite(k = Math.floor(k)) || !(k > 0) ? null : newInterval(function(date) { + date.setUTCFullYear(Math.floor(date.getUTCFullYear() / k) * k); + date.setUTCMonth(0, 1); + date.setUTCHours(0, 0, 0, 0); + }, function(date, step) { + date.setUTCFullYear(date.getUTCFullYear() + step * k); + }); +}; + +function localDate(d) { + if (0 <= d.y && d.y < 100) { + var date = new Date(-1, d.m, d.d, d.H, d.M, d.S, d.L); + date.setFullYear(d.y); + return date; + } + return new Date(d.y, d.m, d.d, d.H, d.M, d.S, d.L); +} + +function utcDate(d) { + if (0 <= d.y && d.y < 100) { + var date = new Date(Date.UTC(-1, d.m, d.d, d.H, d.M, d.S, d.L)); + date.setUTCFullYear(d.y); + return date; + } + return new Date(Date.UTC(d.y, d.m, d.d, d.H, d.M, d.S, d.L)); +} + +function newYear(y) { + return {y: y, m: 0, d: 1, H: 0, M: 0, S: 0, L: 0}; +} + +function formatLocale(locale) { + var locale_dateTime = locale.dateTime, + locale_date = locale.date, + locale_time = locale.time, + locale_periods = locale.periods, + locale_weekdays = locale.days, + locale_shortWeekdays = locale.shortDays, + locale_months = locale.months, + locale_shortMonths = locale.shortMonths; + + var periodRe = formatRe(locale_periods), + periodLookup = formatLookup(locale_periods), + weekdayRe = formatRe(locale_weekdays), + weekdayLookup = formatLookup(locale_weekdays), + shortWeekdayRe = formatRe(locale_shortWeekdays), + shortWeekdayLookup = formatLookup(locale_shortWeekdays), + monthRe = formatRe(locale_months), + monthLookup = formatLookup(locale_months), + shortMonthRe = formatRe(locale_shortMonths), + shortMonthLookup = formatLookup(locale_shortMonths); + + var formats = { + "a": formatShortWeekday, + "A": formatWeekday, + "b": formatShortMonth, + "B": formatMonth, + "c": null, + "d": formatDayOfMonth, + "e": formatDayOfMonth, + "H": formatHour24, + "I": formatHour12, + "j": formatDayOfYear, + "L": formatMilliseconds, + "m": formatMonthNumber, + "M": formatMinutes, + "p": formatPeriod, + "S": formatSeconds, + "U": formatWeekNumberSunday, + "w": formatWeekdayNumber, + "W": formatWeekNumberMonday, + "x": null, + "X": null, + "y": formatYear, + "Y": formatFullYear, + "Z": formatZone, + "%": formatLiteralPercent + }; + + var utcFormats = { + "a": formatUTCShortWeekday, + "A": formatUTCWeekday, + "b": formatUTCShortMonth, + "B": formatUTCMonth, + "c": null, + "d": formatUTCDayOfMonth, + "e": formatUTCDayOfMonth, + "H": formatUTCHour24, + "I": formatUTCHour12, + "j": formatUTCDayOfYear, + "L": formatUTCMilliseconds, + "m": formatUTCMonthNumber, + "M": formatUTCMinutes, + "p": formatUTCPeriod, + "S": formatUTCSeconds, + "U": formatUTCWeekNumberSunday, + "w": formatUTCWeekdayNumber, + "W": formatUTCWeekNumberMonday, + "x": null, + "X": null, + "y": formatUTCYear, + "Y": formatUTCFullYear, + "Z": formatUTCZone, + "%": formatLiteralPercent + }; + + var parses = { + "a": parseShortWeekday, + "A": parseWeekday, + "b": parseShortMonth, + "B": parseMonth, + "c": parseLocaleDateTime, + "d": parseDayOfMonth, + "e": parseDayOfMonth, + "H": parseHour24, + "I": parseHour24, + "j": parseDayOfYear, + "L": parseMilliseconds, + "m": parseMonthNumber, + "M": parseMinutes, + "p": parsePeriod, + "S": parseSeconds, + "U": parseWeekNumberSunday, + "w": parseWeekdayNumber, + "W": parseWeekNumberMonday, + "x": parseLocaleDate, + "X": parseLocaleTime, + "y": parseYear, + "Y": parseFullYear, + "Z": parseZone, + "%": parseLiteralPercent + }; + + // These recursive directive definitions must be deferred. + formats.x = newFormat(locale_date, formats); + formats.X = newFormat(locale_time, formats); + formats.c = newFormat(locale_dateTime, formats); + utcFormats.x = newFormat(locale_date, utcFormats); + utcFormats.X = newFormat(locale_time, utcFormats); + utcFormats.c = newFormat(locale_dateTime, utcFormats); + + function newFormat(specifier, formats) { + return function(date) { + var string = [], + i = -1, + j = 0, + n = specifier.length, + c, + pad, + format; + + if (!(date instanceof Date)) date = new Date(+date); + + while (++i < n) { + if (specifier.charCodeAt(i) === 37) { + string.push(specifier.slice(j, i)); + if ((pad = pads[c = specifier.charAt(++i)]) != null) c = specifier.charAt(++i); + else pad = c === "e" ? " " : "0"; + if (format = formats[c]) c = format(date, pad); + string.push(c); + j = i + 1; + } + } + + string.push(specifier.slice(j, i)); + return string.join(""); + }; + } + + function newParse(specifier, newDate) { + return function(string) { + var d = newYear(1900), + i = parseSpecifier(d, specifier, string += "", 0); + if (i != string.length) return null; + + // The am-pm flag is 0 for AM, and 1 for PM. + if ("p" in d) d.H = d.H % 12 + d.p * 12; + + // Convert day-of-week and week-of-year to day-of-year. + if ("W" in d || "U" in d) { + if (!("w" in d)) d.w = "W" in d ? 1 : 0; + var day$$1 = "Z" in d ? utcDate(newYear(d.y)).getUTCDay() : newDate(newYear(d.y)).getDay(); + d.m = 0; + d.d = "W" in d ? (d.w + 6) % 7 + d.W * 7 - (day$$1 + 5) % 7 : d.w + d.U * 7 - (day$$1 + 6) % 7; + } + + // If a time zone is specified, all fields are interpreted as UTC and then + // offset according to the specified time zone. + if ("Z" in d) { + d.H += d.Z / 100 | 0; + d.M += d.Z % 100; + return utcDate(d); + } + + // Otherwise, all fields are in local time. + return newDate(d); + }; + } + + function parseSpecifier(d, specifier, string, j) { + var i = 0, + n = specifier.length, + m = string.length, + c, + parse; + + while (i < n) { + if (j >= m) return -1; + c = specifier.charCodeAt(i++); + if (c === 37) { + c = specifier.charAt(i++); + parse = parses[c in pads ? specifier.charAt(i++) : c]; + if (!parse || ((j = parse(d, string, j)) < 0)) return -1; + } else if (c != string.charCodeAt(j++)) { + return -1; + } + } + + return j; + } + + function parsePeriod(d, string, i) { + var n = periodRe.exec(string.slice(i)); + return n ? (d.p = periodLookup[n[0].toLowerCase()], i + n[0].length) : -1; + } + + function parseShortWeekday(d, string, i) { + var n = shortWeekdayRe.exec(string.slice(i)); + return n ? (d.w = shortWeekdayLookup[n[0].toLowerCase()], i + n[0].length) : -1; + } + + function parseWeekday(d, string, i) { + var n = weekdayRe.exec(string.slice(i)); + return n ? (d.w = weekdayLookup[n[0].toLowerCase()], i + n[0].length) : -1; + } + + function parseShortMonth(d, string, i) { + var n = shortMonthRe.exec(string.slice(i)); + return n ? (d.m = shortMonthLookup[n[0].toLowerCase()], i + n[0].length) : -1; + } + + function parseMonth(d, string, i) { + var n = monthRe.exec(string.slice(i)); + return n ? (d.m = monthLookup[n[0].toLowerCase()], i + n[0].length) : -1; + } + + function parseLocaleDateTime(d, string, i) { + return parseSpecifier(d, locale_dateTime, string, i); + } + + function parseLocaleDate(d, string, i) { + return parseSpecifier(d, locale_date, string, i); + } + + function parseLocaleTime(d, string, i) { + return parseSpecifier(d, locale_time, string, i); + } + + function formatShortWeekday(d) { + return locale_shortWeekdays[d.getDay()]; + } + + function formatWeekday(d) { + return locale_weekdays[d.getDay()]; + } + + function formatShortMonth(d) { + return locale_shortMonths[d.getMonth()]; + } + + function formatMonth(d) { + return locale_months[d.getMonth()]; + } + + function formatPeriod(d) { + return locale_periods[+(d.getHours() >= 12)]; + } + + function formatUTCShortWeekday(d) { + return locale_shortWeekdays[d.getUTCDay()]; + } + + function formatUTCWeekday(d) { + return locale_weekdays[d.getUTCDay()]; + } + + function formatUTCShortMonth(d) { + return locale_shortMonths[d.getUTCMonth()]; + } + + function formatUTCMonth(d) { + return locale_months[d.getUTCMonth()]; + } + + function formatUTCPeriod(d) { + return locale_periods[+(d.getUTCHours() >= 12)]; + } + + return { + format: function(specifier) { + var f = newFormat(specifier += "", formats); + f.toString = function() { return specifier; }; + return f; + }, + parse: function(specifier) { + var p = newParse(specifier += "", localDate); + p.toString = function() { return specifier; }; + return p; + }, + utcFormat: function(specifier) { + var f = newFormat(specifier += "", utcFormats); + f.toString = function() { return specifier; }; + return f; + }, + utcParse: function(specifier) { + var p = newParse(specifier, utcDate); + p.toString = function() { return specifier; }; + return p; + } + }; +} + +var pads = {"-": "", "_": " ", "0": "0"}; +var numberRe = /^\s*\d+/; +var percentRe = /^%/; +var requoteRe = /[\\\^\$\*\+\?\|\[\]\(\)\.\{\}]/g; + +function pad(value, fill, width) { + var sign = value < 0 ? "-" : "", + string = (sign ? -value : value) + "", + length = string.length; + return sign + (length < width ? new Array(width - length + 1).join(fill) + string : string); +} + +function requote(s) { + return s.replace(requoteRe, "\\$&"); +} + +function formatRe(names) { + return new RegExp("^(?:" + names.map(requote).join("|") + ")", "i"); +} + +function formatLookup(names) { + var map = {}, i = -1, n = names.length; + while (++i < n) map[names[i].toLowerCase()] = i; + return map; +} + +function parseWeekdayNumber(d, string, i) { + var n = numberRe.exec(string.slice(i, i + 1)); + return n ? (d.w = +n[0], i + n[0].length) : -1; +} + +function parseWeekNumberSunday(d, string, i) { + var n = numberRe.exec(string.slice(i)); + return n ? (d.U = +n[0], i + n[0].length) : -1; +} + +function parseWeekNumberMonday(d, string, i) { + var n = numberRe.exec(string.slice(i)); + return n ? (d.W = +n[0], i + n[0].length) : -1; +} + +function parseFullYear(d, string, i) { + var n = numberRe.exec(string.slice(i, i + 4)); + return n ? (d.y = +n[0], i + n[0].length) : -1; +} + +function parseYear(d, string, i) { + var n = numberRe.exec(string.slice(i, i + 2)); + return n ? (d.y = +n[0] + (+n[0] > 68 ? 1900 : 2000), i + n[0].length) : -1; +} + +function parseZone(d, string, i) { + var n = /^(Z)|([+-]\d\d)(?:\:?(\d\d))?/.exec(string.slice(i, i + 6)); + return n ? (d.Z = n[1] ? 0 : -(n[2] + (n[3] || "00")), i + n[0].length) : -1; +} + +function parseMonthNumber(d, string, i) { + var n = numberRe.exec(string.slice(i, i + 2)); + return n ? (d.m = n[0] - 1, i + n[0].length) : -1; +} + +function parseDayOfMonth(d, string, i) { + var n = numberRe.exec(string.slice(i, i + 2)); + return n ? (d.d = +n[0], i + n[0].length) : -1; +} + +function parseDayOfYear(d, string, i) { + var n = numberRe.exec(string.slice(i, i + 3)); + return n ? (d.m = 0, d.d = +n[0], i + n[0].length) : -1; +} + +function parseHour24(d, string, i) { + var n = numberRe.exec(string.slice(i, i + 2)); + return n ? (d.H = +n[0], i + n[0].length) : -1; +} + +function parseMinutes(d, string, i) { + var n = numberRe.exec(string.slice(i, i + 2)); + return n ? (d.M = +n[0], i + n[0].length) : -1; +} + +function parseSeconds(d, string, i) { + var n = numberRe.exec(string.slice(i, i + 2)); + return n ? (d.S = +n[0], i + n[0].length) : -1; +} + +function parseMilliseconds(d, string, i) { + var n = numberRe.exec(string.slice(i, i + 3)); + return n ? (d.L = +n[0], i + n[0].length) : -1; +} + +function parseLiteralPercent(d, string, i) { + var n = percentRe.exec(string.slice(i, i + 1)); + return n ? i + n[0].length : -1; +} + +function formatDayOfMonth(d, p) { + return pad(d.getDate(), p, 2); +} + +function formatHour24(d, p) { + return pad(d.getHours(), p, 2); +} + +function formatHour12(d, p) { + return pad(d.getHours() % 12 || 12, p, 2); +} + +function formatDayOfYear(d, p) { + return pad(1 + day.count(year(d), d), p, 3); +} + +function formatMilliseconds(d, p) { + return pad(d.getMilliseconds(), p, 3); +} + +function formatMonthNumber(d, p) { + return pad(d.getMonth() + 1, p, 2); +} + +function formatMinutes(d, p) { + return pad(d.getMinutes(), p, 2); +} + +function formatSeconds(d, p) { + return pad(d.getSeconds(), p, 2); +} + +function formatWeekNumberSunday(d, p) { + return pad(sunday.count(year(d), d), p, 2); +} + +function formatWeekdayNumber(d) { + return d.getDay(); +} + +function formatWeekNumberMonday(d, p) { + return pad(monday.count(year(d), d), p, 2); +} + +function formatYear(d, p) { + return pad(d.getFullYear() % 100, p, 2); +} + +function formatFullYear(d, p) { + return pad(d.getFullYear() % 10000, p, 4); +} + +function formatZone(d) { + var z = d.getTimezoneOffset(); + return (z > 0 ? "-" : (z *= -1, "+")) + + pad(z / 60 | 0, "0", 2) + + pad(z % 60, "0", 2); +} + +function formatUTCDayOfMonth(d, p) { + return pad(d.getUTCDate(), p, 2); +} + +function formatUTCHour24(d, p) { + return pad(d.getUTCHours(), p, 2); +} + +function formatUTCHour12(d, p) { + return pad(d.getUTCHours() % 12 || 12, p, 2); +} + +function formatUTCDayOfYear(d, p) { + return pad(1 + utcDay.count(utcYear(d), d), p, 3); +} + +function formatUTCMilliseconds(d, p) { + return pad(d.getUTCMilliseconds(), p, 3); +} + +function formatUTCMonthNumber(d, p) { + return pad(d.getUTCMonth() + 1, p, 2); +} + +function formatUTCMinutes(d, p) { + return pad(d.getUTCMinutes(), p, 2); +} + +function formatUTCSeconds(d, p) { + return pad(d.getUTCSeconds(), p, 2); +} + +function formatUTCWeekNumberSunday(d, p) { + return pad(utcSunday.count(utcYear(d), d), p, 2); +} + +function formatUTCWeekdayNumber(d) { + return d.getUTCDay(); +} + +function formatUTCWeekNumberMonday(d, p) { + return pad(utcMonday.count(utcYear(d), d), p, 2); +} + +function formatUTCYear(d, p) { + return pad(d.getUTCFullYear() % 100, p, 2); +} + +function formatUTCFullYear(d, p) { + return pad(d.getUTCFullYear() % 10000, p, 4); +} + +function formatUTCZone() { + return "+0000"; +} + +function formatLiteralPercent() { + return "%"; +} + +var locale$1; +var timeFormat; +var timeParse; +var utcFormat; +var utcParse; + +defaultLocale({ + dateTime: "%x, %X", + date: "%-m/%-d/%Y", + time: "%-I:%M:%S %p", + periods: ["AM", "PM"], + days: ["Sunday", "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday"], + shortDays: ["Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat"], + months: ["January", "February", "March", "April", "May", "June", "July", "August", "September", "October", "November", "December"], + shortMonths: ["Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec"] +}); + +function defaultLocale(definition) { + locale$1 = formatLocale(definition); + timeFormat = locale$1.format; + timeParse = locale$1.parse; + utcFormat = locale$1.utcFormat; + utcParse = locale$1.utcParse; + return locale$1; +} + +var isoSpecifier = "%Y-%m-%dT%H:%M:%S.%LZ"; + +function formatIsoNative(date) { + return date.toISOString(); +} + +var formatIso = Date.prototype.toISOString + ? formatIsoNative + : utcFormat(isoSpecifier); + +function parseIsoNative(string) { + var date = new Date(string); + return isNaN(date) ? null : date; +} + +var parseIso = +new Date("2000-01-01T00:00:00.000Z") + ? parseIsoNative + : utcParse(isoSpecifier); + +var expandData = function(dom, data) { + + data.authors = data.authors || []; + + // paths + data.url = "http://distill.pub/" + data.distillPath; + data.githubUrl = "https://github.com/" + data.githubPath; + + // Homepage + //data.homepage = !post.noHomepage; + data.journal = data.journal || {}; + + // Dates + if (data.publishedDate){//} && data.journal) { + data.volume = data.publishedDate.getFullYear() - 2015; + data.issue = data.publishedDate.getMonth() + 1; + } + + data.publishedDate = data.publishedDate ? data.publishedDate : new Date("Invalid"); + data.updatedDate = data.updatedDate ? data.updatedDate : new Date("Invalid"); + + let RFC = timeFormat("%a, %d %b %Y %H:%M:%S %Z"); + let months = ["Jan", "Feb", "March", "April", "May", "June", "July", "Aug", "Sept", "Oct", "Nov", "Dec"]; + let zeroPad = (n) => { return n < 10 ? "0" + n : n; }; + data.publishedDateRFC = RFC(data.publishedDate); + data.publishedYear = data.publishedDate.getFullYear(); + data.publishedMonth = months[data.publishedDate.getMonth()]; + data.publishedDay = data.publishedDate.getDate(); + data.publishedMonthPadded = zeroPad(data.publishedDate.getMonth() + 1); + data.publishedDayPadded = zeroPad(data.publishedDate.getDate()); + data.updatedDateRFC = RFC(data.updatedDate); + + if (data.authors.length > 2) { + data.concatenatedAuthors = data.authors[0].lastName + ", et al."; + } else if (data.authors.length === 2) { + data.concatenatedAuthors = data.authors[0].lastName + " & " + data.authors[1].lastName; + } else if (data.authors.length === 1) { + data.concatenatedAuthors = data.authors[0].lastName; + } + + data.bibtexAuthors = data.authors.map(function(author){ + return author.lastName + ", " + author.firstName; + }).join(" and "); + + data.slug = data.authors.length ? data.authors[0].lastName.toLowerCase() + data.publishedYear + data.title.split(" ")[0].toLowerCase() : "Untitled"; + +}; + class FrontMatter extends HTMLElement { static get is() { return "d-front-matter"; } constructor() { @@ -3787,15 +4666,16 @@ class FrontMatter extends HTMLElement { this.data = {}; } connectedCallback() { - let el = this.querySelector("script"); + const el = this.querySelector("script"); if (el) { - let text = el.textContent; - this.parse(index.safeLoad(text)); + const text = el.textContent; + this.parse(index.safeLoad(text)); } } parse(localData) { this.data.title = localData.title ? localData.title : "Untitled"; this.data.description = localData.description ? localData.description : "No description."; + this.data.publishedDate = localData.published ? new Date(localData.published) : false; this.data.authors = localData.authors ? localData.authors : []; @@ -3811,7 +4691,7 @@ class FrontMatter extends HTMLElement { a.name = name; a.firstName = names.slice(0, names.length - 1).join(" "); a.lastName = names[names.length -1]; - if(localData.affiliations[i]) { + if (localData.affiliations[i]) { let affiliation = Object.keys(localData.affiliations[i])[0]; if ((typeof localData.affiliations[i]) === "string") { affiliation = localData.affiliations[i]; @@ -3822,6 +4702,8 @@ class FrontMatter extends HTMLElement { } return a; }); + + expandData(null, this.data); } } @@ -3839,6 +4721,8 @@ const Template = (name, templateString, useShadow = true) => { return (superclass) => { return class extends superclass { + static get is() { return name; } + constructor() { super(); @@ -3923,13 +4807,15 @@ function page(selector) { const T = Template("d-title", ` -`, false); + + + +`); class Title extends T(HTMLElement) { + static get is() { return "d-title"; } + connectedCallback() { super.connectedCallback(); - this.byline = document.createElement("d-byline"); - let frontMatter = document.querySelector("d-front-matter"); - this.byline.render(frontMatter.data); - this.appendChild(this.byline); + + // this.byline = document.createElement("d-byline"); + // this.appendChild(this.byline); } + } customElements.define(Title.is, Title); @@ -4589,162 +5486,165 @@ var mustache = createCommonjsModule(function (module, exports) { const T$1 = Template("d-byline", ` -`, false); + + +`); const mustacheTemplate = ` -