This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import { | |
existsSync, | |
mkdirSync, | |
readFileSync, | |
writeFileSync, | |
unlinkSync, | |
} from 'node:fs' | |
import { resolve } from 'node:path' | |
import { homedir } from 'node:os' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function reformatJsDocComment(comment, maxWidth = 80) { | |
// Extract the content of the JSDoc comment | |
const content = comment | |
.split('\n') | |
.filter(line => line.trim() !== '/**' && line.trim() !== '*/') // TODO: handle inline JS Doc | |
.map(line => line.replace(/^\s*\/?\**\s?/g, '').replace(/\s*\*\/?$/, '').trim()) | |
.join(' '); | |
// Split the content into words | |
const words = content.split(/\s+/); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* Lock all scrollbars by disabling mousewheel and locking scrollbars in position | |
* Optionally provide an element to allow it to scroll when hovered | |
*/ | |
const listenerOptions = supportsPassiveEvents | |
? { capture: true, passive: false } | |
: true | |
let lockedScrolls = [] | |
function lockScroll(node) { |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import { readFileSync } from 'node:fs' | |
import { resolve } from 'node:path' | |
function extractPort(script: string) { | |
const portRegex = /next dev.*(?:-p |--port )(\d+)/ | |
const match = script.match(portRegex) | |
return match ? match[1] : null | |
} | |
/* Read package.json and parse the Next.js port number */ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** Get the offset ancestors of a node. */ | |
function getOffsetAncestors(node: HTMLElement): Set<HTMLElement> { | |
let ancestors = new Set<HTMLElement>() | |
let current: Element | null = node.offsetParent | |
while (current) { | |
if (current instanceof HTMLElement) { | |
ancestors.add(current) | |
current = current.offsetParent | |
} else { | |
break |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
'use client' | |
import { useState, useLayoutEffect, useRef, useMemo } from 'react' | |
export function VirtualList({ | |
data, | |
rowHeight, | |
itemsToShow = 4, | |
overscanCount = 2, | |
}: { | |
data: { text: string; id: number }[] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import * as webpack from 'webpack' | |
import { glob } from 'glob' | |
import { dirname, resolve } from 'node:path' | |
function getPathnameFromFilename(filename: string) { | |
return ( | |
filename | |
// Remove file extensions | |
.replace(/\.[^/.]+$/, '') | |
// Remove leading "./" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* Lock all scrollbars by disabling mousewheel and locking scrollbars in position | |
* Optionally provide an element to allow it to scroll when hovered | |
*/ | |
const listenerOptions = supportsPassiveEvents | |
? { capture: true, passive: false } | |
: true | |
let lockedScrolls = [] | |
function lockScroll(node) { |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** Get the closest element that scrolls */ | |
function getClosestOverflowElement(node: HTMLElement, includeHidden?: boolean) { | |
if (node) { | |
const { overflow, overflowX, overflowY } = getComputedStyle(node) | |
const canScroll = ( | |
includeHidden ? /(auto|scroll|hidden)/ : /(auto|scroll)/ | |
).test(overflow + overflowX + overflowY) | |
if (node === document.body || canScroll) { | |
return node | |
} else { |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import fs from 'node:fs/promises' | |
import path from 'node:path' | |
/** Fetches the types for a locally installed NPM package. */ | |
export async function getTypeDeclarations(packageName) { | |
const [parentPackage, submodule] = packageName.split('/') | |
const parentPackagePath = path.resolve( | |
process.cwd(), | |
'node_modules', | |
parentPackage, |
NewerOlder