Skip to content

Commit

Permalink
0.17.6-2 (Assistant copied to assets)
Browse files Browse the repository at this point in the history
  • Loading branch information
zsviczian committed Oct 19, 2024
1 parent e6e2a8c commit c065d09
Show file tree
Hide file tree
Showing 7 changed files with 114 additions and 28 deletions.
21 changes: 6 additions & 15 deletions packages/excalidraw/fonts/ExcalidrawFontFace.ts
Original file line number Diff line number Diff line change
Expand Up @@ -107,11 +107,7 @@ export class ExcalidrawFontFace implements IExcalidrawFontFace {
return promiseTry(async () => {
const result = await fetchFontFromVault(url); //zsviczian
if (result) {
if (typeof result === "string") {
url = result;
} else {
return result;
}
return result;
}
const response = await fetch(url, {
headers: {
Expand Down Expand Up @@ -235,7 +231,7 @@ export class ExcalidrawFontFace implements IExcalidrawFontFace {
const errorMessages = [];

while (i < this.urls.length) {
let url = this.urls[i];
const url = this.urls[i];

if (typeof url === "string" && url.startsWith("data:")) {
// it's dataurl, the font is inlined as base64, no need to fetch
Expand All @@ -245,15 +241,10 @@ export class ExcalidrawFontFace implements IExcalidrawFontFace {
try {
const result = await fetchFontFromVault(url); //zsviczian
if(result) {
if(typeof result === "string") {
url = result;
} else {
return `data:font/woff2;base64,${await stringToBase64(
await toByteString(result),
true,
)}`;
}

return `data:font/woff2;base64,${await stringToBase64(
await toByteString(result),
true,
)}`;
}

const response = await fetch(url, {
Expand Down
8 changes: 4 additions & 4 deletions packages/excalidraw/fonts/css/fonts.css
Original file line number Diff line number Diff line change
Expand Up @@ -4,31 +4,31 @@

@font-face {
font-family: "Assistant";
src: url(../woff2/Assistant/Assistant-Regular.woff2) format("woff2");
src: url(https://unpkg.com/@zsviczian/[email protected]/dist/excalidraw-assets/Assistant-Regular.woff2) format("woff2");
font-weight: 400;
style: normal;
display: swap;
}

@font-face {
font-family: "Assistant";
src: url(../woff2/Assistant/Assistant-Medium.woff2) format("woff2");
src: url(https://unpkg.com/@zsviczian/[email protected]/dist/excalidraw-assets/Assistant-Medium.woff2) format("woff2");
font-weight: 500;
style: normal;
display: swap;
}

@font-face {
font-family: "Assistant";
src: url(../woff2/Assistant/Assistant-SemiBold.woff2) format("woff2");
src: url(https://unpkg.com/@zsviczian/[email protected]/dist/excalidraw-assets/Assistant-SemiBold.woff2) format("woff2");
font-weight: 600;
style: normal;
display: swap;
}

@font-face {
font-family: "Assistant";
src: url(../woff2/Assistant/Assistant-Bold.woff2) format("woff2");
src: url(https://unpkg.com/@zsviczian/[email protected]/dist/excalidraw-assets/Assistant-Bold.woff2) format("woff2");
font-weight: 700;
style: normal;
display: swap;
Expand Down
5 changes: 1 addition & 4 deletions packages/excalidraw/obsidianUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -137,16 +137,13 @@ export async function loadSceneFonts(elements: NonDeletedExcalidrawElement[]): P
await Fonts.loadFontFaces(fontFamilies);
}

export async function fetchFontFromVault(url: string | URL): Promise<ArrayBuffer|undefined|string> {
export async function fetchFontFromVault(url: string | URL): Promise<ArrayBuffer|undefined> {
if(typeof url === "string" && !url.startsWith("data") && url.endsWith(".woff2")) {
const filename = decodeURIComponent(url.substring(url.lastIndexOf("/")+1));
const arrayBuffer = hostPlugin.loadFontFromFile(filename)
if(arrayBuffer) {
return arrayBuffer;
}
if (["Assistant-Regular.woff2", "Assistant-Medium.woff2", "Assistant-SemiBold.woff2", "Assistant-Bold.woff2"].includes(filename)) {
return "https://unpkg.com/@zsviczian/[email protected]/dist/excalidraw-assets/" + filename;
}
}
return;
}
5 changes: 3 additions & 2 deletions packages/excalidraw/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@zsviczian/excalidraw",
"version": "0.17.6-1",
"version": "0.17.6-2",
"main": "main.js",
"types": "types/excalidraw/index.d.ts",
"files": [
Expand Down Expand Up @@ -118,7 +118,8 @@
"webpack-bundle-analyzer": "4.5.0",
"webpack-cli": "4.10.0",
"webpack-dev-server": "4.9.3",
"webpack-merge": "5.8.0"
"webpack-merge": "5.8.0",
"copy-webpack-plugin": "12.0.2"
},
"bugs": "https://github.com/excalidraw/excalidraw/issues",
"homepage": "https://github.com/excalidraw/excalidraw/tree/master/packages/excalidraw",
Expand Down
23 changes: 23 additions & 0 deletions packages/excalidraw/webpack.dev.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ const BundleAnalyzerPlugin =
require("webpack-bundle-analyzer").BundleAnalyzerPlugin;
//const outputDir = process.env.EXAMPLE === "true" ? "example/public" : "dist";
const MiniCssExtractPlugin = require("mini-css-extract-plugin"); //zsviczian
const CopyWebpackPlugin = require('copy-webpack-plugin');

module.exports = {
mode: "development",
Expand Down Expand Up @@ -102,6 +103,28 @@ module.exports = {
path.resolve(__dirname, "../../.env.development"),
),
}),
new CopyWebpackPlugin({
patterns: [
{
from: path.resolve(__dirname, 'fonts/woff2/Assistant'), // Path to your font files
to: path.resolve(__dirname, 'dist/excalidraw-assets'), // First output path
globOptions: {
dot: true,
gitignore: true,
ignore: ['*.DS_Store'], // Ignore any unwanted files
},
},
{
from: path.resolve(__dirname, 'fonts/woff2/Assistant'), // Same source path
to: path.resolve(__dirname, 'dist/excalidraw-assets-dev'), // Second output path
globOptions: {
dot: true,
gitignore: true,
ignore: ['*.DS_Store'], // Ignore any unwanted files
},
},
],
}),
],
externals: {
react: {
Expand Down
23 changes: 23 additions & 0 deletions packages/excalidraw/webpack.prod.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ const TerserPlugin = require("terser-webpack-plugin");
const BundleAnalyzerPlugin =
require("webpack-bundle-analyzer").BundleAnalyzerPlugin;
const MiniCssExtractPlugin = require("mini-css-extract-plugin"); //zsviczian
const CopyWebpackPlugin = require('copy-webpack-plugin');

module.exports = {
mode: "production",
Expand Down Expand Up @@ -121,6 +122,28 @@ module.exports = {
path.resolve(__dirname, "../../.env.production"),
),
}),
new CopyWebpackPlugin({
patterns: [
{
from: path.resolve(__dirname, 'fonts/woff2/Assistant'), // Path to your font files
to: path.resolve(__dirname, 'dist/excalidraw-assets'), // First output path
globOptions: {
dot: true,
gitignore: true,
ignore: ['*.DS_Store'], // Ignore any unwanted files
},
},
{
from: path.resolve(__dirname, 'fonts/woff2/Assistant'), // Same source path
to: path.resolve(__dirname, 'dist/excalidraw-assets-dev'), // Second output path
globOptions: {
dot: true,
gitignore: true,
ignore: ['*.DS_Store'], // Ignore any unwanted files
},
},
],
}),
],
externals: {
react: {
Expand Down
57 changes: 54 additions & 3 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -2751,6 +2751,11 @@
resolved "https://registry.yarnpkg.com/@sinclair/typebox/-/typebox-0.27.8.tgz#6667fac16c436b5434a387a34dedb013198f6e6e"
integrity sha512-+Fj43pSMwJs4KRrH/938Uf+uAELIgVBmQzg/q1YG10djyfA3TnrU8N8XzqCh/okZdszqBQTZf96idMfE5lnwTA==

"@sindresorhus/merge-streams@^2.1.0":
version "2.3.0"
resolved "https://registry.yarnpkg.com/@sindresorhus/merge-streams/-/merge-streams-2.3.0.tgz#719df7fb41766bc143369eaa0dd56d8dc87c9958"
integrity sha512-LtoMMhxAlorcGhmFYI+LhPgbPZCkgP6ra1YL604EeF6U98pLlQ3iWIGMdWSC+vWmPBWBNgmDBAhnAobLROJmwg==

"@sitespeed.io/tracium@^0.3.3":
version "0.3.3"
resolved "https://registry.yarnpkg.com/@sitespeed.io/tracium/-/tracium-0.3.3.tgz#b497a4a8d5837db1fd9e3053c99b78f6c0e1f53b"
Expand Down Expand Up @@ -4783,6 +4788,18 @@ [email protected]:
resolved "https://registry.yarnpkg.com/cookie/-/cookie-0.6.0.tgz#2798b04b071b0ecbff0dbb62a505a8efa4e19051"
integrity sha512-U71cyTamuh1CRNCfpGY6to28lxvNwPG4Guz/EVjgf3Jmzv0vlDp1atT9eS5dDjMYHucpHbWns6Lwf3BKz6svdw==

[email protected]:
version "12.0.2"
resolved "https://registry.yarnpkg.com/copy-webpack-plugin/-/copy-webpack-plugin-12.0.2.tgz#935e57b8e6183c82f95bd937df658a59f6a2da28"
integrity sha512-SNwdBeHyII+rWvee/bTnAYyO8vfVdcSTud4EIb6jcZ8inLeWucJE0DnxXQBjlQ5zlteuuvooGQy3LIyGxhvlOA==
dependencies:
fast-glob "^3.3.2"
glob-parent "^6.0.1"
globby "^14.0.0"
normalize-path "^3.0.0"
schema-utils "^4.2.0"
serialize-javascript "^6.0.2"

core-js-compat@^3.31.0, core-js-compat@^3.37.1, core-js-compat@^3.38.0:
version "3.38.1"
resolved "https://registry.yarnpkg.com/core-js-compat/-/core-js-compat-3.38.1.tgz#2bc7a298746ca5a7bcb9c164bcb120f2ebc09a09"
Expand Down Expand Up @@ -6434,6 +6451,13 @@ glob-parent@^5.1.2, glob-parent@~5.1.2:
dependencies:
is-glob "^4.0.1"

glob-parent@^6.0.1:
version "6.0.2"
resolved "https://registry.yarnpkg.com/glob-parent/-/glob-parent-6.0.2.tgz#6d237d99083950c79290f24c7642a3de9a28f9e3"
integrity sha512-XxwI8EOhVQgWp6iDL+3b0r86f4d6AX6zSU55HfB4ydCEuXLXc5FcYeOu+nnGftS4TEju/11rt4KJPTMgbfmv4A==
dependencies:
is-glob "^4.0.3"

glob-to-regexp@^0.4.1:
version "0.4.1"
resolved "https://registry.yarnpkg.com/glob-to-regexp/-/glob-to-regexp-0.4.1.tgz#c75297087c851b9a578bd217dd59a92f59fe546e"
Expand Down Expand Up @@ -6500,6 +6524,18 @@ globby@^11.1.0:
merge2 "^1.4.1"
slash "^3.0.0"

globby@^14.0.0:
version "14.0.2"
resolved "https://registry.yarnpkg.com/globby/-/globby-14.0.2.tgz#06554a54ccfe9264e5a9ff8eded46aa1e306482f"
integrity sha512-s3Fq41ZVh7vbbe2PN3nrW7yC7U7MFVc5c98/iTl9c2GawNMKx/J648KQRW6WKkuU8GIbbh2IXfIRQjOZnXcTnw==
dependencies:
"@sindresorhus/merge-streams" "^2.1.0"
fast-glob "^3.3.2"
ignore "^5.2.4"
path-type "^5.0.0"
slash "^5.1.0"
unicorn-magic "^0.1.0"

glur@^1.1.2:
version "1.1.2"
resolved "https://registry.yarnpkg.com/glur/-/glur-1.1.2.tgz#f20ea36db103bfc292343921f1f91e83c3467689"
Expand Down Expand Up @@ -6797,7 +6833,7 @@ ignore@^4.0.6:
resolved "https://registry.yarnpkg.com/ignore/-/ignore-4.0.6.tgz#750e3db5862087b4737ebac8207ffd1ef27b25fc"
integrity sha512-cyFDKrqc/YdcWFniJhzI42+AzS+gNwmUzOSFcRCQYwySuBBBy/KjuxWLZ/FHEH6Moq1NizMOBWyTcv8O4OZIMg==

ignore@^5.2.0:
ignore@^5.2.0, ignore@^5.2.4:
version "5.3.2"
resolved "https://registry.yarnpkg.com/ignore/-/ignore-5.3.2.tgz#3cd40e729f3643fd87cb04e50bf0eb722bc596f5"
integrity sha512-hsBTNUqQTDwkWtcdYI2i06Y/nUBEsNEDJKjWdigLvegy8kDuJAS8uRlpkkcQpyEXL0Z/pjDy5HBmMjRCJ2gq+g==
Expand Down Expand Up @@ -8318,6 +8354,11 @@ path-type@^4.0.0:
resolved "https://registry.yarnpkg.com/path-type/-/path-type-4.0.0.tgz#84ed01c0a7ba380afe09d90a8c180dcd9d03043b"
integrity sha512-gDKb8aZMDeD/tZWs9P6+q0J9Mwkdl6xMV8TjnGP3qJVJ06bdMgkbBlLU8IdfOsIsFz2BW1rNVT3XuNEl8zPAvw==

path-type@^5.0.0:
version "5.0.0"
resolved "https://registry.yarnpkg.com/path-type/-/path-type-5.0.0.tgz#14b01ed7aea7ddf9c7c3f46181d4d04f9c785bb8"
integrity sha512-5HviZNaZcfqP95rwpv+1HDgUamezbqdSYTyzjTvwtJSnIH+3vnbmWsItli8OFEndS984VT55M3jduxZbX351gg==

pathe@^0.2.0:
version "0.2.0"
resolved "https://registry.yarnpkg.com/pathe/-/pathe-0.2.0.tgz#30fd7bbe0a0d91f0e60bae621f5d19e9e225c339"
Expand Down Expand Up @@ -9196,7 +9237,7 @@ schema-utils@^3.0.0, schema-utils@^3.1.0, schema-utils@^3.1.1, schema-utils@^3.2
ajv "^6.12.5"
ajv-keywords "^3.5.2"

schema-utils@^4.0.0:
schema-utils@^4.0.0, schema-utils@^4.2.0:
version "4.2.0"
resolved "https://registry.yarnpkg.com/schema-utils/-/schema-utils-4.2.0.tgz#70d7c93e153a273a805801882ebd3bff20d89c8b"
integrity sha512-L0jRsrPpjdckP3oPug3/VxNKt2trR8TcabrM6FOAAlvC/9Phcmm+cuAgTlxBqdBR1WJx7Naj9WHw+aOmheSVbw==
Expand Down Expand Up @@ -9260,7 +9301,7 @@ [email protected]:
range-parser "~1.2.1"
statuses "2.0.1"

serialize-javascript@^6.0.0, serialize-javascript@^6.0.1:
serialize-javascript@^6.0.0, serialize-javascript@^6.0.1, serialize-javascript@^6.0.2:
version "6.0.2"
resolved "https://registry.yarnpkg.com/serialize-javascript/-/serialize-javascript-6.0.2.tgz#defa1e055c83bf6d59ea805d8da862254eb6a6c2"
integrity sha512-Saa1xPByTTq2gdeFZYLLo+RFE35NHZkAbqZeWNd3BpzppeVisAqpDjcp8dyf6uIvEqJRd46jemmyA4iFIeVk8g==
Expand Down Expand Up @@ -9401,6 +9442,11 @@ slash@^3.0.0:
resolved "https://registry.yarnpkg.com/slash/-/slash-3.0.0.tgz#6539be870c165adbd5240220dbe361f1bc4d4634"
integrity sha512-g9Q1haeby36OSStwb4ntCGGGaKsaVSjQ68fBxoQcutl5fS1vuY18H3wSt3jFyFtrkx+Kz0V1G85A4MyAdDMi2Q==

slash@^5.1.0:
version "5.1.0"
resolved "https://registry.yarnpkg.com/slash/-/slash-5.1.0.tgz#be3adddcdf09ac38eebe8dcdc7b1a57a75b095ce"
integrity sha512-ZA6oR3T/pEyuqwMgAKT0/hAv8oAXckzbkmR0UkUosQ+Mc4RxGoJkRmwHgHufaenlyAgE1Mxgpdcrf75y6XcnDg==

slice-ansi@^3.0.0:
version "3.0.0"
resolved "https://registry.yarnpkg.com/slice-ansi/-/slice-ansi-3.0.0.tgz#31ddc10930a1b7e0b67b08c96c2f49b77a789787"
Expand Down Expand Up @@ -10175,6 +10221,11 @@ unicode-property-aliases-ecmascript@^2.0.0:
resolved "https://registry.yarnpkg.com/unicode-property-aliases-ecmascript/-/unicode-property-aliases-ecmascript-2.1.0.tgz#43d41e3be698bd493ef911077c9b131f827e8ccd"
integrity sha512-6t3foTQI9qne+OZoVQB/8x8rk2k1eVy1gRXhV3oFQ5T6R1dqQ1xtin3XqSlx3+ATBkliTaR/hHyJBm+LVPNM8w==

unicorn-magic@^0.1.0:
version "0.1.0"
resolved "https://registry.yarnpkg.com/unicorn-magic/-/unicorn-magic-0.1.0.tgz#1bb9a51c823aaf9d73a8bfcd3d1a23dde94b0ce4"
integrity sha512-lRfVq8fE8gz6QMBuDM6a+LO3IAzTi05H6gCVaUpir2E1Rwpo4ZUog45KpNXKC/Mn3Yb9UDuHumeFTo9iV/D9FQ==

union@~0.5.0:
version "0.5.0"
resolved "https://registry.yarnpkg.com/union/-/union-0.5.0.tgz#b2c11be84f60538537b846edb9ba266ba0090075"
Expand Down

0 comments on commit c065d09

Please sign in to comment.