@stylable/runtime
Advanced tools
Comparing version 2.3.3-alpha.0 to 2.3.3-alpha.1
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
var CacheStyleNodeRenderer = /** @class */ (function () { | ||
function CacheStyleNodeRenderer(options) { | ||
var _this = this; | ||
class CacheStyleNodeRenderer { | ||
constructor(options) { | ||
this.options = options; | ||
this.create = function (stylesheet, key) { | ||
var node = _this.options.createElement('style'); | ||
this.create = (stylesheet, key) => { | ||
const node = this.options.createElement('style'); | ||
node.textContent = stylesheet.$css || ''; | ||
node.setAttribute(_this.options.attrKey, key); | ||
node.setAttribute(this.options.attrKey, key); | ||
node.setAttribute('st-depth', stylesheet.$depth + ''); | ||
return node; | ||
}; | ||
this.hasKey = function (node) { return node.hasAttribute(_this.options.attrKey); }; | ||
this.update = function (stylesheet, node) { | ||
this.hasKey = (node) => node.hasAttribute(this.options.attrKey); | ||
this.update = (stylesheet, node) => { | ||
if (node.textContent !== stylesheet.$css) { | ||
@@ -21,7 +20,6 @@ node.textContent = stylesheet.$css || ''; | ||
}; | ||
this.renderKey = function (stylesheet) { return stylesheet.$id; }; | ||
this.renderKey = (stylesheet) => stylesheet.$id; | ||
} | ||
return CacheStyleNodeRenderer; | ||
}()); | ||
} | ||
exports.CacheStyleNodeRenderer = CacheStyleNodeRenderer; | ||
//# sourceMappingURL=cached-node-renderer.js.map |
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
var cached_node_renderer_1 = require("./cached-node-renderer"); | ||
var keyed_list_renderer_1 = require("./keyed-list-renderer"); | ||
var RuntimeRenderer = /** @class */ (function () { | ||
function RuntimeRenderer() { | ||
var _this = this; | ||
const cached_node_renderer_1 = require("./cached-node-renderer"); | ||
const keyed_list_renderer_1 = require("./keyed-list-renderer"); | ||
class RuntimeRenderer { | ||
constructor() { | ||
this.styles = []; | ||
@@ -13,9 +12,9 @@ this.stylesMap = {}; | ||
this.id = null; | ||
this.update = function () { | ||
if (_this.renderer) { | ||
_this.renderer.render(_this.window.document.head, _this.styles); | ||
this.update = () => { | ||
if (this.renderer) { | ||
this.renderer.render(this.window.document.head, this.styles); | ||
} | ||
}; | ||
} | ||
RuntimeRenderer.prototype.init = function (_window) { | ||
init(_window) { | ||
if (this.window || !_window) { | ||
@@ -33,20 +32,20 @@ return; | ||
this.update(); | ||
}; | ||
RuntimeRenderer.prototype.onRegister = function () { | ||
} | ||
onRegister() { | ||
if (this.window) { | ||
this.window.requestAnimationFrame(this.update); | ||
} | ||
}; | ||
RuntimeRenderer.prototype.register = function (stylesheet) { | ||
var registered = this.stylesMap[stylesheet.$id]; | ||
} | ||
register(stylesheet) { | ||
const registered = this.stylesMap[stylesheet.$id]; | ||
if (registered) { | ||
this.removeStyle(registered); | ||
} | ||
var i = this.findDepthIndex(stylesheet.$depth); | ||
const i = this.findDepthIndex(stylesheet.$depth); | ||
this.styles.splice(i + 1, 0, stylesheet); | ||
this.stylesMap[stylesheet.$id] = stylesheet; | ||
this.onRegister(); | ||
}; | ||
RuntimeRenderer.prototype.removeStyle = function (stylesheet) { | ||
var i = this.styles.indexOf(stylesheet); | ||
} | ||
removeStyle(stylesheet) { | ||
const i = this.styles.indexOf(stylesheet); | ||
if (~i) { | ||
@@ -56,7 +55,7 @@ this.styles.splice(i, 1); | ||
delete this.stylesMap[stylesheet.$id]; | ||
}; | ||
RuntimeRenderer.prototype.findDepthIndex = function (depth) { | ||
var index = this.styles.length; | ||
} | ||
findDepthIndex(depth) { | ||
let index = this.styles.length; | ||
while (index--) { | ||
var stylesheet = this.styles[index]; | ||
const stylesheet = this.styles[index]; | ||
if (stylesheet.$depth <= depth) { | ||
@@ -67,23 +66,19 @@ return index; | ||
return index; | ||
}; | ||
RuntimeRenderer.prototype.getStyles = function (ids, sortIndexes) { | ||
var _this = this; | ||
return this.sortStyles(ids.map(function (id) { return _this.stylesMap[id]; }), sortIndexes); | ||
}; | ||
RuntimeRenderer.prototype.sortStyles = function (styles, sortIndexes) { | ||
var _this = this; | ||
if (sortIndexes === void 0) { sortIndexes = false; } | ||
var s = styles.slice(); | ||
} | ||
getStyles(ids, sortIndexes) { | ||
return this.sortStyles(ids.map(id => this.stylesMap[id]), sortIndexes); | ||
} | ||
sortStyles(styles, sortIndexes = false) { | ||
const s = styles.slice(); | ||
if (sortIndexes) { | ||
s.sort(function (a, b) { | ||
return _this.styles.indexOf(a) - _this.styles.indexOf(b); | ||
s.sort((a, b) => { | ||
return this.styles.indexOf(a) - this.styles.indexOf(b); | ||
}); | ||
} | ||
s.sort(function (a, b) { | ||
s.sort((a, b) => { | ||
return a.$depth - b.$depth; | ||
}); | ||
return s; | ||
}; | ||
return RuntimeRenderer; | ||
}()); | ||
} | ||
} | ||
exports.RuntimeRenderer = RuntimeRenderer; | ||
@@ -90,0 +85,0 @@ // The $ export is a convention with the webpack plugin if changed both needs a change |
"use strict"; | ||
var __assign = (this && this.__assign) || function () { | ||
__assign = Object.assign || function(t) { | ||
for (var s, i = 1, n = arguments.length; i < n; i++) { | ||
s = arguments[i]; | ||
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p)) | ||
t[p] = s[p]; | ||
} | ||
return t; | ||
}; | ||
return __assign.apply(this, arguments); | ||
}; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
var css_runtime_stylesheet_1 = require("./css-runtime-stylesheet"); | ||
const css_runtime_stylesheet_1 = require("./css-runtime-stylesheet"); | ||
// If you see this code and don't know anything about it don't change it. | ||
// Because Barak made a custom bundler we can only support one api export name. | ||
// In order to create legacy api support we allow duplicate export that we know we can override in the bundle. | ||
var newCreate = css_runtime_stylesheet_1.create; | ||
const newCreate = css_runtime_stylesheet_1.create; | ||
function create(namespace, exports, css, depth, id, renderer) { | ||
var stylesheet = newCreate(namespace, exports, css, depth, id, renderer); | ||
const stylesheet = newCreate(namespace, exports, css, depth, id, renderer); | ||
function $cssStates(stateMapping) { | ||
@@ -32,3 +21,3 @@ return { | ||
.split(/\s+/g) | ||
.map(function (className) { return stylesheet.classes[className] || className; }) | ||
.map(className => stylesheet.classes[className] || className) | ||
.join(' '); | ||
@@ -39,3 +28,3 @@ } | ||
if (states) { | ||
var stateClasses = stylesheet.cssStates(states); | ||
const stateClasses = stylesheet.cssStates(states); | ||
if (stateClasses) { | ||
@@ -45,5 +34,5 @@ className += className ? ' ' + stateClasses : stateClasses; | ||
} | ||
var base = {}; | ||
const base = {}; | ||
if (inheritedAttributes) { | ||
for (var k in inheritedAttributes) { | ||
for (const k in inheritedAttributes) { | ||
if (k.match(/^data-/)) { | ||
@@ -64,4 +53,4 @@ base[k] = inheritedAttributes[k]; | ||
} | ||
Object.setPrototypeOf(stylable_runtime_stylesheet, __assign(__assign(__assign({ $root: 'root' }, stylesheet.stVars), stylesheet.classes), { $namespace: stylesheet.namespace, $depth: stylesheet.$depth, $id: stylesheet.$id, $css: stylesheet.$css, $get: $get, | ||
$cssStates: $cssStates })); | ||
Object.setPrototypeOf(stylable_runtime_stylesheet, Object.assign(Object.assign(Object.assign({ $root: 'root' }, stylesheet.stVars), stylesheet.classes), { $namespace: stylesheet.namespace, $depth: stylesheet.$depth, $id: stylesheet.$id, $css: stylesheet.$css, $get, | ||
$cssStates })); | ||
// EDGE CACHE BUG FIX | ||
@@ -68,0 +57,0 @@ stylable_runtime_stylesheet.root = stylesheet.classes.root; |
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
var stateMiddleDelimiter = '-'; | ||
var booleanStateDelimiter = '--'; | ||
var stateWithParamDelimiter = '---'; | ||
const stateMiddleDelimiter = '-'; | ||
const booleanStateDelimiter = '--'; | ||
const stateWithParamDelimiter = '---'; | ||
function create(namespace, exports, css, depth, id, renderer) { | ||
var stylesheet = { | ||
namespace: namespace, | ||
const stylesheet = { | ||
namespace, | ||
classes: exports.classes, | ||
@@ -13,4 +13,4 @@ keyframes: exports.keyframes, | ||
stVars: exports.stVars, | ||
cssStates: cssStates, | ||
style: style, | ||
cssStates, | ||
style, | ||
st: style, | ||
@@ -25,6 +25,6 @@ $id: id, | ||
function cssStates(stateMapping) { | ||
var classNames = []; | ||
for (var stateName in stateMapping) { | ||
var stateValue = stateMapping[stateName]; | ||
var stateClass = createStateClass(stateName, stateValue); | ||
const classNames = []; | ||
for (const stateName in stateMapping) { | ||
const stateValue = stateMapping[stateName]; | ||
const stateClass = createStateClass(stateName, stateValue); | ||
if (stateClass) { | ||
@@ -37,7 +37,7 @@ classNames.push(stateClass); | ||
function createBooleanStateClassName(stateName) { | ||
return "" + namespace + booleanStateDelimiter + stateName; | ||
return `${namespace}${booleanStateDelimiter}${stateName}`; | ||
} | ||
function createStateWithParamClassName(stateName, param) { | ||
// tslint:disable-next-line: max-line-length | ||
return "" + namespace + stateWithParamDelimiter + stateName + stateMiddleDelimiter + param.length + stateMiddleDelimiter + param.replace(/\s/gm, '_'); | ||
return `${namespace}${stateWithParamDelimiter}${stateName}${stateMiddleDelimiter}${param.length}${stateMiddleDelimiter}${param.replace(/\s/gm, '_')}`; | ||
} | ||
@@ -55,10 +55,10 @@ function createStateClass(stateName, stateValue) { | ||
} | ||
var valueAsString = stateValue.toString(); | ||
const valueAsString = stateValue.toString(); | ||
return createStateWithParamClassName(stateName, valueAsString); | ||
} | ||
function style() { | ||
var classNames = []; | ||
const classNames = []; | ||
// tslint:disable-next-line:prefer-for-of | ||
for (var i = 0; i < arguments.length; i++) { | ||
var item = arguments[i]; | ||
for (let i = 0; i < arguments.length; i++) { | ||
const item = arguments[i]; | ||
if (item) { | ||
@@ -69,5 +69,5 @@ if (typeof item === 'string') { | ||
else if (i === 1) { | ||
for (var stateName in item) { | ||
var stateValue = item[stateName]; | ||
var stateClass = createStateClass(stateName, stateValue); | ||
for (const stateName in item) { | ||
const stateValue = item[stateName]; | ||
const stateClass = createStateClass(stateName, stateValue); | ||
if (stateClass) { | ||
@@ -74,0 +74,0 @@ classNames[classNames.length] = stateClass; |
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
function createDOMListRenderer(nodeRenderer) { | ||
var first; | ||
var nodes = {}; | ||
var setNode = function (dataItem, node) { | ||
return (nodes[nodeRenderer.renderKey(dataItem)] = node); | ||
}; | ||
var renderNode = function (dataItem) { | ||
var key = nodeRenderer.renderKey(dataItem); | ||
var node = nodes[key]; | ||
let first; | ||
const nodes = {}; | ||
const setNode = (dataItem, node) => (nodes[nodeRenderer.renderKey(dataItem)] = node); | ||
const renderNode = (dataItem) => { | ||
const key = nodeRenderer.renderKey(dataItem); | ||
const node = nodes[key]; | ||
return node | ||
@@ -16,9 +14,8 @@ ? nodeRenderer.update(dataItem, node) | ||
}; | ||
var render = function (container, data) { | ||
if (data === void 0) { data = []; } | ||
var node; | ||
const render = (container, data = []) => { | ||
let node; | ||
if (data.length) { | ||
var next = first; | ||
let next = first; | ||
// tslint:disable-next-line:prefer-for-of | ||
for (var i = 0; i < data.length; i++) { | ||
for (let i = 0; i < data.length; i++) { | ||
node = renderNode(data[i]); | ||
@@ -44,3 +41,3 @@ if (node !== next) { | ||
while (first) { | ||
var next = first.nextElementSibling; | ||
const next = first.nextElementSibling; | ||
container.removeChild(first); | ||
@@ -51,5 +48,5 @@ first = next && nodeRenderer.hasKey(next) ? next : undefined; | ||
}; | ||
return { render: render, nodes: nodes }; | ||
return { render, nodes }; | ||
} | ||
exports.createDOMListRenderer = createDOMListRenderer; | ||
//# sourceMappingURL=keyed-list-renderer.js.map |
{ | ||
"name": "@stylable/runtime", | ||
"version": "2.3.3-alpha.0", | ||
"version": "2.3.3-alpha.1", | ||
"description": "Stylable runtime DOM integration", | ||
@@ -31,3 +31,3 @@ "main": "cjs/index.js", | ||
"license": "BSD-3-Clause", | ||
"gitHead": "a8fb880ad95147f02bfe18631167e0e9d6abd942" | ||
"gitHead": "9dfdbda11e88cfd20459ec0e3fbdca24f2e2223b" | ||
} |
@@ -1,2 +0,2 @@ | ||
/* runtime version: 2.3.3-alpha.0 */ | ||
/* runtime version: 2.3.3-alpha.1 */ | ||
function StylableRuntime(exports){ | ||
@@ -3,0 +3,0 @@ exports = exports || {}; |
@@ -1,2 +0,2 @@ | ||
/* runtime version: 2.3.3-alpha.0 */ | ||
/* runtime version: 2.3.3-alpha.1 */ | ||
function StylableRuntime(exports){ | ||
@@ -3,0 +3,0 @@ exports = exports || {}; |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
71617
1349