@samva/markup 0.9.0 → 0.10.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.
Files changed (88) hide show
  1. package/AGENTS.md +48 -40
  2. package/CHANGELOG.md +345 -0
  3. package/README.md +6 -6
  4. package/dist/{brand-B-0bN_Ir.d.ts → assets-BIsyMQ92.d.ts} +41 -11
  5. package/dist/{email/brand.js → brand-C0MKTwmX.js} +64 -4
  6. package/dist/{theme-css.d.ts → brand.d.ts} +12 -3
  7. package/dist/brand.js +4 -0
  8. package/dist/compiler.d.ts +231 -11
  9. package/dist/compiler.js +1312 -13
  10. package/dist/components-BZCqegS8.js +1864 -0
  11. package/dist/diagnostic-model-DJtqbETd.js +38 -0
  12. package/dist/diagnostic-model-DxthUZBT.d.ts +31 -0
  13. package/dist/{email/diagnostics.js → diagnostics-CnKFefKz.js} +2 -2
  14. package/dist/diagnostics.d.ts +406 -27
  15. package/dist/diagnostics.js +402 -34
  16. package/dist/edit.d.ts +234 -0
  17. package/dist/{channel-edit.js → edit.js} +341 -3
  18. package/dist/email/jsx-dev-runtime.d.ts +1 -1
  19. package/dist/email/jsx-dev-runtime.js +1 -2
  20. package/dist/email/jsx-runtime.d.ts +1 -1
  21. package/dist/email/jsx-runtime.js +1 -85
  22. package/dist/{email/components.d.ts → email.d.ts} +2 -2
  23. package/dist/email.js +2 -0
  24. package/dist/index.d.ts +1 -1
  25. package/dist/index.js +1 -1
  26. package/dist/{cascade-t6kxlgEI.js → ir-CLhlklKV.js} +8 -4
  27. package/dist/jsx-runtime-CBlexoeR.js +98 -0
  28. package/dist/{elements-cqldpaJt.d.ts → jsx-runtime-ylIOnaSf.d.ts} +74 -74
  29. package/dist/{profile-BH-OtdDA.js → profile-pWGtWZXF.js} +153 -20
  30. package/dist/render-BPonDpCl.d.ts +539 -0
  31. package/dist/{email/render.js → render-BQmfh94k.js} +102 -8
  32. package/dist/render.d.ts +35 -0
  33. package/dist/render.js +49 -0
  34. package/dist/sms.d.ts +1 -1
  35. package/dist/sms.js +1 -1
  36. package/dist/{template-_QE_rQND.d.ts → template-DMPwxMSq.d.ts} +2 -2
  37. package/dist/{template.js → template-zLUjcwfF.js} +2 -2
  38. package/dist/{theme-css-hFqcPSar.js → theme-css-JtRCm1fb.js} +2 -2
  39. package/dist/whatsapp.d.ts +1 -1
  40. package/dist/whatsapp.js +1 -1
  41. package/generated/contract.json +16 -10
  42. package/generated/reference.md +17 -10
  43. package/package.json +36 -119
  44. package/samva-brand.d.ts +4 -4
  45. package/skills/sml/SKILL.md +2 -2
  46. package/dist/assets-C5duwTya.d.ts +0 -40
  47. package/dist/channel-edit.d.ts +0 -121
  48. package/dist/channel-specs-B6M_HlaV.js +0 -29
  49. package/dist/compatibility-DbISoFIq.js +0 -589
  50. package/dist/css-BVQKICKC.d.ts +0 -109
  51. package/dist/diagnostic-codes.d.ts +0 -403
  52. package/dist/diagnostic-codes.js +0 -399
  53. package/dist/email/assets.d.ts +0 -2
  54. package/dist/email/assets.js +0 -63
  55. package/dist/email/brand-footer.d.ts +0 -34
  56. package/dist/email/brand-footer.js +0 -63
  57. package/dist/email/brand.d.ts +0 -2
  58. package/dist/email/components.js +0 -275
  59. package/dist/email/diagnostics.d.ts +0 -2
  60. package/dist/email/elements.d.ts +0 -2
  61. package/dist/email/elements.js +0 -299
  62. package/dist/email/html.d.ts +0 -2
  63. package/dist/email/html.js +0 -321
  64. package/dist/email/render.d.ts +0 -40
  65. package/dist/email/text.d.ts +0 -7
  66. package/dist/email/text.js +0 -100
  67. package/dist/html-BJepOwZ4.d.ts +0 -56
  68. package/dist/ir-aaqNE987.d.ts +0 -252
  69. package/dist/ir.d.ts +0 -2
  70. package/dist/ir.js +0 -7
  71. package/dist/preview-Ekdg1dXG.d.ts +0 -100
  72. package/dist/preview.d.ts +0 -2
  73. package/dist/preview.js +0 -160
  74. package/dist/render-ir.d.ts +0 -19
  75. package/dist/render-ir.js +0 -826
  76. package/dist/sms-segments.d.ts +0 -13
  77. package/dist/sms-segments.js +0 -46
  78. package/dist/source-edit.d.ts +0 -116
  79. package/dist/source-edit.js +0 -343
  80. package/dist/source-locations.d.ts +0 -2
  81. package/dist/source-locations.js +0 -16
  82. package/dist/static.d.ts +0 -57
  83. package/dist/static.js +0 -69
  84. package/dist/tailwind-CMYpZf1v.js +0 -614
  85. package/dist/template.d.ts +0 -2
  86. package/dist/theme-css.js +0 -2
  87. package/dist/theme-imports-lvBw3AD1.js +0 -109
  88. package/dist/transform-Ct2OMkFN.d.ts +0 -153
