samengine 1.6.4

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.
Files changed (50) hide show
  1. package/README.md +145 -0
  2. package/dist/build/index.d.ts +1 -0
  3. package/dist/build/index.js +2 -0
  4. package/dist/build/version.d.ts +1 -0
  5. package/dist/build/version.js +4 -0
  6. package/dist/core.d.ts +3 -0
  7. package/dist/core.js +13 -0
  8. package/dist/html.d.ts +18 -0
  9. package/dist/html.js +66 -0
  10. package/dist/index.d.ts +10 -0
  11. package/dist/index.js +14 -0
  12. package/dist/input.d.ts +17 -0
  13. package/dist/input.js +111 -0
  14. package/dist/keys.d.ts +52 -0
  15. package/dist/keys.js +55 -0
  16. package/dist/logger.d.ts +1 -0
  17. package/dist/logger.js +16 -0
  18. package/dist/renderer.d.ts +13 -0
  19. package/dist/renderer.js +81 -0
  20. package/dist/save.d.ts +5 -0
  21. package/dist/save.js +27 -0
  22. package/dist/sound/audioplayer.d.ts +17 -0
  23. package/dist/sound/audioplayer.js +84 -0
  24. package/dist/sound/index.d.ts +1 -0
  25. package/dist/sound/index.js +2 -0
  26. package/dist/texture.d.ts +37 -0
  27. package/dist/texture.js +171 -0
  28. package/dist/types/circle.d.ts +14 -0
  29. package/dist/types/circle.js +38 -0
  30. package/dist/types/color.d.ts +9 -0
  31. package/dist/types/color.js +27 -0
  32. package/dist/types/index.d.ts +6 -0
  33. package/dist/types/index.js +13 -0
  34. package/dist/types/rectangle.d.ts +16 -0
  35. package/dist/types/rectangle.js +41 -0
  36. package/dist/types/triangle.d.ts +16 -0
  37. package/dist/types/triangle.js +49 -0
  38. package/dist/types/vector2d.d.ts +14 -0
  39. package/dist/types/vector2d.js +72 -0
  40. package/dist/types/vector3d.d.ts +16 -0
  41. package/dist/types/vector3d.js +86 -0
  42. package/dist/utils/index.d.ts +4 -0
  43. package/dist/utils/index.js +6 -0
  44. package/dist/utils/jsonc-parser.d.ts +4 -0
  45. package/dist/utils/jsonc-parser.js +166 -0
  46. package/dist/utils/markdown.d.ts +41 -0
  47. package/dist/utils/markdown.js +657 -0
  48. package/dist/utils/math.d.ts +3 -0
  49. package/dist/utils/math.js +12 -0
  50. package/package.json +41 -0
