@semcore/core 16.0.0-prerelease.10 → 16.0.0-prerelease.11

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.
Files changed (48) hide show
  1. package/lib/LastInteractionType.mjs +1 -1
  2. package/lib/coreFactory.mjs +5 -5
  3. package/lib/enhancement/Children.mjs +1 -1
  4. package/lib/enhancement/Root.mjs +3 -7
  5. package/lib/enhancement/hoistProps.mjs +3 -3
  6. package/lib/enhancement/i18n.mjs +1 -1
  7. package/lib/enhancement/staticChildren.mjs +3 -3
  8. package/lib/enhancement/style.mjs +2 -3
  9. package/lib/enhancement/uncontrolledProps.mjs +2 -2
  10. package/lib/esm/LastInteractionType.mjs +1 -1
  11. package/lib/esm/coreFactory.mjs +5 -5
  12. package/lib/esm/enhancement/Children.mjs +1 -1
  13. package/lib/esm/enhancement/Root.mjs +3 -7
  14. package/lib/esm/enhancement/hoistProps.mjs +3 -3
  15. package/lib/esm/enhancement/i18n.mjs +1 -1
  16. package/lib/esm/enhancement/staticChildren.mjs +3 -3
  17. package/lib/esm/enhancement/style.mjs +2 -3
  18. package/lib/esm/enhancement/uncontrolledProps.mjs +2 -2
  19. package/lib/esm/index.mjs +1 -0
  20. package/lib/esm/styled/index.mjs +8 -0
  21. package/lib/esm/styled/reshadow-core.mjs +219 -3
  22. package/lib/esm/utils/assignProps.mjs +86 -0
  23. package/lib/esm/utils/canUseDOM.mjs +6 -0
  24. package/lib/esm/utils/capitalizeFirstLetter.mjs +6 -0
  25. package/lib/esm/utils/createHoc.mjs +44 -0
  26. package/lib/esm/utils/enhances/WithI18n.mjs +78 -0
  27. package/lib/esm/utils/enhances/i18nEnhance.mjs +91 -0
  28. package/lib/esm/utils/getDisplayName.mjs +6 -0
  29. package/lib/esm/utils/logger.mjs +35 -0
  30. package/lib/esm/utils/pick.mjs +15 -0
  31. package/lib/esm/utils/ref.mjs +86 -0
  32. package/lib/esm/utils/use/useEnhancedEffect.mjs +6 -0
  33. package/lib/index.mjs +1 -0
  34. package/lib/styled/index.mjs +8 -6
  35. package/lib/styled/reshadow-core.mjs +219 -3
  36. package/lib/utils/assignProps.mjs +30 -28
  37. package/lib/utils/canUseDOM.mjs +5 -3
  38. package/lib/utils/capitalizeFirstLetter.mjs +4 -2
  39. package/lib/utils/createHoc.mjs +19 -21
  40. package/lib/utils/enhances/WithI18n.mjs +32 -37
  41. package/lib/utils/enhances/i18nEnhance.mjs +32 -33
  42. package/lib/utils/getDisplayName.mjs +5 -3
  43. package/lib/utils/logger.mjs +16 -13
  44. package/lib/utils/pick.mjs +4 -2
  45. package/lib/utils/ref.mjs +46 -43
  46. package/lib/utils/use/useEnhancedEffect.mjs +4 -3
  47. package/package.json +1 -1
  48. package/vite.config.ts +1 -2
