qrdx 0.0.51 → 0.0.53
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +102 -6
- package/dist/angular.js +252 -0
- package/dist/angular.js.map +1 -0
- package/dist/angular.mjs +226 -0
- package/dist/angular.mjs.map +1 -0
- package/dist/core.js +7 -7
- package/dist/core.js.map +1 -1
- package/dist/core.mjs +7 -7
- package/dist/core.mjs.map +1 -1
- package/dist/element-define.browser.mjs +2 -0
- package/dist/element-define.browser.mjs.map +1 -0
- package/dist/element-define.js +2 -0
- package/dist/element-define.js.map +1 -0
- package/dist/element-define.mjs +2 -0
- package/dist/element-define.mjs.map +1 -0
- package/dist/element.browser.mjs +91 -0
- package/dist/element.browser.mjs.map +1 -0
- package/dist/element.js +2 -0
- package/dist/element.js.map +1 -0
- package/dist/element.mjs +2 -0
- package/dist/element.mjs.map +1 -0
- package/dist/frames-index.js +1 -1
- package/dist/frames-index.js.map +1 -1
- package/dist/frames-index.mjs +1 -1
- package/dist/frames-index.mjs.map +1 -1
- package/dist/frames-official.js +1 -1
- package/dist/frames-official.js.map +1 -1
- package/dist/frames-official.mjs +1 -1
- package/dist/frames-official.mjs.map +1 -1
- package/dist/index.js +7 -7
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +7 -7
- package/dist/index.mjs.map +1 -1
- package/dist/preact.js +2 -0
- package/dist/preact.js.map +1 -0
- package/dist/preact.mjs +2 -0
- package/dist/preact.mjs.map +1 -0
- package/dist/qr-code-canvas.js +1 -1
- package/dist/qr-code-canvas.js.map +1 -1
- package/dist/qr-code-canvas.mjs +1 -1
- package/dist/qr-code-canvas.mjs.map +1 -1
- package/dist/solid.js +2 -0
- package/dist/solid.js.map +1 -0
- package/dist/solid.mjs +2 -0
- package/dist/solid.mjs.map +1 -0
- package/dist/src/angular.d.ts +94 -0
- package/dist/src/element-define.d.ts +3 -0
- package/dist/src/element-define.d.ts.map +1 -0
- package/dist/src/element.d.ts +150 -0
- package/dist/src/element.d.ts.map +1 -0
- package/dist/src/engine.d.ts +3 -3
- package/dist/src/engine.d.ts.map +1 -1
- package/dist/src/frame-spec.d.ts +22 -4
- package/dist/src/frame-spec.d.ts.map +1 -1
- package/dist/src/frame-text.d.ts +19 -0
- package/dist/src/frame-text.d.ts.map +1 -0
- package/dist/src/frame.d.ts +25 -10
- package/dist/src/frame.d.ts.map +1 -1
- package/dist/src/frames/builtin.d.ts +53 -5
- package/dist/src/frames/builtin.d.ts.map +1 -1
- package/dist/src/frames/catalogue/all.d.ts.map +1 -1
- package/dist/src/frames/catalogue/automotive.d.ts.map +1 -1
- package/dist/src/frames/catalogue/counts.d.ts +6 -6
- package/dist/src/frames/catalogue/counts.d.ts.map +1 -1
- package/dist/src/frames/catalogue/events.d.ts.map +1 -1
- package/dist/src/frames/catalogue/holidays.d.ts.map +1 -1
- package/dist/src/frames/catalogue/index.d.ts.map +1 -1
- package/dist/src/frames/catalogue/places.d.ts.map +1 -1
- package/dist/src/frames/catalogue/seasons.d.ts.map +1 -1
- package/dist/src/frames/catalogue/tags.d.ts.map +1 -1
- package/dist/src/preact.d.ts +29 -0
- package/dist/src/preact.d.ts.map +1 -0
- package/dist/src/scan-score.d.ts +4 -3
- package/dist/src/scan-score.d.ts.map +1 -1
- package/dist/src/solid.d.ts +21 -0
- package/dist/src/solid.d.ts.map +1 -0
- package/dist/src/template/arrow.d.ts +0 -1
- package/dist/src/template/arrow.d.ts.map +1 -1
- package/dist/src/template/dot-ring-layout.d.ts +44 -0
- package/dist/src/template/dot-ring-layout.d.ts.map +1 -0
- package/dist/src/template/dot-ring.d.ts +41 -0
- package/dist/src/template/dot-ring.d.ts.map +1 -0
- package/dist/src/template/frame-template.d.ts +19 -0
- package/dist/src/template/frame-template.d.ts.map +1 -0
- package/dist/src/template/halloween.d.ts +0 -1
- package/dist/src/template/halloween.d.ts.map +1 -1
- package/dist/src/template/index.d.ts +1 -0
- package/dist/src/template/index.d.ts.map +1 -1
- package/dist/src/template/square-border.d.ts +0 -1
- package/dist/src/template/square-border.d.ts.map +1 -1
- package/dist/src/template/standard-box.d.ts +0 -1
- package/dist/src/template/standard-box.d.ts.map +1 -1
- package/dist/src/template/striked-box.d.ts +0 -1
- package/dist/src/template/striked-box.d.ts.map +1 -1
- package/dist/src/template-placement.d.ts +8 -0
- package/dist/src/template-placement.d.ts.map +1 -0
- package/dist/src/templates.d.ts.map +1 -1
- package/dist/types/frame-spec.d.ts +703 -14
- package/dist/types/frame-spec.d.ts.map +1 -1
- package/dist/types/index.js +2 -2
- package/dist/types/index.js.map +1 -1
- package/dist/types/index.mjs +2 -2
- package/dist/types/index.mjs.map +1 -1
- package/dist/types/qr.d.ts +137 -3
- package/dist/types/qr.d.ts.map +1 -1
- package/dist/types/template.d.ts +7 -0
- package/dist/types/template.d.ts.map +1 -1
- package/dist/vanilla.browser.mjs +32 -32
- package/dist/vanilla.browser.mjs.map +1 -1
- package/package.json +81 -5
- package/src/angular.ts +218 -0
- package/src/element-define.ts +9 -0
- package/src/element.ts +608 -0
- package/src/engine.ts +13 -2
- package/src/frame-spec.ts +331 -56
- package/src/frame-text.ts +111 -0
- package/src/frame.tsx +74 -287
- package/src/frames/builtin/badge.json +108 -0
- package/src/frames/builtin/banner-bottom.json +2 -1
- package/src/frames/builtin/banner-top-bottom.json +72 -0
- package/src/frames/builtin/banner-top.json +59 -0
- package/src/frames/builtin/border.json +62 -0
- package/src/frames/builtin/chat-bubble.json +54 -0
- package/src/frames/builtin/circle.json +2 -1
- package/src/frames/builtin/envelope.json +81 -0
- package/src/frames/builtin/focus.json +88 -0
- package/src/frames/builtin/gradient-border.json +76 -0
- package/src/frames/builtin/menu-card.json +108 -0
- package/src/frames/builtin/phone.json +75 -0
- package/src/frames/builtin/polaroid.json +56 -0
- package/src/frames/builtin/rounded-border.json +8 -4
- package/src/frames/builtin/speech-bubble-top.json +76 -0
- package/src/frames/builtin/speech-bubble.json +76 -0
- package/src/frames/builtin/sticker.json +78 -0
- package/src/frames/builtin/tag.json +55 -0
- package/src/frames/builtin.ts +181 -12
- package/src/frames/catalogue/all.ts +584 -0
- package/src/frames/catalogue/automotive.ts +2 -0
- package/src/frames/catalogue/counts.ts +6 -6
- package/src/frames/catalogue/events.ts +90 -0
- package/src/frames/catalogue/holidays.ts +336 -0
- package/src/frames/catalogue/index.ts +2733 -0
- package/src/frames/catalogue/places.ts +92 -0
- package/src/frames/catalogue/seasons.ts +64 -0
- package/src/frames/catalogue/tags.ts +384 -0
- package/src/frames/official/africa-day.json +110 -0
- package/src/frames/official/aquarium-feeding.json +113 -0
- package/src/frames/official/autumn-apple-picking.json +81 -0
- package/src/frames/official/autumn-mushroom.json +72 -0
- package/src/frames/official/autumn-pumpkin-patch.json +83 -0
- package/src/frames/official/avurudu-pot.json +87 -0
- package/src/frames/official/beach-conditions.json +113 -0
- package/src/frames/official/beach-info-sticker.json +81 -0
- package/src/frames/official/beach-lifeguard.json +71 -0
- package/src/frames/official/blood-donor-drop.json +87 -0
- package/src/frames/official/blood-donor-sticker.json +94 -0
- package/src/frames/official/book-day-arch.json +71 -0
- package/src/frames/official/book-day-list.json +114 -0
- package/src/frames/official/camp-check-in.json +74 -0
- package/src/frames/official/camp-fire-rules.json +114 -0
- package/src/frames/official/camp-map.json +85 -0
- package/src/frames/official/carnival-mask.json +76 -0
- package/src/frames/official/carnival-pass.json +85 -0
- package/src/frames/official/carnival-plume.json +71 -0
- package/src/frames/official/childrens-day-carp.json +114 -0
- package/src/frames/official/childrens-day-sticker.json +88 -0
- package/src/frames/official/chuseok-gift-tag.json +59 -0
- package/src/frames/official/chuseok-moon.json +99 -0
- package/src/frames/official/chuseok-songpyeon.json +114 -0
- package/src/frames/official/cowork-desk.json +82 -0
- package/src/frames/official/cowork-meeting-room.json +107 -0
- package/src/frames/official/dragon-boat-race.json +83 -0
- package/src/frames/official/dragon-boat-ticket.json +98 -0
- package/src/frames/official/dragon-boat-zongzi.json +81 -0
- package/src/frames/official/durga-puja-lotus.json +114 -0
- package/src/frames/official/dussehra-seal.json +187 -0
- package/src/frames/official/earth-day-globe.json +77 -0
- package/src/frames/official/earth-day-pledge.json +66 -0
- package/src/frames/official/earth-day-recycle.json +109 -0
- package/src/frames/official/enkutatash-daisy.json +87 -0
- package/src/frames/official/enkutatash-seal.json +179 -0
- package/src/frames/official/environment-day.json +83 -0
- package/src/frames/official/event-anniversary.json +107 -0
- package/src/frames/official/event-awards.json +93 -0
- package/src/frames/official/event-baby-gifts.json +113 -0
- package/src/frames/official/event-baby-shower.json +70 -0
- package/src/frames/official/event-birth-announcement.json +71 -0
- package/src/frames/official/event-book-fair.json +142 -0
- package/src/frames/official/event-booth.json +98 -0
- package/src/frames/official/event-craft-fair.json +96 -0
- package/src/frames/official/event-cupcake.json +81 -0
- package/src/frames/official/event-engagement.json +116 -0
- package/src/frames/official/event-film-festival.json +92 -0
- package/src/frames/official/event-food-festival.json +108 -0
- package/src/frames/official/event-fun-run.json +107 -0
- package/src/frames/official/event-gala.json +121 -0
- package/src/frames/official/event-game-night.json +97 -0
- package/src/frames/official/event-grad-diploma.json +126 -0
- package/src/frames/official/event-grad-party.json +108 -0
- package/src/frames/official/event-grad-seal.json +186 -0
- package/src/frames/official/event-grad-stream.json +94 -0
- package/src/frames/official/event-guest-book.json +121 -0
- package/src/frames/official/event-hackathon.json +82 -0
- package/src/frames/official/event-keynote.json +74 -0
- package/src/frames/official/event-match-lineup.json +66 -0
- package/src/frames/official/event-meetup.json +86 -0
- package/src/frames/official/event-memorial.json +124 -0
- package/src/frames/official/event-milestone.json +168 -0
- package/src/frames/official/event-night-market.json +88 -0
- package/src/frames/official/event-open-mic.json +94 -0
- package/src/frames/official/event-party-hat.json +74 -0
- package/src/frames/official/event-prom.json +82 -0
- package/src/frames/official/event-quince.json +70 -0
- package/src/frames/official/event-retirement.json +92 -0
- package/src/frames/official/event-reunion.json +98 -0
- package/src/frames/official/event-runner-tracker.json +101 -0
- package/src/frames/official/event-season-ticket.json +89 -0
- package/src/frames/official/event-session-feedback.json +89 -0
- package/src/frames/official/event-setlist.json +70 -0
- package/src/frames/official/event-short-films.json +113 -0
- package/src/frames/official/event-slides.json +85 -0
- package/src/frames/official/event-speaker-qa.json +112 -0
- package/src/frames/official/event-talent-show.json +130 -0
- package/src/frames/official/event-tour-merch.json +63 -0
- package/src/frames/official/event-tournament.json +98 -0
- package/src/frames/official/event-trivia.json +79 -0
- package/src/frames/official/event-workshop.json +127 -0
- package/src/frames/official/festa-della-repubblica.json +100 -0
- package/src/frames/official/festa-junina-bonfire.json +81 -0
- package/src/frames/official/festa-junina-corn.json +72 -0
- package/src/frames/official/festa-junina-flags.json +110 -0
- package/src/frames/official/fiestas-patrias-chile.json +76 -0
- package/src/frames/official/food-day-wheat.json +109 -0
- package/src/frames/official/freedom-day-south-africa.json +109 -0
- package/src/frames/official/ganesh-marigold.json +71 -0
- package/src/frames/official/ganesh-modak.json +81 -0
- package/src/frames/official/ganesh-pandal.json +109 -0
- package/src/frames/official/garden-plant-label.json +98 -0
- package/src/frames/official/german-unity-day.json +100 -0
- package/src/frames/official/green-ribbon.json +123 -0
- package/src/frames/official/gudi-padwa.json +81 -0
- package/src/frames/official/hanami-arch.json +71 -0
- package/src/frames/official/hanami-picnic.json +90 -0
- package/src/frames/official/hanami-sakura.json +81 -0
- package/src/frames/official/hari-raya-haji.json +122 -0
- package/src/frames/official/hari-raya-ketupat.json +81 -0
- package/src/frames/official/hari-raya-open-house.json +114 -0
- package/src/frames/official/hari-raya-pelita.json +77 -0
- package/src/frames/official/harvest-basket.json +87 -0
- package/src/frames/official/harvest-corn.json +115 -0
- package/src/frames/official/harvest-hay.json +89 -0
- package/src/frames/official/harvest-market.json +109 -0
- package/src/frames/official/hijri-new-year-stamp.json +77 -0
- package/src/frames/official/hijri-new-year.json +122 -0
- package/src/frames/official/historic-marker.json +176 -0
- package/src/frames/official/hostel-check-in.json +113 -0
- package/src/frames/official/hostel-house-rules.json +136 -0
- package/src/frames/official/hostel-local-tips.json +86 -0
- package/src/frames/official/independence-argentina.json +105 -0
- package/src/frames/official/independence-bangladesh.json +64 -0
- package/src/frames/official/independence-colombia.json +108 -0
- package/src/frames/official/independence-ghana.json +105 -0
- package/src/frames/official/independence-indonesia.json +92 -0
- package/src/frames/official/independence-nigeria.json +100 -0
- package/src/frames/official/independence-pakistan.json +95 -0
- package/src/frames/official/independence-peru.json +100 -0
- package/src/frames/official/independence-poland.json +92 -0
- package/src/frames/official/independence-ukraine.json +92 -0
- package/src/frames/official/inti-raymi-sun.json +183 -0
- package/src/frames/official/jamhuri-day.json +116 -0
- package/src/frames/official/janmashtami-feather.json +77 -0
- package/src/frames/official/janmashtami-flute.json +81 -0
- package/src/frames/official/juneteenth-seal.json +187 -0
- package/src/frames/official/juneteenth-star.json +81 -0
- package/src/frames/official/kindness-day.json +109 -0
- package/src/frames/official/kings-day-crown.json +88 -0
- package/src/frames/official/kwanzaa-bands.json +100 -0
- package/src/frames/official/kwanzaa-harvest.json +77 -0
- package/src/frames/official/kwanzaa-kinara.json +81 -0
- package/src/frames/official/lantern-festival-riddles.json +77 -0
- package/src/frames/official/lantern-festival-tangyuan.json +122 -0
- package/src/frames/official/library-catalog.json +120 -0
- package/src/frames/official/library-ebooks.json +107 -0
- package/src/frames/official/library-hours.json +107 -0
- package/src/frames/official/lohri-bonfire.json +81 -0
- package/src/frames/official/lohri-dhol.json +114 -0
- package/src/frames/official/loy-krathong-float.json +88 -0
- package/src/frames/official/loy-krathong-moon.json +96 -0
- package/src/frames/official/loy-krathong-program.json +128 -0
- package/src/frames/official/mardi-gras-seal.json +183 -0
- package/src/frames/official/marina-welcome.json +172 -0
- package/src/frames/official/maslenitsa-pancakes.json +81 -0
- package/src/frames/official/maslenitsa-sun.json +183 -0
- package/src/frames/official/mid-autumn-gift.json +105 -0
- package/src/frames/official/mid-autumn-lantern-walk.json +96 -0
- package/src/frames/official/mid-autumn-mooncake.json +81 -0
- package/src/frames/official/mid-autumn-rabbit.json +77 -0
- package/src/frames/official/mid-autumn-seal.json +178 -0
- package/src/frames/official/monsoon-boots.json +88 -0
- package/src/frames/official/monsoon-chai.json +82 -0
- package/src/frames/official/monsoon-cloud.json +114 -0
- package/src/frames/official/monsoon-paper-boat.json +71 -0
- package/src/frames/official/monsoon-umbrella.json +81 -0
- package/src/frames/official/muertos-marigold.json +87 -0
- package/src/frames/official/muertos-ofrenda.json +129 -0
- package/src/frames/official/muertos-pan.json +78 -0
- package/src/frames/official/muertos-papel-picado.json +120 -0
- package/src/frames/official/muertos-seal.json +185 -0
- package/src/frames/official/museum-artist-note.json +124 -0
- package/src/frames/official/museum-exhibit-label.json +106 -0
- package/src/frames/official/museum-gallery-map.json +99 -0
- package/src/frames/official/museum-ticket.json +86 -0
- package/src/frames/official/national-day-belgium.json +100 -0
- package/src/frames/official/national-day-singapore.json +120 -0
- package/src/frames/official/navratri-dandiya.json +88 -0
- package/src/frames/official/navratri-garba-pass.json +90 -0
- package/src/frames/official/navratri-lamp.json +72 -0
- package/src/frames/official/nowruz-goldfish.json +71 -0
- package/src/frames/official/nowruz-party.json +90 -0
- package/src/frames/official/nowruz-sabzeh.json +81 -0
- package/src/frames/official/nowruz-seal.json +187 -0
- package/src/frames/official/obon-lantern.json +81 -0
- package/src/frames/official/obon-sign.json +109 -0
- package/src/frames/official/ocean-day-waves.json +114 -0
- package/src/frames/official/onam-boat-race.json +83 -0
- package/src/frames/official/onam-kasavu.json +122 -0
- package/src/frames/official/onam-pookalam.json +175 -0
- package/src/frames/official/onam-sadya.json +114 -0
- package/src/frames/official/orthodox-christmas-candle.json +71 -0
- package/src/frames/official/orthodox-christmas-star.json +76 -0
- package/src/frames/official/orthodox-easter-arch.json +77 -0
- package/src/frames/official/orthodox-easter-pysanka.json +87 -0
- package/src/frames/official/orthodox-easter-seal.json +185 -0
- package/src/frames/official/pancake-day.json +114 -0
- package/src/frames/official/park-bench-walks.json +121 -0
- package/src/frames/official/park-dog-rules.json +88 -0
- package/src/frames/official/park-map.json +92 -0
- package/src/frames/official/park-playground.json +64 -0
- package/src/frames/official/park-report.json +118 -0
- package/src/frames/official/parking-find-car.json +89 -0
- package/src/frames/official/peace-day-dove.json +66 -0
- package/src/frames/official/pink-ribbon-seal.json +180 -0
- package/src/frames/official/pink-ribbon.json +82 -0
- package/src/frames/official/pohela-boishakh-mela.json +116 -0
- package/src/frames/official/pohela-boishakh.json +120 -0
- package/src/frames/official/pongal-offers.json +120 -0
- package/src/frames/official/pongal-pot.json +81 -0
- package/src/frames/official/pongal-sun.json +183 -0
- package/src/frames/official/posadas-candle.json +71 -0
- package/src/frames/official/posadas-pinata.json +114 -0
- package/src/frames/official/pride-flag.json +124 -0
- package/src/frames/official/pride-heart.json +83 -0
- package/src/frames/official/pride-rainbow.json +81 -0
- package/src/frames/official/purim-mask.json +109 -0
- package/src/frames/official/purim-pastry.json +71 -0
- package/src/frames/official/puthandu-sun.json +101 -0
- package/src/frames/official/rakhi-envelope.json +75 -0
- package/src/frames/official/rakhi-gift-tag.json +59 -0
- package/src/frames/official/rakhi-thread.json +114 -0
- package/src/frames/official/ramadan-dates.json +81 -0
- package/src/frames/official/ramadan-suhoor.json +94 -0
- package/src/frames/official/red-ribbon.json +66 -0
- package/src/frames/official/republic-day-india-bands.json +120 -0
- package/src/frames/official/republic-day-india.json +182 -0
- package/src/frames/official/reyes-crown.json +78 -0
- package/src/frames/official/reyes-rosca.json +89 -0
- package/src/frames/official/rosh-hashanah-apple.json +81 -0
- package/src/frames/official/rosh-hashanah-honey.json +71 -0
- package/src/frames/official/rosh-hashanah-shofar.json +128 -0
- package/src/frames/official/sankranti-kite.json +114 -0
- package/src/frames/official/sankranti-sky.json +98 -0
- package/src/frames/official/sankranti-sticker.json +90 -0
- package/src/frames/official/school-backpack.json +81 -0
- package/src/frames/official/school-bus-routes.json +83 -0
- package/src/frames/official/school-lunch-menu.json +81 -0
- package/src/frames/official/school-uniform.json +109 -0
- package/src/frames/official/school-welcome-apple.json +71 -0
- package/src/frames/official/seollal-knot.json +122 -0
- package/src/frames/official/sham-el-nessim.json +81 -0
- package/src/frames/official/shogatsu-kadomatsu.json +81 -0
- package/src/frames/official/songkran-bands.json +123 -0
- package/src/frames/official/songkran-bowl.json +81 -0
- package/src/frames/official/songkran-drop.json +90 -0
- package/src/frames/official/songkran-waves.json +96 -0
- package/src/frames/official/spring-cleaning.json +107 -0
- package/src/frames/official/spring-showers.json +71 -0
- package/src/frames/official/spring-watering-can.json +114 -0
- package/src/frames/official/summer-camp.json +90 -0
- package/src/frames/official/summer-pool.json +95 -0
- package/src/frames/official/summer-reading.json +81 -0
- package/src/frames/official/summer-sunglasses.json +114 -0
- package/src/frames/official/summer-watermelon.json +89 -0
- package/src/frames/official/tabaski.json +114 -0
- package/src/frames/official/tanabata-stars.json +170 -0
- package/src/frames/official/tanabata-wishes.json +114 -0
- package/src/frames/official/teachers-day-apple.json +81 -0
- package/src/frames/official/teachers-day-note.json +109 -0
- package/src/frames/official/tet-apricot.json +114 -0
- package/src/frames/official/tet-banh-chung.json +81 -0
- package/src/frames/official/transit-bike-share.json +94 -0
- package/src/frames/official/transit-bus-arrivals.json +113 -0
- package/src/frames/official/transit-fare.json +97 -0
- package/src/frames/official/transit-ferry.json +88 -0
- package/src/frames/official/transit-next-trains.json +119 -0
- package/src/frames/official/transit-report.json +99 -0
- package/src/frames/official/transit-train-timetable.json +98 -0
- package/src/frames/official/ugadi-leaves.json +66 -0
- package/src/frames/official/vaisakhi-bands.json +120 -0
- package/src/frames/official/vaisakhi-dhol.json +81 -0
- package/src/frames/official/vaisakhi-wheat.json +73 -0
- package/src/frames/official/vesak-candle.json +122 -0
- package/src/frames/official/vesak-lantern.json +114 -0
- package/src/frames/official/vesak-lotus.json +71 -0
- package/src/frames/official/vesak-seal.json +179 -0
- package/src/frames/official/visitor-info.json +78 -0
- package/src/frames/official/visitor-town-map.json +108 -0
- package/src/frames/official/visitor-wildlife.json +70 -0
- package/src/frames/official/water-day-drop.json +81 -0
- package/src/frames/official/wifi-cafe-cup.json +81 -0
- package/src/frames/official/wifi-cowork.json +63 -0
- package/src/frames/official/wifi-hostel-board.json +80 -0
- package/src/frames/official/wifi-library.json +96 -0
- package/src/frames/official/wifi-reception.json +118 -0
- package/src/frames/official/wifi-rental.json +91 -0
- package/src/frames/official/wifi-venue.json +80 -0
- package/src/frames/official/wifi-waiting-room.json +89 -0
- package/src/frames/official/winter-lift-pass.json +90 -0
- package/src/frames/official/winter-sale.json +120 -0
- package/src/frames/official/winter-skating.json +71 -0
- package/src/frames/official/winter-snowman.json +81 -0
- package/src/frames/official/womens-day-mimosa.json +81 -0
- package/src/frames/official/womens-day-seal.json +179 -0
- package/src/frames/official/yalda-poem.json +122 -0
- package/src/frames/official/yalda-pomegranate.json +81 -0
- package/src/frames/official/yalda-watermelon.json +72 -0
- package/src/frames/official/yoga-day-lotus.json +81 -0
- package/src/frames/official/zoo-animal-facts.json +109 -0
- package/src/preact.ts +80 -0
- package/src/scan-score.ts +14 -7
- package/src/solid.ts +75 -0
- package/src/template/arrow.ts +14 -0
- package/src/template/dot-ring-layout.ts +230 -0
- package/src/template/dot-ring.tsx +165 -0
- package/src/template/frame-template.tsx +70 -0
- package/src/template/halloween.ts +14 -0
- package/src/template/index.ts +1 -0
- package/src/template/specs/arrow.json +26 -0
- package/src/template/specs/halloween.json +144 -0
- package/src/template/specs/square-border.json +27 -0
- package/src/template/specs/standard-box.json +31 -0
- package/src/template/specs/striked-box.json +56 -0
- package/src/template/square-border.ts +14 -0
- package/src/template/standard-box.ts +14 -0
- package/src/template/striked-box.ts +14 -0
- package/src/template-placement.ts +149 -0
- package/src/templates.tsx +16 -1
- package/types/frame-spec.ts +278 -11
- package/types/qr.ts +1 -1
- package/types/template.ts +7 -0
- package/dist/src/frame-styles.d.ts +0 -50
- package/dist/src/frame-styles.d.ts.map +0 -1
- package/src/frame-styles.ts +0 -1095
- package/src/template/arrow.tsx +0 -40
- package/src/template/halloween.tsx +0 -147
- package/src/template/square-border.tsx +0 -43
- package/src/template/standard-box.tsx +0 -43
- package/src/template/striked-box.tsx +0 -42
package/src/element.ts
ADDED
|
@@ -0,0 +1,608 @@
|
|
|
1
|
+
// qrdx/element: the <qrdx-code> custom element, a QR code in any page or
|
|
2
|
+
// framework. The class draws through qrdx/core into its shadow root;
|
|
3
|
+
// `defineQRdxCode()` registers it (importing this module never does), and
|
|
4
|
+
// `toQRdxCodeHTML()` writes server markup with a declarative shadow root, so
|
|
5
|
+
// the code shows before any script runs.
|
|
6
|
+
|
|
7
|
+
import {
|
|
8
|
+
createQRCodeTree,
|
|
9
|
+
DEFAULT_SIZE,
|
|
10
|
+
type DownloadFormat,
|
|
11
|
+
downloadQRCode,
|
|
12
|
+
getQRCodeDataUrl,
|
|
13
|
+
type QRProps,
|
|
14
|
+
type QRSVGOptions,
|
|
15
|
+
renderToDOM,
|
|
16
|
+
renderToString,
|
|
17
|
+
} from "./core";
|
|
18
|
+
import type { QRCodeDownloadOptions, QRCodeExportOptions } from "./vanilla-api";
|
|
19
|
+
|
|
20
|
+
/** What a `<qrdx-code>` draws with: `QRSVGOptions`, with `value` optional. */
|
|
21
|
+
export type QRdxCodeOptions = Partial<QRSVGOptions>;
|
|
22
|
+
|
|
23
|
+
/** The element's properties (attributes write the simple ones too). */
|
|
24
|
+
export interface QRdxCodeProperties {
|
|
25
|
+
value?: QRProps["value"];
|
|
26
|
+
size?: QRProps["size"];
|
|
27
|
+
level?: QRProps["level"];
|
|
28
|
+
fgColor?: QRProps["fgColor"];
|
|
29
|
+
bgColor?: QRProps["bgColor"];
|
|
30
|
+
eyeColor?: QRProps["eyeColor"];
|
|
31
|
+
dotColor?: QRProps["dotColor"];
|
|
32
|
+
bodyPattern?: QRProps["bodyPattern"];
|
|
33
|
+
cornerEyePattern?: QRProps["cornerEyePattern"];
|
|
34
|
+
cornerEyeDotPattern?: QRProps["cornerEyeDotPattern"];
|
|
35
|
+
margin?: QRProps["margin"];
|
|
36
|
+
templateId?: QRProps["templateId"];
|
|
37
|
+
moduleScale?: QRProps["moduleScale"];
|
|
38
|
+
autoLevel?: QRProps["autoLevel"];
|
|
39
|
+
shape?: QRProps["shape"];
|
|
40
|
+
frame?: QRProps["frame"];
|
|
41
|
+
imageSettings?: QRProps["imageSettings"];
|
|
42
|
+
eyeColors?: QRProps["eyeColors"];
|
|
43
|
+
art?: QRProps["art"];
|
|
44
|
+
customTemplate?: QRProps["customTemplate"];
|
|
45
|
+
customProps?: QRProps["customProps"];
|
|
46
|
+
/** Every option at once; the named properties and attributes win over it */
|
|
47
|
+
props?: QRdxCodeOptions;
|
|
48
|
+
/** What screen readers announce (default "QR code") */
|
|
49
|
+
label?: string;
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
/** The element's attributes, as JSX props (React 19 and Preact set them as attributes). */
|
|
53
|
+
export interface QRdxCodeAttributes {
|
|
54
|
+
value?: string;
|
|
55
|
+
size?: number | string;
|
|
56
|
+
level?: string;
|
|
57
|
+
"fg-color"?: string;
|
|
58
|
+
"bg-color"?: string;
|
|
59
|
+
"eye-color"?: string;
|
|
60
|
+
"dot-color"?: string;
|
|
61
|
+
"body-pattern"?: string;
|
|
62
|
+
"corner-eye-pattern"?: string;
|
|
63
|
+
"corner-eye-dot-pattern"?: string;
|
|
64
|
+
margin?: number | string;
|
|
65
|
+
"template-id"?: string;
|
|
66
|
+
"module-scale"?: number | string;
|
|
67
|
+
"auto-level"?: boolean | string;
|
|
68
|
+
shape?: string;
|
|
69
|
+
label?: string;
|
|
70
|
+
/** Options as JSON, for markup without script */
|
|
71
|
+
props?: string;
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
/**
|
|
75
|
+
* Props for typing `<qrdx-code>` in JSX: the attributes plus the
|
|
76
|
+
* properties (React 19 sets a prop as a property when the element has it).
|
|
77
|
+
*/
|
|
78
|
+
export type QRdxCodeJSXProps = Omit<QRdxCodeAttributes, "props"> &
|
|
79
|
+
Omit<QRdxCodeProperties, "props"> & {
|
|
80
|
+
props?: QRdxCodeOptions | string;
|
|
81
|
+
};
|
|
82
|
+
|
|
83
|
+
/** Detail of the `qrdx-error` event. */
|
|
84
|
+
export interface QRdxCodeErrorDetail {
|
|
85
|
+
error: unknown;
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
type OptionKey = Exclude<keyof QRdxCodeProperties, "props" | "label">;
|
|
89
|
+
type AttributeKind = "string" | "number" | "level" | "boolean";
|
|
90
|
+
|
|
91
|
+
/** Attributes and the option each one sets. */
|
|
92
|
+
const ATTRIBUTES: Record<string, [OptionKey, AttributeKind]> = {
|
|
93
|
+
value: ["value", "string"],
|
|
94
|
+
size: ["size", "number"],
|
|
95
|
+
level: ["level", "level"],
|
|
96
|
+
"fg-color": ["fgColor", "string"],
|
|
97
|
+
"bg-color": ["bgColor", "string"],
|
|
98
|
+
"eye-color": ["eyeColor", "string"],
|
|
99
|
+
"dot-color": ["dotColor", "string"],
|
|
100
|
+
"body-pattern": ["bodyPattern", "string"],
|
|
101
|
+
"corner-eye-pattern": ["cornerEyePattern", "string"],
|
|
102
|
+
"corner-eye-dot-pattern": ["cornerEyeDotPattern", "string"],
|
|
103
|
+
margin: ["margin", "number"],
|
|
104
|
+
"template-id": ["templateId", "string"],
|
|
105
|
+
"module-scale": ["moduleScale", "number"],
|
|
106
|
+
"auto-level": ["autoLevel", "boolean"],
|
|
107
|
+
shape: ["shape", "string"],
|
|
108
|
+
};
|
|
109
|
+
|
|
110
|
+
/** Options that are properties of the element. */
|
|
111
|
+
const OPTION_KEYS: readonly OptionKey[] = [
|
|
112
|
+
...Object.values(ATTRIBUTES).map(([key]) => key),
|
|
113
|
+
"frame",
|
|
114
|
+
"imageSettings",
|
|
115
|
+
"eyeColors",
|
|
116
|
+
"art",
|
|
117
|
+
"customTemplate",
|
|
118
|
+
"customProps",
|
|
119
|
+
];
|
|
120
|
+
|
|
121
|
+
const LEVELS = new Set(["L", "M", "Q", "H"]);
|
|
122
|
+
const DEFAULT_LABEL = "QR code";
|
|
123
|
+
const ELEMENT_MARK: unique symbol = Symbol.for("qrdx.code-element");
|
|
124
|
+
// Lowercase letter first and at least one hyphen. Written as dash-led
|
|
125
|
+
// segments that can't contain a dash, so there's one way to match and no
|
|
126
|
+
// quadratic backtracking on long names full of hyphens.
|
|
127
|
+
const CUSTOM_ELEMENT_NAME = /^[a-z][a-z0-9._]*(?:-[a-z0-9._]*)+$/;
|
|
128
|
+
|
|
129
|
+
/** The shadow root's stylesheet. */
|
|
130
|
+
export const QRDX_CODE_STYLES =
|
|
131
|
+
":host{display:inline-block}:host([hidden]){display:none}svg{display:block;max-width:100%;height:auto}";
|
|
132
|
+
|
|
133
|
+
function parseAttribute(kind: AttributeKind, raw: string): unknown {
|
|
134
|
+
switch (kind) {
|
|
135
|
+
case "number": {
|
|
136
|
+
const number = raw.trim() === "" ? Number.NaN : Number(raw);
|
|
137
|
+
return Number.isFinite(number) ? number : undefined;
|
|
138
|
+
}
|
|
139
|
+
case "level": {
|
|
140
|
+
const level = raw.trim().toUpperCase();
|
|
141
|
+
return LEVELS.has(level) ? level : undefined;
|
|
142
|
+
}
|
|
143
|
+
case "boolean":
|
|
144
|
+
return raw !== "false";
|
|
145
|
+
default:
|
|
146
|
+
return raw;
|
|
147
|
+
}
|
|
148
|
+
}
|
|
149
|
+
|
|
150
|
+
/** Options without the keys set to undefined or null. */
|
|
151
|
+
function compact(options: Record<string, unknown>): QRdxCodeOptions {
|
|
152
|
+
const result: Record<string, unknown> = {};
|
|
153
|
+
for (const key of Object.keys(options)) {
|
|
154
|
+
if (options[key] !== undefined && options[key] !== null) {
|
|
155
|
+
result[key] = options[key];
|
|
156
|
+
}
|
|
157
|
+
}
|
|
158
|
+
return result as QRdxCodeOptions;
|
|
159
|
+
}
|
|
160
|
+
|
|
161
|
+
/** The label screen readers get: never the encoded value, which may be private. */
|
|
162
|
+
function labelFor(options: QRdxCodeOptions, label: string | undefined) {
|
|
163
|
+
const fromOptions = options["aria-label"];
|
|
164
|
+
return (
|
|
165
|
+
label?.trim() ||
|
|
166
|
+
(typeof fromOptions === "string" && fromOptions.trim()) ||
|
|
167
|
+
DEFAULT_LABEL
|
|
168
|
+
);
|
|
169
|
+
}
|
|
170
|
+
|
|
171
|
+
/** The options the shadow root's `<svg>` is drawn with. */
|
|
172
|
+
function drawnOptions(
|
|
173
|
+
options: QRSVGOptions,
|
|
174
|
+
label: string | undefined
|
|
175
|
+
): QRSVGOptions {
|
|
176
|
+
return {
|
|
177
|
+
...options,
|
|
178
|
+
part: "svg",
|
|
179
|
+
role: "img",
|
|
180
|
+
"aria-label": labelFor(options, label),
|
|
181
|
+
};
|
|
182
|
+
}
|
|
183
|
+
|
|
184
|
+
const exportSize = (options: QRSVGOptions, size?: number) => {
|
|
185
|
+
const side = size ?? options.size ?? DEFAULT_SIZE;
|
|
186
|
+
return { width: side, height: side };
|
|
187
|
+
};
|
|
188
|
+
|
|
189
|
+
// Servers have no HTMLElement; the class still loads there, so importing
|
|
190
|
+
// qrdx/element during server rendering is safe.
|
|
191
|
+
const BaseElement: typeof HTMLElement =
|
|
192
|
+
typeof HTMLElement === "undefined"
|
|
193
|
+
? (class {} as unknown as typeof HTMLElement)
|
|
194
|
+
: HTMLElement;
|
|
195
|
+
|
|
196
|
+
/**
|
|
197
|
+
* `<qrdx-code>`: a QR code drawn into the element's shadow root. Simple
|
|
198
|
+
* options are attributes (`value`, `size`, `level`, `fg-color`,
|
|
199
|
+
* `body-pattern`…); object options (`frame`, gradients, `imageSettings`) are
|
|
200
|
+
* properties, or all at once in `props`. Changes are batched and redrawn
|
|
201
|
+
* once, in a microtask. Style the code with `qrdx-code::part(svg)`.
|
|
202
|
+
*/
|
|
203
|
+
export class QRdxCodeElement extends BaseElement {
|
|
204
|
+
static readonly observedAttributes = [
|
|
205
|
+
...Object.keys(ATTRIBUTES),
|
|
206
|
+
"label",
|
|
207
|
+
"props",
|
|
208
|
+
];
|
|
209
|
+
|
|
210
|
+
/** Marks qrdx's element class, across copies of the package. */
|
|
211
|
+
static readonly [ELEMENT_MARK] = true;
|
|
212
|
+
|
|
213
|
+
declare value: QRdxCodeProperties["value"];
|
|
214
|
+
declare size: QRdxCodeProperties["size"];
|
|
215
|
+
declare level: QRdxCodeProperties["level"];
|
|
216
|
+
declare fgColor: QRdxCodeProperties["fgColor"];
|
|
217
|
+
declare bgColor: QRdxCodeProperties["bgColor"];
|
|
218
|
+
declare eyeColor: QRdxCodeProperties["eyeColor"];
|
|
219
|
+
declare dotColor: QRdxCodeProperties["dotColor"];
|
|
220
|
+
declare bodyPattern: QRdxCodeProperties["bodyPattern"];
|
|
221
|
+
declare cornerEyePattern: QRdxCodeProperties["cornerEyePattern"];
|
|
222
|
+
declare cornerEyeDotPattern: QRdxCodeProperties["cornerEyeDotPattern"];
|
|
223
|
+
declare margin: QRdxCodeProperties["margin"];
|
|
224
|
+
declare templateId: QRdxCodeProperties["templateId"];
|
|
225
|
+
declare moduleScale: QRdxCodeProperties["moduleScale"];
|
|
226
|
+
declare autoLevel: QRdxCodeProperties["autoLevel"];
|
|
227
|
+
declare shape: QRdxCodeProperties["shape"];
|
|
228
|
+
declare frame: QRdxCodeProperties["frame"];
|
|
229
|
+
declare imageSettings: QRdxCodeProperties["imageSettings"];
|
|
230
|
+
declare eyeColors: QRdxCodeProperties["eyeColors"];
|
|
231
|
+
declare art: QRdxCodeProperties["art"];
|
|
232
|
+
declare customTemplate: QRdxCodeProperties["customTemplate"];
|
|
233
|
+
declare customProps: QRdxCodeProperties["customProps"];
|
|
234
|
+
|
|
235
|
+
readonly #root: ShadowRoot;
|
|
236
|
+
readonly #values: Partial<Record<OptionKey, unknown>> = {};
|
|
237
|
+
#props: QRdxCodeOptions | undefined;
|
|
238
|
+
#label: string | undefined;
|
|
239
|
+
#svg: SVGSVGElement | null = null;
|
|
240
|
+
#markup = "";
|
|
241
|
+
#dirty = true;
|
|
242
|
+
#queued = false;
|
|
243
|
+
|
|
244
|
+
static {
|
|
245
|
+
for (const key of OPTION_KEYS) {
|
|
246
|
+
Object.defineProperty(QRdxCodeElement.prototype, key, {
|
|
247
|
+
configurable: true,
|
|
248
|
+
enumerable: true,
|
|
249
|
+
get(this: QRdxCodeElement) {
|
|
250
|
+
return this.#values[key];
|
|
251
|
+
},
|
|
252
|
+
set(this: QRdxCodeElement, value: unknown) {
|
|
253
|
+
this.#set(key, value);
|
|
254
|
+
},
|
|
255
|
+
});
|
|
256
|
+
}
|
|
257
|
+
}
|
|
258
|
+
|
|
259
|
+
constructor() {
|
|
260
|
+
super();
|
|
261
|
+
// A server-rendered (declarative) shadow root is reused, and its <svg>
|
|
262
|
+
// replaced by the first render.
|
|
263
|
+
this.#root = this.shadowRoot ?? this.attachShadow({ mode: "open" });
|
|
264
|
+
let style: HTMLStyleElement | null = null;
|
|
265
|
+
for (const child of Array.from(this.#root.children)) {
|
|
266
|
+
if (child.localName === "style") {
|
|
267
|
+
style = child as HTMLStyleElement;
|
|
268
|
+
} else if (child.localName === "svg") {
|
|
269
|
+
this.#svg = child as SVGSVGElement;
|
|
270
|
+
}
|
|
271
|
+
}
|
|
272
|
+
if (!style) {
|
|
273
|
+
style = this.ownerDocument.createElement("style");
|
|
274
|
+
style.textContent = QRDX_CODE_STYLES;
|
|
275
|
+
this.#root.prepend(style);
|
|
276
|
+
}
|
|
277
|
+
// A framework may set properties before the element is defined; those
|
|
278
|
+
// shadow the accessors, so run them through the setters instead.
|
|
279
|
+
for (const key of [...OPTION_KEYS, "props", "label"] as const) {
|
|
280
|
+
if (Object.hasOwn(this, key)) {
|
|
281
|
+
const value = this[key as keyof this];
|
|
282
|
+
delete this[key as keyof this];
|
|
283
|
+
(this as Record<string, unknown>)[key] = value;
|
|
284
|
+
}
|
|
285
|
+
}
|
|
286
|
+
}
|
|
287
|
+
|
|
288
|
+
connectedCallback(): void {
|
|
289
|
+
if (this.#dirty) {
|
|
290
|
+
this.#render();
|
|
291
|
+
}
|
|
292
|
+
}
|
|
293
|
+
|
|
294
|
+
attributeChangedCallback(
|
|
295
|
+
name: string,
|
|
296
|
+
previous: string | null,
|
|
297
|
+
next: string | null
|
|
298
|
+
): void {
|
|
299
|
+
if (previous === next) {
|
|
300
|
+
return;
|
|
301
|
+
}
|
|
302
|
+
if (name === "label") {
|
|
303
|
+
this.#label = next ?? undefined;
|
|
304
|
+
this.#changed();
|
|
305
|
+
return;
|
|
306
|
+
}
|
|
307
|
+
if (name === "props") {
|
|
308
|
+
this.#setPropsAttribute(next);
|
|
309
|
+
return;
|
|
310
|
+
}
|
|
311
|
+
const entry = ATTRIBUTES[name];
|
|
312
|
+
if (entry) {
|
|
313
|
+
const [key, kind] = entry;
|
|
314
|
+
this.#set(key, next === null ? undefined : parseAttribute(kind, next));
|
|
315
|
+
}
|
|
316
|
+
}
|
|
317
|
+
|
|
318
|
+
/** Every option at once; the named properties and attributes win over it. */
|
|
319
|
+
get props(): QRdxCodeOptions | undefined {
|
|
320
|
+
return this.#props;
|
|
321
|
+
}
|
|
322
|
+
|
|
323
|
+
set props(props: QRdxCodeOptions | string | null | undefined) {
|
|
324
|
+
if (typeof props === "string") {
|
|
325
|
+
this.#setPropsAttribute(props);
|
|
326
|
+
return;
|
|
327
|
+
}
|
|
328
|
+
this.#props = props ?? undefined;
|
|
329
|
+
this.#changed();
|
|
330
|
+
}
|
|
331
|
+
|
|
332
|
+
/** What screen readers announce; the encoded value is never used. */
|
|
333
|
+
get label(): string | undefined {
|
|
334
|
+
return this.#label;
|
|
335
|
+
}
|
|
336
|
+
|
|
337
|
+
set label(label: string | null | undefined) {
|
|
338
|
+
this.#label = label ?? undefined;
|
|
339
|
+
this.#changed();
|
|
340
|
+
}
|
|
341
|
+
|
|
342
|
+
/** The options the code is drawn with: `props`, then attributes and properties. */
|
|
343
|
+
get options(): QRdxCodeOptions {
|
|
344
|
+
return compact({ ...this.#props, ...this.#values });
|
|
345
|
+
}
|
|
346
|
+
|
|
347
|
+
/** The drawn `<svg>` (null without a value). Reading it draws any pending change. */
|
|
348
|
+
get svg(): SVGSVGElement | null {
|
|
349
|
+
if (this.#dirty && this.isConnected) {
|
|
350
|
+
this.#render();
|
|
351
|
+
}
|
|
352
|
+
return this.#svg;
|
|
353
|
+
}
|
|
354
|
+
|
|
355
|
+
/** The code's SVG markup, as `toSVGString` from qrdx/core writes it for `options`. */
|
|
356
|
+
toSVGString(): string {
|
|
357
|
+
return renderToString(createQRCodeTree(this.#requireOptions()));
|
|
358
|
+
}
|
|
359
|
+
|
|
360
|
+
/** The code as a data URL: "png" (default), "jpg", "webp", "svg", "pdf" or "eps". */
|
|
361
|
+
async toDataURL(
|
|
362
|
+
format: DownloadFormat = "png",
|
|
363
|
+
options: QRCodeExportOptions = {}
|
|
364
|
+
): Promise<string> {
|
|
365
|
+
const current = this.#requireOptions();
|
|
366
|
+
return await getQRCodeDataUrl(
|
|
367
|
+
current,
|
|
368
|
+
format,
|
|
369
|
+
exportSize(current, options.size),
|
|
370
|
+
{ quality: options.quality }
|
|
371
|
+
);
|
|
372
|
+
}
|
|
373
|
+
|
|
374
|
+
/** Saves the code as a file (a PNG unless `format` says otherwise). */
|
|
375
|
+
async download(options: QRCodeDownloadOptions = {}): Promise<void> {
|
|
376
|
+
const current = this.#requireOptions();
|
|
377
|
+
return await downloadQRCode(current, {
|
|
378
|
+
format: options.format ?? "png",
|
|
379
|
+
size: exportSize(current, options.size),
|
|
380
|
+
filename: options.filename,
|
|
381
|
+
quality: options.quality,
|
|
382
|
+
});
|
|
383
|
+
}
|
|
384
|
+
|
|
385
|
+
#requireOptions(): QRSVGOptions {
|
|
386
|
+
const options = this.options;
|
|
387
|
+
if (!options.value) {
|
|
388
|
+
throw new Error(`qrdx: <${this.localName}> has no value`);
|
|
389
|
+
}
|
|
390
|
+
return options as QRSVGOptions;
|
|
391
|
+
}
|
|
392
|
+
|
|
393
|
+
#set(key: OptionKey, value: unknown): void {
|
|
394
|
+
if (value === undefined || value === null) {
|
|
395
|
+
if (!(key in this.#values)) {
|
|
396
|
+
return;
|
|
397
|
+
}
|
|
398
|
+
delete this.#values[key];
|
|
399
|
+
} else {
|
|
400
|
+
if (this.#values[key] === value) {
|
|
401
|
+
return;
|
|
402
|
+
}
|
|
403
|
+
this.#values[key] = value;
|
|
404
|
+
}
|
|
405
|
+
this.#changed();
|
|
406
|
+
}
|
|
407
|
+
|
|
408
|
+
#setPropsAttribute(json: string | null): void {
|
|
409
|
+
if (json === null || json.trim() === "") {
|
|
410
|
+
this.props = undefined;
|
|
411
|
+
return;
|
|
412
|
+
}
|
|
413
|
+
try {
|
|
414
|
+
const parsed: unknown = JSON.parse(json);
|
|
415
|
+
if (!parsed || typeof parsed !== "object" || Array.isArray(parsed)) {
|
|
416
|
+
throw new TypeError("props must be a JSON object");
|
|
417
|
+
}
|
|
418
|
+
this.props = parsed as QRdxCodeOptions;
|
|
419
|
+
} catch (error) {
|
|
420
|
+
this.#report(error);
|
|
421
|
+
}
|
|
422
|
+
}
|
|
423
|
+
|
|
424
|
+
/** Marks the code for a redraw in a microtask, once however many changes come. */
|
|
425
|
+
#changed(): void {
|
|
426
|
+
this.#dirty = true;
|
|
427
|
+
if (this.#queued) {
|
|
428
|
+
return;
|
|
429
|
+
}
|
|
430
|
+
this.#queued = true;
|
|
431
|
+
queueMicrotask(() => {
|
|
432
|
+
this.#queued = false;
|
|
433
|
+
if (this.#dirty && this.isConnected) {
|
|
434
|
+
this.#render();
|
|
435
|
+
}
|
|
436
|
+
});
|
|
437
|
+
}
|
|
438
|
+
|
|
439
|
+
#render(): void {
|
|
440
|
+
this.#dirty = false;
|
|
441
|
+
const options = this.options;
|
|
442
|
+
if (!options.value) {
|
|
443
|
+
this.#clear();
|
|
444
|
+
return;
|
|
445
|
+
}
|
|
446
|
+
let tree: ReturnType<typeof createQRCodeTree>;
|
|
447
|
+
let markup: string;
|
|
448
|
+
try {
|
|
449
|
+
tree = createQRCodeTree(
|
|
450
|
+
drawnOptions(options as QRSVGOptions, this.#label)
|
|
451
|
+
);
|
|
452
|
+
markup = renderToString(tree);
|
|
453
|
+
} catch (error) {
|
|
454
|
+
this.#clear();
|
|
455
|
+
this.#report(error);
|
|
456
|
+
return;
|
|
457
|
+
}
|
|
458
|
+
if (this.#svg && markup === this.#markup) {
|
|
459
|
+
return;
|
|
460
|
+
}
|
|
461
|
+
const svg = renderToDOM(tree, this.ownerDocument)
|
|
462
|
+
.firstChild as SVGSVGElement;
|
|
463
|
+
if (this.#svg?.parentNode === this.#root) {
|
|
464
|
+
this.#svg.replaceWith(svg);
|
|
465
|
+
} else {
|
|
466
|
+
this.#root.append(svg);
|
|
467
|
+
}
|
|
468
|
+
this.#svg = svg;
|
|
469
|
+
this.#markup = markup;
|
|
470
|
+
}
|
|
471
|
+
|
|
472
|
+
#clear(): void {
|
|
473
|
+
this.#svg?.remove();
|
|
474
|
+
this.#svg = null;
|
|
475
|
+
this.#markup = "";
|
|
476
|
+
}
|
|
477
|
+
|
|
478
|
+
/** A `qrdx-error` event; logged unless a listener calls preventDefault(). */
|
|
479
|
+
#report(error: unknown): void {
|
|
480
|
+
const event = new CustomEvent<QRdxCodeErrorDetail>("qrdx-error", {
|
|
481
|
+
cancelable: true,
|
|
482
|
+
detail: { error },
|
|
483
|
+
});
|
|
484
|
+
if (this.dispatchEvent(event)) {
|
|
485
|
+
console.error(`qrdx: <${this.localName}> could not draw its code`, error);
|
|
486
|
+
}
|
|
487
|
+
}
|
|
488
|
+
}
|
|
489
|
+
|
|
490
|
+
let defaultTag: string | undefined;
|
|
491
|
+
|
|
492
|
+
/**
|
|
493
|
+
* Registers `<qrdx-code>` (or `tagName`) and returns its class. Calling it
|
|
494
|
+
* again is safe. Does nothing where there is no `customElements`, such as
|
|
495
|
+
* on a server.
|
|
496
|
+
*/
|
|
497
|
+
export function defineQRdxCode(tagName = "qrdx-code"): typeof QRdxCodeElement {
|
|
498
|
+
const registry = globalThis.customElements as
|
|
499
|
+
| CustomElementRegistry
|
|
500
|
+
| undefined;
|
|
501
|
+
if (!registry) {
|
|
502
|
+
return QRdxCodeElement;
|
|
503
|
+
}
|
|
504
|
+
const existing = registry.get(tagName);
|
|
505
|
+
if (existing) {
|
|
506
|
+
if (ELEMENT_MARK in existing) {
|
|
507
|
+
return existing as typeof QRdxCodeElement;
|
|
508
|
+
}
|
|
509
|
+
throw new Error(
|
|
510
|
+
`qrdx: <${tagName}> is already defined by another element; pass defineQRdxCode another tag name`
|
|
511
|
+
);
|
|
512
|
+
}
|
|
513
|
+
// A class can be registered under one name only, so other names get a subclass.
|
|
514
|
+
const element =
|
|
515
|
+
defaultTag === undefined
|
|
516
|
+
? QRdxCodeElement
|
|
517
|
+
: class extends QRdxCodeElement {};
|
|
518
|
+
registry.define(tagName, element);
|
|
519
|
+
defaultTag ??= tagName;
|
|
520
|
+
return element;
|
|
521
|
+
}
|
|
522
|
+
|
|
523
|
+
const escapeAttribute = (value: string) =>
|
|
524
|
+
value
|
|
525
|
+
.replace(/&/g, "&")
|
|
526
|
+
.replace(/"/g, """)
|
|
527
|
+
.replace(/</g, "<")
|
|
528
|
+
.replace(/>/g, ">");
|
|
529
|
+
|
|
530
|
+
/** Options written as attributes, as `toQRdxCodeHTML` writes them. */
|
|
531
|
+
function toAttributes(options: QRdxCodeOptions): {
|
|
532
|
+
attributes: [string, string][];
|
|
533
|
+
rest: Record<string, unknown>;
|
|
534
|
+
} {
|
|
535
|
+
const attributes: [string, string][] = [];
|
|
536
|
+
const rest: Record<string, unknown> = { ...options };
|
|
537
|
+
for (const [name, [key, kind]] of Object.entries(ATTRIBUTES)) {
|
|
538
|
+
const value = options[key];
|
|
539
|
+
const fits =
|
|
540
|
+
(kind === "number" && typeof value === "number") ||
|
|
541
|
+
(kind === "boolean" && typeof value === "boolean") ||
|
|
542
|
+
(kind !== "number" && kind !== "boolean" && typeof value === "string");
|
|
543
|
+
if (!fits) {
|
|
544
|
+
continue;
|
|
545
|
+
}
|
|
546
|
+
delete rest[key];
|
|
547
|
+
if (kind === "boolean") {
|
|
548
|
+
if (value) {
|
|
549
|
+
attributes.push([name, ""]);
|
|
550
|
+
}
|
|
551
|
+
} else {
|
|
552
|
+
attributes.push([name, String(value)]);
|
|
553
|
+
}
|
|
554
|
+
}
|
|
555
|
+
return { attributes, rest };
|
|
556
|
+
}
|
|
557
|
+
|
|
558
|
+
/** Options for `toQRdxCodeHTML`. */
|
|
559
|
+
export interface QRdxCodeHTMLOptions {
|
|
560
|
+
/** The element's tag name (default "qrdx-code") */
|
|
561
|
+
tagName?: string;
|
|
562
|
+
/** What screen readers announce (default "QR code") */
|
|
563
|
+
label?: string;
|
|
564
|
+
}
|
|
565
|
+
|
|
566
|
+
/**
|
|
567
|
+
* Server markup for a `<qrdx-code>`: the element with its options as
|
|
568
|
+
* attributes (object options as JSON in `props`) and the drawn code in a
|
|
569
|
+
* declarative shadow root, so it shows before any script runs and the
|
|
570
|
+
* element takes over when it's defined. Works without a DOM.
|
|
571
|
+
* `customTemplate` can't be written as markup: set it as a property on the
|
|
572
|
+
* client.
|
|
573
|
+
*/
|
|
574
|
+
export function toQRdxCodeHTML(
|
|
575
|
+
options: QRSVGOptions,
|
|
576
|
+
{ tagName = "qrdx-code", label }: QRdxCodeHTMLOptions = {}
|
|
577
|
+
): string {
|
|
578
|
+
if (!CUSTOM_ELEMENT_NAME.test(tagName)) {
|
|
579
|
+
throw new Error(`qrdx: ${tagName} is not a custom element name`);
|
|
580
|
+
}
|
|
581
|
+
const current = compact(options as Record<string, unknown>);
|
|
582
|
+
const { attributes, rest } = toAttributes(current);
|
|
583
|
+
// A template's wrapper is a function, which JSON can't carry
|
|
584
|
+
const { customTemplate: _template, ...serializable } = rest;
|
|
585
|
+
if (label !== undefined) {
|
|
586
|
+
attributes.push(["label", label]);
|
|
587
|
+
}
|
|
588
|
+
if (Object.keys(serializable).length > 0) {
|
|
589
|
+
attributes.push(["props", JSON.stringify(serializable)]);
|
|
590
|
+
}
|
|
591
|
+
const opening = attributes
|
|
592
|
+
.map(([name, value]) =>
|
|
593
|
+
value === "" ? ` ${name}` : ` ${name}="${escapeAttribute(value)}"`
|
|
594
|
+
)
|
|
595
|
+
.join("");
|
|
596
|
+
const svg = current.value
|
|
597
|
+
? renderToString(
|
|
598
|
+
createQRCodeTree(drawnOptions(current as QRSVGOptions, label))
|
|
599
|
+
)
|
|
600
|
+
: "";
|
|
601
|
+
return `<${tagName}${opening}><template shadowrootmode="open"><style>${QRDX_CODE_STYLES}</style>${svg}</template></${tagName}>`;
|
|
602
|
+
}
|
|
603
|
+
|
|
604
|
+
declare global {
|
|
605
|
+
interface HTMLElementTagNameMap {
|
|
606
|
+
"qrdx-code": QRdxCodeElement;
|
|
607
|
+
}
|
|
608
|
+
}
|
package/src/engine.ts
CHANGED
|
@@ -76,12 +76,23 @@ export {
|
|
|
76
76
|
} from "./frame-import";
|
|
77
77
|
export {
|
|
78
78
|
FrameSpecError,
|
|
79
|
+
type FrameSpecOptions,
|
|
79
80
|
getCustomFrameLayout,
|
|
81
|
+
getFrameSpecColors,
|
|
80
82
|
getFrameSpecGapRatio,
|
|
81
83
|
resolveFrameSpec,
|
|
82
84
|
} from "./frame-spec";
|
|
83
|
-
export {
|
|
84
|
-
export {
|
|
85
|
+
export { mixFrameColors } from "./frame-text";
|
|
86
|
+
export {
|
|
87
|
+
BUILT_IN_FRAME_SPECS,
|
|
88
|
+
BUILT_IN_FRAMES,
|
|
89
|
+
type BuiltInFrame,
|
|
90
|
+
type BuiltInFrameStyle,
|
|
91
|
+
frameSpecOf,
|
|
92
|
+
GRADIENT_FRAME_DEFAULTS,
|
|
93
|
+
getBuiltInFrame,
|
|
94
|
+
getFrameColors,
|
|
95
|
+
} from "./frames/builtin";
|
|
85
96
|
export {
|
|
86
97
|
OFFICIAL_FRAME_COUNT,
|
|
87
98
|
OFFICIAL_FRAME_COUNTS,
|