onejs-core 1.0.13 → 1.0.15

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.
@@ -65,17 +65,21 @@ declare namespace CS {
65
65
  public includeGlobalObjects : boolean
66
66
  public constructor ()
67
67
  }
68
- class EngineHost extends System.Object implements System.IDisposable
68
+ interface IEngineHost {
69
+ add_onReload ($value: System.Action) : void
70
+ remove_onReload ($value: System.Action) : void
71
+ add_onDispose ($value: System.Action) : void
72
+ remove_onDispose ($value: System.Action) : void
73
+ }
74
+ class EngineHost extends System.Object implements System.IDisposable, IEngineHost
69
75
  {
70
76
  protected [__keep_incompatibility]: never;
71
- public add_onReload ($value: OneJS.EngineHost.ActionCallback) : void
72
- public remove_onReload ($value: OneJS.EngineHost.ActionCallback) : void
73
- public add_onDestroy ($value: OneJS.EngineHost.ActionCallback) : void
74
- public remove_onDestroy ($value: OneJS.EngineHost.ActionCallback) : void
77
+ public add_onReload ($value: System.Action) : void
78
+ public remove_onReload ($value: System.Action) : void
79
+ public add_onDispose ($value: System.Action) : void
80
+ public remove_onDispose ($value: System.Action) : void
75
81
  public subscribe ($eventSource: any, $eventName: string, $handler: Function) : System.Action
76
82
  public subscribe ($eventName: string, $handler: Function) : System.Action
77
- public InvokeOnReload () : void
78
- public InvokeOnDestroy () : void
79
83
  public Dispose () : void
80
84
  public constructor ($engine: OneJS.ScriptEngine)
81
85
  }
@@ -446,14 +450,6 @@ declare namespace CS {
446
450
  public constructor ()
447
451
  }
448
452
  }
