@figtreejs/browser 0.0.1-beta.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.cjs +20 -0
- package/dist/index.cjs.map +1 -0
- package/dist/index.d.ts +22 -0
- package/dist/index.mjs +15320 -0
- package/dist/index.mjs.map +1 -0
- package/package.json +56 -0
- package/src/figtree-options.ts +5 -0
- package/src/figtree-render.ts +51 -0
- package/src/index.ts +15 -0
package/package.json
ADDED
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@figtreejs/browser",
|
|
3
|
+
"version": "0.0.1-beta.0",
|
|
4
|
+
"description": "A standalone library for phylogenetic visualization",
|
|
5
|
+
"repository": {
|
|
6
|
+
"type": "git",
|
|
7
|
+
"url": "https://github.com/figtreo/figtreejs.git"
|
|
8
|
+
},
|
|
9
|
+
"license": "MIT",
|
|
10
|
+
"author": "Andrew Rambaut and JT McCrone",
|
|
11
|
+
"type": "module",
|
|
12
|
+
"exports": {
|
|
13
|
+
".": {
|
|
14
|
+
"types": "./dist/index.d.ts",
|
|
15
|
+
"import": "./dist/index.mjs",
|
|
16
|
+
"require": "./dist/index.cjs"
|
|
17
|
+
}
|
|
18
|
+
},
|
|
19
|
+
"main": "./dist/index.umd.js",
|
|
20
|
+
"module": "./dist/index.mjs",
|
|
21
|
+
"types": "./dist/index.d.ts",
|
|
22
|
+
"files": [
|
|
23
|
+
"./dist/*",
|
|
24
|
+
"./src/*"
|
|
25
|
+
],
|
|
26
|
+
"scripts": {
|
|
27
|
+
"build": "vite build",
|
|
28
|
+
"check-types": "tsc --noEmit ",
|
|
29
|
+
"dev": "vite",
|
|
30
|
+
"lint": "eslint src/"
|
|
31
|
+
},
|
|
32
|
+
"lint-staged": {
|
|
33
|
+
"src/**/*.{js,jsx,ts,tsx}": [
|
|
34
|
+
"eslint",
|
|
35
|
+
"prettier --write --ignore-unknown"
|
|
36
|
+
],
|
|
37
|
+
"!(*.js|*.ts)": [
|
|
38
|
+
"prettier --write --ignore-unknown"
|
|
39
|
+
]
|
|
40
|
+
},
|
|
41
|
+
"dependencies": {
|
|
42
|
+
"@figtreejs/core": "0.0.1-beta.0",
|
|
43
|
+
"react": "^18.3.1",
|
|
44
|
+
"react-dom": "^18.3.1"
|
|
45
|
+
},
|
|
46
|
+
"devDependencies": {
|
|
47
|
+
"@figtreejs/typescript-config": "*",
|
|
48
|
+
"@figtreejs/eslint-config": "*",
|
|
49
|
+
"@types/react-dom": "^19.2.2",
|
|
50
|
+
"@vitejs/plugin-react": "^5.1.0",
|
|
51
|
+
"typescript": "^5.9.3",
|
|
52
|
+
"vite": "^7.2.2",
|
|
53
|
+
"vite-plugin-dts": "^4.5.4",
|
|
54
|
+
"vitest": "^4.0.8"
|
|
55
|
+
}
|
|
56
|
+
}
|
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
import React from "react";
|
|
2
|
+
import { createRoot, type Root } from "react-dom/client";
|
|
3
|
+
|
|
4
|
+
import { FigTree, type FigtreeProps } from "@figtreejs/core";
|
|
5
|
+
import ReactDOMServer from "react-dom/server";
|
|
6
|
+
import type { FigTreeOptions } from "./figtree-options";
|
|
7
|
+
const rootMap = new Map<SVGElement, Root>();
|
|
8
|
+
|
|
9
|
+
//TODO update children to be called Baubles
|
|
10
|
+
export default function figtreeRender(options: FigTreeOptions) {
|
|
11
|
+
const svg = options.svg;
|
|
12
|
+
|
|
13
|
+
const root = rootMap.get(svg);
|
|
14
|
+
if (root !== undefined) {
|
|
15
|
+
root.render(React.createElement(FigTree, options));
|
|
16
|
+
} else {
|
|
17
|
+
const root = createRoot(svg);
|
|
18
|
+
rootMap.set(svg, root);
|
|
19
|
+
root.render(React.createElement(FigTree, options));
|
|
20
|
+
}
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
export function figtreeStatic(options: FigtreeProps) {
|
|
24
|
+
const element = React.createElement(FigTree, options);
|
|
25
|
+
const markup = ReactDOMServer.renderToStaticMarkup(element);
|
|
26
|
+
return `<svg xmlns="http://www.w3.org/2000/svg" width="${options.width}" height="${options.height}">${markup}</svg>`;
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
//TODO set up setters so can use an object style
|
|
30
|
+
|
|
31
|
+
// export function optionalSetGet(key,value){
|
|
32
|
+
// if(value){
|
|
33
|
+
// this[key]=value;
|
|
34
|
+
// this.render();
|
|
35
|
+
// return this;
|
|
36
|
+
// }
|
|
37
|
+
// else{
|
|
38
|
+
// return this[key];
|
|
39
|
+
// }
|
|
40
|
+
// };
|
|
41
|
+
|
|
42
|
+
// export function optionalDeepSetGet(key,innerKey,value){
|
|
43
|
+
// if(value!==null){
|
|
44
|
+
// this[key][innerKey]=value;
|
|
45
|
+
// this.render();
|
|
46
|
+
// return this;
|
|
47
|
+
// }
|
|
48
|
+
// else{
|
|
49
|
+
// return this[key][innerKey];
|
|
50
|
+
// }
|
|
51
|
+
// }
|
package/src/index.ts
ADDED
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
// src/index.ts
|
|
2
|
+
import * as Core from "@figtreejs/core";
|
|
3
|
+
import figtree from "./figtree-render";
|
|
4
|
+
import { figtreeStatic } from "./figtree-render";
|
|
5
|
+
|
|
6
|
+
// named export
|
|
7
|
+
export * from "@figtreejs/core";
|
|
8
|
+
export { figtree, figtreeStatic };
|
|
9
|
+
|
|
10
|
+
// default export as a convenient namespace:
|
|
11
|
+
type FT = typeof Core & {
|
|
12
|
+
figtree: typeof figtree;
|
|
13
|
+
figtreeStatic: typeof figtreeStatic;
|
|
14
|
+
};
|
|
15
|
+
export const ft: FT = { ...Core, figtree, figtreeStatic };
|