Skip to content

Commit 1ad28e6

Browse files
committed
use base36 for style classes
1 parent cbd1a11 commit 1ad28e6

File tree

91 files changed

+115
-115
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

91 files changed

+115
-115
lines changed

src/css/Stylesheet.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -266,7 +266,7 @@ export default class Stylesheet {
266266
children: (Rule|Atrule)[];
267267
keyframes: Map<string, string>;
268268

269-
constructor(source: string, parsed: Parsed, filename: string, cascade: boolean, dev: boolean) {
269+
constructor(source: string, parsed: Parsed, name: string, filename: string, cascade: boolean, dev: boolean) {
270270
this.source = source;
271271
this.parsed = parsed;
272272
this.cascade = cascade;
@@ -277,7 +277,7 @@ export default class Stylesheet {
277277
this.keyframes = new Map();
278278

279279
if (parsed.css && parsed.css.children.length) {
280-
this.id = `svelte-${hash(parsed.css.content.styles)}`;
280+
this.id = `${name ? name.toLowerCase() : 'svelte'}-${hash(parsed.css.content.styles)}`;
281281

282282
this.hasStyles = true;
283283

src/index.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -116,7 +116,7 @@ export function compile(source: string, _options: CompileOptions) {
116116
return;
117117
}
118118

119-
const stylesheet = new Stylesheet(source, parsed, options.filename, options.cascade !== false, options.dev);
119+
const stylesheet = new Stylesheet(source, parsed, options.name, options.filename, options.cascade !== false, options.dev);
120120

121121
validate(parsed, source, stylesheet, options);
122122

src/utils/hash.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
// https://github.com/darkskyapp/string-hash/blob/master/index.js
2-
export default function hash(str: string): number {
2+
export default function hash(str: string): string {
33
let hash = 5381;
44
let i = str.length;
55

66
while (i--) hash = ((hash << 5) - hash) ^ str.charCodeAt(i);
7-
return hash >>> 0;
7+
return (hash >>> 0).toString(36);
88
}

test/css/index.js

+3-3
Original file line numberDiff line numberDiff line change
@@ -95,7 +95,7 @@ describe('css', () => {
9595
css: read(`test/css/samples/${dir}/expected.css`)
9696
};
9797

98-
assert.equal(dom.css.replace(/svelte-\d+/g, 'svelte-xyz'), expected.css);
98+
assert.equal(dom.css.replace(/sveltecomponent-[a-z0-9]+/g, 'sveltecomponent-xyz'), expected.css);
9999

100100
// verify that the right elements have scoping selectors
101101
if (expected.html !== null) {
@@ -114,7 +114,7 @@ describe('css', () => {
114114
fs.writeFileSync(`test/css/samples/${dir}/_actual.html`, html);
115115

116116
assert.equal(
117-
normalizeHtml(window, html.replace(/svelte-\d+/g, 'svelte-xyz')),
117+
normalizeHtml(window, html.replace(/sveltecomponent-[a-z0-9]+/g, 'sveltecomponent-xyz')),
118118
normalizeHtml(window, expected.html)
119119
);
120120

@@ -133,7 +133,7 @@ describe('css', () => {
133133
assert.equal(
134134
normalizeHtml(
135135
window,
136-
component.render(config.data).html.replace(/svelte-\d+/g, 'svelte-xyz')
136+
component.render(config.data).html.replace(/sveltecomponent-[a-z0-9]+/g, 'sveltecomponent-xyz')
137137
),
138138
normalizeHtml(window, expected.html)
139139
);
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
[foo].svelte-xyz{color:red}[baz].svelte-xyz{color:blue}
1+
[foo].sveltecomponent-xyz{color:red}[baz].sveltecomponent-xyz{color:blue}
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
[foo=bar].svelte-xyz{color:red}
1+
[foo=bar].sveltecomponent-xyz{color:red}

test/css/samples/basic/expected.css

+1-1
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
div.svelte-xyz,.svelte-xyz div{color:red}
1+
div.sveltecomponent-xyz,.sveltecomponent-xyz div{color:red}
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
.foo.svelte-xyz{}
1+
.foo.sveltecomponent-xyz{}

test/css/samples/cascade-false-global-keyframes/expected.css

+1-1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

test/css/samples/cascade-false-keyframes-from-to/expected.css

+1-1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

test/css/samples/cascade-false-keyframes/expected.css

+1-1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

test/css/samples/cascade-false-pseudo-element/expected.css

+1-1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
.svelte-xyz{color:red}
1+
.sveltecomponent-xyz{color:red}
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
<div class="svelte-xyz"></div>
1+
<div class="sveltecomponent-xyz"></div>

test/css/samples/cascade-false/expected.css

+1-1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
.test.svelte-xyz>div.svelte-xyz{color:#0af}
1+
.test.sveltecomponent-xyz>div.sveltecomponent-xyz{color:#0af}
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
<div class="test svelte-xyz"><div class="svelte-xyz">Testing...</div></div>
1+
<div class="test sveltecomponent-xyz"><div class="sveltecomponent-xyz">Testing...</div></div>
+1-1
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
div.svelte-xyz,.svelte-xyz div{--test:10}
1+
div.sveltecomponent-xyz,.sveltecomponent-xyz div{--test:10}
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
p.svelte-xyz span.svelte-xyz{color:red}
1+
p.sveltecomponent-xyz span.sveltecomponent-xyz{color:red}
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
<div><p class="svelte-xyz"><span class="svelte-xyz">styled</span></p></div>
1+
<div><p class="sveltecomponent-xyz"><span class="sveltecomponent-xyz">styled</span></p></div>

test/css/samples/keyframes/expected.css

+1-1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
@media only screen and (min-width: 400px){div.svelte-xyz,.svelte-xyz div{color:red}}
1+
@media only screen and (min-width: 400px){div.sveltecomponent-xyz,.sveltecomponent-xyz div{color:red}}
+1-1
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
@media(min-width: 400px){.svelte-xyz.large-screen,.svelte-xyz .large-screen{display:block}}
1+
@media(min-width: 400px){.sveltecomponent-xyz.large-screen,.sveltecomponent-xyz .large-screen{display:block}}
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
[data-foo*='bar'].svelte-xyz{color:red}
1+
[data-foo*='bar'].sveltecomponent-xyz{color:red}
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
1-
<div><p class="svelte-xyz" data-foo="foobarbaz">this is styled</p>
1+
<div><p class="sveltecomponent-xyz" data-foo="foobarbaz">this is styled</p>
22
<p data-foo="fooBARbaz">this is unstyled</p></div>
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
[data-foo='bar' i].svelte-xyz{color:red}
1+
[data-foo='bar' i].sveltecomponent-xyz{color:red}
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
1-
<div><p class="svelte-xyz" data-foo="BAR">this is styled</p>
1+
<div><p class="sveltecomponent-xyz" data-foo="BAR">this is styled</p>
22
<p data-foo="BAZ">this is unstyled</p></div>
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
[data-foo='bar'].svelte-xyz{color:red}
1+
[data-foo='bar'].sveltecomponent-xyz{color:red}
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
1-
<div><p class="svelte-xyz" data-foo="whatever">this is styled</p>
1+
<div><p class="sveltecomponent-xyz" data-foo="whatever">this is styled</p>
22
<p data-foo="baz">this is unstyled</p></div>
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
[data-foo='bar'].svelte-xyz{color:red}
1+
[data-foo='bar'].sveltecomponent-xyz{color:red}
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
1-
<div><p class="svelte-xyz" data-foo="bar">this is styled</p>
1+
<div><p class="sveltecomponent-xyz" data-foo="bar">this is styled</p>
22
<p data-foo="baz">this is unstyled</p></div>
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
[data-foo|='bar'].svelte-xyz{color:red}
1+
[data-foo|='bar'].sveltecomponent-xyz{color:red}
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
1-
<div><p class="svelte-xyz" data-foo="bar">this is styled</p>
2-
<p class="svelte-xyz" data-foo="bar-baz">this is styled</p>
1+
<div><p class="sveltecomponent-xyz" data-foo="bar">this is styled</p>
2+
<p class="sveltecomponent-xyz" data-foo="bar-baz">this is styled</p>
33
<p data-foo="baz-bar">this is unstyled</p></div>
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
[data-foo^='bar'].svelte-xyz{color:red}
1+
[data-foo^='bar'].sveltecomponent-xyz{color:red}
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
1-
<div><p class="svelte-xyz" data-foo="barbaz">this is styled</p>
1+
<div><p class="sveltecomponent-xyz" data-foo="barbaz">this is styled</p>
22
<p data-foo="bazbar">this is unstyled</p></div>
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
[data-foo$='bar'].svelte-xyz{color:red}
1+
[data-foo$='bar'].sveltecomponent-xyz{color:red}
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
11
<div><p data-foo="barbaz">this is unstyled</p>
2-
<p class="svelte-xyz" data-foo="bazbar">this is styled</p></div>
2+
<p class="sveltecomponent-xyz" data-foo="bazbar">this is styled</p></div>
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
[data-foo~='bar'].svelte-xyz{color:red}
1+
[data-foo~='bar'].sveltecomponent-xyz{color:red}
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
1-
<div><p class="svelte-xyz" data-foo="qux bar">this is styled</p>
1+
<div><p class="sveltecomponent-xyz" data-foo="qux bar">this is styled</p>
22
<p data-foo="qux baz">this is unstyled</p></div>
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
[autoplay].svelte-xyz{color:red}
1+
[autoplay].sveltecomponent-xyz{color:red}
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
1-
<div><video class="svelte-xyz" autoplay></video>
1+
<div><video class="sveltecomponent-xyz" autoplay></video>
22
<video></video></div>
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
.foo.svelte-xyz{color:red}
1+
.foo.sveltecomponent-xyz{color:red}
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
1-
<p class="whatever svelte-xyz">this is styled</p>
1+
<p class="whatever sveltecomponent-xyz">this is styled</p>
22
<p class="bar">this is unstyled</p>
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
.foo.svelte-xyz{color:red}
1+
.foo.sveltecomponent-xyz{color:red}
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
1-
<p class="foo svelte-xyz">this is styled</p>
1+
<p class="foo sveltecomponent-xyz">this is styled</p>
22
<p class="bar">this is unstyled</p>
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
.foo.svelte-xyz .bar{color:red}
1+
.foo.sveltecomponent-xyz .bar{color:red}
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
<div class="foo svelte-xyz"></div>
1+
<div class="foo sveltecomponent-xyz"></div>
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
div.svelte-xyz>p>em{color:red}
1+
div.sveltecomponent-xyz>p>em{color:red}
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
<div class="svelte-xyz"></div>
1+
<div class="sveltecomponent-xyz"></div>
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
div.svelte-xyz>p{color:red}
1+
div.sveltecomponent-xyz>p{color:red}
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
<div class="svelte-xyz"></div>
1+
<div class="sveltecomponent-xyz"></div>
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
div>section>p.svelte-xyz{color:red}
1+
div>section>p.sveltecomponent-xyz{color:red}
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
<p class="svelte-xyz">this may or may not be styled</p>
1+
<p class="sveltecomponent-xyz">this may or may not be styled</p>
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
div>p.svelte-xyz{color:red}
1+
div>p.sveltecomponent-xyz{color:red}
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
<p class="svelte-xyz">this may or may not be styled</p>
1+
<p class="sveltecomponent-xyz">this may or may not be styled</p>
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
#foo.svelte-xyz{color:red}
1+
#foo.sveltecomponent-xyz{color:red}
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
1-
<div class="svelte-xyz" id="foo"></div>
1+
<div class="sveltecomponent-xyz" id="foo"></div>
22
<div id="bar"></div>
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
div.svelte-xyz section p.svelte-xyz{color:red}
1+
div.sveltecomponent-xyz section p.sveltecomponent-xyz{color:red}
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
<div class="svelte-xyz"><section><p class="svelte-xyz">this is styled</p></section></div>
1+
<div class="sveltecomponent-xyz"><section><p class="sveltecomponent-xyz">this is styled</p></section></div>
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
div.svelte-xyz p.svelte-xyz{color:red}
1+
div.sveltecomponent-xyz p.sveltecomponent-xyz{color:red}
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
<div class="svelte-xyz"><section><p class="svelte-xyz">this is styled</p></section></div>
1+
<div class="sveltecomponent-xyz"><section><p class="sveltecomponent-xyz">this is styled</p></section></div>
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
p.svelte-xyz{color:red}
1+
p.sveltecomponent-xyz{color:red}
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
<div><p class="svelte-xyz">this is styled</p></div>
1+
<div><p class="sveltecomponent-xyz">this is styled</p></div>
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
[svelte-ref-button].active.svelte-xyz{color:red}
1+
[svelte-ref-button].active.sveltecomponent-xyz{color:red}
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
<button svelte-ref-button="" class="active svelte-xyz">deactivate</button>
1+
<button svelte-ref-button="" class="active sveltecomponent-xyz">deactivate</button>

test/css/samples/refs/expected.css

+1-1
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
[svelte-ref-a].svelte-xyz{color:red}[svelte-ref-b].svelte-xyz{color:green}
1+
[svelte-ref-a].sveltecomponent-xyz{color:red}[svelte-ref-b].sveltecomponent-xyz{color:green}

test/css/samples/refs/expected.html

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
1-
<div class="svelte-xyz" svelte-ref-a=''></div>
2-
<div class="svelte-xyz" svelte-ref-b=''></div>
1+
<div class="sveltecomponent-xyz" svelte-ref-a=''></div>
2+
<div class="sveltecomponent-xyz" svelte-ref-b=''></div>
33
<div></div>
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
.svelte-xyz,.svelte-xyz *{color:red}
1+
.sveltecomponent-xyz,.sveltecomponent-xyz *{color:red}
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
div.svelte-xyz,.svelte-xyz div{@apply --funky-div;}
1+
div.sveltecomponent-xyz,.sveltecomponent-xyz div{@apply --funky-div;}
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
.bar.svelte-xyz{color:red}
1+
.bar.sveltecomponent-xyz{color:red}

0 commit comments

Comments
 (0)