@alphacifer/slidev-addon-theme 0.0.9 → 0.0.10

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 (26) hide show
  1. package/components/defense-in-depth/arc-did/ArcDiD.vue +732 -0
  2. package/components/defense-in-depth/arc-did/ArcDiDLayer.vue +321 -0
  3. package/components/defense-in-depth/arc-did/ArcDiDLayerPart.vue +449 -0
  4. package/components/defense-in-depth/arc-did/ArcDiDLayerParts.vue +11 -0
  5. package/components/defense-in-depth/arc-did/ArcDiDLayerSector.vue +148 -0
  6. package/components/defense-in-depth/arc-did/ArcDiDLayerTitle.vue +98 -0
  7. package/components/pyramid/circular-pyramid/CircularPyramid.vue +10 -23
  8. package/components/pyramid/circular-pyramid/CircularPyramidStack.vue +17 -50
  9. package/components/pyramid/circular-pyramid/CircularPyramidStackContent.vue +98 -1
  10. package/components/pyramid/circular-pyramid/CircularPyramidStackTitle.vue +70 -0
  11. package/components/pyramid/square-pyramid/SquarePyramid.vue +10 -23
  12. package/components/pyramid/square-pyramid/SquarePyramidStack.vue +17 -50
  13. package/components/pyramid/square-pyramid/SquarePyramidStackContent.vue +98 -1
  14. package/components/pyramid/square-pyramid/SquarePyramidStackTitle.vue +70 -0
  15. package/package.json +1 -1
  16. package/utils/defenseInDepth/arcDid/context.ts +110 -0
  17. package/utils/defenseInDepth/arcDid/createArcDiDGeometry.ts +570 -0
  18. package/utils/defenseInDepth/arcDid/index.ts +3 -0
  19. package/utils/defenseInDepth/arcDid/types.ts +140 -0
  20. package/utils/defenseInDepth/index.ts +2 -0
  21. package/utils/defenseInDepth/shared/colors.ts +121 -0
  22. package/utils/defenseInDepth/shared/constants.ts +14 -0
  23. package/utils/defenseInDepth/shared/index.ts +3 -0
  24. package/utils/defenseInDepth/shared/types.ts +12 -0
  25. package/utils/pyramid/shared/constants.ts +1 -0
  26. package/utils/useDiagramAutoScale.ts +61 -15
