2023-02-26 01:30

This commit is contained in:
2023-02-26 01:30:37 +09:00
commit 9a13ccbd17
122 changed files with 32148 additions and 0 deletions

4
.gitignore vendored Normal file
View File

@@ -0,0 +1,4 @@
/node_modules/
/**/node_modules/
/build/
/**/build/

1
README.md Normal file
View File

@@ -0,0 +1 @@
# JS Examples

12
console-io/console-io.js Normal file
View File

@@ -0,0 +1,12 @@
const readline = require('readline').createInterface({
input: process.stdin,
output: process.stdout
});
readline.question('What do you think of Node.js? ', (answer) => {
// TODO: Log the answer in a database
console.log(`Thank you for your valuable feedback: ${answer}`);
readline.close();
});

11
console-io/package.json Normal file
View File

@@ -0,0 +1,11 @@
{
"name": "console-io",
"version": "1.0.0",
"description": "",
"main": "console-io.js",
"scripts": {
"exec": "node console-io.js"
},
"author": "",
"license": "ISC"
}

1
gepetto/.gitignore vendored Normal file
View File

@@ -0,0 +1 @@
/node_modules

30
gepetto/index.html Normal file
View File

@@ -0,0 +1,30 @@
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Test</title>
<script type="module" src="build/bundle.js"></script>
<style>
html,
body {
margin: 0;
border: 0;
padding: 0;
font-size: 16px;
}
</style>
</head>
<body class="grid-container">
<elex-layout>
<div slot="north">
<elex-toolbar title="Elex">Hehehe</elex-toolbar>
</div>
<p>jkjk</p>
</elex-layout>
</body>
</html>

56
gepetto/main.js Normal file
View File

@@ -0,0 +1,56 @@
const { app, BrowserWindow, Menu, MenuItem } = require('electron');
function createWindow() {
let win = new BrowserWindow({
width: 800,
height: 600,
webPreferences: {
nodeIntegration: true
}
});
createMenu();
win.loadFile('index.html');
win.webContents.openDevTools();
}
function createMenu() {
const menu = [
{
label: 'File',
submenu: [
{ label: 'Exit', role: 'quit' }
]
},
{
label: 'Edit',
submenu: [
{ label: 'Copy', role: 'copy' },
{ label: 'Cut', role: 'cut' },
{ label: 'Paste', role: 'paste' },
{ type: 'separator' },
{ label: 'Undo', role: 'undo' },
{ label: 'Redo', role: 'redo' },
]
}
];
Menu.setApplicationMenu(Menu.buildFromTemplate(menu));
}
app.whenReady().then(createWindow);
app.on('window-all-closed', () => {
if (process.platform !== 'darwin') {
app.quit();
}
});
app.on('activate', () => {
if (BrowserWindow.getAllWindows().length === 0) {
createWindow();
}
});

30
gepetto/package.json Normal file
View File

@@ -0,0 +1,30 @@
{
"name": "gepetto",
"version": "1.0.0",
"description": "",
"main": "main.js",
"scripts": {
"start": "electron .",
"clean": "rm -r ./build/*",
"build": "webpack",
"test": "echo \"Error: no test specified\" && exit 1"
},
"keywords": [],
"author": "Elex",
"license": "ELEX",
"devDependencies": {
"@babel/core": "^7.9.0",
"@babel/plugin-proposal-class-properties": "^7.8.3",
"@babel/plugin-proposal-decorators": "^7.8.3",
"@babel/preset-env": "^7.9.5",
"@babel/preset-typescript": "^7.9.0",
"babel-loader": "^8.1.0",
"electron": "^8.2.3",
"webpack": "^4.43.0",
"webpack-cli": "^3.3.11"
},
"dependencies": {
"electron": "^8.2.3",
"lit-element": "^2.3.1"
}
}

6
gepetto/src/App.ts Normal file
View File

@@ -0,0 +1,6 @@
const Toolbar = require('./Toolbar.ts')
const AppLayout = require('./AppLayout.ts')
module.exports = {
Toolbar, AppLayout
};

30
gepetto/src/AppLayout.ts Normal file
View File

@@ -0,0 +1,30 @@
import { LitElement, html, css } from 'lit-element';
export class AppLayout extends LitElement {
static get styles() {
return css`
#layout {
display: grid; width:100%; height:100%;overflow:hidden;
grid-template-rows: fitContent(64) 1fr fitContent(24);
grid-template-columns: fitContent(180) 1fr fitContent(180);
}
.north {grid-row-start:1; grid-row-end: span 1; background-color: red;
grid-column-start:1; grid-column-end: span 3;}
`;
}
render() {
return html`
<div id="layout">
<div class="north"><slot name="north"></slot></div>
<div class="south"><slot name="south"></slot></div>
<div class="east"><slot name="east"></slot></div>
<div class="west"><slot name="west"></slot></div>
<div class="center"><slot name="center"></slot></div>
</div>
`;
}
}
customElements.define('elex-layout', AppLayout);

23
gepetto/src/Toolbar.ts Normal file
View File

@@ -0,0 +1,23 @@
import { LitElement, html, css } from 'lit-element';
export class Toolbar extends LitElement {
static get properties() {
return {
title: { type: String }
};
}
static get styles() {
return css`
div {min-height: 64px;}
h1 {margin:0;padding:0;font-size:2.4rem;}
`;
}
render() {
return html`
<div><h1>${this.title}</h1></div>
`;
}
}
customElements.define('elex-toolbar', Toolbar);

12
gepetto/tsconfig.json Normal file
View File

@@ -0,0 +1,12 @@
{
"compilerOptions": {
"target": "es2017",
"module": "es2015",
"moduleResolution": "node",
"lib": [
"es2017",
"dom"
],
"experimentalDecorators": true
}
}

37
gepetto/webpack.config.js Normal file
View File

@@ -0,0 +1,37 @@
const path = require('path');
module.exports = {
target: 'electron-renderer',
entry: {
app: './src/App.ts',
},
output: {
filename: 'bundle.js',
path: path.resolve(__dirname, 'build')
},
module: {
rules: [
{
test: /\.ts$/,
include: '/src',
//exclude: '/node_modules/',
use: {
loader: 'babel-loader',
options: {
presets: ['@babel/preset-typescript'],
plugins: [
'@babel/plugin-proposal-class-properties',
['@babel/plugin-proposal-decorators',
{ decoratorsBeforeExport: true }],
]
}
}
}
]
},
mode: 'development',
watch: true,
optimization: {
minimize: true,
concatenateModules: true
},
}

View File

@@ -0,0 +1,57 @@
<html>
<head>
<script src="node_modules/chart.js/dist/Chart.bundle.min.js"></script>
</head>
<body>
<div style="width: 400px; height: 300px;">
<canvas id="chart-01" width="400" height="300"></canvas>
</div>
<script>
var ctx = document.getElementById('chart-01');
var myChart = new Chart(ctx, {
type: 'bar',
data: {
labels: ['Red', 'Blue', 'Yellow', 'Green', 'Purple', 'Orange'],
datasets: [{
label: '# of Votes',
data: [12, 19, 3, 5, 2, 3],
backgroundColor: [
'rgba(255, 99, 132, 0.2)',
'rgba(54, 162, 235, 0.2)',
'rgba(255, 206, 86, 0.2)',
'rgba(75, 192, 192, 0.2)',
'rgba(153, 102, 255, 0.2)',
'rgba(255, 159, 64, 0.2)'
],
borderColor: [
'rgba(255, 99, 132, 1)',
'rgba(54, 162, 235, 1)',
'rgba(255, 206, 86, 1)',
'rgba(75, 192, 192, 1)',
'rgba(153, 102, 255, 1)',
'rgba(255, 159, 64, 1)'
],
borderWidth: 1
}]
},
options: {
scales: {
yAxes: [{
ticks: {
beginAtZero: true
}
}]
}
}
});
setTimeout(() => {//빨간
myChart.type = 'line';
myChart.update();
}, 2500);
</script>
</body>
</html>

View File

@@ -0,0 +1,16 @@
{
"name": "getting-chartjs",
"version": "1.0.0",
"description": "",
"main": "index.js",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1"
},
"private": true,
"keywords": [],
"author": "Elex",
"license": "ELEX",
"dependencies": {
"chart.js": "^2.9.3"
}
}

View File