@@ -0,0 +1,44 @@
1
+ import _extends from "@babel/runtime/helpers/esm/extends";
2
+ import _objectSpread from "@babel/runtime/helpers/esm/objectSpread2";
3
+ import _objectWithoutProperties from "@babel/runtime/helpers/esm/objectWithoutProperties";
4
+ import _classCallCheck from "@babel/runtime/helpers/esm/classCallCheck";
5
+ import _createClass from "@babel/runtime/helpers/esm/createClass";
6
+ import _inherits from "@babel/runtime/helpers/esm/inherits";
7
+ import _createSuper from "@babel/runtime/helpers/esm/createSuper";
8
+ import _defineProperty from "@babel/runtime/helpers/esm/defineProperty";
9
+ import React, { PureComponent } from "react";
10
+ import hoistNonReactStatics from "hoist-non-react-statics";
11
+ import getDisplayName from "./getDisplayName.mjs";
12
+ var _excluded = ["forwardedRef"];
13
+ function createHoc(EnhancedComponent) {
14
+ return function createWrapper() {
15
+ var options = arguments.length > 0 && arguments[0] !== void 0 ? arguments[0] : {};
16
+ return function(WrappedComponent) {
17
+ var Component = /* @__PURE__ */ function(_PureComponent) {
18
+ _inherits(Component2, _PureComponent);
19
+ var _super = _createSuper(Component2);
20
+ function Component2() {
21
+ _classCallCheck(this, Component2);
22
+ return _super.apply(this, arguments);
23
+ }
24
+ _createClass(Component2, [{
25
+ key: "render",
26
+ value: function render() {
27
+ var _WrappedComponent$def = _objectSpread(_objectSpread({}, WrappedComponent.defaultProps), this.props), forwardedRef = _WrappedComponent$def.forwardedRef, others = _objectWithoutProperties(_WrappedComponent$def, _excluded);
28
+ return /* @__PURE__ */ React.createElement(EnhancedComponent, _extends({}, options, this.props), function(enhancedComponentProps) {
29
+ return /* @__PURE__ */ React.createElement(WrappedComponent, _extends({
30
+ forwardedRef
31
+ }, others, enhancedComponentProps));
32
+ });
33
+ }
34
+ }]);
35
+ return Component2;
36
+ }(PureComponent);
37
+ _defineProperty(Component, "displayName", getDisplayName(WrappedComponent));
38
+ return hoistNonReactStatics(Component, WrappedComponent);
39
+ };
40
+ };
41
+ }
42
+ export {
43
+ createHoc as default
44
+ };
@@ -0,0 +1,78 @@
1
+ import _classCallCheck from "@babel/runtime/helpers/esm/classCallCheck";
2
+ import _createClass from "@babel/runtime/helpers/esm/createClass";
3
+ import _assertThisInitialized from "@babel/runtime/helpers/esm/assertThisInitialized";
4
+ import _inherits from "@babel/runtime/helpers/esm/inherits";
5
+ import _createSuper from "@babel/runtime/helpers/esm/createSuper";
6
+ import _defineProperty from "@babel/runtime/helpers/esm/defineProperty";
7
+ import React, { createContext, Component } from "react";
8
+ import createHoc from "../createHoc.mjs";
9
+ import { useAsyncI18nMessages } from "./i18nEnhance.mjs";
10
+ import { createIntlCache, createIntl } from "@formatjs/intl";
11
+ var Context = /* @__PURE__ */ createContext(void 0);
12
+ var I18nProvider = Context.Provider, I18nConsumer = Context.Consumer;
13
+ var messagesCache = createIntlCache();
14
+ function getText(dictionaries, locale) {
15
+ return function(key) {
16
+ var dictionary = dictionaries[locale];
17
+ return dictionary ? dictionary[key] : dictionaries["en"][key];
18
+ };
19
+ }
20
+ var WithI18n = /* @__PURE__ */ function(_Component) {
21
+ _inherits(WithI18n2, _Component);
22
+ var _super = _createSuper(WithI18n2);
23
+ function WithI18n2() {
24
+ var _this;
25
+ _classCallCheck(this, WithI18n2);
26
+ for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) {
27
+ args[_key] = arguments[_key];
28
+ }
29
+ _this = _super.call.apply(_super, [this].concat(args));
30
+ _defineProperty(_assertThisInitialized(_this), "context", void 0);
31
+ _defineProperty(_assertThisInitialized(_this), "getText", function(dictionary, selfLocale) {
32
+ var _this$props = _this.props, locale = _this$props.locale, getText2 = _this$props.getText;
33
+ var contextLocale = _this.context;
34
+ return getText2(dictionary, selfLocale || locale || contextLocale);
35
+ });
36
+ return _this;
37
+ }
38
+ _createClass(WithI18n2, [{
39
+ key: "render",
40
+ value: function render() {
41
+ var _ref = this.props, children = _ref.children;
42
+ return children({
43
+ getText: this.getText
44
+ });
45
+ }
46
+ }]);
47
+ return WithI18n2;
48
+ }(Component);
49
+ _defineProperty(WithI18n, "contextType", Context);
50
+ _defineProperty(WithI18n, "defaultProps", {
51
+ getText
52
+ });
53
+ var useI18n = function useI18n2(dictionary) {
54
+ var _React$useContext;
55
+ var locale = arguments.length > 1 && arguments[1] !== void 0 ? arguments[1] : "en";
56
+ var fallbackDictionary = arguments.length > 2 ? arguments[2] : void 0;
57
+ var lang = (_React$useContext = React.useContext(Context)) !== null && _React$useContext !== void 0 ? _React$useContext : locale;
58
+ var resolvedDictionary = useAsyncI18nMessages(dictionary, lang, fallbackDictionary);
59
+ var intl = React.useMemo(function() {
60
+ return createIntl({
61
+ locale: lang,
62
+ messages: resolvedDictionary
63
+ }, messagesCache);
64
+ }, [resolvedDictionary, lang]);
65
+ return React.useCallback(function(messageId, variables) {
66
+ return intl.formatMessage({
67
+ id: messageId !== null && messageId !== void 0 ? messageId : ""
68
+ }, variables);
69
+ }, [intl]);
70
+ };
71
+ const WithI18n$1 = createHoc(WithI18n);
72
+ export {
73
+ Context,
74
+ I18nConsumer,
75
+ I18nProvider,
76
+ WithI18n$1 as default,
77
+ useI18n
78
+ };
@@ -0,0 +1,91 @@
1
+ import _defineProperty from "@babel/runtime/helpers/esm/defineProperty";
2
+ import _typeof from "@babel/runtime/helpers/esm/typeof";
3
+ import _regeneratorRuntime from "@babel/runtime/helpers/esm/regeneratorRuntime";
4
+ import _objectSpread from "@babel/runtime/helpers/esm/objectSpread2";
5
+ import _slicedToArray from "@babel/runtime/helpers/esm/slicedToArray";
6
+ import _asyncToGenerator from "@babel/runtime/helpers/esm/asyncToGenerator";
7
+ import React from "react";
8
+ import { useI18n } from "./WithI18n.mjs";
9
+ var useAsyncI18nMessages = function useAsyncI18nMessages2(primaryContainer, locale, fallbackContainer) {
10
+ var _store$locale;
11
+ var container = React.useMemo(function() {
12
+ if (!fallbackContainer) return primaryContainer;
13
+ if (!primaryContainer) return fallbackContainer;
14
+ if (primaryContainer === fallbackContainer) return primaryContainer;
15
+ var container2 = {};
16
+ var _loop = function _loop2(_locale2) {
17
+ if (typeof primaryContainer[_locale2] === "function" || typeof fallbackContainer[_locale2] === "function") {
18
+ container2[_locale2] = /* @__PURE__ */ _asyncToGenerator(/* @__PURE__ */ _regeneratorRuntime().mark(function _callee() {
19
+ var _yield$Promise$all, _yield$Promise$all2, primary, fallback;
20
+ return _regeneratorRuntime().wrap(function _callee$(_context) {
21
+ while (1) switch (_context.prev = _context.next) {
22
+ case 0:
23
+ _context.next = 2;
24
+ return Promise.all([primaryContainer[_locale2], fallbackContainer[_locale2]]);
25
+ case 2:
26
+ _yield$Promise$all = _context.sent;
27
+ _yield$Promise$all2 = _slicedToArray(_yield$Promise$all, 2);
28
+ primary = _yield$Promise$all2[0];
29
+ fallback = _yield$Promise$all2[1];
30
+ return _context.abrupt("return", _objectSpread(_objectSpread({}, primary), fallback));
31
+ case 7:
32
+ case "end":
33
+ return _context.stop();
34
+ }
35
+ }, _callee);
36
+ }));
37
+ } else {
38
+ var _primaryContainer$_lo, _fallbackContainer$_l;
39
+ container2[_locale2] = _objectSpread(_objectSpread({}, (_primaryContainer$_lo = primaryContainer[_locale2]) !== null && _primaryContainer$_lo !== void 0 ? _primaryContainer$_lo : {}), (_fallbackContainer$_l = fallbackContainer[_locale2]) !== null && _fallbackContainer$_l !== void 0 ? _fallbackContainer$_l : {});
40
+ }
41
+ };
42
+ for (var _locale in primaryContainer) {
43
+ _loop(_locale);
44
+ }
45
+ return container2;
46
+ }, [primaryContainer, fallbackContainer]);
47
+ var initStore = React.useMemo(function() {
48
+ var store2 = {};
49
+ for (var _locale2 in container) {
50
+ if (_typeof(container[_locale2]) === "object") {
51
+ store2[_locale2] = container[_locale2];
52
+ }
53
+ }
54
+ return store2;
55
+ }, [container]);
56
+ var _React$useState = React.useState(initStore), _React$useState2 = _slicedToArray(_React$useState, 2), store = _React$useState2[0], setStore = _React$useState2[1];
57
+ var lastLoadedLocaleRef = React.useRef(null);
58
+ if (store[locale]) lastLoadedLocaleRef.current = locale;
59
+ var fallbackMessages = React.useMemo(function() {
60
+ return Object.values(store)[0];
61
+ }, [store]);
62
+ var loadingLocaleRef = React.useRef(null);
63
+ React.useEffect(function() {
64
+ loadingLocaleRef.current = locale;
65
+ var asyncMessages = container[locale];
66
+ if (typeof asyncMessages === "function") {
67
+ asyncMessages().then(function(module) {
68
+ if (loadingLocaleRef.current !== locale) return;
69
+ var messages = module;
70
+ if ("default" in module && _typeof(module["default"]) === "object") messages = module["default"];
71
+ setStore(function(store2) {
72
+ return _objectSpread(_objectSpread({}, store2), {}, _defineProperty({}, locale, messages));
73
+ });
74
+ })["catch"](console.error);
75
+ }
76
+ }, [container, locale]);
77
+ return (_store$locale = store[locale]) !== null && _store$locale !== void 0 ? _store$locale : fallbackMessages;
78
+ };
79
+ const i18nEnhance = function(container) {
80
+ return function(props) {
81
+ var i18n = props.i18n, locale = props.locale;
82
+ var getI18nText = useI18n(i18n, locale, container);
83
+ return _objectSpread(_objectSpread({}, props), {}, {
84
+ getI18nText
85
+ });
86
+ };
87
+ };
88
+ export {
89
+ i18nEnhance as default,
90
+ useAsyncI18nMessages
91
+ };
@@ -0,0 +1,6 @@
1
+ function getDisplayName(WrappedComponent) {
2
+ return WrappedComponent.displayName || WrappedComponent.name || "Component";
3
+ }
4
+ export {
5
+ getDisplayName as default
6
+ };
@@ -0,0 +1,35 @@
1
+ import _classCallCheck from "@babel/runtime/helpers/esm/classCallCheck";
2
+ import _createClass from "@babel/runtime/helpers/esm/createClass";
3
+ import _defineProperty from "@babel/runtime/helpers/esm/defineProperty";
4
+ var DEV = process.env.NODE_ENV !== "production";
5
+ var Logger = /* @__PURE__ */ function() {
6
+ function Logger2(logger2) {
7
+ _classCallCheck(this, Logger2);
8
+ _defineProperty(this, "logger", void 0);
9
+ this.logger = logger2 || {
10
+ warn: function warn() {
11
+ }
12
+ };
13
+ }
14
+ _createClass(Logger2, [{
15
+ key: "console",
16
+ value: function console2(level, msg, component) {
17
+ this.logger[level](component ? "[".concat(component, "]: ").concat(msg) : msg);
18
+ }
19
+ }, {
20
+ key: "warn",
21
+ value: function warn(condition, msg, component) {
22
+ if (DEV) {
23
+ if (condition) {
24
+ this.console("warn", msg, component);
25
+ }
26
+ }
27
+ }
28
+ }]);
29
+ return Logger2;
30
+ }();
31
+ const logger = new Logger(console);
32
+ export {
33
+ Logger,
34
+ logger as default
35
+ };
@@ -0,0 +1,15 @@
1
+ function pick(obj, keys) {
2
+ var res = {};
3
+ var len = keys.length;
4
+ var idx = -1;
5
+ while (++idx < len) {
6
+ var key = keys[idx];
7
+ if (key in obj) {
8
+ res[key] = obj[key];
9
+ }
10
+ }
11
+ return res;
12
+ }
13
+ export {
14
+ pick as default
15
+ };
@@ -0,0 +1,86 @@
1
+ import _toConsumableArray from "@babel/runtime/helpers/esm/toConsumableArray";
2
+ import _slicedToArray from "@babel/runtime/helpers/esm/slicedToArray";
3
+ import React from "react";
4
+ import { findDOMNode } from "react-dom";
5
+ function setRef(ref, value) {
6
+ if (typeof ref === "function") {
7
+ ref(value);
8
+ } else if (ref !== null && ref !== void 0 && ref.hasOwnProperty("current")) {
9
+ ref["current"] = value;
10
+ }
11
+ }
12
+ function getRef(ref) {
13
+ if (!ref) return null;
14
+ return "current" in ref ? ref.current : ref;
15
+ }
16
+ function useCallbackRef(initialValue, callback) {
17
+ var _React$useState = React.useState(function() {
18
+ return {
19
+ // value
20
+ value: initialValue,
21
+ // last callback
22
+ callback,
23
+ // "memoized" public interface
24
+ facade: {
25
+ get current() {
26
+ return ref.value;
27
+ },
28
+ set current(value) {
29
+ var last = ref.value;
30
+ if (last !== value) {
31
+ ref.value = value;
32
+ ref.callback(value, last);
33
+ }
34
+ }
35
+ }
36
+ };
37
+ }), _React$useState2 = _slicedToArray(_React$useState, 1), ref = _React$useState2[0];
38
+ ref.callback = callback;
39
+ return ref.facade;
40
+ }
41
+ function useForkRef() {
42
+ for (var _len = arguments.length, refs = new Array(_len), _key = 0; _key < _len; _key++) {
43
+ refs[_key] = arguments[_key];
44
+ }
45
+ return React.useCallback(function(refValue) {
46
+ var uniqueRefs = _toConsumableArray(new Set(refs));
47
+ uniqueRefs.forEach(function(ref) {
48
+ return setRef(ref, refValue);
49
+ });
50
+ }, refs);
51
+ }
52
+ function forkRef() {
53
+ for (var _len2 = arguments.length, refs = new Array(_len2), _key2 = 0; _key2 < _len2; _key2++) {
54
+ refs[_key2] = arguments[_key2];
55
+ }
56
+ if (refs.every(function(ref) {
57
+ return ref == null;
58
+ })) {
59
+ return null;
60
+ }
61
+ return function(refValue) {
62
+ var uniqueRefs = _toConsumableArray(new Set(refs));
63
+ uniqueRefs.forEach(function(ref) {
64
+ return setRef(ref, refValue);
65
+ });
66
+ };
67
+ }
68
+ function getNodeByRef(ref) {
69
+ if (typeof ref === "function") {
70
+ ref = ref();
71
+ }
72
+ if (!ref) return null;
73
+ var node = getRef(ref);
74
+ if (!node) return null;
75
+ if (node.nodeType === 1) return node;
76
+ if (Object.keys(node).length === 1 && "getBoundingClientRect" in node) return null;
77
+ return findDOMNode(node);
78
+ }
79
+ export {
80
+ forkRef,
81
+ getNodeByRef,
82
+ getRef,
83
+ setRef,
84
+ useCallbackRef,
85
+ useForkRef
86
+ };
@@ -0,0 +1,6 @@
1
+ import React from "react";
2
+ import canUseDOM from "../canUseDOM.mjs";
3
+ var useEnhancedEffect = canUseDOM() ? React.useLayoutEffect : React.useEffect;
4
+ export {
5
+ useEnhancedEffect as default
6
+ };
package/lib/index.mjs CHANGED
@@ -1,4 +1,5 @@
1
1
  import { assignProps, createBaseComponent, createComponent } from "./coreFactory.mjs";
