@webstudio-is/react-sdk 0.82.0 → 0.84.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/LICENSE +661 -21
- package/lib/cjs/component-renderer.js +125 -0
- package/lib/cjs/components/component-meta.js +10 -0
- package/lib/cjs/components/components-utils.js +1 -0
- package/lib/cjs/context.js +2 -1
- package/lib/cjs/css/index.js +0 -1
- package/lib/cjs/css/style-rules.js +1 -1
- package/lib/cjs/embed-template.js +130 -55
- package/lib/cjs/expression.js +47 -4
- package/lib/cjs/hook.js +34 -0
- package/lib/cjs/index.js +7 -0
- package/lib/cjs/instance-utils.js +65 -0
- package/lib/cjs/props.js +18 -3
- package/lib/cjs/tree/create-elements-tree.js +5 -4
- package/lib/cjs/tree/root.js +7 -2
- package/lib/cjs/tree/webstudio-component.js +26 -10
- package/lib/component-renderer.js +111 -0
- package/lib/components/component-meta.js +10 -0
- package/lib/components/components-utils.js +1 -0
- package/lib/context.js +2 -1
- package/lib/css/index.js +0 -1
- package/lib/css/style-rules.js +1 -1
- package/lib/embed-template.js +138 -55
- package/lib/expression.js +47 -4
- package/lib/hook.js +14 -0
- package/lib/index.js +10 -1
- package/lib/instance-utils.js +45 -0
- package/lib/props.js +19 -4
- package/lib/tree/create-elements-tree.js +8 -5
- package/lib/tree/root.js +14 -4
- package/lib/tree/webstudio-component.js +27 -11
- package/lib/types/app/root.d.ts +1 -2
- package/lib/types/component-renderer.d.ts +8 -0
- package/lib/types/components/component-meta.d.ts +14 -8
- package/lib/types/context.d.ts +3 -1
- package/lib/types/css/css.d.ts +19 -19
- package/lib/types/css/global-rules.d.ts +19 -19
- package/lib/types/css/index.d.ts +0 -1
- package/lib/types/css/normalize.d.ts +47 -47
- package/lib/types/embed-template.d.ts +297 -174
- package/lib/types/expression.d.ts +3 -2
- package/lib/types/hook.d.ts +31 -0
- package/lib/types/index.d.ts +5 -2
- package/lib/types/instance-utils.d.ts +16 -0
- package/lib/types/instance-utils.test.d.ts +1 -0
- package/lib/types/props.d.ts +48 -46
- package/lib/types/tree/create-elements-tree.d.ts +9 -6
- package/lib/types/tree/root.d.ts +8 -5
- package/lib/types/tree/webstudio-component.d.ts +16 -7
- package/package.json +18 -19
- package/src/component-renderer.tsx +117 -0
- package/src/components/component-meta.ts +10 -0
- package/src/context.tsx +4 -0
- package/src/css/index.ts +0 -1
- package/src/css/style-rules.ts +1 -1
- package/src/embed-template.test.ts +113 -26
- package/src/embed-template.ts +149 -56
- package/src/expression.test.ts +74 -6
- package/src/expression.ts +55 -2
- package/src/hook.ts +42 -0
- package/src/index.ts +5 -0
- package/src/instance-utils.test.ts +89 -0
- package/src/instance-utils.ts +65 -0
- package/src/props.ts +19 -2
- package/src/tree/create-elements-tree.tsx +25 -8
- package/src/tree/root.ts +22 -3
- package/src/tree/webstudio-component.tsx +42 -14
- package/lib/cjs/css/get-browser-style.js +0 -83
- package/lib/css/get-browser-style.js +0 -65
- package/lib/types/css/get-browser-style.d.ts +0 -2
- package/src/css/get-browser-style.ts +0 -81
|
@@ -1,83 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __defProp = Object.defineProperty;
|
|
3
|
-
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
-
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
-
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
|
-
var __export = (target, all) => {
|
|
7
|
-
for (var name in all)
|
|
8
|
-
__defProp(target, name, { get: all[name], enumerable: true });
|
|
9
|
-
};
|
|
10
|
-
var __copyProps = (to, from, except, desc) => {
|
|
11
|
-
if (from && typeof from === "object" || typeof from === "function") {
|
|
12
|
-
for (let key of __getOwnPropNames(from))
|
|
13
|
-
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
14
|
-
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
15
|
-
}
|
|
16
|
-
return to;
|
|
17
|
-
};
|
|
18
|
-
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
19
|
-
var get_browser_style_exports = {};
|
|
20
|
-
__export(get_browser_style_exports, {
|
|
21
|
-
getBrowserStyle: () => getBrowserStyle
|
|
22
|
-
});
|
|
23
|
-
module.exports = __toCommonJS(get_browser_style_exports);
|
|
24
|
-
var import_detect_font = require("detect-font");
|
|
25
|
-
var import_css_data = require("@webstudio-is/css-data");
|
|
26
|
-
var import_css_data2 = require("@webstudio-is/css-data");
|
|
27
|
-
const unitsList = Object.values(import_css_data2.units).flat();
|
|
28
|
-
const unitRegex = new RegExp(`${unitsList.join("|")}`);
|
|
29
|
-
const parseValue = (property, value) => {
|
|
30
|
-
const number = Number.parseFloat(value);
|
|
31
|
-
const parsedUnit = unitRegex.exec(value);
|
|
32
|
-
if (value === "rgba(0, 0, 0, 0)") {
|
|
33
|
-
value = "transparent";
|
|
34
|
-
}
|
|
35
|
-
if (Number.isNaN(number)) {
|
|
36
|
-
const values = import_css_data.keywordValues[property];
|
|
37
|
-
if (values?.includes(value)) {
|
|
38
|
-
return {
|
|
39
|
-
type: "keyword",
|
|
40
|
-
value
|
|
41
|
-
};
|
|
42
|
-
}
|
|
43
|
-
return {
|
|
44
|
-
type: "unparsed",
|
|
45
|
-
value
|
|
46
|
-
};
|
|
47
|
-
}
|
|
48
|
-
if (number === 0 && property in import_css_data2.properties) {
|
|
49
|
-
return import_css_data2.properties[property].initial;
|
|
50
|
-
}
|
|
51
|
-
if (parsedUnit === null) {
|
|
52
|
-
return {
|
|
53
|
-
type: "unit",
|
|
54
|
-
unit: "number",
|
|
55
|
-
value: number
|
|
56
|
-
};
|
|
57
|
-
}
|
|
58
|
-
return {
|
|
59
|
-
type: "unit",
|
|
60
|
-
unit: parsedUnit[0],
|
|
61
|
-
value: number
|
|
62
|
-
};
|
|
63
|
-
};
|
|
64
|
-
const getBrowserStyle = (element) => {
|
|
65
|
-
const browserStyle = {};
|
|
66
|
-
if (element === void 0) {
|
|
67
|
-
return browserStyle;
|
|
68
|
-
}
|
|
69
|
-
let knownProperty;
|
|
70
|
-
const computedStyle = getComputedStyle(element);
|
|
71
|
-
for (knownProperty in import_css_data2.properties) {
|
|
72
|
-
if (knownProperty in computedStyle === false) {
|
|
73
|
-
continue;
|
|
74
|
-
}
|
|
75
|
-
const computedValue = computedStyle[knownProperty];
|
|
76
|
-
browserStyle[knownProperty] = parseValue(knownProperty, computedValue);
|
|
77
|
-
}
|
|
78
|
-
browserStyle.fontFamily = {
|
|
79
|
-
type: "fontFamily",
|
|
80
|
-
value: [(0, import_detect_font.detectFont)(element)]
|
|
81
|
-
};
|
|
82
|
-
return browserStyle;
|
|
83
|
-
};
|
|
@@ -1,65 +0,0 @@
|
|
|
1
|
-
import { detectFont } from "detect-font";
|
|
2
|
-
import {
|
|
3
|
-
keywordValues
|
|
4
|
-
} from "@webstudio-is/css-data";
|
|
5
|
-
import { properties, units } from "@webstudio-is/css-data";
|
|
6
|
-
const unitsList = Object.values(units).flat();
|
|
7
|
-
const unitRegex = new RegExp(`${unitsList.join("|")}`);
|
|
8
|
-
const parseValue = (property, value) => {
|
|
9
|
-
const number = Number.parseFloat(value);
|
|
10
|
-
const parsedUnit = unitRegex.exec(value);
|
|
11
|
-
if (value === "rgba(0, 0, 0, 0)") {
|
|
12
|
-
value = "transparent";
|
|
13
|
-
}
|
|
14
|
-
if (Number.isNaN(number)) {
|
|
15
|
-
const values = keywordValues[property];
|
|
16
|
-
if (values?.includes(value)) {
|
|
17
|
-
return {
|
|
18
|
-
type: "keyword",
|
|
19
|
-
value
|
|
20
|
-
};
|
|
21
|
-
}
|
|
22
|
-
return {
|
|
23
|
-
type: "unparsed",
|
|
24
|
-
value
|
|
25
|
-
};
|
|
26
|
-
}
|
|
27
|
-
if (number === 0 && property in properties) {
|
|
28
|
-
return properties[property].initial;
|
|
29
|
-
}
|
|
30
|
-
if (parsedUnit === null) {
|
|
31
|
-
return {
|
|
32
|
-
type: "unit",
|
|
33
|
-
unit: "number",
|
|
34
|
-
value: number
|
|
35
|
-
};
|
|
36
|
-
}
|
|
37
|
-
return {
|
|
38
|
-
type: "unit",
|
|
39
|
-
unit: parsedUnit[0],
|
|
40
|
-
value: number
|
|
41
|
-
};
|
|
42
|
-
};
|
|
43
|
-
const getBrowserStyle = (element) => {
|
|
44
|
-
const browserStyle = {};
|
|
45
|
-
if (element === void 0) {
|
|
46
|
-
return browserStyle;
|
|
47
|
-
}
|
|
48
|
-
let knownProperty;
|
|
49
|
-
const computedStyle = getComputedStyle(element);
|
|
50
|
-
for (knownProperty in properties) {
|
|
51
|
-
if (knownProperty in computedStyle === false) {
|
|
52
|
-
continue;
|
|
53
|
-
}
|
|
54
|
-
const computedValue = computedStyle[knownProperty];
|
|
55
|
-
browserStyle[knownProperty] = parseValue(knownProperty, computedValue);
|
|
56
|
-
}
|
|
57
|
-
browserStyle.fontFamily = {
|
|
58
|
-
type: "fontFamily",
|
|
59
|
-
value: [detectFont(element)]
|
|
60
|
-
};
|
|
61
|
-
return browserStyle;
|
|
62
|
-
};
|
|
63
|
-
export {
|
|
64
|
-
getBrowserStyle
|
|
65
|
-
};
|
|
@@ -1,81 +0,0 @@
|
|
|
1
|
-
import { detectFont } from "detect-font";
|
|
2
|
-
import {
|
|
3
|
-
type Style,
|
|
4
|
-
type StyleValue,
|
|
5
|
-
type Unit,
|
|
6
|
-
keywordValues,
|
|
7
|
-
} from "@webstudio-is/css-data";
|
|
8
|
-
import { properties, units } from "@webstudio-is/css-data";
|
|
9
|
-
|
|
10
|
-
const unitsList = Object.values(units).flat();
|
|
11
|
-
const unitRegex = new RegExp(`${unitsList.join("|")}`);
|
|
12
|
-
|
|
13
|
-
// @todo use a parser
|
|
14
|
-
const parseValue = (
|
|
15
|
-
property: keyof typeof properties,
|
|
16
|
-
value: string
|
|
17
|
-
): StyleValue => {
|
|
18
|
-
const number = Number.parseFloat(value);
|
|
19
|
-
const parsedUnit = unitRegex.exec(value);
|
|
20
|
-
if (value === "rgba(0, 0, 0, 0)") {
|
|
21
|
-
value = "transparent";
|
|
22
|
-
}
|
|
23
|
-
if (Number.isNaN(number)) {
|
|
24
|
-
const values = keywordValues[
|
|
25
|
-
property as keyof typeof keywordValues
|
|
26
|
-
] as ReadonlyArray<string>;
|
|
27
|
-
|
|
28
|
-
if (values?.includes(value)) {
|
|
29
|
-
return {
|
|
30
|
-
type: "keyword",
|
|
31
|
-
value: value,
|
|
32
|
-
};
|
|
33
|
-
}
|
|
34
|
-
|
|
35
|
-
return {
|
|
36
|
-
type: "unparsed",
|
|
37
|
-
value: value,
|
|
38
|
-
};
|
|
39
|
-
}
|
|
40
|
-
|
|
41
|
-
if (number === 0 && property in properties) {
|
|
42
|
-
return properties[property].initial;
|
|
43
|
-
}
|
|
44
|
-
|
|
45
|
-
if (parsedUnit === null) {
|
|
46
|
-
return {
|
|
47
|
-
type: "unit",
|
|
48
|
-
unit: "number",
|
|
49
|
-
value: number,
|
|
50
|
-
};
|
|
51
|
-
}
|
|
52
|
-
|
|
53
|
-
return {
|
|
54
|
-
type: "unit",
|
|
55
|
-
unit: parsedUnit[0] as Unit,
|
|
56
|
-
value: number,
|
|
57
|
-
};
|
|
58
|
-
};
|
|
59
|
-
|
|
60
|
-
export const getBrowserStyle = (element?: Element): Style => {
|
|
61
|
-
const browserStyle: Style = {};
|
|
62
|
-
if (element === undefined) {
|
|
63
|
-
return browserStyle;
|
|
64
|
-
}
|
|
65
|
-
let knownProperty: keyof typeof properties;
|
|
66
|
-
const computedStyle = getComputedStyle(element);
|
|
67
|
-
for (knownProperty in properties) {
|
|
68
|
-
if (knownProperty in computedStyle === false) {
|
|
69
|
-
continue;
|
|
70
|
-
}
|
|
71
|
-
// Typescript doesn't know we can access CSSStyleDeclaration properties by keys
|
|
72
|
-
const computedValue = computedStyle[knownProperty as unknown as number];
|
|
73
|
-
browserStyle[knownProperty] = parseValue(knownProperty, computedValue);
|
|
74
|
-
}
|
|
75
|
-
// We need a single font-family that is actually rendered. Computed style will return a list of potential fonts.
|
|
76
|
-
browserStyle.fontFamily = {
|
|
77
|
-
type: "fontFamily",
|
|
78
|
-
value: [detectFont(element)],
|
|
79
|
-
};
|
|
80
|
-
return browserStyle;
|
|
81
|
-
};
|