@@ -0,0 +1,26 @@
{
"env": {
"browser": true,
"commonjs": true,
"es6": true,
"node": true,
"shared-node-browser": true
},
"extends": [
"eslint:recommended",
"plugin:@typescript-eslint/eslint-recommended"
],
"globals": {
"Atomics": "readonly",
"SharedArrayBuffer": "readonly"
},
"parser": "@typescript-eslint/parser",
"parserOptions": {
"ecmaVersion": 2015,
"sourceType": "module"
},
"plugins": [
"@typescript-eslint"
],
"rules": {}
}

1
getting-lit-element/.gitignore vendored Normal file
View File

@@ -0,0 +1 @@
node_modules

20
getting-lit-element/dist/bundle.js vendored Normal file

File diff suppressed because one or more lines are too long

View File

@@ -0,0 +1,29 @@
<html>
<head>
<script type="module" src="./dist/bundle.js"></script>
<style>
html,
body {
margin: 0;
border: 0;
padding: 0;
}
html * {
box-sizing: content-box;
--theme-color: red;
}
span {
font-weight: bold;
}
</style>
</head>
<body>
<elex-toolbar title="Toolbar"></elex-toolbar>
<elex-component><span>Charlie</span></elex-component>
</body>
</html>

View File

@@ -0,0 +1,54 @@
const { app, BrowserWindow, Menu } = require('electron');
function createWindow() {
let win = new BrowserWindow({
width: 800,
height: 600,
webPreferences: {
nodeIntegration: true
}
});
createMenu();
win.loadFile('index.html');
win.webContents.openDevTools();
}
function createMenu() {
const menu = [
{
label: 'File',
submenu: [
{ label: 'Exit', role: 'quit' }
]
},
{
label: 'Edit',
submenu: [
{ label: 'Copy', role: 'copy' },
{ label: 'Cut', role: 'cut' },
{ label: 'Paste', role: 'paste' },
{ type: 'separator' },
{ label: 'Undo', role: 'undo' },
{ label: 'Redo', role: 'redo' },
]
}
];
Menu.setApplicationMenu(Menu.buildFromTemplate(menu));
}
app.whenReady().then(createWindow);
app.on('window-all-closed', () => {
if (process.platform !== 'darwin') {
app.quit();
}
});
app.on('activate', () => {
if (BrowserWindow.getAllWindows().length === 0) {
createWindow();
}
});

View File

@@ -0,0 +1,36 @@
{
"name": "getting-lit-element",
"version": "1.0.0",
"description": "",
"main": "main.js",
"scripts": {
"start": "electron .",
"build": "webpack",
"test": "echo \"Error: no test specified\" && exit 1"
},
"keywords": [],
"author": "",
"license": "ISC",
"devDependencies": {
"@babel/core": "^7.9.0",
"@babel/plugin-proposal-class-properties": "^7.8.3",
"@babel/plugin-proposal-decorators": "^7.8.3",
"@babel/preset-env": "^7.9.5",
"@babel/preset-typescript": "^7.9.0",
"@typescript-eslint/eslint-plugin": "^2.29.0",
"@typescript-eslint/parser": "^2.29.0",
"babel-loader": "^8.1.0",
"electron": "^8.2.3",
"eslint": "^6.8.0",
"extract-loader": "^5.0.1",
"file-loader": "^6.0.0",
"html-loader": "^1.1.0",
"ts-loader": "^7.0.1",
"typescript": "^3.8.3",
"webpack": "^4.42.1",
"webpack-cli": "^3.3.11"
},
"dependencies": {
"lit-element": "^2.3.1"
}
}

View File

@@ -0,0 +1,17 @@
import { LitElement, html, css} from 'lit-element';
export class MyComponent extends LitElement {
static get styles() {
return css`
::slotted(*) {color:red;}
p {color:blue;}
`;
}
render() {
return html`
<p>Hello, <slot></slot></p>
`;
}
}
customElements.define('elex-component', MyComponent);

View File

@@ -0,0 +1,26 @@
import { LitElement, html, css } from 'lit-element';
export class Toolbar extends LitElement {
static get properties() {
return {
title: { type: String }
};
}
static get styles() {
return css`
header {
width: 100%; height: 64px;
background-color: var(--theme-color, yellow);
}
h1 {font-size: 1.5rem;}
`;
}
render() {
return html`
<header><h1>${this.title}</h1></header>
`;
}
}
customElements.define('elex-toolbar', Toolbar);

View File

@@ -0,0 +1,6 @@
const MyComponent = require('./MyComponent.ts');
const Toolbar = require('./Toolbar.ts');
module.exports = {
MyComponent, Toolbar
};

View File

@@ -0,0 +1,13 @@
{
"compilerOptions": {
"sourceMap": true,
"target": "es2017",
"module": "es2015",
"moduleResolution": "node",
"lib": [
"es2017",
"dom"
],
"experimentalDecorators": true
}
}

View File

@@ -0,0 +1,35 @@
const path = require('path');
module.exports = {
entry: {
main: './src/index.ts',
},
output: {
filename: 'bundle.js',
//path: path.resolve(__dirname, 'build')
},
module: {
rules: [
{
test: /\.ts$/,
include: '/src',
exclude: '/node_modules/',
use: {
loader: 'babel-loader',
options: {
presets: ['@babel/preset-typescript'],
plugins: ['@babel/plugin-proposal-decorators']
}
}
}, {
test: /\.html$/, include: '/src',
use: ['file-loader?name=[name].[ext]', 'extract-loader', 'html-loader']
}
]
},
mode: 'development',
watch: true,
optimization: {
minimize: true,
concatenateModules: true
},
}

3
getting-started-electron/.gitignore vendored Normal file
View File

@@ -0,0 +1,3 @@
node_modules
src/node_modules
dist

View File

@@ -0,0 +1,55 @@
const { app, BrowserWindow, Menu, MenuItem } = require('electron');
function createWindow() {
let win = new BrowserWindow({
width: 800,
height: 600,
webPreferences: {
nodeIntegration: true
}
});
createMenu();
win.loadFile('src/index.html');
win.webContents.openDevTools();
}
function createMenu() {
const menu = [
{
label: 'File',
submenu: [
{ label: 'Exit', role: 'quit' }
]
},
{
label: 'Edit',
submenu: [
{ label: 'Copy', role: 'copy' },
{ label: 'Cut', role: 'cut' },
{ label: 'Paste', role: 'paste' },
{ type: 'separator' },
{ label: 'Undo', role: 'undo' },
{ label: 'Redo', role: 'redo' },
]
}
];
Menu.setApplicationMenu(Menu.buildFromTemplate(menu));
}
app.whenReady().then(createWindow);
app.on('window-all-closed', () => {
if (process.platform !== 'darwin') {
app.quit();
}
});
app.on('activate', () => {
if (BrowserWindow.getAllWindows().length === 0) {
createWindow();
}
});

View File

@@ -0,0 +1,24 @@
{
"name": "getting-electron",
"version": "1.0.0",
"description": "",
"main": "main.js",
"scripts": {
"start": "electron .",
"pack-linux": "electron-packager . my-test-app --out ./dist --platform-linux --asar --overwrite=true --prune=true",
"pack-windows": "electron-packager . my-test-app --out ./dist --platform=win32 --asar --overwrite=true --prune=true",
"clean": "rm -r ./dist/*",
"test": "echo \"Error: no test specified\" && exit 1"
},
"keywords": [],
"author": "",
"license": "ISC",
"devDependencies": {
"asar": "^3.0.3",
"electron": "^8.2.3",
"electron-packager": "^14.2.1"
},
"dependencies": {
"mustache": "^4.0.1"
}
}

View File

@@ -0,0 +1,48 @@
const Mustache = require('mustache');
class UIComponent {
constructor(template, options) {
this.template = template;
this.options = options;
}
apply(params = {}) {
for (let key in params) {
this.options[key] = params[key];
}
}
}
class Toolbar extends UIComponent {
constructor() {
super(`<h1>{{title}}</h1>`, {
title: "empty"
});
}
apply(params = {}) {
super.apply(params);
document.querySelector('#toolbar').innerHTML
= Mustache.render(this.template, this.options);
}
}
class Statusbar extends UIComponent {
constructor() {
super(`<span class="current-time">{{currentDateTime}}</span>`, {
currentDateTime: new Date().toLocaleString()
});
}
apply(params = {}) {
super.apply(params);
this.options['currentDateTime'] = new Date().toLocaleString();
document.querySelector('#statusbar').innerHTML
= Mustache.render(this.template, this.options);
}
}
module.exports = {
Toolbar, Statusbar
};

