@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
@@ -0,0 +1,265 @@
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
+ ICreateSquarePyramidOptions,
13
+ ISquareLayerGeometry,
14
+ ISquarePyramidGeometry,
15
+ ISquarePyramidPalette,
16
+ } from './types';
17
+
18
+ export const DEFAULT_SQUARE_PYRAMID_COLOR = DEFAULT_PYRAMID_COLOR;
19
+ export const DEFAULT_SQUARE_PYRAMID_STACK_COLORS: readonly string[] = [
20
+ '#ec4899', // 0: Pink (matches top slab)
21
+ '#8b5cf6', // 1: Purple (matches 2nd slab)
22
+ '#3b82f6', // 2: Blue (matches 3rd slab)
23
+ '#06b6d4', // 3: Cyan (matches 4th slab)
24
+ '#14b8a6', // 4: Teal (matches 5th slab)
25
+ '#f59e0b', // 5: Amber (warm accent)
26
+ ] as const;
27
+
28
+ export const MIN_SQUARE_COUNT = MIN_PYRAMID_COUNT;
29
+ export const MAX_SQUARE_COUNT = MAX_PYRAMID_COUNT;
30
+
31
+ export { darkenColor, lightenColor };
32
+
33
+ export function clampSquareCount(count?: number): number {
34
+ return clampPyramidCount(count);
35
+ }
36
+
37
+ export function resolveSquarePyramidPalette(
38
+ baseColor: string = DEFAULT_SQUARE_PYRAMID_COLOR,
39
+ ): ISquarePyramidPalette {
40
+ return resolvePyramidPalette(baseColor);
41
+ }
42
+
43
+ function buildSquarePaths({
44
+ cx,
45
+ cy,
46
+ rx,
47
+ ry,
48
+ dx,
49
+ dy,
50
+ slabHeight,
51
+ }: {
52
+ cx: number;
53
+ cy: number;
54
+ rx: number;
55
+ ry: number;
56
+ dx: number;
57
+ dy: number;
58
+ slabHeight: number;
59
+ }) {
60
+ const topFacePath = [
61
+ `M ${cx - dx} ${cy - ry + dy}`,
62
+ `Q ${cx} ${cy - ry} ${cx + dx} ${cy - ry + dy}`,
63
+ `L ${cx + rx - dx} ${cy - dy}`,
64
+ `Q ${cx + rx} ${cy} ${cx + rx - dx} ${cy + dy}`,
65
+ `L ${cx + dx} ${cy + ry - dy}`,
66
+ `Q ${cx} ${cy + ry} ${cx - dx} ${cy + ry - dy}`,
67
+ `L ${cx - rx + dx} ${cy + dy}`,
68
+ `Q ${cx - rx} ${cy} ${cx - rx + dx} ${cy - dy}`,
69
+ 'Z',
70
+ ].join(' ');
71
+
72
+ const innerRatio = 0.65;
73
+ const rxInner = Number((rx * innerRatio).toFixed(2));
74
+ const ryInner = Number((ry * innerRatio).toFixed(2));
75
+ const dxInner = Number((dx * innerRatio).toFixed(2));
76
+ const dyInner = Number((dy * innerRatio).toFixed(2));
77
+
78
+ const innerFacePath = [
79
+ `M ${cx - dxInner} ${cy - ryInner + dyInner}`,
80
+ `Q ${cx} ${cy - ryInner} ${cx + dxInner} ${cy - ryInner + dyInner}`,
81
+ `L ${cx + rxInner - dxInner} ${cy - dyInner}`,
82
+ `Q ${cx + rxInner} ${cy} ${cx + rxInner - dxInner} ${cy + dyInner}`,
83
+ `L ${cx + dxInner} ${cy + ryInner - dyInner}`,
84
+ `Q ${cx} ${cy + ryInner} ${cx - dxInner} ${cy + ryInner - dyInner}`,
85
+ `L ${cx - rxInner + dxInner} ${cy + dyInner}`,
86
+ `Q ${cx - rxInner} ${cy} ${cx - rxInner + dxInner} ${cy - dyInner}`,
87
+ 'Z',
88
+ ].join(' ');
89
+
90
+ const sidePath = [
91
+ `M ${cx - rx + 0.5 * dx} ${cy}`,
92
+ `Q ${cx - rx + 0.5 * dx} ${cy + 0.5 * dy} ${cx - rx + dx} ${cy + dy}`,
93
+ `L ${cx - dx} ${cy + ry - dy}`,
94
+ `Q ${cx} ${cy + ry} ${cx + dx} ${cy + ry - dy}`,
95
+ `L ${cx + rx - dx} ${cy + dy}`,
96
+ `Q ${cx + rx - 0.5 * dx} ${cy + 0.5 * dy} ${cx + rx - 0.5 * dx} ${cy}`,
97
+ `L ${cx + rx - 0.5 * dx} ${cy + slabHeight}`,
98
+ `Q ${cx + rx - 0.5 * dx} ${cy + slabHeight + 0.5 * dy} ${cx + rx - dx} ${cy + slabHeight + dy}`,
99
+ `L ${cx + dx} ${cy + ry + slabHeight - dy}`,
100
+ `Q ${cx} ${cy + ry + slabHeight} ${cx - dx} ${cy + ry + slabHeight - dy}`,
101
+ `L ${cx - rx + dx} ${cy + slabHeight + dy}`,
102
+ `Q ${cx - rx + 0.5 * dx} ${cy + slabHeight + 0.5 * dy} ${cx - rx + 0.5 * dx} ${cy + slabHeight}`,
103
+ 'Z',
104
+ ].join(' ');
105
+
106
+ const leftSidePath = [
107
+ `M ${cx - rx + 0.5 * dx} ${cy}`,
108
+ `Q ${cx - rx + 0.5 * dx} ${cy + 0.5 * dy} ${cx - rx + dx} ${cy + dy}`,
109
+ `L ${cx - dx} ${cy + ry - dy}`,
110
+ `Q ${cx} ${cy + ry} ${cx} ${cy + ry - 0.5 * dy}`,
111
+ `L ${cx} ${cy + ry + slabHeight - 0.5 * dy}`,
112
+ `Q ${cx} ${cy + ry + slabHeight} ${cx - dx} ${cy + ry + slabHeight - dy}`,
113
+ `L ${cx - rx + dx} ${cy + slabHeight + dy}`,
114
+ `Q ${cx - rx + 0.5 * dx} ${cy + slabHeight + 0.5 * dy} ${cx - rx + 0.5 * dx} ${cy + slabHeight}`,
115
+ 'Z',
116
+ ].join(' ');
117
+
118
+ const rightSidePath = [
119
+ `M ${cx} ${cy + ry - 0.5 * dy}`,
120
+ `Q ${cx} ${cy + ry} ${cx + dx} ${cy + ry - dy}`,
121
+ `L ${cx + rx - dx} ${cy + dy}`,
122
+ `Q ${cx + rx - 0.5 * dx} ${cy + 0.5 * dy} ${cx + rx - 0.5 * dx} ${cy}`,
123
+ `L ${cx + rx - 0.5 * dx} ${cy + slabHeight}`,
124
+ `Q ${cx + rx - 0.5 * dx} ${cy + slabHeight + 0.5 * dy} ${cx + rx - dx} ${cy + slabHeight + dy}`,
125
+ `L ${cx + dx} ${cy + ry + slabHeight - dy}`,
126
+ `Q ${cx} ${cy + ry + slabHeight} ${cx} ${cy + ry + slabHeight - 0.5 * dy}`,
127
+ 'Z',
128
+ ].join(' ');
129
+
130
+ const bottomEdgePath = [
131
+ `M ${cx - rx + 0.5 * dx} ${cy + slabHeight}`,
132
+ `Q ${cx - rx + 0.5 * dx} ${cy + slabHeight + 0.5 * dy} ${cx - rx + dx} ${cy + slabHeight + dy}`,
133
+ `L ${cx - dx} ${cy + ry + slabHeight - dy}`,
134
+ `Q ${cx} ${cy + ry + slabHeight} ${cx + dx} ${cy + ry + slabHeight - dy}`,
135
+ `L ${cx + rx - dx} ${cy + slabHeight + dy}`,
136
+ `Q ${cx + rx - 0.5 * dx} ${cy + slabHeight + 0.5 * dy} ${cx + rx - 0.5 * dx} ${cy + slabHeight}`,
137
+ ].join(' ');
138
+
139
+ return {
140
+ topFacePath,
141
+ innerFacePath,
142
+ sidePath,
143
+ leftSidePath,
144
+ rightSidePath,
145
+ bottomEdgePath,
146
+ };
147
+ }
148
+
149
+ export function createSquarePyramidGeometry(
150
+ options: ICreateSquarePyramidOptions = {},
151
+ ): ISquarePyramidGeometry {
152
+ const viewBoxWidth = options.viewBoxWidth ?? 960;
153
+ const viewBoxHeight = options.viewBoxHeight ?? 440;
154
+ const count = clampSquareCount(options.count);
155
+ const ratio = options.ratio ?? 0.46;
156
+ const cx = options.cx ?? viewBoxWidth / 2;
157
+ const slabHeight = options.slabHeight ?? (count >= 5 ? 8 : 10);
158
+ const cornerRadiusRatio = options.cornerRadiusRatio ?? 0.16;
159
+
160
+ if (count === 1) {
161
+ const rx = options.topSize ?? 110;
162
+ const ry = Number((rx * ratio).toFixed(2));
163
+ const cy = Number((viewBoxHeight / 2 - slabHeight / 2).toFixed(2));
164
+ const cornerRadius = Number((rx * cornerRadiusRatio).toFixed(2));
165
+ const dx = cornerRadius;
166
+ const dy = Number((cornerRadius * ratio).toFixed(2));
167
+
168
+ const paths = buildSquarePaths({
169
+ cx,
170
+ cy,
171
+ rx,
172
+ ry,
173
+ dx,
174
+ dy,
175
+ slabHeight,
176
+ });
177
+
178
+ const slabCenterY = Number((cy + slabHeight / 2).toFixed(2));
179
+
180
+ return {
181
+ viewBoxWidth,
182
+ viewBoxHeight,
183
+ count: 1,
184
+ layers: [
185
+ {
186
+ index: 0,
187
+ cx,
188
+ cy,
189
+ rx,
190
+ ry,
191
+ slabHeight,
192
+ cornerRadius,
193
+ slabCenterY,
194
+ ...paths,
195
+ },
196
+ ],
197
+ };
198
+ }
199
+
200
+ const topSize =
201
+ options.topSize ?? (count <= 2 ? 110 : Math.max(75, 100 - (count - 3) * 7));
202
+ const bottomSize = options.bottomSize ?? 185;
203
+
204
+ const radii: { rx: number; ry: number }[] = [];
205
+ for (let i = 0; i < count; i++) {
206
+ const t = i / (count - 1);
207
+ const rx = Number((topSize + t * (bottomSize - topSize)).toFixed(2));
208
+ const ry = Number((rx * ratio).toFixed(2));
209
+ radii.push({ rx, ry });
210
+ }
211
+
212
+ const { startCy, stepYList } = computePyramidStacking({
213
+ count,
214
+ viewBoxHeight,
215
+ slabHeight,
216
+ radii,
217
+ });
218
+
219
+ const layers: ISquareLayerGeometry[] = [];
220
+ let currentCy = startCy;
221
+
222
+ for (let i = 0; i < count; i++) {
223
+ const rx = radii[i]?.rx ?? topSize;
224
+ const ry = radii[i]?.ry ?? topSize * ratio;
225
+ const cy = Number(currentCy.toFixed(2));
226
+ const cornerRadius = Number((rx * cornerRadiusRatio).toFixed(2));
227
+ const dx = cornerRadius;
228
+ const dy = Number((cornerRadius * ratio).toFixed(2));
229
+
230
+ const paths = buildSquarePaths({
231
+ cx,
232
+ cy,
233
+ rx,
234
+ ry,
235
+ dx,
236
+ dy,
237
+ slabHeight,
238
+ });
239
+
240
+ const slabCenterY = Number((cy + slabHeight / 2).toFixed(2));
241
+
242
+ layers.push({
243
+ index: i,
244
+ cx,
245
+ cy,
246
+ rx,
247
+ ry,
248
+ slabHeight,
249
+ cornerRadius,
250
+ slabCenterY,
251
+ ...paths,
252
+ });
253
+
254
+ if (i < count - 1) {
255
+ currentCy += stepYList[i] ?? 0;
256
+ }
257
+ }
258
+
259
+ return {
260
+ viewBoxWidth,
261
+ viewBoxHeight,
262
+ count,
263
+ layers,
264
+ };
265
+ }
@@ -0,0 +1,3 @@
1
+ export * from './context';
2
+ export * from './createSquarePyramidGeometry';
3
+ export * from './types';
@@ -0,0 +1,39 @@
1
+ import type { IPyramidPalette } from '../shared';
2
+
3
+ export interface ISquareLayerGeometry {
4
+ readonly index: number;
5
+ readonly cx: number;
6
+ readonly cy: number;
7
+ readonly rx: number;
8
+ readonly ry: number;
9
+ readonly slabHeight: number;
10
+ readonly cornerRadius: number;
11
+ readonly topFacePath: string;
12
+ readonly innerFacePath: string;
13
+ readonly sidePath: string;
14
+ readonly leftSidePath: string;
15
+ readonly rightSidePath: string;
16
+ readonly bottomEdgePath: string;
17
+ readonly slabCenterY?: number;
18
+ }
19
+
20
+ export interface ISquarePyramidGeometry {
21
+ readonly viewBoxWidth: number;
22
+ readonly viewBoxHeight: number;
23
+ readonly count: number;
24
+ readonly layers: readonly ISquareLayerGeometry[];
25
+ }
26
+
27
+ export interface ICreateSquarePyramidOptions {
28
+ readonly count?: number;
29
+ readonly viewBoxWidth?: number;
30
+ readonly viewBoxHeight?: number;
31
+ readonly topSize?: number;
32
+ readonly bottomSize?: number;
33
+ readonly slabHeight?: number;
34
+ readonly ratio?: number;
35
+ readonly cx?: number;
36
+ readonly cornerRadiusRatio?: number;
37
+ }
38
+
39
+ export interface ISquarePyramidPalette extends IPyramidPalette {}
@@ -140,14 +140,7 @@ export function useDiagramAutoScale(
140
140
  pagyEl && window.getComputedStyle(pagyEl).display !== 'none';
141
141
  const clearance = isPagyVisible ? pagyClearance : 16;
142
142
 
143
- if (parent.clientHeight > 0 && parent !== slideEl) {
144
- availH = Math.max(
145
- 0,
146
- parent.clientHeight - padTop - padBottom - siblingsH - clearance,
147
- );
148
- }
149
-
150
- if (availH <= 0 && slideEl && slideEl.clientHeight > 0) {
143
+ if (slideEl && slideEl.clientHeight > 0) {
151
144
  const slideStyle = window.getComputedStyle(slideEl);
152
145
  const sPadTop = Number.parseFloat(slideStyle.paddingTop) || 0;
153
146
  const sPadBottom = Number.parseFloat(slideStyle.paddingBottom) || 0;
@@ -181,6 +174,11 @@ export function useDiagramAutoScale(
181
174
  slideSiblingsH -
182
175
  clearance,
183
176
  );
177
+ } else if (parent.clientHeight > 0) {
178
+ availH = Math.max(
179
+ 0,
180
+ parent.clientHeight - padTop - padBottom - siblingsH - clearance,
181
+ );
184
182
  }
185
183
  }
186
184