@spillway-cms/blocks 0.0.0-stage → 0.1.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (100) hide show
  1. package/LICENSE +21 -0
  2. package/dist/ask.d.ts +39 -0
  3. package/dist/ask.js +96 -0
  4. package/dist/ask.js.map +1 -0
  5. package/dist/calendar.d.ts +42 -0
  6. package/dist/calendar.js +96 -0
  7. package/dist/calendar.js.map +1 -0
  8. package/dist/collection.d.ts +89 -0
  9. package/dist/collection.js +304 -0
  10. package/dist/collection.js.map +1 -0
  11. package/dist/config.d.ts +208 -0
  12. package/dist/config.js +563 -0
  13. package/dist/config.js.map +1 -0
  14. package/dist/css.d.ts +1 -0
  15. package/dist/css.js +600 -0
  16. package/dist/css.js.map +1 -0
  17. package/dist/docs-feedback.d.ts +34 -0
  18. package/dist/docs-feedback.js +57 -0
  19. package/dist/docs-feedback.js.map +1 -0
  20. package/dist/examples.d.ts +12 -0
  21. package/dist/examples.js +80 -0
  22. package/dist/examples.js.map +1 -0
  23. package/dist/experiment.d.ts +18 -0
  24. package/dist/experiment.js +20 -0
  25. package/dist/experiment.js.map +1 -0
  26. package/dist/form.d.ts +40 -0
  27. package/dist/form.js +252 -0
  28. package/dist/form.js.map +1 -0
  29. package/dist/gallery.d.ts +36 -0
  30. package/dist/gallery.js +114 -0
  31. package/dist/gallery.js.map +1 -0
  32. package/dist/image.d.ts +41 -0
  33. package/dist/image.js +39 -0
  34. package/dist/image.js.map +1 -0
  35. package/dist/index.d.ts +49 -0
  36. package/dist/index.js +28 -0
  37. package/dist/index.js.map +1 -0
  38. package/dist/layouts.d.ts +8 -0
  39. package/dist/layouts.js +81 -0
  40. package/dist/layouts.js.map +1 -0
  41. package/dist/markdown.d.ts +32 -0
  42. package/dist/markdown.js +283 -0
  43. package/dist/markdown.js.map +1 -0
  44. package/dist/marketing.d.ts +53 -0
  45. package/dist/marketing.js +184 -0
  46. package/dist/marketing.js.map +1 -0
  47. package/dist/menu.d.ts +43 -0
  48. package/dist/menu.js +75 -0
  49. package/dist/menu.js.map +1 -0
  50. package/dist/meta.d.ts +14 -0
  51. package/dist/meta.js +183 -0
  52. package/dist/meta.js.map +1 -0
  53. package/dist/module-block.d.ts +29 -0
  54. package/dist/module-block.js +53 -0
  55. package/dist/module-block.js.map +1 -0
  56. package/dist/personalize.d.ts +18 -0
  57. package/dist/personalize.js +32 -0
  58. package/dist/personalize.js.map +1 -0
  59. package/dist/registry-browse.d.ts +31 -0
  60. package/dist/registry-browse.js +97 -0
  61. package/dist/registry-browse.js.map +1 -0
  62. package/dist/registry-gallery.d.ts +22 -0
  63. package/dist/registry-gallery.js +73 -0
  64. package/dist/registry-gallery.js.map +1 -0
  65. package/dist/registry-org.d.ts +22 -0
  66. package/dist/registry-org.js +44 -0
  67. package/dist/registry-org.js.map +1 -0
  68. package/dist/registry-package.d.ts +27 -0
  69. package/dist/registry-package.js +145 -0
  70. package/dist/registry-package.js.map +1 -0
  71. package/dist/registry-publisher.d.ts +20 -0
  72. package/dist/registry-publisher.js +46 -0
  73. package/dist/registry-publisher.js.map +1 -0
  74. package/dist/registry-shared.d.ts +29 -0
  75. package/dist/registry-shared.js +122 -0
  76. package/dist/registry-shared.js.map +1 -0
  77. package/dist/registry-stats.d.ts +15 -0
  78. package/dist/registry-stats.js +42 -0
  79. package/dist/registry-stats.js.map +1 -0
  80. package/dist/registry-types.d.ts +218 -0
  81. package/dist/registry-types.js +29 -0
  82. package/dist/registry-types.js.map +1 -0
  83. package/dist/sanitize.d.ts +37 -0
  84. package/dist/sanitize.js +293 -0
  85. package/dist/sanitize.js.map +1 -0
  86. package/dist/search.d.ts +25 -0
  87. package/dist/search.js +77 -0
  88. package/dist/search.js.map +1 -0
  89. package/dist/shared.d.ts +27 -0
  90. package/dist/shared.js +59 -0
  91. package/dist/shared.js.map +1 -0
  92. package/dist/status-board.d.ts +49 -0
  93. package/dist/status-board.js +81 -0
  94. package/dist/status-board.js.map +1 -0
  95. package/dist/styles.css +1245 -0
  96. package/dist/styles.d.ts +37 -0
  97. package/dist/styles.js +242 -0
  98. package/dist/styles.js.map +1 -0
  99. package/package.json +47 -3
  100. package/README.md +0 -3
