├── .vscode └── settings.json ├── .gitignore ├── src ├── static │ ├── images │ │ ├── io-logo.png │ │ ├── icons │ │ │ └── 512.png │ │ ├── items │ │ │ ├── web.dev.jpg │ │ │ ├── lighthouse.jpg │ │ │ └── squoosh.app.jpg │ │ ├── onboarding │ │ │ ├── step-1.jpg │ │ │ ├── step-2.jpg │ │ │ ├── step-3.jpg │ │ │ └── step-4.jpg │ │ ├── baseline-code-24px.svg │ │ ├── baseline-person-24px.svg │ │ ├── baseline-slideshow-24px.svg │ │ ├── baseline-launch-24px.svg │ │ ├── baseline-link-24px.svg │ │ ├── baseline-delete_forever-24px.svg │ │ └── baseline-share-24px.svg │ └── manifest.json ├── details │ ├── index.md │ ├── rotavo │ │ └── index.md │ ├── squoosh.app │ │ └── index.md │ ├── web.dev │ │ └── index.md │ ├── lighthouse │ │ └── index.md │ └── details.ts ├── list │ ├── index.md │ └── list.ts ├── capture │ ├── index.md │ └── capture.ts ├── settings │ ├── index.md │ └── settings.ts ├── sitemap.md ├── sw │ ├── tsconfig.json │ ├── cache-manifest.ts │ └── sw.ts ├── index.md ├── _includes │ ├── settings │ │ └── settings.css │ ├── index.css │ ├── app.css │ ├── capture │ │ └── capture.css │ ├── list │ │ └── list.css │ ├── details │ │ └── details.css │ └── app.njk ├── defs │ └── scanned-item.ts ├── index.ts ├── scripts │ ├── components │ │ ├── detail-panel │ │ │ ├── detail-panel.ts │ │ │ └── detail-panel.template.ts │ │ └── app-header │ │ │ ├── app-header.ts │ │ │ └── app-header.template.ts │ ├── utils │ │ ├── fire.ts │ │ ├── clamp.ts │ │ ├── double-raf.ts │ │ ├── inject-script.ts │ │ ├── load-document.ts │ │ └── fade.ts │ ├── section.ts │ ├── store.ts │ ├── app.ts │ └── router.ts └── _data │ └── env.js ├── README.md ├── tsconfig.json ├── tslint.json ├── rollup.sw.config.js ├── .eleventy.js ├── package.json ├── generate └── index.html ├── rollup.config.js └── LICENSE /.vscode/settings.json: -------------------------------------------------------------------------------- 1 | { 2 | "typescript.tsdk": "node_modules/typescript/lib" 3 | } -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | .DS_Store 2 | node_modules 3 | dist 4 | .rpt2_cache 5 | bundled 6 | *.swp 7 | -------------------------------------------------------------------------------- /src/static/images/io-logo.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/GoogleChromeLabs/perception-toolkit-io-pwa/HEAD/src/static/images/io-logo.png -------------------------------------------------------------------------------- /src/static/images/icons/512.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/GoogleChromeLabs/perception-toolkit-io-pwa/HEAD/src/static/images/icons/512.png -------------------------------------------------------------------------------- /src/static/images/items/web.dev.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/GoogleChromeLabs/perception-toolkit-io-pwa/HEAD/src/static/images/items/web.dev.jpg -------------------------------------------------------------------------------- /src/static/images/items/lighthouse.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/GoogleChromeLabs/perception-toolkit-io-pwa/HEAD/src/static/images/items/lighthouse.jpg -------------------------------------------------------------------------------- /src/static/images/items/squoosh.app.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/GoogleChromeLabs/perception-toolkit-io-pwa/HEAD/src/static/images/items/squoosh.app.jpg -------------------------------------------------------------------------------- /src/static/images/onboarding/step-1.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/GoogleChromeLabs/perception-toolkit-io-pwa/HEAD/src/static/images/onboarding/step-1.jpg -------------------------------------------------------------------------------- /src/static/images/onboarding/step-2.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/GoogleChromeLabs/perception-toolkit-io-pwa/HEAD/src/static/images/onboarding/step-2.jpg -------------------------------------------------------------------------------- /src/static/images/onboarding/step-3.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/GoogleChromeLabs/perception-toolkit-io-pwa/HEAD/src/static/images/onboarding/step-3.jpg -------------------------------------------------------------------------------- /src/static/images/onboarding/step-4.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/GoogleChromeLabs/perception-toolkit-io-pwa/HEAD/src/static/images/onboarding/step-4.jpg -------------------------------------------------------------------------------- /src/details/index.md: -------------------------------------------------------------------------------- 1 | --- 2 | layout: app.njk 3 | title: Details 4 | expanded: true 5 | header_text_color: '#252324' 6 | header_background_color: '#FBBC06' 7 | --- 8 | -------------------------------------------------------------------------------- /src/list/index.md: -------------------------------------------------------------------------------- 1 | --- 2 | layout: app.njk 3 | title: 'Your scanned items' 4 | header_text_color: '#252324' 5 | header_background_color: '#FBBC06' 6 | styles: 'list/list.css' 7 | --- 8 | -------------------------------------------------------------------------------- /src/capture/index.md: -------------------------------------------------------------------------------- 1 | --- 2 | layout: app.njk 3 | title: 'Scan a new item' 4 | header_text_color: '#252324' 5 | header_background_color: '#FBBC06' 6 | styles: 'capture/capture.css' 7 | --- 8 | 9 |
10 | -------------------------------------------------------------------------------- /src/settings/index.md: -------------------------------------------------------------------------------- 1 | --- 2 | layout: app.njk 3 | title: Settings 4 | header_background_color: '#AAA' 5 | header_text_color: '#444' 6 | styles: 'settings/settings.css' 7 | --- 8 | 9 | 10 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # Perception Toolkit I/O Sandbox PWA 2 | 3 | This demonstrates the use of the [Web Perception 4 | Toolkit](https://github.com/GoogleChromeLabs), by delivering an enhanced I/O 5 | Sandbox experience. 6 | 7 | Try it out at https://io.perceptiontoolkit.dev/! 8 | -------------------------------------------------------------------------------- /src/static/images/baseline-code-24px.svg: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /src/static/images/baseline-person-24px.svg: -------------------------------------------------------------------------------- 1 | 2 | -------------------------------------------------------------------------------- /src/static/images/baseline-slideshow-24px.svg: -------------------------------------------------------------------------------- 1 | 2 | -------------------------------------------------------------------------------- /src/static/images/baseline-launch-24px.svg: -------------------------------------------------------------------------------- 1 | 2 | -------------------------------------------------------------------------------- /src/static/images/baseline-link-24px.svg: -------------------------------------------------------------------------------- 1 | 2 | -------------------------------------------------------------------------------- /src/static/manifest.json: -------------------------------------------------------------------------------- 1 | { 2 | "short_name": "Sandbox", 3 | "name": "Google I/O Sandbox Scanner", 4 | "start_url": "/", 5 | "display": "standalone", 6 | "background_color": "#FFF", 7 | "theme_color": "#333", 8 | "orientation": "portrait", 9 | "icons": [ 10 | { 11 | "src": "/static/images/icons/512.png", 12 | "type": "image/png", 13 | "sizes": "512x512" 14 | } 15 | ] 16 | } 17 | -------------------------------------------------------------------------------- /src/sitemap.md: -------------------------------------------------------------------------------- 1 | --- 2 | permalink: '/sitemap.xml' 3 | --- 4 | 5 | 6 | {% for item in collections.all %} 7 | {% if item.url != "/sitemap.xml" %} 8 | 9 | {{ env.origin }}{{ item.url }} 10 | {{ env.buildDate }} 11 | 12 | {% endif %} 13 | {% endfor %} 14 | 15 | -------------------------------------------------------------------------------- /tsconfig.json: -------------------------------------------------------------------------------- 1 | { 2 | "compileOnSave": false, 3 | "compilerOptions": { 4 | "strict": true, 5 | "target": "esnext", 6 | "module": "esnext", 7 | "lib": [ 8 | "dom", 9 | "esnext" 10 | ], 11 | "moduleResolution": "node", 12 | "experimentalDecorators": true, 13 | "noUnusedLocals": true, 14 | "sourceMap": true, 15 | "allowJs": false, 16 | "baseUrl": "." 17 | } 18 | } 19 | -------------------------------------------------------------------------------- /src/static/images/baseline-delete_forever-24px.svg: -------------------------------------------------------------------------------- 1 | 2 | -------------------------------------------------------------------------------- /src/sw/tsconfig.json: -------------------------------------------------------------------------------- 1 | { 2 | "compileOnSave": false, 3 | "compilerOptions": { 4 | "strict": true, 5 | "target": "esnext", 6 | "module": "esnext", 7 | "lib": [ 8 | "webworker", 9 | "esnext" 10 | ], 11 | "moduleResolution": "node", 12 | "experimentalDecorators": true, 13 | "noUnusedLocals": true, 14 | "sourceMap": true, 15 | "allowJs": false, 16 | "baseUrl": "." 17 | } 18 | } 19 | -------------------------------------------------------------------------------- /src/static/images/baseline-share-24px.svg: -------------------------------------------------------------------------------- 1 | 2 | -------------------------------------------------------------------------------- /src/index.md: -------------------------------------------------------------------------------- 1 | --- 2 | layout: app.njk 3 | title: Welcome 4 | header_background_color: '#4385F4' 5 | header_text_color: '#FFFFFF' 6 | styles: 'index.css' 7 | --- 8 | 9 | ![I/O Logo](/static/images/io-logo.png) 10 | 11 | # Sandbox Scanner 12 | 13 | Welcome to the Google I/O Web Sandbox PWA. You can use this app to scan QR codes, barcodes, and images from around the sandbox area. Each item will be kept in a list of scanned items. 14 | 15 | Start scanning 16 | See your previously scanned items 17 | -------------------------------------------------------------------------------- /tslint.json: -------------------------------------------------------------------------------- 1 | { 2 | "defaultSeverity": "error", 3 | "extends": ["tslint:recommended"], 4 | "jsRules": { 5 | "trailing-comma": false 6 | }, 7 | "rules": { 8 | "quotemark": [true, "single"], 9 | "interface-name": [true, "never-prefix"], 10 | "no-console": false, 11 | "no-shadowed-variable": false, 12 | "arrow-parens": false, 13 | "trailing-comma": false, 14 | "member-access": [true, "no-public"], 15 | "callable-types": false, 16 | "only-arrow-functions": false, 17 | "no-bitwise": false, 18 | "max-classes-per-file": false 19 | }, 20 | "rulesDirectory": [], 21 | "linterOptions": { 22 | "exclude": ["./**/node_modules/**"] 23 | } 24 | } 25 | -------------------------------------------------------------------------------- /src/_includes/settings/settings.css: -------------------------------------------------------------------------------- 1 | /** 2 | * @license 3 | * Copyright 2019 Google LLC 4 | * 5 | * Licensed under the Apache License, Version 2.0 (the "License"); 6 | * you may not use this file except in compliance with the License. 7 | * You may obtain a copy of the License at 8 | * 9 | * https://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | 18 | main { 19 | display: flex; 20 | justify-content: center; 21 | align-items: center; 22 | } 23 | -------------------------------------------------------------------------------- /src/defs/scanned-item.ts: -------------------------------------------------------------------------------- 1 | /** 2 | * @license 3 | * Copyright 2019 Google LLC 4 | * 5 | * Licensed under the Apache License, Version 2.0 (the "License"); 6 | * you may not use this file except in compliance with the License. 7 | * You may obtain a copy of the License at 8 | * 9 | * https://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | 18 | export interface ScannedItem { 19 | '@type': string; 20 | name: string; 21 | image: string; 22 | description: string; 23 | url: string; 24 | scanned: number; 25 | mainEntity?: { 26 | url: string; 27 | }; 28 | } 29 | -------------------------------------------------------------------------------- /src/details/rotavo/index.md: -------------------------------------------------------------------------------- 1 | --- 2 | layout: app.njk 3 | title: 'Rotavo' 4 | description: 'Sketchy app' 5 | image: '/static/images/items/lighthouse.jpg' 6 | expanded: true 7 | header_text_color: '#252324' 8 | header_background_color: '#FBBC06' 9 | styles: 'details/details.css' 10 | target: true 11 | target_url: 'https://developers.google.com/web/tools/lighthouse' 12 | --- 13 | 14 |
15 |
16 |

{{ title }}

17 |

{{ description }}

