This file contains hidden or 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 dateFormat from 'dateformat'; | |
export const exportFrame = (canvas, fileFunction = null) => { | |
const link = document.createElement('a'); | |
const timestamp = dateFormat(new Date(), 'yyyy-mm-dd-HH-MM-ss'); | |
const extension = '.png'; | |
let filename = `${timestamp}${extension}`; | |
if (fileFunction) filename = fileFunction({ canvas, timestamp, extension }); |
This file contains hidden or 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
export const getDateIni = (date) => { | |
const d = date.getUTCDate(); | |
const m = date.getUTCMonth(); | |
const y = date.getUTCFullYear(); | |
// 00:00 | |
const ini = new Date(Date.UTC(y, m, d)); | |
return ini; | |
}; |
This file contains hidden or 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 THREE from 'three'; | |
import glslify from 'glslify'; | |
export default class CustomMaterial extends THREE.MeshStandardMaterial { | |
constructor (opt) { | |
super(opt); | |
this.type = 'CustomMaterial'; | |
this.uniforms = THREE.UniformsUtils.merge([ |
This file contains hidden or 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
let alreadyTested = false; | |
let passiveSupported = false; | |
const isSupported = () => { | |
if (alreadyTested) return passiveSupported; | |
alreadyTested = true; | |
// Test via a getter in the options object to see if the passive property is accessed | |
try { | |
let opts = Object.defineProperty({}, 'passive', { |
This file contains hidden or 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 locale2 from 'locale2'; | |
import { getParam } from './query.utils'; | |
const getLocale = (_list, _default) => { | |
const list = _list || ['en']; | |
const detected = getParam('locale') || locale2; | |
const short = detected.split('-')[0]; | |
const defaultLocale = _default || list[0]; |
This file contains hidden or 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
const addWheelListener = (el, cb, useCapture = false) => { | |
let prefix = ''; | |
let listener; | |
let eventName; | |
if (window.addEventListener) listener = 'addEventListener'; | |
else { | |
listener = 'attachEvent'; | |
prefix = 'on'; | |
} |
This file contains hidden or 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
const hexToRGB = (hex, normalized) => { | |
const result = /^#?([a-f\d]{2})([a-f\d]{2})([a-f\d]{2})$/i.exec(hex); | |
const factor = normalized ? 255 : 1; | |
return result ? { | |
r: parseInt(result[1], 16) / factor, | |
g: parseInt(result[2], 16) / factor, | |
b: parseInt(result[3], 16) / factor | |
} : null; | |
}; |
This file contains hidden or 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
// file.utils.js | |
const addFileDropListener = (el, callback) => { | |
if (window.FileReader) { | |
const cancel = (e) => { | |
if (e.preventDefault) e.preventDefault(); | |
return false; | |
}; |
This file contains hidden or 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
const getComputedTranslate = (el) => { | |
const t = { x: 0, y: 0, z: 0 }; | |
if (!window.getComputedStyle) return t; | |
const style = getComputedStyle(el); | |
const transform = style.transform || style.webkitTransform || style.mozTransform; | |
let mat, x, y, z; | |
mat = transform.match(/^matrix3d\((.+)\)$/); |
This file contains hidden or 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
export const addLeadingZero = (num, zeros = 1) => { | |
let string = String(num); | |
for (let i = 0; i < zeros; i++) { | |
if (num < Math.pow(10, (i + 1)) && num > -1) string = `0${string}`; | |
} | |
return string; | |
}; |
NewerOlder