@@ -0,0 +1,57 @@
1
+ import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
2
+ /** Runs once per page: when the browser has fetch, posts the answer in place and shows the thanks line without leaving the page. */
3
+ export const DOCS_FEEDBACK_SCRIPT = `(function(){var fs=document.querySelectorAll('form[data-sw-docs-feedback]:not([data-sw-bound])');
4
+ for(var i=0;i<fs.length;i++)bind(fs[i]);
5
+ function bind(f){f.setAttribute('data-sw-bound','1');var t=f.querySelector('input[name="_t"]');if(t)t.value=String(Date.now());
6
+ var p=f.querySelector('input[name="_page"]');if(p)p.value=location.href;var pg=f.querySelector('input[name="page"]');if(pg&&!pg.value)pg.value=location.pathname;
7
+ var done=function(ok){var s=f.querySelector('[data-sw-docs-status]');if(!s)return;s.hidden=false;s.textContent=ok?f.getAttribute('data-sw-thanks'):'Something went wrong. Please try again.';var b=f.querySelector('.sw-docs-feedback__body');if(b&&ok)b.hidden=true};
8
+ var clicked=null;var btns=f.querySelectorAll('button[name="helpful"]');for(var k=0;k<btns.length;k++)btns[k].addEventListener('click',function(e){clicked=e.currentTarget});
9
+ f.addEventListener('submit',function(ev){if(!window.fetch)return;ev.preventDefault();var o={};var els=f.querySelectorAll('input,textarea');for(var j=0;j<els.length;j++){if(els[j].name)o[els[j].name]=els[j].value}if(clicked)o.helpful=clicked.value;
10
+ for(var m=0;m<btns.length;m++)btns[m].disabled=true;
11
+ fetch(f.getAttribute('action'),{method:'POST',credentials:'same-origin',headers:{'Content-Type':'application/json','Accept':'application/json'},body:JSON.stringify(o)})
12
+ .then(function(r){done(r.ok);if(!r.ok)for(var m=0;m<btns.length;m++)btns[m].disabled=false}).catch(function(){HTMLFormElement.prototype.submit.call(f)})})}})();`;
13
+ export const docsFeedbackComponent = {
14
+ label: 'Docs feedback',
15
+ fields: {
16
+ formKey: { type: 'text', label: 'Form key', placeholder: 'docs_feedback' },
17
+ question: { type: 'text', label: 'Question' },
18
+ yesLabel: { type: 'text', label: 'Yes button' },
19
+ noLabel: { type: 'text', label: 'No button' },
20
+ commentLabel: { type: 'text', label: 'Comment label' },
21
+ thanksText: { type: 'text', label: 'Thanks text' },
22
+ version: { type: 'text', label: 'Documented version (recorded with the answer)' },
23
+ },
24
+ defaultProps: {
25
+ formKey: 'docs_feedback',
26
+ question: 'Was this page helpful?',
27
+ yesLabel: 'Yes',
28
+ noLabel: 'No',
29
+ commentLabel: 'Tell us more (optional)',
30
+ thanksText: 'Thanks for the feedback.',
31
+ version: '',
32
+ },
33
+ render: ({ formKey, question, yesLabel, noLabel, commentLabel, thanksText, version, resolved, nonce }) => {
34
+ const key = (formKey || 'docs_feedback').trim();
35
+ if (!resolved) {
36
+ return (_jsx("section", { className: "sw-block sw-docs-feedback", children: _jsx("div", { className: "sw-container sw-container--narrow", children: _jsxs("div", { className: "sw-docs-feedback__placeholder", role: "note", children: ["Docs feedback: posts to the form ", _jsx("code", { children: key }), " (created by the docs kit)"] }) }) }));
37
+ }
38
+ const id = `docs-feedback-${key}`;
39
+ return (_jsx("section", { className: "sw-block sw-docs-feedback", "aria-labelledby": `${id}-q`, children: _jsxs("div", { className: "sw-container sw-container--narrow", children: [_jsxs("form", { id: id, className: "sw-docs-feedback__form", method: "post", action: `/api/forms/${encodeURIComponent(key)}/submit`, "data-sw-docs-feedback": key, "data-sw-thanks": thanksText, children: [_jsx("p", { className: "sw-docs-feedback__status", "data-sw-docs-status": "", role: "status", "aria-live": "polite", hidden: !resolved.sent && !resolved.error, children: resolved.sent ? thanksText : resolved.error ? 'Something went wrong. Please try again.' : '' }), _jsxs("div", { className: "sw-docs-feedback__body", hidden: resolved.sent, children: [_jsx("p", { className: "sw-docs-feedback__question", id: `${id}-q`, children: question }), _jsxs("label", { className: "sw-docs-feedback__comment", htmlFor: `${id}-comment`, children: [_jsx("span", { children: commentLabel }), _jsx("textarea", { id: `${id}-comment`, name: "comment", rows: 2, maxLength: 2000 })] }), _jsx("input", { type: "hidden", name: "page", value: resolved.path }), _jsx("input", { type: "hidden", name: "version", value: version }), _jsx("input", { type: "hidden", name: "_page", value: resolved.path }), _jsx("input", { type: "hidden", name: "_t", value: String(Date.now()) }), _jsxs("div", { className: "sw-form__hp", "aria-hidden": "true", children: [_jsx("label", { htmlFor: `${id}-_hp`, children: "Leave this field empty" }), _jsx("input", { id: `${id}-_hp`, type: "text", name: "_hp", tabIndex: -1, autoComplete: "off", defaultValue: "" })] }), _jsxs("div", { className: "sw-docs-feedback__buttons", children: [_jsx("button", { type: "submit", className: "sw-button sw-button--secondary", name: "helpful", value: "yes", children: yesLabel }), _jsx("button", { type: "submit", className: "sw-button sw-button--secondary", name: "helpful", value: "no", children: noLabel })] })] })] }), _jsx("script", { nonce: nonce, dangerouslySetInnerHTML: { __html: DOCS_FEEDBACK_SCRIPT } })] }) }));
40
+ },
41
+ };
42
+ export const docsFeedbackCss = `/* ---------- Docs feedback ---------- */
43
+
44
+ .sw-docs-feedback { padding: var(--sw-space-3) 0 var(--sw-space-4); }
45
+ .sw-docs-feedback__form { padding: var(--sw-space-3); border: 1px solid var(--sw-color-border); border-radius: var(--sw-radius, 8px); background: var(--sw-color-surface); }
46
+ .sw-docs-feedback__question { margin: 0 0 var(--sw-space-2); font-weight: 600; }
47
+ .sw-docs-feedback__comment { display: grid; gap: 0.35rem; margin-bottom: var(--sw-space-2); font-size: 0.9rem; color: var(--sw-color-muted); }
48
+ .sw-docs-feedback__comment textarea { width: 100%; padding: 0.55rem 0.7rem; font: inherit; color: var(--sw-color-text); background: var(--sw-color-bg); border: 1px solid var(--sw-color-border); border-radius: var(--sw-radius, 8px); resize: vertical; }
49
+ .sw-docs-feedback__comment textarea:focus-visible { outline: none; border-color: var(--sw-color-primary); box-shadow: var(--sw-focus-ring); }
50
+ .sw-docs-feedback__buttons { display: flex; gap: var(--sw-space-1); flex-wrap: wrap; }
51
+ .sw-docs-feedback__buttons button { font: inherit; cursor: pointer; }
52
+ .sw-docs-feedback__buttons button[disabled] { opacity: 0.6; cursor: progress; }
53
+ .sw-docs-feedback__status { margin: 0; font-weight: 500; }
54
+ .sw-docs-feedback__status[hidden], .sw-docs-feedback__body[hidden] { display: none; }
55
+ .sw-docs-feedback__placeholder { padding: var(--sw-space-2); border: 1px dashed var(--sw-color-border); border-radius: var(--sw-radius, 8px); color: var(--sw-color-muted); font-size: 0.9rem; text-align: center; }
56
+ `;
57
+ //# sourceMappingURL=docs-feedback.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"docs-feedback.js","sourceRoot":"","sources":["../src/docs-feedback.tsx"],"names":[],"mappings":";AA4BA,oIAAoI;AACpI,MAAM,CAAC,MAAM,oBAAoB,GAAG;;;;;;;;;iKAS6H,CAAC;AAElK,MAAM,CAAC,MAAM,qBAAqB,GAAuC;IACvE,KAAK,EAAE,eAAe;IACtB,MAAM,EAAE;QACN,OAAO,EAAE,EAAE,IAAI,EAAE,MAAM,EAAE,KAAK,EAAE,UAAU,EAAE,WAAW,EAAE,eAAe,EAAE;QAC1E,QAAQ,EAAE,EAAE,IAAI,EAAE,MAAM,EAAE,KAAK,EAAE,UAAU,EAAE;QAC7C,QAAQ,EAAE,EAAE,IAAI,EAAE,MAAM,EAAE,KAAK,EAAE,YAAY,EAAE;QAC/C,OAAO,EAAE,EAAE,IAAI,EAAE,MAAM,EAAE,KAAK,EAAE,WAAW,EAAE;QAC7C,YAAY,EAAE,EAAE,IAAI,EAAE,MAAM,EAAE,KAAK,EAAE,eAAe,EAAE;QACtD,UAAU,EAAE,EAAE,IAAI,EAAE,MAAM,EAAE,KAAK,EAAE,aAAa,EAAE;QAClD,OAAO,EAAE,EAAE,IAAI,EAAE,MAAM,EAAE,KAAK,EAAE,+CAA+C,EAAE;KAClF;IACD,YAAY,EAAE;QACZ,OAAO,EAAE,eAAe;QACxB,QAAQ,EAAE,wBAAwB;QAClC,QAAQ,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QAAQ,EAAC,SAAS,EAAC,gCAAgC,EAAC,IAAI,EAAC,SAAS,EAAC,KAAK,EAAC,IAAI,YACvF,OAAO,GACD,IACL,IACF,IACD,EACP,iBAAQ,KAAK,EAAE,KAAK,EAAE,uBAAuB,EAAE,EAAE,MAAM,EAAE,oBAAoB,EAAE,GAAI,IAC/E,GACE,CACX,CAAC;IACJ,CAAC;CACF,CAAC;AAEF,MAAM,CAAC,MAAM,eAAe,GAAG;;;;;;;;;;;;;;CAc9B,CAAC"}
@@ -0,0 +1,12 @@
1
+ /**
2
+ * Examples for the Components screen (docs/dev/component-library.md): named props that show each block in one typical use.
3
+ * Every example is rendered by the server renderer in the site's brand, so they double as a visual test of every block.
4
+ * Images point at the server's placeholder (`/_placeholder/<width>x<height>.svg`), which every instance serves.
5
+ * Slot props hold child blocks without ids; the renderer gives them ids.
6
+ */
7
+ export interface BlockExample {
8
+ key: string;
9
+ label: string;
10
+ props: Record<string, unknown>;
11
+ }
12
+ export declare const blockExamples: Record<string, BlockExample[]>;
@@ -0,0 +1,80 @@
1
+ const img = (w, h) => `/_placeholder/${w}x${h}.svg`;
2
+ const child = (type, props) => ({ type, props });
3
+ export const blockExamples = {
4
+ Hero: [
5
+ { key: 'centered', label: 'Centered, two buttons', props: { eyebrow: 'Fall admissions', title: 'Find the program that fits your life', subtitle: 'Over 80 degrees and certificates, on campus and online, with advisors who know your name.', primaryLabel: 'Explore programs', primaryHref: '#', secondaryLabel: 'Visit campus', secondaryHref: '#', align: 'center', size: 'default' } },
6
+ { key: 'image', label: 'Large, with a background image', props: { eyebrow: '', title: 'Clean water for every neighborhood', subtitle: 'Your gift funds repairs on the oldest mains first.', primaryLabel: 'Donate', primaryHref: '#', secondaryLabel: '', secondaryHref: '', backgroundImage: img(1600, 900), align: 'left', size: 'large' } },
7
+ { key: 'minimal', label: 'Left aligned, one button', props: { eyebrow: '', title: 'Report a pothole', subtitle: 'Most reports are fixed within two working days.', primaryLabel: 'Start a report', primaryHref: '#', secondaryLabel: '', secondaryHref: '', align: 'left', size: 'default' } },
8
+ ],
9
+ Heading: [
10
+ { key: 'h2', label: 'Section heading (h2)', props: { text: 'What you will learn', level: 'h2', align: 'left' } },
11
+ { key: 'h3-center', label: 'Centered h3', props: { text: 'Questions people ask', level: 'h3', align: 'center' } },
12
+ ],
13
+ Text: [
14
+ { key: 'body', label: 'Body copy with a list and a link', props: { content: '<p>Our advisors help you choose courses, plan your schedule and find funding. Book a time that suits you, online or in person.</p><ul><li>Course planning</li><li>Financial aid and scholarships</li><li>Transfer credit</li></ul><p>Read the <a href="#">advising guide</a> before your first meeting.</p>', format: 'html', size: 'normal', align: 'left' } },
15
+ { key: 'lead', label: 'Lead paragraph', props: { content: '<p>Since 1902, the library has been free and open to everyone in the county.</p>', format: 'html', size: 'lead', align: 'left' } },
16
+ ],
17
+ Image: [
18
+ { key: 'caption', label: 'With a caption', props: { src: img(1200, 800), alt: 'Students talking on the lawn in front of the library', caption: 'The main quad in early autumn.', width: 'normal', rounded: true } },
19
+ { key: 'wide', label: 'Wide, square corners', props: { src: img(1600, 600), alt: 'The river at dusk', caption: '', width: 'wide', rounded: false } },
20
+ ],
21
+ Gallery: [
22
+ {
23
+ key: 'three',
24
+ label: 'Three columns, square',
25
+ props: { images: [1, 2, 3, 4, 5, 6].map((n) => ({ src: img(800, 800), alt: `Photo ${n} from the spring open house`, caption: n === 1 ? 'Welcome tent' : '' })), columns: 3, shape: 'square', lightbox: true },
26
+ },
27
+ ],
28
+ Columns: [
29
+ { key: 'image-text', label: 'Image and text, wide right', props: { ratio: 'wide-right', gap: 'normal', valign: 'center', columns: [{ content: [child('Image', { src: img(800, 600), alt: 'A volunteer planting a tree', caption: '', width: 'normal', rounded: true })] }, { content: [child('Heading', { text: 'Plant a tree this spring', level: 'h3', align: 'left' }), child('Text', { content: '<p>We provide the tree, the tools and a guide. You bring an afternoon.</p>', format: 'html', size: 'normal', align: 'left' }), child('Button', { label: 'Sign up', href: '#', align: 'left' })] }] } },
30
+ { key: 'three', label: 'Three equal columns', props: { ratio: 'equal', gap: 'normal', valign: 'top', columns: ['Plan', 'Apply', 'Enroll'].map((t) => ({ content: [child('Heading', { text: t, level: 'h3', align: 'left' }), child('Text', { content: `<p>What happens when you ${t.toLowerCase()}, in two short sentences.</p>`, format: 'html', size: 'normal', align: 'left' })] })) } },
31
+ ],
32
+ Section: [
33
+ { key: 'surface', label: 'Surface band with heading, text and buttons', props: { background: 'surface', width: 'normal', content: [child('Heading', { text: 'Visit us', level: 'h2', align: 'left' }), child('Text', { content: '<p>Open Monday to Saturday, 9 to 6. Free parking behind the building.</p>', format: 'html', size: 'normal', align: 'left' }), child('Buttons', { align: 'left', buttons: [{ label: 'Get directions', href: '#', emphasis: 'primary', newTab: false }, { label: 'Opening hours', href: '#', emphasis: 'secondary', newTab: false }] })] } },
34
+ { key: 'dark', label: 'Dark band, narrow and centered', props: { background: 'dark', width: 'narrow', content: [child('Heading', { text: 'Stay in the loop', level: 'h2', align: 'center' }), child('Text', { content: '<p>One email a month with news and events. No spam.</p>', format: 'html', size: 'normal', align: 'center' })] } },
35
+ ],
36
+ CallToAction: [{ key: 'default', label: 'Default', props: { title: 'Ready to apply?', text: 'Applications for spring close on January 15. It takes about twenty minutes.', buttonLabel: 'Start your application', buttonHref: '#' } }],
37
+ Cards: [
38
+ { key: 'three', label: 'Three cards with images and links', props: { columns: 3, titleLevel: 'h3', cards: [{ title: 'Undergraduate', text: 'Bachelor degrees in 40 subjects.', href: '#', imageUrl: img(800, 500) }, { title: 'Graduate', text: 'Masters and doctoral programs.', href: '#', imageUrl: img(800, 500) }, { title: 'Continuing education', text: 'Evening and online courses.', href: '#', imageUrl: img(800, 500) }] } },
39
+ { key: 'text-only', label: 'Four text cards', props: { columns: 4, titleLevel: 'h3', cards: ['Pay a bill', 'Report an issue', 'Find a park', 'Apply for a permit'].map((t) => ({ title: t, text: 'One line about the service.', href: '#', imageUrl: '' })) } },
40
+ ],
41
+ Faq: [
42
+ { key: 'admissions', label: 'Admissions questions', props: { title: 'Frequently asked questions', openFirst: true, structuredData: true, items: [{ question: 'How do I apply?', answer: 'Start an application online. It takes about 20 minutes.' }, { question: 'When are the deadlines?', answer: 'March 1 for fall and October 1 for spring.' }, { question: 'Is there an application fee?', answer: 'No. Applying is free.' }] } },
43
+ ],
44
+ Testimonials: [
45
+ { key: 'three', label: 'Three quotes', props: { title: 'What students say', columns: 3, items: [{ quote: 'The team answered every question within a day.', name: 'Maya Chen', role: 'Class of 2025', imageUrl: img(96, 96) }, { quote: 'I found my program in one afternoon.', name: 'Luis Ortega', role: 'Transfer student', imageUrl: img(96, 96) }, { quote: 'Clear, friendly and fast.', name: 'Priya Nair', role: 'Parent', imageUrl: '' }] } },
46
+ { key: 'one', label: 'One large quote', props: { title: '', columns: 1, items: [{ quote: 'We moved forty sites in a month and our editors never noticed.', name: 'Jordan Lee', role: 'Web director, Riverbend University', imageUrl: '' }] } },
47
+ ],
48
+ Stats: [
49
+ { key: 'three', label: 'Three figures, centered', props: { title: '', align: 'center', items: [{ value: '94%', label: 'of graduates employed within six months' }, { value: '40', label: 'undergraduate majors' }, { value: '14:1', label: 'student to faculty ratio' }] } },
50
+ ],
51
+ LogoStrip: [
52
+ { key: 'partners', label: 'Partners, gray until hovered', props: { title: 'Our partners', grayscale: true, logos: ['Northwind', 'Contoso', 'Fabrikam', 'Tailspin'].map((n) => ({ imageUrl: img(320, 96), name: n, href: '' })) } },
53
+ ],
54
+ Spacer: [{ key: 'm', label: 'Medium', props: { size: 'm' } }],
55
+ Divider: [{ key: 'normal', label: 'Full width', props: { width: 'normal' } }, { key: 'narrow', label: 'Narrow', props: { width: 'narrow' } }],
56
+ Search: [
57
+ { key: 'normal', label: 'Inline', props: { label: 'Search this site', showLabel: false, placeholder: 'Search', buttonLabel: 'Search', size: 'normal', align: 'left' } },
58
+ { key: 'large', label: 'Large and centered, with a label', props: { label: 'How can we help?', showLabel: true, placeholder: 'Try “parking permit”', buttonLabel: 'Search', size: 'large', align: 'center' } },
59
+ ],
60
+ Ask: [
61
+ { key: 'help', label: 'With suggested questions', props: { heading: 'Have a question?', label: 'Ask a question', placeholder: 'For example: when is the application deadline?', buttonLabel: 'Ask', align: 'left', questions: [{ question: 'When is the application deadline?' }, { question: 'How much is tuition?' }, { question: 'Where do I park on campus?' }] } },
62
+ { key: 'center', label: 'Centered, no suggestions', props: { heading: 'How can we help?', label: 'Ask a question', placeholder: 'Ask anything about the program', buttonLabel: 'Ask', align: 'center', questions: [] } },
63
+ ],
64
+ Menu: [
65
+ { key: 'sidebar', label: 'A section menu in a sidebar, the current page marked', props: { source: 'menu', menuKey: 'main', show: 'branch', depth: 2, heading: '', layout: 'vertical', menuLabel: 'Main navigation', branch: { label: 'Admissions', href: '#' }, items: [{ label: 'Apply', href: '#', current: true, trail: true }, { label: 'Visit campus', href: '#', children: [{ label: 'Tours', href: '#' }, { label: 'Open days', href: '#' }] }, { label: 'Tuition and aid', href: '#' }] } },
66
+ { key: 'row', label: 'Links in a row', props: { source: 'menu', menuKey: 'footer', show: 'all', depth: 1, heading: 'Quick links', layout: 'horizontal', menuLabel: 'Footer', items: [{ label: 'Pay a bill', href: '#' }, { label: 'Report an issue', href: '#' }, { label: 'Contact us', href: '#' }] } },
67
+ ],
68
+ Embed: [{ key: 'map', label: 'An embedded frame with a caption', props: { html: '<iframe src="https://www.openstreetmap.org/export/embed.html?bbox=-0.1,51.5,-0.08,51.51" title="Map of the area" width="600" height="300"></iframe>', caption: 'Map data © OpenStreetMap contributors.' } }],
69
+ Button: [{ key: 'default', label: 'One button', props: { label: 'Download the brochure', href: '#', align: 'left' } }],
70
+ Buttons: [
71
+ { key: 'pair', label: 'Primary and secondary', props: { align: 'left', buttons: [{ label: 'Book a tour', href: '#', emphasis: 'primary', newTab: false }, { label: 'Ask a question', href: '#', emphasis: 'secondary', newTab: false }] } },
72
+ { key: 'center', label: 'Three, centered', props: { align: 'center', buttons: [{ label: 'Donate', href: '#', emphasis: 'primary', newTab: false }, { label: 'Volunteer', href: '#', emphasis: 'secondary', newTab: false }, { label: 'Partner with us', href: '#', emphasis: 'secondary', newTab: false }] } },
73
+ ],
74
+ Form: [{ key: 'default', label: 'A form by its key', props: { formKey: 'contact', title: 'Contact us', intro: 'We answer within one working day.', submitLabel: 'Send' } }],
75
+ Collection: [{ key: 'cards', label: 'Cards (pick a collection)', props: { collectionId: '', display: 'cards', columns: 3, emptyText: 'Choose a collection to list its items here.' } }],
76
+ Calendar: [{ key: 'month', label: 'Month view (pick a collection)', props: { collectionId: '', view: 'month', monthsAhead: 1 } }],
77
+ DocsFeedback: [{ key: 'default', label: 'Default', props: {} }],
78
+ StatusBoard: [{ key: 'default', label: 'Default', props: { title: 'Status', instances: [], showUptime: true } }],
79
+ };
80
+ //# sourceMappingURL=examples.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"examples.js","sourceRoot":"","sources":["../src/examples.ts"],"names":[],"mappings":"AAYA,MAAM,GAAG,GAAG,CAAC,CAAS,EAAE,CAAS,EAAE,EAAE,CAAC,iBAAiB,CAAC,IAAI,CAAC,MAAM,CAAC;AACpE,MAAM,KAAK,GAAG,CAAC,IAAY,EAAE,KAA8B,EAAE,EAAE,CAAC,CAAC,EAAE,IAAI,EAAE,KAAK,EAAE,CAAC,CAAC;AAElF,MAAM,CAAC,MAAM,aAAa,GAAmC;IAC3D,IAAI,EAAE;QACJ,EAAE,GAAG,EAAE,UAAU,EAAE,KAAK,EAAE,uBAAuB,EAAE,KAAK,EAAE,EAAE,OAAO,EAAE,iBAAiB,EAAE,KAAK,EAAE,sCAAsC,EAAE,QAAQ,EAAE,2FAA2F,EAAE,YAAY,EAAE,kBAAkB,EAAE,WAAW,EAAE,GAAG,EAAE,cAAc,EAAE,cAAc,EAAE,aAAa,EAAE,GAAG,EAAE,KAAK,EAAE,QAAQ,EAAE,IAAI,EAAE,SAAS,EAAE,EAAE;QAC1X,EAAE,GAAG,EAAE,OAAO,EAAE,KAAK,EAAE,gCAAgC,EAAE,KAAK,EAAE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,KAAK,EAAE,mCAAmC,EAAE,WAAW,EAAE,MAAM,EAAE,EAAE,CAAC;IAC3K,UAAU,EAAE,CAAC,EAAE,GAAG,EAAE,OAAO,EAAE,KAAK,EAAE,2BAA2B,EAAE,KAAK,EAAE,EAAE,YAAY,EAAE,EAAE,EAAE,OAAO,EAAE,OAAO,EAAE,OAAO,EAAE,CAAC,EAAE,SAAS,EAAE,6CAA6C,EAAE,EAAE,CAAC;IACvL,QAAQ,EAAE,CAAC,EAAE,GAAG,EAAE,OAAO,EAAE,KAAK,EAAE,gCAAgC,EAAE,KAAK,EAAE,EAAE,YAAY,EAAE,EAAE,EAAE,IAAI,EAAE,OAAO,EAAE,WAAW,EAAE,CAAC,EAAE,EAAE,CAAC;IACjI,YAAY,EAAE,CAAC,EAAE,GAAG,EAAE,SAAS,EAAE,KAAK,EAAE,SAAS,EAAE,KAAK,EAAE,EAAE,EAAE,CAAC;IAC/D,WAAW,EAAE,CAAC,EAAE,GAAG,EAAE,SAAS,EAAE,KAAK,EAAE,SAAS,EAAE,KAAK,EAAE,EAAE,KAAK,EAAE,QAAQ,EAAE,SAAS,EAAE,EAAE,EAAE,UAAU,EAAE,IAAI,EAAE,EAAE,CAAC;CACjH,CAAC"}
@@ -0,0 +1,18 @@
1
+ /**
2
+ * Experiment block: slots `a` (control), `b` and the optional `c`. Visitors of a running experiment
3
+ * are assigned a variant by weight (sticky in the `sw_x` cookie); every other status shows `a`.
4
+ * Cached pages render `a` inside `<div data-sw-island="…">`; the island endpoint renders the block
5
+ * with `show` set to the visitor's variant. Server-safe.
6
+ */
7
+ import type { ComponentConfig, Slot } from '@puckeditor/core';
8
+ export interface ExperimentProps {
9
+ experimentKey: string;
10
+ a: Slot;
11
+ b: Slot;
12
+ c: Slot;
13
+ /** Set by the server on cached pages: `<entityId>/<blockId>`; null renders the content inline. Never stored. */
14
+ island?: string | null;
15
+ /** Set by the island endpoint: the variant this visitor sees (a, b or c). Never stored. */
16
+ show?: string;
17
+ }
18
+ export declare const experimentComponent: ComponentConfig<ExperimentProps>;
@@ -0,0 +1,20 @@
1
+ import { jsxs as _jsxs, jsx as _jsx } from "react/jsx-runtime";
2
+ export const experimentComponent = {
3
+ label: 'Experiment',
4
+ fields: {
5
+ experimentKey: { type: 'text', label: 'Experiment key', placeholder: 'from Experiments in the admin' },
6
+ a: { type: 'slot', label: 'Variant A (control)' },
7
+ b: { type: 'slot', label: 'Variant B' },
8
+ c: { type: 'slot', label: 'Variant C (optional)' },
9
+ },
10
+ defaultProps: { experimentKey: '', a: [], b: [], c: [] },
11
+ render: ({ experimentKey, a: A, b: B, c: C, island, show, puck }) => {
12
+ if (puck?.isEditing) {
13
+ return (_jsxs("div", { className: "sw-island sw-island--editing", "data-sw-experiment": experimentKey || undefined, children: [_jsxs("div", { className: "sw-island__label", children: ["Experiment: ", experimentKey || 'none selected', " \u00B7 Variant A (control)"] }), _jsx(A, { className: "sw-island__slot" }), _jsx("div", { className: "sw-island__label", children: "Variant B" }), _jsx(B, { className: "sw-island__slot" }), _jsx("div", { className: "sw-island__label", children: "Variant C (optional)" }), _jsx(C, { className: "sw-island__slot" })] }));
14
+ }
15
+ const variant = show === 'b' ? 'b' : show === 'c' ? 'c' : 'a';
16
+ const Content = variant === 'b' ? B : variant === 'c' ? C : A;
17
+ return (_jsx("div", { className: "sw-island sw-experiment", "data-sw-island": island || undefined, "data-sw-experiment": experimentKey || undefined, "data-sw-variant": variant, children: _jsx(Content, { className: "sw-island__slot" }) }));
18
+ },
19
+ };
20
+ //# sourceMappingURL=experiment.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"experiment.js","sourceRoot":"","sources":["../src/experiment.tsx"],"names":[],"mappings":";AAmBA,MAAM,CAAC,MAAM,mBAAmB,GAAqC;IACnE,KAAK,EAAE,YAAY;IACnB,MAAM,EAAE;QACN,aAAa,EAAE,EAAE,IAAI,EAAE,MAAM,EAAE,KAAK,EAAE,gBAAgB,EAAE,WAAW,EAAE,+BAA+B,EAAE;QACtG,C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AC,CAAC,CAAC,CAAC,CAAC;QAC9D,OAAO,CACL,cAAK,SAAS,EAAC,yBAAyB,oBAAiB,MAAM,IAAI,SAAS,wBAAsB,aAAa,IAAI,SAAS,qBAAmB,OAAO,YACpJ,KAAC,OAAO,IAAC,SAAS,EAAC,iBAAiB,GAAG,GACnC,CACP,CAAC;IACJ,CAAC;CACF,CAAC"}
package/dist/form.d.ts ADDED
@@ -0,0 +1,40 @@
1
+ /**
2
+ * The Form block. Stored props are `formKey`, `title`, `intro` and `submitLabel`; the server
3
+ * resolves `form: FormDefinition` (plus `nonce` and, when the site has one, `captcha`) into the
4
+ * props before render (core registers a resolver for block type "Form"). Without a resolved form,
5
+ * the block renders a placeholder so the editor and an unpublished form still show something sensible.
6
+ *
7
+ * Server-safe: no hooks, no DOM access. Progressive enhancement comes from a tiny inline script
8
+ * (carrying the page's CSP nonce) that evaluates `visibleWhen` rules, drives the stepper (one step
9
+ * at a time, each validated on the server before moving on), intercepts submit (JSON, or multipart
10
+ * when the form takes files) and shows the outcome in place; when fetch fails it lets the browser
11
+ * submit the form normally (303 back to the page). Without JavaScript every step is visible, the
12
+ * server evaluates the same rules and the form works through that redirect.
13
+ */
14
+ import { type FormCaptchaProvider, type FormDefinition, type FormField } from '@spillway-cms/shared';
15
+ export interface FormProps {
16
+ formKey: string;
17
+ title: string;
18
+ intro: string;
19
+ submitLabel: string;
20
+ }
21
+ /** The CAPTCHA the server resolves for the block: provider, public site key and the widget script. Never the secret. */
22
+ export interface FormCaptchaProps {
23
+ provider: Exclude<FormCaptchaProvider, 'none'>;
24
+ siteKey: string;
25
+ script: string;
26
+ }
27
+ /** The props the server hands to `render`: the stored props plus the resolved definition, the CSP nonce and the CAPTCHA. */
28
+ export type FormRenderProps = FormProps & {
29
+ form?: FormDefinition;
30
+ nonce?: string;
31
+ captcha?: FormCaptchaProps;
32
+ };
33
+ /** The `accept` attribute of a file input from the field's list (extensions get their dot, MIME types pass through). */
34
+ export declare function acceptAttr(field: FormField): string | undefined;
35
+ /** An amount for people: "$25", "€10.50", "¥3,000" (Intl, falling back to "25.00 USD"). */
36
+ export declare function moneyLabel(amount: number, currency: string): string;
37
+ /** The fields of one step: those it lists, in field order; the last step also takes every field no step names. */
38
+ export declare function fieldsOfStep(form: Pick<FormDefinition, 'fields' | 'steps'>, index: number): FormField[];
39
+ export declare function renderForm(props: FormRenderProps): import("react").JSX.Element;
40
+ export declare const FORM_CSS = "\n/* ---------- Form ---------- */\n\n.sw-form-block { padding: var(--sw-space-4) 0; }\n/* Lined up with the headings and text around it; the column is capped so fields stay a readable width. */\n.sw-form-block .sw-container > * { max-width: 45rem; }\n.sw-form__title { margin: 0 0 var(--sw-space-1); font-family: var(--sw-font-heading); font-size: 1.75rem; line-height: 1.2; }\n.sw-form__intro { margin: 0 0 var(--sw-space-3); color: var(--sw-color-muted); }\n.sw-form { display: block; }\n.sw-form--placeholder {\n padding: var(--sw-space-3);\n border: 1px dashed var(--sw-color-border);\n border-radius: var(--sw-radius);\n color: var(--sw-color-muted);\n text-align: center;\n}\n.sw-form__body { display: grid; gap: var(--sw-space-2); }\n.sw-form__field { display: grid; gap: 0.35rem; }\n.sw-form__field[hidden] { display: none; }\n.sw-form__label { font-weight: 600; font-size: 0.95rem; }\n.sw-form__required { color: var(--sw-color-primary); }\n.sw-form input[type=\"text\"],\n.sw-form input[type=\"email\"],\n.sw-form input[type=\"url\"],\n.sw-form input[type=\"search\"],\n.sw-form input[type=\"date\"],\n.sw-form input[type=\"password\"],\n.sw-form input[type=\"tel\"],\n.sw-form input[type=\"number\"],\n.sw-form input[type=\"file\"],\n.sw-form textarea,\n.sw-form select {\n width: 100%;\n padding: 0.65rem 0.8rem;\n font: inherit;\n color: var(--sw-color-text);\n background: var(--sw-color-bg);\n border: 1px solid var(--sw-color-border);\n border-radius: var(--sw-radius);\n transition: border-color 120ms ease, box-shadow 120ms ease;\n}\n.sw-form textarea { resize: vertical; min-height: 7rem; }\n.sw-form input:focus-visible,\n.sw-form textarea:focus-visible,\n.sw-form select:focus-visible,\n.sw-form button:focus-visible { outline: none; border-color: var(--sw-color-primary); box-shadow: var(--sw-focus-ring); }\n.sw-form input:user-invalid,\n.sw-form textarea:user-invalid,\n.sw-form select:user-invalid,\n.sw-form [aria-invalid=\"true\"] { border-color: #b91c1c; }\n.sw-form__check { display: flex; gap: 0.6rem; align-items: flex-start; cursor: pointer; }\n.sw-form__check input { margin-top: 0.3rem; width: 1.1rem; height: 1.1rem; accent-color: var(--sw-color-primary); }\n.sw-form__help { margin: 0; font-size: 0.875rem; color: var(--sw-color-muted); }\n.sw-form__error { margin: 0; font-size: 0.875rem; color: #b91c1c; }\n.sw-form__error[hidden] { display: none; }\n.sw-form__status:empty { padding: 0; margin: 0; border: 0; }\n.sw-form__hp { position: absolute !important; left: -10000px !important; width: 1px; height: 1px; overflow: hidden; opacity: 0; }\n.sw-form__actions { margin-top: var(--sw-space-1); display: flex; gap: var(--sw-space-1); flex-wrap: wrap; }\n.sw-form__actions [hidden] { display: none; }\n.sw-form button[type=\"submit\"], .sw-form button[type=\"button\"] { font: inherit; cursor: pointer; border: 0; }\n.sw-form button[disabled] { opacity: 0.6; cursor: progress; }\n.sw-form__status { margin: 0 0 var(--sw-space-2); padding: 0.8rem 1rem; border-radius: var(--sw-radius); font-weight: 500; }\n.sw-form__status--success { background: color-mix(in srgb, #16a34a 12%, var(--sw-color-bg)); color: #14532d; border: 1px solid color-mix(in srgb, #16a34a 40%, var(--sw-color-bg)); }\n.sw-form__status--error { background: color-mix(in srgb, #dc2626 10%, var(--sw-color-bg)); color: #7f1d1d; border: 1px solid color-mix(in srgb, #dc2626 40%, var(--sw-color-bg)); }\n.sw-form__captcha { grid-column: 1 / -1; min-height: 65px; }\n.sw-form__payment { grid-column: 1 / -1; margin: 0; padding: 0; border: 0; min-width: 0; }\n.sw-form__payment legend { padding: 0; margin-bottom: 0.35rem; }\n.sw-form__amounts { display: flex; flex-wrap: wrap; gap: 0.5rem; }\n.sw-form__amount { position: relative; display: inline-flex; }\n.sw-form__amount input { position: absolute; opacity: 0; inset: 0; width: 100%; height: 100%; margin: 0; cursor: pointer; }\n.sw-form__amount span { display: inline-block; min-width: 4.5rem; padding: 0.6rem 1rem; text-align: center; font-weight: 600; border: 1px solid var(--sw-color-border); border-radius: var(--sw-radius); background: var(--sw-color-bg); transition: border-color 120ms ease, background-color 120ms ease; }\n.sw-form__amount input:checked + span { border-color: var(--sw-color-primary); background: color-mix(in srgb, var(--sw-color-primary) 12%, var(--sw-color-bg)); color: var(--sw-color-text); box-shadow: inset 0 0 0 1px var(--sw-color-primary); }\n.sw-form__amount input:focus-visible + span { box-shadow: var(--sw-focus-ring); border-color: var(--sw-color-primary); }\n.sw-form__other { display: grid; gap: 0.35rem; margin-top: 0.75rem; max-width: 16rem; }\n.sw-form__other[hidden] { display: none; }\n.sw-form__payment-note { grid-column: 1 / -1; }\n.sw-form__status--info { background: color-mix(in srgb, var(--sw-color-primary) 8%, var(--sw-color-bg)); border: 1px solid var(--sw-color-border); }\n.sw-form__progress { display: flex; flex-wrap: wrap; gap: var(--sw-space-1) var(--sw-space-2); margin: 0 0 var(--sw-space-1); padding: 0; list-style: none; font-size: 0.9rem; color: var(--sw-color-muted); grid-column: 1 / -1; }\n.sw-form__progress li { display: flex; align-items: center; gap: 0.4rem; }\n.sw-form__progress-num { display: inline-flex; align-items: center; justify-content: center; width: 1.6rem; height: 1.6rem; border-radius: 999px; border: 1px solid var(--sw-color-border); font-size: 0.8rem; font-weight: 600; }\n.sw-form__progress li.is-current { color: var(--sw-color-text); font-weight: 600; }\n.sw-form__progress li.is-current .sw-form__progress-num { background: var(--sw-color-primary); border-color: var(--sw-color-primary); color: #fff; }\n.sw-form__progress li.is-done .sw-form__progress-num { background: color-mix(in srgb, var(--sw-color-primary) 15%, var(--sw-color-bg)); border-color: var(--sw-color-primary); color: var(--sw-color-primary); }\n.sw-form__step { grid-column: 1 / -1; margin: 0; padding: 0; border: 0; min-width: 0; }\n.sw-form__step[hidden] { display: none; }\n.sw-form__step-title { padding: 0; margin: 0 0 var(--sw-space-2); font-family: var(--sw-font-heading); font-size: 1.15rem; font-weight: 600; }\n.sw-form__step-count { color: var(--sw-color-muted); font-weight: 500; }\n.sw-form--js .sw-form__step-count { display: none; }\n.sw-form__step-fields { display: grid; gap: var(--sw-space-2); }\n@media (min-width: 640px) {\n .sw-form__body, .sw-form__step-fields { grid-template-columns: 1fr 1fr; }\n .sw-form__field--textarea, .sw-form__field--checkbox, .sw-form__field--file, .sw-form__actions, .sw-form__hp { grid-column: 1 / -1; }\n}\n";
package/dist/form.js ADDED
@@ -0,0 +1,252 @@
1
+ import { jsxs as _jsxs, Fragment as _Fragment, jsx as _jsx } from "react/jsx-runtime";
2
+ /**
3
+ * The Form block. Stored props are `formKey`, `title`, `intro` and `submitLabel`; the server
4
+ * resolves `form: FormDefinition` (plus `nonce` and, when the site has one, `captcha`) into the
5
+ * props before render (core registers a resolver for block type "Form"). Without a resolved form,
6
+ * the block renders a placeholder so the editor and an unpublished form still show something sensible.
7
+ *
8
+ * Server-safe: no hooks, no DOM access. Progressive enhancement comes from a tiny inline script
9
+ * (carrying the page's CSP nonce) that evaluates `visibleWhen` rules, drives the stepper (one step
10
+ * at a time, each validated on the server before moving on), intercepts submit (JSON, or multipart
11
+ * when the form takes files) and shows the outcome in place; when fetch fails it lets the browser
12
+ * submit the form normally (303 back to the page). Without JavaScript every step is visible, the
13
+ * server evaluates the same rules and the form works through that redirect.
14
+ */
15
+ import { ZERO_DECIMAL_CURRENCIES, formatMinorUnits } from '@spillway-cms/shared';
16
+ const inputType = (f) => (f.type === 'email' || f.type === 'tel' || f.type === 'number' || f.type === 'hidden' ? f.type : 'text');
17
+ /** The `accept` attribute of a file input from the field's list (extensions get their dot, MIME types pass through). */
18
+ export function acceptAttr(field) {
19
+ const items = (field.accept ?? []).map((a) => a.trim()).filter(Boolean);
20
+ if (!items.length)
21
+ return undefined;
22
+ return items.map((a) => (a.includes('/') || a.startsWith('.') ? a : `.${a}`)).join(',');
23
+ }
24
+ function Field({ field, formId }) {
25
+ const id = `${formId}-${field.key}`;
26
+ const helpId = field.help ? `${id}-help` : undefined;
27
+ // The error line is empty and hidden until the server names the field; it is always part of the control's description.
28
+ const errId = `${id}-error`;
29
+ const describedBy = [helpId, errId].filter(Boolean).join(' ');
30
+ const when = field.visibleWhen ? JSON.stringify(field.visibleWhen) : undefined;
31
+ const labelText = (_jsxs(_Fragment, { children: [field.label, field.required ? (_jsxs("span", { className: "sw-form__required", "aria-hidden": "true", children: [' ', "*"] })) : null] }));
32
+ if (field.type === 'hidden')
33
+ return _jsx("input", { type: "hidden", name: field.key, value: field.placeholder ?? '', "data-sw-when": when });
34
+ if (field.type === 'checkbox') {
35
+ return (_jsxs("div", { className: "sw-form__field sw-form__field--checkbox", "data-sw-field": field.key, "data-sw-when": when, children: [_jsxs("label", { htmlFor: id, className: "sw-form__check", children: [_jsx("input", { id: id, type: "checkbox", name: field.key, value: "true", required: field.required || undefined, "aria-describedby": describedBy }), _jsx("span", { children: labelText })] }), field.help ? (_jsx("p", { id: helpId, className: "sw-form__help", children: field.help })) : null, _jsx("p", { className: "sw-form__error", id: errId, "data-sw-error": field.key, hidden: true })] }));
36
+ }
37
+ const multiple = field.type === 'file' && (field.maxCount ?? 1) > 1;
38
+ return (_jsxs("div", { className: `sw-form__field sw-form__field--${field.type}`, "data-sw-field": field.key, "data-sw-when": when, children: [_jsx("label", { htmlFor: id, className: "sw-form__label", children: labelText }), field.type === 'textarea' ? (_jsx("textarea", { id: id, name: field.key, rows: 5, placeholder: field.placeholder || undefined, required: field.required || undefined, "aria-describedby": describedBy })) : field.type === 'select' ? (_jsxs("select", { id: id, name: field.key, required: field.required || undefined, "aria-describedby": describedBy, defaultValue: "", children: [_jsx("option", { value: "", disabled: field.required || undefined, children: field.placeholder || 'Choose…' }), (field.options ?? []).map((o) => (_jsx("option", { value: o, children: o }, o)))] })) : field.type === 'file' ? (_jsx("input", { id: id, type: "file", name: field.key, accept: acceptAttr(field), multiple: multiple || undefined, required: field.required || undefined, "aria-describedby": describedBy, "data-sw-max": field.maxSize ? String(field.maxSize) : undefined })) : (_jsx("input", { id: id, type: inputType(field), name: field.key, placeholder: field.placeholder || undefined, required: field.required || undefined, "aria-describedby": describedBy, autoComplete: field.type === 'email' ? 'email' : field.type === 'tel' ? 'tel' : undefined, inputMode: field.type === 'number' ? 'decimal' : undefined, step: field.type === 'number' ? 'any' : undefined })), field.help ? (_jsx("p", { id: helpId, className: "sw-form__help", children: field.help })) : null, _jsx("p", { className: "sw-form__error", id: errId, "data-sw-error": field.key, hidden: true })] }));
39
+ }
40
+ /** An amount for people: "$25", "€10.50", "¥3,000" (Intl, falling back to "25.00 USD"). */
41
+ export function moneyLabel(amount, currency) {
42
+ const zero = ZERO_DECIMAL_CURRENCIES.includes(currency.toLowerCase());
43
+ try {
44
+ return new Intl.NumberFormat('en-US', { style: 'currency', currency: currency.toUpperCase(), minimumFractionDigits: zero || amount % 100 === 0 ? 0 : 2 }).format(zero ? amount : amount / 100);
45
+ }
46
+ catch {
47
+ return `${formatMinorUnits(amount, currency)} ${currency.toUpperCase()}`;
48
+ }
49
+ }
50
+ /** A payment form's amount and frequency choices. The server checks them again; the field names start with `_` so they are never stored as data. */
51
+ function Payment({ payment, formId }) {
52
+ const zero = ZERO_DECIMAL_CURRENCIES.includes(payment.currency);
53
+ const cur = payment.currency.toUpperCase();
54
+ const otherId = `${formId}-_amount_other`;
55
+ const errId = `${formId}-_amount-error`;
56
+ const monthly = payment.frequency === 'monthly';
57
+ const legend = monthly ? 'Monthly amount' : 'Amount';
58
+ const min = zero ? String(payment.minimum) : (payment.minimum / 100).toFixed(2);
59
+ return (_jsxs(_Fragment, { children: [payment.amounts.length ? (_jsxs("fieldset", { className: "sw-form__field sw-form__payment", "data-sw-field": "_amount", "aria-describedby": errId, children: [_jsxs("legend", { className: "sw-form__label", children: [legend, _jsxs("span", { className: "sw-form__required", "aria-hidden": "true", children: [' ', "*"] })] }), _jsxs("div", { className: "sw-form__amounts", children: [payment.amounts.map((a, i) => (_jsxs("label", { className: "sw-form__amount", children: [_jsx("input", { type: "radio", name: "_amount", value: String(a), defaultChecked: i === 0, required: true }), _jsx("span", { children: moneyLabel(a, payment.currency) })] }, a))), payment.allowCustom ? (_jsxs("label", { className: "sw-form__amount", children: [_jsx("input", { type: "radio", name: "_amount", value: "other" }), _jsx("span", { children: "Other" })] })) : null] }), payment.allowCustom ? (_jsxs("div", { className: "sw-form__other", "data-sw-when": JSON.stringify({ field: '_amount', op: 'equals', value: 'other' }), "data-sw-field": "_amount_other", children: [_jsx("label", { htmlFor: otherId, className: "sw-form__label", children: `Other amount (${cur})` }), _jsx("input", { id: otherId, type: "number", name: "_amount_other", min: min, step: zero ? '1' : '0.01', inputMode: "decimal", "aria-describedby": errId })] })) : null, _jsx("p", { className: "sw-form__error", id: errId, "data-sw-error": "_amount", hidden: true })] })) : (_jsxs("div", { className: "sw-form__field sw-form__payment", "data-sw-field": "_amount", children: [_jsx("input", { type: "hidden", name: "_amount", value: "other" }), _jsxs("label", { htmlFor: otherId, className: "sw-form__label", children: [`${legend} (${cur})`, _jsxs("span", { className: "sw-form__required", "aria-hidden": "true", children: [' ', "*"] })] }), _jsx("input", { id: otherId, type: "number", name: "_amount_other", min: min, step: zero ? '1' : '0.01', inputMode: "decimal", required: true, "aria-describedby": errId }), _jsx("p", { className: "sw-form__error", id: errId, "data-sw-error": "_amount", hidden: true })] })), payment.frequency === 'choose' ? (_jsxs("fieldset", { className: "sw-form__field sw-form__payment", "data-sw-field": "_frequency", children: [_jsx("legend", { className: "sw-form__label", children: "How often" }), _jsxs("div", { className: "sw-form__amounts", children: [_jsxs("label", { className: "sw-form__amount", children: [_jsx("input", { type: "radio", name: "_frequency", value: "once", defaultChecked: true }), _jsx("span", { children: "Once" })] }), _jsxs("label", { className: "sw-form__amount", children: [_jsx("input", { type: "radio", name: "_frequency", value: "monthly" }), _jsx("span", { children: "Monthly" })] })] })] })) : null, _jsx("p", { className: "sw-form__help sw-form__payment-note", children: monthly ? 'You pay on the next page, through Stripe, every month until you cancel.' : 'You pay on the next page, through Stripe.' })] }));
60
+ }
61
+ /** The fields of one step: those it lists, in field order; the last step also takes every field no step names. */
62
+ export function fieldsOfStep(form, index) {
63
+ const steps = form.steps ?? [];
64
+ if (steps.length === 0)
65
+ return index === 0 ? form.fields : [];
66
+ const step = steps[index];
67
+ if (!step)
68
+ return [];
69
+ const named = new Set(steps.flatMap((s) => s.fields));
70
+ const mine = new Set(step.fields);
71
+ const last = index === steps.length - 1;
72
+ return form.fields.filter((f) => mine.has(f.key) || (last && !named.has(f.key)));
73
+ }
74
+ /**
75
+ * Runs once per page load for every form it finds. Plain ES5 so it works without a build step.
76
+ * - stamps `_t` with the load time (the server-rendered value is the render time, which a cached
77
+ * page would make hours old; both pass the 2 s rule)
78
+ * - fills `_page` and `_utm` from the current URL
79
+ * - evaluates `data-sw-when` rules on every change: hidden fields are disabled so they neither
80
+ * submit nor block with `required` (the server applies the same rules)
81
+ * - the stepper: shows one step at a time, validates it with POST .../validate before moving on
82
+ * - shows the outcome of a non-JS submit (?form=<key>&sent=1 / &error=1)
83
+ * - intercepts submit: POST JSON (multipart when the form has files), show the message inline;
84
+ * on network failure submit normally
85
+ */
86
+ const SCRIPT = `(function(){var forms=document.querySelectorAll('form[data-sw-form]:not([data-sw-bound])');
87
+ for(var i=0;i<forms.length;i++)bind(forms[i]);
88
+ function q(f,n){return f.querySelector('input[name="'+n+'"]')}
89
+ function each(l,fn){for(var i=0;i<l.length;i++)fn(l[i],i)}
90
+ function show(f,kind,text){var s=f.querySelector('[data-sw-status]');if(!s)return;s.textContent=text;s.className='sw-form__status sw-form__status--'+kind;s.hidden=false;if(kind==='success'){var b=f.querySelector('.sw-form__body');if(b)b.hidden=true;}else{s.scrollIntoView&&s.scrollIntoView({block:'nearest'})}}
91
+ function clearErrors(f){each(f.querySelectorAll('[data-sw-error]'),function(e){e.hidden=true;e.textContent=''});each(f.querySelectorAll('[aria-invalid]'),function(c){c.removeAttribute('aria-invalid')})}
92
+ function showErrors(f,details){var first=null;each(details||[],function(d){var e=f.querySelector('[data-sw-error="'+d.field+'"]');if(e){e.textContent=d.message;e.hidden=false}var c=f.querySelector('[name="'+d.field+'"]');if(c){c.setAttribute('aria-invalid','true');if(!first)first=c}});return first}
93
+ function val(f,name){var c=f.querySelector('[name="'+name+'"]');if(!c)return '';if(c.type==='checkbox')return c.checked?'true':'false';if(c.type==='radio'){var r=f.querySelector('[name="'+name+'"]:checked');return r?r.value:''}if(c.type==='file')return c.files&&c.files.length?c.files[0].name:'';return String(c.value||'').trim()}
94
+ function match(f,w){var a=val(f,w.field),e=w.value==null?'':String(w.value).trim(),al=a.toLowerCase(),el=e.toLowerCase();var c=f.querySelector('[name="'+w.field+'"]'),cb=c&&c.type==='checkbox';
95
+ switch(w.op){case 'equals':return al===el;case 'notEquals':return al!==el;case 'contains':return al.indexOf(el)>=0;case 'isEmpty':return a===''||(cb&&a==='false');case 'isNotEmpty':return a!==''&&!(cb&&a==='false');case 'gt':return isFinite(+a)&&isFinite(+e)&&+a>+e;case 'lt':return isFinite(+a)&&isFinite(+e)&&+a<+e;default:return false}}
96
+ function visible(f,key,seen){var el=f.querySelector('[data-sw-field="'+key+'"],input[type=hidden][name="'+key+'"]');if(!el)return false;var w=el.getAttribute('data-sw-when');if(!w)return true;seen=seen||{};if(seen[key])return false;seen[key]=1;try{w=JSON.parse(w)}catch(e){return true}return visible(f,w.field,seen)&&match(f,w)}
97
+ function applyRules(f){each(f.querySelectorAll('[data-sw-when]'),function(el){var key=el.getAttribute('data-sw-field')||el.getAttribute('name'),on=visible(f,key);if(el.tagName==='INPUT'){el.disabled=!on;return}el.hidden=!on;each(el.querySelectorAll('input,select,textarea'),function(c){c.disabled=!on})})}
98
+ function stepOf(f,i){return f.querySelectorAll('[data-sw-step]')[i]}
99
+ function goTo(f,i){var steps=f.querySelectorAll('[data-sw-step]'),n=steps.length;if(!n)return;if(i<0)i=0;if(i>=n)i=n-1;f.setAttribute('data-sw-current',String(i));each(steps,function(s,k){s.hidden=k!==i});each(f.querySelectorAll('[data-sw-progress] li'),function(li,k){li.className=k<i?'is-done':k===i?'is-current':'';if(k===i)li.setAttribute('aria-current','step');else li.removeAttribute('aria-current')});
100
+ var back=f.querySelector('[data-sw-back]'),next=f.querySelector('[data-sw-next]'),sub=f.querySelector('button[type=submit]');if(back)back.hidden=i===0;if(next)next.hidden=i===n-1;if(sub)sub.hidden=i!==n-1;var first=steps[i].querySelector('input:not([type=hidden]):not([disabled]),select:not([disabled]),textarea:not([disabled])');if(first&&i>0)try{first.focus()}catch(e){}}
101
+ function values(f){var o={};each(f.querySelectorAll('input,select,textarea'),function(c){if(!c.name||c.disabled||c.type==='file'||c.type==='submit')return;if(c.type==='checkbox'){if(c.checked)o[c.name]=c.value||'true';return}if(c.type==='radio'){if(c.checked)o[c.name]=c.value;return}o[c.name]=c.value});return o}
102
+ function hasFile(f,scope){var ok=false;each((scope||f).querySelectorAll('input[type=file]'),function(c){if(!c.disabled&&c.files&&c.files.length)ok=true});return ok}
103
+ function tooBig(scope){var bad=null;each(scope.querySelectorAll('input[type=file]'),function(c){var m=+c.getAttribute('data-sw-max');if(!m||c.disabled||!c.files)return;for(var i=0;i<c.files.length;i++)if(c.files[i].size>m)bad=c.name});return bad}
104
+ function bind(f){f.setAttribute('data-sw-bound','1');f.classList.add('sw-form--js');var key=f.getAttribute('data-sw-form');
105
+ var t=q(f,'_t');if(t)t.value=String(Date.now());
106
+ var p=q(f,'_page');if(p)p.value=location.href;
107
+ var u=q(f,'_utm');if(u){try{var sp=new URLSearchParams(location.search),o={},n=0;sp.forEach(function(v,k){if(k.indexOf('utm_')===0){o[k]=v;n++}});if(n)u.value=JSON.stringify(o)}catch(e){}}
108
+ applyRules(f);f.addEventListener('input',function(){applyRules(f)});f.addEventListener('change',function(){applyRules(f)});
109
+ if(location.hash==='#sw-paid-'+key)show(f,'success',f.getAttribute('data-sw-success')||'Thank you.');else if(location.hash==='#sw-cancelled-'+key)show(f,'error','The payment was cancelled, and nothing was charged. You can try again.');
110
+ try{var qs=new URLSearchParams(location.search);if(qs.get('form')===key){if(qs.get('sent')==='1')show(f,'success',f.getAttribute('data-sw-success')||'Thank you.');else if(qs.get('error')==='1')show(f,'error',f.getAttribute('data-sw-error')||'Something went wrong. Please check the form and try again.')}}catch(e){}
111
+ var steps=f.querySelectorAll('[data-sw-step]');if(steps.length>1){goTo(f,0);
112
+ var back=f.querySelector('[data-sw-back]'),next=f.querySelector('[data-sw-next]');
113
+ if(back)back.addEventListener('click',function(){goTo(f,+f.getAttribute('data-sw-current')-1)});
114
+ if(next)next.addEventListener('click',function(){var i=+f.getAttribute('data-sw-current'),s=stepOf(f,i);clearErrors(f);var big=tooBig(s);if(big){showErrors(f,[{field:big,message:'file is too large'}]);return}
115
+ if(!window.fetch){var ok=true;each(s.querySelectorAll('input,select,textarea'),function(c){if(!c.disabled&&c.reportValidity&&!c.reportValidity())ok=false});if(ok)goTo(f,i+1);return}
116
+ var body=values(f);body._step=i;next.disabled=true;
117
+ fetch(f.getAttribute('action').replace(/\\/submit$/,'/validate'),{method:'POST',headers:{'Content-Type':'application/json','Accept':'application/json'},body:JSON.stringify(body),credentials:'same-origin'})
118
+ .then(function(r){return r.json().then(function(j){return{ok:r.ok,body:j}})})
119
+ .then(function(res){next.disabled=false;if(res.ok){goTo(f,i+1)}else{var e=res.body&&res.body.error;var first=showErrors(f,e&&e.details);if(first&&first.focus)first.focus();if(!(e&&e.details&&e.details.length))show(f,'error',(e&&e.message)||'Please check the form.')}})
120
+ .catch(function(){next.disabled=false;goTo(f,i+1)})})}
121
+ f.addEventListener('submit',function(ev){if(!window.fetch||!window.FormData)return;ev.preventDefault();clearErrors(f);
122
+ var big=tooBig(f);if(big){showErrors(f,[{field:big,message:'file is too large'}]);return}
123
+ var btn=f.querySelector('button[type=submit]');if(btn)btn.disabled=true;
124
+ var rk=f.getAttribute('data-sw-recaptcha');if(rk&&window.grecaptcha&&grecaptcha.ready){grecaptcha.ready(function(){grecaptcha.execute(rk,{action:'submit'}).then(function(tok){var h=q(f,'g-recaptcha-response');if(h)h.value=tok;send()},function(){send()})});return}
125
+ send();
126
+ function send(){var init={method:'POST',credentials:'same-origin',headers:{'Accept':'application/json'}};
127
+ if(hasFile(f)){var fd=new FormData(f);if(t)fd.set('_t',t.value);init.body=fd}else{var data=values(f);if(t)data._t=t.value;init.headers['Content-Type']='application/json';init.body=JSON.stringify(data)}
128
+ fetch(f.getAttribute('action'),init)
129
+ .then(function(r){return r.json().then(function(j){return{ok:r.ok,body:j}})})
130
+ .then(function(res){if(res.ok&&res.body.redirect){show(f,'info','Taking you to the payment page…');location.href=res.body.redirect;return}if(res.ok){show(f,'success',res.body.message||f.getAttribute('data-sw-success')||'Thank you.')}else{var e=res.body&&res.body.error,msg=(e&&e.message)||'Something went wrong.';var first=showErrors(f,e&&e.details);if(first){var st=first.closest&&first.closest('[data-sw-step]');if(st&&steps.length>1){var all=f.querySelectorAll('[data-sw-step]');for(var k=0;k<all.length;k++)if(all[k]===st)goTo(f,k)}}show(f,'error',msg);if(btn)btn.disabled=false;if(window.turnstile&&window.turnstile.reset)try{window.turnstile.reset()}catch(x){}if(window.hcaptcha&&window.hcaptcha.reset)try{window.hcaptcha.reset()}catch(x){}if(!rk&&window.grecaptcha&&window.grecaptcha.reset)try{window.grecaptcha.reset()}catch(x){}if(window.frcaptcha&&window.frcaptcha.widgets)try{window.frcaptcha.widgets.forEach(function(w){w.reset()})}catch(x){}}})
131
+ .catch(function(){if(btn)btn.disabled=false;HTMLFormElement.prototype.submit.call(f)})}})}})();`;
132
+ /** Each provider's widget element: the provider's script finds it by class and renders the challenge into it. */
133
+ const CAPTCHA_WIDGET_CLASS = {
134
+ turnstile: 'cf-turnstile',
135
+ hcaptcha: 'h-captcha',
136
+ 'recaptcha-v2': 'g-recaptcha',
137
+ friendly: 'frc-captcha',
138
+ };
139
+ function Captcha({ captcha, nonce }) {
140
+ // reCAPTCHA v3 shows no challenge: the form script asks for a token on submit and puts it in this field (Google's badge
141
+ // appears in a corner of the page). Friendly Captcha's widget is an ES module.
142
+ if (captcha.provider === 'recaptcha-v3') {
143
+ return (_jsxs(_Fragment, { children: [_jsx("input", { type: "hidden", name: "g-recaptcha-response", value: "" }), _jsx("script", { src: captcha.script, async: true, defer: true, nonce: nonce })] }));
144
+ }
145
+ return (_jsxs("div", { className: "sw-form__captcha", children: [_jsx("div", { className: CAPTCHA_WIDGET_CLASS[captcha.provider], "data-sitekey": captcha.siteKey }), _jsx("script", { src: captcha.script, async: true, defer: true, nonce: nonce, ...(captcha.provider === 'friendly' ? { type: 'module' } : {}) })] }));
146
+ }
147
+ export function renderForm(props) {
148
+ const { formKey, title, intro, submitLabel, form, nonce, captcha } = props;
149
+ if (!form) {
150
+ return (_jsx("section", { className: "sw-block sw-form-block", children: _jsx("div", { className: "sw-container", children: _jsx("div", { className: "sw-form sw-form--placeholder", role: "note", children: `Form: ${formKey || '(no form selected)'}` }) }) }));
151
+ }
152
+ const formId = `form-${form.key}`;
153
+ const steps = form.steps?.length ? form.steps : null;
154
+ const hasFiles = form.fields.some((f) => f.type === 'file');
155
+ const fieldList = (fields) => fields.map((f) => _jsx(Field, { field: f, formId: formId }, f.key));
156
+ return (_jsx("section", { className: "sw-block sw-form-block", children: _jsxs("div", { className: "sw-container", children: [title ? _jsx("h2", { className: "sw-form__title", children: title }) : null, intro ? _jsx("p", { className: "sw-form__intro", children: intro }) : null, _jsxs("form", { id: formId, className: `sw-form${steps ? ' sw-form--steps' : ''}`, method: "post", action: `/api/forms/${encodeURIComponent(form.key)}/submit`, encType: hasFiles ? 'multipart/form-data' : undefined, "data-sw-form": form.key, "data-sw-success": form.successMessage, "data-sw-recaptcha": captcha?.provider === 'recaptcha-v3' ? captcha.siteKey : undefined, noValidate: false, children: [_jsx("div", { className: "sw-form__status", "data-sw-status": "", role: "status", "aria-live": "polite" }), _jsxs("div", { className: "sw-form__body", children: [steps ? (_jsxs(_Fragment, { children: [_jsx("ol", { className: "sw-form__progress", "data-sw-progress": "", "aria-label": "Steps", children: steps.map((s, i) => (_jsxs("li", { className: i === 0 ? 'is-current' : undefined, "aria-current": i === 0 ? 'step' : undefined, children: [_jsx("span", { className: "sw-form__progress-num", "aria-hidden": "true", children: i + 1 }), ' ', s.title] }, i))) }), steps.map((s, i) => (_jsxs("fieldset", { className: "sw-form__step", "data-sw-step": String(i), children: [_jsxs("legend", { className: "sw-form__step-title", children: [_jsx("span", { className: "sw-form__step-count", children: `Step ${i + 1} of ${steps.length}:` }), " ", s.title] }), _jsxs("div", { className: "sw-form__step-fields", children: [fieldList(fieldsOfStep(form, i)), form.payment && i === steps.length - 1 ? _jsx(Payment, { payment: form.payment, formId: formId }) : null] })] }, i)))] })) : (_jsxs(_Fragment, { children: [fieldList(form.fields), form.payment ? _jsx(Payment, { payment: form.payment, formId: formId }) : null] })), _jsxs("div", { className: "sw-form__hp", "aria-hidden": "true", children: [_jsx("label", { htmlFor: `${formId}-_hp`, children: "Leave this field empty" }), _jsx("input", { id: `${formId}-_hp`, type: "text", name: "_hp", tabIndex: -1, autoComplete: "off", defaultValue: "" })] }), _jsx("input", { type: "hidden", name: "_t", value: String(Date.now()) }), _jsx("input", { type: "hidden", name: "_page", value: "" }), _jsx("input", { type: "hidden", name: "_utm", value: "" }), captcha ? _jsx(Captcha, { captcha: captcha, nonce: nonce }) : null, _jsxs("div", { className: "sw-form__actions", children: [steps ? (_jsxs(_Fragment, { children: [_jsx("button", { type: "button", className: "sw-button sw-button--secondary", "data-sw-back": "", hidden: true, children: "Back" }), _jsx("button", { type: "button", className: "sw-button sw-button--primary", "data-sw-next": "", hidden: true, children: "Next" })] })) : null, _jsx("button", { type: "submit", className: "sw-button sw-button--primary", children: submitLabel || form.submitLabel || 'Send' })] })] })] }), _jsx("script", { nonce: nonce, dangerouslySetInnerHTML: { __html: SCRIPT } })] }) }));
157
+ }
158
+ export const FORM_CSS = `
159
+ /* ---------- Form ---------- */
160
+
161
+ .sw-form-block { padding: var(--sw-space-4) 0; }
162
+ /* Lined up with the headings and text around it; the column is capped so fields stay a readable width. */
163
+ .sw-form-block .sw-container > * { max-width: 45rem; }
164
+ .sw-form__title { margin: 0 0 var(--sw-space-1); font-family: var(--sw-font-heading); font-size: 1.75rem; line-height: 1.2; }
165
+ .sw-form__intro { margin: 0 0 var(--sw-space-3); color: var(--sw-color-muted); }
166
+ .sw-form { display: block; }
167
+ .sw-form--placeholder {
168
+ padding: var(--sw-space-3);
169
+ border: 1px dashed var(--sw-color-border);
170
+ border-radius: var(--sw-radius);
171
+ color: var(--sw-color-muted);
172
+ text-align: center;
173
+ }
174
+ .sw-form__body { display: grid; gap: var(--sw-space-2); }
175
+ .sw-form__field { display: grid; gap: 0.35rem; }
176
+ .sw-form__field[hidden] { display: none; }
177
+ .sw-form__label { font-weight: 600; font-size: 0.95rem; }
178
+ .sw-form__required { color: var(--sw-color-primary); }
179
+ .sw-form input[type="text"],
180
+ .sw-form input[type="email"],
181
+ .sw-form input[type="url"],
182
+ .sw-form input[type="search"],
183
+ .sw-form input[type="date"],
184
+ .sw-form input[type="password"],
185
+ .sw-form input[type="tel"],
186
+ .sw-form input[type="number"],
187
+ .sw-form input[type="file"],
188
+ .sw-form textarea,
189
+ .sw-form select {
190
+ width: 100%;
191
+ padding: 0.65rem 0.8rem;
192
+ font: inherit;
193
+ color: var(--sw-color-text);
194
+ background: var(--sw-color-bg);
195
+ border: 1px solid var(--sw-color-border);
196
+ border-radius: var(--sw-radius);
197
+ transition: border-color 120ms ease, box-shadow 120ms ease;
198
+ }
199
+ .sw-form textarea { resize: vertical; min-height: 7rem; }
200
+ .sw-form input:focus-visible,
201
+ .sw-form textarea:focus-visible,
202
+ .sw-form select:focus-visible,
203
+ .sw-form button:focus-visible { outline: none; border-color: var(--sw-color-primary); box-shadow: var(--sw-focus-ring); }
204
+ .sw-form input:user-invalid,
205
+ .sw-form textarea:user-invalid,
206
+ .sw-form select:user-invalid,
207
+ .sw-form [aria-invalid="true"] { border-color: #b91c1c; }
208
+ .sw-form__check { display: flex; gap: 0.6rem; align-items: flex-start; cursor: pointer; }
209
+ .sw-form__check input { margin-top: 0.3rem; width: 1.1rem; height: 1.1rem; accent-color: var(--sw-color-primary); }
210
+ .sw-form__help { margin: 0; font-size: 0.875rem; color: var(--sw-color-muted); }
211
+ .sw-form__error { margin: 0; font-size: 0.875rem; color: #b91c1c; }
212
+ .sw-form__error[hidden] { display: none; }
213
+ .sw-form__status:empty { padding: 0; margin: 0; border: 0; }
214
+ .sw-form__hp { position: absolute !important; left: -10000px !important; width: 1px; height: 1px; overflow: hidden; opacity: 0; }
215
+ .sw-form__actions { margin-top: var(--sw-space-1); display: flex; gap: var(--sw-space-1); flex-wrap: wrap; }
216
+ .sw-form__actions [hidden] { display: none; }
217
+ .sw-form button[type="submit"], .sw-form button[type="button"] { font: inherit; cursor: pointer; border: 0; }
218
+ .sw-form button[disabled] { opacity: 0.6; cursor: progress; }
219
+ .sw-form__status { margin: 0 0 var(--sw-space-2); padding: 0.8rem 1rem; border-radius: var(--sw-radius); font-weight: 500; }
220
+ .sw-form__status--success { background: color-mix(in srgb, #16a34a 12%, var(--sw-color-bg)); color: #14532d; border: 1px solid color-mix(in srgb, #16a34a 40%, var(--sw-color-bg)); }
221
+ .sw-form__status--error { background: color-mix(in srgb, #dc2626 10%, var(--sw-color-bg)); color: #7f1d1d; border: 1px solid color-mix(in srgb, #dc2626 40%, var(--sw-color-bg)); }
222
+ .sw-form__captcha { grid-column: 1 / -1; min-height: 65px; }
223
+ .sw-form__payment { grid-column: 1 / -1; margin: 0; padding: 0; border: 0; min-width: 0; }
224
+ .sw-form__payment legend { padding: 0; margin-bottom: 0.35rem; }
225
+ .sw-form__amounts { display: flex; flex-wrap: wrap; gap: 0.5rem; }
226
+ .sw-form__amount { position: relative; display: inline-flex; }
227
+ .sw-form__amount input { position: absolute; opacity: 0; inset: 0; width: 100%; height: 100%; margin: 0; cursor: pointer; }
228
+ .sw-form__amount span { display: inline-block; min-width: 4.5rem; padding: 0.6rem 1rem; text-align: center; font-weight: 600; border: 1px solid var(--sw-color-border); border-radius: var(--sw-radius); background: var(--sw-color-bg); transition: border-color 120ms ease, background-color 120ms ease; }
229
+ .sw-form__amount input:checked + span { border-color: var(--sw-color-primary); background: color-mix(in srgb, var(--sw-color-primary) 12%, var(--sw-color-bg)); color: var(--sw-color-text); box-shadow: inset 0 0 0 1px var(--sw-color-primary); }
230
+ .sw-form__amount input:focus-visible + span { box-shadow: var(--sw-focus-ring); border-color: var(--sw-color-primary); }
231
+ .sw-form__other { display: grid; gap: 0.35rem; margin-top: 0.75rem; max-width: 16rem; }
232
+ .sw-form__other[hidden] { display: none; }
233
+ .sw-form__payment-note { grid-column: 1 / -1; }
234
+ .sw-form__status--info { background: color-mix(in srgb, var(--sw-color-primary) 8%, var(--sw-color-bg)); border: 1px solid var(--sw-color-border); }
235
+ .sw-form__progress { display: flex; flex-wrap: wrap; gap: var(--sw-space-1) var(--sw-space-2); margin: 0 0 var(--sw-space-1); padding: 0; list-style: none; font-size: 0.9rem; color: var(--sw-color-muted); grid-column: 1 / -1; }
236
+ .sw-form__progress li { display: flex; align-items: center; gap: 0.4rem; }
237
+ .sw-form__progress-num { display: inline-flex; align-items: center; justify-content: center; width: 1.6rem; height: 1.6rem; border-radius: 999px; border: 1px solid var(--sw-color-border); font-size: 0.8rem; font-weight: 600; }
238
+ .sw-form__progress li.is-current { color: var(--sw-color-text); font-weight: 600; }
239
+ .sw-form__progress li.is-current .sw-form__progress-num { background: var(--sw-color-primary); border-color: var(--sw-color-primary); color: #fff; }
240
+ .sw-form__progress li.is-done .sw-form__progress-num { background: color-mix(in srgb, var(--sw-color-primary) 15%, var(--sw-color-bg)); border-color: var(--sw-color-primary); color: var(--sw-color-primary); }
241
+ .sw-form__step { grid-column: 1 / -1; margin: 0; padding: 0; border: 0; min-width: 0; }
242
+ .sw-form__step[hidden] { display: none; }
243
+ .sw-form__step-title { padding: 0; margin: 0 0 var(--sw-space-2); font-family: var(--sw-font-heading); font-size: 1.15rem; font-weight: 600; }
244
+ .sw-form__step-count { color: var(--sw-color-muted); font-weight: 500; }
245
+ .sw-form--js .sw-form__step-count { display: none; }
246
+ .sw-form__step-fields { display: grid; gap: var(--sw-space-2); }
247
+ @media (min-width: 640px) {
248
+ .sw-form__body, .sw-form__step-fields { grid-template-columns: 1fr 1fr; }
249
+ .sw-form__field--textarea, .sw-form__field--checkbox, .sw-form__field--file, .sw-form__actions, .sw-form__hp { grid-column: 1 / -1; }
250
+ }
251
+ `;
252
+ //# sourceMappingURL=form.js.map