Skip to content

Commit

Permalink
fix: adds string caching improvements
Browse files Browse the repository at this point in the history
  • Loading branch information
yowainwright committed Jan 10, 2024
1 parent fa3b2ef commit 25f4ee8
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 9 deletions.
4 changes: 2 additions & 2 deletions .github/workflows/nodejs.yml
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,9 @@ jobs:
node-version: [20.x]

steps:
- uses: actions/checkout@v2
- uses: actions/checkout@v4
- name: Use Node.js ${{ matrix.node-version }}
uses: actions/setup-node@v1
uses: actions/setup-node@v4
with:
node-version: ${{ matrix.node-version }}
- run: npm i pnpm -g
Expand Down
15 changes: 8 additions & 7 deletions src/shave.ts
Original file line number Diff line number Diff line change
Expand Up @@ -114,23 +114,24 @@ export default function shave(target: string | NodeList | Node, maxHeight: numbe
let pivot
while (min < max) {
pivot = (min + max + 1) >> 1 // eslint-disable-line no-bitwise
const wordItems = words.slice(0, pivot);
el[textProp] = spaces
? ((words.slice(0, pivot) as string[]).join(' ') as string)
: (words as string).slice(0, pivot)
? (wordItems as string[]).join(' ') as string
: wordItems as string;
el.insertAdjacentElement('beforeend', shavedTextEl)
if (el.offsetHeight > maxHeight) {
max = pivot - 1
} else {
min = pivot
}
}

el[textProp] = spaces ? ((words.slice(0, max) as string[]).join(' ') as string) : (words as string).slice(0, max)
const wordeItems = words.slice(0, max)
el[textProp] = spaces ? ((wordeItems as string[]).join(' ') as string) : wordeItems as string
el.insertAdjacentElement('beforeend', shavedTextEl)
const diffItems = words.slice(max)
const diff: string = spaces
? ` ${(words.slice(max) as string[]).join(' ') as string}`
: (words as string).slice(max)

? ' ' + (diffItems as string[]).join(' ')
: diffItems as string;
const shavedText = document.createTextNode(diff)
const elWithShavedText = document.createElement('span')
elWithShavedText.classList.add(classname)
Expand Down

0 comments on commit 25f4ee8

Please sign in to comment.