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
/** | |
* Converts an image to a dataURL | |
* @param {String} src The src of the image | |
* @param {Function} callback | |
* @param {String} outputFormat [outputFormat='image/png'] | |
* @url https://gist.github.com/HaNdTriX/7704632/ | |
* @docs https://developer.mozilla.org/en-US/docs/Web/API/HTMLCanvasElement#Methods | |
* @author HaNdTriX | |
* @example | |
* |
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 Y from "yjs"; | |
import { bindProxyAndYMap } from "valtio-yjs"; | |
import { WebrtcProvider } from "y-webrtc"; | |
import { IndexeddbPersistence } from "y-indexeddb"; | |
import { proxy } from "valtio"; | |
import { useMemo, useEffect } from "react"; | |
type WebrtcProviderOptions = ConstructorParameters<typeof WebrtcProvider>[2]; | |
export default function useRoom<T extends Record<string, unknown>>( |
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 { useEffect, useRef } from "react"; | |
type ElementPickerProps = { | |
onPick: (event: MouseEvent, element: HTMLElement) => void; | |
}; | |
export default function ElementPicker({ onPick }: ElementPickerProps) { | |
const lastSelectedRef = useRef<HTMLElement>(); | |
const topRef = useRef<HTMLDivElement>(null); | |
const rightRef = useRef<HTMLDivElement>(null); |
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
/** | |
* Convert relative paths to absolute paths | |
* @author HaNdTriX | |
* @param {string} html - HTML string | |
* @param {string} baseUrl - base url to prepend to relative paths | |
* @param {string[]} [attributes] - attributes to convert | |
* @returns {string} | |
*/ | |
function absolutify( | |
html, |
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 createLogger(namespace) { | |
return new Proxy(console, { | |
get(target, key) { | |
return target[key].bind(target, "\x1b[33m%s\x1b[0m", namespace, "-"); | |
}, | |
}); | |
} | |
const logger = createLogger('my-namespace') |
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
/** | |
* Convert a string to an sha256 hash | |
* @param str {string} | |
* @returns {string} | |
*/ | |
async function sha256(str) { | |
const arrayBuffer = new TextEncoder("utf-8").encode(str) | |
const hashAsArrayBuffer = await crypto.subtle.digest('SHA-256', arrayBuffer); | |
const uint8ViewOfHash = new Uint8Array(hashAsArrayBuffer); | |
return Array.from(uint8ViewOfHash).map((b) => b.toString(16).padStart(2, '0')).join(''); |
OlderNewer