@brandocms/jupiter 3.53.0 → 3.54.0

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/package.json CHANGED
@@ -1,46 +1,46 @@
1
1
  {
2
- "name": "@brandocms/jupiter",
3
- "version": "3.53.0",
4
- "description": "Frontend helpers.",
5
- "author": "Univers/Twined",
6
- "license": "UNLICENSED",
7
- "repository": {
8
- "type": "git",
9
- "url": "git+https://brandocms@github.com/brandocms/jupiter.git"
10
- },
11
- "bugs": {
12
- "url": "https://github.com/brandocms/jupiter/issues"
13
- },
14
- "main": "src/index.js",
15
- "module": "src/index.js",
16
- "browser": "src/index.js",
17
- "files": [
18
- "src"
19
- ],
20
- "homepage": "https://github.com/brandocms/jupiter#readme",
21
- "sideEffects": false,
22
- "scripts": {
23
- "test": "jest __tests__ --passWithNoTests",
24
- "coverage": "jest __tests__ --coverage"
25
- },
26
- "jest": {
27
- "testEnvironment": "jsdom",
28
- "transformIgnorePatterns": [
29
- "/node_modules/(?!gsap).+\\.js$"
30
- ]
31
- },
32
- "dependencies": {
33
- "@egjs/hammerjs": "^2.0.17",
34
- "body-scroll-lock": "^4.0.0-beta.0",
35
- "gsap": "3.12.5",
36
- "lodash.defaultsdeep": "^4.6.1"
37
- },
38
- "devDependencies": {
39
- "@babel/core": "^7.25.2",
40
- "@babel/preset-env": "^7.25.3",
41
- "babel-jest": "^29.7.0",
42
- "jest": "^29.7.0",
43
- "jest-environment-jsdom": "^29.7.0"
44
- },
45
- "packageManager": "yarn@1.22.22+sha512.a6b2f7906b721bba3d67d4aff083df04dad64c399707841b7acf00f6b133b7ac24255f2652fa22ae3534329dc6180534e98d17432037ff6fd140556e2bb3137e"
2
+ "name": "@brandocms/jupiter",
3
+ "version": "3.54.0",
4
+ "description": "Frontend helpers.",
5
+ "author": "Univers/Twined",
6
+ "license": "UNLICENSED",
7
+ "repository": {
8
+ "type": "git",
9
+ "url": "git+https://brandocms@github.com/brandocms/jupiter.git"
10
+ },
11
+ "bugs": {
12
+ "url": "https://github.com/brandocms/jupiter/issues"
13
+ },
14
+ "main": "src/index.js",
15
+ "module": "src/index.js",
16
+ "browser": "src/index.js",
17
+ "files": [
18
+ "src"
19
+ ],
20
+ "homepage": "https://github.com/brandocms/jupiter#readme",
21
+ "sideEffects": false,
22
+ "scripts": {
23
+ "test": "jest __tests__ --passWithNoTests",
24
+ "coverage": "jest __tests__ --coverage"
25
+ },
26
+ "jest": {
27
+ "testEnvironment": "jsdom",
28
+ "transformIgnorePatterns": [
29
+ "/node_modules/(?!gsap).+\\.js$"
30
+ ]
31
+ },
32
+ "dependencies": {
33
+ "@egjs/hammerjs": "^2.0.17",
34
+ "body-scroll-lock": "^4.0.0-beta.0",
35
+ "gsap": "3.12.5",
36
+ "lodash.defaultsdeep": "^4.6.1"
37
+ },
38
+ "devDependencies": {
39
+ "@babel/core": "^7.25.2",
40
+ "@babel/preset-env": "^7.25.3",
41
+ "babel-jest": "^29.7.0",
42
+ "jest": "^29.7.0",
43
+ "jest-environment-jsdom": "^29.7.0"
44
+ },
45
+ "packageManager": "yarn@1.22.22+sha512.a6b2f7906b721bba3d67d4aff083df04dad64c399707841b7acf00f6b133b7ac24255f2652fa22ae3534329dc6180534e98d17432037ff6fd140556e2bb3137e"
46
46
  }
