@alphacifer/slidev-addon-theme 0.0.8 → 0.0.9

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/README.md +80 -0
  2. package/components/pyramid/circular-pyramid/CircularPyramid.vue +871 -0
  3. package/components/pyramid/circular-pyramid/CircularPyramidStack.vue +375 -0
  4. package/components/pyramid/circular-pyramid/CircularPyramidStackContent.vue +208 -0
  5. package/components/pyramid/circular-pyramid/CircularPyramidStackTitle.vue +138 -0
  6. package/components/pyramid/square-pyramid/SquarePyramid.vue +876 -0
  7. package/components/pyramid/square-pyramid/SquarePyramidStack.vue +366 -0
  8. package/components/pyramid/square-pyramid/SquarePyramidStackContent.vue +204 -0
  9. package/components/pyramid/square-pyramid/SquarePyramidStackTitle.vue +134 -0
  10. package/package.json +2 -1
  11. package/utils/pyramid/circular-pyramid/context.ts +46 -0
  12. package/utils/pyramid/circular-pyramid/createCircularPyramidGeometry.ts +143 -0
  13. package/utils/pyramid/circular-pyramid/index.ts +3 -0
  14. package/utils/pyramid/circular-pyramid/types.ts +34 -0
  15. package/utils/pyramid/index.ts +3 -0
  16. package/utils/pyramid/shared/colors.ts +92 -0
  17. package/utils/pyramid/shared/connector.ts +111 -0
  18. package/utils/pyramid/shared/constants.ts +8 -0
  19. package/utils/pyramid/shared/index.ts +5 -0
  20. package/utils/pyramid/shared/stacking.ts +76 -0
  21. package/utils/pyramid/shared/types.ts +36 -0
  22. package/utils/pyramid/square-pyramid/context.ts +46 -0
  23. package/utils/pyramid/square-pyramid/createSquarePyramidGeometry.ts +265 -0
  24. package/utils/pyramid/square-pyramid/index.ts +3 -0
  25. package/utils/pyramid/square-pyramid/types.ts +39 -0
  26. package/utils/useDiagramAutoScale.ts +6 -8
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@alphacifer/slidev-addon-theme",
3
- "version": "0.0.8",
3
+ "version": "0.0.9",
4
4
  "description": "All Slidev addons for Alpha presentations",
5
5
  "type": "module",
6
6
  "keywords": [
@@ -39,6 +39,7 @@
39
39
  "vue": "3.5.40"
40
40
  },