2
+ import "./styled/index.mjs";
2
3
  import { Component, Intergalactic, Root, wrapIntergalacticComponent } from "./core-types/Component.mjs";
3
4
  import { CHILDREN_COMPONENT, CONTEXT_COMPONENT, CORE_INSTANCE, CREATE_COMPONENT, INHERITED_NAME } from "./core-types/symbols.mjs";
4
5
  import { default as default2 } from "./register.mjs";
@@ -1,6 +1,8 @@
1
- /** @deprecated */
2
-
3
- /** @ts-ignore */
4
- export { styled, use, css } from "./reshadow-core.mjs";
5
- export { sstyled } from "./sstyled.mjs";
6
- //# sourceMappingURL=index.mjs.map
1
+ import { css, styled, use } from "./reshadow-core.mjs";
2
+ import { sstyled } from "./sstyled.mjs";
3
+ export {
4
+ css,
5
+ sstyled,
6
+ styled,
7
+ use
8
+ };
@@ -1,5 +1,70 @@
1
- import "@babel/runtime/helpers/esm/typeof";
2
- import "@babel/runtime/helpers/esm/defineProperty";
1
+ import _typeof from "@babel/runtime/helpers/esm/typeof";
2
+ import _defineProperty from "@babel/runtime/helpers/esm/defineProperty";
3
+ var _Symbol = function _Symbol2(key) {
4
+ return typeof Symbol !== "undefined" ? Symbol(key) : key;
5
+ };
6
+ var KEYS = {
7
+ __id__: _Symbol("__id__"),
8
+ __store__: _Symbol("__store__"),
9
+ __prev__: _Symbol("__prev__"),
10
+ __use__: _Symbol("__use__"),
11
+ __elements__: "__elements__",
12
+ __style__: "$$style",
13
+ __styles__: "styles",
14
+ __css__: "__css__",
15
+ __hash__: "__hash__",
16
+ /**
17
+ * This prop is needed for the interop between different component frameworks
18
+ */
19
+ __classProp__: "className"
20
+ };
21
+ var index = 0;
22
+ var use = function use2(obj) {
23
+ var result = {};
24
+ result[KEYS.__use__] = obj;
25
+ return result;
26
+ };
27
+ var create = function create2(args) {
28
+ var len = args.length;
29
+ var newStyle = {};
30
+ var id = "";
31
+ var vars = null;
32
+ var uses = null;
33
+ for (var i = 0; i < len; i++) {
34
+ var _style = args[i];
35
+ if (!_style) continue;
36
+ if (!_style[KEYS.__id__]) {
37
+ _style[KEYS.__id__] = ++index;
38
+ _style[KEYS.__store__] = _defineProperty({}, "_" + _style[KEYS.__id__], _style);
39
+ }
40
+ id += "_" + _style[KEYS.__id__];
41
+ if (_style[KEYS.__style__]) {
42
+ vars = Object.assign(vars || {}, _style[KEYS.__style__]);
43
+ }
44
+ if (_style[KEYS.__use__]) {
45
+ uses = Object.assign(uses || {}, _style[KEYS.__use__]);
46
+ }
47
+ if (_style[KEYS.__store__][id]) {
48
+ newStyle = _style[KEYS.__store__][id];
49
+ continue;
50
+ }
51
+ newStyle = Object.create(newStyle);
52
+ for (var key in _style) {
53
+ if (key in KEYS) continue;
54
+ newStyle[key] = appendClassName(_style[key], newStyle[key]);
55
+ }
56
+ _style[KEYS.__store__][id] = newStyle;
57
+ newStyle[KEYS.__id__] = index;
58
+ newStyle[KEYS.__store__] = _defineProperty({}, "_" + _style[KEYS.__id__], newStyle);
59
+ }
60
+ if (vars || use) {
61
+ newStyle = Object.create(newStyle);
62
+ newStyle[KEYS.__style__] = vars;
63
+ newStyle[KEYS.__use__] = uses;
64
+ }
65
+ return newStyle;
66
+ };
67
+ var isSSR = !(typeof window !== "undefined" && window.document && window.document.createElement);
3
68
  var serverMap = {};
