spec-up-t 1.0.36 → 1.0.38

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.
@@ -87,8 +87,8 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
87
87
  * @license MIT
88
88
  * @since 2024-06-09
89
89
  */
90
- function addHrefToSnapshotLink(){const t=((e=specConfig.spec_directory).startsWith("./")?e=e.substring(2):e.startsWith("/")&&(e=e.substring(1)),e.endsWith("/")&&(e=e.slice(0,-1)),e);var e;document.querySelectorAll('dt:has(> span[id^="term:"])').forEach(e=>{const n=function(t){let e=t;for(;e.querySelector('span[id^="term:"]');)e=e.querySelector('span[id^="term:"]');return e}(e),o=n.getAttribute("id").split(":")[1];n.innerHTML+=`<span class="edit-term-buttons"><a title="Link to the term file in the Github repo in a new tab" target="_blank" rel="noopener" href="https://github.com/${specConfig.source.account}/${specConfig.source.repo}/blob/main/${t}/${specConfig.spec_terms_directory}/${o}.md" class="edit-term-button btn">🖊️</a><a title="Link to a GitHub page that shows a history of the edits in a new tab" target="_blank" rel="noopener" href="https://github.com/${specConfig.source.account}/${specConfig.source.repo}/commits/main/${t}/${specConfig.spec_terms_directory}/${o}.md" class="history-term-button btn">📅</a></span>`})}document.addEventListener("DOMContentLoaded",(function(){addHrefToSnapshotLink()}));
91
- function inPageSearch(){const e=document.querySelector("span[issue-count]"),t=specConfig.searchHighlightStyle||"ssi",n="search-h7vc6omi2hr2880",i=document.querySelector("main article");let c=document.createElement("div");c.setAttribute("id","container-"+n),c.setAttribute("class","container-"+n),e.after(c);let o=document.createElement("input");o.setAttribute("type","text"),o.setAttribute("id",n),o.setAttribute("placeholder","🔍"),c.appendChild(o),setTimeout(()=>{o.focus()},1e3);const r=document.createElement("div");r.setAttribute("id","back-and-forth-buttons-container-"+n);const a=document.createElement("button");a.setAttribute("id","one-match-backward-"+n),a.setAttribute("disabled","disabled"),a.setAttribute("title","Go to previous match. Shortcut key: Left Arrow"),a.textContent="▲",r.appendChild(a);const s=document.createElement("button");s.setAttribute("id","one-match-forward-"+n),s.setAttribute("disabled","disabled"),s.setAttribute("title","Go to next match. Shortcut key: Right Arrow"),s.textContent="▼",r.appendChild(s),c.appendChild(r);const d=document.createElement("span");d.setAttribute("id","total-matches-"+n),d.innerHTML="0 matches",c.appendChild(d),o.addEventListener("input",(function(){f(o.value)}));const h="highlight-matches-"+n,l={dif:"highlight-matches-DIF-search-h7vc6omi2hr2880",toip:"highlight-matches-ToIP-search-h7vc6omi2hr2880",btc:"highlight-matches-BTC-search-h7vc6omi2hr2880",keri:"highlight-matches-KERI-search-h7vc6omi2hr2880",ssi:"highlight-matches-SSI-search-h7vc6omi2hr2880",gleif:"highlight-matches-GLEIF-search-h7vc6omi2hr2880"}[t.toLowerCase()];let u=0,m=-1;function b(e){e.scrollIntoView({behavior:"smooth",block:"start"});const t=e.getBoundingClientRect(),n=t.top+window.pageYOffset-(window.innerHeight-t.height)/2;window.scrollTo({top:n,behavior:"smooth"})}function p(){m<=0?document.getElementById("one-match-backward-"+n).setAttribute("disabled","disabled"):document.getElementById("one-match-backward-"+n).removeAttribute("disabled"),m>=u-1?document.getElementById("one-match-forward-"+n).setAttribute("disabled","disabled"):document.getElementById("one-match-forward-"+n).removeAttribute("disabled")}function g(){d.innerHTML=u+" matches"}const f=function(e,t){let n;return function(){const i=this,c=arguments;clearTimeout(n),n=setTimeout(()=>e.apply(i,c),t)}}((function(e){if(function(){document.querySelectorAll("span."+h).forEach(e=>{Array.from(e.childNodes).forEach(t=>{t.nodeType===Node.ELEMENT_NODE&&e.removeChild(t)}),e.classList.contains(h)&&(e.outerHTML=e.innerHTML)})}(),u=0,m=-1,""===e)return void g();let t=0;!function i(c){if(3===c.nodeType){const i=function(i){const c=i.nodeValue,o=new RegExp(e,"gi");let r,a=0,s=document.createDocumentFragment();for(;null!==(r=o.exec(c));){s.appendChild(document.createTextNode(c.substring(a,r.index)));const e=document.createElement("span");e.textContent=r[0],e.classList.add(h),e.classList.add(l),e.setAttribute("id",n+"-"+t),s.appendChild(e),u=t+1,t++,a=r.index+r[0].length}return s.appendChild(document.createTextNode(c.substring(a))),s}(c);i.childNodes.length>1&&c.parentNode.replaceChild(i,c)}else 1===c.nodeType&&Array.from(c.childNodes).forEach(i)}(i);let c=document.querySelector("."+l);null!==c&&b(c);g(),p(),m=-1}),600);a.addEventListener("click",(function(){m--;const e=document.querySelector("#"+n+"-"+m);e&&b(e),e.classList.add("active"),setTimeout(()=>{e.classList.remove("active")},3e3),p()})),s.addEventListener("click",(function(){m++;const e=document.querySelector("#"+n+"-"+m);e&&b(e),e.classList.add("active"),setTimeout(()=>{e.classList.remove("active")},3e3),p()})),document.addEventListener("keyup",e=>{switch(e.key){case"ArrowRight":s.click();break;case"ArrowLeft":a.click()}})}document.addEventListener("DOMContentLoaded",(function(){inPageSearch()}));
90
+ function editTermButtons(){const t=((e=specConfig.spec_directory).startsWith("./")?e=e.substring(2):e.startsWith("/")&&(e=e.substring(1)),e.endsWith("/")&&(e=e.slice(0,-1)),e);var e;document.querySelectorAll('dt:has(> span[id^="term:"])').forEach(e=>{const n=function(t){let e=t;for(;e.querySelector('span[id^="term:"]');)e=e.querySelector('span[id^="term:"]');return e}(e),s=n.getAttribute("id").split(":")[1];n.innerHTML+=`<span class="edit-term-buttons"><a title="Link to the term file in the Github repo in a new tab" target="_blank" rel="noopener" href="https://github.com/${specConfig.source.account}/${specConfig.source.repo}/blob/main/${t}/${specConfig.spec_terms_directory}/${s}.md" class="edit-term-button btn">🖊️</a><a title="Link to a GitHub page that shows a history of the edits in a new tab" target="_blank" rel="noopener" href="https://github.com/${specConfig.source.account}/${specConfig.source.repo}/commits/main/${t}/${specConfig.spec_terms_directory}/${s}.md" class="history-term-button btn">📅</a></span>`})}document.addEventListener("DOMContentLoaded",(function(){editTermButtons()}));
91
+ function inPageSearch(){const e=document.querySelector("span[issue-count]"),t=specConfig.searchHighlightStyle||"ssi",n="search-h7vc6omi2hr2880",i=document.querySelector("main article");let c=document.createElement("div");c.setAttribute("id","container-"+n),c.setAttribute("class","container-"+n),e.after(c);let o=document.createElement("input");o.setAttribute("type","text"),o.setAttribute("id",n),o.setAttribute("placeholder","🔍"),c.appendChild(o),setTimeout(()=>{o.focus()},1e3);const s=document.createElement("div");s.setAttribute("id","back-and-forth-buttons-container-"+n);const r=document.createElement("button");r.setAttribute("id","one-match-backward-"+n),r.setAttribute("disabled","disabled"),r.setAttribute("title","Go to previous match. Shortcut key: Left Arrow"),r.textContent="▲",s.appendChild(r);const a=document.createElement("button");a.setAttribute("id","one-match-forward-"+n),a.setAttribute("disabled","disabled"),a.setAttribute("title","Go to next match. Shortcut key: Right Arrow"),a.textContent="▼",s.appendChild(a),c.appendChild(s);const d=document.createElement("span");d.setAttribute("id","total-matches-"+n),d.innerHTML="0 matches",c.appendChild(d),o.addEventListener("input",(function(){g(o.value)})),document.addEventListener("click",e=>{e.target.classList.contains("collapse-all-defs-button")&&g(o.value)});const l="highlight-matches-"+n,h={dif:"highlight-matches-DIF-search-h7vc6omi2hr2880",toip:"highlight-matches-ToIP-search-h7vc6omi2hr2880",btc:"highlight-matches-BTC-search-h7vc6omi2hr2880",keri:"highlight-matches-KERI-search-h7vc6omi2hr2880",ssi:"highlight-matches-SSI-search-h7vc6omi2hr2880",gleif:"highlight-matches-GLEIF-search-h7vc6omi2hr2880"}[t.toLowerCase()];let u=0,m=-1;function b(e){e.scrollIntoView({behavior:"smooth",block:"start"});const t=e.getBoundingClientRect(),n=t.top+window.pageYOffset-(window.innerHeight-t.height)/2;window.scrollTo({top:n,behavior:"smooth"})}function p(){m<=0?document.getElementById("one-match-backward-"+n).setAttribute("disabled","disabled"):document.getElementById("one-match-backward-"+n).removeAttribute("disabled"),m>=u-1?document.getElementById("one-match-forward-"+n).setAttribute("disabled","disabled"):document.getElementById("one-match-forward-"+n).removeAttribute("disabled")}function f(){d.innerHTML=u+" matches"}const g=function(e,t){let n;return function(){const i=this,c=arguments;clearTimeout(n),n=setTimeout(()=>e.apply(i,c),t)}}((function(e){if(function(){document.querySelectorAll("span."+l).forEach(e=>{Array.from(e.childNodes).forEach(t=>{t.nodeType===Node.ELEMENT_NODE&&e.removeChild(t)}),e.classList.contains(l)&&(e.outerHTML=e.innerHTML)})}(),u=0,m=-1,""===e)return void f();let t=0;!function i(c){if(3!==c.nodeType||function(e){for(;e;){if(e.classList&&e.classList.contains("hidden"))return!0;e=e.parentNode}return!1}(c))1===c.nodeType&&Array.from(c.childNodes).forEach(i);else{const i=function(i){const c=i.nodeValue,o=new RegExp(e,"gi");let s,r=0,a=document.createDocumentFragment();for(;null!==(s=o.exec(c));){a.appendChild(document.createTextNode(c.substring(r,s.index)));const e=document.createElement("span");e.textContent=s[0],e.classList.add(l),e.classList.add(h),e.setAttribute("id",n+"-"+t),a.appendChild(e),u=t+1,t++,r=s.index+s[0].length}return a.appendChild(document.createTextNode(c.substring(r))),a}(c);i.childNodes.length>1&&c.parentNode.replaceChild(i,c)}}(i);let c=document.querySelector("."+h);null!==c&&b(c);f(),p(),m=-1}),600);r.addEventListener("click",(function(){m--;const e=document.querySelector("#"+n+"-"+m);e&&b(e),e.classList.add("active"),setTimeout(()=>{e.classList.remove("active")},3e3),p()})),a.addEventListener("click",(function(){m++;const e=document.querySelector("#"+n+"-"+m);e&&b(e),e.classList.add("active"),setTimeout(()=>{e.classList.remove("active")},3e3),p()})),document.addEventListener("keyup",e=>{switch(e.key){case"ArrowRight":a.click();break;case"ArrowLeft":r.click()}})}document.addEventListener("DOMContentLoaded",(function(){inPageSearch()}));
92
92
  function highlightMenuItems(){let t=null;function e(t){document.querySelectorAll("#toc_list a").forEach(t=>{t.classList.remove("highlight-cfib41dyhcd99sm")});const e=document.querySelector(`#toc_list a[href="#${t.id}"]`);e&&(e.classList.add("highlight-cfib41dyhcd99sm"),e.scrollIntoView({behavior:"smooth",block:"center"}))}const o=new IntersectionObserver((o,n)=>{const c=o.filter(t=>t.isIntersecting).map(t=>t.target);c.length>0?(t=c[0],e(t)):t&&e(t)},{root:null,rootMargin:"0px",threshold:.1});document.querySelectorAll("h2, h3, h4, h5, h6").forEach(t=>o.observe(t))}document.addEventListener("DOMContentLoaded",(function(){highlightMenuItems()}));
