@charcoal-ui/styled 2.0.0-alpha.2 → 2.0.0-alpha.4

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/dist/index.cjs CHANGED
@@ -1,2 +1,1003 @@
1
- var n=require("warning"),t=require("@charcoal-ui/foundation"),e=require("@charcoal-ui/utils"),r=require("react"),o=require("styled-components");function u(n){return n&&"object"==typeof n&&"default"in n?n:{default:n}}var i=/*#__PURE__*/u(n),c=/*#__PURE__*/u(r);function a(){return a=Object.assign||function(n){for(var t=1;t<arguments.length;t++){var e=arguments[t];for(var r in e)Object.prototype.hasOwnProperty.call(e,r)&&(n[r]=e[r])}return n},a.apply(this,arguments)}function l(n,t){return t||(t=n.slice(0)),n.raw=t,n}function f(n){throw new Error(0===arguments.length?"unreachable":"unreachable ("+JSON.stringify(n)+")")}var d=function(n){return null!=n};function s(){return Object.assign.apply(Object,[{}].concat([].slice.call(arguments)))}function v(n){return Object.keys(n)}var p,g,h,m,b,y=function(n,t,e){return Object.defineProperties(n,Object.fromEntries(t.map(function(n){return[n,{get:function(){return e(n)},enumerable:!0,configurable:!0}]})))},S=function(n,t){return y(n,Object.keys(t),function(n){return t[n]})},x=function(n,t){return function e(r){var o=n.filter(function(n){return!r.includes(n)});return y(t(r),o,function(n){return 0===o.length?f():e([].concat(r,[n]))})}([])},w=function(n){return"var("+n+")"},k=o.createGlobalStyle(p||(p=l(["\n ","\n"])),function(n){var t=n.background;return Object.entries(n.themeMap).map(function(n){var e=n[0],r=n[1];return e.startsWith("@media")?o.css(g||(g=l(["\n "," {\n :root {\n ","\n ","\n }\n }\n "])),e,void 0!==t&&o.css(h||(h=l(["\n background-color: ",";\n "])),r.color[t]),E(r)):o.css(m||(m=l(["\n /* stylelint-disable-next-line no-duplicate-selectors */\n "," {\n ","\n ","\n }\n "])),e,void 0!==t&&o.css(b||(b=l(["\n background-color: ",";\n "])),r.color[t]),E(r))})}),E=function(n){return Object.entries(n.color).flatMap(function(t){var r=t[0],o=t[1];return[T(e.customPropertyToken(r),o)].concat(Object.entries(n.effect).map(function(n){var t=n[1];return T(e.customPropertyToken(r,[n[0]]),e.applyEffect(o,[t]))}))}).join(";")},T=function(n,t){return n+": "+t},j=new RegExp(/^(\w|-)+$/);function O(n){if(!j.test(n))throw new Error("Unexpected key :"+n+", expect: /^(\\w|-)+$/")}var L=function(n){return void 0===n&&(n="theme"),function(t){O(n),void 0!==t?document.documentElement.dataset[n]=t:delete document.documentElement.dataset[n]}},P=function(n){void 0===n&&(n="charcoal-theme"),O(n);var t=H("(prefers-color-scheme: dark)"),e=void 0!==t?t?"dark":"light":void 0,r=A(n),o=r[0];return[r[2]&&void 0!==e?null!=o?o:e:void 0,r[1],void 0===o]};function A(n,t){var e=r.useState(!1),o=e[0],u=e[1],i=r.useState(),c=i[0],a=i[1],l=r.useMemo(function(){return null==t?void 0:t()},[t]);r.useEffect(function(){return d(),window.addEventListener("storage",f),function(){window.removeEventListener("storage",f)}});var f=function(t){t.storageArea===localStorage&&t.key===n&&d()},d=function(){var t,e=localStorage.getItem(n);a(null!=(t=null!==e?function(n){try{return JSON.parse(n)}catch(t){return n}}(e):null)?t:l),u(!0)};return[null!=c?c:l,function(t){if(void 0===t)localStorage.removeItem(n);else{var e=function(n){return"string"==typeof n?n:JSON.stringify(n)}(t);localStorage.setItem(n,e)}var r=new StorageEvent("storage",{bubbles:!0,cancelable:!1,key:n,url:location.href,storageArea:localStorage});dispatchEvent(r)},o]}function H(n){var t=r.useState(),e=t[0],o=t[1];return r.useEffect(function(){var t=window.matchMedia(n),e=function(){o(t.matches)};return t.addEventListener("change",e),o(t.matches),function(){t.removeEventListener("change",e)}},[n]),e}function I(n){return O(n.localStorageKey),O(n.rootAttribute),/*#__PURE__*/c.default.createElement("script",{dangerouslySetInnerHTML:{__html:"'use strict';\n(function () {\n var localStorageKey = '"+n.localStorageKey+"'\n var rootAttribute = '"+n.rootAttribute+"'\n var currentTheme = localStorage.getItem(localStorageKey);\n if (currentTheme) {\n document.documentElement.dataset[rootAttribute] = currentTheme;\n }\n})();\n"}})}I.defaultProps={localStorageKey:"charcoal-theme",rootAttribute:"theme"};var z=["margin","padding"],C=["top","right","bottom","left","vertical","horizontal","all"],M=["width","height"],q=["top","right","bottom","left"],K=["focus"];function D(n,t){if(void 0===t&&(t=!1),t)return{};var e=v(n.color),r=v(n.effect),o=v(n.gradientColor),u=G(),i=V(n),c=S({},{bg:s(y({},e,function(n){return x(r,function(t){return u("bg",n,t)})}),y({},o,function(n){return function(t){return x(r,function(e){return i(n,e,t)})}})),font:y({},e,function(n){return x(r,function(t){return u("font",n,t)})})}),a=["monospace","bold","preserveHalfLeading"],l=F(n),d=y({},["typography"],function(n){return function(n){return x(a,function(t){return l(n,{preserveHalfLeading:t.includes("preserveHalfLeading"),monospace:t.includes("monospace"),bold:t.includes("bold")})})}}),p=Q(n),g=y({},z,function(n){return t=C,e=function(t){return p(n,t)},function n(r){var o=t.filter(function(n){return!r.map(function(n){return n[0]}).includes(n)});return function(n,t,e){return Object.defineProperties(n,Object.fromEntries(t.map(function(n){return[n,{value:function(){return e.apply(void 0,[n].concat([].slice.call(arguments)))},enumerable:!0,configurable:!0}]})))}(e(r),o,function(t){return 0===o.length?f():n([].concat(r,[[t].concat([].slice.call(arguments,1))]))})}([]);var t,e}),h=X(n),m=nn(n),b=Z(),w=y({},M,function(n){return S({},{px:function(t){return h(n,t)},column:function(t){return m(n,t)},auto:b(n,"auto"),full:b(n,"100%")})}),k=tn(n),E=x(v(n.elementEffect),function(n){return k(n)}),T=en(n),j=S({},{border:y({},v(n.border),function(n){return x(q,function(t){return T(n,t)})})}),O=rn(n),L=S({},{borderRadius:function(n){return O(n)}}),P=$(n);return s(c,d,g,w,E,j,L,S({},{outline:y({},v(n.outline),function(n){return x(K,function(t){return P(n,t)})})}))}function R(n){return"bg"===n?"background-color":"color"}function J(n){return["hover","press","disabled"].includes(n)}function N(n,t){var r,o,u;return"hover"===n?{"&:hover":(r={},r[e.notDisabledSelector]=t,r)}:"press"===n?{"&:active":(o={},o[e.notDisabledSelector]=t,o)}:"disabled"===n?((u={})[e.disabledSelector]=t,u):f(n)}var G=function(n){return function(n,t,r){return void 0===r&&(r=[]),un(function(){var o;return a(((o={})[R(n)]=w(e.customPropertyToken(t.toString())),o),r.filter(J).reduce(function(r,o){var u;return a({},r,N(o,((u={})[R(n)]=w(e.customPropertyToken(t.toString(),[o])),u)))},{}))},r.length>0?"font"===n?{colorTransition:!0}:{backgroundColorTransition:!0}:{})}},V=function(n){return function(t,r,o){void 0===r&&(r=[]);var u=e.gradient(o);return un(function(o){var c=!B(o),l=e.dur(.2);return c&&r.length>0?a({position:"relative",zIndex:0,overflow:"hidden"},r.filter(J).reduce(function(r,o){var i;return a({},r,{"&::before":a({zIndex:-1},_,{transition:l+" background-color"}),"&::after":a({zIndex:-2},_,u(n.gradientColor[t]))},N(o,{"&::before":{backgroundColor:e.applyEffect(null,null!=(i=n.effect[o])?i:[])}}))},{})):(i.default(0===r.length,"'Transition' will not be applied. You can get around this by specifying 'preserveHalfLeading' or both 'padding' and 'typograpy'."),a({},u(n.gradientColor[t]),r.filter(J).reduce(function(r,o){var i;return a({},r,N(o,a({},u(e.applyEffectToGradient(null!=(i=n.effect[o])?i:[])(n.gradientColor[t])))))},{})))})}},W=function(n,t){return{boxShadow:"0 0 0 "+e.px(n)+" "+t}},$=function(n){return function(t,r){var o=n.outline[t].weight,u=n.outline[t].color;return un(function(){var n,t,i;return r.includes("focus")?(t=W(o,u),(i={})[e.notDisabledSelector]={"&:focus, &:active":a({outline:"none"},t),"&:focus:not(:focus-visible), &:active:not(:focus-visible)":{outline:"none"},"&:focus-visible":a({outline:"none"},t)},i):{"&&":(n={},n[e.notDisabledSelector]=W(o,u),n)}},{boxShadowTransition:!0})}},_={content:"''",display:"block",position:"absolute",width:"100%",height:"100%",top:0,left:0},B=function(n){var t=n.hasVerticalPadding;return void 0!==n.cancelHalfLeadingPx&&!(void 0!==t&&t)},F=function(n){return function(t,r){void 0===r&&(r={});var o=r.preserveHalfLeading,u=void 0!==o&&o,i=r.monospace,c=void 0!==i&&i,l=r.bold,f=void 0!==l&&l,d=n.typography.size[t],s=-e.halfLeading(d);return un(function(n){return a({fontSize:e.px(d.fontSize),lineHeight:e.px(d.lineHeight)},c&&{fontFamily:"monospace"},f&&{fontWeight:"bold"},B(n)&&{display:"flow-root","&::before":a({},U,{marginTop:e.px(s)}),"&::after":a({},U,{marginBottom:e.px(s)})})},u?{}:{cancelHalfLeadingPx:s})}},U={display:"block",width:0,height:0,content:"''"};function Y(n,t){return n+"-"+t}var Q=function(n){return function(t,r){var o=r.reduce(function(n,t){var e=t[0],r=t[1];return"all"===e?(n.top=r,n.right=r,n.bottom=r,n.left=r):"vertical"===e?(n.top=r,n.bottom=r):"horizontal"===e?(n.right=r,n.left=r):n[e]=r,n},{}),u=o.top,i=o.right,c=o.bottom,l=o.left,f="padding"===t&&void 0!==u&&void 0!==c&&"auto"!==u&&"auto"!==c;return un(function(r){var o,d,s,v,p=r.cancelHalfLeadingPx,g=void 0===p?0:p;return a({},void 0!==u&&((o={})[Y(t,"top")]="auto"===u?"auto":e.px(n.spacing[u]+(f?g:0)),o),void 0!==c&&((d={})[Y(t,"bottom")]="auto"===c?"auto":e.px(n.spacing[c]+(f?g:0)),d),void 0!==i&&((s={})[Y(t,"right")]="auto"===i?"auto":e.px(n.spacing[i]),s),void 0!==l&&((v={})[Y(t,"left")]="auto"===l?"auto":e.px(n.spacing[l]),v))},f?{hasVerticalPadding:!0}:{})}},X=function(n){return function(t,r){return un(function(){var o;return(o={})[t]="auto"===r?"auto":e.px(n.spacing[r]),o})}},Z=function(n){return function(n,t){return un(function(){var e;return(e={})[n]=t,e})}},nn=function(n){return function(r,o){return un(function(){var u;return(u={})[r]=e.px(t.columnSystem(o,n.grid.unit.column,n.grid.unit.gutter)),u})}},tn=function(n){return function(t){return void 0===t&&(t=[]),un(function(){return t.filter(J).reduce(function(t,e){var r,o;return a({},t,N(e,{opacity:Array.isArray(n.elementEffect[e])||"opacity"!==(null==(r=n.elementEffect[e])?void 0:r.type)?f():null==(o=n.elementEffect[e])?void 0:o.opacity}))},{})})}},en=function(n){return function(t,e){var r=0===e.length,o="solid 1px "+n.border[t].color;return un(function(){return a({},r?{border:o}:e.reduce(function(n,t){var e;return a({},n,((e={})[function(n){return"border-"+n}(t)]=o,e))},{}))})}},rn=function(n){return function(t){return un(function(){return{borderRadius:e.px(n.borderRadius[t])}})}},on=Symbol("internal");function un(n,t){var e;return void 0===t&&(t={}),(e={})[on]={operation:n,context:t},e}var cn=function(n){return d(n)&&!1!==n};exports.SetThemeScript=I,exports.TokenInjector=function(n){/*#__PURE__*/return c.default.createElement(k,{themeMap:n.theme,background:n.background})},exports.createTheme=function(n){return D({},!0),function(n){return function(t){var r=t.theme;if(null==r)throw new Error("`theme` is invalid. `<ThemeProvider>` is not likely mounted.");var o,u=n(D(r)),i=[].concat(Array.isArray(u)?u:[u],[(o=e.dur(.2),un(function(n){var t=n.colorTransition,e=n.backgroundColorTransition,r=n.boxShadowTransition;return{transition:[void 0!==t&&t?"color":null,void 0!==e&&e?"background-color":null,void 0!==r&&r?"box-shadow":null].filter(d).map(function(n){return o+" "+n}).join(", ")}}))]).filter(cn),c=i.reduce(function(n,t){return a({},n,t[on].context)},{});return i.map(function(n){return n[on].operation(c)})}}},exports.getThemeSync=function(n){return void 0===n&&(n="charcoal-theme"),localStorage.getItem(n)},exports.prefersColorScheme=function(n){return"@media (prefers-color-scheme: "+n+")"},exports.themeSelector=function(n,t){return":root[data-"+(null!=t?t:"theme")+"='"+n+"']"},exports.themeSetter=L,exports.useLocalStorage=A,exports.useMedia=H,exports.useTheme=P,exports.useThemeSetter=function(n){var t=void 0===n?{}:n,e=t.key,o=void 0===e?"charcoal-theme":e,u=t.setter,i=void 0===u?L():u,c=P(o),a=c[0],l=c[2];r.useEffect(function(){void 0!==a&&i(l?void 0:a)},[i,l,a])};
1
+ var warning = require('warning');
2
+ var foundation = require('@charcoal-ui/foundation');
3
+ var utils = require('@charcoal-ui/utils');
4
+ var React = require('react');
5
+ var styledComponents = require('styled-components');
6
+
7
+ function _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'default' in e ? e : { 'default': e }; }
8
+
9
+ var warning__default = /*#__PURE__*/_interopDefaultLegacy(warning);
10
+ var React__default = /*#__PURE__*/_interopDefaultLegacy(React);
11
+
12
+ function _extends() {
13
+ _extends = Object.assign || function (target) {
14
+ for (var i = 1; i < arguments.length; i++) {
15
+ var source = arguments[i];
16
+
17
+ for (var key in source) {
18
+ if (Object.prototype.hasOwnProperty.call(source, key)) {
19
+ target[key] = source[key];
20
+ }
21
+ }
22
+ }
23
+
24
+ return target;
25
+ };
26
+
27
+ return _extends.apply(this, arguments);
28
+ }
29
+
30
+ function _taggedTemplateLiteralLoose(strings, raw) {
31
+ if (!raw) {
32
+ raw = strings.slice(0);
33
+ }
34
+
35
+ strings.raw = raw;
36
+ return strings;
37
+ }
38
+
39
+ function unreachable(value) {
40
+ throw new Error(arguments.length === 0 ? 'unreachable' : "unreachable (" + JSON.stringify(value) + ")");
41
+ }
42
+ /**
43
+ * Check whether a value is non-null and non-undefined
44
+ *
45
+ * @param value nullable
46
+ */
47
+
48
+ var isPresent = function isPresent(value) {
49
+ return value != null;
50
+ }; // eslint-disable-next-line @typescript-eslint/no-explicit-any
51
+
52
+ function objectAssign() {
53
+ return Object.assign.apply(Object, [{}].concat([].slice.call(arguments)));
54
+ }
55
+ function objectKeys(obj) {
56
+ return Object.keys(obj);
57
+ }
58
+
59
+ /**
60
+ * 配列で指定したプロパティを動的に生やす
61
+ *
62
+ * @param source 拡張するオブジェクト
63
+ * @param member オブジェクトに生やすプロパティ一覧
64
+ * @param chain プロパティに格納される値を生成する関数
65
+ *
66
+ * @example
67
+ *
68
+ * const o = factory({}, ['red', 'blue'],
69
+ * color => hex(color)
70
+ * )
71
+ *
72
+ * console.log(o.red) //=> #ff0000
73
+ */
74
+
75
+ var factory = function factory(source, member, chain) {
76
+ return Object.defineProperties(source, Object.fromEntries(member.map(function (key) {
77
+ return [key, {
78
+ get: function get() {
79
+ return chain(key);
80
+ },
81
+ enumerable: true,
82
+ configurable: true
83
+ }];
84
+ })));
85
+ };
86
+ /**
87
+ * 配列で指定した名前のメソッドを動的に生やす
88
+ *
89
+ * @param source 拡張するオブジェクト
90
+ * @param member オブジェクトに生やすメソッド名一覧
91
+ * @param chain メソッドの戻り値になる値を生成する関数
92
+ *
93
+ * @example
94
+ *
95
+ * const o = argumentedFactory({}, ['red', 'blue'],
96
+ * (color, alpha: number) => hex(color, alpha)
97
+ * )
98
+ *
99
+ * console.log(o.red(0.5)) //=> #ff000077
100
+ */
101
+
102
+ var argumentedFactory = function argumentedFactory(source, member, chain) {
103
+ return Object.defineProperties(source, Object.fromEntries(member.map(function (key) {
104
+ return [key, {
105
+ value: function value() {
106
+ return chain.apply(void 0, [key].concat([].slice.call(arguments)));
107
+ },
108
+ enumerable: true,
109
+ configurable: true
110
+ }];
111
+ })));
112
+ };
113
+ /**
114
+ * オブジェクトで指定したプロパティ名と値を動的に生やす
115
+ *
116
+ * @param source 拡張するオブジェクト
117
+ * @param def オブジェクトに生やす定義(プロパティ名と値)
118
+ *
119
+ * @example
120
+ *
121
+ * const o = constFactory({}, {
122
+ * red: '#f00',
123
+ * blue: '#00f',
124
+ * })
125
+ *
126
+ * console.log(o.red) //=> #f00
127
+ */
128
+
129
+ var constFactory = function constFactory(source, def) {
130
+ return factory(source, Object.keys(def), function (key) {
131
+ return def[key];
132
+ });
133
+ };
134
+ /**
135
+ * 配列で指定したモディファイア(プロパティ)をチェーン可能な再帰オブジェクトを動的に生やす
136
+ *
137
+ * @param modifiers オブジェクトに生やすモディファイヤ一覧
138
+ * @param source 指定されたモディファイヤの一覧から値を生成する関数
139
+ *
140
+ * @example
141
+ *
142
+ * const o = modifiedArgumentedFactory(['red', 'blue'],
143
+ * modifiers => modifiers.map(color => hex(color)).join(',')
144
+ * )
145
+ *
146
+ * console.log(o.red.blue) => #f00,#00f
147
+ */
148
+
149
+ var modifiedFactory = function modifiedFactory(modifiers, source) {
150
+ return function recursiveModifiedFactory(applied) {
151
+ var notApplied = modifiers.filter(function (v) {
152
+ return !applied.includes(v);
153
+ });
154
+ return factory(source(applied), notApplied, function (modifier) {
155
+ return notApplied.length === 0 ? unreachable() : recursiveModifiedFactory([].concat(applied, [modifier]));
156
+ });
157
+ }([]);
158
+ };
159
+ /**
160
+ * 配列で指定したモディファイア(メソッド)をチェーン可能な再帰オブジェクトを動的に生やす
161
+ *
162
+ * @param modifiers オブジェクトに生やすモディファイヤ一覧
163
+ * @param source 指定されたモディファイヤの一覧から値を生成する関数
164
+ * @param _inferPhantom 関数形式のモディファイヤの引数型を推論するためのメタタイプ(引数の個数に合わせてタプルで指定する)
165
+ *
166
+ * @example
167
+ *
168
+ * const o = modifiedArgumentedFactory(['red', 'blue'],
169
+ * modifiers => modifiers.map(([color, alpha]) => hex(color, alpha)).join(',')
170
+ * , {} as [number])
171
+ *
172
+ * console.log(o.red(0.5).blue(1)) => #ff000077,#0000ffff
173
+ */
174
+
175
+ var modifiedArgumentedFactory = function modifiedArgumentedFactory(modifiers, source) {
176
+ return function recursiveModifiedFactory(applied) {
177
+ var notApplied = modifiers.filter(function (v) {
178
+ return !applied.map(function (_ref) {
179
+ var w = _ref[0];
180
+ return w;
181
+ }).includes(v);
182
+ });
183
+ return argumentedFactory(source(applied), notApplied, function (modifier) {
184
+ return notApplied.length === 0 ? unreachable() : recursiveModifiedFactory([].concat(applied, [[modifier].concat([].slice.call(arguments, 1))]));
185
+ });
186
+ }([]);
187
+ };
188
+ var variable = function variable(value) {
189
+ return "var(" + value + ")";
190
+ };
191
+
192
+ var _templateObject, _templateObject2, _templateObject3, _templateObject4, _templateObject5;
193
+ var GlobalStyle = styledComponents.createGlobalStyle(_templateObject || (_templateObject = _taggedTemplateLiteralLoose(["\n ", "\n"])), function (_ref) {
194
+ var themeMap = _ref.themeMap,
195
+ background = _ref.background;
196
+ return Object.entries(themeMap).map(function (_ref2) {
197
+ var key = _ref2[0],
198
+ theme = _ref2[1];
199
+ return key.startsWith('@media') ? styledComponents.css(_templateObject2 || (_templateObject2 = _taggedTemplateLiteralLoose(["\n ", " {\n :root {\n ", "\n ", "\n }\n }\n "])), key, background !== undefined && styledComponents.css(_templateObject3 || (_templateObject3 = _taggedTemplateLiteralLoose(["\n background-color: ", ";\n "])), theme.color[background]), customProperties(theme)) : styledComponents.css(_templateObject4 || (_templateObject4 = _taggedTemplateLiteralLoose(["\n /* stylelint-disable-next-line no-duplicate-selectors */\n ", " {\n ", "\n ", "\n }\n "])), key, background !== undefined && styledComponents.css(_templateObject5 || (_templateObject5 = _taggedTemplateLiteralLoose(["\n background-color: ", ";\n "])), theme.color[background]), customProperties(theme));
200
+ });
201
+ });
202
+
203
+ var customProperties = function customProperties(theme) {
204
+ return Object.entries(theme.color).flatMap(function (_ref3) {
205
+ var colorKey = _ref3[0],
206
+ color = _ref3[1];
207
+ return [variableDefinition(utils.customPropertyToken(colorKey), color)].concat(Object.entries(theme.effect).map(function (_ref4) {
208
+ var effectKey = _ref4[0],
209
+ effect = _ref4[1];
210
+ return variableDefinition(utils.customPropertyToken(colorKey, [effectKey]), utils.applyEffect(color, [effect]));
211
+ }));
212
+ }).join(';');
213
+ };
214
+
215
+ var variableDefinition = function variableDefinition(prop, value) {
216
+ return prop + ": " + value;
217
+ };
218
+
219
+ function TokenInjector(_ref5) {
220
+ var themeMap = _ref5.theme,
221
+ background = _ref5.background;
222
+ return /*#__PURE__*/React__default["default"].createElement(GlobalStyle, {
223
+ themeMap: themeMap,
224
+ background: background
225
+ });
226
+ }
227
+
228
+ var LOCAL_STORAGE_KEY = 'charcoal-theme';
229
+ var DEFAULT_ROOT_ATTRIBUTE = 'theme';
230
+ var keyStringRegExp = new RegExp(/^(\w|-)+$/);
231
+ /**
232
+ * 文字列が英数字_-のみで構成されているか検証する。不正な文字列ならエラーを投げる
233
+ * @param key 検証するキー
234
+ */
235
+
236
+ function assertKeyString(key) {
237
+ if (!keyStringRegExp.test(key)) {
238
+ throw new Error("Unexpected key :" + key + ", expect: /^(\\w|-)+$/");
239
+ }
240
+ }
241
+ /**
242
+ * `<html data-theme="dark">` のような設定を行うデフォルトのセッター
243
+ */
244
+
245
+ var themeSetter = function themeSetter(attr) {
246
+ if (attr === void 0) {
247
+ attr = DEFAULT_ROOT_ATTRIBUTE;
248
+ }
249
+
250
+ return function (theme) {
251
+ assertKeyString(attr);
252
+
253
+ if (theme !== undefined) {
254
+ document.documentElement.dataset[attr] = theme;
255
+ } else {
256
+ delete document.documentElement.dataset[attr];
257
+ }
258
+ };
259
+ };
260
+ /**
261
+ * `<html data-theme="dark">` にマッチするセレクタを生成する
262
+ */
263
+
264
+ function themeSelector(theme, attr) {
265
+ return ":root[data-" + (attr != null ? attr : DEFAULT_ROOT_ATTRIBUTE) + "='" + theme + "']";
266
+ }
267
+ /**
268
+ * prefers-color-scheme を利用する media クエリを生成する
269
+ */
270
+
271
+ function prefersColorScheme(theme) {
272
+ return "@media (prefers-color-scheme: " + theme + ")";
273
+ }
274
+ /**
275
+ * LocalStorageからテーマの情報を取得して、変化時にテーマをセットするhooks
276
+ */
277
+
278
+ function useThemeSetter(_temp) {
279
+ var _ref = _temp === void 0 ? {} : _temp,
280
+ _ref$key = _ref.key,
281
+ key = _ref$key === void 0 ? LOCAL_STORAGE_KEY : _ref$key,
282
+ _ref$setter = _ref.setter,
283
+ setter = _ref$setter === void 0 ? themeSetter() : _ref$setter;
284
+
285
+ var _useTheme = useTheme(key),
286
+ theme = _useTheme[0],
287
+ system = _useTheme[2];
288
+
289
+ React.useEffect(function () {
290
+ if (theme === undefined) {
291
+ return;
292
+ } // prefers-color-scheme から値を取っている場合にはcssのみで処理したいのでアンセットする
293
+
294
+
295
+ setter(system ? undefined : theme);
296
+ }, [setter, system, theme]);
297
+ }
298
+ /**
299
+ * 同期的にLocalStorageからテーマを取得するヘルパ
300
+ */
301
+
302
+ function getThemeSync(key) {
303
+ if (key === void 0) {
304
+ key = LOCAL_STORAGE_KEY;
305
+ }
306
+
307
+ var theme = localStorage.getItem(key);
308
+ return theme;
309
+ }
310
+ /**
311
+ * LocalStorage, prefers-color-scheme からテーマの情報を取得して、現在のテーマを返すhooks
312
+ *
313
+ * `dark` `light` という名前だけは特別扱いされていて、prefers-color-schemeにマッチした場合に返ります
314
+ */
315
+
316
+ var useTheme = function useTheme(key) {
317
+ if (key === void 0) {
318
+ key = LOCAL_STORAGE_KEY;
319
+ }
320
+
321
+ assertKeyString(key);
322
+ var isDark = useMedia('(prefers-color-scheme: dark)');
323
+ var media = isDark !== undefined ? isDark ? 'dark' : 'light' : undefined;
324
+
325
+ var _useLocalStorage = useLocalStorage(key),
326
+ local = _useLocalStorage[0],
327
+ setTheme = _useLocalStorage[1],
328
+ ready = _useLocalStorage[2];
329
+
330
+ var theme = !ready || media === undefined ? undefined : local != null ? local : media;
331
+ var system = local === undefined;
332
+ return [theme, setTheme, system];
333
+ };
334
+ function useLocalStorage(key, defaultValue) {
335
+ var _useState = React.useState(false),
336
+ ready = _useState[0],
337
+ setReady = _useState[1];
338
+
339
+ var _useState2 = React.useState(),
340
+ state = _useState2[0],
341
+ setState = _useState2[1];
342
+
343
+ var defaultValueMemo = React.useMemo(function () {
344
+ return defaultValue == null ? void 0 : defaultValue();
345
+ }, [defaultValue]);
346
+ React.useEffect(function () {
347
+ fetch();
348
+ window.addEventListener('storage', handleStorage);
349
+ return function () {
350
+ window.removeEventListener('storage', handleStorage);
351
+ };
352
+ });
353
+
354
+ var handleStorage = function handleStorage(e) {
355
+ if (e.storageArea !== localStorage) {
356
+ return;
357
+ }
358
+
359
+ if (e.key !== key) {
360
+ return;
361
+ }
362
+
363
+ fetch();
364
+ };
365
+
366
+ var fetch = function fetch() {
367
+ var _ref2;
368
+
369
+ var raw = localStorage.getItem(key);
370
+ setState((_ref2 = raw !== null ? deserialize(raw) : null) != null ? _ref2 : defaultValueMemo);
371
+ setReady(true);
372
+ };
373
+
374
+ var set = function set(value) {
375
+ if (value === undefined) {
376
+ // undefinedがセットされる場合にはkeyごと削除
377
+ localStorage.removeItem(key);
378
+ } else {
379
+ var raw = serialize(value);
380
+ localStorage.setItem(key, raw);
381
+ } // 同一ウィンドウではstorageイベントが発火しないので、手動で発火させる
382
+
383
+
384
+ var event = new StorageEvent('storage', {
385
+ bubbles: true,
386
+ cancelable: false,
387
+ key: key,
388
+ url: location.href,
389
+ storageArea: localStorage
390
+ });
391
+ dispatchEvent(event);
392
+ };
393
+
394
+ return [state != null ? state : defaultValueMemo, set, ready];
395
+ }
396
+
397
+ function deserialize(raw) {
398
+ try {
399
+ return JSON.parse(raw);
400
+ } catch (_unused) {
401
+ // syntax error はすべて文字列として扱う
402
+ return raw;
403
+ }
404
+ }
405
+
406
+ function serialize(value) {
407
+ if (typeof value === 'string') {
408
+ return value;
409
+ } else {
410
+ return JSON.stringify(value);
411
+ }
412
+ }
413
+
414
+ function useMedia(query) {
415
+ var _useState3 = React.useState(),
416
+ match = _useState3[0],
417
+ setState = _useState3[1];
418
+
419
+ React.useEffect(function () {
420
+ var matcher = window.matchMedia(query);
421
+
422
+ var onChange = function onChange() {
423
+ setState(matcher.matches);
424
+ };
425
+
426
+ matcher.addEventListener('change', onChange);
427
+ setState(matcher.matches);
428
+ return function () {
429
+ matcher.removeEventListener('change', onChange);
430
+ };
431
+ }, [query]);
432
+ return match;
433
+ }
434
+
435
+ /**
436
+ * 同期的にテーマをローカルストレージから取得してhtmlの属性に設定するスクリプトタグ
437
+ * @param props localStorageのキー、htmlのdataになる属性のキーを含むオブジェクト
438
+ * @returns
439
+ */
440
+
441
+ function SetThemeScript(props) {
442
+ assertKeyString(props.localStorageKey);
443
+ assertKeyString(props.rootAttribute);
444
+ var src = "'use strict';\n(function () {\n var localStorageKey = '" + props.localStorageKey + "'\n var rootAttribute = '" + props.rootAttribute + "'\n var currentTheme = localStorage.getItem(localStorageKey);\n if (currentTheme) {\n document.documentElement.dataset[rootAttribute] = currentTheme;\n }\n})();\n";
445
+ return /*#__PURE__*/React__default["default"].createElement("script", {
446
+ dangerouslySetInnerHTML: {
447
+ __html: src
448
+ }
449
+ });
450
+ }
451
+ var defaultProps = {
452
+ localStorageKey: LOCAL_STORAGE_KEY,
453
+ rootAttribute: DEFAULT_ROOT_ATTRIBUTE
454
+ };
455
+ SetThemeScript.defaultProps = defaultProps;
456
+
457
+ var spacingProperties = ['margin', 'padding'];
458
+ var spacingDirections = ['top', 'right', 'bottom', 'left', 'vertical', 'horizontal', 'all'];
459
+ var fixedProperties = ['width', 'height'];
460
+ var borderDirections = ['top', 'right', 'bottom', 'left'];
461
+ var outlineType = ['focus'];
462
+ /**
463
+ * `theme(o => [...])` の `o` の部分を構築する
464
+ *
465
+ * @param theme テーマオブジェクト
466
+ * @param isPhantom 型推論のためだけに使う場合にランタイムコストをゼロにするフラグ
467
+ */
468
+
469
+ function builder(theme, isPhantom) {
470
+ if (isPhantom === void 0) {
471
+ isPhantom = false;
472
+ }
473
+
474
+ if (isPhantom) {
475
+ // eslint-disable-next-line @typescript-eslint/consistent-type-assertions
476
+ return {};
477
+ }
478
+
479
+ var colors = objectKeys(theme.color);
480
+ var effects = objectKeys(theme.effect); // 色
481
+
482
+ var gradientColors = objectKeys(theme.gradientColor);
483
+ var colorCss = createColorCss();
484
+ var gradientColorCss = createGradientColorCss(theme);
485
+ var colorObject = constFactory({}, {
486
+ bg: objectAssign(factory({}, colors, function (color) {
487
+ return modifiedFactory(effects, function (modifiers) {
488
+ return colorCss('bg', color, modifiers);
489
+ });
490
+ }), factory({}, gradientColors, function (color) {
491
+ return function (direction) {
492
+ return modifiedFactory(effects, function (modifiers) {
493
+ return gradientColorCss(color, modifiers, direction);
494
+ });
495
+ };
496
+ })),
497
+ font: factory({}, colors, function (color) {
498
+ return modifiedFactory(effects, function (modifiers) {
499
+ return colorCss('font', color, modifiers);
500
+ });
501
+ })
502
+ }); // タイポグラフィ
503
+
504
+ var typographyModifiers = [// TODO
505
+ 'monospace', 'bold', 'preserveHalfLeading'];
506
+ var typographyCss = createTypographyCss(theme);
507
+ var typographyObject = factory({}, ['typography'], function (_) {
508
+ return function (size) {
509
+ return modifiedFactory(typographyModifiers, function (modifiers) {
510
+ return typographyCss(size, {
511
+ preserveHalfLeading: modifiers.includes('preserveHalfLeading'),
512
+ monospace: modifiers.includes('monospace'),
513
+ bold: modifiers.includes('bold')
514
+ });
515
+ });
516
+ };
517
+ }); // スペーシング
518
+
519
+ var spacingCss = createSpacingCss(theme);
520
+ var spacingObject = factory({}, spacingProperties, function (spacingProperty) {
521
+ return modifiedArgumentedFactory(spacingDirections, function (modifiers) {
522
+ return spacingCss(spacingProperty, modifiers);
523
+ });
524
+ }); // 大きさ
525
+
526
+ var fixedPxCss = createFixedPxCss(theme);
527
+ var fixedColumnCss = createFixedColumnCss(theme);
528
+ var fixedRelativeCss = createFixedRelativeCss();
529
+ var fixedObject = factory({}, fixedProperties, function (property) {
530
+ return constFactory({}, {
531
+ px: function px(size) {
532
+ return fixedPxCss(property, size);
533
+ },
534
+ column: function column(span) {
535
+ return fixedColumnCss(property, span);
536
+ },
537
+ auto: fixedRelativeCss(property, 'auto'),
538
+ full: fixedRelativeCss(property, '100%')
539
+ });
540
+ }); // 要素へのエフェクト (etc: 透過)
541
+
542
+ var elementEffectCss = createElementEffectCss(theme);
543
+ var elementEffectObject = modifiedFactory(objectKeys(theme.elementEffect), function (modifiers) {
544
+ return elementEffectCss(modifiers);
545
+ }); // ボーダー
546
+
547
+ var borderCss = createBorderCss(theme);
548
+ var borderObject = constFactory({}, {
549
+ border: factory({}, objectKeys(theme.border), function (variant) {
550
+ return modifiedFactory(borderDirections, function (modifiers) {
551
+ return borderCss(variant, modifiers);
552
+ });
553
+ })
554
+ }); // 角丸
555
+
556
+ var borderRadiusCss = createBorderRadiusCss(theme);
557
+ var borderRadiusObject = constFactory({}, {
558
+ borderRadius: function borderRadius(radius) {
559
+ return borderRadiusCss(radius);
560
+ }
561
+ }); // アウトライン
562
+
563
+ var outlineCss = createOutlineColorCss(theme);
564
+ var outlineObject = constFactory({}, {
565
+ outline: factory({}, objectKeys(theme.outline), function (variant) {
566
+ return modifiedFactory(outlineType, function (modifiers) {
567
+ return outlineCss(variant, modifiers);
568
+ });
569
+ })
570
+ });
571
+ return objectAssign(colorObject, typographyObject, spacingObject, fixedObject, elementEffectObject, borderObject, borderRadiusObject, outlineObject);
572
+ }
573
+
574
+ function targetProperty(target) {
575
+ return target === 'bg' ? 'background-color' : 'color';
576
+ }
577
+
578
+ function isSupportedEffect(effect) {
579
+ return ['hover', 'press', 'disabled'].includes(effect);
580
+ }
581
+
582
+ function onEffectPseudo(effect, css) {
583
+ var _hover, _active, _ref;
584
+
585
+ return effect === 'hover' ? {
586
+ '&:hover': (_hover = {}, _hover[utils.notDisabledSelector] = css, _hover)
587
+ } : effect === 'press' ? {
588
+ '&:active': (_active = {}, _active[utils.notDisabledSelector] = css, _active)
589
+ } : // eslint-disable-next-line @typescript-eslint/no-unnecessary-condition
590
+ effect === 'disabled' ? (_ref = {}, _ref[utils.disabledSelector] = css, _ref) : unreachable(effect);
591
+ }
592
+
593
+ var createColorCss = function createColorCss(_theme) {
594
+ return function (target, color, effects) {
595
+ if (effects === void 0) {
596
+ effects = [];
597
+ }
598
+
599
+ return internal(function () {
600
+ var _extends2;
601
+
602
+ return _extends((_extends2 = {}, _extends2[targetProperty(target)] = variable(utils.customPropertyToken(color.toString())), _extends2), effects.filter(isSupportedEffect).reduce(function (acc, effect) {
603
+ var _onEffectPseudo;
604
+
605
+ return _extends({}, acc, onEffectPseudo(effect, (_onEffectPseudo = {}, _onEffectPseudo[targetProperty(target)] = variable(utils.customPropertyToken(color.toString(), [effect])), _onEffectPseudo)));
606
+ }, {}));
607
+ }, effects.length > 0 ? target === 'font' ? {
608
+ colorTransition: true
609
+ } : {
610
+ backgroundColorTransition: true
611
+ } : {});
612
+ };
613
+ }; // TODO: deprecate
614
+
615
+
616
+ var TRANSITION_DURATION = 0.2;
617
+
618
+ var createGradientColorCss = function createGradientColorCss(theme) {
619
+ return function (color, effects, direction) {
620
+ if (effects === void 0) {
621
+ effects = [];
622
+ }
623
+
624
+ var toLinearGradient = utils.gradient(direction);
625
+ return internal(function (context) {
626
+ var optimized = !useHalfLeadingCanceller(context);
627
+ var duration = utils.dur(TRANSITION_DURATION);
628
+
629
+ if (optimized && effects.length > 0) {
630
+ return _extends({
631
+ position: 'relative',
632
+ zIndex: 0,
633
+ overflow: 'hidden'
634
+ }, effects.filter(isSupportedEffect).reduce(function (acc, effect) {
635
+ var _theme$effect$effect;
636
+
637
+ return _extends({}, acc, {
638
+ '&::before': _extends({
639
+ zIndex: -1
640
+ }, overlayElement, {
641
+ transition: duration + " background-color"
642
+ }),
643
+ '&::after': _extends({
644
+ zIndex: -2
645
+ }, overlayElement, toLinearGradient(theme.gradientColor[color]))
646
+ }, onEffectPseudo(effect, {
647
+ '&::before': {
648
+ backgroundColor: utils.applyEffect(null, (_theme$effect$effect = theme.effect[effect]) != null ? _theme$effect$effect : [])
649
+ }
650
+ }));
651
+ }, {}));
652
+ } else {
653
+ warning__default["default"](effects.length === 0, // eslint-disable-next-line max-len
654
+ "'Transition' will not be applied. You can get around this by specifying 'preserveHalfLeading' or both 'padding' and 'typograpy'.");
655
+ return _extends({}, toLinearGradient(theme.gradientColor[color]), effects.filter(isSupportedEffect).reduce(function (acc, effect) {
656
+ var _theme$effect$effect2;
657
+
658
+ return _extends({}, acc, onEffectPseudo(effect, _extends({}, toLinearGradient(utils.applyEffectToGradient((_theme$effect$effect2 = theme.effect[effect]) != null ? _theme$effect$effect2 : [])(theme.gradientColor[color])))));
659
+ }, {}));
660
+ }
661
+ });
662
+ };
663
+ };
664
+ /**
665
+ * @see https://developer.mozilla.org/ja/docs/Web/CSS/:focus-visible#selectively_showing_the_focus_indicator
666
+ */
667
+
668
+
669
+ var onFocus = function onFocus(css) {
670
+ var _ref2;
671
+
672
+ return _ref2 = {}, _ref2[utils.notDisabledSelector] = {
673
+ '&:focus, &:active': _extends({
674
+ outline: 'none'
675
+ }, css),
676
+ '&:focus:not(:focus-visible), &:active:not(:focus-visible)': {
677
+ outline: 'none'
678
+ },
679
+ '&:focus-visible': _extends({
680
+ outline: 'none'
681
+ }, css)
682
+ }, _ref2;
683
+ };
684
+
685
+ var outlineCss = function outlineCss(weight, color) {
686
+ return {
687
+ boxShadow: "0 0 0 " + utils.px(weight) + " " + color
688
+ };
689
+ };
690
+
691
+ var createOutlineColorCss = function createOutlineColorCss(theme) {
692
+ return function (variant, modifiers) {
693
+ var weight = theme.outline[variant].weight;
694
+ var color = theme.outline[variant].color;
695
+ return internal(function () {
696
+ var _2;
697
+
698
+ return modifiers.includes('focus') ? onFocus(outlineCss(weight, color)) : {
699
+ '&&': (_2 = {}, _2[utils.notDisabledSelector] = outlineCss(weight, color), _2)
700
+ };
701
+ }, {
702
+ boxShadowTransition: true
703
+ });
704
+ };
705
+ };
706
+
707
+ var overlayElement = {
708
+ content: "''",
709
+ display: 'block',
710
+ position: 'absolute',
711
+ width: '100%',
712
+ height: '100%',
713
+ top: 0,
714
+ left: 0
715
+ }; // half-leadingをキャンセルするとき && 垂直方向のpaddingが無い時
716
+ // -> before/afterを入れる
717
+
718
+ var useHalfLeadingCanceller = function useHalfLeadingCanceller(_ref3) {
719
+ var cancelHalfLeadingPx = _ref3.cancelHalfLeadingPx,
720
+ _ref3$hasVerticalPadd = _ref3.hasVerticalPadding,
721
+ hasVerticalPadding = _ref3$hasVerticalPadd === void 0 ? false : _ref3$hasVerticalPadd;
722
+ return cancelHalfLeadingPx !== undefined && !hasVerticalPadding;
723
+ };
724
+
725
+ var createTypographyCss = function createTypographyCss(theme) {
726
+ return function (size, options) {
727
+ if (options === void 0) {
728
+ options = {};
729
+ }
730
+
731
+ var _options = options,
732
+ _options$preserveHalf = _options.preserveHalfLeading,
733
+ preserveHalfLeading = _options$preserveHalf === void 0 ? false : _options$preserveHalf,
734
+ _options$monospace = _options.monospace,
735
+ monospace = _options$monospace === void 0 ? false : _options$monospace,
736
+ _options$bold = _options.bold,
737
+ bold = _options$bold === void 0 ? false : _options$bold;
738
+ var descriptor = theme.typography.size[size];
739
+ var margin = -utils.halfLeading(descriptor);
740
+ return internal(function (context) {
741
+ return _extends({
742
+ fontSize: utils.px(descriptor.fontSize),
743
+ lineHeight: utils.px(descriptor.lineHeight)
744
+ }, monospace && {
745
+ fontFamily: 'monospace'
746
+ }, bold && {
747
+ fontWeight: 'bold'
748
+ }, useHalfLeadingCanceller(context) && {
749
+ // prevent margin collapsing
750
+ display: 'flow-root',
751
+ // cancel half-leading with negative margin
752
+ '&::before': _extends({}, leadingCancel, {
753
+ marginTop: utils.px(margin)
754
+ }),
755
+ '&::after': _extends({}, leadingCancel, {
756
+ marginBottom: utils.px(margin)
757
+ })
758
+ });
759
+ }, !preserveHalfLeading ? {
760
+ cancelHalfLeadingPx: margin
761
+ } : {});
762
+ };
763
+ };
764
+
765
+ var leadingCancel = {
766
+ display: 'block',
767
+ width: 0,
768
+ height: 0,
769
+ content: "''"
770
+ };
771
+
772
+ function spacingProperty(property, direction) {
773
+ return property + "-" + direction;
774
+ }
775
+
776
+ var createSpacingCss = function createSpacingCss(theme) {
777
+ return function (property, modifiers) {
778
+ var _modifiers$reduce = modifiers.reduce(function (acc, _ref4) {
779
+ var direction = _ref4[0],
780
+ size = _ref4[1];
781
+
782
+ if (direction === 'all') {
783
+ acc.top = size;
784
+ acc.right = size;
785
+ acc.bottom = size;
786
+ acc.left = size;
787
+ } else if (direction === 'vertical') {
788
+ acc.top = size;
789
+ acc.bottom = size;
790
+ } else if (direction === 'horizontal') {
791
+ acc.right = size;
792
+ acc.left = size;
793
+ } else {
794
+ acc[direction] = size;
795
+ }
796
+
797
+ return acc;
798
+ }, {}),
799
+ top = _modifiers$reduce.top,
800
+ right = _modifiers$reduce.right,
801
+ bottom = _modifiers$reduce.bottom,
802
+ left = _modifiers$reduce.left;
803
+
804
+ var hasVerticalPadding = property === 'padding' && top !== undefined && bottom !== undefined && top !== 'auto' && bottom !== 'auto';
805
+ return internal(function (_ref5) {
806
+ var _ref6, _ref7, _ref8, _ref9;
807
+
808
+ var _ref5$cancelHalfLeadi = _ref5.cancelHalfLeadingPx,
809
+ cancelHalfLeadingPx = _ref5$cancelHalfLeadi === void 0 ? 0 : _ref5$cancelHalfLeadi;
810
+ return _extends({}, top !== undefined && (_ref6 = {}, _ref6[spacingProperty(property, 'top')] = top === 'auto' ? 'auto' : utils.px(theme.spacing[top] + (hasVerticalPadding ? cancelHalfLeadingPx : 0)), _ref6), bottom !== undefined && (_ref7 = {}, _ref7[spacingProperty(property, 'bottom')] = bottom === 'auto' ? 'auto' : utils.px(theme.spacing[bottom] + (hasVerticalPadding ? cancelHalfLeadingPx : 0)), _ref7), right !== undefined && (_ref8 = {}, _ref8[spacingProperty(property, 'right')] = right === 'auto' ? 'auto' : utils.px(theme.spacing[right]), _ref8), left !== undefined && (_ref9 = {}, _ref9[spacingProperty(property, 'left')] = left === 'auto' ? 'auto' : utils.px(theme.spacing[left]), _ref9));
811
+ }, hasVerticalPadding ? {
812
+ hasVerticalPadding: true
813
+ } : {});
814
+ };
815
+ };
816
+
817
+ var createFixedPxCss = function createFixedPxCss(theme) {
818
+ return function (property, size) {
819
+ return internal(function () {
820
+ var _ref10;
821
+
822
+ return _ref10 = {}, _ref10[property] = size === 'auto' ? 'auto' : utils.px(theme.spacing[size]), _ref10;
823
+ });
824
+ };
825
+ };
826
+
827
+ var createFixedRelativeCss = function createFixedRelativeCss(_theme) {
828
+ return function (property, amount) {
829
+ return internal(function () {
830
+ var _ref11;
831
+
832
+ return _ref11 = {}, _ref11[property] = amount, _ref11;
833
+ });
834
+ };
835
+ };
836
+
837
+ var createFixedColumnCss = function createFixedColumnCss(theme) {
838
+ return function (property, span) {
839
+ return internal(function () {
840
+ var _ref12;
841
+
842
+ return _ref12 = {}, _ref12[property] = utils.px(foundation.columnSystem(span, theme.grid.unit.column, theme.grid.unit.gutter)), _ref12;
843
+ });
844
+ };
845
+ };
846
+
847
+ var createElementEffectCss = function createElementEffectCss(theme) {
848
+ return function (effects) {
849
+ if (effects === void 0) {
850
+ effects = [];
851
+ }
852
+
853
+ return internal(function () {
854
+ return effects.filter(isSupportedEffect).reduce(function (acc, effect) {
855
+ var _theme$elementEffect$, _theme$elementEffect$2;
856
+
857
+ return _extends({}, acc, onEffectPseudo(effect, {
858
+ opacity: !Array.isArray(theme.elementEffect[effect]) && ((_theme$elementEffect$ = theme.elementEffect[effect]) == null ? void 0 : _theme$elementEffect$.type) === 'opacity' ? (_theme$elementEffect$2 = theme.elementEffect[effect]) == null ? void 0 : _theme$elementEffect$2.opacity : unreachable()
859
+ }));
860
+ }, {});
861
+ });
862
+ };
863
+ };
864
+
865
+ function borderProperty(direction) {
866
+ return "border-" + direction;
867
+ }
868
+
869
+ function borderShorthand(color) {
870
+ return "solid 1px " + color;
871
+ }
872
+
873
+ var createBorderCss = function createBorderCss(theme) {
874
+ return function (variant, directions) {
875
+ var all = directions.length === 0;
876
+ var value = borderShorthand(theme.border[variant].color);
877
+ return internal(function () {
878
+ return _extends({}, all ? {
879
+ border: value
880
+ } : directions.reduce(function (acc, direction) {
881
+ var _extends3;
882
+
883
+ return _extends({}, acc, (_extends3 = {}, _extends3[borderProperty(direction)] = value, _extends3));
884
+ }, {}));
885
+ });
886
+ };
887
+ };
888
+
889
+ var createBorderRadiusCss = function createBorderRadiusCss(theme) {
890
+ return function (size) {
891
+ return internal(function () {
892
+ return {
893
+ borderRadius: utils.px(theme.borderRadius[size])
894
+ };
895
+ });
896
+ };
897
+ };
898
+
899
+ var commonSpec = function commonSpec(_theme) {
900
+ var duration = utils.dur(TRANSITION_DURATION);
901
+
902
+ var transition = function transition(property) {
903
+ return {
904
+ transition: property.map(function (v) {
905
+ return duration + " " + v;
906
+ }).join(', ')
907
+ };
908
+ };
909
+
910
+ return internal(function (_ref13) {
911
+ var _ref13$colorTransitio = _ref13.colorTransition,
912
+ colorTransition = _ref13$colorTransitio === void 0 ? false : _ref13$colorTransitio,
913
+ _ref13$backgroundColo = _ref13.backgroundColorTransition,
914
+ backgroundColorTransition = _ref13$backgroundColo === void 0 ? false : _ref13$backgroundColo,
915
+ _ref13$boxShadowTrans = _ref13.boxShadowTransition,
916
+ boxShadowTransition = _ref13$boxShadowTrans === void 0 ? false : _ref13$boxShadowTrans;
917
+ return transition([colorTransition ? 'color' : null, backgroundColorTransition ? 'background-color' : null, boxShadowTransition ? 'box-shadow' : null].filter(isPresent));
918
+ });
919
+ };
920
+
921
+ var internalSym = Symbol('internal');
922
+
923
+ function internal(operation, context) {
924
+ var _ref14;
925
+
926
+ if (context === void 0) {
927
+ context = {};
928
+ }
929
+
930
+ return _ref14 = {}, _ref14[internalSym] = {
931
+ operation: operation,
932
+ context: context
933
+ }, _ref14;
934
+ }
935
+
936
+ var nonBlank = function nonBlank(value) {
937
+ return isPresent(value) && value !== false;
938
+ };
939
+ /**
940
+ * `theme(o => [...])` の `theme` ユーティリティを構築する
941
+ *
942
+ * @param _styled styled-componnets の `styled` そのもの (型推論のために用いられる)
943
+ *
944
+ * @example
945
+ *
946
+ * import styled from 'styled-components'
947
+ * const theme = createTheme(styled)
948
+ *
949
+ * @example
950
+ *
951
+ * const theme = createTheme<DefaultTheme>()
952
+ */
953
+
954
+
955
+ function createTheme(_styled) {
956
+ // `theme(o => [...])` の `o` の部分の型推論のためだけに使う意味のない変数
957
+ // Tを型変数のまま渡してcreateThemeが呼ばれるまで型の具象化が行われないようにする
958
+ // eslint-disable-next-line @typescript-eslint/no-unsafe-argument, @typescript-eslint/no-explicit-any
959
+ builder({}, true); // ランタイムの `theme(o => [...])` のインターフェースを構築する
960
+
961
+
962
+ return function ( // ユーザー定義
963
+ spec) {
964
+ return function (_ref15) {
965
+ var theme = _ref15.theme;
966
+
967
+ if (theme == null) {
968
+ // テーマが入っていない場合は復旧不可能なのでエラーにする
969
+ throw new Error('`theme` is invalid. `<ThemeProvider>` is not likely mounted.');
970
+ } // styled-componentsのランタイムから受け取ったthemeオブジェクトをbuilderに食わせて`o`をつくる
971
+ // さらに、ユーザー定義にbuilderが構築した`o`を食わせる
972
+ // (`o`を一時変数に入れてしまうと型Tの具象化が行われるので関数合成を優先する)
973
+
974
+
975
+ var rawSpecDescriptor = spec(builder(theme)); // ユーザー定義の配列を整形
976
+
977
+ var specDescriptor = [].concat(Array.isArray(rawSpecDescriptor) ? rawSpecDescriptor : [rawSpecDescriptor], [commonSpec()]).filter(nonBlank); // 1パス目
978
+ // 全ユーザー定義を舐めて相互に影響し合う定義をチェックし、その結果(コンテキスト)を取得
979
+
980
+ var context = specDescriptor.reduce(function (acc, v) {
981
+ return _extends({}, acc, v[internalSym].context);
982
+ }, {}); // 2パス目
983
+ // コンテキストを見ながら最適化されたCSSを構築
984
+
985
+ return specDescriptor.map(function (v) {
986
+ return v[internalSym].operation(context);
987
+ });
988
+ };
989
+ };
990
+ }
991
+
992
+ exports.SetThemeScript = SetThemeScript;
993
+ exports.TokenInjector = TokenInjector;
994
+ exports.createTheme = createTheme;
995
+ exports.getThemeSync = getThemeSync;
996
+ exports.prefersColorScheme = prefersColorScheme;
997
+ exports.themeSelector = themeSelector;
998
+ exports.themeSetter = themeSetter;
999
+ exports.useLocalStorage = useLocalStorage;
1000
+ exports.useMedia = useMedia;
1001
+ exports.useTheme = useTheme;
1002
+ exports.useThemeSetter = useThemeSetter;
2
1003
  //# sourceMappingURL=index.cjs.map