@divkitframework/divkit 3.0.0
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/CHANGELOG.md +124 -0
- package/LICENSE +406 -0
- package/README.md +282 -0
- package/client/package.json +6 -0
- package/client-devtool/package.json +6 -0
- package/client-hydratable/package.json +6 -0
- package/dist/browser/client-devtool.js +2 -0
- package/dist/browser/client-devtool.js.map +1 -0
- package/dist/browser/client-hydratable.js +2 -0
- package/dist/browser/client-hydratable.js.map +1 -0
- package/dist/browser/client.js +2 -0
- package/dist/browser/client.js.map +1 -0
- package/dist/client-devtool.js +2 -0
- package/dist/client-devtool.js.map +1 -0
- package/dist/client-hydratable.js +2 -0
- package/dist/client-hydratable.js.map +1 -0
- package/dist/client.css +2 -0
- package/dist/client.css.map +1 -0
- package/dist/client.js +2 -0
- package/dist/client.js.map +1 -0
- package/dist/esm/client-devtool.mjs +2 -0
- package/dist/esm/client-devtool.mjs.map +1 -0
- package/dist/esm/client-hydratable.mjs +2 -0
- package/dist/esm/client-hydratable.mjs.map +1 -0
- package/dist/esm/client.mjs +2 -0
- package/dist/esm/client.mjs.map +1 -0
- package/dist/esm/server.mjs +2 -0
- package/dist/esm/server.mjs.map +1 -0
- package/dist/server.js +2 -0
- package/dist/server.js.map +1 -0
- package/package.json +126 -0
- package/server/package.json +6 -0
- package/typings/client-devtool.d.ts +87 -0
- package/typings/client-hydratable.d.ts +26 -0
- package/typings/client.d.ts +25 -0
- package/typings/common.d.ts +141 -0
- package/typings/server.d.ts +8 -0
- package/typings/variables.d.ts +34 -0
package/package.json
ADDED
|
@@ -0,0 +1,126 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@divkitframework/divkit",
|
|
3
|
+
"version": "3.0.0",
|
|
4
|
+
"description": "DivKit for the web",
|
|
5
|
+
"keywords": [
|
|
6
|
+
"server-driven-ui",
|
|
7
|
+
"ssr",
|
|
8
|
+
"web",
|
|
9
|
+
"divkit",
|
|
10
|
+
"renderer"
|
|
11
|
+
],
|
|
12
|
+
"author": "",
|
|
13
|
+
"homepage": "https://github.com/divkit/divkit",
|
|
14
|
+
"repository": "github:divkit/divkit",
|
|
15
|
+
"license": "Apache-2.0",
|
|
16
|
+
"files": [
|
|
17
|
+
"dist/*",
|
|
18
|
+
"typings/*",
|
|
19
|
+
"client/*",
|
|
20
|
+
"client-hydratable/*",
|
|
21
|
+
"client-devtool/*",
|
|
22
|
+
"server/*"
|
|
23
|
+
],
|
|
24
|
+
"sideEffects": [
|
|
25
|
+
"dist/client.css"
|
|
26
|
+
],
|
|
27
|
+
"main": "./dist/server.js",
|
|
28
|
+
"module": "./dist/esm/server.mjs",
|
|
29
|
+
"types": "./typings/server.d.ts",
|
|
30
|
+
"exports": {
|
|
31
|
+
".": {
|
|
32
|
+
"types": "./typings/server.d.ts",
|
|
33
|
+
"require": "./dist/server.js",
|
|
34
|
+
"import": "./dist/esm/server.mjs"
|
|
35
|
+
},
|
|
36
|
+
"./client": {
|
|
37
|
+
"types": "./typings/client.d.ts",
|
|
38
|
+
"require": "./dist/client.js",
|
|
39
|
+
"import": "./dist/esm/client.mjs"
|
|
40
|
+
},
|
|
41
|
+
"./client-hydratable": {
|
|
42
|
+
"types": "./typings/client-hydratable.d.ts",
|
|
43
|
+
"require": "./dist/client-hydratable.js",
|
|
44
|
+
"import": "./dist/esm/client-hydratable.mjs"
|
|
45
|
+
},
|
|
46
|
+
"./client-devtool": {
|
|
47
|
+
"types": "./typings/client-devtool.d.ts",
|
|
48
|
+
"require": "./dist/client-devtool.js",
|
|
49
|
+
"import": "./dist/esm/client-devtool.mjs"
|
|
50
|
+
},
|
|
51
|
+
"./server": {
|
|
52
|
+
"types": "./typings/server.d.ts",
|
|
53
|
+
"require": "./dist/server.js",
|
|
54
|
+
"import": "./dist/esm/server.mjs"
|
|
55
|
+
},
|
|
56
|
+
"./dist/": "./dist/",
|
|
57
|
+
"./typings/": "./typings/",
|
|
58
|
+
"./client/": "./client/",
|
|
59
|
+
"./client-hydratable/": "./client-hydratable/",
|
|
60
|
+
"./client-devtool/": "./client-devtool/",
|
|
61
|
+
"./server/": "./server/"
|
|
62
|
+
},
|
|
63
|
+
"scripts": {
|
|
64
|
+
"test:unit": "jest",
|
|
65
|
+
"test:hermione": "cd ci && ./node_modules/.bin/hermione",
|
|
66
|
+
"test:hermione:gui": "cd ci && ./node_modules/.bin/hermione gui",
|
|
67
|
+
"test:hermione:update": "cd ci && ./node_modules/.bin/hermione --update-refs",
|
|
68
|
+
"check:ts": "tsc --noEmit",
|
|
69
|
+
"check:eslint": "eslint --quiet .",
|
|
70
|
+
"check:svelte": "svelte-check --threshold error",
|
|
71
|
+
"build": "npx webpack-cli",
|
|
72
|
+
"build:watch": "npm run build:peggy && webpack serve --config webpack-dev.config.js",
|
|
73
|
+
"build:peggy": "peggy src/expressions/expressions.peggy --allowed-start-rules start,JsonStringContents --format es",
|
|
74
|
+
"build:dev-prod": "npm run build:peggy && NODE_ENV=production webpack-cli --config webpack-dev.config.js",
|
|
75
|
+
"build:prod": "npm run build:peggy && rm -rf dist/ && NODE_ENV=production npx webpack-cli --progress"
|
|
76
|
+
},
|
|
77
|
+
"browserslist": {
|
|
78
|
+
"production": [
|
|
79
|
+
"chrome >= 58",
|
|
80
|
+
"safari >= 11",
|
|
81
|
+
"firefox >= 67"
|
|
82
|
+
],
|
|
83
|
+
"ssr": [
|
|
84
|
+
"node >= 8"
|
|
85
|
+
],
|
|
86
|
+
"development": [
|
|
87
|
+
"last 1 chrome version",
|
|
88
|
+
"last 1 firefox version",
|
|
89
|
+
"last 1 safari version"
|
|
90
|
+
]
|
|
91
|
+
},
|
|
92
|
+
"devDependencies": {
|
|
93
|
+
"@babel/core": "7.18.10",
|
|
94
|
+
"@babel/preset-env": "7.18.10",
|
|
95
|
+
"@babel/preset-typescript": "7.18.6",
|
|
96
|
+
"@types/jest": "28.1.6",
|
|
97
|
+
"@typescript-eslint/eslint-plugin": "5.32.0",
|
|
98
|
+
"@typescript-eslint/parser": "5.32.0",
|
|
99
|
+
"autoprefixer": "10.4.8",
|
|
100
|
+
"babel-loader": "8.2.5",
|
|
101
|
+
"chai": "4.3.6",
|
|
102
|
+
"css-loader": "6.7.1",
|
|
103
|
+
"css-minimizer-webpack-plugin": "4.0.0",
|
|
104
|
+
"eslint": "7.32.0",
|
|
105
|
+
"eslint-plugin-ascii": "1.0.0",
|
|
106
|
+
"eslint-plugin-import": "2.26.0",
|
|
107
|
+
"eslint-plugin-mocha": "10.1.0",
|
|
108
|
+
"eslint-plugin-svelte3": "3.4.1",
|
|
109
|
+
"html-webpack-plugin": "5.5.0",
|
|
110
|
+
"jest": "28.1.3",
|
|
111
|
+
"jest-html-reporter": "3.6.0",
|
|
112
|
+
"mini-css-extract-plugin": "2.6.1",
|
|
113
|
+
"peggy": "2.0.1",
|
|
114
|
+
"postcss": "8.4.14",
|
|
115
|
+
"postcss-loader": "7.0.1",
|
|
116
|
+
"svelte": "3.49.0",
|
|
117
|
+
"svelte-as-markup-preprocessor": "0.3.0",
|
|
118
|
+
"svelte-check": "2.8.0",
|
|
119
|
+
"svelte-loader": "3.1.3",
|
|
120
|
+
"svelte-preprocess": "4.10.7",
|
|
121
|
+
"typescript": "4.7.4",
|
|
122
|
+
"webpack": "5.74.0",
|
|
123
|
+
"webpack-cli": "4.10.0",
|
|
124
|
+
"webpack-dev-server": "4.9.3"
|
|
125
|
+
}
|
|
126
|
+
}
|
|
@@ -0,0 +1,87 @@
|
|
|
1
|
+
import type {
|
|
2
|
+
DivJson,
|
|
3
|
+
StatCallback,
|
|
4
|
+
ErrorCallback,
|
|
5
|
+
DivkitInstance,
|
|
6
|
+
Platform,
|
|
7
|
+
ComponentCallback,
|
|
8
|
+
CustomActionCallback,
|
|
9
|
+
Theme
|
|
10
|
+
} from './common';
|
|
11
|
+
import type { GlobalVariablesController, Variable } from './variables';
|
|
12
|
+
|
|
13
|
+
export function render(opts: {
|
|
14
|
+
target: HTMLElement;
|
|
15
|
+
json: DivJson;
|
|
16
|
+
id: string;
|
|
17
|
+
hydrate?: boolean;
|
|
18
|
+
globalVariablesController?: GlobalVariablesController;
|
|
19
|
+
onStat?: StatCallback;
|
|
20
|
+
onCustomAction?: CustomActionCallback;
|
|
21
|
+
onError?: ErrorCallback;
|
|
22
|
+
onComponent?: ComponentCallback;
|
|
23
|
+
platform?: Platform;
|
|
24
|
+
/** EXPERIMENTAL SUPPORT */
|
|
25
|
+
theme?: Theme;
|
|
26
|
+
}): DivkitInstance;
|
|
27
|
+
|
|
28
|
+
export { createVariable, createGlobalVariablesController } from './variables';
|
|
29
|
+
|
|
30
|
+
export interface EvalValueBase {
|
|
31
|
+
type: string;
|
|
32
|
+
value: unknown;
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
export interface StringValue extends EvalValueBase {
|
|
36
|
+
type: 'string';
|
|
37
|
+
value: string;
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
export interface UrlValue extends EvalValueBase {
|
|
41
|
+
type: 'url';
|
|
42
|
+
value: string;
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
export interface ColorValue extends EvalValueBase {
|
|
46
|
+
type: 'color';
|
|
47
|
+
value: string;
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
export interface NumberValue extends EvalValueBase {
|
|
51
|
+
type: 'number';
|
|
52
|
+
value: number;
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
export interface IntegerValue extends EvalValueBase {
|
|
56
|
+
type: 'integer';
|
|
57
|
+
value: number;
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
export interface BooleanValue extends EvalValueBase {
|
|
61
|
+
type: 'boolean';
|
|
62
|
+
value: number;
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
export interface DatetimeValue extends EvalValueBase {
|
|
66
|
+
type: 'datetime';
|
|
67
|
+
value: Date;
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
export type EvalValue = StringValue | UrlValue | ColorValue | NumberValue | IntegerValue |
|
|
71
|
+
BooleanValue | DatetimeValue;
|
|
72
|
+
|
|
73
|
+
export interface EvalError {
|
|
74
|
+
type: 'error';
|
|
75
|
+
value: string;
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
export type EvalResult = EvalValue | EvalError;
|
|
79
|
+
|
|
80
|
+
export function evalExpression(expr: string, opts?: {
|
|
81
|
+
variables?: Map<string, Variable>;
|
|
82
|
+
type?: 'exact' | 'json';
|
|
83
|
+
}): EvalResult;
|
|
84
|
+
|
|
85
|
+
export function valToString(val: EvalValue): string;
|
|
86
|
+
|
|
87
|
+
export function functionNames(): string[];
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import type {
|
|
2
|
+
DivJson,
|
|
3
|
+
StatCallback,
|
|
4
|
+
ErrorCallback,
|
|
5
|
+
DivkitInstance,
|
|
6
|
+
Platform,
|
|
7
|
+
CustomActionCallback,
|
|
8
|
+
Theme
|
|
9
|
+
} from './common';
|
|
10
|
+
import type { GlobalVariablesController } from './variables';
|
|
11
|
+
|
|
12
|
+
export function render(opts: {
|
|
13
|
+
target: HTMLElement;
|
|
14
|
+
json: DivJson;
|
|
15
|
+
id: string;
|
|
16
|
+
hydrate?: boolean;
|
|
17
|
+
globalVariablesController?: GlobalVariablesController;
|
|
18
|
+
onStat?: StatCallback;
|
|
19
|
+
onCustomAction?: CustomActionCallback;
|
|
20
|
+
onError?: ErrorCallback;
|
|
21
|
+
platform?: Platform;
|
|
22
|
+
/** EXPERIMENTAL SUPPORT */
|
|
23
|
+
theme?: Theme;
|
|
24
|
+
}): DivkitInstance;
|
|
25
|
+
|
|
26
|
+
export { createVariable, createGlobalVariablesController } from './variables';
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import type {
|
|
2
|
+
DivJson,
|
|
3
|
+
StatCallback,
|
|
4
|
+
ErrorCallback,
|
|
5
|
+
DivkitInstance,
|
|
6
|
+
Platform,
|
|
7
|
+
CustomActionCallback,
|
|
8
|
+
Theme
|
|
9
|
+
} from './common';
|
|
10
|
+
import type { GlobalVariablesController } from './variables';
|
|
11
|
+
|
|
12
|
+
export function render(opts: {
|
|
13
|
+
target: HTMLElement;
|
|
14
|
+
json: DivJson;
|
|
15
|
+
id: string;
|
|
16
|
+
globalVariablesController?: GlobalVariablesController;
|
|
17
|
+
onStat?: StatCallback;
|
|
18
|
+
onCustomAction?: CustomActionCallback;
|
|
19
|
+
onError?: ErrorCallback;
|
|
20
|
+
platform?: Platform;
|
|
21
|
+
/** EXPERIMENTAL SUPPORT */
|
|
22
|
+
theme?: Theme;
|
|
23
|
+
}): DivkitInstance;
|
|
24
|
+
|
|
25
|
+
export { createVariable, createGlobalVariablesController } from './variables';
|
|
@@ -0,0 +1,141 @@
|
|
|
1
|
+
export type BooleanInt = 0 | 1;
|
|
2
|
+
|
|
3
|
+
export type TemplateContext = Record<string, unknown>;
|
|
4
|
+
|
|
5
|
+
export interface DivBase {
|
|
6
|
+
type: string;
|
|
7
|
+
[key: string]: unknown;
|
|
8
|
+
}
|
|
9
|
+
|
|
10
|
+
export interface DivJsonState {
|
|
11
|
+
state_id: number;
|
|
12
|
+
div: DivBase;
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
export interface DivStrVariable {
|
|
16
|
+
type: 'string';
|
|
17
|
+
name: string;
|
|
18
|
+
value: string;
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
export interface DivIntVariable {
|
|
22
|
+
type: 'integer';
|
|
23
|
+
name: string;
|
|
24
|
+
value: number;
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
export interface DivNumberVariable {
|
|
28
|
+
type: 'number';
|
|
29
|
+
name: string;
|
|
30
|
+
value: number;
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
export interface DivBooleanVariable {
|
|
34
|
+
type: 'boolean';
|
|
35
|
+
name: string;
|
|
36
|
+
value: BooleanInt;
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
export interface DivColorVariable {
|
|
40
|
+
type: 'color';
|
|
41
|
+
name: string;
|
|
42
|
+
value: string;
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
export interface DivUrlVariable {
|
|
46
|
+
type: 'url';
|
|
47
|
+
name: string;
|
|
48
|
+
value: string;
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
export type DivVariable = DivStrVariable | DivIntVariable | DivNumberVariable |
|
|
52
|
+
DivBooleanVariable | DivColorVariable | DivUrlVariable;
|
|
53
|
+
|
|
54
|
+
export interface VariableTrigger {
|
|
55
|
+
mode: 'on_condition' | 'on_variable';
|
|
56
|
+
condition: BooleanInt | string;
|
|
57
|
+
actions: Action[];
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
export interface PaletteColor {
|
|
61
|
+
name: string;
|
|
62
|
+
color: string;
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
export type PaletteList = PaletteColor[];
|
|
66
|
+
|
|
67
|
+
export interface Palette {
|
|
68
|
+
light: PaletteList;
|
|
69
|
+
dark: PaletteList;
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
export interface DivJson {
|
|
73
|
+
templates?: Record<string, unknown>;
|
|
74
|
+
card: {
|
|
75
|
+
log_id: string;
|
|
76
|
+
states: DivJsonState[];
|
|
77
|
+
variables?: DivVariable[];
|
|
78
|
+
variable_triggers?: VariableTrigger[];
|
|
79
|
+
}
|
|
80
|
+
/** EXPERIMENTAL SUPPORT */
|
|
81
|
+
palette?: Palette;
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
export interface Action {
|
|
85
|
+
log_id: string;
|
|
86
|
+
url?: string;
|
|
87
|
+
payload?: Record<string, unknown>;
|
|
88
|
+
log_url?: string;
|
|
89
|
+
target?: string;
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
export interface VisibilityAction {
|
|
93
|
+
log_id: string;
|
|
94
|
+
url?: string;
|
|
95
|
+
referer?: string;
|
|
96
|
+
payload?: Record<string, string>;
|
|
97
|
+
visibility_percentage?: number;
|
|
98
|
+
visibility_duration?: number;
|
|
99
|
+
// download_callbacks
|
|
100
|
+
log_limit?: number;
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
export type StatCallback = (details: {
|
|
104
|
+
type: string;
|
|
105
|
+
action: Action | VisibilityAction;
|
|
106
|
+
}) => void;
|
|
107
|
+
|
|
108
|
+
export type CustomActionCallback = (action: Action & { url: string }) => void;
|
|
109
|
+
|
|
110
|
+
export type ComponentCallback = (details: {
|
|
111
|
+
type: 'mount';
|
|
112
|
+
node: HTMLElement;
|
|
113
|
+
json: DivBase;
|
|
114
|
+
origJson: DivBase | undefined;
|
|
115
|
+
templateContext: TemplateContext;
|
|
116
|
+
} | {
|
|
117
|
+
type: 'destroy';
|
|
118
|
+
node: HTMLElement;
|
|
119
|
+
}) => void;
|
|
120
|
+
|
|
121
|
+
export interface WrappedError extends Error {
|
|
122
|
+
level: 'error' | 'warn';
|
|
123
|
+
additional?: Record<string, unknown>;
|
|
124
|
+
}
|
|
125
|
+
|
|
126
|
+
export type ErrorCallback = (details: {
|
|
127
|
+
error: WrappedError;
|
|
128
|
+
}) => void;
|
|
129
|
+
|
|
130
|
+
export interface DivkitInstance {
|
|
131
|
+
$destroy(): void;
|
|
132
|
+
execAction(action: Action | VisibilityAction): void;
|
|
133
|
+
/** @deprecated */
|
|
134
|
+
getVariable(name: string): string | number | undefined;
|
|
135
|
+
/** @deprecated */
|
|
136
|
+
setVariable(name: string, value: string | number): void;
|
|
137
|
+
}
|
|
138
|
+
|
|
139
|
+
export type Platform = 'desktop' | 'touch' | 'auto';
|
|
140
|
+
|
|
141
|
+
export type Theme = 'system' | 'light' | 'dark';
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
/* eslint-disable @typescript-eslint/no-empty-interface */
|
|
2
|
+
|
|
3
|
+
import type { Subscriber, Unsubscriber } from 'svelte/store';
|
|
4
|
+
|
|
5
|
+
export interface Variable<T = any> {
|
|
6
|
+
getName(): string;
|
|
7
|
+
subscribe(cb: Subscriber<T>): Unsubscriber;
|
|
8
|
+
set(val: string): void;
|
|
9
|
+
setValue(value: T): void;
|
|
10
|
+
setValue(value: T): void;
|
|
11
|
+
getValue(): T;
|
|
12
|
+
getType(): string;
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
export interface StringVariable extends Variable<string> {}
|
|
16
|
+
export interface NumberVariable extends Variable<number> {}
|
|
17
|
+
export interface IntegerVariable extends Variable<number> {}
|
|
18
|
+
export interface BooleanVariable extends Variable<number> {}
|
|
19
|
+
export interface ColorVariable extends Variable<string> {}
|
|
20
|
+
export interface UrlVariable extends Variable<string> {}
|
|
21
|
+
|
|
22
|
+
export type AnyVariable = StringVariable | NumberVariable | IntegerVariable |
|
|
23
|
+
BooleanVariable | ColorVariable | UrlVariable;
|
|
24
|
+
|
|
25
|
+
export type VariableType = 'string' | 'number' | 'integer' | 'boolean' | 'color' | 'url';
|
|
26
|
+
|
|
27
|
+
export interface GlobalVariablesController {
|
|
28
|
+
setVariable(variable: AnyVariable): void;
|
|
29
|
+
getVariable(variableName: string): AnyVariable | undefined;
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
export function createVariable(variableName: string, type: VariableType, value: unknown): AnyVariable;
|
|
33
|
+
|
|
34
|
+
export function createGlobalVariablesController(): GlobalVariablesController;
|