vasille-css 7.0.0-rc.1 → 7.0.0-rc.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/lib/dev.js CHANGED
@@ -1,4 +1,35 @@
1
- import { CssStyleInjector } from "./index.js";
1
+ import { CssStyleInjector, setLaptopMaxWidth, setMobileMaxWidth, setTabletMaxWidth } from "./index.js";
2
+ import { desktop, laptopMaxWidth, mobile, mobileMaxWidth, tablet, tabletMaxWidth } from "./lib.js";
3
+ function warn(device) {
4
+ console.warn(`[vasille-css] Setting of ${device} max width in production mode is not supported.`);
5
+ }
6
+ export function devSetMobileMaxWidth(value) {
7
+ setMobileMaxWidth(value);
8
+ if (mobile) {
9
+ mobile.media = `(max-width:${mobileMaxWidth}px)`;
10
+ }
11
+ if (tablet) {
12
+ tablet.media = `(min-width:${mobileMaxWidth}px) and (max-width:${tabletMaxWidth}px)`;
13
+ }
14
+ warn("mobile");
15
+ }
16
+ export function devSetTabletMaxWidth(value) {
17
+ setTabletMaxWidth(value);
18
+ if (tablet) {
19
+ tablet.media = `(min-width:${mobileMaxWidth}px) and (max-width:${tabletMaxWidth}px)`;
20
+ }
21
+ if (desktop) {
22
+ desktop.media = `(min-width:${tabletMaxWidth}px) and (max-width:${laptopMaxWidth}px)`;
23
+ }
24
+ warn("tablet");
25
+ }
26
+ export function devSetLaptopMaxWidth(value) {
27
+ setLaptopMaxWidth(value);
28
+ if (desktop) {
29
+ desktop.media = `(min-width:${tabletMaxWidth}px) and (max-width:${laptopMaxWidth}px)`;
30
+ }
31
+ warn("laptop");
32
+ }
2
33
  export class DevCssStyleInjector extends CssStyleInjector {
3
34
  constructor(key, styles) {
4
35
  super(styles);
@@ -8,10 +39,3 @@ export class DevCssStyleInjector extends CssStyleInjector {
8
39
  return `${super.generateClassName()}-${this.key}`;
9
40
  }
10
41
  }
11
- export function devStyleSheet(styles) {
12
- const result = {};
13
- for (const key in styles) {
14
- result[key] = new DevCssStyleInjector(key, styles[key]);
15
- }
16
- return result;
17
- }
package/lib/index.js CHANGED
@@ -12,13 +12,7 @@ export class CssStyleInjector {
12
12
  }
13
13
  const className = this.generateClassName();
14
14
  for (const item of this.styles) {
15
- if (item instanceof Array) {
16
- const [target, rule] = item;
17
- insertRule(target, rule.replace("{}", className));
18
- }
19
- else {
20
- insertRule(0, item.replace("{}", className));
21
- }
15
+ this.insertRule(item, className);
22
16
  }
23
17
  this.styles.splice(0);
24
18
  return (this.className = className);
@@ -26,6 +20,25 @@ export class CssStyleInjector {
26
20
  generateClassName() {
27
21
  return `vasille-${++index}`;
28
22
  }
23
+ insertRule(rule, className) {
24
+ if (rule instanceof Array) {
25
+ insertRule(rule[0], rule[1].replace("{}", className));
26
+ }
27
+ else {
28
+ insertRule(0, rule.replace("{}", className));
29
+ }
30
+ }
31
+ }
32
+ export class SafeCssStyleInjector extends CssStyleInjector {
33
+ insertRule(rule, className) {
34
+ try {
35
+ super.insertRule(rule, className);
36
+ }
37
+ catch (e) {
38
+ // ignore any style related errors
39
+ void e;
40
+ }
41
+ }
29
42
  }
30
43
  /**
31
44
  * Inserts stylesheet to document
@@ -34,7 +47,7 @@ export class CssStyleInjector {
34
47
  export function styleSheet(styles) {
35
48
  const result = {};
36
49
  for (const key in styles) {
37
- result[key] = new CssStyleInjector(styles[key]);
50
+ result[key] = new SafeCssStyleInjector(styles[key]);
38
51
  }
39
52
  return result;
40
53
  }
package/lib/lib.js CHANGED
@@ -1,12 +1,12 @@
1
1
  let common;
2
- let mobile;
3
- let tablet;
4
- let desktop;
2
+ export let mobile;
3
+ export let tablet;
4
+ export let desktop;
5
5
  let dark;
6
6
  let light;
7
- let mobileMaxWidth = 440;
8
- let tabletMaxWidth = 880;
9
- let laptopMaxWidth = 1320;
7
+ export let mobileMaxWidth = 440;
8
+ export let tabletMaxWidth = 880;
9
+ export let laptopMaxWidth = 1320;
10
10
  export function setMobileMaxWidth(value) {
11
11
  mobileMaxWidth = value;
12
12
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "vasille-css",
3
- "version": "7.0.0-rc.1",
3
+ "version": "7.0.0-rc.3",
4
4
  "description": "The same devkit which is designed to build fault tolerant frontends (CSS style library)",
5
5
  "main": "./lib/index.js",
6
6
  "types": "./types/index.d.ts",
package/types/dev.d.ts CHANGED
@@ -1,11 +1,9 @@
1
1
  import { CssStyleInjector } from "./index.js";
2
+ export declare function devSetMobileMaxWidth(value: number): void;
3
+ export declare function devSetTabletMaxWidth(value: number): void;
4
+ export declare function devSetLaptopMaxWidth(value: number): void;
2
5
  export declare class DevCssStyleInjector extends CssStyleInjector {
3
6
  protected key: string;
4
7
  constructor(key: string, styles: (string | [number, string])[]);
5
8
  protected generateClassName(): string;
6
9
  }
7
- export declare function devStyleSheet<T extends {
8
- [k: string]: (string | [number, string])[];
9
- }>(styles: T): {
10
- [K in keyof T]: DevCssStyleInjector;
11
- };
package/types/index.d.ts CHANGED
@@ -5,6 +5,10 @@ export declare class CssStyleInjector {
5
5
  constructor(styles: (string | [number, string])[]);
6
6
  inject(): string;
7
7
  protected generateClassName(): string;
8
+ protected insertRule(rule: string | [number, string], className: string): void;
9
+ }
10
+ export declare class SafeCssStyleInjector extends CssStyleInjector {
11
+ protected insertRule(rule: string | [number, string], className: string): void;
8
12
  }
9
13
  /**
10
14
  * Inserts stylesheet to document
package/types/lib.d.ts CHANGED
@@ -1,3 +1,9 @@
1
+ export declare let mobile: CSSStyleSheet | undefined;
2
+ export declare let tablet: CSSStyleSheet | undefined;
3
+ export declare let desktop: CSSStyleSheet | undefined;
4
+ export declare let mobileMaxWidth: number;
5
+ export declare let tabletMaxWidth: number;
6
+ export declare let laptopMaxWidth: number;
1
7
  export declare function setMobileMaxWidth(value: number): void;
2
8
  export declare function setTabletMaxWidth(value: number): void;
3
9
  export declare function setLaptopMaxWidth(value: number): void;