449
- namespace OneJS.EngineHost {
450
- interface ActionCallback
451
- {
452
- () : void;
453
- Invoke?: () => void;
454
- }
455
- var ActionCallback: { new (func: () => void): ActionCallback; }
456
- }
457
453
  namespace Puerts {
458
454
  class GenericDelegate extends System.Object
459
455
  {
@@ -34,11 +34,14 @@ declare global {
34
34
  const cancelAnimationFrame: (id: number) => void
35
35
 
36
36
  const console: {
37
- log: (...args: any[]) => void
38
- error: (...args: any[]) => void
39
- warn: (...args: any[]) => void
40
- info: (...args: any[]) => void
41
- debug: (...args: any[]) => void
37
+ log: (...args: any[]) => void;
38
+ info: (...args: any[]) => void;
39
+ warn: (...args: any[]) => void;
40
+ error: (...args: any[]) => void;
41
+ trace: (...args: any[]) => void;
42
+ assert: (condition: boolean, ...args: any[]) => void;
43
+ time: (label: string) => void;
44
+ timeEnd: (label: string) => void;
42
45
  }
43
46
 
44
47
  interface Event {
@@ -12,13 +12,13 @@ declare namespace OneJS {
12
12
  declare const onejs: {
13
13
  add_onReload(handler: () => void): void
14
14
  remove_onReload(handler: () => void): void
15
- add_onDestroy(handler: () => void): void
16
- remove_onDestroy(handler: () => void): void
15
+ add_onDispose(handler: () => void): void
16
+ remove_onDispose(handler: () => void): void
17
17
 
18
- interop: { // TODO
19
- classes: Record<string, any>
20
- objects: Record<string, any>
21
- }
18
+ // interop: { // TODO
19
+ // classes: Record<string, any>
20
+ // objects: Record<string, any>
21
+ // }
22
22
 
23
23
  subscribe<T, K extends OneJS.EventKeys<T>>(
24
24
  eventSource: T,
@@ -7,3 +7,4 @@
7
7
  export { parseColor, parseCSSColor, colorStrToF4, namedColor, namedColors } from "./color-parser";
8
8
  export { palettes } from "./color-palettes";
9
9
  export { parseFloat2, parseFloat3, parseFloat4 } from "./float-parser";
10
+ export { subscribe } from "./subscribe";
@@ -10,3 +10,4 @@ export { parseColor, parseCSSColor, colorStrToF4, namedColor, namedColors } from
10
10
  export { palettes } from "./color-palettes";
11
11
  // @ts-ignore - prevent `allowImportingTsExtensions` error
12
12
  export { parseFloat2, parseFloat3, parseFloat4 } from "./float-parser";
13
+ export { subscribe } from "./subscribe";
@@ -0,0 +1,4 @@
1
+ export declare function subscribe<T, K extends keyof T>(target: T, eventName: K, callback: () => void): () => void;
2
+ export declare function subscribe<T, K extends keyof T>(target: {
3
+ new (): T;
4
+ }, eventName: K, callback: () => void): () => void;
@@ -0,0 +1,10 @@
1
+ import { Action, Delegate } from "System";
2
+ export function subscribe(target, eventName, callback) {
3
+ var action = new Action(callback);
4
+ target[eventName] = Delegate.Combine(target[eventName], action);
5
+ const unsubscribe = () => {
6
+ target[eventName] = Delegate.Remove(target[eventName], action);
7
+ };
8
+ onejs.add_onReload(unsubscribe);
9
+ return unsubscribe;
10
+ }
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": "1.0.13",
4
+ "version": "1.0.15",
5
5
  "main": "./dist/index.js",
6
6
  "types": "./typings.d.ts",
7
7
  "dependencies": {
@@ -0,0 +1,89 @@
1
+ /**
2
+ * postcss-cleanup-plugin
3
+ *
4
+ * A PostCSS plugin that removes unwanted CSS rules and declarations based on the `remove` array in options.
5
+ * Usage example:
6
+ *
7
+ * ```js
8
+ * plugins: [
9
+ * require('./postcss-cleanup-plugin')({
10
+ * remove: [
11
+ * ".someClass", // Remove rules containing this class
12
+ * "line-height:", // Remove any line-height property
13
+ * "display: grid" // Remove only display property if value is grid
14
+ * ]
15
+ * })
16
+ * ]
17
+ * ```
18
+ *
19
+ * How it works:
20
+ * 1) Entries beginning with "." (e.g. ".foo") cause removal of entire rules containing that class.
21
+ * 2) Entries ending with ":" but no value (e.g. "prop:") remove any declaration with the property "prop".
22
+ * 3) Entries with both property and value (e.g. "prop: value") remove only those exact prop-value declarations.
23
+ *
24
+ */
25
+ module.exports = (opts = {}) => {
26
+ const removeEntries = opts.remove || [];
27
+
28
+ // We'll gather them into 3 buckets:
29
+ const classesToRemove = new Set();
30
+ const propertiesToRemoveCompletely = new Set(); // e.g. "line-height:"
31
+ const propertyValuePairsToRemove = []; // e.g. "display: grid"
32
+
33
+ removeEntries.forEach(entry => {
34
+ // 1) If entry starts with ".", assume it's a class to remove
35
+ if (entry.startsWith('.')) {
36
+ classesToRemove.add(entry.slice(1));
37
+ return;
38
+ }
39
+
40
+ // 2) Otherwise, see if there's a ":" for a property
41
+ const parts = entry.split(':').map(s => s.trim());
42
+ if (parts.length === 2) {
43
+ const [prop, value] = parts;
44
+ // If there's no value after the colon => remove that property entirely
45
+ if (!value) {
46
+ propertiesToRemoveCompletely.add(prop);
47
+ } else {
48
+ propertyValuePairsToRemove.push({ prop, value });
49
+ }
50
+ }
51
+ });
52
+
53
+ return {
54
+ postcssPlugin: 'postcss-cleanup-plugin',
55
+ Once(root, { result }) {
56
+ root.walkRules(rule => {
57
+ // Filter out selectors containing unwanted classes
58
+ rule.selectors = rule.selectors.filter(sel => {
59
+ return ![...classesToRemove].some(cls => sel.includes(`.${cls}`));
60
+ });
61
+
62
+ // If no selectors remain, remove the entire rule
63
+ if (rule.selectors.length === 0) {
64
+ rule.remove();
65
+ return;
66
+ }
67
+
68
+ // Remove targeted declarations
69
+ rule.walkDecls(decl => {
70
+ // If the property is in the "remove completely" set, drop it
71
+ if (propertiesToRemoveCompletely.has(decl.prop)) {
72
+ decl.remove();
73
+ return;
74
+ }
75
+
76
+ // If it matches one of the prop-value pairs, drop it
77
+ for (const { prop, value } of propertyValuePairsToRemove) {
78
+ if (decl.prop === prop && decl.value === value) {
79
+ decl.remove();
80
+ return;
81
+ }
82
+ }
83
+ });
84
+ });
85
+ }
86
+ };
87
+ };
88
+
89
+ module.exports.postcss = true;
package/utils/index.ts CHANGED
@@ -11,3 +11,4 @@ export { parseColor, parseCSSColor, colorStrToF4, namedColor, namedColors } from
11
11
  export { palettes } from "./color-palettes"
12
12
  // @ts-ignore - prevent `allowImportingTsExtensions` error
13
13
  export { parseFloat2, parseFloat3, parseFloat4 } from "./float-parser"
14
+ export { subscribe } from "./subscribe"
@@ -0,0 +1,17 @@
1
+ import { Action, Delegate } from "System"
2
+
3
+
4
+ export function subscribe<T, K extends keyof T>(target: T, eventName: K, callback: () => void): () => void
5
+ export function subscribe<T, K extends keyof T>(target: { new(): T }, eventName: K, callback: () => void): () => void
6
+ export function subscribe(target: any, eventName: any, callback: () => void): () => void {
7
+ var action = new Action(callback)
8
+ target[eventName] = Delegate.Combine(target[eventName] as any, action) as any
9
+
10
+ const unsubscribe = () => {
11
+ target[eventName] = Delegate.Remove(target[eventName] as any, action) as any
12
+ }
13
+
14
+ onejs.add_onReload(unsubscribe)
15
+
16
+ return unsubscribe
17
+ }