@@ -1,38 +1,406 @@
1
- //#region src/diagnostics.ts
2
- /** Newline-offset line map. Build once per source, query with `lineColumn`. */
3
- const buildLineMap = (source) => {
4
- const lineStarts = [0];
5
- for (let index = 0; index < source.length; index++) {
6
- const code = source.charCodeAt(index);
7
- if (code === 10 || code === 13 && source.charCodeAt(index + 1) !== 10 || code === 8232 || code === 8233) lineStarts.push(index + 1);
1
+ import { i as lineColumn, n as createDiagnosticFormatter, r as formatDiagnostic, t as buildLineMap } from "./diagnostic-model-DJtqbETd.js";
2
+ import { n as formatEmailDiagnostic, r as hasBlockingDiagnostic, t as EmailCompileError } from "./diagnostics-CnKFefKz.js";
3
+ //#region src/diagnostic-codes.ts
4
+ const codes = (table) => table;
5
+ const DIAGNOSTIC_CODES = codes({
6
+ "no-template": {
7
+ summary: "The entry does not default-export a template.",
8
+ fix: "Default-export defineTemplate({ ... }) imported from @samva/markup."
9
+ },
10
+ "legacy-definition": {
11
+ summary: "The entry default-exports something other than defineTemplate.",
12
+ fix: "Import { defineTemplate } from \"@samva/markup\" and default-export defineTemplate({ ... }).",
13
+ upgrade: [
14
+ "Read the entry and its imports without executing them. For a default-exported defineEmail definition, import defineTemplate from \"@samva/markup\" and replace the definition call.",
15
+ "Preserve the entry path, template id, schema, named fixtures, content, design, bindings, conditions, project partials, assets, theme and brand imports. Replace render(input) returning { subject, preheader?, body } with email: { subject: (input) => ..., preheader: (input) => ..., body: (input) => ... }, retaining its parameter bindings and each returned expression; omit preheader when absent.",
16
+ "Inline module constants only when they are literal strings, numbers or booleans and their bindings are unambiguous; never substitute a fixture value for an input binding. Keep each channel function a single static-profile expression, and keep subject and preheader off <Email>.",
17
+ "Helper calls, `Math.*`, general arithmetic, render statements, spreads, computed properties and runtime clock or seed have no direct conversion. Rewrite with static-profile bindings, conditions, .map, .filter, project partials or `fmt.*` where equivalent; arithmetic is allowed only in formatter arguments and conditions. Otherwise compute the value in the sender, declare a payload field in the schema and every fixture, and explain the required sender change. Never guess time, randomness or computed data.",
18
+ "Explicit text has no email-channel field: plain text is derived from the body. If deriving it changes intended content, or another construct cannot be preserved, explain the tradeoff and ask rather than silently discard it. Do not drop fixtures, weaken validation or hide diagnostics.",
19
+ "Convert every affected entry in the project at its existing path, including emails/ entries. Compile each entry, render every declared fixture and inspect the affected output. Resolve errors before requesting one saved version for the whole project, approved by the user; do not publish."
20
+ ].join("\n\n")
21
+ },
22
+ "dynamic-definition": {
23
+ summary: "A definition field is spread or computed instead of written out.",
24
+ fix: "Write each field as name: value."
25
+ },
26
+ "invalid-template-id": {
27
+ summary: "The template id is not a lowercase kebab-case string literal.",
28
+ fix: "Write id: \"order-shipped\"."
29
+ },
30
+ "missing-schema": {
31
+ summary: "The template declares no input schema.",
32
+ fix: "Add schema: jsonSchema<Input>({ ... })."
33
+ },
34
+ "schema-not-static": {
35
+ summary: "The schema cannot be read without running code.",
36
+ fix: "Write the schema as a literal jsonSchema<Input>({ type: 'object', ... })."
37
+ },
38
+ "invalid-schema": {
39
+ summary: "The schema uses JSON Schema keywords the compiler cannot validate against.",
40
+ fix: "Use only the JSON Schema keywords the package README lists."
41
+ },
42
+ "missing-fixtures": {
43
+ summary: "The template declares no fixtures.",
44
+ fix: "Add fixtures: { default: { ... } } with at least one valid payload."
45
+ },
46
+ "fixtures-not-static": {
47
+ summary: "A fixture is computed instead of written as data.",
48
+ fix: "Write each fixture as a literal object; an imported asset is allowed."
49
+ },
50
+ "invalid-fixture-name": {
51
+ summary: "A fixture key is not a single path segment.",
52
+ fix: "Use letters, digits, '.', '_' and '-', starting with a letter or digit."
53
+ },
54
+ "fixture-invalid": {
55
+ summary: "A fixture does not match the schema.",
56
+ fix: "Change the fixture, or the schema, so every fixture is a payload a send could carry."
57
+ },
58
+ "invalid-locale": {
59
+ summary: "The template's default locale is not a string literal.",
60
+ fix: "Write locale: \"en-US\"."
61
+ },
62
+ "no-channel": {
63
+ summary: "The template declares no channel body.",
64
+ fix: "Add an email body."
65
+ },
66
+ "invalid-channel": {
67
+ summary: "A channel field is not shaped as the channel requires.",
68
+ fix: "Write email: { subject, preheader?, body } with each a function of the input."
69
+ },
70
+ "not-a-function": {
71
+ summary: "A channel field is not a function of the input.",
72
+ fix: "Write (input) => ... in place or declare the function in the project."
73
+ },
74
+ "missing-subject": {
75
+ summary: "The email channel has no subject.",
76
+ fix: "Add subject: (input) => ...."
77
+ },
78
+ "missing-body": {
79
+ summary: "The email channel has no body.",
80
+ fix: "Add body: (input) => (<Email>...</Email>)."
81
+ },
82
+ "multiple-roots": {
83
+ summary: "The body renders nothing or more than one root.",
84
+ fix: "Wrap the body in a single element such as <Email>."
85
+ },
86
+ "preheader-without-shell": {
87
+ summary: "A preheader is set but the body has no <Email> shell to hold it.",
88
+ fix: "Wrap the body in <Email>."
89
+ },
90
+ "wrong-channel": {
91
+ summary: "A channel body does not return its own channel component.",
92
+ fix: "Return one element imported from the channel package.",
93
+ channelOnly: true
94
+ },
95
+ "syntax-error": {
96
+ summary: "A project file does not parse as TSX.",
97
+ fix: "Fix the syntax at the reported location."
98
+ },
99
+ "non-project-import": {
100
+ summary: "The file imports something other than @samva/markup or a project file.",
101
+ fix: "Remove the import, or copy the code you need into a project file."
102
+ },
103
+ "moved-import": {
104
+ summary: "The file imports an @samva/markup entry that moved.",
105
+ fix: "Import email components from \"@samva/markup/email\".",
106
+ upgrade: ["Replace every import from \"@samva/markup/email/components\" with \"@samva/markup/email\" in every project file, templates and partials alike. The imported names are unchanged; change only the specifier.", "Compile each entry and render every declared fixture to confirm the output is unchanged. Resolve errors before requesting one saved version for the whole project, approved by the user; do not publish."].join("\n\n")
107
+ },
108
+ "unresolved-import": {
109
+ summary: "An import names no file in the project.",
110
+ fix: "Check the path and the file extension."
111
+ },
112
+ "recursive-partial": {
113
+ summary: "A partial renders itself; partials are inlined at compile time.",
114
+ fix: "Flatten the recursion, or repeat the structure with .map."
115
+ },
116
+ "nesting-limit": {
117
+ summary: "The template nests deeper than the compiler reads.",
118
+ fix: "Flatten the structure."
119
+ },
120
+ "dynamic-expression": {
121
+ summary: "An expression outside the static profile: a call other than fmt.* and .map, a computed value, or a spread.",
122
+ fix: "Compute the value where the message is sent and bind it from the payload."
123
+ },
124
+ "statement-in-body": {
125
+ summary: "A body contains a statement (const, if, a loop); a body is one expression.",
126
+ fix: "Use cond && <X />, cond ? <A /> : <B /> and .map, or send the computed value in the payload."
127
+ },
128
+ "unsupported-pattern": {
129
+ summary: "A parameter pattern or default value the profile cannot bind.",
130
+ fix: "Use plain names or destructuring without defaults; declare the field required or guard it."
131
+ },
132
+ "hook-call": {
133
+ summary: "A hook was called; templates have no state, effects or context.",
134
+ fix: "Read the input through the function's parameter and send anything else in the payload."
135
+ },
136
+ "unknown-formatter": {
137
+ summary: "fmt.<name> is not a formatter.",
138
+ fix: "Use fmt.money, number, date, time, plural or list."
139
+ },
140
+ "formatter-arguments": {
141
+ summary: "A formatter got the wrong number of arguments.",
142
+ fix: "Match the formatter's signature in the contract."
143
+ },
144
+ "reserved-character": {
145
+ summary: "Text contains a private-use character the compiler reserves.",
146
+ fix: "Remove the characters U+E000 to U+E003."
147
+ },
148
+ "reserved-url": {
149
+ summary: "A URL is the unsubscribe placeholder only BrandFooter can write.",
150
+ fix: "Render <BrandFooter /> instead."
151
+ },
152
+ "reserved-attribute": {
153
+ summary: "An attribute is written only by a brand component.",
154
+ fix: "Render BrandFooter from samva:brand instead of marking an element as the footer."
155
+ },
156
+ "dynamic-class": {
157
+ summary: "A class name is built at run time, and Tailwind cannot see it.",
158
+ fix: "Write classes literally, or choose between literal lists: input.vip ? \"bg-amber-100\" : \"bg-white\"."
159
+ },
160
+ "too-many-class-variants": {
161
+ summary: "A class list chooses between more literal lists than the compiler resolves.",
162
+ fix: "Split the choice into fewer conditions, or move part of it to a partial."
163
+ },
164
+ "invalid-style": {
165
+ summary: "A style prop is not a static property object.",
166
+ fix: "Write style={{ backgroundColor: \"#fff\" }} with literal values, or use classes."
167
+ },
168
+ "unknown-field": {
169
+ summary: "A binding names a field the schema does not declare.",
170
+ fix: "Add the field to the schema, or bind a field it declares (the message suggests the nearest)."
171
+ },
172
+ "unguarded-optional": {
173
+ summary: "An optional field is read outside a guard, so a send without it would render a blank.",
174
+ fix: "Guard it with {input.field && ...}, or make the field required."
175
+ },
176
+ "invalid-binding-type": {
177
+ summary: "A binding has the wrong type for where it is used.",
178
+ fix: "Bind a field of the type the position needs, or send it in that type."
179
+ },
180
+ "unknown-component": {
181
+ summary: "A component the profile cannot read.",
182
+ fix: "Import components from @samva/markup/email, samva:brand, or the project."
183
+ },
184
+ "dynamic-numeric-prop": {
185
+ summary: "A prop that sizes layout at compile time is not a number literal.",
186
+ fix: "Write the number literally, for example height={44}."
187
+ },
188
+ "button-dynamic-label": {
189
+ summary: "A Button label is read at render time, so classic Outlook cannot size it.",
190
+ fix: "Give the button a width: <Button width={200}>."
191
+ },
192
+ "invalid-columns-each": {
193
+ summary: "<Columns each> is not a list from the input.",
194
+ fix: "Write each={input.items} with a callback returning <Column>."
195
+ },
196
+ "invalid-columns-per": {
197
+ summary: "<Columns per> is not a positive integer literal.",
198
+ fix: "Write per={2}."
199
+ },
200
+ "invalid-button-number": {
201
+ summary: "A Button size prop is not a finite number.",
202
+ fix: "Pass a finite number."
203
+ },
204
+ "unsupported-element": {
205
+ summary: "An element outside the supported email vocabulary.",
206
+ fix: "Use an element from the contract's element table."
207
+ },
208
+ "unsupported-attribute": {
209
+ summary: "An attribute the element does not support.",
210
+ fix: "Use a supported attribute, or data-* and aria-*."
211
+ },
212
+ "missing-attribute": {
213
+ summary: "An element is missing a required attribute.",
214
+ fix: "Add the attribute, for example alt on img."
215
+ },
216
+ "invalid-attribute-value": {
217
+ summary: "An attribute value is not a string or number, or contains control characters.",
218
+ fix: "Pass plain text."
219
+ },
220
+ "duplicate-attribute": {
221
+ summary: "An attribute is written twice.",
222
+ fix: "Keep one."
223
+ },
224
+ "invalid-content": {
225
+ summary: "An element holds content its content model does not allow.",
226
+ fix: "Move the child to a parent that accepts it."
227
+ },
228
+ "void-element-children": {
229
+ summary: "A void element has children.",
230
+ fix: "Remove the children."
231
+ },
232
+ "event-handler": {
233
+ summary: "An event handler; email clients strip scripting.",
234
+ fix: "Remove the handler; use a link for interaction."
235
+ },
236
+ "dangerous-html": {
237
+ summary: "dangerouslySetInnerHTML; there is no raw-HTML escape hatch.",
238
+ fix: "Write the markup as JSX."
239
+ },
240
+ "unsafe-url": {
241
+ summary: "A URL uses a scheme email cannot send safely.",
242
+ fix: "Use an https URL, a mailto: or tel: link, or a bound URL."
243
+ },
244
+ "unsafe-raw-text": {
245
+ summary: "Raw text content contains markup that could end its element.",
246
+ fix: "Remove the offending sequence."
247
+ },
248
+ "unsupported-style-property": {
249
+ summary: "A style property name is not a CSS property.",
250
+ fix: "Write camelCase (backgroundColor) or a custom property (--brand)."
251
+ },
252
+ "invalid-style-value": {
253
+ summary: "A style value is not a string or number.",
254
+ fix: "Pass a string or number."
255
+ },
256
+ "unsafe-style-value": {
257
+ summary: "A style value contains CSS that could break out of its declaration.",
258
+ fix: "Remove the offending characters."
259
+ },
260
+ "missing-head": {
261
+ summary: "Styles that cannot be inlined need a <head> to live in.",
262
+ fix: "Wrap the message in <Email>, or write those declarations inline."
263
+ },
264
+ "invalid-subject": {
265
+ summary: "The subject is not one line of text.",
266
+ fix: "Return a single-line string."
267
+ },
268
+ "invalid-preheader": {
269
+ summary: "The preheader is not a string.",
270
+ fix: "Return a string."
271
+ },
272
+ "invalid-text": {
273
+ summary: "The plain-text body is not a string.",
274
+ fix: "Return a string."
275
+ },
276
+ "button-outlook-fallback": {
277
+ summary: "Classic Outlook needs a height and a plain string label to draw the button.",
278
+ fix: "Give <Button> a height and a string label."
279
+ },
280
+ "unmatched-class": {
281
+ summary: "A class produced no styles.",
282
+ fix: "Use a class the theme or Tailwind defines, or write the style inline."
283
+ },
284
+ "tailwind-dynamic-class": {
285
+ summary: "A class list is assembled at run time.",
286
+ fix: "Write the classes literally."
287
+ },
288
+ "css-parse-error": {
289
+ summary: "A stylesheet does not parse.",
290
+ fix: "Fix the CSS at the reported location."
291
+ },
292
+ "css-import-unresolved": {
293
+ summary: "A stylesheet @import cannot be resolved.",
294
+ fix: "Import the stylesheet from the template module, or use the theme.css layers."
295
+ },
296
+ "css-unsupported-at-rule": {
297
+ summary: "An at-rule is not applied to email output.",
298
+ fix: "Remove it or move the declarations into a class rule."
299
+ },
300
+ "css-conditional-variable": {
301
+ summary: "A custom property is redefined inside a conditional at-rule.",
302
+ fix: "Keep the override on a class rule."
303
+ },
304
+ "email-font-fallback": {
305
+ summary: "A font stack names a project font without a generic fallback.",
306
+ fix: "End the stack with sans-serif, serif or monospace."
307
+ },
308
+ "email-font-family": {
309
+ summary: "@font-face declares no font-family.",
310
+ fix: "Add font-family."
311
+ },
312
+ "email-font-src": {
313
+ summary: "@font-face declares no usable url() src.",
314
+ fix: "Add a url() pointing at a .woff2 file."
315
+ },
316
+ "email-font-format": {
317
+ summary: "@font-face uses a format other than WOFF2.",
318
+ fix: "Convert the file to .woff2."
319
+ },
320
+ "email-font-missing": {
321
+ summary: "@font-face names a file the project does not hold.",
322
+ fix: "Add the file; paths resolve from the stylesheet's directory."
323
+ },
324
+ "invalid-asset-base": {
325
+ summary: "The asset base is not an https URL or a path.",
326
+ fix: "Use an https URL, an absolute path, or a relative path."
327
+ },
328
+ "brand-unavailable": {
329
+ summary: "The build has no brand to resolve a samva:brand import.",
330
+ fix: "Create or select the brand the import names."
331
+ },
332
+ "brand-import-conflict": {
333
+ summary: "The project imports two different brands.",
334
+ fix: "Import one brand specifier everywhere."
335
+ },
336
+ "caniemail/unknown-coverage": {
337
+ summary: "A feature has no client-support data.",
338
+ fix: "Verify it in the target clients."
339
+ },
340
+ "invalid-attribute": {
341
+ summary: "A channel component attribute has a value the channel does not accept.",
342
+ fix: "Use one of the listed values.",
343
+ channelOnly: true
344
+ },
345
+ "unknown-attribute": {
346
+ summary: "A channel component attribute the component does not have.",
347
+ fix: "Use one of the listed attributes.",
348
+ channelOnly: true
349
+ },
350
+ "sms-markup": {
351
+ summary: "An SMS body contains an element; SMS is plain text.",
352
+ fix: "Write text and bindings, with a newline for a line break.",
353
+ channelOnly: true
354
+ },
355
+ "whatsapp-structure": {
356
+ summary: "WhatsApp content sits outside Header, Body, Footer or Buttons.",
357
+ fix: "Move it into <WhatsApp.Body>.",
358
+ channelOnly: true
359
+ },
360
+ "whatsapp-body-required": {
361
+ summary: "A WhatsApp template has no body.",
362
+ fix: "Add <WhatsApp.Body>...</WhatsApp.Body>.",
363
+ channelOnly: true
364
+ },
365
+ "whatsapp-conditional": {
366
+ summary: "A WhatsApp part branches or contains elements; Meta registers its text once.",
367
+ fix: "Choose the wording in the payload, or write separate templates.",
368
+ channelOnly: true
369
+ },
370
+ "whatsapp-header-media": {
371
+ summary: "A WhatsApp media header is not exactly one URL.",
372
+ fix: "Write the URL as the only child: a literal or one binding.",
373
+ channelOnly: true
374
+ },
375
+ "whatsapp-header-variables": {
376
+ summary: "A WhatsApp header text takes more than one variable.",
377
+ fix: "Keep one binding in the header and move the rest to the body.",
378
+ channelOnly: true
379
+ },
380
+ "whatsapp-length": {
381
+ summary: "A WhatsApp part exceeds Meta's length limit.",
382
+ fix: "Shorten the text.",
383
+ channelOnly: true
384
+ },
385
+ "whatsapp-button-text": {
386
+ summary: "A WhatsApp button has no label or value between its tags.",
387
+ fix: "Write the label or value as text between the tags.",
388
+ channelOnly: true
389
+ },
390
+ "whatsapp-button-limit": {
391
+ summary: "The conditions can produce more buttons of a kind than Meta allows.",
392
+ fix: "Remove buttons, or split the template.",
393
+ channelOnly: true
8
394
  }
9
- return lineStarts;
10
- };
11
- /** 1-based line/column for an absolute offset, via binary search. */
12
- const lineColumn = (lineMap, offset) => {
13
- let low = 0;
14
- let high = lineMap.length - 1;
15
- while (low < high) {
16
- const middle = low + high + 1 >> 1;
17
- if (lineMap[middle] <= offset) low = middle;
18
- else high = middle - 1;
19
- }
20
- return {
21
- line: low + 1,
22
- column: offset - lineMap[low] + 1
23
- };
24
- };
25
- /** Build one formatter for a batch of diagnostics against the same source. */
26
- const createDiagnosticFormatter = (source) => {
27
- const lineMap = buildLineMap(source);
28
- return (diagnostic) => {
29
- const { line, column } = lineColumn(lineMap, diagnostic.span.start);
30
- return `line ${line}:${column} ${diagnostic.message}`;
31
- };
32
- };
33
- /** "line 12:8 unknown class ..." — the shape agents iterate on. */
34
- const formatDiagnostic = (source, diagnostic) => createDiagnosticFormatter(source)(diagnostic);
395
+ });
396
+ /** Whether a diagnostic identifier selects an agent-driven format upgrade. */
397
+ const hasUpgradeRecipe = (code) => Object.entries(DIAGNOSTIC_CODES).some(([identifier, spec]) => identifier === code && "upgrade" in spec);
398
+ /** Families whose code carries a suffix chosen at run time. */
399
+ const DIAGNOSTIC_CODE_FAMILIES = { "caniemail/": {
400
+ summary: "A CSS property, HTML element or attribute that a target email client ignores or partly supports (from the caniemail.com data), reported as caniemail/<feature>.",
401
+ fix: "Use the alternative the message names, such as an email component instead of display: flex."
402
+ } };
35
403
  //#endregion
36
- export { buildLineMap, createDiagnosticFormatter, formatDiagnostic, lineColumn };
404
+ export { DIAGNOSTIC_CODES, DIAGNOSTIC_CODE_FAMILIES, EmailCompileError, buildLineMap, createDiagnosticFormatter, formatDiagnostic, formatEmailDiagnostic, hasBlockingDiagnostic, hasUpgradeRecipe, lineColumn };
37
405
 
38
406
  //# sourceMappingURL=diagnostics.js.map
package/dist/edit.d.ts ADDED
@@ -0,0 +1,234 @@
1
+ import { i as completeJsxSourceLocation, n as JsxSource, r as JsxSourceLocation, t as JSX_SOURCE_LOCATION_PROP } from "./source-locations-C8wCsiAy.js";
2
+ import { n as WhatsAppCategory, r as WhatsAppHeaderType, t as SmsCategory } from "./channel-specs-C2feJwuP.js";
3
+ //#region src/source-edit.d.ts
4
+ /** One exact source replacement; before text guards against concurrent changes. */
5
+ interface SourceReplacement {
6
+ readonly start: number;
7
+ readonly end: number;
8
+ readonly before: string;
9
+ readonly after: string;
10
+ }
11
+ type SourceEditResult = {
12
+ readonly ok: true;
13
+ readonly source: string;
14
+ } | {
15
+ readonly ok: false;
16
+ readonly reason: string;
17
+ };
18
+ interface SourceProperty {
19
+ readonly name: string;
20
+ readonly kind: "literal" | "binding" | "computed";
21
+ readonly value: string;
22
+ readonly literalType: "string" | "number" | "boolean";
23
+ readonly start: number;
24
+ readonly end: number;
25
+ readonly syntax: "attribute" | "child" | "value";
26
+ }
27
+ interface SourceElement {
28
+ readonly start: number;
29
+ readonly end: number;
30
+ readonly contentStart: number | null;
31
+ readonly contentEnd: number | null;
32
+ readonly tag: string;
33
+ readonly attributeInsertion: number;
34
+ readonly hasSpread: boolean;
35
+ readonly properties: readonly SourceProperty[];
36
+ readonly structural: boolean;
37
+ /** The JSX element sibling directly before / after this one, when both share a JSX parent. */
38
+ readonly previous: SourceRange | null;
39
+ readonly next: SourceRange | null;
40
+ }
41
+ interface SourceRange {
42
+ readonly start: number;
43
+ readonly end: number;
44
+ }
45
+ /** Resolve a renderer origin against the unchanged authored entry, never against HTML offsets. */
46
+ declare const inspectSourceElement: (source: string, file: string, origin: JsxSourceLocation) => SourceElement | null;
47
+ /** Literal controls cannot overwrite a binding or computed expression. */
48
+ declare const literalReplacement: (source: string, field: SourceProperty, value: string) => SourceReplacement | null;
49
+ /** Explicit expression changes are proposals: callers show before/after and require Apply. */
50
+ declare const expressionReplacement: (source: string, field: SourceProperty, expression: string) => SourceReplacement;
51
+ /**
52
+ * Where an edited file sits in its template project. Every edit of a template is checked against
53
+ * the static profile: one that would leave it is refused, so a visual edit can never produce a
54
+ * template the compiler rejects.
55
+ */
56
+ interface ProfileGuard {
57
+ /** The template entry the profile check reads. */
58
+ readonly entry: string;
59
+ /** The file the edit changes; the entry when omitted. A partial names itself here. */
60
+ readonly file?: string | undefined;
61
+ /** The project's other files, when the edited file is not the entry. */
62
+ readonly files?: Readonly<Record<string, string>> | undefined;
63
+ }
64
+ interface ApplyOptions {
65
+ readonly profile?: ProfileGuard | undefined;
66
+ }
67
+ /** Apply exact, nonoverlapping edits and refuse syntax damage without changing the original. */
68
+ declare const applySourceReplacements: (source: string, edits: readonly SourceReplacement[], options?: ApplyOptions) => SourceEditResult;
69
+ type SourceProposal = {
70
+ readonly ok: true;
71
+ readonly edits: readonly SourceReplacement[];
72
+ } | {
73
+ readonly ok: false;
74
+ readonly reason: string;
75
+ };
76
+ /** Structural edits name a whole authored block; loop iterations are never source nodes. */
77
+ declare const structuralReplacements: (source: string, element: SourceElement, operation: {
78
+ readonly kind: "delete";
79
+ } | {
80
+ readonly kind: "duplicate";
81
+ } | {
82
+ readonly kind: "reorder";
83
+ readonly direction: "before" | "after";
84
+ } | {
85
+ readonly kind: "insert";
86
+ readonly tsx: string;
87
+ } | {
88
+ readonly kind: "move";
89
+ readonly destination: SourceElement;
90
+ }) => readonly SourceReplacement[] | null;
91
+ interface SourceFixture {
92
+ readonly name: string;
93
+ readonly start: number;
94
+ readonly end: number;
95
+ readonly source: string;
96
+ }
97
+ /** Declared fixture values are separate source targets from body bindings and literals. */
98
+ declare const inspectSourceFixtures: (source: string) => readonly SourceFixture[];
99
+ type ClassNameOperation = {
100
+ readonly kind: "set";
101
+ readonly value: string;
102
+ } | {
103
+ readonly kind: "add";
104
+ readonly tokens: string;
105
+ } | {
106
+ readonly kind: "remove";
107
+ readonly tokens: string;
108
+ };
109
+ /**
110
+ * Edit an element's class list where it is written. A literal `className` is replaced, extended or
111
+ * trimmed in place; a missing one is added; one that is a condition or any other expression is
112
+ * refused, because rewriting it would discard the choice the author encoded.
113
+ */
114
+ declare const classNameEdit: (source: string, element: SourceElement, operation: ClassNameOperation) => SourceProposal;
115
+ //#endregion
116
+ //#region src/channel-edit.d.ts
117
+ /** A run of body text between two locked segments. It is empty when nothing sits between them. */
118
+ interface TextSegment {
119
+ readonly kind: "text";
120
+ readonly text: string;
121
+ /** The source range the text is written back over. */
122
+ readonly start: number;
123
+ readonly end: number;
124
+ }
125
+ /** An expression, conditional or element the form does not edit, kept as authored. */
126
+ interface LockedSegment {
127
+ readonly kind: "locked";
128
+ /** The authored source, shortened for display. */
129
+ readonly summary: string;
130
+ readonly start: number;
131
+ readonly end: number;
132
+ }
133
+ type ChannelSegment = TextSegment | LockedSegment;
134
+ /** How an attribute appears on an element. Only a literal is editable. */
135
+ type AttributeState = {
136
+ readonly kind: "absent";
137
+ } | {
138
+ readonly kind: "literal";
139
+ readonly value: string;
140
+ } | {
141
+ readonly kind: "expression";
142
+ readonly source: string;
143
+ };
144
+ interface SmsChannelForm {
145
+ readonly category: AttributeState;
146
+ readonly segments: readonly ChannelSegment[];
147
+ /** The input fields the body reads, as dotted paths. */
148
+ readonly variables: readonly string[];
149
+ }
150
+ type WhatsAppButtonKind = "quick-reply" | "url" | "phone" | "copy-code";
151
+ type WhatsAppButtonRow = {
152
+ readonly kind: "editable";
153
+ readonly type: WhatsAppButtonKind;
154
+ /** The label, or the copied code for a copy-code button. */
155
+ readonly text: string;
156
+ readonly url: AttributeState;
157
+ readonly phone: AttributeState;
158
+ } | {
159
+ /** A conditional, or a button whose label reads the input. */
160
+ readonly kind: "locked";
161
+ readonly summary: string;
162
+ };
163
+ interface WhatsAppChannelForm {
164
+ readonly name: AttributeState;
165
+ readonly language: AttributeState;
166
+ readonly category: AttributeState;
167
+ /** Null when the template has no header. */
168
+ readonly header: readonly ChannelSegment[] | null;
169
+ readonly headerType: AttributeState;
170
+ readonly body: readonly ChannelSegment[];
171
+ /** Null when the template has no footer. */
172
+ readonly footer: readonly ChannelSegment[] | null;
173
+ readonly buttons: readonly WhatsAppButtonRow[];
174
+ readonly variables: readonly string[];
175
+ }
176
+ type ChannelEditResult = {
177
+ readonly ok: true;
178
+ readonly edits: readonly SourceReplacement[];
179
+ } | {
180
+ readonly ok: false;
181
+ readonly reason: string;
182
+ };
183
+ type SmsEdit = {
184
+ readonly kind: "category";
185
+ readonly value: SmsCategory | undefined;
186
+ } | {
187
+ readonly kind: "text";
188
+ readonly segment: number;
189
+ readonly text: string;
190
+ };
191
+ type WhatsAppPart = "header" | "body" | "footer";
192
+ type WhatsAppEdit = {
193
+ readonly kind: "attribute";
194
+ readonly name: "name" | "language" | "category";
195
+ readonly value: string | undefined;
196
+ } | {
197
+ readonly kind: "headerType";
198
+ readonly value: WhatsAppHeaderType;
199
+ } | {
200
+ readonly kind: "text";
201
+ readonly part: WhatsAppPart;
202
+ readonly segment: number;
203
+ readonly text: string;
204
+ } | {
205
+ readonly kind: "buttonText";
206
+ readonly button: number;
207
+ readonly text: string;
208
+ } | {
209
+ readonly kind: "buttonAttribute";
210
+ readonly button: number;
211
+ readonly name: "url" | "phone";
212
+ readonly value: string;
213
+ } | {
214
+ readonly kind: "buttonType";
215
+ readonly button: number;
216
+ readonly type: WhatsAppButtonKind;
217
+ } | {
218
+ readonly kind: "buttonAdd";
219
+ readonly type: WhatsAppButtonKind;
220
+ } | {
221
+ readonly kind: "buttonRemove";
222
+ readonly button: number;
223
+ };
224
+ /** The form model of the template's SMS body, or null when it is not a `<Sms>` written in place. */
225
+ declare const readSmsChannel: (source: string) => SmsChannelForm | null;
226
+ /** The source replacements that apply one form change to the SMS body. */
227
+ declare const editSmsChannel: (source: string, edit: SmsEdit) => ChannelEditResult;
228
+ /** The form model of the template's WhatsApp body, or null when it is not a `<WhatsApp>` written in place. */
229
+ declare const readWhatsAppChannel: (source: string) => WhatsAppChannelForm | null;
230
+ /** The source replacements that apply one form change to the WhatsApp body. */
231
+ declare const editWhatsAppChannel: (source: string, edit: WhatsAppEdit) => ChannelEditResult;
232
+ //#endregion
233
+ export { ApplyOptions, AttributeState, ChannelEditResult, ChannelSegment, ClassNameOperation, JSX_SOURCE_LOCATION_PROP, JsxSource, JsxSourceLocation, LockedSegment, ProfileGuard, type SmsCategory, SmsChannelForm, SmsEdit, SourceEditResult, SourceElement, SourceFixture, SourceProperty, SourceProposal, SourceRange, SourceReplacement, TextSegment, WhatsAppButtonKind, WhatsAppButtonRow, type WhatsAppCategory, WhatsAppChannelForm, WhatsAppEdit, type WhatsAppHeaderType, WhatsAppPart, applySourceReplacements, classNameEdit, completeJsxSourceLocation, editSmsChannel, editWhatsAppChannel, expressionReplacement, inspectSourceElement, inspectSourceFixtures, literalReplacement, readSmsChannel, readWhatsAppChannel, structuralReplacements };
234
+ //# sourceMappingURL=edit.d.ts.map