@brandlab-digital/site-core 3.13.0 → 3.14.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.
@@ -0,0 +1,161 @@
1
+ /**
2
+ * Titles and H1s for new pages (Site System v2 §5.2; correction #27). Earning pages keep their recorded titles
3
+ * (`docs/recorded-titles.json`, check E1); every other page takes its family's pattern:
4
+ *
5
+ * | Family | Title | H1 |
6
+ * |---|---|---|
7
+ * | Home | `{Home phrase} \| {Brand}` | `{Home phrase}` |
8
+ * | Service | `{Service phrase} \| {Brand}` | `{Service phrase}` |
9
+ * | Region, suburb | `{Main service} {Place} \| {Brand}` | `{Main service} {Place}` |
10
+ * | Service-region hub, service in suburb | `{Service} {Place} \| {Brand}` | `{Service} {Place}` |
11
+ * | Cost guide | `{Service} Cost {Area} {Year} \| {Brand}` | `{Service} cost {area} ({year})` |
12
+ * | Project | `{Service} {Suburb}: {Job} \| {Brand}` | `{Job}, {Suburb}` |
13
+ *
14
+ * H1s are the short exact phrase with no "in" and no "the". Titles are at most 60 characters: the short brand only
15
+ * when needed, never a cut keyword. A proof tail (`| From $450 |`, "Same-Week Quotes") comes only from data and only
16
+ * on the service page and head-tier pages. One pipe separates the brand; with a tail there are two.
17
+ */
18
+ export const BRANDLAB_TITLE_MAX_LENGTH = 60;
19
+ export const BRANDLAB_TITLE_FAMILIES = [
20
+ 'home',
21
+ 'service',
22
+ 'region',
23
+ 'suburb',
24
+ 'service-region',
25
+ 'service-in-suburb',
26
+ 'cost-guide',
27
+ 'project',
28
+ ];
29
+ const SMALL_WORDS = new Set(['a', 'an', 'and', 'as', 'at', 'but', 'by', 'for', 'of', 'on', 'or', 'to', 'with']);
30
+ const BANNED_WORDS = ['in', 'the'];
31
+ function clean(value, field) {
32
+ const text = typeof value === 'string' ? value.trim().replace(/\s+/g, ' ') : '';
33
+ if (!text)
34
+ throw new Error(`buildPageTitle needs a ${field} for this family.`);
35
+ return text;
36
+ }
37
+ /** Title case: every word capitalised except short joining words after the first; words in capitals stay so. */
38
+ export function titleCase(phrase) {
39
+ return phrase
40
+ .trim()
41
+ .split(/\s+/)
42
+ .map((word, index) => {
43
+ if (word.length > 1 && word === word.toUpperCase() && /[A-Z]/.test(word))
44
+ return word;
45
+ const lower = word.toLowerCase();
46
+ if (index > 0 && SMALL_WORDS.has(lower))
47
+ return lower;
48
+ return lower.charAt(0).toUpperCase() + lower.slice(1);
49
+ })
50
+ .join(' ');
51
+ }
52
+ function sentenceCase(phrase) {
53
+ const words = phrase.trim().split(/\s+/);
54
+ return words.map((word, index) => (word.length > 1 && word === word.toUpperCase() && /[A-Z]/.test(word) ? word : index === 0 ? word.charAt(0).toUpperCase() + word.slice(1).toLowerCase() : word.toLowerCase())).join(' ');
55
+ }
56
+ function bannedWordIn(service) {
57
+ const words = service.toLowerCase().split(/\s+/);
58
+ return BANNED_WORDS.find((banned) => words.includes(banned));
59
+ }
60
+ /** "{Service} {Place}": the service in title case and the place as named. The service has no "in" and no "the". */
61
+ export function locationHeading(service, place) {
62
+ const name = clean(service, 'service');
63
+ const banned = bannedWordIn(name);
64
+ if (banned)
65
+ throw new Error(`A location heading has no "${banned}": "${name}" is not the short exact phrase.`);
66
+ return `${titleCase(name)} ${clean(place, 'place')}`;
67
+ }
68
+ function fit(heading, input, tailAllowed) {
69
+ const brand = clean(input.brand, 'brand');
70
+ const short = input.shortBrand?.trim() || brand;
71
+ const tail = tailAllowed ? input.proofTail?.trim() : undefined;
72
+ const candidates = [
73
+ ...(tail ? [`${heading} | ${tail} | ${brand}`, `${heading} | ${tail} | ${short}`] : []),
74
+ `${heading} | ${brand}`,
75
+ `${heading} | ${short}`,
76
+ ];
77
+ return candidates.find((candidate) => candidate.length <= BRANDLAB_TITLE_MAX_LENGTH) ?? heading;
78
+ }
79
+ /** The title and H1 a new page of `family` takes. */
80
+ export function buildPageTitle(input) {
81
+ if (!BRANDLAB_TITLE_FAMILIES.includes(input.family)) {
82
+ throw new Error(`buildPageTitle does not know the family "${String(input.family)}".`);
83
+ }
84
+ const locationFamily = input.family !== 'home' && input.family !== 'service' && input.family !== 'cost-guide' && input.family !== 'project';
85
+ if (input.proofTail !== undefined) {
86
+ if (input.family !== 'service' && !(locationFamily && input.tier === 'head')) {
87
+ throw new Error('A proof tail goes only on the service page and head-tier pages; standard-tier pages never carry one.');
88
+ }
89
+ }
90
+ let heading;
91
+ let h1;
92
+ switch (input.family) {
93
+ case 'home':
94
+ case 'service': {
95
+ const phrase = clean(input.phrase, 'phrase');
96
+ const banned = bannedWordIn(phrase);
97
+ if (banned)
98
+ throw new Error(`An H1 has no "${banned}": "${phrase}" is not the short exact phrase.`);
99
+ heading = titleCase(phrase);
100
+ h1 = heading;
101
+ break;
102
+ }
103
+ case 'cost-guide': {
104
+ const service = clean(input.service, 'service');
105
+ const place = clean(input.place, 'place');
106
+ if (!Number.isInteger(input.year) || input.year < 2000)
107
+ throw new Error('buildPageTitle needs the year a cost guide is for.');
108
+ heading = `${titleCase(service)} Cost ${place} ${input.year}`;
109
+ h1 = `${sentenceCase(service)} cost ${place} (${input.year})`;
110
+ break;
111
+ }
112
+ case 'project': {
113
+ const job = clean(input.job, 'job');
114
+ const place = clean(input.place, 'place');
115
+ heading = `${locationHeading(clean(input.service, 'service'), place)}: ${job}`;
116
+ h1 = `${job}, ${place}`;
117
+ break;
118
+ }
119
+ default: {
120
+ heading = locationHeading(clean(input.service, 'service'), clean(input.place, 'place'));
121
+ h1 = heading;
122
+ }
123
+ }
124
+ const title = fit(heading, input, input.proofTail !== undefined);
125
+ return { title, h1, heading, length: title.length, overLength: heading.length > BRANDLAB_TITLE_MAX_LENGTH };
126
+ }
127
+ /**
128
+ * Why a location page's H1 and title break "{Service} {Place}", or null when they keep it: the H1 ends with the place
129
+ * and has a service before it, no "in" and no leading "the"; the title starts with the H1 (letter case aside), has at
130
+ * most two pipes and is at most 60 characters.
131
+ */
132
+ export function locationHeadingProblem(sample) {
133
+ const h1 = sample.h1.trim().replace(/\s+/g, ' ');
134
+ const title = sample.title.trim().replace(/\s+/g, ' ');
135
+ const place = sample.place.trim().replace(/\s+/g, ' ');
136
+ const lowerH1 = h1.toLowerCase();
137
+ const lowerPlace = place.toLowerCase();
138
+ if (!lowerH1.endsWith(` ${lowerPlace}`) && lowerH1 !== lowerPlace) {
139
+ return `the H1 "${h1}" is not "{Service} {Place}": it never ends with the place ("${place}").`;
140
+ }
141
+ const service = h1.slice(0, h1.length - place.length).trim();
142
+ if (!service)
143
+ return `the H1 "${h1}" names the place without the service.`;
144
+ const words = service.toLowerCase().split(' ');
145
+ if (words.includes('in'))
146
+ return `the H1 "${h1}" has "in"; it is the short exact phrase "{Service} {Place}".`;
147
+ if (words.includes('the'))
148
+ return `the H1 "${h1}" has "the"; it is the short exact phrase "{Service} {Place}".`;
149
+ if (!title.toLowerCase().startsWith(lowerH1))
150
+ return `the title "${title}" never starts with the H1 "${h1}".`;
151
+ const rest = title.slice(h1.length);
152
+ if (rest && !rest.startsWith(' | '))
153
+ return `the title "${title}" adds words to "${h1}" before its brand.`;
154
+ if ((title.match(/\|/g) ?? []).length > 2)
155
+ return `the title "${title}" chains more than two pipes.`;
156
+ if (title.length > BRANDLAB_TITLE_MAX_LENGTH && title !== h1) {
157
+ return `the title "${title}" is ${title.length} characters; titles are at most 60 characters (drop or shorten the brand, never the keyword).`;
158
+ }
159
+ return null;
160
+ }
161
+ //# sourceMappingURL=page-titles.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"page-titles.js","sourceRoot":"","sources":["../src/page-titles.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;GAgBG;AAEH,MAAM,CAAC,MAAM,yBAAyB,GAAG,EAAE,CAAA;AAE3C,MAAM,CAAC,MAAM,uBAAuB,GAAG;IACrC,MAAM;IACN,SAAS;IACT,QAAQ;IACR,QAAQ;IACR,gBAAgB;IAChB,mBAAmB;IACnB,YAAY;IACZ,SAAS;CACD,CAAA;AAoCV,MAAM,WAAW,GAAG,IAAI,GA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GAAG,yBAAyB,IAAI,KAAK,KAAK,EAAE,EAAE,CAAC;QAC7D,OAAO,cAAc,KAAK,QAAQ,KAAK,CAAC,MAAM,+FAA+F,CAAA;IAC/I,CAAC;IACD,OAAO,IAAI,CAAA;AACb,CAAC","sourcesContent":["/**\n * Titles and H1s for new pages (Site System v2 §5.2; correction #27). Earning pages keep their recorded titles\n * (`docs/recorded-titles.json`, check E1); every other page takes its family's pattern:\n *\n * | Family | Title | H1 |\n * |---|---|---|\n * | Home | `{Home phrase} \\| {Brand}` | `{Home phrase}` |\n * | Service | `{Service phrase} \\| {Brand}` | `{Service phrase}` |\n * | Region, suburb | `{Main service} {Place} \\| {Brand}` | `{Main service} {Place}` |\n * | Service-region hub, service in suburb | `{Service} {Place} \\| {Brand}` | `{Service} {Place}` |\n * | Cost guide | `{Service} Cost {Area} {Year} \\| {Brand}` | `{Service} cost {area} ({year})` |\n * | Project | `{Service} {Suburb}: {Job} \\| {Brand}` | `{Job}, {Suburb}` |\n *\n * H1s are the short exact phrase with no \"in\" and no \"the\". Titles are at most 60 characters: the short brand only\n * when needed, never a cut keyword. A proof tail (`| From $450 |`, \"Same-Week Quotes\") comes only from data and only\n * on the service page and head-tier pages. One pipe separates the brand; with a tail there are two.\n */\n\nexport const BRANDLAB_TITLE_MAX_LENGTH = 60\n\nexport const BRANDLAB_TITLE_FAMILIES = [\n 'home',\n 'service',\n 'region',\n 'suburb',\n 'service-region',\n 'service-in-suburb',\n 'cost-guide',\n 'project',\n] as const\nexport type BrandlabTitleFamily = (typeof BRANDLAB_TITLE_FAMILIES)[number]\n\nexport interface BrandlabPageTitleInput {\n readonly family: BrandlabTitleFamily\n /** The full brand, for example \"AA Tree Services Sydney\". */\n readonly brand: string\n /** The short brand used when the full one would push the title past 60 characters. */\n readonly shortBrand?: string\n /** Home and service pages: the owned phrase, for example \"tree removal sydney\". */\n readonly phrase?: string\n /** Location, cost-guide and project pages: the service (the main service on region and suburb pages). */\n readonly service?: string\n /** The place's display name, for example \"Ryde\" or \"Western Sydney\". */\n readonly place?: string\n /** Location pages: `head` pages may carry a proof tail; `standard` pages never do. */\n readonly tier?: 'head' | 'standard'\n /** \"From $450\" or \"Same-Week Quotes\": only when true and only on service and head-tier pages. */\n readonly proofTail?: string\n /** Cost guides. */\n readonly year?: number\n /** Projects: the job, for example \"Gum tree removal over a pool\". */\n readonly job?: string\n}\n\nexport interface BrandlabPageTitle {\n /** The full `<title>` (pass it with `titleMode: 'absolute'`). */\n readonly title: string\n readonly h1: string\n /** The title before its first pipe. */\n readonly heading: string\n readonly length: number\n /** True only when the heading alone is over 60 characters: it is kept whole rather than cut. */\n readonly overLength: boolean\n}\n\nconst SMALL_WORDS = new Set(['a', 'an', 'and', 'as', 'at', 'but', 'by', 'for', 'of', 'on', 'or', 'to', 'with'])\nconst BANNED_WORDS = ['in', 'the'] as const\n\nfunction clean(value: string | undefined, field: string): string {\n const text = typeof value === 'string' ? value.trim().replace(/\\s+/g, ' ') : ''\n if (!text) throw new Error(`buildPageTitle needs a ${field} for this family.`)\n return text\n}\n\n/** Title case: every word capitalised except short joining words after the first; words in capitals stay so. */\nexport function titleCase(phrase: string): string {\n return phrase\n .trim()\n .split(/\\s+/)\n .map((word, index) => {\n if (word.length > 1 && word === word.toUpperCase() && /[A-Z]/.test(word)) return word\n const lower = word.toLowerCase()\n if (index > 0 && SMALL_WORDS.has(lower)) return lower\n return lower.charAt(0).toUpperCase() + lower.slice(1)\n })\n .join(' ')\n}\n\nfunction sentenceCase(phrase: string): string {\n const words = phrase.trim().split(/\\s+/)\n return words.map((word, index) => (word.length > 1 && word === word.toUpperCase() && /[A-Z]/.test(word) ? word : index === 0 ? word.charAt(0).toUpperCase() + word.slice(1).toLowerCase() : word.toLowerCase())).join(' ')\n}\n\nfunction bannedWordIn(service: string): string | undefined {\n const words = service.toLowerCase().split(/\\s+/)\n return BANNED_WORDS.find((banned) => words.includes(banned))\n}\n\n/** \"{Service} {Place}\": the service in title case and the place as named. The service has no \"in\" and no \"the\". */\nexport function locationHeading(service: string, place: string): string {\n const name = clean(service, 'service')\n const banned = bannedWordIn(name)\n if (banned) throw new Error(`A location heading has no \"${banned}\": \"${name}\" is not the short exact phrase.`)\n return `${titleCase(name)} ${clean(place, 'place')}`\n}\n\nfunction fit(heading: string, input: BrandlabPageTitleInput, tailAllowed: boolean): string {\n const brand = clean(input.brand, 'brand')\n const short = input.shortBrand?.trim() || brand\n const tail = tailAllowed ? input.proofTail?.trim() : undefined\n const candidates = [\n ...(tail ? [`${heading} | ${tail} | ${brand}`, `${heading} | ${tail} | ${short}`] : []),\n `${heading} | ${brand}`,\n `${heading} | ${short}`,\n ]\n return candidates.find((candidate) => candidate.length <= BRANDLAB_TITLE_MAX_LENGTH) ?? heading\n}\n\n/** The title and H1 a new page of `family` takes. */\nexport function buildPageTitle(input: BrandlabPageTitleInput): BrandlabPageTitle {\n if (!(BRANDLAB_TITLE_FAMILIES as readonly string[]).includes(input.family)) {\n throw new Error(`buildPageTitle does not know the family \"${String(input.family)}\".`)\n }\n const locationFamily = input.family !== 'home' && input.family !== 'service' && input.family !== 'cost-guide' && input.family !== 'project'\n if (input.proofTail !== undefined) {\n if (input.family !== 'service' && !(locationFamily && input.tier === 'head')) {\n throw new Error('A proof tail goes only on the service page and head-tier pages; standard-tier pages never carry one.')\n }\n }\n let heading: string\n let h1: string\n switch (input.family) {\n case 'home':\n case 'service': {\n const phrase = clean(input.phrase, 'phrase')\n const banned = bannedWordIn(phrase)\n if (banned) throw new Error(`An H1 has no \"${banned}\": \"${phrase}\" is not the short exact phrase.`)\n heading = titleCase(phrase)\n h1 = heading\n break\n }\n case 'cost-guide': {\n const service = clean(input.service, 'service')\n const place = clean(input.place, 'place')\n if (!Number.isInteger(input.year) || (input.year as number) < 2000) throw new Error('buildPageTitle needs the year a cost guide is for.')\n heading = `${titleCase(service)} Cost ${place} ${input.year}`\n h1 = `${sentenceCase(service)} cost ${place} (${input.year})`\n break\n }\n case 'project': {\n const job = clean(input.job, 'job')\n const place = clean(input.place, 'place')\n heading = `${locationHeading(clean(input.service, 'service'), place)}: ${job}`\n h1 = `${job}, ${place}`\n break\n }\n default: {\n heading = locationHeading(clean(input.service, 'service'), clean(input.place, 'place'))\n h1 = heading\n }\n }\n const title = fit(heading, input, input.proofTail !== undefined)\n return { title, h1, heading, length: title.length, overLength: heading.length > BRANDLAB_TITLE_MAX_LENGTH }\n}\n\n/** What check E1-pattern compares on a location page. */\nexport interface BrandlabLocationHeadingSample {\n readonly h1: string\n readonly title: string\n /** The place the page is for, as named. */\n readonly place: string\n}\n\n/**\n * Why a location page's H1 and title break \"{Service} {Place}\", or null when they keep it: the H1 ends with the place\n * and has a service before it, no \"in\" and no leading \"the\"; the title starts with the H1 (letter case aside), has at\n * most two pipes and is at most 60 characters.\n */\nexport function locationHeadingProblem(sample: BrandlabLocationHeadingSample): string | null {\n const h1 = sample.h1.trim().replace(/\\s+/g, ' ')\n const title = sample.title.trim().replace(/\\s+/g, ' ')\n const place = sample.place.trim().replace(/\\s+/g, ' ')\n const lowerH1 = h1.toLowerCase()\n const lowerPlace = place.toLowerCase()\n if (!lowerH1.endsWith(` ${lowerPlace}`) && lowerH1 !== lowerPlace) {\n return `the H1 \"${h1}\" is not \"{Service} {Place}\": it never ends with the place (\"${place}\").`\n }\n const service = h1.slice(0, h1.length - place.length).trim()\n if (!service) return `the H1 \"${h1}\" names the place without the service.`\n const words = service.toLowerCase().split(' ')\n if (words.includes('in')) return `the H1 \"${h1}\" has \"in\"; it is the short exact phrase \"{Service} {Place}\".`\n if (words.includes('the')) return `the H1 \"${h1}\" has \"the\"; it is the short exact phrase \"{Service} {Place}\".`\n if (!title.toLowerCase().startsWith(lowerH1)) return `the title \"${title}\" never starts with the H1 \"${h1}\".`\n const rest = title.slice(h1.length)\n if (rest && !rest.startsWith(' | ')) return `the title \"${title}\" adds words to \"${h1}\" before its brand.`\n if ((title.match(/\\|/g) ?? []).length > 2) return `the title \"${title}\" chains more than two pipes.`\n if (title.length > BRANDLAB_TITLE_MAX_LENGTH && title !== h1) {\n return `the title \"${title}\" is ${title.length} characters; titles are at most 60 characters (drop or shorten the brand, never the keyword).`\n }\n return null\n}\n"]}
@@ -44,10 +44,55 @@ export type BrandlabTrade = (typeof BRANDLAB_TRADES)[number];
44
44
  /** A trade's changes to the defaults: a new requirement for a section already in a family's order. */
