@mulsense/xnew 0.4.4 → 0.4.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/dist/xnew.d.ts CHANGED
@@ -277,7 +277,7 @@ declare const xnew$1: CreateUnit & {
277
277
  protect(): void;
278
278
  };
279
279
 
280
- declare function AccordionFrame(unit: Unit, { open, duration, easing }?: {
280
+ declare function Accordion(unit: Unit, { open, duration, easing }?: {
281
281
  open?: boolean;
282
282
  duration?: number;
283
283
  easing?: string;
@@ -287,7 +287,6 @@ declare function AccordionFrame(unit: Unit, { open, duration, easing }?: {
287
287
  open(): void;
288
288
  close(): void;
289
289
  };
290
- declare function AccordionContent(unit: Unit, {}?: {}): void;
291
290
 
292
291
  declare function Screen(unit: Unit, { width, height, fit }?: {
293
292
  width?: number | undefined;
@@ -298,24 +297,6 @@ declare function Screen(unit: Unit, { width, height, fit }?: {
298
297
  resize(width: number, height: number): void;
299
298
  };
300
299
 
301
- declare function ModalFrame(unit: Unit, { duration, easing }?: {
302
- duration?: number;
303
- easing?: string;
304
- }): {
305
- close(): void;
306
- };
307
- declare function ModalContent(content: Unit, { background }?: {
308
- background?: string;
309
- }): void;
310
-
311
- declare function DragFrame(unit: Unit, { x, y }?: {
312
- x?: number;
313
- y?: number;
314
- }): {
315
- absolute: HTMLElement | SVGElement;
316
- };
317
- declare function DragTarget(unit: Unit, {}?: {}): void;
318
-
319
300
  declare function AnalogStick(unit: Unit, { stroke, strokeOpacity, strokeWidth, strokeLinejoin, fill, fillOpacity }?: {
320
301
  stroke?: string;
321
302
  strokeOpacity?: number;
@@ -343,13 +324,9 @@ declare function TextStream(unit: Unit, { text, speed, fade }?: {
343
324
 
344
325
  declare const basics: {
345
326
  Screen: typeof Screen;
346
- ModalFrame: typeof ModalFrame;
347
- ModalContent: typeof ModalContent;
348
- AccordionFrame: typeof AccordionFrame;
349
- AccordionContent: typeof AccordionContent;
327
+ Modal: any;
328
+ Accordion: typeof Accordion;
350
329
  TextStream: typeof TextStream;
351
- DragFrame: typeof DragFrame;
352
- DragTarget: typeof DragTarget;
353
330
  AnalogStick: typeof AnalogStick;
354
331
  DirectionalPad: typeof DirectionalPad;
355
332
  };
package/dist/xnew.js CHANGED
@@ -941,9 +941,8 @@
941
941
  }
942
942
 
943
943
  const xnew$1 = Object.assign(function (...args) {
944
- if (Unit.rootUnit === undefined) {
944
+ if (Unit.rootUnit === undefined)
945
945
  Unit.reset();
946
- }
947
946
  return new Unit(Unit.currentUnit, ...args);
948
947
  }, {
949
948
  /**
@@ -1163,8 +1162,8 @@
1163
1162
  }
1164
1163
  });
1165
1164
 
1166
- function AccordionFrame(unit, { open = false, duration = 200, easing = 'ease' } = {}) {
1167
- xnew$1.context('xnew.accordionframe', unit);
1165
+ function Accordion(unit, { open = false, duration = 200, easing = 'ease' } = {}) {
1166
+ xnew$1.context('xnew.accordion', unit);
1168
1167
  unit.on('-transition', ({ state }) => {
1169
1168
  unit.state = state;
1170
1169
  });
@@ -1193,23 +1192,6 @@
1193
1192
  }
1194
1193
  };
1195
1194
  }
1196
- function AccordionContent(unit, {} = {}) {
1197
- const frame = xnew$1.context('xnew.accordionframe');
1198
- const outer = xnew$1.nest(`<div style="display: ${frame.state === 1.9 ? 'block' : 'none'};">`);
1199
- const inner = xnew$1.nest('<div style="padding: 0; display: flex; flex-direction: column; box-sizing: border-box;">');
1200
- frame.on('-transition', ({ state }) => {
1201
- outer.style.display = 'block';
1202
- if (state === 0.0) {
1203
- outer.style.display = 'none';
1204
- }
1205
- else if (state < 1.0) {
1206
- Object.assign(outer.style, { height: inner.offsetHeight * state + 'px', overflow: 'hidden', opacity: state });
1207
- }
1208
- else {
1209
- Object.assign(outer.style, { height: 'auto', overflow: 'visible', opacity: 1.0 });
1210
- }
1211
- });
1212
- }
1213
1195
 
1214
1196
  function Screen(unit, { width = 640, height = 480, fit = 'contain' } = {}) {
1215
1197
  const size = { width, height };
@@ -1258,7 +1240,7 @@
1258
1240
  };
1259
1241
  }
1260
1242
 
1261
- function ModalFrame(unit, { duration = 200, easing = 'ease' } = {}) {
1243
+ function Modal(unit, { duration = 200, easing = 'ease' } = {}) {
1262
1244
  xnew$1.context('xnew.modalframe', unit);
1263
1245
  xnew$1.nest('<div style="position: fixed; inset: 0; z-index: 1000;">');
1264
1246
  unit.on('click', ({ event }) => unit.close());
@@ -1266,57 +1248,13 @@
1266
1248
  xnew$1.emit('-transition', { state: x });
1267
1249
  }, duration, easing);
1268
1250
  return {
1251
+ state: 0.0,
1269
1252
  close() {
1270
1253
  xnew$1.transition((x) => xnew$1.emit('-transition', { state: 1.0 - x }), duration, easing)
1271
1254
  .timeout(() => unit.finalize());
1272
1255
  }
1273
1256
  };
1274
1257
  }
1275
- function ModalContent(content, { background = 'rgba(0, 0, 0, 0.1)' } = {}) {
1276
- const frame = xnew$1.context('xnew.modalframe');
1277
- const outer = xnew$1.nest(`<div style="width: 100%; height: 100%; opacity: 0; background: ${background}">`);
1278
- xnew$1.nest('<div style="position: absolute; inset: 0; margin: auto; width: max-content; height: max-content;">');
1279
- frame.on('click', ({ event }) => event.stopPropagation());
1280
- frame.on('-transition', ({ state }) => {
1281
- outer.style.opacity = state.toString();
1282
- });
1283
- }
1284
-
1285
- function DragFrame(unit, { x = 0, y = 0 } = {}) {
1286
- const absolute = xnew$1.nest(`<div style="position: absolute; top: ${y}px; left: ${x}px;">`);
1287
- xnew$1.context('xnew.dragframe', unit);
1288
- return {
1289
- absolute,
1290
- };
1291
- }
1292
- function DragTarget(unit, {} = {}) {
1293
- const frame = xnew$1.context('xnew.dragframe');
1294
- const current = { x: 0, y: 0 };
1295
- const offset = { x: 0, y: 0 };
1296
- let dragged = false;
1297
- const target = xnew$1(frame.absolute.parentElement);
1298
- target.on('dragstart', ({ event, position }) => {
1299
- if (unit.element.contains(event.target) === false)
1300
- return;
1301
- dragged = true;
1302
- offset.x = position.x - parseFloat(frame.absolute.style.left || '0');
1303
- offset.y = position.y - parseFloat(frame.absolute.style.top || '0');
1304
- current.x = position.x - offset.x;
1305
- current.y = position.y - offset.y;
1306
- });
1307
- target.on('dragmove', ({ event, delta }) => {
1308
- if (dragged !== true)
1309
- return;
1310
- current.x += delta.x;
1311
- current.y += delta.y;
1312
- frame.absolute.style.left = `${current.x}px`;
1313
- frame.absolute.style.top = `${current.y}px`;
1314
- });
1315
- target.on('dragend', ({ event }) => {
1316
- dragged = false;
1317
- });
1318
- xnew$1.nest('<div>');
1319
- }
1320
1258
 
1321
1259
  //----------------------------------------------------------------------------------------------------
1322
1260
  // controller
@@ -1331,139 +1269,109 @@
1331
1269
  }
1332
1270
  function AnalogStick(unit, { stroke = 'currentColor', strokeOpacity = 0.8, strokeWidth = 2, strokeLinejoin = 'round', fill = '#FFF', fillOpacity = 0.8 } = {}) {
1333
1271
  const outer = xnew$1.nest(`<div style="position: relative; width: 100%; height: 100%;">`);
1334
- const internal = xnew$1((unit) => {
1335
- let newsize = Math.min(outer.clientWidth, outer.clientHeight);
1336
- const inner = xnew$1.nest(`<div style="position: absolute; width: ${newsize}px; height: ${newsize}px; margin: auto; inset: 0; cursor: pointer; pointer-select: none; pointer-events: auto; overflow: hidden;">`);
1337
- xnew$1(outer).on('resize', () => {
1338
- newsize = Math.min(outer.clientWidth, outer.clientHeight);
1339
- inner.style.width = `${newsize}px`;
1340
- inner.style.height = `${newsize}px`;
1341
- });
1342
- xnew$1((unit) => {
1343
- xnew$1.extend(SVGTemplate, { fill, fillOpacity, stroke, strokeOpacity, strokeWidth, strokeLinejoin });
1344
- xnew$1('<polygon points="50 7 40 18 60 18">');
1345
- xnew$1('<polygon points="50 93 40 83 60 83">');
1346
- xnew$1('<polygon points=" 7 50 18 40 18 60">');
1347
- xnew$1('<polygon points="93 50 83 40 83 60">');
1348
- });
1349
- const target = xnew$1((unit) => {
1350
- xnew$1.extend(SVGTemplate, { fill, fillOpacity, stroke, strokeOpacity, strokeWidth, strokeLinejoin });
1351
- xnew$1('<circle cx="50" cy="50" r="23">');
1352
- });
1353
- unit.on('dragstart', ({ event, position }) => {
1354
- const vector = getVector(position);
1355
- target.element.style.filter = 'brightness(90%)';
1356
- target.element.style.left = vector.x * newsize / 4 + 'px';
1357
- target.element.style.top = vector.y * newsize / 4 + 'px';
1358
- xnew$1.emit('-down', { vector });
1359
- });
1360
- unit.on('dragmove', ({ event, position }) => {
1361
- const vector = getVector(position);
1362
- target.element.style.filter = 'brightness(90%)';
1363
- target.element.style.left = vector.x * newsize / 4 + 'px';
1364
- target.element.style.top = vector.y * newsize / 4 + 'px';
1365
- xnew$1.emit('-move', { vector });
1366
- });
1367
- unit.on('dragend', ({ event }) => {
1368
- const vector = { x: 0, y: 0 };
1369
- target.element.style.filter = '';
1370
- target.element.style.left = vector.x * newsize / 4 + 'px';
1371
- target.element.style.top = vector.y * newsize / 4 + 'px';
1372
- xnew$1.emit('-up', { vector });
1373
- });
1374
- function getVector(position) {
1375
- const x = position.x - newsize / 2;
1376
- const y = position.y - newsize / 2;
1377
- const d = Math.min(1.0, Math.sqrt(x * x + y * y) / (newsize / 4));
1378
- const a = (y !== 0 || x !== 0) ? Math.atan2(y, x) : 0;
1379
- return { x: Math.cos(a) * d, y: Math.sin(a) * d };
1380
- }
1272
+ let newsize = Math.min(outer.clientWidth, outer.clientHeight);
1273
+ const inner = xnew$1.nest(`<div style="position: absolute; width: ${newsize}px; height: ${newsize}px; margin: auto; inset: 0; cursor: pointer; pointer-select: none; pointer-events: auto; overflow: hidden;">`);
1274
+ xnew$1(outer).on('resize', () => {
1275
+ newsize = Math.min(outer.clientWidth, outer.clientHeight);
1276
+ inner.style.width = `${newsize}px`;
1277
+ inner.style.height = `${newsize}px`;
1278
+ });
1279
+ xnew$1((unit) => {
1280
+ xnew$1.extend(SVGTemplate, { fill, fillOpacity, stroke, strokeOpacity, strokeWidth, strokeLinejoin });
1281
+ xnew$1('<polygon points="50 7 40 18 60 18">');
1282
+ xnew$1('<polygon points="50 93 40 83 60 83">');
1283
+ xnew$1('<polygon points=" 7 50 18 40 18 60">');
1284
+ xnew$1('<polygon points="93 50 83 40 83 60">');
1285
+ });
1286
+ const target = xnew$1((unit) => {
1287
+ xnew$1.extend(SVGTemplate, { fill, fillOpacity, stroke, strokeOpacity, strokeWidth, strokeLinejoin });
1288
+ xnew$1('<circle cx="50" cy="50" r="23">');
1289
+ });
1290
+ unit.on('dragstart dragmove', ({ type, position }) => {
1291
+ const x = position.x - newsize / 2;
1292
+ const y = position.y - newsize / 2;
1293
+ const d = Math.min(1.0, Math.sqrt(x * x + y * y) / (newsize / 4));
1294
+ const a = (y !== 0 || x !== 0) ? Math.atan2(y, x) : 0;
1295
+ const vector = { x: Math.cos(a) * d, y: Math.sin(a) * d };
1296
+ target.element.style.filter = 'brightness(90%)';
1297
+ target.element.style.left = `${vector.x * newsize / 4}px`;
1298
+ target.element.style.top = `${vector.y * newsize / 4}px`;
1299
+ const nexttype = { dragstart: '-down', dragmove: '-move' }[type];
1300
+ xnew$1.emit(nexttype, { type: nexttype, vector });
1301
+ });
1302
+ unit.on('dragend', () => {
1303
+ const vector = { x: 0, y: 0 };
1304
+ target.element.style.filter = '';
1305
+ target.element.style.left = `${vector.x * newsize / 4}px`;
1306
+ target.element.style.top = `${vector.y * newsize / 4}px`;
1307
+ xnew$1.emit('-up', { type: '-up', vector });
1381
1308
  });
1382
- internal.on('-down', (...args) => xnew$1.emit('-down', ...args));
1383
- internal.on('-move', (...args) => xnew$1.emit('-move', ...args));
1384
- internal.on('-up', (...args) => xnew$1.emit('-up', ...args));
1385
1309
  }
1386
1310
  function DirectionalPad(unit, { diagonal = true, stroke = 'currentColor', strokeOpacity = 0.8, strokeWidth = 2, strokeLinejoin = 'round', fill = '#FFF', fillOpacity = 0.8 } = {}) {
1387
1311
  const outer = xnew$1.nest(`<div style="position: relative; width: 100%; height: 100%;">`);
1388
- const internal = xnew$1((unit) => {
1389
- let newsize = Math.min(outer.clientWidth, outer.clientHeight);
1390
- const inner = xnew$1.nest(`<div style="position: absolute; width: ${newsize}px; height: ${newsize}px; margin: auto; inset: 0; cursor: pointer; pointer-select: none; pointer-events: auto; overflow: hidden;">`);
1391
- xnew$1(outer).on('resize', () => {
1392
- newsize = Math.min(outer.clientWidth, outer.clientHeight);
1393
- inner.style.width = `${newsize}px`;
1394
- inner.style.height = `${newsize}px`;
1395
- });
1396
- const polygons = [
1397
- '<polygon points="50 50 35 35 35 5 37 3 63 3 65 5 65 35">',
1398
- '<polygon points="50 50 35 65 35 95 37 97 63 97 65 95 65 65">',
1399
- '<polygon points="50 50 35 35 5 35 3 37 3 63 5 65 35 65">',
1400
- '<polygon points="50 50 65 35 95 35 97 37 97 63 95 65 65 65">'
1401
- ];
1402
- const targets = polygons.map((polygon) => {
1403
- return xnew$1((unit) => {
1404
- xnew$1.extend(SVGTemplate, { stroke: 'none', fill, fillOpacity });
1405
- xnew$1(polygon);
1406
- });
1407
- });
1408
- xnew$1((unit) => {
1409
- xnew$1.extend(SVGTemplate, { fill: 'none', stroke, strokeOpacity, strokeWidth, strokeLinejoin });
1410
- xnew$1('<polyline points="35 35 35 5 37 3 63 3 65 5 65 35">');
1411
- xnew$1('<polyline points="35 65 35 95 37 97 63 97 65 95 65 65">');
1412
- xnew$1('<polyline points="35 35 5 35 3 37 3 63 5 65 35 65">');
1413
- xnew$1('<polyline points="65 35 95 35 97 37 97 63 95 65 65 65">');
1414
- xnew$1('<polygon points="50 11 42 20 58 20">');
1415
- xnew$1('<polygon points="50 89 42 80 58 80">');
1416
- xnew$1('<polygon points="11 50 20 42 20 58">');
1417
- xnew$1('<polygon points="89 50 80 42 80 58">');
1418
- });
1419
- unit.on('dragstart', ({ event, position }) => {
1420
- const vector = getVector(position);
1421
- targets[0].element.style.filter = (vector.y < 0) ? 'brightness(90%)' : '';
1422
- targets[1].element.style.filter = (vector.y > 0) ? 'brightness(90%)' : '';
1423
- targets[2].element.style.filter = (vector.x < 0) ? 'brightness(90%)' : '';
1424
- targets[3].element.style.filter = (vector.x > 0) ? 'brightness(90%)' : '';
1425
- xnew$1.emit('-down', { vector });
1426
- });
1427
- unit.on('dragmove', ({ event, position }) => {
1428
- const vector = getVector(position);
1429
- targets[0].element.style.filter = (vector.y < 0) ? 'brightness(90%)' : '';
1430
- targets[1].element.style.filter = (vector.y > 0) ? 'brightness(90%)' : '';
1431
- targets[2].element.style.filter = (vector.x < 0) ? 'brightness(90%)' : '';
1432
- targets[3].element.style.filter = (vector.x > 0) ? 'brightness(90%)' : '';
1433
- xnew$1.emit('-move', { vector });
1434
- });
1435
- unit.on('dragend', ({ event }) => {
1436
- const vector = { x: 0, y: 0 };
1437
- targets[0].element.style.filter = '';
1438
- targets[1].element.style.filter = '';
1439
- targets[2].element.style.filter = '';
1440
- targets[3].element.style.filter = '';
1441
- xnew$1.emit('-up', { vector });
1312
+ let newsize = Math.min(outer.clientWidth, outer.clientHeight);
1313
+ const inner = xnew$1.nest(`<div style="position: absolute; width: ${newsize}px; height: ${newsize}px; margin: auto; inset: 0; cursor: pointer; pointer-select: none; pointer-events: auto; overflow: hidden;">`);
1314
+ xnew$1(outer).on('resize', () => {
1315
+ newsize = Math.min(outer.clientWidth, outer.clientHeight);
1316
+ inner.style.width = `${newsize}px`;
1317
+ inner.style.height = `${newsize}px`;
1318
+ });
1319
+ const polygons = [
1320
+ '<polygon points="50 50 35 35 35 5 37 3 63 3 65 5 65 35">',
1321
+ '<polygon points="50 50 35 65 35 95 37 97 63 97 65 95 65 65">',
1322
+ '<polygon points="50 50 35 35 5 35 3 37 3 63 5 65 35 65">',
1323
+ '<polygon points="50 50 65 35 95 35 97 37 97 63 95 65 65 65">'
1324
+ ];
1325
+ const targets = polygons.map((polygon) => {
1326
+ return xnew$1((unit) => {
1327
+ xnew$1.extend(SVGTemplate, { stroke: 'none', fill, fillOpacity });
1328
+ xnew$1(polygon);
1442
1329
  });
1443
- function getVector(position) {
1444
- const x = position.x - newsize / 2;
1445
- const y = position.y - newsize / 2;
1446
- const a = (y !== 0 || x !== 0) ? Math.atan2(y, x) : 0;
1447
- const d = Math.min(1.0, Math.sqrt(x * x + y * y) / (newsize / 4));
1448
- const vector = { x: Math.cos(a) * d, y: Math.sin(a) * d };
1449
- if (diagonal === true) {
1450
- vector.x = Math.abs(vector.x) > 0.5 ? Math.sign(vector.x) : 0;
1451
- vector.y = Math.abs(vector.y) > 0.5 ? Math.sign(vector.y) : 0;
1452
- }
1453
- else if (Math.abs(vector.x) > Math.abs(vector.y)) {
1454
- vector.x = Math.abs(vector.x) > 0.5 ? Math.sign(vector.x) : 0;
1455
- vector.y = 0;
1456
- }
1457
- else {
1458
- vector.x = 0;
1459
- vector.y = Math.abs(vector.y) > 0.5 ? Math.sign(vector.y) : 0;
1460
- }
1461
- return vector;
1330
+ });
1331
+ xnew$1((unit) => {
1332
+ xnew$1.extend(SVGTemplate, { fill: 'none', stroke, strokeOpacity, strokeWidth, strokeLinejoin });
1333
+ xnew$1('<polyline points="35 35 35 5 37 3 63 3 65 5 65 35">');
1334
+ xnew$1('<polyline points="35 65 35 95 37 97 63 97 65 95 65 65">');
1335
+ xnew$1('<polyline points="35 35 5 35 3 37 3 63 5 65 35 65">');
1336
+ xnew$1('<polyline points="65 35 95 35 97 37 97 63 95 65 65 65">');
1337
+ xnew$1('<polygon points="50 11 42 20 58 20">');
1338
+ xnew$1('<polygon points="50 89 42 80 58 80">');
1339
+ xnew$1('<polygon points="11 50 20 42 20 58">');
1340
+ xnew$1('<polygon points="89 50 80 42 80 58">');
1341
+ });
1342
+ unit.on('dragstart dragmove', ({ type, position }) => {
1343
+ const x = position.x - newsize / 2;
1344
+ const y = position.y - newsize / 2;
1345
+ const a = (y !== 0 || x !== 0) ? Math.atan2(y, x) : 0;
1346
+ const d = Math.min(1.0, Math.sqrt(x * x + y * y) / (newsize / 4));
1347
+ const vector = { x: Math.cos(a) * d, y: Math.sin(a) * d };
1348
+ if (diagonal === true) {
1349
+ vector.x = Math.abs(vector.x) > 0.5 ? Math.sign(vector.x) : 0;
1350
+ vector.y = Math.abs(vector.y) > 0.5 ? Math.sign(vector.y) : 0;
1351
+ }
1352
+ else if (Math.abs(vector.x) > Math.abs(vector.y)) {
1353
+ vector.x = Math.abs(vector.x) > 0.5 ? Math.sign(vector.x) : 0;
1354
+ vector.y = 0;
1462
1355
  }
1356
+ else {
1357
+ vector.x = 0;
1358
+ vector.y = Math.abs(vector.y) > 0.5 ? Math.sign(vector.y) : 0;
1359
+ }
1360
+ targets[0].element.style.filter = (vector.y < 0) ? 'brightness(90%)' : '';
1361
+ targets[1].element.style.filter = (vector.y > 0) ? 'brightness(90%)' : '';
1362
+ targets[2].element.style.filter = (vector.x < 0) ? 'brightness(90%)' : '';
1363
+ targets[3].element.style.filter = (vector.x > 0) ? 'brightness(90%)' : '';
1364
+ const nexttype = { dragstart: '-down', dragmove: '-move' }[type];
1365
+ xnew$1.emit(nexttype, { type: nexttype, vector });
1366
+ });
1367
+ unit.on('dragend', () => {
1368
+ const vector = { x: 0, y: 0 };
1369
+ targets[0].element.style.filter = '';
1370
+ targets[1].element.style.filter = '';
1371
+ targets[2].element.style.filter = '';
1372
+ targets[3].element.style.filter = '';
1373
+ xnew$1.emit('-up', { type: '-up', vector });
1463
1374
  });
1464
- internal.on('-down', (...args) => xnew$1.emit('-down', ...args));
1465
- internal.on('-move', (...args) => xnew$1.emit('-move', ...args));
1466
- internal.on('-up', (...args) => xnew$1.emit('-up', ...args));
1467
1375
  }
1468
1376
 
1469
1377
  function TextStream(unit, { text = '', speed = 50, fade = 300 } = {}) {
@@ -1513,13 +1421,9 @@
1513
1421
 
1514
1422
  const basics = {
1515
1423
  Screen,
1516
- ModalFrame,
1517
- ModalContent,
1518
- AccordionFrame,
1519
- AccordionContent,
1424
+ Modal,
1425
+ Accordion,
1520
1426
  TextStream,
1521
- DragFrame,
1522
- DragTarget,
1523
1427
  AnalogStick,
1524
1428
  DirectionalPad,
1525
1429
  };
package/dist/xnew.mjs CHANGED
@@ -935,9 +935,8 @@ class UnitTimer {
935
935
  }
936
936
 
937
937
  const xnew$1 = Object.assign(function (...args) {
938
- if (Unit.rootUnit === undefined) {
938
+ if (Unit.rootUnit === undefined)
939
939
  Unit.reset();
940
- }
941
940
  return new Unit(Unit.currentUnit, ...args);
942
941
  }, {
943
942
  /**
@@ -1157,8 +1156,8 @@ const xnew$1 = Object.assign(function (...args) {
1157
1156
  }
1158
1157
  });
1159
1158
 
1160
- function AccordionFrame(unit, { open = false, duration = 200, easing = 'ease' } = {}) {
1161
- xnew$1.context('xnew.accordionframe', unit);
1159
+ function Accordion(unit, { open = false, duration = 200, easing = 'ease' } = {}) {
1160
+ xnew$1.context('xnew.accordion', unit);
1162
1161
  unit.on('-transition', ({ state }) => {
1163
1162
  unit.state = state;
1164
1163
  });
@@ -1187,23 +1186,6 @@ function AccordionFrame(unit, { open = false, duration = 200, easing = 'ease' }
1187
1186
  }
1188
1187
  };
1189
1188
  }
1190
- function AccordionContent(unit, {} = {}) {
1191
- const frame = xnew$1.context('xnew.accordionframe');
1192
- const outer = xnew$1.nest(`<div style="display: ${frame.state === 1.9 ? 'block' : 'none'};">`);
1193
- const inner = xnew$1.nest('<div style="padding: 0; display: flex; flex-direction: column; box-sizing: border-box;">');
1194
- frame.on('-transition', ({ state }) => {
1195
- outer.style.display = 'block';
1196
- if (state === 0.0) {
1197
- outer.style.display = 'none';
1198
- }
1199
- else if (state < 1.0) {
1200
- Object.assign(outer.style, { height: inner.offsetHeight * state + 'px', overflow: 'hidden', opacity: state });
1201
- }
1202
- else {
1203
- Object.assign(outer.style, { height: 'auto', overflow: 'visible', opacity: 1.0 });
1204
- }
1205
- });
1206
- }
1207
1189
 
1208
1190
  function Screen(unit, { width = 640, height = 480, fit = 'contain' } = {}) {
1209
1191
  const size = { width, height };
@@ -1252,7 +1234,7 @@ function Screen(unit, { width = 640, height = 480, fit = 'contain' } = {}) {
1252
1234
  };
1253
1235
  }
1254
1236
 
1255
- function ModalFrame(unit, { duration = 200, easing = 'ease' } = {}) {
1237
+ function Modal(unit, { duration = 200, easing = 'ease' } = {}) {
1256
1238
  xnew$1.context('xnew.modalframe', unit);
1257
1239
  xnew$1.nest('<div style="position: fixed; inset: 0; z-index: 1000;">');
1258
1240
  unit.on('click', ({ event }) => unit.close());
@@ -1260,57 +1242,13 @@ function ModalFrame(unit, { duration = 200, easing = 'ease' } = {}) {
1260
1242
  xnew$1.emit('-transition', { state: x });
1261
1243
  }, duration, easing);
1262
1244
  return {
1245
+ state: 0.0,
1263
1246
  close() {
1264
1247
  xnew$1.transition((x) => xnew$1.emit('-transition', { state: 1.0 - x }), duration, easing)
1265
1248
  .timeout(() => unit.finalize());
1266
1249
  }
1267
1250
  };
1268
1251
  }
1269
- function ModalContent(content, { background = 'rgba(0, 0, 0, 0.1)' } = {}) {
1270
- const frame = xnew$1.context('xnew.modalframe');
1271
- const outer = xnew$1.nest(`<div style="width: 100%; height: 100%; opacity: 0; background: ${background}">`);
1272
- xnew$1.nest('<div style="position: absolute; inset: 0; margin: auto; width: max-content; height: max-content;">');
1273
- frame.on('click', ({ event }) => event.stopPropagation());
1274
- frame.on('-transition', ({ state }) => {
1275
- outer.style.opacity = state.toString();
1276
- });
1277
- }
1278
-
1279
- function DragFrame(unit, { x = 0, y = 0 } = {}) {
1280
- const absolute = xnew$1.nest(`<div style="position: absolute; top: ${y}px; left: ${x}px;">`);
1281
- xnew$1.context('xnew.dragframe', unit);
1282
- return {
1283
- absolute,
1284
- };
1285
- }
1286
- function DragTarget(unit, {} = {}) {
1287
- const frame = xnew$1.context('xnew.dragframe');
1288
- const current = { x: 0, y: 0 };
1289
- const offset = { x: 0, y: 0 };
1290
- let dragged = false;
1291
- const target = xnew$1(frame.absolute.parentElement);
1292
- target.on('dragstart', ({ event, position }) => {
1293
- if (unit.element.contains(event.target) === false)
1294
- return;
1295
- dragged = true;
1296
- offset.x = position.x - parseFloat(frame.absolute.style.left || '0');
1297
- offset.y = position.y - parseFloat(frame.absolute.style.top || '0');
1298
- current.x = position.x - offset.x;
1299
- current.y = position.y - offset.y;
1300
- });
1301
- target.on('dragmove', ({ event, delta }) => {
1302
- if (dragged !== true)
1303
- return;
1304
- current.x += delta.x;
1305
- current.y += delta.y;
1306
- frame.absolute.style.left = `${current.x}px`;
1307
- frame.absolute.style.top = `${current.y}px`;
1308
- });
1309
- target.on('dragend', ({ event }) => {
1310
- dragged = false;
1311
- });
1312
- xnew$1.nest('<div>');
1313
- }
1314
1252
 
1315
1253
  //----------------------------------------------------------------------------------------------------
1316
1254
  // controller
@@ -1325,139 +1263,109 @@ function SVGTemplate(self, { stroke = 'currentColor', strokeOpacity = 0.8, strok
1325
1263
  }
1326
1264
  function AnalogStick(unit, { stroke = 'currentColor', strokeOpacity = 0.8, strokeWidth = 2, strokeLinejoin = 'round', fill = '#FFF', fillOpacity = 0.8 } = {}) {
1327
1265
  const outer = xnew$1.nest(`<div style="position: relative; width: 100%; height: 100%;">`);
1328
- const internal = xnew$1((unit) => {
1329
- let newsize = Math.min(outer.clientWidth, outer.clientHeight);
1330
- const inner = xnew$1.nest(`<div style="position: absolute; width: ${newsize}px; height: ${newsize}px; margin: auto; inset: 0; cursor: pointer; pointer-select: none; pointer-events: auto; overflow: hidden;">`);
1331
- xnew$1(outer).on('resize', () => {
1332
- newsize = Math.min(outer.clientWidth, outer.clientHeight);
1333
- inner.style.width = `${newsize}px`;
1334
- inner.style.height = `${newsize}px`;
1335
- });
1336
- xnew$1((unit) => {
1337
- xnew$1.extend(SVGTemplate, { fill, fillOpacity, stroke, strokeOpacity, strokeWidth, strokeLinejoin });
1338
- xnew$1('<polygon points="50 7 40 18 60 18">');
1339
- xnew$1('<polygon points="50 93 40 83 60 83">');
1340
- xnew$1('<polygon points=" 7 50 18 40 18 60">');
1341
- xnew$1('<polygon points="93 50 83 40 83 60">');
1342
- });
1343
- const target = xnew$1((unit) => {
1344
- xnew$1.extend(SVGTemplate, { fill, fillOpacity, stroke, strokeOpacity, strokeWidth, strokeLinejoin });
1345
- xnew$1('<circle cx="50" cy="50" r="23">');
1346
- });
1347
- unit.on('dragstart', ({ event, position }) => {
1348
- const vector = getVector(position);
1349
- target.element.style.filter = 'brightness(90%)';
1350
- target.element.style.left = vector.x * newsize / 4 + 'px';
1351
- target.element.style.top = vector.y * newsize / 4 + 'px';
1352
- xnew$1.emit('-down', { vector });
1353
- });
1354
- unit.on('dragmove', ({ event, position }) => {
1355
- const vector = getVector(position);
1356
- target.element.style.filter = 'brightness(90%)';
1357
- target.element.style.left = vector.x * newsize / 4 + 'px';
1358
- target.element.style.top = vector.y * newsize / 4 + 'px';
1359
- xnew$1.emit('-move', { vector });
1360
- });
1361
- unit.on('dragend', ({ event }) => {
1362
- const vector = { x: 0, y: 0 };
1363
- target.element.style.filter = '';
1364
- target.element.style.left = vector.x * newsize / 4 + 'px';
1365
- target.element.style.top = vector.y * newsize / 4 + 'px';
1366
- xnew$1.emit('-up', { vector });
1367
- });
1368
- function getVector(position) {
1369
- const x = position.x - newsize / 2;
1370
- const y = position.y - newsize / 2;
1371
- const d = Math.min(1.0, Math.sqrt(x * x + y * y) / (newsize / 4));
1372
- const a = (y !== 0 || x !== 0) ? Math.atan2(y, x) : 0;
1373
- return { x: Math.cos(a) * d, y: Math.sin(a) * d };
1374
- }
1266
+ let newsize = Math.min(outer.clientWidth, outer.clientHeight);
1267
+ const inner = xnew$1.nest(`<div style="position: absolute; width: ${newsize}px; height: ${newsize}px; margin: auto; inset: 0; cursor: pointer; pointer-select: none; pointer-events: auto; overflow: hidden;">`);
1268
+ xnew$1(outer).on('resize', () => {
1269
+ newsize = Math.min(outer.clientWidth, outer.clientHeight);
1270
+ inner.style.width = `${newsize}px`;
1271
+ inner.style.height = `${newsize}px`;
1272
+ });
1273
+ xnew$1((unit) => {
1274
+ xnew$1.extend(SVGTemplate, { fill, fillOpacity, stroke, strokeOpacity, strokeWidth, strokeLinejoin });
1275
+ xnew$1('<polygon points="50 7 40 18 60 18">');
1276
+ xnew$1('<polygon points="50 93 40 83 60 83">');
1277
+ xnew$1('<polygon points=" 7 50 18 40 18 60">');
1278
+ xnew$1('<polygon points="93 50 83 40 83 60">');
1279
+ });
1280
+ const target = xnew$1((unit) => {
1281
+ xnew$1.extend(SVGTemplate, { fill, fillOpacity, stroke, strokeOpacity, strokeWidth, strokeLinejoin });
1282
+ xnew$1('<circle cx="50" cy="50" r="23">');
1283
+ });
1284
+ unit.on('dragstart dragmove', ({ type, position }) => {
1285
+ const x = position.x - newsize / 2;
1286
+ const y = position.y - newsize / 2;
1287
+ const d = Math.min(1.0, Math.sqrt(x * x + y * y) / (newsize / 4));
1288
+ const a = (y !== 0 || x !== 0) ? Math.atan2(y, x) : 0;
1289
+ const vector = { x: Math.cos(a) * d, y: Math.sin(a) * d };
1290
+ target.element.style.filter = 'brightness(90%)';
1291
+ target.element.style.left = `${vector.x * newsize / 4}px`;
1292
+ target.element.style.top = `${vector.y * newsize / 4}px`;
1293
+ const nexttype = { dragstart: '-down', dragmove: '-move' }[type];
1294
+ xnew$1.emit(nexttype, { type: nexttype, vector });
1295
+ });
1296
+ unit.on('dragend', () => {
1297
+ const vector = { x: 0, y: 0 };
1298
+ target.element.style.filter = '';
1299
+ target.element.style.left = `${vector.x * newsize / 4}px`;
1300
+ target.element.style.top = `${vector.y * newsize / 4}px`;
1301
+ xnew$1.emit('-up', { type: '-up', vector });
1375
1302
  });
1376
- internal.on('-down', (...args) => xnew$1.emit('-down', ...args));
1377
- internal.on('-move', (...args) => xnew$1.emit('-move', ...args));
1378
- internal.on('-up', (...args) => xnew$1.emit('-up', ...args));
1379
1303
  }
1380
1304
  function DirectionalPad(unit, { diagonal = true, stroke = 'currentColor', strokeOpacity = 0.8, strokeWidth = 2, strokeLinejoin = 'round', fill = '#FFF', fillOpacity = 0.8 } = {}) {
1381
1305
  const outer = xnew$1.nest(`<div style="position: relative; width: 100%; height: 100%;">`);
1382
- const internal = xnew$1((unit) => {
1383
- let newsize = Math.min(outer.clientWidth, outer.clientHeight);
1384
- const inner = xnew$1.nest(`<div style="position: absolute; width: ${newsize}px; height: ${newsize}px; margin: auto; inset: 0; cursor: pointer; pointer-select: none; pointer-events: auto; overflow: hidden;">`);
1385
- xnew$1(outer).on('resize', () => {
1386
- newsize = Math.min(outer.clientWidth, outer.clientHeight);
1387
- inner.style.width = `${newsize}px`;
1388
- inner.style.height = `${newsize}px`;
1389
- });
1390
- const polygons = [
1391
- '<polygon points="50 50 35 35 35 5 37 3 63 3 65 5 65 35">',
1392
- '<polygon points="50 50 35 65 35 95 37 97 63 97 65 95 65 65">',
1393
- '<polygon points="50 50 35 35 5 35 3 37 3 63 5 65 35 65">',
1394
- '<polygon points="50 50 65 35 95 35 97 37 97 63 95 65 65 65">'
1395
- ];
1396
- const targets = polygons.map((polygon) => {
1397
- return xnew$1((unit) => {
1398
- xnew$1.extend(SVGTemplate, { stroke: 'none', fill, fillOpacity });
1399
- xnew$1(polygon);
1400
- });
1401
- });
1402
- xnew$1((unit) => {
1403
- xnew$1.extend(SVGTemplate, { fill: 'none', stroke, strokeOpacity, strokeWidth, strokeLinejoin });
1404
- xnew$1('<polyline points="35 35 35 5 37 3 63 3 65 5 65 35">');
1405
- xnew$1('<polyline points="35 65 35 95 37 97 63 97 65 95 65 65">');
1406
- xnew$1('<polyline points="35 35 5 35 3 37 3 63 5 65 35 65">');
1407
- xnew$1('<polyline points="65 35 95 35 97 37 97 63 95 65 65 65">');
1408
- xnew$1('<polygon points="50 11 42 20 58 20">');
1409
- xnew$1('<polygon points="50 89 42 80 58 80">');
1410
- xnew$1('<polygon points="11 50 20 42 20 58">');
1411
- xnew$1('<polygon points="89 50 80 42 80 58">');
1412
- });
1413
- unit.on('dragstart', ({ event, position }) => {
1414
- const vector = getVector(position);
1415
- targets[0].element.style.filter = (vector.y < 0) ? 'brightness(90%)' : '';
1416
- targets[1].element.style.filter = (vector.y > 0) ? 'brightness(90%)' : '';
1417
- targets[2].element.style.filter = (vector.x < 0) ? 'brightness(90%)' : '';
1418
- targets[3].element.style.filter = (vector.x > 0) ? 'brightness(90%)' : '';
1419
- xnew$1.emit('-down', { vector });
1420
- });
1421
- unit.on('dragmove', ({ event, position }) => {
1422
- const vector = getVector(position);
1423
- targets[0].element.style.filter = (vector.y < 0) ? 'brightness(90%)' : '';
1424
- targets[1].element.style.filter = (vector.y > 0) ? 'brightness(90%)' : '';
1425
- targets[2].element.style.filter = (vector.x < 0) ? 'brightness(90%)' : '';
1426
- targets[3].element.style.filter = (vector.x > 0) ? 'brightness(90%)' : '';
1427
- xnew$1.emit('-move', { vector });
1428
- });
1429
- unit.on('dragend', ({ event }) => {
1430
- const vector = { x: 0, y: 0 };
1431
- targets[0].element.style.filter = '';
1432
- targets[1].element.style.filter = '';
1433
- targets[2].element.style.filter = '';
1434
- targets[3].element.style.filter = '';
1435
- xnew$1.emit('-up', { vector });
1306
+ let newsize = Math.min(outer.clientWidth, outer.clientHeight);
1307
+ const inner = xnew$1.nest(`<div style="position: absolute; width: ${newsize}px; height: ${newsize}px; margin: auto; inset: 0; cursor: pointer; pointer-select: none; pointer-events: auto; overflow: hidden;">`);
1308
+ xnew$1(outer).on('resize', () => {
1309
+ newsize = Math.min(outer.clientWidth, outer.clientHeight);
1310
+ inner.style.width = `${newsize}px`;
1311
+ inner.style.height = `${newsize}px`;
1312
+ });
1313
+ const polygons = [
1314
+ '<polygon points="50 50 35 35 35 5 37 3 63 3 65 5 65 35">',
1315
+ '<polygon points="50 50 35 65 35 95 37 97 63 97 65 95 65 65">',
1316
+ '<polygon points="50 50 35 35 5 35 3 37 3 63 5 65 35 65">',
1317
+ '<polygon points="50 50 65 35 95 35 97 37 97 63 95 65 65 65">'
1318
+ ];
1319
+ const targets = polygons.map((polygon) => {
1320
+ return xnew$1((unit) => {
1321
+ xnew$1.extend(SVGTemplate, { stroke: 'none', fill, fillOpacity });
1322
+ xnew$1(polygon);
1436
1323
  });
1437
- function getVector(position) {
1438
- const x = position.x - newsize / 2;
1439
- const y = position.y - newsize / 2;
1440
- const a = (y !== 0 || x !== 0) ? Math.atan2(y, x) : 0;
1441
- const d = Math.min(1.0, Math.sqrt(x * x + y * y) / (newsize / 4));
1442
- const vector = { x: Math.cos(a) * d, y: Math.sin(a) * d };
1443
- if (diagonal === true) {
1444
- vector.x = Math.abs(vector.x) > 0.5 ? Math.sign(vector.x) : 0;
1445
- vector.y = Math.abs(vector.y) > 0.5 ? Math.sign(vector.y) : 0;
1446
- }
1447
- else if (Math.abs(vector.x) > Math.abs(vector.y)) {
1448
- vector.x = Math.abs(vector.x) > 0.5 ? Math.sign(vector.x) : 0;
1449
- vector.y = 0;
1450
- }
1451
- else {
1452
- vector.x = 0;
1453
- vector.y = Math.abs(vector.y) > 0.5 ? Math.sign(vector.y) : 0;
1454
- }
1455
- return vector;
1324
+ });
1325
+ xnew$1((unit) => {
1326
+ xnew$1.extend(SVGTemplate, { fill: 'none', stroke, strokeOpacity, strokeWidth, strokeLinejoin });
1327
+ xnew$1('<polyline points="35 35 35 5 37 3 63 3 65 5 65 35">');
1328
+ xnew$1('<polyline points="35 65 35 95 37 97 63 97 65 95 65 65">');
1329
+ xnew$1('<polyline points="35 35 5 35 3 37 3 63 5 65 35 65">');
1330
+ xnew$1('<polyline points="65 35 95 35 97 37 97 63 95 65 65 65">');
1331
+ xnew$1('<polygon points="50 11 42 20 58 20">');
1332
+ xnew$1('<polygon points="50 89 42 80 58 80">');
1333
+ xnew$1('<polygon points="11 50 20 42 20 58">');
1334
+ xnew$1('<polygon points="89 50 80 42 80 58">');
1335
+ });
1336
+ unit.on('dragstart dragmove', ({ type, position }) => {
1337
+ const x = position.x - newsize / 2;
1338
+ const y = position.y - newsize / 2;
1339
+ const a = (y !== 0 || x !== 0) ? Math.atan2(y, x) : 0;
1340
+ const d = Math.min(1.0, Math.sqrt(x * x + y * y) / (newsize / 4));
1341
+ const vector = { x: Math.cos(a) * d, y: Math.sin(a) * d };
1342
+ if (diagonal === true) {
1343
+ vector.x = Math.abs(vector.x) > 0.5 ? Math.sign(vector.x) : 0;
1344
+ vector.y = Math.abs(vector.y) > 0.5 ? Math.sign(vector.y) : 0;
1345
+ }
1346
+ else if (Math.abs(vector.x) > Math.abs(vector.y)) {
1347
+ vector.x = Math.abs(vector.x) > 0.5 ? Math.sign(vector.x) : 0;
1348
+ vector.y = 0;
1456
1349
  }
1350
+ else {
1351
+ vector.x = 0;
1352
+ vector.y = Math.abs(vector.y) > 0.5 ? Math.sign(vector.y) : 0;
1353
+ }
1354
+ targets[0].element.style.filter = (vector.y < 0) ? 'brightness(90%)' : '';
1355
+ targets[1].element.style.filter = (vector.y > 0) ? 'brightness(90%)' : '';
1356
+ targets[2].element.style.filter = (vector.x < 0) ? 'brightness(90%)' : '';
1357
+ targets[3].element.style.filter = (vector.x > 0) ? 'brightness(90%)' : '';
1358
+ const nexttype = { dragstart: '-down', dragmove: '-move' }[type];
1359
+ xnew$1.emit(nexttype, { type: nexttype, vector });
1360
+ });
1361
+ unit.on('dragend', () => {
1362
+ const vector = { x: 0, y: 0 };
1363
+ targets[0].element.style.filter = '';
1364
+ targets[1].element.style.filter = '';
1365
+ targets[2].element.style.filter = '';
1366
+ targets[3].element.style.filter = '';
1367
+ xnew$1.emit('-up', { type: '-up', vector });
1457
1368
  });
1458
- internal.on('-down', (...args) => xnew$1.emit('-down', ...args));
1459
- internal.on('-move', (...args) => xnew$1.emit('-move', ...args));
1460
- internal.on('-up', (...args) => xnew$1.emit('-up', ...args));
1461
1369
  }
1462
1370
 
1463
1371
  function TextStream(unit, { text = '', speed = 50, fade = 300 } = {}) {
@@ -1507,13 +1415,9 @@ function TextStream(unit, { text = '', speed = 50, fade = 300 } = {}) {
1507
1415
 
1508
1416
  const basics = {
1509
1417
  Screen,
1510
- ModalFrame,
1511
- ModalContent,
1512
- AccordionFrame,
1513
- AccordionContent,
1418
+ Modal,
1419
+ Accordion,
1514
1420
  TextStream,
1515
- DragFrame,
1516
- DragTarget,
1517
1421
  AnalogStick,
1518
1422
  DirectionalPad,
1519
1423
  };
package/package.json CHANGED
@@ -4,7 +4,7 @@
4
4
  "keywords": [
5
5
  "Component-Oriented Programming"
6
6
  ],
7
- "version": "0.4.4",
7
+ "version": "0.4.5",
8
8
  "main": "dist/xnew.js",
9
9
  "module": "dist/xnew.mjs",
10
10
  "types": "dist/xnew.d.ts",