Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
108 changes: 51 additions & 57 deletions compiler/src/__snapshots__/compiler.test.ts.snap

Large diffs are not rendered by default.

28 changes: 14 additions & 14 deletions examples/coffeeshop/coffeeshop.squiffy
Original file line number Diff line number Diff line change
Expand Up @@ -30,13 +30,13 @@ In the corner booth, a woman in her late twenties hunches over a laptop, occasio

Who do you approach first?

[The woman with the laptop]
[[The woman with the laptop]]

[The older man by the window]
[[The older man by the window]]

[Wait for someone to come to you]
[[Wait for someone to come to you]]

[The woman with the laptop]:
[[The woman with the laptop]]:
@inc maya
You approach the corner booth. The woman looks up, startled, then breaks into a sheepish grin.

Expand All @@ -52,7 +52,7 @@ She grins. "Exactly. You're going to fit in fine here."

[[Continue morning]](morning continues)

[The older man by the window]:
[[The older man by the window]]:
@inc ellis
You approach the window table. The man looks up—early seventies, neatly dressed, with the kind of face that suggests he's forgotten how to smile but remembers that he used to.

Expand All @@ -68,7 +68,7 @@ You're not sure what to say to that.

[[Continue morning]](morning continues)

[Wait for someone to come to you]:
[[Wait for someone to come to you]]:
You busy yourself wiping down the already-clean counter. After a few minutes, the older man by the window raises his empty cup, catching your eye.

You head over. He's early seventies, neatly dressed.
Expand Down Expand Up @@ -100,11 +100,11 @@ The Daily Grind transforms at night. The overhead lights dim, fairy lights come

You spot a new face: early twenties, headphones around their neck, dark circles under their eyes. They're sketching something in a worn notebook, barely looking at the page.

[Bring them a menu]
[[Bring them a menu]]

[Wait for them to come up]
[[Wait for them to come up]]

[Bring them a menu]:
[[Bring them a menu]]:
@inc sam
You grab a menu and head over. They look up, startled—then pull out an earbud.

Expand All @@ -126,7 +126,7 @@ Sam immediately flips the notebook closed. "It's nothing. Just... keeps my hands

[[End of day one]]

[Wait for them to come up]:
[[Wait for them to come up]]:
Eventually they shuffle to the counter, headphones still half-on.

"Most caffeinated thing you have. Please."
Expand Down Expand Up @@ -218,11 +218,11 @@ You're wiping down tables when the door opens. Sam shuffles in, looking exhauste

