bsmnt 0.2.9 → 0.2.10

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 (153) hide show
  1. package/README.md +84 -146
  2. package/package.json +2 -2
  3. package/src/templates/next-default/README.md +28 -199
  4. package/src/templates/next-default/app/layout.tsx +2 -3
  5. package/src/templates/next-default/biome.json +1 -14
  6. package/src/templates/next-default/components/layout/theme/index.tsx +2 -5
  7. package/src/templates/next-default/components/layout/wrapper/index.tsx +1 -2
  8. package/src/templates/next-default/components/ui/README.md +2 -3
  9. package/src/templates/next-default/components/ui/image/index.tsx +3 -3
  10. package/src/templates/next-default/lib/README.md +3 -3
  11. package/src/templates/next-default/lib/hooks/use-device-detection.ts +3 -2
  12. package/src/templates/next-default/lib/hooks/use-media-breakpoint.ts +10 -3
  13. package/src/templates/next-default/lib/scripts/dev.ts +9 -29
  14. package/src/templates/next-default/lib/styles/README.md +7 -58
  15. package/src/templates/next-default/lib/styles/fonts.ts +7 -15
  16. package/src/templates/next-default/lib/styles/global.css +198 -0
  17. package/src/templates/next-default/lib/styles/index.css +3 -0
  18. package/src/templates/next-default/lib/styles/tokens.css +179 -0
  19. package/src/templates/next-default/lib/utils/global-css.d.ts +1 -0
  20. package/src/templates/next-default/lib/utils/viewport.ts +11 -5
  21. package/src/templates/next-default/next.config.ts +0 -1
  22. package/src/templates/next-default/package.json +10 -17
  23. package/src/templates/next-default/postcss.config.mjs +0 -14
  24. package/src/templates/next-default/tsconfig.tsbuildinfo +1 -0
  25. package/src/templates/next-experiments/README.md +29 -200
  26. package/src/templates/next-experiments/app/layout.tsx +2 -3
  27. package/src/templates/next-experiments/app/page.tsx +46 -39
  28. package/src/templates/next-experiments/biome.json +1 -14
  29. package/src/templates/next-experiments/components/layout/theme/index.tsx +2 -5
  30. package/src/templates/next-experiments/components/layout/wrapper/index.tsx +1 -2
  31. package/src/templates/next-experiments/components/ui/README.md +2 -3
  32. package/src/templates/next-experiments/components/ui/image/index.tsx +3 -2
  33. package/src/templates/next-experiments/lib/README.md +3 -3
  34. package/src/templates/next-experiments/lib/hooks/use-device-detection.ts +3 -2
  35. package/src/templates/next-experiments/lib/hooks/use-media-breakpoint.ts +10 -3
  36. package/src/templates/next-experiments/lib/scripts/dev.ts +9 -29
  37. package/src/templates/next-experiments/lib/styles/README.md +7 -58
  38. package/src/templates/next-experiments/lib/styles/fonts.ts +7 -15
  39. package/src/templates/next-experiments/lib/styles/global.css +198 -0
  40. package/src/templates/next-experiments/lib/styles/index.css +3 -0
  41. package/src/templates/next-experiments/lib/styles/tokens.css +179 -0
  42. package/src/templates/next-experiments/lib/utils/global-css.d.ts +1 -0
  43. package/src/templates/next-experiments/lib/utils/viewport.ts +11 -5
  44. package/src/templates/next-experiments/next.config.ts +0 -1
  45. package/src/templates/next-experiments/package.json +10 -21
  46. package/src/templates/next-experiments/postcss.config.mjs +0 -14
  47. package/src/templates/next-experiments/tsconfig.tsbuildinfo +1 -0
  48. package/src/templates/next-webgl/README.md +30 -200
  49. package/src/templates/next-webgl/app/layout.tsx +2 -3
  50. package/src/templates/next-webgl/biome.json +1 -14
  51. package/src/templates/next-webgl/components/layout/theme/index.tsx +2 -5
  52. package/src/templates/next-webgl/components/layout/wrapper/index.tsx +1 -2
  53. package/src/templates/next-webgl/components/ui/README.md +2 -3
  54. package/src/templates/next-webgl/components/ui/image/index.tsx +3 -3
  55. package/src/templates/next-webgl/lib/README.md +3 -3
  56. package/src/templates/next-webgl/lib/hooks/use-device-detection.ts +3 -2
  57. package/src/templates/next-webgl/lib/hooks/use-media-breakpoint.ts +10 -3
  58. package/src/templates/next-webgl/lib/scripts/dev.ts +9 -29
  59. package/src/templates/next-webgl/lib/styles/README.md +7 -58
  60. package/src/templates/next-webgl/lib/styles/fonts.ts +7 -15
  61. package/src/templates/next-webgl/lib/styles/global.css +198 -0
  62. package/src/templates/next-webgl/lib/styles/index.css +3 -0
  63. package/src/templates/next-webgl/lib/styles/tokens.css +179 -0
  64. package/src/templates/next-webgl/lib/utils/global-css.d.ts +1 -0
  65. package/src/templates/next-webgl/lib/utils/viewport.ts +11 -5
  66. package/src/templates/next-webgl/next.config.ts +0 -1
  67. package/src/templates/next-webgl/package.json +10 -19
  68. package/src/templates/next-webgl/postcss.config.mjs +0 -14
  69. package/src/templates/next-webgl/tsconfig.tsbuildinfo +1 -0
  70. package/src/templates/next-default/components/ui/image/image.module.css +0 -5
  71. package/src/templates/next-default/lib/scripts/generate-component.ts +0 -322
  72. package/src/templates/next-default/lib/scripts/generate-page.ts +0 -193
  73. package/src/templates/next-default/lib/scripts/generate.ts +0 -79
  74. package/src/templates/next-default/lib/store/app.ts +0 -11
  75. package/src/templates/next-default/lib/store/index.ts +0 -11
  76. package/src/templates/next-default/lib/styles/colors.ts +0 -63
  77. package/src/templates/next-default/lib/styles/config.ts +0 -34
  78. package/src/templates/next-default/lib/styles/css/global.css +0 -85
  79. package/src/templates/next-default/lib/styles/css/index.css +0 -6
  80. package/src/templates/next-default/lib/styles/css/reset.css +0 -166
  81. package/src/templates/next-default/lib/styles/css/root.css +0 -68
  82. package/src/templates/next-default/lib/styles/css/tailwind.css +0 -132
  83. package/src/templates/next-default/lib/styles/easings.ts +0 -21
  84. package/src/templates/next-default/lib/styles/index.ts +0 -12
  85. package/src/templates/next-default/lib/styles/layout.mjs +0 -27
  86. package/src/templates/next-default/lib/styles/scripts/README.md +0 -29
  87. package/src/templates/next-default/lib/styles/scripts/generate-root.ts +0 -57
  88. package/src/templates/next-default/lib/styles/scripts/generate-tailwind.ts +0 -162
  89. package/src/templates/next-default/lib/styles/scripts/postcss-functions.mjs +0 -168
  90. package/src/templates/next-default/lib/styles/scripts/setup-styles.ts +0 -24
  91. package/src/templates/next-default/lib/styles/scripts/utils.ts +0 -20
  92. package/src/templates/next-default/lib/styles/typography.ts +0 -36
  93. package/src/templates/next-default/lib/utils/css.d.ts +0 -21
  94. package/src/templates/next-default/lib/utils/math.test.ts +0 -221
  95. package/src/templates/next-default/lib/utils/strings.test.ts +0 -166
  96. package/src/templates/next-default/lib/utils/viewport.test.ts +0 -256
  97. package/src/templates/next-default/public/fonts/geist/Geist-Mono.woff2 +0 -0
  98. package/src/templates/next-experiments/components/ui/image/image.module.css +0 -5
  99. package/src/templates/next-experiments/lib/scripts/generate-component.ts +0 -322
  100. package/src/templates/next-experiments/lib/scripts/generate-page.ts +0 -193
  101. package/src/templates/next-experiments/lib/scripts/generate.ts +0 -79
  102. package/src/templates/next-experiments/lib/store/app.ts +0 -11
  103. package/src/templates/next-experiments/lib/store/index.ts +0 -11
  104. package/src/templates/next-experiments/lib/styles/colors.ts +0 -63
  105. package/src/templates/next-experiments/lib/styles/config.ts +0 -34
  106. package/src/templates/next-experiments/lib/styles/css/global.css +0 -85
  107. package/src/templates/next-experiments/lib/styles/css/index.css +0 -6
  108. package/src/templates/next-experiments/lib/styles/css/reset.css +0 -166
  109. package/src/templates/next-experiments/lib/styles/css/root.css +0 -68
  110. package/src/templates/next-experiments/lib/styles/css/tailwind.css +0 -132
  111. package/src/templates/next-experiments/lib/styles/easings.ts +0 -21
  112. package/src/templates/next-experiments/lib/styles/index.ts +0 -12
  113. package/src/templates/next-experiments/lib/styles/layout.mjs +0 -27
  114. package/src/templates/next-experiments/lib/styles/scripts/README.md +0 -29
  115. package/src/templates/next-experiments/lib/styles/scripts/generate-root.ts +0 -57
  116. package/src/templates/next-experiments/lib/styles/scripts/generate-tailwind.ts +0 -162
  117. package/src/templates/next-experiments/lib/styles/scripts/postcss-functions.mjs +0 -168
  118. package/src/templates/next-experiments/lib/styles/scripts/setup-styles.ts +0 -24
  119. package/src/templates/next-experiments/lib/styles/scripts/utils.ts +0 -20
  120. package/src/templates/next-experiments/lib/styles/typography.ts +0 -36
  121. package/src/templates/next-experiments/lib/utils/css.d.ts +0 -21
  122. package/src/templates/next-experiments/lib/utils/math.test.ts +0 -221
  123. package/src/templates/next-experiments/lib/utils/strings.test.ts +0 -166
  124. package/src/templates/next-experiments/lib/utils/viewport.test.ts +0 -256
  125. package/src/templates/next-experiments/public/fonts/geist/Geist-Mono.woff2 +0 -0
  126. package/src/templates/next-webgl/components/ui/image/image.module.css +0 -5
  127. package/src/templates/next-webgl/lib/scripts/generate-component.ts +0 -322
  128. package/src/templates/next-webgl/lib/scripts/generate-page.ts +0 -193
  129. package/src/templates/next-webgl/lib/scripts/generate.ts +0 -79
  130. package/src/templates/next-webgl/lib/store/app.ts +0 -11
  131. package/src/templates/next-webgl/lib/store/index.ts +0 -11
  132. package/src/templates/next-webgl/lib/styles/colors.ts +0 -63
  133. package/src/templates/next-webgl/lib/styles/config.ts +0 -34
  134. package/src/templates/next-webgl/lib/styles/css/global.css +0 -85
  135. package/src/templates/next-webgl/lib/styles/css/index.css +0 -6
  136. package/src/templates/next-webgl/lib/styles/css/reset.css +0 -166
  137. package/src/templates/next-webgl/lib/styles/css/root.css +0 -68
  138. package/src/templates/next-webgl/lib/styles/css/tailwind.css +0 -132
  139. package/src/templates/next-webgl/lib/styles/easings.ts +0 -21
  140. package/src/templates/next-webgl/lib/styles/index.ts +0 -12
  141. package/src/templates/next-webgl/lib/styles/layout.mjs +0 -27
  142. package/src/templates/next-webgl/lib/styles/scripts/README.md +0 -29
  143. package/src/templates/next-webgl/lib/styles/scripts/generate-root.ts +0 -57
  144. package/src/templates/next-webgl/lib/styles/scripts/generate-tailwind.ts +0 -162
  145. package/src/templates/next-webgl/lib/styles/scripts/postcss-functions.mjs +0 -168
  146. package/src/templates/next-webgl/lib/styles/scripts/setup-styles.ts +0 -24
  147. package/src/templates/next-webgl/lib/styles/scripts/utils.ts +0 -20
  148. package/src/templates/next-webgl/lib/styles/typography.ts +0 -36
  149. package/src/templates/next-webgl/lib/utils/css.d.ts +0 -21
  150. package/src/templates/next-webgl/lib/utils/math.test.ts +0 -221
  151. package/src/templates/next-webgl/lib/utils/strings.test.ts +0 -166
  152. package/src/templates/next-webgl/lib/utils/viewport.test.ts +0 -256
  153. package/src/templates/next-webgl/public/fonts/geist/Geist-Mono.woff2 +0 -0
