@wickermoney/plugin-sdk 0.2.1 → 0.4.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 (103) hide show
  1. package/README.md +53 -2
  2. package/dist/index.d.ts +4 -2
  3. package/dist/index.d.ts.map +1 -1
  4. package/dist/index.js +2 -1
  5. package/dist/index.js.map +1 -1
  6. package/dist/manifest/CORE_TABLES.d.ts.map +1 -1
  7. package/dist/manifest/CORE_TABLES.js +3 -2
  8. package/dist/manifest/CORE_TABLES.js.map +1 -1
  9. package/dist/money/MONEY_SCALE.d.ts +3 -0
  10. package/dist/money/MONEY_SCALE.d.ts.map +1 -0
  11. package/dist/money/MONEY_SCALE.js +3 -0
  12. package/dist/money/MONEY_SCALE.js.map +1 -0
  13. package/dist/money/MONEY_UNIT.d.ts +8 -0
  14. package/dist/money/MONEY_UNIT.d.ts.map +1 -0
  15. package/dist/money/MONEY_UNIT.js +8 -0
  16. package/dist/money/MONEY_UNIT.js.map +1 -0
  17. package/dist/money/Money.d.ts +12 -0
  18. package/dist/money/Money.d.ts.map +1 -0
  19. package/dist/money/Money.js +2 -0
  20. package/dist/money/Money.js.map +1 -0
  21. package/dist/money/ZERO_MONEY.d.ts +8 -0
  22. package/dist/money/ZERO_MONEY.d.ts.map +1 -0
  23. package/dist/money/ZERO_MONEY.js +8 -0
  24. package/dist/money/ZERO_MONEY.js.map +1 -0
  25. package/dist/money/absMoney.d.ts +9 -0
  26. package/dist/money/absMoney.d.ts.map +1 -0
  27. package/dist/money/absMoney.js +14 -0
  28. package/dist/money/absMoney.js.map +1 -0
  29. package/dist/money/addMoney.d.ts +12 -0
  30. package/dist/money/addMoney.d.ts.map +1 -0
  31. package/dist/money/addMoney.js +16 -0
  32. package/dist/money/addMoney.js.map +1 -0
  33. package/dist/money/compareMoney.d.ts +13 -0
  34. package/dist/money/compareMoney.d.ts.map +1 -0
  35. package/dist/money/compareMoney.js +18 -0
  36. package/dist/money/compareMoney.js.map +1 -0
  37. package/dist/money/divideUnits.d.ts +21 -0
  38. package/dist/money/divideUnits.d.ts.map +1 -0
  39. package/dist/money/divideUnits.js +29 -0
  40. package/dist/money/divideUnits.js.map +1 -0
  41. package/dist/money/editableMoney.d.ts +16 -0
  42. package/dist/money/editableMoney.d.ts.map +1 -0
  43. package/dist/money/editableMoney.js +27 -0
  44. package/dist/money/editableMoney.js.map +1 -0
  45. package/dist/money/equalMoney.d.ts +13 -0
  46. package/dist/money/equalMoney.d.ts.map +1 -0
  47. package/dist/money/equalMoney.js +16 -0
  48. package/dist/money/equalMoney.js.map +1 -0
  49. package/dist/money/index.d.ts +44 -0
  50. package/dist/money/index.d.ts.map +1 -0
  51. package/dist/money/index.js +18 -0
  52. package/dist/money/index.js.map +1 -0
  53. package/dist/money/isNegativeMoney.d.ts +9 -0
  54. package/dist/money/isNegativeMoney.d.ts.map +1 -0
  55. package/dist/money/isNegativeMoney.js +12 -0
  56. package/dist/money/isNegativeMoney.js.map +1 -0
  57. package/dist/money/isZeroMoney.d.ts +9 -0
  58. package/dist/money/isZeroMoney.d.ts.map +1 -0
  59. package/dist/money/isZeroMoney.js +12 -0
  60. package/dist/money/isZeroMoney.js.map +1 -0
  61. package/dist/money/moneyToUnits.d.ts +23 -0
  62. package/dist/money/moneyToUnits.d.ts.map +1 -0
  63. package/dist/money/moneyToUnits.js +37 -0
  64. package/dist/money/moneyToUnits.js.map +1 -0
  65. package/dist/money/negateMoney.d.ts +9 -0
  66. package/dist/money/negateMoney.d.ts.map +1 -0
  67. package/dist/money/negateMoney.js +13 -0
  68. package/dist/money/negateMoney.js.map +1 -0
  69. package/dist/money/normalizeMoney.d.ts +12 -0
  70. package/dist/money/normalizeMoney.d.ts.map +1 -0
  71. package/dist/money/normalizeMoney.js +16 -0
  72. package/dist/money/normalizeMoney.js.map +1 -0
  73. package/dist/money/subtractMoney.d.ts +10 -0
  74. package/dist/money/subtractMoney.d.ts.map +1 -0
  75. package/dist/money/subtractMoney.js +14 -0
  76. package/dist/money/subtractMoney.js.map +1 -0
  77. package/dist/money/sumMoney.d.ts +9 -0
  78. package/dist/money/sumMoney.d.ts.map +1 -0
  79. package/dist/money/sumMoney.js +13 -0
  80. package/dist/money/sumMoney.js.map +1 -0
  81. package/dist/money/unitsToMoney.d.ts +14 -0
  82. package/dist/money/unitsToMoney.d.ts.map +1 -0
  83. package/dist/money/unitsToMoney.js +23 -0
  84. package/dist/money/unitsToMoney.js.map +1 -0
  85. package/dist/recurrence/index.d.ts +2 -1
  86. package/dist/recurrence/index.d.ts.map +1 -1
  87. package/dist/recurrence/index.js +1 -0
  88. package/dist/recurrence/index.js.map +1 -1
  89. package/dist/recurrence/projection.d.ts +10 -2
  90. package/dist/recurrence/projection.d.ts.map +1 -1
  91. package/dist/recurrence/projection.js +38 -30
  92. package/dist/recurrence/projection.js.map +1 -1
  93. package/dist/recurrence/scheduled.d.ts +29 -0
  94. package/dist/recurrence/scheduled.d.ts.map +1 -0
  95. package/dist/recurrence/scheduled.js +108 -0
  96. package/dist/recurrence/scheduled.js.map +1 -0
  97. package/dist/recurrence/types.d.ts +42 -0
  98. package/dist/recurrence/types.d.ts.map +1 -1
  99. package/package.json +6 -2
  100. package/dist/recurrence/money.d.ts +0 -39
  101. package/dist/recurrence/money.d.ts.map +0 -1
  102. package/dist/recurrence/money.js +0 -58
  103. package/dist/recurrence/money.js.map +0 -1