View File

@@ -0,0 +1,68 @@
* {
box-sizing: content-box;
}
html,
body {
margin: 0;
padding: 0;
border: 0;
display: block;
width: 100%;
height: 100%;
}
html *,
body * {
font-size: 16px;
}
body > .container {
width: 100%;
height: 100%;
background-color: #f4f4f4;
}
.grid-container {
display: grid;
grid-template-rows: 64px 1fr 24px;
grid-template-columns: 180px 1fr;
}
#toolbar {
grid-row-start: 1;
grid-row-end: 2;
grid-column-start: 1;
grid-column-end: 3;
background-color: yellow;
}
#toolbar * {
margin-top: 0;
margin-bottom: 0;
}
#side-pane {
grid-row-start: 2;
grid-row-end: 3;
grid-column-start: 1;
grid-column-end: 2;
background-color: lightsteelblue;
}
#content-pane {
grid-row-start: 2;
grid-row-end: 3;
grid-column-start: 2;
grid-column-end: 3;
}
#statusbar {
grid-row-start: 3;
grid-row-end: 4;
grid-column-start: 1;
grid-column-end: 3;
background-color: lightgray;
}
#statusbar * {
font-size: 0.85rem;
color: grey;
}
#statusbar > .current-time {
float: right;
}
p {
color: red;
}

View File

@@ -0,0 +1,36 @@
<!DOCTYPE html>
<html lang="ko">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Test</title>
<link rel="stylesheet" href="index.css" />
<script>
const { Toolbar, Statusbar } = require('./components');
let uiToolbar = new Toolbar();
let uiStatusbar = new Statusbar();
window.addEventListener('DOMContentLoaded', () => {
//alert('Hello');
uiToolbar.apply({ title: "Hahaha" });
setInterval(() => {
uiStatusbar.apply();
}, 1000);
});
</script>
</head>
<body class="grid-container">
<div id="toolbar"></div>
<div id="side-pane">sidebar</div>
<div id="contene-pane">
<p>Hello~</p>
<button onclick="uiToolbar.apply({title: 'kiki'})">Click</button>
</div>
<div id="statusbar"></div>
</body>
</html>

1
getting-started/.gitignore vendored Normal file
View File

@@ -0,0 +1 @@
node_modules

9
getting-started/.vscode/settings.json vendored Normal file
View File

@@ -0,0 +1,9 @@
{
"editor.fontFamily": "'Source Code Pro','Droid Sans Mono', 'monospace', monospace, 'Droid Sans Fallback'",
"telemetry.enableCrashReporter": false,
"telemetry.enableTelemetry": false,
"files.autoGuessEncoding": true,
"files.autoSave": "onFocusChange",
"files.insertFinalNewline": true,
"files.trimTrailingWhitespace": true
}

View File

@@ -0,0 +1,26 @@
/*
https://nodejs.dev/
*/
/**
* 콘솔 출력
*/
console.log("Hello,");
setTimeout(() => {
console.log(" world.");
}, 1000);
const x = 100, y = 120;
console.log(x, y);
const age = 24, name = "Charlie";
console.log("%s's age is %d.", name, age);
// 스택 트레이스 출력
console.trace();
// 시간 측정
console.time("myStopwatch");
// do something ..
console.timeEnd("myStopwatch");

View File

@@ -0,0 +1,17 @@
// 프로세스 종료 이벤트 수신
process.on('SIGTERM', function () {
console.log("bye~");
});
/* process.on("SIGKILL", function () {
console.log("앱 죽어.");
process.exitCode = 1;
}); */
// 환경 변수
console.log(process.env.PATH);
console.log(process.env.NODE_ENV); // development
// 프로그램 매개변수
process.argv.slice(2).forEach((val, index) => {
console.log(`${index}: ${val}`)
})

View File

@@ -0,0 +1,10 @@
const ProgressBar = require("progress");
//import { ProgressBar } from "progress";
const bar = new ProgressBar(':percent', { total: 100 });
const timer = setInterval(() => {
bar.tick();
if (bar.complete) {
clearInterval(timer);
}
}, 10);

View File

@@ -0,0 +1,12 @@
const readline = require('readline').createInterface({
input: process.stdin,
output: process.stdout
});
readline.question("Choose?", choice => {
console.log(`Your choice is ${choice}.`);
readline.close();
});

View File

@@ -0,0 +1,7 @@
const readline = require('readline-sync');
let id = readline.question("ID?");
let pw = readline.question("Password?", { hideEchoBack: true });
console.log(`Your ID is ${id}, and password is ${pw}.`);

View File

@@ -0,0 +1,6 @@
const person = {
age: 34,
name: "Steve"
};
module.exports = person;

View File

@@ -0,0 +1,3 @@
const person = require('./06_another_module');
console.log(person);

View File

@@ -0,0 +1,24 @@
let fun0 = function () {
console.log("Hello");
};
let fun2 = function (param1, param2) {
console.log(param1, param2);
};
setTimeout(fun0, 50);
setTimeout(fun2, 100, 1, 2);
const timerId = setTimeout(() => { console.log("Hi"); }, 2000);
clearTimeout(timerId);
/**
*/
const intervalId = setInterval(fun0, 100);
setTimeout(() => { clearInterval(intervalId) }, 1000);
/**
*/
setImmediate(() => { });
process.nextTick(() => { });

View File

@@ -0,0 +1,21 @@
let fun1 = async function () {
let someJobIsDone = true;
let i = 0;
while (i < 100000000) {
i++;
}
return new Promise((resolve, reject) => {
if (someJobIsDone) {
resolve('ok');
} else {
reject('bad');
}
});
};
fun1()
.then(msg => console.log(msg))
.catch(err => console.error(err));
console.log("Hi");

View File

@@ -0,0 +1,11 @@
const Events = require("events");
const eventEmitter = new Events();
eventEmitter.on('start', () => { console.log("onStart") });
eventEmitter.emit('start');
// one time listener
eventEmitter.once('start', () => { console.log("onStart") });
eventEmitter.off('start');

View File

@@ -0,0 +1,23 @@
const http = require('http');
const port = 19090;
const server = http.createServer((req, resp) => {
let data = [];
req.on('data', (chunk) => {
data.push(chunk);
});
req.on('end', () => {
resp.statusCode = 200;
resp.setHeader('Content-Type', 'text/html');
resp.end(`<p>Hello, <b>${JSON.parse(data).message}</b>!</p>`);
});
});
server.listen(port, () => {
console.log('listening on ' + port);
});
process.on('SIGINT', () => {
console.log('closing.. ');
server.close();
});

View File

@@ -0,0 +1,22 @@
const https = require('https');
const options = {
hostname: 'www.elex-project.com',
port: 443,
path: '/',
method: 'GET',
headers: { 'User-Agent': 'Elex Node' }
};
const request = https.request(options, (response) => {
console.log(`httpStatus: ${response.statusCode}`);
response.on('data', (data) => {
process.stdout.write(data);
});
});
request.on('error', (error) => {
console.error(error);
});
request.end();

View File

@@ -0,0 +1,33 @@
const https = require('https');
const body = JSON.stringify({
id: 1234,
message: 'Hello'
});
const options = {
hostname: 'www.elex-project.com',
port: 443,
path: '/',
method: 'POST',
headers: {
'User-Agent': 'Elex Node',
'Content-Type': `application/json`,
'Content-Length': body.length
}
};
const request = https.request(options, (response) => {
console.log(`httpStatus: ${response.statusCode}`);
response.on('data', (data) => {
process.stdout.write(data);
});
});
request.on('error', (error) => {
console.error(error);
});
request.write(body);
request.end();

View File

@@ -0,0 +1,15 @@
const axios = require('axios').create({
headers: { 'User-Agent': 'Elex Node' }
});
axios
.post('https://www.elex-project.com/', {
id: 1234, message: 'Hello~'
})
.then((response) => {
console.log(`httpStatus: ${response.statusCode}`);
console.log(response.data);
})
.catch((error) => {
console.error(error);
});

View File

@@ -0,0 +1,18 @@
const request = require('request');
request.post(
'http://localhost:19090',
{
headers: { 'User-Agent': 'Elex Node' },
json: { id: 1234, message: 'Charlie' }
},
(error, response, body) => {
if (error) {
console.error(error);
} else {
console.log(`httpStatus: ${response.statusCode}`);
console.log(body);
}
}
);

View File

@@ -0,0 +1,34 @@
const fs = require('fs');
/**
get file descriptor async
*/
fs.open('sample.txt', 'r', (error, fd) => {
console.log(fd);
});
/**
get file descriptor sync
*/
const fd = fs.openSync('sample.txt', 'r');
console.log(fd);
/**
get file stat async
*/
fs.stat('sample.txt', (error, stat) => {
if (error) {
console.error(error);
} else {
console.log(stat);
}
});
/**
get file stat sync
*/
const stat = fs.statSync('sample.txt');
console.log(stat);
console.log(stat.isDirectory());
console.log(stat.isSymbolicLink());
console.log(stat.size);

View File

@@ -0,0 +1,26 @@
const path = require('path');
const p = '/var/sample.txt';
// containing dir
console.log(path.dirname(p));
// filename
console.log(path.basename(p));
// ext
console.log(path.extname(p));
// file name without ext
console.log(path.basename(p, path.extname(p)));
// build abs path
const userName = 'steve';
console.log(
path.resolve('/', 'users', userName, 'notes.txt')
);
// full path with cwd
console.log(
path.resolve('sample.txt')
);
// normalize
console.log(
path.resolve('/users/steve/..//sample.txt')
);

View File

@@ -0,0 +1,41 @@
const fs = require('fs');
// read
fs.readFile('sample.txt', (error, data) => {
if (error) {
console.error(error);
} else {
console.log(data);
}
});
// read sync
try {
const data = fs.readFileSync('sample.txt');
console.log(data);
} catch (error) {
console.error(error);
}
// write
const content = 'Test Text';
fs.writeFile('test.txt', content, (error) => {
if (error) {
console.error(error);
}
});
// write sync, append mode
try {
fs.writeFileSync('test.txt', content, { flag: 'a+' });
} catch (error) {
console.error(error);
}
// another append mode
fs.appendFile('test.txt', content, (error) => {
if (error) {
console.error(error);
}
});

View File

@@ -0,0 +1,41 @@
const fs = require('fs');
const path = require('path');
const folder = '/home/elex/nodeTest';
try {
if (!fs.existsSync(folder)) {
fs.mkdirSync(folder);
}
} catch (error) {
console.error(error);
}
let ls = fs.readdirSync(folder)
.map((filename) => {
return path.join(folder, filename);
});
console.log(ls);
// with a filter
let ls2 = fs.readdirSync(folder)
.map((filename) => {
return path.join(folder, filename);
}).filter((filename) => {
return fs.lstatSync(filename).isFile();
});
console.log(ls2);
// a folder exists and has a permission
fs.accessSync(folder)
// rename
fs.rename('/home/elex/nodeTest/새 텍스트 파일', '/home/elex/nodeTest/test.txt', (error) => {
console.error(error);
});
// delete a folder
fs.rmdir(folder);

18
getting-started/19_os.js Normal file
View File

@@ -0,0 +1,18 @@
const os = require('os');
console.log(os.arch());
console.log(os.cpus());
console.log(os.endianness());
console.log(os.freemem());
console.log(os.homedir());
console.log(os.hostname());
console.log(os.loadavg());
console.log(os.networkInterfaces());
console.log(os.platform());
console.log(os.release());
console.log(os.tmpdir());
console.log(os.totalmem());
console.log(os.type());
console.log(os.uptime());
console.log(os.userInfo());

View File

@@ -0,0 +1,23 @@
// 0으로 초기화됨.
const buffer = Buffer.alloc(1024);
//or 초기화 없음
// buffer = Buffer.allocUnsafe(1024);
buffer.write('Hi.');
console.log(buffer.toString());
const buff = Buffer.from('Hello');
console.log(buff[0]);
console.log(buff.length);
console.log(buff.toString());
for (const c of buff) {
console.log(c);
}
// copy
let buf2 = Buffer.alloc(2);
buffer.copy(buf2, 0, 0, 2);
// slice
console.log(buffer.slice(0, 2).toString());

View File

@@ -0,0 +1,25 @@
const fs = require('fs');
const Stream = require('stream')
const readableStream = new Stream.Readable(
{ read() { } }
);
const readableStream2 = fs.createReadStream('sample.txt');
const writableStream = new Stream.Writable(
{
write(chunk, encoding, next) {
console.log(chunk.toString())
next()
}
}
);
readableStream.pipe(writableStream);
readableStream.on('readable', () => {
console.log(readableStream.read());
});
writableStream.write('Hello...');
writableStream.end();

View File

@@ -0,0 +1,21 @@
{
"name": "getting-started",
"version": "1.0.0",
"description": "",
"main": "index.js",
"scripts": {
"eslint": "npx eslint --init",
"test": "echo \"Error: no test specified\" && exit 1"
},
"author": "Elex<mysticzizone@gmail.com>",
"license": "ISC",
"private": true,
"dependencies": {
"progress": "^2.0.3",
"readline-sync": "^1.4.10"
},
"devDependencies": {
"axios": "^0.19.2",
"eslint": "^6.8.0"
}
}

View File

@@ -0,0 +1,2 @@
Hello, Hahaha.
Test Text

1
getting-started/test.txt Normal file
View File

@@ -0,0 +1 @@
Test TextTest Text

1
getting-typescript/.gitignore vendored Normal file
View File

@@ -0,0 +1 @@
node_modules

View File

@@ -0,0 +1,14 @@
{
"name": "getting-typescript",
"version": "1.0.0",
"description": "",
"main": "index.js",
"scripts": {
"watch": "tsc --watch",
"test": "echo \"Error: no test specified\" && exit 1"
},
"keywords": [],
"author": "Elex",
"license": "ISC",
"private": true
}

View File

@@ -0,0 +1,9 @@
"use strict";
class Person {
constructor(name) {
this.name = name;
}
}
;
const person = new Person("Charlie");
console.log(`Hello, ${person.name}.`);

View File

@@ -0,0 +1,10 @@
class Person {
name: string;
constructor(name: string) {
this.name = name;
}
};
const person: Person = new Person("Charlie");
console.log(`Hello, ${person.name}.`);

View File

@@ -0,0 +1,18 @@
{
"compilerOptions": {
"strict": true,
"target": "ES6",
"lib": [
"ES2015",
"DOM"
],
"module": "CommonJS"
},
"include": [
"src/**/*.ts"
],
"exclude": [
"node_modules"
],
"outDir": "./out"
}

23
hello-js/index.html Normal file
View File

@@ -0,0 +1,23 @@
<!doctype html>
<html>
<head>
<title>Test</title>
<style>
.test {
display: inline-block;
}
.test p {
background-color: aqua;
}
</style>
</head>
<body style="background-color: white;margin:0; overflow: hidden;">
<div class="test">
<p>Hello</p>
</div>
</body>
</html>

13
hello-js/package.json Normal file
View File

@@ -0,0 +1,13 @@
{
"name": "hello-js",
"version": "1.0.0",
"description": "",
"main": "index.js",
"scripts": {
"run01": "node test01.js",
"test": "echo \"Error: no test specified\" && exit 1"
},
"keywords": [],
"author": "",
"license": "ISC"
}

17
hello-js/test01.js Normal file
View File

@@ -0,0 +1,17 @@
let websocket = new WebSocket("wss://echo.websocket.org/");
websocket.onopen((event) => {
websocket.send("Hello");
});
websocket.onclose(() => {
});
websocket.onmessage((event) => {
console.log(event.data);
});
websocket.onerror(() => {
});

View File

@@ -0,0 +1,21 @@
const syntaxHighlight = require('@11ty/eleventy-plugin-syntaxhighlight');
module.exports = function (eleventyConfig) {
eleventyConfig.addPlugin(syntaxHighlight);
eleventyConfig.addPassthroughCopy('docs-src/docs.css');
eleventyConfig.addPassthroughCopy('docs-src/.nojekyll');
eleventyConfig.addPassthroughCopy(
'node_modules/@webcomponents/webcomponentsjs'
);
eleventyConfig.addPassthroughCopy('node_modules/lit/polyfill-support.js');
return {
dir: {
input: 'docs-src',
output: 'docs',
},
templateExtensionAliases: {
'11ty.cjs': '11ty.js',
'11tydata.cjs': '11tydata.js',
},
};
};

