@e4779/skills 0.0.0-stage → 0.1.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/chrome-devtools/README.md +76 -0
- package/chrome-devtools/SKILL.md +277 -0
- package/chrome-devtools/references/recipes.md +379 -0
- package/chrome-devtools/references/setup.md +138 -0
- package/drawio/SKILL.md +395 -0
- package/gh-cli/SKILL.md +83 -0
- package/grill/SKILL.md +72 -0
- package/layout-check/README.md +32 -0
- package/layout-check/SKILL.md +416 -0
- package/layout-check/scripts/layoutProbe.mjs +539 -0
- package/mcpls/SKILL.md +261 -0
- package/mcpls/references/configuration.md +131 -0
- package/mcpls/references/install.md +13 -0
- package/mcporter/SKILL.md +90 -0
- package/mindmap/SKILL.md +46 -0
- package/mindmap/references/drawio-recipe.md +60 -0
- package/mindmap/references/mindmap-design.md +63 -0
- package/opensource-contribution/SKILL.md +119 -0
- package/package.json +29 -5
- package/shell-taste/.shellcheckrc +16 -0
- package/shell-taste/SKILL.md +95 -0
- package/shell-taste/references/handbook/dialects.md +168 -0
- package/shell-taste/references/handbook/dom/01-output-logging.md +245 -0
- package/shell-taste/references/handbook/dom/02-errors-exit.md +48 -0
- package/shell-taste/references/handbook/dom/03-installation-setup.md +179 -0
- package/shell-taste/references/handbook/dom/04-network.md +384 -0
- package/shell-taste/references/handbook/dom/05-files-paths.md +74 -0
- package/shell-taste/references/handbook/dom/06-checks-validation.md +127 -0
- package/shell-taste/references/handbook/dom/07-system-administration.md +103 -0
- package/shell-taste/references/handbook/dom/08-privilege-users.md +58 -0
- package/shell-taste/references/handbook/dom/09-text-data.md +62 -0
- package/shell-taste/references/handbook/dom/10-terminal-ux.md +60 -0
- package/shell-taste/references/handbook/dom/11-process-control.md +28 -0
- package/shell-taste/references/handbook/dom/12-uncategorized.md +161 -0
- package/shell-taste/references/handbook/dom/13-containers.md +13 -0
- package/shell-taste/references/handbook/dom/14-agents-ai-tooling.md +13 -0
- package/shell-taste/references/handbook/family-index.md +230 -0
- package/shell-taste/references/handbook/index.md +41 -0
- package/skill-author/SKILL.md +86 -0
- package/sobesednik/SKILL.md +98 -0
- package/sobesednik/card-template.md +23 -0
- package/sobesednik/personas/advocate.md +27 -0
- package/sobesednik/personas/analyst.md +29 -0
- package/sobesednik/personas/chat.md +42 -0
- package/sobesednik/personas/ifs.md +32 -0
- package/sobesednik/personas/journal/README.md +6 -0
- package/sobesednik/personas/nasreddin.md +29 -0
- package/sobesednik/personas/premortem.md +29 -0
- package/sobesednik/personas/rogers.md +27 -0
- package/sobesednik/personas/socratic.md +29 -0
- package/sobesednik/personas/stoic.md +27 -0
- package/sobesednik/references/persona-design.md +41 -0
- package/zai-mcp/README.md +63 -0
- package/zai-mcp/SKILL.md +160 -0
- package/zai-mcp/references/recipes.md +273 -0
- package/zai-mcp/references/tools.md +266 -0
- package/README.md +0 -3
|
@@ -0,0 +1,539 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* layoutProbe — собирает таблицу позиций элементов и их отношений.
|
|
3
|
+
*
|
|
4
|
+
* Используется через evaluate_script в chrome-devtools:
|
|
5
|
+
* evaluate_script(layoutProbe({ selectors: { ... } }))
|
|
6
|
+
*
|
|
7
|
+
* @typedef {{ name: string, text: string, top: number, left: number, bottom: number, right: number, w: number, h: number }} Element
|
|
8
|
+
* @typedef {{ elements: Element[], relations: string[] }} ProbeResult
|
|
9
|
+
*
|
|
10
|
+
* @param {Object} options
|
|
11
|
+
* @param {Object<string,string>} [options.selectors={}] CSS-селекторы { name: '.class' }
|
|
12
|
+
* @param {HTMLElement[]} [options.elements=[]] Готовые DOM-элементы (из evaluate_script args)
|
|
13
|
+
* @param {number} [options.threshold=2] Допуск в px для alignment
|
|
14
|
+
* @param {boolean} [options.relations=true] Включить вычисление отношений
|
|
15
|
+
* @returns {string} markdown-таблица
|
|
16
|
+
*
|
|
17
|
+
* layoutProbe(options) → markdown-строка (для чтения агентом)
|
|
18
|
+
* layoutProbe.structured(options) → ProbeResult (для compare)
|
|
19
|
+
* layoutProbe.compare(before, after) → diff-строка
|
|
20
|
+
*/
|
|
21
|
+
|
|
22
|
+
/**
|
|
23
|
+
* Ядро: сбор элементов + вычисление отношений → structured data.
|
|
24
|
+
* @param {Object} options — те же, что у layoutProbe
|
|
25
|
+
* @returns {ProbeResult & { issues?: string[] }}
|
|
26
|
+
*/
|
|
27
|
+
function probe(options = {}) {
|
|
28
|
+
const {
|
|
29
|
+
selectors = {},
|
|
30
|
+
elements: rawElements = [],
|
|
31
|
+
threshold = 2,
|
|
32
|
+
relations = true,
|
|
33
|
+
issues = true,
|
|
34
|
+
styleAware = false,
|
|
35
|
+
container = '',
|
|
36
|
+
format = 'markdown'
|
|
37
|
+
} = options;
|
|
38
|
+
|
|
39
|
+
/**
|
|
40
|
+
* Извлечь bounding box + метаданные из DOM-элемента.
|
|
41
|
+
* @param {HTMLElement} el
|
|
42
|
+
* @param {string} name
|
|
43
|
+
* @returns {Element}
|
|
44
|
+
*/
|
|
45
|
+
function extract(el, name) {
|
|
46
|
+
const r = el.getBoundingClientRect();
|
|
47
|
+
return {
|
|
48
|
+
name,
|
|
49
|
+
text: el.textContent?.trim()?.slice(0, 15),
|
|
50
|
+
top: +r.top.toFixed(1),
|
|
51
|
+
left: +r.left.toFixed(1),
|
|
52
|
+
bottom: +r.bottom.toFixed(1),
|
|
53
|
+
right: +r.right.toFixed(1),
|
|
54
|
+
w: +r.width.toFixed(1),
|
|
55
|
+
h: +r.height.toFixed(1),
|
|
56
|
+
};
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
// 1. Находим элементы: selectors + raw elements (из evaluate_script args / uid)
|
|
60
|
+
const elements = [];
|
|
61
|
+
|
|
62
|
+
// 1a. Селекторы (CSS)
|
|
63
|
+
for (const [name, selector] of Object.entries(selectors)) {
|
|
64
|
+
const els = document.querySelectorAll(selector);
|
|
65
|
+
if (els.length === 0) continue;
|
|
66
|
+
const needsIndex = els.length > 1;
|
|
67
|
+
els.forEach((el, idx) => {
|
|
68
|
+
elements.push(extract(el, needsIndex ? `${name}-${idx}` : name));
|
|
69
|
+
});
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
// 1b. Готовые DOM-элементы (evaluate_script args — chrome-devtools резолвит uid)
|
|
73
|
+
rawElements.forEach((el, idx) => {
|
|
74
|
+
if (el && el.getBoundingClientRect) {
|
|
75
|
+
elements.push(extract(el, `el-${idx}`));
|
|
76
|
+
}
|
|
77
|
+
});
|
|
78
|
+
|
|
79
|
+
// 2. Вычисляем отношения
|
|
80
|
+
const rels = [];
|
|
81
|
+
if (relations && elements.length >= 2) {
|
|
82
|
+
for (let i = 0; i < elements.length; i++) {
|
|
83
|
+
for (let j = i + 1; j < elements.length; j++) {
|
|
84
|
+
const a = elements[i], b = elements[j];
|
|
85
|
+
|
|
86
|
+
// Горизонтальные выравнивания
|
|
87
|
+
align(a, b, 'bottom', threshold, rels);
|
|
88
|
+
align(a, b, 'top', threshold, rels);
|
|
89
|
+
align(a, b, 'left', threshold, rels);
|
|
90
|
+
align(a, b, 'right', threshold, rels);
|
|
91
|
+
centerAlign(a, b, 'x', threshold, rels);
|
|
92
|
+
centerAlign(a, b, 'y', threshold, rels);
|
|
93
|
+
|
|
94
|
+
// Горизонтальный gap / overlap
|
|
95
|
+
if (b.left > a.right) {
|
|
96
|
+
rels.push(`${a.name} → ${b.name}: gap=${+(b.left - a.right).toFixed(0)}px`);
|
|
97
|
+
} else if (a.left > b.right) {
|
|
98
|
+
rels.push(`${b.name} → ${a.name}: gap=${+(a.left - b.right).toFixed(0)}px`);
|
|
99
|
+
} else {
|
|
100
|
+
const ox = Math.min(a.right, b.right) - Math.max(a.left, b.left);
|
|
101
|
+
if (ox > 0) rels.push(`${a.name} ↔ ${b.name}: overlap=${+ox.toFixed(0)}px`);
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
// Вертикальный gap / overlap
|
|
105
|
+
if (b.top > a.bottom) {
|
|
106
|
+
rels.push(`${a.name} ↓ ${b.name}: vgap=${+(b.top - a.bottom).toFixed(0)}px`);
|
|
107
|
+
} else if (a.top > b.bottom) {
|
|
108
|
+
rels.push(`${b.name} ↓ ${a.name}: vgap=${+(a.top - b.bottom).toFixed(0)}px`);
|
|
109
|
+
} else {
|
|
110
|
+
const oy = Math.min(a.bottom, b.bottom) - Math.max(a.top, b.top);
|
|
111
|
+
if (oy > 0) rels.push(`${a.name} ↔ ${b.name}: voverlap=${+oy.toFixed(0)}px`);
|
|
112
|
+
}
|
|
113
|
+
}
|
|
114
|
+
}
|
|
115
|
+
}
|
|
116
|
+
|
|
117
|
+
const allIssues = [];
|
|
118
|
+
if (issues) {
|
|
119
|
+
allIssues.push(...analyzeIssues(elements, rels, threshold));
|
|
120
|
+
if (styleAware && container) {
|
|
121
|
+
allIssues.push(...analyzeStyleIssues(elements, container, threshold));
|
|
122
|
+
}
|
|
123
|
+
}
|
|
124
|
+
|
|
125
|
+
return { elements, relations: rels, issues: allIssues, format };
|
|
126
|
+
}
|
|
127
|
+
|
|
128
|
+
/**
|
|
129
|
+
* Проверка выравнивания по краю (bottom/top/left/right).
|
|
130
|
+
* @param {Element} a
|
|
131
|
+
* @param {Element} b
|
|
132
|
+
* @param {'bottom'|'top'|'left'|'right'} edge
|
|
133
|
+
* @param {number} threshold
|
|
134
|
+
* @param {string[]} rels — мутабельный массив для добавления relation-строк
|
|
135
|
+
*/
|
|
136
|
+
function align(a, b, edge, threshold, rels) {
|
|
137
|
+
const diff = Math.abs(a[edge] - b[edge]);
|
|
138
|
+
if (diff < threshold) {
|
|
139
|
+
rels.push(`${a.name} ↔ ${b.name}: ${edge}=${a[edge]}`);
|
|
140
|
+
} else if (diff < threshold + 5) {
|
|
141
|
+
rels.push(`${a.name} ↔ ${b.name}: misalign-${edge}=${diff.toFixed(0)}px`);
|
|
142
|
+
}
|
|
143
|
+
}
|
|
144
|
+
|
|
145
|
+
/**
|
|
146
|
+
* Проверка выравнивания по центру (x или y).
|
|
147
|
+
* @param {Element} a
|
|
148
|
+
* @param {Element} b
|
|
149
|
+
* @param {'x'|'y'} axis
|
|
150
|
+
* @param {number} threshold
|
|
151
|
+
* @param {string[]} rels
|
|
152
|
+
*/
|
|
153
|
+
function centerAlign(a, b, axis, threshold, rels) {
|
|
154
|
+
const aC = axis === 'x' ? (a.left + a.right) / 2 : (a.top + a.bottom) / 2;
|
|
155
|
+
const bC = axis === 'x' ? (b.left + b.right) / 2 : (b.top + b.bottom) / 2;
|
|
156
|
+
const diff = Math.abs(aC - bC);
|
|
157
|
+
if (diff < threshold) {
|
|
158
|
+
rels.push(`${a.name} ↔ ${b.name}: center-${axis}=${+aC.toFixed(1)}`);
|
|
159
|
+
} else if (diff < threshold + 5) {
|
|
160
|
+
rels.push(`${a.name} ↔ ${b.name}: misalign-center-${axis}=${diff.toFixed(0)}px`);
|
|
161
|
+
}
|
|
162
|
+
}
|
|
163
|
+
|
|
164
|
+
/**
|
|
165
|
+
* Анализирует отношения и генерирует список проблем с подсказками.
|
|
166
|
+
* @param {Element[]} elements
|
|
167
|
+
* @param {string[]} rels
|
|
168
|
+
* @param {number} threshold
|
|
169
|
+
* @returns {string[]}
|
|
170
|
+
*/
|
|
171
|
+
function analyzeIssues(elements, rels, threshold) {
|
|
172
|
+
const issues = [];
|
|
173
|
+
|
|
174
|
+
for (const r of rels) {
|
|
175
|
+
// Misalign — предложить align-items / align-self
|
|
176
|
+
if (r.includes('misalign-bottom') || r.includes('misalign-top')) {
|
|
177
|
+
issues.push(`⚠ ${r}
|
|
178
|
+
→ попробуй align-items: center или baseline на родителе`);
|
|
179
|
+
}
|
|
180
|
+
if (r.includes('misalign-left') || r.includes('misalign-right')) {
|
|
181
|
+
issues.push(`⚠ ${r}
|
|
182
|
+
→ попробуй justify-content: center или justify-items на родителе`);
|
|
183
|
+
}
|
|
184
|
+
if (r.includes('misalign-center-x') || r.includes('misalign-center-y')) {
|
|
185
|
+
issues.push(`⚠ ${r}
|
|
186
|
+
→ проверь margin/padding — элементы не отцентрированы`);
|
|
187
|
+
}
|
|
188
|
+
|
|
189
|
+
// Overlap — потенциальный баг
|
|
190
|
+
if (r.includes('overlap=') && !r.includes('voverlap')) {
|
|
191
|
+
issues.push(`⚠ ${r}
|
|
192
|
+
→ элементы перекрываются по горизонтали. Проверь width или flex-shrink.`);
|
|
193
|
+
}
|
|
194
|
+
if (r.includes('voverlap=')) {
|
|
195
|
+
issues.push(`⚠ ${r}
|
|
196
|
+
→ элементы перекрываются по вертикали. Проверь height или margin.`);
|
|
197
|
+
}
|
|
198
|
+
}
|
|
199
|
+
|
|
200
|
+
// Неравномерные gaps между соседними элементами
|
|
201
|
+
for (let i = 0; i < elements.length - 1; i++) {
|
|
202
|
+
for (let j = i + 1; j < elements.length; j++) {
|
|
203
|
+
const a = elements[i], b = elements[j];
|
|
204
|
+
// Значительный разрыв (gap > 3x среднего размера элемента)
|
|
205
|
+
const avgW = (a.w + b.w) / 2;
|
|
206
|
+
if (b.left > a.right) {
|
|
207
|
+
const gap = b.left - a.right;
|
|
208
|
+
if (gap > avgW * 3 && gap > 20) {
|
|
209
|
+
issues.push(`⚠ ${a.name} → ${b.name}: большой gap=${+(gap.toFixed(0))}px (>3x средняя ширина ${+avgW.toFixed(0)}px)`);
|
|
210
|
+
}
|
|
211
|
+
}
|
|
212
|
+
}
|
|
213
|
+
}
|
|
214
|
+
|
|
215
|
+
return issues;
|
|
216
|
+
}
|
|
217
|
+
|
|
218
|
+
/**
|
|
219
|
+
* Сравнивает заявленные CSS-свойства родителя с фактическими измерениями.
|
|
220
|
+
* @param {Element[]} elements — позиции детей
|
|
221
|
+
* @param {string} containerSelector — CSS-селектор родителя
|
|
222
|
+
* @param {number} threshold
|
|
223
|
+
* @returns {string[]}
|
|
224
|
+
*/
|
|
225
|
+
function analyzeStyleIssues(elements, containerSelector, threshold) {
|
|
226
|
+
const parent = document.querySelector(containerSelector);
|
|
227
|
+
if (!parent || elements.length < 1) return [];
|
|
228
|
+
|
|
229
|
+
const style = getComputedStyle(parent);
|
|
230
|
+
const display = style.display;
|
|
231
|
+
const issues = [];
|
|
232
|
+
|
|
233
|
+
// Читаем заявленный gap
|
|
234
|
+
const declaredGap = parseFloat(style.gap) || parseFloat(style.columnGap) || 0;
|
|
235
|
+
|
|
236
|
+
// Читаем align-items / justify-content
|
|
237
|
+
const alignItems = style.alignItems;
|
|
238
|
+
const justifyContent = style.justifyContent;
|
|
239
|
+
|
|
240
|
+
// Измеряем фактические gaps между соседними детьми
|
|
241
|
+
const gaps = [];
|
|
242
|
+
if (elements.length >= 2) {
|
|
243
|
+
for (let i = 1; i < elements.length; i++) {
|
|
244
|
+
const prev = elements[i - 1];
|
|
245
|
+
const curr = elements[i];
|
|
246
|
+
if (curr.left > prev.right) gaps.push(curr.left - prev.right);
|
|
247
|
+
if (curr.top > prev.bottom) gaps.push(curr.top - prev.bottom);
|
|
248
|
+
}
|
|
249
|
+
}
|
|
250
|
+
|
|
251
|
+
// 1. Проверка: заявленный gap != фактический
|
|
252
|
+
if (declaredGap > 0 && gaps.length > 0) {
|
|
253
|
+
const avgGap = gaps.reduce((s, g) => s + g, 0) / gaps.length;
|
|
254
|
+
if (Math.abs(avgGap - declaredGap) > threshold) {
|
|
255
|
+
issues.push(`⚠ CSS gap: ${declaredGap}px → фактический ≈ ${+avgGap.toFixed(0)}px (разница ${+(Math.abs(avgGap - declaredGap)).toFixed(0)}px)`);
|
|
256
|
+
}
|
|
257
|
+
}
|
|
258
|
+
|
|
259
|
+
// 2. Проверка align-items
|
|
260
|
+
if (display === 'flex' || display === 'inline-flex') {
|
|
261
|
+
const flexDir = style.flexDirection === 'column' || style.flexDirection === 'column-reverse';
|
|
262
|
+
|
|
263
|
+
if (alignItems === 'center') {
|
|
264
|
+
// Все дети должны быть отцентрированы по cross-axis
|
|
265
|
+
const parentRect = parent.getBoundingClientRect();
|
|
266
|
+
const parentCenter = flexDir
|
|
267
|
+
? (parentRect.left + parentRect.right) / 2
|
|
268
|
+
: (parentRect.top + parentRect.bottom) / 2;
|
|
269
|
+
|
|
270
|
+
let misCentered = false;
|
|
271
|
+
for (const el of elements) {
|
|
272
|
+
const elCenter = flexDir
|
|
273
|
+
? (el.left + el.right) / 2
|
|
274
|
+
: (el.top + el.bottom) / 2;
|
|
275
|
+
if (Math.abs(elCenter - parentCenter) > threshold) {
|
|
276
|
+
misCentered = true;
|
|
277
|
+
break;
|
|
278
|
+
}
|
|
279
|
+
}
|
|
280
|
+
if (misCentered) {
|
|
281
|
+
issues.push(`⚠ align-items: center задан, но дети не отцентрированы`);
|
|
282
|
+
}
|
|
283
|
+
}
|
|
284
|
+
|
|
285
|
+
if (alignItems === 'flex-start' || alignItems === 'start') {
|
|
286
|
+
const parentRect = parent.getBoundingClientRect();
|
|
287
|
+
const parentEdge = flexDir ? parentRect.left : parentRect.top;
|
|
288
|
+
let misAligned = false;
|
|
289
|
+
for (const el of elements) {
|
|
290
|
+
const elEdge = flexDir ? el.left : el.top;
|
|
291
|
+
if (Math.abs(elEdge - parentEdge) > threshold + 5) {
|
|
292
|
+
misAligned = true;
|
|
293
|
+
break;
|
|
294
|
+
}
|
|
295
|
+
}
|
|
296
|
+
if (misAligned) {
|
|
297
|
+
issues.push(`⚠ align-items: flex-start задан, но дети не прижаты к краю`);
|
|
298
|
+
}
|
|
299
|
+
}
|
|
300
|
+
}
|
|
301
|
+
|
|
302
|
+
// 3. Проверка: grid
|
|
303
|
+
if (display === 'grid' || display === 'inline-grid') {
|
|
304
|
+
const cols = style.gridTemplateColumns;
|
|
305
|
+
if (cols && cols !== 'none') {
|
|
306
|
+
// Проверяем, что дети выровнены по grid-колонкам
|
|
307
|
+
issues.push(`ℹ grid-template-columns: ${cols}`);
|
|
308
|
+
}
|
|
309
|
+
}
|
|
310
|
+
|
|
311
|
+
// 4. Проверка justify-content
|
|
312
|
+
if (justifyContent === 'space-between') {
|
|
313
|
+
// Первый и последний должны быть у краёв
|
|
314
|
+
if (elements.length >= 2) {
|
|
315
|
+
const parentRect = parent.getBoundingClientRect();
|
|
316
|
+
const first = elements[0], last = elements[elements.length - 1];
|
|
317
|
+
if (Math.abs(first.left - parentRect.left) > threshold + 5) {
|
|
318
|
+
issues.push(`⚠ justify-content: space-between, но первый элемент не у левого края`);
|
|
319
|
+
}
|
|
320
|
+
if (Math.abs(parentRect.right - last.right) > threshold + 5) {
|
|
321
|
+
issues.push(`⚠ justify-content: space-between, но последний элемент не у правого края`);
|
|
322
|
+
}
|
|
323
|
+
}
|
|
324
|
+
}
|
|
325
|
+
|
|
326
|
+
// 5. Проверка gap consistency
|
|
327
|
+
if (gaps.length >= 2) {
|
|
328
|
+
const minGap = Math.min(...gaps);
|
|
329
|
+
const maxGap = Math.max(...gaps);
|
|
330
|
+
if (maxGap - minGap > threshold + 3) {
|
|
331
|
+
issues.push(`⚠ Неравномерные gaps: от ${+minGap.toFixed(0)}px до ${+maxGap.toFixed(0)}px (разброс ${+(maxGap - minGap).toFixed(0)}px)`);
|
|
332
|
+
}
|
|
333
|
+
}
|
|
334
|
+
|
|
335
|
+
return issues;
|
|
336
|
+
}
|
|
337
|
+
|
|
338
|
+
/**
|
|
339
|
+
* Сериализация в TOON (Token-Oriented Object Notation).
|
|
340
|
+
* Компактнее markdown на ~30%, парсится toonq/serde_toon.
|
|
341
|
+
* @param {ProbeResult} result
|
|
342
|
+
* @returns {string}
|
|
343
|
+
*/
|
|
344
|
+
function formatToon({ elements, relations, issues = [] }) {
|
|
345
|
+
const keys = 'name,text,top,left,bottom,right,w,h';
|
|
346
|
+
const lines = [`[${elements.length}]{${keys}}:`];
|
|
347
|
+
for (const e of elements) {
|
|
348
|
+
lines.push(` ${e.name},${e.text || ''},${e.top},${e.left},${e.bottom},${e.right},${e.w},${e.h}`);
|
|
349
|
+
}
|
|
350
|
+
if (relations.length > 0) {
|
|
351
|
+
lines.push('', `# Relations [${relations.length}]`);
|
|
352
|
+
for (const r of relations) {
|
|
353
|
+
lines.push(` ${r}`);
|
|
354
|
+
}
|
|
355
|
+
}
|
|
356
|
+
if (issues.length > 0) {
|
|
357
|
+
lines.push('', `# Issues [${issues.length}]`);
|
|
358
|
+
for (const issue of issues) {
|
|
359
|
+
lines.push(` ${issue.replace(/\n /g, ' | ')}`);
|
|
360
|
+
}
|
|
361
|
+
}
|
|
362
|
+
return lines.join('\n');
|
|
363
|
+
}
|
|
364
|
+
|
|
365
|
+
/**
|
|
366
|
+
* Рендерит structured data в markdown.
|
|
367
|
+
* @param {ProbeResult} result
|
|
368
|
+
* @returns {string}
|
|
369
|
+
*/
|
|
370
|
+
function formatMarkdown({ elements, relations, issues = [] }) {
|
|
371
|
+
const lines = [];
|
|
372
|
+
lines.push('### Elements', '');
|
|
373
|
+
lines.push('| name | text | top | left | bottom | right | w | h |');
|
|
374
|
+
lines.push('|------|------|-----|------|--------|-------|-----|-----|');
|
|
375
|
+
for (const e of elements) {
|
|
376
|
+
lines.push(`| ${e.name} | ${e.text} | ${e.top} | ${e.left} | ${e.bottom} | ${e.right} | ${e.w} | ${e.h} |`);
|
|
377
|
+
}
|
|
378
|
+
if (relations.length > 0) {
|
|
379
|
+
lines.push('', '### Relations', '');
|
|
380
|
+
for (const r of relations) {
|
|
381
|
+
lines.push(`- ${r}`);
|
|
382
|
+
}
|
|
383
|
+
}
|
|
384
|
+
if (issues.length > 0) {
|
|
385
|
+
lines.push('', '### Issues', '');
|
|
386
|
+
for (const issue of issues) {
|
|
387
|
+
lines.push(issue);
|
|
388
|
+
}
|
|
389
|
+
}
|
|
390
|
+
return lines.join('\n');
|
|
391
|
+
}
|
|
392
|
+
|
|
393
|
+
// ---------------------------------------------------------------------------
|
|
394
|
+
// Публичное API
|
|
395
|
+
// ---------------------------------------------------------------------------
|
|
396
|
+
|
|
397
|
+
/**
|
|
398
|
+
* layoutProbe(options) → markdown или TOON-строка.
|
|
399
|
+
* Основной интерфейс для чтения агентом.
|
|
400
|
+
* @param {Object} options
|
|
401
|
+
* @param {'markdown'|'toon'} [options.format='markdown'] — формат вывода
|
|
402
|
+
* @returns {string}
|
|
403
|
+
*/
|
|
404
|
+
export function layoutProbe(options = {}) {
|
|
405
|
+
const result = probe(options);
|
|
406
|
+
return result.format === 'toon'
|
|
407
|
+
? formatToon(result)
|
|
408
|
+
: formatMarkdown(result);
|
|
409
|
+
}
|
|
410
|
+
|
|
411
|
+
/**
|
|
412
|
+
* layoutProbe.structured(options) → { elements, relations }.
|
|
413
|
+
* Для программного использования (compare, автоматизация).
|
|
414
|
+
* @param {Object} options
|
|
415
|
+
* @returns {ProbeResult}
|
|
416
|
+
*/
|
|
417
|
+
layoutProbe.structured = function (options = {}) {
|
|
418
|
+
return probe(options);
|
|
419
|
+
};
|
|
420
|
+
|
|
421
|
+
/**
|
|
422
|
+
* layoutProbe.compare(before, after) → diff-строка.
|
|
423
|
+
* Принимает structured-объекты (результат layoutProbe.structured()).
|
|
424
|
+
* @param {ProbeResult} before
|
|
425
|
+
* @param {ProbeResult} after
|
|
426
|
+
* @returns {string} diff в формате "~ name.key: old → new" / "+/- relation: ..."
|
|
427
|
+
*/
|
|
428
|
+
layoutProbe.compare = function (before, after) {
|
|
429
|
+
const changes = [];
|
|
430
|
+
|
|
431
|
+
// Индексируем элементы по имени
|
|
432
|
+
const beforeMap = Object.fromEntries((before.elements || []).map(e => [e.name, e]));
|
|
433
|
+
const afterMap = Object.fromEntries((after.elements || []).map(e => [e.name, e]));
|
|
434
|
+
|
|
435
|
+
const allNames = new Set([
|
|
436
|
+
...Object.keys(beforeMap),
|
|
437
|
+
...Object.keys(afterMap),
|
|
438
|
+
]);
|
|
439
|
+
|
|
440
|
+
for (const name of allNames) {
|
|
441
|
+
const b = beforeMap[name];
|
|
442
|
+
const a = afterMap[name];
|
|
443
|
+
|
|
444
|
+
if (!b) {
|
|
445
|
+
changes.push(`+ ${name}: NEW (${a.text || '-'}, ${a.top},${a.left}→${a.bottom},${a.right})`);
|
|
446
|
+
continue;
|
|
447
|
+
}
|
|
448
|
+
if (!a) {
|
|
449
|
+
changes.push(`- ${name}: REMOVED`);
|
|
450
|
+
continue;
|
|
451
|
+
}
|
|
452
|
+
|
|
453
|
+
for (const key of ['text', 'top', 'left', 'bottom', 'right', 'w', 'h']) {
|
|
454
|
+
if (b[key] !== a[key]) {
|
|
455
|
+
changes.push(`~ ${name}.${key}: ${b[key]} → ${a[key]}`);
|
|
456
|
+
}
|
|
457
|
+
}
|
|
458
|
+
}
|
|
459
|
+
|
|
460
|
+
// Relations
|
|
461
|
+
const beforeRels = before.relations || [];
|
|
462
|
+
const afterRels = after.relations || [];
|
|
463
|
+
|
|
464
|
+
for (const r of afterRels) {
|
|
465
|
+
if (!beforeRels.includes(r)) changes.push(`+ relation: ${r}`);
|
|
466
|
+
}
|
|
467
|
+
for (const r of beforeRels) {
|
|
468
|
+
if (!afterRels.includes(r)) changes.push(`- relation: ${r}`);
|
|
469
|
+
}
|
|
470
|
+
|
|
471
|
+
return changes.length > 0 ? changes.join('\n') : 'No changes detected.';
|
|
472
|
+
};
|
|
473
|
+
|
|
474
|
+
// ---------------------------------------------------------------------------
|
|
475
|
+
// Шаблоны для частых проверок
|
|
476
|
+
// ---------------------------------------------------------------------------
|
|
477
|
+
|
|
478
|
+
/**
|
|
479
|
+
* Собрать детей родительского элемента как именованный объект.
|
|
480
|
+
* @param {string} parentSelector — CSS-селектор родителя
|
|
481
|
+
* @returns {Object<string,HTMLElement>} { 'child-0': el, 'child-1': el, ... }
|
|
482
|
+
*/
|
|
483
|
+
function collectChildren(parentSelector) {
|
|
484
|
+
const parent = document.querySelector(parentSelector);
|
|
485
|
+
if (!parent) return {};
|
|
486
|
+
const result = {};
|
|
487
|
+
[...parent.children].forEach((el, i) => {
|
|
488
|
+
result[`child-${i}`] = el;
|
|
489
|
+
});
|
|
490
|
+
return result;
|
|
491
|
+
}
|
|
492
|
+
|
|
493
|
+
/**
|
|
494
|
+
* Шаблон: flex-строка.
|
|
495
|
+
* Все прямые дети выбранного элемента — проверка горизонтального выравнивания.
|
|
496
|
+
*
|
|
497
|
+
* @param {string} parentSelector — CSS-селектор родителя (например, '.row')
|
|
498
|
+
* @param {Object} [options={}] — дополнительные опции layoutProbe
|
|
499
|
+
* @returns {string} markdown
|
|
500
|
+
*
|
|
501
|
+
* @example
|
|
502
|
+
* layoutProbe.row('.react-js-cron-field')
|
|
503
|
+
*/
|
|
504
|
+
layoutProbe.row = function (parentSelector, options = {}) {
|
|
505
|
+
const children = collectChildren(parentSelector);
|
|
506
|
+
return layoutProbe({ ...options, container: parentSelector, styleAware: options.styleAware !== false, elements: Object.values(children) });
|
|
507
|
+
};
|
|
508
|
+
|
|
509
|
+
/**
|
|
510
|
+
* Шаблон: flex-колонка.
|
|
511
|
+
* Все прямые дети — проверка вертикального выравнивания.
|
|
512
|
+
*
|
|
513
|
+
* @param {string} parentSelector
|
|
514
|
+
* @param {Object} [options={}]
|
|
515
|
+
* @returns {string} markdown
|
|
516
|
+
*
|
|
517
|
+
* @example
|
|
518
|
+
* layoutProbe.column('.form-stack')
|
|
519
|
+
*/
|
|
520
|
+
layoutProbe.column = function (parentSelector, options = {}) {
|
|
521
|
+
const children = collectChildren(parentSelector);
|
|
522
|
+
return layoutProbe({ ...options, container: parentSelector, styleAware: options.styleAware !== false, elements: Object.values(children) });
|
|
523
|
+
};
|
|
524
|
+
|
|
525
|
+
/**
|
|
526
|
+
* Шаблон: grid-сетка.
|
|
527
|
+
* Все прямые дети — проверка и горизонтального, и вертикального выравнивания.
|
|
528
|
+
*
|
|
529
|
+
* @param {string} parentSelector
|
|
530
|
+
* @param {Object} [options={}]
|
|
531
|
+
* @returns {string} markdown
|
|
532
|
+
*
|
|
533
|
+
* @example
|
|
534
|
+
* layoutProbe.grid('.card-grid')
|
|
535
|
+
*/
|
|
536
|
+
layoutProbe.grid = function (parentSelector, options = {}) {
|
|
537
|
+
const children = collectChildren(parentSelector);
|
|
538
|
+
return layoutProbe({ ...options, container: parentSelector, styleAware: options.styleAware !== false, elements: Object.values(children) });
|
|
539
|
+
};
|