Merge pull request #546 from Sumangal44/main

css3 update
This commit is contained in:
Fechin authored and GitHub committed 2024-05-29 10:44:51 +08:00
commit b0990cf950
5 files changed
+661 -13

No files matched your search

+242
View File
@@ -0,0 +1,242 @@
---
title: HTML Canvas
date: 2024-05-28 22:16:42
background: bg-[#cc5534]
tags:
- web
categories:
- Programming
intro: |
This HTML Canvas quick reference cheat sheet lists the common HTML5 Canvas design tags in readable layout.
plugins:
- copyCode
---
## Geting Started
### Basic Setup
```html
<!DOCTYPE html>
<html>
<head>
<title>Canvas Example</title>
</head>
<body>
<canvas
id="myCanvas"
width="500"
height="400"
style="border:1px solid #000000;"
></canvas>
<script src="script.js"></script>
</body>
</html>
```
### Getting the Context
```js
const canvas = document.getElementById("myCanvas");
const ctx = canvas.getContext("2d");
```
## Drawing Shapes
### Rectangles
```js
ctx.fillStyle = "red";
ctx.fillRect(10, 10, 150, 100); // x, y, width, height
ctx.strokeStyle = "blue";
ctx.lineWidth = 5;
ctx.strokeRect(200, 10, 150, 100); // x, y, width, height
ctx.clearRect(15, 15, 30, 30); // x, y, width, height
```
## Paths
### Lines
```js
ctx.beginPath();
ctx.moveTo(50, 50); // Starting point
ctx.lineTo(200, 50); // Ending point
ctx.lineTo(200, 200); // Next line ending point
ctx.closePath(); // Connects the end point to the start point
ctx.stroke();
```
### Circles
```js
ctx.beginPath();
ctx.arc(150, 150, 75, 0, 2 * Math.PI); // x, y, radius, startAngle, endAngle
ctx.fillStyle = "green";
ctx.fill();
ctx.stroke();
```
### Arcs
```js
ctx.beginPath();
ctx.arc(150, 150, 75, 0, Math.PI); // x, y, radius, startAngle, endAngle
ctx.stroke();
```
## Bezier and Quadratic Curves
### Quadratic Curve
```js
ctx.beginPath();
ctx.moveTo(50, 250);
ctx.quadraticCurveTo(200, 100, 400, 250); // cpX, cpY, endX, endY
ctx.stroke();
```
### Bezier Curve
```js
ctx.beginPath();
ctx.moveTo(50, 300);
ctx.bezierCurveTo(150, 100, 350, 500, 450, 300); // cp1X, cp1Y, cp2X, cp2Y, endX, endY
ctx.stroke();
```
### Text
```js
ctx.font = "30px Arial";
ctx.fillStyle = "black";
ctx.fillText("Hello Canvas", 10, 50); // text, x, y
ctx.strokeText("Hello Canvas", 10, 100); // text, x, y
```
### Images
```js
const img = new Image();
img.src = "path/to/image.jpg";
img.onload = () => {
ctx.drawImage(img, 10, 10); // img, x, y
ctx.drawImage(img, 50, 50, 100, 100); // img, x, y, width, height
ctx.drawImage(img, 100, 100, 100, 100, 150, 150, 200, 200); // img, sx, sy, sWidth, sHeight, dx, dy, dWidth, dHeight
};
```
## Transformations
### Translation
```js
ctx.translate(100, 100); // x, y
ctx.fillRect(0, 0, 50, 50);
```
### Rotation
```js
ctx.rotate((Math.PI / 180) * 45); // Angle in radians
ctx.fillRect(100, 100, 50, 50);
```
### Scaling
```js
ctx.scale(2, 2); // x, y
ctx.fillRect(50, 50, 50, 50);
```
## Gradients
### Linear Gradient
```js
const linearGradient = ctx.createLinearGradient(0, 0, 200, 0); // x0, y0, x1, y1
linearGradient.addColorStop(0, "red");
linearGradient.addColorStop(1, "blue");
ctx.fillStyle = linearGradient;
ctx.fillRect(10, 10, 200, 100);
```
### Radial Gradient
```js
const radialGradient = ctx.createRadialGradient(75, 50, 5, 90, 60, 100); // x0, y0, r0, x1, y1, r1
radialGradient.addColorStop(0, "red");
radialGradient.addColorStop(1, "blue");
ctx.fillStyle = radialGradient;
ctx.fillRect(10, 10, 200, 100);
```
### Patterns
```js
const img = new Image();
img.src = "path/to/image.jpg";
img.onload = () => {
const pattern = ctx.createPattern(img, "repeat"); // 'repeat', 'repeat-x', 'repeat-y', 'no-repeat'
ctx.fillStyle = pattern;
ctx.fillRect(0, 0, 300, 300);
};
```
### Shadows
```js
ctx.shadowColor = "rgba(0, 0, 0, 0.5)";
ctx.shadowBlur = 10;
ctx.shadowOffsetX = 5;
ctx.shadowOffsetY = 5;
ctx.fillStyle = "red";
ctx.fillRect(100, 100, 100, 100);
```
## Compositing
### Global Alpha
```js
ctx.globalAlpha = 0.5;
ctx.fillStyle = "red";
ctx.fillRect(100, 100, 100, 100);
ctx.fillStyle = "blue";
ctx.fillRect(150, 150, 100, 100);
```
### Global Composite Operation
```js
ctx.globalCompositeOperation = "source-over"; // Default
ctx.fillStyle = "red";
ctx.fillRect(100, 100, 100, 100);
ctx.globalCompositeOperation = "destination-over";
ctx.fillStyle = "blue";
ctx.fillRect(150, 150, 100, 100);
```
### Animations
```js
let x = 0;
function draw() {
ctx.clearRect(0, 0, canvas.width, canvas.height);
ctx.fillStyle = "blue";
ctx.fillRect(x, 100, 50, 50);
x += 2;
requestAnimationFrame(draw);
}
draw();
```
## Also read
- [MDN doc ](https://developer.mozilla.org/en-US/docs/Web/API/Canvas_API)
+13 -13
View File
@@ -1034,7 +1034,7 @@ html {
## Modern CSS
### CONTAINER QUERIES (SIZE)
### container queries(size)
```css
.element-wrap {
@@ -1048,7 +1048,7 @@ html {
}
```
### CONTAINER QUERIES (STYLE)
### container qeries(style)
```css
.container {
@@ -1074,7 +1074,7 @@ html {
}
```
### CONTAINER UNITS
### container units
- The units are cqw (“container query width”),
- cqh (“container query height”),
@@ -1097,7 +1097,7 @@ h2 {
}
```
### THE :HAS() PSEUDO SELECTOR
### the :has() pseudo selector
```css
figure:has(figcaption) {
@@ -1106,7 +1106,7 @@ figure:has(figcaption) {
}
```
### NESTING
### nesting
```css
.cards {
@@ -1123,7 +1123,7 @@ figure:has(figcaption) {
###
### SCOPING @scope
### scoping
```css
@scope {
@@ -1145,7 +1145,7 @@ figure:has(figcaption) {
}
```
### CASCADE LAYERS
### cascade layers
```css
/* Specify the order to apply styles in cascade */
@@ -1164,7 +1164,7 @@ figure:has(figcaption) {
}
```
### LOGICAL PROPERTIES
### logical properties
```css
button {
@@ -1186,7 +1186,7 @@ button {
}
```
### P3 COLORS
### p3 colors
```html
<div class="container">
@@ -1250,7 +1250,7 @@ button {
</div>
```
### COLOR MIXING
### color mixing
```css
.swatch {
@@ -1273,7 +1273,7 @@ button {
}
```
### MARGIN TRIM
### margin trim
```css
.container {
@@ -1287,7 +1287,7 @@ button {
}
```
### TEXT WRAPPING
### text wrapping
```css
.balance {
@@ -1307,7 +1307,7 @@ main {
}
```
### SUBGRID
### subgrid
```css
.grid {
+330
View File
@@ -0,0 +1,330 @@
---
title: TypeScript
date: 2024-05-28 22:12:25
background: bg-[#ebd94e]
tags:
- ts
- web
categories:
- Programming
intro: |
A TypeScript cheat sheet with the most important concepts, functions, methods, and more. A complete quick reference for beginners.
plugins:
- copyCode
---
## Getting Started
### Installing the Compiler
```shell
npm install typescript --save-dev
npm tsc
```
## Basic DataTypes
### basic types
```ts
let isDone: boolean = false;
let age: number = 30;
let userName: string = "John";
let list: number[] = [1, 2, 3];
let tuple: [string, number] = ["hello", 10];
let notSure: any = 4;
notSure = "maybe a string instead";
```
### enums
```ts
enum Color {
Red,
Green,
Blue,
}
let c: Color = Color.Green;
```
### interface
```ts
interface Person {
firstName: string;
lastName: string;
age?: number; // Optional property
}
function greet(person: Person) {
return "Hello, " + person.firstName + " " + person.lastName;
}
```
### Functions
```ts
function add(x: number, y: number): number {
return x + y;
}
let myAdd = function (x: number, y: number): number {
return x + y;
};
let myArrowAdd = (x: number, y: number): number => x + y;
function buildName(firstName: string, lastName = "Smith") {
return firstName + " " + lastName;
}
function buildFullName(firstName: string, ...restOfName: string[]) {
return firstName + " " + restOfName.join(" ");
}
```
### Classes
```ts
class Greeter {
greeting: string;
constructor(message: string) {
this.greeting = message;
}
greet() {
return "Hello, " + this.greeting;
}
}
let greeter = new Greeter("world");
```
### Inheritance
```ts
class Animal {
move(distance: number = 0) {
console.log(`Animal moved ${distance} meters.`);
}
}
class Dog extends Animal {
bark() {
console.log("Woof! Woof!");
}
}
const dog = new Dog();
dog.bark();
dog.move(10);
dog.bark();
```
### Generics
```ts
function identity<T>(arg: T): T {
return arg;
}
let output1 = identity<string>("myString");
let output2 = identity<number>(42);
```
### Type Assertions
```ts
let someValue: any = "this is a string";
let strLength: number = (<string>someValue).length;
// or
let strLength2: number = (someValue as string).length;
```
## Modules
### Export
```ts
export interface StringValidator {
isAcceptable(s: string): boolean;
}
export class ZipCodeValidator implements StringValidator {
isAcceptable(s: string) {
return s.length === 5;
}
}
```
### Import
```ts
import { ZipCodeValidator } from "./ZipCodeValidator";
let myValidator = new ZipCodeValidator();
```
### Namespaces
```ts
namespace Validation {
export interface StringValidator {
isAcceptable(s: string): boolean;
}
export class LettersOnlyValidator implements StringValidator {
isAcceptable(s: string) {
return /^[A-Za-z]+$/.test(s);
}
}
}
let validator = new Validation.LettersOnlyValidator();
```
## Union and Intersection Types
### Union Types
```ts
function padLeft(value: string, padding: string | number) {
if (typeof padding === "number") {
return Array(padding + 1).join(" ") + value;
}
if (typeof padding === "string") {
return padding + value;
}
throw new Error(`Expected string or number, got '${padding}'.`);
}
```
### Intersection Types
```ts
interface ErrorHandling {
success: boolean;
error?: { message: string };
}
interface ArtworksData {
artworks: { title: string }[];
}
type ArtworksResponse = ArtworksData & ErrorHandling;
const response: ArtworksResponse = {
success: true,
artworks: [{ title: "Mona Lisa" }],
};
```
## Utility Types
### Partial
```ts
interface User {
id: number;
name: string;
age: number;
}
let partialUser: Partial<User> = {
name: "Alice",
};
```
### Readonly
```ts
let readonlyUser: Readonly<User> = {
id: 1,
name: "Bob",
age: 25,
};
// readonlyUser.age = 26; // Error: cannot reassign a readonly property
```
### Pick
```ts
type UserName = Pick<User, "name">;
let userName: UserName = {
name: "Charlie",
};
```
### Omit
```ts
type UserWithoutAge = Omit<User, "age">;
let userWithoutAge: UserWithoutAge = {
id: 2,
name: "Dave",
};
```
## Decorators
### Class Decorator
```ts
function sealed(constructor: Function) {
Object.seal(constructor);
Object.seal(constructor.prototype);
}
@sealed
class Greeter {
greeting: string;
constructor(message: string) {
this.greeting = message;
}
greet() {
return "Hello, " + this.greeting;
}
}
```
### Method Decorator
```ts
function enumerable(value: boolean) {
return function (
target: any,
propertyKey: string,
descriptor: PropertyDescriptor
) {
descriptor.enumerable = value;
};
}
class Greeter {
greeting: string;
constructor(message: string) {
this.greeting = message;
}
@enumerable(false)
greet() {
return "Hello, " + this.greeting;
}
}
```
### Async/Await
```ts
async function fetchData(url: string) {
let response = await fetch(url);
let data = await response.json();
return data;
}
```
## Also read
- [TypeScript](https://www.typescriptlang.org/docs/)
+74
View File
@@ -0,0 +1,74 @@
<?xml version="1.0" encoding="utf-8"?>
<!-- Uploaded to: SVG Repo, www.svgrepo.com, Generator: SVG Repo Mixer Tools -->
<svg width="1rem" height="1rem" viewBox="0 0 32 32" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:cc="http://creativecommons.org/ns#" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" id="svg820" version="1.1">
<defs id="defs814">
<linearGradient gradientTransform="matrix(1.25 0 0 1.2 -484.714 468.561)" gradientUnits="userSpaceOnUse" y2="520.79797" x2="401.57144" y1="535.79797" x1="401.57144" id="linearGradient4358" xlink:href="#linearGradient4424"/>
<linearGradient id="linearGradient4424">
<stop style="stop-color:#60a5e7;stop-opacity:0" offset="0" id="stop4426"/>
<stop style="stop-color:#a6f3fb;stop-opacity:.25773194" offset="1" id="stop4428"/>
</linearGradient>
</defs>
<metadata id="metadata817">
<rdf:RDF>
<cc:Work>
<dc:format>image/svg+xml</dc:format>
<dc:type rdf:resource="http://purl.org/dc/dcmitype/StillImage"/>
<dc:title/>
<dc:date>2021</dc:date>
<dc:creator>
<cc:Agent>
<dc:title>Timothée Giet</dc:title>
</cc:Agent>
</dc:creator>
<cc:license rdf:resource="http://creativecommons.org/licenses/by-sa/4.0/"/>
</cc:Work>
<cc:License rdf:about="http://creativecommons.org/licenses/by-sa/4.0/">
<cc:permits rdf:resource="http://creativecommons.org/ns#Reproduction"/>
<cc:permits rdf:resource="http://creativecommons.org/ns#Distribution"/>
<cc:requires rdf:resource="http://creativecommons.org/ns#Notice"/>
<cc:requires rdf:resource="http://creativecommons.org/ns#Attribution"/>
<cc:permits rdf:resource="http://creativecommons.org/ns#DerivativeWorks"/>
<cc:requires rdf:resource="http://creativecommons.org/ns#ShareAlike"/>
</cc:License>
</rdf:RDF>
</metadata>
<g transform="translate(0 -1090.52)" id="layer1">
<path id="rect4122" transform="translate(0 1090.52)" d="M2 2v28h28V2zm2 2h24v24H4zm6 3a3 3 0 0 0-3 3 3 3 0 0 0 3 3 3 3 0 0 0 3-3 3 3 0 0 0-3-3zm2 12-7 7h6l4-4zm8 0-7 7h14z" style="fill:#373737;fill-opacity:1;stroke:none;stroke-width:2.33333325"/>
</g>
</svg>

After

Width:  |  Height:  |  Size: 2.2 KiB

+2
View File
@@ -0,0 +1,2 @@
<?xml version="1.0" encoding="utf-8"?><!-- Uploaded to: SVG Repo, www.svgrepo.com, Generator: SVG Repo Mixer Tools -->
<svg width="1rem" height="1rem" viewBox="0 0 32 32" xmlns="http://www.w3.org/2000/svg"><title>file_type_typescript</title><path d="M23.827,8.243A4.424,4.424,0,0,1,26.05,9.524a5.853,5.853,0,0,1,.852,1.143c.011.045-1.534,1.083-2.471,1.662-.034.023-.169-.124-.322-.35a2.014,2.014,0,0,0-1.67-1c-1.077-.074-1.771.49-1.766,1.433a1.3,1.3,0,0,0,.153.666c.237.49.677.784,2.059,1.383,2.544,1.095,3.636,1.817,4.31,2.843a5.158,5.158,0,0,1,.416,4.333,4.764,4.764,0,0,1-3.932,2.815,10.9,10.9,0,0,1-2.708-.028,6.531,6.531,0,0,1-3.616-1.884,6.278,6.278,0,0,1-.926-1.371,2.655,2.655,0,0,1,.327-.208c.158-.09.756-.434,1.32-.761L19.1,19.6l.214.312a4.771,4.771,0,0,0,1.35,1.292,3.3,3.3,0,0,0,3.458-.175,1.545,1.545,0,0,0,.2-1.974c-.276-.395-.84-.727-2.443-1.422a8.8,8.8,0,0,1-3.349-2.055,4.687,4.687,0,0,1-.976-1.777,7.116,7.116,0,0,1-.062-2.268,4.332,4.332,0,0,1,3.644-3.374A9,9,0,0,1,23.827,8.243ZM15.484,9.726l.011,1.454h-4.63V24.328H7.6V11.183H2.97V9.755A13.986,13.986,0,0,1,3.01,8.289c.017-.023,2.832-.034,6.245-.028l6.211.017Z" style="fill:#007acc"/></svg>

After

Width:  |  Height:  |  Size: 1.1 KiB