mirror of
https://github.com/He4eT/tabswitcher.git
synced 2026-05-05 01:17:23 +00:00
pages/search: shaped tabs
This commit is contained in:
parent
8d91c80b8b
commit
5df95ea62c
6 changed files with 221 additions and 20 deletions
36
pages/search/modules/labels.js
Normal file
36
pages/search/modules/labels.js
Normal file
|
|
@ -0,0 +1,36 @@
|
|||
const labels = {
|
||||
/* tabId: label, */
|
||||
}
|
||||
|
||||
const lettersOrder = 'lkjhyuionm'
|
||||
|
||||
const digits2label = (digits) => [...digits]
|
||||
.map((digit) => lettersOrder[digit])
|
||||
.join('')
|
||||
|
||||
const label2digits = (label) => [...label]
|
||||
.map((letter) => [...lettersOrder].findIndex((x) => x === letter))
|
||||
.join('')
|
||||
|
||||
/* */
|
||||
|
||||
export const id2label = (id, tabs) => {
|
||||
if (!labels[id]) {
|
||||
const label = Object.keys(labels).length
|
||||
labels[id] = String(label)
|
||||
}
|
||||
|
||||
const keyLength = String(tabs?.length).length
|
||||
const digits = String(labels[id]).padStart(keyLength, 0)
|
||||
return digits2label(digits)
|
||||
}
|
||||
|
||||
export const label2id = (label) => {
|
||||
const paddedDigits = label2digits(label)
|
||||
const digits = String(parseInt(paddedDigits))
|
||||
|
||||
const [key] = Object.entries(labels)
|
||||
.find(([_, value]) => value === digits)
|
||||
|
||||
return parseInt(key)
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue