@rettangoli/fe 1.1.2 → 1.1.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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@rettangoli/fe",
3
- "version": "1.1.2",
3
+ "version": "1.1.3",
4
4
  "description": "Frontend framework for building reactive web components",
5
5
  "type": "module",
6
6
  "main": "./src/index.js",
@@ -29,6 +29,51 @@ export const readPropFallbackFromAttributes = (source, propName) => {
29
29
  };
30
30
 
31
31
  const REACTIVE_PROP_VALUES = Symbol("rtglReactivePropValues");
32
+ const NATIVE_HOST_STYLE = Symbol("rtglNativeHostStyle");
33
+
34
+ const findPrototypePropertyDescriptor = (source, propName) => {
35
+ let current = Object.getPrototypeOf(source);
36
+
37
+ while (current) {
38
+ const descriptor = Object.getOwnPropertyDescriptor(current, propName);
39
+ if (descriptor) {
40
+ return descriptor;
41
+ }
42
+ current = Object.getPrototypeOf(current);
43
+ }
44
+
45
+ return undefined;
46
+ };
47
+
48
+ export const getNativeHostStyle = (source) => {
49
+ if (!source || typeof source !== "object") {
50
+ return undefined;
51
+ }
52
+
53
+ if (Object.prototype.hasOwnProperty.call(source, NATIVE_HOST_STYLE)) {
54
+ return source[NATIVE_HOST_STYLE];
55
+ }
56
+
57
+ const styleDescriptor = findPrototypePropertyDescriptor(source, "style");
58
+ let nativeStyle;
59
+
60
+ if (typeof styleDescriptor?.get === "function") {
61
+ nativeStyle = styleDescriptor.get.call(source);
62
+ } else if (source.style && typeof source.style === "object") {
63
+ nativeStyle = source.style;
64
+ }
65
+
66
+ if (nativeStyle && typeof nativeStyle === "object") {
67
+ Object.defineProperty(source, NATIVE_HOST_STYLE, {
68
+ value: nativeStyle,
69
+ enumerable: false,
70
+ configurable: false,
71
+ writable: false,
72
+ });
73
+ }
74
+
75
+ return nativeStyle;
76
+ };
32
77
 
33
78
  const ensureReactivePropValues = (source) => {
34
79
  if (!Object.prototype.hasOwnProperty.call(source, REACTIVE_PROP_VALUES)) {
@@ -50,6 +95,10 @@ export const installReactiveProps = ({
50
95
  }) => {
51
96
  const reactiveValues = ensureReactivePropValues(source);
52
97
 
98
+ if (allowedKeys.includes("style")) {
99
+ getNativeHostStyle(source);
100
+ }
101
+
53
102
  allowedKeys.forEach((propName) => {
54
103
  if (typeof propName !== "string" || propName.length === 0) {
55
104
  return;
@@ -1,3 +1,5 @@
1
+ import { getNativeHostStyle } from "../core/runtime/props.js";
2
+
1
3
  const COMMON_LINK_STYLE_TEXT = `
2
4
  a, a:link, a:visited, a:hover, a:active {
3
5
  display: contents;
@@ -98,7 +100,10 @@ export const initializeComponentDom = ({
98
100
  if (renderTarget.parentNode !== shadow) {
99
101
  shadow.appendChild(renderTarget);
100
102
  }
101
- host.style.display = "contents";
103
+ const hostStyle = getNativeHostStyle(host);
104
+ if (hostStyle && typeof hostStyle === "object") {
105
+ hostStyle.display = "contents";
106
+ }
102
107
 
103
108
  return {
104
109
  shadow,