@mantou/gem 2.2.0 → 2.2.2

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 (159) hide show
  1. package/dist/gem.es.js +2039 -2051
  2. package/dist/gem.umd.js +12 -32
  3. package/elements/base/dialog.d.ts +1 -1
  4. package/elements/base/dialog.d.ts.map +1 -1
  5. package/elements/base/dialog.js +2 -2
  6. package/elements/base/dialog.js.map +1 -1
  7. package/elements/base/gesture.d.ts +1 -1
  8. package/elements/base/gesture.d.ts.map +1 -1
  9. package/elements/base/gesture.js +5 -5
  10. package/elements/base/gesture.js.map +1 -1
  11. package/elements/base/link.d.ts +1 -1
  12. package/elements/base/link.d.ts.map +1 -1
  13. package/elements/base/link.js +18 -19
  14. package/elements/base/link.js.map +1 -1
  15. package/elements/base/modal-factory.d.ts +93 -57
  16. package/elements/base/modal-factory.d.ts.map +1 -1
  17. package/elements/base/modal-factory.js +4 -3
  18. package/elements/base/modal-factory.js.map +1 -1
  19. package/elements/base/reflect.d.ts +1 -2
  20. package/elements/base/reflect.d.ts.map +1 -1
  21. package/elements/base/reflect.js +8 -10
  22. package/elements/base/reflect.js.map +1 -1
  23. package/elements/base/route.d.ts +18 -8
  24. package/elements/base/route.d.ts.map +1 -1
  25. package/elements/base/route.js +17 -21
  26. package/elements/base/route.js.map +1 -1
  27. package/elements/base/title.d.ts +1 -1
  28. package/elements/base/title.d.ts.map +1 -1
  29. package/elements/base/title.js +5 -7
  30. package/elements/base/title.js.map +1 -1
  31. package/elements/base/unsafe.d.ts +4 -3
  32. package/elements/base/unsafe.d.ts.map +1 -1
  33. package/elements/base/unsafe.js +45 -24
  34. package/elements/base/unsafe.js.map +1 -1
  35. package/elements/base/use.d.ts +1 -1
  36. package/elements/base/use.d.ts.map +1 -1
  37. package/elements/base/use.js +1 -1
  38. package/elements/base/use.js.map +1 -1
  39. package/elements/link.js +1 -1
  40. package/elements/link.js.map +1 -1
  41. package/elements/route.js +1 -1
  42. package/elements/route.js.map +1 -1
  43. package/helper/hmr.d.ts +11 -0
  44. package/helper/hmr.d.ts.map +1 -0
  45. package/helper/hmr.js +255 -0
  46. package/helper/hmr.js.map +1 -0
  47. package/helper/i18n.d.ts +2 -2
  48. package/helper/i18n.d.ts.map +1 -1
  49. package/helper/i18n.js +5 -4
  50. package/helper/i18n.js.map +1 -1
  51. package/helper/logger.d.ts +1 -1
  52. package/helper/logger.d.ts.map +1 -1
  53. package/helper/logger.js +8 -5
  54. package/helper/logger.js.map +1 -1
  55. package/helper/mediaquery.js +1 -1
  56. package/helper/mediaquery.js.map +1 -1
  57. package/helper/react-utils.d.ts.map +1 -1
  58. package/helper/react-utils.js +2 -6
  59. package/helper/react-utils.js.map +1 -1
  60. package/helper/ssr-shim.d.ts.map +1 -1
  61. package/helper/ssr-shim.js +2 -1
  62. package/helper/ssr-shim.js.map +1 -1
  63. package/helper/theme.d.ts +17 -6
  64. package/helper/theme.d.ts.map +1 -1
  65. package/helper/theme.js +23 -8
  66. package/helper/theme.js.map +1 -1
  67. package/index.d.ts +1 -2
  68. package/index.d.ts.map +1 -1
  69. package/index.js +1 -3
  70. package/index.js.map +1 -1
  71. package/lib/decorators.d.ts +54 -62
  72. package/lib/decorators.d.ts.map +1 -1
  73. package/lib/decorators.js +90 -91
  74. package/lib/decorators.js.map +1 -1
  75. package/lib/directive.d.ts +0 -18
  76. package/lib/directive.d.ts.map +1 -1
  77. package/lib/directive.js +1 -2
  78. package/lib/directive.js.map +1 -1
  79. package/lib/element.d.ts +8 -137
  80. package/lib/element.d.ts.map +1 -1
  81. package/lib/element.js +16 -481
  82. package/lib/element.js.map +1 -1
  83. package/lib/history.d.ts +68 -10
  84. package/lib/history.d.ts.map +1 -1
  85. package/lib/history.js +15 -15
  86. package/lib/history.js.map +1 -1
  87. package/lib/lit-html.d.ts +7 -109
  88. package/lib/lit-html.d.ts.map +1 -1
  89. package/lib/lit-html.js +75 -32
  90. package/lib/lit-html.js.map +1 -1
  91. package/lib/reactive.d.ts +130 -0
  92. package/lib/reactive.d.ts.map +1 -0
  93. package/lib/reactive.js +474 -0
  94. package/lib/reactive.js.map +1 -0
  95. package/lib/repeat.d.ts +3 -3
  96. package/lib/repeat.d.ts.map +1 -1
  97. package/lib/repeat.js +3 -3
  98. package/lib/repeat.js.map +1 -1
  99. package/lib/store.d.ts +15 -4
  100. package/lib/store.d.ts.map +1 -1
  101. package/lib/store.js +2 -0
  102. package/lib/store.js.map +1 -1
  103. package/lib/utils.d.ts +26 -11
  104. package/lib/utils.d.ts.map +1 -1
  105. package/lib/utils.js +21 -14
  106. package/lib/utils.js.map +1 -1
  107. package/package.json +3 -3
  108. package/src/dist.ts +6 -8
  109. package/src/elements/base/dialog.ts +2 -2
  110. package/src/elements/base/gesture.ts +6 -6
  111. package/src/elements/base/link.ts +18 -24
  112. package/src/elements/base/modal-factory.ts +4 -3
  113. package/src/elements/base/reflect.ts +2 -3
  114. package/src/elements/base/route.ts +21 -28
  115. package/src/elements/base/title.ts +6 -8
  116. package/src/elements/base/unsafe.ts +33 -14
  117. package/src/elements/base/use.ts +1 -1
  118. package/src/elements/link.ts +1 -1
  119. package/src/elements/route.ts +1 -1
  120. package/src/helper/hmr.ts +305 -0
  121. package/src/helper/i18n.ts +7 -7
  122. package/src/helper/logger.ts +9 -5
  123. package/src/helper/mediaquery.ts +1 -1
  124. package/src/helper/react-utils.ts +4 -12
  125. package/src/helper/ssr-shim.ts +3 -1
  126. package/src/helper/theme.ts +29 -14
  127. package/src/index.ts +1 -4
  128. package/src/lib/decorators.ts +107 -117
  129. package/src/lib/directive.ts +3 -5
  130. package/src/lib/element.ts +21 -600
  131. package/src/lib/history.ts +16 -18
  132. package/src/lib/lit-html.ts +89 -34
  133. package/src/lib/reactive.ts +620 -0
  134. package/src/lib/repeat.ts +5 -5
  135. package/src/lib/store.ts +4 -2
  136. package/src/lib/utils.ts +41 -29
  137. package/src/test/elements/link.test.ts +2 -2
  138. package/src/test/elements/reflect.test.ts +3 -3
  139. package/src/test/elements/title.test.ts +2 -2
  140. package/src/test/gem-element/advance.test.ts +11 -10
  141. package/src/test/gem-element/basic.test.ts +4 -5
  142. package/src/test/gem-element/decorators.test.ts +10 -10
  143. package/src/test/gem-element/multi.test.ts +2 -2
  144. package/src/test/history.test.ts +1 -2
  145. package/src/test/store.test.ts +2 -3
  146. package/src/test/utils.test.ts +5 -6
  147. package/src/test/utils.ts +2 -2
  148. package/helper/react-shim.d.ts +0 -15
  149. package/helper/react-shim.d.ts.map +0 -1
  150. package/helper/react-shim.js +0 -56
  151. package/helper/react-shim.js.map +0 -1
  152. package/lib/directives.d.ts +0 -4
  153. package/lib/directives.d.ts.map +0 -1
  154. package/lib/directives.js +0 -5
  155. package/lib/directives.js.map +0 -1
  156. package/lib/ref.d.ts +0 -1
  157. package/lib/ref.d.ts.map +0 -1
  158. package/lib/ref.js +0 -2
  159. package/lib/ref.js.map +0 -1
