diff --git a/framework/controller/controller_test.go b/framework/controller/controller_test.go
index 93fc59c5..9711f38f 100644
--- a/framework/controller/controller_test.go
+++ b/framework/controller/controller_test.go
@@ -1286,7 +1286,6 @@ func TestViewUnnamed(t *testing.T) {
is.NoErr(err)
is.NoErr(res.DiffHeaders(`
HTTP/1.1 200 OK
- Transfer-Encoding: chunked
Content-Type: text/html
`))
el, err := res.Query("#bud_target")
@@ -1308,7 +1307,6 @@ func TestViewUnnamed(t *testing.T) {
is.NoErr(err)
is.NoErr(res.DiffHeaders(`
HTTP/1.1 200 OK
- Transfer-Encoding: chunked
Content-Type: text/html
`))
el, err = res.Query("#bud_target")
@@ -1330,7 +1328,6 @@ func TestViewUnnamed(t *testing.T) {
is.NoErr(err)
is.NoErr(res.DiffHeaders(`
HTTP/1.1 200 OK
- Transfer-Encoding: chunked
Content-Type: text/html
`))
el, err = res.Query("#bud_target")
@@ -1352,7 +1349,6 @@ func TestViewUnnamed(t *testing.T) {
is.NoErr(err)
is.NoErr(res.DiffHeaders(`
HTTP/1.1 200 OK
- Transfer-Encoding: chunked
Content-Type: text/html
`))
el, err = res.Query("#bud_target")
@@ -1435,7 +1431,6 @@ func TestViewNestedUnnamed(t *testing.T) {
is.NoErr(err)
is.NoErr(res.DiffHeaders(`
HTTP/1.1 200 OK
- Transfer-Encoding: chunked
Content-Type: text/html
`))
el, err := res.Query("#bud_target")
@@ -1457,7 +1452,6 @@ func TestViewNestedUnnamed(t *testing.T) {
is.NoErr(err)
is.NoErr(res.DiffHeaders(`
HTTP/1.1 200 OK
- Transfer-Encoding: chunked
Content-Type: text/html
`))
el, err = res.Query("#bud_target")
@@ -1479,7 +1473,6 @@ func TestViewNestedUnnamed(t *testing.T) {
is.NoErr(err)
is.NoErr(res.DiffHeaders(`
HTTP/1.1 200 OK
- Transfer-Encoding: chunked
Content-Type: text/html
`))
el, err = res.Query("#bud_target")
@@ -1501,7 +1494,6 @@ func TestViewNestedUnnamed(t *testing.T) {
is.NoErr(err)
is.NoErr(res.DiffHeaders(`
HTTP/1.1 200 OK
- Transfer-Encoding: chunked
Content-Type: text/html
`))
el, err = res.Query("#bud_target")
@@ -1587,7 +1579,6 @@ func TestViewDeepUnnamed(t *testing.T) {
is.NoErr(err)
is.NoErr(res.DiffHeaders(`
HTTP/1.1 200 OK
- Transfer-Encoding: chunked
Content-Type: text/html
`))
el, err := res.Query("#bud_target")
@@ -1609,7 +1600,6 @@ func TestViewDeepUnnamed(t *testing.T) {
is.NoErr(err)
is.NoErr(res.DiffHeaders(`
HTTP/1.1 200 OK
- Transfer-Encoding: chunked
Content-Type: text/html
`))
el, err = res.Query("#bud_target")
@@ -1631,7 +1621,6 @@ func TestViewDeepUnnamed(t *testing.T) {
is.NoErr(err)
is.NoErr(res.DiffHeaders(`
HTTP/1.1 200 OK
- Transfer-Encoding: chunked
Content-Type: text/html
`))
el, err = res.Query("#bud_target")
@@ -1653,7 +1642,6 @@ func TestViewDeepUnnamed(t *testing.T) {
is.NoErr(err)
is.NoErr(res.DiffHeaders(`
HTTP/1.1 200 OK
- Transfer-Encoding: chunked
Content-Type: text/html
`))
el, err = res.Query("#bud_target")
@@ -1774,7 +1762,6 @@ func TestEmptyActionWithView(t *testing.T) {
// HTML response
is.NoErr(res.DiffHeaders(`
HTTP/1.1 200 OK
- Transfer-Encoding: chunked
Content-Type: text/html
`))
is.In(res.Body().String(), `
hello
`)
@@ -2834,7 +2821,6 @@ func TestCreateRouteAndControllerAndView(t *testing.T) {
is.NoErr(err)
is.NoErr(res.DiffHeaders(`
HTTP/1.1 200 OK
- Transfer-Encoding: chunked
Content-Type: text/html
`))
sel, err := res.Query("#bud_target")
@@ -2875,7 +2861,6 @@ func TestCreateRouteAndControllerAndView(t *testing.T) {
is.NoErr(err)
is.NoErr(res.DiffHeaders(`
HTTP/1.1 200 OK
- Transfer-Encoding: chunked
Content-Type: text/html
`))
sel, err = res.Query("#bud_target")
@@ -2918,7 +2903,6 @@ func TestDeleteRouteAndControllerAndView(t *testing.T) {
is.NoErr(err)
is.NoErr(res.DiffHeaders(`
HTTP/1.1 200 OK
- Transfer-Encoding: chunked
Content-Type: text/html
`))
sel, err := res.Query("#bud_target")
@@ -2931,7 +2915,6 @@ func TestDeleteRouteAndControllerAndView(t *testing.T) {
is.NoErr(err)
is.NoErr(res.DiffHeaders(`
HTTP/1.1 200 OK
- Transfer-Encoding: chunked
Content-Type: text/html
`))
sel, err = res.Query("#bud_target")
diff --git a/framework/view/ssr/ssr.go b/framework/view/ssr/ssr.go
index f4165be2..8be33a6b 100644
--- a/framework/view/ssr/ssr.go
+++ b/framework/view/ssr/ssr.go
@@ -20,6 +20,7 @@ import (
"github.com/livebud/bud/internal/gotemplate"
"github.com/livebud/bud/package/budfs"
"github.com/livebud/bud/package/gomod"
+ "github.com/livebud/bud/package/vfs"
)
// Response from evaluating SSR files
@@ -49,6 +50,11 @@ type Compiler struct {
func (c *Compiler) Compile(ctx context.Context, fsys budfs.FS) ([]byte, error) {
dir := c.module.Directory()
+
+ if existCss := vfs.Exist(fsys, "public/default.css"); nil == existCss {
+ svelteRuntime = strings.Replace(svelteRuntime, ``, ``, 1)
+ }
+
result := esbuild.Build(esbuild.BuildOptions{
EntryPointsAdvanced: []esbuild.EntryPoint{
{
diff --git a/framework/view/ssr/ssr_test.go b/framework/view/ssr/ssr_test.go
index 0d7cacf1..e3f0c018 100644
--- a/framework/view/ssr/ssr_test.go
+++ b/framework/view/ssr/ssr_test.go
@@ -63,6 +63,81 @@ func TestSvelteHello(t *testing.T) {
is.True(strings.Contains(res.Body, `hi world
`))
}
+func TestSvelteRemoveDefaultCss(t *testing.T) {
+ is := is.New(t)
+ log := testlog.New()
+ ctx := context.Background()
+ dir := t.TempDir()
+ td := testdir.New(dir)
+ td.Files["view/index.svelte"] = `hi world
`
+ td.NodeModules["svelte"] = versions.Svelte
+ is.NoErr(td.Write(ctx))
+ vm, err := v8.Load()
+ is.NoErr(err)
+ svelteCompiler, err := svelte.Load(vm)
+ is.NoErr(err)
+ transformer := transformrt.MustLoad(svelte.NewTransformable(svelteCompiler))
+ module, err := gomod.Find(dir)
+ is.NoErr(err)
+ bfs := budfs.New(module, log)
+ is.NoErr(err)
+ bfs.FileGenerator("bud/view/_ssr.js", ssr.New(module, transformer.SSR))
+ // Read the wrapped version of index.svelte with node_modules rewritten
+ code, err := fs.ReadFile(bfs, "bud/view/_ssr.js")
+ is.NoErr(err)
+ is.True(strings.Contains(string(code), `create_ssr_component(`))
+ is.True(strings.Contains(string(code), `hi world
`))
+ is.True(strings.Contains(string(code), `views["/"] = `))
+ result, err := vm.Eval("render.js", string(code)+`; bud.render("/", {})`)
+ is.NoErr(err)
+ var res ssr.Response
+ err = json.Unmarshal([]byte(result), &res)
+ is.NoErr(err)
+ is.Equal(res.Status, 200)
+ is.Equal(len(res.Headers), 1)
+ is.Equal(res.Headers["Content-Type"], "text/html")
+ // svelte must not linked to default.css when removed
+ is.True(!strings.Contains(res.Body, ``))
+ is.True(strings.Contains(res.Body, ``))
+}
+
+func TestSvelteDefaultCss(t *testing.T) {
+ is := is.New(t)
+ log := testlog.New()
+ ctx := context.Background()
+ dir := t.TempDir()
+ td := testdir.New(dir)
+ td.Files["view/index.svelte"] = `hi world
`
+ td.Files["public/default.css"] = `.body{}`
+ td.NodeModules["svelte"] = versions.Svelte
+ is.NoErr(td.Write(ctx))
+ vm, err := v8.Load()
+ is.NoErr(err)
+ svelteCompiler, err := svelte.Load(vm)
+ is.NoErr(err)
+ transformer := transformrt.MustLoad(svelte.NewTransformable(svelteCompiler))
+ module, err := gomod.Find(dir)
+ is.NoErr(err)
+ bfs := budfs.New(module, log)
+ is.NoErr(err)
+ bfs.FileGenerator("bud/view/_ssr.js", ssr.New(module, transformer.SSR))
+ // Read the wrapped version of index.svelte with node_modules rewritten
+ code, err := fs.ReadFile(bfs, "bud/view/_ssr.js")
+ is.NoErr(err)
+ is.True(strings.Contains(string(code), `create_ssr_component(`))
+ is.True(strings.Contains(string(code), `hi world
`))
+ is.True(strings.Contains(string(code), `views["/"] = `))
+ result, err := vm.Eval("render.js", string(code)+`; bud.render("/", {})`)
+ is.NoErr(err)
+ var res ssr.Response
+ err = json.Unmarshal([]byte(result), &res)
+ is.NoErr(err)
+ is.Equal(res.Status, 200)
+ is.Equal(len(res.Headers), 1)
+ is.Equal(res.Headers["Content-Type"], "text/html")
+ is.True(strings.Contains(res.Body, ``))
+}
+
func TestSvelteAwait(t *testing.T) {
is := is.New(t)
log := testlog.New()
diff --git a/framework/view/ssr/svelte.js b/framework/view/ssr/svelte.js
index 0242f6c6..7e5156fa 100644
--- a/framework/view/ssr/svelte.js
+++ b/framework/view/ssr/svelte.js
@@ -326,8 +326,8 @@ var defaultLayout = {
-
-
+
+
${slots.head(props)}
${slots.default(props)}
@@ -336,293 +336,6 @@ var defaultLayout = {
};
}
};
-var defaultCSS = `
-/*! modern-normalize v1.1.0 | MIT License | https://github.com/sindresorhus/modern-normalize */
-
-/*
-Document
-========
-*/
-
-/**
-Use a better box model (opinionated).
-*/
-
-*,
-::before,
-::after {
- box-sizing: border-box;
-}
-
-/**
-1. Correct the line height in all browsers.
-2. Prevent adjustments of font size after orientation changes in iOS.
-3. Use a more readable tab size (opinionated).
-*/
-
-html {
- line-height: 1.15; /* 1 */
- -webkit-text-size-adjust: 100%; /* 2 */
- -moz-tab-size: 4; /* 3 */
- tab-size: 4; /* 3 */
-}
-
-/*
-Sections
-========
-*/
-
-/**
-1. Remove the margin in all browsers.
-2. Improve consistency of default fonts in all browsers. (https://github.com/sindresorhus/modern-normalize/issues/3)
-*/
-
-body {
- margin: 0; /* 1 */
- font-family:
- system-ui,
- -apple-system, /* Firefox supports this but not yet system-ui */
- 'Segoe UI',
- Roboto,
- Helvetica,
- Arial,
- sans-serif,
- 'Apple Color Emoji',
- 'Segoe UI Emoji'; /* 2 */
-}
-
-/*
-Grouping content
-================
-*/
-
-/**
-1. Add the correct height in Firefox.
-2. Correct the inheritance of border color in Firefox. (https://bugzilla.mozilla.org/show_bug.cgi?id=190655)
-*/
-
-hr {
- height: 0; /* 1 */
- color: inherit; /* 2 */
-}
-
-/*
-Text-level semantics
-====================
-*/
-
-/**
-Add the correct text decoration in Chrome, Edge, and Safari.
-*/
-
-abbr[title] {
- text-decoration: underline dotted;
-}
-
-/**
-Add the correct font weight in Edge and Safari.
-*/
-
-b,
-strong {
- font-weight: bolder;
-}
-
-/**
-1. Improve consistency of default fonts in all browsers. (https://github.com/sindresorhus/modern-normalize/issues/3)
-2. Correct the odd 'em' font sizing in all browsers.
-*/
-
-code,
-kbd,
-samp,
-pre {
- font-family:
- ui-monospace,
- SFMono-Regular,
- Consolas,
- 'Liberation Mono',
- Menlo,
- monospace; /* 1 */
- font-size: 1em; /* 2 */
-}
-
-/**
-Add the correct font size in all browsers.
-*/
-
-small {
- font-size: 80%;
-}
-
-/**
-Prevent 'sub' and 'sup' elements from affecting the line height in all browsers.
-*/
-
-sub,
-sup {
- font-size: 75%;
- line-height: 0;
- position: relative;
- vertical-align: baseline;
-}
-
-sub {
- bottom: -0.25em;
-}
-
-sup {
- top: -0.5em;
-}
-
-/*
-Tabular data
-============
-*/
-
-/**
-1. Remove text indentation from table contents in Chrome and Safari. (https://bugs.chromium.org/p/chromium/issues/detail?id=999088, https://bugs.webkit.org/show_bug.cgi?id=201297)
-2. Correct table border color inheritance in all Chrome and Safari. (https://bugs.chromium.org/p/chromium/issues/detail?id=935729, https://bugs.webkit.org/show_bug.cgi?id=195016)
-*/
-
-table {
- text-indent: 0; /* 1 */
- border-color: inherit; /* 2 */
-}
-
-/*
-Forms
-=====
-*/
-
-/**
-1. Change the font styles in all browsers.
-2. Remove the margin in Firefox and Safari.
-*/
-
-button,
-input,
-optgroup,
-select,
-textarea {
- font-family: inherit; /* 1 */
- font-size: 100%; /* 1 */
- line-height: 1.15; /* 1 */
- margin: 0; /* 2 */
-}
-
-/**
-Remove the inheritance of text transform in Edge and Firefox.
-*/
-
-button,
-select {
- text-transform: none;
-}
-
-/**
-Correct the inability to style clickable types in iOS and Safari.
-*/
-
-button,
-[type='button'],
-[type='reset'],
-[type='submit'] {
- -webkit-appearance: button;
-}
-
-/**
-Remove the inner border and padding in Firefox.
-*/
-
-::-moz-focus-inner {
- border-style: none;
- padding: 0;
-}
-
-/**
-Restore the focus styles unset by the previous rule.
-*/
-
-:-moz-focusring {
- outline: 1px dotted ButtonText;
-}
-
-/**
-Remove the additional ':invalid' styles in Firefox.
-See: https://github.com/mozilla/gecko-dev/blob/2f9eacd9d3d995c937b4251a5557d95d494c9be1/layout/style/res/forms.css#L728-L737
-*/
-
-:-moz-ui-invalid {
- box-shadow: none;
-}
-
-/**
-Remove the padding so developers are not caught out when they zero out 'fieldset' elements in all browsers.
-*/
-
-legend {
- padding: 0;
-}
-
-/**
-Add the correct vertical alignment in Chrome and Firefox.
-*/
-
-progress {
- vertical-align: baseline;
-}
-
-/**
-Correct the cursor style of increment and decrement buttons in Safari.
-*/
-
-::-webkit-inner-spin-button,
-::-webkit-outer-spin-button {
- height: auto;
-}
-
-/**
-1. Correct the odd appearance in Chrome and Safari.
-2. Correct the outline style in Safari.
-*/
-
-[type='search'] {
- -webkit-appearance: textfield; /* 1 */
- outline-offset: -2px; /* 2 */
-}
-
-/**
-Remove the inner padding in Chrome and Safari on macOS.
-*/
-
-::-webkit-search-decoration {
- -webkit-appearance: none;
-}
-
-/**
-1. Correct the inability to style clickable types in iOS and Safari.
-2. Change font properties to 'inherit' in Safari.
-*/
-
-::-webkit-file-upload-button {
- -webkit-appearance: button; /* 1 */
- font: inherit; /* 2 */
-}
-
-/*
-Interactive
-===========
-*/
-
-/*
-Add the correct display in Chrome and Safari.
-*/
-
-summary {
- display: list-item;
-}
-`;
export {
createView
};
diff --git a/framework/view/ssr/svelte.ts b/framework/view/ssr/svelte.ts
index 9104a6c4..29aee608 100644
--- a/framework/view/ssr/svelte.ts
+++ b/framework/view/ssr/svelte.ts
@@ -57,8 +57,8 @@ const defaultLayout = {
-
-
+
+
${slots.head(props)}
${slots.default(props)}
@@ -67,293 +67,3 @@ const defaultLayout = {
}
},
}
-
-// Default CSS is modern-normalize by Sindre Sorhus
-// https://raw.githubusercontent.com/sindresorhus/modern-normalize/v1.1.0/modern-normalize.css
-const defaultCSS = `
-/*! modern-normalize v1.1.0 | MIT License | https://github.com/sindresorhus/modern-normalize */
-
-/*
-Document
-========
-*/
-
-/**
-Use a better box model (opinionated).
-*/
-
-*,
-::before,
-::after {
- box-sizing: border-box;
-}
-
-/**
-1. Correct the line height in all browsers.
-2. Prevent adjustments of font size after orientation changes in iOS.
-3. Use a more readable tab size (opinionated).
-*/
-
-html {
- line-height: 1.15; /* 1 */
- -webkit-text-size-adjust: 100%; /* 2 */
- -moz-tab-size: 4; /* 3 */
- tab-size: 4; /* 3 */
-}
-
-/*
-Sections
-========
-*/
-
-/**
-1. Remove the margin in all browsers.
-2. Improve consistency of default fonts in all browsers. (https://github.com/sindresorhus/modern-normalize/issues/3)
-*/
-
-body {
- margin: 0; /* 1 */
- font-family:
- system-ui,
- -apple-system, /* Firefox supports this but not yet system-ui */
- 'Segoe UI',
- Roboto,
- Helvetica,
- Arial,
- sans-serif,
- 'Apple Color Emoji',
- 'Segoe UI Emoji'; /* 2 */
-}
-
-/*
-Grouping content
-================
-*/
-
-/**
-1. Add the correct height in Firefox.
-2. Correct the inheritance of border color in Firefox. (https://bugzilla.mozilla.org/show_bug.cgi?id=190655)
-*/
-
-hr {
- height: 0; /* 1 */
- color: inherit; /* 2 */
-}
-
-/*
-Text-level semantics
-====================
-*/
-
-/**
-Add the correct text decoration in Chrome, Edge, and Safari.
-*/
-
-abbr[title] {
- text-decoration: underline dotted;
-}
-
-/**
-Add the correct font weight in Edge and Safari.
-*/
-
-b,
-strong {
- font-weight: bolder;
-}
-
-/**
-1. Improve consistency of default fonts in all browsers. (https://github.com/sindresorhus/modern-normalize/issues/3)
-2. Correct the odd 'em' font sizing in all browsers.
-*/
-
-code,
-kbd,
-samp,
-pre {
- font-family:
- ui-monospace,
- SFMono-Regular,
- Consolas,
- 'Liberation Mono',
- Menlo,
- monospace; /* 1 */
- font-size: 1em; /* 2 */
-}
-
-/**
-Add the correct font size in all browsers.
-*/
-
-small {
- font-size: 80%;
-}
-
-/**
-Prevent 'sub' and 'sup' elements from affecting the line height in all browsers.
-*/
-
-sub,
-sup {
- font-size: 75%;
- line-height: 0;
- position: relative;
- vertical-align: baseline;
-}
-
-sub {
- bottom: -0.25em;
-}
-
-sup {
- top: -0.5em;
-}
-
-/*
-Tabular data
-============
-*/
-
-/**
-1. Remove text indentation from table contents in Chrome and Safari. (https://bugs.chromium.org/p/chromium/issues/detail?id=999088, https://bugs.webkit.org/show_bug.cgi?id=201297)
-2. Correct table border color inheritance in all Chrome and Safari. (https://bugs.chromium.org/p/chromium/issues/detail?id=935729, https://bugs.webkit.org/show_bug.cgi?id=195016)
-*/
-
-table {
- text-indent: 0; /* 1 */
- border-color: inherit; /* 2 */
-}
-
-/*
-Forms
-=====
-*/
-
-/**
-1. Change the font styles in all browsers.
-2. Remove the margin in Firefox and Safari.
-*/
-
-button,
-input,
-optgroup,
-select,
-textarea {
- font-family: inherit; /* 1 */
- font-size: 100%; /* 1 */
- line-height: 1.15; /* 1 */
- margin: 0; /* 2 */
-}
-
-/**
-Remove the inheritance of text transform in Edge and Firefox.
-*/
-
-button,
-select {
- text-transform: none;
-}
-
-/**
-Correct the inability to style clickable types in iOS and Safari.
-*/
-
-button,
-[type='button'],
-[type='reset'],
-[type='submit'] {
- -webkit-appearance: button;
-}
-
-/**
-Remove the inner border and padding in Firefox.
-*/
-
-::-moz-focus-inner {
- border-style: none;
- padding: 0;
-}
-
-/**
-Restore the focus styles unset by the previous rule.
-*/
-
-:-moz-focusring {
- outline: 1px dotted ButtonText;
-}
-
-/**
-Remove the additional ':invalid' styles in Firefox.
-See: https://github.com/mozilla/gecko-dev/blob/2f9eacd9d3d995c937b4251a5557d95d494c9be1/layout/style/res/forms.css#L728-L737
-*/
-
-:-moz-ui-invalid {
- box-shadow: none;
-}
-
-/**
-Remove the padding so developers are not caught out when they zero out 'fieldset' elements in all browsers.
-*/
-
-legend {
- padding: 0;
-}
-
-/**
-Add the correct vertical alignment in Chrome and Firefox.
-*/
-
-progress {
- vertical-align: baseline;
-}
-
-/**
-Correct the cursor style of increment and decrement buttons in Safari.
-*/
-
-::-webkit-inner-spin-button,
-::-webkit-outer-spin-button {
- height: auto;
-}
-
-/**
-1. Correct the odd appearance in Chrome and Safari.
-2. Correct the outline style in Safari.
-*/
-
-[type='search'] {
- -webkit-appearance: textfield; /* 1 */
- outline-offset: -2px; /* 2 */
-}
-
-/**
-Remove the inner padding in Chrome and Safari on macOS.
-*/
-
-::-webkit-search-decoration {
- -webkit-appearance: none;
-}
-
-/**
-1. Correct the inability to style clickable types in iOS and Safari.
-2. Change font properties to 'inherit' in Safari.
-*/
-
-::-webkit-file-upload-button {
- -webkit-appearance: button; /* 1 */
- font: inherit; /* 2 */
-}
-
-/*
-Interactive
-===========
-*/
-
-/*
-Add the correct display in Chrome and Safari.
-*/
-
-summary {
- display: list-item;
-}
-`
diff --git a/framework/view/view_test.go b/framework/view/view_test.go
index a21cf810..1ffc591b 100644
--- a/framework/view/view_test.go
+++ b/framework/view/view_test.go
@@ -41,7 +41,6 @@ func TestHello(t *testing.T) {
is.NoErr(err)
is.NoErr(res.DiffHeaders(`
HTTP/1.1 200 OK
- Transfer-Encoding: chunked
Content-Type: text/html
`))
is.In(res.Body().String(), "hello
")
@@ -63,7 +62,6 @@ func TestHello(t *testing.T) {
is.NoErr(err)
is.NoErr(res.DiffHeaders(`
HTTP/1.1 200 OK
- Transfer-Encoding: chunked
Content-Type: text/html
`))
is.In(res.Body().String(), "hi
")
@@ -84,7 +82,6 @@ func TestHello(t *testing.T) {
is.NoErr(err)
is.NoErr(res.DiffHeaders(`
HTTP/1.1 200 OK
- Transfer-Encoding: chunked
Content-Type: text/html
`))
is.In(res.Body().String(), "hola
")
@@ -117,7 +114,6 @@ func TestHelloEmbed(t *testing.T) {
is.NoErr(err)
is.NoErr(res.DiffHeaders(`
HTTP/1.1 200 OK
- Transfer-Encoding: chunked
Content-Type: text/html
`))
is.In(res.Body().String(), "hello
")
@@ -138,7 +134,6 @@ func TestHelloEmbed(t *testing.T) {
is.NoErr(err)
is.NoErr(res.DiffHeaders(`
HTTP/1.1 200 OK
- Transfer-Encoding: chunked
Content-Type: text/html
`))
is.In(res.Body().String(), "hello
")
@@ -189,7 +184,6 @@ func TestChunks(t *testing.T) {
is.NoErr(err)
is.NoErr(res.DiffHeaders(`
HTTP/1.1 200 OK
- Transfer-Encoding: chunked
Content-Type: text/html
`))
is.In(res.Body().String(), "index
")
@@ -207,7 +201,6 @@ func TestChunks(t *testing.T) {
is.NoErr(err)
is.NoErr(res.DiffHeaders(`
HTTP/1.1 200 OK
- Transfer-Encoding: chunked
Content-Type: text/html
`))
is.In(res.Body().String(), "show
")
@@ -261,7 +254,6 @@ func TestConsoleLog(t *testing.T) {
is.NoErr(err)
is.NoErr(res.DiffHeaders(`
HTTP/1.1 200 OK
- Transfer-Encoding: chunked
Content-Type: text/html
`))
is.In(res.Body().String(), "hello
")
@@ -306,7 +298,6 @@ func TestRenameView(t *testing.T) {
is.NoErr(err)
is.NoErr(res.DiffHeaders(`
HTTP/1.1 200 OK
- Transfer-Encoding: chunked
Content-Type: text/html
`))
is.In(res.Body().String(), "10
")
@@ -383,7 +374,6 @@ func TestAddView(t *testing.T) {
is.NoErr(err)
is.NoErr(res.DiffHeaders(`
HTTP/1.1 200 OK
- Transfer-Encoding: chunked
Content-Type: text/html
`))
is.In(res.Body().String(), "10
")
@@ -416,7 +406,6 @@ func TestSvelteImportFromNodeModule(t *testing.T) {
is.NoErr(err)
is.NoErr(res.DiffHeaders(`
HTTP/1.1 200 OK
- Transfer-Encoding: chunked
Content-Type: text/html
`))
is.In(res.Body().String(), "")
@@ -454,7 +443,6 @@ func TestSvelteImportFromOtherDir(t *testing.T) {
is.NoErr(err)
is.NoErr(res.DiffHeaders(`
HTTP/1.1 200 OK
- Transfer-Encoding: chunked
Content-Type: text/html
`))
is.In(res.Body().String(), "The Time
")
diff --git a/internal/cli/create/create.go b/internal/cli/create/create.go
index f12f9cbe..6adb0574 100644
--- a/internal/cli/create/create.go
+++ b/internal/cli/create/create.go
@@ -9,6 +9,7 @@ import (
"github.com/livebud/bud/internal/bail"
"github.com/livebud/bud/internal/cli/bud"
+ "github.com/livebud/bud/internal/embedded"
"github.com/livebud/bud/internal/scaffold"
"github.com/livebud/bud/internal/versions"
mod "github.com/livebud/bud/package/gomod"
@@ -159,6 +160,7 @@ func (c *Command) Scaffold(state *State) error {
if err := scaffold.Scaffold(scaffold.OSFS(c.absDir),
scaffold.Template("go.mod", gomod, state.Module),
scaffold.Template(".gitignore", gitignore, nil),
+ scaffold.Template("public/default.css", string(embedded.NormalizeCss()), nil),
scaffold.JSON("package.json", state.Package),
); err != nil {
return err
diff --git a/internal/cli/create/create_test.go b/internal/cli/create/create_test.go
index 1ee4913c..3cf88216 100644
--- a/internal/cli/create/create_test.go
+++ b/internal/cli/create/create_test.go
@@ -39,6 +39,7 @@ func TestCreateOutsideGoPath(t *testing.T) {
is.NoErr(td.Exists("go.sum"))
is.NoErr(td.Exists("package.json"))
is.NoErr(td.Exists("package-lock.json"))
+ is.NoErr(td.Exists("public/default.css"))
}
func TestCreateOutsideGoPathModulePath(t *testing.T) {
@@ -57,6 +58,7 @@ func TestCreateOutsideGoPathModulePath(t *testing.T) {
is.NoErr(td.Exists("go.sum"))
is.NoErr(td.Exists("package.json"))
is.NoErr(td.Exists("package-lock.json"))
+ is.NoErr(td.Exists("public/default.css"))
}
func TestAutoQuote(t *testing.T) {
diff --git a/internal/embedded/embedded.go b/internal/embedded/embedded.go
index b0196d83..03f79291 100644
--- a/internal/embedded/embedded.go
+++ b/internal/embedded/embedded.go
@@ -7,7 +7,15 @@ import (
//go:embed favicon.ico
var favicon []byte
+//go:embed normalize.css
+var normalize []byte
+
// Favicon returns the favicon data
func Favicon() []byte {
return favicon
}
+
+// NormalizeCss returns the normalize css data
+func NormalizeCss() []byte {
+ return normalize
+}
diff --git a/internal/embedded/normalize.css b/internal/embedded/normalize.css
new file mode 100644
index 00000000..a57c2225
--- /dev/null
+++ b/internal/embedded/normalize.css
@@ -0,0 +1,285 @@
+/*! modern-normalize v1.1.0 | MIT License | https://github.com/sindresorhus/modern-normalize */
+
+/*
+Document
+========
+*/
+
+/**
+Use a better box model (opinionated).
+*/
+
+*,
+::before,
+::after {
+ box-sizing: border-box;
+}
+
+/**
+1. Correct the line height in all browsers.
+2. Prevent adjustments of font size after orientation changes in iOS.
+3. Use a more readable tab size (opinionated).
+*/
+
+html {
+ line-height: 1.15; /* 1 */
+ -webkit-text-size-adjust: 100%; /* 2 */
+ -moz-tab-size: 4; /* 3 */
+ tab-size: 4; /* 3 */
+}
+
+/*
+Sections
+========
+*/
+
+/**
+1. Remove the margin in all browsers.
+2. Improve consistency of default fonts in all browsers. (https://github.com/sindresorhus/modern-normalize/issues/3)
+*/
+
+body {
+ margin: 0; /* 1 */
+ font-family:
+ system-ui,
+ -apple-system, /* Firefox supports this but not yet system-ui */
+ 'Segoe UI',
+ Roboto,
+ Helvetica,
+ Arial,
+ sans-serif,
+ 'Apple Color Emoji',
+ 'Segoe UI Emoji'; /* 2 */
+}
+
+/*
+Grouping content
+================
+*/
+
+/**
+1. Add the correct height in Firefox.
+2. Correct the inheritance of border color in Firefox. (https://bugzilla.mozilla.org/show_bug.cgi?id=190655)
+*/
+
+hr {
+ height: 0; /* 1 */
+ color: inherit; /* 2 */
+}
+
+/*
+Text-level semantics
+====================
+*/
+
+/**
+Add the correct text decoration in Chrome, Edge, and Safari.
+*/
+
+abbr[title] {
+ text-decoration: underline dotted;
+}
+
+/**
+Add the correct font weight in Edge and Safari.
+*/
+
+b,
+strong {
+ font-weight: bolder;
+}
+
+/**
+1. Improve consistency of default fonts in all browsers. (https://github.com/sindresorhus/modern-normalize/issues/3)
+2. Correct the odd 'em' font sizing in all browsers.
+*/
+
+code,
+kbd,
+samp,
+pre {
+ font-family:
+ ui-monospace,
+ SFMono-Regular,
+ Consolas,
+ 'Liberation Mono',
+ Menlo,
+ monospace; /* 1 */
+ font-size: 1em; /* 2 */
+}
+
+/**
+Add the correct font size in all browsers.
+*/
+
+small {
+ font-size: 80%;
+}
+
+/**
+Prevent 'sub' and 'sup' elements from affecting the line height in all browsers.
+*/
+
+sub,
+sup {
+ font-size: 75%;
+ line-height: 0;
+ position: relative;
+ vertical-align: baseline;
+}
+
+sub {
+ bottom: -0.25em;
+}
+
+sup {
+ top: -0.5em;
+}
+
+/*
+Tabular data
+============
+*/
+
+/**
+1. Remove text indentation from table contents in Chrome and Safari. (https://bugs.chromium.org/p/chromium/issues/detail?id=999088, https://bugs.webkit.org/show_bug.cgi?id=201297)
+2. Correct table border color inheritance in all Chrome and Safari. (https://bugs.chromium.org/p/chromium/issues/detail?id=935729, https://bugs.webkit.org/show_bug.cgi?id=195016)
+*/
+
+table {
+ text-indent: 0; /* 1 */
+ border-color: inherit; /* 2 */
+}
+
+/*
+Forms
+=====
+*/
+
+/**
+1. Change the font styles in all browsers.
+2. Remove the margin in Firefox and Safari.
+*/
+
+button,
+input,
+optgroup,
+select,
+textarea {
+ font-family: inherit; /* 1 */
+ font-size: 100%; /* 1 */
+ line-height: 1.15; /* 1 */
+ margin: 0; /* 2 */
+}
+
+/**
+Remove the inheritance of text transform in Edge and Firefox.
+*/
+
+button,
+select {
+ text-transform: none;
+}
+
+/**
+Correct the inability to style clickable types in iOS and Safari.
+*/
+
+button,
+[type='button'],
+[type='reset'],
+[type='submit'] {
+ -webkit-appearance: button;
+}
+
+/**
+Remove the inner border and padding in Firefox.
+*/
+
+::-moz-focus-inner {
+ border-style: none;
+ padding: 0;
+}
+
+/**
+Restore the focus styles unset by the previous rule.
+*/
+
+:-moz-focusring {
+ outline: 1px dotted ButtonText;
+}
+
+/**
+Remove the additional ':invalid' styles in Firefox.
+See: https://github.com/mozilla/gecko-dev/blob/2f9eacd9d3d995c937b4251a5557d95d494c9be1/layout/style/res/forms.css#L728-L737
+*/
+
+:-moz-ui-invalid {
+ box-shadow: none;
+}
+
+/**
+Remove the padding so developers are not caught out when they zero out 'fieldset' elements in all browsers.
+*/
+
+legend {
+ padding: 0;
+}
+
+/**
+Add the correct vertical alignment in Chrome and Firefox.
+*/
+
+progress {
+ vertical-align: baseline;
+}
+
+/**
+Correct the cursor style of increment and decrement buttons in Safari.
+*/
+
+::-webkit-inner-spin-button,
+::-webkit-outer-spin-button {
+ height: auto;
+}
+
+/**
+1. Correct the odd appearance in Chrome and Safari.
+2. Correct the outline style in Safari.
+*/
+
+[type='search'] {
+ -webkit-appearance: textfield; /* 1 */
+ outline-offset: -2px; /* 2 */
+}
+
+/**
+Remove the inner padding in Chrome and Safari on macOS.
+*/
+
+::-webkit-search-decoration {
+ -webkit-appearance: none;
+}
+
+/**
+1. Correct the inability to style clickable types in iOS and Safari.
+2. Change font properties to 'inherit' in Safari.
+*/
+
+::-webkit-file-upload-button {
+ -webkit-appearance: button; /* 1 */
+ font: inherit; /* 2 */
+}
+
+/*
+Interactive
+===========
+*/
+
+/*
+Add the correct display in Chrome and Safari.
+*/
+
+summary {
+ display: list-item;
+}
\ No newline at end of file