From b1ec23e3579b1528e6e7eb12f5c9f89793b5390e Mon Sep 17 00:00:00 2001 From: alyx Date: Tue, 31 May 2022 15:15:17 +0000 Subject: moved some stuff around, updated circuitsv2.json, linked the grapher from the searcher --- searcher/index.html | 150 +++++++++++++++++++++++++++++ searcher/script.js | 270 ++++++++++++++++++++++++++++++++++++++++++++++++++++ searcher/style.css | 237 +++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 657 insertions(+) create mode 100644 searcher/index.html create mode 100644 searcher/script.js create mode 100644 searcher/style.css (limited to 'searcher') diff --git a/searcher/index.html b/searcher/index.html new file mode 100644 index 0000000..f6ae0a1 --- /dev/null +++ b/searcher/index.html @@ -0,0 +1,150 @@ + + + + + + + + CV2 Chip Searcher + + + + + + + + + + + + + + + + + + + + + + + + +
+ +
+
+ Options +
+ + + + + + + + +
+
+
+

Fuzzy Finder:

+ + + + + + +
+
+
+

Search By:

+ + + + +
+
+
+ + +
+
+
+
+
+ + + Showing page 0/0. + + +
+
+
+ +

Maintained by @winrg/@✨Aleteoryx, Keeper of Names✨#1027

+
+ ? +
+ +

The Basics

+
+

The chip searcher is a simple program. + To get started, simply type the name of the chip you'd like to know about into the top box. + By default, the searcher will automatically refresh the results as you type.

+

Different types of chips

+
+
    +
  • Beta Chips are indicated by a β symbol.
  • +
  • Soon-to-be deprecated Chips are indicated by yellow text, as well as a warning.
  • +
  • Deprecated Chips are indicated by red text, as well as a warning.
  • +
+

Neither form of deprecated chip will display by default.

+

Options

+
+

The chip searcher supports the following configuration + options, contained in the fold-out menu below the search bar.

+

Toggles

+
+
    +
  • Auto Refresh: Automatically update search results as you type. + When disabled, hit Enter to refresh.
  • +
  • Show Beta Chips: When enabled, beta chips will be included in the search.
  • +
  • Show Deprecated Chips: When enabled, deprecated chips will be included in the search.
  • +
  • Enable Filter Suggestions: When enabled, filters will be displayed as autocomplete options.
  • +
+

Fuzzy Finder

+
+
    +
  • Exact Match: What is typed must appear identically in the results.
  • +
  • Small Typos: Small errors are ignored, though larger ones will still affect the results.
  • +
  • Loose Match: Really only useful if you can't spell.
  • +
+

Search By

+
+
    +
  • Name: Search for what is typed in the chip name.
  • +
  • Description: Search for what is typed in the chip description
  • +
+

Items Per Page

+
+

Configures the number of items that will appear in each page. Defaults to 12.

