@foeewni/web-core 3.0.0-alpha.10 → 3.0.0-alpha.12

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,6 +1,6 @@
1
1
  {
2
2
  "name": "@foeewni/web-core",
3
- "version": "3.0.0-alpha.10",
3
+ "version": "3.0.0-alpha.12",
4
4
  "description": "Friend of the Earth EWNI Core for frontend projects",
5
5
  "browser": {
6
6
  "foe-core.js": "dist/js/foe.core.min.js",
@@ -61,6 +61,10 @@ Form `type=submit`s, `button`s are by default uncolorized, please use one of the
61
61
  margin: 0 auto;
62
62
  }
63
63
 
64
+ .btn-lg {
65
+ width: 100%;
66
+ }
67
+
64
68
  .btn {
65
69
  &:focus {
66
70
  outline: $foe-element-default-outline;
@@ -29,3 +29,8 @@ p a:not(.btn, .foe-cta) {
29
29
  text-decoration: underline;
30
30
  color: $foe-text;
31
31
  }
32
+
33
+ .row > [class*="col-"] {
34
+ // reset the z-index on each column
35
+ z-index: 0;
36
+ }
@@ -17,12 +17,20 @@ https://www.bennadel.com/blog/4310-detecting-rendered-line-breaks-in-a-text-node
17
17
 
18
18
  (() => {
19
19
  // Config
20
- const ROTATION_MAX_DEGREES = 3; // Degrees. "Normal" is around 2.5
20
+ const ROTATION_MAX_DEGREES = 2; // Degrees. "Normal" is around 2.5
21
21
  const BACKGROUND_EXTENSION = 0.5; // rem. Normal is around 1
22
22
  const CORNER_JIGGLE_MAX = 1; // rem. Normal is around .2
23
+ const BREAK_RATIO = 2.5; // ratio for when the variation on the side happens
23
24
  let oneRemInPx = 0;
24
25
  let extension = 0;
25
26
 
27
+ // Constants
28
+ const JIGGLE_ALL = 0;
29
+ const JIGGLE_UP = 1;
30
+ const JIGGLE_DOWN = 2;
31
+ const JIGGLE_LEFT = 3;
32
+ const JIGGLE_RIGHT = 4;
33
+
26
34
  // Helpers
27
35
  const generateRandomHex = (length) => {
28
36
  let result = '';
@@ -45,174 +53,276 @@ https://www.bennadel.com/blog/4310-detecting-rendered-line-breaks-in-a-text-node
45
53
  context.stroke();
46
54
  };
47
55
 
48
- // const drawPoint = (context, x, y) => {
49
- // if (!context.fillStyle) {
50
- // context.fillStyle = "#61bdaa";
51
- // }
52
- // context.fillRect(x - 1.5, y - 1.5, 3, 3);
53
- // };
54
-
55
- const jauntTarget = (target) => {
56
- if (!target.firstChild || target.firstChild.nodeType !== Node.TEXT_NODE) {
56
+ const jauntTarget = (target, action = null) => {
57
+ if (
58
+ !target.firstChild ||
59
+ target.firstChild.nodeType !== Node.TEXT_NODE
60
+ ) {
57
61
  return;
58
62
  }
59
63
 
60
- // Create a unique ID to link this element with the canvas background
61
- if (!target.dataset.backgroundCanvasId) {
62
- target.dataset.backgroundCanvasId = generateRandomHex(12);
63
- }
64
-
65
- // Clean up any existing jauntiness
66
- const existingCanvas = document.getElementById(
67
- target.dataset.backgroundCanvasId
68
- );
69
- if (existingCanvas) {
70
- existingCanvas.remove();
71
- }
72
- const previousTransform = getComputedStyle(target).transform;
73
- target.style.transition = 'none';
74
- target.style.transform = null;
64
+ // jauntSeed is stored on page so remains constant when resizing or hovering
65
+ const jauntSeed = target.dataset.jauntSeed ? target.dataset.jauntSeed : generateRandomHex(4 * 8);
66
+ target.dataset.jauntSeed = jauntSeed;
75
67
 
76
68
  // Set up the parameters
77
69
  const jauntFactor = parseFloat(target.dataset.jauntFactor);
78
70
  extension = BACKGROUND_EXTENSION * oneRemInPx * jauntFactor;
79
- // jauntSeed is stored on page so remains constant when resizing or hovering
80
- const jauntSeed = target.dataset.jauntSeed ? target.dataset.jauntSeed : generateRandomHex(4 * 8);
81
- target.dataset.jauntSeed = jauntSeed;
82
71
 
83
72
  // Figure out the bounding boxes
84
-
85
- // Collapse whitespace
86
- target.textContent = target.textContent.replace(/\s+/g, ' ').trim();
87
-
88
- // Get the individual lines as rendered on screen
89
- const { textContent } = target.firstChild;
90
- const range = document.createRange();
91
- range.setStart(target.firstChild, 0);
92
- range.setEnd(target.firstChild, textContent.length);
93
-
94
73
  // Get the bounding boxes
95
74
  const targetBox = target.getBoundingClientRect();
96
75
  const parentBox = target.offsetParent ? target.offsetParent.getBoundingClientRect() : targetBox;
97
- const outerBox = range.getBoundingClientRect();
98
- const boxes = Array.from(range.getClientRects());
99
76
 
100
- // Insert the new 2D canvas element
77
+ // switch(action) {
78
+ // case 'resize':
79
+ // target.dataset.points = false;
80
+ // break;
81
+ // }
82
+
83
+ // Insert the new 2D canvas element or find the existing one
84
+ if (target.dataset.backgroundCanvasId) {
85
+ document.getElementById(
86
+ target.dataset.backgroundCanvasId
87
+ ).remove();
88
+ }
101
89
  const canvas = document.createElement('canvas');
102
- canvas.id = target.dataset.backgroundCanvasId;
103
- target.parentNode.insertBefore(canvas, target);
104
- canvas.style.position = 'absolute';
105
- canvas.style.zIndex = -1;
106
- canvas.style.top = `${(targetBox.top - parentBox.top) - 2 * extension}px`;
107
- canvas.style.left = `${(targetBox.left - parentBox.left) - 2 * extension}px`;
108
- canvas.style.width = `${targetBox.width + 4 * extension}px`;
109
- canvas.style.height = `${targetBox.height + 4 * extension}px`;
110
- canvas.width = targetBox.width + 4 * extension;
111
- canvas.height = targetBox.height + 4 * extension;
112
- canvas.style.pointerEvents = 'none';
113
-
114
- // Draw the background boxes
90
+ // if (target.dataset.backgroundCanvasId) {
91
+ // canvas.getContext('2d')
92
+ // .clearRect(0, 0, canvas.width, canvas.height);
93
+ // } else {
94
+ // Create a unique ID to link this element with the canvas background
95
+ target.dataset.backgroundCanvasId = generateRandomHex(12);
96
+ canvas.id = target.dataset.backgroundCanvasId;
97
+ canvas.style.position = 'absolute';
98
+ canvas.style.zIndex = -1;
99
+ canvas.style.top = `${(targetBox.top - parentBox.top) - 2 * extension}px`;
100
+ canvas.style.left = `${(targetBox.left - parentBox.left) - 2 * extension}px`;
101
+ canvas.style.width = `${targetBox.width + 4 * extension}px`;
102
+ canvas.style.height = `${targetBox.height + 4 * extension}px`;
103
+ canvas.width = targetBox.width + 4 * extension;
104
+ canvas.height = targetBox.height + 4 * extension;
105
+ canvas.style.pointerEvents = 'none';
106
+ target.parentNode.insertBefore(canvas, target);
107
+ // }
108
+
109
+ // Add rotation
110
+ if (!target.dataset.jauntRotation) {
111
+ const middle = jauntSeed.length / 2 + 1;
112
+ let rotationSeed = jauntSeed.substring(1, middle);
113
+ rotationSeed = Number(`0x${rotationSeed}`);
114
+ rotationSeed /= 10 ** (`${rotationSeed}`).length;
115
+ const rotationFactor = ROTATION_MAX_DEGREES * jauntFactor
116
+ * (rotationSeed * 2 - 1); // -1 to +1
117
+ target.dataset.jauntRotation = rotationFactor;
118
+ }
119
+ target.style.transform = `rotate(${target.dataset.jauntRotation}deg)`;
120
+ canvas.style.transform = `rotate(${target.dataset.jauntRotation}deg)`;
121
+
115
122
  const context = canvas.getContext('2d');
116
123
 
117
124
  // set the background color and remove and existing background
118
- target.style.backgroundColor = null;
119
- target.style.borderColor = null;
125
+ target.style.backgroundColor = '';
126
+ target.style.borderColor = '';
127
+ target.style.transition = 'none';
120
128
  context.fillStyle = getComputedStyle(target).backgroundColor;
121
- if (!context.fillStyle) {
122
- context.fillStyle = '#61bdaa';
123
- }
124
129
  context.strokeStyle = getComputedStyle(target).borderColor;
130
+ target.dataset.jauntBackground = context.fillStyle;
131
+ target.dataset.jauntBorder = context.strokeStyle;
125
132
  target.style.backgroundColor = 'transparent';
126
133
  target.style.borderColor = 'transparent';
127
134
 
128
- const leftShift = getComputedStyle(target).textAlign === 'center'
129
- ? (targetBox.width - outerBox.width) / 2 - extension
130
- : 0;
131
- boxes.forEach((lineBox, i) => {
132
- const points = [];
133
-
134
- points.push({
135
- // Top left
136
- x: leftShift + lineBox.left - outerBox.left + 2 * extension,
137
- y: lineBox.top - outerBox.top + 2 * extension,
138
- });
139
- points.push({
140
- // Top right
141
- x: points[0].x + lineBox.width + 2 * extension,
142
- y: points[0].y,
143
- });
144
- points.push({
145
- // Bottom right
146
- x: points[0].x + lineBox.width + 2 * extension,
147
- y: points[0].y + lineBox.height + 2 * extension,
148
- });
149
- points.push({
150
- // Bottom left
151
- x: points[0].x,
152
- y: points[0].y + lineBox.height + 2 * extension,
153
- });
135
+ // Collapse whitespace
136
+ target.textContent = target.textContent.replace(/\s+/g, ' ').trim();
154
137
 
155
- // context.fillRect(
156
- // lineBox.left - outerBox.left + 2 * extension,
157
- // lineBox.top - outerBox.top + 2 * extension,
158
- // lineBox.width + 2 * extension,
159
- // lineBox.height + 2 * extension,
160
- // );
138
+ // Get the individual lines as rendered on screen
139
+ const { textContent } = target.firstChild;
140
+ const range = document.createRange();
141
+ range.setStart(target.firstChild, 0);
142
+ range.setEnd(target.firstChild, textContent.length);
161
143
 
162
- // Jiggle them points around
144
+ // const outerBox = range.getBoundingClientRect();
145
+ const boxes = target.dataset.jauntFull ? [targetBox] : Array.from(range.getClientRects());
146
+ const storedPoints = [];
147
+
148
+ // function to jiggle the points around using a seed
149
+ const jigglePoint = (point, seed, mod = JIGGLE_ALL) => {
150
+ // isolate a point seed from the master seed
151
+ const startPoint = seed.index * seed.pointSeedLength;
152
+ const endPointX = startPoint + (seed.pointSeedLength / 2);
153
+ const endPointY = startPoint + seed.pointSeedLength;
154
+ const middle = seed.pointSeedLength / 2 + 1;
155
+ let xRandom = seed.boxSeed.substring(startPoint, endPointX);
156
+ let yRandom = seed.boxSeed.substring(endPointX, endPointY);
157
+ // convert the hex seed to decimal
158
+ xRandom = Number(`0x${xRandom}`);
159
+ yRandom = Number(`0x${yRandom}`);
160
+ // reduce the points to 0 -> 1 random float
161
+ xRandom /= 10 ** middle;
162
+ yRandom /= 10 ** middle;
163
+ // modify the direction of jiggle based on modifications
164
+ switch (mod) {
165
+ case JIGGLE_LEFT:
166
+ xRandom *= -2;
167
+ break;
168
+ case JIGGLE_RIGHT:
169
+ xRandom *= 2;
170
+ break;
171
+ default:
172
+ // modify the corners less
173
+ xRandom -= 0.5;
174
+ break;
175
+ }
176
+ switch (mod) {
177
+ case JIGGLE_UP:
178
+ yRandom *= -2;
179
+ break;
180
+ case JIGGLE_DOWN:
181
+ yRandom *= 2;
182
+ break;
183
+ default:
184
+ // modify the corners less
185
+ yRandom -= 0.5;
186
+ break;
187
+ }
188
+ return {
189
+ x:
190
+ point.x
191
+ + xRandom
192
+ * extension / 2
193
+ * CORNER_JIGGLE_MAX
194
+ * jauntFactor,
195
+ y:
196
+ point.y
197
+ + yRandom
198
+ * extension / 2
199
+ * CORNER_JIGGLE_MAX
200
+ * jauntFactor,
201
+ };
202
+ };
203
+ boxes.forEach((lineBox, i) => {
204
+ const points = [];
205
+ // dimension constants to use for points
206
+ const lineWidth = lineBox.width + (target.dataset.jauntFull ? - extension : (4 * extension));
207
+ const lineHeight = lineBox.height + (target.dataset.jauntFull ? - extension : (4 * extension));
208
+ const left = lineBox.left - targetBox.left + (target.dataset.jauntFull ? (3 * extension) : 0);
209
+ const right = lineBox.left - targetBox.left + (target.dataset.jauntFull ? (3 * extension) : 0) + lineWidth;
210
+ const top = lineBox.top - targetBox.top + (target.dataset.jauntFull ? (2 * extension) : 0);
211
+ const bottom = lineBox.top - targetBox.top + (target.dataset.jauntFull ? (2 * extension) : 0) + lineHeight;
212
+ // number of intemidiate points vertically and horizontally
213
+ const widthPointCount = Math.ceil(lineWidth / (lineHeight * BREAK_RATIO)) - 1;
214
+ const heightPointCount = Math.ceil(lineHeight / (lineWidth * BREAK_RATIO)) - 1;
215
+ // modify the seed string for this line box and calculate the secion lengths
163
216
  const boxSeed = jauntSeed.substring(i) + jauntSeed.substring(0, i);
164
- const seedLength = boxSeed.length;
165
- const pointSeedLength = seedLength / points.length;
166
- points.forEach((point, index) => {
167
- const startPoint = index * pointSeedLength;
168
- const endPointX = startPoint + (pointSeedLength / 2);
169
- const endPointY = startPoint + pointSeedLength;
170
- const middle = pointSeedLength / 2 + 1;
171
- let xRandom = boxSeed.substring(startPoint, endPointX);
172
- let yRandom = boxSeed.substring(endPointX, endPointY);
173
- xRandom = Number(`0x${xRandom}`);
174
- yRandom = Number(`0x${yRandom}`);
175
- xRandom /= 10 ** middle;
176
- yRandom /= 10 ** middle;
177
- points[index] = {
178
- x:
179
- point.x
180
- + (xRandom * 2 - 1)
181
- * oneRemInPx
182
- * CORNER_JIGGLE_MAX
183
- * jauntFactor,
184
- y:
185
- point.y
186
- + (yRandom * 2 - 1)
187
- * oneRemInPx
188
- * CORNER_JIGGLE_MAX
189
- * jauntFactor,
190
- };
191
- });
192
-
193
- // points.forEach((point) => {
194
- // drawPoint(context, point.x, point.y);
195
- // });
217
+ const pointSeedLength = boxSeed.length / (widthPointCount * 2 + heightPointCount * 2 + 4);
218
+
219
+ // Top left
220
+ let index = 0;
221
+ points.push(jigglePoint({
222
+ x: left,
223
+ y: top,
224
+ }, {
225
+ index,
226
+ boxSeed,
227
+ pointSeedLength,
228
+ }));
229
+ index += 1;
230
+ // Top edge additional points
231
+ let j = 0;
232
+ while (j < widthPointCount) {
233
+ j += 1;
234
+ points.push(jigglePoint({
235
+ x: left + (j * lineWidth / (widthPointCount + 1)),
236
+ y: top,
237
+ }, {
238
+ index,
239
+ boxSeed,
240
+ pointSeedLength,
241
+ }, JIGGLE_UP));
242
+ index += 1;
243
+ }
244
+ // Top right
245
+ points.push(jigglePoint({
246
+ x: right,
247
+ y: top,
248
+ }, {
249
+ index,
250
+ boxSeed,
251
+ pointSeedLength,
252
+ }));
253
+ index += 1;
254
+ // Right edge additional points
255
+ j = 0;
256
+ while (j < heightPointCount) {
257
+ j += 1;
258
+ points.push(jigglePoint({
259
+ x: right,
260
+ y: top + (j * lineHeight / (heightPointCount + 1)),
261
+ }, {
262
+ index,
263
+ boxSeed,
264
+ pointSeedLength,
265
+ }, JIGGLE_RIGHT));
266
+ index += 1;
267
+ }
268
+ // Bottom right
269
+ points.push(jigglePoint({
270
+ x: right,
271
+ y: bottom,
272
+ }, {
273
+ index,
274
+ boxSeed,
275
+ pointSeedLength,
276
+ }));
277
+ index += 1;
278
+ // Bottom edge additional points
279
+ j = 0;
280
+ while (j < widthPointCount) {
281
+ j += 1;
282
+ points.push(jigglePoint({
283
+ x: right - (j * lineWidth / (widthPointCount + 1)),
284
+ y: bottom,
285
+ }, {
286
+ index,
287
+ boxSeed,
288
+ pointSeedLength,
289
+ }, JIGGLE_DOWN));
290
+ index += 1;
291
+ }
292
+ // Bottom left
293
+ points.push(jigglePoint({
294
+ x: left,
295
+ y: bottom,
296
+ }, {
297
+ index,
298
+ boxSeed,
299
+ pointSeedLength,
300
+ }));
301
+ index += 1;
302
+ // Right edge additional points
303
+ j = 0;
304
+ while (j < heightPointCount) {
305
+ j += 1;
306
+ points.push(jigglePoint({
307
+ x: left,
308
+ y: bottom - (j * lineHeight / (heightPointCount + 1)),
309
+ }, {
310
+ index,
311
+ boxSeed,
312
+ pointSeedLength,
313
+ }, JIGGLE_LEFT));
314
+ index += 1;
315
+ }
196
316
 
197
317
  drawPolygon(context, points);
318
+ storedPoints.push(points);
198
319
  });
199
320
 
200
- target.style.transform = previousTransform;
201
- target.style.transition = null;
202
-
203
- // Add rotation
204
- const middle = jauntSeed.length / 2 + 1;
205
- let rotationSeed = jauntSeed.substring(1, middle);
206
- rotationSeed = Number(`0x${jauntSeed}`);
207
- rotationSeed /= 10 ** (`${rotationSeed}`).length;
208
- const rotationFactor = ROTATION_MAX_DEGREES * jauntFactor
209
- * (rotationSeed * 2 - 1); // -1 to +1
210
- target.style.transform = `rotate(${rotationFactor}deg)`;
211
- canvas.style.transform = `rotate(${rotationFactor}deg)`;
321
+ target.dataset.points = JSON.stringify(storedPoints);
212
322
  };
213
323
 
214
324
  // The main event
215
- const createBackground = () => {
325
+ const createBackground = (action = null) => {
216
326
  oneRemInPx = parseFloat(
217
327
  getComputedStyle(document.documentElement).fontSize
218
328
  );
@@ -221,26 +331,45 @@ https://www.bennadel.com/blog/4310-detecting-rendered-line-breaks-in-a-text-node
221
331
 
222
332
  // Insert some jaunt
223
333
  targets.forEach((target) => {
224
- jauntTarget(target);
334
+ jauntTarget(target, action);
335
+ });
336
+ };
337
+
338
+ const processEvent = (e) => {
339
+ jauntTarget(e.target, e.type);
340
+ }
341
+
342
+ const observer = new IntersectionObserver((entries) => {
343
+ entries.forEach(entry => {
344
+ jauntTarget(entry.target, 'visibility');
345
+ });
346
+ }, {
347
+ root: document.documentElement
348
+ });
349
+
350
+ const init = () => {
351
+ const targets = document.querySelectorAll('[data-jaunt-factor]');
352
+ createBackground('init');
353
+ targets.forEach((target) => {
225
354
  [
355
+ 'blur',
356
+ 'change',
357
+ 'focus',
226
358
  'mouseenter',
227
359
  'mouseleave',
228
- 'focus',
229
360
  ].forEach((action) => {
230
- target.addEventListener(action, (e) => {
231
- jauntTarget(e.target);
232
- });
361
+ target.removeEventListener(action, processEvent);
362
+ target.addEventListener(action, processEvent);
233
363
  });
364
+ observer.observe(target);
234
365
  });
235
366
  };
236
367
 
237
- const init = () => {
238
- createBackground();
239
- };
240
-
241
368
  // Go time
242
369
  document.addEventListener('DOMContentLoaded', init);
243
370
  document.addEventListener('load', init);
244
- window.addEventListener('resize', createBackground);
371
+ window.addEventListener('resize', () => {
372
+ createBackground('resize');
373
+ });
245
374
  window.runJaunt = init;
246
375
  })();
@@ -460,7 +460,7 @@ $font-weight-heavy: 700;
460
460
  $font-weight-base: $font-weight-normal;
461
461
  $line-height-base: 1.5;
462
462
 
463
- $h1-font-size: calc(60 / 16) * $font-size-base;
463
+ $h1-font-size: calc(56 / 16) * $font-size-base;
464
464
  $h2-font-size: calc(40 / 16) * $font-size-base;
465
465
  $h3-font-size: calc(32 / 16) * $font-size-base;
466
466
  $h4-font-size: calc(26 / 16) * $font-size-base;
@@ -482,10 +482,10 @@ $headings-font-weight: 900;
482
482
  $headings-line-height: 1.2;
483
483
  $headings-color: $foe-accent;
484
484
 
485
- $display1-size: calc(60 / 16) * $font-size-base;
486
- $display2-size: calc(60 / 16) * $font-size-base;
487
- $display3-size: 4.5rem;
488
- $display4-size: 3.5rem;
485
+ $display1-size: $h1-font-size;
486
+ $display2-size: $h1-font-size;
487
+ $display3-size: $h3-font-size;
488
+ $display4-size: $h4-font-size;
489
489
 
490
490
  $display1-weight: 900;
491
491
  $display2-weight: 300;