@oxeo/visual 0.0.0-stage → 0.2.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.
Files changed (48) hide show
  1. package/README.md +99 -2
  2. package/bin/oxeo-visual.js +2 -0
  3. package/dist/build.d.ts +23 -0
  4. package/dist/build.js +58 -0
  5. package/dist/cli/build-command.d.ts +5 -0
  6. package/dist/cli/build-command.js +57 -0
  7. package/dist/cli/dev.d.ts +6 -0
  8. package/dist/cli/dev.js +274 -0
  9. package/dist/cli/index.d.ts +1 -0
  10. package/dist/cli/index.js +104 -0
  11. package/dist/cli/open.d.ts +1 -0
  12. package/dist/cli/open.js +21 -0
  13. package/dist/cli/output.d.ts +4 -0
  14. package/dist/cli/output.js +13 -0
  15. package/dist/cli/run.d.ts +7 -0
  16. package/dist/cli/run.js +55 -0
  17. package/dist/cli/worker.d.ts +20 -0
  18. package/dist/cli/worker.js +94 -0
  19. package/dist/config.d.ts +33 -0
  20. package/dist/config.js +26 -0
  21. package/dist/extract.d.ts +8 -0
  22. package/dist/extract.js +300 -0
  23. package/dist/index.d.ts +6 -0
  24. package/dist/index.js +24 -0
  25. package/dist/layout/cards.d.ts +43 -0
  26. package/dist/layout/cards.js +121 -0
  27. package/dist/layout/place.d.ts +40 -0
  28. package/dist/layout/place.js +197 -0
  29. package/dist/layout/route.d.ts +30 -0
  30. package/dist/layout/route.js +192 -0
  31. package/dist/model.d.ts +60 -0
  32. package/dist/model.js +2 -0
  33. package/dist/project.d.ts +14 -0
  34. package/dist/project.js +11 -0
  35. package/dist/render/client.js +871 -0
  36. package/dist/render/html.d.ts +8 -0
  37. package/dist/render/html.js +211 -0
  38. package/dist/render/palette.d.ts +4 -0
  39. package/dist/render/palette.js +66 -0
  40. package/dist/render/svg.d.ts +20 -0
  41. package/dist/render/svg.js +222 -0
  42. package/dist/scheme-meta.d.ts +90 -0
  43. package/dist/scheme-meta.js +2 -0
  44. package/dist/text.d.ts +2 -0
  45. package/dist/text.js +12 -0
  46. package/dist/types.d.ts +15 -0
  47. package/dist/types.js +143 -0
  48. package/package.json +36 -3