@@ -0,0 +1,86 @@
1
+ // 3d Vector
2
+ import { clamp, lerp, map } from "../utils/math.js";
3
+ // Function to create an Object of Type Vector3D
4
+ export function makeVector3d(x, y, z) {
5
+ return {
6
+ x: x,
7
+ y: y,
8
+ z: z
9
+ };
10
+ }
11
+ // Function to add 2 Vectors together
12
+ export function add3d(vector1, vector2) {
13
+ return {
14
+ x: vector1.x + vector2.x,
15
+ y: vector1.y + vector2.y,
16
+ z: vector1.z + vector2.z,
17
+ };
18
+ }
19
+ // Function to subtract 2 Vectors from each other
20
+ export function subtract3d(vector1, vector2) {
21
+ return {
22
+ x: vector1.x - vector2.x,
23
+ y: vector1.y - vector2.y,
24
+ z: vector1.z - vector2.z,
25
+ };
26
+ }
27
+ // Function to get the length from an Vector
28
+ export function length3d(vector) {
29
+ let produkt = vector.x * vector.x + vector.y * vector.y + vector.z * vector.z;
30
+ let root = Math.sqrt(produkt);
31
+ return root;
32
+ }
33
+ // Function to normalize a Vector 2d
34
+ export function normalize3d(vector) {
35
+ // Check if the Vector is zero because then you dont need to
36
+ // calculate sth
37
+ if (vector.x == 0 && vector.y == 0 && vector.z) {
38
+ return vector;
39
+ }
40
+ let root = length3d(vector);
41
+ vector.x = vector.x / root;
42
+ vector.y = vector.y / root;
43
+ vector.z = vector.z / root;
44
+ return vector;
45
+ }
46
+ // Function to make scalar produkt from an Vector
47
+ export function dot3d(v1, v2) {
48
+ return (v1.x * v2.x + v1.y * v2.y + v1.z * v2.z);
49
+ }
50
+ // Function to calculate the cross produkt
51
+ export function crossprodukt3d(v1, v2) {
52
+ return {
53
+ x: (v1.y * v2.z - v1.z * v2.y),
54
+ y: (v1.z * v2.x - v1.x * v2.z),
55
+ z: (v1.x * v2.y - v1.y * v2.x),
56
+ };
57
+ }
58
+ // Calculate the Distance between 2 Vectors
59
+ export function distance3d(v1, v2) {
60
+ let tmp = subtract3d(v1, v2);
61
+ return length3d(tmp);
62
+ }
63
+ // Function to clamp a Vector 3d
64
+ export function clamp3d(vector, min, max) {
65
+ return {
66
+ x: clamp(vector.x, min.x, max.x),
67
+ y: clamp(vector.y, min.y, max.y),
68
+ z: clamp(vector.y, min.y, max.y),
69
+ };
70
+ }
71
+ // Lerp for a 3d Vector
72
+ export function lerp3d(start, end, t) {
73
+ return {
74
+ x: lerp(start.x, end.x, t.x),
75
+ y: lerp(start.y, end.y, t.y),
76
+ z: lerp(start.y, end.y, t.y),
77
+ };
78
+ }
79
+ // Map Function for a 3d Vector
80
+ export function map3d(value, inMin, inMax, outMin, outMax) {
81
+ return {
82
+ x: map(value.x, inMin.x, inMax.x, outMin.x, outMax.x),
83
+ y: map(value.y, inMin.y, inMax.y, outMin.y, outMax.y),
84
+ z: map(value.z, inMin.z, inMax.z, outMin.z, outMax.z),
85
+ };
86
+ }
@@ -0,0 +1,4 @@
1
+ export { clamp, lerp, map } from "./math.js";
2
+ export { parse as parseMarkdown, parseToDocument as parseMarkdownToDocument, exportcss as exportMarkdownCSS } from "./markdown.js";
3
+ export type { JSONValue } from "./jsonc-parser.js";
4
+ export { parseJSONC } from "./jsonc-parser.js";
@@ -0,0 +1,6 @@
1
+ // Utils Package
2
+ // Math Utilities
3
+ export { clamp, lerp, map } from "./math.js";
4
+ // Markdown Parser
5
+ export { parse as parseMarkdown, parseToDocument as parseMarkdownToDocument, exportcss as exportMarkdownCSS } from "./markdown.js";
6
+ export { parseJSONC } from "./jsonc-parser.js";
@@ -0,0 +1,4 @@
1
+ export type JSONValue = string | number | boolean | null | JSONValue[] | {
2
+ [key: string]: JSONValue;
3
+ };
4
+ export declare function parseJSONC(input: string): JSONValue;
@@ -0,0 +1,166 @@
1
+ // jsonc-parser.ts
2
+ // JSON with comments (// and /* */) parser in TypeScript
3
+ export function parseJSONC(input) {
4
+ let i = 0;
5
+ function error(msg) {
6
+ throw new SyntaxError(`${msg} at position ${i}`);
7
+ }
8
+ function peek(offset = 0) {
9
+ return input[i + offset];
10
+ }
11
+ function consume() {
12
+ return input[i++];
13
+ }
14
+ function skipWhitespaceAndComments() {
15
+ while (i < input.length) {
16
+ // whitespace
17
+ if (/\s/.test(peek())) {
18
+ i++;
19
+ continue;
20
+ }
21
+ // line comment //
22
+ if (peek() === '/' && peek(1) === '/') {
23
+ i += 2;
24
+ while (i < input.length && peek() !== '\n')
25
+ i++;
26
+ continue;
27
+ }
28
+ // block comment /* */
29
+ if (peek() === '/' && peek(1) === '*') {
30
+ i += 2;
31
+ while (i < input.length && !(peek() === '*' && peek(1) === '/')) {
32
+ i++;
33
+ }
34
+ if (i >= input.length)
35
+ error("Unterminated block comment");
36
+ i += 2;
37
+ continue;
38
+ }
39
+ break;
40
+ }
41
+ }
42
+ function parseValue() {
43
+ skipWhitespaceAndComments();
44
+ const ch = peek();
45
+ if (ch === '"')
46
+ return parseString();
47
+ if (ch === '{')
48
+ return parseObject();
49
+ if (ch === '[')
50
+ return parseArray();
51
+ if (ch === '-' || /[0-9]/.test(ch))
52
+ return parseNumber();
53
+ if (input.startsWith("true", i)) {
54
+ i += 4;
55
+ return true;
56
+ }
57
+ if (input.startsWith("false", i)) {
58
+ i += 5;
59
+ return false;
60
+ }
61
+ if (input.startsWith("null", i)) {
62
+ i += 4;
63
+ return null;
64
+ }
65
+ error("Unexpected token");
66
+ }
67
+ function parseString() {
68
+ consume(); // "
69
+ let result = "";
70
+ while (i < input.length) {
71
+ const ch = consume();
72
+ if (ch === '"')
73
+ return result;
74
+ if (ch === '\\') {
75
+ const next = consume();
76
+ if (next === 'n')
77
+ result += '\n';
78
+ else if (next === 't')
79
+ result += '\t';
80
+ else if (next === 'r')
81
+ result += '\r';
82
+ else
83
+ result += next;
84
+ }
85
+ else {
86
+ result += ch;
87
+ }
88
+ }
89
+ error("Unterminated string");
90
+ }
91
+ function parseNumber() {
92
+ let num = "";
93
+ while (/[-+0-9.eE]/.test(peek())) {
94
+ num += consume();
95
+ }
96
+ const value = Number(num);
97
+ if (Number.isNaN(value))
98
+ error("Invalid number");
99
+ return value;
100
+ }
101
+ function parseArray() {
102
+ consume(); // [
103
+ const arr = [];
104
+ skipWhitespaceAndComments();
105
+ if (peek() === ']') {
106
+ consume();
107
+ return arr;
108
+ }
109
+ while (true) {
110
+ arr.push(parseValue());
111
+ skipWhitespaceAndComments();
112
+ const ch = consume();
113
+ if (ch === ']')
114
+ break;
115
+ if (ch !== ',')
116
+ error("Expected ',' or ']'");
117
+ skipWhitespaceAndComments();
118
+ if (peek() === ']') {
119
+ consume();
120
+ break;
121
+ }
122
+ }
123
+ return arr;
124
+ }
125
+ function parseObject() {
126
+ consume(); // {
127
+ const obj = {};
128
+ skipWhitespaceAndComments();
129
+ if (peek() === '}') {
130
+ consume();
131
+ return obj;
132
+ }
133
+ while (true) {
134
+ skipWhitespaceAndComments();
135
+ const key = parseKey();
136
+ skipWhitespaceAndComments();
137
+ if (consume() !== ':')
138
+ error("Expected ':'");
139
+ const value = parseValue();
140
+ obj[key] = value;
141
+ skipWhitespaceAndComments();
142
+ const ch = consume();
143
+ if (ch === '}')
144
+ break;
145
+ if (ch !== ',')
146
+ error("Expected ',' or '}'");
147
+ skipWhitespaceAndComments();
148
+ if (peek() === '}') {
149
+ consume();
150
+ break;
151
+ }
152
+ }
153
+ return obj;
154
+ }
155
+ function parseKey() {
156
+ skipWhitespaceAndComments();
157
+ if (peek() === '"')
158
+ return parseString();
159
+ error("Keys must be strings in JSONC");
160
+ }
161
+ const result = parseValue();
162
+ skipWhitespaceAndComments();
163
+ if (i < input.length)
164
+ error("Unexpected trailing input");
165
+ return result;
166
+ }
@@ -0,0 +1,41 @@
1
+ /**
2
+ * markdown-parser.ts
3
+ * Ein vollständiger Markdown → HTML Parser in TypeScript.
4
+ * Unterstützt: Überschriften, Absätze, Fett/Kursiv/Durchgestrichen,
5
+ * Inline-Code, Code-Blöcke (mit Sprach-Tag), Blockquotes (verschachtelt),
6
+ * geordnete & ungeordnete Listen (verschachtelt), Aufgabenlisten,
7
+ * horizontale Linien, Links, Bilder, Tabellen, Fußnoten, HTML-Entities.
8
+ */
9
+ interface ParseOptions {
10
+ /** Fügt target="_blank" rel="noopener noreferrer" zu externen Links hinzu */
11
+ externalLinks?: boolean;
12
+ /** Bricht einfache Zeilenumbrüche in <br> um */
13
+ breaks?: boolean;
14
+ /** Gibt typographische Anführungszeichen zurück (Smartquotes) */
15
+ smartypants?: boolean;
16
+ /** Sanitisiert rohes HTML im Quelltext */
17
+ sanitize?: boolean;
18
+ }
19
+ /**
20
+ * Konvertiert Markdown-Text in HTML.
21
+ *
22
+ * @param markdown Eingabe-Markdown
23
+ * @param options Optionale Parser-Einstellungen
24
+ * @returns Gerendertes HTML
25
+ *
26
+ * @example
27
+ * ```ts
28
+ * import { parse } from "./markdown-parser";
29
+ * const html = parse("# Hallo Welt\n\nDas ist **Markdown**.");
30
+ * ```
31
+ */
32
+ export declare function parse(markdown: string, options?: ParseOptions): string;
33
+ /**
34
+ * Gibt ein vollständiges HTML-Dokument zurück (optional mit eigenem CSS).
35
+ */
36
+ export declare function parseToDocument(markdown: string, options?: ParseOptions & {
37
+ title?: string;
38
+ css?: string;
39
+ }): string;
40
+ export declare function exportcss(): string;
41
+ export {};