View File

@@ -0,0 +1,5 @@
node_modules/*
docs/*
docs-src/*
rollup-config.js
custom-elements.json

View File

@@ -0,0 +1,51 @@
{
"root": true,
"extends": [
"eslint:recommended",
"plugin:@typescript-eslint/eslint-recommended",
"plugin:@typescript-eslint/recommended"
],
"parser": "@typescript-eslint/parser",
"parserOptions": {
"ecmaVersion": 2020,
"sourceType": "module"
},
"plugins": ["@typescript-eslint"],
"env": {
"browser": true
},
"rules": {
"no-prototype-builtins": "off",
"@typescript-eslint/ban-types": "off",
"@typescript-eslint/explicit-function-return-type": "off",
"@typescript-eslint/explicit-module-boundary-types": "off",
"@typescript-eslint/no-explicit-any": "error",
"@typescript-eslint/no-empty-function": "off",
"@typescript-eslint/no-non-null-assertion": "off",
"@typescript-eslint/no-unused-vars": [
"warn",
{
"argsIgnorePattern": "^_"
}
]
},
"overrides": [
{
"files": ["rollup.config.js", "web-test-runner.config.js"],
"env": {
"node": true
}
},
{
"files": [
"*_test.ts",
"**/custom_typings/*.ts",
"packages/lit-ssr/src/test/integration/tests/**",
"packages/lit-ssr/src/lib/util/parse5-utils.ts"
],
"rules": {
"@typescript-eslint/no-explicit-any": "off"
}
}
]
}

9
lit-element-starter-ts/.gitignore vendored Normal file
View File

@@ -0,0 +1,9 @@
node_modules/
/lib/
/test/
custom-elements.json
# top level source
my-element.js
my-element.js.map
my-element.d.ts
my-element.d.ts.map

View File

@@ -0,0 +1,7 @@
{
"trailingComma": "es5",
"tabWidth": 2,
"singleQuote": true,
"bracketSpacing": false,
"arrowParens": "always"
}

View File

@@ -0,0 +1,9 @@
{
// See https://go.microsoft.com/fwlink/?LinkId=827846 to learn about workspace recommendations.
// Extension identifier format: ${publisher}.${name}. Example: vscode.csharp
// List of extensions which should be recommended for users of this workspace.
"recommendations": ["runem.lit-plugin"],
// List of extensions recommended by VS Code that should not be recommended for users of this workspace.
"unwantedRecommendations": []
}

View File

@@ -0,0 +1,28 @@
BSD 3-Clause License
Copyright (c) 2019 Google LLC. All rights reserved.
Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions are met:
1. Redistributions of source code must retain the above copyright notice, this
list of conditions and the following disclaimer.
2. Redistributions in binary form must reproduce the above copyright notice,
this list of conditions and the following disclaimer in the documentation
and/or other materials provided with the distribution.
3. Neither the name of the copyright holder nor the names of its
contributors may be used to endorse or promote products derived from
this software without specific prior written permission.
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.

View File

@@ -0,0 +1,123 @@
# LitElement TypeScript starter
This project includes a sample component using LitElement with TypeScript.
## Setup
Install dependencies:
```bash
npm i
```
## Build
This sample uses the TypeScript compiler to produce JavaScript that runs in modern browsers.
To build the JavaScript version of your component:
```bash
npm run build
```
To watch files and rebuild when the files are modified, run the following command in a separate shell:
```bash
npm run build:watch
```
Both the TypeScript compiler and lit-analyzer are configured to be very strict. You may want to change `tsconfig.json` to make them less strict.
## Testing
This sample uses modern-web.dev's
[@web/test-runner](https://www.npmjs.com/package/@web/test-runner) along with
Mocha, Chai, and some related helpers for testing. See the
[modern-web.dev testing documentation](https://modern-web.dev/docs/test-runner/overview) for
more information.
Tests can be run with the `test` script:
```bash
npm test
```
## Dev Server
This sample uses modern-web.dev's [@web/dev-server](https://www.npmjs.com/package/@web/dev-server) for previewing the project without additional build steps. Web Dev Server handles resolving Node-style "bare" import specifiers, which aren't supported in browsers. It also automatically transpiles JavaScript and adds polyfills to support older browsers. See [modern-web.dev's Web Dev Server documentation](https://modern-web.dev/docs/dev-server/overview/) for more information.
To run the dev server and open the project in a new browser tab:
```bash
npm run serve
```
There is a development HTML file located at `/dev/index.html` that you can view at http://localhost:8000/dev/index.html.
## Editing
If you use VS Code, we highly recommend the [lit-plugin extension](https://marketplace.visualstudio.com/items?itemName=runem.lit-plugin), which enables some extremely useful features for lit-html templates:
- Syntax highlighting
- Type-checking
- Code completion
- Hover-over docs
- Jump to definition
- Linting
- Quick Fixes
The project is setup to recommend lit-plugin to VS Code users if they don't already have it installed.
## Linting
Linting of TypeScript files is provided by [ESLint](eslint.org) and [TypeScript ESLint](https://github.com/typescript-eslint/typescript-eslint). In addition, [lit-analyzer](https://www.npmjs.com/package/lit-analyzer) is used to type-check and lint lit-html templates with the same engine and rules as lit-plugin.
The rules are mostly the recommended rules from each project, but some have been turned off to make LitElement usage easier. The recommended rules are pretty strict, so you may want to relax them by editing `.eslintrc.json` and `tsconfig.json`.
To lint the project run:
```bash
npm run lint
```
## Formatting
[Prettier](https://prettier.io/) is used for code formatting. It has been pre-configured according to the Polymer Project's style. You can change this in `.prettierrc.json`.
Prettier has not been configured to run when committing files, but this can be added with Husky and and `pretty-quick`. See the [prettier.io](https://prettier.io/) site for instructions.
## Static Site
This project includes a simple website generated with the [eleventy](11ty.dev) static site generator and the templates and pages in `/docs-src`. The site is generated to `/docs` and intended to be checked in so that GitHub pages can serve the site [from `/docs` on the master branch](https://help.github.com/en/github/working-with-github-pages/configuring-a-publishing-source-for-your-github-pages-site).
To enable the site go to the GitHub settings and change the GitHub Pages &quot;Source&quot; setting to &quot;master branch /docs folder&quot;.</p>
To build the site, run:
```bash
npm run docs
```
To serve the site locally, run:
```bash
npm run docs:serve
```
To watch the site files, and re-build automatically, run:
```bash
npm run docs:watch
```
The site will usually be served at http://localhost:8000.
## Bundling and minification
This starter project doesn't include any build-time optimizations like bundling or minification. We recommend publishing components as unoptimized JavaScript modules, and performing build-time optimizations at the application level. This gives build tools the best chance to deduplicate code, remove dead code, and so on.
For information on building application projects that include LitElement components, see [Build for production](https://lit.dev/docs/tools/production/) on the Lit site.
## More information
See [Get started](https://lit.dev/docs/getting-started/) on the Lit site for more information.

View File

@@ -0,0 +1 @@
This directory contains HTML files containing your element for development. By running `npm run build:watch` and `npm run serve` you can edit and see changes without bundling.

View File

@@ -0,0 +1,22 @@
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8" />
<title>&lt;my-element> Demo</title>
<script src="../node_modules/@webcomponents/webcomponentsjs/webcomponents-loader.js"></script>
<script src="../node_modules/lit/polyfill-support.js"></script>
<script type="module" src="../my-element.js"></script>
<style>
p {
border: solid 1px blue;
padding: 8px;
}
</style>
</head>
<body>
<my-element>
<p>This is child content</p>
</my-element>
</body>
</html>

View File

@@ -0,0 +1,2 @@
# Ignore files with a leading underscore; useful for e.g. readmes in source documentation
_*.md

View File

@@ -0,0 +1,7 @@
This directory contains the sources for the static site contained in the /docs/ directory. The site is based on the [eleventy](11ty.dev) static site generator.
The site is intended to be used with GitHub pages. To enable the site go to the GitHub settings and change the GitHub Pages "Source" setting to "master branch /docs folder".
To view the site locally, run `npm run docs:serve`.
To edit the site, add to or edit the files in this directory then run `npm run docs` to build the site. The built files must be checked in and pushed to GitHub to appear on GitHub pages.

View File

@@ -0,0 +1,16 @@
/**
* @license
* Copyright 2021 Google LLC
* SPDX-License-Identifier: BSD-3-Clause
*/
const fs = require('fs');
module.exports = () => {
const customElements = JSON.parse(
fs.readFileSync('custom-elements.json', 'utf-8')
);
return {
customElements,
};
};

