@homepages/concrete 1.0.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 +59 -0
- package/README.md +174 -0
- package/codemods/manifest.json +9 -0
- package/dist/artifact/playground/client/assets/index-BSA1yutg.css +1 -0
- package/dist/artifact/playground/client/assets/index-JloQyj8h.js +1101 -0
- package/dist/artifact/playground/client/index.html +13 -0
- package/dist/artifact/playground/client/island-canvas-host.mjs +1 -0
- package/dist/artifact/playground/host.mjs +127 -0
- package/dist/asset-modules.d.ts +99 -0
- package/dist/base.css +220 -0
- package/dist/browser/site-config.d.ts +18 -0
- package/dist/browser/site-config.js +56 -0
- package/dist/browser/submit-lead.d.ts +98 -0
- package/dist/browser/submit-lead.js +188 -0
- package/dist/browser.d.ts +3 -0
- package/dist/browser.js +4 -0
- package/dist/cli/build/artifact.js +225 -0
- package/dist/cli/build/captures.js +67 -0
- package/dist/cli/build/esbuild.js +127 -0
- package/dist/cli/build/fixtures.js +96 -0
- package/dist/cli/build/icons.js +76 -0
- package/dist/cli/build/index.js +38 -0
- package/dist/cli/build/playground.js +31 -0
- package/dist/cli/build/sections.js +236 -0
- package/dist/cli/build/source.js +62 -0
- package/dist/cli/build/static.js +156 -0
- package/dist/cli/capture/bundle.js +37 -0
- package/dist/cli/capture/capture-browser.js +51 -0
- package/dist/cli/capture/capture.js +121 -0
- package/dist/cli/check/analyze.js +95 -0
- package/dist/cli/check/index.js +19 -0
- package/dist/cli/check/load-workspace.js +119 -0
- package/dist/cli/check/messages.js +16 -0
- package/dist/cli/check/render/class-conflicts.js +39 -0
- package/dist/cli/check/render/html.js +86 -0
- package/dist/cli/check/render/inputs.js +53 -0
- package/dist/cli/check/render/invariants.js +58 -0
- package/dist/cli/check/render/island-frames.js +72 -0
- package/dist/cli/check/render/marker-coverage.js +102 -0
- package/dist/cli/check/render/nav.js +64 -0
- package/dist/cli/check/report.js +73 -0
- package/dist/cli/check/stages/bundles.js +129 -0
- package/dist/cli/check/stages/composition.js +67 -0
- package/dist/cli/check/stages/contracts.js +22 -0
- package/dist/cli/check/stages/dependencies.js +261 -0
- package/dist/cli/check/stages/fixtures.js +74 -0
- package/dist/cli/check/stages/lint.js +41 -0
- package/dist/cli/check/stages/logic.js +63 -0
- package/dist/cli/check/stages/render.js +144 -0
- package/dist/cli/check/stages/sections.js +83 -0
- package/dist/cli/check/stages/stylesheet.js +31 -0
- package/dist/cli/check/stages/typecheck.js +68 -0
- package/dist/cli/check/stages/workspace.js +26 -0
- package/dist/cli/commands.js +342 -0
- package/dist/cli/currency/cache.js +89 -0
- package/dist/cli/currency/decide.js +65 -0
- package/dist/cli/currency/opt-out.js +16 -0
- package/dist/cli/currency/preamble.js +183 -0
- package/dist/cli/currency/prompt.js +28 -0
- package/dist/cli/currency/refresh.js +44 -0
- package/dist/cli/currency/resolve-latest.js +185 -0
- package/dist/cli/currency/version-order.js +38 -0
- package/dist/cli/dev/crop.js +22 -0
- package/dist/cli/dev/hmr.js +26 -0
- package/dist/cli/dev/http.js +129 -0
- package/dist/cli/dev/index.js +70 -0
- package/dist/cli/dev/islands.js +390 -0
- package/dist/cli/dev/load-template.js +46 -0
- package/dist/cli/dev/request-error.js +22 -0
- package/dist/cli/dev/server.js +307 -0
- package/dist/cli/dev/tsconfig-paths.js +95 -0
- package/dist/cli/dev/vite.js +85 -0
- package/dist/cli/dev/workspace-reader.js +274 -0
- package/dist/cli/io.d.ts +14 -0
- package/dist/cli/media/cache.js +125 -0
- package/dist/cli/media/derive.js +252 -0
- package/dist/cli/media/deriver-plugin.js +71 -0
- package/dist/cli/property/index.js +180 -0
- package/dist/cli/property/library.js +137 -0
- package/dist/cli/publish/client.js +119 -0
- package/dist/cli/publish/freshness.js +66 -0
- package/dist/cli/publish/git.js +43 -0
- package/dist/cli/publish/index.js +207 -0
- package/dist/cli/publish/pack.js +78 -0
- package/dist/cli/publish/report.js +98 -0
- package/dist/cli/publish/target.js +87 -0
- package/dist/cli/publish/wire.js +29 -0
- package/dist/cli/tar.js +87 -0
- package/dist/cli/upgrade/codemod.js +56 -0
- package/dist/cli/upgrade/index.js +263 -0
- package/dist/cli/upgrade/manifest.js +72 -0
- package/dist/cli/upgrade/plan.js +68 -0
- package/dist/cli/upgrade/stage.js +71 -0
- package/dist/cli/version.d.ts +12 -0
- package/dist/cli/version.js +15 -0
- package/dist/cli/workspace.js +108 -0
- package/dist/cli.d.ts +6 -0
- package/dist/cli.js +94 -0
- package/dist/css/compile.js +77 -0
- package/dist/css/graph.js +109 -0
- package/dist/css/inline.js +132 -0
- package/dist/css/rules.js +65 -0
- package/dist/design-system/format-variants.js +127 -0
- package/dist/eslint/authoring.js +46 -0
- package/dist/eslint/correctness.js +42 -0
- package/dist/eslint/rules/editor-declaration.js +103 -0
- package/dist/eslint/rules/editor-reason.js +135 -0
- package/dist/eslint/rules/island-imports.js +20 -0
- package/dist/eslint/rules/jsx-visitor.js +20 -0
- package/dist/eslint/rules/no-client-runtime.js +88 -0
- package/dist/eslint/rules/no-editor-globals.js +60 -0
- package/dist/eslint/rules/no-hard-coded-color.js +183 -0
- package/dist/eslint/rules/no-inline-style.js +24 -0
- package/dist/eslint/rules/no-marker-literal.js +37 -0
- package/dist/eslint/rules/no-nondeterminism.js +44 -0
- package/dist/eslint/rules/no-px-breakpoint.js +44 -0
- package/dist/eslint/rules/no-raw-values.js +45 -0
- package/dist/eslint/rules/serializable-props.js +95 -0
- package/dist/eslint.d.ts +6 -0
- package/dist/eslint.js +26 -0
- package/dist/fixtures/brand.d.ts +4 -0
- package/dist/fixtures/brand.js +9 -0
- package/dist/fixtures/bundle-rule.js +67 -0
- package/dist/fixtures/canonical.d.ts +149 -0
- package/dist/fixtures/image-dimensions.js +59 -0
- package/dist/fixtures/load.js +154 -0
- package/dist/fixtures/media-plugin.js +141 -0
- package/dist/fixtures/media.js +165 -0
- package/dist/fixtures/property.js +210 -0
- package/dist/fixtures/resolve.js +202 -0
- package/dist/fixtures/rows.js +108 -0
- package/dist/fixtures/synthesize-empties.js +42 -0
- package/dist/fixtures.d.ts +213 -0
- package/dist/fixtures.js +37 -0
- package/dist/index.d.ts +53 -0
- package/dist/index.js +37 -0
- package/dist/islands/client-module.js +97 -0
- package/dist/islands/marker.d.ts +43 -0
- package/dist/islands/marker.js +44 -0
- package/dist/node_modules/.pnpm/fflate@0.8.3/node_modules/fflate/esm/browser.js +687 -0
- package/dist/packages/external/concrete/package.js +5 -0
- package/dist/packages/internal/fact-interpolation/dist/index.js +22 -0
- package/dist/packages/internal/fill-bake/dist/bake-property-ref.js +111 -0
- package/dist/packages/internal/fill-bake/dist/display.js +9 -0
- package/dist/packages/internal/fill-bake/dist/index.js +6 -0
- package/dist/packages/internal/fill-bake/dist/reconcile-cross-section.js +170 -0
- package/dist/packages/internal/fill-vocabulary/dist/facts.d.ts +32 -0
- package/dist/packages/internal/fill-vocabulary/dist/facts.js +131 -0
- package/dist/packages/internal/fill-vocabulary/dist/row-planners.js +73 -0
- package/dist/packages/internal/format-geometry/dist/capture.js +404 -0
- package/dist/packages/internal/format-geometry/dist/format.d.ts +41 -0
- package/dist/packages/internal/format-geometry/dist/geometry.js +58 -0
- package/dist/packages/internal/format-geometry/dist/index.js +4 -0
- package/dist/packages/internal/image-descriptor/dist/index.d.ts +35 -0
- package/dist/packages/internal/image-ladder/dist/crop.js +82 -0
- package/dist/packages/internal/image-ladder/dist/encode.js +23 -0
- package/dist/packages/internal/image-ladder/dist/index.js +4 -0
- package/dist/packages/internal/image-ladder/dist/policy.js +102 -0
- package/dist/packages/internal/island-runtime/dist/capture-holds.d.ts +13 -0
- package/dist/packages/internal/island-runtime/dist/capture-holds.js +45 -0
- package/dist/packages/internal/island-runtime/dist/contract.d.ts +176 -0
- package/dist/packages/internal/island-runtime/dist/contract.js +94 -0
- package/dist/packages/internal/island-runtime/dist/editor-instance-context.js +15 -0
- package/dist/packages/internal/island-runtime/dist/index.d.ts +103 -0
- package/dist/packages/internal/island-runtime/dist/index.js +163 -0
- package/dist/packages/internal/island-runtime/dist/use-capture-ready.d.ts +19 -0
- package/dist/packages/internal/island-runtime/dist/use-capture-ready.js +39 -0
- package/dist/packages/internal/island-runtime/dist/use-editor.d.ts +22 -0
- package/dist/packages/internal/island-runtime/dist/use-editor.js +54 -0
- package/dist/packages/internal/island-runtime/dist/viewport-schedule.js +105 -0
- package/dist/packages/internal/property-facts/dist/derive-facts-view.js +25 -0
- package/dist/packages/internal/property-facts/dist/index.js +3 -0
- package/dist/packages/internal/property-facts/dist/property-facts-CSdkSuD7.js +181 -0
- package/dist/packages/internal/section-contracts/dist/cap-contract.js +59 -0
- package/dist/packages/internal/section-contracts/dist/catalog.js +102 -0
- package/dist/packages/internal/section-contracts/dist/choose-select-contract.js +24 -0
- package/dist/packages/internal/section-contracts/dist/count-bounds-contract.js +48 -0
- package/dist/packages/internal/section-contracts/dist/display-contract.js +30 -0
- package/dist/packages/internal/section-contracts/dist/display-evidence-contract.js +17 -0
- package/dist/packages/internal/section-contracts/dist/group-contract.js +21 -0
- package/dist/packages/internal/section-contracts/dist/index.js +26 -0
- package/dist/packages/internal/section-contracts/dist/interpolation-contract.js +48 -0
- package/dist/packages/internal/section-contracts/dist/list-fill-contract.js +53 -0
- package/dist/packages/internal/section-contracts/dist/list-scalar-contract.js +70 -0
- package/dist/packages/internal/section-contracts/dist/name-title-contract.js +27 -0
- package/dist/packages/internal/section-contracts/dist/nested-slot-contract.js +12 -0
- package/dist/packages/internal/section-contracts/dist/option-source-contract.js +22 -0
- package/dist/packages/internal/section-contracts/dist/poi-curation-contract.js +18 -0
- package/dist/packages/internal/section-contracts/dist/pooling-field-contract.js +30 -0
- package/dist/packages/internal/section-contracts/dist/record-collection-contract.js +24 -0
- package/dist/packages/internal/section-contracts/dist/row-contract.js +37 -0
- package/dist/packages/internal/section-contracts/dist/row-fill-contract.js +38 -0
- package/dist/packages/internal/section-contracts/dist/runners.js +181 -0
- package/dist/packages/internal/section-contracts/dist/select-contract.js +28 -0
- package/dist/packages/internal/section-contracts/dist/source-contract.js +48 -0
- package/dist/packages/internal/section-contracts/dist/source-filter-contract.js +15 -0
- package/dist/packages/internal/section-contracts/dist/sources-contract.js +28 -0
- package/dist/packages/internal/section-contracts/dist/url-contract.js +20 -0
- package/dist/packages/internal/source-resolution/dist/index.js +222 -0
- package/dist/packages/internal/template-artifact/dist/hash.js +50 -0
- package/dist/packages/internal/template-artifact/dist/index.js +7 -0
- package/dist/packages/internal/template-artifact/dist/layout.js +165 -0
- package/dist/packages/internal/template-artifact/dist/manifest.js +73 -0
- package/dist/packages/internal/template-artifact/dist/sha256.js +138 -0
- package/dist/packages/internal/template-artifact/dist/verify.js +275 -0
- package/dist/packages/internal/template-contracts/dist/collection-editing.js +38 -0
- package/dist/packages/internal/template-contracts/dist/content-categories.d.ts +10 -0
- package/dist/packages/internal/template-contracts/dist/content-categories.js +17 -0
- package/dist/packages/internal/template-contracts/dist/document-value.d.ts +33 -0
- package/dist/packages/internal/template-contracts/dist/facts-view.d.ts +81 -0
- package/dist/packages/internal/template-contracts/dist/facts-view.js +136 -0
- package/dist/packages/internal/template-contracts/dist/layout.js +17 -0
- package/dist/packages/internal/template-contracts/dist/markers.d.ts +40 -0
- package/dist/packages/internal/template-contracts/dist/markers.js +41 -0
- package/dist/packages/internal/template-contracts/dist/poi-row.d.ts +63 -0
- package/dist/packages/internal/template-contracts/dist/select-key.js +13 -0
- package/dist/packages/internal/template-contracts/dist/slot-catalog.d.ts +1112 -0
- package/dist/packages/internal/template-contracts/dist/slot-catalog.js +1109 -0
- package/dist/packages/internal/template-contracts/dist/slot-overrides.js +11 -0
- package/dist/packages/internal/template-contracts/dist/tour-value.d.ts +45 -0
- package/dist/packages/internal/template-contracts/dist/video-value.d.ts +63 -0
- package/dist/playground/host/page-state.js +12 -0
- package/dist/playground/host/paths.js +9 -0
- package/dist/playground/layout.js +24 -0
- package/dist/playground/wire.js +36 -0
- package/dist/playground-island-runtime.d.ts +3 -0
- package/dist/playground-island-runtime.js +4 -0
- package/dist/primitives/FrameShell.d.ts +29 -0
- package/dist/primitives/FrameShell.js +34 -0
- package/dist/primitives/Image.d.ts +119 -0
- package/dist/primitives/Image.js +173 -0
- package/dist/primitives/Section.d.ts +22 -0
- package/dist/primitives/Section.js +26 -0
- package/dist/primitives/Tour.d.ts +43 -0
- package/dist/primitives/Tour.js +72 -0
- package/dist/primitives/Video.d.ts +57 -0
- package/dist/primitives/Video.js +116 -0
- package/dist/primitives/embed-playback.js +50 -0
- package/dist/primitives/index.d.ts +11 -0
- package/dist/primitives/marker-attrs.js +44 -0
- package/dist/primitives/object-fit.js +11 -0
- package/dist/primitives/picture-sources.d.ts +24 -0
- package/dist/primitives/picture-sources.js +52 -0
- package/dist/primitives/probe-context.js +24 -0
- package/dist/primitives/slot-bindings.d.ts +96 -0
- package/dist/primitives/slot-bindings.js +226 -0
- package/dist/primitives/slot-document.d.ts +35 -0
- package/dist/primitives/slot-document.js +37 -0
- package/dist/primitives/slot-group.d.ts +40 -0
- package/dist/primitives/slot-group.js +45 -0
- package/dist/primitives/slot-list.d.ts +21 -0
- package/dist/primitives/slot-list.js +23 -0
- package/dist/primitives/slot-media.d.ts +71 -0
- package/dist/primitives/slot-media.js +98 -0
- package/dist/primitives/slot-scalar.d.ts +53 -0
- package/dist/primitives/slot-scalar.js +98 -0
- package/dist/primitives/slot.d.ts +26 -0
- package/dist/primitives/slot.js +28 -0
- package/dist/rules/registry.js +479 -0
- package/dist/schema/compute.d.ts +22 -0
- package/dist/schema/compute.js +30 -0
- package/dist/schema/define-schema.d.ts +27 -0
- package/dist/schema/define-schema.js +73 -0
- package/dist/schema/extract-fill-spec.js +246 -0
- package/dist/schema/extract-used-facts.js +176 -0
- package/dist/schema/fact.d.ts +65 -0
- package/dist/schema/fact.js +33 -0
- package/dist/schema/fill-builders.d.ts +387 -0
- package/dist/schema/fill-builders.js +263 -0
- package/dist/schema/fill-declaration.d.ts +76 -0
- package/dist/schema/fill-declaration.js +43 -0
- package/dist/schema/fill-spec.d.ts +18 -0
- package/dist/schema/fill-spec.js +170 -0
- package/dist/schema/format-presets.d.ts +27 -0
- package/dist/schema/format-presets.js +76 -0
- package/dist/schema/format.d.ts +22 -0
- package/dist/schema/format.js +40 -0
- package/dist/schema/formats.d.ts +6 -0
- package/dist/schema/formats.js +7 -0
- package/dist/schema/layout.d.ts +32 -0
- package/dist/schema/layout.js +30 -0
- package/dist/schema/manifest.js +300 -0
- package/dist/schema/property-facts.d.ts +83 -0
- package/dist/schema/runtime-values.d.ts +88 -0
- package/dist/schema/section-nav.d.ts +38 -0
- package/dist/schema/section-nav.js +29 -0
- package/dist/schema/section-props.d.ts +98 -0
- package/dist/schema/section-schema.d.ts +53 -0
- package/dist/schema/section-schema.js +54 -0
- package/dist/schema/slot-builders.d.ts +497 -0
- package/dist/schema/slot-builders.js +331 -0
- package/dist/schema/slot-types.d.ts +110 -0
- package/dist/schema/slot-types.js +187 -0
- package/dist/section/declare.d.ts +44 -0
- package/dist/section/declare.js +27 -0
- package/dist/section/discovery.js +76 -0
- package/dist/section/groups.js +74 -0
- package/dist/section/materialize.js +28 -0
- package/dist/section/placements.js +28 -0
- package/dist/section/section.d.ts +69 -0
- package/dist/section/section.js +101 -0
- package/dist/site-analytics.d.ts +1 -0
- package/dist/site-analytics.js +15 -0
- package/dist/site-runtime/analytics.js +97 -0
- package/dist/site-runtime/site-integrations.js +97 -0
- package/dist/styles.css +60 -0
- package/dist/template/define-template.d.ts +139 -0
- package/dist/template/define-template.js +98 -0
- package/dist/template/logic-build.js +191 -0
- package/dist/template/logic-shim.d.ts +43 -0
- package/dist/template/logic-shim.js +52 -0
- package/dist/template/logic-transform.js +92 -0
- package/dist/template/materialize.js +107 -0
- package/dist/template/reconcile.d.ts +67 -0
- package/dist/template/reconcile.js +25 -0
- package/dist/template/running-copy.js +58 -0
- package/guide/reference/cli/INDEX.md +79 -0
- package/guide/reference/cli/build.md +48 -0
- package/guide/reference/cli/check.md +49 -0
- package/guide/reference/cli/dev.md +46 -0
- package/guide/reference/cli/property-add.md +53 -0
- package/guide/reference/cli/property-list.md +46 -0
- package/guide/reference/cli/publish.md +54 -0
- package/guide/reference/cli/upgrade.md +48 -0
- package/guide/reference/rules/INDEX.md +190 -0
- package/package.json +137 -0
- package/tsconfig.base.json +16 -0
|
@@ -0,0 +1,154 @@
|
|
|
1
|
+
import { isFixture } from "./brand.js";
|
|
2
|
+
import { MEDIA_LOADERS, createFixtureMediaPlugin, externalOutsideWorkspace } from "./media-plugin.js";
|
|
3
|
+
import { runningCopyPlugin } from "../template/running-copy.js";
|
|
4
|
+
import { readdirSync } from "node:fs";
|
|
5
|
+
import { join, relative, sep } from "node:path";
|
|
6
|
+
import { pathToFileURL } from "node:url";
|
|
7
|
+
import { build } from "esbuild";
|
|
8
|
+
|
|
9
|
+
//#region src/fixtures/load.ts
|
|
10
|
+
/** The one reserved directory: everything fixture-side lives under it. */
|
|
11
|
+
const FIXTURES_DIR = "fixtures";
|
|
12
|
+
const MODULE_FILE = /\.(?:[cm]?[jt]s|[jt]sx)$/;
|
|
13
|
+
const SKIPPED_FILE = /\.test\.[^/]+$|\.d\.[cm]?ts$/;
|
|
14
|
+
const SKIPPED_DIRS = /* @__PURE__ */ new Set(["node_modules", ".concrete"]);
|
|
15
|
+
/** Every module under `<root>/fixtures/`, tests excluded, in a stable order. `[]` when the directory is absent. */
|
|
16
|
+
function listFixtureModules(root) {
|
|
17
|
+
const out = [];
|
|
18
|
+
const walk = (dir) => {
|
|
19
|
+
let entries;
|
|
20
|
+
try {
|
|
21
|
+
entries = readdirSync(dir, { withFileTypes: true });
|
|
22
|
+
} catch {
|
|
23
|
+
return;
|
|
24
|
+
}
|
|
25
|
+
for (const entry of entries.sort((a, b) => a.name.localeCompare(b.name))) {
|
|
26
|
+
if (entry.name.startsWith(".")) continue;
|
|
27
|
+
const path = join(dir, entry.name);
|
|
28
|
+
if (entry.isDirectory()) {
|
|
29
|
+
if (!SKIPPED_DIRS.has(entry.name)) walk(path);
|
|
30
|
+
} else if (entry.isFile() && MODULE_FILE.test(entry.name) && !SKIPPED_FILE.test(entry.name)) out.push(path);
|
|
31
|
+
}
|
|
32
|
+
};
|
|
33
|
+
walk(join(root, FIXTURES_DIR));
|
|
34
|
+
return out;
|
|
35
|
+
}
|
|
36
|
+
function buildMessages(err) {
|
|
37
|
+
const messages = err.errors;
|
|
38
|
+
return Array.isArray(messages) ? messages : null;
|
|
39
|
+
}
|
|
40
|
+
let importSerial = 0;
|
|
41
|
+
/** The default loader: one esbuild pass over every fixture module, then a dynamic import of each output. */
|
|
42
|
+
async function bundleAndImportFixtureModules(root, files) {
|
|
43
|
+
const media = createFixtureMediaPlugin(root);
|
|
44
|
+
const outdir = join(root, ".concrete", "cache", "fixtures");
|
|
45
|
+
let result;
|
|
46
|
+
try {
|
|
47
|
+
result = await build({
|
|
48
|
+
entryPoints: [...files],
|
|
49
|
+
bundle: true,
|
|
50
|
+
splitting: true,
|
|
51
|
+
format: "esm",
|
|
52
|
+
platform: "node",
|
|
53
|
+
target: "node22",
|
|
54
|
+
outdir,
|
|
55
|
+
outbase: root,
|
|
56
|
+
absWorkingDir: root,
|
|
57
|
+
packages: "external",
|
|
58
|
+
jsx: "automatic",
|
|
59
|
+
loader: {
|
|
60
|
+
".css": "empty",
|
|
61
|
+
...MEDIA_LOADERS
|
|
62
|
+
},
|
|
63
|
+
plugins: [
|
|
64
|
+
runningCopyPlugin(),
|
|
65
|
+
externalOutsideWorkspace(root),
|
|
66
|
+
media.plugin
|
|
67
|
+
],
|
|
68
|
+
metafile: true,
|
|
69
|
+
write: true,
|
|
70
|
+
logLevel: "silent"
|
|
71
|
+
});
|
|
72
|
+
} catch (err) {
|
|
73
|
+
const messages = buildMessages(err);
|
|
74
|
+
if (messages === null) throw err;
|
|
75
|
+
return {
|
|
76
|
+
modules: /* @__PURE__ */ new Map(),
|
|
77
|
+
assets: media.assets,
|
|
78
|
+
violations: messages.map((m) => ({
|
|
79
|
+
rule: "fixtures/property-invalid",
|
|
80
|
+
file: m.location?.file ?? `${"fixtures"}/`,
|
|
81
|
+
message: m.location === null || m.location === void 0 ? m.text : `${m.text} (${m.location.file}:${m.location.line})`
|
|
82
|
+
}))
|
|
83
|
+
};
|
|
84
|
+
}
|
|
85
|
+
const outputByInput = /* @__PURE__ */ new Map();
|
|
86
|
+
for (const [out, meta] of Object.entries(result.metafile.outputs)) if (meta.entryPoint !== void 0) outputByInput.set(join(root, meta.entryPoint), join(root, out));
|
|
87
|
+
const modules = /* @__PURE__ */ new Map();
|
|
88
|
+
for (const file of files) {
|
|
89
|
+
const out = outputByInput.get(file);
|
|
90
|
+
if (out === void 0) throw new Error(`fixtures: esbuild produced no output for ${relative(root, file)}.`);
|
|
91
|
+
const url = `${pathToFileURL(out).href}?load=${Date.now()}-${importSerial++}`;
|
|
92
|
+
modules.set(file, await import(url));
|
|
93
|
+
}
|
|
94
|
+
return {
|
|
95
|
+
modules,
|
|
96
|
+
assets: media.assets,
|
|
97
|
+
violations: []
|
|
98
|
+
};
|
|
99
|
+
}
|
|
100
|
+
/**
|
|
101
|
+
* Load the workspace's fixtures, in discovery order: modules by path, and within a
|
|
102
|
+
* module the namespace's own (alphabetical) export order. Two distinct fixtures under
|
|
103
|
+
* one export name is an error — the name is the id, and two values cannot share it. No
|
|
104
|
+
* fixture at all is the `fixtures/none` violation, not an error: `check` reports it
|
|
105
|
+
* beside the rest.
|
|
106
|
+
*/
|
|
107
|
+
async function loadFixtures(options) {
|
|
108
|
+
const { root } = options;
|
|
109
|
+
const files = listFixtureModules(root);
|
|
110
|
+
const importModules = options.importModules ?? ((list) => bundleAndImportFixtureModules(root, list));
|
|
111
|
+
const imported = files.length === 0 ? {
|
|
112
|
+
modules: /* @__PURE__ */ new Map(),
|
|
113
|
+
assets: /* @__PURE__ */ new Map(),
|
|
114
|
+
violations: []
|
|
115
|
+
} : await importModules(files);
|
|
116
|
+
const violations = [...imported.violations];
|
|
117
|
+
const fixtures = [];
|
|
118
|
+
const byId = /* @__PURE__ */ new Map();
|
|
119
|
+
for (const file of files) {
|
|
120
|
+
const exports = imported.modules.get(file);
|
|
121
|
+
if (exports === void 0) continue;
|
|
122
|
+
const module = relative(root, file).split(sep).join("/");
|
|
123
|
+
for (const [exportName, value] of Object.entries(exports)) {
|
|
124
|
+
if (!isFixture(value)) continue;
|
|
125
|
+
const fixture = value;
|
|
126
|
+
const entry = {
|
|
127
|
+
id: exportName,
|
|
128
|
+
label: fixture.label ?? exportName,
|
|
129
|
+
module,
|
|
130
|
+
exportName,
|
|
131
|
+
fixture
|
|
132
|
+
};
|
|
133
|
+
const prior = byId.get(exportName);
|
|
134
|
+
if (prior !== void 0 && prior.fixture !== fixture) throw new Error(`Two fixtures are exported as "${exportName}": ${prior.module} and ${module}. The export name is the fixture id.`);
|
|
135
|
+
if (prior === void 0) {
|
|
136
|
+
byId.set(exportName, entry);
|
|
137
|
+
fixtures.push(entry);
|
|
138
|
+
}
|
|
139
|
+
}
|
|
140
|
+
}
|
|
141
|
+
if (fixtures.length === 0 && violations.length === 0) violations.push({
|
|
142
|
+
rule: "fixtures/none",
|
|
143
|
+
file: `${FIXTURES_DIR}/`,
|
|
144
|
+
message: files.length === 0 ? `the workspace has no modules under ${FIXTURES_DIR}/ — export a defineFixture() value from one` : `no module under ${FIXTURES_DIR}/ exports a defineFixture() value`
|
|
145
|
+
});
|
|
146
|
+
return {
|
|
147
|
+
fixtures,
|
|
148
|
+
assets: imported.assets,
|
|
149
|
+
violations
|
|
150
|
+
};
|
|
151
|
+
}
|
|
152
|
+
|
|
153
|
+
//#endregion
|
|
154
|
+
export { FIXTURES_DIR, bundleAndImportFixtureModules, listFixtureModules, loadFixtures };
|
|
@@ -0,0 +1,141 @@
|
|
|
1
|
+
import { imageDimensions } from "./image-dimensions.js";
|
|
2
|
+
import { basename, extname, sep } from "node:path";
|
|
3
|
+
import { readFile } from "node:fs/promises";
|
|
4
|
+
import { createHash } from "node:crypto";
|
|
5
|
+
|
|
6
|
+
//#region src/fixtures/media-plugin.ts
|
|
7
|
+
const NAMESPACE = "concrete-fixture-media";
|
|
8
|
+
const RESOLVING = Symbol("concrete-fixture-media:resolving");
|
|
9
|
+
/** The public path fixture media serves under in `dev`. */
|
|
10
|
+
const FIXTURE_MEDIA_PATH = "/fixture-media";
|
|
11
|
+
const MEDIA_FILTER = /\.(?:[pP][nN][gG]|[jJ][pP][eE]?[gG]|[wW][eE][bB][pP]|[aA][vV][iI][fF]|[sS][vV][gG]|[gG][iI][fF]|[iI][cC][oO]|[wW][oO][fF][fF]2?|[tT][tT][fF]|[oO][tT][fF]|[eE][oO][tT]|[mM][pP]4|[wW][eE][bB][mM]|[mM][oO][vV]|[mM][pP]3|[wW][aA][vV]|[pP][dD][fF]|[zZ][iI][pP])$/;
|
|
12
|
+
const DERIVED_EXTENSIONS = /* @__PURE__ */ new Set([
|
|
13
|
+
".png",
|
|
14
|
+
".jpg",
|
|
15
|
+
".jpeg",
|
|
16
|
+
".webp",
|
|
17
|
+
".avif"
|
|
18
|
+
]);
|
|
19
|
+
/**
|
|
20
|
+
* esbuild's `file` loader for every media extension the ambient shim types — the
|
|
21
|
+
* fallback for a media import the plugin does not claim (one resolving outside the
|
|
22
|
+
* workspace), so a pass never fails on "no loader is configured".
|
|
23
|
+
*/
|
|
24
|
+
const MEDIA_LOADERS = Object.fromEntries([
|
|
25
|
+
".png",
|
|
26
|
+
".jpg",
|
|
27
|
+
".jpeg",
|
|
28
|
+
".webp",
|
|
29
|
+
".avif",
|
|
30
|
+
".svg",
|
|
31
|
+
".gif",
|
|
32
|
+
".ico",
|
|
33
|
+
".woff",
|
|
34
|
+
".woff2",
|
|
35
|
+
".ttf",
|
|
36
|
+
".otf",
|
|
37
|
+
".eot",
|
|
38
|
+
".mp4",
|
|
39
|
+
".webm",
|
|
40
|
+
".mov",
|
|
41
|
+
".mp3",
|
|
42
|
+
".wav",
|
|
43
|
+
".pdf",
|
|
44
|
+
".zip"
|
|
45
|
+
].map((ext) => [ext, "file"]));
|
|
46
|
+
/**
|
|
47
|
+
* Keep a relative import that resolves OUTSIDE the workspace external, so the loaded
|
|
48
|
+
* module shares the running process's copy of it rather than a bundled second copy.
|
|
49
|
+
* A real workspace never imports past its own root, so in production this claims
|
|
50
|
+
* nothing; the package's own test workspaces reach their framework by relative path,
|
|
51
|
+
* and a bundled copy would carry its own brand symbols and probe contexts.
|
|
52
|
+
*/
|
|
53
|
+
function externalOutsideWorkspace(root) {
|
|
54
|
+
const inside = root.endsWith(sep) ? root : root + sep;
|
|
55
|
+
return {
|
|
56
|
+
name: "concrete-external-outside-workspace",
|
|
57
|
+
setup(build) {
|
|
58
|
+
build.onResolve({ filter: /^\.\.?\// }, async (args) => {
|
|
59
|
+
if (args.pluginData === RESOLVING) return null;
|
|
60
|
+
const resolved = await build.resolve(args.path, {
|
|
61
|
+
importer: args.importer,
|
|
62
|
+
namespace: args.namespace,
|
|
63
|
+
resolveDir: args.resolveDir,
|
|
64
|
+
kind: args.kind,
|
|
65
|
+
pluginData: RESOLVING
|
|
66
|
+
});
|
|
67
|
+
if (resolved.errors.length > 0 || resolved.path === "") return null;
|
|
68
|
+
return resolved.path.startsWith(inside) ? null : {
|
|
69
|
+
path: resolved.path,
|
|
70
|
+
external: true
|
|
71
|
+
};
|
|
72
|
+
});
|
|
73
|
+
}
|
|
74
|
+
};
|
|
75
|
+
}
|
|
76
|
+
/** The served URL of a master: `<stem>-<hash8><ext>` under the fixture media path. */
|
|
77
|
+
function fixtureMediaUrl(path, bytes) {
|
|
78
|
+
const ext = extname(path);
|
|
79
|
+
const hash = createHash("sha256").update(bytes).digest("hex").slice(0, 8);
|
|
80
|
+
return `${FIXTURE_MEDIA_PATH}/${basename(path, ext)}-${hash}${ext.toLowerCase()}`;
|
|
81
|
+
}
|
|
82
|
+
/** A fresh plugin per pass; `assets` is what the pass recorded. */
|
|
83
|
+
function createFixtureMediaPlugin(root) {
|
|
84
|
+
const assets = /* @__PURE__ */ new Map();
|
|
85
|
+
const inside = root.endsWith(sep) ? root : root + sep;
|
|
86
|
+
return {
|
|
87
|
+
plugin: {
|
|
88
|
+
name: NAMESPACE,
|
|
89
|
+
setup(build) {
|
|
90
|
+
build.onResolve({ filter: MEDIA_FILTER }, async (args) => {
|
|
91
|
+
if (args.pluginData === RESOLVING) return null;
|
|
92
|
+
if (args.kind !== "import-statement" && args.kind !== "dynamic-import") return null;
|
|
93
|
+
const resolved = await build.resolve(args.path, {
|
|
94
|
+
importer: args.importer,
|
|
95
|
+
namespace: args.namespace,
|
|
96
|
+
resolveDir: args.resolveDir,
|
|
97
|
+
kind: args.kind,
|
|
98
|
+
pluginData: RESOLVING
|
|
99
|
+
});
|
|
100
|
+
if (resolved.errors.length > 0 || resolved.path === "") return null;
|
|
101
|
+
if (!resolved.path.startsWith(inside)) return null;
|
|
102
|
+
return {
|
|
103
|
+
path: resolved.path,
|
|
104
|
+
namespace: NAMESPACE
|
|
105
|
+
};
|
|
106
|
+
});
|
|
107
|
+
build.onLoad({
|
|
108
|
+
filter: /.*/,
|
|
109
|
+
namespace: NAMESPACE
|
|
110
|
+
}, async (args) => {
|
|
111
|
+
const bytes = await readFile(args.path);
|
|
112
|
+
const url = fixtureMediaUrl(args.path, bytes);
|
|
113
|
+
const derived = DERIVED_EXTENSIONS.has(extname(args.path).toLowerCase());
|
|
114
|
+
assets.set(url, {
|
|
115
|
+
url,
|
|
116
|
+
path: args.path,
|
|
117
|
+
bytes: bytes.byteLength,
|
|
118
|
+
derived
|
|
119
|
+
});
|
|
120
|
+
const value = derived ? {
|
|
121
|
+
url,
|
|
122
|
+
responsive: null,
|
|
123
|
+
...imageDimensions(bytes) ?? {
|
|
124
|
+
width: 0,
|
|
125
|
+
height: 0
|
|
126
|
+
}
|
|
127
|
+
} : url;
|
|
128
|
+
return {
|
|
129
|
+
contents: `export default ${JSON.stringify(value)};`,
|
|
130
|
+
loader: "js",
|
|
131
|
+
watchFiles: [args.path]
|
|
132
|
+
};
|
|
133
|
+
});
|
|
134
|
+
}
|
|
135
|
+
},
|
|
136
|
+
assets
|
|
137
|
+
};
|
|
138
|
+
}
|
|
139
|
+
|
|
140
|
+
//#endregion
|
|
141
|
+
export { FIXTURE_MEDIA_PATH, MEDIA_LOADERS, createFixtureMediaPlugin, externalOutsideWorkspace, fixtureMediaUrl };
|
|
@@ -0,0 +1,165 @@
|
|
|
1
|
+
//#region src/fixtures/media.ts
|
|
2
|
+
const clamp01 = (n) => n < 0 ? 0 : n > 1 ? 1 : n;
|
|
3
|
+
/**
|
|
4
|
+
* A crop rect read off an untrusted value, clamped into the frame, or null when it names
|
|
5
|
+
* none: not an object, a non-finite field, a zero-size region, or the whole image.
|
|
6
|
+
*/
|
|
7
|
+
function cropRectOf(value) {
|
|
8
|
+
if (typeof value !== "object" || value === null) return null;
|
|
9
|
+
const { nx = 0, ny = 0, nw = 1, nh = 1 } = value;
|
|
10
|
+
if (![
|
|
11
|
+
nx,
|
|
12
|
+
ny,
|
|
13
|
+
nw,
|
|
14
|
+
nh
|
|
15
|
+
].every((n) => typeof n === "number" && Number.isFinite(n))) return null;
|
|
16
|
+
const x = clamp01(nx);
|
|
17
|
+
const y = clamp01(ny);
|
|
18
|
+
const rect = {
|
|
19
|
+
nx: x,
|
|
20
|
+
ny: y,
|
|
21
|
+
nw: Math.min(clamp01(nw), 1 - x),
|
|
22
|
+
nh: Math.min(clamp01(nh), 1 - y)
|
|
23
|
+
};
|
|
24
|
+
if (rect.nw <= 0 || rect.nh <= 0) return null;
|
|
25
|
+
return rect.nx === 0 && rect.ny === 0 && rect.nw === 1 && rect.nh === 1 ? null : rect;
|
|
26
|
+
}
|
|
27
|
+
/** The `dev` answer: the URL the loader minted, and whatever ladder the import carried. */
|
|
28
|
+
const servedMedia = { file(file) {
|
|
29
|
+
return typeof file === "string" ? {
|
|
30
|
+
url: file,
|
|
31
|
+
responsive: null
|
|
32
|
+
} : {
|
|
33
|
+
url: file.url,
|
|
34
|
+
responsive: file.responsive
|
|
35
|
+
};
|
|
36
|
+
} };
|
|
37
|
+
function assetId(value) {
|
|
38
|
+
if (typeof value !== "object" || value === null) return null;
|
|
39
|
+
const id = value.asset_id;
|
|
40
|
+
return typeof id === "string" && id !== "" ? id : null;
|
|
41
|
+
}
|
|
42
|
+
/**
|
|
43
|
+
* An image reference's value. A reference carrying a `rect` (and a `mobile_rect`) serves
|
|
44
|
+
* that region through the resolver's `crop`, as one source with no ladder: the crop is cut
|
|
45
|
+
* on the way out, so there are no rungs of it to list. The rect rides along as the
|
|
46
|
+
* cropper's re-edit state, as the platform's value carries it.
|
|
47
|
+
*/
|
|
48
|
+
function imageValue(entry, ref, resolver) {
|
|
49
|
+
if (entry.file === null) return null;
|
|
50
|
+
const rect = resolver.crop === void 0 ? null : cropRectOf(ref.rect);
|
|
51
|
+
const mobileRect = resolver.crop === void 0 ? null : cropRectOf(ref.mobile_rect);
|
|
52
|
+
const served = resolver.file(entry.file);
|
|
53
|
+
const value = rect === null ? {
|
|
54
|
+
photo_id: entry.id,
|
|
55
|
+
url: served.url,
|
|
56
|
+
alt: entry.alt,
|
|
57
|
+
responsive: served.responsive
|
|
58
|
+
} : {
|
|
59
|
+
photo_id: entry.id,
|
|
60
|
+
url: resolver.crop(entry.file, rect),
|
|
61
|
+
alt: entry.alt,
|
|
62
|
+
responsive: null,
|
|
63
|
+
rect
|
|
64
|
+
};
|
|
65
|
+
if (mobileRect !== null) value.mobile = {
|
|
66
|
+
url: resolver.crop(entry.file, mobileRect),
|
|
67
|
+
responsive: null
|
|
68
|
+
};
|
|
69
|
+
return value;
|
|
70
|
+
}
|
|
71
|
+
function videoValue(entry, resolver) {
|
|
72
|
+
if (entry.file === null) return {
|
|
73
|
+
video_id: entry.id,
|
|
74
|
+
url: entry.url ?? "",
|
|
75
|
+
poster: "",
|
|
76
|
+
alt: entry.alt,
|
|
77
|
+
source: "link",
|
|
78
|
+
...entry.provider === null ? {} : { provider: entry.provider }
|
|
79
|
+
};
|
|
80
|
+
return {
|
|
81
|
+
video_id: entry.id,
|
|
82
|
+
url: resolver.file(entry.file).url,
|
|
83
|
+
poster: "",
|
|
84
|
+
alt: entry.alt,
|
|
85
|
+
source: "upload"
|
|
86
|
+
};
|
|
87
|
+
}
|
|
88
|
+
function tourValue(entry) {
|
|
89
|
+
return {
|
|
90
|
+
tour_id: entry.id,
|
|
91
|
+
url: entry.url ?? "",
|
|
92
|
+
poster: "",
|
|
93
|
+
alt: entry.alt,
|
|
94
|
+
...entry.provider === null ? {} : { provider: entry.provider }
|
|
95
|
+
};
|
|
96
|
+
}
|
|
97
|
+
function documentValue(entry, resolver) {
|
|
98
|
+
if (entry.file === null) return null;
|
|
99
|
+
return {
|
|
100
|
+
asset_id: entry.id,
|
|
101
|
+
url: resolver.file(entry.file).url,
|
|
102
|
+
filename: entry.filename,
|
|
103
|
+
content_type: entry.mime,
|
|
104
|
+
size_bytes: 0
|
|
105
|
+
};
|
|
106
|
+
}
|
|
107
|
+
/**
|
|
108
|
+
* One media reference → its rendered value, by the slot kind that holds it. A
|
|
109
|
+
* reference the catalog does not carry resolves to `null`, the renderer's marked-empty
|
|
110
|
+
* branch — the resolver already reported it.
|
|
111
|
+
*/
|
|
112
|
+
function renderMediaRef(kind, value, media, resolver) {
|
|
113
|
+
const id = assetId(value);
|
|
114
|
+
const entry = id === null ? void 0 : media.get(id);
|
|
115
|
+
if (entry === void 0 || entry.kind !== kind) return null;
|
|
116
|
+
switch (kind) {
|
|
117
|
+
case "image": return imageValue(entry, value, resolver);
|
|
118
|
+
case "video": return videoValue(entry, resolver);
|
|
119
|
+
case "tour": return tourValue(entry);
|
|
120
|
+
case "document": return documentValue(entry, resolver);
|
|
121
|
+
default: return null;
|
|
122
|
+
}
|
|
123
|
+
}
|
|
124
|
+
const MEDIA_KINDS = /* @__PURE__ */ new Set([
|
|
125
|
+
"image",
|
|
126
|
+
"video",
|
|
127
|
+
"tour",
|
|
128
|
+
"document"
|
|
129
|
+
]);
|
|
130
|
+
function renderValue(def, value, media, resolver) {
|
|
131
|
+
if (value === null || value === void 0) return value;
|
|
132
|
+
if (MEDIA_KINDS.has(def.type)) return renderMediaRef(def.type, value, media, resolver);
|
|
133
|
+
if (def.type !== "list" || !Array.isArray(value)) return value;
|
|
134
|
+
const items = value;
|
|
135
|
+
if (def.fields !== void 0) {
|
|
136
|
+
const fields = def.fields;
|
|
137
|
+
return items.map((row) => {
|
|
138
|
+
if (typeof row !== "object" || row === null) return row;
|
|
139
|
+
const out = { ...row };
|
|
140
|
+
for (const [field, fieldDef] of Object.entries(fields)) out[field] = renderValue(fieldDef, out[field], media, resolver);
|
|
141
|
+
return out;
|
|
142
|
+
});
|
|
143
|
+
}
|
|
144
|
+
if (def.element !== void 0) {
|
|
145
|
+
const element = def.element;
|
|
146
|
+
return items.map((item) => renderValue(element, item, media, resolver));
|
|
147
|
+
}
|
|
148
|
+
return items;
|
|
149
|
+
}
|
|
150
|
+
/**
|
|
151
|
+
* The slot values a renderer receives for one resolved instance: every media reference
|
|
152
|
+
* resolved through `resolver`, every other value unchanged. The section's declarations
|
|
153
|
+
* decide which values hold media.
|
|
154
|
+
*/
|
|
155
|
+
function renderInstanceSlots(instance, section, media, resolver = servedMedia) {
|
|
156
|
+
const out = {};
|
|
157
|
+
for (const [id, value] of Object.entries(instance.slots)) {
|
|
158
|
+
const def = section.schema.slots[id];
|
|
159
|
+
out[id] = def === void 0 ? value : renderValue(def, value, media, resolver);
|
|
160
|
+
}
|
|
161
|
+
return out;
|
|
162
|
+
}
|
|
163
|
+
|
|
164
|
+
//#endregion
|
|
165
|
+
export { cropRectOf, renderInstanceSlots, renderMediaRef, servedMedia };
|
|
@@ -0,0 +1,210 @@
|
|
|
1
|
+
import { _ as PropertyFactsSchema } from "../packages/internal/property-facts/dist/property-facts-CSdkSuD7.js";
|
|
2
|
+
import "../packages/internal/property-facts/dist/index.js";
|
|
3
|
+
import { basename, extname } from "node:path";
|
|
4
|
+
|
|
5
|
+
//#region src/fixtures/property.ts
|
|
6
|
+
const MIME_BY_EXTENSION = {
|
|
7
|
+
".pdf": "application/pdf",
|
|
8
|
+
".mp4": "video/mp4",
|
|
9
|
+
".webm": "video/webm",
|
|
10
|
+
".mov": "video/quicktime",
|
|
11
|
+
".mp3": "audio/mpeg",
|
|
12
|
+
".wav": "audio/wav",
|
|
13
|
+
".png": "image/png",
|
|
14
|
+
".jpg": "image/jpeg",
|
|
15
|
+
".jpeg": "image/jpeg",
|
|
16
|
+
".webp": "image/webp",
|
|
17
|
+
".avif": "image/avif",
|
|
18
|
+
".gif": "image/gif",
|
|
19
|
+
".svg": "image/svg+xml",
|
|
20
|
+
".zip": "application/zip"
|
|
21
|
+
};
|
|
22
|
+
/** The URL a media file serves at — a derived raster's base rung, or the file itself. */
|
|
23
|
+
function mediaUrl(file) {
|
|
24
|
+
return typeof file === "string" ? file : file.url;
|
|
25
|
+
}
|
|
26
|
+
function displayName(url) {
|
|
27
|
+
const ext = extname(url);
|
|
28
|
+
return basename(url, ext).replace(/-[0-9a-f]{8}$/, "") + ext;
|
|
29
|
+
}
|
|
30
|
+
function mimeOf(url) {
|
|
31
|
+
return MIME_BY_EXTENSION[extname(url).toLowerCase()] ?? "application/octet-stream";
|
|
32
|
+
}
|
|
33
|
+
function isMediaFile(value) {
|
|
34
|
+
if (typeof value === "string") return value.length > 0;
|
|
35
|
+
return typeof value === "object" && value !== null && typeof value.url === "string" && typeof value.width === "number" && typeof value.height === "number";
|
|
36
|
+
}
|
|
37
|
+
/**
|
|
38
|
+
* Map a property's files to ids, derive what the platform derives, and validate the
|
|
39
|
+
* result with the platform schema. `file` is the module the property was loaded from,
|
|
40
|
+
* which every violation names.
|
|
41
|
+
*/
|
|
42
|
+
function canonicalizeProperty(property, file) {
|
|
43
|
+
const violations = [];
|
|
44
|
+
const media = /* @__PURE__ */ new Map();
|
|
45
|
+
const invalid = (message) => {
|
|
46
|
+
violations.push({
|
|
47
|
+
rule: "fixtures/property-invalid",
|
|
48
|
+
file,
|
|
49
|
+
message
|
|
50
|
+
});
|
|
51
|
+
};
|
|
52
|
+
const seen = /* @__PURE__ */ new Map();
|
|
53
|
+
const admit = (pool, id, path) => {
|
|
54
|
+
if (typeof id !== "string" || id === "") {
|
|
55
|
+
invalid(`${path}: every entry needs a non-empty string id`);
|
|
56
|
+
return false;
|
|
57
|
+
}
|
|
58
|
+
let ids = seen.get(pool);
|
|
59
|
+
if (ids === void 0) seen.set(pool, ids = /* @__PURE__ */ new Set());
|
|
60
|
+
if (ids.has(id)) {
|
|
61
|
+
invalid(`${path}: id "${id}" is repeated within ${pool}`);
|
|
62
|
+
return false;
|
|
63
|
+
}
|
|
64
|
+
ids.add(id);
|
|
65
|
+
return true;
|
|
66
|
+
};
|
|
67
|
+
const admitFile = (value, path) => {
|
|
68
|
+
if (isMediaFile(value)) return true;
|
|
69
|
+
invalid(`${path}: expected an imported media file`);
|
|
70
|
+
return false;
|
|
71
|
+
};
|
|
72
|
+
const photos = [];
|
|
73
|
+
for (const [i, photo] of (property.photos ?? []).entries()) {
|
|
74
|
+
const path = `photos[${i}]`;
|
|
75
|
+
if (!admit("photos", photo.id, path) || !admitFile(photo.file, `${path}.file`)) continue;
|
|
76
|
+
const { file: photoFile, ...row } = photo;
|
|
77
|
+
photos.push(row);
|
|
78
|
+
media.set(photo.id, entry(photo.id, "image", photoFile, photo.caption ?? ""));
|
|
79
|
+
}
|
|
80
|
+
const floorPlans = [];
|
|
81
|
+
for (const [i, plan] of (property.floor_plans ?? []).entries()) {
|
|
82
|
+
const path = `floor_plans[${i}]`;
|
|
83
|
+
if (!admit("floor_plans", plan.id, path) || !admitFile(plan.file, `${path}.file`)) continue;
|
|
84
|
+
const { file: planFile, ...row } = plan;
|
|
85
|
+
floorPlans.push({
|
|
86
|
+
...row,
|
|
87
|
+
processed_s3_key: mediaUrl(planFile)
|
|
88
|
+
});
|
|
89
|
+
media.set(plan.id, entry(plan.id, "image", planFile, ""));
|
|
90
|
+
}
|
|
91
|
+
const videos = [];
|
|
92
|
+
for (const [i, video] of (property.videos ?? []).entries()) {
|
|
93
|
+
const path = `videos[${i}]`;
|
|
94
|
+
if (!admit("videos", video.id, path)) continue;
|
|
95
|
+
if (video.source === "upload") {
|
|
96
|
+
if (!admitFile(video.file, `${path}.file`)) continue;
|
|
97
|
+
const { file: videoFile, ...row } = video;
|
|
98
|
+
videos.push({
|
|
99
|
+
...row,
|
|
100
|
+
url: null,
|
|
101
|
+
provider: null
|
|
102
|
+
});
|
|
103
|
+
media.set(video.id, entry(video.id, "video", videoFile, video.caption ?? ""));
|
|
104
|
+
} else {
|
|
105
|
+
videos.push(video);
|
|
106
|
+
media.set(video.id, {
|
|
107
|
+
...entry(video.id, "video", null, video.caption ?? ""),
|
|
108
|
+
url: video.url,
|
|
109
|
+
provider: video.provider
|
|
110
|
+
});
|
|
111
|
+
}
|
|
112
|
+
}
|
|
113
|
+
for (const [i, tour] of (property.tours ?? []).entries()) {
|
|
114
|
+
if (!admit("tours", tour.id, `tours[${i}]`)) continue;
|
|
115
|
+
media.set(tour.id, {
|
|
116
|
+
...entry(tour.id, "tour", null, ""),
|
|
117
|
+
url: tour.url,
|
|
118
|
+
provider: tour.provider
|
|
119
|
+
});
|
|
120
|
+
}
|
|
121
|
+
const documents = [];
|
|
122
|
+
const documentNotes = [];
|
|
123
|
+
for (const [i, doc] of (property.documents ?? []).entries()) {
|
|
124
|
+
const path = `documents[${i}]`;
|
|
125
|
+
if (!admit("documents", doc.id, path) || !admitFile(doc.file, `${path}.file`)) continue;
|
|
126
|
+
const { file: docFile, ...row } = doc;
|
|
127
|
+
const url = mediaUrl(docFile);
|
|
128
|
+
documents.push({
|
|
129
|
+
...row,
|
|
130
|
+
filename: displayName(url),
|
|
131
|
+
mime: mimeOf(url)
|
|
132
|
+
});
|
|
133
|
+
if (typeof doc.notes === "string" && doc.notes !== "") documentNotes.push({
|
|
134
|
+
upload_id: doc.id,
|
|
135
|
+
notes: doc.notes
|
|
136
|
+
});
|
|
137
|
+
media.set(doc.id, entry(doc.id, "document", docFile, ""));
|
|
138
|
+
}
|
|
139
|
+
const contacts = [];
|
|
140
|
+
for (const [i, contact] of (property.contacts ?? []).entries()) {
|
|
141
|
+
const path = `contacts[${i}]`;
|
|
142
|
+
if (!admit("contacts", contact.id, path)) continue;
|
|
143
|
+
const { avatar, logo_dark: logoDark, logo_light: logoLight, ...row } = contact;
|
|
144
|
+
const image = (value, field) => {
|
|
145
|
+
if (value === null || value === void 0) return null;
|
|
146
|
+
if (!admitFile(value, `${path}.${field}`)) return null;
|
|
147
|
+
const id = `contact:${contact.id}:${field}`;
|
|
148
|
+
media.set(id, entry(id, "image", value, contact.name ?? ""));
|
|
149
|
+
return id;
|
|
150
|
+
};
|
|
151
|
+
contacts.push({
|
|
152
|
+
...row,
|
|
153
|
+
avatar_upload_id: image(avatar, "avatar"),
|
|
154
|
+
logo_dark_upload_id: image(logoDark, "logo_dark"),
|
|
155
|
+
logo_light_upload_id: image(logoLight, "logo_light")
|
|
156
|
+
});
|
|
157
|
+
}
|
|
158
|
+
if (violations.length > 0) return {
|
|
159
|
+
facts: null,
|
|
160
|
+
media,
|
|
161
|
+
violations
|
|
162
|
+
};
|
|
163
|
+
const candidate = {
|
|
164
|
+
address: property.address,
|
|
165
|
+
lat: property.lat,
|
|
166
|
+
lon: property.lon,
|
|
167
|
+
property_type: property.property_type,
|
|
168
|
+
listing_intent: property.listing_intent,
|
|
169
|
+
units: property.units,
|
|
170
|
+
narrative: property.narrative,
|
|
171
|
+
tours: property.tours,
|
|
172
|
+
comparables: property.comparables,
|
|
173
|
+
photos,
|
|
174
|
+
floor_plans: floorPlans,
|
|
175
|
+
videos,
|
|
176
|
+
document_notes: documentNotes,
|
|
177
|
+
documents,
|
|
178
|
+
contacts
|
|
179
|
+
};
|
|
180
|
+
const parsed = PropertyFactsSchema.safeParse(candidate);
|
|
181
|
+
if (!parsed.success) {
|
|
182
|
+
for (const issue of parsed.error.issues) invalid(`${issue.path.map(String).join(".") || "(root)"}: ${issue.message}`);
|
|
183
|
+
return {
|
|
184
|
+
facts: null,
|
|
185
|
+
media,
|
|
186
|
+
violations
|
|
187
|
+
};
|
|
188
|
+
}
|
|
189
|
+
return {
|
|
190
|
+
facts: parsed.data,
|
|
191
|
+
media,
|
|
192
|
+
violations
|
|
193
|
+
};
|
|
194
|
+
}
|
|
195
|
+
function entry(id, kind, file, alt) {
|
|
196
|
+
const url = file === null ? "" : mediaUrl(file);
|
|
197
|
+
return {
|
|
198
|
+
id,
|
|
199
|
+
kind,
|
|
200
|
+
file,
|
|
201
|
+
url: null,
|
|
202
|
+
provider: null,
|
|
203
|
+
alt,
|
|
204
|
+
filename: url === "" ? "" : displayName(url),
|
|
205
|
+
mime: url === "" ? "" : mimeOf(url)
|
|
206
|
+
};
|
|
207
|
+
}
|
|
208
|
+
|
|
209
|
+
//#endregion
|
|
210
|
+
export { canonicalizeProperty, mediaUrl };
|