gmljs 2.0.5 → 3.0.0-beta-20260118

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 (80) hide show
  1. package/.claude/settings.local.json +18 -0
  2. package/dist/gml/index.d.ts +34 -0
  3. package/dist/gml/index.js +190 -0
  4. package/dist/gml/map.d.ts +4 -0
  5. package/dist/gml/map.js +79 -0
  6. package/dist/gml/nodes/brush/index.d.ts +6 -0
  7. package/dist/gml/nodes/brush/index.js +23 -0
  8. package/dist/gml/nodes/brush/settings.d.ts +35 -0
  9. package/dist/gml/nodes/brush/settings.js +45 -0
  10. package/dist/gml/nodes/client/index.d.ts +7 -0
  11. package/dist/gml/nodes/client/index.js +25 -0
  12. package/dist/gml/nodes/client/settings.d.ts +48 -0
  13. package/dist/gml/nodes/client/settings.js +74 -0
  14. package/dist/gml/nodes/document/index.d.ts +7 -0
  15. package/dist/gml/nodes/document/index.js +14 -0
  16. package/dist/gml/nodes/drawing/index.d.ts +9 -0
  17. package/dist/gml/nodes/drawing/index.js +17 -0
  18. package/dist/gml/nodes/environment/index.d.ts +10 -0
  19. package/dist/gml/nodes/environment/index.js +38 -0
  20. package/dist/gml/nodes/environment/settings.d.ts +30 -0
  21. package/dist/gml/nodes/environment/settings.js +39 -0
  22. package/dist/gml/nodes/header/index.d.ts +6 -0
  23. package/dist/gml/nodes/header/index.js +11 -0
  24. package/dist/gml/nodes/leaf/float.d.ts +6 -0
  25. package/dist/gml/nodes/leaf/float.js +15 -0
  26. package/dist/gml/nodes/leaf/index.d.ts +4 -0
  27. package/dist/gml/nodes/leaf/index.js +6 -0
  28. package/dist/gml/nodes/leaf/integer.d.ts +6 -0
  29. package/dist/gml/nodes/leaf/integer.js +15 -0
  30. package/dist/gml/nodes/leaf/parent.d.ts +7 -0
  31. package/dist/gml/nodes/leaf/parent.js +38 -0
  32. package/dist/gml/nodes/point/color.d.ts +19 -0
  33. package/dist/gml/nodes/point/color.js +30 -0
  34. package/dist/gml/nodes/point/direction.d.ts +6 -0
  35. package/dist/gml/nodes/point/direction.js +15 -0
  36. package/dist/gml/nodes/point/index.d.ts +10 -0
  37. package/dist/gml/nodes/point/index.js +61 -0
  38. package/dist/gml/nodes/point/points.d.ts +27 -0
  39. package/dist/gml/nodes/point/points.js +28 -0
  40. package/dist/gml/nodes/root/index.d.ts +9 -0
  41. package/dist/gml/nodes/root/index.js +17 -0
  42. package/dist/gml/nodes/stroke/curved.d.ts +6 -0
  43. package/dist/gml/nodes/stroke/curved.js +11 -0
  44. package/dist/gml/nodes/stroke/index.d.ts +10 -0
  45. package/dist/gml/nodes/stroke/index.js +26 -0
  46. package/dist/gml/nodes/stroke/info.d.ts +6 -0
  47. package/dist/gml/nodes/stroke/info.js +11 -0
  48. package/dist/gml/nodes/tag/index.d.ts +12 -0
  49. package/dist/gml/nodes/tag/index.js +34 -0
  50. package/dist/gml/types.d.ts +126 -0
  51. package/dist/gml/types.js +61 -0
  52. package/dist/gml/util/definition.d.ts +2 -0
  53. package/dist/gml/util/definition.js +6 -0
  54. package/dist/gml/util/index.d.ts +21 -0
  55. package/dist/gml/util/index.js +59 -0
  56. package/dist/index.d.ts +27 -0
  57. package/dist/index.js +83 -0
  58. package/dist/util/assert.d.ts +5 -0
  59. package/dist/util/assert.js +22 -0
  60. package/dist/util/xml.d.ts +20 -0
  61. package/dist/util/xml.js +43 -0
  62. package/package.json +16 -36
  63. package/tsconfig.json +31 -0
  64. package/lib/index.js +0 -164
  65. package/lib/node/brush.js +0 -246
  66. package/lib/node/client.js +0 -224
  67. package/lib/node/color.js +0 -118
  68. package/lib/node/document.js +0 -55
  69. package/lib/node/drawing.js +0 -55
  70. package/lib/node/environment.js +0 -218
  71. package/lib/node/header.js +0 -54
  72. package/lib/node/leafnode.js +0 -179
  73. package/lib/node/location.js +0 -86
  74. package/lib/node/node.js +0 -259
  75. package/lib/node/point.js +0 -253
  76. package/lib/node/root.js +0 -60
  77. package/lib/node/stroke.js +0 -128
  78. package/lib/node/tag.js +0 -77
  79. package/lib/util/assert.js +0 -39
  80. package/lib/util/xml.js +0 -37
