├── .editorconfig
├── .github
└── ISSUE_TEMPLATE.md
├── .gitignore
├── .nycrc
├── .travis.yml
├── CHANGELOG.md
├── LICENSE
├── README.md
├── gulpfile.js
├── manual_test
└── index.js
├── package-lock.json
├── package.json
├── saml.html
├── scripts
├── build.js
└── publish.js
├── src
├── adapters
│ ├── DOM.spec.ts
│ └── DOM.ts
├── index.ts
├── tree.spec.ts
├── tree.ts
├── types
│ ├── html-validator
│ │ └── index.d.ts
│ └── hyperx
│ │ └── index.d.ts
├── utils.spec.ts
└── utils.ts
├── test
└── mocha.opts
├── tsconfig.json
├── tsconfig.module.json
├── tslint.json
├── typedoc.js
└── webpack.config.js
/.editorconfig:
--------------------------------------------------------------------------------
1 | root = true
2 |
3 | [{src,scripts,config}/**.{ts,json,js}]
4 | end_of_line = lf
5 | charset = utf-8
6 | quote_type = single
7 | trim_trailing_whitespace = true
8 | insert_final_newline = true
9 | indent_style = space
10 | indent_size = 2
11 |
12 | [*.md]
13 | insert_final_newline = false
14 | trim_trailing_whitespace = false
15 |
--------------------------------------------------------------------------------
/.github/ISSUE_TEMPLATE.md:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 | ## Expected Behavior
5 |
6 |
7 |
8 | ## Current Behavior
9 |
10 |
11 |
12 | ## Possible Solution
13 |
14 |
15 |
16 | ## Steps to Reproduce (for bugs)
17 |
18 |
19 | 1.
20 | 2.
21 | 3.
22 |
23 | ## Additional Screenshots
24 |
25 | 1.
26 | 2.
27 | 3.
28 |
29 | ## Context
30 |
31 |
32 |
33 | ## Your Environment
34 |
35 | * Version used:
36 | * Browser Name and version:
37 | * Operating System and version (desktop or mobile):
38 | * Link to your project:
39 |
--------------------------------------------------------------------------------
/.gitignore:
--------------------------------------------------------------------------------
1 | /build/
2 | /node_modules/
3 | /coverage/
4 | /.nyc_output/
5 | TODO
6 | index.html
7 | /.DS_Store
--------------------------------------------------------------------------------
/.nycrc:
--------------------------------------------------------------------------------
1 | {
2 | "extends": "@istanbuljs/nyc-config-typescript",
3 | "all": true,
4 | "include": "build/main/**/*.js",
5 | "exclude": [
6 | "build/main/index.js",
7 | "build/main/**/*.spec.*"
8 | ],
9 | "check-coverage": true,
10 | "lines": 90,
11 | "statements": 90,
12 | "functions": 90,
13 | "branches": 90,
14 | "reporter": [
15 | "lcov",
16 | "text"
17 | ]
18 | }
19 |
--------------------------------------------------------------------------------
/.travis.yml:
--------------------------------------------------------------------------------
1 | language: node_js
2 | node_js:
3 | - "10"
4 |
--------------------------------------------------------------------------------
/CHANGELOG.md:
--------------------------------------------------------------------------------
1 | # Changelog
2 |
3 | All notable changes to this project will be documented in this file. See [standard-version](https://github.com/conventional-changelog/standard-version) for commit guidelines.
4 |
5 | ## [1.4.0](https://github.com/filestack/adaptive/compare/v1.2.0...v1.4.0) (2020-06-09)
6 |
7 |
8 | ### Features
9 |
10 | * **webcomponent:** add sizes and formats options ([173e119](https://github.com/filestack/adaptive/commit/173e1196a2d97e13308c6a93bcfab052f61719e0))
11 | * **webcomponent:** add support for webcomponent ([00aa3dc](https://github.com/filestack/adaptive/commit/00aa3dc83e97a6463d1735bd7e512a3b1b1793f1))
12 | * **webcomponent:** add support for webcomponent in adaptive ([3c62eda](https://github.com/filestack/adaptive/commit/3c62edaed5e2dcc70700cfcd8b402581297f4572))
13 | * **webcomponent:** add support for webcomponent in adaptive ([74c7f50](https://github.com/filestack/adaptive/commit/74c7f5088af6bb0ebd24eadddb4d575162392498))
14 |
15 | ## [1.3.0](https://github.com/filestack/adaptive/compare/v1.2.0...v1.3.0) (2020-06-08)
16 |
17 |
18 | ### Features
19 |
20 | * **webcomponent:** add support for webcomponent ([00aa3dc](https://github.com/filestack/adaptive/commit/00aa3dc83e97a6463d1735bd7e512a3b1b1793f1))
21 | * **webcomponent:** add support for webcomponent in adaptive ([3c62eda](https://github.com/filestack/adaptive/commit/3c62edaed5e2dcc70700cfcd8b402581297f4572))
22 | * **webcomponent:** add support for webcomponent in adaptive ([74c7f50](https://github.com/filestack/adaptive/commit/74c7f5088af6bb0ebd24eadddb4d575162392498))
23 |
24 | ## 1.1.3 (2020-03-09)
25 | - Merge branch 'master' of github.com:filestack/adaptive
26 | - chore(bump version)
27 | - chore(test fix) (#21)
28 | - chore(dependencies (#20))
29 |
30 | ## 1.1.1 (2019-08-06)
31 | - feat(createFilelink): Always use output task as the first one (#17)
32 |
33 | ## 1.1.0 (2019-06-07)
34 | - chore(package): Add releas-o-tron
35 | - Feature/support cname (#16)
36 |
37 | All notable changes to this project will be documented in this file. See [standard-version](https://github.com/conventional-changelog/standard-version) for commit guidelines.
38 |
39 | ## [1.0.0](https://github.com/filestack/adaptive/compare/v0.2.7...v1.0.0) (2019-05-20)
40 | * Remove Ramda from dependencies
41 | * Add manifest.json with [SRI hash](https://developer.mozilla.org/en-US/docs/Web/Security/Subresource_Integrity)
42 | * Update readme
43 |
44 |
45 | ## [0.2.7](https://github.com/filestack/adaptive/compare/v0.2.6...v0.2.7) (2019-04-08)
46 |
47 | ### Features
48 | * Add posibility to disable a tasks validation (useValdiator option)
49 |
50 | ### Bug Fixes
51 | * Validate params only for the first url in srcset
52 |
53 |
54 | ## [0.2.6](https://github.com/filestack/adaptive/compare/v0.2.5...v0.2.6) (2019-03-28)
55 |
56 |
57 |
58 | ## [0.2.5](https://github.com/filestack/adaptive/compare/v0.2.4...v0.2.5) (2019-03-19)
59 |
60 |
61 | ### Features
62 |
63 | * Use transforms from filestack-js
64 | * Implement support for storage aliases
65 |
66 |
67 |
68 | ## [0.2.4](https://github.com/filestack/adaptive/compare/v0.2.3...v0.2.4) (2019-01-28)
69 |
70 |
71 | ### Bug Fixes
72 |
73 | * **sourcemap:** Fix sourcemap generation ([d55840f](https://github.com/filestack/adaptive/commit/d55840f))
74 |
75 |
76 |
77 |
78 | ## [0.2.3](https://github.com/filestack/adaptive/compare/v0.2.1...v0.2.3) (2018-04-30)
79 |
80 |
81 | ### Bug Fixes
82 |
83 | * bump for npm publish conflict ([cae6521](https://github.com/filestack/adaptive/commit/cae6521))
84 |
85 |
86 |
87 |
88 | ## [0.2.1](https://github.com/filestack/adaptive/compare/v0.2.0...v0.2.1) (2018-04-30)
89 |
90 |
91 | ### Bug Fixes
92 |
93 | * add tslib to production dependencies ([4093cc3](https://github.com/filestack/adaptive/commit/4093cc3))
94 |
95 |
96 |
97 |
98 | # [0.2.0](https://github.com/filestack/adaptive/compare/v0.1.0...v0.2.0) (2018-02-06)
99 |
100 |
101 | ### Features
102 |
103 | * add transform options to picture generator ([aca39f9](https://github.com/filestack/adaptive/commit/aca39f9))
104 |
105 |
106 |
107 |
108 | # 0.1.0 (2017-11-02)
109 |
110 |
111 | ### Bug Fixes
112 |
113 | * change options type on makePictureTree and clean up redundant boolean logic in makeImg ([d8b3667](https://github.com/filestack/adaptive/commit/d8b3667))
114 | * **tree:** remove unfollowed branch in getUnit ([86eaec6](https://github.com/filestack/adaptive/commit/86eaec6))
115 |
--------------------------------------------------------------------------------
/LICENSE:
--------------------------------------------------------------------------------
1 | MIT License
2 |
3 | Copyright (c) 2020 Filestack
4 |
5 | Permission is hereby granted, free of charge, to any person obtaining a copy
6 | of this software and associated documentation files (the "Software"), to deal
7 | in the Software without restriction, including without limitation the rights
8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9 | copies of the Software, and to permit persons to whom the Software is
10 | furnished to do so, subject to the following conditions:
11 |
12 | The above copyright notice and this permission notice shall be included in all
13 | copies or substantial portions of the Software.
14 |
15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21 | SOFTWARE.
22 |
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 | Generate responsive HTML picture elements powered by on-the-fly Filestack image conversions.
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
16 |
17 |
18 |
19 |
20 |
21 |
22 |
23 |
24 |
25 |
26 |
27 |
28 |
29 |
30 |
31 | **Table of Contents**
32 |
33 |
34 | - [What is Adaptive](#what-is-adaptive)
35 | - [Features](#features)
36 | - [Usage](#usage)
37 | - [Browser](#browser)
38 | - [SRI](#sri)
39 | - [Node (react example)](#node-react-example)
40 | - [Use with JSX](#use-with-jsx)
41 | - [Storage aliases and external urls](#storage-aliases-and-external-urls)
42 | - [Image width and pixel density](#image-width-and-pixel-density)
43 | - [Webcomponent](#webcomponent)
44 | - [Using width descriptors](#using-width-descriptors)
45 | - [WebP support](#webp-support)
46 | - [Custom CNAME](#custom-cname)
47 | - [Transformations support](#transformations-support)
48 | - [Disable validator](#disable-validator)
49 | - [Development](#development)
50 | - [Documentation](#documentation)
51 | - [Contributing](#contributing)
52 | - [Future](#future)
53 |
54 | ## What is Adaptive
55 | Adaptive is a tool which allow [Filestack](https://github.com/filestack/filestack-js) users to combine the power of on-the-fly image processing with the latest standard for responsive web images.
56 |
57 |
58 | This library ships with a built-in virtual DOM adapter powered by hyperx, which allows you to simply call `picture(source, options, renderer)`, where renderer can be any DOM builder supported by hyperx (e.g React.createElement). If renderer is not provided then picture will default to returning plain DOM.
59 |
60 |
61 | ### Features
62 | - Focus on usability and performance
63 | - Works with Filestack [handles](https://www.filestack.com/docs/concepts/getting-started/#vocabulary), [storage aliases](https://www.filestack.com/docs/concepts/storage/#storage-aliases) and external urls
64 | - Support for different sizes and formats in srcSet
65 | - Allows you to add some [image transformations](https://www.filestack.com/docs/api/processing/#image-transformations)
66 | - Easily integrable with external virtual DOM renderers
67 |
68 | ## Usage
69 |
70 | ### Browser
71 | You can find the newest version at https://static.filestackapi.com/adaptive/1.4.0/adaptive.min.js
72 |
73 | ```html
74 |
75 |
85 | ```
86 | Output:
87 | ```html
88 |
89 |
108 |
109 | ```
110 | #### SRI
111 | Subresource Integrity (SRI) is a security feature that enables browsers to verify that files they fetch (for example, from a CDN) are delivered without unexpected manipulation. It works by allowing you to provide a cryptographic hash that a fetched file must match
112 |
113 | To obtain sri hashes for adaptive library check manifest.json file on CDN:
114 |
115 | ```
116 | https://static.filestackapi.com/adaptive/{LIBRARY_VERSION}/manifest.json
117 | ```
118 |
119 | ```HTML
120 |
121 | ```
122 |
123 | Where ```{LIBRARY_VERSION}``` is currently used library version and ```{FILE_HASH}``` is one of the hashes from integrity field in manifest.json file
124 |
125 |
126 | ### Node (react example)
127 | ```bash
128 | npm install filestack-adaptive
129 | ```
130 | ```js
131 | import react from 'react';
132 | import reactDOM from 'react-dom';
133 | import { picture } from 'filestack-adaptive';
134 |
135 | // Need to spread children parameter to prevent React key warnings
136 | const createElement = (Component, props, children) => {
137 | return React.createElement(Component, props, ...children);
138 | };
139 |
140 | const options = { alt: 'windsurfer', sizes: { fallback: '100vw' } };
141 | const tree = picture(FILESTACK_HANDLE, options, createElement);
142 | ReactDOM.render(tree, document.body);
143 | ```
144 | #### Use with JSX
145 | In a case of need to create your own `` element you can call **makePictureTree** directly in your JSX
146 | ```js
147 | import React, { Component } from 'react';
148 | import { makePictureTree } from 'filestack-adaptive';
149 |
150 | class Picture extends Component {
151 | renderSources(sources) {
152 | return sources.map((sourceObj) => {
153 | return ;
154 | });
155 | }
156 | renderImage(imageObj) {
157 | return
;
158 | }
159 | render() {
160 | const tree = makePictureTree(this.props.handle, this.props);
161 | return (
162 |
163 | {tree.sources && this.renderSources(tree.sources)}
164 | {this.renderImage(tree.img)}
165 |
166 | );
167 | }
168 | }
169 |
170 | export default Picture;
171 | ```
172 | ### Storage aliases and external urls
173 | You can also use [Filestack storage alias](https://www.filestack.com/docs/concepts/storage/#storage-aliases) or external urls as an image source:
174 | ```html
175 |
176 |
198 | ```
199 | ### Image width and pixel density
200 |
201 | When the image width is known it will generate a srcset for HiDPI screens at 2x. More densities can be specified
202 | by passing an array to the `resolutions` option, e.g. `resolutions: ['1x', '2x', '3x']`.
203 |
204 | ```js
205 | const options = {
206 | alt: 'windsurfer',
207 | width: '768px',
208 | };
209 | picture(FILESTACK_HANDLE, options);
210 | ```
211 |
212 | Output:
213 |
214 | ```html
215 |
216 |
221 |
222 | ```
223 |
224 | ### Webcomponent
225 | Adaptive now supports webcomponent. Supported options: src, width, alt, cname, policy, signature, keys, resolutions
226 | ```HTML
227 |
228 | ```
229 |
230 | Output:
231 |
232 | ```html
233 |
234 |
239 |
240 | ```
241 |
242 | ### Using width descriptors
243 |
244 | You can specify generated widths by using `resolutions`, which takes an array
245 | of numbers or strings (e.g. `540` or `'540w'`).
246 |
247 | ```js
248 | const options = {
249 | alt: 'windsurfer',
250 | sizes: {
251 | '(min-width: 1080px)': '100vw',
252 | fallback: '90vw',
253 | },
254 | resolutions: [540, 1080],
255 | };
256 | picture(FILESTACK_HANDLE, options);
257 | ```
258 |
259 | Output:
260 |
261 | ```html
262 |
263 |
267 |
272 |
273 | ```
274 |
275 | ### WebP support
276 |
277 | WebP can be used when it's supported by the browser. Filestack will take care of the image conversion
278 | and cache it on the delivery network for future requests.
279 |
280 | ```js
281 | const options = {
282 | alt: 'windsurfer',
283 | formats: ['webp', 'jpg'], // order matters!
284 | };
285 | picture(FILESTACK_HANDLE, options);
286 | ```
287 |
288 | Output:
289 |
290 | ```html
291 |
292 |
294 |
296 |
297 |
298 | ```
299 | ### Custom CNAME
300 |
301 | In order to use custom cname for generated file links just use cname option:
302 | ```js
303 | const options = {
304 | cname: 'fs.test123.com'
305 | };
306 | picture(FILESTACK_HANDLE, options);
307 | ```
308 |
309 | Output:
310 | ```html
311 |
312 |
313 |
314 | ```
315 |
316 | ### Transformations support
317 |
318 | Adaptive also supports Filestack transformations.
319 | Available options are listed in doc:
320 |
321 | https://www.filestack.com/docs/image-transformations
322 |
323 | ```js
324 | const options = {
325 | alt: 'windsurfer',
326 | width: 400,
327 | transforms: {
328 | blur: {
329 | amount: 5
330 | },
331 | border: true, // use default options of border transformation
332 | }
333 | };
334 | picture(FILESTACK_HANDLE, options);
335 | ```
336 |
337 | Output:
338 |
339 | ```html
340 |
341 |
342 |
343 |
344 | ```
345 | #### Disable validator
346 | To speed up generating of final output (useful when you have a bunch of images on your site) you can optionally disable validation of transformation params by passing additional prop in options:
347 | ```js
348 | const options = {
349 | ...
350 | useValidator: false,
351 | ...
352 | }
353 | ```
354 |
355 | ## Development
356 | To install and work on Adaptiv locally:
357 | ```bash
358 | git clone git@github.com:filestack/adaptive.git
359 | cd adaptive
360 | npm install
361 | ```
362 | To create build directory:
363 | ```
364 | npm run build
365 | ```
366 | This newly created directory contains
367 | ```text
368 | build/
369 | ├── browser/ # for the UMD module (usable in HTML script tags)
370 | └── index.umd.js #
371 | ├── main/ # for the CommonJS module
372 | ├── ... #
373 | └── index.js #
374 | └── module/ # for the ES Module (suitable for bundlers like Webpack and Rollup)
375 | ├── ... #
376 | └── index.js #
377 | ```
378 |
379 | ## Documentation
380 | For more info about available methods and options check browser documentation:
381 |
382 | https://filestack.github.io/adaptive/
383 |
384 | ## Contributing
385 | We follow the [conventional commits](https://conventionalcommits.org/) specification to ensure consistent commit messages and changelog formatting.
386 |
387 | ## Future
388 | Adaptive is joining an ecosystem already populated with many utilities for responsive images.
389 | We want to remain flexible while still having some opinions on how to implement picture elements using Filestack conversions, and we know it is hard to
390 | cover every use case. Contributions and ideas are welcome that would help improve the usefulness of this library.
391 |
392 | Current ideas:
393 |
394 | * LQIP using the Filestack blur transformation
395 | * Compress HiDPI images using Filestack compress task
396 | * Implement art direction with Filestack crop
397 | * Develop a PostHTML transform for post-processing HTML using `makePictureTree`
398 |
--------------------------------------------------------------------------------
/gulpfile.js:
--------------------------------------------------------------------------------
1 | require('./scripts/build');
2 |
--------------------------------------------------------------------------------
/manual_test/index.js:
--------------------------------------------------------------------------------
1 | // const options = {
2 | // alt: 'windsurfer',
3 | // sizes: {
4 | // fallback: '60vw',
5 | // }
6 | // };
7 |
8 | // const el = fsAdaptive.picture('test', options);
9 |
10 | // document.body.appendChild(el);
11 |
--------------------------------------------------------------------------------
/package.json:
--------------------------------------------------------------------------------
1 | {
2 | "name": "filestack-adaptive",
3 | "author": "Filestack (https://filestack.com)",
4 | "version": "1.4.0",
5 | "description": "HTML5 picture elements powered by Filestack",
6 | "main": "build/main/index.js",
7 | "module": "build/module/index.js",
8 | "browser": "build/browser/index.umd.js",
9 | "typings": "build/main/index.d.ts",
10 | "repository": "https://github.com/filestack/adaptive",
11 | "scripts": {
12 | "build": "npx gulp build:typescript && npm run webpack",
13 | "build:main": "npx gulp typescript:main",
14 | "build:module": "npx gulp typescript:module",
15 | "webpack": "npx gulp build:webpack",
16 | "dev:watch": "rollup -c config/watch.config.js",
17 | "docs": "rm -rf build/docs && typedoc src",
18 | "docs:publish": "npm run docs && gh-pages -d build/docs",
19 | "lint": "tslint --project .",
20 | "publish": "npm run build && node scripts/publish.js && npm run docs:publish",
21 | "pretest": "rm -rf build && npm run build",
22 | "release": "npx standard-version",
23 | "test": "npm run lint && nyc mocha"
24 | },
25 | "license": "MIT",
26 | "keywords": [
27 | "filestack",
28 | "responsive images",
29 | "adaptive images",
30 | "picture",
31 | "pictures",
32 | "react",
33 | "ssr",
34 | "mobile web",
35 | "html5",
36 | "html picture"
37 | ],
38 | "dependencies": {
39 | "filestack-js": "^3.15.0",
40 | "hyperx": "^2.5.4",
41 | "lit-element": "^2.3.1",
42 | "nanohtml": "^1.9.1",
43 | "tslib": "^1.13.0"
44 | },
45 | "devDependencies": {
46 | "@babel/core": "^7.10.2",
47 | "@babel/plugin-transform-runtime": "^7.8.3",
48 | "@babel/preset-env": "^7.10.2",
49 | "@istanbuljs/nyc-config-typescript": "^1.0.1",
50 | "@purtuga/esm-webpack-plugin": "^1.2.1",
51 | "@types/mocha": "^7.0.2",
52 | "@types/node": "^13.13.9",
53 | "aws-sdk": "^2.689.0",
54 | "babel-loader": "^8.1.0",
55 | "babel-plugin-minify-dead-code-elimination": "^0.5.1",
56 | "clean-webpack-plugin": "^3.0.0",
57 | "commitizen": "^4.1.2",
58 | "cz-conventional-changelog": "^3.2.0",
59 | "del": "^5.1.0",
60 | "dotenv": "^8.2.0",
61 | "envify": "^4.1.0",
62 | "fs-jetpack": "^2.4.0",
63 | "gh-pages": "^2.2.0",
64 | "gulp": "^4.0.2",
65 | "gulp-gzip": "^1.4.2",
66 | "gulp-rename": "^2.0.0",
67 | "gulp-replace": "^1.0.0",
68 | "gulp-sourcemaps": "^2.6.5",
69 | "gulp-typescript": "^5.0.1",
70 | "html-validator": "^5.1.14",
71 | "lodash.merge": "^4.6.2",
72 | "mime-types": "^2.1.27",
73 | "mocha": "^7.2.0",
74 | "nyc": "^15.1.0",
75 | "standard-version": "^8.0.0",
76 | "tslint": "^6.1.2",
77 | "tslint-config-semistandard": "^8.0.1",
78 | "typedoc": "^0.17.7",
79 | "typescript": "^3.9.3",
80 | "validate-commit-msg": "^2.14.0",
81 | "webpack": "^4.41.5",
82 | "webpack-assets-manifest": "^3.1.1",
83 | "webpack-bundle-analyzer": "^3.6.1",
84 | "webpack-cli": "^3.3.10",
85 | "webpack-node-externals": "^1.7.2",
86 | "webpack-stream": "^5.2.1",
87 | "webpack-subresource-integrity": "^1.4.0"
88 | },
89 | "config": {
90 | "commitizen": {
91 | "path": "node_modules/cz-conventional-changelog"
92 | },
93 | "validate-commit-msg": {
94 | "types": "conventional-commit-types",
95 | "helpMessage": "Use \"git cz\" or conventional-changelog format :) (https://github.com/commitizen/cz-cli)"
96 | }
97 | }
98 | }
99 |
--------------------------------------------------------------------------------
/saml.html:
--------------------------------------------------------------------------------
1 | Google Accounts2-Step Verification
This extra step shows it’s really you trying to sign in