18 |
19 | 20 | ![{{ title }}]({{ image }}) 21 |
22 | 23 |
24 |
25 | 26 | 27 |
28 | 29 |
Rotavo info
30 | 31 | 34 |
35 | -------------------------------------------------------------------------------- /src/index.ts: -------------------------------------------------------------------------------- 1 | /** 2 | * @license 3 | * Copyright 2019 Google LLC 4 | * 5 | * Licensed under the Apache License, Version 2.0 (the "License"); 6 | * you may not use this file except in compliance with the License. 7 | * You may obtain a copy of the License at 8 | * 9 | * https://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | 18 | import { Section } from './scripts/section.js'; 19 | 20 | class Welcome extends Section { 21 | async setup(parts?: string[]) { 22 | // Nothing. 23 | } 24 | 25 | async teardown() { 26 | // Nothing. 27 | } 28 | } 29 | 30 | export const toRemove = 'bar'; 31 | export default new Welcome(); 32 | -------------------------------------------------------------------------------- /src/scripts/components/detail-panel/detail-panel.ts: -------------------------------------------------------------------------------- 1 | /** 2 | * @license 3 | * Copyright 2019 Google LLC 4 | * 5 | * Licensed under the Apache License, Version 2.0 (the "License"); 6 | * you may not use this file except in compliance with the License. 7 | * You may obtain a copy of the License at 8 | * 9 | * https://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | 18 | import { html, styles } from './detail-panel.template.js'; 19 | 20 | export class DetailPanel extends HTMLElement { 21 | private readonly root = this.attachShadow({mode: 'open'}); 22 | 23 | constructor() { 24 | super(); 25 | 26 | this.root.innerHTML = `${html}`; 27 | } 28 | } 29 | -------------------------------------------------------------------------------- /src/scripts/utils/fire.ts: -------------------------------------------------------------------------------- 1 | /** 2 | * @license 3 | * Copyright 2019 Google LLC 4 | * 5 | * Licensed under the Apache License, Version 2.0 (the "License"); 6 | * you may not use this file except in compliance with the License. 7 | * You may obtain a copy of the License at 8 | * 9 | * https://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | 18 | /** 19 | * A convenience function for firing custom events. 20 | * 21 | * ```javascript 22 | * fire('eventname', someElement, {foo: 'bar'}); 23 | * ``` 24 | */ 25 | export function fire(name: string, target: HTMLElement | Window, detail?: {}) { 26 | const evt = new CustomEvent(name, { bubbles: true, detail }); 27 | target.dispatchEvent(evt); 28 | } 29 | -------------------------------------------------------------------------------- /src/scripts/utils/clamp.ts: -------------------------------------------------------------------------------- 1 | /** 2 | * @license 3 | * Copyright 2019 Google LLC 4 | * 5 | * Licensed under the Apache License, Version 2.0 (the "License"); 6 | * you may not use this file except in compliance with the License. 7 | * You may obtain a copy of the License at 8 | * 9 | * https://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | 18 | /** 19 | * Clamps a number between `min` and `max` values. Both `min` and `max` are 20 | * optional. 21 | * 22 | * ```javascript 23 | * clamp(100, 0, 40); // 40. 24 | * ``` 25 | */ 26 | export function clamp(value: number, 27 | min = Number.NEGATIVE_INFINITY, 28 | max = Number.POSITIVE_INFINITY) { 29 | return Math.max(min, Math.min(max, value)); 30 | } 31 | -------------------------------------------------------------------------------- /src/scripts/components/detail-panel/detail-panel.template.ts: -------------------------------------------------------------------------------- 1 | /** 2 | * @license 3 | * Copyright 2019 Google LLC 4 | * 5 | * Licensed under the Apache License, Version 2.0 (the "License"); 6 | * you may not use this file except in compliance with the License. 7 | * You may obtain a copy of the License at 8 | * 9 | * https://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | 18 | export const html = ` 19 |
20 | 21 |
22 | `; 23 | 24 | export const styles = ` 25 | :host { 26 | display: block; 27 | width: 90%; 28 | height: 100%; 29 | margin: 0 auto; 30 | background: #FFF; 31 | border-radius: 20px 20px 0 0; 32 | box-shadow: 0 2px 1px rgba(0, 0, 0, 0.2); 33 | box-sizing: border-box; 34 | padding: 20px; 35 | } 36 | `; 37 | -------------------------------------------------------------------------------- /rollup.sw.config.js: -------------------------------------------------------------------------------- 1 | /** 2 | * @license 3 | * Copyright (c) 2019 The Polymer Project Authors. All rights reserved. 4 | * This code may only be used under the BSD style license found at http://polymer.github.io/LICENSE.txt 5 | * The complete set of authors may be found at http://polymer.github.io/AUTHORS.txt 6 | * The complete set of contributors may be found at http://polymer.github.io/CONTRIBUTORS.txt 7 | * Code distributed by Google as part of the polymer project is also 8 | * subject to an additional IP rights grant found at http://polymer.github.io/PATENTS.txt 9 | */ 10 | 11 | import typescript from 'rollup-plugin-typescript2'; 12 | import replace from 'rollup-plugin-replace'; 13 | 14 | const VERSION = require('./package.json').version; 15 | 16 | export default [{ 17 | input: [ 18 | 'src/sw/sw.ts', 19 | ], 20 | plugins: [ 21 | typescript({ 22 | tsconfig: "./src/sw/tsconfig.json" 23 | }), 24 | replace({ 25 | delimiters: ['{@', '@}'], 26 | values: { 27 | VERSION 28 | } 29 | }) 30 | ], 31 | output: { 32 | format: 'esm', 33 | file: 'dist/sw.js' 34 | } 35 | }]; 36 | -------------------------------------------------------------------------------- /src/scripts/utils/double-raf.ts: -------------------------------------------------------------------------------- 1 | /** 2 | * @license 3 | * Copyright 2019 Google LLC 4 | * 5 | * Licensed under the Apache License, Version 2.0 (the "License"); 6 | * you may not use this file except in compliance with the License. 7 | * You may obtain a copy of the License at 8 | * 9 | * https://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | 18 | /** 19 | * Convert a double requestAnimationFrame to a Promise. This is primarily used 20 | * when you want to be confident that rendering changes will have taken hold. 21 | * 22 | * ``` 23 | * await doubleRaf(); // Two frame wait. 24 | * ``` 25 | */ 26 | export function doubleRaf(): Promise { 27 | return new Promise((resolve) => { 28 | requestAnimationFrame(() => { 29 | requestAnimationFrame(() => resolve()); 30 | }); 31 | }); 32 | } 33 | -------------------------------------------------------------------------------- /src/details/squoosh.app/index.md: -------------------------------------------------------------------------------- 1 | --- 2 | layout: app.njk 3 | title: 'Squoosh.app' 4 | description: 'Image Compression Made Easy' 5 | image: '/static/images/items/squoosh.app.jpg' 6 | expanded: true 7 | header_text_color: '#252324' 8 | header_background_color: '#FBBC06' 9 | styles: 'details/details.css' 10 | target: true 11 | target_url: 'https://squoosh.app' 12 | --- 13 | 14 |
15 |
16 |

{{ title }}

17 |

{{ description }}

18 |
19 | 20 | ![Squoosh.app]({{ image }}) 21 |
22 | 23 |
24 |
25 | 26 | 27 |
28 | 29 |
Squoosh is a powerful image compression tool that launches almost instantly, and then manages a smooth UI even when it’s doing heavy work, including using Web Assembly to do more with codecs the browser doesn’t have baked in.
30 | 31 | 35 |
36 | -------------------------------------------------------------------------------- /src/scripts/utils/inject-script.ts: -------------------------------------------------------------------------------- 1 | /** 2 | * @license 3 | * Copyright 2019 Google LLC 4 | * 5 | * Licensed under the Apache License, Version 2.0 (the "License"); 6 | * you may not use this file except in compliance with the License. 7 | * You may obtain a copy of the License at 8 | * 9 | * https://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | 18 | /** 19 | * A convenience function for injecting scripts into the document head. The 20 | * `Promise` will either `resolve` (successful load) or `reject` (script error). 21 | * 22 | * ```javascript 23 | * await injectScript('/path/to/some/javascript.js'); 24 | * ``` 25 | */ 26 | export function injectScript(src: string) { 27 | return new Promise((resolve, reject) => { 28 | const script = document.createElement('script'); 29 | script.src = src; 30 | script.onload = resolve; 31 | script.onerror = reject; 32 | document.head.appendChild(script); 33 | }); 34 | } 35 | -------------------------------------------------------------------------------- /src/details/web.dev/index.md: -------------------------------------------------------------------------------- 1 | --- 2 | layout: app.njk 3 | title: 'web.dev' 4 | description: 'Powered by Lighthouse' 5 | image: '/static/images/items/web.dev.jpg' 6 | expanded: true 7 | header_text_color: '#252324' 8 | header_background_color: '#FBBC06' 9 | styles: 'details/details.css' 10 | target: true 11 | target_url: 'https://web.dev/' 12 | --- 13 | 14 |
15 |
16 |

{{ title }}

17 |

{{ description }}

18 |
19 | 20 | ![{{ title }}]({{ image }}) 21 |
22 | 23 |
24 |
25 | 26 | 27 |
28 | 29 |
30 |

Whether you already have a website or you're just getting started, learn to build for the modern web at web.dev, powered by Lighthouse, our automated web page audit tool.

31 |

After you've launched your site, come back to web.dev and measure how well it supports your users. If there are areas where it can improve, you'll get immediate steps to increase your metrics.

