@k8o/arte-odyssey 0.0.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 (276) hide show
  1. package/LICENSE +21 -0
  2. package/dist/components/accordion/accordion-button.d.ts +2 -0
  3. package/dist/components/accordion/accordion-button.js +40 -0
  4. package/dist/components/accordion/accordion-item.d.ts +4 -0
  5. package/dist/components/accordion/accordion-item.js +11 -0
  6. package/dist/components/accordion/accordion-panel.d.ts +2 -0
  7. package/dist/components/accordion/accordion-panel.js +21 -0
  8. package/dist/components/accordion/accordion.d.ts +2 -0
  9. package/dist/components/accordion/accordion.js +17 -0
  10. package/dist/components/accordion/accordion.stories.js +89 -0
  11. package/dist/components/accordion/context.d.ts +10 -0
  12. package/dist/components/accordion/context.js +38 -0
  13. package/dist/components/accordion/index.d.ts +4 -0
  14. package/dist/components/accordion/index.js +4 -0
  15. package/dist/components/alert/alert.d.ts +8 -0
  16. package/dist/components/alert/alert.js +46 -0
  17. package/dist/components/alert/alert.stories.js +51 -0
  18. package/dist/components/alert/index.d.ts +1 -0
  19. package/dist/components/alert/index.js +1 -0
  20. package/dist/components/anchor/anchor.d.ts +14 -0
  21. package/dist/components/anchor/anchor.js +31 -0
  22. package/dist/components/anchor/anchor.stories.js +23 -0
  23. package/dist/components/anchor/index.d.ts +1 -0
  24. package/dist/components/anchor/index.js +1 -0
  25. package/dist/components/baseline-status/baseline-status.d.ts +16 -0
  26. package/dist/components/baseline-status/baseline-status.js +39 -0
  27. package/dist/components/baseline-status/baseline-status.stories.js +15 -0
  28. package/dist/components/baseline-status/index.d.ts +1 -0
  29. package/dist/components/baseline-status/index.js +1 -0
  30. package/dist/components/breadcrumb/breadcrumb.d.ts +18 -0
  31. package/dist/components/breadcrumb/breadcrumb.js +36 -0
  32. package/dist/components/breadcrumb/breadcrumb.stories.js +40 -0
  33. package/dist/components/breadcrumb/index.d.ts +1 -0
  34. package/dist/components/breadcrumb/index.js +1 -0
  35. package/dist/components/button/button.d.ts +10 -0
  36. package/dist/components/button/button.js +55 -0
  37. package/dist/components/button/button.stories.js +96 -0
  38. package/dist/components/button/index.d.ts +1 -0
  39. package/dist/components/button/index.js +1 -0
  40. package/dist/components/card/card.d.ts +3 -0
  41. package/dist/components/card/card.js +26 -0
  42. package/dist/components/card/card.stories.js +38 -0
  43. package/dist/components/card/index.d.ts +2 -0
  44. package/dist/components/card/index.js +2 -0
  45. package/dist/components/card/interactive-card.d.ts +3 -0
  46. package/dist/components/card/interactive-card.js +34 -0
  47. package/dist/components/card/type.d.ts +6 -0
  48. package/dist/components/card/type.js +0 -0
  49. package/dist/components/code/code.d.ts +4 -0
  50. package/dist/components/code/code.js +38 -0
  51. package/dist/components/code/code.stories.js +60 -0
  52. package/dist/components/code/index.d.ts +1 -0
  53. package/dist/components/code/index.js +4 -0
  54. package/dist/components/dialog/dialog.d.ts +17 -0
  55. package/dist/components/dialog/dialog.js +85 -0
  56. package/dist/components/dialog/dialog.stories.js +98 -0
  57. package/dist/components/dialog/index.d.ts +1 -0
  58. package/dist/components/dialog/index.js +1 -0
  59. package/dist/components/drawer/drawer.d.ts +6 -0
  60. package/dist/components/drawer/drawer.js +56 -0
  61. package/dist/components/drawer/drawer.stories.js +25 -0
  62. package/dist/components/drawer/index.d.ts +1 -0
  63. package/dist/components/drawer/index.js +1 -0
  64. package/dist/components/dropdown-menu/dropdown-menu.d.ts +24 -0
  65. package/dist/components/dropdown-menu/dropdown-menu.js +130 -0
  66. package/dist/components/dropdown-menu/dropdown-menu.stories.js +111 -0
  67. package/dist/components/dropdown-menu/hooks.d.ts +23 -0
  68. package/dist/components/dropdown-menu/hooks.js +56 -0
  69. package/dist/components/dropdown-menu/index.d.ts +1 -0
  70. package/dist/components/dropdown-menu/index.js +1 -0
  71. package/dist/components/error-boundary/index.d.ts +1 -0
  72. package/dist/components/error-boundary/index.js +4 -0
  73. package/dist/components/form/autocomplete/autocomplete.d.ts +14 -0
  74. package/dist/components/form/autocomplete/autocomplete.js +225 -0
  75. package/dist/components/form/autocomplete/autocomplete.stories.js +59 -0
  76. package/dist/components/form/autocomplete/index.d.ts +1 -0
  77. package/dist/components/form/autocomplete/index.js +1 -0
  78. package/dist/components/form/checkbox/checkbox.d.ts +8 -0
  79. package/dist/components/form/checkbox/checkbox.js +40 -0
  80. package/dist/components/form/checkbox/checkbox.stories.js +27 -0
  81. package/dist/components/form/checkbox/index.d.ts +1 -0
  82. package/dist/components/form/checkbox/index.js +1 -0
  83. package/dist/components/form/form-control/form-control.d.ts +20 -0
  84. package/dist/components/form/form-control/form-control.js +53 -0
  85. package/dist/components/form/form-control/form-control.stories.js +94 -0
  86. package/dist/components/form/form-control/index.d.ts +1 -0
  87. package/dist/components/form/form-control/index.js +1 -0
  88. package/dist/components/form/number-field/index.d.ts +1 -0
  89. package/dist/components/form/number-field/index.js +1 -0
  90. package/dist/components/form/number-field/number-field.d.ts +17 -0
  91. package/dist/components/form/number-field/number-field.js +150 -0
  92. package/dist/components/form/number-field/number-field.stories.js +106 -0
  93. package/dist/components/form/radio/index.d.ts +1 -0
  94. package/dist/components/form/radio/index.js +1 -0
  95. package/dist/components/form/radio/radio.d.ts +11 -0
  96. package/dist/components/form/radio/radio.js +51 -0
  97. package/dist/components/form/radio/radio.stories.js +55 -0
  98. package/dist/components/form/range-field/index.d.ts +1 -0
  99. package/dist/components/form/range-field/index.js +4 -0
  100. package/dist/components/form/range-field/range-field.d.ts +17 -0
  101. package/dist/components/form/range-field/range-field.js +54 -0
  102. package/dist/components/form/range-field/range-field.stories.js +162 -0
  103. package/dist/components/form/select/index.d.ts +1 -0
  104. package/dist/components/form/select/index.js +1 -0
  105. package/dist/components/form/select/select.d.ts +14 -0
  106. package/dist/components/form/select/select.js +39 -0
  107. package/dist/components/form/select/select.stories.js +58 -0
  108. package/dist/components/form/text-field/index.d.ts +1 -0
  109. package/dist/components/form/text-field/index.js +1 -0
  110. package/dist/components/form/text-field/text-field.d.ts +15 -0
  111. package/dist/components/form/text-field/text-field.js +40 -0
  112. package/dist/components/form/text-field/text-field.stories.js +61 -0
  113. package/dist/components/form/textarea/index.d.ts +1 -0
  114. package/dist/components/form/textarea/index.js +1 -0
  115. package/dist/components/form/textarea/textarea.d.ts +18 -0
  116. package/dist/components/form/textarea/textarea.js +56 -0
  117. package/dist/components/form/textarea/textarea.stories.js +92 -0
  118. package/dist/components/heading/heading.d.ts +8 -0
  119. package/dist/components/heading/heading.js +77 -0
  120. package/dist/components/heading/heading.stories.js +52 -0
  121. package/dist/components/heading/index.d.ts +1 -0
  122. package/dist/components/heading/index.js +1 -0
  123. package/dist/components/icon-button/icon-button.d.ts +8 -0
  124. package/dist/components/icon-button/icon-button.js +38 -0
  125. package/dist/components/icon-button/icon-button.stories.js +54 -0
  126. package/dist/components/icon-button/index.d.ts +1 -0
  127. package/dist/components/icon-button/index.js +1 -0
  128. package/dist/components/icon-link/icon-link.d.ts +17 -0
  129. package/dist/components/icon-link/icon-link.js +37 -0
  130. package/dist/components/icon-link/icon-link.stories.js +40 -0
  131. package/dist/components/icon-link/index.d.ts +1 -0
  132. package/dist/components/icon-link/index.js +1 -0
  133. package/dist/components/icons/arte-odyssey.d.ts +3 -0
  134. package/dist/components/icons/arte-odyssey.js +463 -0
  135. package/dist/components/icons/base.d.ts +9 -0
  136. package/dist/components/icons/base.js +13 -0
  137. package/dist/components/icons/github-mark.d.ts +3 -0
  138. package/dist/components/icons/github-mark.js +33 -0
  139. package/dist/components/icons/icons.stories.js +276 -0
  140. package/dist/components/icons/index.d.ts +7 -0
  141. package/dist/components/icons/index.js +7 -0
  142. package/dist/components/icons/logo.d.ts +6 -0
  143. package/dist/components/icons/logo.js +50 -0
  144. package/dist/components/icons/lucide.d.ts +50 -0
  145. package/dist/components/icons/lucide.js +569 -0
  146. package/dist/components/icons/qiita.d.ts +3 -0
  147. package/dist/components/icons/qiita.js +48 -0
  148. package/dist/components/icons/twitter.d.ts +3 -0
  149. package/dist/components/icons/twitter.js +34 -0
  150. package/dist/components/icons/zenn.d.ts +6 -0
  151. package/dist/components/icons/zenn.js +41 -0
  152. package/dist/components/index.d.ts +37 -0
  153. package/dist/components/index.js +37 -0
  154. package/dist/components/link-button/index.d.ts +1 -0
  155. package/dist/components/link-button/index.js +1 -0
  156. package/dist/components/link-button/link-button.d.ts +19 -0
  157. package/dist/components/link-button/link-button.js +46 -0
  158. package/dist/components/link-button/link-button.stories.js +51 -0
  159. package/dist/components/list-box/hooks.d.ts +37 -0
  160. package/dist/components/list-box/hooks.js +70 -0
  161. package/dist/components/list-box/index.d.ts +1 -0
  162. package/dist/components/list-box/index.js +1 -0
  163. package/dist/components/list-box/list-box.d.ts +22 -0
  164. package/dist/components/list-box/list-box.js +145 -0
  165. package/dist/components/list-box/list-box.stories.js +69 -0
  166. package/dist/components/modal/index.d.ts +1 -0
  167. package/dist/components/modal/index.js +1 -0
  168. package/dist/components/modal/modal.d.ts +8 -0
  169. package/dist/components/modal/modal.js +118 -0
  170. package/dist/components/modal/modal.stories.js +22 -0
  171. package/dist/components/popover/hooks.d.ts +65 -0
  172. package/dist/components/popover/hooks.js +187 -0
  173. package/dist/components/popover/index.d.ts +1 -0
  174. package/dist/components/popover/index.js +1 -0
  175. package/dist/components/popover/popover.d.ts +18 -0
  176. package/dist/components/popover/popover.js +141 -0
  177. package/dist/components/popover/popover.stories.js +45 -0
  178. package/dist/components/progress/index.d.ts +1 -0
  179. package/dist/components/progress/index.js +1 -0
  180. package/dist/components/progress/progress.d.ts +7 -0
  181. package/dist/components/progress/progress.js +21 -0
  182. package/dist/components/progress/progress.stories.js +16 -0
  183. package/dist/components/providers/component-provider.d.ts +2 -0
  184. package/dist/components/providers/component-provider.js +9 -0
  185. package/dist/components/providers/index.d.ts +2 -0
  186. package/dist/components/providers/index.js +2 -0
  187. package/dist/components/providers/portal-root.d.ts +5 -0
  188. package/dist/components/providers/portal-root.js +17 -0
  189. package/dist/components/scroll-linked/index.d.ts +1 -0
  190. package/dist/components/scroll-linked/index.js +1 -0
  191. package/dist/components/scroll-linked/scroll-linked.d.ts +2 -0
  192. package/dist/components/scroll-linked/scroll-linked.js +21 -0
  193. package/dist/components/scroll-linked/scroll-linked.stories.js +18 -0
  194. package/dist/components/separator/index.d.ts +1 -0
  195. package/dist/components/separator/index.js +1 -0
  196. package/dist/components/separator/separator.d.ts +4 -0
  197. package/dist/components/separator/separator.js +20 -0
  198. package/dist/components/separator/separator.stories.js +27 -0
  199. package/dist/components/tabs/index.d.ts +1 -0
  200. package/dist/components/tabs/index.js +1 -0
  201. package/dist/components/tabs/tabs.d.ts +16 -0
  202. package/dist/components/tabs/tabs.js +145 -0
  203. package/dist/components/tabs/tabs.stories.js +49 -0
  204. package/dist/components/text-tag/index.d.ts +1 -0
  205. package/dist/components/text-tag/index.js +1 -0
  206. package/dist/components/text-tag/text-tag.d.ts +5 -0
  207. package/dist/components/text-tag/text-tag.js +23 -0
  208. package/dist/components/text-tag/text-tag.stories.js +30 -0
  209. package/dist/components/toast/index.d.ts +1 -0
  210. package/dist/components/toast/index.js +5 -0
  211. package/dist/components/toast/provider.d.ts +11 -0
  212. package/dist/components/toast/provider.js +125 -0
  213. package/dist/components/toast/toast.d.ts +9 -0
  214. package/dist/components/toast/toast.js +19 -0
  215. package/dist/components/toast/toast.stories.js +45 -0
  216. package/dist/components/tooltip/index.d.ts +1 -0
  217. package/dist/components/tooltip/index.js +1 -0
  218. package/dist/components/tooltip/tooltip.d.ts +13 -0
  219. package/dist/components/tooltip/tooltip.js +60 -0
  220. package/dist/components/tooltip/tooltip.stories.js +40 -0
  221. package/dist/helpers/cn.d.ts +2 -0
  222. package/dist/helpers/cn.js +8 -0
  223. package/dist/helpers/color/find-all-colors.d.ts +12 -0
  224. package/dist/helpers/color/find-all-colors.js +210 -0
  225. package/dist/helpers/is-internal-route.d.ts +1 -0
  226. package/dist/helpers/is-internal-route.js +12 -0
  227. package/dist/helpers/number/between.d.ts +1 -0
  228. package/dist/helpers/number/between.js +19 -0
  229. package/dist/helpers/number/cast.d.ts +1 -0
  230. package/dist/helpers/number/cast.js +41 -0
  231. package/dist/helpers/number/commalize.d.ts +1 -0
  232. package/dist/helpers/number/commalize.js +22 -0
  233. package/dist/helpers/number/index.d.ts +4 -0
  234. package/dist/helpers/number/index.js +10 -0
  235. package/dist/helpers/number/to-precision.d.ts +1 -0
  236. package/dist/helpers/number/to-precision.js +17 -0
  237. package/dist/helpers/uuid-v4.d.ts +1 -0
  238. package/dist/helpers/uuid-v4.js +32 -0
  239. package/dist/hooks/click-away/index.d.ts +2 -0
  240. package/dist/hooks/click-away/index.js +24 -0
  241. package/dist/hooks/click-away/index.test.js +31 -0
  242. package/dist/hooks/client/index.d.ts +1 -0
  243. package/dist/hooks/client/index.js +12 -0
  244. package/dist/hooks/clipboard/index.d.ts +4 -0
  245. package/dist/hooks/clipboard/index.js +17 -0
  246. package/dist/hooks/clipboard/index.test.js +35 -0
  247. package/dist/hooks/hash/index.d.ts +1 -0
  248. package/dist/hooks/hash/index.js +28 -0
  249. package/dist/hooks/hash/index.test.js +46 -0
  250. package/dist/hooks/index.d.ts +10 -0
  251. package/dist/hooks/index.js +10 -0
  252. package/dist/hooks/interval/index.d.ts +1 -0
  253. package/dist/hooks/interval/index.js +17 -0
  254. package/dist/hooks/interval/index.test.js +32 -0
  255. package/dist/hooks/local-storage/index.d.ts +1 -0
  256. package/dist/hooks/local-storage/index.js +48 -0
  257. package/dist/hooks/local-storage/index.test.js +82 -0
  258. package/dist/hooks/scroll-direction/index.d.ts +6 -0
  259. package/dist/hooks/scroll-direction/index.js +40 -0
  260. package/dist/hooks/scroll-direction/index.test.js +174 -0
  261. package/dist/hooks/step/index.d.ts +13 -0
  262. package/dist/hooks/step/index.js +39 -0
  263. package/dist/hooks/step/index.test.js +85 -0
  264. package/dist/hooks/timeout/index.d.ts +1 -0
  265. package/dist/hooks/timeout/index.js +17 -0
  266. package/dist/hooks/timeout/index.test.js +31 -0
  267. package/dist/hooks/window-size/index.d.ts +6 -0
  268. package/dist/hooks/window-size/index.js +22 -0
  269. package/dist/hooks/window-size/index.test.js +18 -0
  270. package/dist/index.d.ts +2 -0
  271. package/dist/index.js +2 -0
  272. package/dist/package.json +6 -0
  273. package/dist/styles/index.css +394 -0
  274. package/dist/types/variables.d.ts +6 -0
  275. package/dist/types/variables.js +0 -0
  276. package/package.json +110 -0
