@xiee/utils 1.14.19 → 1.14.21

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.
package/js/appendix.js CHANGED
@@ -5,15 +5,28 @@
5
5
  const h = d.querySelector([1, 2, 3, 4, 5, 6].map(i => `h${i}.appendix`).join(','));
6
6
  if (!h) return;
7
7
  h.classList.remove('appendix');
8
- // if h is in a wrapper whose next sibling has the same class, simply add class to wrappers
9
- const p1 = h.parentNode; let p2 = p1, wrapper = false;
8
+ // test if two elements have same tag and class
9
+ function sameClass(e1, e2) {
10
+ return e1 && e2 && e1.tagName === e2.tagName && e1.className === e2.className;
11
+ }
12
+ // if h is in a wrapper whose prev/next sibling has the same class, simply add class to wrappers
13
+ const p1 = h.parentNode, p0 = p1.previousElementSibling;
14
+ let has_wrapper = sameClass(p1, p0), h0 = h, p2 = p1;
15
+ // if has_wrapper == false, check if there's any sibling heading before h
16
+ if (!has_wrapper) while (true) {
17
+ h0 = h0.previousElementSibling;
18
+ if (!h0) break;
19
+ // if a heading is found, assume the appendix needs a new wrapper
20
+ has_wrapper = !/^H[1-6]/.test(h0.tagName);
21
+ if (!has_wrapper) break; // heading found, appendix doesn't have wrapper
22
+ }
10
23
  while (p1) {
11
24
  p2 = p2.nextElementSibling;
12
- if (!p2 || p1.tagName !== p2.tagName || p1.className !== p2.className) break;
25
+ if (!sameClass(p1, p2)) break;
13
26
  p2.classList.add('appendix');
14
- wrapper = true;
27
+ has_wrapper = true;
15
28
  }
