gmljs 3.0.0-beta-20260117 → 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.
package/package.json CHANGED
@@ -1,8 +1,9 @@
1
1
  {
2
2
  "name": "gmljs",
3
- "version": "3.0.0-beta-20260117",
3
+ "version": "3.0.0-beta-20260118",
4
4
  "description": "Library for parsing GML documents.",
5
5
  "main": "dist/index.js",
6
+ "types": "dist/index.d.ts",
6
7
  "type": "module",
7
8
  "scripts": {
8
9
  "build": "tsc",
@@ -11,7 +12,7 @@
11
12
  "test:watch": "node --import tsx --test --watch 'src/**/*.test.ts'",
12
13
  "format": "prettier --write .",
13
14
  "clean": "rm -rf dist",
14
- "prepublishOnly:": "npm run clean && npm run build"
15
+ "prepublishOnly": "npm run clean && npm run build"
15
16
  },
16
17
  "author": "Gustav Peterz <gpeterz@gmail.com>",
17
18
  "license": "MIT",
@@ -20,10 +21,10 @@
20
21
  "url": "https://github.com/dwyfl/gmljs.git"
21
22
  },
22
23
  "devDependencies": {
23
- "@types/node": "^22.17.0",
24
- "prettier": "^3.6.2",
24
+ "@types/node": "^25.0.9",
25
+ "prettier": "^3.8.0",
25
26
  "tsx": "^4.21.0",
26
- "typescript": "^5.9.2"
27
+ "typescript": "^5.9.3"
27
28
  },
28
29
  "dependencies": {
29
30
  "@xmldom/xmldom": "^0.9.8"
@@ -1,2 +0,0 @@
1
- import { GMLNodeConstructor, GMLNodeDefinition, GMLNodeName } from "./types";
2
- export declare const createDefinition: (name: GMLNodeName, model: GMLNodeConstructor) => GMLNodeDefinition;
@@ -1,6 +0,0 @@
1
- export const createDefinition = (name, model) => ({
2
- name,
3
- model,
4
- attributes: [],
5
- children: [],
6
- });
@@ -1,21 +0,0 @@
1
- import { GMLNode } from ".";
2
- import { GMLChildNodeDefinition, GMLNodeAttribute, GMLNodeDefinition, GMLNodeName, GMLParsedNode } from "./types";
3
- export declare function createGmlNodeFromTagName(tagName: GMLNodeName, data?: GMLParsedNode): GMLNode;
4
- export declare function createGmlNodeFromXml(xml: string): GMLNode;
5
- export declare function createGmlNode(definition: GMLNodeDefinition, data?: GMLParsedNode): GMLNode;
6
- export declare const isGMLNodeAttribute: (value: unknown) => value is GMLNodeAttribute;
7
- export declare const isGMLNodeName: (value: unknown) => value is GMLNodeName;
8
- export declare const isGMLChildNodeDefinition: (value: unknown) => value is GMLChildNodeDefinition;
9
- export declare const createGMLChildNodeDefinition: (name: GMLNodeName, options?: Partial<GMLChildNodeDefinition>) => GMLChildNodeDefinition;
10
- export { createDefinition } from "./definition";
11
- type PointObj = {
12
- x: number;
13
- y: number;
14
- z?: number;
15
- };
16
- export declare const createGMLDocumentFromPointArrays: (strokes?: PointObj[][], options?: {
17
- screenBounds?: {
18
- x: number;
19
- y: number;
20
- };
21
- }) => GMLNode;
package/dist/gml/util.js DELETED
@@ -1,60 +0,0 @@
1
- import { getGMLNodeDefinition } from "./map";
2
- import { GMLNodeAttribute, GMLNodeName, } from "./types";
3
- import { parseXml } from "../util/xml";
4
- export function createGmlNodeFromTagName(tagName, data) {
5
- const definition = getGMLNodeDefinition(tagName);
6
- if (!definition) {
7
- throw new Error(`Invalid GML! "${tagName}" is not a valid GML tag.`);
8
- }
9
- return createGmlNode(definition, data);
10
- }
11
- export function createGmlNodeFromXml(xml) {
12
- const xmlDocument = parseXml(xml);
13
- const xmlElement = xmlDocument.documentElement ?? undefined;
14
- const tagName = xmlElement?.tagName;
15
- if (!isGMLNodeName(tagName)) {
16
- throw new Error(`Invalid GML! "${tagName}" is not a valid GML tag.`);
17
- }
18
- return createGmlNodeFromTagName(tagName, xmlElement);
19
- }
20
- export function createGmlNode(definition, data) {
21
- const { model } = definition;
22
- return new model(definition, data);
23
- }
24
- export const isGMLNodeAttribute = (value) => Object.values(GMLNodeAttribute).includes(value);
25
- export const isGMLNodeName = (value) => Object.values(GMLNodeName).includes(value);
26
- export const isGMLChildNodeDefinition = (value) => typeof value === "object" &&
27
- value !== null &&
28
- "name" in value &&
29
- typeof value.name === "string";
30
- export const createGMLChildNodeDefinition = (name, options = {}) => ({ name, ...options });
31
- export { createDefinition } from "./definition";
32
- const createPoint = (values) => {
33
- const point = createGmlNodeFromTagName(GMLNodeName.POINT);
34
- point.setValues(values);
35
- return point;
36
- };
37
- const createStroke = (points) => {
38
- const stroke = createGmlNodeFromTagName(GMLNodeName.STROKE);
39
- points.forEach((point) => stroke?.addChild(GMLNodeName.POINT, createPoint(point)));
40
- return stroke;
41
- };
42
- export const createGMLDocumentFromPointArrays = (strokes = [], options = {}) => {
43
- const doc = createGmlNodeFromTagName(GMLNodeName.DOCUMENT);
44
- if (options.screenBounds) {
45
- const screenBounds = doc.getChildPath([
46
- GMLNodeName.ROOT,
47
- GMLNodeName.TAG,
48
- GMLNodeName.HEADER,
49
- GMLNodeName.ENVIRONMENT_SCREEN_BOUNDS,
50
- ]);
51
- screenBounds?.setValues(options.screenBounds);
52
- }
53
- const drawing = doc.getChildPath([
54
- GMLNodeName.ROOT,
55
- GMLNodeName.TAG,
56
- GMLNodeName.DRAWING,
57
- ]);
58
- strokes.forEach((points) => drawing?.addChild(GMLNodeName.STROKE, createStroke(points)));
59
- return doc;
60
- };