@@ -0,0 +1,12 @@
1
+ /**
2
+ * テキスト文字列内のすべての色の値とその位置を見つけます。
3
+ * HSL、RGB、RGBA、HSLA、HEX、名前付き色をサポートします。
4
+ *
5
+ * @param text - 色の値を検索するテキスト
6
+ * @returns 色の値、開始位置、終了位置を含む色オブジェクトの配列
7
+ */
8
+ export declare function findAllColors(text: string): {
9
+ color: string;
10
+ start: number;
11
+ end: number;
12
+ }[];
@@ -0,0 +1,210 @@
1
+ function findAllColors(text) {
2
+ const results = [];
3
+ function extractFunctionContent(text2, funcName) {
4
+ const funcPattern = new RegExp(`${funcName}\\s*\\(`, "gi");
5
+ const matches = [];
6
+ let match = funcPattern.exec(text2);
7
+ while (match !== null) {
8
+ const startIndex = match.index + match[0].length - 1;
9
+ let depth = 0;
10
+ let endIndex = -1;
11
+ for (let i = startIndex; i < text2.length; i++) {
12
+ if (text2[i] === "(") {
13
+ depth++;
14
+ } else if (text2[i] === ")") {
15
+ depth--;
16
+ if (depth === 0) {
17
+ endIndex = i;
18
+ break;
19
+ }
20
+ }
21
+ }
22
+ if (endIndex !== -1) {
23
+ const content = text2.substring(startIndex + 1, endIndex);
24
+ const fullColor = `${funcName.toLowerCase()}(${content})`;
25
+ matches.push({
26
+ color: fullColor,
27
+ start: match.index,
28
+ end: endIndex + 1
29
+ });
30
+ }
31
+ match = funcPattern.exec(text2);
32
+ }
33
+ return matches;
34
+ }
35
+ const colorFunctions = ["hsl", "rgb", "rgba", "hsla"];
36
+ for (const func of colorFunctions) {
37
+ const matches = extractFunctionContent(text, func);
38
+ results.push(...matches);
39
+ }
40
+ const hexPattern = /#([0-9a-fA-F]{3}|[0-9a-fA-F]{6})(?=\s|;|,|$|\)|]|})/g;
41
+ let hexMatch = hexPattern.exec(text);
42
+ while (hexMatch !== null) {
43
+ results.push({
44
+ color: hexMatch[0],
45
+ start: hexMatch.index,
46
+ end: hexMatch.index + hexMatch[0].length
47
+ });
48
+ hexMatch = hexPattern.exec(text);
49
+ }
50
+ const namedColors = [
51
+ "red",
52
+ "blue",
53
+ "green",
54
+ "yellow",
55
+ "orange",
56
+ "purple",
57
+ "pink",
58
+ "brown",
59
+ "black",
60
+ "white",
61
+ "gray",
62
+ "grey",
63
+ "cyan",
64
+ "magenta",
65
+ "lime",
66
+ "navy",
67
+ "maroon",
68
+ "olive",
69
+ "teal",
70
+ "silver",
71
+ "gold",
72
+ "indigo",
73
+ "violet"
74
+ ];
75
+ const lowerText = text.toLowerCase();
76
+ for (const color of namedColors) {
77
+ let startIndex = 0;
78
+ let index = lowerText.indexOf(color, startIndex);
79
+ while (index !== -1) {
80
+ const beforeChar = index > 0 ? lowerText[index - 1] ?? " " : " ";
81
+ const afterChar = index + color.length < lowerText.length ? lowerText[index + color.length] ?? " " : " ";
82
+ if (/\s|;|,|:/.test(beforeChar) && /\s|;|,|$|\)|]|}/.test(afterChar)) {
83
+ results.push({
84
+ color,
85
+ start: index,
86
+ end: index + color.length
87
+ });
88
+ }
89
+ startIndex = index + 1;
90
+ index = lowerText.indexOf(color, startIndex);
91
+ }
92
+ }
93
+ results.sort((a, b) => a.start - b.start);
94
+ const filteredResults = [];
95
+ for (const result of results) {
96
+ const hasOverlap = filteredResults.some(
97
+ (existing) => result.start >= existing.start && result.start < existing.end || result.end > existing.start && result.end <= existing.end || result.start <= existing.start && result.end >= existing.end
98
+ );
99
+ if (!hasOverlap) {
100
+ filteredResults.push(result);
101
+ }
102
+ }
103
+ return filteredResults;
104
+ }
105
+ if (import.meta.vitest) {
106
+ const { describe, expect, it } = import.meta.vitest;
107
+ describe("findAllColors", () => {
108
+ describe("\u5358\u4E00\u306E\u8272\u306E\u5834\u5408", () => {
109
+ it("HSL\u8272\u3092\u898B\u3064\u3051\u308B", () => {
110
+ const result = findAllColors("hsl(280, 70%, 50%)");
111
+ expect(result).toEqual([
112
+ { color: "hsl(280, 70%, 50%)", start: 0, end: 18 }
113
+ ]);
114
+ });
115
+ it("HEX\u8272\u3092\u898B\u3064\u3051\u308B", () => {
116
+ const result = findAllColors("#ff0080");
117
+ expect(result).toEqual([{ color: "#ff0080", start: 0, end: 7 }]);
118
+ });
119
+ it("\u540D\u524D\u4ED8\u304D\u8272\u3092\u898B\u3064\u3051\u308B", () => {
120
+ const result = findAllColors("background-color: red;");
121
+ expect(result).toEqual([{ color: "red", start: 18, end: 21 }]);
122
+ });
123
+ });
124
+ describe("\u8907\u6570\u306E\u8272\u306E\u5834\u5408", () => {
125
+ it("\u7570\u306A\u308B\u5F62\u5F0F\u306E\u8907\u6570\u306E\u8272\u3092\u898B\u3064\u3051\u308B", () => {
126
+ const result = findAllColors(
127
+ "border: 1px solid #ff0080; background: hsl(280, 70%, 50%); color: white;"
128
+ );
129
+ expect(result).toEqual([
130
+ { color: "#ff0080", start: 18, end: 25 },
131
+ { color: "hsl(280, 70%, 50%)", start: 39, end: 57 },
132
+ { color: "white", start: 66, end: 71 }
133
+ ]);
134
+ });
135
+ it("gradient\u5185\u306E\u8907\u6570\u306E\u8272\u3092\u898B\u3064\u3051\u308B", () => {
136
+ const result = findAllColors(
137
+ "linear-gradient(45deg, #ff0080, hsl(280, 70%, 50%), rgba(255, 0, 128, 0.5))"
138
+ );
139
+ expect(result).toEqual([
140
+ { color: "#ff0080", start: 23, end: 30 },
141
+ { color: "hsl(280, 70%, 50%)", start: 32, end: 50 },
142
+ { color: "rgba(255, 0, 128, 0.5)", start: 52, end: 74 }
143
+ ]);
144
+ });
145
+ });
146
+ describe("\u91CD\u8907\u3059\u308B\u8272\u30D1\u30BF\u30FC\u30F3\u306E\u5834\u5408", () => {
147
+ it("\u95A2\u6570\u578B\u8272\u3092\u540D\u524D\u4ED8\u304D\u8272\u3088\u308A\u512A\u5148\u3059\u308B", () => {
148
+ const result = findAllColors("rgb(255, 0, 0) red");
149
+ expect(result).toEqual([
150
+ { color: "rgb(255, 0, 0)", start: 0, end: 14 },
151
+ { color: "red", start: 15, end: 18 }
152
+ ]);
153
+ });
154
+ it("\u91CD\u8907\u3059\u308B\u9818\u57DF\u3067\u306F\u6700\u521D\u306E\u8272\u306E\u307F\u3092\u4FDD\u6301\u3059\u308B", () => {
155
+ const result = findAllColors("background-color: red");
156
+ expect(result).toEqual([{ color: "red", start: 18, end: 21 }]);
157
+ });
158
+ });
159
+ describe("\u8907\u96D1\u306ACSS\u95A2\u6570\u306E\u5834\u5408", () => {
160
+ it("calc\u5F0F\u3092\u542B\u3080HSL\u8272\u3092\u898B\u3064\u3051\u308B", () => {
161
+ const result = findAllColors("hsl(calc(var(--hue) + 50), 70%, 50%)");
162
+ expect(result).toEqual([
163
+ {
164
+ color: "hsl(calc(var(--hue) + 50), 70%, 50%)",
165
+ start: 0,
166
+ end: 36
167
+ }
168
+ ]);
169
+ });
170
+ it("\u30CD\u30B9\u30C8\u3057\u305F\u62EC\u5F27\u3092\u542B\u3080\u8272\u3092\u898B\u3064\u3051\u308B", () => {
171
+ const result = findAllColors(
172
+ "hsl(calc(sign(var(--x)) * 80 + 200), 70%, 50%)"
173
+ );
174
+ expect(result).toEqual([
175
+ {
176
+ color: "hsl(calc(sign(var(--x)) * 80 + 200), 70%, 50%)",
177
+ start: 0,
178
+ end: 46
179
+ }
180
+ ]);
181
+ });
182
+ });
183
+ describe("\u8272\u304C\u898B\u3064\u304B\u3089\u306A\u3044\u5834\u5408", () => {
184
+ it("\u7A7A\u306E\u914D\u5217\u3092\u8FD4\u3059", () => {
185
+ const result = findAllColors("transform: translateX(100px);");
186
+ expect(result).toEqual([]);
187
+ });
188
+ it("\u8272\u3067\u306A\u3044\u30C6\u30AD\u30B9\u30C8\u3067\u306F\u7A7A\u306E\u914D\u5217\u3092\u8FD4\u3059", () => {
189
+ const result = findAllColors("font-size: 16px; margin: 10px;");
190
+ expect(result).toEqual([]);
191
+ });
192
+ });
193
+ describe("\u30A8\u30C3\u30B8\u30B1\u30FC\u30B9", () => {
194
+ it("\u540C\u3058\u8272\u304C\u8907\u6570\u56DE\u51FA\u73FE\u3059\u308B\u5834\u5408", () => {
195
+ const result = findAllColors("color: red; border-color: red;");
196
+ expect(result).toEqual([
197
+ { color: "red", start: 7, end: 10 },
198
+ { color: "red", start: 26, end: 29 }
199
+ ]);
200
+ });
201
+ it("\u6587\u5B57\u5217\u306E\u5883\u754C\u3067\u306E\u8272\u691C\u51FA", () => {
202
+ const result = findAllColors("red");
203
+ expect(result).toEqual([{ color: "red", start: 0, end: 3 }]);
204
+ });
205
+ });
206
+ });
207
+ }
208
+ export {
209
+ findAllColors
210
+ };
@@ -0,0 +1 @@
1
+ export declare const isInternalRoute: (href: string) => boolean;
@@ -0,0 +1,12 @@
1
+ const isInternalRoute = (href) => !href.startsWith("http");
2
+ if (import.meta.vitest) {
3
+ it("http\u304B\u3089\u59CB\u307E\u308Bhref\u306Fexternal\u306A\u3082\u306E\u3068\u3057\u3066\u5224\u5B9A\u3059\u308B", () => {
4
+ expect(isInternalRoute("https://k8o.me/dummy")).toBe(false);
5
+ });
6
+ it("http\u304B\u3089\u59CB\u307E\u3089\u306A\u3044href\u306Fexternal\u306A\u3082\u306E\u3068\u3057\u3066\u5224\u5B9A\u3059\u308B", () => {
7
+ expect(isInternalRoute("/dummy")).toBe(true);
8
+ });
9
+ }
10
+ export {
11
+ isInternalRoute
12
+ };
@@ -0,0 +1 @@
1
+ export declare const between: (value: number, min: number, max: number) => number;
@@ -0,0 +1,19 @@
1
+ const between = (value, min, max) => {
2
+ return Math.min(Math.max(value, min), max);
3
+ };
4
+ if (import.meta.vitest) {
5
+ describe("between", () => {
6
+ it("min\u3068max\u306E\u9593\u306E\u5024\u306E\u5834\u5408\u306F\u305D\u306E\u307E\u307E\u8FD4\u3059", () => {
7
+ expect(between(5, 0, 10)).toBe(5);
8
+ });
9
+ it("min\u3088\u308A\u5C0F\u3055\u3044\u5834\u5408\u306Fmin\u3092\u8FD4\u3059", () => {
10
+ expect(between(-5, 0, 10)).toBe(0);
11
+ });
12
+ it("max\u3088\u308A\u5927\u304D\u3044\u5834\u5408\u306Fmax\u3092\u8FD4\u3059", () => {
13
+ expect(between(15, 0, 10)).toBe(10);
14
+ });
15
+ });
16
+ }
17
+ export {
18
+ between
19
+ };
@@ -0,0 +1 @@
1
+ export declare const cast: (value: string, step: number, precision?: number) => number;
@@ -0,0 +1,41 @@
1
+ import { toPrecision } from "./to-precision";
2
+ const FLOATING_POINT_REGEX = /^[Ee0-9+\-.]$/;
3
+ const isInvalidCharacter = (value) => {
4
+ return FLOATING_POINT_REGEX.test(value);
5
+ };
6
+ const sanitize = (value) => value.split("").filter(isInvalidCharacter).join("");
7
+ const parse = (value) => {
8
+ return Number.parseFloat(value.toString().replace(/[^\w.-]+/g, ""));
9
+ };
10
+ const countDecimalPlaces = (value) => {
11
+ if (!Number.isFinite(value)) return 0;
12
+ let e = 1;
13
+ let p = 0;
14
+ while (Math.round(value * e) / e !== value) {
15
+ e *= 10;
16
+ p += 1;
17
+ }
18
+ return p;
19
+ };
20
+ const cast = (value, step, precision) => {
21
+ const parsedValue = parse(sanitize(value));
22
+ if (Number.isNaN(parsedValue)) return 0;
23
+ const decimalPlaces = Math.max(
24
+ countDecimalPlaces(step),
25
+ countDecimalPlaces(parsedValue)
26
+ );
27
+ return toPrecision(parsedValue, precision ?? decimalPlaces);
28
+ };
29
+ if (import.meta.vitest) {
30
+ it("\u6587\u5B57\u3092\u6570\u5024\u306B\u5909\u63DB\u3059\u308B", () => {
31
+ expect(cast("1", 1)).toBe(1);
32
+ expect(cast("1.1", 1)).toBe(1.1);
33
+ expect(cast("1.1.1", 1)).toBe(1.1);
34
+ expect(cast("1.1.1", 2)).toBe(1.1);
35
+ expect(cast("1e4", 3)).toBe(1e4);
36
+ expect(cast("-19", 3)).toBe(-19);
37
+ });
38
+ }
39
+ export {
40
+ cast
41
+ };
@@ -0,0 +1 @@
1
+ export declare const commalize: (num: number) => string;
@@ -0,0 +1,22 @@
1
+ const commalize = (num) => {
2
+ const roundedNumber = Math.round(num);
3
+ const numberString = roundedNumber.toString();
4
+ return numberString.replace(/\B(?=(\d{3})+(?!\d))/g, ",");
5
+ };
6
+ if (import.meta.vitest) {
7
+ it("3\u6841\u672A\u6E80\u306E\u5834\u5408\u306F\u305D\u306E\u307E\u307E\u8FD4\u3059", () => {
8
+ expect(commalize(100)).toBe("100");
9
+ });
10
+ it("4\u6841\u306E\u5834\u5408\u306F\u30AB\u30F3\u30DE\u533A\u5207\u308A\u306B\u3059\u308B", () => {
11
+ expect(commalize(1e3)).toBe("1,000");
12
+ });
13
+ it("3\u6841\u6BCE\u306B\u30AB\u30F3\u30DE\u533A\u5207\u308A\u306B\u3059\u308B", () => {
14
+ expect(commalize(1e6)).toBe("1,000,000");
15
+ });
16
+ it("\u5C11\u6570\u306E\u5834\u5408\u306F\u56DB\u6368\u4E94\u5165\u3057\u3066\u6574\u6570\u306B\u3059\u308B", () => {
17
+ expect(commalize(1000.5)).toBe("1,001");
18
+ });
19
+ }
20
+ export {
21
+ commalize
22
+ };
@@ -0,0 +1,4 @@
1
+ export { between } from './between';
2
+ export { cast } from './cast';
3
+ export { commalize } from './commalize';
4
+ export { toPrecision } from './to-precision';
@@ -0,0 +1,10 @@
1
+ import { between } from "./between";
2
+ import { cast } from "./cast";
3
+ import { commalize } from "./commalize";
4
+ import { toPrecision } from "./to-precision";
5
+ export {
6
+ between,
7
+ cast,
8
+ commalize,
9
+ toPrecision
10
+ };
@@ -0,0 +1 @@
1
+ export declare const toPrecision: (value: number, precision?: number) => number;
@@ -0,0 +1,17 @@
1
+ const toPrecision = (value, precision) => {
2
+ const scaleFactor = 10 ** (precision ?? 10);
3
+ return Math.round(value * scaleFactor) / scaleFactor;
4
+ };
5
+ if (import.meta.vitest) {
6
+ it("\u6570\u5024\u3092\u6307\u5B9A\u3057\u305F\u6841\u6570\u306B\u4E38\u3081\u308B", () => {
7
+ expect(toPrecision(1.2345, 0)).toBe(1);
8
+ expect(toPrecision(1.2345, 1)).toBe(1.2);
9
+ expect(toPrecision(1.2345, 2)).toBe(1.23);
10
+ expect(toPrecision(1.2345, 3)).toBe(1.235);
11
+ expect(toPrecision(1.2345, 4)).toBe(1.2345);
12
+ expect(toPrecision(1.2345, 5)).toBe(1.2345);
13
+ });
14
+ }
15
+ export {
16
+ toPrecision
17
+ };
@@ -0,0 +1 @@
1
+ export declare const uuidV4: () => string;
@@ -0,0 +1,32 @@
1
+ const HEX_BASE = 16;
2
+ const uuidV4 = () => {
3
+ if (typeof window !== "undefined" && isSecureContext) {
4
+ return crypto.randomUUID();
5
+ }
6
+ return "xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx".replace(/[xy]/g, (c) => {
7
+ const randHex = Math.floor(Math.random() * HEX_BASE);
8
+ if (c === "y") {
9
+ return (randHex & 3 | 8).toString(HEX_BASE);
10
+ }
11
+ return randHex.toString(HEX_BASE);
12
+ });
13
+ };
14
+ if (import.meta.vitest) {
15
+ const testRegex = /^[0-9a-f]{8}-[0-9a-f]{4}-4[0-9a-f]{3}-[89ab][0-9a-f]{3}-[0-9a-f]{12}$/i;
16
+ beforeEach(() => {
17
+ vi.unstubAllGlobals();
18
+ });
19
+ it("\u5B89\u5168\u306A\u30B3\u30F3\u30C6\u30AD\u30B9\u30C8\u3067\u306FrandUUID\u304B\u3089uuidv4\u3092\u8FD4\u3059", () => {
20
+ vi.stubGlobal("isSecureContext", true);
21
+ const result = uuidV4();
22
+ expect(result).toMatch(testRegex);
23
+ });
24
+ it("\u5B89\u5168\u306A\u30B3\u30F3\u30C6\u30AD\u30B9\u30C8\u5916\u3067\u306F\u81EA\u4F5C\u306Euuidv4\u3092\u8FD4\u3059", () => {
25
+ vi.stubGlobal("isSecureContext", false);
26
+ const result = uuidV4();
27
+ expect(result).toMatch(testRegex);
28
+ });
29
+ }
30
+ export {
31
+ uuidV4
32
+ };
@@ -0,0 +1,2 @@
1
+ import { type RefObject } from 'react';
2
+ export declare const useClickAway: <T extends Element = HTMLElement>(callback: (e: Event) => void, enabled?: boolean) => RefObject<T | null>;
@@ -0,0 +1,24 @@
1
+ "use client";
2
+ import { useEffect, useRef } from "react";
3
+ const useClickAway = (callback, enabled = true) => {
4
+ const ref = useRef(null);
5
+ useEffect(() => {
6
+ if (!enabled) return;
7
+ const handler = (e) => {
8
+ const element = ref.current;
9
+ if (element && !element.contains(e.target)) {
10
+ callback(e);
11
+ }
12
+ };
13
+ document.addEventListener("mousedown", handler);
14
+ document.addEventListener("touchstart", handler);
15
+ return () => {
16
+ document.removeEventListener("mousedown", handler);
17
+ document.removeEventListener("touchstart", handler);
18
+ };
19
+ }, [callback, enabled]);
20
+ return ref;
21
+ };
22
+ export {
23
+ useClickAway
24
+ };
@@ -0,0 +1,31 @@
1
+ import { Fragment, jsx, jsxs } from "react/jsx-runtime";
2
+ import { fireEvent, render } from "@testing-library/react";
3
+ import { useClickAway } from ".";
4
+ const OutsideClicker = ({ callback }) => {
5
+ const ref = useClickAway(callback);
6
+ return /* @__PURE__ */ jsxs(Fragment, { children: [
7
+ /* @__PURE__ */ jsx("div", { ref, children: "Element" }),
8
+ /* @__PURE__ */ jsx("div", { children: "Outside" })
9
+ ] });
10
+ };
11
+ describe("useClickAway", () => {
12
+ it("\u9818\u57DF\u5916\u3092\u89E6\u308B\u3068callback\u304C\u547C\u3073\u51FA\u3055\u308C\u308B", () => {
13
+ const fn = vi.fn();
14
+ const { getByText } = render(/* @__PURE__ */ jsx(OutsideClicker, { callback: fn }));
15
+ const element = getByText("Element");
16
+ const outsideElement = getByText("Outside");
17
+ const click = (el) => {
18
+ fireEvent.mouseDown(el);
19
+ fireEvent.mouseUp(el);
20
+ };
21
+ expect(fn).not.toHaveBeenCalled();
22
+ click(element);
23
+ expect(fn).not.toHaveBeenCalled();
24
+ click(outsideElement);
25
+ expect(fn).toHaveBeenCalledOnce();
26
+ click(document.body);
27
+ expect(fn).toHaveBeenCalledTimes(2);
28
+ click(document);
29
+ expect(fn).toHaveBeenCalledTimes(3);
30
+ });
31
+ });
@@ -0,0 +1 @@
1
+ export declare const useClient: () => boolean;
@@ -0,0 +1,12 @@
1
+ import { useSyncExternalStore } from "react";
2
+ const useClient = () => {
3
+ return useSyncExternalStore(
4
+ () => () => {
5
+ },
6
+ () => true,
7
+ () => false
8
+ );
9
+ };
10
+ export {
11
+ useClient
12
+ };
@@ -0,0 +1,4 @@
1
+ export declare const useClipboard: () => {
2
+ writeClipboard: (text: string) => Promise<void>;
3
+ readClipboard: () => Promise<string>;
4
+ };
@@ -0,0 +1,17 @@
1
+ import { useCallback } from "react";
2
+ const useClipboard = () => {
3
+ const writeClipboard = useCallback(async (text) => {
4
+ await navigator.clipboard.writeText(text);
5
+ }, []);
6
+ const readClipboard = useCallback(async () => {
7
+ const text = await navigator.clipboard.readText();
8
+ return text;
9
+ }, []);
10
+ return {
11
+ writeClipboard,
12
+ readClipboard
13
+ };
14
+ };
15
+ export {
16
+ useClipboard
17
+ };
@@ -0,0 +1,35 @@
1
+ import { act, renderHook } from "@testing-library/react";
2
+ import { useClipboard } from ".";
3
+ describe("useClipboard", () => {
4
+ afterEach(() => {
5
+ vi.unstubAllGlobals();
6
+ });
7
+ it("\u30AF\u30EA\u30C3\u30D7\u30DC\u30FC\u30C9\u3092\u66F8\u304D\u8FBC\u3081\u308B", async () => {
8
+ const writeText = "test";
9
+ const writeTextMockFn = vi.fn();
10
+ vi.stubGlobal("navigator", {
11
+ clipboard: {
12
+ writeText: writeTextMockFn
13
+ }
14
+ });
15
+ const { result } = renderHook(() => useClipboard());
16
+ await act(async () => {
17
+ await result.current.writeClipboard(writeText);
18
+ });
19
+ expect(writeTextMockFn).toBeCalledWith(writeText);
20
+ expect(navigator.clipboard.writeText).toHaveBeenCalledOnce();
21
+ });
22
+ it("\u30AF\u30EA\u30C3\u30D7\u30DC\u30FC\u30C9\u3092\u8AAD\u307F\u8FBC\u3081\u308B", async () => {
23
+ const readTextMockFn = vi.fn();
24
+ vi.stubGlobal("navigator", {
25
+ clipboard: {
26
+ readText: readTextMockFn
27
+ }
28
+ });
29
+ const { result } = renderHook(() => useClipboard());
30
+ await act(async () => {
31
+ await result.current.readClipboard();
32
+ });
33
+ expect(readTextMockFn).toHaveBeenCalledOnce();
34
+ });
35
+ });
@@ -0,0 +1 @@
1
+ export declare const useHash: () => string | null;
@@ -0,0 +1,28 @@
1
+ import { useSyncExternalStore } from "react";
2
+ const getHash = () => typeof window !== "undefined" ? decodeURIComponent(window.location.hash.replace("#", "")) : null;
3
+ const subscribe = (callback) => {
4
+ const { pushState, replaceState } = window.history;
5
+ window.history.pushState = (...args) => {
6
+ pushState.apply(window.history, args);
7
+ setTimeout(callback);
8
+ };
9
+ window.history.replaceState = (...args) => {
10
+ replaceState.apply(window.history, args);
11
+ setTimeout(callback);
12
+ };
13
+ window.addEventListener("hashchange", callback);
14
+ return () => {
15
+ window.removeEventListener("hashchange", callback);
16
+ };
17
+ };
18
+ const useHash = () => {
19
+ const hash = useSyncExternalStore(
20
+ subscribe,
21
+ () => getHash(),
22
+ () => null
23
+ );
24
+ return hash;
25
+ };
26
+ export {
27
+ useHash
28
+ };
@@ -0,0 +1,46 @@
1
+ import { renderHook, waitFor } from "@testing-library/react";
2
+ import { act } from "react";
3
+ import { useHash } from ".";
4
+ vi.mock("../client", () => ({
5
+ useClient: () => true
6
+ }));
7
+ describe("useHash", () => {
8
+ const realHash = window.location.hash;
9
+ beforeEach(() => {
10
+ window.location.hash = "#test";
11
+ });
12
+ afterEach(() => {
13
+ vi.unstubAllGlobals();
14
+ window.location.hash = realHash;
15
+ });
16
+ it("\u73FE\u5728\u306Ehash\u5024\u3092\u53D6\u5F97\u3067\u304D\u308B", () => {
17
+ const { result } = renderHook(() => useHash());
18
+ expect(result.current).toBe("test");
19
+ });
20
+ it("hash\u5024\u304C\u5909\u66F4\u3055\u308C\u305F\u3068\u304D\u306B\u66F4\u65B0\u3055\u308C\u308B", () => {
21
+ const { result } = renderHook(() => useHash());
22
+ window.location.hash = "#changed";
23
+ act(() => {
24
+ window.dispatchEvent(new Event("hashchange"));
25
+ });
26
+ expect(result.current).toBe("changed");
27
+ });
28
+ it("pushState\u3067hash\u5024\u304C\u5909\u66F4\u3055\u308C\u305F\u3068\u304D\u306B\u66F4\u65B0\u3055\u308C\u308B", async () => {
29
+ const { result } = renderHook(() => useHash());
30
+ act(() => {
31
+ window.history.pushState({}, "", "/#pushed");
32
+ });
33
+ await waitFor(() => {
34
+ expect(result.current).toBe("pushed");
35
+ });
36
+ });
37
+ it("replaceState\u3067hash\u5024\u304C\u5909\u66F4\u3055\u308C\u305F\u3068\u304D\u306B\u66F4\u65B0\u3055\u308C\u308B", async () => {
38
+ const { result } = renderHook(() => useHash());
39
+ act(() => {
40
+ window.history.replaceState({}, "", "/#replaced");
41
+ });
42
+ await waitFor(() => {
43
+ expect(result.current).toBe("replaced");
44
+ });
45
+ });
46
+ });
@@ -0,0 +1,10 @@
1
+ export * from './click-away';
2
+ export * from './client';
3
+ export * from './clipboard';
4
+ export * from './hash';
5
+ export * from './interval';
6
+ export * from './local-storage';
7
+ export * from './scroll-direction';
8
+ export * from './step';
9
+ export * from './timeout';
10
+ export * from './window-size';
@@ -0,0 +1,10 @@
1
+ export * from "./click-away";
2
+ export * from "./client";
3
+ export * from "./clipboard";
4
+ export * from "./hash";
5
+ export * from "./interval";
6
+ export * from "./local-storage";
7
+ export * from "./scroll-direction";
8
+ export * from "./step";
9
+ export * from "./timeout";
10
+ export * from "./window-size";
@@ -0,0 +1 @@
1
+ export declare const useInterval: (callback: () => void, timeout: number) => void;