+
+
+ + \ No newline at end of file diff --git a/searcher/script.js b/searcher/script.js new file mode 100644 index 0000000..d80cd8f --- /dev/null +++ b/searcher/script.js @@ -0,0 +1,270 @@ +const isNested = Boolean(window.parent != window); + +const deprecationStrings = { + "Active": {Text: "", Class: "hide"}, + "": {Text: "Warning! This chip is being deprecated. It will be broken in the near future, and should not be used.", Class: "depwarn"}, + "Deprecated": {Text: "Warning! This chip is currently deprecated. It is no longer in the palette, and likely does not work.", Class: "depbad"} +}; +const fusenameopts = { + isCaseSensitive: false, + minMatchCharLength: 1, + ignoreLocation: true, + threshold: 0, + keys: ["ReadonlyPaletteName", "ReadonlyChipName"], + includeScore: true +}; +const fusedescopts = { + isCaseSensitive: false, + minMatchCharLength: 1, + ignoreLocation: true, + threshold: 0, + keys: ["Description"], + includeScore: true +}; + +function genExplanation(name) { + return name; +} + +function genSearchPath(path, name) { + const ret = document.createElement("li"); + ret.classList.add("searchpath"); + ret.innerText = path.join("/") + "/" + name; + return ret; +} + +function getChipAddListener(GUID) { + return function(e) { + window.parent.postMessage( + { + type: 'newChip', + GUID: GUID + } + ); + } +} + +var searchresults = []; +var page = 0 + +window.addEventListener("load", async (e) => { + const search = document.getElementById("search"); + const form = document.getElementById("form"); + const suggestions = document.getElementById("paletteSearch"); + + if (isNested) document.getElementById("grapherlink").remove(); + + if (localStorage.length) { + form.depr.checked = localStorage.getItem("depr"); + form.beta.checked = localStorage.getItem("beta"); + form.ReadonlyPaletteName.checked = localStorage.getItem("ReadonlyPaletteName"); + form.Description.checked = localStorage.getItem("Description"); + form.refresh.checked = localStorage.getItem("refresh"); + form.fuzziness.value = localStorage.getItem("fuzz"); + form.items.value = localStorage.getItem("items"); + form.filterSug.checked = localStorage.getItem("fsug"); + } + + let v2pr = fetch(/*"https://raw.githubusercontent.com/tyleo-rec/CircuitsV2Resources/master/misc/circuitsv2.json"/*/"/circuitsv2.json") + .then(res => res.json()); + let termspr = fetch("/terms.json") + .then(res => res.json()); + + [v2json, termsjson] = await Promise.all([v2pr, termspr]); + //console.log(v2json, termsjson); + + + //GUID needs to be in the same object now, because we convert to an array + const searchable = Object.entries(v2json.Nodes) + .map(pair => {return {GUID: pair[0], ...pair[1]}}) + searchable.sort((a, b) => (a.ReadonlyPaletteName.toLowerCase() > b.ReadonlyPaletteName.toLowerCase()) ? 1 : -1); + + const fuses = [new Fuse(searchable, fusenameopts), + new Fuse(searchable, fusedescopts)]; + + const filterTree = {nodes: searchable}; + searchable.forEach(chip => { + chip.NodeFilters.forEach(filter => { + var currentNode = filterTree; + filter.FilterPath.forEach(path => { + if (!currentNode[path.toUpperCase()]) currentNode[path.toUpperCase()] = {nodes: []}; + currentNode = currentNode[path.toUpperCase()] + if (!currentNode.nodes.includes(chip))currentNode.nodes.push(chip); + currentNode.actualname = path; + }) + }) + }) + + //console.log(filterTree); + + const redraw = targ => { + const fuseinuse = fuses.filter(fuse => form[fuse.options.keys[0]].checked); + + start = performance.now(); + + localStorage.setItem("depr", form.depr.checked ? "set" : ""); + localStorage.setItem("beta", form.beta.checked ? "set" : ""); + localStorage.setItem("ReadonlyPaletteName", form.ReadonlyPaletteName.checked ? "set" : ""); + localStorage.setItem("Description", form.Description.checked ? "set" : ""); + localStorage.setItem("refresh", form.refresh.checked ? "set" : ""); + localStorage.setItem("fsug", form.filterSug.checked ? "set" : ""); + localStorage.setItem("fuzz", form.fuzziness.value); + localStorage.setItem("items", form.items.value); + + suggestions.id = form.filterSug.checked ? "paletteSearch" : "" + + var content2 = filterTree; + + const fullPath = targ.value.replace(/\\+|\/+/, "/") + .split("/"); + const startOfPath = fullPath.slice(0, -1); + const endOfPath = fullPath.at(-1); + const startOfSuggestion = startOfPath.join('/'); + + startOfPath.forEach(path => { + try { + content2 = content2[path.toUpperCase()] + } catch (e) {} + }); + + if (!content2) content2 = {nodes: []}; + + suggestions.innerText = ''; + suggestions.append(...Object.keys(content2) + .filter(i => i.toUpperCase() == i) + .sort((a, b) => (a > b) ? 1 : -1) + .map(i => { + var e = document.createElement('option'); + e.value = startOfSuggestion + (startOfSuggestion ? '/' : '') + content2[i].actualname + '/'; + return e; + }) + ) + + + fuseinuse.forEach(fuse => { + fuse.options.minMatchCharLength = Math.floor(endOfPath.length * JSON.parse(form.fuzziness.value).nummod); + fuse.options.threshold = JSON.parse(form.fuzziness.value).thresh; + fuse.setCollection(content2.nodes); + }); + + var content = endOfPath ? (() => { + let m = fuseinuse.map(fuse => fuse.search(endOfPath)).flat() + m.sort((a,b) => a.score - b.score); + m = Array.from(new Set(m.map(e => e.item))); + return m; + })() : content2.nodes; + //console.log(content2.nodes) + + content = content.map(el => { + if ((form.depr.checked || el.DeprecationStage == 0) && (form.beta.checked || !el.IsBetaChip)) { + const ret = newEl("details", "returnedchip"); + if (el.IsBetaChip) ret.classList.add("betaChip"); + + const iret = newEl("div", "infocontainer"); + + const name = document.createElement("summary"); + name.innerText = el.ReadonlyPaletteName + + ((el.ReadonlyPaletteName == el.ReadonlyChipName) ? "" : ` - aka "${el.ReadonlyChipName}"`); + + const deprinfo = deprecationStrings[el.DeprecationStage]; + const depr = newEl("div", deprinfo.Class); + depr.innerText = deprinfo.Text; + + const desc = newEl("p", "chipdesc") + desc.innerText = el.Description == "" ? "No Description!" : el.Description; + + const filters = newEl("ul", "filters") + filters.append(...Object.values(el.NodeFilters).map(val => genSearchPath(val.FilterPath, el.ReadonlyPaletteName))); + + iret.append(desc, filters); + + const addBtn = newEl('button', 'addBtn'); + addBtn.innerText = "+"; + addBtn.setAttribute('title', 'Add to graph'); + addBtn.onclick = getChipAddListener(el.GUID); + if (isNested) name.append(addBtn); + + let m = generateChipHTML(el.NodeDescs); + + ret.append(depr, name, iret, m); + + return ret; + } + }).filter(e => e != undefined); + var perfstring = `returned in ${parseInt(performance.now() - start)} ms.` + display(perfstring, content); + }; + + const redrawHandler = e => redraw(search); + + form.addEventListener("submit", e => {console.log(e); e.preventDefault()}); + search.addEventListener("change", redrawHandler); + form.addEventListener("input", redrawHandler); + + form.refresh.addEventListener("change", e => { + if (e.target.checked) { + form.addEventListener("input", redrawHandler); + } else { + form.removeEventListener("input", redrawHandler); + } + }); + + try { + redraw(search); + } catch (error) { + setTimeout(() => redraw(search), 1000); + } +}); + +function display(perf, content) { + searchresults = content; + page = 0; + update(); +} + +function first() { + page = 0; + update(); +} +function prev() { + page = Math.max(page - 1, 0); + update(); +} + +function next() { + const pagesize = parseInt(document.getElementById("cfgitems").value); + + page = (((page + 1) * pagesize) > searchresults.length) ? page : (page + 1); + update(); +} + +function last() { + const pagesize = parseInt(document.getElementById("cfgitems").value); + + page = Math.max(parseInt((searchresults.length - 1) / pagesize), 0); + update(); +} + + +function update() { + const ndisplay = document.getElementById("pagen"); + const ofdisplay = document.getElementById("of"); + const output = document.getElementById("resultslist"); + const pagesel = document.getElementById("cfgitems"); + + //pagesel.value = ; + + const pagesize = pagesel.value == "" ? 1 : Math.max(parseInt(pagesel.value), 1); + + const start = page * pagesize; + const end = Math.min(searchresults.length, start + pagesize); + + ndisplay.innerText = page + 1; + ofdisplay.innerText = parseInt((searchresults.length - 1) / pagesize) + 1; + + //console.log(start, end); + + output.innerHTML = ""; + output.append(...searchresults.slice(start, end)); +} + diff --git a/searcher/style.css b/searcher/style.css new file mode 100644 index 0000000..d45a04a --- /dev/null +++ b/searcher/style.css @@ -0,0 +1,237 @@ +@import url('https://fonts.googleapis.com/css2?family=Raleway&display=swap'); + +body { +} +html { + --foreforeground: #3788ae; + --foreground: #082f41; + --background: #03141c; + color: white; + background: var(--background); + /*padding: 1cm;*/ + font-size: 12pt; + font-family: 'Raleway', sans-serif; + height: 100%; +} + +hr { + border: 0.5mm solid var(--foreforeground); + background: var(--foreforeground); + width: 100%; + height: 0%; + +} + +.filters::before { + content: "Pallette Search paths:"; +} + +.hide {display: none;} + +input, button, details{ + color: white; + background: var(--foreground); + padding: 1rem; + + border: none; + border-radius: 0.5cm; + font-size: 13pt; + margin: 0.5rem; +} + +input::placeholder { + color: var(--foreforeground); +} + +details :is(input, button) { + background: var(--background); +} + +/*input[type=checkbox] { + display: none; +} + +input[type=checkbox] + label { + position: relative; + padding-left: 2.5rem; + padding-right: .5rem; +} + +input[type=checkbox] + label::before { + background: var(--foreground); + width: 1.5rem; + height: 1.5rem; + margin: auto; + content: ""; + position: absolute; + left: 0; + top: -0.33rem; + border-radius: 0.25rem; + border: 0.25rem var(--foreforeground) solid; +} + + +input[type=checkbox]:checked + label::before { + border-color: var(--foreground); + background: var(--foreforeground); + color: var(--foreground); + font-size: 16pt; + /*content: "✓";* / + align-content: center; +}*/ + +details { + padding: 1rem; + background: var(--foreground); +} + +details.betaChip > summary::before { + content: "β "; + color: paleturquoise; +} + +.returnedchip > summary { + position: relative; +} + +.returnedchip > summary > button.addBtn { + padding: 0rem; + margin: 0; + height: 2rem; + width: 2rem; + position: absolute; + top: calc(50% - 1rem); + right: 0; + left: calc(100% - 2rem); + bottom: calc(50% - 1rem); + text-align: center; + background: #0000; + font-size: 2rem; +} + +details[open] > summary { + border-bottom: 1mm var(--foreforeground) solid; + margin-bottom: 0.5rem; +} + +body { + display: flex; + flex-flow: column; + height: calc(100% - 2cm); + margin: 1cm; +} + +#resultslist { + overflow: auto; +} + +#listcontrols { + display: flex; + flex-flow: row; + align-items: center; +} + + +#helpbox > summary { + height: 1.5cm; + width: 1.5cm; + display: flex; + background: #0000; + border: #fff7 solid 0.9mm; + color: #fff7; + border-radius: 1.5cm; + padding: 0; + font-size: 1.5cm; + align-items: center; + justify-content: center; + float: left; + position: absolute; + bottom: 0; + right: 0; + user-select: none; +} +#helpbox[open] > summary { + margin-bottom: 0; + background: #fff7; + border: #0000 solid 0.9mm; + color: #fff; +} + +#helpbox { + position: fixed; + bottom: 2rem; + right: 2rem; + background: #0000; + border-radius: 0; +} + +#helpbox > div { + background: var(--foreground); + border-radius: 0.5cm; + height: 60vh; + width: 10cm; + overflow-x: auto; + padding: 1rem; + position: relative; + bottom: 2cm; + box-shadow: black 1mm 1mm 3mm +} +a:link { + color: white; +} +a:visited { + color: var(--foreforeground); +} + +.depbad, .depbad + summary { + color: palevioletred; +} +.depwarn, .depwarn + summary { + color: palegoldenrod; +} + +kbd { + background: white; + color: black; + padding: 0.5mm; + border-radius: 1mm; + box-shadow: inset black -0.25mm -0.25mm 1mm; +} + +input:not(:checked).selecttab + .tab { + display: none; +} + +.tab { + position: absolute; + top: 2rem; +} + +summary, +button, +:is(input[type=radio], input[type=checkbox]), +:is(input[type=radio], input[type=checkbox]) + label { + cursor: pointer; +} + + +@media (orientation: portrait) { + #listcontrols { + justify-content: space-between; + } + #form > details { + overflow: auto; + max-height: 20vh; + } + label::after { + content: "\a"; + white-space: pre; + } + input[type=text] { + width: calc(100vw - 3.25cm); + } + #helpbox > div { + width: calc(100vw - 3.5cm); + height: 60vh; + } +} \ No newline at end of file -- cgit v1.2.3-54-g00ecf