@@ -1,17 +1,16 @@
1
- import type { css, Metadata, TemplateResult } from './element';
2
- import { GemElement, UpdateToken, _createTemplate, _RenderErrorEvent, render } from './element';
3
- import { camelToKebabCase, PropProxyMap, GemError } from './utils';
1
+ // biome-ignore-all lint/plugin/no_this_effect: 定义装饰器
2
+
3
+ import type { TemplateResult } from './lit-html';
4
+ import type { Metadata, Sheet } from './reactive';
5
+ import { _createTemplate, _RenderErrorEvent, GemElement, render, UpdateToken } from './reactive';
4
6
  import type { Store } from './store';
5
- import * as elementExports from './element';
6
- import * as decoratorsExports from './decorators';
7
- import * as storeExports from './store';
8
- import * as versionExports from './version';
7
+ import { camelToKebabCase, GemError, PropProxyMap } from './utils';
9
8
 
10
9
  type GemElementPrototype = GemElement & { '': never };
11
10
  type StaticField = Exclude<keyof Metadata, keyof ShadowRootInit | 'aria' | 'noBlocking' | 'penetrable'>;
12
11
 
13
12
  const { deleteProperty, getOwnPropertyDescriptor, defineProperty } = Reflect;
14
- const { getPrototypeOf, assign } = Object;
13
+ const { getPrototypeOf, assign, hasOwn } = Object;
15
14
  const gemElementProxyMap = new PropProxyMap<GemElement>();