93
93
  function backToTop(){const n=document.createElement("a");n.id="back-to-top-a1zncgtqfpzsig8",n.href="#content",n.innerHTML="↑",document.body.appendChild(n);const t=function(n,t){let e;return function(){const o=this,c=arguments;clearTimeout(e),e=setTimeout(()=>n.apply(o,c),t)}}((function(){window.scrollY>300?n.style.display="flex":n.style.display="none"}),600);window.addEventListener("scroll",(function(){t()}))}document.addEventListener("DOMContentLoaded",(function(){backToTop()}));
94
94
  /**
@@ -127,11 +127,11 @@ function helpButtons(){const t=document.createElement("a");t.textContent="?",t.c
127
127
  function createAlphabetIndex(){const e=document.getElementById("alphabet-index-h7vc6omi2hr2880"),t=document.querySelector(".terms-and-definitions-list").querySelectorAll("dt"),n={};t.forEach(e=>{const t=e.querySelector("span");if(t&&t.id){const e=t.id,o=e.charAt(e.indexOf("term:")+5).toUpperCase();n[o]||(n[o]=t.id)}});const o=document.createElement("div");o.className="alphabet-index";const r=document.createElement("p");r.className="number-of-terms",r.textContent=`– There are ${t.length} terms –`;const c=e.parentNode;c.insertBefore(r,e.nextSibling),c.insertBefore(o,r.nextSibling),Object.keys(n).sort().forEach(e=>{const t=document.createElement("a");t.href="#"+n[e],t.textContent=e,o.appendChild(t)})}document.addEventListener("DOMContentLoaded",(function(){createAlphabetIndex()}));
128
128
  function collapseDefinitions(){const t=document.querySelectorAll("#content dl dd"),e=document.querySelectorAll(".collapse-all-defs-button");document.querySelectorAll("dt").forEach(t=>{const e=document.createElement("button");e.classList.add("collapse-all-defs-button","btn"),e.innerHTML="▲",e.setAttribute("id","toggleButton"),t.appendChild(e)}),document.addEventListener("click",n=>{n.target.classList.contains("collapse-all-defs-button")&&(!function(){const n=t[0].classList.contains("hidden");t.forEach(t=>{t.classList.toggle("hidden",!n),t.classList.toggle("visible",n)}),e.forEach(t=>{t.innerHTML=n?"▲":"▼",t.title=n?"Collapse all definitions":"Expand all definitions"})}(),n.target.scrollIntoView({behavior:"smooth",block:"start",inline:"nearest"}),setTimeout(()=>{window.scrollBy({top:-100,behavior:"smooth"})},500))})}document.addEventListener("DOMContentLoaded",(function(){collapseDefinitions()}));
129
129
  /**
130
- * @file This file
130
+ * @file This file adds an href attribute to the snapshot link on the page via client side JS DOM manipulation.
131
131
  * @author Kor Dwarshuis
132
132
  * @version 0.0.1
133
133
  * @license MIT
134
134
  * @since 2024-09-25
135
135
  */
