mirror of
https://github.com/mermaid-js/mermaid.git
synced 2025-08-15 06:19:24 +02:00
fix: json import, js-base64
Co-authored-by: Alois Klink <alois@aloisklink.com>
This commit is contained in:
@@ -2,18 +2,15 @@ import { build, InlineConfig } from 'vite';
|
|||||||
import { resolve } from 'path';
|
import { resolve } from 'path';
|
||||||
import { fileURLToPath } from 'url';
|
import { fileURLToPath } from 'url';
|
||||||
import jisonPlugin from './jisonPlugin.js';
|
import jisonPlugin from './jisonPlugin.js';
|
||||||
import { readFileSync } from 'node:fs';
|
import pkg from '../package.json' assert { type: 'json' };
|
||||||
|
|
||||||
type OutputOptions = Exclude<
|
type OutputOptions = Exclude<
|
||||||
Exclude<InlineConfig['build'], undefined>['rollupOptions'],
|
Exclude<InlineConfig['build'], undefined>['rollupOptions'],
|
||||||
undefined
|
undefined
|
||||||
>['output'];
|
>['output'];
|
||||||
|
|
||||||
const __dirname = fileURLToPath(new URL('.', import.meta.url));
|
const { dependencies } = pkg;
|
||||||
const { dependencies } = JSON.parse(
|
|
||||||
readFileSync(resolve(__dirname, '../package.json'), { encoding: 'utf8' })
|
|
||||||
);
|
|
||||||
const watch = process.argv.includes('--watch');
|
const watch = process.argv.includes('--watch');
|
||||||
|
const __dirname = fileURLToPath(new URL('.', import.meta.url));
|
||||||
|
|
||||||
interface BuildOptions {
|
interface BuildOptions {
|
||||||
minify: boolean | 'esbuild';
|
minify: boolean | 'esbuild';
|
||||||
@@ -23,7 +20,7 @@ interface BuildOptions {
|
|||||||
|
|
||||||
export const getBuildConfig = ({ minify, core, watch }: BuildOptions): InlineConfig => {
|
export const getBuildConfig = ({ minify, core, watch }: BuildOptions): InlineConfig => {
|
||||||
const external = ['require', 'fs', 'path'];
|
const external = ['require', 'fs', 'path'];
|
||||||
let output: OutputOptions = [
|
let output: OutputOptions | OutputOptions[] = [
|
||||||
{
|
{
|
||||||
name: 'mermaid',
|
name: 'mermaid',
|
||||||
format: 'esm',
|
format: 'esm',
|
||||||
|
6
.vite/tsconfig.json
Normal file
6
.vite/tsconfig.json
Normal file
@@ -0,0 +1,6 @@
|
|||||||
|
{
|
||||||
|
"extends": "../tsconfig.json",
|
||||||
|
"compilerOptions": {
|
||||||
|
"module": "ES2022"
|
||||||
|
}
|
||||||
|
}
|
@@ -1,4 +1,6 @@
|
|||||||
import { Base64 } from 'js-base64';
|
const utf8ToB64 = (str) => {
|
||||||
|
return window.btoa(unescape(encodeURIComponent(str)));
|
||||||
|
};
|
||||||
|
|
||||||
export const mermaidUrl = (graphStr, options, api) => {
|
export const mermaidUrl = (graphStr, options, api) => {
|
||||||
const obj = {
|
const obj = {
|
||||||
@@ -6,7 +8,7 @@ export const mermaidUrl = (graphStr, options, api) => {
|
|||||||
mermaid: options,
|
mermaid: options,
|
||||||
};
|
};
|
||||||
const objStr = JSON.stringify(obj);
|
const objStr = JSON.stringify(obj);
|
||||||
let url = 'http://localhost:9000/e2e.html?graph=' + Base64.encodeURI(objStr);
|
let url = 'http://localhost:9000/e2e.html?graph=' + utf8ToB64(objStr);
|
||||||
if (api) {
|
if (api) {
|
||||||
url = 'http://localhost:9000/xss.html?graph=' + graphStr;
|
url = 'http://localhost:9000/xss.html?graph=' + graphStr;
|
||||||
}
|
}
|
||||||
|
@@ -1,6 +1,9 @@
|
|||||||
import { Base64 } from '../../node_modules/js-base64';
|
|
||||||
import mermaid2 from '../../src/mermaid';
|
import mermaid2 from '../../src/mermaid';
|
||||||
|
|
||||||
|
function b64ToUtf8(str) {
|
||||||
|
return decodeURIComponent(escape(window.atob(str)));
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* ##contentLoaded Callback function that is called when page is loaded. This functions fetches
|
* ##contentLoaded Callback function that is called when page is loaded. This functions fetches
|
||||||
* configuration for mermaid rendering and calls init for rendering the mermaid diagrams on the
|
* configuration for mermaid rendering and calls init for rendering the mermaid diagrams on the
|
||||||
@@ -11,7 +14,7 @@ const contentLoaded = function () {
|
|||||||
if (pos > 0) {
|
if (pos > 0) {
|
||||||
pos = pos + 7;
|
pos = pos + 7;
|
||||||
const graphBase64 = document.location.href.substr(pos);
|
const graphBase64 = document.location.href.substr(pos);
|
||||||
const graphObj = JSON.parse(Base64.decode(graphBase64));
|
const graphObj = JSON.parse(b64ToUtf8(graphBase64));
|
||||||
if (graphObj.mermaid && graphObj.mermaid.theme === 'dark') {
|
if (graphObj.mermaid && graphObj.mermaid.theme === 'dark') {
|
||||||
document.body.style.background = '#3f3f3f';
|
document.body.style.background = '#3f3f3f';
|
||||||
}
|
}
|
||||||
@@ -67,7 +70,7 @@ const contentLoadedApi = function () {
|
|||||||
if (pos > 0) {
|
if (pos > 0) {
|
||||||
pos = pos + 7;
|
pos = pos + 7;
|
||||||
const graphBase64 = document.location.href.substr(pos);
|
const graphBase64 = document.location.href.substr(pos);
|
||||||
const graphObj = JSON.parse(Base64.decode(graphBase64));
|
const graphObj = JSON.parse(window.btoa(graphBase64));
|
||||||
// const graph = 'hello'
|
// const graph = 'hello'
|
||||||
if (Array.isArray(graphObj.code)) {
|
if (Array.isArray(graphObj.code)) {
|
||||||
const numCodes = graphObj.code.length;
|
const numCodes = graphObj.code.length;
|
||||||
|
@@ -25,18 +25,18 @@
|
|||||||
],
|
],
|
||||||
"scripts": {
|
"scripts": {
|
||||||
"clean": "rimraf dist",
|
"clean": "rimraf dist",
|
||||||
"build:vite": "ts-node-esm .vite/build.ts",
|
"build:vite": "ts-node-esm --transpileOnly --project=.vite/tsconfig.json .vite/build.ts",
|
||||||
"build:types": "tsc -p ./tsconfig.json --emitDeclarationOnly",
|
"build:types": "tsc -p ./tsconfig.json --emitDeclarationOnly",
|
||||||
"build:watch": "yarn build:code --watch",
|
"build:watch": "yarn build:code --watch",
|
||||||
"build": "yarn clean; concurrently \"yarn build:vite\" \"yarn build:types\"",
|
"build": "yarn clean; concurrently \"yarn build:vite\" \"yarn build:types\"",
|
||||||
"dev": "concurrently \"yarn build:vite --watch\" \"ts-node-esm .vite/server\"",
|
"dev": "concurrently \"yarn build:vite --watch\" \"ts-node-esm .vite/server\"",
|
||||||
"docs:build": "ts-node-esm src/docs.mts",
|
"docs:build": "ts-node-esm --transpileOnly src/docs.mts",
|
||||||
"docs:verify": "yarn docs:build --verify",
|
"docs:verify": "yarn docs:build --verify",
|
||||||
"postbuild": "documentation build src/mermaidAPI.ts src/config.ts src/defaultConfig.ts --shallow -f md --markdown-toc false > src/docs/Setup.md && prettier --write src/docs/Setup.md",
|
"postbuild": "documentation build src/mermaidAPI.ts src/config.ts src/defaultConfig.ts --shallow -f md --markdown-toc false > src/docs/Setup.md && prettier --write src/docs/Setup.md",
|
||||||
"release": "yarn build",
|
"release": "yarn build",
|
||||||
"lint": "eslint --cache --ignore-path .gitignore . && yarn lint:jison && prettier --check .",
|
"lint": "eslint --cache --ignore-path .gitignore . && yarn lint:jison && prettier --check .",
|
||||||
"lint:fix": "eslint --fix --ignore-path .gitignore . && prettier --write .",
|
"lint:fix": "eslint --fix --ignore-path .gitignore . && prettier --write .",
|
||||||
"lint:jison": "ts-node-esm src/jison/lint.mts",
|
"lint:jison": "ts-node-esm --transpileOnly src/jison/lint.mts",
|
||||||
"cypress": "cypress run",
|
"cypress": "cypress run",
|
||||||
"cypress:open": "cypress open",
|
"cypress:open": "cypress open",
|
||||||
"e2e": "start-server-and-test dev http://localhost:9000/ cypress",
|
"e2e": "start-server-and-test dev http://localhost:9000/ cypress",
|
||||||
@@ -98,7 +98,6 @@
|
|||||||
"cypress": "^10.0.0",
|
"cypress": "^10.0.0",
|
||||||
"cypress-image-snapshot": "^4.0.1",
|
"cypress-image-snapshot": "^4.0.1",
|
||||||
"documentation": "13.2.0",
|
"documentation": "13.2.0",
|
||||||
"esbuild": "^0.15.8",
|
|
||||||
"eslint": "^8.23.1",
|
"eslint": "^8.23.1",
|
||||||
"eslint-config-prettier": "^8.5.0",
|
"eslint-config-prettier": "^8.5.0",
|
||||||
"eslint-plugin-cypress": "^2.12.1",
|
"eslint-plugin-cypress": "^2.12.1",
|
||||||
@@ -112,7 +111,6 @@
|
|||||||
"husky": "^8.0.0",
|
"husky": "^8.0.0",
|
||||||
"identity-obj-proxy": "^3.0.0",
|
"identity-obj-proxy": "^3.0.0",
|
||||||
"jison": "^0.4.18",
|
"jison": "^0.4.18",
|
||||||
"js-base64": "3.7.2",
|
|
||||||
"jsdom": "^20.0.0",
|
"jsdom": "^20.0.0",
|
||||||
"lint-staged": "^13.0.0",
|
"lint-staged": "^13.0.0",
|
||||||
"moment": "^2.23.0",
|
"moment": "^2.23.0",
|
||||||
|
@@ -4601,7 +4601,7 @@ esbuild-windows-arm64@0.15.8:
|
|||||||
resolved "https://registry.yarnpkg.com/esbuild-windows-arm64/-/esbuild-windows-arm64-0.15.8.tgz#1d75235290bf23a111e6c0b03febd324af115cb1"
|
resolved "https://registry.yarnpkg.com/esbuild-windows-arm64/-/esbuild-windows-arm64-0.15.8.tgz#1d75235290bf23a111e6c0b03febd324af115cb1"
|
||||||
integrity sha512-dbpAb0VyPaUs9mgw65KRfQ9rqiWCHpNzrJusoPu+LpEoswosjt/tFxN7cd2l68AT4qWdBkzAjDLRon7uqMeWcg==
|
integrity sha512-dbpAb0VyPaUs9mgw65KRfQ9rqiWCHpNzrJusoPu+LpEoswosjt/tFxN7cd2l68AT4qWdBkzAjDLRon7uqMeWcg==
|
||||||
|
|
||||||
esbuild@^0.15.6, esbuild@^0.15.8:
|
esbuild@^0.15.6:
|
||||||
version "0.15.8"
|
version "0.15.8"
|
||||||
resolved "https://registry.yarnpkg.com/esbuild/-/esbuild-0.15.8.tgz#75daa25d03f6dd9cc9355030eba2b93555b42cd4"
|
resolved "https://registry.yarnpkg.com/esbuild/-/esbuild-0.15.8.tgz#75daa25d03f6dd9cc9355030eba2b93555b42cd4"
|
||||||
integrity sha512-Remsk2dmr1Ia65sU+QasE6svJbsHe62lzR+CnjpUvbZ+uSYo1SitiOWPRfZQkCu82YWZBBKXiD/j0i//XWMZ+Q==
|
integrity sha512-Remsk2dmr1Ia65sU+QasE6svJbsHe62lzR+CnjpUvbZ+uSYo1SitiOWPRfZQkCu82YWZBBKXiD/j0i//XWMZ+Q==
|
||||||
@@ -6448,11 +6448,6 @@ jpeg-js@0.4.4:
|
|||||||
resolved "https://registry.yarnpkg.com/jpeg-js/-/jpeg-js-0.4.4.tgz#a9f1c6f1f9f0fa80cdb3484ed9635054d28936aa"
|
resolved "https://registry.yarnpkg.com/jpeg-js/-/jpeg-js-0.4.4.tgz#a9f1c6f1f9f0fa80cdb3484ed9635054d28936aa"
|
||||||
integrity sha512-WZzeDOEtTOBK4Mdsar0IqEU5sMr3vSV2RqkAIzUEV2BHnUfKGyswWFPFwK5EeDo93K3FohSHbLAjj0s1Wzd+dg==
|
integrity sha512-WZzeDOEtTOBK4Mdsar0IqEU5sMr3vSV2RqkAIzUEV2BHnUfKGyswWFPFwK5EeDo93K3FohSHbLAjj0s1Wzd+dg==
|
||||||
|
|
||||||
js-base64@3.7.2:
|
|
||||||
version "3.7.2"
|
|
||||||
resolved "https://registry.yarnpkg.com/js-base64/-/js-base64-3.7.2.tgz#816d11d81a8aff241603d19ce5761e13e41d7745"
|
|
||||||
integrity sha512-NnRs6dsyqUXejqk/yv2aiXlAvOs56sLkX6nUdeaNezI5LFFLlsZjOThmwnrcwh5ZZRwZlCMnVAY3CvhIhoVEKQ==
|
|
||||||
|
|
||||||
js-sdsl@^4.1.4:
|
js-sdsl@^4.1.4:
|
||||||
version "4.1.4"
|
version "4.1.4"
|
||||||
resolved "https://registry.yarnpkg.com/js-sdsl/-/js-sdsl-4.1.4.tgz#78793c90f80e8430b7d8dc94515b6c77d98a26a6"
|
resolved "https://registry.yarnpkg.com/js-sdsl/-/js-sdsl-4.1.4.tgz#78793c90f80e8430b7d8dc94515b6c77d98a26a6"
|
||||||
|
Reference in New Issue
Block a user