@@ -1,166 +0,0 @@
1
- /**
2
- * Unit tests for string utilities
3
- *
4
- * Run with: bun test lib/utils/strings.test.ts
5
- */
6
-
7
- import { describe, expect, it } from "bun:test"
8
- import {
9
- capitalizeFirstLetter,
10
- convertToCamelCase,
11
- isEmptyArray,
12
- isEmptyObject,
13
- numberWithCommas,
14
- slugify,
15
- twoDigits,
16
- } from "./strings"
17
-
18
- describe("slugify", () => {
19
- it("should convert text to URL-friendly format", () => {
20
- expect(slugify("Hello World")).toBe("hello-world")
21
- expect(slugify("Hello World!")).toBe("hello-world")
22
- })
23
-
24
- it("should handle special characters", () => {
25
- expect(slugify("Café & Restaurant")).toBe("cafe-restaurant")
26
- expect(slugify("Rock & Roll")).toBe("rock-roll")
27
- })
28
-
29
- it("should handle multiple spaces and dashes", () => {
30
- expect(slugify("Hello World")).toBe("hello-world")
31
- expect(slugify("Hello--World")).toBe("hello-world")
32
- expect(slugify("Hello - World")).toBe("hello-world")
33
- })
34
-
35
- it("should trim whitespace", () => {
36
- expect(slugify(" Hello World ")).toBe("hello-world")
37
- })
38
-
39
- it("should handle numbers", () => {
40
- expect(slugify("Product 123")).toBe("product-123")
41
- expect(slugify("2024 Review")).toBe("2024-review")
42
- })
43
-
44
- it("should handle objects with toString", () => {
45
- const obj = { toString: () => "Custom Object" }
46
- expect(slugify(obj)).toBe("custom-object")
47
- })
48
- })
49
-
50
- describe("convertToCamelCase", () => {
51
- it("should convert first character to lowercase", () => {
52
- expect(convertToCamelCase("HelloWorld")).toBe("helloWorld")
53
- expect(convertToCamelCase("MyComponent")).toBe("myComponent")
54
- })
55
-
56
- it("should handle already camelCase strings", () => {
57
- expect(convertToCamelCase("helloWorld")).toBe("helloWorld")
58
- })
59
-
60
- it("should handle single characters", () => {
61
- expect(convertToCamelCase("A")).toBe("a")
62
- expect(convertToCamelCase("a")).toBe("a")
63
- })
64
-
65
- it("should handle empty strings", () => {
66
- expect(convertToCamelCase("")).toBe("")
67
- })
68
- })
69
-
70
- describe("capitalizeFirstLetter", () => {
71
- it("should capitalize the first letter", () => {
72
- expect(capitalizeFirstLetter("hello")).toBe("Hello")
73
- expect(capitalizeFirstLetter("world")).toBe("World")
74
- })
75
-
76
- it("should handle already capitalized strings", () => {
77
- expect(capitalizeFirstLetter("Hello")).toBe("Hello")
78
- })
79
-
80
- it("should handle single characters", () => {
81
- expect(capitalizeFirstLetter("a")).toBe("A")
82
- expect(capitalizeFirstLetter("A")).toBe("A")
83
- })
84
-
85
- it("should handle empty strings", () => {
86
- expect(capitalizeFirstLetter("")).toBe("")
87
- })
88
- })
89
-
90
- describe("twoDigits", () => {
91
- it("should pad single digit numbers with zero", () => {
92
- expect(twoDigits(0)).toBe("00")
93
- expect(twoDigits(5)).toBe("05")
94
- expect(twoDigits(9)).toBe("09")
95
- })
96
-
97
- it("should not pad two-digit numbers", () => {
98
- expect(twoDigits(10)).toBe("10")
99
- expect(twoDigits(23)).toBe("23")
100
- expect(twoDigits(99)).toBe("99")
101
- })
102
-
103
- it("should handle numbers greater than 99", () => {
104
- expect(twoDigits(100)).toBe("100")
105
- expect(twoDigits(999)).toBe("999")
106
- })
107
- })
108
-
109
- describe("numberWithCommas", () => {
110
- it("should add commas as thousands separators", () => {
111
- expect(numberWithCommas(1000)).toBe("1,000")
112
- expect(numberWithCommas(1234)).toBe("1,234")
113
- expect(numberWithCommas(1234567)).toBe("1,234,567")
114
- })
115
-
116
- it("should not add commas to numbers less than 1000", () => {
117
- expect(numberWithCommas(999)).toBe("999")
118
- expect(numberWithCommas(1)).toBe("1")
119
- expect(numberWithCommas(0)).toBe("0")
120
- })
121
-
122
- it("should handle objects with toString", () => {
123
- const obj = { toString: () => "1234567" }
124
- expect(numberWithCommas(obj)).toBe("1,234,567")
125
- })
126
- })
127
-
128
- describe("isEmptyObject", () => {
129
- it("should return true for empty objects", () => {
130
- expect(isEmptyObject({})).toBe(true)
131
- })
132
-
133
- it("should return false for non-empty objects", () => {
134
- expect(isEmptyObject({ a: 1 })).toBe(false)
135
- expect(isEmptyObject({ key: "value" })).toBe(false)
136
- })
137
-
138
- it("should return true for null/undefined", () => {
139
- expect(isEmptyObject(null as unknown as Record<string, unknown>)).toBe(true)
140
- expect(isEmptyObject(undefined as unknown as Record<string, unknown>)).toBe(
141
- true
142
- )
143
- })
144
- })
145
-
146
- describe("isEmptyArray", () => {
147
- it("should return true for empty arrays", () => {
148
- expect(isEmptyArray([])).toBe(true)
149
- })
150
-
151
- it("should return false for non-empty arrays", () => {
152
- expect(isEmptyArray([1, 2, 3])).toBe(false)
153
- expect(isEmptyArray(["a"])).toBe(false)
154
- })
155
-
156
- it("should return false for non-arrays (strings)", () => {
157
- // Note: strings are not arrays, so Array.isArray returns false
158
- // The function returns false for non-arrays that have a truthy value
159
- expect(isEmptyArray("test")).toBe(false)
160
- })
161
-
162
- it("should return true for null/undefined", () => {
163
- expect(isEmptyArray(null as unknown as unknown[])).toBe(true)
164
- expect(isEmptyArray(undefined as unknown as unknown[])).toBe(true)
165
- })
166
- })
@@ -1,256 +0,0 @@
1
- /**
2
- * Unit tests for viewport utilities
3
- *
4
- * Run with: bun test lib/utils/viewport.test.ts
5
- */
6
-
7
- import { describe, expect, it } from "bun:test"
8
- import { toem, torem, tovw } from "./viewport"
9
-
10
- // Helper to check vw values with floating point tolerance
11
- function expectVw(actual: string, expectedVw: number) {
12
- const match = actual.match(/^([\d.]+)vw$/)
13
- if (!match?.[1]) {
14
- throw new Error(`Expected vw format, got: ${actual}`)
15
- }
16
- const actualVw = Number.parseFloat(match[1])
17
- expect(actualVw).toBeCloseTo(expectedVw, 4)
18
- }
19
-
20
- // Helper to check max() values with floating point tolerance
21
- function expectMaxVw(actual: string, expectedMin: number, expectedVw: number) {
22
- const match = actual.match(/^max\((\d+)px, ([\d.]+)vw\)$/)
23
- if (!(match?.[1] && match[2])) {
24
- throw new Error(`Expected max() format, got: ${actual}`)
25
- }
26
- const actualMin = Number.parseFloat(match[1])
27
- const actualVw = Number.parseFloat(match[2])
28
- expect(actualMin).toBe(expectedMin)
29
- expect(actualVw).toBeCloseTo(expectedVw, 4)
30
- }
31
-
32
- describe("tovw", () => {
33
- describe("basic conversion (default desktop context)", () => {
34
- it("should convert pixels to vw with default desktop context (1440px)", () => {
35
- expectVw(tovw(100), 6.9444)
36
- expect(tovw(1440)).toBe("100vw")
37
- expect(tovw(720)).toBe("50vw")
38
- })
39
-
40
- it("should handle zero", () => {
41
- expect(tovw(0)).toBe("0")
42
- })
43
- })
44
-
45
- describe("with minimum value", () => {
46
- it("should apply minimum value using max()", () => {
47
- expectMaxVw(tovw(100, 50), 50, 6.9444)
48
- expectMaxVw(tovw(200, 100), 100, 13.8889)
49
- })
50
-
51
- it("should handle zero target with min", () => {
52
- expect(tovw(0, 50)).toBe("0")
53
- })
54
- })
55
-
56
- describe("with context identifier", () => {
57
- it("should use mobile context (375px)", () => {
58
- expectVw(tovw(16, "mobile"), 4.2667)
59
- expect(tovw(375, "mobile")).toBe("100vw")
60
- })
61
-
62
- it("should use desktop-large context (1920px)", () => {
63
- expectVw(tovw(100, "desktop-large"), 5.2083)
64
- expect(tovw(1920, "desktop-large")).toBe("100vw")
65
- })
66
-
67
- it("should use tablet-lg context (1024px)", () => {
68
- expectVw(tovw(100, "tablet-lg"), 9.7656)
69
- expect(tovw(1024, "tablet-lg")).toBe("100vw")
70
- })
71
-
72
- it("should use tablet context (620px)", () => {
73
- expectVw(tovw(100, "tablet"), 16.129)
74
- expect(tovw(620, "tablet")).toBe("100vw")
75
- })
76
-
77
- it("should use desktop context explicitly", () => {
78
- expectVw(tovw(100, "desktop"), 6.9444)
79
- })
80
- })
81
-
82
- describe("with custom numeric context", () => {
83
- it("should use custom pixel context as third parameter", () => {
84
- // Numeric contexts must be passed as third parameter (with undefined min)
85
- // Using type assertion to test the implementation behavior
86
- expectVw(tovw(100, 1920), 5.2083)
87
- expectVw(tovw(100, 800), 12.5)
88
- expectVw(tovw(100, 2000), 5)
89
- })
90
-
91
- it("should treat numeric second parameter as min, not context", () => {
92
- // When second param is a number, it's treated as min, not context
93
- expectMaxVw(tovw(100, 1920), 1920, 6.9444)
94
- })
95
- })
96
-
97
- describe("with both min and context", () => {
98
- it("should apply min and context together", () => {
99
- expectMaxVw(tovw(100, 50, "mobile"), 50, 26.6667)
100
- expectMaxVw(tovw(200, 100, "desktop-large"), 100, 10.4167)
101
- })
102
-
103
- it("should use numeric context with min", () => {
104
- expectMaxVw(tovw(100, 50, 1920), 50, 5.2083)
105
- })
106
- })
107
-
108
- describe("edge cases", () => {
109
- it("should handle very small values", () => {
110
- expectVw(tovw(1), 0.0694)
111
- expectVw(tovw(0.5), 0.0347)
112
- })
113
-
114
- it("should handle very large values", () => {
115
- expectVw(tovw(5000), 347.2222)
116
- })
117
-
118
- it("should handle decimal values", () => {
119
- expectVw(tovw(16.5), 1.1458)
120
- expectVw(tovw(16.5, "mobile"), 4.4)
121
- })
122
- })
123
- })
124
-
125
- describe("torem", () => {
126
- describe("basic conversion (default 16px context)", () => {
127
- it("should convert pixels to rem with default context", () => {
128
- expect(torem(16)).toBe("1rem")
129
- expect(torem(24)).toBe("1.5rem")
130
- expect(torem(32)).toBe("2rem")
131
- expect(torem(8)).toBe("0.5rem")
132
- })
133
-
134
- it("should handle zero", () => {
135
- expect(torem(0)).toBe("0")
136
- })
137
- })
138
-
139
- describe("with custom context", () => {
140
- it("should use custom base font size", () => {
141
- // Using toBeCloseTo for floating point comparison
142
- const result1 = torem(18, 14)
143
- const match1 = result1.match(/^([\d.]+)rem$/)
144
- expect(Number.parseFloat(match1?.[1] || "0")).toBeCloseTo(
145
- 1.2857142857142858,
146
- 4
147
- )
148
-
149
- expect(torem(20, 10)).toBe("2rem")
150
- expect(torem(24, 12)).toBe("2rem")
151
- })
152
-
153
- it("should handle zero with custom context", () => {
154
- expect(torem(0, 14)).toBe("0")
155
- })
156
- })
157
-
158
- describe("edge cases", () => {
159
- it("should handle decimal values", () => {
160
- const result1 = torem(16.5)
161
- const match1 = result1.match(/^([\d.]+)rem$/)
162
- // 16.5 / 16 = 1.03125, rounded to 4 decimals = 1.0313
163
- expect(Number.parseFloat(match1?.[1] || "0")).toBeCloseTo(1.0313, 4)
164
-
165
- const result2 = torem(18.5, 14)
166
- const match2 = result2.match(/^([\d.]+)rem$/)
167
- // 18.5 / 14 = 1.3214285714285714, rounded to 4 decimals = 1.3214
168
- expect(Number.parseFloat(match2?.[1] || "0")).toBeCloseTo(1.3214, 4)
169
- })
170
-
171
- it("should handle very small values", () => {
172
- const result1 = torem(1)
173
- const match1 = result1.match(/^([\d.]+)rem$/)
174
- expect(Number.parseFloat(match1?.[1] || "0")).toBeCloseTo(0.0625, 4)
175
-
176
- const result2 = torem(0.5)
177
- const match2 = result2.match(/^([\d.]+)rem$/)
178
- // 0.5 / 16 = 0.03125, rounded to 4 decimals = 0.0313
179
- expect(Number.parseFloat(match2?.[1] || "0")).toBeCloseTo(0.0313, 4)
180
- })
181
-
182
- it("should handle very large values", () => {
183
- expect(torem(100)).toBe("6.25rem")
184
- expect(torem(200)).toBe("12.5rem")
185
- })
186
- })
187
- })
188
-
189
- describe("toem", () => {
190
- describe("basic conversion", () => {
191
- it("should convert pixels to em", () => {
192
- expect(toem(24, 16)).toBe("1.5em")
193
- expect(toem(16, 16)).toBe("1em")
194
- expect(toem(32, 16)).toBe("2em")
195
- expect(toem(8, 16)).toBe("0.5em")
196
- })
197
-
198
- it("should handle zero", () => {
199
- expect(toem(0, 16)).toBe("0")
200
- })
201
- })
202
-
203
- describe("with different contexts", () => {
204
- it("should use custom context size", () => {
205
- const result1 = toem(18, 14)
206
- const match1 = result1.match(/^([\d.]+)em$/)
207
- expect(Number.parseFloat(match1?.[1] || "0")).toBeCloseTo(
208
- 1.2857142857142858,
209
- 4
210
- )
211
-
212
- expect(toem(20, 10)).toBe("2em")
213
- expect(toem(24, 12)).toBe("2em")
214
- })
215
-
216
- it("should handle zero with different contexts", () => {
217
- expect(toem(0, 14)).toBe("0")
218
- expect(toem(0, 20)).toBe("0")
219
- })
220
- })
221
-
222
- describe("edge cases", () => {
223
- it("should handle decimal values", () => {
224
- const result1 = toem(16.5, 16)
225
- const match1 = result1.match(/^([\d.]+)em$/)
226
- // 16.5 / 16 = 1.03125, rounded to 4 decimals = 1.0313
227
- expect(Number.parseFloat(match1?.[1] || "0")).toBeCloseTo(1.0313, 4)
228
-
229
- const result2 = toem(18.5, 14)
230
- const match2 = result2.match(/^([\d.]+)em$/)
231
- // 18.5 / 14 = 1.3214285714285714, rounded to 4 decimals = 1.3214
232
- expect(Number.parseFloat(match2?.[1] || "0")).toBeCloseTo(1.3214, 4)
233
- })
234
-
235
- it("should handle very small values", () => {
236
- const result1 = toem(1, 16)
237
- const match1 = result1.match(/^([\d.]+)em$/)
238
- expect(Number.parseFloat(match1?.[1] || "0")).toBeCloseTo(0.0625, 4)
239
-
240
- const result2 = toem(0.5, 16)
241
- const match2 = result2.match(/^([\d.]+)em$/)
242
- // 0.5 / 16 = 0.03125, rounded to 4 decimals = 0.0313
243
- expect(Number.parseFloat(match2?.[1] || "0")).toBeCloseTo(0.0313, 4)
244
- })
245
-
246
- it("should handle very large values", () => {
247
- expect(toem(100, 16)).toBe("6.25em")
248
- expect(toem(200, 16)).toBe("12.5em")
249
- })
250
-
251
- it("should handle context larger than target", () => {
252
- expect(toem(8, 16)).toBe("0.5em")
253
- expect(toem(4, 16)).toBe("0.25em")
254
- })
255
- })
256
- })
@@ -1,5 +0,0 @@
1
- .block {
2
- display: block;
3
- width: 100%;
4
- height: auto;
5
- }