@cratis/scene.react 4.3.0 → 4.4.0
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/core/CoreNavigationBar.tsx +8 -2
- package/dist/cjs/core/CoreNavigationBar.js +13 -3
- package/dist/cjs/core/CoreNavigationBar.js.map +1 -1
- package/dist/cjs/icons/IconAdapterContext.js +21 -0
- package/dist/cjs/icons/IconAdapterContext.js.map +1 -0
- package/dist/cjs/icons/IconAdapterRegistry.js +45 -0
- package/dist/cjs/icons/IconAdapterRegistry.js.map +1 -0
- package/dist/cjs/icons/SceneIcon.js +42 -0
- package/dist/cjs/icons/SceneIcon.js.map +1 -0
- package/dist/cjs/icons/useIconGlyph.js +86 -0
- package/dist/cjs/icons/useIconGlyph.js.map +1 -0
- package/dist/cjs/index.js +11 -0
- package/dist/cjs/index.js.map +1 -1
- package/dist/cjs/packages/ScenePackageBundle.js +41 -0
- package/dist/cjs/packages/ScenePackageBundle.js.map +1 -1
- package/dist/esm/core/CoreNavigationBar.d.ts.map +1 -1
- package/dist/esm/core/CoreNavigationBar.js +14 -4
- package/dist/esm/core/CoreNavigationBar.js.map +1 -1
- package/dist/esm/icons/IconAdapter.d.ts +13 -0
- package/dist/esm/icons/IconAdapter.d.ts.map +1 -0
- package/dist/esm/icons/IconAdapter.js +2 -0
- package/dist/esm/icons/IconAdapter.js.map +1 -0
- package/dist/esm/icons/IconAdapterContext.d.ts +8 -0
- package/dist/esm/icons/IconAdapterContext.d.ts.map +1 -0
- package/dist/esm/icons/IconAdapterContext.js +18 -0
- package/dist/esm/icons/IconAdapterContext.js.map +1 -0
- package/dist/esm/icons/IconAdapterRegistry.d.ts +9 -0
- package/dist/esm/icons/IconAdapterRegistry.d.ts.map +1 -0
- package/dist/esm/icons/IconAdapterRegistry.js +42 -0
- package/dist/esm/icons/IconAdapterRegistry.js.map +1 -0
- package/dist/esm/icons/IconLibraryBundle.d.ts +7 -0
- package/dist/esm/icons/IconLibraryBundle.d.ts.map +1 -0
- package/dist/esm/icons/IconLibraryBundle.js +2 -0
- package/dist/esm/icons/IconLibraryBundle.js.map +1 -0
- package/dist/esm/icons/SceneIcon.d.ts +14 -0
- package/dist/esm/icons/SceneIcon.d.ts.map +1 -0
- package/dist/esm/icons/SceneIcon.js +40 -0
- package/dist/esm/icons/SceneIcon.js.map +1 -0
- package/dist/esm/icons/index.d.ts +7 -0
- package/dist/esm/icons/index.d.ts.map +1 -0
- package/dist/esm/icons/index.js +7 -0
- package/dist/esm/icons/index.js.map +1 -0
- package/dist/esm/icons/useIconGlyph.d.ts +14 -0
- package/dist/esm/icons/useIconGlyph.d.ts.map +1 -0
- package/dist/esm/icons/useIconGlyph.js +84 -0
- package/dist/esm/icons/useIconGlyph.js.map +1 -0
- package/dist/esm/index.d.ts +1 -0
- package/dist/esm/index.d.ts.map +1 -1
- package/dist/esm/index.js +5 -1
- package/dist/esm/index.js.map +1 -1
- package/dist/esm/packages/ScenePackageBundle.d.ts +4 -0
- package/dist/esm/packages/ScenePackageBundle.d.ts.map +1 -1
- package/dist/esm/packages/ScenePackageBundle.js +42 -2
- package/dist/esm/packages/ScenePackageBundle.js.map +1 -1
- package/dist/esm/tsconfig.tsbuildinfo +1 -1
- package/icons/IconAdapter.ts +52 -0
- package/icons/IconAdapterContext.tsx +21 -0
- package/icons/IconAdapterRegistry.ts +50 -0
- package/icons/IconLibraryBundle.ts +25 -0
- package/icons/SceneIcon.tsx +73 -0
- package/icons/index.ts +9 -0
- package/icons/useIconGlyph.ts +79 -0
- package/index.ts +1 -0
- package/package.json +5 -5
- package/packages/ScenePackageBundle.ts +58 -1
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import { ComponentType } from 'react';
|
|
2
|
+
import { IconReference } from '@cratis/scene.model';
|
|
3
|
+
export interface IconGlyphProps {
|
|
4
|
+
size: number | string;
|
|
5
|
+
color: string;
|
|
6
|
+
className?: string;
|
|
7
|
+
}
|
|
8
|
+
export type IconGlyph = ComponentType<IconGlyphProps>;
|
|
9
|
+
export interface IconAdapter {
|
|
10
|
+
library: string;
|
|
11
|
+
loadGlyph(reference: IconReference): Promise<IconGlyph | undefined> | IconGlyph | undefined;
|
|
12
|
+
}
|
|
13
|
+
//# sourceMappingURL=IconAdapter.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"IconAdapter.d.ts","sourceRoot":"","sources":["../../../icons/IconAdapter.ts"],"names":[],"mappings":"AAGA,OAAO,EAAE,aAAa,EAAE,MAAM,OAAO,CAAC;AACtC,OAAO,EAAE,aAAa,EAAE,MAAM,qBAAqB,CAAC;AAMpD,MAAM,WAAW,cAAc;IAI3B,IAAI,EAAE,MAAM,GAAG,MAAM,CAAC;IAKtB,KAAK,EAAE,MAAM,CAAC;IAKd,SAAS,CAAC,EAAE,MAAM,CAAC;CACtB;AAKD,MAAM,MAAM,SAAS,GAAG,aAAa,CAAC,cAAc,CAAC,CAAC;AAWtD,MAAM,WAAW,WAAW;IAIxB,OAAO,EAAE,MAAM,CAAC;IAKhB,SAAS,CAAC,SAAS,EAAE,aAAa,GAAG,OAAO,CAAC,SAAS,GAAG,SAAS,CAAC,GAAG,SAAS,GAAG,SAAS,CAAC;CAC/F"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"IconAdapter.js","sourceRoot":"","sources":["../../../icons/IconAdapter.ts"],"names":[],"mappings":""}
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import { ReactNode } from 'react';
|
|
2
|
+
import { IconAdapterRegistry } from './IconAdapterRegistry';
|
|
3
|
+
export declare const IconAdapterProvider: ({ registry, children }: {
|
|
4
|
+
registry: IconAdapterRegistry;
|
|
5
|
+
children?: ReactNode;
|
|
6
|
+
}) => import("react").JSX.Element;
|
|
7
|
+
export declare function useIconAdapters(): IconAdapterRegistry | undefined;
|
|
8
|
+
//# sourceMappingURL=IconAdapterContext.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"IconAdapterContext.d.ts","sourceRoot":"","sources":["../../../icons/IconAdapterContext.tsx"],"names":[],"mappings":"AAGA,OAAO,EAAE,SAAS,EAA6B,MAAM,OAAO,CAAC;AAC7D,OAAO,EAAE,mBAAmB,EAAE,MAAM,uBAAuB,CAAC;AAO5D,eAAO,MAAM,mBAAmB,2BAA4B;IAAE,QAAQ,EAAE,mBAAmB,CAAC;IAAC,QAAQ,CAAC,EAAE,SAAS,CAAA;CAAE,gCAElH,CAAC;AAKF,wBAAgB,eAAe,IAAI,mBAAmB,GAAG,SAAS,CAEjE"}
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import { jsx } from 'react/jsx-runtime';
|
|
2
|
+
import { useContext, createContext } from 'react';
|
|
3
|
+
|
|
4
|
+
const IconAdapterContext = /*#__PURE__*/ createContext(undefined);
|
|
5
|
+
/**
|
|
6
|
+
* Supplies the icon adapters every `SceneIcon` below it renders through.
|
|
7
|
+
*/ const IconAdapterProvider = ({ registry, children })=>/*#__PURE__*/ jsx(IconAdapterContext.Provider, {
|
|
8
|
+
value: registry,
|
|
9
|
+
children: children
|
|
10
|
+
});
|
|
11
|
+
/**
|
|
12
|
+
* The icon adapters in scope, or `undefined` outside an {@link IconAdapterProvider}.
|
|
13
|
+
*/ function useIconAdapters() {
|
|
14
|
+
return useContext(IconAdapterContext);
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
export { IconAdapterProvider, useIconAdapters };
|
|
18
|
+
//# sourceMappingURL=IconAdapterContext.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"IconAdapterContext.js","sources":["../../../icons/IconAdapterContext.tsx"],"sourcesContent":["// Copyright (c) Cratis. All rights reserved.\n// Licensed under the MIT license. See LICENSE file in the project root for full license information.\n\nimport { ReactNode, createContext, useContext } from 'react';\nimport { IconAdapterRegistry } from './IconAdapterRegistry';\n\nconst IconAdapterContext = createContext<IconAdapterRegistry | undefined>(undefined);\n\n/**\n * Supplies the icon adapters every `SceneIcon` below it renders through.\n */\nexport const IconAdapterProvider = ({ registry, children }: { registry: IconAdapterRegistry; children?: ReactNode }) => (\n <IconAdapterContext.Provider value={registry}>{children}</IconAdapterContext.Provider>\n);\n\n/**\n * The icon adapters in scope, or `undefined` outside an {@link IconAdapterProvider}.\n */\nexport function useIconAdapters(): IconAdapterRegistry | undefined {\n return useContext(IconAdapterContext);\n}\n"],"names":["IconAdapterContext","createContext","undefined","IconAdapterProvider","registry","children","_jsx","Provider","value","useIconAdapters","useContext"],"mappings":";;;AAMA,MAAMA,mCAAqBC,aAAAA,CAA+CC,SAAAA,CAAAA;AAE1E;;AAEC,IACM,MAAMC,mBAAAA,GAAsB,CAAC,EAAEC,QAAQ,EAAEC,QAAQ,EAA2D,iBAC/GC,GAAA,CAACN,kBAAAA,CAAmBO,QAAQ,EAAA;QAACC,KAAAA,EAAOJ,QAAAA;AAAWC,QAAAA,QAAAA,EAAAA;AACjD,KAAA;AAEF;;AAEC,IACM,SAASI,eAAAA,GAAAA;AACZ,IAAA,OAAOC,UAAAA,CAAWV,kBAAAA,CAAAA;AACtB;;"}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import { IconAdapter } from './IconAdapter';
|
|
2
|
+
export declare class IconAdapterRegistry {
|
|
3
|
+
#private;
|
|
4
|
+
register(adapter: IconAdapter): this;
|
|
5
|
+
get(library: string): IconAdapter | undefined;
|
|
6
|
+
get libraries(): string[];
|
|
7
|
+
}
|
|
8
|
+
export declare function createIconAdapterRegistry(adapters?: IconAdapter[]): IconAdapterRegistry;
|
|
9
|
+
//# sourceMappingURL=IconAdapterRegistry.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"IconAdapterRegistry.d.ts","sourceRoot":"","sources":["../../../icons/IconAdapterRegistry.ts"],"names":[],"mappings":"AAGA,OAAO,EAAE,WAAW,EAAE,MAAM,eAAe,CAAC;AAO5C,qBAAa,mBAAmB;;IAQ5B,QAAQ,CAAC,OAAO,EAAE,WAAW,GAAG,IAAI,CAOnC;IAKD,GAAG,CAAC,OAAO,EAAE,MAAM,GAAG,WAAW,GAAG,SAAS,CAE5C;IAKD,IAAI,SAAS,IAAI,MAAM,EAAE,CAExB;CACJ;AAKD,wBAAgB,yBAAyB,CAAC,QAAQ,GAAE,WAAW,EAAO,GAAG,mBAAmB,CAI3F"}
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
// Copyright (c) Cratis. All rights reserved.
|
|
2
|
+
// Licensed under the MIT license. See LICENSE file in the project root for full license information.
|
|
3
|
+
/**
|
|
4
|
+
* The icon adapters a renderer has, one per library. Registering is explicit and never replaces: two
|
|
5
|
+
* adapters for one library would mean an icon renders differently depending on registration order, which
|
|
6
|
+
* is the silent swapping the library-qualified reference exists to prevent.
|
|
7
|
+
*/ class IconAdapterRegistry {
|
|
8
|
+
#adapters = new Map();
|
|
9
|
+
/**
|
|
10
|
+
* Adds an adapter.
|
|
11
|
+
*
|
|
12
|
+
* @throws Error when an adapter for the same library is already registered.
|
|
13
|
+
*/ register(adapter) {
|
|
14
|
+
if (this.#adapters.has(adapter.library)) {
|
|
15
|
+
throw new Error(`An icon adapter for the library '${adapter.library}' is already registered`);
|
|
16
|
+
}
|
|
17
|
+
this.#adapters.set(adapter.library, adapter);
|
|
18
|
+
return this;
|
|
19
|
+
}
|
|
20
|
+
/**
|
|
21
|
+
* The adapter for a library, or `undefined` when this renderer has none.
|
|
22
|
+
*/ get(library) {
|
|
23
|
+
return this.#adapters.get(library);
|
|
24
|
+
}
|
|
25
|
+
/**
|
|
26
|
+
* The libraries this registry can render.
|
|
27
|
+
*/ get libraries() {
|
|
28
|
+
return [
|
|
29
|
+
...this.#adapters.keys()
|
|
30
|
+
];
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
/**
|
|
34
|
+
* Creates a registry holding the given adapters.
|
|
35
|
+
*/ function createIconAdapterRegistry(adapters = []) {
|
|
36
|
+
const registry = new IconAdapterRegistry();
|
|
37
|
+
adapters.forEach((adapter)=>registry.register(adapter));
|
|
38
|
+
return registry;
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
export { IconAdapterRegistry, createIconAdapterRegistry };
|
|
42
|
+
//# sourceMappingURL=IconAdapterRegistry.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"IconAdapterRegistry.js","sources":["../../../icons/IconAdapterRegistry.ts"],"sourcesContent":["// Copyright (c) Cratis. All rights reserved.\n// Licensed under the MIT license. See LICENSE file in the project root for full license information.\n\nimport { IconAdapter } from './IconAdapter';\n\n/**\n * The icon adapters a renderer has, one per library. Registering is explicit and never replaces: two\n * adapters for one library would mean an icon renders differently depending on registration order, which\n * is the silent swapping the library-qualified reference exists to prevent.\n */\nexport class IconAdapterRegistry {\n readonly #adapters = new Map<string, IconAdapter>();\n\n /**\n * Adds an adapter.\n *\n * @throws Error when an adapter for the same library is already registered.\n */\n register(adapter: IconAdapter): this {\n if (this.#adapters.has(adapter.library)) {\n throw new Error(`An icon adapter for the library '${adapter.library}' is already registered`);\n }\n\n this.#adapters.set(adapter.library, adapter);\n return this;\n }\n\n /**\n * The adapter for a library, or `undefined` when this renderer has none.\n */\n get(library: string): IconAdapter | undefined {\n return this.#adapters.get(library);\n }\n\n /**\n * The libraries this registry can render.\n */\n get libraries(): string[] {\n return [...this.#adapters.keys()];\n }\n}\n\n/**\n * Creates a registry holding the given adapters.\n */\nexport function createIconAdapterRegistry(adapters: IconAdapter[] = []): IconAdapterRegistry {\n const registry = new IconAdapterRegistry();\n adapters.forEach((adapter) => registry.register(adapter));\n return registry;\n}\n"],"names":["IconAdapterRegistry","Map","register","adapter","has","library","Error","set","get","libraries","keys","createIconAdapterRegistry","adapters","registry","forEach"],"mappings":"AAAA;AACA;AAIA;;;;AAIC,IACM,MAAMA,mBAAAA,CAAAA;IACA,SAAS,GAAG,IAAIC,GAAAA,EAAAA;AAEzB;;;;QAKAC,QAAAA,CAASC,OAAoB,EAAQ;QACjC,IAAI,IAAI,CAAC,SAAS,CAACC,GAAG,CAACD,OAAAA,CAAQE,OAAO,CAAA,EAAG;YACrC,MAAM,IAAIC,MAAM,CAAC,iCAAiC,EAAEH,OAAAA,CAAQE,OAAO,CAAC,uBAAuB,CAAC,CAAA;AAChG,QAAA;QAEA,IAAI,CAAC,SAAS,CAACE,GAAG,CAACJ,OAAAA,CAAQE,OAAO,EAAEF,OAAAA,CAAAA;AACpC,QAAA,OAAO,IAAI;AACf,IAAA;AAEA;;QAGAK,GAAAA,CAAIH,OAAe,EAA2B;AAC1C,QAAA,OAAO,IAAI,CAAC,SAAS,CAACG,GAAG,CAACH,OAAAA,CAAAA;AAC9B,IAAA;AAEA;;AAEC,QACD,IAAII,SAAAA,GAAsB;QACtB,OAAO;AAAI,YAAA,GAAA,IAAI,CAAC,SAAS,CAACC,IAAI;AAAG,SAAA;AACrC,IAAA;AACJ;AAEA;;AAEC,IACM,SAASC,yBAAAA,CAA0BC,QAAAA,GAA0B,EAAE,EAAA;AAClE,IAAA,MAAMC,WAAW,IAAIb,mBAAAA,EAAAA;AACrBY,IAAAA,QAAAA,CAASE,OAAO,CAAC,CAACX,OAAAA,GAAYU,QAAAA,CAASX,QAAQ,CAACC,OAAAA,CAAAA,CAAAA;IAChD,OAAOU,QAAAA;AACX;;"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"IconLibraryBundle.d.ts","sourceRoot":"","sources":["../../../icons/IconLibraryBundle.ts"],"names":[],"mappings":"AAGA,OAAO,EAAE,iBAAiB,EAAE,MAAM,sBAAsB,CAAC;AACzD,OAAO,EAAE,WAAW,EAAE,MAAM,eAAe,CAAC;AAU5C,MAAM,WAAW,iBAAiB;IAI9B,OAAO,EAAE,iBAAiB,CAAC;IAK3B,OAAO,EAAE,WAAW,CAAC;CACxB"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"IconLibraryBundle.js","sourceRoot":"","sources":["../../../icons/IconLibraryBundle.ts"],"names":[],"mappings":""}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import { ReactNode } from 'react';
|
|
2
|
+
import { IconReference } from '@cratis/scene.model';
|
|
3
|
+
import { IconAdapterRegistry } from './IconAdapterRegistry';
|
|
4
|
+
export interface SceneIconProps {
|
|
5
|
+
reference: IconReference;
|
|
6
|
+
adapters?: IconAdapterRegistry;
|
|
7
|
+
size?: number | string;
|
|
8
|
+
color?: string;
|
|
9
|
+
label?: string;
|
|
10
|
+
className?: string;
|
|
11
|
+
fallback?: ReactNode;
|
|
12
|
+
}
|
|
13
|
+
export declare const SceneIcon: ({ reference, adapters, size, color, label, className, fallback }: SceneIconProps) => import("react").JSX.Element;
|
|
14
|
+
//# sourceMappingURL=SceneIcon.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"SceneIcon.d.ts","sourceRoot":"","sources":["../../../icons/SceneIcon.tsx"],"names":[],"mappings":"AAGA,OAAO,EAAE,SAAS,EAAE,MAAM,OAAO,CAAC;AAClC,OAAO,EAAE,aAAa,EAAE,MAAM,qBAAqB,CAAC;AACpD,OAAO,EAAE,mBAAmB,EAAE,MAAM,uBAAuB,CAAC;AAI5D,MAAM,WAAW,cAAc;IAI3B,SAAS,EAAE,aAAa,CAAC;IAKzB,QAAQ,CAAC,EAAE,mBAAmB,CAAC;IAM/B,IAAI,CAAC,EAAE,MAAM,GAAG,MAAM,CAAC;IAKvB,KAAK,CAAC,EAAE,MAAM,CAAC;IAMf,KAAK,CAAC,EAAE,MAAM,CAAC;IAKf,SAAS,CAAC,EAAE,MAAM,CAAC;IAMnB,QAAQ,CAAC,EAAE,SAAS,CAAC;CACxB;AAMD,eAAO,MAAM,SAAS,qEAA+F,cAAc,gCAmBlI,CAAC"}
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
import { jsx } from 'react/jsx-runtime';
|
|
2
|
+
import { useIconAdapters } from './IconAdapterContext.js';
|
|
3
|
+
import { useIconGlyph } from './useIconGlyph.js';
|
|
4
|
+
|
|
5
|
+
// Copyright (c) Cratis. All rights reserved.
|
|
6
|
+
// Licensed under the MIT license. See LICENSE file in the project root for full license information.
|
|
7
|
+
/**
|
|
8
|
+
* Draws a renderer-neutral {@link IconReference} through the adapter registered for its library, honoring
|
|
9
|
+
* size, color and accessible label. The reference is all that is persisted; this is where it becomes pixels.
|
|
10
|
+
*/ const SceneIcon = ({ reference, adapters, size = '1em', color = 'currentColor', label, className, fallback })=>{
|
|
11
|
+
const inScope = useIconAdapters();
|
|
12
|
+
const state = useIconGlyph(reference, adapters ?? inScope);
|
|
13
|
+
const Glyph = state.status === 'ready' ? state.glyph : undefined;
|
|
14
|
+
return /*#__PURE__*/ jsx("span", {
|
|
15
|
+
className: className,
|
|
16
|
+
role: label ? 'img' : undefined,
|
|
17
|
+
"aria-label": label,
|
|
18
|
+
"aria-hidden": label ? undefined : true,
|
|
19
|
+
"data-icon-library": reference.library,
|
|
20
|
+
"data-icon-key": reference.key,
|
|
21
|
+
"data-icon-variant": reference.variant,
|
|
22
|
+
"data-icon-state": state.status,
|
|
23
|
+
style: {
|
|
24
|
+
display: 'inline-flex',
|
|
25
|
+
alignItems: 'center',
|
|
26
|
+
justifyContent: 'center',
|
|
27
|
+
width: size,
|
|
28
|
+
height: size,
|
|
29
|
+
color,
|
|
30
|
+
flexShrink: 0
|
|
31
|
+
},
|
|
32
|
+
children: Glyph ? /*#__PURE__*/ jsx(Glyph, {
|
|
33
|
+
size: size,
|
|
34
|
+
color: color
|
|
35
|
+
}) : state.status === 'unavailable' ? fallback : null
|
|
36
|
+
});
|
|
37
|
+
};
|
|
38
|
+
|
|
39
|
+
export { SceneIcon };
|
|
40
|
+
//# sourceMappingURL=SceneIcon.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"SceneIcon.js","sources":["../../../icons/SceneIcon.tsx"],"sourcesContent":["// Copyright (c) Cratis. All rights reserved.\n// Licensed under the MIT license. See LICENSE file in the project root for full license information.\n\nimport { ReactNode } from 'react';\nimport { IconReference } from '@cratis/scene.model';\nimport { IconAdapterRegistry } from './IconAdapterRegistry';\nimport { useIconAdapters } from './IconAdapterContext';\nimport { useIconGlyph } from './useIconGlyph';\n\nexport interface SceneIconProps {\n /**\n * The icon to draw.\n */\n reference: IconReference;\n\n /**\n * The adapters to render through. Defaults to the ones an `IconAdapterProvider` supplies.\n */\n adapters?: IconAdapterRegistry;\n\n /**\n * The width and height of the icon: a number of pixels or any CSS length. Defaults to `1em`, so an\n * icon scales with the text it sits in.\n */\n size?: number | string;\n\n /**\n * The color to draw in. Defaults to `currentColor`.\n */\n color?: string;\n\n /**\n * The accessible name. With a label the icon is announced as an image; without one it is decorative\n * and hidden from assistive technology - an icon next to its own text label should not be read twice.\n */\n label?: string;\n\n /**\n * An optional class for the box the icon sits in.\n */\n className?: string;\n\n /**\n * What to show when the icon cannot be drawn - no adapter, no such icon, a failed load. Nothing by\n * default; the box keeps its size so layout does not shift.\n */\n fallback?: ReactNode;\n}\n\n/**\n * Draws a renderer-neutral {@link IconReference} through the adapter registered for its library, honoring\n * size, color and accessible label. The reference is all that is persisted; this is where it becomes pixels.\n */\nexport const SceneIcon = ({ reference, adapters, size = '1em', color = 'currentColor', label, className, fallback }: SceneIconProps) => {\n const inScope = useIconAdapters();\n const state = useIconGlyph(reference, adapters ?? inScope);\n const Glyph = state.status === 'ready' ? state.glyph : undefined;\n\n return (\n <span\n className={className}\n role={label ? 'img' : undefined}\n aria-label={label}\n aria-hidden={label ? undefined : true}\n data-icon-library={reference.library}\n data-icon-key={reference.key}\n data-icon-variant={reference.variant}\n data-icon-state={state.status}\n style={{ display: 'inline-flex', alignItems: 'center', justifyContent: 'center', width: size, height: size, color, flexShrink: 0 }}>\n {Glyph ? <Glyph size={size} color={color} /> : state.status === 'unavailable' ? fallback : null}\n </span>\n );\n};\n"],"names":["SceneIcon","reference","adapters","size","color","label","className","fallback","inScope","useIconAdapters","state","useIconGlyph","Glyph","status","glyph","undefined","_jsx","span","role","aria-label","aria-hidden","data-icon-library","library","data-icon-key","key","data-icon-variant","variant","data-icon-state","style","display","alignItems","justifyContent","width","height","flexShrink"],"mappings":";;;;AAAA;AACA;AAgDA;;;UAIaA,SAAAA,GAAY,CAAC,EAAEC,SAAS,EAAEC,QAAQ,EAAEC,IAAAA,GAAO,KAAK,EAAEC,KAAAA,GAAQ,cAAc,EAAEC,KAAK,EAAEC,SAAS,EAAEC,QAAQ,EAAkB,GAAA;AAC/H,IAAA,MAAMC,OAAAA,GAAUC,eAAAA,EAAAA;IAChB,MAAMC,KAAAA,GAAQC,YAAAA,CAAaV,SAAAA,EAAWC,QAAAA,IAAYM,OAAAA,CAAAA;AAClD,IAAA,MAAMI,QAAQF,KAAAA,CAAMG,MAAM,KAAK,OAAA,GAAUH,KAAAA,CAAMI,KAAK,GAAGC,SAAAA;AAEvD,IAAA,qBACIC,GAAA,CAACC,MAAAA,EAAAA;QACGX,SAAAA,EAAWA,SAAAA;AACXY,QAAAA,IAAAA,EAAMb,QAAQ,KAAA,GAAQU,SAAAA;QACtBI,YAAAA,EAAYd,KAAAA;AACZe,QAAAA,aAAAA,EAAaf,QAAQU,SAAAA,GAAY,IAAA;AACjCM,QAAAA,mBAAAA,EAAmBpB,UAAUqB,OAAO;AACpCC,QAAAA,eAAAA,EAAetB,UAAUuB,GAAG;AAC5BC,QAAAA,mBAAAA,EAAmBxB,UAAUyB,OAAO;AACpCC,QAAAA,iBAAAA,EAAiBjB,MAAMG,MAAM;QAC7Be,KAAAA,EAAO;YAAEC,OAAAA,EAAS,aAAA;YAAeC,UAAAA,EAAY,QAAA;YAAUC,cAAAA,EAAgB,QAAA;YAAUC,KAAAA,EAAO7B,IAAAA;YAAM8B,MAAAA,EAAQ9B,IAAAA;AAAMC,YAAAA,KAAAA;YAAO8B,UAAAA,EAAY;AAAE,SAAA;AAChItB,QAAAA,QAAAA,EAAAA,KAAAA,iBAAQI,GAAA,CAACJ,KAAAA,EAAAA;YAAMT,IAAAA,EAAMA,IAAAA;YAAMC,KAAAA,EAAOA;aAAYM,KAAAA,CAAMG,MAAM,KAAK,aAAA,GAAgBN,QAAAA,GAAW;;AAGvG;;"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../icons/index.ts"],"names":[],"mappings":"AAGA,cAAc,eAAe,CAAC;AAC9B,cAAc,uBAAuB,CAAC;AACtC,cAAc,sBAAsB,CAAC;AACrC,cAAc,gBAAgB,CAAC;AAC/B,cAAc,aAAa,CAAC;AAC5B,cAAc,qBAAqB,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../icons/index.ts"],"names":[],"mappings":"AAGA,cAAc,eAAe,CAAC;AAC9B,cAAc,uBAAuB,CAAC;AACtC,cAAc,sBAAsB,CAAC;AACrC,cAAc,gBAAgB,CAAC;AAC/B,cAAc,aAAa,CAAC;AAC5B,cAAc,qBAAqB,CAAC"}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import { IconReference } from '@cratis/scene.model';
|
|
2
|
+
import { IconGlyph } from './IconAdapter';
|
|
3
|
+
import { IconAdapterRegistry } from './IconAdapterRegistry';
|
|
4
|
+
export type IconGlyphState = {
|
|
5
|
+
status: 'loading';
|
|
6
|
+
} | {
|
|
7
|
+
status: 'ready';
|
|
8
|
+
glyph: IconGlyph;
|
|
9
|
+
} | {
|
|
10
|
+
status: 'unavailable';
|
|
11
|
+
reason: string;
|
|
12
|
+
};
|
|
13
|
+
export declare function useIconGlyph(reference: IconReference, adapters: IconAdapterRegistry | undefined): IconGlyphState;
|
|
14
|
+
//# sourceMappingURL=useIconGlyph.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"useIconGlyph.d.ts","sourceRoot":"","sources":["../../../icons/useIconGlyph.ts"],"names":[],"mappings":"AAIA,OAAO,EAAE,aAAa,EAAE,MAAM,qBAAqB,CAAC;AACpD,OAAO,EAAe,SAAS,EAAE,MAAM,eAAe,CAAC;AACvD,OAAO,EAAE,mBAAmB,EAAE,MAAM,uBAAuB,CAAC;AAK5D,MAAM,MAAM,cAAc,GACpB;IAAE,MAAM,EAAE,SAAS,CAAA;CAAE,GACrB;IAAE,MAAM,EAAE,OAAO,CAAC;IAAC,KAAK,EAAE,SAAS,CAAA;CAAE,GACrC;IAAE,MAAM,EAAE,aAAa,CAAC;IAAC,MAAM,EAAE,MAAM,CAAA;CAAE,CAAC;AAmChD,wBAAgB,YAAY,CAAC,SAAS,EAAE,aAAa,EAAE,QAAQ,EAAE,mBAAmB,GAAG,SAAS,GAAG,cAAc,CA6BhH"}
|
|
@@ -0,0 +1,84 @@
|
|
|
1
|
+
import { useState, useEffect } from 'react';
|
|
2
|
+
|
|
3
|
+
// Copyright (c) Cratis. All rights reserved.
|
|
4
|
+
// Licensed under the MIT license. See LICENSE file in the project root for full license information.
|
|
5
|
+
const loads = new WeakMap();
|
|
6
|
+
function keyOf(reference) {
|
|
7
|
+
return JSON.stringify([
|
|
8
|
+
reference.key,
|
|
9
|
+
reference.variant ?? null
|
|
10
|
+
]);
|
|
11
|
+
}
|
|
12
|
+
/**
|
|
13
|
+
* One load per adapter and icon, shared between every place the icon is drawn; a failed load is
|
|
14
|
+
* forgotten so the next render can try again.
|
|
15
|
+
*/ function load(adapter, reference) {
|
|
16
|
+
let perAdapter = loads.get(adapter);
|
|
17
|
+
if (!perAdapter) {
|
|
18
|
+
perAdapter = new Map();
|
|
19
|
+
loads.set(adapter, perAdapter);
|
|
20
|
+
}
|
|
21
|
+
const key = keyOf(reference);
|
|
22
|
+
let pending = perAdapter.get(key);
|
|
23
|
+
if (!pending) {
|
|
24
|
+
pending = Promise.resolve().then(()=>adapter.loadGlyph(reference));
|
|
25
|
+
perAdapter.set(key, pending);
|
|
26
|
+
pending.catch(()=>perAdapter.delete(key));
|
|
27
|
+
}
|
|
28
|
+
return pending;
|
|
29
|
+
}
|
|
30
|
+
/**
|
|
31
|
+
* Loads the artwork for a reference through the adapter registered for its library. An absent registry,
|
|
32
|
+
* a library with no adapter, an icon the library lacks and a failed load are all `unavailable`, each with
|
|
33
|
+
* its reason - never a different icon.
|
|
34
|
+
*/ function useIconGlyph(reference, adapters) {
|
|
35
|
+
const [state, setState] = useState({
|
|
36
|
+
status: 'loading'
|
|
37
|
+
});
|
|
38
|
+
const { library, key, variant } = reference;
|
|
39
|
+
useEffect(()=>{
|
|
40
|
+
let isCurrent = true;
|
|
41
|
+
const adapter = adapters?.get(library);
|
|
42
|
+
if (!adapter) {
|
|
43
|
+
setState({
|
|
44
|
+
status: 'unavailable',
|
|
45
|
+
reason: `No icon adapter is registered for the library '${library}'`
|
|
46
|
+
});
|
|
47
|
+
return;
|
|
48
|
+
}
|
|
49
|
+
setState({
|
|
50
|
+
status: 'loading'
|
|
51
|
+
});
|
|
52
|
+
load(adapter, {
|
|
53
|
+
library,
|
|
54
|
+
key,
|
|
55
|
+
variant
|
|
56
|
+
}).then((glyph)=>{
|
|
57
|
+
if (!isCurrent) return;
|
|
58
|
+
setState(glyph ? {
|
|
59
|
+
status: 'ready',
|
|
60
|
+
glyph
|
|
61
|
+
} : {
|
|
62
|
+
status: 'unavailable',
|
|
63
|
+
reason: `The library '${library}' has no icon '${key}'`
|
|
64
|
+
});
|
|
65
|
+
}, (error)=>{
|
|
66
|
+
if (isCurrent) setState({
|
|
67
|
+
status: 'unavailable',
|
|
68
|
+
reason: error instanceof Error ? error.message : String(error)
|
|
69
|
+
});
|
|
70
|
+
});
|
|
71
|
+
return ()=>{
|
|
72
|
+
isCurrent = false;
|
|
73
|
+
};
|
|
74
|
+
}, [
|
|
75
|
+
adapters,
|
|
76
|
+
library,
|
|
77
|
+
key,
|
|
78
|
+
variant
|
|
79
|
+
]);
|
|
80
|
+
return state;
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
export { useIconGlyph };
|
|
84
|
+
//# sourceMappingURL=useIconGlyph.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"useIconGlyph.js","sources":["../../../icons/useIconGlyph.ts"],"sourcesContent":["// Copyright (c) Cratis. All rights reserved.\n// Licensed under the MIT license. See LICENSE file in the project root for full license information.\n\nimport { useEffect, useState } from 'react';\nimport { IconReference } from '@cratis/scene.model';\nimport { IconAdapter, IconGlyph } from './IconAdapter';\nimport { IconAdapterRegistry } from './IconAdapterRegistry';\n\n/**\n * Where loading one icon's artwork stands.\n */\nexport type IconGlyphState =\n | { status: 'loading' }\n | { status: 'ready'; glyph: IconGlyph }\n | { status: 'unavailable'; reason: string };\n\nconst loads = new WeakMap<IconAdapter, Map<string, Promise<IconGlyph | undefined>>>();\n\nfunction keyOf(reference: IconReference): string {\n return JSON.stringify([reference.key, reference.variant ?? null]);\n}\n\n/**\n * One load per adapter and icon, shared between every place the icon is drawn; a failed load is\n * forgotten so the next render can try again.\n */\nfunction load(adapter: IconAdapter, reference: IconReference): Promise<IconGlyph | undefined> {\n let perAdapter = loads.get(adapter);\n if (!perAdapter) {\n perAdapter = new Map();\n loads.set(adapter, perAdapter);\n }\n\n const key = keyOf(reference);\n let pending = perAdapter.get(key);\n if (!pending) {\n pending = Promise.resolve().then(() => adapter.loadGlyph(reference));\n perAdapter.set(key, pending);\n pending.catch(() => perAdapter.delete(key));\n }\n\n return pending;\n}\n\n/**\n * Loads the artwork for a reference through the adapter registered for its library. An absent registry,\n * a library with no adapter, an icon the library lacks and a failed load are all `unavailable`, each with\n * its reason - never a different icon.\n */\nexport function useIconGlyph(reference: IconReference, adapters: IconAdapterRegistry | undefined): IconGlyphState {\n const [state, setState] = useState<IconGlyphState>({ status: 'loading' });\n const { library, key, variant } = reference;\n\n useEffect(() => {\n let isCurrent = true;\n const adapter = adapters?.get(library);\n if (!adapter) {\n setState({ status: 'unavailable', reason: `No icon adapter is registered for the library '${library}'` });\n return;\n }\n\n setState({ status: 'loading' });\n load(adapter, { library, key, variant }).then(\n (glyph) => {\n if (!isCurrent) return;\n setState(glyph ? { status: 'ready', glyph } : { status: 'unavailable', reason: `The library '${library}' has no icon '${key}'` });\n },\n (error: unknown) => {\n if (isCurrent) setState({ status: 'unavailable', reason: error instanceof Error ? error.message : String(error) });\n }\n );\n\n return () => {\n isCurrent = false;\n };\n }, [adapters, library, key, variant]);\n\n return state;\n}\n"],"names":["loads","WeakMap","keyOf","reference","JSON","stringify","key","variant","load","adapter","perAdapter","get","Map","set","pending","Promise","resolve","then","loadGlyph","catch","delete","useIconGlyph","adapters","state","setState","useState","status","library","useEffect","isCurrent","reason","glyph","error","Error","message","String"],"mappings":";;AAAA;AACA;AAeA,MAAMA,QAAQ,IAAIC,OAAAA,EAAAA;AAElB,SAASC,MAAMC,SAAwB,EAAA;IACnC,OAAOC,IAAAA,CAAKC,SAAS,CAAC;AAACF,QAAAA,SAAAA,CAAUG,GAAG;AAAEH,QAAAA,SAAAA,CAAUI,OAAO,IAAI;AAAK,KAAA,CAAA;AACpE;AAEA;;;AAGC,IACD,SAASC,IAAAA,CAAKC,OAAoB,EAAEN,SAAwB,EAAA;IACxD,IAAIO,UAAAA,GAAaV,KAAAA,CAAMW,GAAG,CAACF,OAAAA,CAAAA;AAC3B,IAAA,IAAI,CAACC,UAAAA,EAAY;AACbA,QAAAA,UAAAA,GAAa,IAAIE,GAAAA,EAAAA;QACjBZ,KAAAA,CAAMa,GAAG,CAACJ,OAAAA,EAASC,UAAAA,CAAAA;AACvB,IAAA;AAEA,IAAA,MAAMJ,MAAMJ,KAAAA,CAAMC,SAAAA,CAAAA;IAClB,IAAIW,OAAAA,GAAUJ,UAAAA,CAAWC,GAAG,CAACL,GAAAA,CAAAA;AAC7B,IAAA,IAAI,CAACQ,OAAAA,EAAS;QACVA,OAAAA,GAAUC,OAAAA,CAAQC,OAAO,EAAA,CAAGC,IAAI,CAAC,IAAMR,OAAAA,CAAQS,SAAS,CAACf,SAAAA,CAAAA,CAAAA;QACzDO,UAAAA,CAAWG,GAAG,CAACP,GAAAA,EAA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CAAA;AACnI,QAAA,CAAA,EACA,CAAC0B,KAAAA,GAAAA;AACG,YAAA,IAAIH,WAAWL,QAAAA,CAAS;gBAAEE,MAAAA,EAAQ,aAAA;AAAeI,gBAAAA,MAAAA,EAAQE,KAAAA,YAAiBC,KAAAA,GAAQD,KAAAA,CAAME,OAAO,GAAGC,MAAAA,CAAOH,KAAAA;AAAO,aAAA,CAAA;AACpH,QAAA,CAAA,CAAA;QAGJ,OAAO,IAAA;YACHH,SAAAA,GAAY,KAAA;AAChB,QAAA,CAAA;IACJ,CAAA,EAAG;AAACP,QAAAA,QAAAA;AAAUK,QAAAA,OAAAA;AAASrB,QAAAA,GAAAA;AAAKC,QAAAA;AAAQ,KAAA,CAAA;IAEpC,OAAOgB,KAAAA;AACX;;"}
|
package/dist/esm/index.d.ts
CHANGED
package/dist/esm/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../index.ts"],"names":[],"mappings":"AAGA,cAAc,oBAAoB,CAAC;AACnC,cAAc,YAAY,CAAC;AAC3B,cAAc,QAAQ,CAAC;AACvB,cAAc,UAAU,CAAC;AACzB,cAAc,YAAY,CAAC;AAC3B,cAAc,SAAS,CAAC;AACxB,cAAc,gBAAgB,CAAC"}
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../index.ts"],"names":[],"mappings":"AAGA,cAAc,oBAAoB,CAAC;AACnC,cAAc,YAAY,CAAC;AAC3B,cAAc,QAAQ,CAAC;AACvB,cAAc,UAAU,CAAC;AACzB,cAAc,SAAS,CAAC;AACxB,cAAc,YAAY,CAAC;AAC3B,cAAc,SAAS,CAAC;AACxB,cAAc,gBAAgB,CAAC"}
|
package/dist/esm/index.js
CHANGED
|
@@ -12,7 +12,11 @@ export { coreComponents } from './core/coreComponents.js';
|
|
|
12
12
|
export { corePackage, corePackageManifest } from './core/corePackage.js';
|
|
13
13
|
export { NavBar } from './NavBar/NavBar.js';
|
|
14
14
|
export { extractNavigationItem } from './NavBar/extractNavigationItem.js';
|
|
15
|
-
export {
|
|
15
|
+
export { IconAdapterRegistry, createIconAdapterRegistry } from './icons/IconAdapterRegistry.js';
|
|
16
|
+
export { IconAdapterProvider, useIconAdapters } from './icons/IconAdapterContext.js';
|
|
17
|
+
export { useIconGlyph } from './icons/useIconGlyph.js';
|
|
18
|
+
export { SceneIcon } from './icons/SceneIcon.js';
|
|
19
|
+
export { componentRegistryKey, mergeIconAdapters, mergePackageRegistries, validatePackageBundle } from './packages/ScenePackageBundle.js';
|
|
16
20
|
export { applyThemeTokens, themeTokenPrefix, themeTokenProperty } from './theme/themeTokens.js';
|
|
17
21
|
export { SceneThemeProvider, useSceneTheme } from './theme/SceneThemeProvider.js';
|
|
18
22
|
export { InteractionScope, attachmentFor, useInteractionScope } from './interactions/InteractionScope.js';
|
package/dist/esm/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sources":[],"sourcesContent":[],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"index.js","sources":[],"sourcesContent":[],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;"}
|
|
@@ -1,4 +1,6 @@
|
|
|
1
1
|
import { ComponentDescriptor, DialogTemplate, Layout, ScenePackage, Screen, ScreenTemplate, Theme } from '@cratis/scene.model';
|
|
2
|
+
import { IconAdapterRegistry } from '../icons/IconAdapterRegistry';
|
|
3
|
+
import { IconLibraryBundle } from '../icons/IconLibraryBundle';
|
|
2
4
|
import { ComponentRegistry } from '../renderer';
|
|
3
5
|
export interface ScenePackageBundle {
|
|
4
6
|
manifest: ScenePackage;
|
|
@@ -9,8 +11,10 @@ export interface ScenePackageBundle {
|
|
|
9
11
|
screens?: Screen[];
|
|
10
12
|
descriptors?: ComponentDescriptor[];
|
|
11
13
|
themes?: Theme[];
|
|
14
|
+
iconLibrary?: IconLibraryBundle;
|
|
12
15
|
}
|
|
13
16
|
export declare function componentRegistryKey(packageName: string, componentName: string): string;
|
|
14
17
|
export declare function validatePackageBundle(bundle: ScenePackageBundle): string[];
|
|
15
18
|
export declare function mergePackageRegistries(bundles: ScenePackageBundle[]): ComponentRegistry;
|
|
19
|
+
export declare function mergeIconAdapters(bundles: ScenePackageBundle[]): IconAdapterRegistry;
|
|
16
20
|
//# sourceMappingURL=ScenePackageBundle.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ScenePackageBundle.d.ts","sourceRoot":"","sources":["../../../packages/ScenePackageBundle.ts"],"names":[],"mappings":"AAGA,OAAO,EAAE,mBAAmB,EAAE,cAAc,EAAE,MAAM,
|
|
1
|
+
{"version":3,"file":"ScenePackageBundle.d.ts","sourceRoot":"","sources":["../../../packages/ScenePackageBundle.ts"],"names":[],"mappings":"AAGA,OAAO,EAAE,mBAAmB,EAAE,cAAc,EAAE,MAAM,EAAkC,YAAY,EAAE,MAAM,EAAE,cAAc,EAAE,KAAK,EAAE,MAAM,qBAAqB,CAAC;AAC/J,OAAO,EAAE,mBAAmB,EAA6B,MAAM,8BAA8B,CAAC;AAC9F,OAAO,EAAE,iBAAiB,EAAE,MAAM,4BAA4B,CAAC;AAC/D,OAAO,EAAE,iBAAiB,EAAE,MAAM,aAAa,CAAC;AAchD,MAAM,WAAW,kBAAkB;IAK/B,QAAQ,EAAE,YAAY,CAAC;IAKvB,UAAU,EAAE,iBAAiB,CAAC;IAK9B,OAAO,CAAC,EAAE,MAAM,EAAE,CAAC;IAMnB,eAAe,CAAC,EAAE,cAAc,EAAE,CAAC;IAKnC,eAAe,CAAC,EAAE,cAAc,EAAE,CAAC;IAMnC,OAAO,CAAC,EAAE,MAAM,EAAE,CAAC;IAQnB,WAAW,CAAC,EAAE,mBAAmB,EAAE,CAAC;IAKpC,MAAM,CAAC,EAAE,KAAK,EAAE,CAAC;IAMjB,WAAW,CAAC,EAAE,iBAAiB,CAAC;CACnC;AAYD,wBAAgB,oBAAoB,CAAC,WAAW,EAAE,MAAM,EAAE,aAAa,EAAE,MAAM,GAAG,MAAM,CAEvF;AAWD,wBAAgB,qBAAqB,CAAC,MAAM,EAAE,kBAAkB,GAAG,MAAM,EAAE,CAiD1E;AAmFD,wBAAgB,sBAAsB,CAAC,OAAO,EAAE,kBAAkB,EAAE,GAAG,iBAAiB,CAEvF;AAOD,wBAAgB,iBAAiB,CAAC,OAAO,EAAE,kBAAkB,EAAE,GAAG,mBAAmB,CAEpF"}
|
|
@@ -1,4 +1,5 @@
|
|
|
1
|
-
import { PropertyValueType } from '@cratis/scene.model';
|
|
1
|
+
import { PackageKind, PropertyValueType } from '@cratis/scene.model';
|
|
2
|
+
import { createIconAdapterRegistry } from '../icons/IconAdapterRegistry.js';
|
|
2
3
|
|
|
3
4
|
// Copyright (c) Cratis. All rights reserved.
|
|
4
5
|
// Licensed under the MIT license. See LICENSE file in the project root for full license information.
|
|
@@ -60,9 +61,39 @@ import { PropertyValueType } from '@cratis/scene.model';
|
|
|
60
61
|
problems.push(`declares the theme '${name}' but provides no definition for it`);
|
|
61
62
|
}
|
|
62
63
|
}
|
|
64
|
+
problems.push(...validateIconLibrary(bundle));
|
|
63
65
|
problems.push(...validateDescriptors(bundle));
|
|
64
66
|
return problems;
|
|
65
67
|
}
|
|
68
|
+
function validateIconLibrary(bundle) {
|
|
69
|
+
const problems = [];
|
|
70
|
+
const { manifest, iconLibrary } = bundle;
|
|
71
|
+
const declaresIconLibrary = manifest.kind === PackageKind.IconLibrary || manifest.iconLibrary !== undefined;
|
|
72
|
+
if (manifest.kind === PackageKind.IconLibrary && !manifest.iconLibrary) {
|
|
73
|
+
problems.push('is an icon library but declares no iconLibrary metadata');
|
|
74
|
+
}
|
|
75
|
+
if (manifest.kind !== PackageKind.IconLibrary && manifest.iconLibrary) {
|
|
76
|
+
problems.push('declares iconLibrary metadata but is not of kind IconLibrary');
|
|
77
|
+
}
|
|
78
|
+
if (declaresIconLibrary && !iconLibrary) {
|
|
79
|
+
problems.push('declares an icon library but the bundle provides no catalog or adapter for it');
|
|
80
|
+
}
|
|
81
|
+
if (!declaresIconLibrary && iconLibrary) {
|
|
82
|
+
problems.push('provides an icon catalog and adapter, which the manifest does not declare');
|
|
83
|
+
}
|
|
84
|
+
if (iconLibrary) {
|
|
85
|
+
if (iconLibrary.catalog.library !== manifest.name) {
|
|
86
|
+
problems.push(`provides an icon catalog for '${iconLibrary.catalog.library}' instead of '${manifest.name}'`);
|
|
87
|
+
}
|
|
88
|
+
if (iconLibrary.adapter.library !== manifest.name) {
|
|
89
|
+
problems.push(`provides an icon adapter for '${iconLibrary.adapter.library}' instead of '${manifest.name}'`);
|
|
90
|
+
}
|
|
91
|
+
if (manifest.iconLibrary && !manifest.iconLibrary.renderers.includes('react')) {
|
|
92
|
+
problems.push("provides a React icon adapter but does not list 'react' among its icon renderers");
|
|
93
|
+
}
|
|
94
|
+
}
|
|
95
|
+
return problems;
|
|
96
|
+
}
|
|
66
97
|
function validateDescriptors(bundle) {
|
|
67
98
|
const problems = [];
|
|
68
99
|
const declared = new Set(bundle.manifest.components.map((name)=>componentRegistryKey(bundle.manifest.name, name)));
|
|
@@ -99,6 +130,15 @@ function validateDescriptors(bundle) {
|
|
|
99
130
|
*/ function mergePackageRegistries(bundles) {
|
|
100
131
|
return Object.assign({}, ...bundles.map((bundle)=>bundle.components));
|
|
101
132
|
}
|
|
133
|
+
/**
|
|
134
|
+
* Collects the icon adapters of several bundles into the registry `SceneIcon` renders through.
|
|
135
|
+
*
|
|
136
|
+
* @throws Error when two bundles provide an adapter for the same library.
|
|
137
|
+
*/ function mergeIconAdapters(bundles) {
|
|
138
|
+
return createIconAdapterRegistry(bundles.flatMap((bundle)=>bundle.iconLibrary ? [
|
|
139
|
+
bundle.iconLibrary.adapter
|
|
140
|
+
] : []));
|
|
141
|
+
}
|
|
102
142
|
|
|
103
|
-
export { componentRegistryKey, mergePackageRegistries, validatePackageBundle };
|
|
143
|
+
export { componentRegistryKey, mergeIconAdapters, mergePackageRegistries, validatePackageBundle };
|
|
104
144
|
//# sourceMappingURL=ScenePackageBundle.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ScenePackageBundle.js","sources":["../../../packages/ScenePackageBundle.ts"],"sourcesContent":["// Copyright (c) Cratis. All rights reserved.\n// Licensed under the MIT license. See LICENSE file in the project root for full license information.\n\nimport { ComponentDescriptor, DialogTemplate, Layout, PropertyValueType, ScenePackage, Screen, ScreenTemplate, Theme } from '@cratis/scene.model';\nimport { ComponentRegistry } from '../renderer';\n\n/**\n * What a package actually ships to a React renderer, as opposed to what it *declares*.\n *\n * `ScenePackage` is the declaration — a name, a kind, dependencies, and the names of what it\n * contributes. It is deliberately platform-agnostic and lives in `Scene.Model`, because Stage's build and\n * Studio's design-time queries both read it without ever loading a component. A bundle is the other half:\n * the real React components, layouts, screens and themes behind those names, which only a renderer needs.\n *\n * A package publishes exactly one bundle, as a named export following its own name —\n * `primeReactPackage`, `cratisComponentsPackage`, `corePackage`. A host loads it from the module the\n * declaration's `ScenePackage.module` names.\n */\nexport interface ScenePackageBundle {\n /**\n * The package's own declaration. Its `components`, `layouts` and `themes` name lists must agree with\n * what this bundle actually provides — {@link validatePackageBundle} is what proves they do.\n */\n manifest: ScenePackage;\n\n /**\n * The components this package provides, keyed by {@link componentRegistryKey}.\n */\n components: ComponentRegistry;\n\n /**\n * The application shells this package provides, if any. Only a blueprint has these.\n */\n layouts?: Layout[];\n\n /**\n * The screen templates this package provides — the shapes that go inside a layout, each declaring\n * which of its parent's slots it fills.\n */\n screenTemplates?: ScreenTemplate[];\n\n /**\n * The dialog templates this package provides.\n */\n dialogTemplates?: DialogTemplate[];\n\n /**\n * Sample screens this package ships — a layout package's gallery, so a preview has real content to\n * put through the real engine rather than a mockup.\n */\n screens?: Screen[];\n\n /**\n * What can be edited on this package's components - one {@link ComponentDescriptor} per component that is\n * editable at design time. They are data, so Studio reads them without rendering anything, and they travel with\n * the components they describe rather than in a registry of their own. {@link validatePackageBundle} checks\n * that every descriptor names a component the manifest declares.\n */\n descriptors?: ComponentDescriptor[];\n\n /**\n * The themes this package ships, if any.\n */\n themes?: Theme[];\n}\n\n/**\n * The key a component is registered and looked up under: the package that provides it, then the bare name\n * a screen refers to it by.\n *\n * A screen writes a bare name (`button`) or a package-qualified one (`PrimeReact.button`);\n * `resolveComponentName` turns either into a `{ name, package }` pair, and this turns that pair into the\n * registry key. Nothing should build this string by hand — the separator is an implementation detail of\n * the registry, deliberately not the `.` used for qualification in a screen, so a package name containing\n * dots stays unambiguous.\n */\nexport function componentRegistryKey(packageName: string, componentName: string): string {\n return `${packageName}:${componentName}`;\n}\n\n/**\n * Checks that a bundle provides everything its manifest declares, and declares everything it provides, and that\n * every descriptor it ships is for a component it declares and is well formed.\n *\n * A manifest that promises a component the bundle does not register renders as `UnresolvedComponent` at\n * runtime — a blank box, far from where the mistake was made. A component registered but not declared is\n * invisible to `resolveComponentName`, so a screen can never name it. Both are silent failures, which is\n * why every package's specs run this.\n */\nexport function validatePackageBundle(bundle: ScenePackageBundle): string[] {\n const problems: string[] = [];\n const { manifest } = bundle;\n\n for (const name of manifest.components) {\n if (!(componentRegistryKey(manifest.name, name) in bundle.components)) {\n problems.push(`declares the component '${name}' but registers no implementation for it`);\n }\n }\n\n const declared = new Set(manifest.components.map((name) => componentRegistryKey(manifest.name, name)));\n for (const key of Object.keys(bundle.components)) {\n if (!declared.has(key)) {\n problems.push(`registers '${key}', which the manifest does not declare`);\n }\n }\n\n const providedLayouts = new Set((bundle.layouts ?? []).map((layout) => layout.name));\n for (const name of manifest.layouts) {\n if (!providedLayouts.has(name)) {\n problems.push(`declares the layout '${name}' but provides no definition for it`);\n }\n }\n\n const providedScreenTemplates = new Set((bundle.screenTemplates ?? []).map((template) => template.name));\n for (const name of manifest.screenTemplates) {\n if (!providedScreenTemplates.has(name)) {\n problems.push(`declares the screen template '${name}' but provides no definition for it`);\n }\n }\n\n const providedDialogTemplates = new Set((bundle.dialogTemplates ?? []).map((template) => template.name));\n for (const name of manifest.dialogTemplates) {\n if (!providedDialogTemplates.has(name)) {\n problems.push(`declares the dialog template '${name}' but provides no definition for it`);\n }\n }\n\n const providedThemes = new Set((bundle.themes ?? []).map((theme) => theme.name));\n for (const name of manifest.themes) {\n if (!providedThemes.has(name)) {\n problems.push(`declares the theme '${name}' but provides no definition for it`);\n }\n }\n\n problems.push(...validateDescriptors(bundle));\n return problems;\n}\n\nfunction validateDescriptors(bundle: ScenePackageBundle): string[] {\n const problems: string[] = [];\n const declared = new Set(bundle.manifest.components.map((name) => componentRegistryKey(bundle.manifest.name, name)));\n const described = new Set<string>();\n\n for (const descriptor of bundle.descriptors ?? []) {\n if (!declared.has(descriptor.component)) {\n problems.push(`describes '${descriptor.component}', which the manifest does not declare as a component`);\n }\n\n if (described.has(descriptor.component)) {\n problems.push(`describes '${descriptor.component}' more than once`);\n }\n\n described.add(descriptor.component);\n\n const paths = new Set<string>();\n for (const property of descriptor.properties) {\n if (paths.has(property.path)) {\n problems.push(`'${descriptor.component}' describes the property '${property.path}' more than once`);\n }\n\n paths.add(property.path);\n\n if (property.valueType === PropertyValueType.Collection && property.item === undefined) {\n problems.push(`'${descriptor.component}' describes the collection '${property.path}' without describing its items`);\n }\n\n if (property.valueType === PropertyValueType.Enum && (property.choices ?? []).length === 0) {\n problems.push(`'${descriptor.component}' describes the enum '${property.path}' without choices`);\n }\n }\n }\n\n return problems;\n}\n\n/**\n * Merges the component registries of several bundles into the single registry a renderer consumes.\n *\n * Keys carry their package name, so nothing collides and merge order does not matter — which package wins\n * a *bare* name is decided earlier, by `resolveComponentName` walking the profile's priority order.\n */\nexport function mergePackageRegistries(bundles: ScenePackageBundle[]): ComponentRegistry {\n return Object.assign({}, ...bundles.map((bundle) => bundle.components)) as ComponentRegistry;\n}\n"],"names":["componentRegistryKey","packageName","componentName","validatePackageBundle","bundle","problems","manifest","name","components","push","declared","Set","map","key","Object","keys","has","providedLayouts","layouts","layout","providedScreenTemplates","screenTemplates","template","providedDialogTemplates","dialogTemplates","providedThemes","themes","theme","validateDescriptors","described","descriptor","descriptors","component","add","paths","property","properties","path","valueType","PropertyValueType","Collection","item","undefined","Enum","choices","length","mergePackageRegistries","bundles","assign"],"mappings":";;AAAA;AACA;AAiEA;;;;;;;;;AASC,IACM,SAASA,oBAAAA,CAAqBC,WAAmB,EAAEC,aAAqB,EAAA;AAC3E,IAAA,OAAO,CAAA,EAAGD,WAAAA,CAAY,CAAC,EAAEC,aAAAA,CAAAA,CAAe;AAC5C;AAEA;;;;;;;;IASO,SAASC,qBAAAA,CAAsBC,MAA0B,EAAA;AAC5D,IAAA,MAAMC,WAAqB,EAAE;IAC7B,MAAM,EAAEC,QAAQ,EAAE,GAAGF,MAAAA;AAErB,IAAA,KAAK,MAAMG,IAAAA,IAAQD,QAAAA,CAASE,UAAU,CAAE;QACpC,IAAI,EAAER,oBAAAA,CAAqBM,QAAAA,CAASC,IAAI,EAAEA,IAAAA,CAAAA,IAASH,MAAAA,CAAOI,UAAS,CAAA,EAAI;AACnEH,YAAAA,QAAAA,CAASI,IAAI,CAAC,CAAC,wBAAwB,EAAEF,IAAAA,CAAK,wCAAwC,CAAC,CAAA;AAC3F,QAAA;AACJ,IAAA;AAEA,IAAA,MAAMG,QAAAA,GAAW,IAAIC,GAAAA,CAAIL,QAAAA,CAASE,UAAU,CAACI,GAAG,CAAC,CAACL,IAAAA,GAASP,oBAAAA,CAAqBM,QAAAA,CAASC,IAAI,EAAEA,IAAAA,CAAAA,CAAAA,CAAAA;AAC/F,IAAA,KAAK,MAAMM,GAAAA,IAAOC,MAAAA,CAAOC,IAAI,CAACX,MAAAA,CAAOI,UAAU,CAAA,CAAG;AAC9C,QAAA,IAAI,CAACE,QAAAA,CAASM,GAAG,CAACH,GAAAA,CAAAA,EAAM;AACpBR,YAAAA,QAAAA,CAASI,IAAI,CAAC,CAAC,WAAW,EAAEI,GAAAA,CAAI,sCAAsC,CAAC,CAAA;AAC3E,QAAA;AACJ,IAAA;AAEA,IAAA,MAAMI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EAAA,GAAMD,OAAAA,CAAQnC,GAAG,CAAC,CAACR,MAAAA,GAAWA,MAAAA,CAAOI,UAAU,CAAA,CAAA;AACzE;;"}
|
|
1
|
+
{"version":3,"file":"ScenePackageBundle.js","sources":["../../../packages/ScenePackageBundle.ts"],"sourcesContent":["// Copyright (c) Cratis. All rights reserved.\n// Licensed under the MIT license. See LICENSE file in the project root for full license information.\n\nimport { ComponentDescriptor, DialogTemplate, Layout, PackageKind, PropertyValueType, ScenePackage, Screen, ScreenTemplate, Theme } from '@cratis/scene.model';\nimport { IconAdapterRegistry, createIconAdapterRegistry } from '../icons/IconAdapterRegistry';\nimport { IconLibraryBundle } from '../icons/IconLibraryBundle';\nimport { ComponentRegistry } from '../renderer';\n\n/**\n * What a package actually ships to a React renderer, as opposed to what it *declares*.\n *\n * `ScenePackage` is the declaration — a name, a kind, dependencies, and the names of what it\n * contributes. It is deliberately platform-agnostic and lives in `Scene.Model`, because Stage's build and\n * Studio's design-time queries both read it without ever loading a component. A bundle is the other half:\n * the real React components, layouts, screens and themes behind those names, which only a renderer needs.\n *\n * A package publishes exactly one bundle, as a named export following its own name —\n * `primeReactPackage`, `cratisComponentsPackage`, `corePackage`. A host loads it from the module the\n * declaration's `ScenePackage.module` names.\n */\nexport interface ScenePackageBundle {\n /**\n * The package's own declaration. Its `components`, `layouts` and `themes` name lists must agree with\n * what this bundle actually provides — {@link validatePackageBundle} is what proves they do.\n */\n manifest: ScenePackage;\n\n /**\n * The components this package provides, keyed by {@link componentRegistryKey}.\n */\n components: ComponentRegistry;\n\n /**\n * The application shells this package provides, if any. Only a blueprint has these.\n */\n layouts?: Layout[];\n\n /**\n * The screen templates this package provides — the shapes that go inside a layout, each declaring\n * which of its parent's slots it fills.\n */\n screenTemplates?: ScreenTemplate[];\n\n /**\n * The dialog templates this package provides.\n */\n dialogTemplates?: DialogTemplate[];\n\n /**\n * Sample screens this package ships — a layout package's gallery, so a preview has real content to\n * put through the real engine rather than a mockup.\n */\n screens?: Screen[];\n\n /**\n * What can be edited on this package's components - one {@link ComponentDescriptor} per component that is\n * editable at design time. They are data, so Studio reads them without rendering anything, and they travel with\n * the components they describe rather than in a registry of their own. {@link validatePackageBundle} checks\n * that every descriptor names a component the manifest declares.\n */\n descriptors?: ComponentDescriptor[];\n\n /**\n * The themes this package ships, if any.\n */\n themes?: Theme[];\n\n /**\n * The icon catalog and renderer adapter of an icon-library package. Present exactly when the\n * manifest declares an icon library.\n */\n iconLibrary?: IconLibraryBundle;\n}\n\n/**\n * The key a component is registered and looked up under: the package that provides it, then the bare name\n * a screen refers to it by.\n *\n * A screen writes a bare name (`button`) or a package-qualified one (`PrimeReact.button`);\n * `resolveComponentName` turns either into a `{ name, package }` pair, and this turns that pair into the\n * registry key. Nothing should build this string by hand — the separator is an implementation detail of\n * the registry, deliberately not the `.` used for qualification in a screen, so a package name containing\n * dots stays unambiguous.\n */\nexport function componentRegistryKey(packageName: string, componentName: string): string {\n return `${packageName}:${componentName}`;\n}\n\n/**\n * Checks that a bundle provides everything its manifest declares, and declares everything it provides, and that\n * every descriptor it ships is for a component it declares and is well formed.\n *\n * A manifest that promises a component the bundle does not register renders as `UnresolvedComponent` at\n * runtime — a blank box, far from where the mistake was made. A component registered but not declared is\n * invisible to `resolveComponentName`, so a screen can never name it. Both are silent failures, which is\n * why every package's specs run this.\n */\nexport function validatePackageBundle(bundle: ScenePackageBundle): string[] {\n const problems: string[] = [];\n const { manifest } = bundle;\n\n for (const name of manifest.components) {\n if (!(componentRegistryKey(manifest.name, name) in bundle.components)) {\n problems.push(`declares the component '${name}' but registers no implementation for it`);\n }\n }\n\n const declared = new Set(manifest.components.map((name) => componentRegistryKey(manifest.name, name)));\n for (const key of Object.keys(bundle.components)) {\n if (!declared.has(key)) {\n problems.push(`registers '${key}', which the manifest does not declare`);\n }\n }\n\n const providedLayouts = new Set((bundle.layouts ?? []).map((layout) => layout.name));\n for (const name of manifest.layouts) {\n if (!providedLayouts.has(name)) {\n problems.push(`declares the layout '${name}' but provides no definition for it`);\n }\n }\n\n const providedScreenTemplates = new Set((bundle.screenTemplates ?? []).map((template) => template.name));\n for (const name of manifest.screenTemplates) {\n if (!providedScreenTemplates.has(name)) {\n problems.push(`declares the screen template '${name}' but provides no definition for it`);\n }\n }\n\n const providedDialogTemplates = new Set((bundle.dialogTemplates ?? []).map((template) => template.name));\n for (const name of manifest.dialogTemplates) {\n if (!providedDialogTemplates.has(name)) {\n problems.push(`declares the dialog template '${name}' but provides no definition for it`);\n }\n }\n\n const providedThemes = new Set((bundle.themes ?? []).map((theme) => theme.name));\n for (const name of manifest.themes) {\n if (!providedThemes.has(name)) {\n problems.push(`declares the theme '${name}' but provides no definition for it`);\n }\n }\n\n problems.push(...validateIconLibrary(bundle));\n problems.push(...validateDescriptors(bundle));\n\n return problems;\n}\n\nfunction validateIconLibrary(bundle: ScenePackageBundle): string[] {\n const problems: string[] = [];\n const { manifest, iconLibrary } = bundle;\n const declaresIconLibrary = manifest.kind === PackageKind.IconLibrary || manifest.iconLibrary !== undefined;\n\n if (manifest.kind === PackageKind.IconLibrary && !manifest.iconLibrary) {\n problems.push('is an icon library but declares no iconLibrary metadata');\n }\n\n if (manifest.kind !== PackageKind.IconLibrary && manifest.iconLibrary) {\n problems.push('declares iconLibrary metadata but is not of kind IconLibrary');\n }\n\n if (declaresIconLibrary && !iconLibrary) {\n problems.push('declares an icon library but the bundle provides no catalog or adapter for it');\n }\n\n if (!declaresIconLibrary && iconLibrary) {\n problems.push('provides an icon catalog and adapter, which the manifest does not declare');\n }\n\n if (iconLibrary) {\n if (iconLibrary.catalog.library !== manifest.name) {\n problems.push(`provides an icon catalog for '${iconLibrary.catalog.library}' instead of '${manifest.name}'`);\n }\n\n if (iconLibrary.adapter.library !== manifest.name) {\n problems.push(`provides an icon adapter for '${iconLibrary.adapter.library}' instead of '${manifest.name}'`);\n }\n\n if (manifest.iconLibrary && !manifest.iconLibrary.renderers.includes('react')) {\n problems.push(\"provides a React icon adapter but does not list 'react' among its icon renderers\");\n }\n }\n\n return problems;\n}\n\nfunction validateDescriptors(bundle: ScenePackageBundle): string[] {\n const problems: string[] = [];\n const declared = new Set(bundle.manifest.components.map((name) => componentRegistryKey(bundle.manifest.name, name)));\n const described = new Set<string>();\n\n for (const descriptor of bundle.descriptors ?? []) {\n if (!declared.has(descriptor.component)) {\n problems.push(`describes '${descriptor.component}', which the manifest does not declare as a component`);\n }\n\n if (described.has(descriptor.component)) {\n problems.push(`describes '${descriptor.component}' more than once`);\n }\n\n described.add(descriptor.component);\n\n const paths = new Set<string>();\n for (const property of descriptor.properties) {\n if (paths.has(property.path)) {\n problems.push(`'${descriptor.component}' describes the property '${property.path}' more than once`);\n }\n\n paths.add(property.path);\n\n if (property.valueType === PropertyValueType.Collection && property.item === undefined) {\n problems.push(`'${descriptor.component}' describes the collection '${property.path}' without describing its items`);\n }\n\n if (property.valueType === PropertyValueType.Enum && (property.choices ?? []).length === 0) {\n problems.push(`'${descriptor.component}' describes the enum '${property.path}' without choices`);\n }\n }\n }\n\n return problems;\n}\n\n/**\n * Merges the component registries of several bundles into the single registry a renderer consumes.\n *\n * Keys carry their package name, so nothing collides and merge order does not matter — which package wins\n * a *bare* name is decided earlier, by `resolveComponentName` walking the profile's priority order.\n */\nexport function mergePackageRegistries(bundles: ScenePackageBundle[]): ComponentRegistry {\n return Object.assign({}, ...bundles.map((bundle) => bundle.components)) as ComponentRegistry;\n}\n\n/**\n * Collects the icon adapters of several bundles into the registry `SceneIcon` renders through.\n *\n * @throws Error when two bundles provide an adapter for the same library.\n */\nexport function mergeIconAdapters(bundles: ScenePackageBundle[]): IconAdapterRegistry {\n return createIconAdapterRegistry(bundles.flatMap((bundle) => (bundle.iconLibrary ? [bundle.iconLibrary.adapter] : [])));\n}\n"],"names":["componentRegistryKey","packageName","componentName","validatePackageBundle","bundle","problems","manifest","name","components","push","declared","Set","map","key","Object","keys","has","providedLayouts","layouts","layout","providedScreenTemplates","screenTemplates","template","providedDialogTemplates","dialogTemplates","providedThemes","themes","theme","validateIconLibrary","validateDescriptors","iconLibrary","declaresIconLibrary","kind","PackageKind","IconLibrary","undefined","catalog","library","adapter","renderers","includes","described","descriptor","descriptors","component","add","paths","property","properties","path","valueType","PropertyValueType","Collection","item","Enum","choices","length","mergePackageRegistries","bundles","assign","mergeIconAdapters","createIconAdapterRegistry","flatMap"],"mappings":";;;AAAA;AACA;AAyEA;;;;;;;;;AASC,IACM,SAASA,oBAAAA,CAAqBC,WAAmB,EAAEC,aAAqB,EAAA;AAC3E,IAAA,OAAO,CAAA,EAAGD,WAAAA,CAAY,CAAC,EAAEC,aAAAA,CAAAA,CAAe;AAC5C;AAEA;;;;;;;;IASO,SAASC,qBAAAA,CAAsBC,MAA0B,EAAA;AAC5D,IAAA,MAAMC,WAAqB,EAAE;IAC7B,MAAM,EAAEC,QAAQ,EAAE,GAAGF,MAAAA;AAErB,IAAA,KAAK,MAAMG,IAAAA,IAAQD,QAAAA,CAASE,UAAU,CAAE;QACpC,IAAI,EAAER,oBAAAA,CAAqBM,QAAAA,CAASC,IAAI,EAAEA,IAAAA,CAAAA,IAASH,MAAAA,CAAOI,UAAS,CAAA,EAAI;AACnEH,YAAAA,QAAAA,CAASI,IAAI,CAAC,CAAC,wBAAwB,EAAEF,IAAAA,CAAK,wCAAwC,CAAC,CAAA;AAC3F,QAAA;AACJ,IAAA;AAEA,IAAA,MAAMG,QAAAA,GAAW,IAAIC,GAAAA,CAAIL,QAAAA,CAASE,UAAU,CAACI,GAAG,CAAC,CAACL,IAAAA,GAASP,oBAAAA,CAAqBM,QAAAA,CAASC,IAAI,EAAEA,IAAAA,CAAAA,CAAAA,CAAAA;AAC/F,IAAA,KAAK,MAAMM,GAAAA,IAAOC,MAAAA,CAAOC,IAAI,CAACX,MAAAA,CAAOI,UAAU,CAAA,CAAG;AAC9C,QAAA,IAAI,CAACE,QAAAA,CAASM,GAAG,CAACH,GAAAA,CAAAA,EAAM;AACpBR,YAAAA,QAAAA,CAASI,IAAI,CAAC,CAAC,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