Skip to content

Commit

Permalink
Refactorings
Browse files Browse the repository at this point in the history
  • Loading branch information
deminearchiver committed Nov 3, 2024
1 parent 8719701 commit 6cf8ed6
Show file tree
Hide file tree
Showing 23 changed files with 325 additions and 51 deletions.
50 changes: 50 additions & 0 deletions packages/dom/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
{
"name": "@star4/dom",
"version": "0.0.1",
"publishConfig": {
"access": "public"
},
"repository": {
"type": "git",
"url": "https://github.com/tmol4/star4.git",
"directory": "packages/dom"
},
"homepage": "https://tmol4.github.io/star4",
"files": [
"dist/**/*"
],
"type": "module",
"main": "./dist/index.cjs",
"module": "./dist/index.js",
"types": "./dist/index.d.ts",
"browser": {},
"exports": {
".": {
"import": {
"types": "./dist/index.d.ts",
"default": "./dist/index.js"
},
"require": {
"types": "./dist/index.d.cts",
"default": "./dist/index.cjs"
}
}
},
"typesVersions": {},
"packageManager": "[email protected]",
"scripts": {
"build": "tsup",
"dev": "tsup --watch",
"publish": "yarn npm publish"
},
"devDependencies": {
"@star4/config": "workspace:^",
"@types/node": "^22.8.6",
"tsup": "^8.3.5",
"typescript": "^5.6.3"
},
"dependencies": {
"@floating-ui/dom": "^1.6.12",
"clsx": "^2.1.1"
}
}
Empty file added packages/dom/src/index.ts
Empty file.
8 changes: 8 additions & 0 deletions packages/dom/tsconfig.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
{
"extends": [
"@star4/config/tsconfig/module",
"@star4/config/tsconfig/web",
"@star4/config/tsconfig/strict",
],
"include": ["src", "tsup.config.ts"],
}
18 changes: 18 additions & 0 deletions packages/dom/tsup.config.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
import { defineConfig, type Options } from "tsup";

export default defineConfig(config => {
const watching = !!config.watch;
return {
target: "esnext",
platform: "browser",
format: watching ? "esm" : ["esm", "cjs"],
clean: !watching, // && i === 0 (for the first config)
dts: true,
entry: ["src/index.ts"],
outDir: "dist",
treeshake: watching ? false : { preset: "safest" },
bundle: true,
minify: !watching,
replaceNodeEnv: true,
};
});
8 changes: 8 additions & 0 deletions packages/react-utils/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
# @star4/react-utils

## 0.0.2

### Patch Changes

- Updated dependencies
- @star4/vanilla-extract@0.0.9
55 changes: 55 additions & 0 deletions packages/react-utils/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
{
"name": "@star4/react-utils",
"version": "0.0.2",
"publishConfig": {
"access": "public"
},
"repository": {
"type": "git",
"url": "https://github.com/tmol4/star4.git",
"directory": "packages/react-utils"
},
"homepage": "https://tmol4.github.io/star4",
"files": [
"dist/**/*"
],
"type": "module",
"main": "./dist/index.cjs",
"module": "./dist/index.js",
"types": "./dist/index.d.ts",
"browser": {},
"exports": {
".": {
"import": {
"types": "./dist/index.d.ts",
"default": "./dist/index.js"
},
"require": {
"types": "./dist/index.d.cts",
"default": "./dist/index.cjs"
}
}
},
"typesVersions": {},
"packageManager": "[email protected]",
"scripts": {
"build": "tsup",
"dev": "tsup --watch",
"publish": "yarn npm publish"
},
"devDependencies": {
"@star4/config": "workspace:^",
"@types/node": "^22.8.6",
"@types/react": "^18.3.12",
"@types/react-dom": "^18.3.1",
"tsup": "^8.3.5",
"typescript": "^5.6.3"
},
"dependencies": {
"@floating-ui/dom": "^1.6.12",
"@star4/vanilla-extract": "workspace:^",
"clsx": "^2.1.1",
"react": "^18.3.1",
"react-dom": "^18.3.1"
}
}
3 changes: 3 additions & 0 deletions packages/react-utils/src/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
export * from "./is-server";
export * from "./use-isomorphic-layout-effect";
export * from "./use-media-query";
1 change: 1 addition & 0 deletions packages/react-utils/src/is-server.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export const IS_SERVER = typeof window === "undefined";
5 changes: 5 additions & 0 deletions packages/react-utils/src/use-isomorphic-layout-effect.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
import { useEffect, useLayoutEffect } from "react";
import { IS_SERVER } from "./is-server";

