muigui 0.0.6 → 0.0.12

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/package.json CHANGED
@@ -1,17 +1,22 @@
1
1
  {
2
2
  "name": "muigui",
3
- "version": "0.0.6",
3
+ "version": "0.0.12",
4
4
  "description": "A Simple GUI",
5
5
  "main": "muigui.js",
6
6
  "module": "src/muigui.js",
7
7
  "type": "module",
8
8
  "scripts": {
9
9
  "build": "npm run build-normal",
10
+ "build-ci": "npm run build && node build/prep-for-deploy.js",
10
11
  "build-normal": "rollup -c",
11
12
  "build-min": "rollup -c",
13
+ "check-ci": "npm run pre-push",
12
14
  "eslint": "eslint \"**/*.js\"",
13
- "pre-push": "npm run eslint",
14
- "test": "echo \"Error: no test specified\" && exit 1"
15
+ "fix": "eslint --fix",
16
+ "pre-push": "npm run eslint && npm run build && npm run test",
17
+ "start": "node build/serve.js",
18
+ "test": "node test/puppeteer.js",
19
+ "watch": "npm run start"
15
20
  },
16
21
  "repository": {
17
22
  "type": "git",
@@ -35,10 +40,20 @@
35
40
  "devDependencies": {
36
41
  "@rollup/plugin-node-resolve": "^15.0.1",
37
42
  "@rollup/plugin-terser": "^0.4.0",
43
+ "@rollup/plugin-typescript": "^11.1.5",
44
+ "@tsconfig/recommended": "^1.0.3",
45
+ "@typescript-eslint/eslint-plugin": "^6.12.0",
46
+ "@typescript-eslint/parser": "^6.12.0",
47
+ "chokidar": "^3.5.3",
38
48
  "eslint": "^8.20.0",
39
49
  "eslint-plugin-html": "^7.1.0",
50
+ "eslint-plugin-one-variable-per-var": "^0.0.3",
40
51
  "eslint-plugin-optional-comma-spacing": "0.0.4",
41
52
  "eslint-plugin-require-trailing-comma": "0.0.1",
42
- "rollup": "^3.20.2"
53
+ "puppeteer": "^21.5.2",
54
+ "rollup": "^3.20.2",
55
+ "servez": "^2.1.2",
56
+ "tslib": "^2.6.2",
57
+ "typescript": "5.2"
43
58
  }
44
59
  }
@@ -1,12 +1,52 @@
1
+ /* eslint-disable no-underscore-dangle */
2
+ import {
3
+ colorFormatConverters,
4
+ guessFormat,
5
+ hasAlpha,
6
+ hexToUint8RGB,
7
+ hslToRgbUint8,
8
+ rgbUint8ToHsl,
9
+ uint8RGBToHex,
10
+ } from '../libs/color-utils.js';
1
11
  import ColorChooserView from '../views/ColorChooserView.js';
2
12
  import TextView from '../views/TextView.js';
3
13
  import PopDownController from './PopDownController.js';
4
14
 
5
15
  export default class ColorChooser extends PopDownController {
6
- constructor(object, property) {
16
+ #colorView;
17
+ #textView;
18
+ #to;
19
+ #setKnobHelper;
20
+
21
+ constructor(object, property, options = {}) {
7
22
  super(object, property, 'muigui-color-chooser');
8
- this.addTop(new TextView(this));
9
- this.addBottom(new ColorChooserView(this));
23
+ const format = options.format || guessFormat(this.getValue());
24
+ const {color, text} = colorFormatConverters[format];
25
+ this.#to = color.to;
26
+ this.#textView = new TextView(this, {converters: text, alpha: hasAlpha(format)});
27
+ this.#colorView = new ColorChooserView(this, {converters: color, alpha: hasAlpha(format)});
28
+ this.addTop(this.#textView);
29
+ this.addBottom(this.#colorView);
30
+ // WTF! FIX!
31
+ this.#setKnobHelper = () => {
32
+ if (this.#to) {
33
+ const hex6Or8 = this.#to(this.getValue());
34
+ const hsl = rgbUint8ToHsl(hexToUint8RGB(hex6Or8));
35
+ hsl[2] = (hsl[2] + 50) % 100;
36
+ const hex = uint8RGBToHex(hslToRgbUint8(hsl));
37
+ this.setKnobColor(`${hex6Or8.substring(0, 7)}FF`, hex);
38
+ }
39
+ };
10
40
  this.updateDisplay();
11
41
  }
42
+ updateDisplay() {
43
+ super.updateDisplay();
44
+ if (this.#setKnobHelper) {
45
+ this.#setKnobHelper();
46
+ }
47
+ }
48
+ setOptions(options) {
49
+ super.setOptions(options);
50
+ return this;
51
+ }
12
52
  }
@@ -26,6 +26,12 @@ export default class Container extends Controller {
26
26
  }
27
27
  return this;
28
28
  }
29
+ updateDisplay() {
30
+ for (const controller of this.#controllers) {
31
+ controller.updateDisplay();
32
+ }
33
+ return this;
34
+ }
29
35
  remove(controller) {
30
36
  const ndx = this.#controllers.indexOf(controller);
31
37
  if (ndx >= 0) {
@@ -37,14 +43,14 @@ export default class Container extends Controller {
37
43
  }
38
44
  return this;
39
45
  }
40
- _addControllerImpl(controller) {
46
+ #addControllerImpl(controller) {
41
47
  this.domElement.appendChild(controller.domElement);
42
48
  this.#controllers.push(controller);
43
49
  controller.setParent(this);
44
50
  return controller;
45
51
  }
46
52
  addController(controller) {
47
- return this.#childDestController._addControllerImpl(controller);
53
+ return this.#childDestController.#addControllerImpl(controller);
48
54
  }
49
55
  pushContainer(container) {
50
56
  this.addController(container);
@@ -113,6 +113,9 @@ export default class Controller extends View {
113
113
  }
114
114
  }
115
115
  }
116
+ updateDisplay() {
117
+ // placeholder. override
118
+ }
116
119
  getColors() {
117
120
  const toCamelCase = s => s.replace(/-([a-z])/g, (m, m1) => m1.toUpperCase());
118
121
  const keys = [
@@ -1,6 +1,5 @@
1
1
  import ElementView from '../views/ElementView.js';
2
2
  import ValueController from './ValueController.js';
3
- import CheckboxView from '../views/CheckboxView.js';
4
3
  import { copyExistingProperties } from '../libs/utils.js';
5
4
  import { createElem } from '../libs/elem.js';
6
5
  /*
@@ -27,22 +26,14 @@ pc.addBottom
27
26
 
28
27
  */
29
28
 
30
- function makeSetter(object, property) {
31
- return {
32
- setValue(v) {
33
- object[property] = v;
34
- },
35
- setFinalValue(v) {
36
- this.setValue(v);
37
- },
38
- };
39
- }
40
-
41
29
  export default class PopDownController extends ValueController {
42
30
  #top;
43
31
  #valuesView;
32
+ #checkboxElem;
44
33
  #bottom;
45
- #options = {open: false};
34
+ #options = {
35
+ open: false,
36
+ };
46
37
 
47
38
  constructor(object, property, options = {}) {
48
39
  super(object, property, 'muigui-pop-down-controller');
@@ -58,12 +49,22 @@ export default class PopDownController extends ValueController {
58
49
  type: 'checkbox',
59
50
  onChange: () => {
60
51
  this.#options.open = checkboxElem.checked;
52
+ this.updateDisplay();
61
53
  },
62
54
  }));
55
+ this.#checkboxElem = checkboxElem;
63
56
  this.#valuesView = this.#top.add(new ElementView('div', 'muigui-pop-down-values'));
64
57
  this.#bottom = this.add(new ElementView('div', 'muigui-pop-down-bottom'));
65
58
  this.setOptions(options);
66
59
  }
60
+ setKnobColor(bgCssColor/*, fgCssColor*/) {
61
+ if (this.#checkboxElem) {
62
+ this.#checkboxElem.style = `
63
+ --range-color: ${bgCssColor};
64
+ --value-bg-color: ${bgCssColor};
65
+ `;
66
+ }
67
+ }
67
68
  updateDisplay() {
68
69
  super.updateDisplay();
69
70
  const {open} = this.#options;
@@ -34,31 +34,39 @@ export default class ValueController extends LabelController {
34
34
  return view;
35
35
  }
36
36
  #setValueImpl(v, ignoreCache) {
37
+ let isDifferent = false;
37
38
  if (typeof v === 'object') {
38
39
  const dst = this.#object[this.#property];
39
40
  // don't replace objects, just their values.
40
- if (Array.isArray(v)) {
41
+ if (Array.isArray(v) || isTypedArray(v)) {
41
42
  for (let i = 0; i < v.length; ++i) {
43
+ isDifferent ||= dst[i] !== v[i];
42
44
  dst[i] = v[i];
43
45
  }
44
- } else if (isTypedArray(v)) {
45
- dst.set(v);
46
46
  } else {
47
+ for (const key of Object.keys(v)) {
48
+ isDifferent ||= dst[key] !== v[key];
49
+ }
47
50
  Object.assign(dst, v);
48
51
  }
49
52
  } else {
53
+ isDifferent = this.#object[this.#property] !== v;
50
54
  this.#object[this.#property] = v;
51
55
  }
52
56
  this.updateDisplay(ignoreCache);
53
- this.emitChange(this.getValue(), this.#object, this.#property);
54
- return this;
57
+ if (isDifferent) {
58
+ this.emitChange(this.getValue(), this.#object, this.#property);
59
+ }
60
+ return isDifferent;
55
61
  }
56
62
  setValue(v) {
57
63
  this.#setValueImpl(v);
58
64
  }
59
65
  setFinalValue(v) {
60
- this.#setValueImpl(v, true);
61
- this.emitFinalChange(this.getValue(), this.#object, this.#property);
66
+ const isDifferent = this.#setValueImpl(v, true);
67
+ if (isDifferent) {
68
+ this.emitFinalChange(this.getValue(), this.#object, this.#property);
69
+ }
62
70
  return this;
63
71
  }
64
72
  updateDisplay(ignoreCache) {
@@ -1,4 +1,3 @@
1
- import GridView from '../views/GridView.js';
2
1
  import NumberView from '../views/NumberView.js';
3
2
  import Vec2View from '../views/Vec2View.js';
4
3
  import PopDownController from './PopDownController.js';
@@ -3,7 +3,6 @@ import View from '../views/View.js';
3
3
 
4
4
  function showCSS(ob) {
5
5
  if (ob.prototype.css) {
6
- console.log(ob.prototype.css);
7
6
  showCSS(ob.prototype);
8
7
  }
9
8
  }