View File

@@ -0,0 +1,43 @@
const page = require('./page.11ty.cjs');
const relative = require('./relative-path.cjs');
/**
* This template extends the page template and adds an examples list.
*/
module.exports = function (data) {
return page({
...data,
content: renderExample(data),
});
};
const renderExample = ({name, content, collections, page}) => {
return `
<h1>Example: ${name}</h1>
<section class="examples">
<nav class="collection">
<ul>
${
collections.example === undefined
? ''
: collections.example
.map(
(post) => `
<li class=${post.url === page.url ? 'selected' : ''}>
<a href="${relative(
page.url,
post.url
)}">${post.data.description.replace('<', '&lt;')}</a>
</li>
`
)
.join('')
}
</ul>
</nav>
<div>
${content}
</div>
</section>
`;
};

View File

@@ -0,0 +1,9 @@
module.exports = function (data) {
return `
<footer>
<p>
Made with
<a href="https://github.com/PolymerLabs/lit-starter-ts">lit-starter-ts</a>
</p>
</footer>`;
};

View File

@@ -0,0 +1,7 @@
module.exports = function (data) {
return `
<header>
<h1>&lt;my-element></h1>
<h2>A web component just for me.</h2>
</header>`;
};

View File

@@ -0,0 +1,11 @@
const relative = require('./relative-path.cjs');
module.exports = function ({page}) {
return `
<nav>
<a href="${relative(page.url, '/')}">Home</a>
<a href="${relative(page.url, '/examples/')}">Examples</a>
<a href="${relative(page.url, '/api/')}">API</a>
<a href="${relative(page.url, '/install/')}">Install</a>
</nav>`;
};

View File

@@ -0,0 +1,37 @@
const header = require('./header.11ty.cjs');
const footer = require('./footer.11ty.cjs');
const nav = require('./nav.11ty.cjs');
const relative = require('./relative-path.cjs');
module.exports = function (data) {
const {title, page, content} = data;
return `
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>${title}</title>
<link rel="stylesheet" href="${relative(page.url, '/docs.css')}">
<link rel="stylesheet" href="https://fonts.googleapis.com/css?family=Open+Sans:300,400,600|Roboto+Mono">
<link href="${relative(page.url, '/prism-okaidia.css')}" rel="stylesheet" />
<script src="/node_modules/@webcomponents/webcomponentsjs/webcomponents-loader.js"></script>
<script src="/node_modules/lit/polyfill-support.js"></script>
<script type="module" src="${relative(
page.url,
'/my-element.bundled.js'
)}"></script>
</head>
<body>
${header()}
${nav(data)}
<div id="main-wrapper">
<main>
${content}
</main>
</div>
${footer()}
</body>
</html>`;
};

View File

@@ -0,0 +1,9 @@
const path = require('path').posix;
module.exports = (base, p) => {
const relativePath = path.relative(base, p);
if (p.endsWith('/') && !relativePath.endsWith('/') && relativePath !== '') {
return relativePath + '/';
}
return relativePath;
};

View File

@@ -0,0 +1,90 @@
/**
* This page generates its content from the custom-element.json file as read by
* the _data/api.11tydata.js script.
*/
module.exports = class Docs {
data() {
return {
layout: 'page.11ty.cjs',
title: '<my-element> ⌲ Docs',
};
}
render(data) {
const customElements = data.api['11tydata'].customElements;
const tags = customElements.tags;
return `
<h1>API</h1>
${tags
.map(
(tag) => `
<h2>&lt;${tag.name}></h2>
<div>
${tag.description}
</div>
${renderTable(
'Attributes',
['name', 'description', 'type', 'default'],
tag.attributes
)}
${renderTable(
'Properties',
['name', 'attribute', 'description', 'type', 'default'],
tag.properties
)}
${
/*
* Methods are not output by web-component-analyzer yet (a bug), so
* this is a placeholder so that at least _something_ will be output
* when that is fixed, and element maintainers will hopefully have a
* signal to update this file to add the neccessary columns.
*/
renderTable('Methods', ['name', 'description'], tag.methods)
}
${renderTable('Events', ['name', 'description'], tag.events)}
${renderTable('Slots', ['name', 'description'], tag.slots)}
${renderTable(
'CSS Shadow Parts',
['name', 'description'],
tag.cssParts
)}
${renderTable(
'CSS Custom Properties',
['name', 'description'],
tag.cssProperties
)}
`
)
.join('')}
`;
}
};
/**
* Renders a table of data, plucking the given properties from each item in
* `data`.
*/
const renderTable = (name, properties, data) => {
if (data === undefined) {
return '';
}
return `
<h3>${name}</h3>
<table>
<tr>
${properties.map((p) => `<th>${capitalize(p)}</th>`).join('')}
</tr>
${data
.map(
(i) => `
<tr>
${properties.map((p) => `<td>${i[p]}</td>`).join('')}
</tr>
`
)
.join('')}
</table>
`;
};
const capitalize = (s) => s[0].toUpperCase() + s.substring(1);

View File

@@ -0,0 +1,162 @@
* {
box-sizing: border-box;
}
body {
margin: 0;
color: #333;
font-family: 'Open Sans', arial, sans-serif;
min-width: min-content;
min-height: 100vh;
font-size: 18px;
display: flex;
flex-direction: column;
align-items: stretch;
}
#main-wrapper {
flex-grow: 1;
}
main {
max-width: 1024px;
margin: 0 auto;
}
a:visited {
color: inherit;
}
header {
width: 100%;
display: flex;
flex-direction: column;
align-items: center;
justify-content: center;
height: 360px;
margin: 0;
background: linear-gradient(0deg, rgba(9,9,121,1) 0%, rgba(0,212,255,1) 100%);
color: white;
}
footer {
width: 100%;
min-height: 120px;
background: gray;
color: white;
display: flex;
flex-direction: column;
justify-content: center;
padding: 12px;
margin-top: 64px;
}
h1 {
font-size: 2.5em;
font-weight: 400;
}
h2 {
font-size: 1.6em;
font-weight: 300;
margin: 64px 0 12px;
}
h3 {
font-weight: 300;
}
header h1 {
width: auto;
font-size: 2.8em;
margin: 0;
}
header h2 {
width: auto;
margin: 0;
}
nav {
display: grid;
width: 100%;
max-width: 100%;
grid-template-columns: repeat(auto-fit, 240px);
justify-content: center;
border-bottom: 1px solid #efefef;
}
nav > a {
color: #444;
display: block;
flex: 1;
font-size: 18px;
padding: 20px 0;
text-align: center;
text-decoration: none;
}
nav > a:hover {
text-decoration: underline;
}
nav.collection {
border: none;
}
nav.collection > ul {
padding: 0;
list-style: none;
}
nav.collection > ul > li {
padding: 4px 0;
}
nav.collection > ul > li.selected {
font-weight: 600;
}
nav.collection a {
text-decoration: none;
}
nav.collection a:hover {
text-decoration: underline;
}
section.columns {
display: grid;
grid-template-columns: repeat(auto-fit, minmax(400px, 488px));
grid-gap: 48px;
justify-content: center;
}
section.columns > div {
flex: 1;
}
section.examples {
display: grid;
grid-template-columns: 240px minmax(400px, 784px);
grid-gap: 48px;
justify-content: center;
}
section.examples h2:first-of-type {
margin-top: 0;
}
table {
width: 100%;
border-collapse: collapse;
}
th {
font-weight: 600;
}
td, th {
border: solid 1px #aaa;
padding: 4px;
text-align: left;
}

View File

@@ -0,0 +1,34 @@
---
layout: example.11ty.cjs
title: <my-element> ⌲ Examples ⌲ Basic
tags: example
name: Basic
description: A basic example
---
<style>
my-element p {
border: solid 1px blue;
padding: 8px;
}
</style>
<my-element>
<p>This is child content</p>
</my-element>
<h3>CSS</h3>
```css
p {
border: solid 1px blue;
padding: 8px;
}
```
<h3>HTML</h3>
```html
<my-element>
<p>This is child content</p>
</my-element>
```

