| 12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061 |
- const asArray = (value) => Array.isArray(value) ? value : [];
- const text = (value, fallback = "") => typeof value === "string" && value.trim() ? value.trim() : fallback;
- const wearingRelations = new Set(["human_wearing", "human_wearing_static", "human_wearing_action"]);
- export function compileSetDiversityPolicy(scenePolicy = {}) {
- const supportMode = text(scenePolicy.support_mode, "installed_or_environmental");
- const wearable = supportMode === "body_worn" || supportMode === "floor_supported" && scenePolicy.wearable_subtype === "footwear";
- return {
- schema_version: "1.0",
- minimum_distinct_content_signatures: 5,
- maximum_same_axis_framing: 2,
- maximum_human_wearing_pages: Number(scenePolicy.set_budget?.maximum_human_wearing_pages ?? (wearable ? 3 : 0)),
- required_relation_families: wearable
- ? ["isolated", "detail", "stable_display", "human_proximity", "human_wearing"]
- : ["isolated", "detail", "environmental", "human_context"],
- allowed_relation_modes: asArray(scenePolicy.allowed_relation_modes).length
- ? [...scenePolicy.allowed_relation_modes]
- : wearable
- ? ["isolated", "detail", "stable_display", "human_proximity", "human_wearing_static", "human_wearing_action"]
- : ["isolated", "detail", "stable_display", "environmental", "human_proximity", "human_handheld"],
- automatic_paid_regeneration: false,
- };
- }
- export function relationFamily(value = "") {
- const relation = text(value, "unknown");
- if (wearingRelations.has(relation)) return "human_wearing";
- if (relation.includes("detail") || relation.includes("material") || relation.includes("feature")) return "detail";
- if (relation.includes("isolated") || relation.includes("single accurate")) return "isolated";
- if (relation.includes("proximity")) return "human_proximity";
- if (relation.includes("handheld")) return "human_context";
- if (relation.includes("environment") || relation.includes("tabletop") || relation.includes("support") || relation.includes("display")) return "stable_display";
- return relation;
- }
- export function contentSignatureForPage({ page = {}, relationMode = "", index = 0 } = {}) {
- const shot = page.shot_spec || {};
- const evidence = asArray(page.evidence_refs).join("+") || `page:${index + 1}`;
- return [
- text(page.business_category, text(page.role, "page")),
- text(page.set_design?.render_family, "render"),
- text(shot.camera_axis, "axis"),
- text(shot.framing_mode, "framing"),
- text(relationMode || shot.interaction_mode, "relation"),
- evidence,
- ].join("|");
- }
- export function summarizePlannedDiversity(images = [], policy = {}) {
- const signatures = asArray(images).map((page) => text(page.set_design?.content_signature));
- const axisFraming = asArray(images).map((page) => `${text(page.shot_spec?.camera_axis)}|${text(page.shot_spec?.framing_mode)}`);
- const wearing = asArray(images).filter((page) => relationFamily(page.expected_page_compliance?.product_human_relation) === "human_wearing").length;
- const counts = (values) => Object.fromEntries([...new Set(values)].map((value) => [value, values.filter((candidate) => candidate === value).length]));
- return {
- distinct_content_signatures: new Set(signatures.filter(Boolean)).size,
- axis_framing_counts: counts(axisFraming),
- human_wearing_pages: wearing,
- policy: policy.schema_version ? policy : compileSetDiversityPolicy(policy),
- };
- }
|