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