@garagem-ai/site-sdk 0.4.10 → 0.4.11
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/README.md +17 -16
- package/dist/index.d.mts +86 -5
- package/dist/index.d.ts +86 -5
- package/dist/index.js +283 -2
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +273 -2
- package/dist/index.mjs.map +1 -1
- package/dist/react.d.mts +1 -1
- package/dist/react.d.ts +1 -1
- package/dist/react.js +1 -1
- package/dist/react.js.map +1 -1
- package/dist/react.mjs +1 -1
- package/dist/react.mjs.map +1 -1
- package/dist/{search-engine-t3SBrLHS.d.mts → search-engine-B83s_fVd.d.mts} +9 -2
- package/dist/{search-engine-t3SBrLHS.d.ts → search-engine-B83s_fVd.d.ts} +9 -2
- package/package.json +1 -1
- package/src/index.ts +19 -0
- package/src/listing-detail.ts +357 -0
- package/src/react/styles/search-chrome-css.generated.ts +1 -1
- package/src/studio-contract.ts +9 -2
- package/src/types.ts +8 -1
package/dist/index.mjs
CHANGED
|
@@ -1919,6 +1919,261 @@ 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
|
+
return {
|
|
2165
|
+
breadcrumb: listingBreadcrumb(listing),
|
|
2166
|
+
values: listingValues(listing),
|
|
2167
|
+
facts: listingFacts(listing),
|
|
2168
|
+
location: listingLocationBlock(listing),
|
|
2169
|
+
description: listingDescriptionPreview(
|
|
2170
|
+
listing.description,
|
|
2171
|
+
options?.descriptionExpanded === true
|
|
2172
|
+
),
|
|
2173
|
+
mediaOverlays: listingMediaOverlays(listing)
|
|
2174
|
+
};
|
|
2175
|
+
}
|
|
2176
|
+
|
|
1922
2177
|
// src/studio-contract.ts
|
|
1923
2178
|
var STUDIO_SDK_PACKAGE = "@garagem-ai/site-sdk";
|
|
1924
2179
|
var STUDIO_SDK_CONTRACT = {
|
|
@@ -1926,8 +2181,9 @@ var STUDIO_SDK_CONTRACT = {
|
|
|
1926
2181
|
/**
|
|
1927
2182
|
* Exact pin for generated Studio sites. Must be ≥ `selfInjectSince` so
|
|
1928
2183
|
* prompts that skip the layout chrome tag match the tarball v0 installs.
|
|
1929
|
-
* 0.4.9 adds
|
|
1930
|
-
*
|
|
2184
|
+
* 0.4.9 adds listingDetailModel (values, facts, location, breadcrumb,
|
|
2185
|
+
* description clamp, video/tour), getSimilarListings, and
|
|
2186
|
+
* listingAmenityGroups so listing detail never prints amenity ids.
|
|
1931
2187
|
*/
|
|
1932
2188
|
minNpmVersion: "0.4.9",
|
|
1933
2189
|
/** First release where ListingCard and ResultsSkeleton inject the sheet. */
|
|
@@ -1962,6 +2218,7 @@ var STUDIO_SDK_CONTRACT = {
|
|
|
1962
2218
|
"isVisitSlotAllowed",
|
|
1963
2219
|
"STUDIO_DEFAULT_VISIT_SCHEDULE"
|
|
1964
2220
|
],
|
|
2221
|
+
listingDetailExports: ["listingDetailModel", "getSimilarListings"],
|
|
1965
2222
|
amenityExports: ["listingAmenityGroups"]
|
|
1966
2223
|
};
|
|
1967
2224
|
var STUDIO_SITE_LAYOUT = {
|
|
@@ -2056,6 +2313,10 @@ function studioLeadInstruction() {
|
|
|
2056
2313
|
const names = STUDIO_SDK_CONTRACT.leadExports.join(", ");
|
|
2057
2314
|
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
2315
|
}
|
|
2316
|
+
function studioListingDetailInstruction() {
|
|
2317
|
+
const names = STUDIO_SDK_CONTRACT.listingDetailExports.join(", ");
|
|
2318
|
+
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 with the helper clamp + toggle (keep the full text; do not drop the remainder). 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.`;
|
|
2319
|
+
}
|
|
2059
2320
|
function studioAmenityInstruction() {
|
|
2060
2321
|
const names = STUDIO_SDK_CONTRACT.amenityExports.join(", ");
|
|
2061
2322
|
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 +2509,7 @@ export {
|
|
|
2248
2509
|
FORBIDDEN_SEARCH_QUERY_KEYS,
|
|
2249
2510
|
GaragemSdkError,
|
|
2250
2511
|
LISTING_AMENITY_TITLES,
|
|
2512
|
+
LISTING_DESCRIPTION_CLAMP,
|
|
2251
2513
|
LeadSubmitError,
|
|
2252
2514
|
SEARCH_CSS_RECIPE,
|
|
2253
2515
|
SEARCH_CSS_VARS,
|
|
@@ -2294,10 +2556,18 @@ export {
|
|
|
2294
2556
|
isVisitSlotAllowed,
|
|
2295
2557
|
labelAmenities,
|
|
2296
2558
|
listingAmenityGroups,
|
|
2559
|
+
listingBreadcrumb,
|
|
2297
2560
|
listingBusinessLabel,
|
|
2561
|
+
listingDescriptionPreview,
|
|
2562
|
+
listingDetailModel,
|
|
2563
|
+
listingFacts,
|
|
2564
|
+
listingLocationBlock,
|
|
2298
2565
|
listingLocationLabel,
|
|
2299
2566
|
listingLookupKey,
|
|
2567
|
+
listingMapsHref,
|
|
2568
|
+
listingMediaOverlays,
|
|
2300
2569
|
listingPublicPath,
|
|
2570
|
+
listingValues,
|
|
2301
2571
|
mergeAppliedSearchQueryIntoSearch2 as mergeAppliedSearchQueryIntoSearch,
|
|
2302
2572
|
normalizeVisitDate,
|
|
2303
2573
|
normalizeVisitTime,
|
|
@@ -2327,6 +2597,7 @@ export {
|
|
|
2327
2597
|
studioDefaultLeadUi,
|
|
2328
2598
|
studioLayoutInstruction,
|
|
2329
2599
|
studioLeadInstruction,
|
|
2600
|
+
studioListingDetailInstruction,
|
|
2330
2601
|
studioSdkPinInstruction,
|
|
2331
2602
|
studioSearchLandmarkInstruction,
|
|
2332
2603
|
studioSiteWidthCss,
|