assign-gingerly 0.0.73 → 0.0.74
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/README.md +29 -92
- package/assignFeatures.js +145 -254
- package/assignFeatures.ts +713 -837
- package/defineWithFeatures.js +12 -72
- package/defineWithFeatures.ts +92 -167
- package/enhanceAll.js +8 -4
- package/enhanceAll.ts +8 -7
- package/inferencer/types/assign-gingerly/types.d.ts +2 -1
- package/inferencer/types/font-face-feature/types.d.ts +9 -0
- package/package.json +9 -1
- package/processHandlerCommands.js +11 -34
- package/processHandlerCommands.ts +13 -40
- package/resolveAndAssignFeatures.js +9 -40
- package/resolveAndAssignFeatures.ts +43 -79
- package/types/assign-gingerly/types.d.ts +2 -16
|
@@ -1,12 +1,12 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* resolveAndAssignFeatures -
|
|
2
|
+
* resolveAndAssignFeatures - Thin wrapper around assignFeatures for backward compatibility.
|
|
3
3
|
*
|
|
4
|
-
*
|
|
5
|
-
*
|
|
6
|
-
*
|
|
4
|
+
* Resolves all configured spawns (including async fallback spawns and string import paths)
|
|
5
|
+
* and installs feature getters on the class prototype, then delegates to the registry's
|
|
6
|
+
* assignFeatures implementation.
|
|
7
7
|
*
|
|
8
|
-
* This
|
|
9
|
-
*
|
|
8
|
+
* This is kept as a convenience entry point for callers that already await this function.
|
|
9
|
+
* The actual resolution logic lives in assignFeatures.
|
|
10
10
|
*
|
|
11
11
|
* @example
|
|
12
12
|
* import { resolveAndAssignFeatures } from 'assign-gingerly/resolveAndAssignFeatures.js';
|
|
@@ -22,46 +22,15 @@
|
|
|
22
22
|
* }
|
|
23
23
|
* });
|
|
24
24
|
*/
|
|
25
|
+
import { assignFeatures } from './assignFeatures.js';
|
|
25
26
|
/**
|
|
26
|
-
*
|
|
27
|
-
*/
|
|
28
|
-
function isAsyncSpawn(fn) {
|
|
29
|
-
if (typeof fn !== 'function')
|
|
30
|
-
return false;
|
|
31
|
-
if (fn.constructor.name === 'AsyncFunction')
|
|
32
|
-
return true;
|
|
33
|
-
if (fn.prototype === undefined)
|
|
34
|
-
return true;
|
|
35
|
-
return false;
|
|
36
|
-
}
|
|
37
|
-
/**
|
|
38
|
-
* Resolves async fallback spawns for features that don't have an explicit spawn,
|
|
39
|
-
* then calls assignFeatures on the registry.
|
|
27
|
+
* Resolves all configured spawns and calls assignFeatures on the registry.
|
|
40
28
|
*
|
|
41
29
|
* @param ElementClass - The custom element class (must have static supportedFeatures)
|
|
42
30
|
* @param featuresConfig - Feature configurations (spawn will be resolved from fallbackSpawn if missing)
|
|
43
31
|
* @param registry - Optional CustomElementRegistry (defaults to global customElements)
|
|
44
32
|
*/
|
|
45
33
|
export async function resolveAndAssignFeatures(ElementClass, featuresConfig, registry) {
|
|
46
|
-
const supportedFeatures = ElementClass.supportedFeatures;
|
|
47
|
-
if (!supportedFeatures) {
|
|
48
|
-
throw new Error(`resolveAndAssignFeatures: ${ElementClass.name || 'constructor'} does not define static supportedFeatures`);
|
|
49
|
-
}
|
|
50
|
-
// Resolve async fallback spawns in parallel for features without explicit spawn
|
|
51
|
-
await Promise.all(Object.entries(featuresConfig).map(async ([key, featureConfig]) => {
|
|
52
|
-
// Skip if spawn is already provided
|
|
53
|
-
if (featureConfig.spawn)
|
|
54
|
-
return;
|
|
55
|
-
const optIn = supportedFeatures[key];
|
|
56
|
-
if (!optIn?.fallbackSpawn)
|
|
57
|
-
return;
|
|
58
|
-
let spawn = optIn.fallbackSpawn;
|
|
59
|
-
if (isAsyncSpawn(spawn)) {
|
|
60
|
-
spawn = await spawn();
|
|
61
|
-
}
|
|
62
|
-
featureConfig.spawn = spawn;
|
|
63
|
-
}));
|
|
64
|
-
// Call assignFeatures on the registry
|
|
65
34
|
const reg = registry || customElements;
|
|
66
|
-
await
|
|
35
|
+
await assignFeatures(ElementClass, featuresConfig, reg.featuresRegistry);
|
|
67
36
|
}
|
|
@@ -1,79 +1,43 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* resolveAndAssignFeatures -
|
|
3
|
-
*
|
|
4
|
-
*
|
|
5
|
-
*
|
|
6
|
-
*
|
|
7
|
-
*
|
|
8
|
-
* This
|
|
9
|
-
*
|
|
10
|
-
*
|
|
11
|
-
* @example
|
|
12
|
-
* import { resolveAndAssignFeatures } from 'assign-gingerly/resolveAndAssignFeatures.js';
|
|
13
|
-
*
|
|
14
|
-
* await resolveAndAssignFeatures(MyElement, {
|
|
15
|
-
* roundabout: {
|
|
16
|
-
* customData: {...},
|
|
17
|
-
* withAttrs: {...},
|
|
18
|
-
* callbackForwarding: ['connectedCallback']
|
|
19
|
-
* },
|
|
20
|
-
* faceUp: {
|
|
21
|
-
* callbackForwarding: ['connectedCallback', 'disconnectedCallback']
|
|
22
|
-
* }
|
|
23
|
-
* });
|
|
24
|
-
*/
|
|
25
|
-
|
|
26
|
-
import { FeatureConfigsMap
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
* @param registry - Optional CustomElementRegistry (defaults to global customElements)
|
|
45
|
-
*/
|
|
46
|
-
export async function resolveAndAssignFeatures(
|
|
47
|
-
ElementClass: Function,
|
|
48
|
-
featuresConfig: FeatureConfigsMap,
|
|
49
|
-
registry?: any
|
|
50
|
-
): Promise<void> {
|
|
51
|
-
const supportedFeatures: SupportedFeaturesMap | undefined = (ElementClass as any).supportedFeatures;
|
|
52
|
-
|
|
53
|
-
if (!supportedFeatures) {
|
|
54
|
-
throw new Error(
|
|
55
|
-
`resolveAndAssignFeatures: ${(ElementClass as any).name || 'constructor'} does not define static supportedFeatures`
|
|
56
|
-
);
|
|
57
|
-
}
|
|
58
|
-
|
|
59
|
-
// Resolve async fallback spawns in parallel for features without explicit spawn
|
|
60
|
-
await Promise.all(
|
|
61
|
-
Object.entries(featuresConfig).map(async ([key, featureConfig]) => {
|
|
62
|
-
// Skip if spawn is already provided
|
|
63
|
-
if (featureConfig.spawn) return;
|
|
64
|
-
|
|
65
|
-
const optIn = supportedFeatures[key];
|
|
66
|
-
if (!optIn?.fallbackSpawn) return;
|
|
67
|
-
|
|
68
|
-
let spawn = optIn.fallbackSpawn;
|
|
69
|
-
if (isAsyncSpawn(spawn)) {
|
|
70
|
-
spawn = await (spawn as () => Promise<any>)();
|
|
71
|
-
}
|
|
72
|
-
(featureConfig as any).spawn = spawn;
|
|
73
|
-
})
|
|
74
|
-
);
|
|
75
|
-
|
|
76
|
-
// Call assignFeatures on the registry
|
|
77
|
-
const reg = registry || customElements;
|
|
78
|
-
await reg.assignFeatures(ElementClass, featuresConfig);
|
|
79
|
-
}
|
|
1
|
+
/**
|
|
2
|
+
* resolveAndAssignFeatures - Thin wrapper around assignFeatures for backward compatibility.
|
|
3
|
+
*
|
|
4
|
+
* Resolves all configured spawns (including async fallback spawns and string import paths)
|
|
5
|
+
* and installs feature getters on the class prototype, then delegates to the registry's
|
|
6
|
+
* assignFeatures implementation.
|
|
7
|
+
*
|
|
8
|
+
* This is kept as a convenience entry point for callers that already await this function.
|
|
9
|
+
* The actual resolution logic lives in assignFeatures.
|
|
10
|
+
*
|
|
11
|
+
* @example
|
|
12
|
+
* import { resolveAndAssignFeatures } from 'assign-gingerly/resolveAndAssignFeatures.js';
|
|
13
|
+
*
|
|
14
|
+
* await resolveAndAssignFeatures(MyElement, {
|
|
15
|
+
* roundabout: {
|
|
16
|
+
* customData: {...},
|
|
17
|
+
* withAttrs: {...},
|
|
18
|
+
* callbackForwarding: ['connectedCallback']
|
|
19
|
+
* },
|
|
20
|
+
* faceUp: {
|
|
21
|
+
* callbackForwarding: ['connectedCallback', 'disconnectedCallback']
|
|
22
|
+
* }
|
|
23
|
+
* });
|
|
24
|
+
*/
|
|
25
|
+
|
|
26
|
+
import { FeatureConfigsMap } from './types/assign-gingerly/types.js';
|
|
27
|
+
import { assignFeatures } from './assignFeatures.js';
|
|
28
|
+
|
|
29
|
+
/**
|
|
30
|
+
* Resolves all configured spawns and calls assignFeatures on the registry.
|
|
31
|
+
*
|
|
32
|
+
* @param ElementClass - The custom element class (must have static supportedFeatures)
|
|
33
|
+
* @param featuresConfig - Feature configurations (spawn will be resolved from fallbackSpawn if missing)
|
|
34
|
+
* @param registry - Optional CustomElementRegistry (defaults to global customElements)
|
|
35
|
+
*/
|
|
36
|
+
export async function resolveAndAssignFeatures(
|
|
37
|
+
ElementClass: Function,
|
|
38
|
+
featuresConfig: FeatureConfigsMap,
|
|
39
|
+
registry?: any
|
|
40
|
+
): Promise<void> {
|
|
41
|
+
const reg = registry || customElements;
|
|
42
|
+
await assignFeatures(ElementClass, featuresConfig, reg.featuresRegistry);
|
|
43
|
+
}
|
|
@@ -591,21 +591,6 @@ export interface SupportedFeatureConfig {
|
|
|
591
591
|
callbackForwarding?: string[];
|
|
592
592
|
}
|
|
593
593
|
|
|
594
|
-
/**
|
|
595
|
-
* Class-level configuration for the features system.
|
|
596
|
-
* Declared as `static featuresConfig` on the class.
|
|
597
|
-
*/
|
|
598
|
-
export interface FeaturesClassConfig {
|
|
599
|
-
/**
|
|
600
|
-
* Lifecycle method configuration.
|
|
601
|
-
* true = install 'whenFeatureReady' method.
|
|
602
|
-
* Object = custom method name.
|
|
603
|
-
*/
|
|
604
|
-
lifecycleKeys?: true | {
|
|
605
|
-
whenFeatureReady?: string;
|
|
606
|
-
};
|
|
607
|
-
}
|
|
608
|
-
|
|
609
594
|
/**
|
|
610
595
|
* Configuration for a feature passed to assignFeatures.
|
|
611
596
|
*/
|
|
@@ -615,7 +600,8 @@ export interface FeatureConfig {
|
|
|
615
600
|
*/
|
|
616
601
|
spawn?:
|
|
617
602
|
| { new(hostElement: any, ctx: FeatureSpawnContext, initVals?: any): any }
|
|
618
|
-
| (() => Promise<{ new(hostElement: any, ctx: FeatureSpawnContext, initVals?: any): any }>)
|
|
603
|
+
| (() => Promise<{ new(hostElement: any, ctx: FeatureSpawnContext, initVals?: any): any }>)
|
|
604
|
+
| string // import path or builtIns.* alias
|
|
619
605
|
|
|
620
606
|
/** Attribute patterns for parsing element attributes into initVals. */
|
|
621
607
|
withAttrs?: AttrPatterns<any>;
|