@schematichq/schematic-components 2.25.2 → 2.27.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,1851 @@
1
+ // src/elements/index.ts
2
+ import {
3
+ BillingDataProvider,
4
+ SchematicI18nProvider,
5
+ useInvalidateBillingData,
6
+ useInvoices as useInvoices2,
7
+ useSchematicI18n as useSchematicI18n2,
8
+ useSchematicLocale as useSchematicLocale2,
9
+ useSchematicStrings,
10
+ useSchematicTranslate,
11
+ useUpcomingInvoice as useUpcomingInvoice2
12
+ } from "@schematichq/schematic-react";
13
+
14
+ // src/elements/model/errors.ts
15
+ function httpStatus(error) {
16
+ if (error === void 0 || error.name !== "SchematicApiError") {
17
+ return void 0;
18
+ }
19
+ const { status } = error;
20
+ return typeof status === "number" ? status : void 0;
21
+ }
22
+
23
+ // src/utils/pluralize.ts
24
+ var pluralRules = [];
25
+ var singularRules = [];
26
+ var uncountables = {};
27
+ var irregularPlurals = {};
28
+ var irregularSingles = {};
29
+ function sanitizeRule(rule) {
30
+ return typeof rule === "string" ? new RegExp("^" + rule + "$", "i") : rule;
31
+ }
32
+ function restoreCase(word, token) {
33
+ if (word === token) {
34
+ return token;
35
+ }
36
+ if (word === word.toLowerCase()) {
37
+ return token.toLowerCase();
38
+ }
39
+ if (word === word.toUpperCase()) {
40
+ return token.toUpperCase();
41
+ }
42
+ if (word[0] === word[0].toUpperCase()) {
43
+ return token.charAt(0).toUpperCase() + token.slice(1).toLowerCase();
44
+ }
45
+ return token.toLowerCase();
46
+ }
47
+ function replace(word, rule) {
48
+ return word.replace(rule[0], function(...args) {
49
+ const [match, index] = args;
50
+ const result = rule[1].replace(
51
+ /\$(\d{1,2})/g,
52
+ (match2, index2) => args[index2] || ""
53
+ );
54
+ if (match === "") {
55
+ return restoreCase(word[index - 1], result);
56
+ }
57
+ return restoreCase(match, result);
58
+ });
59
+ }
60
+ function sanitizeWord(token, word, rules) {
61
+ if (!token.length || token in uncountables) {
62
+ return word;
63
+ }
64
+ let len = rules.length;
65
+ while (len--) {
66
+ const rule = rules[len];
67
+ if (rule[0].test(word)) {
68
+ return replace(word, rule);
69
+ }
70
+ }
71
+ return word;
72
+ }
73
+ function replaceWord(replaceMap, keepMap, rules) {
74
+ return function(word) {
75
+ const token = word.toLowerCase();
76
+ if (token in keepMap) {
77
+ return restoreCase(word, token);
78
+ }
79
+ if (token in replaceMap) {
80
+ return restoreCase(word, replaceMap[token]);
81
+ }
82
+ return sanitizeWord(token, word, rules);
83
+ };
84
+ }
85
+ function checkWord(replaceMap, keepMap, rules) {
86
+ return function(word) {
87
+ const token = word.toLowerCase();
88
+ if (token in keepMap) {
89
+ return true;
90
+ }
91
+ if (token in replaceMap) {
92
+ return false;
93
+ }
94
+ return sanitizeWord(token, token, rules) === token;
95
+ };
96
+ }
97
+ function pluralize(word, count, inclusive) {
98
+ const pluralized = count === 1 ? pluralize.singular(word) : pluralize.plural(word);
99
+ return (inclusive ? count + " " : "") + pluralized;
100
+ }
101
+ pluralize.plural = replaceWord(irregularSingles, irregularPlurals, pluralRules);
102
+ pluralize.isPlural = checkWord(irregularSingles, irregularPlurals, pluralRules);
103
+ pluralize.singular = replaceWord(
104
+ irregularPlurals,
105
+ irregularSingles,
106
+ singularRules
107
+ );
108
+ pluralize.isSingular = checkWord(
109
+ irregularPlurals,
110
+ irregularSingles,
111
+ singularRules
112
+ );
113
+ pluralize.addPluralRule = function(rule, replacement) {
114
+ pluralRules.push([sanitizeRule(rule), replacement]);
115
+ };
116
+ pluralize.addSingularRule = function(rule, replacement) {
117
+ singularRules.push([sanitizeRule(rule), replacement]);
118
+ };
119
+ pluralize.addUncountableRule = function(word) {
120
+ if (typeof word === "string") {
121
+ uncountables[word.toLowerCase()] = true;
122
+ return;
123
+ }
124
+ pluralize.addPluralRule(word, "$0");
125
+ pluralize.addSingularRule(word, "$0");
126
+ };
127
+ pluralize.addIrregularRule = function(single, plural2) {
128
+ plural2 = plural2.toLowerCase();
129
+ single = single.toLowerCase();
130
+ irregularSingles[single] = plural2;
131
+ irregularPlurals[plural2] = single;
132
+ };
133
+ [
134
+ // Pronouns.
135
+ ["I", "we"],
136
+ ["me", "us"],
137
+ ["he", "they"],
138
+ ["she", "they"],
139
+ ["them", "them"],
140
+ ["myself", "ourselves"],
141
+ ["yourself", "yourselves"],
142
+ ["itself", "themselves"],
143
+ ["herself", "themselves"],
144
+ ["himself", "themselves"],
145
+ ["themself", "themselves"],
146
+ ["is", "are"],
147
+ ["was", "were"],
148
+ ["has", "have"],
149
+ ["this", "these"],
150
+ ["that", "those"],
151
+ ["my", "our"],
152
+ ["its", "their"],
153
+ ["his", "their"],
154
+ ["her", "their"],
155
+ // Words ending in with a consonant and `o`.
156
+ ["echo", "echoes"],
157
+ ["dingo", "dingoes"],
158
+ ["volcano", "volcanoes"],
159
+ ["tornado", "tornadoes"],
160
+ ["torpedo", "torpedoes"],
161
+ // Ends with `us`.
162
+ ["genus", "genera"],
163
+ ["viscus", "viscera"],
164
+ // Ends with `ma`.
165
+ ["stigma", "stigmata"],
166
+ ["stoma", "stomata"],
167
+ ["dogma", "dogmata"],
168
+ ["lemma", "lemmata"],
169
+ ["schema", "schemata"],
170
+ ["anathema", "anathemata"],
171
+ // Other irregular rules.
172
+ ["ox", "oxen"],
173
+ ["axe", "axes"],
174
+ ["die", "dice"],
175
+ ["yes", "yeses"],
176
+ ["foot", "feet"],
177
+ ["eave", "eaves"],
178
+ ["goose", "geese"],
179
+ ["tooth", "teeth"],
180
+ ["quiz", "quizzes"],
181
+ ["human", "humans"],
182
+ ["proof", "proofs"],
183
+ ["carve", "carves"],
184
+ ["valve", "valves"],
185
+ ["looey", "looies"],
186
+ ["thief", "thieves"],
187
+ ["groove", "grooves"],
188
+ ["pickaxe", "pickaxes"],
189
+ ["passerby", "passersby"],
190
+ ["canvas", "canvases"]
191
+ ].forEach(function(rule) {
192
+ return pluralize.addIrregularRule(rule[0], rule[1]);
193
+ });
194
+ [
195
+ [/s?$/i, "s"],
196
+ [/[\u0080-\uFFFF]$/i, "$0"],
197
+ [/([^aeiou]ese)$/i, "$1"],
198
+ [/(ax|test)is$/i, "$1es"],
199
+ [/(alias|[^aou]us|t[lm]as|gas|ris)$/i, "$1es"],
200
+ [/(e[mn]u)s?$/i, "$1s"],
201
+ [/([^l]ias|[aeiou]las|[ejzr]as|[iu]am)$/i, "$1"],
202
+ [
203
+ /(alumn|syllab|vir|radi|nucle|fung|cact|stimul|termin|bacill|foc|uter|loc|strat)(?:us|i)$/i,
204
+ "$1i"
205
+ ],
206
+ [/(alumn|alg|vertebr)(?:a|ae)$/i, "$1ae"],
207
+ [/(seraph|cherub)(?:im)?$/i, "$1im"],
208
+ [/(her|at|gr)o$/i, "$1oes"],
209
+ [
210
+ /(agend|addend|millenni|dat|extrem|bacteri|desiderat|strat|candelabr|errat|ov|symposi|curricul|automat|quor)(?:a|um)$/i,
211
+ "$1a"
212
+ ],
213
+ [
214
+ /(apheli|hyperbat|periheli|asyndet|noumen|phenomen|criteri|organ|prolegomen|hedr|automat)(?:a|on)$/i,
215
+ "$1a"
216
+ ],
217
+ [/sis$/i, "ses"],
218
+ [/(?:(kni|wi|li)fe|(ar|l|ea|eo|oa|hoo)f)$/i, "$1$2ves"],
219
+ [/([^aeiouy]|qu)y$/i, "$1ies"],
220
+ [/([^ch][ieo][ln])ey$/i, "$1ies"],
221
+ [/(x|ch|ss|sh|zz)$/i, "$1es"],
222
+ [/(matr|cod|mur|sil|vert|ind|append)(?:ix|ex)$/i, "$1ices"],
223
+ [/\b((?:tit)?m|l)(?:ice|ouse)$/i, "$1ice"],
224
+ [/(pe)(?:rson|ople)$/i, "$1ople"],
225
+ [/(child)(?:ren)?$/i, "$1ren"],
226
+ [/eaux$/i, "$0"],
227
+ [/m[ae]n$/i, "men"],
228
+ ["thou", "you"]
229
+ ].forEach((rule) => {
230
+ pluralize.addPluralRule(rule[0], rule[1]);
231
+ });
232
+ [
233
+ [/s$/i, ""],
234
+ [/(ss)$/i, "$1"],
235
+ [/(wi|kni|(?:after|half|high|low|mid|non|night|[^\w]|^)li)ves$/i, "$1fe"],
236
+ [/(ar|(?:wo|[ae])l|[eo][ao])ves$/i, "$1f"],
237
+ [/ies$/i, "y"],
238
+ [/(dg|ss|ois|lk|ok|wn|mb|th|ch|ec|oal|is|ck|ix|sser|ts|wb)ies$/i, "$1ie"],
239
+ [
240
+ /\b(l|(?:neck|cross|hog|aun)?t|coll|faer|food|gen|goon|group|hipp|junk|vegg|(?:pork)?p|charl|calor|cut)ies$/i,
241
+ "$1ie"
242
+ ],
243
+ [/\b(mon|smil)ies$/i, "$1ey"],
244
+ [/\b((?:tit)?m|l)ice$/i, "$1ouse"],
245
+ [/(seraph|cherub)im$/i, "$1"],
246
+ [
247
+ /(x|ch|ss|sh|zz|tto|go|cho|alias|[^aou]us|t[lm]as|gas|(?:her|at|gr)o|[aeiou]ris)(?:es)?$/i,
248
+ "$1"
249
+ ],
250
+ [
251
+ /(analy|diagno|parenthe|progno|synop|the|empha|cri|ne)(?:sis|ses)$/i,
252
+ "$1sis"
253
+ ],
254
+ [/(movie|twelve|abuse|e[mn]u)s$/i, "$1"],
255
+ [/(test)(?:is|es)$/i, "$1is"],
256
+ [
257
+ /(alumn|syllab|vir|radi|nucle|fung|cact|stimul|termin|bacill|foc|uter|loc|strat)(?:us|i)$/i,
258
+ "$1us"
259
+ ],
260
+ [
261
+ /(agend|addend|millenni|dat|extrem|bacteri|desiderat|strat|candelabr|errat|ov|symposi|curricul|quor)a$/i,
262
+ "$1um"
263
+ ],
264
+ [
265
+ /(apheli|hyperbat|periheli|asyndet|noumen|phenomen|criteri|organ|prolegomen|hedr|automat)a$/i,
266
+ "$1on"
267
+ ],
268
+ [/(alumn|alg|vertebr)ae$/i, "$1a"],
269
+ [/(cod|mur|sil|vert|ind)ices$/i, "$1ex"],
270
+ [/(matr|append)ices$/i, "$1ix"],
271
+ [/(pe)(rson|ople)$/i, "$1rson"],
272
+ [/(child)ren$/i, "$1"],
273
+ [/(eau)x?$/i, "$1"],
274
+ [/men$/i, "man"]
275
+ ].forEach((rule) => {
276
+ pluralize.addSingularRule(rule[0], rule[1]);
277
+ });
278
+ [
279
+ // Singular words with no plurals.
280
+ "adulthood",
281
+ "advice",
282
+ "agenda",
283
+ "aid",
284
+ "aircraft",
285
+ "alcohol",
286
+ "ammo",
287
+ "analytics",
288
+ "anime",
289
+ "athletics",
290
+ "audio",
291
+ "bison",
292
+ "blood",
293
+ "bream",
294
+ "buffalo",
295
+ "butter",
296
+ "carp",
297
+ "cash",
298
+ "chassis",
299
+ "chess",
300
+ "clothing",
301
+ "cod",
302
+ "commerce",
303
+ "cooperation",
304
+ "corps",
305
+ "debris",
306
+ "diabetes",
307
+ "digestion",
308
+ "elk",
309
+ "energy",
310
+ "equipment",
311
+ "excretion",
312
+ "expertise",
313
+ "firmware",
314
+ "flounder",
315
+ "fun",
316
+ "gallows",
317
+ "garbage",
318
+ "graffiti",
319
+ "hardware",
320
+ "headquarters",
321
+ "health",
322
+ "herpes",
323
+ "highjinks",
324
+ "homework",
325
+ "housework",
326
+ "information",
327
+ "jeans",
328
+ "justice",
329
+ "kudos",
330
+ "labour",
331
+ "literature",
332
+ "machinery",
333
+ "mackerel",
334
+ "mail",
335
+ "media",
336
+ "mews",
337
+ "moose",
338
+ "music",
339
+ "mud",
340
+ "manga",
341
+ "news",
342
+ "only",
343
+ "personnel",
344
+ "pike",
345
+ "plankton",
346
+ "pliers",
347
+ "police",
348
+ "pollution",
349
+ "premises",
350
+ "rain",
351
+ "research",
352
+ "rice",
353
+ "salmon",
354
+ "scissors",
355
+ "series",
356
+ "sewage",
357
+ "shambles",
358
+ "shrimp",
359
+ "software",
360
+ "staff",
361
+ "swine",
362
+ "tennis",
363
+ "traffic",
364
+ "transportation",
365
+ "trout",
366
+ "tuna",
367
+ "wealth",
368
+ "welfare",
369
+ "whiting",
370
+ "wildebeest",
371
+ "wildlife",
372
+ "you",
373
+ /pok[eé]mon$/i,
374
+ // Regexes.
375
+ /[^aeiou]ese$/i,
376
+ // "chinese", "japanese"
377
+ /deer$/i,
378
+ // "deer", "reindeer"
379
+ /fish$/i,
380
+ // "fish", "blowfish", "angelfish"
381
+ /measles$/i,
382
+ /o[iu]s$/i,
383
+ // "carnivorous"
384
+ /pox$/i,
385
+ // "chickpox", "smallpox"
386
+ /sheep$/i
387
+ ].forEach(pluralize.addUncountableRule);
388
+
389
+ // src/elements/model/format.ts
390
+ var DEFAULT_LOCALE = "en-US";
391
+ var usableLocales = /* @__PURE__ */ new Map();
392
+ var MAX_CACHED_LOCALES = 64;
393
+ function isUsableLocale(locale) {
394
+ const cached = usableLocales.get(locale);
395
+ if (cached !== void 0) {
396
+ return cached;
397
+ }
398
+ let usable = true;
399
+ try {
400
+ Intl.getCanonicalLocales(locale);
401
+ } catch {
402
+ usable = false;
403
+ }
404
+ if (usableLocales.size >= MAX_CACHED_LOCALES) {
405
+ usableLocales.clear();
406
+ }
407
+ usableLocales.set(locale, usable);
408
+ return usable;
409
+ }
410
+ function usableLocale(locale) {
411
+ return isUsableLocale(locale) ? locale : DEFAULT_LOCALE;
412
+ }
413
+ function resolveLocale(locale) {
414
+ return locale !== void 0 && locale !== "" && isUsableLocale(locale) ? locale : DEFAULT_LOCALE;
415
+ }
416
+ function viewerLocale() {
417
+ if (typeof navigator === "undefined" || navigator.language === "") {
418
+ return void 0;
419
+ }
420
+ return isUsableLocale(navigator.language) ? navigator.language : void 0;
421
+ }
422
+ var ZERO_DECIMAL_CURRENCIES = /* @__PURE__ */ new Set([
423
+ "BIF",
424
+ "CLP",
425
+ "DJF",
426
+ "GNF",
427
+ "JPY",
428
+ "KMF",
429
+ "KRW",
430
+ "MGA",
431
+ "PYG",
432
+ "RWF",
433
+ "UGX",
434
+ "VND",
435
+ "VUV",
436
+ "XAF",
437
+ "XOF",
438
+ "XPF"
439
+ ]);
440
+ var MAXIMUM_FRACTION_DIGITS = 10;
441
+ var MAXIMUM_SIGNIFICANT_DIGITS = 6;
442
+ function toMajorUnits(amountMinor, currency) {
443
+ return ZERO_DECIMAL_CURRENCIES.has(currency.toUpperCase()) ? amountMinor : amountMinor / 100;
444
+ }
445
+ function formatCurrency(amountMinor, currency, locale, options = {}) {
446
+ const resolvedCurrency = currency.toUpperCase();
447
+ const resolvedLocale = usableLocale(locale);
448
+ const { preserveSubUnitPrecision = true } = options;
449
+ const major = toMajorUnits(amountMinor, resolvedCurrency);
450
+ const hasSubUnitPrecision = preserveSubUnitPrecision && /[1-9]/.test((amountMinor % 1).toFixed(MAXIMUM_SIGNIFICANT_DIGITS));
451
+ try {
452
+ return new Intl.NumberFormat(resolvedLocale, {
453
+ style: "currency",
454
+ currency: resolvedCurrency,
455
+ ...hasSubUnitPrecision && {
456
+ minimumSignificantDigits: 1,
457
+ maximumSignificantDigits: 12
458
+ }
459
+ }).format(major);
460
+ } catch {
461
+ return `${formatNumber(major, resolvedLocale, { minimumFractionDigits: 2 })} ${resolvedCurrency}`;
462
+ }
463
+ }
464
+ function formatNumber(value, locale, options) {
465
+ return new Intl.NumberFormat(usableLocale(locale), options).format(value);
466
+ }
467
+ function formatConsumptionRate(rate, locale) {
468
+ return formatNumber(rate, locale, {
469
+ maximumFractionDigits: MAXIMUM_FRACTION_DIGITS
470
+ });
471
+ }
472
+ function formatPercent(fraction, locale) {
473
+ return new Intl.NumberFormat(usableLocale(locale), {
474
+ style: "percent",
475
+ maximumFractionDigits: 2
476
+ }).format(fraction);
477
+ }
478
+ function usableDate(date) {
479
+ if (date === null || date === void 0) {
480
+ return void 0;
481
+ }
482
+ return Number.isNaN(date.getTime()) ? void 0 : date;
483
+ }
484
+ function formatDate(date, locale, options) {
485
+ if (usableDate(date) === void 0) {
486
+ return "";
487
+ }
488
+ return new Intl.DateTimeFormat(usableLocale(locale), {
489
+ month: "long",
490
+ day: "numeric",
491
+ year: "numeric",
492
+ ...options
493
+ }).format(date);
494
+ }
495
+ function formatShortDate(date, locale) {
496
+ if (usableDate(date) === void 0) {
497
+ return "";
498
+ }
499
+ return new Intl.DateTimeFormat(usableLocale(locale), {
500
+ month: "numeric",
501
+ day: "numeric"
502
+ }).format(date);
503
+ }
504
+ function featureName(named, count = 0, locale = DEFAULT_LOCALE) {
505
+ const isOne = pluralCategory(count, locale) === "one";
506
+ const singularName = orNull(named.singularName) ?? named.name;
507
+ const pluralName = orNull(named.pluralName);
508
+ if (isOne) {
509
+ return singularName;
510
+ }
511
+ if (pluralName !== null) {
512
+ return pluralName;
513
+ }
514
+ return isEnglish(locale) ? pluralize(singularName, 2) : singularName;
515
+ }
516
+ function plural(locale, count, forms) {
517
+ return forms[pluralCategory(count, locale)] ?? forms.other;
518
+ }
519
+ function pluralCategory(count, locale) {
520
+ return new Intl.PluralRules(usableLocale(locale)).select(count);
521
+ }
522
+ function isEnglish(locale) {
523
+ return new Intl.Locale(usableLocale(locale)).language === "en";
524
+ }
525
+ function orNull(value) {
526
+ return value === void 0 || value === null || value === "" ? null : value;
527
+ }
528
+
529
+ // src/elements/model/invoices.ts
530
+ function linkableURL(url) {
531
+ if (url === void 0 || url === null || url === "") {
532
+ return null;
533
+ }
534
+ try {
535
+ const { protocol } = new URL(url);
536
+ return protocol === "http:" || protocol === "https:" ? url : null;
537
+ } catch {
538
+ return null;
539
+ }
540
+ }
541
+ function deriveInvoiceList(page, options) {
542
+ const { format, locale } = options;
543
+ return {
544
+ rows: page.invoices.map((invoice) => {
545
+ const date = usableDate(invoice.dueDate) ?? usableDate(invoice.createdAt) ?? null;
546
+ const currency = invoice.currency.toUpperCase();
547
+ return {
548
+ id: invoice.id,
549
+ date,
550
+ dateText: date === null ? "" : format?.date?.(date, locale) ?? formatDate(date, locale),
551
+ amountMinor: invoice.amountDue,
552
+ currency,
553
+ // Absolute: credit notes render in parentheses, not with a minus sign.
554
+ amountText: format?.amount?.(invoice.amountDue, currency, locale) ?? formatCurrency(Math.abs(invoice.amountDue), currency, locale, {
555
+ preserveSubUnitPrecision: false
556
+ }),
557
+ isCredit: invoice.amountDue < 0,
558
+ status: invoice.status ?? null,
559
+ url: linkableURL(invoice.url)
560
+ };
561
+ }),
562
+ count: page.count,
563
+ hasMore: page.hasMore
564
+ };
565
+ }
566
+
567
+ // src/elements/model/upcomingBill.ts
568
+ function deriveUpcomingInvoice(invoice, options) {
569
+ const { format, locale } = options;
570
+ const currency = invoice.currency.toUpperCase();
571
+ const money = (amountMinor) => format?.amount?.(amountMinor, currency, locale) ?? formatCurrency(amountMinor, currency, locale, {
572
+ preserveSubUnitPrecision: false
573
+ });
574
+ const line = (amountMinor) => ({
575
+ amountMinor,
576
+ amountText: money(amountMinor)
577
+ });
578
+ const applied = invoice.customerBalanceApplied;
579
+ const remaining = invoice.customerBalanceRemaining;
580
+ const dueDate = usableDate(invoice.dueDate) ?? null;
581
+ return {
582
+ amountDueMinor: invoice.amountDue,
583
+ amountDueText: money(invoice.amountDue),
584
+ subtotalMinor: invoice.subtotal,
585
+ subtotalText: money(invoice.subtotal),
586
+ currency,
587
+ dueAt: dueDate === null ? null : {
588
+ date: dueDate,
589
+ text: format?.date?.(dueDate, locale) ?? formatDate(dueDate, locale)
590
+ },
591
+ // A deduction: the sign is the locale's, so a host never assembles one.
592
+ balanceApplied: applied > 0 ? line(-applied) : null,
593
+ // Zero remaining is worth saying when a balance was spent; no balance at
594
+ // all is not.
595
+ balanceRemaining: applied > 0 || remaining > 0 ? line(remaining) : null,
596
+ discounts: invoice.discounts.flatMap(
597
+ (discount) => discountLine(discount, currency, locale, money)
598
+ )
599
+ };
600
+ }
601
+ function discountLine(discount, invoiceCurrency, locale, money) {
602
+ const percentOff = discount.percentOff ?? null;
603
+ const amountOff = discount.amountOff ?? null;
604
+ const isPercent = percentOff !== null && percentOff > 0;
605
+ if (!isPercent && (amountOff === null || amountOff <= 0)) {
606
+ return [];
607
+ }
608
+ const currency = discount.currency?.toUpperCase() ?? invoiceCurrency;
609
+ return [
610
+ {
611
+ couponName: discount.couponName,
612
+ code: discount.customerFacingCode ?? null,
613
+ kind: isPercent ? "percent" : "amount",
614
+ valueText: isPercent ? formatPercent(percentOff / 100, locale) : currency === invoiceCurrency ? money(amountOff ?? 0) : formatCurrency(amountOff ?? 0, currency, locale, {
615
+ preserveSubUnitPrecision: false
616
+ }),
617
+ percentOff: isPercent ? percentOff : null,
618
+ amountOffMinor: isPercent ? null : amountOff,
619
+ months: discount.duration === "repeating" ? discount.durationInMonths ?? null : null,
620
+ duration: discount.duration
621
+ }
622
+ ];
623
+ }
624
+
625
+ // src/elements/strings.ts
626
+ var DEFAULT_STRINGS_LOCALE = "en";
627
+ var DEFAULT_STRINGS = {
628
+ retry: "Try again",
629
+ invoicesLoading: "Loading invoices",
630
+ invoicesHeader: "Invoices",
631
+ invoicesError: "There was a problem retrieving your invoices.",
632
+ invoicesUnavailable: "Invoices are not available for this account.",
633
+ invoicesEmpty: "No invoices created yet",
634
+ invoicesSeeMore: "See more",
635
+ invoicesSeeLess: "See less",
636
+ invoicesLoadMore: "Load more",
637
+ invoicesChargeTooltip: "Charge \u2014 you were billed this amount",
638
+ invoicesCreditTooltip: "Credit \u2014 this amount was returned to your account, typically due to a plan change or proration",
639
+ invoicesUndated: "View invoice",
640
+ upcomingBillLoading: "Loading your next bill",
641
+ upcomingBillHeader: "Next bill due {{date}}",
642
+ upcomingBillError: "There was a problem retrieving your upcoming invoice.",
643
+ upcomingBillUnavailable: "Your upcoming invoice is not available for this account.",
644
+ upcomingBillEmpty: "No upcoming invoice",
645
+ upcomingBillEstimate: "Estimated bill",
646
+ upcomingBillBalanceApplied: "Applied balance towards next invoice",
647
+ upcomingBillBalanceRemaining: "Remaining balance after next invoice",
648
+ upcomingBillDiscount: "Discount",
649
+ upcomingBillDiscountValue: "{{value}} off",
650
+ // Looked up by the bare key with `{ count }`; English has two forms.
651
+ upcomingBillDiscountRepeating: "{{value}} off for next {{count}} months",
652
+ upcomingBillDiscountRepeating_one: "{{value}} off for next month",
653
+ upcomingBillDiscountRepeating_other: "{{value}} off for next {{count}} months"
654
+ };
655
+ var MISSING_STRING = "\0schematic:missing";
656
+ function interpolate(template, vars) {
657
+ if (vars === void 0 || !template.includes("{{")) {
658
+ return template;
659
+ }
660
+ return template.replace(/\{\{(\w+)\}\}/g, (whole, name) => {
661
+ const value = vars[name];
662
+ return value === void 0 || value === null ? whole : String(value);
663
+ });
664
+ }
665
+ function pluralCategory2(count, locale) {
666
+ try {
667
+ return new Intl.PluralRules(locale).select(count);
668
+ } catch {
669
+ return "other";
670
+ }
671
+ }
672
+ function lookup(catalog, key, vars, locale = DEFAULT_STRINGS_LOCALE) {
673
+ if (catalog === void 0) {
674
+ return void 0;
675
+ }
676
+ const count = vars?.count;
677
+ const template = typeof count === "number" ? catalog[`${key}_${pluralCategory2(count, locale)}`] ?? catalog[`${key}_other`] ?? catalog[key] : catalog[key];
678
+ return template === void 0 ? void 0 : interpolate(template, vars);
679
+ }
680
+ function defaultString(key, vars) {
681
+ return lookup(DEFAULT_STRINGS, key, vars) ?? DEFAULT_STRINGS[key] ?? key;
682
+ }
683
+
684
+ // src/elements/styles/invoices.ts
685
+ var invoicesCss = `
686
+ .schematic-invoices {
687
+ display: flex;
688
+ flex-direction: column;
689
+ }
690
+
691
+ .schematic-invoices__list {
692
+ display: flex;
693
+ flex-direction: column;
694
+ gap: calc(var(--schematic-space) / 2);
695
+ list-style: none;
696
+ margin: 0;
697
+ padding: 0;
698
+ }
699
+
700
+ .schematic-invoices__row {
701
+ align-items: center;
702
+ display: flex;
703
+ gap: var(--schematic-space);
704
+ justify-content: space-between;
705
+ }
706
+
707
+ .schematic-invoices__date {
708
+ text-align: start;
709
+ }
710
+
711
+ .schematic-invoices__link {
712
+ color: var(--schematic-accent);
713
+ text-decoration: none;
714
+ }
715
+
716
+ .schematic-invoices__link:hover {
717
+ text-decoration: underline;
718
+ }
719
+
720
+ .schematic-invoices__amount {
721
+ cursor: help;
722
+ font-variant-numeric: tabular-nums;
723
+ /* Keeps a lone amount at the end when the date is hidden. */
724
+ margin-inline-start: auto;
725
+ text-align: end;
726
+ }
727
+
728
+ .schematic-invoices__credit {
729
+ color: var(--schematic-muted);
730
+ }
731
+
732
+ .schematic-invoices__actions {
733
+ align-items: center;
734
+ display: flex;
735
+ gap: var(--schematic-space);
736
+ margin-top: var(--schematic-space);
737
+ }
738
+
739
+ .schematic-invoices__see-more {
740
+ align-items: center;
741
+ display: inline-flex;
742
+ gap: 0.375rem;
743
+ }
744
+
745
+ /* A chevron drawn from two borders. The vertical nudge lives in the
746
+ transform with the rotation so one transition carries both. */
747
+ .schematic-invoices__chevron {
748
+ border-block-end: 2px solid var(--schematic-muted);
749
+ border-inline-end: 2px solid var(--schematic-muted);
750
+ display: inline-block;
751
+ height: 0.5em;
752
+ transform: translateY(-0.125em) rotate(45deg);
753
+ transition: transform 0.15s;
754
+ width: 0.5em;
755
+ }
756
+
757
+ .schematic-invoices__see-more[aria-expanded="true"] .schematic-invoices__chevron {
758
+ transform: translateY(0.125em) rotate(-135deg);
759
+ }
760
+
761
+ .schematic-invoices__empty {
762
+ padding: calc(var(--schematic-space) / 2) 0;
763
+ }
764
+
765
+ .schematic-invoices .schematic-skeleton__cell[data-column="date"] {
766
+ width: 7rem;
767
+ }
768
+
769
+ .schematic-invoices .schematic-skeleton__cell[data-column="amount"] {
770
+ width: 4rem;
771
+ }
772
+ `;
773
+
774
+ // src/elements/styles/tokens.ts
775
+ var ld = (light, dark) => `light-dark(${light}, ${dark})`;
776
+ var SCHEMATIC_TOKENS = {
777
+ "--schematic-accent": ld("#194bfb", "#6f92ff"),
778
+ "--schematic-accent-contrast": ld("#ffffff", "#0a0a0a"),
779
+ "--schematic-background": ld("#ffffff", "#0e0e0e"),
780
+ "--schematic-border": ld(
781
+ "hsla(0, 0%, 0%, 0.125)",
782
+ "hsla(0, 0%, 100%, 0.145)"
783
+ ),
784
+ "--schematic-card-divider": ld(
785
+ "hsla(0, 0%, 0%, 0.175)",
786
+ "hsla(0, 0%, 100%, 0.2)"
787
+ ),
788
+ "--schematic-card-padding": "2.8125rem",
789
+ "--schematic-danger": ld("#d75a5c", "#ff6b6e"),
790
+ "--schematic-font-body": '"Public Sans", system-ui, sans-serif',
791
+ "--schematic-font-heading": '"Manrope", system-ui, sans-serif',
792
+ "--schematic-line-height": "1.5",
793
+ "--schematic-line-height-heading": "1.2",
794
+ "--schematic-meter-track": ld("#f2f4f7", "#26282d"),
795
+ "--schematic-muted": ld("#8a8a8a", "#a1a1a1"),
796
+ "--schematic-primary": ld("#000000", "#ffffff"),
797
+ "--schematic-primary-contrast": ld("#ffffff", "#000000"),
798
+ "--schematic-radius": "0.625rem",
799
+ // `light-dark()` takes colours only, so it is applied per shadow layer.
800
+ "--schematic-shadow": `0px 1px 20px 0px ${ld("#1018280f", "#00000099")}, 0px 1px 3px 0px ${ld("#1018281a", "#0000007a")}`,
801
+ "--schematic-space": "1rem",
802
+ "--schematic-text": ld("#000000", "#ffffff"),
803
+ "--schematic-warning": ld("#ffaa06", "#ffbb3d")
804
+ };
805
+ var BARE_TOKEN = /var\((--schematic-[a-z-]+)\)/g;
806
+ function withTokenDefaults(css) {
807
+ return css.replace(BARE_TOKEN, (_match, name) => {
808
+ const fallback = SCHEMATIC_TOKENS[name];
809
+ if (fallback === void 0) {
810
+ throw new Error(`Unknown Schematic token: ${name}`);
811
+ }
812
+ return `var(${name}, ${fallback})`;
813
+ });
814
+ }
815
+ var schematicTokensCss = `:root {
816
+ ${Object.entries(SCHEMATIC_TOKENS).map(([name, value]) => ` ${name}: ${value};`).join("\n")}
817
+ }
818
+ `;
819
+
820
+ // src/elements/styles/upcoming-bill.ts
821
+ var upcomingBillCss = `
822
+ .schematic-upcoming-bill {
823
+ display: flex;
824
+ flex-direction: column;
825
+ gap: var(--schematic-space);
826
+ }
827
+
828
+ .schematic-upcoming-bill .schematic-header {
829
+ margin-bottom: 0;
830
+ }
831
+
832
+ .schematic-upcoming-bill .schematic-header__title {
833
+ margin-bottom: 0;
834
+ }
835
+
836
+ .schematic-upcoming-bill__amount {
837
+ align-items: flex-start;
838
+ display: flex;
839
+ gap: var(--schematic-space);
840
+ justify-content: space-between;
841
+ }
842
+
843
+ .schematic-upcoming-bill__total {
844
+ font-family: var(--schematic-font-heading);
845
+ font-size: 1.8125rem;
846
+ font-variant-numeric: tabular-nums;
847
+ font-weight: 800;
848
+ line-height: 1;
849
+ }
850
+
851
+ .schematic-upcoming-bill__estimate {
852
+ font-weight: 600;
853
+ max-width: 10rem;
854
+ text-align: end;
855
+ }
856
+
857
+ .schematic-upcoming-bill__rows {
858
+ display: flex;
859
+ flex-direction: column;
860
+ gap: var(--schematic-space);
861
+ }
862
+
863
+ .schematic-upcoming-bill .schematic-row__value {
864
+ font-variant-numeric: tabular-nums;
865
+ }
866
+
867
+ .schematic-upcoming-bill__discounts {
868
+ align-items: flex-end;
869
+ display: flex;
870
+ flex-direction: column;
871
+ gap: calc(var(--schematic-space) / 2);
872
+ list-style: none;
873
+ margin: 0;
874
+ padding: 0;
875
+ }
876
+
877
+ .schematic-upcoming-bill__discount {
878
+ align-items: center;
879
+ display: inline-flex;
880
+ gap: calc(var(--schematic-space) / 2);
881
+ }
882
+
883
+ .schematic-upcoming-bill__empty {
884
+ padding: calc(var(--schematic-space) / 2) 0;
885
+ }
886
+
887
+ .schematic-upcoming-bill .schematic-skeleton__cell[data-column="amount"] {
888
+ height: 1.8125rem;
889
+ width: 7rem;
890
+ }
891
+
892
+ .schematic-upcoming-bill .schematic-skeleton__cell[data-column="row"] {
893
+ width: 12rem;
894
+ }
895
+ `;
896
+
897
+ // src/elements/styles/index.tsx
898
+ import { jsx } from "react/jsx-runtime";
899
+ var rulesCss = `
900
+ :where([class^="schematic-"]) {
901
+ box-sizing: border-box;
902
+ color: var(--schematic-text);
903
+ font-family: var(--schematic-font-body);
904
+ line-height: var(--schematic-line-height);
905
+ }
906
+
907
+ :where([class^="schematic-"]) *,
908
+ :where([class^="schematic-"]) *::before,
909
+ :where([class^="schematic-"]) *::after {
910
+ box-sizing: inherit;
911
+ }
912
+
913
+ :where([class^="schematic-"]) p {
914
+ margin: 0;
915
+ }
916
+
917
+ .schematic-card {
918
+ background: var(--schematic-background);
919
+ border-radius: var(--schematic-radius);
920
+ box-shadow: var(--schematic-shadow);
921
+ color: var(--schematic-text);
922
+ padding: calc(var(--schematic-card-padding) * 0.75)
923
+ var(--schematic-card-padding);
924
+ }
925
+
926
+ .schematic-muted {
927
+ color: var(--schematic-muted);
928
+ }
929
+
930
+ .schematic-small {
931
+ font-size: 0.875rem;
932
+ }
933
+
934
+ .schematic-status {
935
+ align-items: center;
936
+ display: flex;
937
+ gap: var(--schematic-space);
938
+ }
939
+
940
+ /* The message may run long; the action beside it stays one line. */
941
+ .schematic-status__retry {
942
+ flex-shrink: 0;
943
+ white-space: nowrap;
944
+ }
945
+
946
+ /* Visually hidden, still read by assistive technology. */
947
+ .schematic-hidden {
948
+ border: 0;
949
+ clip-path: inset(50%);
950
+ height: 1px;
951
+ overflow: hidden;
952
+ padding: 0;
953
+ position: absolute;
954
+ white-space: nowrap;
955
+ width: 1px;
956
+ }
957
+
958
+ .schematic-skeleton {
959
+ animation: schematic-pulse 1.2s ease-in-out infinite;
960
+ display: flex;
961
+ flex-direction: column;
962
+ gap: calc(var(--schematic-space) * 0.75);
963
+ }
964
+
965
+ .schematic-skeleton:empty {
966
+ background: var(--schematic-meter-track);
967
+ border-radius: var(--schematic-radius);
968
+ min-height: 6rem;
969
+ }
970
+
971
+ .schematic-skeleton__heading,
972
+ .schematic-skeleton__cell {
973
+ background: var(--schematic-meter-track);
974
+ border-radius: calc(var(--schematic-radius) / 2);
975
+ }
976
+
977
+ .schematic-skeleton__heading {
978
+ height: 1.25rem;
979
+ margin-bottom: calc(var(--schematic-space) * 0.75);
980
+ width: 8rem;
981
+ }
982
+
983
+ .schematic-skeleton__row {
984
+ align-items: center;
985
+ display: flex;
986
+ gap: var(--schematic-space);
987
+ justify-content: space-between;
988
+ }
989
+
990
+ .schematic-skeleton__cell {
991
+ height: 1rem;
992
+ }
993
+
994
+ @keyframes schematic-pulse {
995
+ 0%,
996
+ 100% {
997
+ opacity: 1;
998
+ }
999
+ 50% {
1000
+ opacity: 0.5;
1001
+ }
1002
+ }
1003
+
1004
+ @media (prefers-reduced-motion: reduce) {
1005
+ .schematic-skeleton {
1006
+ animation: none;
1007
+ }
1008
+ }
1009
+
1010
+ .schematic-error {
1011
+ color: var(--schematic-danger);
1012
+ }
1013
+
1014
+ .schematic-status-note {
1015
+ font-size: 0.875rem;
1016
+ margin-top: var(--schematic-space);
1017
+ }
1018
+
1019
+ .schematic-cta {
1020
+ align-items: center;
1021
+ background: var(--schematic-primary);
1022
+ border: 1px solid var(--schematic-primary);
1023
+ border-radius: 0.5rem;
1024
+ color: var(--schematic-primary-contrast);
1025
+ cursor: pointer;
1026
+ display: inline-flex;
1027
+ font-family: var(--schematic-font-body);
1028
+ font-size: 1.0625rem;
1029
+ font-weight: 500;
1030
+ justify-content: center;
1031
+ line-height: 1;
1032
+ min-height: 3.25rem;
1033
+ padding: 0.5rem 1.5rem;
1034
+ text-decoration: none;
1035
+ transition: background-color 0.1s, border-color 0.1s;
1036
+ }
1037
+
1038
+ .schematic-cta:hover:not(:disabled) {
1039
+ background: color-mix(
1040
+ in srgb,
1041
+ var(--schematic-primary) 85%,
1042
+ var(--schematic-primary-contrast)
1043
+ );
1044
+ border-color: color-mix(
1045
+ in srgb,
1046
+ var(--schematic-primary) 85%,
1047
+ var(--schematic-primary-contrast)
1048
+ );
1049
+ }
1050
+
1051
+ .schematic-cta:focus-visible,
1052
+ .schematic-link-button:focus-visible {
1053
+ outline: 2px solid var(--schematic-accent);
1054
+ outline-offset: 2px;
1055
+ }
1056
+
1057
+ .schematic-cta:disabled {
1058
+ background: var(--schematic-meter-track);
1059
+ border-color: var(--schematic-meter-track);
1060
+ color: var(--schematic-muted);
1061
+ cursor: not-allowed;
1062
+ }
1063
+
1064
+ .schematic-cta--outline {
1065
+ background: transparent;
1066
+ color: var(--schematic-text);
1067
+ }
1068
+
1069
+ .schematic-cta--outline:hover:not(:disabled) {
1070
+ background: color-mix(in srgb, var(--schematic-primary) 10%, transparent);
1071
+ border-color: var(--schematic-primary);
1072
+ }
1073
+
1074
+ .schematic-cta--small {
1075
+ font-size: 0.9375rem;
1076
+ min-height: 2.5rem;
1077
+ padding: 0.375rem 1rem;
1078
+ }
1079
+
1080
+ .schematic-link-button {
1081
+ background: none;
1082
+ border: none;
1083
+ color: var(--schematic-accent);
1084
+ cursor: pointer;
1085
+ font-family: var(--schematic-font-body);
1086
+ font-size: 1rem;
1087
+ padding: 0;
1088
+ }
1089
+
1090
+ .schematic-link-button:hover {
1091
+ text-decoration: underline;
1092
+ }
1093
+
1094
+ .schematic-icon {
1095
+ align-items: center;
1096
+ background: color-mix(
1097
+ in oklch,
1098
+ var(--schematic-background) 87.5%,
1099
+ var(--schematic-text)
1100
+ );
1101
+ border-radius: 9999px;
1102
+ color: var(--schematic-primary);
1103
+ display: inline-flex;
1104
+ flex-shrink: 0;
1105
+ font-size: 1.5rem;
1106
+ font-style: normal;
1107
+ height: 2.75rem;
1108
+ justify-content: center;
1109
+ line-height: 1;
1110
+ width: 2.75rem;
1111
+ }
1112
+
1113
+ .schematic-icon--bare {
1114
+ background: none;
1115
+ font-size: 1.25rem;
1116
+ height: auto;
1117
+ width: auto;
1118
+ }
1119
+
1120
+ .schematic-meter {
1121
+ background: var(--schematic-meter-track);
1122
+ border-radius: 9999px;
1123
+ height: 0.5rem;
1124
+ overflow: hidden;
1125
+ width: 100%;
1126
+ }
1127
+
1128
+ .schematic-meter__fill {
1129
+ background: var(--schematic-accent);
1130
+ border-radius: 9999px;
1131
+ height: 100%;
1132
+ }
1133
+
1134
+ .schematic-meter--warning .schematic-meter__fill {
1135
+ background: var(--schematic-warning);
1136
+ }
1137
+
1138
+ .schematic-meter--over .schematic-meter__fill {
1139
+ background: var(--schematic-danger);
1140
+ }
1141
+
1142
+ .schematic-notice {
1143
+ border: 1px solid var(--schematic-border);
1144
+ border-inline-start: 4px solid var(--schematic-accent);
1145
+ border-radius: var(--schematic-radius);
1146
+ padding: calc(var(--schematic-space) / 2) var(--schematic-space);
1147
+ }
1148
+
1149
+ .schematic-notice--warning {
1150
+ border-inline-start-color: var(--schematic-warning);
1151
+ }
1152
+
1153
+ .schematic-notice--danger {
1154
+ border-inline-start-color: var(--schematic-danger);
1155
+ }
1156
+
1157
+ .schematic-notice a {
1158
+ color: var(--schematic-accent);
1159
+ }
1160
+
1161
+ .schematic-toggle {
1162
+ border: 1px solid var(--schematic-border);
1163
+ border-radius: 2.5rem;
1164
+ display: inline-flex;
1165
+ }
1166
+
1167
+ .schematic-toggle button {
1168
+ background: none;
1169
+ border: none;
1170
+ border-radius: 2.5rem;
1171
+ color: var(--schematic-text);
1172
+ cursor: pointer;
1173
+ font-family: var(--schematic-font-body);
1174
+ font-size: 0.9375rem;
1175
+ font-weight: 400;
1176
+ line-height: var(--schematic-line-height);
1177
+ margin: -1px;
1178
+ padding: 0.4375rem 1.25rem;
1179
+ white-space: nowrap;
1180
+ }
1181
+
1182
+ .schematic-toggle button[aria-pressed="true"] {
1183
+ background: var(--schematic-border);
1184
+ font-weight: 600;
1185
+ }
1186
+
1187
+ .schematic-select {
1188
+ background: var(--schematic-background);
1189
+ border: 1px solid var(--schematic-border);
1190
+ border-radius: 0.5rem;
1191
+ color: var(--schematic-text);
1192
+ font-family: var(--schematic-font-body);
1193
+ padding: 0.375rem 0.625rem;
1194
+ }
1195
+
1196
+ .schematic-header {
1197
+ align-items: baseline;
1198
+ display: flex;
1199
+ gap: var(--schematic-space);
1200
+ justify-content: space-between;
1201
+ margin-bottom: var(--schematic-space);
1202
+ }
1203
+
1204
+ .schematic-header__title {
1205
+ font-family: var(--schematic-font-heading);
1206
+ font-size: 1.25rem;
1207
+ font-weight: 600;
1208
+ line-height: var(--schematic-line-height-heading);
1209
+ margin: 0 0 calc(var(--schematic-space) / 2);
1210
+ }
1211
+
1212
+ /* A label on the left, its value on the right. */
1213
+ .schematic-row {
1214
+ align-items: flex-start;
1215
+ display: flex;
1216
+ gap: var(--schematic-space);
1217
+ justify-content: space-between;
1218
+ }
1219
+
1220
+ .schematic-row__label {
1221
+ font-weight: 600;
1222
+ }
1223
+
1224
+ .schematic-row__value {
1225
+ text-align: end;
1226
+ }
1227
+
1228
+ .schematic-feature-list {
1229
+ display: flex;
1230
+ flex-direction: column;
1231
+ gap: var(--schematic-space);
1232
+ list-style: none;
1233
+ margin: 0;
1234
+ padding: 0;
1235
+ }
1236
+
1237
+ .schematic-feature {
1238
+ display: flex;
1239
+ flex-direction: column;
1240
+ gap: calc(var(--schematic-space) / 2);
1241
+ }
1242
+
1243
+ .schematic-feature__row {
1244
+ align-items: center;
1245
+ display: flex;
1246
+ gap: var(--schematic-space);
1247
+ }
1248
+
1249
+ .schematic-feature__name {
1250
+ flex-grow: 1;
1251
+ font-weight: 500;
1252
+ }
1253
+
1254
+ .schematic-feature__detail {
1255
+ text-align: end;
1256
+ }
1257
+
1258
+ .schematic-feature__description {
1259
+ color: var(--schematic-muted);
1260
+ font-size: 0.875rem;
1261
+ }
1262
+
1263
+ .schematic-feature__actions {
1264
+ display: flex;
1265
+ justify-content: flex-end;
1266
+ }
1267
+
1268
+ .schematic-badge {
1269
+ background: var(--schematic-primary);
1270
+ border-radius: 9999px;
1271
+ color: var(--schematic-primary-contrast);
1272
+ display: inline-block;
1273
+ font-size: 0.75rem;
1274
+ padding: 0.125rem 0.85rem;
1275
+ }
1276
+
1277
+ .schematic-chip {
1278
+ border: 1px solid var(--schematic-border);
1279
+ border-radius: 0.3125rem;
1280
+ font-size: 0.75rem;
1281
+ padding: 0.1875rem 0.375rem;
1282
+ text-transform: uppercase;
1283
+ }
1284
+
1285
+ .schematic-pricing-table {
1286
+ display: flex;
1287
+ flex-direction: column;
1288
+ gap: calc(var(--schematic-space) * 2);
1289
+ }
1290
+
1291
+ .schematic-pricing-table__controls {
1292
+ align-items: center;
1293
+ display: flex;
1294
+ gap: 0.75rem;
1295
+ margin-inline-start: auto;
1296
+ }
1297
+
1298
+ .schematic-pricing-table__plans {
1299
+ display: grid;
1300
+ gap: var(--schematic-space);
1301
+ grid-template-columns: repeat(auto-fill, minmax(300px, 1fr));
1302
+ }
1303
+
1304
+ .schematic-plan-card {
1305
+ display: flex;
1306
+ flex-direction: column;
1307
+ padding: var(--schematic-card-padding) 0;
1308
+ position: relative;
1309
+ }
1310
+
1311
+ .schematic-plan-card--active {
1312
+ outline: 2px solid var(--schematic-primary);
1313
+ }
1314
+
1315
+ .schematic-plan-card__header {
1316
+ border-bottom: 1px solid var(--schematic-card-divider);
1317
+ display: flex;
1318
+ flex-direction: column;
1319
+ gap: 0.75rem;
1320
+ padding: 0 var(--schematic-card-padding)
1321
+ calc(var(--schematic-card-padding) * 0.75);
1322
+ }
1323
+
1324
+ .schematic-plan-card__header h3 {
1325
+ align-items: center;
1326
+ display: flex;
1327
+ font-size: 1.8125rem;
1328
+ font-weight: 800;
1329
+ gap: 0.5rem;
1330
+ margin: 0;
1331
+ }
1332
+
1333
+ .schematic-plan-card__description {
1334
+ min-height: 1.5em;
1335
+ }
1336
+
1337
+ .schematic-plan-card__price {
1338
+ font-family: var(--schematic-font-heading);
1339
+ font-size: 1.8125rem;
1340
+ font-weight: 800;
1341
+ line-height: var(--schematic-line-height-heading);
1342
+ }
1343
+
1344
+ .schematic-plan-card__price sub {
1345
+ font-family: var(--schematic-font-body);
1346
+ font-size: 0.875rem;
1347
+ font-weight: 400;
1348
+ vertical-align: baseline;
1349
+ }
1350
+
1351
+ .schematic-plan-card__badge {
1352
+ position: absolute;
1353
+ inset-inline-end: var(--schematic-space);
1354
+ top: var(--schematic-space);
1355
+ }
1356
+
1357
+ .schematic-plan-card__body {
1358
+ display: flex;
1359
+ flex-direction: column;
1360
+ flex-grow: 1;
1361
+ gap: var(--schematic-card-padding);
1362
+ justify-content: end;
1363
+ padding: calc(var(--schematic-card-padding) * 0.75)
1364
+ var(--schematic-card-padding) 0;
1365
+ }
1366
+
1367
+ .schematic-plan-card__entitlements {
1368
+ display: flex;
1369
+ flex-direction: column;
1370
+ gap: var(--schematic-space);
1371
+ list-style: none;
1372
+ margin: 0;
1373
+ padding: 0;
1374
+ }
1375
+
1376
+ .schematic-plan-card__entitlements li {
1377
+ align-items: center;
1378
+ display: flex;
1379
+ gap: var(--schematic-space);
1380
+ }
1381
+
1382
+ .schematic-plan-card__inclusion {
1383
+ margin-bottom: calc(var(--schematic-space) / 2);
1384
+ }
1385
+
1386
+ .schematic-plan-card__detail {
1387
+ display: block;
1388
+ font-size: 0.875rem;
1389
+ }
1390
+
1391
+ .schematic-plan-card__show-all {
1392
+ margin-top: var(--schematic-space);
1393
+ }
1394
+
1395
+ .schematic-plan-card__current {
1396
+ align-items: center;
1397
+ display: flex;
1398
+ gap: 0.25rem;
1399
+ justify-content: center;
1400
+ padding: 0.625rem 0;
1401
+ }
1402
+
1403
+ .schematic-plan-card__action {
1404
+ display: flex;
1405
+ flex-direction: column;
1406
+ gap: calc(var(--schematic-space) / 2);
1407
+ }
1408
+
1409
+ .schematic-plan-card .schematic-cta {
1410
+ width: 100%;
1411
+ }
1412
+
1413
+ ${invoicesCss}
1414
+ ${upcomingBillCss}
1415
+ `;
1416
+ var schematicStylesCss = withTokenDefaults(rulesCss);
1417
+ var SchematicStyles = () => /* @__PURE__ */ jsx("style", { "data-schematic-styles": "", children: schematicStylesCss });
1418
+
1419
+ // src/elements/Invoices.tsx
1420
+ import { useInvoices } from "@schematichq/schematic-react";
1421
+ import { useId, useMemo, useState } from "react";
1422
+
1423
+ // src/elements/common.tsx
1424
+ import {
1425
+ useSchematicI18n,
1426
+ useSchematicLocale
1427
+ } from "@schematichq/schematic-react";
1428
+ import { useCallback, useEffect, useSyncExternalStore } from "react";
1429
+ import { jsx as jsx2, jsxs } from "react/jsx-runtime";
1430
+ var cx = (...names) => names.filter((name) => typeof name === "string" && name !== "").join(" ");
1431
+ function billingResources(...elements) {
1432
+ const names = [];
1433
+ for (const element of elements) {
1434
+ for (const name of element.resources) {
1435
+ if (!names.includes(name)) {
1436
+ names.push(name);
1437
+ }
1438
+ }
1439
+ }
1440
+ return names;
1441
+ }
1442
+ function useResolvedLocale(locale) {
1443
+ const configured = useSchematicLocale();
1444
+ const viewer = useSyncExternalStore(
1445
+ subscribeToNothing,
1446
+ viewerLocale,
1447
+ noViewerLocale
1448
+ );
1449
+ return resolveLocale(locale ?? configured ?? viewer);
1450
+ }
1451
+ var subscribeToNothing = () => () => {
1452
+ };
1453
+ var noViewerLocale = () => void 0;
1454
+ function useTranslator(overrides, locale) {
1455
+ const resolved = useResolvedLocale(locale);
1456
+ const { onMissingString, strings, translate } = useSchematicI18n();
1457
+ return useCallback(
1458
+ (key, vars) => {
1459
+ const override = lookup(overrides, key, vars, resolved) ?? lookup(strings, key, vars, resolved);
1460
+ if (override !== void 0) {
1461
+ return override;
1462
+ }
1463
+ const fallback = defaultString(key, vars);
1464
+ if (translate === void 0) {
1465
+ return fallback;
1466
+ }
1467
+ const translated = translate(key, {
1468
+ ...vars,
1469
+ defaultValue: MISSING_STRING
1470
+ });
1471
+ if (translated === void 0 || translated === MISSING_STRING || translated === key) {
1472
+ onMissingString?.(key);
1473
+ return fallback;
1474
+ }
1475
+ return translated;
1476
+ },
1477
+ [onMissingString, overrides, resolved, strings, translate]
1478
+ );
1479
+ }
1480
+ var isDevelopment = (() => {
1481
+ try {
1482
+ return process.env.NODE_ENV !== "production";
1483
+ } catch {
1484
+ return false;
1485
+ }
1486
+ })();
1487
+ function useReportHiddenError(error, errorMessage) {
1488
+ useEffect(() => {
1489
+ if (isDevelopment && error !== void 0 && errorMessage !== void 0) {
1490
+ console.error(`Schematic: ${errorMessage}`, error);
1491
+ }
1492
+ }, [error, errorMessage]);
1493
+ }
1494
+ var StatusFrame = ({
1495
+ children,
1496
+ className,
1497
+ error,
1498
+ errorMessage,
1499
+ hasData,
1500
+ isPending,
1501
+ loadingLabel,
1502
+ onRetry,
1503
+ retryText,
1504
+ skeleton = /* @__PURE__ */ jsx2("div", { className: "schematic-skeleton" })
1505
+ }) => {
1506
+ useReportHiddenError(error, errorMessage);
1507
+ if (error !== void 0 && !hasData) {
1508
+ return /* @__PURE__ */ jsx2("div", { className, "data-state": "error", children: /* @__PURE__ */ jsxs("div", { className: "schematic-status", role: "alert", children: [
1509
+ /* @__PURE__ */ jsx2("span", { className: "schematic-error schematic-status__message", children: errorMessage ?? error.message }),
1510
+ onRetry !== void 0 && /* @__PURE__ */ jsx2(
1511
+ "button",
1512
+ {
1513
+ className: "schematic-link-button schematic-status__retry",
1514
+ type: "button",
1515
+ onClick: onRetry,
1516
+ children: retryText
1517
+ }
1518
+ )
1519
+ ] }) });
1520
+ }
1521
+ if (isPending && !hasData) {
1522
+ return /* @__PURE__ */ jsxs("div", { "aria-busy": "true", className, "data-state": "pending", children: [
1523
+ /* @__PURE__ */ jsx2("span", { className: "schematic-hidden", children: loadingLabel }),
1524
+ skeleton
1525
+ ] });
1526
+ }
1527
+ return /* @__PURE__ */ jsxs("div", { className, "data-state": "ready", children: [
1528
+ children,
1529
+ error !== void 0 && /* @__PURE__ */ jsx2("p", { className: "schematic-status-note schematic-error", role: "alert", children: errorMessage ?? error.message })
1530
+ ] });
1531
+ };
1532
+
1533
+ // src/elements/Invoices.tsx
1534
+ import { Fragment, jsx as jsx3, jsxs as jsxs2 } from "react/jsx-runtime";
1535
+ var SKELETON_ROWS = 4;
1536
+ function Invoices({
1537
+ className,
1538
+ collapsible = true,
1539
+ headingLevel = 2,
1540
+ limit = 10,
1541
+ locale: localeProp,
1542
+ query,
1543
+ showAmount = true,
1544
+ showDate = true,
1545
+ showHeader = true,
1546
+ strings
1547
+ }) {
1548
+ const {
1549
+ data: page,
1550
+ error,
1551
+ isPending,
1552
+ loadMore,
1553
+ refetch
1554
+ } = useInvoices(query);
1555
+ const locale = useResolvedLocale(localeProp);
1556
+ const t = useTranslator(strings, localeProp);
1557
+ const [expanded, setExpanded] = useState(false);
1558
+ const list = useMemo(
1559
+ () => page === void 0 ? void 0 : deriveInvoiceList(page, { locale }),
1560
+ [locale, page]
1561
+ );
1562
+ const headingId = useId();
1563
+ const rows = list?.rows ?? [];
1564
+ const canCollapse = collapsible && rows.length > limit;
1565
+ const showingAll = !canCollapse || expanded;
1566
+ const visible = showingAll ? rows : rows.slice(0, limit);
1567
+ const Heading = `h${headingLevel}`;
1568
+ const columns = [].concat(
1569
+ showDate ? "date" : [],
1570
+ showAmount ? "amount" : []
1571
+ );
1572
+ const unavailable = list === void 0 && httpStatus(error) === 404;
1573
+ const errorMessage = error === void 0 ? void 0 : unavailable ? t("invoicesUnavailable") : t("invoicesError");
1574
+ return /* @__PURE__ */ jsx3(
1575
+ StatusFrame,
1576
+ {
1577
+ className: cx("schematic-card", "schematic-invoices", className),
1578
+ error,
1579
+ errorMessage,
1580
+ hasData: list !== void 0,
1581
+ isPending,
1582
+ loadingLabel: t("invoicesLoading"),
1583
+ onRetry: refetch,
1584
+ retryText: t("retry"),
1585
+ skeleton: /* @__PURE__ */ jsx3(
1586
+ InvoicesSkeleton,
1587
+ {
1588
+ columns,
1589
+ rows: Math.max(1, Math.min(limit, SKELETON_ROWS)),
1590
+ showHeader
1591
+ }
1592
+ ),
1593
+ children: list !== void 0 && /* @__PURE__ */ jsxs2(Fragment, { children: [
1594
+ showHeader && /* @__PURE__ */ jsx3("div", { className: "schematic-header", children: /* @__PURE__ */ jsx3(Heading, { className: "schematic-header__title", id: headingId, children: t("invoicesHeader") }) }),
1595
+ rows.length === 0 ? /* @__PURE__ */ jsx3("p", { className: "schematic-muted schematic-invoices__empty", children: t("invoicesEmpty") }) : /* @__PURE__ */ jsx3(
1596
+ "ul",
1597
+ {
1598
+ className: "schematic-invoices__list",
1599
+ "aria-label": showHeader ? void 0 : t("invoicesHeader"),
1600
+ "aria-labelledby": showHeader ? headingId : void 0,
1601
+ children: visible.map((row) => /* @__PURE__ */ jsxs2(
1602
+ "li",
1603
+ {
1604
+ className: "schematic-invoices__row",
1605
+ "data-testid": "schematic-invoice",
1606
+ children: [
1607
+ showDate && /* @__PURE__ */ jsx3("span", { className: "schematic-invoices__date", children: /* @__PURE__ */ jsx3(InvoiceDate, { row, t }) }),
1608
+ showAmount && /* @__PURE__ */ jsx3(
1609
+ "span",
1610
+ {
1611
+ className: cx(
1612
+ "schematic-invoices__amount",
1613
+ row.isCredit && "schematic-invoices__credit"
1614
+ ),
1615
+ title: row.isCredit ? t("invoicesCreditTooltip") : t("invoicesChargeTooltip"),
1616
+ children: row.isCredit ? `(${row.amountText})` : row.amountText
1617
+ }
1618
+ )
1619
+ ]
1620
+ },
1621
+ row.id
1622
+ ))
1623
+ }
1624
+ ),
1625
+ (canCollapse || showingAll && list.hasMore) && /* @__PURE__ */ jsxs2("div", { className: "schematic-invoices__actions", children: [
1626
+ canCollapse && /* @__PURE__ */ jsxs2(
1627
+ "button",
1628
+ {
1629
+ "aria-expanded": expanded,
1630
+ className: "schematic-link-button schematic-invoices__see-more",
1631
+ type: "button",
1632
+ onClick: () => setExpanded((value) => !value),
1633
+ children: [
1634
+ /* @__PURE__ */ jsx3(
1635
+ "span",
1636
+ {
1637
+ "aria-hidden": "true",
1638
+ className: "schematic-invoices__chevron"
1639
+ }
1640
+ ),
1641
+ expanded ? t("invoicesSeeLess") : t("invoicesSeeMore")
1642
+ ]
1643
+ }
1644
+ ),
1645
+ showingAll && list.hasMore && /* @__PURE__ */ jsx3(
1646
+ "button",
1647
+ {
1648
+ className: "schematic-link-button schematic-invoices__load-more",
1649
+ disabled: isPending,
1650
+ type: "button",
1651
+ onClick: () => {
1652
+ setExpanded(true);
1653
+ void loadMore();
1654
+ },
1655
+ children: t("invoicesLoadMore")
1656
+ }
1657
+ )
1658
+ ] })
1659
+ ] })
1660
+ }
1661
+ );
1662
+ }
1663
+ function InvoicesSkeleton({
1664
+ columns,
1665
+ rows,
1666
+ showHeader
1667
+ }) {
1668
+ return /* @__PURE__ */ jsxs2("div", { className: "schematic-skeleton", children: [
1669
+ showHeader && /* @__PURE__ */ jsx3("div", { className: "schematic-skeleton__heading" }),
1670
+ Array.from({ length: rows }, (_, row) => /* @__PURE__ */ jsx3("div", { className: "schematic-skeleton__row", children: columns.map((column) => /* @__PURE__ */ jsx3(
1671
+ "div",
1672
+ {
1673
+ className: "schematic-skeleton__cell",
1674
+ "data-column": column
1675
+ },
1676
+ column
1677
+ )) }, row))
1678
+ ] });
1679
+ }
1680
+ function InvoiceDate({ row, t }) {
1681
+ if (row.url === null) {
1682
+ return /* @__PURE__ */ jsx3("span", { className: "schematic-invoices__date-text", children: row.dateText });
1683
+ }
1684
+ const label = row.dateText === "" ? t("invoicesUndated") : row.dateText;
1685
+ return /* @__PURE__ */ jsx3(
1686
+ "a",
1687
+ {
1688
+ className: "schematic-invoices__link",
1689
+ href: row.url,
1690
+ rel: "noreferrer",
1691
+ target: "_blank",
1692
+ children: label
1693
+ }
1694
+ );
1695
+ }
1696
+ Invoices.resources = ["invoices"];
1697
+
1698
+ // src/elements/UpcomingBill.tsx
1699
+ import { useUpcomingInvoice } from "@schematichq/schematic-react";
1700
+ import { useMemo as useMemo2 } from "react";
1701
+ import { Fragment as Fragment2, jsx as jsx4, jsxs as jsxs3 } from "react/jsx-runtime";
1702
+ function UpcomingBill({
1703
+ className,
1704
+ headingLevel = 2,
1705
+ locale: localeProp,
1706
+ showAmount = true,
1707
+ showBalance = true,
1708
+ showDiscounts = true,
1709
+ showHeader = true,
1710
+ strings
1711
+ }) {
1712
+ const { data: invoice, error, isPending, refetch } = useUpcomingInvoice();
1713
+ const locale = useResolvedLocale(localeProp);
1714
+ const t = useTranslator(strings, localeProp);
1715
+ const bill = useMemo2(
1716
+ () => invoice === void 0 || invoice === null ? null : deriveUpcomingInvoice(invoice, { locale }),
1717
+ [invoice, locale]
1718
+ );
1719
+ const Heading = `h${headingLevel}`;
1720
+ const balanceRows = showBalance && bill !== null && (bill.balanceApplied !== null || bill.balanceRemaining !== null);
1721
+ const discountRow = showDiscounts && bill !== null && bill.discounts.length > 0;
1722
+ const unavailable = invoice === void 0 && httpStatus(error) === 404;
1723
+ const errorMessage = error === void 0 ? void 0 : unavailable ? t("upcomingBillUnavailable") : t("upcomingBillError");
1724
+ return /* @__PURE__ */ jsx4(
1725
+ StatusFrame,
1726
+ {
1727
+ className: cx("schematic-card", "schematic-upcoming-bill", className),
1728
+ error,
1729
+ errorMessage,
1730
+ hasData: invoice !== void 0,
1731
+ isPending,
1732
+ loadingLabel: t("upcomingBillLoading"),
1733
+ onRetry: refetch,
1734
+ retryText: t("retry"),
1735
+ skeleton: /* @__PURE__ */ jsx4(UpcomingBillSkeleton, { showHeader }),
1736
+ children: bill === null ? invoice !== void 0 && /* @__PURE__ */ jsx4("p", { className: "schematic-muted schematic-upcoming-bill__empty", children: t("upcomingBillEmpty") }) : /* @__PURE__ */ jsxs3(Fragment2, { children: [
1737
+ showHeader && bill.dueAt !== null && /* @__PURE__ */ jsx4("div", { className: "schematic-header", children: /* @__PURE__ */ jsx4(Heading, { className: "schematic-header__title", children: t("upcomingBillHeader", { date: bill.dueAt.text }) }) }),
1738
+ showAmount && /* @__PURE__ */ jsxs3("div", { className: "schematic-upcoming-bill__amount", children: [
1739
+ /* @__PURE__ */ jsx4(
1740
+ "span",
1741
+ {
1742
+ className: "schematic-upcoming-bill__total",
1743
+ "data-testid": "schematic-upcoming-total",
1744
+ children: bill.amountDueText
1745
+ }
1746
+ ),
1747
+ /* @__PURE__ */ jsx4("span", { className: "schematic-small schematic-upcoming-bill__estimate", children: t("upcomingBillEstimate") })
1748
+ ] }),
1749
+ (balanceRows || discountRow) && /* @__PURE__ */ jsxs3("div", { className: "schematic-upcoming-bill__rows", children: [
1750
+ balanceRows && bill.balanceApplied !== null && /* @__PURE__ */ jsxs3(
1751
+ "div",
1752
+ {
1753
+ className: "schematic-row schematic-upcoming-bill__balance-applied",
1754
+ "data-testid": "schematic-balance-applied",
1755
+ children: [
1756
+ /* @__PURE__ */ jsx4("span", { className: "schematic-row__label", children: t("upcomingBillBalanceApplied") }),
1757
+ /* @__PURE__ */ jsx4("span", { className: "schematic-row__value", children: bill.balanceApplied.amountText })
1758
+ ]
1759
+ }
1760
+ ),
1761
+ balanceRows && bill.balanceRemaining !== null && /* @__PURE__ */ jsxs3(
1762
+ "div",
1763
+ {
1764
+ className: "schematic-row schematic-upcoming-bill__balance-remaining",
1765
+ "data-testid": "schematic-balance-remaining",
1766
+ children: [
1767
+ /* @__PURE__ */ jsx4("span", { className: "schematic-row__label", children: t("upcomingBillBalanceRemaining") }),
1768
+ /* @__PURE__ */ jsx4("span", { className: "schematic-row__value", children: bill.balanceRemaining.amountText })
1769
+ ]
1770
+ }
1771
+ ),
1772
+ discountRow && /* @__PURE__ */ jsxs3(
1773
+ "div",
1774
+ {
1775
+ className: "schematic-row schematic-upcoming-bill__discount-row",
1776
+ "data-testid": "schematic-discounts",
1777
+ children: [
1778
+ /* @__PURE__ */ jsx4("span", { className: "schematic-row__label", children: t("upcomingBillDiscount") }),
1779
+ /* @__PURE__ */ jsx4("ul", { className: "schematic-row__value schematic-upcoming-bill__discounts", children: bill.discounts.map((discount, index) => /* @__PURE__ */ jsxs3(
1780
+ "li",
1781
+ {
1782
+ className: "schematic-upcoming-bill__discount",
1783
+ "data-testid": "schematic-discount",
1784
+ children: [
1785
+ discount.code !== null && /* @__PURE__ */ jsx4("span", { className: "schematic-chip schematic-upcoming-bill__code", children: discount.code }),
1786
+ /* @__PURE__ */ jsx4("span", { className: "schematic-upcoming-bill__discount-value", children: discountText(discount, t) })
1787
+ ]
1788
+ },
1789
+ `${discount.couponName}-${index}`
1790
+ )) })
1791
+ ]
1792
+ }
1793
+ )
1794
+ ] })
1795
+ ] })
1796
+ }
1797
+ );
1798
+ }
1799
+ function UpcomingBillSkeleton({ showHeader }) {
1800
+ return /* @__PURE__ */ jsxs3("div", { className: "schematic-skeleton", children: [
1801
+ showHeader && /* @__PURE__ */ jsx4("div", { className: "schematic-skeleton__heading" }),
1802
+ /* @__PURE__ */ jsx4("div", { className: "schematic-skeleton__row", children: /* @__PURE__ */ jsx4("div", { className: "schematic-skeleton__cell", "data-column": "amount" }) }),
1803
+ /* @__PURE__ */ jsx4("div", { className: "schematic-skeleton__row", children: /* @__PURE__ */ jsx4("div", { className: "schematic-skeleton__cell", "data-column": "row" }) })
1804
+ ] });
1805
+ }
1806
+ function discountText(discount, t) {
1807
+ if (discount.months === null) {
1808
+ return t("upcomingBillDiscountValue", { value: discount.valueText });
1809
+ }
1810
+ return t("upcomingBillDiscountRepeating", {
1811
+ count: discount.months,
1812
+ value: discount.valueText
1813
+ });
1814
+ }
1815
+ UpcomingBill.resources = ["upcomingInvoice"];
1816
+ export {
1817
+ BillingDataProvider,
1818
+ DEFAULT_STRINGS,
1819
+ Invoices,
1820
+ SCHEMATIC_TOKENS,
1821
+ SchematicI18nProvider,
1822
+ SchematicStyles,
1823
+ UpcomingBill,
1824
+ billingResources,
1825
+ deriveInvoiceList,
1826
+ deriveUpcomingInvoice,
1827
+ featureName,
1828
+ formatConsumptionRate,
1829
+ formatCurrency,
1830
+ formatDate,
1831
+ formatNumber,
1832
+ formatPercent,
1833
+ formatShortDate,
1834
+ httpStatus,
1835
+ interpolate,
1836
+ lookup,
1837
+ plural,
1838
+ resolveLocale,
1839
+ schematicStylesCss,
1840
+ schematicTokensCss,
1841
+ useInvalidateBillingData,
1842
+ useInvoices2 as useInvoices,
1843
+ useResolvedLocale,
1844
+ useSchematicI18n2 as useSchematicI18n,
1845
+ useSchematicLocale2 as useSchematicLocale,
1846
+ useSchematicStrings,
1847
+ useSchematicTranslate,
1848
+ useTranslator,
1849
+ useUpcomingInvoice2 as useUpcomingInvoice,
1850
+ viewerLocale
1851
+ };