@garagem-ai/site-sdk 0.4.10 → 0.4.12

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/dist/index.mjs CHANGED
@@ -1919,6 +1919,265 @@ function paginationPages(currentPage, totalPages, padding) {
1919
1919
  return pages;
1920
1920
  }
1921
1921
 
1922
+ // src/listing-detail.ts
1923
+ var LISTING_DESCRIPTION_CLAMP = 280;
1924
+ var VIDEO_HOST_HINTS = [
1925
+ "youtube.com",
1926
+ "youtu.be",
1927
+ "vimeo.com",
1928
+ "wistia.com",
1929
+ "wistia.net"
1930
+ ];
1931
+ var BREADCRUMB_LABELS = {
1932
+ imoveis: "Im\xF3veis",
1933
+ venda: "Venda",
1934
+ aluguel: "Aluguel",
1935
+ rental: "Aluguel",
1936
+ sale: "Venda"
1937
+ };
1938
+ function finiteNumber(value) {
1939
+ if (typeof value === "number" && Number.isFinite(value)) return value;
1940
+ if (typeof value === "string" && value.trim() !== "") {
1941
+ const parsed = Number(value);
1942
+ if (Number.isFinite(parsed)) return parsed;
1943
+ }
1944
+ return null;
1945
+ }
1946
+ function positiveCount(value) {
1947
+ const amount = finiteNumber(value);
1948
+ return amount != null && amount > 0 ? amount : null;
1949
+ }
1950
+ function formatFloorFact(value) {
1951
+ if (typeof value === "number" && Number.isFinite(value)) {
1952
+ return value === 0 ? "T\xE9rreo" : String(value);
1953
+ }
1954
+ if (typeof value !== "string") return null;
1955
+ const trimmed = value.trim();
1956
+ if (!trimmed) return null;
1957
+ const parsed = Number(trimmed);
1958
+ if (Number.isFinite(parsed) && trimmed === String(parsed)) {
1959
+ return parsed === 0 ? "T\xE9rreo" : trimmed;
1960
+ }
1961
+ return trimmed;
1962
+ }
1963
+ function httpsUrl(raw) {
1964
+ if (!raw) return null;
1965
+ try {
1966
+ const url = new URL(raw);
1967
+ if (url.protocol !== "https:") return null;
1968
+ return url.toString();
1969
+ } catch {
1970
+ return null;
1971
+ }
1972
+ }
1973
+ function isVideoPlatformUrl(url) {
1974
+ const host = new URL(url).hostname.toLowerCase();
1975
+ return VIDEO_HOST_HINTS.some(
1976
+ (hint) => host === hint || host.endsWith(`.${hint}`)
1977
+ );
1978
+ }
1979
+ function overlayKind(type, src) {
1980
+ if (type === "image" || type === "photo") return null;
1981
+ const host = new URL(src).hostname.toLowerCase();
1982
+ if (type === "tour" || type === "virtual_tour" || host.includes("matterport")) {
1983
+ return "tour";
1984
+ }
1985
+ if (isVideoPlatformUrl(src) || type === "video") return "video";
1986
+ return type ? "tour" : null;
1987
+ }
1988
+ var VIMEO_ID_RE = /vimeo\.com\/(?:video\/|channels\/[^/]+\/|groups\/[^/]+\/videos\/)?(\d+)/i;
1989
+ var WISTIA_ID_RE = /\/(?:medias|embed\/(?:iframe|medias))\/([a-zA-Z0-9]+)/i;
1990
+ function vimeoPrivacyHash(url, id) {
1991
+ const fromQuery = url.searchParams.get("h");
1992
+ if (fromQuery) return fromQuery;
1993
+ const segments = url.pathname.split("/").filter(Boolean);
1994
+ const idIndex = segments.indexOf(id);
1995
+ const next = idIndex >= 0 ? segments[idIndex + 1] : void 0;
1996
+ return next && /^[a-f0-9]{6,12}$/i.test(next) ? next : null;
1997
+ }
1998
+ function embedSrc(src) {
1999
+ const url = new URL(src);
2000
+ const host = url.hostname.toLowerCase();
2001
+ if (host === "youtu.be" || host.endsWith(".youtu.be")) {
2002
+ const id = url.pathname.replace(/^\//, "").split("/")[0];
2003
+ return id ? `https://www.youtube.com/embed/${id}` : src;
2004
+ }
2005
+ if (host.includes("youtube.com")) {
2006
+ const id = url.searchParams.get("v") || url.pathname.split("/").pop();
2007
+ return id ? `https://www.youtube.com/embed/${id}` : src;
2008
+ }
2009
+ if (host.includes("player.vimeo.com")) return src;
2010
+ if (host.includes("vimeo.com")) {
2011
+ const id = src.match(VIMEO_ID_RE)?.[1];
2012
+ if (!id) return src;
2013
+ const hash = vimeoPrivacyHash(url, id);
2014
+ return hash ? `https://player.vimeo.com/video/${id}?h=${encodeURIComponent(hash)}` : `https://player.vimeo.com/video/${id}`;
2015
+ }
2016
+ if (host.includes("wistia.com") || host.includes("wistia.net")) {
2017
+ if (src.includes("/embed/iframe/")) return src;
2018
+ const id = src.match(WISTIA_ID_RE)?.[1];
2019
+ return id ? `https://fast.wistia.net/embed/iframe/${id}` : src;
2020
+ }
2021
+ return src;
2022
+ }
2023
+ function crumbLabel(segment) {
2024
+ const mapped = BREADCRUMB_LABELS[segment];
2025
+ if (mapped) return mapped;
2026
+ if (/^[a-z]{2}$/.test(segment)) return segment.toUpperCase();
2027
+ return segment.split("-").filter(Boolean).map((part) => part.charAt(0).toUpperCase() + part.slice(1)).join(" ");
2028
+ }
2029
+ function listingValues(listing) {
2030
+ const values = [
2031
+ {
2032
+ key: "price",
2033
+ label: "Pre\xE7o",
2034
+ text: listing.priceVisibility === "private" ? "Sob consulta" : formatListingPrice(listing.price)
2035
+ }
2036
+ ];
2037
+ const condoFee = positiveCount(listing.property?.condoFee);
2038
+ if (condoFee != null) {
2039
+ values.push({
2040
+ key: "condoFee",
2041
+ label: "Condom\xEDnio",
2042
+ text: formatListingPrice(condoFee)
2043
+ });
2044
+ }
2045
+ const propertyTax = positiveCount(listing.property?.propertyTax);
2046
+ if (propertyTax != null) {
2047
+ values.push({
2048
+ key: "propertyTax",
2049
+ label: "IPTU",
2050
+ text: formatListingPrice(propertyTax)
2051
+ });
2052
+ }
2053
+ return values;
2054
+ }
2055
+ function listingFacts(listing) {
2056
+ const property = listing.property ?? {};
2057
+ const facts = [];
2058
+ const area = formatAreaM2(
2059
+ positiveCount(property.usableArea) ?? positiveCount(property.totalArea)
2060
+ );
2061
+ if (area) facts.push({ key: "area", label: "\xC1rea", text: area });
2062
+ const bedrooms = positiveCount(property.bedrooms);
2063
+ if (bedrooms != null) {
2064
+ facts.push({
2065
+ key: "bedrooms",
2066
+ label: "Dormit\xF3rios",
2067
+ text: String(bedrooms)
2068
+ });
2069
+ }
2070
+ const suites = positiveCount(property.suites);
2071
+ if (suites != null) {
2072
+ facts.push({ key: "suites", label: "Su\xEDtes", text: String(suites) });
2073
+ }
2074
+ const parking = positiveCount(property.parkingSpaces);
2075
+ if (parking != null) {
2076
+ facts.push({ key: "parkingSpaces", label: "Vagas", text: String(parking) });
2077
+ }
2078
+ const rooms = positiveCount(property.rooms);
2079
+ if (rooms != null) {
2080
+ facts.push({ key: "rooms", label: "Salas", text: String(rooms) });
2081
+ }
2082
+ const floorText = formatFloorFact(property.floor);
2083
+ if (floorText) {
2084
+ facts.push({ key: "floor", label: "Andar", text: floorText });
2085
+ }
2086
+ return facts;
2087
+ }
2088
+ function listingMapsHref(location) {
2089
+ if (!location) return null;
2090
+ const lat = finiteNumber(location.coordinates?.lat);
2091
+ const lng = finiteNumber(location.coordinates?.lng);
2092
+ if (lat != null && lng != null && !(lat === 0 && lng === 0)) {
2093
+ return `https://www.google.com/maps/search/?api=1&query=${lat},${lng}`;
2094
+ }
2095
+ const query = [
2096
+ [location.street, location.number].filter(Boolean).join(" ").trim(),
2097
+ location.neighborhood,
2098
+ location.city,
2099
+ location.state
2100
+ ].map((part) => part ? String(part).trim() : "").filter(Boolean).join(", ");
2101
+ if (!query) return null;
2102
+ return `https://www.google.com/maps/search/?api=1&query=${encodeURIComponent(query)}`;
2103
+ }
2104
+ function listingLocationBlock(listing) {
2105
+ const location = listing?.location;
2106
+ if (!location) return null;
2107
+ const street = [location.street, location.number].filter(Boolean).join(" ").trim();
2108
+ const label = street || listingLocationLabel(location);
2109
+ const mapsHref = listingMapsHref(location);
2110
+ if (!label && !mapsHref) return null;
2111
+ return { label, mapsHref };
2112
+ }
2113
+ function listingBreadcrumb(listing) {
2114
+ const path = listingPublicPath(listing);
2115
+ const segments = path.split("/").filter(Boolean);
2116
+ if (segments[0] !== "imoveis") return [];
2117
+ const crumbs = [
2118
+ { label: "Im\xF3veis", href: "/imoveis" }
2119
+ ];
2120
+ let href = "/imoveis";
2121
+ for (const segment of segments.slice(1)) {
2122
+ if (segment.startsWith("id-")) break;
2123
+ href = `${href}/${segment}`;
2124
+ if (isListingDetailPath(href)) continue;
2125
+ crumbs.push({ label: crumbLabel(segment), href });
2126
+ }
2127
+ return crumbs;
2128
+ }
2129
+ function listingDescriptionPreview(description, expanded = false) {
2130
+ const text = description?.trim() ?? "";
2131
+ if (!text) return null;
2132
+ if (text.length <= LISTING_DESCRIPTION_CLAMP) {
2133
+ return { text, truncated: false, toggleLabel: null };
2134
+ }
2135
+ if (expanded) {
2136
+ return { text, truncated: true, toggleLabel: "Ler menos" };
2137
+ }
2138
+ return {
2139
+ text: `${text.slice(0, LISTING_DESCRIPTION_CLAMP).trimEnd()}\u2026`,
2140
+ truncated: true,
2141
+ toggleLabel: "Ler mais"
2142
+ };
2143
+ }
2144
+ function listingMediaOverlays(listing) {
2145
+ const overlays = [];
2146
+ const seen = /* @__PURE__ */ new Set();
2147
+ for (const item of listing.media ?? []) {
2148
+ const src = httpsUrl(item.src);
2149
+ if (!src) continue;
2150
+ const kind = overlayKind(item.type, src);
2151
+ if (!kind || seen.has(kind)) continue;
2152
+ seen.add(kind);
2153
+ overlays.push({
2154
+ key: kind,
2155
+ hash: kind,
2156
+ title: kind === "video" ? "V\xEDdeo" : "Tour virtual",
2157
+ href: `#${kind}`,
2158
+ embedSrc: embedSrc(src)
2159
+ });
2160
+ }
2161
+ return overlays;
2162
+ }
2163
+ function listingDetailModel(listing, options) {
2164
+ const descriptionPreview = listingDescriptionPreview(
2165
+ listing.description,
2166
+ options?.descriptionExpanded === true
2167
+ );
2168
+ return {
2169
+ breadcrumb: listingBreadcrumb(listing),
2170
+ values: listingValues(listing),
2171
+ facts: listingFacts(listing),
2172
+ location: listingLocationBlock(listing),
2173
+ /** Clamped (or full) copy — a string so JSX `{model.description}` is safe. */
2174
+ description: descriptionPreview?.text ?? null,
2175
+ descriptionTruncated: descriptionPreview?.truncated === true,
2176
+ descriptionToggleLabel: descriptionPreview?.toggleLabel ?? null,
2177
+ mediaOverlays: listingMediaOverlays(listing)
2178
+ };
2179
+ }
2180
+
1922
2181
  // src/studio-contract.ts
1923
2182
  var STUDIO_SDK_PACKAGE = "@garagem-ai/site-sdk";
1924
2183
  var STUDIO_SDK_CONTRACT = {
@@ -1926,10 +2185,10 @@ var STUDIO_SDK_CONTRACT = {
1926
2185
  /**
1927
2186
  * Exact pin for generated Studio sites. Must be ≥ `selfInjectSince` so
1928
2187
  * prompts that skip the layout chrome tag match the tarball v0 installs.
1929
- * 0.4.9 adds `listingAmenityGroups` so listing detail never prints
1930
- * amenity ids.
2188
+ * 0.4.12 flattens listingDetailModel.description to a string (plus
2189
+ * descriptionToggleLabel) so JSX cannot render the clamp object.
1931
2190
  */
1932
- minNpmVersion: "0.4.9",
2191
+ minNpmVersion: "0.4.12",
1933
2192
  /** First release where ListingCard and ResultsSkeleton inject the sheet. */
1934
2193
  selfInjectSince: "0.4.2",
1935
2194
  chromeStrategy: "self-inject",
@@ -1962,6 +2221,7 @@ var STUDIO_SDK_CONTRACT = {
1962
2221
  "isVisitSlotAllowed",
1963
2222
  "STUDIO_DEFAULT_VISIT_SCHEDULE"
1964
2223
  ],
2224
+ listingDetailExports: ["listingDetailModel", "getSimilarListings"],
1965
2225
  amenityExports: ["listingAmenityGroups"]
1966
2226
  };
1967
2227
  var STUDIO_SITE_LAYOUT = {
@@ -2056,6 +2316,10 @@ function studioLeadInstruction() {
2056
2316
  const names = STUDIO_SDK_CONTRACT.leadExports.join(", ");
2057
2317
  return `Listing-detail visit/contact leads: import ${names} from \`${STUDIO_SDK_PACKAGE}\` (the main package, not \`/react\`). Call \`submitVisitLead\` / \`submitContactLead\` \u2014 never concatenate a leads webhook URL and never POST the Showcase demo leads route.`;
2058
2318
  }
2319
+ function studioListingDetailInstruction() {
2320
+ const names = STUDIO_SDK_CONTRACT.listingDetailExports.join(", ");
2321
+ return `Listing detail blocks: import ${names} from \`${STUDIO_SDK_PACKAGE}\` and \`ListingCard\` from \`${STUDIO_SDK_PACKAGE}/react\`. Render \`listingDetailModel(listing)\` for breadcrumb (hrefs are search prefixes of \`listing.path\`, never invented paths), values (price / sob consulta, condo, IPTU), facts (omit empty zeros; bedrooms \u2260 salas), location plus a discreet Google Maps \`<a target="_blank" rel="noopener noreferrer">\`, and description as the string \`model.description\` plus \`model.descriptionToggleLabel\` (keep the full text; do not drop the remainder). Map facts/values/breadcrumb items to \`.label\` / \`.text\` / \`.href\`; use \`model.location.label\` and \`model.location.mapsHref\`. Never interpolate \`model.location\`, \`model.facts\`, \`model.values\`, \`model.breadcrumb\`, \`model.mediaOverlays\`, or amenity groups as a React child. Video/tour: \`model.mediaOverlays\` as hash links (\`#video\` / \`#tour\`) and a fullscreen overlay that closes with browser back; omit when empty. Similar listings: \`getSimilarListings({ siteId, listingId, baseUrl })\` + \`ListingCard\`; hide the section when the list is empty. Do not invent a local recommendation loop.`;
2322
+ }
2059
2323
  function studioAmenityInstruction() {
2060
2324
  const names = STUDIO_SDK_CONTRACT.amenityExports.join(", ");
2061
2325
  return `Listing amenities: import ${names} from \`${STUDIO_SDK_PACKAGE}\`. Render \`listingAmenityGroups(listing)\` (optional second arg: \`getSearchUi().dictionary\`). Use the helper titles (\`Comodidades\` / \`Comodidades do condom\xEDnio\`). Labels are already alphabetical (pt-BR) \u2014 keep that order. Omit empty groups. Never print amenity ids, never invent a local label map, and never title a section "Comodidades da unidade".`;
@@ -2248,6 +2512,7 @@ export {
2248
2512
  FORBIDDEN_SEARCH_QUERY_KEYS,
2249
2513
  GaragemSdkError,
2250
2514
  LISTING_AMENITY_TITLES,
2515
+ LISTING_DESCRIPTION_CLAMP,
2251
2516
  LeadSubmitError,
2252
2517
  SEARCH_CSS_RECIPE,
2253
2518
  SEARCH_CSS_VARS,
@@ -2294,10 +2559,18 @@ export {
2294
2559
  isVisitSlotAllowed,
2295
2560
  labelAmenities,
2296
2561
  listingAmenityGroups,
2562
+ listingBreadcrumb,
2297
2563
  listingBusinessLabel,
2564
+ listingDescriptionPreview,
2565
+ listingDetailModel,
2566
+ listingFacts,
2567
+ listingLocationBlock,
2298
2568
  listingLocationLabel,
2299
2569
  listingLookupKey,
2570
+ listingMapsHref,
2571
+ listingMediaOverlays,
2300
2572
  listingPublicPath,
2573
+ listingValues,
2301
2574
  mergeAppliedSearchQueryIntoSearch2 as mergeAppliedSearchQueryIntoSearch,
2302
2575
  normalizeVisitDate,
2303
2576
  normalizeVisitTime,
@@ -2327,6 +2600,7 @@ export {
2327
2600
  studioDefaultLeadUi,
2328
2601
  studioLayoutInstruction,
2329
2602
  studioLeadInstruction,
2603
+ studioListingDetailInstruction,
2330
2604
  studioSdkPinInstruction,
2331
2605
  studioSearchLandmarkInstruction,
2332
2606
  studioSiteWidthCss,