Skip to content

Commit

Permalink
Merge pull request #399 from nuejs/dev
Browse files Browse the repository at this point in the history
Nue 1.0 (Release Candidate)
  • Loading branch information
tipiirai authored Nov 14, 2024
2 parents 9d031c5 + 422adc2 commit 03881a4
Show file tree
Hide file tree
Showing 330 changed files with 9,815 additions and 7,755 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -7,3 +7,4 @@ dist
.vscode
_test
coverage
performance.js
Binary file modified bun.lockb
Binary file not shown.
17 changes: 9 additions & 8 deletions packages/examples/simple-blog/@global/layout.css
Original file line number Diff line number Diff line change
Expand Up @@ -43,17 +43,18 @@ body {
/* global footer */
> footer {
border-top: 1px solid var(--gray-200);
justify-content: space-between;
margin-top: 6rem;
padding: 1rem 0;
display: flex;
margin-top: 8rem;

/* social icons */
> :last-child {
nav {
padding: 1rem 0;
display: flex;
gap: .5em;
a:hover {
transform: scale(1.1)

a { opacity: .8 }
a:hover { opacity: 1 }

a:nth-child(2) {
margin-left: auto;
}
}
}
Expand Down
7 changes: 7 additions & 0 deletions packages/examples/simple-blog/@global/layout.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
<header>
<navi :items="navigation.header"/>
</header>

<footer>
<navi :items="navigation.footer"/>
</footer>
7 changes: 3 additions & 4 deletions packages/examples/simple-blog/blog/color-strategies.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,12 @@ date: 2024-05-23

Working with color is one of the most fun parts of web design. But if you don't use them right in your CSS code, colors can also tank a site's usability and accessibility. In this post, we'll explore simple, real-world tips for effectively using color in your stylesheets.


``` css .blue
/* Tab styling */
[role=tablist] {
background: rgba(0, 0, 0, .7);
background-size: 3.5em;
background-size: 3.8em;
> padding: .7em 1.3em 0;
> overflow: hidden;
> display: flex;
Expand All @@ -40,9 +40,8 @@ Choosing the right colors for a website can be tricky. Get one wrong and your en

- **Consider tone and contrast** - Include light, medium and dark tones for visual interest. Test contrast for accessibility.


[image img/colors-1.png]
foo: bar


Considering the different formatting options, you can optimize CSS color usage for any need. Use hex for one-off values, RGBA where you need opacity control, HSL for color adjustments, variables for theming, and preprocessor operations for transformations. With the right format, implementing colors in CSS becomes much more flexible and manageable.

Expand Down
1 change: 0 additions & 1 deletion packages/examples/simple-blog/blog/hero.html
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@

<header @name="pagehead">
<h1>{ title }</h1>
<p>
Expand Down
24 changes: 12 additions & 12 deletions packages/examples/simple-blog/blog/scaleable-design-system.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,21 +18,21 @@ Design systems are key to managing code at scale, but creating one that’s flex
## Keep things minimal
It's important to keep things lightweight: Write CSS that’s DRY, separating structure from skin using methodologies like BEM. Don't over-engineer - keep logic simple.

[code numbered="true"]
<figure @name="img" :class="class" :id="id">
<img loading="lazy" :alt="alt" :src="_ || src">
``` html numbered
<figure @name="img" :class="class" :id="id">
<img loading="lazy" :alt="alt" :src="_ || src">

- <figcaption :if="caption">{{ caption }}</figcaption>
- <figcaption :if="caption">{{ caption }}</figcaption>

+ <p :if="caption">{{ caption }}</p>

<script>
constructor(data)• {
this.caption = data.caption || ''
}
</script>
</figure>
+ <p :if="caption">{{ caption }}</p>

<script>
constructor(data)• {
this.caption = data.caption || ''
}
</script>
</figure>
```

Use gradual rollouts: Introduce changes incrementally over time. Don't rebuild everything at once. Maintain backwards compatibility.

Expand Down
3 changes: 1 addition & 2 deletions packages/examples/simple-blog/index.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@

---
include: [ gallery, motion ]
content_collection: blog
Expand All @@ -8,4 +7,4 @@ content_collection: blog
I’m Emma Bennett, an user experience developer from Berlin. I build websites that are exceptionally well designed — inside, and outside.


[gallery]
[page-list]
12 changes: 6 additions & 6 deletions packages/examples/simple-blog/site.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ libs: ["@library"]
view_transitions: true
native_css_nesting: true
inline_css: true
sections: true

title_template: "Emma Bennet / %s"
og_image: /img/og_emma.png
Expand All @@ -17,23 +18,22 @@ port: 8083
origin: https://simple-blog.nuejs.org
og: /img/og.jpg

header:
navigation:

navigation:
header:
- Emma Bennet: /
- Contact: /contact/

footer:
copyright:
footer:
- © Emma Bennet: /

social:
- image: /img/twitter.svg
url: //x.com/tipiirai
alt: Twitter (X) profile
size: 22 x 22

- image: /img/github.svg
url: //github.com/nuejs/
url: //github.com/nuejs/nue/
alt: Github Projects
size: 22 x 22

Expand Down
1 change: 0 additions & 1 deletion packages/glow/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -67,4 +67,3 @@ const content = '...'

const html = marked.parse(content)
```

8 changes: 4 additions & 4 deletions packages/glow/package.json
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
{
"name": "nue-glow",
"version": "0.2.1",
"description": "Tiny and powerful Markdown syntax highlighter",
"homepage": "https://nuejs.org/blog/introducing-glow",
"version": "0.2.2",
"description": "Markdown syntax highlighter for CSS developers",
"homepage": "https://nuejs.org/blog/introducing-glow/",
"license": "MIT",
"type": "module",
"main": "index.js",
Expand All @@ -19,7 +19,7 @@
"test": "node --experimental-vm-modules ../../node_modules/jest/bin/jest.js --runInBand"
},
"devDependencies": {
"lightningcss": "^1.26.0"
"lightningcss": "^1.27.0"
},
"jest": {
"setupFilesAfterEnv": [
Expand Down
40 changes: 22 additions & 18 deletions packages/glow/src/glow.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@

const MIXED_HTML = ['html', 'jsx', 'php', 'astro', 'nue', 'vue', 'svelte', 'hb']
const MIXED_HTML = ['html', 'jsx', 'php', 'astro', 'dhtml', 'vue', 'svelte', 'hb']
const LINE_COMMENT = { clojure: ';;', lua: '--', python: '#' }
const PREFIXES = { '+': 'ins', '-': 'del', '>': 'dfn' }
const MARK = /(?)([^]+)\1/g // ALT + q
Expand Down Expand Up @@ -186,7 +186,7 @@ function renderString(str) {


// exported for testing purposes
export function renderRow(row, lang) {
export function renderRow(row, lang, mark=true) {
if (!row) return ''

const els = parseRow(row, lang)
Expand All @@ -211,8 +211,9 @@ export function renderRow(row, lang) {
}

ret.push(row.substring(index))
const res = ret.join('')

return ret.join('').replace(MARK, (_, a, b, c) => {
return !mark ? res : res.replace(MARK, (_, a, b, c) => {
return elem(a[1] ? 'u' : 'mark', b)
})
}
Expand All @@ -221,19 +222,19 @@ export function renderRow(row, lang) {
// comment start & end
const COMMENT = [/(\/\*|^ *{# |<!--|'''|=begin)/, /(\*\/|#}|-->|'''|=end)$/]

export function parseSyntax(str, lang) {
export function parseSyntax(lines, lang, prefix = true) {
const [comm_start, comm_end] = COMMENT
const lines = []
const html = []

// multi-line comment
let comment

function endComment() {
lines.push({ comment })
html.push({ comment })
comment = null
}

str.split(/\r\n|\r|\n/).forEach((line, i) => {
lines.forEach((line, i) => {
if (!comment) {
if (comm_start.test(line)) {
comment = [line]
Expand All @@ -242,13 +243,13 @@ export function parseSyntax(str, lang) {

// highlighted line
const c = line[0]
const wrap = isMD(lang) ? (c == '|' && 'dfn') : PREFIXES[c]
const wrap = prefix && (isMD(lang) ? (c == '|' && 'dfn') : PREFIXES[c])
if (wrap) line = (line[1] == ' ' ? ' ' : '') + line.slice(1)

// escape character
if (c == '\\') line = line.slice(1)
if (!prefix && c == '\\') line = line.slice(1)

lines.push({ line, wrap })
html.push({ line, wrap })
}

} else {
Expand All @@ -258,37 +259,40 @@ export function parseSyntax(str, lang) {
})


return lines
return html
}


// code, { language: 'js', numbered: true }
export function glow(str, opts = {}) {
export function glow(str, opts = { prefix: true, mark: true }) {
if (typeof opts == 'string') opts = { language: opts }
const lines = Array.isArray(str) ? str : str.trim().split(/\r\n|\r|\n/)

if (!lines[0]) return ''

// language
let lang = opts.language
if (!lang && str.trim()[0] == '<') lang = 'html'
const lines = []
if (!lang && lines[0][0] == '<') lang = 'html'
const html = []

function push(line) {
lines.push(opts.numbered ? elem('span', line) : line)
html.push(opts.numbered ? elem('span', line) : line)
}

parseSyntax(str.trim(), lang).forEach(function(block) {
parseSyntax(lines, lang, opts.prefix).forEach(function(block) {
let { line, comment, wrap } = block

// EOL comment
if (comment) {
return comment.forEach(el => push(elem('sup', encode(el))))

} else {
line = renderRow(line, lang)
line = renderRow(line, lang, opts.mark)
}

if (wrap) line = elem(wrap, line)
push(line)
})

return `<code language="${lang || '*'}">${lines.join(NL)}</code>`
return `<code language="${lang || '*'}">${html.join(NL)}</code>`
}
52 changes: 29 additions & 23 deletions packages/glow/test/glow.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,28 +27,34 @@ test('Emphasis', () => {


/* multiline comments */
const HTML_COMMENT = `
<div>
<!--
First
Second
-->
</div>`

const JS_COMMENT = `
/* First */
function() {
/*
Second
*/
}
`

test('extract comments', () => {
let blocks = parseSyntax(HTML_COMMENT.trim())
expect(blocks[1].comment[0]).toBe(' <!--')

blocks = parseSyntax(JS_COMMENT.trim())
test('parse HTML comment', () => {
const blocks = parseSyntax(['<div>', '<!--', 'comment', '-->', '</div>'])
expect(blocks[1].comment[0]).toBe('<!--')
})


test('parse JS comment', () => {
const blocks = parseSyntax(['/* First */', 'function() {', '/*', 'Second', '*/'])
expect(blocks[0].comment).toEqual(['/* First */'])
expect(blocks[2].comment[0]).toEqual(' /*')
expect(blocks[2].comment[0]).toEqual('/*')
})


/* prefix and mark */
test('disable mark', () => {
const html = renderRow('Hey •[img]• girl', undefined, false)
expect(html).toInclude('Hey •')
expect(html).toInclude('• girl')
})

test('disable prefixes', () => {
const blocks = parseSyntax([
'+ not really adding a line',
'- not really removing a line',
'> not really marking a line'
], undefined, false)

expect(blocks[0].wrap).toEqual(false)
expect(blocks[1].wrap).toEqual(false)
expect(blocks[2].wrap).toEqual(false)
})
2 changes: 1 addition & 1 deletion packages/nuejs.org/.gitignore
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
.dist
@lib/ping.js
@lib/ping.js
Loading

0 comments on commit 03881a4

Please sign in to comment.