@parameter1/base-cms-marko-web 3.7.7 → 3.8.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -1,4 +1,5 @@
1
- import { getAsArray } from "@parameter1/base-cms-object-path";
1
+ import { getAsArray, getAsObject } from "@parameter1/base-cms-object-path";
2
+ import imageHeight from "../../node/utils/image-height";
2
3
 
3
4
  $ const { config } = out.global;
4
5
  $ const { src, alt } = input;
@@ -7,10 +8,11 @@ $ const srcset = getAsArray(input.srcset).join(", ") || null;
7
8
 
8
9
  $ const classNames = [input.class];
9
10
  $ if (lazyload) classNames.push("lazyload");
11
+ $ const attrs = getAsObject(input.attrs);
10
12
 
11
13
  <if(lazyload)>
12
14
  <img
13
- ...input.attrs
15
+ ...attrs
14
16
  src="data:image/gif;base64,R0lGODlhAQABAAAAACH5BAEKAAEALAAAAAABAAEAAAICTAEAOw=="
15
17
  srcset=null
16
18
  data-src=src
@@ -21,7 +23,7 @@ $ if (lazyload) classNames.push("lazyload");
21
23
  </if>
22
24
  <else>
23
25
  <img
24
- ...input.attrs
26
+ ...attrs
25
27
  src=src
26
28
  srcset=srcset
27
29
  class=classNames
@@ -63,7 +63,10 @@
63
63
  },
64
64
  "@class": "string",
65
65
  "@attrs": "object",
66
- "@link": "object"
66
+ "@link": "object",
67
+ "@width": "number",
68
+ "@height": "number",
69
+ "@ar": "string"
67
70
  },
68
71
  "<marko-web-link>": {
69
72
  "template": "./link.marko",
@@ -175,7 +178,10 @@
175
178
  },
176
179
  "@class": "string",
177
180
  "@attrs": "object",
178
- "@link": "object"
181
+ "@link": "object",
182
+ "@width": "string",
183
+ "@height": "string",
184
+ "@ar": "string"
179
185
  },
180
186
  "<link>": {
181
187
  "<before>": {},
@@ -195,7 +201,10 @@
195
201
  "@srcset": {
196
202
  "type": "array",
197
203
  "required": true
198
- }
204
+ },
205
+ "@width": "number",
206
+ "@height": "number",
207
+ "@ar": "string"
199
208
  }
200
209
  }
201
210
  }
@@ -28,6 +28,8 @@ $ const hasImage = Boolean(image.src);
28
28
  srcset=srcset
29
29
  data-srcset=dataSrcset
30
30
  media=s.media
31
+ width=s.width
32
+ height=s.height
31
33
  >
32
34
  </for>
33
35
  <image ...image />
@@ -1,20 +1,35 @@
1
- import { buildImgixUrl } from "@parameter1/base-cms-image";
2
- import { get } from "@parameter1/base-cms-object-path";
1
+ import { buildImgixUrl, getRelativeAspectRatioHeight, getRelativeAspectRatioWidth } from "@parameter1/base-cms-image";
2
+ import { get, getAsObject } from "@parameter1/base-cms-object-path";
3
3
 
4
4
  $ const element = "node__image";
5
5
  $ const hasImage = Boolean(input.src);
6
6
 
7
- $ const style = [];
8
- $ if (input.width) style.push(`width: ${input.width}px;`);
9
- $ if (input.height) style.push(`height: ${input.height}px;`);
10
- $ const attrs = { ...input.attrs, style };
7
+ <!--
8
+ 1. If either width or height input is set, use them as the options.w and options.h
9
+ 2. Using options.w and options.h, determine relative w and h when not present
10
+ 3. Finally, using options, set the image width and height attrs
11
+ -->
11
12
 
