onejs-core 0.3.41 → 0.3.43

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.
@@ -78,6 +78,7 @@ declare global {
78
78
 
79
79
  interface IntrinsicAttributes {
80
80
  id?: string
81
+ key?: string | number
81
82
  }
82
83
 
83
84
  // interface VNode<P = {}> {
package/dist/dom/dom.d.ts CHANGED
@@ -27,6 +27,7 @@ export declare class DomWrapper {
27
27
  dom: CS.OneJS.Dom.Dom;
28
28
  domStyleWrapper: DomStyleWrapper;
29
29
  cachedChildNodes: DomWrapper[] | null;
30
+ boundListeners: WeakMap<WeakKey, any>;
30
31
  constructor(dom: CS.OneJS.Dom.Dom);
31
32
  appendChild(child: DomWrapper): void;
32
33
  removeChild(child: DomWrapper): void;
package/dist/dom/dom.js CHANGED
@@ -40,15 +40,20 @@ export class DomWrapper {
40
40
  dom;
41
41
  domStyleWrapper;
42
42
  cachedChildNodes = null;
43
+ boundListeners = new WeakMap();
43
44
  constructor(dom) {
44
45
  this.dom = dom;
45
46
  this.domStyleWrapper = new DomStyleWrapper(dom.style);
46
47
  }
47
48
  appendChild(child) {
49
+ if (!child)
50
+ return;
48
51
  this.dom.appendChild(child.dom);
49
52
  this.cachedChildNodes = null;
50
53
  }
51
54
  removeChild(child) {
55
+ if (!child)
56
+ return;
52
57
  this.dom.removeChild(child.dom);
53
58
  this.cachedChildNodes = null;
54
59
  }
@@ -57,6 +62,8 @@ export class DomWrapper {
57
62
  this.cachedChildNodes = null;
58
63
  }
59
64
  contains(child) {
65
+ if (!child)
66
+ return false;
60
67
  return this.dom.contains(child._dom);
61
68
  }
62
69
  clearChildren() {
@@ -67,12 +74,19 @@ export class DomWrapper {
67
74
  this.dom.focus();
68
75
  }
69
76
  addEventListener(type, listener, useCapture) {
70
- // @ts-ignore
71
- this.dom.addEventListener(type, listener.bind(this), useCapture ? true : false);
77
+ let boundListener = this.boundListeners.get(listener);
78
+ if (!boundListener) {
79
+ boundListener = listener.bind(this);
80
+ this.boundListeners.set(listener, boundListener);
81
+ }
82
+ this.dom.addEventListener(type, boundListener, useCapture ? true : false);
72
83
  }
73
84
  removeEventListener(type, listener, useCapture) {
74
- // @ts-ignore
75
- this.dom.removeEventListener(type, listener.bind(this), useCapture ? true : false);
85
+ const boundListener = this.boundListeners.get(listener);
86
+ if (boundListener) {
87
+ this.dom.removeEventListener(type, boundListener, useCapture ? true : false);
88
+ this.boundListeners.delete(listener); // isn't strictly necessary for WeakMap, but still good practice
89
+ }
76
90
  }
77
91
  setAttribute(name, value) {
78
92
  this.dom.setAttribute(name, value);
package/dom/dom.ts CHANGED
@@ -45,6 +45,7 @@ export class DomWrapper {
45
45
  domStyleWrapper: DomStyleWrapper
46
46
 
47
47
  cachedChildNodes: DomWrapper[] | null = null
48
+ boundListeners = new WeakMap();
48
49
 
49
50
  constructor(dom: CS.OneJS.Dom.Dom) {
50
51
  this.dom = dom
@@ -52,11 +53,13 @@ export class DomWrapper {
52
53
  }
53
54
 
54
55
  appendChild(child: DomWrapper) {
56
+ if (!child) return
55
57
  this.dom.appendChild(child.dom)
56
58
  this.cachedChildNodes = null
57
59
  }
58
60
 
59
61
  removeChild(child: DomWrapper) {
62
+ if (!child) return
60
63
  this.dom.removeChild(child.dom)
61
64
  this.cachedChildNodes = null
62
65
  }
@@ -67,6 +70,7 @@ export class DomWrapper {
67
70
  }
68
71
 
69
72
  contains(child: DomWrapper) {
73
+ if (!child) return false
70
74
  return this.dom.contains(child._dom)
71
75
  }
72
76
 
@@ -80,13 +84,20 @@ export class DomWrapper {
80
84
  }
81
85
 
82
86
  addEventListener(type: string, listener: (event: EventBase) => void, useCapture?: boolean) {
83
- // @ts-ignore
84
- this.dom.addEventListener(type, listener.bind(this), useCapture ? true : false)
87
+ let boundListener = this.boundListeners.get(listener);
88
+ if (!boundListener) {
89
+ boundListener = listener.bind(this);
90
+ this.boundListeners.set(listener, boundListener);
91
+ }
92
+ this.dom.addEventListener(type, boundListener, useCapture ? true : false)
85
93
  }
86
94
 
87
95
  removeEventListener(type: string, listener: (event: EventBase) => void, useCapture?: boolean) {
88
- // @ts-ignore
89
- this.dom.removeEventListener(type, listener.bind(this), useCapture ? true : false)
96
+ const boundListener = this.boundListeners.get(listener);
97
+ if (boundListener) {
98
+ this.dom.removeEventListener(type, boundListener, useCapture ? true : false)
99
+ this.boundListeners.delete(listener); // isn't strictly necessary for WeakMap, but still good practice
100
+ }
90
101
  }
91
102
 
92
103
  setAttribute(name: string, value: any) {
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "onejs-core",
3
3
  "description": "The JS part of OneJS, a UI framework and Scripting Engine for Unity.",
4
- "version": "0.3.41",
4
+ "version": "0.3.43",
5
5
  "main": "./dist/index.js",
6
6
  "types": "./typings.d.ts",
7
7
  "dependencies": {
@@ -13,6 +13,7 @@
13
13
  "fs-extra": "^11.2.0",
14
14
  "postcss": "^8.4.38",
15
15
  "postcss-cli": "^11.0.0",
16
+ "progress": "^2.0.3",
16
17
  "rimraf": "^5.0.7",
17
18
  "tailwindcss": "^3.4.1",
18
19
  "tar": "^7.2.0",
@@ -5,6 +5,7 @@ const path = require('path')
5
5
  const fse = require('fs-extra')
6
6
  const xml2js = require('xml2js')
7
7
  const { rimraf } = require('rimraf')
8
+ const ProgressBar = require('progress')
8
9
 
9
10
  const fsp = fs.promises
10
11
 
@@ -172,7 +173,7 @@ async function downloadFile(fileUrl, outputDir) {
172
173
 
173
174
  ensureDirectoryExistence(outputLocationPath);
174
175
 
175
- // Check if the file already exists
176
+ // Check if file exists (keep existing code)
176
177
  if (fs.existsSync(outputLocationPath)) {
177
178
  console.log(`Local .tgz found: ${outputLocationPath}`);
178
179
  return outputLocationPath;
@@ -185,15 +186,24 @@ async function downloadFile(fileUrl, outputDir) {
185
186
  throw new Error(`Failed to fetch ${fileUrl}: ${response.statusText}`);
186
187
  }
187
188
 
189
+ // Get the total size for the progress bar
190
+ const totalSize = parseInt(response.headers.get('content-length'), 10);
191
+
192
+ // Create progress bar
193
+ const progressBar = new ProgressBar('[:bar] :percent ETA: :etas', {
194
+ complete: '=',
195
+ incomplete: ' ',
196
+ width: 40,
197
+ total: totalSize
198
+ });
199
+
188
200
  const fileStream = fs.createWriteStream(outputLocationPath);
189
201
  for await (const chunk of response.body) {
190
202
  fileStream.write(chunk);
203
+ progressBar.tick(chunk.length);
191
204
  }
192
205
 
193
206
  fileStream.end();
194
- fileStream.on('finish', () => {
195
- console.log(`Download completed: ${outputLocationPath}`);
196
- });
197
207
 
198
208
  return new Promise((resolve, reject) => {
199
209
  fileStream.on('close', () => resolve(outputLocationPath));
@@ -12,7 +12,7 @@ module.exports = () => {
12
12
  root.walkRules((rule) => {
13
13
  // Transform class selectors
14
14
  rule.selectors = rule.selectors.map(selector =>
15
- "." + selector.slice(1).replace(/(\\\.|\\#|\\%|\\:|\\\/|\\\[|\\\]|\\\(|\\\)|\\2c)/g, match => {
15
+ selector.replace(/(\\\.|\\#|\\%|\\:|\\\/|\\\[|\\\]|\\\(|\\\)|\\2c)/g, match => {
16
16
  switch (match) {
17
17
  case '\\.': return '_d_';
18
18
  case '\\#': return '_n_';
@@ -39,12 +39,12 @@ module.exports = () => {
39
39
 
40
40
  // Handle hexadecimal colors with alpha value to RGBA conversion
41
41
  root.walkDecls(decl => {
42
- decl.value = decl.value.replace(/: #([A-Fa-f0-9]{8})/g, (match, hex) => {
42
+ decl.value = decl.value.replace(/#([A-Fa-f0-9]{8})/g, (match, hex) => {
43
43
  const r = parseInt(hex.slice(0, 2), 16);
44
44
  const g = parseInt(hex.slice(2, 4), 16);
45
45
  const b = parseInt(hex.slice(4, 6), 16);
46
46
  const a = parseInt(hex.slice(6, 8), 16) / 255;
47
- return `: rgba(${r}, ${g}, ${b}, ${a})`;
47
+ return `rgba(${r}, ${g}, ${b}, ${a})`;
48
48
  });
49
49
  });
50
50