@likec4/core 1.13.0 → 1.15.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/dist/index.cjs +54 -5
- package/dist/index.d.cts +8 -3
- package/dist/index.d.mts +8 -3
- package/dist/index.d.ts +8 -3
- package/dist/index.mjs +48 -14
- package/dist/shared/{core.C4jDMQ1i.d.cts → core.CYtN9Czk.d.cts} +40 -3
- package/dist/shared/{core.C4jDMQ1i.d.mts → core.CYtN9Czk.d.mts} +40 -3
- package/dist/shared/{core.C4jDMQ1i.d.ts → core.CYtN9Czk.d.ts} +40 -3
- package/dist/shared/{core.IR7XOEkQ.cjs → core.Cq_6j35U.cjs} +26 -0
- package/dist/shared/{core.BJDxVHFh.mjs → core.zYtlWYjW.mjs} +25 -1
- package/dist/types/index.cjs +15 -1
- package/dist/types/index.d.cts +1 -1
- package/dist/types/index.d.mts +1 -1
- package/dist/types/index.d.ts +1 -1
- package/dist/types/index.mjs +1 -1
- package/package.json +8 -8
- package/src/builder/Builder.ts +8 -0
- package/src/index.ts +1 -0
- package/src/model/__test__/fixture.ts +3 -0
- package/src/types/element.ts +3 -0
- package/src/types/global.ts +10 -0
- package/src/types/index.ts +1 -0
- package/src/types/model.ts +4 -0
- package/src/types/view.ts +51 -3
- package/src/utils/commonHead.ts +20 -0
- package/src/utils/index.ts +1 -0
package/src/types/view.ts
CHANGED
|
@@ -1,8 +1,17 @@
|
|
|
1
1
|
import { isArray, isNullish } from 'remeda'
|
|
2
2
|
import type { Tagged } from 'type-fest'
|
|
3
3
|
import type { IconUrl, NonEmptyArray, Point, XYPoint } from './_common'
|
|
4
|
-
import
|
|
4
|
+
import {
|
|
5
|
+
type BorderStyle,
|
|
6
|
+
ElementKind,
|
|
7
|
+
type ElementShape,
|
|
8
|
+
type ElementStyle,
|
|
9
|
+
type Fqn,
|
|
10
|
+
type Link,
|
|
11
|
+
type Tag
|
|
12
|
+
} from './element'
|
|
5
13
|
import type { ElementExpression, ElementPredicateExpression, Expression } from './expression'
|
|
14
|
+
import type { GlobalStyleID } from './global'
|
|
6
15
|
import type { RelationID, RelationshipArrowType, RelationshipKind, RelationshipLineType } from './relation'
|
|
7
16
|
import type { Color, ThemeColorValues } from './theme'
|
|
8
17
|
import type { ElementNotation } from './view-notation'
|
|
@@ -38,6 +47,15 @@ export function isViewRuleStyle(rule: ViewRule): rule is ViewRuleStyle {
|
|
|
38
47
|
return 'style' in rule && 'targets' in rule
|
|
39
48
|
}
|
|
40
49
|
|
|
50
|
+
export interface ViewRuleGlobalStyle {
|
|
51
|
+
styleId: GlobalStyleID
|
|
52
|
+
}
|
|
53
|
+
export function isViewRuleGlobalStyle(rule: ViewRule): rule is ViewRuleGlobalStyle {
|
|
54
|
+
return 'styleId' in rule
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
export type ViewRuleStyleOrGlobalRef = ViewRuleStyle | ViewRuleGlobalStyle
|
|
58
|
+
|
|
41
59
|
export type AutoLayoutDirection = 'TB' | 'BT' | 'LR' | 'RL'
|
|
42
60
|
export function isAutoLayoutDirection(autoLayout: unknown): autoLayout is AutoLayoutDirection {
|
|
43
61
|
return autoLayout === 'TB' || autoLayout === 'BT' || autoLayout === 'LR' || autoLayout === 'RL'
|
|
@@ -52,7 +70,20 @@ export function isViewRuleAutoLayout(rule: ViewRule): rule is ViewRuleAutoLayout
|
|
|
52
70
|
return 'direction' in rule
|
|
53
71
|
}
|
|
54
72
|
|
|
55
|
-
export
|
|
73
|
+
export interface ViewRuleGroup {
|
|
74
|
+
groupRules: Array<ViewRulePredicate | ViewRuleGroup>
|
|
75
|
+
title: string | null
|
|
76
|
+
color?: Color
|
|
77
|
+
border?: BorderStyle
|
|
78
|
+
// 0-100
|
|
79
|
+
opacity?: number
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
export function isViewRuleGroup(rule: ViewRule): rule is ViewRuleGroup {
|
|
83
|
+
return 'title' in rule && 'groupRules' in rule && Array.isArray(rule.groupRules)
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
export type ViewRule = ViewRulePredicate | ViewRuleGroup | ViewRuleStyle | ViewRuleGlobalStyle | ViewRuleAutoLayout
|
|
56
87
|
|
|
57
88
|
export interface BasicView<
|
|
58
89
|
ViewType extends 'element' | 'dynamic',
|
|
@@ -147,7 +178,7 @@ export function isDynamicViewIncludeRule(rule: DynamicViewRule): rule is Dynamic
|
|
|
147
178
|
return 'include' in rule && Array.isArray(rule.include)
|
|
148
179
|
}
|
|
149
180
|
|
|
150
|
-
export type DynamicViewRule = DynamicViewIncludeRule | ViewRuleStyle | ViewRuleAutoLayout
|
|
181
|
+
export type DynamicViewRule = DynamicViewIncludeRule | ViewRuleStyle | ViewRuleGlobalStyle | ViewRuleAutoLayout
|
|
151
182
|
export interface DynamicView<
|
|
152
183
|
ViewIDs extends string = string,
|
|
153
184
|
Tags extends string = string
|
|
@@ -247,6 +278,14 @@ export interface ComputedNode {
|
|
|
247
278
|
*/
|
|
248
279
|
isCustomized?: boolean
|
|
249
280
|
}
|
|
281
|
+
export namespace ComputedNode {
|
|
282
|
+
/**
|
|
283
|
+
* Nodes group is a special kind of node, exisiting only in view
|
|
284
|
+
*/
|
|
285
|
+
export function isNodesGroup(node: ComputedNode): boolean {
|
|
286
|
+
return node.kind === ElementKind.Group
|
|
287
|
+
}
|
|
288
|
+
}
|
|
250
289
|
|
|
251
290
|
export interface ComputedEdge {
|
|
252
291
|
id: EdgeId
|
|
@@ -360,6 +399,15 @@ export interface DiagramNode extends ComputedNode {
|
|
|
360
399
|
labelBBox: BBox
|
|
361
400
|
}
|
|
362
401
|
|
|
402
|
+
export namespace DiagramNode {
|
|
403
|
+
/**
|
|
404
|
+
* Nodes group is a special kind of node, exisiting only in view
|
|
405
|
+
*/
|
|
406
|
+
export function isNodesGroup(node: DiagramNode): boolean {
|
|
407
|
+
return node.kind === ElementKind.Group
|
|
408
|
+
}
|
|
409
|
+
}
|
|
410
|
+
|
|
363
411
|
export interface DiagramEdge extends ComputedEdge {
|
|
364
412
|
// Bezier points
|
|
365
413
|
points: NonEmptyArray<Point>
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import { map, pipe, takeWhile, zip } from 'remeda'
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Common head of two arrays
|
|
5
|
+
*/
|
|
6
|
+
export function commonHead<T>(
|
|
7
|
+
sources: ReadonlyArray<T>,
|
|
8
|
+
targets: ReadonlyArray<T>,
|
|
9
|
+
equals?: (a: T, b: T) => boolean
|
|
10
|
+
): T[] {
|
|
11
|
+
if (sources.length === 0 || targets.length === 0) {
|
|
12
|
+
return []
|
|
13
|
+
}
|
|
14
|
+
equals ??= Object.is
|
|
15
|
+
return pipe(
|
|
16
|
+
zip(sources, targets),
|
|
17
|
+
takeWhile(([source, target]) => equals(source, target)),
|
|
18
|
+
map(([source, _]) => source)
|
|
19
|
+
)
|
|
20
|
+
}
|
package/src/utils/index.ts
CHANGED