@thinkpixellab-public/px-vue 3.0.1
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/.eslintrc.js +14 -0
- package/.prettierrc.js +10 -0
- package/LICENSE.md +9 -0
- package/README.md +83 -0
- package/assets/feather/activity.svg +1 -0
- package/assets/feather/airplay.svg +1 -0
- package/assets/feather/alert-circle.svg +1 -0
- package/assets/feather/alert-octagon.svg +1 -0
- package/assets/feather/alert-triangle.svg +1 -0
- package/assets/feather/align-center.svg +1 -0
- package/assets/feather/align-justify.svg +1 -0
- package/assets/feather/align-left.svg +1 -0
- package/assets/feather/align-right.svg +1 -0
- package/assets/feather/anchor.svg +1 -0
- package/assets/feather/aperture.svg +1 -0
- package/assets/feather/archive.svg +1 -0
- package/assets/feather/arrow-down-circle.svg +1 -0
- package/assets/feather/arrow-down-left.svg +1 -0
- package/assets/feather/arrow-down-right.svg +1 -0
- package/assets/feather/arrow-down.svg +1 -0
- package/assets/feather/arrow-left-circle.svg +1 -0
- package/assets/feather/arrow-left.svg +1 -0
- package/assets/feather/arrow-right-circle.svg +1 -0
- package/assets/feather/arrow-right.svg +1 -0
- package/assets/feather/arrow-up-circle.svg +1 -0
- package/assets/feather/arrow-up-left.svg +1 -0
- package/assets/feather/arrow-up-right.svg +1 -0
- package/assets/feather/arrow-up.svg +1 -0
- package/assets/feather/at-sign.svg +1 -0
- package/assets/feather/award.svg +1 -0
- package/assets/feather/bar-chart-2.svg +1 -0
- package/assets/feather/bar-chart.svg +1 -0
- package/assets/feather/battery-charging.svg +1 -0
- package/assets/feather/battery.svg +1 -0
- package/assets/feather/bell-off.svg +1 -0
- package/assets/feather/bell.svg +1 -0
- package/assets/feather/bluetooth.svg +1 -0
- package/assets/feather/bold.svg +1 -0
- package/assets/feather/book-open.svg +1 -0
- package/assets/feather/book.svg +1 -0
- package/assets/feather/bookmark.svg +1 -0
- package/assets/feather/box.svg +1 -0
- package/assets/feather/briefcase.svg +1 -0
- package/assets/feather/calendar.svg +1 -0
- package/assets/feather/camera-off.svg +1 -0
- package/assets/feather/camera.svg +1 -0
- package/assets/feather/cast.svg +1 -0
- package/assets/feather/check-circle.svg +1 -0
- package/assets/feather/check-square.svg +1 -0
- package/assets/feather/check.svg +1 -0
- package/assets/feather/chevron-down.svg +1 -0
- package/assets/feather/chevron-left.svg +1 -0
- package/assets/feather/chevron-right.svg +1 -0
- package/assets/feather/chevron-up.svg +1 -0
- package/assets/feather/chevrons-down.svg +1 -0
- package/assets/feather/chevrons-left.svg +1 -0
- package/assets/feather/chevrons-right.svg +1 -0
- package/assets/feather/chevrons-up.svg +1 -0
- package/assets/feather/chrome.svg +1 -0
- package/assets/feather/circle.svg +1 -0
- package/assets/feather/clipboard.svg +1 -0
- package/assets/feather/clock.svg +1 -0
- package/assets/feather/cloud-drizzle.svg +1 -0
- package/assets/feather/cloud-lightning.svg +1 -0
- package/assets/feather/cloud-off.svg +1 -0
- package/assets/feather/cloud-rain.svg +1 -0
- package/assets/feather/cloud-snow.svg +1 -0
- package/assets/feather/cloud.svg +1 -0
- package/assets/feather/code.svg +1 -0
- package/assets/feather/codepen.svg +1 -0
- package/assets/feather/codesandbox.svg +1 -0
- package/assets/feather/coffee.svg +1 -0
- package/assets/feather/columns.svg +1 -0
- package/assets/feather/command.svg +1 -0
- package/assets/feather/compass.svg +1 -0
- package/assets/feather/copy.svg +1 -0
- package/assets/feather/corner-down-left.svg +1 -0
- package/assets/feather/corner-down-right.svg +1 -0
- package/assets/feather/corner-left-down.svg +1 -0
- package/assets/feather/corner-left-up.svg +1 -0
- package/assets/feather/corner-right-down.svg +1 -0
- package/assets/feather/corner-right-up.svg +1 -0
- package/assets/feather/corner-up-left.svg +1 -0
- package/assets/feather/corner-up-right.svg +1 -0
- package/assets/feather/cpu.svg +1 -0
- package/assets/feather/credit-card.svg +1 -0
- package/assets/feather/crop.svg +1 -0
- package/assets/feather/crosshair.svg +1 -0
- package/assets/feather/database.svg +1 -0
- package/assets/feather/delete.svg +1 -0
- package/assets/feather/disc.svg +1 -0
- package/assets/feather/divide-circle.svg +1 -0
- package/assets/feather/divide-square.svg +1 -0
- package/assets/feather/divide.svg +1 -0
- package/assets/feather/dollar-sign.svg +1 -0
- package/assets/feather/download-cloud.svg +1 -0
- package/assets/feather/download.svg +1 -0
- package/assets/feather/dribbble.svg +1 -0
- package/assets/feather/droplet.svg +1 -0
- package/assets/feather/edit-2.svg +1 -0
- package/assets/feather/edit-3.svg +1 -0
- package/assets/feather/edit.svg +1 -0
- package/assets/feather/external-link.svg +1 -0
- package/assets/feather/eye-off.svg +1 -0
- package/assets/feather/eye.svg +1 -0
- package/assets/feather/facebook.svg +1 -0
- package/assets/feather/fast-forward.svg +1 -0
- package/assets/feather/feather.svg +1 -0
- package/assets/feather/figma.svg +1 -0
- package/assets/feather/file-minus.svg +1 -0
- package/assets/feather/file-plus.svg +1 -0
- package/assets/feather/file-text.svg +1 -0
- package/assets/feather/file.svg +1 -0
- package/assets/feather/film.svg +1 -0
- package/assets/feather/filter.svg +1 -0
- package/assets/feather/flag.svg +1 -0
- package/assets/feather/folder-minus.svg +1 -0
- package/assets/feather/folder-plus.svg +1 -0
- package/assets/feather/folder.svg +1 -0
- package/assets/feather/framer.svg +1 -0
- package/assets/feather/frown.svg +1 -0
- package/assets/feather/gift.svg +1 -0
- package/assets/feather/git-branch.svg +1 -0
- package/assets/feather/git-commit.svg +1 -0
- package/assets/feather/git-merge.svg +1 -0
- package/assets/feather/git-pull-request.svg +1 -0
- package/assets/feather/github.svg +1 -0
- package/assets/feather/gitlab.svg +1 -0
- package/assets/feather/globe.svg +1 -0
- package/assets/feather/grid.svg +1 -0
- package/assets/feather/hard-drive.svg +1 -0
- package/assets/feather/hash.svg +1 -0
- package/assets/feather/headphones.svg +1 -0
- package/assets/feather/heart.svg +1 -0
- package/assets/feather/help-circle.svg +1 -0
- package/assets/feather/hexagon.svg +1 -0
- package/assets/feather/home.svg +1 -0
- package/assets/feather/image.svg +1 -0
- package/assets/feather/inbox.svg +1 -0
- package/assets/feather/info.svg +1 -0
- package/assets/feather/instagram.svg +1 -0
- package/assets/feather/italic.svg +1 -0
- package/assets/feather/key.svg +1 -0
- package/assets/feather/layers.svg +1 -0
- package/assets/feather/layout.svg +1 -0
- package/assets/feather/life-buoy.svg +1 -0
- package/assets/feather/link-2.svg +1 -0
- package/assets/feather/link.svg +1 -0
- package/assets/feather/linkedin.svg +1 -0
- package/assets/feather/list.svg +1 -0
- package/assets/feather/loader.svg +1 -0
- package/assets/feather/lock.svg +1 -0
- package/assets/feather/log-in.svg +1 -0
- package/assets/feather/log-out.svg +1 -0
- package/assets/feather/mail.svg +1 -0
- package/assets/feather/map-pin.svg +1 -0
- package/assets/feather/map.svg +1 -0
- package/assets/feather/maximize-2.svg +1 -0
- package/assets/feather/maximize.svg +1 -0
- package/assets/feather/meh.svg +1 -0
- package/assets/feather/menu.svg +1 -0
- package/assets/feather/message-circle.svg +1 -0
- package/assets/feather/message-square.svg +1 -0
- package/assets/feather/mic-off.svg +1 -0
- package/assets/feather/mic.svg +1 -0
- package/assets/feather/minimize-2.svg +1 -0
- package/assets/feather/minimize.svg +1 -0
- package/assets/feather/minus-circle.svg +1 -0
- package/assets/feather/minus-square.svg +1 -0
- package/assets/feather/minus.svg +1 -0
- package/assets/feather/monitor.svg +1 -0
- package/assets/feather/moon.svg +1 -0
- package/assets/feather/more-horizontal.svg +1 -0
- package/assets/feather/more-vertical.svg +1 -0
- package/assets/feather/mouse-pointer.svg +1 -0
- package/assets/feather/move.svg +1 -0
- package/assets/feather/music.svg +1 -0
- package/assets/feather/navigation-2.svg +1 -0
- package/assets/feather/navigation.svg +1 -0
- package/assets/feather/octagon.svg +1 -0
- package/assets/feather/package.svg +1 -0
- package/assets/feather/paperclip.svg +1 -0
- package/assets/feather/pause-circle.svg +1 -0
- package/assets/feather/pause.svg +1 -0
- package/assets/feather/pen-tool.svg +1 -0
- package/assets/feather/percent.svg +1 -0
- package/assets/feather/phone-call.svg +1 -0
- package/assets/feather/phone-forwarded.svg +1 -0
- package/assets/feather/phone-incoming.svg +1 -0
- package/assets/feather/phone-missed.svg +1 -0
- package/assets/feather/phone-off.svg +1 -0
- package/assets/feather/phone-outgoing.svg +1 -0
- package/assets/feather/phone.svg +1 -0
- package/assets/feather/pie-chart.svg +1 -0
- package/assets/feather/play-circle.svg +1 -0
- package/assets/feather/play.svg +1 -0
- package/assets/feather/plus-circle.svg +1 -0
- package/assets/feather/plus-square.svg +1 -0
- package/assets/feather/plus.svg +1 -0
- package/assets/feather/pocket.svg +1 -0
- package/assets/feather/power.svg +1 -0
- package/assets/feather/printer.svg +1 -0
- package/assets/feather/radio.svg +1 -0
- package/assets/feather/refresh-ccw.svg +1 -0
- package/assets/feather/refresh-cw.svg +1 -0
- package/assets/feather/repeat.svg +1 -0
- package/assets/feather/rewind.svg +1 -0
- package/assets/feather/rotate-ccw.svg +1 -0
- package/assets/feather/rotate-cw.svg +1 -0
- package/assets/feather/rss.svg +1 -0
- package/assets/feather/save.svg +1 -0
- package/assets/feather/scissors.svg +1 -0
- package/assets/feather/search.svg +1 -0
- package/assets/feather/send.svg +1 -0
- package/assets/feather/server.svg +1 -0
- package/assets/feather/settings.svg +1 -0
- package/assets/feather/share-2.svg +1 -0
- package/assets/feather/share.svg +1 -0
- package/assets/feather/shield-off.svg +1 -0
- package/assets/feather/shield.svg +1 -0
- package/assets/feather/shopping-bag.svg +1 -0
- package/assets/feather/shopping-cart.svg +1 -0
- package/assets/feather/shuffle.svg +1 -0
- package/assets/feather/sidebar.svg +1 -0
- package/assets/feather/skip-back.svg +1 -0
- package/assets/feather/skip-forward.svg +1 -0
- package/assets/feather/slack.svg +1 -0
- package/assets/feather/slash.svg +1 -0
- package/assets/feather/sliders.svg +1 -0
- package/assets/feather/smartphone.svg +1 -0
- package/assets/feather/smile.svg +1 -0
- package/assets/feather/speaker.svg +1 -0
- package/assets/feather/square.svg +1 -0
- package/assets/feather/star.svg +1 -0
- package/assets/feather/stop-circle.svg +1 -0
- package/assets/feather/sun.svg +1 -0
- package/assets/feather/sunrise.svg +1 -0
- package/assets/feather/sunset.svg +1 -0
- package/assets/feather/table.svg +1 -0
- package/assets/feather/tablet.svg +1 -0
- package/assets/feather/tag.svg +1 -0
- package/assets/feather/target.svg +1 -0
- package/assets/feather/terminal.svg +1 -0
- package/assets/feather/thermometer.svg +1 -0
- package/assets/feather/thumbs-down.svg +1 -0
- package/assets/feather/thumbs-up.svg +1 -0
- package/assets/feather/toggle-left.svg +1 -0
- package/assets/feather/toggle-right.svg +1 -0
- package/assets/feather/tool.svg +1 -0
- package/assets/feather/trash-2.svg +1 -0
- package/assets/feather/trash.svg +1 -0
- package/assets/feather/trello.svg +1 -0
- package/assets/feather/trending-down.svg +1 -0
- package/assets/feather/trending-up.svg +1 -0
- package/assets/feather/triangle.svg +1 -0
- package/assets/feather/truck.svg +1 -0
- package/assets/feather/tv.svg +1 -0
- package/assets/feather/twitch.svg +1 -0
- package/assets/feather/twitter.svg +1 -0
- package/assets/feather/type.svg +1 -0
- package/assets/feather/umbrella.svg +1 -0
- package/assets/feather/underline.svg +1 -0
- package/assets/feather/unlock.svg +1 -0
- package/assets/feather/upload-cloud.svg +1 -0
- package/assets/feather/upload.svg +1 -0
- package/assets/feather/user-check.svg +1 -0
- package/assets/feather/user-minus.svg +1 -0
- package/assets/feather/user-plus.svg +1 -0
- package/assets/feather/user-x.svg +1 -0
- package/assets/feather/user.svg +1 -0
- package/assets/feather/users.svg +1 -0
- package/assets/feather/video-off.svg +1 -0
- package/assets/feather/video.svg +1 -0
- package/assets/feather/voicemail.svg +1 -0
- package/assets/feather/volume-1.svg +1 -0
- package/assets/feather/volume-2.svg +1 -0
- package/assets/feather/volume-x.svg +1 -0
- package/assets/feather/volume.svg +1 -0
- package/assets/feather/watch.svg +1 -0
- package/assets/feather/wifi-off.svg +1 -0
- package/assets/feather/wifi.svg +1 -0
- package/assets/feather/wind.svg +1 -0
- package/assets/feather/x-circle.svg +1 -0
- package/assets/feather/x-octagon.svg +1 -0
- package/assets/feather/x-square.svg +1 -0
- package/assets/feather/x.svg +1 -0
- package/assets/feather/youtube.svg +1 -0
- package/assets/feather/zap-off.svg +1 -0
- package/assets/feather/zap.svg +1 -0
- package/assets/feather/zoom-in.svg +1 -0
- package/assets/feather/zoom-out.svg +1 -0
- package/assets/icons/calendar.svg +6 -0
- package/assets/icons/check.svg +1 -0
- package/assets/icons/close-sm.svg +1 -0
- package/assets/icons/close.svg +1 -0
- package/assets/icons/copy.svg +1 -0
- package/assets/icons/dropdown.svg +8 -0
- package/assets/icons/invalid.svg +1 -0
- package/assets/icons/menu.svg +1 -0
- package/assets/icons/nav-next.svg +1 -0
- package/assets/icons/nav-prev.svg +1 -0
- package/assets/icons/sort-asc.svg +1 -0
- package/assets/icons/sort-desc.svg +1 -0
- package/assets/test/README.md +1 -0
- package/assets/test/trash.svg +8 -0
- package/babel.config.js +16 -0
- package/components/PxAspect.vue +127 -0
- package/components/PxAutoClamp.vue +75 -0
- package/components/PxBalancedText.vue +118 -0
- package/components/PxBase.vue +15 -0
- package/components/PxBaseDate.vue +27 -0
- package/components/PxBaseItems.vue +72 -0
- package/components/PxBaseItemsSelect.vue +230 -0
- package/components/PxBaseResize.vue +60 -0
- package/components/PxBaseToggle.vue +56 -0
- package/components/PxBaseVariants.vue +62 -0
- package/components/PxBaseVisible.vue +40 -0
- package/components/PxCalendar.vue +385 -0
- package/components/PxCard.vue +47 -0
- package/components/PxCardGrid.vue +386 -0
- package/components/PxClock.vue +510 -0
- package/components/PxCopyText.vue +78 -0
- package/components/PxDatePicker.vue +249 -0
- package/components/PxDropdown.vue +181 -0
- package/components/PxExpander.vue +46 -0
- package/components/PxFeatherIcon.vue +29 -0
- package/components/PxFeatherIconButton.vue +19 -0
- package/components/PxFit.vue +274 -0
- package/components/PxFlex.vue +93 -0
- package/components/PxFloat.vue +32 -0
- package/components/PxIcon.vue +43 -0
- package/components/PxIconButton.vue +115 -0
- package/components/PxIdUniquer.vue +59 -0
- package/components/PxModal.vue +365 -0
- package/components/PxNineGrid.vue +94 -0
- package/components/PxPivot.vue +207 -0
- package/components/PxPopup.vue +230 -0
- package/components/PxPortal.vue +138 -0
- package/components/PxPortalTarget.vue +25 -0
- package/components/PxProgressCircle.vue +73 -0
- package/components/PxRadioButton.vue +83 -0
- package/components/PxSideDrawer.vue +164 -0
- package/components/PxSlideTransition.vue +116 -0
- package/components/PxSlides.vue +217 -0
- package/components/PxStylesPreview.vue +129 -0
- package/components/PxSvg.vue +157 -0
- package/components/PxSwiper.vue +271 -0
- package/components/PxSwiperSlide.vue +42 -0
- package/components/PxSyncHeight.vue +137 -0
- package/components/PxTable.vue +323 -0
- package/components/PxTabs.vue +1 -0
- package/components/PxTextbox.vue +90 -0
- package/components/PxToggle.vue +125 -0
- package/components/PxToggleButton.vue +139 -0
- package/components/PxToggleButtonList.vue +131 -0
- package/components/PxTransitionExpand.vue +100 -0
- package/components/PxValidator.vue +431 -0
- package/components/PxVueTest.vue +761 -0
- package/components/README.md +0 -0
- package/dev/data/fruits.js +59 -0
- package/dev/data/random.js +13 -0
- package/dev/demos/Demo-PxBaseDrag.vue +94 -0
- package/dev/demos/Demo-PxCardGrid.vue +53 -0
- package/dev/demos/Demo-PxPivot.vue +58 -0
- package/dev/demos/Demo-PxSideDrawer.vue +72 -0
- package/dev/demos/Demo-PxSlideTransition.vue +86 -0
- package/dev/demos/Demo-PxSlides.vue +142 -0
- package/dev/demos/Demo-PxStylesPreview.vue +46 -0
- package/dev/demos/Demo-PxSwiper.vue +44 -0
- package/dev/demos/DemoPicker.vue +79 -0
- package/dev/dev.vue +56 -0
- package/dev/serve.js +17 -0
- package/package.json +45 -0
- package/plugins/common-client.js +13 -0
- package/plugins/common-lib.js +4 -0
- package/plugins/common.js +39 -0
- package/plugins/filters/aspect.js +14 -0
- package/plugins/filters/date.js +26 -0
- package/plugins/filters/kebab.js +9 -0
- package/plugins/filters/phone.js +7 -0
- package/plugins/filters/slug.js +26 -0
- package/plugins/filters/spacenator.js +11 -0
- package/plugins/filters/stringToItems.js +28 -0
- package/plugins/filters/striphtml.js +10 -0
- package/plugins/mixins/eventBus.js +23 -0
- package/px-styles.config.scss +12 -0
- package/styles/helpers.scss +14 -0
- package/styles/px.scss +6 -0
- package/utils/balanceText.js +123 -0
- package/utils/bem.js +99 -0
- package/utils/cardGrid.js +383 -0
- package/utils/cssStr.js +45 -0
- package/utils/drag.js +363 -0
- package/utils/fit.js +73 -0
- package/utils/tween.js +129 -0
- package/utils/utils.js +167 -0
- package/utils/variants.js +33 -0
- package/vue.config.js +12 -0
package/utils/bem.js
ADDED
|
@@ -0,0 +1,99 @@
|
|
|
1
|
+
const bemOptions = {
|
|
2
|
+
separators: {
|
|
3
|
+
element: '__',
|
|
4
|
+
modifier: '--',
|
|
5
|
+
value: '-',
|
|
6
|
+
},
|
|
7
|
+
hyphenate: {
|
|
8
|
+
block: true,
|
|
9
|
+
element: true,
|
|
10
|
+
modifier: true,
|
|
11
|
+
state: true,
|
|
12
|
+
},
|
|
13
|
+
};
|
|
14
|
+
|
|
15
|
+
// Convert to kebab case (flag makes syntax easier with options)
|
|
16
|
+
function hyphenate(str, shouldHyphenate = true) {
|
|
17
|
+
if (str) {
|
|
18
|
+
if (typeof str !== 'string') {
|
|
19
|
+
str = String(str);
|
|
20
|
+
}
|
|
21
|
+
return shouldHyphenate
|
|
22
|
+
? str
|
|
23
|
+
.toString()
|
|
24
|
+
.replace(/([a-z0-9])([A-Z])/g, '$1-$2')
|
|
25
|
+
.toLowerCase()
|
|
26
|
+
: str;
|
|
27
|
+
} else {
|
|
28
|
+
return str;
|
|
29
|
+
}
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
// Get block name
|
|
33
|
+
function getBlockName(component) {
|
|
34
|
+
if (!component.$options._blockName) {
|
|
35
|
+
let block = component.$options.name || component.$options._componentTag;
|
|
36
|
+
if (block && block.indexOf('/') > -1) {
|
|
37
|
+
block = block.split('/').pop().split('.')[0];
|
|
38
|
+
}
|
|
39
|
+
component.$options._blockName = block;
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
return component.$options._blockName;
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
// Calcualte the bem classes for a given block, element and set of modifiers
|
|
46
|
+
function getBemClasses(blockName, elementName, modifiers, options) {
|
|
47
|
+
const block = hyphenate(blockName, options.hyphenate.block);
|
|
48
|
+
const element = elementName
|
|
49
|
+
? options.separators.element + hyphenate(elementName, options.hyphenate.element)
|
|
50
|
+
: '';
|
|
51
|
+
const bem = block + element;
|
|
52
|
+
|
|
53
|
+
if (!modifiers) {
|
|
54
|
+
return bem;
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
let modClasses = Object.keys(modifiers)
|
|
58
|
+
.map(key => {
|
|
59
|
+
const val = modifiers[key];
|
|
60
|
+
const mod = hyphenate(key, options.hyphenate.modifier);
|
|
61
|
+
|
|
62
|
+
// toggle boolean modifiers
|
|
63
|
+
if (typeof val === 'boolean') {
|
|
64
|
+
return val ? bem + options.separators.modifier + mod : null;
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
// concatenate non-boolean modifiers if not falsy
|
|
68
|
+
else {
|
|
69
|
+
return val
|
|
70
|
+
? bem +
|
|
71
|
+
options.separators.modifier +
|
|
72
|
+
mod +
|
|
73
|
+
options.separators.value +
|
|
74
|
+
hyphenate(val, options.hyphenate.state)
|
|
75
|
+
: null;
|
|
76
|
+
}
|
|
77
|
+
})
|
|
78
|
+
.filter(val => !!val);
|
|
79
|
+
|
|
80
|
+
// add bem class to beginning of list
|
|
81
|
+
modClasses.unshift(bem);
|
|
82
|
+
return modClasses.join(' ');
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
/*
|
|
86
|
+
Generates classes using BEM methodology.
|
|
87
|
+
:class="bem()" -> class="my-component"
|
|
88
|
+
:class="bem('element')" -> class="my-component__element"
|
|
89
|
+
:class="bem({dark: true})" -> class="my-component my-component--dark"
|
|
90
|
+
:class="bem({theme: 'dark'})" -> class="my-component--theme-dark"
|
|
91
|
+
:class="bem('el', {dark: true})" -> class="my-component__el my-component__el--dark"
|
|
92
|
+
*/
|
|
93
|
+
function bem(arg1, arg2) {
|
|
94
|
+
let element = typeof arg1 == 'string' ? arg1 : null;
|
|
95
|
+
let modifiers = typeof arg1 == 'string' ? arg2 : arg1;
|
|
96
|
+
return getBemClasses(getBlockName(this), element, modifiers, bemOptions);
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
export default bem;
|
|
@@ -0,0 +1,383 @@
|
|
|
1
|
+
// function arrShuffle(array) {
|
|
2
|
+
// for (let i = array.length - 1; i > 0; i--) {
|
|
3
|
+
// const j = Math.floor(Math.random() * (i + 1));
|
|
4
|
+
// [array[i], array[j]] = [array[j], array[i]];
|
|
5
|
+
// }
|
|
6
|
+
// return array;
|
|
7
|
+
// }
|
|
8
|
+
|
|
9
|
+
// const arrSum = array => {
|
|
10
|
+
// return array.reduce((acc, val) => {
|
|
11
|
+
// return acc + val;
|
|
12
|
+
// }, 0);
|
|
13
|
+
// };
|
|
14
|
+
|
|
15
|
+
// const strFindAll = (str, substr) => {
|
|
16
|
+
// if (!str || !substr) {
|
|
17
|
+
// return [];
|
|
18
|
+
// }
|
|
19
|
+
|
|
20
|
+
// let all = [];
|
|
21
|
+
// let nextIndex = str.indexOf(substr, 0);
|
|
22
|
+
|
|
23
|
+
// while (nextIndex > -1) {
|
|
24
|
+
// all.push(nextIndex);
|
|
25
|
+
// nextIndex = str.indexOf(substr, nextIndex + 1);
|
|
26
|
+
// }
|
|
27
|
+
// return all;
|
|
28
|
+
// };
|
|
29
|
+
|
|
30
|
+
// const strReplaceAt = (str, index, replacement) => {
|
|
31
|
+
// return str.substring(0, index) + replacement + str.substring(index + replacement.length);
|
|
32
|
+
// };
|
|
33
|
+
|
|
34
|
+
// const rowReplace = (rowStr, findStr, replaceStr, num) => {
|
|
35
|
+
// // convert num to an int (less than one interpreted as odds of being 1)
|
|
36
|
+
// if (num < 1) {
|
|
37
|
+
// num = Math.random() <= num ? 1 : 0;
|
|
38
|
+
// }
|
|
39
|
+
// num = Math.floor(num);
|
|
40
|
+
|
|
41
|
+
// // find possible positions, randomize and cap at num
|
|
42
|
+
// const positions = arrShuffle(strFindAll(rowStr, findStr)).slice(0, num);
|
|
43
|
+
|
|
44
|
+
// positions.forEach(pos => {
|
|
45
|
+
// rowStr = strReplaceAt(rowStr, pos, replaceStr);
|
|
46
|
+
// });
|
|
47
|
+
|
|
48
|
+
// const balance = arrSum(positions) / (rowStr.length * num) < 0.5 ? 'L' : 'R';
|
|
49
|
+
// console.log(`- ${rowStr} >> ${balance} `);
|
|
50
|
+
|
|
51
|
+
// return { row: rowStr, balance };
|
|
52
|
+
// };
|
|
53
|
+
|
|
54
|
+
// const cardGridDefaults = {
|
|
55
|
+
// columnCount: 4,
|
|
56
|
+
// rowCount: 4,
|
|
57
|
+
|
|
58
|
+
// // number of halfs per row (if less than one, interpeted as chance of 1)
|
|
59
|
+
// halfsPerRow: 1,
|
|
60
|
+
// doublesPerRow: 1,
|
|
61
|
+
|
|
62
|
+
// // whether to priotize half or double replacements first
|
|
63
|
+
// prioritize: 'half',
|
|
64
|
+
// };
|
|
65
|
+
|
|
66
|
+
// const cardGrid = options => {
|
|
67
|
+
// let op = { ...cardGridDefaults, ...options };
|
|
68
|
+
// let rows = [];
|
|
69
|
+
|
|
70
|
+
// // must have columnCount and rowCount
|
|
71
|
+
// if (!(op.columnCount && op.rowCount)) {
|
|
72
|
+
// return rows;
|
|
73
|
+
// }
|
|
74
|
+
|
|
75
|
+
// // create a naive layout with no half or double variants
|
|
76
|
+
// for (let r = 0; r < op.rowCount; r++) {
|
|
77
|
+
// rows.push('- '.repeat(op.columnCount).trim());
|
|
78
|
+
// }
|
|
79
|
+
|
|
80
|
+
// // iterate through the layout and replace slots with variants
|
|
81
|
+
// rows = rows.map(row => {
|
|
82
|
+
// let result = { row, balance: null };
|
|
83
|
+
|
|
84
|
+
// if (op.prioritize == 'half') {
|
|
85
|
+
// // half then double
|
|
86
|
+
// result = rowReplace(result.row, '-', ':', op.halfsPerRow);
|
|
87
|
+
// result = rowReplace(result.row, '- -', '+++', op.doublesPerRow);
|
|
88
|
+
// } else {
|
|
89
|
+
// // double then half
|
|
90
|
+
// result = rowReplace(result.row, '- -', '+++', op.doublesPerRow);
|
|
91
|
+
// result = rowReplace(result.row, '-', ':', op.halfsPerRow);
|
|
92
|
+
// }
|
|
93
|
+
|
|
94
|
+
// return result;
|
|
95
|
+
// });
|
|
96
|
+
|
|
97
|
+
// console.log(`rows: 👉 ${JSON.stringify(rows, null, 4)}`);
|
|
98
|
+
// };
|
|
99
|
+
|
|
100
|
+
// export default cardGrid;
|
|
101
|
+
|
|
102
|
+
/*
|
|
103
|
+
|
|
104
|
+
Notation:
|
|
105
|
+
|
|
106
|
+
// cards in determined / final state
|
|
107
|
+
|
|
108
|
+
fixed card --
|
|
109
|
+
stacked cards ==
|
|
110
|
+
double card -----
|
|
111
|
+
|
|
112
|
+
// single cards in undermined state
|
|
113
|
+
|
|
114
|
+
growable ++
|
|
115
|
+
shrinkable __
|
|
116
|
+
hidable ??
|
|
117
|
+
grow/shrink +_
|
|
118
|
+
grow/hide +?
|
|
119
|
+
shrink/hide _?
|
|
120
|
+
grow/shr/hide **
|
|
121
|
+
|
|
122
|
+
*/
|
|
123
|
+
|
|
124
|
+
/*
|
|
125
|
+
|
|
126
|
+
Notation:
|
|
127
|
+
|
|
128
|
+
// cards in determined / final state
|
|
129
|
+
|
|
130
|
+
fixed card --
|
|
131
|
+
stacked cards ==
|
|
132
|
+
double card -----
|
|
133
|
+
|
|
134
|
+
// single cards in undermined state
|
|
135
|
+
|
|
136
|
+
growable ++
|
|
137
|
+
shrinkable __
|
|
138
|
+
hidable ??
|
|
139
|
+
grow/shrink +_
|
|
140
|
+
grow/hide +?
|
|
141
|
+
shrink/hide _?
|
|
142
|
+
grow/shr/hide **
|
|
143
|
+
|
|
144
|
+
*/
|
|
145
|
+
|
|
146
|
+
// notation
|
|
147
|
+
|
|
148
|
+
const layoutNotation = {
|
|
149
|
+
// cards in determined / final state
|
|
150
|
+
|
|
151
|
+
// fixed single card
|
|
152
|
+
'--': { canGrow: false, canShrink: false, canHide: false, spaces: 1, cards: 1 },
|
|
153
|
+
|
|
154
|
+
// fixed stacked cards
|
|
155
|
+
'==': { canGrow: false, canShrink: false, canHide: false, spaces: 1, cards: 2 },
|
|
156
|
+
|
|
157
|
+
// fixed double card
|
|
158
|
+
'-----': { canGrow: false, canShrink: false, canHide: false, spaces: 2, cards: 1 },
|
|
159
|
+
|
|
160
|
+
// cards in an undetermined state
|
|
161
|
+
|
|
162
|
+
// growable
|
|
163
|
+
'++': { canGrow: true, canShrink: false, canHide: false, spaces: 1, cards: 1 },
|
|
164
|
+
|
|
165
|
+
// shrinkable
|
|
166
|
+
__: { canGrow: false, canShrink: true, canHide: false, spaces: 1, cards: 1 },
|
|
167
|
+
|
|
168
|
+
// hidable
|
|
169
|
+
'??': { canGrow: false, canShrink: false, canHide: true, spaces: 1, cards: 1 },
|
|
170
|
+
|
|
171
|
+
// grow/shrink
|
|
172
|
+
'+_': { canGrow: true, canShrink: true, canHide: false, spaces: 1, cards: 1 },
|
|
173
|
+
|
|
174
|
+
// grow/hide
|
|
175
|
+
'+?': { canGrow: true, canShrink: false, canHide: true, spaces: 1, cards: 1 },
|
|
176
|
+
|
|
177
|
+
// shrink/hide
|
|
178
|
+
'_?': { canGrow: false, canShrink: true, canHide: true, spaces: 1, cards: 1 },
|
|
179
|
+
|
|
180
|
+
// grow/shrink/hide
|
|
181
|
+
'**': { canGrow: true, canShrink: true, canHide: false, spaces: 1, cards: 1 },
|
|
182
|
+
};
|
|
183
|
+
|
|
184
|
+
// returns the number of columns spanned by the given row (array of spaces)
|
|
185
|
+
// const getRowColumnCount = row => {
|
|
186
|
+
// return row.reduce((cols, sp) => {
|
|
187
|
+
// return cols + sp.colspan;
|
|
188
|
+
// }, 0);
|
|
189
|
+
// };
|
|
190
|
+
|
|
191
|
+
// returns the number of cards contained by the given row
|
|
192
|
+
// const getRowCardCount = row => {
|
|
193
|
+
// return row.reduce((cards, sp) => {
|
|
194
|
+
// return cards + sp.cards;
|
|
195
|
+
// }, 0);
|
|
196
|
+
// };
|
|
197
|
+
|
|
198
|
+
// returns the number of cards cotnained in the given template (array of rows)
|
|
199
|
+
// const getTemplateCardCount = rows => {
|
|
200
|
+
// return rows.reduce((cards, row) => {
|
|
201
|
+
// return cards + getRowCardCount(row);
|
|
202
|
+
// }, 0);
|
|
203
|
+
// };
|
|
204
|
+
|
|
205
|
+
// const printRow = row => {
|
|
206
|
+
// console.log(row.map(sp => sp.notation).join(' '));
|
|
207
|
+
// };
|
|
208
|
+
|
|
209
|
+
// const printTemplate = rows => {
|
|
210
|
+
// rows.forEach(r => {
|
|
211
|
+
// printRow(r);
|
|
212
|
+
// });
|
|
213
|
+
// };
|
|
214
|
+
|
|
215
|
+
// const printTemplateCollection = coll => {
|
|
216
|
+
// coll.forEach(t => {
|
|
217
|
+
// console.log('');
|
|
218
|
+
// console.log(`cols: ${t.cols} | cards:${t.cards}`);
|
|
219
|
+
// printTemplate(t.template);
|
|
220
|
+
// });
|
|
221
|
+
// };
|
|
222
|
+
|
|
223
|
+
function layoutStrToObj(layoutStr) {
|
|
224
|
+
layoutStr = layoutStr.trim();
|
|
225
|
+
if (layoutStr in layoutNotation) {
|
|
226
|
+
return layoutNotation[layoutStr];
|
|
227
|
+
} else {
|
|
228
|
+
// fallback is a fixed single card
|
|
229
|
+
console.warn(`'Unable to interpret the layout string "${layoutStr}".`);
|
|
230
|
+
return layoutNotation['--'];
|
|
231
|
+
}
|
|
232
|
+
}
|
|
233
|
+
|
|
234
|
+
// true if all of the key/values in obj1 are present and match in obj2
|
|
235
|
+
function compareObject(obj1, obj2) {
|
|
236
|
+
for (let prop in obj1) {
|
|
237
|
+
if (!(prop in obj2) || obj1[prop] !== obj2[prop]) {
|
|
238
|
+
return false;
|
|
239
|
+
}
|
|
240
|
+
}
|
|
241
|
+
|
|
242
|
+
return true;
|
|
243
|
+
}
|
|
244
|
+
|
|
245
|
+
// break a flat array of cards into rows
|
|
246
|
+
//function getCardRows(cards, columnCount) {}
|
|
247
|
+
|
|
248
|
+
function findBestCard(cards, orderedFilters) {
|
|
249
|
+
for (let i = 0; i < orderedFilters.length; i++) {
|
|
250
|
+
let filter = orderedFilters[i];
|
|
251
|
+
let card = cards.find(c => compareObject(filter, c));
|
|
252
|
+
if (card) {
|
|
253
|
+
return card;
|
|
254
|
+
}
|
|
255
|
+
}
|
|
256
|
+
return null;
|
|
257
|
+
}
|
|
258
|
+
|
|
259
|
+
function growCards(cards) {
|
|
260
|
+
let card = findBestCard(cards, [
|
|
261
|
+
{ spaces: 1, canGrow: false, canShrink: true, canHide: false },
|
|
262
|
+
{ spaces: 1, canGrow: true, canShrink: true, canHide: false },
|
|
263
|
+
{ spaces: 2, canShrink: true },
|
|
264
|
+
{ spaces: 1, canHide: true },
|
|
265
|
+
]);
|
|
266
|
+
|
|
267
|
+
if (card) {
|
|
268
|
+
card.spaces = 2;
|
|
269
|
+
return true;
|
|
270
|
+
}
|
|
271
|
+
return false;
|
|
272
|
+
}
|
|
273
|
+
|
|
274
|
+
function shrinkCards(cards) {
|
|
275
|
+
// first look for a card that can only grow (so we keep options open)
|
|
276
|
+
let card = findBestCard(cards, [
|
|
277
|
+
{ spaces: 1, canGrow: true, canShrink: false },
|
|
278
|
+
{ spaces: 1, canGrow: true, canShrink: true },
|
|
279
|
+
]);
|
|
280
|
+
|
|
281
|
+
if (card) {
|
|
282
|
+
// TODO
|
|
283
|
+
return true;
|
|
284
|
+
}
|
|
285
|
+
return false;
|
|
286
|
+
}
|
|
287
|
+
|
|
288
|
+
//function shrinkCards(cards) {}
|
|
289
|
+
|
|
290
|
+
// choose the best next action for adjust the card layout
|
|
291
|
+
function getCardGridAction(cards, columnCount, bias) {
|
|
292
|
+
if (!columnCount) {
|
|
293
|
+
return [];
|
|
294
|
+
}
|
|
295
|
+
|
|
296
|
+
// get the total number of spaces needed by this layout
|
|
297
|
+
let spacesNeeded = cards.reduce((total, card) => {
|
|
298
|
+
return total + card.spaces;
|
|
299
|
+
}, 0);
|
|
300
|
+
|
|
301
|
+
// get the number of rows that this layout naturally uses
|
|
302
|
+
let rowsNeeded = Math.ceil(spacesNeeded / columnCount);
|
|
303
|
+
|
|
304
|
+
// get the size of gap that needs to be "filled in" in the final row
|
|
305
|
+
let emptySpaces = rowsNeeded * columnCount - spacesNeeded;
|
|
306
|
+
|
|
307
|
+
// if there is no gap, then we're done
|
|
308
|
+
if (emptySpaces == 0) {
|
|
309
|
+
return null;
|
|
310
|
+
}
|
|
311
|
+
|
|
312
|
+
// how much would we need to grow or shink to fill those spaces
|
|
313
|
+
let growthNeeded = emptySpaces;
|
|
314
|
+
let shrinkNeeded = columnCount - emptySpaces;
|
|
315
|
+
|
|
316
|
+
// get the "grow" power by counting the number of cards that can grow (and limit to 2)
|
|
317
|
+
let growPower = cards.reduce((total, card) => {
|
|
318
|
+
return total + (card.canGrow ? 1 : 0);
|
|
319
|
+
}, 0);
|
|
320
|
+
growPower = Math.min(growPower, 2);
|
|
321
|
+
|
|
322
|
+
// get the "shrink" power by counting the number of cards that can shrink (and then divide by 2)
|
|
323
|
+
let shrinkPower = cards.reduce((total, card) => {
|
|
324
|
+
return total + (card.canShrink ? 1 : 0);
|
|
325
|
+
}, 0);
|
|
326
|
+
shrinkPower = Math.floor(shrinkPower / 2);
|
|
327
|
+
|
|
328
|
+
// decision time? grow or shrink
|
|
329
|
+
|
|
330
|
+
let finalGrowGap = Math.max(0, growthNeeded - growPower);
|
|
331
|
+
let finalShrinkGap = columnCount - (shrinkNeeded - shrinkPower);
|
|
332
|
+
|
|
333
|
+
// console.log('===');
|
|
334
|
+
|
|
335
|
+
// console.log(`growthNeeded: ${growthNeeded}`);
|
|
336
|
+
// console.log(`growPower: ${growPower}`);
|
|
337
|
+
// console.log(`finalGrowGap: ${finalGrowGap}`);
|
|
338
|
+
|
|
339
|
+
// console.log('---');
|
|
340
|
+
|
|
341
|
+
// console.log(`shrinkNeeded: ${shrinkNeeded}`);
|
|
342
|
+
// console.log(`shrinkPower: ${shrinkPower}`);
|
|
343
|
+
// console.log(`finalShrinkGap: ${finalShrinkGap}`);
|
|
344
|
+
|
|
345
|
+
// console.log('---');
|
|
346
|
+
|
|
347
|
+
// console.log(`action: ${action}`);
|
|
348
|
+
|
|
349
|
+
// if we can go either way and there is an expressed bias, use that
|
|
350
|
+
if (bias && finalGrowGap == finalShrinkGap) {
|
|
351
|
+
return bias;
|
|
352
|
+
}
|
|
353
|
+
|
|
354
|
+
// otherwise choose whichever action is more needed
|
|
355
|
+
return finalGrowGap < finalShrinkGap ? 'grow' : 'shrink';
|
|
356
|
+
}
|
|
357
|
+
|
|
358
|
+
function createCardGrid(cards, columnCount) {
|
|
359
|
+
// convert string notation to an array of card
|
|
360
|
+
if (!Array.isArray(cards)) {
|
|
361
|
+
cards = cards.trim().split(/[\s\r\n]+/);
|
|
362
|
+
|
|
363
|
+
// convert layout string notation to an array of objects
|
|
364
|
+
cards = cards.map(cardStr => layoutStrToObj(cardStr));
|
|
365
|
+
}
|
|
366
|
+
|
|
367
|
+
let action = getCardGridAction(cards, columnCount);
|
|
368
|
+
if (action == 'grow') {
|
|
369
|
+
growCards(cards);
|
|
370
|
+
} else if (action == 'shrink') {
|
|
371
|
+
shrinkCards(cards);
|
|
372
|
+
}
|
|
373
|
+
|
|
374
|
+
let str = cards
|
|
375
|
+
.map(c => {
|
|
376
|
+
return c.spaces == 2 ? '-----' : '--';
|
|
377
|
+
})
|
|
378
|
+
.join(' ');
|
|
379
|
+
|
|
380
|
+
console.log(`str: ${str}`);
|
|
381
|
+
}
|
|
382
|
+
|
|
383
|
+
export default createCardGrid;
|
package/utils/cssStr.js
ADDED
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
/*
|
|
2
|
+
Converts a number to a px string
|
|
3
|
+
px(45) => '45px'
|
|
4
|
+
*/
|
|
5
|
+
function cssPx(val, round = true, fallback = null) {
|
|
6
|
+
if (!isNaN(val) && val !== null) {
|
|
7
|
+
return (round ? Math.round(val) : val) + 'px';
|
|
8
|
+
}
|
|
9
|
+
return fallback;
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
/*
|
|
13
|
+
Converts a number to a em string
|
|
14
|
+
px(45) => '45em'
|
|
15
|
+
*/
|
|
16
|
+
function cssEm(val, fallback) {
|
|
17
|
+
if (val) {
|
|
18
|
+
return val + 'em';
|
|
19
|
+
}
|
|
20
|
+
return fallback;
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
/*
|
|
24
|
+
Converts a number to a percentage string
|
|
25
|
+
percent(0.45) => '45%'
|
|
26
|
+
*/
|
|
27
|
+
function cssPcnt(val) {
|
|
28
|
+
if (!isNaN(val)) {
|
|
29
|
+
return val * 100 + '%';
|
|
30
|
+
}
|
|
31
|
+
return null;
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
/*
|
|
35
|
+
Wrap a string in 'url' syntax for CSS
|
|
36
|
+
url('image.png') => 'url("image.png")'
|
|
37
|
+
*/
|
|
38
|
+
function cssUrl(val) {
|
|
39
|
+
if (val) {
|
|
40
|
+
return `url("${val}")`;
|
|
41
|
+
}
|
|
42
|
+
return null;
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
export { cssPx, cssEm, cssPcnt, cssUrl };
|