@@ -0,0 +1,108 @@
1
+ import { fromDayNumber, toDayNumber } from './calendar.js';
2
+ import { nextOccurrence, occurrences } from './schedule.js';
3
+ /**
4
+ * Lists an item's occurrences that land in a half-open range, after its
5
+ * per-occurrence overrides.
6
+ *
7
+ * An occurrence is placed by the date it lands on, so one moved into the
8
+ * range from outside it is included and one moved out is not. Skipped
9
+ * occurrences are left out. Overrides keyed by a date that is not one of the
10
+ * schedule's are ignored.
11
+ *
12
+ * @param item - The item, with any `overrides`.
13
+ * @param from - First day to include, `YYYY-MM-DD`.
14
+ * @param to - First day to exclude, `YYYY-MM-DD`.
15
+ * @returns Occurrences ordered by the date they land, then nominal date.
16
+ * @throws {RangeError} If the schedule, a date, an override date or `to` is invalid.
17
+ */
18
+ export function scheduledOccurrences(item, from, to) {
19
+ const overrides = item.overrides ?? {};
20
+ const found = [];
21
+ const seen = new Set();
22
+ for (const nominalDate of occurrences(item, from, to)) {
23
+ seen.add(nominalDate);
24
+ const placed = place(item, nominalDate, overrides[nominalDate]);
25
+ if (placed !== null && placed.date >= from && placed.date < to)
26
+ found.push(placed);
27
+ }
28
+ // Occurrences scheduled outside the range but moved into it.
29
+ for (const [nominalDate, override] of Object.entries(overrides)) {
30
+ if (seen.has(nominalDate) || override.date == null)
31
+ continue;
32
+ const date = checkedDate(override.date, nominalDate);
33
+ if (date < from || date >= to || !isScheduled(item, nominalDate))
34
+ continue;
35
+ const placed = place(item, nominalDate, override);
36
+ if (placed !== null)
37
+ found.push(placed);
38
+ }
39
+ return found.sort((a, b) => a.date === b.date ? compare(a.nominalDate, b.nominalDate) : compare(a.date, b.date));
40
+ }
41
+ /**
42
+ * The first occurrence that lands on or after a date and still moves money,
43
+ * after overrides. Skipped occurrences and ones whose override leaves no legs
44
+ * are passed over.
45
+ *
46
+ * @param item - The item, with any `overrides`.
47
+ * @param from - Earliest date to consider, inclusive, `YYYY-MM-DD`.
48
+ * @returns The occurrence, or `null` if none is left.
49
+ * @throws {RangeError} If the schedule, a date or an override date is invalid.
50
+ */
51
+ export function nextScheduledOccurrence(item, from) {
52
+ const overrides = item.overrides ?? {};
53
+ let best = null;
54
+ const consider = (candidate) => {
55
+ if (candidate === null || candidate.legs.length === 0 || candidate.date < from)
56
+ return;
57
+ if (best === null || candidate.date < best.date
58
+ || (candidate.date === best.date && candidate.nominalDate < best.nominalDate))
59
+ best = candidate;
60
+ };
61
+ // Every overridden occurrence, wherever it was scheduled: it may have moved past `from`.
62
+ for (const [nominalDate, override] of Object.entries(overrides)) {
63
+ if (override.date != null)
64
+ checkedDate(override.date, nominalDate);
65
+ if (isScheduled(item, nominalDate))
66
+ consider(place(item, nominalDate, override));
67
+ }
68
+ // The first nominal occurrence on or after `from` that nothing overrides.
69
+ // Each overridden one is stepped over, so this ends within overrides + 1 steps.
70
+ for (let cursor = from; cursor !== null;) {
71
+ const nominalDate = nextOccurrence(item, cursor);
72
+ if (nominalDate === null)
73
+ break;
74
+ if (!Object.hasOwn(overrides, nominalDate)) {
75
+ consider({ nominalDate, date: nominalDate, legs: item.legs });
76
+ break;
77
+ }
78
+ cursor = fromDayNumber(toDayNumber(nominalDate) + 1);
79
+ }
80
+ return best;
81
+ }
82
+ /** Applies one occurrence's override; `null` when it is skipped. */
83
+ function place(item, nominalDate, override) {
84
+ if (override === undefined)
85
+ return { nominalDate, date: nominalDate, legs: item.legs };
86
+ if (override.skipped === true)
87
+ return null;
88
+ return {
89
+ nominalDate,
90
+ date: override.date == null ? nominalDate : checkedDate(override.date, nominalDate),
91
+ legs: override.legs ?? item.legs,
92
+ };
93
+ }
94
+ /** Whether `date` is one of the schedule's nominal dates. */
95
+ function isScheduled(item, date) {
96
+ const day = toDayNumber(date, 'override key');
97
+ return occurrences(item, date, fromDayNumber(day + 1)).length === 1;
98
+ }
99
+ /** Validates an override's date, naming the occurrence in the error. */
100
+ function checkedDate(date, nominalDate) {
101
+ toDayNumber(date, `override date for ${nominalDate}`);
102
+ return date;
103
+ }
104
+ /** String order, which is date order for `YYYY-MM-DD`. */
105
+ function compare(a, b) {
106
+ return a < b ? -1 : a > b ? 1 : 0;
107
+ }
108
+ //# sourceMappingURL=scheduled.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"scheduled.js","sourceRoot":"","sources":["../../src/recurrence/scheduled.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,aAAa,EAAE,WAAW,EAAE,MAAM,eAAe,CAAA;AAC1D,OAAO,EAAE,cAAc,EAAE,WAAW,EAAE,MAAM,eAAe,CAAA;AAG3D;;;;;;;;;;;;;;GAcG;AACH,MAAM,UAAU,oBAAoB,CAAC,IAAmB,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AC,CAAA;AACrE,CAAC;AAED,wEAAwE;AACxE,SAAS,WAAW,CAAC,IAAY,EAAE,WAAmB;IACpD,WAAW,CAAC,IAAI,EAAE,qBAAqB,WAAW,EAAE,CAAC,CAAA;IACrD,OAAO,IAAI,CAAA;AACb,CAAC;AAED,0DAA0D;AAC1D,SAAS,OAAO,CAAC,CAAS,EAAE,CAAS;IACnC,OAAO,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAA;AACnC,CAAC"}
@@ -62,6 +62,48 @@ export interface RecurringLeg {
62
62
  export interface RecurringItem extends RecurrenceSchedule {
63
63
  /** The legs applied on each occurrence. */
64
64
  readonly legs: readonly RecurringLeg[];
65
+ /**
66
+ * Changes to single occurrences, keyed by nominal date (`YYYY-MM-DD`): the
67
+ * date the schedule gives, which is what identifies an occurrence even after
68
+ * it moves. A key that is not one of the schedule's dates is ignored, so an
69
+ * override left behind by a schedule edit can never invent an occurrence.
70
+ * `null` or absent when nothing is overridden.
71
+ */
72
+ readonly overrides?: Readonly<Record<string, OccurrenceOverride>> | null;
73
+ }
74
+ /**
75
+ * How one occurrence differs from its series.
76
+ *
77
+ * Every field is optional; an empty object changes nothing. A caller can use
78
+ * these for anything that makes one occurrence differ: a month the user skips,
79
+ * a bill that is larger this time, a payment that moved for a holiday, or (as
80
+ * the Wicker Money API does) money that already arrived and must not be
81
+ * projected again.
82
+ */
83
+ export interface OccurrenceOverride {
84
+ /** `true` drops the occurrence entirely: it is not listed and moves no money. */
85
+ readonly skipped?: boolean;
86
+ /**
87
+ * The date it is expected instead of the nominal one, `YYYY-MM-DD`. May be
88
+ * earlier or later, including outside the range being asked about: an
89
+ * occurrence is placed where it lands, not where it was scheduled.
90
+ */
91
+ readonly date?: string | null;
92
+ /**
93
+ * The legs applied on this occurrence instead of the item's. An empty list
94
+ * keeps the occurrence (it still happens on its date) but moves no money,
95
+ * which is how an occurrence that has already fully posted is expressed.
96
+ */
97
+ readonly legs?: readonly RecurringLeg[] | null;
98
+ }
99
+ /** One occurrence after overrides: when it lands and what it moves. */
100
+ export interface ScheduledOccurrence {
101
+ /** The schedule's date for it, `YYYY-MM-DD`; its identity. */
102
+ readonly nominalDate: string;
103
+ /** The date it lands, `YYYY-MM-DD`; the nominal date unless overridden. */
104
+ readonly date: string;
105
+ /** The legs it applies: the override's if it has any, otherwise the item's. */
106
+ readonly legs: readonly RecurringLeg[];
65
107
  }
66
108
  /** One day of a projected balance series. */
67
109
  export interface DailyBalance {
@@ -1 +1 @@
1
- {"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../src/recurrence/types.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AACH,eAAO,MAAM,sBAAsB,mGAEzB,CAAA;AACV,qDAAqD;AACrD,MAAM,MAAM,mBAAmB,GAAG,CAAC,OAAO,sBAAsB,CAAC,CAAC,MAAM,CAAC,CAAA;AAEzE,wFAAwF;AACxF,eAAO,MAAM,wBAAwB,EAAE,SAAS,CAAC,MAAM,EAAE,MAAM,CAAW,CAAA;AAE1E;;;;GAIG;AACH,MAAM,WAAW,kBAAkB;IACjC,4BAA4B;IAC5B,QAAQ,CAAC,SAAS,EAAE,mBAAmB,CAAA;IACvC;;;;;;;OAOG;IACH,QAAQ,CAAC,eAAe,EAAE,MAAM,CAAA;IAChC;;;OAGG;IACH,QAAQ,CAAC,OAAO,CAAC,EAAE,MAAM,GAAG,IAAI,CAAA;IAChC;;;;;OAKG;IACH,QAAQ,CAAC,eAAe,CAAC,EAAE,SAAS,CAAC,MAAM,EAAE,MAAM,CAAC,GAAG,IAAI,CAAA;CAC5D;AAED,wDAAwD;AACxD,MAAM,WAAW,YAAY;IAC3B,4CAA4C;IAC5C,QAAQ,CAAC,SAAS,EAAE,MAAM,CAAA;IAC1B;;;OAGG;IACH,QAAQ,CAAC,MAAM,EAAE,MAAM,CAAA;CACxB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AAiG;IACjG,QAAQ,CAAC,MAAM,EAAE,MAAM,CAAA;IACvB,sGAAsG;IACtG,QAAQ,CAAC,OAAO,EAAE,MAAM,CAAA;IACxB,0BAA0B;IAC1B,QAAQ,CAAC,GAAG,EAAE,MAAM,CAAA;CACrB"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@wickermoney/plugin-sdk",
3
- "version": "0.2.1",
3
+ "version": "0.4.0",
4
4
  "license": "Apache-2.0",
5
5
  "repository": {
6
6
  "type": "git",
@@ -26,6 +26,10 @@
26
26
  "./recurrence": {
27
27
  "types": "./dist/recurrence/index.d.ts",
28
28
  "default": "./dist/recurrence/index.js"
29
+ },
30
+ "./money": {
31
+ "types": "./dist/money/index.d.ts",
32
+ "default": "./dist/money/index.js"
29
33
  }
30
34
  },
31
35
  "files": [
@@ -40,7 +44,7 @@
40
44
  "@types/react": "^19.3.0",
41
45
  "react": "^19.3.0",
42
46
  "typescript": "^6.0.3",
43
- "vitest": "^5.0.0"
47
+ "vitest": "^5.0.3"
44
48
  },
45
49
  "dependencies": {
46
50
  "zod": "^4.6.5"
@@ -1,39 +0,0 @@
1
- /**
2
- * @module
3
- * Fixed-point money for the recurrence module. Internal to the SDK.
4
- *
5
- * Same rules as the budgets plugin's `shared/money.ts`: amounts are
6
- * `numeric(19,4)` strings at every boundary and `bigint` units of 1/10,000 in
7
- * between, never `number`. Kept private for now so this module does not also
8
- * commit the SDK to a public money API; promoting it (and deleting the plugin
9
- * copies) is a separate decision.
10
- */
11
- /** Integer units per whole currency unit. */
12
- export declare const UNIT = 10000n;
13
- /**
14
- * Parses a decimal string into units of 1/10,000.
15
- *
16
- * @param value - A plain decimal string such as `'-81.2'` or `'2850.0000'`.
17
- * @param label - What the value is, for the error message.
18
- * @returns The scaled amount. Digits beyond the fourth decimal place are
19
- * truncated, since the column holds four.
20
- * @throws {RangeError} If `value` is not a plain decimal number.
21
- */
22
- export declare function parseMoney(value: string, label?: string): bigint;
23
- /**
24
- * Formats units of 1/10,000 as a four-decimal string.
25
- *
26
- * @param units - The scaled amount.
27
- * @returns A string such as `'-81.2000'`; zero is always `'0.0000'`, never `'-0.0000'`.
28
- */
29
- export declare function formatMoney(units: bigint): string;
30
- /**
31
- * Divides and rounds half away from zero, so a value and its negation round
32
- * to mirror images (`-801.66665` and `801.66665` both move away from zero).
33
- *
34
- * @param numerator - Dividend.
35
- * @param denominator - Divisor; must be positive.
36
- * @returns The rounded quotient.
37
- */
38
- export declare function divideRounded(numerator: bigint, denominator: bigint): bigint;
39
- //# sourceMappingURL=money.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"money.d.ts","sourceRoot":"","sources":["../../src/recurrence/money.ts"],"names":[],"mappings":"AAAA;;;;;;;;;GASG;AAEH,6CAA6C;AAC7C,eAAO,MAAM,IAAI,SAAU,CAAA;AAI3B;;;;;;;;GAQG;AACH,wBAAgB,UAAU,CAAC,KAAK,EAAE,MAAM,EAAE,KAAK,SAAW,GAAG,MAAM,CAOlE;AAED;;;;;GAKG;AACH,wBAAgB,WAAW,CAAC,KAAK,EAAE,MAAM,GAAG,MAAM,CAKjD;AAED;;;;;;;GAOG;AACH,wBAAgB,aAAa,CAAC,SAAS,EAAE,MAAM,EAAE,WAAW,EAAE,MAAM,GAAG,MAAM,CAK5E"}
@@ -1,58 +0,0 @@
1
- /**
2
- * @module
3
- * Fixed-point money for the recurrence module. Internal to the SDK.
4
- *
5
- * Same rules as the budgets plugin's `shared/money.ts`: amounts are
6
- * `numeric(19,4)` strings at every boundary and `bigint` units of 1/10,000 in
7
- * between, never `number`. Kept private for now so this module does not also
8
- * commit the SDK to a public money API; promoting it (and deleting the plugin
9
- * copies) is a separate decision.
10
- */
11
- /** Integer units per whole currency unit. */
12
- export const UNIT = 10000n;
13
- const NUMERIC = /^-?\d+(\.\d+)?$/;
14
- /**
15
- * Parses a decimal string into units of 1/10,000.
16
- *
17
- * @param value - A plain decimal string such as `'-81.2'` or `'2850.0000'`.
18
- * @param label - What the value is, for the error message.
19
- * @returns The scaled amount. Digits beyond the fourth decimal place are
20
- * truncated, since the column holds four.
21
- * @throws {RangeError} If `value` is not a plain decimal number.
22
- */
23
- export function parseMoney(value, label = 'amount') {
24
- const text = typeof value === 'string' ? value.trim() : '';
25
- if (!NUMERIC.test(text))
26
- throw new RangeError(`Invalid ${label}: ${JSON.stringify(value)}`);
27
- const negative = text.startsWith('-');
28
- const [whole = '0', fraction = ''] = (negative ? text.slice(1) : text).split('.');
29
- const units = BigInt(whole) * UNIT + BigInt((fraction + '0000').slice(0, 4));
30
- return negative ? -units : units;
31
- }
32
- /**
33
- * Formats units of 1/10,000 as a four-decimal string.
34
- *
35
- * @param units - The scaled amount.
36
- * @returns A string such as `'-81.2000'`; zero is always `'0.0000'`, never `'-0.0000'`.
37
- */
38
- export function formatMoney(units) {
39
- const negative = units < 0n;
40
- const absolute = negative ? -units : units;
41
- const fraction = (absolute % UNIT).toString().padStart(4, '0');
42
- return `${negative ? '-' : ''}${absolute / UNIT}.${fraction}`;
43
- }
44
- /**
45
- * Divides and rounds half away from zero, so a value and its negation round
46
- * to mirror images (`-801.66665` and `801.66665` both move away from zero).
47
- *
48
- * @param numerator - Dividend.
49
- * @param denominator - Divisor; must be positive.
50
- * @returns The rounded quotient.
51
- */
52
- export function divideRounded(numerator, denominator) {
53
- const negative = numerator < 0n;
54
- const absolute = negative ? -numerator : numerator;
55
- const q = (absolute * 2n + denominator) / (denominator * 2n);
56
- return negative ? -q : q;
57
- }
58
- //# sourceMappingURL=money.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"money.js","sourceRoot":"","sources":["../../src/recurrence/money.ts"],"names":[],"mappings":"AAAA;;;;;;;;;GASG;AAEH,6CAA6C;AAC7C,MAAM,CAAC,MAAM,IAAI,GAAG,MAAO,CAAA;AAE3B,MAAM,OAAO,GAAG,iBAAiB,CAAA;AAEjC;;;;;;;;GAQG;AACH,MAAM,UAAU,UAAU,CAAC,KAAa,EAAE,KAAK,GA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