View File

@@ -0,0 +1,15 @@
---
layout: example.11ty.cjs
title: <my-element> ⌲ Examples ⌲ Name Property
tags: example
name: Name Property
description: Setting the name property
---
<my-element name="Earth"></my-element>
<h3>HTML</h3>
```html
<my-element name="Earth"></my-element>
```

View File

@@ -0,0 +1,76 @@
---
layout: page.11ty.cjs
title: <my-element> ⌲ Home
---
# &lt;my-element>
`<my-element>` is an awesome element. It's a great introduction to building web components with LitElement, with nice documentation site as well.
## As easy as HTML
<section class="columns">
<div>
`<my-element>` is just an HTML element. You can it anywhere you can use HTML!
```html
<my-element></my-element>
```
</div>
<div>
<my-element></my-element>
</div>
</section>
## Configure with attributes
<section class="columns">
<div>
`<my-element>` can be configured with attributed in plain HTML.
```html
<my-element name="HTML"></my-element>
```
</div>
<div>
<my-element name="HTML"></my-element>
</div>
</section>
## Declarative rendering
<section class="columns">
<div>
`<my-element>` can be used with declarative rendering libraries like Angular, React, Vue, and lit-html
```js
import {html, render} from 'lit-html';
const name = 'lit-html';
render(
html`
<h2>This is a &lt;my-element&gt;</h2>
<my-element .name=${name}></my-element>
`,
document.body
);
```
</div>
<div>
<h2>This is a &lt;my-element&gt;</h2>
<my-element name="lit-html"></my-element>
</div>
</section>

View File

@@ -0,0 +1,32 @@
---
layout: page.11ty.cjs
title: <my-element> ⌲ Install
---
# Install
`<my-element>` is distributed on npm, so you can install it locally or use it via npm CDNs like unpkg.com.
## Local Installation
```bash
npm i my-element
```
## CDN
npm CDNs like [unpkg.com]() can directly serve files that have been published to npm. This works great for standard JavaScript modules that the browser can load natively.
For this element to work from unpkg.com specifically, you need to include the `?module` query parameter, which tells unpkg.com to rewrite "bare" module specifiers to full URLs.
### HTML
```html
<script type="module" src="https://unpkg.com/my-element?module"></script>
```
### JavaScript
```html
import {MyElement} from 'https://unpkg.com/my-element?module';
```

View File

@@ -0,0 +1,3 @@
{
"type": "commonjs"
}

View File

View File

@@ -0,0 +1,139 @@
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title><my-element> ⌲ Docs</title>
<link rel="stylesheet" href="../docs.css">
<link rel="stylesheet" href="https://fonts.googleapis.com/css?family=Open+Sans:300,400,600|Roboto+Mono">
<link href="../prism-okaidia.css" rel="stylesheet" />
<script src="/node_modules/@webcomponents/webcomponentsjs/webcomponents-loader.js"></script>
<script src="/node_modules/lit/polyfill-support.js"></script>
<script type="module" src="../my-element.bundled.js"></script>
</head>
<body>
<header>
<h1>&lt;my-element></h1>
<h2>A web component just for me.</h2>
</header>
<nav>
<a href="../">Home</a>
<a href="../examples/">Examples</a>
<a href="">API</a>
<a href="../install/">Install</a>
</nav>
<div id="main-wrapper">
<main>
<h1>API</h1>
<h2>&lt;my-element></h2>
<div>
An example element.
</div>
<h3>Attributes</h3>
<table>
<tr>
<th>Name</th><th>Description</th><th>Type</th><th>Default</th>
</tr>
<tr>
<td>name</td><td>The name to say "Hello" to.</td><td>string</td><td>"World"</td>
</tr>
<tr>
<td>count</td><td>The number of times the button has been clicked.</td><td>number</td><td>0</td>
</tr>
</table>
<h3>Properties</h3>
<table>
<tr>
<th>Name</th><th>Attribute</th><th>Description</th><th>Type</th><th>Default</th>
</tr>
<tr>
<td>name</td><td>name</td><td>The name to say "Hello" to.</td><td>string</td><td>"World"</td>
</tr>
<tr>
<td>count</td><td>count</td><td>The number of times the button has been clicked.</td><td>number</td><td>0</td>
</tr>
<tr>
<td>renderRoot</td><td>undefined</td><td>Node or ShadowRoot into which element DOM should be rendered. Defaults
to an open shadowRoot.</td><td>HTMLElement | ShadowRoot</td><td>undefined</td>
</tr>
<tr>
<td>isUpdatePending</td><td>undefined</td><td>undefined</td><td>boolean</td><td>undefined</td>
</tr>
<tr>
<td>hasUpdated</td><td>undefined</td><td>undefined</td><td>boolean</td><td>undefined</td>
</tr>
<tr>
<td>updateComplete</td><td>undefined</td><td>Returns a Promise that resolves when the element has completed updating.
The Promise value is a boolean that is `true` if the element completed the
update without triggering another update. The Promise result is `false` if
a property was set inside `updated()`. If the Promise is rejected, an
exception was thrown during the update.
To await additional asynchronous work, override the `getUpdateComplete`
method. For example, it is sometimes useful to await a rendered element
before fulfilling this Promise. To do this, first await
`super.getUpdateComplete()`, then any subsequent state.</td><td>Promise<boolean></td><td>undefined</td>
</tr>
</table>
<h3>Slots</h3>
<table>
<tr>
<th>Name</th><th>Description</th>
</tr>
<tr>
<td></td><td>This element has a slot</td>
</tr>
</table>
<h3>CSS Shadow Parts</h3>
<table>
<tr>
<th>Name</th><th>Description</th>
</tr>
<tr>
<td>button</td><td>The button</td>
</tr>
</table>
</main>
</div>
<footer>
<p>
Made with
<a href="https://github.com/PolymerLabs/lit-starter-ts">lit-starter-ts</a>
</p>
</footer>
</body>
</html>

View File

@@ -0,0 +1,162 @@
* {
box-sizing: border-box;
}
body {
margin: 0;
color: #333;
font-family: 'Open Sans', arial, sans-serif;
min-width: min-content;
min-height: 100vh;
font-size: 18px;
display: flex;
flex-direction: column;
align-items: stretch;
}
#main-wrapper {
flex-grow: 1;
}
main {
max-width: 1024px;
margin: 0 auto;
}
a:visited {
color: inherit;
}
header {
width: 100%;
display: flex;
flex-direction: column;
align-items: center;
justify-content: center;
height: 360px;
margin: 0;
background: linear-gradient(0deg, rgba(9,9,121,1) 0%, rgba(0,212,255,1) 100%);
color: white;
}
footer {
width: 100%;
min-height: 120px;
background: gray;
color: white;
display: flex;
flex-direction: column;
justify-content: center;
padding: 12px;
margin-top: 64px;
}
h1 {
font-size: 2.5em;
font-weight: 400;
}
h2 {
font-size: 1.6em;
font-weight: 300;
margin: 64px 0 12px;
}
h3 {
font-weight: 300;
}
header h1 {
width: auto;
font-size: 2.8em;
margin: 0;
}
header h2 {
width: auto;
margin: 0;
}
nav {
display: grid;
width: 100%;
max-width: 100%;
grid-template-columns: repeat(auto-fit, 240px);
justify-content: center;
border-bottom: 1px solid #efefef;
}
nav > a {
color: #444;
display: block;
flex: 1;
font-size: 18px;
padding: 20px 0;
text-align: center;
text-decoration: none;
}
nav > a:hover {
text-decoration: underline;
}
nav.collection {
border: none;
}
nav.collection > ul {
padding: 0;
list-style: none;
}
nav.collection > ul > li {
padding: 4px 0;
}
nav.collection > ul > li.selected {
font-weight: 600;
}
nav.collection a {
text-decoration: none;
}
nav.collection a:hover {
text-decoration: underline;
}
section.columns {
display: grid;
grid-template-columns: repeat(auto-fit, minmax(400px, 488px));
grid-gap: 48px;
justify-content: center;
}
section.columns > div {
flex: 1;
}
section.examples {
display: grid;
grid-template-columns: 240px minmax(400px, 784px);
grid-gap: 48px;
justify-content: center;
}
section.examples h2:first-of-type {
margin-top: 0;
}
table {
width: 100%;
border-collapse: collapse;
}
th {
font-weight: 600;
}
td, th {
border: solid 1px #aaa;
padding: 4px;
text-align: left;
}

