@davidsouther/jiffies 1.0.0 → 1.1.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 (172) hide show
  1. package/build/assert.d.ts +23 -23
  2. package/build/assert.js +33 -33
  3. package/build/case.d.ts +1 -1
  4. package/build/case.js +5 -5
  5. package/build/components/button_bar.d.ts +8 -8
  6. package/build/components/button_bar.js +27 -27
  7. package/build/components/inline_edit.d.ts +12 -12
  8. package/build/components/inline_edit.js +48 -48
  9. package/build/components/logger.d.ts +6 -7
  10. package/build/components/logger.js +22 -22
  11. package/build/components/select.d.ts +13 -10
  12. package/build/components/select.js +3 -3
  13. package/build/components/test.d.ts +1 -1
  14. package/build/components/test.js +2 -2
  15. package/build/components/virtual_scroll.d.ts +40 -41
  16. package/build/components/virtual_scroll.js +94 -94
  17. package/build/components/virtual_scroll.test.d.ts +1 -1
  18. package/build/components/virtual_scroll.test.js +21 -21
  19. package/build/context.d.ts +15 -15
  20. package/build/context.js +43 -43
  21. package/build/context.test.d.ts +1 -1
  22. package/build/context.test.js +46 -46
  23. package/build/debounce.d.ts +1 -1
  24. package/build/debounce.js +7 -7
  25. package/build/display.d.ts +5 -5
  26. package/build/display.js +11 -11
  27. package/build/dom/css/border.d.ts +11 -11
  28. package/build/dom/css/border.js +27 -27
  29. package/build/dom/css/constants.d.ts +31 -31
  30. package/build/dom/css/constants.js +28 -28
  31. package/build/dom/css/core.d.ts +5 -5
  32. package/build/dom/css/core.js +24 -24
  33. package/build/dom/css/fstyle.d.ts +5 -5
  34. package/build/dom/css/fstyle.js +32 -32
  35. package/build/dom/css/sizing.d.ts +5 -5
  36. package/build/dom/css/sizing.js +10 -10
  37. package/build/dom/dom.d.ts +26 -27
  38. package/build/dom/dom.js +95 -95
  39. package/build/dom/fc.d.ts +14 -14
  40. package/build/dom/fc.js +36 -35
  41. package/build/dom/fc.test.d.ts +1 -1
  42. package/build/dom/fc.test.js +21 -21
  43. package/build/dom/form/form.app.d.ts +1 -1
  44. package/build/dom/form/form.app.js +23 -23
  45. package/build/dom/form/form.d.ts +26 -26
  46. package/build/dom/form/form.js +34 -34
  47. package/build/dom/form/form.test.js +1 -1
  48. package/build/dom/html.d.ts +113 -117
  49. package/build/dom/html.js +114 -114
  50. package/build/dom/html.test.d.ts +1 -1
  51. package/build/dom/html.test.js +58 -58
  52. package/build/dom/provide.d.ts +3 -3
  53. package/build/dom/provide.js +7 -7
  54. package/build/dom/router/link.d.ts +6 -6
  55. package/build/dom/router/link.js +3 -3
  56. package/build/dom/router/router.d.ts +12 -12
  57. package/build/dom/router/router.js +49 -49
  58. package/build/dom/svg.d.ts +64 -64
  59. package/build/dom/svg.js +65 -65
  60. package/build/dom/test.d.ts +1 -1
  61. package/build/dom/test.js +2 -2
  62. package/build/dom/types/css.d.ts +6612 -6612
  63. package/build/dom/types/css.js +23 -23
  64. package/build/dom/types/dom.js +1 -1
  65. package/build/dom/types/html.d.ts +616 -616
  66. package/build/dom/types/html.js +1 -1
  67. package/build/dom/xml.d.ts +1 -1
  68. package/build/dom/xml.js +4 -5
  69. package/build/equal.d.ts +5 -5
  70. package/build/equal.js +37 -37
  71. package/build/equal.test.d.ts +1 -1
  72. package/build/equal.test.js +20 -20
  73. package/build/flags.d.ts +7 -7
  74. package/build/flags.js +48 -48
  75. package/build/flags.test.d.ts +1 -1
  76. package/build/flags.test.js +35 -35
  77. package/build/fs.d.ts +48 -48
  78. package/build/fs.js +144 -144
  79. package/build/fs.test.d.ts +1 -1
  80. package/build/fs.test.js +43 -43
  81. package/build/generator.d.ts +1 -1
  82. package/build/generator.js +10 -10
  83. package/build/generator.test.d.ts +1 -1
  84. package/build/generator.test.js +24 -24
  85. package/build/is_browser.d.ts +1 -1
  86. package/build/is_browser.js +1 -1
  87. package/build/loader.d.mts +22 -22
  88. package/build/loader.mjs +35 -35
  89. package/build/lock.d.ts +1 -1
  90. package/build/lock.js +23 -23
  91. package/build/lock.test.d.ts +1 -1
  92. package/build/lock.test.js +16 -16
  93. package/build/log.d.ts +26 -26
  94. package/build/log.js +46 -46
  95. package/build/observable/observable.d.ts +83 -0
  96. package/build/observable/observable.js +148 -0
  97. package/build/observable/observable.test.d.ts +1 -0
  98. package/build/observable/observable.test.js +21 -0
  99. package/build/range.d.ts +1 -1
  100. package/build/range.js +7 -7
  101. package/build/result.d.ts +31 -31
  102. package/build/result.js +65 -65
  103. package/build/result.test.d.ts +1 -1
  104. package/build/result.test.js +71 -71
  105. package/build/safe.d.ts +1 -1
  106. package/build/safe.js +10 -10
  107. package/build/scope/describe.d.ts +18 -14
  108. package/build/scope/describe.js +61 -52
  109. package/build/scope/display/console.d.ts +2 -2
  110. package/build/scope/display/console.js +21 -21
  111. package/build/scope/display/dom.d.ts +3 -3
  112. package/build/scope/display/dom.js +26 -26
  113. package/build/scope/display/junit.d.ts +2 -2
  114. package/build/scope/display/junit.js +17 -17
  115. package/build/scope/execute.d.ts +12 -12
  116. package/build/scope/execute.js +85 -85
  117. package/build/scope/expect.d.ts +23 -23
  118. package/build/scope/expect.js +108 -108
  119. package/build/scope/fix.d.ts +4 -4
  120. package/build/scope/fix.js +22 -22
  121. package/build/scope/index.d.ts +3 -3
  122. package/build/scope/index.js +3 -3
  123. package/build/scope/scope.d.ts +17 -17
  124. package/build/scope/scope.js +1 -1
  125. package/build/server/http/apps.d.ts +5 -5
  126. package/build/server/http/apps.js +23 -23
  127. package/build/server/http/css.d.ts +5 -5
  128. package/build/server/http/css.js +50 -47
  129. package/build/server/http/index.d.ts +21 -21
  130. package/build/server/http/index.js +73 -73
  131. package/build/server/http/response.d.ts +4 -4
  132. package/build/server/http/response.js +40 -40
  133. package/build/server/http/sitemap.d.ts +2 -2
  134. package/build/server/http/sitemap.js +42 -42
  135. package/build/server/http/static.d.ts +2 -2
  136. package/build/server/http/static.js +21 -21
  137. package/build/server/http/typescript.d.ts +5 -5
  138. package/build/server/http/typescript.js +40 -40
  139. package/build/server/main.d.ts +2 -2
  140. package/build/server/main.js +9 -9
  141. package/build/test.d.mts +2 -2
  142. package/build/test.mjs +23 -23
  143. package/build/test_all.d.ts +7 -7
  144. package/build/test_all.js +18 -18
  145. package/build/transpile.d.mts +3 -3
  146. package/build/transpile.mjs +18 -18
  147. package/package.json +3 -3
  148. package/src/components/logger.ts +2 -3
  149. package/src/components/virtual_scroll.test.ts +4 -4
  150. package/src/components/virtual_scroll.ts +8 -8
  151. package/src/diff.test.ts +48 -0
  152. package/src/diff.ts +84 -0
  153. package/src/dom/dom.ts +73 -61
  154. package/src/dom/fc.ts +10 -9
  155. package/src/dom/html.test.ts +5 -5
  156. package/src/dom/html.ts +7 -10
  157. package/src/dom/observable.test.ts +43 -0
  158. package/src/dom/observable.ts +11 -0
  159. package/src/dom/router/router.ts +4 -4
  160. package/src/dom/test.ts +5 -1
  161. package/src/dom/xml.ts +1 -2
  162. package/src/index.html +6 -3
  163. package/src/observable/_notes +21 -8
  164. package/src/observable/event.ts +93 -0
  165. package/src/observable/observable.test.ts +73 -0
  166. package/src/observable/observable.ts +403 -0
  167. package/src/scope/describe.ts +14 -1
  168. package/src/scope/display/dom.ts +2 -2
  169. package/src/scope/execute.ts +2 -5
  170. package/src/server/http/css.ts +3 -1
  171. package/src/test_all.ts +10 -8
  172. package/src/observable/observable._js +0 -175
