Skip to content

Commit

Permalink
Tree-counting Functions and Random Values (#244)
Browse files Browse the repository at this point in the history
  • Loading branch information
kizu authored Oct 22, 2024
1 parent 15334bc commit 753d5f4
Show file tree
Hide file tree
Showing 25 changed files with 4,379 additions and 4 deletions.
8 changes: 7 additions & 1 deletion gulpfile.js/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,12 @@ const hugoSrc = () => {
.pipe(gulp.dest('./build/hugo'));
};

const copyScripts = () => {
return gulp
.src('./node_modules/@kizu/custom-elements/src/**/*', { since: gulp.lastRun(copyScripts) })
.pipe(gulp.dest('./build/hugo/static/j/ce'));
};

// TODO: should handle .md and everything else differently
// at least, watcher should run incrementally for docs,
// but completely for dependant files.
Expand Down Expand Up @@ -121,7 +127,7 @@ const watchReloaded = () => {

// Defining tasks
gulp.task('styles', gulp.parallel(stylesFile, stylesSrc));
gulp.task('buildForHugo', gulp.parallel(hugoSrc, pages, documents, examples, scripts, 'styles'));
gulp.task('buildForHugo', gulp.parallel(hugoSrc, copyScripts, pages, documents, examples, scripts, 'styles'));
gulp.task('prepareHugo', gulp.series(clean, 'buildForHugo'));
gulp.task('build', gulp.series('prepareHugo', hugoBuild));

Expand Down
3 changes: 3 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -38,5 +38,8 @@
"rollup-plugin-terser": "^4.0.4",
"shelljs": "^0.8.1",
"yaml-front-matter": "^3.4.0"
},
"dependencies": {
"@kizu/custom-elements": "github:kizu/custom-elements#3e7a2f9915d813abebd1c7e281c75bb5153645dd"
}
}
6 changes: 6 additions & 0 deletions src/css/_custom-elements.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
input-scope,
input-source,
input-value,
clone-content {
display: contents;
}
12 changes: 12 additions & 0 deletions src/css/components/fieldsets.css
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,21 @@
display: flex;
flex-wrap: wrap;
gap: 0.5rem;
}

.fieldsets:first-child {
margin-block-end: 0.5rem;
}

.fieldsets:last-child {
margin-block-start: 0.5rem;
}

.fieldsets > * {
flex: 1 1 var(--min-width);
}

.fieldsets > .options {
flex-basis: 40%;
flex-grow: 1;
}
15 changes: 15 additions & 0 deletions src/css/components/figure.css
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,23 @@ figure {
box-shadow: 0 0 0 1px rgba(0, 0, 0, 0.2);
}

/* For debugging */
figure[data-src] {
position: relative;
}

figure[data-src]::before {
content: attr(data-src);
position: absolute;
bottom: 100%;
left: 0;
font-size: 0.5em;
line-height: 1;
}

aside > figure {
box-shadow: none;
background: none;
padding: 0;
margin-right: 0.5rem;
}
Expand Down
13 changes: 12 additions & 1 deletion src/css/main.css
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
@import url("_config.css");
@import url("_theme.css");
@import url("_utility.css");
@import url("_custom-elements.css");
@import url("components/color-components.css");

@import url("components/articlelist.css");
Expand Down Expand Up @@ -329,10 +330,16 @@ fieldset label {
display: inline-block;
}

