Memos is an open-source, self-hosted note-taking app that brings your everyday thoughts together in a personal timeline. Your data stays yours, and you choose what to keep private or share.
Go dockerfossgomarkdownmemomicroblognote-takingnotesopen-sourceown-your-datareactself-hostedsqlitetimeline
choro: convert html2image to arrow function
steven493391bb0386
diff --git a/web/src/labs/html2image/convertResourceToDataURL.ts b/web/src/labs/html2image/convertResourceToDataURL.tsindex cfcbcb750..8611d084c 100644--- a/web/src/labs/html2image/convertResourceToDataURL.ts+++ b/web/src/labs/html2image/convertResourceToDataURL.ts@@ -1,6 +1,6 @@const cachedResourceMap = new Map<string, string>();-function convertResourceToDataURL(url: string, useCache = true): Promise<string> {+const convertResourceToDataURL = (url: string, useCache = true): Promise<string> => {if (useCache && cachedResourceMap.has(url)) {return Promise.resolve(cachedResourceMap.get(url) as string);}@@ -16,6 +16,6 @@ function convertResourceToDataURL(url: string, useCache = true): Promise<string>};reader.readAsDataURL(blob);});-}+};export default convertResourceToDataURL;diff --git a/web/src/labs/html2image/getCloneStyledElement.ts b/web/src/labs/html2image/getCloneStyledElement.tsindex b979ad7f6..c5b6ac8cd 100644--- a/web/src/labs/html2image/getCloneStyledElement.ts+++ b/web/src/labs/html2image/getCloneStyledElement.ts@@ -1,6 +1,6 @@import convertResourceToDataURL from "./convertResourceToDataURL";-async function getCloneStyledElement(element: HTMLElement) {+const getCloneStyledElement = async (element: HTMLElement) => {const clonedElementContainer = document.createElement(element.tagName);clonedElementContainer.innerHTML = element.innerHTML;@@ -32,6 +32,6 @@ async function getCloneStyledElement(element: HTMLElement) {await applyStyles(element, clonedElementContainer);return clonedElementContainer;-}+};export default getCloneStyledElement;diff --git a/web/src/labs/html2image/getFontsStyleElement.ts b/web/src/labs/html2image/getFontsStyleElement.tsindex 1385a8d2b..625d4a191 100644--- a/web/src/labs/html2image/getFontsStyleElement.ts+++ b/web/src/labs/html2image/getFontsStyleElement.ts@@ -1,6 +1,6 @@import convertResourceToDataURL from "./convertResourceToDataURL";-async function getFontsStyleElement(element: HTMLElement) {+const getFontsStyleElement = async (element: HTMLElement) => {const styleSheets = element.ownerDocument.styleSheets;const fontFamilyStyles: CSSStyleDeclaration[] = [];@@ -41,6 +41,6 @@ async function getFontsStyleElement(element: HTMLElement) {}return styleElement;-}+};export default getFontsStyleElement;diff --git a/web/src/labs/html2image/index.ts b/web/src/labs/html2image/index.tsindex f5b8012bd..2f579a764 100644--- a/web/src/labs/html2image/index.ts+++ b/web/src/labs/html2image/index.ts@@ -13,22 +13,22 @@ type Options = Partial<{pixelRatio: number;}>;-function getElementSize(element: HTMLElement) {+const getElementSize = (element: HTMLElement) => {const { width, height } = window.getComputedStyle(element);return {width: parseInt(width.replace("px", "")),height: parseInt(height.replace("px", "")),};-}+};-function convertSVGToDataURL(svg: SVGElement): string {+const convertSVGToDataURL = (svg: SVGElement): string => {const xml = new XMLSerializer().serializeToString(svg);const url = encodeURIComponent(xml);return `data:image/svg+xml;charset=utf-8,${url}`;-}+};-function generateSVGElement(width: number, height: number, element: HTMLElement): SVGSVGElement {+const generateSVGElement = (width: number, height: number, element: HTMLElement): SVGSVGElement => {const xmlNS = "http://www.w3.org/2000/svg";const svgElement = document.createElementNS(xmlNS, "svg");@@ -48,9 +48,9 @@ function generateSVGElement(width: number, height: number, element: HTMLElement)svgElement.appendChild(foreignObject);return svgElement;-}+};-export async function toSVG(element: HTMLElement, options?: Options) {+export const toSVG = async (element: HTMLElement, options?: Options) => {const { width, height } = getElementSize(element);const clonedElement = await getCloneStyledElement(element);@@ -65,9 +65,9 @@ export async function toSVG(element: HTMLElement, options?: Options) {const url = convertSVGToDataURL(svg);return url;-}+};-export async function toCanvas(element: HTMLElement, options?: Options): Promise<HTMLCanvasElement> {+export const toCanvas = async (element: HTMLElement, options?: Options): Promise<HTMLCanvasElement> => {const url = await toSVG(element, options);const imageEl = new Image();@@ -96,12 +96,12 @@ export async function toCanvas(element: HTMLElement, options?: Options): Promiseresolve(canvas);};});-}+};-async function toImage(element: HTMLElement, options?: Options) {+const toImage = async (element: HTMLElement, options?: Options) => {const canvas = await toCanvas(element, options);return canvas.toDataURL();-}+};export default toImage;