juxscript 1.0.87 → 1.0.89
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/lib/componentsv2/base/BaseEngine.d.ts +10 -0
- package/lib/componentsv2/base/BaseEngine.d.ts.map +1 -1
- package/lib/componentsv2/base/BaseEngine.js +28 -7
- package/lib/componentsv2/base/BaseEngine.js.map +1 -1
- package/lib/componentsv2/base/BaseEngine.ts +29 -0
- package/lib/componentsv2/base/OptionsContract.d.ts +20 -0
- package/lib/componentsv2/base/OptionsContract.d.ts.map +1 -0
- package/lib/componentsv2/base/OptionsContract.js +107 -0
- package/lib/componentsv2/base/OptionsContract.js.map +1 -0
- package/lib/componentsv2/base/OptionsContract.ts +139 -0
- package/lib/componentsv2/element/component.d.ts +22 -0
- package/lib/componentsv2/element/component.d.ts.map +1 -1
- package/lib/componentsv2/element/component.js +22 -0
- package/lib/componentsv2/element/component.js.map +1 -1
- package/lib/componentsv2/element/component.ts +23 -1
- package/lib/componentsv2/element/engine.d.ts +31 -14
- package/lib/componentsv2/element/engine.d.ts.map +1 -1
- package/lib/componentsv2/element/engine.js +74 -23
- package/lib/componentsv2/element/engine.js.map +1 -1
- package/lib/componentsv2/element/engine.ts +86 -29
- package/lib/componentsv2/element/skin.d.ts.map +1 -1
- package/lib/componentsv2/element/skin.js +7 -10
- package/lib/componentsv2/element/skin.js.map +1 -1
- package/lib/componentsv2/element/skin.ts +7 -11
- package/lib/componentsv2/grid/engine.d.ts +48 -3
- package/lib/componentsv2/grid/engine.d.ts.map +1 -1
- package/lib/componentsv2/grid/engine.js +109 -14
- package/lib/componentsv2/grid/engine.js.map +1 -1
- package/lib/componentsv2/grid/engine.ts +120 -16
- package/lib/componentsv2/index.d.ts +7 -0
- package/lib/componentsv2/index.d.ts.map +1 -1
- package/lib/componentsv2/index.js +2 -0
- package/lib/componentsv2/index.js.map +1 -1
- package/lib/componentsv2/index.ts +2 -0
- package/lib/componentsv2/input/engine.d.ts +48 -5
- package/lib/componentsv2/input/engine.d.ts.map +1 -1
- package/lib/componentsv2/input/engine.js +108 -15
- package/lib/componentsv2/input/engine.js.map +1 -1
- package/lib/componentsv2/input/engine.ts +119 -16
- package/lib/componentsv2/input/skin.d.ts.map +1 -1
- package/lib/componentsv2/input/skin.js +1 -4
- package/lib/componentsv2/input/skin.js.map +1 -1
- package/lib/componentsv2/input/skin.ts +1 -4
- package/lib/componentsv2/list/component.d.ts +28 -6
- package/lib/componentsv2/list/component.d.ts.map +1 -1
- package/lib/componentsv2/list/component.js +28 -6
- package/lib/componentsv2/list/component.js.map +1 -1
- package/lib/componentsv2/list/component.ts +28 -6
- package/lib/componentsv2/list/engine.d.ts +61 -9
- package/lib/componentsv2/list/engine.d.ts.map +1 -1
- package/lib/componentsv2/list/engine.js +156 -95
- package/lib/componentsv2/list/engine.js.map +1 -1
- package/lib/componentsv2/list/engine.ts +175 -108
- package/lib/componentsv2/stubs/ComponentSkin.ts.stub +2 -1
- package/package.json +1 -1
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { OptionsContractSchema, ValidationResult } from './OptionsContract.js';
|
|
1
2
|
export interface JuxServiceContract<TEngine = any> {
|
|
2
3
|
name: string;
|
|
3
4
|
version?: string;
|
|
@@ -24,6 +25,15 @@ type EventListener<T = any> = (data: T) => void;
|
|
|
24
25
|
export declare abstract class BaseEngine<TState extends BaseState, TOptions = any> {
|
|
25
26
|
#private;
|
|
26
27
|
constructor(id: string, options: TOptions);
|
|
28
|
+
/**
|
|
29
|
+
* CONTRACT: Override to define the valid options schema for this engine.
|
|
30
|
+
* Enables option validation with helpful error messages.
|
|
31
|
+
*/
|
|
32
|
+
protected get optionsSchema(): OptionsContractSchema | null;
|
|
33
|
+
/**
|
|
34
|
+
* Access validation results (warnings, errors, normalized options)
|
|
35
|
+
*/
|
|
36
|
+
get validation(): ValidationResult | null;
|
|
27
37
|
/**
|
|
28
38
|
* CONTRACT: Must transform input options into the initial State.
|
|
29
39
|
* This separates "mapping logic" from "construction/startup logic".
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"BaseEngine.d.ts","sourceRoot":"","sources":["BaseEngine.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"BaseEngine.d.ts","sourceRoot":"","sources":["BaseEngine.ts"],"names":[],"mappings":"AAEA,OAAO,EAAmB,qBAAqB,EAAE,gBAAgB,EAAE,MAAM,sBAAsB,CAAC;AAGhG,MAAM,WAAW,kBAAkB,CAAC,OAAO,GAAG,GAAG;IAC7C,IAAI,EAAE,MAAM,CAAC;IACb,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,SAAS,CAAC,EAAE,QAAQ,GAAG,QAAQ,GAAG,WAAW,CAAC;IAC9C,OAAO,EAAE,CAAC,MAAM,EAAE,OAAO,KAAK,IAAI,CAAC;IACnC,SAAS,CAAC,EAAE,CAAC,MAAM,EAAE,OAAO,KAAK,IAAI,CAAC;CACzC;AAED,MAAM,WAAW,SAAS;IACtB,EAAE,EAAE,MAAM,CAAC;IACX,OAAO,EAAE,MAAM,EAAE,CAAC;IAClB,OAAO,EAAE,OAAO,CAAC;IACjB,QAAQ,EAAE,OAAO,CAAC;IAClB,OAAO,EAAE,OAAO,CAAC;IACjB,UAAU,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;CACtC;AAED,KAAK,aAAa,CAAC,CAAC,GAAG,GAAG,IAAI,CAAC,IAAI,EAAE,CAAC,KAAK,IAAI,CAAC;AAEhD;;;;;;GAMG;AACH,8BAAsB,UAAU,CAAC,MAAM,SAAS,SAAS,EAAE,QAAQ,GAAG,GAAG;;gBASzD,EAAE,EAAE,MAAM,EAAE,OAAO,EAAE,QAAQ;IAkBzC;;;OAGG;IACH,SAAS,KAAK,aAAa,IAAI,qBAAqB,GAAG,IAAI,CAE1D;IAED;;OAEG;IACH,IAAI,UAAU,IAAI,gBAAgB,GAAG,IAAI,CAExC;IAED;;;OAGG;IACH,SAAS,CAAC,QAAQ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AAC,IAAI,EAAE,MAAM,GAAG,IAAI;IAoBhC,QAAQ,CAAC,SAAS,EAAE,MAAM,GAAG,IAAI;IASjC,WAAW,CAAC,SAAS,EAAE,MAAM,GAAG,IAAI;IASpC,OAAO,CAAC,SAAS,EAAE,OAAO,GAAG,IAAI;IAMjC,OAAO,CAAC,UAAU,GAAE,OAAc,GAAG,IAAI;IAMzC,OAAO,CAAC,SAAS,GAAE,OAAc,GAAG,IAAI;IAMxC,IAAI,CAAC,GAAG,EAAE,MAAM,EAAE,KAAK,EAAE,MAAM,GAAG,IAAI;CAQzC"}
|
|
@@ -1,17 +1,18 @@
|
|
|
1
|
+
var __classPrivateFieldGet = (this && this.__classPrivateFieldGet) || function (receiver, state, kind, f) {
|
|
2
|
+
if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a getter");
|
|
3
|
+
if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError("Cannot read private member from an object whose class did not declare it");
|
|
4
|
+
return kind === "m" ? f : kind === "a" ? f.call(receiver) : f ? f.value : state.get(receiver);
|
|
5
|
+
};
|
|
1
6
|
var __classPrivateFieldSet = (this && this.__classPrivateFieldSet) || function (receiver, state, value, kind, f) {
|
|
2
7
|
if (kind === "m") throw new TypeError("Private method is not writable");
|
|
3
8
|
if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a setter");
|
|
4
9
|
if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError("Cannot write private member to an object whose class did not declare it");
|
|
5
10
|
return (kind === "a" ? f.call(receiver, value) : f ? f.value = value : state.set(receiver, value)), value;
|
|
6
11
|
};
|
|
7
|
-
var
|
|
8
|
-
if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a getter");
|
|
9
|
-
if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError("Cannot read private member from an object whose class did not declare it");
|
|
10
|
-
return kind === "m" ? f : kind === "a" ? f.call(receiver) : f ? f.value : state.get(receiver);
|
|
11
|
-
};
|
|
12
|
-
var _BaseEngine_state, _BaseEngine_listeners, _BaseEngine_cleanupListeners, _BaseEngine_plugins, _BaseEngine_emitHistory, _BaseEngine_debugMode;
|
|
12
|
+
var _BaseEngine_state, _BaseEngine_listeners, _BaseEngine_cleanupListeners, _BaseEngine_plugins, _BaseEngine_emitHistory, _BaseEngine_debugMode, _BaseEngine_validationResult;
|
|
13
13
|
import { State } from './State.js';
|
|
14
14
|
import { GlobalBus } from './GlobalBus.js';
|
|
15
|
+
import { validateOptions } from './OptionsContract.js';
|
|
15
16
|
/**
|
|
16
17
|
* THE ENGINE AGREEMENT
|
|
17
18
|
*
|
|
@@ -27,10 +28,30 @@ export class BaseEngine {
|
|
|
27
28
|
_BaseEngine_plugins.set(this, new Map());
|
|
28
29
|
_BaseEngine_emitHistory.set(this, []);
|
|
29
30
|
_BaseEngine_debugMode.set(this, false);
|
|
31
|
+
_BaseEngine_validationResult.set(this, null);
|
|
32
|
+
// Validate options if schema is defined
|
|
33
|
+
const schema = this.optionsSchema;
|
|
34
|
+
if (schema) {
|
|
35
|
+
__classPrivateFieldSet(this, _BaseEngine_validationResult, validateOptions(this.constructor.name, options, schema, __classPrivateFieldGet(this, _BaseEngine_debugMode, "f")), "f");
|
|
36
|
+
options = __classPrivateFieldGet(this, _BaseEngine_validationResult, "f").normalized;
|
|
37
|
+
}
|
|
30
38
|
// Enforce the Contract: Child must define how state is born from options
|
|
31
39
|
const initialState = this.prepareState(id, options);
|
|
32
40
|
__classPrivateFieldSet(this, _BaseEngine_state, new State(initialState), "f");
|
|
33
41
|
}
|
|
42
|
+
/**
|
|
43
|
+
* CONTRACT: Override to define the valid options schema for this engine.
|
|
44
|
+
* Enables option validation with helpful error messages.
|
|
45
|
+
*/
|
|
46
|
+
get optionsSchema() {
|
|
47
|
+
return null; // Override in child classes
|
|
48
|
+
}
|
|
49
|
+
/**
|
|
50
|
+
* Access validation results (warnings, errors, normalized options)
|
|
51
|
+
*/
|
|
52
|
+
get validation() {
|
|
53
|
+
return __classPrivateFieldGet(this, _BaseEngine_validationResult, "f");
|
|
54
|
+
}
|
|
34
55
|
get state() {
|
|
35
56
|
return __classPrivateFieldGet(this, _BaseEngine_state, "f").value;
|
|
36
57
|
}
|
|
@@ -254,5 +275,5 @@ export class BaseEngine {
|
|
|
254
275
|
return this;
|
|
255
276
|
}
|
|
256
277
|
}
|
|
257
|
-
_BaseEngine_state = new WeakMap(), _BaseEngine_listeners = new WeakMap(), _BaseEngine_cleanupListeners = new WeakMap(), _BaseEngine_plugins = new WeakMap(), _BaseEngine_emitHistory = new WeakMap(), _BaseEngine_debugMode = new WeakMap();
|
|
278
|
+
_BaseEngine_state = new WeakMap(), _BaseEngine_listeners = new WeakMap(), _BaseEngine_cleanupListeners = new WeakMap(), _BaseEngine_plugins = new WeakMap(), _BaseEngine_emitHistory = new WeakMap(), _BaseEngine_debugMode = new WeakMap(), _BaseEngine_validationResult = new WeakMap();
|
|
258
279
|
//# sourceMappingURL=BaseEngine.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"BaseEngine.js","sourceRoot":"","sources":["BaseEngine.ts"],"names":[],"mappings":";;;;;;;;;;;;AAAA,OAAO,EAAE,KAAK,EAAE,MAAM,YAAY,CAAC;AACnC,OAAO,EAAE,SAAS,EAAE,MAAM,gBAAgB,CAAC;
|
|
1
|
+
{"version":3,"file":"BaseEngine.js","sourceRoot":"","sources":["BaseEngine.ts"],"names":[],"mappings":";;;;;;;;;;;;AAAA,OAAO,EAAE,KAAK,EAAE,MAAM,YAAY,CAAC;AACnC,OAAO,EAAE,SAAS,EAAE,MAAM,gBAAgB,CAAC;AAC3C,OAAO,EAAE,eAAe,EAA2C,MAAM,sBAAsB,CAAC;AAsBhG;;;;;;GAMG;AACH,MAAM,OAAgB,UAAU;IAS5B,YAAY,EAAU,EAAE,OAAiB;QARzC,oCAAsB;QACtB,gCAAa,IAAI,GAAG,EAA8B,EAAC;QACnD,uCAAuC,EAAE,EAAC;QAC1C,8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C,CAAC;QAC5D,IAAI,CAAC,IAAI,CAAC,SAAS,EAAE,EAAE,OAAO,EAAE,SAAS,EAAE,CAAC,CAAC;QAC7C,OAAO,IAAI,CAAC;IAChB,CAAC;IAED,OAAO,CAAC,aAAsB,IAAI;QAC9B,IAAI,CAAC,WAAW,CAAC,EAAE,QAAQ,EAAE,UAAU,EAAqB,CAAC,CAAC;QAC9D,IAAI,CAAC,IAAI,CAAC,UAAU,EAAE,EAAE,QAAQ,EAAE,UAAU,EAAE,CAAC,CAAC;QAChD,OAAO,IAAI,CAAC;IAChB,CAAC;IAED,OAAO,CAAC,YAAqB,IAAI;QAC7B,IAAI,CAAC,WAAW,CAAC,EAAE,OAAO,EAAE,SAAS,EAAqB,CAAC,CAAC;QAC5D,IAAI,CAAC,IAAI,CAAC,SAAS,EAAE,EAAE,OAAO,EAAE,SAAS,EAAE,CAAC,CAAC;QAC7C,OAAO,IAAI,CAAC;IAChB,CAAC;IAED,IAAI,CAAC,GAAW,EAAE,KAAa;QAC3B,MAAM,OAAO,GAAG,IAAI,CAAC,KAAK,CAAC,UAAU,CAAC;QACtC,IAAI,CAAC,WAAW,CAAC;YACb,UAAU,EAAE,EAAE,GAAG,OAAO,EAAE,CAAC,GAAG,CAAC,EAAE,KAAK,EAAE;SACxB,CAAC,CAAC;QACtB,IAAI,CAAC,IAAI,CAAC,WAAW,EAAE,EAAE,GAAG,EAAE,KAAK,EAAE,CAAC,CAAC;QACvC,OAAO,IAAI,CAAC;IAChB,CAAC;CACJ"}
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { State } from './State.js';
|
|
2
2
|
import { GlobalBus } from './GlobalBus.js';
|
|
3
|
+
import { validateOptions, OptionsContractSchema, ValidationResult } from './OptionsContract.js';
|
|
3
4
|
|
|
4
5
|
|
|
5
6
|
export interface JuxServiceContract<TEngine = any> {
|
|
@@ -35,13 +36,41 @@ export abstract class BaseEngine<TState extends BaseState, TOptions = any> {
|
|
|
35
36
|
#plugins = new Map<string, JuxServiceContract>();
|
|
36
37
|
#emitHistory: string[] = [];
|
|
37
38
|
#debugMode = false;
|
|
39
|
+
#validationResult: ValidationResult | null = null;
|
|
38
40
|
|
|
39
41
|
constructor(id: string, options: TOptions) {
|
|
42
|
+
// Validate options if schema is defined
|
|
43
|
+
const schema = this.optionsSchema;
|
|
44
|
+
if (schema) {
|
|
45
|
+
this.#validationResult = validateOptions(
|
|
46
|
+
this.constructor.name,
|
|
47
|
+
options as Record<string, any>,
|
|
48
|
+
schema,
|
|
49
|
+
this.#debugMode
|
|
50
|
+
);
|
|
51
|
+
options = this.#validationResult.normalized as TOptions;
|
|
52
|
+
}
|
|
53
|
+
|
|
40
54
|
// Enforce the Contract: Child must define how state is born from options
|
|
41
55
|
const initialState = this.prepareState(id, options);
|
|
42
56
|
this.#state = new State(initialState);
|
|
43
57
|
}
|
|
44
58
|
|
|
59
|
+
/**
|
|
60
|
+
* CONTRACT: Override to define the valid options schema for this engine.
|
|
61
|
+
* Enables option validation with helpful error messages.
|
|
62
|
+
*/
|
|
63
|
+
protected get optionsSchema(): OptionsContractSchema | null {
|
|
64
|
+
return null; // Override in child classes
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
/**
|
|
68
|
+
* Access validation results (warnings, errors, normalized options)
|
|
69
|
+
*/
|
|
70
|
+
get validation(): ValidationResult | null {
|
|
71
|
+
return this.#validationResult;
|
|
72
|
+
}
|
|
73
|
+
|
|
45
74
|
/**
|
|
46
75
|
* CONTRACT: Must transform input options into the initial State.
|
|
47
76
|
* This separates "mapping logic" from "construction/startup logic".
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
export interface OptionDefinition {
|
|
2
|
+
type: 'string' | 'number' | 'boolean' | 'array' | 'object' | 'function';
|
|
3
|
+
required?: boolean;
|
|
4
|
+
default?: any;
|
|
5
|
+
description?: string;
|
|
6
|
+
aliases?: string[];
|
|
7
|
+
}
|
|
8
|
+
export type OptionsContractSchema = Record<string, OptionDefinition>;
|
|
9
|
+
export interface ValidationResult {
|
|
10
|
+
valid: boolean;
|
|
11
|
+
warnings: string[];
|
|
12
|
+
errors: string[];
|
|
13
|
+
normalized: Record<string, any>;
|
|
14
|
+
}
|
|
15
|
+
/**
|
|
16
|
+
* Validates user-provided options against a defined contract schema.
|
|
17
|
+
* Emits warnings for unknown/misnamed options and errors for type mismatches.
|
|
18
|
+
*/
|
|
19
|
+
export declare function validateOptions<T extends Record<string, any>>(componentName: string, userOptions: Record<string, any>, schema: OptionsContractSchema, debugMode?: boolean): ValidationResult;
|
|
20
|
+
//# sourceMappingURL=OptionsContract.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"OptionsContract.d.ts","sourceRoot":"","sources":["OptionsContract.ts"],"names":[],"mappings":"AAAA,MAAM,WAAW,gBAAgB;IAC7B,IAAI,EAAE,QAAQ,GAAG,QAAQ,GAAG,SAAS,GAAG,OAAO,GAAG,QAAQ,GAAG,UAAU,CAAC;IACxE,QAAQ,CAAC,EAAE,OAAO,CAAC;IACnB,OAAO,CAAC,EAAE,GAAG,CAAC;IACd,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB,OAAO,CAAC,EAAE,MAAM,EAAE,CAAC;CACtB;AAED,MAAM,MAAM,qBAAqB,GAAG,MAAM,CAAC,MAAM,EAAE,gBAAgB,CAAC,CAAC;AAErE,MAAM,WAAW,gBAAgB;IAC7B,KAAK,EAAE,OAAO,CAAC;IACf,QAAQ,EAAE,MAAM,EAAE,CAAC;IACnB,MAAM,EAAE,MAAM,EAAE,CAAC;IACjB,UAAU,EAAE,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,CAAC;CACnC;AAED;;;GAGG;AACH,wBAAgB,eAAe,CAAC,CAAC,SAAS,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,EACzD,aAAa,EAAE,MAAM,EACrB,WAAW,EAAE,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,EAChC,MAAM,EAAE,qBAAqB,EAC7B,SAAS,GAAE,OAAe,GAC3B,gBAAgB,CAqElB"}
|
|
@@ -0,0 +1,107 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Validates user-provided options against a defined contract schema.
|
|
3
|
+
* Emits warnings for unknown/misnamed options and errors for type mismatches.
|
|
4
|
+
*/
|
|
5
|
+
export function validateOptions(componentName, userOptions, schema, debugMode = false) {
|
|
6
|
+
const result = {
|
|
7
|
+
valid: true,
|
|
8
|
+
warnings: [],
|
|
9
|
+
errors: [],
|
|
10
|
+
normalized: {}
|
|
11
|
+
};
|
|
12
|
+
const validKeys = new Set(Object.keys(schema));
|
|
13
|
+
const aliasMap = new Map();
|
|
14
|
+
// Build alias lookup
|
|
15
|
+
for (const [key, def] of Object.entries(schema)) {
|
|
16
|
+
if (def.aliases) {
|
|
17
|
+
def.aliases.forEach(alias => aliasMap.set(alias.toLowerCase(), key));
|
|
18
|
+
}
|
|
19
|
+
}
|
|
20
|
+
// Check for unknown or aliased options
|
|
21
|
+
for (const [key, value] of Object.entries(userOptions)) {
|
|
22
|
+
const lowerKey = key.toLowerCase();
|
|
23
|
+
if (validKeys.has(key)) {
|
|
24
|
+
// Valid key - validate type
|
|
25
|
+
const def = schema[key];
|
|
26
|
+
if (!validateType(value, def.type)) {
|
|
27
|
+
result.errors.push(`[${componentName}] Option "${key}" expects type "${def.type}", got "${typeof value}".`);
|
|
28
|
+
result.valid = false;
|
|
29
|
+
}
|
|
30
|
+
else {
|
|
31
|
+
result.normalized[key] = value;
|
|
32
|
+
}
|
|
33
|
+
}
|
|
34
|
+
else if (aliasMap.has(lowerKey)) {
|
|
35
|
+
// Found an alias - warn and normalize
|
|
36
|
+
const correctKey = aliasMap.get(lowerKey);
|
|
37
|
+
result.warnings.push(`[${componentName}] Option "${key}" is not valid. Did you mean "${correctKey}"?`);
|
|
38
|
+
result.normalized[correctKey] = value;
|
|
39
|
+
}
|
|
40
|
+
else {
|
|
41
|
+
// Unknown option
|
|
42
|
+
const suggestion = findClosestMatch(key, Array.from(validKeys));
|
|
43
|
+
const hint = suggestion ? ` Did you mean "${suggestion}"?` : '';
|
|
44
|
+
result.warnings.push(`[${componentName}] Unknown option "${key}".${hint} Valid options: ${Array.from(validKeys).join(', ')}`);
|
|
45
|
+
}
|
|
46
|
+
}
|
|
47
|
+
// Apply defaults for missing required options
|
|
48
|
+
for (const [key, def] of Object.entries(schema)) {
|
|
49
|
+
if (!(key in result.normalized)) {
|
|
50
|
+
if (def.required && def.default === undefined) {
|
|
51
|
+
result.errors.push(`[${componentName}] Required option "${key}" is missing.`);
|
|
52
|
+
result.valid = false;
|
|
53
|
+
}
|
|
54
|
+
else if (def.default !== undefined) {
|
|
55
|
+
result.normalized[key] = def.default;
|
|
56
|
+
}
|
|
57
|
+
}
|
|
58
|
+
}
|
|
59
|
+
// Log warnings/errors in debug mode
|
|
60
|
+
if (debugMode || result.warnings.length || result.errors.length) {
|
|
61
|
+
result.warnings.forEach(w => console.warn(w));
|
|
62
|
+
result.errors.forEach(e => console.error(e));
|
|
63
|
+
}
|
|
64
|
+
return result;
|
|
65
|
+
}
|
|
66
|
+
function validateType(value, expectedType) {
|
|
67
|
+
if (value === undefined || value === null)
|
|
68
|
+
return true; // Allow optional
|
|
69
|
+
switch (expectedType) {
|
|
70
|
+
case 'string': return typeof value === 'string';
|
|
71
|
+
case 'number': return typeof value === 'number';
|
|
72
|
+
case 'boolean': return typeof value === 'boolean';
|
|
73
|
+
case 'array': return Array.isArray(value);
|
|
74
|
+
case 'object': return typeof value === 'object' && !Array.isArray(value);
|
|
75
|
+
case 'function': return typeof value === 'function';
|
|
76
|
+
default: return true;
|
|
77
|
+
}
|
|
78
|
+
}
|
|
79
|
+
function findClosestMatch(input, candidates) {
|
|
80
|
+
const lower = input.toLowerCase();
|
|
81
|
+
let best = null;
|
|
82
|
+
let bestScore = Infinity;
|
|
83
|
+
for (const candidate of candidates) {
|
|
84
|
+
const score = levenshtein(lower, candidate.toLowerCase());
|
|
85
|
+
if (score < bestScore && score <= 3) { // Max 3 edits
|
|
86
|
+
bestScore = score;
|
|
87
|
+
best = candidate;
|
|
88
|
+
}
|
|
89
|
+
}
|
|
90
|
+
return best;
|
|
91
|
+
}
|
|
92
|
+
function levenshtein(a, b) {
|
|
93
|
+
const matrix = [];
|
|
94
|
+
for (let i = 0; i <= b.length; i++)
|
|
95
|
+
matrix[i] = [i];
|
|
96
|
+
for (let j = 0; j <= a.length; j++)
|
|
97
|
+
matrix[0][j] = j;
|
|
98
|
+
for (let i = 1; i <= b.length; i++) {
|
|
99
|
+
for (let j = 1; j <= a.length; j++) {
|
|
100
|
+
matrix[i][j] = b[i - 1] === a[j - 1]
|
|
101
|
+
? matrix[i - 1][j - 1]
|
|
102
|
+
: Math.min(matrix[i - 1][j - 1] + 1, matrix[i][j - 1] + 1, matrix[i - 1][j] + 1);
|
|
103
|
+
}
|
|
104
|
+
}
|
|
105
|
+
return matrix[b.length][a.length];
|
|
106
|
+
}
|
|
107
|
+
//# sourceMappingURL=OptionsContract.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"OptionsContract.js","sourceRoot":"","sources":["OptionsContract.ts"],"names":[],"mappings":"AAiBA;;;GAGG;AACH,MAAM,UAAU,eAAe,CAC3B,aAAqB,EACrB,WAAgC,EAChC,MAA6B,EAC7B,YAAqB,KAAK;IAE1B,MAAM,MAAM,GAAqB;QAC7B,KAAK,EAAE,IAAI;QACX,QAAQ,EAAE,EAAE;QACZ,MAAM,EAAE,EAAE;QACV,UAAU,EAAE,EAAE;KACjB,CAAC;IAEF,MAAM,SAAS,GAAG,IAAI,GAAG,CAAC,MAAM,CAAC,IAAI,CAAC,MAAM,CAAC,CAAC,CAAC;IAC/C,MAAM,QAAQ,GAAG,IAAI,GAAG,EAAkB,CAAC;IAE3C,qBAAqB;IACrB,KAAK,MAAM,CAAC,GAAG,EAAE,GAAG,CAAC,IAAI,MAAM,CAAC,OAAO,CAAC,MAAM,CAAC,EAAE,CAAC;QAC9C,IAAI,GAAG,CAAC,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C,CAAC,MAAM,CAAC,CAAC;AACtC,CAAC"}
|
|
@@ -0,0 +1,139 @@
|
|
|
1
|
+
export interface OptionDefinition {
|
|
2
|
+
type: 'string' | 'number' | 'boolean' | 'array' | 'object' | 'function';
|
|
3
|
+
required?: boolean;
|
|
4
|
+
default?: any;
|
|
5
|
+
description?: string;
|
|
6
|
+
aliases?: string[]; // Common misspellings or alternate names
|
|
7
|
+
}
|
|
8
|
+
|
|
9
|
+
export type OptionsContractSchema = Record<string, OptionDefinition>;
|
|
10
|
+
|
|
11
|
+
export interface ValidationResult {
|
|
12
|
+
valid: boolean;
|
|
13
|
+
warnings: string[];
|
|
14
|
+
errors: string[];
|
|
15
|
+
normalized: Record<string, any>;
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
/**
|
|
19
|
+
* Validates user-provided options against a defined contract schema.
|
|
20
|
+
* Emits warnings for unknown/misnamed options and errors for type mismatches.
|
|
21
|
+
*/
|
|
22
|
+
export function validateOptions<T extends Record<string, any>>(
|
|
23
|
+
componentName: string,
|
|
24
|
+
userOptions: Record<string, any>,
|
|
25
|
+
schema: OptionsContractSchema,
|
|
26
|
+
debugMode: boolean = false
|
|
27
|
+
): ValidationResult {
|
|
28
|
+
const result: ValidationResult = {
|
|
29
|
+
valid: true,
|
|
30
|
+
warnings: [],
|
|
31
|
+
errors: [],
|
|
32
|
+
normalized: {}
|
|
33
|
+
};
|
|
34
|
+
|
|
35
|
+
const validKeys = new Set(Object.keys(schema));
|
|
36
|
+
const aliasMap = new Map<string, string>();
|
|
37
|
+
|
|
38
|
+
// Build alias lookup
|
|
39
|
+
for (const [key, def] of Object.entries(schema)) {
|
|
40
|
+
if (def.aliases) {
|
|
41
|
+
def.aliases.forEach(alias => aliasMap.set(alias.toLowerCase(), key));
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
// Check for unknown or aliased options
|
|
46
|
+
for (const [key, value] of Object.entries(userOptions)) {
|
|
47
|
+
const lowerKey = key.toLowerCase();
|
|
48
|
+
|
|
49
|
+
if (validKeys.has(key)) {
|
|
50
|
+
// Valid key - validate type
|
|
51
|
+
const def = schema[key];
|
|
52
|
+
if (!validateType(value, def.type)) {
|
|
53
|
+
result.errors.push(
|
|
54
|
+
`[${componentName}] Option "${key}" expects type "${def.type}", got "${typeof value}".`
|
|
55
|
+
);
|
|
56
|
+
result.valid = false;
|
|
57
|
+
} else {
|
|
58
|
+
result.normalized[key] = value;
|
|
59
|
+
}
|
|
60
|
+
} else if (aliasMap.has(lowerKey)) {
|
|
61
|
+
// Found an alias - warn and normalize
|
|
62
|
+
const correctKey = aliasMap.get(lowerKey)!;
|
|
63
|
+
result.warnings.push(
|
|
64
|
+
`[${componentName}] Option "${key}" is not valid. Did you mean "${correctKey}"?`
|
|
65
|
+
);
|
|
66
|
+
result.normalized[correctKey] = value;
|
|
67
|
+
} else {
|
|
68
|
+
// Unknown option
|
|
69
|
+
const suggestion = findClosestMatch(key, Array.from(validKeys));
|
|
70
|
+
const hint = suggestion ? ` Did you mean "${suggestion}"?` : '';
|
|
71
|
+
result.warnings.push(
|
|
72
|
+
`[${componentName}] Unknown option "${key}".${hint} Valid options: ${Array.from(validKeys).join(', ')}`
|
|
73
|
+
);
|
|
74
|
+
}
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
// Apply defaults for missing required options
|
|
78
|
+
for (const [key, def] of Object.entries(schema)) {
|
|
79
|
+
if (!(key in result.normalized)) {
|
|
80
|
+
if (def.required && def.default === undefined) {
|
|
81
|
+
result.errors.push(`[${componentName}] Required option "${key}" is missing.`);
|
|
82
|
+
result.valid = false;
|
|
83
|
+
} else if (def.default !== undefined) {
|
|
84
|
+
result.normalized[key] = def.default;
|
|
85
|
+
}
|
|
86
|
+
}
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
// Log warnings/errors in debug mode
|
|
90
|
+
if (debugMode || result.warnings.length || result.errors.length) {
|
|
91
|
+
result.warnings.forEach(w => console.warn(w));
|
|
92
|
+
result.errors.forEach(e => console.error(e));
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
return result;
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
function validateType(value: any, expectedType: string): boolean {
|
|
99
|
+
if (value === undefined || value === null) return true; // Allow optional
|
|
100
|
+
switch (expectedType) {
|
|
101
|
+
case 'string': return typeof value === 'string';
|
|
102
|
+
case 'number': return typeof value === 'number';
|
|
103
|
+
case 'boolean': return typeof value === 'boolean';
|
|
104
|
+
case 'array': return Array.isArray(value);
|
|
105
|
+
case 'object': return typeof value === 'object' && !Array.isArray(value);
|
|
106
|
+
case 'function': return typeof value === 'function';
|
|
107
|
+
default: return true;
|
|
108
|
+
}
|
|
109
|
+
}
|
|
110
|
+
|
|
111
|
+
function findClosestMatch(input: string, candidates: string[]): string | null {
|
|
112
|
+
const lower = input.toLowerCase();
|
|
113
|
+
let best: string | null = null;
|
|
114
|
+
let bestScore = Infinity;
|
|
115
|
+
|
|
116
|
+
for (const candidate of candidates) {
|
|
117
|
+
const score = levenshtein(lower, candidate.toLowerCase());
|
|
118
|
+
if (score < bestScore && score <= 3) { // Max 3 edits
|
|
119
|
+
bestScore = score;
|
|
120
|
+
best = candidate;
|
|
121
|
+
}
|
|
122
|
+
}
|
|
123
|
+
return best;
|
|
124
|
+
}
|
|
125
|
+
|
|
126
|
+
function levenshtein(a: string, b: string): number {
|
|
127
|
+
const matrix: number[][] = [];
|
|
128
|
+
for (let i = 0; i <= b.length; i++) matrix[i] = [i];
|
|
129
|
+
for (let j = 0; j <= a.length; j++) matrix[0][j] = j;
|
|
130
|
+
|
|
131
|
+
for (let i = 1; i <= b.length; i++) {
|
|
132
|
+
for (let j = 1; j <= a.length; j++) {
|
|
133
|
+
matrix[i][j] = b[i - 1] === a[j - 1]
|
|
134
|
+
? matrix[i - 1][j - 1]
|
|
135
|
+
: Math.min(matrix[i - 1][j - 1] + 1, matrix[i][j - 1] + 1, matrix[i - 1][j] + 1);
|
|
136
|
+
}
|
|
137
|
+
}
|
|
138
|
+
return matrix[b.length][a.length];
|
|
139
|
+
}
|
|
@@ -3,5 +3,27 @@ export type ElementComponent = ElementEngine & {
|
|
|
3
3
|
render: (targetId: string | HTMLElement) => ElementComponent;
|
|
4
4
|
injectCSS: (id: string, cssContent: string) => void;
|
|
5
5
|
};
|
|
6
|
+
/**
|
|
7
|
+
* OPTIONS CONTRACT for Element:
|
|
8
|
+
*
|
|
9
|
+
* | Option | Type | Default | Aliases |
|
|
10
|
+
* |--------------|--------|---------|----------------------------------|
|
|
11
|
+
* | tagName | string | 'div' | tag, element, type |
|
|
12
|
+
* | content | string | '' | text, html, innerHTML, value |
|
|
13
|
+
* | contentType | string | 'text' | type, mode |
|
|
14
|
+
* | inlineStyle | string | '' | style, css, styles |
|
|
15
|
+
*
|
|
16
|
+
* METHODS (match state properties):
|
|
17
|
+
* - .tagName(value) - Set HTML tag
|
|
18
|
+
* - .content(value, type) - Set content with type
|
|
19
|
+
* - .contentType(type) - Set content type
|
|
20
|
+
* - .inlineStyle(css) - Set inline styles
|
|
21
|
+
*
|
|
22
|
+
* CONVENIENCE ALIASES:
|
|
23
|
+
* - .tag(value) → .tagName(value)
|
|
24
|
+
* - .text(value) → .content(value, 'text')
|
|
25
|
+
* - .html(value) → .content(value, 'html')
|
|
26
|
+
* - .style(css) → .inlineStyle(css)
|
|
27
|
+
*/
|
|
6
28
|
export declare function Element(id: string, options?: ElementOptions): ElementComponent;
|
|
7
29
|
//# sourceMappingURL=component.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"component.d.ts","sourceRoot":"","sources":["component.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,aAAa,EAAE,cAAc,EAAE,MAAM,aAAa,CAAC;AAG5D,MAAM,MAAM,gBAAgB,GAAG,aAAa,GAAG;IAC3C,MAAM,EAAE,CAAC,QAAQ,EAAE,MAAM,GAAG,WAAW,KAAK,gBAAgB,CAAC;IAC7D,SAAS,EAAE,CAAC,EAAE,EAAE,MAAM,EAAE,UAAU,EAAE,MAAM,KAAK,IAAI,CAAC;CACvD,CAAC;AAEF,wBAAgB,OAAO,CAAC,EAAE,EAAE,MAAM,EAAE,OAAO,GAAE,cAAmB,GAAG,gBAAgB,CAuBlF"}
|
|
1
|
+
{"version":3,"file":"component.d.ts","sourceRoot":"","sources":["component.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,aAAa,EAAE,cAAc,EAAE,MAAM,aAAa,CAAC;AAG5D,MAAM,MAAM,gBAAgB,GAAG,aAAa,GAAG;IAC3C,MAAM,EAAE,CAAC,QAAQ,EAAE,MAAM,GAAG,WAAW,KAAK,gBAAgB,CAAC;IAC7D,SAAS,EAAE,CAAC,EAAE,EAAE,MAAM,EAAE,UAAU,EAAE,MAAM,KAAK,IAAI,CAAC;CACvD,CAAC;AAEF;;;;;;;;;;;;;;;;;;;;;GAqBG;AACH,wBAAgB,OAAO,CAAC,EAAE,EAAE,MAAM,EAAE,OAAO,GAAE,cAAmB,GAAG,gBAAgB,CAuBlF"}
|
|
@@ -1,5 +1,27 @@
|
|
|
1
1
|
import { ElementEngine } from './engine.js';
|
|
2
2
|
import { ElementSkin } from './skin.js';
|
|
3
|
+
/**
|
|
4
|
+
* OPTIONS CONTRACT for Element:
|
|
5
|
+
*
|
|
6
|
+
* | Option | Type | Default | Aliases |
|
|
7
|
+
* |--------------|--------|---------|----------------------------------|
|
|
8
|
+
* | tagName | string | 'div' | tag, element, type |
|
|
9
|
+
* | content | string | '' | text, html, innerHTML, value |
|
|
10
|
+
* | contentType | string | 'text' | type, mode |
|
|
11
|
+
* | inlineStyle | string | '' | style, css, styles |
|
|
12
|
+
*
|
|
13
|
+
* METHODS (match state properties):
|
|
14
|
+
* - .tagName(value) - Set HTML tag
|
|
15
|
+
* - .content(value, type) - Set content with type
|
|
16
|
+
* - .contentType(type) - Set content type
|
|
17
|
+
* - .inlineStyle(css) - Set inline styles
|
|
18
|
+
*
|
|
19
|
+
* CONVENIENCE ALIASES:
|
|
20
|
+
* - .tag(value) → .tagName(value)
|
|
21
|
+
* - .text(value) → .content(value, 'text')
|
|
22
|
+
* - .html(value) → .content(value, 'html')
|
|
23
|
+
* - .style(css) → .inlineStyle(css)
|
|
24
|
+
*/
|
|
3
25
|
export function Element(id, options = {}) {
|
|
4
26
|
const engine = new ElementEngine(id, options);
|
|
5
27
|
if (typeof window !== 'undefined') {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"component.js","sourceRoot":"","sources":["component.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,aAAa,EAAkB,MAAM,aAAa,CAAC;AAC5D,OAAO,EAAE,WAAW,EAAE,MAAM,WAAW,CAAC;AAOxC,MAAM,UAAU,OAAO,CAAC,EAAU,EAAE,UAA0B,EAAE;IAC5D,MAAM,MAAM,GAAG,IAAI,aAAa,CAAC,EAAE,EAAE,OAAO,CAAC,CAAC;IAE9C,IAAI,OAAO,MAAM,KAAK,WAAW,EAAE,CAAC;QAChC,aAAa;QACb,MAAM,CAAC,UAAU,GAAG,MAAM,CAAC,UAAU,IAAI,EAAE,CAAC;QAC5C,aAAa;QACb,MAAM,CAAC,UAAU,CAAC,EAAE,CAAC,GAAG,MAAM,CAAC;IACnC,CAAC;IAED,MAAM,IAAI,GAAG,IAAI,WAAW,CAAC,MAAM,CAAC,CAAC;IAErC,aAAa;IACb,MAAM,CAAC,MAAM,GAAG,CAAC,QAA8B,EAAE,EAAE;QAC/C,MAAM,MAAM,GAAG,OAAO,QAAQ,KAAK,QAAQ,CAAC,CAAC,CAAC,QAAQ,CAAC,cAAc,CAAC,QAAQ,CAAC,CAAC,CAAC,CAAC,QAAQ,CAAC;QAC3F,IAAI,MAAM;YAAE,IAAI,CAAC,UAAU,CAAC,MAAM,CAAC,CAAC;QACpC,OAAO,MAA0B,CAAC;IACtC,CAAC,CAAC;IAEF,aAAa;IACb,MAAM,CAAC,SAAS,GAAG,CAAC,
|
|
1
|
+
{"version":3,"file":"component.js","sourceRoot":"","sources":["component.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,aAAa,EAAkB,MAAM,aAAa,CAAC;AAC5D,OAAO,EAAE,WAAW,EAAE,MAAM,WAAW,CAAC;AAOxC;;;;;;;;;;;;;;;;;;;;;GAqBG;AACH,MAAM,UAAU,OAAO,CAAC,EAAU,EAAE,UAA0B,EAAE;IAC5D,MAAM,MAAM,GAAG,IAAI,aAAa,CAAC,EAAE,EAAE,OAAO,CAAC,CAAC;IAE9C,IAAI,OAAO,MAAM,KAAK,WAAW,EAAE,CAAC;QAChC,aAAa;QACb,MAAM,CAAC,UAAU,GAAG,MAAM,CAAC,UAAU,IAAI,EAAE,CAAC;QAC5C,aAAa;QACb,MAAM,CAAC,UAAU,CAAC,EAAE,CAAC,GAAG,MAAM,CAAC;IACnC,CAAC;IAED,MAAM,IAAI,GAAG,IAAI,WAAW,CAAC,MAAM,CAAC,CAAC;IAErC,aAAa;IACb,MAAM,CAAC,MAAM,GAAG,CAAC,QAA8B,EAAE,EAAE;QAC/C,MAAM,MAAM,GAAG,OAAO,QAAQ,KAAK,QAAQ,CAAC,CAAC,CAAC,QAAQ,CAAC,cAAc,CAAC,QAAQ,CAAC,CAAC,CAAC,CAAC,QAAQ,CAAC;QAC3F,IAAI,MAAM;YAAE,IAAI,CAAC,UAAU,CAAC,MAAM,CAAC,CAAC;QACpC,OAAO,MAA0B,CAAC;IACtC,CAAC,CAAC;IAEF,aAAa;IACb,MAAM,CAAC,SAAS,GAAG,CAAC,EAAU,EAAE,GAAW,EAAE,EAAE,CAAC,IAAI,CAAC,SAAS,CAAC,EAAE,EAAE,GAAG,CAAC,CAAC;IAExE,OAAO,MAA0B,CAAC;AACtC,CAAC"}
|
|
@@ -6,6 +6,28 @@ export type ElementComponent = ElementEngine & {
|
|
|
6
6
|
injectCSS: (id: string, cssContent: string) => void;
|
|
7
7
|
};
|
|
8
8
|
|
|
9
|
+
/**
|
|
10
|
+
* OPTIONS CONTRACT for Element:
|
|
11
|
+
*
|
|
12
|
+
* | Option | Type | Default | Aliases |
|
|
13
|
+
* |--------------|--------|---------|----------------------------------|
|
|
14
|
+
* | tagName | string | 'div' | tag, element, type |
|
|
15
|
+
* | content | string | '' | text, html, innerHTML, value |
|
|
16
|
+
* | contentType | string | 'text' | type, mode |
|
|
17
|
+
* | inlineStyle | string | '' | style, css, styles |
|
|
18
|
+
*
|
|
19
|
+
* METHODS (match state properties):
|
|
20
|
+
* - .tagName(value) - Set HTML tag
|
|
21
|
+
* - .content(value, type) - Set content with type
|
|
22
|
+
* - .contentType(type) - Set content type
|
|
23
|
+
* - .inlineStyle(css) - Set inline styles
|
|
24
|
+
*
|
|
25
|
+
* CONVENIENCE ALIASES:
|
|
26
|
+
* - .tag(value) → .tagName(value)
|
|
27
|
+
* - .text(value) → .content(value, 'text')
|
|
28
|
+
* - .html(value) → .content(value, 'html')
|
|
29
|
+
* - .style(css) → .inlineStyle(css)
|
|
30
|
+
*/
|
|
9
31
|
export function Element(id: string, options: ElementOptions = {}): ElementComponent {
|
|
10
32
|
const engine = new ElementEngine(id, options);
|
|
11
33
|
|
|
@@ -26,7 +48,7 @@ export function Element(id: string, options: ElementOptions = {}): ElementCompon
|
|
|
26
48
|
};
|
|
27
49
|
|
|
28
50
|
// @ts-ignore
|
|
29
|
-
engine.injectCSS = (id, css) => skin.injectCSS(id, css);
|
|
51
|
+
engine.injectCSS = (id: string, css: string) => skin.injectCSS(id, css);
|
|
30
52
|
|
|
31
53
|
return engine as ElementComponent;
|
|
32
54
|
}
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { BaseEngine, BaseState } from '../base/BaseEngine.js';
|
|
2
|
+
import { OptionsContractSchema } from '../base/OptionsContract.js';
|
|
2
3
|
export interface ElementState extends BaseState {
|
|
3
4
|
tagName: string;
|
|
4
5
|
content: string | null;
|
|
@@ -6,37 +7,53 @@ export interface ElementState extends BaseState {
|
|
|
6
7
|
inlineStyle: string;
|
|
7
8
|
}
|
|
8
9
|
export interface ElementOptions {
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
10
|
+
tagName?: string;
|
|
11
|
+
content?: string;
|
|
12
|
+
contentType?: 'text' | 'html';
|
|
13
|
+
inlineStyle?: string;
|
|
13
14
|
}
|
|
14
15
|
export declare class ElementEngine extends BaseEngine<ElementState, ElementOptions> {
|
|
15
16
|
constructor(id: string, options?: ElementOptions);
|
|
17
|
+
/**
|
|
18
|
+
* OPTIONS CONTRACT
|
|
19
|
+
* Defines valid options with types, defaults, and aliases for common mistakes.
|
|
20
|
+
*/
|
|
21
|
+
protected get optionsSchema(): OptionsContractSchema;
|
|
16
22
|
protected prepareState(id: string, options: ElementOptions): ElementState;
|
|
17
23
|
/**
|
|
18
|
-
* Set the HTML
|
|
24
|
+
* Set the HTML tag name (e.g., 'div', 'span', 'h1', 'section')
|
|
25
|
+
* Method name matches state property: tagName
|
|
19
26
|
*/
|
|
20
|
-
|
|
27
|
+
tagName(value: string): this;
|
|
21
28
|
/**
|
|
22
|
-
* Set
|
|
29
|
+
* Set content with explicit type
|
|
30
|
+
* Method name matches state property: content
|
|
23
31
|
*/
|
|
24
|
-
|
|
32
|
+
content(value: string, type?: 'text' | 'html'): this;
|
|
33
|
+
/**
|
|
34
|
+
* Set content type
|
|
35
|
+
* Method name matches state property: contentType
|
|
36
|
+
*/
|
|
37
|
+
contentType(type: 'text' | 'html'): this;
|
|
25
38
|
/**
|
|
26
|
-
* Set
|
|
39
|
+
* Set inline styles (e.g., "color: red; margin: 10px;")
|
|
40
|
+
* Method name matches state property: inlineStyle
|
|
27
41
|
*/
|
|
42
|
+
inlineStyle(cssText: string): this;
|
|
43
|
+
/** @alias for tagName() */
|
|
44
|
+
tag(value: string): this;
|
|
45
|
+
/** @alias for content(value, 'text') */
|
|
46
|
+
text(value: string): this;
|
|
47
|
+
/** @alias for content(value, 'html') */
|
|
28
48
|
html(value: string): this;
|
|
49
|
+
/** @alias for inlineStyle() */
|
|
50
|
+
style(cssText: string): this;
|
|
29
51
|
/**
|
|
30
52
|
* Append raw HTML to existing content
|
|
31
53
|
*/
|
|
32
54
|
appendHtml(value: string): this;
|
|
33
|
-
/**
|
|
34
|
-
* Set inline styles (e.g. "color: red; margin: 10px;")
|
|
35
|
-
*/
|
|
36
|
-
style(cssText: string): this;
|
|
37
55
|
/**
|
|
38
56
|
* Receives RAW DOM events from the Skin and emits them to listeners.
|
|
39
|
-
* This keeps the 'emit' logic encapsulated within the Engine.
|
|
40
57
|
*/
|
|
41
58
|
handleEvent(eventName: string, content: any): void;
|
|
42
59
|
}
|