@ucd-lib/theme-elements 1.2.9 → 2.0.1

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": "@ucd-lib/theme-elements",
3
- "version": "1.2.9",
3
+ "version": "2.0.1",
4
4
  "description": "Custom elements for the UCD brand theme",
5
5
  "main": "index.js",
6
6
  "scripts": {
@@ -10,10 +10,10 @@
10
10
  "license": "MIT",
11
11
  "dependencies": {
12
12
  "@lit-labs/task": "^1.0.0",
13
- "@ucd-lib/theme-sass": "^5.0.15",
13
+ "@ucd-lib/theme-sass": "^6.0.1",
14
14
  "dompurify": "^2.3.9",
15
15
  "ip-cidr": "^3.0.4",
16
- "lit": "^2.0.2",
16
+ "lit": "^3.0.2",
17
17
  "marked": "^4.0.18",
18
18
  "photoswipe": "^4.1.3",
19
19
  "slim-select": "^1.26.2"
@@ -1,6 +1,7 @@
1
1
  import { BreakPointsController } from "./break-points";
2
2
  import { IntersectionObserverController } from "./intersection-observer";
3
3
  import { MutationObserverController } from "./mutation-observer";
4
+ import { PageWidthController } from "./page-width";
4
5
  import { PopStateObserverController } from "./popstate-observer";
5
6
  import { SilsPrimoController } from "./sils-primo";
6
7
  import { WaitController } from "./wait";
@@ -10,7 +11,8 @@ export {
10
11
  BreakPointsController,
11
12
  IntersectionObserverController,
12
13
  MutationObserverController,
14
+ PageWidthController,
13
15
  PopStateObserverController,
14
16
  SilsPrimoController,
15
17
  WaitController,
16
- };
18
+ };
@@ -0,0 +1,78 @@
1
+ /**
2
+ * @class PageWidthController
3
+ * @description Sets the page width as a CSS variable (--page-width), which is needed for some layout classes.
4
+ *
5
+ * @example
6
+ * const pageWidthController = new PageWidthController();
7
+ * pageWidthController.init();
8
+ */
9
+ export class PageWidthController {
10
+
11
+ constructor(){
12
+ this.documentRoot = document.documentElement;
13
+ this.propertyName = '--page-width';
14
+ this.fullWidthPropertyName = '--full-width';
15
+ }
16
+
17
+ /**
18
+ * @description Initialize the controller.
19
+ * @returns
20
+ */
21
+ init(){
22
+ if ( this.isInitialized() ) {
23
+ return;
24
+ }
25
+
26
+ // set initial state
27
+ this.setPageWidthProperty();
28
+ this.setFullWidthProperty();
29
+
30
+ // set up resize listener
31
+ this.resizeListener = window.addEventListener('resize', () => {
32
+ this.setPageWidthProperty();
33
+ });
34
+
35
+ }
36
+
37
+ /**
38
+ * @description Check if the controller has been initialized.
39
+ * @returns {Boolean}
40
+ */
41
+ isInitialized(){
42
+ return this.resizeListener !== undefined;
43
+ }
44
+
45
+ /**
46
+ * @description Destroy the controller.
47
+ */
48
+ destroy(){
49
+ window.removeEventListener('resize', this.resizeListener);
50
+ this.documentRoot.style.removeProperty(this.propertyName);
51
+ this.documentRoot.style.removeProperty(this.fullWidthPropertyName);
52
+ this.resizeListener = undefined;
53
+ }
54
+
55
+ /**
56
+ * @description Get the '--page-width' CSS variable from document root.
57
+ * @returns {String}
58
+ */
59
+ getPageWidthProperty(){
60
+ return this.documentRoot.style.getPropertyValue(this.propertyName);
61
+ }
62
+
63
+ /**
64
+ * @description Set the '--page-width' CSS variable on document root.
65
+ */
66
+ setPageWidthProperty(){
67
+ this.documentRoot.style.setProperty(this.propertyName, `${this.documentRoot.clientWidth}px`);
68
+ }
69
+
70
+ /**
71
+ * @description Set the '--full-width' CSS variable on document root.
72
+ */
73
+ setFullWidthProperty(){
74
+ const value = 'min(var(--page-width, 100vw), 100vw)';
75
+ this.documentRoot.style.setProperty(this.fullWidthPropertyName, value);
76
+ }
77
+
78
+ }