@stylable/runtime
Advanced tools
Comparing version 2.1.3 to 2.1.4-alpha.0
@@ -14,5 +14,5 @@ import { DOMListRenderer } from './keyed-list-renderer'; | ||
renderer: DOMListRenderer<RenderableStylesheet, HTMLStyleElement> | null; | ||
window: typeof window | null; | ||
window: Window | null; | ||
id: number | null; | ||
init(_window: typeof window): void; | ||
init(_window: Window): void; | ||
update: () => void; | ||
@@ -19,0 +19,0 @@ onRegister(): void; |
@@ -61,3 +61,3 @@ "use strict"; | ||
} | ||
Object.setPrototypeOf(stylable_runtime_stylesheet, __assign({ $root: 'root' }, stylesheet.stVars, stylesheet.classes, { $namespace: stylesheet.namespace, $depth: stylesheet.$depth, $id: stylesheet.$id, $css: stylesheet.$css, $get: $get, | ||
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 })); | ||
@@ -64,0 +64,0 @@ // EDGE CACHE BUG FIX |
{ | ||
"name": "@stylable/runtime", | ||
"version": "2.1.3", | ||
"version": "2.1.4-alpha.0", | ||
"description": "Stylable runtime DOM integration", | ||
@@ -32,3 +32,3 @@ "main": "cjs/index.js", | ||
"license": "BSD-3-Clause", | ||
"gitHead": "dcc4099d179ea4fdf3adc54c325b6175ff484266" | ||
"gitHead": "afc507c97909ce8d221ca4dc90344fadbc0e385a" | ||
} |
@@ -1,2 +0,2 @@ | ||
/* runtime version: 2.1.3 */ | ||
/* runtime version: 2.1.4-alpha.0 */ | ||
function StylableRuntime(exports){ | ||
@@ -311,3 +311,3 @@ exports = exports || {}; | ||
} | ||
Object.setPrototypeOf(stylable_runtime_stylesheet, __assign({ $root: 'root' }, stylesheet.stVars, stylesheet.classes, { $namespace: stylesheet.namespace, $depth: stylesheet.$depth, $id: stylesheet.$id, $css: stylesheet.$css, $get: $get, | ||
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 })); | ||
@@ -314,0 +314,0 @@ // EDGE CACHE BUG FIX |
@@ -1,2 +0,2 @@ | ||
/* runtime version: 2.1.3 */ | ||
/* runtime version: 2.1.4-alpha.0 */ | ||
function StylableRuntime(exports){ | ||
@@ -3,0 +3,0 @@ exports = exports || {}; |
@@ -6,90 +6,90 @@ import { CacheStyleNodeRenderer } from './cached-node-renderer'; | ||
declare global { | ||
interface Window { | ||
__stylable_renderer_global_counter?: number; | ||
} | ||
interface Window { | ||
__stylable_renderer_global_counter?: number; | ||
} | ||
} | ||
export class RuntimeRenderer { | ||
public styles: RenderableStylesheet[] = []; | ||
public stylesMap: { [id: string]: RenderableStylesheet } = {}; | ||
public renderer: DOMListRenderer<RenderableStylesheet, HTMLStyleElement> | null = null; | ||
public window: typeof window | null = null; | ||
public id: number | null = null; | ||
public styles: RenderableStylesheet[] = []; | ||
public stylesMap: { [id: string]: RenderableStylesheet } = {}; | ||
public renderer: DOMListRenderer<RenderableStylesheet, HTMLStyleElement> | null = null; | ||
public window: Window | null = null; | ||
public id: number | null = null; | ||
public init(_window: typeof window) { | ||
if (this.window || !_window) { | ||
return; | ||
} | ||
public init(_window: Window) { | ||
if (this.window || !_window) { | ||
return; | ||
} | ||
_window.__stylable_renderer_global_counter = | ||
_window.__stylable_renderer_global_counter || 0; | ||
this.id = _window.__stylable_renderer_global_counter++; | ||
_window.__stylable_renderer_global_counter = | ||
_window.__stylable_renderer_global_counter || 0; | ||
this.id = _window.__stylable_renderer_global_counter++; | ||
this.window = _window; | ||
this.renderer = createDOMListRenderer( | ||
new CacheStyleNodeRenderer({ | ||
attrKey: 'st-id' + (this.id ? '-' + this.id : ''), | ||
createElement: _window.document.createElement.bind(_window.document) | ||
}) | ||
); | ||
this.update(); | ||
} | ||
public update = () => { | ||
if (this.renderer) { | ||
this.renderer.render(this.window!.document.head!, this.styles); | ||
this.window = _window; | ||
this.renderer = createDOMListRenderer( | ||
new CacheStyleNodeRenderer({ | ||
attrKey: 'st-id' + (this.id ? '-' + this.id : ''), | ||
createElement: _window.document.createElement.bind(_window.document) | ||
}) | ||
); | ||
this.update(); | ||
} | ||
} | ||
public onRegister() { | ||
if (this.window) { | ||
this.window.requestAnimationFrame(this.update); | ||
public update = () => { | ||
if (this.renderer) { | ||
this.renderer.render(this.window!.document.head!, this.styles); | ||
} | ||
}; | ||
public onRegister() { | ||
if (this.window) { | ||
this.window.requestAnimationFrame(this.update); | ||
} | ||
} | ||
} | ||
public register(stylesheet: RenderableStylesheet) { | ||
const registered = this.stylesMap[stylesheet.$id]; | ||
public register(stylesheet: RenderableStylesheet) { | ||
const registered = this.stylesMap[stylesheet.$id]; | ||
if (registered) { | ||
this.removeStyle(registered); | ||
} | ||
if (registered) { | ||
this.removeStyle(registered); | ||
} | ||
const i = this.findDepthIndex(stylesheet.$depth); | ||
this.styles.splice(i + 1, 0, stylesheet); | ||
this.stylesMap[stylesheet.$id] = stylesheet; | ||
this.onRegister(); | ||
} | ||
public removeStyle(stylesheet: RenderableStylesheet) { | ||
const i = this.styles.indexOf(stylesheet); | ||
if (~i) { | ||
this.styles.splice(i, 1); | ||
const i = this.findDepthIndex(stylesheet.$depth); | ||
this.styles.splice(i + 1, 0, stylesheet); | ||
this.stylesMap[stylesheet.$id] = stylesheet; | ||
this.onRegister(); | ||
} | ||
delete this.stylesMap[stylesheet.$id]; | ||
} | ||
public findDepthIndex(depth: number) { | ||
let index = this.styles.length; | ||
while (index--) { | ||
const stylesheet = this.styles[index]; | ||
if (stylesheet.$depth <= depth) { | ||
public removeStyle(stylesheet: RenderableStylesheet) { | ||
const i = this.styles.indexOf(stylesheet); | ||
if (~i) { | ||
this.styles.splice(i, 1); | ||
} | ||
delete this.stylesMap[stylesheet.$id]; | ||
} | ||
public findDepthIndex(depth: number) { | ||
let index = this.styles.length; | ||
while (index--) { | ||
const stylesheet = this.styles[index]; | ||
if (stylesheet.$depth <= depth) { | ||
return index; | ||
} | ||
} | ||
return index; | ||
} | ||
} | ||
return index; | ||
} | ||
public getStyles(ids: string[], sortIndexes: boolean) { | ||
return this.sortStyles(ids.map(id => this.stylesMap[id]), sortIndexes); | ||
} | ||
public sortStyles(styles: RenderableStylesheet[], sortIndexes = false) { | ||
const s = styles.slice(); | ||
public getStyles(ids: string[], sortIndexes: boolean) { | ||
return this.sortStyles(ids.map(id => this.stylesMap[id]), sortIndexes); | ||
} | ||
public sortStyles(styles: RenderableStylesheet[], sortIndexes = false) { | ||
const s = styles.slice(); | ||
if (sortIndexes) { | ||
s.sort((a, b) => { | ||
return this.styles.indexOf(a) - this.styles.indexOf(b); | ||
}); | ||
if (sortIndexes) { | ||
s.sort((a, b) => { | ||
return this.styles.indexOf(a) - this.styles.indexOf(b); | ||
}); | ||
} | ||
s.sort((a, b) => { | ||
return a.$depth - b.$depth; | ||
}); | ||
return s; | ||
} | ||
s.sort((a, b) => { | ||
return a.$depth - b.$depth; | ||
}); | ||
return s; | ||
} | ||
} | ||
// The $ export is a convention with the webpack plugin if changed both needs a change | ||
export const $ = new RuntimeRenderer(); |
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
No v1
QualityPackage is not semver >=1. This means it is not stable and does not support ^ ranges.
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
73476
2