4
69
  var getStyles = function getStyles2() {
5
70
  return {
@@ -13,6 +78,157 @@ var getStyles = function getStyles2() {
13
78
  }
14
79
  };
15
80
  };
81
+ var clearStyles = function clearStyles2() {
82
+ serverStyles = "";
83
+ };
84
+ var RESHADOW_ID = "__reshadow__";
85
+ var appendChildToDocumentHead = function appendChildToDocumentHead2(element) {
86
+ return document.head.appendChild(element);
87
+ };
88
+ var css = function css2(code, hash) {
89
+ var id = "reshadow-".concat(hash);
90
+ if (isSSR) {
91
+ serverMap[id] = code;
92
+ return;
93
+ }
94
+ var container = document.getElementById(RESHADOW_ID);
95
+ if (!container) {
96
+ container = document.createElement("object");
97
+ container.id = RESHADOW_ID;
98
+ if (document.head) {
99
+ appendChildToDocumentHead(container);
100
+ } else {
101
+ document.addEventListener("DOMContentLoaded", function() {
102
+ appendChildToDocumentHead(container);
103
+ });
104
+ }
105
+ }
106
+ var css3 = document.getElementById(id);
107
+ if (!css3) {
108
+ css3 = document.createElement("style");
109
+ css3.id = id;
110
+ css3.type = "text/css";
111
+ container.appendChild(css3);
112
+ }
113
+ css3.innerHTML = code;
114
+ };
115
+ var styles = {};
116
+ var style;
117
+ var stack = [];
118
+ var styled = function styled2(elem) {
119
+ var curr = stack.pop() || [];
120
+ styles = curr[0] || styles;
121
+ style = curr[1] || style;
122
+ styled2[KEYS.__styles__] = styles;
123
+ styled2[KEYS.__style__] = style;
124
+ return elem;
125
+ };
126
+ styled[KEYS.__styles__] = styles;
127
+ var set = function set2(args, newStyle) {
128
+ var newStyles = create(args);
129
+ stack.push([styles, style]);
130
+ styles = newStyles;
131
+ style = newStyle;
132
+ if (styles[KEYS.__style__]) {
133
+ style = style ? Object.assign({}, style, styles[KEYS.__style__]) : styles[KEYS.__style__];
134
+ }
135
+ styled[KEYS.__styles__] = styles;
136
+ styled[KEYS.__style__] = style;
137
+ };
138
+ var USE_PREFIX = "use--";
139
+ var ELEMENT_PREFIX = "__";
140
+ var MOD_PREFIX = "_";
141
+ var MOD_SEPARATOR = "_";
142
+ var parseElement = function parseElement2(name) {
143
+ return name.replace(ELEMENT_PREFIX, "");
144
+ };
145
+ var parseAttribute = function parseAttribute2(name) {
146
+ return name.replace(MOD_PREFIX, "").split(MOD_SEPARATOR);
147
+ };
148
+ var appendClassName = function appendClassName2(className) {
149
+ var cn = arguments.length > 1 && arguments[1] !== void 0 ? arguments[1] : "";
150
+ if (className) {
151
+ cn += (cn ? " " : "") + className;
152
+ }
153
+ return cn;
154
+ };
155
+ var appendElement = function appendElement2(styles2, key) {
156
+ var cn = arguments.length > 2 && arguments[2] !== void 0 ? arguments[2] : "";
157
+ return appendClassName(styles2[ELEMENT_PREFIX + key], cn);
158
+ };
159
+ var appendModifier = function appendModifier2(styles2, key, value) {
160
+ var cn = arguments.length > 3 && arguments[3] !== void 0 ? arguments[3] : "";
161
+ if (value === void 0 || value === null || value === false || value === "") return cn;
162
+ cn = appendClassName(styles2[MOD_PREFIX + key], cn);
163
+ if (typeof value === "boolean" || _typeof(value) === "object" || typeof value === "function") return cn;
164
+ cn = appendClassName(styles2[MOD_SEPARATOR + key + MOD_SEPARATOR + value], cn);
165
+ return cn;
166
+ };
167
+ function map(element) {
168
+ var currStyles = styled[KEYS.__styles__];
169
+ var nextProps = {};
170
+ var cn = appendElement(currStyles, element);
171
+ var vars = null;
172
+ var uses = currStyles[KEYS.__use__] || {};
173
+ var len = arguments.length;
174
+ var useProps;
175
+ for (var i = len - 1; i > 0; i--) {
176
+ var currProps = arguments[i];
177
+ if (!currProps) continue;
178
+ useProps = useProps || currProps[KEYS.__use__];
179
+ if (!vars && KEYS.__style__ in currProps) {
180
+ vars = styled[KEYS.__style__];
181
+ }
182
+ for (var key in currProps) {
183
+ if (key === KEYS.__use__ || key === KEYS.__style__ || key in nextProps) {
184
+ continue;
185
+ }
186
+ var value = currProps[key];
187
+ cn = appendModifier(currStyles, key, value, cn);
188
+ var valueType = _typeof(value);
189
+ if (valueType === "string" || valueType === "boolean" || valueType === "number") {
190
+ var useKey = key + "_" + value;
191
+ if (key + "_true" in uses || useKey in uses) {
192
+ cn = appendModifier(currStyles, USE_PREFIX + key, value, cn);
193
+ if (uses[useKey]) {
194
+ continue;
195
+ }
196
+ }
197
+ }
198
+ nextProps[key] = value;
199
+ }
200
+ }
201
+ if (useProps) {
202
+ for (var _key in useProps) {
203
+ var _value = useProps[_key];
204
+ cn = appendModifier(currStyles, USE_PREFIX + _key, _value, cn);
205
+ }
206
+ }
207
+ cn = appendClassName(nextProps[KEYS.__classProp__], cn);
208
+ if (cn) nextProps[KEYS.__classProp__] = cn;
209
+ if (vars) {
210
+ nextProps.style = typeof style === "string" ? vars + (nextProps.style || "") : Object.assign({}, vars, nextProps.style || {});
211
+ }
212
+ return nextProps;
213
+ }
16
214
  export {
17
- getStyles
215
+ ELEMENT_PREFIX,
216
+ KEYS,
217
+ MOD_PREFIX,
218
+ MOD_SEPARATOR,
219
+ RESHADOW_ID,
220
+ USE_PREFIX,
221
+ appendClassName,
222
+ appendElement,
223
+ appendModifier,
224
+ clearStyles,
225
+ create,
226
+ css,
227
+ getStyles,
228
+ map,
229
+ parseAttribute,
230
+ parseElement,
231
+ set,
232
+ styled,
233
+ use
18
234
  };