@xiee/utils 1.5.3 → 1.5.5

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -5,7 +5,7 @@
5
5
  context.font = "72px monospace";
6
6
  const size = context.measureText(text).width;
7
7
  for (let font of [' SC', ' CN', ' TC', ' TW', '']) {
8
- context.font = `72px 'Source Han Serif ${font}', monospace`;
8
+ context.font = `72px 'Source Han Serif${font}', monospace`;
9
9
  // no need to load TypeKit if Source Hans Serif has been installed
10
10
  if (context.measureText(text).width != size) return;
11
11
  }
@@ -1 +1 @@
1
- (e=>{const t=e.createElement("canvas").getContext("2d"),a="abcdefghijklmnopqrstuvwxyz0123456789";t.font="72px monospace";const n=t.measureText(a).width;for(let e of[" SC"," CN"," TC"," TW",""])if(t.font=`72px 'Source Han Serif ${e}', monospace`,t.measureText(a).width!=n)return;let o,c={kitId:"kwz5xar",scriptTimeout:3e3,async:!0},s=e.documentElement,i=setTimeout((function(){s.className=s.className.replace(/\bwf-loading\b/g,"")+" wf-inactive"}),c.scriptTimeout),r=e.createElement("script"),m=!1,l=e.getElementsByTagName("script")[0];s.className+=" wf-loading",r.src="https://use.typekit.net/"+c.kitId+".js",r.async=!0,r.onload=r.onreadystatechange=function(){if(o=this.readyState,!(m||o&&"complete"!=o&&"loaded"!=o)){m=!0,clearTimeout(i);try{Typekit.load(c)}catch(e){}}},l.parentNode.insertBefore(r,l)})(document);
1
+ (e=>{const t=e.createElement("canvas").getContext("2d"),a="abcdefghijklmnopqrstuvwxyz0123456789";t.font="72px monospace";const n=t.measureText(a).width;for(let e of[" SC"," CN"," TC"," TW",""])if(t.font=`72px 'Source Han Serif${e}', monospace`,t.measureText(a).width!=n)return;let o,c={kitId:"kwz5xar",scriptTimeout:3e3,async:!0},s=e.documentElement,i=setTimeout((function(){s.className=s.className.replace(/\bwf-loading\b/g,"")+" wf-inactive"}),c.scriptTimeout),r=e.createElement("script"),m=!1,l=e.getElementsByTagName("script")[0];s.className+=" wf-loading",r.src="https://use.typekit.net/"+c.kitId+".js",r.async=!0,r.onload=r.onreadystatechange=function(){if(o=this.readyState,!(m||o&&"complete"!=o&&"loaded"!=o)){m=!0,clearTimeout(i);try{Typekit.load(c)}catch(e){}}},l.parentNode.insertBefore(r,l)})(document);
package/js/sidenotes.js CHANGED
@@ -14,9 +14,15 @@
14
14
  // add footnote number
15
15
  s.firstElementChild.insertAdjacentHTML('afterbegin', `<span class="bg-number">${a.innerText}</span> `);
16
16
  s.querySelector('a[href^="#fnref"]')?.remove(); // remove backreference
17
+ s.className += ' footnotes';
17
18
  } else {
18
19
  s.innerHTML = el.outerHTML;
19
20
  }
21
+ while (s.lastChild?.nodeName === '#text' && /^\s*$/.test(s.lastChild.textContent)) {
22
+ s.lastChild.remove();
23
+ }
24
+ // remove fullwidth classes if present (because they cannot be used in the margin)
25
+ s.querySelectorAll('.fullwidth').forEach(el => el.classList.remove('fullwidth'));
20
26
  // insert note after the <sup> or <span> that contains a
21
27
  a2.after(s);
22
28
  a2.classList.add('note-ref');
@@ -28,4 +34,20 @@
28
34
  });
29
35
  // also add side classes to TOC
30
36
  d.getElementById('TOC')?.classList.add('side', 'side-left');
