From 29f6298e2fc0e555edd428c2203b172decc14c23 Mon Sep 17 00:00:00 2001 From: Arik Chakma Date: Thu, 12 Oct 2023 23:39:00 +0600 Subject: [PATCH] Implement utils --- .gitignore | 1 + editor/utils/font.ts | 15 +++++++++++++++ editor/utils/roadmap.ts | 8 ++++++++ scripts/generate-renderer.sh | 14 +++++++------- 4 files changed, 31 insertions(+), 7 deletions(-) create mode 100644 editor/utils/font.ts diff --git a/.gitignore b/.gitignore index f8ef7df50..356d7d17e 100644 --- a/.gitignore +++ b/.gitignore @@ -33,6 +33,7 @@ tests-examples !/editor/utils/ !/editor/readonly-editor.tsx !/editor/utils/roadmap.ts +!/editor/utils/font.ts !/editor/utils/is-mobile.ts /renderer/* !/renderer/index.tsx diff --git a/editor/utils/font.ts b/editor/utils/font.ts new file mode 100644 index 000000000..ac5114e00 --- /dev/null +++ b/editor/utils/font.ts @@ -0,0 +1,15 @@ +type LoadFont = (options: { + fontFamily: string; + fontURL: string; +}) => Promise; + +export const loadFont: LoadFont = async (options) => { + const { fontFamily, fontURL } = options; + + const font = new FontFace(fontFamily!, `url(${fontURL})`); + await font.load(); + + if (document.fonts) { + document?.fonts?.add(font); + } +}; diff --git a/editor/utils/roadmap.ts b/editor/utils/roadmap.ts index 2621608ac..63c52b1ac 100644 --- a/editor/utils/roadmap.ts +++ b/editor/utils/roadmap.ts @@ -4,10 +4,18 @@ export const INITIAL_DESKTOP_ZOOM = 1; export const MINIMUM_DESKTOP_ZOOM = 0.75; export function centerRoadmap(options: any) { + console.warn('centerRoadmap is not implemented'); + console.warn('run the following command to generate the renderer:'); + console.warn('> npm run generate-renderer'); + return; } export function calculateDimensions(options: any) { + console.warn('calculateDimensions is not implemented'); + console.warn('run the following command to generate the renderer:'); + console.warn('> npm run generate-renderer'); + return { x: 0, y: 0, diff --git a/scripts/generate-renderer.sh b/scripts/generate-renderer.sh index ed6561eb5..a18e057ca 100644 --- a/scripts/generate-renderer.sh +++ b/scripts/generate-renderer.sh @@ -8,17 +8,17 @@ if [ ! -d ".temp/web-draw" ]; then git clone git@github.com:roadmapsh/web-draw.git .temp/web-draw fi -rm -rf renderer -mkdir renderer +rm -rf editor +mkdir editor -# copy the files at /src/editor/renderer/* to /renderer +# copy the files at /src/editor/* to /editor # while replacing any existing files -cp -rf .temp/web-draw/src/editor/renderer/* renderer +cp -rf .temp/web-draw/src/editor/* editor # Add @ts-nocheck to the top of each ts and tsx file # so that the typescript compiler doesn't complain # about the missing types -find renderer -type f \( -name "*.ts" -o -name "*.tsx" \) -print0 | while IFS= read -r -d '' file; do +find editor -type f \( -name "*.ts" -o -name "*.tsx" \) -print0 | while IFS= read -r -d '' file; do if [ -f "$file" ]; then echo "// @ts-nocheck" > temp cat "$file" >> temp @@ -29,5 +29,5 @@ done -# ignore the worktree changes for the renderer directory -git update-index --skip-worktree renderer/* +# ignore the worktree changes for the editor directory +git update-index --skip-worktree editor/*