export const useIsomorphicLayoutEffect =
IS_SERVER ? useEffect : useLayoutEffect;
61 changes: 61 additions & 0 deletions packages/react-utils/src/use-media-query.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
import { useEffect, useState } from "react";
import { IS_SERVER } from "./is-server";

export const useMediaQuery = (query: string, serverFallback = false): boolean => {
if (IS_SERVER) {
return serverFallback;
}

const initialValue = window.matchMedia(query).matches;
const [matches, setMatches] = useState(initialValue);

useEffect(
() => {
const media = window.matchMedia(query);
const update = () => setMatches(media.matches);
media.addEventListener("change", update);
return media.removeEventListener.bind(media, "change", update)
},
[query],
);

return matches;
}

type MediaFeatures = {
"any-hover": "none" | "hover";
"any-pointer": "none" | "coarse" | "fine";
"aspect-ratio": "";
"color": "";
"color-gamut": "";
"color-index": "";
"device-aspect-ratio Deprecated": "";
"device-height Deprecated": "";
"device-width Deprecated": "";
"display-mode": "";
"dynamic-range": "";
"forced-colors": "none" | "active";
"grid": "";
"height": "";
"hover": "none" | "hover";
"inverted-colors": "none" | "inverted";
"monochrome": "";
"orientation": "portrait" | "landscape";
"overflow-block": "";
"overflow-inline": "";
"pointer": "";
"prefers-color-scheme": "";
"prefers-contrast": "";
"prefers-reduced-motion": "";
"prefers-reduced-transparency": "";
"resolution": "";
"scripting": "";
"update": "";
"video-dynamic-range": "";
"width": "";
}


// export const usePrefersDark = (serverFallback?: boolean) => {
// return useMediaQuery("(prefers-color-scheme: dark)", serverFallback);
// }
11 changes: 11 additions & 0 deletions packages/react-utils/tsconfig.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
{
"extends": [
"@star4/config/tsconfig/module",
"@star4/config/tsconfig/web",
"@star4/config/tsconfig/strict",
],
"compilerOptions": {
"jsx": "react-jsx",
},
"include": ["src", "tsup.config.ts"],
}
18 changes: 18 additions & 0 deletions packages/react-utils/tsup.config.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
import { defineConfig, type Options } from "tsup";

export default defineConfig(config => {
const watching = !!config.watch;
return {
target: "esnext",
platform: "browser",
format: watching ? "esm" : ["esm", "cjs"],
clean: !watching, // && i === 0 (for the first config)
dts: true,
entry: ["src/index.ts"],
outDir: "dist",
treeshake: watching ? false : { preset: "safest" },
bundle: true,
minify: !watching,
replaceNodeEnv: true,
};
});
10 changes: 10 additions & 0 deletions packages/react/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,15 @@
# @star4/react

## 0.0.12

### Patch Changes

- Add "files" field to exclude src from publishing
- Add @star4/react-utils dependency
- Updated dependencies
- @star4/vanilla-extract@0.0.9
- @star4/react-utils@0.0.2

## 0.0.11