{{#if (gt sam 0)}}"{{player_name}}." They manage a tired smile. "Please tell me you have coffee. And maybe a will to live. I'll take either."{{else}}"Coffee. Strongest you've got." They collapse into a chair.{{/if}}

[Check on Sam]
[[Check on Sam]]

[Give them space]
[[Give them space]]

[Check on Sam]:
[[Check on Sam]]:
You bring over their usual red-eye and slide into the seat across from them for a moment.

"You okay?"
Expand All @@ -242,7 +242,7 @@ But they don't put their headphones back on, and you take that as a good sign.{{

[[Closing time]]

[Give them space]:
[[Give them space]]:
You leave the coffee and step away. Some people need space more than conversation.

Sam catches your eye as you walk away and nods once—a small acknowledgment. They understand.
Expand Down
100 changes: 48 additions & 52 deletions examples/gameshow/gameshow.squiffy
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
@set score = 0
@set round = 0
@set patience = 3
{{set "availableRounds" (array "GENERAL KNOWLEDGE" "SCIENCE with PROFESSOR BOOM" "MYSTERY BOX" "THE AUDIENCE DECIDES")}}

**{{#animate "typewriter" interval=200}}WELCOME TO...{{/animate}}**

Expand All @@ -34,7 +35,6 @@ The audience—three people and a cardboard cutout—applauds uncertainly.
{{/animate}}

---
{{#if (not player_name)}}{{set "player_name" "Mystery Contestant"}}{{/if}}
@set round = 1

"Welcome, {{player_name}}! Or as I like to call you... {{player_name}}!"
Expand All @@ -59,7 +59,10 @@ A rusty wheel descends from the ceiling, wobbling dangerously. It has several qu
[[Spin the wheel!]]:
The wheel creaks to life, spinning with a sound like a shopping cart hitting a pothole.

It lands on... {{#animate "toast"}}{{sequence (array "GENERAL KNOWLEDGE" "SCIENCE with PROFESSOR BOOM" "MYSTERY BOX" "THE AUDIENCE DECIDES") set="category"}}!{{/animate}}
{{set "category" (random availableRounds)}}
{{remove "availableRounds" category}}

It lands on... {{#animate "toast"}}{{category}}!{{/animate}}

{{live "category" section="showCategory"}}

Expand Down Expand Up @@ -135,7 +138,7 @@ Hank backs away nervously. "Professor, we talked about bringing chemicals on set
Lab Stability: {{live "stability"}}%

Choose your answer:
- [Answer: Au]
- [[Answer: Au]]
- [Answer: Go]
- [Answer: Gd]
- [Drink the beaker]
Expand All @@ -154,15 +157,6 @@ Professor Boom: "HURRY! The compound is becoming... UNSTABLE!"

Small explosions begin occurring around the lab set.

[Answer: Au]:
{{#animate "toast"}}CORRECT!{{/animate}}

"AU! YES! Gold! Aurum! The element of CHAMPIONS!" Professor Boom throws the beaker in the air and catches it. "You have pleased me, {{player_name}}!"

{{inc "score" 200}}

[[Professor Exit]]

[Answer: Go]:
"GO?! That's not even— that's just the word GO!" Professor Boom's hair somehow becomes more wild.

Expand All @@ -177,16 +171,12 @@ A small explosion singes Hank's eyebrows.
"MY EYEBROWS! Those were RENTED!"
{{/if}}

[[Professor Exit]]

[Answer: Gd]:
"Gd is GADOLINIUM! An honest mistake for a FOOL!"

{{dec "stability" 20}}
{{dec "patience"}}

[[Professor Exit]]

[Drink the beaker]:
You grab the beaker and drink it before anyone can stop you.

Expand All @@ -199,9 +189,15 @@ Professor Boom: "WAIT! That's my lunch!"
{{inc "score" 50}}
The audience (including the cardboard) applauds your boldness.

[[Professor Exit]]
[[Answer: Au]]:
{{#animate "toast"}}CORRECT!{{/animate}}

"AU! YES! Gold! Aurum! The element of CHAMPIONS!" Professor Boom throws the beaker in the air and catches it. "You have pleased me, {{player_name}}!"

{{inc "score" 200}}

+++Continue...

[[Professor Exit]]:
Professor Boom descends back through the trapdoor, cackling.

"UNTIL NEXT TIME, QUIZ PARTICIPANT! REMEMBER: SCIENCE IS JUST EXPLOSIONS IN A LAB COAT!"
Expand All @@ -219,14 +215,14 @@ A golden box descends from the ceiling on a frayed rope.

The box rattles ominously.

[Open the box carefully]
[Shake the box first]
[Refuse to open it]
- [[Open the box carefully]]
- [[Shake the box first]]
- [[Refuse to open it]]

[Open the box carefully]:
[[Open the box carefully]]:
You lift the lid slowly...

{{random (array "prize" "bees" "another_box" "philosophy") set="box_contents"}}
{{set "box_contents" (random (array "prize" "bees" "another_box" "philosophy"))}}

{{#if (eq box_contents "prize")}}
{{#animate "toast"}}JACKPOT!{{/animate}}
Expand Down Expand Up @@ -276,23 +272,23 @@ Hank wipes away a single tear. "Beautiful."

[[Next Round]]

[Shake the box first]:
[[Shake the box first]]:
You shake the box vigorously. Something inside goes "CLANG" and then "moo?"

{{dec "patience"}}

"Please don't shake the— you know what, fine. Open it."

[Open the box carefully]
[[Open the box carefully]]

[Refuse to open it]:
[[Refuse to open it]]:
{{dec "patience"}}{{dec "patience"}}

"You HAVE to open it! It's the MYSTERY BOX! The mystery is legally required to be resolved!"

Hank is sweating now.

[Open the box carefully]
[[Open the box carefully]]

[[Audience Round]]:
"THE AUDIENCE DECIDES!" Hank gestures grandly at the three people and cardboard cutout.
Expand All @@ -301,30 +297,30 @@ Hank is sweating now.

The audience confers. One of them is asleep. The cardboard cutout offers no input.

Finally, a woman in the front row shouts: "MAKE THEM {{random (array "SING" "DANCE" "DO AN IMPRESSION OF A BLENDER" "JUST GIVE THEM POINTS FOR FREE")}}!"
Finally, a woman in the front row shouts: "MAKE THEM {{random (array "SING" "DANCE" "DO AN IMPRESSION OF A BLENDER" "JUST GIVE THEM POINTS FOR FREE") set="make_them"}}!"

{{#if (eq _last_random "SING")}}
{{#if (eq make_them "SING")}}
"You heard her! SING, {{player_name}}! Sing like your points depend on it! Because they do!"

[Sing beautifully]
[Sing terribly on purpose]
- [[Sing beautifully]]
- [[Sing terribly on purpose]]
{{/if}}

{{#if (eq _last_random "DANCE")}}
{{#if (eq make_them "DANCE")}}
"DANCE! Show us your moves!"

[Dance with enthusiasm]
[Do the robot]
- [[Dance with enthusiasm]]
- [[Do the robot]]
{{/if}}

{{#if (eq _last_random "DO AN IMPRESSION OF A BLENDER")}}
{{#if (eq make_them "DO AN IMPRESSION OF A BLENDER")}}
"A BLENDER! Do a blender impression! This is normal television!"

[WHIRRRRRR]
[Refuse on grounds of dignity]
- [[WHIRRRRRR]]
- [[Refuse on grounds of dignity]]
{{/if}}

{{#if (eq _last_random "JUST GIVE THEM POINTS FOR FREE")}}
{{#if (eq make_them "JUST GIVE THEM POINTS FOR FREE")}}
"Free points?! That's not how—" Hank checks his cards. "Actually, that IS an option apparently."

{{inc "score" 150}}
Expand All @@ -335,7 +331,7 @@ Finally, a woman in the front row shouts: "MAKE THEM {{random (array "SING" "DAN
[[Next Round]]
{{/if}}

[Sing beautifully]:
[[Sing beautifully]]:
You belt out an operatic rendition of the show's theme song (which you're making up as you go).

The audience is moved. One of them wakes up specifically to applaud.
Expand All @@ -345,7 +341,7 @@ The audience is moved. One of them wakes up specifically to applaud.

[[Next Round]]

[Sing terribly on purpose]:
[[Sing terribly on purpose]]:
You screech like a cat in a tumble dryer. On purpose. For art.

{{dec "patience"}}
Expand All @@ -356,23 +352,23 @@ Hank: "That was... that was really something. Moving on quickly."

[[Next Round]]

[Dance with enthusiasm]:
[[Dance with enthusiasm]]:
You dance like nobody's watching, except everyone is watching, and also there are cameras.

{{inc "score" 125}}
The cardboard cutout falls over again, but in an approving way.

[[Next Round]]

[Do the robot]:
[[Do the robot]]:
You do the robot so convincingly that a stagehand tries to unplug you.

{{inc "score" 100}}
{{#animate "toast"}}BEEP BOOP{{/animate}}

[[Next Round]]

[WHIRRRRRR]:
[[WHIRRRRRR]]:
You spin around making blender noises. It's deeply unsettling.

{{inc "score" 175}}
Expand All @@ -381,7 +377,7 @@ Professor Boom's voice echoes from below: "MAGNIFICENT!"

[[Next Round]]

[Refuse on grounds of dignity]:
[[Refuse on grounds of dignity]]:
"I'm not doing that."

{{dec "patience"}}
Expand All @@ -393,7 +389,7 @@ Hank: "Fair enough. Moving on with your dignity intact but your score unchanged.
[[Next Round]]:
@inc round

{{#if (gte round 3)}}
{{#if (eq (length "availableRounds") 0)}}
[[Final Round]]
{{else}}
Hank shuffles his cards. "Alright, {{player_name}}, ready for round {{round}}?"
Expand All @@ -418,19 +414,19 @@ The audience gasps. The cardboard cutout gasps (the AC kicked in).

{{#animate "typewriter"}}**What is the name of your host?**{{/animate}}

[Hank Spinneroni]
[Chuck Wheelsworth]
[I genuinely don't remember]
- [[Hank Spinneroni]]
- [[Chuck Wheelsworth]]
- [[I genuinely don't remember]]

[Hank Spinneroni]:
[[Hank Spinneroni]]:
"CORRECT! I AM HANK SPINNERONI! Probably!"

{{set "score" (score * 2)}}
{{inc "score" score}}
{{#animate "toast"}}SCORE DOUBLED!{{/animate}}

[[Ending]]

[Chuck Wheelsworth]:
[[Chuck Wheelsworth]]:
"That was my FIRST name! The WRONG first name! But you remembered SOMETHING!"

{{inc "score" 50}}
Expand All @@ -439,7 +435,7 @@ The audience gasps. The cardboard cutout gasps (the AC kicked in).

[[Ending]]

[I genuinely don't remember]:
[[I genuinely don't remember]]:
{{#if (lte patience 1)}}
Hank stares at you. A vein throbs in his forehead.

Expand Down
9 changes: 6 additions & 3 deletions runtime/src/plugins/animate.ts
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,11 @@ export function AnimatePlugin(): SquiffyPlugin {
continue;
}

// Capture content now, before setupInputValidation modifies the links
// with validation-disabled classes. This ensures when we restore the
// innerHTML after animation, users can still interact with the links.
const originalContent = el.innerHTML;

const runAnimation = () => {
if (params.loop) {
squiffy.animation.runAnimation(params.name, el, params, () => {}, true);
Expand All @@ -52,14 +57,12 @@ export function AnimatePlugin(): SquiffyPlugin {
}
squiffy.addTransition(() => {
return new Promise<void>((resolve) => {
const currentContent = el.innerHTML;

// Reset opacity so the animation can control visibility
el.style.opacity = "";

squiffy.animation.runAnimation(params.name, el, params, () => {
el.classList.remove("squiffy-animate");
el.innerHTML = currentContent;
el.innerHTML = originalContent;
resolve();
}, false);
});
Expand Down
Loading