@parameter1/base-cms-marko-web 3.7.11 → 3.8.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.
@@ -9,11 +9,6 @@ $ const srcset = getAsArray(input.srcset).join(", ") || null;
9
9
  $ const classNames = [input.class];
10
10
  $ if (lazyload) classNames.push("lazyload");
11
11
  $ const attrs = getAsObject(input.attrs);
12
- $ if (input.width && input.width > 0 && !attrs.width && !attrs.height) {
13
- attrs.width = input.width;
14
- const height = input.height || imageHeight(input.width, input.ar) || undefined;
15
- if (height) attrs.height = height;
16
- };
17
12
 
18
13
  <if(lazyload)>
19
14
  <img
@@ -1,26 +1,35 @@
1
- import { buildImgixUrl } from "@parameter1/base-cms-image";
2
- import { get } from "@parameter1/base-cms-object-path";
3
- import imageHeight from "./utils/image-height";
1
+ import { buildImgixUrl, getRelativeAspectRatioHeight, getRelativeAspectRatioWidth } from "@parameter1/base-cms-image";
2
+ import { get, getAsObject } from "@parameter1/base-cms-object-path";
4
3
 
5
4
  $ const element = "node__image";
6
5
  $ const hasImage = Boolean(input.src);
7
6
 
8
- $ const style = [];
9
- $ if (input.width) style.push(`width: ${input.width}px;`);
10
- $ if (input.height) style.push(`height: ${input.height}px;`);
11
- $ 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
+ -->
12
12
 
13
- $ const options = {
14
- fit: get(input, "options.w") && get(input, "options.h") ? "crop" : undefined,
15
- ...input.options,
16
- }
13
+ $ const { width, height } = input;
14
+ $ const options = getAsObject(input, "options");
17
15
 
18
- $ if (options.w) {
19
- attrs.width = options.w;
20
- attrs.height = options.h || (input.ar ? imageHeight(input.width, input.ar) : undefined);
16
+ $ if (width || height) {
17
+ options.w = width || undefined;
18
+ options.h = height || undefined;
21
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;
22
31
 
23
- <!-- @todo add modifiers -->
32
+ $ const attrs = { ...input.attrs, width: options.w, height: options.h };
24
33
 
25
34
  <if(hasImage)>
26
35
  $ const src = buildImgixUrl(input.src, options, input.defaultOptions, input.isLogo);
@@ -32,8 +41,6 @@ $ if (options.w) {
32
41
  attrs=attrs
33
42
  class=[element, input.class]
34
43
  lazyload=input.lazyload
35
- width=input.width
36
- height=input.height
37
44
  />
38
45
  </if>
39
46
  <else-if(input.usePlaceholder)>
@@ -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.11",
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": "ab5824f00f04768be6729f66dfc62fa7b0b09c89"
49
+ "gitHead": "de7ed3f6665b430872553b8f5b51e4cf51db4066"
50
50
  }