@@ -0,0 +1,18 @@
1
+ {
2
+ "permissions": {
3
+ "allow": [
4
+ "Bash(npm test:*)",
5
+ "Bash(grep:*)",
6
+ "Bash(npm run build:*)",
7
+ "Bash(node --import tsx --test 'src/__test__/preview.test.ts')",
8
+ "Bash(node --import tsx -e:*)",
9
+ "Bash(npm ls:*)",
10
+ "Bash(node --import tsx --test --test-update-snapshots 'src/__test__/preview.test.ts')",
11
+ "Bash(git checkout:*)",
12
+ "Bash(xxd:*)",
13
+ "Bash(node --version)",
14
+ "Bash(node --test:*)",
15
+ "Bash(node --import tsx --test --test-update-snapshots 'src/**/*.test.ts')"
16
+ ]
17
+ }
18
+ }
@@ -0,0 +1,34 @@
1
+ import { GMLAttributeDefinition, GMLChildNodeDefinition, GMLNodeAttribute, GMLNodeAttributes, GMLNodeAttributeValue, GMLNodeChildPath, GMLNodeChildren, GMLNodeDefinition, GMLNodeInterface, GMLNodeName, GMLNodeValue, GMLObjectRepresentation, GMLParsedNode } from "./types";
2
+ export declare abstract class GMLNode implements GMLNodeInterface {
3
+ definition: GMLNodeDefinition;
4
+ attributes: GMLNodeAttributes;
5
+ children: GMLNodeChildren;
6
+ value: GMLNodeValue;
7
+ constructor(definition: GMLNodeDefinition, data?: GMLParsedNode);
8
+ init(data?: GMLParsedNode): void;
9
+ verifyAttributes(): void;
10
+ verifyChildren(): void;
11
+ setAttribute(key: GMLNodeAttribute, value: GMLNodeAttributeValue): void;
12
+ getAttribute(key: GMLNodeAttribute): GMLNodeAttributeValue | undefined;
13
+ addChild(name: GMLNodeName, child: GMLNode): void;
14
+ removeChild(name: GMLNodeName, index?: number): void;
15
+ hasChild(name: GMLNodeName): boolean;
16
+ hasChildren(): boolean;
17
+ getChild<T extends GMLNodeInterface>(child: GMLNodeChildPath): T | undefined;
18
+ getChildren<T extends GMLNodeInterface>(name: GMLNodeName): T[] | undefined;
19
+ getChildPath<T extends GMLNodeInterface>(path: GMLNodeChildPath[]): T | undefined;
20
+ getChildValue(path: GMLNodeChildPath[]): GMLNodeValue | undefined;
21
+ getChildValueString(path: GMLNodeChildPath[]): string;
22
+ getValue(): GMLNodeValue;
23
+ setValue(value: GMLNodeValue): void;
24
+ parseValue(data: GMLParsedNode): void;
25
+ parseAttributes(data: GMLParsedNode): void;
26
+ parseChildNodes(data: GMLParsedNode): void;
27
+ getChildNodeDefinition(name: GMLNodeName): GMLChildNodeDefinition | undefined;
28
+ getAttributeDefinition(name: GMLNodeAttribute): GMLAttributeDefinition | undefined;
29
+ getTagStart(): string;
30
+ getTagEnd(): string;
31
+ getTagContent(): string;
32
+ toString(): string;
33
+ toObject(): GMLObjectRepresentation;
34
+ }
@@ -0,0 +1,190 @@
1
+ import { formatXmlTagStart, formatXmlTagEnd } from "../util/xml";
2
+ import { getGMLNodeDefinition } from "./map";
3
+ import { createGMLChildNodeDefinition, createGmlNode, isGMLChildNodeDefinition, isGMLNodeAttribute, isGMLNodeName, } from "./util";
4
+ export class GMLNode {
5
+ definition;
6
+ attributes = {};
7
+ children = {};
8
+ value = "";
9
+ constructor(definition, data) {
10
+ this.definition = definition;
11
+ this.init(data);
12
+ this.verifyAttributes();
13
+ this.verifyChildren();
14
+ }
15
+ init(data) {
16
+ // Apply attribute defaults first
17
+ this.definition.attributes.forEach((item) => {
18
+ if (item.defaultValue !== undefined) {
19
+ this.setAttribute(item.name, item.defaultValue);
20
+ }
21
+ });
22
+ if (data) {
23
+ this.parseValue(data);
24
+ this.parseAttributes(data);
25
+ this.parseChildNodes(data);
26
+ }
27
+ else {
28
+ this.definition.children.forEach((item) => {
29
+ if (typeof item === "object" && item.initDefault) {
30
+ this.addChild(item.name, createGmlNode(getGMLNodeDefinition(item.name)));
31
+ }
32
+ });
33
+ }
34
+ }
35
+ verifyAttributes() {
36
+ // Check for required attributes
37
+ this.definition.attributes.forEach(({ name, required }) => {
38
+ if (required && this.getAttribute(name) === undefined) {
39
+ throw new Error(`Invalid GML: A "${this.definition.name}" node requires a "${name}" attribute.`);
40
+ }
41
+ });
42
+ }
43
+ verifyChildren() {
44
+ // Check for required children
45
+ this.definition.children
46
+ .filter(isGMLChildNodeDefinition)
47
+ .forEach(({ name, required }) => {
48
+ if (required && !this.hasChild(name)) {
49
+ throw new Error(`Invalid GML: A "${this.definition.name}" node requires a "${name}" child node.`);
50
+ }
51
+ });
52
+ }
53
+ setAttribute(key, value) {
54
+ this.attributes[key] = value;
55
+ }
56
+ getAttribute(key) {
57
+ return this.attributes[key];
58
+ }
59
+ addChild(name, child) {
60
+ if (!Array.isArray(this.children[name])) {
61
+ this.children[name] = [];
62
+ }
63
+ this.children[name]?.push(child);
64
+ }
65
+ removeChild(name, index) {
66
+ if (index) {
67
+ this.children[name]?.splice(index, 1);
68
+ if (!this.children[name]?.length) {
69
+ delete this.children[name];
70
+ }
71
+ }
72
+ else {
73
+ delete this.children[name];
74
+ }
75
+ }
76
+ hasChild(name) {
77
+ return Array.isArray(this.children[name]) && this.children[name].length > 0;
78
+ }
79
+ hasChildren() {
80
+ return Object.keys(this.children).length > 0;
81
+ }
82
+ getChild(child) {
83
+ let name;
84
+ let index = 0;
85
+ if (Array.isArray(child)) {
86
+ [name, index] = child;
87
+ }
88
+ else if (typeof child === "string") {
89
+ name = child;
90
+ }
91
+ else {
92
+ return undefined;
93
+ }
94
+ return this.getChildren(name)?.[index];
95
+ }
96
+ getChildren(name) {
97
+ return this.children[name];
98
+ }
99
+ getChildPath(path) {
100
+ if (!Array.isArray(path) || !path.length) {
101
+ return undefined;
102
+ }
103
+ const node = this.getChild(path[0]);
104
+ return path.length > 1 ? node?.getChildPath(path.slice(1)) : node;
105
+ }
106
+ getChildValue(path) {
107
+ const node = this.getChildPath(path);
108
+ return node?.value;
109
+ }
110
+ getChildValueString(path) {
111
+ const node = this.getChildPath(path);
112
+ return String(node?.value ?? "");
113
+ }
114
+ getValue() {
115
+ return this.value;
116
+ }
117
+ setValue(value) {
118
+ this.value = value;
119
+ }
120
+ parseValue(data) {
121
+ const value = data.textContent ?? "";
122
+ this.value =
123
+ (typeof value === "string" ? value : "").split("\n").shift() ?? "";
124
+ }
125
+ parseAttributes(data) {
126
+ if (!Array.isArray(this.definition.attributes)) {
127
+ return;
128
+ }
129
+ if ("attributes" in data && data.attributes.length) {
130
+ for (let i = 0; i < data.attributes.length; ++i) {
131
+ const attr = data.attributes.item(i);
132
+ const name = attr?.nodeName.toLowerCase();
133
+ if (attr && isGMLNodeAttribute(name)) {
134
+ const value = attr.value;
135
+ const attributeDefinition = this.getAttributeDefinition(name);
136
+ if (attributeDefinition) {
137
+ const attributeValue = typeof attributeDefinition.parse === "function"
138
+ ? attributeDefinition.parse(value)
139
+ : value;
140
+ this.setAttribute(name, attributeValue);
141
+ }
142
+ }
143
+ }
144
+ }
145
+ }
146
+ parseChildNodes(data) {
147
+ if (data.childNodes?.length) {
148
+ for (let i = 0; i < data.childNodes.length; ++i) {
149
+ const child = data.childNodes[i];
150
+ const name = child.nodeName.toLowerCase();
151
+ if (isGMLNodeName(name)) {
152
+ const childNode = this.getChildNodeDefinition(name);
153
+ if (childNode) {
154
+ const definition = getGMLNodeDefinition(name);
155
+ this.addChild(name, createGmlNode(definition, child));
156
+ }
157
+ }
158
+ }
159
+ }
160
+ }
161
+ getChildNodeDefinition(name) {
162
+ return this.definition.children
163
+ .map((item) => typeof item === "string" ? createGMLChildNodeDefinition(item) : item)
164
+ .find((item) => item.name === name);
165
+ }
166
+ getAttributeDefinition(name) {
167
+ return this.definition.attributes?.find((item) => item.name === name);
168
+ }
169
+ getTagStart() {
170
+ return formatXmlTagStart(this.definition.name, this.attributes);
171
+ }
172
+ getTagEnd() {
173
+ return formatXmlTagEnd(this.definition.name);
174
+ }
175
+ getTagContent() {
176
+ return Object.keys(this.children)
177
+ .map((child) => this.children[child]?.map((item) => item.toString()).join(""))
178
+ .join("");
179
+ }
180
+ toString() {
181
+ return `${this.getTagStart()}${this.getTagContent()}${this.getTagEnd()}`;
182
+ }
183
+ toObject() {
184
+ const obj = (Object.keys(this.children)).reduce((result, tag) => ({
185
+ ...result,
186
+ [tag]: this.children[tag].map((item) => item.toObject()),
187
+ }), {});
188
+ return obj;
189
+ }
190
+ }
@@ -0,0 +1,4 @@
1
+ import { GMLNodeDefinition, GMLNodeName } from "./types";
2
+ declare const gmlNodeClassMap: Record<GMLNodeName, GMLNodeDefinition>;
3
+ export declare const getGMLNodeDefinition: (nodeName: GMLNodeName) => GMLNodeDefinition;
4
+ export default gmlNodeClassMap;
@@ -0,0 +1,79 @@
1
+ import { GMLNodeName } from "./types";
2
+ import GMLBrush from "./nodes/brush";
3
+ import GMLClient from "./nodes/client";
4
+ import { GMLBrushModeDefinition as GMLBrushMode, GMLBrushSpecDefinition as GMLBrushSpec, GMLBrushWidthDefinition as GMLBrushWidth, GMLBrushSpeedToWidthRatioDefinition as GMLBrushSpeedToWidthRatio, GMLBrushUniqueStyleIdDefinition as GMLBrushUniqueStyleId, GMLBrushLayerAbsoluteDefinition as GMLBrushLayerAbsolute, GMLBrushLayerRelativeDefinition as GMLBrushLayerRelative, GMLBrushDripAmountDefinition as GMLBrushDripAmount, GMLBrushDripSpeedDefinition as GMLBrushDripSpeed, GMLBrushDripVecRelativeToUpDefinition as GMLBrushDripVecRelativeToUp, } from "./nodes/brush/settings";
5
+ import { GMLClientIpDefinition as GMLClientIp, GMLClientKeywordsDefinition as GMLClientKeywords, GMLClientNameDefinition as GMLClientName, GMLClientPermalinkDefinition as GMLClientPermalink, GMLClientUniqueKeyDefinition as GMLClientUniqueKey, GMLClientUsernameDefinition as GMLClientUsername, GMLClientVersionDefinition as GMLClientVersion, GMLLocationDefinition as GMLLocation, GMLLocationLatitudeDefinition as GMLLocationLatitude, GMLLocationLongitudeDefinition as GMLLocationLongitude, GMLTimeDefinition as GMLTime, } from "./nodes/client/settings";
6
+ import GMLDocument from "./nodes/document";
7
+ import GMLDrawing from "./nodes/drawing";
8
+ import GMLEnvironment from "./nodes/environment";
9
+ import { GMLEnvOffsetDefinition as GMLEnvOffset, GMLEnvRotationDefinition as GMLEnvRotation, GMLEnvOriginDefinition as GMLEnvOrigin, GMLEnvRealScareDefinition as GMLEnvRealScare, GMLEnvAudioDefinition as GMLEnvAudio, GMLEnvBackgroundDefinition as GMLEnvBackground, GMLEnvUpDefinition as GMLEnvUp, GMLEnvScreenBoundsDefinition as GMLEnvScreenBounds, } from "./nodes/environment/settings";
10
+ import GMLPoint from "./nodes/point";
11
+ import GMLColor, { GMLColorRDefinition as GMLColorR, GMLColorGDefinition as GMLColorG, GMLColorBDefinition as GMLColorB, GMLColorADefinition as GMLColorA, } from "./nodes/point/color";
12
+ import GMLDirection from "./nodes/point/direction";
13
+ import { GMLPointXDefinition as GMLPointX, GMLPointYDefinition as GMLPointY, GMLPointZDefinition as GMLPointZ, GMLPointTDefinition as GMLPointT,
14
+ // GMLPointTimeDefinition as GMLPointTime,
15
+ GMLPointPressureDefinition as GMLPointPressure, GMLPointRotationDefinition as GMLPointRotation, GMLPointUnitDefinition as GMLPointUnit, } from "./nodes/point/points";
16
+ import GMLRoot from "./nodes/root";
17
+ import GMLStroke from "./nodes/stroke";
18
+ import GMLStrokeInfo from "./nodes/stroke/info";
19
+ import GMLStrokeInfoCurved from "./nodes/stroke/curved";
20
+ import GMLTag from "./nodes/tag";
21
+ import GMLHeader from "./nodes/header";
22
+ const gmlNodeClassMap = {
23
+ [GMLNodeName.BRUSH]: GMLBrush,
24
+ [GMLNodeName.BRUSH_MODE]: GMLBrushMode,
25
+ [GMLNodeName.BRUSH_SPEC]: GMLBrushSpec,
26
+ [GMLNodeName.BRUSH_WIDTH]: GMLBrushWidth,
27
+ [GMLNodeName.BRUSH_SPEED_TO_WIDTH_RATIO]: GMLBrushSpeedToWidthRatio,
28
+ [GMLNodeName.BRUSH_DRIP_AMOUNT]: GMLBrushDripAmount,
29
+ [GMLNodeName.BRUSH_DRIP_SPEED]: GMLBrushDripSpeed,
30
+ [GMLNodeName.BRUSH_DRIP_VEC_RELATIVE_TO_UP]: GMLBrushDripVecRelativeToUp,
31
+ [GMLNodeName.BRUSH_LAYER_ABSOLUTE]: GMLBrushLayerAbsolute,
32
+ [GMLNodeName.BRUSH_LAYER_RELATIVE]: GMLBrushLayerRelative,
33
+ [GMLNodeName.BRUSH_UNIQUE_STYLE_ID]: GMLBrushUniqueStyleId,
34
+ [GMLNodeName.CLIENT]: GMLClient,
35
+ [GMLNodeName.CLIENT_IP]: GMLClientIp,
36
+ [GMLNodeName.CLIENT_NAME]: GMLClientName,
37
+ [GMLNodeName.CLIENT_KEYWORDS]: GMLClientKeywords,
38
+ [GMLNodeName.CLIENT_PERMALINK]: GMLClientPermalink,
39
+ [GMLNodeName.CLIENT_UNIQUEKEY]: GMLClientUniqueKey,
40
+ [GMLNodeName.CLIENT_USERNAME]: GMLClientUsername,
41
+ [GMLNodeName.CLIENT_VERSION]: GMLClientVersion,
42
+ [GMLNodeName.CLIENT_LOCATION]: GMLLocation,
43
+ [GMLNodeName.CLIENT_LOCATION_LAT]: GMLLocationLatitude,
44
+ [GMLNodeName.CLIENT_LOCATION_LON]: GMLLocationLongitude,
45
+ [GMLNodeName.CLIENT_TIME]: GMLTime,
46
+ [GMLNodeName.COLOR]: GMLColor,
47
+ [GMLNodeName.COLOR_R]: GMLColorR,
48
+ [GMLNodeName.COLOR_G]: GMLColorG,
49
+ [GMLNodeName.COLOR_B]: GMLColorB,
50
+ [GMLNodeName.COLOR_A]: GMLColorA,
51
+ [GMLNodeName.DIRECTION]: GMLDirection,
52
+ [GMLNodeName.DOCUMENT]: GMLDocument,
53
+ [GMLNodeName.DRAWING]: GMLDrawing,
54
+ [GMLNodeName.ENVIRONMENT]: GMLEnvironment,
55
+ [GMLNodeName.ENVIRONMENT_OFFSET]: GMLEnvOffset,
56
+ [GMLNodeName.ENVIRONMENT_ROTATION]: GMLEnvRotation,
57
+ [GMLNodeName.ENVIRONMENT_UP]: GMLEnvUp,
58
+ [GMLNodeName.ENVIRONMENT_SCREEN_BOUNDS]: GMLEnvScreenBounds,
59
+ [GMLNodeName.ENVIRONMENT_ORIGIN]: GMLEnvOrigin,
60
+ [GMLNodeName.ENVIRONMENT_REAL_SCALE]: GMLEnvRealScare,
61
+ [GMLNodeName.ENVIRONMENT_AUDIO]: GMLEnvAudio,
62
+ [GMLNodeName.ENVIRONMENT_BACKGROUND]: GMLEnvBackground,
63
+ [GMLNodeName.HEADER]: GMLHeader,
64
+ [GMLNodeName.POINT]: GMLPoint,
65
+ [GMLNodeName.POINT_T]: GMLPointT,
66
+ [GMLNodeName.POINT_X]: GMLPointX,
67
+ [GMLNodeName.POINT_Y]: GMLPointY,
68
+ [GMLNodeName.POINT_Z]: GMLPointZ,
69
+ [GMLNodeName.PRESSURE]: GMLPointPressure,
70
+ [GMLNodeName.ROOT]: GMLRoot,
71
+ [GMLNodeName.ROTATION]: GMLPointRotation,
72
+ [GMLNodeName.STROKE]: GMLStroke,
73
+ [GMLNodeName.STROKE_INFO]: GMLStrokeInfo,
74
+ [GMLNodeName.STROKE_INFO_CURVED]: GMLStrokeInfoCurved,
75
+ [GMLNodeName.TAG]: GMLTag,
76
+ [GMLNodeName.UNIT]: GMLPointUnit,
77
+ };
78
+ export const getGMLNodeDefinition = (nodeName) => gmlNodeClassMap[nodeName];
79
+ export default gmlNodeClassMap;
@@ -0,0 +1,6 @@
1
+ import { GMLNode } from "../..";
2
+ import { GMLNodeDefinition } from "../../types";
3
+ export declare class GMLBrush extends GMLNode {
4
+ }
5
+ export declare const GMLBrushDefinition: GMLNodeDefinition;
6
+ export default GMLBrushDefinition;
@@ -0,0 +1,23 @@
1
+ import { GMLNode } from "../..";
2
+ import { GMLNodeName } from "../../types";
3
+ export class GMLBrush extends GMLNode {
4
+ }
5
+ export const GMLBrushDefinition = {
6
+ name: GMLNodeName.BRUSH,
7
+ model: GMLBrush,
8
+ attributes: [],
9
+ children: [
10
+ GMLNodeName.COLOR,
11
+ GMLNodeName.BRUSH_MODE,
12
+ GMLNodeName.BRUSH_SPEC,
13
+ GMLNodeName.BRUSH_WIDTH,
14
+ GMLNodeName.BRUSH_SPEED_TO_WIDTH_RATIO,
15
+ GMLNodeName.BRUSH_DRIP_AMOUNT,
16
+ GMLNodeName.BRUSH_DRIP_SPEED,
17
+ GMLNodeName.BRUSH_DRIP_VEC_RELATIVE_TO_UP,
18
+ GMLNodeName.BRUSH_LAYER_ABSOLUTE,
19
+ GMLNodeName.BRUSH_LAYER_RELATIVE,
20
+ GMLNodeName.BRUSH_UNIQUE_STYLE_ID,
21
+ ],
22
+ };
23
+ export default GMLBrushDefinition;
@@ -0,0 +1,35 @@
1
+ import { GMLNodeDefinition } from "../../types";
2
+ import { GMLLeafNode } from "../leaf";
3
+ import { GMLFloatNode } from "../leaf/float";
4
+ import { GMLIntegerNode } from "../leaf/integer";
5
+ import { GMLLeafNodeParent } from "../leaf/parent";
6
+ export declare class GMLBrushMode extends GMLLeafNode {
7
+ }
8
+ export declare const GMLBrushModeDefinition: GMLNodeDefinition;
9
+ export declare class GMLBrushSpec extends GMLLeafNode {
10
+ }
11
+ export declare const GMLBrushSpecDefinition: GMLNodeDefinition;
12
+ export declare class GMLBrushWidth extends GMLFloatNode {
13
+ }
14
+ export declare const GMLBrushWidthDefinition: GMLNodeDefinition;
15
+ export declare class GMLBrushSpeedToWidthRatio extends GMLFloatNode {
16
+ }
17
+ export declare const GMLBrushSpeedToWidthRatioDefinition: GMLNodeDefinition;
18
+ export declare class GMLBrushUniqueStyleId extends GMLLeafNode {
19
+ }
20
+ export declare const GMLBrushUniqueStyleIdDefinition: GMLNodeDefinition;
21
+ export declare class GMLBrushLayerAbsolute extends GMLIntegerNode {
22
+ }
23
+ export declare const GMLBrushLayerAbsoluteDefinition: GMLNodeDefinition;
24
+ export declare class GMLBrushLayerRelative extends GMLIntegerNode {
25
+ }
26
+ export declare const GMLBrushLayerRelativeDefinition: GMLNodeDefinition;
27
+ export declare class GMLBrushDripAmount extends GMLFloatNode {
28
+ }
29
+ export declare const GMLBrushDripAmountDefinition: GMLNodeDefinition;
30
+ export declare class GMLBrushDripSpeed extends GMLFloatNode {
31
+ }
32
+ export declare const GMLBrushDripSpeedDefinition: GMLNodeDefinition;
33
+ export declare class GMLBrushDripVecRelativeToUp extends GMLLeafNodeParent {
34
+ }
35
+ export declare const GMLBrushDripVecRelativeToUpDefinition: GMLNodeDefinition;
@@ -0,0 +1,45 @@
1
+ import { GMLNodeName } from "../../types";
2
+ import { createDefinition } from "../../util/definition";
3
+ import { GMLLeafNode } from "../leaf";
4
+ import { GMLFloatNode } from "../leaf/float";
5
+ import { GMLIntegerNode } from "../leaf/integer";
6
+ import { GMLLeafNodeParent } from "../leaf/parent";
7
+ export class GMLBrushMode extends GMLLeafNode {
8
+ }
9
+ export const GMLBrushModeDefinition = createDefinition(GMLNodeName.BRUSH_MODE, GMLBrushMode);
10
+ export class GMLBrushSpec extends GMLLeafNode {
11
+ }
12
+ export const GMLBrushSpecDefinition = createDefinition(GMLNodeName.BRUSH_SPEC, GMLBrushSpec);
13
+ export class GMLBrushWidth extends GMLFloatNode {
14
+ }
15
+ export const GMLBrushWidthDefinition = createDefinition(GMLNodeName.BRUSH_WIDTH, GMLBrushWidth);
16
+ export class GMLBrushSpeedToWidthRatio extends GMLFloatNode {
17
+ }
18
+ export const GMLBrushSpeedToWidthRatioDefinition = createDefinition(GMLNodeName.BRUSH_SPEED_TO_WIDTH_RATIO, GMLBrushSpeedToWidthRatio);
19
+ export class GMLBrushUniqueStyleId extends GMLLeafNode {
20
+ }
21
+ export const GMLBrushUniqueStyleIdDefinition = createDefinition(GMLNodeName.BRUSH_UNIQUE_STYLE_ID, GMLBrushUniqueStyleId);
22
+ export class GMLBrushLayerAbsolute extends GMLIntegerNode {
23
+ }
24
+ export const GMLBrushLayerAbsoluteDefinition = createDefinition(GMLNodeName.BRUSH_LAYER_ABSOLUTE, GMLBrushLayerAbsolute);
25
+ export class GMLBrushLayerRelative extends GMLIntegerNode {
26
+ }
27
+ export const GMLBrushLayerRelativeDefinition = createDefinition(GMLNodeName.BRUSH_LAYER_RELATIVE, GMLBrushLayerRelative);
28
+ export class GMLBrushDripAmount extends GMLFloatNode {
29
+ }
30
+ export const GMLBrushDripAmountDefinition = createDefinition(GMLNodeName.BRUSH_DRIP_AMOUNT, GMLBrushDripAmount);
31
+ export class GMLBrushDripSpeed extends GMLFloatNode {
32
+ }
33
+ export const GMLBrushDripSpeedDefinition = createDefinition(GMLNodeName.BRUSH_DRIP_SPEED, GMLBrushDripSpeed);
34
+ export class GMLBrushDripVecRelativeToUp extends GMLLeafNodeParent {
35
+ }
36
+ export const GMLBrushDripVecRelativeToUpDefinition = {
37
+ name: GMLNodeName.BRUSH_DRIP_VEC_RELATIVE_TO_UP,
38
+ model: GMLBrushDripVecRelativeToUp,
39
+ attributes: [],
40
+ children: [
41
+ { name: GMLNodeName.POINT_X, required: true },
42
+ { name: GMLNodeName.POINT_Y, required: true },
43
+ GMLNodeName.POINT_Z,
44
+ ],
45
+ };
@@ -0,0 +1,7 @@
1
+ import { GMLNode } from "../..";
2
+ import { GMLNodeDefinition, GMLParsedNode } from "../../types";
3
+ export declare class GMLClient extends GMLNode {
4
+ init(data?: GMLParsedNode): void;
5
+ }
6
+ export declare const definition: GMLNodeDefinition;
7
+ export default definition;
@@ -0,0 +1,25 @@
1
+ import { GMLNode } from "../..";
2
+ import { GMLNodeName } from "../../types";
3
+ export class GMLClient extends GMLNode {
4
+ init(data) {
5
+ super.init(data);
6
+ // TODO: Add <version> if default <name> was created
7
+ }
8
+ }
9
+ export const definition = {
10
+ name: GMLNodeName.CLIENT,
11
+ model: GMLClient,
12
+ attributes: [],
13
+ children: [
14
+ { name: GMLNodeName.CLIENT_NAME, initDefault: true },
15
+ { name: GMLNodeName.CLIENT_VERSION, initDefault: true },
16
+ { name: GMLNodeName.CLIENT_TIME, initDefault: true },
17
+ GMLNodeName.CLIENT_USERNAME,
18
+ GMLNodeName.CLIENT_PERMALINK,
19
+ GMLNodeName.CLIENT_KEYWORDS,
20
+ GMLNodeName.CLIENT_UNIQUEKEY,
21
+ GMLNodeName.CLIENT_IP,
22
+ GMLNodeName.CLIENT_LOCATION,
23
+ ],
24
+ };
25
+ export default definition;
@@ -0,0 +1,48 @@
1
+ import { GMLNodeDefinition, GMLParsedNode } from "../../types";
2
+ import { GMLLeafNode } from "../leaf";
3
+ import { GMLLeafNodeParent } from "../leaf/parent";
4
+ export declare class GMLClientUsername extends GMLLeafNode {
5
+ }
6
+ export declare const GMLClientUsernameDefinition: GMLNodeDefinition;
7
+ export declare class GMLClientPermalink extends GMLLeafNode {
8
+ }
9
+ export declare const GMLClientPermalinkDefinition: GMLNodeDefinition;
10
+ export declare class GMLClientKeywords extends GMLLeafNode {
11
+ }
12
+ export declare const GMLClientKeywordsDefinition: GMLNodeDefinition;
13
+ export declare class GMLClientUniqueKey extends GMLLeafNode {
14
+ }
15
+ export declare const GMLClientUniqueKeyDefinition: GMLNodeDefinition;
16
+ export declare class GMLClientIp extends GMLLeafNode {
17
+ }
18
+ export declare const GMLClientIpDefinition: GMLNodeDefinition;
19
+ export declare class GMLClientName extends GMLLeafNode {
20
+ init(data?: GMLParsedNode): void;
21
+ }
22
+ export declare const GMLClientNameDefinition: GMLNodeDefinition;
23
+ export declare class GMLTime extends GMLLeafNode {
24
+ /**
25
+ * `declare` tells TypeScript the property exists but does not emit
26
+ * any initialization code. This allows the value set in init() to
27
+ * persist.
28
+ */
29
+ private stringValue;
30
+ constructor(definition: GMLNodeDefinition, data?: GMLParsedNode);
31
+ init(data?: GMLParsedNode): void;
32
+ parseValue(data: GMLParsedNode): void;
33
+ get floatValue(): number | undefined;
34
+ }
35
+ export declare const GMLTimeDefinition: GMLNodeDefinition;
36
+ export declare class GMLClientVersion extends GMLLeafNode {
37
+ init(data?: GMLParsedNode): void;
38
+ }
39
+ export declare const GMLClientVersionDefinition: GMLNodeDefinition;
40
+ export declare class GMLLocation extends GMLLeafNodeParent {
41
+ }
42
+ export declare const GMLLocationDefinition: GMLNodeDefinition;
43
+ export declare class GMLLocationLongitude extends GMLLeafNode {
44
+ }
45
+ export declare const GMLLocationLongitudeDefinition: GMLNodeDefinition;
46
+ export declare class GMLLocationLatitude extends GMLLeafNode {
47
+ }
48
+ export declare const GMLLocationLatitudeDefinition: GMLNodeDefinition;
@@ -0,0 +1,74 @@
1
+ import { GMLNodeName, } from "../../types";
2
+ import { GMLLeafNode } from "../leaf";
3
+ import { createDefinition } from "../../util/definition";
4
+ import { GMLLeafNodeParent } from "../leaf/parent";
5
+ import config from "../../../../package.json";
6
+ export class GMLClientUsername extends GMLLeafNode {
7
+ }
8
+ export const GMLClientUsernameDefinition = createDefinition(GMLNodeName.CLIENT_USERNAME, GMLClientUsername);
9
+ export class GMLClientPermalink extends GMLLeafNode {
10
+ }
11
+ export const GMLClientPermalinkDefinition = createDefinition(GMLNodeName.CLIENT_PERMALINK, GMLClientPermalink);
12
+ export class GMLClientKeywords extends GMLLeafNode {
13
+ }
14
+ export const GMLClientKeywordsDefinition = createDefinition(GMLNodeName.CLIENT_KEYWORDS, GMLClientKeywords);
15
+ export class GMLClientUniqueKey extends GMLLeafNode {
16
+ }
17
+ export const GMLClientUniqueKeyDefinition = createDefinition(GMLNodeName.CLIENT_UNIQUEKEY, GMLClientUniqueKey);
18
+ export class GMLClientIp extends GMLLeafNode {
19
+ }
20
+ export const GMLClientIpDefinition = createDefinition(GMLNodeName.CLIENT_IP, GMLClientIp);
21
+ export class GMLClientName extends GMLLeafNode {
22
+ init(data) {
23
+ this.setValue("gmljs");
24
+ super.init(data);
25
+ }
26
+ }
27
+ export const GMLClientNameDefinition = createDefinition(GMLNodeName.CLIENT_NAME, GMLClientName);
28
+ export class GMLTime extends GMLLeafNode {
29
+ constructor(definition, data) {
30
+ super(definition, data);
31
+ this.stringValue = data?.textContent ?? "";
32
+ }
33
+ init(data) {
34
+ this.setValue(Math.floor(Date.now() * 0.001));
35
+ super.init(data);
36
+ }
37
+ parseValue(data) {
38
+ const value = data.textContent ?? "";
39
+ const intValue = parseInt(value, 10);
40
+ if (!Number.isFinite(intValue)) {
41
+ throw new Error(`Unable to parse value "${value}" as integer.`);
42
+ }
43
+ this.value = intValue;
44
+ this.stringValue = value;
45
+ }
46
+ get floatValue() {
47
+ return this.stringValue ? parseFloat(this.stringValue) : undefined;
48
+ }
49
+ }
50
+ export const GMLTimeDefinition = createDefinition(GMLNodeName.CLIENT_TIME, GMLTime);
51
+ export class GMLClientVersion extends GMLLeafNode {
52
+ init(data) {
53
+ this.setValue(config.version ?? "unknown");
54
+ super.init(data);
55
+ }
56
+ }
57
+ export const GMLClientVersionDefinition = createDefinition(GMLNodeName.CLIENT_VERSION, GMLClientVersion);
58
+ export class GMLLocation extends GMLLeafNodeParent {
59
+ }
60
+ export const GMLLocationDefinition = {
61
+ name: GMLNodeName.CLIENT_LOCATION,
62
+ model: GMLLocation,
63
+ attributes: [],
64
+ children: [
65
+ { name: GMLNodeName.CLIENT_LOCATION_LAT, required: true },
66
+ { name: GMLNodeName.CLIENT_LOCATION_LON, required: true },
67
+ ],
68
+ };
69
+ export class GMLLocationLongitude extends GMLLeafNode {
70
+ }
71
+ export const GMLLocationLongitudeDefinition = createDefinition(GMLNodeName.CLIENT_LOCATION_LON, GMLLocationLongitude);
72
+ export class GMLLocationLatitude extends GMLLeafNode {
73
+ }
74
+ export const GMLLocationLatitudeDefinition = createDefinition(GMLNodeName.CLIENT_LOCATION_LAT, GMLLocationLatitude);
@@ -0,0 +1,7 @@
1
+ import { GMLNode } from "../..";
2
+ import { GMLNodeDefinition } from "../../types";
3
+ export declare class GMLDocument extends GMLNode {
4
+ toString(): string;
5
+ }
6
+ export declare const GMLDocumentDefinition: GMLNodeDefinition;
7
+ export default GMLDocumentDefinition;
@@ -0,0 +1,14 @@
1
+ import { GMLNode } from "../..";
2
+ import { GMLNodeName } from "../../types";
3
+ export class GMLDocument extends GMLNode {
4
+ toString() {
5
+ return this.getChild(GMLNodeName.ROOT)?.toString() ?? "";
6
+ }
7
+ }
8
+ export const GMLDocumentDefinition = {
9
+ name: GMLNodeName.DOCUMENT,
10
+ model: GMLDocument,
11
+ attributes: [],
12
+ children: [{ name: GMLNodeName.ROOT, initDefault: true }],
13
+ };
14
+ export default GMLDocumentDefinition;
@@ -0,0 +1,9 @@
1
+ import { GMLNode } from "../..";
2
+ import { GMLNodeDefinition } from "../../types";
3
+ import { GMLStroke } from "../stroke";
4
+ export declare class GMLDrawing extends GMLNode {
5
+ getStroke(index: number): GMLStroke | undefined;
6
+ getStrokes(): GMLStroke[];
7
+ }
8
+ export declare const GMLDrawingDefinition: GMLNodeDefinition;
9
+ export default GMLDrawingDefinition;
@@ -0,0 +1,17 @@
1
+ import { GMLNode } from "../..";
2
+ import { GMLNodeName } from "../../types";
3
+ export class GMLDrawing extends GMLNode {
4
+ getStroke(index) {
5
+ return this.getChildPath([[GMLNodeName.STROKE, index]]);
6
+ }
7
+ getStrokes() {
8
+ return this.getChildren(GMLNodeName.STROKE) ?? [];
9
+ }
10
+ }
11
+ export const GMLDrawingDefinition = {
12
+ name: GMLNodeName.DRAWING,
13
+ model: GMLDrawing,
14
+ attributes: [],
15
+ children: [GMLNodeName.STROKE],
16
+ };
17
+ export default GMLDrawingDefinition;
@@ -0,0 +1,10 @@
1
+ import { GMLNode } from "../..";
2
+ import { GMLNodeDefinition } from "../../types";
3
+ export declare class GMLEnvironment extends GMLNode {
4
+ getUp(): number[] | undefined;
5
+ getScreenBounds(): number[] | undefined;
6
+ getOffset(): number[] | undefined;
7
+ getRotation(): number[] | undefined;
8
+ }
9
+ export declare const GMLEnvironmentDefinition: GMLNodeDefinition;
10
+ export default GMLEnvironmentDefinition;