@@ -1,94 +1,94 @@
1
- import { debounce } from "../debounce.js";
2
- import { FC, State } from "../dom/fc.js";
3
- import { div } from "../dom/html.js";
4
- export function arrayAdapter(data) {
5
- return (offset, limit) => data.slice(offset, offset + limit);
6
- }
7
- export function fillVirtualScrollSettings(settings) {
8
- const { minIndex = 0, maxIndex = 1, startIndex = 0, itemHeight = 20, count = maxIndex - minIndex + 1, tolerance = count, } = settings;
9
- return { minIndex, maxIndex, startIndex, itemHeight, count, tolerance };
10
- }
11
- export function initialState(settings) {
12
- // From Denis Hilt, https://blog.logrocket.com/virtual-scrolling-core-principles-and-basic-implementation-in-react/
13
- const { minIndex, maxIndex, startIndex, itemHeight, count, tolerance } = settings;
14
- const bufferedItems = count + 2 * tolerance;
15
- const itemsAbove = Math.max(0, startIndex - tolerance - minIndex);
16
- const viewportHeight = count * itemHeight;
17
- const totalHeight = (maxIndex - minIndex + 1) * itemHeight;
18
- const toleranceHeight = tolerance * itemHeight;
19
- const bufferHeight = viewportHeight + 2 * toleranceHeight;
20
- const topPaddingHeight = itemsAbove * itemHeight;
21
- const bottomPaddingHeight = totalHeight - (topPaddingHeight + bufferHeight);
22
- return {
23
- scrollTop: 0,
24
- settings,
25
- viewportHeight,
26
- totalHeight,
27
- toleranceHeight,
28
- bufferedItems,
29
- topPaddingHeight,
30
- bottomPaddingHeight,
31
- data: [],
32
- rows: [],
33
- };
34
- }
35
- export function getData(minIndex, maxIndex, offset, limit, get) {
36
- const start = Math.max(0, minIndex, offset);
37
- const end = Math.min(maxIndex, offset + limit - 1);
38
- const data = get(start, end - start);
39
- return [...data];
40
- }
41
- export function doScroll(scrollTop, state, get) {
42
- const { totalHeight, toleranceHeight, bufferedItems, settings: { itemHeight, minIndex, maxIndex }, } = state;
43
- const index = minIndex + Math.floor((scrollTop - toleranceHeight) / itemHeight);
44
- const data = getData(minIndex, maxIndex, index, bufferedItems, get);
45
- const topPaddingHeight = Math.max((index - minIndex) * itemHeight, 0);
46
- const bottomPaddingHeight = Math.max(totalHeight - (topPaddingHeight + data.length * itemHeight), 0);
47
- return { scrollTop, topPaddingHeight, bottomPaddingHeight, data };
48
- }
49
- // export interface VirtualScroll<T, U extends HTMLElement> {
50
- // state: VirtualScrollState<T>;
51
- // rows: UHTMLElement<U>[];
52
- // }
53
- export const VirtualScroll = FC("virtual-scroll", (element, props) => {
54
- const settings = fillVirtualScrollSettings(props.settings);
55
- const state = (element[State] = {
56
- ...initialState(settings),
57
- ...element[State],
58
- });
59
- const scrollTo = ({ target } = { target: state }) => {
60
- const scrollTop = target?.scrollTop ?? state.topPaddingHeight;
61
- const updatedSate = {
62
- ...state,
63
- ...doScroll(scrollTop, state, props.get),
64
- };
65
- setState(updatedSate);
66
- };
67
- const viewportElement = div({
68
- style: { height: `${state.viewportHeight}px`, overflowY: "scroll" },
69
- events: { scroll: debounce(scrollTo, 0) },
70
- });
71
- setTimeout(() => {
72
- viewportElement.scroll({ top: state.scrollTop });
73
- });
74
- const setState = (newState) => {
75
- state.scrollTop = newState.scrollTop;
76
- state.topPaddingHeight = newState.topPaddingHeight;
77
- state.bottomPaddingHeight = newState.bottomPaddingHeight;
78
- state.data = newState.data;
79
- element[State].rows = state.data.map(props.row);
80
- viewportElement.update(div({
81
- class: "VirtualScroll__topPadding",
82
- style: { height: `${state.topPaddingHeight}px` },
83
- }), ...(element[State].rows ?? []).map((row, i) => div({
84
- class: `VirtualScroll__item_${i}`,
85
- style: { height: `${settings.itemHeight}px` },
86
- }, row)), div({
87
- class: "VirtualScroll__bottomPadding",
88
- style: { height: `${state.bottomPaddingHeight}px` },
89
- }));
90
- };
91
- scrollTo();
92
- return viewportElement;
93
- });
94
- export default VirtualScroll;
1
+ import { debounce } from "../debounce.js";
2
+ import { FC, State } from "../dom/fc.js";
3
+ import { div } from "../dom/html.js";
4
+ export function arrayAdapter(data) {
5
+ return (offset, limit) => data.slice(offset, offset + limit);
6
+ }
7
+ export function fillVirtualScrollSettings(settings) {
8
+ const { minIndex = 0, maxIndex = 1, startIndex = 0, itemHeight = 20, count = maxIndex - minIndex + 1, tolerance = count, } = settings;
9
+ return { minIndex, maxIndex, startIndex, itemHeight, count, tolerance };
10
+ }
11
+ export function initialState(settings) {
12
+ // From Denis Hilt, https://blog.logrocket.com/virtual-scrolling-core-principles-and-basic-implementation-in-react/
13
+ const { minIndex, maxIndex, startIndex, itemHeight, count, tolerance } = settings;
14
+ const bufferedItems = count + 2 * tolerance;
15
+ const itemsAbove = Math.max(0, startIndex - tolerance - minIndex);
16
+ const viewportHeight = count * itemHeight;
17
+ const totalHeight = (maxIndex - minIndex + 1) * itemHeight;
18
+ const toleranceHeight = tolerance * itemHeight;
19
+ const bufferHeight = viewportHeight + 2 * toleranceHeight;
20
+ const topPaddingHeight = itemsAbove * itemHeight;
21
+ const bottomPaddingHeight = totalHeight - (topPaddingHeight + bufferHeight);
22
+ return {
23
+ scrollTop: 0,
24
+ settings,
25
+ viewportHeight,
26
+ totalHeight,
27
+ toleranceHeight,
28
+ bufferedItems,
29
+ topPaddingHeight,
30
+ bottomPaddingHeight,
31
+ data: [],
32
+ rows: [],
33
+ };
34
+ }
35
+ export function getData(minIndex, maxIndex, offset, limit, get) {
36
+ const start = Math.max(0, minIndex, offset);
37
+ const end = Math.min(maxIndex, offset + limit - 1);
38
+ const data = get(start, end - start);
39
+ return [...data];
40
+ }
41
+ export function doScroll(scrollTop, state, get) {
42
+ const { totalHeight, toleranceHeight, bufferedItems, settings: { itemHeight, minIndex, maxIndex }, } = state;
43
+ const index = minIndex + Math.floor((scrollTop - toleranceHeight) / itemHeight);
44
+ const data = getData(minIndex, maxIndex, index, bufferedItems, get);
45
+ const topPaddingHeight = Math.max((index - minIndex) * itemHeight, 0);
46
+ const bottomPaddingHeight = Math.max(totalHeight - (topPaddingHeight + data.length * itemHeight), 0);
47
+ return { scrollTop, topPaddingHeight, bottomPaddingHeight, data };
48
+ }
49
+ // export interface VirtualScroll<T, U extends HTMLElement> {
50
+ // state: VirtualScrollState<T>;
51
+ // rows: UHTMLElement<U>[];
52
+ // }
53
+ export const VirtualScroll = FC("virtual-scroll", (element, props) => {
54
+ const settings = fillVirtualScrollSettings(props.settings);
55
+ const state = (element[State] = {
56
+ ...initialState(settings),
57
+ ...element[State],
58
+ });
59
+ const scrollTo = ({ target } = { target: state }) => {
60
+ const scrollTop = target?.scrollTop ?? state.topPaddingHeight;
61
+ const updatedSate = {
62
+ ...state,
63
+ ...doScroll(scrollTop, state, props.get),
64
+ };
65
+ setState(updatedSate);
66
+ };
67
+ const viewportElement = div({
68
+ style: { height: `${state.viewportHeight}px`, overflowY: "scroll" },
69
+ events: { scroll: debounce(scrollTo, 0) },
70
+ });
71
+ setTimeout(() => {
72
+ viewportElement.scroll({ top: state.scrollTop });
73
+ });
74
+ const setState = (newState) => {
75
+ state.scrollTop = newState.scrollTop;
76
+ state.topPaddingHeight = newState.topPaddingHeight;
77
+ state.bottomPaddingHeight = newState.bottomPaddingHeight;
78
+ state.data = newState.data;
79
+ state.rows = state.data.map(props.row);
80
+ viewportElement.update(div({
81
+ class: "VirtualScroll__topPadding",
82
+ style: { height: `${state.topPaddingHeight}px` },
83
+ }), ...(state.rows ?? []).map((row, i) => div({
84
+ class: `VirtualScroll__item_${i}`,
85
+ style: { height: `${settings.itemHeight}px` },
86
+ }, row)), div({
87
+ class: "VirtualScroll__bottomPadding",
88
+ style: { height: `${state.bottomPaddingHeight}px` },
89
+ }));
90
+ };
91
+ scrollTo();
92
+ return viewportElement;
93
+ });
94
+ export default VirtualScroll;
@@ -1 +1 @@
1
- export {};
1
+ export {};
@@ -1,21 +1,21 @@
1
- import { State } from "../dom/fc.js";
2
- import { div } from "../dom/html.js";
3
- import { describe, it, expect } from "../scope/index.js";
4
- import VirtualScroll, { arrayAdapter, } from "./virtual_scroll.js";
5
- describe("VirtualScroll", () => {
6
- it("tracks scroll position", () => {
7
- const data = [0, 1, 2, 3, 4, 5, 6, 7, 8, 9];
8
- const props = {
9
- settings: { count: 3, startIndex: 2 },
10
- get: arrayAdapter(data),
11
- row: (i) => div(`${i}`),
12
- };
13
- // @ts-ignore TODO(TFC)
14
- const scroll = VirtualScroll(props);
15
- expect(scroll[State].bufferedItems).toBe(9);
16
- expect(scroll[State].data).toEqual([0, 1, 2, 3, 4, 5, 6, 7, 8]);
17
- //expect(scroll.state.topPaddingHeight).toBe(0);
18
- expect(scroll[State].viewportHeight).toBe(60);
19
- //expect(scroll.state.totalHeight).toBe(200);
20
- });
21
- });
1
+ import { State } from "../dom/fc.js";
2
+ import { div } from "../dom/html.js";
3
+ import { describe, it, expect } from "../scope/index.js";
4
+ import VirtualScroll, { arrayAdapter, } from "./virtual_scroll.js";
5
+ describe("VirtualScroll", () => {
6
+ it("tracks scroll position", () => {
7
+ const data = [0, 1, 2, 3, 4, 5, 6, 7, 8, 9];
8
+ const props = {
9
+ settings: { count: 3, startIndex: 2 },
10
+ get: arrayAdapter(data),
11
+ row: (i) => div(`${i}`),
12
+ };
13
+ // @ts-ignore TODO(TFC)
14
+ const scroll = VirtualScroll(props);
15
+ expect(scroll[State]?.bufferedItems).toBe(9);
16
+ expect(scroll[State]?.data).toEqual([0, 1, 2, 3, 4, 5, 6, 7, 8]);
17
+ //expect(scroll.state.topPaddingHeight).toBe(0);
18
+ expect(scroll[State]?.viewportHeight).toBe(60);
19
+ //expect(scroll.state.totalHeight).toBe(200);
20
+ });
21
+ });
@@ -1,15 +1,15 @@
1
- import { Err, Result } from "./result.js";
2
- export declare const Enter: unique symbol;
3
- export declare const Exit: unique symbol;
4
- export interface Context {
5
- [Enter]: () => void;
6
- [Exit]: () => void;
7
- }
8
- export interface Operation<T, E extends Error, C extends Context> {
9
- (c: C): T | Result<T, E>;
10
- }
11
- export interface AsyncOperation<T, E extends Error, C extends Context> {
12
- (c: C): Promise<T | Result<T, E>>;
13
- }
14
- export declare function using<T, E extends Error, C extends Context>(context: C | (() => C) | Operation<T, E, C>, operation?: Operation<T, E, C>, normalizeError?: (e: Error | unknown | any) => Err<E>): Result<T, E>;
15
- export declare function asyncUsing<T, E extends Error, C extends Context>(context: C | (() => Promise<C>), operation: AsyncOperation<T, E, C>, normalizeError?: (e: Error | unknown | any) => Err<E>): Promise<Result<T, E>>;
1
+ import { Err, Result } from "./result.js";
2
+ export declare const Enter: unique symbol;
3
+ export declare const Exit: unique symbol;
4
+ export interface Context {
5
+ [Enter]: () => void;
6
+ [Exit]: () => void;
7
+ }
8
+ export interface Operation<T, E extends Error, C extends Context> {
9
+ (c: C): T | Result<T, E>;
10
+ }
11
+ export interface AsyncOperation<T, E extends Error, C extends Context> {
12
+ (c: C): Promise<T | Result<T, E>>;
13
+ }
14
+ export declare function using<T, E extends Error, C extends Context>(context: C | (() => C) | Operation<T, E, C>, operation?: Operation<T, E, C>, normalizeError?: (e: Error | unknown | any) => Err<E>): Result<T, E>;
15
+ export declare function asyncUsing<T, E extends Error, C extends Context>(context: C | (() => Promise<C>), operation: AsyncOperation<T, E, C>, normalizeError?: (e: Error | unknown | any) => Err<E>): Promise<Result<T, E>>;
package/build/context.js CHANGED
@@ -1,43 +1,43 @@
1
- import { Ok, Err, isResult } from "./result.js";
2
- export const Enter = Symbol("Context Enter");
3
- export const Exit = Symbol("Context Exit");
4
- export function using(context, operation, normalizeError = (e) => Err(e)) {
5
- if (typeof context == "function") {
6
- if (context.length == 1) {
7
- operation = context;
8
- context = {};
9
- }
10
- else {
11
- context = context();
12
- }
13
- }
14
- let result;
15
- try {
16
- context[Enter]();
17
- const op = operation(context);
18
- result = isResult(op) ? op : Ok(op);
19
- }
20
- catch (e) {
21
- result = normalizeError(e);
22
- }
23
- finally {
24
- context[Exit]();
25
- }
26
- return result;
27
- }
28
- export async function asyncUsing(context, operation, normalizeError = (e) => Err(e)) {
29
- context = typeof context == "function" ? await context() : context;
30
- let result;
31
- try {
32
- context[Enter]();
33
- const op = await operation(context);
34
- result = isResult(op) ? op : Ok(op);
35
- }
36
- catch (e) {
37
- result = normalizeError(e);
38
- }
39
- finally {
40
- context[Exit]();
41
- }
42
- return result;
43
- }
1
+ import { Ok, Err, isResult } from "./result.js";
2
+ export const Enter = Symbol("Context Enter");
3
+ export const Exit = Symbol("Context Exit");
4
+ export function using(context, operation, normalizeError = (e) => Err(e)) {
5
+ if (typeof context == "function") {
6
+ if (context.length == 1) {
7
+ operation = context;
8
+ context = {};
9
+ }
10
+ else {
11
+ context = context();
12
+ }
13
+ }
14
+ let result;
15
+ try {
16
+ context[Enter]();
17
+ const op = operation(context);
18
+ result = isResult(op) ? op : Ok(op);
19
+ }
20
+ catch (e) {
21
+ result = normalizeError(e);
22
+ }
23
+ finally {
24
+ context[Exit]();
25
+ }
26
+ return result;
27
+ }
28
+ export async function asyncUsing(context, operation, normalizeError = (e) => Err(e)) {
29
+ context = typeof context == "function" ? await context() : context;
30
+ let result;
31
+ try {
32
+ context[Enter]();
33
+ const op = await operation(context);
34
+ result = isResult(op) ? op : Ok(op);
35
+ }
36
+ catch (e) {
37
+ result = normalizeError(e);
38
+ }
39
+ finally {
40
+ context[Exit]();
41
+ }
42
+ return result;
43
+ }
@@ -1 +1 @@
1
- export {};
1
+ export {};
@@ -1,46 +1,46 @@
1
- import { Enter, Exit, using } from "./context.js";
2
- import { Err, isErr, isOk, Ok, unwrap } from "./result.js";
3
- import { describe, it } from "./scope/describe.js";
4
- import { expect } from "./scope/expect.js";
5
- describe("Context", () => {
6
- it("performs an operation using a context", () => {
7
- const context = TestContext();
8
- const result = using(context, () => Ok(5));
9
- expect(unwrap(result)).toBe(5);
10
- expect(context.initialized).toBe(true);
11
- expect(context.completed).toBe(true);
12
- });
13
- it("reports the result of a thrown error", () => {
14
- const context = TestContext();
15
- const result = using(context, () => {
16
- throw new Error("Failed");
17
- });
18
- expect(isErr(result)).toBe(true);
19
- expect(Err(result)).toMatchObject({
20
- message: "Failed",
21
- });
22
- });
23
- it("passes the context to the operation", () => {
24
- const op = using(TestContext, ({ initialized, completed }) => ({
25
- initialized,
26
- completed,
27
- }));
28
- expect(isOk(op)).toBe(true);
29
- const { completed, initialized } = unwrap(op);
30
- expect(initialized).toBe(true);
31
- expect(completed).toBe(false);
32
- });
33
- });
34
- function TestContext() {
35
- const context = {
36
- [Enter]: () => {
37
- context.initialized = true;
38
- },
39
- [Exit]: () => {
40
- context.completed = true;
41
- },
42
- initialized: false,
43
- completed: false,
44
- };
45
- return context;
46
- }
1
+ import { Enter, Exit, using } from "./context.js";
2
+ import { Err, isErr, isOk, Ok, unwrap } from "./result.js";
3
+ import { describe, it } from "./scope/describe.js";
4
+ import { expect } from "./scope/expect.js";
5
+ describe("Context", () => {
6
+ it("performs an operation using a context", () => {
7
+ const context = TestContext();
8
+ const result = using(context, () => Ok(5));
9
+ expect(unwrap(result)).toBe(5);
10
+ expect(context.initialized).toBe(true);
11
+ expect(context.completed).toBe(true);
12
+ });
13
+ it("reports the result of a thrown error", () => {
14
+ const context = TestContext();
15
+ const result = using(context, () => {
16
+ throw new Error("Failed");
17
+ });
18
+ expect(isErr(result)).toBe(true);
19
+ expect(Err(result)).toMatchObject({
20
+ message: "Failed",
21
+ });
22
+ });
23
+ it("passes the context to the operation", () => {
24
+ const op = using(TestContext, ({ initialized, completed }) => ({
25
+ initialized,
26
+ completed,
27
+ }));
28
+ expect(isOk(op)).toBe(true);
29
+ const { completed, initialized } = unwrap(op);
30
+ expect(initialized).toBe(true);
31
+ expect(completed).toBe(false);
32
+ });
33
+ });
34
+ function TestContext() {
35
+ const context = {
36
+ [Enter]: () => {
37
+ context.initialized = true;
38
+ },
39
+ [Exit]: () => {
40
+ context.completed = true;
41
+ },
42
+ initialized: false,
43
+ completed: false,
44
+ };
45
+ return context;
46
+ }
@@ -1 +1 @@
1
- export declare function debounce(fn: (...args: any[]) => any, ms?: number): (...args: Parameters<typeof fn>) => ReturnType<typeof fn>;
1
+ export declare function debounce(fn: (...args: any[]) => any, ms?: number): (...args: Parameters<typeof fn>) => ReturnType<typeof fn>;
package/build/debounce.js CHANGED
@@ -1,7 +1,7 @@
1
- export function debounce(fn, ms = 32) {
2
- let timer;
3
- return (...args) => {
4
- clearTimeout(timer);
5
- timer = setTimeout(() => (clearTimeout(timer), fn(...args)), ms);
6
- };
7
- }
1
+ export function debounce(fn, ms = 32) {
2
+ let timer;
3
+ return (...args) => {
4
+ clearTimeout(timer);
5
+ timer = setTimeout(() => (clearTimeout(timer), fn(...args)), ms);
6
+ };
7
+ }
@@ -1,5 +1,5 @@
1
- export declare type Display = string | {
2
- toString(): string;
3
- };
4
- export declare const isDisplay: (a: unknown) => a is Display;
5
- export declare const display: (a: unknown | Display) => string;
1
+ export declare type Display = string | {
2
+ toString(): string;
3
+ };
4
+ export declare const isDisplay: (a: unknown) => a is Display;
5
+ export declare const display: (a: unknown | Display) => string;
package/build/display.js CHANGED
@@ -1,11 +1,11 @@
1
- export const isDisplay = (/** @type unknown */ a) => typeof a.toString === "function" ||
2
- typeof a === "string";
3
- export const display = (a) => {
4
- if (isDisplay(a)) {
5
- const str = a.toString();
6
- if (str === "[object Object]")
7
- return JSON.stringify(a);
8
- return str;
9
- }
10
- return JSON.stringify(a);
11
- };
1
+ export const isDisplay = (/** @type unknown */ a) => typeof a.toString === "function" ||
2
+ typeof a === "string";
3
+ export const display = (a) => {
4
+ if (isDisplay(a)) {
5
+ const str = a.toString();
6
+ if (str === "[object Object]")
7
+ return JSON.stringify(a);
8
+ return str;
9
+ }
10
+ return JSON.stringify(a);
11
+ };
@@ -1,11 +1,11 @@
1
- import { Properties } from "../types/css.js";
2
- import { Side, Size } from "./constants.js";
3
- export declare function rounded(size?: Size, side?: Side): Properties<0 | (string & {}), string & {}>;
4
- export declare function border({ side, style, radius, width, color, }: {
5
- side?: Side;
6
- style?: "solid" | "dotted" | "dashed" | "double" | "none";
7
- radius?: Size;
8
- width?: 0 | 1 | 2 | 4 | 8;
9
- color?: string;
10
- }): {};
11
- export declare function inset(width: 0 | 1 | 2 | 4 | 8, color1?: string, color2?: string): {};
1
+ import { Properties } from "../types/css.js";
2
+ import { Side, Size } from "./constants.js";
3
+ export declare function rounded(size?: Size, side?: Side): Properties<0 | (string & {}), string & {}>;
4
+ export declare function border({ side, style, radius, width, color, }: {
5
+ side?: Side;
6
+ style?: "solid" | "dotted" | "dashed" | "double" | "none";
7
+ radius?: Size;
8
+ width?: 0 | 1 | 2 | 4 | 8;
9
+ color?: string;
10
+ }): {};
11
+ export declare function inset(width: 0 | 1 | 2 | 4 | 8, color1?: string, color2?: string): {};
@@ -1,27 +1,27 @@
1
- import { isSide, getSize, getSide } from "./core.js";
2
- export function rounded(size = "", side = "") {
3
- if (isSide(size)) {
4
- side = size;
5
- size = "";
6
- }
7
- const sized = getSize(size);
8
- return getSide(side).reduce((prev, curr) => {
9
- if (curr === "") {
10
- prev.borderRadius = sized;
11
- }
12
- else {
13
- // @ts-ignore
14
- prev[`border${curr}Radius`] = sized;
15
- }
16
- return prev;
17
- }, {});
18
- }
19
- export function border({ side = "", style = "solid", radius = "", width = 1, color = "black", }) {
20
- return {};
21
- }
22
- export function inset(width, color1 = "gray", color2 = "lightgray") {
23
- return {
24
- ...border({ side: "tl", width, color: color1, radius: "none" }),
25
- ...border({ side: "br", width, color: color2, radius: "none" }),
26
- };
27
- }
1
+ import { isSide, getSize, getSide } from "./core.js";
2
+ export function rounded(size = "", side = "") {
3
+ if (isSide(size)) {
4
+ side = size;
5
+ size = "";
6
+ }
7
+ const sized = getSize(size);
8
+ return getSide(side).reduce((prev, curr) => {
9
+ if (curr === "") {
10
+ prev.borderRadius = sized;
11
+ }
12
+ else {
13
+ // @ts-ignore
14
+ prev[`border${curr}Radius`] = sized;
15
+ }
16
+ return prev;
17
+ }, {});
18
+ }
19
+ export function border({ side = "", style = "solid", radius = "", width = 1, color = "black", }) {
20
+ return {};
21
+ }
22
+ export function inset(width, color1 = "gray", color2 = "lightgray") {
23
+ return {
24
+ ...border({ side: "tl", width, color: color1, radius: "none" }),
25
+ ...border({ side: "br", width, color: color2, radius: "none" }),
26
+ };
27
+ }
@@ -1,31 +1,31 @@
1
- export declare const Sizes: {
2
- none: string;
3
- sm: string;
4
- "": string;
5
- md: string;
6
- lg: string;
7
- xl: string;
8
- "2xl": string;
9
- "3xl": string;
10
- full: string;
11
- };
12
- export declare const Sides: {
13
- "": string;
14
- t: string;
15
- r: string;
16
- l: string;
17
- b: string;
18
- tl: string;
19
- tr: string;
20
- bl: string;
21
- br: string;
22
- };
23
- export declare const Widths: {
24
- "1/4": string;
25
- "1/2": string;
26
- "3/4": string;
27
- full: string;
28
- };
29
- export declare type Size = keyof typeof Sizes;
30
- export declare type Side = keyof typeof Sides;
31
- export declare type Width = keyof typeof Widths;
1
+ export declare const Sizes: {
2
+ none: string;
3
+ sm: string;
4
+ "": string;
5
+ md: string;
6
+ lg: string;
7
+ xl: string;
8
+ "2xl": string;
9
+ "3xl": string;
10
+ full: string;
11
+ };
12
+ export declare const Sides: {
13
+ "": string;
14
+ t: string;
15
+ r: string;
16
+ l: string;
17
+ b: string;
18
+ tl: string;
19
+ tr: string;
20
+ bl: string;
21
+ br: string;
22
+ };
23
+ export declare const Widths: {
24
+ "1/4": string;
25
+ "1/2": string;
26
+ "3/4": string;
27
+ full: string;
28
+ };
29
+ export declare type Size = keyof typeof Sizes;
30
+ export declare type Side = keyof typeof Sides;
31
+ export declare type Width = keyof typeof Widths;