-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathyss.min.js.map
1 lines (1 loc) · 12 KB
/
yss.min.js.map
1
{"version":3,"file":"yss.min.js","sources":["src/utils.js","src/render.js","src/helpers.js","src/index.js"],"sourcesContent":["'use strict'\n\nvar KEBAB_REGEX = /[A-Z\\u00C0-\\u00D6\\u00D8-\\u00DE]/g\n\nexport function kebabCase(str) {\n return str.replace(KEBAB_REGEX, match => `-${match.toLowerCase()}`)\n}\n\nexport function camelize(s) {\n return s.replace(/-([a-z])/g, g => g[1].toUpperCase())\n}\n\nexport function cleanSplit(s, regExp) {\n return s\n .split(regExp)\n .map(a => a.trim())\n .filter(a => a)\n}\n\nexport function isObject(thing) {\n return typeof thing === 'object'\n}\n\nexport function toAlphabetNumber(number) {\n return number.toString(36)\n}\n\nexport function getClassName(n) {\n return '.y' + toAlphabetNumber(n)\n}\n\nexport const keys = Object.keys\nexport function map(obj, fn) {\n return Object.keys(obj).map(key => fn(obj[key], key))\n}\n","'use strict'\n\nimport { kebabCase, map, toAlphabetNumber, keys } from './utils'\n\nfunction isAttr(attr) {\n return attr[0] !== ':' && attr[0] !== ' ' && attr[0] !== '@'\n}\n\nfunction isSubselector(attr) {\n return attr[0] === ':' || attr[0] === ' '\n}\n\nfunction isMediaQuery(attr) {\n return attr[0] === '@'\n}\n\nconst animationNameByStyle = {}\nlet animationCounter = 0\nexport default function (style) {\n const usedAnimations = {}\n function toCssDefinition(cssClass, style) {\n const baseStyle = keys(style)\n .filter(isAttr)\n .map(attr => {\n let value = style[attr]\n if (attr === 'animation') {\n const frameStyles = style[attr].frameStyles\n const animationStyle = map(frameStyles, (y, frameName) =>\n toCssDefinition(frameName, y.style)\n ).join('')\n if (!animationNameByStyle[animationStyle]) {\n animationNameByStyle[animationStyle] =\n 'a' + toAlphabetNumber(animationCounter++)\n }\n usedAnimations[animationStyle] = animationNameByStyle[animationStyle]\n value = `${style[attr].timing || ''} ${\n animationNameByStyle[animationStyle]\n }`\n }\n return `${kebabCase(attr)}:${value}`\n })\n .join(';')\n const subStyles = keys(style)\n .filter(isSubselector)\n .map(pseudo => toCssDefinition(cssClass + pseudo, style[pseudo].style))\n .join('')\n const mediaStyles = keys(style)\n .filter(isMediaQuery)\n .map(\n mediaQuery =>\n `${mediaQuery}{${toCssDefinition(\n `${cssClass}`,\n style[mediaQuery].style\n )}}`\n )\n .join('')\n return `${cssClass}{${baseStyle}}${subStyles}${mediaStyles}`\n }\n\n const styles = keys(style)\n .map(function (cssClass) {\n return `${toCssDefinition(cssClass, style[cssClass])}`\n })\n .join('')\n const keyframes = map(\n usedAnimations,\n (name, keyframeStyle) => `@keyframes ${name}{${keyframeStyle}}`\n ).join('')\n return keyframes + styles\n}\n","'use strict'\n\nexport function nest(y, selector, style) {\n y.style[` ${selector}`] = y.yss(style)\n}\n\nexport function media(y, def, style) {\n y.style[`@media ${def}`] = y.yss(style)\n}\n\nexport function animate(y, timing, frameStyles) {\n y.style.animation = { frameStyles, timing }\n}\n\nexport function pseudo(yss, name, helperName = name) {\n const selector = `:${name}`\n yss.helper(helperName, (y, key, ...args) => {\n if (!y.style[selector] || !y.style[selector].style) {\n y.style[selector] = yss(y.style[selector])\n }\n y.style[selector](key, ...args)\n })\n}\n","'use strict'\nimport {\n camelize,\n cleanSplit,\n isObject,\n toAlphabetNumber,\n getClassName,\n} from './utils'\nimport render from './render'\nimport { nest, media, animate, pseudo } from './helpers'\n\nlet classCounter = 0\nfunction Yss(opts = {}) {\n const classNamesByStyle = {}\n opts = Object.assign(\n {\n getClassName,\n render,\n },\n opts\n )\n\n // this is the prototype of a styling instance.\n const baseInstance = {\n get class() {\n const serializedStyle = JSON.stringify(this.style)\n const existingClassname = classNamesByStyle[serializedStyle]\n if (existingClassname) {\n return existingClassname\n }\n const className = opts.getClassName(classCounter++, this.style)\n classNamesByStyle[serializedStyle] = className\n yss.style[className] = this.style\n return className\n },\n toString: function () {\n return this.class\n },\n toJSON: function () {\n return this.style\n },\n get className() {\n return this.class.slice(1)\n },\n }\n Object.setPrototypeOf(baseInstance, function () {})\n\n function parseStyle(styleInstance, key, ...args) {\n if (typeof key === 'string' && !args[0]) {\n // plain string, parse like template string\n key = [key]\n }\n if (Array.isArray(key)) {\n // template string\n // fold string array with args\n const string = key\n .map((part, i) => part + (args[i] == null ? '' : args[i]))\n .join('')\n // build style object\n return cleanSplit(string, /[;\\n]/).reduce((style, row) => {\n let [key, ...value] = cleanSplit(row, /[ :]/)\n const prop = camelize(key)\n // if there is a helper with prop name, use it\n if (styleInstance[prop]) {\n styleInstance[prop](...value)\n } else {\n style[prop] = value.join(' ')\n }\n return style\n }, {})\n }\n if (key && key.style) {\n // merge instances\n return key.style\n }\n if (args[0]) {\n // key/value definition\n return { [key]: args[0] }\n }\n return key // object\n }\n\n // this creates a styling instance and hooks the upper prototype to it\n function yss(...args) {\n function styleInstance(...styleArgs) {\n Object.assign(\n styleInstance.style,\n parseStyle(styleInstance, ...styleArgs)\n )\n return styleInstance\n }\n styleInstance.style = {}\n styleInstance.yss = yss\n Object.setPrototypeOf(styleInstance, baseInstance)\n return styleInstance(...args)\n }\n\n yss.style = {}\n Object.defineProperty(yss, 'css', {\n get: () => opts.render(yss.style),\n })\n\n // this is the function to create helpers. Helpers are attached to the prototype of the styling\n // instances and to yss itself. When called on yss, they automatically create an instance and\n // and call the helpers on them right away\n yss.helper = function (name, ...args) {\n if (isObject(name)) {\n // define multiple helpers at once\n const helpers = name\n for (name in helpers) {\n yss.helper(name, helpers[name])\n }\n return\n }\n let fn = args[0]\n if (\n typeof args[0] === 'string' ||\n Array.isArray(args[0]) ||\n args[0].style\n ) {\n fn = y => y(...args)\n }\n if (fn.length === 1) {\n // set to baseInstance\n Object.defineProperty(baseInstance, name, {\n get: function () {\n fn(this)\n return this\n },\n })\n // set to yss itself\n Object.defineProperty(yss, name, {\n // create an instance and call helper right away\n get: () => yss({})[name],\n })\n } else {\n // set to baseInstance\n baseInstance[name] = function (...args) {\n fn(this, ...args)\n return this\n }\n // set to yss itself\n yss[name] = (...args) => yss({})[name](...args)\n }\n }\n\n // add default helpers\n yss.helper('nest', nest)\n yss.helper('media', media)\n yss.helper('animate', animate)\n pseudo(yss, 'hover')\n pseudo(yss, 'focus')\n\n return yss\n}\n\nexport default Yss\n"],"names":["KEBAB_REGEX","cleanSplit","s","regExp","split","map","a","trim","filter","toAlphabetNumber","number","toString","getClassName","n","const","keys","Object","obj","fn","key","isAttr","attr","isSubselector","isMediaQuery","animationNameByStyle","animationCounter","style","usedAnimations","toCssDefinition","cssClass","baseStyle","let","animationStyle","value","frameStyles","y","frameName","join","timing","replace","match","toLowerCase","subStyles","pseudo","mediaStyles","mediaQuery","styles","name","keyframeStyle","nest","selector","yss","media","def","animate","animation","helperName","helper","args","classCounter","opts","classNamesByStyle","assign","render","baseInstance","class","serializedStyle","JSON","stringify","this","existingClassname","className","toJSON","slice","parseStyle","styleInstance","Array","isArray","part","i","reduce","row","prop","g","toUpperCase","styleArgs","setPrototypeOf","defineProperty","get","length","ref","helpers"],"mappings":"mOAEA,IAAIA,EAAc,mCAUX,SAASC,EAAWC,EAAGC,GAC5B,OAAOD,EACJE,MAAMD,GACNE,aAAIC,UAAKA,EAAEC,SACXC,gBAAOF,UAAKA,IAOV,SAASG,EAAiBC,GAC/B,OAAOA,EAAOC,SAAS,IAGlB,SAASC,EAAaC,GAC3B,MAAO,KAAOJ,EAAiBI,GAG1BC,IAAMC,EAAOC,OAAOD,KACpB,SAASV,EAAIY,EAAKC,GACvB,OAAOF,OAAOD,KAAKE,GAAKZ,aAAIc,UAAOD,EAAGD,EAAIE,GAAMA,KC7BlD,SAASC,EAAOC,GACd,MAAmB,MAAZA,EAAK,IAA0B,MAAZA,EAAK,IAA0B,MAAZA,EAAK,GAGpD,SAASC,EAAcD,GACrB,MAAmB,MAAZA,EAAK,IAA0B,MAAZA,EAAK,GAGjC,SAASE,EAAaF,GACpB,MAAmB,MAAZA,EAAK,GAGdP,IAAMU,EAAuB,GACzBC,EAAmB,EACR,WAA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