@marktiderman/genesis-forms-studio 0.4.0 → 0.5.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/README.md CHANGED
@@ -14,9 +14,10 @@ form's rows and handles every action (save, publish, mark handled, reply), so an
14
14
 
15
15
  ```tsx
16
16
  import {
17
- ResourceHeader, ReadinessChip, formNavItems, formStatusChip, FORM_NAV_ICONS,
18
- formAvailability, formCounts, readinessOf,
17
+ formNavItems, formStatusChip, FORM_NAV_ICONS, formAvailability, formCounts,
18
+ FORM_READINESS_LABELS, FORM_READINESS_OPTIONS,
19
19
  } from "@marktiderman/genesis-forms-studio";
20
+ import { ResourceHeader, ReadinessChip, readinessOf } from "@marktiderman/genesis-ui/resource";
20
21
  import { AppShellPageHeader, AppShellSubNavEnd, useAppShellSubNav } from "@marktiderman/genesis-ui/layout";
21
22
 
22
23
  useAppShellSubNav(
@@ -35,14 +36,21 @@ useAppShellSubNav(
35
36
  publish={{ onClick: publish, label: form.version ? "Publish changes" : "Publish" }}
36
37
  />
37
38
  </AppShellPageHeader>
38
- <AppShellSubNavEnd><ReadinessChip readiness={readinessOf(analysis.findings)} /></AppShellSubNavEnd>
39
+ <AppShellSubNavEnd>
40
+ <ReadinessChip
41
+ readiness={readinessOf(analysis.findings, FORM_READINESS_OPTIONS)}
42
+ labels={FORM_READINESS_LABELS}
43
+ />
44
+ </AppShellSubNavEnd>
39
45
  ```
40
46
 
41
47
  - `formNavItems("/forms/f1", { questions, logic, responses })` declares the form's four child items
42
48
  (Questions, Logic and endings, Responses, Settings) as `?tab=` links with their counts as badges,
43
49
  for the app shell's `useAppShellSubNav`. `formCounts(definition)` gives the first two.
44
50
  - `ReadinessChip` ("Ready to publish", or "3 problems to fix") goes in the row's trailing slot,
45
- `<AppShellSubNavEnd>`. `readinessOf(analysis.findings)` reads it from the builder's checks.
51
+ `<AppShellSubNavEnd>`. `readinessOf(analysis.findings, FORM_READINESS_OPTIONS)` reads it from
52
+ the builder's checks (`no-questions` is "empty"), and `FORM_READINESS_LABELS` says "Add a
53
+ question" for an empty form.
46
54
 
47
55
  ## Responses
48
56
 
@@ -89,23 +97,36 @@ section without `content` is a jump link only, for a part of the page the host r
89
97
 
90
98
  ## Share
91
99
 
