ctx-core 6.7.1 → 6.8.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.
package/README.md CHANGED
@@ -2,8 +2,6 @@
2
2
 
3
3
  The ctx-core library is a 0 dependency library with several exports to support general app development. This library has several exports to limit what is loaded into memory & to make tree-shaking less intensive. Some of the underlying functions are in multiple exports. The full list of exports is below. There is varying comprehensiveness & usage for these functions.
4
4
 
5
-
6
-
7
5
  ## Development Monorepo
8
6
 
9
7
  The [development monorepo](https://github.com/ctx-core/dev) used to have the ctx-core/ctx-core project name but has been moved to make room for this package.
@@ -117,3 +115,5 @@ The docs for rmemo are in https://github.com/ctx-core/rmemo. Since the source fo
117
115
  ## ctx-core/uri
118
116
 
119
117
  ## ctx-core/uuid
118
+
119
+ ## ctx-core/web_animation
@@ -1 +1,12 @@
1
- export * from './index.js'
1
+ /**
2
+ * @param {string}str
3
+ * @returns {string}
4
+ */
5
+ export const atob = globalThis.atob
6
+ /**
7
+ * @return {typeof atob}
8
+ */
9
+ export function atob_() {
10
+ return atob
11
+ }
12
+ export { atob_ as _atob, }
@@ -1 +1,12 @@
1
- export * from './index.js'
1
+ /**
2
+ * @param {string}str
3
+ * @returns {string}
4
+ */
5
+ export const btoa = globalThis.btoa
6
+ /**
7
+ * @return {typeof btoa}
8
+ */
9
+ export function btoa_() {
10
+ return btoa
11
+ }
12
+ export { btoa_ as _btoa, }
package/all/btoa/index.js CHANGED
@@ -8,7 +8,7 @@ export function btoa(str) {
8
8
  return (
9
9
  process_release_name
10
10
  ? new Buffer(str).toString('base64')
11
- : window.btoa(str)
11
+ : globalThis.btoa(str)
12
12
  )
13
13
  }
14
14
  /**
@@ -42,11 +42,9 @@ export type sig_T<val_T, E = unknown> = (()=>val_T)&{
42
42
  _:val_T
43
43
  readonly a?:rmemo_a_T
44
44
  readonly f?:rmemo_f_T
45
- readonly s?:rmemo_r_T
46
- readonly t:rmemo_r_T[]
47
45
  readonly l:number
48
- readonly u:rmemo_T<unknown>[]
49
- readonly v:rmemo_T<unknown>[]
46
+ readonly t:rmemo_T<unknown>[]
47
+ readonly i:rmemo_T<unknown>[]
50
48
  readonly val:val_T
51
49
  add<add_val_T>(fn:rmemo_add_def_T<val_T, add_val_T>):sig_T<val_T, E>
52
50
  memo_<_val_T, E = unknown>(def:memo_def_T<_val_T>):memo_T<_val_T, E>
@@ -66,9 +64,5 @@ export type rmemo_val_T<sig_T> = sig_T extends { ():infer val_T }
66
64
  export type memo_def_T<val_T, E = unknown> = (sig:sig_T<val_T, E>)=>val_T
67
65
  export type rmemo_a_T = unknown[]
68
66
  export type rmemo_add_def_T<val_T, add_val_T, E = unknown> = (sig:sig_T<val_T, E>)=>add_val_T
69
- export type rmemo_f_T = (()=>void)&{
70
- readonly l:number
71
- readonly s:rmemo_T<unknown>[]
72
- readonly t:rmemo_T<unknown>[]
73
- }
67
+ export type rmemo_f_T = (()=>void)
74
68
  export type rmemo_r_T = WeakRef<rmemo_f_T>&{ readonly d?: ()=>rmemo_f_T }
@@ -12,20 +12,19 @@ let $ = globalThis.__rmemo__ ??= { q: new Set }
12
12
  * @private
13
13
  */
14
14
  export function memo_(memo_def, ...add_def_a) {
15
+ let t = []
15
16
  /** @type {memo_T} */
16
17
  let memo = ()=>{
17
- if (!('val' in memo)) {
18
- memo.f()
19
- }
18
+ 'val' in memo || memo.f()
20
19
  if ($.c) {
21
- if (!memo.t.includes($.c.s ??= new WeakRef($.c.f))) {
22
- memo.t.push($.c.s)
20
+ if (!t.includes($.c.r ??= new WeakRef($.c))) {
21
+ t.push($.c.r)
23
22
  }
24
- if ($.c.f.l < memo.f.l + 1) $.c.f.l = memo.f.l + 1
23
+ if ($.c.l < memo.l + 1) $.c.l = memo.l + 1
25
24
  // memo is called by $.c's conditional execution...next change to memo will notify $.c
26
- $.c.f.s.push(memo)
25
+ $.c.t.push(memo)
27
26
  // prevent memo from GC while $.c still has a strong reference
28
- if (!$.c.f.t.includes(memo)) $.c.f.t.push(memo)
27
+ if (!$.c.i.includes(memo)) $.c.i.push(memo)
29
28
  }
30
29
  return memo.val
31
30
  }
@@ -33,9 +32,9 @@ export function memo_(memo_def, ...add_def_a) {
33
32
  get: memo,
34
33
  set: val=>{
35
34
  if (memo.val !== val) {
36
- memo.t = memo.t.filter(r=>{
35
+ t = t.filter(r=>{
37
36
  r = r.deref()
38
- if (r?.s.includes(memo)) { // if added by $.c.f.s.push(memo), add to $.q
37
+ if (r?.t.includes(memo)) { // if added by $.c.t.push(memo), add to $.q
39
38
  $.q.add(r)
40
39
  }
41
40
  return r
@@ -54,7 +53,7 @@ export function memo_(memo_def, ...add_def_a) {
54
53
  continue cur_refresh_loop
55
54
  }
56
55
  }
57
- cur_refresh()
56
+ cur_refresh.f()
58
57
  }
59
58
  },
60
59
  })
@@ -78,7 +77,7 @@ export function memo_(memo_def, ...add_def_a) {
78
77
  memo.f = ()=>{
79
78
  let prev_memo = $.c
80
79
  $.c = memo
81
- memo.f.s = [] // reset references in memo_def conditional execution path...see $.c.f.s.push(memo)
80
+ memo.t = [] // reset references in memo_def conditional execution path...see $.c.t.push(memo)
82
81
  try {
83
82
  memo._ = memo_def(memo)
84
83
  } catch (err) {
@@ -86,10 +85,9 @@ export function memo_(memo_def, ...add_def_a) {
86
85
  }
87
86
  $.c = prev_memo // catch does not throw
88
87
  }
89
- memo.f.l = 0
90
- memo.f.s = []
91
- memo.f.t = []
88
+ memo.l = 0
92
89
  memo.t = []
90
+ memo.i = []
93
91
  return memo
94
92
  }
95
93
  export { memo_ as memosig_ }
@@ -155,8 +153,8 @@ export function memo__bind(fn) {
155
153
  */
156
154
  export function rmemo__on(rmemo, off_fn) {
157
155
  if (off_fn) rmemo__off__add(rmemo, off_fn)
158
- if (rmemo.s?.d) {
159
- rmemo.s.deref = rmemo.s.d
156
+ if (rmemo.r?.d) {
157
+ rmemo.r.deref = rmemo.r.d
160
158
  }
161
159
  rmemo.f()
162
160
  return rmemo
@@ -167,9 +165,9 @@ export function rmemo__on(rmemo, off_fn) {
167
165
  * @returns {rmemo_T}
168
166
  */
169
167
  export function rmemo__off(rmemo) {
170
- if (rmemo.s) {
171
- rmemo.s.d ??= rmemo.s.deref
172
- rmemo.s.deref = ()=>{
168
+ if (rmemo.r) {
169
+ rmemo.r.d ??= rmemo.r.deref
170
+ rmemo.r.deref = ()=>{
173
171
  }
174
172
  }
175
173
  for (let a_o of rmemo.a ?? []) {
@@ -8,7 +8,7 @@ test('rmemo__wait|rmemo', async ()=>{
8
8
  subject$,
9
9
  subject=>subject >= 0,
10
10
  10_000)
11
- equal(promise.m.t, [])
11
+ // equal(promise.m.t, [])
12
12
  equal(subject$(), -1)
13
13
  subject$._ = 1
14
14
  equal(subject$(), 1)
@@ -21,7 +21,7 @@ test('rmemo__wait|rmemolike', async ()=>{
21
21
  ()=>subject$(),
22
22
  subject=>subject >= 0,
23
23
  10_000)
24
- equal(promise.m.t, [])
24
+ // equal(promise.m.t, [])
25
25
  equal(subject$(), -1)
26
26
  subject$._ = 1
27
27
  equal(subject$(), 1)
@@ -0,0 +1 @@
1
+ export * from './index.js'
@@ -0,0 +1 @@
1
+ export * from './index.js'
@@ -0,0 +1,15 @@
1
+ import type { nullish } from '../nullish/index.js'
2
+ import type { sig_T } from '../rmemo/index.js'
3
+ export declare function wanimato__new<E extends Element>(
4
+ $:sig_T<wanimato_T|nullish>,
5
+ el:E,
6
+ animation_:(el:E)=>Animation
7
+ ):wanimato_T
8
+ export type wanimato_T = {
9
+ animation:Animation
10
+ el:Element
11
+ is_play:boolean
12
+ is_finish:boolean
13
+ finish_currentTime:number|null
14
+ is_remove:boolean
15
+ }
@@ -0,0 +1,128 @@
1
+ /**
2
+ * @param {sig_T<wanimato_T|nullish>}$
3
+ * @param {Element}el
4
+ * @param {(el:Element)=>Animation}animation_
5
+ * @returns {wanimato_T}
6
+ */
7
+ export function wanimato__new($, el, animation_) {
8
+ if ($.val?.el === el) return $.val
9
+ let _animation = animation_(el)
10
+ _animation.addEventListener('finish', ()=>{
11
+ $._ = {
12
+ ...$(),
13
+ is_finish: true,
14
+ finish_currentTime: $().animation.currentTime
15
+ }
16
+ })
17
+ _animation.addEventListener('remove', ()=>{
18
+ $._ = {
19
+ ...$(),
20
+ is_remove: true
21
+ }
22
+ })
23
+ let play_state__ensure = ()=>{
24
+ if ($().is_play !== true || $().is_finish !== false) {
25
+ $._ = {
26
+ ...$(),
27
+ is_play: true,
28
+ is_finish: false
29
+ }
30
+ }
31
+ }
32
+ let begin_state__ensure__setTimeout = ()=>{
33
+ setTimeout(
34
+ ()=>{
35
+ if ($().is_play !== !!_animation.currentTime || $().is_finish !== false) {
36
+ $._ = {
37
+ ...$(),
38
+ is_play: !!_animation.currentTime,
39
+ is_finish: false,
40
+ }
41
+ }
42
+ },
43
+ _animation.currentTime / -_animation.playbackRate)
44
+ }
45
+ let animation_mixin = {
46
+ play() {
47
+ if (_animation.playbackRate < 0) {
48
+ this.reverse()
49
+ } else {
50
+ _animation.play()
51
+ play_state__ensure()
52
+ if (_animation.playbackRate < 0) {
53
+ begin_state__ensure__setTimeout()
54
+ }
55
+ }
56
+ },
57
+ reverse() {
58
+ _animation.reverse()
59
+ play_state__ensure()
60
+ begin_state__ensure__setTimeout()
61
+ },
62
+ finish() {
63
+ _animation.finish()
64
+ if ($().is_play !== false || $().is_finish !== !!_animation.currentTime) {
65
+ $._ = {
66
+ ...$(),
67
+ is_play: false,
68
+ is_finish: !!_animation.currentTime
69
+ }
70
+ }
71
+ },
72
+ cancel() {
73
+ _animation.cancel()
74
+ if ($().is_play !== false || $().is_finish !== false) {
75
+ $._ = {
76
+ ...$(),
77
+ is_play: false,
78
+ is_finish: false
79
+ }
80
+ }
81
+ },
82
+ updatePlaybackRate(playbackRate) {
83
+ _animation.updatePlaybackRate(playbackRate)
84
+ _animation.ready
85
+ .then(()=>{
86
+ if (_animation.playbackRate < 0) {
87
+ begin_state__ensure__setTimeout()
88
+ }
89
+ })
90
+ },
91
+ addEventListener(...arg_a) {
92
+ _animation.addEventListener(...arg_a)
93
+ },
94
+ removeEventListener(...arg_a) {
95
+ _animation.removeEventListener(...arg_a)
96
+ },
97
+ }
98
+ return {
99
+ el,
100
+ animation: new Proxy(_animation, {
101
+ get(_animation, /** @type {keyof Animation} */prop) {
102
+ return animation_mixin[prop] ?? _animation[prop]
103
+ },
104
+ set(
105
+ _animation,
106
+ /** @type {keyof Omit<Animation, 'finished'|'pending'|'playState'|'ready'|'replaceState'>} */
107
+ prop,
108
+ val
109
+ ) {
110
+ if (prop === 'playbackRate') {
111
+ if (_animation[prop] === val) return false
112
+ _animation[prop] = val
113
+ if (val < 0) {
114
+ begin_state__ensure__setTimeout()
115
+ }
116
+ return true
117
+ }
118
+ if (_animation[prop] === val) return false
119
+ _animation[prop] = val
120
+ return true
121
+ }
122
+ }),
123
+ is_play: true,
124
+ is_finish: false,
125
+ finish_currentTime: null,
126
+ is_remove: false,
127
+ }
128
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "ctx-core",
3
- "version": "6.7.1",
3
+ "version": "6.8.1",
4
4
  "description": "ctx-core core library",
5
5
  "keywords": [
6
6
  "ctx-core",
@@ -82,6 +82,7 @@
82
82
  "types",
83
83
  "uri",
84
84
  "uuid",
85
+ "web_animation",
85
86
  "package.json"
86
87
  ],
87
88
  "exports": {
@@ -298,6 +299,10 @@
298
299
  "browser": "./uuid/index.browser.js",
299
300
  "default": "./uuid/index.js"
300
301
  },
302
+ "./web_animation": {
303
+ "browser": "./web_animation/index.browser.js",
304
+ "default": "./web_animation/index.js"
305
+ },
301
306
  "./package.json": "./package.json"
302
307
  },
303
308
  "devDependencies": {
@@ -369,28 +374,28 @@
369
374
  "import": {
370
375
  "./rmemo": "{ memo_ }"
371
376
  },
372
- "limit": "376 B"
377
+ "limit": "377 B"
373
378
  },
374
379
  {
375
380
  "name": "memo_ sig_",
376
381
  "import": {
377
382
  "./rmemo": "{ sig_, memo_ }"
378
383
  },
379
- "limit": "395 B"
384
+ "limit": "393 B"
380
385
  },
381
386
  {
382
387
  "name": "memo_ sig_ be_ ctx_",
383
388
  "import": {
384
389
  "./rmemo": "{ sig_, memo_, be_, ctx_ }"
385
390
  },
386
- "limit": "498 B"
391
+ "limit": "499 B"
387
392
  },
388
393
  {
389
394
  "name": "memo_ sig_ be_ ctx_ be_memo_pair_ be_sig_triple_",
390
395
  "import": {
391
396
  "./rmemo": "{ sig_, memo_, be_, ctx_, be_memo_pair_, be_sig_triple_ }"
392
397
  },
393
- "limit": "591 B"
398
+ "limit": "587 B"
394
399
  },
395
400
  {
396
401
  "name": "class_",
@@ -419,6 +424,13 @@
419
424
  "./uuid": "{ uuid__compact }"
420
425
  },
421
426
  "limit": "107 B"
427
+ },
428
+ {
429
+ "name": "web_animation",
430
+ "import": {
431
+ "./web_animation": "{ memo_, wanimato__new }"
432
+ },
433
+ "limit": "728 B"
422
434
  }
423
435
  ],
424
436
  "scripts": {
@@ -0,0 +1 @@
1
+ export * from '../all/wanimato/index.js'
@@ -0,0 +1 @@
1
+ export * from '../all/wanimato/index.js'
@@ -0,0 +1,2 @@
1
+ export * from '../rmemo/index.js'
2
+ export * from '../all/wanimato/index.js'
@@ -0,0 +1,2 @@
1
+ export * from '../rmemo/index.js'
2
+ export * from '../all/wanimato/index.js'