12
- $ const options = {
13
- fit: get(input, "options.w") && get(input, "options.h") ? "crop" : undefined,
14
- ...input.options,
13
+ $ const { width, height } = input;
14
+ $ const options = getAsObject(input, "options");
15
+
16
+ $ if (width || height) {
17
+ options.w = width || undefined;
18
+ options.h = height || undefined;
15
19
  }
20
+ $ if (input.ar) options.ar = input.ar;
21
+
22
+ $ const {
23
+ w,
24
+ h,
25
+ ar,
26
+ fit,
27
+ } = options;
28
+ $ if (w && !h) options.h = ar ? getRelativeAspectRatioHeight(w, ar) : undefined;
29
+ $ if (h && !w) options.w = ar ? getRelativeAspectRatioWidth(h, ar) : undefined;
30
+ $ if (!fit) options.fit = options.w && options.h ? "crop" : undefined;
16
31
 
17
- <!-- @todo add modifiers -->
32
+ $ const attrs = { ...input.attrs, width: options.w, height: options.h };
18
33
 
19
34
  <if(hasImage)>
20
35
  $ const src = buildImgixUrl(input.src, options, input.defaultOptions, input.isLogo);
@@ -172,6 +172,7 @@
172
172
  "template": "./image.marko",
173
173
  "@src": "string",
174
174
  "@alt": "string",
175
+ "@ar": "string",
175
176
  "@width": "number",
176
177
  "@height": "number",
177
178
  "@options": "object",
@@ -1,5 +1,3 @@
1
- module.exports = (width, ar) => {
2
- const [x, y] = ar.split(':');
3
- const r = x / y;
4
- return Math.round(width / r);
5
- };
1
+ const { getRelativeAspectRatioHeight } = require('@parameter1/base-cms-image');
2
+
3
+ module.exports = getRelativeAspectRatioHeight;
@@ -1,12 +1,17 @@
1
1
  const imageHeight = require('./image-height');
2
2
 
3
- module.exports = ({ fluid, ar, width = 320 }) => {
3
+ module.exports = ({
4
+ fluid,
5
+ ar,
6
+ width = 320,
7
+ delimiter = ':',
8
+ }) => {
4
9
  if (fluid === true) {
5
- if (ar) return { modifier: `fluid-${ar.replace(':', 'by')}` };
10
+ if (ar) return { modifier: `fluid-${ar.replace(delimiter, 'by')}` };
6
11
  return { modifier: 'fluid' };
7
12
  }
8
13
  if (ar) {
9
- return { width, height: imageHeight(width, ar) };
14
+ return { width, height: imageHeight(width, ar, delimiter) };
10
15
  }
11
16
  return { width };
12
17
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@parameter1/base-cms-marko-web",
3
- "version": "3.7.7",
3
+ "version": "3.8.0",
4
4
  "description": "Core Marko+Express components for BaseCMS websites",
5
5
  "author": "Jacob Bare <jacob@parameter1.com>",
6
6
  "main": "index.js",
@@ -16,10 +16,10 @@
16
16
  "dependencies": {
17
17
  "@godaddy/terminus": "^4.9.0",
18
18
  "@parameter1/base-cms-apollo-ssr": "^3.0.0",
19
- "@parameter1/base-cms-embedded-media": "^3.0.0",
19
+ "@parameter1/base-cms-embedded-media": "^3.8.0",
20
20
  "@parameter1/base-cms-express-apollo": "^3.0.0",
21
21
  "@parameter1/base-cms-graphql-fragment-types": "^3.0.0",
22
- "@parameter1/base-cms-image": "^3.0.0",
22
+ "@parameter1/base-cms-image": "^3.8.0",
23
23
  "@parameter1/base-cms-inflector": "^3.0.0",
24
24
  "@parameter1/base-cms-marko-node-require": "^3.0.0",
25
25
  "@parameter1/base-cms-object-path": "^3.0.0",
@@ -46,5 +46,5 @@
46
46
  "publishConfig": {
47
47
  "access": "public"
48
48
  },
49
- "gitHead": "edb1abe156385d8be587881f240a305376551472"
49
+ "gitHead": "de7ed3f6665b430872553b8f5b51e4cf51db4066"
50
50
  }