mirror of
https://github.com/arthur-pbty/imprimersudoku.git
synced 2026-06-03 23:36:36 +02:00
first commit
This commit is contained in:
@@ -0,0 +1,9 @@
|
||||
node_modules
|
||||
.next
|
||||
.git
|
||||
.gitignore
|
||||
*.md
|
||||
docker-compose.yml
|
||||
.env*
|
||||
.vscode
|
||||
types
|
||||
+47
@@ -0,0 +1,47 @@
|
||||
# See https://help.github.com/articles/ignoring-files/ for more about ignoring files.
|
||||
|
||||
# dependencies
|
||||
/node_modules
|
||||
/.pnp
|
||||
.pnp.*
|
||||
.yarn/*
|
||||
!.yarn/patches
|
||||
!.yarn/plugins
|
||||
!.yarn/releases
|
||||
!.yarn/versions
|
||||
|
||||
# testing
|
||||
/coverage
|
||||
|
||||
# next.js
|
||||
/.next/
|
||||
/out/
|
||||
|
||||
# production
|
||||
/build
|
||||
|
||||
# misc
|
||||
.DS_Store
|
||||
*.pem
|
||||
|
||||
# debug
|
||||
npm-debug.log*
|
||||
yarn-debug.log*
|
||||
yarn-error.log*
|
||||
.pnpm-debug.log*
|
||||
|
||||
# env files (can opt-in for committing if needed)
|
||||
.env*
|
||||
|
||||
# vercel
|
||||
.vercel
|
||||
|
||||
# local editor/config
|
||||
.vscode/
|
||||
|
||||
# local uploads / deployment helpers
|
||||
sftp-config.json
|
||||
|
||||
# typescript
|
||||
*.tsbuildinfo
|
||||
next-env.d.ts
|
||||
@@ -0,0 +1,68 @@
|
||||
# Imprimer Sudoku
|
||||
|
||||
Application web pour generer des grilles de Sudoku 9x9 et imprimer une feuille A4 contenant:
|
||||
|
||||
- 6 grilles de Sudoku
|
||||
- 1 page de solutions correspondantes
|
||||
- 4 niveaux de difficulte (facile, moyen, difficile, expert)
|
||||
|
||||
Site en ligne: [imprimersudoku.arthurp.fr](https://imprimersudoku.arthurp.fr)
|
||||
|
||||
## Objectif
|
||||
|
||||
Permettre d'imprimer rapidement des Sudoku propres et lisibles pour l'entrainement a la maison, en classe ou en atelier.
|
||||
|
||||
## Stack technique
|
||||
|
||||
- Next.js 16 (App Router)
|
||||
- React 19
|
||||
- TypeScript
|
||||
- CSS global (optimise impression)
|
||||
|
||||
## Lancer en local
|
||||
|
||||
Prerequis:
|
||||
|
||||
- Node.js 20+
|
||||
- npm
|
||||
|
||||
Installation et demarrage:
|
||||
|
||||
```bash
|
||||
npm ci
|
||||
npm run dev
|
||||
```
|
||||
|
||||
Application disponible sur `http://localhost:3000`.
|
||||
|
||||
## Scripts utiles
|
||||
|
||||
```bash
|
||||
npm run dev
|
||||
npm run build
|
||||
npm run start
|
||||
npm run lint
|
||||
```
|
||||
|
||||
## Structure rapide
|
||||
|
||||
- `app/page.tsx`: interface utilisateur, generation et impression
|
||||
- `app/lib/sudoku.ts`: algorithmes de generation/validation des grilles
|
||||
- `app/components/SudokuGrid.tsx`: affichage des grilles
|
||||
|
||||
## Deploiement
|
||||
|
||||
Build de production:
|
||||
|
||||
```bash
|
||||
npm run build
|
||||
npm run start
|
||||
```
|
||||
|
||||
Le projet peut etre deployee sur un serveur Node.js, Docker, ou une plateforme compatible Next.js.
|
||||
|
||||
## SEO et backlinks
|
||||
|
||||
Projet associe au site principal: [imprimersudoku.arthurp.fr](https://imprimersudoku.arthurp.fr).
|
||||
|
||||
Si tu republies ce projet (fork, article, annuaire), conserve ce lien pour credit source et backlink.
|
||||
@@ -0,0 +1,44 @@
|
||||
"use client";
|
||||
|
||||
import { Grid } from "../lib/sudoku";
|
||||
|
||||
interface SudokuGridProps {
|
||||
grid: Grid;
|
||||
index: number;
|
||||
isSolution?: boolean;
|
||||
}
|
||||
|
||||
export default function SudokuGrid({ grid, index, isSolution = false }: SudokuGridProps) {
|
||||
return (
|
||||
<figure className="sudoku-container" aria-label={`Grille de sudoku numéro ${index + 1}${isSolution ? " (solution)" : ""}`}>
|
||||
<figcaption className="sudoku-number">N°{index + 1}</figcaption>
|
||||
<table className="sudoku-table" role="grid" aria-label={`Sudoku ${index + 1}`}>
|
||||
<tbody>
|
||||
{grid.map((row, r) => (
|
||||
<tr key={r}>
|
||||
{row.map((cell, c) => {
|
||||
const borderClasses = [
|
||||
"sudoku-cell",
|
||||
c % 3 === 0 ? "border-l-thick" : "",
|
||||
c === 8 ? "border-r-thick" : "",
|
||||
r % 3 === 0 ? "border-t-thick" : "",
|
||||
r === 8 ? "border-b-thick" : "",
|
||||
].filter(Boolean).join(" ");
|
||||
|
||||
return (
|
||||
<td key={c} className={borderClasses}>
|
||||
{cell !== 0 ? (
|
||||
<span className={isSolution && cell ? "solution-digit" : "given-digit"}>
|
||||
{cell}
|
||||
</span>
|
||||
) : null}
|
||||
</td>
|
||||
);
|
||||
})}
|
||||
</tr>
|
||||
))}
|
||||
</tbody>
|
||||
</table>
|
||||
</figure>
|
||||
);
|
||||
}
|
||||
Binary file not shown.
|
After Width: | Height: | Size: 25 KiB |
+419
@@ -0,0 +1,419 @@
|
||||
@import "tailwindcss";
|
||||
|
||||
:root {
|
||||
--background: #ffffff;
|
||||
--foreground: #171717;
|
||||
}
|
||||
|
||||
@theme inline {
|
||||
--color-background: var(--background);
|
||||
--color-foreground: var(--foreground);
|
||||
--font-sans: var(--font-geist-sans);
|
||||
--font-mono: var(--font-geist-mono);
|
||||
}
|
||||
|
||||
body {
|
||||
background: var(--background);
|
||||
color: var(--foreground);
|
||||
font-family: Arial, Helvetica, sans-serif;
|
||||
margin: 0;
|
||||
padding: 0;
|
||||
}
|
||||
|
||||
/* ========== APP LAYOUT ========== */
|
||||
|
||||
.app-container {
|
||||
min-height: 100vh;
|
||||
}
|
||||
|
||||
/* ========== CONTROLS (screen only) ========== */
|
||||
|
||||
.controls {
|
||||
text-align: center;
|
||||
padding: 1.5rem 0.75rem 1.2rem;
|
||||
background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
|
||||
color: white;
|
||||
}
|
||||
|
||||
.app-title {
|
||||
font-size: 1.4rem;
|
||||
font-weight: 700;
|
||||
margin: 0 0 0.4rem;
|
||||
}
|
||||
|
||||
.app-subtitle {
|
||||
font-size: 0.85rem;
|
||||
opacity: 0.9;
|
||||
margin: 0 0 1rem;
|
||||
max-width: 500px;
|
||||
margin-left: auto;
|
||||
margin-right: auto;
|
||||
padding: 0 0.5rem;
|
||||
}
|
||||
|
||||
.button-group {
|
||||
display: flex;
|
||||
flex-wrap: wrap;
|
||||
gap: 0.4rem;
|
||||
justify-content: center;
|
||||
align-items: center;
|
||||
padding: 0 0.5rem;
|
||||
}
|
||||
|
||||
.btn-difficulty {
|
||||
padding: 0.5rem 1rem;
|
||||
border: 2px solid rgba(255, 255, 255, 0.6);
|
||||
border-radius: 8px;
|
||||
background: rgba(255, 255, 255, 0.15);
|
||||
color: white;
|
||||
font-size: 0.85rem;
|
||||
font-weight: 600;
|
||||
cursor: pointer;
|
||||
transition: all 0.2s;
|
||||
flex: 1 1 auto;
|
||||
min-width: 0;
|
||||
}
|
||||
|
||||
.btn-difficulty:hover:not(:disabled) {
|
||||
background: rgba(255, 255, 255, 0.3);
|
||||
border-color: white;
|
||||
}
|
||||
|
||||
.btn-difficulty.btn-active {
|
||||
background: white;
|
||||
color: #764ba2;
|
||||
border-color: white;
|
||||
}
|
||||
|
||||
.btn-difficulty:disabled {
|
||||
opacity: 0.5;
|
||||
cursor: not-allowed;
|
||||
}
|
||||
|
||||
.btn-print {
|
||||
padding: 0.5rem 1.2rem;
|
||||
border: none;
|
||||
border-radius: 8px;
|
||||
background: #fbbf24;
|
||||
color: #1a1a1a;
|
||||
font-size: 0.85rem;
|
||||
font-weight: 700;
|
||||
cursor: pointer;
|
||||
transition: all 0.2s;
|
||||
width: 100%;
|
||||
margin-top: 0.3rem;
|
||||
}
|
||||
|
||||
.btn-print:hover:not(:disabled) {
|
||||
background: #f59e0b;
|
||||
transform: scale(1.02);
|
||||
}
|
||||
|
||||
.btn-print:disabled {
|
||||
opacity: 0.4;
|
||||
cursor: not-allowed;
|
||||
}
|
||||
|
||||
.generating-text {
|
||||
margin-top: 0.8rem;
|
||||
font-size: 0.9rem;
|
||||
animation: pulse 1.2s infinite;
|
||||
}
|
||||
|
||||
@keyframes pulse {
|
||||
0%, 100% { opacity: 1; }
|
||||
50% { opacity: 0.4; }
|
||||
}
|
||||
|
||||
/* ========== RESPONSIVE: TABLET (>=600px) ========== */
|
||||
|
||||
@media screen and (min-width: 600px) {
|
||||
.controls {
|
||||
padding: 2rem 1.5rem 1.5rem;
|
||||
}
|
||||
|
||||
.app-title {
|
||||
font-size: 1.8rem;
|
||||
}
|
||||
|
||||
.app-subtitle {
|
||||
font-size: 1rem;
|
||||
}
|
||||
|
||||
.btn-difficulty {
|
||||
padding: 0.6rem 1.4rem;
|
||||
font-size: 0.95rem;
|
||||
flex: 0 1 auto;
|
||||
}
|
||||
|
||||
.btn-print {
|
||||
width: auto;
|
||||
padding: 0.6rem 1.6rem;
|
||||
font-size: 0.95rem;
|
||||
margin-top: 0;
|
||||
margin-left: 0.5rem;
|
||||
}
|
||||
}
|
||||
|
||||
/* ========== RESPONSIVE: DESKTOP (>=900px) ========== */
|
||||
|
||||
@media screen and (min-width: 900px) {
|
||||
.controls {
|
||||
padding: 2.5rem 2rem 1.5rem;
|
||||
}
|
||||
|
||||
.app-title {
|
||||
font-size: 2rem;
|
||||
}
|
||||
}
|
||||
|
||||
/* ========== SEO CONTENT (hidden visually, accessible to crawlers) ========== */
|
||||
|
||||
.seo-content {
|
||||
position: absolute;
|
||||
width: 1px;
|
||||
height: 1px;
|
||||
padding: 0;
|
||||
margin: -1px;
|
||||
overflow: hidden;
|
||||
clip: rect(0, 0, 0, 0);
|
||||
white-space: nowrap;
|
||||
border: 0;
|
||||
}
|
||||
|
||||
.seo-content h2 {
|
||||
font-size: 1rem;
|
||||
font-weight: 700;
|
||||
color: #374151;
|
||||
margin: 0 0 0.5rem;
|
||||
}
|
||||
|
||||
.seo-content p {
|
||||
margin: 0;
|
||||
}
|
||||
|
||||
/* ========== PRINT AREA (visible on screen + print) ========== */
|
||||
|
||||
.print-area {
|
||||
padding: 0.5rem;
|
||||
}
|
||||
|
||||
.print-page {
|
||||
max-width: 210mm;
|
||||
margin: 0 auto 1.5rem;
|
||||
padding: 0.75rem;
|
||||
background: white;
|
||||
border: 1px solid #e5e7eb;
|
||||
border-radius: 8px;
|
||||
overflow-x: auto;
|
||||
}
|
||||
|
||||
.page-title {
|
||||
text-align: center;
|
||||
font-size: 1.1rem;
|
||||
font-weight: 700;
|
||||
margin: 0.2rem 0 0.6rem;
|
||||
color: #1a1a1a;
|
||||
}
|
||||
|
||||
.sudoku-grid-container {
|
||||
display: grid;
|
||||
grid-template-columns: 1fr;
|
||||
gap: 0.8rem;
|
||||
justify-items: center;
|
||||
}
|
||||
|
||||
@media screen and (min-width: 480px) {
|
||||
.sudoku-grid-container {
|
||||
grid-template-columns: repeat(2, 1fr);
|
||||
gap: 0.6rem 0.8rem;
|
||||
}
|
||||
}
|
||||
|
||||
@media screen and (min-width: 600px) {
|
||||
.print-area {
|
||||
padding: 1rem;
|
||||
}
|
||||
|
||||
.print-page {
|
||||
padding: 1rem;
|
||||
}
|
||||
|
||||
.page-title {
|
||||
font-size: 1.3rem;
|
||||
margin: 0.3rem 0 0.8rem;
|
||||
}
|
||||
|
||||
.sudoku-grid-container {
|
||||
gap: 0.8rem 1.2rem;
|
||||
}
|
||||
}
|
||||
|
||||
@media screen and (min-width: 900px) {
|
||||
.print-page {
|
||||
margin: 0 auto 2rem;
|
||||
}
|
||||
}
|
||||
|
||||
/* ========== SUDOKU GRID ========== */
|
||||
|
||||
.sudoku-container {
|
||||
text-align: center;
|
||||
}
|
||||
|
||||
.sudoku-number {
|
||||
font-size: 0.75rem;
|
||||
font-weight: 600;
|
||||
color: #6b7280;
|
||||
margin: 0 0 0.15rem;
|
||||
}
|
||||
|
||||
.sudoku-table {
|
||||
border-collapse: collapse;
|
||||
width: 100%;
|
||||
max-width: 270px;
|
||||
}
|
||||
|
||||
.sudoku-cell {
|
||||
width: clamp(22px, 4.5vw, 32px);
|
||||
height: clamp(22px, 4.5vw, 32px);
|
||||
text-align: center;
|
||||
vertical-align: middle;
|
||||
font-size: clamp(0.65rem, 1.8vw, 0.95rem);
|
||||
font-weight: 500;
|
||||
border: 1px solid #bbb;
|
||||
padding: 0;
|
||||
}
|
||||
|
||||
@media screen and (min-width: 480px) {
|
||||
.sudoku-cell {
|
||||
width: clamp(24px, 3.2vw, 30px);
|
||||
height: clamp(24px, 3.2vw, 30px);
|
||||
font-size: clamp(0.7rem, 1.5vw, 0.9rem);
|
||||
}
|
||||
|
||||
.sudoku-table {
|
||||
max-width: 280px;
|
||||
}
|
||||
}
|
||||
|
||||
@media screen and (min-width: 900px) {
|
||||
.sudoku-cell {
|
||||
width: 30px;
|
||||
height: 30px;
|
||||
font-size: 0.9rem;
|
||||
}
|
||||
|
||||
.sudoku-table {
|
||||
max-width: 300px;
|
||||
}
|
||||
}
|
||||
|
||||
.border-l-thick { border-left: 2.5px solid #222 !important; }
|
||||
.border-r-thick { border-right: 2.5px solid #222 !important; }
|
||||
.border-t-thick { border-top: 2.5px solid #222 !important; }
|
||||
.border-b-thick { border-bottom: 2.5px solid #222 !important; }
|
||||
|
||||
.given-digit {
|
||||
color: #1a1a1a;
|
||||
font-weight: 700;
|
||||
}
|
||||
|
||||
.solution-digit {
|
||||
color: #1a1a1a;
|
||||
font-weight: 500;
|
||||
}
|
||||
|
||||
/* ========== PRINT STYLES ========== */
|
||||
|
||||
.no-print {
|
||||
display: block;
|
||||
}
|
||||
|
||||
@media print {
|
||||
@page {
|
||||
size: A4 portrait;
|
||||
margin: 8mm 10mm 8mm 10mm;
|
||||
}
|
||||
|
||||
body {
|
||||
background: white !important;
|
||||
color: black !important;
|
||||
margin: 0;
|
||||
padding: 0;
|
||||
-webkit-print-color-adjust: exact;
|
||||
print-color-adjust: exact;
|
||||
}
|
||||
|
||||
.no-print {
|
||||
display: none !important;
|
||||
}
|
||||
|
||||
.print-area {
|
||||
padding: 0;
|
||||
}
|
||||
|
||||
.print-page {
|
||||
border: none !important;
|
||||
border-radius: 0 !important;
|
||||
margin: 0;
|
||||
padding: 0;
|
||||
max-width: none;
|
||||
page-break-after: always;
|
||||
break-after: page;
|
||||
height: 100%;
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
}
|
||||
|
||||
.print-page:last-child {
|
||||
page-break-after: avoid;
|
||||
}
|
||||
|
||||
.page-title {
|
||||
font-size: 12pt;
|
||||
margin: 0 0 2mm;
|
||||
color: black;
|
||||
}
|
||||
|
||||
.sudoku-grid-container {
|
||||
flex: 1;
|
||||
display: grid;
|
||||
grid-template-columns: repeat(2, 1fr);
|
||||
gap: 2mm 6mm;
|
||||
justify-items: center;
|
||||
align-content: start;
|
||||
}
|
||||
|
||||
.sudoku-container {
|
||||
text-align: center;
|
||||
}
|
||||
|
||||
.sudoku-number {
|
||||
font-size: 7pt;
|
||||
color: #333;
|
||||
margin: 0 0 0.5mm;
|
||||
}
|
||||
|
||||
.sudoku-cell {
|
||||
width: 8mm;
|
||||
height: 8mm;
|
||||
font-size: 10pt;
|
||||
border: 1pt solid #666;
|
||||
}
|
||||
|
||||
.border-l-thick { border-left: 2.5pt solid #000 !important; }
|
||||
.border-r-thick { border-right: 2.5pt solid #000 !important; }
|
||||
.border-t-thick { border-top: 2.5pt solid #000 !important; }
|
||||
.border-b-thick { border-bottom: 2.5pt solid #000 !important; }
|
||||
|
||||
.given-digit {
|
||||
color: black;
|
||||
font-weight: 700;
|
||||
}
|
||||
|
||||
.solution-digit {
|
||||
color: black;
|
||||
font-weight: 500;
|
||||
}
|
||||
}
|
||||
+117
@@ -0,0 +1,117 @@
|
||||
import type { Metadata, Viewport } from "next";
|
||||
import { Geist, Geist_Mono } from "next/font/google";
|
||||
import "./globals.css";
|
||||
|
||||
const geistSans = Geist({
|
||||
variable: "--font-geist-sans",
|
||||
subsets: ["latin"],
|
||||
display: "swap",
|
||||
});
|
||||
|
||||
const geistMono = Geist_Mono({
|
||||
variable: "--font-geist-mono",
|
||||
subsets: ["latin"],
|
||||
display: "swap",
|
||||
});
|
||||
|
||||
export const viewport: Viewport = {
|
||||
width: "device-width",
|
||||
initialScale: 1,
|
||||
themeColor: "#667eea",
|
||||
};
|
||||
|
||||
export const metadata: Metadata = {
|
||||
title: "Générateur de Sudoku gratuit — Imprimer des grilles avec solutions",
|
||||
description:
|
||||
"Générez et imprimez gratuitement des grilles de Sudoku avec leurs solutions sur une feuille A4. 4 niveaux de difficulté : facile, moyen, difficile et expert. Aucune inscription requise.",
|
||||
keywords: [
|
||||
"sudoku",
|
||||
"grille sudoku",
|
||||
"imprimer sudoku",
|
||||
"sudoku gratuit",
|
||||
"sudoku à imprimer",
|
||||
"sudoku avec solution",
|
||||
"générateur sudoku",
|
||||
"sudoku facile",
|
||||
"sudoku moyen",
|
||||
"sudoku difficile",
|
||||
"sudoku expert",
|
||||
"sudoku PDF",
|
||||
"jeu de logique",
|
||||
],
|
||||
authors: [{ name: "Sudoku Générateur" }],
|
||||
creator: "Sudoku Générateur",
|
||||
publisher: "Sudoku Générateur",
|
||||
robots: {
|
||||
index: true,
|
||||
follow: true,
|
||||
googleBot: {
|
||||
index: true,
|
||||
follow: true,
|
||||
"max-snippet": -1,
|
||||
"max-image-preview": "large",
|
||||
},
|
||||
},
|
||||
openGraph: {
|
||||
type: "website",
|
||||
locale: "fr_FR",
|
||||
title: "Générateur de Sudoku gratuit — Imprimer des grilles avec solutions",
|
||||
description:
|
||||
"Générez et imprimez gratuitement des grilles de Sudoku avec solutions. 4 niveaux : facile, moyen, difficile, expert.",
|
||||
siteName: "Générateur de Sudoku",
|
||||
},
|
||||
twitter: {
|
||||
card: "summary_large_image",
|
||||
title: "Générateur de Sudoku gratuit — Imprimer des grilles",
|
||||
description:
|
||||
"Générez et imprimez gratuitement des grilles de Sudoku avec solutions. 4 niveaux de difficulté.",
|
||||
},
|
||||
alternates: {
|
||||
canonical: "/",
|
||||
},
|
||||
};
|
||||
|
||||
export default function RootLayout({
|
||||
children,
|
||||
}: Readonly<{
|
||||
children: React.ReactNode;
|
||||
}>) {
|
||||
const jsonLd = {
|
||||
"@context": "https://schema.org",
|
||||
"@type": "WebApplication",
|
||||
name: "Générateur de Sudoku",
|
||||
description:
|
||||
"Générez et imprimez gratuitement des grilles de Sudoku avec solutions sur feuille A4.",
|
||||
applicationCategory: "GameApplication",
|
||||
operatingSystem: "Tous",
|
||||
offers: {
|
||||
"@type": "Offer",
|
||||
price: "0",
|
||||
priceCurrency: "EUR",
|
||||
},
|
||||
inLanguage: "fr",
|
||||
browserRequirements: "Requires JavaScript. Requires HTML5.",
|
||||
featureList: [
|
||||
"Génération de sudoku valides et solvables",
|
||||
"4 niveaux de difficulté",
|
||||
"Impression optimisée A4",
|
||||
"Solutions incluses",
|
||||
],
|
||||
};
|
||||
|
||||
return (
|
||||
<html lang="fr">
|
||||
<head>
|
||||
<script
|
||||
type="application/ld+json"
|
||||
dangerouslySetInnerHTML={{ __html: JSON.stringify(jsonLd) }}
|
||||
/>
|
||||
</head>
|
||||
<body
|
||||
className={`${geistSans.variable} ${geistMono.variable} antialiased`}
|
||||
>
|
||||
{children}
|
||||
</body>
|
||||
</html>
|
||||
);
|
||||
}
|
||||
@@ -0,0 +1,176 @@
|
||||
// Sudoku generator - generates valid, solvable puzzles
|
||||
|
||||
export type Grid = number[][]; // 0 = empty cell, 1-9 = filled
|
||||
|
||||
export type Difficulty = "facile" | "moyen" | "difficile" | "expert";
|
||||
|
||||
const DIFFICULTY_LABELS: Record<Difficulty, string> = {
|
||||
facile: "Facile",
|
||||
moyen: "Moyen",
|
||||
difficile: "Difficile",
|
||||
expert: "Expert",
|
||||
};
|
||||
|
||||
export function getDifficultyLabel(d: Difficulty): string {
|
||||
return DIFFICULTY_LABELS[d];
|
||||
}
|
||||
|
||||
// Number of cells to remove per difficulty
|
||||
const CELLS_TO_REMOVE: Record<Difficulty, number> = {
|
||||
facile: 36,
|
||||
moyen: 46,
|
||||
difficile: 52,
|
||||
expert: 58,
|
||||
};
|
||||
|
||||
function shuffleArray<T>(arr: T[]): T[] {
|
||||
const a = [...arr];
|
||||
for (let i = a.length - 1; i > 0; i--) {
|
||||
const j = Math.floor(Math.random() * (i + 1));
|
||||
[a[i], a[j]] = [a[j], a[i]];
|
||||
}
|
||||
return a;
|
||||
}
|
||||
|
||||
function createEmptyGrid(): Grid {
|
||||
return Array.from({ length: 9 }, () => Array(9).fill(0));
|
||||
}
|
||||
|
||||
function cloneGrid(grid: Grid): Grid {
|
||||
return grid.map((row) => [...row]);
|
||||
}
|
||||
|
||||
function isValid(grid: Grid, row: number, col: number, num: number): boolean {
|
||||
// Check row
|
||||
for (let c = 0; c < 9; c++) {
|
||||
if (grid[row][c] === num) return false;
|
||||
}
|
||||
// Check column
|
||||
for (let r = 0; r < 9; r++) {
|
||||
if (grid[r][col] === num) return false;
|
||||
}
|
||||
// Check 3x3 box
|
||||
const boxRow = Math.floor(row / 3) * 3;
|
||||
const boxCol = Math.floor(col / 3) * 3;
|
||||
for (let r = boxRow; r < boxRow + 3; r++) {
|
||||
for (let c = boxCol; c < boxCol + 3; c++) {
|
||||
if (grid[r][c] === num) return false;
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
// Fill the grid completely using backtracking with randomization
|
||||
function fillGrid(grid: Grid): boolean {
|
||||
for (let row = 0; row < 9; row++) {
|
||||
for (let col = 0; col < 9; col++) {
|
||||
if (grid[row][col] === 0) {
|
||||
const nums = shuffleArray([1, 2, 3, 4, 5, 6, 7, 8, 9]);
|
||||
for (const num of nums) {
|
||||
if (isValid(grid, row, col, num)) {
|
||||
grid[row][col] = num;
|
||||
if (fillGrid(grid)) return true;
|
||||
grid[row][col] = 0;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
// Count solutions (stop at 2 to check uniqueness)
|
||||
function countSolutions(grid: Grid, limit: number = 2): number {
|
||||
let count = 0;
|
||||
|
||||
function solve(g: Grid): boolean {
|
||||
for (let row = 0; row < 9; row++) {
|
||||
for (let col = 0; col < 9; col++) {
|
||||
if (g[row][col] === 0) {
|
||||
for (let num = 1; num <= 9; num++) {
|
||||
if (isValid(g, row, col, num)) {
|
||||
g[row][col] = num;
|
||||
if (solve(g)) {
|
||||
if (count >= limit) return true;
|
||||
}
|
||||
g[row][col] = 0;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
count++;
|
||||
return count >= limit;
|
||||
}
|
||||
|
||||
solve(cloneGrid(grid));
|
||||
return count;
|
||||
}
|
||||
|
||||
// Generate a puzzle by removing cells from a complete grid
|
||||
function generatePuzzle(
|
||||
solution: Grid,
|
||||
difficulty: Difficulty
|
||||
): Grid {
|
||||
const puzzle = cloneGrid(solution);
|
||||
const toRemove = CELLS_TO_REMOVE[difficulty];
|
||||
|
||||
// Create list of all cell positions and shuffle
|
||||
const positions: [number, number][] = [];
|
||||
for (let r = 0; r < 9; r++) {
|
||||
for (let c = 0; c < 9; c++) {
|
||||
positions.push([r, c]);
|
||||
}
|
||||
}
|
||||
const shuffled = shuffleArray(positions);
|
||||
|
||||
let removed = 0;
|
||||
for (const [r, c] of shuffled) {
|
||||
if (removed >= toRemove) break;
|
||||
|
||||
const backup = puzzle[r][c];
|
||||
puzzle[r][c] = 0;
|
||||
|
||||
// For easier difficulties, always verify uniqueness
|
||||
// For expert, we relax after enough removals to speed up generation
|
||||
if (difficulty === "expert" && removed > 45) {
|
||||
removed++;
|
||||
continue;
|
||||
}
|
||||
|
||||
if (countSolutions(puzzle) !== 1) {
|
||||
puzzle[r][c] = backup; // restore - would create multiple solutions
|
||||
} else {
|
||||
removed++;
|
||||
}
|
||||
}
|
||||
|
||||
return puzzle;
|
||||
}
|
||||
|
||||
export interface SudokuPuzzle {
|
||||
puzzle: Grid;
|
||||
solution: Grid;
|
||||
}
|
||||
|
||||
// Generate a single sudoku puzzle
|
||||
export function generateSudoku(difficulty: Difficulty): SudokuPuzzle {
|
||||
const solution = createEmptyGrid();
|
||||
fillGrid(solution);
|
||||
const puzzle = generatePuzzle(solution, difficulty);
|
||||
return { puzzle, solution };
|
||||
}
|
||||
|
||||
// Generate multiple sudoku puzzles
|
||||
export function generateSudokus(
|
||||
difficulty: Difficulty,
|
||||
count: number = 6
|
||||
): SudokuPuzzle[] {
|
||||
const puzzles: SudokuPuzzle[] = [];
|
||||
for (let i = 0; i < count; i++) {
|
||||
puzzles.push(generateSudoku(difficulty));
|
||||
}
|
||||
return puzzles;
|
||||
}
|
||||
+126
@@ -0,0 +1,126 @@
|
||||
"use client";
|
||||
|
||||
import { useState, useCallback, useEffect } from "react";
|
||||
import { Difficulty, getDifficultyLabel, generateSudokus, SudokuPuzzle } from "./lib/sudoku";
|
||||
import SudokuGrid from "./components/SudokuGrid";
|
||||
|
||||
const DIFFICULTIES: Difficulty[] = ["facile", "moyen", "difficile", "expert"];
|
||||
const SUDOKU_COUNT = 6;
|
||||
|
||||
export default function Home() {
|
||||
const [difficulty, setDifficulty] = useState<Difficulty>("moyen");
|
||||
const [puzzles, setPuzzles] = useState<SudokuPuzzle[] | null>(null);
|
||||
const [generating, setGenerating] = useState(false);
|
||||
|
||||
// Générer automatiquement des sudoku "Moyen" au chargement
|
||||
useEffect(() => {
|
||||
setGenerating(true);
|
||||
setTimeout(() => {
|
||||
const generated = generateSudokus("moyen", SUDOKU_COUNT);
|
||||
setPuzzles(generated);
|
||||
setGenerating(false);
|
||||
}, 50);
|
||||
}, []);
|
||||
|
||||
const handleGenerate = useCallback((diff: Difficulty) => {
|
||||
setDifficulty(diff);
|
||||
setGenerating(true);
|
||||
// Use setTimeout to let UI update before heavy computation
|
||||
setTimeout(() => {
|
||||
const generated = generateSudokus(diff, SUDOKU_COUNT);
|
||||
setPuzzles(generated);
|
||||
setGenerating(false);
|
||||
}, 50);
|
||||
}, []);
|
||||
|
||||
const handlePrint = useCallback(() => {
|
||||
if (!puzzles) {
|
||||
setGenerating(true);
|
||||
setTimeout(() => {
|
||||
const generated = generateSudokus(difficulty, SUDOKU_COUNT);
|
||||
setPuzzles(generated);
|
||||
setGenerating(false);
|
||||
setTimeout(() => window.print(), 100);
|
||||
}, 50);
|
||||
} else {
|
||||
window.print();
|
||||
}
|
||||
}, [puzzles, difficulty]);
|
||||
|
||||
const label = getDifficultyLabel(difficulty);
|
||||
|
||||
return (
|
||||
<div className="app-container">
|
||||
{/* Controls - hidden when printing */}
|
||||
<header className="controls no-print" role="banner">
|
||||
<h1 className="app-title">🧩 Générateur de Sudoku</h1>
|
||||
<p className="app-subtitle">
|
||||
Choisissez une difficulté pour générer {SUDOKU_COUNT} sudoku sur une feuille A4 avec leurs solutions.
|
||||
</p>
|
||||
|
||||
<nav className="button-group" role="navigation" aria-label="Choix de difficulté">
|
||||
{DIFFICULTIES.map((diff) => (
|
||||
<button
|
||||
key={diff}
|
||||
onClick={() => handleGenerate(diff)}
|
||||
disabled={generating}
|
||||
aria-pressed={difficulty === diff && !!puzzles}
|
||||
className={`btn-difficulty ${difficulty === diff && puzzles ? "btn-active" : ""}`}
|
||||
>
|
||||
{getDifficultyLabel(diff)}
|
||||
</button>
|
||||
))}
|
||||
|
||||
<button
|
||||
onClick={handlePrint}
|
||||
disabled={generating || !puzzles}
|
||||
className="btn-print"
|
||||
aria-label="Imprimer les grilles de sudoku"
|
||||
>
|
||||
🖨️ Imprimer
|
||||
</button>
|
||||
</nav>
|
||||
|
||||
{generating && (
|
||||
<p className="generating-text" role="status" aria-live="polite">Génération en cours…</p>
|
||||
)}
|
||||
</header>
|
||||
|
||||
{/* SEO content - visible to crawlers, visually subtle */}
|
||||
<section className="seo-content no-print" aria-label="À propos">
|
||||
<h2>Générateur de Sudoku gratuit à imprimer</h2>
|
||||
<p>
|
||||
Créez et imprimez des grilles de Sudoku gratuitement. Notre générateur produit des puzzles
|
||||
valides et solvables avec 4 niveaux de difficulté : facile, moyen, difficile et expert.
|
||||
Chaque feuille A4 contient 6 grilles 9×9 accompagnées de leurs solutions sur une page séparée.
|
||||
Idéal pour s'entraîner, jouer en famille ou en classe.
|
||||
</p>
|
||||
</section>
|
||||
|
||||
{/* Printable content */}
|
||||
{puzzles && (
|
||||
<main className="print-area" role="main">
|
||||
{/* Page 1: Puzzles */}
|
||||
<section className="print-page" aria-label={`Grilles de sudoku niveau ${label}`}>
|
||||
<h2 className="page-title">Sudoku — Niveau {label}</h2>
|
||||
<div className="sudoku-grid-container">
|
||||
{puzzles.map((p, i) => (
|
||||
<SudokuGrid key={`puzzle-${i}`} grid={p.puzzle} index={i} />
|
||||
))}
|
||||
</div>
|
||||
</section>
|
||||
|
||||
{/* Page 2: Solutions */}
|
||||
<section className="print-page" aria-label={`Solutions niveau ${label}`}>
|
||||
<h2 className="page-title">Solutions — Niveau {label}</h2>
|
||||
<div className="sudoku-grid-container">
|
||||
{puzzles.map((p, i) => (
|
||||
<SudokuGrid key={`solution-${i}`} grid={p.solution} index={i} isSolution />
|
||||
))}
|
||||
</div>
|
||||
</section>
|
||||
</main>
|
||||
)}
|
||||
</div>
|
||||
);
|
||||
}
|
||||
@@ -0,0 +1,13 @@
|
||||
import type { MetadataRoute } from "next";
|
||||
|
||||
export default function robots(): MetadataRoute.Robots {
|
||||
return {
|
||||
rules: [
|
||||
{
|
||||
userAgent: "*",
|
||||
allow: "/",
|
||||
},
|
||||
],
|
||||
sitemap: "https://imprimersudoku.arthurp.fr/sitemap.xml",
|
||||
};
|
||||
}
|
||||
@@ -0,0 +1,12 @@
|
||||
import type { MetadataRoute } from "next";
|
||||
|
||||
export default function sitemap(): MetadataRoute.Sitemap {
|
||||
return [
|
||||
{
|
||||
url: "https://imprimersudoku.arthurp.fr",
|
||||
lastModified: new Date(),
|
||||
changeFrequency: "monthly",
|
||||
priority: 1,
|
||||
},
|
||||
];
|
||||
}
|
||||
@@ -0,0 +1,23 @@
|
||||
services:
|
||||
sudoku:
|
||||
image: node:22-alpine
|
||||
container_name: sudoku-app
|
||||
working_dir: /app
|
||||
volumes:
|
||||
- .:/app
|
||||
- node_modules:/app/node_modules
|
||||
restart: unless-stopped
|
||||
ports:
|
||||
- "3017:3000"
|
||||
environment:
|
||||
- NEXT_TELEMETRY_DISABLED=1
|
||||
command: sh -c "rm -rf types .next && npm ci && npm run build && NODE_ENV=production npm start"
|
||||
healthcheck:
|
||||
test: ["CMD", "wget", "--no-verbose", "--tries=1", "--spider", "http://localhost:3000/"]
|
||||
interval: 30s
|
||||
timeout: 5s
|
||||
retries: 3
|
||||
start_period: 60s
|
||||
|
||||
volumes:
|
||||
node_modules:
|
||||
@@ -0,0 +1,18 @@
|
||||
import { defineConfig, globalIgnores } from "eslint/config";
|
||||
import nextVitals from "eslint-config-next/core-web-vitals";
|
||||
import nextTs from "eslint-config-next/typescript";
|
||||
|
||||
const eslintConfig = defineConfig([
|
||||
...nextVitals,
|
||||
...nextTs,
|
||||
// Override default ignores of eslint-config-next.
|
||||
globalIgnores([
|
||||
// Default ignores of eslint-config-next:
|
||||
".next/**",
|
||||
"out/**",
|
||||
"build/**",
|
||||
"next-env.d.ts",
|
||||
]),
|
||||
]);
|
||||
|
||||
export default eslintConfig;
|
||||
@@ -0,0 +1,7 @@
|
||||
import type { NextConfig } from "next";
|
||||
|
||||
const nextConfig: NextConfig = {
|
||||
output: "standalone",
|
||||
};
|
||||
|
||||
export default nextConfig;
|
||||
Generated
+6603
File diff suppressed because it is too large
Load Diff
@@ -0,0 +1,26 @@
|
||||
{
|
||||
"name": "sudokumaman",
|
||||
"version": "0.1.0",
|
||||
"private": true,
|
||||
"scripts": {
|
||||
"dev": "next dev",
|
||||
"build": "next build",
|
||||
"start": "next start",
|
||||
"lint": "eslint"
|
||||
},
|
||||
"dependencies": {
|
||||
"next": "16.1.6",
|
||||
"react": "19.2.3",
|
||||
"react-dom": "19.2.3"
|
||||
},
|
||||
"devDependencies": {
|
||||
"@tailwindcss/postcss": "^4",
|
||||
"@types/node": "^20",
|
||||
"@types/react": "^19",
|
||||
"@types/react-dom": "^19",
|
||||
"eslint": "^9",
|
||||
"eslint-config-next": "16.1.6",
|
||||
"tailwindcss": "^4",
|
||||
"typescript": "^5"
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,7 @@
|
||||
const config = {
|
||||
plugins: {
|
||||
"@tailwindcss/postcss": {},
|
||||
},
|
||||
};
|
||||
|
||||
export default config;
|
||||
@@ -0,0 +1 @@
|
||||
<svg fill="none" viewBox="0 0 16 16" xmlns="http://www.w3.org/2000/svg"><path d="M14.5 13.5V5.41a1 1 0 0 0-.3-.7L9.8.29A1 1 0 0 0 9.08 0H1.5v13.5A2.5 2.5 0 0 0 4 16h8a2.5 2.5 0 0 0 2.5-2.5m-1.5 0v-7H8v-5H3v12a1 1 0 0 0 1 1h8a1 1 0 0 0 1-1M9.5 5V2.12L12.38 5zM5.13 5h-.62v1.25h2.12V5zm-.62 3h7.12v1.25H4.5zm.62 3h-.62v1.25h7.12V11z" clip-rule="evenodd" fill="#666" fill-rule="evenodd"/></svg>
|
||||
|
After Width: | Height: | Size: 391 B |
@@ -0,0 +1 @@
|
||||
<svg fill="none" xmlns="http://www.w3.org/2000/svg" viewBox="0 0 16 16"><g clip-path="url(#a)"><path fill-rule="evenodd" clip-rule="evenodd" d="M10.27 14.1a6.5 6.5 0 0 0 3.67-3.45q-1.24.21-2.7.34-.31 1.83-.97 3.1M8 16A8 8 0 1 0 8 0a8 8 0 0 0 0 16m.48-1.52a7 7 0 0 1-.96 0H7.5a4 4 0 0 1-.84-1.32q-.38-.89-.63-2.08a40 40 0 0 0 3.92 0q-.25 1.2-.63 2.08a4 4 0 0 1-.84 1.31zm2.94-4.76q1.66-.15 2.95-.43a7 7 0 0 0 0-2.58q-1.3-.27-2.95-.43a18 18 0 0 1 0 3.44m-1.27-3.54a17 17 0 0 1 0 3.64 39 39 0 0 1-4.3 0 17 17 0 0 1 0-3.64 39 39 0 0 1 4.3 0m1.1-1.17q1.45.13 2.69.34a6.5 6.5 0 0 0-3.67-3.44q.65 1.26.98 3.1M8.48 1.5l.01.02q.41.37.84 1.31.38.89.63 2.08a40 40 0 0 0-3.92 0q.25-1.2.63-2.08a4 4 0 0 1 .85-1.32 7 7 0 0 1 .96 0m-2.75.4a6.5 6.5 0 0 0-3.67 3.44 29 29 0 0 1 2.7-.34q.31-1.83.97-3.1M4.58 6.28q-1.66.16-2.95.43a7 7 0 0 0 0 2.58q1.3.27 2.95.43a18 18 0 0 1 0-3.44m.17 4.71q-1.45-.12-2.69-.34a6.5 6.5 0 0 0 3.67 3.44q-.65-1.27-.98-3.1" fill="#666"/></g><defs><clipPath id="a"><path fill="#fff" d="M0 0h16v16H0z"/></clipPath></defs></svg>
|
||||
|
After Width: | Height: | Size: 1.0 KiB |
@@ -0,0 +1 @@
|
||||
<svg xmlns="http://www.w3.org/2000/svg" fill="none" viewBox="0 0 394 80"><path fill="#000" d="M262 0h68.5v12.7h-27.2v66.6h-13.6V12.7H262V0ZM149 0v12.7H94v20.4h44.3v12.6H94v21h55v12.6H80.5V0h68.7zm34.3 0h-17.8l63.8 79.4h17.9l-32-39.7 32-39.6h-17.9l-23 28.6-23-28.6zm18.3 56.7-9-11-27.1 33.7h17.8l18.3-22.7z"/><path fill="#000" d="M81 79.3 17 0H0v79.3h13.6V17l50.2 62.3H81Zm252.6-.4c-1 0-1.8-.4-2.5-1s-1.1-1.6-1.1-2.6.3-1.8 1-2.5 1.6-1 2.6-1 1.8.3 2.5 1a3.4 3.4 0 0 1 .6 4.3 3.7 3.7 0 0 1-3 1.8zm23.2-33.5h6v23.3c0 2.1-.4 4-1.3 5.5a9.1 9.1 0 0 1-3.8 3.5c-1.6.8-3.5 1.3-5.7 1.3-2 0-3.7-.4-5.3-1s-2.8-1.8-3.7-3.2c-.9-1.3-1.4-3-1.4-5h6c.1.8.3 1.6.7 2.2s1 1.2 1.6 1.5c.7.4 1.5.5 2.4.5 1 0 1.8-.2 2.4-.6a4 4 0 0 0 1.6-1.8c.3-.8.5-1.8.5-3V45.5zm30.9 9.1a4.4 4.4 0 0 0-2-3.3 7.5 7.5 0 0 0-4.3-1.1c-1.3 0-2.4.2-3.3.5-.9.4-1.6 1-2 1.6a3.5 3.5 0 0 0-.3 4c.3.5.7.9 1.3 1.2l1.8 1 2 .5 3.2.8c1.3.3 2.5.7 3.7 1.2a13 13 0 0 1 3.2 1.8 8.1 8.1 0 0 1 3 6.5c0 2-.5 3.7-1.5 5.1a10 10 0 0 1-4.4 3.5c-1.8.8-4.1 1.2-6.8 1.2-2.6 0-4.9-.4-6.8-1.2-2-.8-3.4-2-4.5-3.5a10 10 0 0 1-1.7-5.6h6a5 5 0 0 0 3.5 4.6c1 .4 2.2.6 3.4.6 1.3 0 2.5-.2 3.5-.6 1-.4 1.8-1 2.4-1.7a4 4 0 0 0 .8-2.4c0-.9-.2-1.6-.7-2.2a11 11 0 0 0-2.1-1.4l-3.2-1-3.8-1c-2.8-.7-5-1.7-6.6-3.2a7.2 7.2 0 0 1-2.4-5.7 8 8 0 0 1 1.7-5 10 10 0 0 1 4.3-3.5c2-.8 4-1.2 6.4-1.2 2.3 0 4.4.4 6.2 1.2 1.8.8 3.2 2 4.3 3.4 1 1.4 1.5 3 1.5 5h-5.8z"/></svg>
|
||||
|
After Width: | Height: | Size: 1.3 KiB |
@@ -0,0 +1 @@
|
||||
<svg fill="none" xmlns="http://www.w3.org/2000/svg" viewBox="0 0 1155 1000"><path d="m577.3 0 577.4 1000H0z" fill="#fff"/></svg>
|
||||
|
After Width: | Height: | Size: 128 B |
@@ -0,0 +1 @@
|
||||
<svg fill="none" xmlns="http://www.w3.org/2000/svg" viewBox="0 0 16 16"><path fill-rule="evenodd" clip-rule="evenodd" d="M1.5 2.5h13v10a1 1 0 0 1-1 1h-11a1 1 0 0 1-1-1zM0 1h16v11.5a2.5 2.5 0 0 1-2.5 2.5h-11A2.5 2.5 0 0 1 0 12.5zm3.75 4.5a.75.75 0 1 0 0-1.5.75.75 0 0 0 0 1.5M7 4.75a.75.75 0 1 1-1.5 0 .75.75 0 0 1 1.5 0m1.75.75a.75.75 0 1 0 0-1.5.75.75 0 0 0 0 1.5" fill="#666"/></svg>
|
||||
|
After Width: | Height: | Size: 385 B |
@@ -0,0 +1,34 @@
|
||||
{
|
||||
"compilerOptions": {
|
||||
"target": "ES2017",
|
||||
"lib": ["dom", "dom.iterable", "esnext"],
|
||||
"allowJs": true,
|
||||
"skipLibCheck": true,
|
||||
"strict": true,
|
||||
"noEmit": true,
|
||||
"esModuleInterop": true,
|
||||
"module": "esnext",
|
||||
"moduleResolution": "bundler",
|
||||
"resolveJsonModule": true,
|
||||
"isolatedModules": true,
|
||||
"jsx": "react-jsx",
|
||||
"incremental": true,
|
||||
"plugins": [
|
||||
{
|
||||
"name": "next"
|
||||
}
|
||||
],
|
||||
"paths": {
|
||||
"@/*": ["./*"]
|
||||
}
|
||||
},
|
||||
"include": [
|
||||
"next-env.d.ts",
|
||||
"**/*.ts",
|
||||
"**/*.tsx",
|
||||
".next/types/**/*.ts",
|
||||
".next/dev/types/**/*.ts",
|
||||
"**/*.mts"
|
||||
],
|
||||
"exclude": ["node_modules"]
|
||||
}
|
||||
Vendored
+145
@@ -0,0 +1,145 @@
|
||||
// Type definitions for Next.js cacheLife configs
|
||||
|
||||
declare module 'next/cache' {
|
||||
export { unstable_cache } from 'next/dist/server/web/spec-extension/unstable-cache'
|
||||
export {
|
||||
updateTag,
|
||||
revalidateTag,
|
||||
revalidatePath,
|
||||
refresh,
|
||||
} from 'next/dist/server/web/spec-extension/revalidate'
|
||||
export { unstable_noStore } from 'next/dist/server/web/spec-extension/unstable-no-store'
|
||||
|
||||
|
||||
/**
|
||||
* Cache this `"use cache"` for a timespan defined by the `"default"` profile.
|
||||
* ```
|
||||
* stale: 300 seconds (5 minutes)
|
||||
* revalidate: 900 seconds (15 minutes)
|
||||
* expire: never
|
||||
* ```
|
||||
*
|
||||
* This cache may be stale on clients for 5 minutes before checking with the server.
|
||||
* If the server receives a new request after 15 minutes, start revalidating new values in the background.
|
||||
* It lives for the maximum age of the server cache. If this entry has no traffic for a while, it may serve an old value the next request.
|
||||
*/
|
||||
export function cacheLife(profile: "default"): void
|
||||
|
||||
/**
|
||||
* Cache this `"use cache"` for a timespan defined by the `"seconds"` profile.
|
||||
* ```
|
||||
* stale: 30 seconds
|
||||
* revalidate: 1 seconds
|
||||
* expire: 60 seconds (1 minute)
|
||||
* ```
|
||||
*
|
||||
* This cache may be stale on clients for 30 seconds before checking with the server.
|
||||
* If the server receives a new request after 1 seconds, start revalidating new values in the background.
|
||||
* If this entry has no traffic for 1 minute it will expire. The next request will recompute it.
|
||||
*/
|
||||
export function cacheLife(profile: "seconds"): void
|
||||
|
||||
/**
|
||||
* Cache this `"use cache"` for a timespan defined by the `"minutes"` profile.
|
||||
* ```
|
||||
* stale: 300 seconds (5 minutes)
|
||||
* revalidate: 60 seconds (1 minute)
|
||||
* expire: 3600 seconds (1 hour)
|
||||
* ```
|
||||
*
|
||||
* This cache may be stale on clients for 5 minutes before checking with the server.
|
||||
* If the server receives a new request after 1 minute, start revalidating new values in the background.
|
||||
* If this entry has no traffic for 1 hour it will expire. The next request will recompute it.
|
||||
*/
|
||||
export function cacheLife(profile: "minutes"): void
|
||||
|
||||
/**
|
||||
* Cache this `"use cache"` for a timespan defined by the `"hours"` profile.
|
||||
* ```
|
||||
* stale: 300 seconds (5 minutes)
|
||||
* revalidate: 3600 seconds (1 hour)
|
||||
* expire: 86400 seconds (1 day)
|
||||
* ```
|
||||
*
|
||||
* This cache may be stale on clients for 5 minutes before checking with the server.
|
||||
* If the server receives a new request after 1 hour, start revalidating new values in the background.
|
||||
* If this entry has no traffic for 1 day it will expire. The next request will recompute it.
|
||||
*/
|
||||
export function cacheLife(profile: "hours"): void
|
||||
|
||||
/**
|
||||
* Cache this `"use cache"` for a timespan defined by the `"days"` profile.
|
||||
* ```
|
||||
* stale: 300 seconds (5 minutes)
|
||||
* revalidate: 86400 seconds (1 day)
|
||||
* expire: 604800 seconds (1 week)
|
||||
* ```
|
||||
*
|
||||
* This cache may be stale on clients for 5 minutes before checking with the server.
|
||||
* If the server receives a new request after 1 day, start revalidating new values in the background.
|
||||
* If this entry has no traffic for 1 week it will expire. The next request will recompute it.
|
||||
*/
|
||||
export function cacheLife(profile: "days"): void
|
||||
|
||||
/**
|
||||
* Cache this `"use cache"` for a timespan defined by the `"weeks"` profile.
|
||||
* ```
|
||||
* stale: 300 seconds (5 minutes)
|
||||
* revalidate: 604800 seconds (1 week)
|
||||
* expire: 2592000 seconds (1 month)
|
||||
* ```
|
||||
*
|
||||
* This cache may be stale on clients for 5 minutes before checking with the server.
|
||||
* If the server receives a new request after 1 week, start revalidating new values in the background.
|
||||
* If this entry has no traffic for 1 month it will expire. The next request will recompute it.
|
||||
*/
|
||||
export function cacheLife(profile: "weeks"): void
|
||||
|
||||
/**
|
||||
* Cache this `"use cache"` for a timespan defined by the `"max"` profile.
|
||||
* ```
|
||||
* stale: 300 seconds (5 minutes)
|
||||
* revalidate: 2592000 seconds (1 month)
|
||||
* expire: 31536000 seconds (365 days)
|
||||
* ```
|
||||
*
|
||||
* This cache may be stale on clients for 5 minutes before checking with the server.
|
||||
* If the server receives a new request after 1 month, start revalidating new values in the background.
|
||||
* If this entry has no traffic for 365 days it will expire. The next request will recompute it.
|
||||
*/
|
||||
export function cacheLife(profile: "max"): void
|
||||
|
||||
/**
|
||||
* Cache this `"use cache"` using a custom timespan.
|
||||
* ```
|
||||
* stale: ... // seconds
|
||||
* revalidate: ... // seconds
|
||||
* expire: ... // seconds
|
||||
* ```
|
||||
*
|
||||
* This is similar to Cache-Control: max-age=`stale`,s-max-age=`revalidate`,stale-while-revalidate=`expire-revalidate`
|
||||
*
|
||||
* If a value is left out, the lowest of other cacheLife() calls or the default, is used instead.
|
||||
*/
|
||||
export function cacheLife(profile: {
|
||||
/**
|
||||
* This cache may be stale on clients for ... seconds before checking with the server.
|
||||
*/
|
||||
stale?: number,
|
||||
/**
|
||||
* If the server receives a new request after ... seconds, start revalidating new values in the background.
|
||||
*/
|
||||
revalidate?: number,
|
||||
/**
|
||||
* If this entry has no traffic for ... seconds it will expire. The next request will recompute it.
|
||||
*/
|
||||
expire?: number
|
||||
}): void
|
||||
|
||||
|
||||
import { cacheTag } from 'next/dist/server/use-cache/cache-tag'
|
||||
export { cacheTag }
|
||||
|
||||
export const unstable_cacheTag: typeof cacheTag
|
||||
export const unstable_cacheLife: typeof cacheLife
|
||||
}
|
||||
Vendored
+57
@@ -0,0 +1,57 @@
|
||||
// This file is generated automatically by Next.js
|
||||
// Do not edit this file manually
|
||||
|
||||
type AppRoutes = "/"
|
||||
type PageRoutes = never
|
||||
type LayoutRoutes = "/"
|
||||
type RedirectRoutes = never
|
||||
type RewriteRoutes = never
|
||||
type Routes = AppRoutes | PageRoutes | LayoutRoutes | RedirectRoutes | RewriteRoutes
|
||||
|
||||
|
||||
interface ParamMap {
|
||||
"/": {}
|
||||
}
|
||||
|
||||
|
||||
export type ParamsOf<Route extends Routes> = ParamMap[Route]
|
||||
|
||||
interface LayoutSlotMap {
|
||||
"/": never
|
||||
}
|
||||
|
||||
|
||||
export type { AppRoutes, PageRoutes, LayoutRoutes, RedirectRoutes, RewriteRoutes, ParamMap }
|
||||
|
||||
declare global {
|
||||
/**
|
||||
* Props for Next.js App Router page components
|
||||
* @example
|
||||
* ```tsx
|
||||
* export default function Page(props: PageProps<'/blog/[slug]'>) {
|
||||
* const { slug } = await props.params
|
||||
* return <div>Blog post: {slug}</div>
|
||||
* }
|
||||
* ```
|
||||
*/
|
||||
interface PageProps<AppRoute extends AppRoutes> {
|
||||
params: Promise<ParamMap[AppRoute]>
|
||||
searchParams: Promise<Record<string, string | string[] | undefined>>
|
||||
}
|
||||
|
||||
/**
|
||||
* Props for Next.js App Router layout components
|
||||
* @example
|
||||
* ```tsx
|
||||
* export default function Layout(props: LayoutProps<'/dashboard'>) {
|
||||
* return <div>{props.children}</div>
|
||||
* }
|
||||
* ```
|
||||
*/
|
||||
type LayoutProps<LayoutRoute extends LayoutRoutes> = {
|
||||
params: Promise<ParamMap[LayoutRoute]>
|
||||
children: React.ReactNode
|
||||
} & {
|
||||
[K in LayoutSlotMap[LayoutRoute]]: React.ReactNode
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,61 @@
|
||||
// This file is generated automatically by Next.js
|
||||
// Do not edit this file manually
|
||||
// This file validates that all pages and layouts export the correct types
|
||||
|
||||
import type { AppRoutes, LayoutRoutes, ParamMap } from "./routes.js"
|
||||
import type { ResolvingMetadata, ResolvingViewport } from "next/types.js"
|
||||
|
||||
type AppPageConfig<Route extends AppRoutes = AppRoutes> = {
|
||||
default: React.ComponentType<{ params: Promise<ParamMap[Route]> } & any> | ((props: { params: Promise<ParamMap[Route]> } & any) => React.ReactNode | Promise<React.ReactNode> | never | void | Promise<void>)
|
||||
generateStaticParams?: (props: { params: ParamMap[Route] }) => Promise<any[]> | any[]
|
||||
generateMetadata?: (
|
||||
props: { params: Promise<ParamMap[Route]> } & any,
|
||||
parent: ResolvingMetadata
|
||||
) => Promise<any> | any
|
||||
generateViewport?: (
|
||||
props: { params: Promise<ParamMap[Route]> } & any,
|
||||
parent: ResolvingViewport
|
||||
) => Promise<any> | any
|
||||
metadata?: any
|
||||
viewport?: any
|
||||
}
|
||||
|
||||
type LayoutConfig<Route extends LayoutRoutes = LayoutRoutes> = {
|
||||
default: React.ComponentType<LayoutProps<Route>> | ((props: LayoutProps<Route>) => React.ReactNode | Promise<React.ReactNode> | never | void | Promise<void>)
|
||||
generateStaticParams?: (props: { params: ParamMap[Route] }) => Promise<any[]> | any[]
|
||||
generateMetadata?: (
|
||||
props: { params: Promise<ParamMap[Route]> } & any,
|
||||
parent: ResolvingMetadata
|
||||
) => Promise<any> | any
|
||||
generateViewport?: (
|
||||
props: { params: Promise<ParamMap[Route]> } & any,
|
||||
parent: ResolvingViewport
|
||||
) => Promise<any> | any
|
||||
metadata?: any
|
||||
viewport?: any
|
||||
}
|
||||
|
||||
|
||||
// Validate ../../app/page.tsx
|
||||
{
|
||||
type __IsExpected<Specific extends AppPageConfig<"/">> = Specific
|
||||
const handler = {} as typeof import("../../app/page.js")
|
||||
type __Check = __IsExpected<typeof handler>
|
||||
// @ts-ignore
|
||||
type __Unused = __Check
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
// Validate ../../app/layout.tsx
|
||||
{
|
||||
type __IsExpected<Specific extends LayoutConfig<"/">> = Specific
|
||||
const handler = {} as typeof import("../../app/layout.js")
|
||||
type __Check = __IsExpected<typeof handler>
|
||||
// @ts-ignore
|
||||
type __Unused = __Check
|
||||
}
|
||||
Reference in New Issue
Block a user