Skip to content

Instantly share code, notes, and snippets.

View tak-dcxi's full-sized avatar
🏠
Working from home

TAK tak-dcxi

🏠
Working from home
View GitHub Profile
@tak-dcxi
tak-dcxi / initializeMasonry.ts
Last active July 15, 2024 17:34
Masonry Layout
const resizeMasonryItem = (
element: HTMLElement,
itemWrapper: HTMLElement
): void => {
const item = itemWrapper.firstChild;
if (!(item instanceof HTMLElement)) return;
const rowSize = parseInt(getComputedStyle(element).gridAutoRows, 10);
const gapSize = parseInt(getComputedStyle(element).rowGap, 10);
const itemSize = isWritingModeVertical(element)
@tak-dcxi
tak-dcxi / initializeViewTransitions.ts
Created June 19, 2024 15:18
initializeViewTransitions
// View Transitions API は TypeScript の型定義に含まれていないため自身で定義する
declare global {
interface ViewTransition {
finished: Promise<void>
ready: Promise<void>
updateCallbackDone: Promise<void>
}
interface Document {
startViewTransition(updateCallback: () => Promise<void> | void): ViewTransition
@tak-dcxi
tak-dcxi / ArticleLinkCard.astro
Last active June 9, 2024 01:56
AstroLinkCard
---
import { load } from 'cheerio'
import Image from 'astro/components/Image.astro'
import { writeFileSync, readFileSync } from 'node:fs'
import BaseIcon from '@/components/BaseIcon.astro'
type Props = {
href: string
}
@tak-dcxi
tak-dcxi / clamp.css
Last active June 4, 2024 03:02
clamp.css
body *,
body ::before,
body ::after {
--clamp-base-font-size: 16;
--clamp-viewport-min: 375;
--clamp-viewport-max: 1200;
--clamp-slope: calc((var(--clamp-max) - var(--clamp-min)) / (var(--clamp-viewport-max) - var(--clamp-viewport-min)));
--clamp-y-axis-intersection: calc(var(--clamp-min) - (var(--clamp-slope) * var(--clamp-viewport-min)));
--clamp-preffered-value: calc(
var(--clamp-y-axis-intersection) * (1rem / var(--clamp-base-font-size)) + (var(--clamp-slope) * 100svi)
@tak-dcxi
tak-dcxi / backfaceFixed.ts
Created April 30, 2024 15:06
initializeModal
const backfaceFixed = (fixed: boolean): void => {
const scrollBarWidth = getScrollBarSize()
const scrollPosition = getScrollPosition(fixed)
document.body.style.borderInlineEnd = fixed ? `${scrollBarWidth}px solid transparent` : ''
applyStyles(scrollPosition, fixed)
if (!fixed) restorePosition(scrollPosition)
}
const isWritingModeVertical = (): boolean => {
@tak-dcxi
tak-dcxi / backfaceFixed.ts
Last active April 30, 2024 14:43
backfaceFixed
const backfaceFixed = (fixed: boolean): void => {
const scrollBarWidth = getScrollBarSize()
const scrollPosition = getScrollPosition(fixed)
document.body.style.borderInlineEnd = fixed ? `${scrollBarWidth}px solid transparent` : ''
applyStyles(scrollPosition, fixed)
if (!fixed) restorePosition(scrollPosition)
}
const isWritingModeVertical = (): boolean => {
@tak-dcxi
tak-dcxi / initializeAccordion.ts
Last active May 7, 2024 02:17
initializeAccordion
export type AccordionOptions = {
buttonSelector: string | undefined
panelSelector: string | undefined
duration?: number
easing?: string
printAll?: boolean
}
const defaultOptions: AccordionOptions = {
buttonSelector: undefined,
@tak-dcxi
tak-dcxi / initializeDetailsAccordion.ts
Last active April 30, 2024 08:43
initializeDetailsAccordion
export type AccordionOptions = {
duration?: number
easing?: string
printAll?: boolean
}
const defaultOptions: AccordionOptions = {
duration: 300,
easing: 'ease-in-out',
printAll: false,
@tak-dcxi
tak-dcxi / initializeAnchorPositioning.ts
Last active April 28, 2024 12:57
initializeAnchorPositioning
const initializeAnchorPositioning = (): void => {
const anchorElements = document.querySelectorAll('[data-anchor]') as NodeListOf<HTMLElement>
anchorElements.forEach((anchorElement) => {
const targetId = anchorElement.getAttribute('data-anchor')
if (!targetId) return
const anchorTarget = document.getElementById(targetId) as HTMLElement
if (!anchorTarget) return
@tak-dcxi
tak-dcxi / initializeSplitText.ts
Last active April 26, 2024 07:37
initializeSplitText
type AccordionOptions = {
duration?: number
easing?: string
}
const defaultOptions: AccordionOptions = {
duration: 300,
easing: 'ease-in-out',
}