2022-11-23 02:42:20 +03:00
|
|
|
import type { Emoji } from 'masto'
|
|
|
|
|
2022-11-23 06:48:01 +03:00
|
|
|
export const UserLinkRE = /^https?:\/\/([^/]+)\/@([^/]+)$/
|
|
|
|
export const TagLinkRE = /^https?:\/\/([^/]+)\/tags\/([^/]+)$/
|
2022-12-21 10:46:36 +03:00
|
|
|
export const HTMLTagRE = /<[^>]+>/g
|
2022-11-23 06:48:01 +03:00
|
|
|
|
2022-11-21 16:21:53 +03:00
|
|
|
export function getDataUrlFromArr(arr: Uint8ClampedArray, w: number, h: number) {
|
|
|
|
if (typeof w === 'undefined' || typeof h === 'undefined')
|
|
|
|
w = h = Math.sqrt(arr.length / 4)
|
|
|
|
|
|
|
|
const canvas = document.createElement('canvas')
|
|
|
|
const ctx = canvas.getContext('2d')!
|
|
|
|
|
|
|
|
canvas.width = w
|
|
|
|
canvas.height = h
|
|
|
|
|
|
|
|
const imgData = ctx.createImageData(w, h)
|
|
|
|
imgData.data.set(arr)
|
|
|
|
ctx.putImageData(imgData, 0, 0)
|
|
|
|
|
|
|
|
return canvas.toDataURL()
|
|
|
|
}
|
2022-11-23 02:42:20 +03:00
|
|
|
|
|
|
|
export function emojisArrayToObject(emojis: Emoji[]) {
|
|
|
|
return Object.fromEntries(emojis.map(i => [i.shortcode, i]))
|
|
|
|
}
|
2022-11-24 06:42:03 +03:00
|
|
|
|
2022-11-30 09:35:12 +03:00
|
|
|
export function noop() {}
|
|
|
|
|
2022-12-02 11:52:00 +03:00
|
|
|
export const useIsMac = () => computed(() =>
|
|
|
|
useRequestHeaders(['user-agent'])['user-agent']?.includes('Macintosh')
|
|
|
|
?? navigator?.platform?.includes('Mac') ?? false)
|
2022-12-21 10:46:36 +03:00
|
|
|
|
2022-12-26 11:50:11 +03:00
|
|
|
export const isEmptyObject = (object: Object) => Object.keys(object).length === 0
|
|
|
|
|
2022-12-21 10:46:36 +03:00
|
|
|
export function removeHTMLTags(str: string) {
|
|
|
|
return str.replaceAll(HTMLTagRE, '')
|
|
|
|
}
|