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