16
15
 
17
16
  function pushStaticField(context: ClassFieldDecoratorContext | ClassDecoratorContext, field: StaticField, member: any) {
@@ -27,7 +26,8 @@ function pushStaticField(context: ClassFieldDecoratorContext | ClassDecoratorCon
27
26
  }
28
27
 
29
28
  function clearField<T extends GemElement>(instance: T, prop: string) {
30
- const { value } = getOwnPropertyDescriptor(instance, prop)!;
29
+ // hmr 支持不存在属性
30
+ const { value } = getOwnPropertyDescriptor(instance, prop) || {};
31
31
  deleteProperty(instance, prop);
32
32
  (instance as any)[prop] = value;
33
33
  }
@@ -37,18 +37,19 @@ const observedTargetAttributes = new WeakMap<GemElementPrototype, Map<string, st
37
37
  // 不在 Devtools 中工作 https://developer.mozilla.org/en-US/docs/Mozilla/Add-ons/WebExtensions/Content_scripts#dom_access
38
38
  // 使用 Gem DevTools 注入脚本监听 attribute 变化
39
39
  const { setAttribute, toggleAttribute, removeAttribute } = Element.prototype;
40
+ const getObservedPropName = (i: GemElement, n: string) => observedTargetAttributes.get(getPrototypeOf(i))?.get(n);
40
41
  GemElement.prototype.setAttribute = function (n: string, v: string) {
41
- const prop = observedTargetAttributes.get(getPrototypeOf(this))?.get(n);
42
+ const prop = getObservedPropName(this, n);
42
43
  if (!prop) return setAttribute.call(this, n, v);
43
44
  (this as any)[prop] = v;
44
45
  };
45
46
  GemElement.prototype.removeAttribute = function (n: string) {
46
- const prop = observedTargetAttributes.get(getPrototypeOf(this))?.get(n);
47
+ const prop = getObservedPropName(this, n);
47
48
  if (!prop) return removeAttribute.call(this, n);
48
49
  (this as any)[prop] = null;
49
50
  };
50
51
  GemElement.prototype.toggleAttribute = function (n: string, force?: boolean) {
51
- const prop = observedTargetAttributes.get(getPrototypeOf(this))?.get(n);
52
+ const prop = getObservedPropName(this, n);
52
53
  if (!prop) return toggleAttribute.call(this, n, force);
53
54
  return ((this as any)[prop] = force ?? !this.hasAttribute(n));
54
55
  };
@@ -114,7 +115,7 @@ function defineProp(
114
115
 
115
116
  // https://github.com/tc39/proposal-decorators/issues/517
116
117
  const targetCache = new WeakMap<DecoratorMetadataObject, GemElementPrototype>();
117
- function getDecoratorTarget(element: GemElement, { metadata }: ClassFieldDecoratorContext) {
118
+ function getDecoratorTarget(element: GemElement, { metadata }: ClassMemberDecoratorContext) {
118
119
  const target = targetCache.get(metadata);
119
120
  if (target) return target;
120
121
  let result = element as GemElementPrototype;
@@ -131,7 +132,7 @@ function decoratorAttr<T extends GemElement>(context: ClassFieldDecoratorContext
131
132
  const attr = camelToKebabCase(prop);
132
133
  context.addInitializer(function (this: T) {
133
134
  const target = getDecoratorTarget(this, context);
134
- if (!target.hasOwnProperty(prop)) {
135
+ if (!hasOwn(target, prop)) {
135
136
  pushStaticField(context, 'observedAttributes', attr); // 没有 observe 的效果
136
137
  defineProp(target, prop, { attr, attrType });
137
138
  }
@@ -151,11 +152,11 @@ function decoratorAttr<T extends GemElement>(context: ClassFieldDecoratorContext
151
152
  /**
152
153
  * 定义一个响应式的 attribute,驼峰字段名将自动映射到烤串 attribute,默认值为空字符串;不要覆盖定义
153
154
  *
154
- * For example
155
+ * @example
155
156
  * ```ts
156
- * class App extends GemElement {
157
- * @attribute attr: string;
158
- * }
157
+ * class App extends GemElement {
158
+ * @​attribute attr: string;
159
+ * }
159
160
  * ```
160
161
  */
161
162
  export function attribute<T extends GemElement>(_: undefined, context: ClassFieldDecoratorContext<T, string>) {
@@ -171,18 +172,18 @@ export function numattribute<T extends GemElement>(_: undefined, context: ClassF
171
172
  /**
172
173
  * 定义一个响应式的 property,注意值可能为 `undefined`;不要覆盖定义
173
174
  *
174
- * For example
175
+ * @example
175
176
  * ```ts
176
- * class App extends GemElement {
177
- * @property prop: Data | undefined;
178
- * }
177
+ * class App extends GemElement {
178
+ * @​property prop: Data | undefined;
179
+ * }
179
180
  * ```
180
181
  */
181
182
  export function property<T extends GemElement>(_: undefined, context: ClassFieldDecoratorContext<T>) {
182
183
  const prop = context.name as string;
183
184
  context.addInitializer(function (this: T) {
184
185
  const target = getDecoratorTarget(this, context);
185
- if (!target.hasOwnProperty(prop)) {
186
+ if (!hasOwn(target, prop)) {
186
187
  pushStaticField(context, 'observedProperties', prop);
187
188
  defineProp(target, prop);
188
189
  }
@@ -197,32 +198,40 @@ export function property<T extends GemElement>(_: undefined, context: ClassField
197
198
  /**
198
199
  * 依赖 `GemElement.memo`
199
200
  *
200
- * For example
201
+ * @example
201
202
  * ```ts
202
- * class App extends GemElement {
203
- * @memo(() => [])
204
- * get data() {
205
- * return 1;
206
- * }
207
- * }
203
+ * class App extends GemElement {
204
+ * @​memo(() => [])
205
+ * get data() {
206
+ * return 1;
207
+ * }
208
+ * }
208
209
  * ```
209
210
  */
210
211
  export function memo<T extends GemElement, V = any, K = any[] | undefined>(
211
212
  getDep?: K extends readonly any[] ? (instance: T) => K : undefined,
212
213
  ) {
213
- return function (
214
+ return (
214
215
  _: any,
215
216
  context: ClassGetterDecoratorContext<T, V> | ClassFieldDecoratorContext<T> | ClassMethodDecoratorContext<T>,
216
- ) {
217
+ ) => {
217
218
  const { addInitializer, name, access, kind } = context;
218
219
  addInitializer(function (this: T) {
219
220
  const dep = getDep && (() => getDep(this) as any);
220
221
  if (kind === 'getter') {
221
222
  // 不能设置私有字段 https://github.com/tc39/proposal-decorators/issues/509
222
223
  if (context.private) throw new GemError('not support');
223
- this.memo(() => defineProperty(this, name, { configurable: true, value: access.get(this) }), dep);
224
+ const target = getDecoratorTarget(this, context as any);
225
+ // 不能直接用 `access.get.bind(this)` 是现有 builder 工具的 bug?
226
+ const getter = getOwnPropertyDescriptor(target, name)!.get!.bind(this);
227
+ this.memo(() => {
228
+ defineProperty(this, name, {
229
+ configurable: true,
230
+ value: getter(),
231
+ });
232
+ }, dep);
224
233
  } else {
225
- this.memo((access.get(this) as any).bind(this) as any, dep);
234
+ this.memo((access.get.call(this, this) as any).bind(this), dep);
226
235
  }
227
236
  });
228
237
  };
@@ -233,37 +242,31 @@ export function memo<T extends GemElement, V = any, K = any[] | undefined>(
233
242
  * - 方法执行在字段前面
234
243
  * - 如果没有 oldValue,在为首次执行
235
244
  *
236
- * For example
245
+ * @example
237
246
  * ```ts
238
- * class App extends GemElement {
239
- * @effect(() => [])
240
- * #fetchData(newValue, oldValue) {
241
- * console.log('fetch')
242
- * }
243
- * }
247
+ * class App extends GemElement {
248
+ * @​effect(() => [])
249
+ * #fetchData(newValue, oldValue) {
250
+ * console.log('fetch')
251
+ * }
252
+ * }
244
253
  * ```
245
254
  */
246
255
  export function effect<T extends GemElement, V extends (depValues: K, oldDepValues?: K) => any, K = any[] | undefined>(
247
256
  getDep?: K extends readonly any[] ? (instance: T) => K : undefined,
248
257
  ) {
249
- return function (
250
- _: any,
251
- { addInitializer, access }: ClassFieldDecoratorContext<T, V> | ClassMethodDecoratorContext<T, V>,
252
- ) {
258
+ return (_: any, { addInitializer, access }: ClassFieldDecoratorContext<T, V> | ClassMethodDecoratorContext<T, V>) => {
253
259
  addInitializer(function (this: T) {
254
- this.effect(access.get(this).bind(this) as any, getDep && (() => getDep(this) as any));
260
+ this.effect(access.get.call(this, this).bind(this) as any, getDep && (() => getDep(this) as any));
255
261
  });
256
262
  };
257
263
  }
258
264
 
259
265
  export function unmounted<T extends GemElement, V extends () => any>() {
260
- return function (
261
- _: any,
262
- { addInitializer, access }: ClassFieldDecoratorContext<T, V> | ClassMethodDecoratorContext<T, V>,
263
- ) {
266
+ return (_: any, { addInitializer, access }: ClassFieldDecoratorContext<T, V> | ClassMethodDecoratorContext<T, V>) => {
264
267
  addInitializer(function (this: T) {
265
268
  this.effect(
266
- () => access.get(this).bind(this) as any,
269
+ () => access.get.call(this, this).bind(this) as any,
267
270
  () => [],
268
271
  );
269
272
  });
@@ -284,13 +287,10 @@ export function template<T extends GemElement, V extends () => TemplateResult |
284
287
  /** 当所有 `template` 返回 `false` 时不进行更新,包括 `memo` */
285
288
  condition?: (instance: T) => boolean,
286
289
  ) {
287
- return function (
288
- _: any,
289
- { addInitializer, access }: ClassFieldDecoratorContext<T, V> | ClassMethodDecoratorContext<T, V>,
290
- ) {
290
+ return (_: any, { addInitializer, access }: ClassFieldDecoratorContext<T, V> | ClassMethodDecoratorContext<T, V>) => {
291
291
  addInitializer(function (this: T) {
292
292
  _createTemplate(this, {
293
- render: access.get(this).bind(this),
293
+ render: access.get.call(this, this).bind(this),
294
294
  condition: condition && (() => condition(this) as any),
295
295
  });
296
296
  });
@@ -298,13 +298,10 @@ export function template<T extends GemElement, V extends () => TemplateResult |
298
298
  }
299
299
 
300
300
  export function fallback<T extends GemElement, V extends (err: any) => TemplateResult | null | undefined>() {
301
- return function (
302
- _: any,
303
- { addInitializer, access }: ClassFieldDecoratorContext<T, V> | ClassMethodDecoratorContext<T, V>,
304
- ) {
301
+ return (_: any, { addInitializer, access }: ClassFieldDecoratorContext<T, V> | ClassMethodDecoratorContext<T, V>) => {
305
302
  addInitializer(function (this: T) {
306
303
  this.addEventListener(_RenderErrorEvent, ({ detail }: CustomEvent) => {
307
- render(access.get(this).apply(this, [detail]), this.internals.shadowRoot || this);
304
+ render(access.get.call(this, this).apply(this, [detail]), this.internals.shadowRoot || this);
308
305
  });
309
306
  });
310
307
  };
@@ -336,11 +333,11 @@ function defineCSSState(target: GemElementPrototype, prop: string, stateStr: str
336
333
  * 重新赋值转换 css 伪类
337
334
  * 将来也可能用于 IDE 识别
338
335
  *
339
- * For example
336
+ * @example
340
337
  * ```ts
341
- * class App extends GemElement {
342
- * @state state: boolean;
343
- * }
338
+ * class App extends GemElement {
339
+ * @​state state: boolean;
340
+ * }
344
341
  * ```
345
342
  */
346
343
  export function state<T extends GemElement>(_: undefined, context: ClassFieldDecoratorContext<T, boolean>) {
@@ -348,7 +345,7 @@ export function state<T extends GemElement>(_: undefined, context: ClassFieldDec
348
345
  const attr = camelToKebabCase(prop);
349
346
  context.addInitializer(function (this: T) {
350
347
  const target = getDecoratorTarget(this, context);
351
- if (!target.hasOwnProperty(prop)) {
348
+ if (!hasOwn(target, prop)) {
352
349
  pushStaticField(context, 'definedCSSStates', attr);
353
350
  defineCSSState(target, prop, attr);
354
351
  }
@@ -379,12 +376,12 @@ function defineStaticField(
379
376
  /**
380
377
  * 定义一个内部 slot,默认值即为字段名,不能使用全局属性 `slot`
381
378
  *
382
- * For example
379
+ * @example
383
380
  * ```ts
384
- * class App extends GemElement {
385
- * @slot slot: string;
386
- * @slot static slot: string;
387
- * }
381
+ * class App extends GemElement {
382
+ * @​slot slot: string;
383
+ * @​slot static slot: string;
384
+ * }
388
385
  * ```
389
386
  */
390
387
  export function slot(_: undefined, context: ClassFieldDecoratorContext<any, string>) {
@@ -396,12 +393,12 @@ export function slot(_: undefined, context: ClassFieldDecoratorContext<any, stri
396
393
  /**
397
394
  * 定义一个内部 part,默认值即为字段名,不能使用全局属性 `part`
398
395
  *
399
- * For example
396
+ * @example
400
397
  * ```ts
401
- * class App extends GemElement {
402
- * @part part: string;
403
- * @part static part: string;
404
- * }
398
+ * class App extends GemElement {
399
+ * @​part part: string;
400
+ * @​part static part: string;
401
+ * }
405
402
  * ```
406
403
  */
407
404
  export function part(_: undefined, context: ClassFieldDecoratorContext<any, string>) {
@@ -410,17 +407,27 @@ export function part(_: undefined, context: ClassFieldDecoratorContext<any, stri
410
407
  };
411
408
  }
412
409
 
413
- export type Emitter<T = any> = (detail?: T, options?: Omit<CustomEventInit<unknown>, 'detail'>) => Promise<void> | void;
410
+ type EmitterHandler<T> = (evt: CustomEvent<T>) => void;
411
+
412
+ export type Emitter<T = any> = ((
413
+ detail?: T,
414
+ options?: Omit<CustomEventInit<unknown>, 'detail'>,
415
+ ) => Promise<void> | void) & {
416
+ /**
417
+ * @internal 用来为 ts plugin 提供类型签名,没有值
418
+ */
419
+ handler?: EmitterHandler<T> | (AddEventListenerOptions & { handleEvent: EmitterHandler<T> });
420
+ };
414
421
 
415
422
  /**
416
423
  * 定义一个事件发射器,类似 `HTMLElement.click`,
417
424
  * 调用时将同步发送一个和字段名称的烤串式格式的自定义事件
418
425
  *
419
- * For example
426
+ * @example
420
427
  * ```ts
421
- * class App extends GemElement {
422
- * @emitter load: Function;
423
- * }
428
+ * class App extends GemElement {
429
+ * @​emitter load: Function;
430
+ * }
424
431
  * ```
425
432
  */
426
433
  export function emitter<T extends GemElement>(_: undefined, context: ClassFieldDecoratorContext<T, Emitter>) {
@@ -437,7 +444,7 @@ function defineEmitter<T extends GemElement>(
437
444
  const event = camelToKebabCase(prop);
438
445
  context.addInitializer(function (this: T) {
439
446
  const target = getDecoratorTarget(this, context);
440
- if (!target.hasOwnProperty(prop)) {
447
+ if (!hasOwn(target, prop)) {
441
448
  pushStaticField(context, 'definedEvents', event);
442
449
  defineProp(target, prop, { event, eventOptions });
443
450
  }
@@ -448,14 +455,14 @@ function defineEmitter<T extends GemElement>(
448
455
  /**
449
456
  * 分配一个构造的样式表,前面的优先级越高(因为装饰器是越近越早执行)
450
457
  *
451
- * For example
458
+ * @example
452
459
  * ```ts
453
- * @adoptedStyle(stylesheet)
454
- * class App extends GemElement {}
460
+ * ​@​adoptedStyle(stylesheet)
461
+ * class App extends GemElement {}
455
462
  * ```
456
463
  */
457
- export function adoptedStyle(sheet: ReturnType<typeof css>) {
458
- return function (_: unknown, context: ClassDecoratorContext) {
464
+ export function adoptedStyle(sheet: Sheet<unknown>) {
465
+ return (_: unknown, context: ClassDecoratorContext) => {
459
466
  pushStaticField(context, 'adoptedStyleSheets', sheet);
460
467
  };
461
468
  }
@@ -463,14 +470,14 @@ export function adoptedStyle(sheet: ReturnType<typeof css>) {
463
470
  /**
464
471
  * 链接一个 store,当 store 更新时更新元素
465
472
  *
466
- * For example
473
+ * @example
467
474
  * ```ts
468
- * @connectStore(store)
469
- * class App extends GemElement {}
475
+ * ​@​connectStore(store)
476
+ * class App extends GemElement {}
470
477
  * ```
471
478
  */
472
479
  export function connectStore(store: Store<any>) {
473
- return function (_: unknown, context: ClassDecoratorContext) {
480
+ return (_: unknown, context: ClassDecoratorContext) => {
474
481
  pushStaticField(context, 'observedStores', store);
475
482
  };
476
483
  }
@@ -481,14 +488,14 @@ export function shadow({
481
488
  delegatesFocus,
482
489
  slotAssignment,
483
490
  }: Partial<ShadowRootInit> = {}) {
484
- return function (_: any, context: ClassDecoratorContext) {
491
+ return (_: any, context: ClassDecoratorContext) => {
485
492
  const metadata = context.metadata as Metadata;
486
493
  assign(metadata, { mode, serializable, delegatesFocus, slotAssignment });
487
494
  };
488
495
  }
489
496
 
490
497
  export function light({ penetrable }: Pick<Metadata, 'penetrable'>) {
491
- return function (_: any, context: ClassDecoratorContext) {
498
+ return (_: any, context: ClassDecoratorContext) => {
492
499
  const metadata = context.metadata as Metadata;
493
500
  metadata.penetrable = penetrable;
494
501
  };
@@ -499,7 +506,7 @@ export function light({ penetrable }: Pick<Metadata, 'penetrable'>) {
499
506
  * 例如:https://examples.gemjs.org/async
500
507
  */
501
508
  export function async() {
502
- return function (_: any, context: ClassDecoratorContext) {
509
+ return (_: any, context: ClassDecoratorContext) => {
503
510
  const metadata = context.metadata as Metadata;
504
511
  metadata.noBlocking = true;
505
512
  };
@@ -509,7 +516,7 @@ export function async() {
509
516
  * 定义元素的可访问性属性
510
517
  */
511
518
  export function aria(info: Metadata['aria']) {
512
- return function (_: any, context: ClassDecoratorContext) {
519
+ return (_: any, context: ClassDecoratorContext) => {
513
520
  const metadata = context.metadata as Metadata;
514
521
  metadata.aria = { ...metadata.aria, ...info };
515
522
  };
@@ -518,33 +525,16 @@ export function aria(info: Metadata['aria']) {
518
525
  /**
519
526
  * 定义自定义元素
520
527
  *
521
- * For example
528
+ * @example
522
529
  * ```ts
523
- * @customElement('my-element')
524
- * class App extends GemElement {}
530
+ * ​@​customElement('my-element')
531
+ * class App extends GemElement {}
525
532
  * ```
526
533
  */
527
534
  export function customElement(name: string) {
528
- return function (cls: new (...args: any) => any, { addInitializer }: ClassDecoratorContext) {
529
- addInitializer(function () {
535
+ return (cls: new (...args: any) => any, { addInitializer }: ClassDecoratorContext) => {
536
+ addInitializer(() => {
530
537
  customElements.define(name, cls);
531
538
  });
532
539
  };
533
540
  }
534
-
535
- declare global {
536
- interface Window {
537
- __GEM_DEVTOOLS__HOOK__?:
538
- | (typeof elementExports & typeof decoratorsExports & typeof storeExports & typeof versionExports)
539
- | Record<string, never>;
540
- }
541
- }
542
-
543
- if (window.__GEM_DEVTOOLS__HOOK__ && !window.__GEM_DEVTOOLS__HOOK__.GemElement) {
544
- assign(window.__GEM_DEVTOOLS__HOOK__, {
545
- ...elementExports,
546
- ...decoratorsExports,
547
- ...storeExports,
548
- ...versionExports,
549
- });
550
- }
@@ -35,7 +35,7 @@ export interface DirectiveResult<C extends DirectiveClass = DirectiveClass> {
35
35
  * This property needs to remain unminified.
36
36
  * @internal
37
37
  */
38
- ['_$litDirective$']: C;
38
+ _$litDirective$: C;
39
39
  /** @internal */
40
40
  values: DirectiveParameters<InstanceType<C>>;
41
41
  }
@@ -86,7 +86,7 @@ export const directive =
86
86
  <C extends DirectiveClass>(c: C) =>
87
87
  (...values: DirectiveParameters<InstanceType<C>>): DirectiveResult<C> => ({
88
88
  // This property needs to remain unminified.
89
- ['_$litDirective$']: c,
89
+ _$litDirective$: c,
90
90
  values,
91
91
  });
92
92
 
@@ -111,9 +111,7 @@ export abstract class Directive implements Disconnectable {
111
111
  _$disconnectableChildren?: Set<Disconnectable>;
112
112
  // This property needs to remain unminified.
113
113
  //@internal
114
- ['_$notifyDirectiveConnectionChanged']?(isConnected: boolean): void;
115
-
116
- constructor(_partInfo: PartInfo) {}
114
+ _$notifyDirectiveConnectionChanged?(isConnected: boolean): void;
117
115
 
118
116
  // See comment in Disconnectable interface for why this is a getter
119
117
  get _$isConnected() {