This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* requestPlaylist: Callback for the say_request_playlist intent | |
* @param {Object} assistant Assistant instance. | |
*/ | |
const requestPlaylist = function(assistant) { | |
// formatted data from current intent | |
let artists = assistant.data.artist || []; | |
let genres = assistant.data.genre || []; | |
let moods = assistant.data.mood || []; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// On fetch | |
// ... | |
if (event.request.headers.get('accept').includes('text/html')) { | |
event.respondWith(toolbox.networkFirst(event.request)); | |
return; | |
} | |
// ... | |
// Runtime cache configuration, using the sw-toolbox library. | |
toolbox.router.get(/^https:\/\/images\.contentful\.com/, toolbox.cacheFirst, {}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
export const getImageWidthByUserContext = (width, MAX_WIDTH = 2880) => { | |
if (typeof(window) === 'undefined') return width; | |
// Pixel ratio | |
let qualityRatio = window.devicePixelRatio ? window.devicePixelRatio : 1; | |
// If bad connection, we downgrade | |
let type = null; | |
if (navigator && navigator.connection && navigator.connection.type) type = navigator.connection.type; | |
if (navigator && navigator.connection && navigator.connection.effectiveType) type = navigator.connection.effectiveType; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import tinycolor from 'tinycolor2'; | |
import VARS from 'base/vars'; | |
// https://www.w3.org/TR/WCAG20/#contrast-ratiodef | |
export const CONTRAST_RATIO = 3.1; | |
/* | |
* @name getValidColor | |
* @description Returns a color that satisfies that contrast color check between a background color and a text color. | |
* @param backgroundColor {string} Hexadecimal value of the background color |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
* Based on https://medium.freecodecamp.org/reducing-css-bundle-size-70-by-cutting-the-class-names-and-using-scope-isolation-625440de600b | |
* Creates a shared dictionnary for client and server side classname rendering | |
*/ | |
const incstr = require('incstr'); | |
const fs = require('fs'); | |
const jsonfile = require('jsonfile'); | |
// creates dictionnary file if doesn't exists |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import React, {PropTypes, Component} from 'react'; | |
import Loadable from 'react-loadable'; | |
class ExperiencePageComponent extends Component { | |
render() { | |
const { data } = this.props; | |
let LoadableComponent = null; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class LottieWebAnimation extends React.Component { | |
/* | |
.. render()... | |
*/ | |
// Capturing mouse move | |
onMouseMove = (e) => { | |
this.mouseCoords.x = e.clientX || e.pageX; | |
this.mouseCoords.y = e.clientY || e.pageY; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Update the path of the assets in the animation data to use CMS assets instead (optmized) | |
const updateAnimationData = (assets, animationData, maxAssetWidth) => { | |
const refIdDictionary = []; | |
animationData.assets.forEach((asset, i) => { | |
if (!asset.u || !asset.id) return; | |
// replace id | |
const newId = asset.p.split('.')[0]; | |
const prevId = asset.id !== newId ? asset.id : `image_${i}`; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Here is a simple class that contains loading methods. | |
// Nothing fancy, but the idea is simply to return a Promise | |
import { loadImg } from './load'; | |
class Sprite { | |
/* | |
@Example | |
import Sprite from './Sprite'; |