mirror of
https://github.com/Matysh/houseplan-card
synced 2026-10-07 15:09:30 +00:00
refactor: type custom decor image contracts
Issue: #51 User-Visible: no
This commit is contained in:
+6
-2
@@ -22,11 +22,15 @@ export type DecorImageProjection = readonly [
|
||||
|
||||
const resolveCache = new WeakMap<object, [string, Map<string, DecorAsset>]>();
|
||||
|
||||
export function decorAssetIds(config: any): string[] {
|
||||
type DecorAssetConfig = {
|
||||
spaces?: readonly { decor?: readonly { kind?: unknown; asset_id?: string }[] }[];
|
||||
};
|
||||
|
||||
export function decorAssetIds(config: DecorAssetConfig | null | undefined): string[] {
|
||||
const ids = new Set<string>();
|
||||
for (const space of config?.spaces || []) {
|
||||
for (const shape of space?.decor || []) {
|
||||
if (shape?.kind === 'image' && DECOR_ASSET_ID_RE.test(shape.asset_id)) ids.add(shape.asset_id);
|
||||
if (shape?.kind === 'image' && DECOR_ASSET_ID_RE.test(shape.asset_id!)) ids.add(shape.asset_id!);
|
||||
}
|
||||
}
|
||||
return [...ids];
|
||||
|
||||
@@ -10481,12 +10481,14 @@ public _renderBackupExportDialog(): TemplateResult {
|
||||
}
|
||||
|
||||
public _renderBackupImportDialog(): TemplateResult {
|
||||
type ContentItem = { kind?: string; url: string; state?: string };
|
||||
const d = this.host._backupImportDialog!;
|
||||
const p = d.preview;
|
||||
const decorContent = (p?.content || []).filter((item: any) => item.kind === 'decor_asset');
|
||||
const decorAssetCount = new Set(decorContent.map((item: any) => item.url)).size;
|
||||
const missingDecor = decorContent.filter((item: any) => item.state === 'missing_preserved');
|
||||
const missingDecorAssetCount = new Set(missingDecor.map((item: any) => item.url)).size;
|
||||
const decorContent = ((p?.content || []) as ContentItem[])
|
||||
.filter((item) => item.kind === 'decor_asset');
|
||||
const decorAssetCount = new Set(decorContent.map((item) => item.url)).size;
|
||||
const missingDecor = decorContent.filter((item) => item.state === 'missing_preserved');
|
||||
const missingDecorAssetCount = new Set(missingDecor.map((item) => item.url)).size;
|
||||
const counts = p?.counts || {};
|
||||
const report = p?.reference_report || {};
|
||||
const sum = (values: any): number => Object.values(values || {}).reduce(
|
||||
@@ -10587,7 +10589,7 @@ public _renderBackupImportDialog(): TemplateResult {
|
||||
assets: decorAssetCount, objects: decorContent.length,
|
||||
missing: missingDecorAssetCount,
|
||||
})}</span>` : nothing}
|
||||
${p.content.filter((item: any) => item.kind !== 'decor_asset').map((item: any) => html`<span>${item.url} · ${this.host._t(
|
||||
${(p.content as ContentItem[]).filter((item) => item.kind !== 'decor_asset').map((item) => html`<span>${item.url} · ${this.host._t(
|
||||
item.state === 'available' ? 'backup.content_available'
|
||||
: item.state === 'external' ? 'backup.content_external'
|
||||
: 'backup.content_detach_required',
|
||||
|
||||
+3
-2
@@ -58,6 +58,7 @@ import { resolveZeroWalls } from './zero-walls';
|
||||
import { geometryOpenings } from './plan-geometry-preflight';
|
||||
import { resolveDeviceAreaRelocations } from './device-area-relocation';
|
||||
import { projectDecorImage } from './decor-assets';
|
||||
import type { DecorShape } from './editors/decor/types';
|
||||
import {
|
||||
buildGlowClipGeometry, buildLightBarrierScene, forgetGlowSource, forgetGlowSpace,
|
||||
glowSourceInOpaqueBody, pruneGlowSources, readGlowClip, renderGlowPools,
|
||||
@@ -333,7 +334,7 @@ export function renderSpaceStatic(o: StaticRenderOpts): TemplateResult | null {
|
||||
placed.push({ minX: x, minY: y, maxX: x, maxY: y });
|
||||
}
|
||||
}
|
||||
const spCfg: any = o.cfg.spaces.find((s: any) => s.id === o.spaceId) || {};
|
||||
const spCfg = o.cfg.spaces.find((space) => space.id === o.spaceId) || {};
|
||||
if (!disp.hideDecor) for (const shape of spCfg.decor || []) {
|
||||
if (shape?.kind !== 'image' || !o.decorAssetUrl?.(String(shape.asset_id || ''))) continue;
|
||||
const item = decorBoxItem(shape);
|
||||
@@ -634,7 +635,7 @@ export function renderSpaceStatic(o: StaticRenderOpts): TemplateResult | null {
|
||||
: [];
|
||||
|
||||
const bgHref = space.bg ? (o.displayUrl ? o.displayUrl(space.bg.href) : space.bg.href) : '';
|
||||
const decorImages = (spCfg.decor || []).flatMap((shape: any) => {
|
||||
const decorImages = (spCfg.decor || []).flatMap((shape: DecorShape) => {
|
||||
if (shape?.kind !== 'image' || disp.hideDecor) return [];
|
||||
const raw = o.decorAssetUrl?.(String(shape.asset_id || '')) || '';
|
||||
const href = raw && o.displayUrl ? o.displayUrl(raw) : raw;
|
||||
|
||||
Reference in New Issue
Block a user