32 |
33 | 34 | 37 |
38 | -------------------------------------------------------------------------------- /src/_data/env.js: -------------------------------------------------------------------------------- 1 | /** 2 | * @license 3 | * Copyright 2019 Google LLC 4 | * 5 | * Licensed under the Apache License, Version 2.0 (the "License"); 6 | * you may not use this file except in compliance with the License. 7 | * You may obtain a copy of the License at 8 | * 9 | * https://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | 18 | function buildDate() { 19 | const d = new Date(); 20 | const pad = (n) => n.toString().padStart(2, '0'); 21 | 22 | const yy = pad(d.getFullYear()); 23 | const mm = pad(d.getMonth() + 1); 24 | const dd = pad(d.getDate()); 25 | const hh = pad(d.getUTCHours()); 26 | const mn = pad(d.getUTCMinutes()); 27 | const ss = pad(d.getUTCSeconds()); 28 | 29 | return `${yy}-${mm}-${dd}T${hh}:${mn}:${ss}`; 30 | } 31 | 32 | const { version } = require('../../package.json'); 33 | 34 | module.exports = { 35 | origin: process.env.ELEVENTY_ENV === 'development' ? 36 | 'http://localhost:8080' : 'http://io-web-sandbox.firebaseapp.com', 37 | buildDate: buildDate(), 38 | version 39 | }; 40 | -------------------------------------------------------------------------------- /src/details/lighthouse/index.md: -------------------------------------------------------------------------------- 1 | --- 2 | layout: app.njk 3 | title: 'Lighthouse' 4 | description: 'Test your website' 5 | image: '/static/images/items/lighthouse.jpg' 6 | expanded: true 7 | header_text_color: '#252324' 8 | header_background_color: '#FBBC06' 9 | styles: 'details/details.css' 10 | target: true 11 | target_url: 'https://developers.google.com/web/tools/lighthouse' 12 | --- 13 | 14 |
15 |
16 |

{{ title }}

17 |

{{ description }}

18 |
19 | 20 | ![{{ title }}]({{ image }}) 21 |
22 | 23 |
24 |
25 | 26 | 27 |
28 | 29 |
Lighthouse is an open-source, automated tool for improving the quality of web pages. You can run it against any web page, public or requiring authentication. It has audits for performance, accessibility, progressive web apps, and more.
30 | 31 | 36 |
37 | -------------------------------------------------------------------------------- /.eleventy.js: -------------------------------------------------------------------------------- 1 | /** 2 | * @license 3 | * Copyright (c) 2019 The Polymer Project Authors. All rights reserved. 4 | * This code may only be used under the BSD style license found at http://polymer.github.io/LICENSE.txt 5 | * The complete set of authors may be found at http://polymer.github.io/AUTHORS.txt 6 | * The complete set of contributors may be found at http://polymer.github.io/CONTRIBUTORS.txt 7 | * Code distributed by Google as part of the polymer project is also 8 | * subject to an additional IP rights grant found at http://polymer.github.io/PATENTS.txt 9 | */ 10 | 11 | const CleanCSS = require('clean-css'); 12 | 13 | module.exports = function(eleventyConfig) { 14 | eleventyConfig.setTemplateFormats('md,js,json'); 15 | eleventyConfig.addFilter('cssmin', (code) => { 16 | return new CleanCSS({}).minify(code).styles; 17 | }); 18 | 19 | eleventyConfig.addPassthroughCopy( 20 | 'node_modules/@webcomponents/webcomponentsjs/webcomponents-loader.js'); 21 | eleventyConfig.addPassthroughCopy( 22 | 'node_modules/perception-toolkit/lib'); 23 | eleventyConfig.addPassthroughCopy( 24 | 'node_modules/perception-toolkit/third_party'); 25 | eleventyConfig.addPassthroughCopy( 26 | 'node_modules/idb-keyval/dist/idb-keyval-iife.min.js'); 27 | eleventyConfig.addPassthroughCopy('src/static'); 28 | eleventyConfig.addPassthroughCopy('bundled'); 29 | 30 | return { 31 | passthroughFileCopy: true 32 | }; 33 | } 34 | -------------------------------------------------------------------------------- /src/scripts/components/app-header/app-header.ts: -------------------------------------------------------------------------------- 1 | /** 2 | * @license 3 | * Copyright 2019 Google LLC 4 | * 5 | * Licensed under the Apache License, Version 2.0 (the "License"); 6 | * you may not use this file except in compliance with the License. 7 | * You may obtain a copy of the License at 8 | * 9 | * https://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | 18 | import * as Router from '../../router.js'; 19 | import { fire } from '../../utils/fire.js'; 20 | import { html, styles } from './app-header.template.js'; 21 | export class AppHeader extends HTMLElement { 22 | private readonly root = this.attachShadow({mode: 'open'}); 23 | 24 | constructor() { 25 | super(); 26 | 27 | this.root.innerHTML = `${html}`; 28 | 29 | this.root.addEventListener('transitionend', () => { 30 | fire('animationcomplete', this); 31 | }); 32 | 33 | this.root.addEventListener('click', (evt) => { 34 | const target = evt.target as HTMLAnchorElement; 35 | if (target.tagName !== 'A') { 36 | return; 37 | } 38 | 39 | evt.preventDefault(); 40 | Router.go(target.href); 41 | }); 42 | } 43 | 44 | connectedCallback() { 45 | this.classList.add('visible'); 46 | } 47 | } 48 | -------------------------------------------------------------------------------- /src/scripts/utils/load-document.ts: -------------------------------------------------------------------------------- 1 | /** 2 | * @license 3 | * Copyright 2019 Google LLC 4 | * 5 | * Licensed under the Apache License, Version 2.0 (the "License"); 6 | * you may not use this file except in compliance with the License. 7 | * You may obtain a copy of the License at 8 | * 9 | * https://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | 18 | export interface LoadedDocument { 19 | main: HTMLElement; 20 | header: HTMLElement; 21 | styles?: HTMLStyleElement; 22 | } 23 | 24 | export async function loadDocument(url: Location): Promise { 25 | const response = await fetch(url.href); 26 | const content = await response.text(); 27 | 28 | const parser = new DOMParser(); 29 | const document = parser.parseFromString(content, 'text/html'); 30 | if (document.querySelector('parsererror')) { 31 | throw new Error(`Unable to load: ${url.href}`); 32 | } 33 | 34 | const main = document.querySelector('main') as HTMLElement; 35 | const header = document.querySelector('app-header') as HTMLElement; 36 | const styles = 37 | document.head.querySelector('style[custom]') as HTMLStyleElement; 38 | if (!main || !header) { 39 | throw new Error(`${url.href} has no
or `); 40 | } 41 | 42 | return { main, header, styles }; 43 | } 44 | -------------------------------------------------------------------------------- /package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "perception-toolkit-io-pwa", 3 | "version": "0.0.1", 4 | "description": "Perception Toolkit IO PWA", 5 | "main": "dist/index.html", 6 | "scripts": { 7 | "install": "napa", 8 | "build": "rollup -c && ELEVENTY_ENV=development eleventy --input=src --output=dist && npm run build-cache-manifest && npm run sw && npm run gzip && npm run sitemap", 9 | "build-cache-manifest": "node build/generate.js", 10 | "prod": "npm version patch && rollup -c && ELEVENTY_ENV=production eleventy --input=src --output=dist && npm run build-cache-manifest && npm run sw && npm run sitemap", 11 | "sw": "rollup -c rollup.sw.config.js", 12 | "gzip": "find dist -type f -name '*.js' -exec gzip -kf \"{}\" \\;", 13 | "serve": "http-server dist -g -c0 --cors=\"*\"", 14 | "sitemap": "node build/sitemap.js" 15 | }, 16 | "napa": { 17 | "qrcodejs": "davidshimjs/qrcodejs" 18 | }, 19 | "license": "Apache-2.0", 20 | "devDependencies": { 21 | "@11ty/eleventy": "^0.7.1", 22 | "clean-css": "^4.2.1", 23 | "express": "^4.16.4", 24 | "idb-keyval": "^3.2.0", 25 | "lit-html": "^1.0.0", 26 | "napa": "^3.0.0", 27 | "rimraf": "^2.6.3", 28 | "rollup": "^1.6.0", 29 | "rollup-plugin-license": "^0.8.1", 30 | "rollup-plugin-loadz0r": "^0.7.0", 31 | "rollup-plugin-node-resolve": "^4.0.1", 32 | "rollup-plugin-replace": "^2.1.1", 33 | "rollup-plugin-terser": "^4.0.4", 34 | "rollup-plugin-typescript2": "^0.20.1", 35 | "sitemap-generator": "git+ssh://git@github.com/PolymerLabs/perception-toolkit.git#sitemap-generator", 36 | "walk": "^2.3.14" 37 | }, 38 | "dependencies": { 39 | "@webcomponents/webcomponentsjs": "^2.2.7", 40 | "perception-toolkit": "^0.0.1" 41 | } 42 | } 43 | -------------------------------------------------------------------------------- /generate/index.html: -------------------------------------------------------------------------------- 1 | 17 | 18 | 19 | 20 | 21 | QR Code 22 | 23 | 24 | 25 |
26 | 27 | 28 |
29 | 30 |
31 | 32 | 53 | 54 | 55 | -------------------------------------------------------------------------------- /src/_includes/index.css: -------------------------------------------------------------------------------- 1 | /** 2 | * @license 3 | * Copyright 2019 Google LLC 4 | * 5 | * Licensed under the Apache License, Version 2.0 (the "License"); 6 | * you may not use this file except in compliance with the License. 7 | * You may obtain a copy of the License at 8 | * 9 | * https://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | 18 | body { 19 | background: #FFF; 20 | font-size: 16px; 21 | text-align: center; 22 | } 23 | 24 | p { 25 | font-size: 15px; 26 | line-height: 1.5; 27 | color: #626262; 28 | width: 90%; 29 | max-width: 420px; 30 | margin: 0 auto 1em auto; 31 | } 32 | 33 | img { 34 | width: 130px; 35 | margin-top: 40px; 36 | } 37 | 38 | @media(min-width: 400px) { 39 | img { 40 | width: 180px; 41 | height: 130px; 42 | margin-top: 50px; 43 | } 44 | } 45 | 46 | h1 { 47 | margin-bottom: 36px; 48 | } 49 | 50 | #start-scanning { 51 | background: rgb(42, 135, 67); 52 | height: 48px; 53 | max-width: 300px; 54 | border-radius: 32px; 55 | color: rgb(255, 255, 255); 56 | text-transform: uppercase; 57 | text-decoration: none; 58 | font-size: 20px; 59 | display: flex; 60 | justify-content: center; 61 | align-items: center; 62 | margin: 40px auto 24px auto; 63 | } 64 | 65 | @media(min-width: 400px) { 66 | #start-scanning { 67 | margin-top: 60px; 68 | } 69 | } 70 | 71 | @media(min-width: 600px) { 72 | #start-scanning { 73 | margin-top: 80px; 74 | } 75 | } 76 | 77 | #see-list { 78 | font-size: 14px; 79 | color: rgb(90, 90, 90); 80 | } 81 | 82 | p:last-of-type { 83 | margin-bottom: 32px; 84 | } 85 | -------------------------------------------------------------------------------- /src/settings/settings.ts: -------------------------------------------------------------------------------- 1 | /** 2 | * @license 3 | * Copyright 2019 Google LLC 4 | * 5 | * Licensed under the Apache License, Version 2.0 (the "License"); 6 | * you may not use this file except in compliance with the License. 7 | * You may obtain a copy of the License at 8 | * 9 | * https://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | 18 | 19 | import { Section } from '../scripts/section.js'; 20 | import * as store from '../scripts/store.js'; 21 | 22 | class Settings extends Section { 23 | private readonly onClearBound = this.onClear.bind(this); 24 | 25 | async setup(parts?: string[]) { 26 | const clearDataButton = 27 | document.querySelector('#clear-data') as HTMLButtonElement; 28 | if (!clearDataButton) { 29 | console.warn('Clear Data button unavailable'); 30 | return; 31 | } 32 | clearDataButton.addEventListener('click', this.onClearBound); 33 | } 34 | 35 | async teardown() { 36 | const clearDataButton = 37 | document.querySelector('#clear-data') as HTMLButtonElement; 38 | if (!clearDataButton) { 39 | console.warn('Clear Data button unavailable'); 40 | return; 41 | } 42 | clearDataButton.removeEventListener('click', this.onClearBound); 43 | } 44 | 45 | async onClear() { 46 | if (!confirm('Are you sure you want to reset?')) { 47 | return; 48 | } 49 | 50 | await store.clear(); 51 | const reg = await navigator.serviceWorker.getRegistration(); 52 | if (reg) { 53 | await reg.unregister(); 54 | } 55 | const cacheNames = await caches.keys(); 56 | for (const cacheName of cacheNames) { 57 | await caches.delete(cacheName); 58 | } 59 | 60 | alert('All clear'); 61 | window.location.href = '/'; 62 | } 63 | } 64 | 65 | export const toRemove = 'bar'; 66 | export default new Settings(); 67 | -------------------------------------------------------------------------------- /rollup.config.js: -------------------------------------------------------------------------------- 1 | /** 2 | * @license 3 | * Copyright 2019 Google LLC 4 | * 5 | * Licensed under the Apache License, Version 2.0 (the "License"); 6 | * you may not use this file except in compliance with the License. 7 | * You may obtain a copy of the License at 8 | * 9 | * https://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | 18 | import typescript from 'rollup-plugin-typescript2'; 19 | import nodeResolve from 'rollup-plugin-node-resolve'; 20 | import loadz0r from 'rollup-plugin-loadz0r'; 21 | import { terser } from 'rollup-plugin-terser'; 22 | import license from 'rollup-plugin-license'; 23 | 24 | require('rimraf').sync('dist'); 25 | require('rimraf').sync('bundled'); 26 | 27 | export default [{ 28 | input: [ 29 | 'src/scripts/app.ts', 30 | 'src/index.ts', 31 | 'src/list/list.ts', 32 | 'src/settings/settings.ts', 33 | 'src/details/details.ts', 34 | 'src/capture/capture.ts', 35 | ], 36 | plugins: [ 37 | typescript({ 38 | target: 'es2015', 39 | module: 'esnext' 40 | }), 41 | nodeResolve(), 42 | loadz0r({ publicPath: '/bundled'}), 43 | terser(), 44 | license({ 45 | sourcemap: true, 46 | 47 | banner: ` 48 | @license 49 | Copyright 2019 Google LLC 50 | 51 | Licensed under the Apache License, Version 2.0 (the "License"); 52 | you may not use this file except in compliance with the License. 53 | You may obtain a copy of the License at 54 | 55 | https://www.apache.org/licenses/LICENSE-2.0 56 | 57 | Unless required by applicable law or agreed to in writing, software 58 | distributed under the License is distributed on an "AS IS" BASIS, 59 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 60 | See the License for the specific language governing permissions and 61 | limitations under the License. 62 | ` 63 | }) 64 | ], 65 | 66 | output: { 67 | dir: 'bundled', 68 | format: 'amd', 69 | exports: 'named' 70 | } 71 | }]; 72 | -------------------------------------------------------------------------------- /src/scripts/section.ts: -------------------------------------------------------------------------------- 1 | /** 2 | * @license 3 | * Copyright 2019 Google LLC 4 | * 5 | * Licensed under the Apache License, Version 2.0 (the "License"); 6 | * you may not use this file except in compliance with the License. 7 | * You may obtain a copy of the License at 8 | * 9 | * https://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | 18 | import { fade } from './utils/fade.js'; 19 | 20 | enum SectionState { 21 | INITIALIZING = 'initializing', 22 | TEARING_DOWN = 'tearingdown', 23 | ACTIVE = 'active', 24 | INACTIVE = 'inactive' 25 | } 26 | 27 | export interface Section { 28 | init(parts?: string[]): Promise; 29 | finish(): Promise; 30 | } 31 | 32 | export abstract class Section implements Section { 33 | private state = SectionState.INACTIVE; 34 | 35 | abstract async teardown(): Promise; 36 | abstract async setup(parts?: string[]): Promise; 37 | 38 | async init(parts?: string[]) { 39 | if (this.state === SectionState.ACTIVE || 40 | this.state === SectionState.INITIALIZING) { 41 | return; 42 | } 43 | 44 | this.state = SectionState.INITIALIZING; 45 | await this.setup(parts); 46 | 47 | // Check it's not been interrupted. 48 | if (this.state !== SectionState.INITIALIZING) { 49 | return; 50 | } 51 | 52 | this.state = SectionState.ACTIVE; 53 | 54 | const main = document.querySelector('main') as HTMLElement; 55 | await fade(main, { from: 0, to: 1, duration: 140}); 56 | } 57 | 58 | async finish() { 59 | if (this.state === SectionState.INACTIVE || 60 | this.state === SectionState.TEARING_DOWN) { 61 | return; 62 | } 63 | 64 | const main = document.querySelector('main') as HTMLElement; 65 | await fade(main, { from: 1, to: 0, duration: 140}); 66 | 67 | this.state = SectionState.TEARING_DOWN; 68 | await this.teardown(); 69 | 70 | // Check it's not been interrupted. 71 | if (this.state !== SectionState.TEARING_DOWN) { 72 | return; 73 | } 74 | this.state = SectionState.INACTIVE; 75 | } 76 | } 77 | -------------------------------------------------------------------------------- /src/scripts/store.ts: -------------------------------------------------------------------------------- 1 | /** 2 | * @license 3 | * Copyright 2019 Google LLC 4 | * 5 | * Licensed under the Apache License, Version 2.0 (the "License"); 6 | * you may not use this file except in compliance with the License. 7 | * You may obtain a copy of the License at 8 | * 9 | * https://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | 18 | import * as IDBKeyVal from 'idb-keyval'; 19 | 20 | interface ModelCallback { 21 | (value: any): void; 22 | } 23 | 24 | const subscribers: Map = 25 | new Map(); 26 | export async function subscribe(name: string, subscriber: ModelCallback) { 27 | let subscriberList = subscribers.get(name); 28 | if (!subscriberList) { 29 | subscriberList = []; 30 | } 31 | 32 | subscriberList.push(subscriber); 33 | subscribers.set(name, subscriberList); 34 | 35 | const data = await IDBKeyVal.get(name) as T; 36 | subscriber(data); 37 | } 38 | 39 | export function unsubscribe(name: string, subscriber: ModelCallback) { 40 | const subscriberList = subscribers.get(name); 41 | if (!subscriberList) { 42 | return; 43 | } 44 | 45 | const idx = subscriberList.findIndex((s) => s === subscriber); 46 | if (idx === -1) { 47 | return; 48 | } 49 | 50 | subscriberList.splice(idx, 1); 51 | subscribers.set(name, subscriberList); 52 | } 53 | 54 | export async function publish(name: string, value: any) { 55 | await IDBKeyVal.set(name, value); 56 | 57 | const subscriberList = subscribers.get(name); 58 | if (!subscriberList) { 59 | return; 60 | } 61 | 62 | for (const subscriber of subscriberList) { 63 | subscriber(value); 64 | } 65 | } 66 | 67 | export async function get(name: string, def?: T): Promise { 68 | const value = await IDBKeyVal.get(name) as T; 69 | if (!value && def) { 70 | await IDBKeyVal.set(name, def); 71 | return def; 72 | } 73 | 74 | return value; 75 | } 76 | 77 | export async function clear(name?: string) { 78 | const keys = await IDBKeyVal.keys(); 79 | for (const key of keys) { 80 | if (!name || key === name) { 81 | console.log(`Deleting ${key}`); 82 | await IDBKeyVal.del(key); 83 | } 84 | } 85 | } 86 | -------------------------------------------------------------------------------- /src/sw/cache-manifest.ts: -------------------------------------------------------------------------------- 1 | export const pathManifest = [ 2 | "/", 3 | "/capture/", 4 | "/details/", 5 | "/details/squoosh.app/", 6 | "/list/", 7 | "/settings/" 8 | ] 9 | 10 | export const cacheManifest = [ 11 | "/sw/tsconfig.json", 12 | "/static/manifest.json", 13 | "/static/images/baseline-code-24px.svg", 14 | "/static/images/baseline-delete_forever-24px.svg", 15 | "/static/images/baseline-launch-24px.svg", 16 | "/static/images/baseline-link-24px.svg", 17 | "/static/images/baseline-person-24px.svg", 18 | "/static/images/baseline-share-24px.svg", 19 | "/static/images/baseline-slideshow-24px.svg", 20 | "/static/images/io-logo.png", 21 | "/static/images/onboarding/step-1.jpg", 22 | "/static/images/onboarding/step-2.jpg", 23 | "/static/images/onboarding/step-3.jpg", 24 | "/static/images/onboarding/step-4.jpg", 25 | "/static/images/items/lighthouse.jpg", 26 | "/static/images/items/squoosh.app.jpg", 27 | "/static/images/items/web.dev.jpg", 28 | "/static/images/icons/512.png", 29 | "/node_modules/perception-toolkit/third_party/zxing/zxing_reader.js", 30 | "/node_modules/perception-toolkit/third_party/intersection-observer/intersection-observer-polyfill.js", 31 | "/node_modules/perception-toolkit/third_party/idb-keyval/idb-keyval-iife.min.js", 32 | "/node_modules/perception-toolkit/lib/index.js", 33 | "/node_modules/perception-toolkit/lib/polyfills/barcode-detector.js", 34 | "/node_modules/perception-toolkit/lib/polyfills/barcode-detector_test.js", 35 | "/node_modules/perception-toolkit/lib/polyfills/barcode-detector_worker.js", 36 | "/node_modules/perception-toolkit/lib/perception-toolkit/bootstrap.js", 37 | "/node_modules/perception-toolkit/lib/perception-toolkit/events.js", 38 | "/node_modules/perception-toolkit/lib/perception-toolkit/meaning-maker.js", 39 | "/node_modules/perception-toolkit/lib/bundled/bootstrap.js", 40 | "/node_modules/perception-toolkit/lib/bundled/meaning-maker.js", 41 | "/node_modules/perception-toolkit/lib/bundled/pt-chunk-2c2752b3.js", 42 | "/node_modules/perception-toolkit/lib/bundled/pt-chunk-bc29be45.js", 43 | "/node_modules/perception-toolkit/lib/bundled/pt-chunk-d3dcaf5d.js", 44 | "/node_modules/idb-keyval/dist/idb-keyval-iife.min.js", 45 | "/node_modules/@webcomponents/webcomponentsjs/webcomponents-loader.js", 46 | "/bundled/app.js", 47 | "/bundled/capture.js", 48 | "/bundled/chunk-09a48bee.js", 49 | "/bundled/chunk-b15f23f2.js", 50 | "/bundled/chunk-f34ff910.js", 51 | "/bundled/details.js", 52 | "/bundled/index.js", 53 | "/bundled/list.js", 54 | "/bundled/settings.js" 55 | ]; 56 | -------------------------------------------------------------------------------- /src/scripts/utils/fade.ts: -------------------------------------------------------------------------------- 1 | /** 2 | * @license 3 | * Copyright 2019 Google LLC 4 | * 5 | * Licensed under the Apache License, Version 2.0 (the "License"); 6 | * you may not use this file except in compliance with the License. 7 | * You may obtain a copy of the License at 8 | * 9 | * https://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | 18 | import { clamp } from './clamp.js'; 19 | 20 | function easeOut(value: number) { 21 | return 1 - Math.pow(1 - value, 3); 22 | } 23 | 24 | type Resolver = (value?: void | PromiseLike) => void; 25 | 26 | const animations = new WeakMap(); 27 | 28 | /** 29 | * Fades an element using `requestAnimationFrame`. Takes a parameter detailing 30 | * the animation, which is an object containing `to` (`0 <= to <= 1`), `from` 31 | * (`0 <= to <= 1`), duration (milliseconds), and `ease` (a function that takes 32 | * a value between `0` and `1` and returns a new value, also between `0` and 33 | * `1`) properties. 34 | * 35 | * ```javascript 36 | * fade(someElement, { from: 1, to: 1, duration: 200, ease: (v) => v }) 37 | * ``` 38 | * 39 | * @param target The element to fade. 40 | */ 41 | export function fade(target: HTMLElement, 42 | {from = 1, 43 | to = 0, 44 | delay = 0, 45 | duration = 250, 46 | ease = easeOut} = {}): Promise { 47 | return new Promise((resolve) => { 48 | const existingAnimation = animations.get(target); 49 | if (existingAnimation) { 50 | cancelAnimationFrame(existingAnimation.id); 51 | animations.delete(target); 52 | existingAnimation.resolve(); 53 | } 54 | 55 | target.style.opacity = from.toString(); 56 | const start = self.performance.now() + delay; 57 | const update = () => { 58 | const now = self.performance.now(); 59 | const time = clamp((now - start) / duration, 0, 1); 60 | const value = from + ((to - from) * ease(time)); 61 | 62 | target.style.opacity = value.toString(); 63 | 64 | if (time < 1) { 65 | animations.set(target, {id: requestAnimationFrame(update), resolve}); 66 | } else { 67 | target.style.opacity = to.toString(); 68 | animations.delete(target); 69 | resolve(); 70 | } 71 | }; 72 | 73 | animations.set(target, {id: requestAnimationFrame(update), resolve}); 74 | }); 75 | } 76 | -------------------------------------------------------------------------------- /src/_includes/app.css: -------------------------------------------------------------------------------- 1 | /** 2 | * @license 3 | * Copyright 2019 Google LLC 4 | * 5 | * Licensed under the Apache License, Version 2.0 (the "License"); 6 | * you may not use this file except in compliance with the License. 7 | * You may obtain a copy of the License at 8 | * 9 | * https://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | 18 | html, body { 19 | margin: 0; 20 | padding: 0; 21 | font-family: 'Roboto', Arial, Helvetica, sans-serif; 22 | background: #FAFAFA; 23 | min-height: 100vh; 24 | min-width: 100vw; 25 | } 26 | 27 | h1, h2, h3 { 28 | font-family: 'Raleway', 'Roboto', Arial, Helvetica, sans-serif; 29 | margin: 0; 30 | font-weight: normal; 31 | } 32 | 33 | body { 34 | display: flex; 35 | flex-direction: column; 36 | } 37 | 38 | main { 39 | position: relative; 40 | z-index: 3; 41 | flex: 1; 42 | opacity: 0; 43 | padding-bottom: 80px; 44 | } 45 | 46 | a { 47 | color: rgb(42, 135, 67); 48 | } 49 | 50 | app-header { 51 | min-height: 64px; 52 | font-size: 0; 53 | opacity: 0; 54 | } 55 | 56 | app-header::after { 57 | padding: 20px 24px; 58 | content: 'Loading...'; 59 | color: #FFF; 60 | font-size: 18px; 61 | flex: 1; 62 | text-align: left; 63 | display: block; 64 | } 65 | 66 | footer { 67 | height: 40px; 68 | background: #efefef; 69 | color: #6d6d6d; 70 | font-size: 12px; 71 | margin-top: 24px; 72 | text-align: left; 73 | display: flex; 74 | align-items: center; 75 | box-sizing: border-box; 76 | padding: 8px 24px; 77 | position: fixed; 78 | bottom: 0; 79 | width: 100%; 80 | left: 0; 81 | z-index: 3; 82 | } 83 | 84 | #source-code { 85 | color: #6d6d6d; 86 | padding-left: 32px; 87 | background: url(/static/images/baseline-code-24px.svg) left center no-repeat; 88 | height: 24px; 89 | display: flex; 90 | align-items: center; 91 | } 92 | 93 | #share-app { 94 | cursor: pointer; 95 | margin-left: 16px; 96 | padding: 0 0 0 32px; 97 | background: url(/static/images/baseline-share-24px.svg) left center no-repeat; 98 | border: none; 99 | margin: 0 0 0 24px; 100 | font-size: 12px; 101 | color: #6d6d6d; 102 | text-decoration: underline; 103 | height: 24px; 104 | display: none; 105 | } 106 | 107 | #share-app.visible { 108 | display: block; 109 | } 110 | 111 | #version { 112 | flex: 1; 113 | text-align: right; 114 | color: #CCC; 115 | } 116 | -------------------------------------------------------------------------------- /src/_includes/capture/capture.css: -------------------------------------------------------------------------------- 1 | /** 2 | * @license 3 | * Copyright 2019 Google LLC 4 | * 5 | * Licensed under the Apache License, Version 2.0 (the "License"); 6 | * you may not use this file except in compliance with the License. 7 | * You may obtain a copy of the License at 8 | * 9 | * https://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | 18 | html, body { 19 | height: 100%; 20 | min-height: auto; 21 | } 22 | 23 | body { 24 | background: #111; 25 | } 26 | 27 | footer { 28 | opacity: 0 !important; 29 | } 30 | 31 | stream-capture { 32 | position: fixed; 33 | top: 0; 34 | left: 0; 35 | z-index: 2; 36 | width: 100%; 37 | height: 100%; 38 | } 39 | 40 | dot-loader { 41 | position: absolute; 42 | top: 50%; 43 | left: 50%; 44 | transform: translate(-50%, -50%); 45 | } 46 | 47 | main { 48 | pointer-events: none; 49 | } 50 | 51 | .container { 52 | position: fixed; 53 | width: 100%; 54 | height: 100%; 55 | padding: 32px; 56 | display: flex; 57 | flex-direction: column; 58 | align-items: center; 59 | justify-content: flex-end; 60 | box-sizing: border-box; 61 | z-index: 1; 62 | pointer-events: none; 63 | top: 0; 64 | left: 0; 65 | } 66 | 67 | .container data-card { 68 | margin-top: 16px; 69 | pointer-events: auto; 70 | } 71 | 72 | data-card { 73 | animation: fadeAndSlideIn forwards 0.3s cubic-bezier(0, 0, 0.3, 1); 74 | } 75 | 76 | data-card.no-support { 77 | opacity: 0; 78 | box-shadow: 0 2px 4px rgba(0, 0, 0, 0.3); 79 | animation: fadeIn 0.3s cubic-bezier(0, 0, 0.3, 1) forwards 0.2s; 80 | position: absolute; 81 | left: 50%; 82 | top: 50%; 83 | transform: translate(-50%, -50%); 84 | width: 100%; 85 | max-width: 90vw; 86 | } 87 | 88 | onboarding-card { 89 | --background: #FFF; 90 | --padding: 0 0 16px 0; 91 | position: absolute; 92 | top: 50%; 93 | left: 50%; 94 | transform: translate(-50%, -50%); 95 | opacity: 0; 96 | box-shadow: 0 12px 20px rgba(0, 0, 0, 0.3); 97 | animation: fadeIn 0.3s cubic-bezier(0, 0, 0.3, 1) forwards 0.2s; 98 | overflow: auto; 99 | z-index: 4; 100 | } 101 | 102 | @keyframes fadeIn { 103 | from { 104 | opacity: 0; 105 | } 106 | 107 | to { 108 | opacity: 1; 109 | } 110 | } 111 | 112 | @keyframes fadeAndSlideIn { 113 | from { 114 | transform: translate(0, 10px); 115 | opacity: 0; 116 | } 117 | 118 | to { 119 | transform: none; 120 | opacity: 1; 121 | } 122 | } 123 | -------------------------------------------------------------------------------- /src/_includes/list/list.css: -------------------------------------------------------------------------------- 1 | /** 2 | * @license 3 | * Copyright 2019 Google LLC 4 | * 5 | * Licensed under the Apache License, Version 2.0 (the "License"); 6 | * you may not use this file except in compliance with the License. 7 | * You may obtain a copy of the License at 8 | * 9 | * https://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | 18 | img { 19 | width: 82px; 20 | height: 82px; 21 | object-fit: cover; 22 | border-right: 1px solid #DEDEDE; 23 | } 24 | 25 | main ul { 26 | padding: 0; 27 | margin: 16px auto; 28 | list-style: none; 29 | border-radius: 9px; 30 | background: #FFFFFF; 31 | box-shadow: 0 2px 3px 0 rgba(0,0,0,0.17); 32 | width: 90%; 33 | max-width: 600px; 34 | overflow: auto; 35 | } 36 | 37 | main li { 38 | border-bottom: 1px solid #DEDEDE; 39 | } 40 | 41 | main li::before { 42 | content: ''; 43 | position: absolute; 44 | top: 0; 45 | left: 0; 46 | width: 100%; 47 | height: 100%; 48 | background: #F7F7F7; 49 | opacity: 0; 50 | transition: opacity 0.3s cubic-bezier(0, 0, 0.3, 1); 51 | } 52 | 53 | main li:focus::before, 54 | main li:hover::before { 55 | opacity: 1; 56 | } 57 | 58 | main li:last-of-type { 59 | border-bottom: none; 60 | } 61 | 62 | main li, 63 | main li a { 64 | display: flex; 65 | flex-direction: row; 66 | align-items: center; 67 | justify-content: center; 68 | text-decoration: none; 69 | position: relative; 70 | } 71 | 72 | main li a { 73 | flex: 1; 74 | } 75 | 76 | main li a > * { 77 | pointer-events: none; 78 | } 79 | 80 | .details { 81 | flex: 1; 82 | padding: 12px; 83 | } 84 | 85 | .details__name { 86 | font-family: 'Raleway'; 87 | font-size: 22px; 88 | color: #626262; 89 | } 90 | 91 | .details__scanned { 92 | font-family: 'Roboto'; 93 | font-size: 13px; 94 | color: #A5A5A5; 95 | } 96 | 97 | li:hover .details__name { 98 | color: #444; 99 | } 100 | 101 | li button { 102 | position: relative; 103 | width: 24px; 104 | height: 24px; 105 | border: none; 106 | font-size: 0;background: url(/static/images/baseline-launch-24px.svg) center center no-repeat; 107 | margin: 24px; 108 | cursor: pointer; 109 | opacity: 0.7; 110 | } 111 | 112 | li button:focus, 113 | li button:hover { 114 | transition: opacity 0.3s cubic-bezier(0, 0, 0.3, 1); 115 | opacity: 1; 116 | } 117 | 118 | .no-items { 119 | width: 90%; 120 | height: 100%; 121 | font-size: 16px; 122 | max-width: 400px; 123 | margin: 0 auto; 124 | display: flex; 125 | flex-direction: column; 126 | align-items: center; 127 | justify-content: center; 128 | } 129 | 130 | .no-items .title { 131 | font-size: 20px; 132 | margin: 16px 0; 133 | } 134 | 135 | .no-items a { 136 | color: #33A852; 137 | } 138 | -------------------------------------------------------------------------------- /src/scripts/app.ts: -------------------------------------------------------------------------------- 1 | /** 2 | * @license 3 | * Copyright 2019 Google LLC 4 | * 5 | * Licensed under the Apache License, Version 2.0 (the "License"); 6 | * you may not use this file except in compliance with the License. 7 | * You may obtain a copy of the License at 8 | * 9 | * https://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | 18 | import { AppHeader } from './components/app-header/app-header.js'; 19 | import * as Router from './router.js'; 20 | 21 | if (!customElements.get('app-header')) { 22 | customElements.define('app-header', AppHeader); 23 | } 24 | 25 | declare global { 26 | interface Window { 27 | PerceptionToolkit: any; 28 | } 29 | interface Navigator { 30 | share(opts: { 31 | title: string; 32 | text: string; 33 | url: string; 34 | }): void; 35 | } 36 | } 37 | 38 | class App { 39 | constructor() { 40 | Router.register([{ 41 | load: () => import('../index.js').then(m => m.default), 42 | path: /^\/$/ 43 | }, { 44 | load: () => import('../list/list.js').then(m => m.default), 45 | path: /^\/list\// 46 | }, { 47 | load: () => import('../settings/settings.js').then(m => m.default), 48 | path: /^\/settings\//, 49 | }, { 50 | load: () => import('../details/details.js').then(m => m.default), 51 | path: /^\/details\//, 52 | }, { 53 | load: () => import('../capture/capture.js').then(m => m.default), 54 | path: /^\/capture\//, 55 | }]); 56 | 57 | Router.init().then(() => { 58 | this.hijackLinks(); 59 | this.initServiceWorker(); 60 | }); 61 | 62 | const shareApp = document.querySelector('#share-app'); 63 | if (!(shareApp && ('share' in navigator))) { 64 | return; 65 | } 66 | 67 | shareApp.classList.add('visible'); 68 | shareApp.addEventListener('click', () => { 69 | navigator.share({ 70 | text: 'Check out the Web Sandbox PWA', 71 | title: 'Google I/O - Web Sandbox', 72 | url: window.location.origin, 73 | }); 74 | }); 75 | } 76 | 77 | private hijackLinks() { 78 | let transitioning = false; 79 | document.addEventListener('click', async (evt) => { 80 | const target = evt.target as HTMLAnchorElement; 81 | if (target.tagName !== 'A') { 82 | return; 83 | } 84 | 85 | // If not this origin then treat as a typical anchor. 86 | const targetUrl = new URL(target.href, window.location.toString()); 87 | if (targetUrl.origin !== window.location.origin) { 88 | return; 89 | } 90 | 91 | evt.preventDefault(); 92 | 93 | // Bail if we're already handling a change. 94 | if (transitioning) { 95 | return; 96 | } 97 | 98 | transitioning = true; 99 | await Router.go(target.href); 100 | transitioning = false; 101 | }); 102 | } 103 | 104 | private async initServiceWorker() { 105 | await navigator.serviceWorker.register('/sw.js'); 106 | } 107 | } 108 | 109 | // tslint:disable-next-line:no-unused-expression 110 | new App(); 111 | -------------------------------------------------------------------------------- /src/sw/sw.ts: -------------------------------------------------------------------------------- 1 | /** 2 | * @license 3 | * Copyright 2019 Google LLC 4 | * 5 | * Licensed under the Apache License, Version 2.0 (the "License"); 6 | * you may not use this file except in compliance with the License. 7 | * You may obtain a copy of the License at 8 | * 9 | * https://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | 18 | import { cacheManifest, pathManifest } from './cache-manifest'; 19 | 20 | declare var self: ServiceWorkerGlobalScope; 21 | 22 | const NAME = 'io-sandbox-scanner'; 23 | const VERSION = '{@VERSION@}'; 24 | 25 | self.oninstall = (evt) => { 26 | evt.waitUntil( 27 | caches 28 | .open(`${NAME}-v${VERSION}`) 29 | .then(newCache => { 30 | const toCache = [ 31 | ...pathManifest, 32 | ...cacheManifest 33 | ]; 34 | 35 | return toCache.map((url) => { 36 | const urlParts = url.split('|'); 37 | const srcUrl = urlParts[0]; 38 | const destUrl = urlParts.length === 2 ? urlParts[1] : urlParts[0]; 39 | 40 | console.log(`Getting ${srcUrl} from network.`); 41 | return fetch(srcUrl) 42 | .then(response => { 43 | if (destUrl === '/404/') { 44 | response = new Response(response.body, { 45 | headers: response.headers, 46 | status: 404, 47 | statusText: 'Not Found', 48 | }); 49 | } 50 | 51 | newCache.put(destUrl, response); 52 | }); 53 | }); 54 | }) 55 | ); 56 | 57 | self.skipWaiting(); 58 | }; 59 | 60 | self.onactivate = _ => { 61 | const currentCacheName = `${NAME}-v${VERSION}`; 62 | caches.keys().then(cacheNames => { 63 | return Promise.all( 64 | cacheNames.map((cacheName) => { 65 | if (cacheName.indexOf(NAME) === -1) { 66 | return Promise.resolve(true); 67 | } 68 | 69 | if (cacheName !== currentCacheName) { 70 | return caches.delete(cacheName); 71 | } 72 | 73 | return Promise.resolve(true); 74 | }) 75 | ); 76 | }); 77 | 78 | self.clients.claim(); 79 | }; 80 | 81 | self.onmessage = evt => { 82 | const action = evt.data.action; 83 | if (!action || !evt.source) { 84 | console.warn('Message received with no action:', evt); 85 | return; 86 | } 87 | 88 | switch (action) { 89 | case 'version': 90 | evt.source.postMessage({ 91 | version: VERSION 92 | }); 93 | return; 94 | } 95 | }; 96 | 97 | self.onfetch = (evt: FetchEvent) => { 98 | const request = evt.request; 99 | 100 | evt.respondWith( 101 | // Check the cache for a hit. 102 | caches.match(request).then(async (response) => { 103 | // If we have a response return it. 104 | if (response) { 105 | return response; 106 | } 107 | 108 | const fetchedResponse = await fetch(request); 109 | 110 | if (fetchedResponse) { 111 | const cacheName = request.url.endsWith('.wasm') ? 112 | 'wasm' : 113 | `${NAME}-v${VERSION}`; 114 | const cache = await caches.open(cacheName); 115 | cache.put(request, fetchedResponse.clone()); 116 | console.log(`Storing ${request.url} in ${cacheName} for future requests.`); 117 | return fetchedResponse; 118 | } 119 | 120 | // And worst case we fire out a not found. 121 | return new Response('Sorry, not found'); 122 | }) 123 | ); 124 | }; 125 | -------------------------------------------------------------------------------- /src/details/details.ts: -------------------------------------------------------------------------------- 1 | /** 2 | * @license 3 | * Copyright 2019 Google LLC 4 | * 5 | * Licensed under the Apache License, Version 2.0 (the "License"); 6 | * you may not use this file except in compliance with the License. 7 | * You may obtain a copy of the License at 8 | * 9 | * https://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | 18 | import { ScannedItem } from '../defs/scanned-item.js'; 19 | import * as Router from '../scripts/router.js'; 20 | import { Section } from '../scripts/section.js'; 21 | import * as store from '../scripts/store.js'; 22 | 23 | class Details extends Section { 24 | private readonly key = 'scanned-items'; 25 | private readonly onShareClickBound = this.onShareClick.bind(this); 26 | private readonly onDeleteClickBound = 27 | this.onDeleteClick.bind(this); 28 | 29 | setup(parts?: string[]): Promise { 30 | if (!parts || !parts.length) { 31 | Router.go('/'); 32 | return Promise.resolve(); 33 | } 34 | 35 | const shareButton = document.querySelector('#share') as HTMLElement; 36 | shareButton.classList.toggle('visible', 'share' in navigator); 37 | 38 | document.addEventListener('click', this.onShareClickBound); 39 | document.addEventListener('click', this.onDeleteClickBound); 40 | 41 | return new Promise((resolve) => { 42 | const appHeader = document.querySelector('app-header'); 43 | if (!appHeader || appHeader.classList.contains('expanded')) { 44 | resolve(); 45 | return; 46 | } 47 | appHeader.classList.add('expanded'); 48 | appHeader.addEventListener('animationcomplete', 49 | () => resolve(), { once: true }); 50 | }); 51 | } 52 | 53 | teardown(): Promise { 54 | document.removeEventListener('click', this.onShareClickBound); 55 | 56 | return new Promise((resolve) => { 57 | const appHeader = document.querySelector('app-header'); 58 | if (!appHeader || !appHeader.classList.contains('expanded')) { 59 | resolve(); 60 | return; 61 | } 62 | appHeader.classList.remove('expanded'); 63 | appHeader.addEventListener('animationcomplete', 64 | () => resolve(), { once: true }); 65 | }); 66 | } 67 | 68 | async onShareClick(evt: Event) { 69 | const target = evt.target as HTMLElement; 70 | if (target.id !== 'share') { 71 | return; 72 | } 73 | 74 | evt.stopImmediatePropagation(); 75 | if (!('share' in navigator)) { 76 | return; 77 | } 78 | 79 | const title = document.querySelector('h1')!.textContent || ''; 80 | const url = window.location.toString(); 81 | const text = `Check out ${title}: `; 82 | 83 | await navigator.share({ 84 | text, 85 | title, 86 | url, 87 | }); 88 | } 89 | 90 | async onDeleteClick(evt: Event) { 91 | const target = evt.target as HTMLElement; 92 | if (!target.id.startsWith('del')) { 93 | return; 94 | } 95 | 96 | evt.stopImmediatePropagation(); 97 | if (!confirm('Are you sure you want to delete this?')) { 98 | return; 99 | } 100 | 101 | // Find and remove the chosen item. 102 | const items = await store.get(this.key); 103 | const startLength = items.length; 104 | const updatedItems = 105 | items.filter((i) => i.url !== window.location.toString()); 106 | const endLength = updatedItems.length; 107 | 108 | if (startLength !== endLength) { 109 | await store.publish(this.key, updatedItems); 110 | Router.go('/list/'); 111 | } 112 | } 113 | } 114 | 115 | export const toRemove = 'bar'; 116 | export default new Details(); 117 | -------------------------------------------------------------------------------- /src/_includes/details/details.css: -------------------------------------------------------------------------------- 1 | /** 2 | * @license 3 | * Copyright 2019 Google LLC 4 | * 5 | * Licensed under the Apache License, Version 2.0 (the "License"); 6 | * you may not use this file except in compliance with the License. 7 | * You may obtain a copy of the License at 8 | * 9 | * https://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | 18 | img { 19 | width: 160px; 20 | height: 160px; 21 | object-fit: cover; 22 | border-radius: 80px; 23 | box-shadow: 0 6px 8px rgba(0, 0, 0, 0.3); 24 | margin-bottom: 20px; 25 | animation: scaleIn forwards 0.5s cubic-bezier(0, 0.6, 0.3, 1); 26 | } 27 | 28 | #header-block { 29 | display: flex; 30 | flex-direction: column; 31 | align-items: center; 32 | justify-content: space-between; 33 | height: 280px; 34 | margin-top: -200px; 35 | text-align: center; 36 | position: relative; 37 | z-index: 1; 38 | pointer-events: none; 39 | } 40 | 41 | #header-block h2 { 42 | font-size: 13px; 43 | font-family: 'Roboto', Arial, Helvetica, sans-serif; 44 | margin-top: 8px; 45 | } 46 | 47 | #header-block p { 48 | margin: 0; 49 | } 50 | 51 | #details { 52 | position: relative; 53 | margin: -100px auto 0 auto; 54 | padding: 116px 24px; 55 | background: #FFF; 56 | border-radius: 20px 20px 3px 3px; 57 | opacity: 0; 58 | animation: slideAndFadeIn forwards 1.2s cubic-bezier(0, 0.6, 0.3, 1) 0.3s; 59 | max-width: 700px; 60 | box-shadow: 0 3px 3px rgba(0, 0, 0, 0.1); 61 | } 62 | 63 | #details ul { 64 | padding: 0; 65 | list-style: none; 66 | font-size: 15px; 67 | max-width: 600px; 68 | margin: 16px auto 32px auto; 69 | } 70 | 71 | #details li { 72 | line-height: 36px; 73 | } 74 | 75 | #details li a { 76 | color: #4385F4; 77 | display: block; 78 | padding-left: 32px; 79 | } 80 | 81 | #details a.person { 82 | background: url(/static/images/baseline-person-24px.svg) left center no-repeat; 83 | } 84 | 85 | #details a.link { 86 | background: url(/static/images/baseline-link-24px.svg) left center no-repeat; 87 | } 88 | 89 | #details a.slides { 90 | background: url(/static/images/baseline-slideshow-24px.svg) left center no-repeat; 91 | } 92 | 93 | #details a:hover { 94 | color: rgb(51, 103, 193); 95 | } 96 | 97 | @media (min-width: 700px) { 98 | #details { 99 | margin-bottom: 32px; 100 | } 101 | } 102 | 103 | #controls { 104 | position: absolute; 105 | right: 11px; 106 | top: 11px; 107 | height: 40px; 108 | padding: 10px 16px; 109 | background: #F7F7F7; 110 | border-radius: 20px; 111 | box-sizing: border-box; 112 | display: flex; 113 | justify-content: center; 114 | align-items: center; 115 | } 116 | 117 | #share, #delete { 118 | width: 24px; 119 | height: 24px; 120 | background: url(/static/images/baseline-share-24px.svg) center center no-repeat; 121 | border: none; 122 | cursor: pointer; 123 | font-size: 0; 124 | } 125 | 126 | #share { 127 | margin-right: 8px; 128 | display: none; 129 | } 130 | 131 | #share.visible { 132 | display: block; 133 | } 134 | 135 | #delete { 136 | background: url(/static/images/baseline-delete_forever-24px.svg) center center no-repeat; 137 | } 138 | 139 | #description { 140 | line-height: 1.5; 141 | font-size: 15px; 142 | max-width: 600px; 143 | margin: 0 auto; 144 | } 145 | 146 | @keyframes scaleIn { 147 | from { 148 | transform: scale(0.7); 149 | } 150 | 151 | to { 152 | transform: scale(1); 153 | } 154 | } 155 | 156 | @keyframes slideAndFadeIn { 157 | 0% { 158 | transform: translateY(20px); 159 | opacity: 0; 160 | } 161 | 162 | 10% { 163 | opacity: 1; 164 | } 165 | 166 | 100% { 167 | transform: none; 168 | opacity: 1; 169 | } 170 | } 171 | -------------------------------------------------------------------------------- /src/list/list.ts: -------------------------------------------------------------------------------- 1 | /** 2 | * @license 3 | * Copyright 2019 Google LLC 4 | * 5 | * Licensed under the Apache License, Version 2.0 (the "License"); 6 | * you may not use this file except in compliance with the License. 7 | * You may obtain a copy of the License at 8 | * 9 | * https://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | 18 | import { html, parts, render } from 'lit-html'; 19 | import { repeat } from 'lit-html/directives/repeat.js'; 20 | import { ScannedItem } from '../defs/scanned-item.js'; 21 | import { Section } from '../scripts/section.js'; 22 | import * as store from '../scripts/store.js'; 23 | 24 | class List extends Section { 25 | private readonly key = 'scanned-items'; 26 | private readonly onScannedItemChangeBound = 27 | this.onScannedItemChange.bind(this); 28 | private readonly onLaunchButtonClickBound = 29 | this.onLaunchButtonClick.bind(this); 30 | private main!: HTMLElement; 31 | 32 | async setup(parts?: string[]): Promise { 33 | store.subscribe(this.key, this.onScannedItemChangeBound); 34 | this.main = document.querySelector('main') as HTMLElement; 35 | 36 | this.main.addEventListener('click', this.onLaunchButtonClickBound); 37 | 38 | const header = document.querySelector('app-header') as HTMLElement; 39 | header.classList.add('capture-available'); 40 | } 41 | 42 | async teardown() { 43 | store.unsubscribe(this.key, this.onScannedItemChangeBound); 44 | 45 | // Clear Lit's tracking of main. 46 | parts.delete(this.main); 47 | 48 | this.main.removeEventListener('click', this.onLaunchButtonClickBound); 49 | 50 | const header = document.querySelector('app-header') as HTMLElement; 51 | header.classList.remove('capture-available'); 52 | } 53 | 54 | onLaunchButtonClick(evt: Event) { 55 | const target = evt.target as HTMLElement; 56 | if (!target.id.startsWith('launch')) { 57 | return; 58 | } 59 | 60 | evt.stopImmediatePropagation(); 61 | window.open(target.dataset.for); 62 | } 63 | 64 | onScannedItemChange(listItems?: ScannedItem[]) { 65 | let tmpl; 66 | 67 | const format = new Intl.DateTimeFormat('en-US', { 68 | day: 'numeric', 69 | hour: 'numeric', 70 | hour12: false, 71 | minute: 'numeric', 72 | month: 'numeric', 73 | second: 'numeric', 74 | year: 'numeric', 75 | }); 76 | if (listItems && listItems.length > 0) { 77 | tmpl = html` 78 | `; 106 | } else { 107 | tmpl = html`
108 |
No items scanned yet.
109 | Start scanning 110 |
`; 111 | } 112 | 113 | render(tmpl, this.main); 114 | } 115 | } 116 | 117 | export const toRemove = 'bar'; 118 | export default new List(); 119 | -------------------------------------------------------------------------------- /src/scripts/components/app-header/app-header.template.ts: -------------------------------------------------------------------------------- 1 | /** 2 | * @license 3 | * Copyright 2019 Google LLC 4 | * 5 | * Licensed under the Apache License, Version 2.0 (the "License"); 6 | * you may not use this file except in compliance with the License. 7 | * You may obtain a copy of the License at 8 | * 9 | * https://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | 18 | export const html = ` 19 |
20 | Home 21 |
22 | Capture 23 | List 24 | `; 25 | 26 | export const styles = ` 27 | :host { 28 | --header-background-color: #111; 29 | --header-text-color: #FFF; 30 | 31 | display: flex; 32 | height: 64px; 33 | justify-content: center; 34 | position: relative; 35 | z-index: 1; 36 | box-sizing: border-box; 37 | padding: 20px 24px; 38 | transition: opacity 0.25s cubic-bezier(0, 0, 0.3, 1); 39 | } 40 | 41 | :host(.visible) { 42 | opacity: 1 !important; 43 | } 44 | 45 | :host(.visible)::after { 46 | display: none !important; 47 | } 48 | 49 | #home, #capture, #list { 50 | display: block; 51 | z-index: 1; 52 | width: 24px; 53 | height: 24px; 54 | margin-right: 12px; 55 | transition: opacity 0.1s cubic-bezier(0, 0, 0.3, 1); 56 | cursor: pointer; 57 | } 58 | 59 | #home { 60 | background: url(data:image/svg+xml;base64,PHN2ZyB4bWxucz0iaHR0cDovL3d` + 61 | `3dy53My5vcmcvMjAwMC9zdmciIHdpZHRoPSIyNCIgaGVpZ2h0PSIyNCIgdmlld0Jve` + 62 | `D0iMCAwIDI0IDI0Ij48cGF0aCBmaWxsPSIjMzMzIiBkPSJNMTAgMjB2LTZoNHY2aDV` + 63 | `2LThoM0wxMiAzIDIgMTJoM3Y4eiIvPjxwYXRoIGQ9Ik0wIDBoMjR2MjRIMHoiIGZpb` + 64 | `Gw9Im5vbmUiLz48L3N2Zz4K); 65 | pointer-events: none; 66 | opacity: 0; 67 | } 68 | 69 | #capture { 70 | background: url(data:image/svg+xml;base64,PHN2ZyB4bWxucz0iaHR0cDovL3d` + 71 | `3dy53My5vcmcvMjAwMC9zdmciIHdpZHRoPSIyNCIgaGVpZ2h0PSIyNCIgdmlld0Jve` + 72 | `D0iMCAwIDI0IDI0Ij48Y2lyY2xlIGN4PSIxMiIgY3k9IjEyIiByPSIzLjIiLz48cGF` + 73 | `0aCBmaWxsPSIjMzMzIiBkPSJNOSAyTDcuMTcgNEg0Yy0xLjEgMC0yIC45LTIgMnYxM` + 74 | `mMwIDEuMS45IDIgMiAyaDE2YzEuMSAwIDItLjkgMi0yVjZjMC0xLjEtLjktMi0yLTJ` + 75 | `oLTMuMTdMMTUgMkg5em0zIDE1Yy0yLjc2IDAtNS0yLjI0LTUtNXMyLjI0LTUgNS01I` + 76 | `DUgMi4yNCA1IDUtMi4yNCA1LTUgNXoiLz48cGF0aCBkPSJNMCAwaDI0djI0SDB6IiB` + 77 | `maWxsPSJub25lIi8+PC9zdmc+Cg==); 78 | pointer-events: none; 79 | opacity: 0; 80 | position: absolute; 81 | right: 12px; 82 | top: 20px; 83 | } 84 | 85 | #list { 86 | background: url(data:image/svg+xml;base64,PHN2ZyB4bWxucz0iaHR0cDovL3d` + 87 | `3dy53My5vcmcvMjAwMC9zdmciIHdpZHRoPSIyNCIgaGVpZ2h0PSIyNCIgdmlld0Jve` + 88 | `D0iMCAwIDI0IDI0Ij48cGF0aCBmaWxsPSIjMzMzIiBkPSJNNCAxNGg0di00SDR2NHp` + 89 | `tMCA1aDR2LTRINHY0ek00IDloNFY1SDR2NHptNSA1aDEydi00SDl2NHptMCA1aDEyd` + 90 | `i00SDl2NHpNOSA1djRoMTJWNUg5eiIvPjxwYXRoIGQ9Ik0wIDBoMjR2MjRIMHoiIGZ` + 91 | `pbGw9Im5vbmUiLz48L3N2Zz4K); 92 | pointer-events: auto; 93 | opacity: 1; 94 | position: absolute; 95 | right: 12px; 96 | top: 20px; 97 | } 98 | 99 | :host(.home-available) #home { 100 | pointer-events: auto; 101 | opacity: 1; 102 | transition: opacity 0.2s cubic-bezier(0, 0, 0.3, 1) 0.1s; 103 | } 104 | 105 | :host(.capture-available) #capture { 106 | pointer-events: auto; 107 | opacity: 1; 108 | } 109 | 110 | :host(.capture-available) #list { 111 | pointer-events: none; 112 | opacity: 0; 113 | } 114 | 115 | #background { 116 | height: 64px; 117 | background-color: var(--header-background-color); 118 | position: absolute; 119 | top: 0; 120 | left: 0; 121 | width: 100%; 122 | transform-origin: 0 0; 123 | transition: background-color 0.2s cubic-bezier(0, 0, 0.3, 1), 124 | transform 0.2s cubic-bezier(0, 0, 0.3, 1); 125 | z-index: 0; 126 | } 127 | 128 | :host(.expanded) { 129 | height: 302px; 130 | z-index: 0; 131 | } 132 | 133 | :host(.expanded) #background { 134 | transform: scaleY(4.72); 135 | } 136 | 137 | #slotted { 138 | position: relative; 139 | color: var(--header-text-color); 140 | z-index: 1; 141 | font-size: 18px; 142 | flex: 1; 143 | text-align: left; 144 | transform: translateX(-36px); 145 | transition: transform 0.2s cubic-bezier(0, 0, 0.3, 1); 146 | } 147 | 148 | :host(.home-available) #slotted { 149 | transform: none; 150 | } 151 | `; 152 | -------------------------------------------------------------------------------- /src/capture/capture.ts: -------------------------------------------------------------------------------- 1 | /** 2 | * @license 3 | * Copyright 2019 Google LLC 4 | * 5 | * Licensed under the Apache License, Version 2.0 (the "License"); 6 | * you may not use this file except in compliance with the License. 7 | * You may obtain a copy of the License at 8 | * 9 | * https://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | 18 | import { ScannedItem } from '../defs/scanned-item.js'; 19 | import * as Router from '../scripts/router.js'; 20 | import { Section } from '../scripts/section.js'; 21 | import * as Storage from '../scripts/store.js'; 22 | 23 | class Capture extends Section { 24 | private readonly onCaptureStartBound = this.onCaptureStart.bind(this); 25 | private readonly onCaptureCloseBound = this.onCaptureClose.bind(this); 26 | private readonly onMarkerChangesBound = this.onMarkerChange.bind(this); 27 | private readonly onCameraAccessDeniedBound = 28 | this.onCameraAccessDenied.bind(this); 29 | private readonly key = 'scanned-items'; 30 | private container!: HTMLElement; 31 | 32 | async setup() { 33 | this.container = document.querySelector('.container') as HTMLElement; 34 | if (!this.container) { 35 | throw new Error('Unable to find container'); 36 | } 37 | 38 | const header = document.querySelector('app-header') as HTMLElement; 39 | header.classList.remove('visible'); 40 | 41 | const { Events, Functions } = window.PerceptionToolkit; 42 | Functions.initializeExperience(); 43 | 44 | window.addEventListener(Events.CaptureStarted, this.onCaptureStartBound); 45 | window.addEventListener(Events.CaptureClosed, this.onCaptureCloseBound); 46 | window.addEventListener(Events.MarkerChanges, this.onMarkerChangesBound); 47 | window.addEventListener(Events.CameraAccessDenied, 48 | this.onCameraAccessDeniedBound); 49 | } 50 | 51 | async teardown() { 52 | const header = document.querySelector('app-header') as HTMLElement; 53 | header.classList.add('visible'); 54 | 55 | const { Events, Functions } = window.PerceptionToolkit; 56 | 57 | window.removeEventListener(Events.CaptureStarted, this.onCaptureStartBound); 58 | window.removeEventListener(Events.CaptureClosed, this.onCaptureCloseBound); 59 | window.removeEventListener(Events.MarkerChanges, this.onMarkerChangesBound); 60 | window.removeEventListener(Events.CameraAccessDenied, 61 | this.onCameraAccessDeniedBound); 62 | 63 | Functions.closeExperience(); 64 | 65 | const cards = document.querySelectorAll('data-card'); 66 | for (const card of Array.from(cards)) { 67 | card.remove(); 68 | } 69 | } 70 | 71 | private onCaptureStart() { 72 | // Prevent future onboarding flows beginning. 73 | window.PerceptionToolkit.config.onboarding = false; 74 | window.PerceptionToolkit.config.cardContainer = 75 | document.querySelector('.container'); 76 | } 77 | 78 | private onCaptureClose() { 79 | Router.go('/list/'); 80 | delete window.PerceptionToolkit.config.cardContainer; 81 | } 82 | 83 | private async onMarkerChange(evt: Event) { 84 | const markerEvent = evt as CustomEvent<{found: any[], lost: []}>; 85 | const { found, lost } = markerEvent.detail; 86 | const currentScannedItems = await Storage.get(this.key, []); 87 | const { Card } = window.PerceptionToolkit.Elements; 88 | 89 | // Getting an event with zero diff implies an invalid 90 | if (found.length === 0 && lost.length === 0) { 91 | // Take control of the UI rendering. 92 | evt.preventDefault(); 93 | 94 | if (this.container.childNodes.length > 0) { 95 | return; 96 | } 97 | 98 | const card = new Card(); 99 | card.classList.add('not-found'); 100 | card.src = 'Sorry, that marker was not recognized.'; 101 | this.container.appendChild(card); 102 | return; 103 | } else if (found.length > 0) { 104 | // Remove any 'can not find' cards. 105 | const notFoundCards = 106 | this.container.querySelectorAll('data-card.not-found'); 107 | for (const nfCard of Array.from(notFoundCards)) { 108 | nfCard.remove(); 109 | } 110 | } 111 | 112 | // Only add new items to the scan list. 113 | for (const newItem of found) { 114 | const existingItem = currentScannedItems.find((i) => { 115 | return i.url === newItem.content.url; 116 | }); 117 | 118 | if (!existingItem) { 119 | currentScannedItems.push({...newItem.content, scanned: Date.now()}); 120 | } 121 | } 122 | 123 | // Update the stored items. 124 | await Storage.publish(this.key, currentScannedItems); 125 | } 126 | 127 | private onCameraAccessDenied() { 128 | const { Card } = window.PerceptionToolkit.Elements; 129 | const card = new Card(); 130 | card.src = 'Camera unavailable or access denied'; 131 | this.container.appendChild(card); 132 | } 133 | } 134 | 135 | export const toRemove = 'bar'; 136 | export default new Capture(); 137 | -------------------------------------------------------------------------------- /src/_includes/app.njk: -------------------------------------------------------------------------------- 1 | 17 | 18 | 19 | 20 | 21 | 22 | 33 | 34 | 35 | 36 | 37 | Google I/O - Sandbox Scanner 38 | 39 | 40 | 41 | {% if target %} 42 | 62 | 63 | 64 | 65 | {% endif %} 66 | 67 | 68 | 69 | 73 | 74 | 75 | 76 | {% set appcss %}{% include "app.css" %}{% endset %} 77 | 80 | 86 | 87 | 88 | {% if not target %}{{ title }}{% endif %} 92 | 93 |
94 | {{ content | safe }} 95 |
96 | 97 | 98 | 142 | 143 | 149 | 150 | 151 | -------------------------------------------------------------------------------- /src/scripts/router.ts: -------------------------------------------------------------------------------- 1 | /** 2 | * @license 3 | * Copyright 2019 Google LLC 4 | * 5 | * Licensed under the Apache License, Version 2.0 (the "License"); 6 | * you may not use this file except in compliance with the License. 7 | * You may obtain a copy of the License at 8 | * 9 | * https://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | 18 | interface Registration { 19 | path: RegExp; 20 | load(): Promise
; 21 | } 22 | 23 | interface DocumentParts { 24 | main?: HTMLElement; 25 | header?: HTMLElement; 26 | styles?: HTMLStyleElement; 27 | } 28 | 29 | import { Section } from './section.js'; 30 | import { loadDocument, LoadedDocument } from './utils/load-document.js'; 31 | 32 | window.addEventListener('popstate', () => processUrl()); 33 | 34 | const sections = new Map Promise
, 36 | elements: Map, 37 | module?: Section, 38 | }>(); 39 | export function register(registrations: Registration | Registration[]) { 40 | if (!Array.isArray(registrations)) { 41 | registrations = [registrations]; 42 | } 43 | 44 | for (const {path, load} of registrations) { 45 | sections.set(path, { load, elements: new Map() }); 46 | } 47 | } 48 | 49 | export async function go(url: string, data = {}) { 50 | window.history.pushState(data, '', url); 51 | await processUrl(); 52 | } 53 | 54 | function getSectionRegExp(path: string): RegExp | undefined { 55 | for (const key of sections.keys()) { 56 | if (key.test(path)) { 57 | return key; 58 | } 59 | } 60 | } 61 | 62 | function getModule(name: string): Section { 63 | const sectionRegExp = getSectionRegExp(name); 64 | if (!sectionRegExp) { 65 | throw new Error(`Unable to find section: ${name}`); 66 | } 67 | 68 | const section = sections.get(sectionRegExp); 69 | if (!section || !section.module) { 70 | throw new Error(`Unable to find module for section: ${name}`); 71 | } 72 | 73 | return section.module; 74 | } 75 | 76 | function isLoadedDoc(item: Section | LoadedDocument): item is LoadedDocument { 77 | return typeof (item as LoadedDocument).header !== 'undefined'; 78 | } 79 | 80 | let currentSection: string; 81 | async function processUrl() { 82 | // Shut down the current section. 83 | if (currentSection) { 84 | await getModule(currentSection).finish(); 85 | } 86 | 87 | // Grab the new section based on URL. 88 | const path = window.location.pathname; 89 | const sectionRegExp = getSectionRegExp(path); 90 | if (typeof sectionRegExp === 'undefined') { 91 | throw new Error(`Unknown section: ${path}`); 92 | } 93 | 94 | const section = sections.get(sectionRegExp); 95 | if (!section) { 96 | throw new Error(`Unable to find section: ${path}`); 97 | } 98 | 99 | // Load it if necessary. 100 | const toLoad: Array> = []; 101 | if (!section.module) { 102 | toLoad.push(section.load()); 103 | } 104 | 105 | if (!section.elements.get(window.location.href)) { 106 | toLoad.push(loadDocument(window.location)); 107 | } 108 | 109 | if (toLoad.length > 0) { 110 | const loadedItems = await Promise.all(toLoad); 111 | for (const item of loadedItems) { 112 | if (isLoadedDoc(item)) { 113 | section.elements.set(window.location.href, item); 114 | } else { 115 | section.module = item; 116 | } 117 | } 118 | 119 | // Store for future 120 | sections.set(sectionRegExp, section); 121 | } 122 | 123 | // if (load.length ) 124 | // const load = await Promise.all(toLoad); 125 | // section.module = load[0] as Section; 126 | 127 | // if (load.length === 2) { 128 | // const loaded = load[1] as LoadedDocument; 129 | // const documentParts = { 130 | // header: document.adoptNode(loaded.header), 131 | // main: document.adoptNode(loaded.main), 132 | // styles: document.adoptNode(loaded.styles || 133 | // document.createElement('style')) 134 | // }; 135 | 136 | // section.elements.set(window.location.href, documentParts); 137 | // } 138 | 139 | // sections.set(sectionRegExp, section); 140 | // } 141 | 142 | // If the path has changed by the end of the load then don't bother booting up 143 | // the new section. 144 | if (path !== window.location.pathname) { 145 | return; 146 | } 147 | 148 | const header = document.querySelector('app-header') as HTMLElement; 149 | header.classList.toggle('home-available', window.location.pathname !== '/'); 150 | 151 | // Replace the current section's content. 152 | if (currentSection) { 153 | const elementParts = section.elements.get(window.location.href); 154 | const main = document.querySelector('main'); 155 | if (!elementParts) { 156 | throw new Error('Section unpopulated'); 157 | } 158 | 159 | if (!main || !elementParts.main) { 160 | throw new Error('No main in document, or section unpopulated'); 161 | } 162 | 163 | // Clear out the existing main and populate with the new section's HTML. 164 | main.innerHTML = elementParts.main.innerHTML; 165 | 166 | // Next update the header. 167 | if (!header || !elementParts.header) { 168 | throw new Error('No header in document, or section unpopulated'); 169 | } 170 | 171 | const headerStyle = elementParts.header.getAttribute('style'); 172 | if (headerStyle) { 173 | header.setAttribute('style', headerStyle); 174 | } else { 175 | header.removeAttribute('style'); 176 | } 177 | 178 | header.textContent = elementParts.header.textContent; 179 | 180 | // Finally any styles. 181 | const customStyles = 182 | document.head.querySelector('style[custom]') as HTMLStyleElement; 183 | 184 | if (elementParts.styles) { 185 | customStyles.textContent = elementParts.styles.textContent; 186 | } else { 187 | customStyles.textContent = ''; 188 | } 189 | } 190 | 191 | const data = path 192 | .replace(sectionRegExp, '') 193 | .replace(/\/?$/, '') 194 | .split('/') 195 | .filter(p => !!p); 196 | currentSection = path; 197 | await getModule(currentSection).init(data); 198 | } 199 | 200 | export function init() { 201 | return processUrl(); 202 | } 203 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | 2 | Apache License 3 | Version 2.0, January 2004 4 | http://www.apache.org/licenses/ 5 | 6 | TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION 7 | 8 | 1. Definitions. 9 | 10 | "License" shall mean the terms and conditions for use, reproduction, 11 | and distribution as defined by Sections 1 through 9 of this document. 12 | 13 | "Licensor" shall mean the copyright owner or entity authorized by 14 | the copyright owner that is granting the License. 15 | 16 | "Legal Entity" shall mean the union of the acting entity and all 17 | other entities that control, are controlled by, or are under common 18 | control with that entity. For the purposes of this definition, 19 | "control" means (i) the power, direct or indirect, to cause the 20 | direction or management of such entity, whether by contract or 21 | otherwise, or (ii) ownership of fifty percent (50%) or more of the 22 | outstanding shares, or (iii) beneficial ownership of such entity. 23 | 24 | "You" (or "Your") shall mean an individual or Legal Entity 25 | exercising permissions granted by this License. 26 | 27 | "Source" form shall mean the preferred form for making modifications, 28 | including but not limited to software source code, documentation 29 | source, and configuration files. 30 | 31 | "Object" form shall mean any form resulting from mechanical 32 | transformation or translation of a Source form, including but 33 | not limited to compiled object code, generated documentation, 34 | and conversions to other media types. 35 | 36 | "Work" shall mean the work of authorship, whether in Source or 37 | Object form, made available under the License, as indicated by a 38 | copyright notice that is included in or attached to the work 39 | (an example is provided in the Appendix below). 40 | 41 | "Derivative Works" shall mean any work, whether in Source or Object 42 | form, that is based on (or derived from) the Work and for which the 43 | editorial revisions, annotations, elaborations, or other modifications 44 | represent, as a whole, an original work of authorship. For the purposes 45 | of this License, Derivative Works shall not include works that remain 46 | separable from, or merely link (or bind by name) to the interfaces of, 47 | the Work and Derivative Works thereof. 48 | 49 | "Contribution" shall mean any work of authorship, including 50 | the original version of the Work and any modifications or additions 51 | to that Work or Derivative Works thereof, that is intentionally 52 | submitted to Licensor for inclusion in the Work by the copyright owner 53 | or by an individual or Legal Entity authorized to submit on behalf of 54 | the copyright owner. For the purposes of this definition, "submitted" 55 | means any form of electronic, verbal, or written communication sent 56 | to the Licensor or its representatives, including but not limited to 57 | communication on electronic mailing lists, source code control systems, 58 | and issue tracking systems that are managed by, or on behalf of, the 59 | Licensor for the purpose of discussing and improving the Work, but 60 | excluding communication that is conspicuously marked or otherwise 61 | designated in writing by the copyright owner as "Not a Contribution." 62 | 63 | "Contributor" shall mean Licensor and any individual or Legal Entity 64 | on behalf of whom a Contribution has been received by Licensor and 65 | subsequently incorporated within the Work. 66 | 67 | 2. Grant of Copyright License. Subject to the terms and conditions of 68 | this License, each Contributor hereby grants to You a perpetual, 69 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable 70 | copyright license to reproduce, prepare Derivative Works of, 71 | publicly display, publicly perform, sublicense, and distribute the 72 | Work and such Derivative Works in Source or Object form. 73 | 74 | 3. Grant of Patent License. Subject to the terms and conditions of 75 | this License, each Contributor hereby grants to You a perpetual, 76 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable 77 | (except as stated in this section) patent license to make, have made, 78 | use, offer to sell, sell, import, and otherwise transfer the Work, 79 | where such license applies only to those patent claims licensable 80 | by such Contributor that are necessarily infringed by their 81 | Contribution(s) alone or by combination of their Contribution(s) 82 | with the Work to which such Contribution(s) was submitted. If You 83 | institute patent litigation against any entity (including a 84 | cross-claim or counterclaim in a lawsuit) alleging that the Work 85 | or a Contribution incorporated within the Work constitutes direct 86 | or contributory patent infringement, then any patent licenses 87 | granted to You under this License for that Work shall terminate 88 | as of the date such litigation is filed. 89 | 90 | 4. Redistribution. You may reproduce and distribute copies of the 91 | Work or Derivative Works thereof in any medium, with or without 92 | modifications, and in Source or Object form, provided that You 93 | meet the following conditions: 94 | 95 | (a) You must give any other recipients of the Work or 96 | Derivative Works a copy of this License; and 97 | 98 | (b) You must cause any modified files to carry prominent notices 99 | stating that You changed the files; and 100 | 101 | (c) You must retain, in the Source form of any Derivative Works 102 | that You distribute, all copyright, patent, trademark, and 103 | attribution notices from the Source form of the Work, 104 | excluding those notices that do not pertain to any part of 105 | the Derivative Works; and 106 | 107 | (d) If the Work includes a "NOTICE" text file as part of its 108 | distribution, then any Derivative Works that You distribute must 109 | include a readable copy of the attribution notices contained 110 | within such NOTICE file, excluding those notices that do not 111 | pertain to any part of the Derivative Works, in at least one 112 | of the following places: within a NOTICE text file distributed 113 | as part of the Derivative Works; within the Source form or 114 | documentation, if provided along with the Derivative Works; or, 115 | within a display generated by the Derivative Works, if and 116 | wherever such third-party notices normally appear. The contents 117 | of the NOTICE file are for informational purposes only and 118 | do not modify the License. You may add Your own attribution 119 | notices within Derivative Works that You distribute, alongside 120 | or as an addendum to the NOTICE text from the Work, provided 121 | that such additional attribution notices cannot be construed 122 | as modifying the License. 123 | 124 | You may add Your own copyright statement to Your modifications and 125 | may provide additional or different license terms and conditions 126 | for use, reproduction, or distribution of Your modifications, or 127 | for any such Derivative Works as a whole, provided Your use, 128 | reproduction, and distribution of the Work otherwise complies with 129 | the conditions stated in this License. 130 | 131 | 5. Submission of Contributions. Unless You explicitly state otherwise, 132 | any Contribution intentionally submitted for inclusion in the Work 133 | by You to the Licensor shall be under the terms and conditions of 134 | this License, without any additional terms or conditions. 135 | Notwithstanding the above, nothing herein shall supersede or modify 136 | the terms of any separate license agreement you may have executed 137 | with Licensor regarding such Contributions. 138 | 139 | 6. Trademarks. This License does not grant permission to use the trade 140 | names, trademarks, service marks, or product names of the Licensor, 141 | except as required for reasonable and customary use in describing the 142 | origin of the Work and reproducing the content of the NOTICE file. 143 | 144 | 7. Disclaimer of Warranty. Unless required by applicable law or 145 | agreed to in writing, Licensor provides the Work (and each 146 | Contributor provides its Contributions) on an "AS IS" BASIS, 147 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or 148 | implied, including, without limitation, any warranties or conditions 149 | of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A 150 | PARTICULAR PURPOSE. You are solely responsible for determining the 151 | appropriateness of using or redistributing the Work and assume any 152 | risks associated with Your exercise of permissions under this License. 153 | 154 | 8. Limitation of Liability. In no event and under no legal theory, 155 | whether in tort (including negligence), contract, or otherwise, 156 | unless required by applicable law (such as deliberate and grossly 157 | negligent acts) or agreed to in writing, shall any Contributor be 158 | liable to You for damages, including any direct, indirect, special, 159 | incidental, or consequential damages of any character arising as a 160 | result of this License or out of the use or inability to use the 161 | Work (including but not limited to damages for loss of goodwill, 162 | work stoppage, computer failure or malfunction, or any and all 163 | other commercial damages or losses), even if such Contributor 164 | has been advised of the possibility of such damages. 165 | 166 | 9. Accepting Warranty or Additional Liability. While redistributing 167 | the Work or Derivative Works thereof, You may choose to offer, 168 | and charge a fee for, acceptance of support, warranty, indemnity, 169 | or other liability obligations and/or rights consistent with this 170 | License. However, in accepting such obligations, You may act only 171 | on Your own behalf and on Your sole responsibility, not on behalf 172 | of any other Contributor, and only if You agree to indemnify, 173 | defend, and hold each Contributor harmless for any liability 174 | incurred by, or claims asserted against, such Contributor by reason 175 | of your accepting any such warranty or additional liability. 176 | 177 | END OF TERMS AND CONDITIONS 178 | 179 | APPENDIX: How to apply the Apache License to your work. 180 | 181 | To apply the Apache License to your work, attach the following 182 | boilerplate notice, with the fields enclosed by brackets "[]" 183 | replaced with your own identifying information. (Don't include 184 | the brackets!) The text should be enclosed in the appropriate 185 | comment syntax for the file format. We also recommend that a 186 | file or class name and description of purpose be included on the 187 | same "printed page" as the copyright notice for easier 188 | identification within third-party archives. 189 | 190 | Copyright [yyyy] [name of copyright owner] 191 | 192 | Licensed under the Apache License, Version 2.0 (the "License"); 193 | you may not use this file except in compliance with the License. 194 | You may obtain a copy of the License at 195 | 196 | http://www.apache.org/licenses/LICENSE-2.0 197 | 198 | Unless required by applicable law or agreed to in writing, software 199 | distributed under the License is distributed on an "AS IS" BASIS, 200 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 201 | See the License for the specific language governing permissions and 202 | limitations under the License. 203 | --------------------------------------------------------------------------------