Skip to content

Instantly share code, notes, and snippets.

View manabuyasuda's full-sized avatar

安田 学 manabuyasuda

View GitHub Profile
import { debounce } from '@utility/debounce'
import { throttle } from '@utility/throttle'
/**
* @classdesc 指定した要素までスクロールしたかを検知してコールバック関数で処理を実行します。
* @author Manabu Yasuda <[email protected]>
* @example
* import ScrollFixed from '@lib/ScrollFixed'
*
* const fixed = new ScrollFixed({
//- @param {Object} params
//- @param {String} params.width [null] セルの横幅
//- @param {String} params.parentWidth [null] テーブル全体の横幅
//-
//- @examples Input
//- colgroup
//- +Col({ width: 300, parentWidth: 900 })
//- +Col({ width: "300", parentWidth: "900" })
//- +Col({ width: "300px", parentWidth: "900px" })
//-
// `npm i -D glob js-beautify`
const fs = require('fs')
const glob = require('glob')
const beautify = require('js-beautify')
const beautifyOptions = {
indent_size: 2,
end_with_newline: true,
preserve_newlines: false,
max_preserve_newlines: 0,
wrap_line_length: 0,
/**
* 要素の幅と高さを取得します。
* @param {HTMLElement} target 幅と高さを取得する要素
* @return {{width: Number, height: Number}}
* @example
* const foo = getSize(document.querySelector('.foo'))
* console.log(foo) // => {width: 300, height: 200}
* console.log(foo.width) // => 300
* console.log(foo.height) // => 200
*/
/**
* 仕様としてフォーカス可能な要素。
*/
const focusableElementsString =
'a[href]:not([disabled]), button:not([disabled]), textarea:not([disabled]), input[type="text"]:not([disabled]), input[type="radio"]:not([disabled]), input[type="checkbox"]:not([disabled]), input[type="search"]:not([disabled]), select:not([disabled])'
/**
* 仕様としてフォーカス可能、かつ`tabindex="-1"`が指定されていない要素。
*/
const currentFocusableElementsString =
@manabuyasuda
manabuyasuda / adjustLineBreaks.js
Last active February 14, 2023 18:13
Googleの「budoux」で文字列に適切な改行を挿入します。
import { loadDefaultJapaneseParser } from 'budoux'
const parser = loadDefaultJapaneseParser()
/**
* 文字列を解析して、適切に改行されるように`wbr`タグを挿入します。
* IEは`wbr`タグに対応していません。
* @see https://caniuse.com/wbr-element
* @see https://github.com/google/budoux/tree/main/javascript
* @param {HTMLElement} element 最適化する要素
//- @param {Object} params
//- @param {String} params.name [""] SVGスプライトのid名
//-
//- @examples Input
//- +Icon({ name: "menu" })
//- @examples Output
//- <svg role="img">
//- <use xlink:href="/assets/svg/sprite.svg#menu"></use>
//- </svg>
mixin Icon(params={})
//- @param {Object} params
//- @param {String} params.src [""] 画像パス
//- @param {String} params.srcset [""] 画像のalt属性値
//-
//- @examples Input
//- +Picture({ src: "https://placehold.jp/300x300.png", alt: "" })
//- +Picture_Source({ media: "lg", srcset: "https://placehold.jp/1000x1000.png" })
//- +Picture_Source({ media: "md", srcset: "https://placehold.jp/600x600.png" })
//-
//- @examples Output
//- @param {Object} params
//- @param {String} params.type ["button"] type属性値
//- @param {boolean|string} params.size [false] ボタンのサイズ指定(`auto`,`full`)
//- @param {boolean|string} params.icon [false] ボタンのアイコン指定(`more`)
//- @param {boolean} params.disabled [false] disabled属性値を出力するかの真偽値
//-
//- @examples Input
//- +Button デフォルトボタン
//- @examples Output
//- <button class="sw-Button" type="button">デフォルトボタン</button>
//- @param {Object} params
//- @param {boolean|string} params.start [false] start属性値を出力するかの真偽値、または出力する数値
//-
//- @examples Input
//- +ListOrder
//- +ListOrder_Item リスト1
//- +ListOrder_Item リスト2
//- +ListOrder_Child
//- +ListOrder_Item リスト2-1
//- +ListOrder_Item リスト2-2