@davidsouther/jiffies 1.1.0 → 2.0.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.
- package/{build → lib/cjs}/assert.d.ts +23 -23
- package/lib/cjs/assert.js +40 -0
- package/{build → lib/cjs}/case.d.ts +1 -1
- package/lib/cjs/case.js +9 -0
- package/{build → lib/cjs}/components/button_bar.d.ts +8 -8
- package/lib/cjs/components/button_bar.js +29 -0
- package/{build → lib/cjs}/components/inline_edit.d.ts +12 -12
- package/lib/cjs/components/inline_edit.js +51 -0
- package/{build → lib/cjs}/components/logger.d.ts +6 -6
- package/lib/cjs/components/logger.js +27 -0
- package/lib/cjs/components/select.d.ts +10 -0
- package/lib/cjs/components/select.js +6 -0
- package/lib/cjs/components/test.d.ts +1 -0
- package/lib/cjs/components/test.js +7 -0
- package/{build → lib/cjs}/components/virtual_scroll.d.ts +40 -40
- package/lib/cjs/components/virtual_scroll.js +102 -0
- package/{build → lib/cjs}/components/virtual_scroll.test.d.ts +1 -1
- package/lib/cjs/components/virtual_scroll.test.js +22 -0
- package/{build → lib/cjs}/context.d.ts +15 -15
- package/lib/cjs/context.js +48 -0
- package/{build → lib/cjs}/context.test.d.ts +1 -1
- package/lib/cjs/context.test.js +48 -0
- package/{build → lib/cjs}/debounce.d.ts +1 -1
- package/lib/cjs/debounce.js +11 -0
- package/lib/cjs/diff.d.ts +15 -0
- package/lib/cjs/diff.js +58 -0
- package/{build/components/test.d.ts → lib/cjs/diff.test.d.ts} +1 -1
- package/lib/cjs/diff.test.js +41 -0
- package/{build → lib/cjs}/display.d.ts +5 -5
- package/lib/cjs/display.js +16 -0
- package/{build → lib/cjs}/dom/css/border.d.ts +11 -11
- package/lib/cjs/dom/css/border.js +33 -0
- package/{build → lib/cjs}/dom/css/constants.d.ts +31 -31
- package/lib/cjs/dom/css/constants.js +31 -0
- package/{build → lib/cjs}/dom/css/core.d.ts +5 -5
- package/lib/cjs/dom/css/core.js +31 -0
- package/{build → lib/cjs}/dom/css/fstyle.d.ts +5 -5
- package/lib/cjs/dom/css/fstyle.js +36 -0
- package/{build → lib/cjs}/dom/css/sizing.d.ts +5 -5
- package/lib/cjs/dom/css/sizing.js +14 -0
- package/{build → lib/cjs}/dom/dom.d.ts +27 -26
- package/lib/cjs/dom/dom.js +110 -0
- package/{build → lib/cjs}/dom/fc.d.ts +14 -14
- package/lib/cjs/dom/fc.js +39 -0
- package/{build → lib/cjs}/dom/fc.test.d.ts +1 -1
- package/lib/cjs/dom/fc.test.js +23 -0
- package/{build → lib/cjs}/dom/form/form.app.d.ts +1 -1
- package/lib/cjs/dom/form/form.app.js +27 -0
- package/{build → lib/cjs}/dom/form/form.d.ts +26 -26
- package/lib/cjs/dom/form/form.js +49 -0
- package/{build → lib/cjs}/dom/form/form.test.d.ts +0 -0
- package/{build → lib/cjs}/dom/form/form.test.js +1 -1
- package/{build → lib/cjs}/dom/html.d.ts +113 -113
- package/lib/cjs/dom/html.js +119 -0
- package/{build → lib/cjs}/dom/html.test.d.ts +1 -1
- package/lib/cjs/dom/html.test.js +60 -0
- package/lib/cjs/dom/observable.d.ts +2 -0
- package/lib/cjs/dom/observable.js +10 -0
- package/{build/observable → lib/cjs/dom}/observable.test.d.ts +1 -1
- package/lib/cjs/dom/observable.test.js +35 -0
- package/{build → lib/cjs}/dom/provide.d.ts +3 -3
- package/lib/cjs/dom/provide.js +12 -0
- package/{build → lib/cjs}/dom/router/link.d.ts +6 -6
- package/lib/cjs/dom/router/link.js +7 -0
- package/{build → lib/cjs}/dom/router/router.d.ts +12 -12
- package/lib/cjs/dom/router/router.js +52 -0
- package/{build → lib/cjs}/dom/svg.d.ts +64 -64
- package/lib/cjs/dom/svg.js +69 -0
- package/lib/cjs/dom/test.d.ts +1 -0
- package/lib/cjs/dom/test.js +13 -0
- package/{build → lib/cjs}/dom/types/css.d.ts +6612 -6612
- package/lib/cjs/dom/types/css.js +24 -0
- package/{build → lib/cjs}/dom/types/dom.d.ts +0 -0
- package/{build → lib/cjs}/dom/types/dom.js +1 -1
- package/{build → lib/cjs}/dom/types/html.d.ts +616 -616
- package/lib/cjs/dom/types/html.js +2 -0
- package/{build → lib/cjs}/dom/xml.d.ts +1 -1
- package/lib/cjs/dom/xml.js +8 -0
- package/{build → lib/cjs}/equal.d.ts +5 -5
- package/lib/cjs/equal.js +43 -0
- package/{build → lib/cjs}/equal.test.d.ts +1 -1
- package/lib/cjs/equal.test.js +22 -0
- package/{build → lib/cjs}/flags.d.ts +7 -7
- package/lib/cjs/flags.js +52 -0
- package/{build → lib/cjs}/flags.test.d.ts +1 -1
- package/lib/cjs/flags.test.js +37 -0
- package/{build → lib/cjs}/fs.d.ts +48 -48
- package/lib/cjs/fs.js +151 -0
- package/{build → lib/cjs}/fs.test.d.ts +1 -1
- package/lib/cjs/fs.test.js +45 -0
- package/{build → lib/cjs}/generator.d.ts +1 -1
- package/lib/cjs/generator.js +14 -0
- package/{build → lib/cjs}/generator.test.d.ts +1 -1
- package/lib/cjs/generator.test.js +26 -0
- package/{build → lib/cjs}/is_browser.d.ts +1 -1
- package/lib/cjs/is_browser.js +4 -0
- package/{build → lib/cjs}/loader.d.mts +22 -22
- package/lib/cjs/loader.mjs +40 -0
- package/{build → lib/cjs}/lock.d.ts +1 -1
- package/lib/cjs/lock.js +27 -0
- package/{build → lib/cjs}/lock.test.d.ts +1 -1
- package/lib/cjs/lock.test.js +18 -0
- package/{build → lib/cjs}/log.d.ts +26 -26
- package/lib/cjs/log.js +54 -0
- package/lib/cjs/observable/event.d.ts +35 -0
- package/lib/cjs/observable/event.js +61 -0
- package/lib/cjs/observable/observable.d.ts +132 -0
- package/lib/cjs/observable/observable.js +363 -0
- package/lib/cjs/observable/observable.test.d.ts +1 -0
- package/lib/cjs/observable/observable.test.js +65 -0
- package/{build → lib/cjs}/range.d.ts +1 -1
- package/lib/cjs/range.js +11 -0
- package/{build → lib/cjs}/result.d.ts +31 -31
- package/lib/cjs/result.js +80 -0
- package/{build → lib/cjs}/result.test.d.ts +1 -1
- package/lib/cjs/result.test.js +73 -0
- package/{build → lib/cjs}/safe.d.ts +1 -1
- package/lib/cjs/safe.js +14 -0
- package/{build → lib/cjs}/scope/describe.d.ts +18 -18
- package/lib/cjs/scope/describe.js +73 -0
- package/{build → lib/cjs}/scope/display/console.d.ts +2 -2
- package/lib/cjs/scope/display/console.js +25 -0
- package/{build → lib/cjs}/scope/display/dom.d.ts +3 -3
- package/lib/cjs/scope/display/dom.js +30 -0
- package/{build → lib/cjs}/scope/display/junit.d.ts +2 -2
- package/lib/cjs/scope/display/junit.js +21 -0
- package/{build → lib/cjs}/scope/execute.d.ts +12 -12
- package/lib/cjs/scope/execute.js +91 -0
- package/{build → lib/cjs}/scope/expect.d.ts +23 -23
- package/lib/cjs/scope/expect.js +114 -0
- package/{build → lib/cjs}/scope/fix.d.ts +4 -4
- package/lib/cjs/scope/fix.js +26 -0
- package/{build → lib/cjs}/scope/index.d.ts +3 -3
- package/lib/cjs/scope/index.js +15 -0
- package/{build → lib/cjs}/scope/scope.d.ts +17 -17
- package/lib/cjs/scope/scope.js +2 -0
- package/lib/cjs/scope/state.d.ts +1 -0
- package/lib/cjs/scope/state.js +11 -0
- package/{build → lib/cjs}/server/http/apps.d.ts +5 -5
- package/lib/cjs/server/http/apps.js +27 -0
- package/{build → lib/cjs}/server/http/css.d.ts +5 -5
- package/lib/cjs/server/http/css.js +54 -0
- package/{build → lib/cjs}/server/http/index.d.ts +21 -21
- package/lib/cjs/server/http/index.js +77 -0
- package/{build → lib/cjs}/server/http/response.d.ts +4 -4
- package/lib/cjs/server/http/response.js +45 -0
- package/{build → lib/cjs}/server/http/sitemap.d.ts +2 -2
- package/lib/cjs/server/http/sitemap.js +46 -0
- package/{build → lib/cjs}/server/http/static.d.ts +2 -2
- package/lib/cjs/server/http/static.js +25 -0
- package/{build → lib/cjs}/server/http/typescript.d.ts +5 -5
- package/lib/cjs/server/http/typescript.js +44 -0
- package/{build → lib/cjs}/server/main.d.ts +2 -2
- package/lib/cjs/server/main.js +14 -0
- package/{build → lib/cjs}/test.d.mts +2 -2
- package/lib/cjs/test.mjs +28 -0
- package/{build → lib/cjs}/test_all.d.ts +9 -7
- package/lib/cjs/test_all.js +30 -0
- package/{build → lib/cjs}/transpile.d.mts +3 -3
- package/lib/cjs/transpile.mjs +22 -0
- package/lib/cjs/tsconfig.tsbuildinfo +1 -0
- package/lib/esm/assert.d.ts +23 -0
- package/{build → lib/esm}/assert.js +33 -33
- package/lib/esm/case.d.ts +1 -0
- package/{build → lib/esm}/case.js +5 -5
- package/lib/esm/components/button_bar.d.ts +8 -0
- package/{build → lib/esm}/components/button_bar.js +27 -27
- package/lib/esm/components/inline_edit.d.ts +12 -0
- package/{build → lib/esm}/components/inline_edit.js +48 -48
- package/lib/esm/components/logger.d.ts +6 -0
- package/{build → lib/esm}/components/logger.js +22 -22
- package/lib/esm/components/select.d.ts +10 -0
- package/{build → lib/esm}/components/select.js +3 -3
- package/lib/esm/components/test.d.ts +1 -0
- package/lib/esm/components/test.js +3 -0
- package/lib/esm/components/virtual_scroll.d.ts +40 -0
- package/{build → lib/esm}/components/virtual_scroll.js +94 -94
- package/lib/esm/components/virtual_scroll.test.d.ts +1 -0
- package/{build → lib/esm}/components/virtual_scroll.test.js +20 -21
- package/lib/esm/context.d.ts +15 -0
- package/{build → lib/esm}/context.js +43 -43
- package/lib/esm/context.test.d.ts +1 -0
- package/{build → lib/esm}/context.test.js +46 -46
- package/lib/esm/debounce.d.ts +1 -0
- package/{build → lib/esm}/debounce.js +7 -7
- package/lib/esm/diff.d.ts +15 -0
- package/lib/esm/diff.js +54 -0
- package/lib/esm/diff.test.d.ts +1 -0
- package/lib/esm/diff.test.js +39 -0
- package/lib/esm/display.d.ts +5 -0
- package/{build → lib/esm}/display.js +11 -11
- package/lib/esm/dom/css/border.d.ts +11 -0
- package/{build → lib/esm}/dom/css/border.js +27 -27
- package/lib/esm/dom/css/constants.d.ts +31 -0
- package/{build → lib/esm}/dom/css/constants.js +28 -28
- package/lib/esm/dom/css/core.d.ts +5 -0
- package/{build → lib/esm}/dom/css/core.js +24 -24
- package/lib/esm/dom/css/fstyle.d.ts +5 -0
- package/{build → lib/esm}/dom/css/fstyle.js +32 -32
- package/lib/esm/dom/css/sizing.d.ts +5 -0
- package/{build → lib/esm}/dom/css/sizing.js +10 -10
- package/lib/esm/dom/dom.d.ts +27 -0
- package/{build → lib/esm}/dom/dom.js +104 -95
- package/lib/esm/dom/fc.d.ts +14 -0
- package/{build → lib/esm}/dom/fc.js +35 -36
- package/lib/esm/dom/fc.test.d.ts +1 -0
- package/{build → lib/esm}/dom/fc.test.js +21 -21
- package/lib/esm/dom/form/form.app.d.ts +1 -0
- package/{build → lib/esm}/dom/form/form.app.js +23 -23
- package/lib/esm/dom/form/form.d.ts +26 -0
- package/{build → lib/esm}/dom/form/form.js +34 -34
- package/lib/esm/dom/form/form.test.d.ts +0 -0
- package/lib/esm/dom/form/form.test.js +1 -0
- package/lib/esm/dom/html.d.ts +113 -0
- package/{build → lib/esm}/dom/html.js +114 -114
- package/lib/esm/dom/html.test.d.ts +1 -0
- package/{build → lib/esm}/dom/html.test.js +58 -58
- package/lib/esm/dom/observable.d.ts +2 -0
- package/lib/esm/dom/observable.js +6 -0
- package/lib/esm/dom/observable.test.d.ts +1 -0
- package/lib/esm/dom/observable.test.js +33 -0
- package/lib/esm/dom/provide.d.ts +3 -0
- package/{build → lib/esm}/dom/provide.js +7 -7
- package/lib/esm/dom/router/link.d.ts +6 -0
- package/{build → lib/esm}/dom/router/link.js +3 -3
- package/lib/esm/dom/router/router.d.ts +12 -0
- package/{build → lib/esm}/dom/router/router.js +49 -49
- package/lib/esm/dom/svg.d.ts +64 -0
- package/{build → lib/esm}/dom/svg.js +65 -65
- package/lib/esm/dom/test.d.ts +1 -0
- package/lib/esm/dom/test.js +9 -0
- package/lib/esm/dom/types/css.d.ts +6612 -0
- package/{build → lib/esm}/dom/types/css.js +23 -23
- package/lib/esm/dom/types/dom.d.ts +0 -0
- package/lib/esm/dom/types/dom.js +1 -0
- package/lib/esm/dom/types/html.d.ts +616 -0
- package/{build → lib/esm}/dom/types/html.js +1 -1
- package/lib/esm/dom/xml.d.ts +1 -0
- package/{build → lib/esm}/dom/xml.js +4 -4
- package/lib/esm/equal.d.ts +5 -0
- package/{build → lib/esm}/equal.js +37 -37
- package/lib/esm/equal.test.d.ts +1 -0
- package/{build → lib/esm}/equal.test.js +20 -20
- package/lib/esm/flags.d.ts +7 -0
- package/{build → lib/esm}/flags.js +48 -48
- package/lib/esm/flags.test.d.ts +1 -0
- package/{build → lib/esm}/flags.test.js +35 -35
- package/lib/esm/fs.d.ts +48 -0
- package/{build → lib/esm}/fs.js +144 -144
- package/lib/esm/fs.test.d.ts +1 -0
- package/{build → lib/esm}/fs.test.js +43 -43
- package/lib/esm/generator.d.ts +1 -0
- package/{build → lib/esm}/generator.js +10 -10
- package/lib/esm/generator.test.d.ts +1 -0
- package/{build → lib/esm}/generator.test.js +24 -24
- package/lib/esm/is_browser.d.ts +1 -0
- package/{build → lib/esm}/is_browser.js +1 -1
- package/lib/esm/loader.d.mts +22 -0
- package/{build → lib/esm}/loader.mjs +35 -35
- package/lib/esm/lock.d.ts +1 -0
- package/{build → lib/esm}/lock.js +23 -23
- package/lib/esm/lock.test.d.ts +1 -0
- package/{build → lib/esm}/lock.test.js +16 -16
- package/lib/esm/log.d.ts +26 -0
- package/{build → lib/esm}/log.js +46 -46
- package/lib/esm/observable/event.d.ts +35 -0
- package/lib/esm/observable/event.js +46 -0
- package/lib/esm/observable/observable.d.ts +132 -0
- package/lib/esm/observable/observable.js +343 -0
- package/lib/esm/observable/observable.test.d.ts +1 -0
- package/lib/esm/observable/observable.test.js +63 -0
- package/lib/esm/range.d.ts +1 -0
- package/{build → lib/esm}/range.js +7 -7
- package/lib/esm/result.d.ts +31 -0
- package/{build → lib/esm}/result.js +65 -65
- package/lib/esm/result.test.d.ts +1 -0
- package/{build → lib/esm}/result.test.js +71 -71
- package/lib/esm/safe.d.ts +1 -0
- package/{build → lib/esm}/safe.js +10 -10
- package/lib/esm/scope/describe.d.ts +18 -0
- package/{build → lib/esm}/scope/describe.js +60 -61
- package/lib/esm/scope/display/console.d.ts +2 -0
- package/{build → lib/esm}/scope/display/console.js +21 -21
- package/lib/esm/scope/display/dom.d.ts +3 -0
- package/{build → lib/esm}/scope/display/dom.js +26 -26
- package/lib/esm/scope/display/junit.d.ts +2 -0
- package/{build → lib/esm}/scope/display/junit.js +17 -17
- package/lib/esm/scope/execute.d.ts +12 -0
- package/{build → lib/esm}/scope/execute.js +85 -85
- package/lib/esm/scope/expect.d.ts +23 -0
- package/{build → lib/esm}/scope/expect.js +108 -108
- package/lib/esm/scope/fix.d.ts +4 -0
- package/{build → lib/esm}/scope/fix.js +22 -22
- package/lib/esm/scope/index.d.ts +3 -0
- package/{build → lib/esm}/scope/index.js +3 -3
- package/lib/esm/scope/scope.d.ts +17 -0
- package/{build → lib/esm}/scope/scope.js +1 -1
- package/lib/esm/scope/state.d.ts +1 -0
- package/lib/esm/scope/state.js +7 -0
- package/lib/esm/server/http/apps.d.ts +5 -0
- package/{build → lib/esm}/server/http/apps.js +23 -23
- package/lib/esm/server/http/css.d.ts +5 -0
- package/{build → lib/esm}/server/http/css.js +50 -50
- package/lib/esm/server/http/index.d.ts +21 -0
- package/{build → lib/esm}/server/http/index.js +73 -73
- package/lib/esm/server/http/response.d.ts +4 -0
- package/{build → lib/esm}/server/http/response.js +40 -40
- package/lib/esm/server/http/sitemap.d.ts +2 -0
- package/{build → lib/esm}/server/http/sitemap.js +42 -42
- package/lib/esm/server/http/static.d.ts +2 -0
- package/{build → lib/esm}/server/http/static.js +21 -21
- package/lib/esm/server/http/typescript.d.ts +5 -0
- package/{build → lib/esm}/server/http/typescript.js +40 -40
- package/lib/esm/server/main.d.ts +2 -0
- package/{build → lib/esm}/server/main.js +12 -9
- package/lib/esm/test.d.mts +2 -0
- package/lib/esm/test.mjs +26 -0
- package/lib/esm/test_all.d.ts +9 -0
- package/{build → lib/esm}/test_all.js +28 -18
- package/lib/esm/transpile.d.mts +3 -0
- package/{build → lib/esm}/transpile.mjs +18 -18
- package/lib/esm/tsconfig.tsbuildinfo +1 -0
- package/package.json +13 -14
- package/src/assert.ts +1 -1
- package/src/components/button_bar.ts +3 -3
- package/src/components/inline_edit.ts +3 -3
- package/src/components/logger.ts +3 -3
- package/src/components/select.ts +3 -3
- package/src/components/test.js +3 -2
- package/src/context.ts +3 -3
- package/src/diff.ts +2 -2
- package/src/dom/css/border.ts +3 -3
- package/src/dom/css/core.ts +1 -1
- package/src/dom/css/fstyle.ts +2 -2
- package/src/dom/css/sizing.ts +1 -1
- package/src/dom/dom.ts +1 -1
- package/src/dom/fc.test.ts +3 -3
- package/src/dom/fc.ts +1 -1
- package/src/dom/form/form.app.ts +2 -2
- package/src/dom/form/form.ts +3 -3
- package/src/dom/html.test.ts +3 -3
- package/src/dom/html.ts +1 -1
- package/src/dom/observable.test.ts +6 -6
- package/src/dom/observable.ts +1 -1
- package/src/dom/provide.ts +1 -1
- package/src/dom/router/link.ts +2 -2
- package/src/dom/router/router.ts +2 -2
- package/src/dom/svg.ts +1 -1
- package/src/dom/test.ts +8 -6
- package/src/dom/types/html.ts +1 -1
- package/src/equal.ts +1 -1
- package/src/flags.ts +1 -1
- package/src/fs.ts +4 -4
- package/src/index.html +6 -6
- package/src/observable/event.ts +2 -2
- package/src/observable/observable.test.ts +2 -2
- package/src/observable/observable.ts +72 -12
- package/src/pico/_variables.scss +1 -1
- package/src/pico/layout/_sectioning.scss +2 -0
- package/src/result.ts +1 -1
- package/src/scope/describe.ts +2 -5
- package/src/scope/display/console.ts +4 -4
- package/src/scope/display/dom.ts +6 -6
- package/src/scope/display/junit.ts +3 -3
- package/src/scope/execute.ts +2 -2
- package/src/scope/expect.ts +3 -3
- package/src/scope/state.ts +10 -0
- package/src/server/http/sitemap.ts +1 -1
- package/src/server/main.ts +9 -2
- package/src/test.mjs +22 -18
- package/src/test_all.ts +10 -0
- package/build/components/select.d.ts +0 -13
- package/build/components/test.js +0 -2
- package/build/dom/test.d.ts +0 -1
- package/build/dom/test.js +0 -2
- package/build/observable/observable.d.ts +0 -83
- package/build/observable/observable.js +0 -148
- package/build/observable/observable.test.js +0 -21
- package/build/test.mjs +0 -23
|
@@ -0,0 +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,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
|
|
6
|
-
if (context.length
|
|
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
|
|
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
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
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
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare function debounce(fn: (...args: any[]) => any, ms?: number): (...args: Parameters<typeof fn>) => ReturnType<typeof fn>;
|
|
@@ -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
|
+
}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
export declare const DiffA: unique symbol;
|
|
2
|
+
export declare const DiffB: unique symbol;
|
|
3
|
+
export declare type DiffIndex = string | number;
|
|
4
|
+
export declare type DiffPrimitive = string | number | boolean | null | undefined;
|
|
5
|
+
interface DiffEntry {
|
|
6
|
+
key: DiffIndex;
|
|
7
|
+
left: DiffPrimitive;
|
|
8
|
+
right: DiffPrimitive;
|
|
9
|
+
}
|
|
10
|
+
interface DiffList {
|
|
11
|
+
key: DiffIndex;
|
|
12
|
+
children: (DiffEntry | DiffList)[];
|
|
13
|
+
}
|
|
14
|
+
export declare function diff<T>(a: Partial<T>, b: Partial<T>): (DiffEntry | DiffList)[];
|
|
15
|
+
export {};
|
package/lib/esm/diff.js
ADDED
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
import { range } from "./range.js";
|
|
2
|
+
import { isSome, None, Some } from "./result.js";
|
|
3
|
+
export const DiffA = Symbol("A");
|
|
4
|
+
export const DiffB = Symbol("B");
|
|
5
|
+
function doDiff(va, vb, k) {
|
|
6
|
+
if (Array.isArray(va)) {
|
|
7
|
+
// @ts-ignore
|
|
8
|
+
return diffArray(va, vb, k);
|
|
9
|
+
}
|
|
10
|
+
if (typeof va === "object") {
|
|
11
|
+
const d = diffObject(va, vb, k);
|
|
12
|
+
if (d.children.length === 0) {
|
|
13
|
+
return None();
|
|
14
|
+
}
|
|
15
|
+
else {
|
|
16
|
+
return Some(d);
|
|
17
|
+
}
|
|
18
|
+
}
|
|
19
|
+
if (Object.is(va, vb)) {
|
|
20
|
+
return None();
|
|
21
|
+
}
|
|
22
|
+
else {
|
|
23
|
+
// @ts-ignore
|
|
24
|
+
return { key: k, left: va, right: vb };
|
|
25
|
+
}
|
|
26
|
+
}
|
|
27
|
+
function diffArray(a, b, key) {
|
|
28
|
+
const indexes = Math.max(a.length, b.length);
|
|
29
|
+
const children = range(0, indexes)
|
|
30
|
+
.map((i) => doDiff(a[i], b[i], i))
|
|
31
|
+
.filter(isSome);
|
|
32
|
+
return children.length > 0 ? { key, children } : None();
|
|
33
|
+
}
|
|
34
|
+
function diffObject(a, b, key = "") {
|
|
35
|
+
const keys = new Set([...Object.keys(a), ...Object.keys(b)]);
|
|
36
|
+
const children = [...keys]
|
|
37
|
+
// @ts-ignore
|
|
38
|
+
.map((k) => doDiff(a[k], b[k], k))
|
|
39
|
+
.filter(isSome);
|
|
40
|
+
return {
|
|
41
|
+
key,
|
|
42
|
+
children,
|
|
43
|
+
};
|
|
44
|
+
}
|
|
45
|
+
export function diff(a, b) {
|
|
46
|
+
if (typeof a != "object" && !Object.is(a, b)) {
|
|
47
|
+
// @ts-ignore
|
|
48
|
+
return [{ key: "", left: a, right: b }];
|
|
49
|
+
}
|
|
50
|
+
return (Array.isArray(a)
|
|
51
|
+
? // @ts-ignore
|
|
52
|
+
diffArray(a, b, "") ?? { children: [] }
|
|
53
|
+
: diffObject(a, b, "")).children;
|
|
54
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
import { diff } from "./diff.js";
|
|
2
|
+
import { describe, it } from "./scope/describe.js";
|
|
3
|
+
import { expect } from "./scope/expect.js";
|
|
4
|
+
describe("diff", () => {
|
|
5
|
+
it("diffs primitives", () => {
|
|
6
|
+
const diffed = diff(1, 2);
|
|
7
|
+
expect(diffed).toEqual([{ key: "", left: 1, right: 2 }]);
|
|
8
|
+
});
|
|
9
|
+
it("diffs objects", () => {
|
|
10
|
+
const diffed = diff({ a: 1, b: 2 }, { a: 2, b: 2 });
|
|
11
|
+
expect(diffed).toEqual([{ key: "a", left: 1, right: 2 }]);
|
|
12
|
+
});
|
|
13
|
+
it("diffs nested objects", () => {
|
|
14
|
+
const diffed = diff({ a: { c: 1 }, b: 2 }, { a: { c: 2 }, b: 2 });
|
|
15
|
+
expect(diffed).toEqual([
|
|
16
|
+
{ key: "a", children: [{ key: "c", left: 1, right: 2 }] },
|
|
17
|
+
]);
|
|
18
|
+
});
|
|
19
|
+
it("diffs missing sides", () => {
|
|
20
|
+
const diffed = diff({ a: 1 }, { b: 2 });
|
|
21
|
+
expect(diffed).toEqual([
|
|
22
|
+
{ key: "a", left: 1, right: undefined },
|
|
23
|
+
{ key: "b", left: undefined, right: 2 },
|
|
24
|
+
]);
|
|
25
|
+
});
|
|
26
|
+
it("diffs arrays", () => {
|
|
27
|
+
const diffed = diff([1, 2, 3], [1, 4, 3]);
|
|
28
|
+
expect(diffed).toEqual([{ key: 1, left: 2, right: 4 }]);
|
|
29
|
+
});
|
|
30
|
+
it("diffs objects in an array", () => {
|
|
31
|
+
const diffed = diff([{ a: { b: 1 } }, { a: { b: 2 } }, { a: { b: 3 } }], [{ a: { b: 1 } }, { a: { b: 4 } }, { a: { b: 3 } }]);
|
|
32
|
+
expect(diffed).toEqual([
|
|
33
|
+
{
|
|
34
|
+
key: 1,
|
|
35
|
+
children: [{ key: "a", children: [{ key: "b", left: 2, right: 4 }] }],
|
|
36
|
+
},
|
|
37
|
+
]);
|
|
38
|
+
});
|
|
39
|
+
});
|
|
@@ -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
|
+
};
|
|
@@ -0,0 +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,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
|
+
}
|
|
@@ -0,0 +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,28 +1,28 @@
|
|
|
1
|
-
export const Sizes = {
|
|
2
|
-
none: "0px",
|
|
3
|
-
sm: "0.125rem",
|
|
4
|
-
"": "0.25rem",
|
|
5
|
-
md: "0.375rem",
|
|
6
|
-
lg: "0.5rem",
|
|
7
|
-
xl: "0.75rem",
|
|
8
|
-
"2xl": "1rem",
|
|
9
|
-
"3xl": "1.5rem",
|
|
10
|
-
full: "9999px",
|
|
11
|
-
};
|
|
12
|
-
export const Sides = {
|
|
13
|
-
"": "",
|
|
14
|
-
t: "Top",
|
|
15
|
-
r: "Right",
|
|
16
|
-
l: "Left",
|
|
17
|
-
b: "Bottom",
|
|
18
|
-
tl: "TopLeft",
|
|
19
|
-
tr: "TopRight",
|
|
20
|
-
bl: "BottomLeft",
|
|
21
|
-
br: "BottomRight",
|
|
22
|
-
};
|
|
23
|
-
export const Widths = {
|
|
24
|
-
"1/4": "25%",
|
|
25
|
-
"1/2": "50%",
|
|
26
|
-
"3/4": "75%",
|
|
27
|
-
full: "100%",
|
|
28
|
-
};
|
|
1
|
+
export const Sizes = {
|
|
2
|
+
none: "0px",
|
|
3
|
+
sm: "0.125rem",
|
|
4
|
+
"": "0.25rem",
|
|
5
|
+
md: "0.375rem",
|
|
6
|
+
lg: "0.5rem",
|
|
7
|
+
xl: "0.75rem",
|
|
8
|
+
"2xl": "1rem",
|
|
9
|
+
"3xl": "1.5rem",
|
|
10
|
+
full: "9999px",
|
|
11
|
+
};
|
|
12
|
+
export const Sides = {
|
|
13
|
+
"": "",
|
|
14
|
+
t: "Top",
|
|
15
|
+
r: "Right",
|
|
16
|
+
l: "Left",
|
|
17
|
+
b: "Bottom",
|
|
18
|
+
tl: "TopLeft",
|
|
19
|
+
tr: "TopRight",
|
|
20
|
+
bl: "BottomLeft",
|
|
21
|
+
br: "BottomRight",
|
|
22
|
+
};
|
|
23
|
+
export const Widths = {
|
|
24
|
+
"1/4": "25%",
|
|
25
|
+
"1/2": "50%",
|
|
26
|
+
"3/4": "75%",
|
|
27
|
+
full: "100%",
|
|
28
|
+
};
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
import { Side, Size, Sizes } from "./constants.js";
|
|
2
|
+
export declare function isSide(v: string): v is Side;
|
|
3
|
+
export declare function isSize(v: string): v is Size;
|
|
4
|
+
export declare function getSize(size: keyof typeof Sizes): string;
|
|
5
|
+
export declare function getSide(side: Side): string[];
|
|
@@ -1,24 +1,24 @@
|
|
|
1
|
-
import { Sides, Sizes } from "./constants.js";
|
|
2
|
-
export function isSide(v) {
|
|
3
|
-
return Sides[v] !== undefined;
|
|
4
|
-
}
|
|
5
|
-
export function isSize(v) {
|
|
6
|
-
return Sizes[v] !== undefined;
|
|
7
|
-
}
|
|
8
|
-
export function getSize(size) {
|
|
9
|
-
return Sizes[size];
|
|
10
|
-
}
|
|
11
|
-
export function getSide(side) {
|
|
12
|
-
switch (side) {
|
|
13
|
-
case "t":
|
|
14
|
-
return [...getSide("tl"), ...getSide("tr")];
|
|
15
|
-
case "r":
|
|
16
|
-
return [...getSide("tr"), ...getSide("br")];
|
|
17
|
-
case "b":
|
|
18
|
-
return [...getSide("br"), ...getSide("bl")];
|
|
19
|
-
case "l":
|
|
20
|
-
return [...getSide("tl"), ...getSide("bl")];
|
|
21
|
-
default:
|
|
22
|
-
return [Sides[side]];
|
|
23
|
-
}
|
|
24
|
-
}
|
|
1
|
+
import { Sides, Sizes } from "./constants.js";
|
|
2
|
+
export function isSide(v) {
|
|
3
|
+
return Sides[v] !== undefined;
|
|
4
|
+
}
|
|
5
|
+
export function isSize(v) {
|
|
6
|
+
return Sizes[v] !== undefined;
|
|
7
|
+
}
|
|
8
|
+
export function getSize(size) {
|
|
9
|
+
return Sizes[size];
|
|
10
|
+
}
|
|
11
|
+
export function getSide(side) {
|
|
12
|
+
switch (side) {
|
|
13
|
+
case "t":
|
|
14
|
+
return [...getSide("tl"), ...getSide("tr")];
|
|
15
|
+
case "r":
|
|
16
|
+
return [...getSide("tr"), ...getSide("br")];
|
|
17
|
+
case "b":
|
|
18
|
+
return [...getSide("br"), ...getSide("bl")];
|
|
19
|
+
case "l":
|
|
20
|
+
return [...getSide("tl"), ...getSide("bl")];
|
|
21
|
+
default:
|
|
22
|
+
return [Sides[side]];
|
|
23
|
+
}
|
|
24
|
+
}
|
|
@@ -1,32 +1,32 @@
|
|
|
1
|
-
import { dashCase } from "../../case.js";
|
|
2
|
-
export function compileFStyle(fstyle, prefix = "") {
|
|
3
|
-
const properties = [];
|
|
4
|
-
const rules = [];
|
|
5
|
-
for (const [key, value] of Object.entries(fstyle)) {
|
|
6
|
-
if (typeof value == "string") {
|
|
7
|
-
properties.push({ key, value });
|
|
8
|
-
}
|
|
9
|
-
else {
|
|
10
|
-
rules.push({ key, value });
|
|
11
|
-
}
|
|
12
|
-
}
|
|
13
|
-
let rule = "";
|
|
14
|
-
if (properties.length > 0) {
|
|
15
|
-
rule += `${prefix} {\n`;
|
|
16
|
-
for (const { key, value } of properties) {
|
|
17
|
-
rule += ` ${dashCase(key)}: ${value};\n`;
|
|
18
|
-
}
|
|
19
|
-
rule += "}\n\n";
|
|
20
|
-
}
|
|
21
|
-
for (const { key, value } of rules) {
|
|
22
|
-
if (key.startsWith("@media")) {
|
|
23
|
-
rule += `${key} {\n`;
|
|
24
|
-
rule += compileFStyle(value, " ");
|
|
25
|
-
rule += `}\n\n`;
|
|
26
|
-
}
|
|
27
|
-
else {
|
|
28
|
-
rule += compileFStyle(value, `${prefix} ${key}`);
|
|
29
|
-
}
|
|
30
|
-
}
|
|
31
|
-
return rule;
|
|
32
|
-
}
|
|
1
|
+
import { dashCase } from "../../case.js";
|
|
2
|
+
export function compileFStyle(fstyle, prefix = "") {
|
|
3
|
+
const properties = [];
|
|
4
|
+
const rules = [];
|
|
5
|
+
for (const [key, value] of Object.entries(fstyle)) {
|
|
6
|
+
if (typeof value == "string") {
|
|
7
|
+
properties.push({ key, value });
|
|
8
|
+
}
|
|
9
|
+
else {
|
|
10
|
+
rules.push({ key, value });
|
|
11
|
+
}
|
|
12
|
+
}
|
|
13
|
+
let rule = "";
|
|
14
|
+
if (properties.length > 0) {
|
|
15
|
+
rule += `${prefix} {\n`;
|
|
16
|
+
for (const { key, value } of properties) {
|
|
17
|
+
rule += ` ${dashCase(key)}: ${value};\n`;
|
|
18
|
+
}
|
|
19
|
+
rule += "}\n\n";
|
|
20
|
+
}
|
|
21
|
+
for (const { key, value } of rules) {
|
|
22
|
+
if (key.startsWith("@media")) {
|
|
23
|
+
rule += `${key} {\n`;
|
|
24
|
+
rule += compileFStyle(value, " ");
|
|
25
|
+
rule += `}\n\n`;
|
|
26
|
+
}
|
|
27
|
+
else {
|
|
28
|
+
rule += compileFStyle(value, `${prefix} ${key}`);
|
|
29
|
+
}
|
|
30
|
+
}
|
|
31
|
+
return rule;
|
|
32
|
+
}
|