@mantou/gem 1.7.3 → 1.7.5

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/src/lib/utils.ts CHANGED
@@ -44,7 +44,7 @@ interface LinkedListEventMap {
44
44
  start: Event;
45
45
  end: Event;
46
46
  }
47
- interface LinkedListItem<T> {
47
+ export interface LinkedListItem<T> {
48
48
  value: T;
49
49
  prev?: LinkedListItem<T>;
50
50
  next?: LinkedListItem<T>;
@@ -83,6 +83,30 @@ export class LinkedList<T = any> extends EventTarget {
83
83
  return this.#map.size;
84
84
  }
85
85
 
86
+ get first() {
87
+ return this.#firstItem;
88
+ }
89
+
90
+ get last() {
91
+ return this.#lastItem;
92
+ }
93
+
94
+ isSuperLinkOf(subLink: LinkedList<T>) {
95
+ let subItem = subLink.first;
96
+ if (!subItem) return true;
97
+ let item = this.find(subItem.value);
98
+ while (item && item.value === subItem.value) {
99
+ subItem = subItem.next;
100
+ if (!subItem) return true;
101
+ item = item.next;
102
+ }
103
+ return false;
104
+ }
105
+
106
+ find(value: T) {
107
+ return this.#map.get(value);
108
+ }
109
+
86
110
  // 添加到尾部,已存在时会删除老的项目
87
111
  // 如果是添加第一个,start 事件会在添加前触发,避免处理事件重复的逻辑
88
112
  add(value: T) {
@@ -112,6 +136,7 @@ export class LinkedList<T = any> extends EventTarget {
112
136
  }
113
137
 
114
138
  // 获取头部元素
139
+ // 会从链表删除
115
140
  get(): T | undefined {
116
141
  const firstItem = this.#firstItem;
117
142
  if (!firstItem) return;
@@ -363,7 +388,7 @@ export function styleMap(object: StyleObject) {
363
388
  );
364
389
  }
365
390
 
366
- export function classMap(object: Record<string, boolean>) {
391
+ export function classMap(object: Record<string, boolean | string | number | undefined>) {
367
392
  return objectMapToString(object, ' ', (key, value) => (value ? key : ''));
368
393
  }
369
394
 
@@ -1 +1 @@
1
- export const version = '1.7.3';
1
+ export const version = '1.7.5';