chrono-phylo-tree 1.1.8 → 1.1.10

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.
@@ -1,73 +0,0 @@
1
- import { Species } from "../classes/Species";
2
-
3
- export const example = Species.fromJSON({
4
- name: "Hominoidea",
5
- apparition: -25e6,
6
- duration: 6e6,
7
- descendants: [
8
- {
9
- name: "Hilobates",
10
- afterApparition: 6e6,
11
- duration: 19e6,
12
- image: "https://upload.wikimedia.org/wikipedia/commons/4/40/Hylobaes_lar_Canarias.jpg"
13
- },
14
- {
15
- name: "Hominidae",
16
- afterApparition: 6e6,
17
- duration: 6e6,
18
- descendants: [
19
- {
20
- name: "Pongo",
21
- afterApparition: 6e6,
22
- duration: 13e6,
23
- image: "https://upload.wikimedia.org/wikipedia/commons/6/65/Pongo_tapanuliensis.jpg"
24
- },
25
- {
26
- name: "Homininae",
27
- afterApparition: 6e6,
28
- duration: 5e6,
29
- descendants: [
30
- {
31
- name: "Gorilla",
32
- afterApparition: 5e6,
33
- duration: 8e6,
34
- image: "https://gorillas-world.com/wp-content/uploads/anatomia.jpg"
35
- },
36
- {
37
- name: "Hominini",
38
- afterApparition: 5e6,
39
- duration: 2e6,
40
- descendants: [
41
- {
42
- name: "Pan",
43
- afterApparition: 2e6,
44
- duration: 3e6,
45
- descendants: [
46
- {
47
- name: "Pan Troglodytes",
48
- afterApparition: 3e6,
49
- duration: 3e6,
50
- image:"https://encrypted-tbn0.gstatic.com/images?q=tbn%3AANd9GcR-v4-d4R9AUgsHdG42VPYuYj_d4OMRHKasUQ&s"
51
- },
52
- {
53
- name:"Pan Paniscus",
54
- afterApparition : 3e6,
55
- duration : 3e6,
56
- image : "https://upload.wikimedia.org/wikipedia/commons/e/e2/Apeldoorn_Apenheul_zoo_Bonobo.jpg"
57
- }
58
- ],
59
- },
60
- {
61
- name: "Homo",
62
- afterApparition: 2e6,
63
- duration: 6e6,
64
- image: "https://encrypted-tbn0.gstatic.com/images?q=tbn:ANd9GcR7XK_e3HG0jhOticytH1Dn3tzBEZyRyWc5Mg&s"
65
- }
66
- ],
67
- }
68
- ],
69
- }
70
- ]
71
- }
72
- ]
73
- });
@@ -1,12 +0,0 @@
1
- const hexToRGB = (hex: string) => {
2
- hex = hex.replace(/^#/, '');
3
- const r = parseInt(hex.substring(0, 2), 16);
4
- const g = parseInt(hex.substring(2, 4), 16);
5
- const b = parseInt(hex.substring(4, 6), 16);
6
- return { r, g, b };
7
- };
8
-
9
- export const hexToRGBA = (hex: string, a: number) => {
10
- const {r, g, b} = hexToRGB(hex);
11
- return `rgba(${r}, ${g}, ${b}, ${a})`
12
- };
@@ -1,20 +0,0 @@
1
- export const scientificNotation = (n: number, decimals: number = 2) => {
2
- if(n === 0) {
3
- return "0";
4
- }
5
- const abs = Math.abs(n);
6
- const exp = Math.floor(Math.log10(abs));
7
- const mant = n / Math.pow(10, exp);
8
- let mantText = mant.toFixed(decimals);
9
- for(let i = mantText.length - 1; i >= 0; i--) {
10
- if(mantText[i] === "0") {
11
- mantText = mantText.slice(0, i);
12
- } else {
13
- if(mantText[i] === ".") {
14
- mantText = mantText.slice(0, i);
15
- }
16
- break;
17
- }
18
- }
19
- return mantText + ((abs >= 1 && abs < 10) ? "" : ("e" + exp));
20
- };
@@ -1,40 +0,0 @@
1
- import { Species } from "../classes/Species";
2
- import { SpeciesJSON } from "../types";
3
-
4
- const handleFileChange = (file: File | undefined): Promise<SpeciesJSON> => {
5
- return new Promise((resolve, reject) => {
6
- if (file && file.type === 'application/json') {
7
- const reader = new FileReader();
8
- reader.onload = (event) => {
9
- try {
10
- const jsonContent = JSON.parse(event.target?.result as string);
11
- resolve(jsonContent);
12
- } catch (error) {
13
- reject('Error parsing JSON');
14
- }
15
- };
16
- reader.onerror = () => {
17
- reject('Error reading file');
18
- };
19
- reader.readAsText(file);
20
- } else {
21
- reject('Please select a valid JSON file.');
22
- }
23
- });
24
- };
25
-
26
- export const setFromJson = (
27
- setSpecies: (species: Species | undefined) => void,
28
- setScale: (scale: number) => void,
29
- setPresentTime: (time: number) => void,
30
- presentTimeBoolean: boolean
31
- ) => async (file: File | undefined) => {
32
- setSpecies(undefined);
33
- const json = await handleFileChange(file);
34
- const newSpecies = Species.fromJSON(json);
35
- setSpecies(newSpecies);
36
- if(presentTimeBoolean){
37
- setPresentTime(newSpecies.absoluteExtinction());
38
- }
39
- setScale(newSpecies.absoluteDuration());
40
- };
@@ -1,68 +0,0 @@
1
- import Papa from 'papaparse';
2
- import { useEffect, useState } from 'react';
3
-
4
- let data0: any[] = [];
5
-
6
- const fetchCSVData = async (filePath: string): Promise<any[]> => {
7
- const response = await fetch(filePath);
8
- const reader = response.body!.getReader();
9
- const result = await reader.read();
10
- const decoder = new TextDecoder('utf-8');
11
- const CSVString = decoder.decode(result.value!);
12
- const { data } = Papa.parse(CSVString, {
13
- header: true,
14
- dynamicTyping: true,
15
- delimiter: ";",
16
- });
17
- return data;
18
- };
19
-
20
- const provisionalData = (filePath: string = "/translate.csv") => (async (filePath: string = "/translate.csv") => {
21
- data0 = await fetchCSVData(filePath);
22
- })(filePath);
23
-
24
- export const codeText = (code: string, language: string, arg: string[] = [], filePath: string = "/translate.csv") => {
25
- const [data, setData] = useState<any[]>([]);
26
- useEffect(() => {
27
- fetchCSVData(filePath).then(setData);
28
- provisionalData(filePath);
29
- }, [language]);
30
- const row = data.find((row: any) => row.code === code) ?? data0.find((row: any) => row.code === code);
31
- try{
32
- const str = row[language];
33
- const val = arg.reduce((acc, arg, i) => acc.replace(`{${i}}`, arg), str);
34
- return val as string;
35
- } catch {
36
- return;
37
- }
38
- };
39
-
40
- export const codeTextAlt = async (code: string, language: string, arg: string[] = [], filePath: string = "/translate.csv"): Promise<string> => {
41
- const data = await fetchCSVData(filePath);
42
- const row = data.find((row: any) => row.code === code);
43
- try {
44
- const str = row[language];
45
- return arg.reduce((acc, arg, i) => acc.replace(`{${i}}`, arg), str);
46
- } catch {
47
- return "";
48
- }
49
- };
50
-
51
- export const getLanguageOptions = (filePath: string = "/translate.csv") => {
52
- const [languageOptions, setLanguageOptions] = useState<Map<string, string>>(new Map());
53
-
54
- useEffect(() => {
55
- const loadLanguage = async () => {
56
- const data = await fetchCSVData(filePath);
57
- const lan = data.find((row: any) => row.code === "lan");
58
- if (lan) {
59
- delete lan.code;
60
- const lanMap = new Map<string, string>(Object.entries(lan));
61
- setLanguageOptions(lanMap);
62
- }
63
- };
64
-
65
- loadLanguage();
66
- }, []);
67
- return languageOptions;
68
- };
@@ -1,129 +0,0 @@
1
- import { Species } from "../classes/Species";
2
- import { codeTextAlt } from "./translate";
3
-
4
- export const saveSpecies = (
5
- setSpecies: (sp?: Species) => void,
6
- language: string
7
- ) => async (
8
- s: Species,
9
- name: string,
10
- apparition: number,
11
- duration: number,
12
- description: string,
13
- image: string
14
- ) => {
15
- if(duration <= 0){
16
- const alertText = await codeTextAlt("alert01", language, [name])
17
- alert(alert);
18
- throw new Error(alertText);
19
- }
20
- const newSpecies = s.copy();
21
- setSpecies(undefined);
22
- newSpecies.name = name;
23
- newSpecies.apparition = apparition;
24
- newSpecies.duration = duration;
25
- newSpecies.description = description === "" ? undefined : description;
26
- newSpecies.image = image === "" ? undefined : image;
27
- setSpecies(newSpecies.firstAncestor());
28
- };
29
-
30
- export const createDescendant = (
31
- setSpecies: (sp?: Species) => void,
32
- language: string,
33
- presentTimeBoolean: boolean,
34
- setPresentTime: (time: number) => void,
35
- setScale: (scale: number) => void
36
- ) => async (
37
- s: Species,
38
- name: string,
39
- afterApparition: number,
40
- duration: number,
41
- description: string,
42
- image: string
43
- ) => {
44
- if(duration <= 0){
45
- const alertText = await codeTextAlt("alert01", language, [name]);
46
- alert(alertText);
47
- throw new Error(alertText);
48
- }
49
- if(afterApparition < 0 || afterApparition > s.duration) {
50
- const alertText = await codeTextAlt("alert02", language, [name, s.apparition.toString(), s.extinction().toString(), s.name]);
51
- alert(alertText);
52
- throw new Error(alertText);
53
- }
54
- const newSpecies = s.addDescendant(name, afterApparition, duration, description, image, true).firstAncestor();
55
- //*
56
- setSpecies(undefined);
57
- if(presentTimeBoolean){
58
- setPresentTime(newSpecies.absoluteExtinction());
59
- }
60
- setScale(newSpecies.absoluteDuration());
61
- setSpecies(newSpecies);
62
- //*/
63
- };
64
-
65
- export const createAncestor = (
66
- setSpecies: (sp?: Species) => void,
67
- language: string,
68
- presentTimeBoolean: boolean,
69
- setPresentTime: (time: number) => void,
70
- setScale: (scale: number) => void
71
- ) => async (
72
- s: Species,
73
- name: string,
74
- previousApparition: number,
75
- duration: number,
76
- description: string,
77
- image: string
78
- ) => {
79
- if(duration <= 0){
80
- const alertText = await codeTextAlt("alert01", language, [name])
81
- alert(alert);
82
- throw new Error(alertText);
83
- }
84
- if(previousApparition < 0 || duration < previousApparition) {
85
- const alertText = await codeTextAlt("alert02" + (duration < previousApparition) ? "_0" : "", language, [name, s.apparition.toString(), s.name]);
86
- alert(alertText);
87
- throw new Error(alertText);
88
- }
89
- const newSpecies = s.addAncestor(name, previousApparition, duration, description, image, true, true).firstAncestor();
90
- //*
91
- setSpecies(undefined);
92
- if(presentTimeBoolean){
93
- setPresentTime(newSpecies.absoluteExtinction());
94
- }
95
- setScale(newSpecies.absoluteDuration());
96
- setSpecies(newSpecies);
97
- //*/
98
- };
99
-
100
- export const deleteAncestor = (
101
- sp: Species,
102
- setSpecies: (sp?: Species) => void,
103
- setScale: (scale: number) => void,
104
- language: string
105
- ) => async () => {
106
- if(!confirm(await codeTextAlt("cnfrm00" + (sp.ancestor?.ancestor ? "_0" : ""), language, [sp.name]))) {
107
- return;
108
- }
109
- setSpecies(undefined);
110
- const removingAncestor = sp?.copy();
111
- removingAncestor.ancestor = undefined;
112
- setScale(removingAncestor.absoluteDuration());
113
- setSpecies(removingAncestor);
114
- };
115
-
116
- export const deleteSpecies = (
117
- sp: Species,
118
- setSpecies: (sp?: Species) => void,
119
- language: string
120
- ) => async () => {
121
- if(!confirm(await codeTextAlt("cnfrm01" + (sp.descendants.length > 0 ? "_0" : ""), language, [sp.name]))) {
122
- return;
123
- }
124
- setSpecies(undefined);
125
- const removingSpecies = sp?.copy();
126
- const ancestor = removingSpecies?.ancestor;
127
- ancestor?.removeDescendant(removingSpecies);
128
- setSpecies(ancestor?.firstAncestor());
129
- };
package/src/vite-env.d.ts DELETED
@@ -1 +0,0 @@
1
- /// <reference types="vite/client" />