16
- if (wrapper) {
29
+ if (has_wrapper) {
17
30
  p1.classList.add('appendix');
18
31
  return;
19
32
  }
@@ -1,2 +1,2 @@
1
- (e=>{const a=e.querySelector([1,2,3,4,5,6].map(e=>`h${e}.appendix`).join(","));if(!a)return;a.classList.remove("appendix");const n=a.parentNode;let t=n,d=!1;for(;n&&(t=t.nextElementSibling,t&&n.tagName===t.tagName&&n.className===t.className);)t.classList.add("appendix"),d=!0;if(d)return void n.classList.add("appendix");const p=e.createElement("div");for(p.className="appendix",p.append(a.cloneNode(!0));a.nextSibling;)p.append(a.nextSibling);"BODY"===a.parentNode.tagName?e.body.append(p):a.parentNode.after(p),a.remove()})(document);
1
+ (e=>{const n=e.querySelector([1,2,3,4,5,6].map(e=>`h${e}.appendix`).join(","));if(!n)return;function a(e,n){return e&&n&&e.tagName===n.tagName&&e.className===n.className}n.classList.remove("appendix");const t=n.parentNode;let i=a(t,t.previousElementSibling),p=n,o=t;if(!i)for(;p=p.previousElementSibling,p&&(i=!/^H[1-6]/.test(p.tagName),i););for(;t&&(o=o.nextElementSibling,a(t,o));)o.classList.add("appendix"),i=!0;if(i)return void t.classList.add("appendix");const s=e.createElement("div");for(s.className="appendix",s.append(n.cloneNode(!0));n.nextSibling;)s.append(n.nextSibling);"BODY"===n.parentNode.tagName?e.body.append(s):n.parentNode.after(s),n.remove()})(document);
2
2
  //# sourceMappingURL=appendix.min.js.map
@@ -1 +1 @@
1
- {"version":3,"names":["d","h","querySelector","map","i","join","classList","remove","p1","parentNode","p2","wrapper","nextElementSibling","tagName","className","add","a","createElement","append","cloneNode","nextSibling","body","after","document"],"sources":["appendix.js"],"mappings":"AAGA,CAACA,IACC,MAAMC,EAAID,EAAEE,cAAc,CAAC,EAAG,EAAG,EAAG,EAAG,EAAG,GAAGC,IAAIC,GAAK,IAAIA,cAAcC,KAAK,MAC7E,IAAKJ,EAAG,OACRA,EAAEK,UAAUC,OAAO,YAEnB,MAAMC,EAAKP,EAAEQ,WAAY,IAAIC,EAAKF,EAAIG,GAAU,EAChD,KAAOH,IACLE,EAAKA,EAAGE,mBACHF,GAAMF,EAAGK,UAAYH,EAAGG,SAAWL,EAAGM,YAAcJ,EAAGI,YAC5DJ,EAAGJ,UAAUS,IAAI,YACjBJ,GAAU,EAEZ,GAAIA,EAEF,YADAH,EAAGF,UAAUS,IAAI,YAInB,MAAMC,EAAIhB,EAAEiB,cAAc,OAG1B,IAFAD,EAAEF,UAAY,WACdE,EAAEE,OAAOjB,EAAEkB,WAAU,IACflB,EAAEmB,aACNJ,EAAEE,OAAOjB,EAAEmB,aAEY,SAAzBnB,EAAEQ,WAAWI,QAAqBb,EAAEqB,KAAKH,OAAOF,GAAKf,EAAEQ,WAAWa,MAAMN,GACxEf,EAAEM,QACH,EAzBD,CAyBGgB","ignoreList":[]}
1
+ {"version":3,"names":["d","h","querySelector","map","i","join","sameClass","e1","e2","tagName","className","classList","remove","p1","parentNode","has_wrapper","previousElementSibling","h0","p2","test","nextElementSibling","add","a","createElement","append","cloneNode","nextSibling","body","after","document"],"sources":["appendix.js"],"mappings":"AAGA,CAACA,IACC,MAAMC,EAAID,EAAEE,cAAc,CAAC,EAAG,EAAG,EAAG,EAAG,EAAG,GAAGC,IAAIC,GAAK,IAAIA,cAAcC,KAAK,MAC7E,IAAKJ,EAAG,OAGR,SAASK,EAAUC,EAAIC,GACrB,OAAOD,GAAMC,GAAMD,EAAGE,UAAYD,EAAGC,SAAWF,EAAGG,YAAcF,EAAGE,SACtE,CAJAT,EAAEU,UAAUC,OAAO,YAMnB,MAAMC,EAAKZ,EAAEa,WACb,IAAIC,EAAcT,EAAUO,EADEA,EAAGG,wBACIC,EAAKhB,EAAGiB,EAAKL,EAElD,IAAKE,EAAa,KAChBE,EAAKA,EAAGD,uBACHC,IAELF,GAAe,UAAUI,KAAKF,EAAGR,SAC5BM,KAEP,KAAOF,IACLK,EAAKA,EAAGE,mBACHd,EAAUO,EAAIK,KACnBA,EAAGP,UAAUU,IAAI,YACjBN,GAAc,EAEhB,GAAIA,EAEF,YADAF,EAAGF,UAAUU,IAAI,YAInB,MAAMC,EAAItB,EAAEuB,cAAc,OAG1B,IAFAD,EAAEZ,UAAY,WACdY,EAAEE,OAAOvB,EAAEwB,WAAU,IACfxB,EAAEyB,aACNJ,EAAEE,OAAOvB,EAAEyB,aAEY,SAAzBzB,EAAEa,WAAWL,QAAqBT,EAAE2B,KAAKH,OAAOF,GAAKrB,EAAEa,WAAWc,MAAMN,GACxErB,EAAEW,QACH,EAtCD,CAsCGiB","ignoreList":[]}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@xiee/utils",
3
- "version": "1.14.19",
3
+ "version": "1.14.21",
4
4
  "description": "Miscellaneous tools and utilities to manipulate HTML pages",
5
5
  "scripts": {
6
6
  "test": "echo \"Error: no test specified\" && exit 1"