@floless/app 0.172.0 → 0.172.1

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.
@@ -0,0 +1,380 @@
1
+ // The section sketcher's model, with no screen in it (epic #3382 slice P5, design §7.4).
2
+ //
3
+ // The sketcher edits ONE kind-version-2 definition (`floless.section-profile`, `steel-custom-sections.js`): a name, a prefix, a
4
+ // group, sizes, validity conditions, an outer loop and holes of corner points written as formulas over the sizes, and the order
5
+ // the sizes are written in a name. This module holds what a person, the AI chat and the server all share, so nobody has a
6
+ // private reading of a draft:
7
+ //
8
+ // - the DRAFT, a plain object the sketcher edits and the chat writes (`normalizeDraft` checks its shape, never its meaning);
9
+ // - the three templates (rectangle, L and T) and the blank start;
10
+ // - `draftToDefinition` / `definitionToDraft`, the draft and the definition it saves as;
11
+ // - `analyzeDraft`: everything the sketcher shows (the drawing, the checks, area and weight at the default sizes, and an
12
+ // honest "where this shape can go"), worked out by the SAME checker and evaluator the model uses, never a second one.
13
+ //
14
+ // A draft may be unfinished: a name still empty, a corner still missing. That is not an error, it is a draft, and the checks say
15
+ // what is left. Only SAVING needs a shape that works, and even then the reasons are said in words (the "nothing to act on"
16
+ // carve-out: a shape with no valid section is not something to place on a member).
17
+ //
18
+ // Each size remembers where it came from — the paper sketch, the text, the person, or an ASSUMPTION the AI had to make — so the
19
+ // sketcher can outline the assumed ones. That record is the draft's; it is not part of the saved definition.
20
+
21
+ import {
22
+ SECTION_PROFILE_KIND, canonicalName, checkSectionProfileV2, customKgPerM, densityFor, evalFormulaV2, evaluatePredicate,
23
+ evaluateSectionV2, parseFormulaV2, parsePredicate, v2ReadersBlock, SIZE_LIMITS,
24
+ } from './steel-custom-sections.js';
25
+
26
+ export const MY_SHAPES_ID = 'my-shapes';
27
+ export const MY_SHAPES_NAME = 'My shapes';
28
+ export const DEFAULT_GROUP = 'My shapes';
29
+ /** Where each size's value came from. `assumed` is the one the sketcher outlines in amber. */
30
+ export const SIZE_SOURCES = Object.freeze(['sketch', 'text', 'person', 'assumed']);
31
+ export const SOURCE_WORDS = Object.freeze({
32
+ sketch: 'read from the sketch', text: 'taken from the description', person: 'typed by you', assumed: 'assumed, not given',
33
+ });
34
+ export const SEPARATORS = Object.freeze(['*', '-', 'x']);
35
+ export const TEMPLATE_IDS = Object.freeze(['rectangle', 'l', 't']);
36
+
37
+ export const LIMITS = Object.freeze({ sizes: 12, corners: 64, holes: 4, text: 400, predicates: 8 });
38
+
39
+ const isObj = (v) => !!v && typeof v === 'object' && !Array.isArray(v);
40
+ const isNum = (v) => typeof v === 'number' && Number.isFinite(v);
41
+ const round6 = (v) => Math.round(v * 1e6) / 1e6;
42
+
43
+ // ---- the draft ------------------------------------------------------------------------------------------------
44
+
45
+ export function blankDraft() {
46
+ return { name: '', description: '', prefix: '', group: DEFAULT_GROUP, sizes: [], predicates: [], outer: [], holes: [], order: [], separator: '*' };
47
+ }
48
+
49
+ const size = (symbol, label, defaultValue, extra = {}) => ({ symbol, label, kind: 'length', default: defaultValue, source: 'person', ...extra });
50
+
51
+ /** A template is a normal draft: every number and formula in it is the person's to change. Shapes are centred on their own origin. */
52
+ export function templateDraft(id, name = '') {
53
+ if (id === 'rectangle') {
54
+ return {
55
+ ...blankDraft(), name: name || 'Rectangle', prefix: 'RECT', description: 'A solid rectangle.',
56
+ sizes: [size('h', 'Height', 200, { min: 5, max: 2000 }), size('b', 'Width', 100, { min: 5, max: 2000 })],
57
+ outer: [['-b/2', '-h/2'], ['b/2', '-h/2'], ['b/2', 'h/2'], ['-b/2', 'h/2']], order: ['h', 'b'],
58
+ };
59
+ }
60
+ if (id === 'l') {
61
+ return {
62
+ ...blankDraft(), name: name || 'Angle', prefix: 'ANG', description: 'An L shape with legs of different length and one thickness.',
63
+ sizes: [size('h', 'Tall leg', 150, { min: 20, max: 1000 }), size('b', 'Wide leg', 100, { min: 20, max: 1000 }), size('t', 'Thickness', 10, { min: 2, max: 60 })],
64
+ predicates: [{ when: 't < b and t < h', reason: 'The thickness must be less than both legs.' }],
65
+ outer: [['-b/2', '-h/2'], ['b/2', '-h/2'], ['b/2', '-h/2 + t'], ['-b/2 + t', '-h/2 + t'], ['-b/2 + t', 'h/2'], ['-b/2', 'h/2']], order: ['h', 'b', 't'],
66
+ };
67
+ }
68
+ if (id === 't') {
69
+ return {
70
+ ...blankDraft(), name: name || 'Tee', prefix: 'TEE', description: 'A T shape: a flange across the top and a stem below it.',
71
+ sizes: [size('h', 'Overall height', 200, { min: 20, max: 1000 }), size('b', 'Flange width', 150, { min: 20, max: 1000 }),
72
+ size('tw', 'Stem thickness', 10, { min: 2, max: 60 }), size('tf', 'Flange thickness', 14, { min: 2, max: 60 })],
73
+ predicates: [{ when: 'tw < b and tf < h', reason: 'The stem must be thinner than the flange is wide, and the flange thinner than the whole height.' }],
74
+ outer: [['-b/2', 'h/2'], ['b/2', 'h/2'], ['b/2', 'h/2 - tf'], ['tw/2', 'h/2 - tf'], ['tw/2', '-h/2'], ['-tw/2', '-h/2'], ['-tw/2', 'h/2 - tf'], ['-b/2', 'h/2 - tf']],
75
+ order: ['h', 'b', 'tw', 'tf'],
76
+ };
77
+ }
78
+ return blankDraft();
79
+ }
80
+
81
+ const textOf = (v) => (typeof v === 'number' ? String(v) : v);
82
+
83
+ /**
84
+ * Check the SHAPE of a draft (types, counts, lengths), never what it means. A person's unfinished sketch passes; text where a
85
+ * number belongs does not. Answers `{ draft }` with exactly the fields the sketcher uses, or `{ problems }` in plain words.
86
+ */
87
+ export function normalizeDraft(raw) {
88
+ const problems = [];
89
+ if (!isObj(raw)) return { problems: ['The sketch must be an object with a name, sizes and corner points.'] };
90
+ const known = new Set(['name', 'description', 'prefix', 'group', 'sizes', 'predicates', 'outer', 'holes', 'order', 'separator']);
91
+ for (const key of Object.keys(raw)) if (!known.has(key)) problems.push(`The sketch has a field “${key}” the sketcher does not use.`);
92
+ const text = (key, max, fallback = '') => {
93
+ const v = raw[key];
94
+ if (v === undefined || v === null) return fallback;
95
+ if (typeof v !== 'string' || v.length > max) { problems.push(`“${key}” must be text of at most ${max} characters.`); return fallback; }
96
+ return v;
97
+ };
98
+ const out = blankDraft();
99
+ out.name = text('name', 80); out.description = text('description', 500); out.prefix = text('prefix', 16); out.group = text('group', 60, DEFAULT_GROUP) || DEFAULT_GROUP;
100
+
101
+ const sizes = raw.sizes === undefined ? [] : raw.sizes;
102
+ if (!Array.isArray(sizes) || sizes.length > LIMITS.sizes) problems.push(`The sketch may have at most ${LIMITS.sizes} sizes.`);
103
+ else {
104
+ sizes.forEach((s, i) => {
105
+ const at = `Size ${i + 1}`;
106
+ if (!isObj(s)) { problems.push(`${at} must be an object with a symbol, a label, a kind and a default.`); return; }
107
+ for (const key of Object.keys(s)) if (!['symbol', 'label', 'kind', 'default', 'min', 'max', 'source'].includes(key)) problems.push(`${at} has a field “${key}” the sketcher does not use.`);
108
+ if (typeof s.symbol !== 'string' || s.symbol.length > 32) problems.push(`${at} needs a symbol of at most 32 characters.`);
109
+ if (typeof s.label !== 'string' || s.label.length > 80) problems.push(`${at} needs a label of at most 80 characters.`);
110
+ if (!Object.hasOwn(SIZE_LIMITS, s.kind)) problems.push(`${at} must be a length, an angle or a number.`);
111
+ if (!isNum(s.default)) problems.push(`${at} needs a default that is a number.`);
112
+ for (const key of ['min', 'max']) if (s[key] !== undefined && s[key] !== null && !isNum(s[key])) problems.push(`${at}: “${key}” must be a number.`);
113
+ const source = s.source === undefined ? 'person' : s.source;
114
+ if (!SIZE_SOURCES.includes(source)) problems.push(`${at}: where the value came from must be one of ${SIZE_SOURCES.join(', ')}.`);
115
+ out.sizes.push({
116
+ symbol: String(s.symbol ?? ''), label: String(s.label ?? ''), kind: s.kind, default: s.default, source,
117
+ ...(isNum(s.min) ? { min: s.min } : {}), ...(isNum(s.max) ? { max: s.max } : {}),
118
+ });
119
+ });
120
+ }
121
+
122
+ const preds = raw.predicates === undefined ? [] : raw.predicates;
123
+ if (!Array.isArray(preds) || preds.length > LIMITS.predicates) problems.push(`The sketch may have at most ${LIMITS.predicates} conditions.`);
124
+ else preds.forEach((p, i) => {
125
+ if (!isObj(p) || typeof p.when !== 'string' || typeof p.reason !== 'string' || p.when.length > LIMITS.text || p.reason.length > 200
126
+ || Object.keys(p).some((k) => k !== 'when' && k !== 'reason')) problems.push(`Condition ${i + 1} must be {when, reason}, both text.`);
127
+ else out.predicates.push({ when: p.when, reason: p.reason });
128
+ });
129
+
130
+ const loop = (points, name) => {
131
+ if (!Array.isArray(points) || points.length > LIMITS.corners) { problems.push(`${name} may have at most ${LIMITS.corners} corners.`); return []; }
132
+ const result = [];
133
+ points.forEach((p, i) => {
134
+ const ok = Array.isArray(p) && p.length === 2 && p.every((c) => (typeof c === 'string' && c.length <= LIMITS.text) || isNum(c));
135
+ if (!ok) problems.push(`${name} corner ${i + 1} must be a pair [x, y] of numbers or formulas.`);
136
+ else result.push([textOf(p[0]), textOf(p[1])]);
137
+ });
138
+ return result;
139
+ };
140
+ out.outer = loop(raw.outer === undefined ? [] : raw.outer, 'The outline');
141
+ const holes = raw.holes === undefined ? [] : raw.holes;
142
+ if (!Array.isArray(holes) || holes.length > LIMITS.holes) problems.push(`The sketch may have at most ${LIMITS.holes} holes.`);
143
+ else out.holes = holes.map((h, i) => loop(h, `Hole ${i + 1}`));
144
+
145
+ const order = raw.order === undefined ? out.sizes.map((s) => s.symbol) : raw.order;
146
+ if (!Array.isArray(order) || order.length > LIMITS.sizes || order.some((s) => typeof s !== 'string')) problems.push('The name order must be a list of size symbols.');
147
+ else out.order = order;
148
+ const separator = raw.separator === undefined ? '*' : raw.separator;
149
+ if (!SEPARATORS.includes(separator)) problems.push(`The separator between sizes in the name must be one of ${SEPARATORS.map((s) => `“${s}”`).join(', ')}.`);
150
+ else out.separator = separator;
151
+ return problems.length ? { problems } : { draft: out };
152
+ }
153
+
154
+ // ---- draft <-> definition -------------------------------------------------------------------------------------
155
+
156
+ /** A lower-case, dash-separated name for the definition id: “Chamfered plate” becomes “chamfered-plate”. */
157
+ export function slugOf(name) {
158
+ const slug = String(name ?? '').toLowerCase().normalize('NFKD').replace(/[^a-z0-9]+/g, '-').replace(/^-+|-+$/g, '').slice(0, 60).replace(/-+$/, '');
159
+ return slug || 'shape';
160
+ }
161
+
162
+ /** The order the sizes are written in a name: the draft's own list first, every size once, any it forgot last. */
163
+ export function effectiveOrder(draft) {
164
+ const symbols = draft.sizes.map((s) => s.symbol);
165
+ const seen = new Set();
166
+ const order = [];
167
+ for (const s of [...(draft.order ?? []), ...symbols]) if (symbols.includes(s) && !seen.has(s)) { seen.add(s); order.push(s); }
168
+ return order;
169
+ }
170
+
171
+ export function draftToPayload(draft) {
172
+ const tokens = [];
173
+ effectiveOrder(draft).forEach((symbol, i) => {
174
+ if (i > 0) tokens.push({ text: draft.separator || '*' });
175
+ tokens.push({ size: symbol });
176
+ });
177
+ const loopOf = (points) => points.map(([x, y]) => [x, y]);
178
+ return {
179
+ name: draft.name.trim(),
180
+ ...(draft.description.trim() ? { description: draft.description.trim() } : {}),
181
+ parameters: draft.sizes.map((s) => ({
182
+ symbol: s.symbol, label: s.label.trim(), kind: s.kind, default: s.default,
183
+ ...(isNum(s.min) || isNum(s.max) ? { typical: { ...(isNum(s.min) ? { min: s.min } : {}), ...(isNum(s.max) ? { max: s.max } : {}) } } : {}),
184
+ })),
185
+ ...(draft.predicates.length ? { predicates: draft.predicates.map((p) => ({ when: p.when, reason: p.reason })) } : {}),
186
+ grammar: { prefix: draft.prefix, tokens },
187
+ start: { outer: loopOf(draft.outer), holes: draft.holes.map(loopOf) },
188
+ };
189
+ }
190
+
191
+ /** The definition the draft saves as (`id` is what My shapes will give it; the evaluator needs one that is well formed). */
192
+ export function draftToDefinition(draft, slug = slugOf(draft.name), revision = 1) {
193
+ return { kind: SECTION_PROFILE_KIND, kindVersion: 2, id: `${MY_SHAPES_ID}/${slug}@${revision}`, payload: draftToPayload(draft) };
194
+ }
195
+
196
+ /**
197
+ * Open a saved definition in the sketcher again. Only what the sketcher can draw comes back: sizes, conditions, one start face
198
+ * of formula corners and a name of sizes and one separator. Anything else (named expressions, optional parts of a name, a round
199
+ * shape, a face at the end) answers in words why, and the person starts a new sketch instead of losing it silently.
200
+ */
201
+ export function definitionToDraft(definition) {
202
+ const p = definition?.payload;
203
+ if (!isObj(p) || definition.kind !== SECTION_PROFILE_KIND || definition.kindVersion !== 2) return { problems: ['FloLess can only open a shape made with the sketcher.'] };
204
+ const why = [];
205
+ if (Array.isArray(p.expressions) && p.expressions.length) why.push('it uses named expressions');
206
+ if (p.end) why.push('it has a different face at its end');
207
+ if (p.export) why.push('it is a round shape the sketcher does not draw');
208
+ if (!isObj(p.start)) why.push('it has no outline the sketcher can edit');
209
+ const tokens = p.grammar?.tokens ?? [];
210
+ const separators = new Set(tokens.filter((t) => typeof t.text === 'string').map((t) => t.text));
211
+ if (tokens.some((t) => Array.isArray(t.optional))) why.push('its name has optional parts');
212
+ if (separators.size > 1) why.push('its name uses different separators');
213
+ const corner = (pt) => !Array.isArray(pt) || pt.length !== 2;
214
+ if (isObj(p.start) && ([...(p.start.outer ?? []), ...(p.start.holes ?? []).flat()].some(corner))) why.push('it has rounded corners');
215
+ if (why.length) return { problems: [`The sketcher cannot open “${p.name ?? 'this shape'}” yet: ${why.join(', ')}. Start a new sketch, or keep using the saved shape as it is.`] };
216
+ const draft = {
217
+ name: p.name ?? '', description: p.description ?? '', prefix: p.grammar?.prefix ?? '', group: DEFAULT_GROUP,
218
+ sizes: (p.parameters ?? []).map((s) => ({
219
+ symbol: s.symbol, label: s.label, kind: s.kind, default: s.default, source: 'person',
220
+ ...(isNum(s.typical?.min) ? { min: s.typical.min } : {}), ...(isNum(s.typical?.max) ? { max: s.typical.max } : {}),
221
+ })),
222
+ predicates: (p.predicates ?? []).map((x) => ({ when: x.when, reason: x.reason })),
223
+ outer: (p.start?.outer ?? []).map(([x, y]) => [textOf(x), textOf(y)]),
224
+ holes: (p.start?.holes ?? []).map((h) => h.map(([x, y]) => [textOf(x), textOf(y)])),
225
+ order: tokens.filter((t) => typeof t.size === 'string').map((t) => t.size),
226
+ separator: [...separators][0] ?? '*',
227
+ };
228
+ const checked = normalizeDraft(draft);
229
+ return checked.draft ? { draft: checked.draft } : { problems: checked.problems };
230
+ }
231
+
232
+ // ---- what the sketcher shows ----------------------------------------------------------------------------------
233
+
234
+ /** Evaluate every corner of a loop at the default sizes. A corner that cannot be worked out is null, never a guess. */
235
+ function rawLoop(points, symbols, scope) {
236
+ return points.map(([x, y]) => {
237
+ try {
238
+ const fx = evalFormulaV2(parseFormulaV2(x, symbols), scope), fy = evalFormulaV2(parseFormulaV2(y, symbols), scope);
239
+ return Number.isFinite(fx) && Number.isFinite(fy) ? [round6(fx), round6(fy)] : null;
240
+ } catch { return null; }
241
+ });
242
+ }
243
+
244
+ const cross = (o, a, b) => (a[0] - o[0]) * (b[1] - o[1]) - (a[1] - o[1]) * (b[0] - o[0]);
245
+ function segmentsMeet(p1, p2, p3, p4) {
246
+ const d1 = cross(p3, p4, p1), d2 = cross(p3, p4, p2), d3 = cross(p1, p2, p3), d4 = cross(p1, p2, p4);
247
+ if (((d1 > 0 && d2 < 0) || (d1 < 0 && d2 > 0)) && ((d3 > 0 && d4 < 0) || (d3 < 0 && d4 > 0))) return true;
248
+ const on = (a, b, c) => Math.min(a[0], b[0]) <= c[0] && c[0] <= Math.max(a[0], b[0]) && Math.min(a[1], b[1]) <= c[1] && c[1] <= Math.max(a[1], b[1]);
249
+ return (d1 === 0 && on(p3, p4, p1)) || (d2 === 0 && on(p3, p4, p2)) || (d3 === 0 && on(p1, p2, p3)) || (d4 === 0 && on(p1, p2, p4));
250
+ }
251
+ /** The first two edges of a loop that cross or touch (1-based corner numbers), or null. Edges that share a corner are not a crossing. */
252
+ function selfCrossing(loop) {
253
+ const n = loop.length;
254
+ for (let i = 0; i < n; i += 1) {
255
+ for (let j = i + 1; j < n; j += 1) {
256
+ if (j === i + 1 || (i === 0 && j === n - 1)) continue;
257
+ if (segmentsMeet(loop[i], loop[(i + 1) % n], loop[j], loop[(j + 1) % n])) return [[i + 1, ((i + 1) % n) + 1], [j + 1, ((j + 1) % n) + 1]];
258
+ }
259
+ }
260
+ return null;
261
+ }
262
+
263
+ const STEEL_WORDS = 'steel, 7850 kg/m³';
264
+
265
+ /**
266
+ * Everything the sketcher shows about a draft. `others` is what the draft's prefix and name are checked against:
267
+ * `{ prefixes: [{ prefix, where }], mine: [{ slug, name }] }`, both optional.
268
+ * @returns {{ ok: boolean, problems: string[], checks: {id:string, ok:boolean, text:string}[], drawing: object, section: object|null,
269
+ * area: number|null, kgPerM: number|null, example: string|null, reach: {id:string, state:'yes'|'partly'|'no', text:string}[],
270
+ * notes: string[], assumed: string[], slug: string, replaces: string|null }}
271
+ */
272
+ export function analyzeDraft(draft, others = {}) {
273
+ const problems = [];
274
+ const notes = [];
275
+ const checks = [];
276
+ const symbols = new Set(draft.sizes.map((s) => s.symbol));
277
+ const defaults = Object.fromEntries(draft.sizes.map((s) => [s.symbol, s.default]));
278
+ const slug = slugOf(draft.name);
279
+
280
+ // Incomplete, said as what is left to do.
281
+ if (!draft.name.trim()) problems.push('Give the shape a name.');
282
+ if (!draft.prefix.trim()) problems.push('Give the shape a short prefix; it starts every name of this shape, such as “PL” in PL12*150.');
283
+ if (!draft.sizes.length) problems.push('Add at least one size.');
284
+ if (draft.outer.length < 3) problems.push(`The outline needs at least 3 corners; it has ${draft.outer.length}.`);
285
+
286
+ // The drawing: corners worked out at the default sizes; a corner that cannot be worked out is shown, not hidden.
287
+ const outer = rawLoop(draft.outer, symbols, defaults);
288
+ const holes = draft.holes.map((h) => rawLoop(h, symbols, defaults));
289
+ const loops = [{ name: 'The outline', points: outer }, ...holes.map((points, i) => ({ name: `Hole ${i + 1}`, points }))];
290
+ const drawing = { outer, holes, crossings: [] };
291
+ for (const loop of loops) {
292
+ if (loop.points.length < 3) continue;
293
+ if (loop.points.some((p) => !p)) {
294
+ const bad = loop.points.map((p, i) => (p ? 0 : i + 1)).filter(Boolean);
295
+ checks.push({ id: 'closed', ok: false, text: `${loop.name}: corner ${bad.join(', ')} cannot be worked out at the default sizes. Check its formulas.` });
296
+ continue;
297
+ }
298
+ checks.push({ id: 'closed', ok: true, text: `${loop.name} has ${loop.points.length} corners and closes on itself.` });
299
+ const crossing = selfCrossing(loop.points);
300
+ if (crossing) {
301
+ drawing.crossings.push({ loop: loop.name, edges: crossing });
302
+ checks.push({ id: 'simple', ok: false, text: `${loop.name} crosses itself: the edge from corner ${crossing[0][0]} to ${crossing[0][1]} meets the edge from corner ${crossing[1][0]} to ${crossing[1][1]}.` });
303
+ } else checks.push({ id: 'simple', ok: true, text: `${loop.name} does not cross itself.` });
304
+ }
305
+ if (draft.outer.length > 0 && draft.outer.length < 3) checks.push({ id: 'closed', ok: false, text: `The outline has ${draft.outer.length} corner${draft.outer.length === 1 ? '' : 's'}; it needs at least 3 to close.` });
306
+
307
+ // Conditions at the default sizes (the shape must exist where it is drawn).
308
+ draft.predicates.forEach((p) => {
309
+ try {
310
+ const { met, nonFinite } = evaluatePredicate(parsePredicate(p.when, symbols), defaults);
311
+ checks.push({ id: 'condition', ok: met, text: met ? `Condition holds at the default sizes: ${p.when}.` : `${p.reason || p.when}${nonFinite ? ' (it cannot be worked out at the default sizes)' : ' This is not true at the default sizes.'}` });
312
+ } catch (error) { problems.push(`Condition “${p.when}”: ${error.message}`); }
313
+ });
314
+
315
+ // The definition's own checker, then its evaluator: one judgement of whether this is a shape FloLess can use.
316
+ let section = null;
317
+ let example = null;
318
+ const complete = draft.name.trim() && draft.prefix.trim() && draft.sizes.length && draft.outer.length >= 3;
319
+ if (complete) {
320
+ const definition = draftToDefinition(draft, slug);
321
+ const checker = checkSectionProfileV2(definition.payload);
322
+ problems.push(...checker);
323
+ if (!checker.length) {
324
+ const evaluated = evaluateSectionV2(definition, defaults);
325
+ if (evaluated.section) {
326
+ section = evaluated.section;
327
+ try { example = canonicalName(definition, defaults); } catch { example = null; }
328
+ notes.push(...(evaluated.advisories ?? []));
329
+ } else {
330
+ // The evaluator's own sentence for a crossing outline says less than the check above, which names the corners.
331
+ const crossing = checks.some((c) => !c.ok && c.id === 'simple');
332
+ const said = (evaluated.problems ?? ['At the default sizes this shape has no valid section.']).filter((p) => !(crossing && /touches or crosses itself/.test(p)));
333
+ problems.push(...said);
334
+ }
335
+ }
336
+ }
337
+ // A crossing the drawing names is a problem in its own right, in the person's words, ahead of the evaluator's.
338
+ problems.unshift(...checks.filter((c) => !c.ok && c.id === 'simple').map((c) => c.text));
339
+ const unique = [...new Set(problems)].map((p) => p.charAt(0).toUpperCase() + p.slice(1));
340
+
341
+ checks.push(section
342
+ ? { id: 'section', ok: true, text: 'FloLess can build this section at the default sizes.' }
343
+ : { id: 'section', ok: false, text: unique.length ? 'FloLess cannot build this section yet; see what to fix below.' : 'Add a name, a prefix, sizes and at least 3 corners, then FloLess can check it.' });
344
+ if (example) checks.push({ id: 'name', ok: true, text: `A name of this shape reads like ${example}.` });
345
+
346
+ // Names: a prefix other shapes already use is a warning, never a refusal; the name reader then asks which one is meant.
347
+ const clash = (others.prefixes ?? []).find((p) => p.prefix.toLowerCase() === draft.prefix.trim().toLowerCase());
348
+ if (clash) notes.push(`The prefix “${draft.prefix.trim()}” is already used by ${clash.where}. You can keep it, but a name that starts with it will ask which shape you mean. A different prefix avoids that.`);
349
+ const replaces = (others.mine ?? []).find((m) => m.slug === slug) ?? null;
350
+ if (replaces) notes.push(`You already have a shape called “${replaces.name}” in My shapes. Saving adds a new version of it; models that use the old version keep it until you update them.`);
351
+
352
+ const area = section && typeof section.area === 'number' ? section.area : null;
353
+ const density = densityFor('');
354
+ const kgPerM = area !== null ? customKgPerM(section, density) : null;
355
+
356
+ const block = section ? v2ReadersBlock(section) : '';
357
+ const reach = [
358
+ section
359
+ ? (block ? { id: 'floless', state: 'partly', text: block } : { id: 'floless', state: 'yes', text: 'FloLess draws it in 3D, counts its weight and lists it in the bill.' })
360
+ : { id: 'floless', state: 'no', text: 'Not until the shape works at its default sizes.' },
361
+ { id: 'ifc', state: section ? 'partly' : 'no', text: section
362
+ ? 'An IFC file carries it as its real outline when the installed AWARE can (AWARE 0.180.0 or newer). With an older AWARE you choose at export: leave it out, or send a labelled box.'
363
+ : 'Not until the shape works at its default sizes.' },
364
+ { id: 'tekla', state: section ? 'partly' : 'no', text: section
365
+ ? 'Tekla has no profile with this name, and FloLess cannot create it there yet. When you send members to Tekla you choose: leave it out, or send a labelled placeholder.'
366
+ : 'Not until the shape works at its default sizes.' },
367
+ ];
368
+
369
+ const assumed = draft.sizes.filter((s) => s.source === 'assumed').map((s) => s.symbol);
370
+ return {
371
+ ok: !!section && unique.length === 0, problems: unique, checks, drawing, section, area, kgPerM, example, reach, notes, assumed, slug, replaces: replaces ? replaces.slug : null,
372
+ weightBasis: STEEL_WORDS,
373
+ };
374
+ }
375
+
376
+ /** One paragraph a card or a chat reply can say about a draft: what it is, its sizes and where each came from. */
377
+ export function describeDraft(draft) {
378
+ const sizes = draft.sizes.map((s) => `${s.symbol} (${s.label}) ${s.default}${s.kind === 'angle' ? '°' : s.kind === 'length' ? ' mm' : ''}${s.source === 'assumed' ? ', assumed' : ''}`).join('; ');
379
+ return `${draft.name || 'Unnamed shape'}, prefix ${draft.prefix || '(none yet)'}: ${draft.outer.length} corner${draft.outer.length === 1 ? '' : 's'}${draft.holes.length ? `, ${draft.holes.length} hole${draft.holes.length === 1 ? '' : 's'}` : ''}. Sizes: ${sizes || 'none yet'}.`;
380
+ }