Minimalist DOM and events manager focused on performances
Iterates over items and apply callback on each one.
Parameters
items
any The iterable.callback
forEachCallback The callback to call for each iteratee.Examples
//esnext
import { forEach } from 'chirashi'
const items = forEach([0, 1, 2], (item, i) => console.log(`${i}: ${item + 1}`)) //returns: [0, 1, 2]
// logs:
// 0: 1
// 1: 2
// 2: 3
forEach(0, (item, i) => console.log(`${i}: ${item + 1}`)) //returns: [0]
// 0: 1
//es5
var items = Chirashi.forEach([0, 1, 2], function (item, i) { console.log(i+': '+(item + 1)) }) //returns: [0, 1, 2]
// logs:
// 0: 1
// 1: 2
// 2: 3
Chirashi.forEach(0, function (item, i) { console.log(i+': '+(item + 1)) }) //returns: [0]
// logs:
// 0: 1
Returns any iterable - items if it’s an array-like or an array containing items.
Callback to apply on item.
Parameters
item
anyindex
number Index of item in items.Iterates over dom elements and apply callback on each one.
Parameters
elements **(string | Array | NodeList |
HTMLCollection | Window | Node)** The iterable, selector or elements. Note that it’ll be passed to getElements. |
callback
forElementsCallback The function to call for each element.Examples
//esnext
import { createElement, append, forElements } from 'chirashi'
const sushi = createElement('.sushi')
const unagi = createElement('.unagi')
const yakitori = createElement('.yakitori')
const sashimi = createElement('.sashimi')
append(document.body, [sushi, unagi, yakitori, sashimi])
forElements('div', console.log) //returns: [<div class="sushi"></div>, <div class="unagi"></div>, <div class="yakitori"></div>, <div class="sashimi"></div>]
// logs:
// <div class="sushi"></div> 0
// <div class="unagi"></div> 1
// <div class="yakitori"></div> 2
// <div class="sashimi"></div> 3
forElements([yakitori, sashimi], console.log) //returns: [<div class="yakitori"></div>, <div class="sashimi"></div>]
// logs:
// <div class="yakitori"></div> 0
// <div class="sashimi"></div> 1
//es5
var sushi = Chirashi.createElement('.sushi')
var unagi = Chirashi.createElement('.unagi')
var yakitori = Chirashi.createElement('.yakitori')
var sashimi = Chirashi.createElement('.sashimi')
Chirashi.append(document.body, [sushi, unagi, yakitori, sashimi])
Chirashi.forElements('div', console.log) //returns: [<div class="sushi"></div>, <div class="unagi"></div>, <div class="yakitori"></div>, <div class="sashimi"></div>]
// logs:
// <div class="sushi"></div> 0
// <div class="unagi"></div> 1
// <div class="yakitori"></div> 2
// <div class="sashimi"></div> 3
Chirashi.forElements([yakitori, sashimi], console.log) //returns: [<div class="yakitori"></div>, <div class="sashimi"></div>]
// logs:
// <div class="yakitori"></div> 0
// <div class="sashimi"></div> 1
Returns Array iterable - The getElements’ result for chaining.
Callback to apply on element.
Parameters
element
(Window | document | HTMLElement | SVGElement | Text)index
number Index of element in elements.Iterates over object’s keys and apply callback on each one.
Parameters
object
Object The iterable.callback
forInCallback The function to call for each key-value pair.Examples
//esnext
import { forIn } from 'chirashi'
const californiaRoll = { name: 'California Roll', price: 4.25, recipe: ['avocado', 'cucumber', 'crab', 'mayonnaise', 'sushi rice', 'seaweed'] }
forIn(californiaRoll, (key, value) => {
console.log(`${key} -> ${value}`)
}) //returns: { name: 'California Roll', price: 4.25, recipe: ['avocado', 'cucumber', 'crab', 'mayonnaise', 'sushi rice', 'seaweed'] }
// LOGS:
// name -> California Roll
// price -> 4.25
// recipe -> ['avocado', 'cucumber', 'crab', 'mayonnaise', 'sushi rice', 'seaweed']
//es5
var californiaRoll = { name: 'California Roll', price: 4.25, recipe: ['avocado', 'cucumber', 'crab', 'mayonnaise', 'sushi rice', 'seaweed'] }
Chirashi.forIn(californiaRoll, (key, value) => {
console.log(key + ' -> ' + value)
}) //returns: { name: 'California Roll', price: 4.25, recipe: ['avocado', 'cucumber', 'crab', 'mayonnaise', 'sushi rice', 'seaweed'] }
// LOGS:
// name -> California Roll
// price -> 4.25
// recipe -> ['avocado', 'cucumber', 'crab', 'mayonnaise', 'sushi rice', 'seaweed']
Returns Object object - The iterable for chaining.
Callback to apply on each key-value pair.
Parameters
key
stringvalue
anyGet first dom element from iterable or selector.
Parameters
input **(string | Array | NodeList |
HTMLCollection | Window | Node)** The iterable, selector or elements. |
Examples
//esnext
import { createElement, append, getElement } from 'chirashi'
const sushi = createElement('.sushi')
const unagi = createElement('.unagi')
const yakitori = createElement('.yakitori')
const sashimi = createElement('.sashimi')
append(document.body, [sushi, unagi, yakitori, sashimi])
getElement('div') //returns: <div class="sushi"></div>
getElement('.yakitori, .sashimi') //returns: <div class="yakitori"></div>
getElement([sushi, unagi, '.sashimi', '.unknown']) //returns: <div class="sushi"></div>
getElement('.wasabi') //returns: undefined
//es5
var sushi = Chirashi.createElement('.sushi')
var unagi = Chirashi.createElement('.unagi')
var yakitori = Chirashi.createElement('.yakitori')
var sashimi = Chirashi.createElement('.sashimi')
Chirashi.append(document.body, [sushi, unagi, yakitori, sashimi])
Chirashi.getElement('div') //returns: <div class="sushi"></div>
Chirashi.getElement('.yakitori, .sashimi') //returns: <div class="yakitori"></div>
Chirashi.getElement([sushi, unagi, '.sashimi', '.unknown']) //returns: <div class="sushi"></div>
Chirashi.getElement('.wasabi') //returns: undefined
Returns (Window | Node | boolean) element - The dom element from input.
Get dom element recursively from iterable or selector.
Parameters
input **(string | Array | NodeList |
HTMLCollection | Window | Node)** The iterable, selector or elements. |
Examples
//esnext
import { createElement, append, getElements } from 'chirashi'
const sushi = createElement('.sushi')
const unagi = createElement('.unagi')
const yakitori = createElement('.yakitori')
const sashimi = createElement('.sashimi')
append(document.body, [sushi, unagi, yakitori, sashimi])
getElements('div') //returns: [<div class="sushi"></div>, <div class="unagi"></div>, <div class="yakitori"></div>, <div class="sashimi"></div>]
getElements('.yakitori, .sashimi') //returns: [<div class="yakitori"></div>, <div class="sashimi"></div>]
getElements([sushi, unagi, '.sashimi', '.wasabi']) //returns: [<div class="sushi"></div>, <div class="unagi"></div>, <div class="sashimi"></div>]
getElements('.wasabi') //returns: []
//es5
var sushi = Chirashi.createElement('.sushi')
var unagi = Chirashi.createElement('.unagi')
var yakitori = Chirashi.createElement('.yakitori')
var sashimi = Chirashi.createElement('.sashimi')
Chirashi.append(document.body, [sushi, unagi, yakitori, sashimi])
Chirashi.getElements('div') //returns: [<div class="sushi"></div>, <div class="unagi"></div>, <div class="yakitori"></div>, <div class="sashimi"></div>]
Chirashi.getElements('.yakitori, .sashimi') //returns: [<div class="yakitori"></div>, <div class="sashimi"></div>]
Chirashi.getElements([sushi, unagi, '.sashimi', '.wasabi']) //returns: [<div class="sushi"></div>, <div class="unagi"></div>, <div class="sashimi"></div>]
Chirashi.getElements('.wasabi') //returns: []
Returns Array domElements - The array of dom elements from input.
lib/core/isDomElement.js:19-21
Test if element is a dom element. Doesn’t resolve selectors.
Parameters
element
any The element to test.Examples
//esnext
import { createElement, append, isDomElement } from 'chirashi'
const sushi = createElement('.sushi')
append(document.body, sushi)
isDomElement(window) //returns: true
isDomElement(sushi) //returns: true
isDomElement('.sushi') //returns: false
//es5
var sushi = Chirashi.createElement('.sushi')
Chirashi.append(document.body, sushi)
Chirashi.isDomElement(window) //returns: true
Chirashi.isDomElement(sushi) //returns: true
Chirashi.isDomElement('.sushi') //returns: false
Returns boolean isDomElement - true if element is an instance of Node or Window.
Iterates over classes and add it on each element of elements or ignore it if already set.
Parameters
elements **(string | Array | NodeList |
HTMLCollection | Element)** The iterable, selector or elements. |
classes
…string Classes to add.Examples
//esnext
import { createElement, addClass } from 'chirashi'
const maki = createElement('.maki')
addClass(maki, 'wasabi') //returns: <div class="wasabi"></div>
addClass(maki, 'seaweed', 'cheese') //returns: <div class="wasabi seaweed cheese"></div>
addClass('.maki', 'avocado', 'salmon') //returns: <div class="wasabi seaweed cheese avocado salmon"></div>
//es5
var maki = Chirashi.createElement('.maki')
Chirashi.addClass(maki, 'wasabi') //returns: <div class="wasabi"></div>
Chirashi.addClass(maki, 'seaweed', 'cheese') //returns: <div class="wasabi seaweed cheese"></div>
Chirashi.addClass('.maki', 'avocado', 'salmon') //returns: <div class="wasabi seaweed cheese avocado salmon"></div>
Returns Array iterable - The getElements’ result for chaining.
Appends each node to a parent node.
Parameters
element **(string | Array | NodeList |
HTMLCollection | Node)** The parent node. Note that it’ll be passed to getElement to ensure there’s only one. |
nodes **(string | Array<(string | Node)> |
Node)** String, node or array of nodes and/or strings. Each string will be passed to createElement then append. |
Examples
//esnext
import { createElement, append } from 'chirashi'
const maki = createElement('.maki')
append(maki, '.salmon[data-fish="salmon"]') //returns: <div class="maki"><div class="salmon" data-fish="salmon"></div></div>
const avocado = createElement('.avocado')
append(maki, [avocado, '.cheese[data-cheese="cream"]']) //returns: <div class="maki"><div class="salmon" data-fish="salmon"></div><div class="avocado"></div><div class="cheese" data-cheese="cream"></div></div>
//es5
var maki = Chirashi.createElement('.maki')
Chirashi.append(maki, '.salmon[data-fish="salmon"]') //returns: <div class="maki"><div class="salmon" data-fish="salmon"></div></div>
var avocado = Chirashi.createElement('.avocado')
Chirashi.append(maki, [avocado, '.cheese[data-cheese="cream"]']) //returns: <div class="maki"><div class="salmon" data-fish="salmon"></div><div class="avocado"></div><div class="cheese" data-cheese="cream"></div></div>
Returns (Node | boolean) node - The node for chaining or false if nodes can’t be appended.
Returns an element’s children as Array.
Parameters
element **(string | Array | NodeList |
HTMLCollection | Node)** The parent node. Note that it’ll be passed to getElement to ensure there’s only one. |
Examples
//esnext
import { createElement, append, children } from 'chirashi'
const maki = createElement('.maki')
append(maki, ['.salmon', '.avocado'])
children(maki) //returns: [<div class="salmon"></div>, <div class="avocado"></div>]
//es5
const maki = Chirashi.createElement('.maki')
Chirashi.append(maki, ['.salmon', '.avocado'])
Chirashi.children(maki) //returns: [<div class="salmon"></div>, <div class="avocado"></div>]
Returns Array<Element> children - Element’s children as array.
Clones element.
Parameters
element **(string | Array | NodeList |
HTMLCollection | Node)** The node to clone. Note that it’ll be passed to getElement to ensure there’s only one. |
Examples
//esnext
import { createElement, append, clone } from 'chirashi'
const maki = createElement('.maki')
clone(maki) //returns: <div class="maki"></div>
const sushi = createElement('.sushi')
append(document.body, sushi)
clone('.sushi') //returns: <div class="sushi"></div>
//es5
var maki = Chirashi.createElement('.maki')
Chirashi.clone(maki) //returns: <div class="maki"></div>
var sushi = Chirashi.createElement('.sushi')
Chirashi.append(document.body, sushi)
Chirashi.clone('.sushi') //returns: <div class="sushi"></div>
Returns (Node | boolean) clone - element’s clone or false if element isn’t a node.
Get closest element matching the tested selector or tested element traveling up the DOM tree from element to limit.
Parameters
element **(string | Array | NodeList |
HTMLCollection | Element)** First tested element. Note that it’ll be passed to getElement to ensure there’s only one. |
tested
(string | Element) The selector or dom element to match.limit
[(string | Node)] Returns false when this selector or element is reached. (optional, default document
)Examples
//esnext
import { createElement, append, closest } from 'chirashi'
const maki = createElement('.maki')
const cheese = createElement('.cheese')
append(maki, cheese)
append(cheese, '.avocado')
append(document.body, maki)
closest('.avocado', '.maki') //returns: <div class="maki"></div>
closest('.avocado', '.maki', '.cheese') //returns: false
//es5
var maki = Chirashi.createElement('.maki')
var cheese = Chirashi.createElement('.cheese')
Chirashi.append(maki, cheese)
Chirashi.append(cheese, '.avocado')
Chirashi.append(document.body, maki)
Chirashi.closest('.avocado', '.maki') //returns: <div class="maki"></div>
Chirashi.closest('.avocado', '.maki', '.cheese') //returns: false
Returns (Element | boolean) matchedElement - The matched element or false.
lib/dom/createElement.js:15-58
Creates a dom element from an HTML string, tag or css like selector with text between {} if needed.
Parameters
string
string The html string, tag or css like selector.Examples
//esnext
import { createElement } from 'chirashi'
const maki = createElement('a#sushi.link[data-href="chirashijs.org"][data-link]{click me!}') //returns: <a class="link" id="sushi" data-href="chirashijs.org" data-link>click me!</a>
const greetings = createElement('<h1>Hello <strong>World</strong>!</h1>') //returns: <h1>Hello <strong>World</strong>!</h1>
//es5
var maki = Chirashi.createElement('a#sushi.link[data-href="chirashijs.org"][data-link]{click me!}') //returns: <a class="link" id="sushi" data-href="chirashijs.org" data-link>click me!</a>
var greetings = Chirashi.createElement('<h1>Hello <strong>World</strong>!</h1>') //returns: <h1>Hello <strong>World</strong>!</h1>
Returns Element element - The dom element created from the string.
Remove every child of elements.
Parameters
elements **(string | Array | NodeList |
HTMLCollection | Node)** The iterable, selector or elements. Note that it’ll be passed to getElements. |
Examples
//esnext
import { createElement, append, empty } from 'chirashi'
const maki = createElement('.maki') //returns: <div class="maki"></div>
append(maki, '.cheese') //returns: <div class="maki"><div class="cheese"></div></div>
empty(maki) //returns: [<div class="maki"></div>]
//es5
const maki = Chirashi.createElement('.maki') //returns: <div class="maki"></div>
Chirashi.append(maki, '.cheese') //returns: <div class="maki"><div class="cheese"></div></div>
Chirashi.empty(maki) //returns: [<div class="maki"></div>]
Returns Array iterable - The getElements’ result for chaining.
Iterates over elements, returning an array of all elements matching tested selector.
Parameters
elements **(string | Array | NodeList |
HTMLCollection | Element)** The iterable, selector or elements. Note that it’ll be passed to getElements. |
tested
(string | Element) The selector or dom element to match.Examples
//esnext
import { createElement, append, filter } from 'chirashi'
const salmonMaki = createElement('.salmon.maki')
const tunaMaki = createElement('.tuna.maki')
const salmonSushi = createElement('.salmon.sushi')
const tunaSushi = createElement('.tuna.sushi')
append(document.body, [salmonMaki, tunaMaki, salmonSushi, tunaSushi])
filter('div', '.salmon') //returns: [<div class="salmon sushi"></div>, <div class="salmon maki"></div>]
filter([salmonMaki, tunaMaki, salmonSushi, tunaSushi], '.maki') //returns: [<div class="salmon maki"></div>, <div class="tuna maki"></div>]
filter('div', '.salmon') //returns: [<div class="salmon sushi"></div>, <div class="salmon maki"></div>]
//es5
var salmonMaki = Chirashi.createElement('.salmon.maki')
var tunaMaki = Chirashi.createElement('.tuna.maki')
var salmonSushi = Chirashi.createElement('.salmon.sushi')
var tunaSushi = Chirashi.createElement('.tuna.sushi')
Chirashi.append(document.body, [salmonMaki, tunaMaki, salmonSushi, tunaSushi])
Chirashi.filter('div', '.salmon') //returns: [<div class="salmon sushi"></div>, <div class="salmon maki"></div>]
Chirashi.filter([salmonMaki, tunaMaki, salmonSushi, tunaSushi], '.maki') //returns: [<div class="salmon maki"></div>, <div class="tuna maki"></div>]
Chirashi.filter('div', '.salmon') //returns: [<div class="salmon sushi"></div>, <div class="salmon maki"></div>]
Returns Array<Element> matching - The array of filtered elements.
Iterates over each element of elements and returns an array containing all elements’ children matching a selector.
Parameters
elements **(string | Array | NodeList |
HTMLCollection | Element | Document | ParentNode)** The iterable, selector or parent elements. Note that it’ll be passed to getElements. |
selector
string The selector.Examples
//esnext
import { createElement, append, find } from 'chirashi'
const maki = createElement('.maki')
append(maki, ['.salmon[data-fish][data-inside]', '.avocado[data-inside]'])
const roll = createElement('.roll')
append(roll, '.tuna[data-fish][data-inside]')
append(document.body, [maki, roll])
find('div', '[data-fish]') //returns: [<div class="salmon" data-fish data-inside></div>, <div class="tuna" data-fish data-inside></div>]
find(maki, '[data-inside]') //returns: [<div class="salmon" data-fish data-inside></div>, <div class="avocado" data-inside></div>]
//es5
var maki = Chirashi.createElement('.maki')
Chirashi.append(maki, ['.salmon[data-fish][data-inside]', '.avocado[data-inside]'])
var roll = Chirashi.createElement('.roll')
Chirashi.append(roll, '.tuna[data-fish][data-inside]')
Chirashi.append(document.body, [maki, roll])
Chirashi.find('div', '[data-fish]') //returns: [<div class="salmon" data-fish data-inside></div>, <div class="tuna" data-fish data-inside></div>]
Chirashi.find(maki, '[data-inside]') //returns: [<div class="salmon" data-fish data-inside></div>, <div class="avocado" data-inside></div>]
Returns Array<Element> found - The array of elements’ descendants matching the selector.
Find the first element’s child matching the selector.
Parameters
element **(string | Array | NodeList |
HTMLCollection | Element | Document | ParentNode)** The parent node. Note that it’ll be passed to getElement to ensure there’s only one. |
selector
string The selector to match.Examples
//esnext
import { createElement, append, find } from 'chirashi'
const maki = createElement('.maki')
append(maki, ['.salmon[data-fish][data-inside]', '.avocado[data-inside]'])
const roll = createElement('.roll')
append(roll, '.tuna[data-fish][data-inside]')
append(document.body, [maki, roll])
findOne('div', '[data-fish]') //returns: <div class="salmon" data-fish data-inside></div>
findOne(maki, '[data-inside]') //returns: <div class="salmon" data-fish data-inside></div>
//es5
var maki = Chirashi.createElement('.maki')
Chirashi.append(maki, ['.salmon[data-fish][data-inside]', '.avocado[data-inside]'])
var roll = Chirashi.createElement('.roll')
Chirashi.append(roll, '.tuna[data-fish][data-inside]')
Chirashi.append(document.body, [maki, roll])
Chirashi.findOne('div', '[data-fish]') //returns: <div class="salmon" data-fish data-inside></div>
Chirashi.findOne(maki, '[data-inside]') //returns: <div class="salmon" data-fish data-inside></div>
Returns **(Element | null)** element - The first child of elements matching the selector or null. |
Get value for named attribute of element.
Parameters
element **(string | Array | NodeList |
HTMLCollection | Element)** The element. Note that it’ll be passed to getElement to ensure there’s only one. |
names
…string The attributes’ names.Examples
//esnext
import { createElement, getAttr } from 'chirashi'
const maki = createElement('.maki[data-fish="salmon"]')
getAttr(maki, 'data-fish') //returns: "salmon"
//es5
const maki = Chirashi.createElement('.maki[data-fish="salmon"]')
Chirashi.getAttr(maki, 'data-fish') //returns: "salmon"
Returns **(Object<string, (string | boolean)> | string | boolean)** value - The value for the attribute if only one name, object of attributes’ name-value pairs or false if no element found. |
Alias on getAttr prefixing name with ‘data-‘.
Parameters
element **(string | Array | NodeList |
HTMLCollection | Element)** The element. Note that it’ll be passed to getElement to ensure there’s only one. |
names
…string The data-attributes’ names.Examples
//esnext
import { createElement, getData } from 'chirashi'
const maki = createElement('.maki[data-fish="salmon"]')
getData(maki, 'fish') //returns: "salmon"
//es5
const maki = Chirashi.createElement('.maki[data-fish="salmon"]')
Chirashi.getData(maki, 'fish') //returns: "salmon"
Returns **(Object<string, (string | boolean)> | string | boolean)** value - The value for the data-attribute if only one name, object of data-attributes’ name-value pairs or false if no element found. |
Get the inner html of an element.
Parameters
element **(string | Array | NodeList |
HTMLCollection | Element)** The element. Note that it’ll be passed to getElement to ensure there’s only one. |
Examples
//esnext
import { createElement, setHtml, getHtml } from 'chirashi'
const maki = createElement('p.maki')
setHtml(maki, 'salmon')
getHtml(maki) //returns: "salmon"
//es5
var maki = createElement('p.maki')
setHtml(maki, 'salmon')
getHtml(maki) //returns: "salmon"
Returns **(string | null)** innerHTML - The inner html of the element or null if no element found. |
Get the value for the property name on the element.
Parameters
element **(string | Array | NodeList |
HTMLCollection | Window | Node)** The element. Note that it’ll be passed to getElement to ensure there’s only one. |
string
…properties - The properties’ names.Examples
//esnext
import { createElement, append, getProp } from 'chirashi'
const maki = createElement('.maki')
append(maki, '.salmon')
getProp(maki, 'firstChild') //returns: <div class="salmon"></div>
//es5
var maki = Chirashi.createElement('.maki')
Chirashi.append(maki, '.salmon')
Chirashi.getProp(maki, 'firstChild') //returns: <div class="salmon"></div>
Returns any value - The value for property on element if only one property, object of property-value pairs or false if no element found.
Iterates over classes and test if element has each.
Parameters
elements **(string | Array | NodeList |
HTMLCollection | Element)** The iterable, selector or elements. |
classes
…string Classes to test.element
Examples
//esnext
import { createElement, hasClass } from 'chirashi'
const maki = createElement('.salmon.cheese.maki')
hasClass(maki, 'salmon', 'cheese') //returns: true
hasClass(maki, 'salmon', 'avocado') //returns: false
//es5
var maki = Chirashi.createElement('.salmon.cheese.maki')
Chirashi.hasClass(maki, 'salmon', 'cheese') //returns: true
Chirashi.hasClass(maki, 'salmon', 'avocado') //returns: false
Returns boolean hasClass - Is true if element has all classes.
lib/dom/indexInParent.js:19-28
Returns index of element in parent’s children.
@param {(string | Array | NodeList | HTMLCollection | NonDocumentTypeChildNode)} element - The element. Note that it’ll be passed to getElement to ensure there’s only one. |
Parameters
element
Examples
//esnext
import { createElement, append, indexInParent } from 'chirashi'
const maki = createElement('.maki')
append(document.body, maki)
append(maki, ['.salmon[data-fish="salmon"]', '.cheese[data-cheese="cream"]']) //returns: <div class="maki"><div class="salmon" data-fish="salmon"></div><div class="cheese" data-cheese="cream"></div></div>
indexInParent('.cheese') //returns: 1
//es5
var maki = Chirashi.createElement('.maki')
Chirashi.append(document.body, maki)
Chirashi.append(maki, ['.salmon[data-fish="salmon"]', '.cheese[data-cheese="cream"]']) //returns: <div class="maki"><div class="salmon" data-fish="salmon"></div><div class="cheese" data-cheese="cream"></div></div>
Chirashi.indexInParent('.cheese') //returns: 1
Returns **(number | null)** index - The position of element in his parent’s children or null if no element found. |
Insert nodes after element in his parent.
Parameters
element **(string | Array | NodeList |
HTMLCollection | NonDocumentTypeChildNode)** The element. Note that it’ll be passed to getElement to ensure there’s only one. |
nodes **(Array<(string | Node)> |
string | Node)** Array of dom elements or string to create it using createElement. |
Examples
//esnext
import { createElement, append, insertAfter } from 'chirashi'
const maki = createElement('.maki')
append(document.body, maki)
append(maki, ['.salmon[data-fish="salmon"]', '.cheese[data-cheese="cream"]'])
insertAfter('.salmon', ['.avocado', '.wasabi']) //returns: <div class="maki"><div class="salmon" data-fish="salmon"></div><div class="avocado"></div><div class="wasabi"></div><div class="cheese" data-cheese="cream"></div></div>
//es5
var maki = Chirashi.createElement('.maki')
Chirashi.append(document.body, maki)
Chirashi.append(maki, ['.salmon[data-fish="salmon"]', '.cheese[data-cheese="cream"]'])
Chirashi.insertAfter('.salmon', ['.avocado', '.wasabi']) //returns: <div class="maki"><div class="salmon" data-fish="salmon"></div><div class="avocado"></div><div class="wasabi"></div><div class="cheese" data-cheese="cream"></div></div>
Returns (Node | undefined) element - The element for chaining or undefined if no element found or element has no parent.
Insert nodes before element in his parent.
Parameters
element **(string | Array | NodeList |
HTMLCollection | NonDocumentTypeChildNode)** The element. Note that it’ll be passed to getElement to ensure there’s only one. |
nodes **(Array<(string | Node)> |
string | Node)** Array of dom elements or string to create it using createElement. |
Examples
//esnext
import { createElement, append, insertBefore } from 'chirashi'
const maki = createElement('.maki')
append(document.body, maki)
append(maki, ['.salmon[data-fish="salmon"]', '.cheese[data-cheese="cream"]'])
insertBefore('.cheese', ['.avocado', '.wasabi']) //returns: <div class="maki"><div class="salmon" data-fish="salmon"></div><div class="avocado"></div><div class="wasabi"></div><div class="cheese" data-cheese="cream"></div></div>
//es5
var maki = Chirashi.createElement('.maki')
Chirashi.append(document.body, maki)
Chirashi.append(maki, ['.salmon[data-fish="salmon"]', '.cheese[data-cheese="cream"]'])
Chirashi.insertBefore('.cheese', ['.avocado', '.wasabi']) //returns: <div class="maki"><div class="salmon" data-fish="salmon"></div><div class="avocado"></div><div class="wasabi"></div><div class="cheese" data-cheese="cream"></div></div>
Returns (Node | undefined) element - The element for chaining or undefined if no element found or element has no parent.
Get the next sibling of element.
Parameters
element **(string | Array | NodeList |
HTMLCollection | NonDocumentTypeChildNode)** The element. Note that it’ll be passed to getElement to ensure there’s only one. |
Examples
//esnext
import { createElement, append, next } from 'chirashi'
const maki = createElement('.maki')
append(maki, '.salmon[data-fish="salmon"]') //returns: <div class="maki"><div class="salmon" data-fish="salmon"></div></div>
const avocado = createElement('.avocado')
append(maki, [avocado, '.cheese[data-cheese="cream"]']) //returns: <div class="maki"><div class="salmon" data-fish="salmon"></div><div class="avocado"></div><div class="cheese" data-cheese="cream"></div></div>
next(avocado) //returns: <div class="cheese" data-cheese="cream"></div>
//es5
var maki = Chirashi.createElement('.maki')
Chirashi.append(maki, '.salmon[data-fish="salmon"]') //returns: <div class="maki"><div class="salmon" data-fish="salmon"></div></div>
var avocado = Chirashi.createElement('.avocado')
Chirashi.append(maki, [avocado, '.cheese[data-cheese="cream"]']) //returns: <div class="maki"><div class="salmon" data-fish="salmon"></div><div class="avocado"></div><div class="cheese" data-cheese="cream"></div></div>
Chirashi.next(avocado) //returns: <div class="cheese" data-cheese="cream"></div>
Returns **(Node | null)** nextElement - The element’s next sibling or null if no element found. |
Returns the parent node of the element.
Parameters
element **(string | Array | NodeList |
HTMLCollection | Node)** The element. Note that it’ll be passed to getElement to ensure there’s only one. |
Examples
//esnext
import { createElement, append, parent } from 'chirashi'
const maki = createElement('.maki')
append(document.body, maki)
append(maki, '.salmon[data-fish="salmon"]') //returns: <div class="maki"><div class="salmon" data-fish="salmon"></div></div>
parent('.salmon') //returns: <div class="maki"><div class="salmon" data-fish="salmon"></div></div>
//es5
var maki = Chirashi.createElement('.maki')
append(maki
Chirashi.append(document.body, maki)
Chirashi.append(maki, '.salmon[data-fish="salmon"]') //returns: <div class="maki"><div class="salmon" data-fish="salmon"></div></div>
Chirashi.parent('.salmon') //returns: <div class="maki"><div class="salmon" data-fish="salmon"></div></div>
Returns **(document | Element | null)** parentElement - The parent node or null if no element found. |
Returns an array of every element’s ancestors.
Parameters
element **(string | Array | NodeList |
HTMLCollection | Node)** The element. Note that it’ll be passed to getElement to ensure there’s only one. |
Examples
//esnext
import { createElement, append, parents } from 'chirashi'
const maki = createElement('.maki')
append(document.body, maki)
append(maki, '.salmon[data-fish="salmon"]') //returns: <div class="maki"><div class="salmon" data-fish="salmon"></div></div>
parents('.salmon') //returns: [<div class="maki">...</div>, <body>...</body>, <html>...</html>, document]
//es5
var maki = Chirashi.createElement('.maki')
append(maki
Chirashi.append(document.body, maki)
Chirashi.append(maki, '.salmon[data-fish="salmon"]') //returns: <div class="maki"><div class="salmon" data-fish="salmon"></div></div>
Chirashi.parents('.salmon') //returns: [<div class="maki">...</div>, <body>...</body>, <html>...</html>, document]
Returns Array<Node> parents - Array of element’s ancestors.
Get the previous sibling of element.
Parameters
element **(string | Array | NodeList |
HTMLCollection | NonDocumentTypeChildNode)** The element. Note that it’ll be passed to getElement to ensure there’s only one. |
Examples
//esnext
import { createElement, append, prev } from 'chirashi'
const maki = createElement('.maki')
append(maki, '.salmon[data-fish="salmon"]') //returns: <div class="maki"><div class="salmon" data-fish="salmon"></div></div>
const avocado = createElement('.avocado')
append(maki, [avocado, '.cheese[data-cheese="cream"]']) //returns: <div class="maki"><div class="salmon" data-fish="salmon"></div><div class="avocado"></div><div class="cheese" data-cheese="cream"></div></div>
prev(avocado) //returns: <div class="salmon" data-fish="salmon"></div>
//es5
var maki = Chirashi.createElement('.maki')
Chirashi.append(maki, '.salmon[data-fish="salmon"]') //returns: <div class="maki"><div class="salmon" data-fish="salmon"></div></div>
var avocado = Chirashi.createElement('.avocado')
Chirashi.append(maki, [avocado, '.cheese[data-cheese="cream"]']) //returns: <div class="maki"><div class="salmon" data-fish="salmon"></div><div class="avocado"></div><div class="cheese" data-cheese="cream"></div></div>
Chirashi.prev(avocado) //returns: <div class="salmon" data-fish="salmon"></div>
Returns **(Node | null)** previousElement - The element’s previous sibling or null if no element found. |
Iterates over elements and removes it from DOM.
Parameters
Examples
//esnext
import { createElement, append, remove } from 'chirashi'
const maki = createElement('.maki')
append(document.body, maki)
append(maki, '.salmon[data-fish="salmon"]') //returns: <div class="maki"><div class="salmon" data-fish="salmon"></div></div>
const avocado = createElement('.avocado')
append(maki, [avocado, '.cheese[data-cheese="cream"]']) //returns: <div class="maki"><div class="salmon" data-fish="salmon"></div><div class="avocado"></div><div class="cheese" data-cheese="cream"></div></div>
remove('.cheese') //returns: [<div class="cheese" data-cheese="cream"></div>]
//es5
var maki = Chirashi.createElement('.maki')
Chirashi.append(document.body, maki)
Chirashi.append(maki, '.salmon[data-fish="salmon"]') //returns: <div class="maki"><div class="salmon" data-fish="salmon"></div></div>
var avocado = Chirashi.createElement('.avocado')
Chirashi.append(maki, [avocado, '.cheese[data-cheese="cream"]']) //returns: <div class="maki"><div class="salmon" data-fish="salmon"></div><div class="avocado"></div><div class="cheese" data-cheese="cream"></div></div>
Chirashi.remove('.cheese') //returns: [<div class="cheese" data-cheese="cream"></div>]
Returns **(Array | NodeList | HTMLCollection)** removedElements - The array or nodelist of removed dom elements. |
Iterates over attributes and removes it from each element of elements.
Parameters
elements **(string | Array | NodeList |
HTMLCollection | Element)** The iterable, selector or elements. |
attributes
…string Names of attributes to remove.Examples
//esnext
import { createElement, append, removeAttr } from 'chirashi'
const maki = createElement('.maki')
append(document.body, maki)
append(maki, ['.salmon[data-fish="salmon"]', '.cheese[data-cheese="cream"]']) //returns: <div class="maki"><div class="salmon" data-fish="salmon"></div><div class="cheese" data-cheese="cream"></div></div>
removeAttr('.salmon', 'data-fish') //returns: [<div class="salmon"></div>]
//es5
var maki = Chirashi.createElement('.maki')
Chirashi.append(document.body, maki)
Chirashi.append(maki, ['.salmon[data-fish="salmon"]', '.cheese[data-cheese="cream"]']) //returns: <div class="maki"><div class="salmon" data-fish="salmon"></div><div class="cheese" data-cheese="cream"></div></div>
Chirashi.removeAttr('.salmon', 'data-fish') //returns: [<div class="salmon"></div>]
Returns Array iterable - The getElements’ result for chaining.
Iterates over classes and remove it from each element of elements.
Parameters
elements **(string | Array | NodeList |
HTMLCollection | Element)** The iterable, selector or elements. |
classes
…string Classes to remove.Examples
//esnext
import { createElement, removeClass } from 'chirashi'
const maki = createElement('.maki.salmon.cheese.wasabi') //returns: <div class="maki salmon cheese wasabi"></div>
removeClass(maki, 'cheese', 'wasabi') //returns: [<div class="maki salmon"></div>]
//es5
var maki = Chirashi.createElement('.maki.salmon.cheese.wasabi') //returns: <div class="maki salmon cheese wasabi"></div>
Chirashi.removeClass(maki, 'cheese', 'wasabi') //returns: [<div class="maki salmon"></div>]
Returns Array iterable - The getElements’ result for chaining.
Iterates over attributes and removes it from each element of elements.
Parameters
elements **(string | Array | NodeList |
HTMLCollection | Element)** The iterable, selector or elements. |
attributes
…string Names of data attributes to remove.Examples
//esnext
import { createElement, append, removeData } from 'chirashi'
const maki = createElement('.maki')
append(document.body, maki)
append(maki, ['.salmon[data-fish="salmon"]', '.cheese[data-cheese="cream"]']) //returns: <div class="maki"><div class="salmon" data-fish="salmon"></div><div class="cheese" data-cheese="cream"></div></div>
removeData('.salmon', 'fish') //returns: [<div class="salmon"></div>]
//es5
var maki = Chirashi.createElement('.maki')
Chirashi.append(document.body, maki)
Chirashi.append(maki, ['.salmon[data-fish="salmon"]', '.cheese[data-cheese="cream"]']) //returns: <div class="maki"><div class="salmon" data-fish="salmon"></div><div class="cheese" data-cheese="cream"></div></div>
Chirashi.removeData('.salmon', 'fish') //returns: [<div class="salmon"></div>]
Returns Array iterable - The getElements’ result for chaining.
Iterates over attributes as key value pairs and apply on each element of elements.
Parameters
elements **(string | Array | NodeList |
HTMLCollection | Element)** The iterable, selector or elements. |
attributes
Object<string, (number | string)> The attributes key value pairs.Examples
//esnext
import { createElement, setAttr } from 'chirashi'
const maki = createElement('.maki')
setAttr(maki, {
dataFish: 'salmon'
}) //returns: [<div class="maki" data-fish="salmon">]
//es5
var maki = Chirashi.createElement('.maki')
Chirashi.setAttr(maki, {
dataFish: 'salmon'
}) //returns: [<div class="maki" data-fish="salmon">]
Returns Array iterable - The getElements’ result for chaining.
Iterates over data-attributes as key value pairs and apply on each element of elements.
Parameters
elements **(string | Array | NodeList |
HTMLCollection | Element)** The iterable, selector or elements. |
dataAttributes
Object<string, (number | string)> The data-attributes key value pairsExamples
//esnext
import { createElement, setData } from 'chirashi'
const maki = createElement('.maki')
setData(maki, {
fish: 'salmon'
}) //returns: [<div class="maki" data-fish="salmon">]
//es5
var maki = Chirashi.createElement('.maki')
Chirashi.setData(maki, {
fish: 'salmon'
}) //returns: [<div class="maki" data-fish="salmon">]
Returns Array iterable - The getElements’ result for chaining.
Set the inner html of elements.
Parameters
elements **(string | Array | NodeList |
HTMLCollection | Element)** The iterable, selector or elements. |
html
string The html to insert.Examples
//esnext
import { createElement, setHtml, getHtml } from 'chirashi'
const maki = createElement('p.maki')
setHtml(maki, 'salmon') //returns: [<p class="maki">salmon</p>]
getHtml(maki) //returns: "salmon"
//es5
var maki = createElement('p.maki')
setHtml(maki, 'salmon') //returns: [<p class="maki">salmon</p>]
getHtml(maki) //returns: "salmon"
Returns Array iterable - The getElements’ result for chaining.
Apply props as key value pairs on each element of elements.
Parameters
elements **(string | Array | NodeList |
HTMLCollection | Window | Node)** The iterable, selector or elements. |
props
Object The props key value pairs.Examples
//esnext
import { createElement, setProp, getProp } from 'chirashi'
const maki = createElement('input.maki')
setProp(maki, { value: 'こんにちは世界' })
getProp(maki, 'value') //returns: こんにちは世界
//es5
var maki = Chirashi.createElement('input.maki')
Chirashi.setProp(maki, { value: 'こんにちは世界' })
Chirashi.getProp(maki, 'value') //returns: こんにちは世界
Returns Array iterable - The getElements’ result for chaining.
Iterates over classes and toggle it on each element of elements.
Parameters
elements **(string | Array | NodeList |
HTMLCollection | Element)** The iterable, selector or elements. |
classes
(string | Array | Object) Array of classes or string of classes seperated with comma and/or spaces. Or object with keys being the string of classes seperated with comma and/or spaces and values function returning a booleanean.args
…anyExamples
//esnext
import { createElement, toggleClass, clone, setData, getData } from 'chirashi'
const maki = createElement('.wasabi.salmon.maki') //returns: <div class="maki salmon wasabi"></div>
const sushi = createElement('.salmon.sushi') //returns: <div class="sushi salmon"></div>
toggleClass([maki, sushi], 'wasabi') //returns: [<div class="maki salmon"></div>, <div class="sushi salmon wasabi"></div>]
const scdMaki = clone(maki)
setData(maki, { for: 'leonard' })
setData(scdMaki, { for: 'sheldon' })
toggleClass([maki, scdMaki], {
cheese: element => {
return getData(element, 'for') !== 'leonard'
}
}) //returns: [<div class="maki salmon cheese" data-for="sheldon"></div>, <div class="maki salmon" data-for="leonard"></div>]
//es5
var maki = Chirashi.createElement('.wasabi.salmon.maki') //returns: <div class="wasabi salmon maki"></div>
var sushi = Chirashi.createElement('.salmon.sushi') //returns: <div class="salmon sushi"></div>
Chirashi.toggleClass([maki, sushi], 'wasabi') //returns: [<div class="maki salmon"></div>, <div class="sushi salmon wasabi"></div>]
var scdMaki = Chirashi.clone(maki)
Chirashi.setData(maki, { for: 'leonard' })
Chirashi.setData(scdMaki, { for: 'sheldon' })
Chirashi.toggleClass([maki, scdMaki], {
cheese: function (element) {
return Chirashi.getData(element, 'for') !== 'leonard'
}
}) //returns: [<div class="maki salmon cheese" data-for="sheldon"></div>, <div class="maki salmon" data-for="leonard"></div>]
Returns Array iterable - The getElements’ result for chaining.
Delegate events listener on delegate and execute callback when target matches selector (targets doesn’t have to be in the DOM).
Parameters
selector
string The selector to match.input
Object<string, delegateCallback> An object in which keys are events to delegate seperated with coma and/or spaces and values are delegateCallbacks.target **[(string | Array | NodeList |
HTMLCollection | EventTarget)]** The event target. Note that it’ll be passed to getElement to ensure there’s only one. (optional, default document.body ) |
Examples
//esnext
import { createElement, append, delegate, trigger } from 'chirashi'
const off = delegate('.cheese, .wasabi', {
click(e, target) => {
console.log('clicked', target)
},
'mouseenter mousemove': (e, target) => {
console.log('mouse in', target)
}
})
const maki = createElement('a.cheese.maki')
const sushi = createElement('a.wasabi.sushi')
append(document.body, [maki, sushi])
trigger(maki, 'click') //simulate user's click
// LOGS: "clicked" <a class="maki cheese"></a>
trigger(sushi, 'click') //simulate user's click
// LOGS: "clicked" <a class="sushi wasabi"></a>
off('mouseenter mousemove') //remove mouseenter and mousemove listeners
off() //remove all listeners
//es5
var off = Chirashi.delegate('.cheese, .wasabi', {
'click': function (e, target) {
console.log('clicked', target)
},
'mouseenter mousemove': function(e, target) {
console.log('mouse in', target)
}
})
var maki = Chirashi.createElement('a.cheese.maki')
var sushi = Chirashi.createElement('a.wasabi.sushi')
Chirashi.append(document.body, [maki, sushi])
Chirashi.trigger(maki, 'click') //simulate user's click
// LOGS: "clicked" <a class="maki cheese"></a>
Chirashi.trigger(sushi, 'click') //simulate user's click
// LOGS: "clicked" <a class="sushi wasabi"></a>
off('mouseenter mousemove') //remove mouseenter and mousemove listeners
off() //remove all listeners
Returns offCallback off - The unbind function.
Called to off one or all events.
Parameters
events
[string] The events to off. Must be provided in the same syntax as in input.Called to remove one or all events listeners of one or all elements.
Parameters
offElements **[(string | Array | NodeList |
HTMLCollection | EventTarget)]** The iterable, selector or elements to unbind. |
events
[string] The events to unbind. Must be provided in the same syntax as in input.Callback to execute on event using delegate.
Parameters
event
Event Triggered event.target
(HTMLElement | SVGElement) Target of the event.Bind events listener on each element of elements.
Parameters
elements **(string | Array | NodeList |
HTMLCollection | EventTarget)** The iterable, selector or elements. |
input
Object<string, (eventCallback | EventObject)> An object in which keys are events to bind seperated with coma and/or spaces and values are eventCallbacks or EventObjects.Examples
//esnext
import { createElement, append, on, trigger } from 'chirashi'
const maki = createElement('a.cheese.maki')
const sushi = createElement('a.wasabi.sushi')
append(document.body, [maki, sushi])
const off = on('.cheese, .wasabi', {
click(e, target) {
console.log('clicked', target)
},
'mouseenter mousemove': {
handler: (e, target) => {
console.log('mouse in', target)
},
passive: true
}
})
trigger(maki, 'click') //simulate user's click
// LOGS: "clicked" <a class="maki cheese"></a>
trigger(sushi, 'click') //simulate user's click
// LOGS: "clicked" <a class="sushi wasabi"></a>
off(maki, 'click') //remove click event listener on maki
off() //remove all listeners from all elements
//es5
var off = Chirashi.bind('.cheese, .wasabi', {
'click': function (e, target) {
console.log('clicked', target)
},
'mouseenter mousemove': {
handler: (e, target) => {
console.log('mouse in', target)
},
passive: true
}
})
var maki = Chirashi.createElement('a.cheese.maki')
var sushi = Chirashi.createElement('a.wasabi.sushi')
Chirashi.append(document.body, [maki, sushi])
Chirashi.trigger(maki, 'click') //simulate user's click
// LOGS: "clicked" <a class="maki cheese"></a>
Chirashi.trigger(sushi, 'click') //simulate user's click
// LOGS: "clicked" <a class="sushi wasabi"></a>
off(maki, 'click') //remove click event listener on maki
off() //remove all listeners from all elements
Returns offCallback off - The unbinding function.
Options to bind event.
Properties
handler
eventCallback The callback to execute on event.capture
[boolean] Indicates that events of this type will be dispatched to the registered listener before being dispatched to any EventTarget beneath it in the DOM tree.once
[boolean] Indicates that the listener should be invoked at most once after being added. If it is true, the listener would be removed automatically when it is invoked.passive
[boolean] Indicates that the listener will never call preventDefault(). If it does, the user agent should ignore it and generate a console warning.Callback to execute on event.
Parameters
event
Event Triggered event.Bind events listener on each element of elements and unbind after first triggered.
Parameters
elements **(string | Array | NodeList |
HTMLCollection | EventTarget)** The iterable, selector or elements. |
input
Object<string, eventCallback> An object in which keys are events to bind seperated with coma and/or spaces and values are eventCallbacks.eachElement
[boolean] If true only current target’s events listeners will be removed after trigger. (optional, default false
)eachEvent
[boolean] If true only triggered event group of events listeners will be removed. (optional, default false
)Examples
//esnext
import { createElement, append, once, trigger } from 'chirashi'
const maki = createElement('a.cheese.maki')
const sushi = createElement('a.wasabi.sushi')
append(document.body, [maki, sushi])
const cancel = once('.cheese, .wasabi', {
click(e, target) => {
console.log('clicked', target)
},
'mouseenter mousemove': (e, target) => {
console.log('mouse in', target)
}
}, true, true)
trigger(maki, 'click') //simulate user's click
// LOGS: "clicked" <a class="maki cheese"></a>
// click event listener was auto-removed from maki
trigger(sushi, 'click') //simulate user's click
// LOGS: "clicked" <a class="sushi wasabi"></a>
// click event listener was auto-removed from sushi
cancel() //remove all listeners from all elements
once('.cheese, .wasabi', {
click(e, target) => {
console.log('clicked', target)
}
})
trigger(maki, 'click') //simulate user's click
// LOGS: "clicked" <a class="maki cheese"></a>
// all events listeners were auto-removed from all elements
trigger(sushi, 'click') //simulate user's click
// won't log anything
//es5
var maki = Chirashi.createElement('a.cheese.maki')
var sushi = Chirashi.createElement('a.wasabi.sushi')
Chirashi.append(document.body, [maki, sushi])
var cancel = Chirashi.once('.cheese, .wasabi', {
click: function (e, target) {
console.log('clicked', target)
},
'mouseenter mousemove': function (e, target) {
console.log('mouse in', target)
}
}, true, true)
Chirashi.trigger(maki, 'click') //simulate user's click
// LOGS: "clicked" <a class="maki cheese"></a>
// click event listener was auto-removed from maki
Chirashi.trigger(sushi, 'click') //simulate user's click
// LOGS: "clicked" <a class="sushi wasabi"></a>
// click event listener was auto-removed from sushi
cancel() //remove all listeners from all elements
Chirashi.once('.cheese, .wasabi', {
click: function (e, target) {
console.log('clicked', target)
}
})
Chirashi.trigger(maki, 'click') //simulate user's click
// LOGS: "clicked" <a class="maki cheese"></a>
// all events listeners were auto-removed from all elements
Chirashi.trigger(sushi, 'click') //simulate user's click
// won't log anything
Returns offCallback cancel - cancel function for unbinding.
Execute callback when dom is ready.
Parameters
callback
eventCallback The callback.Examples
//esnext
import { ready } from 'chirashi'
ready(() => {
console.log('Hello World!')
})
// Dom already complete or event fired.
// LOGS: "Hello World!"
//es5
Chirashi.ready(function () {
console.log('Hello World!')
})
// Dom already complete or event fired.
// LOGS: "Hello World!"
Trigger events on elements with data
Parameters
elements **(string | Array | NodeList |
HTMLCollection | EventTarget)** The iterable, selector or elements. |
events
string The events that should be tiggered seperated with spacesdata
Object The events’ dataoptions
(optional, default {}
)Examples
//esnext
import { createElement, append, on, trigger } from 'chirashi'
const maki = createElement('a.cheese.maki')
const sushi = createElement('a.wasabi.sushi')
append(document.body, [maki, sushi])
const listener = on('.cheese, .wasabi', {
click(e, target) => {
console.log('clicked', target)
}
})
trigger(maki, 'click') //simulate user's click
// LOGS: "clicked" <a class="maki cheese"></a>
trigger(sushi, 'click') //simulate user's click
// LOGS: "clicked" <a class="sushi wasabi"></a>
//es5
var listener = Chirashi.bind('.cheese, .wasabi', {
'click': function (e, target) {
console.log('clicked', target)
}
})
var maki = Chirashi.createElement('a.cheese.maki')
var sushi = Chirashi.createElement('a.wasabi.sushi')
Chirashi.append(document.body, [maki, sushi])
Chirashi.trigger(maki, 'click') //simulate user's click
// LOGS: "clicked" <a class="maki cheese"></a>
Chirashi.trigger(sushi, 'click') //simulate user's click
// LOGS: "clicked" <a class="sushi wasabi"></a>
Returns Array iterable - The getElements’ result for chaining.
lib/styles/clearStyle.js:31-36
Clear inline style properties from elements.
Parameters
elements **(string | Array | NodeList |
HTMLCollection | HTMLElement)** The iterable, selector or elements. |
props
…string The style properties to clear.Examples
//esnext
import { createElement, setStyle, clearStyle } from 'chirashi'
const maki = createElement('a.cheese.maki')
setStyleProp(maki, {
position: 'absolute',
top: 10,
width: 200,
height: 200,
background: 'red'
}) // returns: [<a class="cheese maki" style="position: 'absolute'; top: '10px'; width: '200px'; height: '200px'; background: 'red';"></a>]
clearStyle(maki, 'width', 'height', 'background') // returns: [<a class="cheese maki" style="position: 'absolute'; top: '10px';"></a>]
//es5
var maki = Chirashi.createElement('a.cheese.maki')
Chirashi.setStyleProp(maki, {
position: 'absolute',
top: 10,
width: 200,
height: 200,
background: 'red'
}) // returns: [<a class="cheese maki" style="position: 'absolute'; top: '10px'; width: '200px'; height: '200px'; background: 'red';"></a>]
Chirashi.clearStyle(maki, 'width', 'height', 'background') // returns: [<a class="cheese maki" style="position: 'absolute'; top: '10px';"></a>]
Returns Array iterable - The getElements’ result for chaining.
lib/styles/clientRect.js:56-72
Return the screen relative position of an element.
Parameters
element **(string | Array | NodeList |
HTMLCollection | Element)** The element. Note that it’ll be passed to getElement to ensure there’s only one. |
Examples
esnext
import { setStyleProp, append, clientRect } from 'chirashi'
setStyleProp([document.documentElement, document.body], {
position: 'relative',
margin: 0,
padding: 0
})
append(document.body, '.poulp')
const poulp = setStyleProp('.poulp', {
display: 'block',
position: 'absolute',
top: 200,
left: 240,
width: 100,
height: 100,
background: 'red'
})
clientRect(poulp) // returns: { bottom: 300, height: 100, left: 240, right: 0, top: 200, width: 100 }
es5
Chirashi.setStyleProp([document.documentElement, document.body], {
position: 'relative',
margin: 0,
padding: 0
})
Chirashi.append(document.body, '.poulp')
var poulp = Chirashi.setStyleProp('.poulp', {
display: 'block',
position: 'absolute',
top: 200,
left: 240,
width: 100,
height: 100,
background: 'red'
})
Chirashi.clientRect(poulp) // returns: { bottom: 300, height: 100, left: 240, right: 0, top: 200, width: 100 }
Returns (Object | boolean) clientRect - Element’s screen position or false if no element found.
Returns number clientRect.bottom - Y-coordinate, relative to the viewport origin, of the bottom of the rectangle box.
Returns number clientRect.height - Height of the rectangle box (This is identical to bottom minus top).
Returns number clientRect.left - X-coordinate, relative to the viewport origin, of the left of the rectangle box.
Returns number clientRect.right - X-coordinate, relative to the viewport origin, of the right of the rectangle box.
Returns number clientRect.top - Y-coordinate, relative to the viewport origin, of the top of the rectangle box.
Returns number clientRect.width - Width of the rectangle box (This is identical to right minus left).
lib/styles/getComputedStyle.js:25-27
Get computed style of an element.
Parameters
element **(string | Array | NodeList |
HTMLCollection | Element)** The element. Note that it’ll be passed to getElement to ensure there’s only one. |
Examples
//esnext
import { append, setStyleProp, getComputedStyle } from 'chirashi'
append(document.body, '.maki')
const maki = setStyleProp('.maki', {
display: 'block',
position: 'relative',
top: 10
})
getComputedStyle(maki) //returns: { display: 'block', position: 'relative', top: '10px', [... other properties according to the browser] }
//es5
Chirashi.append(document.body, '.maki')
var maki = Chirashi.setStyleProp('.maki', {
display: 'block',
position: 'relative',
top: 10
})
Chirashi.getComputedStyle(maki) //returns: { display: 'block', position: 'relative', top: '10px', [... other properties according to the browser] }
Returns Object<string, string> computedStyle - the computed style of the element.
Get element’s height in pixels.
Parameters
element **(string | Array | NodeList |
HTMLCollection | Element | HTMLElement)** The element. Note that it’ll be passed to getElement to ensure there’s only one. |
offset
[boolean] If true height will include scrollbar and borders to size. (optional, default false
)Examples
//esnext
import { append, setStyleProp, getHeight } from 'chirashi'
append(document.body, '.maki')
const maki = setStyleProp('.maki', {
display: 'block',
border: '20px solid red',
padding: 10,
height: 200,
width: 200
})
getHeight(maki, true) //returns: 260
getHeight(maki) //returns: 220
//es5
Chirashi.append(document.body, '.maki')
var maki = Chirashi.setStyleProp('.maki', {
display: 'block',
border: '20px solid red',
padding: 10,
height: 200,
width: 200
})
Chirashi.getHeight(maki, true) //returns: 260
Chirashi.getHeight(maki) //returns: 220
Returns number height - The height in pixels.
Get element’s size in pixels.
Parameters
element **(string | Array | NodeList |
HTMLCollection | Element | HTMLElement)** The element. Note that it’ll be passed to getElement to ensure there’s only one. |
offset
[boolean] If true size will include scrollbar and borders. (optional, default false
)Examples
//esnext
import { append, setStyleProp, getSize } from 'chirashi'
append(document.body, '.maki')
const maki = setStyleProp('.maki', {
display: 'block',
border: '20px solid red',
padding: 10,
height: 200,
width: 200
})
getSize(maki, true) //returns: { width: 260, height: 260 }
getSize(maki) //returns: { width: 220, height: 220 }
//es5
Chirashi.append(document.body, '.maki')
var maki = Chirashi.setStyleProp('.maki', {
display: 'block',
border: '20px solid red',
padding: 10,
height: 200,
width: 200
})
Chirashi.getSize(maki, true) //returns: { width: 260, height: 260 }
Chirashi.getSize(maki) //returns: { width: 220, height: 220 }
Returns number size - The size in pixels.
lib/styles/getStyleProp.js:26-32
Get computed style props of an element. While getComputedStyle returns all properties, getStyleProp returns only needed and convert unitless numeric values or pixels values into numbers.
Parameters
element **(string | Array | NodeList |
HTMLCollection | Element)** The element. Note that it’ll be passed to getElement to ensure there’s only one. |
props
…anyExamples
//esnext
import { append, setStyleProp, getStyleProp } from 'chirashi'
append(document.body, '.maki')
const maki = setStyleProp('.maki', {
display: 'block',
position: 'relative',
top: 10
})
getStyleProp(maki, 'display', 'top') //returns: { display: "block", top: 10 }
//es5
Chirashi.append(document.body, '.maki')
var maki = Chirashi.setStyleProp('.maki', {
display: 'block',
position: 'relative',
top: 10
})
Chirashi.getStyleProp(maki, 'display', 'top') //returns: { display: "block", top: 10 }
Returns (string | number | Object<string, (string | number)>) computedStyle - Value of computed for provided prop if only one or parsed copy of element’s computed style if several.
Get element’s width in pixels.
Parameters
element **(string | Array | NodeList |
HTMLCollection | Element | HTMLElement)** The element. Note that it’ll be passed to getElement to ensure there’s only one. |
offset
[boolean] If true width will include scrollbar and borders to size. (optional, default false
)Examples
//esnext
import { append, setStyleProp, getWidth } from 'chirashi'
append(document.body, '.maki')
const maki = setStyleProp('.maki', {
display: 'block',
border: '20px solid red',
padding: 10,
height: 200,
width: 200
})
getWidth(maki, true) //returns: 260
getWidth(maki) //returns: 220
//es5
Chirashi.append(document.body, '.maki')
var maki = Chirashi.setStyleProp('.maki', {
display: 'block',
border: '20px solid red',
padding: 10,
height: 200,
width: 200
})
Chirashi.getWidth(maki, true) //returns: 260
Chirashi.getWidth(maki) //returns: 220
Returns number width - The width in pixels.
Hide each element of elements using visibility.
Parameters
elements **(string | Array | NodeList |
HTMLCollection | HTMLElement)** The iterable, selector or elements. |
Examples
//esnext
import { append, hide, getStyleProp }
append(document.body, '.maki')
const maki = hide('.maki')
getStyleProp(maki, 'visibility') // returns: "hidden"
//es5
Chirashi.append(document.body, '.maki')
var maki = Chirashi.hide('.maki')
Chirashi.getStyleProp(maki, 'visibility') // returns: "hidden"
Returns Array iterable - The getElements’ result for chaining.
Returns the top and left offset of an element. Offset is relative to web page.
Parameters
element **(string | Array | NodeList |
HTMLCollection | Element)** The element. Note that it’ll be passed to getElement to ensure there’s only one. |
Examples
//esnext
import { setStyleProp, append, offset }
setStyleProp([document.documentElement, document.body], {
position: 'relative',
margin: 0,
padding: 0
})
append(document.body, '.sushi')
const sushi = setStyleProp('.sushi', {
display: 'block',
width: 100,
height: 100,
position: 'absolute',
top: 200,
left: 240,
background: 'red'
})
offset(sushi) // returns: { top: 200, left: 240 }
//es5
Chirashi.setStyleProp([document.documentElement, document.body], {
position: 'relative',
margin: 0,
padding: 0
})
Chirashi.append(document.body, '.sushi')
var sushi = Chirashi.setStyleProp('.sushi', {
display: 'block',
width: 100,
height: 100,
position: 'absolute',
top: 200,
left: 240,
background: 'red'
})
Chirashi.offset(sushi) // returns: { top: 200, left: 240 }
Returns (Object | boolean) offset - Offset object or false if no element found.
Returns Object.top top - Top offset in pixels.
Returns Object.left left - Left offset in pixels.
Return the top and left position of an element. Position is relative to parent.
Parameters
element **(string | Array | NodeList |
HTMLCollection | document | Element)** The selector or dom element. |
Examples
//esnext
import { append, setStyleProp, position } from 'chirashi'
setStyleProp([document.documentElement, document.body], {
position: 'relative',
margin: 0,
padding: 0
})
append(document.body, '.maki')
append('.maki', '.salmon')
setStyleProp('.maki', {
display: 'block',
position: 'absolute',
top: 200,
left: 240,
width: 100,
height: 100,
borderRadius: '50%',
background: 'black'
})
const salmon = setStyleProp('.salmon', {
display: 'block',
position: 'absolute',
top: 20,
left: 10,
width: 10,
height: 10,
borderRadius: '50%',
background: 'pink'
})
position(salmon) // returns: { top: 20, left: 10 }
//es5
Chirashi.setStyleProp([document.documentElement, document.body], {
position: 'relative',
margin: 0,
padding: 0
})
Chirashi.append(document.body, '.maki')
Chirashi.append('.maki', '.salmon')
Chirashi.setStyleProp('.maki', {
display: 'block',
position: 'absolute',
top: 200,
left: 240,
width: 100,
height: 100,
borderRadius: '50%',
background: 'black'
})
var salmon = Chirashi.setStyleProp('.salmon', {
display: 'block',
position: 'absolute',
top: 20,
left: 10,
width: 10,
height: 10,
borderRadius: '50%',
background: 'pink'
})
Chirashi.position(salmon) // returns: { top: 20, left: 10 }
Returns (Object | boolean) offset - Offset object or false if no element found.
Returns Object.top top - Top position in pixels.
Returns Object.left left - Left position in pixels.
lib/styles/screenPosition.js:52-59
Return the screen relative position of an element.
Parameters
element **(string | Array | NodeList |
HTMLCollection | Element)** The element. Note that it’ll be passed to getElement to ensure there’s only one. |
Examples
esnext
import { setStyleProp, append, screenPosition } from 'chirashi'
setStyleProp([document.documentElement, document.body], {
position: 'relative',
margin: 0,
padding: 0
})
append(document.body, '.poulp')
const poulp = setStyleProp('.poulp', {
display: 'block',
position: 'absolute',
top: 200,
left: 240,
width: 100,
height: 100,
background: 'red'
})
screenPosition(poulp) // returns: { top: 200, left: 240 }
es5
Chirashi.setStyleProp([document.documentElement, document.body], {
position: 'relative',
margin: 0,
padding: 0
})
Chirashi.append(document.body, '.poulp')
var poulp = Chirashi.setStyleProp('.poulp', {
display: 'block',
position: 'absolute',
top: 200,
left: 240,
width: 100,
height: 100,
background: 'red'
})
Chirashi.screenPosition(poulp) // returns: { top: 200, left: 240 }
Returns (Object | boolean) screenPosition - Element’s screen position or false if no element found.
Returns Object.top top - Y-coordinate, relative to the viewport origin, of the top of the rectangle box.
Returns Object.left left - X-coordinate, relative to the viewport origin, of the left of the rectangle box.
lib/styles/setCssVariable.js:27-27
Set the provided css variables to elements.
Parameters
elements **(string | Array | NodeList |
HTMLCollection)** The iterable, selector or elements. |
variables
Object<string, (number | string)> The key-value pairs of variables to set, the variable name shouldn’t be prefixed with – and can be in camelCase.Examples
//esnext
import { append, setCssVariable } from 'chirashi'
append(document.body, '.maki')
setCssVariable('.maki', {
opacity: 0.5,
textColor: 'blue'
}) // returns: [<div class="maki" style="--opacity: 0.5; --text-color: 'rgb(0,0,255)'"></div>]
//es5
Chirashi.append(document.body, '.maki')
Chirashi.setCssVariable('.maki', {
opacity: 0.5,
textColor: 'blue'
}) // returns: [<div class="maki" style="--opacity: 0.5; --text-color: 'rgb(0,0,255)'"></div>]
Returns Array iterable - The getElements’ result for chaining.
Set the provided height to elements.
Parameters
elements **(string | Array | NodeList |
HTMLCollection | HTMLElement)** The iterable, selector or elements. |
height
(number | string) The height as number or string. For number, unit used will be pixels.Examples
//esnext
import { append, setHeight } from 'chirashi'
append(document.body, '.maki')
setHeight('.maki', 20) // returns: [<div class="maki" style="height: 20px;"></div>]
setHeight('.maki', '100%') // returns: [<div class="maki" style="height: 100%;"></div>]
//es5
Chirashi.append(document.body, '.maki')
Chirashi.setHeight('.maki', 20) // returns: [<div class="maki" style="height: 20px;"></div>]
Chirashi.setHeight('.maki', '100%') // returns: [<div class="maki" style="height: 100%;"></div>]
Returns Array iterable - The getElements’ result for chaining.
Set the provided size to elements.
Parameters
elements **(string | Array | NodeList |
HTMLCollection)** The iterable, selector or elements. |
width
(number | string) The width as number or string. For number, unit used will be pixels.height
(number | string) The height as number or string. For number, unit used will be pixels.Examples
//esnext
import { append, setSize } from 'chirashi'
append(document.body, '.maki')
setSize('.maki', 20, '100%') // returns: [<div class="maki" style="width: 20px; height: 100%;"></div>]
//es5
Chirashi.append(document.body, '.maki')
Chirashi.setSize('.maki', 20, '100%') // returns: [<div class="maki" style="width: 20px; height: 100%;"></div>]
Returns Array iterable - The getElements’ result for chaining.
lib/styles/setStyleProp.js:76-76
Set the provided style to elements.
Parameters
elements **(string | Array | NodeList |
HTMLCollection)** The iterable, selector or elements. |
style
Object<string, (number | string)> The style options as object with keys the css property and values, string values or number. If the value is a number and property doesn’t support unitless values, pixels will be used.Examples
//esnext
import { append, setStyleProp } from 'chirashi'
append(document.body, '.maki')
append('.maki', '.salmon')
setStyleProp('.maki', {
display: 'block',
position: 'absolute',
top: 200,
left: 240,
width: 100,
height: 100,
borderRadius: '50%',
background: 'black'
}) // returns: [<div class="maki" style="display: block; position: absolute; top: 200px; left: 240px; width: 100px; height: 100px; border-radius: 50%; background: black;"><div class="salmon"></div></div>]
const salmon = setStyleProp('.salmon', {
display: 'block',
position: 'absolute',
top: 20,
left: 10,
width: 10,
height: 10,
borderRadius: '50%',
background: 'pink'
}) // returns: [<div class="salmon" style="display: block; position: absolute; top: 20px; left: 10px; width: 10px; height: 10px; border-radius: 50%; background: pink;"></div>]
//es5
Chirashi.append(document.body, '.maki')
Chirashi.append('.maki', '.salmon')
Chirashi.setStyleProp('.maki', {
display: 'block',
position: 'absolute',
top: 200,
left: 240,
width: 100,
height: 100,
borderRadius: '50%',
background: 'black'
}) // returns: [<div class="maki" style="display: block; position: absolute; top: 200px; left: 240px; width: 100px; height: 100px; border-radius: 50%; background: black;"><div class="salmon"></div></div>]
const salmon = Chirashi.setStyleProp('.salmon', {
display: 'block',
position: 'absolute',
top: 20,
left: 10,
width: 10,
height: 10,
borderRadius: '50%',
background: 'pink'
}) // returns: [<div class="salmon" style="display: block; position: absolute; top: 20px; left: 10px; width: 10px; height: 10px; border-radius: 50%; background: pink;"></div>]
Returns Array iterable - The getElements’ result for chaining.
Set the provided width to elements.
Parameters
elements **(string | Array | NodeList |
HTMLCollection | HTMLElement)** The iterable, selector or elements. |
width
(number | string) The width as number or string. For number, unit used will be pixels.Examples
//esnext
import { append, setWidth } from 'chirashi'
append(document.body, '.maki')
setWidth('.maki', 20) // returns: [<div class="maki" style="width: 20px;"></div>]
setWidth('.maki', '100%') // returns: [<div class="maki" style="width: 100%;"></div>]
//es5
Chirashi.append(document.body, '.maki')
Chirashi.setWidth('.maki', 20) // returns: [<div class="maki" style="width: 20px;"></div>]
Chirashi.setWidth('.maki', '100%') // returns: [<div class="maki" style="width: 100%;"></div>]
Returns Array iterable - The getElements’ result for chaining.
Show each element of elements using visibility.
Parameters
elements **(string | Array | NodeList |
HTMLCollection | HTMLElement)** The iterable, selector or elements. |
Examples
//esnext
import { append, show, getStyleProp }
append(document.body, '.maki')
const maki = show('.maki')
getStyleProp(maki, 'visibility') // returns: "visible"
//es5
Chirashi.append(document.body, '.maki')
var maki = Chirashi.show('.maki')
Chirashi.getStyleProp(maki, 'visibility') // returns: "visible"
Returns Array iterable - The getElements’ result for chaining.
Compute and apply 3d transform matrix from provided transformation to each element of elements.
Parameters
elements **(string | Array | NodeList |
HTMLCollection)** The iterable or selector. |
transformation
Transformation The transformation as an objectExamples
//esnext
import { createElement, setHtml, transform } from 'chirashi'
const wasabiPea = createElement('p')
setHtml(wasabiPea, 'Wasabi')
transform(wasabiPea, {}) // returns: [<p style="transform: "matrix3d(1,0,0,0,0,1,0,0,0,0,1,0,0,0,0,1)">Wasabi</p>]
transform(wasabiPea, {x: 5, y: 6, z: 7}) // returns: [<p style="transform: "matrix3d(1,0,0,0,0,1,0,0,0,0,1,0,5,6,7,1)">Wasabi</p>]
transform(wasabiPea, {scale: 2}) // returns: [<p style="transform: "matrix3d(2,0,0,0,0,2,0,0,0,0,1,0,0,0,0,1)">Wasabi</p>]
transform(wasabiPea, {scale: {x: 2, y: 3, z: 4}}) // returns: [<p style="transform: "matrix3d(2,0,0,0,0,3,0,0,0,0,4,0,0,0,0,1)">Wasabi</p>]
transform(wasabiPea, {rotate: 45}) // returns: [<p style="transform: "matrix3d(0.53,0.85,0,0,-0.85,0.53,0,0,0,0,1,0,0,0,0,1)">Wasabi</p>]
transform(wasabiPea, {rotate: {x: 45, y: 20, z: 15}}) // returns: [<p style="transform: "matrix3d(-0.31,0.65,-0.91,0,-0.65,-0.4,0.85,0,0.91,-0.85,0.21,0,0,0,0,1)">Wasabi</p>]
transform(wasabiPea, {skew: 45}) // returns: [<p style="transform: "matrix3d(1,1.62,0,0,1.62,1,0,0,0,0,1,0,0,0,0,1)">Wasabi</p>]
transform(wasabiPea, {skew: {x: 25, y: 45}}) // returns: [<p style="transform: "matrix3d(1,1.62,0,0,-0.13,1,0,0,0,0,1,0,0,0,0,1)">Wasabi</p>]
transform(wasabiPea, {x: 5, y: 6, z: 7, scale: {x: 2, y: 3}, rotate: {x: 45, y: 20, z: 15}, skew: {x: 25, y: 45}}) // returns: [<p style="transform: "matrix3d(-0.62,2.27,-0.91,0,-0.78,-1.2,0.85,0,0.91,-0.85,0.21,0,5,6,7,1)">Wasabi</p>]
//es5
var wasabiPea = Chirashi.createElement('p')
Chirashi.setHtml(wasabiPea, 'Wasabi')
Chirashi.transform(wasabiPea, {}) // returns: [<p style="transform: "matrix3d(1,0,0,0,0,1,0,0,0,0,1,0,0,0,0,1)">Wasabi</p>]
Chirashi.transform(wasabiPea, {x: 5, y: 6, z: 7}) // returns: [<p style="transform: "matrix3d(1,0,0,0,0,1,0,0,0,0,1,0,5,6,7,1)">Wasabi</p>]
Chirashi.transform(wasabiPea, {scale: 2}) // returns: [<p style="transform: "matrix3d(2,0,0,0,0,2,0,0,0,0,1,0,0,0,0,1)">Wasabi</p>]
Chirashi.transform(wasabiPea, {scale: {x: 2, y: 3, z: 4}}) // returns: [<p style="transform: "matrix3d(2,0,0,0,0,3,0,0,0,0,4,0,0,0,0,1)">Wasabi</p>]
Chirashi.transform(wasabiPea, {rotate: 45}) // returns: [<p style="transform: "matrix3d(0.53,0.85,0,0,-0.85,0.53,0,0,0,0,1,0,0,0,0,1)">Wasabi</p>]
Chirashi.transform(wasabiPea, {rotate: {x: 45, y: 20, z: 15}}) // returns: [<p style="transform: "matrix3d(-0.31,0.65,-0.91,0,-0.65,-0.4,0.85,0,0.91,-0.85,0.21,0,0,0,0,1)">Wasabi</p>]
Chirashi.transform(wasabiPea, {skew: 45}) // returns: [<p style="transform: "matrix3d(1,1.62,0,0,1.62,1,0,0,0,0,1,0,0,0,0,1)">Wasabi</p>]
Chirashi.transform(wasabiPea, {skew: {x: 25, y: 45}}) // returns: [<p style="transform: "matrix3d(1,1.62,0,0,-0.13,1,0,0,0,0,1,0,0,0,0,1)">Wasabi</p>]
Chirashi.transform(wasabiPea, {x: 5, y: 6, z: 7, scale: {x: 2, y: 3}, rotate: {x: 45, y: 20, z: 15}, skew: {x: 25, y: 45}}) // returns: [<p style="transform: "matrix3d(-0.62,2.27,-0.91,0,-0.78,-1.2,0.85,0,0.91,-0.85,0.21,0,5,6,7,1)">Wasabi</p>]
Returns Array iterable - The getElements’ result for chaining.
Returns function domElements.chrshPush - Methods to push dom elements into the array. Accepts same input as getElements.
lib/styles/transform.js:75-103
Properties
x
[number] Translation value on x axis in pixels.y
[number] Translation value on y axis in pixels.z
[number] Translation value on z axis in pixels.scale
[(number | object)] Scale value for x and y axes or object of values for axes.
rotate
[(number | object)] Rotation value for z axis in radians or object of values for axes.
skew
[(number | object)] Skew value for x and y axes in radians or object of values for axes.