@thulite/images 3.3.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.
@@ -0,0 +1,135 @@
1
+ {{- /* Last modified: 2023-09-04T20:30:30-07:00 */}}
2
+
3
+ {{- /*
4
+ Copyright 2023 Veriphor LLC
5
+
6
+ Licensed under the Apache License, Version 2.0 (the "License"); you may not
7
+ use this file except in compliance with the License. You may obtain a copy of
8
+ the License at
9
+
10
+ https://www.apache.org/licenses/LICENSE-2.0
11
+
12
+ Unless required by applicable law or agreed to in writing, software
13
+ distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
14
+ WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
15
+ License for the specific language governing permissions and limitations under
16
+ the License.
17
+ */}}
18
+
19
+ {{- /*
20
+ Renders an HTML img element, in multiple formats and sizes.
21
+
22
+ It resolves internal destinations by looking for a matching:
23
+
24
+ 1. Page resource (an image in the current page bundle)
25
+ 2. Section resource (an image in the current section)
26
+ 3. Global resource (an image in the assets directory)
27
+
28
+ It skips the section resource lookup if the current page is a leaf bundle, and
29
+ captures external destinations as resources for local hosting. The build will
30
+ fail if this shortcode is unable to resolve a destination.
31
+
32
+ You must place global resources in the assets directory. If you have placed
33
+ your resources in the static directory, and you are unable or unwilling to move
34
+ them, you must mount the static directory to the assets directory by including
35
+ both of these entries in your site configuration:
36
+
37
+ [[module.mounts]]
38
+ source = 'assets'
39
+ target = 'assets'
40
+
41
+ [[module.mounts]]
42
+ source = 'static'
43
+ target = 'assets'
44
+
45
+ Add this CSS to your site to enable responsive image behavior:
46
+
47
+ img {
48
+ height: auto;
49
+ max-width: 100%;
50
+ }
51
+
52
+ Add this CSS to your site to remove small gaps between adjacent elements:
53
+
54
+ img, picture {
55
+ font-size: 0;
56
+ }
57
+
58
+ This shortcode is a wrapper for, and requires, the img partial:
59
+ <https://www.veriphor.com/articles/images-with-overlays/#partial-source-code>
60
+
61
+ @context {string} Inner The content between the opening and closing shortcode tags.
62
+ @context {string} InnerDeindent The content between the opening and closing shortcode tags with indentation removed.
63
+ @context {string} Name The file name of the shortcode template, excluding the extension.
64
+ @context {int} Ordinal The zero-based ordinal of the shortcode on the page, or within its parent shortcode.
65
+ @context {page} Page A reference to the page containing the shortcode.
66
+ @context {map} Params The parameters specified in the opening shortcode tag.
67
+ @context {hugolib.ShortcodeWithPage} Parent The context of the parent shortcode.
68
+ @context {text.Position} Position The position of the shortcode within the page content.
69
+
70
+ @method {any} Get Returns the parameter value for the given key (for named parameters) or position (for positional parameters).
71
+ @mathod {bool} IsNamedParams Returns true if the shortcode is called with named instead of positional parameters.
72
+ @method {maps.Scratch) Scratch Returns a writable Scratch to store and manipulate data.
73
+
74
+ @param {string} [src] The path to the image: a page resource, a global resource, or a remote resource.
75
+ @param {int} [width] The display width of the image, in pixels, falling back to 100% of the viewport width.
76
+ @param {string} [sizes] = "" # "100vw", "75vw", or "auto" for example
77
+ @param {string slice} [formats] A slice of image formats, ordered by precedence, to use when creating images for the srcset attribute of each source element.
78
+ @param {string} [process] = "" # "fill 1600x900" for example
79
+ @param {string} [lqip] = "" # "16x webp q20" or "21x webp q20" for example
80
+ @param {string} [decoding] The img element's decoding attribute.
81
+ @param {string} [fetchpriority] The img element's fetchpriority attribute.
82
+ @param {string} [loading] The img element's loading attribute.
83
+ @param {string} [alt] The img element's alt attribute.
84
+ @param {string} [title] The img element's title attribute.
85
+ @param {string} [class] The img element's class attribute.
86
+
87
+ @returns {template.HTML}
88
+
89
+ @example (required args only)
90
+
91
+ {{< img src="images/zion-national-park.jpg" >}}
92
+
93
+ @example (all args)
94
+
95
+ {{< img
96
+ src="images/bryce-canyon-national-park.jpg"
97
+ width=768
98
+ sizes="75w"
99
+ formats="webp, jpeg"
100
+ process="fill 1600x900"
101
+ lqip="16x webp q20"
102
+ decoding="async"
103
+ fetchpriority="auto"
104
+ loading="eager"
105
+ alt="Bryce Canyon National Park"
106
+ title="A beautiful day in Bryce Canyon National Park"
107
+ class="foo"
108
+ >}}
109
+
110
+ */}}
111
+
112
+ {{- /* Create slices from comma or space separated values. */}}
113
+ {{- $formats := slice }}
114
+ {{- with .Get "formats" }}
115
+ {{- range partial "inline/split.html" . }}
116
+ {{- $formats = $formats | append . }}
117
+ {{- end }}
118
+ {{- end }}
119
+
120
+ {{- /* Build the context to send to the img partial. */}}
121
+ {{- $ctx := merge .Params
122
+ (dict "page" .Page)
123
+ (dict "formats" $formats)
124
+ }}
125
+
126
+ {{- /* Call the img partial. */}}
127
+ {{- partial "img.html" $ctx -}}
128
+
129
+ {{- /* Returns a slice of strings, splitting s by a comma or whitespace. */}}
130
+ {{- define "partials/inline/split.html" }}
131
+ {{- $s := trim . " " }}
132
+ {{- $s = replace $s " " "," }}
133
+ {{- $s := replaceRE `,{2,}` "," $s }}
134
+ {{- return split $s "," }}
135
+ {{- end -}}
@@ -0,0 +1,135 @@
1
+ {{- /* Last modified: 2023-09-04T20:30:30-07:00 */}}
2
+
3
+ {{- /*
4
+ Copyright 2023 Veriphor LLC
5
+
6
+ Licensed under the Apache License, Version 2.0 (the "License"); you may not
7
+ use this file except in compliance with the License. You may obtain a copy of
8
+ the License at
9
+
10
+ https://www.apache.org/licenses/LICENSE-2.0
11
+
12
+ Unless required by applicable law or agreed to in writing, software
13
+ distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
14
+ WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
15
+ License for the specific language governing permissions and limitations under
16
+ the License.
17
+ */}}
18
+
19
+ {{- /*
20
+ Renders an HTML picture element, in multiple formats and sizes.
21
+
22
+ It resolves internal destinations by looking for a matching:
23
+
24
+ 1. Page resource (an image in the current page bundle)
25
+ 2. Section resource (an image in the current section)
26
+ 3. Global resource (an image in the assets directory)
27
+
28
+ It skips the section resource lookup if the current page is a leaf bundle, and
29
+ captures external destinations as resources for local hosting. The build will
30
+ fail if this shortcode is unable to resolve a destination.
31
+
32
+ You must place global resources in the assets directory. If you have placed
33
+ your resources in the static directory, and you are unable or unwilling to move
34
+ them, you must mount the static directory to the assets directory by including
35
+ both of these entries in your site configuration:
36
+
37
+ [[module.mounts]]
38
+ source = 'assets'
39
+ target = 'assets'
40
+
41
+ [[module.mounts]]
42
+ source = 'static'
43
+ target = 'assets'
44
+
45
+ Add this CSS to your site to enable responsive image behavior:
46
+
47
+ img {
48
+ height: auto;
49
+ max-width: 100%;
50
+ }
51
+
52
+ Add this CSS to your site to remove small gaps between adjacent elements:
53
+
54
+ img, picture {
55
+ font-size: 0;
56
+ }
57
+
58
+ This shortcode is a wrapper for, and requires, the picture partial:
59
+ <https://www.veriphor.com/articles/images-with-overlays/#partial-source-code>
60
+
61
+ @context {string} Inner The content between the opening and closing shortcode tags.
62
+ @context {string} InnerDeindent The content between the opening and closing shortcode tags with indentation removed.
63
+ @context {string} Name The file name of the shortcode template, excluding the extension.
64
+ @context {int} Ordinal The zero-based ordinal of the shortcode on the page, or within its parent shortcode.
65
+ @context {page} Page A reference to the page containing the shortcode.
66
+ @context {map} Params The parameters specified in the opening shortcode tag.
67
+ @context {hugolib.ShortcodeWithPage} Parent The context of the parent shortcode.
68
+ @context {text.Position} Position The position of the shortcode within the page content.
69
+
70
+ @method {any} Get Returns the parameter value for the given key (for named parameters) or position (for positional parameters).
71
+ @mathod {bool} IsNamedParams Returns true if the shortcode is called with named instead of positional parameters.
72
+ @method {maps.Scratch) Scratch Returns a writable Scratch to store and manipulate data.
73
+
74
+ @param {string} [src] The path to the image: a page resource, a global resource, or a remote resource.
75
+ @param {int} [width] The display width of the image, in pixels, falling back to 100% of the viewport width.
76
+ @param {string} [sizes] = "" # "100vw", "75vw", or "auto" for example
77
+ @param {string slice} [formats] A slice of image formats, ordered by precedence, to use when creating images for the srcset attribute of each source element.
78
+ @param {string} [process] = "" # "fill 1600x900" for example
79
+ @param {string} [lqip] = "" # "16x webp q20" or "21x webp q20" for example
80
+ @param {string} [decoding] The img element's decoding attribute.
81
+ @param {string} [fetchpriority] The img element's fetchpriority attribute.
82
+ @param {string} [loading] The img element's loading attribute.
83
+ @param {string} [alt] The img element's alt attribute.
84
+ @param {string} [title] The img element's title attribute.
85
+ @param {string} [class] The img element's class attribute.
86
+
87
+ @returns {template.HTML}
88
+
89
+ @example (required args only)
90
+
91
+ {{< picture src="images/zion-national-park.jpg" >}}
92
+
93
+ @example (all args)
94
+
95
+ {{< picture
96
+ src="images/bryce-canyon-national-park.jpg"
97
+ width=768
98
+ sizes="75w"
99
+ formats="webp, jpeg"
100
+ process="fill 1600x900"
101
+ lqip="16x webp q20"
102
+ decoding="async"
103
+ fetchpriority="auto"
104
+ loading="eager"
105
+ alt="Bryce Canyon National Park"
106
+ title="A beautiful day in Bryce Canyon National Park"
107
+ class="foo"
108
+ >}}
109
+
110
+ */}}
111
+
112
+ {{- /* Create slices from comma or space separated values. */}}
113
+ {{- $formats := slice }}
114
+ {{- with .Get "formats" }}
115
+ {{- range partial "inline/split.html" . }}
116
+ {{- $formats = $formats | append . }}
117
+ {{- end }}
118
+ {{- end }}
119
+
120
+ {{- /* Build the context to send to the picture partial. */}}
121
+ {{- $ctx := merge .Params
122
+ (dict "page" .Page)
123
+ (dict "formats" $formats)
124
+ }}
125
+
126
+ {{- /* Call the picture partial. */}}
127
+ {{- partial "picture.html" $ctx -}}
128
+
129
+ {{- /* Returns a slice of strings, splitting s by a comma or whitespace. */}}
130
+ {{- define "partials/inline/split.html" }}
131
+ {{- $s := trim . " " }}
132
+ {{- $s = replace $s " " "," }}
133
+ {{- $s := replaceRE `,{2,}` "," $s }}
134
+ {{- return split $s "," }}
135
+ {{- end -}}
package/package.json ADDED
@@ -0,0 +1,26 @@
1
+ {
2
+ "name": "@thulite/images",
3
+ "version": "3.3.0",
4
+ "description": "Thulite images",
5
+ "author": "Thulite",
6
+ "license": "MIT",
7
+ "repository": {
8
+ "type": "git",
9
+ "url": "https://github.com/thuliteio/images.git"
10
+ },
11
+ "scripts": {
12
+ "format": "prettier **/** -w -c"
13
+ },
14
+ "devDependencies": {
15
+ "@changesets/changelog-github": "^0.5.0",
16
+ "@changesets/cli": "^2.27.7",
17
+ "prettier": "^3.3.3"
18
+ },
19
+ "engines": {
20
+ "node": ">=20.11.0"
21
+ },
22
+ "publishConfig": {
23
+ "access": "public",
24
+ "registry": "https://registry.npmjs.org/"
25
+ }
26
+ }