fieldset label:not(:has(> :checked)) {
label:not(:has(> :checked)) {
cursor: pointer;
}

label:not(:hover):has(> input:hover),
/* Very specific, for the tree-counting-and-random article */
fieldset:not(:hover):has(> *:not(label) > *:not(label) > input:hover) {
outline: 4px solid var(--GREEN);
}

fieldset label > input {
cursor: inherit;
}
Expand All @@ -341,6 +348,10 @@ fieldset label:active {
user-select: none;
}

input[type=range] {
vertical-align: middle;
}

::selection {
text-shadow: none !important;
background-color: var(--THEME_SELECTION, #B1D2FB);
Expand Down
6 changes: 6 additions & 0 deletions src/hugo/layouts/_default/baseof.html
Original file line number Diff line number Diff line change
Expand Up @@ -76,5 +76,11 @@
</div>

{{ partial "web_components/mastodon_post_info.html" . }}
<script type="module">// @ts-check
import { CloneContent, InputSource, InputValue } from '/j/ce/index.js';
CloneContent.register();
InputSource.register();
InputValue.register();
</script>
</body>
</html>
4 changes: 3 additions & 1 deletion src/hugo/layouts/shortcodes/Partial.html
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,9 @@
{{- $id := (replace $file ".html" "") -}}
{{- $id = (replace $id "examples/" "") -}}
<figure
{{- if not hugo.IsProduction -}}
{{/**/}} data-src="{{ print $src }}"
{{- end -}}
{{- if .Get "class" -}}
{{/**/}} class="{{ print (.Get "class") }}"
{{- end -}}
Expand Down Expand Up @@ -54,7 +57,6 @@
{{- $src | readFile | safeHTML -}}
</div>
{{- end -}}
{{- .Inner | markdownify -}}
{{- end -}}

</figure>
Expand Down
2 changes: 1 addition & 1 deletion src/pages/_index.en.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ aliases: [/en/everything/]

# **Articles & Experiments** by <span class="p-name p-author">Roman Komarov</span>

Welcome! I’m Roman, a <span class="p-job-title">front-end web developer</span> at [Datadog](https://www.datadoghq.com/ "{:class='p-org'}"). <span class="p-note">I love <span class="p-category">CSS</span>, and most of the things I do, write, or think about are CSS-related.</span> On this site I collect my experiments and articles about it (and, occasionally, about some other topics).
Welcome! I’m Roman, a <span class="p-job-title">senior front-end engineer</span> at [Datadog](https://www.datadoghq.com/ "{:class='p-org'}"), and a member of [CSSWG](https://www.w3.org/groups/wg/css/). <span class="p-note">I love <span class="p-category">CSS</span>, and most of the things I do, write, or think about are CSS-related.</span> On this site, I collect my experiments and articles about it (and, occasionally, about some other topics).

{{<ArticleList>}}

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,145 @@
<style>
.algorithm-example {
max-height: 80vh;
position: relative;
overflow: auto;

& ol {
display: flex;
flex-wrap: wrap;
justify-content: space-between;
--gap: 0.5em;
gap: var(--gap);
}
& li {
padding: var(--gap);
border-radius: var(--gap);
background: color-mix(in oklch,
var(--GREEN) min(100%, var(--sibling-index) * 100%),
var(--PINK)
);

&::before {
position: static;
width: auto;
margin: 0;
}
&::after {
counter-reset: index var(--sibling-index);
content: counter(index);
}
}
}

.algorithm-1 {
& li:nth-child(1) { --sibling-index: 1 }
& li:nth-child(2) { --sibling-index: 2 }
& li:nth-child(3) { --sibling-index: 3 }
& li:nth-child(4) { --sibling-index: 4 }
& li:nth-child(5) { --sibling-index: 5 }
& li:nth-child(6) { --sibling-index: 6 }
& li:nth-child(7) { --sibling-index: 7 }
& li:nth-child(8) { --sibling-index: 8 }
& li:nth-child(9) { --sibling-index: 9 }
}

/* For easier debugging later */
@property --is-reversed {
syntax: "<integer>";
initial-value: 0;
inherits: true;
}
@property --diff {
syntax: "<integer>";
initial-value: 0;
inherits: true;
}
@property --sibling-index {
syntax: "<integer>";
initial-value: 0;
inherits: true;
}
@property --sibling-count {
syntax: "<integer>";
initial-value: 0;
inherits: true;
}
@property --children-count {
syntax: "<integer>";
initial-value: 0;
inherits: true;
}
@property --y-index {
syntax: "<integer>";
initial-value: 0;
inherits: true;
}
@property --x-index {
syntax: "<integer>";
initial-value: 0;
inherits: true;
}
@property --y-count {
syntax: "<integer>";
initial-value: 0;
inherits: true;
}
@property --x-count {
syntax: "<integer>";
initial-value: 0;
inherits: true;
}
@property --x-score {
syntax: "<number>";
initial-value: 0;
inherits: false;
}
@property --y-score {
syntax: "<number>";
initial-value: 0;
inherits: false;
}
@property --x-distance {
syntax: "<number>";
initial-value: 0;
inherits: false;
}
@property --y-distance {
syntax: "<number>";
initial-value: 0;
inherits: false;
}
</style>

<input-scope>
<div class="fieldsets">
<fieldset class="number-of-items">
<legend>Number of items</legend>
<input-value from=".number-of-items input" as="@value" to="input">
<input-source>
<input type="range" value="9" max="17" id="algorithm-1-range" />
</input-source>
<input-source>
<input type="number" value="9" min="0" max="17" size="2" />
</input-source>
</input-value>
</fieldset>
</div>
<input-value from=".number-of-items input" as="@count" to="clone-content">
<clone-content root="ol">
<div class="algorithm-example algorithm-1">
<ol>
<li></li>
<li></li>
<li></li>
<li></li>
<li></li>
<li></li>
<li></li>
<li></li>
<li></li>
</ol>
</div>
</clone-content>
</input-value>
</input-scope>
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
<style>
.algorithm-2 {
& li {
--si2: 0;
--si1: 0;
--sibling-index: calc(3 * var(--si2) + var(--si1));

}
& li:nth-child(3n+1) { --si1: 1 }
& li:nth-child(3n+2) { --si1: 2 }
& li:nth-child(n+3):nth-child(-n+5) { --si2: 1 }
& li:nth-child(n+6):nth-child(-n+8) { --si2: 2 }

/* Otherwise some of the broken items will be highlighted in green */
& li:nth-child(n+10) {
background: var(--PINK);
}
}
</style>

<input-scope>
<div class="fieldsets">
<fieldset class="number-of-items">
<legend>Number of items</legend>
<input-value from=".number-of-items input" as="@value" to="input">
<input-source>
<input type="range" value="9" max="17" />
</input-source>
<input-source>
<input type="number" value="9" min="0" max="17" size="2" />
</input-source>
</input-value>
</fieldset>
</div>
<input-value from=".number-of-items input" as="@count" to="clone-content">
<clone-content root="ol">
<div class="algorithm-example algorithm-2">
<ol>
<li></li>
<li></li>
<li></li>
<li></li>
<li></li>
<li></li>
<li></li>
<li></li>
<li></li>
</ol>
</div>
</clone-content>
</input-value>
</input-scope>
Loading

0 comments on commit 753d5f4

Please sign in to comment.