package/dist/text.js ADDED
@@ -0,0 +1,12 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.escapeXml = exports.plural = void 0;
4
+ const plural = (n, forms) => {
5
+ const m10 = n % 10;
6
+ const m100 = n % 100;
7
+ const form = m10 === 1 && m100 !== 11 ? 0 : m10 >= 2 && m10 <= 4 && (m100 < 10 || m100 >= 20) ? 1 : 2;
8
+ return `${n} ${forms[form]}`;
9
+ };
10
+ exports.plural = plural;
11
+ const escapeXml = (text) => text.replace(/[&<>"]/g, (c) => ({ '&': '&amp;', '<': '&lt;', '>': '&gt;', '"': '&quot;' })[c]);
12
+ exports.escapeXml = escapeXml;
@@ -0,0 +1,15 @@
1
+ import * as ts from 'typescript';
2
+ export declare class TypeCatalog {
3
+ private readonly program;
4
+ readonly types: Record<string, string>;
5
+ private readonly ids;
6
+ private readonly checker;
7
+ constructor(program: ts.Program);
8
+ refsOf(typeNode: ts.TypeNode | undefined): string[];
9
+ private collect;
10
+ private resolve;
11
+ private declare;
12
+ private text;
13
+ private inline;
14
+ }
15
+ export declare const compilerOptions: (tsconfig?: string) => ts.CompilerOptions;
package/dist/types.js ADDED
@@ -0,0 +1,143 @@
1
+ "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
9
+ }) : (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ o[k2] = m[k];
12
+ }));
13
+ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
14
+ Object.defineProperty(o, "default", { enumerable: true, value: v });
15
+ }) : function(o, v) {
16
+ o["default"] = v;
17
+ });
18
+ var __importStar = (this && this.__importStar) || (function () {
19
+ var ownKeys = function(o) {
20
+ ownKeys = Object.getOwnPropertyNames || function (o) {
21
+ var ar = [];
22
+ for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
23
+ return ar;
24
+ };
25
+ return ownKeys(o);
26
+ };
27
+ return function (mod) {
28
+ if (mod && mod.__esModule) return mod;
29
+ var result = {};
30
+ if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
31
+ __setModuleDefault(result, mod);
32
+ return result;
33
+ };
34
+ })();
35
+ Object.defineProperty(exports, "__esModule", { value: true });
36
+ exports.compilerOptions = exports.TypeCatalog = void 0;
37
+ const path = __importStar(require("path"));
38
+ const ts = __importStar(require("typescript"));
39
+ const MAX_DEPTH = 3;
40
+ const MAX_DECLARATIONS = 12;
41
+ const MAX_INLINE = 240;
42
+ const isTypeDeclaration = (node) => ts.isInterfaceDeclaration(node) || ts.isTypeAliasDeclaration(node) || ts.isEnumDeclaration(node);
43
+ const isOpaque = (decl) => {
44
+ if (!ts.isTypeAliasDeclaration(decl))
45
+ return false;
46
+ const opaque = (node) => ts.isTypeQueryNode(node) ||
47
+ ts.isTypeOperatorNode(node) ||
48
+ ts.isIndexedAccessTypeNode(node) ||
49
+ Boolean(ts.forEachChild(node, opaque));
50
+ return opaque(decl.type);
51
+ };
52
+ class TypeCatalog {
53
+ constructor(program) {
54
+ this.program = program;
55
+ this.types = {};
56
+ this.ids = new Map();
57
+ this.checker = program.getTypeChecker();
58
+ }
59
+ refsOf(typeNode) {
60
+ const out = [];
61
+ if (typeNode)
62
+ this.collect(typeNode, out, 0);
63
+ return out;
64
+ }
65
+ collect(node, out, depth) {
66
+ const visit = (n) => {
67
+ const name = ts.isTypeReferenceNode(n)
68
+ ? n.typeName
69
+ : ts.isExpressionWithTypeArguments(n)
70
+ ? n.expression
71
+ : undefined;
72
+ const decl = name && out.length < MAX_DECLARATIONS ? this.resolve(name) : undefined;
73
+ if (decl) {
74
+ const id = this.declare(decl);
75
+ if (!out.includes(id)) {
76
+ out.push(id);
77
+ if (depth < MAX_DEPTH && !isOpaque(decl))
78
+ this.collect(decl, out, depth + 1);
79
+ }
80
+ }
81
+ ts.forEachChild(n, visit);
82
+ };
83
+ visit(node);
84
+ }
85
+ resolve(name) {
86
+ let symbol = this.checker.getSymbolAtLocation(name);
87
+ if (symbol && symbol.flags & ts.SymbolFlags.Alias)
88
+ symbol = this.checker.getAliasedSymbol(symbol);
89
+ const decl = symbol?.declarations?.find(isTypeDeclaration);
90
+ if (!decl)
91
+ return undefined;
92
+ const source = decl.getSourceFile();
93
+ const standard = this.program.isSourceFileDefaultLibrary(source) ||
94
+ /[\\/]typescript[\\/]lib[\\/]/.test(source.fileName);
95
+ return standard ? undefined : decl;
96
+ }
97
+ declare(decl) {
98
+ const known = this.ids.get(decl);
99
+ if (known)
100
+ return known;
101
+ const name = decl.name.text;
102
+ const id = name in this.types ? `${name} (${path.basename(decl.getSourceFile().fileName)})` : name;
103
+ this.ids.set(decl, id);
104
+ this.types[id] = isOpaque(decl) ? this.inline(decl) : this.text(decl);
105
+ return id;
106
+ }
107
+ text(decl) {
108
+ const source = decl.getSourceFile();
109
+ const indent = source.getLineAndCharacterOfPosition(decl.getStart()).character;
110
+ return decl
111
+ .getText()
112
+ .replace(/^export\s+(declare\s+)?/, '')
113
+ .split('\n')
114
+ .map((line, i) => i === 0 ? line : line.slice(Math.min(indent, line.length - line.trimStart().length)))
115
+ .join('\n');
116
+ }
117
+ inline(decl) {
118
+ const type = this.checker.getTypeAtLocation(decl.name);
119
+ let text = this.checker.typeToString(type, undefined, ts.TypeFormatFlags.NoTruncation | ts.TypeFormatFlags.UseSingleQuotesForStringLiteralType);
120
+ if (text.length > MAX_INLINE)
121
+ text = `${text.slice(0, MAX_INLINE - 1)}…`;
122
+ return `type ${decl.name.text} = ${text}`;
123
+ }
124
+ }
125
+ exports.TypeCatalog = TypeCatalog;
126
+ const compilerOptions = (tsconfig) => {
127
+ if (tsconfig) {
128
+ const { config } = ts.readConfigFile(tsconfig, ts.sys.readFile);
129
+ return {
130
+ ...ts.parseJsonConfigFileContent(config, ts.sys, path.dirname(tsconfig)).options,
131
+ noEmit: true
132
+ };
133
+ }
134
+ return {
135
+ target: ts.ScriptTarget.ES2020,
136
+ module: ts.ModuleKind.CommonJS,
137
+ moduleResolution: ts.ModuleResolutionKind.Node10,
138
+ experimentalDecorators: true,
139
+ skipLibCheck: true,
140
+ noEmit: true
141
+ };
142
+ };
143
+ exports.compilerOptions = compilerOptions;
package/package.json CHANGED
@@ -1,6 +1,39 @@
1
1
  {
2
2
  "name": "@oxeo/visual",
3
- "version": "0.0.0-stage",
4
- "stub": true,
5
- "description": "Temporary package placeholder for staged publishing"
3
+ "version": "0.2.0",
4
+ "description": "Интерактивная карта схемы данных oxeo: модели, поля, embedded-блоки и связи по исходникам схемы.",
5
+ "repository": {
6
+ "type": "git",
7
+ "url": "git+https://github.com/troovi/oxeo.git",
8
+ "directory": "tools/visual"
9
+ },
10
+ "main": "dist/index.js",
11
+ "types": "./dist/index.d.ts",
12
+ "bin": {
13
+ "oxeo-visual": "bin/oxeo-visual.js"
14
+ },
15
+ "files": [
16
+ "dist",
17
+ "bin"
18
+ ],
19
+ "scripts": {
20
+ "echo": "echo \"@oxeo/visual\"",
21
+ "build": "rm -rf dist && tsc -p tsconfig.build.json && tsc -p tsconfig.client.json",
22
+ "typecheck": "tsc --noEmit -p tsconfig.json && tsc --noEmit -p tsconfig.client.json"
23
+ },
24
+ "dependencies": {
25
+ "libavoid-js": "0.4.5",
26
+ "typescript": "^5.4.0"
27
+ },
28
+ "peerDependencies": {
29
+ "ts-node": ">=10"
30
+ },
31
+ "peerDependenciesMeta": {
32
+ "ts-node": {
33
+ "optional": true
34
+ }
35
+ },
36
+ "devDependencies": {
37
+ "@types/node": "*"
38
+ }
6
39
  }