@rgsoft/lsystem 1.0.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/LICENSE +21 -0
- package/README.md +73 -0
- package/dist/index.cjs +97 -0
- package/dist/index.cjs.map +1 -0
- package/dist/index.d.cts +22 -0
- package/dist/index.d.ts +22 -0
- package/dist/index.mjs +69 -0
- package/dist/index.mjs.map +1 -0
- package/package.json +41 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2024 Ricardo Miranda
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
ADDED
|
@@ -0,0 +1,73 @@
|
|
|
1
|
+
# Turtle
|
|
2
|
+
|
|
3
|
+
Turtle and L-Systems library
|
|
4
|
+
|
|
5
|
+
## L-Systems
|
|
6
|
+
|
|
7
|
+
The `LSystem` class is an implementation of the
|
|
8
|
+
[Lindenmayer systems](https://en.wikipedia.org/wiki/L-system) based on an
|
|
9
|
+
alphabet of symbols and production rules.
|
|
10
|
+
|
|
11
|
+
```js
|
|
12
|
+
const lsystem = new LSystem(axiom, rules);
|
|
13
|
+
```
|
|
14
|
+
|
|
15
|
+
The `axiom` is the base sentence from which future sentences will be generated
|
|
16
|
+
or inferred, and must be composed only by symbols of a defined alphabet.
|
|
17
|
+
|
|
18
|
+
The `rules` is an instance of `Map`, where each entry defines a
|
|
19
|
+
**production rule** for spawning the next generation sentence.
|
|
20
|
+
|
|
21
|
+
### Generation
|
|
22
|
+
|
|
23
|
+
The `generate` method in the `LSystem` class spawns new generations of the
|
|
24
|
+
current sentence.
|
|
25
|
+
|
|
26
|
+
```js
|
|
27
|
+
const axiom = 'F';
|
|
28
|
+
const rules = new Map([
|
|
29
|
+
['F', ['F', '[', '+', 'F', ']', '[', '-', 'G', ']']]
|
|
30
|
+
]);
|
|
31
|
+
const lsystem = new LSystem(axiom, rules);
|
|
32
|
+
console.log(lsystem.sentence); // F
|
|
33
|
+
lsystem.generate();
|
|
34
|
+
console.log(lsystem.sentence); // F[+F][-G]
|
|
35
|
+
```
|
|
36
|
+
|
|
37
|
+
This method also admits a number argument that indicates the number of
|
|
38
|
+
generations to generate.
|
|
39
|
+
|
|
40
|
+
```js
|
|
41
|
+
const axiom = 'F';
|
|
42
|
+
const rules = new Map([
|
|
43
|
+
['F', ['F', 'G']]
|
|
44
|
+
]);
|
|
45
|
+
const lsystem = new LSystem(axiom, rules);
|
|
46
|
+
console.log(lsystem.sentence); // F
|
|
47
|
+
lsystem.generate(4);
|
|
48
|
+
console.log(lsystem.sentence); // FGGGG
|
|
49
|
+
```
|
|
50
|
+
|
|
51
|
+
### Rules
|
|
52
|
+
|
|
53
|
+
Each entry in the rules map representa a production rule that allows the
|
|
54
|
+
generation from a symbol to an array of one or more symbols from the alphabet.
|
|
55
|
+
The `parseRules` is a util function receives an array of strings in the format
|
|
56
|
+
`Symbol=>Symbol+`, and returns a Map with the inferred entries.
|
|
57
|
+
|
|
58
|
+
```js
|
|
59
|
+
const str = 'F => FG';
|
|
60
|
+
const rules = parseRules[ str ];
|
|
61
|
+
console.log(rules.get('F')); // ['F', 'G']
|
|
62
|
+
const definitions = ['F : FFFFGH'];
|
|
63
|
+
parseRules(definitions); // Throws "Invalid rule: F : FFFFGH"
|
|
64
|
+
```
|
|
65
|
+
|
|
66
|
+
Alternatively, it accepts a second parameter `alphabet`, that specifies the
|
|
67
|
+
list of valid symbols.
|
|
68
|
+
|
|
69
|
+
```js
|
|
70
|
+
const definitions = ['F => FFFFGH'];
|
|
71
|
+
const alphabet = ['F', 'G'];
|
|
72
|
+
parseRules(definitions, alphabet) // Throws 'Unknown symbol "H" in rule: F => FFFFGH'
|
|
73
|
+
```
|
package/dist/index.cjs
ADDED
|
@@ -0,0 +1,97 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __defProp = Object.defineProperty;
|
|
3
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
|
+
var __export = (target, all) => {
|
|
7
|
+
for (var name in all)
|
|
8
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
9
|
+
};
|
|
10
|
+
var __copyProps = (to, from, except, desc) => {
|
|
11
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
12
|
+
for (let key of __getOwnPropNames(from))
|
|
13
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
14
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
15
|
+
}
|
|
16
|
+
return to;
|
|
17
|
+
};
|
|
18
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
19
|
+
|
|
20
|
+
// src/index.ts
|
|
21
|
+
var index_exports = {};
|
|
22
|
+
__export(index_exports, {
|
|
23
|
+
LSystem: () => LSystem,
|
|
24
|
+
parseRules: () => parseRules
|
|
25
|
+
});
|
|
26
|
+
module.exports = __toCommonJS(index_exports);
|
|
27
|
+
|
|
28
|
+
// src/lsystem.ts
|
|
29
|
+
var LSystem = class {
|
|
30
|
+
constructor(_axiom, _rules) {
|
|
31
|
+
this._axiom = _axiom;
|
|
32
|
+
this._rules = _rules;
|
|
33
|
+
this._generation = 0;
|
|
34
|
+
this._sentence = [..._axiom];
|
|
35
|
+
}
|
|
36
|
+
/**
|
|
37
|
+
*
|
|
38
|
+
* @param { number } n Number of generations to generate
|
|
39
|
+
* @returns { string } The generated sentence
|
|
40
|
+
*/
|
|
41
|
+
generate(n = 1) {
|
|
42
|
+
let sentence = [...this._sentence];
|
|
43
|
+
for (let i = 0; i < n; i++) {
|
|
44
|
+
sentence = sentence.flatMap((s) => this._rules.get(s) ?? [s]);
|
|
45
|
+
this._generation++;
|
|
46
|
+
}
|
|
47
|
+
this._sentence = sentence;
|
|
48
|
+
return this._sentence.join("");
|
|
49
|
+
}
|
|
50
|
+
get sentence() {
|
|
51
|
+
return this._sentence.join("");
|
|
52
|
+
}
|
|
53
|
+
get generation() {
|
|
54
|
+
return this._generation;
|
|
55
|
+
}
|
|
56
|
+
get axiom() {
|
|
57
|
+
return [...this._axiom];
|
|
58
|
+
}
|
|
59
|
+
get rules() {
|
|
60
|
+
return this._rules;
|
|
61
|
+
}
|
|
62
|
+
reset() {
|
|
63
|
+
this._sentence = [...this._axiom];
|
|
64
|
+
this._generation = 0;
|
|
65
|
+
}
|
|
66
|
+
};
|
|
67
|
+
|
|
68
|
+
// src/utils.ts
|
|
69
|
+
function parseRules(definitions, alphabet) {
|
|
70
|
+
const map = /* @__PURE__ */ new Map();
|
|
71
|
+
for (const def of definitions) {
|
|
72
|
+
const [left, right] = def.replace(/\s+/g, "").split("=>");
|
|
73
|
+
if (!left || !right) {
|
|
74
|
+
throw new Error(`Invalid rule: ${def}`);
|
|
75
|
+
}
|
|
76
|
+
const lhs = left;
|
|
77
|
+
const rhs = right.split("");
|
|
78
|
+
if (alphabet) {
|
|
79
|
+
if (!alphabet.includes(lhs)) {
|
|
80
|
+
throw new Error(`Unknown symbol "${lhs}" in rule: ${def}`);
|
|
81
|
+
}
|
|
82
|
+
for (const s of rhs) {
|
|
83
|
+
if (!alphabet.includes(s)) {
|
|
84
|
+
throw new Error(`Unknown symbol "${s}" in rule: ${def}`);
|
|
85
|
+
}
|
|
86
|
+
}
|
|
87
|
+
}
|
|
88
|
+
map.set(lhs, rhs);
|
|
89
|
+
}
|
|
90
|
+
return map;
|
|
91
|
+
}
|
|
92
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
93
|
+
0 && (module.exports = {
|
|
94
|
+
LSystem,
|
|
95
|
+
parseRules
|
|
96
|
+
});
|
|
97
|
+
//# sourceMappingURL=index.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/index.ts","../src/lsystem.ts","../src/utils.ts"],"sourcesContent":["export { LSystem } from './lsystem';\r\nexport { parseRules } from './utils';\r\n","export class LSystem<Symbol extends string = string> {\r\n private _sentence: Symbol[];\r\n private _generation: number = 0;\r\n\r\n constructor(\r\n private readonly _axiom: Symbol[],\r\n private readonly _rules: Map<Symbol, Symbol[]>\r\n ) {\r\n this._sentence = [..._axiom];\r\n }\r\n\r\n /**\r\n *\r\n * @param { number } n Number of generations to generate\r\n * @returns { string } The generated sentence\r\n */\r\n generate(n: number = 1): string {\r\n let sentence = [...this._sentence];\r\n for (let i = 0; i < n; i++) {\r\n sentence = sentence.flatMap((s) => this._rules.get(s) ?? [s]);\r\n this._generation++;\r\n }\r\n this._sentence = sentence;\r\n return this._sentence.join(\"\");\r\n }\r\n\r\n get sentence(): string {\r\n return this._sentence.join(\"\");\r\n }\r\n\r\n get generation(): number {\r\n return this._generation;\r\n }\r\n\r\n get axiom(): Symbol[] {\r\n return [...this._axiom];\r\n }\r\n\r\n get rules(): Map<Symbol, Symbol[]> {\r\n return this._rules;\r\n }\r\n\r\n reset(): void {\r\n this._sentence = [...this._axiom];\r\n this._generation = 0;\r\n }\r\n}\r\n","export function parseRules<Symbol extends string>(\r\n definitions: string[],\r\n alphabet?: readonly Symbol[]\r\n): Map<Symbol, Symbol[]> {\r\n const map = new Map<Symbol, Symbol[]>();\r\n\r\n for (const def of definitions) {\r\n const [left, right] = def.replace(/\\s+/g, \"\").split(\"=>\");\r\n if (!left || !right) {\r\n throw new Error(`Invalid rule: ${def}`);\r\n }\r\n\r\n const lhs = left as Symbol;\r\n const rhs = right.split(\"\") as Symbol[];\r\n\r\n if (alphabet) {\r\n if (!alphabet.includes(lhs)) {\r\n throw new Error(`Unknown symbol \"${lhs}\" in rule: ${def}`);\r\n }\r\n for (const s of rhs) {\r\n if (!alphabet.includes(s)) {\r\n throw new Error(`Unknown symbol \"${s}\" in rule: ${def}`);\r\n }\r\n }\r\n }\r\n\r\n map.set(lhs, rhs);\r\n }\r\n\r\n return map;\r\n}\r\n"],"mappings":";;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;;;ACAO,IAAM,UAAN,MAA8C;AAAA,EAInD,YACmB,QACA,QACjB;AAFiB;AACA;AAJnB,SAAQ,cAAsB;AAM5B,SAAK,YAAY,CAAC,GAAG,MAAM;AAAA,EAC7B;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAOA,SAAS,IAAY,GAAW;AAC9B,QAAI,WAAW,CAAC,GAAG,KAAK,SAAS;AACjC,aAAS,IAAI,GAAG,IAAI,GAAG,KAAK;AAC1B,iBAAW,SAAS,QAAQ,CAAC,MAAM,KAAK,OAAO,IAAI,CAAC,KAAK,CAAC,CAAC,CAAC;AAC5D,WAAK;AAAA,IACP;AACA,SAAK,YAAY;AACjB,WAAO,KAAK,UAAU,KAAK,EAAE;AAAA,EAC/B;AAAA,EAEA,IAAI,WAAmB;AACrB,WAAO,KAAK,UAAU,KAAK,EAAE;AAAA,EAC/B;AAAA,EAEA,IAAI,aAAqB;AACvB,WAAO,KAAK;AAAA,EACd;AAAA,EAEA,IAAI,QAAkB;AACpB,WAAO,CAAC,GAAG,KAAK,MAAM;AAAA,EACxB;AAAA,EAEA,IAAI,QAA+B;AACjC,WAAO,KAAK;AAAA,EACd;AAAA,EAEA,QAAc;AACZ,SAAK,YAAY,CAAC,GAAG,KAAK,MAAM;AAChC,SAAK,cAAc;AAAA,EACrB;AACF;;;AC9CO,SAAS,WACd,aACA,UACuB;AACvB,QAAM,MAAM,oBAAI,IAAsB;AAEtC,aAAW,OAAO,aAAa;AAC7B,UAAM,CAAC,MAAM,KAAK,IAAI,IAAI,QAAQ,QAAQ,EAAE,EAAE,MAAM,IAAI;AACxD,QAAI,CAAC,QAAQ,CAAC,OAAO;AACnB,YAAM,IAAI,MAAM,iBAAiB,GAAG,EAAE;AAAA,IACxC;AAEA,UAAM,MAAM;AACZ,UAAM,MAAM,MAAM,MAAM,EAAE;AAE1B,QAAI,UAAU;AACZ,UAAI,CAAC,SAAS,SAAS,GAAG,GAAG;AAC3B,cAAM,IAAI,MAAM,mBAAmB,GAAG,cAAc,GAAG,EAAE;AAAA,MAC3D;AACA,iBAAW,KAAK,KAAK;AACnB,YAAI,CAAC,SAAS,SAAS,CAAC,GAAG;AACzB,gBAAM,IAAI,MAAM,mBAAmB,CAAC,cAAc,GAAG,EAAE;AAAA,QACzD;AAAA,MACF;AAAA,IACF;AAEA,QAAI,IAAI,KAAK,GAAG;AAAA,EAClB;AAEA,SAAO;AACT;","names":[]}
|
package/dist/index.d.cts
ADDED
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
declare class LSystem<Symbol extends string = string> {
|
|
2
|
+
private readonly _axiom;
|
|
3
|
+
private readonly _rules;
|
|
4
|
+
private _sentence;
|
|
5
|
+
private _generation;
|
|
6
|
+
constructor(_axiom: Symbol[], _rules: Map<Symbol, Symbol[]>);
|
|
7
|
+
/**
|
|
8
|
+
*
|
|
9
|
+
* @param { number } n Number of generations to generate
|
|
10
|
+
* @returns { string } The generated sentence
|
|
11
|
+
*/
|
|
12
|
+
generate(n?: number): string;
|
|
13
|
+
get sentence(): string;
|
|
14
|
+
get generation(): number;
|
|
15
|
+
get axiom(): Symbol[];
|
|
16
|
+
get rules(): Map<Symbol, Symbol[]>;
|
|
17
|
+
reset(): void;
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
declare function parseRules<Symbol extends string>(definitions: string[], alphabet?: readonly Symbol[]): Map<Symbol, Symbol[]>;
|
|
21
|
+
|
|
22
|
+
export { LSystem, parseRules };
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
declare class LSystem<Symbol extends string = string> {
|
|
2
|
+
private readonly _axiom;
|
|
3
|
+
private readonly _rules;
|
|
4
|
+
private _sentence;
|
|
5
|
+
private _generation;
|
|
6
|
+
constructor(_axiom: Symbol[], _rules: Map<Symbol, Symbol[]>);
|
|
7
|
+
/**
|
|
8
|
+
*
|
|
9
|
+
* @param { number } n Number of generations to generate
|
|
10
|
+
* @returns { string } The generated sentence
|
|
11
|
+
*/
|
|
12
|
+
generate(n?: number): string;
|
|
13
|
+
get sentence(): string;
|
|
14
|
+
get generation(): number;
|
|
15
|
+
get axiom(): Symbol[];
|
|
16
|
+
get rules(): Map<Symbol, Symbol[]>;
|
|
17
|
+
reset(): void;
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
declare function parseRules<Symbol extends string>(definitions: string[], alphabet?: readonly Symbol[]): Map<Symbol, Symbol[]>;
|
|
21
|
+
|
|
22
|
+
export { LSystem, parseRules };
|
package/dist/index.mjs
ADDED
|
@@ -0,0 +1,69 @@
|
|
|
1
|
+
// src/lsystem.ts
|
|
2
|
+
var LSystem = class {
|
|
3
|
+
constructor(_axiom, _rules) {
|
|
4
|
+
this._axiom = _axiom;
|
|
5
|
+
this._rules = _rules;
|
|
6
|
+
this._generation = 0;
|
|
7
|
+
this._sentence = [..._axiom];
|
|
8
|
+
}
|
|
9
|
+
/**
|
|
10
|
+
*
|
|
11
|
+
* @param { number } n Number of generations to generate
|
|
12
|
+
* @returns { string } The generated sentence
|
|
13
|
+
*/
|
|
14
|
+
generate(n = 1) {
|
|
15
|
+
let sentence = [...this._sentence];
|
|
16
|
+
for (let i = 0; i < n; i++) {
|
|
17
|
+
sentence = sentence.flatMap((s) => this._rules.get(s) ?? [s]);
|
|
18
|
+
this._generation++;
|
|
19
|
+
}
|
|
20
|
+
this._sentence = sentence;
|
|
21
|
+
return this._sentence.join("");
|
|
22
|
+
}
|
|
23
|
+
get sentence() {
|
|
24
|
+
return this._sentence.join("");
|
|
25
|
+
}
|
|
26
|
+
get generation() {
|
|
27
|
+
return this._generation;
|
|
28
|
+
}
|
|
29
|
+
get axiom() {
|
|
30
|
+
return [...this._axiom];
|
|
31
|
+
}
|
|
32
|
+
get rules() {
|
|
33
|
+
return this._rules;
|
|
34
|
+
}
|
|
35
|
+
reset() {
|
|
36
|
+
this._sentence = [...this._axiom];
|
|
37
|
+
this._generation = 0;
|
|
38
|
+
}
|
|
39
|
+
};
|
|
40
|
+
|
|
41
|
+
// src/utils.ts
|
|
42
|
+
function parseRules(definitions, alphabet) {
|
|
43
|
+
const map = /* @__PURE__ */ new Map();
|
|
44
|
+
for (const def of definitions) {
|
|
45
|
+
const [left, right] = def.replace(/\s+/g, "").split("=>");
|
|
46
|
+
if (!left || !right) {
|
|
47
|
+
throw new Error(`Invalid rule: ${def}`);
|
|
48
|
+
}
|
|
49
|
+
const lhs = left;
|
|
50
|
+
const rhs = right.split("");
|
|
51
|
+
if (alphabet) {
|
|
52
|
+
if (!alphabet.includes(lhs)) {
|
|
53
|
+
throw new Error(`Unknown symbol "${lhs}" in rule: ${def}`);
|
|
54
|
+
}
|
|
55
|
+
for (const s of rhs) {
|
|
56
|
+
if (!alphabet.includes(s)) {
|
|
57
|
+
throw new Error(`Unknown symbol "${s}" in rule: ${def}`);
|
|
58
|
+
}
|
|
59
|
+
}
|
|
60
|
+
}
|
|
61
|
+
map.set(lhs, rhs);
|
|
62
|
+
}
|
|
63
|
+
return map;
|
|
64
|
+
}
|
|
65
|
+
export {
|
|
66
|
+
LSystem,
|
|
67
|
+
parseRules
|
|
68
|
+
};
|
|
69
|
+
//# sourceMappingURL=index.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/lsystem.ts","../src/utils.ts"],"sourcesContent":["export class LSystem<Symbol extends string = string> {\r\n private _sentence: Symbol[];\r\n private _generation: number = 0;\r\n\r\n constructor(\r\n private readonly _axiom: Symbol[],\r\n private readonly _rules: Map<Symbol, Symbol[]>\r\n ) {\r\n this._sentence = [..._axiom];\r\n }\r\n\r\n /**\r\n *\r\n * @param { number } n Number of generations to generate\r\n * @returns { string } The generated sentence\r\n */\r\n generate(n: number = 1): string {\r\n let sentence = [...this._sentence];\r\n for (let i = 0; i < n; i++) {\r\n sentence = sentence.flatMap((s) => this._rules.get(s) ?? [s]);\r\n this._generation++;\r\n }\r\n this._sentence = sentence;\r\n return this._sentence.join(\"\");\r\n }\r\n\r\n get sentence(): string {\r\n return this._sentence.join(\"\");\r\n }\r\n\r\n get generation(): number {\r\n return this._generation;\r\n }\r\n\r\n get axiom(): Symbol[] {\r\n return [...this._axiom];\r\n }\r\n\r\n get rules(): Map<Symbol, Symbol[]> {\r\n return this._rules;\r\n }\r\n\r\n reset(): void {\r\n this._sentence = [...this._axiom];\r\n this._generation = 0;\r\n }\r\n}\r\n","export function parseRules<Symbol extends string>(\r\n definitions: string[],\r\n alphabet?: readonly Symbol[]\r\n): Map<Symbol, Symbol[]> {\r\n const map = new Map<Symbol, Symbol[]>();\r\n\r\n for (const def of definitions) {\r\n const [left, right] = def.replace(/\\s+/g, \"\").split(\"=>\");\r\n if (!left || !right) {\r\n throw new Error(`Invalid rule: ${def}`);\r\n }\r\n\r\n const lhs = left as Symbol;\r\n const rhs = right.split(\"\") as Symbol[];\r\n\r\n if (alphabet) {\r\n if (!alphabet.includes(lhs)) {\r\n throw new Error(`Unknown symbol \"${lhs}\" in rule: ${def}`);\r\n }\r\n for (const s of rhs) {\r\n if (!alphabet.includes(s)) {\r\n throw new Error(`Unknown symbol \"${s}\" in rule: ${def}`);\r\n }\r\n }\r\n }\r\n\r\n map.set(lhs, rhs);\r\n }\r\n\r\n return map;\r\n}\r\n"],"mappings":";AAAO,IAAM,UAAN,MAA8C;AAAA,EAInD,YACmB,QACA,QACjB;AAFiB;AACA;AAJnB,SAAQ,cAAsB;AAM5B,SAAK,YAAY,CAAC,GAAG,MAAM;AAAA,EAC7B;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAOA,SAAS,IAAY,GAAW;AAC9B,QAAI,WAAW,CAAC,GAAG,KAAK,SAAS;AACjC,aAAS,IAAI,GAAG,IAAI,GAAG,KAAK;AAC1B,iBAAW,SAAS,QAAQ,CAAC,MAAM,KAAK,OAAO,IAAI,CAAC,KAAK,CAAC,CAAC,CAAC;AAC5D,WAAK;AAAA,IACP;AACA,SAAK,YAAY;AACjB,WAAO,KAAK,UAAU,KAAK,EAAE;AAAA,EAC/B;AAAA,EAEA,IAAI,WAAmB;AACrB,WAAO,KAAK,UAAU,KAAK,EAAE;AAAA,EAC/B;AAAA,EAEA,IAAI,aAAqB;AACvB,WAAO,KAAK;AAAA,EACd;AAAA,EAEA,IAAI,QAAkB;AACpB,WAAO,CAAC,GAAG,KAAK,MAAM;AAAA,EACxB;AAAA,EAEA,IAAI,QAA+B;AACjC,WAAO,KAAK;AAAA,EACd;AAAA,EAEA,QAAc;AACZ,SAAK,YAAY,CAAC,GAAG,KAAK,MAAM;AAChC,SAAK,cAAc;AAAA,EACrB;AACF;;;AC9CO,SAAS,WACd,aACA,UACuB;AACvB,QAAM,MAAM,oBAAI,IAAsB;AAEtC,aAAW,OAAO,aAAa;AAC7B,UAAM,CAAC,MAAM,KAAK,IAAI,IAAI,QAAQ,QAAQ,EAAE,EAAE,MAAM,IAAI;AACxD,QAAI,CAAC,QAAQ,CAAC,OAAO;AACnB,YAAM,IAAI,MAAM,iBAAiB,GAAG,EAAE;AAAA,IACxC;AAEA,UAAM,MAAM;AACZ,UAAM,MAAM,MAAM,MAAM,EAAE;AAE1B,QAAI,UAAU;AACZ,UAAI,CAAC,SAAS,SAAS,GAAG,GAAG;AAC3B,cAAM,IAAI,MAAM,mBAAmB,GAAG,cAAc,GAAG,EAAE;AAAA,MAC3D;AACA,iBAAW,KAAK,KAAK;AACnB,YAAI,CAAC,SAAS,SAAS,CAAC,GAAG;AACzB,gBAAM,IAAI,MAAM,mBAAmB,CAAC,cAAc,GAAG,EAAE;AAAA,QACzD;AAAA,MACF;AAAA,IACF;AAEA,QAAI,IAAI,KAAK,GAAG;AAAA,EAClB;AAEA,SAAO;AACT;","names":[]}
|
package/package.json
ADDED
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@rgsoft/lsystem",
|
|
3
|
+
"version": "1.0.0",
|
|
4
|
+
"description": "L-Systems library",
|
|
5
|
+
"main": "./dist/index.js",
|
|
6
|
+
"module": "./dist/index.mjs",
|
|
7
|
+
"types": "./dist/index.d.ts",
|
|
8
|
+
"files": [
|
|
9
|
+
"dist"
|
|
10
|
+
],
|
|
11
|
+
"exports": {
|
|
12
|
+
".": {
|
|
13
|
+
"types": "./dist/index.d.ts",
|
|
14
|
+
"import": "./dist/index.mjs",
|
|
15
|
+
"require": "./dist/index.cjs"
|
|
16
|
+
}
|
|
17
|
+
},
|
|
18
|
+
"repository": {
|
|
19
|
+
"type": "git",
|
|
20
|
+
"url": "git+https://github.com/rgmiranda/turtle.git"
|
|
21
|
+
},
|
|
22
|
+
"keywords": [
|
|
23
|
+
"l-systems"
|
|
24
|
+
],
|
|
25
|
+
"author": "Ricardo Miranda <rgmiranda@live.com.ar>",
|
|
26
|
+
"license": "MIT",
|
|
27
|
+
"bugs": {
|
|
28
|
+
"url": "https://github.com/rgmiranda/turtle/issues"
|
|
29
|
+
},
|
|
30
|
+
"homepage": "https://github.com/rgmiranda/turtle#readme",
|
|
31
|
+
"publishConfig": {
|
|
32
|
+
"access": "public"
|
|
33
|
+
},
|
|
34
|
+
"type": "module",
|
|
35
|
+
"sideEffects": false,
|
|
36
|
+
"scripts": {
|
|
37
|
+
"test": "vitest",
|
|
38
|
+
"coverage": "vitest run --coverage",
|
|
39
|
+
"build": "tsup"
|
|
40
|
+
}
|
|
41
|
+
}
|