View File

@@ -0,0 +1,75 @@
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title><my-element> ⌲ Examples ⌲ Basic</title>
<link rel="stylesheet" href="../docs.css">
<link rel="stylesheet" href="https://fonts.googleapis.com/css?family=Open+Sans:300,400,600|Roboto+Mono">
<link href="../prism-okaidia.css" rel="stylesheet" />
<script src="/node_modules/@webcomponents/webcomponentsjs/webcomponents-loader.js"></script>
<script src="/node_modules/lit/polyfill-support.js"></script>
<script type="module" src="../my-element.bundled.js"></script>
</head>
<body>
<header>
<h1>&lt;my-element></h1>
<h2>A web component just for me.</h2>
</header>
<nav>
<a href="../">Home</a>
<a href="">Examples</a>
<a href="../api/">API</a>
<a href="../install/">Install</a>
</nav>
<div id="main-wrapper">
<main>
<h1>Example: Basic</h1>
<section class="examples">
<nav class="collection">
<ul>
<li class=>
<a href="name-property/">Setting the name property</a>
</li>
<li class=selected>
<a href="">A basic example</a>
</li>
</ul>
</nav>
<div>
<style>
my-element p {
border: solid 1px blue;
padding: 8px;
}
</style>
<my-element>
<p>This is child content</p>
</my-element>
<h3>CSS</h3>
<pre class="language-css"><code class="language-css"><span class="token selector">p</span> <span class="token punctuation">{</span><br> <span class="token property">border</span><span class="token punctuation">:</span> solid 1px blue<span class="token punctuation">;</span><br> <span class="token property">padding</span><span class="token punctuation">:</span> 8px<span class="token punctuation">;</span><br><span class="token punctuation">}</span></code></pre>
<h3>HTML</h3>
<pre class="language-html"><code class="language-html"><span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span>my-element</span><span class="token punctuation">></span></span><br> <span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span>p</span><span class="token punctuation">></span></span>This is child content<span class="token tag"><span class="token tag"><span class="token punctuation">&lt;/</span>p</span><span class="token punctuation">></span></span><br><span class="token tag"><span class="token tag"><span class="token punctuation">&lt;/</span>my-element</span><span class="token punctuation">></span></span></code></pre>
</div>
</section>
</main>
</div>
<footer>
<p>
Made with
<a href="https://github.com/PolymerLabs/lit-starter-ts">lit-starter-ts</a>
</p>
</footer>
</body>
</html>

View File

@@ -0,0 +1,65 @@
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title><my-element> ⌲ Examples ⌲ Name Property</title>
<link rel="stylesheet" href="../../docs.css">
<link rel="stylesheet" href="https://fonts.googleapis.com/css?family=Open+Sans:300,400,600|Roboto+Mono">
<link href="../../prism-okaidia.css" rel="stylesheet" />
<script src="/node_modules/@webcomponents/webcomponentsjs/webcomponents-loader.js"></script>
<script src="/node_modules/lit/polyfill-support.js"></script>
<script type="module" src="../../my-element.bundled.js"></script>
</head>
<body>
<header>
<h1>&lt;my-element></h1>
<h2>A web component just for me.</h2>
</header>
<nav>
<a href="../../">Home</a>
<a href="../">Examples</a>
<a href="../../api/">API</a>
<a href="../../install/">Install</a>
</nav>
<div id="main-wrapper">
<main>
<h1>Example: Name Property</h1>
<section class="examples">
<nav class="collection">
<ul>
<li class=selected>
<a href="">Setting the name property</a>
</li>
<li class=>
<a href="../">A basic example</a>
</li>
</ul>
</nav>
<div>
<p><my-element name="Earth"></my-element></p>
<h3>HTML</h3>
<pre class="language-html"><code class="language-html"><span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span>my-element</span> <span class="token attr-name">name</span><span class="token attr-value"><span class="token punctuation attr-equals">=</span><span class="token punctuation">"</span>Earth<span class="token punctuation">"</span></span><span class="token punctuation">></span></span><span class="token tag"><span class="token tag"><span class="token punctuation">&lt;/</span>my-element</span><span class="token punctuation">></span></span></code></pre>
</div>
</section>
</main>
</div>
<footer>
<p>
Made with
<a href="https://github.com/PolymerLabs/lit-starter-ts">lit-starter-ts</a>
</p>
</footer>
</body>
</html>

View File

@@ -0,0 +1,75 @@
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title><my-element> ⌲ Home</title>
<link rel="stylesheet" href="docs.css">
<link rel="stylesheet" href="https://fonts.googleapis.com/css?family=Open+Sans:300,400,600|Roboto+Mono">
<link href="prism-okaidia.css" rel="stylesheet" />
<script src="/node_modules/@webcomponents/webcomponentsjs/webcomponents-loader.js"></script>
<script src="/node_modules/lit/polyfill-support.js"></script>
<script type="module" src="my-element.bundled.js"></script>
</head>
<body>
<header>
<h1>&lt;my-element></h1>
<h2>A web component just for me.</h2>
</header>
<nav>
<a href="">Home</a>
<a href="examples/">Examples</a>
<a href="api/">API</a>
<a href="install/">Install</a>
</nav>
<div id="main-wrapper">
<main>
<h1>&lt;my-element&gt;</h1>
<p><code>&lt;my-element&gt;</code> is an awesome element. It's a great introduction to building web components with LitElement, with nice documentation site as well.</p>
<h2>As easy as HTML</h2>
<section class="columns">
<div>
<p><code>&lt;my-element&gt;</code> is just an HTML element. You can it anywhere you can use HTML!</p>
<pre class="language-html"><code class="language-html"><span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span>my-element</span><span class="token punctuation">></span></span><span class="token tag"><span class="token tag"><span class="token punctuation">&lt;/</span>my-element</span><span class="token punctuation">></span></span></code></pre>
</div>
<div>
<p><my-element></my-element></p>
</div>
</section>
<h2>Configure with attributes</h2>
<section class="columns">
<div>
<p><code>&lt;my-element&gt;</code> can be configured with attributed in plain HTML.</p>
<pre class="language-html"><code class="language-html"><span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span>my-element</span> <span class="token attr-name">name</span><span class="token attr-value"><span class="token punctuation attr-equals">=</span><span class="token punctuation">"</span>HTML<span class="token punctuation">"</span></span><span class="token punctuation">></span></span><span class="token tag"><span class="token tag"><span class="token punctuation">&lt;/</span>my-element</span><span class="token punctuation">></span></span></code></pre>
</div>
<div>
<p><my-element name="HTML"></my-element></p>
</div>
</section>
<h2>Declarative rendering</h2>
<section class="columns">
<div>
<p><code>&lt;my-element&gt;</code> can be used with declarative rendering libraries like Angular, React, Vue, and lit-html</p>
<pre class="language-js"><code class="language-js"><span class="token keyword">import</span> <span class="token punctuation">{</span>html<span class="token punctuation">,</span> render<span class="token punctuation">}</span> <span class="token keyword">from</span> <span class="token string">'lit-html'</span><span class="token punctuation">;</span><br><br><span class="token keyword">const</span> name <span class="token operator">=</span> <span class="token string">'lit-html'</span><span class="token punctuation">;</span><br><br><span class="token function">render</span><span class="token punctuation">(</span><br> html<span class="token template-string"><span class="token template-punctuation string">`</span><span class="token string"><br> &lt;h2>This is a &amp;lt;my-element&amp;gt;&lt;/h2><br> &lt;my-element .name=</span><span class="token interpolation"><span class="token interpolation-punctuation punctuation">${</span>name<span class="token interpolation-punctuation punctuation">}</span></span><span class="token string">>&lt;/my-element><br> </span><span class="token template-punctuation string">`</span></span><span class="token punctuation">,</span><br> document<span class="token punctuation">.</span>body<br><span class="token punctuation">)</span><span class="token punctuation">;</span></code></pre>
</div>
<div>
<h2>This is a &lt;my-element&gt;</h2>
<my-element name="lit-html"></my-element>
</div>
</section>
</main>
</div>
<footer>
<p>
Made with
<a href="https://github.com/PolymerLabs/lit-starter-ts">lit-starter-ts</a>
</p>
</footer>
</body>
</html>

Some files were not shown because too many files have changed in this diff Show More