@astrale-os/sdk 0.6.0-beta.60 → 0.6.0-beta.62
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 +24 -6
- package/dist/application/define.d.ts +10 -3
- package/dist/application/define.js +3 -3
- package/dist/application/domain.d.ts +4 -1
- package/dist/application/error/error.js +1 -1
- package/dist/deployment/build/build.d.ts +1 -1
- package/dist/deployment/build/compile.js +6 -1
- package/dist/deployment/build/material.js +2 -2
- package/dist/platform/schema/class-icon-svg.d.ts +10 -0
- package/dist/platform/schema/class-icon-svg.js +39 -6
- package/dist/platform/schema/domain-icon.d.ts +43 -0
- package/dist/platform/schema/domain-icon.js +102 -0
- package/dist/platform/schema/index.d.ts +2 -0
- package/dist/platform/schema/index.js +1 -0
- package/dist/platform/schema/kernel-compiled.d.ts +1 -1
- package/dist/platform/schema/kernel-compiled.js +2 -2
- package/dist/tooling/cli/icons.d.ts +12 -0
- package/dist/tooling/cli/icons.js +56 -0
- package/dist/tooling/cli/orchestrate.js +4 -0
- package/dist/tooling/linter/implementations/source/schema.js +58 -0
- package/dist/tooling/linter/policy/generated.js +2 -2
- package/dist/tooling/linter/requirements/registry.js +1 -0
- package/package.json +7 -6
package/README.md
CHANGED
|
@@ -454,15 +454,33 @@ Apache License 2.0 — see [LICENSE](LICENSE) for details.
|
|
|
454
454
|
|
|
455
455
|
## Domain icon
|
|
456
456
|
|
|
457
|
-
|
|
458
|
-
import { classIcon } from '@astrale-os/sdk/schema'
|
|
459
|
-
import { Building2 } from '@astrale-os/sdk/schema/icons'
|
|
457
|
+
A Domain declares its icon in its root Schema, in up to three hand-drawn sizes of inline SVG:
|
|
460
458
|
|
|
461
|
-
|
|
459
|
+
```ts
|
|
460
|
+
import { defineSchema, domainIcon } from '@astrale-os/sdk/schema'
|
|
461
|
+
|
|
462
|
+
export const schema = defineSchema('notes.example', {
|
|
463
|
+
name: 'Notes',
|
|
464
|
+
icon: domainIcon({
|
|
465
|
+
small: { svg: SMALL_SVG, dark: SMALL_DARK_SVG }, // 16 to 24 px, viewBox 0 0 24 24
|
|
466
|
+
medium: MEDIUM_SVG, // 28 to 96 px, viewBox 0 0 64 64
|
|
467
|
+
large: LARGE_SVG, // 128 px and more, viewBox 0 0 512 512
|
|
468
|
+
}),
|
|
469
|
+
})
|
|
462
470
|
```
|
|
463
471
|
|
|
464
|
-
|
|
465
|
-
|
|
472
|
+
Every Domain must declare an icon with at least a `small` size: the linter fails otherwise
|
|
473
|
+
(`SCH-DOMAIN-ICON`). Each size takes an SVG string (a `classIcon.svg(...)` value is one) or
|
|
474
|
+
`{ svg, dark? }`, checked with the Kernel's own rules: 8 KiB for `small`, 32 KiB for `medium`,
|
|
475
|
+
256 KiB for `large`, in UTF-8 bytes, dark variants included. Gradients, filters and masks may
|
|
476
|
+
reference elements of the same SVG with `url(#id)`; any other `url(`, the `style` attribute and
|
|
477
|
+
external references are refused. The CLI warns when SVGO (2 decimals) would shrink an icon:
|
|
478
|
+
optimize the source SVG (for example with `npx svgo`), since the icon is part of the Schema
|
|
479
|
+
revision.
|
|
480
|
+
|
|
481
|
+
The release also publishes the `small` SVG as `manifest.logo` for older Kernels. The former
|
|
482
|
+
`defineDomain({ schema, runtime, icon })` is deprecated: it only feeds that `logo`, and only when
|
|
483
|
+
the Schema declares no icon.
|
|
466
484
|
|
|
467
485
|
## View host requirements
|
|
468
486
|
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type { ClassIcon, schema } from '../platform/schema/index.js';
|
|
1
|
+
import type { ClassIcon, DomainIcon, schema } from '../platform/schema/index.js';
|
|
2
2
|
import type { DomainDefinition } from './domain.js';
|
|
3
3
|
import type { Requirements } from './requirements/index.js';
|
|
4
4
|
import type { Routes } from './routes/index.js';
|
|
@@ -10,8 +10,15 @@ export interface DomainDefinitionInput<Schema extends schema.DomainSchema, Runti
|
|
|
10
10
|
readonly frontend?: FrontendValue;
|
|
11
11
|
readonly routes?: RoutesValue;
|
|
12
12
|
readonly requirements?: RequirementsValue;
|
|
13
|
-
/**
|
|
14
|
-
|
|
13
|
+
/**
|
|
14
|
+
* The application's release logo.
|
|
15
|
+
*
|
|
16
|
+
* @deprecated Declare the Domain icon in its Schema instead:
|
|
17
|
+
* `defineSchema(origin, { name, icon: domainIcon({ small, medium, large }) })`. This value only
|
|
18
|
+
* feeds the release manifest `logo` for Kernels that predate Schema icons, and is ignored when the
|
|
19
|
+
* Schema declares an icon.
|
|
20
|
+
*/
|
|
21
|
+
readonly icon?: ClassIcon | DomainIcon;
|
|
15
22
|
}
|
|
16
23
|
/** Capture one inert authored Domain without resolving, compiling, loading, or deploying it. */
|
|
17
24
|
export declare function defineDomain<const Schema extends schema.DomainSchema, const RuntimeValue extends Runtime<Schema>, const FrontendValue extends Frontend<Schema> | undefined = undefined, const RoutesValue extends Routes | undefined = undefined, const RequirementsValue extends Requirements | undefined = undefined>(input: DomainDefinitionInput<Schema, RuntimeValue, FrontendValue, RoutesValue, RequirementsValue>): DomainDefinition<Schema, RuntimeValue, FrontendValue, RoutesValue, RequirementsValue>;
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { domainLogo } from '../platform/schema/domain-icon.js';
|
|
2
2
|
import { isRequirements } from './requirements/index.js';
|
|
3
3
|
import { isRoutes } from './routes/index.js';
|
|
4
4
|
import { isRuntime } from './runtime/index.js';
|
|
@@ -33,8 +33,8 @@ export function defineDomain(input) {
|
|
|
33
33
|
if (input.requirements !== undefined && !isRequirements(input.requirements)) {
|
|
34
34
|
throw new TypeError('Domain requirements are not admitted.');
|
|
35
35
|
}
|
|
36
|
-
// The
|
|
37
|
-
const icon = input.icon === undefined ? undefined :
|
|
36
|
+
// The release logo is the `small` size: one self-contained inline SVG.
|
|
37
|
+
const icon = input.icon === undefined ? undefined : domainLogo(input.icon);
|
|
38
38
|
const domain = Object.freeze({
|
|
39
39
|
schema: input.schema,
|
|
40
40
|
runtime: input.runtime,
|
|
@@ -16,7 +16,10 @@ export interface DomainDefinition<Schema extends schema.DomainSchema = schema.Do
|
|
|
16
16
|
readonly frontend?: FrontendValue;
|
|
17
17
|
readonly routes?: RoutesValue;
|
|
18
18
|
readonly requirements?: RequirementsValue;
|
|
19
|
-
/**
|
|
19
|
+
/**
|
|
20
|
+
* The release manifest `logo`: the `small` size of the deprecated `defineDomain({ icon })`.
|
|
21
|
+
* A Schema icon (`defineSchema(origin, { name, icon })`) takes precedence over it.
|
|
22
|
+
*/
|
|
20
23
|
readonly icon?: ClassIcon;
|
|
21
24
|
readonly [DOMAIN_DEFINITION_SCHEMA]: (schema: Schema) => Schema;
|
|
22
25
|
}
|
|
@@ -56,7 +56,7 @@ export function declaredErrorFactory(definition) {
|
|
|
56
56
|
}
|
|
57
57
|
let details;
|
|
58
58
|
try {
|
|
59
|
-
const accepted = value.accept(parsed.data
|
|
59
|
+
const accepted = value.accept(parsed.data);
|
|
60
60
|
value.json.encode(accepted, { limits: { maxBytes: MAXIMUM_DETAILS_BYTES } });
|
|
61
61
|
if (!isRecord(accepted))
|
|
62
62
|
throw new TypeError('Details must be an object.');
|
|
@@ -19,6 +19,6 @@ export interface Build<Schema extends schema.DomainSchema = schema.DomainSchema,
|
|
|
19
19
|
*/
|
|
20
20
|
export type BuildRequirements = release.Requirements;
|
|
21
21
|
export interface BuildPresentation {
|
|
22
|
-
/**
|
|
22
|
+
/** The release `logo`: the `small` Domain icon, one self-contained inline SVG. */
|
|
23
23
|
readonly icon?: string;
|
|
24
24
|
}
|
|
@@ -2,6 +2,7 @@ import { artifact as artifactProtocol, release, routes } from '@astrale-os/kerne
|
|
|
2
2
|
import { isDomainDefinition } from '../../application/index.js';
|
|
3
3
|
import { admit as admitRoutes } from '../../application/routes/index.js';
|
|
4
4
|
import { admitRuntimeRegistry } from '../../application/runtime/index.js';
|
|
5
|
+
import { schemaIcon } from '../../platform/schema/domain-icon.js';
|
|
5
6
|
import { bundle } from '../../platform/schema/index.js';
|
|
6
7
|
import { schema as schemaApi } from '../../platform/schema/index.js';
|
|
7
8
|
import { admitBuild } from './admission.js';
|
|
@@ -20,7 +21,11 @@ export function compile(definition) {
|
|
|
20
21
|
const compiled = schemaApi.compile(definition.schema);
|
|
21
22
|
const requirements = compileRequirements(domain, definition.requirements, sourceBundle);
|
|
22
23
|
const frontend = compileFrontend(definition.frontend, domain);
|
|
23
|
-
|
|
24
|
+
// A Schema icon owns the release logo (the Kernel refuses a release whose logo differs from its
|
|
25
|
+
// `small` SVG); the deprecated `defineDomain({ icon })` serves only Schemas that declare none.
|
|
26
|
+
const declared = schemaIcon(definition.schema);
|
|
27
|
+
const logo = declared === undefined ? definition.icon : declared.small?.svg;
|
|
28
|
+
const presentation = logo === undefined ? undefined : Object.freeze({ icon: logo });
|
|
24
29
|
const plan = routes.compile({
|
|
25
30
|
domain,
|
|
26
31
|
routes: admitRoutes(definition.routes, registry),
|
|
@@ -8,7 +8,7 @@ import { BUNDLE_MEDIA_TYPE } from '@astrale-os/kernel-protocol/release';
|
|
|
8
8
|
import { admitRequirements, validateRequirements } from '@astrale-os/kernel-protocol/release';
|
|
9
9
|
import * as routes from '@astrale-os/kernel-protocol/routes';
|
|
10
10
|
import { admitRuntimeRegistry, isRuntime } from '../../application/runtime/index.js';
|
|
11
|
-
import {
|
|
11
|
+
import { admitIconSvgWithin, SMALL_DOMAIN_ICON_MAX_BYTES, } from '../../platform/schema/class-icon-svg.js';
|
|
12
12
|
import { admitBuild, isBuild } from './admission.js';
|
|
13
13
|
/** Detach the provider-neutral, runtime-free material embedded into generated execution code. */
|
|
14
14
|
export function material(build) {
|
|
@@ -195,7 +195,7 @@ function admitPresentation(input) {
|
|
|
195
195
|
return Object.freeze({});
|
|
196
196
|
if (typeof icon !== 'string')
|
|
197
197
|
invalid();
|
|
198
|
-
const admitted =
|
|
198
|
+
const admitted = admitIconSvgWithin(icon, 'Domain icon small', SMALL_DOMAIN_ICON_MAX_BYTES);
|
|
199
199
|
// Material carries an exact admitted value, rather than authored text to normalize.
|
|
200
200
|
if (admitted !== icon)
|
|
201
201
|
invalid();
|
|
@@ -6,4 +6,14 @@ export type ClassIcon = string & {
|
|
|
6
6
|
/** Stable empty SVG used when an author explicitly chooses to render no icon glyph. */
|
|
7
7
|
export declare const NEUTRAL_CLASS_ICON_SVG = "<svg xmlns=\"http://www.w3.org/2000/svg\" viewBox=\"0 0 24 24\"></svg>";
|
|
8
8
|
export declare function admitClassIconSvg(source: string): ClassIcon;
|
|
9
|
+
/**
|
|
10
|
+
* Bound of a Domain icon `small` SVG in UTF-8 bytes, the Kernel's `metadata.domainIcon.small`. Kept
|
|
11
|
+
* here so worker-side code can re-admit the release logo without loading the Kernel builder.
|
|
12
|
+
*/
|
|
13
|
+
export declare const SMALL_DOMAIN_ICON_MAX_BYTES = 8192;
|
|
14
|
+
/**
|
|
15
|
+
* Admit one inline SVG under a UTF-8 byte bound, with the same content rules as a Class icon.
|
|
16
|
+
* Worker-side re-admission of an already admitted Domain icon size uses it.
|
|
17
|
+
*/
|
|
18
|
+
export declare function admitIconSvgWithin(source: string, label: string, maxBytes: number): ClassIcon;
|
|
9
19
|
export {};
|
|
@@ -3,7 +3,10 @@ const SVG_ROOT = /^<svg(?:\s[^>]*)?>[\s\S]*<\/svg>$/u;
|
|
|
3
3
|
const SVG_ROOT_OPEN = /<svg(?:\s|>)/gu;
|
|
4
4
|
const SVG_ROOT_CLOSE = /<\/svg\s*>/gu;
|
|
5
5
|
const SVG_GRAPHIC = /<(?:circle|ellipse|line|path|polygon|polyline|rect)\b/iu;
|
|
6
|
-
const UNSAFE_SVG = /<\s*(?:animate|discard|embed|foreignObject|iframe|image|object|script|set|style|use)\b|<!DOCTYPE\b|<!ENTITY\b|\son[a-z][\w:.-]*\s*=|(?:href|xlink:href)\s*=|javascript\s
|
|
6
|
+
const UNSAFE_SVG = /<\s*(?:animate|discard|embed|foreignObject|iframe|image|object|script|set|style|use)\b|<!DOCTYPE\b|<!ENTITY\b|\son[a-z][\w:.-]*\s*=|\sstyle\s*=|(?:href|xlink:href)\s*=|javascript\s*:/iu;
|
|
7
|
+
/** The one admitted `url(...)` form: a fragment reference to an element of the same SVG. */
|
|
8
|
+
const INTERNAL_URL = /url\(#[A-Za-z][A-Za-z0-9_-]*\)/gu;
|
|
9
|
+
const ANY_URL = /url\s*\(/iu;
|
|
7
10
|
/** Stable empty SVG used when an author explicitly chooses to render no icon glyph. */
|
|
8
11
|
export const NEUTRAL_CLASS_ICON_SVG = '<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24"></svg>';
|
|
9
12
|
export function admitClassIconSvg(source) {
|
|
@@ -14,16 +17,46 @@ export function admitClassIconSvg(source) {
|
|
|
14
17
|
if (Array.from(value).length > MAX_CLASS_ICON_LENGTH) {
|
|
15
18
|
throw new TypeError(`Class icon must contain at most ${MAX_CLASS_ICON_LENGTH} characters.`);
|
|
16
19
|
}
|
|
20
|
+
admitSvgContent(value, 'Class icon');
|
|
21
|
+
return value;
|
|
22
|
+
}
|
|
23
|
+
/**
|
|
24
|
+
* Bound of a Domain icon `small` SVG in UTF-8 bytes, the Kernel's `metadata.domainIcon.small`. Kept
|
|
25
|
+
* here so worker-side code can re-admit the release logo without loading the Kernel builder.
|
|
26
|
+
*/
|
|
27
|
+
export const SMALL_DOMAIN_ICON_MAX_BYTES = 8_192;
|
|
28
|
+
/**
|
|
29
|
+
* Admit one inline SVG under a UTF-8 byte bound, with the same content rules as a Class icon.
|
|
30
|
+
* Worker-side re-admission of an already admitted Domain icon size uses it.
|
|
31
|
+
*/
|
|
32
|
+
export function admitIconSvgWithin(source, label, maxBytes) {
|
|
33
|
+
if (typeof source !== 'string') {
|
|
34
|
+
throw new TypeError(`${label} must be an inline SVG string.`);
|
|
35
|
+
}
|
|
36
|
+
const value = source.trim();
|
|
37
|
+
const bytes = new TextEncoder().encode(value).byteLength;
|
|
38
|
+
if (bytes > maxBytes) {
|
|
39
|
+
throw new TypeError(`${label} must contain at most ${maxBytes} UTF-8 bytes; it has ${bytes}.`);
|
|
40
|
+
}
|
|
41
|
+
admitSvgContent(value, label);
|
|
42
|
+
// Unlike a Class icon, a Domain icon size always draws: the neutral SVG is no exception.
|
|
43
|
+
if (!SVG_GRAPHIC.test(value)) {
|
|
44
|
+
throw new TypeError(`${label} SVG must contain a visible vector element.`);
|
|
45
|
+
}
|
|
46
|
+
return value;
|
|
47
|
+
}
|
|
48
|
+
function admitSvgContent(value, label) {
|
|
17
49
|
if (!SVG_ROOT.test(value) ||
|
|
18
50
|
(value.match(SVG_ROOT_OPEN)?.length ?? 0) !== 1 ||
|
|
19
51
|
(value.match(SVG_ROOT_CLOSE)?.length ?? 0) !== 1) {
|
|
20
|
-
throw new TypeError(
|
|
52
|
+
throw new TypeError(`${label} must be one complete inline <svg> element.`);
|
|
21
53
|
}
|
|
22
|
-
|
|
23
|
-
|
|
54
|
+
// `url(#id)` reaches gradients, filters, masks and clip paths inside the same SVG; every other
|
|
55
|
+
// `url(` form may fetch an external resource and stays refused.
|
|
56
|
+
if (UNSAFE_SVG.test(value) || ANY_URL.test(value.replace(INTERNAL_URL, ''))) {
|
|
57
|
+
throw new TypeError(`${label} SVG must be self-contained and contain no executable content.`);
|
|
24
58
|
}
|
|
25
59
|
if (value !== NEUTRAL_CLASS_ICON_SVG && !SVG_GRAPHIC.test(value)) {
|
|
26
|
-
throw new TypeError(
|
|
60
|
+
throw new TypeError(`${label} SVG must contain a visible vector element.`);
|
|
27
61
|
}
|
|
28
|
-
return value;
|
|
29
62
|
}
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
import type { DomainIcon } from '@astrale-os/kernel-dsl/v1';
|
|
2
|
+
import { metadata } from '@astrale-os/kernel-dsl/v1';
|
|
3
|
+
import type { ClassIcon } from './class-icon-svg.js';
|
|
4
|
+
export type { DomainIcon, DomainIconArt } from '@astrale-os/kernel-dsl/v1';
|
|
5
|
+
export type DomainIconSize = (typeof metadata.DOMAIN_ICON_SIZES)[number];
|
|
6
|
+
/** One size as authored: an SVG string (a `ClassIcon` is one), or its light and dark variants. */
|
|
7
|
+
export type DomainIconArtInput = string | {
|
|
8
|
+
readonly svg: string;
|
|
9
|
+
readonly dark?: string;
|
|
10
|
+
};
|
|
11
|
+
export type DomainIconInput = {
|
|
12
|
+
readonly [Size in DomainIconSize]?: DomainIconArtInput;
|
|
13
|
+
};
|
|
14
|
+
/** The sizes of a Domain icon, smallest first. Owned by the Kernel. */
|
|
15
|
+
export declare const DOMAIN_ICON_SIZES: readonly DomainIconSize[];
|
|
16
|
+
/** Bound of each SVG string of a size, light and dark alike, in UTF-8 bytes. Owned by the Kernel. */
|
|
17
|
+
export declare const DOMAIN_ICON_MAX_BYTES: Readonly<Record<DomainIconSize, number>>;
|
|
18
|
+
/** Expected viewBox of each size. Advisory: the drawing grid, not an admission rule. */
|
|
19
|
+
export declare const DOMAIN_ICON_VIEW_BOX: Readonly<Record<DomainIconSize, string>>;
|
|
20
|
+
/**
|
|
21
|
+
* Admit a Domain icon for `defineSchema(origin, { name, icon })`. Each size takes an SVG string or
|
|
22
|
+
* `{ svg, dark? }`; every SVG is trimmed, then checked with the Kernel's own admission (internal
|
|
23
|
+
* `url(#id)` allowed, no `style` attribute, no external reference, the size's byte bound), so an
|
|
24
|
+
* icon `domainIcon` accepts is one the Kernel installs.
|
|
25
|
+
*/
|
|
26
|
+
export declare function domainIcon(input: DomainIconInput): DomainIcon;
|
|
27
|
+
/**
|
|
28
|
+
* Re-admit an icon received as data (Build material, a loaded Schema) and require it to be exactly
|
|
29
|
+
* what authoring admits: no normalization happens on this path.
|
|
30
|
+
*/
|
|
31
|
+
export declare function admitDomainIcon(input: unknown): DomainIcon;
|
|
32
|
+
/** One SVG drawing of a Domain icon size, trimmed and admitted by the Kernel's rule. */
|
|
33
|
+
export declare function admitDomainIconSvg(source: string, size: DomainIconSize, label?: string): ClassIcon;
|
|
34
|
+
/**
|
|
35
|
+
* The release manifest `logo` of an icon: the `small` size, as one admitted SVG. An SVG string is
|
|
36
|
+
* the former single-size Domain icon, which the Kernel reads as `small`.
|
|
37
|
+
*/
|
|
38
|
+
export declare function domainLogo(icon: string | DomainIconInput): ClassIcon | undefined;
|
|
39
|
+
/**
|
|
40
|
+
* The icon a Domain Schema declares at its root (`defineSchema(origin, { name, icon })`), admitted,
|
|
41
|
+
* or `undefined` when it declares none.
|
|
42
|
+
*/
|
|
43
|
+
export declare function schemaIcon(schema: object): DomainIcon | undefined;
|
|
@@ -0,0 +1,102 @@
|
|
|
1
|
+
import { metadata } from '@astrale-os/kernel-dsl/v1';
|
|
2
|
+
/** The sizes of a Domain icon, smallest first. Owned by the Kernel. */
|
|
3
|
+
export const DOMAIN_ICON_SIZES = metadata.DOMAIN_ICON_SIZES;
|
|
4
|
+
/** Bound of each SVG string of a size, light and dark alike, in UTF-8 bytes. Owned by the Kernel. */
|
|
5
|
+
export const DOMAIN_ICON_MAX_BYTES = metadata.domainIcon;
|
|
6
|
+
/** Expected viewBox of each size. Advisory: the drawing grid, not an admission rule. */
|
|
7
|
+
export const DOMAIN_ICON_VIEW_BOX = Object.freeze({
|
|
8
|
+
small: '0 0 24 24',
|
|
9
|
+
medium: '0 0 64 64',
|
|
10
|
+
large: '0 0 512 512',
|
|
11
|
+
});
|
|
12
|
+
/**
|
|
13
|
+
* Admit a Domain icon for `defineSchema(origin, { name, icon })`. Each size takes an SVG string or
|
|
14
|
+
* `{ svg, dark? }`; every SVG is trimmed, then checked with the Kernel's own admission (internal
|
|
15
|
+
* `url(#id)` allowed, no `style` attribute, no external reference, the size's byte bound), so an
|
|
16
|
+
* icon `domainIcon` accepts is one the Kernel installs.
|
|
17
|
+
*/
|
|
18
|
+
export function domainIcon(input) {
|
|
19
|
+
if (input === null || typeof input !== 'object' || Array.isArray(input)) {
|
|
20
|
+
throw new TypeError('Domain icon must be an object with small, medium or large.');
|
|
21
|
+
}
|
|
22
|
+
const keys = Reflect.ownKeys(input);
|
|
23
|
+
if (keys.some((key) => !DOMAIN_ICON_SIZES.includes(key))) {
|
|
24
|
+
throw new TypeError('Domain icon may contain only small, medium and large.');
|
|
25
|
+
}
|
|
26
|
+
const icon = {};
|
|
27
|
+
for (const size of DOMAIN_ICON_SIZES) {
|
|
28
|
+
const art = input[size];
|
|
29
|
+
if (art !== undefined)
|
|
30
|
+
icon[size] = admitArt(size, art);
|
|
31
|
+
}
|
|
32
|
+
if (Object.keys(icon).length === 0) {
|
|
33
|
+
throw new TypeError('Domain icon must declare at least one size.');
|
|
34
|
+
}
|
|
35
|
+
return Object.freeze(icon);
|
|
36
|
+
}
|
|
37
|
+
/**
|
|
38
|
+
* Re-admit an icon received as data (Build material, a loaded Schema) and require it to be exactly
|
|
39
|
+
* what authoring admits: no normalization happens on this path.
|
|
40
|
+
*/
|
|
41
|
+
export function admitDomainIcon(input) {
|
|
42
|
+
const icon = domainIcon(input);
|
|
43
|
+
for (const size of DOMAIN_ICON_SIZES) {
|
|
44
|
+
const authored = input[size];
|
|
45
|
+
const admitted = icon[size];
|
|
46
|
+
if (authored === undefined)
|
|
47
|
+
continue;
|
|
48
|
+
if (typeof authored !== 'object' ||
|
|
49
|
+
Reflect.ownKeys(authored).some((key) => key !== 'svg' && key !== 'dark') ||
|
|
50
|
+
authored.svg !== admitted?.svg ||
|
|
51
|
+
authored.dark !== admitted?.dark) {
|
|
52
|
+
throw new TypeError('Domain icon is not in its admitted form.');
|
|
53
|
+
}
|
|
54
|
+
}
|
|
55
|
+
return icon;
|
|
56
|
+
}
|
|
57
|
+
function admitArt(size, art) {
|
|
58
|
+
const label = `Domain icon ${size}`;
|
|
59
|
+
if (typeof art === 'string')
|
|
60
|
+
return Object.freeze({ svg: admitDomainIconSvg(art, size, label) });
|
|
61
|
+
if (art === null || typeof art !== 'object' || Array.isArray(art)) {
|
|
62
|
+
throw new TypeError(`${label} must be an SVG string or { svg, dark? }.`);
|
|
63
|
+
}
|
|
64
|
+
if (Reflect.ownKeys(art).some((key) => key !== 'svg' && key !== 'dark')) {
|
|
65
|
+
throw new TypeError(`${label} may contain only svg and dark.`);
|
|
66
|
+
}
|
|
67
|
+
const svg = admitDomainIconSvg(art.svg, size, label);
|
|
68
|
+
if (art.dark === undefined)
|
|
69
|
+
return Object.freeze({ svg });
|
|
70
|
+
return Object.freeze({ svg, dark: admitDomainIconSvg(art.dark, size, `${label} dark`) });
|
|
71
|
+
}
|
|
72
|
+
/** One SVG drawing of a Domain icon size, trimmed and admitted by the Kernel's rule. */
|
|
73
|
+
export function admitDomainIconSvg(source, size, label = `Domain icon ${size}`) {
|
|
74
|
+
if (typeof source !== 'string')
|
|
75
|
+
throw new TypeError(`${label} must be an inline SVG string.`);
|
|
76
|
+
const svg = source.trim();
|
|
77
|
+
const issue = metadata.domainIconSvgIssue(svg, size);
|
|
78
|
+
if (issue !== undefined)
|
|
79
|
+
throw new TypeError(`${label} ${issue}.`);
|
|
80
|
+
return svg;
|
|
81
|
+
}
|
|
82
|
+
/**
|
|
83
|
+
* The release manifest `logo` of an icon: the `small` size, as one admitted SVG. An SVG string is
|
|
84
|
+
* the former single-size Domain icon, which the Kernel reads as `small`.
|
|
85
|
+
*/
|
|
86
|
+
export function domainLogo(icon) {
|
|
87
|
+
if (typeof icon === 'string') {
|
|
88
|
+
return admitDomainIconSvg(icon, 'small');
|
|
89
|
+
}
|
|
90
|
+
if (icon === null || typeof icon !== 'object') {
|
|
91
|
+
throw new TypeError('Domain icon must be an inline SVG string or domainIcon({ ... }).');
|
|
92
|
+
}
|
|
93
|
+
return domainIcon(icon).small?.svg;
|
|
94
|
+
}
|
|
95
|
+
/**
|
|
96
|
+
* The icon a Domain Schema declares at its root (`defineSchema(origin, { name, icon })`), admitted,
|
|
97
|
+
* or `undefined` when it declares none.
|
|
98
|
+
*/
|
|
99
|
+
export function schemaIcon(schema) {
|
|
100
|
+
const icon = schema.icon;
|
|
101
|
+
return icon === undefined ? undefined : admitDomainIcon(icon);
|
|
102
|
+
}
|
|
@@ -15,6 +15,8 @@ export { error } from './error.js';
|
|
|
15
15
|
export type { DeclaredErrorDefinition, DeclaredErrorFamily } from './error.js';
|
|
16
16
|
export { classIcon } from './class-icon.js';
|
|
17
17
|
export type { ClassIcon } from './class-icon.js';
|
|
18
|
+
export { DOMAIN_ICON_MAX_BYTES, DOMAIN_ICON_SIZES, DOMAIN_ICON_VIEW_BOX, domainIcon, } from './domain-icon.js';
|
|
19
|
+
export type { DomainIcon, DomainIconArt, DomainIconArtInput, DomainIconInput, DomainIconSize, } from './domain-icon.js';
|
|
18
20
|
export type { StoredPropertyInputOf } from './property-input.js';
|
|
19
21
|
export type { CallablePolicyBuilder, CallablePolicyContext, ClassRuleBuilder, ClassRuleContext, PolicyCheckContext, CallableProjection, AuthoredMethodProjection, AuthoredPropertyProjection, ClassIdentityProjection, ClassOwnerProjection, CoreEdge, CoreEndpoint, CoreNode, DefinedSchema, DirectedEdgeClass, ClassReferenceProjection, ClassProjection, FunctionProjection, EdgeClass, AutoOptions, AutoProperty, Function, Method, MethodProjection, Lazy, NodeClass, Policy, PolicyExistsContext, PolicyNodeBinder, PolicyPatternContext, Property, PropertyProjection, ResolvedDomainOfInput, View, } from '@astrale-os/kernel-dsl/v1/builder';
|
|
20
22
|
export type { Array, Object, Value } from '@astrale-os/kernel-dsl/value';
|
|
@@ -8,6 +8,7 @@ export { defineClass, edgeClass, nodeClass } from './class-authoring.js';
|
|
|
8
8
|
export { func, method } from './callable-authoring.js';
|
|
9
9
|
export { error } from './error.js';
|
|
10
10
|
export { classIcon } from './class-icon.js';
|
|
11
|
+
export { DOMAIN_ICON_MAX_BYTES, DOMAIN_ICON_SIZES, DOMAIN_ICON_VIEW_BOX, domainIcon, } from './domain-icon.js';
|
|
11
12
|
/** Kernel-owned Schema values used by authored product Schemas and graph operations. */
|
|
12
13
|
export { AuthorityOperationOrder, AuthorityOperations, AuthorityRelations, KernelRootFunctions, OperationCore, operationOf, } from '@astrale-os/kernel-core/schema';
|
|
13
14
|
export { K, KernelSchema } from './kernel.js';
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
/** Generated from the Kernel Schema of @astrale-os/kernel-core 1.0.0-beta.
|
|
1
|
+
/** Generated from the Kernel Schema of @astrale-os/kernel-core 1.0.0-beta.39, reduced to its Classes. Regenerate with pnpm sync:kernel-schema. */
|
|
2
2
|
export declare const kernelCompiledSchema: string;
|