├── .gitignore ├── LICENSE ├── README.md ├── examples ├── commits.html ├── components.html ├── grid.html ├── markdown.html ├── svg.html ├── todomvc.html └── tree.html ├── index.html ├── package.json ├── pnpm-lock.yaml ├── scripts └── release.js ├── src ├── app.ts ├── block.ts ├── context.ts ├── directives │ ├── bind.ts │ ├── effect.ts │ ├── for.ts │ ├── html.ts │ ├── if.ts │ ├── index.ts │ ├── model.ts │ ├── on.ts │ ├── ref.ts │ ├── show.ts │ └── text.ts ├── eval.ts ├── index.ts ├── scheduler.ts ├── utils.ts └── walk.ts ├── tests ├── bind.html ├── cloak.html ├── component.html ├── custom-delimiters.html ├── effect.html ├── for.html ├── html.html ├── if.html ├── model.html ├── multi-mount.html ├── on.html ├── once.html ├── pre.html ├── reactive.html ├── ref.html ├── scope.html ├── show.html └── text.html ├── tsconfig.json └── vite.config.ts /.gitignore: -------------------------------------------------------------------------------- 1 | TODOs.md 2 | node_modules 3 | dist 4 | explorations -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | The MIT License (MIT) 2 | 3 | Copyright (c) 2021-present, Yuxi (Evan) You 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in 13 | all copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 21 | THE SOFTWARE. 22 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # pico-vue 2 | 3 | `pico-vue` is a fork of `petite-vue`, which is an alternative distribution of [Vue](https://vuejs.org) optimized for [progressive enhancement](https://developer.mozilla.org/en-US/docs/Glossary/Progressive_Enhancement). It provides the same template syntax and reactivity mental model as standard Vue. However, it is specifically optimized for "sprinkling" a small amount of interactions on an existing HTML page rendered by a server framework. See more details on [how it differs from standard Vue](#comparison-with-standard-vue). 4 | 5 | - Only ~6kb 6 | - Vue-compatible template syntax 7 | - DOM-based, mutates in place 8 | - Driven by `@vue/reactivity` 9 | 10 | ## Status 11 | 12 | - `petite-vue` it's not mantained anymore, hence we will provide bug fixes and handle feature requests. Feel free to open issue or PR. 13 | - this fork is focused on web components, but we will provide new generic features too 14 | 15 | 16 | ## Usage 17 | 18 | `pico-vue` can be used without a build step. Simply load it from a CDN: 19 | 20 | ```html 21 | 22 | 23 | 24 |
25 | {{ count }} 26 | 27 |
28 | 29 | 30 | 36 | ``` 37 | 38 | - Use `v-scope` to mark regions on the page that should be controlled by `pico-vue`. 39 | - The `defer` attribute makes the script execute after HTML content is parsed. 40 | - The `init` attribute tells `pico-vue` to automatically query and initialize all elements that have `v-scope` on the page. 41 | 42 | ### Manual Init 43 | 44 | If you don't want the auto init, remove the `init` attribute and move the scripts to end of ``: 45 | 46 | ```html 47 | 48 | 51 | ``` 52 | 53 | Or, use the ES module build: 54 | 55 | ```html 56 | 60 | ``` 61 | 62 | ### Production CDN URLs 63 | 64 | The short CDN URL is meant for prototyping. For production usage, use a fully resolved CDN URL to avoid resolving and redirect cost: 65 | 66 | - Global build: `https://unpkg.com/pico-vue@1.0.3/dist/pico-vue.iife.js` 67 | - exposes `PetiteVue` global, supports auto init 68 | - ESM build: `https://unpkg.com/pico-vue@1.0.3/dist/pico-vue.es.js` 69 | - Must be used with ` 92 | 93 | 94 |
95 |

{{ count }}

96 |

{{ plusOne }}

97 | 98 |
99 | ``` 100 | 101 | Note `v-scope` doesn't need to have a value here and simply serves as a hint for `pico-vue` to process the element. 102 | 103 | ### Explicit Mount Target 104 | 105 | You can specify a mount target (selector or element) to limit `pico-vue` to only that region of the page: 106 | 107 | ```js 108 | createApp().mount('#only-this-div') 109 | ``` 110 | 111 | This also means you can have multiple `pico-vue` apps to control different regions on the same page: 112 | 113 | ```js 114 | createApp({ 115 | // root scope for app one 116 | }).mount('#app1') 117 | 118 | createApp({ 119 | // root scope for app two 120 | }).mount('#app2') 121 | ``` 122 | 123 | ### Components 124 | 125 | The concept of "Components" are different in `pico-vue`, as it is much more bare-bones. 126 | 127 | First, reusable scope logic can be created with functions: 128 | 129 | ```html 130 | 149 | 150 |
151 |

{{ count }}

152 | 153 |
154 | 155 |
156 |

{{ count }}

157 | 158 |
159 | ``` 160 | 161 | ### Components with Template 162 | 163 | If you also want to reuse a piece of template, you can provide a special `$template` key on a scope object. The value can be the template string, or an ID selector to a `