Before Width: | Height: | Size: 46 KiB |
@ -1,9 +1,9 @@
|
||||
<script>
|
||||
import FancyButton from './FancyButton.svelte';
|
||||
import CustomButton from './CustomButton.svelte';
|
||||
|
||||
function handleClick() {
|
||||
alert('clicked');
|
||||
}
|
||||
</script>
|
||||
|
||||
<FancyButton on:click={handleClick}/>
|
||||
<CustomButton on:click={handleClick}/>
|
@ -0,0 +1,22 @@
|
||||
<style>
|
||||
button {
|
||||
height: 4rem;
|
||||
width: 8rem;
|
||||
background-color: #aaa;
|
||||
border-color: #f1c40f;
|
||||
color: #f1c40f;
|
||||
font-size: 1.25rem;
|
||||
background-image: linear-gradient(45deg, #f1c40f 50%, transparent 50%);
|
||||
background-position: 100%;
|
||||
background-size: 400%;
|
||||
transition: background 300ms ease-in-out;
|
||||
}
|
||||
button:hover {
|
||||
background-position: 0;
|
||||
color: #aaa;
|
||||
}
|
||||
</style>
|
||||
|
||||
<button on:click>
|
||||
Click me
|
||||
</button>
|
@ -1,15 +0,0 @@
|
||||
<style>
|
||||
button {
|
||||
font-family: 'Comic Sans MS', cursive;
|
||||
font-size: 2em;
|
||||
padding: 0.5em 1em;
|
||||
color: royalblue;
|
||||
background: gold;
|
||||
border-radius: 1em;
|
||||
box-shadow: 2px 2px 4px rgba(0,0,0,0.5);
|
||||
}
|
||||
</style>
|
||||
|
||||
<button on:click>
|
||||
Click me
|
||||
</button>
|
@ -1,9 +1,9 @@
|
||||
<script>
|
||||
import FancyButton from './FancyButton.svelte';
|
||||
import CustomButton from './CustomButton.svelte';
|
||||
|
||||
function handleClick() {
|
||||
alert('clicked');
|
||||
}
|
||||
</script>
|
||||
|
||||
<FancyButton on:click={handleClick}/>
|
||||
<CustomButton on:click={handleClick}/>
|
@ -0,0 +1,22 @@
|
||||
<style>
|
||||
button {
|
||||
height: 4rem;
|
||||
width: 8rem;
|
||||
background-color: #aaa;
|
||||
border-color: #f1c40f;
|
||||
color: #f1c40f;
|
||||
font-size: 1.25rem;
|
||||
background-image: linear-gradient(45deg, #f1c40f 50%, transparent 50%);
|
||||
background-position: 100%;
|
||||
background-size: 400%;
|
||||
transition: background 300ms ease-in-out;
|
||||
}
|
||||
button:hover {
|
||||
background-position: 0;
|
||||
color: #aaa;
|
||||
}
|
||||
</style>
|
||||
|
||||
<button>
|
||||
Click me
|
||||
</button>
|
@ -1,15 +0,0 @@
|
||||
<style>
|
||||
button {
|
||||
font-family: 'Comic Sans MS', cursive;
|
||||
font-size: 2em;
|
||||
padding: 0.5em 1em;
|
||||
color: royalblue;
|
||||
background: gold;
|
||||
border-radius: 1em;
|
||||
box-shadow: 2px 2px 4px rgba(0,0,0,0.5);
|
||||
}
|
||||
</style>
|
||||
|
||||
<button>
|
||||
Click me
|
||||
</button>
|
@ -1,9 +1,9 @@
|
||||
<script>
|
||||
import FancyButton from './FancyButton.svelte';
|
||||
import CustomButton from './CustomButton.svelte';
|
||||
|
||||
function handleClick() {
|
||||
alert('clicked');
|
||||
}
|
||||
</script>
|
||||
|
||||
<FancyButton on:click={handleClick}/>
|
||||
<CustomButton on:click={handleClick}/>
|
@ -0,0 +1,22 @@
|
||||
<style>
|
||||
button {
|
||||
height: 4rem;
|
||||
width: 8rem;
|
||||
background-color: #aaa;
|
||||
border-color: #f1c40f;
|
||||
color: #f1c40f;
|
||||
font-size: 1.25rem;
|
||||
background-image: linear-gradient(45deg, #f1c40f 50%, transparent 50%);
|
||||
background-position: 100%;
|
||||
background-size: 400%;
|
||||
transition: background 300ms ease-in-out;
|
||||
}
|
||||
button:hover {
|
||||
background-position: 0;
|
||||
color: #aaa;
|
||||
}
|
||||
</style>
|
||||
|
||||
<button on:click>
|
||||
Click me
|
||||
</button>
|
@ -1,15 +0,0 @@
|
||||
<style>
|
||||
button {
|
||||
font-family: 'Comic Sans MS', cursive;
|
||||
font-size: 2em;
|
||||
padding: 0.5em 1em;
|
||||
color: royalblue;
|
||||
background: gold;
|
||||
border-radius: 1em;
|
||||
box-shadow: 2px 2px 4px rgba(0,0,0,0.5);
|
||||
}
|
||||
</style>
|
||||
|
||||
<button on:click>
|
||||
Click me
|
||||
</button>
|
Before Width: | Height: | Size: 4.0 KiB After Width: | Height: | Size: 2.1 KiB |
Before Width: | Height: | Size: 2.0 KiB After Width: | Height: | Size: 1.3 KiB |
Before Width: | Height: | Size: 275 B After Width: | Height: | Size: 184 B |
Before Width: | Height: | Size: 229 B After Width: | Height: | Size: 168 B |
Before Width: | Height: | Size: 221 B After Width: | Height: | Size: 161 B |
Before Width: | Height: | Size: 405 B After Width: | Height: | Size: 320 B |
Before Width: | Height: | Size: 212 B After Width: | Height: | Size: 155 B |
Before Width: | Height: | Size: 213 B After Width: | Height: | Size: 155 B |
Before Width: | Height: | Size: 333 B After Width: | Height: | Size: 256 B |
Before Width: | Height: | Size: 411 B After Width: | Height: | Size: 315 B |
Before Width: | Height: | Size: 415 B After Width: | Height: | Size: 344 B |
Before Width: | Height: | Size: 356 B After Width: | Height: | Size: 258 B |
Before Width: | Height: | Size: 290 B After Width: | Height: | Size: 215 B |
Before Width: | Height: | Size: 320 B After Width: | Height: | Size: 260 B |
Before Width: | Height: | Size: 1.6 KiB After Width: | Height: | Size: 1.5 KiB |
Before Width: | Height: | Size: 5.7 KiB After Width: | Height: | Size: 3.3 KiB |
Before Width: | Height: | Size: 1.6 KiB After Width: | Height: | Size: 1.2 KiB |
Before Width: | Height: | Size: 1.7 KiB After Width: | Height: | Size: 1.3 KiB |
Before Width: | Height: | Size: 2.7 KiB After Width: | Height: | Size: 2.7 KiB |
Before Width: | Height: | Size: 1.7 KiB After Width: | Height: | Size: 1.3 KiB |
Before Width: | Height: | Size: 280 B After Width: | Height: | Size: 221 B |
Before Width: | Height: | Size: 303 B After Width: | Height: | Size: 242 B |
Before Width: | Height: | Size: 260 B After Width: | Height: | Size: 200 B |
Before Width: | Height: | Size: 354 B After Width: | Height: | Size: 311 B |
Before Width: | Height: | Size: 334 B After Width: | Height: | Size: 280 B |
Before Width: | Height: | Size: 262 B After Width: | Height: | Size: 193 B |
Before Width: | Height: | Size: 292 B After Width: | Height: | Size: 239 B |
Before Width: | Height: | Size: 111 KiB After Width: | Height: | Size: 108 KiB |
@ -0,0 +1,73 @@
|
||||
import { INode } from '../../../nodes/interfaces';
|
||||
import { trim_end, trim_start } from '../../../../utils/trim';
|
||||
import { link } from '../../../../utils/link';
|
||||
|
||||
// similar logic from `compile/render_dom/wrappers/Fragment`
|
||||
// We want to remove trailing whitespace inside an element/component/block,
|
||||
// *unless* there is no whitespace between this node and its next sibling
|
||||
export default function remove_whitespace_children(children: INode[], next?: INode): INode[] {
|
||||
const nodes: INode[] = [];
|
||||
let last_child: INode;
|
||||
let i = children.length;
|
||||
while (i--) {
|
||||
const child = children[i];
|
||||
|
||||
if (child.type === 'Text') {
|
||||
if (child.should_skip()) {
|
||||
continue;
|
||||
}
|
||||
|
||||
let { data } = child;
|
||||
|
||||
if (nodes.length === 0) {
|
||||
const should_trim = next
|
||||
? next.type === 'Text' &&
|
||||
/^\s/.test(next.data) &&
|
||||
trimmable_at(child, next)
|
||||
: !child.has_ancestor('EachBlock');
|
||||
|
||||
if (should_trim) {
|
||||
data = trim_end(data);
|
||||
if (!data) continue;
|
||||
}
|
||||
}
|
||||
|
||||
// glue text nodes (which could e.g. be separated by comments) together
|
||||
if (last_child && last_child.type === 'Text') {
|
||||
last_child.data = data + last_child.data;
|
||||
continue;
|
||||
}
|
||||
|
||||
nodes.unshift(child);
|
||||
link(last_child, last_child = child);
|
||||
} else {
|
||||
nodes.unshift(child);
|
||||
link(last_child, last_child = child);
|
||||
}
|
||||
}
|
||||
|
||||
const first = nodes[0];
|
||||
if (first && first.type === 'Text') {
|
||||
first.data = trim_start(first.data);
|
||||
if (!first.data) {
|
||||
first.var = null;
|
||||
nodes.shift();
|
||||
|
||||
if (nodes[0]) {
|
||||
nodes[0].prev = null;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return nodes;
|
||||
}
|
||||
|
||||
function trimmable_at(child: INode, next_sibling: INode): boolean {
|
||||
// Whitespace is trimmable if one of the following is true:
|
||||
// The child and its sibling share a common nearest each block (not at an each block boundary)
|
||||
// The next sibling's previous node is an each block
|
||||
return (
|
||||
next_sibling.find_nearest(/EachBlock/) ===
|
||||
child.find_nearest(/EachBlock/) || next_sibling.prev.type === 'EachBlock'
|
||||
);
|
||||
}
|
@ -0,0 +1,5 @@
|
||||
export const reserved_keywords = new Set(["$$props", "$$restProps"]);
|
||||
|
||||
export function is_reserved_keyword(name) {
|
||||
return reserved_keywords.has(name);
|
||||
}
|
@ -0,0 +1,35 @@
|
||||
import { Pattern, Identifier, RestElement } from "estree";
|
||||
import { Node } from "acorn";
|
||||
|
||||
export default function traverse_destructure_pattern(
|
||||
node: Pattern,
|
||||
callback: (node: Identifier, parent: Node, key: string | number) => void
|
||||
) {
|
||||
function traverse(node: Pattern, parent, key) {
|
||||
switch (node.type) {
|
||||
case "Identifier":
|
||||
return callback(node, parent, key);
|
||||
case "ArrayPattern":
|
||||
for (let i = 0; i < node.elements.length; i++) {
|
||||
const element = node.elements[i];
|
||||
traverse(element, node.elements, i);
|
||||
}
|
||||
break;
|
||||
case "ObjectPattern":
|
||||
for (let i = 0; i < node.properties.length; i++) {
|
||||
const property = node.properties[i];
|
||||
if (property.type === "Property") {
|
||||
traverse(property.value, property, "value");
|
||||
} else {
|
||||
traverse((property as any) as RestElement, node.properties, i);
|
||||
}
|
||||
}
|
||||
break;
|
||||
case "RestElement":
|
||||
return traverse(node.argument, node, 'argument');
|
||||
case "AssignmentPattern":
|
||||
return traverse(node.left, node, 'left');
|
||||
}
|
||||
}
|
||||
traverse(node, null, null);
|
||||
}
|
@ -0,0 +1,28 @@
|
||||
const SQUARE_BRACKET_OPEN = "[".charCodeAt(0);
|
||||
const SQUARE_BRACKET_CLOSE = "]".charCodeAt(0);
|
||||
const CURLY_BRACKET_OPEN = "{".charCodeAt(0);
|
||||
const CURLY_BRACKET_CLOSE = "}".charCodeAt(0);
|
||||
|
||||
export function is_bracket_open(code) {
|
||||
return code === SQUARE_BRACKET_OPEN || code === CURLY_BRACKET_OPEN;
|
||||
}
|
||||
|
||||
export function is_bracket_close(code) {
|
||||
return code === SQUARE_BRACKET_CLOSE || code === CURLY_BRACKET_CLOSE;
|
||||
}
|
||||
|
||||
export function is_bracket_pair(open, close) {
|
||||
return (
|
||||
(open === SQUARE_BRACKET_OPEN && close === SQUARE_BRACKET_CLOSE) ||
|
||||
(open === CURLY_BRACKET_OPEN && close === CURLY_BRACKET_CLOSE)
|
||||
);
|
||||
}
|
||||
|
||||
export function get_bracket_close(open) {
|
||||
if (open === SQUARE_BRACKET_OPEN) {
|
||||
return SQUARE_BRACKET_CLOSE;
|
||||
}
|
||||
if (open === CURLY_BRACKET_OPEN) {
|
||||
return CURLY_BRACKET_CLOSE;
|
||||
}
|
||||
}
|
@ -0,0 +1,4 @@
|
||||
export function link<T extends { next?: T; prev?: T }>(next: T, prev: T) {
|
||||
prev.next = next;
|
||||
if (next) next.prev = prev;
|
||||
}
|
@ -0,0 +1,2 @@
|
||||
class CustomButton extends HTMLButtonElement {}
|
||||
customElements.define('custom-button', CustomButton, { extends: 'button' });
|
@ -1,2 +0,0 @@
|
||||
class FancyButton extends HTMLButtonElement {}
|
||||
customElements.define('fancy-button', FancyButton, { extends: 'button' });
|
@ -1,7 +1,7 @@
|
||||
<svelte:options tag="custom-element"/>
|
||||
|
||||
<script>
|
||||
import './fancy-button.js';
|
||||
import './custom-button.js';
|
||||
</script>
|
||||
|
||||
<button is="fancy-button">click me</button>
|
||||
<button is="custom-button">click me</button>
|
@ -0,0 +1 @@
|
||||
<div>Hello world</div>
|
@ -0,0 +1,2 @@
|
||||
<main>This should be thrown away</main>
|
||||
<div>hello</div>
|
@ -0,0 +1 @@
|
||||
export default {};
|