koishi-plugin-cchess 1.2.0 → 1.3.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/lib/index.js
CHANGED
|
@@ -38,6 +38,209 @@ __export(src_exports, {
|
|
|
38
38
|
});
|
|
39
39
|
module.exports = __toCommonJS(src_exports);
|
|
40
40
|
var import_koishi = require("koishi");
|
|
41
|
+
|
|
42
|
+
// src/m3.ts
|
|
43
|
+
var WHITE_X = 95.047;
|
|
44
|
+
var WHITE_Y = 100;
|
|
45
|
+
var WHITE_Z = 108.883;
|
|
46
|
+
function labToXyz(l, a, b) {
|
|
47
|
+
const fy = (l + 16) / 116;
|
|
48
|
+
const fx = fy + a / 500;
|
|
49
|
+
const fz = fy - b / 200;
|
|
50
|
+
const f = /* @__PURE__ */ __name((t) => t > 6 / 29 ? t * t * t : 3 * (6 / 29) ** 2 * (t - 4 / 29), "f");
|
|
51
|
+
return [f(fx) * WHITE_X, f(fy) * WHITE_Y, f(fz) * WHITE_Z];
|
|
52
|
+
}
|
|
53
|
+
__name(labToXyz, "labToXyz");
|
|
54
|
+
function gamma(value) {
|
|
55
|
+
return value <= 31308e-7 ? value * 12.92 : 1.055 * value ** (1 / 2.4) - 0.055;
|
|
56
|
+
}
|
|
57
|
+
__name(gamma, "gamma");
|
|
58
|
+
function xyzToRgb(x, y, z) {
|
|
59
|
+
x /= 100;
|
|
60
|
+
y /= 100;
|
|
61
|
+
z /= 100;
|
|
62
|
+
return [
|
|
63
|
+
gamma(3.2406 * x - 1.5372 * y - 0.4986 * z),
|
|
64
|
+
gamma(-0.9689 * x + 1.8758 * y + 0.0415 * z),
|
|
65
|
+
gamma(0.0557 * x - 0.204 * y + 1.057 * z)
|
|
66
|
+
];
|
|
67
|
+
}
|
|
68
|
+
__name(xyzToRgb, "xyzToRgb");
|
|
69
|
+
var EPSILON = 1 / 512;
|
|
70
|
+
function lch(tone, chroma, hue) {
|
|
71
|
+
const radian = hue * Math.PI / 180;
|
|
72
|
+
const at = /* @__PURE__ */ __name((c) => xyzToRgb(...labToXyz(tone, Math.cos(radian) * c, Math.sin(radian) * c)), "at");
|
|
73
|
+
const inGamut = /* @__PURE__ */ __name((rgb2) => rgb2.every((value) => value >= -EPSILON && value <= 1 + EPSILON), "inGamut");
|
|
74
|
+
let rgb = at(chroma);
|
|
75
|
+
if (!inGamut(rgb)) {
|
|
76
|
+
let low = 0;
|
|
77
|
+
let high = chroma;
|
|
78
|
+
while (high - low > 0.05) {
|
|
79
|
+
const mid = (low + high) / 2;
|
|
80
|
+
if (inGamut(at(mid))) low = mid;
|
|
81
|
+
else high = mid;
|
|
82
|
+
}
|
|
83
|
+
rgb = at(low);
|
|
84
|
+
}
|
|
85
|
+
return "#" + rgb.map((value) => Math.round(Math.min(1, Math.max(0, value)) * 255).toString(16).padStart(2, "0")).join("");
|
|
86
|
+
}
|
|
87
|
+
__name(lch, "lch");
|
|
88
|
+
function degamma(value) {
|
|
89
|
+
value /= 255;
|
|
90
|
+
return value <= 0.04045 ? value / 12.92 : ((value + 0.055) / 1.055) ** 2.4;
|
|
91
|
+
}
|
|
92
|
+
__name(degamma, "degamma");
|
|
93
|
+
function lchOf(hex) {
|
|
94
|
+
const value = parseInt(hex.replace("#", "").slice(0, 6), 16) || 0;
|
|
95
|
+
const r = degamma(value >> 16 & 255);
|
|
96
|
+
const g = degamma(value >> 8 & 255);
|
|
97
|
+
const b = degamma(value & 255);
|
|
98
|
+
const x = (0.4124 * r + 0.3576 * g + 0.1805 * b) * 100 / WHITE_X;
|
|
99
|
+
const y = (0.2126 * r + 0.7152 * g + 0.0722 * b) * 100 / WHITE_Y;
|
|
100
|
+
const z = (0.0193 * r + 0.1192 * g + 0.9505 * b) * 100 / WHITE_Z;
|
|
101
|
+
const f = /* @__PURE__ */ __name((t) => t > (6 / 29) ** 3 ? Math.cbrt(t) : t / (3 * (6 / 29) ** 2) + 4 / 29, "f");
|
|
102
|
+
const [fx, fy, fz] = [f(x), f(y), f(z)];
|
|
103
|
+
const a = 500 * (fx - fy);
|
|
104
|
+
const bb = 200 * (fy - fz);
|
|
105
|
+
return {
|
|
106
|
+
tone: 116 * fy - 16,
|
|
107
|
+
chroma: Math.hypot(a, bb),
|
|
108
|
+
hue: (Math.atan2(bb, a) * 180 / Math.PI + 360) % 360
|
|
109
|
+
};
|
|
110
|
+
}
|
|
111
|
+
__name(lchOf, "lchOf");
|
|
112
|
+
function harmonize(hex, tone, chroma = 48, fallbackHue = 0) {
|
|
113
|
+
const source = lchOf(hex);
|
|
114
|
+
const hue = source.chroma < 4 ? fallbackHue : source.hue;
|
|
115
|
+
return lch(tone, source.chroma < 4 ? Math.min(chroma, 6) : chroma, hue);
|
|
116
|
+
}
|
|
117
|
+
__name(harmonize, "harmonize");
|
|
118
|
+
function palette(hue, chroma) {
|
|
119
|
+
const cache = /* @__PURE__ */ new Map();
|
|
120
|
+
return (tone) => {
|
|
121
|
+
const hit = cache.get(tone);
|
|
122
|
+
if (hit) return hit;
|
|
123
|
+
const value = lch(tone, chroma, hue);
|
|
124
|
+
cache.set(tone, value);
|
|
125
|
+
return value;
|
|
126
|
+
};
|
|
127
|
+
}
|
|
128
|
+
__name(palette, "palette");
|
|
129
|
+
function palettesOf(hue, options = {}) {
|
|
130
|
+
const { chroma = 56, tertiaryShift = 60 } = options;
|
|
131
|
+
return {
|
|
132
|
+
primary: palette(hue, chroma),
|
|
133
|
+
secondary: palette(hue, Math.max(16, chroma / 3.2)),
|
|
134
|
+
tertiary: palette(hue + tertiaryShift, Math.max(28, chroma / 1.8)),
|
|
135
|
+
neutral: palette(hue, 4),
|
|
136
|
+
neutralVariant: palette(hue, 9),
|
|
137
|
+
error: palette(36, 68)
|
|
138
|
+
};
|
|
139
|
+
}
|
|
140
|
+
__name(palettesOf, "palettesOf");
|
|
141
|
+
function scheme(hue, dark = false, options = {}) {
|
|
142
|
+
const p = palettesOf(hue, options);
|
|
143
|
+
const { primary: P, secondary: S, tertiary: T, neutral: N, neutralVariant: V, error: E } = p;
|
|
144
|
+
if (dark) {
|
|
145
|
+
return {
|
|
146
|
+
primary: P(80),
|
|
147
|
+
onPrimary: P(20),
|
|
148
|
+
primaryContainer: P(30),
|
|
149
|
+
onPrimaryContainer: P(90),
|
|
150
|
+
secondary: S(80),
|
|
151
|
+
onSecondary: S(20),
|
|
152
|
+
secondaryContainer: S(30),
|
|
153
|
+
onSecondaryContainer: S(90),
|
|
154
|
+
tertiary: T(80),
|
|
155
|
+
onTertiary: T(20),
|
|
156
|
+
tertiaryContainer: T(30),
|
|
157
|
+
onTertiaryContainer: T(90),
|
|
158
|
+
error: E(80),
|
|
159
|
+
onError: E(20),
|
|
160
|
+
errorContainer: E(30),
|
|
161
|
+
onErrorContainer: E(90),
|
|
162
|
+
background: N(6),
|
|
163
|
+
onBackground: N(90),
|
|
164
|
+
surface: N(6),
|
|
165
|
+
onSurface: N(90),
|
|
166
|
+
surfaceVariant: V(30),
|
|
167
|
+
onSurfaceVariant: V(80),
|
|
168
|
+
surfaceDim: N(6),
|
|
169
|
+
surfaceBright: N(24),
|
|
170
|
+
surfaceContainerLowest: N(4),
|
|
171
|
+
surfaceContainerLow: N(10),
|
|
172
|
+
surfaceContainer: N(12),
|
|
173
|
+
surfaceContainerHigh: N(17),
|
|
174
|
+
surfaceContainerHighest: N(22),
|
|
175
|
+
outline: V(60),
|
|
176
|
+
outlineVariant: V(30),
|
|
177
|
+
inverseSurface: N(90),
|
|
178
|
+
inverseOnSurface: N(20),
|
|
179
|
+
inversePrimary: P(40),
|
|
180
|
+
scrim: N(0),
|
|
181
|
+
shadow: N(0)
|
|
182
|
+
};
|
|
183
|
+
}
|
|
184
|
+
return {
|
|
185
|
+
primary: P(40),
|
|
186
|
+
onPrimary: P(100),
|
|
187
|
+
primaryContainer: P(90),
|
|
188
|
+
onPrimaryContainer: P(30),
|
|
189
|
+
secondary: S(40),
|
|
190
|
+
onSecondary: S(100),
|
|
191
|
+
secondaryContainer: S(90),
|
|
192
|
+
onSecondaryContainer: S(30),
|
|
193
|
+
tertiary: T(40),
|
|
194
|
+
onTertiary: T(100),
|
|
195
|
+
tertiaryContainer: T(90),
|
|
196
|
+
onTertiaryContainer: T(30),
|
|
197
|
+
error: E(40),
|
|
198
|
+
onError: E(100),
|
|
199
|
+
errorContainer: E(90),
|
|
200
|
+
onErrorContainer: E(30),
|
|
201
|
+
background: N(98),
|
|
202
|
+
onBackground: N(10),
|
|
203
|
+
surface: N(98),
|
|
204
|
+
onSurface: N(10),
|
|
205
|
+
surfaceVariant: V(90),
|
|
206
|
+
onSurfaceVariant: V(30),
|
|
207
|
+
surfaceDim: N(87),
|
|
208
|
+
surfaceBright: N(98),
|
|
209
|
+
surfaceContainerLowest: N(100),
|
|
210
|
+
surfaceContainerLow: N(96),
|
|
211
|
+
surfaceContainer: N(94),
|
|
212
|
+
surfaceContainerHigh: N(92),
|
|
213
|
+
surfaceContainerHighest: N(90),
|
|
214
|
+
outline: V(50),
|
|
215
|
+
outlineVariant: V(80),
|
|
216
|
+
inverseSurface: N(20),
|
|
217
|
+
inverseOnSurface: N(95),
|
|
218
|
+
inversePrimary: P(80),
|
|
219
|
+
scrim: N(0),
|
|
220
|
+
shadow: N(0)
|
|
221
|
+
};
|
|
222
|
+
}
|
|
223
|
+
__name(scheme, "scheme");
|
|
224
|
+
var SHAPE = {
|
|
225
|
+
none: 0,
|
|
226
|
+
extraSmall: 4,
|
|
227
|
+
small: 8,
|
|
228
|
+
medium: 12,
|
|
229
|
+
large: 16,
|
|
230
|
+
largeIncreased: 20,
|
|
231
|
+
extraLarge: 28,
|
|
232
|
+
extraLargeIncreased: 32,
|
|
233
|
+
extraExtraLarge: 48,
|
|
234
|
+
full: 9999
|
|
235
|
+
};
|
|
236
|
+
var FONT_STACK = '"Roboto Flex", "Roboto", "Noto Sans SC", "PingFang SC", "Microsoft YaHei", "Source Han Sans SC", system-ui, sans-serif';
|
|
237
|
+
var MEDAL = {
|
|
238
|
+
gold: lch(58, 52, 85),
|
|
239
|
+
silver: lch(66, 5, 260),
|
|
240
|
+
bronze: lch(48, 36, 48)
|
|
241
|
+
};
|
|
242
|
+
|
|
243
|
+
// src/index.ts
|
|
41
244
|
var path = __toESM(require("path"));
|
|
42
245
|
var fs = __toESM(require("fs"));
|
|
43
246
|
var name = "cchess";
|
|
@@ -115,6 +318,22 @@ function apply(ctx, config) {
|
|
|
115
318
|
}
|
|
116
319
|
});
|
|
117
320
|
});
|
|
321
|
+
const FRAME = scheme(60);
|
|
322
|
+
function roundRect(context, x, y, width, height, radius) {
|
|
323
|
+
const r = Math.max(0, Math.min(radius, width / 2, height / 2));
|
|
324
|
+
context.beginPath();
|
|
325
|
+
context.moveTo(x + r, y);
|
|
326
|
+
context.lineTo(x + width - r, y);
|
|
327
|
+
context.arcTo(x + width, y, x + width, y + r, r);
|
|
328
|
+
context.lineTo(x + width, y + height - r);
|
|
329
|
+
context.arcTo(x + width, y + height, x + width - r, y + height, r);
|
|
330
|
+
context.lineTo(x + r, y + height);
|
|
331
|
+
context.arcTo(x, y + height, x, y + height - r, r);
|
|
332
|
+
context.lineTo(x, y + r);
|
|
333
|
+
context.arcTo(x, y, x + r, y, r);
|
|
334
|
+
context.closePath();
|
|
335
|
+
}
|
|
336
|
+
__name(roundRect, "roundRect");
|
|
118
337
|
const CELL_WIDTH = 54;
|
|
119
338
|
const ARROW_OFFSET = 33;
|
|
120
339
|
const BOARD_PADDING = 33;
|
|
@@ -132,8 +351,14 @@ function apply(ctx, config) {
|
|
|
132
351
|
const thinkingDepth = Math.max(1, Math.round(config.defaultEngineThinkingDepth) || 1);
|
|
133
352
|
const ENGINE_TIMEOUT = 120 * 1e3;
|
|
134
353
|
const piecesImgResources = loadPiecesImageResources(config.pieceSkin);
|
|
135
|
-
const outerFrameImg = fs.readFileSync(path.join(__dirname, "assets", "棋盘皮肤", `外框.png`));
|
|
136
354
|
const boardSkinImg = fs.readFileSync(path.join(__dirname, "assets", "棋盘皮肤", `${config.boardSkin}.webp`));
|
|
355
|
+
const FRAME_WIDTH = 620;
|
|
356
|
+
const FRAME_HEIGHT = 780;
|
|
357
|
+
const FRAME_BOARD = { x: 36.5, y: 90, width: 550, height: 605 };
|
|
358
|
+
const FRAME_ZOOM = FRAME_BOARD.width / BOARD_WIDTH;
|
|
359
|
+
const FILES = ["a", "b", "c", "d", "e", "f", "g", "h", "i"];
|
|
360
|
+
const RED_FILES = ["九", "八", "七", "六", "五", "四", "三", "二", "一"];
|
|
361
|
+
const ARROW_COLOR = harmonize("#80ab45", 58, 56);
|
|
137
362
|
const possibleFigureNames = ["将", "士", "象", "车", "马", "炮", "卒", "帅", "仕", "相", "兵"];
|
|
138
363
|
ctx.model.extend("cchess_game_records", {
|
|
139
364
|
id: "unsigned",
|
|
@@ -1389,12 +1614,42 @@ function apply(ctx, config) {
|
|
|
1389
1614
|
}
|
|
1390
1615
|
__name(convertTurnToString, "convertTurnToString");
|
|
1391
1616
|
async function createImage(buffer) {
|
|
1392
|
-
const canvas = await ctx.canvas.createCanvas(
|
|
1617
|
+
const canvas = await ctx.canvas.createCanvas(FRAME_WIDTH * scale, FRAME_HEIGHT * scale);
|
|
1393
1618
|
const context = canvas.getContext("2d");
|
|
1394
|
-
|
|
1395
|
-
context.
|
|
1619
|
+
context.scale(scale, scale);
|
|
1620
|
+
context.fillStyle = FRAME.surfaceContainer;
|
|
1621
|
+
roundRect(context, 0, 0, FRAME_WIDTH, FRAME_HEIGHT, SHAPE.extraLarge);
|
|
1622
|
+
context.fill();
|
|
1396
1623
|
const boardImg = await ctx.canvas.loadImage(buffer);
|
|
1397
|
-
context.drawImage(
|
|
1624
|
+
context.drawImage(
|
|
1625
|
+
boardImg,
|
|
1626
|
+
FRAME_BOARD.x,
|
|
1627
|
+
FRAME_BOARD.y,
|
|
1628
|
+
FRAME_BOARD.width,
|
|
1629
|
+
FRAME_BOARD.height
|
|
1630
|
+
);
|
|
1631
|
+
const columnAt = /* @__PURE__ */ __name((col) => FRAME_BOARD.x + (col * CELL_WIDTH + BOARD_PADDING) * FRAME_ZOOM, "columnAt");
|
|
1632
|
+
const rowAt = /* @__PURE__ */ __name((row) => FRAME_BOARD.y + (row * CELL_WIDTH + BOARD_PADDING) * FRAME_ZOOM, "rowAt");
|
|
1633
|
+
context.textAlign = "center";
|
|
1634
|
+
context.textBaseline = "middle";
|
|
1635
|
+
const label = /* @__PURE__ */ __name((text, x, y, size, color) => {
|
|
1636
|
+
context.font = `600 ${size}px ${FONT_STACK}`;
|
|
1637
|
+
context.fillStyle = color;
|
|
1638
|
+
context.fillText(text, x, y);
|
|
1639
|
+
}, "label");
|
|
1640
|
+
for (let col = 0; col < 9; col++) {
|
|
1641
|
+
const x = columnAt(isFlipBoard ? 8 - col : col);
|
|
1642
|
+
label(FILES[col], x, 30, 22, FRAME.onSurfaceVariant);
|
|
1643
|
+
label(String(col + 1), x, 64, 22, FRAME.outline);
|
|
1644
|
+
label(RED_FILES[col], x, FRAME_HEIGHT - 62, 24, FRAME.onSurfaceVariant);
|
|
1645
|
+
label(FILES[col], x, FRAME_HEIGHT - 26, 22, FRAME.outline);
|
|
1646
|
+
}
|
|
1647
|
+
for (let row = 0; row < 10; row++) {
|
|
1648
|
+
const y = rowAt(isFlipBoard ? 9 - row : row);
|
|
1649
|
+
const text = String(9 - row);
|
|
1650
|
+
label(text, 19, y, 22, FRAME.outline);
|
|
1651
|
+
label(text, FRAME_WIDTH - 19, y, 22, FRAME.outline);
|
|
1652
|
+
}
|
|
1398
1653
|
return canvas.toBuffer(imageMimeType);
|
|
1399
1654
|
}
|
|
1400
1655
|
__name(createImage, "createImage");
|
|
@@ -1864,7 +2119,7 @@ function apply(ctx, config) {
|
|
|
1864
2119
|
let dist = Math.sqrt((startX - endX) ** 2 + (startY - endY) ** 2);
|
|
1865
2120
|
let adjustedEndX = startX + (endX - startX) * (dist - 30) / dist;
|
|
1866
2121
|
let adjustedEndY = startY + (endY - startY) * (dist - 30) / dist;
|
|
1867
|
-
await drawLineArrow(context, startX * scale, startY * scale, adjustedEndX * scale, adjustedEndY * scale,
|
|
2122
|
+
await drawLineArrow(context, startX * scale, startY * scale, adjustedEndX * scale, adjustedEndY * scale, ARROW_COLOR + "b3", 15 * scale);
|
|
1868
2123
|
}
|
|
1869
2124
|
if (moveList.length > 0) {
|
|
1870
2125
|
const currentMoveId = moveList[moveList.length - 1].moveId;
|
package/lib/m3.d.ts
ADDED
|
@@ -0,0 +1,256 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Material 3 Expressive 设计系统。
|
|
3
|
+
*
|
|
4
|
+
* 只依赖标准库,输出纯 CSS 变量与常量,任何渲染后端(puppeteer / canvas)都能用。
|
|
5
|
+
* 色板按 M3 的做法从一个源色推出六套色调板,再按角色映射成明暗两套配色。
|
|
6
|
+
*/
|
|
7
|
+
/** M3 的「色调」就是 CIE L*,0 为黑、100 为白。 */
|
|
8
|
+
export type Tone = number;
|
|
9
|
+
/** LCh -> #rrggbb。超出 sRGB 色域时按二分法降低彩度,色调与色相保持不变。 */
|
|
10
|
+
export declare function lch(tone: Tone, chroma: number, hue: number): string;
|
|
11
|
+
/** `#rrggbb` -> LCh,`lch()` 的逆运算。 */
|
|
12
|
+
export declare function lchOf(hex: string): {
|
|
13
|
+
tone: number;
|
|
14
|
+
chroma: number;
|
|
15
|
+
hue: number;
|
|
16
|
+
};
|
|
17
|
+
/**
|
|
18
|
+
* 把一个任意来源的颜色(头像主色、用户自选色)收进本设计系统。
|
|
19
|
+
*
|
|
20
|
+
* 只保留它的色相,色调与彩度一律换成设计系统里的取值——于是每个人都还有
|
|
21
|
+
* 自己的颜色,整张图的明度节奏却是齐的,不会因为某个头像特别暗就糊成一团。
|
|
22
|
+
* 彩度太低的灰色头像没有可用的色相,退回主色。
|
|
23
|
+
*/
|
|
24
|
+
export declare function harmonize(hex: string, tone: Tone, chroma?: number, fallbackHue?: number): string;
|
|
25
|
+
/** 一套色调板:固定色相与彩度,按色调取色。 */
|
|
26
|
+
export type Palette = (tone: Tone) => string;
|
|
27
|
+
export declare function palette(hue: number, chroma: number): Palette;
|
|
28
|
+
export interface Palettes {
|
|
29
|
+
primary: Palette;
|
|
30
|
+
secondary: Palette;
|
|
31
|
+
tertiary: Palette;
|
|
32
|
+
neutral: Palette;
|
|
33
|
+
neutralVariant: Palette;
|
|
34
|
+
error: Palette;
|
|
35
|
+
}
|
|
36
|
+
export interface SourceOptions {
|
|
37
|
+
/** 主色彩度,默认 56,够鲜艳又不至于在浅色调上大面积溢出色域。 */
|
|
38
|
+
chroma?: number;
|
|
39
|
+
/**
|
|
40
|
+
* 第三色相对主色的相位差,默认 +60°。
|
|
41
|
+
* 这个值规范里是个经验值,并非永远合适:暖橙 +60° 会落到发闷的橄榄绿,
|
|
42
|
+
* 这种时候改成 -60° 取玫红,强调色才跳得出来。
|
|
43
|
+
*/
|
|
44
|
+
tertiaryShift?: number;
|
|
45
|
+
}
|
|
46
|
+
/**
|
|
47
|
+
* 按 M3 的推导规则从源色相生成六套色调板。
|
|
48
|
+
*
|
|
49
|
+
* Expressive 相比基础风格更敢用彩度:第三色比规范里的保守取值更高,
|
|
50
|
+
* 中性色也留了一点源色的味道,成片的表面不会灰得发死。
|
|
51
|
+
*/
|
|
52
|
+
export declare function palettesOf(hue: number, options?: SourceOptions): Palettes;
|
|
53
|
+
export interface Scheme {
|
|
54
|
+
primary: string;
|
|
55
|
+
onPrimary: string;
|
|
56
|
+
primaryContainer: string;
|
|
57
|
+
onPrimaryContainer: string;
|
|
58
|
+
secondary: string;
|
|
59
|
+
onSecondary: string;
|
|
60
|
+
secondaryContainer: string;
|
|
61
|
+
onSecondaryContainer: string;
|
|
62
|
+
tertiary: string;
|
|
63
|
+
onTertiary: string;
|
|
64
|
+
tertiaryContainer: string;
|
|
65
|
+
onTertiaryContainer: string;
|
|
66
|
+
error: string;
|
|
67
|
+
onError: string;
|
|
68
|
+
errorContainer: string;
|
|
69
|
+
onErrorContainer: string;
|
|
70
|
+
background: string;
|
|
71
|
+
onBackground: string;
|
|
72
|
+
surface: string;
|
|
73
|
+
onSurface: string;
|
|
74
|
+
surfaceVariant: string;
|
|
75
|
+
onSurfaceVariant: string;
|
|
76
|
+
surfaceDim: string;
|
|
77
|
+
surfaceBright: string;
|
|
78
|
+
surfaceContainerLowest: string;
|
|
79
|
+
surfaceContainerLow: string;
|
|
80
|
+
surfaceContainer: string;
|
|
81
|
+
surfaceContainerHigh: string;
|
|
82
|
+
surfaceContainerHighest: string;
|
|
83
|
+
outline: string;
|
|
84
|
+
outlineVariant: string;
|
|
85
|
+
inverseSurface: string;
|
|
86
|
+
inverseOnSurface: string;
|
|
87
|
+
inversePrimary: string;
|
|
88
|
+
scrim: string;
|
|
89
|
+
shadow: string;
|
|
90
|
+
}
|
|
91
|
+
/** 生成一套完整的角色配色。`dark` 为真时返回暗色方案。 */
|
|
92
|
+
export declare function scheme(hue: number, dark?: boolean, options?: SourceOptions): Scheme;
|
|
93
|
+
/**
|
|
94
|
+
* M3 Expressive 形状刻度(px)。
|
|
95
|
+
* Expressive 把圆角整体推大了一档,容器之间靠「圆角差」而不是分隔线来分层。
|
|
96
|
+
*/
|
|
97
|
+
export declare const SHAPE: {
|
|
98
|
+
readonly none: 0;
|
|
99
|
+
readonly extraSmall: 4;
|
|
100
|
+
readonly small: 8;
|
|
101
|
+
readonly medium: 12;
|
|
102
|
+
readonly large: 16;
|
|
103
|
+
readonly largeIncreased: 20;
|
|
104
|
+
readonly extraLarge: 28;
|
|
105
|
+
readonly extraLargeIncreased: 32;
|
|
106
|
+
readonly extraExtraLarge: 48;
|
|
107
|
+
readonly full: 9999;
|
|
108
|
+
};
|
|
109
|
+
/** 正文与标题字体栈,覆盖 Windows / macOS / Linux 与随包字体三种情况。 */
|
|
110
|
+
export declare const FONT_STACK = "\"Roboto Flex\", \"Roboto\", \"Noto Sans SC\", \"PingFang SC\", \"Microsoft YaHei\", \"Source Han Sans SC\", system-ui, sans-serif";
|
|
111
|
+
/** 等宽字体栈,用于比分、倒计时这类需要对齐的数字。 */
|
|
112
|
+
export declare const MONO_STACK = "\"Roboto Mono\", \"JetBrains Mono\", \"SF Mono\", \"Cascadia Mono\", Consolas, \"Noto Sans Mono\", monospace";
|
|
113
|
+
export interface TypeStyle {
|
|
114
|
+
size: number;
|
|
115
|
+
line: number;
|
|
116
|
+
weight: number;
|
|
117
|
+
tracking: number;
|
|
118
|
+
}
|
|
119
|
+
/**
|
|
120
|
+
* M3 Expressive 字阶。`emphasized` 档提高字重,用在需要被一眼看到的地方,
|
|
121
|
+
* 这是 Expressive 与基础风格最直观的差别之一。
|
|
122
|
+
*/
|
|
123
|
+
export declare const TYPE: {
|
|
124
|
+
displayLarge: {
|
|
125
|
+
size: number;
|
|
126
|
+
line: number;
|
|
127
|
+
weight: number;
|
|
128
|
+
tracking: number;
|
|
129
|
+
};
|
|
130
|
+
displayMedium: {
|
|
131
|
+
size: number;
|
|
132
|
+
line: number;
|
|
133
|
+
weight: number;
|
|
134
|
+
tracking: number;
|
|
135
|
+
};
|
|
136
|
+
displaySmall: {
|
|
137
|
+
size: number;
|
|
138
|
+
line: number;
|
|
139
|
+
weight: number;
|
|
140
|
+
tracking: number;
|
|
141
|
+
};
|
|
142
|
+
headlineLarge: {
|
|
143
|
+
size: number;
|
|
144
|
+
line: number;
|
|
145
|
+
weight: number;
|
|
146
|
+
tracking: number;
|
|
147
|
+
};
|
|
148
|
+
headlineMedium: {
|
|
149
|
+
size: number;
|
|
150
|
+
line: number;
|
|
151
|
+
weight: number;
|
|
152
|
+
tracking: number;
|
|
153
|
+
};
|
|
154
|
+
headlineSmall: {
|
|
155
|
+
size: number;
|
|
156
|
+
line: number;
|
|
157
|
+
weight: number;
|
|
158
|
+
tracking: number;
|
|
159
|
+
};
|
|
160
|
+
titleLarge: {
|
|
161
|
+
size: number;
|
|
162
|
+
line: number;
|
|
163
|
+
weight: number;
|
|
164
|
+
tracking: number;
|
|
165
|
+
};
|
|
166
|
+
titleMedium: {
|
|
167
|
+
size: number;
|
|
168
|
+
line: number;
|
|
169
|
+
weight: number;
|
|
170
|
+
tracking: number;
|
|
171
|
+
};
|
|
172
|
+
titleSmall: {
|
|
173
|
+
size: number;
|
|
174
|
+
line: number;
|
|
175
|
+
weight: number;
|
|
176
|
+
tracking: number;
|
|
177
|
+
};
|
|
178
|
+
bodyLarge: {
|
|
179
|
+
size: number;
|
|
180
|
+
line: number;
|
|
181
|
+
weight: number;
|
|
182
|
+
tracking: number;
|
|
183
|
+
};
|
|
184
|
+
bodyMedium: {
|
|
185
|
+
size: number;
|
|
186
|
+
line: number;
|
|
187
|
+
weight: number;
|
|
188
|
+
tracking: number;
|
|
189
|
+
};
|
|
190
|
+
bodySmall: {
|
|
191
|
+
size: number;
|
|
192
|
+
line: number;
|
|
193
|
+
weight: number;
|
|
194
|
+
tracking: number;
|
|
195
|
+
};
|
|
196
|
+
labelLarge: {
|
|
197
|
+
size: number;
|
|
198
|
+
line: number;
|
|
199
|
+
weight: number;
|
|
200
|
+
tracking: number;
|
|
201
|
+
};
|
|
202
|
+
labelMedium: {
|
|
203
|
+
size: number;
|
|
204
|
+
line: number;
|
|
205
|
+
weight: number;
|
|
206
|
+
tracking: number;
|
|
207
|
+
};
|
|
208
|
+
labelSmall: {
|
|
209
|
+
size: number;
|
|
210
|
+
line: number;
|
|
211
|
+
weight: number;
|
|
212
|
+
tracking: number;
|
|
213
|
+
};
|
|
214
|
+
};
|
|
215
|
+
/**
|
|
216
|
+
* Expressive 的强调字重。取 600 而非规范里的 500:很多机器上只装了 400 / 700 两档,
|
|
217
|
+
* 500 会回落成常规字重,强调就白做了;600 在这种字体集下会匹配到 700,效果才稳定。
|
|
218
|
+
* 正文维持 400,字重拉高反而伤可读性。
|
|
219
|
+
*/
|
|
220
|
+
export declare const EMPHASIZED_WEIGHT: {
|
|
221
|
+
readonly display: 600;
|
|
222
|
+
readonly headline: 600;
|
|
223
|
+
readonly title: 600;
|
|
224
|
+
readonly label: 600;
|
|
225
|
+
};
|
|
226
|
+
/** 阴影高度(dp -> box-shadow),M3 只有 0 ~ 5 六档。 */
|
|
227
|
+
export declare const ELEVATION: readonly ["none", "0 1px 2px 0 rgba(0,0,0,.30), 0 1px 3px 1px rgba(0,0,0,.15)", "0 1px 2px 0 rgba(0,0,0,.30), 0 2px 6px 2px rgba(0,0,0,.15)", "0 1px 3px 0 rgba(0,0,0,.30), 0 4px 8px 3px rgba(0,0,0,.15)", "0 2px 3px 0 rgba(0,0,0,.30), 0 6px 10px 4px rgba(0,0,0,.15)", "0 4px 4px 0 rgba(0,0,0,.30), 0 8px 12px 6px rgba(0,0,0,.15)"];
|
|
228
|
+
/** 把配色方案铺成 `--md-sys-color-*` 变量。 */
|
|
229
|
+
export declare function colorVars(s: Scheme): string;
|
|
230
|
+
/** 形状、字阶、高度的变量,与配色一起构成完整的令牌集。 */
|
|
231
|
+
export declare function systemVars(): string;
|
|
232
|
+
/** 一段可直接塞进 `<style>` 的基础样式:令牌 + 排版重置。 */
|
|
233
|
+
export declare function baseline(s: Scheme): string;
|
|
234
|
+
/**
|
|
235
|
+
* 通用组件样式。各插件按需挑用,命名统一为 `m3-` 前缀。
|
|
236
|
+
*
|
|
237
|
+
* Expressive 的取向体现在三处:圆角整体偏大且同一张图里刻意拉开层次、
|
|
238
|
+
* 强调元素用高彩度的容器色而不是描边、以及成组元素之间用间距而不是分隔线来断句。
|
|
239
|
+
*/
|
|
240
|
+
/** 金银铜。色调依次 58 / 66 / 48,深浅本身就排出了名次。 */
|
|
241
|
+
export declare const MEDAL: {
|
|
242
|
+
readonly gold: string;
|
|
243
|
+
readonly silver: string;
|
|
244
|
+
readonly bronze: string;
|
|
245
|
+
};
|
|
246
|
+
export declare function components(): string;
|
|
247
|
+
/**
|
|
248
|
+
* 浏览器端的配色小库,序列化进页面脚本用。
|
|
249
|
+
*
|
|
250
|
+
* 有些图是在页面里用 canvas 画的,那边拿不到这个模块。与其在客户端另写一套
|
|
251
|
+
* HSL 近似,不如把同一套 LCh 运算原样送过去——服务端与浏览器端算出来的颜色
|
|
252
|
+
* 必须一致,否则「同一支色相」的承诺在两边会对不上。
|
|
253
|
+
*
|
|
254
|
+
* 暴露的接口与本模块同名:`M3.lch` / `M3.lchOf` / `M3.harmonize`。
|
|
255
|
+
*/
|
|
256
|
+
export declare function clientColorScript(): string;
|
package/package.json
CHANGED