@ingcreators/annot-core 0.1.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/CHANGELOG.md +7 -0
- package/LICENSE +201 -0
- package/README.md +56 -0
- package/dist/auto-capture-options.d.ts +78 -0
- package/dist/editor/arrow-markers.d.ts +142 -0
- package/dist/editor/bake-translate.d.ts +192 -0
- package/dist/editor/font-registry.d.ts +58 -0
- package/dist/editor/gradient-utils.d.ts +23 -0
- package/dist/editor/history-core.d.ts +48 -0
- package/dist/editor/icons/brand-icons.d.ts +53 -0
- package/dist/editor/icons/material-symbols.d.ts +105 -0
- package/dist/editor/icons/registry.d.ts +179 -0
- package/dist/editor/icons/render.d.ts +22 -0
- package/dist/editor/icons/sanitize.d.ts +60 -0
- package/dist/editor/index.d.ts +13 -0
- package/dist/editor/path-utils.d.ts +32 -0
- package/dist/editor/property-schema.d.ts +263 -0
- package/dist/editor/rich-text-mapper.d.ts +8 -0
- package/dist/editor/selection-geometry.d.ts +66 -0
- package/dist/editor/shape-utils.d.ts +27 -0
- package/dist/editor/svg-format.d.ts +68 -0
- package/dist/editor/svg-id-utils.d.ts +37 -0
- package/dist/editor/svg-to-annotation-shapes.d.ts +34 -0
- package/dist/editor/text-utils.d.ts +212 -0
- package/dist/editor/tool-lifecycle.d.ts +56 -0
- package/dist/editor/tool-options.d.ts +126 -0
- package/dist/editor/tool-panel-adapter.d.ts +105 -0
- package/dist/editor/tool-preset-serde.d.ts +43 -0
- package/dist/editor/tool-registry.d.ts +320 -0
- package/dist/editor/tool-style-reader.d.ts +36 -0
- package/dist/editor/tool-style-writer.d.ts +33 -0
- package/dist/editor/toolbar-icons.d.ts +84 -0
- package/dist/editor/transform-utils.d.ts +127 -0
- package/dist/editor/viewport-math.d.ts +69 -0
- package/dist/encode/index.d.ts +4 -0
- package/dist/encode/options.d.ts +79 -0
- package/dist/encode/png8.d.ts +10 -0
- package/dist/headless.d.ts +29 -0
- package/dist/icons/index.d.ts +15 -0
- package/dist/icons/types.d.ts +108 -0
- package/dist/index.d.ts +1 -0
- package/dist/index.js +3164 -0
- package/dist/storage/errors.d.ts +59 -0
- package/dist/storage/index.d.ts +6 -0
- package/dist/storage/metadata-cache.d.ts +231 -0
- package/dist/storage/path.d.ts +49 -0
- package/dist/storage/thumbnail-cache.d.ts +110 -0
- package/dist/storage/thumbnail.d.ts +31 -0
- package/dist/storage/types.d.ts +677 -0
- package/dist/utils/assert.d.ts +31 -0
- package/dist/utils/constants.d.ts +10 -0
- package/dist/utils/dash-utils.d.ts +6 -0
- package/dist/utils/desktop-bridge.d.ts +349 -0
- package/dist/utils/filename.d.ts +48 -0
- package/dist/utils/id.d.ts +21 -0
- package/dist/utils/index.d.ts +5 -0
- package/dist/utils/types.d.ts +20 -0
- package/dist/xmp/xmp-browser.d.ts +39 -0
- package/dist/zip/zip-builder.d.ts +8 -0
- package/dist/zip/zip-bytes.d.ts +22 -0
- package/package.json +58 -0
- package/styles/editor.css +1912 -0
- package/styles/fonts.css +46 -0
- package/styles/property-panel.css +779 -0
- package/styles/toolbar.css +673 -0
|
@@ -0,0 +1,69 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Default minimum / maximum zoom levels mirroring the historical
|
|
3
|
+
* `setZoom()` clamp inside `CanvasManager`. Exported so callers can
|
|
4
|
+
* stay aligned with the editor's published behavior.
|
|
5
|
+
*/
|
|
6
|
+
export declare const DEFAULT_MIN_ZOOM = 0.1;
|
|
7
|
+
export declare const DEFAULT_MAX_ZOOM = 5;
|
|
8
|
+
/**
|
|
9
|
+
* Padding (in CSS pixels) the editor reserves around the canvas when
|
|
10
|
+
* computing "Fit to window". Matches the historical magic number in
|
|
11
|
+
* CanvasManager.fitToView.
|
|
12
|
+
*/
|
|
13
|
+
export declare const FIT_VIEW_PADDING = 40;
|
|
14
|
+
/**
|
|
15
|
+
* Clamp `z` into the supported zoom range. Pure replacement for the
|
|
16
|
+
* inline `Math.max(min, Math.min(z, max))` previously embedded in
|
|
17
|
+
* `CanvasManager.setZoom`.
|
|
18
|
+
*/
|
|
19
|
+
export declare function clampZoom(z: number, min?: number, max?: number): number;
|
|
20
|
+
/**
|
|
21
|
+
* Compute the "Fit to window" zoom factor for an image of the given
|
|
22
|
+
* intrinsic size against a container. Padding is subtracted from the
|
|
23
|
+
* container dimensions before fitting (matching the historical
|
|
24
|
+
* editor behavior); the result is capped at `maxZoom` so a small
|
|
25
|
+
* image never scales above 1× in fit mode.
|
|
26
|
+
*
|
|
27
|
+
* Returns 0 when either container dimension would be ≤ 0 after
|
|
28
|
+
* padding, signalling "container not yet laid out — caller should
|
|
29
|
+
* skip this fit pass". This matches the legacy behavior of
|
|
30
|
+
* `Math.min(negativeNumber, 1)` becoming a non-positive scale that
|
|
31
|
+
* the editor effectively ignored when the surrounding container had
|
|
32
|
+
* not been measured yet.
|
|
33
|
+
*/
|
|
34
|
+
export declare function computeFitZoom(imageWidth: number, imageHeight: number, containerWidth: number, containerHeight: number, padding?: number, maxZoom?: number): number;
|
|
35
|
+
/**
|
|
36
|
+
* Compute the rendered pixel size of the canvas at a given zoom,
|
|
37
|
+
* rounding to integer device pixels (matching what CanvasManager
|
|
38
|
+
* writes into the `<svg>` element's width/height attributes).
|
|
39
|
+
*/
|
|
40
|
+
export declare function computeRenderedSize(imageWidth: number, imageHeight: number, zoom: number): {
|
|
41
|
+
width: number;
|
|
42
|
+
height: number;
|
|
43
|
+
};
|
|
44
|
+
/**
|
|
45
|
+
* 2D affine matrix expressed as a six-tuple `[a, b, c, d, e, f]`,
|
|
46
|
+
* applying the transform `(x, y) → (a*x + c*y + e, b*x + d*y + f)`.
|
|
47
|
+
*
|
|
48
|
+
* This matches the layout of `DOMMatrix` / `SVGMatrix` in the
|
|
49
|
+
* browser, so callers can populate it from `getScreenCTM()` via
|
|
50
|
+
* `[m.a, m.b, m.c, m.d, m.e, m.f]` and feed it to `applyInverse`
|
|
51
|
+
* without needing a real `DOMMatrix` instance under jsdom / Node.
|
|
52
|
+
*/
|
|
53
|
+
export type AffineMatrix = readonly [number, number, number, number, number, number];
|
|
54
|
+
/**
|
|
55
|
+
* Apply the inverse of a 2D affine matrix to a client-space point,
|
|
56
|
+
* yielding the corresponding SVG-space point. This is the pure-math
|
|
57
|
+
* core of `CanvasManager.svgPoint(e)`:
|
|
58
|
+
* 1. Read the live `getScreenCTM()` (browser-only, in CanvasManager).
|
|
59
|
+
* 2. Pass its components to `applyInverseAffine` along with the
|
|
60
|
+
* pointer's `clientX/clientY` (here).
|
|
61
|
+
*
|
|
62
|
+
* Throws if the matrix is singular (det ≈ 0); the editor never
|
|
63
|
+
* encounters this in practice because an unrendered `<svg>` returns
|
|
64
|
+
* `null` from `getScreenCTM()` and CanvasManager skips the call.
|
|
65
|
+
*/
|
|
66
|
+
export declare function applyInverseAffine(matrix: AffineMatrix, clientX: number, clientY: number): {
|
|
67
|
+
x: number;
|
|
68
|
+
y: number;
|
|
69
|
+
};
|
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
import { EncodeOptions, EncodeResult } from './options.js';
|
|
2
|
+
export { computeResizeTarget, DEFAULT_ENCODE_OPTIONS, type EncodeFormat, type EncodeOptions, type EncodeResult, SAVE_SIZE_LABEL, SAVE_SIZE_MAX_WIDTH, type SaveSizePreset, } from './options.js';
|
|
3
|
+
/** Encode a PNG data URL per the given options. */
|
|
4
|
+
export declare function encodeCapture(pngDataUrl: string, options?: EncodeOptions): Promise<EncodeResult>;
|
|
@@ -0,0 +1,79 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Encode option types + defaults — split out of `./index.ts` so callers
|
|
3
|
+
* that only need the data shape (e.g. the web app's preferences
|
|
4
|
+
* loader) can import this leaf without dragging in the WASM
|
|
5
|
+
* imagequant binding that `encodeCapture` requires. Keeps the
|
|
6
|
+
* encoder lazy-loadable as a separate chunk.
|
|
7
|
+
*/
|
|
8
|
+
export type EncodeFormat = "smart" | "png" | "jpeg";
|
|
9
|
+
/**
|
|
10
|
+
* Save size presets — apply a max-width cap to the image before
|
|
11
|
+
* encoding so 4K screenshots don't end up as 5–10 MB files.
|
|
12
|
+
* Values match the spec in
|
|
13
|
+
* `docs/plans/_done/web-capture-redesign.md`'s "Deferred" item.
|
|
14
|
+
*
|
|
15
|
+
* Aspect ratio is preserved; height scales proportionally. Images
|
|
16
|
+
* narrower than the preset's max-width pass through unscaled (we
|
|
17
|
+
* never upscale).
|
|
18
|
+
*/
|
|
19
|
+
export type SaveSizePreset = "light" | "standard" | "highQuality" | "original";
|
|
20
|
+
/** Mapping from preset → max-width in pixels (`null` = no resize). */
|
|
21
|
+
export declare const SAVE_SIZE_MAX_WIDTH: Record<SaveSizePreset, number | null>;
|
|
22
|
+
/** Human-readable label for the preset, used by the dialog selector
|
|
23
|
+
* + the (future) extension settings UI. Shared so both surfaces
|
|
24
|
+
* speak the same language. */
|
|
25
|
+
export declare const SAVE_SIZE_LABEL: Record<SaveSizePreset, string>;
|
|
26
|
+
export interface EncodeOptions {
|
|
27
|
+
/** "smart" | "png" | "jpeg" */
|
|
28
|
+
format: EncodeFormat;
|
|
29
|
+
/** Fallback format used by "smart" mode when the image is photo-heavy. */
|
|
30
|
+
smartFallback: "png" | "jpeg";
|
|
31
|
+
/**
|
|
32
|
+
* Heuristic: if a sampled pixel pass finds more unique RGBA colors than
|
|
33
|
+
* this threshold, treat the image as photo-heavy and skip PNG-8.
|
|
34
|
+
* Typical UI screenshots return <5000; photo-heavy pages return >20000.
|
|
35
|
+
*/
|
|
36
|
+
smartColorThreshold: number;
|
|
37
|
+
/** JPEG quality 60–100 (%). Used for "jpeg" and smart's JPEG fallback. */
|
|
38
|
+
jpegPercent: number;
|
|
39
|
+
/**
|
|
40
|
+
* Cap the encoded image's max width per
|
|
41
|
+
* {@link SAVE_SIZE_MAX_WIDTH}. Aspect-preserving down-scale; no
|
|
42
|
+
* upscale when the source is already narrower.
|
|
43
|
+
*
|
|
44
|
+
* Optional on the interface so existing callers that don't
|
|
45
|
+
* surface this knob (today: the Browser Extension's capture
|
|
46
|
+
* pipeline at `@ingcreators/annot-capture/shared/encode`) keep
|
|
47
|
+
* compiling without changes — `encodeCapture` treats `undefined`
|
|
48
|
+
* as `"original"` (no resize, identical pre-feature behaviour).
|
|
49
|
+
*
|
|
50
|
+
* `DEFAULT_ENCODE_OPTIONS` sets it to `"standard"` (1920px),
|
|
51
|
+
* which the Annot Web app's encode-options loader uses by
|
|
52
|
+
* default. Future extension settings UI work will wire its own
|
|
53
|
+
* `Settings.quality.saveSizePreset` field here.
|
|
54
|
+
*/
|
|
55
|
+
saveSizePreset?: SaveSizePreset;
|
|
56
|
+
}
|
|
57
|
+
export declare const DEFAULT_ENCODE_OPTIONS: EncodeOptions;
|
|
58
|
+
/** Compute the resize target for a given source size + preset.
|
|
59
|
+
* Returns the source dimensions unchanged when the preset is
|
|
60
|
+
* `"original"` or the source is already narrower than the cap.
|
|
61
|
+
* Pure helper — usable by both the encoder (during the
|
|
62
|
+
* re-encode pass) and the (future) extension settings UI for
|
|
63
|
+
* preview labels. */
|
|
64
|
+
export declare function computeResizeTarget(sourceWidth: number, sourceHeight: number, preset: SaveSizePreset): {
|
|
65
|
+
width: number;
|
|
66
|
+
height: number;
|
|
67
|
+
scaled: boolean;
|
|
68
|
+
};
|
|
69
|
+
export interface EncodeResult {
|
|
70
|
+
dataUrl: string;
|
|
71
|
+
/** Actual format chosen (may differ from requested in "smart" mode). */
|
|
72
|
+
chosen: "png" | "jpeg";
|
|
73
|
+
/** Human-readable note (e.g. "png-8", "photo-fallback") — useful for logs. */
|
|
74
|
+
reason?: string;
|
|
75
|
+
/** Final pixel dimensions of the encoded image. May differ from
|
|
76
|
+
* the input when `saveSizePreset` triggered a down-scale. */
|
|
77
|
+
width?: number;
|
|
78
|
+
height?: number;
|
|
79
|
+
}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Encode a palette + per-pixel indices buffer as a PNG-8 file.
|
|
3
|
+
*
|
|
4
|
+
* @param palette RGBA bytes per palette entry, length = 4 * N (1 ≤ N ≤ 256).
|
|
5
|
+
* @param indices One byte per pixel, length = width * height.
|
|
6
|
+
* @param width Image width in pixels.
|
|
7
|
+
* @param height Image height in pixels.
|
|
8
|
+
* @param level DEFLATE compression level 0–9 (default 9 = smallest file).
|
|
9
|
+
*/
|
|
10
|
+
export declare function encodePng8(palette: Uint8Array, indices: Uint8Array, width: number, height: number, level?: 0 | 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9): Uint8Array;
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
export { coerceToLogicalFamily, cssStackFor, isLogicalFamily, LOGICAL_FAMILIES, type LogicalFamily, ooxmlTypefacesFor, } from './editor/font-registry.js';
|
|
2
|
+
export { createHistoryCore, DEFAULT_HISTORY_DEPTH, type HistoryCore, type HistoryHooks, } from './editor/history-core.js';
|
|
3
|
+
export { BUILTIN_ICON_IDS, BUILTIN_ICONS, type BuiltinIconId, resolveBuiltinIcon, } from './editor/icons/registry.js';
|
|
4
|
+
export { renderIconElement, renderIconHtml } from './editor/icons/render.js';
|
|
5
|
+
export { sanitizeIconSvg } from './editor/icons/sanitize.js';
|
|
6
|
+
export { translatePathD } from './editor/path-utils.js';
|
|
7
|
+
export { CATEGORY_CONTROL_SHAPE, classifyPropertyElement, classifyPropertySelection, PROPERTY_CONTROL_IDS, PROPERTY_CONTROLS, PROPERTY_EFFECT_IDS, type PropertyCategory, type PropertyControlDef, type PropertyControlId, type PropertyControlOption, type PropertyControlType, type PropertyEffectId, } from './editor/property-schema.js';
|
|
8
|
+
export { computeSnap, cursorForAngle, type Rect, rotateAround, type SnapGuide, type SnapInput, type SnapResult, } from './editor/selection-geometry.js';
|
|
9
|
+
export { ANNOT_SVG_VERSION, ANNOT_SVG_VERSION_ATTR, ANNOT_SVG_VERSION_UNSTAMPED, getAnnotVersionFromString, readAnnotVersion, stampAnnotVersion, } from './editor/svg-format.js';
|
|
10
|
+
export { createMockToolSurface, type MockToolSurface, type ToolDOMSurface, } from './editor/tool-lifecycle.js';
|
|
11
|
+
export { selectionDefMetadata, TOOL_PANEL_ADAPTER_IDS, TOOL_PANEL_ADAPTERS, type ToolPanelAdapter, type ToolPanelAdapterId, type ToolPanelAdapterMetadata, } from './editor/tool-panel-adapter.js';
|
|
12
|
+
export { fieldForSnakeKey, type PresetWireFormat, presetFromWire, presetToWire, } from './editor/tool-preset-serde.js';
|
|
13
|
+
export { normalizeVariantSideFields, TOOL_PANEL_EXTRA_CONTROL_IDS, TOOL_REGISTRY, TOOL_REGISTRY_IDS, type ToolPanelControlDef, type ToolPanelExtraControlId, type ToolPanelSection, type ToolRegistryEntry, type ToolRegistryId, type ToolRegistryVariant, } from './editor/tool-registry.js';
|
|
14
|
+
export { readUniversalStyleAttrs, resolveStyleReadSource, } from './editor/tool-style-reader.js';
|
|
15
|
+
export { writeUniversalStyleAttrs } from './editor/tool-style-writer.js';
|
|
16
|
+
export { type AffineMatrix, applyInverseAffine, clampZoom, computeFitZoom, computeRenderedSize, DEFAULT_MAX_ZOOM, DEFAULT_MIN_ZOOM, FIT_VIEW_PADDING, } from './editor/viewport-math.js';
|
|
17
|
+
export { builtinIcon, type IconSpec, isBuiltinIcon, isSvgIcon, isUrlIcon, svgIcon, urlIcon, } from './icons/types.js';
|
|
18
|
+
export { StorageConflictError, StorageError, type StorageErrorCode, StorageNotFoundError, StoragePermissionError, StorageQuotaError, } from './storage/errors.js';
|
|
19
|
+
export { type ListingEntry, type ListingEntryKind, type MetadataCache, MetadataCacheError, MetadataCacheQuotaError, type StorageWithMetadataCache, supportsMetadataCache, } from './storage/metadata-cache.js';
|
|
20
|
+
export { ancestorPaths, getFilename, getParentPath, isDescendantOrSame, joinPath, ROOT_PATH, rewritePathPrefix, splitExt, splitPath, uniquifyFilename, uniquifyFilenameAsync, validateName, } from './storage/path.js';
|
|
21
|
+
export { type CachedThumbnail, type ThumbnailCache, ThumbnailCacheError, type ThumbnailCacheGetRequest, ThumbnailCacheQuotaError, } from './storage/thumbnail-cache.js';
|
|
22
|
+
export type { DocumentRecord, DocumentRecordUpdate, FolderRecord, ImageRecord, ImageRecordUpdate, PageElement, PageMetadata, StorageProvider, StorageWithDocuments, StorageWithForceRefresh, StorageWithInit, StorageWithRateLimit, StorageWithResync, StorageWithTokenRefresher, } from './storage/types.js';
|
|
23
|
+
export { supportsDocuments, supportsForceRefresh, supportsInit, supportsRateLimit, supportsResync, supportsTokenRefresher, } from './storage/types.js';
|
|
24
|
+
export { assertNonNull } from './utils/assert.js';
|
|
25
|
+
export { DEFAULT_FILL_COLOR, DEFAULT_FONT_SIZE, DEFAULT_STROKE_COLOR, DEFAULT_STROKE_WIDTH, JPEG_QUALITY, MOSAIC_BLOCK_SIZE, } from './utils/constants.js';
|
|
26
|
+
export { computeDasharray, detectDashKey } from './utils/dash-utils.js';
|
|
27
|
+
export { ANNOT_FILENAME_PREFIX, defaultAnnotFilenameStem, defaultAnnotImageFilename, formatLocalTimestamp, } from './utils/filename.js';
|
|
28
|
+
export { newIdB58 } from './utils/id.js';
|
|
29
|
+
export { buildZip, dataUrlExt, dataUrlToBytes } from './zip/zip-builder.js';
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* `@ingcreators/annot-core/icons` — Tier-A icon types + value-level
|
|
3
|
+
* helpers + the narrow `BuiltinIconId` union from the Tier-B
|
|
4
|
+
* registry.
|
|
5
|
+
*
|
|
6
|
+
* Plugin authors and host code that need autocomplete on builtin
|
|
7
|
+
* ids import from here. The barrel intentionally pulls in the
|
|
8
|
+
* registry so consumers get a SINGLE narrow `BuiltinIconId` —
|
|
9
|
+
* earlier phases used a broad `string` alias for the type while
|
|
10
|
+
* the registry was being scaffolded; with Phase 2 in, the broad
|
|
11
|
+
* alias from `./types` is shadowed by the narrow one from the
|
|
12
|
+
* registry below.
|
|
13
|
+
*/
|
|
14
|
+
export { BUILTIN_ICON_IDS, BUILTIN_ICONS, type BuiltinIconId, resolveBuiltinIcon, } from '../editor/icons/registry.js';
|
|
15
|
+
export { builtinIcon, type IconSpec, isBuiltinIcon, isSvgIcon, isUrlIcon, svgIcon, urlIcon, } from './types.js';
|
|
@@ -0,0 +1,108 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Tier A icon types for `@ingcreators/annot-core`.
|
|
3
|
+
*
|
|
4
|
+
* Phase 1 of `docs/plans/svg-icons-and-plugin-icon-spec.md`.
|
|
5
|
+
*
|
|
6
|
+
* `IconSpec` is the public, plugin-facing handle for "render this
|
|
7
|
+
* icon here". Hosts (the toolbar, the sidebar, every panel header)
|
|
8
|
+
* and plugins (storage backend chips, sidebar tabs, drawer
|
|
9
|
+
* external-link rows) all describe their icons via the same
|
|
10
|
+
* discriminated-union shape so the renderer routes builtins,
|
|
11
|
+
* plugin-supplied SVG, and bundled image assets uniformly.
|
|
12
|
+
*
|
|
13
|
+
* This file is **pure types + value-level constructor helpers** —
|
|
14
|
+
* no DOM access, no Element imports, no module-level side
|
|
15
|
+
* effects. Importable in pure Node, jsdom, or the browser
|
|
16
|
+
* unchanged. The Tier B registry in
|
|
17
|
+
* `@ingcreators/annot-core/editor/icons/registry` (Phase 2) is
|
|
18
|
+
* what binds `BuiltinIconId` to concrete SVG strings; this Tier A
|
|
19
|
+
* file declares only the broad shape so downstream consumers
|
|
20
|
+
* that don't want the registry as a value-level dependency
|
|
21
|
+
* (rare; primarily plugin authors who only ever produce
|
|
22
|
+
* `kind: "svg"` icons) can still type-check against `IconSpec`.
|
|
23
|
+
*
|
|
24
|
+
* The narrow union `BuiltinIconId = keyof typeof BUILTIN_ICONS` is
|
|
25
|
+
* exported FROM the registry module, and re-exported by the icons
|
|
26
|
+
* subpath barrel (`@ingcreators/annot-core/icons`) so plugin
|
|
27
|
+
* authors who DO want compile-time autocomplete on builtin ids
|
|
28
|
+
* can import it without dragging the registry's data graph in
|
|
29
|
+
* unnecessarily — the registry's value side is tree-shakeable.
|
|
30
|
+
*/
|
|
31
|
+
/**
|
|
32
|
+
* Identity of a host-shipped icon. The narrow string-literal union
|
|
33
|
+
* is exported from `@ingcreators/annot-core/editor/icons/registry`
|
|
34
|
+
* via `keyof typeof BUILTIN_ICONS`; this Tier A alias keeps the
|
|
35
|
+
* structural shape (a string) so non-registry consumers can name
|
|
36
|
+
* the type without importing the registry's data.
|
|
37
|
+
*
|
|
38
|
+
* Plugin authors should prefer the narrow union exported from the
|
|
39
|
+
* `@ingcreators/annot-core/icons` subpath (which re-exports the
|
|
40
|
+
* registry's `BuiltinIconId`) for compile-time autocomplete — at
|
|
41
|
+
* runtime the two are identical (both are `string`).
|
|
42
|
+
*/
|
|
43
|
+
export type BuiltinIconId = string;
|
|
44
|
+
/**
|
|
45
|
+
* Plugin-friendly icon descriptor. Discriminated on `kind`:
|
|
46
|
+
*
|
|
47
|
+
* - `"builtin"` — refers to a host-provided registry icon by id.
|
|
48
|
+
* Cheapest at runtime (no parsing, no sanitisation); recommended
|
|
49
|
+
* whenever a suitable host icon exists. Plugins cross-check the
|
|
50
|
+
* available ids by importing `BUILTIN_ICON_IDS` from the
|
|
51
|
+
* registry; passing an id that isn't in the registry is treated
|
|
52
|
+
* as "no icon" by the renderer (returns the empty string / null).
|
|
53
|
+
*
|
|
54
|
+
* - `"svg"` — raw inline SVG markup. Use for plugin-owned
|
|
55
|
+
* logomarks not present in the host registry. Sanitised at
|
|
56
|
+
* render time (Phase 3 allow-list walker — see
|
|
57
|
+
* `docs/plans/svg-icons-and-plugin-icon-spec.md`). Plugin
|
|
58
|
+
* authors MUST author stand-alone `<svg>` elements (no
|
|
59
|
+
* surrounding HTML); the renderer refuses anything that doesn't
|
|
60
|
+
* parse as a single SVG root.
|
|
61
|
+
*
|
|
62
|
+
* - `"url"` — same-origin or `data:` URL pointing at an SVG asset.
|
|
63
|
+
* Used by plugins that ship their logomark as a static asset
|
|
64
|
+
* bundled with the plugin's JS. The host renders this via
|
|
65
|
+
* `<img src=…>` so the SVG is sandboxed (no CSS / script access
|
|
66
|
+
* to the host page). External-origin URLs are rejected at
|
|
67
|
+
* render time.
|
|
68
|
+
*/
|
|
69
|
+
export type IconSpec = {
|
|
70
|
+
readonly kind: "builtin";
|
|
71
|
+
readonly id: BuiltinIconId;
|
|
72
|
+
} | {
|
|
73
|
+
readonly kind: "svg";
|
|
74
|
+
readonly svg: string;
|
|
75
|
+
} | {
|
|
76
|
+
readonly kind: "url";
|
|
77
|
+
readonly url: string;
|
|
78
|
+
};
|
|
79
|
+
/** `IconSpec` constructor for a host registry id. Equivalent to
|
|
80
|
+
* writing `{ kind: "builtin", id }` inline; the helper makes
|
|
81
|
+
* call sites less noisy when an `IconSpec` is built dynamically
|
|
82
|
+
* (e.g. mapping a list of names to specs). */
|
|
83
|
+
export declare function builtinIcon(id: BuiltinIconId): IconSpec;
|
|
84
|
+
/** `IconSpec` constructor for raw plugin-supplied SVG markup. The
|
|
85
|
+
* string is NOT validated here — sanitisation happens at render
|
|
86
|
+
* time (Phase 3). */
|
|
87
|
+
export declare function svgIcon(svg: string): IconSpec;
|
|
88
|
+
/** `IconSpec` constructor for a same-origin or `data:` URL. The
|
|
89
|
+
* URL is NOT validated here — the renderer enforces same-origin
|
|
90
|
+
* / `data:`-only at render time. */
|
|
91
|
+
export declare function urlIcon(url: string): IconSpec;
|
|
92
|
+
/** Type guard for the `"builtin"` arm. Useful in renderer / plugin
|
|
93
|
+
* code that needs to pick a different rendering strategy per
|
|
94
|
+
* kind. */
|
|
95
|
+
export declare function isBuiltinIcon(spec: IconSpec): spec is {
|
|
96
|
+
readonly kind: "builtin";
|
|
97
|
+
readonly id: BuiltinIconId;
|
|
98
|
+
};
|
|
99
|
+
/** Type guard for the `"svg"` arm. */
|
|
100
|
+
export declare function isSvgIcon(spec: IconSpec): spec is {
|
|
101
|
+
readonly kind: "svg";
|
|
102
|
+
readonly svg: string;
|
|
103
|
+
};
|
|
104
|
+
/** Type guard for the `"url"` arm. */
|
|
105
|
+
export declare function isUrlIcon(spec: IconSpec): spec is {
|
|
106
|
+
readonly kind: "url";
|
|
107
|
+
readonly url: string;
|
|
108
|
+
};
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from './headless.js';
|