92
- `ShareDialog`: the link with Copy, a QR code and poster (the host draws it), embed code, and a
93
- prefilled-link builder (`prefilledUrl`).
100
+ `ShareDialog` (genesis-ui): the link with Copy, a QR code and poster (the host draws it), embed
101
+ code, and a prefilled-link builder (`prefilledUrl`). genesis-ui's defaults say "page"; pass
102
+ `{...FORM_SHARE_LABELS}` for "Share your form" and "Anyone with the link can answer." (this
103
+ package's deprecated `ShareDialog` does that for you).
94
104
 
95
105
  ## Rules only
96
106
 
97
107
  `@marktiderman/genesis-forms-studio/rules` has the pure functions without React, for a server:
98
108
  `summarizeResponses`, the filters, `answerColumns`, `answersByKey`, `answerCell`, `toCsv`,
99
109
  `carryAnswers` (re-exported from genesis-forms), `formAvailability`, `takesResponses`,
100
- `prefilledUrl`, `embedSnippet` and the rest. For a forms list: `slugFromTitle` ("How was class?" →
110
+ and the rest (`prefilledUrl`, `embedSnippet` and `dayLabel` are still here, deprecated: they
111
+ moved to `@marktiderman/genesis-ui/resource/rules`). For a forms list: `slugFromTitle` ("How was class?" →
101
112
  `how-was-class`), `SLUG_PATTERN` and `validateSlug`, and for a duplicate `copyTitle` ("Copy of …")
102
113
  and `freeSlug` (the first of `slug`, `slug-2`… not taken). `offersSubmitAnother` says whether a
103
114
  thank-you page offers "Send another response" (never on a one-response-per-person form that isn't
104
115
  anonymous).
105
116
 
106
- ## Generic pieces
107
-
108
- `src/generic/` holds what isn't about forms: `ResourceHeader`, `ReadinessChip`,
109
- `ResponsesToolbar`, `HeadlineNumbers`, `SummaryCard`, `FollowUpList`,
110
- `ResourceSettingsPage`, `SettingsSection`, `ShareDialog` and their words. Courses, lessons and
111
- worksheets use the same page pattern, so these are meant to move to genesis-ui.
117
+ ## Moved to genesis-ui
118
+
119
+ The pieces that aren't about forms now live in genesis-ui's resource workspace, so courses,
120
+ lessons and worksheets use the same page: `ResourceHeader`, `ReadinessChip`, `readinessOf`,
121
+ `readinessChip`, `ResponsesToolbar`, `HeadlineNumbers`, `SummaryCard`, `FollowUpList`,
122
+ `ResourceSettingsPage`, `SettingsSection`, `ShareDialog`, `Chip`, `dayLabel`, `SAVE_STATE_LABEL`,
123
+ `prefilledUrl`, `embedSnippet` and their types. Import them from
124
+ `@marktiderman/genesis-ui/resource` (the pure ones also from `/resource/rules`, safe on a
125
+ server).
126
+
127
+ This package still exports every one of those names, marked `@deprecated`, and they behave as
128
+ before: the deprecated `ShareDialog`, `ReadinessChip`, `readinessOf` and `readinessChip` pass the
129
+ form's words and rule (`FORM_SHARE_LABELS`, `FORM_READINESS_LABELS`, `FORM_READINESS_OPTIONS`),
130
+ since genesis-ui's defaults are neutral. `SettingsPageSection` is genesis-ui's
131
+ `ResourceSettingsSection` (renamed, because genesis-ui's `SettingsPage` already has a
132
+ `SettingsPageSection`).
@@ -1,7 +1,18 @@
1
1
  import { summarizeValue, isOtherValue, otherOption, choiceOptions, computePath } from '@marktiderman/genesis-forms';
2
2
  export { carryAnswers } from '@marktiderman/genesis-forms';
3
+ import { SAVE_STATE_LABEL as SAVE_STATE_LABEL$1, dayLabel as dayLabel$1, embedSnippet as embedSnippet$1, prefilledUrl as prefilledUrl$1, readinessOf as readinessOf$1, readinessChip as readinessChip$1 } from '@marktiderman/genesis-ui/resource/rules';
3
4
 
4
5
  // src/answers.ts
6
+ var labelMaps = /* @__PURE__ */ new WeakMap();
7
+ function optionLabels(options) {
8
+ let map = labelMaps.get(options);
9
+ if (!map) {
10
+ map = /* @__PURE__ */ new Map();
11
+ for (const o of options) if (!map.has(o.value)) map.set(o.value, o.label);
12
+ labelMaps.set(options, map);
13
+ }
14
+ return map;
15
+ }
5
16
  function answerCell(field, value) {
6
17
  if (value === void 0 || value === null) return "";
7
18
  if (field.type === "yes-no")
@@ -9,7 +20,8 @@ function answerCell(field, value) {
9
20
  if (field.type === "consent")
10
21
  return value === true ? "Agreed" : value === false ? "Didn't agree" : String(value);
11
22
  const options = Array.isArray(field.props?.["options"]) ? field.props["options"] : [];
12
- const label = (v) => options.find((o) => o.value === v)?.label ?? String(v);
23
+ const labels = optionLabels(options);
24
+ const label = (v) => labels.get(v) ?? String(v);
13
25
  const structured = Array.isArray(value) ? value.some((v) => v !== null && typeof v === "object") : typeof value === "object";
14
26
  if (structured) {
15
27
  const summary = summarizeValue(value, field);
@@ -171,23 +183,30 @@ function summarizeResponses(items, definitions, skip = /* @__PURE__ */ new Set()
171
183
  }
172
184
  if (CHOICE_TYPES.has(field.type)) {
173
185
  const options = optionsOf(field).map((o) => ({ ...o, count: 0 }));
174
- const find = (value, from) => {
175
- if (isOtherValue(from, value) && !options.some((o) => o.value === value)) {
176
- value = OTHER_BUCKET;
177
- let bucket = options.find((o) => o.value === OTHER_BUCKET);
178
- if (!bucket) {
179
- bucket = { value: OTHER_BUCKET, label: (otherOption(field) ?? otherOption(from)).label, count: 0 };
180
- options.push(bucket);
181
- }
182
- return bucket;
186
+ const byValue = /* @__PURE__ */ new Map();
187
+ for (const o of options) if (!byValue.has(o.value)) byValue.set(o.value, o);
188
+ const add = (option) => {
189
+ options.push(option);
190
+ byValue.set(option.value, option);
191
+ return option;
192
+ };
193
+ const oldOptions = /* @__PURE__ */ new Map();
194
+ const oldOption = (from, value) => {
195
+ let map = oldOptions.get(from);
196
+ if (!map) {
197
+ map = /* @__PURE__ */ new Map();
198
+ for (const o of optionsOf(from)) if (!map.has(o.value)) map.set(o.value, o);
199
+ oldOptions.set(from, map);
183
200
  }
184
- let option = options.find((o) => o.value === value);
185
- if (!option) {
186
- const old = optionsOf(from).find((o) => o.value === value);
187
- option = { value, label: old?.label ?? value, count: 0 };
188
- options.push(option);
201
+ return map.get(value);
202
+ };
203
+ const find = (value, from) => {
204
+ const known = byValue.get(value);
205
+ if (known) return known;
206
+ if (isOtherValue(from, value)) {
207
+ return byValue.get(OTHER_BUCKET) ?? add({ value: OTHER_BUCKET, label: (otherOption(field) ?? otherOption(from)).label, count: 0 });
189
208
  }
190
- return option;
209
+ return add({ value, label: oldOption(from, value)?.label ?? value, count: 0 });
191
210
  };
192
211
  let count = 0;
193
212
  for (const { values } of answered) {
@@ -559,47 +578,6 @@ function needsFollowUp(items, options = {}) {
559
578
  ).map((x) => x.f);
560
579
  }
561
580
 
562
- // src/generic/days.ts
563
- var MONTH_DAY = new Intl.DateTimeFormat("en-US", { month: "short", day: "numeric", timeZone: "UTC" });
564
- var MONTH_DAY_YEAR = new Intl.DateTimeFormat("en-US", {
565
- month: "short",
566
- day: "numeric",
567
- year: "numeric",
568
- timeZone: "UTC"
569
- });
570
- function dayLabel(day, today) {
571
- const t = Date.parse(`${day}T00:00:00Z`);
572
- if (Number.isNaN(t)) return day;
573
- if (today) {
574
- const diff = Math.round((Date.parse(`${today}T00:00:00Z`) - t) / 864e5);
575
- if (diff === 0) return "Today";
576
- if (diff === 1) return "Yesterday";
577
- if (day.slice(0, 4) !== today.slice(0, 4)) return MONTH_DAY_YEAR.format(t);
578
- }
579
- return MONTH_DAY.format(t);
580
- }
581
-
582
- // src/generic/share.ts
583
- var RELATIVE_BASE = "http://relative.invalid";
584
- function prefilledUrl(url, values) {
585
- let absolute = true;
586
- let u;
587
- try {
588
- u = new URL(url);
589
- } catch {
590
- absolute = false;
591
- u = new URL(url, RELATIVE_BASE);
592
- }
593
- for (const [k, v] of Object.entries(values)) if (v) u.searchParams.set(k, v);
594
- if (absolute) return u.toString();
595
- const path = url.startsWith("/") ? u.pathname : u.pathname.replace(/^\//, "");
596
- return `${path}${u.search}${u.hash}`;
597
- }
598
- var attr = (s) => s.replace(/&/g, "&amp;").replace(/"/g, "&quot;").replace(/</g, "&lt;").replace(/>/g, "&gt;");
599
- function embedSnippet(url, title) {
600
- return `<iframe src="${attr(url)}" title="${attr(title)}" width="100%" height="720" style="border:0;max-width:100%" loading="lazy"></iframe>`;
601
- }
602
-
603
581
  // src/availability.ts
604
582
  function isFull(form) {
605
583
  if (form.full !== void 0) return form.full;
@@ -677,41 +655,17 @@ function formNavItems(at, counts = {}, icons) {
677
655
  item("settings", "Settings")
678
656
  ];
679
657
  }
680
-
681
- // src/generic/status.ts
682
- var SAVE_STATE_LABEL = {
683
- saved: "Changes saved",
684
- saving: "Saving\u2026",
685
- unsaved: "Unsaved changes",
686
- failed: "Couldn't save; trying again",
687
- stopped: "Couldn't save",
688
- conflict: "Changed elsewhere; reload"
689
- };
658
+ var FORM_READINESS_OPTIONS = { emptyCode: "no-questions" };
659
+ var FORM_READINESS_LABELS = { empty: "Add a question" };
660
+ var SAVE_STATE_LABEL = SAVE_STATE_LABEL$1;
661
+ var dayLabel = dayLabel$1;
662
+ var prefilledUrl = prefilledUrl$1;
663
+ var embedSnippet = embedSnippet$1;
690
664
  function readinessOf(findings, options = {}) {
691
- if (findings.some((f) => f.code === "no-questions")) return { state: "empty", count: 0 };
692
- const errors = findings.filter((f) => f.level === "error").length;
693
- if (errors) return { state: "problems", count: errors };
694
- if (options.pending) return { state: "pending", count: 0 };
695
- const warnings = findings.filter((f) => f.level === "warning").length;
696
- if (warnings) return { state: "warnings", count: warnings };
697
- return { state: "ready", count: 0 };
698
- }
699
- function readinessChip(readiness) {
700
- switch (readiness.state) {
701
- case "ready":
702
- return { label: "Ready to publish", tone: "success" };
703
- case "empty":
704
- return { label: "Add a question", tone: "muted" };
705
- case "pending":
706
- return { label: "In progress", tone: "muted" };
707
- case "problems":
708
- return {
709
- label: `${readiness.count} ${readiness.count === 1 ? "problem" : "problems"} to fix`,
710
- tone: "danger"
711
- };
712
- case "warnings":
713
- return { label: `${readiness.count} to check`, tone: "warning" };
714
- }
665
+ return readinessOf$1(findings, { ...FORM_READINESS_OPTIONS, ...options });
666
+ }
667
+ function readinessChip(readiness, labels = {}) {
668
+ return readinessChip$1(readiness, { ...FORM_READINESS_LABELS, ...labels });
715
669
  }
716
670
 
717
671
  // src/slug.ts
@@ -741,6 +695,6 @@ function offersSubmitAnother(form) {
741
695
  return form.submitAnother !== false && !onePerPerson;
742
696
  }
743
697
 
744
- export { NO_FILTERS, RESPONSE_STATUS_LABEL, SAVE_STATE_LABEL, SLUG_PATTERN, STATUS_FILTER_LABEL, answerCell, answerColumns, answersByKey, comparisonFilter, copyTitle, dayLabel, dropOffByQuestion, dropOffSummary, embedSnippet, filterResponses, followUpOf, formAvailability, formCounts, formNavItems, formStatusChip, freeSlug, hasLowRating, hasLowRatingExcept, headlineCards, headlineNumbers, highestRating, isFiltered, isFull, lowRatingAtMost, lowRatingLabel, lowScaleAtMost, lowThisWeek, lowestRating, matchesStatus, needsFollowUp, offersSubmitAnother, parseInstant, plainLabel, prefilledUrl, presetRange, readinessChip, readinessOf, slugFromTitle, summarizeResponses, takesResponses, toCsv, toResponseFilter, validateSlug, valuesByKey };
745
- //# sourceMappingURL=chunk-7XQXES5I.js.map
746
- //# sourceMappingURL=chunk-7XQXES5I.js.map
698
+ export { FORM_READINESS_LABELS, FORM_READINESS_OPTIONS, NO_FILTERS, RESPONSE_STATUS_LABEL, SAVE_STATE_LABEL, SLUG_PATTERN, STATUS_FILTER_LABEL, answerCell, answerColumns, answersByKey, comparisonFilter, copyTitle, dayLabel, dropOffByQuestion, dropOffSummary, embedSnippet, filterResponses, followUpOf, formAvailability, formCounts, formNavItems, formStatusChip, freeSlug, hasLowRating, hasLowRatingExcept, headlineCards, headlineNumbers, highestRating, isFiltered, isFull, lowRatingAtMost, lowRatingLabel, lowScaleAtMost, lowThisWeek, lowestRating, matchesStatus, needsFollowUp, offersSubmitAnother, parseInstant, plainLabel, prefilledUrl, presetRange, readinessChip, readinessOf, slugFromTitle, summarizeResponses, takesResponses, toCsv, toResponseFilter, validateSlug, valuesByKey };
699
+ //# sourceMappingURL=chunk-KUYYXBEN.js.map
700
+ //# sourceMappingURL=chunk-KUYYXBEN.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../src/answers.ts","../src/summary.ts","../src/headline.ts","../src/dropoff.ts","../src/followups.ts","../src/availability.ts","../src/status.ts","../src/moved-rules.ts","../src/slug.ts","../src/respondent.ts"],"names":["addDays","at","UI_SAVE_STATE_LABEL","uiDayLabel","uiPrefilledUrl","uiEmbedSnippet","uiReadinessOf","uiReadinessChip"],"mappings":";;;;;AAoBA,IAAM,SAAA,uBAAgB,OAAA,EAAwF;AAC9G,SAAS,aAAa,OAAA,EAAuD;AAC3E,EAAA,IAAI,GAAA,GAAM,SAAA,CAAU,GAAA,CAAI,OAAO,CAAA;AAC/B,EAAA,IAAI,CAAC,GAAA,EAAK;AACR,IAAA,GAAA,uBAAU,GAAA,EAAI;AACd,IAAA,KAAA,MAAW,CAAA,IAAK,OAAA,EAAS,IAAI,CAAC,IAAI,GAAA,CAAI,CAAA,CAAE,KAAK,CAAA,EAAG,GAAA,CAAI,GAAA,CAAI,CAAA,CAAE,KAAA,EAAO,EAAE,KAAK,CAAA;AACxE,IAAA,SAAA,CAAU,GAAA,CAAI,SAAS,GAAG,CAAA;AAAA,EAC5B;AACA,EAAA,OAAO,GAAA;AACT;AAGO,SAAS,UAAA,CAAW,OAAmB,KAAA,EAA+B;AAC3E,EAAA,IAAI,KAAA,KAAU,MAAA,IAAa,KAAA,KAAU,IAAA,EAAM,OAAO,EAAA;AAClD,EAAA,IAAI,MAAM,IAAA,KAAS,QAAA;AACjB,IAAA,OAAO,UAAU,IAAA,GAAO,KAAA,GAAQ,UAAU,KAAA,GAAQ,IAAA,GAAO,OAAO,KAAK,CAAA;AACvE,EAAA,IAAI,MAAM,IAAA,KAAS,SAAA;AACjB,IAAA,OAAO,UAAU,IAAA,GAAO,QAAA,GAAW,UAAU,KAAA,GAAQ,cAAA,GAAiB,OAAO,KAAK,CAAA;AACpF,EAAA,MAAM,OAAA,GAAU,KAAA,CAAM,OAAA,CAAQ,KAAA,CAAM,KAAA,GAAQ,SAAS,CAAC,CAAA,GACjD,KAAA,CAAM,KAAA,CAAM,SAAS,CAAA,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O,IAAA,CAAK,aAAA,KAAkB,KAAA,IAAS,CAAC,YAAA;AAC1C","file":"chunk-KUYYXBEN.js","sourcesContent":["// Turning genesis-forms answers into plain cells and columns. Shared by everything that\n// shows or exports answers: a Sheet or email delivery, a responses table, a CSV. Pure: no\n// storage, no React. Moved up from the host app's src/lib/forms/answers.ts.\nimport {\n summarizeValue,\n type FieldBlock,\n type FormDefinition,\n type Json,\n} from \"@marktiderman/genesis-forms\";\n\nexport type Cell = string | number | boolean;\n\n// carryAnswers moved to genesis-forms (an edit link's prefill runs where the engine does);\n// re-exported so the rules entry keeps it.\nexport { carryAnswers } from \"@marktiderman/genesis-forms\";\n\n// Option labels by value, built once per options array: answerCell runs once per answer, and\n// option lists can hold thousands of options. The first option with a value wins, as find() did.\n// Keys are the stored values as they are (a Map matches them like ===), so number and boolean\n// option values keep their labels too.\nconst labelMaps = new WeakMap<readonly { value: string; label?: string }[], Map<unknown, string | undefined>>();\nfunction optionLabels(options: readonly { value: string; label?: string }[]) {\n let map = labelMaps.get(options);\n if (!map) {\n map = new Map();\n for (const o of options) if (!map.has(o.value)) map.set(o.value, o.label);\n labelMaps.set(options, map);\n }\n return map;\n}\n\n/** One answer as a cell: option labels for choices, Yes/No, lists joined with commas. */\nexport function answerCell(field: FieldBlock, value: Json | undefined): Cell {\n if (value === undefined || value === null) return \"\";\n if (field.type === \"yes-no\")\n return value === true ? \"Yes\" : value === false ? \"No\" : String(value);\n if (field.type === \"consent\")\n return value === true ? \"Agreed\" : value === false ? \"Didn't agree\" : String(value);\n const options = Array.isArray(field.props?.[\"options\"])\n ? (field.props[\"options\"] as { value: string; label?: string }[])\n : [];\n const labels = optionLabels(options);\n const label = (v: Json) => labels.get(v) ?? String(v);\n // Structured values (a worksheet's rows, notes or highlights) use each type's own summary\n // from genesis-forms. Flat values keep raw numbers, so a Sheet can sort and average them.\n const structured = Array.isArray(value)\n ? value.some((v) => v !== null && typeof v === \"object\")\n : typeof value === \"object\";\n if (structured) {\n // A type genesis-forms doesn't know (yet) summarizes as \"[object Object]\": fall back to JSON.\n const summary = summarizeValue(value, field);\n return summary && !summary.includes(\"[object Object]\") ? summary : JSON.stringify(value);\n }\n if (Array.isArray(value)) return value.map(label).join(\", \");\n if (options.length) return label(value);\n return typeof value === \"number\" || typeof value === \"boolean\" ? value : String(value);\n}\n\n/** A label with recall tokens replaced by their fallback. */\nexport const plainLabel = (label: string) =>\n label.replace(/\\{\\{[^}|]*\\|?([^}]*)\\}\\}/g, (_, fallback: string) => fallback || \"…\");\n\nexport interface AnswerColumn {\n /** The field's key: stable across versions, so one column covers every version's answers. */\n key: string;\n label: string;\n}\n\n/**\n * One column per field key across the given definitions, in the order the newest\n * definition asks them, then keys only older versions had (in their order). Labels come\n * from the newest definition that has the key.\n */\nexport function answerColumns(\n definitions: readonly FormDefinition[],\n skip: ReadonlySet<string> = new Set(),\n): AnswerColumn[] {\n const columns: AnswerColumn[] = [];\n const seen = new Set<string>();\n for (const definition of definitions) {\n for (const block of definition.blocks) {\n if (block.kind !== \"field\" || seen.has(block.key) || skip.has(block.key)) continue;\n seen.add(block.key);\n columns.push({ key: block.key, label: plainLabel(block.label) });\n }\n }\n return columns;\n}\n\n/** A response's answers by field key, as cells (answers are stored by field id). */\nexport function answersByKey(\n definition: FormDefinition,\n answers: Record<string, Json>,\n): Record<string, Cell> {\n const cells: Record<string, Cell> = {};\n for (const block of definition.blocks) {\n if (block.kind !== \"field\") continue;\n const value = answers[block.id];\n if (value !== undefined) cells[block.key] = answerCell(block, value);\n }\n return cells;\n}\n\n/** A response's raw answers by field key, with the field each was given to (answers are stored by field id). */\nexport function valuesByKey(\n definition: FormDefinition,\n answers: Record<string, Json>,\n): Map<string, { field: FieldBlock; value: Json }> {\n const values = new Map<string, { field: FieldBlock; value: Json }>();\n for (const block of definition.blocks) {\n if (block.kind !== \"field\") continue;\n const value = answers[block.id];\n if (value !== undefined && value !== null) values.set(block.key, { field: block, value });\n }\n return values;\n}\n\n/**\n * CSV text (RFC 4180, CRLF) with a header row; every cell is quoted when it needs to be.\n * Text that a spreadsheet would run as a formula (starting with = + - @, tab or CR) gets a\n * leading apostrophe, so a respondent's answer can't run in Excel when staff open the\n * download. Numbers stay as they are. (Sheets delivery writes RAW values and needs none.)\n */\nexport function toCsv(header: readonly string[], rows: readonly (readonly Cell[])[]): string {\n const quote = (v: Cell) => {\n const raw = String(v);\n const s = typeof v === \"string\" && /^[=+\\-@\\t\\r]/.test(raw) ? `'${raw}` : raw;\n return /[\",\\r\\n]/.test(s) ? `\"${s.replace(/\"/g, '\"\"')}\"` : s;\n };\n return [header, ...rows].map((r) => r.map(quote).join(\",\")).join(\"\\r\\n\") + \"\\r\\n\";\n}\n","// A form's responses, question by question, as a Summary tab shows them: the average and\n// spread of each rating or NPS question, counts for each choice, the latest text answers.\n// Also the filters a Summary and its table share (dates, extra columns such as a class, a\n// low rating). Built on answers.ts, so every version's answers count under one key. Pure:\n// no storage, no React. Moved up from the host app's src/lib/forms/summary.ts.\nimport {\n choiceOptions,\n isOtherValue,\n otherOption,\n type FieldBlock,\n type FormDefinition,\n type Json,\n} from \"@marktiderman/genesis-forms\";\nimport { answerColumns, answersByKey, valuesByKey, type Cell } from \"./answers\";\n\n/**\n * Where a response is, on a form that saves answers as they go (`settings.saveProgress`):\n * `in_progress` while someone is answering, `partial` once they stopped without sending\n * (kept, and counted like a sent one), `completed` once sent.\n */\nexport type ResponseStatus = \"in_progress\" | \"partial\" | \"completed\";\n\n/** One answered form (a feedback response, a worksheet entry). */\nexport interface SummaryItem {\n id: string;\n /** The day it was answered, YYYY-MM-DD. */\n date: string;\n definition: FormDefinition;\n answers: Record<string, Json>;\n /** Extra plain values a filter can match, such as the class or coach. */\n extra?: Record<string, Cell>;\n /** Default `completed`. */\n status?: ResponseStatus | undefined;\n /**\n * The furthest question reached (a field id of `definition`), for an unfinished\n * response: genesis-forms `formProgress`'s `fieldId`. Drop-off by question reads it.\n */\n furthest?: string | null | undefined;\n /**\n * Its hidden inputs, as stored. Drop-off by question rebuilds the respondent's path\n * from them and `answers`, so logic that reads a hidden input is followed.\n */\n hidden?: Record<string, Json> | undefined;\n /**\n * Answers the host keeps apart from `answers` (contact details on their own row, say),\n * by field key. Only the path reads them: summaries and filters don't.\n */\n extraAnswers?: Record<string, Json | null | undefined> | undefined;\n}\n\n/**\n * Which responses to show by status. `counted` (the default): sent and partial ones,\n * which summaries count; `in_progress` ones are still being answered.\n */\nexport type StatusFilter = \"counted\" | \"completed\" | \"partial\" | \"in_progress\";\n\n/** The status filter's words, in the menu's order. */\nexport const STATUS_FILTER_LABEL: Record<StatusFilter, string> = {\n counted: \"Sent and partial\",\n completed: \"Sent\",\n partial: \"Partial\",\n in_progress: \"In progress\",\n};\n\n/** A response status's word, as a table or a detail panel shows it. */\nexport const RESPONSE_STATUS_LABEL: Record<ResponseStatus, string> = {\n in_progress: \"In progress\",\n partial: \"Partial\",\n completed: \"Sent\",\n};\n\n/** Whether `item` passes a status filter (no status is `completed`). */\nexport function matchesStatus(item: Pick<SummaryItem, \"status\">, filter: StatusFilter = \"counted\"): boolean {\n const status = item.status ?? \"completed\";\n return filter === \"counted\" ? status !== \"in_progress\" : status === filter;\n}\n\nexport interface ScaleSummary {\n kind: \"scale\";\n key: string;\n label: string;\n type: \"rating\" | \"nps\";\n /** The field type, as for every summary. */\n fieldType: \"rating\" | \"nps\";\n /** How many responses answered it. */\n count: number;\n min: number;\n max: number;\n /** Null when no one answered. */\n average: number | null;\n /** One per value from min to max, in order, zeros included. */\n buckets: { value: number; count: number }[];\n /**\n * Answers given on an older version's different scale (a 1–10 rating now 1–5), moved\n * onto this one in proportion: they count, at their nearest point on this scale.\n */\n rescaled: number;\n /** Answers left out: outside their own question's scale, or not a whole number. */\n excluded: number;\n /** NPS only: promoters 9–10, passives 7–8, detractors 0–6, score = % promoters − % detractors. */\n nps: { promoters: number; passives: number; detractors: number; score: number } | null;\n}\n\nexport interface ChoiceSummary {\n kind: \"choice\";\n key: string;\n label: string;\n /** single-choice, multi-choice, dropdown, yes-no or consent. */\n fieldType: string;\n /** How many responses answered it. */\n count: number;\n /** Several options per response, so the percentages can add up to more than 100. */\n multiple: boolean;\n /** The newest version's options in order, then any only older versions had. */\n options: { value: string; label: string; count: number; percent: number }[];\n}\n\nexport interface TextSummary {\n kind: \"text\";\n key: string;\n label: string;\n /** The field type: short-text, long-text, email… */\n fieldType: string;\n count: number;\n /** Every answer, newest day first. */\n answers: { id: string; date: string; text: string }[];\n}\n\nexport type QuestionSummary = ScaleSummary | ChoiceSummary | TextSummary;\n\nconst CHOICE_TYPES: ReadonlySet<string> = new Set([\n \"single-choice\",\n \"multi-choice\",\n \"dropdown\",\n \"yes-no\",\n \"consent\",\n]);\nconst YES_NO = [\n { value: \"true\", label: \"Yes\" },\n { value: \"false\", label: \"No\" },\n];\nconst CONSENT = [\n { value: \"true\", label: \"Agreed\" },\n { value: \"false\", label: \"Didn't agree\" },\n];\n\n/** The summary row that counts a question's typed \"Other\" answers. */\nexport const OTHER_BUCKET = \"__other__\";\n\nconst optionsOf = (field: FieldBlock) =>\n field.type === \"yes-no\"\n ? YES_NO\n : field.type === \"consent\"\n ? CONSENT\n : choiceOptions(field).map((o) => ({ value: o.value, label: o.label ?? o.value }));\n\nconst ratingMax = (field: FieldBlock) => {\n const max = field.props?.[\"max\"];\n return typeof max === \"number\" && Number.isInteger(max) && max >= 1 && max <= 100 ? max : 5;\n};\n\n/** A rating or NPS question's own scale; null for other questions. */\nconst scaleOf = (field: FieldBlock): { min: number; max: number } | null =>\n field.type === \"nps\" ? { min: 0, max: 10 } : field.type === \"rating\" ? { min: 1, max: ratingMax(field) } : null;\n\nconst newestFirst = <T extends { date: string }>(items: readonly T[]) =>\n items\n .map((item, index) => ({ item, index }))\n .sort((x, y) =>\n x.item.date < y.item.date ? 1 : x.item.date > y.item.date ? -1 : x.index - y.index,\n )\n .map((x) => x.item);\n\n/**\n * One summary per question across `definitions` (newest first: it sets the order, labels,\n * type and options), counting each item's answers by field key. Keys in `skip` are left out.\n */\nexport function summarizeResponses(\n items: readonly SummaryItem[],\n definitions: readonly FormDefinition[],\n skip: ReadonlySet<string> = new Set(),\n): QuestionSummary[] {\n const newest = new Map<string, FieldBlock>();\n for (const definition of definitions) {\n for (const block of definition.blocks) {\n if (block.kind === \"field\" && !newest.has(block.key)) newest.set(block.key, block);\n }\n }\n const answered = newestFirst(items).map((item) => ({\n item,\n values: valuesByKey(item.definition, item.answers),\n cells: answersByKey(item.definition, item.answers),\n }));\n\n return answerColumns(definitions, skip).flatMap((column): QuestionSummary[] => {\n const field = newest.get(column.key);\n if (!field) return [];\n const { key, label } = column;\n\n if (field.type === \"rating\" || field.type === \"nps\") {\n const nps = field.type === \"nps\";\n // The newest version sets the scale. One pass: a bucket array, never a spread of\n // every answer (that overflows the stack on large forms).\n const min = nps ? 0 : 1;\n const max = nps ? 10 : ratingMax(field);\n const counts = new Array<number>(max - min + 1).fill(0);\n let count = 0;\n let sum = 0;\n let promoters = 0;\n let detractors = 0;\n let rescaled = 0;\n let excluded = 0;\n for (const { values } of answered) {\n const answer = values.get(key);\n if (!answer) continue;\n const v = answer.value;\n const own = scaleOf(answer.field);\n if (!own || typeof v !== \"number\" || !Number.isInteger(v) || v < own.min || v > own.max) {\n excluded++;\n continue;\n }\n let x = v;\n if (own.min !== min || own.max !== max) {\n // Another version's scale: the same share of the way along this one.\n x = own.max === own.min ? max : min + ((v - own.min) * (max - min)) / (own.max - own.min);\n rescaled++;\n }\n const point = Math.round(x);\n counts[point - min]! += 1;\n count++;\n sum += x;\n if (point >= 9) promoters++;\n else if (point <= 6) detractors++;\n }\n return [\n {\n kind: \"scale\",\n key,\n label,\n type: field.type,\n fieldType: field.type,\n count,\n min,\n max,\n average: count ? sum / count : null,\n buckets: counts.map((c, i) => ({ value: min + i, count: c })),\n rescaled,\n excluded,\n nps:\n nps && count\n ? {\n promoters,\n passives: count - promoters - detractors,\n detractors,\n score: Math.round(((promoters - detractors) / count) * 100),\n }\n : null,\n },\n ];\n }\n\n if (CHOICE_TYPES.has(field.type)) {\n const options = optionsOf(field).map((o) => ({ ...o, count: 0 }));\n // Lookups by value, not options.find per answer: option lists can hold thousands.\n const byValue = new Map<string, (typeof options)[number]>();\n for (const o of options) if (!byValue.has(o.value)) byValue.set(o.value, o);\n const add = (option: (typeof options)[number]) => {\n options.push(option);\n byValue.set(option.value, option);\n return option;\n };\n const oldOptions = new Map<FieldBlock, Map<string, { label?: string }>>();\n const oldOption = (from: FieldBlock, value: string) => {\n let map = oldOptions.get(from);\n if (!map) {\n map = new Map();\n for (const o of optionsOf(from)) if (!map.has(o.value)) map.set(o.value, o);\n oldOptions.set(from, map);\n }\n return map.get(value);\n };\n const find = (value: string, from: FieldBlock) => {\n const known = byValue.get(value);\n if (known) return known;\n // Typed \"Other\" answers count together, under the question's Other label. (Checked only\n // for values not already counted: isOtherValue looks through the question's options.)\n if (isOtherValue(from, value)) {\n return (\n byValue.get(OTHER_BUCKET) ??\n add({ value: OTHER_BUCKET, label: (otherOption(field) ?? otherOption(from))!.label, count: 0 })\n );\n }\n // An option only an older version had: its label from that version.\n return add({ value, label: oldOption(from, value)?.label ?? value, count: 0 });\n };\n let count = 0;\n for (const { values } of answered) {\n const answer = values.get(key);\n if (!answer) continue;\n const chosen = (Array.isArray(answer.value) ? answer.value : [answer.value]).filter(\n (v): v is string | boolean => typeof v === \"string\" || typeof v === \"boolean\",\n );\n if (!chosen.length) continue;\n count++;\n for (const v of new Set(chosen.map(String))) find(v, answer.field).count++;\n }\n return [\n {\n kind: \"choice\",\n key,\n label,\n fieldType: field.type,\n count,\n multiple: field.type === \"multi-choice\",\n options: options.map((o) => ({ ...o, percent: count ? (o.count / count) * 100 : 0 })),\n },\n ];\n }\n\n const answers = answered.flatMap(({ item, cells }) => {\n const text = String(cells[key] ?? \"\").trim();\n return text ? [{ id: item.id, date: item.date, text }] : [];\n });\n return [{ kind: \"text\", key, label, fieldType: field.type, count: answers.length, answers }];\n });\n}\n\n/** The highest score any rating question in `definitions` asks for (NPS left out); null when none. */\nexport function highestRating(definitions: readonly FormDefinition[]): number | null {\n let max: number | null = null;\n for (const definition of definitions) {\n for (const block of definition.blocks) {\n if (block.kind === \"field\" && block.type === \"rating\")\n max = Math.max(max ?? 0, ratingMax(block));\n }\n }\n return max;\n}\n\n/** The lowest rating-question answer in an item (NPS left out), or null when it has none. */\nexport function lowestRating(item: SummaryItem): number | null {\n let lowest: number | null = null;\n for (const { field, value } of valuesByKey(item.definition, item.answers).values()) {\n if (field.type === \"rating\" && typeof value === \"number\" && (lowest === null || value < lowest))\n lowest = value;\n }\n return lowest;\n}\n\n/** \"Low\" is the bottom 40% of a rating's scale: 2 or below out of 5, 4 or below out of 10. */\nconst LOW_SHARE = 0.4;\n/** NPS detractors: 0 to 6. */\nconst NPS_LOW = 6;\n\n/**\n * The highest answer that counts as low on a rating or NPS question: the bottom 40% of a\n * rating's scale (at least 1), or 0–6 (detractors) on NPS. Null for other questions.\n */\nexport function lowRatingAtMost(field: FieldBlock): number | null {\n if (field.type === \"nps\") return NPS_LOW;\n if (field.type !== \"rating\") return null;\n return lowScaleAtMost(\"rating\", ratingMax(field));\n}\n\n/** lowRatingAtMost for a scale known only by its type and top score (a ScaleSummary's). */\nexport function lowScaleAtMost(type: \"rating\" | \"nps\", max: number): number {\n return type === \"nps\" ? NPS_LOW : Math.max(1, Math.floor(max * LOW_SHARE));\n}\n\n/** Whether any rating or NPS answer in an item is low on its own question's scale. */\nexport function hasLowRating(item: SummaryItem): boolean {\n return hasLowRatingExcept(item, new Set());\n}\n\n/** hasLowRating, leaving out the answers to keys in `skip` (as summaries and needsFollowUp do). */\nexport function hasLowRatingExcept(item: SummaryItem, skip: ReadonlySet<string>): boolean {\n for (const [key, { field, value }] of valuesByKey(item.definition, item.answers)) {\n if (skip.has(key)) continue;\n const atMost = lowRatingAtMost(field);\n if (atMost !== null && typeof value === \"number\" && value <= atMost) return true;\n }\n return false;\n}\n\n/**\n * What \"low\" means across `definitions`, in words: \"2 or below\" for one 1–5 scale, \"2 or\n * below out of 5, 4 or below out of 10\" for two, \"0–6 on NPS\" beside them (\"0–6\" alone).\n * Null when no question has a rating or NPS answer.\n */\nexport function lowRatingLabel(definitions: readonly FormDefinition[]): string | null {\n const scales = new Set<number>();\n let nps = false;\n for (const definition of definitions) {\n for (const block of definition.blocks) {\n if (block.kind !== \"field\") continue;\n if (block.type === \"nps\") nps = true;\n else if (block.type === \"rating\") scales.add(ratingMax(block));\n }\n }\n const several = scales.size + (nps ? 1 : 0) > 1;\n const parts = [...scales]\n .sort((a, b) => a - b)\n .map((max) => {\n const atMost = Math.max(1, Math.floor(max * LOW_SHARE));\n return several ? `${atMost} or below out of ${max}` : `${atMost} or below`;\n });\n if (nps) parts.push(several ? `0–${NPS_LOW} on NPS` : `0–${NPS_LOW}`);\n return parts.length ? parts.join(\", \") : null;\n}\n\nexport interface ResponseFilter {\n /** First and last day, YYYY-MM-DD, both included; open-ended when absent. */\n from?: string | null;\n to?: string | null;\n /** Extra values that must match exactly, such as { class: \"6am WOD\" }. */\n match?: Record<string, string | null | undefined>;\n /** Only items with a rating at or below this (any rating question). */\n ratingAtMost?: number | null;\n /** Only items with a low answer on its question's own scale (hasLowRating). */\n low?: boolean;\n /** By status (matchesStatus); default `counted`: sent and partial, not in progress. */\n status?: StatusFilter | undefined;\n}\n\n/** Whether a filter leaves anything out beyond the default (in-progress responses). */\nexport function isFiltered(filter: ResponseFilter): boolean {\n return Boolean(\n filter.from ||\n filter.to ||\n filter.ratingAtMost != null ||\n filter.low ||\n (filter.status && filter.status !== \"counted\") ||\n Object.values(filter.match ?? {}).some((v) => v != null && v !== \"\"),\n );\n}\n\n/** The items a filter keeps, in their order. */\nexport function filterResponses<T extends SummaryItem>(\n items: readonly T[],\n filter: ResponseFilter,\n): T[] {\n const match = Object.entries(filter.match ?? {}).filter(\n (e): e is [string, string] => e[1] != null && e[1] !== \"\",\n );\n return items.filter((item) => {\n if (!matchesStatus(item, filter.status)) return false;\n if (filter.from && item.date < filter.from) return false;\n if (filter.to && item.date > filter.to) return false;\n if (match.some(([key, value]) => String(item.extra?.[key] ?? \"\") !== value)) return false;\n if (filter.ratingAtMost != null) {\n const lowest = lowestRating(item);\n if (lowest === null || lowest > filter.ratingAtMost) return false;\n }\n if (filter.low && !hasLowRating(item)) return false;\n return true;\n });\n}\n\nexport type DatePreset = \"all\" | \"today\" | \"week\" | \"7d\" | \"30d\" | \"month\";\n\nconst addDays = (day: string, n: number) => {\n const t = Date.parse(`${day}T00:00:00Z`) + n * 86_400_000;\n return new Date(t).toISOString().slice(0, 10);\n};\n\n/**\n * A preset's first and last day, given today (YYYY-MM-DD, on the clock the items' days\n * use). \"week\" starts on Monday; \"7d\" and \"30d\" include today.\n */\nexport function presetRange(\n preset: DatePreset,\n today: string,\n): { from: string | null; to: string | null } {\n switch (preset) {\n case \"all\":\n return { from: null, to: null };\n case \"today\":\n return { from: today, to: today };\n case \"week\": {\n const weekday = new Date(`${today}T00:00:00Z`).getUTCDay(); // 0 is Sunday\n return { from: addDays(today, -((weekday + 6) % 7)), to: today };\n }\n case \"7d\":\n return { from: addDays(today, -6), to: today };\n case \"30d\":\n return { from: addDays(today, -29), to: today };\n case \"month\":\n return { from: `${today.slice(0, 7)}-01`, to: today };\n }\n}\n\n// The filter bar ----------------------------------------------------------------------------\n\n/** What the filter bar holds; `toResponseFilter` turns it into a filter. */\nexport interface FiltersValue {\n when: DatePreset | \"custom\";\n /** Custom range, YYYY-MM-DD; empty for open-ended. */\n from: string;\n to: string;\n /** By choice filter key, e.g. { class: \"6am WOD\" }; missing or empty for any. */\n match: Record<string, string>;\n ratingAtMost: number | null;\n /** Low ratings, each on its own question's scale (lowRatingAtMost). */\n low: boolean;\n /** By status, on a form that saves answers as they go; missing is `counted`. */\n status?: StatusFilter | undefined;\n}\n\nexport const NO_FILTERS: FiltersValue = {\n when: \"all\",\n from: \"\",\n to: \"\",\n match: {},\n ratingAtMost: null,\n low: false,\n};\n\n/** The filter for `value`, given today's date on the clock the responses' days use. */\nexport function toResponseFilter(value: FiltersValue, today: string): ResponseFilter {\n const range =\n value.when === \"custom\"\n ? { from: value.from || null, to: value.to || null }\n : presetRange(value.when, today);\n return {\n ...range,\n match: value.match,\n ratingAtMost: value.ratingAtMost,\n low: value.low,\n ...(value.status ? { status: value.status } : {}),\n };\n}\n\n/**\n * The one-click \"Low ratings this week\": this week, and low on each question's own scale\n * (lowRatingAtMost: the bottom 40% of a rating, NPS detractors), other filters kept.\n */\nexport const lowThisWeek = (value: FiltersValue): FiltersValue => ({\n ...value,\n when: \"week\",\n low: true,\n});\n","// The Responses tab's headline numbers: how many responses (and the change against the\n// period before), the average of the form's main rating, how many have a low rating, and\n// the rate of the form's first consent or yes/no question. Built on summary.ts. Pure.\nimport type { FormDefinition } from \"@marktiderman/genesis-forms\";\nimport type { HeadlineNumber } from \"@marktiderman/genesis-ui/resource\";\nimport {\n hasLowRatingExcept,\n presetRange,\n summarizeResponses,\n type FiltersValue,\n type ResponseFilter,\n type SummaryItem,\n} from \"./summary\";\n\nexport interface Headline {\n responses: {\n count: number;\n /** Responses in the period before, under the same other filters; null with no period. */\n previous: number | null;\n /** count − previous; null with no period. */\n change: number | null;\n /** How many of `count` are partial (never sent); left out when there are none. */\n partial?: number;\n };\n /** The first rating question (newest definition order); null when the form has none. */\n rating: {\n key: string;\n label: string;\n max: number;\n /** Null when nobody answered it. */\n average: number | null;\n /** The same question's average in the period before; null without one or without answers. */\n previousAverage: number | null;\n /** average − previousAverage, when both are known. */\n change: number | null;\n } | null;\n /** Responses with a low answer on any rating or NPS question; null when there is none. */\n low: { count: number } | null;\n /** The first consent question, else the first yes/no one; null when there is none. */\n rate: {\n key: string;\n label: string;\n type: \"consent\" | \"yes-no\";\n /** Agreed or Yes. */\n yes: number;\n /** How many answered it. */\n count: number;\n /** 0–100; null when nobody answered. */\n percent: number | null;\n } | null;\n}\n\n/**\n * The headline numbers for `items` (already filtered), with `previous` (the same filters\n * over the period before, from `comparisonFilter`) for the changes. `definitions` are\n * newest first, as `summarizeResponses` takes them; `skip` leaves keys out.\n */\nexport function headlineNumbers(\n items: readonly SummaryItem[],\n definitions: readonly FormDefinition[],\n options: { previous?: readonly SummaryItem[] | null; skip?: ReadonlySet<string> } = {},\n): Headline {\n const previous = options.previous ?? null;\n const summaries = summarizeResponses(items, definitions, options.skip);\n const partial = items.filter((i) => i.status === \"partial\").length;\n const before = previous ? summarizeResponses(previous, definitions, options.skip) : null;\n\n const scale = summaries.find((s) => s.kind === \"scale\" && s.type === \"rating\");\n let rating: Headline[\"rating\"] = null;\n if (scale && scale.kind === \"scale\") {\n const old = before?.find((s) => s.kind === \"scale\" && s.key === scale.key);\n const previousAverage = old && old.kind === \"scale\" ? old.average : null;\n rating = {\n key: scale.key,\n label: scale.label,\n max: scale.max,\n average: scale.average,\n previousAverage,\n change:\n scale.average !== null && previousAverage !== null\n ? Math.round((scale.average - previousAverage) * 10) / 10\n : null,\n };\n }\n\n const scored = summaries.some((s) => s.kind === \"scale\");\n const choice =\n summaries.find((s) => s.kind === \"choice\" && s.fieldType === \"consent\") ??\n summaries.find((s) => s.kind === \"choice\" && s.fieldType === \"yes-no\");\n let rate: Headline[\"rate\"] = null;\n if (choice && choice.kind === \"choice\") {\n const yes = choice.options.find((o) => o.value === \"true\")?.count ?? 0;\n rate = {\n key: choice.key,\n label: choice.label,\n type: choice.fieldType as \"consent\" | \"yes-no\",\n yes,\n count: choice.count,\n percent: choice.count ? Math.round((yes / choice.count) * 100) : null,\n };\n }\n\n return {\n responses: {\n count: items.length,\n previous: previous ? previous.length : null,\n change: previous ? items.length - previous.length : null,\n ...(partial ? { partial } : {}),\n },\n rating,\n // The same skip as needsFollowUp, so the Low ratings card and the follow-up list agree.\n low: scored ? { count: items.filter((i) => hasLowRatingExcept(i, options.skip ?? new Set())).length } : null,\n rate,\n };\n}\n\nconst addDays = (day: string, n: number) =>\n new Date(Date.parse(`${day}T00:00:00Z`) + n * 86_400_000).toISOString().slice(0, 10);\nconst daysBetween = (from: string, to: string) =>\n Math.round((Date.parse(`${to}T00:00:00Z`) - Date.parse(`${from}T00:00:00Z`)) / 86_400_000);\n\n/**\n * The period before the one the filter bar picks, with the bar's other filters kept, and\n * what to call it (\"last week\"). \"This week\" compares with the same weekdays last week,\n * \"This month\" with last month up to the same day, any other range with as many days\n * just before it. Null for \"All time\", or a\n * custom range with an open end.\n */\nexport function comparisonFilter(\n value: FiltersValue,\n today: string,\n): { filter: ResponseFilter; label: string } | null {\n const range =\n value.when === \"custom\"\n ? { from: value.from || null, to: value.to || null }\n : presetRange(value.when, today);\n if (!range.from || !range.to || range.to < range.from) return null;\n let from: string;\n let to: string;\n if (value.when === \"month\") {\n const first = `${range.from.slice(0, 7)}-01`;\n const lastMonth = addDays(first, -1); // the last day of last month\n from = `${lastMonth.slice(0, 7)}-01`;\n const day = Math.min(Number(range.to.slice(8, 10)), Number(lastMonth.slice(8, 10)));\n to = `${lastMonth.slice(0, 7)}-${String(day).padStart(2, \"0\")}`;\n } else if (value.when === \"week\") {\n // Monday to today, against the same weekdays last week.\n from = addDays(range.from, -7);\n to = addDays(range.to, -7);\n } else {\n const length = daysBetween(range.from, range.to) + 1;\n to = addDays(range.from, -1);\n from = addDays(range.from, -length);\n }\n const label =\n value.when === \"today\"\n ? \"yesterday\"\n : value.when === \"week\"\n ? \"last week\"\n : value.when === \"month\"\n ? \"last month\"\n : value.when === \"7d\"\n ? \"the 7 days before\"\n : value.when === \"30d\"\n ? \"the 30 days before\"\n : \"the days before\";\n return {\n filter: {\n from,\n to,\n match: value.match,\n ratingAtMost: value.ratingAtMost,\n low: value.low,\n ...(value.status ? { status: value.status } : {}),\n },\n label,\n };\n}\n\nconst signed = (n: number, digits = 0) => {\n const s = Math.abs(n).toFixed(digits);\n return n > 0 ? `+${s}` : n < 0 ? `−${s}` : s;\n};\n\n/**\n * The cards for `headlineNumbers`' answer: Responses (with the change against `period`,\n * e.g. \"last week\"), Average rating, Low ratings, and the consent or yes/no rate. A card\n * the form has no question for is left out.\n */\nexport function headlineCards(\n headline: Headline,\n options: {\n period?: string | null | undefined;\n /** How many low-rated responses still need a follow-up (not handled); the card says so. */\n lowOpen?: number | undefined;\n } = {},\n): HeadlineNumber[] {\n const cards: HeadlineNumber[] = [];\n const { responses, rating, low, rate } = headline;\n // Partial responses count, and the card says how many there are.\n const partial = responses.partial ? `${responses.partial} partial` : null;\n cards.push({\n key: \"responses\",\n label: \"Responses\",\n value: responses.count,\n ...(responses.change !== null && options.period\n ? {\n detail:\n (responses.change === 0 ? `Same as ${options.period}` : `${signed(responses.change)} vs ${options.period}`) +\n (partial ? ` · ${partial}` : \"\"),\n tone: responses.change > 0 ? (\"positive\" as const) : responses.change < 0 ? (\"negative\" as const) : (\"muted\" as const),\n }\n : partial\n ? { detail: `Including ${partial}` }\n : {}),\n });\n if (rating) {\n const change = rating.change;\n cards.push({\n key: \"rating\",\n label: \"Average rating\",\n value: rating.average === null ? \"–\" : `${rating.average.toFixed(1)} / ${rating.max}`,\n ...(change !== null && options.period\n ? {\n detail: change === 0 ? `Same as ${options.period}` : `${change > 0 ? \"Up\" : \"Down\"} ${Math.abs(change).toFixed(1)}`,\n tone: change > 0 ? (\"positive\" as const) : change < 0 ? (\"warning\" as const) : (\"muted\" as const),\n }\n : rating.average === null\n ? { detail: \"No ratings yet\" }\n : {}),\n });\n }\n if (low) {\n const open = options.lowOpen ?? low.count;\n cards.push({\n key: \"low\",\n label: \"Low ratings\",\n value: low.count,\n ...(open\n ? { detail: open === 1 ? \"Needs a follow-up\" : `${open} need a follow-up`, tone: \"negative\" as const }\n : { detail: low.count ? \"All followed up\" : \"None\" }),\n });\n }\n if (rate) {\n cards.push({\n key: \"rate\",\n label: rate.label || (rate.type === \"consent\" ? \"Agreed\" : \"Yes\"),\n value: rate.percent === null ? \"–\" : `${rate.percent}%`,\n detail: rate.count\n ? `${rate.yes} of ${rate.count} ${rate.type === \"consent\" ? \"agreed\" : \"said yes\"}`\n : \"No answers yet\",\n });\n }\n return cards;\n}\n","// Drop-off by question (Typeform's \"question-by-question insights\"), for a form that saves\n// answers as they go: for each question, how many people reached it and how many stopped\n// there without sending. Worked out on each respondent's own path, rebuilt with genesis-forms\n// `computePath` from what a response keeps, and its furthest question. Pure.\nimport { computePath, type FieldBlock, type FormDefinition, type Json } from \"@marktiderman/genesis-forms\";\nimport { answerColumns } from \"./answers\";\nimport type { SummaryItem } from \"./summary\";\n\nexport interface QuestionDropOff {\n key: string;\n label: string;\n /** How many responses reached this question (it was on their path, on screen or answered). */\n views: number;\n /** How many stopped here: their furthest question, never sent. */\n stopped: number;\n /** stopped ÷ views as a whole percentage; null when nobody reached it. */\n dropOff: number | null;\n}\n\nexport interface DropOffSummary {\n /**\n * How many people started: distinct responses of any status (sent, partial, in progress),\n * each once. Someone is saved once they answer a question or move on from the first.\n */\n started: number;\n /** Each question's views and drop-off (`dropOffByQuestion`). */\n dropOffs: QuestionDropOff[];\n}\n\n/**\n * The field ids on a response's path, in order: genesis-forms `computePath` over its\n * `answers` (by field id), its `hidden` inputs and its `extraAnswers` (by field key).\n */\nfunction pathFields(item: SummaryItem): string[] {\n const { definition } = item;\n const fields = new Map<string, FieldBlock>();\n for (const block of definition.blocks) if (block.kind === \"field\") fields.set(block.id, block);\n const values: Record<string, Json | undefined> = { ...item.answers };\n if (item.extraAnswers) {\n for (const field of fields.values()) {\n const kept = Object.prototype.hasOwnProperty.call(item.extraAnswers, field.key)\n ? item.extraAnswers[field.key]\n : undefined;\n // A null in `answers` is a placeholder for a value kept apart: the extra one fills it.\n if (kept != null && values[field.id] == null) values[field.id] = kept;\n }\n }\n const { path } = computePath(definition, { values, hidden: item.hidden ?? {}, fields });\n return path.filter((id) => fields.has(id));\n}\n\n/**\n * Each question's views and drop-off, in the newest definition's order (`definitions`\n * newest first, as `summarizeResponses` takes them), matched across versions by field key.\n * Each response counts once (by `id`).\n *\n * - A sent response (`completed`, or no status) reached every question on its path and\n * stopped at none. A question logic hid or jumped over for them was never reached.\n * - A `partial` response reached the questions on its path before its `furthest` (the\n * path is rebuilt from the answers so far, so it can run past it), then `furthest`, and\n * stopped there. One without `furthest` (saved before it was kept) is left out.\n * - An `in_progress` response is left out: they may still be answering.\n *\n * The path is rebuilt from `answers`, `hidden` and `extraAnswers`; give the item every\n * answer logic can read, or a rule reading a missing one sees it unanswered. Two things a\n * stored response can't tell, so they count as on the path:\n *\n * - A question a prefilled link answered and hid (`props.prefill.hideWhenPrefilled`):\n * which answers came from the link lives in the form's answer events, which aren't kept.\n * - A rule comparing a pick from a host-supplied option list to an option value, when the\n * host stores the pick as its label: the rule sees the label.\n *\n * Someone who opened the form and left before moving on from the first question was\n * never saved, so they aren't counted.\n */\nexport function dropOffByQuestion(\n items: readonly SummaryItem[],\n definitions: readonly FormDefinition[],\n skip: ReadonlySet<string> = new Set(),\n): QuestionDropOff[] {\n const views = new Map<string, number>();\n const stopped = new Map<string, number>();\n const add = (map: Map<string, number>, key: string) => map.set(key, (map.get(key) ?? 0) + 1);\n const seen = new Set<string>();\n for (const item of items) {\n if (seen.has(item.id)) continue;\n seen.add(item.id);\n const status = item.status ?? \"completed\";\n if (status === \"in_progress\") continue;\n const keyOf = new Map<string, string>();\n const order = new Map<string, number>();\n item.definition.blocks.forEach((b, at) => {\n if (b.kind === \"field\") keyOf.set(b.id, b.key);\n order.set(b.id, at);\n });\n if (status === \"completed\") {\n for (const id of pathFields(item)) add(views, keyOf.get(id)!);\n continue;\n }\n const furthest = item.furthest ?? null;\n if (furthest === null || !keyOf.has(furthest)) continue;\n const at = order.get(furthest)!;\n for (const id of pathFields(item)) if (id !== furthest && order.get(id)! < at) add(views, keyOf.get(id)!);\n add(views, keyOf.get(furthest)!);\n add(stopped, keyOf.get(furthest)!);\n }\n return answerColumns(definitions, skip).map(({ key, label }) => {\n const reached = views.get(key) ?? 0;\n const left = stopped.get(key) ?? 0;\n return {\n key,\n label,\n views: reached,\n stopped: left,\n dropOff: reached ? Math.round((left / reached) * 100) : null,\n };\n });\n}\n\n/**\n * What `<DropOffByQuestion>` shows: how many people started and each question's drop-off.\n * Pass every response under the host's filters except status (in-progress ones count as\n * started, never per question).\n */\nexport function dropOffSummary(\n items: readonly SummaryItem[],\n definitions: readonly FormDefinition[],\n skip: ReadonlySet<string> = new Set(),\n): DropOffSummary {\n return {\n started: new Set(items.map((i) => i.id)).size,\n dropOffs: dropOffByQuestion(items, definitions, skip),\n };\n}\n","// Which responses need a follow-up (a low rating, not handled yet), with the low score\n// and the first written comment each one has. Pure.\nimport { answerCell, valuesByKey } from \"./answers\";\nimport { lowRatingAtMost, type SummaryItem } from \"./summary\";\n\nexport interface FollowUp<T extends SummaryItem = SummaryItem> {\n item: T;\n /** The lowest low answer, on its own question's scale. */\n rating: { value: number; max: number; type: \"rating\" | \"nps\" };\n /** The first written answer (short or long text), trimmed; null when there is none. */\n comment: string | null;\n}\n\nconst TEXT_TYPES: ReadonlySet<string> = new Set([\"long-text\", \"short-text\", \"text\"]);\n\nconst scaleMax = (type: string, props: Record<string, unknown> | undefined) =>\n type === \"nps\" ? 10 : typeof props?.[\"max\"] === \"number\" ? (props[\"max\"] as number) : 5;\n\n/** One item's follow-up, or null when none of its answers is low. */\nexport function followUpOf<T extends SummaryItem>(\n item: T,\n skip: ReadonlySet<string> = new Set(),\n): FollowUp<T> | null {\n let rating: FollowUp[\"rating\"] | null = null;\n let comment: string | null = null;\n for (const [key, { field, value }] of valuesByKey(item.definition, item.answers)) {\n if (skip.has(key)) continue;\n const atMost = lowRatingAtMost(field);\n if (atMost !== null && typeof value === \"number\" && value <= atMost) {\n const max = scaleMax(field.type, field.props);\n // The lowest share of its scale wins: a 2 of 5 is lower than a 4 of 10.\n if (!rating || value / max < rating.value / rating.max)\n rating = { value, max, type: field.type as \"rating\" | \"nps\" };\n } else if (comment === null && TEXT_TYPES.has(field.type)) {\n const text = String(answerCell(field, value)).trim();\n if (text) comment = text;\n }\n }\n return rating ? { item, rating, comment } : null;\n}\n\n/**\n * The items that need a follow-up, newest day first: a low answer on a rating or NPS\n * question (lowRatingAtMost), and not handled yet. `skip` leaves keys out (contact details).\n */\nexport function needsFollowUp<T extends SummaryItem>(\n items: readonly T[],\n options: { isHandled?: (item: T) => boolean; skip?: ReadonlySet<string> } = {},\n): FollowUp<T>[] {\n return items\n .map((item, index) => ({ index, f: options.isHandled?.(item) ? null : followUpOf(item, options.skip) }))\n .filter((x): x is { index: number; f: FollowUp<T> } => x.f !== null)\n .sort((x, y) =>\n x.f.item.date < y.f.item.date ? 1 : x.f.item.date > y.f.item.date ? -1 : x.index - y.index,\n )\n .map((x) => x.f);\n}\n","// Whether a form is taking responses, and if not why: the one rule every surface uses\n// (the public page and its submit endpoint, a forms list, the form's header and\n// settings). Generic form settings (status, opening and closing times, paused and a\n// response cap). Pure. Moved up from the host app's src/lib/forms/availability.ts; an app\n// that stores forms should apply the same rule on save.\n\nexport type FormAvailability =\n \"draft\" | \"archived\" | \"paused\" | \"scheduled\" | \"closed\" | \"full\" | \"live\";\n\nexport interface AvailabilityInput {\n status: \"draft\" | \"active\" | \"archived\";\n /** False when the form has never been published (it has no version to serve). */\n published?: boolean;\n /**\n * ISO times it takes responses from and until; open-ended when absent. Each needs `Z` or\n * an offset (`+02:00`): a time without one would be read on whatever clock the code runs\n * on. One that doesn't parse, or has no offset, keeps the form closed (fail closed).\n * Normalise times where they are written (`new Date(…).toISOString()`).\n */\n opensAt?: string | null | undefined;\n closesAt?: string | null | undefined;\n paused?: boolean | undefined;\n /** At most this many completed responses; null or absent for no cap. */\n responseCap?: number | null | undefined;\n /** Completed, non-deleted responses so far, when the caller knows the count. */\n completedResponses?: number | null | undefined;\n /** Whether the cap is reached, when only that is known (the public page never sees the count). */\n full?: boolean | undefined;\n}\n\n/** Whether the form has its response cap: from `full` when given, else from the cap and count. */\nexport function isFull(\n form: Pick<AvailabilityInput, \"responseCap\" | \"completedResponses\" | \"full\">,\n): boolean {\n if (form.full !== undefined) return form.full;\n return (\n form.responseCap != null &&\n form.completedResponses != null &&\n form.completedResponses >= form.responseCap\n );\n}\n\n// A date, a time, then Z or an hours-and-minutes offset.\nconst INSTANT = /^\\d{4}-\\d{2}-\\d{2}[T ]\\d{2}:\\d{2}(?::\\d{2}(?:\\.\\d+)?)?(?:Z|[+-]\\d{2}:?\\d{2})$/i;\n\n/** An ISO time with `Z` or an offset, as epoch milliseconds; NaN for anything else. */\nexport function parseInstant(value: string): number {\n const v = value.trim();\n return INSTANT.test(v) ? Date.parse(v.replace(\" \", \"T\")) : Number.NaN;\n}\n\n/**\n * Where a form stands at `at`. Archived and draft first, then paused (staff chose it,\n * whatever the clock says), then the opening window (a time that can't be read, or has no\n * offset, counts as closed), then the cap. Only \"live\" takes\n * responses.\n */\nexport function formAvailability(form: AvailabilityInput, at: Date = new Date()): FormAvailability {\n if (form.status === \"archived\") return \"archived\";\n if (form.status === \"draft\" || form.published === false) return \"draft\";\n if (form.paused) return \"paused\";\n const t = at.getTime();\n if (form.opensAt) {\n const opens = parseInstant(form.opensAt);\n // A time that can't be read never opens the form.\n if (Number.isNaN(opens)) return \"closed\";\n if (t < opens) return \"scheduled\";\n }\n if (form.closesAt) {\n const closes = parseInstant(form.closesAt);\n if (Number.isNaN(closes) || t >= closes) return \"closed\";\n }\n if (isFull(form)) return \"full\";\n return \"live\";\n}\n\n/** Whether the form takes responses at `at`. */\nexport function takesResponses(form: AvailabilityInput, at: Date = new Date()): boolean {\n return formAvailability(form, at) === \"live\";\n}\n","// A form page's status chip and its four child navigation items with their counts. Pure.\nimport type { FormDefinition } from \"@marktiderman/genesis-forms\";\nimport type { FormAvailability } from \"./availability\";\nimport type { SubNavItem } from \"@marktiderman/genesis-ui/layout\";\nimport type { ChipTone } from \"@marktiderman/genesis-ui/resource/rules\";\n\n/**\n * A form's status chip: \"Live · version 3\", \"Draft\", \"Paused · version 3\"… `availability`\n * is formAvailability's answer; `version` the live version, when there is one.\n */\nexport function formStatusChip(\n availability: FormAvailability,\n version?: number | null,\n): { label: string; tone: ChipTone } {\n const v = version ? ` · version ${version}` : \"\";\n switch (availability) {\n case \"live\":\n return { label: `Live${v}`, tone: \"success\" };\n case \"draft\":\n return { label: \"Draft\", tone: \"muted\" };\n case \"paused\":\n return { label: `Paused${v}`, tone: \"warning\" };\n case \"scheduled\":\n return { label: `Scheduled${v}`, tone: \"info\" };\n case \"closed\":\n return { label: `Closed${v}`, tone: \"muted\" };\n case \"full\":\n return { label: `Full${v}`, tone: \"warning\" };\n case \"archived\":\n return { label: \"Archived\", tone: \"muted\" };\n }\n}\n\n/** The form page's four places, in order. */\nexport type FormTab = \"questions\" | \"logic\" | \"responses\" | \"settings\";\n\n/** One of a form page's child navigation items: genesis-ui's `SubNavItem`, plus its place. */\nexport type FormNavItem = SubNavItem & { id: FormTab; badge?: number };\n\n/** How many questions a definition asks, and how many rules plus endings it has. */\nexport function formCounts(definition: FormDefinition | null | undefined): {\n questions: number;\n logic: number;\n} {\n if (!definition) return { questions: 0, logic: 0 };\n return {\n questions: definition.blocks.filter((b) => b.kind === \"field\").length,\n logic: (definition.logic?.length ?? 0) + (definition.endings?.length ?? 0),\n };\n}\n\n/**\n * The form page's child navigation items (Questions, Logic and endings, Responses,\n * Settings) with their counts as badges, for the app shell's sub-navigation:\n * `useAppShellSubNav(formNavItems(\"/forms/f1\", counts))`. `at` is the form page's path\n * (each place is `?tab=<id>` on it, Questions the path itself, which the shell's most\n * specific match keeps from lighting up on the others) or a function giving each place's\n * address. A count left out (or null) shows no badge.\n */\nexport function formNavItems(\n at: string | ((tab: FormTab) => string),\n counts: { questions?: number | null; logic?: number | null; responses?: number | null } = {},\n /** Each place's icon, for the rail and the phone's bottom bar (`FORM_NAV_ICONS`). */\n icons?: Partial<Record<FormTab, SubNavItem[\"icon\"]>>,\n): FormNavItem[] {\n const to = typeof at === \"function\" ? at : (tab: FormTab) => (tab === \"questions\" ? at : `${at}?tab=${tab}`);\n const item = (id: FormTab, label: string, badge?: number | null): FormNavItem => {\n const icon = icons?.[id];\n return {\n id,\n to: to(id),\n label,\n ...(badge == null ? {} : { badge }),\n ...(icon ? { icon } : {}),\n };\n };\n return [\n item(\"questions\", \"Questions\", counts.questions),\n item(\"logic\", \"Logic and endings\", counts.logic),\n item(\"responses\", \"Responses\", counts.responses),\n item(\"settings\", \"Settings\"),\n ];\n}\n","// The pure half of the resource workspace moved to genesis-ui\n// (`@marktiderman/genesis-ui/resource/rules`). These names stay here, deprecated, so\n// existing imports keep working; the form's own words (an empty form says \"Add a\n// question\") are passed from here.\nimport {\n SAVE_STATE_LABEL as UI_SAVE_STATE_LABEL,\n dayLabel as uiDayLabel,\n embedSnippet as uiEmbedSnippet,\n prefilledUrl as uiPrefilledUrl,\n readinessChip as uiReadinessChip,\n readinessOf as uiReadinessOf,\n type ChipTone as UiChipTone,\n type PrefillChoice as UiPrefillChoice,\n type Readiness as UiReadiness,\n type ReadinessFinding,\n type ReadinessLabels,\n type ReadinessOptions,\n type SaveState as UiSaveState,\n} from \"@marktiderman/genesis-ui/resource/rules\";\n\n/** A form's readiness rule: the builder's `no-questions` finding means \"nothing to publish yet\". */\nexport const FORM_READINESS_OPTIONS = { emptyCode: \"no-questions\" } as const satisfies ReadinessOptions;\n\n/** A form's readiness words: an empty form says \"Add a question\". */\nexport const FORM_READINESS_LABELS = { empty: \"Add a question\" } as const satisfies ReadinessLabels;\n\n/** @deprecated import from @marktiderman/genesis-ui */\nexport type SaveState = UiSaveState;\n/** @deprecated import from @marktiderman/genesis-ui */\nexport type ChipTone = UiChipTone;\n/** @deprecated import from @marktiderman/genesis-ui */\nexport type Readiness = UiReadiness;\n/** @deprecated import from @marktiderman/genesis-ui */\nexport type PrefillChoice = UiPrefillChoice;\n\n/** @deprecated import from @marktiderman/genesis-ui */\nexport const SAVE_STATE_LABEL: Record<SaveState, string> = UI_SAVE_STATE_LABEL;\n/** @deprecated import from @marktiderman/genesis-ui */\nexport const dayLabel: typeof uiDayLabel = uiDayLabel;\n/** @deprecated import from @marktiderman/genesis-ui */\nexport const prefilledUrl: typeof uiPrefilledUrl = uiPrefilledUrl;\n/** @deprecated import from @marktiderman/genesis-ui */\nexport const embedSnippet: typeof uiEmbedSnippet = uiEmbedSnippet;\n\n/**\n * Readiness from a form builder's findings (`no-questions` is \"empty\").\n * @deprecated import from @marktiderman/genesis-ui: `readinessOf(findings, { ...FORM_READINESS_OPTIONS, pending })`\n */\nexport function readinessOf(\n findings: readonly ReadinessFinding[],\n options: ReadinessOptions = {},\n): Readiness {\n return uiReadinessOf(findings, { ...FORM_READINESS_OPTIONS, ...options });\n}\n\n/**\n * The readiness chip's label and tone, in a form's words.\n * @deprecated import from @marktiderman/genesis-ui: `readinessChip(readiness, FORM_READINESS_LABELS)`\n */\nexport function readinessChip(\n readiness: Readiness,\n labels: ReadinessLabels = {},\n): { label: string; tone: ChipTone } {\n return uiReadinessChip(readiness, { ...FORM_READINESS_LABELS, ...labels });\n}\n","// A form's public link and a duplicate's name: what a forms list needs to make a form or\n// copy one, without storage. Pure. Moved up from the host app's src/lib/feedback/admin.ts.\n\n/**\n * \"How was class?\" → \"how-was-class\": the public link's last part (lowercase words and\n * hyphens, at most 60). `fallback` is used when the title has no letters or numbers.\n */\nexport function slugFromTitle(title: string, fallback = \"form\"): string {\n const slug = title\n .toLowerCase()\n .normalize(\"NFKD\")\n .replace(/[^a-z0-9]+/g, \"-\")\n .replace(/^-+|-+$/g, \"\")\n .slice(0, 60)\n .replace(/-+$/g, \"\");\n return slug || fallback;\n}\n\n/** A form link: lowercase letters and numbers, in words joined by single hyphens. */\nexport const SLUG_PATTERN = /^[a-z0-9]+(-[a-z0-9]+)*$/;\n\n/** Why a form link can't be used, or nothing when it fits SLUG_PATTERN. */\nexport function validateSlug(slug: string): string | undefined {\n return SLUG_PATTERN.test(slug)\n ? undefined\n : \"Use lowercase letters, numbers and hyphens for the link, like how-was-class.\";\n}\n\n/** A duplicate's name: \"Copy of …\", within the 120 characters a form name may have. */\nexport function copyTitle(title: string): string {\n return `Copy of ${title}`.slice(0, 120);\n}\n\n/** The first of `slug`, `slug-2`, `slug-3`… that isn't in `taken`, within 60 characters. */\nexport function freeSlug(slug: string, taken: ReadonlySet<string>): string {\n if (!taken.has(slug)) return slug;\n for (let n = 2; ; n++) {\n const suffix = `-${n}`;\n const candidate = `${slug.slice(0, 60 - suffix.length).replace(/-+$/, \"\")}${suffix}`;\n if (!taken.has(candidate)) return candidate;\n }\n}\n","// What a respondent's thank-you page offers. Pure: safe in the browser bundle and in\n// tests. Moved up from the host app's src/lib/feedback/respondent.ts.\n\n/**\n * Whether the thank-you page offers \"Send another response\" (on unless `submitAnother`\n * is false). Never on a form that takes one response per person: a second response\n * would be refused. Anonymous forms don't know who answered, so one per person doesn't apply.\n */\nexport function offersSubmitAnother(form: {\n submitAnother?: boolean | null | undefined;\n onePerPerson?: boolean | null | undefined;\n anonymous?: boolean | null | undefined;\n}): boolean {\n const onePerPerson = form.onePerPerson === true && !form.anonymous;\n return form.submitAnother !== false && !onePerPerson;\n}\n"]}