@sitepulse/web 1.0.1 → 1.0.2

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.js CHANGED
@@ -1241,6 +1241,7 @@ function renderCampaignDOM(campaign, handlers = {}) {
1241
1241
  let originalPaddingTop = null;
1242
1242
  let originalPaddingBottom = null;
1243
1243
  let resizeObserver = null;
1244
+ const shiftedElements = [];
1244
1245
  if (isBanner && typeof document !== "undefined" && document.body) {
1245
1246
  try {
1246
1247
  const isBottom = design.position === "bottom";
@@ -1262,14 +1263,64 @@ function renderCampaignDOM(campaign, handlers = {}) {
1262
1263
  }
1263
1264
  } catch {
1264
1265
  }
1266
+ const findTopFixedElements = () => {
1267
+ const candidates = [];
1268
+ try {
1269
+ const elements = Array.from(
1270
+ document.querySelectorAll(
1271
+ 'header, nav, [role="banner"], [class*="header"], [class*="navbar"], [class*="nav-fixed"], [class*="sticky"]'
1272
+ )
1273
+ );
1274
+ Array.from(document.body.children).forEach((child) => {
1275
+ if (child instanceof HTMLElement && child !== wrapper && child !== overlayEl && !elements.includes(child)) {
1276
+ elements.push(child);
1277
+ }
1278
+ });
1279
+ for (const el of elements) {
1280
+ if (el === wrapper || el === overlayEl || !el.isConnected) continue;
1281
+ const style = window.getComputedStyle(el);
1282
+ const pos = style.position;
1283
+ if (pos === "fixed" || pos === "sticky") {
1284
+ const rect = el.getBoundingClientRect();
1285
+ if (rect.top <= 15 && rect.height > 0 && rect.height < window.innerHeight * 0.5) {
1286
+ candidates.push(el);
1287
+ }
1288
+ }
1289
+ }
1290
+ } catch {
1291
+ }
1292
+ return candidates;
1293
+ };
1265
1294
  const updateOffset = () => {
1266
1295
  if (!wrapper || !document.body) return;
1267
1296
  const bannerHeight = wrapper.offsetHeight;
1268
1297
  if (bannerHeight > 0) {
1269
1298
  if (isBottom) {
1270
1299
  document.body.style.paddingBottom = `${basePaddingBottom + bannerHeight}px`;
1300
+ document.documentElement.style.setProperty(
1301
+ "--sitepulse-bottom-banner-height",
1302
+ `${bannerHeight}px`
1303
+ );
1271
1304
  } else {
1272
1305
  document.body.style.paddingTop = `${basePaddingTop + bannerHeight}px`;
1306
+ document.documentElement.style.setProperty(
1307
+ "--sitepulse-top-banner-height",
1308
+ `${bannerHeight}px`
1309
+ );
1310
+ document.documentElement.classList.add("has-sitepulse-top-banner");
1311
+ const fixedHeaders = findTopFixedElements();
1312
+ for (const el of fixedHeaders) {
1313
+ if (!shiftedElements.some((r) => r.el === el)) {
1314
+ shiftedElements.push({
1315
+ el,
1316
+ originalTop: el.style.top,
1317
+ originalTransform: el.style.transform,
1318
+ originalTransition: el.style.transition
1319
+ });
1320
+ el.style.transition = el.style.transition ? `${el.style.transition}, transform 0.2s ease` : "transform 0.2s ease";
1321
+ el.style.transform = `translateY(${bannerHeight}px)`;
1322
+ }
1323
+ }
1273
1324
  }
1274
1325
  }
1275
1326
  };
@@ -1302,6 +1353,23 @@ function renderCampaignDOM(campaign, handlers = {}) {
1302
1353
  if (originalPaddingBottom !== null) {
1303
1354
  document.body.style.paddingBottom = originalPaddingBottom;
1304
1355
  }
1356
+ document.documentElement.style.setProperty(
1357
+ "--sitepulse-top-banner-height",
1358
+ "0px"
1359
+ );
1360
+ document.documentElement.style.setProperty(
1361
+ "--sitepulse-bottom-banner-height",
1362
+ "0px"
1363
+ );
1364
+ document.documentElement.classList.remove("has-sitepulse-top-banner");
1365
+ for (const record of shiftedElements) {
1366
+ if (record.el && record.el.isConnected) {
1367
+ record.el.style.transform = record.originalTransform;
1368
+ record.el.style.transition = record.originalTransition;
1369
+ record.el.style.top = record.originalTop;
1370
+ }
1371
+ }
1372
+ shiftedElements.length = 0;
1305
1373
  } catch {
1306
1374
  }
1307
1375
  }
package/dist/index.mjs CHANGED
@@ -1202,6 +1202,7 @@ function renderCampaignDOM(campaign, handlers = {}) {
1202
1202
  let originalPaddingTop = null;
1203
1203
  let originalPaddingBottom = null;
1204
1204
  let resizeObserver = null;
1205
+ const shiftedElements = [];
1205
1206
  if (isBanner && typeof document !== "undefined" && document.body) {
1206
1207
  try {
1207
1208
  const isBottom = design.position === "bottom";
@@ -1223,14 +1224,64 @@ function renderCampaignDOM(campaign, handlers = {}) {
1223
1224
  }
1224
1225
  } catch {
1225
1226
  }
1227
+ const findTopFixedElements = () => {
1228
+ const candidates = [];
1229
+ try {
1230
+ const elements = Array.from(
1231
+ document.querySelectorAll(
1232
+ 'header, nav, [role="banner"], [class*="header"], [class*="navbar"], [class*="nav-fixed"], [class*="sticky"]'
1233
+ )
1234
+ );
1235
+ Array.from(document.body.children).forEach((child) => {
1236
+ if (child instanceof HTMLElement && child !== wrapper && child !== overlayEl && !elements.includes(child)) {
1237
+ elements.push(child);
1238
+ }
1239
+ });
1240
+ for (const el of elements) {
1241
+ if (el === wrapper || el === overlayEl || !el.isConnected) continue;
1242
+ const style = window.getComputedStyle(el);
1243
+ const pos = style.position;
1244
+ if (pos === "fixed" || pos === "sticky") {
1245
+ const rect = el.getBoundingClientRect();
1246
+ if (rect.top <= 15 && rect.height > 0 && rect.height < window.innerHeight * 0.5) {
1247
+ candidates.push(el);
1248
+ }
1249
+ }
1250
+ }
1251
+ } catch {
1252
+ }
1253
+ return candidates;
1254
+ };
1226
1255
  const updateOffset = () => {
1227
1256
  if (!wrapper || !document.body) return;
1228
1257
  const bannerHeight = wrapper.offsetHeight;
1229
1258
  if (bannerHeight > 0) {
1230
1259
  if (isBottom) {
1231
1260
  document.body.style.paddingBottom = `${basePaddingBottom + bannerHeight}px`;
1261
+ document.documentElement.style.setProperty(
1262
+ "--sitepulse-bottom-banner-height",
1263
+ `${bannerHeight}px`
1264
+ );
1232
1265
  } else {
1233
1266
  document.body.style.paddingTop = `${basePaddingTop + bannerHeight}px`;
1267
+ document.documentElement.style.setProperty(
1268
+ "--sitepulse-top-banner-height",
1269
+ `${bannerHeight}px`
1270
+ );
1271
+ document.documentElement.classList.add("has-sitepulse-top-banner");
1272
+ const fixedHeaders = findTopFixedElements();
1273
+ for (const el of fixedHeaders) {
1274
+ if (!shiftedElements.some((r) => r.el === el)) {
1275
+ shiftedElements.push({
1276
+ el,
1277
+ originalTop: el.style.top,
1278
+ originalTransform: el.style.transform,
1279
+ originalTransition: el.style.transition
1280
+ });
1281
+ el.style.transition = el.style.transition ? `${el.style.transition}, transform 0.2s ease` : "transform 0.2s ease";
1282
+ el.style.transform = `translateY(${bannerHeight}px)`;
1283
+ }
1284
+ }
1234
1285
  }
1235
1286
  }
1236
1287
  };
@@ -1263,6 +1314,23 @@ function renderCampaignDOM(campaign, handlers = {}) {
1263
1314
  if (originalPaddingBottom !== null) {
1264
1315
  document.body.style.paddingBottom = originalPaddingBottom;
1265
1316
  }
1317
+ document.documentElement.style.setProperty(
1318
+ "--sitepulse-top-banner-height",
1319
+ "0px"
1320
+ );
1321
+ document.documentElement.style.setProperty(
1322
+ "--sitepulse-bottom-banner-height",
1323
+ "0px"
1324
+ );
1325
+ document.documentElement.classList.remove("has-sitepulse-top-banner");
1326
+ for (const record of shiftedElements) {
1327
+ if (record.el && record.el.isConnected) {
1328
+ record.el.style.transform = record.originalTransform;
1329
+ record.el.style.transition = record.originalTransition;
1330
+ record.el.style.top = record.originalTop;
1331
+ }
1332
+ }
1333
+ shiftedElements.length = 0;
1266
1334
  } catch {
1267
1335
  }
1268
1336
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@sitepulse/web",
3
- "version": "1.0.1",
3
+ "version": "1.0.2",
4
4
  "description": "Official SitePulse Web SDK for telemetry, visitor analytics, and on-site engagement",
5
5
  "main": "dist/index.js",
6
6
  "module": "dist/index.mjs",