45
45
  export type BrandlabTradeSectionRules = Readonly<Partial<Record<BrandlabPageFamily, Readonly<Partial<Record<BrandlabSectionId, BrandlabSectionRequirement>>>>>>;
46
46
  /**
47
- * The trade map (matrix part B). A stub in 3.11.0: every trade uses the defaults until its playbook's rules are
48
- * confirmed per client (licence classes, permit notes and emergency work are "inferred, confirm" in the matrix).
47
+ * Lines inside a section that a trade can require (3.14.0): the permit note is `LocalFacts`' `permit` slot; the
48
+ * qualifications and insurance lines stand in for a licence block where the trade has no licence. A component marks
49
+ * each slot it renders with `data-bl-slot="<slot>"`; when its data is missing or stale it renders nothing for the slot
50
+ * and lists `<slot>:<no-… reason>` in the section's `data-bl-slot-skip` attribute (check K12-slots reads both).
49
51
  */
52
+ export declare const BRANDLAB_SECTION_SLOTS: readonly ["permit", "qualifications", "insurance", "licence"];
53
+ export type BrandlabSectionSlot = (typeof BRANDLAB_SECTION_SLOTS)[number];
54
+ export declare const SECTION_SLOT_ATTRIBUTE = "data-bl-slot";
55
+ export declare const SECTION_SLOT_SKIP_ATTRIBUTE = "data-bl-slot-skip";
56
+ /** A slot left empty for a data-backed reason, such as `{ slot: 'permit', reason: 'no-current-council-record' }`. */
57
+ export interface BrandlabSectionSlotSkip {
58
+ readonly slot: BrandlabSectionSlot;
59
+ readonly reason: `no-${string}`;
60
+ }
61
+ /** The `data-bl-slot-skip` value: space-separated `slot:reason` pairs. */
62
+ export declare function formatSectionSlotSkips(skips: readonly BrandlabSectionSlotSkip[]): string;
63
+ /** Reads a `data-bl-slot-skip` value; pairs that are not `slot:no-…` are ignored. */
64
+ export declare function parseSectionSlotSkips(value: string | undefined): BrandlabSectionSlotSkip[];
65
+ /** Slots a trade requires inside a family's sections. */
66
+ export type BrandlabTradeSlotRules = Readonly<Partial<Record<BrandlabPageFamily, Readonly<Partial<Record<BrandlabSectionId, readonly BrandlabSectionSlot[]>>>>>>;
67
+ /**
68
+ * One trade's column of matrix part B: its credential block (a licence block, or qualifications and insurance where
69
+ * the trade has no licence), its section requirement changes and the slots it requires. `unconfirmed` trades keep the
70
+ * defaults until their playbook's rules are confirmed (licence classes, permit notes and emergency work are
71
+ * "inferred, confirm" in the matrix).
72
+ */
73
+ export interface BrandlabTradeProfile {
74
+ readonly credentials: 'licence' | 'qualifications' | 'unconfirmed';
75
+ readonly sections: BrandlabTradeSectionRules;
76
+ readonly slots: BrandlabTradeSlotRules;
77
+ /** Where the rules come from. */
78
+ readonly source: string;
79
+ }
80
+ /** Validates trade profiles: requirement changes and slots name sections the family uses, and known slots. */
81
+ export declare function defineTradeProfiles<const T extends Readonly<Record<BrandlabTrade, BrandlabTradeProfile>>>(profiles: T): T;
82
+ /**
83
+ * Matrix part B, as confirmed (3.14.0). Trees: no NSW licence for tree work, so the licence block is optional and the
84
+ * about page's owner block carries the qualifications and insurance lines; the council permit note is required on
85
+ * suburb and service-in-suburb pages (hidden, with its reason, once the council record is stale). The other trades
86
+ * stay on the defaults until their rules are confirmed.
87
+ */
88
+ export declare const SECTION_TRADE_PROFILES: Readonly<Record<BrandlabTrade, BrandlabTradeProfile>>;
89
+ /** The trade map (matrix part B): each trade's section requirement changes, from `SECTION_TRADE_PROFILES`. */
50
90
  export declare const SECTION_ORDER_TRADE_MAP: Readonly<Record<BrandlabTrade, BrandlabTradeSectionRules>>;
