@builder.io/sdk-qwik 0.12.6 → 0.12.7

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.
@@ -313,6 +313,201 @@ function getProcessedBlock({ block, context, shouldEvaluateBindings, localState,
313
313
  else
314
314
  return transformedBlock;
315
315
  }
316
+ function throttle(func, wait, options = {}) {
317
+ let context;
318
+ let args;
319
+ let result;
320
+ let timeout = null;
321
+ let previous = 0;
322
+ const later = function() {
323
+ previous = options.leading === false ? 0 : Date.now();
324
+ timeout = null;
325
+ result = func.apply(context, args);
326
+ if (!timeout)
327
+ context = args = null;
328
+ };
329
+ return function() {
330
+ const now = Date.now();
331
+ if (!previous && options.leading === false)
332
+ previous = now;
333
+ const remaining = wait - (now - previous);
334
+ context = this;
335
+ args = arguments;
336
+ if (remaining <= 0 || remaining > wait) {
337
+ if (timeout) {
338
+ clearTimeout(timeout);
339
+ timeout = null;
340
+ }
341
+ previous = now;
342
+ result = func.apply(context, args);
343
+ if (!timeout)
344
+ context = args = null;
345
+ } else if (!timeout && options.trailing !== false)
346
+ timeout = setTimeout(later, remaining);
347
+ return result;
348
+ };
349
+ }
350
+ function assign(target, ..._args) {
351
+ const to = Object(target);
352
+ for (let index = 1; index < arguments.length; index++) {
353
+ const nextSource = arguments[index];
354
+ if (nextSource != null) {
355
+ for (const nextKey in nextSource)
356
+ if (Object.prototype.hasOwnProperty.call(nextSource, nextKey))
357
+ to[nextKey] = nextSource[nextKey];
358
+ }
359
+ }
360
+ return to;
361
+ }
362
+ const camelCaseToKebabCase = (str) => str ? str.replace(/([A-Z])/g, (g) => `-${g[0].toLowerCase()}`) : "";
363
+ function bindAnimations(animations) {
364
+ for (const animation of animations)
365
+ switch (animation.trigger) {
366
+ case "pageLoad":
367
+ triggerAnimation(animation);
368
+ break;
369
+ case "hover":
370
+ bindHoverAnimation(animation);
371
+ break;
372
+ case "scrollInView":
373
+ bindScrollInViewAnimation(animation);
374
+ break;
375
+ }
376
+ }
377
+ function warnElementNotPresent(id) {
378
+ console.warn(`Cannot animate element: element with ID ${id} not found!`);
379
+ }
380
+ function augmentAnimation(animation, element) {
381
+ const stylesUsed = getAllStylesUsed(animation);
382
+ const computedStyle = getComputedStyle(element);
383
+ const firstStyles = animation.steps[0].styles;
384
+ const lastStyles = animation.steps[animation.steps.length - 1].styles;
385
+ const bothStyles = [
386
+ firstStyles,
387
+ lastStyles
388
+ ];
389
+ for (const styles of bothStyles) {
390
+ for (const style of stylesUsed)
391
+ if (!(style in styles))
392
+ styles[style] = computedStyle[style];
393
+ }
394
+ }
395
+ function getAllStylesUsed(animation) {
396
+ const properties = [];
397
+ for (const step of animation.steps) {
398
+ for (const key in step.styles)
399
+ if (properties.indexOf(key) === -1)
400
+ properties.push(key);
401
+ }
402
+ return properties;
403
+ }
404
+ function triggerAnimation(animation) {
405
+ const elements = Array.prototype.slice.call(document.getElementsByClassName(animation.elementId || animation.id || ""));
406
+ if (!elements.length) {
407
+ warnElementNotPresent(animation.elementId || animation.id || "");
408
+ return;
409
+ }
410
+ Array.from(elements).forEach((element) => {
411
+ augmentAnimation(animation, element);
412
+ element.style.transition = "none";
413
+ element.style.transitionDelay = "0";
414
+ assign(element.style, animation.steps[0].styles);
415
+ setTimeout(() => {
416
+ element.style.transition = `all ${animation.duration}s ${camelCaseToKebabCase(animation.easing)}`;
417
+ if (animation.delay)
418
+ element.style.transitionDelay = animation.delay + "s";
419
+ assign(element.style, animation.steps[1].styles);
420
+ setTimeout(() => {
421
+ element.style.transition = "";
422
+ element.style.transitionDelay = "";
423
+ }, (animation.delay || 0) * 1e3 + animation.duration * 1e3 + 100);
424
+ });
425
+ });
426
+ }
427
+ function bindHoverAnimation(animation) {
428
+ const elements = Array.prototype.slice.call(document.getElementsByClassName(animation.elementId || animation.id || ""));
429
+ if (!elements.length) {
430
+ warnElementNotPresent(animation.elementId || animation.id || "");
431
+ return;
432
+ }
433
+ Array.from(elements).forEach((element) => {
434
+ augmentAnimation(animation, element);
435
+ const defaultState = animation.steps[0].styles;
436
+ const hoverState = animation.steps[1].styles;
437
+ function attachDefaultState() {
438
+ assign(element.style, defaultState);
439
+ }
440
+ function attachHoverState() {
441
+ assign(element.style, hoverState);
442
+ }
443
+ attachDefaultState();
444
+ element.addEventListener("mouseenter", attachHoverState);
445
+ element.addEventListener("mouseleave", attachDefaultState);
446
+ setTimeout(() => {
447
+ element.style.transition = `all ${animation.duration}s ${camelCaseToKebabCase(animation.easing)}`;
448
+ if (animation.delay)
449
+ element.style.transitionDelay = animation.delay + "s";
450
+ });
451
+ });
452
+ }
453
+ function bindScrollInViewAnimation(animation) {
454
+ const elements = Array.prototype.slice.call(document.getElementsByClassName(animation.elementId || animation.id || ""));
455
+ if (!elements.length) {
456
+ warnElementNotPresent(animation.elementId || animation.id || "");
457
+ return;
458
+ }
459
+ Array.from(elements).forEach((element) => {
460
+ augmentAnimation(animation, element);
461
+ let triggered = false;
462
+ let pendingAnimation = false;
463
+ function immediateOnScroll() {
464
+ if (!triggered && isScrolledIntoView(element)) {
465
+ triggered = true;
466
+ pendingAnimation = true;
467
+ setTimeout(() => {
468
+ assign(element.style, animation.steps[1].styles);
469
+ if (!animation.repeat)
470
+ document.removeEventListener("scroll", onScroll);
471
+ setTimeout(() => {
472
+ pendingAnimation = false;
473
+ if (!animation.repeat) {
474
+ element.style.transition = "";
475
+ element.style.transitionDelay = "";
476
+ }
477
+ }, (animation.duration + (animation.delay || 0)) * 1e3 + 100);
478
+ });
479
+ } else if (animation.repeat && triggered && !pendingAnimation && !isScrolledIntoView(element)) {
480
+ triggered = false;
481
+ assign(element.style, animation.steps[0].styles);
482
+ }
483
+ }
484
+ const onScroll = throttle(immediateOnScroll, 200, {
485
+ leading: false
486
+ });
487
+ function isScrolledIntoView(elem) {
488
+ const rect = elem.getBoundingClientRect();
489
+ const windowHeight = window.innerHeight;
490
+ const thresholdPercent = (animation.thresholdPercent || 0) / 100;
491
+ const threshold = thresholdPercent * windowHeight;
492
+ return rect.bottom > threshold && rect.top < windowHeight - threshold;
493
+ }
494
+ const defaultState = animation.steps[0].styles;
495
+ function attachDefaultState() {
496
+ assign(element.style, defaultState);
497
+ }
498
+ attachDefaultState();
499
+ setTimeout(() => {
500
+ element.style.transition = `all ${animation.duration}s ${camelCaseToKebabCase(animation.easing)}`;
501
+ if (animation.delay)
502
+ element.style.transitionDelay = animation.delay + "s";
503
+ });
504
+ document.addEventListener("scroll", onScroll, {
505
+ capture: true,
506
+ passive: true
507
+ });
508
+ immediateOnScroll();
509
+ });
510
+ }
316
511
  const getComponent = ({ block, context, registeredComponents }) => {
317
512
  var _a;
318
513
  const componentName = (_a = getProcessedBlock({
@@ -859,6 +1054,18 @@ const Block = /* @__PURE__ */ qwik.componentQrl(/* @__PURE__ */ qwik.inlinedQrl(
859
1054
  props,
860
1055
  state
861
1056
  ]));
1057
+ qwik.useVisibleTaskQrl(/* @__PURE__ */ qwik.inlinedQrl(() => {
1058
+ const [processedBlock2] = qwik.useLexicalScope();
1059
+ const blockId = processedBlock2.value.id;
1060
+ const animations = processedBlock2.value.animations;
1061
+ if (animations && blockId)
1062
+ bindAnimations(animations.filter((item) => item.trigger !== "hover").map((animation) => ({
1063
+ ...animation,
1064
+ elementId: blockId
1065
+ })));
1066
+ }, "Block_component_useVisibleTask_hrTYvqw0Tbs", [
1067
+ processedBlock
1068
+ ]));
862
1069
  return /* @__PURE__ */ qwik._jsxC(jsxRuntime.Fragment, {
863
1070
  children: canShowBlock.value ? /* @__PURE__ */ qwik._jsxC(jsxRuntime.Fragment, {
864
1071
  children: [
@@ -3355,7 +3562,7 @@ const getInteractionPropertiesForEvent = (event) => {
3355
3562
  }
3356
3563
  };
3357
3564
  };
3358
- const SDK_VERSION = "0.12.6";
3565
+ const SDK_VERSION = "0.12.7";
3359
3566
  const registry = {};
3360
3567
  function register(type, info) {
3361
3568
  let typeList = registry[type];
@@ -3540,6 +3747,9 @@ const processMessage = function processMessage2(props, state, elementRef, event)
3540
3747
  state.forceReRenderCount = state.forceReRenderCount + 1;
3541
3748
  break;
3542
3749
  }
3750
+ case "builder.triggerAnimation":
3751
+ triggerAnimation(data.data);
3752
+ break;
3543
3753
  case "builder.contentUpdate": {
3544
3754
  const messageContent = data.data;
3545
3755
  const key = messageContent.key || messageContent.alias || messageContent.entry || messageContent.modelName;
@@ -1,4 +1,4 @@
1
- import { componentQrl, inlinedQrl, _jsxBranch, _jsxC, Slot as Slot$1, _fnSignal, _IMMUTABLE, createContextId, _jsxQ, useComputedQrl, useLexicalScope, useStore, useContextProvider, _wrapProp, useStylesScopedQrl, useContext, Fragment as Fragment$1, _jsxS, useSignal, useOn, useTaskQrl, createElement } from "@builder.io/qwik";
1
+ import { componentQrl, inlinedQrl, _jsxBranch, _jsxC, Slot as Slot$1, _fnSignal, _IMMUTABLE, createContextId, _jsxQ, useComputedQrl, useLexicalScope, useStore, useContextProvider, useVisibleTaskQrl, _wrapProp, useStylesScopedQrl, useContext, Fragment as Fragment$1, _jsxS, useSignal, useOn, useTaskQrl, createElement } from "@builder.io/qwik";
2
2
  import { Fragment } from "@builder.io/qwik/jsx-runtime";
3
3
  import { isBrowser as isBrowser$1 } from "@builder.io/qwik/build";
4
4
  const EMPTY_HTML_ELEMENTS = /* @__PURE__ */ new Set([
@@ -311,6 +311,201 @@ function getProcessedBlock({ block, context, shouldEvaluateBindings, localState,
311
311
  else
312
312
  return transformedBlock;
313
313
  }
314
+ function throttle(func, wait, options = {}) {
315
+ let context;
316
+ let args;
317
+ let result;
318
+ let timeout = null;
319
+ let previous = 0;
320
+ const later = function() {
321
+ previous = options.leading === false ? 0 : Date.now();
322
+ timeout = null;
323
+ result = func.apply(context, args);
324
+ if (!timeout)
325
+ context = args = null;
326
+ };
327
+ return function() {
328
+ const now = Date.now();
329
+ if (!previous && options.leading === false)
330
+ previous = now;
331
+ const remaining = wait - (now - previous);
332
+ context = this;
333
+ args = arguments;
334
+ if (remaining <= 0 || remaining > wait) {
335
+ if (timeout) {
336
+ clearTimeout(timeout);
337
+ timeout = null;
338
+ }
339
+ previous = now;
340
+ result = func.apply(context, args);
341
+ if (!timeout)
342
+ context = args = null;
343
+ } else if (!timeout && options.trailing !== false)
344
+ timeout = setTimeout(later, remaining);
345
+ return result;
346
+ };
347
+ }
348
+ function assign(target, ..._args) {
349
+ const to = Object(target);
350
+ for (let index = 1; index < arguments.length; index++) {
351
+ const nextSource = arguments[index];
352
+ if (nextSource != null) {
353
+ for (const nextKey in nextSource)
354
+ if (Object.prototype.hasOwnProperty.call(nextSource, nextKey))
355
+ to[nextKey] = nextSource[nextKey];
356
+ }
357
+ }
358
+ return to;
359
+ }
360
+ const camelCaseToKebabCase = (str) => str ? str.replace(/([A-Z])/g, (g) => `-${g[0].toLowerCase()}`) : "";
361
+ function bindAnimations(animations) {
362
+ for (const animation of animations)
363
+ switch (animation.trigger) {
364
+ case "pageLoad":
365
+ triggerAnimation(animation);
366
+ break;
367
+ case "hover":
368
+ bindHoverAnimation(animation);
369
+ break;
370
+ case "scrollInView":
371
+ bindScrollInViewAnimation(animation);
372
+ break;
373
+ }
374
+ }
375
+ function warnElementNotPresent(id) {
376
+ console.warn(`Cannot animate element: element with ID ${id} not found!`);
377
+ }
378
+ function augmentAnimation(animation, element) {
379
+ const stylesUsed = getAllStylesUsed(animation);
380
+ const computedStyle = getComputedStyle(element);
381
+ const firstStyles = animation.steps[0].styles;
382
+ const lastStyles = animation.steps[animation.steps.length - 1].styles;
383
+ const bothStyles = [
384
+ firstStyles,
385
+ lastStyles
386
+ ];
387
+ for (const styles of bothStyles) {
388
+ for (const style of stylesUsed)
389
+ if (!(style in styles))
390
+ styles[style] = computedStyle[style];
391
+ }
392
+ }
393
+ function getAllStylesUsed(animation) {
394
+ const properties = [];
395
+ for (const step of animation.steps) {
396
+ for (const key in step.styles)
397
+ if (properties.indexOf(key) === -1)
398
+ properties.push(key);
399
+ }
400
+ return properties;
401
+ }
402
+ function triggerAnimation(animation) {
403
+ const elements = Array.prototype.slice.call(document.getElementsByClassName(animation.elementId || animation.id || ""));
404
+ if (!elements.length) {
405
+ warnElementNotPresent(animation.elementId || animation.id || "");
406
+ return;
407
+ }
408
+ Array.from(elements).forEach((element) => {
409
+ augmentAnimation(animation, element);
410
+ element.style.transition = "none";
411
+ element.style.transitionDelay = "0";
412
+ assign(element.style, animation.steps[0].styles);
413
+ setTimeout(() => {
414
+ element.style.transition = `all ${animation.duration}s ${camelCaseToKebabCase(animation.easing)}`;
415
+ if (animation.delay)
416
+ element.style.transitionDelay = animation.delay + "s";
417
+ assign(element.style, animation.steps[1].styles);
418
+ setTimeout(() => {
419
+ element.style.transition = "";
420
+ element.style.transitionDelay = "";
421
+ }, (animation.delay || 0) * 1e3 + animation.duration * 1e3 + 100);
422
+ });
423
+ });
424
+ }
425
+ function bindHoverAnimation(animation) {
426
+ const elements = Array.prototype.slice.call(document.getElementsByClassName(animation.elementId || animation.id || ""));
427
+ if (!elements.length) {
428
+ warnElementNotPresent(animation.elementId || animation.id || "");
429
+ return;
430
+ }
431
+ Array.from(elements).forEach((element) => {
432
+ augmentAnimation(animation, element);
433
+ const defaultState = animation.steps[0].styles;
434
+ const hoverState = animation.steps[1].styles;
435
+ function attachDefaultState() {
436
+ assign(element.style, defaultState);
437
+ }
438
+ function attachHoverState() {
439
+ assign(element.style, hoverState);
440
+ }
441
+ attachDefaultState();
442
+ element.addEventListener("mouseenter", attachHoverState);
443
+ element.addEventListener("mouseleave", attachDefaultState);
444
+ setTimeout(() => {
445
+ element.style.transition = `all ${animation.duration}s ${camelCaseToKebabCase(animation.easing)}`;
446
+ if (animation.delay)
447
+ element.style.transitionDelay = animation.delay + "s";
448
+ });
449
+ });
450
+ }
451
+ function bindScrollInViewAnimation(animation) {
452
+ const elements = Array.prototype.slice.call(document.getElementsByClassName(animation.elementId || animation.id || ""));
453
+ if (!elements.length) {
454
+ warnElementNotPresent(animation.elementId || animation.id || "");
455
+ return;
456
+ }
457
+ Array.from(elements).forEach((element) => {
458
+ augmentAnimation(animation, element);
459
+ let triggered = false;
460
+ let pendingAnimation = false;
461
+ function immediateOnScroll() {
462
+ if (!triggered && isScrolledIntoView(element)) {
463
+ triggered = true;
464
+ pendingAnimation = true;
465
+ setTimeout(() => {
466
+ assign(element.style, animation.steps[1].styles);
467
+ if (!animation.repeat)
468
+ document.removeEventListener("scroll", onScroll);
469
+ setTimeout(() => {
470
+ pendingAnimation = false;
471
+ if (!animation.repeat) {
472
+ element.style.transition = "";
473
+ element.style.transitionDelay = "";
474
+ }
475
+ }, (animation.duration + (animation.delay || 0)) * 1e3 + 100);
476
+ });
477
+ } else if (animation.repeat && triggered && !pendingAnimation && !isScrolledIntoView(element)) {
478
+ triggered = false;
479
+ assign(element.style, animation.steps[0].styles);
480
+ }
481
+ }
482
+ const onScroll = throttle(immediateOnScroll, 200, {
483
+ leading: false
484
+ });
485
+ function isScrolledIntoView(elem) {
486
+ const rect = elem.getBoundingClientRect();
487
+ const windowHeight = window.innerHeight;
488
+ const thresholdPercent = (animation.thresholdPercent || 0) / 100;
489
+ const threshold = thresholdPercent * windowHeight;
490
+ return rect.bottom > threshold && rect.top < windowHeight - threshold;
491
+ }
492
+ const defaultState = animation.steps[0].styles;
493
+ function attachDefaultState() {
494
+ assign(element.style, defaultState);
495
+ }
496
+ attachDefaultState();
497
+ setTimeout(() => {
498
+ element.style.transition = `all ${animation.duration}s ${camelCaseToKebabCase(animation.easing)}`;
499
+ if (animation.delay)
500
+ element.style.transitionDelay = animation.delay + "s";
501
+ });
502
+ document.addEventListener("scroll", onScroll, {
503
+ capture: true,
504
+ passive: true
505
+ });
506
+ immediateOnScroll();
507
+ });
508
+ }
314
509
  const getComponent = ({ block, context, registeredComponents }) => {
315
510
  var _a;
316
511
  const componentName = (_a = getProcessedBlock({
@@ -857,6 +1052,18 @@ const Block = /* @__PURE__ */ componentQrl(/* @__PURE__ */ inlinedQrl((props) =>
857
1052
  props,
858
1053
  state
859
1054
  ]));
1055
+ useVisibleTaskQrl(/* @__PURE__ */ inlinedQrl(() => {
1056
+ const [processedBlock2] = useLexicalScope();
1057
+ const blockId = processedBlock2.value.id;
1058
+ const animations = processedBlock2.value.animations;
1059
+ if (animations && blockId)
1060
+ bindAnimations(animations.filter((item) => item.trigger !== "hover").map((animation) => ({
1061
+ ...animation,
1062
+ elementId: blockId
1063
+ })));
1064
+ }, "Block_component_useVisibleTask_hrTYvqw0Tbs", [
1065
+ processedBlock
1066
+ ]));
860
1067
  return /* @__PURE__ */ _jsxC(Fragment, {
861
1068
  children: canShowBlock.value ? /* @__PURE__ */ _jsxC(Fragment, {
862
1069
  children: [
@@ -3353,7 +3560,7 @@ const getInteractionPropertiesForEvent = (event) => {
3353
3560
  }
3354
3561
  };
3355
3562
  };
3356
- const SDK_VERSION = "0.12.6";
3563
+ const SDK_VERSION = "0.12.7";
3357
3564
  const registry = {};
3358
3565
  function register(type, info) {
3359
3566
  let typeList = registry[type];
@@ -3538,6 +3745,9 @@ const processMessage = function processMessage2(props, state, elementRef, event)
3538
3745
  state.forceReRenderCount = state.forceReRenderCount + 1;
3539
3746
  break;
3540
3747
  }
3748
+ case "builder.triggerAnimation":
3749
+ triggerAnimation(data.data);
3750
+ break;
3541
3751
  case "builder.contentUpdate": {
3542
3752
  const messageContent = data.data;
3543
3753
  const key = messageContent.key || messageContent.alias || messageContent.entry || messageContent.modelName;