41
41
  "scripts": {
42
+ "test": "vitest run --coverage",
42
43
  "dev": "slidev slides.md --open",
43
44
  "dev:academic": "slidev academic-slides.md --open",
44
45
  "preview:build": "slidev build slides.md"
@@ -0,0 +1,46 @@
1
+ import type { ComputedRef, InjectionKey, Ref } from 'vue';
2
+
3
+ import type { IPyramidPalette, IPyramidRegistration } from '../shared';
4
+ import type { ICircularLayerGeometry, ICircularPyramidGeometry } from './types';
5
+
6
+ export interface ICircularPyramidRegistration extends IPyramidRegistration {}
7
+
8
+ export interface ICircularPyramidRootContext {
9
+ readonly count: ComputedRef<number>;
10
+ readonly activeIndex: Ref<number> | ComputedRef<number>;
11
+ readonly color: ComputedRef<string>;
12
+ readonly geo: ComputedRef<ICircularPyramidGeometry>;
13
+ readonly palette: ComputedRef<IPyramidPalette>;
14
+ readonly animation: ComputedRef<boolean>;
15
+ readonly interactive: ComputedRef<boolean>;
16
+ readonly titleWidthPx: ComputedRef<number>;
17
+ readonly contentWidthPx: ComputedRef<number>;
18
+ readonly contentRightOffsetPx: ComputedRef<number>;
19
+ readonly registerStack: (
20
+ id?: symbol,
21
+ color?: ComputedRef<string | undefined>,
22
+ ) => {
23
+ index: ComputedRef<number>;
24
+ unregister: () => void;
25
+ };
26
+ readonly getLayerColor: (index: number) => string;
27
+ readonly setActiveIndex: (index: number) => void;
28
+ readonly getCardDeltaY?: (index: number) => number;
29
+ }
30
+
31
+ export interface ICircularPyramidStackContext {
32
+ readonly index: ComputedRef<number>;
33
+ readonly isActive: ComputedRef<boolean>;
34
+ readonly step: ComputedRef<string | number>;
35
+ readonly color?: ComputedRef<string>;
36
+ readonly layerGeo?: ComputedRef<ICircularLayerGeometry | undefined>;
37
+ readonly deltaY?: ComputedRef<number>;
38
+ readonly connectorWidth?: ComputedRef<number>;
39
+ readonly setActive?: () => void;
40
+ }
41
+
42
+ export const CIRCULAR_PYRAMID_ROOT_KEY: InjectionKey<ICircularPyramidRootContext> =
43
+ Symbol('CIRCULAR_PYRAMID_ROOT_KEY');
44
+
45
+ export const CIRCULAR_PYRAMID_STACK_KEY: InjectionKey<ICircularPyramidStackContext> =
46
+ Symbol('CIRCULAR_PYRAMID_STACK_KEY');
@@ -0,0 +1,143 @@
1
+ import {
2
+ clampPyramidCount,
3
+ computePyramidStacking,
4
+ DEFAULT_PYRAMID_COLOR,
5
+ darkenColor,
6
+ lightenColor,
7
+ MAX_PYRAMID_COUNT,
8
+ MIN_PYRAMID_COUNT,
9
+ resolvePyramidPalette,
10
+ } from '../shared';
11
+ import type {
12
+ ICircularLayerGeometry,
13
+ ICircularPyramidGeometry,
14
+ ICircularPyramidPalette,
15
+ ICreateCircularPyramidOptions,
16
+ } from './types';
17
+
18
+ export const DEFAULT_CIRCULAR_PYRAMID_COLOR = DEFAULT_PYRAMID_COLOR;
19
+ export const DEFAULT_CIRCULAR_PYRAMID_STACK_COLORS: readonly string[] = [
20
+ '#3b82f6', // 0: Blue
21
+ '#6366f1', // 1: Indigo
22
+ '#10b981', // 2: Emerald
23
+ '#f59e0b', // 3: Amber
24
+ '#ec4899', // 4: Pink
25
+ '#06b6d4', // 5: Cyan
26
+ ] as const;
27
+
28
+ export const MIN_CIRCULAR_COUNT = MIN_PYRAMID_COUNT;
29
+ export const MAX_CIRCULAR_COUNT = MAX_PYRAMID_COUNT;
30
+
31
+ export { darkenColor, lightenColor };
32
+
33
+ export function clampCircularCount(count?: number): number {
34
+ return clampPyramidCount(count);
35
+ }
36
+
37
+ export function resolveCircularPyramidPalette(
38
+ baseColor: string = DEFAULT_CIRCULAR_PYRAMID_COLOR,
39
+ ): ICircularPyramidPalette {
40
+ return resolvePyramidPalette(baseColor);
41
+ }
42
+
43
+ export function createCircularPyramidGeometry(
44
+ options: ICreateCircularPyramidOptions = {},
45
+ ): ICircularPyramidGeometry {
46
+ const viewBoxWidth = options.viewBoxWidth ?? 960;
47
+ const viewBoxHeight = options.viewBoxHeight ?? 440;
48
+ const count = clampCircularCount(options.count);
49
+ const ratio = options.ratio ?? 0.45;
50
+
51
+ const cx = options.cx ?? viewBoxWidth / 2;
52
+ const cylinderHeight = options.cylinderHeight ?? (count >= 5 ? 7 : 8);
53
+
54
+ if (count === 1) {
55
+ const rx = options.topRadius ?? 120;
56
+ const ry = Number((rx * ratio).toFixed(2));
57
+ const cy = Number((viewBoxHeight / 2 - cylinderHeight / 2).toFixed(2));
58
+
59
+ const topEllipsePath = `M ${cx - rx} ${cy} a ${rx} ${ry} 0 1 0 ${rx * 2} 0 a ${rx} ${ry} 0 1 0 ${-rx * 2} 0`;
60
+ const cylinderPath = `M ${cx - rx} ${cy} L ${cx - rx} ${cy + cylinderHeight} A ${rx} ${ry} 0 0 0 ${cx + rx} ${cy + cylinderHeight} L ${cx + rx} ${cy} A ${rx} ${ry} 0 0 1 ${cx - rx} ${cy} Z`;
61
+ const bottomArcPath = `M ${cx - rx} ${cy + cylinderHeight} A ${rx} ${ry} 0 0 0 ${cx + rx} ${cy + cylinderHeight}`;
62
+
63
+ const slabCenterY = Number((cy + cylinderHeight / 2).toFixed(2));
64
+
65
+ return {
66
+ viewBoxWidth,
67
+ viewBoxHeight,
68
+ count: 1,
69
+ layers: [
70
+ {
71
+ index: 0,
72
+ cx,
73
+ cy,
74
+ rx,
75
+ ry,
76
+ cylinderHeight,
77
+ cylinderPath,
78
+ bottomArcPath,
79
+ topEllipsePath,
80
+ slabCenterY,
81
+ },
82
+ ],
83
+ };
84
+ }
85
+
86
+ const topRadius =
87
+ options.topRadius ??
88
+ (count <= 2 ? 120 : Math.max(80, 115 - (count - 3) * 8));
89
+ const bottomRadius = options.bottomRadius ?? 215;
90
+
91
+ const radii: { rx: number; ry: number }[] = [];
92
+ for (let i = 0; i < count; i++) {
93
+ const t = i / (count - 1);
94
+ const rx = Number((topRadius + t * (bottomRadius - topRadius)).toFixed(2));
95
+ const ry = Number((rx * ratio).toFixed(2));
96
+ radii.push({ rx, ry });
97
+ }
98
+
99
+ const { startCy, stepYList } = computePyramidStacking({
100
+ count,
101
+ viewBoxHeight,
102
+ slabHeight: cylinderHeight,
103
+ radii,
104
+ });
105
+
106
+ const layers: ICircularLayerGeometry[] = [];
107
+ let currentCy = startCy;
108
+
109
+ for (let i = 0; i < count; i++) {
110
+ const rx = radii[i]?.rx ?? topRadius;
111
+ const ry = radii[i]?.ry ?? topRadius * ratio;
112
+ const cy = Number(currentCy.toFixed(2));
113
+
114
+ const topEllipsePath = `M ${cx - rx} ${cy} a ${rx} ${ry} 0 1 0 ${rx * 2} 0 a ${rx} ${ry} 0 1 0 ${-rx * 2} 0`;
115
+ const cylinderPath = `M ${cx - rx} ${cy} L ${cx - rx} ${cy + cylinderHeight} A ${rx} ${ry} 0 0 0 ${cx + rx} ${cy + cylinderHeight} L ${cx + rx} ${cy} A ${rx} ${ry} 0 0 1 ${cx - rx} ${cy} Z`;
116
+ const bottomArcPath = `M ${cx - rx} ${cy + cylinderHeight} A ${rx} ${ry} 0 0 0 ${cx + rx} ${cy + cylinderHeight}`;
117
+ const slabCenterY = Number((cy + cylinderHeight / 2).toFixed(2));
118
+
119
+ layers.push({
120
+ index: i,
121
+ cx,
122
+ cy,
123
+ rx,
124
+ ry,
125
+ cylinderHeight,
126
+ cylinderPath,
127
+ bottomArcPath,
128
+ topEllipsePath,
129
+ slabCenterY,
130
+ });
131
+
132
+ if (i < count - 1) {
133
+ currentCy += stepYList[i] ?? 0;
134
+ }
135
+ }
136
+
137
+ return {
138
+ viewBoxWidth,
139
+ viewBoxHeight,
140
+ count,
141
+ layers,
142
+ };
143
+ }
@@ -0,0 +1,3 @@
1
+ export * from './context';
2
+ export * from './createCircularPyramidGeometry';
3
+ export * from './types';
@@ -0,0 +1,34 @@
1
+ import type { IPyramidPalette } from '../shared';
2
+
3
+ export interface ICircularLayerGeometry {
4
+ readonly index: number;
5
+ readonly cx: number;
6
+ readonly cy: number;
7
+ readonly rx: number;
8
+ readonly ry: number;
9
+ readonly cylinderHeight: number;
10
+ readonly cylinderPath: string;
11
+ readonly bottomArcPath: string;
12
+ readonly topEllipsePath: string;
13
+ readonly slabCenterY?: number;
14
+ }
15
+
16
+ export interface ICircularPyramidGeometry {
17
+ readonly viewBoxWidth: number;
18
+ readonly viewBoxHeight: number;
19
+ readonly count: number;
20
+ readonly layers: readonly ICircularLayerGeometry[];
21
+ }
22
+
23
+ export interface ICreateCircularPyramidOptions {
24
+ readonly count?: number;
25
+ readonly viewBoxWidth?: number;
26
+ readonly viewBoxHeight?: number;
27
+ readonly topRadius?: number;
28
+ readonly bottomRadius?: number;
29
+ readonly cylinderHeight?: number;
30
+ readonly ratio?: number;
31
+ readonly cx?: number;
32
+ }
33
+
34
+ export interface ICircularPyramidPalette extends IPyramidPalette {}
@@ -0,0 +1,3 @@
1
+ export * from './circular-pyramid';
2
+ export * from './shared';
3
+ export * from './square-pyramid';
@@ -0,0 +1,92 @@
1
+ import { DEFAULT_PYRAMID_COLOR } from './constants';
2
+ import type { IColorModifierParams, IPyramidPalette } from './types';
3
+
4
+ export function lightenColor({
5
+ hex,
6
+ ratio = 0.5,
7
+ }: IColorModifierParams): string {
8
+ const raw = hex.trim().replace(/^#/, '');
9
+ const sanitized =
10
+ raw.length === 3
11
+ ? raw
12
+ .split('')
13
+ .map((char) => char + char)
14
+ .join('')
15
+ : raw;
16
+
17
+ if (sanitized.length !== 6) {
18
+ return hex;
19
+ }
20
+
21
+ const r = Number.parseInt(sanitized.slice(0, 2), 16);
22
+ const g = Number.parseInt(sanitized.slice(2, 4), 16);
23
+ const b = Number.parseInt(sanitized.slice(4, 6), 16);
24
+
25
+ if (Number.isNaN(r) || Number.isNaN(g) || Number.isNaN(b)) {
26
+ return hex;
27
+ }
28
+
29
+ const clamp = (val: number): number =>
30
+ Math.min(255, Math.max(0, Math.round(val)));
31
+ const lr = clamp(r + (255 - r) * ratio);
32
+ const lg = clamp(g + (255 - g) * ratio);
33
+ const lb = clamp(b + (255 - b) * ratio);
34
+
35
+ const toHex = (n: number): string => n.toString(16).padStart(2, '0');
36
+
37
+ return `#${toHex(lr)}${toHex(lg)}${toHex(lb)}`;
38
+ }
39
+
40
+ export function darkenColor({
41
+ hex,
42
+ ratio = 0.5,
43
+ }: IColorModifierParams): string {
44
+ const raw = hex.trim().replace(/^#/, '');
45
+ const sanitized =
46
+ raw.length === 3
47
+ ? raw
48
+ .split('')
49
+ .map((char) => char + char)
50
+ .join('')
51
+ : raw;
52
+
53
+ if (sanitized.length !== 6) {
54
+ return hex;
55
+ }
56
+
57
+ const r = Number.parseInt(sanitized.slice(0, 2), 16);
58
+ const g = Number.parseInt(sanitized.slice(2, 4), 16);
59
+ const b = Number.parseInt(sanitized.slice(4, 6), 16);
60
+
61
+ if (Number.isNaN(r) || Number.isNaN(g) || Number.isNaN(b)) {
62
+ return hex;
63
+ }
64
+
65
+ const clamp = (val: number): number =>
66
+ Math.min(255, Math.max(0, Math.round(val)));
67
+ const dr = clamp(r * (1 - ratio));
68
+ const dg = clamp(g * (1 - ratio));
69
+ const db = clamp(b * (1 - ratio));
70
+
71
+ const toHex = (n: number): string => n.toString(16).padStart(2, '0');
72
+
73
+ return `#${toHex(dr)}${toHex(dg)}${toHex(db)}`;
74
+ }
75
+
76
+ export function resolvePyramidPalette(
77
+ baseColor: string = DEFAULT_PYRAMID_COLOR,
78
+ ): IPyramidPalette {
79
+ return {
80
+ activeTopStart: lightenColor({ hex: baseColor, ratio: 0.82 }),
81
+ activeTopEnd: baseColor,
82
+ activeSideStart: darkenColor({ hex: baseColor, ratio: 0.28 }),
83
+ activeSideEnd: lightenColor({ hex: baseColor, ratio: 0.35 }),
84
+ activeStroke: lightenColor({ hex: baseColor, ratio: 0.7 }),
85
+ defaultTopStart: '#ffffff',
86
+ defaultTopEnd: lightenColor({ hex: baseColor, ratio: 0.88 }),
87
+ defaultSideStart: lightenColor({ hex: baseColor, ratio: 0.72 }),
88
+ defaultSideEnd: lightenColor({ hex: baseColor, ratio: 0.88 }),
89
+ defaultStroke: '#ffffff',
90
+ glow: baseColor,
91
+ };
92
+ }
@@ -0,0 +1,111 @@
1
+ export interface IPyramidConnectorPoint {
2
+ readonly x: number;
3
+ readonly y: number;
4
+ }
5
+
6
+ export function createPyramidConnectorPath(
7
+ start: IPyramidConnectorPoint,
8
+ end: IPyramidConnectorPoint,
9
+ ): string {
10
+ const startX = Number(start.x.toFixed(2));
11
+ const startY = Number(start.y.toFixed(2));
12
+ const endX = Number(end.x.toFixed(2));
13
+ const endY = Number(end.y.toFixed(2));
14
+
15
+ // If startY and endY are virtually aligned, return straight line
16
+ if (Math.abs(startY - endY) < 1) {
17
+ return `M ${startX} ${startY} L ${endX} ${endY}`;
18
+ }
19
+
20
+ const width = Math.max(0, endX - startX);
21
+ // Initial horizontal stub leaving the disc dot
22
+ const stubWidth = Math.min(14, width * 0.2);
23
+ const x1 = Number((startX + stubWidth).toFixed(2));
24
+
25
+ // Ramp/elbow transition to target card elevation
26
+ const rampWidth = Math.min(28, Math.max(14, (width - stubWidth) * 0.45));
27
+ const x2 = Number((x1 + rampWidth).toFixed(2));
28
+
29
+ // Connect: (startX, startY) -> (x1, startY) -> (x2, endY) -> (endX, endY)
30
+ return `M ${startX} ${startY} L ${x1} ${startY} L ${x2} ${endY} L ${endX} ${endY}`;
31
+ }
32
+
33
+ export interface IResolvePyramidCardPositionsParams {
34
+ readonly targetYList: readonly number[];
35
+ readonly heights: readonly number[];
36
+ readonly gap?: number;
37
+ readonly minY?: number;
38
+ readonly maxY?: number;
39
+ }
40
+
41
+ export function resolvePyramidCardPositions(
42
+ params: IResolvePyramidCardPositionsParams,
43
+ ): number[] {
44
+ const { targetYList, heights, gap = 10, minY = 16, maxY = 464 } = params;
45
+ const count = targetYList.length;
46
+ if (count <= 1) {
47
+ return [...targetYList];
48
+ }
49
+
50
+ const yList: number[] = [...targetYList];
51
+
52
+ // 1. Forward pass: push down any overlapping cards
53
+ for (let i = 0; i < count - 1; i++) {
54
+ const curY = yList[i] ?? 0;
55
+ const nextY = yList[i + 1] ?? 0;
56
+ const curH = heights[i] ?? 48;
57
+ const nextH = heights[i + 1] ?? 48;
58
+ const minCenterNext = curY + curH / 2 + nextH / 2 + gap;
59
+ if (nextY < minCenterNext) {
60
+ yList[i + 1] = minCenterNext;
61
+ }
62
+ }
63
+
64
+ // 2. Center the shift by redistributing excess displacement
65
+ const avgShift =
66
+ yList.reduce((sum, y, i) => sum + (y - (targetYList[i] ?? y)), 0) / count;
67
+ const firstY = yList[0] ?? 0;
68
+ const firstH = heights[0] ?? 48;
69
+ const maxAllowableUpShift = firstY - firstH / 2 - minY;
70
+ const shiftUp = Math.max(0, Math.min(avgShift, maxAllowableUpShift));
71
+ for (let i = 0; i < count; i++) {
72
+ yList[i] = (yList[i] ?? 0) - shiftUp;
73
+ }
74
+
75
+ // 3. Backward pass from bottom boundary
76
+ const lastY = yList[count - 1] ?? 0;
77
+ const lastH = heights[count - 1] ?? 48;
78
+ const bottomOverlap = lastY + lastH / 2 - maxY;
79
+ if (bottomOverlap > 0) {
80
+ yList[count - 1] = lastY - bottomOverlap;
81
+ for (let i = count - 2; i >= 0; i--) {
82
+ const curY = yList[i] ?? 0;
83
+ const nextY = yList[i + 1] ?? 0;
84
+ const curH = heights[i] ?? 48;
85
+ const nextH = heights[i + 1] ?? 48;
86
+ const maxCenterPrev = nextY - nextH / 2 - curH / 2 - gap;
87
+ if (curY > maxCenterPrev) {
88
+ yList[i] = maxCenterPrev;
89
+ }
90
+ }
91
+ }
92
+
93
+ // 4. Final top boundary safety
94
+ const updatedFirstY = yList[0] ?? 0;
95
+ const topOverlap = minY - (updatedFirstY - firstH / 2);
96
+ if (topOverlap > 0) {
97
+ yList[0] = updatedFirstY + topOverlap;
98
+ for (let i = 0; i < count - 1; i++) {
99
+ const curY = yList[i] ?? 0;
100
+ const nextY = yList[i + 1] ?? 0;
101
+ const curH = heights[i] ?? 48;
102
+ const nextH = heights[i + 1] ?? 48;
103
+ const minCenterNext = curY + curH / 2 + nextH / 2 + gap;
104
+ if (nextY < minCenterNext) {
105
+ yList[i + 1] = minCenterNext;
106
+ }
107
+ }
108
+ }
109
+
110
+ return yList.map((y) => Number(y.toFixed(2)));
111
+ }
@@ -0,0 +1,8 @@
1
+ export const DEFAULT_PYRAMID_COLOR = '#3b82f6';
2
+ export const MIN_PYRAMID_COUNT = 1;
3
+ export const MAX_PYRAMID_COUNT = 6;
4
+
5
+ export const PYRAMID_TITLE_WIDTH_PX = 150;
6
+ export const PYRAMID_CONTENT_WIDTH_PX = 240;
7
+ export const PYRAMID_CONTENT_RIGHT_OFFSET_PX = 0;
8
+ export const PYRAMID_DOT_POSITION_X = 210;
@@ -0,0 +1,5 @@
1
+ export * from './colors';
2
+ export * from './connector';
3
+ export * from './constants';
4
+ export * from './stacking';
5
+ export * from './types';
@@ -0,0 +1,76 @@
1
+ import { MAX_PYRAMID_COUNT, MIN_PYRAMID_COUNT } from './constants';
2
+ import type {
3
+ IComputePyramidStackingParams,
4
+ IPyramidStackingResult,
5
+ } from './types';
6
+
7
+ export function clampPyramidCount(count?: number): number {
8
+ if (count === undefined || Number.isNaN(count)) {
9
+ return 4;
10
+ }
11
+
12
+ return Math.min(
13
+ MAX_PYRAMID_COUNT,
14
+ Math.max(MIN_PYRAMID_COUNT, Math.round(count)),
15
+ );
16
+ }
17
+
18
+ export function computePyramidStacking({
19
+ count,
20
+ viewBoxHeight,
21
+ slabHeight,
22
+ radii,
23
+ }: IComputePyramidStackingParams): IPyramidStackingResult {
24
+ let sumAdjacentRy = 0;
25
+ for (let i = 0; i < count - 1; i++) {
26
+ const rCurrent = radii[i]?.ry ?? 0;
27
+ const rNext = radii[i + 1]?.ry ?? 0;
28
+ sumAdjacentRy += rCurrent + rNext;
29
+ }
30
+
31
+ const firstRy = radii[0]?.ry ?? 0;
32
+ const lastRy = radii[count - 1]?.ry ?? 0;
33
+
34
+ const baseOverlap =
35
+ count <= 2
36
+ ? 0.24
37
+ : count === 3
38
+ ? 0.26
39
+ : count === 4
40
+ ? 0.28
41
+ : count === 5
42
+ ? 0.34
43
+ : 0.38;
44
+
45
+ const maxAllowedHeight = viewBoxHeight - 60;
46
+ const naturalHeight =
47
+ firstRy + lastRy + count * slabHeight + (1 - baseOverlap) * sumAdjacentRy;
48
+
49
+ const effectiveOverlap =
50
+ naturalHeight > maxAllowedHeight && sumAdjacentRy > 0
51
+ ? 1 -
52
+ (maxAllowedHeight - firstRy - lastRy - count * slabHeight) /
53
+ sumAdjacentRy
54
+ : baseOverlap;
55
+
56
+ const stepYList: number[] = [];
57
+ let totalStepY = 0;
58
+ for (let i = 0; i < count - 1; i++) {
59
+ const rCurrent = radii[i]?.ry ?? 0;
60
+ const rNext = radii[i + 1]?.ry ?? 0;
61
+ const step = (rCurrent + rNext) * (1 - effectiveOverlap) + slabHeight;
62
+ stepYList.push(step);
63
+ totalStepY += step;
64
+ }
65
+
66
+ const actualTotalHeight = firstRy + totalStepY + slabHeight + lastRy;
67
+ const startCy = Number(
68
+ (viewBoxHeight / 2 - actualTotalHeight / 2 + firstRy).toFixed(2),
69
+ );
70
+
71
+ return {
72
+ startCy,
73
+ stepYList,
74
+ actualTotalHeight,
75
+ };
76
+ }
@@ -0,0 +1,36 @@
1
+ export interface IColorModifierParams {
2
+ readonly hex: string;
3
+ readonly ratio?: number;
4
+ }
5
+
6
+ export interface IPyramidPalette {
7
+ readonly activeTopStart: string;
8
+ readonly activeTopEnd: string;
9
+ readonly activeSideStart: string;
10
+ readonly activeSideEnd: string;
11
+ readonly activeStroke: string;
12
+ readonly defaultTopStart: string;
13
+ readonly defaultTopEnd: string;
14
+ readonly defaultSideStart: string;
15
+ readonly defaultSideEnd: string;
16
+ readonly defaultStroke: string;
17
+ readonly glow: string;
18
+ }
19
+
20
+ export interface IPyramidRegistration {
21
+ readonly index: number;
22
+ readonly unregister: () => void;
23
+ }
24
+
25
+ export interface IComputePyramidStackingParams {
26
+ readonly count: number;
27
+ readonly viewBoxHeight: number;
28
+ readonly slabHeight: number;
29
+ readonly radii: readonly { readonly rx: number; readonly ry: number }[];
30
+ }
31
+
32
+ export interface IPyramidStackingResult {
33
+ readonly startCy: number;
34
+ readonly stepYList: readonly number[];
35
+ readonly actualTotalHeight: number;
36
+ }
@@ -0,0 +1,46 @@
1
+ import type { ComputedRef, InjectionKey, Ref } from 'vue';
2
+
3
+ import type { IPyramidPalette, IPyramidRegistration } from '../shared';
4
+ import type { ISquareLayerGeometry, ISquarePyramidGeometry } from './types';
5
+
6
+ export interface ISquarePyramidRegistration extends IPyramidRegistration {}
7
+
8
+ export interface ISquarePyramidRootContext {
9
+ readonly count: ComputedRef<number>;
10
+ readonly activeIndex: Ref<number> | ComputedRef<number>;
11
+ readonly color: ComputedRef<string>;
12
+ readonly geo: ComputedRef<ISquarePyramidGeometry>;
13
+ readonly palette: ComputedRef<IPyramidPalette>;
14
+ readonly animation: ComputedRef<boolean>;
15
+ readonly interactive: ComputedRef<boolean>;
16
+ readonly titleWidthPx: ComputedRef<number>;
17
+ readonly contentWidthPx: ComputedRef<number>;
18
+ readonly contentRightOffsetPx: ComputedRef<number>;
19
+ readonly registerStack: (
20
+ id?: symbol,
21
+ color?: ComputedRef<string | undefined>,
22
+ ) => {
23
+ index: ComputedRef<number>;
24
+ unregister: () => void;
25
+ };
26
+ readonly getLayerColor: (index: number) => string;
27
+ readonly setActiveIndex: (index: number) => void;
28
+ readonly getCardDeltaY?: (index: number) => number;
29
+ }
30
+
31
+ export interface ISquarePyramidStackContext {
32
+ readonly index: ComputedRef<number>;
33
+ readonly isActive: ComputedRef<boolean>;
34
+ readonly step: ComputedRef<string | number>;
35
+ readonly color?: ComputedRef<string>;
36
+ readonly layerGeo?: ComputedRef<ISquareLayerGeometry | undefined>;
37
+ readonly deltaY?: ComputedRef<number>;
38
+ readonly connectorWidth?: ComputedRef<number>;
39
+ readonly setActive?: () => void;
40
+ }
41
+
42
+ export const SQUARE_PYRAMID_ROOT_KEY: InjectionKey<ISquarePyramidRootContext> =
43
+ Symbol('SQUARE_PYRAMID_ROOT_KEY');
44
+
45
+ export const SQUARE_PYRAMID_STACK_KEY: InjectionKey<ISquarePyramidStackContext> =
46
+ Symbol('SQUARE_PYRAMID_STACK_KEY');