snail.view 1.0.21 → 1.0.23

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/.code-snippets CHANGED
@@ -10,16 +10,6 @@
10
10
  "@import \"snail.view/dist/styles/base-mixins.less\";"
11
11
  ]
12
12
  },
13
- // ***************************************** 👉 所有元素 *****************************************
14
- ".*-box-sizing": {
15
- "prefix": ".*-box-sizing",
16
- "scope": "less",
17
- "description": "所有元素的box-sizing属性设置为border-box",
18
- "body": [
19
- "// 所有元素的box-sizing属性设置为border-box",
20
- ".\\*-box-sizing();",
21
- ]
22
- },
23
13
  // ***************************************** 👉 文本样式 *****************************************
24
14
  "text-ellipsis": {
25
15
  "prefix": ".text-ellipsis",
@@ -76,6 +66,24 @@
76
66
  ".left-top-center();"
77
67
  ]
78
68
  },
69
+ "absolute-fill": {
70
+ "prefix": ".absolute-fill",
71
+ "scope": "less",
72
+ "description": "绝对定位,填充父元素,并定位到0,0位置",
73
+ "body": [
74
+ "// 绝对定位,填充父元素,并定位到0,0位置",
75
+ ".absolute-fill();"
76
+ ]
77
+ },
78
+ "absolute-fill-hidden": {
79
+ "prefix": ".absolute-fill-hidden",
80
+ "scope": "less",
81
+ "description": "绝对定位,填充父元素,隐藏溢出的内容,并定位到0,0位置",
82
+ "body": [
83
+ "// 绝对定位,填充父元素,隐藏溢出的内容,并定位到0,0位置",
84
+ ".absolute-fill-hidden();"
85
+ ]
86
+ },
79
87
  // ***************************************** 👉 弹性盒子 *****************************************"
80
88
  "flex-main-center": {
81
89
  "prefix": ".flex-main-center",
@@ -506,6 +506,17 @@ interface IObserver {
506
506
  * @returns 作用域,可销毁监听
507
507
  */
508
508
  onClient(el: Element, fn: (rect: DOMRectReadOnly) => void): IScope;
509
+ /**
510
+ * 监听元素的突变
511
+ * - 通过options配置支持元素自身属性、子元素、子元素属性等;如支持子元素发生变化时(添加、删除、属性变化)等
512
+ * - 内部通过 MutationObserver 实现;详细参照:https://developer.mozilla.org/zh-CN/docs/Web/API/MutationObserver
513
+ * - scope销毁时自动移除监听
514
+ * @param el 监听元素
515
+ * @param options 配置选项,监听元素的哪些变化
516
+ * @param fn 回调方法
517
+ * @returns 作用域,可销毁监听
518
+ */
519
+ onMutation(el: Element, options: MutationObserverInit, fn: (record: MutationRecord[], observer: MutationObserver) => void): IScope;
509
520
  }
510
521
  /**
511
522
  * 元素尺寸
@@ -1,5 +1,5 @@
1
1
  //@ sourceURL=/snail.view.js
2
- import { checkScope, throwIfFalse, useKeyScope, isArrayNotEmpty, isStringNotEmpty, isObject, useScopes, mountScope, extract, hasOwnProperty, tidyString, event, mustString, version, useScope, run, mustFunction } from 'snail.core';
2
+ import { checkScope, throwIfFalse, useKeyScope, isArrayNotEmpty, isStringNotEmpty, isObject, useScopes, mountScope, extract, hasOwnProperty, tidyString, event, mustString, version, useScope, mustFunction, run } from 'snail.core';
3
3
 
4
4
  function getAnimationScope(manager, el) {
5
5
  checkScope(manager, "getAnimationScope: manager destroyed.");
@@ -303,10 +303,19 @@ function useObserver() {
303
303
  }, 100);
304
304
  return scope.onDestroy(() => clearInterval(timer));
305
305
  }
306
+ function onMutation(el, options, fn) {
307
+ checkScope(manager, "onClient: observer destroyed.");
308
+ throwIfFalse(el instanceof Element, "onClient: el must be a Element.");
309
+ mustFunction(fn, "onMutation: fn");
310
+ const observe = new MutationObserver(fn);
311
+ observe.observe(el, options);
312
+ return scopes.get().onDestroy(() => observe.disconnect());
313
+ }
306
314
  const manager = mountScope({
307
315
  onEvent,
308
316
  onSize,
309
- onClient
317
+ onClient,
318
+ onMutation
310
319
  }, "IObserver");
311
320
  manager.onDestroy(scopes.destroy);
312
321
  return Object.freeze(manager);
@@ -307,10 +307,19 @@
307
307
  }, 100);
308
308
  return scope.onDestroy(() => clearInterval(timer));
309
309
  }
310
+ function onMutation(el, options, fn) {
311
+ snail_core.checkScope(manager, "onClient: observer destroyed.");
312
+ snail_core.throwIfFalse(el instanceof Element, "onClient: el must be a Element.");
313
+ snail_core.mustFunction(fn, "onMutation: fn");
314
+ const observe = new MutationObserver(fn);
315
+ observe.observe(el, options);
316
+ return scopes.get().onDestroy(() => observe.disconnect());
317
+ }
310
318
  const manager = snail_core.mountScope({
311
319
  onEvent,
312
320
  onSize,
313
- onClient
321
+ onClient,
322
+ onMutation
314
323
  }, "IObserver");
315
324
  manager.onDestroy(scopes.destroy);
316
325
  return Object.freeze(manager);
@@ -27,9 +27,9 @@
27
27
 
28
28
  // 高度、宽度100%填充满,隐藏溢出的内容
29
29
  .wh-fill-hidden() {
30
- width: 100%;
31
- height: 100%;
32
30
  overflow: hidden;
31
+ // width:100%;height:100%
32
+ .wh-fill();
33
33
  }
34
34
 
35
35
  // left、top起始位置:left: 0; top: 0;
@@ -45,6 +45,21 @@
45
45
  transform: translate(-50%, -50%);
46
46
  }
47
47
 
48
+ // 绝对定位,填充父元素,并定位到0,0位置
49
+ .absolute-fill() {
50
+ position: absolute;
51
+ // width:100%;height:100%
52
+ .wh-fill();
53
+ // left、top起始位置:left: 0; top: 0
54
+ .left-top-start();
55
+ }
56
+
57
+ // 绝对定位,填充父元素,隐藏溢出的内容,并定位到0,0位置
58
+ .absolute-fill-hidden() {
59
+ .absolute-fill();
60
+ overflow: hidden;
61
+ }
62
+
48
63
  // ***************************************** 👉 弹性盒子 *****************************************
49
64
  // flex 布局,主轴居中
50
65
  .flex-main-center() {
package/package.json CHANGED
@@ -3,7 +3,7 @@
3
3
  "description": "对视图界面做的一些封装。如样式计算助手方法,常用样式less混入、变量等;dom相关助手类",
4
4
  "author": "snail_dev@163.com",
5
5
  "license": "MIT",
6
- "version": "1.0.21",
6
+ "version": "1.0.23",
7
7
  "type": "module",
8
8
  "main": "dist/snail.view.js",
9
9
  "module": "dist/snail.view.js",