### Patch Changes
Expand Down
7 changes: 6 additions & 1 deletion packages/react/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@star4/react",
"version": "0.0.11",
"version": "0.0.12",
"publishConfig": {
"access": "public"
},
Expand All @@ -9,6 +9,10 @@
"url": "https://github.com/tmol4/star4.git",
"directory": "packages/react"
},
"homepage": "https://tmol4.github.io/star4",
"files": [
"dist/**/*"
],
"type": "module",
"main": "./dist/index.cjs",
"module": "./dist/index.js",
Expand Down Expand Up @@ -43,6 +47,7 @@
},
"dependencies": {
"@floating-ui/dom": "^1.6.12",
"@star4/react-utils": "workspace:^",
"@star4/vanilla-extract": "workspace:^",
"@vanilla-extract/css": "^1.16.0",
"@vanilla-extract/dynamic": "^2.1.2",
Expand Down
8 changes: 8 additions & 0 deletions packages/solid/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,13 @@
# @star4/solid

## 0.0.10

### Patch Changes

- Add "files" field to exclude src from publishing
- Updated dependencies
- @star4/vanilla-extract@0.0.9

## 0.0.9

### Patch Changes
Expand Down
8 changes: 5 additions & 3 deletions packages/solid/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@star4/solid",
"version": "0.0.9",
"version": "0.0.10",
"publishConfig": {
"access": "public"
},
Expand All @@ -9,6 +9,10 @@
"url": "https://github.com/tmol4/star4.git",
"directory": "packages/solid"
},
"homepage": "https://tmol4.github.io/star4",
"files": [
"dist/**/*"
],
"type": "module",
"main": "./dist/index.cjs",
"module": "./dist/index.js",
Expand Down Expand Up @@ -38,7 +42,6 @@
"@types/node": "^22.8.6",
"esbuild-plugin-solid": "^0.6.0",
"tsup": "^8.3.5",
"tsup-preset-solid": "^2.2.0",
"typescript": "^5.6.3"
},
"dependencies": {
Expand All @@ -61,7 +64,6 @@
"@star4/vanilla-extract": "workspace:^",
"@vanilla-extract/css": "^1.16.0",
"@vanilla-extract/dynamic": "^2.1.2",
"@vanilla-extract/esbuild-plugin": "^2.3.11",
"@vanilla-extract/recipes": "^0.5.5",
"clsx": "^2.1.1",
"lenis": "^1.1.14",
Expand Down
2 changes: 1 addition & 1 deletion packages/solid/tsup.config.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { defineConfig, type Options } from "tsup";
import { solidPlugin as solid } from "esbuild-plugin-solid";
import { vanillaExtractPlugin as vanillaExtract } from "@vanilla-extract/esbuild-plugin";
// import { vanillaExtractPlugin as vanillaExtract } from "@vanilla-extract/esbuild-plugin";
// import { generatePackageExports, generateTsupOptions, parsePresetOptions, writePackageJson, type PresetOptions } from "tsup-preset-solid";

// const PRESET_OPTIONS: PresetOptions = {
Expand Down
6 changes: 6 additions & 0 deletions packages/theme/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,11 @@
# @star4/theme

## 0.0.9

### Patch Changes

- Add "files" field to exclude src from publishing

## 0.0.8

### Patch Changes
Expand Down
6 changes: 5 additions & 1 deletion packages/theme/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@star4/theme",
"version": "0.0.8",
"version": "0.0.9",
"publishConfig": {
"access": "public"
},
Expand All @@ -9,6 +9,10 @@
"url": "https://github.com/tmol4/star4.git",
"directory": "packages/theme"
},
"homepage": "https://tmol4.github.io/star4",
"files": [
"dist/**/*"
],
"type": "module",
"main": "./dist/index.cjs",
"module": "./dist/index.js",
Expand Down
8 changes: 8 additions & 0 deletions packages/vanilla-extract/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,13 @@
# @star4/vanilla-extract

## 0.0.9

### Patch Changes

- Add "files" field to exclude src from publishing
- Updated dependencies
- @star4/theme@0.0.9

## 0.0.8

### Patch Changes
Expand Down
Loading

0 comments on commit 6cf8ed6

Please sign in to comment.