2023-01-08 07:21:09 +01:00
|
|
|
import type { mastodon } from 'masto'
|
2022-11-23 00:42:20 +01:00
|
|
|
|
2023-04-23 21:40:55 +02:00
|
|
|
export const UserLinkRE = /^(?:https:\/)?\/([^/]+)\/@([^/]+)$/
|
2022-11-23 04:48:01 +01:00
|
|
|
export const TagLinkRE = /^https?:\/\/([^/]+)\/tags\/([^/]+)$/
|
2022-12-21 08:46:36 +01:00
|
|
|
export const HTMLTagRE = /<[^>]+>/g
|
2022-11-23 04:48:01 +01:00
|
|
|
|
2022-11-21 14:21:53 +01: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 00:42:20 +01:00
|
|
|
|
2023-01-08 07:21:09 +01:00
|
|
|
export function emojisArrayToObject(emojis: mastodon.v1.CustomEmoji[]) {
|
2022-11-23 00:42:20 +01:00
|
|
|
return Object.fromEntries(emojis.map(i => [i.shortcode, i]))
|
|
|
|
}
|
2022-11-24 04:42:03 +01:00
|
|
|
|
2022-11-30 07:35:12 +01:00
|
|
|
export function noop() {}
|
|
|
|
|
2023-03-30 21:01:24 +02:00
|
|
|
export function useIsMac() {
|
2023-02-12 12:48:52 +01:00
|
|
|
const headers = useRequestHeaders(['user-agent'])
|
|
|
|
return computed(() => headers['user-agent']?.includes('Macintosh')
|
2022-12-02 09:52:00 +01:00
|
|
|
?? navigator?.platform?.includes('Mac') ?? false)
|
2023-02-12 12:48:52 +01:00
|
|
|
}
|
2022-12-21 08:46:36 +01:00
|
|
|
|
2023-03-30 21:01:24 +02:00
|
|
|
export function isEmptyObject(object: Object) {
|
|
|
|
return Object.keys(object).length === 0
|
|
|
|
}
|
2022-12-26 09:50:11 +01:00
|
|
|
|
2022-12-21 08:46:36 +01:00
|
|
|
export function removeHTMLTags(str: string) {
|
|
|
|
return str.replaceAll(HTMLTagRE, '')
|
|
|
|
}
|