@@ -87,14 +87,14 @@ const DEFAULT_OPTIONS = {
87
87
  /* The transitions that will be tweened */
88
88
  transition: {
89
89
  from: {
90
- opacity: 0
90
+ opacity: 0,
91
91
  },
92
92
  to: {
93
- opacity: 1
94
- }
95
- }
96
- }
97
- }
93
+ opacity: 1,
94
+ },
95
+ },
96
+ },
97
+ },
98
98
  }
99
99
 
100
100
  export default class Moonwalk {
@@ -111,13 +111,13 @@ export default class Moonwalk {
111
111
  if (this.opts.clearNestedSections) {
112
112
  container
113
113
  .querySelectorAll('[data-moonwalk-section] [data-moonwalk-section]')
114
- .forEach(ms => ms.removeAttribute('data-moonwalk-section'))
114
+ .forEach((ms) => ms.removeAttribute('data-moonwalk-section'))
115
115
  }
116
116
 
117
117
  if (this.opts.clearNestedWalks) {
118
118
  container
119
119
  .querySelectorAll('[data-moonwalk] [data-moonwalk]')
120
- .forEach(ms => ms.removeAttribute('data-moonwalk'))
120
+ .forEach((ms) => ms.removeAttribute('data-moonwalk'))
121
121
  }
122
122
 
123
123
  if (this.opts.clearMoonwalkOnAnchors) {
@@ -162,7 +162,7 @@ export default class Moonwalk {
162
162
 
163
163
  // Get all elements with the 'data-moonwalk' attribute
164
164
  const moonwalkElements = document.querySelectorAll('[data-moonwalk]')
165
- moonwalkElements.forEach(el => {
165
+ moonwalkElements.forEach((el) => {
166
166
  const position = el.compareDocumentPosition(targetElement)
167
167
  // Check if 'el' comes before 'targetElement' or is the same element
168
168
  if (position & Node.DOCUMENT_POSITION_FOLLOWING || el === targetElement) {
@@ -172,8 +172,10 @@ export default class Moonwalk {
172
172
  })
173
173
 
174
174
  // Get all elements with the 'data-moonwalk-section' attribute
175
- const moonwalkSectionElements = document.querySelectorAll('[data-moonwalk-section]')
176
- moonwalkSectionElements.forEach(el => {
175
+ const moonwalkSectionElements = document.querySelectorAll(
176
+ '[data-moonwalk-section]'
177
+ )
178
+ moonwalkSectionElements.forEach((el) => {
177
179
  const position = el.compareDocumentPosition(targetElement)
178
180
  // Check if 'el' comes before 'targetElement' or is the same element
179
181
  if (position & Node.DOCUMENT_POSITION_FOLLOWING || el === targetElement) {
@@ -186,19 +188,27 @@ export default class Moonwalk {
186
188
  * Remove all moonwalks. Useful for clients who prefer reduced motion
187
189
  */
188
190
  removeAllWalks(container = document.body, beforeEl = nil) {
189
- const keys = ['data-moonwalk', 'data-moonwalk-section', 'data-moonwalk-children']
190
- keys.forEach(key => {
191
+ const keys = [
192
+ 'data-moonwalk',
193
+ 'data-moonwalk-section',
194
+ 'data-moonwalk-children',
195
+ ]
196
+ keys.forEach((key) => {
191
197
  const elems = container.querySelectorAll(`[${key}]`)
192
- Array.from(elems).forEach(el => el.removeAttribute(key))
198
+ Array.from(elems).forEach((el) => el.removeAttribute(key))
193
199
  container.removeAttribute(key)
194
200
  })
195
201
  }
196
202
 
197
203
  removeFor(container = document.body, selector) {
198
- const keys = ['data-moonwalk', 'data-moonwalk-section', 'data-moonwalk-children']
199
- keys.forEach(key => {
204
+ const keys = [
205
+ 'data-moonwalk',
206
+ 'data-moonwalk-section',
207
+ 'data-moonwalk-children',
208
+ ]
209
+ keys.forEach((key) => {
200
210
  const elems = container.querySelectorAll(`${selector}[${key}]`)
201
- Array.from(elems).forEach(el => el.removeAttribute(key))
211
+ Array.from(elems).forEach((el) => el.removeAttribute(key))
202
212
  })
203
213
  }
204
214
 
@@ -208,7 +218,7 @@ export default class Moonwalk {
208
218
  removeRun(container = document.body, name) {
209
219
  const key = 'data-moonwalk-run'
210
220
  const elems = container.querySelectorAll(`[${key}="${name}"]`)
211
- Array.from(elems).forEach(el => el.removeAttribute(key))
221
+ Array.from(elems).forEach((el) => el.removeAttribute(key))
212
222
  }
213
223
 
214
224
  /**
@@ -217,7 +227,7 @@ export default class Moonwalk {
217
227
  removeRuns(container = document.body) {
218
228
  const key = 'data-moonwalk-run'
219
229
  const elems = container.querySelectorAll(`[${key}]`)
220
- Array.from(elems).forEach(el => el.removeAttribute(key))
230
+ Array.from(elems).forEach((el) => el.removeAttribute(key))
221
231
  }
222
232
 
223
233
  /**
@@ -226,8 +236,11 @@ export default class Moonwalk {
226
236
  * @param {*} section
227
237
  */
228
238
  addIds(section) {
229
- Array.from(section.querySelectorAll('[data-moonwalk]')).forEach(el => {
230
- el.setAttribute('data-moonwalk-id', Math.random().toString(36).substring(7))
239
+ Array.from(section.querySelectorAll('[data-moonwalk]')).forEach((el) => {
240
+ el.setAttribute(
241
+ 'data-moonwalk-id',
242
+ Math.random().toString(36).substring(7)
243
+ )
231
244
  })
232
245
  }
233
246
 
@@ -237,8 +250,9 @@ export default class Moonwalk {
237
250
  * @param {*} section
238
251
  */
239
252
  addIndexes(section) {
240
- Object.keys(this.opts.walks).forEach(key => {
241
- const searchAttr = key === 'default' ? '[data-moonwalk=""]' : `[data-moonwalk="${key}"]`
253
+ Object.keys(this.opts.walks).forEach((key) => {
254
+ const searchAttr =
255
+ key === 'default' ? '[data-moonwalk=""]' : `[data-moonwalk="${key}"]`
242
256
  const elements = section.querySelectorAll(searchAttr)
243
257
 
244
258
  Array.from(elements).forEach((element, index) => {
@@ -253,7 +267,7 @@ export default class Moonwalk {
253
267
  */
254
268
  initializeRuns(container = document.body) {
255
269
  const runs = container.querySelectorAll('[data-moonwalk-run]')
256
- return Array.from(runs).map(run => {
270
+ return Array.from(runs).map((run) => {
257
271
  const foundRun = this.opts.runs[run.getAttribute('data-moonwalk-run')]
258
272
  if (foundRun) {
259
273
  if (foundRun.initialize) {
@@ -266,7 +280,7 @@ export default class Moonwalk {
266
280
  callback: foundRun.callback,
267
281
  onExit: foundRun.onExit,
268
282
  repeated: foundRun.repeated,
269
- rootMargin: foundRun.rootMargin
283
+ rootMargin: foundRun.rootMargin,
270
284
  }
271
285
  }
272
286
 
@@ -289,7 +303,9 @@ export default class Moonwalk {
289
303
  return [this.initializeSection(container)]
290
304
  }
291
305
 
292
- return Array.from(sections).map(section => this.initializeSection(section))
306
+ return Array.from(sections).map((section) =>
307
+ this.initializeSection(section)
308
+ )
293
309
  }
294
310
 
295
311
  initializeSection(section) {
@@ -305,7 +321,7 @@ export default class Moonwalk {
305
321
 
306
322
  const timeline = gsap.timeline({
307
323
  autoRemoveChildren: false,
308
- smoothChildTiming: false
324
+ smoothChildTiming: false,
309
325
  })
310
326
 
311
327
  return {
@@ -317,9 +333,9 @@ export default class Moonwalk {
317
333
  stage: {
318
334
  name: section.getAttribute('data-moonwalk-stage') || null,
319
335
  running: false,
320
- firstTween: false
336
+ firstTween: false,
321
337
  },
322
- elements: []
338
+ elements: [],
323
339
  }
324
340
  }
325
341
 
@@ -328,8 +344,12 @@ export default class Moonwalk {
328
344
  * Can be used if Moonwalking interferes with custom lazyloading animations
329
345
  */
330
346
  clearLazyloads(container = document.body) {
331
- const srcsets = container.querySelectorAll('[data-ll-srcset][data-moonwalk]')
332
- Array.from(srcsets).forEach(srcset => srcset.removeAttribute('data-moonwalk'))
347
+ const srcsets = container.querySelectorAll(
348
+ '[data-ll-srcset][data-moonwalk]'
349
+ )
350
+ Array.from(srcsets).forEach((srcset) =>
351
+ srcset.removeAttribute('data-moonwalk')
352
+ )
333
353
  }
334
354
 
335
355
  /**
@@ -342,7 +362,7 @@ export default class Moonwalk {
342
362
  parseChildren(section) {
343
363
  const mwc = Dom.all(section, '[data-moonwalk-children]')
344
364
 
345
- Array.from(mwc).forEach(c => {
365
+ Array.from(mwc).forEach((c) => {
346
366
  const key = c.getAttribute('data-moonwalk-children')
347
367
  this.setAttrs(c, key)
348
368
  })
@@ -357,7 +377,7 @@ export default class Moonwalk {
357
377
  setAttrs(element, val) {
358
378
  const affectedElements = []
359
379
 
360
- Array.prototype.forEach.call(element.children, c => {
380
+ Array.prototype.forEach.call(element.children, (c) => {
361
381
  c.setAttribute('data-moonwalk', val)
362
382
  affectedElements.push(c)
363
383
  })
@@ -380,7 +400,7 @@ export default class Moonwalk {
380
400
  }
381
401
 
382
402
  const {
383
- opts: { walks }
403
+ opts: { walks },
384
404
  } = this
385
405
 
386
406
  if (section.name) {
@@ -397,7 +417,7 @@ export default class Moonwalk {
397
417
  const fromTransition = sectionWalk.alphaTween
398
418
  ? {
399
419
  ...sectionWalk.transition.from,
400
- opacity: 0
420
+ opacity: 0,
401
421
  }
402
422
  : sectionWalk.transition.from
403
423
 
@@ -445,7 +465,7 @@ export default class Moonwalk {
445
465
 
446
466
  const to = {
447
467
  ...stageTween.transition.to,
448
- duration: stageTween.duration
468
+ duration: stageTween.duration,
449
469
  }
450
470
 
451
471
  section.timeline.to(entry.target, to, 0)
@@ -458,7 +478,9 @@ export default class Moonwalk {
458
478
  const tween = walks[section.name]
459
479
 
460
480
  if (!tween) {
461
- console.error(`==> JUPITER: Walk [${section.name}] not found in config`)
481
+ console.error(
482
+ `==> JUPITER: Walk [${section.name}] not found in config`
483
+ )
462
484
  }
463
485
 
464
486
  if (typeof tween.alphaTween === 'object') {
@@ -468,14 +490,14 @@ export default class Moonwalk {
468
490
  } else if (tween.alphaTween === true) {
469
491
  tween.alphaTween = {
470
492
  duration: tween.duration,
471
- ease: 'sine.in'
493
+ ease: 'sine.in',
472
494
  }
473
495
  }
474
496
 
475
497
  if (tween.startDelay) {
476
498
  tween.transition.to = {
477
499
  ...tween.transition.to,
478
- delay: tween.startDelay
500
+ delay: tween.startDelay,
479
501
  }
480
502
  }
481
503
 
@@ -494,7 +516,7 @@ export default class Moonwalk {
494
516
  {
495
517
  opacity: 1,
496
518
  ease: tween.alphaTween.ease,
497
- delay: tween.startDelay || 0
519
+ delay: tween.startDelay || 0,
498
520
  },
499
521
  tween.interval,
500
522
  0
@@ -599,7 +621,7 @@ export default class Moonwalk {
599
621
  }
600
622
 
601
623
  section.elements = section.el.querySelectorAll('[data-moonwalk]')
602
- section.elements.forEach(box => section.observer.observe(box))
624
+ section.elements.forEach((box) => section.observer.observe(box))
603
625
  }
604
626
  }
605
627
 
@@ -615,16 +637,22 @@ export default class Moonwalk {
615
637
  for (let i = 0; i < entries.length; i += 1) {
616
638
  const entry = entries[i]
617
639
  if (entry.isIntersecting && run.callback) {
618
- const runRepeated = entry.target.hasAttribute('data-moonwalk-run-triggered')
640
+ const runRepeated = entry.target.hasAttribute(
641
+ 'data-moonwalk-run-triggered'
642
+ )
619
643
  run.callback(entry.target, runRepeated)
620
644
  entry.target.setAttribute('data-moonwalk-run-triggered', '')
621
645
  if (!run.onExit && !run.repeated) {
622
646
  self.unobserve(entry.target)
623
647
  }
624
648
  } else {
625
- if (run.onExit && entry.target.hasAttribute('data-moonwalk-run-triggered')) {
626
- const runExited = entry.target.hasAttribute('data-moonwalk-run-exit-triggered')
627
- // entry.target.removeAttribute('data-moonwalk-run-triggered')
649
+ if (
650
+ run.onExit &&
651
+ entry.target.hasAttribute('data-moonwalk-run-triggered')
652
+ ) {
653
+ const runExited = entry.target.hasAttribute(
654
+ 'data-moonwalk-run-exit-triggered'
655
+ )
628
656
  entry.target.setAttribute('data-moonwalk-run-exit-triggered', '')
629
657
  run.onExit(entry.target, runExited)
630
658
  if (!run.repeated) {
@@ -636,7 +664,7 @@ export default class Moonwalk {
636
664
  },
637
665
  {
638
666
  rootMargin,
639
- threshold: run.threshold
667
+ threshold: run.threshold,
640
668
  }
641
669
  )
642
670
  }
@@ -664,7 +692,9 @@ export default class Moonwalk {
664
692
  }
665
693
 
666
694
  const walkName = entry.target.getAttribute('data-moonwalk')
667
- const cfg = !walkName.length ? opts.walks.default : opts.walks[walkName]
695
+ const cfg = !walkName.length
696
+ ? opts.walks.default
697
+ : opts.walks[walkName]
668
698
 
669
699
  const { duration, transition, interval, startDelay } = cfg
670
700
 
@@ -677,18 +707,28 @@ export default class Moonwalk {
677
707
  }
678
708
 
679
709
  if (typeof alphaTween === 'object' && alphaTween !== null) {
680
- alphaTween.duration = alphaTween.duration ? alphaTween.duration : duration
710
+ alphaTween.duration = alphaTween.duration
711
+ ? alphaTween.duration
712
+ : duration
681
713
  } else if (alphaTween === true) {
682
714
  alphaTween = {
683
715
  duration,
684
- ease: 'sine.in'
716
+ ease: 'sine.in',
685
717
  }
686
718
  }
687
719
 
688
720
  const tween = transition ? this.tweenJS : this.tweenCSS
689
721
 
690
722
  const tweenFn = () => {
691
- tween(section, entry.target, duration, interval, transition, overlap, alphaTween)
723
+ tween(
724
+ section,
725
+ entry.target,
726
+ duration,
727
+ interval,
728
+ transition,
729
+ overlap,
730
+ alphaTween
731
+ )
692
732
  }
693
733
 
694
734
  const wrappedTweenFn = () => {
@@ -710,8 +750,17 @@ export default class Moonwalk {
710
750
  } else {
711
751
  const imagesInEntry = entry.target.querySelectorAll('img')
712
752
  if (imagesInEntry.length) {
713
- // entry has children elements that are images
714
- imagesAreLoaded(imagesInEntry).then(() => wrappedTweenFn())
753
+ const allPlaceholders = Array.from(imagesInEntry).every(
754
+ (img) => img.hasAttribute('data-ll-placeholder')
755
+ )
756
+
757
+ // if all images in the entry have `data-ll-placeholder`,
758
+ // they are lazyloaded and we don't need to wait
759
+ if (allPlaceholders) {
760
+ wrappedTweenFn()
761
+ } else {
762
+ imagesAreLoaded(imagesInEntry).then(() => wrappedTweenFn())
763
+ }
715
764
  } else {
716
765
  // regular entry, just tween it
717
766
  wrappedTweenFn()
@@ -724,7 +773,7 @@ export default class Moonwalk {
724
773
  },
725
774
  {
726
775
  rootMargin,
727
- threshold: opts.threshold
776
+ threshold: opts.threshold,
728
777
  }
729
778
  )
730
779
  }
@@ -781,7 +830,7 @@ export default class Moonwalk {
781
830
  const toTransition = {
782
831
  ...tweenTransition.to,
783
832
  duration: tweenDuration,
784
- onComplete: () => target.setAttribute('data-moonwalked', '')
833
+ onComplete: () => target.setAttribute('data-moonwalked', ''),
785
834
  }
786
835
 
787
836
  section.timeline.to(target, toTransition, tweenPosition())
@@ -793,7 +842,7 @@ export default class Moonwalk {
793
842
  duration: alphaTween.duration,
794
843
  opacity: 1,
795
844
  ease: alphaTween.ease,
796
- delay: alphaTween.delay ? alphaTween.delay : 0
845
+ delay: alphaTween.delay ? alphaTween.delay : 0,
797
846
  },
798
847
  '<'
799
848
  )
@@ -809,7 +858,14 @@ export default class Moonwalk {
809
858
  * @param {*} transition
810
859
  * @param {*} overlap
811
860
  */
812
- tweenCSS(section, target, tweenDuration, tweenInterval, tweenTransition, tweenOverlap) {
861
+ tweenCSS(
862
+ section,
863
+ target,
864
+ tweenDuration,
865
+ tweenInterval,
866
+ tweenTransition,
867
+ tweenOverlap
868
+ ) {
813
869
  let tweenPosition
814
870
  const startingPoint = tweenDuration - tweenOverlap * -1
815
871
 
@@ -843,9 +899,11 @@ export default class Moonwalk {
843
899
  target,
844
900
  {
845
901
  css: {
846
- className: target.className ? `${target.className} moonwalked` : 'moonwalked'
902
+ className: target.className
903
+ ? `${target.className} moonwalked`
904
+ : 'moonwalked',
847
905
  },
848
- duration: tweenDuration
906
+ duration: tweenDuration,
849
907
  },
850
908
  tweenPosition()
851
909
  )
@@ -1,7 +1,9 @@
1
1
  import _defaultsDeep from 'lodash.defaultsdeep'
2
2
  import Dom from '../Dom'
3
3
 
4
- const DEFAULT_OPTIONS = {}
4
+ const DEFAULT_OPTIONS = {
5
+ onIntersect: (target, trigger) => {}
6
+ }
5
7
 
6
8
  export default class ScrollSpy {
7
9
  constructor(app, opts = {}) {
@@ -37,6 +39,7 @@ export default class ScrollSpy {
37
39
  }
38
40
  if (shouldBeActive) {
39
41
  shouldBeActive.dataset.scrollspyActive = ''
42
+ this.opts.onIntersect(entry.target, shouldBeActive)
40
43
  }
41
44
  }
42
45
  }