136
- function addHrefToSnapshotLink(){const n=document.querySelector(".snapshots a");console.log("snapshotLink: ",n);const o=window.location.href.match(/^(https?:\/\/[^\/]+\/[^\/]+\/)versions\//),t=(o?o[1]:"")+"versions/";n&&n.setAttribute("href",t)}document.addEventListener("DOMContentLoaded",(function(){addHrefToSnapshotLink()}));
136
+ function addHrefToSnapshotLink(){const e=document.querySelector(".snapshots a"),t=window.location.href,n=t.match(/^(https?:\/\/[^\/]+(?:\/[^\/]+)*)\/versions\/(?:[^\/]+\/)?/);let o;o=n?n[1]+"/versions/":t.replace(/\/$/,"")+"/versions/",e&&e.setAttribute("href",o)}document.addEventListener("DOMContentLoaded",(function(){addHrefToSnapshotLink()}));
137
137
  !function(){var e=window.markdownit();delegateEvent("pointerup","[panel-toggle]",(e,t)=>{slidepanels.toggle(t.getAttribute("panel-toggle"))},{passive:!0}),window.addEventListener("hashchange",e=>slidepanels.close());let t=specConfig.source;t&&"github"===t.host&&fetch(`https://api.github.com/repos/${t.account+"/"+t.repo}/issues`).then(e=>e.json()).then(t=>{let n=t.length;document.querySelectorAll("[issue-count]").forEach(e=>{e.setAttribute("issue-count",n)}),repo_issue_list.innerHTML=t.map(t=>`<li class="repo-issue">\n <detail-box>\n <section>${e.render(t.body||"")}</section>\n <header class="repo-issue-title">\n <span class="repo-issue-number">${t.number}</span>\n <span class="repo-issue-link">\n <a href="${t.html_url}" target="_blank">${t.title}</a>\n </span>\n <span detail-box-toggle></span>\n </header>\n </detail-box>\n </li>`).join(""),Prism.highlightAllUnder(repo_issue_list)}),mermaid.initialize({startOnLoad:!0,theme:"neutral"}),document.querySelectorAll(".chartjs").forEach(e=>{new Chart(e,JSON.parse(e.textContent))});let n=new WeakMap;delegateEvent("pointerover",".term-reference, .spec-reference",(e,t)=>{const s=t.getAttribute("data-local-href")||t.getAttribute("href")||"";let l=document.getElementById(s.replace("#",""));if(!l||n.has(t))return;let r=l.closest("dt, td:first-child");if(!r)return;let i={allowHTML:!0,inlinePositioning:!0};switch(r.tagName){case"DT":i.content=r.nextElementSibling.textContent;break;case"TD":let e=r.closest("table"),t=Array.from(r.closest("tr").children);if(t.shift(),e){let n=Array.from(e.querySelectorAll("thead th"));n.shift(),n.length&&(i.content=`\n <header>${r.textContent}</header>\n <table>\n ${n.map((e,n)=>`<tr><td>${e.textContent}:</td><td>${t[n]?t[n].textContent:""}</td></tr>`).join("")}\n </table>`)}}i.content&&n.set(t,tippy(t,i))},{passive:!0})}();
@@ -7,28 +7,28 @@
7
7
  */
8
8
 
9
9
  function addHrefToSnapshotLink() {
10
- // Find the snapshot link and add the href attribute
11
10
  const snapshotLink = document.querySelector('.snapshots a');
12
11
 
13
12
  // Get the current URL of the page
14
13
  const currentUrl = window.location.href;
15
14
 
16
- // Use a regular expression to match the base URL up to the 'versions' directory
17
- // The regex matches 'http(s)://', followed by any characters that are not '/', followed by '/'
18
- // followed by any characters that are not '/', followed by '/', followed by 'versions/'
19
- const baseUrlMatch = currentUrl.match(/^(https?:\/\/[^\/]+\/[^\/]+\/)versions\//);
20
-
21
- // If the match is found, use the matched string as the base URL, otherwise use an empty string
22
- const baseUrl = baseUrlMatch ? baseUrlMatch[1] : '';
23
-
24
- // Construct the snapshot link href by appending 'versions/' to the base URL
25
- const snapshotLinkHref = `${baseUrl}versions/`;
15
+ // Regex to match up to and including the 'versions/' directory (if it exists)
16
+ const versionsMatch = currentUrl.match(/^(https?:\/\/[^\/]+(?:\/[^\/]+)*)\/versions\/(?:[^\/]+\/)?/);
17
+
18
+ // If we are already in the 'versions' directory or deeper, strip down to 'versions/'
19
+ // Otherwise, append '/versions/' to the current directory
20
+ let snapshotLinkHref;
21
+ if (versionsMatch) {
22
+ snapshotLinkHref = `${versionsMatch[1]}/versions/`;
23
+ } else {
24
+ // Append '/versions/' to the current directory
25
+ snapshotLinkHref = currentUrl.replace(/\/$/, '') + '/versions/';
26
+ }
26
27
 
27
28
  // Set the 'href' attribute of the snapshot link element to the constructed URL
28
29
  if (snapshotLink) {
29
30
  snapshotLink.setAttribute('href', snapshotLinkHref);
30
31
  }
31
-
32
32
  }
33
33
 
34
34
  document.addEventListener("DOMContentLoaded", function () {
@@ -87,13 +87,20 @@ function inPageSearch() {
87
87
  totalMatchesSpan.innerHTML = `0 ${matches}`;
88
88
  // backAndForthButtonsContainer.after(totalMatchesSpan);
89
89
  searchContainer.appendChild(totalMatchesSpan);
90
+
91
+ /* END Add DOM elements */
90
92
 
91
93
  // Add an event listener to the input element
92
94
  searchInput.addEventListener("input", function () {
93
95
  debouncedSearchAndHighlight(searchInput.value);
94
96
  });
95
- /* END Add DOM elements */
96
97
 
98
+ // The search will run when the user clicks the collapse button, so the search results are updated when the terms are collapsed or expanded. If the definitions are collapsed, the search results in the definitions will be removed.
99
+ document.addEventListener('click', event => {
100
+ if (event.target.classList.contains('collapse-all-defs-button')) {
101
+ debouncedSearchAndHighlight(searchInput.value);
102
+ }
103
+ });
97
104
 
98
105
  const matchesClassName = "highlight-matches-" + antiNameCollisions;
99
106
  const matchesStyleSelectorClassName = matchesStyleSelector[matchesStyle.toLowerCase()];
@@ -264,7 +271,25 @@ function inPageSearch() {
264
271
 
265
272
  // Recursive function that searches all nodes in the DOM tree and highlights the text that matches the search string (case-insensitive) with a span element
266
273
  function searchNodes(node) {
274
+ /*
275
+ Helper function to check if any ancestor has the 'hidden' class. Why the 'hidden' class? Because we don't want to highlight text that is hidden, and 'hidden' is the class that is used in the JS that collapses and expands the terms and definitions in the specs. The class is applied to the <dd>'s
276
+ */
277
+ function hasHiddenAncestor(node) {
278
+ while (node) {
279
+ if (node.classList && node.classList.contains('hidden')) {
280
+ return true;
281
+ }
282
+ node = node.parentNode;
283
+ }
284
+ return false;
285
+ }
286
+
287
+ // A:
267
288
  if (node.nodeType === 3) { // Node.TEXT_NODE
289
+
290
+ // B: ”&& !hasHiddenAncestor(node)” makes search only in terms when definitions are collapsed
291
+ // if (node.nodeType === 3 && !hasHiddenAncestor(node)) { // Node.TEXT_NODE
292
+
268
293
  const fragments = markAndCountMatches(node);
269
294
  if (fragments.childNodes.length > 1) {
270
295
  // Replace the text node with the fragments if there were matches
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "spec-up-t",
3
- "version": "1.0.36",
3
+ "version": "1.0.38",
4
4
  "description": "Technical specification drafting tool that generates rich specification documents from markdown. Forked from https://github.com/decentralized-identity/spec-up by Daniel Buchner (https://github.com/csuwildcat)",
5
5
  "main": "./index",
6
6
  "repository": {