@@ -0,0 +1,121 @@
1
+ import {
2
+ DEFAULT_DID_COLOR,
3
+ DEFAULT_DID_DOT_COLOR,
4
+ DEFAULT_DID_DOT_GLOW_COLOR,
5
+ DEFAULT_DID_LAYER_COLORS,
6
+ } from './constants';
7
+ import type { IColorModifierParams, IDefenseInDepthPalette } from './types';
8
+
9
+ export function lightenColor({
10
+ hex,
11
+ ratio = 0.5,
12
+ }: IColorModifierParams): string {
13
+ const raw = hex.trim().replace(/^#/, '');
14
+ const sanitized =
15
+ raw.length === 3
16
+ ? raw
17
+ .split('')
18
+ .map((char) => char + char)
19
+ .join('')
20
+ : raw;
21
+
22
+ if (sanitized.length !== 6) {
23
+ return hex;
24
+ }
25
+
26
+ const r = Number.parseInt(sanitized.slice(0, 2), 16);
27
+ const g = Number.parseInt(sanitized.slice(2, 4), 16);
28
+ const b = Number.parseInt(sanitized.slice(4, 6), 16);
29
+
30
+ if (Number.isNaN(r) || Number.isNaN(g) || Number.isNaN(b)) {
31
+ return hex;
32
+ }
33
+
34
+ const clamp = (val: number): number =>
35
+ Math.min(255, Math.max(0, Math.round(val)));
36
+ const lr = clamp(r + (255 - r) * ratio);
37
+ const lg = clamp(g + (255 - g) * ratio);
38
+ const lb = clamp(b + (255 - b) * ratio);
39
+
40
+ const toHex = (n: number): string => n.toString(16).padStart(2, '0');
41
+
42
+ return `#${toHex(lr)}${toHex(lg)}${toHex(lb)}`;
43
+ }
44
+
45
+ export function darkenColor({
46
+ hex,
47
+ ratio = 0.5,
48
+ }: IColorModifierParams): string {
49
+ const raw = hex.trim().replace(/^#/, '');
50
+ const sanitized =
51
+ raw.length === 3
52
+ ? raw
53
+ .split('')
54
+ .map((char) => char + char)
55
+ .join('')
56
+ : raw;
57
+
58
+ if (sanitized.length !== 6) {
59
+ return hex;
60
+ }
61
+
62
+ const r = Number.parseInt(sanitized.slice(0, 2), 16);
63
+ const g = Number.parseInt(sanitized.slice(2, 4), 16);
64
+ const b = Number.parseInt(sanitized.slice(4, 6), 16);
65
+
66
+ if (Number.isNaN(r) || Number.isNaN(g) || Number.isNaN(b)) {
67
+ return hex;
68
+ }
69
+
70
+ const clamp = (val: number): number =>
71
+ Math.min(255, Math.max(0, Math.round(val)));
72
+ const dr = clamp(r * (1 - ratio));
73
+ const dg = clamp(g * (1 - ratio));
74
+ const db = clamp(b * (1 - ratio));
75
+
76
+ const toHex = (n: number): string => n.toString(16).padStart(2, '0');
77
+
78
+ return `#${toHex(dr)}${toHex(dg)}${toHex(db)}`;
79
+ }
80
+
81
+ export function resolveArcDiDPalette(
82
+ baseColor: string = DEFAULT_DID_COLOR,
83
+ count = 3,
84
+ ): IDefenseInDepthPalette {
85
+ if (baseColor === DEFAULT_DID_COLOR && count === 3) {
86
+ return {
87
+ layerColors: DEFAULT_DID_LAYER_COLORS,
88
+ dotColor: DEFAULT_DID_DOT_COLOR,
89
+ dotGlowColor: DEFAULT_DID_DOT_GLOW_COLOR,
90
+ strokeColor: '#ffffff',
91
+ decorativeStrokeColor: lightenColor({ hex: baseColor, ratio: 0.65 }),
92
+ };
93
+ }
94
+
95
+ const layerColors: string[] = [];
96
+ const safeCount = Math.max(1, count);
97
+
98
+ for (let i = 0; i < safeCount; i++) {
99
+ // 0 = outermost (lightest, ratio ~0.35), count - 1 = innermost (deepest, ratio ~0.25 darken)
100
+ if (safeCount === 1) {
101
+ layerColors.push(baseColor);
102
+ } else {
103
+ const t = i / (safeCount - 1);
104
+ if (t < 0.5) {
105
+ const lightenRatio = 0.35 * (1 - t * 2);
106
+ layerColors.push(lightenColor({ hex: baseColor, ratio: lightenRatio }));
107
+ } else {
108
+ const darkenRatio = 0.25 * ((t - 0.5) * 2);
109
+ layerColors.push(darkenColor({ hex: baseColor, ratio: darkenRatio }));
110
+ }
111
+ }
112
+ }
113
+
114
+ return {
115
+ layerColors,
116
+ dotColor: darkenColor({ hex: baseColor, ratio: 0.2 }),
117
+ dotGlowColor: lightenColor({ hex: baseColor, ratio: 0.7 }),
118
+ strokeColor: '#ffffff',
119
+ decorativeStrokeColor: lightenColor({ hex: baseColor, ratio: 0.65 }),
120
+ };
121
+ }
@@ -0,0 +1,14 @@
1
+ export const DEFAULT_DID_COLOR = '#0ea5e9';
2
+
3
+ export const DEFAULT_DID_OUTER_COLOR = '#38bdf8';
4
+ export const DEFAULT_DID_MIDDLE_COLOR = '#0ea5e9';
5
+ export const DEFAULT_DID_INNER_COLOR = '#0284c7';
6
+
7
+ export const DEFAULT_DID_LAYER_COLORS: readonly string[] = [
8
+ DEFAULT_DID_OUTER_COLOR,
9
+ DEFAULT_DID_MIDDLE_COLOR,
10
+ DEFAULT_DID_INNER_COLOR,
11
+ ];
12
+
13
+ export const DEFAULT_DID_DOT_COLOR = '#0284c7';
14
+ export const DEFAULT_DID_DOT_GLOW_COLOR = 'rgba(56, 189, 248, 0.35)';
@@ -0,0 +1,3 @@
1
+ export * from './colors';
2
+ export * from './constants';
3
+ export * from './types';
@@ -0,0 +1,12 @@
1
+ export interface IColorModifierParams {
2
+ readonly hex: string;
3
+ readonly ratio?: number;
4
+ }
5
+
6
+ export interface IDefenseInDepthPalette {
7
+ readonly layerColors: readonly string[];
8
+ readonly dotColor: string;
9
+ readonly dotGlowColor: string;
10
+ readonly strokeColor: string;
11
+ readonly decorativeStrokeColor: string;
12
+ }
@@ -6,3 +6,4 @@ export const PYRAMID_TITLE_WIDTH_PX = 150;
6
6
  export const PYRAMID_CONTENT_WIDTH_PX = 240;
7
7
  export const PYRAMID_CONTENT_RIGHT_OFFSET_PX = 0;
8
8
  export const PYRAMID_DOT_POSITION_X = 210;
9
+ export const PYRAMID_DOT_GAP_PX = 10;
@@ -14,6 +14,9 @@ export interface IUseDiagramAutoScaleOptions {
14
14
  readonly scale?: Ref<number | undefined> | (() => number | undefined);
15
15
  readonly autoScale?: Ref<boolean | undefined> | (() => boolean | undefined);
16
16
  readonly maxScale?: Ref<number | undefined> | (() => number | undefined);
17
+ readonly width?:
18
+ | Ref<number | string | undefined>
19
+ | (() => number | string | undefined);
17
20
  readonly height?:
18
21
  | Ref<number | string | undefined>
19
22
  | (() => number | string | undefined);
@@ -94,6 +97,19 @@ export function useDiagramAutoScale(
94
97
  availW = el.clientWidth;
95
98
  }
96
99
 
100
+ const explicitWidth = resolveValue(options.width, undefined);
101
+ if (typeof explicitWidth === 'number' && explicitWidth > 0) {
102
+ availW = availW > 0 ? Math.min(availW, explicitWidth) : explicitWidth;
103
+ } else if (
104
+ typeof explicitWidth === 'string' &&
105
+ explicitWidth.endsWith('px')
106
+ ) {
107
+ const parsedW = Number.parseFloat(explicitWidth);
108
+ if (parsedW > 0) {
109
+ availW = availW > 0 ? Math.min(availW, parsedW) : parsedW;
110
+ }
111
+ }
112
+
97
113
  // Available height inside parent or slide layout
98
114
  let availH = 0;
99
115
  const explicitHeight = resolveValue(options.height, undefined);
@@ -140,6 +156,25 @@ export function useDiagramAutoScale(
140
156
  pagyEl && window.getComputedStyle(pagyEl).display !== 'none';
141
157
  const clearance = isPagyVisible ? pagyClearance : 16;
142
158
 
159
+ // Check for internal component header inside el (e.g. ArcDiD, GearTriad, HexTriad)
160
+ let internalHeaderH = 0;
161
+ for (let i = 0; i < el.children.length; i++) {
162
+ const child = el.children[i];
163
+ if (
164
+ child instanceof HTMLElement &&
165
+ (child.tagName === 'HEADER' ||
166
+ child.classList.contains('alpha-arc-did__header') ||
167
+ child.classList.contains('alpha-gear-triad__header') ||
168
+ child.classList.contains('alpha-hex-triad__header'))
169
+ ) {
170
+ internalHeaderH += child.offsetHeight;
171
+ const cs = window.getComputedStyle(child);
172
+ internalHeaderH +=
173
+ (Number.parseFloat(cs.marginTop) || 0) +
174
+ (Number.parseFloat(cs.marginBottom) || 0);
175
+ }
176
+ }
177
+
143
178
  if (slideEl && slideEl.clientHeight > 0) {
144
179
  const slideStyle = window.getComputedStyle(slideEl);
145
180
  const sPadTop = Number.parseFloat(slideStyle.paddingTop) || 0;
@@ -148,21 +183,26 @@ export function useDiagramAutoScale(
148
183
  let slideSiblingsH = siblingsH;
149
184
 
150
185
  if (parent !== slideEl) {
151
- for (let i = 0; i < slideEl.children.length; i++) {
152
- const child = slideEl.children[i];
153
-
154
- if (
155
- child &&
156
- child !== parent &&
157
- !child.contains(parent) &&
158
- child instanceof HTMLElement
159
- ) {
160
- slideSiblingsH += child.offsetHeight;
161
- const cs = window.getComputedStyle(child);
162
- slideSiblingsH +=
163
- (Number.parseFloat(cs.marginTop) || 0) +
164
- (Number.parseFloat(cs.marginBottom) || 0);
186
+ let curr: HTMLElement | null = parent;
187
+ while (curr && curr !== slideEl && curr.parentElement) {
188
+ const p: HTMLElement = curr.parentElement;
189
+ for (let i = 0; i < p.children.length; i++) {
190
+ const child = p.children[i];
191
+ if (
192
+ child &&
193
+ child !== curr &&
194
+ !child.contains(curr) &&
195
+ child instanceof HTMLElement
196
+ ) {
197
+ slideSiblingsH += child.offsetHeight;
198
+ const cs = window.getComputedStyle(child);
199
+ slideSiblingsH +=
200
+ (Number.parseFloat(cs.marginTop) || 0) +
201
+ (Number.parseFloat(cs.marginBottom) || 0);
202
+ }
165
203
  }
204
+ if (p === slideEl) break;
205
+ curr = p;
166
206
  }
167
207
  }
168
208
 
@@ -172,12 +212,18 @@ export function useDiagramAutoScale(
172
212
  sPadTop -
173
213
  sPadBottom -
174
214
  slideSiblingsH -
215
+ internalHeaderH -
175
216
  clearance,
176
217
  );
177
218
  } else if (parent.clientHeight > 0) {
178
219
  availH = Math.max(
179
220
  0,
180
- parent.clientHeight - padTop - padBottom - siblingsH - clearance,
221
+ parent.clientHeight -
222
+ padTop -
223
+ padBottom -
224
+ siblingsH -
225
+ internalHeaderH -
226
+ clearance,
181
227
  );
182
228
  }
183
229
  }