37
+ // if a sidenote collapses with any fullwidth element, remove the side class
38
+ const sides = d.querySelectorAll('.side.side-right, .side.side-left'), fulls = [];
39
+ d.querySelectorAll('.fullwidth').forEach(el => {
40
+ fulls.push([el, el.getBoundingClientRect()]);
41
+ });
42
+ // add a class to document body if it has sidenotes
43
+ sides.length && d.body.classList.add('has-sidenotes');
44
+ sides.forEach(s => {
45
+ const r1 = s.getBoundingClientRect();
46
+ for (let f of fulls) {
47
+ const r2 = f[1];
48
+ if (!(r1.right < r2.left || r1.left > r2.right || r1.bottom < r2.top || r1.top > r2.bottom)) {
49
+ f[0].classList.remove('fullwidth');
50
+ }
51
+ }
52
+ });
31
53
  })(document);
@@ -1 +1 @@
1
- (e=>{e.querySelectorAll('.footnotes > ol > li[id^="fn"], #refs > div[id^="ref-"]').forEach((t=>{const r=`a[href="#${t.id}"]`,n=e.querySelector(`${r} > sup, sup > ${r}, .citation > ${r}`);if(!n)return;const s=n.parentNode;("A"===n.tagName?n:s).removeAttribute("href");const i=e.createElement("div");i.className="side side-right",/^fn/.test(t.id)?(i.innerHTML=t.innerHTML,i.firstElementChild.insertAdjacentHTML("afterbegin",`<span class="bg-number">${n.innerText}</span> `),i.querySelector('a[href^="#fnref"]')?.remove()):i.innerHTML=t.outerHTML,s.after(i),s.classList.add("note-ref"),t.remove()})),e.querySelectorAll(".footnotes, #refs").forEach((e=>{/^\s*$/.test(e.innerText)&&e.remove()})),e.getElementById("TOC")?.classList.add("side","side-left")})(document);
1
+ (e=>{e.querySelectorAll('.footnotes > ol > li[id^="fn"], #refs > div[id^="ref-"]').forEach((t=>{const s=`a[href="#${t.id}"]`,r=e.querySelector(`${s} > sup, sup > ${s}, .citation > ${s}`);if(!r)return;const o=r.parentNode;("A"===r.tagName?r:o).removeAttribute("href");const l=e.createElement("div");for(l.className="side side-right",/^fn/.test(t.id)?(l.innerHTML=t.innerHTML,l.firstElementChild.insertAdjacentHTML("afterbegin",`<span class="bg-number">${r.innerText}</span> `),l.querySelector('a[href^="#fnref"]')?.remove(),l.className+=" footnotes"):l.innerHTML=t.outerHTML;"#text"===l.lastChild?.nodeName&&/^\s*$/.test(l.lastChild.textContent);)l.lastChild.remove();l.querySelectorAll(".fullwidth").forEach((e=>e.classList.remove("fullwidth"))),o.after(l),o.classList.add("note-ref"),t.remove()})),e.querySelectorAll(".footnotes, #refs").forEach((e=>{/^\s*$/.test(e.innerText)&&e.remove()})),e.getElementById("TOC")?.classList.add("side","side-left");const t=e.querySelectorAll(".side.side-right, .side.side-left"),s=[];e.querySelectorAll(".fullwidth").forEach((e=>{s.push([e,e.getBoundingClientRect()])})),t.length&&e.body.classList.add("has-sidenotes"),t.forEach((e=>{const t=e.getBoundingClientRect();for(let e of s){const s=e[1];t.right<s.left||t.left>s.right||t.bottom<s.top||t.top>s.bottom||e[0].classList.remove("fullwidth")}}))})(document);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@xiee/utils",
3
- "version": "1.5.3",
3
+ "version": "1.5.5",
4
4
  "description": "Miscellaneous tools and utilities to manipulate HTML pages",
5
5
  "scripts": {
6
6
  "test": "echo \"Error: no test specified\" && exit 1"