91
+ /** The slots a trade requires on a family's pages, section by section, in the order the profile lists them. */
92
+ export declare function requiredSectionSlots(family: BrandlabPageFamily, trade?: BrandlabTrade, profiles?: Readonly<Partial<Record<BrandlabTrade, BrandlabTradeProfile>>>): {
93
+ readonly section: BrandlabSectionId;
94
+ readonly slot: BrandlabSectionSlot;
95
+ }[];
51
96
  /** A family's default order, with the trade's rules applied. */
52
97
  export declare function defaultSectionOrder(family: BrandlabPageFamily, trade?: BrandlabTrade, tradeMap?: Readonly<Partial<Record<BrandlabTrade, BrandlabTradeSectionRules>>>): BrandlabFamilyOrder;
53
98
  /** A site's recorded alternative order for one family (LIB §7a), with the decision that recorded it. */
@@ -1 +1 @@
1
- {"version":3,"file":"section-order.d.ts","sourceRoot":"","sources":["../src/section-order.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;GAUG;AAEH,eAAO,MAAM,oBAAoB,yZAgCvB,CAAA;AACV,MAAM,MAAM,iBAAiB,GAAG,CAAC,OAAO,oBAAoB,CAAC,CAAC,MAAM,CAAC,CAAA;AAErE,eAAO,MAAM,sBAAsB,kPAoBzB,CAAA;AACV,MAAM,MAAM,kBAAkB,GAAG,CAAC,OAAO,sBAAsB,CAAC,CAAC,MAAM,CAAC,CAAA;AAExE,mHAAmH;AACnH,eAAO,MAAM,6BAA6B,iCAAkC,CAAA;AAC5E,MAAM,MAAM,0BAA0B,GAAG,CAAC,OAAO,6BAA6B,CAAC,CAAC,MAAM,CAAC,CAAA;AAEvF,mGAAmG;AACnG,eAAO,MAAM,sBAAsB,iDAAkD,CAAA;AACrF,MAAM,MAAM,mBAAmB,GAAG,CAAC,OAAO,sBAAsB,CAAC,CAAC,MAAM,CAAC,CAAA;AAEzE,uHAAuH;AACvH,MAAM,MAAM,0BAA0B,GAAG,MAAM,GAAG,MAAM,GAAG,OAAO,CAAA;AAElE,MAAM,WAAW,yBAAyB;IACxC,QAAQ,CAAC,EAAE,EAAE,iBAAiB,CAAA;IAC9B,QAAQ,CAAC,WAAW,EAAE,0BAA0B,CAAA;IAChD,4FAA4F;IAC5F,QAAQ,CAAC,YAAY,CAAC,EAAE,SAAS,iBAAiB,EAAE,CAAA;IACpD,qGAAqG;IACrG,QAAQ,CAAC,UAAU,CAAC,EAAE,iBAAiB,CAAA;CACxC;AAED,MAAM,WAAW,mBAAmB;IAClC,QAAQ,CAAC,MAAM,EAAE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kB,CAAC,QAAQ,EAAE,SAAS,0BAA0B,EAAE,GAAG,mBAAmB,EAAE,CAsBzG;AAKD;;;;;GAKG;AACH,wBAAgB,mBAAmB,CACjC,KAAK,EAAE,mBAAmB,EAC1B,UAAU,EAAE,SAAS,yBAAyB,EAAE,EAChD,IAAI,CAAC,EAAE,MAAM,GACZ,oBAAoB,CAqFtB"}
@@ -277,10 +277,103 @@ export const BRANDLAB_TRADES = [
277
277
  'trees',
278
278
  ];
279
279
  /**
280
- * The trade map (matrix part B). A stub in 3.11.0: every trade uses the defaults until its playbook's rules are
281
- * confirmed per client (licence classes, permit notes and emergency work are "inferred, confirm" in the matrix).
280
+ * Lines inside a section that a trade can require (3.14.0): the permit note is `LocalFacts`' `permit` slot; the
281
+ * qualifications and insurance lines stand in for a licence block where the trade has no licence. A component marks
282
+ * each slot it renders with `data-bl-slot="<slot>"`; when its data is missing or stale it renders nothing for the slot
283
+ * and lists `<slot>:<no-… reason>` in the section's `data-bl-slot-skip` attribute (check K12-slots reads both).
282
284
  */
283
- export const SECTION_ORDER_TRADE_MAP = Object.freeze(Object.fromEntries(BRANDLAB_TRADES.map((trade) => [trade, Object.freeze({})])));
285
+ export const BRANDLAB_SECTION_SLOTS = ['permit', 'qualifications', 'insurance', 'licence'];
286
+ export const SECTION_SLOT_ATTRIBUTE = 'data-bl-slot';
287
+ export const SECTION_SLOT_SKIP_ATTRIBUTE = 'data-bl-slot-skip';
288
+ /** The `data-bl-slot-skip` value: space-separated `slot:reason` pairs. */
289
+ export function formatSectionSlotSkips(skips) {
290
+ return skips
291
+ .map((skip) => {
292
+ if (!BRANDLAB_SECTION_SLOTS.includes(skip.slot))
293
+ throw new Error(`Unknown section slot "${skip.slot}".`);
294
+ if (!/^no-[a-z0-9]+(?:-[a-z0-9]+)*$/.test(skip.reason))
295
+ throw new Error(`A slot skip reason says what data is missing: "no-…", not "${skip.reason}".`);
296
+ return `${skip.slot}:${skip.reason}`;
297
+ })
298
+ .join(' ');
299
+ }
300
+ /** Reads a `data-bl-slot-skip` value; pairs that are not `slot:no-…` are ignored. */
301
+ export function parseSectionSlotSkips(value) {
302
+ return (value ?? '')
303
+ .split(/\s+/)
304
+ .flatMap((pair) => {
305
+ const [slot, reason] = pair.split(':');
306
+ return slot && reason && BRANDLAB_SECTION_SLOTS.includes(slot) && /^no-[a-z0-9]+(?:-[a-z0-9]+)*$/.test(reason)
307
+ ? [{ slot: slot, reason: reason }]
308
+ : [];
309
+ });
310
+ }
311
+ const UNCONFIRMED = Object.freeze({
312
+ credentials: 'unconfirmed',
313
+ sections: Object.freeze({}),
314
+ slots: Object.freeze({}),
315
+ source: 'Defaults until the playbook rules are confirmed (v2 §3.4).',
316
+ });
317
+ /** Validates trade profiles: requirement changes and slots name sections the family uses, and known slots. */
318
+ export function defineTradeProfiles(profiles) {
319
+ for (const [trade, profile] of Object.entries(profiles)) {
320
+ if (!BRANDLAB_TRADES.includes(trade))
321
+ throw new Error(`Unknown trade "${trade}".`);
322
+ if (!['licence', 'qualifications', 'unconfirmed'].includes(profile.credentials)) {
323
+ throw new Error(`Trade ${trade}: credentials must be licence, qualifications or unconfirmed.`);
324
+ }
325
+ const check = (rules, kind, value) => {
326
+ for (const [family, sections] of Object.entries(rules)) {
327
+ const rows = DEFAULT_ROWS[family];
328
+ if (!rows)
329
+ throw new Error(`Trade ${trade}: unknown page family "${family}" in its ${kind}.`);
330
+ for (const [section, sectionValue] of Object.entries(sections)) {
331
+ if (!rows.some((row) => row[0] === section))
332
+ throw new Error(`Trade ${trade}: ${family} pages have no "${section}" section for its ${kind}.`);
333
+ value(sectionValue, `Trade ${trade}: ${family} "${section}"`);
334
+ }
335
+ }
336
+ };
337
+ check(profile.sections, 'requirements', (requirement, where) => {
338
+ if (!BRANDLAB_SECTION_REQUIREMENTS.includes(requirement))
339
+ throw new Error(`${where} has an unknown requirement.`);
340
+ });
341
+ check(profile.slots, 'slots', (slots, where) => {
342
+ if (!Array.isArray(slots) || slots.length === 0 || slots.some((slot) => !BRANDLAB_SECTION_SLOTS.includes(slot))) {
343
+ throw new Error(`${where} lists an unknown slot; slots are ${BRANDLAB_SECTION_SLOTS.join(', ')}.`);
344
+ }
345
+ });
346
+ }
347
+ return profiles;
348
+ }
349
+ /**
350
+ * Matrix part B, as confirmed (3.14.0). Trees: no NSW licence for tree work, so the licence block is optional and the
351
+ * about page's owner block carries the qualifications and insurance lines; the council permit note is required on
352
+ * suburb and service-in-suburb pages (hidden, with its reason, once the council record is stale). The other trades
353
+ * stay on the defaults until their rules are confirmed.
354
+ */
355
+ export const SECTION_TRADE_PROFILES = Object.freeze(defineTradeProfiles({
356
+ ...Object.fromEntries(BRANDLAB_TRADES.map((trade) => [trade, UNCONFIRMED])),
357
+ trees: Object.freeze({
358
+ credentials: 'qualifications',
359
+ sections: Object.freeze({ about: Object.freeze({ licences: 'O' }) }),
360
+ slots: Object.freeze({
361
+ suburb: Object.freeze({ 'local-facts': Object.freeze(['permit']) }),
362
+ 'service-in-suburb': Object.freeze({ 'local-facts': Object.freeze(['permit']) }),
363
+ about: Object.freeze({ 'about-owner': Object.freeze(['qualifications', 'insurance']) }),
364
+ }),
365
+ source: 'v2 §3.4 matrix part B (trees row); playbook-trees §2.3 (permit slot, rows 2 and 6) and §1.7 (no tree-work licence).',
366
+ }),
367
+ }));
368
+ /** The trade map (matrix part B): each trade's section requirement changes, from `SECTION_TRADE_PROFILES`. */
369
+ export const SECTION_ORDER_TRADE_MAP = Object.freeze(Object.fromEntries(BRANDLAB_TRADES.map((trade) => [trade, SECTION_TRADE_PROFILES[trade].sections])));
370
+ /** The slots a trade requires on a family's pages, section by section, in the order the profile lists them. */
371
+ export function requiredSectionSlots(family, trade, profiles = SECTION_TRADE_PROFILES) {
372
+ const rules = trade ? profiles[trade]?.slots[family] : undefined;
373
+ if (!rules)
374
+ return [];
375
+ return Object.entries(rules).flatMap(([section, slots]) => slots.map((slot) => ({ section, slot })));
376
+ }
284
377
  /** A family's default order, with the trade's rules applied. */
285
378
  export function defaultSectionOrder(family, trade, tradeMap = SECTION_ORDER_TRADE_MAP) {
286
379
  const rows = DEFAULT_ROWS[family];