@mulsense/xnew 0.1.1 → 0.1.3

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/dist/xnew.js CHANGED
@@ -4,6 +4,23 @@
4
4
  (global = typeof globalThis !== 'undefined' ? globalThis : global || self, global.xnew = factory());
5
5
  })(this, (function () { 'use strict';
6
6
 
7
+ function ResizeEvent(resize) {
8
+ const observer = new ResizeObserver((entries) => {
9
+ for (const entry of entries) {
10
+ resize.emit('-resize');
11
+ break;
12
+ }
13
+ });
14
+ if (resize.element) {
15
+ observer.observe(resize.element);
16
+ }
17
+ resize.on('finalize', () => {
18
+ if (resize.element) {
19
+ observer.unobserve(resize.element);
20
+ }
21
+ });
22
+ }
23
+
7
24
  //----------------------------------------------------------------------------------------------------
8
25
  // ticker
9
26
  //----------------------------------------------------------------------------------------------------
@@ -108,56 +125,42 @@
108
125
  }
109
126
  }
110
127
 
111
- //----------------------------------------------------------------------------------------------------
112
- // map ex
113
- //----------------------------------------------------------------------------------------------------
114
- class MapEx {
115
- constructor() {
116
- this.map = new Map;
117
- }
118
- get size() {
119
- return this.map.size;
120
- }
121
- forEach(callback) {
122
- this.map.forEach(callback);
123
- }
124
- clear() {
125
- this.map.clear();
126
- }
127
- }
128
128
  //----------------------------------------------------------------------------------------------------
129
129
  // map set
130
130
  //----------------------------------------------------------------------------------------------------
131
- class MapSet extends MapEx {
131
+ class MapSet extends Map {
132
132
  has(key, value) {
133
133
  var _a, _b;
134
134
  if (value === undefined) {
135
- return this.map.has(key);
135
+ return super.has(key);
136
136
  }
137
137
  else {
138
- return (_b = (_a = this.map.get(key)) === null || _a === void 0 ? void 0 : _a.has(value)) !== null && _b !== void 0 ? _b : false;
138
+ return (_b = (_a = super.get(key)) === null || _a === void 0 ? void 0 : _a.has(value)) !== null && _b !== void 0 ? _b : false;
139
139
  }
140
140
  }
141
- get(key) {
142
- return this.map.get(key);
143
- }
144
- keys() {
145
- return this.map.keys();
146
- }
147
141
  add(key, value) {
148
142
  var _a;
149
- this.map.set(key, ((_a = this.map.get(key)) !== null && _a !== void 0 ? _a : new Set).add(value));
143
+ super.set(key, ((_a = super.get(key)) !== null && _a !== void 0 ? _a : new Set).add(value));
150
144
  return this;
151
145
  }
146
+ keys(key) {
147
+ var _a, _b;
148
+ if (key === undefined) {
149
+ return super.keys();
150
+ }
151
+ else {
152
+ return (_b = (_a = super.get(key)) === null || _a === void 0 ? void 0 : _a.values()) !== null && _b !== void 0 ? _b : [].values();
153
+ }
154
+ }
152
155
  delete(key, value) {
153
156
  var _a, _b, _c, _d;
154
157
  let ret = false;
155
158
  if (value === undefined) {
156
- ret = (((_a = this.map.get(key)) === null || _a === void 0 ? void 0 : _a.size) === 0) ? this.map.delete(key) : false;
159
+ ret = (((_a = super.get(key)) === null || _a === void 0 ? void 0 : _a.size) === 0) ? super.delete(key) : false;
157
160
  }
158
161
  else {
159
- ret = (_c = (_b = this.map.get(key)) === null || _b === void 0 ? void 0 : _b.delete(value)) !== null && _c !== void 0 ? _c : false;
160
- (((_d = this.map.get(key)) === null || _d === void 0 ? void 0 : _d.size) === 0) && this.map.delete(key);
162
+ ret = (_c = (_b = super.get(key)) === null || _b === void 0 ? void 0 : _b.delete(value)) !== null && _c !== void 0 ? _c : false;
163
+ (((_d = super.get(key)) === null || _d === void 0 ? void 0 : _d.size) === 0) && super.delete(key);
161
164
  }
162
165
  return ret;
163
166
  }
@@ -165,131 +168,71 @@
165
168
  //----------------------------------------------------------------------------------------------------
166
169
  // map map
167
170
  //----------------------------------------------------------------------------------------------------
168
- class MapMap extends MapEx {
171
+ class MapMap extends Map {
169
172
  has(key1, key2) {
170
173
  var _a, _b;
171
174
  if (key2 === undefined) {
172
- return this.map.has(key1);
175
+ return super.has(key1);
173
176
  }
174
177
  else {
175
- return (_b = (_a = this.map.get(key1)) === null || _a === void 0 ? void 0 : _a.has(key2)) !== null && _b !== void 0 ? _b : false;
178
+ return (_b = (_a = super.get(key1)) === null || _a === void 0 ? void 0 : _a.has(key2)) !== null && _b !== void 0 ? _b : false;
176
179
  }
177
180
  }
178
- set(key1, key2, value) {
181
+ set(key1, key2OrValue, value) {
179
182
  var _a;
180
- this.map.set(key1, ((_a = this.map.get(key1)) !== null && _a !== void 0 ? _a : new Map).set(key2, value));
183
+ if (value === undefined) {
184
+ // 2 args: directly set Map<Key2, Value>
185
+ super.set(key1, key2OrValue);
186
+ }
187
+ else {
188
+ // 3 args: set nested value
189
+ super.set(key1, ((_a = super.get(key1)) !== null && _a !== void 0 ? _a : new Map).set(key2OrValue, value));
190
+ }
181
191
  return this;
182
192
  }
183
193
  get(key1, key2) {
184
194
  var _a;
185
195
  if (key2 === undefined) {
186
- return this.map.get(key1);
196
+ return super.get(key1);
187
197
  }
188
198
  else {
189
- return (_a = this.map.get(key1)) === null || _a === void 0 ? void 0 : _a.get(key2);
199
+ return (_a = super.get(key1)) === null || _a === void 0 ? void 0 : _a.get(key2);
190
200
  }
191
201
  }
192
202
  keys(key1) {
193
203
  var _a, _b;
194
204
  if (key1 === undefined) {
195
- return this.map.keys();
205
+ return super.keys();
196
206
  }
197
207
  else {
198
- return (_b = (_a = this.map.get(key1)) === null || _a === void 0 ? void 0 : _a.keys()) !== null && _b !== void 0 ? _b : (function* () { })();
208
+ return (_b = (_a = super.get(key1)) === null || _a === void 0 ? void 0 : _a.keys()) !== null && _b !== void 0 ? _b : [].values();
199
209
  }
200
210
  }
201
211
  delete(key1, key2) {
202
212
  var _a, _b, _c, _d;
203
213
  let ret = false;
204
214
  if (key2 === undefined) {
205
- ret = (((_a = this.map.get(key1)) === null || _a === void 0 ? void 0 : _a.size) === 0) ? this.map.delete(key1) : false;
206
- }
207
- else {
208
- ret = (_c = (_b = this.map.get(key1)) === null || _b === void 0 ? void 0 : _b.delete(key2)) !== null && _c !== void 0 ? _c : false;
209
- (((_d = this.map.get(key1)) === null || _d === void 0 ? void 0 : _d.size) === 0) && this.map.delete(key1);
210
- }
211
- return ret;
212
- }
213
- }
214
- //----------------------------------------------------------------------------------------------------
215
- // map map map
216
- //----------------------------------------------------------------------------------------------------
217
- class MapMapMap extends MapEx {
218
- has(key1, key2, key3) {
219
- var _a, _b;
220
- if (key2 === undefined) {
221
- return this.map.has(key1);
222
- }
223
- else {
224
- return (_b = (_a = this.map.get(key1)) === null || _a === void 0 ? void 0 : _a.has(key2, key3)) !== null && _b !== void 0 ? _b : false;
225
- }
226
- }
227
- set(key1, key2, key3, value) {
228
- var _a;
229
- this.map.set(key1, ((_a = this.map.get(key1)) !== null && _a !== void 0 ? _a : new MapMap).set(key2, key3, value));
230
- return this;
231
- }
232
- get(key1, key2, key3) {
233
- var _a, _b;
234
- if (key2 === undefined) {
235
- return this.map.get(key1);
236
- }
237
- else if (key3 === undefined) {
238
- return (_a = this.map.get(key1)) === null || _a === void 0 ? void 0 : _a.get(key2);
239
- }
240
- else {
241
- return (_b = this.map.get(key1)) === null || _b === void 0 ? void 0 : _b.get(key2, key3);
242
- }
243
- }
244
- keys(key1, key2) {
245
- var _a, _b, _c, _d, _e;
246
- if (key1 === undefined) {
247
- return this.map.keys();
248
- }
249
- else if (key2 === undefined) {
250
- return (_b = (_a = this.map.get(key1)) === null || _a === void 0 ? void 0 : _a.keys()) !== null && _b !== void 0 ? _b : (function* () { })();
251
- }
252
- else {
253
- return (_e = (_d = (_c = this.map.get(key1)) === null || _c === void 0 ? void 0 : _c.get(key2)) === null || _d === void 0 ? void 0 : _d.keys()) !== null && _e !== void 0 ? _e : (function* () { })();
254
- }
255
- }
256
- delete(key1, key2, key3) {
257
- var _a, _b, _c, _d;
258
- let ret = false;
259
- if (key2 === undefined) {
260
- ret = (((_a = this.map.get(key1)) === null || _a === void 0 ? void 0 : _a.size) === 0) ? this.map.delete(key1) : false;
215
+ ret = (((_a = super.get(key1)) === null || _a === void 0 ? void 0 : _a.size) === 0) ? super.delete(key1) : false;
261
216
  }
262
217
  else {
263
- ret = (_c = (_b = this.map.get(key1)) === null || _b === void 0 ? void 0 : _b.delete(key2, key3)) !== null && _c !== void 0 ? _c : false;
264
- (((_d = this.map.get(key1)) === null || _d === void 0 ? void 0 : _d.size) === 0) && this.map.delete(key1);
218
+ ret = (_c = (_b = super.get(key1)) === null || _b === void 0 ? void 0 : _b.delete(key2)) !== null && _c !== void 0 ? _c : false;
219
+ (((_d = super.get(key1)) === null || _d === void 0 ? void 0 : _d.size) === 0) && super.delete(key1);
265
220
  }
266
221
  return ret;
267
222
  }
268
223
  }
269
224
 
270
225
  //----------------------------------------------------------------------------------------------------
271
- // Constants
226
+ // Definitions
272
227
  //----------------------------------------------------------------------------------------------------
273
- const LIFECYCLE_EVENTS = ['start', 'update', 'stop', 'finalize'];
274
- const LIFECYCLE_STATES = {
275
- INVOKED: 'invoked',
276
- INITIALIZED: 'initialized',
277
- STARTED: 'started',
278
- STOPPED: 'stopped',
279
- PRE_FINALIZED: 'pre finalized',
280
- FINALIZED: 'finalized',
281
- };
282
- const CUSTOM_EVENT_PREFIX = {
283
- GLOBAL: '+',
284
- INTERNAL: '-',
285
- };
228
+ const SYSTEM_EVENTS = ['start', 'update', 'stop', 'finalize'];
286
229
  //----------------------------------------------------------------------------------------------------
287
- // unit main
230
+ // Unit
288
231
  //----------------------------------------------------------------------------------------------------
289
232
  class Unit {
290
233
  constructor(target, component, props) {
291
- var _a, _b, _c, _d, _e;
292
- const parent = UnitScope.current;
234
+ var _a, _b, _c;
235
+ const parent = Unit.current;
293
236
  let baseElement;
294
237
  if (target instanceof HTMLElement || target instanceof SVGElement) {
295
238
  baseElement = target;
@@ -298,27 +241,29 @@
298
241
  baseElement = (_a = parent._.currentElement) !== null && _a !== void 0 ? _a : parent._.baseElement;
299
242
  }
300
243
  else {
301
- baseElement = (_c = (_b = document.currentScript) === null || _b === void 0 ? void 0 : _b.parentElement) !== null && _c !== void 0 ? _c : document.body;
244
+ baseElement = document.body;
302
245
  }
303
- let baseComponent = null;
246
+ let baseComponent;
304
247
  if (typeof component === 'function') {
305
248
  baseComponent = component;
306
249
  }
307
250
  else if (typeof component === 'string') {
308
251
  baseComponent = (self) => { self.element.textContent = component; };
309
252
  }
253
+ else {
254
+ baseComponent = (self) => { };
255
+ }
256
+ const baseContext = (_b = parent === null || parent === void 0 ? void 0 : parent._.currentContext) !== null && _b !== void 0 ? _b : null;
310
257
  this._ = {
311
- root: (_d = parent === null || parent === void 0 ? void 0 : parent._.root) !== null && _d !== void 0 ? _d : this,
312
258
  parent,
313
259
  target,
260
+ baseElement,
261
+ baseContext,
314
262
  baseComponent,
315
263
  props,
316
- baseElement,
317
- nextNest: { element: baseElement, position: 'beforeend' },
318
- baseContext: UnitScope.get(parent),
319
264
  };
320
- ((_e = parent === null || parent === void 0 ? void 0 : parent._.children) !== null && _e !== void 0 ? _e : Unit.roots).push(this);
321
- Unit.initialize(this);
265
+ ((_c = parent === null || parent === void 0 ? void 0 : parent._.children) !== null && _c !== void 0 ? _c : Unit.roots).push(this);
266
+ Unit.initialize(this, { element: baseElement, position: 'beforeend' });
322
267
  }
323
268
  get element() {
324
269
  return this._.currentElement;
@@ -342,99 +287,50 @@
342
287
  }
343
288
  reboot() {
344
289
  Unit.stop(this);
345
- let trace = this._.currentElement;
346
- while (trace.parentElement && trace.parentElement !== this._.baseElement) {
347
- trace = trace.parentElement;
290
+ let first = this._.currentElement;
291
+ while (first.parentElement && first.parentElement !== this._.baseElement) {
292
+ first = first.parentElement;
348
293
  }
349
- if (trace.parentElement === this._.baseElement) {
350
- this._.nextNest.element = trace.nextElementSibling;
351
- this._.nextNest.position = 'beforebegin';
294
+ let nextNest;
295
+ if (first.parentElement === this._.baseElement && first.nextElementSibling) {
296
+ nextNest = { element: first.nextElementSibling, position: 'beforebegin' };
352
297
  }
353
- Unit.finalize(this);
354
- Unit.initialize(this);
355
- }
356
- get components() {
357
- return this._.components;
358
- }
359
- on(type, listener, options) {
360
- try {
361
- if (typeof type === 'string') {
362
- const filtered = type.trim().split(/\s+/).filter((type) => LIFECYCLE_EVENTS.includes(type));
363
- filtered.forEach((type) => {
364
- this._.system[type].push(listener);
365
- });
366
- }
367
- UnitEvent.on(this, type, listener, options);
368
- }
369
- catch (error) {
370
- console.error('unit.on(type, listener, option?): ', error);
371
- }
372
- return this;
373
- }
374
- off(type, listener) {
375
- try {
376
- if (type === undefined) {
377
- this._.system = { start: [], update: [], stop: [], finalize: [] };
378
- }
379
- else if (typeof type === 'string') {
380
- const filtered = type.trim().split(/\s+/).filter((type) => LIFECYCLE_EVENTS.includes(type));
381
- filtered.forEach((type) => {
382
- if (listener === undefined) {
383
- this._.system[type] = [];
384
- }
385
- else {
386
- this._.system[type] = this._.system[type].filter((l) => l !== listener);
387
- }
388
- });
389
- }
390
- UnitEvent.off(this, type, listener);
391
- }
392
- catch (error) {
393
- console.error('unit.off(type, listener): ', error);
394
- }
395
- return this;
396
- }
397
- emit(type, ...args) {
398
- try {
399
- UnitEvent.emit(this, type, ...args);
400
- }
401
- catch (error) {
402
- console.error('unit.emit(type, ...args): ', error);
298
+ else {
299
+ nextNest = { element: this._.baseElement, position: 'beforeend' };
403
300
  }
301
+ Unit.finalize(this);
302
+ Unit.initialize(this, nextNest);
404
303
  }
405
- //----------------------------------------------------------------------------------------------------
406
- // internal
407
- //----------------------------------------------------------------------------------------------------
408
- static initialize(unit) {
304
+ static initialize(unit, nextNest) {
409
305
  var _a;
410
306
  unit._ = Object.assign(unit._, {
307
+ nextNest,
411
308
  children: [],
412
- components: [],
309
+ components: new Set(),
310
+ listeners: new MapMap(),
311
+ sublisteners: new MapMap(),
413
312
  captures: [],
414
- state: LIFECYCLE_STATES.INVOKED,
313
+ state: 'invoked',
415
314
  tostart: true,
416
315
  currentElement: unit._.baseElement,
417
- upcount: 0,
418
- resolved: false,
316
+ currentContext: unit._.baseContext,
419
317
  defines: {},
420
318
  system: { start: [], update: [], stop: [], finalize: [] },
421
319
  });
422
- UnitScope.initialize(unit, unit._.baseContext);
320
+ Unit.current = unit;
423
321
  // nest html element
424
322
  if (typeof unit._.target === 'string') {
425
323
  Unit.nest(unit, unit._.target);
426
324
  }
427
325
  // setup component
428
326
  if (typeof unit._.baseComponent === 'function') {
429
- UnitScope.execute({ unit, context: null, element: null }, () => Unit.extend(unit, unit._.baseComponent, unit._.props));
327
+ Unit.extend(unit, unit._.baseComponent, unit._.props);
430
328
  }
431
329
  // whether the unit promise was resolved
432
- (_a = UnitPromise.get(unit)) === null || _a === void 0 ? void 0 : _a.then(() => {
433
- unit._.resolved = true;
434
- });
435
- unit._.state = LIFECYCLE_STATES.INITIALIZED;
330
+ (_a = UnitPromise.get(unit)) === null || _a === void 0 ? void 0 : _a.then(() => unit._.state = 'initialized');
331
+ // setup capture
436
332
  let current = unit;
437
- while (current !== null) {
333
+ while (1) {
438
334
  let captured = false;
439
335
  for (const capture of current._.captures) {
440
336
  if (capture.checker(unit)) {
@@ -442,25 +338,27 @@
442
338
  captured = true;
443
339
  }
444
340
  }
445
- if (captured === false) {
341
+ if (captured === false && current._.parent !== null) {
446
342
  current = current._.parent;
447
343
  }
448
344
  else {
449
345
  break;
450
346
  }
451
347
  }
348
+ Unit.current = unit._.parent;
452
349
  }
453
350
  static finalize(unit) {
454
- if (unit._.state !== LIFECYCLE_STATES.FINALIZED && unit._.state !== LIFECYCLE_STATES.PRE_FINALIZED) {
455
- unit._.state = LIFECYCLE_STATES.PRE_FINALIZED;
351
+ if (unit._.state !== 'finalized' && unit._.state !== 'pre-finalized') {
352
+ unit._.state = 'pre-finalized';
456
353
  unit._.children.forEach((child) => child.finalize());
457
354
  unit._.system.finalize.forEach((listener) => {
458
- UnitScope.execute(UnitScope.snapshot(unit), listener);
355
+ Unit.scope(Unit.snapshot(unit), listener);
356
+ });
357
+ unit.off();
358
+ Unit.suboff(unit, null);
359
+ unit._.components.forEach((component) => {
360
+ Unit.componentUnits.delete(component, unit);
459
361
  });
460
- UnitEvent.off(unit);
461
- UnitEvent.suboff(unit, null);
462
- UnitScope.finalize(unit);
463
- UnitComponent.finalize(unit);
464
362
  UnitPromise.finalize(unit);
465
363
  while (unit._.currentElement !== unit._.baseElement && unit._.currentElement.parentElement !== null) {
466
364
  const parent = unit._.currentElement.parentElement;
@@ -469,12 +367,12 @@
469
367
  }
470
368
  // reset defines
471
369
  Object.keys(unit._.defines).forEach((key) => {
472
- if (!LIFECYCLE_EVENTS.includes(key)) {
370
+ if (SYSTEM_EVENTS.includes(key) === false) {
473
371
  delete unit[key];
474
372
  }
475
373
  });
476
374
  unit._.defines = {};
477
- unit._.state = LIFECYCLE_STATES.FINALIZED;
375
+ unit._.state = 'finalized';
478
376
  }
479
377
  }
480
378
  static nest(unit, tag) {
@@ -496,66 +394,61 @@
496
394
  }
497
395
  static extend(unit, component, props) {
498
396
  var _a;
499
- unit._.components.push(component);
500
- UnitComponent.add(unit, component);
397
+ unit._.components.add(component);
398
+ Unit.componentUnits.add(component, unit);
501
399
  const defines = (_a = component(unit, props)) !== null && _a !== void 0 ? _a : {};
502
- const snapshot = UnitScope.snapshot(unit);
503
400
  Object.keys(defines).forEach((key) => {
504
- const descriptor = Object.getOwnPropertyDescriptor(defines, key);
505
401
  if (unit[key] !== undefined && unit._.defines[key] === undefined) {
506
402
  throw new Error(`The property "${key}" already exists.`);
507
403
  }
508
- const newDescriptor = { configurable: true, enumerable: true };
404
+ const descriptor = Object.getOwnPropertyDescriptor(defines, key);
405
+ const wrappedDesc = { configurable: true, enumerable: true };
509
406
  if (descriptor === null || descriptor === void 0 ? void 0 : descriptor.get) {
510
- newDescriptor.get = (...args) => UnitScope.execute(snapshot, descriptor.get, ...args);
407
+ wrappedDesc.get = Unit.wrap(descriptor.get);
511
408
  }
512
409
  if (descriptor === null || descriptor === void 0 ? void 0 : descriptor.set) {
513
- newDescriptor.set = (...args) => UnitScope.execute(snapshot, descriptor.set, ...args);
410
+ wrappedDesc.set = Unit.wrap(descriptor.set);
514
411
  }
515
412
  if (typeof (descriptor === null || descriptor === void 0 ? void 0 : descriptor.value) === 'function') {
516
- newDescriptor.value = (...args) => UnitScope.execute(snapshot, descriptor.value, ...args);
413
+ wrappedDesc.value = Unit.wrap(descriptor.value);
517
414
  }
518
415
  else if ((descriptor === null || descriptor === void 0 ? void 0 : descriptor.value) !== undefined) {
519
- newDescriptor.writable = true;
520
- newDescriptor.value = descriptor.value;
416
+ wrappedDesc.writable = true;
417
+ wrappedDesc.value = descriptor.value;
521
418
  }
522
- Object.defineProperty(unit._.defines, key, newDescriptor);
523
- Object.defineProperty(unit, key, newDescriptor);
419
+ Object.defineProperty(unit._.defines, key, wrappedDesc);
420
+ Object.defineProperty(unit, key, wrappedDesc);
524
421
  });
525
422
  }
526
423
  static start(unit, time) {
527
- if (!unit._.resolved || !unit._.tostart)
424
+ if (unit._.tostart === false)
528
425
  return;
529
- const { state } = unit._;
530
- if (state === LIFECYCLE_STATES.INVOKED || state === LIFECYCLE_STATES.INITIALIZED || state === LIFECYCLE_STATES.STOPPED) {
531
- unit._.state = LIFECYCLE_STATES.STARTED;
426
+ if (unit._.state === 'initialized' || unit._.state === 'stopped') {
427
+ unit._.state = 'started';
532
428
  unit._.children.forEach((child) => Unit.start(child, time));
533
429
  unit._.system.start.forEach((listener) => {
534
- UnitScope.execute(UnitScope.snapshot(unit), listener);
430
+ Unit.scope(Unit.snapshot(unit), listener);
535
431
  });
536
432
  }
537
- else if (state === LIFECYCLE_STATES.STARTED) {
433
+ else if (unit._.state === 'started') {
538
434
  unit._.children.forEach((child) => Unit.start(child, time));
539
435
  }
540
436
  }
541
437
  static stop(unit) {
542
- if (unit._.state === LIFECYCLE_STATES.STARTED) {
543
- unit._.state = LIFECYCLE_STATES.STOPPED;
438
+ if (unit._.state === 'started') {
439
+ unit._.state = 'stopped';
544
440
  unit._.children.forEach((child) => Unit.stop(child));
545
441
  unit._.system.stop.forEach((listener) => {
546
- UnitScope.execute(UnitScope.snapshot(unit), listener);
442
+ Unit.scope(Unit.snapshot(unit), listener);
547
443
  });
548
444
  }
549
445
  }
550
446
  static update(unit, time) {
551
- if (unit._.state === LIFECYCLE_STATES.STARTED) {
447
+ if (unit._.state === 'started') {
552
448
  unit._.children.forEach((child) => Unit.update(child, time));
553
- if (unit._.state === LIFECYCLE_STATES.STARTED) {
554
- unit._.system.update.forEach((listener) => {
555
- UnitScope.execute(UnitScope.snapshot(unit), listener, unit._.upcount);
556
- });
557
- unit._.upcount++;
558
- }
449
+ unit._.system.update.forEach((listener) => {
450
+ Unit.scope(Unit.snapshot(unit), listener);
451
+ });
559
452
  }
560
453
  }
561
454
  static ticker(time) {
@@ -570,40 +463,25 @@
570
463
  Ticker.clear(Unit.ticker);
571
464
  Ticker.set(Unit.ticker);
572
465
  }
573
- }
574
- Unit.roots = [];
575
- Unit.reset();
576
- //----------------------------------------------------------------------------------------------------
577
- // unit scope
578
- //----------------------------------------------------------------------------------------------------
579
- class UnitScope {
580
- static initialize(unit, context) {
581
- if (context !== null) {
582
- UnitScope.contexts.set(unit, context);
583
- }
584
- }
585
- static finalize(unit) {
586
- UnitScope.contexts.delete(unit);
587
- }
588
- static set(unit, context) {
589
- UnitScope.contexts.set(unit, context);
590
- }
591
- static get(unit) {
592
- var _a;
593
- return (_a = UnitScope.contexts.get(unit)) !== null && _a !== void 0 ? _a : null;
466
+ //----------------------------------------------------------------------------------------------------
467
+ // scope
468
+ //----------------------------------------------------------------------------------------------------
469
+ static wrap(listener) {
470
+ const snapshot = Unit.snapshot(Unit.current);
471
+ return (...args) => Unit.scope(snapshot, listener, ...args);
594
472
  }
595
- static execute(snapshot, func, ...args) {
596
- if (!snapshot)
473
+ static scope(snapshot, func, ...args) {
474
+ if (snapshot === null)
597
475
  return;
598
- const current = UnitScope.current;
476
+ const current = Unit.current;
599
477
  let context = null;
600
478
  let element = null;
601
479
  try {
602
- UnitScope.current = snapshot.unit;
480
+ Unit.current = snapshot.unit;
603
481
  if (snapshot.unit !== null) {
604
482
  if (snapshot.context !== null) {
605
- context = UnitScope.get(snapshot.unit);
606
- UnitScope.contexts.set(snapshot.unit, snapshot.context);
483
+ context = snapshot.unit._.currentContext;
484
+ snapshot.unit._.currentContext = snapshot.context;
607
485
  }
608
486
  if (snapshot.element !== null) {
609
487
  element = snapshot.unit._.currentElement;
@@ -616,10 +494,10 @@
616
494
  throw error;
617
495
  }
618
496
  finally {
619
- UnitScope.current = current;
497
+ Unit.current = current;
620
498
  if (snapshot.unit !== null) {
621
499
  if (context !== null) {
622
- UnitScope.contexts.set(snapshot.unit, context);
500
+ snapshot.unit._.currentContext = context;
623
501
  }
624
502
  if (element !== null) {
625
503
  snapshot.unit._.currentElement = element;
@@ -627,151 +505,96 @@
627
505
  }
628
506
  }
629
507
  }
630
- static snapshot(unit = UnitScope.current) {
631
- if (unit !== null) {
632
- return { unit, context: UnitScope.get(unit), element: unit.element };
633
- }
634
- return null;
508
+ static snapshot(unit) {
509
+ return { unit, context: unit._.currentContext, element: unit._.currentElement };
635
510
  }
636
511
  static stack(unit, key, value) {
637
- UnitScope.contexts.set(unit, { stack: UnitScope.get(unit), key, value });
512
+ unit._.currentContext = { stack: unit._.currentContext, key, value };
638
513
  }
639
514
  static trace(unit, key) {
640
- for (let context = UnitScope.get(unit); context !== null; context = context.stack) {
515
+ for (let context = unit._.currentContext; context !== null; context = context.stack) {
641
516
  if (context.key === key) {
642
517
  return context.value;
643
518
  }
644
519
  }
645
520
  }
646
- }
647
- UnitScope.current = null;
648
- UnitScope.contexts = new Map();
649
- //----------------------------------------------------------------------------------------------------
650
- // unit component
651
- //----------------------------------------------------------------------------------------------------
652
- class UnitComponent {
653
- static finalize(unit) {
654
- var _a;
655
- (_a = UnitComponent.components.get(unit)) === null || _a === void 0 ? void 0 : _a.forEach((component) => {
656
- UnitComponent.units.delete(component, unit);
657
- });
658
- UnitComponent.components.delete(unit);
659
- }
660
- static add(unit, component) {
661
- UnitComponent.components.add(unit, component);
662
- UnitComponent.units.add(component, unit);
521
+ get components() {
522
+ return this._.components;
663
523
  }
664
524
  static find(component) {
665
525
  var _a;
666
- return [...((_a = UnitComponent.units.get(component)) !== null && _a !== void 0 ? _a : [])];
526
+ return [...((_a = Unit.componentUnits.get(component)) !== null && _a !== void 0 ? _a : [])];
667
527
  }
668
- }
669
- UnitComponent.components = new MapSet();
670
- UnitComponent.units = new MapSet();
671
- //----------------------------------------------------------------------------------------------------
672
- // unit event
673
- //----------------------------------------------------------------------------------------------------
674
- class UnitEvent {
675
- static on(unit, type, listener, options) {
676
- if (typeof type !== 'string' || type.trim() === '') {
677
- throw new Error('"type" is invalid.');
678
- }
679
- else if (typeof listener !== 'function') {
680
- throw new Error('"listener" is invalid.');
681
- }
682
- const snapshot = UnitScope.snapshot();
683
- const types = type.trim().split(/\s+/);
684
- types.forEach((type) => {
685
- if (!UnitEvent.listeners.has(unit, type, listener)) {
686
- const execute = (...args) => {
687
- UnitScope.execute(snapshot, listener, ...args);
688
- };
689
- UnitEvent.listeners.set(unit, type, listener, [unit.element, execute]);
690
- UnitEvent.units.add(type, unit);
528
+ on(type, listener, options) {
529
+ if (this._.state === 'finalized')
530
+ return;
531
+ type.trim().split(/\s+/).forEach((type) => {
532
+ if (SYSTEM_EVENTS.includes(type)) {
533
+ this._.system[type].push(listener);
534
+ }
535
+ if (this._.listeners.has(type, listener) === false) {
536
+ const execute = Unit.wrap(listener);
537
+ this._.listeners.set(type, listener, [this.element, execute]);
538
+ Unit.typeUnits.add(type, this);
691
539
  if (/^[A-Za-z]/.test(type)) {
692
- unit.element.addEventListener(type, execute, options);
540
+ this.element.addEventListener(type, execute, options);
693
541
  }
694
542
  }
695
543
  });
696
544
  }
697
- static off(unit, type, listener) {
698
- if (typeof type === 'string' && type.trim() === '') {
699
- throw new Error('"type" is invalid.');
700
- }
701
- else if (listener !== undefined && typeof listener !== 'function') {
702
- throw new Error('"listener" is invalid.');
703
- }
704
- const types = typeof type === 'string' ? type.trim().split(/\s+/) : [...UnitEvent.listeners.keys(unit)];
545
+ off(type, listener) {
546
+ const types = typeof type === 'string' ? type.trim().split(/\s+/) : [...this._.listeners.keys()];
705
547
  types.forEach((type) => {
706
- const listeners = listener ? [listener] : [...UnitEvent.listeners.keys(unit, type)];
707
- listeners.forEach((lis) => {
708
- const tuple = UnitEvent.listeners.get(unit, type, lis);
548
+ if (SYSTEM_EVENTS.includes(type)) {
549
+ this._.system[type] = this._.system[type].filter((lis) => listener ? lis !== listener : false);
550
+ }
551
+ (listener ? [listener] : [...this._.listeners.keys(type)]).forEach((lis) => {
552
+ const tuple = this._.listeners.get(type, lis);
709
553
  if (tuple !== undefined) {
710
554
  const [target, execute] = tuple;
711
- UnitEvent.listeners.delete(unit, type, lis);
555
+ this._.listeners.delete(type, lis);
712
556
  if (/^[A-Za-z]/.test(type)) {
713
557
  target.removeEventListener(type, execute);
714
558
  }
715
559
  }
716
560
  });
717
- if (!UnitEvent.listeners.has(unit, type)) {
718
- UnitEvent.units.delete(type, unit);
561
+ if (this._.listeners.has(type) === false) {
562
+ Unit.typeUnits.delete(type, this);
719
563
  }
720
564
  });
721
565
  }
722
- static emit(unit, type, ...args) {
566
+ emit(type, ...args) {
723
567
  var _a, _b;
724
- if (typeof type !== 'string') {
725
- throw new Error('The argument [type] is invalid.');
726
- }
727
- else if ((unit === null || unit === void 0 ? void 0 : unit._.state) === LIFECYCLE_STATES.FINALIZED) {
728
- throw new Error('This function can not be called after finalized.');
729
- }
730
- if (type[0] === CUSTOM_EVENT_PREFIX.GLOBAL) {
731
- (_a = UnitEvent.units.get(type)) === null || _a === void 0 ? void 0 : _a.forEach((unit) => {
568
+ if (this._.state === 'finalized')
569
+ return;
570
+ if (type[0] === '+') {
571
+ (_a = Unit.typeUnits.get(type)) === null || _a === void 0 ? void 0 : _a.forEach((unit) => {
732
572
  var _a;
733
- (_a = UnitEvent.listeners.get(unit, type)) === null || _a === void 0 ? void 0 : _a.forEach(([_, execute]) => execute(...args));
573
+ (_a = unit._.listeners.get(type)) === null || _a === void 0 ? void 0 : _a.forEach(([_, execute]) => execute(...args));
734
574
  });
735
575
  }
736
- else if (type[0] === CUSTOM_EVENT_PREFIX.INTERNAL && unit !== null) {
737
- (_b = UnitEvent.listeners.get(unit, type)) === null || _b === void 0 ? void 0 : _b.forEach(([_, execute]) => execute(...args));
576
+ else if (type[0] === '-') {
577
+ (_b = this._.listeners.get(type)) === null || _b === void 0 ? void 0 : _b.forEach(([_, execute]) => execute(...args));
738
578
  }
739
579
  }
740
580
  static subon(unit, target, type, listener, options) {
741
- if (typeof type !== 'string' || type.trim() === '') {
742
- throw new Error('"type" is invalid.');
743
- }
744
- else if (typeof listener !== 'function') {
745
- throw new Error('"listener" is invalid.');
746
- }
747
- const snapshot = UnitScope.snapshot();
748
- const types = type.trim().split(/\s+/);
749
- types.forEach((type) => {
750
- if (!UnitEvent.sublisteners.has(unit, type, listener)) {
751
- const execute = (...args) => {
752
- UnitScope.execute(snapshot, listener, ...args);
753
- };
754
- UnitEvent.sublisteners.set(unit, type, listener, [target, execute]);
581
+ type.trim().split(/\s+/).forEach((type) => {
582
+ if (unit._.sublisteners.has(type, listener) === false) {
583
+ const execute = Unit.wrap(listener);
584
+ unit._.sublisteners.set(type, listener, [target, execute]);
755
585
  target.addEventListener(type, execute, options);
756
586
  }
757
587
  });
758
588
  }
759
589
  static suboff(unit, target, type, listener) {
760
- if (typeof type === 'string' && type.trim() === '') {
761
- throw new Error('"type" is invalid.');
762
- }
763
- else if (listener !== undefined && typeof listener !== 'function') {
764
- throw new Error('"listener" is invalid.');
765
- }
766
- const types = typeof type === 'string' ? type.trim().split(/\s+/) : [...UnitEvent.sublisteners.keys(unit)];
590
+ const types = typeof type === 'string' ? type.trim().split(/\s+/) : [...unit._.sublisteners.keys()];
767
591
  types.forEach((type) => {
768
- const listeners = listener ? [listener] : [...UnitEvent.sublisteners.keys(unit, type)];
769
- listeners.forEach((lis) => {
770
- const tuple = UnitEvent.sublisteners.get(unit, type, lis);
592
+ (listener ? [listener] : [...unit._.sublisteners.keys(type)]).forEach((lis) => {
593
+ const tuple = unit._.sublisteners.get(type, lis);
771
594
  if (tuple !== undefined) {
772
595
  const [element, execute] = tuple;
773
596
  if (target === null || target === element) {
774
- UnitEvent.sublisteners.delete(unit, type, lis);
597
+ unit._.sublisteners.delete(type, lis);
775
598
  element.removeEventListener(type, execute);
776
599
  }
777
600
  }
@@ -779,9 +602,17 @@
779
602
  });
780
603
  }
781
604
  }
782
- UnitEvent.units = new MapSet;
783
- UnitEvent.listeners = new MapMapMap;
784
- UnitEvent.sublisteners = new MapMapMap;
605
+ Unit.roots = [];
606
+ Unit.current = null;
607
+ //----------------------------------------------------------------------------------------------------
608
+ // component
609
+ //----------------------------------------------------------------------------------------------------
610
+ Unit.componentUnits = new MapSet();
611
+ //----------------------------------------------------------------------------------------------------
612
+ // event
613
+ //----------------------------------------------------------------------------------------------------
614
+ Unit.typeUnits = new MapSet();
615
+ Unit.reset();
785
616
  //----------------------------------------------------------------------------------------------------
786
617
  // unit promise
787
618
  //----------------------------------------------------------------------------------------------------
@@ -790,18 +621,15 @@
790
621
  this.promise = new Promise(executor);
791
622
  }
792
623
  then(callback) {
793
- const snapshot = UnitScope.snapshot();
794
- this.promise = this.promise.then((...args) => UnitScope.execute(snapshot, callback, ...args));
624
+ this.promise = this.promise.then(Unit.wrap(callback));
795
625
  return this;
796
626
  }
797
627
  catch(callback) {
798
- const snapshot = UnitScope.snapshot();
799
- this.promise = this.promise.catch((...args) => UnitScope.execute(snapshot, callback, ...args));
628
+ this.promise = this.promise.catch(Unit.wrap(callback));
800
629
  return this;
801
630
  }
802
631
  finally(callback) {
803
- const snapshot = UnitScope.snapshot();
804
- this.promise = this.promise.finally((...args) => UnitScope.execute(snapshot, callback, ...args));
632
+ this.promise = this.promise.finally(Unit.wrap(callback));
805
633
  return this;
806
634
  }
807
635
  static get(unit) {
@@ -812,20 +640,14 @@
812
640
  UnitPromise.promises.delete(unit);
813
641
  }
814
642
  static execute(unit, promise) {
643
+ const inner = promise !== null && promise !== void 0 ? promise : UnitPromise.get(unit);
644
+ const unitPromise = new UnitPromise((resolve, reject) => {
645
+ inner.then((...args) => resolve(...args)).catch((...args) => reject(...args));
646
+ });
815
647
  if (promise !== undefined) {
816
- const upromise = new UnitPromise((resolve, reject) => {
817
- promise.then((...args) => resolve(...args)).catch((...args) => reject(...args));
818
- });
819
- UnitPromise.promises.add(unit, upromise);
820
- return upromise;
821
- }
822
- else {
823
- const promiseall = UnitPromise.get(unit);
824
- const upromise = new UnitPromise((resolve, reject) => {
825
- promiseall.then((...args) => resolve(...args)).catch((...args) => reject(...args));
826
- });
827
- return upromise;
648
+ UnitPromise.promises.add(unit, unitPromise);
828
649
  }
650
+ return unitPromise;
829
651
  }
830
652
  }
831
653
  UnitPromise.promises = new MapSet();
@@ -838,8 +660,7 @@
838
660
  }
839
661
  else if (typeof args[0] === 'string') {
840
662
  const str = args.shift(); // a selector for an existing html element
841
- const match = str.match(/<([^>]*)\/?>/);
842
- if (match) {
663
+ if (str.match(/<([^>]*)\/?>/)) {
843
664
  target = str;
844
665
  }
845
666
  else {
@@ -856,7 +677,7 @@
856
677
  return unit;
857
678
  };
858
679
  fn.nest = (tag) => {
859
- const current = UnitScope.current;
680
+ const current = Unit.current;
860
681
  if ((current === null || current === void 0 ? void 0 : current._.state) === 'invoked') {
861
682
  const element = Unit.nest(current, tag);
862
683
  if (element instanceof HTMLElement || element instanceof SVGElement) {
@@ -871,7 +692,7 @@
871
692
  }
872
693
  };
873
694
  fn.extend = (component, props) => {
874
- const current = UnitScope.current;
695
+ const current = Unit.current;
875
696
  if ((current === null || current === void 0 ? void 0 : current._.state) === 'invoked') {
876
697
  return Unit.extend(current, component, props);
877
698
  }
@@ -881,16 +702,16 @@
881
702
  };
882
703
  fn.context = (key, value = undefined) => {
883
704
  try {
884
- const unit = UnitScope.current;
705
+ const unit = Unit.current;
885
706
  if (typeof key !== 'string') {
886
707
  throw new Error('The argument [key] is invalid.');
887
708
  }
888
709
  else if (unit !== null) {
889
710
  if (value !== undefined) {
890
- UnitScope.stack(unit, key, value);
711
+ Unit.stack(unit, key, value);
891
712
  }
892
713
  else {
893
- return UnitScope.trace(unit, key);
714
+ return Unit.trace(unit, key);
894
715
  }
895
716
  }
896
717
  else {
@@ -903,8 +724,8 @@
903
724
  };
904
725
  fn.promise = (promise) => {
905
726
  try {
906
- if (UnitScope.current !== null) {
907
- return UnitPromise.execute(UnitScope.current, promise);
727
+ if (Unit.current !== null) {
728
+ return UnitPromise.execute(Unit.current, promise);
908
729
  }
909
730
  else {
910
731
  throw new Error('No current unit.');
@@ -917,8 +738,8 @@
917
738
  };
918
739
  fn.then = (callback) => {
919
740
  try {
920
- if (UnitScope.current !== null) {
921
- return UnitPromise.execute(UnitScope.current).then(callback);
741
+ if (Unit.current !== null) {
742
+ return UnitPromise.execute(Unit.current).then(callback);
922
743
  }
923
744
  else {
924
745
  throw new Error('No current unit.');
@@ -931,8 +752,8 @@
931
752
  };
932
753
  fn.catch = (callback) => {
933
754
  try {
934
- if (UnitScope.current !== null) {
935
- return UnitPromise.execute(UnitScope.current).catch(callback);
755
+ if (Unit.current !== null) {
756
+ return UnitPromise.execute(Unit.current).catch(callback);
936
757
  }
937
758
  else {
938
759
  throw new Error('No current unit.');
@@ -945,8 +766,8 @@
945
766
  };
946
767
  fn.finally = (callback) => {
947
768
  try {
948
- if (UnitScope.current !== null) {
949
- return UnitPromise.execute(UnitScope.current).finally(callback);
769
+ if (Unit.current !== null) {
770
+ return UnitPromise.execute(Unit.current).finally(callback);
950
771
  }
951
772
  else {
952
773
  throw new Error('No current unit.');
@@ -960,8 +781,8 @@
960
781
  fn.fetch = (url, options) => {
961
782
  try {
962
783
  const promise = fetch(url, options);
963
- if (UnitScope.current !== null) {
964
- return UnitPromise.execute(UnitScope.current, promise);
784
+ if (Unit.current !== null) {
785
+ return UnitPromise.execute(Unit.current, promise);
965
786
  }
966
787
  else {
967
788
  throw new Error('No current unit.');
@@ -973,12 +794,14 @@
973
794
  }
974
795
  };
975
796
  fn.scope = (callback) => {
976
- const snapshot = UnitScope.snapshot();
977
- return (...args) => UnitScope.execute(snapshot, callback, ...args);
797
+ if (Unit.current !== null) {
798
+ const snapshot = Unit.snapshot(Unit.current);
799
+ return (...args) => Unit.scope(snapshot, callback, ...args);
800
+ }
978
801
  };
979
802
  fn.find = (component) => {
980
803
  if (typeof component === 'function') {
981
- return UnitComponent.find(component);
804
+ return Unit.find(component);
982
805
  }
983
806
  else {
984
807
  throw new Error(`The argument [component] is invalid.`);
@@ -986,22 +809,22 @@
986
809
  };
987
810
  fn.append = (base, ...args) => {
988
811
  if (typeof base === 'function') {
989
- for (let unit of UnitComponent.find(base)) {
990
- UnitScope.execute(UnitScope.snapshot(unit), xnew$1, ...args);
812
+ for (let unit of Unit.find(base)) {
813
+ Unit.scope(Unit.snapshot(unit), xnew$1, ...args);
991
814
  }
992
815
  }
993
816
  else if (base instanceof Unit) {
994
- UnitScope.execute(UnitScope.snapshot(base), xnew$1, ...args);
817
+ Unit.scope(Unit.snapshot(base), xnew$1, ...args);
995
818
  }
996
819
  else {
997
820
  throw new Error(`The argument [component] is invalid.`);
998
821
  }
999
822
  };
1000
823
  fn.timeout = (callback, delay) => {
1001
- const snapshot = UnitScope.snapshot();
824
+ const snapshot = Unit.snapshot(Unit.current);
1002
825
  const unit = xnew$1((self) => {
1003
826
  const timer = new Timer(() => {
1004
- UnitScope.execute(snapshot, callback);
827
+ Unit.scope(snapshot, callback);
1005
828
  self.finalize();
1006
829
  }, null, delay);
1007
830
  self.on('finalize', () => {
@@ -1011,10 +834,10 @@
1011
834
  return { clear: () => unit.finalize() };
1012
835
  };
1013
836
  fn.interval = (callback, delay) => {
1014
- const snapshot = UnitScope.snapshot();
837
+ const snapshot = Unit.snapshot(Unit.current);
1015
838
  const unit = xnew$1((self) => {
1016
839
  const timer = new Timer(() => {
1017
- UnitScope.execute(snapshot, callback);
840
+ Unit.scope(snapshot, callback);
1018
841
  }, null, delay, true);
1019
842
  self.on('finalize', () => {
1020
843
  timer.clear();
@@ -1023,13 +846,13 @@
1023
846
  return { clear: () => unit.finalize() };
1024
847
  };
1025
848
  fn.transition = (callback, interval, easing = 'linear') => {
1026
- const snapshot = UnitScope.snapshot();
849
+ const snapshot = Unit.snapshot(Unit.current);
1027
850
  let stacks = [];
1028
851
  let unit = xnew$1(Local, { callback, interval, easing });
1029
852
  let isRunning = true;
1030
853
  function Local(self, { callback, interval, easing }) {
1031
854
  const timer = new Timer(() => {
1032
- UnitScope.execute(snapshot, callback, 1.0);
855
+ Unit.scope(snapshot, callback, 1.0);
1033
856
  self.finalize();
1034
857
  }, (progress) => {
1035
858
  if (progress < 1.0) {
@@ -1045,7 +868,7 @@
1045
868
  else if (easing === 'ease-in-out') {
1046
869
  progress = (1.0 - Math.cos(progress * Math.PI)) / 2.0;
1047
870
  }
1048
- UnitScope.execute(snapshot, callback, progress);
871
+ Unit.scope(snapshot, callback, progress);
1049
872
  }
1050
873
  }, interval);
1051
874
  self.on('finalize', () => {
@@ -1077,38 +900,21 @@
1077
900
  fn.listener = function (target) {
1078
901
  return {
1079
902
  on(type, listener, options) {
1080
- UnitEvent.subon(UnitScope.current, target, type, listener, options);
903
+ Unit.subon(Unit.current, target, type, listener, options);
1081
904
  },
1082
905
  off(type, listener) {
1083
- UnitEvent.suboff(UnitScope.current, target, type, listener);
906
+ Unit.suboff(Unit.current, target, type, listener);
1084
907
  }
1085
908
  };
1086
909
  };
1087
910
  fn.capture = function (checker, execute) {
1088
- const current = UnitScope.current;
1089
- const snapshot = UnitScope.snapshot();
1090
- current._.captures.push({ checker, execute: (unit) => UnitScope.execute(snapshot, execute, unit) });
911
+ const current = Unit.current;
912
+ const snapshot = Unit.snapshot(Unit.current);
913
+ current._.captures.push({ checker, execute: (unit) => Unit.scope(snapshot, execute, unit) });
1091
914
  };
1092
915
  return fn;
1093
916
  })();
1094
917
 
1095
- function ResizeEvent(self) {
1096
- const observer = new ResizeObserver(xnew$1.scope((entries) => {
1097
- for (const entry of entries) {
1098
- self.emit('-resize');
1099
- break;
1100
- }
1101
- }));
1102
- if (self.element) {
1103
- observer.observe(self.element);
1104
- }
1105
- self.on('finalize', () => {
1106
- if (self.element) {
1107
- observer.unobserve(self.element);
1108
- }
1109
- });
1110
- }
1111
-
1112
918
  function UserEvent(self) {
1113
919
  const unit = xnew$1();
1114
920
  unit.on('pointerdown', (event) => self.emit('-pointerdown', { event, position: getPosition(self.element, event) }));
@@ -1319,18 +1125,13 @@
1319
1125
 
1320
1126
  function ModalFrame(frame, {} = {}) {
1321
1127
  xnew$1.context('xnew.modalframe', frame);
1322
- xnew$1.nest('<div style="position: fixed; inset: 0;">');
1323
- let content = null;
1324
- xnew$1.capture((unit) => unit.components.includes(ModalContent), (unit) => {
1325
- content = unit;
1326
- });
1327
- xnew$1().on('click', (event) => {
1328
- frame === null || frame === void 0 ? void 0 : frame.close();
1128
+ xnew$1.nest('<div style="position: fixed; inset: 0; z-index: 1000;">');
1129
+ xnew$1.capture((unit) => unit.components.has(ModalContent), (unit) => {
1329
1130
  });
1131
+ xnew$1().on('click', (event) => frame === null || frame === void 0 ? void 0 : frame.close());
1330
1132
  return {
1331
1133
  close() {
1332
1134
  frame.emit('-close');
1333
- content === null || content === void 0 ? void 0 : content.deselect();
1334
1135
  }
1335
1136
  };
1336
1137
  }
@@ -1339,40 +1140,28 @@
1339
1140
  const div = xnew$1.nest('<div style="width: 100%; height: 100%; opacity: 0;">');
1340
1141
  div.style.background = background;
1341
1142
  xnew$1.nest('<div style="position: absolute; inset: 0; margin: auto; width: max-content; height: max-content;">');
1342
- xnew$1().on('click', (event) => {
1343
- event.stopPropagation();
1344
- });
1345
- let status = 0;
1143
+ xnew$1().on('click', (event) => event.stopPropagation());
1346
1144
  xnew$1.timeout(() => frame.emit('-open'));
1347
1145
  frame.on('-open', () => {
1348
1146
  xnew$1.transition((x) => {
1349
- status = x;
1350
- frame.emit('-transition', { status });
1351
- content.transition(status);
1147
+ div.style.opacity = x.toString();
1352
1148
  }, duration, easing);
1353
1149
  });
1354
1150
  frame.on('-close', () => {
1355
1151
  xnew$1.transition((x) => {
1356
- status = 1.0 - x;
1357
- frame.emit('-transition', { status });
1358
- content.transition(status);
1152
+ div.style.opacity = (1.0 - x).toString();
1359
1153
  }, duration, easing).next(() => frame.finalize());
1360
1154
  });
1361
- return {
1362
- transition(status) {
1363
- div.style.opacity = status.toString();
1364
- }
1365
- };
1366
1155
  }
1367
1156
 
1368
1157
  function TabFrame(frame, { select = 0 } = {}) {
1369
1158
  xnew$1.context('xnew.tabframe', frame);
1370
1159
  const buttons = [];
1371
1160
  const contents = [];
1372
- xnew$1.capture((unit) => unit.components.includes(TabButton), (unit) => {
1161
+ xnew$1.capture((unit) => unit.components.has(TabButton), (unit) => {
1373
1162
  buttons.push(unit);
1374
1163
  });
1375
- xnew$1.capture((unit) => unit.components.includes(TabContent), (unit) => {
1164
+ xnew$1.capture((unit) => unit.components.has(TabContent), (unit) => {
1376
1165
  contents.push(unit);
1377
1166
  });
1378
1167
  frame.on('-click', ({ unit }) => execute(buttons.indexOf(unit)));
@@ -1416,7 +1205,7 @@
1416
1205
  function AccordionFrame(frame, {} = {}) {
1417
1206
  xnew$1.context('xnew.accordionframe', frame);
1418
1207
  let content = null;
1419
- xnew$1.capture((unit) => unit.components.includes(AccordionContent), (unit) => {
1208
+ xnew$1.capture((unit) => unit.components.has(AccordionContent), (unit) => {
1420
1209
  content = unit;
1421
1210
  });
1422
1211
  return {
@@ -1440,10 +1229,10 @@
1440
1229
  }
1441
1230
  };
1442
1231
  }
1443
- function AccordionButton(button, {} = {}) {
1232
+ function AccordionHeader(header, {} = {}) {
1444
1233
  const frame = xnew$1.context('xnew.accordionframe');
1445
1234
  xnew$1.nest('<button style="display: flex; align-items: center; margin: 0; padding: 0; width: 100%; text-align: left; border: none; font: inherit; color: inherit; background: none; cursor: pointer;">');
1446
- button.on('click', () => frame.toggle());
1235
+ header.on('click', () => frame.toggle());
1447
1236
  }
1448
1237
  function AccordionBullet(bullet, { type = 'arrow' } = {}) {
1449
1238
  const frame = xnew$1.context('xnew.accordionframe');
@@ -1508,20 +1297,6 @@
1508
1297
  };
1509
1298
  }
1510
1299
 
1511
- function PanelFrame(frame) {
1512
- xnew$1.context('xnew.panelframe', frame);
1513
- }
1514
- function PanelGroup(group, { name, open = false } = {}) {
1515
- xnew$1.extend(AccordionFrame);
1516
- xnew$1((button) => {
1517
- xnew$1.nest('<div style="margin: 0.2em 0;">');
1518
- xnew$1.extend(AccordionButton);
1519
- xnew$1(AccordionBullet);
1520
- xnew$1('<div>', name);
1521
- });
1522
- xnew$1.extend(AccordionContent, { open });
1523
- }
1524
-
1525
1300
  function DragFrame(frame, { x = 0, y = 0 } = {}) {
1526
1301
  const absolute = xnew$1.nest(`<div style="position: absolute; top: ${y}px; left: ${x}px;">`);
1527
1302
  xnew$1.context('xnew.dragframe', { frame, absolute });
@@ -1554,7 +1329,7 @@
1554
1329
  ${stroke ? `stroke: ${stroke}; stroke-opacity: ${strokeOpacity}; stroke-width: ${strokeWidth}; stroke-linejoin: ${strokeLinejoin};` : ''}
1555
1330
  ">`);
1556
1331
  }
1557
- function VirtualStick(self, { size = 130, fill = '#FFF', fillOpacity = 0.8, stroke = '#000', strokeOpacity = 0.8, strokeWidth = 2, strokeLinejoin = 'round' } = {}) {
1332
+ function TouchStick(self, { size = 130, fill = '#FFF', fillOpacity = 0.8, stroke = '#000', strokeOpacity = 0.8, strokeWidth = 2, strokeLinejoin = 'round' } = {}) {
1558
1333
  strokeWidth /= (size / 100);
1559
1334
  xnew$1.nest(`<div style="position: relative; width: ${size}px; height: ${size}px; cursor: pointer; user-select: none; overflow: hidden;">`);
1560
1335
  xnew$1((self) => {
@@ -1598,7 +1373,7 @@
1598
1373
  return { x: Math.cos(a) * d, y: Math.sin(a) * d };
1599
1374
  }
1600
1375
  }
1601
- function VirtualDPad(self, { size = 130, fill = '#FFF', fillOpacity = 0.8, stroke = '#000', strokeOpacity = 0.8, strokeWidth = 2, strokeLinejoin = 'round' } = {}) {
1376
+ function TouchDPad(self, { size = 130, fill = '#FFF', fillOpacity = 0.8, stroke = '#000', strokeOpacity = 0.8, strokeWidth = 2, strokeLinejoin = 'round' } = {}) {
1602
1377
  strokeWidth /= (size / 100);
1603
1378
  xnew$1.nest(`<div style="position: relative; width: ${size}px; height: ${size}px; cursor: pointer; user-select: none; overflow: hidden;">`);
1604
1379
  const polygons = [
@@ -1660,7 +1435,7 @@
1660
1435
  return vector;
1661
1436
  }
1662
1437
  }
1663
- function VirtualButton(self, { size = 80, fill = '#FFF', fillOpacity = 0.8, stroke = '#000', strokeOpacity = 0.8, strokeWidth = 2, strokeLinejoin = 'round' } = {}) {
1438
+ function TouchButton(self, { size = 80, fill = '#FFF', fillOpacity = 0.8, stroke = '#000', strokeOpacity = 0.8, strokeWidth = 2, strokeLinejoin = 'round' } = {}) {
1664
1439
  strokeWidth /= (size / 100);
1665
1440
  xnew$1.nest(`<div style="position: relative; width: ${size}px; height: ${size}px; cursor: pointer; user-select: none; overflow: hidden;">`);
1666
1441
  const target = xnew$1((self) => {
@@ -1985,20 +1760,18 @@
1985
1760
  ModalFrame,
1986
1761
  ModalContent,
1987
1762
  AccordionFrame,
1988
- AccordionButton,
1763
+ AccordionHeader,
1989
1764
  AccordionBullet,
1990
1765
  AccordionContent,
1991
1766
  TabFrame,
1992
1767
  TabButton,
1993
1768
  TabContent,
1994
- PanelFrame,
1995
- PanelGroup,
1996
1769
  InputFrame,
1997
1770
  DragFrame,
1998
1771
  DragTarget,
1999
- VirtualStick,
2000
- VirtualDPad,
2001
- VirtualButton,
1772
+ TouchStick,
1773
+ TouchDPad,
1774
+ TouchButton,
2002
1775
  };
2003
1776
  const audio = {
2004
1777
  synthesizer