@brandocms/jupiter 3.52.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.52.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 {
@@ -108,23 +108,22 @@ export default class Moonwalk {
108
108
  }
109
109
 
110
110
  initialize(container = document.body) {
111
- if (this.opts.clearMoonwalkOnAnchors) {
112
- if (window.location.hash) {
113
- this.removeAllWalks()
114
- return
115
- }
116
- }
117
-
118
111
  if (this.opts.clearNestedSections) {
119
112
  container
120
113
  .querySelectorAll('[data-moonwalk-section] [data-moonwalk-section]')
121
- .forEach(ms => ms.removeAttribute('data-moonwalk-section'))
114
+ .forEach((ms) => ms.removeAttribute('data-moonwalk-section'))
122
115
  }
123
116
 
124
117
  if (this.opts.clearNestedWalks) {
125
118
  container
126
119
  .querySelectorAll('[data-moonwalk] [data-moonwalk]')
127
- .forEach(ms => ms.removeAttribute('data-moonwalk'))
120
+ .forEach((ms) => ms.removeAttribute('data-moonwalk'))
121
+ }
122
+
123
+ if (this.opts.clearMoonwalkOnAnchors) {
124
+ if (window.location.hash) {
125
+ this.walkToThisPoint(window.location.hash)
126
+ }
128
127
  }
129
128
 
130
129
  this.addClass()
@@ -151,19 +150,52 @@ export default class Moonwalk {
151
150
  document.documentElement.classList.add('moonwalk')
152
151
  }
153
152
 
153
+ /**
154
+ * Matching moonwalk elements before the element matching the hash should be set to visible
155
+ * by setting the `data-moonwalked` attribute on `data-moonwalk` elements and
156
+ * `data-moonwalk-section-ready` on `data-moonwalk-section` elements.
157
+ */
158
+ walkToThisPoint(hash) {
159
+ // Find the target element using the hash
160
+ const targetElement = document.querySelector(hash)
161
+ if (!targetElement) return // Exit if the element is not found
162
+
163
+ // Get all elements with the 'data-moonwalk' attribute
164
+ const moonwalkElements = document.querySelectorAll('[data-moonwalk]')
165
+ moonwalkElements.forEach((el) => {
166
+ const position = el.compareDocumentPosition(targetElement)
167
+ // Check if 'el' comes before 'targetElement' or is the same element
168
+ if (position & Node.DOCUMENT_POSITION_FOLLOWING || el === targetElement) {
169
+ el.setAttribute('data-moonwalked', '')
170
+ el.classList.add('moonwalked')
171
+ }
172
+ })
173
+
174
+ // Get all elements with the 'data-moonwalk-section' attribute
175
+ const moonwalkSectionElements = document.querySelectorAll(
176
+ '[data-moonwalk-section]'
177
+ )
178
+ moonwalkSectionElements.forEach((el) => {
179
+ const position = el.compareDocumentPosition(targetElement)
180
+ // Check if 'el' comes before 'targetElement' or is the same element
181
+ if (position & Node.DOCUMENT_POSITION_FOLLOWING || el === targetElement) {
182
+ el.setAttribute('data-moonwalk-section-ready', '')
183
+ }
184
+ })
185
+ }
186
+
154
187
  /**
155
188
  * Remove all moonwalks. Useful for clients who prefer reduced motion
156
189
  */
157
- removeAllWalks(container = document.body) {
190
+ removeAllWalks(container = document.body, beforeEl = nil) {
158
191
  const keys = [
159
192
  'data-moonwalk',
160
- 'data-moonwalk-run',
161
193
  'data-moonwalk-section',
162
- 'data-moonwalk-children'
194
+ 'data-moonwalk-children',
163
195
  ]
164
- keys.forEach(key => {
196
+ keys.forEach((key) => {
165
197
  const elems = container.querySelectorAll(`[${key}]`)
166
- Array.from(elems).forEach(el => el.removeAttribute(key))
198
+ Array.from(elems).forEach((el) => el.removeAttribute(key))
167
199
  container.removeAttribute(key)
168
200
  })
169
201
  }
@@ -171,13 +203,12 @@ export default class Moonwalk {
171
203
  removeFor(container = document.body, selector) {
172
204
  const keys = [
173
205
  'data-moonwalk',
174
- 'data-moonwalk-run',
175
206
  'data-moonwalk-section',
176
- 'data-moonwalk-children'
207
+ 'data-moonwalk-children',
177
208
  ]
178
- keys.forEach(key => {
209
+ keys.forEach((key) => {
179
210
  const elems = container.querySelectorAll(`${selector}[${key}]`)
180
- Array.from(elems).forEach(el => el.removeAttribute(key))
211
+ Array.from(elems).forEach((el) => el.removeAttribute(key))
181
212
  })
182
213
  }
183
214
 
@@ -187,7 +218,7 @@ export default class Moonwalk {
187
218
  removeRun(container = document.body, name) {
188
219
  const key = 'data-moonwalk-run'
189
220
  const elems = container.querySelectorAll(`[${key}="${name}"]`)
190
- Array.from(elems).forEach(el => el.removeAttribute(key))
221
+ Array.from(elems).forEach((el) => el.removeAttribute(key))
191
222
  }
192
223
 
193
224
  /**
@@ -196,7 +227,7 @@ export default class Moonwalk {
196
227
  removeRuns(container = document.body) {
197
228
  const key = 'data-moonwalk-run'
198
229
  const elems = container.querySelectorAll(`[${key}]`)
199
- Array.from(elems).forEach(el => el.removeAttribute(key))
230
+ Array.from(elems).forEach((el) => el.removeAttribute(key))
200
231
  }
201
232
 
202
233
  /**
@@ -205,8 +236,11 @@ export default class Moonwalk {
205
236
  * @param {*} section
206
237
  */
207
238
  addIds(section) {
208
- Array.from(section.querySelectorAll('[data-moonwalk]')).forEach(el => {
209
- 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
+ )
210
244
  })
211
245
  }
212
246
 
@@ -216,8 +250,9 @@ export default class Moonwalk {
216
250
  * @param {*} section
217
251
  */
218
252
  addIndexes(section) {
219
- Object.keys(this.opts.walks).forEach(key => {
220
- 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}"]`
221
256
  const elements = section.querySelectorAll(searchAttr)
222
257
 
223
258
  Array.from(elements).forEach((element, index) => {
@@ -232,7 +267,7 @@ export default class Moonwalk {
232
267
  */
233
268
  initializeRuns(container = document.body) {
234
269
  const runs = container.querySelectorAll('[data-moonwalk-run]')
235
- return Array.from(runs).map(run => {
270
+ return Array.from(runs).map((run) => {
236
271
  const foundRun = this.opts.runs[run.getAttribute('data-moonwalk-run')]
237
272
  if (foundRun) {
238
273
  if (foundRun.initialize) {
@@ -245,7 +280,7 @@ export default class Moonwalk {
245
280
  callback: foundRun.callback,
246
281
  onExit: foundRun.onExit,
247
282
  repeated: foundRun.repeated,
248
- rootMargin: foundRun.rootMargin
283
+ rootMargin: foundRun.rootMargin,
249
284
  }
250
285
  }
251
286
 
@@ -268,7 +303,9 @@ export default class Moonwalk {
268
303
  return [this.initializeSection(container)]
269
304
  }
270
305
 
271
- return Array.from(sections).map(section => this.initializeSection(section))
306
+ return Array.from(sections).map((section) =>
307
+ this.initializeSection(section)
308
+ )
272
309
  }
273
310
 
274
311
  initializeSection(section) {
@@ -284,7 +321,7 @@ export default class Moonwalk {
284
321
 
285
322
  const timeline = gsap.timeline({
286
323
  autoRemoveChildren: false,
287
- smoothChildTiming: false
324
+ smoothChildTiming: false,
288
325
  })
289
326
 
290
327
  return {
@@ -296,9 +333,9 @@ export default class Moonwalk {
296
333
  stage: {
297
334
  name: section.getAttribute('data-moonwalk-stage') || null,
298
335
  running: false,
299
- firstTween: false
336
+ firstTween: false,
300
337
  },
301
- elements: []
338
+ elements: [],
302
339
  }
303
340
  }
304
341
 
@@ -307,8 +344,12 @@ export default class Moonwalk {
307
344
  * Can be used if Moonwalking interferes with custom lazyloading animations
308
345
  */
309
346
  clearLazyloads(container = document.body) {
310
- const srcsets = container.querySelectorAll('[data-ll-srcset][data-moonwalk]')
311
- 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
+ )
312
353
  }
313
354
 
314
355
  /**
@@ -321,7 +362,7 @@ export default class Moonwalk {
321
362
  parseChildren(section) {
322
363
  const mwc = Dom.all(section, '[data-moonwalk-children]')
323
364
 
324
- Array.from(mwc).forEach(c => {
365
+ Array.from(mwc).forEach((c) => {
325
366
  const key = c.getAttribute('data-moonwalk-children')
326
367
  this.setAttrs(c, key)
327
368
  })
@@ -336,7 +377,7 @@ export default class Moonwalk {
336
377
  setAttrs(element, val) {
337
378
  const affectedElements = []
338
379
 
339
- Array.prototype.forEach.call(element.children, c => {
380
+ Array.prototype.forEach.call(element.children, (c) => {
340
381
  c.setAttribute('data-moonwalk', val)
341
382
  affectedElements.push(c)
342
383
  })
@@ -359,7 +400,7 @@ export default class Moonwalk {
359
400
  }
360
401
 
361
402
  const {
362
- opts: { walks }
403
+ opts: { walks },
363
404
  } = this
364
405
 
365
406
  if (section.name) {
@@ -376,7 +417,7 @@ export default class Moonwalk {
376
417
  const fromTransition = sectionWalk.alphaTween
377
418
  ? {
378
419
  ...sectionWalk.transition.from,
379
- opacity: 0
420
+ opacity: 0,
380
421
  }
381
422
  : sectionWalk.transition.from
382
423
 
@@ -424,7 +465,7 @@ export default class Moonwalk {
424
465
 
425
466
  const to = {
426
467
  ...stageTween.transition.to,
427
- duration: stageTween.duration
468
+ duration: stageTween.duration,
428
469
  }
429
470
 
430
471
  section.timeline.to(entry.target, to, 0)
@@ -437,7 +478,9 @@ export default class Moonwalk {
437
478
  const tween = walks[section.name]
438
479
 
439
480
  if (!tween) {
440
- console.error(`==> JUPITER: Walk [${section.name}] not found in config`)
481
+ console.error(
482
+ `==> JUPITER: Walk [${section.name}] not found in config`
483
+ )
441
484
  }
442
485
 
443
486
  if (typeof tween.alphaTween === 'object') {
@@ -447,14 +490,14 @@ export default class Moonwalk {
447
490
  } else if (tween.alphaTween === true) {
448
491
  tween.alphaTween = {
449
492
  duration: tween.duration,
450
- ease: 'sine.in'
493
+ ease: 'sine.in',
451
494
  }
452
495
  }
453
496
 
454
497
  if (tween.startDelay) {
455
498
  tween.transition.to = {
456
499
  ...tween.transition.to,
457
- delay: tween.startDelay
500
+ delay: tween.startDelay,
458
501
  }
459
502
  }
460
503
 
@@ -473,7 +516,7 @@ export default class Moonwalk {
473
516
  {
474
517
  opacity: 1,
475
518
  ease: tween.alphaTween.ease,
476
- delay: tween.startDelay || 0
519
+ delay: tween.startDelay || 0,
477
520
  },
478
521
  tween.interval,
479
522
  0
@@ -578,7 +621,7 @@ export default class Moonwalk {
578
621
  }
579
622
 
580
623
  section.elements = section.el.querySelectorAll('[data-moonwalk]')
581
- section.elements.forEach(box => section.observer.observe(box))
624
+ section.elements.forEach((box) => section.observer.observe(box))
582
625
  }
583
626
  }
584
627
 
@@ -594,16 +637,22 @@ export default class Moonwalk {
594
637
  for (let i = 0; i < entries.length; i += 1) {
595
638
  const entry = entries[i]
596
639
  if (entry.isIntersecting && run.callback) {
597
- const runRepeated = entry.target.hasAttribute('data-moonwalk-run-triggered')
640
+ const runRepeated = entry.target.hasAttribute(
641
+ 'data-moonwalk-run-triggered'
642
+ )
598
643
  run.callback(entry.target, runRepeated)
599
644
  entry.target.setAttribute('data-moonwalk-run-triggered', '')
600
645
  if (!run.onExit && !run.repeated) {
601
646
  self.unobserve(entry.target)
602
647
  }
603
648
  } else {
604
- if (run.onExit && entry.target.hasAttribute('data-moonwalk-run-triggered')) {
605
- const runExited = entry.target.hasAttribute('data-moonwalk-run-exit-triggered')
606
- // 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
+ )
607
656
  entry.target.setAttribute('data-moonwalk-run-exit-triggered', '')
608
657
  run.onExit(entry.target, runExited)
609
658
  if (!run.repeated) {
@@ -615,7 +664,7 @@ export default class Moonwalk {
615
664
  },
616
665
  {
617
666
  rootMargin,
618
- threshold: run.threshold
667
+ threshold: run.threshold,
619
668
  }
620
669
  )
621
670
  }
@@ -643,7 +692,9 @@ export default class Moonwalk {
643
692
  }
644
693
 
645
694
  const walkName = entry.target.getAttribute('data-moonwalk')
646
- const cfg = !walkName.length ? opts.walks.default : opts.walks[walkName]
695
+ const cfg = !walkName.length
696
+ ? opts.walks.default
697
+ : opts.walks[walkName]
647
698
 
648
699
  const { duration, transition, interval, startDelay } = cfg
649
700
 
@@ -656,18 +707,28 @@ export default class Moonwalk {
656
707
  }
657
708
 
658
709
  if (typeof alphaTween === 'object' && alphaTween !== null) {
659
- alphaTween.duration = alphaTween.duration ? alphaTween.duration : duration
710
+ alphaTween.duration = alphaTween.duration
711
+ ? alphaTween.duration
712
+ : duration
660
713
  } else if (alphaTween === true) {
661
714
  alphaTween = {
662
715
  duration,
663
- ease: 'sine.in'
716
+ ease: 'sine.in',
664
717
  }
665
718
  }
666
719
 
667
720
  const tween = transition ? this.tweenJS : this.tweenCSS
668
721
 
669
722
  const tweenFn = () => {
670
- 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
+ )
671
732
  }
672
733
 
673
734
  const wrappedTweenFn = () => {
@@ -689,8 +750,17 @@ export default class Moonwalk {
689
750
  } else {
690
751
  const imagesInEntry = entry.target.querySelectorAll('img')
691
752
  if (imagesInEntry.length) {
692
- // entry has children elements that are images
693
- 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
+ }
694
764
  } else {
695
765
  // regular entry, just tween it
696
766
  wrappedTweenFn()
@@ -703,7 +773,7 @@ export default class Moonwalk {
703
773
  },
704
774
  {
705
775
  rootMargin,
706
- threshold: opts.threshold
776
+ threshold: opts.threshold,
707
777
  }
708
778
  )
709
779
  }
@@ -760,7 +830,7 @@ export default class Moonwalk {
760
830
  const toTransition = {
761
831
  ...tweenTransition.to,
762
832
  duration: tweenDuration,
763
- onComplete: () => target.setAttribute('data-moonwalked', '')
833
+ onComplete: () => target.setAttribute('data-moonwalked', ''),
764
834
  }
765
835
 
766
836
  section.timeline.to(target, toTransition, tweenPosition())
@@ -772,7 +842,7 @@ export default class Moonwalk {
772
842
  duration: alphaTween.duration,
773
843
  opacity: 1,
774
844
  ease: alphaTween.ease,
775
- delay: alphaTween.delay ? alphaTween.delay : 0
845
+ delay: alphaTween.delay ? alphaTween.delay : 0,
776
846
  },
777
847
  '<'
778
848
  )
@@ -788,7 +858,14 @@ export default class Moonwalk {
788
858
  * @param {*} transition
789
859
  * @param {*} overlap
790
860
  */
791
- tweenCSS(section, target, tweenDuration, tweenInterval, tweenTransition, tweenOverlap) {
861
+ tweenCSS(
862
+ section,
863
+ target,
864
+ tweenDuration,
865
+ tweenInterval,
866
+ tweenTransition,
867
+ tweenOverlap
868
+ ) {
792
869
  let tweenPosition
793
870
  const startingPoint = tweenDuration - tweenOverlap * -1
794
871
 
@@ -822,9 +899,11 @@ export default class Moonwalk {
822
899
  target,
823
900
  {
824
901
  css: {
825
- className: target.className ? `${target.className} moonwalked` : 'moonwalked'
902
+ className: target.className
903
+ ? `${target.className} moonwalked`
904
+ : 'moonwalked',
826
905
  },
827
- duration: tweenDuration
906
+ duration: tweenDuration,
828
907
  },
829
908
  tweenPosition()
830
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
  }